coze-bridge 0.1.100-beta.0 → 0.1.100-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +85 -80
  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 Fp=Object.create;var ha=Object.defineProperty;var Up=Object.getOwnPropertyDescriptor;var Gp=Object.getOwnPropertyNames;var qp=Object.getPrototypeOf,jp=Object.prototype.hasOwnProperty;var ce=(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 $e=(t,e)=>()=>(t&&(e=t(t=0)),e);var ie=(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})},Hp=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Gp(e))!jp.call(t,o)&&o!==r&&ha(t,o,{get:()=>e[o],enumerable:!(i=Up(e,o))||i.enumerable});return t};var St=(t,e,r)=>(r=t!=null?Fp(qp(t)):{},Hp(e||!t||!t.__esModule?ha(r,"default",{value:t,enumerable:!0}):r,t));function Ve(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Hr=$e(()=>{"use strict"});import{createWriteStream as Wp,mkdirSync as Kp,readdirSync as $p,unlinkSync as Vp}from"node:fs";import{join as tl}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 Zn(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 Jp(t,e,r){let i=c=>{let[l,u,h]=c.split("-").map(Number);return Date.UTC(l??0,(u??1)-1,h??1)};return Math.floor((i(e)-i(t))/864e5)>r}function Xi(t,e,r,i){let o;try{o=$p(t)}catch{return}for(let c of o){let l=pa(c,e);if(l&&Jp(l,r,i))try{Vp(tl(t,c))}catch{}}}var Wr,ga=$e(()=>{"use strict";Wr=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{Kp(this.dir,{recursive:!0});let r=Wp(tl(this.dir,Zn(this.prefix,e)),{flags:"a"});r.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
8
+ var $p=Object.create;var ga=Object.defineProperty;var Vp=Object.getOwnPropertyDescriptor;var Zp=Object.getOwnPropertyNames;var Yp=Object.getPrototypeOf,Jp=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 Ve=(t,e)=>()=>(t&&(e=t(t=0)),e);var se=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ma=(t,e)=>{for(var r in e)ga(t,r,{get:e[r],enumerable:!0})},Xp=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Zp(e))!Jp.call(t,o)&&o!==r&&ga(t,o,{get:()=>e[o],enumerable:!(i=Vp(e,o))||i.enumerable});return t};var It=(t,e,r)=>(r=t!=null?$p(Yp(t)):{},Xp(e||!t||!t.__esModule?ga(r,"default",{value:t,enumerable:!0}):r,t));function He(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Xn=Ve(()=>{"use strict"});import{createWriteStream as Qp,mkdirSync as eg,readdirSync as tg,unlinkSync as ng}from"node:fs";import{join as ol}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 Qn(t,e){return`${t}-${e}.log`}function wa(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function rg(t,e,r){let i=c=>{let[l,u,x]=c.split("-").map(Number);return Date.UTC(l??0,(u??1)-1,x??1)};return Math.floor((i(e)-i(t))/864e5)>r}function ns(t,e,r,i){let o;try{o=tg(t)}catch{return}for(let c of o){let l=wa(c,e);if(l&&rg(l,r,i))try{ng(ol(t,c))}catch{}}}var $r,_a=Ve(()=>{"use strict";$r=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{eg(this.dir,{recursive:!0});let r=Qp(ol(this.dir,Qn(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&&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 Zp,mkdirSync as Xp}from"node:fs";import{join as Yp}from"node:path";function rl(t){let e=t.retentionDays??tg,r=t.clock??(()=>Sn(new Date));Qi={bridgeSink:new Wr(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new Wr(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 ng(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function il(t){ma=t}function sl(t){return Xn[ma]<=Xn[t]}function ol(t,e){let r=Xn[t];return r===void 0?!0:r>=Xn[e]}function es(t){nl={...t}}function al(t){let e=(u,h=2)=>String(u).padStart(h,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),l=e(o%60);return`${Sn(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${l}`}function Yn(t,e,r,i,o){try{let c=`${JSON.stringify({ts:al(new Date),level:e,module:r,msg:i,...o})}
11
- `;Xp(t,{recursive:!0}),Zp(Yp(t,Zn("bridge",Sn(new Date))),c)}catch{}}function rg(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(Xn[t]<Xn[ma])return;let c=`${JSON.stringify({ts:al(new Date),level:t,module:e,msg:r,...nl,...i})}
12
- `;if(Qi){let l=rg(o,i),u=l?ng(Qi,l):Qi.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?eg.write(c):Qp.write(c)}function U(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=>U(`${t}.${r}`,e),forAgent:r=>U(t,r)}}var Xn,ma,Qp,eg,nl,tg,Qi,te=$e(()=>{"use strict";Hr();ga();Xn={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"})(),Qp=process.stdout,eg=process.stderr,nl={},tg=Ve("COZE_BRIDGE_LOG_RETENTION_DAYS",30),Qi=null});var C,He=$e(()=>{"use strict";C=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 ul={};xa(ul,{ACP_WRAPPER_NPM_PACKAGES:()=>$r,_resetAcpInstallerForTests:()=>dg,_setBinaryPathCacheForTests:()=>lg,buildAcpSpawn:()=>Vr,ensureAcpInstalled:()=>Qn,getAcpBinaryPath:()=>ts,pickWhichLine:()=>ya,probeAcpVersion:()=>cg,resolveAcpCommand:()=>ll});import{readFileSync as cl}from"node:fs";import{createRequire as ig}from"node:module";import{dirname as sg,resolve as og}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 ag(t){let e=dl.resolve(`${t.npmPackage}/package.json`),r=sg(e),i=JSON.parse(cl(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 og(r,o)}async function Qn(t,e){let r=_a[t];if(!r)throw new C("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=Kr.get(t);if(i)return i;try{let o=ag(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 C("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 cg(t){let e=_a[t];if(e)try{let r=dl.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(cl(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 ts(t){return Kr.get(t)}function ll(t,e){if(e)return e;let r=ts(t);if(!r)throw new C("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=ll(t);return{command:process.execPath,args:[i,...r]}}function dg(){Kr.clear()}function lg(t,e){Kr.set(t,e)}var wa,_a,$r,dl,Kr,en=$e(()=>{"use strict";He();te();wa=U("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),dl=ig(import.meta.url),Kr=new Map});import{chmod as fg,mkdir as hg,readFile as xg,rename as xl,writeFile as pl}from"node:fs/promises";import{dirname as pg}from"node:path";async function er(t){try{let e=await xg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function tr(t,e,r){await hg(pg(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 pl(o,i,{encoding:"utf8",mode:r.mode}):await pl(o,i,"utf8"),await xl(o,t),r?.mode!==void 0&&await fg(t,r.mode)}catch(c){await xl(o,o).catch(()=>{});let{rm:l}=await import("node:fs/promises");throw await l(o,{force:!0}).catch(()=>{}),c}}var Jr=$e(()=>{"use strict"});import{promises as gl,readdirSync as gg}from"node:fs";import{homedir as mg}from"node:os";import{sep as wg,join as Ae,resolve as ml}from"node:path";function X(t){let e=t??mg(),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 Je(t,e=X()){let r=Ae(e.agentsRoot,t);return{root:r,config:Ae(r,"config.json"),workspace:Ae(r,"workspace"),logs:Ae(r,"logs")}}function ns(t=X()){try{return gg(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function Zr(t,e){let r=await gl.realpath(ml(t)).catch(()=>null);if(!r)return!1;let i=await gl.realpath(ml(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+wg)}var Pe=$e(()=>{"use strict"});var ss={};xa(ss,{AGENT_CONFIG_FILE_MODE:()=>rs,enforceAgentConfigMode:()=>bg,loadAgentConfig:()=>Ge,persistAgentSessions:()=>Xr,persistAgentSkills:()=>is,saveAgentConfig:()=>Ze});import{chmod as _g,stat as yg}from"node:fs/promises";function Ge(t,e){return er(Je(t,e).config)}function Ze(t,e){return tr(Je(t.agentId,e).config,t,{mode:rs})}async function bg(t,e){if(process.platform==="win32")return;let r=Je(t,e).config;try{let i=await yg(r);if(!i.isFile())return;let o=i.mode&511;o!==rs&&(await _g(r,rs),wl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;wl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function Xr(t,e,r){let i=await Ge(t,r);i&&(i.sessions=Object.fromEntries(e),await Ze(i,r))}async function is(t,e,r){let i=await Ge(t,r);i&&(i.skills=e,await Ze(i,r))}var wl,rs,tn=$e(()=>{"use strict";Jr();te();Pe();wl=U("agent-config"),rs=384});var Ea=ie((JS,El)=>{El.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 as=ie(Sl=>{var vl={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 Ag(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(vl))Sl[t]=Ag(vl[t])});var Rl=ie((XS,Cl)=>{var Tg=ce("fs"),ke=ce("path"),Il=Ea(),Cg=as(),Rg=typeof process=="object"&&process.platform==="win32",Al=t=>typeof t=="object"&&t!==null,Tl=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=ke.sep,this.fs=Tg,Al(t)&&Al(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Cl.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 l;try{l=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(l&&l.isFile())throw Cg.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 l=ke.dirname(t);o.fs.existsSync(l)||o.makeDir(l);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}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(l){if(l&&!r)return o(!1);c.fs.stat(t,function(u,h){if(l&&h.isDirectory())return o(!1);var p=ke.dirname(t);c.fs.exists(p,function(_){_||c.makeDir(p),c.fs.open(t,"w",438,function(E,A){E?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(b,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)})})})})}):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 l=[];return e.fs.readdirSync(i).forEach(function(u){let h=ke.join(i,u),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)};Ee.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(u){u=ke.join(t,u),r.fs.stat(u,function(h,p){if(h)return e(h);p&&(i.push(ke.normalize(u)+(p.isDirectory()?r.sep:"")),p.isDirectory()?r.findFilesAsync(u,function(_,E){if(_)return e(_);i=i.concat(E),--l||e(null,i)}):--l||e(null,i))})})})};Ee.prototype.getAttributes=function(){};Ee.prototype.setAttributes=function(){};Ee.crc32update=function(t,e){return Tl[(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 Il.STORED:return"STORED ("+t+")";case Il.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Ee.canonical=function(t){if(!t)return"";let e=ke.posix.normalize("/"+t.split("\\").join("/"));return ke.join(".",e)};Ee.zipnamefix=function(t){if(!t)return"";let e=ke.posix.normalize("/"+t.split("\\").join("/"));return ke.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=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)))};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=Rg;Ee.crcTable=Tl});var Pl=ie((YS,Dl)=>{var Dg=ce("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=Dg.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 Ol=ie((QS,kl)=>{kl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var ir=ie((e2,rr)=>{rr.exports=Rl();rr.exports.Constants=Ea();rr.exports.Errors=as();rr.exports.FileAttr=Pl();rr.exports.decoder=Ol()});var Ll=ie((t2,Nl)=>{var nn=ir(),F=nn.Constants;Nl.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,l=0,u=0,h=0,p=0,_=0,E=0,A=0,b=0,v=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,N=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 N(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 u},set size(y){u=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 _},set commentLength(y){_=y},get diskNumStart(){return E},set diskNumStart(y){E=S(y)},get inAttr(){return A},set inAttr(y){A=S(y)},get attr(){return b},set attr(y){b=S(y)},get fileAttr(){return(b||0)>>16&4095},get offset(){return v},set offset(y){v=S(y)},get encrypted(){return(r&F.FLG_ENC)===F.FLG_ENC},get centralHeaderSize(){return F.CENHDR+h+p+_},get realDataOffset(){return v+F.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(y){var D=y.slice(v,v+F.LOCHDR);if(D.readUInt32LE(0)!==F.LOCSIG)throw nn.Errors.INVALID_LOC();I.version=D.readUInt16LE(F.LOCVER),I.flags=D.readUInt16LE(F.LOCFLG),I.flags_desc=(I.flags&F.FLG_DESC)>0,I.method=D.readUInt16LE(F.LOCHOW),I.time=D.readUInt32LE(F.LOCTIM),I.crc=D.readUInt32LE(F.LOCCRC),I.compressedSize=D.readUInt32LE(F.LOCSIZ),I.size=D.readUInt32LE(F.LOCLEN),I.fnameLen=D.readUInt16LE(F.LOCNAM),I.extraLen=D.readUInt16LE(F.LOCEXT);let P=v+F.LOCHDR+I.fnameLen,M=P+I.extraLen;return y.slice(P,M)},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),l=y.readUInt32LE(F.CENSIZ),u=y.readUInt32LE(F.CENLEN),h=y.readUInt16LE(F.CENNAM),p=y.readUInt16LE(F.CENEXT),_=y.readUInt16LE(F.CENCOM),E=y.readUInt16LE(F.CENDSK),A=y.readUInt16LE(F.CENATT),b=y.readUInt32LE(F.CENATX),v=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(l,F.LOCSIZ),y.writeUInt32LE(u,F.LOCLEN),y.writeUInt16LE(h,F.LOCNAM),y.writeUInt16LE(I.extraLen,F.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(F.CENHDR+h+p+_);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(l,F.CENSIZ),y.writeUInt32LE(u,F.CENLEN),y.writeUInt16LE(h,F.CENNAM),y.writeUInt16LE(p,F.CENEXT),y.writeUInt16LE(_,F.CENCOM),y.writeUInt16LE(E,F.CENDSK),y.writeUInt16LE(A,F.CENATT),y.writeUInt32LE(b,F.CENATX),y.writeUInt32LE(v,F.CENOFF),y},toJSON:function(){let y=function(D){return D+" bytes"};return{made:t,version:e,flags:r,method:nn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(l),size:y(u),fileNameLength:y(h),extraLength:y(p),commentLength:y(_),diskNumStart:E,inAttr:A,attr:b,offset:v,centralHeaderSize:y(F.CENHDR+h+p+_)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Bl=ie((n2,Ml)=>{var sr=ir(),me=sr.Constants;Ml.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 sr.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=sr.readBigUInt64LE(c,me.ZIP64SUB),e=sr.readBigUInt64LE(c,me.ZIP64TOT),r=sr.readBigUInt64LE(c,me.ZIP64SIZE),i=sr.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,u){let h=l.toString(16).toUpperCase();for(;h.length<u;)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=ie(va=>{va.EntryHeader=Ll();va.MainHeader=Bl()});var Fl=ie((i2,zl)=>{zl.exports=function(t){var e=ce("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(u){c.push(u),l+=u.length}),o.on("end",function(){var u=Buffer.alloc(l),h=0;u.fill(0);for(var p=0;p<c.length;p++){var _=c[p];_.copy(u,h),h+=_.length}i&&i(u)}),o.end(t)}}}});var Gl=ie((s2,Ul)=>{var Pg=+(process.versions?process.versions.node:"").split(".")[0]||0;Ul.exports=function(t,e){var r=ce("zlib");let i=Pg>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),l=[],u=0;c.on("data",function(h){l.push(h),u+=h.length}),c.on("end",function(){var h=Buffer.alloc(u),p=0;h.fill(0);for(var _=0;_<l.length;_++){var E=l[_];E.copy(h,p),p+=E.length}o&&o(h)}),c.end(t)}}}});var Kl=ie((o2,Wl)=>{"use strict";var{randomFillSync:ql}=ce("crypto"),kg=as(),Og=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,jl=(t,e)=>Og[(t^e)&255]^t>>>8,Yr=()=>typeof ql=="function"?ql(Buffer.alloc(12)):Yr.node();Yr.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 cs={genSalt:Yr};function ds(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])}ds.prototype.updateKeys=function(t){let e=this.keys;return e[0]=jl(e[0],t),e[1]+=e[0]&255,e[1]=Hl(e[1],134775813)+1,e[2]=jl(e[2],e[1]>>>24),t};ds.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Hl(t,t^1)>>8&255};function Ng(t){let e=new ds(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 Lg(t){let e=new ds(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 Mg(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Ng(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw kg.WRONG_PASSWORD();return i(t.slice(12))}function Bg(t){Buffer.isBuffer(t)&&t.length>=12?cs.genSalt=function(){return t.slice(0,12)}:t==="node"?cs.genSalt=Yr.node:cs.genSalt=Yr}function zg(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Lg(r),c=cs.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)}Wl.exports={decrypt:Mg,encrypt:zg,_salter:Bg}});var $l=ie(ls=>{ls.Deflater=Fl();ls.Inflater=Gl();ls.ZipCrypto=Kl()});var Aa=ie((c2,Vl)=>{var se=ir(),Fg=Sa(),ve=se.Constants,Ia=$l();Vl.exports=function(t,e){var r=new Fg.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,l=null,u=Buffer.alloc(0),h=Buffer.alloc(0),p=!0;let _=t,E=typeof _.decoder=="object"?_.decoder:se.decoder;p=E.hasOwnProperty("efs")?E.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 b(y){if(!r.flags_desc&&!r.localHeader.flags_desc){if(se.crc32(y)!==r.localHeader.crc)return!1}else{let D={},P=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(P)==ve.LOCSIG||e.readUInt32LE(P)==ve.CENSIG)throw se.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(P)==ve.EXTSIG)D.crc=e.readUInt32LE(P+ve.EXTCRC),D.compressedSize=e.readUInt32LE(P+ve.EXTSIZ),D.size=e.readUInt32LE(P+ve.EXTLEN);else if(e.readUInt16LE(P+12)===19280)D.crc=e.readUInt32LE(P+ve.EXTCRC-4),D.compressedSize=e.readUInt32LE(P+ve.EXTSIZ-4),D.size=e.readUInt32LE(P+ve.EXTLEN-4);else throw se.Errors.DESCRIPTOR_UNKNOWN();if(D.compressedSize!==r.compressedSize||D.size!==r.size||D.crc!==r.crc)throw se.Errors.DESCRIPTOR_FAULTY();if(se.crc32(y)!==D.crc)return!1}return!0}function v(y,D,P){if(typeof D>"u"&&typeof y=="string"&&(P=y,y=void 0),c)return y&&D&&D(Buffer.alloc(0),se.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var M=A();if(M.length===0)return y&&D&&D(M),M;if(r.encrypted){if(typeof P!="string"&&!Buffer.isBuffer(P))throw se.Errors.INVALID_PASS_PARAM();M=Ia.ZipCrypto.decrypt(M,r,P)}var z=Buffer.alloc(r.size);switch(r.method){case se.Constants.STORED:if(M.copy(z),b(z))return y&&D&&D(z),z;throw y&&D&&D(z,se.Errors.BAD_CRC()),se.Errors.BAD_CRC();case se.Constants.DEFLATED:var $=new Ia.Inflater(M,r.size);if(y)$.inflateAsync(function(V){V.copy(V,0),D&&(b(V)?D(V):D(V,se.Errors.BAD_CRC()))});else{if($.inflate(z).copy(z,0),!b(z))throw se.Errors.BAD_CRC(`"${E.decode(i)}"`);return z}break;default:throw y&&D&&D(Buffer.alloc(0),se.Errors.UNKNOWN_METHOD()),se.Errors.UNKNOWN_METHOD()}}function I(y,D){if((!l||!l.length)&&Buffer.isBuffer(e))return y&&D&&D(A()),A();if(l.length&&!c){var P;switch(r.method){case se.Constants.STORED:return r.compressedSize=r.size,P=Buffer.alloc(l.length),l.copy(P),y&&D&&D(P),P;default:case se.Constants.DEFLATED:var M=new Ia.Deflater(l);if(y)M.deflateAsync(function($){P=Buffer.alloc($.length),r.compressedSize=$.length,$.copy(P),D&&D(P)});else{var z=M.deflate();return r.compressedSize=z.length,z}M=null;break}}else if(y&&D)D(Buffer.alloc(0));else return Buffer.alloc(0)}function S(y,D){return se.readBigUInt64LE(y,D)}function R(y){try{for(var D=0,P,M,z;D+4<y.length;)P=y.readUInt16LE(D),D+=2,M=y.readUInt16LE(D),D+=2,z=y.slice(D,D+M),D+=M,ve.ID_ZIP64===P&&N(z)}catch{throw se.Errors.EXTRA_FIELD_PARSE_ERROR()}}function N(y){var D,P,M,z;y.length>=ve.EF_ZIP64_SCOMP&&(D=S(y,ve.EF_ZIP64_SUNCOMP),r.size===ve.EF_ZIP64_OR_32&&(r.size=D)),y.length>=ve.EF_ZIP64_RHO&&(P=S(y,ve.EF_ZIP64_SCOMP),r.compressedSize===ve.EF_ZIP64_OR_32&&(r.compressedSize=P)),y.length>=ve.EF_ZIP64_DSN&&(M=S(y,ve.EF_ZIP64_RHO),r.offset===ve.EF_ZIP64_OR_32&&(r.offset=M)),y.length>=ve.EF_ZIP64_DSN+4&&(z=y.readUInt32LE(ve.EF_ZIP64_DSN),r.diskNumStart===ve.EF_ZIP64_OR_16&&(r.diskNumStart=z))}return{get entryName(){return E.decode(i)},get rawEntryName(){return i},set entryName(y){i=se.toBuffer(y,E.encode);var D=i[i.length-1];c=D===47||D===92,r.fileNameLength=i.length},get efs(){return typeof p=="function"?p(this.entryName):p},get extra(){return u},set extra(y){u=y,r.extraLength=y.length,R(y)},get comment(){return E.decode(o)},set comment(y){if(o=se.toBuffer(y,E.encode),r.commentLength=o.length,o.length>65535)throw se.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=se.toBuffer(y,se.decoder.encode),!c&&l.length?(r.size=l.length,r.method=se.Constants.DEFLATED,r.crc=se.crc32(y),r.changed=!0):r.method=se.Constants.STORED},getData:function(y){return r.changed?l:v(!1,null,y)},getDataAsync:function(y,D){r.changed?y(l):v(!0,y,D)},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=u.length;var y=r.centralHeaderToBinary(),D=se.Constants.CENHDR;return i.copy(y,D),D+=i.length,u.copy(y,D),D+=r.extraLength,o.copy(y,D),y},packLocalHeader:function(){let y=0;r.flags_efs=this.efs,r.extraLocalLength=h.length;let D=r.localHeaderToBinary(),P=Buffer.alloc(D.length+i.length+r.extraLocalLength);return D.copy(P,y),y+=D.length,i.copy(P,y),y+=i.length,h.copy(P,y),y+=h.length,P},toJSON:function(){let y=function(D){return"<"+(D&&D.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 Xl=ie((d2,Zl)=>{var Jl=Aa(),Ug=Sa(),qe=ir();Zl.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new Ug.MainHeader,l=!1,u=null;let h=new Set,p=e,{noSort:_,decoder:E}=p;t?v(p.readEntries):l=!0;function A(){let S=new Set;for(let R of Object.keys(i)){let N=R.split("/");if(N.pop(),!!N.length)for(let y=0;y<N.length;y++){let D=N.slice(0,y+1).join("/")+"/";S.add(D)}}for(let R of S)if(!(R in i)){let N=new Jl(p);N.entryName=R,N.attr=16,N.temporary=!0,r.push(N),i[N.entryName]=N,h.add(N)}}function b(){if(l=!0,i={},c.diskEntries>(t.length-c.offset)/qe.Constants.CENHDR)throw qe.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var S=c.offset,R=0;R<r.length;R++){var N=S,y=new Jl(p,t);y.header=t.slice(N,N+=qe.Constants.CENHDR),y.entryName=t.slice(N,N+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(N,N+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(N,N+y.header.commentLength)),S+=y.header.centralHeaderSize,r[R]=y,i[y.entryName]=y}h.clear(),A()}function v(S){var R=t.length-qe.Constants.ENDHDR,N=Math.max(0,R-65535),y=N,D=t.length,P=-1,M=0;for(typeof p.trailingSpace=="boolean"&&p.trailingSpace&&(N=0),R;R>=y;R--)if(t[R]===80){if(t.readUInt32LE(R)===qe.Constants.ENDSIG){P=R,M=R,D=R+qe.Constants.ENDHDR,y=R-qe.Constants.END64HDR;continue}if(t.readUInt32LE(R)===qe.Constants.END64SIG){y=N;continue}if(t.readUInt32LE(R)===qe.Constants.ZIP64SIG){P=R,D=R+qe.readBigUInt64LE(t,R+qe.Constants.ZIP64SIZE)+qe.Constants.ZIP64LEAD;break}}if(P==-1)throw qe.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(P,D)),c.commentLength&&(o=t.slice(M+qe.Constants.ENDHDR)),S&&b()}function I(){r.length>1&&!_&&r.sort((S,R)=>S.entryName.toLowerCase().localeCompare(R.entryName.toLowerCase()))}return{get entries(){return l||b(),r.filter(S=>!h.has(S))},get comment(){return E.decode(o)},set comment(S){o=qe.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||b(),i[S]||null},setEntry:function(S){l||b(),r.push(S),i[S.entryName]=S,c.totalEntries=r.length},deleteFile:function(S,R=!0){l||b();let N=i[S];this.getEntryChildren(N,R).map(D=>D.entryName).forEach(this.deleteEntry)},deleteEntry:function(S){l||b();let R=i[S],N=r.indexOf(R);N>=0&&(r.splice(N,1),delete i[S],c.totalEntries=r.length)},getEntryChildren:function(S,R=!0){if(l||b(),typeof S=="object")if(S.isDirectory&&R){let N=[],y=S.entryName;for(let D of r)D.entryName.startsWith(y)&&N.push(D);return N}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||b(),I();let S=[],R=[],N=0,y=0;c.size=0,c.offset=0;let D=0;for(let z of this.entries){let $=z.getCompressedData();z.header.offset=y;let V=z.packLocalHeader(),ee=V.length+$.length;y+=ee,S.push(V),S.push($);let Y=z.packCentralHeader();R.push(Y),c.size+=Y.length,N+=ee+Y.length,D++}N+=c.mainHeaderSize,c.offset=y,c.totalEntries=D,y=0;let P=Buffer.alloc(N);for(let z of S)z.copy(P,y),y+=z.length;for(let z of R)z.copy(P,y),y+=z.length;let M=c.toBinary();return o&&o.copy(M,qe.Constants.ENDHDR),M.copy(P,y),t=P,l=!1,P},toAsyncBuffer:function(S,R,N,y){try{l||b(),I();let D=[],P=[],M=0,z=0,$=0;c.size=0,c.offset=0;let V=function(ee){if(ee.length>0){let Y=ee.shift(),be=Y.entryName+Y.extra.toString();N&&N(be),Y.getCompressedDataAsync(function(he){y&&y(be),Y.header.offset=z;let O=Y.packLocalHeader(),G=O.length+he.length;z+=G,D.push(O),D.push(he);let W=Y.packCentralHeader();P.push(W),c.size+=W.length,M+=G+W.length,$++,V(ee)})}else{M+=c.mainHeaderSize,c.offset=z,c.totalEntries=$,z=0;let Y=Buffer.alloc(M);D.forEach(function(he){he.copy(Y,z),z+=he.length}),P.forEach(function(he){he.copy(Y,z),z+=he.length});let be=c.toBinary();o&&o.copy(be,qe.Constants.ENDHDR),be.copy(Y,z),t=Y,l=!1,S(Y)}};V(Array.from(this.entries))}catch(D){R(D)}}}}});var eu=ie((l2,Ql)=>{var _e=ir(),we=ce("path"),Gg=Aa(),qg=Xl(),In=(...t)=>_e.findLast(t,e=>typeof e=="boolean"),Yl=(...t)=>_e.findLast(t,e=>typeof e=="string"),jg=(...t)=>_e.findLast(t,e=>typeof e=="function"),Hg={noSort:!1,readEntries:!1,method:_e.Constants.NONE,fs:null};Ql.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),Hg);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 qg(r,i),{canonical:l,sanitize:u,zipnamefix:h}=_e;function p(b){if(b&&c){var v;if(typeof b=="string"&&(v=c.getEntry(we.posix.normalize(b))),typeof b=="object"&&typeof b.entryName<"u"&&typeof b.header<"u"&&(v=c.getEntry(b.entryName)),v)return v}return null}function _(b){let{join:v,normalize:I,sep:S}=we.posix;return v(we.isAbsolute(b)?"/":".",I(S+b.split("\\").join(S)+S))}function E(b){return b instanceof RegExp?(function(v){return function(I){return v.test(I)}})(b):typeof b!="function"?()=>!0:b}let A=(b,v)=>{let I=v.slice(-1);return I=I===o.sep?o.sep:"",we.relative(b,v)+I};return{readFile:function(b,v){var I=p(b);return I&&I.getData(v)||null},childCount:function(b){let v=p(b);if(v)return c.getChildCount(v)},readFileAsync:function(b,v){var I=p(b);I?I.getDataAsync(v):v(null,"getEntry failed for:"+b)},readAsText:function(b,v){var I=p(b);if(I){var S=I.getData();if(S&&S.length)return S.toString(v||"utf8")}return""},readAsTextAsync:function(b,v,I){var S=p(b);S?S.getDataAsync(function(R,N){if(N){v(R,N);return}R&&R.length?v(R.toString(I||"utf8")):v("")}):v("")},deleteFile:function(b,v=!0){var I=p(b);I&&c.deleteFile(I.entryName,v)},deleteEntry:function(b){var v=p(b);v&&c.deleteEntry(v.entryName)},addZipComment:function(b){c.comment=b},getZipComment:function(){return c.comment||""},addZipEntryComment:function(b,v){var I=p(b);I&&(I.comment=v)},getZipEntryComment:function(b){var v=p(b);return v&&v.comment||""},updateFile:function(b,v){var I=p(b);I&&I.setData(v)},addLocalFile:function(b,v,I,S){if(o.fs.existsSync(b)){v=v?_(v):"";let R=we.win32.basename(we.win32.normalize(b));v+=I||R;let N=o.fs.statSync(b),y=N.isFile()?o.fs.readFileSync(b):Buffer.alloc(0);N.isDirectory()&&(v+=o.sep),this.addFile(v,y,S,N)}else throw _e.Errors.FILE_NOT_FOUND(b)},addLocalFileAsync:function(b,v){b=typeof b=="object"?b:{localPath:b};let I=we.resolve(b.localPath),{comment:S}=b,{zipPath:R,zipName:N}=b,y=this;o.fs.stat(I,function(D,P){if(D)return v(D,!1);R=R?_(R):"";let M=we.win32.basename(we.win32.normalize(I));if(R+=N||M,P.isFile())o.fs.readFile(I,function(z,$){return z?v(z,!1):(y.addFile(R,$,S,P),setImmediate(v,void 0,!0))});else if(P.isDirectory())return R+=o.sep,y.addFile(R,Buffer.alloc(0),S,P),setImmediate(v,void 0,!0)})},addLocalFolder:function(b,v,I){if(I=E(I),v=v?_(v):"",b=we.normalize(b),o.fs.existsSync(b)){let S=o.findFiles(b),R=this;if(S.length)for(let N of S){let y=we.join(v,A(b,N));I(y)&&R.addLocalFile(N,we.dirname(y))}}else throw _e.Errors.FILE_NOT_FOUND(b)},addLocalFolderAsync:function(b,v,I,S){S=E(S),I=I?_(I):"",b=we.normalize(b);var R=this;o.fs.open(b,"r",function(N){if(N&&N.code==="ENOENT")v(void 0,_e.Errors.FILE_NOT_FOUND(b));else if(N)v(void 0,N);else{var y=o.findFiles(b),D=-1,P=function(){if(D+=1,D<y.length){var M=y[D],z=A(b,M).split("\\").join("/");z=z.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),S(z)?o.fs.stat(M,function($,V){$&&v(void 0,$),V.isFile()?o.fs.readFile(M,function(ee,Y){ee?v(void 0,ee):(R.addFile(I+z,Y,"",V),P())}):(R.addFile(I+z+"/",Buffer.alloc(0),"",V),P())}):process.nextTick(()=>{P()})}else v(!0,void 0)};P()}})},addLocalFolderAsync2:function(b,v){let I=this;b=typeof b=="object"?b:{localPath:b},localPath=we.resolve(_(b.localPath));let{zipPath:S,filter:R,namefix:N}=b;R instanceof RegExp?R=(function(P){return function(M){return P.test(M)}})(R):typeof R!="function"&&(R=function(){return!0}),S=S?_(S):"",N=="latin1"&&(N=P=>P.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof N!="function"&&(N=P=>P);let y=P=>we.join(S,N(A(localPath,P))),D=P=>we.win32.basename(we.win32.normalize(N(P)));o.fs.open(localPath,"r",function(P){P&&P.code==="ENOENT"?v(void 0,_e.Errors.FILE_NOT_FOUND(localPath)):P?v(void 0,P):o.findFilesAsync(localPath,function(M,z){if(M)return v(M);z=z.filter($=>R(y($))),z.length||v(void 0,!1),setImmediate(z.reverse().reduce(function($,V){return function(ee,Y){if(ee||Y===!1)return setImmediate($,ee,!1);I.addLocalFileAsync({localPath:V,zipPath:we.dirname(y(V)),zipName:D(V)},$)}},v))})})},addLocalFolderPromise:function(b,v){return new Promise((I,S)=>{this.addLocalFolderAsync2(Object.assign({localPath:b},v),(R,N)=>{R&&S(R),N&&I(this)})})},addFile:function(b,v,I,S){b=h(b);let R=p(b),N=R!=null;N||(R=new Gg(i),R.entryName=b),R.comment=I||"";let y=typeof S=="object"&&S instanceof o.fs.Stats;y&&(R.header.time=S.mtime);var D=R.isDirectory?16:0;let P=R.isDirectory?16384:32768;return y?P|=4095&S.mode:typeof S=="number"?P|=4095&S:P|=R.isDirectory?493:420,D=(D|P<<16)>>>0,R.attr=D,R.setData(v),N||c.setEntry(R),R},getEntries:function(b){return c.password=b,c?c.entries:[]},getEntry:function(b){return p(b)},getEntryCount:function(){return c.getEntryCount()},forEach:function(b){return c.forEach(b)},extractEntryTo:function(b,v,I,S,R,N){S=In(!1,S),R=In(!1,R),I=In(!0,I),N=Yl(R,N);var y=p(b);if(!y)throw _e.Errors.NO_ENTRY();var D=l(y.entryName),P=u(v,N&&!y.isDirectory?N:I?D:we.basename(D));if(y.isDirectory){var M=c.getEntryChildren(y);return M.forEach(function(V){if(V.isDirectory)return;var ee=V.getData();if(!ee)throw _e.Errors.CANT_EXTRACT_FILE();var Y=l(V.entryName),be=u(v,I?Y:we.basename(Y));let he=R?V.header.fileAttr:void 0;o.writeFileTo(be,ee,S,he)}),!0}var z=y.getData(c.password);if(!z)throw _e.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(P)&&!S)throw _e.Errors.CANT_OVERRIDE();let $=R?b.header.fileAttr:void 0;return o.writeFileTo(P,z,S,$),!0},test:function(b){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var I=c.entries[v].getData(b);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(b,v,I,S){if(I=In(!1,I),S=Yl(I,S),v=In(!1,v),!c)throw _e.Errors.NO_ZIP();c.entries.forEach(function(R){var N=u(b,l(R.entryName));if(R.isDirectory){o.makeDir(N);return}var y=R.getData(S);if(!y)throw _e.Errors.CANT_EXTRACT_FILE();let D=I?R.header.fileAttr:void 0;o.writeFileTo(N,y,v,D);try{o.fs.utimesSync(N,R.header.time,R.header.time)}catch{throw _e.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(b,v,I,S){if(S=jg(v,I,S),I=In(!1,I),v=In(!1,v),!S)return new Promise((P,M)=>{this.extractAllToAsync(b,v,I,function(z){z?M(z):P(this)})});if(!c){S(_e.Errors.NO_ZIP());return}b=we.resolve(b);let R=P=>u(b,we.normalize(l(P.entryName))),N=(P,M)=>new Error(P+': "'+M+'"'),y=[],D=[];c.entries.forEach(P=>{P.isDirectory?y.push(P):D.push(P)});for(let P of y){let M=R(P),z=I?P.header.fileAttr:void 0;try{o.makeDir(M),z&&o.fs.chmodSync(M,z),o.fs.utimesSync(M,P.header.time,P.header.time)}catch{S(N("Unable to create folder",M))}}D.reverse().reduce(function(P,M){return function(z){if(z)P(z);else{let $=we.normalize(l(M.entryName)),V=u(b,$);M.getDataAsync(function(ee,Y){if(Y)P(Y);else if(!ee)P(_e.Errors.CANT_EXTRACT_FILE());else{let be=I?M.header.fileAttr:void 0;o.writeFileToAsync(V,ee,v,be,function(he){he||P(N("Unable to write file",V)),o.fs.utimes(V,M.header.time,M.header.time,function(O){O?P(N("Unable to set times",V)):P()})})}})}}},S)()},writeZip:function(b,v){if(arguments.length===1&&typeof b=="function"&&(v=b,b=""),!b&&i.filename&&(b=i.filename),!!b){var I=c.compressToBuffer();if(I){var S=o.writeFileTo(b,I,!0);typeof v=="function"&&v(S?null:new Error("failed"),"")}}},writeZipPromise:function(b,v){let{overwrite:I,perm:S}=Object.assign({overwrite:!0},v);return new Promise((R,N)=>{!b&&i.filename&&(b=i.filename),b||N("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let D=P=>P?R(P):N("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(b,y,I,S,D)},N)})},toBufferPromise:function(){return new Promise((b,v)=>{c.toAsyncBuffer(b,v)})},toBuffer:function(b,v,I,S){return typeof b=="function"?(c.toAsyncBuffer(b,v,I,S),null):c.compressToBuffer()}}}});import{execFile as N_,spawn as L_,spawnSync as vA}from"node:child_process";import{promisify as M_}from"node:util";function z_(t){if(process.platform!=="win32")return!1;if(Jf.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(Jf,"").toLowerCase();return B_.has(r)}function Zf(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return z_(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function at(t,e=[],r={}){return L_(t,e,Zf(t,r))}function Xf(t,e=[],r={}){return F_(t,e,Zf(t,r))}var B_,Jf,F_,wn=$e(()=>{"use strict";B_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Jf=/\.(cmd|bat|ps1)$/i;F_=M_(N_)});var Y0=ie(ye=>{"use strict";var L=q;(function(t,e){let r=q,i=t();for(;;)try{if(-parseInt(r(1296))/1*(-parseInt(r(855))/2)+parseInt(r(1422))/3+-parseInt(r(978))/4*(-parseInt(r(1289))/5)+parseInt(r(395))/6+-parseInt(r(1221))/7*(-parseInt(r(1660))/8)+parseInt(r(812))/9*(parseInt(r(1647))/10)+-parseInt(r(498))/11===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(So,168369);var Rb=Object["definePr"+L(1219)],Db=Object["getOwnPr"+L(626)+L(1097)],$0=(t,e)=>function(){return t&&(e=(0,t[{SuBUo:function(c,l){return c(l)}}[L(1739)](Db,t)[0]])(t=0)),e},Pb=(t,e)=>{let r={OqrYJ:function(o,c,l,u){return o(c,l,u)}};for(var i in e)r.OqrYJ(Rb,t,i,{get:e[i],enumerable:!0})};function kb(){return q0||(q0=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Ob(){let t=L;return j0||(j0=[IDBCursor.prototype[t(707)],IDBCursor[t(1898)+"e"][t(1182)],IDBCursor[t(1898)+"e"].continuePrimaryKey])}function Nb(t){let e=L,r={yhQAV:e(717),iBJeW:function(o,c){return o(c)},YYhPl:function(o){return o()},ZRKMX:e(713),yJdHF:function(o,c){return o!==c},wYBLN:e(533),SaQVf:e(1864),yYHlI:e(597),DbWLH:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let l=e,u={fmbCa:r[l(367)],mAast:function(h,p){return r[l(1755)](h,p)},nmmKd:function(h){return h()}};if(r.yJdHF(l(533),r[l(1200)]))return this.endpoints[this[l(822)+l(1537)]];{let h=()=>{let E=l;t[E(611)+E(508)+"ner"](r[E(1156)],p),t[E(611)+E(508)+E(614)]("error",_)},p=()=>{let E=l,A={NqHdx:function(b,v,I){return b(v,I)}};if(u.fmbCa===u[E(547)])u[E(1467)](o,Lt(t[E(952)])),u[E(789)](h);else{let b=A[E(1730)](_0x5c43d5,_0xde15a9,_0x505a90[E(1675)]);_0x1c1f88.bytes[E(1133)](_0x18b184,b)}},_=()=>{r[l(1755)](c,t.error),r.YYhPl(h)};t[l(1617)+"Listener"](l(717),p),t[l(1617)+"Listener"](r[l(557)],_)}});return i[e(1360)](o=>{let c=e;if(r[c(750)](c(796),r[c(599)]))r[c(892)](o,IDBCursor)&&Qc[c(1133)](o,t);else return this._qosDB[c(1113)+c(1426)]()})[e(1164)](()=>{}),Eo[e(1133)](i,t),i}function Lb(t){let e=L,r={hvbWh:"complete",tlMNl:"error",gzHxs:"abort",noxpe:function(o,c){return o(c)},dRCNJ:e(582)+"or",adXBN:function(o){return o()},Rqjeh:function(o,c){return o||c},KpNgB:function(o,c){return o===c},EqrTH:"IxKXU"};if(bo[e(1680)](t))return;let i=new Promise((o,c)=>{let l=e,u={JPeMG:function(h,p){return r.Rqjeh(h,p)},fythy:function(h){return r[q(650)](h)}};if(r[l(675)]("BpVIK",r[l(657)])){let h=this[l(1715)][l(591)+"geSync"](this[l(1160)]);return _0x2a49c8[l(1279)](u[l(1425)](h,"{}"))[_0x36b784]}else{let h=()=>{let E=l;t[E(611)+E(508)+E(614)](r.hvbWh,p),t[E(611)+E(508)+E(614)](r[E(1341)],_),t[E(611)+E(508)+E(614)](r[E(1678)],_)},p=()=>{let E=l;o(),u[E(714)](h)},_=()=>{let E=l;r[E(1787)](c,t.error||new DOMException(r[E(1851)],r.dRCNJ)),r[E(650)](h)};t[l(1617)+l(1255)](r[l(973)],p),t[l(1617)+l(1255)]("error",_),t[l(1617)+l(1255)](r[l(1678)],_)}});bo.set(t,i)}function Mb(t){vo={clXVZ:function(i,o){return i(o)}}[L(555)](t,vo)}function Bb(t){let e=L,r={rXIqA:function(i,o){return i|o},pqJWw:function(i,o){return i|o},POXKt:function(i,o){return i<<o},BWEfr:function(i,o){return i+o},EfLqN:function(i,o){return i<<o},LJmlF:function(i,o){return i+o},zRDuk:function(i,o){return i|o},dvdjO:function(i,o){return i+o},JaWiw:function(i,o){return i+o},GrrOq:function(i,o){return i(o)},EwDPt:function(i,o){return i!==o},PAqEA:e(481),Qomle:"DAPmk",AkjPO:e(1518),sUTUU:function(i,o){return i(o)},zXdlw:function(i,o){return i(o)},gZdvF:function(i,o){return i(o)},WloSX:function(i,o){return i===o},rOjvH:function(i,o){return i in o},VCwwX:"objectSt"+e(1140),nAwPn:function(i,o){return i===o},CmvlW:e(609),OXeZL:e(672)};if(r.WloSX(t,IDBDatabase[e(1898)+"e"].transaction)&&!r[e(1785)](r[e(1778)],IDBTransaction[e(1898)+"e"]))if(r[e(1559)](r[e(825)],r[e(1573)])){let i=new _0x219506(r[e(1737)](r[e(1123)](r.POXKt(_0x230471[r[e(1235)](_0x31a7c4,4)],24)|_0xb2125[r[e(1235)](_0x27b452,5)]<<16,r[e(1468)](_0x22afef[r[e(1235)](_0x209b34,6)],8)),_0x2063c7[r.LJmlF(_0x4a270d,7)]),r[e(1252)](r[e(1252)](_0x355481[r[e(1120)](_0x1dc376,0)]<<24,r[e(1468)](_0x385c46[r[e(1530)](_0xedd2c9,1)],16)),r.EfLqN(_0x492566[_0x39662f+2],8))|_0x56e380[_0x4961f2+3],!0);return _0x5924ec+=8,{value:i,offset:_0x4faec6+8}}else return function(i,...o){let c=e,l=t.call(Bi(this),i,...o);return Yc[c(1133)](l,i[c(1271)]?i.sort():[i]),r.GrrOq(Lt,l)};return Ob()[e(681)](t)?function(...i){let o=e;if(r[o(1080)](r[o(1202)],r[o(1759)]))return t[o(1472)](r[o(1587)](Bi,this),i),r.zXdlw(Lt,Qc[o(431)](this));_0x172ac8[o(536)+"d"]&&(this[o(1092)+o(1128)]()&&(!this[o(1656)]||r[o(1080)](this[o(1656)].readyState,this[o(1528)])||r.EwDPt(this[o(1656)][o(1763)+"te"],this.CONNECTING))&&this[o(1194)+"nLine"](),this._isBrowser&&_0x21a53c["addEvent"+o(1255)](r[o(1457)],this[o(1194)+o(1222)]),this[o(1284)+"er"]&&_0x159aad[o(1617)+o(1255)](o(998),this["_handleO"+o(456)]))}:function(...i){let o=e;return r[o(1885)](Lt,t.apply(r[o(1244)](Bi,this),i))}}function zb(t){let e=L,r={xhmQR:function(i,o){return i===o},BzsJs:e(1175),GjohB:function(i,o){return i(o)},TJlqq:function(i,o){return i(o)},BQMAS:function(i,o,c){return i(o,c)},NGYos:function(i){return i()}};return r.xhmQR(typeof t,r[e(996)])?r.GjohB(Bb,t):(t instanceof IDBTransaction&&r[e(1179)](Lb,t),r[e(734)](V0,t,r[e(1752)](kb))?new Proxy(t,vo):t)}function Lt(t){let e=L,r={DWAsS:function(o,c){return o instanceof c},FcNoe:function(o,c){return o(c)}};if(r.DWAsS(t,IDBRequest))return r[e(1331)](Nb,t);if(_o[e(1680)](t))return _o[e(431)](t);let i=zb(t);return i!==t&&(_o.set(t,i),Eo[e(1133)](i,t)),i}var V0,q0,j0,Qc,bo,Yc,_o,Eo,vo,Bi,H0=$0({"node_modules/idb/build/wrap-idb-value.js"(){let t=L,e={ukqCn:function(r,i){return r===i},iVbBa:t(1469)+"oreNames",hDWYt:function(r,i){return r===i},dsiHg:t(959),feowL:"tFuhT",rrsTb:"store",GZyEl:function(r,i){return r===i},nVZvp:t(419),JOicb:function(r,i){return r(i)},LhtvX:function(r,i){return r instanceof i},bsvpI:t(1121),GhVGF:"KKgzy",IqzSW:t(1264),aNVKN:function(r,i){return r in i}};V0=(r,i)=>i.some(o=>r instanceof o),Qc=new WeakMap,bo=new WeakMap,Yc=new WeakMap,_o=new WeakMap,Eo=new WeakMap,vo={get(r,i,o){let c=t;if(r instanceof IDBTransaction){if(e[c(830)](i,c(1121)))return bo.get(r);if(i===e[c(430)])if(e[c(1068)](e.dsiHg,e[c(435)]))this[c(439)](_0x3c6f28,_0x377de7);else return r[c(1469)+c(1140)]||Yc.get(r);if(e[c(830)](i,e[c(1746)]))return e[c(858)](e[c(1414)],c(419))?o["objectSt"+c(1140)][1]?void 0:o["objectSt"+c(793)](o.objectStoreNames[0]):this[c(945)][c(636)+"ns"]}return e.JOicb(Lt,r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return e.LhtvX(r,IDBTransaction)&&(e[o(858)](i,e[o(1779)])||i===o(1e3))?e[o(1068)](e[o(817)],e[o(600)])?_0x45e270||(_0x309903=[_0x2ac88b[o(1898)+"e"][o(707)],_0x59c129[o(1898)+"e"][o(1182)],_0x33a30a[o(1898)+"e"][o(1182)+"PrimaryKey"]]):!0:e[o(1733)](i,r)}},Bi=r=>Eo[t(431)](r)}}),J0={};Pb(J0,{deleteDB:()=>Ub,openDB:()=>Fb,unwrap:()=>Bi,wrap:()=>Lt});function Fb(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let l=L,u={jZYOG:function(_,E){return _(E)},rSHCd:l(1306),AXDdr:l(391)+l(1670),cukMJ:l(1665)+l(1661),ZKlwj:l(674)},h=indexedDB[l(785)](t,e),p=u.jZYOG(Lt,h);return i&&h["addEvent"+l(1255)](u[l(1373)],_=>{let E=l;i(u.jZYOG(Lt,h[E(952)]),_[E(670)+"on"],_[E(1057)+"on"],u[E(1220)](Lt,h["transact"+E(1161)]))}),r&&h[l(1617)+l(1255)](u.ZKlwj,()=>r()),p[l(1360)](_=>{let E=l;c&&_["addEvent"+E(1255)](u[E(1048)],()=>c()),o&&_[E(1617)+E(1255)](u[E(1773)],()=>o())})[l(1164)](()=>{}),p}function Ub(t,{blocked:e}={}){let r=L,i={ePmqJ:"blocked",KGWFd:function(c,l){return c(l)}},o=indexedDB["deleteDa"+r(1033)](t);return e&&o[r(1617)+r(1255)](i[r(1010)],()=>e()),i[r(601)](Lt,o)[r(1360)](()=>{})}function W0(t,e){let r=L,i={BAHwT:function(h,p){return h<<p},KsBFb:function(h,p){return h<p},ekJVI:function(h,p){return h(p)},bgybe:r(500),xrjmx:function(h,p){return h instanceof p},QkMCu:function(h,p){return h===p},NQgfF:r(1290),GbHCb:function(h,p){return h!==p},TqJmO:function(h,p){return h===p},HRWjH:r(1379),JjtFx:r(654)};if(!(i[r(1881)](t,IDBDatabase)&&!(e in t)&&i[r(1625)](typeof e,i[r(1073)])))return;if(yo.get(e))return yo[r(431)](e);let o=e[r(1615)](/FromIndex$/,""),c=i[r(522)](e,o),l=X0[r(681)](o);if(!(o in(c?IDBIndex:IDBObjectStore)[r(1898)+"e"])||!(l||Z0[r(681)](o)))if(i[r(1195)](i.HRWjH,i[r(1494)]))_0x277bf5=i[r(1212)](31&_0x30f375,6)|63&_0xc64e4d,i[r(690)](_0x1c78c5,128)?_0x43fe7f+=_0x23bdeb:(_0x49da76+=i[r(1850)](_0x441fc2,_0x45666e),_0x1a0398++);else return;let u=async function(h,...p){let _=r,E=this["transact"+_(1161)](h,l?_(1654)+"e":i[_(1402)]),A=E[_(1e3)];return c&&(A=A[_(989)](p[_(1383)]())),(await Promise[_(934)]([A[o](...p),l&&E[_(1121)]]))[0]};return yo.set(e,u),u}var Z0,X0,yo,Gb=$0({"node_modules/idb/build/index.js"(){let t=L,e={MEAqz:t(1795)+"2|1",PKjVe:function(o,c){return o(c)},wPLVB:t(1060),taVDK:t(1686),hJlnT:t(1887),baKtS:t(431),fCDuw:t(977),qgHqh:t(1563),qkcPO:t(746)+"ys"},r=e[t(803)][t(1783)]("|"),i=0;for(;;){switch(r[i++]){case"0":H0();continue;case"1":e[t(916)](Mb,o=>({...o,get:(c,l,u)=>W0(c,l)||o.get(c,l,u),has:(c,l)=>!!W0(c,l)||o[t(1680)](c,l)}));continue;case"2":yo=new Map;continue;case"3":H0();continue;case"4":X0=[e[t(1857)],e.taVDK,e[t(1564)],"clear"];continue;case"5":Z0=[e[t(490)],e[t(1648)],e[t(950)],e[t(889)],t(980)];continue}break}}}),qb={idb:function(t){let e=L,r={VYnnn:function(i){return i()},FVJkb:function(i,o){return i!==o},sPKgq:"twtwi"};t.exports=Promise[e(396)]()[e(1360)](()=>(Gb(),J0))[e(1360)](function(i){let o=e;return r[o(724)]("twtwi",r[o(1801)])?(this[o(1488)+o(866)+o(1668)](_0x87b6b8),r[o(1838)](_0x8d0046)):i})}},K0={};function q(t,e){t=t-365;let r=So(),i=r[t];if(q.eLDkTw===void 0){var o=function(h){let p="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",_="",E="";for(let A=0,b,v,I=0;v=h.charAt(I++);~v&&(b=A%4?b*64+v:v,A++%4)?_+=String.fromCharCode(255&b>>(-2*A&6)):0)v=p.indexOf(v);for(let A=0,b=_.length;A<b;A++)E+="%"+("00"+_.charCodeAt(A).toString(16)).slice(-2);return decodeURIComponent(E)};q.AGFJtC=o,q.dMPtvh={},q.eLDkTw=!0}let c=r[0],l=t+c,u=q.dMPtvh[l];return u?i=u:(i=q.AGFJtC(i),q.dMPtvh[l]=i),i}function Nt(t){let e=L,r={EFtkJ:function(u,h){return u!==h}},i=(e(1521)+"2")[e(1783)]("|"),o=0;for(;;){switch(i[o++]){case"0":var c=K0[t];continue;case"1":qb[t](l,l[e(1095)],Nt);continue;case"2":return l[e(1095)];case"3":var l=K0[t]={exports:{}};continue;case"4":if(r[e(745)](void 0,c))return c[e(1095)];continue}break}}Nt.d=(t,e)=>{let r=q;for(var i in e)Nt.o(e,i)&&!Nt.o(t,i)&&Object["definePr"+r(1219)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=L;Nt.o=(e,r)=>Object[t(1898)+"e"][t(1572)+"operty"][t(756)](e,r)})(),(()=>{let t={KNrwA:function(e,r){return e!=r}};Nt.r=e=>{let r=q;if(r(1597)!=="cfOWH")return new _0x451683(_0x3c7de3,{message:_0x3c9b00,code:_0x3ca4ac,error:_0x55d767});t.KNrwA("undefined",typeof Symbol)&&Symbol["toString"+r(1672)]&&Object[r(1724)+"operty"](e,Symbol[r(1439)+"Tag"],{value:"Module"}),Object[r(1724)+r(1219)](e,r(371)+"le",{value:!0})}})();var Ce={};(()=>{let t=L,e={fOJyv:function(a,n){return a(n)},geKjd:function(a,n){return a+n},jIius:function(a,n){return a*n},qELUV:function(a,n){return a*n},mfNXL:function(a,n){return a+n},dwXbP:function(a,n,s){return a(n,s)},xhMbH:function(a,n,s){return a(n,s)},Xmyxs:function(a,n){return a(n)},AwINT:function(a,n){return a(n)},yUHiN:t(1543),qlrsL:t(1273),isgKv:function(a,n){return a(n)},orvtO:function(a,n){return a*n},Lkzam:function(a,n){return a>n},OyPUG:function(a,n){return a<n},hcEVS:function(a,n){return a>n},NJpAR:function(a,n){return a<n},EXBIQ:function(a,n){return a!==n},ADswg:function(a,n){return a-n},PkBws:function(a,n){return a!==n},dNlDe:function(a,n){return a-n},lNVvE:function(a,n){return a===n},DCbAf:t(879),KPiTm:function(a,n){return a!==n},NiZTU:function(a,n,s){return a(n,s)},IpmeZ:function(a,n,s){return a(n,s)},HRWUr:function(a,n){return a>>>n},lKMSm:function(a,n,s){return a(n,s)},USUFs:function(a,n){return a&n},oCPeB:function(a,n){return a===n},EbXnJ:"Missing required"+t(620)+"key",FaLZh:function(a,n){return a===n},SaJTd:function(a){return a()},KrKsN:function(a,n,s){return a(n,s)},eWaPH:function(a,n){return a!==n},wZIjJ:function(a,n,s){return a(n,s)},bZMAM:function(a,n){return a!==n},GISsU:function(a,n,s){return a(n,s)},daoVL:function(a,n){return a(n)},zYiDt:function(a,n){return a===n},jmSsk:t(434),MDwqX:t(659),lscOi:function(a,n,s){return a(n,s)},umowB:function(a){return a()},JmGPy:function(a,n,s){return a(n,s)},LbbqE:function(a,n,s){return a(n,s)},oZSLr:function(a,n,s){return a(n,s)},qVRHS:function(a,n){return a!==n},JjPEX:function(a,n,s){return a(n,s)},yBioI:function(a,n){return a!==n},qCTfL:"gHhEP",sPhaD:function(a,n,s){return a(n,s)},nbZlE:function(a,n,s){return a(n,s)},TXVvh:function(a,n){return a!==n},PoOzb:function(a,n,s){return a(n,s)},ZGMhg:t(575),zYzhU:function(a,n,s){return a(n,s)},DCtbP:function(a,n,s){return a(n,s)},dirTW:function(a,n){return a!==n},cLcph:function(a,n,s){return a(n,s)},lJlSj:function(a,n,s){return a(n,s)},neTAV:function(a,n){return a!==n},VTdkp:function(a,n,s){return a(n,s)},POGxX:function(a,n){return a(n)},rBPDD:function(a,n){return a(n)},CUPDP:function(a,n,s){return a(n,s)},Kibog:function(a,n,s){return a(n,s)},DGqag:function(a,n){return a(n)},NIuGZ:function(a,n){return a(n)},IsCAQ:function(a,n,s){return a(n,s)},TyIJA:function(a,n){return a(n)},VGmCT:function(a,n){return a(n)},MXZrZ:function(a,n,s){return a(n,s)},KgdTo:function(a,n){return a===n},vwpQT:function(a,n){return a===n},bBkyR:t(521)+"required"+t(620)+t(1818),MjrvV:t(521)+t(1307)+t(620)+t(1424),KVPrO:function(a,n){return a(n)},bbsyC:function(a,n){return a+n},gGojT:function(a,n){return a&n},oJjwV:function(a,n){return a(n)},BubJf:function(a,n){return a(n)},MNGek:function(a,n,s){return a(n,s)},cwkyk:function(a,n){return a+n},AqCpT:t(1369)+"ented ty"+t(949),FJnAC:function(a,n){return a>>n},enDjB:function(a,n){return a>=n},BQNcs:function(a,n){return a+n},CSRtC:t(1002)+"t limit",RyVPi:function(a,n){return a!==n},hEPsy:t(1278),kOBcz:t(1261),vNrju:function(a,n){return a<n},uGMgX:function(a,n){return a>n},NhdlQ:function(a,n){return a(n)},xWmYj:function(a,n){return a|n},FRUme:function(a,n){return a>n},OCQtR:function(a,n){return a===n},JTTFS:t(1324),NLqBq:function(a,n){return a*n},xuczD:function(a,n){return a>n},yCukR:function(a,n){return a instanceof n},dJOCN:"done",qJDGc:"store",pwxue:function(a,n){return a===n},bwNUH:t(1499),UNicb:function(a,n){return a+n},tRQbF:t(416)+"t limit",tLfkV:function(a,n,s){return a(n,s)},EbTJB:function(a,n,s){return a(n,s)},OWWok:function(a,n){return a<n},KCYqD:function(a,n){return a===n},YhBNe:function(a,n){return a(n)},LFhuJ:function(a,n){return a>=n},byQdK:function(a,n){return a<<n},OFOjo:function(a,n){return a<n},FcjVT:function(a,n){return a(n)},fBPmE:function(a,n){return a&n},zdBqM:function(a,n){return a+n},wnLGk:function(a,n){return a+n},JfiPx:function(a,n){return a+n},hVyQp:function(a,n){return a!==n},VASRI:function(a,n){return a&n},gVCeu:function(a,n){return a|n},nMWGj:function(a,n){return a|n},huMqG:function(a,n){return a<=n},urvEb:function(a,n){return a(n)},AhMKU:function(a,n){return a&n},zmGaE:function(a,n){return a+n},SUfQY:function(a,n){return a+n},kPOpP:function(a,n){return a+n},lQBKj:function(a,n){return a&n},ABXiS:function(a,n){return a|n},jDtMy:function(a,n){return a&n},MOoTN:function(a,n){return a<<n},NCVoH:function(a,n){return a<<n},PddbR:function(a,n){return a&n},btyEv:function(a,n){return a&n},vbSUg:function(a,n){return a>n},PvHlG:function(a,n,s){return a(n,s)},NgWCt:function(a,n){return a>>n},zVIMd:function(a,n,s){return a(n,s)},FPXyL:t(1864),oOyld:function(a,n){return a!==n},agmmY:t(602),wPPNc:function(a,n){return a<n},HAGqK:function(a,n){return a<n},GFaSS:function(a,n){return a!==n},vwxpn:t(1651),XCIFR:function(a,n){return a>=n},mGsgK:function(a,n){return a<n},mDIvw:function(a,n){return a+n},Mnjqm:function(a,n){return a-n},FXfDy:function(a,n){return a<<n},JsMSl:function(a,n){return a|n},HbOwO:function(a,n){return a|n},tzaNx:function(a,n){return a|n},doEcH:function(a,n){return a&n},ETSHq:function(a,n){return a(n)},ZZGBY:function(a,n){return a<n},OnpRb:function(a,n){return a&n},SBoph:function(a,n){return a&n},AZULn:function(a,n){return a>=n},npOec:function(a,n,s){return a(n,s)},bKxQQ:"close",BQNkq:function(a,n){return a&n},KWbze:function(a,n){return a<<n},bpXnw:function(a,n){return a&n},VSXdC:function(a,n){return a===n},QXqwg:t(1575),TPfUZ:t(1184),XUpyW:function(a,n){return a&n},VZxSY:function(a,n){return a===n},OjSSu:t(632),FZPLd:function(a,n){return a(n)},oKlZv:"zIThe",rTNpg:function(a,n){return a<<n},WKnwu:function(a,n){return a&n},FgjOw:function(a,n){return a&n},cXeXS:function(a,n){return a(n)},deAYQ:function(a,n){return a<<n},RMQze:function(a,n){return a&n},RRDGA:function(a,n){return a&n},EfBKT:function(a,n){return a(n)},GNYzj:function(a,n){return a(n)},BtLsV:function(a,n){return a&n},emnuV:function(a,n){return a&n},LncrZ:function(a,n){return a>>>n},mWiJf:function(a,n){return a<<n},ZzVje:function(a,n){return a|n},Ocrqd:function(a,n){return a<n},cBHbY:function(a,n){return a<n},eedVp:function(a,n){return a&n},gPxJh:function(a,n){return a>>>n},GzSQH:function(a,n){return a>>>n},SqvKP:function(a,n){return a|n},LEVvx:function(a,n){return a>>>n},ehQWq:function(a,n){return a&n},RiEpl:function(a,n){return a!==n},dAdIZ:function(a,n){return a|n},jTegX:function(a,n){return a>>>n},waDje:function(a,n){return a!==n},OvmIy:function(a,n){return a|n},Evtgg:function(a,n){return a&n},IOpAE:function(a,n){return a>>>n},bhorO:function(a,n){return a!==n},deuyY:function(a,n){return a>>>n},INAAq:function(a,n){return a|n},iVBQD:function(a,n){return a!==n},LQKPu:function(a,n){return a|n},dTylP:function(a,n){return a&n},nPONe:function(a,n){return a(n)},RdngW:function(a,n){return a<n},JSQjD:function(a,n){return a<<n},Qqyyx:t(700),uQvJc:function(a,n){return a|n},PHYcf:function(a,n){return a|n},oyvBS:function(a,n){return a<<n},kBKNt:function(a,n){return a<<n},DPuno:function(a,n){return a|n},IAmkT:function(a,n){return a|n},jcXFe:function(a,n){return a<<n},oPOhK:function(a,n){return a>=n},IyORJ:function(a,n){return a===n},etIHY:t(1240),JvYhW:function(a,n){return a|n},SjVDO:function(a,n){return a<<n},lWbyU:function(a,n){return a|n},WfRQx:function(a,n){return a<<n},dVPXZ:function(a,n){return a===n},ZdnWy:function(a,n){return a>>>n},XHvPm:function(a,n){return a|n},YQgpK:function(a,n){return a|n},lRiRs:function(a,n){return a<<n},RnJcC:function(a,n){return a<<n},GGQFz:function(a,n){return a>>>n},yiQOb:function(a,n){return a>>>n},bfIlx:function(a,n){return a&n},wnrIw:function(a,n){return a>>>n},fguoa:function(a,n){return a>>>n},zmtOE:function(a,n){return a>>>n},JfBqa:function(a,n){return a>=n},bvcqM:function(a,n){return a<=n},yfyAR:function(a,n){return a>=n},lEzKP:function(a,n){return a|n},VSoPL:function(a,n){return a%n},oteSn:function(a,n){return a/n},cKYmU:function(a,n){return a+n},DJARw:function(a,n){return a*n},VGlHP:function(a,n){return a>>>n},pfJIu:function(a,n){return a>>>n},vqgGU:function(a,n){return a>>>n},LPiWm:function(a,n){return a&n},CPrgC:function(a,n){return a&n},slUIM:function(a,n){return a&n},aQBct:function(a,n){return a+n},Psxlh:function(a,n){return a+n},cPXpF:function(a,n){return a+n},KWezD:function(a,n){return a|n},tpdBU:function(a,n){return a===n},QsLJA:function(a,n){return a+n},GrzHD:function(a,n){return a&n},zmCBa:function(a,n){return a&n},ceiTg:function(a,n){return a&n},nLtUj:function(a,n){return a>>>n},hIuIV:function(a,n){return a&n},cCGXk:function(a,n){return a&n},EnfMm:function(a,n){return a>>>n},sWiiY:function(a,n){return a>>>n},uwZey:function(a,n){return a>>>n},QNCAb:"NATIVE_E"+t(404),KecUV:t(1646)+t(1340),OodHi:t(647)+t(1487)+"R",eHDQV:t(1003)+t(1738),XyXuz:t(1305)+"OR",LGTNK:function(a,n){return a-n},zhMfJ:"hCCKd",zrDXF:t(398),GQgkB:t(1662),xrGEb:t(1849),jFmbO:t(1762),ntXVQ:function(a,n){return a>=n},WInyz:t(854),dAjSR:function(a,n){return a==n},OlanA:t(791),IvkSy:function(a,n){return a instanceof n},mKzOM:t(1347)+t(1640),Esdks:function(a,n){return a+n},ZulWh:function(a,n){return a*n},vDGPt:function(a,n){return a===n},pLEOt:function(a,n){return a!==n},adfaC:"RPFCC",VVZgI:function(a,n){return a<n},jAfyX:t(1136),YrvPZ:"open",olWdT:t(1767),mZgda:function(a,n){return a instanceof n},qrydD:function(a,n){return a+n},sTFUb:t(861),EKCBb:"uLiSC",ibhgj:function(a,n){return a instanceof n},DJdDd:function(a,n){return a+n},HEKoJ:function(a,n){return a||n},hLXCq:function(a,n){return a!=n},TIMoB:"undefined",RXGkA:t(986)+"4",JlgcV:function(a,n){return a+n},wFDad:function(a,n){return a(n)},GlglL:t(1434)+"alled mu"+t(1288)+t(1059)+t(743),gRziL:function(a,n){return a!==n},mLahp:t(423),LOkoF:function(a,n){return a<n},KZLHZ:function(a,n){return a<n},zvQbu:function(a,n){return a===n},UcMMi:function(a,n){return a<n},PFnzK:function(a,n){return a<n},nTQNH:function(a,n){return a<n},uVzRt:function(a,n){return a|n},LlfQk:function(a,n){return a|n},ErUgf:function(a,n){return a<<n},SshzX:function(a,n){return a&n},WYcYv:function(a,n){return a<n},pvvXX:function(a,n){return a|n},erRMO:function(a,n){return a===n},UuPHi:function(a,n){return a+n},KpKqV:t(1096)+t(1637),cznQc:function(a,n){return a|n},ByjDe:function(a,n){return a&n},BxxLY:function(a,n){return a+n},fEysy:function(a,n){return a+n},bOHNd:function(a,n){return a|n},XbbVD:function(a,n){return a|n},gotQk:function(a,n){return a&n},IIHwO:function(a,n){return a>>n},kMcYG:"rNfcA",lmqlu:function(a,n){return a|n},VDEzr:function(a,n){return a>>n},OvJWk:function(a,n){return a|n},dPIli:function(a,n){return a==n},IynXO:function(a,n){return a(n)},RPzza:function(a,n,s,d){return a(n,s,d)},EkdCy:function(a,n){return a instanceof n},sVNmi:t(1290),PkjuI:t(1496),eOKub:t(1507),PYyPp:t(410)+t(678),ZEDgs:function(a,n){return a(n)},imQSp:"success",PyHzk:t(1583)+t(1520)+"s",zshaI:t(489),DgajR:t(1119)+t(972)+t(1042)+"P",MOwwk:function(a,n){return a!==n},XjdSW:"SxJyD",shWWH:t(1382),djOLA:t(589),mSGph:function(a,n){return a!==n},Lxclh:t(1230),DAxEK:function(a,n){return a===n},bNxwB:"EMCOW",DxTHO:function(a){return a()},WLmDw:function(a,n,s,d){return a(n,s,d)},fMYYr:function(a,n){return a(n)},EXtla:"oWsRD",pVtNn:"pWLfK",DbWdQ:t(458),tuDGz:function(a,n){return a&n},NgspR:function(a,n){return a>>>n},EMJCK:function(a,n){return a&n},qDmIc:function(a,n){return a&n},dGtgj:t(771),axEon:function(a,n){return a!==n},SqBLW:function(a,n){return a<n},mbTkD:function(a,n){return a!==n},NsTiw:t(1794),pjzmz:t(664),JRPHe:"NDPdD",NDuye:function(a,n){return a||n},RFZID:function(a,n){return a||n},ZjQnJ:function(a,n){return a||n},miRIU:t(1129),oScnl:function(a,n,s){return a(n,s)},POBat:function(a,n,s){return a(n,s)},EtDeH:function(a,n){return a(n)},InQqr:t(1246),ZNseG:function(a,n){return a(n)},Lkmfo:function(a,n){return a!=n},KJlPa:t(1162)+t(1427)+"d",htjoc:"qos",kwHwF:t(646)+"id",EfptB:function(a,n,s){return a(n,s)},wRCVc:"zKDsA",RZhMP:function(a,n){return a<n},goxPu:t(539),IymSb:"function",Khmgg:function(a,n){return a(n)},OyJvs:t(532),gzFEU:"ujxFs",PxPRQ:"qmzTi",UPmbQ:t(930),jUlkc:t(387)+t(1556),VcBOn:function(a,n,s,d){return a(n,s,d)},ViRQH:t(387)+t(1464)+"k",xlkHl:t(387)+"er_ack_msgid",MTqjp:t(1043),KxyDB:t(1835),bdBCO:t(625),synPB:t(1346),NHNRb:function(a,n){return a+n},wyhuZ:t(565),UFaER:function(a,n){return a instanceof n},qzOQi:t(372)+"in;charset=utf-8",rJkqO:t(1896)+t(810),TLXNy:t(1896)+"ion/json;charset=utf-8",YrwZo:t(1445)+"e",vZqoH:t(1108),aOQGR:function(a,n){return a||n},mTjIL:function(a,n){return a==n},HTWWq:function(a,n){return a!==n},tduvi:t(720)+t(446)+t(680),TnbuT:function(a,n){return a>n},pfqNT:function(a,n){return a+n},kmEMh:t(1525),LPKMJ:function(a,n){return a+n},xcWkV:function(a,n){return a+n},PqoyC:function(a,n){return a+n},ksyzS:function(a,n){return a+n},kDEjJ:t(1181),wDfXh:t(1187),KDEkf:function(a,n){return a+n},OFtkp:function(a,n){return a+n},DDLmJ:function(a,n){return a+n},wRQqe:function(a,n,s){return a(n,s)},xfSBW:function(a,n){return a>>>n},fCXUi:function(a,n){return a<<n},ecVEm:function(a,n){return a<n},IbVai:function(a,n){return a+n},XNdkP:function(a,n,s,d){return a(n,s,d)},bjMoI:function(a,n){return a|n},gAtHN:function(a,n){return a|n},ZbFLz:function(a,n){return a<<n},TMECZ:function(a,n){return a<<n},EBOOv:function(a,n){return a<<n},wENOc:function(a,n){return a+n},hgNFl:function(a,n){return a|n},TxqiO:function(a,n){return a+n},ukYcw:function(a,n){return a&n},ebENo:function(a,n){return a+n},YqMVc:function(a,n){return a+n},nuYfV:function(a,n){return a+n},GPmEQ:function(a,n){return a>>>n},voNvz:function(a,n){return a+n},NWiTy:function(a,n){return a+n},iJXZS:function(a,n){return a<n},egpPT:function(a,n){return a|n},fwPAL:function(a,n){return a<<n},BLjKI:function(a,n){return a<n},HMqaC:function(a,n){return a|n},bWQVp:function(a,n){return a|n},bNFXZ:t(1248),gUiuF:t(1623),EBSBW:function(a,n){return a(n)},pRplA:function(a,n){return a+n},YVbfP:function(a,n,s,d){return a(n,s,d)},krwgx:"1|3|10|4"+t(1012)+t(1069),XnAPB:t(1818),EMffu:t(1706),WIBkE:t(495),qHDLj:"BhVid",mEuAN:function(a,n,s){return a(n,s)},CPbtO:function(a,n,s){return a(n,s)},MNyct:function(a,n){return a+n},AdWVB:t(1619)+t(1044),Fglwo:t(1644)+t(1435),jpVpj:t(1604)+t(1017),Qrhtr:t(1029),MLDBp:"CONTINUE",WIAup:function(a){return a()},HNnwz:t(1370),KRudt:function(a,n){return a instanceof n},eSmSi:t(1389),KVScw:t(1562),MLgve:function(a,n,s){return a(n,s)},zRDVc:function(a,n){return a||n},RlEJk:t(1310),wHTqT:t(655),fNlwk:function(a,n,s,d){return a(n,s,d)},Vkpmd:"code",OuPsl:t(387)+t(688),egPGg:function(a,n,s){return a(n,s)},QgyVC:t(387)+t(1610),yQvol:function(a,n,s,d){return a(n,s,d)},CCmFp:t(757)+"s",LSzTF:t(1446)+t(384)+"e",sMWub:function(a,n){return a(n)},adPjM:function(a,n,s){return a(n,s)},VCKlq:function(a,n){return a+n},IDTwt:function(a){return a()},PbygR:t(702),alFjD:function(a){return a()},UtSiT:function(a,n){return a<n},EBCpF:function(a){return a()},bQFgc:t(1008),fbpjv:function(a){return a()},aeCcp:function(a){return a()},gCvMP:function(a,n){return a===n},hrDoT:"fWain",BNMWp:t(1503),PPvfz:function(a){return a()},wGdWH:function(a,n){return a+n},FRhqF:function(a,n){return a<n},PddWR:function(a,n){return a===n},HMqri:"FblVw",HgRmX:t(544),eQkEy:t(1250),oBSwZ:function(a,n,s){return a(n,s)},BIXjZ:function(a){return a()},GIknF:function(a,n,s){return a(n,s)},wQnnl:t(1236),ZpABK:function(a,n,s){return a(n,s)},BwhtM:t(692),eTIBt:function(a,n){return a(n)},FmPir:function(a,n,s){return a(n,s)},EveUt:function(a,n){return a===n},kKBcM:t(882),PAUlc:function(a,n,s){return a(n,s)},vOZJN:function(a,n,s){return a(n,s)},IxJxP:function(a,n){return a===n},eVBjn:t(936),bwYok:function(a,n){return a==n},twMrE:function(a,n,s,d){return a(n,s,d)},SSzaM:"arraybuffer",WmUgC:function(a,n){return a===n},dejZr:t(794)+"rovide ws params"+t(1592)+t(1674)+t(1780)+t(1614)+t(1591),GnRaY:function(a,n,s){return a(n,s)},mCrIS:"reconnect",Pvhxt:t(938)+"ediately"+t(393)+"ct",EMuBC:t(481),XPPNA:t(998),qrrnU:t(1803),XBlIZ:"pageshow",BceUV:function(a,n){return a===n},TjYiM:t(703),AVOAS:function(a,n){return a!==n},GBxDm:function(a,n){return a==n},JjzGy:t(1598),voIPJ:t(1034),bmoEW:t(1817),HHmQt:t(1886),WDqeF:t(1734),XMTdD:function(a,n){return a||n},zSiQJ:t(794)+t(1856)+t(1366)+t(1149)+t(1107),BGHkh:function(a,n){return a==n},YxCzl:function(a,n,s){return a(n,s)},ZGKPx:t(1483),YWRHZ:t(1639)+"0",qdDOS:t(432),LRqiC:t(1871),EiCtr:"LqKli",FhhvU:t(379),JILDV:t(875),sTMis:t(1408),rqUmv:t(1127),WnQKC:t(1616),ntVtd:function(a,n){return a>n},yFghr:function(a,n){return a-n},DrCuO:function(a,n,s){return a(n,s)},xBqXT:function(a,n){return a(n)},FtMIC:"FRONTIER>",eXGHy:function(a,n){return a===n},JymrP:function(a,n){return a||n},GPRpH:function(a,n){return a!==n},Zmuex:t(1173),KQLZF:t(588),dTuah:t(1583)+t(797)+"t",fOXSA:t(1736),kVQaa:t(1421),rjpCl:"going aw"+t(737)+t(754)+t(1728)+t(1664),Mdusi:"received",KXPng:function(a){return a()},ejpql:"nfMKu",YoIjw:"timeout, try rec"+t(1786)+"g",bmGhT:function(a,n){return a(n)},CfNPe:function(a,n){return a&n},BixyS:function(a,n){return a&n},GDdFL:function(a,n){return a!==n},yVofE:t(727),meeKd:function(a,n){return a===n},rAhJj:"hfKnO",gpUbF:t(883)+"3",nXTUo:function(a,n,s){return a(n,s)},ErhfR:function(a,n){return a===n},kRWTa:t(1538),oFujy:t(990),ftfxn:function(a,n,s){return a(n,s)},fBaYl:t(1869)+t(561)+t(644)+"ine",DXXYL:"3|6|8|0|"+t(470)+t(1178),kloYo:function(a,n,s,d){return a(n,s,d)},mmUmz:t(699)+t(1345),onEaL:"service-name",cJSQb:function(a,n){return a(n)},nuklm:function(a,n){return a===n},CjsdP:t(965),nFVzT:function(a,n){return a(n)},BedYy:function(a,n){return a&n},VOWRb:function(a,n){return a&n},wfqTl:function(a,n){return a!==n},ytKGq:"wUJsG",AGAll:function(a,n,s){return a(n,s)},ZxezF:t(1735),jMRoM:function(a,n){return a===n},qiTMS:t(748),VFgnt:t(1742),QAwDY:function(a,n){return a|n},wLUkm:function(a,n){return a|n},Hvqbb:function(a,n){return a|n},qTecU:function(a,n){return a|n},ozAMp:function(a,n){return a>>>n},zRmdC:t(606),nUmGU:t(592)+"1|4|3|5",risrr:function(a,n){return a===n},JISvB:t(666)+t(1171)+t(1344),PWADm:t(666)+t(486)+t(392)+t(881)+"ed",cABMb:t(1826),afeSn:function(a,n){return a==n},IITtO:t(1704),YntOR:function(a,n){return a!=n},sQiDO:function(a,n){return a instanceof n},dOJcZ:function(a,n){return a(n)},LgFmm:"please provide a"+t(1571)+t(1345),jMKGW:function(a,n){return a instanceof n},ComCR:function(a,n){return a instanceof n},AaTad:function(a,n){return a===n},UjHhx:"sent",vXySo:t(1611),ywjir:function(a,n){return a!==n},kyDFL:"0|3|2|1|4",hrnWo:function(a,n){return a(n)},zRawU:t(1603),ejdCE:t(1504),FIaye:function(a,n){return a*n},xJbrP:function(a,n){return a/n},sjsLP:t(782),eDwLH:function(a,n){return a===n},KxLyV:function(a,n){return a===n},pjTGS:"Object",gKnLn:function(a,n){return a===n},RGict:t(1712)+t(1018)+t(1330)+"pe",LIcpg:function(a,n){return a!=n},kXKPt:t(1384)+t(1450)+t(1105),YEpCP:function(a,n){return a===n},MXDSG:"ServiceW"+t(503)+t(1466)};Nt.r(Ce),Nt.d(Ce,{FWS:()=>Lp,CustomErrorEvent:()=>Bd,createCloseEvent:()=>ut,ReconnectEvent:()=>Md,createErrorEvent:()=>it,decodedFrame:()=>Zt,createOpenEvent:()=>jd,CustomCloseEvent:()=>zd,createReconnectEvent:()=>na,FrontierMessageEvent:()=>Ud,encodeFrame:()=>Bt,createMessageEvent:()=>qd,OpenEvent:()=>Gd,ErrorCode:()=>Yt,Event:()=>$n,MessageEvent:()=>Fd});let r="";function i(a=""){let n=t,s="02",d=""+Date[n(668)](),f=r||(r=e[n(765)](h,a)),g=Math[n(1716)]()[n(1439)](16).slice(-6);return e.geKjd(s+d+f,g)}function o(){let a=t;return e.jIius(1e4,Date[a(668)]())+Math[a(1118)](e[a(1106)](1e4,Math.random()))}function c(a){let n=t;return e.mfNXL(e[n(765)](Array,8).join("0"),e[n(1809)](parseInt,a,10).toString(2)).slice(-8)}function l(a){let n=t;return(Array(4)[n(1460)]("0")+e[n(904)](parseInt,a,2).toString(16)).slice(-4)}function u(a){let n=t,s=a[n(1783)](/\./)[n(769)](g=>c(g)),d=[];return d[0]=e[n(839)](l,s[0]+s[1]),d[1]=e.AwINT(l,s[2]+s[3]),[e[n(1553)],n(1543),e[n(1553)],e[n(1553)],e[n(1553)],e[n(1713)],d[0],d[1]][n(1460)]("")}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(838)](a);return s?u(a):d?e.isgKv(p,a):"00000000"+n(940)+n(940)+n(940)}function p(a){let n=t,s={kOwli:function(T,k){return e[q(1109)](T,k)},LpGbm:function(T,k){return e[q(488)](T,k)}},d="",f=[],g=0,m=0,w=!0,x=e[n(1553)];if(e[n(1334)](a[n(917)]("::"),-1)){let T=a[n(1783)]("::");for(let B=0;e[n(1584)](B,T[n(1675)]);B++){let J=T[B];if(e.hcEVS(J[n(917)](":"),0)){let H=J[n(1783)](":");w&&(g=H[n(1675)]),m+=H[n(1675)];for(let de=0;e[n(1082)](de,H[n(1675)]);de++)if(e[n(827)](4,H[de][n(1675)])){let Et=x[n(1539)+"g"](0,e.ADswg(4,H[de][n(1675)])),vt=Et[n(1527)](H[de]);f[n(1455)](vt)}else f[n(1455)](H[de]);w=!1}else{if(e[n(770)](4,J[n(1675)])){let H=x[n(1539)+"g"](0,4-J.length),de=H[n(1527)](J);f[n(1455)](de)}else f[n(1455)](J);w&&(g+=1),m+=1,w=!1}}let k="";for(let B=0;e[n(1082)](B,e[n(1862)](8,m));B++)k=k[n(1527)](x);for(let B=0;B<f[n(1675)];B++)e[n(394)](B,g)&&(d=d[n(1527)](k)),d=d[n(1527)](f[B]);return d}{let T=a.split(":");for(let k=0;e[n(1082)](k,T.length);k++){let B=T[k];if(e[n(827)](4,T[k][n(1675)])){if(e[n(394)](n(1599),e.DCbAf))return FPvkMF[n(1558)](1e4*_0xb4a1f8[n(668)](),_0x2f6da7[n(1118)](FPvkMF[n(1478)](1e4,_0xe2ab0.random())));{let J=x.substring(0,e[n(928)](4,T[k].length)),H=J[n(1527)](B);d=d.concat(H)}}else d=d[n(1527)](B)}return d}}function _(a,n){let s=t,d=a[s(1211)];e[s(1103)](void 0,d)&&(e.xhMbH(ue,n,10),e.dwXbP(G,n,d));let f=a[s(1524)];e.EXBIQ(void 0,f)&&(e[s(1050)](ue,n,18),e[s(1396)](G,n,f))}function E(a){let n=t,s={};e:for(;!V(a);){let d=e[n(1186)](le,a);switch(e[n(942)](d,3)){case 0:break e;case 1:s[n(1211)]=O(a,e.fOJyv(le,a));break;case 2:s[n(1524)]=e.lKMSm(O,a,e[n(499)](le,a));break;default:e.IpmeZ(R,a,e[n(593)](7,d))}}if(e[n(815)](void 0,s[n(1211)]))throw new Error(e[n(1624)]);if(e[n(773)](void 0,s.value))throw new Error(n(521)+n(1307)+n(620)+"value");return s}function A(a){let n=t,s=e[n(941)](D);return e[n(935)](b,a,s),z(s)}function b(a,n){let s=t,d=a[s(1874)];e[s(997)](void 0,d)&&(e.NiZTU(ue,n,8),lt(n,d));let f=a[s(1351)];e[s(770)](void 0,f)&&(e[s(1751)](ue,n,16),lt(n,f));let g=a[s(1818)];g!==void 0&&(ue(n,24),e[s(1396)](lt,n,e[s(1186)](N,g)));let m=a[s(1424)];e[s(982)](void 0,m)&&(ue(n,32),e[s(1045)](lt,n,e[s(1280)](N,m)));let w=a[s(1852)];if(w!==void 0)for(let Et of w){if(e[s(1413)](e[s(523)],e[s(1481)]))return this[s(945)][s(1313)];{e[s(1134)](ue,n,42);let vt=e.umowB(D);e[s(380)](_,Et,vt),e[s(1254)](ue,n,vt[s(800)]),e[s(1732)](W,n,vt),P(vt)}}let x=a[s(438)+s(1666)];e[s(731)](void 0,x)&&(e[s(684)](ue,n,50),e[s(1396)](G,n,x));let T=a[s(1729)+s(1052)];e[s(515)](void 0,T)&&(e[s(394)](s(1196),e[s(955)])?this[s(945)]&&this[s(945)].close({code:_0x553f45,reason:_0x596a7a}):(e[s(540)](ue,n,58),e[s(1566)](G,n,T)));let k=a[s(1681)];e[s(408)](void 0,k)&&(e[s(1050)](ue,n,66),e[s(402)](ue,n,k[s(1675)]),he(n,k));let B=a[s(1768)];if(e.TXVvh(void 0,B)){if(e[s(770)](e.ZGMhg,e[s(437)]))return new _0x375b2b(_0x586ea6,{data:_0x36b400,message:_0x2cac12});ue(n,74),e[s(970)](G,n,B)}let J=a[s(1708)+s(1830)];J!==void 0&&(e[s(1050)](ue,n,82),e[s(1268)](G,n,J));let H=a.msgID;e[s(976)](void 0,H)&&(e[s(1401)](ue,n,90),e[s(1828)](G,n,H));let de=a.frameType;e[s(1132)](void 0,de)&&(e[s(380)](ue,n,96),e[s(804)](lt,n,N(de)))}function v(a){return e[t(1367)](I,M(a))}function I(a){let n=t,s={};e:for(;!e[n(1049)](V,a);){let d=le(a);switch(e[n(942)](d,3)){case 0:break e;case 1:s.SeqID=e.CUPDP(bt,a,!0);break;case 2:s[n(1351)]=e[n(479)](bt,a,!0);break;case 3:s.service=le(a);break;case 4:s.method=e.AwINT(le,a);break;case 5:{let f=e[n(1367)](S,a);(s[n(1852)]||(s.headers=[]))[n(1455)](e[n(1297)](E,a)),a[n(800)]=f;break}case 6:s[n(438)+n(1666)]=O(a,e[n(499)](le,a));break;case 7:s[n(1729)+n(1052)]=O(a,le(a));break;case 8:s[n(1681)]=be(a,e[n(814)](le,a));break;case 9:s[n(1768)]=e[n(673)](O,a,e.TyIJA(le,a));break;case 10:s[n(1708)+n(1830)]=e[n(1751)](O,a,e.AwINT(le,a));break;case 11:s[n(1243)]=e[n(380)](O,a,e[n(1074)](le,a));break;case 12:s.frameType=le(a);break;default:e[n(1633)](R,a,e.USUFs(7,d))}}if(e[n(728)](void 0,s[n(1874)]))throw new Error(n(521)+"required"+n(620)+n(1874));if(e[n(394)](void 0,s[n(1351)]))throw new Error(n(521)+"required field: "+n(1351));if(e[n(1404)](void 0,s[n(1818)]))throw new Error(e[n(1253)]);if(s[n(1424)]===void 0)throw new Error(e.MjrvV);return s}function S(a){let n=t,s=e[n(844)](le,a),d=a.limit;return a.limit=e[n(1557)](a[n(1169)],s),d}function R(a,n){let s=t;switch(n){case 0:for(;e.gGojT(128,e.oJjwV(re,a)););break;case 2:$(a,e[s(1875)](le,a));break;case 5:e[s(1027)]($,a,4);break;case 1:$(a,8);break;default:throw new Error(e[s(1294)](e[s(1064)],n))}}function N(a){let n=t;return a|=0,{low:a,high:e[n(1577)](a,31),unsigned:e.enDjB(a,0)}}let y=[];function D(){let a=t,n=y[a(1327)]();return n?(n.offset=n[a(800)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function P(a){y[t(1455)](a)}function M(a){return{bytes:a,offset:0,limit:a[t(1675)]}}function z(a){let n=t,s=a[n(652)],d=a[n(800)];return e[n(728)](s.length,d)?s:s[n(1497)](0,d)}function $(a,n){let s=t;if(e.hcEVS(e.BQNcs(a.offset,n),a.limit))throw new Error(e[s(1190)]);a.offset+=n}function V(a){let n=t;if(e[n(1006)](e[n(894)],e[n(878)]))return a[n(1169)]>=a[n(800)];this[n(1656)]&&this[n(1656)][n(528)](_0x2fd244),this[n(1365)+"Queue"][_0x4f9e24]=null}function ee(a,n){let s=t,d={pxbRO:function(x,T){return e.vNrju(x,T)},TVYTc:function(x,T){return e[q(1482)](x,T)},HvbEv:function(x,T){return e[q(763)](x,T)},PrTXo:function(x,T){return e[q(985)](x,T)}},f=a[s(652)],g=a.offset,m=a.limit,w=e[s(961)](g,n);if(e[s(888)](w,f[s(1675)]))if(e.OCQtR(s(1324),e[s(1293)])){let x=new Uint8Array(e[s(1477)](2,w));x[s(1133)](f),a[s(652)]=x}else{if(d[s(1618)](_0x3080f7,1)||d[s(671)](_0x30ccd4,_0x4b7312))return d[s(615)](_0x323a1f,_0x25951e);d[s(671)](_0x12e566+_0x24da5c,_0x43a424)&&(_0xa2fc20=d[s(615)](_0x286a31,_0x41c472),_0xb9fdde=0);let x=_0x52ef73[s(756)](_0x5114a3,_0x550f53,_0x159167+=_0x3e8051);return 7&_0x884967&&(_0xfb9cc4=d.PrTXo(7,_0x3a568a)+1),x}return a.offset=w,e[s(541)](w,m)&&(a.limit=w),g}function Y(a,n){let s=t;if(e[s(1094)](e[s(635)],e[s(635)])){let d=a.offset;if(e[s(541)](e[s(637)](d,n),a[s(800)]))throw new Error(e[s(1145)]);return a[s(1169)]+=n,d}else return TGTiOi[s(1451)](_0x3d0308,_0x54c354)&&(_0x1af9e3===TGTiOi[s(689)]||TGTiOi[s(1632)](_0x2555e5,TGTiOi.qJDGc))?!0:_0x2b5093 in _0xfb85c1}function be(a,n){let s=t,d=e[s(1658)](Y,a,n);return a[s(652)].subarray(d,d+n)}function he(a,n){let s=t,d=ee(a,n[s(1675)]);a[s(652)][s(1133)](n,d)}function O(a,n){let s=t,d=e[s(1431)](Y,a,n),f=String["fromChar"+s(795)],g=a[s(652)],m="\uFFFD",w="";for(let x=0;e.OWWok(x,n);x++){let T=g[e.cwkyk(x,d)],k,B,J,H;e[s(1189)](e.gGojT(128,T),0)?w+=e[s(454)](f,T):(224&T)===192?e[s(1277)](e[s(1055)](x,1),n)?w+=m:(k=g[e[s(1294)](e[s(1109)](x,d),1)],e.gGojT(192,k)!==128?w+=m:(H=e[s(870)](e[s(788)](31,T),6)|e[s(788)](63,k),e[s(780)](H,128)?w+=m:(w+=e[s(1232)](f,H),x++))):e.fBPmE(240,T)==224?e[s(1109)](x,2)>=n?w+=m:(k=g[e[s(545)](e[s(1557)](x,d),1)],B=g[e.wnLGk(e[s(376)](x,d),2)],e[s(621)](e[s(1249)](e[s(595)](k,B<<8),49344),32896)?w+=m:(H=e[s(1031)](e[s(870)](e[s(1249)](15,T),12),(63&k)<<6)|63&B,H<2048||e.enDjB(H,55296)&&e[s(663)](H,57343)?w+=m:(w+=e[s(425)](f,H),x+=2))):e[s(1523)](248,T)==240?e[s(1452)](x+3,n)?w+=m:(k=g[e.BQNcs(e[s(1135)](x,d),1)],B=g[e.SUfQY(e[s(505)](x,d),2)],J=g[e[s(376)](e.BQNcs(x,d),3)],e[s(770)](e[s(627)](e[s(813)](k|e[s(870)](B,8),e[s(870)](J,16)),12632256),8421504)?w+=m:(H=e[s(595)](e.ABXiS(e[s(1038)](7,T)<<18,e.MOoTN(e[s(1723)](63,k),12))|e.NCVoH(e[s(1536)](63,B),6),e[s(761)](63,J)),H<65536||e.vbSUg(H,1114111)?w+=m:(H-=65536,w+=e[s(562)](f,e[s(1157)](H,10)+55296,(1023&H)+56320),x+=3))):w+=m}return w}function G(a,n){let s=t,d={kEzsV:e[s(719)],rwrty:function(x,T,k){return e[s(1027)](x,T,k)},bQBYB:function(x,T){return e[s(1086)](x,T)}},f=n[s(1675)],g=0;for(let x=0;x<f;x++)if(e.oOyld(e.agmmY,e[s(667)]))e[s(1037)](_0x56806b,_0x4549b9,90),_0x29e31b(_0x1bc09a,_0x1603eb);else{let T=n[s(455)+"At"](x);e[s(1277)](T,55296)&&e.huMqG(T,56319)&&e[s(1294)](x,1)<f&&(T=e[s(1807)](T,10)+n[s(455)+"At"](++x)-56613888),g+=e[s(496)](T,128)?1:e.HAGqK(T,2048)?2:e[s(912)](T,65536)?3:4}e.EbTJB(ue,a,g);let m=e.IsCAQ(ee,a,g),w=a.bytes;for(let x=0;x<f;x++)if(e[s(723)](e.vwxpn,e[s(1225)])){let T=_0x2cacd1[s(725)].slice(_0x492086[s(751)+"et"],d[s(1832)](_0x334c46[s(514)+"th"],_0x37f0d3[s(751)+"et"]));this[s(945)]&&this[s(945)].send({data:T,fail:k=>{let B=s;this[B(915)](d.kEzsV,d[B(525)](_0x82ac42,B(1864),{message:this[B(603)+B(1177)+B(1510)](k)}))}})}else{let T=n[s(455)+"At"](x);e[s(1447)](T,55296)&&T<=56319&&e[s(1223)](e[s(576)](x,1),f)&&(T=e[s(1725)](e[s(1682)](T,10)+n[s(455)+"At"](++x),56613888)),T<128?w[m++]=T:(T<2048?w[m++]=e[s(985)](e[s(1577)](T,6)&31,192):(T<65536?w[m++]=e[s(1577)](T,12)&15|224:(w[m++]=e[s(820)](e[s(1157)](T,18)&7,240),w[m++]=e[s(871)](T>>12&63,128)),w[m++]=e[s(1544)](e[s(1837)](e[s(1577)](T,6),63),128)),w[m++]=e[s(985)](e[s(761)](63,T),128))}}function W(a,n){let s=t,d=e[s(1254)](ee,a,n.limit),f=a.bytes,g=n[s(652)];for(let m=0,w=n.limit;m<w;m++)f[e.mfNXL(m,d)]=g[m]}function re(a){return a[t(652)][Y(a,1)]}function Ke(a,n){let s=t,d=e[s(1027)](ee,a,1);a.bytes[d]=n}function le(a){let n=t,s=0,d=0,f;do f=e[n(975)](re,a),e.ZZGBY(s,32)&&(d|=e[n(1682)](e[n(1721)](127,f),s)),s+=7;while(e.SBoph(128,f));return d}function ue(a,n){let s=t;for(n>>>=0;e[s(1438)](n,128);)e[s(1210)](Ke,a,e[s(595)](e[s(1249)](127,n),128)),n>>>=7;e[s(1633)](Ke,a,n)}function bt(a,n){let s=t,d={xKfix:function(x,T,k){return e[q(1658)](x,T,k)},QBTFy:e[s(1700)]},f=0,g=0,m=0,w;if(w=e[s(844)](re,a),f=127&w,e[s(1067)](128,w)&&(w=e.Xmyxs(re,a),f|=e[s(610)](e[s(564)](127,w),7),128&w)){if(e.VSXdC(e[s(1791)],e[s(517)]))return;if(w=re(a),f|=e[s(870)](e[s(1282)](127,w),14),e[s(593)](128,w))if(e[s(1375)](e[s(629)],e.OjSSu)){if(w=re(a),f|=e[s(441)](127,w)<<21,e[s(1523)](128,w)&&(w=e[s(1833)](re,a),g=127&w,128&w))if(e[s(815)](e.oKlZv,s(1353)))w=e[s(763)](re,a),g|=e[s(559)](e.WKnwu(127,w),7),e[s(450)](128,w)&&(w=e.cXeXS(re,a),g|=e.deAYQ(e[s(824)](127,w),14),e[s(1013)](128,w)&&(w=e[s(420)](re,a),g|=e[s(1723)](127,w)<<21,e.USUFs(128,w)&&(w=e[s(1076)](re,a),m=e[s(740)](127,w),e.PddbR(128,w)&&(w=e[s(839)](re,a),m|=e.emnuV(127,w)<<7))));else{let x=this[s(1594)+s(933)]?.[s(1053)+"ntEndpoint"]();this[s(1488)+s(1613)+s(1198)](d[s(730)](_0x286760,d[s(957)],{code:1006,reason:s(656)+x+(s(1462)+s(1417)+s(1016)+s(386)),wasClean:!0}))}}else _0xb650a4&&this[s(1770)+s(1776)][s(1102)+"rsorFileName"](_0x101031)}return{low:e[s(871)](f,e[s(610)](g,28)),high:e[s(1070)](g,4)|e[s(908)](m,24),unsigned:n}}function lt(a,n){let s=t,d=e.HRWUr(n[s(885)],0),f=e.ZzVje(e[s(1070)](n[s(885)],28),e[s(1807)](n[s(366)],4))>>>0,g=n[s(366)]>>>24,m=e[s(1098)](0,g)?e[s(728)](0,f)?d<16384?d<128?1:2:d<2097152?3:4:e[s(1040)](f,16384)?f<128?5:6:f<2097152?7:8:e[s(1749)](g,128)?9:10,w=e[s(1268)](ee,a,m),x=a[s(652)];switch(m){case 10:x[e[s(505)](w,9)]=e[s(1606)](g>>>7,1);case 9:x[e[s(505)](w,8)]=e[s(827)](9,m)?e[s(595)](128,g):e[s(1038)](127,g);case 8:x[w+7]=m!==8?e[s(1641)](f,21)|128:e[s(1523)](e[s(1378)](f,21),127);case 7:x[e[s(376)](w,6)]=m!==7?e.SqvKP(e[s(1709)](f,14),128):e[s(1823)](e.LEVvx(f,14),127);case 6:x[e[s(686)](w,5)]=e[s(1319)](6,m)?e.dAdIZ(f>>>7,128):e.jTegX(f,7)&127;case 5:x[e.zmGaE(w,4)]=e[s(711)](5,m)?e[s(726)](128,f):127&f;case 4:x[w+3]=e[s(1006)](4,m)?e[s(413)](d>>>21,128):e[s(1281)](e[s(1362)](d,21),127);case 3:x[w+2]=e[s(1337)](3,m)?e[s(595)](e[s(1709)](d,14),128):e.doEcH(e[s(370)](d,14),127);case 2:x[e[s(545)](w,1)]=m!==2?e.INAAq(e.GzSQH(d,7),128):e[s(1281)](d>>>7,127);case 1:x[w]=e[s(954)](1,m)?e[s(1471)](128,d):e[s(1205)](127,d)}}function Zt(a){return e[t(1074)](v,a)}function Bt(a){return e.nPONe(A,a)}let Xt=65536,Gr=e[t(920)],ge=e.orvtO(Xt,Xt),Ie=e[t(1697)](ge,ge),Kn=e[t(560)](Ie,2),De=String[t(1898)+"e"][t(455)+"At"];class ae{constructor(n,s,d){let f=t,g={hfAyw:function(m,w){return m(w)},GJaTo:function(m,w){return e.RdngW(m,w)},rqZqC:function(m,w){return e.JSQjD(m,w)},rOFkf:function(m,w){return m&w}};f(1036)!==e[f(1199)]?(this.isLong=!0,this[f(885)]=e[f(413)](0,n),this[f(366)]=e[f(595)](0,s),this.unsigned=!!d):(_0xa753d2=BelEkd.hfAyw(_0x47baeb,_0x2bdd27),BelEkd[f(676)](_0x2d3269,32)&&(_0x1f07a5|=BelEkd[f(1339)](BelEkd.rOFkf(127,_0x1d9506),_0x2436f0)),_0x3972e1+=7)}static[t(1554)](n){return n&&n.isLong===!0}static[t(873)](n,s,d){return new ae(n,s,d)}static[t(1834)+"s"](n,s,d){let f=t;return d?ae["fromByte"+f(1493)](n,s):ae[f(1834)+f(1506)](n,s)}static fromBytesLE(n,s){let d=t;return new ae(e[d(452)](e.xWmYj(e[d(704)](n[0],e.mWiJf(n[1],8)),e[d(549)](n[2],16)),e.kBKNt(n[3],24)),e.DPuno(e.IAmkT(e[d(1031)](n[4],e[d(924)](n[5],8)),n[6]<<16),n[7]<<24),s)}static[t(1834)+t(1506)](n,s){let d=t,f={YyvKf:function(g,m){return e[q(1030)](g,m)}};return e[d(604)](d(1240),e.etIHY)?new ae(e[d(1087)](e[d(1087)](e[d(759)](n[4],24),e[d(964)](n[5],16))|e[d(610)](n[6],8),n[7]),e[d(805)](n[0]<<24,e[d(851)](n[1],16))|n[2]<<8|n[3],s):(_0x8e4d05|=0,{low:_0x57416c,high:_0x233a76>>31,unsigned:TsLBZG[d(1602)](_0x3cee70,0)})}static[t(407)](n){let s=t;return e[s(552)](n,Gr)?Ld:new ae(e[s(534)](e.PHYcf(e[s(1046)](e[s(1673)](De[s(756)](n,0),e.KWbze(De[s(756)](n,1),8)),e.deAYQ(De[s(756)](n,2),16)),De[s(756)](n,3)<<24),0),(e[s(1673)](De[s(756)](n,4),e[s(1612)](De[s(756)](n,5),8))|e[s(1163)](De[s(756)](n,6),16)|e[s(1789)](De[s(756)](n,7),24))>>>0,!0)}[t(1153)](){let n=t;return String[n(1201)+n(795)](e[n(563)](255,this.low),e[n(1249)](e[n(1443)](this[n(885)],8),255),e.FgjOw(e[n(1039)](this[n(885)],16),255),e.LEVvx(this.low,24),e[n(1500)](255,this[n(366)]),e[n(1237)](this[n(366)],8)&255,e.OnpRb(e[n(1459)](this.high,16),255),e[n(1111)](this[n(366)],24))}static[t(649)+"er"](n,s=!0){let d=t;if(e[d(814)](isNaN,n))return s?$x:Ld;if(s){if(e[d(1320)](n,Ie))return Jx}else{if(e[d(1228)](n,-Kn))return Zx;if(e.yfyAR(e[d(686)](n,1),Kn))return Vx}return ae.fromBits(e[d(1702)](e.VSoPL(n,ge),0),e.oteSn(n,ge)|0,s)}[t(738)](){let n=t;return this[n(1740)]?e.cKYmU(e.DJARw(e.VGlHP(this[n(366)],0),ge),e.pfJIu(this[n(885)],0)):e[n(686)](e[n(1638)](this[n(366)],ge),this[n(885)]>>>0)}isZero(){let n=t;return e[n(1189)](0,this[n(366)])&&this[n(885)]===0}[t(1686)](n){let s=t;ae[s(1554)](n)||(n=ae[s(649)+"er"](n));let d=e.vqgGU(this[s(366)],16),f=e[s(953)](65535,this[s(366)]),g=e[s(1459)](this[s(885)],16),m=e[s(1823)](65535,this[s(885)]),w=e.LEVvx(n[s(366)],16),x=e.CPrgC(65535,n[s(366)]),T=e[s(569)](n[s(885)],16),k=e[s(660)](65535,n[s(885)]),B=0,J=0,H=0,de=0;return de+=m+k,H+=e[s(1459)](de,16),de&=65535,H+=e[s(1854)](g,T),J+=e[s(1237)](H,16),H&=65535,J+=e.Psxlh(f,x),B+=J>>>16,J&=65535,B+=e.cPXpF(d,w),B&=65535,ae[s(873)](e.KWezD(e[s(1789)](H,16),de),e[s(388)](B,16)|J,this.unsigned)}equals(n){let s=t;return ae[s(1554)](n)||(n=ae[s(649)+"er"](n)),e[s(478)](this.unsigned,n[s(1740)])&&e[s(370)](this[s(366)],31)===1&&n.high>>>31===1?!1:this.high===n.high&&e.tpdBU(this[s(885)],n.low)}addOne(){let n=t;return this[n(885)]===-1&&this.high===-1?ae.fromBits(0,0,this[n(1740)]):e[n(1189)](-1,this[n(885)])?ae[n(873)](0,e[n(1372)](this[n(366)],1),this[n(1740)]):ae[n(873)](e[n(376)](this[n(885)],1),this[n(366)],this[n(1740)])}[t(1291)](n){return n?this[t(624)+"E"]():this.toBytesBE()}[t(624)+"E"](){let n=t,s=this.high,d=this[n(885)];return[e[n(991)](255,d),e[n(677)](e[n(1641)](d,8),255),e[n(1667)](e[n(461)](d,16),255),e[n(1237)](d,24),e.hIuIV(255,s),e[n(548)](e[n(1709)](s,8),255),e.cCGXk(s>>>16,255),e.deuyY(s,24)]}toBytesBE(){let n=t,s=this[n(366)],d=this[n(885)];return[e.nLtUj(s,24),e[n(1362)](s,16)&255,e[n(543)](s,8)&255,e[n(1500)](255,s),e[n(1111)](d,24),e[n(640)](e.sWiiY(d,16),255),e[n(399)](e[n(1829)](d,8),255),e.OnpRb(255,d)]}}let Ld=new ae(0,0,!1),$x=new ae(0,0,!0),Vx=ae[t(873)](-1,2147483647,!1),Jx=ae[t(873)](-1,-1,!0),Zx=ae.fromBits(0,-2147483648,!1);var Yt=(function(a){let n=t;return a[a[e[n(691)]]=5001]="NATIVE_ERROR",a[a[e[n(1004)]]=5002]=n(1646)+n(1340),a[a[e.OodHi]=5003]=e[n(1579)],a[a[e[n(1072)]]=5004]=n(1003)+n(1738),a[a[e.XyXuz]=5005]=n(1305)+"OR",a})({});class $n{constructor(n){let s=t,d={AvFVD:function(f,g){return e[q(693)](f,g)}};if(e[s(815)](e[s(1846)],e[s(1115)])){let f=_0x4440ed[s(1539)+"g"](0,PDsfHl[s(778)](4,_0x4e639e[s(1675)])),g=f[s(1527)](_0x3a92d0);_0x3e9e5a[s(1455)](g)}else this[s(1318)]=n,this.target=null}}class Md extends $n{constructor(n,s){let d=t;if(e[d(997)](d(1662),e[d(579)]))try{return!!this._qosDB}catch(f){return _0x33e300[d(729)](f),!1}else super(n),this.message=s&&s[d(1767)]||null}}class Bd extends $n{constructor(n,s){let d=t;super(n),this[d(1864)]=s&&s.error||null,this[d(777)]=s&&s[d(777)]||0,this[d(453)]=s&&s.filename||"",this.lineno=s&&s[d(516)]||0,this[d(1767)]=s&&s[d(1767)]||"",this.code=s&&s[d(1489)]||5001}}class zd extends $n{constructor(n,s){let d=t,f=(d(853)+"3")[d(1783)]("|"),g=0;for(;;){switch(f[g++]){case"0":this[d(1722)]=s&&s[d(1722)]||!1;continue;case"1":super(n);continue;case"2":this.reason=s&&s[d(678)]||"";continue;case"3":this.willReconnect=s&&s[d(1342)+d(1312)]||!1;continue;case"4":this.code=s&&s[d(1489)]||0;continue}break}}}class Fd extends $n{constructor(n,s){let d=t;super(n),this[d(1238)]=s&&s[d(1238)]||null}}class Ud extends Fd{constructor(n,s){let d=t;super(n),this[d(1238)]=s&&s[d(1238)]||null,this[d(1767)]=s&&s[d(1767)]||null}}class Gd extends $n{constructor(n,s){let d=t;super(n),this.data=s&&s[d(1238)]||null}}function it(a,{message:n,code:s,error:d}){return new Bd(a,{message:n,code:s,error:d})}function ut(a,{code:n,reason:s,wasClean:d,willReconnect:f}){let g=t;return e.yBioI(e[g(992)],e[g(992)])?this[g(1656)]?this[g(1656)].url:this._url:new zd(a,{code:n,reason:s,wasClean:d,willReconnect:f})}function qd(a,{data:n,message:s}){return new Ud(a,{data:n,message:s})}function jd(a,{data:n}){return new Gd(a,{data:n})}function na(a,{message:n}){return new Md(a,{message:n})}class Hd{constructor(n,s){let d=t;this[d(1519)+"s"]=n,this[d(1492)+"es"]=s,this[d(822)+d(1537)]=0,this[d(1546)+d(1608)+d(1541)+"t"]=0}["resetEndpointCon"+t(716)](){let n=t;if(e[n(1404)](n(389),n(584))){if(!this[n(1656)])return;this[n(1560)+"WebSocket"](_0x483490,_0x32c408,_0x13c0e9)}else this["currentI"+n(1537)]=0,this[n(1546)+n(1608)+n(1541)+"t"]=0}resetTries(){let n=t;this[n(1546)+n(1608)+n(1541)+"t"]=0}[t(1053)+t(1836)+"nt"](){let n=t,s={ZrShE:function(d,f,g){return e[q(380)](d,f,g)},NBNHJ:function(d,f){return e[q(1286)](d,f)},FRszn:function(d,f){return e[q(1294)](d,f)}};if(e[n(1319)](n(1762),e[n(1224)])){let d=GwJyhw[n(1274)](_0x2e180d,_0x38897b,_0x1f193e.limit),f=_0x358c74.bytes,g=_0x2da8f3[n(652)];for(let m=0,w=_0xdece3d.limit;GwJyhw.NBNHJ(m,w);m++)f[GwJyhw.FRszn(m,d)]=g[m]}else return this[n(1519)+"s"][this[n(822)+n(1537)]]}["getCurre"+t(1836)+"ntTriesCount"](){let n=t;return this[n(1546)+"ndpointT"+n(1541)+"t"]}[t(706)+"chMaxTries"](){let n=t;return!!(e[n(1374)](this[n(822)+n(1537)],this[n(1519)+"s"][n(1675)])||this[n(822)+n(1537)]===e[n(1862)](this[n(1519)+"s"][n(1675)],1)&&this[n(1546)+n(1608)+"riesCount"]===this.maxRetries)}["checkCur"+t(886)+t(1840)+t(856)+"tries"](){let n=t,s={lsbSu:e[n(719)],YBOdN:function(d,f,g){return e[n(402)](d,f,g)}};if(e[n(501)]==="ndCdQ")this[n(915)](s[n(568)],s[n(801)](_0x2bbc88,n(1864),{message:this[n(603)+n(1177)+"age"](_0x257ee8)}));else return e[n(511)](this[n(822)+n(1537)],this.endpoints[n(1675)])?!0:e[n(888)](this[n(1546)+n(1608)+n(1541)+"t"],this.maxRetries)}[t(1437)+t(914)+t(1607)+t(1626)+t(1442)](){let n=t;return this.currentEndpointTriesCount=1,this.currentIndex++,this[n(1519)+"s"][this[n(822)+n(1537)]]}["getCurre"+t(1836)+t(1410)+t(1859)](){let n=t;return this["currentE"+n(1608)+n(1541)+"t"]++,this[n(1053)+n(1836)+"nt"]()}}let Vn=(e[t(443)](e.TIMoB,typeof globalThis)&&e[t(1719)]===globalThis["construc"+t(1311)].name||e.hLXCq(e[t(828)],typeof window)&&e[t(661)](e[t(1719)],window[t(619)+t(1311)][t(1077)]))&&e[t(1819)](t(662)+"d",typeof document),vn=t(662)+"d"!=typeof globalThis&&(e.KxLyV(e[t(618)],globalThis["construc"+t(1311)][t(1077)])||e[t(1815)](e.RGict,globalThis[t(619)+t(1311)][t(1077)]))&&e[t(828)]!=typeof tt,qr=(e[t(443)](e[t(828)],typeof globalThis)&&e[t(833)](t(421),globalThis["construc"+t(1311)].name)||e[t(828)]==typeof globalThis||e[t(1819)]("undefined",typeof globalThis)&&!!globalThis[t(1683)+t(993)])&&e[t(1298)]("undefined",typeof wx),jr=typeof globalThis<"u"&&(e[t(1375)](e[t(768)],globalThis[t(619)+"tor"][t(1077)])||e[t(573)](e[t(1593)],globalThis.constructor[t(1077)])||e[t(1717)](e.MXDSG,globalThis[t(619)+t(1311)][t(1077)]))&&e.hLXCq(e.TIMoB,typeof self),Xx=e[t(443)]("undefined",typeof globalThis)&&e[t(1657)](e.pjTGS,globalThis[t(619)+t(1311)][t(1077)])&&e[t(828)]!=typeof global&&e.pjTGS===global[t(619)+"tor"][t(1077)]&&e[t(1819)](t(662)+"d",typeof process)&&!!process[t(527)];class ra{constructor(){let n=t;if(e[n(645)](n(791),e[n(643)]))this[n(840)+"rs"]={};else{if(this[n(529)]["disableA"+n(641)+"nect"]||this[n(1419)+"osed"])return;this[n(417)+n(446)]()}}emit(n,...s){let d=t,f=this[d(840)+"rs"][n];if(f)f[d(385)]()[d(1694)](g=>g.fn[d(1472)](g[d(1743)],s));else if(e[d(604)](e[d(719)],n)&&!this.onerror){let g=s[d(1675)]&&s[0];if(e.IvkSy(g,Error))throw g;let m=new Error(e.JfiPx(e.mKzOM,g?e[d(1188)](e[d(1557)](" (",g[d(1767)]),")"):""));throw m.context=g,g}return this}[t(439)](n,s){let d=t,f={WJirG:function(g,m){return e[q(1372)](g,m)},JDBBw:function(g,m){return e[q(1804)](g,m)},Npeaq:function(g,m){return e[q(461)](g,m)}};if(e[d(1394)](void 0,n))this[d(840)+"rs"]={};else if(e[d(1094)](void 0,s))this[d(840)+"rs"][n]=null;else if(e[d(648)](e.adfaC,d(907))){let g=this[d(840)+"rs"][n];if(g)for(let m=0;e.VVZgI(m,g[d(1675)]);)e.pwxue(g[m].fn,s)?g[d(1586)](m,1):++m}else return this[d(1740)]?qXMJeH.WJirG(qXMJeH[d(1368)](qXMJeH[d(1078)](this[d(366)],0),_0x52b352),this[d(885)]>>>0):qXMJeH[d(531)](this.high*_0x16f01f,qXMJeH[d(1078)](this[d(885)],0));return this}on(n,s,d){let f=t;return(this._listeners[n]||(this[f(840)+"rs"][n]=[]))[f(1455)]({fn:s,ctx:d||this}),this}}class Yx extends ra{[t(603)+"rrorMess"+t(1510)](n){let s=t;return n[s(1363)]||n.errNo?("message: "+(n[s(1363)]||"")+s(852)+(n[s(477)]||""))[s(1692)]():JSON[s(758)+"y"](n)}constructor(n,s,d){let f=t;if(e[f(604)](f(951),e.jAfyX)){let g=this[f(1594)+"tManager"]?.[f(1053)+f(1836)+"nt"]();this[f(1488)+f(1613)+"ent"](e.MNGek(_0x43a078,e.bKxQQ,{code:_0x5e35bc[f(1489)],reason:f(513)+f(665)+f(1897)+f(979)+"n, hostn"+f(939)+g})),this[f(1594)+f(933)]?.[f(896)+"pointCon"+f(716)](),this[f(1821)+"sCounter"]?.[f(1139)+f(695)]();return}else super(),this[f(945)]=null,qr&&wx["connectS"+f(735)]&&(this[f(945)]=wx["connectS"+f(735)]({url:n,protocols:s,header:d,fail:this[f(1191)+f(847)+f(444)][f(1814)](this),success:this[f(1191)+"ocketSuc"+f(1676)+f(411)].bind(this)})),vn&&tt[f(849)+f(735)]&&(this[f(945)]=tt.connectSocket({url:n,protocols:s,header:d,fail:this["_createS"+f(847)+f(444)][f(1814)](this),success:this[f(1191)+f(1479)+f(1676)+f(411)][f(1814)](this)}))}[t(1191)+"ocketSuc"+t(1676)+t(411)](){let n=t;Promise[n(396)]().then(()=>{this[n(755)+"steners"]()})}[t(1191)+t(847)+t(444)](n){let s=t;Promise[s(396)]()[s(1360)](()=>{let d=s,f=it(e[d(719)],{message:this[d(603)+d(1177)+d(1510)](n)});this.emit(e[d(719)],f);let g=e[d(1658)](ut,"close",{reason:this["_formatE"+d(1177)+"age"](n)});this[d(915)](e[d(1700)],g)})}[t(755)+"steners"](){let n=t,s={LQiEH:e.bKxQQ,eIBRS:function(d,f,g){return e.sPhaD(d,f,g)}};this._socket[n(946)](d=>{let f=n;this.emit(e[f(1649)],e.IsCAQ(jd,f(785),{...d,data:d[f(1363)]||""}))}),this[n(945)][n(1449)](d=>{let f=n;this.emit(s[f(628)],s[f(774)](ut,f(1306),{...d}))}),this[n(945)].onMessage(d=>{let f=n;this[f(915)](e[f(925)],qd(e.olWdT,{...d}))}),this[n(945)][n(1650)](d=>{let f=n;this[f(915)](e[f(719)],e[f(380)](it,e[f(719)],{...d,message:d[f(1363)]||""}))})}[t(528)](n){let s=t,d={BRWEG:e[s(719)],QAAsA:function(f,g,m){return f(g,m)},xjiGk:e[s(682)]};if(e[s(1375)](e[s(742)],e[s(742)]))if(e[s(922)](n,Uint8Array)){let f=n[s(725)].slice(n[s(751)+"et"],e[s(1332)](n[s(514)+"th"],n[s(751)+"et"]));this._socket&&this[s(945)][s(528)]({data:f,fail:g=>{let m=s;this.emit(d[m(630)],d[m(1390)](it,"error",{message:this[m(603)+m(1177)+m(1510)](g)}))}})}else this._socket&&this._socket[s(528)]({data:n,fail:f=>{let g=s;d[g(835)]==="WFaYc"?this[g(915)](g(1864),it(d[g(630)],{message:this[g(603)+g(1177)+g(1510)](f)})):this[g(1546)+"ndpointT"+g(1541)+"t"]=0}});else{let f={hGWln:e[s(719)],PMDNc:function(g,m,w){return e[s(1045)](g,m,w)}};if(e[s(1684)](_0x4161f7,_0x30d4ee)){let g=_0x533679[s(725)][s(385)](_0x5841de[s(751)+"et"],e[s(1517)](_0x4050b6[s(514)+"th"],_0x523bc8[s(751)+"et"]));this._socket&&this[s(945)].send({data:g,fail:m=>{let w=s;this[w(915)]("error",_0x374c42(f[w(1516)],{message:this["_formatE"+w(1177)+w(1510)](m)}))}})}else this[s(945)]&&this[s(945)][s(528)]({data:_0x37e567,fail:g=>{let m=s;this[m(915)]("error",f.PMDNc(_0x1b7f53,f[m(1516)],{message:this[m(603)+m(1177)+m(1510)](g)}))}})}}[t(1306)](n,s){let d=t;this._socket&&this[d(945)][d(1306)]({code:n,reason:s})}["addEvent"+t(1255)](n,s){this.on(n,s)}[t(611)+"entListe"+t(614)](n,s){this[t(439)](n,s)}get[t(1763)+"te"](){return this[t(945)].readyState}get[t(918)+"pe"](){let n=t;return this[n(945)][n(918)+"pe"]}set[t(918)+"pe"](n){}get[t(1313)](){let n=t;return this[n(945)][n(1313)]}get protocol(){let n=t;return this[n(945)][n(808)]}get[t(636)+"ns"](){let n=t;return this[n(945)][n(636)+"ns"]}get[t(1878)+"Amount"](){return 0}}function Qx(a,n){let s=t;if(n)return new n(a[s(1313)],a.protocol);if(e.HEKoJ(qr,vn))return new Yx(a[s(1313)],a[s(808)],a[s(1852)]);if((Vn||jr)&&e[s(1819)](e[s(828)],typeof WebSocket)&&WebSocket)return new WebSocket(a.url,a.protocols)}function ep(a){let n=t,s=e[n(571)].split("|"),d=0;for(;;){switch(s[d++]){case"0":if(vn&&tt[n(849)+n(735)])return!0;continue;case"1":if(e[n(679)](Vn,jr)&&e.TIMoB!=typeof WebSocket&&WebSocket)return!0;continue;case"2":if(qr&&wx[n(849)+n(735)])return!0;continue;case"3":if(a)return!0;continue;case"4":return!1}break}}function Wd(a,n,s){let d=t,f={SrylF:function(w,x){return e[q(999)](w,x)},ZEPkw:function(w,x){return e[q(1590)](w,x)},aAhMC:function(w,x,T){return e[q(402)](w,x,T)},tXAbm:function(w,x){return w===x},qCHzd:"PcnLm",wMlOm:e[d(799)],CWWSH:function(w,x){return e.mDIvw(w,x)}},g=-1;async function m(w){let x=d;return f[x(1203)](x(733),f[x(1359)])?w<=g?Promise[x(1229)](new Error(f[x(1813)])):(g=w,f[x(1203)](w,s[x(1675)])?Promise[x(396)]():s[w].bind(a)(n,m[x(1814)](null,f.CWWSH(w,1)))):BsSXUV.SrylF(BsSXUV[x(504)](_0x575659,4).join("0"),BsSXUV[x(1300)](_0x5052da,_0x1cfb34,2)[x(1439)](16))[x(385)](-4)}m(0)}function Kd(a){let n=t,s={eqdqz:function(g,m,w){return g(m,w)}},d=0,f=0;for(let g=0;g<a[n(1675)];++g)e.gRziL("oApiE",e[n(1233)])?(f=a[n(455)+"At"](g),e[n(943)](f,128)?d+=1:e[n(1142)](f,2048)?d+=2:e[n(1189)](e[n(399)](64512,f),55296)&&e[n(923)](64512&a[n(455)+"At"](g+1),56320)?(++g,d+=4):d+=3):(_0xc022a3(_0x51778b,66),KgowmX[n(1769)](_0x22d576,_0xfcbf9d,_0x31ac55[n(1675)]),_0x2201e5(_0x231e29,_0x2665d4));return d}function $d(a,n,s){let d=t;if(e[d(1335)](e[d(1725)](s,n),1))return"";let f="";for(let g=n;e[d(1793)](g,s);){let m=a[g++];if(m<=127)f+=String[d(1201)+d(795)](m);else if(e[d(1374)](m,192)&&e[d(1001)](m,224))f+=String[d(1201)+d(795)](e[d(1679)](e[d(740)](31,m)<<6,e[d(593)](63,a[g++])));else if(m>=224&&e[d(1075)](m,240))f+=String.fromCharCode(e[d(1046)](e.uVzRt((15&m)<<12,e.KWbze(63&a[g++],6)),63&a[g++]));else if(e[d(1698)](m,240)){let w=e[d(928)](e[d(805)](e[d(1750)]((7&m)<<18|e[d(388)](e[d(1067)](63,a[g++]),12),e[d(617)](e.SshzX(63,a[g++]),6)),e[d(1721)](63,a[g++])),65536);f+=String[d(1201)+d(795)](e[d(1257)](55296,w>>10)),f+=String["fromChar"+d(795)](e[d(1332)](56320,1023&w))}}return f}function ia(a,n,s){let d=t,f=s,g,m;for(let w=0;e[d(1117)](w,a.length);++w)if(g=a[d(455)+"At"](w),e[d(1117)](g,128))n[s++]=g;else if(g<2048)n[s++]=g>>6|192,n[s++]=e.pvvXX(63&g,128);else if(e.erRMO(64512&g,55296)&&e[d(815)](64512&(m=a[d(455)+"At"](e[d(1629)](w,1))),56320)){let x=e[d(1703)].split("|"),T=0;for(;;){switch(x[T++]){case"0":n[s++]=e[d(512)](e.ByjDe(63,g),128);continue;case"1":g=e.BxxLY(e[d(1166)](65536,e[d(1807)](e[d(1038)](1023,g),10)),e.GrzHD(1023,m));continue;case"2":n[s++]=e[d(1490)](e[d(1577)](g,12)&63,128);continue;case"3":n[s++]=e[d(1679)](g>>18,240);continue;case"4":++w;continue;case"5":n[s++]=e.XbbVD(e[d(1843)](e[d(1180)](g,6),63),128);continue}break}}else e.oCPeB(d(821),e.kMcYG)?(n[s++]=g>>12|224,n[s++]=e[d(705)](e[d(824)](e[d(1015)](g,6),63),128),n[s++]=e.OvJWk(63&g,128)):(this._miniNavigatorOnline=_0x43c931,_0x19b4a9?this[d(1194)+"nLine"]():this[d(1194)+"ffLine"]());return s-f}async function Vd(a){let n=t;if(e[n(638)](n(1290),typeof a)){let s=new Uint8Array(e[n(1580)](Kd,a));return e.RPzza(ia,a,s,0),s}return e[n(1555)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(725)],a[n(751)+"et"],a[n(514)+"th"])}function tp(a){let n=t;try{return e[n(1819)](e.sVNmi,typeof a)&&(e[n(1451)](a,ArrayBuffer)||a[n(725)]&&e.ibhgj(a[n(725)],ArrayBuffer))||e[n(1819)](e[n(1213)],typeof a)?"":(JSON[n(1279)](a),n(1896)+n(810))}catch{return n(1290)==typeof a?n(372)+n(1399)+n(415):""}}let np=(a,n)=>{let s=t;switch(a){case e[s(842)]:case e.eOKub:return{[s(1258)+a]:1,"x-tt-env":n};default:return{}}};class rp{constructor(n){let s=t;this[s(1387)+s(1879)]=n,this.count=0}addCount(){let n=t;this[n(980)]++}[t(706)+t(1329)+"nt"](){let n=t;return this[n(980)]>=this["maxLossC"+n(1879)]}[t(1139)+t(695)](n=0){let s=t;this["maxLossC"+s(1879)]=n,this[s(980)]=0}}async function ip(a){let n=t,s={Vhkww:e[n(687)],ZbTVg:function(d,f){return e.ZEDgs(d,f)},HVSOI:e[n(829)],IOXHi:e[n(1561)],IZgHU:n(1806),PSTCM:"text/jav"+n(1021),nQNQK:e[n(944)],bcQYr:e[n(1430)],VogFw:function(d,f){return e[n(1634)](d,f)},iSsZw:e.XjdSW};return new Promise(d=>{let f=n;if(!Vn)return s[f(491)](d,f(410)+f(678));try{let g=document[f(1766)+f(1691)](s[f(1428)]);window[f(767)+f(1797)]=m=>{let w=f;document[w(1895)][w(1798)+w(448)](g),window[w(767)+w(1797)]=void 0,d(m&&m[w(1485)]||s[w(744)])},g[f(1318)]=s[f(578)],g.src=a[f(1615)](/^ws/,s.nQNQK)+s.bcQYr;try{document[f(1895)][f(1831)+f(448)](g)}catch{s.VogFw(s[f(1622)],s[f(1622)])?(s[f(491)](_0x4f70b9,s[f(752)]),this[f(439)](s.IOXHi,_0x98bb24),this[f(439)](f(1583)+f(797)+"t",_0x195363)):document[f(1895)][f(1798)+f(448)](g)}}catch{window[f(767)+f(1797)]=void 0,d(s[f(744)])}})}function Qt(a,n,s){let d=t;return!!a?.[d(442)](f=>f[d(1211)]===n&&f[d(1524)]===s)}function Jn(a,n){let s=t;return a?.[s(442)](d=>d[s(1211)]===n)?.value}let sa=null;async function sp(){let a=t;return sa||(sa=Promise[a(396)]()[a(1360)](Nt.bind(Nt,e.shWWH))),sa}class op extends ra{constructor(n,s){let d=t;super(),this[d(1035)]=n,this[d(1775)]=s,this[d(1715)]=void 0,this[d(1841)+d(1259)]=null}async[t(1461)](){let n=t;if(e[n(1714)]("JxIwj",e[n(1054)])){let s=e[n(839)](_0x405682,_0xb1a3a5);this[n(1656)]&&e.dVPXZ(this[n(1656)][n(1763)+"te"],this[n(1528)])&&(this[n(1656)]&&this[n(1656)][n(528)](s),this[n(440)](e[n(1275)],_0x46db76))}else await this._init()}async[t(1515)](){let n=t,s={AGhWh:function(d,f){return e[q(653)](d,f)},rWqvM:function(d,f){return e.FcjVT(d,f)},kOTHt:e[n(842)],cIbde:e.eOKub};if(!this[n(1715)]){if(this[n(1841)+n(1259)])return this[n(1841)+"mise"];try{let d=this[n(1035)],f=this[n(1775)];this[n(1841)+"mise"]=(async()=>{let g=n;if(e.DAxEK(g(1513),e[g(1355)])){let{openDB:m}=await e[g(897)](sp);this._qosDB=await e.WLmDw(m,g(767)+"_"+d,1,{upgrade(w){let x=g;w[x(931)+x(1024)+"e"](d,{keyPath:f})}})}else return xEkHiC[g(558)](_0x5910bd,xEkHiC[g(783)](_0x59d661,_0x4c1b20))})(),await this["_initPro"+n(1259)]}catch(d){console.log(d)}finally{if(e[n(731)](e.EXtla,e.pVtNn))this[n(1841)+n(1259)]=null;else switch(_0x32c1b9){case xEkHiC[n(403)]:case xEkHiC[n(1304)]:return{[n(1258)+_0x50341f]:1,"x-tt-env":_0x44913e};default:return{}}}}}async[t(431)](n){let s=t;try{return await this._init(),this[s(1715)]?.[s(431)](this[s(1035)],n)}catch(d){console[s(729)](d)}}async[t(1133)](n,s){let d=t;return await this[d(1515)](),this[d(1715)]?.[d(1060)](this[d(1035)],n)}async del(n){let s=t;try{return await this._init(),this[s(1715)]?.[s(1887)](this[s(1035)],n)}catch(d){console[s(729)](d)}}async[t(623)](){let n=t;try{return await this[n(1515)](),this[n(1715)]?.[n(623)](this[n(1035)])}catch(s){console.log(s)}}async keys(){let n=t;return await this[n(1515)](),this[n(1715)]?.[n(746)+"ys"](this[n(1035)])}async[t(1563)](){let n=t;return await this._init(),this._qosDB?.[n(1563)](this._dbName)}async[t(834)](){let n=t;if(e[n(984)]==="OtcVE")try{this._qosDB?.[n(1306)](),this[n(1715)]=void 0}catch(s){console[n(729)](s)}else return this[n(1715)][n(623)]()}get[t(1385)](){let n=t,s={XfIse:function(d,f){return d(f)},jPekx:function(d){return e.umowB(d)}};try{return e[n(1404)](e.dGtgj,e.dGtgj)?!!this[n(1715)]:_0x1239cd[n(1201)+n(795)](e[n(399)](255,this[n(885)]),e[n(1400)](e[n(1709)](this[n(885)],8),255),e.OnpRb(e[n(502)](this[n(885)],16),255),e.gPxJh(this[n(885)],24),e[n(472)](255,this[n(366)]),e[n(370)](this[n(366)],8)&255,e[n(697)](e[n(461)](this[n(366)],16),255),e[n(963)](this[n(366)],24))}catch(d){if(e[n(570)](n(1669),"FSsJB"))return console[n(729)](d),!1;fBmXBq[n(1392)](_0x42cb97,_0x3bef35(_0x42fc86[n(952)])),fBmXBq[n(1063)](_0x3ecd27)}}}class ap{constructor(n,s){let d=t;this._DBName=n,this[d(1511)]=s,this[d(1715)]=localStorage}async[t(1461)](){}get[t(1160)](){return t(767)+"_"+this._DBName}async[t(431)](n){let s=t;if(e[s(1508)](e[s(1354)],e[s(1890)])){let d=this[s(1715)][s(1845)](this[s(1160)]);return JSON.parse(e.HEKoJ(d,"{}"))[n]}else{let d=0,f=_0x4780c7,g=_0x38db2c+4;for(;e[s(1782)](f,g);){let{value:m,offset:w}=e.MNGek(_0x4f4ee1,_0x4e6f74,f);f=w,d=e[s(963)](e[s(567)](d,8),0),d+=m}return{value:d,offset:g}}}async[t(1133)](n,s){let d=t;if(e.VZxSY(d(476),e.JRPHe))this[d(537)+d(1155)+"line"]=_0x204e36,_0x37e919?this._handleOnLine():this["_handleO"+d(456)]();else{let f=this[d(1715)][d(1845)](this[d(1160)]),g=JSON[d(1279)](e[d(1241)](f,"{}"));return g[s||n[this[d(1511)]]]=n,this._qosDB[d(1377)](this[d(1160)],JSON[d(758)+"y"](g)),s||n[this._pathKey]}}async[t(1032)](n){let s=t,d=this[s(1715)].getItem(this[s(1160)]),f=JSON[s(1279)](e[s(1812)](d,"{}"));return f[n]=void 0,this[s(1715)][s(1377)](this[s(1160)],JSON.stringify(f))}async[t(623)](){let n=t;return this._qosDB[n(623)]()}async keys(){let n=t,s=this[n(1715)][n(1845)](this._prefix),d=JSON[n(1279)](s||"{}");return Object[n(465)](d)}async[t(1563)](){let n=t,s=this[n(1715)][n(1845)](this._prefix),d=JSON[n(1279)](e[n(1241)](s,"{}"));return Object.values(d)}[t(834)](){return Promise[t(396)]()}get isReady(){return!!this[t(1715)]}}class cp{constructor(n,s){let d=t;this[d(1412)]=n,this[d(1511)]=s,this[d(1715)]=vn?tt:qr?wx:null}async[t(1461)](){}get[t(1160)](){return"frontier_"+this[t(1412)]}async[t(431)](n){let s=t,d=this[s(1715)]["getStora"+s(1771)](this[s(1160)]);return JSON.parse(e.RFZID(d,"{}"))[n]}async set(n,s){let d=t,f=this[d(1715)].getStorageSync(this._prefix),g=JSON[d(1279)](e[d(1548)](f,"{}"));return g[s||n[this[d(1511)]]]=n,this._qosDB[d(1315)+d(1771)](this[d(1160)],JSON[d(758)+"y"](g)),s||n[this[d(1511)]]}async[t(1032)](n){let s=t,d=this._qosDB[s(591)+"geSync"](this[s(1160)]),f=JSON.parse(d||"{}");return f[n]=void 0,this._qosDB["setStora"+s(1771)](this[s(1160)],JSON[s(758)+"y"](f))}async[t(623)](){let n=t;return e[n(923)](e.miRIU,e[n(905)])?this[n(1715)].clearStorageSync():(this["currentEndpointT"+n(1541)+"t"]++,this[n(1053)+n(1836)+"nt"]())}async[t(465)](){let n=t,s=this._qosDB["getStora"+n(837)+"nc"](this._prefix),d=JSON[n(1279)](s||"{}");return Object.keys(d)}async[t(1563)](){let n=t,s={xLvBY:function(d,f,g){return e[q(538)](d,f,g)},aVJfK:function(d,f,g){return e.POBat(d,f,g)},Tviih:function(d,f){return e[q(1041)](d,f)}};if(e[n(773)](e[n(424)],e[n(424)])){let d=this[n(1715)]["getStora"+n(837)+"nc"](this[n(1160)]),f=JSON[n(1279)](d||"{}");return Object[n(1151)](f)}else sxaMEs.xLvBY(_0x3b4719,_0x2dd89a,32),sxaMEs.aVJfK(_0x176d04,_0x313422,sxaMEs.Tviih(_0x57c14d,_0x181290))}[t(834)](){return Promise[t(396)]()}get[t(1385)](){let n=t;if(n(418)==="EisIe")e[n(546)](_0x54dcd6,this[n(1019)+"ionTimeoutId"]),this[n(1019)+n(1533)+"utId"]=null;else return!!this[n(1715)]}}function Jd(a,n){let s=t;if(e.HEKoJ(vn,vn))return new cp(a,n);if(e[s(679)](Vn,jr)&&e[s(443)](e[s(828)],typeof indexedDB))return new op(a,n);if((Vn||jr)&&e[s(443)]("undefined",typeof localStorage))return new ap(a,n);throw new Error(e.KJlPa)}class dp{constructor(){let n=t;this[n(802)+n(1295)+"Id"]=null,this._interval=36e5,this[n(1715)]=e[n(1828)](Jd,e[n(1192)],e[n(1218)])}async[t(802)+t(1630)](){let n=t;e[n(1833)](clearInterval,this[n(802)+n(1295)+"Id"]),this[n(802)+n(1295)+"Id"]=e.EfptB(setInterval,()=>{let s=n;this[s(1058)+s(1853)]()},this[n(802)+"l"])}async openDB(){let n=t,s={WNiSF:e[n(719)],ipYrh:function(d,f){return e.neTAV(d,f)},ZfezL:n(1099),vyIfB:e[n(887)]};await this[n(1715)][n(1461)]()[n(1360)](()=>{let d=n;if(s[d(1208)](s.ZfezL,s[d(1727)]))this._intervalFlush();else{let f=d(656)+_0x1b61db+(d(1462)+d(1417)+d(1016)+d(386));this[d(440)](f),this["_dispatchErrorEv"+d(1198)](_0x2640e2(s[d(551)],{message:f,code:_0x154021[d(647)+d(1487)+"R"]}));return}})}async[t(1058)+t(1853)](){let n=t;if(e[n(526)]===n(1861)){let s=0,d={};for(let f=0;e.RZhMP(f,_0x12afe5[n(1675)]);f++)d[_0x3a14ea[f][n(1644)+"ame"]]=e[n(911)](_0x584508,_0x1e7ea9[f][n(1644)+n(1435)]),s+=e.UNicb(14,d[_0x193cff[f][n(1644)+n(1435)]]);return[s,d]}else(await this._qosDB?.[n(1563)]()||[]).filter(({timestamp:f})=>f<Date[n(668)]()).forEach(f=>{let g=n;this[g(1715)]?.[g(1032)](f.message_id)})}async[t(1032)](n){let s=t,d={ddzDF:e[s(1491)],cPZrc:function(f,g){return f(g)},cqoXx:function(f,g){return e[s(1711)](f,g)}};return e[s(1098)](e[s(1635)],e[s(792)])?typeof _0x57b7ba===mqKWdd[s(1131)]?mqKWdd[s(1741)](_0x1f74f6,_0x40a486):(_0x588178 instanceof _0x31afa1&&mqKWdd[s(1267)](_0x31ca2e,_0x5a51b8),_0x55f6b3(_0x2739df,_0x5bf67a())?new _0x8a9964(_0x1ba266,_0x2178f3):_0x8f171b):this[s(1715)]?.[s(1032)](n)}async[t(1133)](n,s){let d=t;return this._qosDB?.[d(1133)]({message_id:n,timestamp:s})}async[t(431)](n){return this._qosDB?.get(n)}async closeDB(){let n=t,s={uWqfv:function(d,f){return e[q(1332)](d,f)},ojwGP:function(d,f){return e.RRDGA(d,f)}};if(e[n(712)]==="qmzTi")e[n(844)](clearInterval,this[n(802)+n(1295)+"Id"]),await this[n(1715)]?.[n(834)]();else return _0x4e7903[n(1185)+"8"]?{value:_0x3b9348.readUInt8(_0x18f0c0),offset:s[n(859)](_0x4f77d9,1)}:{value:s.ojwGP(255,_0x8296e[_0x17eec3]),offset:_0x2057ab+1}}get[t(1385)](){return this[t(1715)]?.isReady}}function oa(a){let n=t;if(e[n(394)](e[n(1701)],e.UPmbQ)){let s=!!this[n(529)][n(1535)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let d=e[n(1020)](Qt,a[n(1767)][n(1852)],e[n(816)],"2"),f=d&&e[n(1020)](Qt,a.message[n(1852)],n(387)+n(1088)+"ck","1"),g=d&&e[n(1655)](Qt,a[n(1767)][n(1852)],e.ViRQH,"1"),m=g?e[n(804)](Jn,a[n(1767)].headers,e[n(1323)])?.[n(1783)](",")[n(948)](Boolean)||[]:[];return{enabled:s,isQoSMessage:d,isQoSAck:f,isAckCleanupMessage:g,ackMsgIds:m}}else{let s=e[n(1037)](_0x44b7c4,_0x1883eb,1);_0x31e004[n(652)][s]=_0x3e28f4}}async function Zd(){let a=t;return this[a(1159)+a(480)]||(this._QoSManager=new dp),this[a(1159)+a(480)][a(1385)]||await this[a(1159)+"ger"].openDB(),this[a(1159)+a(480)]}async function lp(a,n){let s=t,{enableAutoAck:d}=this._options,f=e[s(1020)](Qt,a.message[s(1852)],e[s(913)],"1"),g=Qt(a[s(1767)][s(1852)],s(1835),"1"),m=oa[s(756)](this,a);if(d&&f){let{SeqID:w,LogID:x,service:T,LogIDNew:k,method:B}=a[s(1767)];this[s(1569)]({SeqID:w,LogID:x,LogIDNew:k,service:T,method:B,headers:[{key:e[s(960)],value:"1"},{key:e.bdBCO,value:e[s(1241)](k,"")},{key:e[s(397)],value:"0"}]})}g&&!m[s(698)]&&this[s(1488)+s(1071)+s(732)](a),e[s(696)](n)}async function up(a,n){let s=t;this[s(440)](s(1007),a[s(1767)]),e[s(897)](n)}async function fp(a,n){let s=t,d={WHgry:function(g,m){return g&m},mwWPU:function(g,m){return e.NHNRb(g,m)}},f=e.EfBKT(Zt,await Vd(a.data));try{if(e[s(1451)](f[s(1681)],Uint8Array))if(e[s(1893)](e[s(1784)],e[s(1784)])){let g=e[s(710)](this._options[s(438)+s(1666)],Object)?{force:!!this[s(529)].payloadEncoding[s(899)],encoding:this[s(529)][s(438)+s(1666)][s(1585)]?this[s(529)][s(438)+"ncoding"][s(1585)][s(1615)](/\s/g,"")[s(826)+s(1514)]():""}:{force:!1,encoding:this[s(529)].payloadEncoding?this[s(529)][s(438)+s(1666)].replace(/\s/g,"")[s(826)+s(1514)]():""},m=f[s(438)+s(1666)]?f[s(438)+"ncoding"].replace(/\s/g,"")[s(826)+s(1514)]():"",w=this[s(529)][s(1729)+"ype"]instanceof Object?{force:!!this[s(529)][s(1729)+s(1052)][s(899)],type:this._options.payloadType.type?this[s(529)][s(1729)+"ype"].type[s(1615)](/\s/g,"")[s(826)+"ase"]():""}:{force:!1,type:this[s(529)][s(1729)+"ype"]?this._options[s(1729)+s(1052)][s(1615)](/\s/g,"").toLowerCase():""},x=f[s(1729)+"ype"]?f[s(1729)+s(1052)][s(1615)](/\s/g,"")[s(826)+s(1514)]():"",T=w.force?w[s(1318)]:x||w[s(1318)],k=g[s(899)]?g.encoding:m||g.encoding,B=[e[s(1760)],e[s(1204)],e.TLXNy,e.sVNmi],J=[e[s(594)],e[s(1317)]];this[s(529)][s(596)+s(1269)+"extPayload"]&&B[s(681)](T)&&(!k||J[s(681)](k))?f[s(1621)+s(1028)]=$d(f.payload,0,f.payload[s(514)+"th"]):f[s(1621)+"oad"]=""}else return _0x1d2a14[s(1062)+"t8"]?_0x12efcb[s(1062)+"t8"](_0x1525a3,_0x192622):_0x5f3a6a[_0x2ef640]=d[s(1596)](255,_0x3d70e2),d.mwWPU(_0x157ba9,1);else f[s(1621)+"oad"]=""}catch(g){f[s(1621)+s(1028)]="",console.log(g)}a[s(1767)]=f,n()}function hp(a,n,s){let d=t,f={uymSy:function(g,m){return e.SqBLW(g,m)},dfTec:function(g,m){return e.uGMgX(g,m)},MEVyF:function(g,m){return e[q(524)](g,m)},LOGTE:function(g,m){return e.TnbuT(g,m)},UCdxr:function(g,m){return g(m)},eqWGR:function(g,m){return e[q(616)](g,m)},gMcVg:function(g,m){return e.pfqNT(g,m)}};if(d(1525)===e.kmEMh){let g=s||8192,m=g>>>1,w=null,x=g;return function(T){let k=d;if(f.uymSy(T,1)||f[k(433)](T,m))return f[k(1100)](a,T);f.LOGTE(x+T,g)&&(w=f[k(613)](a,g),x=0);let B=n[k(756)](w,x,x+=T);return f[k(1688)](7,x)&&(x=f[k(412)](7|x,1)),B}}else{let{url:g}=e[d(1847)](_0x433006,{}),m=_0x35dcc3[d(1114)](g)?g:e[d(709)](e[d(1213)],typeof g)?[g]:[];_0x1ad07d&&_0x538a69[d(969)](this._options,_0x4525a0),m&&m[d(1675)]?this["_endpoin"+d(933)]=new _0x16050f(m,this[d(529)][d(1492)+"es"]):this["_endpoin"+d(933)]?.[d(896)+d(1764)+d(716)](),this["_pingLos"+d(1653)]?.[d(1139)+"nter"](this[d(529)]["pingLoss"+d(1839)]),this[d(1419)+"osed"]=!1,this[d(1656)]&&e[d(1231)](this[d(1656)].readyState,this[d(845)])?this[d(530)+d(1860)](1e3,e[d(1792)],!0):(this[d(921)]=!0,this[d(1019)]())}}let xp=4294967295;function pp(a,n,s){let d=t;return e[d(1232)](RangeError,e.LPKMJ(e[d(1257)](e[d(401)](e[d(903)](e[d(1338)](d(832)+d(1509)+d(753),a),d(1056)),e[d(1847)](n,1)),e.kDEjJ),s))}function gp(a,n,s){let d=t;if(e[d(1731)](s,xp))throw new Error("integer too large");let f=3;for(;e[d(1374)](f,0);)if(e[d(711)](e[d(1475)],e[d(1475)]))this[d(822)+d(1537)]=0,this[d(1546)+"ndpointT"+d(1541)+"t"]=0;else{let g=e[d(761)](255,s);e.WLmDw(ca,g,a,e[d(1138)](n,f)),s>>>=8,f--}return e.OFtkp(n,4)}function mp(a,n){let s=t,d=0,f=n,g=e[s(466)](n,4);for(;e[s(1584)](f,g);){let{value:m,offset:w}=e[s(1796)](aa,a,f);f=w,d=e[s(1089)](e.fCXUi(d,8),0),d+=m}return{value:d,offset:g}}function wp(a,n,s){let d=t;return a?e.ecVEm(a[d(1675)],40)?e[d(1578)](ia(a,n,s),s):n[d(1066)+"e"]?n[d(1066)+"e"](a,s)+s:n[d(968)]?n.write(a,s)+s:e[d(1816)](ia,a,n,s)+s:s}function _p(a,n){let s=t,d=new ae(e[s(1777)](e[s(726)](e[s(1256)](e[s(1540)](a[e[s(1188)](n,4)],24),e[s(966)](a[n+5],16)),e[s(634)](a[e.KDEkf(n,6)],8)),a[e.wENOc(n,7)]),e[s(377)](a[e.PqoyC(n,0)]<<24,e.lRiRs(a[e[s(1636)](n,1)],16))|a[n+2]<<8|a[e[s(505)](n,3)],!0);return n+=8,{value:d,offset:n+8}}function yp(a,n,s){let d=t,f=a[d(885)],g=a[d(366)];return n[s]=e[d(1641)](g,24),n[e[d(451)](s,1)]=e.NgspR(g,16)&255,n[s+2]=e[d(927)](e.NgspR(g,8),255),n[e[d(1473)](s,3)]=255&g,n[e[d(1605)](s,4)]=e[d(502)](f,24),n[e[d(809)](s,5)]=e[d(1067)](e[d(1443)](f,16),255),n[e.xcWkV(s,6)]=e[d(640)](e[d(487)](f,8),255),n[e[d(1808)](s,7)]=e[d(1282)](255,f),s+=8,s}function aa(a,n){let s=t;return a[s(1185)+"8"]?{value:a[s(1185)+"8"](n),offset:e.NWiTy(n,1)}:{value:e[s(1823)](255,a[n]),offset:e.PqoyC(n,1)}}function ca(a,n,s){let d=t;return n[d(1062)+"t8"]?n[d(1062)+"t8"](a,s):n[s]=e[d(563)](255,a),s+1}let bp=function(a){return new Uint8Array(a)},Ep=typeof Buffer<"u"?Buffer["allocUns"+t(1870)]:hp(bp,Uint8Array[t(1898)+"e"][t(1497)]);(()=>{let a=t,n={QKCZE:function(s,d){return e[q(1076)](s,d)},UJNwY:function(s,d){return e.GzSQH(s,d)},rMQsc:function(s,d){return e[q(927)](s,d)},TuPgc:function(s,d){return e.WYcYv(s,d)},eJEzp:function(s,d){return s|d},RYCzL:function(s,d){return e[q(908)](s,d)},TjTOu:function(s,d){return e[q(1720)](s,d)},QkPRn:function(s,d){return s|d},vcMdm:function(s,d){return e[q(1014)](s,d)},efeZs:function(s,d){return e[q(779)](s,d)},RNJkB:function(s,d){return e[q(1206)](s,d)},yOCxF:function(s,d){return e[q(669)](s,d)},YrpTT:function(s,d){return s&d},CPuWC:function(s,d){return e[q(868)](s,d)},HxzXl:function(s,d){return e[q(1423)](s,d)},FveVg:function(s,d){return s!==d},jRViC:e[a(1542)],QMQbU:function(s,d,f,g){return e[a(1655)](s,d,f,g)},EsBqN:function(s,d){return e[a(871)](s,d)}};if(e.zvQbu(a(365),e[a(1705)]))return(ye[a(840)+"rs"][_0x566ac2]||(ye[a(840)+"rs"][_0x1d8979]=[]))[a(1455)]({fn:_0x29fb0f,ctx:_0x438d4e||ye}),ye;{let s=4294967295;return function(d,f,g=!0){let m=a;if(s=n[m(382)](n[m(1476)](127,d[f]),0),n[m(848)](d[f++],128))return{value:g?s:0|s,offset:f};if(s=n[m(1824)](s,n[m(506)](n[m(1476)](127,d[f]),7))>>>0,n[m(1411)](d[f++],128))return{value:g?s:n[m(900)](0,s),offset:f};if(s=n[m(1824)](s,n[m(506)](n.rMQsc(127,d[f]),14))>>>0,d[f++]<128)return{value:g?s:0|s,offset:f};if(s=n[m(382)](n.vcMdm(s,n[m(1502)](n[m(1476)](127,d[f]),21)),0),n.RNJkB(d[f++],128))return{value:g?s:n[m(1391)](0,s),offset:f};if(s=n[m(1824)](s,n[m(1502)](n[m(1176)](15,d[f]),28))>>>0,n[m(848)](d[f++],128))return{value:g?s:n[m(1403)](0,s),offset:f};if(n[m(1756)](f+=5,d.length))if(n[m(994)](n[m(1642)],n[m(1642)]))_0x434e25+=JOlgRB[m(1350)](_0xe5c8b1,_0x52f61e),_0x55d24c+=2;else throw f=d[m(1675)],n.QMQbU(pp,f,10,d.length);return{value:g?s:n[m(1292)](0,s),offset:f}}}})();let vp=16,da=32;function Sp(a){let n=t,s=0,d={};for(let f=0;e.wPPNc(f,a[n(1675)]);f++)d[a[f]["cursor_n"+n(1435)]]=e[n(1474)](Kd,a[f][n(1644)+n(1435)]),s+=e[n(475)](14,d[a[f]["cursor_n"+n(1435)]]);return[s,d]}function Xd(a,n,s){let d=t,f={spqeo:function(g,m,w,x){return e[q(880)](g,m,w,x)},TFHYj:function(g,m){return e[q(648)](g,m)},peWTX:d(926),GcMQm:e[d(1393)],BOaaA:d(860)+d(1077),ekXPc:d(699)+d(1345),rZuFA:function(g,m,w,x){return g(m,w,x)},YcRXd:function(g,m,w,x){return g(m,w,x)},jgzRD:e[d(1395)],yrfDw:e[d(1124)],CxxTB:e[d(1811)]};if(e[d(1398)]===e[d(1398)]){let[g,m]=Sp(a),w=Ep(g),x=0;return a[d(1694)](T=>{let k=d;if(f[k(818)](f[k(1589)],f[k(1589)]))for(var B in _0x39d215)CSkTNz[k(1251)](_0x77d949,_0x429e2e,B,{get:_0x337755[B],enumerable:!0});else{let J=f.GcMQm[k(1783)]("|"),H=0;for(;;){switch(J[H++]){case"0":console[k(729)](f[k(932)],x);continue;case"1":console[k(729)](f[k(1643)],T,T.service);continue;case"2":x=f[k(1047)](yp,ae[k(649)+"er"](T[k(1026)]||n),w,x);continue;case"3":x=f.spqeo(ca,0,w,x);continue;case"4":x=f[k(400)](gp,w,x,T.service||0);continue;case"5":console.log(k(1077),x);continue;case"6":console[k(729)](f[k(760)],x);continue;case"7":x=wp(T["cursor_n"+k(1435)],w,x);continue;case"8":console.log(f.yrfDw,x);continue;case"9":x=f.spqeo(ca,m[T[k(1644)+"ame"]],w,x);continue;case"10":console[k(729)](f[k(1880)],x);continue}break}}}),{frameType:da,headers:[{key:d(1619)+d(1044),value:s}],payload:w}}else f[d(400)](_0x22608b,this,_0x47f9d0,[_0x332b96,_0x1d358a,_0x135212,_0x4b0468,_0x31b3a0,_0x155344])}function Ip(a){let n=t,s=0,d=[];for(;e[n(1800)](s,a[n(514)+"th"]);){let{offset:f}=e[n(1899)](aa,a,s);s=f;let g={cursor_name:"",cursor:0,service:0},{value:m,offset:w}=mp(a,s);g[n(1818)]=m,s=w;let{value:x,offset:T}=e[n(468)](aa,a,s);s=T,g[n(1644)+n(1435)]=e.XNdkP($d,a,s,e[n(485)](s,x)),s+=x;let{value:k,offset:B}=_p(a,s);g[n(1026)]=k[n(738)](),s=B,d[n(1455)](g)}return d}function Ap(){let a=t;return{frameType:da,headers:[{key:e[a(967)],value:"FILE_NOT"+a(863)}],payload:void 0}}class Tp{constructor(n,s,d){let f=t;this[f(519)+f(550)]=n,this["_cursorF"+f(1301)]=s,this[f(1365)+"Strategy"]=d,this[f(1715)]=e[f(1732)](Jd,this[f(519)+f(550)],e[f(378)])}async[t(1461)](){let n=t;await this[n(1715)][n(1461)]()}async getCursors(){let n=t;if(!this[n(1715)][n(1385)])return;let s=this["_message"+n(981)],d=await this[n(1715)][n(1563)]();switch(console[n(729)](e[n(1820)],d),s){case n(1358):return d&&d.length?Xd(d,0,this._cursorFileName):void 0;case e[n(1051)]:return;case e[n(1726)]:return d&&d[n(1675)]?e[n(1816)](Xd,d,0,this._cursorFileName):e[n(715)](Ap)}}async[t(1133)](n,s,d){let f=t;return console.log(e[f(721)],n,s,d),this[f(1715)].set({cursor_name:n,cursor:s,service:d})}async[t(1165)+"rs"](n){let s=t,d=e[s(420)](Ip,n);for(let f of d)console[s(729)](s(445)+"r",d),await this[s(1715)][s(1133)](f)}async[t(431)](n){let s=t;if(e.eSmSi===e[s(786)]){if(TGTiOi.KRudt(_0x13aa15,_0x74f95f))return TGTiOi[s(1590)](_0x3de95d,_0x2265fc);if(_0x50abb0[s(1680)](_0x4b13e2))return _0x1d70a7[s(431)](_0x239b8b);let d=TGTiOi[s(454)](_0x184803,_0x19a4ef);return TGTiOi[s(997)](d,_0x38c38c)&&(_0x19c3da[s(1133)](_0x45a811,d),_0x25eaa7.set(d,_0x31197f)),d}else return(await this[s(1715)].get(n))?.[s(1026)]}async[t(834)](){let n=t;await this._qosDB[n(834)]()}[t(1102)+t(1747)+"Name"](n){let s=t;this[s(1116)+s(1301)]=n}get isReady(){let n=t;return this[n(1715)][n(1385)]}}let Cp=t(1863)+t(1551);async function Yd(a){let n=t,s={XBBhp:function(w,x){return e[q(1847)](w,x)}};if(!this._options[n(1535)+"S"])return null;let{aID:d,fpID:f,messageStrategy:g}=this[n(529)],m=e[n(1299)](a,Cp);try{if(e[n(604)](e[n(1588)],e[n(1588)])){if(this[n(1770)+n(1776)])if(e.wHTqT!==e.wHTqT){let w="connect "+_0x454fc8+(n(574)+n(518)+n(857)+"ed");this["_dispatc"+n(1287)+n(1198)](e[n(1215)](_0x465477,e[n(719)],{message:w,code:_0x1828fa[n(647)+"IES_ERROR"],error:_0x467b19}));return}else a&&this[n(1770)+n(1776)][n(1102)+n(1747)+n(1336)](a);else this["_cursorM"+n(1776)]=new Tp(f+"_"+d+"_"+m,m,g);return this[n(1770)+n(1776)].isReady||await this[n(1770)+n(1776)][n(1461)](),this["_cursorM"+n(1776)]}else{let w=this[n(1715)][n(1845)](this[n(1160)]),x=_0x399602[n(1279)](iOmUQm[n(1567)](w,"{}"));return x[_0x3584aa||_0x5052fb[this[n(1511)]]]=_0x412180,this[n(1715)].setItem(this._prefix,_0x235afe.stringify(x)),_0x4b8fd5||_0x109dfd[this[n(1511)]]}}catch{return null}}async function Rp(a,n){let s=t,d=e.fNlwk(Qt,a[s(1767)][s(1852)],e[s(874)],"-1"),f=e[s(1816)](Qt,a[s(1767)].headers,e.KxyDB,"1"),g=e[s(890)](Jn,a[s(1767)][s(1852)],e.OuPsl),m=e[s(844)](Number,e[s(869)](Jn,a.message[s(1852)],e.QgyVC))||0,w=oa[s(756)](this,a),x=e.yQvol(Qt,a[s(1767)].headers,e[s(381)],"2"),T=e[s(1396)](Jn,a[s(1767)][s(1852)],e[s(1364)]),k=e[s(427)](Number,e.adPjM(Jn,a.message.headers,s(1446)+s(987)+"ue"));if(w[s(698)])return n();let B=w[s(1061)+s(390)]?await Zd.call(this):null;if(e[s(1334)](a[s(1767)][s(1818)],0)&&f&&!d||e[s(1334)](a[s(1767)][s(1818)],0)){if(g&&w.isQoSMessage&&B)return!!!await B.get(g)&&(this[s(1488)+s(866)+s(1668)](a),await B.set(g,e.VCKlq(Date[s(668)](),m))),e[s(864)](n);if(x)if(e[s(1104)](e[s(426)],e[s(426)])){let J=await Yd[s(756)](this);if(!J)return this[s(1488)+s(866)+"Event"](a),e[s(1242)](n);let H=await J[s(431)](T)??-1;if(e[s(507)](H,k))this[s(1488)+"hMessage"+s(1668)](a),J[s(1133)](T,k,a[s(1767)][s(1818)]);else throw new Error(s(956)+s(1495)+s(1757)+k+(s(1470)+s(1532)+s(375)+"r ")+H);return e.EBCpF(n)}else return null;return this[s(1488)+s(866)+s(1668)](a),n()}}async function Dp(a,n){let s=t,d={gROBH:function(f,g,m){return e[q(1045)](f,g,m)}};if(e[s(997)](s(1008),e[s(1380)]))_0x34ecad(_0x41003e,50),Qufbxb[s(509)](_0x33ca49,_0x31065b,_0x2b7478);else{let f=oa[s(756)](this,a);if(!f[s(1061)+s(390)])return e[s(1197)](n);let g=await Zd[s(756)](this);if(f[s(1582)+"anupMess"+s(1510)]&&f[s(1065)+"s"][s(1675)])for(let m of f.ackMsgIds)await g[s(1032)](m);e[s(1545)](n)}}async function Pp(a,n){let s=t,d=a.message[s(1805)+"e"]===vp,f=e[s(406)](a[s(1767)][s(1805)+"e"],da);if(!d&&!f)return n();let g=e[s(1658)](Jn,a[s(1767)][s(1852)],s(1619)+s(1044));if(!g)return e[s(1197)](n);let m=await Yd[s(756)](this,g);if(!m)return e[s(1545)](n);if(d){let w=await m[s(1645)+"rs"](),x={frameType:w?.[s(1805)+"e"],SeqID:ae[s(649)+"er"](this[s(1873)]++),LogID:ae[s(649)+"er"](this[s(529)][s(1137)+s(1436)]()),service:9e3,method:5,headers:w?.headers,payload:w?.[s(1681)]},T=e[s(1833)](A,x);this[s(1656)]&&this[s(1656)][s(1763)+"te"]&&this[s(1656)][s(528)](T)}if(f){let w=a[s(1767)][s(1681)];w&&m[s(1165)+"rs"](w)}}let kp=async function(a,n){let s=t;e.lNVvE(e.hrDoT,e[s(1810)])?this.emit(e[s(1700)],e.zYzhU(_0xd30ab0,"close",{..._0x2e087b})):(this._isInit=!1,clearTimeout(this[s(1019)+s(1533)+s(1433)]),e[s(581)](n))},Op=async function(a,n){let s=t,d={HvIsb:function(m,w){return m(w)},OllnH:function(m,w){return e[q(1894)](m,w)},mNsAo:e.yUHiN,xNIrG:s(1273)};if(!this[s(1656)]||e.pLEOt(this[s(1656)].readyState,this[s(1528)]))return e[s(581)](n);let{pingInterval:f}=this[s(529)];this[s(1594)+"tManager"]?.[s(896)+s(1764)+s(716)]();for(let m=0;e[s(1011)](m,this[s(1365)+s(460)][s(1675)]);m++)if(e[s(1501)](e[s(1628)],e[s(831)])){let w=_0x19a067[s(1783)](/\./)[s(769)](k=>_0x41b7af(k)),x=[];return x[0]=lypZTX[s(1148)](_0x565012,lypZTX[s(910)](w[0],w[1])),x[1]=_0x2bdfc4(w[2]+w[3]),[lypZTX[s(1600)],s(1543),lypZTX.mNsAo,lypZTX[s(1600)],s(1543),lypZTX.xNIrG,x[0],x[1]][s(1460)]("")}else{let w=this[s(1365)+s(460)][m];if(e[s(1104)](this[s(1656)].readyState,this.OPEN)&&e[s(711)](null,w))if(e[s(1158)]===e[s(1158)])this[s(1656)]&&this._ws[s(528)](w),this[s(1365)+s(460)][m]=null;else return this._isMiniTT||this._isMiniWX?this["_miniNav"+s(1155)+s(554)]:(this._isBrowser||this._isWorker)&&this._options[s(1226)+s(1309)+s(1456)]?_0x259ca9[s(1260)]:!0;else break}this[s(1365)+s(460)]=this[s(1365)+s(460)][s(948)](m=>!!m),this[s(1444)+s(1744)+"Id"]=e[s(1547)](setTimeout,()=>this[s(1549)](),f),this[s(1488)+s(1892)+"nt"](a),this._isBrowser&&this._ws&&(this[s(1656)].binaryType=this[s(1699)+s(1052)]);let g=this[s(1594)+"tManager"]?.[s(1053)+s(1836)+"nt"]();this._debug(s(1150)+g+s(1827)),n()},Np=async function(a,n){let s=t,d=this[s(1594)+"tManager"]?.[s(1053)+s(1836)+"nt"]();this[s(440)]("open "+d),e[s(483)](n)};class Lp extends ra{constructor(n){let s=t,d={sxyWG:function(w,x,T){return e[q(1262)](w,x,T)},pAvPY:e[s(719)],nWyiC:function(w,x){return w||x},xYUoF:function(w,x){return e.zYiDt(w,x)},fzEbY:function(w,x){return e[s(739)](w,x)},QmhkF:function(w,x){return e[s(739)](w,x)},KyhQE:e[s(1440)],XtaWo:function(w,x){return e[s(1632)](w,x)},mmRAP:s(1126),AiEwP:s(1583)+s(1520)+"s",NiYzy:e[s(829)],TRNuH:function(w,x,T){return w(x,T)},QtlaQ:function(w,x){return e[s(1214)](w,x)},OUUHO:e.sVNmi,HobTr:function(w,x){return e[s(1867)](w,x)},sOcUj:function(w,x,T,k){return e[s(836)](w,x,T,k)},PsvJS:function(w,x){return e[s(1684)](w,x)}};super(),this["_miniNav"+s(1155)+s(554)]=!0,this[s(1284)+"er"]=Vn,this[s(1529)]=Xx,this[s(919)+"T"]=vn,this[s(1025)+"X"]=qr,this._isWorker=jr,this[s(1365)+s(460)]=[],this[s(1594)+s(933)]=null,this[s(1419)+s(577)]=!1,this[s(1699)+s(1052)]=e.SSzaM,this["_connect"+s(823)]=!1,this[s(1019)+"ionTimeo"+s(1433)]=null,this[s(1761)+s(1172)+s(1754)]=null,this[s(1444)+s(1744)+"Id"]=null,this[s(1873)]=0,this[s(921)]=!1,this._url="",this[s(1159)+s(480)]=null,this[s(1770)+s(1776)]=null,this["_pingLos"+s(1653)]=null,this._protocols=s(846),this[s(845)]=3,this[s(1646)+"NG"]=0,this[s(1528)]=1,this[s(995)]=2,this[s(607)]=w=>{let x=s;try{Wd(this,w,[kp,Op,Np])}catch(T){let k=d[x(459)](it,d.pAvPY,{message:T.message,code:Yt[x(1305)+"OR"],error:T});this[x(1488)+x(1287)+x(1198)](k)}},this[s(1283)+"ge"]=async w=>{let x=s,T={MEMJY:function(J,H){return d[q(1381)](J,H)}},{pingInterval:k,pingFrequency:B}=this[x(529)];if(d[x(1552)]("hi",w[x(1238)])&&d[x(1091)](x(1085),B)||d.QmhkF(d[x(1799)],B))if(d.XtaWo(x(893),d[x(1453)])){let J=this[x(1715)][x(591)+x(837)+"nc"](this._prefix),H=_0x75b8f0[x(1279)](oLkjdP[x(1631)](J,"{}"));return _0x595fd9[x(465)](H)}else this[x(1891)+x(1868)](),this[x(915)](d[x(583)],d.NiYzy),this[x(1444)+x(1744)+"Id"]=d[x(587)](setTimeout,this[x(1549)][x(1814)](this),k);if(!d[x(1552)]("hi",w[x(1238)]))try{Wd(this,w,[fp,lp,Dp,Pp,Rp,up])}catch(J){let H=d.sxyWG(it,d[x(566)],{message:J[x(1767)],code:Yt[x(1003)+x(1738)],error:J});this["_dispatc"+x(1287)+x(1198)](H)}},this[s(1418)]=w=>{let x=s,T=this[x(1594)+"tManager"]?.[x(706)+x(1671)+"es"](),k=this[x(1594)+x(933)]?.[x(1053)+x(1836)+"nt"]();if(T&&!w.message){let B=x(656)+k+(x(574)+x(518)+x(857)+"ed");this[x(1488)+x(1287)+x(1198)](e[x(890)](it,x(1864),{message:B,code:Yt[x(647)+x(1487)+"R"],error:w}));return}this[x(1656)]&&e[x(1094)](this[x(1656)][x(1763)+"te"],this[x(1528)])&&this[x(530)+x(1860)](),this[x(1488)+x(1287)+x(1198)](e.tLfkV(it,e.FPXyL,{message:w[x(1767)],code:Yt[x(1415)+x(404)],error:w}))},this._onClose=async w=>{let x=s;this[x(1143)+"mer"](),this["_clearPi"+x(1868)](),this["_removeW"+x(841)+"rs"](),this[x(1656)]=null,this[x(1019)+x(823)]=!1;let T=this["_endpoin"+x(933)]?.["checkRea"+x(1671)+"es"]();if(!T&&this["_navigat"+x(1128)]()&&!this[x(1419)+x(577)]){let k=this[x(1594)+x(933)]?.[x(1053)+"ntEndpoint"](),B=this[x(529)][x(754)+x(1748)+x(1486)](w[x(1489)],w[x(678)]);this[x(1488)+x(1613)+x(1198)](e[x(1565)](ut,e[x(1700)],{code:1006,reason:w[x(678)]||"connecti"+x(665)+x(1897)+x(979)+"n, hostn"+x(939)+k,willReconnect:B})),B&&this[x(1019)]();return}if(e[x(997)](1e3,w.code)&&this[x(1419)+x(577)])if(e[x(747)]===e[x(747)]){this[x(1488)+"hCloseEv"+x(1198)](e[x(694)](ut,e[x(1700)],{code:1e3,reason:e[x(1609)]})),this[x(1594)+x(933)]?.[x(896)+x(1764)+x(716)](),this._pingLossCounter?.[x(1139)+"nter"]();return}else{if(CImSab[x(409)](CImSab.OUUHO,typeof _0x4f4d04)){let k=new _0x26cb14(CImSab[x(484)](_0x4d0cdc,_0x3949cb));return CImSab.sOcUj(_0x3545c2,_0x2f9062,k,0),k}return CImSab.PsvJS(_0x372e1f,_0x411761)?new _0x65fd16(_0x54fded):new _0x48be89(_0x64de75[x(725)],_0x2b573f[x(751)+"et"],_0x43cdbe[x(514)+"th"])}if(e[x(408)](1e3,w[x(1489)])&&T){let k=this[x(1594)+"tManager"]?.[x(1053)+x(1836)+"nt"](),B=w[x(678)];B||(B=await e[x(749)](ip,this[x(1454)])),B=x(513)+"ng faile"+x(633)+B+", hostname: "+k+(x(1417)+x(1016)+"ached"),this[x(1488)+x(1613)+x(1198)](e[x(1101)](ut,e[x(1700)],{code:w.code,reason:B}));let J="connect "+k+(" fail, m"+x(518)+x(857)+"ed");this["_dispatc"+x(1287)+x(1198)](e.adPjM(it,e[x(719)],{message:J,code:Yt[x(647)+x(1487)+"R"]})),this[x(1594)+x(933)]?.[x(896)+"pointCon"+x(716)](),this[x(1821)+x(1653)]?.[x(1139)+x(695)]();return}if(e[x(408)](1e3,w[x(1489)])&&!w[x(678)])if(e.EveUt(e[x(1710)],e[x(1710)])){let k=this[x(1594)+x(933)]?.[x(1053)+x(1836)+"nt"]();this[x(1488)+x(1613)+x(1198)](e[x(642)](ut,e.bKxQQ,{code:w.code,reason:"connecti"+x(665)+"d, unkno"+x(979)+x(971)+x(939)+k})),this[x(1594)+"tManager"]?.[x(896)+"pointCon"+x(716)](),this[x(1821)+x(1653)]?.[x(1139)+x(695)]();return}else return _0x236149[x(1363)]||_0x11ebdc[x(477)]?("message: "+(_0x5b8d64[x(1363)]||"")+" code: "+(_0x2e1383[x(477)]||"")).trim():_0x352cbb[x(758)+"y"](_0x2ecf2f);this[x(1488)+x(1613)+x(1198)](w),this[x(1594)+"tManager"]?.[x(896)+x(1764)+x(716)](),this["_pingLos"+x(1653)]?.[x(1139)+x(695)]()},this[s(535)]=null,this.onerror=null,this.onmessage=null,this[s(891)]=null,this[s(497)+"econnect"]=null,this[s(947)+"eAck"]=null,this[s(429)+s(901)+s(806)+"ct"]=null,this[s(1194)+s(1222)]=this["_handleO"+s(1222)][s(1814)](this),this[s(1194)+s(456)]=this._handleOffLine.bind(this),this[s(1316)+s(1265)]=this["_handleP"+s(1265)][s(1814)](this),this._handlePageShow=this[s(1316)+"ageShow"][s(1814)](this),this._options={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(1858)](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(936),pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(1726)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:g}=n,m=Array[s(1114)](f)?f:s(1290)==typeof f?[f]:[];if(!m||e[s(1657)](0,m[s(1675)]))throw new Error(s(794)+s(1144)+"alid url");if(!ep(g))throw new Error(e[s(1872)]);Object.assign(this[s(529)],n),this[s(1594)+"tManager"]=new Hd(m,this._options.maxRetries),this[s(1821)+s(1653)]=new rp(this[s(529)][s(1209)+s(1839)]),this[s(529)][s(436)+s(428)]&&(this._isInit=!0,this[s(1019)]()),this[s(529)][s(1226)+s(1309)+s(1456)]&&(this[s(919)+"T"]||this[s(1025)+"X"]?this[s(1333)+s(1758)+s(1093)]():this[s(1284)+"er"]&&this["_initGlo"+s(469)+s(1255)]())}[t(1194)+"nLine"](){let n=t;this[n(529)]["disableA"+n(641)+n(1458)]||this[n(1419)+n(577)]||this[n(417)+n(446)]()}[t(1194)+"ffLine"](){let n=t;this[n(1560)+"WebSocket"]();let s=e.GnRaY(na,e[n(781)],{message:e[n(1781)]});this["onStopIm"+n(901)+"yReconnect"]&&this[n(429)+"mediatelyReconnect"](s)}[t(1193)+t(469)+t(1255)](){let n=t;this[n(1284)+"er"]&&window["addEvent"+n(1255)](e[n(1531)],this[n(1194)+n(1222)]),this[n(1284)+"er"]&&window[n(1617)+n(1255)](e[n(895)],this[n(1194)+n(456)]),this._isBrowser&&window.addEventListener(e[n(1352)],this["_handleP"+n(1265)]),this._isBrowser&&window["addEvent"+n(1255)](e[n(1349)],this[n(1316)+n(422)])}[t(1090)+t(469)+t(1255)](){let n=t;this[n(1284)+"er"]&&window[n(611)+n(508)+n(614)](e.EMuBC,this[n(1194)+n(1222)]),this._isBrowser&&window[n(611)+n(508)+n(614)](e[n(895)],this[n(1194)+n(456)]),this[n(1284)+"er"]&&window["removeEv"+n(508)+n(614)](n(1803),this[n(1316)+n(1265)]),this[n(1284)+"er"]&&window[n(611)+n(508)+n(614)]("pageshow",this[n(1316)+n(422)])}[t(1316)+t(1265)](n){let s=t;e.BceUV(s(1371),e.TjYiM)?(this["_dispatchMessage"+s(1668)](_0x24c9fc),_0x2cb712.set(_0x282070,_0x2bbcf4,_0x400d8e[s(1767)].service)):(!n.persisted&&(this[s(1284)+"er"]&&window[s(611)+s(508)+s(614)](e[s(1352)],this[s(1316)+s(1265)]),this[s(1284)+"er"]&&window[s(611)+s(508)+s(614)](s(1693),this[s(1316)+s(422)]),this.close()),this._isBrowser&&window["removeEventListe"+s(614)](e[s(1531)],this[s(1194)+"nLine"]),this[s(1284)+"er"]&&window[s(611)+s(508)+"ner"](e[s(895)],this[s(1194)+s(456)]))}[t(1316)+"ageShow"](n){let s=t;n[s(536)+"d"]&&(this["_navigat"+s(1128)]()&&(!this._ws||e.hVyQp(this[s(1656)][s(1763)+"te"],this[s(1528)])||e[s(867)](this[s(1656)][s(1763)+"te"],this[s(1646)+"NG"]))&&this[s(1194)+s(1222)](),this[s(1284)+"er"]&&window[s(1617)+s(1255)](e[s(1531)],this[s(1194)+s(1222)]),this[s(1284)+"er"]&&window[s(1617)+s(1255)](s(998),this[s(1194)+"ffLine"]))}async[t(474)+"eUrl"](n){let s=t,{fpID:d,deviceID:f,bddID:g,ttwID:m,accessKey:w,aID:x,customParams:T={},enableAutoAck:k,enableQoS:B,QoSLevel:J,env:H}=this._options,de,Et,vt;this[s(1284)+"er"]||this[s(1025)+"X"]||this[s(919)+"T"]?(de=location&&e[s(1321)](e.JjzGy,location[s(808)])?e.voIPJ:e.bmoEW,Et=n[s(1615)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),vt=/^wss(.*:\/\/)/[s(838)](n)?n:""+de+Et):(de=e[s(1361)],Et=n[s(1615)](/(^http)((?:[s]*:\/\/))/,""),vt=/(^ws)((?:[s]*:\/\/))/.test(Et)?Et:""+de+Et);let Qd=g?e[s(1303)]:m?e[s(1463)]:s(683)+"d",el=g||m||f;if(e[s(1620)](!el,!Qd))throw new Error(e[s(1216)]);let Mp=e[s(787)](s(1175),typeof T)?await e[s(1545)](T):T,Bp=H?e[s(510)](np,H[s(1534)],H[s(898)]):{},la=Object[s(969)]({device_platform:e[s(449)],version_code:e[s(798)],access_key:w,fpid:d,aid:x,[Qd]:el,xsack:k?1:0,xaack:k?1:0,xsqos:B?1:0,qos_level:B?J:void 0,qos_sdk_version:2,...Bp},Mp),zp=Object[s(465)](la)[s(1772)]((ua,fa)=>la[fa]!==void 0?""+ua+(ua?"&":"?")+fa+"="+la[fa]:ua,"");return vt+s(1314)+zp}async[t(1019)](){let n=t,s={hUnrK:function(d,f){return d|f},QoTMd:function(d,f){return d|f},KEnyf:e[n(1145)],KiXcj:function(d,f){return d(f)}};if(e[n(648)](e.qdDOS,n(432)))this[n(1554)]=!0,this.low=EFnSPk[n(368)](0,_0x526ee),this[n(366)]=EFnSPk.QoTMd(0,_0x95812f),this[n(1740)]=!!_0x33b72a;else{if(this[n(1019)+"Lock"]||this[n(1419)+n(577)])return;this._connectLock=!0;try{let d=this["_endpoin"+n(933)]?.[n(631)+n(886)+n(1840)+"hedMaxRe"+n(988)](),{timeoutInterval:f}=this[n(529)];if(d)if(e.LRqiC!=="npGpf"){let m=_0x36255c[n(1169)];if(m+_0x320147>_0x43ee19[n(800)])throw new _0x35aa71(EFnSPk[n(1883)]);return _0x59d982[n(1169)]+=_0x2f7d54,m}else{let m=this[n(1594)+n(933)]?.["getCurre"+n(1836)+"nt"](),w=this["_endpoin"+n(933)]?.[n(1437)+n(914)+n(1607)+n(1626)+n(1442)](),x=this[n(1594)+n(933)]?.["getCurre"+n(1836)+n(884)+n(1879)]();if(w)if(e[n(997)](e.EiCtr,e[n(572)])){let T=n(656)+m+(" timeout"+n(1417)+n(1016)+"ached, will use "+n(1079)+n(598))+w+(n(1272)+"y"),k=it(e[n(719)],{message:T,code:Yt[n(647)+n(1487)+"R"]});this[n(440)](T),this[n(1488)+n(1287)+n(1198)](k),this[n(1454)]=await this[n(474)+"eUrl"](w),this[n(440)](n(656)+w+" "+x+" times"),this[n(1152)+"sListeners"]()}else _0x3ab924.log(_0x25f5c2);else if(e[n(471)]===e[n(471)]){let T=n(656)+m+(n(1462)+n(1417)+n(1016)+n(386));this[n(440)](T),this[n(1488)+n(1287)+n(1198)](e[n(1828)](it,e[n(719)],{message:T,code:Yt["MAX_RETR"+n(1487)+"R"]}));return}else return e.WmUgC(0,this[n(366)])&&this[n(885)]===0}else{if(e[n(1842)]===e.rqUmv)return _0x37968e[n(1472)](EFnSPk[n(1802)](_0x1cd502,this),_0x5038a0),EFnSPk[n(1802)](_0x33f272,_0x59d313[n(431)](this));{let m=this[n(1594)+"tManager"]?.[n(1053)+n(1836)+"ntAndUpd"+n(1859)](),w=this[n(1594)+"tManager"]?.[n(1053)+n(1836)+n(884)+n(1879)]();this[n(1454)]=await this["_generat"+n(1146)](e[n(1299)](m,"")),this[n(440)](n(656)+m+" "+w+n(1357)),this._removeWsListeners()}}if(this[n(921)])this._isInit=!1;else{let m=e.lJlSj(na,e[n(781)],{message:e.WnQKC});this[n(497)+n(446)]&&this.onStartReconnect(m)}let g=this[n(1594)+n(933)]?.[n(1053)+n(1836)+n(884)+n(1879)]()||0;e[n(877)](g,1)&&await this[n(776)](e.yFghr(g,1)),this[n(440)](n(513)+n(1788)+this._url+(n(862)+n(1376))+this._protocols),this[n(1656)]=e[n(843)](Qx,{url:this[n(1454)],protocols:[this[n(1168)+"ls"]],headers:this[n(529)][n(651)+n(1685)+"s"][n(1154)+"tpHeader"]},this._options.ws),(this[n(1284)+"er"]||this[n(1388)+"r"])&&this[n(1656)]&&(this[n(1656)][n(918)+"pe"]=this[n(1699)+n(1052)]),this[n(755)+n(1022)](),this[n(1019)+n(1533)+n(1433)]=e.lKMSm(setTimeout,this[n(1441)+"ut"][n(1814)](this),f)}catch(d){throw this[n(1019)+n(823)]=!1,d}}}[t(1143)+t(1009)](){let n=t;e[n(499)](clearTimeout,this["_connect"+n(1533)+n(1433)]),this["_connectionTimeo"+n(1433)]=null}[t(1891)+t(1868)](){let n=t;e[n(1867)](clearTimeout,this["_pingPon"+n(1744)+"Id"]),e[n(983)](clearTimeout,this[n(1761)+"ctTimeoutId"]),this[n(1444)+n(1744)+"Id"]=null,this[n(1761)+n(1172)+n(1754)]=null}_debug(...n){let s=t;this._options.debug&&console.log[s(1472)](console,[e.FtMIC,...n])}[t(1217)+t(906)+"e"](n){let s=t,{initReconnectInterval:d,maxReconnectInterval:f,reconnectIntervalGrowFactor:g}=this._options,m=e[s(1477)](d,Math.pow(g,e[s(928)](n,1)));return e[s(877)](m,f)?f:m}[t(1549)](){let n=t;if(this._ws&&e[n(1234)](this._ws.readyState,this[n(1646)+"NG"])){this[n(1891)+n(1868)](),this[n(1444)+n(1744)+"Id"]=setTimeout(this[n(1549)].bind(this),this._options[n(1125)+n(1888)]);return}if(!this[n(1656)]||this._ws[n(1763)+"te"]!==this.OPEN)return void this["_handleR"+n(446)]();this[n(1656)]&&this[n(1656)].send("hi"),this["_reconnectTimeou"+n(1754)]=e[n(935)](setTimeout,this[n(417)+n(446)+"Timeout"][n(1814)](this),this[n(529)][n(865)+n(958)+n(1397)])}[t(417)+t(446)+t(405)](){let n=t;if(e[n(741)](e[n(1550)],e[n(542)]))this[n(1821)+n(1653)]?.[n(1429)](),this[n(915)](e[n(1084)],e.fOXSA),this._pingLossCounter?.["checkRea"+n(1329)+"nt"]()?this[n(417)+n(446)]():this[n(1549)]();else{let s=this[n(1715)][n(1845)](this[n(1160)]);return _0x39024c[n(1279)](e[n(492)](s,"{}"))[_0x1b8135]}}["_navigat"+t(1128)](){let n=t,s={nRxvg:e[n(378)]};if(e[n(1634)](e.kVQaa,e[n(1687)]))this[n(519)+n(550)]=_0x4714ff,this[n(1116)+n(1301)]=_0x270b25,this[n(1365)+n(981)]=_0x23259e,this[n(1715)]=_0x2cf0bb(this[n(519)+"ameSpace"],oiqUFe[n(937)]);else return this[n(919)+"T"]||this._isMiniWX?this[n(537)+n(1155)+"line"]:(this[n(1284)+"er"]||this[n(1388)+"r"])&&this[n(529)][n(1226)+n(1309)+n(1456)]?navigator[n(1260)]:!0}[t(417)+"econnect"](){let n=t;!this["_navigat"+n(1128)]()||this[n(1419)+n(577)]||(this[n(1594)+n(933)]?.[n(896)+n(1764)+n(716)](),this[n(1821)+n(1653)]?.[n(1139)+n(695)](),this[n(1656)]?this[n(530)+n(1860)](1001,e[n(1110)],!0):this[n(1019)]())}[t(1333)+t(1758)+"ange"](){let n=t,s={ehyBq:e[n(807)],weuji:function(d){return e[n(658)](d)},nJcxl:function(d,f){return e[n(1893)](d,f)},OzuuC:e[n(1753)]};this[n(919)+"T"]?tt[n(373)+"kStatusC"+n(1670)](({isConnected:d})=>{let f=n;this[f(537)+f(1155)+"line"]=d,d?this[f(1194)+f(1222)]():this[f(1194)+"ffLine"]()}):this[n(1025)+"X"]&&wx[n(373)+"kStatusChange"](({isConnected:d})=>{let f=n,g={jZVDK:s[f(736)],GAfqI:function(m){return s.weuji(m)}};s.nJcxl(s[f(1356)],s[f(1356)])?(this._miniNavigatorOnline=d,d?this[f(1194)+f(1222)]():this[f(1194)+f(456)]()):(this._debug(BCzagT[f(1774)],_0x96ac73[f(1767)]),BCzagT.GAfqI(_0xbadd08))})}[t(776)](n){return new Promise(s=>{let d=q;e[d(970)](setTimeout,s,this[d(1217)+"rvalValue"](n))})}["_disconn"+t(1860)](n=1e3,s="",d=!1){let f=t;this._ws&&this[f(1560)+f(1574)+"t"](n,s,d)}[t(1441)+"ut"](){let n=t,s=this[n(1594)+n(933)]?.[n(1053)+n(1836)+"nt"]();this._debug("connect "+s+" timeout"),this[n(530)+n(1860)](1001,e[n(1227)],!0)}_sendAck(n){let s=t,d={owWrr:function(g,m){return e.bmGhT(g,m)},yLTth:function(g,m){return e.fCXUi(g,m)},vZSHI:function(g,m){return e[q(640)](g,m)},njdRr:function(g,m){return e[q(759)](g,m)},oqnPz:function(g,m){return e.RRDGA(g,m)},CzCDR:function(g,m){return e.CfNPe(g,m)},tXPed:function(g,m){return g&m},lqHCK:function(g,m){return e[q(1865)](g,m)}},f=e[s(911)](Bt,n);this[s(1656)]&&e[s(728)](this[s(1656)][s(1763)+"te"],this[s(1528)])&&(e.GDdFL(e[s(493)],e[s(493)])?(_0x39fe70=htgzwf[s(1576)](_0x3fc144,_0x56d009),_0x51f0fa|=htgzwf.yLTth(htgzwf[s(811)](127,_0x5615dd),14),128&_0x34ec1a&&(_0xa909c8=_0x297691(_0x30b279),_0x375f59|=htgzwf[s(1689)](htgzwf[s(1844)](127,_0x3c27fc),21),htgzwf[s(1677)](128,_0x19c39d)&&(_0x33a7d0=_0x4c1dd3(_0x1ed502),_0x2a3c61=127&_0x36f3da,htgzwf[s(1526)](128,_0x580cf2)&&(_0x1e6913=_0x2e232e(_0x5a8817),_0x19ddef|=htgzwf.lqHCK(127,_0x1b8b8d)<<7)))):(this[s(1656)]&&this[s(1656)][s(528)](f),this[s(440)](e.djOLA,n)))}[t(1152)+t(841)+"rs"](){let n=t;if(e[n(1627)](e.rAhJj,e[n(586)])){if(!this[n(1656)])return;this[n(1656)][n(611)+n(508)+"ner"](e[n(1649)],this[n(607)]),this[n(1656)][n(611)+n(508)+n(614)]("close",this._onClose),this[n(1656)][n(611)+n(508)+n(614)](n(1767),this[n(1283)+"ge"]),this[n(1656)][n(611)+n(508)+n(614)](e.FPXyL,this._onError)}else return}[t(755)+t(1022)](){let n=t,s=e[n(1825)][n(1783)]("|"),d=0;for(;;){switch(s[d++]){case"0":if(!this._ws)return;continue;case"1":this[n(1656)][n(1617)+n(1255)](e.bKxQQ,this[n(1690)]);continue;case"2":this[n(1656)][n(1617)+n(1255)](e[n(1649)],this[n(607)]);continue;case"3":this[n(1656)][n(1617)+n(1255)](e[n(719)],this[n(1418)]);continue;case"4":this[n(1656)][n(1617)+n(1255)](e[n(925)],this[n(1283)+"ge"]);continue}break}}[t(962)+t(1409)](n=1e3,s=""){let d=t;try{this._ws&&this[d(1656)].close(n,s)}catch{}}[t(1560)+t(1574)+"t"](n=1e3,s="",d=!1){let f=t;if(this[f(1891)+f(1868)](),this[f(1143)+f(1009)](),this[f(1152)+f(841)+"rs"](),this[f(962)+f(1409)](1e3,s),this[f(1019)+f(823)]=!1,d&&this[f(1092)+"orOnline"]()&&!this["_readyCl"+f(577)]){if(this[f(1594)+f(933)]?.["checkRea"+f(1671)+"es"]())if(e[f(1276)]!==e[f(1276)]){let m=this[f(1594)+f(933)]?.[f(706)+f(1671)+"es"](),w=this[f(1594)+"tManager"]?.[f(1053)+f(1836)+"nt"]();if(m&&!_0x46eb36.message){let x=f(656)+w+(f(574)+f(518)+f(857)+"ed");this[f(1488)+f(1287)+f(1198)](e.nXTUo(_0x14e6c8,e[f(719)],{message:x,code:_0x765a80[f(647)+f(1487)+"R"],error:_0x4a3670}));return}this[f(1656)]&&e.ErhfR(this[f(1656)][f(1763)+"te"],this[f(1528)])&&this["_disconn"+f(1860)](),this[f(1488)+f(1287)+f(1198)](e[f(684)](_0x1f2f8e,e[f(719)],{message:_0x18b5b7[f(1767)],code:_0x4fd7bb["NATIVE_E"+f(404)],error:_0x38a072}))}else{let m=this[f(1594)+"tManager"]?.[f(1053)+f(1836)+"nt"]();this[f(1488)+"hCloseEv"+f(1198)](ut("close",{code:1006,reason:"connect "+m+(f(1462)+f(1417)+f(1016)+f(386)),wasClean:!0}))}else if(e.zvQbu("tbWnN",e[f(369)])){let m=this[f(529)][f(754)+f(1748)+f(1486)](n,s);this[f(1488)+f(1613)+f(1198)](e.ftfxn(ut,e[f(1700)],{code:n,reason:s,wasClean:!0,willReconnect:m})),m&&this[f(1019)]()}else return this._qosDB?.[f(1032)](_0x20d320);return}this["_navigat"+f(1128)]()||this[f(1419)+f(577)]?this[f(1488)+f(1613)+f(1198)](e[f(1262)](ut,f(1306),{code:n,reason:e[f(1609)]})):this[f(1488)+"hCloseEv"+f(1198)](e[f(1899)](ut,e.bKxQQ,{code:1006,reason:e[f(462)]})),this._ws=null,this[f(1594)+f(933)]?.[f(896)+f(1764)+"fig"](),this[f(1821)+f(1653)]?.["resetCou"+f(695)]()}[t(1488)+t(1892)+"nt"](n){let s=t;this[s(915)](e[s(1649)],n),this.onopen&&this[s(891)](n)}[t(1488)+t(866)+t(1668)](n){let s=t;this.emit(e[s(925)],n),this[s(872)+"e"]&&this[s(872)+"e"](n)}[t(1488)+t(1071)+t(732)](n){let s=t;if(e[s(1245)](e[s(819)],s(965)))this[s(915)](s(1322),n),this[s(947)+s(1512)]&&this[s(947)+"eAck"](n);else{let d={Oxony:e.DXXYL,VBAaQ:function(x,T,k,B){return e[s(1822)](x,T,k,B)},ygCRI:e[s(701)],ZDSuo:e[s(1174)],mjdFB:e[s(1811)],arFkL:e[s(1124)]},[f,g]=e[s(1285)](_0x27a061,_0xa98573),m=e[s(1147)](_0x26a36c,f),w=0;return _0x10596c[s(1694)](x=>{let T=s,k=d[T(414)].split("|"),B=0;for(;;){switch(k[B++]){case"0":w=_0x1e4f03(m,w,x.service||0);continue;case"1":w=d[T(1406)](_0x36a2b2,g[x[T(1644)+"ame"]],m,w);continue;case"2":_0x9acee4[T(729)](T(1818),w);continue;case"3":_0x3b81b1[T(729)](d[T(772)],x,x[T(1818)]);continue;case"4":_0x2decbb[T(729)](d[T(1595)],w);continue;case"5":_0x7758b6[T(729)](T(1077),w);continue;case"6":w=d[T(1406)](_0x1c4fef,0,m,w);continue;case"7":w=_0x3a17d1(x[T(1644)+"ame"],m,w);continue;case"8":_0x180685[T(729)](d[T(876)],w);continue;case"9":w=d[T(1406)](_0x43fed2,_0x3229d5[T(649)+"er"](x[T(1026)]||_0x3ce05c),m,w);continue;case"10":_0x20d660[T(729)](d.arFkL,w);continue}break}}),{frameType:_0x4088c6,headers:[{key:e.AdWVB,value:_0x4efe22}],payload:m}}}[t(1488)+t(1287)+t(1198)](n){let s=t;this[s(915)](e[s(719)],n),this[s(1270)]&&this[s(1270)](n)}[t(1488)+"hCloseEv"+t(1198)](n){let s=t;this[s(915)](e.bKxQQ,n),this.onclose&&this[s(535)](n)}get[t(918)+"pe"](){let n=t;return this[n(1656)]?this[n(1656)][n(918)+"pe"]:this["_binaryT"+n(1052)]}set binaryType(n){let s=t;this[s(1699)+s(1052)]=n,this[s(1656)]&&(this[s(1656)][s(918)+"pe"]=n)}get[t(622)+"nt"](){let n=t;return this._endpointManager?.[n(1053)+n(1836)+n(884)+n(1879)]()||0}get[t(1878)+t(909)](){let n=t;return this[n(1365)+n(460)][n(1772)]((d,f)=>(d+=f&&f.byteLength||0,d),0)+(this[n(1656)]?this._ws[n(1878)+n(909)]:0)}get[t(636)+"ns"](){let n=t;if(e[n(974)](n(1707),e[n(1328)])){let s=0,d=0,f;do f=e[n(1266)](_0x29ef0f,_0x44fa07),s<32&&(d|=e[n(567)](e[n(1325)](127,f),s)),s+=7;while(e[n(1420)](128,f));return d}else return this[n(1656)]?this._ws.extensions:""}get protocol(){let n=t;if(n(1735)!==e[n(1170)]){let s=e.tLfkV(_0x360505,"error",{message:this[n(603)+n(1177)+n(1510)](_0x3f7dda)});this[n(915)](e[n(719)],s);let d=e.AGAll(_0xa9d693,e[n(1700)],{reason:this[n(603)+n(1177)+"age"](_0x5898e3)});this[n(915)](n(1306),d)}else return this[n(1656)]?this._ws.protocol:""}get[t(1763)+"te"](){let n=t;if(e[n(833)](e.qiTMS,e[n(494)]))_0x33cb46=n(1034),_0x5f1bf1=_0x3727c1[n(1615)](/(^http)((?:[s]*:\/\/))/,""),_0x51e367=/(^ws)((?:[s]*:\/\/))/[n(838)](_0x342678)?_0x52545f:""+_0x5e1f03+_0x158b30;else return this[n(1656)]?this[n(1656)][n(1763)+"te"]:this[n(529)][n(436)+n(428)]?this[n(1646)+"NG"]:this[n(845)]}get[t(1313)](){let n=t,s={yLxUh:"8|6|7|2|"+n(1522)+"|10|3|0|4",NvLPT:function(d,f){return d>f},Athvt:function(d,f,g,m){return d(f,g,m)},uqmms:function(d,f){return e[n(1142)](d,f)},YneLl:function(d,f){return d|f},AuDIK:function(d,f){return d<f},wCxxf:function(d,f){return d|f},WfZjz:function(d,f){return e[n(1167)](d,f)},YpfZC:function(d,f){return e[n(1641)](d,f)},XSQlS:function(d,f){return e[n(1889)](d,f)},nefHe:function(d,f){return e[n(870)](d,f)},xmXOQ:function(d,f){return e.FgjOw(d,f)},uRQsC:function(d,f){return e[n(1308)](d,f)},rPtXC:function(d,f){return e.qTecU(d,f)},eWSxY:function(d,f){return e.lRiRs(d,f)},tUDiZ:function(d,f){return e[n(1709)](d,f)},KzlQh:function(d,f){return e[n(1765)](d,f)},gvmvF:function(d,f){return d<<f}};if(e.GDdFL(e[n(1465)],e.zRmdC)){let d=s.yLxUh[n(1783)]("|"),f=0;for(;;){switch(d[f++]){case"0":if(QdsyNf[n(520)](_0x4119e4+=5,_0x2918f8.length))throw _0x334f72=_0x1c7bdf[n(1675)],QdsyNf.Athvt(_0x166208,_0x336aa2,10,_0x58fe6d.length);continue;case"1":if(QdsyNf[n(1877)](_0x36b702[_0x17f5b8++],128))return{value:_0x51144a?_0x34b97e:QdsyNf[n(1696)](0,_0x225205),offset:_0x2808d6};continue;case"2":if(QdsyNf.AuDIK(_0x57978c[_0xc6d802++],128))return{value:_0x2755dd?_0x40c0e8:QdsyNf[n(790)](0,_0xa43fc3),offset:_0x348489};continue;case"3":if(QdsyNf[n(1882)](_0x9ad304[_0x428275++],128))return{value:_0x4ac914?_0x3d6d8a:0|_0x2c2371,offset:_0xa718d5};continue;case"4":return{value:_0x3bd8ca?_0x346631:QdsyNf[n(1263)](0,_0x441ed9),offset:_0x49285d};case"5":_0x495d96=QdsyNf[n(850)](QdsyNf[n(1745)](_0x5e71c4,QdsyNf[n(1081)](QdsyNf.xmXOQ(127,_0x3b406a[_0x1047d4]),14)),0);continue;case"6":if(_0x251735[_0x3945b5++]<128)return{value:_0x4b1beb?_0x2a59d2:QdsyNf[n(1432)](0,_0x2683ef),offset:_0x60c261};continue;case"7":_0x5de16d=QdsyNf[n(850)](QdsyNf[n(1718)](_0x153876,QdsyNf[n(553)](QdsyNf[n(1348)](127,_0x537cb3[_0x112a6b]),7)),0);continue;case"8":_0x15e49e=(127&_0x15c304[_0x3112a6])>>>0;continue;case"9":if(QdsyNf[n(1877)](_0x4f3b6f[_0x2d21ba++],128))return{value:_0x43d46d?_0x2ac9d4:QdsyNf[n(1696)](0,_0x4d7ee7),offset:_0x49dde7};continue;case"10":_0x24e261=QdsyNf[n(1480)](_0x42e35d|(15&_0x56cc9f[_0x4c4db4])<<28,0);continue;case"11":_0x1bd7aa=QdsyNf[n(1448)](QdsyNf.uRQsC(_0x57175b,QdsyNf[n(1247)](127&_0x5c9d12[_0x40be20],21)),0);continue}break}}else return this[n(1656)]?this[n(1656)].url:this[n(1454)]}[t(1306)](n=1e3,s){let d=t,f=e[d(902)].split("|"),g=0;for(;;){switch(f[g++]){case"0":this[d(1143)+"mer"]();continue;case"1":this[d(1159)+"ger"]?.[d(834)]();continue;case"2":this[d(1419)+"osed"]=!0;continue;case"3":if(e[d(1083)](this[d(1656)].readyState,this.CLOSED)||this[d(1656)][d(1763)+"te"]===this[d(995)])return void this[d(440)](e[d(556)]);continue;case"4":if(!this._ws)return void this[d(440)](e[d(374)]);continue;case"5":this["_destroy"+d(1574)+"t"](n,s);continue;case"6":this[d(1891)+d(1868)]();continue;case"7":this["_dropGlo"+d(469)+d(1255)]();continue}break}}async send(n,s){let d=t;if(e[d(764)]==="vhjQu"){if(e[d(482)](null,n))throw new Error("please provide a"+d(464)+d(1407)+d(766)+"e a stri"+d(1581)+d(762)+d(467));e.GBxDm(e[d(1326)],typeof n)&&(n=JSON[d(758)+"y"](n)),e[d(722)](e[d(1213)],typeof n)&&!e[d(1122)](n,ArrayBuffer)&&!(n[d(725)]&&e[d(1555)](n[d(725)],ArrayBuffer))&&(n=JSON[d(758)+"y"](n));let f=await e[d(1266)](Vd,n),g=tp(n),{method:m=0,service:w=this[d(529)][d(1818)],logID:x=this._options[d(1137)+d(1436)](),headers:T=this[d(529)][d(1852)],payloadEncoding:k=this[d(529)][d(438)+d(1666)],payloadType:B=this[d(529)][d(1729)+d(1052)],logIDNew:J=this[d(529)][d(784)+d(1239)]["enableAu"+d(1652)+d(1848)+"ew"]?e[d(1416)](i,this._options[d(784)+d(1239)][d(1855)]):""}=e[d(679)](s,{});if(!w)throw new Error(e.LgFmm);let H={SeqID:ae.fromNumber(this._seqId++),LogID:ae[d(649)+"er"](x),service:w,method:m,headers:T,payloadEncoding:e.jMKGW(k,Object)?k[d(1585)]?k.encoding:"":k,payloadType:e[d(1876)](B,Object)?B.type?B[d(1318)]:g:B||g,payload:f,LogIDNew:J},de=Bt(H);return this[d(1656)]&&e[d(1659)](this._ws[d(1763)+"te"],this[d(1528)])?(this[d(1656)]&&this._ws.send(de),this[d(440)](e.UjHhx,H)):e[d(1082)](this[d(1365)+d(460)][d(1675)],this._options[d(473)+"geQueueL"+d(1884)])?(this[d(1365)+d(460)][d(1455)](de),this[d(440)](e[d(708)],H)):(this[d(1365)+d(460)][d(1383)](),this[d(1365)+d(460)][d(1455)](de)),{seqID:this[d(1873)],logID:x,logIDNew:J}}else this._isInit=!0,this[d(1019)]()}async[t(754)+"t"](n){let s=t,{url:d}=n||{},f=Array[s(1114)](d)?d:e[s(1321)](s(1290),typeof d)?[d]:[];n&&Object[s(969)](this[s(529)],n),f&&f[s(1675)]?this[s(1594)+s(933)]=new Hd(f,this._options[s(1492)+"es"]):this[s(1594)+"tManager"]?.[s(896)+"pointCon"+s(716)](),this[s(1821)+s(1653)]?.[s(1139)+"nter"](this[s(529)][s(1209)+"Count"]),this["_readyCl"+s(577)]=!1,this[s(1656)]&&e[s(457)](this[s(1656)][s(1763)+"te"],this[s(845)])?this[s(530)+s(1860)](1e3,e[s(1792)],!0):(this[s(921)]=!0,this[s(1019)]())}async[t(1023)](){let n=t;if(!this[n(1019)+n(823)]){let s=e[n(1130)][n(1783)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1594)+n(933)]?.[n(896)+n(1764)+n(716)]();continue;case"1":this[n(921)]=!0;continue;case"2":this[n(1419)+n(577)]=!1;continue;case"3":this[n(1821)+n(1653)]?.[n(1139)+n(695)]();continue;case"4":this[n(1019)]();continue}break}}}[t(1617)+t(1255)](n,s){this.on(n,s)}[t(1484)+t(1668)](n){let{type:s}=n;this.emit(s,n)}[t(611)+t(508)+t(614)](n,s){this[t(439)](n,s)}[t(639)](){let n=t,s={yJeuo:function(d,f){return e.hrnWo(d,f)},OzzHE:e[n(829)],cfmjz:e[n(1561)],fZEwQ:e[n(383)],VOZpA:n(1583)+n(797)+"t",xvhZE:function(d,f){return e[n(1804)](d,f)}};if(n(1302)!==e[n(1568)])return new Promise((d,f)=>{let g=n;this[g(1891)+g(1868)](),this[g(1444)+"gTimeoutId"]=setTimeout(this[g(1549)][g(1814)](this),this._options[g(1125)+g(1888)]);let m=()=>{let x=g;s[x(1141)](d,s.OzzHE),this[x(439)](s.cfmjz,m),this.off("ping_onc"+x(797)+"t",w)},w=()=>{let x=g;f(s[x(1695)]),this[x(439)](s.cfmjz,m),this[x(439)](s[x(1663)],w)};this.on(s[g(1183)],m),this.on(g(1583)+g(797)+"t",w),this[g(1549)]()});{let d=_0x2cdb3e[n(652)],f=_0x28ff88[n(1169)],g=_0x521092[n(800)],m=f+_0x458787;if(m>d[n(1675)]){let w=new _0x38ef34(bbKfjg[n(1405)](2,m));w[n(1133)](d),_0x4abbfd.bytes=w}return _0x22586d.offset=m,m>g&&(_0x49545e[n(800)]=m),f}}}})(),ye[L(585)+L(612)]=Ce[L(585)+L(612)],ye[L(1505)+L(929)]=Ce[L(1505)+L(929)],ye[L(608)+"e"]=Ce.ErrorCode,ye[L(1668)]=Ce[L(1668)],ye[L(463)]=Ce[L(463)],ye[L(590)+L(1601)+L(580)]=Ce[L(590)+L(1601)+L(580)],ye[L(1601)+"vent"]=Ce[L(1601)+L(580)],ye[L(447)+"t"]=Ce[L(447)+"t"],ye[L(1386)+L(1207)]=Ce[L(1386)+"tEvent"],ye[L(718)+L(612)]=Ce[L(718)+"oseEvent"],ye[L(1343)+L(929)]=Ce[L(1343)+L(929)],ye[L(1790)+L(685)+"nt"]=Ce[L(1790)+L(685)+"nt"],ye[L(1498)+L(1005)]=Ce[L(1498)+L(1005)],ye[L(1112)+"connectE"+L(580)]=Ce[L(1112)+"connectE"+L(580)],ye["decodedF"+L(775)]=Ce[L(1866)+L(775)],ye[L(1570)+"ame"]=Ce[L(1570)+L(1435)];for(wo in Ce)[L(585)+"oseEvent","CustomEr"+L(929),L(608)+"e","Event",L(463),L(590)+L(1601)+L(580),L(1601)+"vent",L(447)+"t",L(1386)+"tEvent","createCl"+L(612),L(1343)+L(929),"createMe"+L(685)+"nt",L(1498)+L(1005),L(1112)+L(605)+L(580),L(1866)+L(775),L(1570)+L(1435)][L(917)](wo)===-1&&(ye[wo]=Ce[wo]);function So(){let t=["s3LOuuu","vLzAz0K","C1blz3e","s2Lyy2O","CgfNzwHPzgu","wNvSv2G","zNjHBwvuExa","C2nYAxb0","tu9Vve4","DM9oDNO","zhDyyLa","qK5nv3a","v0LcA0u","uKzAsuq","D01St20","yMLUza","z0TUtg4","we5KA1a","D3m6lY8","C2vYDMLJzq","AeXyq3e","ANbwCgO","x3bPBMDmB3m","A2XVww8","zwHrv3e","zuPfENa","z3bvyKy","DMHQuxu","ihn1y2nLC3m","BePSu2O","DxDAzxK","BwLUzW","yxbWzw5Kq2G","yLfcwui","rLPqtgq","zNjVBuj5Dgu","AxnFywnR","BNrfBMrWB2K","zg9fy0G","vLLUBM4","q291BNq","B2LUDfjLywm","x2LUAxrqCM8","C1rnAxm","z290uwS","B3fUuhO","z2v0sxrLBq","EMHnzKO","yu9rr1i","DgvmB2Djre4","v29JENa","zwTkvKK","zfjdtKO","AgvHzgvYCW","AxjLza","yvfcy3q","DxnLCKLW","CM92AwrLigi","D1bmvKi","B3rLu24","yxrLq291BNq","zwn0","B2rdEeS","ze5Srgu","x194x21Zz18","zxjYB3i","qML4Evm","zgvJB2rLzey","y1HLwfm","BMDuAw1LCG","z29PBMCGyxC","ywzL","BNbhCgy","zgvQwNi","x3nLCuLK","u2vXsuq","qNvIsMy","q29Tq1i","DxfTBxm","yNvMzMvYzwq","B3vUDa","q3H4vei","EhjQBxG","qxvesuS","s0vUEwy","zw5NDgG","z1PKDKy","yMrFzgLK","zgvSzxrL","CNzHBa","D0XvA20","CgP6BxO","x2nSzwfYugK","Ae9Wzw5fDMu","zxjstu8","D0DKv0G","yM9KEq","yxbWBgLJyxq","zcWGDw5RBM8","ChjVDg90Exa","Buv1qu4","y3LPy2m","AgLNAa","wLjltvG","AfvUCKS","B0z1ANK","zgv1EvK","x19LC01Vzhu","Dgv4Dc9WBge","B25ozxr3B3i","ufDbrg0","ywWGy3vYC28","sMzPuhG","AgDorMW","rMDSD28","uvr2yva","sM1huhK","q0nTrNa","vuPoD1K","zK9yu0e","CNnVCL9Uyw0","C2XPy2u","ywnOzwq","Ef9MCM9UDgK","tKnwB0G","A1fQCxy","C2fNzq","DMvYC2LVBMm","y2uGBM90igK","ihjLy29UBMu","Be5wDKu","mty1nZuXofrAChjnrq","CMvZB2X2zq","C3LUuei","DKDzyLu","q1bYz0m","wwnswgq","EgnxA1y","ug9pEMi","A09ushq","uLjpuG","vgLTzw91Da","z0n2tva","zNjVBuHHC2G","vfHwDMG","uxrSyve","Dw5RBM93BIa","BgvY","z01JvMC","t3zTsxK","t3HVBNK","zxq9DxrMltG","uMvHzcbWyxm","x2HHBMrSzvi","u3jptu8","CuDYq0O","rwzcs1q","t2jQzwn0","ywDLu2HVDW","DvDzBgu","sw5rCxi","Dxj2rwi","ugj5z1i","C01xDwi","y09Wzw4","B25tDg9Wsw0","AvzIqMe","z2v0","u2rTuNq","zgzuzwm","whrWv2i","zMvVD0W","yxv0B21HDgK","wKDnAgC","Cgf5Bg9Hzeu","B2zM","x2rLyNvN","u0jVCgG","zMLUza","tgTTzM8","BeHHBMrSzxi","C2v0y3vYC28","zwnVBM5Ly3q","t3bLBKv2zw4","AwXK","wKDluhG","rMDQt3C","t0z0A3a","Dvf2sMm","zMLSzw5HBwu","wwHctMu","y2HHCKnVzgu","zMzmAw5L","ExDQAxi","t3rJvKu","C3H5v0C","uxvLDwu","BKX0vwO","zKjHwwW","rLDt","ihzHBgLKigq","A2v5CW","rermBuO","zMzLCG","q1bIDe8","yMfSrxzLBNq","mNWXFdr8n3W","sKLmrfy","ru1kq0S","Bwf4twvZC2e","x2DLBMvYyxq","CfjWBee","tMTXtxy","zxjYtM8","B095Bgq","s2LIB2C","z2vY","B25SAw5L","ywzLu24","qKLyALO","sg9Ivhi","tu55y3q","CYbPBNn0yw4","r1bTrve","B3j2De8","Ahr0Ca","yMflDfm","wMjuvMC","sNLTCLa","EvzVzKu","vKzNBNq","AgvHzgvY","D1bqtMm","B25tDgfYDfi","mta3odi3mtDjy0HVuhu","qxDjtLq","CMvHzg9UBhK","v0LUExO","tMDZCfi","B3jRzxjhBg8","wKvqA3C","A1bpCfa","uLLdEKW","vxrtAvq","zw50tgLZDgu","z1jpqKG","wxHdEMW","zefQu1i","y3PUuwm","y29UBMvJDgK","yNL0zuXLBMC","EujPB0K","BgLUzw5V","vfbMvvO","yxGGCMv0CMK","x2n1CNnVCK4","tNzmufq","twLZC2LUzYa","r2jiq2i","AM1tC2S","wKvez3m","CNDYDhK","z294uhu","DMvYC2LVBG","C2vUza","x29WDgLVBNm","x2rPC2nVBM4","v0PPCKC","C0jHBM4","uMv3wwe","wMrUv3K","B25JBg9Zzq","CgvYC2LZDgu","x21PBMLoyxy","B1nJBMW","CND5q3a","C1bOyuq","EhvJEKq","s1fmwKy","rw5Mtw0","y2TgwLu","EMrcCu0","wK5ZzuC","zM1Iq2e","v0TUD3u","B3L2qLm","yw1Lu3bHy2u","v05Pu0y","zfzqwfO","zvDtEfK","BgLUzq","y2XyvLO","sKLtDKi","u2frvMy","quDOv2G","CLroCgC","EePICLa","yxKSig5LDhC","uhziBeC","zw1UDvy","yNbyBNC","swHtAfO","Cef2ufK","sLnrAKq","BhnIu3u","DNfNr1u","yxHfB24","uLHhA0e","rMHODLu","s3HmEvy","igzHAwWSig0","sxPksvK","BurjDNC","B3nLza","ufnuq00","r1fNA0i","DMvUDa","ufb2zNO","qwjVCNrfCNi","qwLfD1a","C1nHvuq","q3vZDg9Tq2W","CKfOsMO","vfjoDuG","zNbtEe8","C2vUzf9Hy2S","rNjVBNrPzxi","z2v0u3rVCMe","mNWWFdz8n3W","vvnvrNm","wxj3wM8","z1zdzxu","zw5HyMXLvhi","tNvQvum","BMrWB2LUDca","EvLiBeK","sxf6u1C","s0DxrMq","s1fQBve","x2zVCM1HDeu","sxLpuKO","y29UBMvJDeu","C0LKvwi","x29Ut3bLBG","rxjYB3jdB2q","s2zdBeG","s1DIEMu","CMvTB3zLrxy","B3nLrxzLBNq","vunKEhi","BMvY","shzIrxy","y0nhwgS","rxjvz2y","CgPur1m","y29UC3rYDwm","igzPzwXKoIa","Afz5uxa","CMv0CNLdB3u","y2XLyxi","Dg9cExrLC0W","ywnRx2LK","B3bLCNr5tMe","Bffcs2O","tffPruG","t2Ptu3u","qLjxruC","y2HLy2TdDxi","AgD6rey","zcWG","rujpt3y","yNDovuG","zxH0zw5ZAw8","vu5Py2i","zfbjBgK","CgLUz09Uy2u","AeL1svy","DxrVuMvJB24","uefvBgm","t2XHBKe","B3jRig9MzMW","DhbKqLu","BwvZC2fNzv8","tufyx1jfvfi","CeXft3q","zNjVBu51Bwi","ywryqK4","BwLUAvbYB2C","yNL0zxm","zK1zwxi","EfLiCeW","DgfYsuG","y29UBMvJDca","rxfYveG","s1HqBMC","qxboBfe","C2Xvsu0","zur3teG","Dw5KzwzPBMu","AhvnCuC","tfDju20","BMCGzMfPBgu","y2XVC2uSihC","ywDTBvK","BM93","se1Xyum","B2XKvMvYC2K","vfzzvgm","vgfUzwK","sxndqve","yMXVy2TLza","s3boz0i","r0PHvg8","EM1dqMe","CMvHC29U","sevlB0O","Aw5N","Aw5JBhvKzxm","C1rgvwi","zgv2AwnLx2K","sMPqrvG","C3nHz2vfDMu","D25mr2S","ufL5uha","zxjFBxnNAwq","zePpq04","s3ncrMi","uu5dqwi","yNLL","teDutKS","wNbbqKS","BNrLCG","Dw1VD0i","CurTswm","AxnrB1nby2S","y3vYC29YlNm","wef0tNy","Bw1vBxO","q2TSqwy","r05SB0m","ueHzy2y","Bg1XBhu","y2HLy2Tszwe","ywr2yw5Jzq","DLH5u28","BvrQsuW","vuzHrvi","D2feAMu","uhHquLe","BvjAtwe","zNL0AhK","v0LbDxa","zMLN","C3vJy2vZCW","y3jLyxrLq2W","rLbyEuW","BwfUDwfSihi","se5UD3O","ww50t1i","r0zHu1m","rLzkA2i","yNvMzMvY","zefKsvO","AM9Rzhu","s2DKvg8","Bg9N","EeTMAxG","Cvzssfm","ywDLrxzLBNq","ugnUtg0","qLfnqvm","B2nRzxq","zwH5qNe","yxKSihrYEsa","Dg9oDw1Izxi","sxHkEfa","qNrmC1y","r1bsCeG","ruTdqMi","ChjVy2vZCW","vMHRD3C","ruz0A0O","z2v0qwXSs2u","D1fUBMW","rM1fy0e","zvrjqNq","EuPKsey","yNL0zu9MzNm","sfztt0K","z2u6ia","CMvJB25Uzwm","x2fKzfDZtgK","y2fSBa","Ec1TC2CTCw8","C3rYAw5NAwy","u2Pwre8","AMD6uKq","yNr5rxy","igfYCMf5yNu","tMHKBfe","y0fctwi","zK9kExy","ysbTDxn0igi","zNjVBNrPzxi","uKDPy3q","BwfW","ugTcD3m","rMjRBxu","EwDduKK","rMfmwMG","zuLcuLm","CMfTzq","x3DHAxq","y29SBM8","qxzgvKq","zNDqquW","t0zpAM8","BunYsvm","v2LUzg93","CLDXDK0","Bg9NsurozxC","B3bLBG","s1zty3C","qKDiA2G","z0DVALq","BM1Ts2q","D0n4Egy","CNH1Dwe","z3Pgrvu","B3jL","CgXLyxnLiha","q29Kzq","we1WwuK","zv90Aw1LB3u","wvDssfO","r2XNBeW","BgLTAxq","wujpze4","x2LUDgvYDMe","tuvbCxO","vLrKA3a","BfDIEvu","EvjLy29UBMu","twr1C2K","ChjVDg9JB2W","BNvzzLy","Aw9Ul2PZB24","DLPtseK","otG3odeZswXWBhPi","qujyAvm","tKL1r1O","B0nqzui","ALvSA2m","r2Hwr0y","veziwwO","q2PZzfa","sNnnu2W","CK5My0e","y3vYCMvUDeK","tg9JAW","uK1rEMu","q212BfC","Dg9mB3DLCKm","rvHcsve","veLnB0i","Aw1ru3a","DwTXq24","sgDsBvG","Aw5KzxGGB3u","AK1sB00","y2XVC2veqG","EgPPr2S","DhDnCKu","z2vjBMzVu3K","DgvZDa","wg15Ehm","x2XPC3rLBMu","C0XPC3rLBMu","ugTQDuK","rhjdDu8","s1zqCK8","q0Xpu0ve","CgjICdi","B2nRzxrgywK","vhvqz2m","y29UBMvJDfm","wxbMwKm","v2zsuxG","ignVzgu6ia","mxW0Fdj8mhW","sgzKr00","mteWCefxtvrO","AgvKtwf4uMu","zxmGCMvHy2G","r1P5rwW","DvDXzNy","C2vYDMLJzs0","v0zHwwm","ihbYB3rVy28","x0vysvnu","suruD3q","CgLUz1rPBwu","Ae1LC3nHz2u","qvzpqvm","yLDrvNa","zwDqr2C","yNLrzeS","sgjpD08","B25TzxnZywC","zNjVBujPDhm","vMTWBwq","EgXgrgS","BwPKrKi","BNrwDgq","A09cy3O","u1npr0W","wvzIzLa","BML0AwfSAxO","vLDYAvy","mhWYFdf8nhW","BNruCMLLC0m","Bg93","CMvUDevUzha","D1jdvMm","rLjvBwu","CwTJue8","rwzWDei","B25VCgvU","rgjxteG","Bfvjt1G","AevqC3K","wfbqtKe","CMvZzxrfBMq","rhHuse8","Efrurw52","zM9Yy2u","uwTquM4","BwvKAwf0zwW","BLvTr1u","uhfVEum","EgHnyKG","BwLssvu","CNzHBfzHBhu","zhb3CeG","BvDPsMy","qw1VDw50","t2XSBKG","B0PQD1y","DK5YANu","tvrXANa","ywnRDxbfBMq","zw1PDa","ueTQvMu","Aw5KzxHpzG","yMLUyxj5vhK","x2LZtwLUAvq","zwPKq0u","x2LZsw5PDa","AwjOz2O","ENzryNu","AMnyrMu","B2Xxzfq","sgLYBw0","DwTzy3C","qurZD2C","CM9YrxzLBNq","wNnQsKi","y3jLyxrLt2i","qK9Hyue","De1HBMfNzxi","ywXS","s3jlC04","yxv0BW","BLj4DMC","C3rVCcbPBw0","yw1LoIa","mdaWmdaWmda","u2fkvgq","sfjxvxi","te9RB0y","ENnOyuK","x3nVy2TLDa","B25pCgvU","B25szwnLAxy","zMLSDgvY","Cgu6ia","CwDiCwG","B1riy2W","CMvZDwX0","tfbPv20","Avzcuuq","CunuzKW","CMvJzxzPzwq","uujurNK","B3v0sw50zxi","zLHAwNi","s3H5rei","z2vlAMq","x3DZsw5ZDge","C1DPAvK","zgvbwve","yMf5EgG","ve1fq1O","qwrxvKi","D3jPDgu","yxnZAwDU","ELL6Afu","BIWGAg9ZDg4","ywnRpwzYB24","AhzIv2G","D2zXvgW","rvrtshe","zgLYvfC","z2v0s2v5","ndu0mfj4qwfWEa","D24GCMvHC28","y291BNq","u3rYyxrLz3K","yLPnqu0","EejXwfq","rgjxzfe","EfDTwwO","m3WYFdb8mxW","CNnVCL92ywW","DhjPzxm","Aw5KzxG","DgjxBK4","r3j6seq","Ehjhrwi","qNjPzgDL","rNzLvMC","q0Xpu0LorW","qNPZsNm","zvDHueG","B2zMBgLUzq","sMXNy1y","C3rVCMu","t1DxB2S","u2TPCcbWyxm","tuvtu0fhrv8","s2vJvvy","zw5fDMvUDa","uNLwugK","CMvJzwL2zwq","zNzLtKe","BwvY","zvbTCuO","rLjOCuy","Fdz8oxWWFdC","uLjer0e","zwDWufq","vKrfENi","DhjPzxmGCMu","CLzHBhvLCW","zfDVCMTLCKC","x2nVBM5Ly3q","v0XTrhC","yxnJCMLWDa","C3rLBMvYCW","y29UBMvJDa","AMvJDfn0B3i","x2LZtwLUAvC","y3vYC29Y","tu5hzwS","B2fK","su5tvefova","B1bpAeS","BK1xr2O","zgvS","DgfIyxnL","D3nZoI8V","x2rItMfTzq","DNvJD3a","ELzjtwq","AKr0txK","EwLrt2i","t2nYCwq","rxrezuG","DgLLCKPtt04","BMvLzf9Hy2S","AwXLx25HBwu","r0LtC1u","weH2ug0","CLP1rKe","CLniq2q","CKjqreq","tMLAvfu","uxjODhi","ExbL","z2v0q3vYCMu","thHJBgG","qLfoy3m","icSG","BMv3vMvYC2K","zMX1C2HfEha","Aw1LCYbPBIa","Chv0","AxnrB1nnzxm","D3jPDgvvAw4","ALbLA3G","qxfdCfq","ywnRtxnNswq","DxrMofDYAxq","qLfoA3e","Aerxwxq","Fdv8mNW4","tg5JCLO","AefJA01LC3m","zuHeuvy","tLfNzKy","vKDTq1q","BLrrtKG","r05zEMO","BMfTzq","tNbLyxe","yMfJA3vWigu","rxDeuhq","BMvMsgu","tKPWqvi","CMLZCNi","zfr1ywG","ywX3yxLZ","u1vMuvK","sNzzAfC","zxjFCw9Zx2e","EgztqLC","x2rYB3bhBg8","zNPfyLK","x25HDMLNyxq","yw5Nzq","ChD4Dwu","zxHWB3j0CW","mxW0Fdn8mNW","BwvZ","vLnyzem","AuTYuvu","tuvwEuy","rM1qAxi","DxbKyxrLq3u","s1bPvg0","ref4ruS","ywXty29Wzq","Cuvmvvy","CIb0DhDjra","yMLUyxj5","BwzoweW","CMPWq2W","EM10t0u","y3jLyxrLuMu","y2XLyxjtDg8","AxnbCNjHEq","ENjewey","x2n1CNnVCKy","v1LJwxy","zMXVB3i","jMPZy2fSBgi","zhzKAK8","zg9Uzq","C1fPre8","Chfkv3C","ru1MzNu","CgLUz0LUDgu","ChD6Duu","Dfveq1C","B3jpBMXPBMu","ExPwDha","A3LerKW","zgr6rey","BMvuqvy","C2v0","BhnJt2K","EM1hyuu","z0rYDNy","Bg9Nsurhzw4","s0rfA2y","CMvZzxrdB3u","B3jLtMfTzxm","EuPLDw8","s1PmsfO","x2nSzwfYvgK","CM92AwrLihy","DfjryKy","zvvYBa","BLbptMu","shzjC2i","DMLJzuLeig8","B3bLBIa","DMfSDwvZ","x3jLBw92zvC","Dg9iyxnO","y3vZDg9Tshq","AwDHDg9Yt24","EwHrqvy","tMDxq3q","zvfRrxK","x1fVu01HBMe","x3bYzwzPEa","Aw9U","Aw5PDcbrB1m","uM5ky0m","y2f0y2G","C2v0q3vYC28","zKv5C3K","uuf3rfK","x3bYB3rVy28","B2zMC2v0","wNHLEKy","CYbHBhjLywq","y3ruAw1LB3u","shbVzxa","B25fyuW","zNvUy3rPB24","wxjWvfq","CNjVCK1LC3m","nxW5FdeW","vePSCxe","suLiD08","id4G","y29UDgLUDwu","y2zTANO","y2PZC1C","CMvHzfvjBNq","AxnNs3y","wfvZvKS","rxnKA3m","s0nzCuq","q1nsDem","x2nYzwf0zvm","AhrQB2m","x2LUAxrhBg8","x2HHBMrSzu8","vhfkBu8","rgv3BeW","zMjWANy","zw50","uxf5ExG","D1Lcte4","zNjVBunOyxi","uw9TBgu","DfHbyM0","CKPRCu8","zfr5Bfa","qKXQs0K","Dev2zw50","AxbzCMG","CgLUz0XVC3m","BNbpzwm","A2v5","qKfiD1q","C1zoBwK","yNDzB2S","tuXNDMu","ELnPuuO","x2DLDeLUDgu","A3DiD0y","B3bLCNr5","ALPzt0C","mtKZnde3sejZrenz","BKXPBMu","BuDZz0S","AKzTyK8","DND4Cg4","BgLZDgvUtMu","ww9jANC","yNzJCu0","CMvQzwn0","sNHjD2O","sfrxv3e","rMnQvLq","BuXHAha","zvHhshK","qLDfzNi","wNnlvwy","D25YsxC","zgf0yq","q29UzMLN","rufQu2C","tKr1Ewu","ywXgAKq","BxnNsuq","r3jYt3e","BNvRBg0","EK1eEhq","z3zTDKy","C0vbu0G","vKftuKK","q2virw0","C3bXzw8","ELjeDwS","yKjREvi","tgjICuu","tgLZDgvUzxi","z0f0se4","y0TzBvu","Ec11C2uT","BwLZzq","B25mAw5L","DxLhwg8","DK9AsK4","v2zAANO","v29QuuG","ywDLsgLKzq","BKzwELq","y3fVwhG","ren0yLa","yw5ZzM9YBvq","B25LCNjVCG","C29YDa","ihrVihjLDhi","zMzMzG","wNjtAeu","zgPptee","A1jxvge","tezODuO","AhvVr28","CgfYC2u","zgfVvKW","rxz0z2C","wfvWEvC","x29UtwvZC2e","x2LZqNjVD3m","y0Ptuwi","sefhCuS","AevYCM9Yrxy","BhrPCgXLihq","mZi1BxHPwKfl","C3rYAw5N","Dg9cExrLCW","rxncCu4","sLrurLm","y3DREwS","BfrPBwvVDxq","ndCZn0Xnz2Hvsq","reDXywC","teLJCgC","ELjevMm","yufOtum","AwXLtMfTzq","uMzoyKi","seHTuxq","y0LIzgu","t1bftL9fuLi","y2XVC2u","CMvXDwLYzwq","shzXyMi","DhDVCMTdAge","CMDeCe0","Dg9Y","BM5Ly3q","DxjS","l3DZl3yY","C2v0u3rVCMe","x2HHBMrSzva","DLPXB0G","DhLWzq","uMLfCgW","sMzcCwe","r0j4rg0","ywnR","EgXRsgW","wvfnsve","qMvKwxK","suLuDe8","Cg9W","Exrlr3e","y2HnyxHdB3u","Bg9IywXty28","rMnoB2u","rePKrgq","x29UugfNzu4","tgT6yw0","vwnntwK","tMfTzq","yMHVCK8","A3n5ELm","CNfACum","tKDFrvjst1i","DgXntMW","D2LSBfjLy28","y3jLyxrLrxi","EsbJBg9Zzwq","zxj2AwnL","ywnRx2nVzgu","vw5Oyw5KBgu","Eg1yt1e","wejSsvO","uuTdwKu","tg9Nsuq","CxjYBLu","EKLuAgu","tNnuAxC","yK54D0i","t3P1Dum","ihrPBwvZ","quXm","CuniEMq","DgHLBG","DM9jueO","su9Wquu","zxjYtxnN","tfn6vey","x21LC3nHz2u","zgrjrcWGzgu","ue9hEfG","sKrcqNC","vw5PBxbSzw0","C2v0zgi","CgTpCLC","uxnmsKe","y3vRtuO","BNryvLe","vLP4u1K","Bhm6ia","C2v0sxrLBq","r3PtuuG","rg1NqMe","yLfgz2m","BLD5Aum","AwrI","C2HPzNq","u2HHCMvKv28","AxnszwfKEq","uMvJB25Uzwm","Bwf4tg9ZC0m","x2LZv29YA2u","q2LAyxO","uufbC0e","Eu9dEey","wgzjC2u","A3j3z3G","DKrhuhq","wg5buei","sxbTzvO","DMfS","CuHetgO","Aw47y2HHCNm","Dhver3O","y0XJCgG","yMD5yMu","q1b1v0m","DNDWuvq","EhzOwKu","vKjbyve","yxrHlcbKyxq","vLfsC1i","BMnLq2XVC2u","BNrbBMrvCgq","vgPut3u","x0rctMfTzq","ELLPrhq","BLzADNa","tKfusvzfx0u","ze9ky1O","lcbTyxGGCMu","x29UrxjYB3i","x3jLywr5q2W","vK9xuMi","EejusMq","mZC3nJy3zu10Ce1s","vg5IDvq","Bwv0Ag9K","sLbLtuC","CMfNzvn5BMm","reiGzMfPBgu","svPNsfu","ywrKq291BNq","rgDHALi","rwjusKi","DvjrC0m","Dxrjza","BMv4DcGPigm","yw1L","zxjHDg9Y","CMvWBgfJzui","qvPvtg4","Dg9tDhjPBMC","zvzcAM4","x29UvgLTzw8","Dw50","r0DrrNO","x3bPBMDqB24","BM9Uzv9UB24","Ec1TC2CTy3u","wenjrLi","s3PSuwG","B25dBg9Zzq","CMTLCKDSB2i","Eun1A1i","zw5eAKi","Bw1sqva","x3vYBa","ChvZAa","BMDLza","uefXrue","BMvJDa","zMD1B2e","AM9PBG","B3bLBKrc","ihrPBwvVDxq","v0rXzuy","zxjFAxnFywm","ELjTzem","yMfSu2nVCgu","BufHC3q","rwzmCu4","B2jQzwn0u3q","igXHCMDLCIa","tffluhu","yxbWBhK","zwjftM8","rujtqLC","D0rMwgG","CK1rC2m","tKXXqNe","thbhyM0","B2nRzxrtDwm","DfveAvO","tur3CvG","DuDnz1G","D2vI","zgLZCgf0y2G","BxnN","ChrVCG","suvtx0vsuK8","x2rPC3bHDgm","y29Kzq","yK9itMq","sxLTu2i","Bwf4uMv0CMK","C0Xf","sMP0rNG","ig1LC3nHz2u","yM9L","C3vIyxjYyxK","y3jLyxrLt3a","shDMDKm","yMzjBhG","ugrKv1i","zwzLwNm","rvfovwW","aaaaaaaaaaa","q3vZDg9Trxi","C0jf","ChbL","BwjuA0q","DcbVzIbYyw4","ywDL","x3bHDgHlzxK","zufJAW","ru1dt1C","yxnL","x2LUAxq","AeDxBg4","Cxj5zeq","v3vAswi","zw5KCg9PBNq","zv9ZDwnJzxm","mhW0Fdn8mxW","nxW5FdeXFde","qwHns1u","DMfSDwu","wvPoyuS","DfHqzwq","y29Uy2f0","t1bftG","x2LZtM9Kzq","sMfxAxC","ru11qKm","DgHHBIbSB2m","Aw9UvgLTzw8","EfvZzuvUDG","zw5HyMXLuw8","ugrKyLi","BMrLEa","EuXer24","C3vIC3rYAw4","wMjgthO","CMLLC0nVDw4","yK5gwfO","mdaWma","DhPHtNG","ywvdy3a","y3vYCMvUDeu","B0jtD1O","wMPrBKO","x3bPBMC","wM11zxG","Cw9Zx18","EfLvB0y","EvviAu4","AxnmB25N","rwTKq3K","zxjFCw9Z","yMjZEum","A093BgK","BKf3ug4","x2rLC3rYB3K","uhLiEMS","turJBhC","z2v0qwXS","AePSBLq","r0LRBKy","BMjABeu","wejcAha","ELjHD1u","x3nLBMrby2S","zw5JB2rLrNi","ihzHBgLKihm","AgfZt3DUuhi","t1HLwKW","v2vIu29JA2u","r1zhEg0","B3DxCNi","rKPUqum","swjwywK","t29KsgK","sxLUwe8","BMCGB3iGyw4","Axnby2TdBgu","CgLUz19VBMm","t3LqvuC","zw5JB2rPBMC","C3bSAwnL","C1vuvvu","uMXfsMS","CgvxvfG","D0zeywq","Aw5Lza","lcbxzwjtB2m","A1Hluhq","x2vUzhbVAw4","wKrtDw8","v0HNCNK","y2zpv0G","Ahr0Chm6","wu1Iuwm","Bu5Zqw8","twvZC2fNzuu","wxL2s2y","A0XpqKq","ywXSq3vYC28","wxfnvMm","zwvKvNa","Cg9PBNrbBMq","BMrWB2LUDfq","qNDODe0","zxjFDhrS","zw5XDwv1zq","BfjPuNm","AenSB3nLrxy","AxmGDw5Kzwy","CMvWBgfJzq","C3rHCNq","ywrKrxzLBNq","ChHIuK8","y3vYC29Yx2y","we1uzeq","Dgv4DfbHEwW","AvnZwNC","EuvnA2C","rwjyBKO","uwTnq3u","vxbKyxrLq28","BwvLs2q","se1XCMK","vxvqsgK","BezSDxnO","tuvnsLK","t0nrDfi","tvHACLO","tu93D2S","t3LkDNm","vhHXAu8","nxWW","rePbuNC","zNDZxZeUmc4","zcbLCNjVCI4","z1b4sMG","ALjwAum","zwTyugm","y3vYC29Yx24","z2v0q3vYC28","q09otKvdveK","mZbSt3PkCgG","zKneDxC","wxj2ufO","B25fCNjVCG","AuXmv2q","Dg9hzw5LCMe","C0nVDw50zxi","CMvHzhDYAxq","vMnct24","x3DZ","v21vz0m","DeXMA1y","qwfuywq","mJrUuhDcvM0","zwvKzwq","ugz4uNq","vK9ACee","DMvY","DxbNCMfKzw4","BMnVzgLUzW","y2vPvgC","rxzLBNq","vwnttvi","AgfUz2u","y2HnyxHuCMK","vgfN","wvfNCeS","A2v0ignVBNm","BgvUz3rO","y2vZC0HHBMq","q3Pdrfi","z3PiEhm","rfb1BM8","AgfZ","Cgf5Bg9Hza","rLHMrhK","v2vPEgLUsLm","BvPNzge","CMfTugfYyw0","ywrK","A1zrywe","zxfxr1i","BMPKuNi","x29Uq2XVC2u","zw1LBNq","DhjPBq","CgfNzxnOB3C","zM9YrwfJAa","zLPfD1e","ww5LtgW","rKLHEwu","Ewz5qvi","x2jPBMfYEvq","yKT4uve","vvbTyLe","Bev6s1a","s3blCvy","BNvTyMvY","z1vPDuy","y3vYDMfSDwu","D1vkC0C","C2vYDMvYvgK","tevwDNG","A0Tcy00","s2HTz2C","rgvKAwnHDgu","CwXYC0W","BvnhCgG","x3fVC0rc","CMfUzg9T","wuvWq1a","CLb0wem","C2PZtfa","AuPywLm","t25WuMi","D2fZq2XLyw4","zKjqBuu","zgvMAw5Luhi","tw5QCw0","tuXeqNa","DNLjzKi","DgLUzYbZzxi","Cgf5Bg9Hzfq","tNfizhG","DMjtvwC","B1Ptthi","yu5ws04","Dhr3Awq","CgruD3i","DgLTzw91Da","CLHjCue","rvjst1i","u3vcvw8","Dw5ZAwDUzwq","y1bACMm","DevSuLa","y3r4","z1rPBwvVDxq","wfnrBfm","CNjZvgi","CNnVCKzPBgu","DeLUDgvYy2u","y0jiyLK","tgXMuwS","D1PjAKO","tKDzB3m","zwPWCwW","DeLK","AujkzvC","shH6wgW","ign1CNnVCIa","zxrxB3jRq2G","qwTQue8","CxPpuwK","x3jLy29UBMu","AujZDKm","CMvHzhLtDge","Cg9PBNrdB24","B3Pbtxa","y3jLyxrLrwW","BwvZC2fNzq","tg9NsurozxC","zxfKCxO","x2n1CNnVCK0","z2vtEw5J","CMvKDwnL","qvHezhi","ALPwreS","x2TLEvbHDgG","yw5Hz2vY","yMPnB0K","vKn3D1G","yNn2CeK","Dhj1y3rVCIa","uhzOEhq","u3fctfC","C3bSAxq","D3LODvO","CK9QDKG","B25Uzwn0Aw4","BM94Cgu","BMCGDxjSoIa","A0jltNq","y3jLyxrLtwu","uvHXD2C","Dgr1DMK","uezUEKS","yK1ywgS","mhWZFdv8nhW","D1jrCwu","sLnptLa","CMvTB3zLq2G"];return So=function(){return t},So()}var wo;Object[L(1724)+L(1219)](ye,"__esModule",{value:!0})});var Wt=ie((e3,th)=>{"use strict";var Q0=["nodebuffer","arraybuffer","fragments"],eh=typeof Blob<"u";eh&&Q0.push("blob");th.exports={BINARY_TYPES:Q0,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:eh,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var zi=ie((t3,Io)=>{"use strict";var{EMPTY_BUFFER:jb}=Wt(),ed=Buffer[Symbol.species];function Hb(t,e){if(t.length===0)return jb;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 ed(r.buffer,r.byteOffset,i):r}function nh(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function rh(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function Wb(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function td(t){if(td.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new ed(t):ArrayBuffer.isView(t)?e=new ed(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),td.readOnly=!1),e}Io.exports={concat:Hb,mask:nh,toArrayBuffer:Wb,toBuffer:td,unmask:rh};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=ce("bufferutil");Io.exports.mask=function(e,r,i,o,c){c<48?nh(e,r,i,o,c):t.mask(e,r,i,o,c)},Io.exports.unmask=function(e,r){e.length<32?rh(e,r):t.unmask(e,r)}}catch{}});var oh=ie((n3,sh)=>{"use strict";var ih=Symbol("kDone"),nd=Symbol("kRun"),rd=class{constructor(e){this[ih]=()=>{this.pending--,this[nd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[nd]()}[nd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[ih])}}};sh.exports=rd});var Dr=ie((r3,lh)=>{"use strict";var Fi=ce("zlib"),ah=zi(),Kb=oh(),{kStatusCode:ch}=Wt(),$b=Buffer[Symbol.species],Vb=Buffer.from([0,0,255,255]),To=Symbol("permessage-deflate"),Kt=Symbol("total-length"),Cr=Symbol("callback"),yn=Symbol("buffers"),Rr=Symbol("error"),Ao,id=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,!Ao){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Ao=new Kb(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[Cr];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){Ao.add(o=>{this._decompress(e,r,(c,l)=>{o(),i(c,l)})})}compress(e,r,i){Ao.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[To]=this,this._inflate[Kt]=0,this._inflate[yn]=[],this._inflate.on("error",Zb),this._inflate.on("data",dh)}this._inflate[Cr]=i,this._inflate.write(e),r&&this._inflate.write(Vb),this._inflate.flush(()=>{let c=this._inflate[Rr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let l=ah.concat(this._inflate[yn],this._inflate[Kt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Kt]=0,this._inflate[yn]=[],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[Kt]=0,this._deflate[yn]=[],this._deflate.on("data",Jb)}this._deflate[Cr]=i,this._deflate.write(e),this._deflate.flush(Fi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=ah.concat(this._deflate[yn],this._deflate[Kt]);r&&(c=new $b(c.buffer,c.byteOffset,c.length-4)),this._deflate[Cr]=null,this._deflate[Kt]=0,this._deflate[yn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};lh.exports=id;function Jb(t){this[yn].push(t),this[Kt]+=t.length}function dh(t){if(this[Kt]+=t.length,this[To]._maxPayload<1||this[Kt]<=this[To]._maxPayload){this[yn].push(t);return}this[Rr]=new RangeError("Max payload size exceeded"),this[Rr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Rr][ch]=1009,this.removeListener("data",dh),this.reset()}function Zb(t){if(this[To]._inflate=null,this[Rr]){this[Cr](this[Rr]);return}t[ch]=1007,this[Cr](t)}});var Pr=ie((i3,Co)=>{"use strict";var{isUtf8:uh}=ce("buffer"),{hasBlob:Xb}=Wt(),Yb=[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 sd(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 eE(t){return Xb&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Co.exports={isBlob:eE,isValidStatusCode:Qb,isValidUTF8:sd,tokenChars:Yb};if(uh)Co.exports.isValidUTF8=function(t){return t.length<24?sd(t):uh(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=ce("utf-8-validate");Co.exports.isValidUTF8=function(e){return e.length<32?sd(e):t(e)}}catch{}});var ld=ie((s3,wh)=>{"use strict";var{Writable:tE}=ce("stream"),fh=Dr(),{BINARY_TYPES:nE,EMPTY_BUFFER:hh,kStatusCode:rE,kWebSocket:iE}=Wt(),{concat:od,toArrayBuffer:sE,unmask:oE}=zi(),{isValidStatusCode:aE,isValidUTF8:xh}=Pr(),Ro=Buffer[Symbol.species],ct=0,ph=1,gh=2,mh=3,ad=4,cd=5,Do=6,dd=class extends tE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||nE[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[iE]=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 Ro(i.buffer,i.byteOffset+e,i.length-e),new Ro(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 Ro(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 ph:this.getPayloadLength16(e);break;case gh:this.getPayloadLength64(e);break;case mh:this.getMask();break;case ad:this.getData(e);break;case cd:case Do: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[fh.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=ph:this._payloadLength===127?this._state=gh: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=mh:this._state=ad}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=ad}getData(e){let r=hh;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&&oE(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=cd,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[fh.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===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=od(i,r):this._binaryType==="arraybuffer"?o=sE(od(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=ct):(this._state=Do,setImmediate(()=>{this.emit("message",o,!0),this._state=ct,this.startLoop(e)}))}else{let o=od(i,r);if(!this._skipUTF8Validation&&!xh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===cd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=ct):(this._state=Do,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,hh),this.end();else{let i=e.readUInt16BE(0);if(!aE(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Ro(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!xh(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=Do,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 l=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(l,this.createError),l.code=c,l[rE]=o,l}};wh.exports=dd});var hd=ie((a3,bh)=>{"use strict";var{Duplex:o3}=ce("stream"),{randomFillSync:cE}=ce("crypto"),_h=Dr(),{EMPTY_BUFFER:dE,kWebSocket:lE,NOOP:uE}=Wt(),{isBlob:kr,isValidStatusCode:fE}=Pr(),{mask:yh,toBuffer:Un}=zi(),dt=Symbol("kByteLength"),hE=Buffer.alloc(4),Po=8*1024,Gn,Or=Po,yt=0,xE=1,pE=2,ud=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=yt,this.onerror=uE,this[lE]=void 0}static frame(e,r){let i,o=!1,c=2,l=!1;r.mask&&(i=r.maskBuffer||hE,r.generateMask?r.generateMask(i):(Or===Po&&(Gn===void 0&&(Gn=Buffer.alloc(Po)),cE(Gn,0,Po),Or=0),i[0]=Gn[Or++],i[1]=Gn[Or++],i[2]=Gn[Or++],i[3]=Gn[Or++]),l=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||l)&&r[dt]!==void 0?u=r[dt]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!l);let h=u;u>=65536?(c+=8,h=127):u>125&&(c+=2,h=126);let p=Buffer.allocUnsafe(o?u+c:c);return p[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(p[0]|=64),p[1]=h,h===126?p.writeUInt16BE(u,2):h===127&&(p[2]=p[3]=0,p.writeUIntBE(u,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?(yh(e,i,p,c,u),[p]):(yh(e,i,e,0,u),[p,e])):[p,e]}close(e,r,i,o){let c;if(e===void 0)c=dE;else{if(typeof e!="number"||!fE(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 u=Buffer.byteLength(r);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof r=="string"?c.write(r,2):c.set(r,2)}}let l={[dt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==yt?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):kr(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 l={[dt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};kr(e)?this._state!==yt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==yt?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):kr(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 l={[dt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};kr(e)?this._state!==yt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==yt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}send(e,r,i){let o=this._extensions[_h.extensionName],c=r.binary?2:1,l=r.compress,u,h;typeof e=="string"?(u=Buffer.byteLength(e),h=!1):kr(e)?(u=e.size,h=!1):(e=Un(e),u=e.length,h=Un.readOnly),this._firstFragment?(this._firstFragment=!1,l&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(l=u>=o._threshold),this._compress=l):(l=!1,c=0),r.fin&&(this._firstFragment=!0);let p={[dt]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:h,rsv1:l};kr(e)?this._state!==yt?this.enqueue([this.getBlobData,e,this._compress,p,i]):this.getBlobData(e,this._compress,p,i):this._state!==yt?this.enqueue([this.dispatch,e,this._compress,p,i]):this.dispatch(e,this._compress,p,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[dt],this._state=pE,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(fd,this,u,o);return}this._bufferedBytes-=i[dt];let l=Un(c);r?this.dispatch(l,r,i,o):(this._state=yt,this.sendFrame(t.frame(l,i),o),this.dequeue())}).catch(c=>{process.nextTick(gE,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[_h.extensionName];this._bufferedBytes+=i[dt],this._state=xE,c.compress(e,i.fin,(l,u)=>{if(this._socket.destroyed){let h=new Error("The socket was closed while data was being compressed");fd(this,h,o);return}this._bufferedBytes-=i[dt],this._state=yt,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===yt&&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)}};bh.exports=ud;function fd(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 gE(t,e,r){fd(t,e,r),t.onerror(e)}});var Dh=ie((c3,Rh)=>{"use strict";var{kForOnEventAttribute:Ui,kListener:xd}=Wt(),Eh=Symbol("kCode"),vh=Symbol("kData"),Sh=Symbol("kError"),Ih=Symbol("kMessage"),Ah=Symbol("kReason"),Nr=Symbol("kTarget"),Th=Symbol("kType"),Ch=Symbol("kWasClean"),$t=class{constructor(e){this[Nr]=null,this[Th]=e}get target(){return this[Nr]}get type(){return this[Th]}};Object.defineProperty($t.prototype,"target",{enumerable:!0});Object.defineProperty($t.prototype,"type",{enumerable:!0});var qn=class extends $t{constructor(e,r={}){super(e),this[Eh]=r.code===void 0?0:r.code,this[Ah]=r.reason===void 0?"":r.reason,this[Ch]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Eh]}get reason(){return this[Ah]}get wasClean(){return this[Ch]}};Object.defineProperty(qn.prototype,"code",{enumerable:!0});Object.defineProperty(qn.prototype,"reason",{enumerable:!0});Object.defineProperty(qn.prototype,"wasClean",{enumerable:!0});var Lr=class extends $t{constructor(e,r={}){super(e),this[Sh]=r.error===void 0?null:r.error,this[Ih]=r.message===void 0?"":r.message}get error(){return this[Sh]}get message(){return this[Ih]}};Object.defineProperty(Lr.prototype,"error",{enumerable:!0});Object.defineProperty(Lr.prototype,"message",{enumerable:!0});var Gi=class extends $t{constructor(e,r={}){super(e),this[vh]=r.data===void 0?null:r.data}get data(){return this[vh]}};Object.defineProperty(Gi.prototype,"data",{enumerable:!0});var mE={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Ui]&&o[xd]===e&&!o[Ui])return;let i;if(t==="message")i=function(c,l){let u=new Gi("message",{data:l?c:c.toString()});u[Nr]=this,ko(e,this,u)};else if(t==="close")i=function(c,l){let u=new qn("close",{code:c,reason:l.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Nr]=this,ko(e,this,u)};else if(t==="error")i=function(c){let l=new Lr("error",{error:c,message:c.message});l[Nr]=this,ko(e,this,l)};else if(t==="open")i=function(){let c=new $t("open");c[Nr]=this,ko(e,this,c)};else return;i[Ui]=!!r[Ui],i[xd]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[xd]===e&&!r[Ui]){this.removeListener(t,r);break}}};Rh.exports={CloseEvent:qn,ErrorEvent:Lr,Event:$t,EventTarget:mE,MessageEvent:Gi};function ko(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Oo=ie((d3,Ph)=>{"use strict";var{tokenChars:qi}=Pr();function Mt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function wE(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,l,u,h=-1,p=-1,_=-1,E=0;for(;E<t.length;E++)if(p=t.charCodeAt(E),l===void 0)if(_===-1&&qi[p]===1)h===-1&&(h=E);else if(E!==0&&(p===32||p===9))_===-1&&h!==-1&&(_=E);else if(p===59||p===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${E}`);_===-1&&(_=E);let b=t.slice(h,_);p===44?(Mt(e,b,r),r=Object.create(null)):l=b,h=_=-1}else throw new SyntaxError(`Unexpected character at index ${E}`);else if(u===void 0)if(_===-1&&qi[p]===1)h===-1&&(h=E);else if(p===32||p===9)_===-1&&h!==-1&&(_=E);else if(p===59||p===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${E}`);_===-1&&(_=E),Mt(r,t.slice(h,_),!0),p===44&&(Mt(e,l,r),r=Object.create(null),l=void 0),h=_=-1}else if(p===61&&h!==-1&&_===-1)u=t.slice(h,E),h=_=-1;else throw new SyntaxError(`Unexpected character at index ${E}`);else if(o){if(qi[p]!==1)throw new SyntaxError(`Unexpected character at index ${E}`);h===-1?h=E:i||(i=!0),o=!1}else if(c)if(qi[p]===1)h===-1&&(h=E);else if(p===34&&h!==-1)c=!1,_=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(_===-1&&qi[p]===1)h===-1&&(h=E);else if(h!==-1&&(p===32||p===9))_===-1&&(_=E);else if(p===59||p===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${E}`);_===-1&&(_=E);let b=t.slice(h,_);i&&(b=b.replace(/\\/g,""),i=!1),Mt(r,u,b),p===44&&(Mt(e,l,r),r=Object.create(null),l=void 0),u=void 0,h=_=-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");_===-1&&(_=E);let A=t.slice(h,_);return l===void 0?Mt(e,A,r):(u===void 0?Mt(r,A,!0):i?Mt(r,u,A.replace(/\\/g,"")):Mt(r,u,A),Mt(e,l,r)),e}function _E(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(", ")}Ph.exports={format:_E,parse:wE}});var Bo=ie((f3,jh)=>{"use strict";var yE=ce("events"),bE=ce("https"),EE=ce("http"),Nh=ce("net"),vE=ce("tls"),{randomBytes:SE,createHash:IE}=ce("crypto"),{Duplex:l3,Readable:u3}=ce("stream"),{URL:pd}=ce("url"),bn=Dr(),AE=ld(),TE=hd(),{isBlob:CE}=Pr(),{BINARY_TYPES:kh,CLOSE_TIMEOUT:RE,EMPTY_BUFFER:No,GUID:DE,kForOnEventAttribute:gd,kListener:PE,kStatusCode:kE,kWebSocket:Fe,NOOP:Lh}=Wt(),{EventTarget:{addEventListener:OE,removeEventListener:NE}}=Dh(),{format:LE,parse:ME}=Oo(),{toBuffer:BE}=zi(),Mh=Symbol("kAborted"),md=[8,13],Vt=["CONNECTING","OPEN","CLOSING","CLOSED"],zE=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,pe=class t extends yE{constructor(e,r,i){super(),this._binaryType=kh[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=No,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]),Bh(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){kh.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 AE({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new TE(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",GE),o.on("drain",qE),o.on("error",jE),o.on("message",HE),o.on("ping",WE),o.on("pong",KE),c.onerror=$E,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Uh),e.on("data",Mo),e.on("end",Gh),e.on("error",qh),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[bn.extensionName]&&this._extensions[bn.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){rt(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())}),Fh(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){wd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||No,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){wd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||No,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){wd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[bn.extensionName]||(o.compress=!1),this._sender.send(e||No,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){rt(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:Vt.indexOf("CONNECTING")});Object.defineProperty(pe.prototype,"CONNECTING",{enumerable:!0,value:Vt.indexOf("CONNECTING")});Object.defineProperty(pe,"OPEN",{enumerable:!0,value:Vt.indexOf("OPEN")});Object.defineProperty(pe.prototype,"OPEN",{enumerable:!0,value:Vt.indexOf("OPEN")});Object.defineProperty(pe,"CLOSING",{enumerable:!0,value:Vt.indexOf("CLOSING")});Object.defineProperty(pe.prototype,"CLOSING",{enumerable:!0,value:Vt.indexOf("CLOSING")});Object.defineProperty(pe,"CLOSED",{enumerable:!0,value:Vt.indexOf("CLOSED")});Object.defineProperty(pe.prototype,"CLOSED",{enumerable:!0,value:Vt.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[gd])return e[PE];return null},set(e){for(let r of this.listeners(t))if(r[gd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[gd]:!0})}})});pe.prototype.addEventListener=OE;pe.prototype.removeEventListener=NE;jh.exports=pe;function Bh(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:RE,protocolVersion:md[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,!md.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${md.join(", ")})`);let c;if(e instanceof pd)c=e;else try{c=new pd(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:",u=c.protocol==="ws+unix:",h;if(c.protocol!=="ws:"&&!l&&!u?h=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!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,_=SE(16).toString("base64"),E=l?bE.request:EE.request,A=new Set,b;if(o.createConnection=o.createConnection||(l?UE:FE),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":_,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(b=new bn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=LE({[bn.extensionName]:b.offer()})),r.length){for(let I of r){if(typeof I!="string"||!zE.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}`),u){let I=o.path.split(":");o.socketPath=I[0],o.path=I[1]}let v;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=l,t._originalHostOrSocketPath=u?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=u?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",()=>{rt(t,v,"Opening handshake has timed out")}),v.on("error",I=>{v===null||v[Mh]||(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){rt(t,v,"Maximum redirects exceeded");return}v.abort();let N;try{N=new pd(S,e)}catch{let D=new SyntaxError(`Invalid URL: ${S}`);Lo(t,D);return}Bh(t,N,r,i)}else t.emit("unexpected-response",v,I)||rt(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 N=I.headers.upgrade;if(N===void 0||N.toLowerCase()!=="websocket"){rt(t,S,"Invalid Upgrade header");return}let y=IE("sha1").update(_+DE).digest("base64");if(I.headers["sec-websocket-accept"]!==y){rt(t,S,"Invalid Sec-WebSocket-Accept header");return}let D=I.headers["sec-websocket-protocol"],P;if(D!==void 0?A.size?A.has(D)||(P="Server sent an invalid subprotocol"):P="Server sent a subprotocol but none was requested":A.size&&(P="Server sent no subprotocol"),P){rt(t,S,P);return}D&&(t._protocol=D);let M=I.headers["sec-websocket-extensions"];if(M!==void 0){if(!b){rt(t,S,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let z;try{z=ME(M)}catch{rt(t,S,"Invalid Sec-WebSocket-Extensions header");return}let $=Object.keys(z);if($.length!==1||$[0]!==bn.extensionName){rt(t,S,"Server indicated an extension that was not requested");return}try{b.accept(z[bn.extensionName])}catch{rt(t,S,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[bn.extensionName]=b}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 FE(t){return t.path=t.socketPath,Nh.connect(t)}function UE(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Nh.isIP(t.host)?"":t.host),vE.connect(t)}function rt(t,e,r){t._readyState=pe.CLOSING;let i=new Error(r);Error.captureStackTrace(i,rt),e.setHeader?(e[Mh]=!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 wd(t,e,r){if(e){let i=CE(e)?e.size:BE(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Vt[t.readyState]})`);process.nextTick(r,i)}}function GE(t,e){let r=this[Fe];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Fe]!==void 0&&(r._socket.removeListener("data",Mo),process.nextTick(zh,r._socket),t===1005?r.close():r.close(t,e))}function qE(){let t=this[Fe];t.isPaused||t._socket.resume()}function jE(t){let e=this[Fe];e._socket[Fe]!==void 0&&(e._socket.removeListener("data",Mo),process.nextTick(zh,e._socket),e.close(t[kE])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Oh(){this[Fe].emitClose()}function HE(t,e){this[Fe].emit("message",t,e)}function WE(t){let e=this[Fe];e._autoPong&&e.pong(t,!this._isServer,Lh),e.emit("ping",t)}function KE(t){this[Fe].emit("pong",t)}function zh(t){t.resume()}function $E(t){let e=this[Fe];e.readyState!==pe.CLOSED&&(e.readyState===pe.OPEN&&(e._readyState=pe.CLOSING,Fh(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Fh(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Uh(){let t=this[Fe];if(this.removeListener("close",Uh),this.removeListener("data",Mo),this.removeListener("end",Gh),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",Oh),t._receiver.on("finish",Oh))}function Mo(t){this[Fe]._receiver.write(t)||this.pause()}function Gh(){let t=this[Fe];t._readyState=pe.CLOSING,t._receiver.end(),this.end()}function qh(){let t=this[Fe];this.removeListener("error",qh),this.on("error",Lh),t&&(t._readyState=pe.CLOSING,this.destroy())}});var $h=ie((x3,Kh)=>{"use strict";var h3=Bo(),{Duplex:VE}=ce("stream");function Hh(t){t.emit("close")}function JE(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Wh(t){this.removeListener("error",Wh),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function ZE(t,e){let r=!0,i=new VE({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,l){let u=!l&&i._readableState.objectMode?c.toString():c;i.push(u)||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(Hh,i);return}let l=!1;t.once("error",function(h){l=!0,c(h)}),t.once("close",function(){l||c(o),process.nextTick(Hh,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",JE),i.on("error",Wh),i}Kh.exports=ZE});var _d=ie((p3,Vh)=>{"use strict";var{tokenChars:XE}=Pr();function YE(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&&XE[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 u=t.slice(r,i);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);e.add(u),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}Vh.exports={parse:YE}});var tx=ie((m3,ex)=>{"use strict";var QE=ce("events"),zo=ce("http"),{Duplex:g3}=ce("stream"),{createHash:ev}=ce("crypto"),Jh=Oo(),jn=Dr(),tv=_d(),nv=Bo(),{CLOSE_TIMEOUT:rv,GUID:iv,kWebSocket:sv}=Wt(),ov=/^[+/0-9A-Za-z]{22}==$/,Zh=0,Xh=1,Qh=2,yd=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:rv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:nv,...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=zo.createServer((i,o)=>{let c=zo.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=av(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=Zh}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(ji,this);return}if(e&&this.once("close",e),this._state!==Xh)if(this._state=Xh,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(ji,this):process.nextTick(ji,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{ji(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",Yh);let c=e.headers["sec-websocket-key"],l=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Hn(this,e,r,405,"Invalid HTTP method");return}if(l===void 0||l.toLowerCase()!=="websocket"){Hn(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!ov.test(c)){Hn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){Hn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Hi(r,400);return}let h=e.headers["sec-websocket-protocol"],p=new Set;if(h!==void 0)try{p=tv.parse(h)}catch{Hn(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let _=e.headers["sec-websocket-extensions"],E={};if(this.options.perMessageDeflate&&_!==void 0){let A=new jn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let b=Jh.parse(_);b[jn.extensionName]&&(A.accept(b[jn.extensionName]),E[jn.extensionName]=A)}catch{Hn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let A={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(A,(b,v,I,S)=>{if(!b)return Hi(r,v||401,I,S);this.completeUpgrade(E,c,p,e,r,i,o)});return}if(!this.options.verifyClient(A))return Hi(r,401)}this.completeUpgrade(E,c,p,e,r,i,o)}completeUpgrade(e,r,i,o,c,l,u){if(!c.readable||!c.writable)return c.destroy();if(c[sv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Zh)return Hi(c,503);let p=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${ev("sha1").update(r+iv).digest("base64")}`],_=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}`),_._protocol=E)}if(e[jn.extensionName]){let E=e[jn.extensionName].params,A=Jh.format({[jn.extensionName]:[E]});p.push(`Sec-WebSocket-Extensions: ${A}`),_._extensions=e}this.emit("headers",p,o),c.write(p.concat(`\r
10
+ `),this.stream=void 0;return}this.currentDate!==void 0&&ns(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 ig,mkdirSync as sg}from"node:fs";import{join as og}from"node:path";function cl(t){let e=t.retentionDays??dg,r=t.clock??(()=>An(new Date));is={bridgeSink:new $r(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new $r(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();ns(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])ns(t.agentLogsDir(o),"agent",i,e)}function lg(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function dl(t){ya=t}function ll(t){return er[ya]<=er[t]}function ul(t,e){let r=er[t];return r===void 0?!0:r>=er[e]}function ss(t){al={...t}}function fl(t){let e=(u,x=2)=>String(u).padStart(x,"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 At(t,e,r,i,o){try{let c=`${JSON.stringify({ts:fl(new Date),level:e,module:r,msg:i,...o})}
11
+ `;sg(t,{recursive:!0}),ig(og(t,Qn("bridge",An(new Date))),c)}catch{}}function ug(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function rs(t,e,r,i,o){if(er[t]<er[ya])return;let c=`${JSON.stringify({ts:fl(new Date),level:t,module:e,msg:r,...al,...i})}
12
+ `;if(is){let l=ug(o,i),u=l?lg(is,l):is.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?cg.write(c):ag.write(c)}function G(t,e){return{debug:(r,i)=>rs("debug",t,r,i,e),info:(r,i)=>rs("info",t,r,i,e),warn:(r,i)=>rs("warn",t,r,i,e),error:(r,i)=>rs("error",t,r,i,e),child:r=>G(`${t}.${r}`,e),forAgent:r=>G(t,r)}}var er,ya,ag,cg,al,dg,is,ne=Ve(()=>{"use strict";Xn();_a();er={debug:10,info:20,warn:30,error:40},ya=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),ag=process.stdout,cg=process.stderr,al={},dg=He("COZE_BRIDGE_LOG_RETENTION_DAYS",30),is=null});var T,We=Ve(()=>{"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 gl={};ma(gl,{ACP_WRAPPER_NPM_PACKAGES:()=>Zr,_resetAcpInstallerForTests:()=>mg,_setBinaryPathCacheForTests:()=>wg,buildAcpSpawn:()=>Yr,ensureAcpInstalled:()=>tr,getAcpBinaryPath:()=>os,pickWhichLine:()=>va,probeAcpVersion:()=>gg,resolveAcpCommand:()=>pl});import{readFileSync as xl}from"node:fs";import{createRequire as fg}from"node:module";import{dirname as xg,resolve as hg}from"node:path";function va(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 pg(t){let e=hl.resolve(`${t.npmPackage}/package.json`),r=xg(e),i=JSON.parse(xl(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 hg(r,o)}async function tr(t,e){let r=ba[t];if(!r)throw new T("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=Vr.get(t);if(i)return i;try{let o=pg(r);return Vr.set(t,o),Ea.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw Ea.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 gg(t){let e=ba[t];if(e)try{let r=hl.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(xl(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){Ea.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function os(t){return Vr.get(t)}function pl(t,e){if(e)return e;let r=os(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 Yr(t,e,r){if(e)return{command:e,args:[...r]};let i=pl(t);return{command:process.execPath,args:[i,...r]}}function mg(){Vr.clear()}function wg(t,e){Vr.set(t,e)}var Ea,ba,Zr,hl,Vr,nn=Ve(()=>{"use strict";We();ne();Ea=G("agents.acp-installer"),ba={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},Zr=Object.values(ba).filter(t=>t!==void 0).map(t=>t.npmPackage),hl=fg(import.meta.url),Vr=new Map});import{chmod as yg,mkdir as Eg,readFile as bg,rename as _l,writeFile as yl}from"node:fs/promises";import{dirname as vg}from"node:path";async function nr(t){try{let e=await bg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function rr(t,e,r){await Eg(vg(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 yl(o,i,{encoding:"utf8",mode:r.mode}):await yl(o,i,"utf8"),await _l(o,t),r?.mode!==void 0&&await yg(t,r.mode)}catch(c){await _l(o,o).catch(()=>{});let{rm:l}=await import("node:fs/promises");throw await l(o,{force:!0}).catch(()=>{}),c}}var Jr=Ve(()=>{"use strict"});import{promises as El,readdirSync as Sg}from"node:fs";import{homedir as Ig}from"node:os";import{sep as Ag,join as Ae,resolve as bl}from"node:path";function J(t){let e=t??Ig(),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=J()){let r=Ae(e.agentsRoot,t);return{root:r,config:Ae(r,"config.json"),workspace:Ae(r,"workspace"),logs:Ae(r,"logs")}}function as(t=J()){try{return Sg(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function Xr(t,e){let r=await El.realpath(bl(t)).catch(()=>null);if(!r)return!1;let i=await El.realpath(bl(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+Ag)}var ke=Ve(()=>{"use strict"});var ls={};ma(ls,{AGENT_CONFIG_FILE_MODE:()=>cs,enforceAgentConfigMode:()=>Dg,loadAgentConfig:()=>Ge,persistAgentSessions:()=>Qr,persistAgentSkills:()=>ds,saveAgentConfig:()=>Ye});import{chmod as Tg,stat as Cg}from"node:fs/promises";function Ge(t,e){return nr(Ze(t,e).config)}function Ye(t,e){return rr(Ze(t.agentId,e).config,t,{mode:cs})}async function Dg(t,e){if(process.platform==="win32")return;let r=Ze(t,e).config;try{let i=await Cg(r);if(!i.isFile())return;let o=i.mode&511;o!==cs&&(await Tg(r,cs),vl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;vl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function Qr(t,e,r){let i=await Ge(t,r);i&&(i.sessions=Object.fromEntries(e),await Ye(i,r))}async function ds(t,e,r){let i=await Ge(t,r);i&&(i.skills=e,await Ye(i,r))}var vl,cs,rn=Ve(()=>{"use strict";Jr();ne();ke();vl=G("agent-config"),cs=384});var Ia=se((u2,Tl)=>{Tl.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 fs=se(Dl=>{var Cl={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 Ng(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(Cl))Dl[t]=Ng(Cl[t])});var Nl=se((x2,Ol)=>{var Lg=de("fs"),Pe=de("path"),Rl=Ia(),Mg=fs(),Bg=typeof process=="object"&&process.platform==="win32",kl=t=>typeof t=="object"&&t!==null,Pl=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=Pe.sep,this.fs=Lg,kl(t)&&kl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Ol.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(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(l&&l.isFile())throw Mg.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=Pe.dirname(t);o.fs.existsSync(l)||o.makeDir(l);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}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(u,x){if(l&&x.isDirectory())return o(!1);var p=Pe.dirname(t);c.fs.exists(p,function(w){w||c.makeDir(p),c.fs.open(t,"w",438,function(_,S){_?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(E,b){c.fs.write(b,e,0,e.length,0,function(){c.fs.close(b,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):S?c.fs.write(S,e,0,e.length,0,function(){c.fs.close(S,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(u){let x=Pe.join(i,u),p=e.fs.statSync(x);(!o||o.test(x))&&l.push(Pe.normalize(x)+(p.isDirectory()?e.sep:"")),p.isDirectory()&&c&&(l=l.concat(r(x,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(u){u=Pe.join(t,u),r.fs.stat(u,function(x,p){if(x)return e(x);p&&(i.push(Pe.normalize(u)+(p.isDirectory()?r.sep:"")),p.isDirectory()?r.findFilesAsync(u,function(w,_){if(w)return e(w);i=i.concat(_),--l||e(null,i)}):--l||e(null,i))})})})};be.prototype.getAttributes=function(){};be.prototype.setAttributes=function(){};be.crc32update=function(t,e){return Pl[(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 Rl.STORED:return"STORED ("+t+")";case Rl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};be.canonical=function(t){if(!t)return"";let e=Pe.posix.normalize("/"+t.split("\\").join("/"));return Pe.join(".",e)};be.zipnamefix=function(t){if(!t)return"";let e=Pe.posix.normalize("/"+t.split("\\").join("/"));return Pe.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=Pe.resolve(Pe.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Pe.normalize(Pe.join(t,r.slice(i,o).join(Pe.sep)));if(c.indexOf(t)===0)return c}return Pe.normalize(Pe.join(t,Pe.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=Bg;be.crcTable=Pl});var Ml=se((h2,Ll)=>{var zg=de("path");Ll.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=zg.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 zl=se((p2,Bl)=>{Bl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var or=se((g2,sr)=>{sr.exports=Nl();sr.exports.Constants=Ia();sr.exports.Errors=fs();sr.exports.FileAttr=Ml();sr.exports.decoder=zl()});var Ul=se((m2,Fl)=>{var sn=or(),U=sn.Constants;Fl.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,l=0,u=0,x=0,p=0,w=0,_=0,S=0,E=0,b=0;t|=sn.isWin?2560:768,r|=U.FLG_EFS;let A={extraLen:0},I=y=>Math.max(0,y)>>>0,C=y=>Math.max(0,y)&65535,O=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=I(y)},get timeHighByte(){return O(o>>>8)},get crc(){return c},set crc(y){c=I(y)},get compressedSize(){return l},set compressedSize(y){l=I(y)},get size(){return u},set size(y){u=I(y)},get fileNameLength(){return x},set fileNameLength(y){x=y},get extraLength(){return p},set extraLength(y){p=y},get extraLocalLength(){return A.extraLen},set extraLocalLength(y){A.extraLen=y},get commentLength(){return w},set commentLength(y){w=y},get diskNumStart(){return _},set diskNumStart(y){_=I(y)},get inAttr(){return S},set inAttr(y){S=I(y)},get attr(){return E},set attr(y){E=I(y)},get fileAttr(){return(E||0)>>16&4095},get offset(){return b},set offset(y){b=I(y)},get encrypted(){return(r&U.FLG_ENC)===U.FLG_ENC},get centralHeaderSize(){return U.CENHDR+x+p+w},get realDataOffset(){return b+U.LOCHDR+A.fnameLen+A.extraLen},get localHeader(){return A},loadLocalHeaderFromBinary:function(y){var D=y.slice(b,b+U.LOCHDR);if(D.readUInt32LE(0)!==U.LOCSIG)throw sn.Errors.INVALID_LOC();A.version=D.readUInt16LE(U.LOCVER),A.flags=D.readUInt16LE(U.LOCFLG),A.flags_desc=(A.flags&U.FLG_DESC)>0,A.method=D.readUInt16LE(U.LOCHOW),A.time=D.readUInt32LE(U.LOCTIM),A.crc=D.readUInt32LE(U.LOCCRC),A.compressedSize=D.readUInt32LE(U.LOCSIZ),A.size=D.readUInt32LE(U.LOCLEN),A.fnameLen=D.readUInt16LE(U.LOCNAM),A.extraLen=D.readUInt16LE(U.LOCEXT);let R=b+U.LOCHDR+A.fnameLen,M=R+A.extraLen;return y.slice(R,M)},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),u=y.readUInt32LE(U.CENLEN),x=y.readUInt16LE(U.CENNAM),p=y.readUInt16LE(U.CENEXT),w=y.readUInt16LE(U.CENCOM),_=y.readUInt16LE(U.CENDSK),S=y.readUInt16LE(U.CENATT),E=y.readUInt32LE(U.CENATX),b=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(u,U.LOCLEN),y.writeUInt16LE(x,U.LOCNAM),y.writeUInt16LE(A.extraLen,U.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(U.CENHDR+x+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(u,U.CENLEN),y.writeUInt16LE(x,U.CENNAM),y.writeUInt16LE(p,U.CENEXT),y.writeUInt16LE(w,U.CENCOM),y.writeUInt16LE(_,U.CENDSK),y.writeUInt16LE(S,U.CENATT),y.writeUInt32LE(E,U.CENATX),y.writeUInt32LE(b,U.CENOFF),y},toJSON:function(){let y=function(D){return D+" 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(u),fileNameLength:y(x),extraLength:y(p),commentLength:y(w),diskNumStart:_,inAttr:S,attr:E,offset:b,centralHeaderSize:y(U.CENHDR+x+p+w)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var ql=se((w2,Gl)=>{var ar=or(),me=ar.Constants;Gl.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 ar.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=ar.readBigUInt64LE(c,me.ZIP64SUB),e=ar.readBigUInt64LE(c,me.ZIP64TOT),r=ar.readBigUInt64LE(c,me.ZIP64SIZE),i=ar.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,u){let x=l.toString(16).toUpperCase();for(;x.length<u;)x="0"+x;return"0x"+x};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Ta=se(Aa=>{Aa.EntryHeader=Ul();Aa.MainHeader=ql()});var jl=se((y2,Hl)=>{Hl.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(u){c.push(u),l+=u.length}),o.on("end",function(){var u=Buffer.alloc(l),x=0;u.fill(0);for(var p=0;p<c.length;p++){var w=c[p];w.copy(u,x),x+=w.length}i&&i(u)}),o.end(t)}}}});var Kl=se((E2,Wl)=>{var Fg=+(process.versions?process.versions.node:"").split(".")[0]||0;Wl.exports=function(t,e){var r=de("zlib");let i=Fg>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),l=[],u=0;c.on("data",function(x){l.push(x),u+=x.length}),c.on("end",function(){var x=Buffer.alloc(u),p=0;x.fill(0);for(var w=0;w<l.length;w++){var _=l[w];_.copy(x,p),p+=_.length}o&&o(x)}),c.end(t)}}}});var Jl=se((b2,Yl)=>{"use strict";var{randomFillSync:$l}=de("crypto"),Ug=fs(),Gg=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}),Zl=(t,e)=>Math.imul(t,e)>>>0,Vl=(t,e)=>Gg[(t^e)&255]^t>>>8,ei=()=>typeof $l=="function"?$l(Buffer.alloc(12)):ei.node();ei.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 xs={genSalt:ei};function hs(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])}hs.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Vl(e[0],t),e[1]+=e[0]&255,e[1]=Zl(e[1],134775813)+1,e[2]=Vl(e[2],e[1]>>>24),t};hs.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Zl(t,t^1)>>8&255};function qg(t){let e=new hs(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 Hg(t){let e=new hs(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 jg(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=qg(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Ug.WRONG_PASSWORD();return i(t.slice(12))}function Wg(t){Buffer.isBuffer(t)&&t.length>=12?xs.genSalt=function(){return t.slice(0,12)}:t==="node"?xs.genSalt=ei.node:xs.genSalt=ei}function Kg(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Hg(r),c=xs.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)}Yl.exports={decrypt:jg,encrypt:Kg,_salter:Wg}});var Xl=se(ps=>{ps.Deflater=jl();ps.Inflater=Kl();ps.ZipCrypto=Jl()});var Da=se((S2,Ql)=>{var oe=or(),$g=Ta(),ve=oe.Constants,Ca=Xl();Ql.exports=function(t,e){var r=new $g.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,l=null,u=Buffer.alloc(0),x=Buffer.alloc(0),p=!0;let w=t,_=typeof w.decoder=="object"?w.decoder:oe.decoder;p=_.hasOwnProperty("efs")?_.efs:!1;function S(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(x=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function E(y){if(!r.flags_desc&&!r.localHeader.flags_desc){if(oe.crc32(y)!==r.localHeader.crc)return!1}else{let D={},R=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(R)==ve.LOCSIG||e.readUInt32LE(R)==ve.CENSIG)throw oe.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(R)==ve.EXTSIG)D.crc=e.readUInt32LE(R+ve.EXTCRC),D.compressedSize=e.readUInt32LE(R+ve.EXTSIZ),D.size=e.readUInt32LE(R+ve.EXTLEN);else if(e.readUInt16LE(R+12)===19280)D.crc=e.readUInt32LE(R+ve.EXTCRC-4),D.compressedSize=e.readUInt32LE(R+ve.EXTSIZ-4),D.size=e.readUInt32LE(R+ve.EXTLEN-4);else throw oe.Errors.DESCRIPTOR_UNKNOWN();if(D.compressedSize!==r.compressedSize||D.size!==r.size||D.crc!==r.crc)throw oe.Errors.DESCRIPTOR_FAULTY();if(oe.crc32(y)!==D.crc)return!1}return!0}function b(y,D,R){if(typeof D>"u"&&typeof y=="string"&&(R=y,y=void 0),c)return y&&D&&D(Buffer.alloc(0),oe.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var M=S();if(M.length===0)return y&&D&&D(M),M;if(r.encrypted){if(typeof R!="string"&&!Buffer.isBuffer(R))throw oe.Errors.INVALID_PASS_PARAM();M=Ca.ZipCrypto.decrypt(M,r,R)}var z=Buffer.alloc(r.size);switch(r.method){case oe.Constants.STORED:if(M.copy(z),E(z))return y&&D&&D(z),z;throw y&&D&&D(z,oe.Errors.BAD_CRC()),oe.Errors.BAD_CRC();case oe.Constants.DEFLATED:var $=new Ca.Inflater(M,r.size);if(y)$.inflateAsync(function(V){V.copy(V,0),D&&(E(V)?D(V):D(V,oe.Errors.BAD_CRC()))});else{if($.inflate(z).copy(z,0),!E(z))throw oe.Errors.BAD_CRC(`"${_.decode(i)}"`);return z}break;default:throw y&&D&&D(Buffer.alloc(0),oe.Errors.UNKNOWN_METHOD()),oe.Errors.UNKNOWN_METHOD()}}function A(y,D){if((!l||!l.length)&&Buffer.isBuffer(e))return y&&D&&D(S()),S();if(l.length&&!c){var R;switch(r.method){case oe.Constants.STORED:return r.compressedSize=r.size,R=Buffer.alloc(l.length),l.copy(R),y&&D&&D(R),R;default:case oe.Constants.DEFLATED:var M=new Ca.Deflater(l);if(y)M.deflateAsync(function($){R=Buffer.alloc($.length),r.compressedSize=$.length,$.copy(R),D&&D(R)});else{var z=M.deflate();return r.compressedSize=z.length,z}M=null;break}}else if(y&&D)D(Buffer.alloc(0));else return Buffer.alloc(0)}function I(y,D){return oe.readBigUInt64LE(y,D)}function C(y){try{for(var D=0,R,M,z;D+4<y.length;)R=y.readUInt16LE(D),D+=2,M=y.readUInt16LE(D),D+=2,z=y.slice(D,D+M),D+=M,ve.ID_ZIP64===R&&O(z)}catch{throw oe.Errors.EXTRA_FIELD_PARSE_ERROR()}}function O(y){var D,R,M,z;y.length>=ve.EF_ZIP64_SCOMP&&(D=I(y,ve.EF_ZIP64_SUNCOMP),r.size===ve.EF_ZIP64_OR_32&&(r.size=D)),y.length>=ve.EF_ZIP64_RHO&&(R=I(y,ve.EF_ZIP64_SCOMP),r.compressedSize===ve.EF_ZIP64_OR_32&&(r.compressedSize=R)),y.length>=ve.EF_ZIP64_DSN&&(M=I(y,ve.EF_ZIP64_RHO),r.offset===ve.EF_ZIP64_OR_32&&(r.offset=M)),y.length>=ve.EF_ZIP64_DSN+4&&(z=y.readUInt32LE(ve.EF_ZIP64_DSN),r.diskNumStart===ve.EF_ZIP64_OR_16&&(r.diskNumStart=z))}return{get entryName(){return _.decode(i)},get rawEntryName(){return i},set entryName(y){i=oe.toBuffer(y,_.encode);var D=i[i.length-1];c=D===47||D===92,r.fileNameLength=i.length},get efs(){return typeof p=="function"?p(this.entryName):p},get extra(){return u},set extra(y){u=y,r.extraLength=y.length,C(y)},get comment(){return _.decode(o)},set comment(y){if(o=oe.toBuffer(y,_.encode),r.commentLength=o.length,o.length>65535)throw oe.Errors.COMMENT_TOO_LONG()},get name(){var y=_.decode(i);return c?y.substr(y.length-1).split("/").pop():y.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return A(!1,null)},getCompressedDataAsync:function(y){A(!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:b(!1,null,y)},getDataAsync:function(y,D){r.changed?y(l):b(!0,y,D)},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=u.length;var y=r.centralHeaderToBinary(),D=oe.Constants.CENHDR;return i.copy(y,D),D+=i.length,u.copy(y,D),D+=r.extraLength,o.copy(y,D),y},packLocalHeader:function(){let y=0;r.flags_efs=this.efs,r.extraLocalLength=x.length;let D=r.localHeaderToBinary(),R=Buffer.alloc(D.length+i.length+r.extraLocalLength);return D.copy(R,y),y+=D.length,i.copy(R,y),y+=i.length,x.copy(R,y),y+=x.length,R},toJSON:function(){let y=function(D){return"<"+(D&&D.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 nu=se((I2,tu)=>{var eu=Da(),Vg=Ta(),qe=or();tu.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new Vg.MainHeader,l=!1,u=null;let x=new Set,p=e,{noSort:w,decoder:_}=p;t?b(p.readEntries):l=!0;function S(){let I=new Set;for(let C of Object.keys(i)){let O=C.split("/");if(O.pop(),!!O.length)for(let y=0;y<O.length;y++){let D=O.slice(0,y+1).join("/")+"/";I.add(D)}}for(let C of I)if(!(C in i)){let O=new eu(p);O.entryName=C,O.attr=16,O.temporary=!0,r.push(O),i[O.entryName]=O,x.add(O)}}function E(){if(l=!0,i={},c.diskEntries>(t.length-c.offset)/qe.Constants.CENHDR)throw qe.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var I=c.offset,C=0;C<r.length;C++){var O=I,y=new eu(p,t);y.header=t.slice(O,O+=qe.Constants.CENHDR),y.entryName=t.slice(O,O+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(O,O+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(O,O+y.header.commentLength)),I+=y.header.centralHeaderSize,r[C]=y,i[y.entryName]=y}x.clear(),S()}function b(I){var C=t.length-qe.Constants.ENDHDR,O=Math.max(0,C-65535),y=O,D=t.length,R=-1,M=0;for(typeof p.trailingSpace=="boolean"&&p.trailingSpace&&(O=0),C;C>=y;C--)if(t[C]===80){if(t.readUInt32LE(C)===qe.Constants.ENDSIG){R=C,M=C,D=C+qe.Constants.ENDHDR,y=C-qe.Constants.END64HDR;continue}if(t.readUInt32LE(C)===qe.Constants.END64SIG){y=O;continue}if(t.readUInt32LE(C)===qe.Constants.ZIP64SIG){R=C,D=C+qe.readBigUInt64LE(t,C+qe.Constants.ZIP64SIZE)+qe.Constants.ZIP64LEAD;break}}if(R==-1)throw qe.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(R,D)),c.commentLength&&(o=t.slice(M+qe.Constants.ENDHDR)),I&&E()}function A(){r.length>1&&!w&&r.sort((I,C)=>I.entryName.toLowerCase().localeCompare(C.entryName.toLowerCase()))}return{get entries(){return l||E(),r.filter(I=>!x.has(I))},get comment(){return _.decode(o)},set comment(I){o=qe.toBuffer(I,_.encode),c.commentLength=o.length},getEntryCount:function(){return l?r.length:c.diskEntries},forEach:function(I){this.entries.forEach(I)},getEntry:function(I){return l||E(),i[I]||null},setEntry:function(I){l||E(),r.push(I),i[I.entryName]=I,c.totalEntries=r.length},deleteFile:function(I,C=!0){l||E();let O=i[I];this.getEntryChildren(O,C).map(D=>D.entryName).forEach(this.deleteEntry)},deleteEntry:function(I){l||E();let C=i[I],O=r.indexOf(C);O>=0&&(r.splice(O,1),delete i[I],c.totalEntries=r.length)},getEntryChildren:function(I,C=!0){if(l||E(),typeof I=="object")if(I.isDirectory&&C){let O=[],y=I.entryName;for(let D of r)D.entryName.startsWith(y)&&O.push(D);return O}else return[I];return[]},getChildCount:function(I){if(I&&I.isDirectory){let C=this.getEntryChildren(I);return C.includes(I)?C.length-1:C.length}return 0},compressToBuffer:function(){l||E(),A();let I=[],C=[],O=0,y=0;c.size=0,c.offset=0;let D=0;for(let z of this.entries){let $=z.getCompressedData();z.header.offset=y;let V=z.packLocalHeader(),te=V.length+$.length;y+=te,I.push(V),I.push($);let X=z.packCentralHeader();C.push(X),c.size+=X.length,O+=te+X.length,D++}O+=c.mainHeaderSize,c.offset=y,c.totalEntries=D,y=0;let R=Buffer.alloc(O);for(let z of I)z.copy(R,y),y+=z.length;for(let z of C)z.copy(R,y),y+=z.length;let M=c.toBinary();return o&&o.copy(M,qe.Constants.ENDHDR),M.copy(R,y),t=R,l=!1,R},toAsyncBuffer:function(I,C,O,y){try{l||E(),A();let D=[],R=[],M=0,z=0,$=0;c.size=0,c.offset=0;let V=function(te){if(te.length>0){let X=te.shift(),Ee=X.entryName+X.extra.toString();O&&O(Ee),X.getCompressedDataAsync(function(xe){y&&y(Ee),X.header.offset=z;let N=X.packLocalHeader(),q=N.length+xe.length;z+=q,D.push(N),D.push(xe);let j=X.packCentralHeader();R.push(j),c.size+=j.length,M+=q+j.length,$++,V(te)})}else{M+=c.mainHeaderSize,c.offset=z,c.totalEntries=$,z=0;let X=Buffer.alloc(M);D.forEach(function(xe){xe.copy(X,z),z+=xe.length}),R.forEach(function(xe){xe.copy(X,z),z+=xe.length});let Ee=c.toBinary();o&&o.copy(Ee,qe.Constants.ENDHDR),Ee.copy(X,z),t=X,l=!1,I(X)}};V(Array.from(this.entries))}catch(D){C(D)}}}}});var su=se((A2,iu)=>{var _e=or(),we=de("path"),Zg=Da(),Yg=nu(),Tn=(...t)=>_e.findLast(t,e=>typeof e=="boolean"),ru=(...t)=>_e.findLast(t,e=>typeof e=="string"),Jg=(...t)=>_e.findLast(t,e=>typeof e=="function"),Xg={noSort:!1,readEntries:!1,method:_e.Constants.NONE,fs:null};iu.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),Xg);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 Yg(r,i),{canonical:l,sanitize:u,zipnamefix:x}=_e;function p(E){if(E&&c){var b;if(typeof E=="string"&&(b=c.getEntry(we.posix.normalize(E))),typeof E=="object"&&typeof E.entryName<"u"&&typeof E.header<"u"&&(b=c.getEntry(E.entryName)),b)return b}return null}function w(E){let{join:b,normalize:A,sep:I}=we.posix;return b(we.isAbsolute(E)?"/":".",A(I+E.split("\\").join(I)+I))}function _(E){return E instanceof RegExp?(function(b){return function(A){return b.test(A)}})(E):typeof E!="function"?()=>!0:E}let S=(E,b)=>{let A=b.slice(-1);return A=A===o.sep?o.sep:"",we.relative(E,b)+A};return{readFile:function(E,b){var A=p(E);return A&&A.getData(b)||null},childCount:function(E){let b=p(E);if(b)return c.getChildCount(b)},readFileAsync:function(E,b){var A=p(E);A?A.getDataAsync(b):b(null,"getEntry failed for:"+E)},readAsText:function(E,b){var A=p(E);if(A){var I=A.getData();if(I&&I.length)return I.toString(b||"utf8")}return""},readAsTextAsync:function(E,b,A){var I=p(E);I?I.getDataAsync(function(C,O){if(O){b(C,O);return}C&&C.length?b(C.toString(A||"utf8")):b("")}):b("")},deleteFile:function(E,b=!0){var A=p(E);A&&c.deleteFile(A.entryName,b)},deleteEntry:function(E){var b=p(E);b&&c.deleteEntry(b.entryName)},addZipComment:function(E){c.comment=E},getZipComment:function(){return c.comment||""},addZipEntryComment:function(E,b){var A=p(E);A&&(A.comment=b)},getZipEntryComment:function(E){var b=p(E);return b&&b.comment||""},updateFile:function(E,b){var A=p(E);A&&A.setData(b)},addLocalFile:function(E,b,A,I){if(o.fs.existsSync(E)){b=b?w(b):"";let C=we.win32.basename(we.win32.normalize(E));b+=A||C;let O=o.fs.statSync(E),y=O.isFile()?o.fs.readFileSync(E):Buffer.alloc(0);O.isDirectory()&&(b+=o.sep),this.addFile(b,y,I,O)}else throw _e.Errors.FILE_NOT_FOUND(E)},addLocalFileAsync:function(E,b){E=typeof E=="object"?E:{localPath:E};let A=we.resolve(E.localPath),{comment:I}=E,{zipPath:C,zipName:O}=E,y=this;o.fs.stat(A,function(D,R){if(D)return b(D,!1);C=C?w(C):"";let M=we.win32.basename(we.win32.normalize(A));if(C+=O||M,R.isFile())o.fs.readFile(A,function(z,$){return z?b(z,!1):(y.addFile(C,$,I,R),setImmediate(b,void 0,!0))});else if(R.isDirectory())return C+=o.sep,y.addFile(C,Buffer.alloc(0),I,R),setImmediate(b,void 0,!0)})},addLocalFolder:function(E,b,A){if(A=_(A),b=b?w(b):"",E=we.normalize(E),o.fs.existsSync(E)){let I=o.findFiles(E),C=this;if(I.length)for(let O of I){let y=we.join(b,S(E,O));A(y)&&C.addLocalFile(O,we.dirname(y))}}else throw _e.Errors.FILE_NOT_FOUND(E)},addLocalFolderAsync:function(E,b,A,I){I=_(I),A=A?w(A):"",E=we.normalize(E);var C=this;o.fs.open(E,"r",function(O){if(O&&O.code==="ENOENT")b(void 0,_e.Errors.FILE_NOT_FOUND(E));else if(O)b(void 0,O);else{var y=o.findFiles(E),D=-1,R=function(){if(D+=1,D<y.length){var M=y[D],z=S(E,M).split("\\").join("/");z=z.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),I(z)?o.fs.stat(M,function($,V){$&&b(void 0,$),V.isFile()?o.fs.readFile(M,function(te,X){te?b(void 0,te):(C.addFile(A+z,X,"",V),R())}):(C.addFile(A+z+"/",Buffer.alloc(0),"",V),R())}):process.nextTick(()=>{R()})}else b(!0,void 0)};R()}})},addLocalFolderAsync2:function(E,b){let A=this;E=typeof E=="object"?E:{localPath:E},localPath=we.resolve(w(E.localPath));let{zipPath:I,filter:C,namefix:O}=E;C instanceof RegExp?C=(function(R){return function(M){return R.test(M)}})(C):typeof C!="function"&&(C=function(){return!0}),I=I?w(I):"",O=="latin1"&&(O=R=>R.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof O!="function"&&(O=R=>R);let y=R=>we.join(I,O(S(localPath,R))),D=R=>we.win32.basename(we.win32.normalize(O(R)));o.fs.open(localPath,"r",function(R){R&&R.code==="ENOENT"?b(void 0,_e.Errors.FILE_NOT_FOUND(localPath)):R?b(void 0,R):o.findFilesAsync(localPath,function(M,z){if(M)return b(M);z=z.filter($=>C(y($))),z.length||b(void 0,!1),setImmediate(z.reverse().reduce(function($,V){return function(te,X){if(te||X===!1)return setImmediate($,te,!1);A.addLocalFileAsync({localPath:V,zipPath:we.dirname(y(V)),zipName:D(V)},$)}},b))})})},addLocalFolderPromise:function(E,b){return new Promise((A,I)=>{this.addLocalFolderAsync2(Object.assign({localPath:E},b),(C,O)=>{C&&I(C),O&&A(this)})})},addFile:function(E,b,A,I){E=x(E);let C=p(E),O=C!=null;O||(C=new Zg(i),C.entryName=E),C.comment=A||"";let y=typeof I=="object"&&I instanceof o.fs.Stats;y&&(C.header.time=I.mtime);var D=C.isDirectory?16:0;let R=C.isDirectory?16384:32768;return y?R|=4095&I.mode:typeof I=="number"?R|=4095&I:R|=C.isDirectory?493:420,D=(D|R<<16)>>>0,C.attr=D,C.setData(b),O||c.setEntry(C),C},getEntries:function(E){return c.password=E,c?c.entries:[]},getEntry:function(E){return p(E)},getEntryCount:function(){return c.getEntryCount()},forEach:function(E){return c.forEach(E)},extractEntryTo:function(E,b,A,I,C,O){I=Tn(!1,I),C=Tn(!1,C),A=Tn(!0,A),O=ru(C,O);var y=p(E);if(!y)throw _e.Errors.NO_ENTRY();var D=l(y.entryName),R=u(b,O&&!y.isDirectory?O:A?D:we.basename(D));if(y.isDirectory){var M=c.getEntryChildren(y);return M.forEach(function(V){if(V.isDirectory)return;var te=V.getData();if(!te)throw _e.Errors.CANT_EXTRACT_FILE();var X=l(V.entryName),Ee=u(b,A?X:we.basename(X));let xe=C?V.header.fileAttr:void 0;o.writeFileTo(Ee,te,I,xe)}),!0}var z=y.getData(c.password);if(!z)throw _e.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(R)&&!I)throw _e.Errors.CANT_OVERRIDE();let $=C?E.header.fileAttr:void 0;return o.writeFileTo(R,z,I,$),!0},test:function(E){if(!c)return!1;for(var b in c.entries)try{if(b.isDirectory)continue;var A=c.entries[b].getData(E);if(!A)return!1}catch{return!1}return!0},extractAllTo:function(E,b,A,I){if(A=Tn(!1,A),I=ru(A,I),b=Tn(!1,b),!c)throw _e.Errors.NO_ZIP();c.entries.forEach(function(C){var O=u(E,l(C.entryName));if(C.isDirectory){o.makeDir(O);return}var y=C.getData(I);if(!y)throw _e.Errors.CANT_EXTRACT_FILE();let D=A?C.header.fileAttr:void 0;o.writeFileTo(O,y,b,D);try{o.fs.utimesSync(O,C.header.time,C.header.time)}catch{throw _e.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(E,b,A,I){if(I=Jg(b,A,I),A=Tn(!1,A),b=Tn(!1,b),!I)return new Promise((R,M)=>{this.extractAllToAsync(E,b,A,function(z){z?M(z):R(this)})});if(!c){I(_e.Errors.NO_ZIP());return}E=we.resolve(E);let C=R=>u(E,we.normalize(l(R.entryName))),O=(R,M)=>new Error(R+': "'+M+'"'),y=[],D=[];c.entries.forEach(R=>{R.isDirectory?y.push(R):D.push(R)});for(let R of y){let M=C(R),z=A?R.header.fileAttr:void 0;try{o.makeDir(M),z&&o.fs.chmodSync(M,z),o.fs.utimesSync(M,R.header.time,R.header.time)}catch{I(O("Unable to create folder",M))}}D.reverse().reduce(function(R,M){return function(z){if(z)R(z);else{let $=we.normalize(l(M.entryName)),V=u(E,$);M.getDataAsync(function(te,X){if(X)R(X);else if(!te)R(_e.Errors.CANT_EXTRACT_FILE());else{let Ee=A?M.header.fileAttr:void 0;o.writeFileToAsync(V,te,b,Ee,function(xe){xe||R(O("Unable to write file",V)),o.fs.utimes(V,M.header.time,M.header.time,function(N){N?R(O("Unable to set times",V)):R()})})}})}}},I)()},writeZip:function(E,b){if(arguments.length===1&&typeof E=="function"&&(b=E,E=""),!E&&i.filename&&(E=i.filename),!!E){var A=c.compressToBuffer();if(A){var I=o.writeFileTo(E,A,!0);typeof b=="function"&&b(I?null:new Error("failed"),"")}}},writeZipPromise:function(E,b){let{overwrite:A,perm:I}=Object.assign({overwrite:!0},b);return new Promise((C,O)=>{!E&&i.filename&&(E=i.filename),E||O("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let D=R=>R?C(R):O("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(E,y,A,I,D)},O)})},toBufferPromise:function(){return new Promise((E,b)=>{c.toAsyncBuffer(E,b)})},toBuffer:function(E,b,A,I){return typeof E=="function"?(c.toAsyncBuffer(E,b,A,I),null):c.compressToBuffer()}}}});import{execFile as q_,spawn as H_,spawnSync as FA}from"node:child_process";import{promisify as j_}from"node:util";function K_(t){if(process.platform!=="win32")return!1;if(Q0.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(Q0,"").toLowerCase();return W_.has(r)}function ef(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 dt(t,e=[],r={}){return H_(t,e,ef(t,r))}function tf(t,e=[],r={}){return $_(t,e,ef(t,r))}var W_,Q0,$_,yn=Ve(()=>{"use strict";W_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Q0=/\.(cmd|bat|ps1)$/i;$_=j_(q_)});var sx=se(ye=>{"use strict";var B=F;(function(t,e){let r=F,i=t();for(;;)try{if(-parseInt(r(1160))/1+-parseInt(r(1340))/2+parseInt(r(1707))/3*(parseInt(r(232))/4)+parseInt(r(514))/5+parseInt(r(649))/6+parseInt(r(439))/7+parseInt(r(1005))/8*(parseInt(r(453))/9)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(To,202418);var zE=Object[B(582)+B(1754)],FE=Object[B(1283)+B(523)+B(188)],ex=(t,e)=>function(){return t&&(e=(0,t[{KmNfV:function(c,l){return c(l)}}[B(1050)](FE,t)[0]])(t=0)),e},UE=(t,e)=>{let r={BzWlU:function(o,c,l,u){return o(c,l,u)}};for(var i in e)r.BzWlU(zE,t,i,{get:e[i],enumerable:!0})};function GE(){return Zf||(Zf=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function qE(){let t=B;return Yf||(Yf=[IDBCursor.prototype[t(1149)],IDBCursor[t(952)+"e"][t(1344)],IDBCursor.prototype[t(1344)+t(390)+"ey"]])}function HE(t){let e=B,r={WxlMy:function(o,c){return o(c)},Vidri:e(1235),WeGox:"success",laccL:function(o,c){return o instanceof c},kxdfU:function(o,c){return o===c},dPXFl:"ChyIs",cgtNJ:e(433)},i=new Promise((o,c)=>{let l=e,u={zPKCW:"success",vJlgd:r.Vidri},x=()=>{let _=F;t["removeEv"+_(1245)+_(761)](u[_(498)],p),t[_(861)+_(1245)+_(761)](u.vJlgd,w)},p=()=>{let _=F;r[_(716)](o,Bt(t[_(549)])),x()},w=()=>{r[F(716)](c,t.error),x()};t[l(1717)+l(1040)](r[l(405)],p),t["addEvent"+l(1040)](l(1235),w)});return i[e(1252)](o=>{let c=e;if(r[c(900)](o,IDBCursor)){if(r[c(545)](r[c(576)],r[c(1476)]))return this[c(1465)+"s"][this.currentIndex];nd.set(o,t)}}).catch(()=>{}),Io[e(1312)](i,t),i}function jE(t){let e=B,r={karbj:function(o,c){return o===c},qhpDQ:"mxbdS",adLON:function(o,c){return o(c)},YGLTW:e(719)+"or",FIWLX:function(o){return o()},ugWyq:e(950),Dvtyh:e(1235),MALVr:e(852),OqOfa:function(o,c){return o!==c},qntel:e(1701),LvDjN:e(1638),VxMZu:function(o){return o()}};if(So[e(1204)](t))return;let i=new Promise((o,c)=>{let l=e,u={HeknP:r[l(670)],FyzVv:r[l(505)],aFiSN:r.MALVr,XYIlf:function(_,S){return r[l(792)](_,S)},sprDO:r[l(1080)],DPDga:r[l(572)],ZDdvD:function(_){return r[l(1588)](_)},herGp:function(_){return r.VxMZu(_)}},x=()=>{let _=l;t[_(861)+_(1245)+"ner"](u[_(342)],p),t["removeEv"+_(1245)+_(761)](u.FyzVv,w),t[_(861)+_(1245)+_(761)](u[_(640)],w)},p=()=>{let _=l;if(u.XYIlf(u.sprDO,u.DPDga))u[_(1087)](o),u.herGp(x);else return!!this._qosDB},w=()=>{let _=l,S={NZnOs:_(1739)};r[_(721)](_(1006),r[_(626)])?(this[_(797)](S.NZnOs,_0xe86819),this[_(184)]&&this[_(184)](_0x358e6f)):(r[_(1454)](c,t[_(1235)]||new DOMException(r[_(1374)],r[_(1374)])),r[_(1588)](x))};t[l(1717)+l(1040)](l(950),p),t[l(1717)+l(1040)](r.Dvtyh,w),t[l(1717)+l(1040)](r[l(643)],w)});So.set(t,i)}function WE(t){Ao=t(Ao)}function KE(t){let e=B,r={giJBa:function(i,o){return i(o)},FicJM:function(i,o){return i(o)},AfSMz:function(i,o,c,l){return i(o,c,l)},sjaIf:function(i,o){return i(o)},OYuMv:function(i,o){return i===o},osjcQ:function(i,o){return i in o},UwBEg:e(1600)+e(570)};if(r.OYuMv(t,IDBDatabase[e(952)+"e"].transaction)&&!r[e(286)](r.UwBEg,IDBTransaction[e(952)+"e"]))return function(i,...o){let c=e,l=t.call(r[c(208)](Gi,this),i,...o);return td[c(1312)](l,i[c(1251)]?i.sort():[i]),r[c(208)](Bt,l)};if(qE()[e(443)](t)){if(e(423)!==e(1603))return function(...i){let o=e;return t[o(1211)](r[o(899)](Gi,this),i),r[o(208)](Bt,nd[o(267)](this))};r[e(760)](_0xcd8d47,this,_0x1127a6,[_0x16dc3a,_0x49de35,_0x4a376e])}return function(...i){let o=e;return r[o(208)](Bt,t[o(1211)](r.sjaIf(Gi,this),i))}}function $E(t){let e=B,r={tYsPW:function(i,o){return i===o},jgArj:function(i,o){return i(o)},lCRij:function(i,o){return i instanceof o},jTmBF:function(i,o){return i(o)},OZnBI:function(i,o,c){return i(o,c)},pMJlJ:function(i){return i()}};return r[e(583)](typeof t,e(543))?r[e(1164)](KE,t):(r.lCRij(t,IDBTransaction)&&r[e(1352)](jE,t),r[e(831)](tx,t,r[e(259)](GE))?new Proxy(t,Ao):t)}function Bt(t){let e=B,r={llvkR:function(o,c){return o instanceof c},HeovP:function(o,c){return o(c)},MsqXB:function(o,c){return o!==c}};if(r[e(1099)](t,IDBRequest))return r[e(875)](HE,t);if(bo[e(1204)](t))return bo[e(267)](t);let i=r[e(875)]($E,t);return r[e(337)](i,t)&&(bo[e(1312)](t,i),Io[e(1312)](i,t)),i}var tx,Zf,Yf,nd,So,td,bo,Io,Ao,Gi,Jf=ex({"node_modules/idb/build/wrap-idb-value.js"(){let t=B,e={aqlFT:function(r,i){return r instanceof i},pCPqX:function(r,i){return r===i},IxWAh:function(r,i){return r===i},LSFMW:function(r,i){return r===i},lneUr:function(r,i){return r===i},NOftC:t(1292),Mddwu:function(r,i){return r instanceof i},uXQNo:function(r,i){return r===i},Efkwv:t(579),varpT:function(r,i){return r in i}};tx=(r,i)=>i.some(o=>r instanceof o),nd=new WeakMap,So=new WeakMap,td=new WeakMap,bo=new WeakMap,Io=new WeakMap,Ao={get(r,i,o){let c=t;if(e[c(740)](r,IDBTransaction)){if(e[c(959)](i,c(579)))return So[c(267)](r);if(e[c(1200)](i,"objectSt"+c(570)))return r.objectStoreNames||td[c(267)](r);if(e[c(558)](i,c(1371)))return o[c(1600)+c(570)][1]?void 0:o["objectSt"+c(1639)](o[c(1600)+c(570)][0])}return Bt(r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;if(e[o(1022)](e[o(735)],"cpuAK"))_0x33e048[o(1229)][o(1172)+o(346)](_0x1c71e3);else return e[o(686)](r,IDBTransaction)&&(e[o(447)](i,e[o(1516)])||e[o(447)](i,o(1371)))?!0:e[o(982)](i,r)}},Gi=r=>Io.get(r)}}),nx={};UE(nx,{deleteDB:()=>ZE,openDB:()=>VE,unwrap:()=>Gi,wrap:()=>Bt});function VE(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let l=B,u={hupoR:function(w,_,S,E,b){return w(_,S,E,b)},ZcrXB:function(w,_){return w(_)},pGBVI:function(w,_){return w(_)},ZKSML:l(734),cRAKl:function(w){return w()},FTNso:l(1739),VjgyW:l(1066)+l(469),kQAki:function(w,_){return w(_)},pzeRA:l(1389),gnABE:"wCIWu",Yzswr:l(269)},x=indexedDB[l(1665)](t,e),p=u[l(597)](Bt,x);return i&&(u.pzeRA!==u[l(1653)]?x[l(1717)+l(1040)](l(677)+l(1205),w=>{let _=l;u[_(1500)](i,u[_(688)](Bt,x[_(549)]),w[_(1092)+"on"],w[_(1015)+"on"],u[_(499)](Bt,x[_(718)+_(495)]))}):(this[l(1093)](u[l(1722)],_0x370fc8.message),u[l(741)](_0x3c74fc))),r&&x.addEventListener(u[l(563)],()=>r()),p[l(1252)](w=>{let _=l;c&&w.addEventListener(u[_(898)],()=>c()),o&&w["addEvent"+_(1040)](u[_(632)],()=>o())})[l(542)](()=>{}),p}function ZE(t,{blocked:e}={}){let r=B,i={UdJpB:r(269),HSLEP:function(c,l){return c(l)}},o=indexedDB[r(1288)+r(908)](t);return e&&o[r(1717)+r(1040)](i.UdJpB,()=>e()),i[r(537)](Bt,o)[r(1252)](()=>{})}function Xf(t,e){let r=B,i={WKMbe:r(517)+"e",ZZfTy:"readonly",cjKFK:function(x,p){return x instanceof p},yzvOL:function(x,p){return x in p},ttGeZ:"string",vdSTd:r(428),DGeLK:function(x,p){return x!==p}};if(!(i[r(784)](t,IDBDatabase)&&!i[r(464)](e,t)&&typeof e===i[r(1620)]))return i[r(1033)]!==i[r(1033)]?(_0xe65603+=_0x539995&&_0x32bffe.byteLength||0,_0x5de408):void 0;if(vo[r(267)](e))return vo[r(267)](e);let o=e.replace(/FromIndex$/,""),c=i.DGeLK(e,o),l=ix.includes(o);if(!(o in(c?IDBIndex:IDBObjectStore)[r(952)+"e"])||!(l||rx[r(443)](o)))return;let u=async function(x,...p){let w=r,_=this[w(718)+w(495)](x,l?i[w(880)]:i[w(1644)]),S=_.store;return c&&(S=S.index(p[w(1051)]())),(await Promise[w(467)]([S[o](...p),l&&_[w(579)]]))[0]};return vo[r(1312)](e,u),u}var rx,ix,vo,YE=ex({"node_modules/idb/build/index.js"(){let t=B,e={vYRLi:function(o){return o()},LFDLf:function(o,c){return o(c)},sIRfc:t(267),NlKmW:"getKey",HYJAn:t(1068),uuIWZ:t(1393),bmtcc:t(345),hyRog:t(1316),jluta:t(1467)},r=(t(997)+t(465))[t(1405)]("|"),i=0;for(;;){switch(r[i++]){case"0":e[t(1195)](Jf);continue;case"1":e[t(573)](WE,o=>({...o,get:(c,l,u)=>Xf(c,l)||o[t(267)](c,l,u),has:(c,l)=>!!Xf(c,l)||o[t(1204)](c,l)}));continue;case"2":vo=new Map;continue;case"3":rx=[e[t(1727)],e.NlKmW,t(1446),t(1504)+"ys",e[t(1480)]];continue;case"4":Jf();continue;case"5":ix=[e[t(1276)],e[t(496)],e[t(565)],e[t(733)]];continue}break}}}),JE={idb:function(t){let e=B;t.exports=Promise[e(1244)]()[e(1252)](()=>(YE(),nx)).then(function(r){return r})}},Qf={};function Mt(t){let e=B,r={MQyFz:function(u,x){return u!==x}},i="1|0|2|4|3".split("|"),o=0;for(;;){switch(i[o++]){case"0":if(r[e(628)](void 0,c))return c[e(1681)];continue;case"1":var c=Qf[t];continue;case"2":var l=Qf[t]={exports:{}};continue;case"3":return l[e(1681)];case"4":JE[t](l,l[e(1681)],Mt);continue}break}}Mt.d=(t,e)=>{let r=F;for(var i in e)Mt.o(e,i)&&!Mt.o(t,i)&&Object[r(582)+r(1754)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=B;Mt.o=(e,r)=>Object[t(952)+"e"].hasOwnProperty[t(1642)](e,r)})(),(()=>{let t=B,e={xAkbN:function(r,i){return r+i},qjWfC:function(r,i){return r!==i},xMrGW:t(304),hgsbo:function(r,i){return r!=i},dKDxd:t(427)+"d",hmqWz:"__esModule"};Mt.r=r=>{let i=t,o={qqvlH:function(c,l){return e[F(910)](c,l)}};if(e[i(386)](e[i(812)],e.xMrGW)){let c=ye["_message"+i(1152)][i(1112)]((l,u)=>(l+=u&&u[i(275)+"th"]||0,l),0);return o[i(217)](c,ye[i(581)]?ye[i(581)][i(1619)+i(803)]:0)}else e.hgsbo(e[i(1259)],typeof Symbol)&&Symbol["toString"+i(1137)]&&Object[i(582)+i(1754)](r,Symbol[i(636)+i(1137)],{value:i(466)}),Object[i(582)+i(1754)](r,e.hmqWz,{value:!0})}})();var Ce={};(()=>{let t=B,e={xcuoC:function(a,n){return a(n)},BTOWj:function(a,n){return a+n},tccmv:t(646),GHJCg:function(a,n){return a+n},MhqfY:function(a,n){return a*n},TLOqK:function(a,n){return a===n},nMavK:"GPCJd",DgMjp:function(a,n){return a(n)},JygSI:function(a,n,s){return a(n,s)},eQudk:function(a,n){return a(n)},XabHN:t(864),imwcd:function(a,n){return a(n)},xQoqw:t(341)+t(341)+"0000000000000000",VmKYv:function(a,n){return a||n},thYbx:t(1739),NHeaC:t(1333),ljCzl:function(a){return a()},fzEDi:function(a,n){return a(n)},kTgHH:function(a,n){return a===n},ZSbTV:t(1064),lkIzt:function(a,n){return a>n},VtCcF:function(a,n){return a!==n},SYiaP:"TCmMp",LthhO:function(a,n){return a<n},hfsVe:function(a,n){return a>n},AErXb:function(a,n){return a<n},IHCkq:function(a,n){return a-n},hyGla:function(a,n){return a<n},VzDaU:function(a,n){return a===n},RXoEV:function(a,n){return a===n},BCEFz:t(695),OxDEg:function(a,n){return a===n},EHZXy:t(902),kGYRM:t(1067),OMsBv:t(678)+"0",VjzQT:function(a,n){return a+n},ncKsX:function(a,n){return a<n},wDqcm:function(a,n){return a!==n},xRNoM:function(a,n){return a!==n},rbfKU:t(472),QXILT:function(a,n,s){return a(n,s)},febCx:function(a,n){return a>=n},cnLnr:function(a,n){return a|n},BvJiC:function(a,n){return a&n},XLtbC:function(a,n,s){return a(n,s)},yaQAe:function(a,n){return a>>>n},pNPNl:function(a,n){return a<<n},rnBDb:function(a,n){return a>>>n},DvRCj:function(a,n){return a<n},SkesD:function(a,n){return a<n},IvLBT:function(a,n,s){return a(n,s)},MqHSH:function(a,n){return a&n},vSpDT:function(a,n){return a+n},asxEv:function(a,n){return a>>>n},wynmM:function(a,n){return a>>>n},axeuO:function(a,n){return a&n},rCYwt:function(a,n){return a+n},xsMsy:function(a,n){return a>>>n},IkkFM:function(a,n){return a>>>n},RcRPT:function(a,n){return a|n},sFBbk:function(a,n){return a+n},DZayu:function(a,n){return a&n},tOXgN:function(a,n){return a>>>n},xhSfq:function(a,n){return a+n},IGTAA:function(a,n){return a!==n},cVcxQ:function(a,n){return a|n},bWuHO:function(a,n){return a>>>n},HhIhy:function(a,n){return a&n},zDeto:function(a,n){return a&n},dtGVi:function(a,n){return a!==n},nhrTA:function(a,n){return a|n},BWrhO:t(400),dSyrg:"oJDnp",AMBxp:function(a,n){return a===n},PlvFY:t(1699),Nqzpb:function(a,n){return a>>>n},oQobM:function(a,n,s){return a(n,s)},Miocy:function(a,n){return a(n)},GVqFI:function(a,n){return a&n},GKJpE:t(1592)+"required"+t(877)+"key",LBJad:function(a,n){return a===n},XrSSD:function(a,n){return a(n)},IGiVv:t(1235),pabbp:function(a,n,s){return a(n,s)},KPUCc:function(a,n,s){return a(n,s)},PdVnG:function(a,n){return a!==n},WwYLY:function(a,n){return a!==n},yMaBs:t(1646),TvUgM:function(a,n,s){return a(n,s)},BvmvS:function(a,n,s){return a(n,s)},KqOry:function(a,n){return a!==n},RuVNl:function(a,n){return a===n},tuHDm:t(1240),RPFlk:function(a,n,s){return a(n,s)},KSgxj:function(a,n,s){return a(n,s)},uscuQ:function(a,n){return a(n)},mTMMg:function(a,n,s){return a(n,s)},xyQXq:function(a,n){return a!==n},IcMsH:t(375),jiglG:function(a,n){return a(n)},WyIsi:function(a,n){return a(n)},Jixbz:function(a,n){return a(n)},Vaqlt:function(a,n,s){return a(n,s)},mQqbK:function(a,n){return a&n},XPFoM:t(1592)+t(1632)+t(877)+t(309),hsJxL:function(a,n){return a===n},ocYcr:function(a,n){return a===n},UMuhp:t(1592)+t(1632)+t(877)+t(1686),fiJkf:t(621)+"3|4|2|6",qorxP:function(a,n){return a===n},OeXNd:t(418)+"s alread"+t(253),uenyN:"close, w"+t(825)+t(1397)+t(363)+"ed",GpUXj:function(a,n){return a!==n},adeYy:t(844),gYhGX:function(a,n){return a(n)},XTJqn:function(a,n){return a(n)},rOYCp:function(a,n){return a+n},LUKmG:function(a,n){return a>>n},cWyon:function(a,n){return a>=n},JtjPA:function(a,n){return a===n},IstOD:"drnaI",uZVIW:function(a,n){return a|n},QdxvI:function(a,n){return a&n},anCMx:function(a,n){return a>n},rnOYt:t(1079),NAlmh:"rBDkc",lItXM:"Skip pas"+t(1462),QYxNp:t(1675),akEYV:t(873)+t(838)+"s",bLOgp:"ping_onc"+t(1740)+"t",LVcBs:function(a,n){return a>n},rCPYe:function(a,n){return a===n},EBAgG:"WpEKj",RtsBf:function(a,n){return a>n},pCQQg:t(995)+t(1462),wRfdv:function(a,n,s){return a(n,s)},qkgwm:function(a,n){return a<n},EYaqk:t(1191),ubeaV:function(a,n){return a+n},ySQJa:function(a,n){return a(n)},PGRBq:function(a,n){return a===n},SYCiE:function(a,n){return a>=n},iShtI:function(a,n){return a+n},BgEgx:function(a,n){return a+n},bHoel:function(a,n){return a+n},YKtpe:function(a,n){return a&n},RAcKH:function(a,n){return a|n},cIzJu:function(a,n){return a<<n},pvrXJ:function(a,n){return a&n},teNcy:function(a,n){return a==n},uhrTP:function(a,n){return a>=n},vRJuw:t(1233),uUWkr:function(a,n){return a&n},oMBuE:function(a,n){return a===n},DNTCh:t(653),rpCix:function(a,n){return a<<n},ABgIL:function(a,n){return a&n},SZSvm:function(a,n){return a<n},yqLkt:function(a,n){return a>=n},HDwHB:function(a,n){return a<=n},KXpAj:function(a,n){return a(n)},rBDwo:function(a,n){return a==n},drAlh:function(a,n){return a>=n},WrNzz:function(a,n){return a+n},jPcbI:function(a,n){return a+n},aIDKg:function(a,n){return a+n},sRjYD:function(a,n){return a|n},PTfUB:function(a,n){return a<<n},Tuvhs:function(a,n){return a<<n},GSKKv:function(a,n){return a|n},qRuka:function(a,n){return a<<n},wklWU:function(a,n){return a&n},HXUjs:function(a,n){return a+n},PWJAn:function(a,n){return a+n},qaOiI:function(a,n){return a<<n},zBSlm:function(a,n,s){return a(n,s)},mHaER:function(a,n){return a<n},mOwDL:function(a,n){return a<<n},rjotX:function(a,n){return a<n},qIYuN:function(a,n){return a|n},CjfIt:function(a,n){return a>>n},nIFBg:function(a,n){return a|n},hQbkQ:function(a,n){return a&n},rYHrA:function(a,n){return a>>n},rVjIV:function(a,n){return a|n},VfhVn:function(a,n){return a>>n},RpdMG:function(a,n){return a|n},IKQOc:function(a,n){return a&n},rVDBI:function(a,n){return a&n},Wwwsy:function(a,n,s){return a(n,s)},qJJTe:function(a,n){return a(n)},yawcu:function(a,n){return a<<n},dmnRV:function(a,n){return a&n},ClPez:function(a,n){return a&n},TRIYj:function(a,n){return a|n},NkicM:function(a,n){return a&n},CtjQA:function(a,n){return a<<n},NXkfr:t(1495),jbxvh:t(195),ybCBK:function(a,n){return a(n)},vJktC:function(a,n){return a&n},VuCeQ:"OeVTu",JIpdF:function(a,n){return a(n)},RUKip:function(a,n){return a&n},pxZAO:function(a,n){return a&n},cLzvU:function(a,n){return a(n)},fgonj:function(a,n){return a<<n},SHKsp:function(a,n){return a&n},ErAkF:function(a,n){return a(n)},fHSJC:t(706),ZzaMO:t(398),hCoib:function(a,n){return a&n},YXZET:function(a,n){return a&n},Mmabs:function(a,n){return a(n)},wqvMO:function(a,n){return a<<n},gKAXK:function(a,n){return a<<n},mJedb:function(a,n){return a>>>n},HPRls:function(a,n){return a<n},zmgVF:function(a,n){return a<n},SHSFR:function(a,n){return a<n},KqBRr:function(a,n){return a<n},QnglZ:function(a,n){return a<n},CSVQv:function(a,n){return a>>>n},RalJI:function(a,n){return a!==n},bfMpN:function(a,n){return a|n},ddAfS:function(a,n){return a&n},wuZps:function(a,n){return a>>>n},wkOHW:function(a,n){return a|n},CgkGI:function(a,n){return a>>>n},naxcd:function(a,n){return a&n},wjnHh:function(a,n){return a>>>n},nnjPh:function(a,n){return a+n},ZKwcN:function(a,n){return a!==n},lxrvi:function(a,n){return a|n},GUFgu:function(a,n){return a&n},dZzRM:function(a,n){return a>>>n},ntwAn:function(a,n){return a!==n},gMfWI:function(a,n){return a&n},dGZdi:function(a,n){return a|n},nnzru:function(a,n){return a>>>n},hAVVN:function(a,n){return a+n},iuyuC:function(a,n){return a|n},pYnaq:function(a,n){return a>>>n},SBoWx:function(a,n){return a>>>n},CujFN:function(a,n){return a!==n},JazcO:function(a,n){return a|n},JgcjQ:function(a,n){return a>>>n},ynsFI:function(a,n){return a&n},QoDON:function(a,n){return a(n)},sqLmG:function(a,n){return a===n},AYzbN:function(a,n){return a<<n},ABmrp:function(a,n){return a<<n},IsTzF:function(a,n){return a|n},onnOC:function(a,n){return a|n},WSbNW:function(a,n){return a<<n},lWVpz:function(a,n){return a<<n},NDtvc:function(a,n){return a|n},xfjUl:function(a,n){return a|n},WutPt:function(a,n){return a|n},rWGtz:function(a,n){return a<<n},Atdts:function(a,n){return a>>>n},ewKbx:function(a,n){return a&n},XdWRh:function(a,n){return a&n},ILdqN:function(a,n){return a&n},idmzO:function(a,n){return a>>>n},tBqCx:function(a,n){return a>>>n},ykDke:function(a,n){return a>=n},jTkDQ:function(a,n){return a/n},yQtFy:function(a,n){return a>>>n},iopyR:function(a,n){return a*n},lozOV:function(a,n){return a===n},dSngB:function(a,n){return a&n},NwClR:function(a,n){return a>>>n},xPnNr:function(a,n){return a+n},rrOWO:function(a,n){return a>>>n},yCUxm:function(a,n){return a<<n},axZyd:function(a,n){return a|n},kjdKn:function(a,n){return a===n},maWHG:function(a,n){return a>>>n},rTIzv:function(a,n){return a>>>n},VPxfe:function(a,n){return a===n},uuhcv:function(a,n){return a+n},YnvDe:function(a,n){return a&n},XWgzG:function(a,n){return a&n},bXDWO:function(a,n){return a>>>n},PNjLL:function(a,n){return a&n},BQYEu:function(a,n){return a&n},OrUql:function(a,n){return a>>>n},cFOtj:function(a,n){return a&n},ijKuG:function(a,n){return a(n)},UgXHE:t(729),bjgmU:t(272),pPNDQ:function(a,n){return a&n},GOApW:function(a,n){return a&n},mIQba:function(a,n){return a>>>n},jcUAS:function(a,n){return a>>>n},KluqR:function(a,n){return a&n},PbxRt:function(a,n){return a>>>n},aABJV:function(a,n){return a&n},GdQmv:function(a,n){return a>=n},iiKWV:"nkwCc",xmHEH:t(1448)+t(551),iwZlD:t(1014)+t(1559),HoCLs:t(1188)+t(524),UnNoa:function(a,n){return a|n},kqQYk:function(a,n){return a!==n},TRuuG:t(759),nwxuH:t(1027)+"2",rgpDl:"VBqJW",BGfgQ:t(1030),EOhYr:function(a,n){return a!==n},TPpRK:t(817),NMXgD:t(1468),vIKqt:"QJmci",Adump:function(a,n){return a!==n},ngSmG:t(1428),svzfI:t(762),rCyGO:function(a,n,s){return a(n,s)},VgGEG:t(1153),eVWQK:t(1365),UfrRI:function(a,n){return a===n},FJqPn:function(a,n){return a+n},PLyvT:"Unhandle"+t(975),pTKxN:function(a,n){return a+n},jTNqv:function(a,n){return a+n},pDOJA:function(a,n){return a===n},ObPqA:function(a,n){return a===n},euIQc:function(a,n,s){return a(n,s)},MRMSi:t(1665),oIUNn:"message",CAFfh:function(a,n,s){return a(n,s)},olgvC:function(a,n,s){return a(n,s)},ptVEk:function(a,n,s){return a(n,s)},pfYnb:function(a,n){return a instanceof n},QbpjR:function(a,n){return a+n},GNhvU:function(a,n){return a!==n},Wzpik:"NbnaB",qAObA:function(a,n){return a!==n},NrsBq:t(630),HbuaO:function(a,n){return a||n},YaChC:function(a,n){return a!=n},ENGaz:t(427)+"d",cbBtv:t(319)+"0",XgScf:function(a,n){return a||n},nWqcR:function(a,n){return a!=n},HnpNS:t(692)+t(1190)+t(1201)+t(629)+t(434),kwOXC:function(a,n){return a===n},xrbHa:t(1032),NqVET:"RCZzJ",PTexC:function(a,n){return a(n)},DoVMT:function(a,n){return a===n},fmlzy:t(1129),PkpPE:t(532),EMCpJ:t(1382),YWGcy:function(a,n){return a<n},iMOUw:function(a,n){return a===n},ibpzN:function(a,n){return a&n},MBqto:function(a,n){return a===n},levPM:function(a,n){return a+n},iVobz:function(a,n){return a<n},GdaXh:function(a,n){return a|n},TGwiQ:function(a,n){return a&n},ixotz:function(a,n){return a|n},zfebq:function(a,n){return a|n},ftvhj:function(a,n){return a|n},vvPSi:function(a,n){return a|n},gPDYy:function(a,n){return a<<n},ekcpv:function(a,n){return a!==n},YBQLM:t(1165),WYCWf:function(a,n){return a<n},FfHxz:t(1690),ReGad:t(1576),AetAq:function(a,n){return a>>n},cOEAF:t(1412)+t(350),qeVyU:function(a,n){return a&n},rzvUE:function(a,n){return a>>n},IJvte:function(a,n){return a|n},ezTMB:function(a,n){return a&n},yodrX:function(a,n){return a+n},aUGOS:function(a,n){return a+n},ROGrc:function(a,n){return a|n},aEjor:function(a,n){return a&n},BCrxV:function(a,n){return a>>n},pAlBm:function(a,n,s,d){return a(n,s,d)},skhJX:t(1186),yGMSx:function(a,n){return a instanceof n},pFTlg:function(a,n){return a==n},zaaYV:"qHAPB",SiNgL:t(788),LxyfN:t(1486),liLFQ:t(944),MiMIW:function(a,n){return a+n},krOpz:t(654),qvMFL:"unknown "+t(1453),naqzC:function(a,n){return a===n},kgVLs:"vEnFU",eplmZ:t(850),AkgAP:function(a,n){return a(n)},toOxR:t(1121),hbQYJ:t(260),hYAdV:t(1243)+t(588),rAiJI:"&jscallb"+t(1610)+t(1167)+"P",WVNPQ:t(1227),AzqeP:t(687),TvjQe:function(a,n){return a!==n},peQeR:t(506),NslFJ:function(a,n){return a&n},qVhHG:function(a,n){return a>=n},nBzIj:function(a,n){return a<n},vikQh:function(a,n){return a<<n},lWzOI:function(a,n){return a&n},EZhNb:function(a,n){return a+n},gnZMR:t(810),YgPZf:t(331),EJSpl:t(992),SRXMy:t(1744),SHTxU:t(1485),eGUKA:t(1652),trpLa:t(969),sVkWh:t(739),lRCQc:function(a,n){return a+n},HEpAz:function(a,n){return a(n)},qsaxl:function(a,n){return a!==n},hVtqU:t(204),RVeWo:t(742),dluKF:t(1418)+t(283)+t(536)+"g",fvBZj:t(435),ZblSi:t(912),AsxWy:function(a,n){return a!==n},VRkbf:t(379),XITTv:function(a,n){return a||n},qnYNl:function(a,n){return a!==n},YPEus:t(557),kayAh:function(a,n){return a===n},AcsVZ:t(1269),JlBLL:t(1096),WPcra:function(a,n){return a||n},PYfCo:function(a,n){return a!=n},GeZqj:function(a,n){return a===n},rsJnt:t(903),CoByO:"init QoS"+t(1517)+"d",MYBbA:t(1304),aBglH:"message_id",wveaa:"YuSFF",aSqHb:function(a,n,s,d,f){return a(n,s,d,f)},CGUcN:function(a,n){return a(n)},udtwa:function(a,n){return a(n)},WcQbl:function(a,n){return a(n)},iLvSz:t(1069),Bjhzw:function(a,n){return a===n},SToMt:t(1056),NofiC:"x_fronti"+t(1045),nIpWx:function(a,n,s,d){return a(n,s,d)},cTMeg:t(1124)+t(973)+"ck",biJoN:function(a,n,s,d){return a(n,s,d)},StIIF:"x_fronti"+t(1072)+"k",lPwor:t(1124)+t(1228)+t(961),NEoLg:t(752),mlYwD:t(556),yvBrx:function(a,n){return a&&n},ASclA:function(a,n){return a===n},Boxaz:t(440),XfAPA:function(a,n){return a||n},uKDMP:t(568),UHBhN:function(a){return a()},NClxG:t(734),OnaTv:function(a,n){return a(n)},dOMeN:function(a,n){return a instanceof n},mGQxE:t(1363)+t(1275)+t(1037),BIEvI:t(528)+t(1357),ACnWz:t(1601)+"e",LBUPB:t(926),fxdEe:function(a){return a()},tuFLB:function(a,n){return a>n},pKSVv:function(a,n){return a+n},jyzau:function(a,n){return a(n)},ZqWQs:function(a,n){return a&n},eODfq:function(a,n){return a+n},PcZFF:function(a,n){return a+n},EzKHT:function(a,n){return a+n},CIABF:function(a,n){return a+n},tLnVH:"index out of ran"+t(1300),zxDfY:function(a,n){return a>=n},Zxntf:function(a,n,s,d){return a(n,s,d)},VaGMa:function(a,n){return a+n},gycAO:function(a,n){return a<n},qomqV:function(a,n){return a<<n},hQOOs:function(a,n){return a>=n},pIzga:function(a,n){return a|n},lkyRd:"jKjoB",LTgBj:t(202)+"3",VDDOC:function(a,n){return a+n},UGjwI:function(a,n){return a+n},NxgdT:function(a,n){return a|n},UGwuc:function(a,n){return a|n},NuDup:function(a,n){return a|n},XFYfy:function(a,n){return a<<n},MXbIm:function(a,n){return a<<n},rRqAb:function(a,n){return a<<n},AKSFp:function(a,n){return a+n},jbgvy:function(a,n){return a|n},ppuFc:function(a,n){return a+n},KLgrP:function(a,n){return a<<n},fjoUL:function(a,n){return a+n},yIvws:function(a,n){return a+n},FcfaJ:function(a,n){return a+n},zKmHJ:function(a,n){return a+n},RzXLI:function(a,n){return a&n},IyhUz:function(a,n){return a+n},Gypaf:function(a,n){return a+n},KkaWE:function(a,n){return a&n},DMzzF:function(a,n){return a+n},SekaO:function(a,n){return a&n},ZvezY:"online",kslKy:t(933),XvjnI:function(a,n){return a!=n},QuDOP:t(1469),nanQi:t(1166),SYumE:function(a,n){return a(n)},fsoKQ:"cursor.s"+t(1081),qcuFx:function(a,n,s,d){return a(n,s,d)},tPvEg:t(927),nqVFI:t(1598),ijMKi:t(320)+t(285),rAqEv:"name",KbfNm:function(a,n,s,d){return a(n,s,d)},OZbDV:t(1481),DrOVN:function(a,n){return a(n)},NNCeo:t(1025)+t(1711),oDWfN:function(a,n,s){return a(n,s)},CVguX:t(1401),gkDeu:function(a,n){return a<n},uKaTe:function(a,n,s){return a(n,s)},pPyVq:function(a,n,s){return a(n,s)},mGZIa:function(a,n,s,d){return a(n,s,d)},GofzA:function(a,n){return a+n},NFWqk:t(265)+"_EXIST",eptSJ:function(a){return a()},Qwcsp:function(a,n,s){return a(n,s)},WTlox:t(244),dQUyO:t(641)+"ame",IchyT:t(1308),srARL:function(a,n,s,d){return a(n,s,d)},hoKmi:t(1607),uqutl:t(1668),Aaijx:function(a,n,s,d){return a(n,s,d)},KaDAV:"setdb",ycuVD:t(522)+"r",ASoQH:function(a,n){return a<n},uYtqU:function(a,n){return a>n},qdYwr:function(a,n){return a(n)},BtAyB:function(a,n){return a>n},ajgFU:function(a,n){return a+n},ZpUNx:function(a,n){return a(n)},KWDmF:function(a,n){return a&n},WqLeD:function(a,n){return a+n},PVSPT:function(a,n){return a!==n},WIehR:"WVgQc",nVBRe:t(1594),aLHip:function(a,n){return a!==n},evXxB:t(1107),oOYKH:function(a,n,s,d){return a(n,s,d)},SCeTR:t(1074),byDjU:"x_fronti"+t(1415),coWXc:function(a,n){return a(n)},tpUGU:function(a,n,s){return a(n,s)},gkoYA:"x_fronti"+t(205),tpQpb:function(a,n,s,d){return a(n,s,d)},nHZPP:"x-msg-qos",dQuuh:"x-msg-cursor_name",GdqMO:function(a,n){return a(n)},VweYX:"x-msg-cu"+t(539)+"ue",TgveC:function(a){return a()},gJWLG:function(a,n){return a>n},Otnuu:t(1012),edyPc:function(a){return a()},OGqph:function(a){return a()},cDNfv:function(a,n){return a<n},mbKxw:function(a){return a()},mFZQm:function(a,n){return a===n},iwFIF:function(a,n){return a&&n},ntoGl:function(a){return a()},CozEB:function(a,n,s){return a(n,s)},PrObR:function(a){return a()},FYjlH:function(a){return a()},HOmJQ:function(a,n){return a(n)},ACZJM:function(a,n){return a!==n},yDSAX:function(a){return a()},cJFIF:"aWOoo",sxeOO:t(612),vCmay:t(1515),sZTTP:function(a,n){return a!==n},zhLgH:function(a,n,s){return a(n,s)},caFBc:function(a,n){return a(n)},OCnrk:function(a,n){return a!==n},pLZqk:function(a,n,s){return a(n,s)},PAssl:function(a,n,s){return a(n,s)},ryQiM:function(a,n){return a+n},KUiZa:t(358),Pogdp:t(1089),NqOQL:t(1009)+t(1514),siOic:"pbbp2",hFnLo:function(a,n){return a/n},MHPbL:t(1522),GkoQg:t(702)+t(534)+"alid url",dXEKn:function(a,n){return a(n)},ONNmQ:t(702)+"rovide ws params"+t(949)+t(920)+t(789)+t(510)+"ined",KpoIl:function(a,n,s){return a(n,s)},Szhjb:"reconnect",TTDPA:t(306),KIzGq:t(1100),zzKnx:t(689),rDGSL:t(1671),xvMlv:function(a,n){return a+n},twRyl:function(a,n){return a+n},kTlMS:function(a,n){return a+n},kVeSz:function(a,n){return a|n},TvcVv:function(a,n){return a&n},pXjRD:function(a,n){return a<<n},BMcCs:function(a,n){return a<=n},kvTkr:function(a,n){return a===n},ZOCLA:"XSMim",IpYHx:t(380),hYlbu:function(a,n){return a===n},UikEd:t(1715),Mpfnl:t(1373),IGpiB:t(919)+"d",PeuCh:t(702)+t(531)+t(1738)+t(1142)+"r ttwID",YPmPd:t(543),IUENE:function(a){return a()},feXHX:t(849)+"0",toiKg:function(a,n){return a(n)},ovdHk:t(719)+"or",hzWAE:function(a){return a()},ytRip:t(1394),QjnNt:function(a,n){return a-n},DEnGs:function(a,n,s){return a(n,s)},CDWDY:function(a,n,s){return a(n,s)},GQueQ:function(a,n){return a===n},giPxK:t(1624),ZODUv:function(a,n){return a(n)},Pynyc:function(a,n){return a(n)},YiDxd:function(a,n){return a*n},ZeBvU:function(a,n){return a>n},rCeIX:function(a,n){return a===n},pjnEA:t(1705),MaRNz:function(a,n){return a===n},XUyRM:"http",WCiby:"HIdHJ",vHFDR:"sSyFV",DXJgT:function(a,n){return a!==n},KbskH:"eGnwm",kuAjo:t(360),VzDxR:t(693),aWYlJ:t(1077)+"2",BESlM:function(a,n){return a!==n},NAwPU:t(855),LCJnD:t(1708),fImFG:t(764),fAAYk:function(a,n,s){return a(n,s)},SFtDz:"zCqXK",IooJo:function(a,n){return a+n},fZeOe:t(895),hUgpK:"5|6|0|10"+t(980)+"|1|3|2",UKzpp:t(1694),QiJjf:"xekeA",HqCfJ:t(1622),EhhPv:"6|1|7|5|0|4|2|3",dvacL:t(702)+t(1125)+" valid data, dat"+t(1046)+"e a stri"+t(1731)+t(828)+"ffer",gWttN:"number",vgmYO:function(a,n){return a!=n},yKgHa:function(a,n){return a instanceof n},TNGvK:function(a,n){return a(n)},yDiWR:function(a,n){return a||n},Vmjck:t(702)+"rovide a"+t(1451)+t(1081),zvyUH:function(a,n){return a instanceof n},XiHdM:function(a,n){return a===n},HluWv:"sent",kwvTv:function(a,n){return a==n},UsKfr:function(a,n){return a!==n},YoCwD:t(1574)+"econnect"+t(642),jFBRb:function(a,n){return a|n},avdaO:function(a,n){return a|n},UIZrY:function(a,n){return a&n},cJBFo:function(a,n){return a>>n},IKPQK:function(a,n){return a&n},SlIXt:function(a,n){return a>>n},cSJHr:function(a,n){return a&n},IeBGj:function(a,n){return a>>n},hOWhp:"zXuEJ",TXFzd:"ZHQVW",iaJTP:"3|2|1|4|0",EsWev:function(a,n){return a!==n},MHzVb:"SqkhY",snEAT:function(a,n){return a*n},ZqtjU:function(a,n){return a*n},gTNeR:function(a,n){return a!=n},GzMie:t(330),AOSAv:function(a,n){return a===n},wjVlI:function(a,n){return a!=n},EloXC:t(876),tJKIu:function(a,n){return a===n},FEXqS:function(a,n){return a!=n},MdyvC:t(1337)+t(1155)+"lobalScope",iDnXe:t(348)+t(884)+"alScope",fDiYi:function(a,n){return a!=n},PaOUs:function(a,n){return a!=n},NrfUl:function(a,n){return a===n},fdfQa:function(a,n,s){return a(n,s)}};Mt.r(Ce),Mt.d(Ce,{FWS:()=>jp,CustomErrorEvent:()=>Hd,createCloseEvent:()=>xt,ReconnectEvent:()=>qd,createErrorEvent:()=>st,decodedFrame:()=>Xt,createOpenEvent:()=>Zd,CustomCloseEvent:()=>jd,createReconnectEvent:()=>sa,FrontierMessageEvent:()=>Kd,encodeFrame:()=>Ft,createMessageEvent:()=>Vd,OpenEvent:()=>$d,ErrorCode:()=>en,Event:()=>Zn,MessageEvent:()=>Wd});let r="";function i(a=""){let n=t,s="02",d=""+Date[n(254)](),f=r||(r=e.xcuoC(x,a)),h=Math[n(475)]()[n(636)](16)[n(1258)](-6);return e[n(1328)](s+d,f)+h}function o(){let a=t;if(a(1406)!==e.tccmv)return e[a(1753)](1e4*Date[a(254)](),Math.floor(e[a(442)](1e4,Math[a(475)]())));this._messageQueue[a(1051)](),this[a(896)+a(1152)][a(874)](_0xdfb4dd)}function c(a){let n=t;if(e[n(1519)](e[n(1154)],n(1073)))_0x2c2ed0.log(_0x55a86c);else return e[n(1753)](e[n(230)](Array,8)[n(1751)]("0"),e[n(1473)](parseInt,a,10).toString(2)).slice(-8)}function l(a){let n=t;return(e[n(1540)](Array,4)[n(1751)]("0")+e[n(1473)](parseInt,a,2)[n(636)](16))[n(1258)](-4)}function u(a){let n=t,s=a[n(1405)](/\./)[n(479)](h=>c(h)),d=[];return d[0]=e[n(622)](l,s[0]+s[1]),d[1]=l(e.BTOWj(s[2],s[3])),[e[n(1750)],e.XabHN,"0000",e[n(1750)],n(864),n(1088),d[0],d[1]][n(1751)]("")}function x(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(1219)](a);return s?e.eQudk(u,a):d?e[n(1221)](p,a):e.xQoqw}function p(a){let n=t;if(e.kTgHH("lRDeA",e[n(711)])){let s=this[n(1139)][n(471)](this[n(858)]);return _0x18a28b[n(1280)](e[n(1403)](s,"{}"))[_0x25c68a]}else{let s="",d=[],f=0,h=0,m=!0,v=n(864);if(e[n(366)](a.indexOf("::"),-1))if(e[n(501)](e[n(1429)],"WAWhp")){let g=a[n(1405)]("::");for(let k=0;e[n(703)](k,g[n(1369)]);k++){let L=g[k];if(e[n(694)](L.indexOf(":"),0)){let W=L[n(1405)](":");m&&(f=W[n(1369)]),h+=W[n(1369)];for(let Q=0;e[n(1689)](Q,W[n(1369)]);Q++)if(e.VtCcF(4,W[Q][n(1369)])){let Y=v.substring(0,e[n(1410)](4,W[Q][n(1369)])),Xe=Y[n(559)](W[Q]);d[n(874)](Xe)}else d[n(874)](W[Q]);m=!1}else{if(e[n(501)](4,L[n(1369)])){let W=v.substring(0,4-L[n(1369)]),Q=W[n(559)](L);d[n(874)](Q)}else d.push(L);m&&(f+=1),h+=1,m=!1}}let P="";for(let k=0;e[n(963)](k,8-h);k++)P=P[n(559)](v);for(let k=0;e[n(963)](k,d.length);k++)e[n(1568)](k,f)?e[n(468)](n(695),e[n(1584)])?(s=s[n(559)](P),s=s[n(559)](d[k])):(this[n(668)]=!0,this._connect()):s=s[n(559)](d[k]);return s}else{this[n(905)+n(307)+n(1571)](_0x4a2d25(e[n(1392)],{code:1e3,reason:e[n(1298)]})),this[n(277)+n(1108)]?.["resetEndpointCon"+n(371)](),this[n(1693)+"sCounter"]?.["resetCou"+n(726)]();return}{let g=a[n(1405)](":");for(let P=0;e[n(703)](P,g[n(1369)]);P++)if(e[n(1147)](e[n(392)],e[n(312)])){let k=e[n(1131)](_0x957592);return _0x4cbe15(_0x203bfd,k),e[n(1419)](_0x4ee5b0,k)}else{let k=g[P];if(g[P].length!==4){let L=v[n(500)+"g"](0,4-g[P].length),W=L[n(559)](k);s=s.concat(W)}else s=s[n(559)](k)}return s}}}function w(a,n){let s=t,d={PLVBo:e[s(339)],gYCsC:function(m,v){return e[s(834)](m,v)},ruMIG:function(m,v){return e.ncKsX(m,v)},Hihlx:function(m,v,g,P){return m(v,g,P)}},f=a[s(1674)];e[s(1169)](void 0,f)&&(ue(n,10),e[s(1473)](q,n,f));let h=a[s(1509)];if(e.xRNoM(void 0,h))if(e[s(501)](s(738),e[s(357)]))e[s(297)](ue,n,18),e[s(297)](q,n,h);else{let m=d.PLVBo[s(1405)]("|"),v=0;for(;;){switch(m[v++]){case"0":return d[s(1487)](_0x1f75a2(_0x17c0dc,_0x224ad3,_0x5f0121),_0x2d8154);case"1":if(_0x3db4ed.utf8Write)return d[s(1487)](_0x19f6e4[s(1307)+"e"](_0x2d3daf,_0x673032),_0x174bb5);continue;case"2":if(d[s(676)](_0x3795af[s(1369)],40))return d[s(675)](_0x36f535,_0x540878,_0xe74fcf,_0x5d2a9f)+_0x14780f;continue;case"3":if(_0x5ec22b[s(1656)])return d[s(1487)](_0x28265b[s(1656)](_0xcf1764,_0x473cb1),_0x2b201d);continue;case"4":if(!_0x42c90d)return _0x47b493;continue}break}}}function _(a){let n=t;if(e[n(1519)](e[n(1217)],e[n(1493)])){for(_0x5b50d9>>>=0;e[n(486)](_0x513c1a,128);)e.QXILT(_0x473482,_0x1474ba,e[n(1449)](e.BvJiC(127,_0x57caab),128)),_0x43d7db>>>=7;e[n(1641)](_0x413cf1,_0x26536f,_0xb6073c)}else{let s={};e:for(;!e[n(622)](V,a);)if(e[n(1347)](e[n(1513)],n(954))){let d=e[n(1423)](_0x247913[n(221)],0),f=e[n(1423)](e[n(1449)](e.yaQAe(_0x5c6095.low,28),e[n(1034)](_0x90344.high,4)),0),h=e[n(1041)](_0x580b79[n(299)],24),m=e[n(1147)](0,h)?e[n(1147)](0,f)?d<16384?e[n(1181)](d,128)?1:2:e[n(1181)](d,2097152)?3:4:e.hyGla(f,16384)?e[n(617)](f,128)?5:6:f<2097152?7:8:e[n(1181)](h,128)?9:10,v=e[n(888)](_0x2ea924,_0x30a28d,m),g=_0x4ae759[n(1111)];switch(m){case 10:g[e.BTOWj(v,9)]=e[n(1667)](h>>>7,1);case 9:g[e[n(1753)](v,8)]=e[n(1169)](9,m)?e[n(1449)](128,h):e[n(1456)](127,h);case 8:g[e[n(1377)](v,7)]=m!==8?e[n(209)](f,21)|128:e[n(220)](f,21)&127;case 7:g[e[n(1377)](v,6)]=e[n(1169)](7,m)?f>>>14|128:e[n(291)](e[n(1041)](f,14),127);case 6:g[e[n(1612)](v,5)]=e.xRNoM(6,m)?e[n(601)](f,7)|128:e.IkkFM(f,7)&127;case 5:g[e[n(834)](v,4)]=m!==5?e.RcRPT(128,f):127&f;case 4:g[e[n(497)](v,3)]=e[n(501)](4,m)?e[n(1097)](d>>>21,128):e[n(1007)](e[n(571)](d,21),127);case 3:g[e[n(448)](v,2)]=e[n(645)](3,m)?e[n(246)](e[n(1376)](d,14),128):e[n(527)](e.rnBDb(d,14),127);case 2:g[e.BTOWj(v,1)]=e[n(501)](2,m)?e.RcRPT(e[n(601)](d,7),128):e[n(1435)](e[n(1041)](d,7),127);case 1:g[v]=e[n(1630)](1,m)?e[n(892)](128,d):e[n(1667)](127,d)}}else{let d=le(a);switch(e[n(1095)](d,3)){case 0:break e;case 1:s[n(1674)]=e[n(913)](N,a,e[n(230)](le,a));break;case 2:s[n(1509)]=N(a,e[n(1441)](le,a));break;default:e[n(913)](C,a,e.GVqFI(7,d))}}if(e[n(1147)](void 0,s[n(1674)]))throw new Error(e[n(938)]);if(e[n(1478)](void 0,s.value))throw new Error(n(1592)+n(1632)+" field: "+n(1509));return s}}function S(a){let n=t,s=e[n(1131)](D);return E(a,s),e[n(1714)](z,s)}function E(a,n){let s=t,d={MlLjM:function(ot,ht,ts){return e[F(297)](ot,ht,ts)},lFcsO:s(1739)},f=a[s(1144)];e[s(501)](void 0,f)&&(e.pabbp(ue,n,8),ft(n,f));let h=a[s(309)];e[s(645)](void 0,h)&&(ue(n,16),e[s(456)](ft,n,h));let m=a[s(1598)];e[s(1169)](void 0,m)&&(ue(n,24),e.JygSI(ft,n,O(m)));let v=a[s(1686)];e[s(425)](void 0,v)&&(e[s(297)](ue,n,32),e[s(1641)](ft,n,e[s(622)](O,v)));let g=a.headers;if(g!==void 0)for(let ot of g)if(e[s(865)](e[s(311)],e.yMaBs)){let ht=s(829)+_0x9e7751+(s(1234)+s(1617)+s(1633)+"ed");this[s(905)+s(1572)+s(1571)](_0x194bc0(e.IGiVv,{message:ht,code:_0x369415[s(1086)+s(211)+"R"],error:_0x4c378e}));return}else{e[s(494)](ue,n,42);let ht=e.ljCzl(D);e[s(1706)](w,ot,ht),e[s(1641)](ue,n,ht[s(1257)]),j(n,ht),e.imwcd(R,ht)}let P=a["payloadE"+s(1521)];e[s(946)](void 0,P)&&(e[s(1473)](ue,n,50),e[s(888)](q,n,P));let k=a[s(394)+s(403)];if(e[s(1169)](void 0,k))if(e[s(1039)](s(1240),e[s(1536)]))ue(n,58),e[s(888)](q,n,k);else{let ot=this[s(277)+s(1108)]?.getCurrentEndpoint();this[s(905)+"hCloseEv"+s(1571)](d[s(1338)](_0x34fa04,d.lFcsO,{code:_0x433584[s(1074)],reason:s(381)+s(1113)+"d, unkno"+s(1133)+s(832)+s(807)+ot})),this[s(277)+s(1108)]?.[s(1177)+"pointCon"+s(371)](),this[s(1693)+s(947)]?.[s(813)+s(726)]();return}let L=a[s(767)];e[s(865)](void 0,L)&&(ue(n,66),e[s(494)](ue,n,L[s(1369)]),e[s(456)](xe,n,L));let W=a[s(610)];e.wDqcm(void 0,W)&&(e[s(456)](ue,n,74),e[s(790)](q,n,W));let Q=a[s(1718)+s(580)];Q!==void 0&&(e.pabbp(ue,n,82),q(n,Q));let Y=a[s(1286)];Y!==void 0&&(ue(n,90),e[s(456)](q,n,Y));let Xe=a[s(1311)+"e"];e[s(700)](void 0,Xe)&&(e[s(790)](ue,n,96),e[s(1728)](ft,n,O(Xe)))}function b(a){let n=t;return e[n(622)](A,e[n(1221)](M,a))}function A(a){let n=t,s={};e:for(;!e[n(1279)](V,a);){let d=le(a);switch(e[n(1423)](d,3)){case 0:break e;case 1:s[n(1144)]=e[n(790)](St,a,!0);break;case 2:s[n(309)]=e.mTMMg(St,a,!0);break;case 3:s[n(1598)]=le(a);break;case 4:s.method=e[n(1714)](le,a);break;case 5:if(e[n(1506)](e[n(1182)],"IqSer")){let f=e[n(1419)](I,a);(s[n(1132)]||(s[n(1132)]=[])).push(_(a)),a[n(1257)]=f;break}else _0x164478[n(937)](_0x1ced8b);case 6:s[n(1673)+"ncoding"]=e[n(297)](N,a,le(a));break;case 7:s[n(394)+n(403)]=e.TvUgM(N,a,e[n(605)](le,a));break;case 8:s[n(767)]=Ee(a,e[n(665)](le,a));break;case 9:s[n(610)]=e[n(1473)](N,a,le(a));break;case 10:s[n(1718)+"ming"]=N(a,e[n(1419)](le,a));break;case 11:s[n(1286)]=e[n(790)](N,a,e[n(622)](le,a));break;case 12:s[n(1311)+"e"]=e[n(419)](le,a);break;default:e[n(1043)](C,a,e.mQqbK(7,d))}}if(s[n(1144)]===void 0)throw new Error(n(1592)+n(1632)+n(877)+n(1144));if(e[n(1147)](void 0,s[n(309)]))throw new Error(e.XPFoM);if(e[n(1261)](void 0,s[n(1598)]))throw new Error("Missing required"+n(877)+n(1598));if(e[n(1547)](void 0,s.method))throw new Error(e.UMuhp);return s}function I(a){let n=t;if(e.GpUXj(e[n(1334)],e[n(1334)])){let s=e[n(1238)][n(1405)]("|"),d=0;for(;;){switch(s[d++]){case"0":this["_clearTi"+n(841)]();continue;case"1":this[n(777)+n(577)]();continue;case"2":if(this[n(581)].readyState===this[n(1116)]||e[n(1683)](this._ws.readyState,this[n(1136)]))return void this._debug(e.OeXNd);continue;case"3":this["_QoSMana"+n(1725)]?.[n(766)]();continue;case"4":if(!this[n(581)])return void this[n(1093)](e.uenyN);continue;case"5":this[n(548)+n(1555)]=!0;continue;case"6":this[n(416)+n(1479)+"t"](_0x2e368a,_0x3f744f);continue;case"7":this[n(432)+n(972)+"Listener"]();continue}break}}else{let s=e[n(1221)](le,a),d=a[n(1257)];return a[n(1257)]=e[n(448)](a[n(1114)],s),d}}function C(a,n){let s=t;switch(n){case 0:for(;128&e[s(1413)](ie,a););break;case 2:e[s(1641)]($,a,e[s(771)](le,a));break;case 5:e[s(1573)]($,a,4);break;case 1:e[s(790)]($,a,8);break;default:throw new Error(e.rOYCp(s(1370)+"ented ty"+s(1062),n))}}function O(a){let n=t;return a|=0,{low:a,high:e[n(1134)](a,31),unsigned:e[n(627)](a,0)}}let y=[];function D(){let a=t,n=y[a(781)]();return n?(n[a(1114)]=n[a(1257)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function R(a){let n=t;if(e[n(680)]("drnaI",e[n(324)]))y[n(874)](a);else return this[n(905)+n(412)+n(783)](_0x550634),_0x128014()}function M(a){return{bytes:a,offset:0,limit:a.length}}function z(a){let n=t,s=a[n(1111)],d=a.limit;return e[n(680)](s[n(1369)],d)?s:s[n(1488)](0,d)}function $(a,n){let s=t,d={ohKKK:function(f,h){return e[F(224)](f,h)},WfdOf:function(f,h){return f+h},MJwmb:function(f,h){return f+h},Goxpm:function(f,h){return e[F(946)](f,h)},RWKhc:function(f,h){return e.uZVIW(f,h)},jNktf:function(f,h){return f<<h},Tgyfd:function(f,h){return e[F(1435)](f,h)},tyVwA:function(f,h){return e.pNPNl(f,h)},QKCZG:function(f,h){return e.QdxvI(f,h)},vPnTZ:function(f,h){return e[F(602)](f,h)},aVuCw:function(f,h){return f>>h}};if(e[s(509)]!==e[s(1670)]){if(e[s(1612)](a[s(1114)],n)>a.limit)throw new Error(e[s(1246)]);a[s(1114)]+=n}else _0x38264d=_0x511c21[d[s(1589)](_0x2552a0+_0x4923b0,1)],_0x1258a5=_0x57091e[d[s(476)](_0xa62cec+_0x10f119,2)],_0x58c9d7=_0x11936c[d[s(333)](d[s(476)](_0x244fda,_0x4ad061),3)],d[s(679)]((d[s(648)](_0x2dc2bc,d[s(1719)](_0x3ddcac,8))|d.jNktf(_0x866955,16))&12632256,8421504)?_0x2b6751+=_0x298487:(_0x454796=d[s(648)](d.RWKhc(d[s(1719)](d[s(1262)](7,_0x1d70e3),18),d[s(1179)](63&_0x3e066a,12)),d[s(1719)](d.QKCZG(63,_0x230c14),6))|d[s(1730)](63,_0x26e9ba),_0x45d6e8<65536||d[s(473)](_0x5d8d23,1114111)?_0x52106f+=_0x4764a8:(_0x545ee6-=65536,_0x478162+=_0x4a3d02(d[s(333)](d[s(1496)](_0x2d8fbd,10),55296),d[s(1589)](1023&_0x436053,56320)),_0x168d13+=3))}function V(a){let n=t;return e[n(627)](a[n(1114)],a[n(1257)])}function te(a,n){let s=t,d={VaLrw:function(g,P){return g(P)},wGlYl:e[s(296)],pWMnF:e[s(1184)],RJsDY:e.bLOgp},f=a[s(1111)],h=a[s(1114)],m=a.limit,v=h+n;if(e[s(567)](v,f[s(1369)]))if(e[s(1593)](e[s(1120)],s(1122)))d[s(1421)](_0xd9b178,d[s(336)]),this[s(1492)](d[s(384)],_0x120fea),this.off(d.RJsDY,_0xc88763);else{let g=new Uint8Array(2*v);g.set(f),a[s(1111)]=g}return a[s(1114)]=v,e[s(751)](v,m)&&(a[s(1257)]=v),h}function X(a,n){let s=t,d=a[s(1114)];if(e[s(751)](d+n,a.limit))throw new Error(e.pCQQg);return a.offset+=n,d}function Ee(a,n){let s=t,d=e[s(888)](X,a,n);return a[s(1111)][s(1488)](d,e.rOYCp(d,n))}function xe(a,n){let s=t,d=e[s(913)](te,a,n[s(1369)]);a.bytes.set(n,d)}function N(a,n){let s=t,d={xsdnP:function(P,k){return P(k)},nUvHB:function(P,k){return e[F(578)](P,k)},YQUyU:function(P,k){return e.Miocy(P,k)}},f=e.wRfdv(X,a,n),h=String[s(236)+s(329)],m=a[s(1111)],v="\uFFFD",g="";for(let P=0;e[s(470)](P,n);P++)if(e[s(1506)](e[s(890)],e[s(890)])){let k=d[s(1484)](_0x415bca,_0x34abf9);this[s(581)]&&d.nUvHB(this[s(581)][s(1532)+"te"],this[s(1115)])&&(this[s(581)]&&this[s(581)][s(1296)](k),this._debug(s(693),_0x2ecfec))}else{let k=m[e[s(1058)](P,f)],L,W,Q,Y;if(e.kTgHH(128&k,0))g+=e[s(837)](h,k);else if(e.PGRBq(224&k,192))e[s(1586)](e.iShtI(P,1),n)?g+=v:(L=m[e[s(321)](e[s(787)](P,f),1)],e.YKtpe(192,L)!==128?g+=v:(Y=e.RAcKH(e[s(964)](e[s(1281)](31,k),6),e.axeuO(63,L)),e[s(963)](Y,128)?g+=v:(g+=h(Y),P++)));else if(e.teNcy(e[s(527)](240,k),224))if(e[s(989)](P+2,n))g+=v;else if(e[s(1039)](e[s(1445)],s(1233)))if(L=m[e[s(321)](e[s(321)](P,f),1)],W=m[e[s(321)](e[s(970)](P,f),2)],e.PdVnG(e[s(1356)](e[s(1713)](L,e[s(1034)](W,8)),49344),32896))g+=v;else if(e.oMBuE("KuaQA",e.DNTCh)){let Xe=this[s(1139)][s(1196)+"geSync"](this[s(858)]),ot=_0x1d04c4[s(1280)](Xe||"{}");return ot[_0x121f01||_0x55bc42[this[s(613)]]]=_0x3c8f88,this[s(1139)][s(901)+s(1427)](this._prefix,_0x54b6ee[s(795)+"y"](ot)),_0x1b868b||_0x37aae8[this[s(613)]]}else Y=e[s(1097)](e.pNPNl(e[s(1356)](15,k),12)|e[s(1512)](e[s(487)](63,L),6),e[s(1667)](63,W)),e[s(1263)](Y,2048)||e[s(658)](Y,55296)&&e[s(1425)](Y,57343)?g+=v:(g+=e.KXpAj(h,Y),P+=2);else _0x4bac48=d.YQUyU(_0x315187,_0x1f4338),_0x5523ab=0;else e[s(1314)](e.ABgIL(248,k),240)?e[s(1198)](e[s(1377)](P,3),n)?g+=v:(L=m[P+f+1],W=m[e.WrNzz(e[s(343)](P,f),2)],Q=m[e[s(183)](e[s(183)](P,f),3)],e[s(425)](e.YKtpe(e[s(691)](e.sRjYD(L,e[s(1140)](W,8)),e[s(242)](Q,16)),12632256),8421504)?g+=v:(Y=e[s(1317)](e[s(691)](e.cnLnr(e[s(1356)](7,k)<<18,e[s(984)](e[s(1691)](63,L),12)),e.HhIhy(63,W)<<6),e.QdxvI(63,Q)),Y<65536||e[s(567)](Y,1114111)?g+=v:(Y-=65536,g+=e.mTMMg(h,e[s(1134)](Y,10)+55296,e.HXUjs(e[s(527)](1023,Y),56320)),P+=3))):g+=v}return g}function q(a,n){let s=t,d=n[s(1369)],f=0;for(let v=0;v<d;v++){let g=n.charCodeAt(v);e[s(486)](g,55296)&&e.HDwHB(g,56319)&&e[s(963)](v+1,d)&&(g=e[s(1410)](e[s(1118)](e[s(1460)](g,10),n[s(511)+"At"](++v)),56613888)),f+=e.DvRCj(g,128)?1:e[s(470)](g,2048)?2:e[s(470)](g,65536)?3:4}e[s(611)](ue,a,f);let h=te(a,f),m=a[s(1111)];for(let v=0;e[s(1407)](v,d);v++){let g=n.charCodeAt(v);g>=55296&&g<=56319&&v+1<d&&(g=e[s(833)](g,10)+n[s(511)+"At"](++v)-56613888),e[s(1407)](g,128)?m[h++]=g:(e[s(1162)](g,2048)?m[h++]=e.qIYuN(e[s(1356)](e[s(768)](g,6),31),192):(e[s(1407)](g,65536)?m[h++]=e[s(1097)](g>>12&15,224):(m[h++]=e.nIFBg(e[s(1595)](e.rYHrA(g,18),7),240),m[h++]=e.rVjIV(e.VfhVn(g,12)&63,128)),m[h++]=e.RpdMG(e[s(1102)](e[s(1134)](g,6),63),128)),m[h++]=e.cnLnr(e.rVDBI(63,g),128))}}function j(a,n){let s=t,d=e[s(1209)](te,a,n[s(1257)]),f=a[s(1111)],h=n.bytes;for(let m=0,v=n[s(1257)];m<v;m++)f[e[s(1753)](m,d)]=h[m]}function ie(a){return a.bytes[X(a,1)]}function $e(a,n){let s=t,d=te(a,1);a[s(1111)][d]=n}function le(a){let n=t,s=0,d=0,f;do f=e[n(193)](ie,a),e[n(703)](s,32)&&(d|=e[n(1143)](e[n(1691)](127,f),s)),s+=7;while(e[n(1090)](128,f));return d}function ue(a,n){let s=t;for(n>>>=0;e[s(1198)](n,128);)e.Wwwsy($e,a,e[s(1372)](e[s(1271)](127,n),128)),n>>>=7;$e(a,n)}function St(a,n){let s=t,d=0,f=0,h=0,m;if(m=ie(a),d=e[s(1595)](127,m),e[s(709)](128,m)&&(m=ie(a),d|=e[s(1318)](e.MqHSH(127,m),7),128&m))if(e.GpUXj(e.NXkfr,e[s(1355)])){if(m=e.ybCBK(ie,a),d|=e[s(401)](127,m)<<14,e[s(1477)](128,m)&&(m=e[s(1565)](ie,a),d|=e[s(291)](127,m)<<21,e[s(1691)](128,m))){if(e[s(1630)](s(1466),e[s(809)]))this[s(1282)]=!0,this[s(221)]=e[s(671)](0,_0x3ef1c4),this[s(299)]=e.RAcKH(0,_0x405919),this[s(1386)]=!!_0x103999;else if(m=e[s(614)](ie,a),f=e[s(971)](127,m),e[s(824)](128,m)&&(m=e[s(622)](ie,a),f|=(127&m)<<7,e[s(487)](128,m)&&(m=e[s(1551)](ie,a),f|=e.fgonj(e[s(1691)](127,m),14),e.SHKsp(128,m)&&(m=e[s(1709)](ie,a),f|=e[s(1512)](127&m,21),128&m))))if(e[s(700)](e.fHSJC,e[s(786)]))m=ie(a),h=e.hCoib(127,m),e[s(713)](128,m)&&(m=e[s(284)](ie,a),h|=e[s(1034)](e[s(866)](127,m),7));else{if(!this[s(1567)+s(352)]()||this[s(548)+s(1555)])return;this[s(277)+s(1108)]?.[s(1177)+"pointCon"+s(371)](),this[s(1693)+s(947)]?.["resetCou"+s(726)](),this[s(581)]?this[s(395)+s(1151)](1001,s(314)+"ay, try reconnecting server",!0):this[s(424)]()}}}else{let v=_0x451d6c.substring(0,e[s(1410)](4,_0x2f564d[_0x5bda40][s(1369)])),g=v[s(559)](_0x42a011[_0x4f75b7]);_0x16b7f1[s(874)](g)}return{low:e[s(691)](d,e[s(516)](f,28)),high:e.RAcKH(e[s(1376)](f,4),e.gKAXK(h,24)),unsigned:n}}function ft(a,n){let s=t,d=n[s(221)]>>>0,f=e[s(815)](e[s(1449)](n[s(221)]>>>28,n[s(299)]<<4),0),h=n.high>>>24,m=e[s(1478)](0,h)?f===0?e[s(714)](d,16384)?e.zmgVF(d,128)?1:2:d<2097152?3:4:f<16384?e[s(210)](f,128)?5:6:e[s(1503)](f,2097152)?7:8:e[s(604)](h,128)?9:10,v=e[s(1641)](te,a,m),g=a.bytes;switch(m){case 10:g[v+9]=e[s(1458)](e.CSVQv(h,7),1);case 9:g[e[s(834)](v,8)]=e[s(743)](9,m)?128|h:127&h;case 8:g[v+7]=m!==8?e[s(763)](e[s(770)](f,21),128):e[s(848)](e[s(1734)](f,21),127);case 7:g[v+6]=m!==7?e[s(845)](e.CgkGI(f,14),128):e.naxcd(e[s(939)](f,14),127);case 6:g[e[s(1741)](v,5)]=e[s(406)](6,m)?e[s(226)](e[s(631)](f,7),128):e[s(935)](e[s(1400)](f,7),127);case 5:g[e[s(224)](v,4)]=e.ntwAn(5,m)?e.wkOHW(128,f):e[s(1101)](127,f);case 4:g[e[s(787)](v,3)]=e[s(1323)](4,m)?e[s(839)](e[s(1214)](d,21),128):d>>>21&127;case 3:g[e[s(826)](v,2)]=e[s(425)](3,m)?e[s(477)](e[s(492)](d,14),128):e[s(1411)](d,14)&127;case 2:g[e.rCYwt(v,1)]=e.CujFN(2,m)?e[s(1635)](e.JgcjQ(d,7),128):e.ABgIL(e[s(1400)](d,7),127);case 1:g[v]=m!==1?128|d:e[s(1562)](127,d)}}function Xt(a){return e[t(278)](b,a)}function Ft(a){return e[t(1716)](S,a)}let Qt=65536,jr=t(1220),ge=e[t(747)](Qt,Qt),Ie=e[t(754)](ge,ge),Vn=Ie/2,Re=String[t(952)+"e"][t(511)+"At"];class ce{constructor(n,s,d){let f=t;this.isLong=!0,this[f(221)]=e[f(1317)](0,n),this[f(299)]=0|s,this[f(1386)]=!!d}static[t(1282)](n){let s=t;return n&&e[s(1053)](!0,n[s(1282)])}static fromBits(n,s,d){return new ce(n,s,d)}static[t(796)+"s"](n,s,d){let f=t;return d?ce["fromByte"+f(429)](n,s):ce["fromByte"+f(1001)](n,s)}static[t(796)+"sLE"](n,s){let d=t;return new ce(e.cVcxQ(n[0]|e[d(853)](n[1],8),n[2]<<16)|e[d(1512)](n[3],24),e[d(691)](e[d(246)](n[4],n[5]<<8),e[d(1723)](n[6],16))|e[d(964)](n[7],24),s)}static[t(796)+t(1001)](n,s){let d=t;return new ce(e[d(454)](e[d(1439)](e[d(1613)](n[4],24),e[d(1723)](n[5],16))|e.lWVpz(n[6],8),n[7]),e[d(1544)](e[d(562)](n[0]<<24,e[d(984)](n[1],16)),n[2]<<8)|n[3],s)}static[t(871)](n){let s=t;return e[s(468)](n,jr)?Gd:new ce(e[s(631)](e[s(1712)](Re[s(1642)](n,0)|e[s(881)](Re[s(1642)](n,1),8),Re[s(1642)](n,2)<<16)|e[s(853)](Re.call(n,3),24),0),e[s(1602)](e[s(1213)](e.uZVIW(Re[s(1642)](n,4),e[s(1613)](Re.call(n,5),8))|Re[s(1642)](n,6)<<16,e[s(1034)](Re[s(1642)](n,7),24)),0),!0)}[t(1604)](){let n=t;return String[n(236)+n(329)](255&this[n(221)],e[n(935)](this[n(221)]>>>8,255),e[n(364)](e.wuZps(this[n(221)],16),255),e[n(1602)](this[n(221)],24),e[n(1645)](255,this[n(299)]),e[n(461)](e.rnBDb(this[n(299)],8),255),e[n(1438)](this[n(299)],16)&255,e[n(1746)](this[n(299)],24))}static[t(1026)+"er"](n,s=!0){let d=t;if(e.QoDON(isNaN,n))return s?np:Gd;if(s){if(e.ykDke(n,Ie))return ip}else{if(n<=-Vn)return sp;if(e[d(1510)](e[d(1058)](n,1),Vn))return rp}return ce.fromBits(n%ge|0,e[d(562)](e[d(1535)](n,ge),0),s)}[t(1117)](){let n=t;return this.unsigned?e[n(321)](e[n(1290)](this[n(299)],0)*ge,e[n(1734)](this[n(221)],0)):e[n(1611)](this[n(299)],ge)+e.CgkGI(this.low,0)}[t(757)](){let n=t;return e[n(1083)](0,this[n(299)])&&e[n(1053)](0,this[n(221)])}add(n){let s=t;ce[s(1282)](n)||(n=ce.fromNumber(n));let d=this[s(299)]>>>16,f=e[s(709)](65535,this[s(299)]),h=this[s(221)]>>>16,m=e[s(758)](65535,this.low),v=e[s(815)](n[s(299)],16),g=e[s(393)](65535,n[s(299)]),P=e[s(413)](n[s(221)],16),k=65535&n[s(221)],L=0,W=0,Q=0,Y=0;return Y+=e[s(1753)](m,k),Q+=e[s(1438)](Y,16),Y&=65535,Q+=e[s(458)](h,P),W+=e[s(1682)](Q,16),Q&=65535,W+=f+g,L+=W>>>16,W&=65535,L+=e[s(497)](d,v),L&=65535,ce[s(308)](e[s(765)](e[s(1669)](Q,16),Y),e[s(1527)](e[s(1669)](L,16),W),this[s(1386)])}[t(411)](n){let s=t;return ce[s(1282)](n)||(n=ce[s(1026)+"er"](n)),e[s(1323)](this.unsigned,n[s(1386)])&&e.kjdKn(e[s(1563)](this[s(299)],31),1)&&e[s(359)](n[s(299)],31)===1?!1:e.VzDaU(this[s(299)],n.high)&&e.PGRBq(this.low,n[s(221)])}[t(776)](){let n=t;return e[n(1147)](-1,this[n(221)])&&e[n(1525)](-1,this.high)?ce[n(308)](0,0,this.unsigned):e[n(578)](-1,this[n(221)])?ce[n(308)](0,e.uuhcv(this[n(299)],1),this[n(1386)]):ce[n(308)](e[n(183)](this[n(221)],1),this[n(299)],this.unsigned)}[t(187)](n){let s=t;return n?this[s(438)+"E"]():this[s(1326)+"E"]()}[t(438)+"E"](){let n=t,s=this[n(299)],d=this.low;return[e[n(399)](255,d),e.XWgzG(e[n(1290)](d,8),255),e[n(1041)](d,16)&255,e.bXDWO(d,24),e[n(1399)](255,s),e[n(657)](e[n(616)](s,8),255),e[n(1098)](s>>>16,255),e.dZzRM(s,24)]}toBytesBE(){let n=t;if(e.wDqcm(e[n(697)],e.bjgmU)){let s=this[n(299)],d=this[n(221)];return[e[n(631)](s,24),e[n(1356)](e[n(1423)](s,16),255),e[n(1442)](s>>>8,255),e.GOApW(255,s),e[n(212)](d,24),e[n(866)](e[n(778)](d,16),255),e[n(889)](e[n(1272)](d,8),255),e[n(869)](255,d)]}else return e[n(193)](_0x3121fd,e[n(369)](_0xd39648,_0x5b2758))}}let Gd=new ce(0,0,!1),np=new ce(0,0,!0),rp=ce[t(308)](-1,2147483647,!1),ip=ce[t(308)](-1,-1,!0),sp=ce[t(308)](0,-2147483648,!1);var en=(function(a){let n=t;if(e[n(1083)](e[n(1422)],e.iiKWV)){let s=(n(814)+"1|3").split("|"),d=0;for(;;){switch(s[d++]){case"0":a[a[e[n(445)]]=5002]=e[n(445)];continue;case"1":a[a[n(872)+"OR"]=5005]=n(872)+"OR";continue;case"2":a[a[e[n(1505)]]=5004]=e.iwZlD;continue;case"3":return a;case"4":a[a[e.HoCLs]=5001]=e[n(417)];continue;case"5":a[a[n(1086)+"IES_ERROR"]=5003]="MAX_RETRIES_ERROR";continue}break}}else return _0x455ee1|=0,{low:_0x3bf666,high:e.CjfIt(_0x5e883a,31),unsigned:e.GdQmv(_0x3c992a,0)}})({});class Zn{constructor(n){let s=t;this.type=n,this[s(1106)]=null}}class qd extends Zn{constructor(n,s){let d=t;super(n),this[d(808)]=s&&s[d(808)]||null}}class Hd extends Zn{constructor(n,s){let d=t;super(n),this[d(1235)]=s&&s[d(1235)]||null,this[d(1023)]=s&&s[d(1023)]||0,this[d(1055)]=s&&s[d(1055)]||"",this[d(868)]=s&&s.lineno||0,this[d(808)]=s&&s.message||"",this[d(1074)]=s&&s[d(1074)]||5001}}class jd extends Zn{constructor(n,s){let d=t,f={PaGRS:function(h,m){return e[F(1676)](h,m)},SkcOt:function(h,m){return e[F(516)](h,m)},ocOEF:function(h,m){return e[F(881)](h,m)},IdFgX:function(h,m){return e[F(1712)](h,m)}};if(e[d(1752)](e[d(1174)],e[d(1174)]))return new _0x4ecc99(gTrhzV.PaGRS(_0x1db795[0],gTrhzV[d(956)](_0xffa5c0[1],8))|gTrhzV[d(823)](_0x311e4c[2],16)|_0x3deef3[3]<<24,gTrhzV.IdFgX(_0x1fa697[4]|_0x1a8bcd[5]<<8,_0xa96c2a[6]<<16)|gTrhzV[d(956)](_0x2cf0b1[7],24),_0x317972);{let h=e[d(1126)][d(1405)]("|"),m=0;for(;;){switch(h[m++]){case"0":this[d(1074)]=s&&s[d(1074)]||0;continue;case"1":this[d(1453)]=s&&s.reason||"";continue;case"2":this["willReco"+d(704)]=s&&s[d(1749)+"nnect"]||!1;continue;case"3":this[d(1145)]=s&&s.wasClean||!1;continue;case"4":super(n);continue}break}}}}class Wd extends Zn{constructor(n,s){let d=t;e[d(1506)](d(1306),e.rgpDl)?(super(n),this[d(1414)]=s&&s[d(1414)]||null):this[d(720)+d(1748)]()}}class Kd extends Wd{constructor(n,s){let d=t;super(n),this[d(1414)]=s&&s[d(1414)]||null,this[d(808)]=s&&s[d(808)]||null}}class $d extends Zn{constructor(n,s){let d=t;super(n),this[d(1414)]=s&&s[d(1414)]||null}}function st(a,{message:n,code:s,error:d}){return new Hd(a,{message:n,code:s,error:d})}function xt(a,{code:n,reason:s,wasClean:d,willReconnect:f}){let h=t;if(e[h(1568)](e[h(746)],h(1030)))return new jd(a,{code:n,reason:s,wasClean:d,willReconnect:f});this.maxLossCount=_0x5e28a9,this[h(1068)]=0}function Vd(a,{data:n,message:s}){return new Kd(a,{data:n,message:s})}function Zd(a,{data:n}){let s=t;return e.EOhYr(e[s(1582)],e[s(1618)])?new $d(a,{data:n}):_0x39ff0c}function sa(a,{message:n}){return new qd(a,{message:n})}class Yd{constructor(n,s){let d=t;this.endpoints=n,this.maxRetries=s,this["currentI"+d(513)]=0,this[d(934)+d(936)+"riesCount"]=0}[t(1177)+"pointConfig"](){let n=t;this[n(289)+n(513)]=0,this[n(934)+n(936)+"riesCount"]=0}[t(1553)+"es"](){let n=t;e[n(1623)](e[n(430)],n(1206))?this[n(934)+"ndpointT"+n(1061)+"t"]=0:this.on(_0x16b5e2,_0x43f4e9)}["getCurre"+t(1564)+"nt"](){let n=t,s={ICzgk:function(d,f){return d(f)}};if(e[n(1148)](e[n(722)],e.svzfI))return this[n(1465)+"s"][this[n(289)+n(513)]];_0x55f5c5[n(1229)]["removeCh"+n(346)](_0x15a6de),_0x1d09e8[n(1570)+n(821)]=void 0,s.ICzgk(_0x2ca141,_0x151b3a&&_0x4a8833.msg||n(986)+n(1453))}[t(914)+"ntEndpointTriesCount"](){let n=t;return this[n(934)+n(936)+n(1061)+"t"]}checkReachMaxTries(){let n=t;return!!(e[n(627)](this[n(289)+n(513)],this[n(1465)+"s"][n(1369)])||e[n(1285)](this[n(289)+n(513)],this[n(1465)+"s"].length-1)&&this[n(934)+"ndpointT"+n(1061)+"t"]===this[n(203)+"es"])}[t(916)+"rentEndpointReac"+t(1029)+t(1351)](){let n=t;return this.currentIndex==this[n(1465)+"s"][n(1369)]?!0:e[n(694)](this[n(934)+n(936)+n(1061)+"t"],this[n(203)+"es"])}[t(928)+t(1702)+t(356)+t(1634)+t(644)](){let n=t;return this["currentE"+n(936)+n(1061)+"t"]=1,this["currentI"+n(513)]++,this[n(1465)+"s"][this[n(289)+n(513)]]}["getCurre"+t(1564)+t(1687)+t(243)](){let n=t;return this[n(934)+n(936)+n(1061)+"t"]++,this["getCurre"+n(1564)+"nt"]()}}let Yn=(e.gTNeR(t(427)+"d",typeof globalThis)&&e.PGRBq(e[t(302)],globalThis["construc"+t(1358)][t(285)])||e[t(619)]!=typeof window&&e.AOSAv(e.GzMie,window[t(1249)+t(1358)][t(285)]))&&e[t(1057)](e.ENGaz,typeof document),In=e.wjVlI(e.ENGaz,typeof globalThis)&&(e[t(451)]===globalThis[t(1249)+t(1358)].name||e[t(274)](t(1337)+"dWorkerG"+t(664)+"pe",globalThis[t(1249)+t(1358)][t(285)]))&&e[t(619)]!=typeof tt,Wr=(e[t(921)](e.ENGaz,typeof globalThis)&&e.tJKIu(t(876),globalThis[t(1249)+t(1358)][t(285)])||e[t(1314)](e[t(619)],typeof globalThis)||e[t(1550)](t(427)+"d",typeof globalThis)&&!!globalThis["WeixinJS"+t(599)])&&e[t(1550)](t(427)+"d",typeof wx),Kr=e[t(619)]!=typeof globalThis&&(e[t(1614)]===globalThis[t(1249)+"tor"][t(285)]||e[t(1519)](e[t(1127)],globalThis[t(1249)+t(1358)][t(285)])||t(575)+"orkerGlo"+t(1197)===globalThis[t(1249)+t(1358)].name)&&e[t(893)](t(427)+"d",typeof self),op=e[t(619)]!=typeof globalThis&&e[t(451)]===globalThis[t(1249)+"tor"][t(285)]&&e[t(830)](t(427)+"d",typeof global)&&e[t(1225)](e[t(451)],global["construc"+t(1358)][t(285)])&&t(427)+"d"!=typeof process&&!!process[t(1010)];class oa{constructor(){let n=t;if(e[n(1242)](e.VgGEG,e[n(410)]))this[n(1071)+"rs"]={};else{let s=this[n(756)][n(1003)+n(1499)+"ptor"](_0x57dfe2,_0x4f1da5);this[n(905)+n(307)+"ent"](e.rCyGO(_0x3319a1,n(1739),{code:_0x4607a7,reason:_0xd5f65c,wasClean:!0,willReconnect:s})),s&&this._connect()}}[t(797)](n,...s){let d=t,f=this[d(1071)+"rs"][n];if(f)f[d(1258)]()[d(728)](h=>h.fn[d(1211)](h[d(1489)],s));else if(e[d(227)](d(1235),n)&&!this.onerror){let h=s[d(1369)]&&s[0];if(h instanceof Error)throw h;let m=new Error(e[d(1175)](e[d(1348)],h?e.pTKxN(e[d(1583)](" (",h[d(808)]),")"):""));throw m[d(257)]=h,h}return this}[t(1492)](n,s){let d=t;if(n===void 0)this[d(1071)+"rs"]={};else if(e[d(1697)](void 0,s))this._listeners[n]=null;else{let f=this[d(1071)+"rs"][n];if(f)for(let h=0;e[d(604)](h,f[d(1369)]);)e[d(1523)](f[h].fn,s)?f[d(540)](h,1):++h}return this}on(n,s,d){let f=t;return(this._listeners[n]||(this[f(1071)+"rs"][n]=[]))[f(874)]({fn:s,ctx:d||this}),this}}class ap extends oa{[t(948)+"rrorMess"+t(1695)](n){let s=t;return n[s(755)]||n.errNo?(s(303)+" "+(n[s(755)]||"")+s(219)+(n.errNo||""))[s(533)]():JSON[s(795)+"y"](n)}constructor(n,s,d){let f=t;super(),this[f(229)]=null,Wr&&wx[f(1161)+"ocket"]&&(this[f(229)]=wx[f(1161)+f(1185)]({url:n,protocols:s,header:d,fail:this["_createS"+f(1187)+f(266)][f(1018)](this),success:this[f(1569)+"ocketSuccessHand"+f(682)][f(1018)](this)})),In&&tt["connectS"+f(1185)]&&(this[f(229)]=tt["connectS"+f(1185)]({url:n,protocols:s,header:d,fail:this[f(1569)+"ocketFailHandler"][f(1018)](this),success:this[f(1569)+f(1452)+f(840)+"ler"].bind(this)}))}[t(1569)+t(1452)+t(840)+"ler"](){let n=t;Promise.resolve()[n(1252)](()=>{let s=n;this[s(720)+s(1748)]()})}[t(1569)+"ocketFai"+t(266)](n){let s=t,d={ZLeYX:function(f,h,m){return e[F(594)](f,h,m)},bJHiu:e.IGiVv,vZMMP:e[s(1392)]};Promise[s(1244)]()[s(1252)](()=>{let f=s,h=d.ZLeYX(st,d.bJHiu,{message:this[f(948)+f(1284)+f(1695)](n)});this[f(797)](d[f(1733)],h);let m=xt(d[f(1241)],{reason:this[f(948)+f(1284)+f(1695)](n)});this[f(797)](f(1739),m)})}[t(720)+t(1748)](){let n=t,s={NkAhm:e[n(1392)],ffImW:function(d,f,h){return d(f,h)}};this[n(229)][n(347)](d=>{let f=n;this[f(797)](f(1665),e[f(913)](Zd,e[f(1605)],{...d,data:d[f(755)]||""}))}),this._socket[n(1104)](d=>{let f=n;this.emit(s[f(1433)],s.ffImW(xt,f(1739),{...d}))}),this[n(229)][n(794)+"e"](d=>{let f=n;this[f(797)](e.oIUNn,e[f(318)](Vd,f(808),{...d}))}),this[n(229)].onError(d=>{let f=n;this[f(797)](e[f(782)],e[f(297)](st,"error",{...d,message:d[f(755)]||""}))})}[t(1296)](n){let s=t;if(e[s(1432)](n,Uint8Array)){let d=n[s(1548)][s(1258)](n[s(801)+"et"],e[s(225)](n[s(275)+"th"],n[s(801)+"et"]));this._socket&&this[s(229)][s(1296)]({data:d,fail:f=>{let h=s;this[h(797)](e[h(782)],e.olgvC(st,e[h(782)],{message:this["_formatE"+h(1284)+h(1695)](f)}))}})}else this[s(229)]&&this[s(229)].send({data:n,fail:d=>{let f=s;this.emit(e.IGiVv,e[f(590)](st,e.IGiVv,{message:this[f(948)+f(1284)+"age"](d)}))}})}[t(1739)](n,s){let d=t;this[d(229)]&&this[d(229)][d(1739)]({code:n,reason:s})}["addEvent"+t(1040)](n,s){this.on(n,s)}[t(861)+t(1245)+t(761)](n,s){this.off(n,s)}get[t(1532)+"te"](){let n=t;if(e[n(228)](e[n(860)],e[n(860)]))this[n(1492)](_0x5a4a98,_0x581384);else return this[n(229)].readyState}get[t(586)+"pe"](){return this._socket.binaryType}set[t(586)+"pe"](n){}get url(){let n=t;if(e[n(271)](e[n(1016)],e[n(1016)])){let s={lYHna:n(1235)},d=_0x1bad00.buffer[n(1258)](_0x5f05e0[n(801)+"et"],_0x2ebf49.byteLength+_0x15dc4a.byteOffset);this[n(229)]&&this[n(229)][n(1296)]({data:d,fail:f=>{let h=n;this[h(797)](h(1235),_0x2e0aff(s.lYHna,{message:this[h(948)+h(1284)+h(1695)](f)}))}})}else return this[n(229)].url}get[t(450)](){return this[t(229)].protocol}get[t(978)+"ns"](){return this._socket.extensions}get["buffered"+t(803)](){return 0}}function cp(a,n){let s=t;if(n)return new n(a[s(1710)],a[s(450)]);if(e[s(530)](Wr,In))return new ap(a[s(1710)],a.protocol,a[s(1132)]);if(e[s(530)](Yn,Kr)&&e[s(1587)](e.ENGaz,typeof WebSocket)&&WebSocket)return new WebSocket(a[s(1710)],a[s(450)+"s"])}function dp(a){let n=t,s=e.cbBtv[n(1405)]("|"),d=0;for(;;){switch(s[d++]){case"0":return!1;case"1":if(a)return!0;continue;case"2":if(Wr&&wx["connectS"+n(1185)])return!0;continue;case"3":if(In&&tt.connectSocket)return!0;continue;case"4":if(e[n(737)](Yn,Kr)&&e[n(1364)](e[n(619)],typeof WebSocket)&&WebSocket)return!0;continue}break}}function Jd(a,n,s){let d=t,f={XtYWd:function(h,m){return e.HDwHB(h,m)},SoNwA:e[d(1545)],fwKMH:function(h,m){return e.rCYwt(h,m)}};if(e[d(274)](e.xrbHa,e[d(1157)])){let h=_0x2b0f8c[d(1674)];h!==void 0&&(_0x19f289(_0x4624fd,10),_0x275353(_0x170860,h));let m=_0x2dc139[d(1509)];m!==void 0&&(_0x574b29(_0x224977,18),_0x156766(_0x4be6a,m))}else{let h=-1;async function m(v){let g=d;return f[g(1180)](v,h)?Promise[g(724)](new Error(f[g(731)])):(h=v,v===s[g(1369)]?Promise[g(1244)]():s[v].bind(a)(n,m[g(1018)](null,f[g(249)](v,1))))}e[d(420)](m,0)}}function Xd(a){let n=t;if(e[n(279)](e[n(1345)],n(550)))_0x2ae585=_0x2ecc8d[n(559)](_0x45d7f3),_0x433aee=_0x16105c[n(559)](_0x141b69[_0x38fc36]);else{let s=0,d=0;for(let f=0;e[n(617)](f,a[n(1369)]);++f)if(e[n(1491)]!==e.EMCpJ)d=a[n(511)+"At"](f),e.ncKsX(d,128)?s+=1:e.YWGcy(d,2048)?s+=2:e[n(222)](e[n(1625)](64512,d),55296)&&e[n(325)](e[n(889)](64512,a.charCodeAt(e[n(293)](f,1))),56320)?(++f,s+=4):s+=3;else{let h={dIAxN:function(m,v,g){return m(v,g)},NXQIi:e[n(782)],oFkCz:n(1739)};_0x146b31[n(1244)]()[n(1252)](()=>{let m=n,v=h[m(1320)](_0x11920e,h.NXQIi,{message:this["_formatE"+m(1284)+m(1695)](_0x1bf6c7)});this[m(797)](m(1235),v);let g=h[m(1320)](_0x5a1133,h[m(197)],{reason:this[m(948)+m(1284)+m(1695)](_0x2cbf3b)});this[m(797)](h[m(197)],g)})}return s}}function Qd(a,n,s){let d=t;if(e[d(1410)](s,n)<1)return"";let f="";for(let h=n;e[d(214)](h,s);){let m=a[h++];if(m<=127)f+=String[d(236)+"Code"](m);else if(e[d(989)](m,192)&&e[d(963)](m,224))f+=String[d(236)+d(329)](e[d(715)](e.WSbNW(31&m,6),e[d(623)](63,a[h++])));else if(m>=224&&e[d(1181)](m,240))f+=String["fromChar"+d(329)](e.ixotz(e.zfebq(e[d(461)](15,m)<<12,e[d(984)](e[d(623)](63,a[h++]),6)),e[d(1562)](63,a[h++])));else if(e[d(627)](m,240)){let v=e[d(1518)](e[d(1736)](e[d(1560)](e.PNjLL(7,m),18)|e.rVDBI(63,a[h++])<<12,(63&a[h++])<<6),63&a[h++])-65536;f+=String[d(236)+"Code"](e[d(448)](55296,e[d(1253)](v,10))),f+=String[d(236)+d(329)](e[d(717)](56320,1023&v))}}return f}function aa(a,n,s){let d=t;if(e[d(1301)](e.YBQLM,d(1165)))try{this[d(581)]&&this._ws.close(_0x5cdffd,_0x22bfa9)}catch{}else{let f=s,h,m;for(let v=0;e[d(234)](v,a[d(1369)]);++v)if(e[d(946)](e.FfHxz,e[d(1309)]))if(h=a.charCodeAt(v),e[d(703)](h,128))n[s++]=h;else if(e[d(604)](h,2048))n[s++]=e[d(1094)](h,6)|192,n[s++]=e[d(1527)](63&h,128);else if(e[d(1478)](64512&h,55296)&&(64512&(m=a[d(511)+"At"](e[d(224)](v,1))))===56320){let g=e[d(1011)].split("|"),P=0;for(;;){switch(g[P++]){case"0":n[s++]=e[d(1408)](e.rzvUE(h,6),63)|128;continue;case"1":n[s++]=e[d(1322)](e[d(768)](h,18),240);continue;case"2":++v;continue;case"3":n[s++]=e.IJvte(e[d(660)](63,h),128);continue;case"4":h=e.yodrX(e[d(1339)](65536,e[d(1460)](1023&h,10)),e[d(623)](1023,m));continue;case"5":n[s++]=e[d(1302)](h>>12&63,128);continue}break}}else n[s++]=e[d(1736)](h>>12,224),n[s++]=e[d(484)](e[d(1013)](h,6),63)|128,n[s++]=e[d(1736)](e[d(1477)](63,h),128);else{if(this[d(756)][d(270)+d(248)+d(804)]||this[d(548)+"osed"])return;this[d(991)+d(987)]()}return e[d(1410)](s,f)}}async function el(a){let n=t;if(n(1186)==typeof a){let s=new Uint8Array(e[n(1716)](Xd,a));return e[n(1436)](aa,a,s,0),s}return e[n(1432)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(1548)],a[n(801)+"et"],a[n(275)+"th"])}function lp(a){let n=t;try{return e.YaChC(e[n(983)],typeof a)&&(e.yGMSx(a,ArrayBuffer)||a[n(1548)]&&a.buffer instanceof ArrayBuffer)||e[n(1364)](e.skhJX,typeof a)?"":(JSON[n(1280)](a),"applicat"+n(1357))}catch{return e[n(1461)](e[n(983)],typeof a)?n(1363)+n(1275)+n(1037):""}}let up=(a,n)=>{let s=t;if(e.zaaYV!==e[s(886)])switch(a){case e[s(372)]:case e.liLFQ:return{[s(1444)+a]:1,"x-tt-env":n};default:return{}}else return ye[s(277)+"tManager"]?.[s(914)+s(1564)+"ntTriesC"+s(245)]()||0};class fp{constructor(n){let s=t;this["maxLossC"+s(245)]=n,this[s(1068)]=0}addCount(){let n=t;this[n(1068)]++}[t(1390)+t(662)+"nt"](){let n=t;return this[n(1068)]>=this[n(1396)+"ount"]}resetCounter(n=0){let s=t;this[s(1396)+s(245)]=n,this.count=0}}async function xp(a){return new Promise(n=>{let s=F,d={NqufT:function(f,h){return f>>h},OGTaS:function(f,h){return e.WutPt(f,h)},sMndL:function(f,h){return e[F(971)](f,h)},IqMRX:function(f,h){return e[F(885)](f,h)},FvUMS:function(f,h){return f!==h},yfURt:"XZYMZ",bRSBd:e[s(943)],LMGYB:e.qvMFL};if(e[s(1028)](e.kgVLs,e.eplmZ))this._DBName=_0x30cc13,this[s(613)]=_0x50ff2e,this[s(1139)]=_0x10a1ad?_0x37c98e:_0x504a5f?_0x57b212:null;else{if(!Yn)return e[s(1534)](n,e[s(1378)]);try{if(e[s(1659)]!==e[s(1659)])_0x22382b[_0x4709e2++]=nDxQnZ[s(1420)](_0x59e4b0,6)|192,_0x16a2be[_0x3510a7++]=nDxQnZ[s(185)](nDxQnZ[s(1267)](63,_0x9862fd),128);else{let f=document[s(1360)+s(198)](e[s(294)]);window[s(1570)+s(821)]=h=>{let m=s;if(d[m(1156)](d[m(1380)],d[m(1212)]))document.body[m(1075)+m(346)](f),window["frontier"+m(821)]=void 0,n(h&&h[m(1700)]||d[m(223)]);else return _0x5078c7[m(1524)+"t8"]?_0x596b1d[m(1524)+"t8"](_0xc67508,_0x3c3906):_0x517cdb[_0x4a9a9e]=255&_0x5e5127,d[m(1138)](_0x499dd6,1)},f[s(1621)]=e[s(327)],f[s(1585)]=e[s(293)](a.replace(/^ws/,s(1105)),e[s(1254)]);try{document[s(1229)][s(1172)+s(346)](f)}catch{document[s(1229)][s(1075)+s(346)](f)}}}catch{window[s(1570)+s(821)]=void 0,e.PTexC(n,e.qvMFL)}}})}function tn(a,n,s){return!!a?.find(d=>d.key===n&&d.value===s)}function Jn(a,n){let s=t;return a?.[s(595)](d=>d[s(1674)]===n)?.value}let ca=null;async function hp(){let a=t;return e[a(271)](e.WVNPQ,e.AzqeP)?(ca||(ca=Promise[a(1244)]()[a(1252)](Mt[a(1018)](Mt,a(1019)))),ca):this[a(1139)]?.[a(267)](_0x182672)}class pp extends oa{constructor(n,s){let d=t;super(),this._dbName=n,this[d(592)]=s,this[d(1139)]=void 0,this[d(1529)+"mise"]=null}async[t(917)](){await this[t(1247)]()}async _init(){let n=t,s={zQCNZ:function(d,f){return d<=f},jzjQE:function(d,f){return e[F(516)](d,f)},dWsID:function(d,f){return e[F(647)](d,f)},HLGzT:function(d,f){return e[F(280)](d,f)},VXxaj:function(d,f){return e[F(1020)](d,f)},gEVZj:function(d,f){return e[F(1295)](d,f)},zmYpZ:function(d,f){return e.lWzOI(d,f)},mhUIX:function(d,f){return e[F(1322)](d,f)},btYtd:function(d,f){return e[F(246)](d,f)},vPHCg:function(d,f){return e.HhIhy(d,f)},FZnkF:function(d,f){return e[F(1273)](d,f)},WjPjl:function(d,f){return d>>f},yOUfw:function(d,f){return e.hsJxL(d,f)},QrGgb:e[n(1384)],DBLxC:e[n(1176)],ZkCDW:e[n(1248)]};if(!this._qosDB){if(this[n(1529)+n(1192)])return this[n(1529)+"mise"];try{let d=this[n(1168)],f=this[n(592)];this["_initPro"+n(1192)]=(async()=>{let h=n;if(e[h(457)](e[h(1256)],e[h(1256)])){let m=_0x1e7f4f[h(781)]();return m?(m[h(1114)]=m[h(1257)]=0,m):{bytes:new _0x1a8083(64),offset:0,limit:0}}else{let{openDB:m}=await hp();this[h(1139)]=await e.pAlBm(m,h(1570)+"_"+d,1,{upgrade(v){let g=h,P={hxIJC:function(k,L){return s[F(836)](k,L)},lWfMS:function(k,L){return k>=L},sBgxe:function(k,L){return k<L},BUVWf:function(k,L){return s[F(1109)](k,L)},nstFP:function(k,L){return s[F(1135)](k,L)},ZfIqO:function(k,L){return s.dWsID(k,L)},hXmiK:function(k,L){return s[F(361)](k,L)},GhxdQ:function(k,L){return s[F(1042)](k,L)},sNkOd:function(k,L){return k|L},elJCu:function(k,L){return s.gEVZj(k,L)},BmGGE:function(k,L){return s[F(463)](k,L)},RIHys:function(k,L){return s[F(485)](k,L)},RMJrd:function(k,L){return k|L},OfKLk:function(k,L){return s[F(1679)](k,L)},Aesdy:function(k,L){return s[F(842)](k,L)},AdQuD:function(k,L){return s[F(847)](k,L)},kiHQf:function(k,L){return s[F(535)](k,L)},bjfxZ:function(k,L){return s.vPHCg(k,L)}};if(s[g(835)](s[g(1672)],s[g(483)])){let k=_0x4ede31[_0x348c81++];if(nWjZBY[g(915)](k,127))_0x40a5ea+=_0x36d7a0["fromChar"+g(329)](k);else if(nWjZBY[g(772)](k,192)&&nWjZBY.sBgxe(k,224))_0x3c8261+=_0x6a75b3[g(236)+g(329)](nWjZBY.BUVWf(nWjZBY[g(1654)](31,k),6)|nWjZBY[g(1123)](63,_0x351b96[_0x4b6151++]));else if(nWjZBY[g(655)](k,224)&&nWjZBY[g(1742)](k,240))_0x134a55+=_0x308bb5[g(236)+"Code"](nWjZBY[g(367)](nWjZBY[g(1743)](nWjZBY[g(1123)](15,k),12)|nWjZBY[g(603)](63,_0x849169[_0x328757++])<<6,nWjZBY[g(1654)](63,_0x161b54[_0x5d1998++])));else if(nWjZBY.hXmiK(k,240)){let L=nWjZBY.RIHys(nWjZBY[g(478)](nWjZBY[g(1293)](nWjZBY.elJCu(7&k,18),nWjZBY[g(402)](63&_0x3b916e[_0x353dca++],12)),nWjZBY.BUVWf(nWjZBY[g(1654)](63,_0x3a4068[_0x5e6fc2++]),6)),nWjZBY[g(526)](63,_0x3a6be7[_0x5a5e46++]))-65536;_0x410418+=_0x1ecce7[g(236)+g(329)](nWjZBY[g(945)](55296,nWjZBY[g(791)](L,10))),_0x148e83+=_0x18f919[g(236)+g(329)](56320+nWjZBY[g(561)](1023,L))}}else v.createObjectStore(d,{keyPath:f})}})}})(),await this[n(1529)+"mise"]}catch(d){console[n(937)](d)}finally{e.iMOUw(e[n(753)],e.SRXMy)?this[n(1529)+"mise"]=null:(this[n(896)+n(1152)][n(874)](_0x49d435),this[n(1093)](s[n(201)],_0x285ec3))}}}async[t(267)](n){let s=t;try{return await this._init(),this[s(1139)]?.get(this._dbName,n)}catch(d){console.log(d)}}async[t(1312)](n,s){let d=t;return await this[d(1247)](),this[d(1139)]?.[d(1393)](this[d(1168)],n)}async del(n){let s=t;if(e[s(1038)]===e[s(525)])this[s(1139)]?.[s(656)](_0x102788[s(282)+"id"]);else try{return await this[s(1247)](),this._qosDB?.[s(1316)](this[s(1168)],n)}catch(d){console.log(d)}}async[t(1467)](){let n=t,s={KeDfY:function(d,f){return d==f},hLIKb:function(d,f){return e[F(567)](d,f)}};if(e.kwOXC(e[n(1575)],e[n(1443)]))return KAvaSL.KeDfY(this[n(289)+n(513)],this.endpoints[n(1369)])?!0:KAvaSL[n(481)](this[n(934)+"ndpointT"+n(1061)+"t"],this[n(203)+"es"]);try{return await this[n(1247)](),this._qosDB?.clear(this[n(1168)])}catch(d){console[n(937)](d)}}async keys(){let n=t;return await this[n(1247)](),this[n(1139)]?.getAllKeys(this[n(1168)])}async[t(1446)](){let n=t;return e[n(1260)](e[n(1335)],e[n(985)])?(await this[n(1247)](),this._qosDB?.[n(1446)](this[n(1168)])):e[n(965)](e[n(593)](_0x1ad597,4).join("0"),_0x1b3e3f(_0x551ecf,2)[n(636)](16)).slice(-4)}async[t(766)](){let n=t;try{this[n(1139)]?.[n(1739)](),this[n(1139)]=void 0}catch(s){console[n(937)](s)}}get[t(365)](){let n=t;if(e[n(274)]("dxyKU",e[n(606)])){let s=this[n(277)+n(1108)]?.["getCurre"+n(1564)+"nt"]();this._debug("connect "+s+n(1146)),this[n(395)+n(1151)](1001,e[n(990)],!0)}else try{return!!this._qosDB}catch(s){if(e[n(1662)]===e[n(1662)])return console[n(937)](s),!1;{let{type:d}=_0x3857c4;this[n(797)](d,_0x5cfb4f)}}}}class gp{constructor(n,s){let d=t;this[d(507)]=n,this[d(613)]=s,this[d(1139)]=localStorage}async openDB(){}get[t(858)](){return t(1570)+"_"+this._DBName}async get(n){let s=t,d={HhqEf:function(f,h){return e[F(737)](f,h)},qIeml:function(f,h){return e[F(1587)](f,h)},blObD:e[s(619)]};if(e[s(730)](e[s(1577)],e[s(1577)])){if(_0x2c5c0d)return new _0x5512bd(_0x22e8d8[s(1710)],_0x454ffd[s(450)]);if(_0x5c8521||_0x2624ee)return new _0x56de66(_0x4e9af1.url,_0x3df73a[s(450)],_0x1a75ff[s(1132)]);if(mVgveq[s(941)](_0x256562,_0x5b974d)&&mVgveq[s(598)](mVgveq[s(239)],typeof _0x2d23b4)&&_0x35b991)return new _0x20cbba(_0x323ae5.url,_0x25fa56.protocols)}else{let f=this[s(1139)][s(471)](this[s(858)]);return JSON[s(1280)](e[s(737)](f,"{}"))[n]}}async[t(1312)](n,s){let d=t,f=this._qosDB[d(471)](this[d(858)]),h=JSON[d(1280)](f||"{}");return h[s||n[this[d(613)]]]=n,this[d(1139)].setItem(this._prefix,JSON[d(795)+"y"](h)),s||n[this[d(613)]]}async[t(656)](n){let s=t,d=this[s(1139)].getItem(this[s(858)]),f=JSON[s(1280)](d||"{}");return f[n]=void 0,this[s(1139)].setItem(this[s(858)],JSON.stringify(f))}async[t(1467)](){let n=t;return this[n(1139)][n(1467)]()}async[t(480)](){let n=t,s=this._qosDB[n(471)](this[n(858)]),d=JSON.parse(e[n(459)](s,"{}"));return Object[n(480)](d)}async getAll(){let n=t,s=this[n(1139)][n(471)](this[n(858)]),d=JSON.parse(e[n(737)](s,"{}"));return Object[n(1008)](d)}[t(766)](){let n=t;if(e.qnYNl(e[n(1299)],e[n(1299)])){let s=this[n(1139)][n(1196)+n(519)+"nc"](this[n(858)]),d=_0x3e67d0[n(1280)](e[n(1403)](s,"{}"));return _0x38dc52[n(1008)](d)}else return Promise[n(1244)]()}get[t(365)](){let n=t,s={HGhJo:function(d,f,h){return d(f,h)},dqDeJ:function(d,f,h){return e[F(456)](d,f,h)},ezGEu:function(d,f,h){return d(f,h)},pfsuA:function(d,f){return d+f}};if(e[n(1368)](e[n(1362)],e[n(373)])){let{offset:d}=s.HGhJo(_0x59c522,_0x122df9,_0x20ab40);_0x2fc7d2=d;let f={cursor_name:"",cursor:0,service:0},{value:h,offset:m}=s.dqDeJ(_0xe98a1c,_0x4d9b64,_0x1b6495);f[n(1598)]=h,_0x5eaa03=m;let{value:v,offset:g}=s[n(1321)](_0x231d8d,_0xcd9e52,_0x2cea43);_0x1b934c=g,f["cursor_n"+n(862)]=_0x16c121(_0x53e074,_0x51c2f6,s[n(635)](_0x3bb4e7,v)),_0x2714f7+=v;let{value:P,offset:k}=s.dqDeJ(_0xa89309,_0x335abb,_0x17ef40);f.cursor=P[n(1117)](),_0x257cee=k,_0x46070e[n(874)](f)}else return!!this[n(1139)]}}class mp{constructor(n,s){let d=t;this[d(507)]=n,this[d(613)]=s,this[d(1139)]=In?tt:Wr?wx:null}async[t(917)](){}get[t(858)](){let n=t;return n(1570)+"_"+this[n(507)]}async[t(267)](n){let s=t,d=this[s(1139)]["getStora"+s(1427)](this._prefix);return JSON[s(1280)](d||"{}")[n]}async set(n,s){let d=t,f=this._qosDB[d(1196)+"geSync"](this[d(858)]),h=JSON[d(1280)](e[d(737)](f,"{}"));return h[s||n[this[d(613)]]]=n,this[d(1139)][d(901)+d(1427)](this[d(858)],JSON[d(795)+"y"](h)),s||n[this._pathKey]}async[t(656)](n){let s=t,d=this[s(1139)][s(1196)+s(1427)](this[s(858)]),f=JSON[s(1280)](e[s(530)](d,"{}"));return f[n]=void 0,this[s(1139)][s(901)+s(1427)](this[s(858)],JSON.stringify(f))}async clear(){let n=t;return this[n(1139)][n(1361)+n(489)]()}async keys(){let n=t,s=this._qosDB[n(1196)+n(519)+"nc"](this[n(858)]),d=JSON.parse(s||"{}");return Object[n(480)](d)}async[t(1446)](){let n=t,s=this[n(1139)]["getStora"+n(519)+"nc"](this._prefix),d=JSON.parse(e[n(566)](s,"{}"));return Object.values(d)}closeDB(){return Promise[t(1244)]()}get[t(365)](){return!!this[t(1139)]}}function tl(a,n){let s=t,d={BGvqM:function(f,h){return e[F(1057)](f,h)},OnGzF:s(518)+"le"};if(e[s(1084)](e[s(1533)],e.rsJnt)){if(In||In)return new mp(a,n);if(e[s(1403)](Yn,Kr)&&e[s(1587)](e.ENGaz,typeof indexedDB))return new pp(a,n);if((Yn||Kr)&&e[s(1057)](e[s(619)],typeof localStorage))return new gp(a,n);throw new Error(e.CoByO)}else _0x3e616d.r=f=>{let h=s;BVLkMh[h(1035)]("undefined",typeof _0x705371)&&_0x5a4244[h(636)+h(1137)]&&_0xdb5d81[h(582)+h(1754)](f,_0x5a41bc[h(636)+h(1137)],{value:h(466)}),_0x1ea234["definePr"+h(1754)](f,BVLkMh.OnGzF,{value:!0})}}class wp{constructor(){let n=t;this[n(1531)+n(1343)+"Id"]=null,this[n(1531)+"l"]=36e5,this[n(1139)]=tl(e[n(1666)],e[n(250)])}async[t(1531)+t(894)](){let n=t,s={kThfT:function(d,f,h,m,v){return e.aSqHb(d,f,h,m,v)},oYHwx:function(d,f){return e[F(1565)](d,f)},sKvDY:function(d,f){return e[F(1615)](d,f)}};e[n(666)](clearInterval,this[n(1531)+n(1343)+"Id"]),this[n(1531)+n(1343)+"Id"]=e.euIQc(setInterval,()=>{let d=n;e.wveaa===d(1678)?DbUeqI[d(1048)](_0x403e61,DbUeqI[d(1036)](_0x52c11c,_0x44c53d[d(549)]),_0x5e23dc.oldVersion,_0x1c4472[d(1015)+"on"],DbUeqI[d(710)](_0x5c1572,_0xec1037[d(718)+d(495)])):this[d(515)+d(911)]()},this._interval)}async[t(917)](){let n=t;await this._qosDB[n(917)]()[n(1252)](()=>{this["_interva"+n(894)]()})}async["flushExp"+t(911)](){let n=t;(await this[n(1139)]?.[n(1446)]()||[])[n(287)](({timestamp:f})=>f<Date[n(254)]())[n(728)](f=>{let h=n;this[h(1139)]?.[h(656)](f[h(282)+"id"])})}async del(n){let s=t;return this[s(1139)]?.[s(656)](n)}async[t(1312)](n,s){let d=t;return this[d(1139)]?.[d(1312)]({message_id:n,timestamp:s})}async get(n){let s=t;return this[s(1139)]?.[s(267)](n)}async closeDB(){let n=t;e[n(1520)](clearInterval,this["_interva"+n(1343)+"Id"]),await this._qosDB?.closeDB()}get isReady(){let n=t;return this[n(1139)]?.[n(365)]}}function da(a){let n=t,s={YkVNl:function(d,f){return d(f)},Ygjxm:e.iLvSz,PjbsI:e[n(1184)],oCATE:e[n(882)]};if(e[n(1470)](n(591),e[n(189)]))s[n(1660)](_0x469f57,s[n(785)]),this[n(1492)](s[n(1224)],_0x291b91),this[n(1492)](s[n(1004)],_0x199c46);else{let d=!!this[n(756)][n(1561)+"S"];if(!d)return{enabled:d,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let f=e.pAlBm(tn,a.message[n(1132)],e.NofiC,"2"),h=f&&e[n(1331)](tn,a[n(808)].headers,e.cTMeg,"1"),m=f&&e[n(1685)](tn,a.message[n(1132)],e[n(1239)],"1"),v=m?e.wRfdv(Jn,a.message[n(1132)],e[n(1103)])?.[n(1405)](",")[n(287)](Boolean)||[]:[];return{enabled:d,isQoSMessage:f,isQoSAck:h,isAckCleanupMessage:m,ackMsgIds:v}}}async function nl(){let a=t;return this[a(1698)+"ger"]||(this[a(1698)+"ger"]=new wp),this[a(1698)+"ger"][a(365)]||await this[a(1698)+"ger"].openDB(),this["_QoSMana"+a(1725)]}async function _p(a,n){let s=t,{enableAutoAck:d}=this[s(756)],f=e[s(1436)](tn,a[s(808)].headers,e.NEoLg,"1"),h=tn(a.message.headers,e[s(661)],"1"),m=da.call(this,a);if(e.yvBrx(d,f))if(e[s(999)](e.Boxaz,s(215)))this["_cursorF"+s(389)]=_0x46d92e;else{let{SeqID:v,LogID:g,service:P,LogIDNew:k,method:L}=a[s(808)];this._sendAck({SeqID:v,LogID:g,LogIDNew:k,service:P,method:L,headers:[{key:e[s(661)],value:"1"},{key:"ack_id",value:e.XfAPA(k,"")},{key:e[s(650)],value:"0"}]})}h&&!m[s(233)]&&this[s(905)+s(1703)+"ageEvent"](a),e[s(1327)](n)}async function yp(a,n){let s=t;this[s(1093)](e[s(1651)],a[s(808)]),e[s(1327)](n)}async function Ep(a,n){let s=t,d=e[s(1520)](Xt,await e[s(994)](el,a[s(1414)]));try{if(e.dOMeN(d[s(767)],Uint8Array)){let f=this[s(756)][s(1673)+s(1521)]instanceof Object?{force:!!this[s(756)].payloadEncoding[s(252)],encoding:this._options[s(1673)+s(1521)][s(460)]?this[s(756)].payloadEncoding[s(460)][s(387)](/\s/g,"")[s(441)+s(1591)]():""}:{force:!1,encoding:this._options[s(1673)+s(1521)]?this[s(756)][s(1673)+s(1521)][s(387)](/\s/g,"")[s(441)+s(1591)]():""},h=d[s(1673)+s(1521)]?d[s(1673)+"ncoding"].replace(/\s/g,"")[s(441)+s(1591)]():"",m=this[s(756)][s(394)+s(403)]instanceof Object?{force:!!this._options[s(394)+s(403)][s(252)],type:this[s(756)][s(394)+s(403)][s(1621)]?this[s(756)].payloadType[s(1621)][s(387)](/\s/g,"")[s(441)+s(1591)]():""}:{force:!1,type:this[s(756)][s(394)+s(403)]?this[s(756)][s(394)+s(403)][s(387)](/\s/g,"")[s(441)+s(1591)]():""},v=d[s(394)+s(403)]?d[s(394)+s(403)][s(387)](/\s/g,"")["toLowerC"+s(1591)]():"",g=m.force?m[s(1621)]:v||m[s(1621)],P=f.force?f[s(460)]:h||f[s(460)],k=[e[s(967)],e[s(1507)],"applicat"+s(1357)+s(404)+"=utf-8",e[s(983)]],L=[e[s(1232)],e.LBUPB];this[s(756)][s(1059)+"ansformT"+s(538)+"ad"]&&k[s(443)](g)&&(!P||L[s(443)](P))?d[s(800)+s(362)]=Qd(d[s(767)],0,d.payload.byteLength):d[s(800)+s(362)]=""}else d[s(800)+"oad"]=""}catch(f){d.textPayload="",console.log(f)}a[s(808)]=d,e.fxdEe(n)}function bp(a,n,s){let d=t,f=e[d(566)](s,8192),h=e[d(359)](f,1),m=null,v=f;return function(g){let P=d;if(g<1||e.tuFLB(g,h))return e.AkgAP(a,g);e.pKSVv(v,g)>f&&(m=e[P(1128)](a,f),v=0);let k=n.call(m,v,v+=g);return e.ZqWQs(7,v)&&(v=e[P(1274)](7|v,1)),k}}let vp=4294967295;function Sp(a,n,s){let d=t;return RangeError(e[d(1082)](e[d(787)](e.EzKHT(e[d(1647)](e[d(261)]+a,d(344)),e[d(459)](n,1)),d(546)),s))}function Ip(a,n,s){let d=t;if(s>vp)throw new Error(d(258)+d(1130)+"e");let f=3;for(;e[d(1724)](f,0);){let h=255&s;e[d(1430)](ua,h,a,e[d(787)](n,f)),s>>>=8,f--}return n+4}function Ap(a,n){let s=t,d=0,f=n,h=e[s(923)](n,4);for(;e[s(1542)](f,h);){let{value:m,offset:v}=e[s(590)](la,a,f);f=v,d=e[s(815)](e.qomqV(d,8),0),d+=m}return{value:d,offset:h}}function Tp(a,n,s){let d=t,f={rGAHx:function(h,m){return h-m},uuUtZ:function(h,m){return h<m},KagYX:function(h,m){return e[F(1696)](h,m)},HqSoG:function(h,m){return e[F(763)](h,m)},ZwmMI:function(h,m){return e.SYCiE(h,m)},xvTLu:function(h,m){return e[F(1477)](h,m)},jqYcA:function(h,m){return e[F(1295)](h,m)},YzRXC:function(h,m){return h>=m},ZqOaA:function(h,m){return e[F(859)](h,m)},nRuRt:function(h,m){return e[F(242)](h,m)},dLZJu:function(h,m){return h&m},JrOaj:function(h,m){return e.lWzOI(h,m)},aTBcg:function(h,m){return e.BTOWj(h,m)},lLjdJ:function(h,m){return e[F(1189)](h,m)},bSawz:function(h,m){return h&m}};if(e.VzDaU(e.lkyRd,d(256))){if(VigZkK[d(960)](_0xd724a2,_0x1a4d65)<1)return"";let h="";for(let m=_0x1da0b0;VigZkK[d(750)](m,_0xa5d533);){let v=_0x1476b3[m++];if(v<=127)h+=_0x5278cd["fromChar"+d(329)](v);else if(VigZkK.KagYX(v,192)&&VigZkK[d(750)](v,224))h+=_0xee521f[d(236)+"Code"](VigZkK.HqSoG((31&v)<<6,63&_0x132b66[m++]));else if(VigZkK.ZwmMI(v,224)&&VigZkK[d(750)](v,240))h+=_0x5607aa[d(236)+d(329)](VigZkK.HqSoG(VigZkK[d(854)](VigZkK[d(1552)](15,v)<<12,VigZkK[d(1e3)](63&_0xf95885[m++],6)),63&_0x5579a8[m++]));else if(VigZkK[d(263)](v,240)){let g=VigZkK[d(960)](VigZkK.HqSoG(VigZkK[d(1110)](VigZkK.HqSoG(VigZkK[d(1e3)](VigZkK[d(1552)](7,v),18),(63&_0x5b1b8d[m++])<<12),VigZkK[d(1554)](VigZkK[d(368)](63,_0x419b07[m++]),6)),VigZkK[d(1658)](63,_0x467ad2[m++])),65536);h+=_0x287f2b[d(236)+d(329)](VigZkK[d(370)](55296,VigZkK[d(313)](g,10))),h+=_0x3ce5c2[d(236)+d(329)](56320+VigZkK[d(1076)](1023,g))}}return h}else{let h=e[d(681)][d(1405)]("|"),m=0;for(;;){switch(h[m++]){case"0":if(n[d(1307)+"e"])return e[d(826)](n.utf8Write(a,s),s);continue;case"1":if(!a)return s;continue;case"2":if(e[d(1689)](a.length,40))return e[d(712)](e[d(1436)](aa,a,n,s),s);continue;case"3":return e.BTOWj(e.Zxntf(aa,a,n,s),s);case"4":if(n.write)return e[d(1052)](n[d(1656)](a,s),s);continue}break}}}function Cp(a,n){let s=t,d=new ce(e[s(1566)](e[s(1231)](e[s(409)](e[s(805)](a[e.pTKxN(n,4)],24),e[s(816)](a[n+5],16)),e[s(521)](a[e[s(637)](n,6)],8)),a[e[s(569)](n,7)]),e.UGwuc(e[s(317)](e[s(226)](e[s(1034)](a[e.ppuFc(n,0)],24),e.KLgrP(a[n+1],16)),a[e[s(1395)](n,2)]<<8),a[e.yIvws(n,3)]),!0);return n+=8,{value:d,offset:e[s(663)](n,8)}}function Dp(a,n,s){let d=t,f=a[d(221)],h=a[d(299)];return n[s]=h>>>24,n[e[d(1082)](s,1)]=e[d(1546)](h,16)&255,n[e[d(1721)](s,2)]=e[d(799)](e.IkkFM(h,8),255),n[e[d(1463)](s,3)]=255&h,n[s+4]=e[d(815)](f,24),n[e[d(1556)](s,5)]=e[d(1447)](e[d(815)](f,16),255),n[s+6]=e[d(918)](e[d(1528)](f,8),255),n[e.DMzzF(s,7)]=255&f,s+=8,s}function la(a,n){let s=t;return a[s(1385)+"8"]?{value:a[s(1385)+"8"](n),offset:e.GHJCg(n,1)}:{value:e[s(1475)](255,a[n]),offset:e[s(1556)](n,1)}}function ua(a,n,s){let d=t;return n[d(1524)+"t8"]?n[d(1524)+"t8"](a,s):n[s]=e[d(1688)](255,a),s+1}let Rp=function(a){let n=t,s={QjrRU:function(d,f){return d!==f},FxCcf:function(d,f){return e.PdVnG(d,f)},BgCah:e[n(1541)]};if(e[n(1568)](n(547),n(547)))return new Uint8Array(a);this._navigatorOnline()&&(!this._ws||s.QjrRU(this[n(581)].readyState,this[n(1115)])||s.FxCcf(this[n(581)][n(1532)+"te"],this[n(1448)+"NG"]))&&this[n(335)+n(1663)](),this._isBrowser&&_0x25f02a[n(1717)+n(1040)](s[n(1483)],this[n(335)+n(1663)]),this._isBrowser&&_0x1eca0f[n(1717)+n(1040)](n(689),this["_handleO"+n(1193)])},kp=e[t(893)](e[t(619)],typeof Buffer)?Buffer[t(316)+t(1237)]:e.fdfQa(bp,Rp,Uint8Array[t(952)+"e"].subarray);(()=>{let a=t,n={vdcTU:function(d,f){return e[F(220)](d,f)},UWJNx:function(d,f){return d|f},KZQDt:function(d,f){return d<<f},Gitkw:function(d,f){return e[F(869)](d,f)},POSvC:function(d,f){return e[F(1317)](d,f)},mpoOn:function(d,f){return e[F(1416)](d,f)},OZtsp:function(d,f){return d|f},KGsLD:function(d,f){return d>f},DhMpa:e[a(887)],tpQkZ:function(d,f,h,m){return d(f,h,m)}},s=4294967295;return function(d,f,h=!0){let m=a;if(s=n[m(383)](127&d[f],0),d[f++]<128)return{value:h?s:n[m(904)](0,s),offset:f};if(s=n[m(383)](n.UWJNx(s,n[m(634)](n[m(1291)](127,d[f]),7)),0),d[f++]<128)return{value:h?s:0|s,offset:f};if(s=n[m(436)](s,n.KZQDt(n[m(1291)](127,d[f]),14))>>>0,d[f++]<128)return{value:h?s:n[m(436)](0,s),offset:f};if(s=n.vdcTU(n[m(904)](s,n[m(634)](127&d[f],21)),0),n.mpoOn(d[f++],128))return{value:h?s:0|s,offset:f};if(s=n[m(383)](n[m(625)](s,n[m(1291)](15,d[f])<<28),0),d[f++]<128)return{value:h?s:0|s,offset:f};if(n[m(1471)](f+=5,d[m(1369)])){if(n.DhMpa!==n[m(1402)])return!0;throw f=d[m(1369)],n[m(857)](Sp,f,10,d[m(1369)])}return{value:h?s:n[m(436)](0,s),offset:f}}})();let Pp=16,fa=32;function Op(a){let n=t;if(e[n(1508)]!==e.QuDOP)return this[n(229)][n(586)+"pe"];{let s=0,d={};for(let f=0;f<a.length;f++)if(e[n(1547)](e[n(315)],n(1166)))d[a[f][n(641)+n(862)]]=e[n(1474)](Xd,a[f][n(641)+n(862)]),s+=e[n(408)](14,d[a[f][n(641)+n(862)]]);else return e.XvjnI(e.skhJX,typeof _0x1487b7)&&(e[n(385)](_0x42c8db,_0x1badbf)||_0x4432f9[n(1548)]&&_0xf7890c.buffer instanceof _0x408573)||n(1186)!=typeof _0x3cc6f1?"":(_0x3edd49[n(1280)](_0x4a50fa),e.BIEvI);return[s,d]}}function rl(a,n,s){let d=t,[f,h]=e[d(1183)](Op,a),m=kp(f),v=0;return a[d(728)](g=>{let P=d;console[P(937)](e[P(1349)],g,g.service),v=e.qcuFx(ua,0,m,v),console[P(937)](e.tPvEg,v),v=Ip(m,v,g[P(1598)]||0),console.log(e[P(196)],v),v=e[P(1436)](ua,h[g.cursor_name],m,v),console[P(937)](e[P(1223)],v),v=e[P(1430)](Tp,g[P(641)+P(862)],m,v),console.log(e[P(1287)],v),v=e.KbfNm(Dp,ce[P(1026)+"er"](g[P(554)]||n),m,v),console[P(937)](e[P(508)],v)}),{frameType:fa,headers:[{key:e[d(1178)],value:s}],payload:m}}function Np(a){let n=t;if(e[n(279)](e.CVguX,e.CVguX)){let s=0,d=[];for(;e.gkDeu(s,a[n(275)+"th"]);){let{offset:f}=e[n(1692)](la,a,s);s=f;let h={cursor_name:"",cursor:0,service:0},{value:m,offset:v}=e.QXILT(Ap,a,s);h[n(1598)]=m,s=v;let{value:g,offset:P}=e[n(446)](la,a,s);s=P,h[n(641)+n(862)]=e[n(1336)](Qd,a,s,e[n(1530)](s,g)),s+=g;let{value:k,offset:L}=Cp(a,s);h[n(554)]=k[n(1117)](),s=L,d.push(h)}return d}else this[n(797)](e.IGiVv,e.oDWfN(_0x40897c,e[n(782)],{..._0x5ac76a,message:_0x2e1fe1[n(755)]||""}))}function Lp(){let a=t;return{frameType:fa,headers:[{key:e[a(1178)],value:e[a(310)]}],payload:void 0}}class Mp{constructor(n,s,d){let f=t;if(e[f(425)](e[f(1720)],"aolpM")){_0x47fbaf(_0x40bc04,42);let h=e[f(1596)](_0x4e35c5);e[f(790)](_0x3e8f3f,_0x5b1e58,h),e[f(207)](_0x56992e,_0x363d42,h[f(1257)]),e[f(793)](_0x3b070c,_0x5f3fae,h),e[f(369)](_0x1d1162,h)}else this["_cursorN"+f(247)]=n,this[f(779)+f(389)]=s,this[f(896)+f(1060)]=d,this._qosDB=tl(this[f(1266)+"ameSpace"],e[f(1578)])}async[t(917)](){let n=t;await this[n(1139)][n(917)]()}async[t(1159)+"rs"](){let n=t;if(!this[n(1139)][n(365)])return;let s=this[n(896)+"Strategy"],d=await this[n(1139)][n(1446)]();switch(console[n(937)](n(1498)+"rValues",d),s){case e[n(1628)]:return d&&d[n(1369)]?e.srARL(rl,d,0,this[n(779)+n(389)]):void 0;case e[n(1278)]:return;case e[n(863)]:return d&&d.length?e[n(955)](rl,d,0,this._cursorFileName):Lp()}}async[t(1312)](n,s,d){let f=t;return console.log(e.KaDAV,n,s,d),this[f(1139)][f(1312)]({cursor_name:n,cursor:s,service:d})}async setCursors(n){let s=t,d=Np(n);for(let f of d)console[s(937)](e.ycuVD,d),await this[s(1139)].set(f)}async[t(267)](n){let s=t;return(await this._qosDB[s(267)](n))?.cursor}async[t(766)](){await this[t(1139)].closeDB()}[t(194)+t(240)+"Name"](n){let s=t;this[s(779)+s(389)]=n}get[t(365)](){let n=t;return this[n(1139)][n(365)]}}let Bp=t(607)+t(806);async function il(a){let n=t;if(e[n(1085)](e[n(377)],e.nVBRe)){if(!this[n(756)][n(1561)+"S"])return null;let{aID:s,fpID:d,messageStrategy:f}=this[n(756)],h=e.VmKYv(a,Bp);try{return this[n(1150)+n(1680)]?a&&this[n(1150)+n(1680)]["updateCursorFile"+n(1649)](a):this["_cursorM"+n(1680)]=new Mp(d+"_"+s+"_"+h,h,f),this[n(1150)+n(1680)].isReady||await this[n(1150)+n(1680)][n(917)](),this[n(1150)+"anager"]}catch{return e[n(340)](e[n(922)],e[n(922)])?new _0x108989(_0xb067fb,{data:_0xdaf96c,message:_0xf15ce9}):null}}else{if(e[n(909)](_0x51a220,1)||e[n(1497)](_0x598385,_0x78cf48))return e[n(1294)](_0x11d26e,_0x314fd0);e[n(608)](e[n(354)](_0x13b338,_0x792e2),_0x56c3e5)&&(_0x36cec6=e[n(744)](_0x987b0a,_0x3bfbe9),_0x43f45c=0);let s=_0x49ef73.call(_0x45b070,_0x3513ef,_0x5502d1+=_0x344353);return e[n(355)](7,_0x1dd073)&&(_0x2df4bb=e.WqLeD(e[n(1544)](7,_0xa1ee1f),1)),s}}async function zp(a,n){let s=t,d={aVTPs:function(Q,Y){return Q(Y)}},f=e[s(574)](tn,a[s(808)][s(1132)],e[s(1664)],"-1"),h=e.srARL(tn,a.message.headers,e[s(661)],"1"),m=e.RPFlk(Jn,a[s(808)][s(1132)],e[s(674)]),v=e.coWXc(Number,e[s(1207)](Jn,a.message.headers,e[s(1636)]))||0,g=da[s(1642)](this,a),P=e[s(251)](tn,a[s(808)][s(1132)],e[s(699)],"2"),k=e[s(1692)](Jn,a[s(808)].headers,e[s(996)]),L=e[s(1210)](Number,e[s(1043)](Jn,a[s(808)][s(1132)],e[s(1511)]));if(g[s(233)])return e.TgveC(n);let W=g[s(415)+"sage"]?await nl[s(1642)](this):null;if(e[s(1440)](a[s(808)].service,0)&&h&&!f||e[s(602)](a.message[s(1598)],0))if(e[s(1169)]("UUXGC",e[s(1367)])){if(m&&g[s(415)+s(1606)]&&W)return!!!await W[s(267)](m)&&(this[s(905)+s(412)+"Event"](a),await W[s(1312)](m,e[s(408)](Date[s(254)](),v))),e.edyPc(n);if(P){let Q=await il[s(1642)](this);if(!Q)return this[s(905)+s(412)+"Event"](a),e[s(431)](n);let Y=await Q[s(267)](k)??-1;if(e[s(780)](Y,L))this[s(905)+"hMessage"+s(783)](a),Q.set(k,L,a[s(808)].service);else throw new Error("recevied"+s(1627)+s(1558)+L+(s(925)+s(1078)+s(1049)+"r ")+Y);return n()}return this[s(905)+s(412)+s(783)](a),e[s(773)](n)}else _0x4e210b[_0x4c441d[_0x33b201][s(641)+s(862)]]=QDbUbY.aVTPs(_0x1da704,_0x3adc19[_0x1acbc4][s(641)+s(862)]),_0x661bb3+=14+_0x2c3f55[_0x9cb71c[_0x27bd87][s(641)+s(862)]]}async function Fp(a,n){let s=t,d=da[s(1642)](this,a);if(!d["isQoSMes"+s(1606)])return e[s(1054)](n);let f=await nl[s(1642)](this);if(d[s(1202)+s(685)+s(1695)]&&d[s(1502)+"s"][s(1369)])for(let h of d[s(1502)+"s"])await f[s(656)](h);n()}async function Up(a,n){let s=t,d=e[s(301)](a[s(808)][s(1311)+"e"],Pp),f=e[s(1285)](a[s(808)][s(1311)+"e"],fa);if(e.iwFIF(!d,!f))return e.ntoGl(n);let h=e[s(589)](Jn,a[s(808)][s(1132)],e[s(1178)]);if(!h)return e.PrObR(n);let m=await il[s(1642)](this,h);if(!m)return e.FYjlH(n);if(d){let v=await m[s(1159)+"rs"](),g={frameType:v?.[s(1311)+"e"],SeqID:ce[s(1026)+"er"](this[s(1424)]++),LogID:ce[s(1026)+"er"](this[s(756)][s(1017)+"erator"]()),service:9e3,method:5,headers:v?.[s(1132)],payload:v?.[s(767)]},P=e.HOmJQ(S,g);this._ws&&this[s(581)].readyState&&this[s(581)][s(1296)](P)}if(f){let v=a[s(808)][s(767)];v&&m[s(1455)+"rs"](v)}}let Gp=async function(a,n){let s=t;this[s(668)]=!1,e[s(1565)](clearTimeout,this[s(424)+s(1119)+s(1353)]),e[s(773)](n)},qp=async function(a,n){let s=t;if(!this[s(581)]||e[s(769)](this[s(581)][s(1532)+"te"],this[s(1115)]))return e.TgveC(n);let{pingInterval:d}=this._options;this[s(277)+"tManager"]?.[s(1177)+s(976)+s(371)]();for(let h=0;e[s(780)](h,this["_message"+s(1152)][s(1369)]);h++){let m=this[s(896)+s(1152)][h];if(e[s(1368)](this[s(581)][s(1532)+"te"],this[s(1115)])&&e.TvjQe(null,m))this._ws&&this[s(581)][s(1296)](m),this[s(896)+s(1152)][h]=null;else break}this[s(896)+s(1152)]=this[s(896)+s(1152)].filter(h=>!!h),this[s(1732)+s(305)+"Id"]=setTimeout(()=>this[s(490)](),d),this[s(905)+s(953)+"nt"](a),this[s(449)+"er"]&&this[s(581)]&&(this[s(581)][s(586)+"pe"]=this[s(1608)+s(403)]);let f=this[s(277)+s(1108)]?.["getCurre"+s(1564)+"nt"]();this[s(1093)](s(1657)+f+s(609)),e[s(1464)](n)},Hp=async function(a,n){let s=t,d={sKcXP:function(f,h){return f(h)}};if(e[s(1285)](e.cJFIF,e[s(1581)]))_0x36e775=HkesPc.sKcXP(_0x4513a7,_0x5f27eb),_0x25cb68|=(127&_0x3791ab)<<7;else{let f=this[s(277)+s(1108)]?.[s(914)+s(1564)+"nt"]();this[s(1093)](s(1657)+f),n()}};class jp extends oa{constructor(n){let s=t,d={RvXEz:e[s(782)],YfICu:function(f,h,m){return e[s(553)](f,h,m)},yXshk:s(1417),RbmHw:function(f,h){return e[s(382)](f,h)}};if(e.KUiZa!==e[s(186)]){super(),this[s(1289)+s(819)+s(334)]=!0,this[s(449)+"er"]=Yn,this._isNode=op,this[s(723)+"T"]=In,this[s(541)+"X"]=Wr,this[s(462)+"r"]=Kr,this[s(896)+s(1152)]=[],this[s(277)+"tManager"]=null,this[s(548)+s(1555)]=!1,this["_binaryT"+s(403)]=e[s(1745)],this["_connect"+s(727)]=!1,this["_connect"+s(1119)+s(1353)]=null,this["_reconne"+s(820)+s(1215)]=null,this[s(1732)+s(305)+"Id"]=null,this[s(1424)]=0,this[s(668)]=!1,this[s(1599)]="",this[s(1698)+s(1725)]=null,this[s(1150)+s(1680)]=null,this[s(1693)+s(947)]=null,this[s(981)+"ls"]=e[s(879)],this.CLOSED=3,this[s(1448)+"NG"]=0,this[s(1115)]=1,this.CLOSING=2,this[s(1726)]=v=>{let g=s;try{Jd(this,v,[Gp,qp,Hp])}catch(P){let k=st(d.RvXEz,{message:P[g(808)],code:en[g(872)+"OR"],error:P});this["_dispatchErrorEv"+g(1571)](k)}},this._onMessage=async v=>{let g=s,{pingInterval:P,pingFrequency:k}=this[g(756)];if((e[g(1547)]("hi",v[g(1414)])&&e[g(325)](e.vCmay,k)||e[g(1523)](g(1522),k))&&(this[g(777)+g(577)](),this.emit(e[g(1184)],e[g(296)]),this[g(1732)+"gTimeoutId"]=setTimeout(this[g(490)][g(1018)](this),P)),v.data!=="hi")try{e[g(437)](Jd,this,v,[Ep,_p,Fp,Up,zp,yp])}catch(L){let W=st(e[g(782)],{message:L[g(808)],code:en.MESSAGE_ERROR,error:L});this["_dispatchErrorEv"+g(1571)](W)}},this[s(1065)]=v=>{let g=s,P=this["_endpoin"+g(1108)]?.[g(1390)+g(1268)+"es"](),k=this[g(277)+g(1108)]?.["getCurre"+g(1564)+"nt"]();if(P&&!v[g(808)]){let L=g(829)+k+(" fail, m"+g(1617)+g(1633)+"ed");this["_dispatc"+g(1572)+g(1571)](d.YfICu(st,d[g(1325)],{message:L,code:en[g(1086)+g(211)+"R"],error:v}));return}this[g(581)]&&this[g(581)].readyState===this[g(1115)]&&this[g(395)+g(1151)](),this["_dispatc"+g(1572)+g(1571)](d[g(1319)](st,d[g(1325)],{message:v[g(808)],code:en[g(1188)+"RROR"],error:v}))},this[s(512)]=async v=>{let g=s;if(e[g(228)]("FkWdy",g(684))){this[g(843)+"mer"](),this["_clearPi"+g(577)](),this["_removeW"+g(638)+"rs"](),this[g(581)]=null,this["_connect"+g(727)]=!1;let P=this[g(277)+g(1108)]?.[g(1390)+g(1268)+"es"]();if(!P&&this[g(1567)+g(352)]()&&!this[g(548)+"osed"]){let k=this[g(277)+g(1108)]?.[g(914)+g(1564)+"nt"](),L=this[g(756)][g(1003)+"tInterce"+g(1398)](v[g(1074)],v[g(1453)]);this[g(905)+g(307)+"ent"](xt(e[g(1392)],{code:1006,reason:v[g(1453)]||g(381)+g(1113)+g(491)+g(1133)+g(832)+g(807)+k,willReconnect:L})),L&&this[g(424)]();return}if(e[g(827)](1e3,v.code)&&this[g(548)+g(1555)]){this[g(905)+g(307)+g(1571)](e[g(1222)](xt,g(1739),{code:1e3,reason:e[g(1298)]})),this[g(277)+g(1108)]?.["resetEnd"+g(976)+g(371)](),this[g(1693)+g(947)]?.["resetCou"+g(726)]();return}if(e[g(1729)](1e3,v[g(1074)])&&P){let k=this[g(277)+g(1108)]?.[g(914)+g(1564)+"nt"](),L=v[g(1453)];L||(L=await e[g(216)](xp,this[g(1599)])),L=g(381)+g(1113)+g(1459)+L+(", hostna"+g(338))+k+(", max re"+g(199)+g(1250)),this[g(905)+g(307)+g(1571)](e[g(1573)](xt,g(1739),{code:v[g(1074)],reason:L}));let W=g(829)+k+(g(1234)+"ax retri"+g(1633)+"ed");this[g(905)+g(1572)+g(1571)](e.uKaTe(st,e[g(782)],{message:W,code:en["MAX_RETR"+g(211)+"R"]})),this[g(277)+g(1108)]?.[g(1177)+g(976)+g(371)](),this["_pingLos"+g(947)]?.[g(813)+g(726)]();return}if(e.OCnrk(1e3,v[g(1074)])&&!v[g(1453)]){let k=this[g(277)+g(1108)]?.[g(914)+g(1564)+"nt"]();this["_dispatc"+g(307)+g(1571)](e[g(1199)](xt,e.thYbx,{code:v[g(1074)],reason:g(381)+"ng faile"+g(491)+"wn reaso"+g(832)+g(807)+k})),this[g(277)+g(1108)]?.[g(1177)+"pointCon"+g(371)](),this._pingLossCounter?.[g(813)+g(726)]();return}this[g(905)+g(307)+"ent"](v),this[g(277)+g(1108)]?.[g(1177)+g(976)+"fig"](),this[g(1693)+"sCounter"]?.resetCounter()}else return this[g(1139)]?.[g(365)]},this[s(184)]=null,this.onerror=null,this[s(190)+"e"]=null,this[s(1431)]=null,this[s(1640)+s(987)]=null,this[s(1375)+s(1313)]=null,this[s(1597)+s(474)+"yReconnect"]=null,this[s(335)+s(1663)]=this[s(335)+s(1663)][s(1018)](this),this._handleOffLine=this[s(335)+s(1193)][s(1018)](this),this["_handleP"+s(520)]=this[s(391)+s(520)][s(1018)](this),this._handlePageShow=this[s(391)+s(1024)].bind(this),this[s(756)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e.hFnLo(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(529)],pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(863)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:h}=n,m=Array[s(378)](f)?f:e.pFTlg("string",typeof f)?[f]:[];if(!m||e.kjdKn(0,m[s(1369)]))throw new Error(e[s(584)]);if(!e[s(1310)](dp,h))throw new Error(e[s(639)]);Object.assign(this[s(756)],n),this[s(277)+s(1108)]=new Yd(m,this[s(756)][s(203)+"es"]),this[s(1693)+s(947)]=new fp(this._options[s(426)+s(351)]),this[s(756)][s(1482)+"cOpen"]&&(s(1457)===s(452)?(this[s(581)]&&this[s(581)][s(1296)](_0x124718),this[s(1093)](d[s(846)],_0x14d85f)):(this[s(668)]=!0,this[s(424)]())),this[s(756)]["listenNetworkCha"+s(802)]&&(this._isMiniTT||this[s(541)+"X"]?this[s(1437)+s(1171)+s(455)]():this[s(449)+"er"]&&this[s(1226)+s(972)+s(1040)]())}else{let f=_0x2b1d82[s(1114)];if(ZDDzBt[s(1063)](f,_0x595120)>_0x54234e.limit)throw new _0x357527(s(995)+s(1462));return _0x19a194.offset+=_0x21da95,f}}[t(335)+"nLine"](){let n=t;this._options[n(270)+n(248)+n(804)]||this[n(548)+n(1555)]||this[n(991)+n(987)]()}[t(335)+t(1193)](){let n=t;this[n(416)+n(1479)+"t"]();let s=e[n(290)](sa,e[n(587)],{message:n(951)+"ediately reconnect"});this[n(1597)+n(474)+n(690)+"ct"]&&this[n(1597)+n(474)+n(690)+"ct"](s)}[t(1226)+t(972)+t(1040)](){let n=t;this._isBrowser&&window[n(1717)+"Listener"](e.ZvezY,this[n(335)+n(1663)]),this[n(449)+"er"]&&window[n(1717)+n(1040)](n(689),this["_handleO"+n(1193)]),this[n(449)+"er"]&&window[n(1717)+n(1040)](e.TTDPA,this["_handleP"+n(520)]),this[n(449)+"er"]&&window[n(1717)+n(1040)](e[n(1677)],this["_handleP"+n(1024)])}[t(432)+"balEvent"+t(1040)](){let n=t;this._isBrowser&&window[n(861)+n(1245)+n(761)](n(1230),this["_handleO"+n(1663)]),this._isBrowser&&window["removeEventListe"+n(761)](e[n(1472)],this[n(335)+"ffLine"]),this[n(449)+"er"]&&window["removeEv"+n(1245)+"ner"](e[n(1332)],this["_handleP"+n(520)]),this[n(449)+"er"]&&window[n(861)+n(1245)+n(761)](e[n(1677)],this["_handleP"+n(1024)])}[t(391)+"ageHide"](n){let s=t;n[s(1264)+"d"]||(e[s(227)](e.rDGSL,e[s(1218)])?(this[s(449)+"er"]&&window[s(861)+s(1245)+"ner"](e[s(1332)],this[s(391)+"ageHide"]),this[s(449)+"er"]&&window["removeEventListe"+s(761)](s(1100),this[s(391)+s(1024)]),this[s(1739)]()):this[s(723)+"T"]?_0xd4d34c[s(1684)+s(811)+"hange"](({isConnected:d})=>{let f=s;this["_miniNav"+f(819)+f(334)]=d,d?this[f(335)+f(1663)]():this[f(335)+"ffLine"]()}):this[s(541)+"X"]&&_0x46c139[s(1684)+"kStatusC"+s(469)](({isConnected:d})=>{let f=s;this[f(1289)+f(819)+f(334)]=d,d?this[f(335)+f(1663)]():this["_handleO"+f(1193)]()})),this[s(449)+"er"]&&window[s(861)+s(1245)+s(761)](e.ZvezY,this[s(335)+"nLine"]),this[s(449)+"er"]&&window[s(861)+s(1245)+s(761)](e[s(1472)],this["_handleO"+s(1193)])}[t(391)+t(1024)](n){let s=t;e[s(667)](e[s(504)],s(1650))?n[s(1264)+"d"]&&(this[s(1567)+s(352)]()&&(!this._ws||this[s(581)].readyState!==this[s(1115)]||this[s(581)].readyState!==this[s(1448)+"NG"])&&this._handleOnLine(),this[s(449)+"er"]&&window[s(1717)+s(1040)](e[s(1541)],this["_handleO"+s(1663)]),this._isBrowser&&window["addEvent"+s(1040)](e[s(1472)],this[s(335)+s(1193)])):(_0x30df6a=_0x98b907[e[s(633)](_0x4f8eee,_0x572050)+1],_0x57176e=_0x1abff0[e[s(585)](e[s(798)](_0x2b97e7,_0x3c88cf),2)],e[s(657)](e[s(659)](_0x39f986,e.qaOiI(_0x1b3982,8)),49344)!==32896?_0x36c3a6+=_0x14dbdd:(_0x5562ce=e[s(732)](15,_0x21a86a)<<12|e[s(897)](63&_0x6e8805,6)|e.SekaO(63,_0x491c1a),_0x1fc84<2048||_0x1edf04>=55296&&e[s(1580)](_0x5465b7,57343)?_0x46f81a+=_0x389852:(_0x3d3efc+=_0x20d73f(_0x1d5fb9),_0x1e568f+=2)))}async["_generat"+t(1434)](n){let s=t,{fpID:d,deviceID:f,bddID:h,ttwID:m,accessKey:v,aID:g,customParams:P={},enableAutoAck:k,enableQoS:L,QoSLevel:W,env:Q}=this._options,Y,Xe,ot;if(this[s(449)+"er"]||this[s(541)+"X"]||this[s(723)+"T"])Y=location&&e.IpYHx==location.protocol?s(1373):s(708),Xe=n.replace(/((^ws)|(^http))((?:[s]*:\/\/))/,""),ot=/^wss(.*:\/\/)/[s(1219)](n)?n:""+Y+Xe;else if(e[s(241)](e[s(292)],e[s(292)]))Y=e[s(407)],Xe=n[s(387)](/(^http)((?:[s]*:\/\/))/,""),ot=/(^ws)((?:[s]*:\/\/))/[s(1219)](Xe)?Xe:""+Y+Xe;else return _0x540d97(_0x4dd8e3);let ht=h?s(1346):m?s(1163):e.IGpiB,ts=h||m||f;if(!ts||!ht)throw new Error(e.PeuCh);let sl=e.YPmPd==typeof P?await e.IUENE(P):P,Wp=Q?e[s(1706)](up,Q[s(1265)],Q[s(907)]):{},xa=Object[s(652)]({device_platform:s(958),version_code:e[s(218)],access_key:v,fpid:d,aid:g,[ht]:ts,xsack:k?1:0,xaack:k?1:0,xsqos:L?1:0,qos_level:L?W:void 0,qos_sdk_version:2,...Wp},sl),Kp=Object[s(480)](xa).reduce((ha,pa)=>xa[pa]!==void 0?""+ha+(ha?"&":"?")+pa+"="+xa[pa]:ha,"");return ot+s(620)+Kp}async[t(424)](){let n=t;if(!(this[n(424)+n(727)]||this[n(548)+"osed"])){this["_connect"+n(727)]=!0;try{let s=this[n(277)+n(1108)]?.[n(916)+n(555)+"ointReac"+n(1029)+n(1351)](),{timeoutInterval:d}=this._options;if(s){let h=this["_endpoin"+n(1108)]?.[n(914)+n(1564)+"nt"](),m=this[n(277)+n(1108)]?.[n(928)+n(1702)+n(356)+n(1634)+"unt"](),v=this[n(277)+"tManager"]?.[n(914)+n(1564)+"ntTriesC"+n(245)]();if(m){let g=n(829)+h+(n(1146)+n(1747)+n(199)+n(1047)+n(749)+"backup e"+n(1637))+m+(n(707)+"y"),P=e[n(553)](st,e[n(782)],{message:g,code:en["MAX_RETR"+n(211)+"R"]});this[n(1093)](g),this[n(905)+n(1572)+n(1571)](P),this[n(1599)]=await this._generateUrl(m),this._debug(n(829)+m+" "+v+n(932)),this[n(237)+"sListeners"]()}else{let g="connect "+h+(n(1146)+n(1747)+n(199)+n(1250));this._debug(g),this[n(905)+n(1572)+n(1571)](e.zhLgH(st,e[n(782)],{message:g,code:en[n(1086)+n(211)+"R"]}));return}}else{let h=this[n(277)+"tManager"]?.[n(914)+n(1564)+n(1687)+n(243)](),m=this[n(277)+"tManager"]?.[n(914)+n(1564)+"ntTriesCount"]();this[n(1599)]=await this[n(1303)+"eUrl"](e[n(737)](h,"")),this[n(1093)](n(829)+h+" "+m+n(932)),this._removeWsListeners()}if(this[n(668)])this[n(668)]=!1;else{let h=e[n(553)](sa,e[n(587)],{message:e.ytRip});this[n(1640)+n(987)]&&this[n(1640)+n(987)](h)}let f=this[n(277)+n(1108)]?.[n(914)+n(1564)+n(924)+n(245)]()||0;f>1&&await this[n(870)](e.QjnNt(f,1)),this[n(1093)](n(381)+n(725)+this._url+(n(705)+"ls: ")+this[n(981)+"ls"]),this[n(581)]=e[n(281)](cp,{url:this[n(1599)],protocols:[this[n(981)+"ls"]],headers:this[n(756)][n(1208)+n(235)+"s"][n(698)+n(1158)]},this._options.ws),(this[n(449)+"er"]||this._isWorker)&&this[n(581)]&&(this._ws[n(586)+"pe"]=this[n(1608)+n(403)]),this[n(720)+n(1748)](),this[n(424)+n(1119)+n(1353)]=e[n(974)](setTimeout,this[n(1557)+"ut"][n(1018)](this),d)}catch(s){if(e.GQueQ(e.giPxK,"vykAb"))rJVtcy.toiKg(_0xfc81be,_0x2b10c5[n(1235)]||new _0x15d89d(n(719)+"or",rJVtcy[n(1203)])),rJVtcy[n(1626)](_0x36fb30);else throw this[n(424)+"Lock"]=!1,s}}}[t(843)+"mer"](){let n=t;e[n(1409)](clearTimeout,this[n(424)+n(1119)+"utId"]),this[n(424)+n(1119)+n(1353)]=null}[t(777)+t(577)](){let n=t;e[n(622)](clearTimeout,this[n(1732)+"gTimeoutId"]),e[n(1255)](clearTimeout,this[n(748)+n(820)+n(1215)]),this[n(1732)+n(305)+"Id"]=null,this[n(748)+n(820)+n(1215)]=null}[t(1093)](...n){let s=t;this[s(756)].debug&&console.log[s(1211)](console,[s(1091)+">",...n])}[t(1359)+"rvalValue"](n){let s=t,{initReconnectInterval:d,maxReconnectInterval:f,reconnectIntervalGrowFactor:h}=this[s(756)],m=e.YiDxd(d,Math[s(867)](h,e[s(1410)](n,1)));return e.ZeBvU(m,f)?f:m}[t(490)](){let n=t,s={vFGgi:function(d,f){return e[F(1366)](d,f)}};if(e[n(1630)](e[n(1170)],e[n(1170)])){let d=_0x2f0d37[n(1111)],f=_0x330500[n(1257)];return Vsliwg[n(488)](d[n(1369)],f)?d:d.subarray(0,f)}else{if(this[n(581)]&&e.MaRNz(this[n(581)][n(1532)+"te"],this[n(1448)+"NG"])){this[n(777)+n(577)](),this[n(1732)+n(305)+"Id"]=setTimeout(this[n(490)][n(1018)](this),this[n(756)][n(374)+n(1173)]);return}if(!this._ws||this._ws.readyState!==this[n(1115)])return void this[n(991)+n(987)]();this[n(581)]&&this[n(581)][n(1296)]("hi"),this[n(748)+n(820)+n(1215)]=e[n(503)](setTimeout,this[n(991)+n(987)+"Timeout"][n(1018)](this),this._options[n(968)+n(683)+n(323)])}}["_handleR"+t(987)+t(273)](){let n=t;this[n(1693)+n(947)]?.addCount(),this[n(797)](e[n(882)],n(1069)),this[n(1693)+n(947)]?.[n(1390)+n(662)+"nt"]()?this[n(991)+n(987)]():this._ping()}[t(1567)+"orOnline"](){let n=t,s={iSVqX:function(d,f){return e[F(419)](d,f)},rmJdQ:n(986)+n(1453),xlxqK:e[n(327)],VNbgh:function(d,f){return d+f},micHN:e[n(1543)],MHzvE:n(1631)+n(1610)+n(1167)+"P"};if(e[n(1277)]===e[n(564)]){let d=_0x44bd70["createEl"+n(198)]("script");_0x4df7ff[n(1570)+n(821)]=f=>{let h=n;_0x132b5c[h(1229)][h(1075)+h(346)](d),_0x5d24d2[h(1570)+h(821)]=void 0,WZoNEc[h(1501)](_0x14fe12,f&&f[h(1700)]||WZoNEc.rmJdQ)},d[n(1621)]=WZoNEc[n(1305)],d.src=WZoNEc[n(276)](_0x2b0e47[n(387)](/^ws/,WZoNEc[n(1629)]),WZoNEc[n(600)]);try{_0x36175b.body[n(1172)+"ild"](d)}catch{_0x4e42ab[n(1229)]["removeCh"+n(346)](d)}}else return this[n(723)+"T"]||this[n(541)+"X"]?this["_miniNav"+n(819)+n(334)]:(this[n(449)+"er"]||this[n(462)+"r"])&&this._options[n(1616)+n(349)+n(802)]?navigator[n(736)]:!0}[t(991)+t(987)](){let n=t;!this[n(1567)+n(352)]()||this[n(548)+"osed"]||(this[n(277)+n(1108)]?.[n(1177)+"pointCon"+n(371)](),this[n(1693)+"sCounter"]?.["resetCou"+n(726)](),this[n(581)]?this[n(395)+n(1151)](1001,n(314)+"ay, try "+n(1003)+n(414)+n(298),!0):this[n(424)]())}[t(1437)+t(1171)+t(455)](){let n=t;this[n(723)+"T"]?tt[n(1684)+n(811)+n(469)](({isConnected:s})=>{let d=n;this[d(1289)+d(819)+d(334)]=s,s?this[d(335)+d(1663)]():this[d(335)+d(1193)]()}):this[n(541)+"X"]&&wx["onNetwor"+n(811)+n(469)](({isConnected:s})=>{let d=n;this["_miniNavigatorOn"+d(334)]=s,s?this[d(335)+d(1663)]():this[d(335)+d(1193)]()})}[t(870)](n){let s=t;if(e[s(1704)]("eGnwm",e[s(1354)]))rJVtcy[s(1709)](_0x24e86c,rJVtcy[s(593)](_0x28ae4f,_0x5d2bb3[s(549)])),rJVtcy[s(1464)](_0x2d3471);else return new Promise(d=>{setTimeout(d,this[s(1359)+"rvalValue"](n))})}[t(395)+t(1151)](n=1e3,s="",d=!1){let f=t;this._ws&&this[f(416)+f(1479)+"t"](n,s,d)}_onTimeout(){let n=t,s=this[n(277)+n(1108)]?.["getCurre"+n(1564)+"nt"]();this[n(1093)]("connect "+s+" timeout"),this[n(395)+n(1151)](1001,n(1418)+n(283)+n(536)+"g",!0)}[t(774)](n){let s=t,d=e.HEpAz(Ft,n);if(this._ws&&e[s(1697)](this[s(581)][s(1532)+"te"],this.OPEN)){if(e[s(332)]===s(818))return new _0x3b3941(_0x39aaaa,{data:_0x81b7f4});this[s(581)]&&this[s(581)].send(d),this._debug(e[s(1315)],n)}}[t(237)+t(638)+"rs"](){let n=t,s=(n(1388)+"0")[n(1405)]("|"),d=0;for(;;){switch(s[d++]){case"0":this._ws[n(861)+n(1245)+n(761)](e.IGiVv,this[n(1065)]);continue;case"1":if(!this[n(581)])return;continue;case"2":this[n(581)]["removeEv"+n(1245)+n(761)](e[n(1392)],this._onClose);continue;case"3":this[n(581)]["removeEv"+n(1245)+"ner"](e.oIUNn,this._onMessage);continue;case"4":this[n(581)][n(861)+n(1245)+n(761)](e[n(1605)],this[n(1726)]);continue}break}}[t(720)+t(1748)](){let n=t,s=e.aWYlJ[n(1405)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(581)][n(1717)+"Listener"](e[n(1392)],this[n(512)]);continue;case"1":if(!this[n(581)])return;continue;case"2":this[n(581)][n(1717)+n(1040)](e[n(782)],this._onError);continue;case"3":this[n(581)][n(1717)+n(1040)](e[n(1236)],this[n(1141)+"ge"]);continue;case"4":this._ws[n(1717)+"Listener"](e[n(1605)],this._onOpen);continue}break}}[t(1539)+t(651)](n=1e3,s=""){let d=t;if(e[d(422)](d(855),e[d(1490)])){if(_0x5f7667>=_0x5f2845)return _0x33cd10}else try{if(e.LCJnD!==e.fImFG)this[d(581)]&&this._ws[d(1739)](n,s);else{let f=this[d(277)+d(1108)]?.getCurrentEndpoint(),h=this[d(756)][d(1003)+d(1499)+d(1398)](_0x26eb73.code,_0x94543a[d(1453)]);this["_dispatc"+d(307)+d(1571)](e[d(1043)](_0x37473d,e[d(1392)],{code:1006,reason:_0x5a3743[d(1453)]||d(381)+"ng faile"+d(491)+d(1133)+d(832)+d(807)+f,willReconnect:h})),h&&this._connect();return}}catch{}}[t(416)+t(1479)+"t"](n=1e3,s="",d=!1){let f=t;if(this._clearPingTimer(),this[f(843)+f(841)](),this[f(237)+f(638)+"rs"](),this[f(1539)+f(651)](1e3,s),this[f(424)+f(727)]=!1,d&&this[f(1567)+f(352)]()&&!this["_readyCl"+f(1555)]){if(this[f(277)+f(1108)]?.[f(1390)+"chMaxTries"]()){let m=this["_endpoin"+f(1108)]?.["getCurre"+f(1564)+"nt"]();this["_dispatchCloseEv"+f(1571)](e[f(446)](xt,e[f(1392)],{code:1006,reason:f(829)+m+(f(1146)+", max retries re"+f(1250)),wasClean:!0}))}else{let m=this[f(756)][f(1003)+f(1499)+"ptor"](n,s);this[f(905)+f(307)+f(1571)](e[f(1692)](xt,e[f(1392)],{code:n,reason:s,wasClean:!0,willReconnect:m})),m&&this[f(424)]()}return}this[f(1567)+f(352)]()||this[f(548)+f(1555)]?this[f(905)+f(307)+f(1571)](e[f(503)](xt,e[f(1392)],{code:n,reason:e[f(1298)]})):this[f(905)+f(307)+f(1571)](e.fAAYk(xt,e[f(1392)],{code:1006,reason:"going aw"+f(191)+"ork offl"+f(231)})),this[f(581)]=null,this[f(277)+f(1108)]?.["resetEnd"+f(976)+f(371)](),this[f(1693)+f(947)]?.resetCounter()}["_dispatc"+t(953)+"nt"](n){let s=t;if(e[s(192)]==="ariNP")return _0x2268e3?_0x2e146c["fromByte"+s(429)](_0x15dd33,_0x5dc1e0):_0x397bdf[s(796)+s(1001)](_0x33a655,_0x57016a);this[s(797)](e.MRMSi,n),this[s(1431)]&&this[s(1431)](n)}["_dispatchMessage"+t(783)](n){let s=t;this[s(797)](s(808),n),this[s(190)+"e"]&&this[s(190)+"e"](n)}[t(905)+"hAckMess"+t(883)](n){let s=t;this[s(797)](s(673),n),this.onReceiveAck&&this[s(1375)+s(1313)](n)}[t(905)+t(1572)+t(1571)](n){let s=t;this[s(797)](s(1235),n),this[s(906)]&&this[s(906)](n)}["_dispatc"+t(307)+t(1571)](n){let s=t,d={ElJaM:function(f,h){return e[F(593)](f,h)},BNoyk:function(f,h){return e[F(977)](f,h)},CcOpc:function(f,h){return f(h)},CuMTq:s(864),wJgvq:"ffff"};if(e[s(1194)]===s(895))this[s(797)](s(1739),n),this[s(184)]&&this.onclose(n);else{let f=_0x7941f[s(1405)](/\./).map(v=>_0x35ceec(v)),h=[];return h[0]=CXjaSz.ElJaM(_0x2c5397,CXjaSz[s(396)](f[0],f[1])),h[1]=CXjaSz[s(672)](_0x5a8db9,CXjaSz[s(396)](f[2],f[3])),[s(864),CXjaSz[s(942)],CXjaSz.CuMTq,CXjaSz[s(942)],CXjaSz[s(942)],CXjaSz.wJgvq,h[0],h[1]][s(1751)]("")}}get[t(586)+"pe"](){let n=t,s={JyVwx:e[n(200)],HZQtf:e[n(1383)],MCJGb:e[n(1287)],OCYFU:e[n(508)],gcWEv:function(d,f,h,m){return e.srARL(d,f,h,m)},fhHnC:e[n(196)]};if(e[n(1752)](e.UKzpp,e[n(891)]))return this[n(581)]?this._ws.binaryType:this[n(1608)+n(403)];{let d=s.JyVwx[n(1405)]("|"),f=0;for(;;){switch(d[f++]){case"0":_0x5c1fe4[n(937)](Zeujof[n(940)],_0x3fe36c);continue;case"1":_0x44fa23[n(937)](Zeujof.MCJGb,_0x323ef9);continue;case"2":_0x551d06[n(937)](Zeujof[n(1329)],_0x482c77);continue;case"3":_0x5c9af9=Zeujof.gcWEv(_0x44a48e,_0x10236b[n(1026)+"er"](_0x4da407[n(554)]||_0x18c3ec),_0x33ad4b,_0x440cc1);continue;case"4":_0x2ab6a2[n(937)](Zeujof[n(931)],_0x42b23b);continue;case"5":_0x7993c1.log(n(1494)+n(1081),_0x4687f8,_0x3a4de9.service);continue;case"6":_0x3b9808=_0x26cfdd(0,_0x5e7080,_0x3ab3e4);continue;case"7":_0x378341=Zeujof[n(930)](_0x3c1205,_0x4cb0c6[_0x225c67[n(641)+n(862)]],_0x4b9be9,_0x329069);continue;case"8":_0x324193=Zeujof[n(930)](_0x4338a9,_0x126990[n(641)+n(862)],_0x4ebafc,_0x4e5281);continue;case"9":_0x52ba16[n(937)](n(320)+n(285),_0x26e94a);continue;case"10":_0x1e262e=Zeujof.gcWEv(_0x56a350,_0x253500,_0x330e9a,_0x47c51f[n(1598)]||0);continue}break}}}set binaryType(n){let s=t;this[s(1608)+s(403)]=n,this[s(581)]&&(this._ws[s(586)+"pe"]=n)}get[t(1537)+"nt"](){let n=t;return this[n(277)+n(1108)]?.[n(914)+"ntEndpoi"+n(924)+n(245)]()||0}get[t(1619)+t(803)](){let n=t;return this[n(896)+n(1152)][n(1112)]((d,f)=>(d+=f&&f.byteLength||0,d),0)+(this[n(581)]?this[n(581)][n(1619)+n(803)]:0)}get[t(978)+"ns"](){let n=t;return this._ws?this._ws[n(978)+"ns"]:""}get[t(450)](){let n=t;return this[n(581)]?this[n(581)][n(450)]:""}get[t(1532)+"te"](){let n=t;return this[n(581)]?this[n(581)][n(1532)+"te"]:this[n(756)][n(1482)+n(560)]?this[n(1448)+"NG"]:this[n(1116)]}get[t(1710)](){let n=t;if(e[n(1028)](e[n(1404)],e[n(1404)]))return this._ws?this[n(581)].url:this._url;{let s=this[n(1139)][n(471)](this[n(858)]),d=_0x19705b[n(1280)](e[n(566)](s,"{}"));return _0x1b5ac0[n(480)](d)}}[t(1739)](n=1e3,s){let d=t,f=e[d(618)][d(1405)]("|"),h=0;for(;;){switch(f[h++]){case"0":this[d(1698)+d(1725)]?.[d(766)]();continue;case"1":this[d(843)+d(841)]();continue;case"2":if(this[d(581)][d(1532)+"te"]===this[d(1116)]||e[d(680)](this[d(581)][d(1532)+"te"],this[d(1136)]))return void this[d(1093)](e[d(1426)]);continue;case"3":this[d(416)+d(1479)+"t"](n,s);continue;case"4":if(!this[d(581)])return void this[d(1093)](d(418)+"s instan"+d(1397)+"nitialized");continue;case"5":this["_dropGlo"+d(972)+d(1040)]();continue;case"6":this[d(548)+d(1555)]=!0;continue;case"7":this[d(777)+d(577)]();continue}break}}async[t(1296)](n,s){let d=t;if(e[d(1461)](null,n))throw new Error(e[d(1070)]);e.pFTlg(e[d(502)],typeof n)&&(n=JSON[d(795)+"y"](n)),e[d(993)]("string",typeof n)&&!e.dOMeN(n,ArrayBuffer)&&!(n[d(1548)]&&e[d(1330)](n[d(1548)],ArrayBuffer))&&(n=JSON[d(795)+"y"](n));let f=await el(n),h=e.TNGvK(lp,n),{method:m=0,service:v=this._options[d(1598)],logID:g=this[d(756)][d(1017)+d(979)](),headers:P=this[d(756)].headers,payloadEncoding:k=this._options[d(1673)+d(1521)],payloadType:L=this._options[d(394)+d(403)],logIDNew:W=this._options["logIDNew"+d(388)][d(1450)+d(1216)+d(300)+"ew"]?i(this._options[d(696)+d(388)][d(1655)]):""}=e.yDiWR(s,{});if(!v)throw new Error(e.Vmjck);let Q={SeqID:ce.fromNumber(this[d(1424)]++),LogID:ce[d(1026)+"er"](g),service:v,method:m,headers:P,payloadEncoding:e[d(262)](k,Object)?k.encoding?k[d(460)]:"":k,payloadType:e[d(1021)](L,Object)?L.type?L.type:h:L||h,payload:f,LogIDNew:W},Y=e.qJJTe(Ft,Q);return this[d(581)]&&e[d(1549)](this[d(581)][d(1532)+"te"],this.OPEN)?(this[d(581)]&&this[d(581)][d(1296)](Y),this[d(1093)](e[d(1031)],Q)):e[d(1263)](this["_message"+d(1152)][d(1369)],this[d(756)]["maxMessa"+d(998)+"ength"])?(this["_message"+d(1152)][d(874)](Y),this[d(1093)](e[d(1248)],Q)):(this[d(896)+d(1152)][d(1051)](),this._messageQueue[d(874)](Y)),{seqID:this[d(1424)],logID:g,logIDNew:W}}async reconnect(n){let s=t,{url:d}=e.VmKYv(n,{}),f=Array[s(378)](d)?d:e[s(288)](e.skhJX,typeof d)?[d]:[];n&&Object[s(652)](this._options,n),f&&f[s(1369)]?this[s(277)+s(1108)]=new Yd(f,this[s(756)][s(203)+"es"]):this[s(277)+"tManager"]?.[s(1177)+s(976)+s(371)](),this[s(1693)+s(947)]?.[s(813)+s(726)](this._options[s(426)+"Count"]),this[s(548)+"osed"]=!1,this._ws&&e[s(397)](this[s(581)][s(1532)+"te"],this[s(1116)])?this._disconnect(1e3,e[s(1002)],!0):(this[s(668)]=!0,this._connect())}async[t(962)](){let n=t,s={LIglG:function(d,f){return e[F(1181)](d,f)},tCUtl:function(d,f){return e[F(1341)](d,f)},JhIfb:function(d,f){return d&f},osNid:function(d,f){return d>>f},Vihri:function(d,f){return d<f},IzGrP:function(d,f){return e.avdaO(d,f)},GkbgO:function(d,f){return e[F(1643)](d,f)},wqiLr:function(d,f){return e[F(1342)](d,f)},BMwou:function(d,f){return e[F(213)](d,f)},FSzQL:function(d,f){return e[F(1735)](d,f)},TjqcO:function(d,f){return e[F(1134)](d,f)},kGKjq:function(d,f){return e[F(1297)](d,f)},DPjps:function(d,f){return e.IeBGj(d,f)}};e[n(745)]===n(255)?(OBINZY[n(1381)](_0x439749,2048)?_0x1c15dc[_0x3e631c++]=OBINZY[n(264)](OBINZY[n(1737)](OBINZY[n(615)](_0x11505e,6),31),192):(OBINZY[n(421)](_0x3372e3,65536)?_0x3a80c5[_0xc60c70++]=OBINZY.IzGrP(OBINZY[n(206)](OBINZY[n(1391)](_0x14b795,12),15),224):(_0x485053[_0x1ee5a2++]=OBINZY[n(966)](OBINZY[n(493)](OBINZY[n(596)](_0x179c54,18),7),240),_0xa517fc[_0x478ec5++]=OBINZY[n(493)](OBINZY.TjqcO(_0x1f6125,12),63)|128),_0x19db0c[_0x5e46cd++]=OBINZY[n(669)](OBINZY.DPjps(_0x47f520,6),63)|128),_0xdf8560[_0x29acd7++]=OBINZY[n(1737)](63,_0x170ea0)|128):!this[n(424)+n(727)]&&(this[n(277)+"tManager"]?.[n(1177)+n(976)+"fig"](),this[n(1693)+n(947)]?.[n(813)+"nter"](),this._readyClosed=!1,this._isInit=!0,this[n(424)]())}[t(1717)+t(1040)](n,s){this.on(n,s)}["dispatch"+t(783)](n){let s=t;if(e[s(353)]==="XghNb")return this._isMiniTT||this[s(541)+"X"]?this["_miniNavigatorOn"+s(334)]:(this[s(449)+"er"]||this[s(462)+"r"])&&this[s(756)]["listenNe"+s(349)+s(802)]?_0x3bf692[s(736)]:!0;{let{type:d}=n;this.emit(d,n)}}[t(861)+"entListener"](n,s){this[t(1492)](n,s)}[t(1579)](){let n=t,s={eZmEQ:e[n(296)],oLmhb:n(873)+"e_success",vDPem:n(873)+n(1740)+"t",DhiPF:function(d,f){return e[n(929)](d,f)},WmzTu:e[n(376)],TPwPQ:function(d,f){return e[n(1294)](d,f)},Wszqu:e[n(1661)]};return new Promise((d,f)=>{let h=n,m={lQfng:e.iaJTP};this[h(777)+h(577)](),this[h(1732)+h(305)+"Id"]=setTimeout(this[h(490)][h(1018)](this),this._options[h(374)+h(1173)]);let v=()=>{let P=h;d(s[P(326)]),this[P(1492)](s.oLmhb,v),this[P(1492)](s[P(988)],g)},g=()=>{let P=h;if(s[P(851)](s[P(1609)],s[P(1609)])){let k=m[P(1350)][P(1405)]("|"),L=0;for(;;){switch(k[L++]){case"0":this[P(424)]();continue;case"1":this[P(548)+P(1555)]=!1;continue;case"2":this[P(1693)+"sCounter"]?.["resetCou"+P(726)]();continue;case"3":this[P(277)+"tManager"]?.[P(1177)+"pointCon"+P(371)]();continue;case"4":this[P(668)]=!0;continue}break}}else s[P(544)](f,s.Wszqu),this[P(1492)]("ping_onc"+P(838)+"s",v),this[P(1492)](s[P(988)],g)};this.on(e[h(1184)],v),this.on(h(873)+h(1740)+"t",g),this[h(490)]()})}}})(),ye[B(1270)+B(1590)]=Ce[B(1270)+B(1590)],ye[B(552)+B(1538)]=Ce[B(552)+B(1538)],ye[B(1324)+"e"]=Ce.ErrorCode,ye.Event=Ce.Event,ye.FWS=Ce.FWS,ye["Frontier"+B(322)+B(957)]=Ce["Frontier"+B(322)+B(957)],ye["MessageE"+B(957)]=Ce[B(322)+B(957)],ye[B(328)+"t"]=Ce.OpenEvent,ye[B(268)+B(856)]=Ce["Reconnec"+B(856)],ye[B(482)+"oseEvent"]=Ce["createCl"+B(1590)],ye["createEr"+B(1538)]=Ce[B(701)+B(1538)],ye[B(822)+B(1387)+"nt"]=Ce[B(822)+B(1387)+"nt"],ye[B(1379)+B(1526)]=Ce[B(1379)+"enEvent"],ye[B(878)+B(444)+B(957)]=Ce[B(878)+"connectE"+B(957)],ye.decodedFrame=Ce[B(238)+B(775)],ye[B(1044)+"ame"]=Ce.encodeFrame;function F(t,e){t=t-183;let r=To(),i=r[t];if(F.kVMSrI===void 0){var o=function(x){let p="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",w="",_="";for(let S=0,E,b,A=0;b=x.charAt(A++);~b&&(E=S%4?E*64+b:b,S++%4)?w+=String.fromCharCode(255&E>>(-2*S&6)):0)b=p.indexOf(b);for(let S=0,E=w.length;S<E;S++)_+="%"+("00"+w.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(_)};F.dxTpHs=o,F.CegKiS={},F.kVMSrI=!0}let c=r[0],l=t+c,u=F.CegKiS[l];return u?i=u:(i=F.dxTpHs(i),F.CegKiS[l]=i),i}for(Eo in Ce)[B(1270)+B(1590),B(552)+B(1538),B(1324)+"e","Event",B(295),B(1648)+B(322)+"vent","MessageEvent",B(328)+"t",B(268)+B(856),"createCl"+B(1590),B(701)+"rorEvent",B(822)+B(1387)+"nt",B(1379)+"enEvent","createReconnectE"+B(957),B(238)+B(775),"encodeFr"+B(862)][B(624)](Eo)===-1&&(ye[Eo]=Ce[Eo]);var Eo;function To(){let t=["z1LOr1G","zgf0yq","zxjFBxnNAwq","wvDhy3K","C2vUDa","DgLTzw91DcW","zNPfrgK","tNf1zLq","vMfmCNC","AwLlv1y","Ewfrqwu","x3nLCuLK","ser3sei","t2vytMq","z2vtEw5J","y0Dlzfq","u1LPyva","wNHUDgy","B25VCgvU","CgzzBMi","tMTbAg0","zvvYBa","EKrLDg8","CefSqM0","x29UugfNzu4","AwrTEK8","B25Ut0m","z0PxteC","twLVy3K","Cfborfe","C1zRv2G","Ec11C2uT","DLjkDxC","z2v0qwXS","s2THv0u","q09otKvdveK","y25mBNi","zw5HyMXLqxu","ihzHBgLKihm","B2nRzxrtDwm","CMvHC29U","ywrmt04","C2v0q3vYC28","qNzkAum","q0LMvLi","AenVAwi","zcWG","CwfpAuK","CezuBgC","DcbSAw1PDa","sxLOvxO","EurtqvG","zw5KCg9PBNq","t2vwvhu","y2XLyxi","DwPmA28","u0vWrLq","qMPOENC","s0DZteq","ENPlBNG","sNLNu0K","u1L1Buu","u2vRyu8","y2D0tKO","DKPRDem","tejkywq","v2vIu29JA2u","sfLkqw4","y3vYDMfSDwu","yxv0B21HDgK","qMDdywG","EhnKBLa","Exnju1e","yM9L","z1LdC0m","C3vIyxjYyxK","y3r4","tKf3ufu","ugTWueu","B2zM","zfn5CMC","y3vYC29YlNm","yLbABMi","yvz1q3C","DvL0Cvu","ywXSq3vYC28","DeLUDgvYy2u","AhvWB1i","AvnwCvG","ywnRtxnNswq","s3fcuNi","z2v0qwXSs2u","AxDABeq","EhLrwhe","qKLfDKK","uxvet1a","DMfSDwu","EwTeA2u","vNDLwvG","CNbdAxG","ugX2rLK","zMvY","ywX3yxLZ","rwzRD3y","reiGzMfPBgu","zNr2AgO","veXpCuS","v2nryMW","BMnVzgLUzW","yxv0BW","t2jqCue","D3jPDgvvAw4","vLb4zMu","zw5fDMvUDa","yxHAEwq","sMDJALe","x2LUAxrqCM8","r29MEKe","x2LUDgvYDMe","CMvHzhLtDge","CNnkBNq","qwTNqva","ALrRrfe","Dhvirg0","CMv0CNLdB3u","CM9YrxzLBNq","x3DZsw5ZDge","Egn1B0m","wNzLELK","z3LJqu8","wfv5uK0","tKr0DMm","sg5WtLm","yLHev08","B2nzy3i","yNvMzMvY","wgLize0","rKvyCvm","y0X6DLu","Ehzuthu","CMvZzxruCMK","BLj1uNq","B3nLza","r3LWywy","x29UvgLTzw8","ign1CNnVCIa","rvjst1i","z1bewxK","zw5HyMXLuw8","Ew5ZrKK","BwfxseC","BNrfBMrWB2K","s1HWqwO","tNHNzfq","x25HDMLNyxq","vNPeyvu","x2nYzwf0zvm","zNjVBNrPzxi","zw50","AevYCM9Yrxy","BvrntwC","BwfUDwfSihi","DhjWtge","BNrtrwO","vLjRyMy","zffvEu8","CgLUz09Uy2u","qK1Jq3m","C3HLt08","vfbWuKS","ALroCxy","qKnfrNO","C3jJ","u1LdAuu","wwfdAem","rKLxtfG","B2Hls0S","B3nLrxzLBNq","yxnL","twLZC2LUzYa","CKnqwwu","BuPxu1m","AffIA1e","zxb0u0O","B25tDg9Wsw0","C2vYDMLJzq","x3vYBa","B2jQzwn0u3q","BM9Uzv9UB24","qxrKDhm","Bg5UvwG","Dg9iyxnO","tvjnu2K","C2fNzq","su5tvefova","x2jPBMfYEvq","v216vhu","ywnRpwzYB24","Aw9WEvi","CKnzD3q","v1nItLC","twr5DKm","q0Dvy04","BgLZDgvUtMu","yxGGCMv0CMK","tK1yz0q","yNvMzMvYzwq","DhrhzvO","DhLWzq","rKrxCNK","A2PKs24","thDYtMe","AwjWEK4","AhPxquu","ig1LC3nHz2u","swnOEvq","BwLJse4","zhrhvMK","jMPZy2fSBgi","CMvXDwLYzwq","zxmGCMvHy2G","vxbKyxrLq28","sMf6y08","z2TVwue","BMrWB2LUDca","qKTYue0","B3jL","B25tDgfYDfi","weX0yKm","y2fSBa","vuLACLK","wLPMvhK","wgrxuMG","BMrjwLG","q0LbqKy","rNjVBNrPzxi","tMfTzq","wfnnAw0","tKnSEeC","v3D0Eva","z25bqKu","BNn0rLa","DxnLCKLW","D3jPDgu","B3bLBIa","sNjpywO","Dg9pEfi","wwTwtMW","AuX2u3O","wMjSu2K","BKXPBMu","u0nLvfi","B3bLBG","tvLcyKe","txfiu0G","q09oveLovuu","EunvEg0","tKfSBwG","Bw9YB0O","uxjhz2i","Cgf5Bg9Hzeu","A2v5","C3vJy2vZCW","vw5oB2e","s0L6r3e","r0fNwuG","yNrzDgq","yw5Hz2vY","zxHWB3j0CW","CNjpv08","Cw9YEfa","B25ozxr3B3i","yMLkB04","Bwv0Ag9K","BNrbBMrvCgq","r09bCfC","quvYwgi","AhPrzwy","D2TSv1u","DuTHvgu","x3bPBMDmB3m","vMzgv3a","ywDL","Affpt3m","CerpsKe","x1fVu01HBMe","wMTMy0S","BxnN","veDcweG","ywnRDxbfBMq","AefJA01LC3m","rfHkz1q","AKvTCgO","qNzTDLm","oduWmZHHD01vzu8","tfPev1i","rxjbA0y","DxjS","AwXLx25HBwu","v3v0uhq","uKfJs0G","whjtu0q","wMHutee","EwjdqKS","ywrKrxzLBNq","C2vYDMvYvgK","AK5RDgy","v1rSB3G","EKTTseO","wKTttuW","qujTCNa","ENHezLK","z2vY","x29Ut3bLBG","C0LszMm","s1nNEgO","Cw5ztMW","uuTdwKC","BMCGB3iGyw4","x3bPBMDqB24","yKPiAxu","D3vAChm","u2Xjwhq","DNzqu2K","sMHjzMi","zgrjrcWGzgu","y2XVC2u","zv90Aw1LB3u","BM5QugG","r2H4zfe","zwXkq3u","BfHdq0e","tNfpuuW","DejXq3G","lcbTyxGGCMu","C3rLBMvYCW","D2LSBfjLy28","wgfIse4","AM9PBG","A3frwwS","r0Hkq2C","B3bLCNr5","yuLes2C","B25JBg9Zzq","t0Duyvm","ug9Nzha","Dg9cExrLCW","BwvZ","u1rVtxq","B25TzxnZywC","yxKSig5LDhC","u0z0rhO","CuPkvgu","DxbKyxrLq3u","CwDvAeG","BNfwrKK","B0zRq3O","zw1LBNq","DhjPzxmGCMu","AfvNCeS","wMTdrfC","mxWYFdb8nhW","Bwf4uMv0CMK","C3vTANK","zxjFDhrS","r2TIz08","uxDJC3a","z2LkqMe","yxn4rxy","u0HtrLi","suvtx0vsuK8","BuLryMe","suTquuS","AvzVyNO","v2TUEM8","y2fgqMm","Cxf2BeG","zMvysfG","ignVzgu6ia","D3LUBu0","Bg93","Au1pvxC","te1hwui","CK9zq3a","uwjWALi","BhHYDMK","vwzYuKK","r05ODLu","x3nVy2TLDa","rgDnANa","Aw5L","ntj2CNj2BKq","AxnrB1nby2S","v1Ldv2y","CMfTugfYyw0","zNjVBunOyxi","x3jLBw92zvC","zgvJB2rLzey","yMXpyKq","CNnVCKzPBgu","AfLSyNu","vhv2Ahm","yxrLq291BNq","yw9SCe0","B3vUDa","y1zJEfe","yw1Lu3bHy2u","DxrVuMvJB24","zNDltuG","yujNBeG","DhbrCgi","zM9Yy2u","EsbJBg9Zzwq","BM93","yNzMA2y","AvLyB1i","y29UDgv4Da","Aw50zwDLCIa","Ce1kBeO","C2nYAxb0","DeXUvKG","EuDnu3G","wxPswem","DenvDgW","rKLmrv9ot1q","BeHHBMrSzxi","z2v0","uMvJB25Uzwm","yMXVy2TLza","zgLZywjSzue","CufpyKe","zefxDwu","vgLTzw91Da","A3Dpwem","yNL0zuXLBMC","vK5Iz2G","x2vUzhbVAw4","uw9et04","rg9wtvq","CvzOseC","revUr3m","BwvZC2fNzv8","ihrYEsbYzwm","tw1HyNm","BMfTzq","B3nQy1e","zMLSDgvY","A3D2vhy","y3vYCMvUDeK","s3bVswW","yxHLDu8","vwLRrwq","Bgv2ue0","AgjrwuO","rLDt","uvL4tNa","uvHjtfq","DMvY","AgLNAa","DgvmB2Djre4","BuzAuw0","r3PnAwu","BwvZC2fNztO","EffPrMm","z1rPBwvVDxq","CgfNzwHPzgu","AenSB3nLrxy","zNjVBujPDhm","tg9Nsuq","tKzxCwS","Eu1HqNm","A0DzuK0","BeXQzeO","z29PBMCGyxC","BMfUuwK","ywXSB2nvBNm","AMjNDNK","q0fgzMG","mxWYFdn8nhW","C2vYDMLJzs0","qMDfz3G","twvZC2fNzuu","DMfS","sxn0t0q","tujXDg8","zvPTrve","AfLbzfy","t3bLBKv2zw4","q29Kzq","v2LUzg93","EfrbAhy","A3vbAM8","tuP3Bwi","BgLUzq","x2HHBMrSzu8","D0DSwwW","txnXwei","Bwu6ia","t01ZqNy","yuXiAxa","mdaWmdaWmda","sgvRBLa","ALbJyKK","icSG","ywrK","AwXK","B25pCgvU","u2HHCMvKv28","DhDVCMTdAge","mhWZ","q291BNq","B3jpBMXPBMu","vfHgEMq","ywPNrLu","s1DeBuy","Cg9PBNrbBMq","CMjMs1u","EvDcDxC","CLrjENy","t1rNs2y","seXhELq","B2fK","BML0AwfSAxO","zxDlyNG","AxnszwfKEq","BgTjENq","C05Rt2q","zeXAsNu","AwPlDuC","yvrcy2C","zMLN","thH5zK4","sMXcteW","CgLUz0LUDgu","qw1LANu","tuH6vMi","v0LLAfi","AxnbCNjHEq","AgTLDw0","Ahr0Chm6","y29UBMvJDgK","CNLrAu0","DMrJvfu","CfDnBKy","ze9nzu4","CwPxzKm","CMvWBgfJzq","q29UzMLN","AwXLtMfTzq","uhjPBwfYEuS","x2HHBMrSzva","ruHAwhK","BMf4y2q","Cgf5Bg9Hzfq","x2rPC2nVBM4","qK5VEwS","vxnlzNi","B1LSEMq","ww52rgu","wez3Bgm","BvfXyKS","qLvwv2y","ExbL","o2nOyxjZzxq","v2vhB3G","wKT3y04","txbMBMW","CeTtvNy","tNveDxa","zvzxuuS","zxf1ywXZ","Ae1LC3nHz2u","tNDdBfi","DgLUzYbZzxi","AxnrB1nnzxm","x2rLC3rYB3K","sg9dthm","y2XVC2uSihC","sML4yNO","ufrLEem","vMLOCMK","qKvtBe0","DwTcDKC","x2nVBM5Ly3q","ugrwBKC","CgLUz0XVC3m","Dw5KzwzPBMu","r3PfD3C","C0Xf","DKLlCxq","t0DXCgG","x2rYB3bhBg8","yNPxrK4","ChjVy2vZCW","t3DtvvO","ue9tDKm","C3jbuKW","Dg9cExrLC0W","nJm5ndC4ywvxrMv3","DK9JugG","Dg9mB3DLCKm","twHXzLK","Aw5JBhvKzxm","y29UBMvJDeu","Eg1iruG","Cfb5vNe","DvHrtM8","EgHtzNe","x2LZqNjVD3m","ChjVDg9JB2W","rwXVwem","Du5LveW","mJG1mZLPrvLMvhu","sxnuEKy","yw5Nzq","s1bvq2m","vhzQuwu","EfbUtNi","weLuvhy","zw5JB2rPBMC","suXKCu4","x2LZv29YA2u","EM1zCfO","ExP2t0W","mNWX","tw9KDwXL","ywXS","uLHVrvy","AgfUz2u","CwTND20","z2v0sxrLBq","yu9Mr1u","DLbUvfO","BwvKAwf0zwW","CMfUzg9T","v2zKt2y","Axv5Dum","uK1kCMq","BwfW","A2v5CW","AeXjs2i","y3jLyxrLq2W","rejmEem","yuvQB3i","BwHvsvG","zMvIq3G","qujNsuW","DKzhz2K","CMfNzvn5BMm","x3bPBMC","zcWGDw5RBM8","CfLUyxe","qK13B3u","vhzvz00","Aw9U","yM10y2m","C0zcyMS","ELblq1C","CeDcvKK","C3vIC3rYAw4","vNrdy0y","z1D0De4","CKn5r08","wK9dtee","rhz0EwG","BxbzDw0","x0rctMfTzq","t1PIrfy","CM5pwxq","AxmGDw5Kzwy","y2HHCKnVzgu","x29Uq2XVC2u","BMrLEa","nti2mtCWt1f4s3Dq","zMX1C2HfEha","D3f2tu8","CMvHzhDYAxq","x19LC01Vzhu","z2vjBMzVu3K","ywDLsgLKzq","CLjXqwi","C2v0y3vYC28","B3bLCNr5tMe","uLjpuG","zuDvs0e","qwvZzhK","sgHjAhK","yxbWBgLJyxq","tuHqyKW","sgj1yu8","CM92AwrLigi","qLb3D3K","DhjPBq","CM92AwrLihy","v2PqAMW","B25Uzwn0Aw4","sfnmrva","zxH0ugf5Bg8","CNnVCL92ywW","C3bSAwnL","x2LZtwLUAvC","y2f0y2G","zNvUy3rPB24","vfb3ufe","A3HKzLu","id4G","qKnWu3O","x3jLywr5q2W","CMvZDwX0","D0LUEeq","tKDFrvjst1i","q3vZDg9Trxi","uefZC2W","y3vYC29Y","CMvUDevUzha","AxnFywnR","C014BKi","tfngtvC","y29Uy2f0","y09Wzw4","yMPMEfO","EgzQvwW","wxPZD3i","DKHgrfi","AhLsB2C","v1bJCMe","tfzJqNm","ywnRx2nVzgu","quTtrNa","B3jLtMfTzxm","De9yz04","thzeAK4","tezetgy","B09zs0G","u2vYDMLJzvC","zfbyrMW","BMDuAw1LCG","A1rNseG","zg9Uzq","BwLUzW","x3DZ","zgvMAw5Luhi","DfLZufC","r2TVuwC","DhDsEwW","yMLUyxj5vhK","u3POAMi","yxnJCMLWDa","q296rui","ChrwrwS","svf2BKS","x2TLEvbHDgG","sevWqxO","zxvjuwm","zMLUza","rLn6uuW","A1fbA2K","CuLLBwW","qNjPzgDL","tuH6DKu","EhnnC3K","yw5dtxG","qM1hr0u","uw5NBfO","AMLNBeC","zNzcwMO","x194x21Zz18","qNrbEui","ihn1y2nLC3m","tg9NsurozxC","EKjtBg0","uLbfALq","x3bHDgHlzxK","sKLWzey","B3noAwq","t3jvCwW","u2TLC0q","rwHOuhy","ru5hyxO","l3DZl3yY","nxWWFdf8n3W","zvf1zgS","veD3Ave","Aw5KzxHpzG","t1P0C3a","CwHWrfe","y1D5B24","tvf5rNO","Aw1LCYbPBIa","whviEvi","q1nwuxy","vMPNEvC","EhznBhy","s1Prrhq","CgzZDue","Dg9tDhjPBMC","Ew9KCLG","C0XPC3rLBMu","t05oBve","yuzPu04","y3vYC29Yx24","Aw5N","tufmvNi","Dw50","suDuque","ywLLs0e","tNnSrKO","uLDlAgm","mtyYoda4ofnkCezLDa","DuTetva","BMnLq2XVC2u","yxnZAwDU","A2TmCxC","A25nDg8","AfHTAuS","zgvS","qLfzrxu","ExfmA3q","A1zLu3O","zxPutui","BwXzD0q","y2HnyxHdB3u","rMnMyuO","Bg9IywXty28","v3LjC2K","Dwr0D2e","A3zuA3i","x2LZsw5PDa","A0DlANe","DwDxExe","vfjjwwO","q2npCgm","ywnR","yNLeALu","sgLOBhG","CNvnsuC","DxbNCMfKzw4","nhWYFdf8m3W","r294Cg0","sNrQuee","tfrNqMO","BgvY","B3v0sw50zxi","tgvAzKe","yw51Ce1LC3m","twrKD3u","zMniBha","wMnYwei","B2zMBgLUzq","EvjLy29UBMu","C1jQwuq","BMv4DcGPigm","C2vUzf9Hy2S","AgzZvMu","CuTpr0C","Bg9NsurozxC","vwDyseu","y3vZDg9Tshq","BKHAufa","EfjoB00","y3jLyxrLrxi","CgXLyxnLiha","thrOAe8","BM5Ly3q","ihbYB3rVy28","AK1xD0K","ihrVihjLDhi","D3m6lY8","tMTPy00","C0T2rfK","wLnIvfy","vKret0m","wvHArvq","sfbsBhm","r2rHwgG","v3HStxK","CfrlEe4","DhjHBNnHy3q","qwjVCNrfCNi","x2fKzfDZtgK","A2fYyMO","BMDtBuC","x2LZtwLUAvq","CMvQzwn0","BMCGDxjSoIa","BNrLCG","tg9JAW","zM9YrwfJAa","DvvQCK0","qxn4v3K","u29oD0e","vhzJvNy","AMX1Dge","CMvJzwL2zwq","tK9MDem","B25mAw5L","wgDty2y","BLP3swy","ruLVqLO","yxfSrLq","y1jbs2W","r2juy0W","uMfSsKK","wNbvtNG","Ae9xAha","qKDMz1e","C25fqvq","x3jLy29UBMu","AwXSihvZzsa","DxvvDfO","uNrZqMy","BMvLzf9Hy2S","u1jytxK","wNf0ALu","zxjYtxnN","x29WDgLVBNm","AxnAzxjV","zfnUz0i","yujwt2y","qwzttxO","BMvY","yLLPyNO","yMznCe4","Bff3B0y","CLzQsvy","y2XVC2veqG","Cgf5Bg9Hza","q2PMsxq","qunAsK0","swTRrK0","wfrkCw4","BfDMtvm","zwr5ugm","x3nLBMrby2S","CMfTzq","ywrKt25L","x2nSzwfYugK","AMnvqvm","x2n1CNnVCKy","y0rozNy","Cg9W","suDPvNy","rxzLBNq","y2PlrKS","wwDQEg0","wNPHtu8","yKHVzwW","rLbrvKW","Dhj1y3rVCIa","uLbgBgS","A2Liuwy","t3fpzMe","B2XNDKm","B25nzxnZywC","C3rYAw5NAwy","zNjVBuj5Dgu","zw1PDa","A1rStvm","uNPyteK","Dgv4DfbHEwW","yNL0zu9MzNm","BMDLza","qw1VDw50","BMvJDa","wezzzNK","Cw9Zx18","yw1LoIa","BwvZC2fNzq","vNvdzve","BLPXDxe","A1n0yxr1C0m","Ee1Yr1C","CMvZzxrdB3u","nhWWFdv8mNW","BuPLzgi","tvHIsw0","sejqAuC","z09vswq","AwDHDg9Yt24","y3ruAw1LB3u","sLnptLa","y3jLyxrLtwu","B2npruy","ChHAqu8","CYbPBNn0yw4","AefwvK4","C1Puvfa","igfYCMf5yNu","y29UBMvJDca","ugfpvxm","t1PUqKK","BIWGAg9ZDg4","Bu93reW","vMP6uvq","Eu9vzNC","ELfdtLO","EvnrsMe","zv9ZDwnJzxm","zeDAzgK","y2vZC0HHBMq","BwvY","DLbiq2C","x2nSzwfYvgK","CMvSANi","D2TpsfC","EvHZAgS","rLPUA0y","zgrbzLm","zNDZxZeUmc4","q3jwD3C","rgHPuey","ywjVCNq","qvL6yK4","shftB0C","CwrIrfe","Dev2zw50","DhbrA1O","x3bYzwzPEa","CeL6z2e","v3PWAwS","CMvTB3zLrxy","yw1L","Dxf1DgW","mdaWma","v3DztfK","wuT0Cgu","Cg93","BgLUzw5V","yufcsLy","x3DHAxq","zNjVBuHHC2G","t1bftL9fuLi","CgLUz19VBMm","ChvZAa","sgvVDLa","t2jQzwn0","igzPzwXKoIa","y3jLyxrLuMu","C2LpAwm","v0TnyMu","CLDhDhO","yKXpz3a","ywDLrxzLBNq","CMTLCKDSB2i","twLnsvC","u2Loz0W","A3nSs3K","sxzmqLq","s2X1Cvi","rvLHCwS","uwLkAMy","BMHYvee","zKrPwwK","BezSDxnO","uNn5rNy","x21LC3nHz2u","CfHQuKq","rLroC28","rMLJsK0","BgfJy0W","C2v0u3rVCMe","D05kEvO","rKH5De8","vvDktNG","x2rPC3bHDgm","B25LCNjVCG","Efrurw52","DgfIyxnL","qvnVuuG","EefRyK4","AxjLza","ufrpue0","B1fVyK0","z2v0q3vYCMu","AhHjsKm","y2HLy2TdDxi","B3bLBKrc","wfDNEKC","zgv2AwnLx2K","A2v0ignVBNm","z1rozvi","zxzyEei","vMfhtwe","BNruCMLLC0m","igXHCMDLCIa","yMLUyxj5","AgvHzgvY","CMvWBgfJzui","rxnxzxy","z2nxrxy","zMHiBKm","ihrPBwvZ","zNvMtKO","y3vYCMvUDeu","r1vgz3u","BMrWB2LUDfq","Bg9N","r0TkCeu","D2PUsgG","sfPrDgy","sgHXrwy","q3vnvhe","A3jpChO","ChbL","qwrrDuq","s3fpCNK","C0nVDw50zxi","x2zVCM1HDeu","lcbxzwjtB2m","y29TCgXLDgu","C3rVCcbPBw0","ChjVDg90Exa","Ae9Wzw5fDMu","sfb2sfm","qwfPANG","u2TJt3q","DMvUDa","D2vI","CenqCvG","CKDbshG","C2DPza","y29UBMvJDa","AhLhBge","y0L6sNu","Bfjduwm","sxPhCLa","BuDrEeu","CgLUz1rPBwu","wujpELq","AvnODeK","uLvlAxa","yMfSrxzLBNq","zxjFCw9Zx2e","q0rxrfK","zcbLCNjVCI4","Cg9PBNrdB24","sw9VsM8","zxH0zw5ZAw8","zxjHDg9Y","Fdr8n3W5FdG","x3bYB3rVy28","DMfYCfq","C2TOsLG","Cvj1A2e","uLzLv28","Dw5RBM93BIa","zwnVBM5Ly3q","DKrqzw0","DwHYvfa","zgX1s0y","x2HHBMrSzvi","zw5XDwv1zq","DMDTwu8","t25Hvhy","uMvHzcbWyxm","zff1DwG","mhW0Fdn8nxW","z2vrDwv1zuW","qvnJBee","ANfzy0e","C0jf","ww9dD0q","CMvJB25Uzwm","B0nbveu","mtzkEKzICue","rM5QDfa","rfPHExu","DMfSDwvZ","yxjYyxLIDwy","DMvYC2LVBG","y09fquy","ExbWt04","qKnYEfy","tuvtu0fhrv8","BMv3vMvYC2K","tNjZqNe","Bg9Nsurhzw4","yMLUza","AwrI","BKj6swO","ENz5vuG","Bg5Lvxi","y29SBM8","ywDLu2HVDW","y3vYC29Yx2y","zNjVBu51Bwi","nhWWFdf8m3W","BMfXEKm","AgvKtwf4uMu","seDmCNG","sgX1v3y","wM5Mt1m","DMrtvgq","Ce5qtMW","qKD2Cu0","B1LiD3G","zxq9DxrMltG","u0HuEfu","uNvwtMW","tgLZDgvUzxi","CM5crgi","vLH4ywO","vMfXBhq","zw5JB2rLrNi","zxjFCw9Z","ysbTDxn0igi","ywnOzwqSihC","A1rOzLq","ywWGy3vYC28","s21ozLy","C2HPzNq","vuDQD0K","C3fmBuC","BwjlEhC","zMLSzw5HBwu","whHkrui","ufLMq28","DwjLyvy","zw5HyMXLvhi","u3rYyxrLz3K","CMLLC0nVDw4","Cgu6ia","uMjTshC","uLPRz2u","x29UrxjYB3i","DMvYC2LVBMm","yxzYsLa","y291BNq","DgLTzw91Da","zhzHy0W","x2XPC3rLBMu","zxjFAxnFywm","zK5cCg8","y29Kzq","CMvTB3zLq2G","yLnHD3O","mxW0Fdb8m3W","DgHHBIbSB2m","BvjHBgi","Cw50zwW","zxj2AwnL","ugnArKy","Bg96t1y","r2vACwO","ufztufq","tufyx1jfvfi","wKrKDKq","zMzMzG","BKnttKy","zg1UuLy","rLjptLrjrvi","B2XKvMvYC2K","x2rLyNvN","qwv0qxe","tNf6Cgi","BLLREwq","uMnsufq","y0zpDgO","BgX2A1i","CgfNzxnOB3C","z01Mv0K","suTrt2m","Bfb3B3i","B25dBg9Zzq","Ahr0Ca","DgfYz2v0","C2vnyui","De1HBMfNzxi","ANPQuuu","wNfpyue","yNL0zxm","CMvKDwnL","BMCGzMfPBgu","B2zMC2v0","t1bftG","q0Xpu0ve","Dg9oDw1Izxi","ufDkqw4","Aw9UvgLTzw8","rujbz0C","BxHTvwS","AePyrgq","wMzjCu8","Ef9MCM9UDgK","CM92AwrLige","BND4DuG","AurUwgu","ANL6yxu","u29Hwvq","Dg9VigXHCMC","BgPdEMW","AgvHzgvYCW","D24GCMvHC28","tfvlBuC","zfDZsuq","q0Xpu0LorW","vgfN","sxfnuLG","x3fVC0rc","ufrMvui","x29UtwvZC2e","DMLJzuLeig8","Ewf3y3u","u2vXsuq","D2fZq2XLyw4","ihrPBwvVDxq","t3HerwC","qwr1Bxa","ywr2yw5Jzq","x2n1CNnVCK0","zwn0","uxvLDwu","whzkvxq","BK1HDKS","zfDVCMTLCKC","rNzvtvm","tNfwrvq","DhbizwfKzxi","z2v0q3vYC28","mZGXmtqWC3DcCeLq","y29UBMvJDfm","CMPVDfG","Dhr3Awq","AMDbCMO","vKTczxO","sKvODuG","DgLLCKPtt04","x2rItMfTzq","D0rXy20","CgPUrue","zxrxB3jRq2G","yxbWzw5Kq2G","CNzHBa","vfj1DuC","rKPXug4","wwDqwMy","CMvZzxrfBMq","tK5dzw8","DhLwD0e","whrzv2q","rhzsq2O","swnnC0G","rhjpvK4","ywTfwvy","B2nRzxq","C3rYAw5N","B2nRzxrgywK","tKfusvzfx0u","CNP2vuu","ywXSzwqGBxu","CvPJsMS","BwLZzq","zMzmAw5L","zLPLt2u","DLLstgK","z2v0u3rVCMe","yMfSu2nVCgu","zhjbBgG","CeXACwS","sxHxqwG","BhrPCgXLihq","Axnby2TdBgu","B3zKsgS","AgfZ","zwvKzwq","uuPTy2K","Dhbvr1u","BwLUAvbYB2C","v3D3C3K","r2rXtu8","yxbWBhK","yLjtqMq","uNbKtuC","BM56CNu","DeLK","Dg9hzw5LCMe","qLDYAe8","CKrhu0W","DgvZDa","aaaaaaaaaaa","Aw13y2q","EMHmz0G","AwPns2K","ugPIC0K","tNjMvwW","x2LUAxrhBg8","DLHsr3m","zxjFywnRx20","yM9KEq","B25SAw5L","vuD3Dwm","qunUv3O","u0LVBhq","igzHAwWSig0","zxjYB3i","B0LvtM4","ywzL","zMLkA2y","u3rjsuy","wgDrA1e","DLPntva","ru9Owxi","Dgv4Dc9Qyxy","CMvZB2X2zq","zw50tgLZDgu","BeL0we0","x2LUAxq","ruPtCgW","y29UC3rYDwm","ywnOzwq","C29YDa","DgHLBG","CLLiCKe","CKfPsKK","uhLUEwm","Cgvrzvi","BgLTAxq","C2XPy2u","zeTeEgq","CxnHEgW","AhnkEeW","vgD5zMq","u1PtDM0","CgvYC2LZDgu","EfvZzuvUDG","x2n1CNnVCK4","C01UzeW","y2HnyxHuCMK","A3rWu0i","q3vZDg9Tq2W","q2XqzxO","ugj4uNq","rvPOtMi","zu9ezNe","Aw47y2HHCNm","Dxvjv1O","v0nPyNK","Ag9lBwK","DxnJDve","CgfYC2u","ChzYweO","AxnmB25N","z2v0t3DUuhi","CNjVCK1LC3m","B01cDuu","BxnNsuq","CKfXrxy","zgvSzxrLrge","x21PBMLoyxy","Evf0rNK","r2L0A3C","D0Tqu0G","t2zltgS","CwrzD3i","DMLRuwG","C2vUza","y1nkshi","tKHLyum","wvbfDxm","z2u6ia","zwTJChy","uK9hCMm","x2DLBMvYyxq","Cw9Z","EgX4CuS","vLDoC2i","DxrMofDYAxq","quXm","uMvhywq","zfHfs24","zNjHBwvuExa","C2v0","zufJAW","CKjeD28","vNPeEfi","zgvSzxrL","r1nls3y","q3rQuue","wwzjq3u","zeLbEe4","zxPhrxu","suP2Dgu","r3bvwgO","rxjYB3jdB2q","uNzyrxO","Dg9cExrLC0i","vuHcAe4","qLrpv2O","t0nzrLu","EuTNsge","BKLWv3G","vfreuee","yNLL","ywrLwxK","Afz0Cvu","BuDAswe","rgvKAwnHDgu","twXmAK0","yvvht1m","nte4ndm2BM9lqxvv","AKzcuMi","y0PcrM8","BfrPBwvVDxq","y29UDgLUDwu","zM1SENK","yMrFzgLK","qu1cEha","ueX5DLq","zNnVs1e","BffMBMC","DhjPzxm","ALrTqKy","Dxrjza","s2jZA0G","AMj4DMG","DvvxA3i","Aw9Ul2PZB24","Dg9Y","x2DLDeLUDgu","y3jLyxrLrwW","y2XLyxjtDg8","qwnZvLO","Dgv4Dc9WBge","BLDXy1i","vhjKuui","CKnLsvG","t3rUDxu","A2f5qwG","BgvUz3rO","vw5PBxbSzw0","C3rVCMu","BKLgqMC","D3nZoI8V","wuDmvfC","B25szwnLAxy","yLD1se8","DLnWrfq","CxznrKW","y3jLyxrLt3a","EwzvuNq","teLNBeC","zKvpvgO","Dfb2rwC","z25Atvi","CMvHzfvjBNq","Dw5ZAwDUzwq","C3nHz2vfDMu","mxW0Fdj8m3W","B3HOBuK","y2HLy2Tszwe","D3fPthi","DgHzyNG","Chv0","C3rHCNq","zMPVvuW","Bwf4tg9ZC0m","y2uGBM90igK","ChrVCG","ue5QteW","zfP6uK0","sfHxrei","rgHnCge","vM1lwxy","shfdzKO","C3bSAxq","vKvMvfC","BuHHrvi","CwvwEvu","wK9evxy","suHdA3e","u0jVv3G","nhWYFdf8nxW"];return To=function(){return t},To()}Object[B(582)+B(1754)](ye,B(518)+"le",{value:!0})});var $t=se((gC,cx)=>{"use strict";var ox=["nodebuffer","arraybuffer","fragments"],ax=typeof Blob<"u";ax&&ox.push("blob");cx.exports={BINARY_TYPES:ox,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:ax,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var qi=se((mC,Co)=>{"use strict";var{EMPTY_BUFFER:XE}=$t(),rd=Buffer[Symbol.species];function QE(t,e){if(t.length===0)return XE;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 rd(r.buffer,r.byteOffset,i):r}function dx(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function lx(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function eb(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function id(t){if(id.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new rd(t):ArrayBuffer.isView(t)?e=new rd(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),id.readOnly=!1),e}Co.exports={concat:QE,mask:dx,toArrayBuffer:eb,toBuffer:id,unmask:lx};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=de("bufferutil");Co.exports.mask=function(e,r,i,o,c){c<48?dx(e,r,i,o,c):t.mask(e,r,i,o,c)},Co.exports.unmask=function(e,r){e.length<32?lx(e,r):t.unmask(e,r)}}catch{}});var xx=se((wC,fx)=>{"use strict";var ux=Symbol("kDone"),sd=Symbol("kRun"),od=class{constructor(e){this[ux]=()=>{this.pending--,this[sd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[sd]()}[sd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[ux])}}};fx.exports=od});var Or=se((_C,mx)=>{"use strict";var Hi=de("zlib"),hx=qi(),tb=xx(),{kStatusCode:px}=$t(),nb=Buffer[Symbol.species],rb=Buffer.from([0,0,255,255]),Ro=Symbol("permessage-deflate"),Vt=Symbol("total-length"),kr=Symbol("callback"),bn=Symbol("buffers"),Pr=Symbol("error"),Do,ad=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,!Do){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Do=new tb(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[kr];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){Do.add(o=>{this._decompress(e,r,(c,l)=>{o(),i(c,l)})})}compress(e,r,i){Do.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"?Hi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Hi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:l}),this._inflate[Ro]=this,this._inflate[Vt]=0,this._inflate[bn]=[],this._inflate.on("error",sb),this._inflate.on("data",gx)}this._inflate[kr]=i,this._inflate.write(e),r&&this._inflate.write(rb),this._inflate.flush(()=>{let c=this._inflate[Pr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let l=hx.concat(this._inflate[bn],this._inflate[Vt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Vt]=0,this._inflate[bn]=[],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"?Hi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Hi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:l}),this._deflate[Vt]=0,this._deflate[bn]=[],this._deflate.on("data",ib)}this._deflate[kr]=i,this._deflate.write(e),this._deflate.flush(Hi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=hx.concat(this._deflate[bn],this._deflate[Vt]);r&&(c=new nb(c.buffer,c.byteOffset,c.length-4)),this._deflate[kr]=null,this._deflate[Vt]=0,this._deflate[bn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};mx.exports=ad;function ib(t){this[bn].push(t),this[Vt]+=t.length}function gx(t){if(this[Vt]+=t.length,this[Ro]._maxPayload<1||this[Vt]<=this[Ro]._maxPayload){this[bn].push(t);return}this[Pr]=new RangeError("Max payload size exceeded"),this[Pr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Pr][px]=1009,this.removeListener("data",gx),this.reset()}function sb(t){if(this[Ro]._inflate=null,this[Pr]){this[kr](this[Pr]);return}t[px]=1007,this[kr](t)}});var Nr=se((yC,ko)=>{"use strict";var{isUtf8:_x}=de("buffer"),{hasBlob:ob}=$t(),ab=[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 cb(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function cd(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 db(t){return ob&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}ko.exports={isBlob:db,isValidStatusCode:cb,isValidUTF8:cd,tokenChars:ab};if(_x)ko.exports.isValidUTF8=function(t){return t.length<24?cd(t):_x(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=de("utf-8-validate");ko.exports.isValidUTF8=function(e){return e.length<32?cd(e):t(e)}}catch{}});var xd=se((EC,Ax)=>{"use strict";var{Writable:lb}=de("stream"),yx=Or(),{BINARY_TYPES:ub,EMPTY_BUFFER:Ex,kStatusCode:fb,kWebSocket:xb}=$t(),{concat:dd,toArrayBuffer:hb,unmask:pb}=qi(),{isValidStatusCode:gb,isValidUTF8:bx}=Nr(),Po=Buffer[Symbol.species],lt=0,vx=1,Sx=2,Ix=3,ld=4,ud=5,Oo=6,fd=class extends lb{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||ub[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[xb]=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=lt}_write(e,r,i){if(this._opcode===8&&this._state==lt)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 Po(i.buffer,i.byteOffset+e,i.length-e),new Po(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 Po(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 lt:this.getInfo(e);break;case vx:this.getPayloadLength16(e);break;case Sx:this.getPayloadLength64(e);break;case Ix:this.getMask();break;case ld:this.getData(e);break;case ud:case Oo: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[yx.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=vx:this._payloadLength===127?this._state=Sx: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=Ix:this._state=ld}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=ld}getData(e){let r=Ex;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&&pb(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=ud,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[yx.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===lt&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=lt;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=dd(i,r):this._binaryType==="arraybuffer"?o=hb(dd(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=lt):(this._state=Oo,setImmediate(()=>{this.emit("message",o,!0),this._state=lt,this.startLoop(e)}))}else{let o=dd(i,r);if(!this._skipUTF8Validation&&!bx(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===ud||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=lt):(this._state=Oo,setImmediate(()=>{this.emit("message",o,!1),this._state=lt,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,Ex),this.end();else{let i=e.readUInt16BE(0);if(!gb(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Po(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!bx(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=lt;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=lt):(this._state=Oo,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=lt,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[fb]=o,l}};Ax.exports=fd});var gd=se((vC,Dx)=>{"use strict";var{Duplex:bC}=de("stream"),{randomFillSync:mb}=de("crypto"),Tx=Or(),{EMPTY_BUFFER:wb,kWebSocket:_b,NOOP:yb}=$t(),{isBlob:Lr,isValidStatusCode:Eb}=Nr(),{mask:Cx,toBuffer:qn}=qi(),ut=Symbol("kByteLength"),bb=Buffer.alloc(4),No=8*1024,Hn,Mr=No,vt=0,vb=1,Sb=2,hd=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=yb,this[_b]=void 0}static frame(e,r){let i,o=!1,c=2,l=!1;r.mask&&(i=r.maskBuffer||bb,r.generateMask?r.generateMask(i):(Mr===No&&(Hn===void 0&&(Hn=Buffer.alloc(No)),mb(Hn,0,No),Mr=0),i[0]=Hn[Mr++],i[1]=Hn[Mr++],i[2]=Hn[Mr++],i[3]=Hn[Mr++]),l=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||l)&&r[ut]!==void 0?u=r[ut]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!l);let x=u;u>=65536?(c+=8,x=127):u>125&&(c+=2,x=126);let p=Buffer.allocUnsafe(o?u+c:c);return p[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(p[0]|=64),p[1]=x,x===126?p.writeUInt16BE(u,2):x===127&&(p[2]=p[3]=0,p.writeUIntBE(u,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?(Cx(e,i,p,c,u),[p]):(Cx(e,i,e,0,u),[p,e])):[p,e]}close(e,r,i,o){let c;if(e===void 0)c=wb;else{if(typeof e!="number"||!Eb(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 u=Buffer.byteLength(r);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof r=="string"?c.write(r,2):c.set(r,2)}}let l={[ut]: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):Lr(e)?(o=e.size,c=!1):(e=qn(e),o=e.length,c=qn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ut]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Lr(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):Lr(e)?(o=e.size,c=!1):(e=qn(e),o=e.length,c=qn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ut]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Lr(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[Tx.extensionName],c=r.binary?2:1,l=r.compress,u,x;typeof e=="string"?(u=Buffer.byteLength(e),x=!1):Lr(e)?(u=e.size,x=!1):(e=qn(e),u=e.length,x=qn.readOnly),this._firstFragment?(this._firstFragment=!1,l&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(l=u>=o._threshold),this._compress=l):(l=!1,c=0),r.fin&&(this._firstFragment=!0);let p={[ut]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:x,rsv1:l};Lr(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[ut],this._state=Sb,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(pd,this,u,o);return}this._bufferedBytes-=i[ut];let l=qn(c);r?this.dispatch(l,r,i,o):(this._state=vt,this.sendFrame(t.frame(l,i),o),this.dequeue())}).catch(c=>{process.nextTick(Ib,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Tx.extensionName];this._bufferedBytes+=i[ut],this._state=vb,c.compress(e,i.fin,(l,u)=>{if(this._socket.destroyed){let x=new Error("The socket was closed while data was being compressed");pd(this,x,o);return}this._bufferedBytes-=i[ut],this._state=vt,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===vt&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][ut],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][ut],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)}};Dx.exports=hd;function pd(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 Ib(t,e,r){pd(t,e,r),t.onerror(e)}});var zx=se((SC,Bx)=>{"use strict";var{kForOnEventAttribute:ji,kListener:md}=$t(),Rx=Symbol("kCode"),kx=Symbol("kData"),Px=Symbol("kError"),Ox=Symbol("kMessage"),Nx=Symbol("kReason"),Br=Symbol("kTarget"),Lx=Symbol("kType"),Mx=Symbol("kWasClean"),Zt=class{constructor(e){this[Br]=null,this[Lx]=e}get target(){return this[Br]}get type(){return this[Lx]}};Object.defineProperty(Zt.prototype,"target",{enumerable:!0});Object.defineProperty(Zt.prototype,"type",{enumerable:!0});var jn=class extends Zt{constructor(e,r={}){super(e),this[Rx]=r.code===void 0?0:r.code,this[Nx]=r.reason===void 0?"":r.reason,this[Mx]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Rx]}get reason(){return this[Nx]}get wasClean(){return this[Mx]}};Object.defineProperty(jn.prototype,"code",{enumerable:!0});Object.defineProperty(jn.prototype,"reason",{enumerable:!0});Object.defineProperty(jn.prototype,"wasClean",{enumerable:!0});var zr=class extends Zt{constructor(e,r={}){super(e),this[Px]=r.error===void 0?null:r.error,this[Ox]=r.message===void 0?"":r.message}get error(){return this[Px]}get message(){return this[Ox]}};Object.defineProperty(zr.prototype,"error",{enumerable:!0});Object.defineProperty(zr.prototype,"message",{enumerable:!0});var Wi=class extends Zt{constructor(e,r={}){super(e),this[kx]=r.data===void 0?null:r.data}get data(){return this[kx]}};Object.defineProperty(Wi.prototype,"data",{enumerable:!0});var Ab={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[ji]&&o[md]===e&&!o[ji])return;let i;if(t==="message")i=function(c,l){let u=new Wi("message",{data:l?c:c.toString()});u[Br]=this,Lo(e,this,u)};else if(t==="close")i=function(c,l){let u=new jn("close",{code:c,reason:l.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Br]=this,Lo(e,this,u)};else if(t==="error")i=function(c){let l=new zr("error",{error:c,message:c.message});l[Br]=this,Lo(e,this,l)};else if(t==="open")i=function(){let c=new Zt("open");c[Br]=this,Lo(e,this,c)};else return;i[ji]=!!r[ji],i[md]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[md]===e&&!r[ji]){this.removeListener(t,r);break}}};Bx.exports={CloseEvent:jn,ErrorEvent:zr,Event:Zt,EventTarget:Ab,MessageEvent:Wi};function Lo(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Mo=se((IC,Fx)=>{"use strict";var{tokenChars:Ki}=Nr();function zt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function Tb(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,l,u,x=-1,p=-1,w=-1,_=0;for(;_<t.length;_++)if(p=t.charCodeAt(_),l===void 0)if(w===-1&&Ki[p]===1)x===-1&&(x=_);else if(_!==0&&(p===32||p===9))w===-1&&x!==-1&&(w=_);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);w===-1&&(w=_);let E=t.slice(x,w);p===44?(zt(e,E,r),r=Object.create(null)):l=E,x=w=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);else if(u===void 0)if(w===-1&&Ki[p]===1)x===-1&&(x=_);else if(p===32||p===9)w===-1&&x!==-1&&(w=_);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);w===-1&&(w=_),zt(r,t.slice(x,w),!0),p===44&&(zt(e,l,r),r=Object.create(null),l=void 0),x=w=-1}else if(p===61&&x!==-1&&w===-1)u=t.slice(x,_),x=w=-1;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(o){if(Ki[p]!==1)throw new SyntaxError(`Unexpected character at index ${_}`);x===-1?x=_:i||(i=!0),o=!1}else if(c)if(Ki[p]===1)x===-1&&(x=_);else if(p===34&&x!==-1)c=!1,w=_;else if(p===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(p===34&&t.charCodeAt(_-1)===61)c=!0;else if(w===-1&&Ki[p]===1)x===-1&&(x=_);else if(x!==-1&&(p===32||p===9))w===-1&&(w=_);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);w===-1&&(w=_);let E=t.slice(x,w);i&&(E=E.replace(/\\/g,""),i=!1),zt(r,u,E),p===44&&(zt(e,l,r),r=Object.create(null),l=void 0),u=void 0,x=w=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);if(x===-1||c||p===32||p===9)throw new SyntaxError("Unexpected end of input");w===-1&&(w=_);let S=t.slice(x,w);return l===void 0?zt(e,S,r):(u===void 0?zt(r,S,!0):i?zt(r,u,S.replace(/\\/g,"")):zt(r,u,S),zt(e,l,r)),e}function Cb(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(", ")}Fx.exports={format:Cb,parse:Tb}});var Uo=se((CC,Jx)=>{"use strict";var Db=de("events"),Rb=de("https"),kb=de("http"),qx=de("net"),Pb=de("tls"),{randomBytes:Ob,createHash:Nb}=de("crypto"),{Duplex:AC,Readable:TC}=de("stream"),{URL:wd}=de("url"),vn=Or(),Lb=xd(),Mb=gd(),{isBlob:Bb}=Nr(),{BINARY_TYPES:Ux,CLOSE_TIMEOUT:zb,EMPTY_BUFFER:Bo,GUID:Fb,kForOnEventAttribute:_d,kListener:Ub,kStatusCode:Gb,kWebSocket:Fe,NOOP:Hx}=$t(),{EventTarget:{addEventListener:qb,removeEventListener:Hb}}=zx(),{format:jb,parse:Wb}=Mo(),{toBuffer:Kb}=qi(),jx=Symbol("kAborted"),yd=[8,13],Yt=["CONNECTING","OPEN","CLOSING","CLOSED"],$b=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,pe=class t extends Db{constructor(e,r,i){super(),this._binaryType=Ux[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Bo,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]),Wx(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Ux.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 Lb({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new Mb(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",Yb),o.on("drain",Jb),o.on("error",Xb),o.on("message",Qb),o.on("ping",ev),o.on("pong",tv),c.onerror=nv,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Vx),e.on("data",Fo),e.on("end",Zx),e.on("error",Yx),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){it(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())}),$x(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){Ed(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Bo,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){Ed(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Bo,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){Ed(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||Bo,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){it(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:Yt.indexOf("CONNECTING")});Object.defineProperty(pe.prototype,"CONNECTING",{enumerable:!0,value:Yt.indexOf("CONNECTING")});Object.defineProperty(pe,"OPEN",{enumerable:!0,value:Yt.indexOf("OPEN")});Object.defineProperty(pe.prototype,"OPEN",{enumerable:!0,value:Yt.indexOf("OPEN")});Object.defineProperty(pe,"CLOSING",{enumerable:!0,value:Yt.indexOf("CLOSING")});Object.defineProperty(pe.prototype,"CLOSING",{enumerable:!0,value:Yt.indexOf("CLOSING")});Object.defineProperty(pe,"CLOSED",{enumerable:!0,value:Yt.indexOf("CLOSED")});Object.defineProperty(pe.prototype,"CLOSED",{enumerable:!0,value:Yt.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[_d])return e[Ub];return null},set(e){for(let r of this.listeners(t))if(r[_d]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[_d]:!0})}})});pe.prototype.addEventListener=qb;pe.prototype.removeEventListener=Hb;Jx.exports=pe;function Wx(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:zb,protocolVersion:yd[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,!yd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${yd.join(", ")})`);let c;if(e instanceof wd)c=e;else try{c=new wd(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:",u=c.protocol==="ws+unix:",x;if(c.protocol!=="ws:"&&!l&&!u?x=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?x="The URL's pathname is empty":c.hash&&(x="The URL contains a fragment identifier"),x){let A=new SyntaxError(x);if(t._redirects===0)throw A;zo(t,A);return}let p=l?443:80,w=Ob(16).toString("base64"),_=l?Rb.request:kb.request,S=new Set,E;if(o.createConnection=o.createConnection||(l?Zb:Vb),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&&(E=new vn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=jb({[vn.extensionName]:E.offer()})),r.length){for(let A of r){if(typeof A!="string"||!$b.test(A)||S.has(A))throw new SyntaxError("An invalid or duplicated subprotocol was specified");S.add(A)}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}`),u){let A=o.path.split(":");o.socketPath=A[0],o.path=A[1]}let b;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=l,t._originalHostOrSocketPath=u?o.socketPath:c.host;let A=i&&i.headers;if(i={...i,headers:{}},A)for(let[I,C]of Object.entries(A))i.headers[I.toLowerCase()]=C}else if(t.listenerCount("redirect")===0){let A=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!A||t._originalSecure&&!l)&&(delete o.headers.authorization,delete o.headers.cookie,A||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),b=t._req=_(o),t._redirects&&t.emit("redirect",t.url,b)}else b=t._req=_(o);o.timeout&&b.on("timeout",()=>{it(t,b,"Opening handshake has timed out")}),b.on("error",A=>{b===null||b[jx]||(b=t._req=null,zo(t,A))}),b.on("response",A=>{let I=A.headers.location,C=A.statusCode;if(I&&o.followRedirects&&C>=300&&C<400){if(++t._redirects>o.maxRedirects){it(t,b,"Maximum redirects exceeded");return}b.abort();let O;try{O=new wd(I,e)}catch{let D=new SyntaxError(`Invalid URL: ${I}`);zo(t,D);return}Wx(t,O,r,i)}else t.emit("unexpected-response",b,A)||it(t,b,`Unexpected server response: ${A.statusCode}`)}),b.on("upgrade",(A,I,C)=>{if(t.emit("upgrade",A),t.readyState!==pe.CONNECTING)return;b=t._req=null;let O=A.headers.upgrade;if(O===void 0||O.toLowerCase()!=="websocket"){it(t,I,"Invalid Upgrade header");return}let y=Nb("sha1").update(w+Fb).digest("base64");if(A.headers["sec-websocket-accept"]!==y){it(t,I,"Invalid Sec-WebSocket-Accept header");return}let D=A.headers["sec-websocket-protocol"],R;if(D!==void 0?S.size?S.has(D)||(R="Server sent an invalid subprotocol"):R="Server sent a subprotocol but none was requested":S.size&&(R="Server sent no subprotocol"),R){it(t,I,R);return}D&&(t._protocol=D);let M=A.headers["sec-websocket-extensions"];if(M!==void 0){if(!E){it(t,I,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let z;try{z=Wb(M)}catch{it(t,I,"Invalid Sec-WebSocket-Extensions header");return}let $=Object.keys(z);if($.length!==1||$[0]!==vn.extensionName){it(t,I,"Server indicated an extension that was not requested");return}try{E.accept(z[vn.extensionName])}catch{it(t,I,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[vn.extensionName]=E}t.setSocket(I,C,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(b,t):b.end()}function zo(t,e){t._readyState=pe.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Vb(t){return t.path=t.socketPath,qx.connect(t)}function Zb(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=qx.isIP(t.host)?"":t.host),Pb.connect(t)}function it(t,e,r){t._readyState=pe.CLOSING;let i=new Error(r);Error.captureStackTrace(i,it),e.setHeader?(e[jx]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(zo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Ed(t,e,r){if(e){let i=Bb(e)?e.size:Kb(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Yt[t.readyState]})`);process.nextTick(r,i)}}function Yb(t,e){let r=this[Fe];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Fe]!==void 0&&(r._socket.removeListener("data",Fo),process.nextTick(Kx,r._socket),t===1005?r.close():r.close(t,e))}function Jb(){let t=this[Fe];t.isPaused||t._socket.resume()}function Xb(t){let e=this[Fe];e._socket[Fe]!==void 0&&(e._socket.removeListener("data",Fo),process.nextTick(Kx,e._socket),e.close(t[Gb])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Gx(){this[Fe].emitClose()}function Qb(t,e){this[Fe].emit("message",t,e)}function ev(t){let e=this[Fe];e._autoPong&&e.pong(t,!this._isServer,Hx),e.emit("ping",t)}function tv(t){this[Fe].emit("pong",t)}function Kx(t){t.resume()}function nv(t){let e=this[Fe];e.readyState!==pe.CLOSED&&(e.readyState===pe.OPEN&&(e._readyState=pe.CLOSING,$x(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function $x(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Vx(){let t=this[Fe];if(this.removeListener("close",Vx),this.removeListener("data",Fo),this.removeListener("end",Zx),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",Gx),t._receiver.on("finish",Gx))}function Fo(t){this[Fe]._receiver.write(t)||this.pause()}function Zx(){let t=this[Fe];t._readyState=pe.CLOSING,t._receiver.end(),this.end()}function Yx(){let t=this[Fe];this.removeListener("error",Yx),this.on("error",Hx),t&&(t._readyState=pe.CLOSING,this.destroy())}});var th=se((RC,eh)=>{"use strict";var DC=Uo(),{Duplex:rv}=de("stream");function Xx(t){t.emit("close")}function iv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Qx(t){this.removeListener("error",Qx),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function sv(t,e){let r=!0,i=new rv({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,l){let u=!l&&i._readableState.objectMode?c.toString():c;i.push(u)||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(Xx,i);return}let l=!1;t.once("error",function(x){l=!0,c(x)}),t.once("close",function(){l||c(o),process.nextTick(Xx,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",iv),i.on("error",Qx),i}eh.exports=sv});var bd=se((kC,nh)=>{"use strict";var{tokenChars:ov}=Nr();function av(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&&ov[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 u=t.slice(r,i);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);e.add(u),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}nh.exports={parse:av}});var dh=se((OC,ch)=>{"use strict";var cv=de("events"),Go=de("http"),{Duplex:PC}=de("stream"),{createHash:dv}=de("crypto"),rh=Mo(),Wn=Or(),lv=bd(),uv=Uo(),{CLOSE_TIMEOUT:fv,GUID:xv,kWebSocket:hv}=$t(),pv=/^[+/0-9A-Za-z]{22}==$/,ih=0,sh=1,ah=2,vd=class extends cv{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:fv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:uv,...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=Go.createServer((i,o)=>{let c=Go.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=gv(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=ih}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===ah){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick($i,this);return}if(e&&this.once("close",e),this._state!==sh)if(this._state=sh,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($i,this):process.nextTick($i,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{$i(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",oh);let c=e.headers["sec-websocket-key"],l=e.headers.upgrade,u=+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||!pv.test(c)){Kn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){Kn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Vi(r,400);return}let x=e.headers["sec-websocket-protocol"],p=new Set;if(x!==void 0)try{p=lv.parse(x)}catch{Kn(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let w=e.headers["sec-websocket-extensions"],_={};if(this.options.perMessageDeflate&&w!==void 0){let S=new Wn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let E=rh.parse(w);E[Wn.extensionName]&&(S.accept(E[Wn.extensionName]),_[Wn.extensionName]=S)}catch{Kn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let S={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(S,(E,b,A,I)=>{if(!E)return Vi(r,b||401,A,I);this.completeUpgrade(_,c,p,e,r,i,o)});return}if(!this.options.verifyClient(S))return Vi(r,401)}this.completeUpgrade(_,c,p,e,r,i,o)}completeUpgrade(e,r,i,o,c,l,u){if(!c.readable||!c.writable)return c.destroy();if(c[hv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>ih)return Vi(c,503);let p=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${dv("sha1").update(r+xv).digest("base64")}`],w=new this.options.WebSocket(null,void 0,this.options);if(i.size){let _=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;_&&(p.push(`Sec-WebSocket-Protocol: ${_}`),w._protocol=_)}if(e[Wn.extensionName]){let _=e[Wn.extensionName].params,S=rh.format({[Wn.extensionName]:[_]});p.push(`Sec-WebSocket-Extensions: ${S}`),w._extensions=e}this.emit("headers",p,o),c.write(p.concat(`\r
15
15
  `).join(`\r
16
- `)),c.removeListener("error",Yh),_.setSocket(c,l,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(_),_.on("close",()=>{this.clients.delete(_),this._shouldEmitClose&&!this.clients.size&&process.nextTick(ji,this)})),u(_,o)}};ex.exports=yd;function av(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 ji(t){t._state=Qh,t.emit("close")}function Yh(){this.destroy()}function Hi(t,e,r,i){r=r||zo.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} ${zo.STATUS_CODES[e]}\r
16
+ `)),c.removeListener("error",oh),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($i,this)})),u(w,o)}};ch.exports=vd;function gv(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 $i(t){t._state=ah,t.emit("close")}function oh(){this.destroy()}function Vi(t,e,r,i){r=r||Go.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} ${Go.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 Hn(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let l=new Error(o);Error.captureStackTrace(l,Hn),t.emit("wsClientError",l,r,e)}else Hi(r,i,o,c)}});import{existsSync as Pv,openSync as kv}from"node:fs";import{mkdir as Ov}from"node:fs/promises";import{dirname as Nv}from"node:path";import{fileURLToPath as Lv}from"node:url";function Bv(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Sd(t=X()){return Pv(t.libEntry)?t.libEntry:Lv(new URL("../index.ts",import.meta.url))}async function px(t={}){let e=t.paths??X(),r=t.entryOverride??Sd(e),i=Bv(e,process.env.COZE_BRIDGE_LOG_MODE);await Ov(Nv(i),{recursive:!0});let o=kv(i,"a"),l=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=at(process.execPath,l,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[$i]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return Mv.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var Mv,$i,jo=$e(()=>{"use strict";wn();te();Pe();Mv=U("spawn-daemon"),$i="COZE_BRIDGE_DAEMON"});import{spawn as A1}from"node:child_process";import{mkdir as T1,unlink as C1,writeFile as R1}from"node:fs/promises";import{dirname as D1,join as P1}from"node:path";function Fr(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function k1(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Fr(r)}</key>
21
- <string>${Fr(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 Vi(r,i,o,c)}});import{existsSync as qv,openSync as Hv}from"node:fs";import{mkdir as jv}from"node:fs/promises";import{dirname as Wv}from"node:path";import{fileURLToPath as Kv}from"node:url";function Vv(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Cd(t=J()){return qv(t.libEntry)?t.libEntry:Kv(new URL("../index.ts",import.meta.url))}async function bh(t={}){let e=t.paths??J(),r=t.entryOverride??Cd(e),i=Vv(e,process.env.COZE_BRIDGE_LOG_MODE);await jv(Wv(i),{recursive:!0});let o=Hv(i,"a"),l=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=dt(process.execPath,l,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[Ji]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return $v.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var $v,Ji,Ko=Ve(()=>{"use strict";yn();ne();ke();$v=G("spawn-daemon"),Ji="COZE_BRIDGE_DAEMON"});import{spawn as q1}from"node:child_process";import{mkdir as H1,unlink as j1,writeFile as W1}from"node:fs/promises";import{dirname as K1,join as $1}from"node:path";function qr(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function V1(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${qr(r)}</key>
21
+ <string>${qr(i)}</string>`).join(`
22
22
  `);return e?`
23
23
  <key>EnvironmentVariables</key>
24
24
  <dict>
25
25
  ${e}
26
- </dict>`:""}function O1(t,e){return new Promise((r,i)=>{let o=A1(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,Pd,Ox=$e(()=>{"use strict";te();zr=U("supervisor.launchd"),Ji="ai.coze.bridge",Zo=O1,Pd={platform:"darwin",renderConfig(t){return`<?xml version="1.0" encoding="UTF-8"?>
26
+ </dict>`:""}function Z1(t,e){return new Promise((r,i)=>{let o=q1(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 Gr,Qi,Qo,Bd,Gh=Ve(()=>{"use strict";ne();Gr=G("supervisor.launchd"),Qi="ai.coze.bridge",Qo=Z1,Bd={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>${Ji}</string>
31
+ <string>${Qi}</string>
32
32
  <key>ProgramArguments</key>
33
33
  <array>
34
- <string>${Fr(t.nodeBin)}</string>
35
- <string>${Fr(t.entry)}</string>
34
+ <string>${qr(t.nodeBin)}</string>
35
+ <string>${qr(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>${Fr(t.logFile)}</string>
45
+ <string>${qr(t.logFile)}</string>
46
46
  <key>StandardErrorPath</key>
47
- <string>${Fr(t.logFile)}</string>${k1(t.env)}
47
+ <string>${qr(t.logFile)}</string>${V1(t.env)}
48
48
  </dict>
49
49
  </plist>
50
- `},configPath(t){return P1(t.homeDir,"Library","LaunchAgents",`${Ji}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await T1(D1(i),{recursive:!0}),await R1(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 C1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),zr.info("launchd job removed",{plistPath:e})}}});import{spawn as N1}from"node:child_process";import{mkdir as L1,unlink as M1,writeFile as B1}from"node:fs/promises";import{dirname as z1,join as Nx}from"node:path";function Yo(t,e){return t.isRoot?e:["--user",...e]}function U1(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=N1(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 Xo,Ur,F1,kd,Lx=$e(()=>{"use strict";te();Xo=U("supervisor.systemd"),Ur="coze-bridge.service",F1="/etc/systemd/system";kd={platform:"linux",renderConfig(t){let e=t.isRoot?"multi-user.target":"default.target";return`[Unit]
50
+ `},configPath(t){return $1(t.homeDir,"Library","LaunchAgents",`${Qi}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await H1(K1(i),{recursive:!0}),await W1(i,this.renderConfig(t),"utf8"),Gr.info("plist written",{plistPath:i,activate:r}),!r)return;await Qo("launchctl",["unload","-w",i]).catch(c=>Gr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await Qo("launchctl",["load","-w",i]),Gr.info("launchd job loaded",{label:Qi});let o=process.getuid?.()??0;await Qo("launchctl",["kickstart","-k",`gui/${o}/${Qi}`]),Gr.info("launchd job kickstarted",{label:Qi,uid:o})},async uninstall(t){let e=this.configPath(t);await Qo("launchctl",["unload","-w",e]).catch(r=>Gr.warn("launchctl unload failed (ignored)",{err:String(r)})),await j1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),Gr.info("launchd job removed",{plistPath:e})}}});import{spawn as Y1}from"node:child_process";import{mkdir as J1,unlink as X1,writeFile as Q1}from"node:fs/promises";import{dirname as eS,join as qh}from"node:path";function ta(t,e){return t.isRoot?e:["--user",...e]}function nS(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
+ `):""}function na(t,e){return new Promise((r,i)=>{let o=Y1(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 ea,Hr,tS,zd,Hh=Ve(()=>{"use strict";ne();ea=G("supervisor.systemd"),Hr="coze-bridge.service",tS="/etc/systemd/system";zd={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
- ${U1(t.env)}
62
+ ${nS(t.env)}
63
63
  [Install]
64
64
  WantedBy=${e}
65
- `},configPath(t){return t.isRoot?Nx(F1,Ur):Nx(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 L1(z1(i),{recursive:!0}),await B1(i,this.renderConfig(t),"utf8"),Xo.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await Qo("systemctl",Yo(t,["daemon-reload"])),await Qo("systemctl",Yo(t,r?["enable","--now",Ur]:["enable",Ur])),Xo.info("systemd unit enabled",{unitName:Ur,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await Qo("systemctl",Yo(t,["disable","--now",Ur])).catch(r=>Xo.warn("systemctl disable failed (ignored)",{err:String(r)})),await M1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await Qo("systemctl",Yo(t,["daemon-reload"])).catch(()=>{}),Xo.info("systemd unit removed",{unitPath:e})}}});import{spawn as G1}from"node:child_process";import{join as q1}from"node:path";function Mx(t,e){return new Promise((r,i)=>{let o=G1(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,Nd,Bx=$e(()=>{"use strict";te();Od=U("supervisor.taskscheduler"),ea="CozeBridge",Nd={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
65
+ `},configPath(t){return t.isRoot?qh(tS,Hr):qh(t.homeDir,".config","systemd","user",Hr)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await J1(eS(i),{recursive:!0}),await Q1(i,this.renderConfig(t),"utf8"),ea.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await na("systemctl",ta(t,["daemon-reload"])),await na("systemctl",ta(t,r?["enable","--now",Hr]:["enable",Hr])),ea.info("systemd unit enabled",{unitName:Hr,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await na("systemctl",ta(t,["disable","--now",Hr])).catch(r=>ea.warn("systemctl disable failed (ignored)",{err:String(r)})),await X1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await na("systemctl",ta(t,["daemon-reload"])).catch(()=>{}),ea.info("systemd unit removed",{unitPath:e})}}});import{spawn as rS}from"node:child_process";import{join as iS}from"node:path";function jh(t,e){return new Promise((r,i)=>{let o=rS(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 Fd,ra,Ud,Wh=Ve(()=>{"use strict";ne();Fd=G("supervisor.taskscheduler"),ra="CozeBridge",Ud={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,45 @@ WantedBy=${e}
86
86
  </Exec>
87
87
  </Actions>
88
88
  </Task>
89
- `},configPath(t){return q1(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 Mx("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 Mx("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 zx={};xa(zx,{buildContext:()=>V1,getSupervisor:()=>W1,launchdSupervisor:()=>Pd,systemdSupervisor:()=>kd,taskSchedulerSupervisor:()=>Nd});import{homedir as j1,userInfo as H1}from"node:os";function W1(t=process.platform){switch(t){case"darwin":return Pd;case"linux":return kd;case"win32":return Nd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function $1(){let t={};for(let e of K1){let r=process.env[e];r&&(t[e]=r)}return t}function V1(){let t=X();return{nodeBin:process.execPath,entry:Sd(t),logFile:t.logFile,homeDir:j1(),userName:H1().username,isRoot:process.getuid?.()===0,env:$1()}}var K1,Fx=$e(()=>{"use strict";Pe();jo();Ox();Lx();Bx();K1=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});te();en();var fl=U("acp-installer-warmup"),ug=["claude-code","codex"];async function hl(t={}){let e=t.ensure??Qn,i=(await Promise.allSettled(ug.map(async o=>{let c=await e(o);fl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&fl.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();te();import{readdir as vg}from"node:fs/promises";import{mkdir as _l,writeFile as yl}from"node:fs/promises";import{join as ba}from"node:path";var Eg={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function nr(t,e,r){await _l(t,{recursive:!0});let i=Eg[e],o=ba(t,i);return await yl(o,r??"","utf8"),o}async function bl(t,e){let r=ba(t,".claude");await _l(r,{recursive:!0});let i=ba(r,"settings.local.json"),o={permissions:{defaultMode:"bypassPermissions"}};e==="cloud"&&(o.autoCompactWindow=15e4);let c=JSON.stringify(o,null,2);return await yl(i,c,"utf8"),i}var Ye=U("agent-detail-sync"),Sg=6e4,Ig=5*6e4,os=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await vg(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(l){Ye.warn("detail sync failed for agent, skipping",{agentId:o,err:String(l)})}}})),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(u){Ye.warn("detail RPC failed, using local data",{agentId:e,err:String(u)});let h=this.retryQueue.get(e),p=h?Math.min(h.currentDelay*2,Ig):Sg;this.retryQueue.set(e,{dueAt:Date.now()+p,currentDelay:p});return}if(o.agentId&&o.agentId!==e){Ye.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&&Ye.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Ye.debug("detail sync: no diff",{agentId:e});return}await Ze(i,this.opts.paths),Ye.info("detail sync: config updated",{agentId:e,identityChanged:l,agentName:i.agentName}),l&&(await nr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var zf=St(eu(),1);import{lstat as Mc,mkdir as Bc,readFile as Nf,readdir as Yw,rm as Qw,stat as e_,writeFile as zc}from"node:fs/promises";import{dirname as t_,join as Pt,normalize as n_,relative as Gc,resolve as Fc,sep as Lf}from"node:path";import{Readable as Mf}from"node:stream";import{pipeline as Bf}from"node:stream/promises";import $g from"events";import Xe from"fs";import{EventEmitter as yc}from"node:events";import Lu from"node:stream";import{StringDecoder as Vg}from"node:string_decoder";import zu from"node:path";import xr from"node:fs";import{dirname as am,parse as cm}from"path";import{EventEmitter as gm}from"events";import tc from"assert";import{Buffer as Ln}from"buffer";import*as su from"zlib";import mm from"zlib";import{posix as ar}from"node:path";import{basename as Hm}from"node:path";import zs from"fs";import Ct from"fs";import fu from"path";import{win32 as tw}from"node:path";import _u from"path";import Qu from"node:fs";import ww from"node:assert";import{randomBytes as ef}from"node:crypto";import ne from"node:fs";import Oe from"node:path";import tf from"fs";import $s from"node:fs";import gi from"node:path";import nt from"node:fs";import Iw from"node:fs/promises";import Gs from"node:path";import{join as hf}from"node:path";import et from"node:fs";import gf from"node:path";var Wg=Object.defineProperty,Kg=(t,e)=>{for(var r in e)Wg(t,r,{get:e[r],enumerable:!0})},tu=typeof process=="object"&&process?process:{stdout:null,stderr:null},Jg=t=>!!t&&typeof t=="object"&&(t instanceof zn||t instanceof Lu||Zg(t)||Xg(t)),Zg=t=>!!t&&typeof t=="object"&&t instanceof yc&&typeof t.pipe=="function"&&t.pipe!==Lu.Writable.prototype.pipe,Xg=t=>!!t&&typeof t=="object"&&t instanceof yc&&typeof t.write=="function"&&typeof t.end=="function",zt=Symbol("EOF"),Ft=Symbol("maybeEmitEnd"),rn=Symbol("emittedEnd"),us=Symbol("emittingEnd"),Qr=Symbol("emittedError"),fs=Symbol("closed"),nu=Symbol("read"),hs=Symbol("flush"),ru=Symbol("flushChunk"),ft=Symbol("encoding"),or=Symbol("decoder"),Le=Symbol("flowing"),ei=Symbol("paused"),ur=Symbol("resume"),Me=Symbol("buffer"),We=Symbol("pipes"),Be=Symbol("bufferLength"),Ta=Symbol("bufferPush"),xs=Symbol("bufferShift"),je=Symbol("objectMode"),Se=Symbol("destroyed"),Ca=Symbol("error"),Ra=Symbol("emitData"),iu=Symbol("emitEnd"),Da=Symbol("emitEnd2"),It=Symbol("async"),Pa=Symbol("abort"),ps=Symbol("aborted"),ti=Symbol("signal"),An=Symbol("dataListeners"),Qe=Symbol("discarded"),ni=t=>Promise.resolve().then(t),Yg=t=>t(),Qg=t=>t==="end"||t==="finish"||t==="prefinish",em=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,tm=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Mu=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[ur](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},nm=class extends Mu{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)}},rm=t=>!!t.objectMode,im=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",zn=class extends yc{[Le]=!1;[ei]=!1;[We]=[];[Me]=[];[je];[ft];[It];[or];[zt]=!1;[rn]=!1;[us]=!1;[fs]=!1;[Qr]=null;[Be]=0;[Se]=!1;[ti];[ps]=!1;[An]=0;[Qe]=!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");rm(e)?(this[je]=!0,this[ft]=null):im(e)?(this[ft]=e.encoding,this[je]=!1):(this[je]=!1,this[ft]=null),this[It]=!!e.async,this[or]=this[ft]?new Vg(this[ft]):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[ti]=r,r.aborted?this[Pa]():r.addEventListener("abort",()=>this[Pa]()))}get bufferLength(){return this[Be]}get encoding(){return this[ft]}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[je]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[It]}set async(t){this[It]=this[It]||!!t}[Pa](){this[ps]=!0,this.emit("abort",this[ti]?.reason),this.destroy(this[ti]?.reason)}get aborted(){return this[ps]}set aborted(t){}write(t,e,r){if(this[ps])return!1;if(this[zt])throw new Error("write after end");if(this[Se])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[It]?ni:Yg;if(!this[je]&&!Buffer.isBuffer(t)){if(tm(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(em(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[je]?(this[Le]&&this[Be]!==0&&this[hs](!0),this[Le]?this.emit("data",t):this[Ta](t),this[Be]!==0&&this.emit("readable"),r&&i(r),this[Le]):t.length?(typeof t=="string"&&!(e===this[ft]&&!this[or]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[ft]&&(t=this[or].write(t)),this[Le]&&this[Be]!==0&&this[hs](!0),this[Le]?this.emit("data",t):this[Ta](t),this[Be]!==0&&this.emit("readable"),r&&i(r),this[Le]):(this[Be]!==0&&this.emit("readable"),r&&i(r),this[Le])}read(t){if(this[Se])return null;if(this[Qe]=!1,this[Be]===0||t===0||t&&t>this[Be])return this[Ft](),null;this[je]&&(t=null),this[Me].length>1&&!this[je]&&(this[Me]=[this[ft]?this[Me].join(""):Buffer.concat(this[Me],this[Be])]);let e=this[nu](t||null,this[Me][0]);return this[Ft](),e}[nu](t,e){if(this[je])this[xs]();else{let r=e;t===r.length||t===null?this[xs]():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[zt]&&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[zt]=!0,this.writable=!1,(this[Le]||!this[ei])&&this[Ft](),this}[ur](){this[Se]||(!this[An]&&!this[We].length&&(this[Qe]=!0),this[ei]=!1,this[Le]=!0,this.emit("resume"),this[Me].length?this[hs]():this[zt]?this[Ft]():this.emit("drain"))}resume(){return this[ur]()}pause(){this[Le]=!1,this[ei]=!0,this[Qe]=!1}get destroyed(){return this[Se]}get flowing(){return this[Le]}get paused(){return this[ei]}[Ta](t){this[je]?this[Be]+=1:this[Be]+=t.length,this[Me].push(t)}[xs](){return this[je]?this[Be]-=1:this[Be]-=this[Me][0].length,this[Me].shift()}[hs](t=!1){do;while(this[ru](this[xs]())&&this[Me].length);!t&&!this[Me].length&&!this[zt]&&this.emit("drain")}[ru](t){return this.emit("data",t),this[Le]}pipe(t,e){if(this[Se])return t;this[Qe]=!1;let r=this[rn];return e=e||{},t===tu.stdout||t===tu.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[We].push(e.proxyErrors?new nm(this,t,e):new Mu(this,t,e)),this[It]?ni(()=>this[ur]()):this[ur]()),t}unpipe(t){let e=this[We].find(r=>r.dest===t);e&&(this[We].length===1?(this[Le]&&this[An]===0&&(this[Le]=!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[Qe]=!1,this[An]++,!this[We].length&&!this[Le]&&this[ur]();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[Qr]){let i=e;this[It]?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[An]=this.listeners("data").length,this[An]===0&&!this[Qe]&&!this[We].length&&(this[Le]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[An]=0,!this[Qe]&&!this[We].length&&(this[Le]=!1)),e}get emittedEnd(){return this[rn]}[Ft](){!this[us]&&!this[rn]&&!this[Se]&&this[Me].length===0&&this[zt]&&(this[us]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[fs]&&this.emit("close"),this[us]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Se&&this[Se])return!1;if(t==="data")return!this[je]&&!r?!1:this[It]?(ni(()=>this[Ra](r)),!0):this[Ra](r);if(t==="end")return this[iu]();if(t==="close"){if(this[fs]=!0,!this[rn]&&!this[Se])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[Qr]=r,super.emit(Ca,r);let o=!this[ti]||this.listeners("error").length?super.emit("error",r):!1;return this[Ft](),o}else if(t==="resume"){let o=super.emit("resume");return this[Ft](),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[Ft](),i}[Ra](t){for(let r of this[We])r.dest.write(t)===!1&&this.pause();let e=this[Qe]?!1:super.emit("data",t);return this[Ft](),e}[iu](){return this[rn]?!1:(this[rn]=!0,this.readable=!1,this[It]?(ni(()=>this[Da]()),!0):this[Da]())}[Da](){if(this[or]){let e=this[or].end();if(e){for(let r of this[We])r.dest.write(e);this[Qe]||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[je]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[je]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[je])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[ft]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Se,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[Qe]=!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[zt])return e();let i,o,c=p=>{this.off("data",l),this.off("end",u),this.off(Se,h),e(),o(p)},l=p=>{this.off("error",c),this.off("end",u),this.off(Se,h),this.pause(),i({value:p,done:!!this[zt]})},u=()=>{this.off("error",c),this.off("data",l),this.off(Se,h),e(),i({done:!0,value:void 0})},h=()=>c(new Error("stream destroyed"));return new Promise((p,_)=>{o=_,i=p,this.once(Se,h),this.once("error",c),this.once("end",u),this.once("data",l)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[Qe]=!1;let t=!1,e=()=>(this.pause(),this.off(Ca,e),this.off(Se,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(Ca,e),this.once(Se,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Se])return t?this.emit("error",t):this.emit(Se),this;this[Se]=!0,this[Qe]=!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(Se),this}static get isStream(){return Jg}},sm=Xe.writev,xn=Symbol("_autoClose"),gt=Symbol("_close"),ri=Symbol("_ended"),oe=Symbol("_fd"),ka=Symbol("_finished"),jt=Symbol("_flags"),Oa=Symbol("_flush"),Qa=Symbol("_handleChunk"),ec=Symbol("_makeBuf"),xi=Symbol("_mode"),gs=Symbol("_needDrain"),gr=Symbol("_onerror"),mr=Symbol("_onopen"),Na=Symbol("_onread"),fr=Symbol("_onwrite"),pn=Symbol("_open"),pt=Symbol("_path"),dn=Symbol("_pos"),At=Symbol("_queue"),hr=Symbol("_read"),La=Symbol("_readSize"),qt=Symbol("_reading"),ii=Symbol("_remain"),Ma=Symbol("_size"),As=Symbol("_write"),Tn=Symbol("_writing"),Ts=Symbol("_defaultFlag"),Nn=Symbol("_errored"),bc=class extends zn{[Nn]=!1;[oe];[pt];[La];[qt]=!1;[Ma];[ii];[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[Nn]=!1,this[oe]=typeof e.fd=="number"?e.fd:void 0,this[pt]=t,this[La]=e.readSize||16*1024*1024,this[qt]=!1,this[Ma]=typeof e.size=="number"?e.size:1/0,this[ii]=this[Ma],this[xn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[oe]=="number"?this[hr]():this[pn]()}get fd(){return this[oe]}get path(){return this[pt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[pn](){Xe.open(this[pt],"r",(t,e)=>this[mr](t,e))}[mr](t,e){t?this[gr](t):(this[oe]=e,this.emit("open",e),this[hr]())}[ec](){return Buffer.allocUnsafe(Math.min(this[La],this[ii]))}[hr](){if(!this[qt]){this[qt]=!0;let t=this[ec]();if(t.length===0)return process.nextTick(()=>this[Na](null,0,t));Xe.read(this[oe],t,0,t.length,null,(e,r,i)=>this[Na](e,r,i))}}[Na](t,e,r){this[qt]=!1,t?this[gr](t):this[Qa](e,r)&&this[hr]()}[gt](){if(this[xn]&&typeof this[oe]=="number"){let t=this[oe];this[oe]=void 0,Xe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[gr](t){this[qt]=!0,this[gt](),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[gt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[oe]=="number"&&this[hr](),!1;case"error":return this[Nn]?!1:(this[Nn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},om=class extends bc{[pn](){let t=!0;try{this[mr](null,Xe.openSync(this[pt],"r")),t=!1}finally{t&&this[gt]()}}[hr](){let t=!0;try{if(!this[qt]){this[qt]=!0;do{let e=this[ec](),r=e.length===0?0:Xe.readSync(this[oe],e,0,e.length,null);if(!this[Qa](r,e))break}while(!0);this[qt]=!1}t=!1}finally{t&&this[gt]()}}[gt](){if(this[xn]&&typeof this[oe]=="number"){let t=this[oe];this[oe]=void 0,Xe.closeSync(t),this.emit("close")}}},qs=class extends $g{readable=!1;writable=!0;[Nn]=!1;[Tn]=!1;[ri]=!1;[At]=[];[gs]=!1;[pt];[xi];[xn];[oe];[Ts];[jt];[ka]=!1;[dn];constructor(t,e){e=e||{},super(e),this[pt]=t,this[oe]=typeof e.fd=="number"?e.fd:void 0,this[xi]=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[Ts]=e.flags===void 0,this[jt]=e.flags===void 0?r:e.flags,this[oe]===void 0&&this[pn]()}emit(t,...e){if(t==="error"){if(this[Nn])return!1;this[Nn]=!0}return super.emit(t,...e)}get fd(){return this[oe]}get path(){return this[pt]}[gr](t){this[gt](),this[Tn]=!0,this.emit("error",t)}[pn](){Xe.open(this[pt],this[jt],this[xi],(t,e)=>this[mr](t,e))}[mr](t,e){this[Ts]&&this[jt]==="r+"&&t&&t.code==="ENOENT"?(this[jt]="w",this[pn]()):t?this[gr](t):(this[oe]=e,this.emit("open",e),this[Tn]||this[Oa]())}end(t,e){return t&&this.write(t,e),this[ri]=!0,!this[Tn]&&!this[At].length&&typeof this[oe]=="number"&&this[fr](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[oe]===void 0||this[Tn]||this[At].length?(this[At].push(t),this[gs]=!0,!1):(this[Tn]=!0,this[As](t),!0)}[As](t){Xe.write(this[oe],t,0,t.length,this[dn],(e,r)=>this[fr](e,r))}[fr](t,e){t?this[gr](t):(this[dn]!==void 0&&typeof e=="number"&&(this[dn]+=e),this[At].length?this[Oa]():(this[Tn]=!1,this[ri]&&!this[ka]?(this[ka]=!0,this[gt](),this.emit("finish")):this[gs]&&(this[gs]=!1,this.emit("drain"))))}[Oa](){if(this[At].length===0)this[ri]&&this[fr](null,0);else if(this[At].length===1)this[As](this[At].pop());else{let t=this[At];this[At]=[],sm(this[oe],t,this[dn],(e,r)=>this[fr](e,r))}}[gt](){if(this[xn]&&typeof this[oe]=="number"){let t=this[oe];this[oe]=void 0,Xe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Bu=class extends qs{[pn](){let t;if(this[Ts]&&this[jt]==="r+")try{t=Xe.openSync(this[pt],this[jt],this[xi])}catch(e){if(e?.code==="ENOENT")return this[jt]="w",this[pn]();throw e}else t=Xe.openSync(this[pt],this[jt],this[xi]);this[mr](null,t)}[gt](){if(this[xn]&&typeof this[oe]=="number"){let t=this[oe];this[oe]=void 0,Xe.closeSync(t),this.emit("close")}}[As](t){let e=!0;try{this[fr](null,Xe.writeSync(this[oe],t,0,t.length,this[dn])),e=!1}finally{if(e)try{this[gt]()}catch{}}}},dm=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"]]),lm=t=>!!t.sync&&!!t.file,um=t=>!t.sync&&!!t.file,fm=t=>!!t.sync&&!t.file,hm=t=>!t.sync&&!t.file,xm=t=>!!t.file,pm=t=>dm.get(t)||t,Ec=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=pm(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,u)=>{Array.isArray(c)&&(l=c,c={}),typeof l=="function"&&(u=l,l=void 0),l=l?Array.from(l):[];let h=Ec(c);if(o?.(h,l),lm(h)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(h,l)}else if(um(h)){let p=e(h,l);return u?p.then(()=>u(),u):p}else if(fm(h)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(h,l)}else if(hm(h)){if(typeof u=="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}),wm=mm.constants||{ZLIB_VERNUM:4736},Dt=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},wm)),_m=Ln.concat,ou=Object.getOwnPropertyDescriptor(Ln,"concat"),ym=t=>t,Ba=ou?.writable===!0||ou?.set!==void 0?t=>{Ln.concat=t?ym:_m}:t=>{},Mn=Symbol("_superWrite"),ms=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 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 su[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new su[e](t)}catch(r){throw new ms(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 ms(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(Ln.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}[Mn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Ln.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 ms(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 ms(h,this.write)));let u;if(l)if(Array.isArray(l)&&l.length>0){let h=l[0];u=this[Mn](Ln.from(h));for(let p=1;p<l.length;p++)u=this[Mn](l[p])}else u=this[Mn](Ln.from(l));return r&&r(),u}},Fu=class extends vc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Dt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Dt.Z_FINISH,t.fullFlushFlag=Dt.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(Dt.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)}}}},bm=class extends Fu{#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)}},Em=class extends Fu{constructor(t){super(t,"Unzip")}},Uu=class extends vc{constructor(t,e){t=t||{},t.flush=t.flush||Dt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Dt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Dt.BROTLI_OPERATION_FLUSH,super(t,e)}},vm=class extends Uu{constructor(t){super(t,"BrotliCompress")}},Sm=class extends Uu{constructor(t){super(t,"BrotliDecompress")}},Gu=class extends vc{constructor(t,e){t=t||{},t.flush=t.flush||Dt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Dt.ZSTD_e_end,t.fullFlushFlag=Dt.ZSTD_e_flush,super(t,e)}},Im=class extends Gu{constructor(t){super(t,"ZstdCompress")}},Am=class extends Gu{constructor(t){super(t,"ZstdDecompress")}},Tm=(t,e)=>{if(Number.isSafeInteger(t))t<0?Rm(t,e):Cm(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Cm=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},Rm=(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]=qu(o):o===0?e[i-1]=0:(r=!0,e[i-1]=ju(o))}},Dm=t=>{let e=t[0],r=e===128?km(t.subarray(1,t.length)):e===255?Pm(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},Pm=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),l;i?l=qu(c):c===0?l=c:(i=!0,l=ju(c)),l!==0&&(r-=l*Math.pow(256,e-o-1))}return r},km=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},qu=t=>(255^t)&255,ju=t=>(255^t)+1&255,Om={};Kg(Om,{code:()=>Sc,isCode:()=>Cs,isName:()=>Nm,name:()=>js});var Cs=t=>js.has(t),Nm=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]])),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??Cn(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??Fa(t,e+136,12),this.cksum=ln(t,e+148,12),i&&this.#n(i,!0),r&&this.#n(r);let o=Cn(t,e+156,1);if(Cs(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??ln(t,e+329,8)??0,this.devmin=r?.devmin??i?.devmin??ln(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=Lm(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Rn(t,e,100,o)||this.needPax,this.needPax=un(t,e+100,8,this.mode)||this.needPax,this.needPax=un(t,e+108,8,this.uid)||this.needPax,this.needPax=un(t,e+116,8,this.gid)||this.needPax,this.needPax=un(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=Rn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Rn(t,e+265,32,this.uname)||this.needPax,this.needPax=Rn(t,e+297,32,this.gname)||this.needPax,this.needPax=un(t,e+329,8,this.devmaj)||this.needPax,this.needPax=un(t,e+337,8,this.devmin)||this.needPax,this.needPax=Rn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=Rn(t,e+345,155,c)||this.needPax:(this.needPax=Rn(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 u=e;u<e+148;u++)l+=t[u];for(let u=e+156;u<e+512;u++)l+=t[u];return this.cksum=l,un(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(Cs(e)||e==="Unsupported")this.#e=e;else if(Cs(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Lm=(t,e)=>{let r=t,i="",o,c=ar.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=ar.dirname(r),r=ar.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=ar.join(ar.basename(i),r),i=ar.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)=>Mm(ln(t,e,r)),Mm=t=>t===void 0?void 0:new Date(t*1e3),ln=(t,e,r)=>Number(t[e])&128?Dm(t.subarray(e,e+r)):zm(t,e,r),Bm=t=>isNaN(t)?void 0:t,zm=(t,e,r)=>Bm(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),Fm={12:8589934591,8:2097151},un=(t,e,r,i)=>i===void 0?!1:i>Fm[r]||i<0?(Tm(i,t.subarray(e,e+r)),!0):(Um(t,e,r,i),!1),Um=(t,e,r,i)=>t.write(Gm(i,r),e,r,"ascii"),Gm=(t,e)=>qm(Math.floor(t).toString(8),e),qm=(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:un(t,e,r,i.getTime()/1e3),jm=new Array(156).join("\0"),Rn=(t,e,r,i)=>i===void 0?!1:(t.write(i+jm,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),Bs=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 Bn({path:("PaxHeader/"+Hm(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(Wm(Km(e),r),i)}},Wm=(t,e)=>e?Object.assign({},e,t):t,Km=t=>t.replace(/\n$/,"").split(`
91
- `).reduce($m,Object.create(null)),$m=(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},Vm=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Z=Vm!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),Wu=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=Z(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?Z(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=Z(t.path)),t.linkpath&&(t.linkpath=Z(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))},Jm=1024*1024,nc=Buffer.from([31,139]),rc=Buffer.from([40,181,47,253]),Zm=Math.max(nc.length,rc.length),st=Symbol("state"),Dn=Symbol("writeEntry"),Ut=Symbol("readEntry"),Ga=Symbol("nextEntry"),au=Symbol("processEntry"),Tt=Symbol("extendedHeader"),si=Symbol("globalExtendedHeader"),sn=Symbol("meta"),cu=Symbol("emitMeta"),fe=Symbol("buffer"),Gt=Symbol("queue"),on=Symbol("ended"),qa=Symbol("emittedEnd"),Pn=Symbol("emit"),Te=Symbol("unzip"),ws=Symbol("consumeChunk"),_s=Symbol("consumeChunkSub"),ja=Symbol("consumeBody"),du=Symbol("consumeMeta"),lu=Symbol("consumeHeader"),oi=Symbol("consuming"),Ha=Symbol("bufferConcat"),ys=Symbol("maybeEnd"),cr=Symbol("writing"),an=Symbol("aborted"),bs=Symbol("onDone"),kn=Symbol("sawValidEntry"),Es=Symbol("sawNullBlock"),vs=Symbol("sawEOF"),uu=Symbol("closeStream"),Xm=()=>!0,Ei=class extends gm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Gt]=[];[fe];[Ut];[Dn];[st]="begin";[sn]="";[Tt];[si];[on]=!1;[Te];[an]=!1;[kn];[Es]=!1;[vs]=!1;[cr]=!1;[oi]=!1;[qa]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(bs,()=>{(this[st]==="begin"||this[kn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(bs,t.ondone):this.on(bs,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||Jm,this.filter=typeof t.filter=="function"?t.filter:Xm;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[uu]()),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)}[lu](t,e){this[kn]===void 0&&(this[kn]=!1);let r;try{r=new Bn(t,e,this[Tt],this[si])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Es]?(this[vs]=!0,this[st]==="begin"&&(this[st]="header"),this[Pn]("eof")):(this[Es]=!0,this[Pn]("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 Wu(r,this[Tt],this[si]);if(!this[kn])if(o.remain){let c=()=>{o.invalid||(this[kn]=!0)};o.on("end",c)}else this[kn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Pn]("ignoredEntry",o),this[st]="ignore",o.resume()):o.size>0&&(this[sn]="",o.on("data",c=>this[sn]+=c),this[st]="meta"):(this[Tt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Pn]("ignoredEntry",o),this[st]=o.remain?"ignore":"header",o.resume()):(o.remain?this[st]="body":(this[st]="header",o.end()),this[Ut]?this[Gt].push(o):(this[Gt].push(o),this[Ga]())))}}}[uu](){queueMicrotask(()=>this.emit("close"))}[au](t){let e=!0;if(!t)this[Ut]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[Ut]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Ga]()),e=!1);return e}[Ga](){do;while(this[au](this[Gt].shift()));if(this[Gt].length===0){let t=this[Ut];!t||t.flowing||t.size===t.remain?this[cr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[ja](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}[du](t,e){let r=this[Dn],i=this[ja](t,e);return!this[Dn]&&r&&this[cu](r),i}[Pn](t,e,r){this[Gt].length===0&&!this[Ut]?this.emit(t,e,r):this[Gt].push([t,e,r])}[cu](t){switch(this[Pn]("meta",this[sn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Tt]=Bs.parse(this[sn],this[Tt],!1);break;case"GlobalExtendedHeader":this[si]=Bs.parse(this[sn],this[si],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Tt]??Object.create(null);this[Tt]=e,e.path=this[sn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Tt]||Object.create(null);this[Tt]=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[fe]&&(t=Buffer.concat([this[fe],t]),this[fe]=void 0),t.length<Zm)return this[fe]=t,r?.(),!0;for(let l=0;this[Te]===void 0&&l<nc.length;l++)t[l]!==nc[l]&&(this[Te]=!1);let o=!1;if(this[Te]===!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[Te]===!1&&c)if(t.length<512)if(this[on])this.brotli=!0;else return this[fe]=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 l=this[on];this[on]=!1,this[Te]=this[Te]===void 0?new Em({}):o?new Am({}):new Sm({}),this[Te].on("data",h=>this[ws](h)),this[Te].on("error",h=>this.abort(h)),this[Te].on("end",()=>{this[on]=!0,this[ws]()}),this[cr]=!0;let u=!!this[Te][l?"end":"write"](t);return this[cr]=!1,r?.(),u}}this[cr]=!0,this[Te]?this[Te].write(t):this[ws](t),this[cr]=!1;let i=this[Gt].length>0?!1:this[Ut]?this[Ut].flowing:!0;return!i&&this[Gt].length===0&&this[Ut]?.once("drain",()=>this.emit("drain")),r?.(),i}[Ha](t){t&&!this[an]&&(this[fe]=this[fe]?Buffer.concat([this[fe],t]):t)}[ys](){if(this[on]&&!this[qa]&&!this[an]&&!this[oi]){this[qa]=!0;let t=this[Dn];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](bs)}}[ws](t){if(this[oi]&&t)this[Ha](t);else if(!t&&!this[fe])this[ys]();else if(t){if(this[oi]=!0,this[fe]){this[Ha](t);let e=this[fe];this[fe]=void 0,this[_s](e)}else this[_s](t);for(;this[fe]&&this[fe]?.length>=512&&!this[an]&&!this[vs];){let e=this[fe];this[fe]=void 0,this[_s](e)}this[oi]=!1}(!this[fe]||this[on])&&this[ys]()}[_s](t){let e=0,r=t.length;for(;e+512<=r&&!this[an]&&!this[vs];)switch(this[st]){case"begin":case"header":this[lu](t,e),e+=512;break;case"ignore":case"body":e+=this[ja](t,e);break;case"meta":e+=this[du](t,e);break;default:throw new Error("invalid state: "+this[st])}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[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}},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)},Ym=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},Ku=(t,e)=>{let r=new Map(e.map(c=>[pi(c),!0])),i=t.filter,o=(c,l="")=>{let u=l||cm(c).root||".",h;if(c===u)h=!1;else{let p=r.get(c);h=p!==void 0?p:o(am(c),u)}return r.set(c,h),h};t.filter=i?(c,l)=>i(c,l)&&o(pi(c)):c=>o(pi(c))},Qm=t=>{let e=new Ei(t),r=t.file,i;try{i=xr.openSync(r,"r");let o=xr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let l=Buffer.allocUnsafe(o.size),u=xr.readSync(i,l,0,o.size,0);e.end(u===l.byteLength?l:l.subarray(0,u))}else{let l=0,u=Buffer.allocUnsafe(c);for(;l<o.size;){let h=xr.readSync(i,u,0,c,l);if(h===0)break;l+=h,e.write(u.subarray(0,h))}e.end()}}finally{if(typeof i=="number")try{xr.closeSync(i)}catch{}}},ew=(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),xr.stat(o,(u,h)=>{if(u)l(u);else{let p=new bc(o,{readSize:i,size:h.size});p.on("error",l),p.pipe(r)}})})},wr=vi(Qm,ew,t=>new Ei(t),t=>new Ei(t),(t,e)=>{e?.length&&Ku(t,e),t.noResume||Ym(t)}),$u=(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:nw,parse:hu}=tw,Ic=t=>{let e="",r=hu(t);for(;nw(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=hu(t)}return[e,t]},Ws=["|","<",">","?",":"],Ac=Ws.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),rw=new Map(Ws.map((t,e)=>[t,Ac[e]])),iw=new Map(Ac.map((t,e)=>[t,Ws[e]])),xu=t=>Ws.reduce((e,r)=>e.split(r).join(rw.get(r)),t),sw=t=>Ac.reduce((e,r)=>e.split(r).join(iw.get(r)),t),Vu=(t,e)=>e?(t=Z(t).replace(/^\.(\/|$)/,""),pi(e)+"/"+t):Z(t),ow=16*1024*1024,pu=Symbol("process"),gu=Symbol("file"),mu=Symbol("directory"),ic=Symbol("symlink"),wu=Symbol("hardlink"),ai=Symbol("header"),Rs=Symbol("read"),sc=Symbol("lstat"),Ds=Symbol("onlstat"),oc=Symbol("onread"),ac=Symbol("onreadlink"),cc=Symbol("openfile"),dc=Symbol("onopenfile"),fn=Symbol("close"),Fs=Symbol("mode"),lc=Symbol("awaitDrain"),Wa=Symbol("ondrain"),Rt=Symbol("prefix"),Ju=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=Ec(e);super(),this.path=Z(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||ow,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=Z(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?Z(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=sw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=Z(r.absolute||fu.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[Ds](o):this[sc]()}warn(t,e,r={}){return Hs(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[sc](){Ct.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Ds](e)})}[Ds](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=dw(t),this.emit("stat",t),this[pu]()}[pu](){switch(this.type){case"File":return this[gu]();case"Directory":return this[mu]();case"SymbolicLink":return this[ic]();default:return this.end()}}[Fs](t){return $u(t,this.type==="Directory",this.portable)}[Rt](t){return Vu(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 Bn({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this[Fs](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 Bs({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[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](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)}[mu](){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](){Ct.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[ac](e)})}[ac](t){this.linkpath=Z(t),this[ai](),this.end()}[wu](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=Z(fu.relative(this.cwd,t)),this.stat.size=0,this[ai](),this.end()}[gu](){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[wu](e);this.linkCache.set(t,this.absolute)}if(this[ai](),this.stat.size===0)return this.end();this[cc]()}[cc](){Ct.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[fn]();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");Ct.read(t,e,r,i,o,(c,l)=>{if(c)return this[fn](()=>this.emit("error",c));this[oc](l)})}[fn](t=()=>{}){this.fd!==void 0&&Ct.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[fn](()=>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[fn](()=>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[fn](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]()}},aw=class extends Ju{sync=!0;[sc](){this[Ds](Ct.lstatSync(this.absolute))}[ic](){this[ac](Ct.readlinkSync(this.absolute))}[cc](){this[dc](Ct.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 l=Ct.readSync(e,r,i,o,c);this[oc](l),t=!1}finally{if(t)try{this[fn](()=>{})}catch{}}}[lc](t){t()}[fn](t=()=>{}){this.fd!==void 0&&Ct.closeSync(this.fd),t()}},cw=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=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=Z(t.path),this.mode=t.mode!==void 0?this[Fs](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?Z(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[l,u]=Ic(this.path);l&&typeof u=="string"&&(this.path=u,o=l)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Bn({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](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 Bs({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[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](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)}[Rt](t){return Vu(t,this.prefix)}[Fs](t){return $u(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}},dw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",lw=class pr{tail;head;length=0;static create(e=[]){return new pr(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++)fw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)hw(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 pr;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 pr;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 pr;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 pr;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=uw(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 uw(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 fw(t,e){t.tail=new Tc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function hw(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}},yu=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},bu=Buffer.alloc(1024),Ps=Symbol("onStat"),ci=Symbol("ended"),ht=Symbol("queue"),di=Symbol("queue"),cn=Symbol("current"),On=Symbol("process"),li=Symbol("processing"),Ss=Symbol("processJob"),xt=Symbol("jobs"),Ka=Symbol("jobDone"),ks=Symbol("addFSEntry"),Eu=Symbol("addTarEntry"),uc=Symbol("stat"),fc=Symbol("readdir"),Os=Symbol("onreaddir"),Ns=Symbol("pipe"),vu=Symbol("entry"),$a=Symbol("entryOpt"),Ls=Symbol("writeEntryClass"),Zu=Symbol("write"),Va=Symbol("ondrain"),Ks=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];[di]=new Map;[xt]=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=Z(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]=Ju,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 bm(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new vm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new Im(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[ht]=new lw,this[xt]=0,this.jobs=Number(t.jobs)||4,this[li]=!1,this[ci]=!1}[Zu](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[On](),r&&r(),this}write(t){if(this[ci])throw new Error("write after end");return t instanceof Wu?this[Eu](t):this[ks](t),this.flowing}[Eu](t){let e=Z(_u.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new yu(t.path,e);r.entry=new cw(t,this[$a](r)),r.entry.on("end",()=>this[Ka](r)),this[xt]+=1,this[ht].push(r)}this[On]()}[ks](t){let e=Z(_u.resolve(this.cwd,t));this[ht].push(new yu(t,e)),this[On]()}[uc](t){t.pending=!0,this[xt]+=1;let e=this.follow?"stat":"lstat";zs[e](t.absolute,(r,i)=>{t.pending=!1,this[xt]-=1,r?this.emit("error",r):this[Ps](t,i)})}[Ps](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[Ss](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[On]()}[fc](t){t.pending=!0,this[xt]+=1,zs.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[On]()}[On](){if(!this[li]){this[li]=!0;for(let t=this[ht].head;t&&this[xt]<this.jobs;t=t.next)if(this[Ss](t.value),t.value.ignore){let e=t.next;this[ht].removeNode(t),t.next=e}this[li]=!1,this[ci]&&this[ht].length===0&&this[xt]===0&&(this.zip?this.zip.end(bu):(super.write(bu),super.end()))}}get[cn](){return this[ht]&&this[ht].head&&this[ht].head.value}[Ka](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[di].get(r);if(i){this[di].delete(r);for(let o of i)o.pending=!1,this[Ss](o)}}this[On]()}[Ss](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[Ns](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Ps](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[Os](t,e):this[fc](t),!t.readdir)return}if(t.entry=this[vu](t),!t.entry){t.ignore=!0;return}t===this[cn]&&!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}}[vu](t){this[xt]+=1;try{return new this[Ls](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[cn]&&this[cn].entry&&this[cn].entry.resume()}[Ns](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)}},Cc=class extends Ks{sync=!0;constructor(t){super(t),this[Ls]=aw}pause(){}resume(){}[uc](t){let e=this.follow?"statSync":"lstatSync";this[Ps](t,zs[e](t.absolute))}[fc](t){this[Os](t,zs.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[ks](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[Zu](i)})}},xw=(t,e)=>{let r=new Cc(t),i=new Bu(t.file,{mode:t.mode||438});r.pipe(i),Xu(r,e)},pw=(t,e)=>{let r=new Ks(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 Yu(r,e).catch(c=>r.emit("error",c)),o},Xu=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?wr({file:zu.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},Yu=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await wr({file:zu.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},gw=(t,e)=>{let r=new Cc(t);return Xu(r,e),r},mw=(t,e)=>{let r=new Ks(t);return Yu(r,e).catch(i=>r.emit("error",i)),r},D2=vi(xw,pw,gw,mw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),_w=process.env.__FAKE_PLATFORM__||process.platform,nf=_w==="win32",{O_CREAT:rf,O_NOFOLLOW:Su,O_TRUNC:sf,O_WRONLY:of}=tf.constants,af=Number(process.env.__FAKE_FS_O_FILENAME__)||tf.constants.UV_FS_O_FILEMAP||0,yw=nf&&!!af,bw=512*1024,Ew=af|sf|rf|of,Iu=!nf&&typeof Su=="number"?Su|sf|rf|of:null,cf=Iu!==null?()=>Iu:yw?t=>t<bw?Ew:"w":()=>"w",hc=(t,e,r)=>{try{return $s.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},Us=(t,e,r,i)=>{$s.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},vw=(t,e,r,i,o)=>{if(e.isDirectory())df(gi.resolve(t,e.name),r,i,c=>{if(c)return o(c);let l=gi.resolve(t,e.name);Us(l,r,i,o)});else{let c=gi.resolve(t,e.name);Us(c,r,i,o)}},df=(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 Us(t,e,r,i);let l=c.length,u=null,h=p=>{if(!u){if(p)return i(u=p);if(--l===0)return Us(t,e,r,i)}};for(let p of c)vw(t,p,e,r,h)})},Sw=(t,e,r,i)=>{e.isDirectory()&&lf(gi.resolve(t,e.name),r,i),hc(gi.resolve(t,e.name),r,i)},lf=(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 hc(t,e,r);throw c}for(let o of i)Sw(t,o,e,r);return hc(t,e,r)},uf=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"}},Vs=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"}},Aw=(t,e)=>{nt.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new uf(t,r?.code||"ENOTDIR")),e(r)})},Tw=(t,e,r)=>{t=Z(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,l=e.uid,u=e.gid,h=typeof l=="number"&&typeof u=="number"&&(l!==e.processUid||u!==e.processGid),p=e.preserve,_=e.unlink,E=Z(e.cwd),A=(v,I)=>{v?r(v):I&&h?df(I,l,u,S=>A(S)):c?nt.chmod(t,o,r):r()};if(t===E)return Aw(t,A);if(p)return Iw.mkdir(t,{mode:o,recursive:!0}).then(v=>A(null,v??void 0),A);let b=Z(Gs.relative(E,t)).split("/");xc(E,b,o,_,E,void 0,A)},xc=(t,e,r,i,o,c,l)=>{if(e.length===0)return l(null,c);let u=e.shift(),h=Z(Gs.resolve(t+"/"+u));nt.mkdir(h,r,ff(h,e,r,i,o,c,l))},ff=(t,e,r,i,o,c,l)=>u=>{u?nt.lstat(t,(h,p)=>{if(h)h.path=h.path&&Z(h.path),l(h);else if(p.isDirectory())xc(t,e,r,i,o,c,l);else if(i)nt.unlink(t,_=>{if(_)return l(_);nt.mkdir(t,r,ff(t,e,r,i,o,c,l))});else{if(p.isSymbolicLink())return l(new Vs(t,t+"/"+e.join("/")));l(u)}}):(c=c||t,xc(t,e,r,i,o,c,l))},Cw=t=>{let e=!1,r;try{e=nt.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new uf(t,r??"ENOTDIR")}},Rw=(t,e)=>{t=Z(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,l=e.gid,u=typeof c=="number"&&typeof l=="number"&&(c!==e.processUid||l!==e.processGid),h=e.preserve,p=e.unlink,_=Z(e.cwd),E=v=>{v&&u&&lf(v,c,l),o&&nt.chmodSync(t,i)};if(t===_)return Cw(_),E();if(h)return E(nt.mkdirSync(t,{mode:i,recursive:!0})??void 0);let A=Z(Gs.relative(_,t)).split("/"),b;for(let v=A.shift(),I=_;v&&(I+="/"+v);v=A.shift()){I=Z(Gs.resolve(I));try{nt.mkdirSync(I,i),b=b||I}catch{let S=nt.lstatSync(I);if(S.isDirectory())continue;if(p){nt.unlinkSync(I),nt.mkdirSync(I,i),b=b||I;continue}else if(S.isSymbolicLink())return new Vs(I,I+"/"+A.join("/"))}}return E(b)},Ja=Object.create(null),Au=1e4,dr=new Set,Dw=t=>{dr.has(t)?dr.delete(t):Ja[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),dr.add(t);let e=Ja[t],r=dr.size-Au;if(r>Au/10){for(let i of dr)if(dr.delete(i),delete Ja[i],--r<=0)break}return e},Pw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,kw=Pw==="win32",Ow=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=hf(i,r)),e.push(r||"/"),e},[]),Nw=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=kw?["win32 parallelization disabled"]:t.map(i=>pi(hf(Dw(i))));let r=new Set(t.map(i=>Ow(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 u=l[1];if(!u){this.#e.delete(c);continue}if(l.shift(),typeof u=="function")o.add(u);else for(let h of u)o.add(h)}for(let c of i){let l=this.#e.get(c),u=l?.[0];if(!(!l||!(u instanceof Set)))if(u.size===1&&l.length===1){this.#e.delete(c);continue}else if(u.size===1){l.shift();let h=l[0];typeof h=="function"&&o.add(h)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},Lw=()=>process.umask(),Tu=Symbol("onEntry"),pc=Symbol("checkFs"),Cu=Symbol("checkFs2"),gc=Symbol("isReusable"),ot=Symbol("makeFs"),mc=Symbol("file"),wc=Symbol("directory"),Ms=Symbol("link"),Ru=Symbol("symlink"),Du=Symbol("hardlink"),hi=Symbol("ensureNoSymlink"),Pu=Symbol("unsupported"),ku=Symbol("checkPath"),Za=Symbol("stripAbsolutePath"),hn=Symbol("mkdir"),ze=Symbol("onError"),Is=Symbol("pending"),Ou=Symbol("pend"),lr=Symbol("unpend"),Xa=Symbol("ended"),Ya=Symbol("maybeClose"),_c=Symbol("skip"),mi=Symbol("doChown"),wi=Symbol("uid"),_i=Symbol("gid"),yi=Symbol("checkedCwd"),Mw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,bi=Mw==="win32",Bw=1024,zw=(t,e)=>{if(!bi)return ne.unlink(t,e);let r=t+".DELETE."+ef(16).toString("hex");ne.rename(t,r,i=>{if(i)return e(i);ne.unlink(r,e)})},Fw=t=>{if(!bi)return ne.unlinkSync(t);let e=t+".DELETE."+ef(16).toString("hex");ne.renameSync(t,e),ne.unlinkSync(e)},Nu=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Rc=class extends Ei{[Xa]=!1;[yi]=!1;[Is]=0;reservations=new Nw;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[Xa]=!0,this[Ya]()},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:Bw,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=Z(Oe.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:Lw():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[Tu](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[Ya](){this[Xa]&&this[Is]===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 u=Oe.posix.dirname(t.path),h=Oe.posix.normalize(Oe.posix.join(u,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}[ku](t){let e=Z(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=Z(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)?Z(Oe.resolve(t.path)):Z(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:Z(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+xu(String(t.absolute).slice(i.length));let{root:o}=Oe.win32.parse(t.path);t.path=o+xu(t.path.slice(o.length))}return!0}[Tu](t){if(!this[ku](t))return t.resume();switch(ww.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[Pu](t)}}[ze](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[lr](),e.resume())}[hn](t,e,r){Tw(Z(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 Nu(this.uid,t.uid,this.processUid)}[_i](t){return Nu(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:cf(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&ne.close(i.fd,()=>{}),i.write=()=>!0,this[ze](u,t),e()});let o=1,c=u=>{if(u){i.fd&&ne.close(i.fd,()=>{}),this[ze](u,t),e();return}--o===0&&i.fd!==void 0&&ne.close(i.fd,h=>{h?this[ze](h,t):this[lr](),e()})};i.on("finish",()=>{let u=String(t.absolute),h=i.fd;if(typeof h=="number"&&t.mtime&&!this.noMtime){o++;let p=t.atime||new Date,_=t.mtime;ne.futimes(h,p,_,E=>E?ne.utimes(u,p,_,A=>c(A&&E)):c())}if(typeof h=="number"&&this[mi](t)){o++;let p=this[wi](t),_=this[_i](t);typeof p=="number"&&typeof _=="number"&&ne.fchown(h,p,_,E=>E?ne.chown(u,p,_,A=>c(A&&E)):c())}c()});let l=this.transform&&this.transform(t)||t;l!==t&&(l.on("error",u=>{this[ze](u,t),e()}),t.pipe(l)),l.pipe(i)}[wc](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[lr](),t.resume())};t.mtime&&!this.noMtime&&(o++,ne.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[mi](t)&&(o++,ne.chown(String(t.absolute),Number(this[wi](t)),Number(this[_i](t)),c)),c()})}[Pu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Ru](t,e){let r=Z(Oe.relative(this.cwd,Oe.resolve(Oe.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[hi](t,this.cwd,r,()=>this[Ms](t,String(t.linkpath),"symlink",e),i=>{this[ze](i,t),e()})}[Du](t,e){let r=Z(Oe.resolve(this.cwd,String(t.linkpath))),i=Z(String(t.linkpath)).split("/");this[hi](t,this.cwd,i,()=>this[Ms](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);ne.lstat(l,(u,h)=>{if(u)return i();if(h?.isSymbolicLink())return o(new Vs(l,Oe.resolve(l,r.join("/"))));this[hi](t,l,r,i,o)})}[Ou](){this[Is]++}[lr](){this[Is]--,this[Ya]()}[_c](t){this[lr](),t.resume()}[gc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!bi}[pc](t){this[Ou]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Cu](t,r))}[Cu](t,e){let r=l=>{e(l)},i=()=>{this[hn](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=Z(Oe.dirname(String(t.absolute)));if(l!==this.cwd)return this[hn](l,this.dmode,u=>{if(u){this[ze](u,t),r();return}c()})}c()},c=()=>{ne.lstat(String(t.absolute),(l,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[_c](t),r();return}if(l||this[gc](t,u))return this[ot](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let h=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,p=_=>this[ot](_??null,t,r);return h?ne.chmod(String(t.absolute),Number(t.mode),p):p()}if(t.absolute!==this.cwd)return ne.rmdir(String(t.absolute),h=>this[ot](h??null,t,r))}if(t.absolute===this.cwd)return this[ot](null,t,r);zw(String(t.absolute),h=>this[ot](h??null,t,r))})};this[yi]?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[mc](e,r);case"Link":return this[Du](e,r);case"SymbolicLink":return this[Ru](e,r);case"Directory":case"GNUDumpDir":return this[wc](e,r)}}[Ms](t,e,r,i){ne[r](e,String(t.absolute),o=>{o?this[ze](o,t):(this[lr](),t.resume()),i()})}},ui=t=>{try{return[null,t()]}catch(e){return[e,null]}},xf=class extends Rc{sync=!0;[ot](t,e){return super[ot](t,e,()=>{})}[pc](t){if(!this[yi]){let o=this[hn](this.cwd,this.dmode);if(o)return this[ze](o,t);this[yi]=!0}if(t.absolute!==this.cwd){let o=Z(Oe.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]=ui(()=>ne.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[ot](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[l]=c?ui(()=>{ne.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ot](l,t)}let[o]=ui(()=>ne.rmdirSync(String(t.absolute)));this[ot](o,t)}let[i]=t.absolute===this.cwd?[]:ui(()=>Fw(String(t.absolute)));this[ot](i,t)}[mc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=l=>{let u;try{ne.closeSync(o)}catch(h){u=h}(l||u)&&this[ze](l||u,t),e()},o;try{o=ne.openSync(String(t.absolute),cf(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{ne.writeSync(o,l,0,l.length)}catch(u){i(u)}}),c.on("end",()=>{let l=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,h=t.mtime;try{ne.futimesSync(o,u,h)}catch(p){try{ne.utimesSync(String(t.absolute),u,h)}catch{l=p}}}if(this[mi](t)){let u=this[wi](t),h=this[_i](t);try{ne.fchownSync(o,Number(u),Number(h))}catch(p){try{ne.chownSync(String(t.absolute),Number(u),Number(h))}catch{l=l||p}}}i(l)})}[wc](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{ne.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[mi](t))try{ne.chownSync(String(t.absolute),Number(this[wi](t)),Number(this[_i](t)))}catch{}e(),t.resume()}[hn](t,e){try{return Rw(Z(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[u,h]=ui(()=>ne.lstatSync(c));if(u)return i();if(h.isSymbolicLink())return o(new Vs(c,Oe.resolve(e,r.join("/"))))}i()}[Ms](t,e,r,i){let o=`${r}Sync`;try{ne[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[ze](c,t)}}},Uw=t=>{let e=new xf(t),r=t.file,i=Qu.statSync(r),o=t.maxReadSize||16*1024*1024;new om(r,{readSize:o,size:i.size}).pipe(e)},Gw=(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),Qu.stat(o,(u,h)=>{if(u)l(u);else{let p=new bc(o,{readSize:i,size:h.size});p.on("error",l),p.pipe(r)}})})},pf=vi(Uw,Gw,t=>new xf(t),t=>new Rc(t),(t,e)=>{e?.length&&Ku(t,e)}),qw=(t,e)=>{let r=new Cc(t),i=!0,o,c;try{try{o=et.openSync(t.file,"r+")}catch(h){if(h?.code==="ENOENT")o=et.openSync(t.file,"w+");else throw h}let l=et.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<l.size;c+=512){for(let _=0,E=0;_<512;_+=E){if(E=et.readSync(o,u,_,u.length-_,c+_),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!E)break e}let h=new Bn(u);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,jw(t,r,c,o,e)}finally{if(i)try{et.closeSync(o)}catch{}}},jw=(t,e,r,i,o)=>{let c=new Bu(t.file,{fd:i,start:r});e.pipe(c),Ww(e,o)},Hw=(t,e)=>{e=Array.from(e);let r=new Ks(t),i=(o,c,l)=>{let u=(A,b)=>{A?et.close(o,v=>l(A)):l(null,b)},h=0;if(c===0)return u(null,0);let p=0,_=Buffer.alloc(512),E=(A,b)=>{if(A||b===void 0)return u(A);if(p+=b,p<512&&b)return et.read(o,_,p,_.length-p,h+p,E);if(h===0&&_[0]===31&&_[1]===139)return u(new Error("cannot append to compressed archives"));if(p<512)return u(null,h);let v=new Bn(_);if(!v.cksumValid)return u(null,h);let I=512*Math.ceil((v.size??0)/512);if(h+I+512>c||(h+=I+512,h>=c))return u(null,h);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),p=0,et.read(o,_,0,512,h,E)};et.read(o,_,0,512,h,E)};return new Promise((o,c)=>{r.on("error",c);let l="r+",u=(h,p)=>{if(h&&h.code==="ENOENT"&&l==="r+")return l="w+",et.open(t.file,l,u);if(h||!p)return c(h);et.fstat(p,(_,E)=>{if(_)return et.close(p,()=>c(_));i(p,E.size,(A,b)=>{if(A)return c(A);let v=new qs(t.file,{fd:p,start:b});r.pipe(v),v.on("error",c),v.on("close",o),Kw(r,e)})})};et.open(t.file,l,u)})},Ww=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?wr({file:gf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},Kw=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await wr({file:gf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},fi=vi(qw,Hw,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!xm(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")}),W2=vi(fi.syncFile,fi.asyncFile,fi.syncNoFile,fi.asyncNoFile,(t,e=[])=>{fi.validate?.(t,e),$w(t)}),$w=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 Si(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function mf(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function Dc(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function wf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function _r(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}He();te();Pe();He();function Ht(t,e){if(Si(t)!=="cloud")throw new C("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Js(t){return t.startsWith("http://")||t.startsWith("https://")}function Zs(t){return t.endsWith("/")?t.slice(0,-1):t}He();te();var Xs="1008033",_f="1289";var yf="pbbp2",bf="https://www.coze.cn",Ef="/api/coze_claw/resource/get_frontier_key",Jw="https://www.coze.cn",Zw="wss://frontier.coze.cn";function Ys(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??Jw}function vf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??Zw}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 Ai(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Ii=U("handshake");async function Pc(t){let e=Ys(t.endpoint),r=t.timeoutMs??1e4,i=`${Zs(e)}${Ef}?aid=${encodeURIComponent(Xs)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...yr(t.ppeOverride)},c=new AbortController,l=setTimeout(()=>c.abort(),r);Ii.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),h=u.headers.get("x-tt-logid")??"",p=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let v=await u.text().catch(()=>"");throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${h}: ${v.slice(0,200)}`)}let _=await u.json();if(_.code!==void 0&&_.code!==0)throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${_.code} msg=${_.msg??"-"} logid=${h}`);let E=_.data??{},A=typeof E.access_key=="string"&&E.access_key||typeof E.accessKey=="string"&&E.accessKey||void 0,b=typeof E.device_id=="string"&&E.device_id||typeof E.deviceId=="string"&&E.deviceId||void 0;if(!A||!b){let v=JSON.stringify(_).slice(0,500);throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${h}: ${v}`)}return Ii.info("handshake ok",{remoteDeviceId:b,logid:h,traceId:p}),{accessKey:A,deviceId:b}}catch(u){if(u instanceof C)throw Ii.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Ii.warn("handshake timeout",{base:e,timeoutMs:r}),new C("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let h=u.cause;throw Ii.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:h?.code,syscall:h?.syscall,cause:String(u).slice(0,300)}),new C("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(l)}}var kc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",wt="auto",Sf=15e4;function If(t){return{model:Oc(t.model)??wt,...t.modelToken?{modelToken:t.modelToken}:{}}}function Af(t){return!t||t===wt}var Xw=new Set(["auto","\u81EA\u52A8"]);function Oc(t){let e=t?.trim();if(e)return Xw.has(e.toLowerCase())?wt:e}function Tf(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=kc,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 Af(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Cf(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||wt}"`):Af(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="${kc}/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??Sf;e.push("-c",`model_context_window=${r}`)}return e}function Rf(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function Nc(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 Df(t,e,r){if(!t.modelToken)return{};let i=Nc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,l])=>`${c}:${l}`).join(`
92
- `)}}function Lc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function Pf(t,e,r){if(!t.modelToken)return null;let i=t.model||wt,o=Nc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let l={baseUrl:`${kc}/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??Sf,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(l.headers=o),l}function kf(t,e,r){if(!t.modelToken)return[];let i=Nc(e,r),o=[];for(let[c,l]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${l}"`);return o}var Ne=U("agent-handlers"),Of=5*1024*1024,r_=1,i_=6,s_=new Set(["node_modules",".git",".coze","dist","build",".next"]),Qs=class{constructor(e){this.opts=e}opts;async listSkills(e){Ht(e._meta,"_agent/listSkills");let r=_r(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Je(r).workspace,c=i?.skills??[],l=[];for(let u of c){let h=Pt(o,u.relPath,"SKILL.md");await e_(h).then(_=>_.isFile()).catch(()=>!1)&&l.push(l_(u))}return{skills:l}}async addSkills(e){Ht(e._meta,"_agent/addSkills");let r=_r(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],l=new Map(c.map((h,p)=>[h.skillId,p])),u=[];for(let h of o){let p=await qc({agentId:r,workspace:i.workspace,framework:i.framework,skill:h});jc(c,l,p),u.push(h)}return await is(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){Ht(e._meta,"_agent/removeSkills");let r=_r(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],l=[];for(let u of c){if(!o.has(u.skillId)){l.push(u);continue}let h=Pt(i.workspace,u.relPath);await Qw(h,{recursive:!0,force:!0}),Ne.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await is(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,Ne.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,Ne.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l}),h.stop(r).catch(p=>Ne.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 Ne.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await Ge(r);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Ne.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await nr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Ne.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new C("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Ze(i),Ne.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 C("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Ge(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Ze(i),Ne.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}):(Ne.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(Ht(e._meta,"_agent/switchModel"),!e.agentId)throw new C("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Oc(e.model)??wt,i=await Ge(e.agentId);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Ze(i),Ne.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Ne.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=>Ne.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(l)}));let c=[];for(let[l,u]of o.allSessionQueues())c.push(u.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),Ne.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 C("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),Ne.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 Xr(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 Ze(r)}async repairAgent(e){if(Ht(e._meta,mt.REPAIR),!e.agentId)throw new C("IPC_BAD_REQUEST",`${mt.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new C("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){Ne.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){Ne.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Ne.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=_r(r),o=await this.resolveWorkspace(i),c=e.filePath??"",l=this.safeJoin(o,c),u=await Mc(l).catch(()=>null);if(!u)throw new C("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await Zr(l,o))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let h=b_(e.depth);return u.isDirectory()?{tree:await y_(o,l,c,h)}:{tree:[{name:E_(c),path:Uf(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){Ht(e._meta,"_agent/getFileContent");let r=_r(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new C("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await Mc(o).catch(()=>null);if(!c||!c.isFile())throw new C("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await Zr(o,i))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Of)throw new C("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Of})`);let l=await Nf(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 Ge(e).catch(()=>null))?.workspace??Je(e).workspace}safeJoin(e,r){let i=Fc(e,r||"."),o=Gc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Lf}`))throw new C("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 C("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function o_(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new C("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new C("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function a_(t){return t==="claude-code"?Pt(".claude","skills"):Pt(".agents","skills")}var c_=3e4,d_=50*1024*1024,br=3e4;async function qc(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new C("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 C("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=o_(o.skillName),h=a_(i),p=Pt(h,u),_=Pt(r,p);if(await Bc(_,{recursive:!0}),c){let A=Buffer.from(o.content,"utf8");Ti(A.length),await zc(Pt(_,"SKILL.md"),A,"utf8")}else{let A=await u_(o.downloadUrl);h_(A)?await m_(A,_):x_(A)?await p_(A,_):await zc(Pt(_,"SKILL.md"),A.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 Ne.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:p,source:c?"content":"downloadUrl"}),E}function jc(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 l_(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 u_(t){if(!t)throw new C("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Ti(e);let r=f_(t);return Ti(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await Nf(e);return Ti(r.length),r}if(Js(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),c_);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new C("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 C("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Ti(t){if(t>d_)throw new C("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function f_(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new C("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 h_(t){return t.length>=2&&t[0]===31&&t[1]===139}function x_(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 p_(t,e){let r,i;try{r=new zf.default(t),i=r.getEntries()}catch(l){throw new C("IPC_BAD_REQUEST",`zip parse failed: ${l.message}`,{cause:l})}for(let l of i){let u=l.entryName;if(!u||Uc(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new C("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(p=>p===".."))throw new C("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let h=l.header.attr>>>16&61440;if(h!==0&&h!==32768&&h!==16384)throw new C("IPC_BAD_REQUEST",`zip entry kind 0x${h.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=g_(i),c=Fc(e);for(let l of i){if(Uc(l.entryName))continue;let u=l.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let h=Fc(e,u),p=Gc(c,h);if(p.startsWith("..")||p==="..")throw new C("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(l.isDirectory){await Bc(h,{recursive:!0});continue}await Bc(t_(h),{recursive:!0});let _;try{_=l.getData()}catch(E){throw new C("IPC_BAD_REQUEST",`zip entry getData failed (${l.entryName}): ${E.message}`,{cause:E})}await zc(h,_)}}function g_(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 m_(t,e){await w_(t);let r=pf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new C("IPC_BAD_REQUEST",`tar extract timeout (${br}ms)`))},br);try{await Bf(Mf.from(t),r)}catch(c){throw c instanceof C?c:i?new C("IPC_BAD_REQUEST",`tar extract timeout (${br}ms)`):new C("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function w_(t){let e=[],r=wr({onReadEntry:c=>{let l=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' 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 C("IPC_BAD_REQUEST",`tar list timeout (${br}ms)`))},br);try{await Bf(Mf.from(t),r)}catch(c){throw i?new C("IPC_BAD_REQUEST",`tar list timeout (${br}ms)`):new C("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new C("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var __=5e3;async function y_(t,e,r,i){return Ff(t,e,r,i,{count:0})}async function Ff(t,e,r,i,o){if(i<=0)return[];let c;try{c=await Yw(e,{withFileTypes:!0})}catch{return[]}let l=[];for(let u of c){if(s_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=__){l.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let h=Pt(e,u.name),p=n_(Pt(r,u.name)),_=null;try{_=await Mc(h)}catch{continue}if(_.isSymbolicLink())continue;o.count++;let E={name:u.name,path:Uf(Gc(t,h)),isDir:_.isDirectory(),size:_.size,modifiedAt:Math.floor(_.mtimeMs)};_.isDirectory()&&i>1&&(E.children=await Ff(t,h,p,i-1,o)),l.push(E)}return l.sort((u,h)=>u.isDir!==h.isDir?u.isDir?-1:1:u.name.localeCompare(h.name)),l}function b_(t){return!t||t<=0?r_:Math.min(t,i_)}function E_(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function Uf(t){return t.split(Lf).join("/")}te();import{readFileSync as tA}from"node:fs";import{dirname as rA,join as iA}from"node:path";import{fileURLToPath as oA}from"node:url";var Er="0.1.100-beta.0";var gn=U("agent-health-reporter"),v_=1e4,Ci=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??v_}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 l of this.opts.core.agents.values()){let u=S_(l);if(!u)continue;let h={agentId:l.agentId,status:u};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:Er,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(l){gn.warn("heartbeat batch send failed",{count:r.length,err:String(l)})}let c=o?.authFailures;if(c&&c.length>0&&(gn.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){gn.warn("onAuthFailures callback failed (ignored)",{err:String(l)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){gn.warn("onTickEnd hook failed",{err:String(r)})}}};function S_(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}tn();import{chmod as yy,mkdir as uo,rm as by,stat as Ey,writeFile as vy}from"node:fs/promises";import{homedir as Sy}from"node:os";import{join as h0}from"node:path";en();import{existsSync as q_}from"node:fs";import{release as j_}from"node:os";import{basename as H_,isAbsolute as W_}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 vr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Sr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function mn(t,e){return{jsonrpc:"2.0",id:t,error:e}}He();var eo=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 Gf(t){return"method"in t&&"id"in t&&t.id!==void 0}function qf(t){return"method"in t&&!("id"in t)}function to(t){return!("method"in t)&&"id"in t}var I_={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 A_(t){if(t!=null)return t instanceof Error?{name:t.name,message:Di(t.message)}:typeof t=="string"?Di(t):typeof t=="object"?C_(t):t}var T_=[[/\/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 Di(t){let e=t;for(let[r,i]of T_)e=e.replace(r,i);return e}function C_(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Di(i):e[r]=i;return e}function Pi(t){if(t instanceof C){let e=A_(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:I_[t.code]??Q.INTERNAL_ERROR,message:Di(t.message),data:r}}return{code:Q.INTERNAL_ERROR,message:Di(t instanceof Error?t.message:String(t))}}function jf(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,...u}=e;c=u}return new C(r,o,{retriable:e?.retriable??!1,cause:c})}function Wf(t){return`${JSON.stringify(t)}
93
- `}var Hf=10*1024*1024,no=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>Hf){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${Hf} 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 $f={"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"},mA=Object.fromEntries(Object.entries($f).map(([t,e])=>[e,t])),R_={"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:[]},Ir=class{seq=0;next(e,r){this.seq+=1;let i=$f[e]??D_(e),o=R_[i]??[],c=[i,String(this.seq)];if(o.length>0){let l=o.map(h=>Kf(r?.[h]??"")),u=P_(l).join(":");u&&c.push(u)}else r&&Object.values(r).some(l=>l)&&c.push(Object.values(r).filter(Boolean).map(l=>Kf(String(l))).join(":"));return c.join("_")}reset(){this.seq=0}};function D_(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function Kf(t){return t.replace(/[:_\s]+/g,"-")}function P_(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}Jr();import{readFileSync as k_}from"node:fs";var O_=384;async function Hc(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await tr(t.agentEnvFile,r,{mode:O_})}function Wc(t){try{let e=JSON.parse(k_(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function Vf(t,e,r={},i=o=>o){return{...i({...t,...Wc(e)}),...r}}wn();Hr();He();te();Pe();import{spawnSync as U_}from"node:child_process";function ro(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function io(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),U_("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var Kc=new Set;function Yf(t){typeof t=="number"&&t>0&&Kc.add(t)}function Qf(t){typeof t=="number"&&Kc.delete(t)}function e0(){for(let t of Kc)io(t,"SIGKILL")}var G_=[{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 t0(t,e){if(!e)return null;for(let r of G_)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function n0(t,e){return t0(t,e)}function r0(t,e){return t0(t,e)}function Ar(t,e,r){return!e&&r.firstUpdateMs>0&&t<r.firstUpdateMs?Math.max(1,r.firstUpdateMs-t):t<r.phase2GateMs?Math.max(1,r.phase2GateMs-t):Math.max(1,r.livenessWindowMs)}function i0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let p=t.suspendedMs+o,_=r-t.startedAt-p;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Ar(_,t.firstFrameSeen,e)}}let c=r-t.startedAt-t.suspendedMs,l=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=l?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Ar(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Ar(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Ar(c,!1,e)}}var s0=Ve("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),K_=200,$_=40,V_=Ve("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),J_=Ve("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),Z_=Ve("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),X_=Ve("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),Y_=Ve("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Q_=Ve("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),o0=500;function ey(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=o0?t:`${e.slice(0,o0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function ty(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 a0(t){try{return q_(t)}catch{return}}function ny(t,e){return{platform:process.platform,osRelease:j_(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:W_(e.command)?a0(e.command):void 0,cwd:e.cwd,cwdExists:a0(e.cwd),envKeys:e.envKeys}}function ry(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${H_(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var kt=class{constructor(e){this.opts=e;this.log=U(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new no({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Ir;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new C("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=Vf(process.env,this.opts.agentEnvFile??X().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,Yf(i.pid),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>K_&&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,Qf(i.pid),(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 u of this.decoder.flush())this.dispatch(u)}catch(u){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(u)})}this.failAllPending(this.buildExitError(o,c));for(let u of this.exitHandlers)u(o,c)}),i.on("error",o=>{let c=o,l=ny(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 C("AGENT_SPAWN_FAILED",ry(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()));io(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||io(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){let i={firstUpdateMs:Y_,phase2GateMs:V_,livenessWindowMs:J_,absoluteMaxMs:Z_,approvalMaxMs:Q_,suspendThresholdMs:X_,...r};return this.call("session/prompt",e,s0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(vr("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(Sr(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=s0,o){if(!this.child||this.stopped)return Promise.reject(new C("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),l=Ri(c,e,r),u=(()=>{if(typeof r!="object"||r===null)return;let h=r.sessionId;return typeof h=="string"?h:void 0})();return new Promise((h,p)=>{let _={resolve:h,reject:p,timer:null,method:e,promptTimeout:null};if(o){let E=this.now(),A={cfg:o,startedAt:E,lastActivityAt:E,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:E,expectedIntervalMs:Ar(0,!1,o),sessionId:u};_.promptTimeout=A;let b=()=>{let v={startedAt:A.startedAt,lastActivityAt:A.lastActivityAt,firstFrameSeen:A.firstFrameSeen,hasActiveTool:A.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:A.suspendedMs,armedAt:A.armedAt,expectedIntervalMs:A.expectedIntervalMs},I=this.now(),S=i0(v,A.cfg,I),R=N=>{A.armedAt=I,A.expectedIntervalMs=N,_.timer=setTimeout(b,N)};if(S.action==="suspend"){A.suspendedMs+=S.suspendedDeltaMs,A.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:S.suspendedDeltaMs,suspendedMs:A.suspendedMs,...A.sessionId?{sessionId:A.sessionId}:{}}),R(S.rearmMs);return}if(S.action==="continue"){R(S.rearmMs);return}this.pending.delete(c),S.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:S.awaitingApproval,...A.sessionId?{sessionId:A.sessionId}:{}}),p(S.awaitingApproval?new C("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${A.cfg.approvalMaxMs}ms`):new C("AGENT_TIMEOUT",`${e} timed out after ${A.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...A.sessionId?{sessionId:A.sessionId}:{}}),p(new C("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${A.cfg.livenessWindowMs}ms`)))};_.timer=setTimeout(b,A.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(_.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),p(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,_);try{this.writeFrame(l)}catch(E){_.timer&&clearTimeout(_.timer),this.pending.delete(c),p(E)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new C("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(Wf(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(to(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),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 C("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:ey(e.result)}),r.resolve(e.result));return}if(qf(e)){if(e.method==="session/update"){let r=e.params;for(let i of this.pending.values()){let o=i.promptTimeout;o&&(o.firstFrameSeen=!0,o.lastActivityAt=this.now(),this.trackToolCall(o,r))}for(let i of this.updateHandlers)try{Promise.resolve(i(r)).catch(o=>this.log.warn("update handler failed (async)",{err:String(o)}))}catch(o){this.log.warn("update handler threw sync, swallowed",{err:String(o)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(Gf(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)})}}}trackToolCall(e,r){let i=r.update,o=i?.sessionUpdate;if(o!=="tool_call"&&o!=="tool_call_update")return;let c=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!c)return;let l=typeof i.status=="string"?i.status:void 0,u=l==="completed"||l==="failed"||l==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}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,Pi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=jf(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=r0(this.framework,ty(e));return i?new C(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 C("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail($_).join(`
95
- `),o=n0(this.framework,i);return o?new C(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new C("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.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function iy(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 so=class extends kt{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 iy(e)}};en();import{mkdtempSync as sy,rmSync as oy}from"node:fs";import{tmpdir as ay}from"node:os";import{join as cy}from"node:path";var oo=class extends kt{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?sy(cy(ay(),"coze-bridge-codex-home-")):void 0,u=l?{...e.env??{},CODEX_HOME:l}:e.env,h={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};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{oy(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};var dy=3e4,Tr=class extends kt{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.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},dy))}get acpSessionName(){return this.sessionName}};He();te();Pe();function $c(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}en();var _n=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 ao=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 _n,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)ki(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 ki(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}wn();te();import{constants as c0}from"node:fs";import{access as ly}from"node:fs/promises";import{delimiter as uy,join as fy}from"node:path";var _t=U("framework-detector"),d0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},hy=[".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??ly}}async detect(e){let r=d0[e],i=await this.which(r);if(!i)return _t.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)]),u={path:i,version:c};return l&&(u.defaultAgent=l),u}async detectAll(){let e=await Promise.all(Object.keys(d0).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(uy).filter(Boolean),i=this.env.platform==="win32"?["",...hy]:[""];for(let o of r)for(let c of i){let l=fy(o,e+c);if(await this.isExecutable(l))return l}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?c0.F_OK:c0.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 _t.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return _t.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 _t.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 _t.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?(_t.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}:(_t.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return _t.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 _t.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||_t.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){_t.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&&(py(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,l,u=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"),u(null)},15e3),h.stdout?.on("data",p=>{o+=p.toString("utf8")}),h.on("error",()=>u(null)),h.on("close",p=>u({code:p,stdout:o}))}catch{u(null)}})}},xy=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function py(t){return t.replace(xy,"")}import{homedir as gy}from"node:os";import{join as my}from"node:path";wn();Hr();He();Jr();te();async function f0(){let t=my(gy(),".openclaw/openclaw.json");return(await er(t))?.gateway?.auth?.token??""}var l0=U("openclaw.config"),wy=[0,5e3,5e3],_y=Ve("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),u0="models.providers.",co="agents.defaults.models",lo=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new _n;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??wy,this.cliTimeoutMs=e.cliTimeoutMs??_y}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,l0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(l)})}}throw new C("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","ignore","pipe"],env:this.env}),c="",l=!1,u=p=>{l||(l=!0,clearTimeout(h),p())};o.stderr?.on("data",p=>{c+=p.toString("utf8")});let h=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);h.unref(),o.on("error",p=>u(()=>i(p))),o.on("close",p=>u(()=>{p===0?r():i(new Error(`exit ${p}: ${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){l0.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",`${u0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${u0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${co}[${e}]`,()=>this.runCli(["config","set",co,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${co}[${e}]`,`${co}.${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=U("agent-manager"),Iy=(t,e,r,i,o,c,l,u,h)=>{switch(t){case"claude-code":{let p={...o?{...Tf(o),...Df(o,l,u)}:{},...h??{},IS_SANDBOX:"1"};return new so({cwd:r,env:p,agentId:i})}case"codex":{let _=[...o?[...Cf(o),...kf(o,l,u)]:[],"-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"'],E={...o?Rf(o):{},...h??{}},A=!!o;return new oo({cwd:r,agentId:i,..._.length>0?{extraArgs:_}:{},...Object.keys(E).length>0?{env:E}:{},...A?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Tr({command:e,cwd:r,agentId:i,...c?{sessionName:$c(c)}:{}})}};function Vc(t){return t==="claude-code"||t==="codex"}function Ay(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(Ty(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
89
+ `},configPath(t){return iS(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 jh("schtasks",["/Create","/SC","ONLOGON","/TN",ra,"/TR",r,"/RU",t.userName,"/F"]),Fd.info("task scheduler entry created",{task:ra,logFile:t.logFile})},async uninstall(t){await jh("schtasks",["/Delete","/TN",ra,"/F"]).catch(e=>Fd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Fd.info("task scheduler entry removed",{task:ra})}}});var Kh={};ma(Kh,{buildContext:()=>lS,getSupervisor:()=>aS,launchdSupervisor:()=>Bd,systemdSupervisor:()=>zd,taskSchedulerSupervisor:()=>Ud});import{homedir as sS,userInfo as oS}from"node:os";function aS(t=process.platform){switch(t){case"darwin":return Bd;case"linux":return zd;case"win32":return Ud;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function dS(){let t={};for(let e of cS){let r=process.env[e];r&&(t[e]=r)}return t}function lS(){let t=J();return{nodeBin:process.execPath,entry:Cd(t),logFile:t.logFile,homeDir:sS(),userName:oS().username,isRoot:process.getuid?.()===0,env:dS()}}var cS,$h=Ve(()=>{"use strict";ke();Ko();Gh();Hh();Wh();cS=["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 ml=G("acp-installer-warmup"),_g=["claude-code","codex"];async function wl(t={}){let e=t.ensure??tr,i=(await Promise.allSettled(_g.map(async o=>{let c=await e(o);ml.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&ml.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 kg}from"node:fs/promises";import{mkdir as Sl,writeFile as Il}from"node:fs/promises";import{join as Sa}from"node:path";var Rg={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function ir(t,e,r){await Sl(t,{recursive:!0});let i=Rg[e],o=Sa(t,i);return await Il(o,r??"","utf8"),o}async function Al(t,e){let r=Sa(t,".claude");await Sl(r,{recursive:!0});let i=Sa(r,"settings.local.json"),o={permissions:{defaultMode:"bypassPermissions"}};e==="cloud"&&(o.autoCompactWindow=15e4);let c=JSON.stringify(o,null,2);return await Il(i,c,"utf8"),i}var Qe=G("agent-detail-sync"),Pg=6e4,Og=5*6e4,us=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await kg(r)}catch(o){Qe.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}Qe.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){Qe.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(l){Qe.warn("detail sync failed for agent, skipping",{agentId:o,err:String(l)})}}})),Qe.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){Qe.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){Qe.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){Qe.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(u){Qe.warn("detail RPC failed, using local data",{agentId:e,err:String(u)});let x=this.retryQueue.get(e),p=x?Math.min(x.currentDelay*2,Og):Pg;this.retryQueue.set(e,{dueAt:Date.now()+p,currentDelay:p});return}if(o.agentId&&o.agentId!==e){Qe.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&&Qe.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Qe.debug("detail sync: no diff",{agentId:e});return}await Ye(i,this.opts.paths),Qe.info("detail sync: config updated",{agentId:e,identityChanged:l,agentName:i.agentName}),l&&(await ir(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var q0=It(su(),1);import{lstat as Fc,mkdir as Uc,readFile as z0,readdir as o_,rm as a_,stat as c_,writeFile as Gc}from"node:fs/promises";import{dirname as d_,join as Ot,normalize as l_,relative as jc,resolve as qc,sep as F0}from"node:path";import{Readable as U0}from"node:stream";import{pipeline as G0}from"node:stream/promises";import tm from"events";import Je from"fs";import{EventEmitter as vc}from"node:events";import Uu from"node:stream";import{StringDecoder as nm}from"node:string_decoder";import Hu from"node:path";import gr from"node:fs";import{dirname as pm,parse as gm}from"path";import{EventEmitter as Sm}from"events";import ic from"assert";import{Buffer as Bn}from"buffer";import*as lu from"zlib";import Im from"zlib";import{posix as dr}from"node:path";import{basename as Xm}from"node:path";import Hs from"fs";import Rt from"fs";import mu from"path";import{win32 as dw}from"node:path";import Su from"path";import i0 from"node:fs";import Aw from"node:assert";import{randomBytes as s0}from"node:crypto";import re from"node:fs";import Oe from"node:path";import o0 from"fs";import Xs from"node:fs";import wi from"node:path";import rt from"node:fs";import Ow from"node:fs/promises";import Ks from"node:path";import{join as m0}from"node:path";import nt from"node:fs";import y0 from"node:path";var Qg=Object.defineProperty,em=(t,e)=>{for(var r in e)Qg(t,r,{get:e[r],enumerable:!0})},ou=typeof process=="object"&&process?process:{stdout:null,stderr:null},rm=t=>!!t&&typeof t=="object"&&(t instanceof Un||t instanceof Uu||im(t)||sm(t)),im=t=>!!t&&typeof t=="object"&&t instanceof vc&&typeof t.pipe=="function"&&t.pipe!==Uu.Writable.prototype.pipe,sm=t=>!!t&&typeof t=="object"&&t instanceof vc&&typeof t.write=="function"&&typeof t.end=="function",Ut=Symbol("EOF"),Gt=Symbol("maybeEmitEnd"),on=Symbol("emittedEnd"),gs=Symbol("emittingEnd"),ti=Symbol("emittedError"),ms=Symbol("closed"),au=Symbol("read"),ws=Symbol("flush"),cu=Symbol("flushChunk"),pt=Symbol("encoding"),cr=Symbol("decoder"),Le=Symbol("flowing"),ni=Symbol("paused"),xr=Symbol("resume"),Me=Symbol("buffer"),Ke=Symbol("pipes"),Be=Symbol("bufferLength"),Ra=Symbol("bufferPush"),_s=Symbol("bufferShift"),je=Symbol("objectMode"),Se=Symbol("destroyed"),ka=Symbol("error"),Pa=Symbol("emitData"),du=Symbol("emitEnd"),Oa=Symbol("emitEnd2"),Tt=Symbol("async"),Na=Symbol("abort"),ys=Symbol("aborted"),ri=Symbol("signal"),Cn=Symbol("dataListeners"),et=Symbol("discarded"),ii=t=>Promise.resolve().then(t),om=t=>t(),am=t=>t==="end"||t==="finish"||t==="prefinish",cm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,dm=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Gu=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[xr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},lm=class extends Gu{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)}},um=t=>!!t.objectMode,fm=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Un=class extends vc{[Le]=!1;[ni]=!1;[Ke]=[];[Me]=[];[je];[pt];[Tt];[cr];[Ut]=!1;[on]=!1;[gs]=!1;[ms]=!1;[ti]=null;[Be]=0;[Se]=!1;[ri];[ys]=!1;[Cn]=0;[et]=!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");um(e)?(this[je]=!0,this[pt]=null):fm(e)?(this[pt]=e.encoding,this[je]=!1):(this[je]=!1,this[pt]=null),this[Tt]=!!e.async,this[cr]=this[pt]?new nm(this[pt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Me]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Ke]});let{signal:r}=e;r&&(this[ri]=r,r.aborted?this[Na]():r.addEventListener("abort",()=>this[Na]()))}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[je]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[Tt]}set async(t){this[Tt]=this[Tt]||!!t}[Na](){this[ys]=!0,this.emit("abort",this[ri]?.reason),this.destroy(this[ri]?.reason)}get aborted(){return this[ys]}set aborted(t){}write(t,e,r){if(this[ys])return!1;if(this[Ut])throw new Error("write after end");if(this[Se])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[Tt]?ii:om;if(!this[je]&&!Buffer.isBuffer(t)){if(dm(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(cm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[je]?(this[Le]&&this[Be]!==0&&this[ws](!0),this[Le]?this.emit("data",t):this[Ra](t),this[Be]!==0&&this.emit("readable"),r&&i(r),this[Le]):t.length?(typeof t=="string"&&!(e===this[pt]&&!this[cr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[pt]&&(t=this[cr].write(t)),this[Le]&&this[Be]!==0&&this[ws](!0),this[Le]?this.emit("data",t):this[Ra](t),this[Be]!==0&&this.emit("readable"),r&&i(r),this[Le]):(this[Be]!==0&&this.emit("readable"),r&&i(r),this[Le])}read(t){if(this[Se])return null;if(this[et]=!1,this[Be]===0||t===0||t&&t>this[Be])return this[Gt](),null;this[je]&&(t=null),this[Me].length>1&&!this[je]&&(this[Me]=[this[pt]?this[Me].join(""):Buffer.concat(this[Me],this[Be])]);let e=this[au](t||null,this[Me][0]);return this[Gt](),e}[au](t,e){if(this[je])this[_s]();else{let r=e;t===r.length||t===null?this[_s]():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[Le]||!this[ni])&&this[Gt](),this}[xr](){this[Se]||(!this[Cn]&&!this[Ke].length&&(this[et]=!0),this[ni]=!1,this[Le]=!0,this.emit("resume"),this[Me].length?this[ws]():this[Ut]?this[Gt]():this.emit("drain"))}resume(){return this[xr]()}pause(){this[Le]=!1,this[ni]=!0,this[et]=!1}get destroyed(){return this[Se]}get flowing(){return this[Le]}get paused(){return this[ni]}[Ra](t){this[je]?this[Be]+=1:this[Be]+=t.length,this[Me].push(t)}[_s](){return this[je]?this[Be]-=1:this[Be]-=this[Me][0].length,this[Me].shift()}[ws](t=!1){do;while(this[cu](this[_s]())&&this[Me].length);!t&&!this[Me].length&&!this[Ut]&&this.emit("drain")}[cu](t){return this.emit("data",t),this[Le]}pipe(t,e){if(this[Se])return t;this[et]=!1;let r=this[on];return e=e||{},t===ou.stdout||t===ou.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[Ke].push(e.proxyErrors?new lm(this,t,e):new Gu(this,t,e)),this[Tt]?ii(()=>this[xr]()):this[xr]()),t}unpipe(t){let e=this[Ke].find(r=>r.dest===t);e&&(this[Ke].length===1?(this[Le]&&this[Cn]===0&&(this[Le]=!1),this[Ke]=[]):this[Ke].splice(this[Ke].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[et]=!1,this[Cn]++,!this[Ke].length&&!this[Le]&&this[xr]();else if(t==="readable"&&this[Be]!==0)super.emit("readable");else if(am(t)&&this[on])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[ti]){let i=e;this[Tt]?ii(()=>i.call(this,this[ti])):i.call(this,this[ti])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Cn]=this.listeners("data").length,this[Cn]===0&&!this[et]&&!this[Ke].length&&(this[Le]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Cn]=0,!this[et]&&!this[Ke].length&&(this[Le]=!1)),e}get emittedEnd(){return this[on]}[Gt](){!this[gs]&&!this[on]&&!this[Se]&&this[Me].length===0&&this[Ut]&&(this[gs]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[ms]&&this.emit("close"),this[gs]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Se&&this[Se])return!1;if(t==="data")return!this[je]&&!r?!1:this[Tt]?(ii(()=>this[Pa](r)),!0):this[Pa](r);if(t==="end")return this[du]();if(t==="close"){if(this[ms]=!0,!this[on]&&!this[Se])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[ti]=r,super.emit(ka,r);let o=!this[ri]||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}[Pa](t){for(let r of this[Ke])r.dest.write(t)===!1&&this.pause();let e=this[et]?!1:super.emit("data",t);return this[Gt](),e}[du](){return this[on]?!1:(this[on]=!0,this.readable=!1,this[Tt]?(ii(()=>this[Oa]()),!0):this[Oa]())}[Oa](){if(this[cr]){let e=this[cr].end();if(e){for(let r of this[Ke])r.dest.write(e);this[et]||super.emit("data",e)}}for(let e of this[Ke])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[je]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[je]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[je])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(Se,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[et]=!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",u),this.off(Se,x),e(),o(p)},l=p=>{this.off("error",c),this.off("end",u),this.off(Se,x),this.pause(),i({value:p,done:!!this[Ut]})},u=()=>{this.off("error",c),this.off("data",l),this.off(Se,x),e(),i({done:!0,value:void 0})},x=()=>c(new Error("stream destroyed"));return new Promise((p,w)=>{o=w,i=p,this.once(Se,x),this.once("error",c),this.once("end",u),this.once("data",l)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[et]=!1;let t=!1,e=()=>(this.pause(),this.off(ka,e),this.off(Se,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(ka,e),this.once(Se,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Se])return t?this.emit("error",t):this.emit(Se),this;this[Se]=!0,this[et]=!0,this[Me].length=0,this[Be]=0;let e=this;return typeof e.close=="function"&&!this[ms]&&e.close(),t?this.emit("error",t):this.emit(Se),this}static get isStream(){return rm}},xm=Je.writev,gn=Symbol("_autoClose"),_t=Symbol("_close"),si=Symbol("_ended"),ae=Symbol("_fd"),La=Symbol("_finished"),Wt=Symbol("_flags"),Ma=Symbol("_flush"),nc=Symbol("_handleChunk"),rc=Symbol("_makeBuf"),gi=Symbol("_mode"),Es=Symbol("_needDrain"),wr=Symbol("_onerror"),_r=Symbol("_onopen"),Ba=Symbol("_onread"),hr=Symbol("_onwrite"),mn=Symbol("_open"),wt=Symbol("_path"),un=Symbol("_pos"),Ct=Symbol("_queue"),pr=Symbol("_read"),za=Symbol("_readSize"),jt=Symbol("_reading"),oi=Symbol("_remain"),Fa=Symbol("_size"),ks=Symbol("_write"),Dn=Symbol("_writing"),Ps=Symbol("_defaultFlag"),Mn=Symbol("_errored"),Sc=class extends Un{[Mn]=!1;[ae];[wt];[za];[jt]=!1;[Fa];[oi];[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[za]=e.readSize||16*1024*1024,this[jt]=!1,this[Fa]=typeof e.size=="number"?e.size:1/0,this[oi]=this[Fa],this[gn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[ae]=="number"?this[pr]():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](){Je.open(this[wt],"r",(t,e)=>this[_r](t,e))}[_r](t,e){t?this[wr](t):(this[ae]=e,this.emit("open",e),this[pr]())}[rc](){return Buffer.allocUnsafe(Math.min(this[za],this[oi]))}[pr](){if(!this[jt]){this[jt]=!0;let t=this[rc]();if(t.length===0)return process.nextTick(()=>this[Ba](null,0,t));Je.read(this[ae],t,0,t.length,null,(e,r,i)=>this[Ba](e,r,i))}}[Ba](t,e,r){this[jt]=!1,t?this[wr](t):this[nc](e,r)&&this[pr]()}[_t](){if(this[gn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Je.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[wr](t){this[jt]=!0,this[_t](),this.emit("error",t)}[nc](t,e){let r=!1;return this[oi]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[oi]<=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[pr](),!1;case"error":return this[Mn]?!1:(this[Mn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},hm=class extends Sc{[mn](){let t=!0;try{this[_r](null,Je.openSync(this[wt],"r")),t=!1}finally{t&&this[_t]()}}[pr](){let t=!0;try{if(!this[jt]){this[jt]=!0;do{let e=this[rc](),r=e.length===0?0:Je.readSync(this[ae],e,0,e.length,null);if(!this[nc](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,Je.closeSync(t),this.emit("close")}}},$s=class extends tm{readable=!1;writable=!0;[Mn]=!1;[Dn]=!1;[si]=!1;[Ct]=[];[Es]=!1;[wt];[gi];[gn];[ae];[Ps];[Wt];[La]=!1;[un];constructor(t,e){e=e||{},super(e),this[wt]=t,this[ae]=typeof e.fd=="number"?e.fd:void 0,this[gi]=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[Ps]=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]}[wr](t){this[_t](),this[Dn]=!0,this.emit("error",t)}[mn](){Je.open(this[wt],this[Wt],this[gi],(t,e)=>this[_r](t,e))}[_r](t,e){this[Ps]&&this[Wt]==="r+"&&t&&t.code==="ENOENT"?(this[Wt]="w",this[mn]()):t?this[wr](t):(this[ae]=e,this.emit("open",e),this[Dn]||this[Ma]())}end(t,e){return t&&this.write(t,e),this[si]=!0,!this[Dn]&&!this[Ct].length&&typeof this[ae]=="number"&&this[hr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[si]?(this.emit("error",new Error("write() after end()")),!1):this[ae]===void 0||this[Dn]||this[Ct].length?(this[Ct].push(t),this[Es]=!0,!1):(this[Dn]=!0,this[ks](t),!0)}[ks](t){Je.write(this[ae],t,0,t.length,this[un],(e,r)=>this[hr](e,r))}[hr](t,e){t?this[wr](t):(this[un]!==void 0&&typeof e=="number"&&(this[un]+=e),this[Ct].length?this[Ma]():(this[Dn]=!1,this[si]&&!this[La]?(this[La]=!0,this[_t](),this.emit("finish")):this[Es]&&(this[Es]=!1,this.emit("drain"))))}[Ma](){if(this[Ct].length===0)this[si]&&this[hr](null,0);else if(this[Ct].length===1)this[ks](this[Ct].pop());else{let t=this[Ct];this[Ct]=[],xm(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,Je.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},qu=class extends $s{[mn](){let t;if(this[Ps]&&this[Wt]==="r+")try{t=Je.openSync(this[wt],this[Wt],this[gi])}catch(e){if(e?.code==="ENOENT")return this[Wt]="w",this[mn]();throw e}else t=Je.openSync(this[wt],this[Wt],this[gi]);this[_r](null,t)}[_t](){if(this[gn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Je.closeSync(t),this.emit("close")}}[ks](t){let e=!0;try{this[hr](null,Je.writeSync(this[ae],t,0,t.length,this[un])),e=!1}finally{if(e)try{this[_t]()}catch{}}}},mm=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"]]),wm=t=>!!t.sync&&!!t.file,_m=t=>!t.sync&&!!t.file,ym=t=>!!t.sync&&!t.file,Em=t=>!t.sync&&!t.file,bm=t=>!!t.file,vm=t=>mm.get(t)||t,Ic=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=vm(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ii=(t,e,r,i,o)=>Object.assign((c=[],l,u)=>{Array.isArray(c)&&(l=c,c={}),typeof l=="function"&&(u=l,l=void 0),l=l?Array.from(l):[];let x=Ic(c);if(o?.(x,l),wm(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(x,l)}else if(_m(x)){let p=e(x,l);return u?p.then(()=>u(),u):p}else if(ym(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(x,l)}else if(Em(x)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(x,l)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),Am=Im.constants||{ZLIB_VERNUM:4736},Pt=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},Am)),Tm=Bn.concat,uu=Object.getOwnPropertyDescriptor(Bn,"concat"),Cm=t=>t,Ua=uu?.writable===!0||uu?.set!==void 0?t=>{Bn.concat=t?Cm:Tm}:t=>{},zn=Symbol("_superWrite"),bs=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"}},Ga=Symbol("flushFlag"),Ac=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 lu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new lu[e](t)}catch(r){throw new bs(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 bs(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return ic(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),{[Ga]: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;ic(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},Ua(!0);let l;try{let x=typeof t[Ga]=="number"?t[Ga]:this.#r;l=this.#t._processChunk(t,x),Ua(!1)}catch(x){Ua(!1),this.#o(new bs(x,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",x=>this.#o(new bs(x,this.write)));let u;if(l)if(Array.isArray(l)&&l.length>0){let x=l[0];u=this[zn](Bn.from(x));for(let p=1;p<l.length;p++)u=this[zn](l[p])}else u=this[zn](Bn.from(l));return r&&r(),u}},ju=class extends Ac{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Pt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Pt.Z_FINISH,t.fullFlushFlag=Pt.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(Pt.Z_SYNC_FLUSH),ic(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)}}}},Dm=class extends ju{#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)}},Rm=class extends ju{constructor(t){super(t,"Unzip")}},Wu=class extends Ac{constructor(t,e){t=t||{},t.flush=t.flush||Pt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Pt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Pt.BROTLI_OPERATION_FLUSH,super(t,e)}},km=class extends Wu{constructor(t){super(t,"BrotliCompress")}},Pm=class extends Wu{constructor(t){super(t,"BrotliDecompress")}},Ku=class extends Ac{constructor(t,e){t=t||{},t.flush=t.flush||Pt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Pt.ZSTD_e_end,t.fullFlushFlag=Pt.ZSTD_e_flush,super(t,e)}},Om=class extends Ku{constructor(t){super(t,"ZstdCompress")}},Nm=class extends Ku{constructor(t){super(t,"ZstdDecompress")}},Lm=(t,e)=>{if(Number.isSafeInteger(t))t<0?Bm(t,e):Mm(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Mm=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},Bm=(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]=$u(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Vu(o))}},zm=t=>{let e=t[0],r=e===128?Um(t.subarray(1,t.length)):e===255?Fm(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},Fm=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),l;i?l=$u(c):c===0?l=c:(i=!0,l=Vu(c)),l!==0&&(r-=l*Math.pow(256,e-o-1))}return r},Um=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},$u=t=>(255^t)&255,Vu=t=>(255^t)+1&255,Gm={};em(Gm,{code:()=>Tc,isCode:()=>Os,isName:()=>qm,name:()=>Vs});var Os=t=>Vs.has(t),qm=t=>Tc.has(t),Vs=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"]]),Tc=new Map(Array.from(Vs).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??Rn(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??qa(t,e+136,12),this.cksum=fn(t,e+148,12),i&&this.#n(i,!0),r&&this.#n(r);let o=Rn(t,e+156,1);if(Os(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??fn(t,e+329,8)??0,this.devmin=r?.devmin??i?.devmin??fn(t,e+337,8)??0,t[e+475]!==0){let l=Rn(t,e+345,155);this.path=l+"/"+this.path}else{let l=Rn(t,e+345,130);l&&(this.path=l+"/"+this.path),this.atime=r?.atime??i?.atime??qa(t,e+476,12),this.ctime=r?.ctime??i?.ctime??qa(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=Hm(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=kn(t,e,100,o)||this.needPax,this.needPax=xn(t,e+100,8,this.mode)||this.needPax,this.needPax=xn(t,e+108,8,this.uid)||this.needPax,this.needPax=xn(t,e+116,8,this.gid)||this.needPax,this.needPax=xn(t,e+124,12,this.size)||this.needPax,this.needPax=Ha(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=xn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=xn(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=Ha(t,e+476,12,this.atime)||this.needPax,this.needPax=Ha(t,e+488,12,this.ctime)||this.needPax);let l=256;for(let u=e;u<e+148;u++)l+=t[u];for(let u=e+156;u<e+512;u++)l+=t[u];return this.cksum=l,xn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:Vs.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Tc.get(t));if(Os(e)||e==="Unsupported")this.#e=e;else if(Os(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Hm=(t,e)=>{let r=t,i="",o,c=dr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=dr.dirname(r),r=dr.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=dr.join(dr.basename(i),r),i=dr.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.*/,""),qa=(t,e,r)=>jm(fn(t,e,r)),jm=t=>t===void 0?void 0:new Date(t*1e3),fn=(t,e,r)=>Number(t[e])&128?zm(t.subarray(e,e+r)):Km(t,e,r),Wm=t=>isNaN(t)?void 0:t,Km=(t,e,r)=>Wm(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),$m={12:8589934591,8:2097151},xn=(t,e,r,i)=>i===void 0?!1:i>$m[r]||i<0?(Lm(i,t.subarray(e,e+r)),!0):(Vm(t,e,r,i),!1),Vm=(t,e,r,i)=>t.write(Zm(i,r),e,r,"ascii"),Zm=(t,e)=>Ym(Math.floor(t).toString(8),e),Ym=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Ha=(t,e,r,i)=>i===void 0?!1:xn(t,e,r,i.getTime()/1e3),Jm=new Array(156).join("\0"),kn=(t,e,r,i)=>i===void 0?!1:(t.write(i+Jm,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),qs=class Zu{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/"+Xm(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 Zu(Qm(ew(e),r),i)}},Qm=(t,e)=>e?Object.assign({},e,t):t,ew=t=>t.replace(/\n$/,"").split(`
91
+ `).reduce(tw,Object.create(null)),tw=(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},nw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Z=nw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),Yu=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=Z(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?Z(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=Z(t.path)),t.linkpath&&(t.linkpath=Z(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},Zs=(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))},rw=1024*1024,sc=Buffer.from([31,139]),oc=Buffer.from([40,181,47,253]),iw=Math.max(sc.length,oc.length),at=Symbol("state"),Pn=Symbol("writeEntry"),qt=Symbol("readEntry"),ja=Symbol("nextEntry"),fu=Symbol("processEntry"),Dt=Symbol("extendedHeader"),ai=Symbol("globalExtendedHeader"),an=Symbol("meta"),xu=Symbol("emitMeta"),fe=Symbol("buffer"),Ht=Symbol("queue"),cn=Symbol("ended"),Wa=Symbol("emittedEnd"),On=Symbol("emit"),Te=Symbol("unzip"),vs=Symbol("consumeChunk"),Ss=Symbol("consumeChunkSub"),Ka=Symbol("consumeBody"),hu=Symbol("consumeMeta"),pu=Symbol("consumeHeader"),ci=Symbol("consuming"),$a=Symbol("bufferConcat"),Is=Symbol("maybeEnd"),lr=Symbol("writing"),dn=Symbol("aborted"),As=Symbol("onDone"),Nn=Symbol("sawValidEntry"),Ts=Symbol("sawNullBlock"),Cs=Symbol("sawEOF"),gu=Symbol("closeStream"),sw=()=>!0,Si=class extends Sm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Ht]=[];[fe];[qt];[Pn];[at]="begin";[an]="";[Dt];[ai];[cn]=!1;[Te];[dn]=!1;[Nn];[Ts]=!1;[Cs]=!1;[lr]=!1;[ci]=!1;[Wa]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(As,()=>{(this[at]==="begin"||this[Nn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(As,t.ondone):this.on(As,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||rw,this.filter=typeof t.filter=="function"?t.filter:sw;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[gu]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){Zs(this,t,e,r)}[pu](t,e){this[Nn]===void 0&&(this[Nn]=!1);let r;try{r=new Fn(t,e,this[Dt],this[ai])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Ts]?(this[Cs]=!0,this[at]==="begin"&&(this[at]="header"),this[On]("eof")):(this[Ts]=!0,this[On]("nullBlock"));else if(this[Ts]=!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[Pn]=new Yu(r,this[Dt],this[ai]);if(!this[Nn])if(o.remain){let c=()=>{o.invalid||(this[Nn]=!0)};o.on("end",c)}else this[Nn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[On]("ignoredEntry",o),this[at]="ignore",o.resume()):o.size>0&&(this[an]="",o.on("data",c=>this[an]+=c),this[at]="meta"):(this[Dt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[On]("ignoredEntry",o),this[at]=o.remain?"ignore":"header",o.resume()):(o.remain?this[at]="body":(this[at]="header",o.end()),this[qt]?this[Ht].push(o):(this[Ht].push(o),this[ja]())))}}}[gu](){queueMicrotask(()=>this.emit("close"))}[fu](t){let e=!0;if(!t)this[qt]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[qt]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[ja]()),e=!1);return e}[ja](){do;while(this[fu](this[Ht].shift()));if(this[Ht].length===0){let t=this[qt];!t||t.flowing||t.size===t.remain?this[lr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Ka](t,e){let r=this[Pn];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[at]="header",this[Pn]=void 0,r.end()),o.length}[hu](t,e){let r=this[Pn],i=this[Ka](t,e);return!this[Pn]&&r&&this[xu](r),i}[On](t,e,r){this[Ht].length===0&&!this[qt]?this.emit(t,e,r):this[Ht].push([t,e,r])}[xu](t){switch(this[On]("meta",this[an]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Dt]=qs.parse(this[an],this[Dt],!1);break;case"GlobalExtendedHeader":this[ai]=qs.parse(this[an],this[ai],!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[Te]===void 0||this.brotli===void 0&&this[Te]===!1)&&t){if(this[fe]&&(t=Buffer.concat([this[fe],t]),this[fe]=void 0),t.length<iw)return this[fe]=t,r?.(),!0;for(let l=0;this[Te]===void 0&&l<sc.length;l++)t[l]!==sc[l]&&(this[Te]=!1);let o=!1;if(this[Te]===!1&&this.zstd!==!1){o=!0;for(let l=0;l<oc.length;l++)if(t[l]!==oc[l]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Te]===!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[Te]===void 0||this[Te]===!1&&(this.brotli||o)){let l=this[cn];this[cn]=!1,this[Te]=this[Te]===void 0?new Rm({}):o?new Nm({}):new Pm({}),this[Te].on("data",x=>this[vs](x)),this[Te].on("error",x=>this.abort(x)),this[Te].on("end",()=>{this[cn]=!0,this[vs]()}),this[lr]=!0;let u=!!this[Te][l?"end":"write"](t);return this[lr]=!1,r?.(),u}}this[lr]=!0,this[Te]?this[Te].write(t):this[vs](t),this[lr]=!1;let i=this[Ht].length>0?!1:this[qt]?this[qt].flowing:!0;return!i&&this[Ht].length===0&&this[qt]?.once("drain",()=>this.emit("drain")),r?.(),i}[$a](t){t&&!this[dn]&&(this[fe]=this[fe]?Buffer.concat([this[fe],t]):t)}[Is](){if(this[cn]&&!this[Wa]&&!this[dn]&&!this[ci]){this[Wa]=!0;let t=this[Pn];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[On](As)}}[vs](t){if(this[ci]&&t)this[$a](t);else if(!t&&!this[fe])this[Is]();else if(t){if(this[ci]=!0,this[fe]){this[$a](t);let e=this[fe];this[fe]=void 0,this[Ss](e)}else this[Ss](t);for(;this[fe]&&this[fe]?.length>=512&&!this[dn]&&!this[Cs];){let e=this[fe];this[fe]=void 0,this[Ss](e)}this[ci]=!1}(!this[fe]||this[cn])&&this[Is]()}[Ss](t){let e=0,r=t.length;for(;e+512<=r&&!this[dn]&&!this[Cs];)switch(this[at]){case"begin":case"header":this[pu](t,e),e+=512;break;case"ignore":case"body":e+=this[Ka](t,e);break;case"meta":e+=this[hu](t,e);break;default:throw new Error("invalid state: "+this[at])}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[Te]?(t&&this[Te].write(t),this[Te].end()):(this[cn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Is]())),this}},mi=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)},ow=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=>[mi(c),!0])),i=t.filter,o=(c,l="")=>{let u=l||gm(c).root||".",x;if(c===u)x=!1;else{let p=r.get(c);x=p!==void 0?p:o(pm(c),u)}return r.set(c,x),x};t.filter=i?(c,l)=>i(c,l)&&o(mi(c)):c=>o(mi(c))},aw=t=>{let e=new Si(t),r=t.file,i;try{i=gr.openSync(r,"r");let o=gr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let l=Buffer.allocUnsafe(o.size),u=gr.readSync(i,l,0,o.size,0);e.end(u===l.byteLength?l:l.subarray(0,u))}else{let l=0,u=Buffer.allocUnsafe(c);for(;l<o.size;){let x=gr.readSync(i,u,0,c,l);if(x===0)break;l+=x,e.write(u.subarray(0,x))}e.end()}}finally{if(typeof i=="number")try{gr.closeSync(i)}catch{}}},cw=(t,e)=>{let r=new Si(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("end",c),gr.stat(o,(u,x)=>{if(u)l(u);else{let p=new Sc(o,{readSize:i,size:x.size});p.on("error",l),p.pipe(r)}})})},yr=Ii(aw,cw,t=>new Si(t),t=>new Si(t),(t,e)=>{e?.length&&Ju(t,e),t.noResume||ow(t)}),Xu=(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:lw,parse:wu}=dw,Cc=t=>{let e="",r=wu(t);for(;lw(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=wu(t)}return[e,t]},Ys=["|","<",">","?",":"],Dc=Ys.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),uw=new Map(Ys.map((t,e)=>[t,Dc[e]])),fw=new Map(Dc.map((t,e)=>[t,Ys[e]])),_u=t=>Ys.reduce((e,r)=>e.split(r).join(uw.get(r)),t),xw=t=>Dc.reduce((e,r)=>e.split(r).join(fw.get(r)),t),Qu=(t,e)=>e?(t=Z(t).replace(/^\.(\/|$)/,""),mi(e)+"/"+t):Z(t),hw=16*1024*1024,yu=Symbol("process"),Eu=Symbol("file"),bu=Symbol("directory"),ac=Symbol("symlink"),vu=Symbol("hardlink"),di=Symbol("header"),Ns=Symbol("read"),cc=Symbol("lstat"),Ls=Symbol("onlstat"),dc=Symbol("onread"),lc=Symbol("onreadlink"),uc=Symbol("openfile"),fc=Symbol("onopenfile"),hn=Symbol("close"),js=Symbol("mode"),xc=Symbol("awaitDrain"),Va=Symbol("ondrain"),kt=Symbol("prefix"),e0=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=Ic(e);super(),this.path=Z(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||hw,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=Z(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?Z(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]=Cc(this.path);c&&typeof l=="string"&&(this.path=l,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=xw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=Z(r.absolute||mu.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[Ls](o):this[cc]()}warn(t,e,r={}){return Zs(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[cc](){Rt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Ls](e)})}[Ls](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=mw(t),this.emit("stat",t),this[yu]()}[yu](){switch(this.type){case"File":return this[Eu]();case"Directory":return this[bu]();case"SymbolicLink":return this[ac]();default:return this.end()}}[js](t){return Xu(t,this.type==="Directory",this.portable)}[kt](t){return Qu(t,this.prefix)}[di](){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[kt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[kt](this.linkpath):this.linkpath,mode:this[js](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 qs({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[kt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[kt](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)}[bu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[di](),this.end()}[ac](){Rt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[lc](e)})}[lc](t){this.linkpath=Z(t),this[di](),this.end()}[vu](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=Z(mu.relative(this.cwd,t)),this.stat.size=0,this[di](),this.end()}[Eu](){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[vu](e);this.linkCache.set(t,this.absolute)}if(this[di](),this.stat.size===0)return this.end();this[uc]()}[uc](){Rt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[fc](e)})}[fc](t){if(this.fd=t,this.#e)return this[hn]();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[Ns]()}[Ns](){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[hn](()=>this.emit("error",c));this[dc](l)})}[hn](t=()=>{}){this.fd!==void 0&&Rt.close(this.fd,t)}[dc](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[hn](()=>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[hn](()=>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[Va]():this[xc](()=>this[Va]())}[xc](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)}[Va](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[hn](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[Ns]()}},pw=class extends e0{sync=!0;[cc](){this[Ls](Rt.lstatSync(this.absolute))}[ac](){this[lc](Rt.readlinkSync(this.absolute))}[uc](){this[fc](Rt.openSync(this.absolute,"r"))}[Ns](){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[dc](l),t=!1}finally{if(t)try{this[hn](()=>{})}catch{}}}[xc](t){t()}[hn](t=()=>{}){this.fd!==void 0&&Rt.closeSync(this.fd),t()}},gw=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 Zs(this,t,e,r)}constructor(t,e={}){let r=Ic(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=Z(t.path),this.mode=t.mode!==void 0?this[js](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?Z(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[l,u]=Cc(this.path);l&&typeof u=="string"&&(this.path=u,o=l)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Fn({path:this[kt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[kt](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 qs({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[kt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[kt](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)}[kt](t){return Qu(t,this.prefix)}[js](t){return Xu(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}},mw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",ww=class mr{tail;head;length=0;static create(e=[]){return new mr(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++)yw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)Ew(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 mr;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 mr;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 mr;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 mr;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=_w(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 _w(t,e,r){let i=e,o=e?e.next:t.head,c=new Rc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function yw(t,e){t.tail=new Rc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function Ew(t,e){t.head=new Rc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Rc=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}},Iu=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Au=Buffer.alloc(1024),Ms=Symbol("onStat"),li=Symbol("ended"),gt=Symbol("queue"),ui=Symbol("queue"),ln=Symbol("current"),Ln=Symbol("process"),fi=Symbol("processing"),Ds=Symbol("processJob"),mt=Symbol("jobs"),Za=Symbol("jobDone"),Bs=Symbol("addFSEntry"),Tu=Symbol("addTarEntry"),hc=Symbol("stat"),pc=Symbol("readdir"),zs=Symbol("onreaddir"),Fs=Symbol("pipe"),Cu=Symbol("entry"),Ya=Symbol("entryOpt"),Us=Symbol("writeEntryClass"),t0=Symbol("write"),Ja=Symbol("ondrain"),Js=class extends Un{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Us];onWriteEntry;[gt];[ui]=new Map;[mt]=0;[fi]=!1;[li]=!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=Z(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[Us]=e0,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 Dm(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new km(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new Om(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[Ja]()),this.on("resume",()=>e.resume())}else this.on("drain",this[Ja]);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 ww,this[mt]=0,this.jobs=Number(t.jobs)||4,this[fi]=!1,this[li]=!1}[t0](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[li]=!0,this[Ln](),r&&r(),this}write(t){if(this[li])throw new Error("write after end");return t instanceof Yu?this[Tu](t):this[Bs](t),this.flowing}[Tu](t){let e=Z(Su.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Iu(t.path,e);r.entry=new gw(t,this[Ya](r)),r.entry.on("end",()=>this[Za](r)),this[mt]+=1,this[gt].push(r)}this[Ln]()}[Bs](t){let e=Z(Su.resolve(this.cwd,t));this[gt].push(new Iu(t,e)),this[Ln]()}[hc](t){t.pending=!0,this[mt]+=1;let e=this.follow?"stat":"lstat";Hs[e](t.absolute,(r,i)=>{t.pending=!1,this[mt]-=1,r?this.emit("error",r):this[Ms](t,i)})}[Ms](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[Ds](t);else{let r=`${e.dev}:${e.ino}`,i=this[ui].get(r);i?i.push(t):this[ui].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Ln]()}[pc](t){t.pending=!0,this[mt]+=1,Hs.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[mt]-=1,e)return this.emit("error",e);this[zs](t,r)})}[zs](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Ln]()}[Ln](){if(!this[fi]){this[fi]=!0;for(let t=this[gt].head;t&&this[mt]<this.jobs;t=t.next)if(this[Ds](t.value),t.value.ignore){let e=t.next;this[gt].removeNode(t),t.next=e}this[fi]=!1,this[li]&&this[gt].length===0&&this[mt]===0&&(this.zip?this.zip.end(Au):(super.write(Au),super.end()))}}get[ln](){return this[gt]&&this[gt].head&&this[gt].head.value}[Za](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[ui].get(r);if(i){this[ui].delete(r);for(let o of i)o.pending=!1,this[Ds](o)}}this[Ln]()}[Ds](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[Fs](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Ms](t,e):this[hc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[zs](t,e):this[pc](t),!t.readdir)return}if(t.entry=this[Cu](t),!t.entry){t.ignore=!0;return}t===this[ln]&&!t.piped&&this[Fs](t)}}}[Ya](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}}[Cu](t){this[mt]+=1;try{return new this[Us](t.path,this[Ya](t)).on("end",()=>this[Za](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[Ja](){this[ln]&&this[ln].entry&&this[ln].entry.resume()}[Fs](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Bs](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={}){Zs(this,t,e,r)}},kc=class extends Js{sync=!0;constructor(t){super(t),this[Us]=pw}pause(){}resume(){}[hc](t){let e=this.follow?"statSync":"lstatSync";this[Ms](t,Hs[e](t.absolute))}[pc](t){this[zs](t,Hs.readdirSync(t.absolute))}[Fs](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Bs](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[t0](i)})}},bw=(t,e)=>{let r=new kc(t),i=new qu(t.file,{mode:t.mode||438});r.pipe(i),n0(r,e)},vw=(t,e)=>{let r=new Js(t),i=new $s(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 r0(r,e).catch(c=>r.emit("error",c)),o},n0=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?yr({file:Hu.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},r0=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await yr({file:Hu.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},Sw=(t,e)=>{let r=new kc(t);return n0(r,e),r},Iw=(t,e)=>{let r=new Js(t);return r0(r,e).catch(i=>r.emit("error",i)),r},K2=Ii(bw,vw,Sw,Iw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),Tw=process.env.__FAKE_PLATFORM__||process.platform,a0=Tw==="win32",{O_CREAT:c0,O_NOFOLLOW:Du,O_TRUNC:d0,O_WRONLY:l0}=o0.constants,u0=Number(process.env.__FAKE_FS_O_FILENAME__)||o0.constants.UV_FS_O_FILEMAP||0,Cw=a0&&!!u0,Dw=512*1024,Rw=u0|d0|c0|l0,Ru=!a0&&typeof Du=="number"?Du|d0|c0|l0:null,f0=Ru!==null?()=>Ru:Cw?t=>t<Dw?Rw:"w":()=>"w",gc=(t,e,r)=>{try{return Xs.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},Ws=(t,e,r,i)=>{Xs.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},kw=(t,e,r,i,o)=>{if(e.isDirectory())x0(wi.resolve(t,e.name),r,i,c=>{if(c)return o(c);let l=wi.resolve(t,e.name);Ws(l,r,i,o)});else{let c=wi.resolve(t,e.name);Ws(c,r,i,o)}},x0=(t,e,r,i)=>{Xs.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 Ws(t,e,r,i);let l=c.length,u=null,x=p=>{if(!u){if(p)return i(u=p);if(--l===0)return Ws(t,e,r,i)}};for(let p of c)kw(t,p,e,r,x)})},Pw=(t,e,r,i)=>{e.isDirectory()&&h0(wi.resolve(t,e.name),r,i),gc(wi.resolve(t,e.name),r,i)},h0=(t,e,r)=>{let i;try{i=Xs.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return gc(t,e,r);throw c}for(let o of i)Pw(t,o,e,r);return gc(t,e,r)},p0=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"}},Qs=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"}},Nw=(t,e)=>{rt.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new p0(t,r?.code||"ENOTDIR")),e(r)})},Lw=(t,e,r)=>{t=Z(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,l=e.uid,u=e.gid,x=typeof l=="number"&&typeof u=="number"&&(l!==e.processUid||u!==e.processGid),p=e.preserve,w=e.unlink,_=Z(e.cwd),S=(b,A)=>{b?r(b):A&&x?x0(A,l,u,I=>S(I)):c?rt.chmod(t,o,r):r()};if(t===_)return Nw(t,S);if(p)return Ow.mkdir(t,{mode:o,recursive:!0}).then(b=>S(null,b??void 0),S);let E=Z(Ks.relative(_,t)).split("/");mc(_,E,o,w,_,void 0,S)},mc=(t,e,r,i,o,c,l)=>{if(e.length===0)return l(null,c);let u=e.shift(),x=Z(Ks.resolve(t+"/"+u));rt.mkdir(x,r,g0(x,e,r,i,o,c,l))},g0=(t,e,r,i,o,c,l)=>u=>{u?rt.lstat(t,(x,p)=>{if(x)x.path=x.path&&Z(x.path),l(x);else if(p.isDirectory())mc(t,e,r,i,o,c,l);else if(i)rt.unlink(t,w=>{if(w)return l(w);rt.mkdir(t,r,g0(t,e,r,i,o,c,l))});else{if(p.isSymbolicLink())return l(new Qs(t,t+"/"+e.join("/")));l(u)}}):(c=c||t,mc(t,e,r,i,o,c,l))},Mw=t=>{let e=!1,r;try{e=rt.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new p0(t,r??"ENOTDIR")}},Bw=(t,e)=>{t=Z(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,l=e.gid,u=typeof c=="number"&&typeof l=="number"&&(c!==e.processUid||l!==e.processGid),x=e.preserve,p=e.unlink,w=Z(e.cwd),_=b=>{b&&u&&h0(b,c,l),o&&rt.chmodSync(t,i)};if(t===w)return Mw(w),_();if(x)return _(rt.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=Z(Ks.relative(w,t)).split("/"),E;for(let b=S.shift(),A=w;b&&(A+="/"+b);b=S.shift()){A=Z(Ks.resolve(A));try{rt.mkdirSync(A,i),E=E||A}catch{let I=rt.lstatSync(A);if(I.isDirectory())continue;if(p){rt.unlinkSync(A),rt.mkdirSync(A,i),E=E||A;continue}else if(I.isSymbolicLink())return new Qs(A,A+"/"+S.join("/"))}}return _(E)},Xa=Object.create(null),ku=1e4,ur=new Set,zw=t=>{ur.has(t)?ur.delete(t):Xa[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),ur.add(t);let e=Xa[t],r=ur.size-ku;if(r>ku/10){for(let i of ur)if(ur.delete(i),delete Xa[i],--r<=0)break}return e},Fw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Uw=Fw==="win32",Gw=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=m0(i,r)),e.push(r||"/"),e},[]),qw=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=Uw?["win32 parallelization disabled"]:t.map(i=>mi(m0(zw(i))));let r=new Set(t.map(i=>Gw(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 u=l[1];if(!u){this.#e.delete(c);continue}if(l.shift(),typeof u=="function")o.add(u);else for(let x of u)o.add(x)}for(let c of i){let l=this.#e.get(c),u=l?.[0];if(!(!l||!(u instanceof Set)))if(u.size===1&&l.length===1){this.#e.delete(c);continue}else if(u.size===1){l.shift();let x=l[0];typeof x=="function"&&o.add(x)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},Hw=()=>process.umask(),Pu=Symbol("onEntry"),wc=Symbol("checkFs"),Ou=Symbol("checkFs2"),_c=Symbol("isReusable"),ct=Symbol("makeFs"),yc=Symbol("file"),Ec=Symbol("directory"),Gs=Symbol("link"),Nu=Symbol("symlink"),Lu=Symbol("hardlink"),pi=Symbol("ensureNoSymlink"),Mu=Symbol("unsupported"),Bu=Symbol("checkPath"),Qa=Symbol("stripAbsolutePath"),pn=Symbol("mkdir"),ze=Symbol("onError"),Rs=Symbol("pending"),zu=Symbol("pend"),fr=Symbol("unpend"),ec=Symbol("ended"),tc=Symbol("maybeClose"),bc=Symbol("skip"),_i=Symbol("doChown"),yi=Symbol("uid"),Ei=Symbol("gid"),bi=Symbol("checkedCwd"),jw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,vi=jw==="win32",Ww=1024,Kw=(t,e)=>{if(!vi)return re.unlink(t,e);let r=t+".DELETE."+s0(16).toString("hex");re.rename(t,r,i=>{if(i)return e(i);re.unlink(r,e)})},$w=t=>{if(!vi)return re.unlinkSync(t);let e=t+".DELETE."+s0(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},Fu=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Pc=class extends Si{[ec]=!1;[bi]=!1;[Rs]=0;reservations=new qw;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[ec]=!0,this[tc]()},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:Ww,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||vi,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=Z(Oe.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:Hw():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[Pu](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[tc](){this[ec]&&this[Rs]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[Qa](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Cc(r),l=c.replaceAll(/\\/g,"/").split("/");if(l.includes("..")||vi&&/^[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 u=Oe.posix.dirname(t.path),x=Oe.posix.normalize(Oe.posix.join(u,l.join("/")));if(x.startsWith("../")||x==="..")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}[Bu](t){let e=Z(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=Z(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[Qa](t,"path")||!this[Qa](t,"linkpath"))return!1;if(t.absolute=Oe.isAbsolute(t.path)?Z(Oe.resolve(t.path)):Z(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:Z(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+_u(String(t.absolute).slice(i.length));let{root:o}=Oe.win32.parse(t.path);t.path=o+_u(t.path.slice(o.length))}return!0}[Pu](t){if(!this[Bu](t))return t.resume();switch(Aw.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[wc](t);default:return this[Mu](t)}}[ze](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[fr](),e.resume())}[pn](t,e,r){Lw(Z(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)}[_i](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}[yi](t){return Fu(this.uid,t.uid,this.processUid)}[Ei](t){return Fu(this.gid,t.gid,this.processGid)}[yc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new $s(String(t.absolute),{flags:f0(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[ze](u,t),e()});let o=1,c=u=>{if(u){i.fd&&re.close(i.fd,()=>{}),this[ze](u,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,x=>{x?this[ze](x,t):this[fr](),e()})};i.on("finish",()=>{let u=String(t.absolute),x=i.fd;if(typeof x=="number"&&t.mtime&&!this.noMtime){o++;let p=t.atime||new Date,w=t.mtime;re.futimes(x,p,w,_=>_?re.utimes(u,p,w,S=>c(S&&_)):c())}if(typeof x=="number"&&this[_i](t)){o++;let p=this[yi](t),w=this[Ei](t);typeof p=="number"&&typeof w=="number"&&re.fchown(x,p,w,_=>_?re.chown(u,p,w,S=>c(S&&_)):c())}c()});let l=this.transform&&this.transform(t)||t;l!==t&&(l.on("error",u=>{this[ze](u,t),e()}),t.pipe(l)),l.pipe(i)}[Ec](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[fr](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[_i](t)&&(o++,re.chown(String(t.absolute),Number(this[yi](t)),Number(this[Ei](t)),c)),c()})}[Mu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Nu](t,e){let r=Z(Oe.relative(this.cwd,Oe.resolve(Oe.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[pi](t,this.cwd,r,()=>this[Gs](t,String(t.linkpath),"symlink",e),i=>{this[ze](i,t),e()})}[Lu](t,e){let r=Z(Oe.resolve(this.cwd,String(t.linkpath))),i=Z(String(t.linkpath)).split("/");this[pi](t,this.cwd,i,()=>this[Gs](t,r,"link",e),o=>{this[ze](o,t),e()})}[pi](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,(u,x)=>{if(u)return i();if(x?.isSymbolicLink())return o(new Qs(l,Oe.resolve(l,r.join("/"))));this[pi](t,l,r,i,o)})}[zu](){this[Rs]++}[fr](){this[Rs]--,this[tc]()}[bc](t){this[fr](),t.resume()}[_c](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!vi}[wc](t){this[zu]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Ou](t,r))}[Ou](t,e){let r=l=>{e(l)},i=()=>{this[pn](this.cwd,this.dmode,l=>{if(l){this[ze](l,t),r();return}this[bi]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let l=Z(Oe.dirname(String(t.absolute)));if(l!==this.cwd)return this[pn](l,this.dmode,u=>{if(u){this[ze](u,t),r();return}c()})}c()},c=()=>{re.lstat(String(t.absolute),(l,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[bc](t),r();return}if(l||this[_c](t,u))return this[ct](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let x=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,p=w=>this[ct](w??null,t,r);return x?re.chmod(String(t.absolute),Number(t.mode),p):p()}if(t.absolute!==this.cwd)return re.rmdir(String(t.absolute),x=>this[ct](x??null,t,r))}if(t.absolute===this.cwd)return this[ct](null,t,r);Kw(String(t.absolute),x=>this[ct](x??null,t,r))})};this[bi]?o():i()}[ct](t,e,r){if(t){this[ze](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[yc](e,r);case"Link":return this[Lu](e,r);case"SymbolicLink":return this[Nu](e,r);case"Directory":case"GNUDumpDir":return this[Ec](e,r)}}[Gs](t,e,r,i){re[r](e,String(t.absolute),o=>{o?this[ze](o,t):(this[fr](),t.resume()),i()})}},xi=t=>{try{return[null,t()]}catch(e){return[e,null]}},w0=class extends Pc{sync=!0;[ct](t,e){return super[ct](t,e,()=>{})}[wc](t){if(!this[bi]){let o=this[pn](this.cwd,this.dmode);if(o)return this[ze](o,t);this[bi]=!0}if(t.absolute!==this.cwd){let o=Z(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]=xi(()=>re.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[bc](t);if(e||this[_c](t,r))return this[ct](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[l]=c?xi(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ct](l,t)}let[o]=xi(()=>re.rmdirSync(String(t.absolute)));this[ct](o,t)}let[i]=t.absolute===this.cwd?[]:xi(()=>$w(String(t.absolute)));this[ct](i,t)}[yc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=l=>{let u;try{re.closeSync(o)}catch(x){u=x}(l||u)&&this[ze](l||u,t),e()},o;try{o=re.openSync(String(t.absolute),f0(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(u){i(u)}}),c.on("end",()=>{let l=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,x=t.mtime;try{re.futimesSync(o,u,x)}catch(p){try{re.utimesSync(String(t.absolute),u,x)}catch{l=p}}}if(this[_i](t)){let u=this[yi](t),x=this[Ei](t);try{re.fchownSync(o,Number(u),Number(x))}catch(p){try{re.chownSync(String(t.absolute),Number(u),Number(x))}catch{l=l||p}}}i(l)})}[Ec](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[_i](t))try{re.chownSync(String(t.absolute),Number(this[yi](t)),Number(this[Ei](t)))}catch{}e(),t.resume()}[pn](t,e){try{return Bw(Z(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}}[pi](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[u,x]=xi(()=>re.lstatSync(c));if(u)return i();if(x.isSymbolicLink())return o(new Qs(c,Oe.resolve(e,r.join("/"))))}i()}[Gs](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)}}},Vw=t=>{let e=new w0(t),r=t.file,i=i0.statSync(r),o=t.maxReadSize||16*1024*1024;new hm(r,{readSize:o,size:i.size}).pipe(e)},Zw=(t,e)=>{let r=new Pc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("close",c),i0.stat(o,(u,x)=>{if(u)l(u);else{let p=new Sc(o,{readSize:i,size:x.size});p.on("error",l),p.pipe(r)}})})},_0=Ii(Vw,Zw,t=>new w0(t),t=>new Pc(t),(t,e)=>{e?.length&&Ju(t,e)}),Yw=(t,e)=>{let r=new kc(t),i=!0,o,c;try{try{o=nt.openSync(t.file,"r+")}catch(x){if(x?.code==="ENOENT")o=nt.openSync(t.file,"w+");else throw x}let l=nt.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<l.size;c+=512){for(let w=0,_=0;w<512;w+=_){if(_=nt.readSync(o,u,w,u.length-w,c+w),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!_)break e}let x=new Fn(u);if(!x.cksumValid)break;let p=512*Math.ceil((x.size||0)/512);if(c+p+512>l.size)break;c+=p,t.mtimeCache&&x.mtime&&t.mtimeCache.set(String(x.path),x.mtime)}i=!1,Jw(t,r,c,o,e)}finally{if(i)try{nt.closeSync(o)}catch{}}},Jw=(t,e,r,i,o)=>{let c=new qu(t.file,{fd:i,start:r});e.pipe(c),Qw(e,o)},Xw=(t,e)=>{e=Array.from(e);let r=new Js(t),i=(o,c,l)=>{let u=(S,E)=>{S?nt.close(o,b=>l(S)):l(null,E)},x=0;if(c===0)return u(null,0);let p=0,w=Buffer.alloc(512),_=(S,E)=>{if(S||E===void 0)return u(S);if(p+=E,p<512&&E)return nt.read(o,w,p,w.length-p,x+p,_);if(x===0&&w[0]===31&&w[1]===139)return u(new Error("cannot append to compressed archives"));if(p<512)return u(null,x);let b=new Fn(w);if(!b.cksumValid)return u(null,x);let A=512*Math.ceil((b.size??0)/512);if(x+A+512>c||(x+=A+512,x>=c))return u(null,x);t.mtimeCache&&b.mtime&&t.mtimeCache.set(String(b.path),b.mtime),p=0,nt.read(o,w,0,512,x,_)};nt.read(o,w,0,512,x,_)};return new Promise((o,c)=>{r.on("error",c);let l="r+",u=(x,p)=>{if(x&&x.code==="ENOENT"&&l==="r+")return l="w+",nt.open(t.file,l,u);if(x||!p)return c(x);nt.fstat(p,(w,_)=>{if(w)return nt.close(p,()=>c(w));i(p,_.size,(S,E)=>{if(S)return c(S);let b=new $s(t.file,{fd:p,start:E});r.pipe(b),b.on("error",c),b.on("close",o),e_(r,e)})})};nt.open(t.file,l,u)})},Qw=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?yr({file:y0.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},e_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await yr({file:y0.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},hi=Ii(Yw,Xw,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!bm(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")}),aI=Ii(hi.syncFile,hi.asyncFile,hi.syncNoFile,hi.asyncNoFile,(t,e=[])=>{hi.validate?.(t,e),t_(t)}),t_=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 Ai(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function E0(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function Oc(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function b0(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function Er(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}We();ne();ke();We();function Kt(t,e){if(Ai(t)!=="cloud")throw new T("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function eo(t){return t.startsWith("http://")||t.startsWith("https://")}function to(t){return t.endsWith("/")?t.slice(0,-1):t}We();ne();var no="1008033",v0="1289";var S0="pbbp2",I0="https://www.coze.cn",A0="/api/coze_claw/resource/get_frontier_key",r_="https://www.coze.cn",i_="wss://frontier.coze.cn";function ro(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??r_}function T0(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??i_}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 Ci(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Ti=G("handshake");async function Nc(t){let e=ro(t.endpoint),r=t.timeoutMs??1e4,i=`${to(e)}${A0}?aid=${encodeURIComponent(no)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...br(t.ppeOverride)},c=new AbortController,l=setTimeout(()=>c.abort(),r);Ti.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),x=u.headers.get("x-tt-logid")??"",p=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let b=await u.text().catch(()=>"");throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${x}: ${b.slice(0,200)}`)}let w=await u.json();if(w.code!==void 0&&w.code!==0)throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${w.code} msg=${w.msg??"-"} logid=${x}`);let _=w.data??{},S=typeof _.access_key=="string"&&_.access_key||typeof _.accessKey=="string"&&_.accessKey||void 0,E=typeof _.device_id=="string"&&_.device_id||typeof _.deviceId=="string"&&_.deviceId||void 0;if(!S||!E){let b=JSON.stringify(w).slice(0,500);throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${x}: ${b}`)}return Ti.info("handshake ok",{remoteDeviceId:E,logid:x,traceId:p}),{accessKey:S,deviceId:E}}catch(u){if(u instanceof T)throw Ti.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Ti.warn("handshake timeout",{base:e,timeoutMs:r}),new T("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let x=u.cause;throw Ti.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:x?.code,syscall:x?.syscall,cause:String(u).slice(0,300)}),new T("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(l)}}var Lc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",Et="auto",C0=15e4;function D0(t){return{model:Mc(t.model)??Et,...t.modelToken?{modelToken:t.modelToken}:{}}}function R0(t){return!t||t===Et}var s_=new Set(["auto","\u81EA\u52A8"]);function Mc(t){let e=t?.trim();if(e)return s_.has(e.toLowerCase())?Et:e}function k0(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Lc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||Et;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 R0(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function P0(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||Et}"`):R0(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="${Lc}/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??C0;e.push("-c",`model_context_window=${r}`)}return e}function O0(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function Bc(t,e){let{ttEnv:r,usePpe:i}=Ci(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function N0(t,e,r){if(!t.modelToken)return{};let i=Bc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,l])=>`${c}:${l}`).join(`
92
+ `)}}function zc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function L0(t,e,r){if(!t.modelToken)return null;let i=t.model||Et,o=Bc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let l={baseUrl:`${Lc}/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??C0,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(l.headers=o),l}function M0(t,e,r){if(!t.modelToken)return[];let i=Bc(e,r),o=[];for(let[c,l]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${l}"`);return o}var Ne=G("agent-handlers"),B0=5*1024*1024,u_=1,f_=6,x_=new Set(["node_modules",".git",".coze","dist","build",".next"]),io=class{constructor(e){this.opts=e}opts;async listSkills(e){Kt(e._meta,"_agent/listSkills");let r=Er(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Ze(r).workspace,c=i?.skills??[],l=[];for(let u of c){let x=Ot(o,u.relPath,"SKILL.md");await c_(x).then(w=>w.isFile()).catch(()=>!1)&&l.push(w_(u))}return{skills:l}}async addSkills(e){Kt(e._meta,"_agent/addSkills");let r=Er(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],l=new Map(c.map((x,p)=>[x.skillId,p])),u=[];for(let x of o){let p=await Wc({agentId:r,workspace:i.workspace,framework:i.framework,skill:x});Kc(c,l,p),u.push(x)}return await ds(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){Kt(e._meta,"_agent/removeSkills");let r=Er(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],l=[];for(let u of c){if(!o.has(u.skillId)){l.push(u);continue}let x=Ot(i.workspace,u.relPath);await a_(x,{recursive:!0,force:!0}),Ne.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await ds(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,Ne.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l});continue}let x=c.downstream;c.downstream=void 0,Ne.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l}),x.stop(r).catch(p=>Ne.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 Ne.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 Ne.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await ir(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Ne.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 Ye(i),Ne.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 Ye(i),Ne.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}):(Ne.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(Kt(e._meta,"_agent/switchModel"),!e.agentId)throw new T("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Mc(e.model)??Et,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 Ye(i),Ne.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Ne.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=>Ne.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(l)}));let c=[];for(let[l,u]of o.allSessionQueues())c.push(u.enqueue(async()=>{let x=o.sessions.get(l);x?.downstream&&(await x.downstream.stop(`switchModel: ${r}`).catch(()=>{}),x.downstream=void 0)}));return await Promise.all(c),Ne.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 T("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),Ne.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 Qr(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 Ye(r)}async repairAgent(e){if(Kt(e._meta,yt.REPAIR),!e.agentId)throw new T("IPC_BAD_REQUEST",`${yt.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new T("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){Ne.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){Ne.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Ne.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=Er(r),o=await this.resolveWorkspace(i),c=e.filePath??"",l=this.safeJoin(o,c),u=await Fc(l).catch(()=>null);if(!u)throw new T("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await Xr(l,o))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let x=D_(e.depth);return u.isDirectory()?{tree:await C_(o,l,c,x)}:{tree:[{name:R_(c),path:j0(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){Kt(e._meta,"_agent/getFileContent");let r=Er(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 Fc(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 Xr(o,i))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>B0)throw new T("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${B0})`);let l=await z0(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 Ge(e).catch(()=>null))?.workspace??Ze(e).workspace}safeJoin(e,r){let i=qc(e,r||"."),o=jc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${F0}`))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 h_(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 p_(t){return t==="claude-code"?Ot(".claude","skills"):Ot(".agents","skills")}var g_=3e4,m_=50*1024*1024,vr=3e4;async function Wc(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,l=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!l)throw new T("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=h_(o.skillName),x=p_(i),p=Ot(x,u),w=Ot(r,p);if(await Uc(w,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");Di(S.length),await Gc(Ot(w,"SKILL.md"),S,"utf8")}else{let S=await __(o.downloadUrl);E_(S)?await I_(S,w):b_(S)?await v_(S,w):await Gc(Ot(w,"SKILL.md"),S.toString("utf8"),"utf8")}let _={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 Ne.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:p,source:c?"content":"downloadUrl"}),_}function Kc(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 w_(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 __(t){if(!t)throw new T("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Di(e);let r=y_(t);return Di(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await z0(e);return Di(r.length),r}if(eo(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),g_);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 Di(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 Di(t){if(t>m_)throw new T("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function y_(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 E_(t){return t.length>=2&&t[0]===31&&t[1]===139}function b_(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 Hc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function v_(t,e){let r,i;try{r=new q0.default(t),i=r.getEntries()}catch(l){throw new T("IPC_BAD_REQUEST",`zip parse failed: ${l.message}`,{cause:l})}for(let l of i){let u=l.entryName;if(!u||Hc(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new T("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(p=>p===".."))throw new T("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let x=l.header.attr>>>16&61440;if(x!==0&&x!==32768&&x!==16384)throw new T("IPC_BAD_REQUEST",`zip entry kind 0x${x.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=S_(i),c=qc(e);for(let l of i){if(Hc(l.entryName))continue;let u=l.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let x=qc(e,u),p=jc(c,x);if(p.startsWith("..")||p==="..")throw new T("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(l.isDirectory){await Uc(x,{recursive:!0});continue}await Uc(d_(x),{recursive:!0});let w;try{w=l.getData()}catch(_){throw new T("IPC_BAD_REQUEST",`zip entry getData failed (${l.entryName}): ${_.message}`,{cause:_})}await Gc(x,w)}}function S_(t){let e;for(let r of t){let i=r.entryName;if(!i||Hc(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 I_(t,e){await A_(t);let r=_0({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar extract timeout (${vr}ms)`))},vr);try{await G0(U0.from(t),r)}catch(c){throw c instanceof T?c:i?new T("IPC_BAD_REQUEST",`tar extract timeout (${vr}ms)`):new T("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function A_(t){let e=[],r=yr({onReadEntry:c=>{let l=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' 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 T("IPC_BAD_REQUEST",`tar list timeout (${vr}ms)`))},vr);try{await G0(U0.from(t),r)}catch(c){throw i?new T("IPC_BAD_REQUEST",`tar list timeout (${vr}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 T_=5e3;async function C_(t,e,r,i){return H0(t,e,r,i,{count:0})}async function H0(t,e,r,i,o){if(i<=0)return[];let c;try{c=await o_(e,{withFileTypes:!0})}catch{return[]}let l=[];for(let u of c){if(x_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=T_){l.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let x=Ot(e,u.name),p=l_(Ot(r,u.name)),w=null;try{w=await Fc(x)}catch{continue}if(w.isSymbolicLink())continue;o.count++;let _={name:u.name,path:j0(jc(t,x)),isDir:w.isDirectory(),size:w.size,modifiedAt:Math.floor(w.mtimeMs)};w.isDirectory()&&i>1&&(_.children=await H0(t,x,p,i-1,o)),l.push(_)}return l.sort((u,x)=>u.isDir!==x.isDir?u.isDir?-1:1:u.name.localeCompare(x.name)),l}function D_(t){return!t||t<=0?u_:Math.min(t,f_)}function R_(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function j0(t){return t.split(F0).join("/")}ne();import{readFileSync as mA}from"node:fs";import{dirname as _A,join as yA}from"node:path";import{fileURLToPath as bA}from"node:url";var Sr="0.1.100-beta.2";var wn=G("agent-health-reporter"),k_=1e4,Ri=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??k_}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 u=P_(l);if(!u)continue;let x={agentId:l.agentId,status:u};l.patToken&&(x.patToken=l.patToken),l.accountId&&(x.accountId=l.accountId),r.push(x)}if(r.length===0)return;let i={agents:r,bridgeVersion:Sr,_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 P_(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}rn();import{chmod as Dy,mkdir as ho,rm as Ry,stat as ky,writeFile as Py}from"node:fs/promises";import{homedir as Oy}from"node:os";import{join as yf}from"node:path";nn();import{existsSync as J_}from"node:fs";import{release as X_}from"node:os";import{basename as Q_,isAbsolute as ey}from"node:path";function ki(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Ir(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Ar(t,e){return{jsonrpc:"2.0",id:t,result:e}}function _n(t,e){return{jsonrpc:"2.0",id:t,error:e}}We();var so=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 W0(t){return"method"in t&&"id"in t&&t.id!==void 0}function K0(t){return"method"in t&&!("id"in t)}function oo(t){return!("method"in t)&&"id"in t}var O_={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 N_(t){if(t!=null)return t instanceof Error?{name:t.name,message:Pi(t.message)}:typeof t=="string"?Pi(t):typeof t=="object"?M_(t):t}var L_=[[/\/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 Pi(t){let e=t;for(let[r,i]of L_)e=e.replace(r,i);return e}function M_(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Pi(i):e[r]=i;return e}function Oi(t){if(t instanceof T){let e=N_(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:O_[t.code]??ee.INTERNAL_ERROR,message:Pi(t.message),data:r}}return{code:ee.INTERNAL_ERROR,message:Pi(t instanceof Error?t.message:String(t))}}function $0(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,...u}=e;c=u}return new T(r,o,{retriable:e?.retriable??!1,cause:c})}function Z0(t){return`${JSON.stringify(t)}
93
+ `}var V0=10*1024*1024,ao=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>V0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${V0} 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])),B_={"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:[]},Tr=class{seq=0;next(e,r){this.seq+=1;let i=J0[e]??z_(e),o=B_[i]??[],c=[i,String(this.seq)];if(o.length>0){let l=o.map(x=>Y0(r?.[x]??"")),u=F_(l).join(":");u&&c.push(u)}else r&&Object.values(r).some(l=>l)&&c.push(Object.values(r).filter(Boolean).map(l=>Y0(String(l))).join(":"));return c.join("_")}reset(){this.seq=0}};function z_(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function Y0(t){return t.replace(/[:_\s]+/g,"-")}function F_(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}Jr();import{readFileSync as U_}from"node:fs";var G_=384;async function $c(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await rr(t.agentEnvFile,r,{mode:G_})}function Vc(t){try{let e=JSON.parse(U_(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function X0(t,e,r={},i=o=>o){return{...i({...t,...Vc(e)}),...r}}yn();Xn();We();ne();ke();import{execFileSync as V_,spawnSync as Z_}from"node:child_process";function Ni(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function Li(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),Z_("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var Zc=new Set;function nf(t){typeof t=="number"&&t>0&&Zc.add(t)}function rf(t){typeof t=="number"&&Zc.delete(t)}function sf(){for(let t of Zc)Li(t,"SIGKILL")}var Cr="coze-bridge-daemon";function of(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return V_("pgrep",["-U",String(o),"-f",Cr],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:2e3})}),r;try{r=e()}catch{return[]}let i=process.pid;return r.split(`
95
+ `).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function af(t,e){if(t.length===0)return;let r=e?.killFn??Li,i=e?.isAliveFn??Ni,o=e?.sleepFn??(u=>new Promise(x=>setTimeout(x,u))),c=e?.graceMs??3e3,l=e?.pollMs??100;for(let u of t)r(u,"SIGTERM");for(let u=0;u<c&&t.some(x=>i(x));u+=l)await o(Math.min(l,c-u));for(let u of t)i(u)&&r(u,"SIGKILL")}var Y_=[{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|QCLAW_CLI_NODE_BINARY not set)/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:"acp_module_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code","codex"],match:/Cannot find module[^\n]*node_modules[\\/]@(agentclientprotocol[\\/]claude-agent-acp|zed-industries[\\/]codex-acp)/i,message:"ACP \u4F9D\u8D56\u672A\u6B63\u786E\u5B89\u88C5 (wrapper \u5165\u53E3\u7F3A\u5931)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u91CD\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"},{reason:"prompt_too_long",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code"],match:/Prompt is too long|bad request: failed to read body: length limit exceeded/i,message:"\u672C\u8F6E\u8F93\u5165\u8FC7\u957F\uFF0C\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u7CBE\u7B80\u8F93\u5165\u6216\u5F00\u542F\u65B0\u4F1A\u8BDD\u540E\u91CD\u8BD5"}];function cf(t,e){if(!e)return null;for(let r of Y_)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function df(t,e){return cf(t,e)}function lf(t,e){return cf(t,e)}function Dr(t,e,r){return!e&&r.firstUpdateMs>0&&t<r.firstUpdateMs?Math.max(1,r.firstUpdateMs-t):t<r.phase2GateMs?Math.max(1,r.phase2GateMs-t):Math.max(1,r.livenessWindowMs)}function uf(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let p=t.suspendedMs+o,w=r-t.startedAt-p;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Dr(w,t.firstFrameSeen,e)}}let c=r-t.startedAt-t.suspendedMs,l=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=l?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Dr(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Dr(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Dr(c,!1,e)}}var ff=He("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),ty=200,ny=40,ry=He("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),iy=He("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),sy=He("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),oy=He("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),ay=He("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),cy=He("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),xf=500;function dy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=xf?t:`${e.slice(0,xf)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function ly(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 hf(t){try{return J_(t)}catch{return}}function uy(t,e){return{platform:process.platform,osRelease:X_(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:ey(e.command)?hf(e.command):void 0,cwd:e.cwd,cwdExists:hf(e.cwd),envKeys:e.envKeys}}function fy(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${Q_(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Nt=class{constructor(e){this.opts=e;this.log=G(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new ao({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Tr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new T("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=X0(process.env,this.opts.agentEnvFile??J().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=dt(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,nf(i.pid),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>ty&&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,rf(i.pid),(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 u of this.decoder.flush())this.dispatch(u)}catch(u){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(u)})}this.failAllPending(this.buildExitError(o,c));for(let u of this.exitHandlers)u(o,c)}),i.on("error",o=>{let c=o,l=uy(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 T("AGENT_SPAWN_FAILED",fy(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()));Li(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Li(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){let i={firstUpdateMs:ay,phase2GateMs:ry,livenessWindowMs:iy,absoluteMaxMs:sy,approvalMaxMs:cy,suspendThresholdMs:oy,...r};return this.call("session/prompt",e,ff,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Ir("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(Ar(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=ff,o){if(!this.child||this.stopped)return Promise.reject(new T("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),l=ki(c,e,r),u=(()=>{if(typeof r!="object"||r===null)return;let x=r.sessionId;return typeof x=="string"?x:void 0})();return new Promise((x,p)=>{let w={resolve:x,reject:p,timer:null,method:e,promptTimeout:null};if(o){let _=this.now(),S={cfg:o,startedAt:_,lastActivityAt:_,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:_,expectedIntervalMs:Dr(0,!1,o),sessionId:u};w.promptTimeout=S;let E=()=>{let b={startedAt:S.startedAt,lastActivityAt:S.lastActivityAt,firstFrameSeen:S.firstFrameSeen,hasActiveTool:S.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:S.suspendedMs,armedAt:S.armedAt,expectedIntervalMs:S.expectedIntervalMs},A=this.now(),I=uf(b,S.cfg,A),C=O=>{S.armedAt=A,S.expectedIntervalMs=O,w.timer=setTimeout(E,O)};if(I.action==="suspend"){S.suspendedMs+=I.suspendedDeltaMs,S.lastActivityAt=A,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:I.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),C(I.rearmMs);return}if(I.action==="continue"){C(I.rearmMs);return}this.pending.delete(c),I.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:I.awaitingApproval,...S.sessionId?{sessionId:S.sessionId}:{}}),p(I.awaitingApproval?new T("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new T("AGENT_TIMEOUT",`${e} timed out after ${S.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...S.sessionId?{sessionId:S.sessionId}:{}}),p(new T("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};w.timer=setTimeout(E,S.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(w.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),p(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,w);try{this.writeFrame(l)}catch(_){w.timer&&clearTimeout(w.timer),this.pending.delete(c),p(_)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new T("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(Z0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(oo(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),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 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:dy(e.result)}),r.resolve(e.result));return}if(K0(e)){if(e.method==="session/update"){let r=e.params;for(let i of this.pending.values()){let o=i.promptTimeout;o&&(o.firstFrameSeen=!0,o.lastActivityAt=this.now(),this.trackToolCall(o,r))}for(let i of this.updateHandlers)try{Promise.resolve(i(r)).catch(o=>this.log.warn("update handler failed (async)",{err:String(o)}))}catch(o){this.log.warn("update handler threw sync, swallowed",{err:String(o)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(W0(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)})}}}trackToolCall(e,r){let i=r.update,o=i?.sessionUpdate;if(o!=="tool_call"&&o!=="tool_call_update")return;let c=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!c)return;let l=typeof i.status=="string"?i.status:void 0,u=l==="completed"||l==="failed"||l==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}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,Oi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=$0(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=lf(this.framework,ly(e));return i?new T(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 T("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(ny).join(`
96
+ `),o=df(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.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function xy(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 co=class extends Nt{framework="claude-code";constructor(e){let{command:r,args:i}=Yr("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 xy(e)}};nn();import{mkdtempSync as hy,rmSync as py}from"node:fs";import{tmpdir as gy}from"node:os";import{join as my}from"node:path";var lo=class extends Nt{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=Yr("codex",e.command,i),l=e.isolateCodexHome?hy(my(gy(),"coze-bridge-codex-home-")):void 0,u=l?{...e.env??{},CODEX_HOME:l}:e.env,x={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(x),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{py(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};var wy=3e4,Rr=class extends Nt{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.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},wy))}get acpSessionName(){return this.sessionName}};We();ne();ke();function Yc(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}nn();var En=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 uo=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 En,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)Mi(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 Mi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}yn();ne();import{constants as pf}from"node:fs";import{access as _y}from"node:fs/promises";import{delimiter as yy,join as Ey}from"node:path";var bt=G("framework-detector"),gf={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},by=[".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??dt,access:e.access??_y}}async detect(e){let r=gf[e],i=await this.which(r);if(!i)return bt.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)]),u={path:i,version:c};return l&&(u.defaultAgent=l),u}async detectAll(){let e=await Promise.all(Object.keys(gf).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(yy).filter(Boolean),i=this.env.platform==="win32"?["",...by]:[""];for(let o of r)for(let c of i){let l=Ey(o,e+c);if(await this.isExecutable(l))return l}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?pf.F_OK:pf.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 bt.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return bt.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 bt.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 bt.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?(bt.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}:(bt.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return bt.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 bt.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||bt.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){bt.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&&(Sy(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,l,u=x=>{c||(c=!0,l&&clearTimeout(l),i(x))};try{let x=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});l=setTimeout(()=>{x.kill("SIGKILL"),u(null)},15e3),x.stdout?.on("data",p=>{o+=p.toString("utf8")}),x.on("error",()=>u(null)),x.on("close",p=>u({code:p,stdout:o}))}catch{u(null)}})}},vy=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function Sy(t){return t.replace(vy,"")}import{homedir as Iy}from"node:os";import{join as Ay}from"node:path";yn();Xn();We();Jr();ne();async function _f(){let t=Ay(Iy(),".openclaw/openclaw.json");return(await nr(t))?.gateway?.auth?.token??""}var mf=G("openclaw.config"),Ty=[0,5e3,5e3],Cy=He("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),wf="models.providers.",fo="agents.defaults.models",xo=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new En;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??Ty,this.cliTimeoutMs=e.cliTimeoutMs??Cy}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,mf.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(l)})}}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=dt(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",l=!1,u=p=>{l||(l=!0,clearTimeout(x),p())};o.stderr?.on("data",p=>{c+=p.toString("utf8")});let x=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);x.unref(),o.on("error",p=>u(()=>i(p))),o.on("close",p=>u(()=>{p===0?r():i(new Error(`exit ${p}: ${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){mf.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",`${wf}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${wf}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${fo}[${e}]`,()=>this.runCli(["config","set",fo,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${fo}[${e}]`,`${fo}.${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 he=G("agent-manager"),Ny=(t,e,r,i,o,c,l,u,x)=>{switch(t){case"claude-code":{let p={...o?{...k0(o),...N0(o,l,u)}:{},...x??{},IS_SANDBOX:"1"};return new co({cwd:r,env:p,agentId:i})}case"codex":{let w=[...o?[...P0(o),...M0(o,l,u)]:[],"-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"'],_={...o?O0(o):{},...x??{}},S=!!o;return new lo({cwd:r,agentId:i,...w.length>0?{extraArgs:w}:{},...Object.keys(_).length>0?{env:_}:{},...S?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Rr({command:e,cwd:r,agentId:i,...c?{sessionName:Yc(c)}:{}})}};function Jc(t){return t==="claude-code"||t==="codex"}function Ly(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
97
  `)}
97
- `}function Ty(t){if(t.includes(`
98
- `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var Cy={path:"",version:"cloud-deployed"},x0="openclaw_gateway_unavailable",Ry="openclaw_default_agent_missing";function p0(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 Dy={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},Py=6e4,fo=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??Iy,this.createTimeoutMs=e.createTimeoutMs??Py,this.detectorFactory=e.detectorFactory??(()=>new Fn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new lo({command:r})),this.openclawConfigDir=e.openclawConfigDir??h0(Sy(),".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 C("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=h0(e,".env");if(await Ey(r).then(c=>c.isFile()).catch(()=>!1)){xe.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}await uo(e,{recursive:!0});let o=Ay({...process.env,...Wc(this.paths.agentEnvFile)});if(await vy(r,o,"utf8"),process.platform!=="win32")try{await yy(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 C("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new C("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 C("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 Ze(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 Ze(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 C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let l=Je(e.agentId,this.paths),u=Si(e._meta),h=e.framework==="openclaw"&&u==="local",p;h&&!r?.revive&&(p=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let _=p??(h?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),E=e.workspace??_??l.workspace,A=new AbortController,b=setTimeout(()=>A.abort(new C("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),v,I=!1;try{i&&Vc(e.framework)&&await Qn(e.framework,A.signal);let S=()=>{if(A.signal.aborted)throw A.signal.reason instanceof Error?A.signal.reason:new C("AGENT_TIMEOUT","_agent/create aborted")};await uo(l.root,{recursive:!0}),await uo(E,{recursive:!0}),await uo(l.logs,{recursive:!0}),S(),h||await nr(E,e.framework,e.cozeIdentity),e.framework==="claude-code"&&await bl(E,u),S();let R=await Ge(e.agentId,this.paths).catch(()=>null),N=If({model:e.model??R?.model}),y=mf(e._meta)??R?.accountId,D=e.patToken??R?.patToken,P=u==="cloud"?e.modelInfo??R?.modelInfo:void 0;if(v=new ao({agentId:e.agentId,framework:e.framework,workspace:E,model:N.model??wt,deployType:u,...y?{accountId:y}:{},...D?{patToken:D}:{},...P?{modelInfo:P}:{}}),v.status="ok",R?.sessions){for(let[V,ee]of Object.entries(R.sessions))v.sessions.set(V,{acpSessionId:ee.acpSessionId,modelToken:ee.modelToken,tokenGeneratedAt:ee.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0});let $=Object.keys(R.sessions).length;$>0&&xe.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:$})}this.registry.register(v),I=!0;let M={agentId:e.agentId,framework:e.framework,workspace:E,cozeIdentity:e.cozeIdentity,createdAt:R?.createdAt??Date.now(),sessions:R?.sessions??{},model:N.model};u==="cloud"&&(M.deployType="cloud"),y&&(M.accountId=y),D&&(M.patToken=D),P&&(M.modelInfo=P),R?.skills&&(M.skills=R.skills),R?.agentName&&(M.agentName=R.agentName),R?.description&&(M.description=R.description),e.framework==="openclaw"&&u==="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 z=e.initialSkills??[];if(z.length>0){let $=[...M.skills??[]],V=new Map($.map((be,he)=>[be.skillId,he])),ee=await Promise.allSettled(z.map(be=>qc({agentId:e.agentId,workspace:E,framework:e.framework,skill:be}))),Y=0;for(let[be,he]of ee.entries()){let O=z[be];O&&(he.status==="fulfilled"?(jc($,V,he.value),Y++):xe.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:O.skillId,skillName:O.skillName,err:String(he.reason)}))}Y>0&&(M.skills=$,xe.info("initialSkills installed",{agentId:e.agentId,installed:Y,requested:z.length}))}return await Ze(M,this.paths),xe.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:u}),{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 by(l.root,{recursive:!0,force:!0}).catch(R=>xe.warn("rm agent dir failed (ignored)",{err:String(R)})),S instanceof C?S:new C("AGENT_SPAWN_FAILED",String(S),{cause:S})}finally{clearTimeout(b)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&Vc(e.framework))u=Cy;else throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);Vc(e.framework)&&!ts(e.framework)&&(xe.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await Qn(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:u.path}):p=this.factory(e.framework,u.path,e.workspace,e.agentId,h,i,o,c,this.buildBinShimPathEnv());try{return await p.start(),await p.initialize(Dy),p}catch(_){let E=p instanceof kt?p.getStderrTail():[];throw E.length>0&&xe.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:_ instanceof C?_.code:"unknown",recentStderr:E}),await p.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,_)}}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 C("AGENT_ENV_NOT_READY",p0(o),{cause:{reason:x0}})}catch(o){xe.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof C?new C(i.code,i.message,{retriable:i.retriable,cause:i.cause??i}):new C("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 C("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:Ry}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new C("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new C("AGENT_ENV_NOT_READY",p0(r),{cause:{reason:x0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:l,command:u}=e,h=$c(o);if(r.deployType==="local"){let A=await this.ensureOpenclawDefaultAgent();return new Tr({command:u,cwd:A.workspace,agentId:A.id,sessionName:h})}let p=await f0(),_=i?Pf(i,c,l):null,E;if(_){let A=Lc(o),v=_.models[0]?.id??wt,I=`${A}/${v}`;if(!this.ensuredProviders.has(I)){let S=this.getOpenclawConfig();await S.ensureProvider(A,_),await S.addModelToAllowlist(I),this.ensuredProviders.add(I)}E=I}return new Tr({command:u,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=Lc(i),c=`${o}/${e.model}`,l=!0;try{await r.removeProvider(o)}catch(u){l=!1,xe.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){l=!1,xe.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}l&&this.ensuredProviders.delete(c)}}};import{randomUUID as y0}from"node:crypto";import{promises as Fy}from"node:fs";import{basename as b0}from"node:path";He();te();import{promises as Oy}from"node:fs";import{basename as Ny}from"node:path";var g0=U("file-upload"),Ly="/api/coze_claw/file/agent_upload",My=6e4;async function m0(t,e={}){let i=`${Zs(Ys(e.handshakeBase))}${Ly}`,o=e.timeoutMs??My,c=await Oy.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 u={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,p=setTimeout(()=>h.abort(),o);g0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let _=await fetch(i,{method:"POST",headers:u,body:l,signal:h.signal}),E=_.headers.get("x-tt-logid")??"";if(!_.ok){let v=await _.text().catch(()=>"");throw new C("UPLOAD_FAILED",`upload HTTP ${_.status} logid=${E}: ${v.slice(0,200)}`)}let A=await _.json();if(A.code!==void 0&&A.code!==0)throw new C("UPLOAD_FAILED",`upload code=${A.code} msg=${A.msg??"-"} logid=${E}`);let b=A.data?.file?.file_url;if(!b)throw new C("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${E}: ${JSON.stringify(A).slice(0,200)}`);return g0.info("file upload ok",{uri:b,logid:E}),{uri:b}}catch(_){throw _ instanceof C?_:_.name==="AbortError"?new C("UPLOAD_FAILED",`upload timeout (${o}ms) for ${Ny(t.path)}`):new C("UPLOAD_FAILED",String(_),{cause:_})}finally{clearTimeout(p)}}He();te();import{extname as By}from"node:path";var zy={".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 w0(t){let e=By(t).toLowerCase();return zy[e]??"application/octet-stream"}Pe();var ho=U("agent-send"),_0=50*1024*1024;function E0(t,e,r){let i=t.get(e);if(!i)throw new C("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new C("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new C("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function v0(t,e,r,i,o,c){let u;for(let h=0;h<=2;h++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(p){u=p,h<2&&(ho.warn("sendAgentFileUpdate failed, retrying",{attempt:h+1,err:String(p)}),await new Promise(_=>setTimeout(_,5e3)))}throw new C("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function S0(t,e){let{session:r,runtime:i}=E0(e.core,t.agentId,t.sessionId);if(!await Zr(t.path,r.workspace))throw new C("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await Fy.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new C("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>_0)throw new C("FILE_TOO_LARGE",`${o.size} bytes > limit ${_0}`);let c=await w0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new C("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new C("UPSTREAM_NOT_READY","cloud WS not connected");let l=t.name??b0(t.path),u;try{u=await m0({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 ho.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:p instanceof C?p.code:"UNKNOWN",message:p instanceof Error?p.message:String(p)}),p}let h={sessionUpdate:"agent_file",messageId:y0(),content:{type:t.kind==="image"?"image":"resource",uri:u.uri,mimeType:c,name:l,sizeBytes:o.size,...u.fileId!==void 0?{fileId:u.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await v0(e,r,i,t.sessionId,h,"agent file uploaded to cloud but sendAgentFileUpdate failed"),ho.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:l,bytes:o.size,mime:c,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:c,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function I0(t,e){let{session:r,runtime:i}=E0(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new C("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new C("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??b0(t.path),c={sessionUpdate:"group_file",messageId:y0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await v0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),ho.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 A0(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,u=i[c]??0;if(l<u)return!0;if(l>u)return!1}return!1}en();wn();te();var Ot=U("coze-cli-installer"),T0="@coze/cli@latest",Uy="coze",C0="0.1.8",Gy=5e3,qy=5e3,jy=9e4,R0=1e4,Oi=null,xo=!1;async function Jc(t,e={}){if(xo)return;if(Oi)return Oi;let r=e.exec??Xf;return Oi=(async()=>{try{let i=await Hy(Uy,r),o=!1;if(i){let l=await Wy(r);if(l===void 0)Ot.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(A0(l,C0))Ot.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:l,min:C0}),o=!0;else{Ot.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:l}),xo=!0;return}}let c=o?"upgrade-only":"full";Ot.info("coze-cli install start",{package:T0,mode:c});try{await r("npm",["i","-g","--prefer-online",T0],{timeout:jy,maxBuffer:10*1024*1024}),Ot.info("coze-cli install ok")}catch(l){Ot.warn("coze-cli install failed (skip subsequent steps)",{err:String(l)});return}if(o){xo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:R0}),Ot.info("coze config set xTTEnv ok",{env:t.env})}catch(l){Ot.warn("coze config set failed (continue to auth login)",{err:String(l)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:R0}),Ot.info("coze auth login ok")}catch(l){Ot.warn("coze auth login failed",{err:String(l)});return}xo=!0}finally{Oi=null}})(),Oi}async function Hy(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:Gy});return ya(i)}catch{return}}async function Wy(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:qy});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}Jr();Pe();var Ky=10*6e4;function D0(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?Ky:e}function po(t){return er(t??X().configFile)}function Ni(t,e){return tr(e??X().configFile,t)}import{randomBytes as fb}from"node:crypto";Hr();He();te();import{createReadStream as $y}from"node:fs";import{mkdir as Vy,readFile as Jy,realpath as Zy,stat as Xy,writeFile as Yy}from"node:fs/promises";import{basename as Qy,dirname as Zc,isAbsolute as eb,join as tb,relative as nb,resolve as P0,sep as rb}from"node:path";import{createInterface as ib}from"node:readline";var O0=U("fs-rpc"),Li=Ve("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function N0(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Li)throw new C("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Li} bytes`);let i=await M0(t.path,e);return await Vy(Zc(i),{recursive:!0}),await Yy(i,t.content,"utf8"),O0.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function L0(t,e){let r=await M0(t.path,e),i=await Xy(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Li&&!o)throw new C("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Li} bytes`);let c;if(o&&i.size>Li)c=await sb(r,t.line??1,t.limit);else{let l=await Jy(r,"utf8");if(o){let u=l.split(`
99
- `),h=Math.max(0,(t.line??1)-1),p=typeof t.limit=="number"?h+t.limit:void 0;c=u.slice(h,p).join(`
100
- `)}else c=l}return O0.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function sb(t,e,r){let i=ib({input:$y(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,l=[],u=0;try{for await(let h of i)if(u>=o&&u<c&&l.push(h),u++,u>=c)break}finally{i.close()}return l.join(`
101
- `)}async function M0(t,e){if(typeof t!="string"||t.length===0)throw new C("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([k0(P0(e)),k0(P0(t))]),o=nb(r,i);if(ob(o,rb,eb(o)))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function ob(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function k0(t){let e=[],r=t;for(;r!==Zc(r);)try{let i=await Zy(r);return e.length?tb(i,...e.reverse()):i}catch{e.push(Qy(r)),r=Zc(r)}return t}te();var B0=U("prompt-multimodal"),z0=10*1024*1024,ab=15e3,cb=6;async function F0(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 db(l))}}let o=Array.from({length:Math.min(cb,t.length)},()=>i());return await Promise.all(o),e}function U0(t){return t.some(e=>e.type==="image")}async function db(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Js(e.uri))return t;try{let{buf:r,contentType:i}=await ub(e.uri),o=e.mimeType||lb(i)||"application/octet-stream";return B0.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 B0.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function lb(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function ub(t){let e=new AbortController,r=setTimeout(()=>e.abort(),ab);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>z0)throw new Error(`image too large: ${o.byteLength} bytes (max ${z0})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}tn();He();te();var K=U("core"),hb=3e4,xb=/^(boe|ppe)_[A-Za-z0-9_-]+$/,pb="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",gb="\u5BA1\u6279\u5DF2\u8D85\u65F6",mb=3e4,go=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Ir;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=D0(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(),K.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){K.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),K.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){K.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)&&K.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)=>{K.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:l}),ki(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){K.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(l=>K.debug("send error response to upstream failed (ignored)",{err:String(l)}));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)){K.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 C("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(to(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&&xb.test(i)?this.currentCozeEnv=i:i&&K.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}`):K.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(Sr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Sr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Sr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,Q.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):K.warn("drop unknown notification",{method:e.method})}catch(o){K.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(mn(r,Pi(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new C("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new C("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new C("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new C("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,_=Dc(r._meta);return K.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,h,c,pb,p,_)}}let l=Date.now(),u=!1;try{let h=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,h}finally{K.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-l,ok:u})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=wf(i);switch(r){case"session/new":{let c=wb();return K.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return K.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 C("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=await this.ensureRuntime(e,l);if(u.replySeq=0,await this.ensureDownstream(e,l,u),!u.downstream||!u.acpSessionId)throw new C("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");let h=i._meta?.cozeTriggerMsgId;h?e.activeTriggers.set(u.acpSessionId,h):e.activeTriggers.delete(u.acpSessionId);let p=Dc(i._meta);if(p?e.activeGroupIds.set(u.acpSessionId,p):e.activeGroupIds.delete(u.acpSessionId),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&U0(c.prompt))throw new C("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let _=await F0(c.prompt);try{let E=await u.downstream.sessionPrompt({...c,sessionId:u.acpSessionId,prompt:_});return u.lastActiveAt=Date.now(),E}catch(E){if(E instanceof C&&E.code==="AGENT_APPROVAL_TIMEOUT"){let A=u.pendingPermission;A&&(A.downstream.respondAgentRequest(A.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(A.upstreamId),u.pendingPermission=void 0);let b=u.acpSessionId,v=b?e.activeTriggers.get(b):void 0,I=b?e.activeGroupIds.get(b):void 0;return K.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:l}),await this.synthesizePromptReply(e,u,l,gb,v,I)}throw E}finally{if(e.activeTriggers.delete(u.acpSessionId),e.activeGroupIds.delete(u.acpSessionId),u.pendingPermission=void 0,u.reloadAfterTurn){u.reloadAfterTurn=!1;let E=u.downstream;E&&(u.downstream=void 0,K.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:l,acpId:u.acpSessionId}),E.stop("reload-after-turn").catch(A=>K.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:l,err:String(A)})))}else u.downstream?.isAlive()&&this.armIdleTimer(e,l,u)}}case"session/cancel":{let l=o.sessionId;if(!l)throw new C("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(l);if(e.hasSessionQueue(l)){let h=e.getSessionQueue(l);h.size>0&&(K.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:l,queuedCount:h.size}),h.dispose(new C("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${l}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}default:throw new C("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,mb);if(!o?.modelToken)throw new C("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof C&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new C("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(ki(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new C("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,l=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(l>=o&&Date.now()-u<c)throw new C("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()-u))/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&&(K.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),p}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=h,this.attachRuntimeHooks(e,r,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await h.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),K.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(p){K.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(p)}),i.acpSessionId=void 0;let _=await h.sessionNew({cwd:e.workspace});i.acpSessionId=_.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)}}catch(p){throw K.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(p)}),await h.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,p}h.afterSessionEstablished&&i.acpSessionId&&await h.afterSessionEstablished(i.acpSessionId)}armIdleTimer(e,r,i){if(ki(i),this.isRuntimeBusy(e,i)){K.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)){K.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}K.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=>K.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 u=e.activeGroupIds.get(r.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(vr("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,l){let u={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(u.cozeTriggerMsgId=c),l&&(u.cozeGroupId=l),await this.upstream.send(vr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(h=>K.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){K.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){K.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(bb(r)){K.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let l={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},u=e.activeTriggers.get(i);u&&(l.cozeTriggerMsgId=u);let h=e.activeGroupIds.get(i);h&&(l.cozeGroupId=h),this.upstream.send(vr("session/update",{...r,sessionId:o,_meta:l})).catch(p=>K.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}K.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??{},l=await N0(c,o);r.respondAgentRequest(i.id,l)}else{let c=i.params??{},l=await L0(c,o);r.respondAgentRequest(i.id,l)}}catch(o){K.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Pi(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??{},u=c.sessionId,h=u?e.activeTriggers.get(u):void 0,p={cozeAgentId:e.agentId};h&&(p.cozeTriggerMsgId=h);let _=u?e.activeGroupIds.get(u):void 0;_&&(p.cozeGroupId=_);let E=u?this.reverseSessionId(e,u):void 0,A=E?e.sessions.get(E):void 0;A&&(A.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let b={...c,...E?{sessionId:E}:{},_meta:p};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:E}),K.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,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",b)).catch(v=>{this.pendingUpstream.delete(o),K.error("forward permission request failed",{agentId:e.agentId,err:String(v)}),r.respondAgentRequestError(i.id,{code:Q.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?(K.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"&&_b(e.result,o),K.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 eo(e.error)):i.value.resolve(e.result);return}K.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 K.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:l,key:c}}}sendRequest(e,r,i=hb){let o=this.upstreamIds.next(e);return new Promise((c,l)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),l(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:l,timer:u}),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 Xr(e.agentId,r,this.paths)}catch(r){K.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 wb(){return fb(16).toString("hex")}function _b(t,e){if(!t||typeof t!="object"){K.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){K.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"){K.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")&&K.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var yb=["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 bb(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 yb.some(c=>o.startsWith(c))}te();Pe();import{randomBytes as Eb}from"node:crypto";import{chmod as vb,mkdir as Sb,writeFile as G0}from"node:fs/promises";import{createServer as Ib}from"node:http";import{dirname as Ab}from"node:path";var Tb=1e6,Xc=U("ipc"),mo=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=Eb(32).toString("hex");let e=Ib((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(),Xc.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 Sb(Ab(this.paths.portFile),{recursive:!0}),await G0(this.paths.portFile,String(this.port),"utf8"),await G0(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await vb(this.paths.tokenFile,384)}catch(e){Xc.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 Cb(e)}catch(u){Mi(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(l,e);Mi(r,200,u??{ok:!0})}catch(u){Xc.error("IPC handler failed",{key:o,err:String(u)}),Mi(r,500,{error:u instanceof Error?u.message:String(u)})}}};function Mi(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function Cb(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>Tb)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}var dx=St(Y0(),1);var cv=St($h(),1),dv=St(Oo(),1),lv=St(Dr(),1),uv=St(ld(),1),fv=St(hd(),1),hv=St(_d(),1),nx=St(Bo(),1),xv=St(tx(),1);var rx=nx.default;He();te();var Re=U("upstream.frontier"),sx="application/json",ox="none",gv=15e3;function mv(t){class e extends rx{constructor(i){super(i,yf,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>Re.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(sl("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");Re.debug("WS raw frame out",{bytes:c.byteLength,headHex:l})}catch(c){Re.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){Re.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:bf,...yr(this.opts.ppeOverride)},r=mv(e),i=vf(this.opts.urlOverride),o={url:i,ws:r,fpID:_f,aID:Xs,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:sx,force:!0},payloadEncoding:{encoding:ox,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new dx.FWS(o),l=!1,u=null,h,p,_=new Promise((b,v)=>{h=b,p=v}),E=b=>{l||(l=!0,u&&(clearTimeout(u),u=null),b?p(b):h())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let b=this.openCount===1;Re.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:b,openCount:this.openCount}),b&&E();for(let v of this.connectHandlers)Promise.resolve(v({initial:b})).catch(I=>Re.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=b=>{this.opened=!1,Re.info("frontier closed",{code:b.code,reason:b.reason,willReconnect:b.willReconnect})},c.onerror=b=>{Re.warn("frontier error",{code:b.code,msg:b.message}),E(new C("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${b.code} msg=${b.message??""}`))},c.onmessage=b=>this.handleMessage(b),this.fws=c;let A=this.opts.openTimeoutMs??gv;u=setTimeout(()=>{E(new C("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${A}ms (handshake or upgrade slow)`))},A),await c.connect();try{await _}catch(b){try{c.close(1e3,"open failed")}catch(v){Re.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,b}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){Re.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw Re.warn("frontier send refused: upstream not started",{method:i}),new C("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let u=Date.now();throw u-this.lastSendRefusedLogAt>1e3?(Re.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:r.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=u,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new C("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;ax(c)||Re.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:sx,payloadEncoding:ox})}catch(u){throw Re.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new C("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}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){Re.debug("drop non-adapter frontier frame",{service:r});return}let i=yv(e);if(!i){Re.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){Re.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(l){Re.warn("frontier message JSON parse failed",{err:String(l),head:i.slice(0,80)});return}let c=o;ax(c)||Re.info("frontier frame in",{logid:_v(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:wv(i)}),Promise.resolve(this.handler(o)).catch(l=>Re.warn("frontier frame handler threw",{err:String(l)}))}};function ax(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var cx=2e3;function wv(t){return t.length<=cx?t:`${t.slice(0,cx)}...<truncated, total ${t.length} chars>`}function _v(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function yv(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}}te();var bd=U("upstream.switchable"),Fo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;bd.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 bd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>bd.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()}};te();var Ed=U("upstream"),Mr=class{handler=null;async start(){Ed.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Ed.info("NoopUpstream stopped",{reason:e})}async send(e){Ed.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)}};He();te();te();Pe();import{promises as vd}from"node:fs";import{dirname as bv}from"node:path";var Ev=U("pat-token-store");async function Uo(t=X()){try{let r=(await vd.readFile(t.patTokenFile,"utf8")).trim();return r.length>0?r:null}catch(e){let r=e?.code;return r!=="ENOENT"&&Ev.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 vd.mkdir(bv(e.patTokenFile),{recursive:!0}),await vd.writeFile(e.patTokenFile,t,{encoding:"utf8",mode:384})}Pe();Pe();import{promises as Go}from"node:fs";import{join as vv}from"node:path";function Sv(t,e){return`#!/bin/sh
98
+ `}function My(t){if(t.includes(`
99
+ `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var By={path:"",version:"cloud-deployed"},Ef="openclaw_gateway_unavailable",zy="openclaw_default_agent_missing";function bf(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 Fy={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},Uy=6e4,po=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??Ny,this.createTimeoutMs=e.createTimeoutMs??Uy,this.detectorFactory=e.detectorFactory??(()=>new Gn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new xo({command:r})),this.openclawConfigDir=e.openclawConfigDir??yf(Oy(),".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=>{he.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=yf(e,".env");if(await ky(r).then(c=>c.isFile()).catch(()=>!1)){he.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}await ho(e,{recursive:!0});let o=Ly({...process.env,...Vc(this.paths.agentEnvFile)});if(await Py(r,o,"utf8"),process.platform!=="win32")try{await Dy(r,384)}catch(c){he.warn("chmod ~/.openclaw/.env to 0600 failed (ignored)",{err:String(c)})}he.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),he.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=Ai(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")he.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await o.dispose("rebuild after error").catch(I=>he.warn("dispose stale agent failed (ignored)",{err:String(I)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==o.patToken){he.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),o.setPatToken(e.patToken);let I=await Ge(e.agentId,this.paths).catch(()=>null);I&&(I.patToken=e.patToken,await Ye(I,this.paths))}if(o.deployType==="cloud"&&e.modelInfo){he.info("updating agent modelInfo on re-create",{agentId:e.agentId}),o.setModelInfo(e.modelInfo);let I=await Ge(e.agentId,this.paths).catch(()=>null);I&&(I.modelInfo=e.modelInfo,await Ye(I,this.paths))}return he.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 l=Ze(e.agentId,this.paths),u=Ai(e._meta),x=e.framework==="openclaw"&&u==="local",p;x&&!r?.revive&&(p=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let w=p??(x?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),_=e.workspace??w??l.workspace,S=new AbortController,E=setTimeout(()=>S.abort(new T("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),b,A=!1;try{i&&Jc(e.framework)&&await tr(e.framework,S.signal);let I=()=>{if(S.signal.aborted)throw S.signal.reason instanceof Error?S.signal.reason:new T("AGENT_TIMEOUT","_agent/create aborted")};await ho(l.root,{recursive:!0}),await ho(_,{recursive:!0}),await ho(l.logs,{recursive:!0}),I(),x||await ir(_,e.framework,e.cozeIdentity),e.framework==="claude-code"&&await Al(_,u),I();let C=await Ge(e.agentId,this.paths).catch(()=>null),O=D0({model:e.model??C?.model}),y=E0(e._meta)??C?.accountId,D=e.patToken??C?.patToken,R=u==="cloud"?e.modelInfo??C?.modelInfo:void 0;if(b=new uo({agentId:e.agentId,framework:e.framework,workspace:_,model:O.model??Et,deployType:u,...y?{accountId:y}:{},...D?{patToken:D}:{},...R?{modelInfo:R}:{}}),b.status="ok",C?.sessions){for(let[V,te]of Object.entries(C.sessions))b.sessions.set(V,{acpSessionId:te.acpSessionId,modelToken:te.modelToken,tokenGeneratedAt:te.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0});let $=Object.keys(C.sessions).length;$>0&&he.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:$})}this.registry.register(b),A=!0;let M={agentId:e.agentId,framework:e.framework,workspace:_,cozeIdentity:e.cozeIdentity,createdAt:C?.createdAt??Date.now(),sessions:C?.sessions??{},model:O.model};u==="cloud"&&(M.deployType="cloud"),y&&(M.accountId=y),D&&(M.patToken=D),R&&(M.modelInfo=R),C?.skills&&(M.skills=C.skills),C?.agentName&&(M.agentName=C.agentName),C?.description&&(M.description=C.description),e.framework==="openclaw"&&u==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,_)):he.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let z=e.initialSkills??[];if(z.length>0){let $=[...M.skills??[]],V=new Map($.map((Ee,xe)=>[Ee.skillId,xe])),te=await Promise.allSettled(z.map(Ee=>Wc({agentId:e.agentId,workspace:_,framework:e.framework,skill:Ee}))),X=0;for(let[Ee,xe]of te.entries()){let N=z[Ee];N&&(xe.status==="fulfilled"?(Kc($,V,xe.value),X++):he.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:N.skillId,skillName:N.skillName,err:String(xe.reason)}))}X>0&&(M.skills=$,he.info("initialSkills installed",{agentId:e.agentId,installed:X,requested:z.length}))}return await Ye(M,this.paths),he.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:u}),{ok:!0,agentId:e.agentId,workspace:_,framework:e.framework}}catch(I){throw he.error("agent create failed, rolling back",{agentId:e.agentId,err:String(I)}),A&&b&&(await b.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Ry(l.root,{recursive:!0,force:!0}).catch(C=>he.warn("rm agent dir failed (ignored)",{err:String(C)})),I instanceof T?I:new T("AGENT_SPAWN_FAILED",String(I),{cause:I})}finally{clearTimeout(E)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&Jc(e.framework))u=By;else throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);Jc(e.framework)&&!os(e.framework)&&(he.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await tr(e.framework));let x=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:x,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path}):p=this.factory(e.framework,u.path,e.workspace,e.agentId,x,i,o,c,this.buildBinShimPathEnv());try{return await p.start(),await p.initialize(Fy),p}catch(w){let _=p instanceof Nt?p.getStderrTail():[];throw _.length>0&&he.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:w instanceof T?w.code:"unknown",recentStderr:_}),await p.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.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 T("AGENT_ENV_NOT_READY",bf(o),{cause:{reason:Ef}})}catch(o){he.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof T?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};he.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 he.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:zy}})}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",bf(r),{cause:{reason:Ef}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:l,command:u}=e,x=Yc(o);if(r.deployType==="local"){let S=await this.ensureOpenclawDefaultAgent();return new Rr({command:u,cwd:S.workspace,agentId:S.id,sessionName:x})}let p=await _f(),w=i?L0(i,c,l):null,_;if(w){let S=zc(o),b=w.models[0]?.id??Et,A=`${S}/${b}`;if(!this.ensuredProviders.has(A)){let I=this.getOpenclawConfig();await I.ensureProvider(S,w),await I.addModelToAllowlist(A),this.ensuredProviders.add(A)}_=A}return new Rr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:x,...p?{gatewayToken:p}:{},..._?{slashModelOnStart:_}:{}})}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=zc(i),c=`${o}/${e.model}`,l=!0;try{await r.removeProvider(o)}catch(u){l=!1,he.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){l=!1,he.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}l&&this.ensuredProviders.delete(c)}}};import{randomUUID as Tf}from"node:crypto";import{promises as Vy}from"node:fs";import{basename as Cf}from"node:path";We();ne();import{promises as qy}from"node:fs";import{basename as Hy}from"node:path";var vf=G("file-upload"),jy="/api/coze_claw/file/agent_upload",Wy=6e4;async function Sf(t,e={}){let i=`${to(ro(e.handshakeBase))}${jy}`,o=e.timeoutMs??Wy,c=await qy.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 u={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...br(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},x=new AbortController,p=setTimeout(()=>x.abort(),o);vf.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:u,body:l,signal:x.signal}),_=w.headers.get("x-tt-logid")??"";if(!w.ok){let b=await w.text().catch(()=>"");throw new T("UPLOAD_FAILED",`upload HTTP ${w.status} logid=${_}: ${b.slice(0,200)}`)}let S=await w.json();if(S.code!==void 0&&S.code!==0)throw new T("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${_}`);let E=S.data?.file?.file_url;if(!E)throw new T("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${_}: ${JSON.stringify(S).slice(0,200)}`);return vf.info("file upload ok",{uri:E,logid:_}),{uri:E}}catch(w){throw w instanceof T?w:w.name==="AbortError"?new T("UPLOAD_FAILED",`upload timeout (${o}ms) for ${Hy(t.path)}`):new T("UPLOAD_FAILED",String(w),{cause:w})}finally{clearTimeout(p)}}We();ne();import{extname as Ky}from"node:path";var $y={".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 If(t){let e=Ky(t).toLowerCase();return $y[e]??"application/octet-stream"}ke();var go=G("agent-send"),Af=50*1024*1024;function Df(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 Rf(t,e,r,i,o,c){let u;for(let x=0;x<=2;x++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(p){u=p,x<2&&(go.warn("sendAgentFileUpdate failed, retrying",{attempt:x+1,err:String(p)}),await new Promise(w=>setTimeout(w,5e3)))}throw new T("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function kf(t,e){let{session:r,runtime:i}=Df(e.core,t.agentId,t.sessionId);if(!await Xr(t.path,r.workspace))throw new T("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await Vy.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>Af)throw new T("FILE_TOO_LARGE",`${o.size} bytes > limit ${Af}`);let c=await If(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 l=t.name??Cf(t.path),u;try{u=await Sf({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 go.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:p instanceof T?p.code:"UNKNOWN",message:p instanceof Error?p.message:String(p)}),p}let x={sessionUpdate:"agent_file",messageId:Tf(),content:{type:t.kind==="image"?"image":"resource",uri:u.uri,mimeType:c,name:l,sizeBytes:o.size,...u.fileId!==void 0?{fileId:u.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await Rf(e,r,i,t.sessionId,x,"agent file uploaded to cloud but sendAgentFileUpdate failed"),go.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:l,bytes:o.size,mime:c,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:c,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function Pf(t,e){let{session:r,runtime:i}=Df(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??Cf(t.path),c={sessionUpdate:"group_file",messageId:Tf(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await Rf(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),go.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 Of(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,u=i[c]??0;if(l<u)return!0;if(l>u)return!1}return!1}nn();yn();ne();var Lt=G("coze-cli-installer"),Nf="@coze/cli@latest",Zy="coze",Lf="0.1.8",Yy=5e3,Jy=5e3,Xy=9e4,Mf=1e4,Bi=null,mo=!1;async function Xc(t,e={}){if(mo)return;if(Bi)return Bi;let r=e.exec??tf;return Bi=(async()=>{try{let i=await Qy(Zy,r),o=!1;if(i){let l=await eE(r);if(l===void 0)Lt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(Of(l,Lf))Lt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:l,min:Lf}),o=!0;else{Lt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:l}),mo=!0;return}}let c=o?"upgrade-only":"full";Lt.info("coze-cli install start",{package:Nf,mode:c});try{await r("npm",["i","-g","--prefer-online",Nf],{timeout:Xy,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){mo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:Mf}),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:Mf}),Lt.info("coze auth login ok")}catch(l){Lt.warn("coze auth login failed",{err:String(l)});return}mo=!0}finally{Bi=null}})(),Bi}async function Qy(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:Yy});return va(i)}catch{return}}async function eE(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:Jy});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}Jr();ke();var tE=10*6e4;function Bf(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?tE:e}function wo(t){return nr(t??J().configFile)}function zi(t,e){return rr(e??J().configFile,t)}import{randomBytes as EE}from"node:crypto";Xn();We();ne();import{createReadStream as nE}from"node:fs";import{mkdir as rE,readFile as iE,realpath as sE,stat as oE,writeFile as aE}from"node:fs/promises";import{basename as cE,dirname as Qc,isAbsolute as dE,join as lE,relative as uE,resolve as zf,sep as fE}from"node:path";import{createInterface as xE}from"node:readline";var Uf=G("fs-rpc"),Fi=He("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function Gf(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Fi)throw new T("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Fi} bytes`);let i=await Hf(t.path,e);return await rE(Qc(i),{recursive:!0}),await aE(i,t.content,"utf8"),Uf.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function qf(t,e){let r=await Hf(t.path,e),i=await oE(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Fi&&!o)throw new T("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Fi} bytes`);let c;if(o&&i.size>Fi)c=await hE(r,t.line??1,t.limit);else{let l=await iE(r,"utf8");if(o){let u=l.split(`
100
+ `),x=Math.max(0,(t.line??1)-1),p=typeof t.limit=="number"?x+t.limit:void 0;c=u.slice(x,p).join(`
101
+ `)}else c=l}return Uf.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function hE(t,e,r){let i=xE({input:nE(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,l=[],u=0;try{for await(let x of i)if(u>=o&&u<c&&l.push(x),u++,u>=c)break}finally{i.close()}return l.join(`
102
+ `)}async function Hf(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([Ff(zf(e)),Ff(zf(t))]),o=uE(r,i);if(pE(o,fE,dE(o)))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function pE(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function Ff(t){let e=[],r=t;for(;r!==Qc(r);)try{let i=await sE(r);return e.length?lE(i,...e.reverse()):i}catch{e.push(cE(r)),r=Qc(r)}return t}ne();var jf=G("prompt-multimodal"),Wf=10*1024*1024,gE=15e3,mE=6;async function Kf(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 wE(l))}}let o=Array.from({length:Math.min(mE,t.length)},()=>i());return await Promise.all(o),e}function $f(t){return t.some(e=>e.type==="image")}async function wE(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!eo(e.uri))return t;try{let{buf:r,contentType:i}=await yE(e.uri),o=e.mimeType||_E(i)||"application/octet-stream";return jf.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 jf.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function _E(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function yE(t){let e=new AbortController,r=setTimeout(()=>e.abort(),gE);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>Wf)throw new Error(`image too large: ${o.byteLength} bytes (max ${Wf})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}rn();We();ne();var K=G("core"),bE=3e4,vE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,SE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",IE="\u5BA1\u6279\u5DF2\u8D85\u65F6",AE=3e4,_o=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Tr;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=Bf(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(),K.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){K.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),K.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){K.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)&&K.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)=>{K.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:l}),Mi(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){K.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=>K.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)){K.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 T("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(oo(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&&vE.test(i)?this.currentCozeEnv=i:i&&K.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}`):K.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(Ar(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Ar(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Ar(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,ee.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):K.warn("drop unknown notification",{method:e.method})}catch(o){K.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(_n(r,Oi(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 x=o.sessions.get(c);if(x?.pendingPermission){let p=r._meta?.cozeTriggerMsgId,w=Oc(r._meta);return K.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,x,c,SE,p,w)}}let l=Date.now(),u=!1;try{let x=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,x}finally{K.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-l,ok:u})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=b0(i);switch(r){case"session/new":{let c=TE();return K.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return K.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 T("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=await this.ensureRuntime(e,l);if(u.replySeq=0,await this.ensureDownstream(e,l,u),!u.downstream||!u.acpSessionId)throw new T("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");let x=i._meta?.cozeTriggerMsgId;x?e.activeTriggers.set(u.acpSessionId,x):e.activeTriggers.delete(u.acpSessionId);let p=Oc(i._meta);if(p?e.activeGroupIds.set(u.acpSessionId,p):e.activeGroupIds.delete(u.acpSessionId),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&$f(c.prompt))throw new T("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let w=await Kf(c.prompt);try{let _=await u.downstream.sessionPrompt({...c,sessionId:u.acpSessionId,prompt:w});return u.lastActiveAt=Date.now(),_}catch(_){if(_ instanceof T&&_.code==="AGENT_APPROVAL_TIMEOUT"){let S=u.pendingPermission;S&&(S.downstream.respondAgentRequest(S.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(S.upstreamId),u.pendingPermission=void 0);let E=u.acpSessionId,b=E?e.activeTriggers.get(E):void 0,A=E?e.activeGroupIds.get(E):void 0;return K.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:l}),await this.synthesizePromptReply(e,u,l,IE,b,A)}throw _}finally{if(e.activeTriggers.delete(u.acpSessionId),e.activeGroupIds.delete(u.acpSessionId),u.pendingPermission=void 0,u.reloadAfterTurn){u.reloadAfterTurn=!1;let _=u.downstream;_&&(u.downstream=void 0,K.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:l,acpId:u.acpSessionId}),_.stop("reload-after-turn").catch(S=>K.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:l,err:String(S)})))}else u.downstream?.isAlive()&&this.armIdleTimer(e,l,u)}}case"session/cancel":{let l=o.sessionId;if(!l)throw new T("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(l);if(e.hasSessionQueue(l)){let x=e.getSessionQueue(l);x.size>0&&(K.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:l,queuedCount:x.size}),x.dispose(new T("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${l}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.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(yt.GEN_MODEL_TOKEN,i,AE);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(Mi(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,l=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(l>=o&&Date.now()-u<c)throw new T("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()-u))/1e3)}s`);let x;try{x=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&&(K.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),p}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=x,this.attachRuntimeHooks(e,r,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await x.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),K.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(p){K.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 x.sessionNew({cwd:e.workspace});i.acpSessionId=w.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let p=await x.sessionNew({cwd:e.workspace});i.acpSessionId=p.sessionId,await this.persistSessionMapping(e)}}catch(p){throw K.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(p)}),await x.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,p}x.afterSessionEstablished&&i.acpSessionId&&await x.afterSessionEstablished(i.acpSessionId)}armIdleTimer(e,r,i){if(Mi(i),this.isRuntimeBusy(e,i)){K.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)){K.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}K.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=>K.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 u=e.activeGroupIds.get(r.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Ir("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,l){let u={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(u.cozeTriggerMsgId=c),l&&(u.cozeGroupId=l),await this.upstream.send(Ir("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(x=>K.warn("synthesizePromptReply update send failed (ignored)",{err:String(x)})),{stopReason:"end_turn"}}forwardUpdate(e,r){let i=r.sessionId,o=this.reverseSessionId(e,i);if(!o){K.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){K.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(RE(r)){K.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let l={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},u=e.activeTriggers.get(i);u&&(l.cozeTriggerMsgId=u);let x=e.activeGroupIds.get(i);x&&(l.cozeGroupId=x),this.upstream.send(Ir("session/update",{...r,sessionId:o,_meta:l})).catch(p=>K.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}K.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 Gf(c,o);r.respondAgentRequest(i.id,l)}else{let c=i.params??{},l=await qf(c,o);r.respondAgentRequest(i.id,l)}}catch(o){K.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Oi(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??{},u=c.sessionId,x=u?e.activeTriggers.get(u):void 0,p={cozeAgentId:e.agentId};x&&(p.cozeTriggerMsgId=x);let w=u?e.activeGroupIds.get(u):void 0;w&&(p.cozeGroupId=w);let _=u?this.reverseSessionId(e,u):void 0,S=_?e.sessions.get(_):void 0;S&&(S.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let E={...c,..._?{sessionId:_}:{},_meta:p};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:_}),K.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:_,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(b=>({optionId:b.optionId,kind:b.kind,name:b.name}))}),this.upstream.send(ki(o,"session/request_permission",E)).catch(b=>{this.pendingUpstream.delete(o),K.error("forward permission request failed",{agentId:e.agentId,err:String(b)}),r.respondAgentRequestError(i.id,{code:ee.INTERNAL_ERROR,message:`upstream send failed: ${String(b)}`})})}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?(K.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"&&CE(e.result,o),K.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 so(e.error)):i.value.resolve(e.result);return}K.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 K.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:l,key:c}}}sendRequest(e,r,i=bE){let o=this.upstreamIds.next(e);return new Promise((c,l)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),l(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:l,timer:u}),this.upstream.send(ki(o,e,r)).catch(x=>{let p=this.pendingBridge.get(o);p&&(clearTimeout(p.timer),this.pendingBridge.delete(o)),l(x)})})}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 Qr(e.agentId,r,this.paths)}catch(r){K.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:Sr}}))}};function TE(){return EE(16).toString("hex")}function CE(t,e){if(!t||typeof t!="object"){K.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){K.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"){K.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")&&K.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var DE=["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 RE(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 DE.some(c=>o.startsWith(c))}ne();ke();import{randomBytes as kE}from"node:crypto";import{chmod as PE,mkdir as OE,writeFile as Vf}from"node:fs/promises";import{createServer as NE}from"node:http";import{dirname as LE}from"node:path";var ME=1e6,ed=G("ipc"),yo=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??J()}async start(){this.token=kE(32).toString("hex");let e=NE((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(),ed.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 OE(LE(this.paths.portFile),{recursive:!0}),await Vf(this.paths.portFile,String(this.port),"utf8"),await Vf(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await PE(this.paths.tokenFile,384)}catch(e){ed.warn("chmod token file failed (non-POSIX?)",{err:String(e)})}}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Ui(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Ui(r,404,{error:"not found"});return}let l=null;if(e.method==="POST")try{l=await BE(e)}catch(u){Ui(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(l,e);Ui(r,200,u??{ok:!0})}catch(u){ed.error("IPC handler failed",{key:o,err:String(u)}),Ui(r,500,{error:u instanceof Error?u.message:String(u)})}}};function Ui(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function BE(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>ME)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}var mh=It(sx(),1);var mv=It(th(),1),wv=It(Mo(),1),_v=It(Or(),1),yv=It(xd(),1),Ev=It(gd(),1),bv=It(bd(),1),lh=It(Uo(),1),vv=It(dh(),1);var uh=lh.default;We();ne();var De=G("upstream.frontier"),xh="application/json",hh="none",Iv=15e3;function Av(t){class e extends uh{constructor(i){super(i,S0,{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(ll("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 Zi=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:I0,...br(this.opts.ppeOverride)},r=Av(e),i=T0(this.opts.urlOverride),o={url:i,ws:r,fpID:v0,aID:no,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:xh,force:!0},payloadEncoding:{encoding:hh,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new mh.FWS(o),l=!1,u=null,x,p,w=new Promise((E,b)=>{x=E,p=b}),_=E=>{l||(l=!0,u&&(clearTimeout(u),u=null),E?p(E):x())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let E=this.openCount===1;De.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:E,openCount:this.openCount}),E&&_();for(let b of this.connectHandlers)Promise.resolve(b({initial:E})).catch(A=>De.warn("onConnect handler threw (ignored)",{err:String(A)}))},c.onclose=E=>{this.opened=!1,De.info("frontier closed",{code:E.code,reason:E.reason,willReconnect:E.willReconnect})},c.onerror=E=>{De.warn("frontier error",{code:E.code,msg:E.message}),_(new T("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${E.code} msg=${E.message??""}`))},c.onmessage=E=>this.handleMessage(E),this.fws=c;let S=this.opts.openTimeoutMs??Iv;u=setTimeout(()=>{_(new T("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${S}ms (handshake or upgrade slow)`))},S),await c.connect();try{await w}catch(E){try{c.close(1e3,"open failed")}catch(b){De.warn("fws close during start failure threw (ignored)",{err:String(b)})}throw this.fws=null,this.opened=!1,E}}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 T("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let u=Date.now();throw u-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=u,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;ph(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:xh,payloadEncoding:hh})}catch(u){throw De.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new T("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}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=Dv(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;ph(c)||De.info("frontier frame in",{logid:Cv(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:Tv(i)}),Promise.resolve(this.handler(o)).catch(l=>De.warn("frontier frame handler threw",{err:String(l)}))}};function ph(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var gh=2e3;function Tv(t){return t.length<=gh?t:`${t.slice(0,gh)}...<truncated, total ${t.length} chars>`}function Cv(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function Dv(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 Sd=G("upstream.switchable"),qo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;Sd.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 Sd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>Sd.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 Id=G("upstream"),Fr=class{handler=null;async start(){Id.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Id.info("NoopUpstream stopped",{reason:e})}async send(e){Id.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)}};We();ne();ne();ke();import{promises as Ad}from"node:fs";import{dirname as Rv}from"node:path";var kv=G("pat-token-store");async function Ho(t=J()){try{let r=(await Ad.readFile(t.patTokenFile,"utf8")).trim();return r.length>0?r:null}catch(e){let r=e?.code;return r!=="ENOENT"&&kv.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function Yi(t,e=J()){if(!t)throw new Error("writePatToken: empty patToken");await Ad.mkdir(Rv(e.patTokenFile),{recursive:!0}),await Ad.writeFile(e.patTokenFile,t,{encoding:"utf8",mode:384})}ke();ke();import{promises as jo}from"node:fs";import{join as Pv}from"node:path";function Ov(t,e){return`#!/bin/sh
102
103
  exec ${JSON.stringify(e)} ${JSON.stringify(t)} "$@"
103
- `}function Iv(t,e){return`@echo off\r
104
+ `}function Nv(t,e){return`@echo off\r
104
105
  "${e}" "${t}" %*\r
105
- `}async function lx(t,e=X()){let r=e.binDir;await Go.mkdir(r,{recursive:!0});let i=vv(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?Iv(t,o):Sv(t,o);return await Go.readFile(i,"utf8").catch(()=>null)===c||(await Go.writeFile(i,c,"utf8"),process.platform!=="win32"&&await Go.chmod(i,493)),r}te();Pe();import{execSync as ux}from"node:child_process";import{readFileSync as fx,unlinkSync as Av}from"node:fs";import{mkdir as Tv,readFile as hx,unlink as xx,writeFile as Cv}from"node:fs/promises";import{dirname as Rv}from"node:path";var Dv=U("single-instance"),qo=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&&(Dv.warn("removing stale pid file",{stalePid:e}),await xx(this.pidFile).catch(()=>{})),await Tv(Rv(this.pidFile),{recursive:!0}),await Cv(this.pidFile,String(process.pid),"utf8"),this.acquired=!0,this.installCleanupHooks(),{kind:"acquired"})}async release(){if(this.acquired){try{(await hx(this.pidFile,"utf8")).trim()===String(process.pid)&&await xx(this.pidFile)}catch{}this.acquired=!1}}async readExistingPid(){try{let e=await hx(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 ro(e)?this.matchesDaemonTitle(e):!1}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let r=fx(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes("coze-bridge-daemon")||r.includes("lib/index.js"))}catch{}try{let r=ux(`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=ux(`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{fx(this.pidFile,"utf8").trim()===String(process.pid)&&Av(this.pidFile)}catch{}})}};jo();te();var Wn=U("daemon.upstream-watchdog"),zv=12e4,Fv=9e5,Uv=3e4;function Id(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Ho=class{constructor(e){this.opts=e;this.softMs=e.softMs??Id("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",zv),this.hardMs=e.hardMs??Id("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",Fv),this.intervalMs=e.intervalMs??Id("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",Uv),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 j=U("daemon"),Gv="coze-bridge-daemon";async function mx(){let t=X();process.env.COZE_BRIDGE_LOG_MODE!=="legacy"&&rl({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:O=>Je(O,t).logs,listAgentIds:()=>ns(t)});let e=new qo({processTitle:Gv}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await po(),o=i??{};es({pid:process.pid}),j.info(i?"loaded bridge config":"initialized bridge config");let c=new Fo(new Mr),l=null,u=new go({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(O,G,W,re)=>{if(!l)throw new Error("agentManager not ready");return l.spawnSessionDownstream(O,G,W,re)}}),h=new fo({paths:t,config:o,registry:u});l=h;let p,_,E=null,A={},b,v=null,I=null,S=null,R=new _n;function N(O,G){return R.enqueue(()=>D(O,G))}function y(){I||(I=new Ho({isConnected:()=>c.isConnected(),forceReconnect:()=>S?N(S,{force:!0}):void 0,onFatal:O=>{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:O});return}j.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:O}),process.exit(1)}})),I.start()}async function D(O,G){let W=O,re=W?.privatecode;if(!re)throw new C("IPC_BAD_REQUEST","/connect requires privatecode");let Ke=Ai(W.env),le=W.handshake_url,ue=W.frontier_url,bt=gx(W.env,le,ue);if(S=W,!G?.force&&p===re&&_===bt){let ge=await qv(t);return u.agents.size===0&&ge?(j.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),Ko(t,h).catch(Ie=>j.warn("connect-noop auto-revive error (ignored)",{err:String(Ie)}))):j.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let lt=!!p&&p!==re,Zt=_!==void 0&&_!==bt,Bt=lt||Zt,Xt=await Pc({privatecode:re,...le?{endpoint:le}:{},ppeOverride:Ke});if(Bt){j.warn("connect config switched, resetting agents",{pcChanged:lt,envChanged:Zt,previousPc:p?Wo(p):"",nextPc:Wo(re)});for(let ge of[...u.agents.values()])await ge.dispose("connect config switch").catch(()=>{}),u.agents.delete(ge.agentId);u.disconnectedAgents.size>0&&(j.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Mr,"connect switch").catch(()=>{})}E=Xt.deviceId,es({deviceId:E,pid:process.pid}),Jc({patToken:re,env:W.env}).catch(ge=>j.warn("coze-cli setup error (ignored)",{err:String(ge)}));let Gr=new Wi({handshake:Xt,privatecode:re,...ue?{urlOverride:ue}:{},ppeOverride:Ke,getPatTokenForAgent:ge=>u.agents.get(ge)?.patToken});return await c.swap(Gr,"connect"),p=re,_=bt,A=Ke,b=le,W.mock_scenario!==void 0&&(u.setMockScenario(W.mock_scenario),j.info("mock scenario set",{scenario:W.mock_scenario})),v||(v=new Ci({core:u,getDeviceId:()=>E??"",onTickEnd:()=>z.retryPending().catch(ge=>j.warn("detailSync.retryPending failed (ignored)",{err:String(ge)})),onAuthFailures:$})),v.start(),y(),Bt&&Ko(t,h).catch(ge=>j.warn("post-connect-switch auto-revive error (ignored)",{err:String(ge)})),Ki(re,t).catch(ge=>j.warn("writePatToken after /connect failed (ignored)",{err:String(ge)})),j.info("/connect: WS established",{deviceId:E}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async O=>h.createAgent(O.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let P={},M=new Qs({agents:u.agents,disposeAndMarkDisconnected:async(O,G)=>{let W=u.agents.get(O);if(W){await h.cleanupOpenclawSessionProviders(W).catch(Ke=>j.warn("cleanup openclaw providers failed (ignored)",{agentId:O,err:String(Ke)}));let re=!0;try{await W.dispose(`disconnect: ${G}`)}catch(Ke){re=!1,j.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:O,err:String(Ke)}),W.status="error"}re&&(W.status="disconnected",u.unregister(O),u.disconnectedAgents.add(O))}else u.disconnectedAgents.add(O)},detailSyncer:async O=>{if(!P.ref)throw new Error("agent-detail-sync not initialized yet");await P.ref.syncOne(O)},cleanupOpenclawProviders:async O=>{await h.cleanupOpenclawSessionProviders(O)},openclawRepair:async(O,G)=>{await h.openclawRepair(O,G)},isRuntimePendingPermission:O=>u.hasPendingPermissionFor(O)});u.registerExtension("_agent/listSkills",O=>M.listSkills(O.params)),u.registerExtension("_agent/addSkills",O=>M.addSkills(O.params)),u.registerExtension("_agent/removeSkills",O=>M.removeSkills(O.params)),u.registerExtension("_agent/getFileTree",O=>M.getFileTree(O.params)),u.registerExtension("_agent/getFileContent",O=>M.getFileContent(O.params)),u.registerExtension("_agent/update",O=>M.updateAgent(O.params)),u.registerExtension("_agent/disconnect",O=>M.disconnectAgent(O.params)),u.registerExtension("_agent/switchModel",O=>M.switchModel(O.params)),u.registerExtension("_agent/reset",O=>M.resetAgent(O.params)),u.registerExtension("_agent/repair",O=>M.repairAgent(O.params));let z=new os({paths:t,handlers:M,sendDetail:O=>u.sendRequest("_agent/detail",O)});P.ref=z;let $=async O=>{await Promise.allSettled(O.map(async G=>{try{await M.disconnectAgent({agentId:G.agentId,reason:`auth_failure: code=${G.code} ${G.message}`}),j.info("agent disconnected due to auth failure from heartbeat response",{agentId:G.agentId,code:G.code,message:G.message})}catch(W){j.warn("disconnect during authFailure handling failed (ignored)",{agentId:G.agentId,err:String(W)})}}))};c.onConnect(({initial:O})=>{j.info("frontier upstream connected, triggering detail sync",{initial:O}),z.syncAll(O?"initial-connect":"reconnect").catch(G=>j.warn("detail sync top-level error (ignored)",{err:String(G)}))});let V=new mo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let O=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[$i]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:E??"",frameworksCache:o.frameworksCache??{},...O?{mockScenario:O}:{}}}},{method:"POST",path:"/pair",handler:async O=>{let G=O,W=G?.privatecode,re=G?.pairing_code;if(!W||!re)throw new C("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Ke=Ai(G.env),le=G.handshake_url,ue=G.frontier_url,bt=gx(G.env,le,ue),lt=!!p&&p!==W,Zt=_!==void 0&&_!==bt,Bt=lt||Zt,Xt=await Pc({privatecode:W,...le?{endpoint:le}:{},ppeOverride:Ke});if(Bt){j.warn("pair config switched, resetting agents",{pcChanged:lt,envChanged:Zt,previousPc:p?Wo(p):"",nextPc:Wo(W),previousEnvKey:_??"",nextEnvKey:bt});for(let Ie of[...u.agents.values()])await Ie.dispose("pair config switch").catch(()=>{}),u.agents.delete(Ie.agentId);u.disconnectedAgents.size>0&&(j.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Mr,"pair switch").catch(()=>{})}E=Xt.deviceId,es({deviceId:E,pid:process.pid}),Jc({patToken:W,env:G.env}).catch(Ie=>j.warn("coze-cli setup error (ignored)",{err:String(Ie)}));let Gr=new Wi({handshake:Xt,privatecode:W,...ue?{urlOverride:ue}:{},ppeOverride:Ke,getPatTokenForAgent:Ie=>u.agents.get(Ie)?.patToken});await c.swap(Gr,"pair");try{let Ie=new Fn;o.frameworksCache=await Ie.detectAll(),await Ni(o),j.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ie){j.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ie)})}let ge=Object.keys(o.frameworksCache??{});try{let Ie=await u.sendRequest("_agent/pair",{pairCode:re,patToken:W,frameworks:ge,_meta:{cozeDeviceId:E}});j.info("_agent/pair ok",{pairResult:Ie}),p=W,_=bt,A=Ke,b=le,G.mock_scenario!==void 0&&(u.setMockScenario(G.mock_scenario),j.info("mock scenario set",{scenario:G.mock_scenario})),Ki(W,t).catch(De=>j.warn("writePatToken after /pair failed (ignored)",{err:String(De)})),v||(v=new Ci({core:u,getDeviceId:()=>E??"",onTickEnd:()=>z.retryPending().catch(De=>j.warn("detailSync.retryPending failed (ignored)",{err:String(De)})),onAuthFailures:$})),v.start(),y(),Bt&&Ko(t,h).catch(De=>j.warn("post-pair-switch auto-revive error (ignored)",{err:String(De)}));let Kn;return G.agent_id&&(Kn=await Hv(G.agent_id,t,h,De=>u.sendRequest("_agent/detail",De),W).catch(De=>(j.error("--agent-id ensureAgent failed",{agentId:G.agent_id,err:String(De)}),{ok:!1,agentId:G.agent_id??"",note:String(De)}))),{ok:!0,note:"paired with cloud",...Kn?{agent:Kn}:{}}}catch(Ie){return j.error("_agent/pair failed",{err:String(Ie)}),{ok:!1,note:`pair failed: ${String(Ie)}`}}}},{method:"POST",path:"/connect",handler:O=>N(O)},{method:"POST",path:"/_agent/create",handler:async O=>{let G=O;return{ok:!0,result:await h.createAgent(G)}}},{method:"POST",path:"/agent/send",handler:async O=>{let G=O;if(!G?.agentId||!G?.sessionId||!G?.kind||!G?.path)throw new C("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!p)throw new C("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let W=G;return await(W.groupFile?I0:S0)(W,{core:u,patToken:p,handshakeBase:b,ppeOverride:A})}catch(W){if(W instanceof C)return{ok:!1,code:W.code,message:W.message};throw W}}},{method:"POST",path:"/reload",handler:async O=>{let G=O?.agent_id,W=await u.reloadAgents(G);return j.info("IPC /reload: recycled agent subprocesses",{agentId:G??"(all)",recycled:W}),{ok:!0,recycled:W}}},{method:"POST",path:"/shutdown",handler:async()=>(j.info("IPC /shutdown received"),setImmediate(()=>{he.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:ee,token:Y}=await V.start();try{await lx(t.libEntry,t)}catch(O){j.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(O)})}await u.start(),Wv({paths:t,core:u,agentManager:h,detectAll:async()=>(o.frameworksCache=await new Fn().detectAll(),await Ni(o),o.frameworksCache)}).catch(O=>j.warn("startup warmup error (ignored)",{err:String(O)})),hl().then(async()=>{let{probeAcpVersion:O}=await Promise.resolve().then(()=>(en(),ul));for(let G of["claude-code","codex"]){let W=await O(G);W&&j.info("acp wrapper version",{framework:G,version:W})}}).catch(O=>j.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(O)}));let be=null,he={port:ee,token:Y,core:u,ipc:V,shutdown(O){return be||(j.info("daemon shutdown",{reason:O}),be=(async()=>{v?.stop(),I?.stop(),await u.stop(O),await V.stop(),await e.release()})(),be)}};for(let O of["SIGTERM","SIGINT"])process.on(O,()=>{he.shutdown(O).then(()=>process.exit(0))});return process.on("exit",()=>e0()),process.on("unhandledRejection",O=>{j.error("unhandledRejection",{reason:O instanceof Error?O.message:String(O),stack:O instanceof Error?O.stack:void 0})}),process.on("uncaughtException",O=>{j.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)}),j.info("daemon ready",{port:ee,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),Kv({cliSpawned:process.env[$i]==="1",readPatToken:()=>Uo(t),connect:N}).catch(O=>j.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(O)})),he}async function qv(t){return ns(t).length>0}function Wo(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function gx(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function jv(t,e){let r=ns(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(tn(),ss));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 Hv(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(tn(),ss)),l=await c(t,e);if(l){j.info("--agent-id: local config found, reconnecting",{agentId:t,framework:l.framework,hadDisconnect:!!l.disconnectedAt});let _={agentId:l.agentId,framework:l.framework,...l.cozeIdentity?{cozeIdentity:l.cozeIdentity}:{},...l.model?{model:l.model}:{},...o?{patToken:o}:{}};return await r.createAgent(_),{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 u=await i({_meta:{cozeAgentId:t}});if(!u.framework)throw new C("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:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...u.deployType?{_meta:{cozeDeployType:u.deployType}}:{}};await r.createAgent(h);let p=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:p?"cloud agent acknowledged":"created from cloud detail"}}async function Wv(t){let e=t.logger??j;try{let r=await t.detectAll();e.info("refreshed frameworks_cache",{detected:Object.keys(r??{})})}catch(r){e.warn("framework detection failed (using cached)",{err:String(r)})}await jv(t.paths,t.core).catch(r=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(r)})),await Ko(t.paths,t.agentManager).catch(r=>e.warn("auto-revive top-level error (ignored)",{err:String(r)}))}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(()=>(tn(),ss));j.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,l=0;for(let u of i){let h;try{h=await o(u,t)}catch(p){j.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(p)}),l+=1;continue}if(!h){l+=1;continue}if(h.disconnectedAt){j.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:h.disconnectedAt}),l+=1;continue}try{j.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:h.framework});let p=$v(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:u,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 Kv(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 $v(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}jo();Pe();import{readFile as _x}from"node:fs/promises";var Jt=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:Jv(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 u=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 u.text();return{status:u.status,body:Vv(h)}}finally{clearTimeout(l)}}};async function $o(t){try{let[e,r]=await Promise.all([_x(t.portFile,"utf8"),_x(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 Vv(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function Jv(t){return t instanceof Error?t.message:String(t)}wn();te();Pe();function En(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],l=!1;for(let u of e){if(c===u){i=t[o+1],o+=1,l=!0;break}if(c.startsWith(`${u}=`)){i=c.slice(u.length+1),l=!0;break}}l||r.push(c)}return{value:i,rest:r}}en();import{chmod as Zv,copyFile as yx,mkdir as Ex,readFile as Vo,rename as bx,rm as Ad,stat as vx,writeFile as Xv}from"node:fs/promises";import{homedir as OR}from"node:os";import{dirname as Yv,join as Br,resolve as Td,sep as Vi}from"node:path";import{fileURLToPath as Qv}from"node:url";wn();te();Pe();var Cd=U("dist-install");function e1(t){let e=Qv(t),r=Yv(e),i=`${Vi}src${Vi}`;if(r.includes(i)||r.endsWith(`${Vi}src${Vi}cli`))return null;let o=Td(r,"index.js"),c=Td(r,"..","package.json");return{dist:o,pkgJson:c}}async function Dd(t={}){let e=t.paths??X(),r=e1(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 A=JSON.parse(await Vo(o,"utf8"));c=A.version??"unknown",l=A.dependencies??{}}catch(A){return Cd.warn("cannot read source package.json,skip dist install",{err:String(A)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(A)}`}}let u=$r.map(A=>`${A}@${l[A]??"latest"}`),h=await po(e.configFile)??{},p=h.libVersion,_=await Vo(e.libEntry).then(()=>!0).catch(()=>!1),E=p===c;if(E&&_&&await Rd(e))return{kind:"already-current",libVersion:c};if(!E||!_){await Ex(e.libDir,{recursive:!0}),await yx(i,e.libEntry),await yx(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let A=Td(e.libDir,"package.json"),b=`${JSON.stringify({type:"module"},null,2)}
107
- `;await Vo(A,"utf8").catch(()=>null)!==b&&await Xv(A,b)}return(!E||!await Rd(e))&&await(t.installWrappers??t1)(e,u),h.libVersion=c,await Ni(h,e.configFile),Cd.info("dist installed",{libEntry:e.libEntry,fromVersion:p,toVersion:c}),E&&_?{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 Rd(t){for(let e of $r){let r=Br(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await vx(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function t1(t,e){await i1(t.installLock,async()=>{if(await Rd(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 Ex(i,{recursive:!0}),await n1(e,i),await r1(o);let l=`${c}.trash-${r}`;await bx(c,l).catch(()=>{}),await bx(o,c),await Ad(l,{recursive:!0,force:!0}).catch(()=>{}),Cd.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await Ad(i,{recursive:!0,force:!0}).catch(()=>{})}})}function n1(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"]}),l="";c.stderr?.on("data",h=>{l.length<8192&&(l+=h.toString("utf8"))});let u=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",h=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(h)}`))}),c.once("close",h=>{clearTimeout(u),h===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${h}: ${l.trim().slice(0,2e3)}`))})})}async function r1(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 vx(c);process.platform!=="win32"&&!(l.mode&73)&&await Zv(c,l.mode|73).catch(()=>{})}}async function i1(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 Ad(t,{force:!0}).catch(()=>{})}}ga();te();Pe();import{closeSync as Ix,fstatSync as Ax,openSync as Tx,readFileSync as s1,readSync as o1,readdirSync as a1,statSync as c1}from"node:fs";import{join as Jo}from"node:path";var d1=new Set(["debug","info","warn","error"]);function Cx(t){let e=t,r=En(e,"--agent-id");e=r.rest;let i=En(e,"--date");e=i.rest;let o=En(e,"-n","--lines");e=o.rest;let c=En(e,"--level");e=c.rest;let l=En(e,"--grep");e=l.rest;let u=o.value===void 0?200:Number(o.value),h=Number.isInteger(u)&&u>=0?u:200,p=c.value&&d1.has(c.value)?c.value:void 0,_={lines:h,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(_.agentId=r.value),i.value&&(_.date=i.value),p&&(_.level=p),l.value&&(_.grep=l.value),_}function l1(t,e){return t.agentId?Jo(Je(t.agentId,e).logs,Zn("agent",t.date)):Jo(e.bridgeLogsDir,Zn("bridge",t.date))}function u1(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function f1(t,e){let r;try{r=a1(t)}catch{return[]}let i=[];for(let o of r){let c=pa(o,e);if(!c)continue;let l=0;try{l=c1(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 Rx(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"&&!ol(r,e.level))return!1}return!0}var Sx={debug:"90",info:"36",warn:"33",error:"31"},h1=new Set(["ts","level","module","msg"]);function x1(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function Dx(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=x1(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&Sx[o]&&(c=`\x1B[${Sx[o]}m${c}\x1B[0m`);let l=typeof r.module=="string"?r.module:"",u=typeof r.msg=="string"?r.msg:"",h=Object.entries(r).filter(([p])=>!h1.has(p)).map(([p,_])=>` ${p}=${typeof _=="string"?_:JSON.stringify(_)}`).join("");return`${i} ${c} ${l} ${u}${h}`}function p1(t,e,r){let c=s1(t,"utf8").split(`
108
- `).filter(l=>l.length>0).filter(l=>Rx(l,{level:e.level,grep:e.grep}));for(let l of u1(c,e.lines))process.stdout.write(`${Dx(l,{raw:e.raw,color:r})}
109
- `)}async function Px(t,e){let r=e.paths??X(),i=process.stdout.isTTY===!0;if(t.list){let l=t.agentId?Je(t.agentId,r).logs:r.bridgeLogsDir,u=t.agentId?"agent":"bridge",h=f1(l,u);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??Sn(new Date),c=l1({agentId:t.agentId,date:o},r);try{p1(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
106
+ `}async function wh(t,e=J()){let r=e.binDir;await jo.mkdir(r,{recursive:!0});let i=Pv(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?Nv(t,o):Ov(t,o);return await jo.readFile(i,"utf8").catch(()=>null)===c||(await jo.writeFile(i,c,"utf8"),process.platform!=="win32"&&await jo.chmod(i,493)),r}ne();ke();import{execSync as _h}from"node:child_process";import{readFileSync as yh,unlinkSync as Lv}from"node:fs";import{mkdir as Mv,open as Bv,readFile as Eh,unlink as Td,writeFile as zv}from"node:fs/promises";import{dirname as Fv}from"node:path";var Uv=G("single-instance"),Gv=t=>new Promise(e=>setTimeout(e,t)),Wo=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??J().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:r=>Ni(r),isDaemon:r=>this.matchesDaemonTitle(r)},e.processTitle&&(process.title=e.processTitle)}async acquire(){let e=await this.readExistingPid();if(e!==null&&e!==this.selfPid&&this.isLiveDaemon(e))return{kind:"already-running",pid:e};let r=await this.withClaimLock(async()=>{let i=await this.readExistingPid();return i!==null&&i!==this.selfPid&&this.isLiveDaemon(i)?{kind:"already-running",pid:i}:(i!==null&&i!==this.selfPid&&Uv.warn("removing stale pid file",{stalePid:i}),await zv(this.pidFile,String(this.selfPid),"utf8"),{kind:"acquired"})});return r.kind==="acquired"&&(this.acquired=!0,this.installCleanupHooks()),r}async release(){if(this.acquired){try{(await Eh(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Td(this.pidFile)}catch{}this.acquired=!1}}isLiveDaemon(e){return this.probe.isAlive(e)&&this.probe.isDaemon(e)}async readExistingPid(){return this.readPidFrom(this.pidFile)}async readPidFrom(e){try{let r=await Eh(e,"utf8"),i=Number.parseInt(r.trim(),10);return Number.isFinite(i)&&i>0?i:null}catch(r){if(r.code==="ENOENT")return null;throw r}}async withClaimLock(e){let r=`${this.pidFile}.lock`;await Mv(Fv(r),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await Bv(r,"wx")}catch(c){if(c.code!=="EEXIST")throw c;let l=await this.readPidFrom(r);if(l!==null&&l!==this.selfPid&&this.probe.isAlive(l)){await Gv(this.claimLockIntervalMs);continue}await Td(r).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Td(r).catch(()=>{})}}throw new Error(`failed to acquire claim lock: ${r} (after ${this.claimLockMaxAttempts} attempts)`)}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let r=yh(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes(Cr)||r.includes("lib/index.js"))}catch{}try{let r=_h(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes(Cr)||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=_h(`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{yh(this.pidFile,"utf8").trim()===String(this.selfPid)&&Lv(this.pidFile)}catch{}})}};Ko();ne();var $n=G("daemon.upstream-watchdog"),Zv=12e4,Yv=9e5,Jv=3e4;function Dd(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var $o=class{constructor(e){this.opts=e;this.softMs=e.softMs??Dd("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",Zv),this.hardMs=e.hardMs??Dd("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",Yv),this.intervalMs=e.intervalMs??Dd("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",Jv),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 H=G("daemon");async function Sh(){let t=J();process.env.COZE_BRIDGE_LOG_MODE!=="legacy"&&cl({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:N=>Ze(N,t).logs,listAgentIds:()=>as(t)});let e=new Wo({processTitle:Cr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await wo(),o=i??{};ss({pid:process.pid}),H.info(i?"loaded bridge config":"initialized bridge config");let c=new qo(new Fr),l=null,u=new _o({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(N,q,j,ie)=>{if(!l)throw new Error("agentManager not ready");return l.spawnSessionDownstream(N,q,j,ie)}}),x=new po({paths:t,config:o,registry:u});l=x;let p,w,_=null,S={},E,b=null,A=null,I=null,C=new En;function O(N,q){return C.enqueue(()=>D(N,q))}function y(){A||(A=new $o({isConnected:()=>c.isConnected(),forceReconnect:()=>I?O(I,{force:!0}):void 0,onFatal:N=>{if(process.env[Ji]==="1"){H.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:N});return}H.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:N}),process.exit(1)}})),A.start()}async function D(N,q){let j=N,ie=j?.privatecode;if(!ie)throw new T("IPC_BAD_REQUEST","/connect requires privatecode");let $e=Ci(j.env),le=j.handshake_url,ue=j.frontier_url,St=vh(j.env,le,ue);if(I=j,!q?.force&&p===ie&&w===St){let ge=await Xv(t);return u.agents.size===0&&ge?(H.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),Zo(t,x).catch(Ie=>H.warn("connect-noop auto-revive error (ignored)",{err:String(Ie)}))):H.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let ft=!!p&&p!==ie,Xt=w!==void 0&&w!==St,Ft=ft||Xt,Qt=await Nc({privatecode:ie,...le?{endpoint:le}:{},ppeOverride:$e});if(Ft){H.warn("connect config switched, resetting agents",{pcChanged:ft,envChanged:Xt,previousPc:p?Vo(p):"",nextPc:Vo(ie)});for(let ge of[...u.agents.values()])await ge.dispose("connect config switch").catch(()=>{}),u.agents.delete(ge.agentId);u.disconnectedAgents.size>0&&(H.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Fr,"connect switch").catch(()=>{})}_=Qt.deviceId,ss({deviceId:_,pid:process.pid}),Xc({patToken:ie,env:j.env}).catch(ge=>H.warn("coze-cli setup error (ignored)",{err:String(ge)}));let jr=new Zi({handshake:Qt,privatecode:ie,...ue?{urlOverride:ue}:{},ppeOverride:$e,getPatTokenForAgent:ge=>u.agents.get(ge)?.patToken});return await c.swap(jr,"connect"),p=ie,w=St,S=$e,E=le,j.mock_scenario!==void 0&&(u.setMockScenario(j.mock_scenario),H.info("mock scenario set",{scenario:j.mock_scenario})),b||(b=new Ri({core:u,getDeviceId:()=>_??"",onTickEnd:()=>z.retryPending().catch(ge=>H.warn("detailSync.retryPending failed (ignored)",{err:String(ge)})),onAuthFailures:$})),b.start(),y(),Ft&&Zo(t,x).catch(ge=>H.warn("post-connect-switch auto-revive error (ignored)",{err:String(ge)})),Yi(ie,t).catch(ge=>H.warn("writePatToken after /connect failed (ignored)",{err:String(ge)})),H.info("/connect: WS established",{deviceId:_}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async N=>x.createAgent(N.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let R={},M=new io({agents:u.agents,disposeAndMarkDisconnected:async(N,q)=>{let j=u.agents.get(N);if(j){await x.cleanupOpenclawSessionProviders(j).catch($e=>H.warn("cleanup openclaw providers failed (ignored)",{agentId:N,err:String($e)}));let ie=!0;try{await j.dispose(`disconnect: ${q}`)}catch($e){ie=!1,H.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:N,err:String($e)}),j.status="error"}ie&&(j.status="disconnected",u.unregister(N),u.disconnectedAgents.add(N))}else u.disconnectedAgents.add(N)},detailSyncer:async N=>{if(!R.ref)throw new Error("agent-detail-sync not initialized yet");await R.ref.syncOne(N)},cleanupOpenclawProviders:async N=>{await x.cleanupOpenclawSessionProviders(N)},openclawRepair:async(N,q)=>{await x.openclawRepair(N,q)},isRuntimePendingPermission:N=>u.hasPendingPermissionFor(N)});u.registerExtension("_agent/listSkills",N=>M.listSkills(N.params)),u.registerExtension("_agent/addSkills",N=>M.addSkills(N.params)),u.registerExtension("_agent/removeSkills",N=>M.removeSkills(N.params)),u.registerExtension("_agent/getFileTree",N=>M.getFileTree(N.params)),u.registerExtension("_agent/getFileContent",N=>M.getFileContent(N.params)),u.registerExtension("_agent/update",N=>M.updateAgent(N.params)),u.registerExtension("_agent/disconnect",N=>M.disconnectAgent(N.params)),u.registerExtension("_agent/switchModel",N=>M.switchModel(N.params)),u.registerExtension("_agent/reset",N=>M.resetAgent(N.params)),u.registerExtension("_agent/repair",N=>M.repairAgent(N.params));let z=new us({paths:t,handlers:M,sendDetail:N=>u.sendRequest("_agent/detail",N)});R.ref=z;let $=async N=>{await Promise.allSettled(N.map(async q=>{try{await M.disconnectAgent({agentId:q.agentId,reason:`auth_failure: code=${q.code} ${q.message}`}),H.info("agent disconnected due to auth failure from heartbeat response",{agentId:q.agentId,code:q.code,message:q.message})}catch(j){H.warn("disconnect during authFailure handling failed (ignored)",{agentId:q.agentId,err:String(j)})}}))};c.onConnect(({initial:N})=>{H.info("frontier upstream connected, triggering detail sync",{initial:N}),z.syncAll(N?"initial-connect":"reconnect").catch(q=>H.warn("detail sync top-level error (ignored)",{err:String(q)}))});let V=new yo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let N=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[Ji]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:_??"",frameworksCache:o.frameworksCache??{},...N?{mockScenario:N}:{}}}},{method:"POST",path:"/pair",handler:async N=>{let q=N,j=q?.privatecode,ie=q?.pairing_code;if(!j||!ie)throw new T("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let $e=Ci(q.env),le=q.handshake_url,ue=q.frontier_url,St=vh(q.env,le,ue),ft=!!p&&p!==j,Xt=w!==void 0&&w!==St,Ft=ft||Xt,Qt=await Nc({privatecode:j,...le?{endpoint:le}:{},ppeOverride:$e});if(Ft){H.warn("pair config switched, resetting agents",{pcChanged:ft,envChanged:Xt,previousPc:p?Vo(p):"",nextPc:Vo(j),previousEnvKey:w??"",nextEnvKey:St});for(let Ie of[...u.agents.values()])await Ie.dispose("pair config switch").catch(()=>{}),u.agents.delete(Ie.agentId);u.disconnectedAgents.size>0&&(H.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Fr,"pair switch").catch(()=>{})}_=Qt.deviceId,ss({deviceId:_,pid:process.pid}),Xc({patToken:j,env:q.env}).catch(Ie=>H.warn("coze-cli setup error (ignored)",{err:String(Ie)}));let jr=new Zi({handshake:Qt,privatecode:j,...ue?{urlOverride:ue}:{},ppeOverride:$e,getPatTokenForAgent:Ie=>u.agents.get(Ie)?.patToken});await c.swap(jr,"pair");try{let Ie=new Gn;o.frameworksCache=await Ie.detectAll(),await zi(o),H.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ie){H.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ie)})}let ge=Object.keys(o.frameworksCache??{});try{let Ie=await u.sendRequest("_agent/pair",{pairCode:ie,patToken:j,frameworks:ge,_meta:{cozeDeviceId:_}});H.info("_agent/pair ok",{pairResult:Ie}),p=j,w=St,S=$e,E=le,q.mock_scenario!==void 0&&(u.setMockScenario(q.mock_scenario),H.info("mock scenario set",{scenario:q.mock_scenario})),Yi(j,t).catch(Re=>H.warn("writePatToken after /pair failed (ignored)",{err:String(Re)})),b||(b=new Ri({core:u,getDeviceId:()=>_??"",onTickEnd:()=>z.retryPending().catch(Re=>H.warn("detailSync.retryPending failed (ignored)",{err:String(Re)})),onAuthFailures:$})),b.start(),y(),Ft&&Zo(t,x).catch(Re=>H.warn("post-pair-switch auto-revive error (ignored)",{err:String(Re)}));let Vn;return q.agent_id&&(Vn=await e1(q.agent_id,t,x,Re=>u.sendRequest("_agent/detail",Re),j).catch(Re=>(H.error("--agent-id ensureAgent failed",{agentId:q.agent_id,err:String(Re)}),{ok:!1,agentId:q.agent_id??"",note:String(Re)}))),{ok:!0,note:"paired with cloud",...Vn?{agent:Vn}:{}}}catch(Ie){return H.error("_agent/pair failed",{err:String(Ie)}),{ok:!1,note:`pair failed: ${String(Ie)}`}}}},{method:"POST",path:"/connect",handler:N=>O(N)},{method:"POST",path:"/_agent/create",handler:async N=>{let q=N;return{ok:!0,result:await x.createAgent(q)}}},{method:"POST",path:"/agent/send",handler:async N=>{let q=N;if(!q?.agentId||!q?.sessionId||!q?.kind||!q?.path)throw new T("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!p)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let j=q;return await(j.groupFile?Pf:kf)(j,{core:u,patToken:p,handshakeBase:E,ppeOverride:S})}catch(j){if(j instanceof T)return{ok:!1,code:j.code,message:j.message};throw j}}},{method:"POST",path:"/reload",handler:async N=>{let q=N?.agent_id,j=await u.reloadAgents(q);return H.info("IPC /reload: recycled agent subprocesses",{agentId:q??"(all)",recycled:j}),{ok:!0,recycled:j}}},{method:"POST",path:"/shutdown",handler:async()=>(H.info("IPC /shutdown received"),setImmediate(()=>{xe.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:te,token:X}=await V.start();try{await wh(t.libEntry,t)}catch(N){H.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(N)})}await u.start(),t1({paths:t,core:u,agentManager:x,detectAll:async()=>(o.frameworksCache=await new Gn().detectAll(),await zi(o),o.frameworksCache)}).catch(N=>H.warn("startup warmup error (ignored)",{err:String(N)})),wl().then(async()=>{let{probeAcpVersion:N}=await Promise.resolve().then(()=>(nn(),gl));for(let q of["claude-code","codex"]){let j=await N(q);j&&H.info("acp wrapper version",{framework:q,version:j})}}).catch(N=>H.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(N)}));let Ee=null,xe={port:te,token:X,core:u,ipc:V,shutdown(N){return Ee||(H.info("daemon shutdown",{reason:N}),Ee=(async()=>{b?.stop(),A?.stop(),await u.stop(N),await V.stop(),await e.release()})(),Ee)}};for(let N of["SIGTERM","SIGINT"])process.on(N,()=>{xe.shutdown(N).then(()=>process.exit(0))});return process.on("exit",()=>sf()),process.on("unhandledRejection",N=>{H.error("unhandledRejection",{reason:N instanceof Error?N.message:String(N),stack:N instanceof Error?N.stack:void 0})}),process.on("uncaughtException",N=>{H.error("uncaughtException (will exit, supervisor will restart)",{message:N.message,stack:N.stack,name:N.name});try{process.stderr.write(`FATAL uncaughtException: ${N.stack??N.message}
107
+ `)}catch{}process.exit(1)}),H.info("daemon ready",{port:te,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),n1({cliSpawned:process.env[Ji]==="1",readPatToken:()=>Ho(t),connect:O}).catch(N=>H.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(N)})),xe}async function Xv(t){return as(t).length>0}function Vo(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function vh(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function Qv(t,e){let r=as(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(rn(),ls));for(let c of r){await o(c,t).catch(l=>H.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(l)}));try{let l=await i(c,t);l?.disconnectedAt&&(e.disconnectedAgents.add(c),H.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:l.disconnectedAt,reason:l.disconnectReason??""}))}catch(l){H.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(l)})}}}async function e1(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(rn(),ls)),l=await c(t,e);if(l){H.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"}}H.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let u=await i({_meta:{cozeAgentId:t}});if(!u.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 x={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...u.deployType?{_meta:{cozeDeployType:u.deployType}}:{}};await r.createAgent(x);let p=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:p?"cloud agent acknowledged":"created from cloud detail"}}async function t1(t){let e=t.logger??H;try{let r=await t.detectAll();e.info("refreshed frameworks_cache",{detected:Object.keys(r??{})})}catch(r){e.warn("framework detection failed (using cached)",{err:String(r)})}await Qv(t.paths,t.core).catch(r=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(r)})),await Zo(t.paths,t.agentManager).catch(r=>e.warn("auto-revive top-level error (ignored)",{err:String(r)}))}async function Zo(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(),ls));H.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,l=0;for(let u of i){let x;try{x=await o(u,t)}catch(p){H.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(p)}),l+=1;continue}if(!x){l+=1;continue}if(x.disconnectedAt){H.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:x.disconnectedAt}),l+=1;continue}try{H.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:x.framework});let p=r1(x);await e.createAgent({agentId:x.agentId,framework:x.framework,...x.cozeIdentity?{cozeIdentity:x.cozeIdentity}:{},...x.model?{model:x.model}:{},...p?{_meta:p}:{}},{revive:!0}),c+=1}catch(p){H.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:x.framework,err:String(p)}),l+=1}}return H.info("auto-revive: done",{revived:c,skipped:l,total:i.length}),{revived:c,skipped:l,total:i.length}}async function n1(t){let e=t.logger??H;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 r1(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}Ko();ke();import{readFile as Ih}from"node:fs/promises";var Jt=class{paths;constructor(e){this.paths=e??J()}async probe(e=1e3){let r=await Yo(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:s1(i)}}}async request(e){let r=await Yo(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 u=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}),x=await u.text();return{status:u.status,body:i1(x)}}finally{clearTimeout(l)}}};async function Yo(t){try{let[e,r]=await Promise.all([Ih(t.portFile,"utf8"),Ih(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 i1(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function s1(t){return t instanceof Error?t.message:String(t)}yn();ne();Xn();import{spawn as o1}from"node:child_process";import{userInfo as Th}from"node:os";var Rd="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",a1=new Set(["bash","zsh","sh","dash","ksh"]),Ah=He("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),c1=2e3;function d1(t,e=Rd){let r=t.indexOf(e);if(r===-1)return null;let i=t.indexOf(e,r+e.length);if(i===-1)return null;let o=t.slice(r+e.length,i),c={};for(let l of o.split(`
108
+ `)){let u=l.indexOf("=");u<=0||(c[l.slice(0,u)]=l.slice(u+1))}return c}function l1(){let t=(process.env.SHELL??"").trim()||(Th().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return a1.has(e)?t:null}function u1(t){return new Promise(e=>{let r=`printf '%s' '${Rd}'; env; printf '%s' '${Rd}'`,i;try{i=o1(t,["-ilc",r],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??Th().homedir}})}catch{e(null);return}let o="",c=!1,l=w=>{try{i.pid&&process.kill(-i.pid,w)}catch{}},u=w=>{c||(c=!0,clearTimeout(x),clearTimeout(p),e(w))};i.stdout?.on("data",w=>{o+=w.toString("utf8")}),i.on("error",()=>u(null)),i.on("close",()=>u(o.length>0?o:null));let x=setTimeout(()=>l("SIGTERM"),Ah),p=setTimeout(()=>{l("SIGKILL"),u(o.length>0?o:null)},Ah+c1)})}async function kd(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let r=l1();if(!r)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??u1)(r);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=d1(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}ke();function Sn(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],l=!1;for(let u of e){if(c===u){i=t[o+1],o+=1,l=!0;break}if(c.startsWith(`${u}=`)){i=c.slice(u.length+1),l=!0;break}}l||r.push(c)}return{value:i,rest:r}}nn();import{chmod as f1,copyFile as Ch,mkdir as Rh,readFile as Jo,rename as Dh,rm as Pd,stat as kh,writeFile as x1}from"node:fs/promises";import{homedir as QD}from"node:os";import{dirname as h1,join as Ur,resolve as Od,sep as Xi}from"node:path";import{fileURLToPath as p1}from"node:url";yn();ne();ke();var Nd=G("dist-install");function g1(t){let e=p1(t),r=h1(e),i=`${Xi}src${Xi}`;if(r.includes(i)||r.endsWith(`${Xi}src${Xi}cli`))return null;let o=Od(r,"index.js"),c=Od(r,"..","package.json");return{dist:o,pkgJson:c}}async function Md(t={}){let e=t.paths??J(),r=g1(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 S=JSON.parse(await Jo(o,"utf8"));c=S.version??"unknown",l=S.dependencies??{}}catch(S){return Nd.warn("cannot read source package.json,skip dist install",{err:String(S)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(S)}`}}let u=Zr.map(S=>`${S}@${l[S]??"latest"}`),x=await wo(e.configFile)??{},p=x.libVersion,w=await Jo(e.libEntry).then(()=>!0).catch(()=>!1),_=p===c;if(_&&w&&await Ld(e))return{kind:"already-current",libVersion:c};if(!_||!w){await Rh(e.libDir,{recursive:!0}),await Ch(i,e.libEntry),await Ch(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let S=Od(e.libDir,"package.json"),E=`${JSON.stringify({type:"module"},null,2)}
109
+ `;await Jo(S,"utf8").catch(()=>null)!==E&&await x1(S,E)}return(!_||!await Ld(e))&&await(t.installWrappers??m1)(e,u),x.libVersion=c,await zi(x,e.configFile),Nd.info("dist installed",{libEntry:e.libEntry,fromVersion:p,toVersion:c}),_&&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 Ld(t){for(let e of Zr){let r=Ur(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await kh(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function m1(t,e){await y1(t.installLock,async()=>{if(await Ld(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${Xi}.staging-${process.pid}-${r}`,o=Ur(i,"node_modules"),c=Ur(t.libDir,"node_modules");try{await Rh(i,{recursive:!0}),await w1(e,i),await _1(o);let l=`${c}.trash-${r}`;await Dh(c,l).catch(()=>{}),await Dh(o,c),await Pd(l,{recursive:!0,force:!0}).catch(()=>{}),Nd.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await Pd(i,{recursive:!0,force:!0}).catch(()=>{})}})}function w1(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=dt("npm",r,{stdio:["ignore","pipe","pipe"]}),l="";c.stderr?.on("data",x=>{l.length<8192&&(l+=x.toString("utf8"))});let u=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",x=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(x)}`))}),c.once("close",x=>{clearTimeout(u),x===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${x}: ${l.trim().slice(0,2e3)}`))})})}async function _1(t){for(let e of Zr){let r=Ur(t,...e.split("/")),i=JSON.parse(await Jo(Ur(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=Ur(t,".bin",o),l=await kh(c);process.platform!=="win32"&&!(l.mode&73)&&await f1(c,l.mode|73).catch(()=>{})}}async function y1(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 Pd(t,{force:!0}).catch(()=>{})}}_a();ne();ke();import{closeSync as Oh,fstatSync as Nh,openSync as Lh,readFileSync as E1,readSync as b1,readdirSync as v1,statSync as S1}from"node:fs";import{join as Xo}from"node:path";var I1=new Set(["debug","info","warn","error"]);function Mh(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 u=o.value===void 0?200:Number(o.value),x=Number.isInteger(u)&&u>=0?u:200,p=c.value&&I1.has(c.value)?c.value:void 0,w={lines:x,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 A1(t,e){return t.agentId?Xo(Ze(t.agentId,e).logs,Qn("agent",t.date)):Xo(e.bridgeLogsDir,Qn("bridge",t.date))}function T1(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function C1(t,e){let r;try{r=v1(t)}catch{return[]}let i=[];for(let o of r){let c=wa(o,e);if(!c)continue;let l=0;try{l=S1(Xo(t,o)).size}catch{}i.push({file:Xo(t,o),date:c,size:l})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function Bh(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"&&!ul(r,e.level))return!1}return!0}var Ph={debug:"90",info:"36",warn:"33",error:"31"},D1=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 zh(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&&Ph[o]&&(c=`\x1B[${Ph[o]}m${c}\x1B[0m`);let l=typeof r.module=="string"?r.module:"",u=typeof r.msg=="string"?r.msg:"",x=Object.entries(r).filter(([p])=>!D1.has(p)).map(([p,w])=>` ${p}=${typeof w=="string"?w:JSON.stringify(w)}`).join("");return`${i} ${c} ${l} ${u}${x}`}function k1(t,e,r){let c=E1(t,"utf8").split(`
110
+ `).filter(l=>l.length>0).filter(l=>Bh(l,{level:e.level,grep:e.grep}));for(let l of T1(c,e.lines))process.stdout.write(`${zh(l,{raw:e.raw,color:r})}
111
+ `)}async function Fh(t,e){let r=e.paths??J(),i=process.stdout.isTTY===!0;if(t.list){let l=t.agentId?Ze(t.agentId,r).logs:r.bridgeLogsDir,u=t.agentId?"agent":"bridge",x=C1(l,u);if(x.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${l}
112
+ `),1;for(let p of x)process.stdout.write(`${p.date} ${(p.size/1024).toFixed(1)}KB ${p.file}
113
+ `);return 0}let o=t.date??An(new Date),c=A1({agentId:t.agentId,date:o},r);try{k1(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
112
114
  \u7528 'coze-bridge log${t.agentId?` --agent-id ${t.agentId}`:""} --list' \u770B\u6709\u54EA\u4E9B\u65E5\u671F\u3002
113
115
  (legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${r.logFile})
114
- `),1}return t.follow&&await w1(c,t,i),0}var g1=500;function m1(t){try{let e=Tx(t,"r");try{return Ax(e).size}finally{Ix(e)}}catch{return 0}}async function w1(t,e,r){let i=m1(t),o="",c=!1,l=()=>{c=!0};process.on("SIGINT",l);try{for(;!c;){let u="";try{let h=Tx(t,"r");try{let p=Ax(h).size;if(p>i){let _=Buffer.allocUnsafe(p-i),E=o1(h,_,0,_.length,i);u=_.subarray(0,E).toString("utf8"),i+=E}}finally{Ix(h)}}catch{}if(u){let h=(o+u).split(`
115
- `);o=h.pop()??"";for(let p of h)p.length>0&&Rx(p,{level:e.level,grep:e.grep})&&process.stdout.write(`${Dx(p,{raw:e.raw,color:r})}
116
- `)}await new Promise(h=>setTimeout(h,g1))}}finally{process.off("SIGINT",l)}}import{basename as _1,resolve as y1}from"node:path";Pe();var b1=9e4,E1={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 v1(t){return E1[t]??1}async function kx(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>
116
+ `),1}return t.follow&&await N1(c,t,i),0}var P1=500;function O1(t){try{let e=Lh(t,"r");try{return Nh(e).size}finally{Oh(e)}}catch{return 0}}async function N1(t,e,r){let i=O1(t),o="",c=!1,l=()=>{c=!0};process.on("SIGINT",l);try{for(;!c;){let u="";try{let x=Lh(t,"r");try{let p=Nh(x).size;if(p>i){let w=Buffer.allocUnsafe(p-i),_=b1(x,w,0,w.length,i);u=w.subarray(0,_).toString("utf8"),i+=_}}finally{Oh(x)}}catch{}if(u){let x=(o+u).split(`
117
+ `);o=x.pop()??"";for(let p of x)p.length>0&&Bh(p,{level:e.level,grep:e.grep})&&process.stdout.write(`${zh(p,{raw:e.raw,color:r})}
118
+ `)}await new Promise(x=>setTimeout(x,P1))}}finally{process.off("SIGINT",l)}}import{basename as L1,resolve as M1}from"node:path";ke();var B1=9e4,z1={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 z1[t]??1}async function Uh(t,e={}){let r=e.paths??J();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
119
  `),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 $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:y1(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 S1(i,"/agent/send",o,b1)}catch(l){return process.stderr.write(`Error: daemon IPC failed: ${l instanceof Error?l.message:String(l)}
120
+ `),3;let i=await Yo(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.
121
+ `),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:M1(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 U1(i,"/agent/send",o,B1)}catch(l){return process.stderr.write(`Error: daemon IPC failed: ${l instanceof Error?l.message:String(l)}
120
122
  `),4}if(!c.ok)return process.stderr.write(`Error: ${c.code}: ${c.message}
121
- `),v1(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
122
- `);else{let l=t.name??_1(o.path);if(t.groupFile){let u=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${l} (uri=${u})
123
- `)}else process.stdout.write(`Sent ${t.kind} ${l} (${I1(c.bytes)})
124
- `)}return 0}async function S1(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}),u=await l.text(),h=u?JSON.parse(u):null;return h&&typeof h=="object"&&"ok"in h?h:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${l.status}): ${u.slice(0,200)}`}}finally{clearTimeout(c)}}function I1(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var Gx=U("cli");function Ue(t,e){let{value:r,rest:i}=En(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 J1(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 Z1(e.slice(1));if(e[0]==="log")return{mode:"log",...Cx(e.slice(1))};if(e[0]==="connect")return X1(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:u,rest:h}=Ue(r,"--env");r=h;let{value:p,rest:_}=Ue(r,"--handshake-url");r=_;let{value:E,rest:A}=Ue(r,"--frontier-url");r=A;let{value:b,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 u&&(S.env=u),p&&(S.handshakeUrl=p),E&&(S.frontierUrl=E),b&&(S.mockScenario=b),I&&(S.agentId=I),S}function Z1(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:u}=Ue(i,"--name");i=u;let{value:h,rest:p}=Ue(i,"--agent-id");i=p;let{value:_,rest:E}=Ue(i,"--session-id");i=E;let{value:A,rest:b}=Ue(i,"--mime");i=b;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),_&&(S.sessionId=_),v&&(S.groupFile=!0),A&&(S.mimeType=A),S}function X1(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:u}=Ue(e,"--handshake-url");e=u;let{value:h,rest:p}=Ue(e,"--frontier-url");e=p;let{value:_,rest:E}=Ue(e,"--mock-scenario");e=E;let A={mode:"connect"};return r&&(A.privatecode=r),o&&(A.env=o),l&&(A.handshakeUrl=l),h&&(A.frontierUrl=h),_&&(A.mockScenario=_),A}var Y1=`
123
+ `),F1(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
124
+ `);else{let l=t.name??L1(o.path);if(t.groupFile){let u=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${l} (uri=${u})
125
+ `)}else process.stdout.write(`Sent ${t.kind} ${l} (${G1(c.bytes)})
126
+ `)}return 0}async function U1(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}),u=await l.text(),x=u?JSON.parse(u):null;return x&&typeof x=="object"&&"ok"in x?x:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${l.status}): ${u.slice(0,200)}`}}finally{clearTimeout(c)}}function G1(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var Zh=G("cli");function Ue(t,e){let{value:r,rest:i}=Sn(t,e);return{value:r,rest:i}}function ia(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
127
+ `)}function uS(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:O}=Ue(e.slice(1),"--agent-id");return O?{mode:"reload",agentId:O}:{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 fS(e.slice(1));if(e[0]==="log")return{mode:"log",...Mh(e.slice(1))};if(e[0]==="connect")return xS(e.slice(1));if(e.includes("--status"))return ia("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return ia("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return ia("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return ia("--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:u,rest:x}=Ue(r,"--env");r=x;let{value:p,rest:w}=Ue(r,"--handshake-url");r=w;let{value:_,rest:S}=Ue(r,"--frontier-url");r=S;let{value:E,rest:b}=Ue(r,"--mock-scenario");r=b;let{value:A}=Ue(r,"--agent-id"),I=r.includes("--skip-rebuild-env");if(!i||!c)return{mode:"help"};let C={mode:"pair",privatecode:i,pairingCode:c};return u&&(C.env=u),p&&(C.handshakeUrl=p),_&&(C.frontierUrl=_),E&&(C.mockScenario=E),A&&(C.agentId=A),I&&(C.skipRebuildEnv=!0),C}function fS(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:u}=Ue(i,"--name");i=u;let{value:x,rest:p}=Ue(i,"--agent-id");i=p;let{value:w,rest:_}=Ue(i,"--session-id");i=_;let{value:S,rest:E}=Ue(i,"--mime");i=E;let b=i.includes("--group-file");i=i.filter(C=>C!=="--group-file");let A=i.includes("--json"),I={mode:"send",kind:e,path:r,json:A};return o&&(I.caption=o),l&&(I.name=l),x&&(I.agentId=x),w&&(I.sessionId=w),b&&(I.groupFile=!0),S&&(I.mimeType=S),I}function xS(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:u}=Ue(e,"--handshake-url");e=u;let{value:x,rest:p}=Ue(e,"--frontier-url");e=p;let{value:w,rest:_}=Ue(e,"--mock-scenario");e=_;let S=e.includes("--skip-rebuild-env"),E={mode:"connect"};return r&&(E.privatecode=r),o&&(E.env=o),l&&(E.handshakeUrl=l),x&&(E.frontierUrl=x),w&&(E.mockScenario=w),S&&(E.skipRebuildEnv=!0),E}var hS=`
126
128
  coze-bridge - local bridge daemon for cloud Agent Service
127
129
 
128
130
  Pair (paste from cloud UI; start/reuse daemon and deliver pair-code):
@@ -185,6 +187,8 @@ Pair flags (optional, per-pair, not persisted):
185
187
  ppe_coze_project mock_conf \u914D\u7F6E (TCC \u9700\u5F00 mock_conf.enabled).
186
188
  --agent-id <id> pair \u540E\u81EA\u52A8 connect \u6307\u5B9A agent \u2014 \u672C\u5730\u5DF2\u6709\u8D70 reconnect/
187
189
  revive, \u6CA1\u6709\u8D70 _agent/detail \u62C9\u4E91\u7AEF\u8BE6\u60C5\u7136\u540E\u672C\u5730\u65B0\u5EFA
190
+ --skip-rebuild-env \u4E0D\u8DD1 $SHELL -ilc \u91CD\u5EFA\u767B\u5F55\u73AF\u5883, \u76F4\u63A5\u7528\u5F53\u524D\u8FDB\u7A0B env \u5199
191
+ agent-env.json (\u9ED8\u8BA4\u4F1A\u91CD\u5EFA; cloud \u6D3E\u53D1\u5E94\u5E26\u6B64 flag)
188
192
 
189
193
  Example: npx -y coze-bridge --pat-token=sat_xxx --pair-code=xxx --env=ppe_xxx --agent-id=7639628097007927571
190
194
 
@@ -201,56 +205,57 @@ Deprecated flags (still work, but emit a warning; will be removed in a future re
201
205
 
202
206
  Internal:
203
207
  <node> <entry> --daemon daemon mode (OS supervisor only)
204
- `.trimStart();async function qx(t=process.argv,e={}){let r=J1(t);switch(r.mode){case"help":return process.stdout.write(Y1),0;case"version":return process.stdout.write(`${Er}
205
- `),0;case"daemon":{try{await mx()}catch(i){return Gx.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return Q1(e);case"stop":return Hx(e);case"reload":return nS(r.agentId,e);case"log":return Px(r,e);case"update":return eS(e);case"purge":return rS(e);case"service-install":return iS(e);case"service-uninstall":return sS(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),oS(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),aS(r.privatecode,e,i)}case"send":return kx({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 jx(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 Q1(t){let e=t.paths??X(),r=new Jt(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 jx(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
208
+ `.trimStart();async function Yh(t=process.argv,e={}){let r=uS(t);switch(r.mode){case"help":return process.stdout.write(hS),0;case"version":return process.stdout.write(`${Sr}
209
+ `),0;case"daemon":{try{await Sh()}catch(i){return Zh.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return pS(e);case"stop":return Xh(e);case"reload":return wS(r.agentId,e);case"log":return Fh(r,e);case"update":return gS(e);case"purge":return _S(e);case"service-install":return yS(e);case"service-uninstall":return ES(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),bS(r.privatecode,r.pairingCode,e,i,r.agentId,r.skipRebuildEnv)}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),vS(r.privatecode,e,i,r.skipRebuildEnv)}case"send":return Uh({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 Jh(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 pS(t){let e=t.paths??J(),r=new Jt(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
210
+ `),1;if(i.kind==="stale")return await Jh(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
207
211
  `),1;let o=await r.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
208
212
  ${JSON.stringify(o.body,null,2)}
209
- `),0}async function Hx(t){let e=t.paths??X(),r=new Jt(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
- `)}let c=await r.probe();if(c.kind==="not-running")return process.stdout.write(o?`coze-bridge: stopped
213
+ `),0}async function Xh(t){let e=t.paths??J(),r=new Jt(e),i=t.daemonSweep??(async()=>{let x=of();return await af(x),x}),o=async()=>{t.skipProcessKill||await i(e)},c=await es(t),l=!1;if(c)try{await c.uninstall(),l=!0}catch(x){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(x)}
214
+ `)}let u=await r.probe();if(u.kind==="not-running")return await o(),process.stdout.write(l?`coze-bridge: stopped
211
215
  `:`coze-bridge: not running
212
- `),0;if(c.kind==="stale")return await jx(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
213
- `),0;try{return await r.request({method:"POST",path:"/shutdown"}),process.stdout.write(`coze-bridge: stopped
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 eS(t){return await Hx(t),(t.spawnNpx??tS)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function tS(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 nS(t,e){let r=new Jt(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
216
+ `),0;if(u.kind==="stale")return await Jh(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
217
+ `),0;try{return await r.request({method:"POST",path:"/shutdown"}),await o(),process.stdout.write(`coze-bridge: stopped
218
+ `),0}catch(x){return(await r.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
219
+ `),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(x)}
220
+ `),1)}}async function gS(t){return await Xh(t),(t.spawnNpx??mS)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function mS(t){return new Promise(e=>{let r=dt("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)}
221
+ `),e(1)})})}async function wS(t,e){let r=new Jt(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
218
222
  `),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
223
  `):process.stdout.write(`coze-bridge: reloaded ${c.length} agent(s): ${c.join(", ")||"(none)"}
220
224
  `),0}return process.stderr.write(`coze-bridge: reload failed: ${JSON.stringify(o.body)}
221
225
  `),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,l={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:u=>c.install(l,u),uninstall:()=>c.uninstall(l)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>(Fx(),zx)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function Wx(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??px,o=t.waitTimeoutMs??15e3,c=t.sleep??dS,l=t.paths??X(),u=await Zi(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let h=await Ux(e,o,c);if(h.kind==="connected")return h;Yn(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){Yn(l.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(h)})}Yn(l.bridgeLogsDir,"warn","cli","\u79FB\u9664\u5F00\u673A\u81EA\u542F\u914D\u7F6E (supervisor \u63A5\u7BA1\u672A\u6210\u529F, \u56DE\u9000\u624B\u52A8 spawn; \u4E0B\u6B21\u91CD\u542F\u4E0D\u518D\u81EA\u542F, \u9700\u91CD\u65B0 service install)",{platform:u.platform}),await u.uninstall().catch(()=>{}),await cS(l.pidFile,c)}else u&&await u.install({activate:!1}).catch(h=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(h)}
226
+ `),1}}async function es(t){if(t.supervisor){let c=t.supervisor,l={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:u=>c.install(l,u),uninstall:()=>c.uninstall(l)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>($h(),Kh)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function Qh(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??bh,o=t.waitTimeoutMs??15e3,c=t.sleep??IS,l=t.paths??J(),u=await es(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let x=await Vh(e,o,c);if(x.kind==="connected")return x;At(l.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:o})}catch(x){At(l.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(x)})}At(l.bridgeLogsDir,"warn","cli","\u79FB\u9664\u5F00\u673A\u81EA\u542F\u914D\u7F6E (supervisor \u63A5\u7BA1\u672A\u6210\u529F, \u56DE\u9000\u624B\u52A8 spawn; \u4E0B\u6B21\u91CD\u542F\u4E0D\u518D\u81EA\u542F, \u9700\u91CD\u65B0 service install)",{platform:u.platform}),await u.uninstall().catch(()=>{}),await SS(l.pidFile,c)}else u&&await u.install({activate:!1}).catch(x=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(x)}
223
227
  `));return process.stdout.write(`coze-bridge: starting daemon...
224
- `),await i({paths:t.paths}),Ux(e,o,c)}async function rS(t){let e=new Jt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
228
+ `),await i({paths:t.paths}),Vh(e,o,c)}async function _S(t){let e=new Jt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
225
229
  `);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
230
+ `)}await new Promise(l=>setTimeout(l,500))}let i=await es(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
227
231
  `)}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}
232
+ `)}let o=t.paths??J(),{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
233
  `)}catch(l){return process.stderr.write(`coze-bridge: remove failed: ${String(l)}
230
234
  `),1}return process.stdout.write(`coze-bridge: purged (agents workspaces preserved under ~/.coze/agents)
231
- `),0}async function iS(t){let e=await Zi(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
235
+ `),0}async function yS(t){let e=await es(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
232
236
  `),await e.install(),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
233
237
  `),0}catch(r){return process.stderr.write(`coze-bridge: service install failed: ${String(r)}
234
- `),1}}async function sS(t){let e=await Zi(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
238
+ `),1}}async function ES(t){let e=await es(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
235
239
  `),0}catch(r){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(r)}
236
- `),1}}async function oS(t,e,r,i={},o){let c=new Jt(r.paths),l=r.paths??X();if(await Hc(l).catch(p=>Yn(l.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(p)})),!r.skipDistInstall){let p=await Dd({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 u=await Wx(r,c);if(u.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${u.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 _=p.body.agent;return _&&!_.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${_.agentId}): ${_.note}
240
+ `),1}}async function ep(t,e,r){if(e)return At(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await r();return i.kind==="ok"?(At(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(At(t.bridgeLogsDir,"info","cli","agent-env: rebuild not applicable, use process.env",{reason:i.reason}),process.env):(process.stderr.write(`coze-bridge: \u91CD\u5EFA shell \u73AF\u5883\u5931\u8D25, \u56DE\u9000\u5F53\u524D\u8FDB\u7A0B\u73AF\u5883 (\u53EF\u7528 --skip-rebuild-env \u663E\u5F0F\u8DF3\u8FC7)
241
+ `),At(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function bS(t,e,r,i={},o,c){let l=new Jt(r.paths),u=r.paths??J(),x=await ep(u,c,r.reconstructEnv??kd);if(await $c(u,x).catch(_=>At(u.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(_)})),!r.skipDistInstall){let _=await Md({paths:r.paths});_.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${_.fromVersion} \u2192 ${_.toVersion}
242
+ `),(await l.probe()).kind==="connected"&&(await l.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(E=>setTimeout(E,500)))):_.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${_.libVersion}
243
+ `)}let p=await Qh(r,l);if(p.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${p.kind}
244
+ `),1;let w={privatecode:t,pairing_code:e};i.env&&(w.env=i.env),i.handshakeUrl&&(w.handshake_url=i.handshakeUrl),i.frontierUrl&&(w.frontier_url=i.frontierUrl),i.mockScenario&&(w.mock_scenario=i.mockScenario),o&&(w.agent_id=o);try{let _=await l.request({method:"POST",path:"/pair",body:w,timeoutMs:35e3});if(_.status===200&&_.body?.ok){let S=_.body.agent;return S&&!S.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${S.agentId}): ${S.note}
240
245
  `),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(p.body)}
242
- `),1}catch(p){return process.stderr.write(`coze-bridge: pair failed: ${String(p)}
243
- `),1}}async function aS(t,e,r={}){let i=e.paths??X(),o=t??await Uo(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 Jt(e.paths);if(await Hc(i).catch(h=>Yn(i.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(h)})),!e.skipDistInstall){let h=await Dd({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(_=>setTimeout(_,500)))):h.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${h.libVersion}
245
- `)}let l=await Wx(e,c);if(l.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${l.kind}
246
- `),1;let u={privatecode:o};r.env&&(u.env=r.env),r.handshakeUrl&&(u.handshake_url=r.handshakeUrl),r.frontierUrl&&(u.frontier_url=r.frontierUrl),r.mockScenario&&(u.mock_scenario=r.mockScenario);try{let h=await c.request({method:"POST",path:"/connect",body:u,timeoutMs:35e3});return h.status===200&&h.body?.ok?(process.stdout.write(`coze-bridge: connected (${h.body.note??"ok"})
247
- `),await Ki(o,i).catch(p=>Gx.warn("writePatToken after connect failed (ignored)",{err:String(p)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(h.body)}
248
- `),1)}catch(h){return process.stderr.write(`coze-bridge: connect failed: ${String(h)}
249
- `),1}}async function Ux(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 cS(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 u=Number.parseInt(l.trim(),10);if(!Number.isFinite(u)||u<=0||!ro(u))return;await e(i)}}function dS(t){return new Promise(e=>setTimeout(e,t))}te();function lS(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 Kx(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=lS(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
246
+ `),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(_.body)}
247
+ `),1}catch(_){return process.stderr.write(`coze-bridge: pair failed: ${String(_)}
248
+ `),1}}async function vS(t,e,r={},i){let o=e.paths??J(),c=t??await Ho(o);if(!c)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 l=new Jt(e.paths),u=await ep(o,i,e.reconstructEnv??kd);if(await $c(o,u).catch(w=>At(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(w)})),!e.skipDistInstall){let w=await Md({paths:e.paths});w.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${w.fromVersion} \u2192 ${w.toVersion}
249
+ `),(await l.probe()).kind==="connected"&&(await l.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(S=>setTimeout(S,500)))):w.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${w.libVersion}
250
+ `)}let x=await Qh(e,l);if(x.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${x.kind}
251
+ `),1;let p={privatecode:c};r.env&&(p.env=r.env),r.handshakeUrl&&(p.handshake_url=r.handshakeUrl),r.frontierUrl&&(p.frontier_url=r.frontierUrl),r.mockScenario&&(p.mock_scenario=r.mockScenario);try{let w=await l.request({method:"POST",path:"/connect",body:p,timeoutMs:35e3});return w.status===200&&w.body?.ok?(process.stdout.write(`coze-bridge: connected (${w.body.note??"ok"})
252
+ `),await Yi(c,o).catch(_=>Zh.warn("writePatToken after connect failed (ignored)",{err:String(_)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(w.body)}
253
+ `),1)}catch(w){return process.stderr.write(`coze-bridge: connect failed: ${String(w)}
254
+ `),1}}async function Vh(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 SS(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 u=Number.parseInt(l.trim(),10);if(!Number.isFinite(u)||u<=0||!Ni(u))return;await e(i)}}function IS(t){return new Promise(e=>setTimeout(e,t))}ne();function AS(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 tp(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=AS(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
255
  `),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
256
  \u5347\u7EA7\u5B8C\u540E\u9700\u8981\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u91CD\u65B0\u8FDE\u63A5:
252
257
  npx -y coze-bridge@latest stop
253
258
  npx -y coze-bridge@latest connect
254
259
 
255
- `)}Kx();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&il("warn");qx(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
260
+ `)}tp();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&dl("warn");Yh(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
256
261
  `),process.exit(1)});