coze-bridge 0.1.104-alpha.13 → 0.1.104-alpha.14

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 +80 -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 eg=Object.create;var _a=Object.defineProperty;var tg=Object.getOwnPropertyDescriptor;var ng=Object.getOwnPropertyNames;var rg=Object.getPrototypeOf,ig=Object.prototype.hasOwnProperty;var le=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Je=(t,e)=>()=>(t&&(e=t(t=0)),e);var ae=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ya=(t,e)=>{for(var r in e)_a(t,r,{get:e[r],enumerable:!0})},sg=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ng(e))!ig.call(t,o)&&o!==r&&_a(t,o,{get:()=>e[o],enumerable:!(i=tg(e,o))||i.enumerable});return t};var Ft=(t,e,r)=>(r=t!=null?eg(rg(t)):{},sg(e||!t||!t.__esModule?_a(r,"default",{value:t,enumerable:!0}):r,t));function je(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var nr=Je(()=>{"use strict"});import{createWriteStream as og,mkdirSync as ag,readdirSync as cg,unlinkSync as dg}from"node:fs";import{join as uu}from"node:path";function kn(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function rr(t,e){return`${t}-${e}.log`}function ba(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function ug(t,e,r){let i=c=>{let[u,f,x]=c.split("-").map(Number);return Date.UTC(u??0,(f??1)-1,x??1)};return Math.floor((i(e)-i(t))/864e5)>r}function ss(t,e,r,i){let o;try{o=cg(t)}catch{return}for(let c of o){let u=ba(c,e);if(u&&ug(u,r,i))try{dg(uu(t,c))}catch{}}}var Jr,Ea=Je(()=>{"use strict";Jr=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>kn(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{ag(this.dir,{recursive:!0});let r=og(uu(this.dir,rr(this.prefix,e)),{flags:"a"});r.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
8
+ var ng=Object.create;var wa=Object.defineProperty;var rg=Object.getOwnPropertyDescriptor;var ig=Object.getOwnPropertyNames;var sg=Object.getPrototypeOf,og=Object.prototype.hasOwnProperty;var ue=(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 Ze=(t,e)=>()=>(t&&(e=t(t=0)),e);var ae=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),_a=(t,e)=>{for(var r in e)wa(t,r,{get:e[r],enumerable:!0})},ag=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ig(e))!og.call(t,o)&&o!==r&&wa(t,o,{get:()=>e[o],enumerable:!(i=rg(e,o))||i.enumerable});return t};var Ft=(t,e,r)=>(r=t!=null?ng(sg(t)):{},ag(e||!t||!t.__esModule?wa(r,"default",{value:t,enumerable:!0}):r,t));function We(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var er=Ze(()=>{"use strict"});import{createWriteStream as cg,mkdirSync as dg,readdirSync as lg,unlinkSync as ug}from"node:fs";import{join as ll}from"node:path";function Tn(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function tr(t,e){return`${t}-${e}.log`}function ya(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function fg(t,e,r){let i=c=>{let[l,f,x]=c.split("-").map(Number);return Date.UTC(l??0,(f??1)-1,x??1)};return Math.floor((i(e)-i(t))/864e5)>r}function rs(t,e,r,i){let o;try{o=lg(t)}catch{return}for(let c of o){let l=ya(c,e);if(l&&fg(l,r,i))try{ug(ll(t,c))}catch{}}}var Jr,Ea=Ze(()=>{"use strict";Jr=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>Tn(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{dg(this.dir,{recursive:!0});let r=cg(ll(this.dir,tr(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&&ss(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 lg,mkdirSync as fg}from"node:fs";import{join as xg}from"node:path";function fu(t){let e=t.retentionDays??gg,r=t.clock??(()=>kn(new Date));as={bridgeSink:new Jr(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new Jr(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();ss(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])ss(t.agentLogsDir(o),"agent",i,e)}function mg(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function xu(t){va=t}function hu(t){return ir[va]<=ir[t]}function pu(t,e){let r=ir[t];return r===void 0?!0:r>=ir[e]}function cs(t){lu={...t}}function gu(t){let e=(f,x=2)=>String(f).padStart(x,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),u=e(o%60);return`${kn(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${u}`}function St(t,e,r,i,o){try{let c=`${JSON.stringify({ts:gu(new Date),level:e,module:r,msg:i,...o})}
11
- `;fg(t,{recursive:!0}),lg(xg(t,rr("bridge",kn(new Date))),c)}catch{}}function wg(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function os(t,e,r,i,o){if(ir[t]<ir[va])return;let c=`${JSON.stringify({ts:gu(new Date),level:t,module:e,msg:r,...lu,...i})}
12
- `;if(as){let u=wg(o,i),f=u?mg(as,u):as.bridgeSink;try{f.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?pg.write(c):hg.write(c)}function q(t,e){return{debug:(r,i)=>os("debug",t,r,i,e),info:(r,i)=>os("info",t,r,i,e),warn:(r,i)=>os("warn",t,r,i,e),error:(r,i)=>os("error",t,r,i,e),child:r=>q(`${t}.${r}`,e),forAgent:r=>q(t,r)}}var ir,va,hg,pg,lu,gg,as,ne=Je(()=>{"use strict";nr();Ea();ir={debug:10,info:20,warn:30,error:40},va=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),hg=process.stdout,pg=process.stderr,lu={},gg=je("COZE_BRIDGE_LOG_RETENTION_DAYS",30),as=null});var C,We=Je(()=>{"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 yu={};ya(yu,{ACP_WRAPPER_NPM_PACKAGES:()=>Qr,_resetAcpInstallerForTests:()=>Sg,_setBinaryPathCacheForTests:()=>Ag,buildAcpSpawn:()=>ei,ensureAcpInstalled:()=>sr,getAcpBinaryPath:()=>ds,pickWhichLine:()=>Ia,probeAcpVersion:()=>vg,resolveAcpCommand:()=>_u});import{readFileSync as mu}from"node:fs";import{createRequire as _g}from"node:module";import{dirname as yg,resolve as bg}from"node:path";function Ia(t){let e=t.split(/\r?\n/).map(i=>i.trim()).filter(Boolean);if(e.length===0)return;if(process.platform!=="win32")return e[0];let r=i=>e.find(o=>o.toLowerCase().endsWith(i));return r(".cmd")??r(".exe")??r(".bat")??r(".ps1")??e[0]}function Eg(t){let e=wu.resolve(`${t.npmPackage}/package.json`),r=yg(e),i=JSON.parse(mu(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 bg(r,o)}async function sr(t,e){let r=Aa[t];if(!r)throw new C("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=Xr.get(t);if(i)return i;try{let o=Eg(r);return Xr.set(t,o),Sa.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw Sa.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 vg(t){let e=Aa[t];if(e)try{let r=wu.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(mu(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){Sa.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function ds(t){return Xr.get(t)}function _u(t,e){if(e)return e;let r=ds(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 ei(t,e,r){if(e)return{command:e,args:[...r]};let i=_u(t);return{command:process.execPath,args:[i,...r]}}function Sg(){Xr.clear()}function Ag(t,e){Xr.set(t,e)}var Sa,Aa,Qr,wu,Xr,rn=Je(()=>{"use strict";We();ne();Sa=q("agents.acp-installer"),Aa={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},Qr=Object.values(Aa).filter(t=>t!==void 0).map(t=>t.npmPackage),wu=_g(import.meta.url),Xr=new Map});import{chmod as Tg,mkdir as Cg,readFile as Rg,rename as kg,rm as Dg,writeFile as Pg}from"node:fs/promises";import{dirname as Og}from"node:path";async function or(t){try{let e=await Rg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function sn(t,e,r){await Cg(Og(t),{recursive:!0});let i=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{await Pg(i,e,{encoding:"utf8",mode:r?.mode}),await kg(i,t),r?.mode!==void 0&&await Tg(t,r.mode)}catch(o){throw await Dg(i,{force:!0}).catch(()=>{}),o}}async function ar(t,e,r){await sn(t,`${JSON.stringify(e,null,2)}
14
- `,r)}var on=Je(()=>{"use strict"});import{promises as vu,readdirSync as Lg}from"node:fs";import{homedir as Ng}from"node:os";import{sep as Mg,join as Te,resolve as Su}from"node:path";function X(t){let e=t??Ng(),r=Te(e,".coze"),i=Te(r,"bridge"),o=Te(i,"lib"),c=Te(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Te(o,"index.js"),binDir:Te(i,"bin"),pidFile:Te(i,"bridge.pid"),portFile:Te(i,"bridge.port"),tokenFile:Te(i,"bridge.token"),patTokenFile:Te(i,"pat-token"),agentEnvFile:Te(i,"agent-env.json"),logFile:Te(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Te(c,"daemon-stdio.log"),installLock:Te(i,"install.lock"),configFile:Te(i,"config.json"),agentsRoot:Te(r,"agents")}}function Xe(t,e=X()){let r=Te(e.agentsRoot,t);return{root:r,config:Te(r,"config.json"),workspace:Te(r,"workspace"),logs:Te(r,"logs")}}function us(t=X()){try{return Lg(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function ti(t,e){let r=await vu.realpath(Su(t)).catch(()=>null);if(!r)return!1;let i=await vu.realpath(Su(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+Mg)}var Oe=Je(()=>{"use strict"});var xs={};ya(xs,{AGENT_CONFIG_FILE_MODE:()=>ls,enforceAgentConfigMode:()=>Fg,loadAgentConfig:()=>Me,persistAgentSessions:()=>ni,persistAgentSkills:()=>fs,saveAgentConfig:()=>Qe});import{chmod as Bg,stat as zg}from"node:fs/promises";function Me(t,e){return or(Xe(t,e).config)}function Qe(t,e){return ar(Xe(t.agentId,e).config,t,{mode:ls})}async function Fg(t,e){if(process.platform==="win32")return;let r=Xe(t,e).config;try{let i=await zg(r);if(!i.isFile())return;let o=i.mode&511;o!==ls&&(await Bg(r,ls),Au.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Au.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function ni(t,e,r){let i=await Me(t,r);i&&(i.sessions=Object.fromEntries(e),await Qe(i,r))}async function fs(t,e,r){let i=await Me(t,r);i&&(i.skills=e,await Qe(i,r))}var Au,ls,an=Je(()=>{"use strict";on();ne();Oe();Au=q("agent-config"),ls=384});var Ra=ae((S2,Cu)=>{Cu.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 ps=ae(ku=>{var Ru={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 Wg(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(Ru))ku[t]=Wg(Ru[t])});var Nu=ae((I2,Lu)=>{var Kg=le("fs"),Le=le("path"),Du=Ra(),$g=ps(),Vg=typeof process=="object"&&process.platform==="win32",Pu=t=>typeof t=="object"&&t!==null,Ou=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=Le.sep,this.fs=Kg,Pu(t)&&Pu(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Lu.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 u;try{u=e.fs.statSync(o)}catch(f){if(f.message&&f.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw f}if(u&&u.isFile())throw $g.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 u=Le.dirname(t);o.fs.existsSync(u)||o.makeDir(u);var f;try{f=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),f=o.fs.openSync(t,"w",438)}if(f)try{o.fs.writeSync(f,e,0,e.length,0)}finally{o.fs.closeSync(f)}return o.fs.chmodSync(t,i||438),!0};be.prototype.writeFileToAsync=function(t,e,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(u){if(u&&!r)return o(!1);c.fs.stat(t,function(f,x){if(u&&x.isDirectory())return o(!1);var p=Le.dirname(t);c.fs.exists(p,function(m){m||c.makeDir(p),c.fs.open(t,"w",438,function(_,S){_?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(y,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)})})})})}):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 u=[];return e.fs.readdirSync(i).forEach(function(f){let x=Le.join(i,f),p=e.fs.statSync(x);(!o||o.test(x))&&u.push(Le.normalize(x)+(p.isDirectory()?e.sep:"")),p.isDirectory()&&c&&(u=u.concat(r(x,o,c)))}),u}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 u=c.length;if(!u)return e(null,i);c.forEach(function(f){f=Le.join(t,f),r.fs.stat(f,function(x,p){if(x)return e(x);p&&(i.push(Le.normalize(f)+(p.isDirectory()?r.sep:"")),p.isDirectory()?r.findFilesAsync(f,function(m,_){if(m)return e(m);i=i.concat(_),--u||e(null,i)}):--u||e(null,i))})})})};be.prototype.getAttributes=function(){};be.prototype.setAttributes=function(){};be.crc32update=function(t,e){return Ou[(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 Du.STORED:return"STORED ("+t+")";case Du.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};be.canonical=function(t){if(!t)return"";let e=Le.posix.normalize("/"+t.split("\\").join("/"));return Le.join(".",e)};be.zipnamefix=function(t){if(!t)return"";let e=Le.posix.normalize("/"+t.split("\\").join("/"));return Le.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=Le.resolve(Le.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Le.normalize(Le.join(t,r.slice(i,o).join(Le.sep)));if(c.indexOf(t)===0)return c}return Le.normalize(Le.join(t,Le.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=Vg;be.crcTable=Ou});var Bu=ae((T2,Mu)=>{var Yg=le("path");Mu.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=Yg.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 Fu=ae((C2,zu)=>{zu.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var ur=ae((R2,dr)=>{dr.exports=Nu();dr.exports.Constants=Ra();dr.exports.Errors=ps();dr.exports.FileAttr=Bu();dr.exports.decoder=Fu()});var qu=ae((k2,Uu)=>{var cn=ur(),U=cn.Constants;Uu.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,u=0,f=0,x=0,p=0,m=0,_=0,S=0,y=0,v=0;t|=cn.isWin?2560:768,r|=U.FLG_EFS;let A={extraLen:0},I=E=>Math.max(0,E)>>>0,R=E=>Math.max(0,E)&65535,D=E=>Math.max(0,E)&255;return o=cn.fromDate2DOS(new Date),{get made(){return t},set made(E){t=E},get version(){return e},set version(E){e=E},get flags(){return r},set flags(E){r=E},get flags_efs(){return(r&U.FLG_EFS)>0},set flags_efs(E){E?r|=U.FLG_EFS:r&=~U.FLG_EFS},get flags_desc(){return(r&U.FLG_DESC)>0},set flags_desc(E){E?r|=U.FLG_DESC:r&=~U.FLG_DESC},get method(){return i},set method(E){switch(E){case U.STORED:this.version=10;case U.DEFLATED:default:this.version=20}i=E},get time(){return cn.fromDOS2Date(this.timeval)},set time(E){E=new Date(E),this.timeval=cn.fromDate2DOS(E)},get timeval(){return o},set timeval(E){o=I(E)},get timeHighByte(){return D(o>>>8)},get crc(){return c},set crc(E){c=I(E)},get compressedSize(){return u},set compressedSize(E){u=I(E)},get size(){return f},set size(E){f=I(E)},get fileNameLength(){return x},set fileNameLength(E){x=E},get extraLength(){return p},set extraLength(E){p=E},get extraLocalLength(){return A.extraLen},set extraLocalLength(E){A.extraLen=E},get commentLength(){return m},set commentLength(E){m=E},get diskNumStart(){return _},set diskNumStart(E){_=I(E)},get inAttr(){return S},set inAttr(E){S=I(E)},get attr(){return y},set attr(E){y=I(E)},get fileAttr(){return(y||0)>>16&4095},get offset(){return v},set offset(E){v=I(E)},get encrypted(){return(r&U.FLG_ENC)===U.FLG_ENC},get centralHeaderSize(){return U.CENHDR+x+p+m},get realDataOffset(){return v+U.LOCHDR+A.fnameLen+A.extraLen},get localHeader(){return A},loadLocalHeaderFromBinary:function(E){var k=E.slice(v,v+U.LOCHDR);if(k.readUInt32LE(0)!==U.LOCSIG)throw cn.Errors.INVALID_LOC();A.version=k.readUInt16LE(U.LOCVER),A.flags=k.readUInt16LE(U.LOCFLG),A.flags_desc=(A.flags&U.FLG_DESC)>0,A.method=k.readUInt16LE(U.LOCHOW),A.time=k.readUInt32LE(U.LOCTIM),A.crc=k.readUInt32LE(U.LOCCRC),A.compressedSize=k.readUInt32LE(U.LOCSIZ),A.size=k.readUInt32LE(U.LOCLEN),A.fnameLen=k.readUInt16LE(U.LOCNAM),A.extraLen=k.readUInt16LE(U.LOCEXT);let P=v+U.LOCHDR+A.fnameLen,F=P+A.extraLen;return E.slice(P,F)},loadFromBinary:function(E){if(E.length!==U.CENHDR||E.readUInt32LE(0)!==U.CENSIG)throw cn.Errors.INVALID_CEN();t=E.readUInt16LE(U.CENVEM),e=E.readUInt16LE(U.CENVER),r=E.readUInt16LE(U.CENFLG),i=E.readUInt16LE(U.CENHOW),o=E.readUInt32LE(U.CENTIM),c=E.readUInt32LE(U.CENCRC),u=E.readUInt32LE(U.CENSIZ),f=E.readUInt32LE(U.CENLEN),x=E.readUInt16LE(U.CENNAM),p=E.readUInt16LE(U.CENEXT),m=E.readUInt16LE(U.CENCOM),_=E.readUInt16LE(U.CENDSK),S=E.readUInt16LE(U.CENATT),y=E.readUInt32LE(U.CENATX),v=E.readUInt32LE(U.CENOFF)},localHeaderToBinary:function(){var E=Buffer.alloc(U.LOCHDR);return E.writeUInt32LE(U.LOCSIG,0),E.writeUInt16LE(e,U.LOCVER),E.writeUInt16LE(r,U.LOCFLG),E.writeUInt16LE(i,U.LOCHOW),E.writeUInt32LE(o,U.LOCTIM),E.writeUInt32LE(c,U.LOCCRC),E.writeUInt32LE(u,U.LOCSIZ),E.writeUInt32LE(f,U.LOCLEN),E.writeUInt16LE(x,U.LOCNAM),E.writeUInt16LE(A.extraLen,U.LOCEXT),E},centralHeaderToBinary:function(){var E=Buffer.alloc(U.CENHDR+x+p+m);return E.writeUInt32LE(U.CENSIG,0),E.writeUInt16LE(t,U.CENVEM),E.writeUInt16LE(e,U.CENVER),E.writeUInt16LE(r,U.CENFLG),E.writeUInt16LE(i,U.CENHOW),E.writeUInt32LE(o,U.CENTIM),E.writeUInt32LE(c,U.CENCRC),E.writeUInt32LE(u,U.CENSIZ),E.writeUInt32LE(f,U.CENLEN),E.writeUInt16LE(x,U.CENNAM),E.writeUInt16LE(p,U.CENEXT),E.writeUInt16LE(m,U.CENCOM),E.writeUInt16LE(_,U.CENDSK),E.writeUInt16LE(S,U.CENATT),E.writeUInt32LE(y,U.CENATX),E.writeUInt32LE(v,U.CENOFF),E},toJSON:function(){let E=function(k){return k+" bytes"};return{made:t,version:e,flags:r,method:cn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:E(u),size:E(f),fileNameLength:E(x),extraLength:E(p),commentLength:E(m),diskNumStart:_,inAttr:S,attr:y,offset:v,centralHeaderSize:E(U.CENHDR+x+p+m)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Hu=ae((D2,Gu)=>{var lr=ur(),we=lr.Constants;Gu.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 we.ENDHDR+o},loadFromBinary:function(c){if((c.length!==we.ENDHDR||c.readUInt32LE(0)!==we.ENDSIG)&&(c.length<we.ZIP64HDR||c.readUInt32LE(0)!==we.ZIP64SIG))throw lr.Errors.INVALID_END();c.readUInt32LE(0)===we.ENDSIG?(t=c.readUInt16LE(we.ENDSUB),e=c.readUInt16LE(we.ENDTOT),r=c.readUInt32LE(we.ENDSIZ),i=c.readUInt32LE(we.ENDOFF),o=c.readUInt16LE(we.ENDCOM)):(t=lr.readBigUInt64LE(c,we.ZIP64SUB),e=lr.readBigUInt64LE(c,we.ZIP64TOT),r=lr.readBigUInt64LE(c,we.ZIP64SIZE),i=lr.readBigUInt64LE(c,we.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(we.ENDHDR+o);return c.writeUInt32LE(we.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,we.ENDSUB),c.writeUInt16LE(e,we.ENDTOT),c.writeUInt32LE(r,we.ENDSIZ),c.writeUInt32LE(i,we.ENDOFF),c.writeUInt16LE(o,we.ENDCOM),c.fill(" ",we.ENDHDR),c},toJSON:function(){let c=function(u,f){let x=u.toString(16).toUpperCase();for(;x.length<f;)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 Da=ae(ka=>{ka.EntryHeader=qu();ka.MainHeader=Hu()});var Wu=ae((O2,ju)=>{ju.exports=function(t){var e=le("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=[],u=0;o.on("data",function(f){c.push(f),u+=f.length}),o.on("end",function(){var f=Buffer.alloc(u),x=0;f.fill(0);for(var p=0;p<c.length;p++){var m=c[p];m.copy(f,x),x+=m.length}i&&i(f)}),o.end(t)}}}});var $u=ae((L2,Ku)=>{var Zg=+(process.versions?process.versions.node:"").split(".")[0]||0;Ku.exports=function(t,e){var r=le("zlib");let i=Zg>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),u=[],f=0;c.on("data",function(x){u.push(x),f+=x.length}),c.on("end",function(){var x=Buffer.alloc(f),p=0;x.fill(0);for(var m=0;m<u.length;m++){var _=u[m];_.copy(x,p),p+=_.length}o&&o(x)}),c.end(t)}}}});var Xu=ae((N2,Ju)=>{"use strict";var{randomFillSync:Vu}=le("crypto"),Jg=ps(),Xg=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}),Zu=(t,e)=>Math.imul(t,e)>>>0,Yu=(t,e)=>Xg[(t^e)&255]^t>>>8,ri=()=>typeof Vu=="function"?Vu(Buffer.alloc(12)):ri.node();ri.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 gs={genSalt:ri};function ms(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])}ms.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Yu(e[0],t),e[1]+=e[0]&255,e[1]=Zu(e[1],134775813)+1,e[2]=Yu(e[2],e[1]>>>24),t};ms.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Zu(t,t^1)>>8&255};function Qg(t){let e=new ms(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 em(t){let e=new ms(t);return function(r,i,o=0){i||(i=Buffer.alloc(r.length));for(let c of r){let u=e.next();i[o++]=c^u,e.updateKeys(c)}return i}}function tm(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 Jg.WRONG_PASSWORD();return i(t.slice(12))}function nm(t){Buffer.isBuffer(t)&&t.length>=12?gs.genSalt=function(){return t.slice(0,12)}:t==="node"?gs.genSalt=ri.node:gs.genSalt=ri}function rm(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=em(r),c=gs.genSalt();c[11]=e.crc>>>24&255,i&&(c[10]=e.crc>>>16&255);let u=Buffer.alloc(t.length+12);return o(c,u),o(t,u,12)}Ju.exports={decrypt:tm,encrypt:rm,_salter:nm}});var Qu=ae(ws=>{ws.Deflater=Wu();ws.Inflater=$u();ws.ZipCrypto=Xu()});var Oa=ae((B2,el)=>{var ce=ur(),im=Da(),Ee=ce.Constants,Pa=Qu();el.exports=function(t,e){var r=new im.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,u=null,f=Buffer.alloc(0),x=Buffer.alloc(0),p=!0;let m=t,_=typeof m.decoder=="object"?m.decoder:ce.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 y(E){if(!r.flags_desc&&!r.localHeader.flags_desc){if(ce.crc32(E)!==r.localHeader.crc)return!1}else{let k={},P=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(P)==Ee.LOCSIG||e.readUInt32LE(P)==Ee.CENSIG)throw ce.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(P)==Ee.EXTSIG)k.crc=e.readUInt32LE(P+Ee.EXTCRC),k.compressedSize=e.readUInt32LE(P+Ee.EXTSIZ),k.size=e.readUInt32LE(P+Ee.EXTLEN);else if(e.readUInt16LE(P+12)===19280)k.crc=e.readUInt32LE(P+Ee.EXTCRC-4),k.compressedSize=e.readUInt32LE(P+Ee.EXTSIZ-4),k.size=e.readUInt32LE(P+Ee.EXTLEN-4);else throw ce.Errors.DESCRIPTOR_UNKNOWN();if(k.compressedSize!==r.compressedSize||k.size!==r.size||k.crc!==r.crc)throw ce.Errors.DESCRIPTOR_FAULTY();if(ce.crc32(E)!==k.crc)return!1}return!0}function v(E,k,P){if(typeof k>"u"&&typeof E=="string"&&(P=E,E=void 0),c)return E&&k&&k(Buffer.alloc(0),ce.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var F=S();if(F.length===0)return E&&k&&k(F),F;if(r.encrypted){if(typeof P!="string"&&!Buffer.isBuffer(P))throw ce.Errors.INVALID_PASS_PARAM();F=Pa.ZipCrypto.decrypt(F,r,P)}var z=Buffer.alloc(r.size);switch(r.method){case ce.Constants.STORED:if(F.copy(z),y(z))return E&&k&&k(z),z;throw E&&k&&k(z,ce.Errors.BAD_CRC()),ce.Errors.BAD_CRC();case ce.Constants.DEFLATED:var Y=new Pa.Inflater(F,r.size);if(E)Y.inflateAsync(function($){$.copy($,0),k&&(y($)?k($):k($,ce.Errors.BAD_CRC()))});else{if(Y.inflate(z).copy(z,0),!y(z))throw ce.Errors.BAD_CRC(`"${_.decode(i)}"`);return z}break;default:throw E&&k&&k(Buffer.alloc(0),ce.Errors.UNKNOWN_METHOD()),ce.Errors.UNKNOWN_METHOD()}}function A(E,k){if((!u||!u.length)&&Buffer.isBuffer(e))return E&&k&&k(S()),S();if(u.length&&!c){var P;switch(r.method){case ce.Constants.STORED:return r.compressedSize=r.size,P=Buffer.alloc(u.length),u.copy(P),E&&k&&k(P),P;default:case ce.Constants.DEFLATED:var F=new Pa.Deflater(u);if(E)F.deflateAsync(function(Y){P=Buffer.alloc(Y.length),r.compressedSize=Y.length,Y.copy(P),k&&k(P)});else{var z=F.deflate();return r.compressedSize=z.length,z}F=null;break}}else if(E&&k)k(Buffer.alloc(0));else return Buffer.alloc(0)}function I(E,k){return ce.readBigUInt64LE(E,k)}function R(E){try{for(var k=0,P,F,z;k+4<E.length;)P=E.readUInt16LE(k),k+=2,F=E.readUInt16LE(k),k+=2,z=E.slice(k,k+F),k+=F,Ee.ID_ZIP64===P&&D(z)}catch{throw ce.Errors.EXTRA_FIELD_PARSE_ERROR()}}function D(E){var k,P,F,z;E.length>=Ee.EF_ZIP64_SCOMP&&(k=I(E,Ee.EF_ZIP64_SUNCOMP),r.size===Ee.EF_ZIP64_OR_32&&(r.size=k)),E.length>=Ee.EF_ZIP64_RHO&&(P=I(E,Ee.EF_ZIP64_SCOMP),r.compressedSize===Ee.EF_ZIP64_OR_32&&(r.compressedSize=P)),E.length>=Ee.EF_ZIP64_DSN&&(F=I(E,Ee.EF_ZIP64_RHO),r.offset===Ee.EF_ZIP64_OR_32&&(r.offset=F)),E.length>=Ee.EF_ZIP64_DSN+4&&(z=E.readUInt32LE(Ee.EF_ZIP64_DSN),r.diskNumStart===Ee.EF_ZIP64_OR_16&&(r.diskNumStart=z))}return{get entryName(){return _.decode(i)},get rawEntryName(){return i},set entryName(E){i=ce.toBuffer(E,_.encode);var k=i[i.length-1];c=k===47||k===92,r.fileNameLength=i.length},get efs(){return typeof p=="function"?p(this.entryName):p},get extra(){return f},set extra(E){f=E,r.extraLength=E.length,R(E)},get comment(){return _.decode(o)},set comment(E){if(o=ce.toBuffer(E,_.encode),r.commentLength=o.length,o.length>65535)throw ce.Errors.COMMENT_TOO_LONG()},get name(){var E=_.decode(i);return c?E.substr(E.length-1).split("/").pop():E.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return A(!1,null)},getCompressedDataAsync:function(E){A(!0,E)},setData:function(E){u=ce.toBuffer(E,ce.decoder.encode),!c&&u.length?(r.size=u.length,r.method=ce.Constants.DEFLATED,r.crc=ce.crc32(E),r.changed=!0):r.method=ce.Constants.STORED},getData:function(E){return r.changed?u:v(!1,null,E)},getDataAsync:function(E,k){r.changed?E(u):v(!0,E,k)},set attr(E){r.attr=E},get attr(){return r.attr},set header(E){r.loadFromBinary(E)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=f.length;var E=r.centralHeaderToBinary(),k=ce.Constants.CENHDR;return i.copy(E,k),k+=i.length,f.copy(E,k),k+=r.extraLength,o.copy(E,k),E},packLocalHeader:function(){let E=0;r.flags_efs=this.efs,r.extraLocalLength=x.length;let k=r.localHeaderToBinary(),P=Buffer.alloc(k.length+i.length+r.extraLocalLength);return k.copy(P,E),E+=k.length,i.copy(P,E),E+=i.length,x.copy(P,E),E+=x.length,P},toJSON:function(){let E=function(k){return"<"+(k&&k.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:E(e),data:E(u)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var rl=ae((z2,nl)=>{var tl=Oa(),sm=Da(),He=ur();nl.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new sm.MainHeader,u=!1,f=null;let x=new Set,p=e,{noSort:m,decoder:_}=p;t?v(p.readEntries):u=!0;function S(){let I=new Set;for(let R of Object.keys(i)){let D=R.split("/");if(D.pop(),!!D.length)for(let E=0;E<D.length;E++){let k=D.slice(0,E+1).join("/")+"/";I.add(k)}}for(let R of I)if(!(R in i)){let D=new tl(p);D.entryName=R,D.attr=16,D.temporary=!0,r.push(D),i[D.entryName]=D,x.add(D)}}function y(){if(u=!0,i={},c.diskEntries>(t.length-c.offset)/He.Constants.CENHDR)throw He.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var I=c.offset,R=0;R<r.length;R++){var D=I,E=new tl(p,t);E.header=t.slice(D,D+=He.Constants.CENHDR),E.entryName=t.slice(D,D+=E.header.fileNameLength),E.header.extraLength&&(E.extra=t.slice(D,D+=E.header.extraLength)),E.header.commentLength&&(E.comment=t.slice(D,D+E.header.commentLength)),I+=E.header.centralHeaderSize,r[R]=E,i[E.entryName]=E}x.clear(),S()}function v(I){var R=t.length-He.Constants.ENDHDR,D=Math.max(0,R-65535),E=D,k=t.length,P=-1,F=0;for(typeof p.trailingSpace=="boolean"&&p.trailingSpace&&(D=0),R;R>=E;R--)if(t[R]===80){if(t.readUInt32LE(R)===He.Constants.ENDSIG){P=R,F=R,k=R+He.Constants.ENDHDR,E=R-He.Constants.END64HDR;continue}if(t.readUInt32LE(R)===He.Constants.END64SIG){E=D;continue}if(t.readUInt32LE(R)===He.Constants.ZIP64SIG){P=R,k=R+He.readBigUInt64LE(t,R+He.Constants.ZIP64SIZE)+He.Constants.ZIP64LEAD;break}}if(P==-1)throw He.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(P,k)),c.commentLength&&(o=t.slice(F+He.Constants.ENDHDR)),I&&y()}function A(){r.length>1&&!m&&r.sort((I,R)=>I.entryName.toLowerCase().localeCompare(R.entryName.toLowerCase()))}return{get entries(){return u||y(),r.filter(I=>!x.has(I))},get comment(){return _.decode(o)},set comment(I){o=He.toBuffer(I,_.encode),c.commentLength=o.length},getEntryCount:function(){return u?r.length:c.diskEntries},forEach:function(I){this.entries.forEach(I)},getEntry:function(I){return u||y(),i[I]||null},setEntry:function(I){u||y(),r.push(I),i[I.entryName]=I,c.totalEntries=r.length},deleteFile:function(I,R=!0){u||y();let D=i[I];this.getEntryChildren(D,R).map(k=>k.entryName).forEach(this.deleteEntry)},deleteEntry:function(I){u||y();let R=i[I],D=r.indexOf(R);D>=0&&(r.splice(D,1),delete i[I],c.totalEntries=r.length)},getEntryChildren:function(I,R=!0){if(u||y(),typeof I=="object")if(I.isDirectory&&R){let D=[],E=I.entryName;for(let k of r)k.entryName.startsWith(E)&&D.push(k);return D}else return[I];return[]},getChildCount:function(I){if(I&&I.isDirectory){let R=this.getEntryChildren(I);return R.includes(I)?R.length-1:R.length}return 0},compressToBuffer:function(){u||y(),A();let I=[],R=[],D=0,E=0;c.size=0,c.offset=0;let k=0;for(let z of this.entries){let Y=z.getCompressedData();z.header.offset=E;let $=z.packLocalHeader(),te=$.length+Y.length;E+=te,I.push($),I.push(Y);let Z=z.packCentralHeader();R.push(Z),c.size+=Z.length,D+=te+Z.length,k++}D+=c.mainHeaderSize,c.offset=E,c.totalEntries=k,E=0;let P=Buffer.alloc(D);for(let z of I)z.copy(P,E),E+=z.length;for(let z of R)z.copy(P,E),E+=z.length;let F=c.toBinary();return o&&o.copy(F,He.Constants.ENDHDR),F.copy(P,E),t=P,u=!1,P},toAsyncBuffer:function(I,R,D,E){try{u||y(),A();let k=[],P=[],F=0,z=0,Y=0;c.size=0,c.offset=0;let $=function(te){if(te.length>0){let Z=te.shift(),ie=Z.entryName+Z.extra.toString();D&&D(ie),Z.getCompressedDataAsync(function(oe){E&&E(ie),Z.header.offset=z;let L=Z.packLocalHeader(),G=L.length+oe.length;z+=G,k.push(L),k.push(oe);let K=Z.packCentralHeader();P.push(K),c.size+=K.length,F+=G+K.length,Y++,$(te)})}else{F+=c.mainHeaderSize,c.offset=z,c.totalEntries=Y,z=0;let Z=Buffer.alloc(F);k.forEach(function(oe){oe.copy(Z,z),z+=oe.length}),P.forEach(function(oe){oe.copy(Z,z),z+=oe.length});let ie=c.toBinary();o&&o.copy(ie,He.Constants.ENDHDR),ie.copy(Z,z),t=Z,u=!1,I(Z)}};$(Array.from(this.entries))}catch(k){R(k)}}}}});var ol=ae((F2,sl)=>{var ye=ur(),_e=le("path"),om=Oa(),am=rl(),Dn=(...t)=>ye.findLast(t,e=>typeof e=="boolean"),il=(...t)=>ye.findLast(t,e=>typeof e=="string"),cm=(...t)=>ye.findLast(t,e=>typeof e=="function"),dm={noSort:!1,readEntries:!1,method:ye.Constants.NONE,fs:null};sl.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),dm);t&&typeof t=="object"&&(t instanceof Uint8Array||(Object.assign(i,t),t=i.input?i.input:void 0,i.input&&delete i.input),Buffer.isBuffer(t)&&(r=t,i.method=ye.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new ye(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=ye.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=ye.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw ye.Errors.INVALID_FILENAME();let c=new am(r,i),{canonical:u,sanitize:f,zipnamefix:x}=ye;function p(y){if(y&&c){var v;if(typeof y=="string"&&(v=c.getEntry(_e.posix.normalize(y))),typeof y=="object"&&typeof y.entryName<"u"&&typeof y.header<"u"&&(v=c.getEntry(y.entryName)),v)return v}return null}function m(y){let{join:v,normalize:A,sep:I}=_e.posix;return v(_e.isAbsolute(y)?"/":".",A(I+y.split("\\").join(I)+I))}function _(y){return y instanceof RegExp?(function(v){return function(A){return v.test(A)}})(y):typeof y!="function"?()=>!0:y}let S=(y,v)=>{let A=v.slice(-1);return A=A===o.sep?o.sep:"",_e.relative(y,v)+A};return{readFile:function(y,v){var A=p(y);return A&&A.getData(v)||null},childCount:function(y){let v=p(y);if(v)return c.getChildCount(v)},readFileAsync:function(y,v){var A=p(y);A?A.getDataAsync(v):v(null,"getEntry failed for:"+y)},readAsText:function(y,v){var A=p(y);if(A){var I=A.getData();if(I&&I.length)return I.toString(v||"utf8")}return""},readAsTextAsync:function(y,v,A){var I=p(y);I?I.getDataAsync(function(R,D){if(D){v(R,D);return}R&&R.length?v(R.toString(A||"utf8")):v("")}):v("")},deleteFile:function(y,v=!0){var A=p(y);A&&c.deleteFile(A.entryName,v)},deleteEntry:function(y){var v=p(y);v&&c.deleteEntry(v.entryName)},addZipComment:function(y){c.comment=y},getZipComment:function(){return c.comment||""},addZipEntryComment:function(y,v){var A=p(y);A&&(A.comment=v)},getZipEntryComment:function(y){var v=p(y);return v&&v.comment||""},updateFile:function(y,v){var A=p(y);A&&A.setData(v)},addLocalFile:function(y,v,A,I){if(o.fs.existsSync(y)){v=v?m(v):"";let R=_e.win32.basename(_e.win32.normalize(y));v+=A||R;let D=o.fs.statSync(y),E=D.isFile()?o.fs.readFileSync(y):Buffer.alloc(0);D.isDirectory()&&(v+=o.sep),this.addFile(v,E,I,D)}else throw ye.Errors.FILE_NOT_FOUND(y)},addLocalFileAsync:function(y,v){y=typeof y=="object"?y:{localPath:y};let A=_e.resolve(y.localPath),{comment:I}=y,{zipPath:R,zipName:D}=y,E=this;o.fs.stat(A,function(k,P){if(k)return v(k,!1);R=R?m(R):"";let F=_e.win32.basename(_e.win32.normalize(A));if(R+=D||F,P.isFile())o.fs.readFile(A,function(z,Y){return z?v(z,!1):(E.addFile(R,Y,I,P),setImmediate(v,void 0,!0))});else if(P.isDirectory())return R+=o.sep,E.addFile(R,Buffer.alloc(0),I,P),setImmediate(v,void 0,!0)})},addLocalFolder:function(y,v,A){if(A=_(A),v=v?m(v):"",y=_e.normalize(y),o.fs.existsSync(y)){let I=o.findFiles(y),R=this;if(I.length)for(let D of I){let E=_e.join(v,S(y,D));A(E)&&R.addLocalFile(D,_e.dirname(E))}}else throw ye.Errors.FILE_NOT_FOUND(y)},addLocalFolderAsync:function(y,v,A,I){I=_(I),A=A?m(A):"",y=_e.normalize(y);var R=this;o.fs.open(y,"r",function(D){if(D&&D.code==="ENOENT")v(void 0,ye.Errors.FILE_NOT_FOUND(y));else if(D)v(void 0,D);else{var E=o.findFiles(y),k=-1,P=function(){if(k+=1,k<E.length){var F=E[k],z=S(y,F).split("\\").join("/");z=z.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),I(z)?o.fs.stat(F,function(Y,$){Y&&v(void 0,Y),$.isFile()?o.fs.readFile(F,function(te,Z){te?v(void 0,te):(R.addFile(A+z,Z,"",$),P())}):(R.addFile(A+z+"/",Buffer.alloc(0),"",$),P())}):process.nextTick(()=>{P()})}else v(!0,void 0)};P()}})},addLocalFolderAsync2:function(y,v){let A=this;y=typeof y=="object"?y:{localPath:y},localPath=_e.resolve(m(y.localPath));let{zipPath:I,filter:R,namefix:D}=y;R instanceof RegExp?R=(function(P){return function(F){return P.test(F)}})(R):typeof R!="function"&&(R=function(){return!0}),I=I?m(I):"",D=="latin1"&&(D=P=>P.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof D!="function"&&(D=P=>P);let E=P=>_e.join(I,D(S(localPath,P))),k=P=>_e.win32.basename(_e.win32.normalize(D(P)));o.fs.open(localPath,"r",function(P){P&&P.code==="ENOENT"?v(void 0,ye.Errors.FILE_NOT_FOUND(localPath)):P?v(void 0,P):o.findFilesAsync(localPath,function(F,z){if(F)return v(F);z=z.filter(Y=>R(E(Y))),z.length||v(void 0,!1),setImmediate(z.reverse().reduce(function(Y,$){return function(te,Z){if(te||Z===!1)return setImmediate(Y,te,!1);A.addLocalFileAsync({localPath:$,zipPath:_e.dirname(E($)),zipName:k($)},Y)}},v))})})},addLocalFolderPromise:function(y,v){return new Promise((A,I)=>{this.addLocalFolderAsync2(Object.assign({localPath:y},v),(R,D)=>{R&&I(R),D&&A(this)})})},addFile:function(y,v,A,I){y=x(y);let R=p(y),D=R!=null;D||(R=new om(i),R.entryName=y),R.comment=A||"";let E=typeof I=="object"&&I instanceof o.fs.Stats;E&&(R.header.time=I.mtime);var k=R.isDirectory?16:0;let P=R.isDirectory?16384:32768;return E?P|=4095&I.mode:typeof I=="number"?P|=4095&I:P|=R.isDirectory?493:420,k=(k|P<<16)>>>0,R.attr=k,R.setData(v),D||c.setEntry(R),R},getEntries:function(y){return c.password=y,c?c.entries:[]},getEntry:function(y){return p(y)},getEntryCount:function(){return c.getEntryCount()},forEach:function(y){return c.forEach(y)},extractEntryTo:function(y,v,A,I,R,D){I=Dn(!1,I),R=Dn(!1,R),A=Dn(!0,A),D=il(R,D);var E=p(y);if(!E)throw ye.Errors.NO_ENTRY();var k=u(E.entryName),P=f(v,D&&!E.isDirectory?D:A?k:_e.basename(k));if(E.isDirectory){var F=c.getEntryChildren(E);return F.forEach(function($){if($.isDirectory)return;var te=$.getData();if(!te)throw ye.Errors.CANT_EXTRACT_FILE();var Z=u($.entryName),ie=f(v,A?Z:_e.basename(Z));let oe=R?$.header.fileAttr:void 0;o.writeFileTo(ie,te,I,oe)}),!0}var z=E.getData(c.password);if(!z)throw ye.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(P)&&!I)throw ye.Errors.CANT_OVERRIDE();let Y=R?y.header.fileAttr:void 0;return o.writeFileTo(P,z,I,Y),!0},test:function(y){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var A=c.entries[v].getData(y);if(!A)return!1}catch{return!1}return!0},extractAllTo:function(y,v,A,I){if(A=Dn(!1,A),I=il(A,I),v=Dn(!1,v),!c)throw ye.Errors.NO_ZIP();c.entries.forEach(function(R){var D=f(y,u(R.entryName));if(R.isDirectory){o.makeDir(D);return}var E=R.getData(I);if(!E)throw ye.Errors.CANT_EXTRACT_FILE();let k=A?R.header.fileAttr:void 0;o.writeFileTo(D,E,v,k);try{o.fs.utimesSync(D,R.header.time,R.header.time)}catch{throw ye.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(y,v,A,I){if(I=cm(v,A,I),A=Dn(!1,A),v=Dn(!1,v),!I)return new Promise((P,F)=>{this.extractAllToAsync(y,v,A,function(z){z?F(z):P(this)})});if(!c){I(ye.Errors.NO_ZIP());return}y=_e.resolve(y);let R=P=>f(y,_e.normalize(u(P.entryName))),D=(P,F)=>new Error(P+': "'+F+'"'),E=[],k=[];c.entries.forEach(P=>{P.isDirectory?E.push(P):k.push(P)});for(let P of E){let F=R(P),z=A?P.header.fileAttr:void 0;try{o.makeDir(F),z&&o.fs.chmodSync(F,z),o.fs.utimesSync(F,P.header.time,P.header.time)}catch{I(D("Unable to create folder",F))}}k.reverse().reduce(function(P,F){return function(z){if(z)P(z);else{let Y=_e.normalize(u(F.entryName)),$=f(y,Y);F.getDataAsync(function(te,Z){if(Z)P(Z);else if(!te)P(ye.Errors.CANT_EXTRACT_FILE());else{let ie=A?F.header.fileAttr:void 0;o.writeFileToAsync($,te,v,ie,function(oe){oe||P(D("Unable to write file",$)),o.fs.utimes($,F.header.time,F.header.time,function(L){L?P(D("Unable to set times",$)):P()})})}})}}},I)()},writeZip:function(y,v){if(arguments.length===1&&typeof y=="function"&&(v=y,y=""),!y&&i.filename&&(y=i.filename),!!y){var A=c.compressToBuffer();if(A){var I=o.writeFileTo(y,A,!0);typeof v=="function"&&v(I?null:new Error("failed"),"")}}},writeZipPromise:function(y,v){let{overwrite:A,perm:I}=Object.assign({overwrite:!0},v);return new Promise((R,D)=>{!y&&i.filename&&(y=i.filename),y||D("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(E=>{let k=P=>P?R(P):D("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(y,E,A,I,k)},D)})},toBufferPromise:function(){return new Promise((y,v)=>{c.toAsyncBuffer(y,v)})},toBuffer:function(y,v,A,I){return typeof y=="function"?(c.toAsyncBuffer(y,v,A,I),null):c.compressToBuffer()}}}});import{execFile as p_,spawn as g_,spawnSync as rI}from"node:child_process";import{promisify as m_}from"node:util";function __(t){if(process.platform!=="win32")return!1;if(If.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(If,"").toLowerCase();return w_.has(r)}function Tf(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return __(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function nt(t,e=[],r={}){return g_(t,e,Tf(t,r))}function Cf(t,e=[],r={}){return y_(t,e,Tf(t,r))}var w_,If,y_,Kt=Je(()=>{"use strict";w_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),If=/\.(cmd|bat|ps1)$/i;y_=m_(p_)});var Vt=ae((LC,rx)=>{"use strict";var tx=["nodebuffer","arraybuffer","fragments"],nx=typeof Blob<"u";nx&&tx.push("blob");rx.exports={BINARY_TYPES:tx,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:nx,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var ji=ae((NC,So)=>{"use strict";var{EMPTY_BUFFER:Jb}=Vt(),od=Buffer[Symbol.species];function Xb(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 od(r.buffer,r.byteOffset,i):r}function ix(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function sx(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function Qb(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function ad(t){if(ad.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new od(t):ArrayBuffer.isView(t)?e=new od(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),ad.readOnly=!1),e}So.exports={concat:Xb,mask:ix,toArrayBuffer:Qb,toBuffer:ad,unmask:sx};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=le("bufferutil");So.exports.mask=function(e,r,i,o,c){c<48?ix(e,r,i,o,c):t.mask(e,r,i,o,c)},So.exports.unmask=function(e,r){e.length<32?sx(e,r):t.unmask(e,r)}}catch{}});var cx=ae((MC,ax)=>{"use strict";var ox=Symbol("kDone"),cd=Symbol("kRun"),dd=class{constructor(e){this[ox]=()=>{this.pending--,this[cd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[cd]()}[cd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[ox])}}};ax.exports=dd});var Br=ae((BC,fx)=>{"use strict";var Wi=le("zlib"),dx=ji(),eE=cx(),{kStatusCode:ux}=Vt(),tE=Buffer[Symbol.species],nE=Buffer.from([0,0,255,255]),Io=Symbol("permessage-deflate"),Yt=Symbol("total-length"),Nr=Symbol("callback"),In=Symbol("buffers"),Mr=Symbol("error"),Ao,ud=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 eE(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[Nr];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,u)=>{o(),i(c,u)})})}compress(e,r,i){Ao.add(o=>{this._compress(e,r,(c,u)=>{o(),i(c,u)})})}_decompress(e,r,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,u=typeof this.params[c]!="number"?Wi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Wi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:u}),this._inflate[Io]=this,this._inflate[Yt]=0,this._inflate[In]=[],this._inflate.on("error",iE),this._inflate.on("data",lx)}this._inflate[Nr]=i,this._inflate.write(e),r&&this._inflate.write(nE),this._inflate.flush(()=>{let c=this._inflate[Mr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let u=dx.concat(this._inflate[In],this._inflate[Yt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Yt]=0,this._inflate[In]=[],r&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,u)})}_compress(e,r,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,u=typeof this.params[c]!="number"?Wi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Wi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:u}),this._deflate[Yt]=0,this._deflate[In]=[],this._deflate.on("data",rE)}this._deflate[Nr]=i,this._deflate.write(e),this._deflate.flush(Wi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=dx.concat(this._deflate[In],this._deflate[Yt]);r&&(c=new tE(c.buffer,c.byteOffset,c.length-4)),this._deflate[Nr]=null,this._deflate[Yt]=0,this._deflate[In]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};fx.exports=ud;function rE(t){this[In].push(t),this[Yt]+=t.length}function lx(t){if(this[Yt]+=t.length,this[Io]._maxPayload<1||this[Yt]<=this[Io]._maxPayload){this[In].push(t);return}this[Mr]=new RangeError("Max payload size exceeded"),this[Mr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Mr][ux]=1009,this.removeListener("data",lx),this.reset()}function iE(t){if(this[Io]._inflate=null,this[Mr]){this[Nr](this[Mr]);return}t[ux]=1007,this[Nr](t)}});var zr=ae((zC,To)=>{"use strict";var{isUtf8:xx}=le("buffer"),{hasBlob:sE}=Vt(),oE=[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 aE(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function ld(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 cE(t){return sE&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}To.exports={isBlob:cE,isValidStatusCode:aE,isValidUTF8:ld,tokenChars:oE};if(xx)To.exports.isValidUTF8=function(t){return t.length<24?ld(t):xx(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=le("utf-8-validate");To.exports.isValidUTF8=function(e){return e.length<32?ld(e):t(e)}}catch{}});var gd=ae((FC,bx)=>{"use strict";var{Writable:dE}=le("stream"),hx=Br(),{BINARY_TYPES:uE,EMPTY_BUFFER:px,kStatusCode:lE,kWebSocket:fE}=Vt(),{concat:fd,toArrayBuffer:xE,unmask:hE}=ji(),{isValidStatusCode:pE,isValidUTF8:gx}=zr(),Co=Buffer[Symbol.species],ut=0,mx=1,_x=2,yx=3,xd=4,hd=5,Ro=6,pd=class extends dE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||uE[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=e.maxBufferedChunks|0,this._maxFragments=e.maxFragments|0,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[fE]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=ut}_write(e,r,i){if(this._opcode===8&&this._state==ut)return i();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){i(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(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 Co(i.buffer,i.byteOffset+e,i.length-e),new Co(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 Co(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case ut:this.getInfo(e);break;case mx:this.getPayloadLength16(e);break;case _x:this.getPayloadLength64(e);break;case yx:this.getMask();break;case xd:this.getData(e);break;case hd:case Ro:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if((r[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(r[0]&64)===64;if(i&&!this._extensions[hx.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=mx:this._payloadLength===127?this._state=_x: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=yx:this._state=xd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=xd}getData(e){let r=px;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&&hE(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=hd,this.decompress(r,e);return}if(r.length){if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let i=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(i);return}this._messageLength=this._totalPayloadLength,this._fragments.push(r)}this.dataMessage(e)}decompress(e,r){this._extensions[hx.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 u=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(u);return}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let u=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");r(u);return}this._fragments.push(c)}this.dataMessage(r),this._state===ut&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=ut;return}let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=fd(i,r):this._binaryType==="arraybuffer"?o=xE(fd(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=ut):(this._state=Ro,setImmediate(()=>{this.emit("message",o,!0),this._state=ut,this.startLoop(e)}))}else{let o=fd(i,r);if(!this._skipUTF8Validation&&!gx(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===hd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=ut):(this._state=Ro,setImmediate(()=>{this.emit("message",o,!1),this._state=ut,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,px),this.end();else{let i=e.readUInt16BE(0);if(!pE(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Co(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!gx(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(c);return}this._loop=!1,this.emit("conclude",i,o),this.end()}this._state=ut;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=ut):(this._state=Ro,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=ut,this.startLoop(r)}))}createError(e,r,i,o,c){this._loop=!1,this._errored=!0;let u=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(u,this.createError),u.code=c,u[lE]=o,u}};bx.exports=pd});var _d=ae((qC,Sx)=>{"use strict";var{Duplex:UC}=le("stream"),{randomFillSync:gE}=le("crypto"),{types:{isUint8Array:mE}}=le("util"),Ex=Br(),{EMPTY_BUFFER:wE,kWebSocket:_E,NOOP:yE}=Vt(),{isBlob:Fr,isValidStatusCode:bE}=zr(),{mask:vx,toBuffer:Kn}=ji(),lt=Symbol("kByteLength"),EE=Buffer.alloc(4),ko=8*1024,$n,Ur=ko,Et=0,vE=1,SE=2,md=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=Et,this.onerror=yE,this[_E]=void 0}static frame(e,r){let i,o=!1,c=2,u=!1;r.mask&&(i=r.maskBuffer||EE,r.generateMask?r.generateMask(i):(Ur===ko&&($n===void 0&&($n=Buffer.alloc(ko)),gE($n,0,ko),Ur=0),i[0]=$n[Ur++],i[1]=$n[Ur++],i[2]=$n[Ur++],i[3]=$n[Ur++]),u=(i[0]|i[1]|i[2]|i[3])===0,c=6);let f;typeof e=="string"?(!r.mask||u)&&r[lt]!==void 0?f=r[lt]:(e=Buffer.from(e),f=e.length):(f=e.length,o=r.mask&&r.readOnly&&!u);let x=f;f>=65536?(c+=8,x=127):f>125&&(c+=2,x=126);let p=Buffer.allocUnsafe(o?f+c:c);return p[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(p[0]|=64),p[1]=x,x===126?p.writeUInt16BE(f,2):x===127&&(p[2]=p[3]=0,p.writeUIntBE(f,4,6)),r.mask?(p[1]|=128,p[c-4]=i[0],p[c-3]=i[1],p[c-2]=i[2],p[c-1]=i[3],u?[p,e]:o?(vx(e,i,p,c,f),[p]):(vx(e,i,e,0,f),[p,e])):[p,e]}close(e,r,i,o){let c;if(e===void 0)c=wE;else{if(typeof e!="number"||!bE(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let f=Buffer.byteLength(r);if(f>123)throw new RangeError("The message must not be greater than 123 bytes");if(c=Buffer.allocUnsafe(2+f),c.writeUInt16BE(e,0),typeof r=="string")c.write(r,2);else if(mE(r))c.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let u={[lt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==Et?this.enqueue([this.dispatch,c,!1,u,o]):this.sendFrame(t.frame(c,u),o)}ping(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Fr(e)?(o=e.size,c=!1):(e=Kn(e),o=e.length,c=Kn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let u={[lt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Fr(e)?this._state!==Et?this.enqueue([this.getBlobData,e,!1,u,i]):this.getBlobData(e,!1,u,i):this._state!==Et?this.enqueue([this.dispatch,e,!1,u,i]):this.sendFrame(t.frame(e,u),i)}pong(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Fr(e)?(o=e.size,c=!1):(e=Kn(e),o=e.length,c=Kn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let u={[lt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Fr(e)?this._state!==Et?this.enqueue([this.getBlobData,e,!1,u,i]):this.getBlobData(e,!1,u,i):this._state!==Et?this.enqueue([this.dispatch,e,!1,u,i]):this.sendFrame(t.frame(e,u),i)}send(e,r,i){let o=this._extensions[Ex.extensionName],c=r.binary?2:1,u=r.compress,f,x;typeof e=="string"?(f=Buffer.byteLength(e),x=!1):Fr(e)?(f=e.size,x=!1):(e=Kn(e),f=e.length,x=Kn.readOnly),this._firstFragment?(this._firstFragment=!1,u&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(u=f>=o._threshold),this._compress=u):(u=!1,c=0),r.fin&&(this._firstFragment=!0);let p={[lt]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:x,rsv1:u};Fr(e)?this._state!==Et?this.enqueue([this.getBlobData,e,this._compress,p,i]):this.getBlobData(e,this._compress,p,i):this._state!==Et?this.enqueue([this.dispatch,e,this._compress,p,i]):this.dispatch(e,this._compress,p,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[lt],this._state=SE,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let f=new Error("The socket was closed while the blob was being read");process.nextTick(wd,this,f,o);return}this._bufferedBytes-=i[lt];let u=Kn(c);r?this.dispatch(u,r,i,o):(this._state=Et,this.sendFrame(t.frame(u,i),o),this.dequeue())}).catch(c=>{process.nextTick(AE,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Ex.extensionName];this._bufferedBytes+=i[lt],this._state=vE,c.compress(e,i.fin,(u,f)=>{if(this._socket.destroyed){let x=new Error("The socket was closed while data was being compressed");wd(this,x,o);return}this._bufferedBytes-=i[lt],this._state=Et,i.readOnly=!1,this.sendFrame(t.frame(f,i),o),this.dequeue()})}dequeue(){for(;this._state===Et&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][lt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][lt],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)}};Sx.exports=md;function wd(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 AE(t,e,r){wd(t,e,r),t.onerror(e)}});var Ox=ae((GC,Px)=>{"use strict";var{kForOnEventAttribute:Ki,kListener:yd}=Vt(),Ax=Symbol("kCode"),Ix=Symbol("kData"),Tx=Symbol("kError"),Cx=Symbol("kMessage"),Rx=Symbol("kReason"),qr=Symbol("kTarget"),kx=Symbol("kType"),Dx=Symbol("kWasClean"),Zt=class{constructor(e){this[qr]=null,this[kx]=e}get target(){return this[qr]}get type(){return this[kx]}};Object.defineProperty(Zt.prototype,"target",{enumerable:!0});Object.defineProperty(Zt.prototype,"type",{enumerable:!0});var Vn=class extends Zt{constructor(e,r={}){super(e),this[Ax]=r.code===void 0?0:r.code,this[Rx]=r.reason===void 0?"":r.reason,this[Dx]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Ax]}get reason(){return this[Rx]}get wasClean(){return this[Dx]}};Object.defineProperty(Vn.prototype,"code",{enumerable:!0});Object.defineProperty(Vn.prototype,"reason",{enumerable:!0});Object.defineProperty(Vn.prototype,"wasClean",{enumerable:!0});var Gr=class extends Zt{constructor(e,r={}){super(e),this[Tx]=r.error===void 0?null:r.error,this[Cx]=r.message===void 0?"":r.message}get error(){return this[Tx]}get message(){return this[Cx]}};Object.defineProperty(Gr.prototype,"error",{enumerable:!0});Object.defineProperty(Gr.prototype,"message",{enumerable:!0});var $i=class extends Zt{constructor(e,r={}){super(e),this[Ix]=r.data===void 0?null:r.data}get data(){return this[Ix]}};Object.defineProperty($i.prototype,"data",{enumerable:!0});var IE={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Ki]&&o[yd]===e&&!o[Ki])return;let i;if(t==="message")i=function(c,u){let f=new $i("message",{data:u?c:c.toString()});f[qr]=this,Do(e,this,f)};else if(t==="close")i=function(c,u){let f=new Vn("close",{code:c,reason:u.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});f[qr]=this,Do(e,this,f)};else if(t==="error")i=function(c){let u=new Gr("error",{error:c,message:c.message});u[qr]=this,Do(e,this,u)};else if(t==="open")i=function(){let c=new Zt("open");c[qr]=this,Do(e,this,c)};else return;i[Ki]=!!r[Ki],i[yd]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[yd]===e&&!r[Ki]){this.removeListener(t,r);break}}};Px.exports={CloseEvent:Vn,ErrorEvent:Gr,Event:Zt,EventTarget:IE,MessageEvent:$i};function Do(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Po=ae((HC,Lx)=>{"use strict";var{tokenChars:Vi}=zr();function Lt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function TE(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,u,f,x=-1,p=-1,m=-1,_=0;for(;_<t.length;_++)if(p=t.charCodeAt(_),u===void 0)if(m===-1&&Vi[p]===1)x===-1&&(x=_);else if(_!==0&&(p===32||p===9))m===-1&&x!==-1&&(m=_);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);m===-1&&(m=_);let y=t.slice(x,m);p===44?(Lt(e,y,r),r=Object.create(null)):u=y,x=m=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);else if(f===void 0)if(m===-1&&Vi[p]===1)x===-1&&(x=_);else if(p===32||p===9)m===-1&&x!==-1&&(m=_);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);m===-1&&(m=_),Lt(r,t.slice(x,m),!0),p===44&&(Lt(e,u,r),r=Object.create(null),u=void 0),x=m=-1}else if(p===61&&x!==-1&&m===-1)f=t.slice(x,_),x=m=-1;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(o){if(Vi[p]!==1)throw new SyntaxError(`Unexpected character at index ${_}`);x===-1?x=_:i||(i=!0),o=!1}else if(c)if(Vi[p]===1)x===-1&&(x=_);else if(p===34&&x!==-1)c=!1,m=_;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(m===-1&&Vi[p]===1)x===-1&&(x=_);else if(x!==-1&&(p===32||p===9))m===-1&&(m=_);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);m===-1&&(m=_);let y=t.slice(x,m);i&&(y=y.replace(/\\/g,""),i=!1),Lt(r,f,y),p===44&&(Lt(e,u,r),r=Object.create(null),u=void 0),f=void 0,x=m=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);if(x===-1||c||p===32||p===9)throw new SyntaxError("Unexpected end of input");m===-1&&(m=_);let S=t.slice(x,m);return u===void 0?Lt(e,S,r):(f===void 0?Lt(r,S,!0):i?Lt(r,f,S.replace(/\\/g,"")):Lt(r,f,S),Lt(e,u,r)),e}function CE(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(u=>u===!0?o:`${o}=${u}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Lx.exports={format:CE,parse:TE}});var Mo=ae((KC,Kx)=>{"use strict";var RE=le("events"),kE=le("https"),DE=le("http"),Bx=le("net"),PE=le("tls"),{randomBytes:OE,createHash:LE}=le("crypto"),{Duplex:jC,Readable:WC}=le("stream"),{URL:bd}=le("url"),Tn=Br(),NE=gd(),ME=_d(),{isBlob:BE}=zr(),{BINARY_TYPES:Nx,CLOSE_TIMEOUT:zE,EMPTY_BUFFER:Oo,GUID:FE,kForOnEventAttribute:Ed,kListener:UE,kStatusCode:qE,kWebSocket:qe,NOOP:zx}=Vt(),{EventTarget:{addEventListener:GE,removeEventListener:HE}}=Ox(),{format:jE,parse:WE}=Po(),{toBuffer:KE}=ji(),Fx=Symbol("kAborted"),vd=[8,13],Jt=["CONNECTING","OPEN","CLOSING","CLOSED"],$E=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,ge=class t extends RE{constructor(e,r,i){super(),this._binaryType=Nx[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Oo,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]),Ux(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Nx.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 NE({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxBufferedChunks:i.maxBufferedChunks,maxFragments:i.maxFragments,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new ME(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[qe]=this,c[qe]=this,e[qe]=this,o.on("conclude",ZE),o.on("drain",JE),o.on("error",XE),o.on("message",QE),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",Hx),e.on("data",No),e.on("end",jx),e.on("error",Wx),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[Tn.extensionName]&&this._extensions[Tn.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){ot(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())}),Gx(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){Sd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Oo,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){Sd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Oo,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){Sd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[Tn.extensionName]||(o.compress=!1),this._sender.send(e||Oo,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){ot(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(ge,"CONNECTING",{enumerable:!0,value:Jt.indexOf("CONNECTING")});Object.defineProperty(ge.prototype,"CONNECTING",{enumerable:!0,value:Jt.indexOf("CONNECTING")});Object.defineProperty(ge,"OPEN",{enumerable:!0,value:Jt.indexOf("OPEN")});Object.defineProperty(ge.prototype,"OPEN",{enumerable:!0,value:Jt.indexOf("OPEN")});Object.defineProperty(ge,"CLOSING",{enumerable:!0,value:Jt.indexOf("CLOSING")});Object.defineProperty(ge.prototype,"CLOSING",{enumerable:!0,value:Jt.indexOf("CLOSING")});Object.defineProperty(ge,"CLOSED",{enumerable:!0,value:Jt.indexOf("CLOSED")});Object.defineProperty(ge.prototype,"CLOSED",{enumerable:!0,value:Jt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(ge.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(ge.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Ed])return e[UE];return null},set(e){for(let r of this.listeners(t))if(r[Ed]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[Ed]:!0})}})});ge.prototype.addEventListener=GE;ge.prototype.removeEventListener=HE;Kx.exports=ge;function Ux(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:zE,protocolVersion:vd[1],maxBufferedChunks:1048576,maxFragments:131072,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,!vd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${vd.join(", ")})`);let c;if(e instanceof bd)c=e;else try{c=new bd(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 u=c.protocol==="wss:",f=c.protocol==="ws+unix:",x;if(c.protocol!=="ws:"&&!u&&!f?x=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:f&&!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;Lo(t,A);return}let p=u?443:80,m=OE(16).toString("base64"),_=u?kE.request:DE.request,S=new Set,y;if(o.createConnection=o.createConnection||(u?YE:VE),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":m,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(y=new Tn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=jE({[Tn.extensionName]:y.offer()})),r.length){for(let A of r){if(typeof A!="string"||!$E.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}`),f){let A=o.path.split(":");o.socketPath=A[0],o.path=A[1]}let v;if(o.followRedirects){if(t._redirects===0){t._originalIpc=f,t._originalSecure=u,t._originalHostOrSocketPath=f?o.socketPath:c.host;let A=i&&i.headers;if(i={...i,headers:{}},A)for(let[I,R]of Object.entries(A))i.headers[I.toLowerCase()]=R}else if(t.listenerCount("redirect")===0){let A=f?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!A||t._originalSecure&&!u)&&(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")),v=t._req=_(o),t._redirects&&t.emit("redirect",t.url,v)}else v=t._req=_(o);o.timeout&&v.on("timeout",()=>{ot(t,v,"Opening handshake has timed out")}),v.on("error",A=>{v===null||v[Fx]||(v=t._req=null,Lo(t,A))}),v.on("response",A=>{let I=A.headers.location,R=A.statusCode;if(I&&o.followRedirects&&R>=300&&R<400){if(++t._redirects>o.maxRedirects){ot(t,v,"Maximum redirects exceeded");return}v.abort();let D;try{D=new bd(I,e)}catch{let k=new SyntaxError(`Invalid URL: ${I}`);Lo(t,k);return}Ux(t,D,r,i)}else t.emit("unexpected-response",v,A)||ot(t,v,`Unexpected server response: ${A.statusCode}`)}),v.on("upgrade",(A,I,R)=>{if(t.emit("upgrade",A),t.readyState!==ge.CONNECTING)return;v=t._req=null;let D=A.headers.upgrade;if(D===void 0||D.toLowerCase()!=="websocket"){ot(t,I,"Invalid Upgrade header");return}let E=LE("sha1").update(m+FE).digest("base64");if(A.headers["sec-websocket-accept"]!==E){ot(t,I,"Invalid Sec-WebSocket-Accept header");return}let k=A.headers["sec-websocket-protocol"],P;if(k!==void 0?S.size?S.has(k)||(P="Server sent an invalid subprotocol"):P="Server sent a subprotocol but none was requested":S.size&&(P="Server sent no subprotocol"),P){ot(t,I,P);return}k&&(t._protocol=k);let F=A.headers["sec-websocket-extensions"];if(F!==void 0){if(!y){ot(t,I,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let z;try{z=WE(F)}catch{ot(t,I,"Invalid Sec-WebSocket-Extensions header");return}let Y=Object.keys(z);if(Y.length!==1||Y[0]!==Tn.extensionName){ot(t,I,"Server indicated an extension that was not requested");return}try{y.accept(z[Tn.extensionName])}catch{ot(t,I,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[Tn.extensionName]=y}t.setSocket(I,R,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(v,t):v.end()}function Lo(t,e){t._readyState=ge.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function VE(t){return t.path=t.socketPath,Bx.connect(t)}function YE(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Bx.isIP(t.host)?"":t.host),PE.connect(t)}function ot(t,e,r){t._readyState=ge.CLOSING;let i=new Error(r);Error.captureStackTrace(i,ot),e.setHeader?(e[Fx]=!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 Sd(t,e,r){if(e){let i=BE(e)?e.size:KE(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Jt[t.readyState]})`);process.nextTick(r,i)}}function ZE(t,e){let r=this[qe];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[qe]!==void 0&&(r._socket.removeListener("data",No),process.nextTick(qx,r._socket),t===1005?r.close():r.close(t,e))}function JE(){let t=this[qe];t.isPaused||t._socket.resume()}function XE(t){let e=this[qe];e._socket[qe]!==void 0&&(e._socket.removeListener("data",No),process.nextTick(qx,e._socket),e.close(t[qE])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Mx(){this[qe].emitClose()}function QE(t,e){this[qe].emit("message",t,e)}function ev(t){let e=this[qe];e._autoPong&&e.pong(t,!this._isServer,zx),e.emit("ping",t)}function tv(t){this[qe].emit("pong",t)}function qx(t){t.resume()}function nv(t){let e=this[qe];e.readyState!==ge.CLOSED&&(e.readyState===ge.OPEN&&(e._readyState=ge.CLOSING,Gx(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Gx(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Hx(){let t=this[qe];if(this.removeListener("close",Hx),this.removeListener("data",No),this.removeListener("end",jx),t._readyState=ge.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[qe]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Mx),t._receiver.on("finish",Mx))}function No(t){this[qe]._receiver.write(t)||this.pause()}function jx(){let t=this[qe];t._readyState=ge.CLOSING,t._receiver.end(),this.end()}function Wx(){let t=this[qe];this.removeListener("error",Wx),this.on("error",zx),t&&(t._readyState=ge.CLOSING,this.destroy())}});var Zx=ae((VC,Yx)=>{"use strict";var $C=Mo(),{Duplex:rv}=le("stream");function $x(t){t.emit("close")}function iv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Vx(t){this.removeListener("error",Vx),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,u){let f=!u&&i._readableState.objectMode?c.toString():c;i.push(f)||t.pause()}),t.once("error",function(c){i.destroyed||(r=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick($x,i);return}let u=!1;t.once("error",function(x){u=!0,c(x)}),t.once("close",function(){u||c(o),process.nextTick($x,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,u){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,u)});return}t.send(o,u)},i.on("end",iv),i.on("error",Vx),i}Yx.exports=sv});var Ad=ae((YC,Jx)=>{"use strict";var{tokenChars:ov}=zr();function av(t){let e=new Set,r=-1,i=-1,o=0;for(o;o<t.length;o++){let u=t.charCodeAt(o);if(i===-1&&ov[u]===1)r===-1&&(r=o);else if(o!==0&&(u===32||u===9))i===-1&&r!==-1&&(i=o);else if(u===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let f=t.slice(r,i);if(e.has(f))throw new SyntaxError(`The "${f}" subprotocol is duplicated`);e.add(f),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(r,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}Jx.exports={parse:av}});var ih=ae((JC,rh)=>{"use strict";var cv=le("events"),Bo=le("http"),{Duplex:ZC}=le("stream"),{createHash:dv}=le("crypto"),Xx=Po(),Yn=Br(),uv=Ad(),lv=Mo(),{CLOSE_TIMEOUT:fv,GUID:xv,kWebSocket:hv}=Vt(),pv=/^[+/0-9A-Za-z]{22}==$/,Qx=0,eh=1,nh=2,Id=class extends cv{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:1024*1024,maxFragments:128*1024,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:lv,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=Bo.createServer((i,o)=>{let c=Bo.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=gv(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(o,c,u)=>{this.handleUpgrade(o,c,u,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Qx}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===nh){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Yi,this);return}if(e&&this.once("close",e),this._state!==eh)if(this._state=eh,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(Yi,this):process.nextTick(Yi,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{Yi(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",th);let c=e.headers["sec-websocket-key"],u=e.headers.upgrade,f=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Zn(this,e,r,405,"Invalid HTTP method");return}if(u===void 0||u.toLowerCase()!=="websocket"){Zn(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!pv.test(c)){Zn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(f!==13&&f!==8){Zn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Zi(r,400);return}let x=e.headers["sec-websocket-protocol"],p=new Set;if(x!==void 0)try{p=uv.parse(x)}catch{Zn(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let m=e.headers["sec-websocket-extensions"],_={};if(this.options.perMessageDeflate&&m!==void 0){let S=new Yn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let y=Xx.parse(m);y[Yn.extensionName]&&(S.accept(y[Yn.extensionName]),_[Yn.extensionName]=S)}catch{Zn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let S={origin:e.headers[`${f===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(S,(y,v,A,I)=>{if(!y)return Zi(r,v||401,A,I);this.completeUpgrade(_,c,p,e,r,i,o)});return}if(!this.options.verifyClient(S))return Zi(r,401)}this.completeUpgrade(_,c,p,e,r,i,o)}completeUpgrade(e,r,i,o,c,u,f){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>Qx)return Zi(c,503);let p=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${dv("sha1").update(r+xv).digest("base64")}`],m=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: ${_}`),m._protocol=_)}if(e[Yn.extensionName]){let _=e[Yn.extensionName].params,S=Xx.format({[Yn.extensionName]:[_]});p.push(`Sec-WebSocket-Extensions: ${S}`),m._extensions=e}this.emit("headers",p,o),c.write(p.concat(`\r
10
+ `),this.stream=void 0;return}this.currentDate!==void 0&&rs(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 xg,mkdirSync as hg}from"node:fs";import{join as pg}from"node:path";function fl(t){let e=t.retentionDays??wg,r=t.clock??(()=>Tn(new Date));ss={bridgeSink:new Jr(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new Jr(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();rs(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])rs(t.agentLogsDir(o),"agent",i,e)}function _g(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function xl(t){ba=t}function hl(t){return nr[ba]<=nr[t]}function pl(t,e){let r=nr[t];return r===void 0?!0:r>=nr[e]}function os(t){ul={...t}}function gl(t){let e=(f,x=2)=>String(f).padStart(x,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),l=e(o%60);return`${Tn(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${l}`}function St(t,e,r,i,o){try{let c=`${JSON.stringify({ts:gl(new Date),level:e,module:r,msg:i,...o})}
11
+ `;hg(t,{recursive:!0}),xg(pg(t,tr("bridge",Tn(new Date))),c)}catch{}}function yg(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function is(t,e,r,i,o){if(nr[t]<nr[ba])return;let c=`${JSON.stringify({ts:gl(new Date),level:t,module:e,msg:r,...ul,...i})}
12
+ `;if(ss){let l=yg(o,i),f=l?_g(ss,l):ss.bridgeSink;try{f.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?mg.write(c):gg.write(c)}function q(t,e){return{debug:(r,i)=>is("debug",t,r,i,e),info:(r,i)=>is("info",t,r,i,e),warn:(r,i)=>is("warn",t,r,i,e),error:(r,i)=>is("error",t,r,i,e),child:r=>q(`${t}.${r}`,e),forAgent:r=>q(t,r)}}var nr,ba,gg,mg,ul,wg,ss,ne=Ze(()=>{"use strict";er();Ea();nr={debug:10,info:20,warn:30,error:40},ba=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),gg=process.stdout,mg=process.stderr,ul={},wg=We("COZE_BRIDGE_LOG_RETENTION_DAYS",30),ss=null});var k,Ke=Ze(()=>{"use strict";k=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 yl={};_a(yl,{ACP_WRAPPER_NPM_PACKAGES:()=>Zr,_resetAcpInstallerForTests:()=>Ag,_setBinaryPathCacheForTests:()=>Cg,buildAcpSpawn:()=>Xr,ensureAcpInstalled:()=>rr,getAcpBinaryPath:()=>as,pickWhichLine:()=>Ia,probeAcpVersion:()=>Ig,resolveAcpCommand:()=>_l});import{readFileSync as ml}from"node:fs";import{createRequire as Eg}from"node:module";import{dirname as bg,resolve as vg}from"node:path";function Ia(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 Sg(t){let e=wl.resolve(`${t.npmPackage}/package.json`),r=bg(e),i=JSON.parse(ml(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 vg(r,o)}async function rr(t,e){let r=Sa[t];if(!r)throw new k("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=Yr.get(t);if(i)return i;try{let o=Sg(r);return Yr.set(t,o),va.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw va.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 k("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 Ig(t){let e=Sa[t];if(e)try{let r=wl.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(ml(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){va.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function as(t){return Yr.get(t)}function _l(t,e){if(e)return e;let r=as(t);if(!r)throw new k("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return r}function Xr(t,e,r){if(e)return{command:e,args:[...r]};let i=_l(t);return{command:process.execPath,args:[i,...r]}}function Ag(){Yr.clear()}function Cg(t,e){Yr.set(t,e)}var va,Sa,Zr,wl,Yr,rn=Ze(()=>{"use strict";Ke();ne();va=q("agents.acp-installer"),Sa={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},Zr=Object.values(Sa).filter(t=>t!==void 0).map(t=>t.npmPackage),wl=Eg(import.meta.url),Yr=new Map});import{chmod as kg,mkdir as Rg,readFile as Dg,rename as vl,writeFile as Sl}from"node:fs/promises";import{dirname as Pg}from"node:path";async function ir(t){try{let e=await Dg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function sr(t,e,r){await Rg(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 Sl(o,i,{encoding:"utf8",mode:r.mode}):await Sl(o,i,"utf8"),await vl(o,t),r?.mode!==void 0&&await kg(t,r.mode)}catch(c){await vl(o,o).catch(()=>{});let{rm:l}=await import("node:fs/promises");throw await l(o,{force:!0}).catch(()=>{}),c}}var Qr=Ze(()=>{"use strict"});import{promises as Il,readdirSync as Og}from"node:fs";import{homedir as Lg}from"node:os";import{sep as Ng,join as Ce,resolve as Al}from"node:path";function Q(t){let e=t??Lg(),r=Ce(e,".coze"),i=Ce(r,"bridge"),o=Ce(i,"lib"),c=Ce(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Ce(o,"index.js"),binDir:Ce(i,"bin"),pidFile:Ce(i,"bridge.pid"),portFile:Ce(i,"bridge.port"),tokenFile:Ce(i,"bridge.token"),patTokenFile:Ce(i,"pat-token"),agentEnvFile:Ce(i,"agent-env.json"),logFile:Ce(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Ce(c,"daemon-stdio.log"),installLock:Ce(i,"install.lock"),configFile:Ce(i,"config.json"),agentsRoot:Ce(r,"agents")}}function Xe(t,e=Q()){let r=Ce(e.agentsRoot,t);return{root:r,config:Ce(r,"config.json"),workspace:Ce(r,"workspace"),logs:Ce(r,"logs")}}function cs(t=Q()){try{return Og(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function ei(t,e){let r=await Il.realpath(Al(t)).catch(()=>null);if(!r)return!1;let i=await Il.realpath(Al(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+Ng)}var Pe=Ze(()=>{"use strict"});var us={};_a(us,{AGENT_CONFIG_FILE_MODE:()=>ds,enforceAgentConfigMode:()=>zg,loadAgentConfig:()=>Ne,persistAgentSessions:()=>ti,persistAgentSkills:()=>ls,saveAgentConfig:()=>Qe});import{chmod as Mg,stat as Bg}from"node:fs/promises";function Ne(t,e){return ir(Xe(t,e).config)}function Qe(t,e){return sr(Xe(t.agentId,e).config,t,{mode:ds})}async function zg(t,e){if(process.platform==="win32")return;let r=Xe(t,e).config;try{let i=await Bg(r);if(!i.isFile())return;let o=i.mode&511;o!==ds&&(await Mg(r,ds),Cl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Cl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function ti(t,e,r){let i=await Ne(t,r);i&&(i.sessions=Object.fromEntries(e),await Qe(i,r))}async function ls(t,e,r){let i=await Ne(t,r);i&&(i.skills=e,await Qe(i,r))}var Cl,ds,sn=Ze(()=>{"use strict";Qr();ne();Pe();Cl=q("agent-config"),ds=384});var Ta=ae((k1,Rl)=>{Rl.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 xs=ae(Pl=>{var Dl={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 Hg(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(Dl))Pl[t]=Hg(Dl[t])});var Bl=ae((D1,Ml)=>{var Wg=ue("fs"),Oe=ue("path"),Ol=Ta(),Kg=xs(),$g=typeof process=="object"&&process.platform==="win32",Ll=t=>typeof t=="object"&&t!==null,Nl=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function Ee(t){this.sep=Oe.sep,this.fs=Wg,Ll(t)&&Ll(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Ml.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(f){if(f.message&&f.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw f}if(l&&l.isFile())throw Kg.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=Oe.dirname(t);o.fs.existsSync(l)||o.makeDir(l);var f;try{f=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),f=o.fs.openSync(t,"w",438)}if(f)try{o.fs.writeSync(f,e,0,e.length,0)}finally{o.fs.closeSync(f)}return o.fs.chmodSync(t,i||438),!0};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(f,x){if(l&&x.isDirectory())return o(!1);var p=Oe.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(y,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)})})})})}):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)})})})})})};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(f){let x=Oe.join(i,f),p=e.fs.statSync(x);(!o||o.test(x))&&l.push(Oe.normalize(x)+(p.isDirectory()?e.sep:"")),p.isDirectory()&&c&&(l=l.concat(r(x,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(f){f=Oe.join(t,f),r.fs.stat(f,function(x,p){if(x)return e(x);p&&(i.push(Oe.normalize(f)+(p.isDirectory()?r.sep:"")),p.isDirectory()?r.findFilesAsync(f,function(w,_){if(w)return e(w);i=i.concat(_),--l||e(null,i)}):--l||e(null,i))})})})};Ee.prototype.getAttributes=function(){};Ee.prototype.setAttributes=function(){};Ee.crc32update=function(t,e){return Nl[(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 Ol.STORED:return"STORED ("+t+")";case Ol.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Ee.canonical=function(t){if(!t)return"";let e=Oe.posix.normalize("/"+t.split("\\").join("/"));return Oe.join(".",e)};Ee.zipnamefix=function(t){if(!t)return"";let e=Oe.posix.normalize("/"+t.split("\\").join("/"));return Oe.posix.join(".",e)};Ee.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let r=t.length>>>0;for(let i=r-1;i>=0;i--)if(e(t[i],i,t))return t[i]};Ee.sanitize=function(t,e){t=Oe.resolve(Oe.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Oe.normalize(Oe.join(t,r.slice(i,o).join(Oe.sep)));if(c.indexOf(t)===0)return c}return Oe.normalize(Oe.join(t,Oe.basename(e)))};Ee.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};Ee.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};Ee.fromDOS2Date=function(t){return new Date((t>>25&127)+1980,Math.max((t>>21&15)-1,0),Math.max(t>>16&31,1),t>>11&31,t>>5&63,(t&31)<<1)};Ee.fromDate2DOS=function(t){let e=0,r=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),r=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|r};Ee.isWin=$g;Ee.crcTable=Nl});var Fl=ae((P1,zl)=>{var Vg=ue("path");zl.exports=function(t,{fs:e}){var r=t||"",i=c(),o=null;function c(){return{directory:!1,readonly:!1,hidden:!1,executable:!1,mtime:0,atime:0}}return r&&e.existsSync(r)?(o=e.statSync(r),i.directory=o.isDirectory(),i.mtime=o.mtime,i.atime=o.atime,i.executable=(73&o.mode)!==0,i.readonly=(128&o.mode)===0,i.hidden=Vg.basename(r)[0]==="."):console.warn("Invalid path: "+r),{get directory(){return i.directory},get readOnly(){return i.readonly},get hidden(){return i.hidden},get mtime(){return i.mtime},get atime(){return i.atime},get executable(){return i.executable},decodeAttributes:function(){},encodeAttributes:function(){},toJSON:function(){return{path:r,isDirectory:i.directory,isReadOnly:i.readonly,isHidden:i.hidden,isExecutable:i.executable,mTime:i.mtime,aTime:i.atime}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Gl=ae((O1,Ul)=>{Ul.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var cr=ae((L1,ar)=>{ar.exports=Bl();ar.exports.Constants=Ta();ar.exports.Errors=xs();ar.exports.FileAttr=Fl();ar.exports.decoder=Gl()});var jl=ae((N1,ql)=>{var on=cr(),G=on.Constants;ql.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,l=0,f=0,x=0,p=0,w=0,_=0,S=0,y=0,v=0;t|=on.isWin?2560:768,r|=G.FLG_EFS;let I={extraLen:0},C=E=>Math.max(0,E)>>>0,R=E=>Math.max(0,E)&65535,O=E=>Math.max(0,E)&255;return o=on.fromDate2DOS(new Date),{get made(){return t},set made(E){t=E},get version(){return e},set version(E){e=E},get flags(){return r},set flags(E){r=E},get flags_efs(){return(r&G.FLG_EFS)>0},set flags_efs(E){E?r|=G.FLG_EFS:r&=~G.FLG_EFS},get flags_desc(){return(r&G.FLG_DESC)>0},set flags_desc(E){E?r|=G.FLG_DESC:r&=~G.FLG_DESC},get method(){return i},set method(E){switch(E){case G.STORED:this.version=10;case G.DEFLATED:default:this.version=20}i=E},get time(){return on.fromDOS2Date(this.timeval)},set time(E){E=new Date(E),this.timeval=on.fromDate2DOS(E)},get timeval(){return o},set timeval(E){o=C(E)},get timeHighByte(){return O(o>>>8)},get crc(){return c},set crc(E){c=C(E)},get compressedSize(){return l},set compressedSize(E){l=C(E)},get size(){return f},set size(E){f=C(E)},get fileNameLength(){return x},set fileNameLength(E){x=E},get extraLength(){return p},set extraLength(E){p=E},get extraLocalLength(){return I.extraLen},set extraLocalLength(E){I.extraLen=E},get commentLength(){return w},set commentLength(E){w=E},get diskNumStart(){return _},set diskNumStart(E){_=C(E)},get inAttr(){return S},set inAttr(E){S=C(E)},get attr(){return y},set attr(E){y=C(E)},get fileAttr(){return(y||0)>>16&4095},get offset(){return v},set offset(E){v=C(E)},get encrypted(){return(r&G.FLG_ENC)===G.FLG_ENC},get centralHeaderSize(){return G.CENHDR+x+p+w},get realDataOffset(){return v+G.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(E){var D=E.slice(v,v+G.LOCHDR);if(D.readUInt32LE(0)!==G.LOCSIG)throw on.Errors.INVALID_LOC();I.version=D.readUInt16LE(G.LOCVER),I.flags=D.readUInt16LE(G.LOCFLG),I.flags_desc=(I.flags&G.FLG_DESC)>0,I.method=D.readUInt16LE(G.LOCHOW),I.time=D.readUInt32LE(G.LOCTIM),I.crc=D.readUInt32LE(G.LOCCRC),I.compressedSize=D.readUInt32LE(G.LOCSIZ),I.size=D.readUInt32LE(G.LOCLEN),I.fnameLen=D.readUInt16LE(G.LOCNAM),I.extraLen=D.readUInt16LE(G.LOCEXT);let L=v+G.LOCHDR+I.fnameLen,F=L+I.extraLen;return E.slice(L,F)},loadFromBinary:function(E){if(E.length!==G.CENHDR||E.readUInt32LE(0)!==G.CENSIG)throw on.Errors.INVALID_CEN();t=E.readUInt16LE(G.CENVEM),e=E.readUInt16LE(G.CENVER),r=E.readUInt16LE(G.CENFLG),i=E.readUInt16LE(G.CENHOW),o=E.readUInt32LE(G.CENTIM),c=E.readUInt32LE(G.CENCRC),l=E.readUInt32LE(G.CENSIZ),f=E.readUInt32LE(G.CENLEN),x=E.readUInt16LE(G.CENNAM),p=E.readUInt16LE(G.CENEXT),w=E.readUInt16LE(G.CENCOM),_=E.readUInt16LE(G.CENDSK),S=E.readUInt16LE(G.CENATT),y=E.readUInt32LE(G.CENATX),v=E.readUInt32LE(G.CENOFF)},localHeaderToBinary:function(){var E=Buffer.alloc(G.LOCHDR);return E.writeUInt32LE(G.LOCSIG,0),E.writeUInt16LE(e,G.LOCVER),E.writeUInt16LE(r,G.LOCFLG),E.writeUInt16LE(i,G.LOCHOW),E.writeUInt32LE(o,G.LOCTIM),E.writeUInt32LE(c,G.LOCCRC),E.writeUInt32LE(l,G.LOCSIZ),E.writeUInt32LE(f,G.LOCLEN),E.writeUInt16LE(x,G.LOCNAM),E.writeUInt16LE(I.extraLen,G.LOCEXT),E},centralHeaderToBinary:function(){var E=Buffer.alloc(G.CENHDR+x+p+w);return E.writeUInt32LE(G.CENSIG,0),E.writeUInt16LE(t,G.CENVEM),E.writeUInt16LE(e,G.CENVER),E.writeUInt16LE(r,G.CENFLG),E.writeUInt16LE(i,G.CENHOW),E.writeUInt32LE(o,G.CENTIM),E.writeUInt32LE(c,G.CENCRC),E.writeUInt32LE(l,G.CENSIZ),E.writeUInt32LE(f,G.CENLEN),E.writeUInt16LE(x,G.CENNAM),E.writeUInt16LE(p,G.CENEXT),E.writeUInt16LE(w,G.CENCOM),E.writeUInt16LE(_,G.CENDSK),E.writeUInt16LE(S,G.CENATT),E.writeUInt32LE(y,G.CENATX),E.writeUInt32LE(v,G.CENOFF),E},toJSON:function(){let E=function(D){return D+" bytes"};return{made:t,version:e,flags:r,method:on.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:E(l),size:E(f),fileNameLength:E(x),extraLength:E(p),commentLength:E(w),diskNumStart:_,inAttr:S,attr:y,offset:v,centralHeaderSize:E(G.CENHDR+x+p+w)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Wl=ae((M1,Hl)=>{var dr=cr(),we=dr.Constants;Hl.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 we.ENDHDR+o},loadFromBinary:function(c){if((c.length!==we.ENDHDR||c.readUInt32LE(0)!==we.ENDSIG)&&(c.length<we.ZIP64HDR||c.readUInt32LE(0)!==we.ZIP64SIG))throw dr.Errors.INVALID_END();c.readUInt32LE(0)===we.ENDSIG?(t=c.readUInt16LE(we.ENDSUB),e=c.readUInt16LE(we.ENDTOT),r=c.readUInt32LE(we.ENDSIZ),i=c.readUInt32LE(we.ENDOFF),o=c.readUInt16LE(we.ENDCOM)):(t=dr.readBigUInt64LE(c,we.ZIP64SUB),e=dr.readBigUInt64LE(c,we.ZIP64TOT),r=dr.readBigUInt64LE(c,we.ZIP64SIZE),i=dr.readBigUInt64LE(c,we.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(we.ENDHDR+o);return c.writeUInt32LE(we.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,we.ENDSUB),c.writeUInt16LE(e,we.ENDTOT),c.writeUInt32LE(r,we.ENDSIZ),c.writeUInt32LE(i,we.ENDOFF),c.writeUInt16LE(o,we.ENDCOM),c.fill(" ",we.ENDHDR),c},toJSON:function(){let c=function(l,f){let x=l.toString(16).toUpperCase();for(;x.length<f;)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 Ra=ae(ka=>{ka.EntryHeader=jl();ka.MainHeader=Wl()});var $l=ae((z1,Kl)=>{Kl.exports=function(t){var e=ue("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],l=0;o.on("data",function(f){c.push(f),l+=f.length}),o.on("end",function(){var f=Buffer.alloc(l),x=0;f.fill(0);for(var p=0;p<c.length;p++){var w=c[p];w.copy(f,x),x+=w.length}i&&i(f)}),o.end(t)}}}});var Jl=ae((F1,Vl)=>{var Jg=+(process.versions?process.versions.node:"").split(".")[0]||0;Vl.exports=function(t,e){var r=ue("zlib");let i=Jg>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),l=[],f=0;c.on("data",function(x){l.push(x),f+=x.length}),c.on("end",function(){var x=Buffer.alloc(f),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 eu=ae((U1,Ql)=>{"use strict";var{randomFillSync:Yl}=ue("crypto"),Yg=xs(),Zg=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}),Xl=(t,e)=>Math.imul(t,e)>>>0,Zl=(t,e)=>Zg[(t^e)&255]^t>>>8,ni=()=>typeof Yl=="function"?Yl(Buffer.alloc(12)):ni.node();ni.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 hs={genSalt:ni};function ps(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])}ps.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Zl(e[0],t),e[1]+=e[0]&255,e[1]=Xl(e[1],134775813)+1,e[2]=Zl(e[2],e[1]>>>24),t};ps.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Xl(t,t^1)>>8&255};function Xg(t){let e=new ps(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 Qg(t){let e=new ps(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 em(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Xg(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Yg.WRONG_PASSWORD();return i(t.slice(12))}function tm(t){Buffer.isBuffer(t)&&t.length>=12?hs.genSalt=function(){return t.slice(0,12)}:t==="node"?hs.genSalt=ni.node:hs.genSalt=ni}function nm(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Qg(r),c=hs.genSalt();c[11]=e.crc>>>24&255,i&&(c[10]=e.crc>>>16&255);let l=Buffer.alloc(t.length+12);return o(c,l),o(t,l,12)}Ql.exports={decrypt:em,encrypt:nm,_salter:tm}});var tu=ae(gs=>{gs.Deflater=$l();gs.Inflater=Jl();gs.ZipCrypto=eu()});var Pa=ae((q1,nu)=>{var ce=cr(),rm=Ra(),be=ce.Constants,Da=tu();nu.exports=function(t,e){var r=new rm.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,l=null,f=Buffer.alloc(0),x=Buffer.alloc(0),p=!0;let w=t,_=typeof w.decoder=="object"?w.decoder:ce.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 y(E){if(!r.flags_desc&&!r.localHeader.flags_desc){if(ce.crc32(E)!==r.localHeader.crc)return!1}else{let D={},L=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(L)==be.LOCSIG||e.readUInt32LE(L)==be.CENSIG)throw ce.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(L)==be.EXTSIG)D.crc=e.readUInt32LE(L+be.EXTCRC),D.compressedSize=e.readUInt32LE(L+be.EXTSIZ),D.size=e.readUInt32LE(L+be.EXTLEN);else if(e.readUInt16LE(L+12)===19280)D.crc=e.readUInt32LE(L+be.EXTCRC-4),D.compressedSize=e.readUInt32LE(L+be.EXTSIZ-4),D.size=e.readUInt32LE(L+be.EXTLEN-4);else throw ce.Errors.DESCRIPTOR_UNKNOWN();if(D.compressedSize!==r.compressedSize||D.size!==r.size||D.crc!==r.crc)throw ce.Errors.DESCRIPTOR_FAULTY();if(ce.crc32(E)!==D.crc)return!1}return!0}function v(E,D,L){if(typeof D>"u"&&typeof E=="string"&&(L=E,E=void 0),c)return E&&D&&D(Buffer.alloc(0),ce.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var F=S();if(F.length===0)return E&&D&&D(F),F;if(r.encrypted){if(typeof L!="string"&&!Buffer.isBuffer(L))throw ce.Errors.INVALID_PASS_PARAM();F=Da.ZipCrypto.decrypt(F,r,L)}var z=Buffer.alloc(r.size);switch(r.method){case ce.Constants.STORED:if(F.copy(z),y(z))return E&&D&&D(z),z;throw E&&D&&D(z,ce.Errors.BAD_CRC()),ce.Errors.BAD_CRC();case ce.Constants.DEFLATED:var J=new Da.Inflater(F,r.size);if(E)J.inflateAsync(function(V){V.copy(V,0),D&&(y(V)?D(V):D(V,ce.Errors.BAD_CRC()))});else{if(J.inflate(z).copy(z,0),!y(z))throw ce.Errors.BAD_CRC(`"${_.decode(i)}"`);return z}break;default:throw E&&D&&D(Buffer.alloc(0),ce.Errors.UNKNOWN_METHOD()),ce.Errors.UNKNOWN_METHOD()}}function I(E,D){if((!l||!l.length)&&Buffer.isBuffer(e))return E&&D&&D(S()),S();if(l.length&&!c){var L;switch(r.method){case ce.Constants.STORED:return r.compressedSize=r.size,L=Buffer.alloc(l.length),l.copy(L),E&&D&&D(L),L;default:case ce.Constants.DEFLATED:var F=new Da.Deflater(l);if(E)F.deflateAsync(function(J){L=Buffer.alloc(J.length),r.compressedSize=J.length,J.copy(L),D&&D(L)});else{var z=F.deflate();return r.compressedSize=z.length,z}F=null;break}}else if(E&&D)D(Buffer.alloc(0));else return Buffer.alloc(0)}function C(E,D){return ce.readBigUInt64LE(E,D)}function R(E){try{for(var D=0,L,F,z;D+4<E.length;)L=E.readUInt16LE(D),D+=2,F=E.readUInt16LE(D),D+=2,z=E.slice(D,D+F),D+=F,be.ID_ZIP64===L&&O(z)}catch{throw ce.Errors.EXTRA_FIELD_PARSE_ERROR()}}function O(E){var D,L,F,z;E.length>=be.EF_ZIP64_SCOMP&&(D=C(E,be.EF_ZIP64_SUNCOMP),r.size===be.EF_ZIP64_OR_32&&(r.size=D)),E.length>=be.EF_ZIP64_RHO&&(L=C(E,be.EF_ZIP64_SCOMP),r.compressedSize===be.EF_ZIP64_OR_32&&(r.compressedSize=L)),E.length>=be.EF_ZIP64_DSN&&(F=C(E,be.EF_ZIP64_RHO),r.offset===be.EF_ZIP64_OR_32&&(r.offset=F)),E.length>=be.EF_ZIP64_DSN+4&&(z=E.readUInt32LE(be.EF_ZIP64_DSN),r.diskNumStart===be.EF_ZIP64_OR_16&&(r.diskNumStart=z))}return{get entryName(){return _.decode(i)},get rawEntryName(){return i},set entryName(E){i=ce.toBuffer(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 f},set extra(E){f=E,r.extraLength=E.length,R(E)},get comment(){return _.decode(o)},set comment(E){if(o=ce.toBuffer(E,_.encode),r.commentLength=o.length,o.length>65535)throw ce.Errors.COMMENT_TOO_LONG()},get name(){var E=_.decode(i);return c?E.substr(E.length-1).split("/").pop():E.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(E){I(!0,E)},setData:function(E){l=ce.toBuffer(E,ce.decoder.encode),!c&&l.length?(r.size=l.length,r.method=ce.Constants.DEFLATED,r.crc=ce.crc32(E),r.changed=!0):r.method=ce.Constants.STORED},getData:function(E){return r.changed?l:v(!1,null,E)},getDataAsync:function(E,D){r.changed?E(l):v(!0,E,D)},set attr(E){r.attr=E},get attr(){return r.attr},set header(E){r.loadFromBinary(E)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=f.length;var E=r.centralHeaderToBinary(),D=ce.Constants.CENHDR;return i.copy(E,D),D+=i.length,f.copy(E,D),D+=r.extraLength,o.copy(E,D),E},packLocalHeader:function(){let E=0;r.flags_efs=this.efs,r.extraLocalLength=x.length;let D=r.localHeaderToBinary(),L=Buffer.alloc(D.length+i.length+r.extraLocalLength);return D.copy(L,E),E+=D.length,i.copy(L,E),E+=i.length,x.copy(L,E),E+=x.length,L},toJSON:function(){let E=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:E(e),data:E(l)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var su=ae((j1,iu)=>{var ru=Pa(),im=Ra(),He=cr();iu.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new im.MainHeader,l=!1,f=null;let x=new Set,p=e,{noSort:w,decoder:_}=p;t?v(p.readEntries):l=!0;function S(){let C=new Set;for(let R of Object.keys(i)){let O=R.split("/");if(O.pop(),!!O.length)for(let E=0;E<O.length;E++){let D=O.slice(0,E+1).join("/")+"/";C.add(D)}}for(let R of C)if(!(R in i)){let O=new ru(p);O.entryName=R,O.attr=16,O.temporary=!0,r.push(O),i[O.entryName]=O,x.add(O)}}function y(){if(l=!0,i={},c.diskEntries>(t.length-c.offset)/He.Constants.CENHDR)throw He.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var C=c.offset,R=0;R<r.length;R++){var O=C,E=new ru(p,t);E.header=t.slice(O,O+=He.Constants.CENHDR),E.entryName=t.slice(O,O+=E.header.fileNameLength),E.header.extraLength&&(E.extra=t.slice(O,O+=E.header.extraLength)),E.header.commentLength&&(E.comment=t.slice(O,O+E.header.commentLength)),C+=E.header.centralHeaderSize,r[R]=E,i[E.entryName]=E}x.clear(),S()}function v(C){var R=t.length-He.Constants.ENDHDR,O=Math.max(0,R-65535),E=O,D=t.length,L=-1,F=0;for(typeof p.trailingSpace=="boolean"&&p.trailingSpace&&(O=0),R;R>=E;R--)if(t[R]===80){if(t.readUInt32LE(R)===He.Constants.ENDSIG){L=R,F=R,D=R+He.Constants.ENDHDR,E=R-He.Constants.END64HDR;continue}if(t.readUInt32LE(R)===He.Constants.END64SIG){E=O;continue}if(t.readUInt32LE(R)===He.Constants.ZIP64SIG){L=R,D=R+He.readBigUInt64LE(t,R+He.Constants.ZIP64SIZE)+He.Constants.ZIP64LEAD;break}}if(L==-1)throw He.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(L,D)),c.commentLength&&(o=t.slice(F+He.Constants.ENDHDR)),C&&y()}function I(){r.length>1&&!w&&r.sort((C,R)=>C.entryName.toLowerCase().localeCompare(R.entryName.toLowerCase()))}return{get entries(){return l||y(),r.filter(C=>!x.has(C))},get comment(){return _.decode(o)},set comment(C){o=He.toBuffer(C,_.encode),c.commentLength=o.length},getEntryCount:function(){return l?r.length:c.diskEntries},forEach:function(C){this.entries.forEach(C)},getEntry:function(C){return l||y(),i[C]||null},setEntry:function(C){l||y(),r.push(C),i[C.entryName]=C,c.totalEntries=r.length},deleteFile:function(C,R=!0){l||y();let O=i[C];this.getEntryChildren(O,R).map(D=>D.entryName).forEach(this.deleteEntry)},deleteEntry:function(C){l||y();let R=i[C],O=r.indexOf(R);O>=0&&(r.splice(O,1),delete i[C],c.totalEntries=r.length)},getEntryChildren:function(C,R=!0){if(l||y(),typeof C=="object")if(C.isDirectory&&R){let O=[],E=C.entryName;for(let D of r)D.entryName.startsWith(E)&&O.push(D);return O}else return[C];return[]},getChildCount:function(C){if(C&&C.isDirectory){let R=this.getEntryChildren(C);return R.includes(C)?R.length-1:R.length}return 0},compressToBuffer:function(){l||y(),I();let C=[],R=[],O=0,E=0;c.size=0,c.offset=0;let D=0;for(let z of this.entries){let J=z.getCompressedData();z.header.offset=E;let V=z.packLocalHeader(),te=V.length+J.length;E+=te,C.push(V),C.push(J);let Z=z.packCentralHeader();R.push(Z),c.size+=Z.length,O+=te+Z.length,D++}O+=c.mainHeaderSize,c.offset=E,c.totalEntries=D,E=0;let L=Buffer.alloc(O);for(let z of C)z.copy(L,E),E+=z.length;for(let z of R)z.copy(L,E),E+=z.length;let F=c.toBinary();return o&&o.copy(F,He.Constants.ENDHDR),F.copy(L,E),t=L,l=!1,L},toAsyncBuffer:function(C,R,O,E){try{l||y(),I();let D=[],L=[],F=0,z=0,J=0;c.size=0,c.offset=0;let V=function(te){if(te.length>0){let Z=te.shift(),ie=Z.entryName+Z.extra.toString();O&&O(ie),Z.getCompressedDataAsync(function(oe){E&&E(ie),Z.header.offset=z;let N=Z.packLocalHeader(),j=N.length+oe.length;z+=j,D.push(N),D.push(oe);let $=Z.packCentralHeader();L.push($),c.size+=$.length,F+=j+$.length,J++,V(te)})}else{F+=c.mainHeaderSize,c.offset=z,c.totalEntries=J,z=0;let Z=Buffer.alloc(F);D.forEach(function(oe){oe.copy(Z,z),z+=oe.length}),L.forEach(function(oe){oe.copy(Z,z),z+=oe.length});let ie=c.toBinary();o&&o.copy(ie,He.Constants.ENDHDR),ie.copy(Z,z),t=Z,l=!1,C(Z)}};V(Array.from(this.entries))}catch(D){R(D)}}}}});var cu=ae((H1,au)=>{var ye=cr(),_e=ue("path"),sm=Pa(),om=su(),kn=(...t)=>ye.findLast(t,e=>typeof e=="boolean"),ou=(...t)=>ye.findLast(t,e=>typeof e=="string"),am=(...t)=>ye.findLast(t,e=>typeof e=="function"),cm={noSort:!1,readEntries:!1,method:ye.Constants.NONE,fs:null};au.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),cm);t&&typeof t=="object"&&(t instanceof Uint8Array||(Object.assign(i,t),t=i.input?i.input:void 0,i.input&&delete i.input),Buffer.isBuffer(t)&&(r=t,i.method=ye.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new ye(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=ye.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=ye.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw ye.Errors.INVALID_FILENAME();let c=new om(r,i),{canonical:l,sanitize:f,zipnamefix:x}=ye;function p(y){if(y&&c){var v;if(typeof y=="string"&&(v=c.getEntry(_e.posix.normalize(y))),typeof y=="object"&&typeof y.entryName<"u"&&typeof y.header<"u"&&(v=c.getEntry(y.entryName)),v)return v}return null}function w(y){let{join:v,normalize:I,sep:C}=_e.posix;return v(_e.isAbsolute(y)?"/":".",I(C+y.split("\\").join(C)+C))}function _(y){return y instanceof RegExp?(function(v){return function(I){return v.test(I)}})(y):typeof y!="function"?()=>!0:y}let S=(y,v)=>{let I=v.slice(-1);return I=I===o.sep?o.sep:"",_e.relative(y,v)+I};return{readFile:function(y,v){var I=p(y);return I&&I.getData(v)||null},childCount:function(y){let v=p(y);if(v)return c.getChildCount(v)},readFileAsync:function(y,v){var I=p(y);I?I.getDataAsync(v):v(null,"getEntry failed for:"+y)},readAsText:function(y,v){var I=p(y);if(I){var C=I.getData();if(C&&C.length)return C.toString(v||"utf8")}return""},readAsTextAsync:function(y,v,I){var C=p(y);C?C.getDataAsync(function(R,O){if(O){v(R,O);return}R&&R.length?v(R.toString(I||"utf8")):v("")}):v("")},deleteFile:function(y,v=!0){var I=p(y);I&&c.deleteFile(I.entryName,v)},deleteEntry:function(y){var v=p(y);v&&c.deleteEntry(v.entryName)},addZipComment:function(y){c.comment=y},getZipComment:function(){return c.comment||""},addZipEntryComment:function(y,v){var I=p(y);I&&(I.comment=v)},getZipEntryComment:function(y){var v=p(y);return v&&v.comment||""},updateFile:function(y,v){var I=p(y);I&&I.setData(v)},addLocalFile:function(y,v,I,C){if(o.fs.existsSync(y)){v=v?w(v):"";let R=_e.win32.basename(_e.win32.normalize(y));v+=I||R;let O=o.fs.statSync(y),E=O.isFile()?o.fs.readFileSync(y):Buffer.alloc(0);O.isDirectory()&&(v+=o.sep),this.addFile(v,E,C,O)}else throw ye.Errors.FILE_NOT_FOUND(y)},addLocalFileAsync:function(y,v){y=typeof y=="object"?y:{localPath:y};let I=_e.resolve(y.localPath),{comment:C}=y,{zipPath:R,zipName:O}=y,E=this;o.fs.stat(I,function(D,L){if(D)return v(D,!1);R=R?w(R):"";let F=_e.win32.basename(_e.win32.normalize(I));if(R+=O||F,L.isFile())o.fs.readFile(I,function(z,J){return z?v(z,!1):(E.addFile(R,J,C,L),setImmediate(v,void 0,!0))});else if(L.isDirectory())return R+=o.sep,E.addFile(R,Buffer.alloc(0),C,L),setImmediate(v,void 0,!0)})},addLocalFolder:function(y,v,I){if(I=_(I),v=v?w(v):"",y=_e.normalize(y),o.fs.existsSync(y)){let C=o.findFiles(y),R=this;if(C.length)for(let O of C){let E=_e.join(v,S(y,O));I(E)&&R.addLocalFile(O,_e.dirname(E))}}else throw ye.Errors.FILE_NOT_FOUND(y)},addLocalFolderAsync:function(y,v,I,C){C=_(C),I=I?w(I):"",y=_e.normalize(y);var R=this;o.fs.open(y,"r",function(O){if(O&&O.code==="ENOENT")v(void 0,ye.Errors.FILE_NOT_FOUND(y));else if(O)v(void 0,O);else{var E=o.findFiles(y),D=-1,L=function(){if(D+=1,D<E.length){var F=E[D],z=S(y,F).split("\\").join("/");z=z.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),C(z)?o.fs.stat(F,function(J,V){J&&v(void 0,J),V.isFile()?o.fs.readFile(F,function(te,Z){te?v(void 0,te):(R.addFile(I+z,Z,"",V),L())}):(R.addFile(I+z+"/",Buffer.alloc(0),"",V),L())}):process.nextTick(()=>{L()})}else v(!0,void 0)};L()}})},addLocalFolderAsync2:function(y,v){let I=this;y=typeof y=="object"?y:{localPath:y},localPath=_e.resolve(w(y.localPath));let{zipPath:C,filter:R,namefix:O}=y;R instanceof RegExp?R=(function(L){return function(F){return L.test(F)}})(R):typeof R!="function"&&(R=function(){return!0}),C=C?w(C):"",O=="latin1"&&(O=L=>L.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof O!="function"&&(O=L=>L);let E=L=>_e.join(C,O(S(localPath,L))),D=L=>_e.win32.basename(_e.win32.normalize(O(L)));o.fs.open(localPath,"r",function(L){L&&L.code==="ENOENT"?v(void 0,ye.Errors.FILE_NOT_FOUND(localPath)):L?v(void 0,L):o.findFilesAsync(localPath,function(F,z){if(F)return v(F);z=z.filter(J=>R(E(J))),z.length||v(void 0,!1),setImmediate(z.reverse().reduce(function(J,V){return function(te,Z){if(te||Z===!1)return setImmediate(J,te,!1);I.addLocalFileAsync({localPath:V,zipPath:_e.dirname(E(V)),zipName:D(V)},J)}},v))})})},addLocalFolderPromise:function(y,v){return new Promise((I,C)=>{this.addLocalFolderAsync2(Object.assign({localPath:y},v),(R,O)=>{R&&C(R),O&&I(this)})})},addFile:function(y,v,I,C){y=x(y);let R=p(y),O=R!=null;O||(R=new sm(i),R.entryName=y),R.comment=I||"";let E=typeof C=="object"&&C instanceof o.fs.Stats;E&&(R.header.time=C.mtime);var D=R.isDirectory?16:0;let L=R.isDirectory?16384:32768;return E?L|=4095&C.mode:typeof C=="number"?L|=4095&C:L|=R.isDirectory?493:420,D=(D|L<<16)>>>0,R.attr=D,R.setData(v),O||c.setEntry(R),R},getEntries:function(y){return c.password=y,c?c.entries:[]},getEntry:function(y){return p(y)},getEntryCount:function(){return c.getEntryCount()},forEach:function(y){return c.forEach(y)},extractEntryTo:function(y,v,I,C,R,O){C=kn(!1,C),R=kn(!1,R),I=kn(!0,I),O=ou(R,O);var E=p(y);if(!E)throw ye.Errors.NO_ENTRY();var D=l(E.entryName),L=f(v,O&&!E.isDirectory?O:I?D:_e.basename(D));if(E.isDirectory){var F=c.getEntryChildren(E);return F.forEach(function(V){if(V.isDirectory)return;var te=V.getData();if(!te)throw ye.Errors.CANT_EXTRACT_FILE();var Z=l(V.entryName),ie=f(v,I?Z:_e.basename(Z));let oe=R?V.header.fileAttr:void 0;o.writeFileTo(ie,te,C,oe)}),!0}var z=E.getData(c.password);if(!z)throw ye.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(L)&&!C)throw ye.Errors.CANT_OVERRIDE();let J=R?y.header.fileAttr:void 0;return o.writeFileTo(L,z,C,J),!0},test:function(y){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var I=c.entries[v].getData(y);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(y,v,I,C){if(I=kn(!1,I),C=ou(I,C),v=kn(!1,v),!c)throw ye.Errors.NO_ZIP();c.entries.forEach(function(R){var O=f(y,l(R.entryName));if(R.isDirectory){o.makeDir(O);return}var E=R.getData(C);if(!E)throw ye.Errors.CANT_EXTRACT_FILE();let D=I?R.header.fileAttr:void 0;o.writeFileTo(O,E,v,D);try{o.fs.utimesSync(O,R.header.time,R.header.time)}catch{throw ye.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(y,v,I,C){if(C=am(v,I,C),I=kn(!1,I),v=kn(!1,v),!C)return new Promise((L,F)=>{this.extractAllToAsync(y,v,I,function(z){z?F(z):L(this)})});if(!c){C(ye.Errors.NO_ZIP());return}y=_e.resolve(y);let R=L=>f(y,_e.normalize(l(L.entryName))),O=(L,F)=>new Error(L+': "'+F+'"'),E=[],D=[];c.entries.forEach(L=>{L.isDirectory?E.push(L):D.push(L)});for(let L of E){let F=R(L),z=I?L.header.fileAttr:void 0;try{o.makeDir(F),z&&o.fs.chmodSync(F,z),o.fs.utimesSync(F,L.header.time,L.header.time)}catch{C(O("Unable to create folder",F))}}D.reverse().reduce(function(L,F){return function(z){if(z)L(z);else{let J=_e.normalize(l(F.entryName)),V=f(y,J);F.getDataAsync(function(te,Z){if(Z)L(Z);else if(!te)L(ye.Errors.CANT_EXTRACT_FILE());else{let ie=I?F.header.fileAttr:void 0;o.writeFileToAsync(V,te,v,ie,function(oe){oe||L(O("Unable to write file",V)),o.fs.utimes(V,F.header.time,F.header.time,function(N){N?L(O("Unable to set times",V)):L()})})}})}}},C)()},writeZip:function(y,v){if(arguments.length===1&&typeof y=="function"&&(v=y,y=""),!y&&i.filename&&(y=i.filename),!!y){var I=c.compressToBuffer();if(I){var C=o.writeFileTo(y,I,!0);typeof v=="function"&&v(C?null:new Error("failed"),"")}}},writeZipPromise:function(y,v){let{overwrite:I,perm:C}=Object.assign({overwrite:!0},v);return new Promise((R,O)=>{!y&&i.filename&&(y=i.filename),y||O("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(E=>{let D=L=>L?R(L):O("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(y,E,I,C,D)},O)})},toBufferPromise:function(){return new Promise((y,v)=>{c.toAsyncBuffer(y,v)})},toBuffer:function(y,v,I,C){return typeof y=="function"?(c.toAsyncBuffer(y,v,I,C),null):c.compressToBuffer()}}}});import{execFile as h_,spawn as p_,spawnSync as cA}from"node:child_process";import{promisify as g_}from"node:util";function w_(t){if(process.platform!=="win32")return!1;if(Tf.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(Tf,"").toLowerCase();return m_.has(r)}function kf(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return w_(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function nt(t,e=[],r={}){return p_(t,e,kf(t,r))}function Rf(t,e=[],r={}){return __(t,e,kf(t,r))}var m_,Tf,__,Kt=Ze(()=>{"use strict";m_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Tf=/\.(cmd|bat|ps1)$/i;__=g_(h_)});var Vt=ae((Fk,sx)=>{"use strict";var rx=["nodebuffer","arraybuffer","fragments"],ix=typeof Blob<"u";ix&&rx.push("blob");sx.exports={BINARY_TYPES:rx,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:ix,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var ji=ae((Uk,vo)=>{"use strict";var{EMPTY_BUFFER:tb}=Vt(),sd=Buffer[Symbol.species];function nb(t,e){if(t.length===0)return tb;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 sd(r.buffer,r.byteOffset,i):r}function ox(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function ax(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function rb(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function od(t){if(od.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new sd(t):ArrayBuffer.isView(t)?e=new sd(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),od.readOnly=!1),e}vo.exports={concat:nb,mask:ox,toArrayBuffer:rb,toBuffer:od,unmask:ax};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=ue("bufferutil");vo.exports.mask=function(e,r,i,o,c){c<48?ox(e,r,i,o,c):t.mask(e,r,i,o,c)},vo.exports.unmask=function(e,r){e.length<32?ax(e,r):t.unmask(e,r)}}catch{}});var lx=ae((Gk,dx)=>{"use strict";var cx=Symbol("kDone"),ad=Symbol("kRun"),cd=class{constructor(e){this[cx]=()=>{this.pending--,this[ad]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[ad]()}[ad](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[cx])}}};dx.exports=cd});var Nr=ae((qk,hx)=>{"use strict";var Hi=ue("zlib"),ux=ji(),ib=lx(),{kStatusCode:fx}=Vt(),sb=Buffer[Symbol.species],ob=Buffer.from([0,0,255,255]),Io=Symbol("permessage-deflate"),Jt=Symbol("total-length"),Or=Symbol("callback"),Sn=Symbol("buffers"),Lr=Symbol("error"),So,dd=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,!So){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;So=new ib(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[Or];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){So.add(o=>{this._decompress(e,r,(c,l)=>{o(),i(c,l)})})}compress(e,r,i){So.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[Io]=this,this._inflate[Jt]=0,this._inflate[Sn]=[],this._inflate.on("error",cb),this._inflate.on("data",xx)}this._inflate[Or]=i,this._inflate.write(e),r&&this._inflate.write(ob),this._inflate.flush(()=>{let c=this._inflate[Lr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let l=ux.concat(this._inflate[Sn],this._inflate[Jt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Jt]=0,this._inflate[Sn]=[],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[Jt]=0,this._deflate[Sn]=[],this._deflate.on("data",ab)}this._deflate[Or]=i,this._deflate.write(e),this._deflate.flush(Hi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=ux.concat(this._deflate[Sn],this._deflate[Jt]);r&&(c=new sb(c.buffer,c.byteOffset,c.length-4)),this._deflate[Or]=null,this._deflate[Jt]=0,this._deflate[Sn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};hx.exports=dd;function ab(t){this[Sn].push(t),this[Jt]+=t.length}function xx(t){if(this[Jt]+=t.length,this[Io]._maxPayload<1||this[Jt]<=this[Io]._maxPayload){this[Sn].push(t);return}this[Lr]=new RangeError("Max payload size exceeded"),this[Lr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Lr][fx]=1009,this.removeListener("data",xx),this.reset()}function cb(t){if(this[Io]._inflate=null,this[Lr]){this[Or](this[Lr]);return}t[fx]=1007,this[Or](t)}});var Mr=ae((jk,Ao)=>{"use strict";var{isUtf8:px}=ue("buffer"),{hasBlob:db}=Vt(),lb=[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 ub(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function ld(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 fb(t){return db&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Ao.exports={isBlob:fb,isValidStatusCode:ub,isValidUTF8:ld,tokenChars:lb};if(px)Ao.exports.isValidUTF8=function(t){return t.length<24?ld(t):px(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=ue("utf-8-validate");Ao.exports.isValidUTF8=function(e){return e.length<32?ld(e):t(e)}}catch{}});var pd=ae((Hk,vx)=>{"use strict";var{Writable:xb}=ue("stream"),gx=Nr(),{BINARY_TYPES:hb,EMPTY_BUFFER:mx,kStatusCode:pb,kWebSocket:gb}=Vt(),{concat:ud,toArrayBuffer:mb,unmask:wb}=ji(),{isValidStatusCode:_b,isValidUTF8:_x}=Mr(),Co=Buffer[Symbol.species],lt=0,yx=1,Ex=2,bx=3,fd=4,xd=5,To=6,hd=class extends xb{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||hb[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=e.maxBufferedChunks|0,this._maxFragments=e.maxFragments|0,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[gb]=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();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){i(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(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 Co(i.buffer,i.byteOffset+e,i.length-e),new Co(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 Co(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 yx:this.getPayloadLength16(e);break;case Ex:this.getPayloadLength64(e);break;case bx:this.getMask();break;case fd:this.getData(e);break;case xd:case To:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if((r[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(r[0]&64)===64;if(i&&!this._extensions[gx.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=yx:this._payloadLength===127?this._state=Ex: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=bx:this._state=fd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=fd}getData(e){let r=mx;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&&wb(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=xd,this.decompress(r,e);return}if(r.length){if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let i=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(i);return}this._messageLength=this._totalPayloadLength,this._fragments.push(r)}this.dataMessage(e)}decompress(e,r){this._extensions[gx.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}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let l=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");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=ud(i,r):this._binaryType==="arraybuffer"?o=mb(ud(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=lt):(this._state=To,setImmediate(()=>{this.emit("message",o,!0),this._state=lt,this.startLoop(e)}))}else{let o=ud(i,r);if(!this._skipUTF8Validation&&!_x(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===xd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=lt):(this._state=To,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,mx),this.end();else{let i=e.readUInt16BE(0);if(!_b(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Co(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!_x(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=To,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[pb]=o,l}};vx.exports=hd});var wd=ae((Kk,Ax)=>{"use strict";var{Duplex:Wk}=ue("stream"),{randomFillSync:yb}=ue("crypto"),{types:{isUint8Array:Eb}}=ue("util"),Sx=Nr(),{EMPTY_BUFFER:bb,kWebSocket:vb,NOOP:Sb}=Vt(),{isBlob:Br,isValidStatusCode:Ib}=Mr(),{mask:Ix,toBuffer:Hn}=ji(),ut=Symbol("kByteLength"),Ab=Buffer.alloc(4),ko=8*1024,Wn,zr=ko,bt=0,Cb=1,Tb=2,gd=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=bt,this.onerror=Sb,this[vb]=void 0}static frame(e,r){let i,o=!1,c=2,l=!1;r.mask&&(i=r.maskBuffer||Ab,r.generateMask?r.generateMask(i):(zr===ko&&(Wn===void 0&&(Wn=Buffer.alloc(ko)),yb(Wn,0,ko),zr=0),i[0]=Wn[zr++],i[1]=Wn[zr++],i[2]=Wn[zr++],i[3]=Wn[zr++]),l=(i[0]|i[1]|i[2]|i[3])===0,c=6);let f;typeof e=="string"?(!r.mask||l)&&r[ut]!==void 0?f=r[ut]:(e=Buffer.from(e),f=e.length):(f=e.length,o=r.mask&&r.readOnly&&!l);let x=f;f>=65536?(c+=8,x=127):f>125&&(c+=2,x=126);let p=Buffer.allocUnsafe(o?f+c:c);return p[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(p[0]|=64),p[1]=x,x===126?p.writeUInt16BE(f,2):x===127&&(p[2]=p[3]=0,p.writeUIntBE(f,4,6)),r.mask?(p[1]|=128,p[c-4]=i[0],p[c-3]=i[1],p[c-2]=i[2],p[c-1]=i[3],l?[p,e]:o?(Ix(e,i,p,c,f),[p]):(Ix(e,i,e,0,f),[p,e])):[p,e]}close(e,r,i,o){let c;if(e===void 0)c=bb;else{if(typeof e!="number"||!Ib(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let f=Buffer.byteLength(r);if(f>123)throw new RangeError("The message must not be greater than 123 bytes");if(c=Buffer.allocUnsafe(2+f),c.writeUInt16BE(e,0),typeof r=="string")c.write(r,2);else if(Eb(r))c.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let l={[ut]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==bt?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):Br(e)?(o=e.size,c=!1):(e=Hn(e),o=e.length,c=Hn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ut]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Br(e)?this._state!==bt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==bt?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):Br(e)?(o=e.size,c=!1):(e=Hn(e),o=e.length,c=Hn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ut]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Br(e)?this._state!==bt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==bt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}send(e,r,i){let o=this._extensions[Sx.extensionName],c=r.binary?2:1,l=r.compress,f,x;typeof e=="string"?(f=Buffer.byteLength(e),x=!1):Br(e)?(f=e.size,x=!1):(e=Hn(e),f=e.length,x=Hn.readOnly),this._firstFragment?(this._firstFragment=!1,l&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(l=f>=o._threshold),this._compress=l):(l=!1,c=0),r.fin&&(this._firstFragment=!0);let p={[ut]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:x,rsv1:l};Br(e)?this._state!==bt?this.enqueue([this.getBlobData,e,this._compress,p,i]):this.getBlobData(e,this._compress,p,i):this._state!==bt?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=Tb,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let f=new Error("The socket was closed while the blob was being read");process.nextTick(md,this,f,o);return}this._bufferedBytes-=i[ut];let l=Hn(c);r?this.dispatch(l,r,i,o):(this._state=bt,this.sendFrame(t.frame(l,i),o),this.dequeue())}).catch(c=>{process.nextTick(kb,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Sx.extensionName];this._bufferedBytes+=i[ut],this._state=Cb,c.compress(e,i.fin,(l,f)=>{if(this._socket.destroyed){let x=new Error("The socket was closed while data was being compressed");md(this,x,o);return}this._bufferedBytes-=i[ut],this._state=bt,i.readOnly=!1,this.sendFrame(t.frame(f,i),o),this.dequeue()})}dequeue(){for(;this._state===bt&&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)}};Ax.exports=gd;function md(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 kb(t,e,r){md(t,e,r),t.onerror(e)}});var Nx=ae(($k,Lx)=>{"use strict";var{kForOnEventAttribute:Wi,kListener:_d}=Vt(),Cx=Symbol("kCode"),Tx=Symbol("kData"),kx=Symbol("kError"),Rx=Symbol("kMessage"),Dx=Symbol("kReason"),Fr=Symbol("kTarget"),Px=Symbol("kType"),Ox=Symbol("kWasClean"),Yt=class{constructor(e){this[Fr]=null,this[Px]=e}get target(){return this[Fr]}get type(){return this[Px]}};Object.defineProperty(Yt.prototype,"target",{enumerable:!0});Object.defineProperty(Yt.prototype,"type",{enumerable:!0});var Kn=class extends Yt{constructor(e,r={}){super(e),this[Cx]=r.code===void 0?0:r.code,this[Dx]=r.reason===void 0?"":r.reason,this[Ox]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Cx]}get reason(){return this[Dx]}get wasClean(){return this[Ox]}};Object.defineProperty(Kn.prototype,"code",{enumerable:!0});Object.defineProperty(Kn.prototype,"reason",{enumerable:!0});Object.defineProperty(Kn.prototype,"wasClean",{enumerable:!0});var Ur=class extends Yt{constructor(e,r={}){super(e),this[kx]=r.error===void 0?null:r.error,this[Rx]=r.message===void 0?"":r.message}get error(){return this[kx]}get message(){return this[Rx]}};Object.defineProperty(Ur.prototype,"error",{enumerable:!0});Object.defineProperty(Ur.prototype,"message",{enumerable:!0});var Ki=class extends Yt{constructor(e,r={}){super(e),this[Tx]=r.data===void 0?null:r.data}get data(){return this[Tx]}};Object.defineProperty(Ki.prototype,"data",{enumerable:!0});var Rb={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Wi]&&o[_d]===e&&!o[Wi])return;let i;if(t==="message")i=function(c,l){let f=new Ki("message",{data:l?c:c.toString()});f[Fr]=this,Ro(e,this,f)};else if(t==="close")i=function(c,l){let f=new Kn("close",{code:c,reason:l.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});f[Fr]=this,Ro(e,this,f)};else if(t==="error")i=function(c){let l=new Ur("error",{error:c,message:c.message});l[Fr]=this,Ro(e,this,l)};else if(t==="open")i=function(){let c=new Yt("open");c[Fr]=this,Ro(e,this,c)};else return;i[Wi]=!!r[Wi],i[_d]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[_d]===e&&!r[Wi]){this.removeListener(t,r);break}}};Lx.exports={CloseEvent:Kn,ErrorEvent:Ur,Event:Yt,EventTarget:Rb,MessageEvent:Ki};function Ro(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Do=ae((Vk,Mx)=>{"use strict";var{tokenChars:$i}=Mr();function Lt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function Db(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,l,f,x=-1,p=-1,w=-1,_=0;for(;_<t.length;_++)if(p=t.charCodeAt(_),l===void 0)if(w===-1&&$i[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 y=t.slice(x,w);p===44?(Lt(e,y,r),r=Object.create(null)):l=y,x=w=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);else if(f===void 0)if(w===-1&&$i[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=_),Lt(r,t.slice(x,w),!0),p===44&&(Lt(e,l,r),r=Object.create(null),l=void 0),x=w=-1}else if(p===61&&x!==-1&&w===-1)f=t.slice(x,_),x=w=-1;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(o){if($i[p]!==1)throw new SyntaxError(`Unexpected character at index ${_}`);x===-1?x=_:i||(i=!0),o=!1}else if(c)if($i[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&&$i[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 y=t.slice(x,w);i&&(y=y.replace(/\\/g,""),i=!1),Lt(r,f,y),p===44&&(Lt(e,l,r),r=Object.create(null),l=void 0),f=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?Lt(e,S,r):(f===void 0?Lt(r,S,!0):i?Lt(r,f,S.replace(/\\/g,"")):Lt(r,f,S),Lt(e,l,r)),e}function Pb(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(", ")}Mx.exports={format:Pb,parse:Db}});var No=ae((Zk,Vx)=>{"use strict";var Ob=ue("events"),Lb=ue("https"),Nb=ue("http"),Fx=ue("net"),Mb=ue("tls"),{randomBytes:Bb,createHash:zb}=ue("crypto"),{Duplex:Jk,Readable:Yk}=ue("stream"),{URL:yd}=ue("url"),In=Nr(),Fb=pd(),Ub=wd(),{isBlob:Gb}=Mr(),{BINARY_TYPES:Bx,CLOSE_TIMEOUT:qb,EMPTY_BUFFER:Po,GUID:jb,kForOnEventAttribute:Ed,kListener:Hb,kStatusCode:Wb,kWebSocket:Ue,NOOP:Ux}=Vt(),{EventTarget:{addEventListener:Kb,removeEventListener:$b}}=Nx(),{format:Vb,parse:Jb}=Do(),{toBuffer:Yb}=ji(),Gx=Symbol("kAborted"),bd=[8,13],Zt=["CONNECTING","OPEN","CLOSING","CLOSED"],Zb=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,ge=class t extends Ob{constructor(e,r,i){super(),this._binaryType=Bx[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Po,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),qx(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Bx.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 Fb({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxBufferedChunks:i.maxBufferedChunks,maxFragments:i.maxFragments,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new Ub(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[Ue]=this,c[Ue]=this,e[Ue]=this,o.on("conclude",ev),o.on("drain",tv),o.on("error",nv),o.on("message",rv),o.on("ping",iv),o.on("pong",sv),c.onerror=ov,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Wx),e.on("data",Lo),e.on("end",Kx),e.on("error",$x),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[In.extensionName]&&this._extensions[In.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){ot(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())}),Hx(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){vd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Po,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){vd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Po,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){vd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[In.extensionName]||(o.compress=!1),this._sender.send(e||Po,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){ot(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(ge,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(ge.prototype,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(ge,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(ge.prototype,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(ge,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(ge.prototype,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(ge,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});Object.defineProperty(ge.prototype,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(ge.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(ge.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Ed])return e[Hb];return null},set(e){for(let r of this.listeners(t))if(r[Ed]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[Ed]:!0})}})});ge.prototype.addEventListener=Kb;ge.prototype.removeEventListener=$b;Vx.exports=ge;function qx(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:qb,protocolVersion:bd[1],maxBufferedChunks:1048576,maxFragments:131072,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,!bd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${bd.join(", ")})`);let c;if(e instanceof yd)c=e;else try{c=new yd(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let l=c.protocol==="wss:",f=c.protocol==="ws+unix:",x;if(c.protocol!=="ws:"&&!l&&!f?x=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:f&&!c.pathname?x="The URL's pathname is empty":c.hash&&(x="The URL contains a fragment identifier"),x){let I=new SyntaxError(x);if(t._redirects===0)throw I;Oo(t,I);return}let p=l?443:80,w=Bb(16).toString("base64"),_=l?Lb.request:Nb.request,S=new Set,y;if(o.createConnection=o.createConnection||(l?Qb:Xb),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&&(y=new In({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=Vb({[In.extensionName]:y.offer()})),r.length){for(let I of r){if(typeof I!="string"||!Zb.test(I)||S.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");S.add(I)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),f){let I=o.path.split(":");o.socketPath=I[0],o.path=I[1]}let v;if(o.followRedirects){if(t._redirects===0){t._originalIpc=f,t._originalSecure=l,t._originalHostOrSocketPath=f?o.socketPath:c.host;let I=i&&i.headers;if(i={...i,headers:{}},I)for(let[C,R]of Object.entries(I))i.headers[C.toLowerCase()]=R}else if(t.listenerCount("redirect")===0){let I=f?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!I||t._originalSecure&&!l)&&(delete o.headers.authorization,delete o.headers.cookie,I||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),v=t._req=_(o),t._redirects&&t.emit("redirect",t.url,v)}else v=t._req=_(o);o.timeout&&v.on("timeout",()=>{ot(t,v,"Opening handshake has timed out")}),v.on("error",I=>{v===null||v[Gx]||(v=t._req=null,Oo(t,I))}),v.on("response",I=>{let C=I.headers.location,R=I.statusCode;if(C&&o.followRedirects&&R>=300&&R<400){if(++t._redirects>o.maxRedirects){ot(t,v,"Maximum redirects exceeded");return}v.abort();let O;try{O=new yd(C,e)}catch{let D=new SyntaxError(`Invalid URL: ${C}`);Oo(t,D);return}qx(t,O,r,i)}else t.emit("unexpected-response",v,I)||ot(t,v,`Unexpected server response: ${I.statusCode}`)}),v.on("upgrade",(I,C,R)=>{if(t.emit("upgrade",I),t.readyState!==ge.CONNECTING)return;v=t._req=null;let O=I.headers.upgrade;if(O===void 0||O.toLowerCase()!=="websocket"){ot(t,C,"Invalid Upgrade header");return}let E=zb("sha1").update(w+jb).digest("base64");if(I.headers["sec-websocket-accept"]!==E){ot(t,C,"Invalid Sec-WebSocket-Accept header");return}let D=I.headers["sec-websocket-protocol"],L;if(D!==void 0?S.size?S.has(D)||(L="Server sent an invalid subprotocol"):L="Server sent a subprotocol but none was requested":S.size&&(L="Server sent no subprotocol"),L){ot(t,C,L);return}D&&(t._protocol=D);let F=I.headers["sec-websocket-extensions"];if(F!==void 0){if(!y){ot(t,C,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let z;try{z=Jb(F)}catch{ot(t,C,"Invalid Sec-WebSocket-Extensions header");return}let J=Object.keys(z);if(J.length!==1||J[0]!==In.extensionName){ot(t,C,"Server indicated an extension that was not requested");return}try{y.accept(z[In.extensionName])}catch{ot(t,C,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[In.extensionName]=y}t.setSocket(C,R,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(v,t):v.end()}function Oo(t,e){t._readyState=ge.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Xb(t){return t.path=t.socketPath,Fx.connect(t)}function Qb(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Fx.isIP(t.host)?"":t.host),Mb.connect(t)}function ot(t,e,r){t._readyState=ge.CLOSING;let i=new Error(r);Error.captureStackTrace(i,ot),e.setHeader?(e[Gx]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Oo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function vd(t,e,r){if(e){let i=Gb(e)?e.size:Yb(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Zt[t.readyState]})`);process.nextTick(r,i)}}function ev(t,e){let r=this[Ue];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Ue]!==void 0&&(r._socket.removeListener("data",Lo),process.nextTick(jx,r._socket),t===1005?r.close():r.close(t,e))}function tv(){let t=this[Ue];t.isPaused||t._socket.resume()}function nv(t){let e=this[Ue];e._socket[Ue]!==void 0&&(e._socket.removeListener("data",Lo),process.nextTick(jx,e._socket),e.close(t[Wb])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function zx(){this[Ue].emitClose()}function rv(t,e){this[Ue].emit("message",t,e)}function iv(t){let e=this[Ue];e._autoPong&&e.pong(t,!this._isServer,Ux),e.emit("ping",t)}function sv(t){this[Ue].emit("pong",t)}function jx(t){t.resume()}function ov(t){let e=this[Ue];e.readyState!==ge.CLOSED&&(e.readyState===ge.OPEN&&(e._readyState=ge.CLOSING,Hx(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Hx(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Wx(){let t=this[Ue];if(this.removeListener("close",Wx),this.removeListener("data",Lo),this.removeListener("end",Kx),t._readyState=ge.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[Ue]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",zx),t._receiver.on("finish",zx))}function Lo(t){this[Ue]._receiver.write(t)||this.pause()}function Kx(){let t=this[Ue];t._readyState=ge.CLOSING,t._receiver.end(),this.end()}function $x(){let t=this[Ue];this.removeListener("error",$x),this.on("error",Ux),t&&(t._readyState=ge.CLOSING,this.destroy())}});var Xx=ae((Qk,Zx)=>{"use strict";var Xk=No(),{Duplex:av}=ue("stream");function Jx(t){t.emit("close")}function cv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Yx(t){this.removeListener("error",Yx),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function dv(t,e){let r=!0,i=new av({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,l){let f=!l&&i._readableState.objectMode?c.toString():c;i.push(f)||t.pause()}),t.once("error",function(c){i.destroyed||(r=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick(Jx,i);return}let l=!1;t.once("error",function(x){l=!0,c(x)}),t.once("close",function(){l||c(o),process.nextTick(Jx,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",cv),i.on("error",Yx),i}Zx.exports=dv});var Sd=ae((eR,Qx)=>{"use strict";var{tokenChars:lv}=Mr();function uv(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&&lv[l]===1)r===-1&&(r=o);else if(o!==0&&(l===32||l===9))i===-1&&r!==-1&&(i=o);else if(l===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let f=t.slice(r,i);if(e.has(f))throw new SyntaxError(`The "${f}" subprotocol is duplicated`);e.add(f),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(r,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}Qx.exports={parse:uv}});var oh=ae((nR,sh)=>{"use strict";var fv=ue("events"),Mo=ue("http"),{Duplex:tR}=ue("stream"),{createHash:xv}=ue("crypto"),eh=Do(),$n=Nr(),hv=Sd(),pv=No(),{CLOSE_TIMEOUT:gv,GUID:mv,kWebSocket:wv}=Vt(),_v=/^[+/0-9A-Za-z]{22}==$/,th=0,nh=1,ih=2,Id=class extends fv{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:1024*1024,maxFragments:128*1024,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:gv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:pv,...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=Mo.createServer((i,o)=>{let c=Mo.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=yv(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=th}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===ih){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Vi,this);return}if(e&&this.once("close",e),this._state!==nh)if(this._state=nh,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(Vi,this):process.nextTick(Vi,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{Vi(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",rh);let c=e.headers["sec-websocket-key"],l=e.headers.upgrade,f=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Vn(this,e,r,405,"Invalid HTTP method");return}if(l===void 0||l.toLowerCase()!=="websocket"){Vn(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!_v.test(c)){Vn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(f!==13&&f!==8){Vn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Ji(r,400);return}let x=e.headers["sec-websocket-protocol"],p=new Set;if(x!==void 0)try{p=hv.parse(x)}catch{Vn(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 $n({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let y=eh.parse(w);y[$n.extensionName]&&(S.accept(y[$n.extensionName]),_[$n.extensionName]=S)}catch{Vn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let S={origin:e.headers[`${f===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(S,(y,v,I,C)=>{if(!y)return Ji(r,v||401,I,C);this.completeUpgrade(_,c,p,e,r,i,o)});return}if(!this.options.verifyClient(S))return Ji(r,401)}this.completeUpgrade(_,c,p,e,r,i,o)}completeUpgrade(e,r,i,o,c,l,f){if(!c.readable||!c.writable)return c.destroy();if(c[wv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>th)return Ji(c,503);let p=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${xv("sha1").update(r+mv).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[$n.extensionName]){let _=e[$n.extensionName].params,S=eh.format({[$n.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",th),m.setSocket(c,u,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxBufferedChunks:this.options.maxBufferedChunks,maxFragments:this.options.maxFragments,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(m),m.on("close",()=>{this.clients.delete(m),this._shouldEmitClose&&!this.clients.size&&process.nextTick(Yi,this)})),f(m,o)}};rh.exports=Id;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 Yi(t){t._state=nh,t.emit("close")}function th(){this.destroy()}function Zi(t,e,r,i){r=r||Bo.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${Bo.STATUS_CODES[e]}\r
16
+ `)),c.removeListener("error",rh),w.setSocket(c,l,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxBufferedChunks:this.options.maxBufferedChunks,maxFragments:this.options.maxFragments,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(w),w.on("close",()=>{this.clients.delete(w),this._shouldEmitClose&&!this.clients.size&&process.nextTick(Vi,this)})),f(w,o)}};sh.exports=Id;function yv(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 Vi(t){t._state=ih,t.emit("close")}function rh(){this.destroy()}function Ji(t,e,r,i){r=r||Mo.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} ${Mo.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 Zn(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let u=new Error(o);Error.captureStackTrace(u,Zn),t.emit("wsClientError",u,r,e)}else Zi(r,i,o,c)}});var mh=ae(ve=>{"use strict";var B=N;(function(t,e){let r=N,i=t();for(;;)try{if(-parseInt(r(1506))/1*(-parseInt(r(1498))/2)+parseInt(r(1063))/3+parseInt(r(551))/4+-parseInt(r(1180))/5+parseInt(r(611))/6+-parseInt(r(1475))/7+parseInt(r(1222))/8*(-parseInt(r(1199))/9)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(qo,150383);function qo(){let t=["BvjNBMq","t2XhwKy","uxPsEee","yNL0zu9MzNm","x2HHBMrSzva","yvvoAMS","CYbHBhjLywq","CuXysMO","z2v0qwXSs2u","tNLPB0u","tM9Yv0G","CMvPy28","zeLAAwm","CgLUz09Uy2u","zwn0","tvvpz2q","AK9Wqvq","DfvzzLC","t3vWz3C","Au1yDNK","sNjXwK8","Aw5KzxG","y2XVC2veqG","wgzoB3m","sNrbqwC","renhv0e","BfDmwum","rK1REvm","B25ozxr3B3i","BhLUuge","zNvUy3rPB24","qKjhuuC","vKTfsgi","zgvMAw5Luhi","Aw47y2HHCNm","zcWG","lcbxzwjtB2m","zw50zwqGDhK","EhH2DhK","AgfZ","yu9NyLK","BNrWsvC","s2nxzMy","y29TCgXLDgu","rMnHtuO","AgfUz2u","tgz1BNG","uuXfs3O","CMvWBgfJzq","o2nOyxjZzxq","Eu9WqK8","DgfIyxnL","r0z0Awe","x0rctMfTzq","C3rVCMu","sxbND3i","zNjHBwvuExa","r0nYtMS","tKLoBMq","zwjdCLu","venAEfi","DxrMofDYAxq","zgv2AwnLx2K","ywXSzwqGBxu","mxW2FdD8oxW","y3ruAw1LB3u","vwLnC3i","y3jLyxrLq2W","C0Pjr1i","u1rjyLm","Cg93","C3vIBvm","tMv4yxa","id4G","vff0zxe","ufjnCg8","CLzPCwu","CKrjA3K","uNHZELO","nhWXFdH8mta","BxnN","uNDkyuq","zxjFDhrS","BwXSz04","AK9jzMG","CxjSwwm","zwfHAgm","vuDbu0i","B1forMq","BwT0zxi","rMHksfG","BurSwfK","Dg9oDw1Izxi","y2XVC2u","qLfPCNm","wKXfBMG","CNzHBa","q0LJyxm","DxnLCKLW","tvjMsK0","DMfSDwu","AxmGDw5Kzwy","C2vUza","zNjVBuHHC2G","tLvAz0i","Cu5ot3e","DeLUDgvYy2u","zvjfB3i","Ehf5CNu","t3zfz3u","wff0u2e","ChvZAa","yw51Ce1LC3m","twTZAg8","ihrPBwvZ","Fdn8mtb8mhW","AwrRtva","BgLUzq","y29UBMvJDgK","EeHerfK","wKPUvwW","y2XIAva","DezsEhq","r1Lvuxq","CMvHzg9UBhK","yKjrvgq","u2fMuee","yLDvDvu","x29UvgLTzw8","A1brqwS","DLLUDuq","rMHPrLK","BxnNsuq","zvvWwMW","rNfSyMe","v0rdEwO","twLZC2LUzYa","yxvTtMK","AevYCM9Yrxy","DKDovMy","qw9fvu8","BM95yxC","yMLUyxj5","z2vtEw5J","qNjPzgDL","sLPgtLG","DvjVzeO","EsbJBg9Zzwq","z3jZshu","AwXLx25HBwu","B2fK","y3vZDg9Tshq","t2PnDvi","tKzfwuy","z2v0s2v5","s1LpsgK","y29Uy2f0","wurNy3y","DvjXshe","B3DbvgO","rfznBw8","BIWGAg9ZDg4","AuzovxO","sKfRrLO","v3r3DNC","CNnXB3C","BwvZC2fNzv8","wxDhzvC","y2XLyxi","zgf0yq","wuTrze0","C2Hkt3a","ywL3vMe","uLvQEe4","re1jENy","tufyx1jfvfi","CxHpv3K","vKD1Ehe","z3r6ueS","EKT6tfO","Ce5qrhO","ign1CNnVCIa","x3DZ","yxrLq291BNq","AwnTuLi","C2fNzq","zNjPqNC","ywDLu2HVDW","mxWWFdj8m3W","CeLOtey","D2LxDxa","rfDnqu0","C2jNwLK","C2ThEuC","l3DZl3yY","vM5Mvfy","uKj5vgy","x2jPBMfYEvq","D0DWsva","x2zVCM1HDeu","Dw5hDvG","EhfjC0u","BxfnDvC","ChjVy2vZCW","uKPMtvO","C3rVCcbPBw0","zxH0ugf5Bg8","vuHJEw8","B2nRq1q","Bwf4uMv0CMK","yxKSig5LDhC","x3vYBa","v2vNs00","y3jLyxrLuMu","AwXSihvZzsa","yxKSihrYEsa","v3f6rgm","u1jZu3u","AuHjCxy","rxbmAgi","r0zsDwS","BMjVqMq","r0L0s3m","rNf5qxi","y3jLyxrLt2i","DcbSAw1PDa","CMvKDwnL","CM92AwrLige","BMCGzMfPBgu","CLzHBhvLCW","C3zvwgG","zMPKwvG","uLnlAfm","zxjYB3i","BwP5y0q","wenYqxq","Ae9Wzw5fDMu","uxbsEMG","DMTwDwu","vhzJwg4","ywXSq3vYC28","q29UzMLN","vMTny0i","ENLKvuO","nhWWFdj8mxW","vLHwtNO","zgDuzeq","qwjVCNrfCNi","vNrQEMi","Dvj1qvC","y2HnyxHuCMK","uhLzrKi","BvnUz3a","qxfUuvu","EhHowNa","r3viB1O","tLLivLm","rMDJu3O","DgHHBIbSB2m","tfPNru0","rMT4C1i","yujztLu","EvfYwNy","mhWZFdj8nhW","x3bHDgHlzxK","CeHvEKG","B3LjBg4","zevVqK8","B3jRzxjhBg8","vNHczhK","CxLXr2G","rKLMzK8","Cgf5Bg9Hzfq","D3nZoI8V","Cg9PBNrbBMq","BK5Stvu","BMrWB2LUDca","CNnVCKzPBgu","z2v0q3vYCMu","BKfZwwq","x3nLCuLK","rxzLBNq","DK1HC0S","zsbHihn0CMK","u0Htqwq","s2fKz0O","uvDuy3K","rgnyzw4","zuDbrLC","Dxrjza","ywXPzcb1CMW","zKreu1K","x2rPC2nVBM4","t0HUvhK","Cg9PBNrdB24","zw5JB2rPBMC","ywrK","qNzRAKK","BMfxrxy","CKPWsK8","yNL0zxm","C2v0u3rVCMe","rNf5ANC","AKT3vha","sLjovMW","Dw50","B2HmvfO","BgvY","DcbVzIbYyw4","quX0CuC","DgrJy1m","vgzWBey","rvLpwfK","CIb0DhDjra","B0Txwgu","AxzYs1O","vw5Oyw5KBgu","x2rLC3rYB3K","yxrHlcbKyxq","mdaWma","AwPIu3C","nxWZFdb8mxW","A0LYwMq","AMTHBg0","tw1RqMG","zKPLvfq","suvtx0vsuK8","zKfKqMe","EKLuz3e","B2nRzxq","uNrWyMG","CMvZzxruCMK","t2TZEeu","DuvtAhm","serXELy","r2Dztxu","qu1er1C","AgvHzgvY","C0jf","DxHiBfG","ihbYB3rVy28","x2nSzwfYvgK","qNrWuee","x2LUAxrqCM8","x2LUAxq","A0Hos2O","Bg9N","se9SAxq","C3vIyxjYyxK","qLzcvfG","ugviv08","DgHcvMm","x2rItMfTzq","Ehn2q1C","suzbsxK","DxbKyxrLq3u","yvL0DLC","C1ryCKu","vwPYEfm","BNLuD2y","x1fVu01HBMe","vMHkwKu","vu55EMK","x2TLEvbHDgG","A2z4Chi","DMvYC2LVBG","Ef9MCM9UDgK","A1fuwvG","y29UDgLUDwu","ywXS","Dhr3Awq","twDIveW","x3jLywr5q2W","ywnRDxbfBMq","mxWZFdj8nhW","Dgv4Dc9WBge","Dfr5EuK","DgLTzw91DcW","BgrOvfa","DKrbrMu","sfjrzgW","Efrurw52","vgDUzLG","rK9gAei","AwrRr0u","twvZC2fNzuu","qMLfr0O","Dg9tDhjPBMC","B25JBg9Zzq","tMziyvq","wKjdDuq","r3vAseu","DfLNrxi","rNjVBNrPzxi","zMLN","u1LvwK0","teL1tuy","CKTMB2C","s2Tmqxy","A1jlvMW","thHWD2C","A2PUvuy","BgXtveu","q0rIreO","t3zvBMK","vwTTquK","BMDuAw1LCG","uwfwvLO","A2v5","rvrrAwu","uhjPBwfYEuS","zeLSwNq","CgvYC2LZDgu","wuHet1C","wM5nsNm","Bg9NsurozxC","rLDt","igzHAwWSig0","qu16DeK","y2T3zKO","ywDL","u0jVCuS","DxHQDhe","r3HVBgO","z2v0q3vYC28","tMfTzq","sgH2sMW","t0zrvLa","uwXVDwC","CuvzCMG","Euroz3G","Ec11C2uT","qwftufm","C3bSAwnL","ywnRpwzYB24","BNrfBMrWB2K","zgvJB2rLzey","zLDfEhG","x3bPBMC","swDYuvu","y1b3A2W","B0rhD1e","wgTRv3a","Dg9hzw5LCMe","C2DbshC","r3fNAxi","mhWYFdr8m3W","DhDAyum","qufryu0","te1euK4","EvHAtei","mhWYFdr8mxW","CKrcv1K","BfrPBwvVDxq","rMnrvfy","mtf8ohW1Fdi","CuLewwS","AxnszwfKEq","wxHuEgm","tezTquG","zK1sDNe","tvfOA08","twDftui","Cg9W","BuPbwxy","AvnIzNu","B3nLza","wuPXBKK","BfHOtgq","we9Sr20","C3vJy2vZCW","BLjgqwi","twzKAu0","C1Dtteu","tMH0ywq","AMPPwwO","sMrnrfm","yxjdChq","t2jQzwn0","D09NBe0","uLL3CM0","Dg9cExrLC0W","ALD4ELe","u0PIBNy","zNjVBu51Bwi","tuDJDxK","C3rYAw5NAwy","yxbWBgLJyxq","vwT6zxa","Bwf4tg9ZC0m","zM9YrwfJAa","yxv0B21HDgK","twjoAMG","z1DVAw8","BwHiC3G","CM92AwrLihy","CMvJB25Uzwm","wxnbCvy","CYbPBNn0yw4","uhbRuhu","wxn2seO","DhLWzq","Aw9UvgLTzw8","ChfiuK4","A2v0ignVBNm","y2jZBfC","EM5Tr1C","ug5rDK4","zMLSzw5HBwu","wKHvquS","v0Hhtxu","BuTwD2u","Cgf5Bg9Hza","Dg9Y","x2nYzwf0zvm","icSG","AuLNuu8","A2TNCKS","Fdf8n3W5Fdi","x29Uq2XVC2u","qwXIzvO","yLPowhm","zxjFAxnFywm","rvfjBNO","s3bUsMS","zw1LBNq","AgrHrxe","B25LCNjVCG","wvrOqvu","x2HHBMrSzu8","zxjYtxnN","BNHurwm","wvz3zvO","EMzqBwC","AvboDwu","t05UD3m","yw5Hz2vY","CMfNzvn5BMm","v3b1Dgu","whjpsK4","tK9NCu0","BgXLyxi","AgvHzgvYCW","uNrmt2W","Dw1ktNK","zNjVBunOyxi","ChjVDg9JB2W","x21PBMLoyxy","CfLetw4","tgzmAvG","AuHkCK8","y3vYCMvUDeu","rNntDMi","C3vIC3rYAw4","suTgywK","BhPvvw8","BMCGB3iGyw4","C2f0CfC","seDOz0e","y2fSBa","t2zdwNO","yw1Lrwu","CvLir1i","y0fjseS","zKrkwfG","DxHAzxO","CMvHC29U","BwfW","B3bLBKrc","ywjVCNq","yK9iyNq","u3fjA2i","v0LsC0K","sfrYCNC","x25HDMLNyxq","vMPtCgu","BhfSDe8","C3rYAw5N","C0Xf","uvPeyxq","zMLSDgvY","sunTs1y","qMjdrNK","uMvHzcbWyxm","whvRAM0","re5vr2m","x29Ut3bLBG","txPdtuC","EK9wrw8","v1Hjz0u","DgH0t3u","Be5mAxK","ihzHBgLKigq","z29PBMCGyxC","tffcsve","q29Kzq","C3rHCNq","rgzuCKW","ruvtq0K","B3bLCNr5","B3bLBG","CgfYC2u","mdaWmdaWmda","wu9uwfO","z2v0sxrLBq","yLnnre0","vunmz0m","BMDLza","z1HPqxu","BMnVzgLUzW","zK50B0e","A2j5rMi","y2Dbq0q","BKrIvhG","B25nzxnZywC","Bg93","AefJA01LC3m","rg1WD0y","BNrLCG","uwjSALu","q2TXqu0","x2rPC3bHDgm","AwHntvu","z2vrDwv1zuW","ndC5mdiWrK1Nu0Pc","yxvsB2q","tg9NsurozxC","uKzqEK0","DgHLBG","DgvmB2Djre4","zhjtuLy","zxH0zw5ZAw8","q09otKvdveK","DhjPBq","C2v0y3vYC28","yxbWEKS","BgLUzw5V","CKvPBve","BeXPrKm","CNzHBfzHBhu","sNjyBxa","vgL0zue","zgvS","vwTqtg8","vxviq0O","svLSBhO","uxvLDwu","ze5wu1e","Dfzks2G","EvDXqNe","DhDVCMTdAge","qKLbEMK","zfvcrwO","su1qqwq","CNjbtva","BMH2tu4","yKPWtwW","wKrtr3C","yMPes3O","y0HJENa","yMrOqLm","CwjPEMy","x3DZsw5ZDge","zhDtBum","DgDPt1O","CMLRt1i","ExHKDeS","Den4DKe","uNbewNC","BMv3vMvYC2K","zwTdr3K","AernyM0","tun5D28","yw5Nzq","B2nRzxrgywK","x2n1CNnVCK0","yNL0zuXLBMC","zwnVBM5Ly3q","whfev28","wKjXq0q","DgjXB0u","tuj5ze0","tgLRrLq","AMn5uLy","mZy3otK4ExPNANvL","A1PjteS","u25Yww4","q09oveLovuu","BwDmz1m","x3bYB3rVy28","yKX4Ee8","B2Hqshu","rfDjANu","CMv0CNLdB3u","wK9ZCKG","CKDet1y","x29UugfNzu4","uMvJB25Uzwm","Eef4Dvq","x3fVC0rc","AvDHDgm","zg9Uzq","ANP0Bxu","DvD5uuC","DeTHAgK","q0vuC3a","yxGGCMv0CMK","CMvHzfvjBNq","v2vPEgLUsLm","sfnHzwq","yxnL","x2LZsw5PDa","sNfgvNO","BwT6CKi","zLH0z2K","q1HXA1G","tKPxqu0","DMvYC2LVBMm","BML0AwfSAxO","BwvY","B3vUDa","zMvY","uwfuruy","DKf5r2m","ChPAu20","AwXLtMfTzq","zcWGDw5RBM8","BKXPBMu","rvPgwK0","vuTzrhK","B1DXD0G","tuPfz3i","CMfTugfYyw0","AgvKtwf4uMu","Bhn2v0i","zfbesgy","uunPuKC","t2LPBvG","x21LC3nHz2u","B0zQvKW","tgz4uMS","EfvZzuvUDG","CgLUz0XVC3m","ywnRx2LK","wfPwCxG","vK56qKm","v25KtM8","u2TPCcbWyxm","CeTPEhi","vKTwuha","x2LZqNjVD3m","y0Pcr08","zMDHrK0","q0n3B0u","DgjjzLC","wgLgB3O","Cgu6ia","twLKCva","EuPMDeG","vuHZDKe","zgLZCgf0y2G","x19LC01Vzhu","D2fZq2XLyw4","BgvUz3rO","y29UDgv4Da","D29yzfq","qNzhALa","vuj2BMS","C3zwshu","C05Qvxe","A0Xusei","CuXRtMW","rhnMq1m","CLnwrNy","x29UrxjYB3i","r2LozwS","rxjYB3jdB2q","wKzprhq","sLnptLa","Dunqs1O","q0Xpu0ve","sxfAA1u","C2HPzNq","AxnZu2S","y2XLyxjtDg8","sKfyDgO","ChjVDg90Exa","wKjIEKe","ExbL","igzPzwXKoIa","s292t2G","Dvnjqwq","rwP1EhK","AxnFywnR","sMnhtgW","CM9YrxzLBNq","twnXtxe","EejmufK","sMPzBfO","Bwu6ia","BNvTyMvY","zxq9DxrMltG","rerRy3u","ChbL","Dwzyquq","zgDIBfK","EhDrBey","yxbWzw5Kq2G","AurmEgi","u2HHCMvKv28","CKryDxK","t01zzMq","EMjbu1m","quLADhi","Aw5KzxHpzG","uMzID0u","Dg9cExrLCW","CMvTB3zLrxy","CgXLyxnLiha","q2nNvvG","ueDqrg8","x3bYzwzPEa","q1fXDhu","sePJEM4","BMfbuM4","x2LZv29YA2u","BM5Ly3q","q3fzthC","qw16A3K","revNzMy","BMvY","v2nwzgq","Bhv4qwO","venLugW","B3nwtgm","ve9qwhm","BuzTthG","x2LZtwLUAvq","BuTZAha","y291BNq","uNjhrhe","yw5ZzM9YBvq","zw50","B3vvy3y","mxWZFdj8nxW","zhvyu0q","DMTKsMi","uNHtzu4","qMfRBKq","tgLZDgvUzxi","x2LUAxrhBg8","x2HHBMrSzvi","x2LZtwLUAvC","EefHDfq","thvtz0q","BM9Uzv9UB24","DKn3rvq","y2roEvK","DgLUzYbZzxi","yM9KEq","uvfVqNe","uvnRwu4","EK9ls2O","DLHQwfC","v2T0tfC","zxf1ywXZ","zw5HyMXLuw8","wgfOAKy","C0XPC3rLBMu","wKfytge","tLb5zwu","t3vTufe","x0vysvnu","sePhB3e","sKXcBMC","x3bPBMDqB24","t3bSthC","tfjMuwS","yMLUza","r2PgCLi","CgLUz19VBMm","zwDSAfm","uNnlBwu","EvjLy29UBMu","CMvZzxrfBMq","AxnmB25N","Cgf5Bg9Hzeu","vhfiANC","yKjKAfu","t3rvsLm","y09Wzw4","yurLANG","tgziBeS","ELDVyMu","wK9qv0O","wur0EvC","ywnOzwq","EK5yD0O","twrXv24","Eej2vgG","Aw5KzxGGB3u","C3nMA1y","Dwz6z3a","yMXVy2TLza","Cuj0r2S","D3zhBu8","BgLZDgvUtMu","yvfJEwu","Aw5PDcbrB1m","u0DRzvC","ruviwMW","y3vYC29Yx2y","zwLmque","x3nLBMrby2S","tNrkze8","qvvlwNe","C2vYDMLJzq","CvHWv1C","q3DkBxC","yw1PA3K","vejssKi","uLjpuG","zfb5wem","wMf6rha","q1zuEKS","AwXK","DhjPzxmGCMu","q1nYtM0","Ec1TC2CTy3u","A2v5CW","suvkzvq","A0LZB1y","qKfIBu0","t2TyqLa","wK5grfu","y29Kzq","C2v0sxrLBq","yLn0uLm","s2zwC2G","B2zMC2v0","CM1PCge","vMfbz04","sMrKq3G","Aw5N","teH3zNG","zw5KCg9PBNq","CNjVCK1LC3m","revxC2K","lcbTyxGGCMu","DLfWvxu","CLjABeW","Ae1Rvee","uKPYDve","sg9PyM0","zKPUrvq","rhbcDuq","yM9L","yMLUyxj5vhK","ihrPBwvVDxq","B3nLrxzLBNq","BKjpwK0","vM9iqvK","BeTAwNK","vMHgv0O","y3vYC29YlNm","thH4ChO","q0TcAvK","BwvZ","z2LVu2W","wK1Mzuy","zLH4sMO","s2ruqM0","Avzxrxq","tuvtu0fhrv8","CMvZDwX0","zgvSzxrLrge","rgvKAwnHDgu","vgfN","y29UC3rYDwm","EfjZDfu","t2jczui","qMXOqu4","x2LUDgvYDMe","y2XVC2uSihC","B1nUBwq","BwLUzW","vuHqENu","y3jLyxrLt3a","Bgrxzeu","BLLsv1G","CwDKsgG","x3nVy2TLDa","DMHIvu4","ywDLsgLKzq","zeHoteq","tLfmrui","s3DwCLi","u3f3uvC","s3zuqvm","BMrWB2LUDfq","Aw5Lza","x2n1CNnVCK4","vgLTzw91Da","BM93","tfzNELK","wvjuufa","BwvZC2fNzq","q3LsBMy","x2rYB3bhBg8","C2v0q3vYC28","yxnZAwDU","ChrVCG","EKD4zK4","y29UBMvJDca","DNbYDhO","zxmGCMvHy2G","BeHbsfG","zwrPyxrLBhK","ywLXD08","qLLNvKq","vhDqrum","CeDzEKi","ywnR","Bg9Nsurhzw4","uNHeqM4","q3PIA0i","rwXOA0S","ALv1AMO","CYbWyxjHBxm","tMjoALK","CMLLC0nVDw4","DgLTzw91Da","D3m6lY8","vMDsEhK","A2nqzuW","tKLSvxC","AgrQrKW","vw5PBxbSzw0","DvPTtwi","q291BNq","x2nVBM5Ly3q","CMLZuhm","ywDLrxzLBNq","wuD1wxi","yMfJA3vWigu","BwHKC3O","vfPIuxu","vvDevgm","vLDHvfe","x2DLDeLUDgu","C3nHz2vfDMu","Dg9mB3DLCKm","uhffCKu","zM9Yy2u","DK92tei","ENPuBuq","vfz4qum","x3jLy29UBMu","CNnVCL92ywW","BMrLEa","t1bftL9fuLi","vMvOEMy","A25vvva","CMvQzwn0","CgfNzxnOB3C","zMzLCG","vxv1A0i","Bu9ewxe","zxrxB3jRq2G","shLuzgW","x2XPC3rLBMu","tg9Nsuq","x2vUzhbVAw4","CLH4uLa","shPyz3e","z1Dmz2u","z2XRrMC","z2v0","AMvpDeG","rvjsEhG","wgDUwNq","t1LjB2C","zfDVCMTLCKC","Eg90BNa","EhHSChm","B2LUDfjLywm","qKn1veq","vxj3sve","r01lqu4","x3DHAxq","Cej6AwG","vwjXv0m","z2v0u3rVCMe","B25dBg9Zzq","Aw9Ul2PZB24","q0Xpu0LorW","zufJAW","zgvSzxrL","D3jPDgvvAw4","B2vcy0K","vu9wqxC","y3vYDMfSDwu","uNDTwvO","AwrmyNG","C3PStvy","x2rLyNvN","BMnLq2XVC2u","y3vYC29Y","wvHHzxK","Ahr0Chm6","BxHRwwG","vKHyvMC","y29UBMvJDeu","r25Az2S","CMvJzxzPzwq","tfr5Dum","zw5HyMXLqxu","Cuz0uxu","Fdz8mhW0","wxbqvNK","qMP5B1y","BgLTAxq","CM92AwrLigi","z1rPBwvVDxq","tMHYrxe","CgfNzwHPzgu","A3jxAuC","yMrFzgLK","CNjlt0O","swDTqvu","tuTJCNu","uKfzDNy","CMvHzhLtDge","DNDQr2u","CMTLCKDSB2i","D24GCMvHC28","mZq2mti1DgrIsfPV","BeHHBMrSzxi","y29UBMvJDa","wgHuEKq","ywr2yw5Jzq","vg5huKu","twTluhC","ELDurfu","B2nRzxrtDwm","veDgthy","y2zkAwi","AvbLDMO","y3vYC29Yx24","D3jtAge","tgryANK","q1Lgs2m","ignVzgu6ia","v1fZAhy","yKHqrhO","AxnrB1nnzxm","BwLZzq","vNHfuw8","Be5ZwMW","DKXsBxO","zNjVBuj5Dgu","z1jKEum","t2T0wxe","sM5esgy","zevPre4","r0zqDgS","ywrKrxzLBNq","C29YDa","B2zbDLi","Ae1LC3nHz2u","uwX0C0C","CwLAuee","C2LnuvC","ywXty29Wzq","Axnby2TdBgu","C3bSAxq","vLLQu2q","q0v5wwW","Dev2zw50","zw5NDgG","yLr2wKK","sNn3t2S","ywnRtxnNswq","tevQqLa","q0TpBg4","AwDHDg9Yt24","A3fSAK0","zxj2AwnL","zMLXqKy","zwn5rNC","z1PrtwK","Bu92sum","tgf3DKC","BMvJDa","tg5bsNq","DMvUDa","BwLUAvbYB2C","tKDyDxC","vePKC0C","r2zJvNq","jMPZy2fSBgi","AxfJvfC","y3rqtNO","D3jPDgu","reiGzMfPBgu","C0nVDw50zxi","BMnAte4","z2u6ia","y3jLyxrLrxi","Cw9Zx18","C3rLBMvYCW","CLbouKW","Ag1OtMC","zwvnCxO","tw9KDwXL","uLH6AMW","rerUrhO","Efvjtvy","rLnSyuy","B25tDgfYDfi","uefcEgK","CvP2Bg8","AMvJDfn0B3i","yvngCNu","qLPhz1a","qMPotLO","zMX1C2HfEha","z3r3yM8","DgDzyuO","x194x21Zz18","Dfjbuwe","BMz2t3G","CwTAyLO","BwHOueq","sxD2ufG","AgDIvLK","zNjVBNrPzxi","ywnRx2nVzgu","yu9xtxG","u1bwtuS","zvvYBa","zv90Aw1LB3u","EhbVBw0","DgvZDa","yw1L","y09xuMG","quXm","De1HBMfNzxi","yu5xEeq","tgf5DK0","AfHUyMe","zw50tgLZDgu","z2j4DgO","ndeXndu1zLH2BKfu","B2XKvMvYC2K","BNrbBMrvCgq","BwLVChq","q3vZDg9Trxi","tM5suvG","tuHYzwy","zNDZxZeUmc4","tND0Cfu","A2nAuMy","tg9JAW","yMT6rNi","sej3EuK","suj0DeC","ywrKq291BNq","yNvMzMvYzwq","CuDxB08","ChHfA1u","uKrlC2i","mtCYmJKXnxnfBMfWsW","B25TzxnZywC","x2DLBMvYyxq","qw1VDw50","u1rYC2y","vhrHDvm","z29SDLy","B2jQzwn0u3q","v0fiuNK","Bgvky20","nhWW","twPRBKy","EgTXuxe","tMnsz2i","DhHQELy","AwrI","ywXSB2nvBNm","rNHbrve","AxnbCNjHEq","DgLLCKPtt04","uvPsuM4","qvvHzfm","yNbACue","offJBM1Nzq","EKLhBhK","yuztCuO","BwvZC2fNztO","A3rNtgq","CMvZB2X2zq","Ew1kqxK","BwHetLC","zv9ZDwnJzxm","B3bLCNr5tMe","uKDytfm","u2PhAxO","wgPqvK4","B2zM","B3bLBIa","v2LUzg93","Cgrut3O","x3jLBw92zvC","ELH2zuK","AxnrB1nby2S","wLjvENG","D1fmy2u","BNruCMLLC0m","EgXKqKy","v2LTsLm","C0jbrgG","EKjXsge","Dg9iyxnO","y3jLyxrLrwW","BMXiu3O","sMHzDw4","D1Dty3e","B2rAtwu","Dw5KzwzPBMu","C3vPz2W","vxbKyxrLq28","DhjHBNnHy3q","uhvhufy","rwn3BNK","r216Dwq","v2vIu29JA2u","yw1LoIa","CMvUDevUzha","vu5nBfC","q1rlrg8","BuTiAhq","uLLXtLy","ANj4EMO","y3jLyxrLtwu","q0TvC0O","B2DpvNe","CKDiAg4","rKjuswq","ig1LC3nHz2u","quHKq2S","AgrnvK0","rgzUtNe","CgjICdi","CNfusKy","AgLNAa","uxn5DKi","CMfUzg9T","veTgteG","CwHpC1q","Dw5RBM93BIa","ueDyseW","v2HitNa","AvH3uwW","v1n0zeO","zw1tEwe","BezSDxnO","Bwv0Ag9K","ENLvCeu","s1rfyu8","Aw9U","CMvTB3zLq2G","Ahr0Ca","qu5Jq2O","z3zzt28","AMjtuKe","BwfUDwfSihi","z2vjBMzVu3K","r3vyA1q","zKfvzuq","tLfxwKW","tNr4De4","vNrNyvy","BMfTzq","rufNvgu","ueDwqNO","x29WDgLVBNm","B25Uzwn0Aw4","DezeA2m","CvfUtfe","CMfTzq","B3vsywy","wuj2y04","Au50zgK","t3bLBKv2zw4","su5tvefova","rvjst1i","Bwf4twvZC2e","B1rwwuK","uMnIuhy","CLfdzvi","A2nSDu4","A1n0yxr1C0m","EM1MuhC","wLnUywG","D05NELO","sufpC2m","EhHWsu8","y2HLy2TdDxi","B25pCgvU","shfAB1u","sxLvvhG","Bu1ZzgC","vgjpv3i","wxPcD2q","zgnqrvK","Cgj2wfC","rNLgrwS","CMvZzxrdB3u","BMLLtNe","wKD5qLy","q2rzANu","z2vY","D2zfALi","yMPxvwS","zuPosKe","s1LItgi","n3WXFdb8nG","D2vI","tKfusvzfx0u","q3r3EKi","wfPPy3i","y3vYCMvUDeK","mxW0Fdb8mNW","ihn1y2nLC3m","yxv0BW","tKHtzxi","ENHNthe","twLcwKy","DhjPzxm","BfzwCuO","Aw5L","BMvLzf9Hy2S","y0jHuwO","rLLhthK","ru5vrLq","wenLCKO","Dg9cExrLC0i","s1HWCwm","sMDSquW","wu5vA3a","vxv2zwu","r1vbDKO","v2r1wNq","EMnMBwu","zw5fDMvUDa","wKDvB3m","AfLVv2q","zMzMzG","ww1zBhG","t1feA0q","zgvIDwC","Dgv4DfbHEwW","t1bftG","yxbmt1i","B3jpBMXPBMu","Euj0vg0","yxbWBhK","AKThyui","yxnJCMLWDa","x2fKzfDZtgK","Cw9Z","CxvKte4","C2XPy2u","EwvZwKC","B3jL","zfPjAMm","C2v0","yM9Jufa","tu5Zt2i","vuvQs3O","y0fPuxG","y2HLy2Tszwe","Cw5sBvq","CMvXDwLYzwq","yvnTrKW","z2v0t3DUuhi","uhbtAMe","zw5XDwv1zq","wMjntNC","u3rYyxrLz3K","A2vAquS","BvLTyLm","shDXyxO","zMTxBfm","DxbNCMfKzw4","v1vAwLK","D2LSBfjLy28","tfPNCMq","Dw5ZAwDUzwq","mhW3FdL8mNW","vxPQsxK","tfLtt3C","y29SBM8","tKDgDLy","vvrrAue","mxWYFdn8nhW","tfzPA0m","AejHBgW","x2nSzwfYugK","q0jPANq","u2vXsuq","yMfSrxzLBNq","B25VCgvU","zw1PDa","wMnYvwG","ysbTDxn0igi","wwLxDKu","CK9rtvO","EwHqsg0","Bg1or1m","B0T1AK8","DxjS","A1j4EfO","CxjTtNy","venTrxy","q2jkt2S","C0vfzvK","zuXsBva","B3jLtMfTzxm","BhjPz1e","z0PTBgq","yuXQswq","su9urxa","v0f4EgW","yu1bCem","y29UBMvJDfm","sM9Oq2e","B1nUDvC","DgfYz2v0","r0DOyLa","Be9hv1a","B25tDg9Wsw0","zhbrsgu","BKDhD2O","AenSB3nLrxy","t0zdrLi","zLvivxy","B2HHsKe","ntu4otaXzMDxC0Du","qK9LBxu","y2HMvMm","rhLxzeG","ELrWtuy","rKTzz3u","C2vYDMLJzs0","ohWXmhWZFdu","AgLzyui","C29Tzq","EwTis3e","CfbStfi","sefgBw0","t0rPBhu","BMCGDxjSoIa","sNrZquC","A1zHwwu","seTvufm","AxnAzxjV","B2zMBgLUzq","sLHkCfq","tgvmvKW","zuztzei","nde0otC4yNDAAMTL","ywnOzwqSihC","y2HHCKnVzgu","Chv0","zwPXy1G","A3LAA1u","u2XIz3G","y2HnyxHdB3u","mxnHuw9ODW","BwvKAwf0zwW","AfvOBwG","qxjyAeG","vfLREeW","B3jRig9MzMW","sgHWvxe","CxvrD0i","C2vUzf9Hy2S","AevMzLe","CuPusu4","zfLuu1O","thPjCve","q3vZDg9Tq2W","C2nYAxb0","vgzRCgO","yNvMzMvY","wg5dq0y","Ec1TC2CTCw8","Aw5JBhvKzxm","wxnNu1y","AejNvhm","zMzmAw5L","yvj0tuS","zw5JB2rLrNi","DeLK","EwfIuMu","s2DkAfa","wMvXqLq","rKLmrv9ot1q","CMvWBgfJzui","ANrztLe","x29UtwvZC2e","A3z5ugy","yw1Lu3bHy2u","DvnWzeq","B25szwnLAxy","zxjHDg9Y","AM9PBG","z2v0qwXS","zNjVBujPDhm","u1fMBNm","CgLUz0LUDgu","D2P6ELa","B3v0sw50zxi","EwjmBwC","EuHyCg8","wxjMt0y","ywThqwi","zxHWB3j0CW","tNPwAKS","zK5ywMC","x2n1CNnVCKy","zgrjrcWGzgu","zvbyEg4","ihjLy29UBMu","vKzPzg0","x3bPBMDmB3m","AxjLza","C2vYDMvYvgK","CNnVCL9Uyw0","r3DAthq","DhbizwfKzxi"];return qo=function(){return t},qo()}var Sv=Object[B(1602)+B(526)],Av=Object[B(1412)+B(1231)+B(894)],fh=(t,e)=>function(){return t&&(e=(0,t[{yWTQc:function(o,c){return o(c)}}.yWTQc(Av,t)[0]])(t=0)),e},Iv=(t,e)=>{let r=B,i={icmRR:function(c,u,f,x){return c(u,f,x)}};for(var o in e)i[r(1753)](Sv,t,o,{get:e[o],enumerable:!0})};function Tv(){return ah||(ah=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Cv(){let t=B;return ch||(ch=[IDBCursor.prototype[t(1067)],IDBCursor.prototype[t(1937)],IDBCursor.prototype[t(1937)+t(1979)+"ey"]])}function Rv(t){let e=B,r={iMXvy:e(807)+e(1230)+"s",qQnLQ:"ping_onc"+e(1168)+"t",Hxslk:function(o,c){return o(c)},WqzDc:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let u=e,f={SqIkb:"success",PGVBz:function(_){return _()},OlGZF:u(958),mkzrB:r[u(1588)],kRxxZ:r[u(1315)],dPDHf:function(_,S){return r.Hxslk(_,S)}},x=()=>{let _=u;t[_(744)+_(1178)+"ner"](f[_(498)],p),t[_(744)+_(1178)+_(757)](_(1802),m)},p=()=>{let _=u;o(Mt(t[_(901)])),f[_(1311)](x)},m=()=>{let _=u,S={nlHSz:function(y,v){return y(v)},KpyTx:f[_(1570)],DEWsi:f[_(640)],HSaed:f[_(1449)],jkalm:f[_(498)]};if(_(1952)==="wWptJ"){let y={DyWdH:function(I,R){return I(R)},weCXg:S[_(1892)],XkBRm:_(807)+_(1230)+"s",fSxlO:S[_(636)]};this[_(1435)+"ngTimer"](),this[_(802)+_(1050)+"Id"]=_0xa6bfa4(this[_(365)].bind(this),this[_(1312)].pingInterval);let v=()=>{let I=_;y[I(1478)](_0x35e4c3,y.weCXg),this[I(1235)](y.XkBRm,v),this[I(1235)](y.fSxlO,A)},A=()=>{let I=_;S[I(1251)](_0x54e56f,S.KpyTx),this[I(1235)](S[I(874)],v),this[I(1235)](S[I(636)],A)};this.on(S[_(874)],v),this.on(S[_(636)],A),this[_(365)]()}else f[_(662)](c,t[_(1802)]),x()};t["addEvent"+u(776)](u(397),p),t[u(1093)+u(776)](u(1802),m)});return i[e(555)](o=>{r[e(1785)](o,IDBCursor)&&Cd.set(o,t)}).catch(()=>{}),Ho[e(1403)](i,t),i}function kv(t){let e=B,r={oKWXe:e(1612),wiWup:e(1802),qkZbZ:function(o){return o()},Ecwny:function(o){return o()},bjDKz:function(o,c){return o(c)},NWwum:e(1816)+"or"};if(Go.has(t))return;let i=new Promise((o,c)=>{let u=e,f={qrlYc:function(_){return r[N(1159)](_)},jOpAT:function(_){return r[N(1260)](_)},JfdjE:function(_,S){return r[N(585)](_,S)},ElhkK:r.NWwum},x=()=>{let _=N;t[_(744)+_(1178)+"ner"](r[_(1883)],p),t[_(744)+_(1178)+_(757)](r[_(1759)],m),t[_(744)+"entListener"]("abort",m)},p=()=>{let _=N;f[_(1654)](o),f[_(1585)](x)},m=()=>{let _=N;f.JfdjE(c,t[_(1802)]||new DOMException(_(1816)+"or",f[_(953)])),f[_(1585)](x)};t[u(1093)+u(776)](r.oKWXe,p),t["addEvent"+u(776)](r.wiWup,m),t[u(1093)+u(776)](u(496),m)});Go[e(1403)](t,i)}function Dv(t){jo=t(jo)}function N(t,e){t=t-351;let r=qo(),i=r[t];if(N.UHQXqH===void 0){var o=function(x){let p="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",m="",_="";for(let S=0,y,v,A=0;v=x.charAt(A++);~v&&(y=S%4?y*64+v:v,S++%4)?m+=String.fromCharCode(255&y>>(-2*S&6)):0)v=p.indexOf(v);for(let S=0,y=m.length;S<y;S++)_+="%"+("00"+m.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(_)};N.myurEc=o,N.wzzCMr={},N.UHQXqH=!0}let c=r[0],u=t+c,f=N.wzzCMr[u];return f?i=f:(i=N.myurEc(i),N.wzzCMr[u]=i),i}function Pv(t){let e=B,r={amiky:function(i,o){return i(o)},BQirs:function(i,o){return i===o},TiteA:function(i,o){return i in o},kUwwj:e(1206)+"oreNames",tUYfW:function(i){return i()}};return r[e(1663)](t,IDBDatabase[e(713)+"e"][e(1258)+e(1296)])&&!r[e(568)](r.kUwwj,IDBTransaction[e(713)+"e"])?function(i,...o){let c=e,u=t[c(486)](r[c(846)](Ji,this),i,...o);return Td[c(1403)](u,i[c(1094)]?i[c(1094)]():[i]),Mt(u)}:r[e(1586)](Cv)[e(1525)](t)?function(...i){let o=e;return t.apply(Ji(this),i),Mt(Cd[o(1004)](this))}:function(...i){return Mt(t[e(1393)](Ji(this),i))}}function Ov(t){let e=B,r={kkgrK:e(1599),ZeqBT:function(i,o){return i(o)},BCuTD:function(i,o){return i instanceof o},EZFZM:function(i,o){return i(o)},gWoio:function(i){return i()}};return typeof t===r[e(444)]?r[e(1534)](Pv,t):(r[e(1013)](t,IDBTransaction)&&r[e(655)](kv,t),xh(t,r[e(420)](Tv))?new Proxy(t,jo):t)}function Mt(t){let e=B,r={SnrYn:function(o,c){return o instanceof c},Mksho:function(o,c){return o(c)},rsUld:function(o,c){return o!==c}};if(r[e(613)](t,IDBRequest))return r[e(1682)](Rv,t);if(Fo[e(1608)](t))return Fo[e(1004)](t);let i=Ov(t);return r.rsUld(i,t)&&(Fo[e(1403)](t,i),Ho[e(1403)](i,t)),i}var xh,ah,ch,Cd,Go,Td,Fo,Ho,jo,Ji,dh=fh({"node_modules/idb/build/wrap-idb-value.js"(){let t=B,e={znmGW:t(991),oSnuW:function(r,i){return r instanceof i},vRJGU:t(628),dYTSZ:function(r,i){return r===i},AaSPS:t(1206)+t(1455),JAkFZ:t(1056),naWEv:function(r,i){return r(i)},luxAj:function(r,i){return r===i},YHDOW:t(1623),FcQTV:function(r,i){return r in i}};xh=(r,i)=>i[t(1484)](o=>r instanceof o),Cd=new WeakMap,Go=new WeakMap,Td=new WeakMap,Fo=new WeakMap,Ho=new WeakMap,jo={get(r,i,o){let c=t,u={RxszZ:c(1052),qNNOq:e[c(433)]};if(e[c(1464)](r,IDBTransaction)){if(i===e.vRJGU)return Go.get(r);if(e.dYTSZ(i,e[c(359)]))return r[c(1206)+c(1455)]||Td[c(1004)](r);if(i==="store"){if(e[c(1517)](e[c(1732)],e[c(1732)]))return o[c(1206)+c(1455)][1]?void 0:o[c(1206)+c(1401)](o["objectSt"+c(1455)][0]);this[c(677)+"er"]&&_0x4d4e49[c(744)+c(1178)+c(757)](u[c(1647)],this[c(1573)+c(920)]),this._isBrowser&&_0x41f1f4[c(744)+c(1178)+c(757)](u[c(1674)],this["_handleP"+c(1756)]),this[c(1662)]()}}return e[c(1867)](Mt,r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return e.oSnuW(r,IDBTransaction)&&(e[o(759)](i,e.vRJGU)||e[o(1517)](i,e[o(1982)]))?!0:e[o(381)](i,r)}},Ji=r=>Ho[t(1004)](r)}}),hh={};Iv(hh,{deleteDB:()=>Nv,openDB:()=>Lv,unwrap:()=>Ji,wrap:()=>Mt});function Lv(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let u=B,f={CkqAM:function(m,_,S,y,v){return m(_,S,y,v)},lzUUo:function(m,_){return m===_},YsgSV:"close",osVLc:u(1421)+"eeded"},x=indexedDB[u(527)](t,e),p=Mt(x);return i&&x[u(1093)+u(776)](f[u(761)],m=>{let _=u;f[_(547)](i,Mt(x.result),m[_(1181)+"on"],m[_(596)+"on"],Mt(x["transact"+_(1296)]))}),r&&x[u(1093)+u(776)](u(830),()=>r()),p.then(m=>{let _=u,S={pBzih:function(y,v,A){return y(v,A)}};if(f[_(482)](_(1844),"efBlR"))return new _0x48a3d0(y=>{let v=_;S[v(1017)](_0x3c4a1c,y,this[v(976)+v(566)+"e"](_0x55b29e))});c&&m["addEvent"+_(776)](f[_(1526)],()=>c()),o&&m[_(1093)+_(776)](_(644)+_(1614),()=>o())}).catch(()=>{}),p}function Nv(t,{blocked:e}={}){let r=B,i={AFvBX:r(830),ultBJ:function(c,u){return c(u)}},o=indexedDB[r(902)+r(1620)](t);return e&&o[r(1093)+r(776)](i.AFvBX,()=>e()),i.ultBJ(Mt,o)[r(555)](()=>{})}function uh(t,e){let r=B,i={JtsAG:function(x,p){return x!==p},xpomm:r(1492),qNepH:r(1786),bTvZI:"readwrite",krWiG:r(1693),UTQiA:function(x,p){return x instanceof p},XOlGm:function(x,p){return x in p},NcRgb:function(x,p){return x===p},mMxpT:function(x,p){return x!==p}};if(!(i[r(1431)](t,IDBDatabase)&&!i[r(396)](e,t)&&i[r(1212)](typeof e,r(504))))return;if(Uo[r(1004)](e))return Uo[r(1004)](e);let o=e[r(1617)](/FromIndex$/,""),c=i.mMxpT(e,o),u=gh[r(1525)](o);if(!i[r(396)](o,(c?IDBIndex:IDBObjectStore)[r(713)+"e"])||!(u||ph[r(1525)](o)))return;let f=async function(x,...p){let m=r;if(i[m(1490)](i[m(1169)],i.qNepH)){let _=this[m(1258)+m(1296)](x,u?i[m(1107)]:i[m(1053)]),S=_[m(1623)];return c&&(S=S[m(1590)](p[m(709)]())),(await Promise[m(1938)]([S[o](...p),u&&_[m(628)]]))[0]}else return this[m(918)][m(1059)+"te"]};return Uo[r(1403)](e,f),f}var ph,gh,Uo,Mv=fh({"node_modules/idb/build/index.js"(){let t=B,e={hdaEq:t(771)+t(1209),cHczp:function(o,c){return o(c)},HMPRU:function(o){return o()},rrKOJ:t(1004),oYgfJ:t(1723),XDZKE:t(1545),Amzky:t(1577)+"ys",BFqav:"count",MzHAI:function(o){return o()},IMPAd:"put",JrqZO:t(1865),XjPVN:t(1737)},r=e[t(453)].split("|"),i=0;for(;;){switch(r[i++]){case"0":e[t(586)](Dv,o=>({...o,get:(c,u,f)=>uh(c,u)||o[t(1004)](c,u,f),has:(c,u)=>!!uh(c,u)||o[t(1608)](c,u)}));continue;case"1":e.HMPRU(dh);continue;case"2":ph=[e[t(1055)],e.oYgfJ,e.XDZKE,e[t(755)],e.BFqav];continue;case"3":e.MzHAI(dh);continue;case"4":Uo=new Map;continue;case"5":gh=[e[t(580)],e[t(1589)],t(1024),e[t(1234)]];continue}break}}}),Bv={idb:function(t){let e=B;t.exports=Promise[e(1227)]()[e(555)](()=>(Mv(),hh)).then(function(r){return r})}},lh={};function Nt(t){let e=B,r={IwxJX:e(1943)+"0"},i=r.IwxJX[e(1102)]("|"),o=0;for(;;){switch(i[o++]){case"0":return u[e(1555)];case"1":var c=lh[t];continue;case"2":var u=lh[t]={exports:{}};continue;case"3":if(c!==void 0)return c[e(1555)];continue;case"4":Bv[t](u,u[e(1555)],Nt);continue}break}}Nt.d=(t,e)=>{let r=N;for(var i in e)Nt.o(e,i)&&!Nt.o(t,i)&&Object[r(1602)+"operty"](t,i,{enumerable:!0,get:e[i]})},Nt.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),(()=>{let t=B,e={TbOWr:function(r,i){return r!==i},iDLxb:t(1748),WUZZY:t(1255)+"d"};Nt.r=r=>{let i=t;e[i(1339)](e[i(735)],e[i(735)])?(ve[i(1622)]=_0x25704d,ve[i(1833)]=_0x1e59b8,ve[i(626)]=_0xccdb41):(e[i(1422)]!=typeof Symbol&&Symbol[i(1956)+"Tag"]&&Object[i(1602)+i(526)](r,Symbol[i(1956)+i(904)],{value:i(1141)}),Object[i(1602)+"operty"](r,i(688)+"le",{value:!0}))}})();var Re={};(()=>{let t=B,e={bOHbt:function(a,n){return a+n},lqltO:function(a,n){return a+n},xxvty:function(a,n){return a+n},UCLgC:function(a,n){return a+n},wmzId:function(a,n){return a*n},PGXHL:function(a,n){return a(n)},Hwqaz:function(a){return a()},YGuYr:function(a,n){return a!==n},LdXjy:t(697),zBqHa:function(a,n){return a(n)},TCePl:function(a,n){return a!==n},jrxzj:t(1914),YpPVy:t(1467),OksxE:function(a,n){return a(n)},XqDWo:function(a,n,s){return a(n,s)},WktLW:function(a,n){return a+n},WIRsI:t(1888),eLRmP:t(1384),oyIln:t(529)+t(529)+t(529)+"00000000",iWatc:function(a,n){return a(n)},jcyRV:t(1813)+"3",NFEYF:function(a,n){return a<n},LOJSC:function(a,n,s,d){return a(n,s,d)},FkxsR:function(a,n){return a+n},xHDDY:function(a,n){return a>n},rKfog:function(a,n){return a>n},YBvcN:function(a,n){return a!==n},aFSqJ:function(a,n){return a-n},fAUeD:t(509),EESCI:t(1923),CDbDJ:function(a,n){return a===n},VqnmZ:function(a,n){return a<n},aYtvW:t(1301),uRodJ:function(a,n){return a!==n},OMYfd:function(a,n,s){return a(n,s)},NOgqM:function(a,n){return a!==n},rDIky:"SYMil",iPevj:function(a,n,s){return a(n,s)},qLXJj:function(a,n){return a>>>n},TvcXn:function(a,n,s){return a(n,s)},sgAHw:function(a,n){return a&n},fNtoA:function(a,n){return a===n},jOIfh:t(1705)+t(1410)+t(716)+t(1977),WcVdd:function(a,n){return a===n},VWaTQ:"Missing "+t(1410)+t(716)+"value",BZGgP:function(a,n,s){return a(n,s)},CTKDo:function(a,n){return a<=n},dUBEj:function(a,n){return a>=n},naARn:function(a,n,s){return a(n,s)},YsAqV:t(562),KNnCJ:t(538),aQcye:function(a,n,s){return a(n,s)},kIrZd:function(a,n){return a!==n},kPQAk:function(a,n,s){return a(n,s)},UBvnk:function(a){return a()},SJbnv:function(a,n,s){return a(n,s)},dXGKe:function(a,n,s){return a(n,s)},pIhLF:function(a,n,s){return a(n,s)},sNjUq:t(1154),cbslW:t(1581),ufXAD:function(a,n,s){return a(n,s)},RYqNV:t(591),YiWvE:t(1903),LIuMF:t(1147),tFRxt:function(a,n,s){return a(n,s)},vGNVf:function(a,n){return a!==n},iFedf:t(1070),nGGwj:function(a,n,s){return a(n,s)},mhHsx:function(a,n,s){return a(n,s)},BdBvX:t(1516),NorWH:function(a,n){return a(n)},TnGRE:function(a,n){return a(n)},miopt:function(a,n){return a>>>n},FgcSz:t(1466),qZvlo:function(a,n){return a(n)},FMkyS:function(a,n,s){return a(n,s)},MQhkO:function(a,n){return a(n)},nBOZM:function(a,n,s){return a(n,s)},Lxpwg:function(a,n){return a===n},AauPa:t(1705)+t(1410)+t(716)+t(1437),gvYOo:function(a,n){return a===n},MtUzT:t(1705)+t(1410)+" field: LogID",ymJAy:t(1705)+t(1410)+t(716)+t(843),aOgbY:function(a,n){return a===n},sJIGR:t(1705)+t(1410)+t(716)+t(1293),BVBTX:t(1376),pKixr:function(a,n){return a(n)},rRZlL:function(a,n){return a&n},nYRWX:function(a,n){return a(n)},rPNRL:t(964)+t(1606)+t(683),NtxtN:function(a,n){return a>>n},LHwfx:function(a,n){return a===n},Gqgir:function(a,n){return a+n},bJpMl:t(1802),rqTJF:function(a,n,s){return a(n,s)},vMasK:t(661),uRuAW:function(a,n){return a*n},vFABd:function(a,n){return a>n},TCmEv:function(a,n,s){return a(n,s)},Hoibm:function(a,n,s){return a(n,s)},YDgcv:t(1662),BvGjP:function(a,n){return a!==n},WAxxl:function(a,n){return a+n},EQInz:t(510)+t(1794),Ejuxy:function(a,n){return a|n},eJNJA:function(a,n){return a>>n},xhUVc:"vDXMv",IgrQU:function(a,n,s){return a(n,s)},qFtQu:function(a,n){return a+n},CzbkB:function(a,n,s){return a(n,s)},BtpPA:function(a,n){return a(n)},GYUQt:function(a,n){return a===n},OtUJS:function(a,n){return a(n)},AAQaM:function(a,n){return a===n},RwmYZ:function(a,n){return a>=n},HyTdl:function(a,n){return a+n},szlMV:function(a,n){return a+n},aUNjk:function(a,n){return a<<n},YRTPP:function(a,n){return a&n},QltsG:function(a,n){return a<n},kQTYX:function(a,n){return a==n},RAYvv:function(a,n){return a>=n},vOvLB:function(a,n){return a+n},nAsYd:function(a,n){return a&n},iHIqv:function(a,n){return a|n},YVweZ:function(a,n){return a<<n},HTjdT:function(a,n){return a&n},OkXBP:function(a,n){return a<<n},cdNyY:function(a,n){return a&n},EDuic:function(a,n){return a>=n},FsSvb:function(a,n){return a(n)},WvGvv:function(a,n){return a==n},JjYlZ:function(a,n){return a+n},QbljU:t(899),MjknF:t(1704),FhJHX:function(a,n){return a+n},BvkjI:function(a,n){return a+n},gPlmM:function(a,n){return a!==n},llear:function(a,n){return a&n},VXVNz:function(a,n){return a&n},nyTwf:function(a,n){return a&n},NYHVS:function(a,n){return a&n},GgYMu:function(a,n){return a>>n},aBYNU:function(a,n){return a+n},Fqyjw:function(a,n){return a&n},Lxxpz:function(a,n){return a!==n},bHPDz:"nhvMN",zydUJ:function(a,n){return a<=n},jKGaB:function(a,n){return a<n},wrSha:function(a,n,s){return a(n,s)},CETsp:function(a,n){return a<n},KkLAv:function(a,n){return a<n},LayvM:function(a,n){return a===n},aOWMx:t(1834),kIsoV:"VJbwn",UNyzi:function(a,n){return a|n},aiqwO:function(a,n){return a&n},ojXfi:function(a,n){return a>>n},xwQlF:function(a,n){return a|n},NGFvV:function(a,n){return a>>n},yXZLB:function(a,n){return a|n},JtAAg:function(a,n){return a&n},Tfkpj:function(a,n,s){return a(n,s)},rmipa:function(a,n){return a(n)},mMsdg:function(a,n){return a&n},BYgVD:function(a,n,s){return a(n,s)},ouRaf:"always",aDejx:t(397),qyqGh:function(a,n,s){return a(n,s)},QWTcy:function(a,n,s,d){return a(n,s,d)},mKHht:function(a,n){return a(n)},LzIqQ:function(a,n){return a&n},HdWQa:function(a,n){return a===n},ldhTP:t(1959),iYnWS:"hnsoI",qIbqC:function(a,n){return a(n)},ERRxx:function(a,n){return a<<n},FYGLy:t(1158),mkter:function(a,n){return a&n},YDtyW:function(a,n){return a&n},aSFru:function(a,n){return a&n},LnAJt:function(a,n){return a(n)},jKwTp:function(a,n){return a&n},fkWlS:function(a,n){return a<<n},QaVVZ:function(a,n){return a&n},BBGQG:function(a,n){return a(n)},GwZLt:function(a,n){return a&n},CKUsJ:function(a,n){return a&n},MgbTL:function(a,n){return a===n},oiCbU:t(765),MidqP:t(557),bFpIK:function(a,n){return a&n},IwvPX:function(a,n){return a(n)},ZbMNw:function(a,n){return a<<n},BlhAN:function(a,n){return a&n},shJOp:function(a,n){return a<<n},Wpute:function(a,n){return a|n},lmNGS:function(a,n){return a<<n},PyYFB:function(a,n){return a>>>n},VjSpe:function(a,n){return a===n},qgdHh:function(a,n){return a<n},EWVbV:function(a,n){return a<n},RxSeN:function(a,n,s){return a(n,s)},MUOgd:function(a,n){return a|n},ldWdE:function(a,n){return a&n},thBVc:function(a,n){return a!==n},ecyFw:function(a,n){return a&n},VYjSd:function(a,n){return a+n},zEjox:function(a,n){return a&n},glkFg:function(a,n){return a>>>n},XhTzD:function(a,n){return a+n},XwkEK:function(a,n){return a|n},UHPzu:function(a,n){return a+n},RSKhS:function(a,n){return a(n)},DeRic:function(a,n){return a|n},Oupgw:function(a,n){return a|n},clbiP:function(a,n){return a&n},YmYlx:function(a,n){return a|n},PeHWO:function(a,n){return a|n},dwSmC:function(a,n){return a<<n},MHref:function(a,n){return a|n},GiNek:function(a,n){return a<<n},TCZxR:function(a,n){return a<<n},zzTmD:function(a,n){return a|n},bocPP:function(a,n){return a<<n},NGXuw:function(a,n){return a<<n},emSya:function(a,n){return a<<n},DEgff:t(933),DWIju:"XJNCL",nieNq:"EYPcP",lVVqJ:function(a,n){return a>>>n},VkQhp:function(a,n){return a|n},ohPHu:function(a,n){return a|n},CcgUX:function(a,n){return a|n},NbNjY:function(a,n){return a<<n},EYOXY:function(a,n){return a|n},kvyPf:"SSoSN",MBydM:"ZePqN",MCywo:function(a,n){return a&n},ebCrU:function(a,n){return a>>>n},KadgJ:function(a,n){return a>>>n},STIbS:function(a,n){return a>>>n},CYFKc:function(a,n){return a>>>n},UKYDy:function(a,n){return a>>>n},yesZG:"done",WhHNp:t(1206)+t(1455),kfxpr:function(a,n){return a!==n},cqbjN:"iHiKC",CBijt:function(a,n){return a(n)},NQLEB:function(a,n){return a>=n},HJczn:function(a,n){return a>=n},ufzgp:function(a,n){return a%n},cJBGO:function(a,n){return a|n},GFPtk:t(1789),MXIHp:function(a,n){return a+n},mKVwe:function(a,n){return a>>>n},WRHqy:function(a,n){return a&n},HJErN:function(a,n){return a+n},VhJZE:function(a,n){return a+n},DcXen:function(a,n){return a>>>n},OQspE:function(a,n){return a+n},XiFoz:function(a,n){return a|n},zfPmg:function(a,n){return a<<n},fDDSY:function(a,n){return a|n},uabvC:function(a,n){return a!==n},woXdT:function(a,n){return a===n},gXiAu:function(a,n){return a>>>n},DVMmo:function(a,n){return a===n},vwjGe:function(a,n){return a===n},UkPLo:function(a,n){return a===n},dPyXC:function(a,n){return a+n},pzZSm:function(a,n){return a&n},gbxtj:function(a,n){return a>>>n},RcbPv:function(a,n){return a&n},ijbSw:function(a,n){return a>>>n},LQBIQ:function(a,n){return a&n},ODilu:function(a,n){return a&n},svVHu:function(a,n){return a&n},UiMsr:function(a,n){return a>>>n},RJruQ:function(a,n){return a&n},rsqow:function(a,n){return a&n},NINnd:t(1890)+"2|4",hdMVM:"MAX_RETRIES_ERROR",kjnUF:t(900)+t(1322),fjdYX:t(987)+"OR",wNgzZ:t(559)+"NG_ERROR",VFidm:t(1355)+t(848),LTyuC:t(378)+"3",wGpIn:t(1615),ngQHH:function(a,n){return a>>>n},zyUpE:function(a,n){return a&n},STrsf:function(a,n){return a|n},qrmNv:function(a,n){return a===n},XCerJ:function(a,n){return a+n},HVMae:function(a,n){return a+n},RwJaD:function(a,n){return a>n},YahVV:function(a,n){return a>>n},gtzPK:function(a,n){return a===n},mRgnd:"aDydu",ruIRb:function(a,n){return a>=n},oLLof:function(a,n){return a===n},SjGiz:t(925),ejqcX:function(a,n){return a>n},iHJrO:function(a,n){return a!==n},ykHKq:"LDZZr",qBtGk:function(a,n){return a instanceof n},JTghJ:t(1885)+"d error.",suigl:function(a,n){return a===n},zITgq:function(a,n){return a===n},kcZRf:function(a,n){return a<n},VgRxy:function(a,n){return a|n},KTEaO:function(a,n){return a>>n},iIgQO:function(a,n){return a|n},WNkDz:function(a,n){return a&n},Slbgx:function(a,n){return a&n},knUUP:function(a,n){return a!==n},WndNo:t(1736),ZJLzH:t(1757)+"4",FqyAr:t(1204),TqHjw:function(a,n){return a===n},BAbmM:t(1980),bStRS:function(a,n,s){return a(n,s)},UWDTc:function(a,n,s){return a(n,s)},TJdsG:t(527),dZIjc:t(878),FhiFY:t(1515),MKcru:function(a,n,s){return a(n,s)},BjyoV:function(a,n){return a>=n},ybLmg:function(a,n){return a<n},OjMuR:function(a,n){return a&n},WegKM:function(a,n){return a|n},GuXkT:function(a,n){return a|n},ezILn:function(a,n,s){return a(n,s)},TYkxL:function(a,n){return a||n},xxNZp:t(1926),QsyvB:function(a,n){return a+n},KXpqc:function(a,n){return a!==n},JdMDS:"WNJZt",UkmAI:function(a,n){return a>n},XahjF:function(a,n){return a+n},jtYNQ:function(a,n){return a(n)},FKYgu:t(1896),kZILK:t(1095),aLjId:function(a,n){return a||n},mFmLx:t(1255)+"d",ZyaFb:t(470),mSngp:t(1278),ZNFDU:function(a,n){return a!=n},SBoqK:function(a,n){return a+n},owATj:function(a,n){return a<n},ZRUzx:function(a,n){return a===n},IEJeT:function(a,n){return a&n},tCxvA:function(a,n){return a*n},qnRmT:function(a,n){return a>n},cBaQj:t(1679),kqljM:function(a,n){return a!==n},SGkeW:"qPPiQ",noyaw:t(1487),DftPL:function(a,n){return a|n},AMDGW:function(a,n){return a&n},dEiDN:function(a,n){return a|n},NhrEq:function(a,n){return a<<n},bLxxO:function(a,n){return a>=n},zOVEo:function(a,n){return a-n},LZgEM:function(a,n){return a<<n},mXFbz:function(a,n){return a&n},AIZtr:function(a,n){return a<n},akGAb:function(a,n){return a<n},uSIAd:function(a,n){return a|n},unGuX:function(a,n){return a&n},VGtAa:function(a,n){return a&n},stoRz:function(a,n){return a+n},tFDkc:function(a,n){return a&n},hDMbm:function(a,n){return a&n},dNVSQ:function(a,n){return a>>n},KYbLb:function(a,n){return a&n},JwLgn:function(a,n){return a>>n},oyjvS:function(a,n){return a|n},QZDat:function(a,n){return a|n},uWyQG:function(a,n){return a&n},YXaey:function(a,n){return a-n},LMDRN:function(a,n){return a==n},LfLiX:t(504),zmfPw:t(490),AUKZq:function(a,n){return a!=n},yabRe:function(a,n){return a==n},SafPA:t(1944)+t(1603)+t(728),jWxzQ:t(883),YThAU:t(730),mJAYv:function(a,n){return a>=n},AnoaO:function(a,n,s){return a(n,s)},yBTxw:function(a,n){return a!==n},pbvXW:"PzsXl",xAxuT:t(1520),XfNos:"text/jav"+t(1395),DmpwF:function(a,n){return a+n},eeMqz:t(1298),SqwQW:t(1127)+t(361)+t(1218)+"P",sbgZY:function(a,n){return a(n)},JohCa:t(1286)+t(493),kyZkU:"ping_once_timeout",WQshv:t(958),VGuxq:function(a,n){return a===n},wcVFb:t(821),lvfao:t(1139),NJWAM:"WAXvT",ZfyuP:t(595),TubWJ:t(1817),qbizf:"zWobe",hdjFL:function(a,n){return a||n},PpSja:function(a,n){return a+n},KRJmY:t(1014),ohaJA:function(a,n){return a|n},KcWff:function(a,n){return a+n},DWMAM:function(a,n){return a|n},friBw:function(a,n){return a+n},qYHGR:t(1806),sbRuE:t(430),eFSdB:function(a,n){return a||n},rSEkN:t(1482)+t(445)+t(1045),UoGlh:function(a,n,s,d){return a(n,s,d)},mjycD:t(843),xxlps:t(1906),iXwQl:t(1028),HhvJl:function(a,n,s,d){return a(n,s,d)},jeOtH:t(891)+t(1114),NnRQX:function(a,n){return a===n},aMApC:t(1971),leJcm:function(a,n){return a!==n},pNPDz:t(427),nepkl:t(1857),iFNUz:function(a,n){return a||n},lHAHX:t(1397),NPyee:t(1735)+"id",XCrAt:function(a,n,s){return a(n,s)},idkMP:t(961),nKqqq:t(1362),RXzjl:function(a,n){return a(n)},pyKeI:function(a,n){return a-n},ArXhH:function(a,n){return a!==n},WduZt:t(1987),QGTAM:function(a,n){return a===n},XZVqx:function(a,n){return a===n},lWLYC:"UIaPM",TfplF:function(a,n,s,d){return a(n,s,d)},FxAEQ:"x_frontier_qos",AHdCk:t(1935)+"er_qos_ack",xUIMV:function(a,n,s,d){return a(n,s,d)},zjLLj:"x_fronti"+t(449)+"k",MfdiM:function(a,n,s){return a(n,s)},auRod:function(a,n,s,d){return a(n,s,d)},dcPEY:t(1368),apLOR:t(720),rViqe:function(a,n){return a&&n},aRtMK:t(670),Ukzep:function(a,n){return a||n},dEoBO:t(1164),xBLPY:function(a){return a()},fNXZg:function(a){return a()},Uuvee:function(a,n){return a+n},QSkYN:function(a,n){return a===n},xhoxt:"stMzc",UHsvA:function(a,n){return a(n)},hdwrS:function(a,n){return a instanceof n},Rtpbh:t(414)+t(1021),xqIsE:function(a){return a()},CdYju:function(a,n){return a!==n},NZNbG:"afhXm",XCBsM:function(a,n){return a>n},JddCx:function(a,n){return a&n},PmHtl:function(a,n){return a|n},uRqHq:function(a,n){return a||n},tYgEr:function(a,n){return a(n)},aumNi:function(a,n){return a+n},fXxJj:function(a,n){return a+n},AqnQU:t(827)+t(1877)+t(1134),nMbWU:t(442),redqX:function(a,n){return a||n},Pejqy:t(1642),RYwrm:function(a,n){return a>n},uEShs:"integer too large",qudLN:function(a,n){return a&n},reico:function(a,n){return a<n},GuHoZ:function(a,n){return a>>>n},AKpGA:function(a,n){return a<<n},SPVMK:t(373)+"1",ZLEnh:function(a,n){return a+n},XkkWp:function(a,n,s,d){return a(n,s,d)},LeLVL:function(a,n){return a+n},TOPXs:function(a,n){return a|n},IYllz:function(a,n){return a+n},zcfme:function(a,n){return a+n},AUadS:function(a,n){return a|n},iNtdi:function(a,n){return a<<n},tgYaJ:function(a,n){return a+n},CXmuU:function(a,n){return a!==n},WStdJ:t(1733),GCrNk:function(a,n){return a+n},TNRjU:function(a,n){return a&n},ekCGy:function(a,n){return a>>>n},VdNMk:function(a,n){return a+n},rQCeR:function(a,n){return a>>>n},YrfOF:function(a,n){return a+n},OFCFR:function(a,n){return a+n},rGHhn:function(a,n){return a>>>n},Vehzf:function(a,n){return a>>>n},vDAFe:function(a,n){return a&n},gJmld:t(379),fiqBF:function(a,n){return a+n},JRNVl:function(a,n){return a===n},mODYq:t(1456),lKZZy:function(a,n){return a&n},QCiRG:function(a,n){return a===n},oGWIH:"FcaMJ",yxdtK:function(a,n){return a<n},NIlUw:function(a,n){return a<n},Gmzud:function(a,n){return a&n},MgEMB:function(a,n){return a>>>n},FIffO:function(a,n){return a<n},LikFT:function(a,n){return a>n},DfTrL:function(a,n){return a+n},hUhmh:t(1426)+t(1648)+"|6|3|5",WXIgE:function(a,n,s,d){return a(n,s,d)},satpW:function(a,n,s,d){return a(n,s,d)},WgoRB:function(a,n,s,d){return a(n,s,d)},VxEQo:"name",ogOVq:function(a,n){return a(n)},uZmMb:function(a,n){return a<n},ZnMJs:function(a,n,s){return a(n,s)},RqYgj:function(a,n,s){return a(n,s)},idLbx:t(1371),ockCT:t(386),mgLgS:"cursor_f"+t(1718),ziYYD:t(1075)+t(1171),XGgSj:t(1809)+t(1798),UvAyY:t(1321),jztmu:t(614),PGPDo:function(a,n,s,d){return a(n,s,d)},KwVrR:"setdb",ZOsrH:t(1699),gWLge:t(561)+"r",GfcVt:function(a,n,s){return a(n,s)},XrOJN:t(1988),OumPQ:t(1790),NKTmd:t(676),cgACD:function(a,n){return a&n},hYoWd:function(a,n){return a>>>n},LfHlK:function(a,n){return a>>>n},bdhBS:function(a,n){return a||n},HkKhn:function(a,n){return a>n},xqyru:function(a,n){return a+n},EAgTe:function(a,n,s,d){return a(n,s,d)},issSk:t(862),wOglM:function(a,n,s,d){return a(n,s,d)},OplLw:t(1935)+"er_msgid",PqErE:function(a,n,s){return a(n,s)},rikOR:t(1524)+"s",fWExx:t(855)+t(1566)+"e",YJqnI:function(a,n,s){return a(n,s)},vAyGc:"x-msg-cu"+t(985)+"ue",ONnws:function(a){return a()},bJEgw:function(a){return a()},cYHUL:function(a,n){return a<n},qiZPA:t(732),yLRla:t(1541),LrPba:function(a){return a()},sEEeY:function(a){return a()},WimJS:function(a){return a()},WHGMu:function(a,n,s){return a(n,s)},tTyyI:t(1527),UHcyo:function(a,n){return a&&n},EEHZl:function(a){return a()},KLZeR:function(a){return a()},KpnJk:function(a,n,s){return a(n,s)},UEjKz:function(a,n){return a instanceof n},ivrKZ:function(a,n,s,d){return a(n,s,d)},VQiAs:t(1361),xkqQq:function(a,n){return a===n},QZRRn:function(a,n){return a===n},mDlXY:t(1643),dgTdD:t(815),lNsZl:function(a,n,s){return a(n,s)},MtBuJ:function(a,n,s){return a(n,s)},pPlLR:function(a,n){return a!==n},oFjVL:"bye",bpZqA:function(a,n){return a!==n},VxBdy:t(400),TZbQu:function(a,n){return a(n)},UbqWC:function(a,n,s){return a(n,s)},yJftH:function(a,n,s){return a(n,s)},hiYaB:function(a,n,s){return a(n,s)},ZHUAK:function(a,n){return a(n)},xxpIO:t(606),Ipgwr:function(a,n){return a===n},sztfZ:function(a,n,s){return a(n,s)},CtwzB:function(a,n){return a!==n},CQqtu:t(1364),LawvG:"arraybuf"+t(648),qxOWy:t(1279),MzCMG:function(a,n){return a/n},TgnfX:function(a,n){return a(n)},rFRNu:t(745)+"rovide w"+t(955)+t(1605)+t(431)+"tructor "+t(1670)+t(927),JZFNX:function(a,n,s){return a(n,s)},zNXwJ:t(423)+"t",rrAMP:"online",KfVsh:t(1052),Fqlba:t(991),fUHUv:t(1494),vXjXW:function(a,n){return a!==n},fMRvq:t(1036),TGFLv:t(1842),MGcuy:t(959),hQPds:t(1939),CwJmw:t(1631)+"d",zxgLq:t(745)+t(1049)+t(1559)+"viceID o"+t(1882),Qloug:function(a,n){return a==n},NwtpU:t(1599),NzVjK:function(a,n,s){return a(n,s)},ouUcv:t(1354),LfxRk:t(1187)+"0",ZAXLa:"ping_onc"+t(1230)+"s",rOQMZ:t(844),mVIxr:function(a,n){return a===n},ETQie:t(1656),gbNUx:function(a,n){return a||n},MdqWn:t(523),ZazDp:function(a,n){return a-n},MNsOb:function(a,n,s){return a(n,s)},cnPKi:t(1633)+t(382)+t(1684)+"4",CbJOk:function(a,n){return a>>>n},xooHF:function(a,n){return a|n},hXnba:function(a,n){return a&n},PuGPV:function(a,n){return a|n},GFtia:function(a,n){return a<n},Ifuld:function(a,n){return a>>>n},skGyG:t(1619),OFQVP:"FRONTIER>",NtJdO:function(a,n){return a>n},LEjBP:t(419),mxkYh:"WIgJL",OiimX:function(a,n){return a===n},QQoBq:function(a,n){return a>>>n},DNUGc:function(a,n){return a===n},fJnET:t(828),RJfMZ:t(714),ENdNO:t(520)+t(1784)+t(423)+t(785)+"ver",oDGwQ:t(1946)+" try rec"+t(1313)+"g",ameEe:function(a,n){return a+n},wkSIx:"dHNLD",xAatT:function(a,n){return a|n},Zogvo:function(a,n){return a&n},TVxAC:function(a,n){return a+n},FBTId:function(a,n){return a<<n},zGxfN:function(a,n){return a&n},keZAK:function(a,n){return a&n},wfEjR:"giXOB",TwPEC:t(1432)+"0",VaAgN:t(1359)+"3",tRAQa:t(1535)+t(799),nmuwN:t(1702),RrWPi:function(a,n,s){return a(n,s)},LRfQk:function(a,n){return a+n},CIcas:"MvGBD",svUXh:t(949),FSlaF:function(a,n){return a!==n},RDKsb:t(890),chfVc:"XLWPv",NyioE:function(a,n){return a+n},HBwyI:"4|2|5|3|"+t(1353),Gxolj:function(a,n){return a===n},keaWA:function(a,n){return a===n},fgaFM:t(910)+t(425)+"ce not i"+t(645)+"ed",nRFAb:t(745)+t(1796)+t(519)+t(1887)+t(1442)+t(1852)+t(483)+" arraybu"+t(992),ZJnUl:function(a,n){return a!=n},CKOln:function(a,n){return a instanceof n},YzBwd:function(a,n){return a instanceof n},BaknD:function(a,n){return a(n)},LYSOw:function(a,n){return a||n},KdTBm:function(a,n){return a instanceof n},zTpMF:function(a,n){return a instanceof n},LVikC:function(a,n){return a===n},VHXVg:t(1414),wLrqN:function(a,n){return a||n},HhpUq:t(1302)+t(604)+t(870),HGhgA:function(a,n){return a<n},IBttG:function(a,n){return a+n},jBZGP:function(a,n){return a-n},CXqkX:function(a,n){return a+n},hPOOg:function(a,n){return a<n},xtwXL:function(a,n){return a<n},nDbTx:function(a,n){return a!==n},ePXxn:t(492),mhDNW:function(a,n){return a!==n},XnCCF:t(1099),JrXmp:t(1832)+"1",YcOwa:function(a,n){return a!==n},VnfTV:t(893),ycmNI:t(1476),NfHaT:"vZxht",bjWUk:function(a,n,s){return a(n,s)},aSmFL:function(a,n){return a<=n},HTrrw:function(a,n){return a<n},UNMlW:function(a,n){return a|n},KovOh:function(a,n){return a<<n},ZFODt:function(a,n){return a-n},pGYzB:function(a,n){return a|n},Xukjm:function(a,n){return a<<n},FKgFo:t(1771),JqFVz:"eOxlp",jjiYj:"\0\0\0\0\0\0\0\0",XtMwI:function(a,n){return a*n},xuFNz:function(a,n){return a===n},wjzzP:t(1237),mllgN:function(a,n){return a!=n},OHnTy:function(a,n){return a===n},oWqwH:function(a,n){return a!=n},ObBeB:t(903)+t(1009)+"lobalScope",LVgzY:function(a,n){return a!=n},XgnZt:t(405),fUUOB:function(a,n){return a!=n},BmuJD:function(a,n){return a===n},YGxGa:t(736)+t(1061)+t(1100),ZGUos:"ServiceW"+t(1837)+"balScope",uxjtq:function(a,n){return a!=n},KgJhP:function(a,n){return a!=n},DEZQw:function(a,n){return a===n},eglhS:function(a,n){return a!=n},IOTEp:function(a,n){return a!=n},submS:function(a,n){return a!=n},VtgaV:function(a,n,s){return a(n,s)},IqZkU:t(1156)+t(1136)};Nt.r(Re),Nt.d(Re,{FWS:()=>Jp,CustomErrorEvent:()=>$d,createCloseEvent:()=>xt,ReconnectEvent:()=>Kd,createErrorEvent:()=>at,decodedFrame:()=>Qt,createOpenEvent:()=>Qd,CustomCloseEvent:()=>Vd,createReconnectEvent:()=>ca,FrontierMessageEvent:()=>Zd,encodeFrame:()=>Bt,createMessageEvent:()=>Xd,OpenEvent:()=>Jd,ErrorCode:()=>tn,Event:()=>Qn,MessageEvent:()=>Yd});let r="";function i(a=""){let n=t,s="02",d=""+Date[n(930)](),l=r||(r=x(a)),h=Math[n(1283)]().toString(16)[n(1399)](-6);return e.bOHbt(e[n(503)](e[n(1607)](s,d),l),h)}function o(){let a=t;return e[a(533)](e.wmzId(1e4,Date[a(930)]()),Math.floor(e.wmzId(1e4,Math[a(1283)]())))}function c(a){let n=t,s={kVaYe:function(d,l){return e[N(1287)](d,l)},sBADh:function(d){return e[N(1419)](d)}};if(e[n(970)](e[n(1077)],n(1252)))return e.lqltO(e[n(1248)](Array,8)[n(1544)]("0"),parseInt(a,10).toString(2))[n(1399)](-8);_0x2ed55b(QLBhDK[n(1491)](_0x4d24d1,_0x25f1c2[n(901)])),QLBhDK[n(1247)](_0x37f526)}function u(a){let n=t,s={skQuO:function(d,l,h){return d(l,h)}};if(e[n(760)](e[n(1269)],e[n(1046)]))return(e[n(1901)](Array,4).join("0")+e[n(605)](parseInt,a,2)[n(1956)](16))[n(1399)](-4);this["_clearPi"+n(1975)](),this[n(1440)](n(807)+"e_success",n(397)),this[n(802)+n(1050)+"Id"]=s.skQuO(_0x8cf7b7,this[n(365)][n(805)](this),_0x7ab4c1)}function f(a){let n=t,s=a.split(/\./)[n(494)](h=>c(h)),d=[];return d[0]=e.PGXHL(u,e[n(533)](s[0],s[1])),d[1]=e[n(1901)](u,e[n(791)](s[2],s[3])),[n(1888),e.WIRsI,e[n(499)],"0000",e[n(499)],e[n(1454)],d[0],d[1]][n(1544)]("")}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}/[n(1170)](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(1170)](a);return s?f(a):d?e[n(1287)](p,a):e.oyIln}function p(a){let n=t,s={BkhOl:e[n(610)],Cblsw:function(T,O){return e.NFEYF(T,O)},lXhLd:function(T,O,M,V){return e.LOJSC(T,O,M,V)},RrGDq:function(T,O){return e[n(1829)](T,O)}},d="",l=[],h=0,w=0,b=!0,g=e[n(499)];if(e[n(1688)](a[n(741)]("::"),-1)){let T=a[n(1102)]("::");for(let M=0;e[n(1722)](M,T[n(690)]);M++){let V=T[M];if(e.rKfog(V.indexOf(":"),0)){let j=V[n(1102)](":");b&&(h=j.length),w+=j.length;for(let ee=0;ee<j[n(690)];ee++)if(e[n(1318)](4,j[ee][n(690)])){let Pe=g[n(480)+"g"](0,e[n(1224)](4,j[ee].length)),Ze=Pe[n(1725)](j[ee]);l[n(1680)](Ze)}else l.push(j[ee]);b=!1}else if(e[n(970)](e[n(1305)],n(1196))){if(e[n(760)](4,V[n(690)]))if(e[n(525)]!==n(1160)){let j=g.substring(0,e[n(1224)](4,V[n(690)])),ee=j[n(1725)](V);l[n(1680)](ee)}else this._qosDB?.[n(1662)](),this[n(626)]=void 0;else l[n(1680)](V);b&&(h+=1),w+=1,b=!1}else e[n(627)](_0x3218e1,this[n(967)+n(429)+n(1858)]),this[n(967)+n(429)+n(1858)]=null}let O="";for(let M=0;e[n(1722)](M,8-w);M++)O=O[n(1725)](g);for(let M=0;e[n(1722)](M,l[n(690)]);M++)e[n(1972)](M,h)&&(d=d.concat(O)),d=d[n(1725)](l[M]);return d}{let T=a.split(":");for(let O=0;e.VqnmZ(O,T[n(690)]);O++){let M=T[O];if(e[n(970)](4,T[O].length))if(e.CDbDJ(e[n(1925)],e[n(1925)])){let V=g[n(480)+"g"](0,4-T[O][n(690)]),j=V.concat(M);d=d[n(1725)](j)}else{let V=s.BkhOl.split("|"),j=0;for(;;){switch(V[j++]){case"0":if(s.Cblsw(_0x2a3af7[n(690)],40))return s[n(395)](_0x157cf1,_0x1596c2,_0x6785a6,_0x3c1dc1)+_0x4208a2;continue;case"1":if(_0x2ed368.write)return s[n(767)](_0x19dbb1.write(_0xe96bcb,_0x9db88d),_0x4d16a2);continue;case"2":if(_0x808540.utf8Write)return s[n(767)](_0x438684.utf8Write(_0x5e0335,_0x7f8dc8),_0x23dd60);continue;case"3":return s[n(767)](s[n(395)](_0x5324c0,_0x4ba953,_0x34024a,_0x7d3397),_0x572436);case"4":if(!_0x278d7b)return _0x202a35;continue}break}}else d=d[n(1725)](M)}return d}}function m(a,n){let s=t,d=a[s(1977)];e[s(1715)](void 0,d)&&(e[s(605)](he,n,10),e[s(738)](G,n,d));let l=a[s(1669)];e[s(467)](void 0,l)&&(e[s(1646)]!=="SYMil"?_0x52f911[s(1915)](_0x2a3029):(e[s(1074)](he,n,18),G(n,l)))}function _(a){let n=t,s={};e:for(;!e[n(1287)]($,a);){let d=e[n(1287)](xe,a);switch(e[n(1576)](d,3)){case 0:break e;case 1:s[n(1977)]=e.TvcXn(L,a,xe(a));break;case 2:s[n(1669)]=L(a,e[n(1901)](xe,a));break;default:R(a,e[n(371)](7,d))}}if(e[n(537)](void 0,s[n(1977)]))throw new Error(e[n(1653)]);if(e.WcVdd(void 0,s.value))throw new Error(e[n(975)]);return s}function S(a){let n=t,s=k();return e[n(1151)](y,a,s),z(s)}function y(a,n){let s=t,d={JoRvv:function(Ze,zt,is){return e[N(751)](Ze,zt,is)}},l=a[s(1437)];l!==void 0&&(e[s(424)]!==e.KNnCJ?(e[s(834)](he,n,8),e[s(1074)](ft,n,l)):this[s(1235)](_0x4f832d,_0x3b7e9b));let h=a[s(998)];e[s(467)](void 0,h)&&(e[s(1151)](he,n,16),ft(n,h));let w=a[s(843)];e[s(1891)](void 0,w)&&(he(n,24),ft(n,e.PGXHL(D,w)));let b=a[s(1293)];e[s(1891)](void 0,b)&&(e.BZGgP(he,n,32),e.kPQAk(ft,n,D(b)));let g=a[s(469)];if(g!==void 0)for(let Ze of g){he(n,42);let zt=e[s(694)](k);m(Ze,zt),e[s(1698)](he,n,zt[s(1048)]),e[s(410)](K,n,zt),e[s(1248)](P,zt)}let T=a.payloadEncoding;e[s(467)](void 0,T)&&(e[s(410)](he,n,50),e.dXGKe(G,n,T));let O=a["payloadT"+s(715)];e.YGuYr(void 0,O)&&(e[s(1074)](he,n,58),e[s(1758)](G,n,O));let M=a.payload;if(M!==void 0)if(e.kIrZd(e[s(696)],e[s(432)]))he(n,66),e[s(731)](he,n,M.length),oe(n,M);else return this[s(478)+"ndpointT"+s(957)+"t"];let V=a[s(553)];if(V!==void 0)if(e[s(1268)]!==e[s(1443)])e.XqDWo(he,n,74),e.kPQAk(G,n,V);else{if(e[s(1266)](_0x3298a7,-_0x3430f0))return _0x48e4d9;if(e[s(579)](e.lqltO(_0x349d1c,1),_0x5e4224))return _0x4234d1}let j=a[s(1565)+s(912)];if(j!==void 0)if(e[s(1972)](e[s(1965)],s(1601))){this._clearPingTimer(),this[s(802)+"gTimeoutId"]=d.JoRvv(_0x321731,this[s(365)][s(805)](this),this[s(1312)]["pingInte"+s(1665)]);return}else e[s(1691)](he,n,82),e[s(751)](G,n,j);let ee=a[s(1701)];e[s(1708)](void 0,ee)&&(e.iFedf==="zWTDU"?(he(n,90),e[s(1470)](G,n,ee)):(this[s(1440)](s(933),_0x18d7b7),this[s(1200)+"e"]&&this[s(1200)+"e"](_0x5a8e11)));let Pe=a[s(1625)+"e"];e.YGuYr(void 0,Pe)&&(e[s(1691)](he,n,96),e[s(421)](ft,n,e[s(1287)](D,Pe)))}function v(a){let n=t,s={mhdsz:function(d,l){return e.sgAHw(d,l)},tKahi:function(d,l){return d&l},jUujj:function(d,l){return e[N(1576)](d,l)},rJpJO:function(d,l){return e[N(1576)](d,l)}};return e.BdBvX!=="qJTIN"?_0x30df4f[n(472)+n(522)](s[n(972)](255,this[n(542)]),s.tKahi(s[n(954)](this.low,8),255),s[n(972)](s.jUujj(this[n(542)],16),255),s[n(1868)](this[n(542)],24),s[n(631)](255,this[n(1281)]),s[n(954)](this[n(1281)],8)&255,s[n(972)](s[n(954)](this[n(1281)],16),255),s.jUujj(this[n(1281)],24)):e[n(1579)](A,F(a))}function A(a){let n=t,s={};e:for(;!e[n(1068)]($,a);){let d=e[n(1248)](xe,a);switch(e.miopt(d,3)){case 0:break e;case 1:s[n(1437)]=vt(a,!0);break;case 2:s[n(998)]=vt(a,!0);break;case 3:s.service=xe(a);break;case 4:s[n(1293)]=e[n(627)](xe,a);break;case 5:{if(e.YBvcN(e[n(1826)],e.FgcSz))return 0;{let l=e[n(627)](I,a);(s[n(469)]||(s[n(469)]=[]))[n(1680)](e[n(1148)](_,a)),a[n(1048)]=l;break}}case 6:s.payloadEncoding=L(a,e[n(1287)](xe,a));break;case 7:s[n(1841)+n(715)]=e[n(1596)](L,a,xe(a));break;case 8:s[n(439)]=ie(a,e[n(388)](xe,a));break;case 9:s[n(553)]=e[n(1808)](L,a,e.TnGRE(xe,a));break;case 10:s[n(1565)+"ming"]=L(a,xe(a));break;case 11:s[n(1701)]=L(a,e[n(1287)](xe,a));break;case 12:s.frameType=xe(a);break;default:e[n(887)](R,a,e.sgAHw(7,d))}}if(e[n(1969)](void 0,s.SeqID))throw new Error(e.AauPa);if(e[n(1300)](void 0,s[n(998)]))throw new Error(e.MtUzT);if(s[n(843)]===void 0)throw new Error(e[n(1228)]);if(e[n(1609)](void 0,s[n(1293)]))throw new Error(e[n(1637)]);return s}function I(a){let n=t;if(e[n(1918)]==="YNUkp"){let s=e[n(675)](xe,a),d=a[n(1048)];return a.limit=a[n(866)]+s,d}else this[n(638)]=!0,this._connect()}function R(a,n){let s=t;switch(n){case 0:for(;e[s(877)](128,e.qZvlo(se,a)););break;case 2:e[s(887)](Y,a,e[s(916)](xe,a));break;case 5:Y(a,4);break;case 1:e[s(887)](Y,a,8);break;default:throw new Error(e.WktLW(e[s(1138)],n))}}function D(a){let n=t;return a|=0,{low:a,high:e[n(1307)](a,31),unsigned:e[n(579)](a,0)}}let E=[];function k(){let a=t,n=E[a(390)]();return n?(n[a(866)]=n[a(1048)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function P(a){E.push(a)}function F(a){return{bytes:a,offset:0,limit:a.length}}function z(a){let n=t,s=a.bytes,d=a.limit;return e.LHwfx(s[n(690)],d)?s:s[n(1917)](0,d)}function Y(a,n){let s=t;if(e[s(372)](a[s(866)],n)>a[s(1048)])throw new Error(s(674)+s(1794));a[s(866)]+=n}function $(a){return a[t(866)]>=a.limit}function te(a,n){let s=t,d={aNGuT:e[s(583)],GpTOQ:function(l,h,w){return e[s(1280)](l,h,w)}};if(s(888)===e[s(1851)])this.emit(d.aNGuT,d.GpTOQ(_0x113bf2,d.aNGuT,{message:this[s(1768)+s(873)+s(1989)](_0x3a803f)}));else{let l=a[s(1869)],h=a[s(866)],w=a[s(1048)],b=h+n;if(e[s(1966)](b,l.length)){let g=new Uint8Array(e[s(1818)](2,b));g[s(1403)](l),a[s(1869)]=g}return a.offset=b,e.vFABd(b,w)&&(a.limit=b),h}}function Z(a,n){let s=t,d={xsvCW:function(l,h,w){return e[N(1451)](l,h,w)},CSrNm:e[s(583)],vkVue:function(l,h,w){return e[s(880)](l,h,w)},fXtgi:e[s(1726)]};if(e[s(693)](s(1133),s(1133))){let l=d[s(1922)](_0xbad3bf,s(1802),{message:this[s(1768)+s(873)+s(1989)](_0x8cdabc)});this[s(1440)](d[s(854)],l);let h=d[s(1807)](_0x41c0cc,d[s(641)],{reason:this[s(1768)+s(873)+s(1989)](_0x43aef7)});this[s(1440)](d[s(641)],h)}else{let l=a.offset;if(e[s(1966)](e[s(1460)](l,n),a[s(1048)]))throw new Error(e[s(450)]);return a[s(866)]+=n,l}}function ie(a,n){let s=t;if(e.xhUVc!=="jCQuy"){let d=e[s(366)](Z,a,n);return a[s(1869)].subarray(d,e[s(1044)](d,n))}else _0x5c5eec[_0x3c581e++]=e.Ejuxy(e[s(1351)](_0xac1755,18)&7,240),_0x2d82a1[_0x5e776c++]=e[s(371)](e[s(1351)](_0x32f2f1,12),63)|128}function oe(a,n){let s=t,d=e[s(952)](te,a,n.length);a[s(1869)][s(1403)](n,d)}function L(a,n){let s=t,d=e[s(1596)](Z,a,n),l=String[s(472)+s(522)],h=a[s(1869)],w="\uFFFD",b="";for(let g=0;e[s(1722)](g,n);g++){let T=h[g+d],O,M,V,j;if(e.GYUQt(e[s(371)](128,T),0))b+=e.OtUJS(l,T);else if(e[s(375)](224&T,192))e.RwmYZ(e[s(791)](g,1),n)?b+=w:(O=h[e.HyTdl(e[s(1031)](g,d),1)],e[s(693)](192&O,128)?b+=w:(j=e[s(719)](e[s(1574)](e[s(932)](31,T),6),63&O),e[s(1097)](j,128)?b+=w:(b+=e.BtpPA(l,j),g++)));else if(e[s(1936)](e[s(932)](240,T),224))e[s(1058)](g+2,n)?b+=w:(O=h[e[s(1031)](g,d)+1],M=h[e[s(981)](g+d,2)],e[s(467)](e.nAsYd(e[s(1787)](O,e[s(459)](M,8)),49344),32896)?b+=w:(j=e.iHIqv(e[s(459)](e.HTjdT(15,T),12)|e[s(860)](e[s(784)](63,O),6),e[s(371)](63,M)),j<2048||e.EDuic(j,55296)&&j<=57343?b+=w:(b+=e[s(479)](l,j),g+=2)));else if(e.WvGvv(248&T,240))if(e.EDuic(e[s(725)](g,3),n))b+=w;else if(e[s(546)]!==e[s(1210)])O=h[g+d+1],M=h[e.UCLgC(e[s(1659)](g,d),2)],V=h[e[s(725)](e[s(1866)](g,d),3)],e.gPlmM(e[s(468)](e[s(719)](O,e[s(860)](M,8))|V<<16,12632256),8421504)?b+=w:(j=e[s(1787)](e[s(719)](e.VXVNz(7,T)<<18,e[s(1574)](e[s(1928)](63,O),12))|e[s(1825)](63,M)<<6,e.llear(63,V)),e.QltsG(j,65536)||e[s(1966)](j,1114111)?b+=w:(j-=65536,b+=e[s(731)](l,e[s(791)](e.GgYMu(j,10),55296),e[s(1830)](e[s(1871)](1023,j),56320)),g+=3));else{let ee=e[s(1911)](_0x3ec32c,_0x5f1c27),Pe=_0xee7148[s(1048)];return _0xd3a577[s(1048)]=e.bOHbt(_0x315f26.offset,ee),Pe}else b+=w}return b}function G(a,n){let s=t,d=n[s(690)],l=0;for(let b=0;e[s(1097)](b,d);b++){if(e.Lxxpz(e[s(1081)],s(582)))return this[s(665)+s(573)][s(1795)]((T,O)=>(T+=O&&O[s(603)+"th"]||0,T),0)+(this[s(1751)]?this._ws["buffered"+s(1202)]:0);{let g=n[s(1500)+"At"](b);e.RwmYZ(g,55296)&&e[s(1812)](g,56319)&&e[s(1097)](b+1,d)&&(g=e.OkXBP(g,10)+n[s(1500)+"At"](++b)-56613888),l+=g<128?1:e[s(1722)](g,2048)?2:e.jKGaB(g,65536)?3:4}}e.wrSha(he,a,l);let h=e[s(1074)](te,a,l),w=a.bytes;for(let b=0;e[s(632)](b,d);b++){let g=n[s(1500)+"At"](b);g>=55296&&g<=56319&&b+1<d&&(g=e[s(1224)](e[s(996)](g<<10,n.charCodeAt(++b)),56613888)),e[s(1967)](g,128)?w[h++]=g:e[s(1176)](e[s(1165)],e[s(858)])?this.on(_0x14fd04,_0x3ea602):(g<2048?w[h++]=e[s(1931)](e[s(945)](e[s(1351)](g,6),31),192):(e.jKGaB(g,65536)?w[h++]=e[s(719)](e[s(945)](e.ojXfi(g,12),15),224):(w[h++]=e[s(1787)](e[s(1351)](g,18)&7,240),w[h++]=e[s(733)](e[s(1848)](e[s(1904)](g,12),63),128)),w[h++]=e[s(1430)](g,6)&63|128),w[h++]=e[s(377)](e[s(1593)](63,g),128))}}function K(a,n){let s=t,d=te(a,n[s(1048)]),l=a[s(1869)],h=n[s(1869)];for(let w=0,b=n[s(1048)];w<b;w++)l[w+d]=h[w]}function se(a){let n=t;return a.bytes[e[n(1521)](Z,a,1)]}function Ye(a,n){let s=t,d=e[s(366)](te,a,1);a[s(1869)][d]=n}function xe(a){let n=t,s=0,d=0,l;do l=e[n(867)](se,a),e[n(1967)](s,32)&&(d|=e.mMsdg(127,l)<<s),s+=7;while(128&l);return d}function he(a,n){let s=t;for(n>>>=0;n>=128;)e.BYgVD(Ye,a,e[s(719)](127&n,128)),n>>>=7;e.nGGwj(Ye,a,n)}function vt(a,n){let s=t,d={qEYrh:function(g,T){return g===T},iSbfu:function(g,T){return g===T},MSRZz:e[s(1317)],sXWGA:"auto",qLkNl:s(807)+s(1230)+"s",noZTj:e.aDejx,ohLTZ:function(g,T,O){return e.qyqGh(g,T,O)},vprtz:function(g,T,O,M){return e[s(1855)](g,T,O,M)},nxTEc:e[s(583)]},l=0,h=0,w=0,b;if(b=e[s(1267)](se,a),l=e.LzIqQ(127,b),128&b){if(e.HdWQa(e[s(1947)],e.iYnWS)){let{pingInterval:g,pingFrequency:T}=this._options;if((d[s(356)]("hi",_0x2c1802[s(1738)])&&d[s(392)](d.MSRZz,T)||d.sXWGA===T)&&(this[s(1435)+s(1975)](),this[s(1440)](d[s(698)],d.noZTj),this[s(802)+s(1050)+"Id"]=d.ohLTZ(_0x595e1b,this[s(365)][s(805)](this),g)),_0x56d444[s(1738)]==="hi")return;try{d[s(941)](_0x1ab3d9,this,_0x3dad9f,[_0x3378c2,_0x5de602,_0x466c63,_0x43888a,_0x28074b,_0x3bd39d])}catch(O){let M=d[s(1875)](_0x1780a6,d[s(458)],{message:O[s(933)],code:_0xce3d75[s(900)+s(1322)],error:O});this[s(548)+s(1707)+"ent"](M)}}else if(b=e.qIbqC(se,a),l|=e.ERRxx(e.llear(127,b),7),e[s(1848)](128,b)){if(e[s(1370)]!==e[s(1370)])return this[s(626)]?.[s(1403)]({message_id:_0x14e8ac,timestamp:_0x521e29});if(b=e[s(1579)](se,a),l|=e[s(1658)](127,b)<<14,e[s(1825)](128,b)&&(b=e.BtpPA(se,a),l|=e[s(822)](127,b)<<21,e[s(1814)](128,b)&&(b=e[s(1579)](se,a),h=e[s(1150)](127,b),128&b&&(b=e[s(1121)](se,a),h|=e.OkXBP(e.aiqwO(127,b),7),e[s(1872)](128,b)&&(b=e.iWatc(se,a),h|=e.fkWlS(e[s(1871)](127,b),14),e[s(1976)](128,b)&&(b=e[s(1600)](se,a),h|=e.GwZLt(127,b)<<21,e[s(1271)](128,b)))))))if(e[s(1940)](e.oiCbU,e[s(684)])){let g={VkMcB:function(T,O){return T(O)}};return function(T,...O){let M=s,V=_0x13c39d[M(486)](_0x5796a9(this),T,...O);return _0x1ad50e[M(1403)](V,T[M(1094)]?T[M(1094)]():[T]),g[M(1811)](_0x350034,V)}}else b=e[s(1068)](se,a),w=e[s(1848)](127,b),e.bFpIK(128,b)&&(b=e[s(1161)](se,a),w|=e[s(1415)](e[s(908)](127,b),7))}}return{low:e.UNyzi(l,e.shJOp(h,28)),high:e[s(465)](h>>>4,e[s(1740)](w,24)),unsigned:n}}function ft(a,n){let s=t,d=e.miopt(n[s(542)],0),l=e[s(1576)](e[s(1787)](n[s(542)]>>>28,e[s(1446)](n.high,4)),0),h=e[s(1820)](n.high,24),w=e.VjSpe(0,h)?e[s(375)](0,l)?e.NFEYF(d,16384)?d<128?1:2:e[s(1967)](d,2097152)?3:4:e[s(917)](l,16384)?l<128?5:6:e[s(1967)](l,2097152)?7:8:e.EWVbV(h,128)?9:10,b=e[s(774)](te,a,w),g=a[s(1869)];switch(w){case 10:g[b+9]=h>>>7&1;case 9:g[e[s(996)](b,8)]=e.YGuYr(9,w)?e[s(1584)](128,h):e[s(915)](127,h);case 8:g[e[s(1044)](b,7)]=e[s(1920)](8,w)?e[s(1584)](l>>>21,128):e[s(1576)](l,21)&127;case 7:g[e[s(981)](b,6)]=w!==7?e[s(1787)](e[s(1183)](l,14),128):e[s(1116)](e[s(1576)](l,14),127);case 6:g[e[s(1103)](b,5)]=e[s(1891)](6,w)?e[s(465)](e[s(1820)](l,7),128):l>>>7&127;case 5:g[e[s(1829)](b,4)]=e[s(892)](5,w)?e.Wpute(128,l):e[s(1150)](127,l);case 4:g[b+3]=e[s(1920)](4,w)?e.xwQlF(e[s(1820)](d,21),128):e.zEjox(e[s(1003)](d,21),127);case 3:g[e[s(1066)](b,2)]=e[s(1715)](3,w)?e.XwkEK(d>>>14,128):e[s(1518)](d>>>14,127);case 2:g[e.UHPzu(b,1)]=w!==2?e[s(1584)](d>>>7,128):d>>>7&127;case 1:g[b]=e.thBVc(1,w)?e[s(1931)](128,d):127&d}}function Qt(a){return v(a)}function Bt(a){return e[t(1801)](S,a)}let en=65536,Vr=e[t(402)],me=e.XtMwI(en,en),Ie=e[t(594)](me,me),Xn=e[t(514)](Ie,2),De=String[t(713)+"e"].charCodeAt;class fe{constructor(n,s,d){let l=t;this[l(812)]=!0,this.low=e.DeRic(0,n),this[l(1281)]=e.Oupgw(0,s),this[l(1425)]=!!d}static isLong(n){return n&&n[t(812)]===!0}static[t(1546)](n,s,d){return new fe(n,s,d)}static[t(1087)+"s"](n,s,d){let l=t;return d?fe["fromByte"+l(505)](n,s):fe[l(1087)+l(1907)](n,s)}static[t(1087)+t(505)](n,s){let d=t,l={mgLbF:function(h,w,b){return h(w,b)},eaahc:function(h,w){return h|w},LoPBu:function(h,w){return e[N(1690)](h,w)}};if(e[d(1969)]("ZSnah",d(1330)))return new fe(e[d(1385)](e[d(1919)](n[0],e[d(590)](n[1],8))|n[2]<<16,e[d(1740)](n[3],24)),e[d(1385)](e[d(1186)](e[d(377)](n[4],n[5]<<8),e[d(702)](n[6],16)),e[d(1629)](n[7],24)),s);hhXuEd.mgLbF(_0x12f2a4,_0x1b851e,hhXuEd[d(1655)](hhXuEd.LoPBu(127,_0x100c96),128)),_0x276d2>>>=7}static[t(1087)+t(1907)](n,s){let d=t;return new fe(e[d(1931)](e[d(982)](e[d(982)](n[4]<<24,n[5]<<16),e.bocPP(n[6],8)),n[7]),e[d(733)](e[d(982)](e[d(982)](e[d(1404)](n[0],24),e[d(1124)](n[1],16)),e[d(1291)](n[2],8)),n[3]),s)}static[t(1672)](n){let s=t;if(e.TCePl(e[s(619)],e[s(1345)]))return e.aOgbY(n,Vr)?Wd:new fe(e[s(1366)](e.VkQhp(e[s(618)](e.CcgUX(De[s(486)](n,0),e[s(956)](De[s(486)](n,1),8)),e[s(1574)](De[s(486)](n,2),16)),De[s(486)](n,3)<<24),0),(e.EYOXY(e[s(1587)](De[s(486)](n,4),De[s(486)](n,5)<<8),De[s(486)](n,6)<<16)|e[s(956)](De.call(n,7),24))>>>0,!0);if(!this[s(1751)])return;this._ws[s(744)+s(1178)+s(757)](s(527),this[s(513)]),this[s(1751)][s(744)+s(1178)+s(757)](e[s(1726)],this[s(446)]),this[s(1751)]["removeEventListe"+s(757)](e[s(756)],this._onMessage),this[s(1751)][s(744)+s(1178)+s(757)](e[s(583)],this._onError)}[t(1249)](){let n=t,s={xBvTh:function(d,l,h){return d(l,h)}};if(e[n(693)](e[n(1539)],e[n(608)]))return String[n(472)+"Code"](e[n(599)](255,this[n(542)]),e[n(1628)](this.low,8)&255,e[n(1854)](this[n(542)],16)&255,e[n(1366)](this[n(542)],24),e[n(822)](255,this[n(1281)]),e.STIbS(this[n(1281)],8)&255,e[n(877)](e[n(1078)](this.high,16),255),e[n(656)](this[n(1281)],24));{let d=this[n(999)+"tManager"]?.["getCurre"+n(362)+"nt"]();this[n(548)+n(1471)+n(769)](s[n(826)](_0xe10bbb,n(1662),{code:_0x18ede4.code,reason:n(1687)+n(1797)+"d, unkno"+n(1062)+"n, hostname: "+d})),this[n(999)+"tManager"]?.[n(811)+n(1863)+"fig"](),this["_pingLos"+n(1132)]?.[n(1344)+n(545)]();return}}static[t(411)+"er"](n,s=!0){let d=t;if(e[d(1933)](e.cqbjN,"iHiKC")){if(_0x65fcbe instanceof _0xf91a20){if(_0x4de3e7===irftOA[d(1400)])return _0x22f625[d(1004)](_0x361a94);if(irftOA[d(871)](_0x316f74,irftOA[d(1288)]))return _0x4fefda[d(1206)+"oreNames"]||_0x2750db[d(1004)](_0x212a98);if(irftOA[d(1972)](_0x56dc56,d(1623)))return _0x3b6ac8[d(1206)+"oreNames"][1]?void 0:_0x2ebe9b[d(1206)+d(1401)](_0x31c444[d(1206)+d(1455)][0])}return _0x4577f4(_0x46d987[_0x230574])}else{if(e[d(1436)](isNaN,n))return s?dp:Wd;if(s){if(e[d(922)](n,Ie))return lp}else{if(e[d(1266)](n,-Xn))return fp;if(e[d(750)](n+1,Xn))return up}return fe[d(1546)](e[d(746)](e[d(829)](n,me),0),e[d(678)](n/me,0),s)}}[t(1661)](){let n=t;if(e[n(1092)]!=="CpgQR")return this.unsigned?e.MXIHp(e[n(438)](this[n(1281)],0)*me,this[n(542)]>>>0):e.MXIHp(e[n(1818)](this[n(1281)],me),this.low>>>0);_0x3394dd(_0x5d8b8c,90),e[n(751)](_0x2b6c0c,_0x5645b2,_0x3426fd)}[t(1493)](){let n=t;return e[n(871)](0,this.high)&&e[n(1972)](0,this[n(542)])}[t(1865)](n){let s=t;fe[s(812)](n)||(n=fe[s(411)+"er"](n));let d=this[s(1281)]>>>16,l=65535&this[s(1281)],h=e[s(1854)](this.low,16),w=e[s(1338)](65535,this[s(542)]),b=e[s(1078)](n.high,16),g=e.WRHqy(65535,n[s(1281)]),T=e[s(1638)](n[s(542)],16),O=e[s(1518)](65535,n[s(542)]),M=0,V=0,j=0,ee=0;return ee+=e.HJErN(w,O),j+=e[s(656)](ee,16),ee&=65535,j+=e[s(1930)](h,T),V+=e.DcXen(j,16),j&=65535,V+=e.OQspE(l,g),M+=V>>>16,V&=65535,M+=e[s(913)](d,b),M&=65535,fe[s(1546)](e[s(682)](e[s(460)](j,16),ee),e[s(1860)](e[s(1404)](M,16),V),this.unsigned)}[t(792)](n){let s=t;return fe[s(812)](n)||(n=fe[s(411)+"er"](n)),e.uabvC(this[s(1425)],n.unsigned)&&e[s(692)](this[s(1281)]>>>31,1)&&e[s(1969)](e[s(535)](n.high,31),1)?!1:e[s(1729)](this[s(1281)],n[s(1281)])&&e[s(502)](this[s(542)],n[s(542)])}addOne(){let n=t;return e[n(758)](-1,this[n(542)])&&e[n(1060)](-1,this[n(1281)])?fe[n(1546)](0,0,this[n(1425)]):e[n(570)](-1,this.low)?fe[n(1546)](0,e[n(849)](this[n(1281)],1),this[n(1425)]):fe[n(1546)](this.low+1,this[n(1281)],this[n(1425)])}[t(743)](n){let s=t;return n?this[s(408)+"E"]():this[s(1373)+"E"]()}toBytesLE(){let n=t,s=this.high,d=this[n(542)];return[e.pzZSm(255,d),e[n(1567)](e[n(1179)](d,8),255),e[n(1325)](d>>>16,255),e[n(1856)](d,24),e[n(915)](255,s),e[n(1889)](s,8)&255,e[n(521)](e.ebCrU(s,16),255),e[n(438)](s,24)]}[t(1373)+"E"](){let n=t,s=this[n(1281)],d=this[n(542)];return[s>>>24,e[n(877)](e[n(1820)](s,16),255),e[n(1488)](e.PyYFB(s,8),255),e[n(695)](255,s),e[n(1635)](d,24),e[n(879)](e.gXiAu(d,16),255),d>>>8&255,e[n(1734)](255,d)]}}let Wd=new fe(0,0,!1),dp=new fe(0,0,!0),up=fe.fromBits(-1,2147483647,!1),lp=fe[t(1546)](-1,-1,!0),fp=fe.fromBits(0,-2147483648,!1);var tn=(function(a){let n=t,s=e[n(1627)].split("|"),d=0;for(;;){switch(s[d++]){case"0":a[a[e[n(1277)]]=5003]=e[n(1277)];continue;case"1":a[a[n(900)+n(1322)]=5004]=e[n(1970)];continue;case"2":a[a.OPEN_ERROR=5005]=e[n(1800)];continue;case"3":a[a[e[n(1331)]]=5002]=e.wNgzZ;continue;case"4":return a;case"5":a[a[e[n(1562)]]=5001]=e[n(1562)];continue}break}})({});class Qn{constructor(n){let s=t;this[s(428)]=n,this[s(1465)]=null}}class Kd extends Qn{constructor(n,s){let d=t;super(n),this.message=s&&s[d(933)]||null}}class $d extends Qn{constructor(n,s){let d=t;super(n),this[d(1802)]=s&&s[d(1802)]||null,this[d(1429)]=s&&s[d(1429)]||0,this[d(435)]=s&&s[d(435)]||"",this.lineno=s&&s[d(563)]||0,this[d(933)]=s&&s.message||"",this[d(862)]=s&&s.code||5001}}class Vd extends Qn{constructor(n,s){let d=t,l=e[d(1042)][d(1102)]("|"),h=0;for(;;){switch(l[h++]){case"0":super(n);continue;case"1":this[d(689)]=s&&s.wasClean||!1;continue;case"2":this[d(862)]=s&&s[d(862)]||0;continue;case"3":this[d(1423)+d(753)]=s&&s[d(1423)+d(753)]||!1;continue;case"4":this[d(493)]=s&&s[d(493)]||"";continue}break}}}class Yd extends Qn{constructor(n,s){let d=t;super(n),this[d(1738)]=s&&s.data||null}}class Zd extends Yd{constructor(n,s){let d=t;e.wGpIn!==d(1615)?(_0x68d464(_0x126095,24),e[d(605)](_0x30cf4f,_0x47444c,_0x14a2d0(_0x1f3372))):(super(n),this[d(1738)]=s&&s[d(1738)]||null,this[d(933)]=s&&s[d(933)]||null)}}class Jd extends Qn{constructor(n,s){let d=t,l={RGsVg:function(h,w){return e.ngQHH(h,w)},IKFai:function(h,w){return h&w},DDnDz:function(h,w){return e[N(1294)](h,w)},HRQdl:function(h,w){return e.STIbS(h,w)},PRMpo:function(h,w){return h+w},cfJib:function(h,w){return e[N(1003)](h,w)},RfbwE:function(h,w){return h+w},ihMMU:function(h,w){return e[N(996)](h,w)},lLiFC:function(h,w){return e[N(1203)](h,w)},TKFLH:function(h,w){return e[N(860)](h,w)}};if(e[d(1450)]("bCgCe",d(1927))){_0x5c7b24[d(812)](_0x488fbb)||(_0x155827=_0x5bc428[d(411)+"er"](_0x27b039));let h=EqUsIW.RGsVg(this[d(1281)],16),w=EqUsIW[d(481)](65535,this.high),b=this[d(542)]>>>16,g=65535&this.low,T=_0x7b2b4f[d(1281)]>>>16,O=EqUsIW[d(1143)](65535,_0x4eb867[d(1281)]),M=EqUsIW[d(1949)](_0x77884e[d(542)],16),V=65535&_0x2916bc.low,j=0,ee=0,Pe=0,Ze=0;return Ze+=EqUsIW[d(1644)](g,V),Pe+=EqUsIW[d(1073)](Ze,16),Ze&=65535,Pe+=EqUsIW[d(742)](b,M),ee+=EqUsIW[d(1949)](Pe,16),Pe&=65535,ee+=EqUsIW.RfbwE(w,O),j+=ee>>>16,ee&=65535,j+=EqUsIW[d(549)](h,T),j&=65535,_0x27542d[d(1546)](EqUsIW[d(565)](EqUsIW[d(1284)](Pe,16),Ze),EqUsIW.lLiFC(j<<16,ee),this[d(1425)])}else super(n),this[d(1738)]=s&&s.data||null}}function at(a,{message:n,code:s,error:d}){return new $d(a,{message:n,code:s,error:d})}function xt(a,{code:n,reason:s,wasClean:d,willReconnect:l}){return new Vd(a,{code:n,reason:s,wasClean:d,willReconnect:l})}function Xd(a,{data:n,message:s}){return new Zd(a,{data:n,message:s})}function Qd(a,{data:n}){return new Jd(a,{data:n})}function ca(a,{message:n}){return new Kd(a,{message:n})}class eu{constructor(n,s){let d=t;this[d(872)+"s"]=n,this[d(1778)+"es"]=s,this["currentI"+d(986)]=0,this[d(478)+d(926)+d(957)+"t"]=0}[t(811)+t(1863)+t(1963)](){let n=t,s={iqcTW:function(d,l){return d+l},McqMq:function(d,l){return e[N(1372)](d,l)},xldBF:function(d,l){return e.HVMae(d,l)},yQrZv:function(d,l){return d!==l},NQWZL:function(d,l){return e[N(1446)](d,l)},xGnYi:function(d,l){return d|l},oKujO:function(d,l){return e[N(1385)](d,l)},yDNgx:function(d,l){return e[N(1574)](d,l)},DMIzv:function(d,l){return e[N(1325)](d,l)},MOmUo:function(d,l){return e[N(917)](d,l)},GItKs:function(d,l){return e[N(1650)](d,l)},uUzBx:function(d,l,h){return e[N(1839)](d,l,h)},VNzBC:function(d,l){return e.YahVV(d,l)}};e.gtzPK(e[n(1569)],e[n(1569)])?(this["currentI"+n(986)]=0,this["currentE"+n(926)+n(957)+"t"]=0):(_0x425cb0=_0x13d66b[dhWLPY[n(1128)](dhWLPY[n(1128)](_0x4bdc75,_0x2bfe9c),1)],_0xd96843=_0x505c74[dhWLPY[n(723)](dhWLPY.iqcTW(_0x10b39a,_0x57f4c7),2)],_0x435135=_0x4145b0[dhWLPY[n(1245)](_0x3177a6,_0x473346)+3],dhWLPY[n(1831)]((_0x212856|_0x3fb35a<<8|dhWLPY.NQWZL(_0x1a9b3c,16))&12632256,8421504)?_0x5030ea+=_0x2fad7c:(_0x50ebf8=dhWLPY.xGnYi(dhWLPY.oKujO(dhWLPY[n(1447)](dhWLPY[n(357)](dhWLPY[n(1743)](7,_0x60c057),18),dhWLPY.yDNgx(dhWLPY[n(1743)](63,_0x12c699),12)),dhWLPY[n(1306)](63&_0x2ecb19,6)),dhWLPY.DMIzv(63,_0x344014)),dhWLPY.MOmUo(_0x2ff1d4,65536)||dhWLPY[n(1791)](_0x5b0c62,1114111)?_0x471c00+=_0x1aa847:(_0x1efc66-=65536,_0x1c6947+=dhWLPY.uUzBx(_0x471a5b,dhWLPY[n(1245)](dhWLPY[n(672)](_0x100218,10),55296),dhWLPY[n(1245)](1023&_0x138445,56320)),_0x855d38+=3)))}[t(1900)+"es"](){let n=t;this[n(478)+n(926)+n(957)+"t"]=0}[t(1847)+t(362)+"nt"](){let n=t;return this.endpoints[this["currentI"+n(986)]]}[t(1847)+t(362)+t(1244)+"ount"](){let n=t;return this["currentE"+n(926)+n(957)+"t"]}[t(1408)+t(1819)+"es"](){let n=t;return!!(e.ruIRb(this["currentI"+n(986)],this[n(872)+"s"].length)||e.oLLof(this[n(1358)+"ndex"],this[n(872)+"s"].length-1)&&e[n(1060)](this[n(478)+n(926)+n(957)+"t"],this[n(1778)+"es"]))}[t(1334)+"rentEndp"+t(1012)+t(660)+t(1365)](){let n=t;if(n(925)===e[n(1233)])return this[n(1358)+n(986)]==this[n(872)+"s"][n(690)]?!0:e[n(1502)](this["currentE"+n(926)+n(957)+"t"],this[n(1778)+"es"]);_0x5575a9[n(1403)](_0x58daf0,_0x452c9d),_0x3f26e2[n(1403)](_0x23622d,_0xbb9ef3)}[t(1536)+t(1942)+t(1843)+t(1257)+t(1874)](){let n=t;return this[n(478)+n(926)+"riesCount"]=1,this[n(1358)+n(986)]++,this[n(872)+"s"][this[n(1358)+"ndex"]]}[t(1847)+t(362)+t(1182)+t(1752)](){let n=t;return e[n(477)](e[n(1485)],e[n(1485)])?new _0x5784bc(_0xe1fe45,{message:_0x3a0dad}):(this[n(478)+n(926)+n(957)+"t"]++,this[n(1847)+n(362)+"nt"]())}}let er=(e.mFmLx!=typeof globalThis&&e.xuFNz(e[t(1549)],globalThis[t(905)+t(440)][t(1309)])||e[t(1652)](e[t(763)],typeof window)&&e[t(1862)](e[t(1549)],window.constructor[t(1309)]))&&e[t(657)](e.mFmLx,typeof document),Rn=e[t(861)](e[t(763)],typeof globalThis)&&(e.OHnTy(t(405),globalThis[t(905)+t(440)][t(1309)])||e[t(1747)](e[t(907)],globalThis[t(905)+t(440)].name))&&e[t(763)]!=typeof tt,Yr=(e[t(931)](e[t(763)],typeof globalThis)&&e[t(1940)](e.XgnZt,globalThis[t(905)+t(440)][t(1309)])||e[t(763)]==typeof globalThis||e.mFmLx!=typeof globalThis&&!!globalThis[t(635)+t(1713)])&&e.fUUOB(e.mFmLx,typeof wx),Zr=e[t(763)]!=typeof globalThis&&(e[t(671)](e[t(907)],globalThis[t(905)+t(440)][t(1309)])||e.BmuJD(e.YGxGa,globalThis[t(905)+t(440)].name)||e[t(1382)]===globalThis[t(905)+t(440)][t(1309)])&&e[t(1991)](e[t(763)],typeof self),xp=e[t(1533)](e[t(763)],typeof globalThis)&&e.DEZQw(e[t(1007)],globalThis[t(905)+t(440)][t(1309)])&&e[t(808)](t(1255)+"d",typeof global)&&t(405)===global[t(905)+"tor"][t(1309)]&&e[t(1459)](e[t(763)],typeof process)&&!!process[t(1934)];class da{constructor(){let n=t;this[n(997)+"rs"]={}}emit(n,...s){let d=t,l=this._listeners[n];if(l)l[d(1399)]()[d(417)](h=>h.fn.apply(h.ctx,s));else if(n==="error"&&!this.onerror){let h=s.length&&s[0];if(e[d(831)](h,Error))throw h;let w=new Error(e.JTghJ+(h?e.HyTdl(e[d(725)](" (",h[d(933)]),")"):""));throw w[d(691)]=h,h}return this}[t(1235)](n,s){let d=t;if(e[d(1256)](void 0,n))this[d(997)+"rs"]={};else if(e[d(1897)](void 0,s))this[d(997)+"rs"][n]=null;else{let l=this[d(997)+"rs"][n];if(l)for(let h=0;e[d(1189)](h,l[d(690)]);)e[d(1692)](l[h].fn,s)?l[d(360)](h,1):++h}return this}on(n,s,d){let l=t;return(this[l(997)+"rs"][n]||(this[l(997)+"rs"][n]=[]))[l(1680)]({fn:s,ctx:d||this}),this}}class hp extends da{["_formatE"+t(873)+"age"](n){let s=t;return n[s(457)]||n.errNo?(s(1225)+" "+(n[s(457)]||"")+s(1079)+(n.errNo||""))[s(560)]():JSON[s(413)+"y"](n)}constructor(n,s,d){let l=t;e[l(989)](e[l(673)],"sBMEr")?(super(),this._socket=null,Yr&&wx[l(1462)+"ocket"]&&(this._socket=wx.connectSocket({url:n,protocols:s,header:d,fail:this[l(441)+"ocketFailHandler"][l(805)](this),success:this[l(441)+l(1071)+"cessHand"+l(1876)].bind(this)})),Rn&&tt[l(1462)+l(1898)]&&(this._socket=tt[l(1462)+"ocket"]({url:n,protocols:s,header:d,fail:this[l(441)+l(601)+l(1064)].bind(this),success:this["_createSocketSuccessHand"+l(1876)][l(805)](this)}))):(_0x1bcc61[_0x582f30++]=e[l(960)](e[l(1295)](_0x350085,12),224),_0x55f42f[_0x54ef65++]=e.iIgQO(e.WNkDz(e[l(1430)](_0x5cf77d,6),63),128),_0x5cc86e[_0x57ab0a++]=e[l(1504)](63,_0x17e8e6)|128)}[t(441)+"ocketSuccessHand"+t(1876)](){let n=t,s={SYUZM:function(d,l,h){return e[N(1076)](d,l,h)},bZNXs:function(d,l){return d(l)}};if(e[n(814)](e[n(859)],e[n(859)]))Promise[n(1227)]()[n(555)](()=>{let d=n,l={UuHCJ:e.ZJLzH};if(e[d(375)](e[d(1792)],e[d(1792)]))this[d(1396)+d(1137)]();else if(!this[d(967)+d(1190)]){let h=l[d(571)][d(1102)]("|"),w=0;for(;;){switch(h[w++]){case"0":this["_pingLos"+d(1132)]?.[d(1344)+d(545)]();continue;case"1":this[d(999)+d(1174)]?.["resetEnd"+d(1863)+d(1963)]();continue;case"2":this[d(1941)+d(393)]=!1;continue;case"3":this[d(638)]=!0;continue;case"4":this._connect();continue}break}}});else{let d=_0x451173();return bbvuJi[n(1964)](_0x4ea00d,_0x17d274,d),bbvuJi[n(448)](_0x10a26d,d)}}["_createS"+t(601)+t(1064)](n){let s=t;Promise.resolve()[s(555)](()=>{let d=s,l=e[d(864)](at,e.bJpMl,{message:this[d(1768)+"rrorMessage"](n)});this[d(1440)](e[d(583)],l);let h=e[d(974)](xt,"close",{reason:this[d(1768)+d(873)+d(1989)](n)});this.emit(e.YDgcv,h)})}["_addWsLi"+t(1137)](){let n=t,s={kcluN:function(d,l){return e[N(1812)](d,l)},pdTOz:function(d,l){return e.BjyoV(d,l)},bvOEg:function(d,l){return e[N(1551)](d,l)},WAHRy:function(d,l){return e.XwkEK(d,l)},vhbUN:function(d,l){return e.OkXBP(d,l)},mYmbS:function(d,l){return e[N(1721)](d,l)},dpQHe:function(d,l){return e[N(1047)](d,l)},SQfns:function(d,l){return d<l},zOKKj:function(d,l){return e[N(1781)](d,l)},GuZHE:function(d,l){return e[N(1446)](d,l)},XZicr:function(d,l){return d&l},zXveI:function(d,l){return d<<l},xotnp:function(d,l){return e.GuXkT(d,l)},bSMDM:function(d,l){return e[N(1740)](d,l)},CcScD:function(d,l){return e[N(849)](d,l)},RFPzM:e[n(1726)],uxHlX:function(d,l,h){return e.ezILn(d,l,h)},pxEkU:n(933),eiLAA:function(d,l){return e.TYkxL(d,l)}};this._socket[n(1335)](d=>{let l=n;if(l(1767)===l(934)){let h=_0x18a152[_0x54a56a++];if(s[l(1327)](h,127))_0xc80a6a+=_0x4963d0[l(472)+l(522)](h);else if(s.pdTOz(h,192)&&s.bvOEg(h,224))_0x449398+=_0x91e63e[l(472)+l(522)](s[l(1207)](s.vhbUN(s[l(1418)](31,h),6),s.mYmbS(63,_0x30eda1[_0x52d48b++])));else if(s[l(1469)](h,224)&&s[l(1547)](h,240))_0x48e153+=_0xc204c2[l(472)+l(522)](s[l(789)](s.WAHRy(s[l(1960)](s[l(1357)](15,h),12),s[l(1240)](s[l(1357)](63,_0x2b184e[_0xbbee70++]),6)),63&_0x2e259e[_0x58ed1d++]));else if(s[l(1238)](h,240)){let w=s[l(1010)](s.WAHRy(s[l(919)](7&h,18),s[l(532)](63&_0x5b277f[_0x37ba06++],12))|(63&_0x42983d[_0x514d8b++])<<6,63&_0x231366[_0x3ea8fb++])-65536;_0x7ec2a2+=_0x1084ef.fromCharCode(55296+(w>>10)),_0x1fc111+=_0x556b3d[l(472)+"Code"](s.CcScD(56320,s.XZicr(1023,w)))}}else this[l(1440)](l(527),e.nGGwj(Qd,e[l(1125)],{...d,data:d[l(457)]||""}))}),this[n(918)][n(1020)](d=>{let l=n;this[l(1440)](s[l(554)],s[l(1908)](xt,s[l(554)],{...d}))}),this[n(918)][n(541)+"e"](d=>{let l=n;this[l(1440)](s.pxEkU,s.uxHlX(Xd,s[l(1197)],{...d}))}),this._socket.onError(d=>{let l=n;if(e.AAQaM(e[l(1402)],e[l(1700)])){let h=this[l(626)][l(1019)+l(1303)+"nc"](this[l(748)]),w=_0x405fc6[l(528)](s[l(839)](h,"{}"));return _0x13ef2a[l(856)](w)}else this[l(1440)](l(1802),e[l(1057)](at,e.bJpMl,{...d,message:d[l(457)]||""}))})}send(n){let s=t,d={YKQdM:e[s(583)]};if(n instanceof Uint8Array)if(e[s(970)](e[s(1823)],e[s(1823)]))this[s(1440)](e.TJdsG,_0x14d147),this[s(1439)]&&this.onopen(_0x2b7be8);else{let l=n[s(1522)].slice(n[s(1572)+"et"],e[s(1282)](n.byteLength,n[s(1572)+"et"]));this._socket&&this[s(918)][s(1671)]({data:l,fail:h=>{let w=s;this[w(1440)](d[w(1739)],at(w(1802),{message:this[w(1768)+"rrorMess"+w(1989)](h)}))}})}else this[s(918)]&&this[s(918)][s(1671)]({data:n,fail:l=>{let h=s;this.emit(e.bJpMl,e[h(366)](at,e[h(583)],{message:this[h(1768)+h(873)+h(1989)](l)}))}})}close(n,s){let d=t;e[d(1374)](e[d(403)],e[d(403)])?(_0x58cb98=_0x166222[d(1725)](_0x9f534e),_0x31f57e=_0x193668[d(1725)](_0x33df47[_0x158c2b])):this[d(918)]&&this._socket[d(1662)]({code:n,reason:s})}[t(1093)+"Listener"](n,s){this.on(n,s)}[t(744)+"entListe"+t(757)](n,s){let d=t,l={PhhYP:function(h,w){return h<w},DpBuD:function(h,w){return e[N(1974)](h,w)},rXxRP:function(h,w){return e.XahjF(h,w)},wWScq:function(h,w){return e[N(1537)](h,w)},DsfCS:function(h,w){return h||w},mOvIC:function(h,w){return e.lVVqJ(h,w)}};if(e[d(467)](e[d(1480)],e[d(612)]))this.off(n,s);else{let h=l[d(699)](_0x45240d,8192),w=l[d(1118)](h,1),b=null,g=h;return function(T){let O=d;if(l.PhhYP(T,1)||l[O(882)](T,w))return _0x522a6a(T);l.DpBuD(l[O(1e3)](g,T),h)&&(b=l[O(1253)](_0x2aee5d,h),g=0);let M=_0x5bb8eb.call(b,g,g+=T);return 7&g&&(g=l[O(1e3)](7|g,1)),M}}}get[t(1059)+"te"](){let n=t;return this[n(918)][n(1059)+"te"]}get[t(884)+"pe"](){let n=t;return this[n(918)][n(884)+"pe"]}set[t(884)+"pe"](n){}get url(){let n=t;return this._socket[n(1448)]}get[t(473)](){let n=t;return this._socket[n(473)]}get extensions(){let n=t;return this[n(918)][n(558)+"ns"]}get[t(1195)+t(1202)](){return 0}}function pp(a,n){let s=t;if(n)return new n(a[s(1448)],a[s(473)]);if(e[s(1458)](Yr,Rn))return new hp(a[s(1448)],a.protocol,a[s(469)]);if(e[s(1510)](er,Zr)&&e.mFmLx!=typeof WebSocket&&WebSocket)return new WebSocket(a[s(1448)],a[s(473)+"s"])}function gp(a){let n=t;return e.kIrZd(e.ZyaFb,e[n(1821)])?!!(a||Yr&&wx[n(1462)+n(1898)]||Rn&&tt[n(1462)+"ocket"]||e[n(1458)](er,Zr)&&e.ZNFDU(e[n(763)],typeof WebSocket)&&WebSocket):this[n(999)+n(1174)]?.[n(1847)+n(362)+n(1244)+"ount"]()||0}function tu(a,n,s){let d=t,l=-1;async function h(w){let b=N;return e[b(1266)](w,l)?Promise[b(990)](new Error("next() c"+b(1632)+"ltiple times in "+b(1772))):(l=w,e[b(537)](w,s[b(690)])?Promise[b(1227)]():s[w][b(805)](a)(n,h.bind(null,e[b(1990)](w,1))))}e[d(1161)](h,0)}function nu(a){let n=t,s=0,d=0;for(let l=0;e[n(1728)](l,a[n(690)]);++l)d=a[n(1500)+"At"](l),e[n(1722)](d,128)?s+=1:d<2048?s+=2:e[n(1242)](e[n(1271)](64512,d),55296)&&e.TqHjw(e[n(857)](64512,a.charCodeAt(e[n(1930)](l,1))),56320)?(++l,s+=4):s+=3;return s}function ru(a,n,s){let d=t,l={yHXpo:function(h,w){return e[N(594)](h,w)},grsHu:function(h,w){return h-w},cOWRh:function(h,w){return e[N(1409)](h,w)}};if(d(1679)===e[d(1369)]){if(e[d(1394)](s-n,1))return"";let h="";for(let w=n;e[d(1728)](w,s);)if(e[d(1113)](e[d(836)],e[d(1710)])){let b=a[w++];if(e.CTKDo(b,127))h+=String["fromChar"+d(522)](b);else if(b>=192&&e[d(1097)](b,224))h+=String[d(472)+"Code"](e.DftPL(e[d(1446)](e[d(1905)](31,b),6),63&a[w++]));else if(e[d(750)](b,224)&&e.CETsp(b,240))h+=String[d(472)+d(522)](e.dEiDN(e[d(1051)](e.HTjdT(15,b),12),e.TCZxR(e[d(1848)](63,a[w++]),6))|63&a[w++]);else if(e[d(617)](b,240)){let g=e[d(515)](e[d(1787)](e[d(678)](e[d(1828)](7&b,18),e[d(1006)](63&a[w++],12)),e.NbNjY(e[d(599)](63,a[w++]),6))|63&a[w++],65536);h+=String.fromCharCode(55296+(g>>10)),h+=String["fromChar"+d(522)](e[d(1830)](56320,e.mXFbz(1023,g)))}}else this["_cursorF"+d(652)]=_0x21ee64;return h}else{let{initReconnectInterval:h,maxReconnectInterval:w,reconnectIntervalGrowFactor:b}=this[d(1312)],g=l[d(1552)](h,_0x28534f[d(1639)](b,l[d(1717)](_0x402296,1)));return l[d(1172)](g,w)?w:g}}function ua(a,n,s){let d=t,l=s,h,w;for(let b=0;e.AIZtr(b,a[d(690)]);++b)h=a[d(1500)+"At"](b),h<128?n[s++]=h:e.akGAb(h,2048)?(n[s++]=h>>6|192,n[s++]=e[d(718)](e[d(1769)](63,h),128)):e.VGtAa(64512,h)===55296&&e[d(945)](64512,w=a[d(1500)+"At"](b+1))===56320?(h=e.stoRz(65536+e[d(1291)](e[d(1314)](1023,h),10),e[d(598)](1023,w)),++b,n[s++]=e[d(618)](e.dNVSQ(h,18),240),n[s++]=e[d(521)](e[d(1307)](h,12),63)|128,n[s++]=e.VkQhp(e[d(1352)](e.JwLgn(h,6),63),128),n[s++]=e.llear(63,h)|128):(n[s++]=e.oyjvS(h>>12,224),n[s++]=e[d(574)](h,6)&63|128,n[s++]=e[d(506)](e[d(630)](63,h),128));return e[d(1035)](s,l)}async function iu(a){let n=t;if(e.LMDRN(e[n(476)],typeof a)){if(e[n(758)](n(1088),e[n(1329)]))return(this[n(997)+"rs"][_0x1ef649]||(this[n(997)+"rs"][_0x38b297]=[]))[n(1680)]({fn:_0x17ab2d,ctx:_0x1c3809||this}),this;{let s=new Uint8Array(e[n(1121)](nu,a));return e.LOJSC(ua,a,s,0),s}}return a instanceof ArrayBuffer?new Uint8Array(a):new Uint8Array(a[n(1522)],a[n(1572)+"et"],a[n(603)+"th"])}function mp(a){let n=t;try{return e[n(842)](e[n(476)],typeof a)&&(e[n(831)](a,ArrayBuffer)||a[n(1522)]&&e[n(831)](a[n(1522)],ArrayBuffer))||e.ZNFDU(n(504),typeof a)?"":(JSON.parse(a),n(414)+n(1021))}catch{return e[n(1532)](n(504),typeof a)?e[n(1695)]:""}}let wp=(a,n)=>{let s=t;switch(a){case e[s(409)]:case e[s(455)]:return{[s(358)+a]:1,"x-tt-env":n};default:return{}}};class _p{constructor(n){let s=t;this[s(416)+s(647)]=n,this[s(766)]=0}[t(1194)](){let n=t;this[n(766)]++}[t(1408)+t(1505)+"nt"](){let n=t;return e[n(391)](this[n(766)],this[n(416)+"ount"])}["resetCou"+t(545)](n=0){let s=t;this[s(416)+s(647)]=n,this[s(766)]=0}}async function yp(a){let n=t,s={JLBng:e[n(1463)]};return new Promise(d=>{let l=n,h={ZMfeF:e[l(583)],IAOsc:function(w,b,g){return e.AnoaO(w,b,g)},txjzV:e[l(1726)]};if(e.yBTxw(e[l(1342)],"IIAQv")){if(!er)return e.RSKhS(d,"unknown "+l(493));try{let w=document[l(1250)+l(452)](e[l(625)]);window[l(1163)+"JSONP"]=b=>{let g=l;document[g(786)][g(1297)+g(852)](w),window[g(1163)+g(705)]=void 0,d(b&&b[g(1649)]||s[g(801)])},w[l(428)]=e[l(1592)],w.src=e[l(544)](a[l(1617)](/^ws/,e[l(1140)]),e[l(924)]);try{document[l(786)][l(734)+"ild"](w)}catch{document[l(786)][l(1297)+l(852)](w)}}catch{window[l(1163)+l(705)]=void 0,e.sbgZY(d,e[l(1463)])}}else _0x50eada[l(1227)]()[l(555)](()=>{let w=l,b=_0x58fa03(okkuXj[w(896)],{message:this["_formatE"+w(873)+w(1989)](_0x52f90b)});this[w(1440)](okkuXj[w(896)],b);let g=okkuXj[w(1332)](_0x5de6d9,okkuXj.txjzV,{reason:this[w(1768)+w(873)+w(1989)](_0x371651)});this[w(1440)](okkuXj[w(1213)],g)})})}function nn(a,n,s){let d=t;return!!a?.find(l=>l.key===n&&l[d(1669)]===s)}function tr(a,n){let s=t;return a?.find(d=>d[s(1977)]===n)?.[s(1669)]}let la=null;async function bp(){let a=t;return la||(la=Promise[a(1227)]()[a(555)](Nt[a(805)](Nt,a(1214)))),la}class Ep extends da{constructor(n,s){let d=t;super(),this[d(1921)]=n,this[d(1932)]=s,this[d(626)]=void 0,this[d(1912)+d(1083)]=null}async[t(495)](){await this[t(1913)]()}async[t(1913)](){let n=t,s={TwmjJ:function(d){return e.UBvnk(d)}};if(!this[n(626)]){if(this[n(1912)+n(1083)])return this[n(1912)+n(1083)];try{let d=this[n(1921)],l=this[n(1932)];this[n(1912)+n(1083)]=(async()=>{let h=n,{openDB:w}=await s.TwmjJ(bp);this[h(626)]=await w(h(1163)+"_"+d,1,{upgrade(b){let g=h;b[g(1793)+g(1149)+"e"](d,{keyPath:l})}})})(),await this[n(1912)+n(1083)]}catch(d){console.log(d)}finally{this[n(1912)+n(1083)]=null}}}async get(n){let s=t,d={SHSAd:e[s(1503)],qIDYk:e[s(1080)]};if(e[s(1746)](e.wcVFb,"eDtkM"))try{this._ws&&this[s(1751)][s(1662)](_0x48a622,_0x54ac61)}catch{}else try{return await this._init(),this[s(626)]?.[s(1004)](this[s(1921)],n)}catch(l){e[s(892)](e.lvfao,e[s(643)])?console[s(1915)](l):(this[s(1563)+s(1132)]?.[s(1194)](),this.emit(d[s(1853)],d[s(383)]),this["_pingLos"+s(1132)]?.["checkRea"+s(1505)+"nt"]()?this[s(778)+s(604)]():this[s(365)]())}}async set(n,s){let d=t;return await this[d(1913)](),this[d(626)]?.[d(1501)](this[d(1921)],n)}async[t(569)](n){let s=t,d={gioSl:function(l,h){return e.woXdT(l,h)}};try{return await this[s(1913)](),this[s(626)]?.[s(1024)](this[s(1921)],n)}catch(l){if(e.ZfyuP===e.TubWJ)return _0x5c99dd&&AmzSse[s(895)](!0,_0x2726de[s(812)]);console[s(1915)](l)}}async[t(1737)](){let n=t;try{return await this[n(1913)](),this[n(626)]?.[n(1737)](this[n(1921)])}catch(s){console.log(s)}}async[t(856)](){let n=t;return await this._init(),this._qosDB?.[n(1577)+"ys"](this[n(1921)])}async getAll(){let n=t;return await this._init(),this[n(626)]?.[n(1545)](this._dbName)}async closeDB(){let n=t;try{this[n(626)]?.[n(1662)](),this._qosDB=void 0}catch(s){if(n(820)===e[n(588)])console.log(s);else return _0x593549[n(1869)][_0x573171(_0x4fa115,1)]}}get[t(384)](){let n=t;try{return!!this[n(626)]}catch(s){return console[n(1915)](s),!1}}}class vp{constructor(n,s){let d=t;this._DBName=n,this._pathKey=s,this[d(626)]=localStorage}async openDB(){}get _prefix(){let n=t;return n(1163)+"_"+this[n(1622)]}async[t(1004)](n){let s=t,d=this._qosDB.getItem(this[s(748)]);return JSON[s(528)](e[s(1458)](d,"{}"))[n]}async[t(1403)](n,s){let d=t,l=this._qosDB[d(531)](this[d(748)]),h=JSON[d(528)](l||"{}");return h[s||n[this._pathKey]]=n,this[d(626)][d(863)](this[d(748)],JSON[d(413)+"y"](h)),s||n[this[d(1833)]]}async[t(569)](n){let s=t,d=this[s(626)][s(531)](this._prefix),l=JSON[s(528)](e[s(963)](d,"{}"));return l[n]=void 0,this[s(626)][s(863)](this._prefix,JSON[s(413)+"y"](l))}async[t(1737)](){let n=t;return this[n(626)][n(1737)]()}async[t(856)](){let n=t,s={AoEUO:function(d,l,h){return e[N(410)](d,l,h)},odZMe:function(d,l){return e[N(1413)](d,l)}};if(e.Lxpwg(n(1014),e.KRJmY)){let d=this._qosDB[n(531)](this[n(748)]),l=JSON[n(528)](e[n(1458)](d,"{}"));return Object[n(856)](l)}else{let d=SmDEDR[n(1709)](_0x14a30f,_0x46562d,_0x3eb7d1);return _0x3f17c2[n(1869)][n(1917)](d,SmDEDR[n(1254)](d,_0x3b8f3a))}}async[t(1545)](){let n=t,s={RUjxN:function(d,l){return d|l},rSVFv:function(d,l){return e[N(1474)](d,l)},QzRxA:function(d,l){return e[N(956)](d,l)},BjNNZ:function(d,l){return e[N(1611)](d,l)},bBQTd:function(d,l){return d+l},UOEAM:function(d,l){return e[N(1760)](d,l)},cAiQx:function(d,l){return d<<l},quQwB:function(d,l){return e[N(725)](d,l)},MXbHT:function(d,l){return d<<l},EpLhb:function(d,l){return e[N(1755)](d,l)}};if(e[n(537)](e[n(489)],e.sbRuE)){let d=new _0x550f90(s[n(1742)](s[n(1742)](s[n(700)](s[n(1571)](_0x1d84bf[s[n(1152)](_0x461156,4)],24),s[n(1571)](_0x465d7d[s[n(1694)](_0xe28a18,5)],16)),s[n(1571)](_0xaa4828[_0x1a0c1d+6],8)),_0x3ca69c[_0x148d3d+7]),s.UOEAM(s[n(700)](s[n(1742)](s[n(1571)](_0x1951ca[s[n(1694)](_0x266fe8,0)],24),s[n(1407)](_0x53ca8e[s[n(1513)](_0x23ea27,1)],16)),s.MXbHT(_0x44da89[_0xb5d832+2],8)),_0x221466[s.BjNNZ(_0xa9c03c,3)]),!0);return _0xdebe72+=8,{value:d,offset:s[n(1788)](_0x5ba8cf,8)}}else{let d=this[n(626)][n(531)](this[n(748)]),l=JSON[n(528)](e[n(1497)](d,"{}"));return Object.values(l)}}closeDB(){return Promise[t(1227)]()}get[t(384)](){return!!this._qosDB}}class Sp{constructor(n,s){let d=t;if(e[d(1185)](d(1162),e[d(1461)])){let l=e.rSEkN.split("|"),h=0;for(;;){switch(l[h++]){case"0":_0x3f7d0a=e.UoGlh(_0x71ddd,_0x17551a[d(411)+"er"](_0xce8ddc[d(1034)]||_0x55155e),_0x270039,_0x22e8dd);continue;case"1":_0xba944e[d(1915)](e[d(1803)],_0x391d60);continue;case"2":_0x3e5fda=_0x3f8f9b(_0x49b933[d(1075)+"ame"],_0x2b1131,_0x54d9fd);continue;case"3":_0x572c9c[d(1915)](e[d(1011)],_0x12a8b3);continue;case"4":_0x4a6d78.log(e[d(1289)],_0x1b0391);continue;case"5":_0x50c899=_0x26dcf8(_0x49f79b,_0x1a6c1b,_0x2eec9b[d(843)]||0);continue;case"6":_0x1baf85.log("name",_0x4ccf4b);continue;case"7":_0x3b4984=e[d(353)](_0xe06244,_0x3fb3a1[_0x2c6720["cursor_n"+d(1171)]],_0x5e921d,_0x4839b9);continue;case"8":_0x37ffd2[d(1915)](e[d(1005)],_0x4bc39f,_0x1a0ca5[d(843)]);continue;case"9":_0x54dfe6[d(1915)](d(1481)+"name",_0x4dbfde);continue;case"10":_0x5202b5=e.QWTcy(_0x46a582,0,_0x4f326a,_0x11479f);continue}break}}else this[d(1622)]=n,this._pathKey=s,this[d(626)]=Rn?tt:Yr?wx:null}async openDB(){}get _prefix(){let n=t;return n(1163)+"_"+this[n(1622)]}async[t(1004)](n){let s=t,d=this[s(626)][s(1019)+s(1712)](this[s(748)]);return JSON[s(528)](e[s(1497)](d,"{}"))[n]}async[t(1403)](n,s){let d=t;if(e[d(1208)](e[d(1749)],e.nepkl)){let l=this[d(626)]["getStora"+d(1712)](this[d(748)]),h=JSON[d(528)](l||"{}");return h[s||n[this[d(1833)]]]=n,this[d(626)][d(1870)+d(1712)](this[d(748)],JSON.stringify(h)),s||n[this[d(1833)]]}else return this[d(918)][d(884)+"pe"]}async[t(569)](n){let s=t,d=this[s(626)]["getStora"+s(1712)](this[s(748)]),l=JSON[s(528)](d||"{}");return l[n]=void 0,this[s(626)][s(1870)+s(1712)](this[s(748)],JSON[s(413)+"y"](l))}async[t(1737)](){let n=t;return this[n(626)][n(711)+n(464)]()}async[t(856)](){let n=t,s=this[n(626)][n(1019)+"geInfoSync"](this[n(748)]),d=JSON[n(528)](e[n(1497)](s,"{}"));return Object.keys(d)}async[t(1545)](){let n=t,s=this[n(626)][n(1019)+"geInfoSync"](this[n(748)]),d=JSON[n(528)](s||"{}");return Object.values(d)}[t(1591)](){return Promise.resolve()}get[t(384)](){return!!this[t(626)]}}function su(a,n){let s=t;if(e[s(1731)](Rn,Rn))return new Sp(a,n);if((er||Zr)&&e[s(861)](e[s(763)],typeof indexedDB))return new Ep(a,n);if(e[s(1497)](er,Zr)&&e[s(861)](e.mFmLx,typeof localStorage))return new vp(a,n);throw new Error(s(835)+s(1131)+"d")}class Ap{constructor(){let n=t;this[n(909)+n(380)+"Id"]=null,this[n(909)+"l"]=36e5,this._qosDB=e[n(1596)](su,e[n(943)],e[n(797)])}async[t(909)+t(1292)](){let n=t,s={xAAMT:function(d,l,h){return e[N(1804)](d,l,h)},fJeTT:function(d,l){return d!==l},PpXKF:e[n(1685)],EYmbF:e.nKqqq};e[n(1142)](clearInterval,this[n(909)+n(380)+"Id"]),this[n(909)+n(380)+"Id"]=e.nGGwj(setInterval,()=>{let d=n,l={YxTxc:function(h,w,b){return s.xAAMT(h,w,b)}};s[d(1894)](s.PpXKF,s.EYmbF)?this[d(1153)+"ired"]():(xGuQKi[d(385)](_0xbc3e9a,_0x6704e8,10),_0x38fea6(_0x664c1c,_0x16d435))},this._interval)}async[t(495)](){let n=t,s={risPs:e[n(756)],GjFrR:function(d,l){return e.NFEYF(d,l)},NUZgB:function(d,l){return e.pyKeI(d,l)},DDkcu:function(d,l){return e[n(1509)](d,l)}};e[n(1379)]==="Hhord"?this[n(1440)](NUUASQ.risPs,_0x1d2e20(NUUASQ[n(968)],{..._0x3888f7})):await this._qosDB[n(495)]().then(()=>{let d=n,l={cNudG:function(h,w){return s[N(806)](h,w)},ZcrUh:function(h,w){return s[N(1673)](h,w)}};if(s[d(729)]("umJNy",d(471))){let h=_0x3ac04b[d(1102)](":");_0x149f5d&&(_0x2aa072=h[d(690)]),_0x38b3c0+=h[d(690)];for(let w=0;LAITqO.cNudG(w,h[d(690)]);w++)if(h[w][d(690)]!==4){let b=_0x101726.substring(0,LAITqO[d(1441)](4,h[w].length)),g=b[d(1725)](h[w]);_0x309504.push(g)}else _0x4bece9.push(h[w]);_0x490a5c=!1}else this[d(909)+"lFlush"]()})}async["flushExp"+t(1564)](){let n=t;if(e.XZVqx(e[n(1595)],e.lWLYC))(await this._qosDB?.[n(1545)]()||[])[n(507)](({timestamp:l})=>l<Date[n(930)]())[n(417)](l=>{let h=n;this[h(626)]?.[h(569)](l.message_id)});else return e[n(1176)](-1,this[n(542)])&&e[n(1242)](-1,this[n(1281)])?_0x176077[n(1546)](0,0,this[n(1425)]):e.QGTAM(-1,this[n(542)])?_0x4deefa[n(1546)](0,this[n(1281)]+1,this.unsigned):_0x85dee9[n(1546)](e[n(913)](this[n(542)],1),this[n(1281)],this[n(1425)])}async[t(569)](n){let s=t;return this[s(626)]?.[s(569)](n)}async[t(1403)](n,s){let d=t;if(d(1598)!==d(1594))return this._qosDB?.[d(1403)]({message_id:n,timestamp:s});{let l=this._qosDB[d(1019)+d(1303)+"nc"](this[d(748)]),h=_0x5937ab[d(528)](l||"{}");return _0x48ba01.values(h)}}async get(n){return this[t(626)]?.get(n)}async closeDB(){let n=t;e[n(1911)](clearInterval,this[n(909)+n(380)+"Id"]),await this[n(626)]?.closeDB()}get isReady(){let n=t;return this[n(626)]?.[n(384)]}}function fa(a){let n=t,s=!!this[n(1312)][n(793)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let d=e[n(1880)](nn,a[n(933)][n(469)],e[n(1216)],"2"),l=d&&nn(a.message[n(469)],e[n(1276)],"1"),h=d&&e[n(1144)](nn,a[n(933)][n(469)],e.zjLLj,"1"),w=h?e[n(399)](tr,a[n(933)][n(469)],n(1935)+"er_ack_msgid")?.[n(1102)](",").filter(Boolean)||[]:[];return{enabled:s,isQoSMessage:d,isQoSAck:l,isAckCleanupMessage:h,ackMsgIds:w}}async function ou(){let a=t;return this[a(1929)+a(1348)]||(this[a(1929)+a(1348)]=new Ap),this[a(1929)+a(1348)][a(384)]||await this[a(1929)+a(1348)][a(495)](),this[a(1929)+a(1348)]}async function Ip(a,n){let s=t,{enableAutoAck:d}=this._options,l=e[s(552)](nn,a[s(933)][s(469)],e[s(1341)],"1"),h=nn(a.message[s(469)],e.apLOR,"1"),w=fa[s(486)](this,a);if(e[s(1645)](d,l)){let{SeqID:b,LogID:g,service:T,LogIDNew:O,method:M}=a[s(933)];this[s(840)]({SeqID:b,LogID:g,LogIDNew:O,service:T,method:M,headers:[{key:"is_ack",value:"1"},{key:e[s(1529)],value:e[s(415)](O,"")},{key:e[s(1836)],value:"0"}]})}h&&!w[s(1241)]&&this[s(548)+s(543)+"ageEvent"](a),e[s(724)](n)}async function Tp(a,n){let s=t;this._debug("received",a.message),e[s(1557)](n)}async function Cp(a,n){let s=t;if(e[s(788)](e.xhoxt,s(1040)))return e[s(1377)](e[s(627)](_0x4c55e8,4)[s(1544)]("0"),_0x4f3119(_0x5ddb82,2)[s(1956)](16))[s(1399)](-4);{let d=e[s(686)](Qt,await iu(a[s(1738)]));try{if(d[s(439)]instanceof Uint8Array){let l=e.hdwrS(this[s(1312)][s(813)+"ncoding"],Object)?{force:!!this._options["payloadE"+s(536)][s(980)],encoding:this[s(1312)][s(813)+s(536)][s(1864)]?this[s(1312)][s(813)+s(536)][s(1864)][s(1617)](/\s/g,"")[s(978)+s(637)]():""}:{force:!1,encoding:this._options[s(813)+s(536)]?this[s(1312)][s(813)+s(536)][s(1617)](/\s/g,"")[s(978)+s(637)]():""},h=d.payloadEncoding?d["payloadE"+s(536)].replace(/\s/g,"")[s(978)+s(637)]():"",w=e.hdwrS(this[s(1312)]["payloadT"+s(715)],Object)?{force:!!this[s(1312)][s(1841)+s(715)][s(980)],type:this._options[s(1841)+s(715)][s(428)]?this._options[s(1841)+s(715)][s(428)][s(1617)](/\s/g,"")[s(978)+"ase"]():""}:{force:!1,type:this[s(1312)].payloadType?this[s(1312)][s(1841)+s(715)][s(1617)](/\s/g,"")[s(978)+s(637)]():""},b=d[s(1841)+s(715)]?d[s(1841)+s(715)][s(1617)](/\s/g,"")[s(978)+s(637)]():"",g=w[s(980)]?w[s(428)]:b||w.type,T=l[s(980)]?l.encoding:h||l[s(1864)],O=[s(1944)+s(1603)+s(728),e[s(1899)],s(414)+"ion/json"+s(1618)+"=utf-8",e.LfLiX],M=[s(782)+"e",s(1711)];this._options["enableTr"+s(768)+s(1775)+"ad"]&&O[s(1525)](g)&&(!T||M[s(1525)](T))?d["textPayl"+s(1719)]=ru(d[s(439)],0,d.payload[s(603)+"th"]):d[s(1388)+s(1719)]=""}else d[s(1388)+s(1719)]=""}catch(l){d.textPayload="",console.log(l)}a[s(933)]=d,e[s(1770)](n)}}function Rp(a,n,s){let d=t,l={wvGmO:function(T,O){return e[N(1347)](T,O)},UuukB:e.NZNbG,YOTXZ:function(T,O){return e[N(1650)](T,O)},lmFGa:function(T,O){return e.XCBsM(T,O)},AXZSk:function(T,O){return e[N(544)](T,O)},golvV:function(T,O){return e[N(1801)](T,O)},FyFEk:function(T,O){return e[N(869)](T,O)},MmkBh:function(T,O){return T+O},VPGQf:function(T,O){return e.PmHtl(T,O)}},h=e[d(1727)](s,8192),w=e[d(1576)](h,1),b=null,g=h;return function(T){let O=d;if(l[O(832)](l[O(993)],l[O(993)])){let M=_0x1da82a.pop();return M?(M[O(866)]=M.limit=0,M):{bytes:new _0x2547f0(64),offset:0,limit:0}}else{if(T<1||l[O(530)](T,w))return a(T);l.lmFGa(l.AXZSk(g,T),h)&&(b=l[O(1205)](a,h),g=0);let M=n.call(b,g,g+=T);return l[O(1343)](7,g)&&(g=l[O(1893)](l.VPGQf(7,g),1)),M}}}let kp=4294967295;function Dp(a,n,s){let d=t;return e[d(1961)](RangeError,e[d(1706)](e[d(497)](e[d(497)](e[d(897)](e[d(1822)],a),e.nMbWU)+e.redqX(n,1),e.Pejqy),s))}function Pp(a,n,s){let d=t;if(e[d(407)](s,kp))throw new Error(e[d(1902)]);let l=3;for(;l>=0;){let h=e[d(1398)](255,s);e.TfplF(ha,h,a,n+l),s>>>=8,l--}return e[d(1706)](n,4)}function Op(a,n){let s=t,d=0,l=n,h=e[s(372)](n,4);for(;e[s(1580)](l,h);){let{value:w,offset:b}=e.TCmEv(xa,a,l);l=b,d=e[s(1824)](e.AKpGA(d,8),0),d+=w}return{value:d,offset:h}}function Lp(a,n,s){let d=t,l=e[d(1166)][d(1102)]("|"),h=0;for(;;){switch(l[h++]){case"0":if(!a)return s;continue;case"1":return e[d(1664)](e[d(369)](ua,a,n,s),s);case"2":if(e[d(1722)](a[d(690)],40))return e[d(725)](ua(a,n,s),s);continue;case"3":if(n[d(1130)])return e[d(1496)](n[d(1130)](a,s),s);continue;case"4":if(n[d(1630)+"e"])return e[d(1930)](n[d(1630)+"e"](a,s),s);continue}break}}function Np(a,n){let s=t,d=new fe(e[s(1881)](e[s(443)](e[s(762)](e[s(1404)](a[e[s(572)](n,4)],24),e[s(1574)](a[e[s(1380)](n,5)],16)),e[s(590)](a[n+6],8)),a[e.IYllz(n,7)]),e[s(1220)](e[s(1304)](e[s(377)](e.fkWlS(a[n+0],24),e.lmNGS(a[n+1],16)),e[s(1319)](a[e[s(1155)](n,2)],8)),a[n+3]),!0);return n+=8,{value:d,offset:e[s(1829)](n,8)}}function Mp(a,n,s){let d=t;if(e.CXmuU(e[d(1290)],e[d(1290)]))_0x275f1a.body[d(1297)+"ild"](_0x34830b);else{let l=a[d(542)],h=a[d(1281)];return n[s]=e[d(1820)](h,24),n[e[d(1626)](s,1)]=e.TNRjU(e[d(597)](h,16),255),n[e.VdNMk(s,2)]=e.mMsdg(e[d(1326)](h,8),255),n[e[d(1553)](s,3)]=255&h,n[s+4]=e[d(1183)](l,24),n[e[d(1472)](s,5)]=e[d(1273)](l,16)&255,n[e[d(1626)](s,6)]=e.Slbgx(e[d(988)](l,8),255),n[e[d(503)](s,7)]=e[d(1948)](255,l),s+=8,s}}function xa(a,n){let s=t,d={hGWgJ:function(l,h){return e.LnAJt(l,h)}};if(e[s(1176)](e[s(1457)],s(1232)))_0x17874d(this["_pingPon"+s(1050)+"Id"]),d.hGWgJ(_0x367d8e,this["_reconne"+s(1634)+"tId"]),this[s(802)+"gTimeoutId"]=null,this[s(984)+s(1634)+s(1531)]=null;else return a.readUInt8?{value:a[s(634)+"8"](n),offset:e[s(1380)](n,1)}:{value:e[s(651)](255,a[n]),offset:e[s(1115)](n,1)}}function ha(a,n,s){let d=t;if(e[d(1873)](e[d(994)],d(1456)))return n[d(1025)+"t8"]?n.writeUint8(a,s):n[s]=e[d(889)](255,a),e[d(1155)](s,1);this["_miniNav"+d(1112)+d(1686)]=_0x49292a,_0x1faf80?this[d(456)+"nLine"]():this[d(456)+d(1528)]()}let Bp=function(a){let n=t;return e[n(663)](n(1613),e.oGWIH)?new Uint8Array(a):this[n(626)]?.[n(569)](_0x1f4387)},zp=e[t(1640)](e[t(763)],typeof Buffer)?Buffer[t(1215)+"afe"]:e[t(1308)](Rp,Bp,Uint8Array[t(713)+"e"][t(1917)]);(()=>{let a=t,n={aNWxD:function(d,l,h,w){return d(l,h,w)},yWqBq:function(d,l){return d>>>l},yBtTm:function(d,l){return e[N(593)](d,l)},rGDOV:function(d,l){return d|l},vLRmz:function(d,l){return e[N(1420)](d,l)},vQpUu:function(d,l){return e[N(962)](d,l)},uCPKZ:function(d,l){return e[N(1760)](d,l)},OQDkD:function(d,l){return e[N(1824)](d,l)},Nhtad:function(d,l){return e[N(860)](d,l)},oSnmd:function(d,l){return e[N(1261)](d,l)},JswOk:function(d,l){return e[N(389)](d,l)},rDXuy:function(d,l){return e[N(1840)](d,l)},OjNjf:function(d,l){return e[N(719)](d,l)},TBRJB:function(d,l){return e[N(609)](d,l)},UOVAw:function(d,l){return e[N(1113)](d,l)},BIAzi:a(1955),WzYvv:function(d,l){return e[a(719)](d,l)}},s=4294967295;return function(d,l,h=!0){let w=a,b={OvEgu:function(g,T,O,M){return n[N(1175)](g,T,O,M)}};if(s=n[w(576)](127&d[l],0),n[w(1392)](d[l++],128))return{value:h?s:n.rGDOV(0,s),offset:l};if(s=n[w(622)](s,n[w(1086)](127&d[l],7))>>>0,n[w(876)](d[l++],128))return{value:h?s:n.uCPKZ(0,s),offset:l};if(s=n[w(1386)](n[w(622)](s,n[w(401)](n[w(911)](127,d[l]),14)),0),n[w(1392)](d[l++],128))return{value:h?s:n[w(622)](0,s),offset:l};if(s=n[w(1108)](s|(127&d[l])<<21,0),n[w(737)](d[l++],128))return{value:h?s:n[w(706)](0,s),offset:l};if(s=n[w(1386)](n[w(706)](s,n.Nhtad(15&d[l],28)),0),n[w(876)](d[l++],128))return{value:h?s:n.OjNjf(0,s),offset:l};if(n[w(847)](l+=5,d[w(690)]))if(n[w(1027)](n.BIAzi,n[w(578)]))b[w(1678)](_0x13e404,this,_0x40231e,[_0x12b18f,_0x1bc63f,_0x3c2361,_0x4a0f75,_0x3d4ef2,_0x37ec8d]);else throw l=d[w(690)],n.aNWxD(Dp,l,10,d[w(690)]);return{value:h?s:n.WzYvv(0,s),offset:l}}})();let Fp=16,pa=32;function Up(a){let n=t,s=0,d={};for(let l=0;l<a[n(690)];l++)d[a[l][n(1075)+n(1171)]]=e[n(627)](nu,a[l][n(1075)+"ame"]),s+=e[n(524)](14,d[a[l][n(1075)+"ame"]]);return[s,d]}function au(a,n,s){let d=t,[l,h]=e[d(1272)](Up,a),w=e[d(867)](zp,l),b=0;return a[d(417)](g=>{let T=d,O=e[T(1508)][T(1102)]("|"),M=0;for(;;){switch(O[M++]){case"0":console.log(e[T(1005)],g,g.service);continue;case"1":b=e[T(516)](ha,h[g[T(1075)+"ame"]],w,b);continue;case"2":b=e[T(484)](Pp,w,b,g[T(843)]||0);continue;case"3":b=e.WgoRB(Mp,fe[T(411)+"er"](g[T(1034)]||n),w,b);continue;case"4":console.log(T(843),b);continue;case"5":console.log(e[T(1289)],b);continue;case"6":console[T(1915)](e[T(1084)],b);continue;case"7":b=e[T(1855)](ha,0,w,b);continue;case"8":console.log(T(1481)+T(1309),b);continue;case"9":console[T(1915)](e.xxlps,b);continue;case"10":b=e[T(1880)](Lp,g[T(1075)+T(1171)],w,b);continue}break}}),{frameType:pa,headers:[{key:d(838)+d(1718),value:s}],payload:w}}function qp(a){let n=t,s=0,d=[];for(;e[n(965)](s,a.byteLength);){let{offset:l}=xa(a,s);s=l;let h={cursor_name:"",cursor:0,service:0},{value:w,offset:b}=e[n(1983)](Op,a,s);h.service=w,s=b;let{value:g,offset:T}=e[n(1057)](xa,a,s);s=T,h[n(1075)+n(1171)]=e.QWTcy(ru,a,s,e[n(996)](s,g)),s+=g;let{value:O,offset:M}=e.RqYgj(Np,a,s);h.cursor=O[n(1661)](),s=M,d[n(1680)](h)}return d}function Gp(){let a=t;return e[a(1969)](e[a(1030)],e[a(1777)])?this[a(1751)]?this[a(1751)][a(884)+"pe"]:this["_binaryT"+a(715)]:{frameType:pa,headers:[{key:e[a(615)],value:a(1535)+a(799)}],payload:void 0}}class Hp{constructor(n,s,d){let l=t;this[l(928)+l(1540)]=n,this["_cursorF"+l(652)]=s,this[l(665)+l(1416)]=d,this._qosDB=e[l(774)](su,this[l(928)+"ameSpace"],e.ziYYD)}async[t(495)](){await this[t(626)].openDB()}async[t(351)+"rs"](){let n=t;if(!this._qosDB.isReady)return;let s=this["_message"+n(1416)],d=await this._qosDB[n(1545)]();switch(console.log(e.XGgSj,d),s){case n(1173):return d&&d[n(690)]?au(d,0,this[n(1558)+n(652)]):void 0;case e.UvAyY:return;case e[n(629)]:return d&&d[n(690)]?e[n(747)](au,d,0,this[n(1558)+n(652)]):e[n(1419)](Gp)}}async set(n,s,d){let l=t;return console[l(1915)](e[l(923)],n,s,d),this[l(626)][l(1403)]({cursor_name:n,cursor:s,service:d})}async[t(936)+"rs"](n){let s=t,d=qp(n);for(let l of d)if(e[s(621)]===e[s(621)])console[s(1915)](e[s(1002)],d),await this[s(626)][s(1403)](l);else return _0xbcc489?.find(h=>h.key===_0x30f49c)?.[s(1669)]}async[t(1004)](n){let s=t,d={MJEgr:function(l,h,w){return e[N(1126)](l,h,w)},rEimQ:function(l,h,w,b){return l(h,w,b)},ANcCj:function(l,h){return e[N(794)](l,h)}};if(e[s(1300)]("HTIhV",e[s(466)])){let{offset:l}=YzeBFH[s(658)](_0x44eb94,_0x431ddf,_0x1ddff4);_0x55f345=l;let h={cursor_name:"",cursor:0,service:0},{value:w,offset:b}=YzeBFH.MJEgr(_0x2a9944,_0x5ca7c0,_0x53f3c7);h[s(843)]=w,_0x15c528=b;let{value:g,offset:T}=YzeBFH[s(658)](_0x217a7c,_0x8c1847,_0xbd3912);_0x59d1aa=T,h.cursor_name=YzeBFH[s(564)](_0x497a49,_0x3cba87,_0x2f3668,YzeBFH[s(1299)](_0x42db5e,g)),_0x39ca20+=g;let{value:O,offset:M}=YzeBFH[s(658)](_0x107b64,_0x3135eb,_0x13158b);h[s(1034)]=O[s(1661)](),_0xe78d27=M,_0x2070fd.push(h)}else return(await this[s(626)][s(1004)](n))?.cursor}async[t(1591)](){let n=t;await this[n(626)][n(1591)]()}[t(1924)+t(1846)+t(352)](n){let s=t;if(e.TCePl(e[s(798)],e.NKTmd))this[s(1558)+s(652)]=n;else{let d=/(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(_0x4e28c4),l=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[s(1170)](_0xe041eb);return d?e[s(816)](_0x3ff8a5,_0x2a0498):l?_0x16b22e(_0xe6f765):e[s(1835)]}}get[t(384)](){let n=t;return this._qosDB[n(384)]}}let jp=e[t(708)];async function cu(a){let n=t,s={eREor:function(b,g){return b>>>g},IyUTx:function(b,g){return e[N(539)](b,g)},lNLiy:function(b,g){return e[N(1383)](b,g)},kRKVl:function(b,g){return e[N(1948)](b,g)},LZgrd:function(b,g){return e[N(877)](b,g)},tVJKh:function(b,g){return e[N(819)](b,g)},Nexap:function(b,g){return b>>>g},llzkZ:function(b,g){return b&g}};if(!this[n(1312)][n(793)+"S"])return null;let{aID:d,fpID:l,messageStrategy:h}=this[n(1312)],w=e[n(587)](a,jp);try{if(this[n(602)+n(463)])if(e[n(1256)]("ICmKV",n(508)))a&&this._cursorManager[n(1924)+n(1846)+n(352)](a);else{let b=this[n(1281)],g=this[n(542)];return[RbmkpX[n(1676)](b,24),RbmkpX[n(1337)](RbmkpX[n(518)](b,16),255),RbmkpX[n(1968)](RbmkpX[n(1676)](b,8),255),RbmkpX[n(1968)](255,b),g>>>24,RbmkpX[n(1424)](RbmkpX[n(575)](g,16),255),RbmkpX[n(1337)](RbmkpX[n(1641)](g,8),255),RbmkpX.llzkZ(255,g)]}else this[n(602)+n(463)]=new Hp(l+"_"+d+"_"+w,w,h);return this[n(602)+n(463)][n(384)]||await this[n(602)+n(463)][n(495)](),this[n(602)+n(463)]}catch{return null}}async function Wp(a,n){let s=t,d=e[s(1310)](nn,a[s(933)][s(469)],e[s(710)],"-1"),l=e[s(406)](nn,a[s(933)].headers,e[s(1390)],"1"),h=e.bStRS(tr,a.message[s(469)],e[s(803)]),w=Number(e[s(979)](tr,a[s(933)][s(469)],s(1935)+s(1651)))||0,b=fa.call(this,a),g=e.XkkWp(nn,a[s(933)].headers,e[s(592)],"2"),T=e.qyqGh(tr,a.message[s(469)],e[s(364)]),O=e[s(1537)](Number,e[s(394)](tr,a[s(933)].headers,e[s(650)]));if(b[s(1241)])return n();let M=b[s(1082)+s(1754)]?await ou[s(486)](this):null;if(a.message[s(843)]>0&&l&&!d||e[s(1974)](a[s(933)][s(843)],0)){if(h&&b[s(1082)+s(1754)]&&M)return!!!await M[s(1004)](h)&&(this[s(548)+s(1096)+"Event"](a),await M[s(1403)](h,e[s(1496)](Date[s(930)](),w))),e[s(462)](n);if(g){let V=await cu[s(486)](this);if(!V)return this[s(548)+s(1096)+s(1850)](a),e.bJEgw(n);let j=await V[s(1004)](T)??-1;if(e.cYHUL(j,O))if(e[s(1098)]===e.yLRla){let ee=_0x413038[s(866)];if(e.HkKhn(e[s(1677)](ee,_0x4b8d57),_0x45438a[s(1048)]))throw new _0x3f78ca(e[s(450)]);return _0x3adf5e[s(866)]+=_0x36bd2b,ee}else this[s(548)+s(1096)+s(1850)](a),V[s(1403)](T,O,a[s(933)][s(843)]);else throw new Error(s(1041)+s(1275)+s(1750)+O+(" larger "+s(1827)+"al cursor ")+j);return e.LrPba(n)}return this[s(548)+s(1096)+s(1850)](a),n()}}async function Kp(a,n){let s=t,d=fa.call(this,a);if(!d[s(1082)+s(1754)])return e[s(1453)](n);let l=await ou[s(486)](this);if(d[s(1101)+s(1681)+"age"]&&d[s(1109)+"s"][s(690)])for(let h of d[s(1109)+"s"])await l[s(569)](h);e[s(1246)](n)}async function $p(a,n){let s=t,d={DPRIQ:function(l,h,w){return e[N(437)](l,h,w)}};if(e[s(671)](e[s(1945)],s(712))){let l=IOBUvZ.DPRIQ(_0x3d88ef,_0x500d09,_0x129f76[s(690)]);_0x394136[s(1869)][s(1403)](_0x4dec71,l)}else{let l=a[s(933)].frameType===Fp,h=a[s(933)][s(1625)+"e"]===pa;if(e[s(1776)](!l,!h))return e[s(837)](n);let w=e[s(751)](tr,a[s(933)][s(469)],e.mgLgS);if(!w)return n();let b=await cu[s(486)](this,w);if(!b)return e.KLZeR(n);if(l){let g=await b.getCursors(),T={frameType:g?.[s(1625)+"e"],SeqID:fe.fromNumber(this[s(1849)]++),LogID:fe.fromNumber(this[s(1312)][s(950)+"erator"]()),service:9e3,method:5,headers:g?.[s(469)],payload:g?.[s(439)]},O=e[s(1287)](S,T);this[s(1751)]&&this[s(1751)][s(1059)+"te"]&&this[s(1751)][s(1671)](O)}if(h){let g=a[s(933)][s(439)];g&&b[s(936)+"rs"](g)}}}let Vp=async function(a,n){let s=t;this[s(638)]=!1,e[s(816)](clearTimeout,this[s(967)+s(429)+s(1858)]),e[s(1419)](n)},Yp=async function(a,n){let s=t;if(!this._ws||e[s(1715)](this._ws.readyState,this[s(1389)]))return e[s(724)](n);let{pingInterval:d}=this._options;this[s(999)+s(1174)]?.[s(811)+"pointCon"+s(1963)]();for(let h=0;h<this._messageQueue[s(690)];h++){let w=this[s(665)+s(573)][h];if(e[s(692)](this[s(1751)].readyState,this[s(1389)])&&w!==null)this[s(1751)]&&this[s(1751)][s(1671)](w),this["_message"+s(573)][h]=null;else break}this[s(665)+s(573)]=this[s(665)+"Queue"][s(507)](h=>!!h),this[s(802)+s(1050)+"Id"]=e[s(451)](setTimeout,()=>this[s(365)](),d),this[s(548)+s(1805)+"nt"](a),this[s(677)+"er"]&&this._ws&&(this[s(1751)][s(884)+"pe"]=this["_binaryT"+s(715)]);let l=this[s(999)+s(1174)]?.[s(1847)+s(362)+"nt"]();this[s(1032)]("open "+l+s(1360)),e[s(694)](n)},Zp=async function(a,n){let s=t,d=this[s(999)+s(1174)]?.["getCurre"+s(362)+"nt"]();this._debug(s(1236)+d),n()};class Jp extends da{constructor(n){let s=t,d={tbIfW:function(l,h){return e[N(436)](l,h)},yhPHm:function(l,h){return e.NOgqM(l,h)},UzjIy:s(1243),YlxPq:e[s(1333)],CVTzK:function(l,h,w){return e[s(451)](l,h,w)},JXJpT:e[s(583)],CCwoE:function(l,h){return e[s(1624)](l,h)},LuSgD:function(l,h,w){return e.sztfZ(l,h,w)}};if(e[s(1356)](e[s(749)],e.CQqtu)){if(e[s(1532)](s(504),typeof _0x4797c0)){let l=new _0x3d74e0(e[s(1600)](_0x36bd06,_0x41e117));return _0x286018(_0x30ec5b,l,0),l}return e[s(1406)](_0x1bc75f,_0x19d5b2)?new _0x21e439(_0x621c82):new _0x2d9947(_0x4cba79.buffer,_0x17b091[s(1572)+"et"],_0x55380c[s(603)+"th"])}else{super(),this[s(474)+s(1112)+s(1686)]=!0,this[s(677)+"er"]=er,this._isNode=xp,this[s(764)+"T"]=Rn,this[s(779)+"X"]=Yr,this[s(752)+"r"]=Zr,this[s(665)+s(573)]=[],this[s(999)+"tManager"]=null,this[s(1941)+s(393)]=!1,this["_binaryT"+s(715)]=e[s(1119)],this["_connect"+s(1190)]=!1,this["_connect"+s(429)+s(1858)]=null,this[s(984)+"ctTimeou"+s(1531)]=null,this[s(802)+"gTimeoutId"]=null,this._seqId=0,this[s(638)]=!1,this._url="",this["_QoSMana"+s(1348)]=null,this[s(602)+s(463)]=null,this["_pingLos"+s(1132)]=null,this[s(616)+"ls"]=e[s(1745)],this[s(707)]=3,this[s(559)+"NG"]=0,this[s(1389)]=1,this[s(1022)]=2,this[s(513)]=b=>{let g=s;try{e[g(1884)](tu,this,b,[Vp,Yp,Zp])}catch(T){let O=at(g(1802),{message:T[g(933)],code:tn.OPEN_ERROR,error:T});this["_dispatchErrorEv"+g(769)](O)}},this[s(1538)+"ge"]=async b=>{let g=s,{pingInterval:T,pingFrequency:O}=this[g(1312)];if((e[g(758)]("hi",b[g(1738)])&&e[g(1256)](e[g(1317)],O)||e[g(1729)](e.VQiAs,O))&&(e[g(1211)](g(1015),g(1015))?(this[g(1435)+g(1975)](),this[g(1440)](g(807)+g(1230)+"s",e[g(818)]),this[g(802)+g(1050)+"Id"]=e[g(979)](setTimeout,this[g(365)][g(805)](this),T)):_0x12f025[g(786)][g(734)+"ild"](_0x50f60e)),!e[g(1219)]("hi",b.data))try{if(e[g(1176)](e[g(1660)],e[g(1815)]))return _0x5b15d0(cKZjtg[g(681)](_0x5e9608,_0x2c6cfd));tu(this,b,[Cp,Ip,Kp,$p,Wp,Tp])}catch(M){let V=e[g(1085)](at,e.bJpMl,{message:M[g(933)],code:tn[g(900)+g(1322)],error:M});this[g(548)+g(1707)+"ent"](V)}},this[s(701)]=b=>{let g=s,T=this[g(999)+g(1174)]?.checkReachMaxTries(),O=this[g(999)+g(1174)]?.[g(1847)+"ntEndpoint"]();if(T&&!b[g(933)])if(d[g(1445)](d[g(1427)],d.YlxPq)){let M=g(940)+O+(g(1986)+g(633)+"es reached");this["_dispatc"+g(1707)+"ent"](d[g(851)](at,d[g(1495)],{message:M,code:tn["MAX_RETR"+g(1895)+"R"],error:b}));return}else return this[g(626)].isReady;this._ws&&d[g(680)](this[g(1751)][g(1059)+"te"],this.OPEN)&&this._disconnect(),this[g(548)+g(1707)+g(769)](d[g(781)](at,d[g(1495)],{message:b.message,code:tn["NATIVE_E"+g(848)],error:b}))},this._onClose=async b=>{let g=s;this[g(1910)+g(646)](),this[g(1435)+g(1975)](),this[g(1239)+g(795)+"rs"](),this[g(1751)]=null,this[g(967)+g(1190)]=!1;let T=this[g(999)+g(1174)]?.[g(1408)+g(1819)+"es"]();if(!T&&this[g(501)+g(1391)]()&&!this[g(1941)+g(393)]){let O=this[g(999)+"tManager"]?.[g(1847)+g(362)+"nt"](),M=this[g(1312)][g(423)+g(1675)+g(938)](b.code,b.reason);this[g(548)+"hCloseEvent"](e.MtBuJ(xt,e.YDgcv,{code:1006,reason:b[g(493)]||g(1687)+g(1797)+"d, unkno"+g(1062)+g(1730)+"ame: "+O,willReconnect:M})),M&&this[g(967)]();return}if(e[g(1486)](1e3,b.code)&&this[g(1941)+g(393)]){this[g(548)+g(1471)+g(769)](e[g(974)](xt,e.YDgcv,{code:1e3,reason:e[g(666)]})),this["_endpoin"+g(1174)]?.[g(811)+g(1863)+g(1963)](),this[g(1563)+g(1132)]?.[g(1344)+g(545)]();return}if(e[g(1221)](1e3,b[g(862)])&&T){if(e[g(1838)]!==e.VxBdy)return this[g(626)]["clearSto"+g(464)]();{let O=this[g(999)+"tManager"]?.["getCurre"+g(362)+"nt"](),M=b[g(493)];M||(M=await e[g(973)](yp,this[g(1780)])),M=g(1687)+g(1797)+g(1604)+M+(", hostna"+g(726))+O+(g(875)+g(853)+g(823)),this[g(548)+g(1471)+g(769)](e[g(1018)](xt,e[g(1726)],{code:b[g(862)],reason:M}));let V="connect "+O+(g(1986)+g(633)+g(942)+"ed");this[g(548)+g(1707)+g(769)](e[g(685)](at,e.bJpMl,{message:V,code:tn["MAX_RETR"+g(1895)+"R"]})),this[g(999)+"tManager"]?.[g(811)+g(1863)+g(1963)](),this[g(1563)+g(1132)]?.[g(1344)+g(545)]();return}}if(e[g(1486)](1e3,b[g(862)])&&!b[g(493)]){let O=this[g(999)+"tManager"]?.getCurrentEndpoint();this["_dispatc"+g(1471)+g(769)](e[g(1483)](xt,e[g(1726)],{code:b.code,reason:g(1687)+g(1797)+g(653)+g(1062)+g(1730)+g(1263)+O})),this[g(999)+g(1174)]?.[g(811)+g(1863)+"fig"](),this[g(1563)+g(1132)]?.[g(1344)+g(545)]();return}this[g(548)+g(1471)+"ent"](b),this[g(999)+"tManager"]?.[g(811)+g(1863)+"fig"](),this[g(1563)+g(1132)]?.["resetCou"+g(545)]()},this[s(1957)]=null,this[s(454)]=null,this[s(1200)+"e"]=null,this[s(1439)]=null,this[s(1146)+"econnect"]=null,this[s(1542)+s(1023)]=null,this[s(1468)+s(1507)+s(810)+"ct"]=null,this[s(456)+"nLine"]=this[s(456)+s(654)][s(805)](this),this["_handleO"+s(1528)]=this._handleOffLine[s(805)](this),this["_handleP"+s(920)]=this[s(1573)+s(920)].bind(this),this[s(1573)+s(1756)]=this[s(1573)+s(1756)].bind(this),this[s(1312)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(514)](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.VQiAs,pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:s(614),env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:l,ws:h}=n,w=Array[s(1217)](l)?l:e[s(476)]==typeof l?[l]:[];if(!w||e[s(671)](0,w[s(690)]))throw new Error(s(745)+s(422)+s(1859));if(!e[s(1951)](gp,h))throw new Error(e.rFRNu);Object[s(937)](this._options,n),this[s(999)+s(1174)]=new eu(w,this[s(1312)][s(1778)+"es"]),this[s(1563)+"sCounter"]=new _p(this._options[s(669)+"Count"]),this[s(1312)][s(418)+s(817)]&&(this._isInit=!0,this._connect()),this[s(1312)]["listenNe"+s(577)+s(534)]&&(this[s(764)+"T"]||this._isMiniWX?this[s(623)+"etWorkCh"+s(600)]():this[s(677)+"er"]&&this[s(777)+s(1438)+s(776)]())}}[t(456)+t(654)](){let n=t;this[n(1312)]["disableAutoRecon"+n(1120)]||this[n(1941)+"osed"]||this[n(778)+n(604)]()}[t(456)+t(1528)](){let n=t;this[n(1886)+n(1262)+"t"]();let s=e[n(1714)](ca,e[n(824)],{message:n(1774)+n(944)+n(1561)+"ct"});this[n(1468)+"mediatelyReconnect"]&&this[n(1468)+"mediatelyReconnect"](s)}[t(777)+t(1438)+"Listener"](){let n=t;this._isBrowser&&window["addEvent"+n(776)](e[n(581)],this[n(456)+n(654)]),this[n(677)+"er"]&&window["addEvent"+n(776)](n(1494),this["_handleO"+n(1528)]),this._isBrowser&&window.addEventListener(e[n(865)],this[n(1573)+n(920)]),this[n(677)+"er"]&&window[n(1093)+n(776)](e[n(1703)],this[n(1573)+n(1756)])}[t(935)+"balEvent"+t(776)](){let n=t;this[n(677)+"er"]&&window["removeEv"+n(1178)+n(757)](e[n(581)],this[n(456)+n(654)]),this._isBrowser&&window["removeEv"+n(1178)+n(757)](e[n(1473)],this[n(456)+n(1528)]),this[n(677)+"er"]&&window["removeEv"+n(1178)+n(757)](e[n(865)],this[n(1573)+n(920)]),this._isBrowser&&window[n(744)+n(1178)+"ner"](n(991),this[n(1573)+n(1756)])}[t(1573)+t(920)](n){let s=t;!n[s(1981)+"d"]&&(this._isBrowser&&window[s(744)+s(1178)+s(757)]("pagehide",this[s(1573)+"ageHide"]),this[s(677)+"er"]&&window[s(744)+s(1178)+s(757)](e[s(1703)],this[s(1573)+s(1756)]),this[s(1662)]()),this[s(677)+"er"]&&window[s(744)+"entListener"](e[s(581)],this[s(456)+"nLine"]),this[s(677)+"er"]&&window[s(744)+"entListe"+s(757)](e.fUHUv,this[s(456)+s(1528)])}[t(1573)+t(1756)](n){let s=t;n[s(1981)+"d"]&&(this[s(501)+s(1391)]()&&(!this[s(1751)]||this[s(1751)][s(1059)+"te"]!==this[s(1389)]||e[s(790)](this[s(1751)][s(1059)+"te"],this[s(559)+"NG"]))&&this[s(456)+s(654)](),this[s(677)+"er"]&&window[s(1093)+s(776)](e[s(581)],this["_handleO"+s(654)]),this[s(677)+"er"]&&window[s(1093)+"Listener"](e[s(1473)],this[s(456)+s(1528)]))}async[t(1201)+t(1167)](n){let s=t,{fpID:d,deviceID:l,bddID:h,ttwID:w,accessKey:b,aID:g,customParams:T={},enableAutoAck:O,enableQoS:M,QoSLevel:V,env:j}=this[s(1312)],ee,Pe,Ze;this._isBrowser||this[s(779)+"X"]||this[s(764)+"T"]?(ee=location&&e[s(387)]==location.protocol?e[s(1072)]:e[s(412)],Pe=n[s(1617)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),Ze=/^wss(.*:\/\/)/[s(1170)](n)?n:""+ee+Pe):(ee="wss://",Pe=n[s(1617)](/(^http)((?:[s]*:\/\/))/,""),Ze=/(^ws)((?:[s]*:\/\/))/[s(1170)](Pe)?Pe:""+ee+Pe);let zt=h?s(1054):w?e.hQPds:e[s(845)],is=h||w||l;if(e[s(415)](!is,!zt))throw new Error(e[s(1363)]);let du=e[s(355)](e[s(1188)],typeof T)?await e[s(1246)](T):T,Xp=j?e[s(1556)](wp,j[s(668)],j[s(1950)]):{},ga=Object.assign({device_platform:e[s(770)],version_code:e[s(667)],access_key:b,fpid:d,aid:g,[zt]:is,xsack:O?1:0,xaack:O?1:0,xsqos:M?1:0,qos_level:M?V:void 0,qos_sdk_version:2,...Xp},du),Qp=Object.keys(ga).reduce((ma,wa)=>ga[wa]!==void 0?""+ma+(ma?"&":"?")+wa+"="+ga[wa]:ma,"");return Ze+s(1763)+Qp}async[t(967)](){let n=t,s={dzpRF:function(d,l){return e[N(436)](d,l)},mthjt:n(397),tGNEM:e[n(796)],riFAg:n(807)+n(1168)+"t"};if(e[n(1444)]!==e[n(1444)])s.dzpRF(_0x52e42a,s.mthjt),this[n(1235)](s.tGNEM,_0x1129f5),this[n(1235)](s.riFAg,_0x33bc8a);else{if(this[n(967)+n(1190)]||this["_readyCl"+n(393)])return;this[n(967)+"Lock"]=!0;try{let d=this._endpointManager?.[n(1334)+n(1264)+"ointReachedMaxRe"+n(1365)](),{timeoutInterval:l}=this[n(1312)];if(d)if(e.mVIxr(e[n(1978)],n(1656))){let w=this._endpointManager?.[n(1847)+n(362)+"nt"](),b=this["_endpoin"+n(1174)]?.[n(1536)+"ackupEnd"+n(1843)+n(1257)+n(1874)](),g=this[n(999)+"tManager"]?.["getCurrentEndpoi"+n(1244)+"ount"]();if(b){let T="connect "+w+(n(885)+n(875)+"tries re"+n(1499)+n(1783)+n(971)+n(1845))+b+" to retry",O=e.UWDTc(at,e[n(583)],{message:T,code:tn[n(1744)+n(1895)+"R"]});this[n(1032)](T),this[n(548)+n(1707)+n(769)](O),this._url=await this[n(1201)+"eUrl"](b),this[n(1032)](n(940)+b+" "+g+" times"),this["_removeW"+n(795)+"rs"]()}else{let T=n(940)+w+(n(885)+n(875)+n(853)+"ached");this[n(1032)](T),this[n(548)+n(1707)+n(769)](e.MKcru(at,n(1802),{message:T,code:tn["MAX_RETR"+n(1895)+"R"]}));return}}else return;else{let w=this[n(999)+n(1174)]?.[n(1847)+"ntEndpoi"+n(1182)+n(1752)](),b=this[n(999)+"tManager"]?.[n(1847)+n(362)+"ntTriesC"+n(647)]();this[n(1780)]=await this[n(1201)+n(1167)](e.gbNUx(w,"")),this._debug(n(940)+w+" "+b+n(1683)),this[n(1239)+n(795)+"rs"]()}if(this._isInit)this[n(638)]=!1;else{let w=e.dXGKe(ca,e[n(824)],{message:e[n(825)]});this[n(1146)+n(604)]&&this.onStartReconnect(w)}let h=this[n(999)+"tManager"]?.[n(1847)+n(362)+n(1244)+n(647)]()||0;e.rKfog(h,1)&&await this[n(1016)](e[n(850)](h,1)),this[n(1032)]("connecti"+n(1489)+this._url+(n(1909)+"ls: ")+this[n(616)+"ls"]),this[n(1751)]=pp({url:this._url,protocols:[this[n(616)+"ls"]],headers:this[n(1312)][n(1123)+n(659)+"s"][n(1720)+n(1568)]},this[n(1312)].ws),(this._isBrowser||this[n(752)+"r"])&&this[n(1751)]&&(this[n(1751)][n(884)+"pe"]=this[n(1766)+"ype"]),this["_addWsLi"+n(1137)](),this[n(967)+"ionTimeo"+n(1858)]=e[n(1405)](setTimeout,this[n(1697)+"ut"][n(805)](this),l)}catch(d){throw this["_connect"+n(1190)]=!1,d}}}[t(1910)+"mer"](){let n=t;clearTimeout(this[n(967)+"ionTimeo"+n(1858)]),this["_connect"+n(429)+n(1858)]=null}[t(1435)+t(1975)](){let n=t;clearTimeout(this[n(802)+"gTimeoutId"]),clearTimeout(this["_reconnectTimeou"+n(1531)]),this["_pingPon"+n(1050)+"Id"]=null,this["_reconne"+n(1634)+n(1531)]=null}_debug(...n){let s=t,d={xRstU:e.cnPKi,yiMvD:function(l,h){return e.XCBsM(l,h)},CqYLw:function(l,h){return e[N(1452)](l,h)},ZGyBV:function(l,h){return e.FIffO(l,h)},QaTEF:function(l,h){return e.xooHF(l,h)},ZDSGw:function(l,h){return e.Ejuxy(l,h)},bWUuU:function(l,h){return e[N(1177)](l,h)},HzXgq:function(l,h){return e[N(1319)](l,h)},gZQMi:function(l,h){return l|h},oeBcI:function(l,h){return e.gbxtj(l,h)},KYOHi:function(l,h){return e[N(459)](l,h)},CEyYl:function(l,h){return e[N(1259)](l,h)},arCpt:function(l,h){return e[N(1621)](l,h)},JglAL:function(l,h){return e.Ifuld(l,h)},tzVAb:function(l,h){return e[N(682)](l,h)}};if(e.NOgqM("yOpBO",e[s(1762)])){let l=d[s(906)][s(1102)]("|"),h=0;for(;;){switch(l[h++]){case"0":if(uvfzxD.yiMvD(_0x29a1b7+=5,_0x146411.length))throw _0x56f12b=_0x365ec8[s(690)],_0x855ca1(_0x521be7,10,_0x2f1605[s(690)]);continue;case"1":_0x117d32=uvfzxD[s(754)](127&_0x1136da[_0x135b37],0);continue;case"2":if(uvfzxD[s(1346)](_0x512eb0[_0x1110e6++],128))return{value:_0x5db605?_0x3dbebf:uvfzxD.QaTEF(0,_0x581f7b),offset:_0x10add0};continue;case"3":_0x2e2165=uvfzxD[s(754)](uvfzxD[s(584)](_0x58af11,uvfzxD.bWUuU(15,_0x3abc4d[_0x577c9e])<<28),0);continue;case"4":return{value:_0x1a7ba9?_0x16ac39:uvfzxD[s(649)](0,_0xbed499),offset:_0x5b7f74};case"5":_0x2da580=uvfzxD.ZDSGw(_0x3f4694,uvfzxD[s(1001)](uvfzxD[s(1696)](127,_0x27cfe4[_0x512af6]),21))>>>0;continue;case"6":if(uvfzxD[s(1346)](_0x5ada76[_0x384fa2++],128))return{value:_0x333f1b?_0x4d1587:uvfzxD[s(1117)](0,_0x3b4caa),offset:_0x4dfb21};continue;case"7":_0xe1b5b2=uvfzxD[s(1026)](uvfzxD.QaTEF(_0xb0d3ff,uvfzxD[s(1724)](uvfzxD[s(1696)](127,_0x7a273[_0x2578c7]),7)),0);continue;case"8":if(uvfzxD[s(1346)](_0x4db73c[_0x2e4456++],128))return{value:_0x17b7f7?_0x3742bf:uvfzxD[s(649)](0,_0x5300bf),offset:_0x2cf496};continue;case"9":if(_0x3ea1f8[_0x2c471c++]<128)return{value:_0x54407f?_0x30db35:uvfzxD[s(1104)](0,_0x19a3c5),offset:_0x45589b};continue;case"10":if(uvfzxD[s(404)](_0x185493[_0x183687++],128))return{value:_0x32ca9c?_0x4aa920:uvfzxD[s(1104)](0,_0x4e9708),offset:_0x52ba90};continue;case"11":_0x4f4f16=uvfzxD[s(1375)](uvfzxD.tzVAb(_0x2ef3b5,uvfzxD[s(1001)](uvfzxD[s(1696)](127,_0x4a38b5[_0x1f9067]),14)),0);continue}break}}else this[s(1312)][s(1387)]&&console[s(1915)][s(1393)](console,[e[s(354)],...n])}["_getInte"+t(566)+"e"](n){let s=t,{initReconnectInterval:d,maxReconnectInterval:l,reconnectIntervalGrowFactor:h}=this[s(1312)],w=d*Math[s(1639)](h,n-1);return e[s(841)](w,l)?l:w}_ping(){let n=t;if(this[n(1751)]&&this[n(1751)][n(1059)+"te"]===this[n(559)+"NG"]){if(e.qrmNv(e[n(1110)],e[n(1037)]))return _0x3d6a52||(_0x590a89=[_0x3cc32c[n(713)+"e"][n(1067)],_0xd18e97[n(713)+"e"][n(1937)],_0x436794.prototype[n(1937)+"PrimaryKey"]]);this[n(1435)+n(1975)](),this[n(802)+n(1050)+"Id"]=e[n(1451)](setTimeout,this[n(365)].bind(this),this[n(1312)][n(1548)+"rval"]);return}if(!this[n(1751)]||this[n(1751)][n(1059)+"te"]!==this[n(1389)])return void this[n(778)+n(604)]();this[n(1751)]&&this[n(1751)][n(1671)]("hi"),this["_reconne"+n(1634)+"tId"]=setTimeout(this[n(778)+n(604)+n(929)][n(805)](this),this[n(1312)]["pingTime"+n(1550)+"val"])}[t(778)+t(604)+t(929)](){let n=t;this[n(1563)+n(1132)]?.[n(1194)](),this.emit(e[n(1503)],e[n(1080)]),this[n(1563)+"sCounter"]?.[n(1408)+n(1505)+"nt"]()?this[n(778)+n(604)]():this[n(365)]()}[t(501)+t(1391)](){let n=t;return this[n(764)+"T"]||this[n(779)+"X"]?this[n(474)+n(1112)+n(1686)]:(this[n(677)+"er"]||this._isWorker)&&this[n(1312)][n(833)+n(577)+n(534)]?navigator.onLine:!0}[t(778)+"econnect"](){let n=t,s={pYDMn:function(d,l){return e[N(664)](d,l)},idkGE:function(d,l){return e[N(787)](d,l)},hBall:function(d,l){return e.PyYFB(d,l)}};if(e[n(512)](e[n(881)],e[n(1773)]))return _0x5ca237.isLong(_0xf9afc2)||(_0x2aa0b8=_0x1f23fe[n(411)+"er"](_0x3c8251)),this[n(1425)]!==_0x8bc099[n(1425)]&&fYdQyx[n(475)](fYdQyx[n(1953)](this[n(1281)],31),1)&&fYdQyx.pYDMn(fYdQyx[n(1434)](_0x39098d[n(1281)],31),1)?!1:fYdQyx[n(475)](this[n(1281)],_0x13106d[n(1281)])&&fYdQyx[n(475)](this[n(542)],_0x1dd67f[n(542)]);if(!this["_navigat"+n(1391)]()||this[n(1941)+n(393)])return;this[n(999)+n(1174)]?.[n(811)+n(1863)+"fig"](),this["_pingLos"+n(1132)]?.[n(1344)+n(545)](),this._ws?this[n(1861)+n(1583)](1001,e.ENdNO,!0):this[n(967)]()}[t(623)+t(995)+t(600)](){let n=t;this[n(764)+"T"]?tt[n(1597)+n(1328)+n(1614)](({isConnected:s})=>{let d=n;this[d(474)+d(1112)+d(1686)]=s,s?this[d(456)+"nLine"]():this[d(456)+d(1528)]()}):this[n(779)+"X"]&&wx[n(1597)+"kStatusC"+n(1614)](({isConnected:s})=>{let d=n;this[d(474)+d(1112)+"line"]=s,s?this[d(456)+"nLine"]():this[d(456)+d(1528)]()})}[t(1016)](n){return new Promise(s=>{let d=N;e[d(1521)](setTimeout,s,this[d(976)+d(566)+"e"](n))})}["_disconn"+t(1583)](n=1e3,s="",d=!1){let l=t;this[l(1751)]&&this[l(1886)+"WebSocket"](n,s,d)}[t(1697)+"ut"](){let n=t,s=this["_endpoin"+n(1174)]?.getCurrentEndpoint();this[n(1032)](n(940)+s+n(885)),this[n(1861)+n(1583)](1001,e[n(368)],!0)}[t(840)](n){let s=t,d={tdccS:function(l,h){return e[N(488)](l,h)}};if(e.WcVdd(s(921),e.wkSIx)){let l=e[s(686)](Bt,n);this._ws&&e.JRNVl(this[s(1751)][s(1059)+"te"],this.OPEN)&&(this[s(1751)]&&this[s(1751)].send(l),this[s(1032)](s(1514),n))}else return _0x174855.writeUint8?_0x5f3582[s(1025)+"t8"](_0x1bdb89,_0xccd6e7):_0x2393e6[_0x3425d7]=255&_0xba089a,LYKIuk[s(1879)](_0x5c1d00,1)}[t(1239)+t(795)+"rs"](){let n=t,s={vCwET:function(d,l){return d<l},fDJXX:function(d,l){return e[N(740)](d,l)},MkKPw:function(d,l){return e[N(780)](d,l)},JnDHf:function(d,l){return d&l},HJGoq:function(d,l){return e.Zogvo(d,l)},OfCZz:function(d,l){return e[N(570)](d,l)},RxDBn:function(d,l){return e[N(983)](d,l)},RsKme:function(d,l){return e[N(1274)](d,l)},qhEdI:function(d,l){return d&l},aiwVa:function(d,l){return e[N(1091)](d,l)},RByTf:function(d,l){return e[N(939)](d,l)},oQNFd:function(d,l){return d>>l},HOlit:function(d,l){return e[N(1295)](d,l)},OvUni:function(d,l){return e[N(1417)](d,l)},zbASS:function(d,l){return e.ojXfi(d,l)}};if(e[n(1374)](e[n(1349)],e[n(1349)]))_0x5e2f09=_0x581556[n(1500)+"At"](_0x20ee68),gQYVRK[n(783)](_0x14e8bb,128)?_0x6e5d6[_0x1d0418++]=_0x59b1ea:gQYVRK[n(491)](_0x2e0da9,2048)?(_0x3f17ac[_0x18ebbd++]=gQYVRK[n(1069)](_0x7d98d4>>6,192),_0x77a289[_0x598085++]=gQYVRK.JnDHf(63,_0x491ec4)|128):gQYVRK[n(800)](64512,_0x449bf5)===55296&&gQYVRK[n(487)](64512&(_0x3220e2=_0x51de9a[n(1500)+"At"](gQYVRK[n(951)](_0x31cfd6,1))),56320)?(_0x4743db=gQYVRK[n(951)](65536,gQYVRK[n(809)](gQYVRK[n(800)](1023,_0x30314c),10))+gQYVRK.qhEdI(1023,_0x55c2bc),++_0x59770b,_0x54504d[_0x9e56c6++]=gQYVRK.aiwVa(_0x4fa4e8>>18,240),_0x441f2f[_0xfacc53++]=gQYVRK.aiwVa(gQYVRK[n(1765)](_0x4891f7>>12,63),128),_0x403176[_0x393a9e++]=gQYVRK[n(1657)](_0x52d43b,6)&63|128,_0x552a73[_0x4cb443++]=gQYVRK[n(1741)](gQYVRK[n(1090)](63,_0x34af06),128)):(_0x3c4339[_0x55da05++]=gQYVRK[n(1741)](gQYVRK[n(1916)](_0x30feca,12),224),_0x5af96d[_0x1b3cad++]=gQYVRK.aiwVa(gQYVRK[n(1973)](gQYVRK[n(739)](_0x1b128f,6),63),128),_0x280737[_0x166c68++]=gQYVRK[n(1765)](63,_0x273fe5)|128);else{let d=e[n(947)][n(1102)]("|"),l=0;for(;;){switch(d[l++]){case"0":this._ws["removeEv"+n(1178)+n(757)](e[n(583)],this[n(701)]);continue;case"1":if(!this[n(1751)])return;continue;case"2":this[n(1751)][n(744)+"entListe"+n(757)](e[n(1125)],this[n(513)]);continue;case"3":this._ws[n(744)+"entListe"+n(757)](e[n(1726)],this._onClose);continue;case"4":this[n(1751)][n(744)+"entListe"+n(757)](e[n(756)],this[n(1538)+"ge"]);continue}break}}}[t(1396)+"steners"](){let n=t,s=e[n(868)].split("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1751)][n(1093)+"Listener"](e[n(1726)],this[n(446)]);continue;case"1":if(!this[n(1751)])return;continue;case"2":this._ws[n(1093)+n(776)](e[n(756)],this[n(1538)+"ge"]);continue;case"3":this[n(1751)][n(1093)+n(776)](e[n(583)],this[n(701)]);continue;case"4":this[n(1751)][n(1093)+n(776)](e[n(1125)],this[n(513)]);continue}break}}[t(589)+t(1033)](n=1e3,s=""){let d=t;if(d(426)!==e.nmuwN)try{this[d(1751)]&&this[d(1751)][d(1662)](n,s)}catch{}else return{frameType:_0x18c20d,headers:[{key:"cursor_f"+d(1718),value:e[d(1157)]}],payload:void 0}}[t(1886)+"WebSocket"](n=1e3,s="",d=!1){let l=t;if(this[l(1435)+l(1975)](),this[l(1910)+l(646)](),this["_removeW"+l(795)+"rs"](),this["_wsInsta"+l(1033)](1e3,s),this["_connect"+l(1190)]=!1,d&&this[l(501)+l(1391)]()&&!this["_readyCl"+l(393)]){if(this[l(999)+l(1174)]?.[l(1408)+"chMaxTries"]()){let w=this[l(999)+l(1174)]?.["getCurre"+l(362)+"nt"]();this[l(548)+"hCloseEv"+l(769)](e[l(946)](xt,e[l(1726)],{code:1006,reason:l(940)+w+(l(885)+l(875)+l(853)+l(823)),wasClean:!0}))}else{let w=this[l(1312)]["reconnec"+l(1675)+l(938)](n,s);this[l(548)+l(1471)+"ent"](e[l(864)](xt,e[l(1726)],{code:n,reason:s,wasClean:!0,willReconnect:w})),w&&this[l(967)]()}return}this[l(501)+l(1391)]()||this[l(1941)+l(393)]?this["_dispatchCloseEv"+l(769)](e[l(1280)](xt,e[l(1726)],{code:n,reason:e[l(666)]})):this[l(548)+l(1471)+l(769)](e.RrWPi(xt,e[l(1726)],{code:1006,reason:l(520)+l(1779)+l(1511)+l(1367)})),this._ws=null,this[l(999)+l(1174)]?.[l(811)+l(1863)+"fig"](),this["_pingLos"+l(1132)]?.["resetCou"+l(545)]()}["_dispatc"+t(1805)+"nt"](n){let s=t;this.emit("open",n),this[s(1439)]&&this[s(1439)](n)}[t(548)+"hMessageEvent"](n){let s=t;if(e[s(502)](e.CIcas,e[s(1666)]))this[s(1440)](e.DEgff,n),this[s(1200)+"e"]&&this[s(1200)+"e"](n);else return _0x4ba938[s(634)+"8"]?{value:_0x2ef95a[s(634)+"8"](_0x2553c4),offset:e[s(1103)](_0x30c589,1)}:{value:e[s(371)](255,_0x38b944[_0x3f49e8]),offset:e[s(804)](_0x43c74f,1)}}[t(548)+t(543)+t(969)](n){let s=t;this[s(1440)](e[s(1799)],n),this[s(1542)+s(1023)]&&this[s(1542)+s(1023)](n)}[t(548)+t(1707)+t(769)](n){let s=t;this[s(1440)](e.bJpMl,n),this.onerror&&this[s(454)](n)}[t(548)+t(1471)+t(769)](n){let s=t;this.emit(e[s(1726)],n),this[s(1957)]&&this.onclose(n)}get[t(884)+"pe"](){let n=t;return this[n(1751)]?this[n(1751)][n(884)+"pe"]:this[n(1766)+n(715)]}set[t(884)+"pe"](n){let s=t;e[s(1145)](e[s(1198)],e[s(1477)])?(this[s(1766)+s(715)]=n,this[s(1751)]&&(this._ws[s(884)+"pe"]=n)):(this[s(1440)]("ack",_0x301e0a),this[s(1542)+"eAck"]&&this[s(1542)+s(1023)](_0x5b2677))}get[t(620)+"nt"](){let n=t;return this["_endpoin"+n(1174)]?.[n(1847)+n(362)+n(1244)+n(647)]()||0}get bufferedAmount(){let n=t,s=this[n(665)+n(573)][n(1795)]((d,l)=>(d+=l&&l[n(603)+"th"]||0,d),0);return e[n(1578)](s,this._ws?this[n(1751)][n(1195)+n(1202)]:0)}get[t(558)+"ns"](){let n=t;return this._ws?this[n(1751)].extensions:""}get[t(473)](){let n=t;return this._ws?this[n(1751)][n(473)]:""}get readyState(){let n=t;return this[n(1751)]?this[n(1751)][n(1059)+"te"]:this[n(1312)][n(418)+n(817)]?this.CONNECTING:this[n(707)]}get[t(1448)](){let n=t;return this[n(1751)]?this[n(1751)][n(1448)]:this[n(1780)]}close(n=1e3,s){let d=t,l=e[d(1192)].split("|"),h=0;for(;;){switch(l[h++]){case"0":if(e[d(1992)](this._ws[d(1059)+"te"],this.CLOSED)||e.keaWA(this[d(1751)][d(1059)+"te"],this[d(1022)]))return void this[d(1032)]("close, w"+d(1575)+d(1716));continue;case"1":if(!this._ws)return void this[d(1032)](e[d(679)]);continue;case"2":this[d(1910)+"mer"]();continue;case"3":this[d(935)+d(1438)+d(776)]();continue;case"4":this["_readyCl"+d(393)]=!0;continue;case"5":this[d(1435)+d(1975)]();continue;case"6":this["_destroy"+d(1262)+"t"](n,s);continue;case"7":this[d(1929)+d(1348)]?.closeDB();continue}break}}async[t(1671)](n,s){let d=t;if(n==null)throw new Error(e[d(398)]);e[d(376)](d(727),typeof n)&&(n=JSON.stringify(n)),e[d(1689)](e[d(476)],typeof n)&&!e[d(1111)](n,ArrayBuffer)&&!(n[d(1522)]&&e[d(1340)](n[d(1522)],ArrayBuffer))&&(n=JSON.stringify(n));let l=await e[d(1600)](iu,n),h=e[d(775)](mp,n),{method:w=0,service:b=this[d(1312)][d(843)],logID:g=this[d(1312)]["logIDGen"+d(1543)](),headers:T=this[d(1312)][d(469)],payloadEncoding:O=this[d(1312)]["payloadE"+d(536)],payloadType:M=this[d(1312)]["payloadT"+d(715)],logIDNew:V=this[d(1312)][d(1984)+d(1810)][d(1043)+d(370)+d(556)+"ew"]?i(this._options[d(1984)+"Config"][d(1667)]):""}=e[d(1428)](s,{});if(!b)throw new Error(d(745)+d(1796)+" valid s"+d(1114));let j={SeqID:fe[d(411)+"er"](this[d(1849)]++),LogID:fe[d(411)+"er"](g),service:b,method:w,headers:T,payloadEncoding:e[d(898)](O,Object)?O.encoding?O[d(1864)]:"":O,payloadType:e[d(1479)](M,Object)?M[d(428)]?M[d(428)]:h:M||h,payload:l,LogIDNew:V},ee=e.ogOVq(Bt,j);return this[d(1751)]&&e[d(1433)](this[d(1751)][d(1059)+"te"],this[d(1389)])?(this[d(1751)]&&this[d(1751)][d(1671)](ee),this._debug("sent",j)):this["_message"+d(573)][d(690)]<this[d(1312)][d(1323)+d(550)+d(1106)]?(this[d(665)+d(573)].push(ee),this._debug(e[d(1038)],j)):(this[d(665)+d(573)][d(709)](),this[d(665)+d(573)].push(ee)),{seqID:this[d(1849)],logID:g,logIDNew:V}}async reconnect(n){let s=t,{url:d}=e.wLrqN(n,{}),l=Array[s(1217)](d)?d:e[s(476)]==typeof d?[d]:[];n&&Object[s(937)](this[s(1312)],n),l&&l[s(690)]?this[s(999)+s(1174)]=new eu(l,this._options.maxRetries):this[s(999)+s(1174)]?.[s(811)+s(1863)+s(1963)](),this[s(1563)+s(1132)]?.["resetCou"+s(545)](this._options[s(669)+s(966)]),this[s(1941)+s(393)]=!1,this[s(1751)]&&e[s(1715)](this[s(1751)][s(1059)+"te"],this[s(707)])?this[s(1861)+s(1583)](1e3,e[s(1512)],!0):(this[s(638)]=!0,this[s(967)]())}async[t(1065)](){let n=t;if(e[n(540)](e[n(1560)],"uxZez")){let s=_0x14b985[n(1500)+"At"](_0x17147b);e[n(1029)](s,55296)&&s<=56319&&e[n(485)](e[n(1193)](_0x4020b4,1),_0x281c96)&&(s=e.jBZGP(e[n(642)](s<<10,_0x263332[n(1500)+"At"](++_0x1297ae)),56613888)),_0x2ab314+=e[n(1554)](s,128)?1:e.hPOOg(s,2048)?2:e.xtwXL(s,65536)?3:4}else if(!this[n(967)+n(1190)])if(e[n(1229)](e.XnCCF,e[n(1523)]))_0x53aeb4["createOb"+n(1149)+"e"](_0xbacf,{keyPath:_0x245881});else{let s=e[n(567)][n(1102)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(999)+n(1174)]?.[n(811)+n(1863)+n(1963)]();continue;case"1":this._connect();continue;case"2":this[n(1941)+n(393)]=!1;continue;case"3":this[n(1563)+n(1132)]?.[n(1344)+n(545)]();continue;case"4":this[n(638)]=!0;continue}break}}}[t(1093)+t(776)](n,s){this.on(n,s)}[t(687)+"Event"](n){let s=t,{type:d}=n;this[s(1440)](d,n)}["removeEv"+t(1178)+"ner"](n,s){this[t(1235)](n,s)}[t(1582)](){let n=t,s={YKzYd:function(d,l){return e[N(1554)](d,l)},RytMS:function(d,l){return e[N(1411)](d,l)},ctPNz:function(d,l){return e[N(500)](d,l)},PnQvN:function(d,l){return d|l},MRfJM:function(d,l){return d<<l},OYIog:function(d,l){return d&l},vkdJb:function(d,l){return e.dUBEj(d,l)},UYAef:function(d,l){return d<l},OktYq:function(d,l){return e[N(1265)](d,l)},iPNue:function(d,l){return e[N(717)](d,l)},ktgLd:function(d,l){return d&l},qhOsT:function(d,l){return d&l},zIGly:function(d,l){return e[N(704)](d,l)},duXSD:function(d,l){return e[N(948)](d,l)},wzpDb:function(d,l){return e[N(511)](d,l)},twZaC:function(d,l){return e.hDMbm(d,l)},JcGLl:function(d,l){return e[N(1472)](d,l)},tbqoE:function(d,l){return d>>l},AlbeZ:function(d,l){return e.IYllz(d,l)}};if(e[n(1229)](e.FKgFo,e[n(639)]))return new Promise((d,l)=>{let h=n,w={cPwkl:function(b,g){return b(g)},bkzFr:function(b,g){return e.YcOwa(b,g)},GUAvJ:e[h(1764)],ALtqG:e[h(818)],thtOu:e.kyZkU,HqZoU:function(b,g){return b===g},QLEKz:e.ycmNI,GZUqr:function(b,g){return e[h(1761)](b,g)},oTVYI:h(958),ntpIW:e.ZAXLa};if(e[h(788)](e[h(1958)],"YZVvB")){if(VgZacC.YKzYd(_0x2397b8-_0x431313,1))return"";let b="";for(let g=_0x23f42e;g<_0x52e6e8;){let T=_0x589c17[g++];if(VgZacC.RytMS(T,127))b+=_0x390a8e.fromCharCode(T);else if(T>=192&&VgZacC[h(1129)](T,224))b+=_0x55df70[h(472)+"Code"](VgZacC[h(434)](VgZacC[h(1668)](VgZacC[h(1008)](31,T),6),VgZacC[h(1008)](63,_0x2ea5c3[g++])));else if(VgZacC[h(773)](T,224)&&VgZacC.UYAef(T,240))b+=_0x3dcbcf[h(472)+h(522)](VgZacC[h(1089)](VgZacC.OktYq(VgZacC[h(461)](15&T,12),VgZacC[h(1226)](63,_0x5983f4[g++])<<6),VgZacC[h(1285)](63,_0x3981e8[g++])));else if(T>=240){let O=VgZacC[h(1223)](VgZacC.duXSD(VgZacC[h(772)](VgZacC.iPNue(VgZacC[h(1226)](7,T),18),VgZacC[h(1668)](VgZacC[h(1226)](63,_0x1400a3[g++]),12)),VgZacC.wzpDb(VgZacC[h(374)](63,_0xac0986[g++]),6))|VgZacC[h(1226)](63,_0x38ba38[g++]),65536);b+=_0x458dac.fromCharCode(VgZacC[h(721)](55296,VgZacC[h(607)](O,10))),b+=_0x4a0c46[h(472)+h(522)](VgZacC[h(447)](56320,VgZacC[h(1008)](1023,O)))}}return b}else{this._clearPingTimer(),this[h(802)+h(1050)+"Id"]=e[h(1350)](setTimeout,this._ping[h(805)](this),this[h(1312)][h(1548)+h(1665)]);let b=()=>{let T=h;if(w[T(1191)]("TxHga",w[T(1378)]))w[T(367)](d,w[T(1878)]),this[T(1235)]("ping_once_success",b),this[T(1235)](w[T(517)],g);else{let O=_0x28bf50["deleteDa"+T(1620)](_0x53a786);return _0xc57ded&&O.addEventListener("blocked",()=>_0x220e00()),iRCKSt.cPwkl(_0x1824fe,O).then(()=>{})}},g=()=>{let T=h;w[T(1336)](w[T(1616)],w[T(1616)])?(w.GZUqr(l,w[T(1324)]),this[T(1235)](w[T(1610)],b),this[T(1235)](w[T(517)],g)):this.on(_0x470031,_0x1c2952)};this.on(e[h(796)],b),this.on(e.kyZkU,g),this[h(365)]()}});this[n(416)+n(647)]=_0x44b363,this.count=0}}})(),ve[B(1519)+B(886)]=Re["CustomCl"+B(886)],ve[B(1184)+"rorEvent"]=Re[B(1184)+"rorEvent"],ve.ErrorCode=Re[B(703)+"e"],ve[B(1850)]=Re[B(1850)],ve[B(1985)]=Re.FWS,ve[B(1962)+B(1954)+B(1122)]=Re[B(1962)+B(1954)+B(1122)],ve[B(1954)+B(1122)]=Re[B(1954)+B(1122)],ve[B(1320)+"t"]=Re[B(1320)+"t"],ve[B(624)+B(1105)]=Re["Reconnec"+B(1105)],ve[B(1636)+B(886)]=Re[B(1636)+B(886)],ve[B(1135)+B(722)]=Re[B(1135)+B(722)],ve[B(1270)+B(977)+"nt"]=Re.createMessageEvent,ve[B(914)+B(1381)]=Re["createOp"+B(1381)],ve.createReconnectEvent=Re[B(1782)+B(1039)+B(1122)],ve[B(363)+"rame"]=Re["decodedF"+B(1316)],ve[B(1530)+B(1171)]=Re[B(1530)+B(1171)];for(zo in Re)[B(1519)+B(886),B(1184)+B(722),B(703)+"e",B(1850),"FWS",B(1962)+B(1954)+B(1122),B(1954)+B(1122),"OpenEvent",B(624)+B(1105),"createCl"+B(886),B(1135)+B(722),"createMe"+B(977)+"nt",B(914)+B(1381),B(1782)+B(1039)+B(1122),B(363)+B(1316),B(1530)+B(1171)].indexOf(zo)===-1&&(ve[zo]=Re[zo]);var zo;Object[B(1602)+"operty"](ve,B(688)+"le",{value:!0})});import{existsSync as nS,openSync as rS}from"node:fs";import{mkdir as iS}from"node:fs/promises";import{dirname as sS}from"node:path";import{fileURLToPath as oS}from"node:url";function cS(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Pd(t=X()){return nS(t.libEntry)?t.libEntry:oS(new URL("../index.ts",import.meta.url))}async function Ch(t={}){let e=t.paths??X(),r=t.entryOverride??Pd(e),i=cS(e,process.env.COZE_BRIDGE_LOG_MODE);await iS(sS(i),{recursive:!0});let o=rS(i,"a"),u=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],f=nt(process.execPath,u,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[es]:"1"}});if(f.unref(),typeof f.pid!="number")throw new Error("failed to spawn daemon (no pid)");return aS.info("daemon spawned",{pid:f.pid,entry:r}),{pid:f.pid,entry:r}}var aS,es,Yo=Je(()=>{"use strict";Kt();ne();Oe();aS=q("spawn-daemon"),es="COZE_BRIDGE_DAEMON"});import{spawn as t1}from"node:child_process";import{mkdir as n1,unlink as r1,writeFile as i1}from"node:fs/promises";import{dirname as s1,join as o1}from"node:path";function Kr(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function a1(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Kr(r)}</key>
21
- <string>${Kr(i)}</string>`).join(`
20
+ `+r)}function Vn(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let l=new Error(o);Error.captureStackTrace(l,Vn),t.emit("wsClientError",l,r,e)}else Ji(r,i,o,c)}});var _h=ae(ve=>{"use strict";var B=M;(function(t,e){let r=M,i=t();for(;;)try{if(-parseInt(r(1892))/1*(-parseInt(r(958))/2)+-parseInt(r(781))/3+parseInt(r(1628))/4+parseInt(r(1590))/5*(parseInt(r(1221))/6)+parseInt(r(1334))/7*(-parseInt(r(1802))/8)+parseInt(r(1554))/9*(-parseInt(r(717))/10)+parseInt(r(736))/11*(parseInt(r(443))/12)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(Uo,842645);function M(t,e){t=t-310;let r=Uo(),i=r[t];if(M.kdyCzV===void 0){var o=function(x){let p="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",w="",_="";for(let S=0,y,v,I=0;v=x.charAt(I++);~v&&(y=S%4?y*64+v:v,S++%4)?w+=String.fromCharCode(255&y>>(-2*S&6)):0)v=p.indexOf(v);for(let S=0,y=w.length;S<y;S++)_+="%"+("00"+w.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(_)};M.TnEjZd=o,M.rMohHA={},M.kdyCzV=!0}let c=r[0],l=t+c,f=M.rMohHA[l];return f?i=f:(i=M.TnEjZd(i),M.rMohHA[l]=i),i}var Tv=Object[B(856)+B(1015)],kv=Object["getOwnPr"+B(580)+B(836)],hh=(t,e)=>function(){return t&&(e=(0,t[kv(t)[0]])(t=0)),e},Rv=(t,e)=>{let r={jTYtX:function(o,c,l,f){return o(c,l,f)}};for(var i in e)r.jTYtX(Tv,t,i,{get:e[i],enumerable:!0})};function Dv(){return dh||(dh=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Pv(){let t=B;return lh||(lh=[IDBCursor[t(319)+"e"][t(359)],IDBCursor[t(319)+"e"].continue,IDBCursor[t(319)+"e"]["continue"+t(1293)+"ey"]])}function Ov(t){let e=B,r={MbNIs:function(o,c){return o(c)},zWNzJ:function(o,c){return o(c)},zeigq:function(o){return o()},kjeQd:function(o,c){return o(c)},fRllx:function(o){return o()},Jbune:e(421),gyMyL:e(1757),nfbps:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let l=e,f={rwHYe:r.Jbune},x=()=>{let _=M;t[_(1360)+_(386)+_(895)](f[_(1522)],p),t["removeEv"+_(386)+"ner"]("error",w)},p=()=>{let _=M;r[_(806)](o,r[_(1526)](Mt,t[_(1203)])),r[_(609)](x)},w=()=>{let _=M;r[_(1897)](c,t[_(1757)]),r[_(560)](x)};t[l(1617)+l(1583)](r[l(1701)],p),t[l(1617)+"Listener"](r[l(1315)],w)});return i.then(o=>{let c=e;r[c(1341)](o,IDBCursor)&&Cd[c(1716)](o,t)})[e(896)](()=>{}),qo[e(1716)](i,t),i}function Lv(t){let e=B,r={Ftviq:e(1162),qDXdV:e(1757),hatta:e(1117),eHeiR:function(o,c,l){return o(c,l)},bMsrm:function(o,c){return o!==c},fwQsP:e(1149),uRDQg:function(o,c){return o(c)},kXFur:e(1098)+"or"};if(Go.has(t))return;let i=new Promise((o,c)=>{let l=e,f={NGWLb:function(_){return _()},zwDXB:function(_,S,y){return r[M(1094)](_,S,y)},qvsCv:function(_,S){return r.bMsrm(_,S)},MtFXc:r[l(1322)],YyCLx:function(_,S){return r[l(1417)](_,S)},QlbZe:r.kXFur,FMVMm:function(_){return _()}},x=()=>{let _=l;t[_(1360)+_(386)+_(895)](r[_(1420)],p),t[_(1360)+_(386)+"ner"](r[_(458)],w),t[_(1360)+"entListener"](r[_(1547)],w)},p=()=>{o(),f.NGWLb(x)},w=()=>{let _=l,S={NfkhE:function(y,v,I){return f[M(796)](y,v,I)},uqIHf:function(y,v){return y(v)}};f[_(778)](f[_(1436)],f[_(1436)])?(_0x38a585(_0x35e52f,32),S[_(1028)](_0x2229e6,_0x5c4f82,S[_(1805)](_0x52c16c,_0x2029cd))):(f[_(1125)](c,t[_(1757)]||new DOMException(f[_(1725)],f[_(1725)])),f[_(1804)](x))};t[l(1617)+"Listener"](r[l(1420)],p),t["addEvent"+l(1583)](r[l(458)],w),t[l(1617)+l(1583)](r[l(1547)],w)});Go[e(1716)](t,i)}function Nv(t){jo={BrsYg:function(r,i){return r(i)}}.BrsYg(t,jo)}function Mv(t){let e=B,r={xXViW:function(i,o){return i(o)},XdXbX:function(i,o){return i(o)},umEFt:function(i,o){return i===o},RQWDh:function(i,o){return i in o},VJvBy:function(i){return i()}};return r.umEFt(t,IDBDatabase[e(319)+"e"].transaction)&&!r.RQWDh(e(685)+e(939),IDBTransaction[e(319)+"e"])?function(i,...o){let c=e,l=t[c(765)](r[c(1168)](Yi,this),i,...o);return Ad.set(l,i[c(961)]?i[c(961)]():[i]),r[c(1168)](Mt,l)}:r[e(1267)](Pv)[e(972)](t)?function(...i){let o=e;return t.apply(r[o(1168)](Yi,this),i),r[o(1601)](Mt,Cd.get(this))}:function(...i){let o=e;return r[o(1601)](Mt,t[o(1072)](r[o(1601)](Yi,this),i))}}function Bv(t){let e=B,r={SPZnz:e(465),HYyHq:function(i,o){return i instanceof o},OJlvI:function(i,o){return i(o)},PVbvF:function(i,o,c){return i(o,c)}};return typeof t===r[e(1197)]?Mv(t):(r[e(842)](t,IDBTransaction)&&r[e(463)](Lv,t),r[e(1609)](ph,t,Dv())?new Proxy(t,jo):t)}function Uo(){let t=["vLjrtLG","v0TxBLK","BwLsyu0","qw9rDMq","CurywuG","DgLLCKPtt04","EKrxywC","DMjlthC","q2LIrwS","tK9lB04","q0rUy3O","z1b3tgK","z0TjzgG","qNDkzNO","D3nZoI8V","Ef9MCM9UDgK","y3vYC29Yx24","yMHVExu","rgDxvwe","DcbSAw1PDa","De1drKm","ufL1BvC","uurgEg4","BMCGB3iGyw4","x19LC01Vzhu","zgvJB2rLzey","uw5rwfe","mxWWFdn8mNW","vK1IB0K","BxnNsuq","B3noz3q","t1b6zwq","A3POBhq","shbgrfe","Aw1LCYbPBIa","ELHVEha","AgLgBe0","AMvJDfn0B3i","EfzQz0m","DgL0vKG","C1zose8","y21RA2W","qvHqshy","x0rctMfTzq","yLrfyNG","rvDYuu8","Aw5REuK","AMLsvee","Dw5KzwzPBMu","CunkvgS","tgThrKW","zNrRyLu","vML4B3e","x3jLBw92zvC","DMnUvKS","uLjpuG","sffswK0","sMj1BMu","DNLWvfu","Ec1TC2CTCw8","ANLhvuy","Cgf5Bg9Hza","z2v0q3vYC28","quvYvhK","tuzKELC","EM1JA1a","yxviA3u","CgfYC2u","x3DHAxq","y2rAvNK","CMvTB3zLq2G","BfriuMu","C2v0","BNnpq2O","uNPkDMC","qvzxB0C","zvLhAKm","Efrurw52","ExDSA3C","A1n0yxr1C0m","B2XUvu4","uwXIwMu","wxLJvMC","r0DWDhe","rNjVBNrPzxi","zMX1C2HfEha","D3m6lY8","Chv0","CNvVu2C","nxWZ","CNnxruS","vuHktgS","zefPqK4","DhjHBNnHy3q","Dvb2zMu","D1r3Afa","rKLmrv9ot1q","yxb1t2u","AxnbCNjHEq","wuDVBfu","qNvuzeS","tunNAhi","vgfN","zxj2AwnL","yNL0zu9MzNm","x3jLy29UBMu","z2v0q3vYCMu","Aw9IrLe","BMnLq2XVC2u","s2DtB2q","r0nkCfK","u1z2vxO","DevYCMK","zxjYB3i","DeLK","zevnufa","uuPHzNO","BNruCMLLC0m","uwnJBwW","BgLZDgvUtMu","CfvIu0W","tg9Nsuq","rurctKq","EKjOA3y","B3v0sw50zxi","rLrxAM8","tuDgBNC","EfHzuum","CNjVCK1LC3m","uenmyLu","ChvZAa","z0LYDeq","DMvY","BIWGAg9ZDg4","ihrPBwvZ","y29SvKW","y3jLyxrLq2W","C2vYDMvYvgK","z1rJsgG","BLzrCwi","DMntB0C","y291BNq","C3rLBMvYCW","CNvTuxO","C2vUzf9Hy2S","qMTWAw4","wgfRwLG","Ahr0Ca","Dg9Y","yM9L","we9WvKC","CgLUz0XVC3m","sfzPreK","yM9KEq","v29stue","DgvZDa","Cg5WDMm","AMzvBu8","mJCYtefczLP6","se5hDeO","rK1wtw0","Dxfjsgy","B0fvvwu","icSG","AwXK","x2rPC2nVBM4","B25Uzwn0Aw4","igzHAwWSig0","CM92AwrLigi","BgLUzq","zgXuBe0","wgDXAge","A2fWALG","rxjYB3jdB2q","CMvWBgfJzq","uK1pzNi","v2Lsvxe","CLj4seu","B2zM","ihjLy29UBMu","CMX3zuq","rgLjqxe","u2TPCcbWyxm","DejhEfC","CMvHzfvjBNq","B3nLza","uM9sseC","AMvqruu","DMfSDwu","ugLOq0i","x3DZ","qxLqCNa","zxHWB3j0CW","zvLQuxK","B0Dcs3a","CgnOA0e","zcWG","Ehr6sLK","vNzUvxm","qMTLCwy","CNzHBfzHBhu","BgvY","CunetvC","vgXtu0O","EM5AD2m","uuHREhe","y214sfa","zxjFCw9Zx2e","BwPVCNu","x2LZtwLUAvC","yLneuha","rg1Wv0q","ALfyzMG","s2zbDw8","CMvJzwL2zwq","DuPgv1G","vgLTzw91Da","yNvMzMvYzwq","uhzcCLO","r2Toz3a","uu5Nwhi","quHIrhG","zM9Yy2u","DwDcB2m","y3jLyxrLrxi","C2vYDMLJzs0","Aer4CxG","wLjrAM4","AMrMq3a","ELvuBui","qw1VDw50","BvbOrNu","x2LZqNjVD3m","u2vYDMLJzvC","v2Pyt00","EvjLy29UBMu","sfvlwNC","wNrhqNi","wfbRBxy","AuHXy2y","tg9stvG","Dg9tDhjPBMC","B2fK","C1bPAK8","B3bLBIa","DeLUDgvYy2u","Evz4Bfm","zMPqzgG","mM96z2DTuG","CMvZzxrfBMq","CuvvB2u","y2XVC2veqG","uxPYwfe","A2PLuwq","DKnHrui","zermvfC","tKfusvzfx0u","wuHyqLG","B1nXEKG","CMvZzxruCMK","A25vqLC","zxmGCMvHy2G","vLvVquu","vKzzrLi","BhjYq3G","svHUAfu","D2fZq2XLyw4","uMz1q3O","x29Ut3bLBG","uxvLDwu","s3PswNO","CgXLyxnLiha","uK90EuO","CvfrseW","v1HICM0","ChjVDg90Exa","x29UugfNzu4","zw50zwqGDhK","B25LCNjVCG","tKHNuKq","y2jztvm","vuP4q1a","ANzWC2y","rgLNrhy","zwn0","C2XPy2u","DgHHBIbSB2m","Afbcv1K","ywnRx2LK","sxD3q2m","CMvKDwnL","vw5QBw4","Dgrtu3O","Ew9NChq","swTrBLe","ywDLu2HVDW","y3jLyxrLrwW","wMHjEhm","ign1CNnVCIa","ugj0q1G","ALvSEwK","zMLUza","Cw9Z","zwvKzwq","u2XHsfO","zw50","zcWGDw5RBM8","s1Ltuw8","BML0AwfSAxO","BMvLzf9Hy2S","rK5rt00","B1jzCMW","CgvYC2LZDgu","rvjlveu","BfbuExa","ywr2yw5Jzq","Dhj1y3rVCIa","C0jYzwu","sgXqENK","yu93Bgm","BwHRrxe","svLYvvu","tw5WCgO","x2HHBMrSzva","zNjVBuHHC2G","DLbIyvm","zw5HyMXLuw8","v2PNt3K","A3HhqMu","B25nzxnZywC","BMrLEa","Bhm6ia","DgT4Dvy","mxW2Fdr8nxW","q1Pguvm","nhW1Fdb8mxW","B2LUDfjLywm","uKnbteW","C2LxDKS","B3vUDa","DLHKCNe","qKfptKS","zw50tgLZDgu","BM9Uzv9UB24","BNvTyMvY","zxrxB3jRq2G","x2nVBM5Ly3q","C3vIyxjYyxK","z21bzxC","t0PYvLK","qNrhzhG","x2LUAxq","BezSDxnO","zgf0yq","sxvuDhG","rNDpBxy","t1H4EvC","wMTfBvC","reXlC1m","vg9myvu","uxLrEKm","zxjYtxnN","EKvTwum","zgLZywjSzue","zgvSzxrL","x2nYzwf0zvm","yxbWBgLJyxq","DenowvO","Agfpv3i","C0vWrLe","AM9QCgO","yMPjv0i","uxblre0","DxrVuMvJB24","uLroBeW","wKXVwhi","zgvSzxrLrge","C3vJy2vZCW","o2nOyxjZzxq","q3D2zw0","uxb1wee","yK1IAgK","r0jXyuW","y29SBM8","DNrHvMy","vMLOq0W","yxv0BW","vujYDLC","nhWYFdb8m3W","ChjVDg9JB2W","AKH6zNm","ywnRtxnNswq","BKjNCfO","Ahr0Chm6","AwrI","q01iyM0","Exjtwxa","u0njr0W","DereCgy","mJrHz2v3yvG","q29UzMLN","sxf5uKG","x3bPBMDqB24","rvnlzwu","DhjeC1i","y0nRvMm","Dw1mtee","ve9vuvG","DKnjsfK","Ee5Iyve","rwvRve8","igzPzwXKoIa","x2LUDgvYDMe","zxjYtM8","Curyzfy","v2LIvxO","rNjRwvu","lcbTyxGGCMu","AhffqxC","t0PSDKK","AgD5CLK","zNvUy3rPB24","CMvZB2X2zq","y2T4tve","uLPevxK","qxrnsNe","C0XPC3rLBMu","ExbL","wunsvfi","A1DuDxq","A3vKs1e","rhHyAK8","r0jIA1u","CMLLC0nVDw4","sgzjuMq","CMv0CNLdB3u","CxDrALy","qNHAvwG","vLbMEuW","AxrRs2i","zLr2A2K","rhHwzK4","zg9Uzq","C3jMyLe","D24GCMvHC28","swPIwve","BKXPBMu","sw9iqNO","qLz4C1G","BMDuAw1LCG","B3f6B3C","x25HDMLNyxq","s1Dftg8","v1jWENC","DLnJrNe","yw5Nzq","qLvqufu","Ew12suS","tvDetuy","t2znsLy","q1jAsvi","yw9KD3a","u0rkr2K","uMHmr2u","B25dBg9Zzq","tfz3zxC","vfHRChG","Bwf4uMv0CMK","DuTIufq","AgfUz2u","rLDt","CKLAy2O","z3rosM0","vhD5z3y","AhniDeu","BgvUz3rO","shDiA2C","zw1PDa","x2n1CNnVCK4","qMPzvM8","u2fIwxu","BLflvKe","CgfNzxnOB3C","x0vysvnu","seDQyuG","CerhuMy","DhvUCuC","txnXt1q","x29UvgLTzw8","qwPsyMi","D0jADge","y3jLyxrLuMu","ve1yBuy","Ehnzu0S","u0LOrNu","sLPOr0i","uLrMAhu","t1bftL9fuLi","CfrVy3C","t2zrt3G","DxbKyxrLq3u","weLquLi","tLPHs2y","EwHHCNa","CNnVCL92ywW","BNrfBMrWB2K","rezVChe","z2u6ia","AwXLtMfTzq","BhrPCgXLihq","yw5ZzM9YBvq","u2PLu3q","s25Auge","CMfTzq","BwvZC2fNzq","s1PfzK8","zLjSBhG","q291BNq","zNHvzeG","yw1LoIa","Bez3ELO","y2vZC0HHBMq","zNjVBujPDhm","qNv3Evi","AwT4D1u","B2nRzxq","B2X6DNi","BgTVtvy","Aw9UvgLTzw8","ueLwB1K","C1LcC1i","ignVzgu6ia","Au5xywq","zgv2AwnLx2K","Dhr3Awq","Aw5KzxHpzG","B3bLCNr5tMe","qKXOB2i","zKnzvvK","zv90Aw1LB3u","zMzMzG","qMz0q3u","A2v1Ag4","y3jLyxrLtwu","u1vnwwC","vwvlu00","qM9eEwy","vNP1D1m","r0rkEhm","q0fNweS","zgjWs3G","wfvQs2m","DLfpCxe","ihn1y2nLC3m","CgLUz0LUDgu","Dff1wgy","r216D3G","AePcwfi","D3jPDgu","BgLry20","q3HpAxG","t0Pfr3C","Cvfwrvu","CgLUz1rPBwu","sgvhBfu","EMvPz3e","AfbdqwW","Bu9QwNu","u25TsLy","vw5Oyw5KBgu","BMThs0S","C3LgugW","lcbOB3n0BMe","Ec11C2uT","tuL5DLK","x3nVy2TLDa","zgPzseq","BhD6y3O","ChbL","yxnJCMLWDa","r3HqwNu","AhH5BNy","Aw9U","B3bLBG","z2vjBMzVu3K","thbXsuS","rgvKAwnHDgu","B25VCgvU","tuzlt2i","swzRq2e","Dgv4DfbHEwW","seLWyLm","r05Pzfe","D2Lgwui","ywXSq3vYC28","AxmGDw5Kzwy","BwDuzvy","C2HPzNq","q2DXC0K","weTYEee","ywrK","D0Xzr0m","Eu1rwNy","CYbPBNn0yw4","CMvHzhDYAxq","twvZC2fNzuu","CMfUzg9T","zfzdsKe","z0nMy3y","ywDLsgLKzq","D0D0A0C","thLXqxK","nxWWFdz8m3W","zv9ZDwnJzxm","DgPVs0e","BMrZqMS","BwvKAwf0zwW","tfHivg4","ywDLrxzLBNq","rM5YzLe","ufPtCuq","y3vYCMvUDeK","CLfUExq","B05QDLi","Cgf5Bg9Hzfq","y3vYC29Y","zKL0DM0","BxnN","ChrVCG","u2vXsuq","ywXty29Wzq","ywnOzwqSihC","AM9PBG","ENbTv2C","x3fVC0rc","x194x21Zz18","zMLSDgvY","DMvQsLG","CMvUDevUzha","EvnqvKC","A0Hkyui","B2jQzwn0u3q","DffoAvy","zufQENm","B25TzxnZywC","wg1wvKO","y2HLy2TdDxi","zNjVBNrPzxi","vfv5q3u","y29UBMvJDca","x3DZsw5ZDge","D2LSBfjLy28","zwjVt1u","zNjVBunOyxi","x21LC3nHz2u","zxjFBxnNAwq","x2LUAxrqCM8","zfDVCMTLCKC","yMXVy2TLza","CYbHBhjLywq","zwnVBM5Ly3q","whb6D3e","z2v0s2v5","BeHHBMrSzxi","Cg9W","ze9YDLO","zgvS","BxnQDvK","CungCNG","r1nmuMK","x29UtwvZC2e","vLnUr20","y29Kzq","nte5mtbhsK9Yu1C","sfzks0O","BMv3vMvYC2K","Aw47y2HHCNm","CM92AwrLige","ENDMDuW","Dg9mB3DLCKm","vMzgz3K","wxDkC2m","vKjLAe4","rvPqqNe","zhDfCei","BLb4Ag8","uujIDwm","yMrFzgLK","Euv3Ae4","x2LZtwLUAvq","CgjICdi","mdaWma","nJyXnZi3zufQvLjl","yNPRqLC","x2rItMfTzq","yLvUwvK","vg9HwNG","t0jksNy","yxnL","CuHmteO","AxnmB25N","y3jLyxrLt3a","ihrYEsbYzwm","zw5KCg9PBNq","C3rYAw5NAwy","EgHysui","Bg9IywXty28","thjoCKC","mxW0Fdb8mNW","zMvY","zgvIDwC","y29UBMvJDa","AuTiCMW","runmsgK","r1PpvLy","v3jst0K","qLrzD3q","CMvHzg9UBhK","EeXZsLi","ruD5q2q","DKX2yKG","y2fSBa","txz6v2O","DeLJwxO","sNDAtuu","BwvY","yMLUza","vxDqAMy","CM9YrxzLBNq","BM5Ly3q","zxPrqMe","vLDYt1i","CgT2s0K","wKjVEeu","CxzZq3y","AuHotwq","x2HHBMrSzvi","ndqWnJmXm3fZsfD5tW","t2vdu0u","q1LwtwC","CNLwvKS","thvXzxu","ANvrBg8","yxv0B21HDgK","AxjLza","tufyx1jfvfi","x29Uq2XVC2u","C3bNAKu","CLzsv1y","DMvUDa","DhjPzxmGCMu","ExD0v2G","ENDewei","D2zYtve","Aw5KzxG","DwL4DfO","B25mAw5L","Dw5RBM93BIa","B25tDgfYDfi","A2f0Bey","suzLqNa","DK50q3e","twjosxm","AfbIquq","uKnWEfO","zw1LBNq","wvnZzMu","CgfNzwHPzgu","x2rLyNvN","s3PwDNq","yxKSihrYEsa","rLj4Due","mhWYFdf8nhW","AxnFywnR","BwLZzq","mNWWFdf8mta","Aw9Ul2PZB24","D01oAuK","CwPZt0W","CfHMt3C","DMfS","z1z1DKO","Ae5jAfa","x2fKzfDZtgK","De1HBMfNzxi","BMDLza","id4G","revcqu8","zgjyrKi","u2vzs3a","Aw5PDcbrB1m","yw51Ce1LC3m","BwvZ","zxjFDhrS","B2zOwem","CMvWBgfJzui","CxncqvG","r0DerKS","sfL5she","DgLUzYbZzxi","yMjiy1C","DgfIyxnL","B2nRzxrtDwm","DNrjz0W","r0fcCKu","AxnrB1nnzxm","DuvABei","wejmsNK","rhzmA0W","Eufvs1y","ueLWu1G","seTquNG","zgvMAw5Luhi","zxjFCw9Z","C0nVDw50zxi","z29PBMCGyxC","yxrLq291BNq","wwPQt1K","CKrNz2K","C3r3DKq","A2PwEfq","qK9eBhC","u3bTDvG","ihzHBgLKigq","thPlvxm","v2zQvuS","CgLUz19VBMm","wLHcCLG","zvvYBa","rMP0ELC","B3DWqxa","Dw5ZAwDUzwq","nxW0","uxnmvuC","ywLfwey","x2rLC3rYB3K","Bwf4tg9ZC0m","zLf3Bwe","txbjBwS","y29UC3rYDwm","ANrbrLi","y29UDgv4Da","v2PAt3G","rxLWuu4","ywHhC0y","Berby3y","ELrqB04","ihrVihjLDhi","BMfTzq","C0fXrMO","sNnZA2y","BMvY","y2f0y2G","yLbbsxy","Dg9hzw5LCMe","AuLwwMK","igXHCMDLCIa","CfjLv1i","AePKrMW","vfPcBfm","x2nSzwfYugK","ANvAvNe","EurkEui","x3jLywr5q2W","r0fZDvq","rKXPDeO","DLHdwgy","tfL6uwC","qwPcBvu","x2XPC3rLBMu","BNrLCG","ExrNCMW","rMTss1q","BNbVBwq","tMfIsui","vNHeDwK","tvboyvK","EgDjDeK","yw5Hz2vY","vLDSz3G","CfDdu24","A2v5","sNvUBwO","Bg9Nsurhzw4","C3nHz2vfDMu","qKHjzxu","Dg5cyuu","DuTSwuW","C2v0u3rVCMe","zMzmAw5L","ANL0uuG","q1HZuhi","EfvZzuvUDG","Dgv4Dc9Qyxy","v2LUzg93","B3jLtMfTzxm","D1vPwLy","y0LxB1C","x2TLEvbHDgG","yK5Ry2C","B0fSBhq","rKPnqxK","B2TMt3u","wLLPB1q","u3rYyxrLz3K","D0jHr3u","uMnUtMy","y29UBMvJDeu","rvLbAKe","x2n1CNnVCK0","CLP4qvK","y29UBMvJDfm","A3HTB3C","x3vYBa","mtaYmJm1og95uu5UzG","BfLStLi","qwLsyxi","C29YDa","C01vsKO","Cg93","v0rJvNm","y2XLyxjtDg8","DgHsqMS","EevMuKe","C3rHCNq","DxjS","C0jf","y2LzzLO","Aw5JBhvKzxm","ywrKq291BNq","yuLwsgm","vw5PBxbSzw0","vuvRzvm","zxjFAxnFywm","q1LJtfa","CfblrMG","y01UDue","q0Dsy1e","C2niA2m","AwLsAxK","Dw50","x2jPBMfYEvq","EgTqwMS","AgvKtwf4uMu","rwLuEuO","y0vkA1O","yMfSrxzLBNq","BMLQCgy","BwvZC2fNzv8","A1HlwNe","twLZC2LUzYa","vNHSreG","rgj4y1e","uNHvqxy","EM5kDxm","x2LZsw5PDa","z2vrDwv1zuW","q3vZDg9Tq2W","ww5dEg8","B2nRzxrgywK","yuXgruO","CNnVCL9Uyw0","tvPtsue","zhnVAxq","v3v3Dxq","BwjytgG","A05vBw4","BwfUDwfSihi","ANDkDg4","q0Xpu0ve","Dfzisxi","B3bLCNr5","BhfxENq","sgjYBNK","ruXzCNO","D3jPDgvvAw4","BKLHuwq","tM9eCKu","mdaWmdaWmda","B3nLrxzLBNq","B3jRzxjhBg8","Ec1TC2CTy3u","BNLuy2S","sND3see","tMzRAeu","CLvfA0q","uxzfr0O","yLnOqvi","zw5XDwv1zq","y2XVC2u","EKvNALC","twHpqvi","x2HHBMrSzu8","q1zkEuK","rxzLBNq","qwnHq0y","AhLIq2u","AfzYugu","ywXSzwqGBxu","BMzJt3i","CgnUtgq","tufos0G","DuXKsem","sLnptLa","zKnpwg4","sMDWyMq","yxnZAwDU","C2v0q3vYC28","B25SAw5L","zxjHDg9Y","r2TQDeC","uNDqDNy","s21nDLe","ugjXAxO","EhHUsLq","AgDgyxy","ywX3yxLZ","rvjst1i","rg9yCw0","CMnVqwG","rNvIEuC","B3jL","AKn5s3i","r2HAAuq","mhWYFdn8nhW","A2HjwNq","y2HnyxHdB3u","DhjPzxm","yxbWBhK","x3bHDgHlzxK","y3vZDg9Tshq","BgL2Eg8","C29Tzq","tMjKr1K","ELP1DuG","z2v0","t1bftG","y0fzwxq","rKTKC2y","whDIuhG","ywnRDxbfBMq","x2LZtM9Kzq","vg9Ht0y","BwLUAvbYB2C","CNnVCKzPBgu","tNjTr0e","y2XVC2uSihC","rurHs1a","tKfyChe","z2v0sxrLBq","zuHLAvi","vef3u2e","CMvHC29U","zLLAz28","qwjVCNrfCNi","tvjVzNi","rvPftLG","z2PXvxC","tfPrrM0","sunJsfu","qLjSrfK","Dxrjza","Ew1KDNK","l3DZl3yY","u2X0vwG","B2XKvMvYC2K","t3bfzK4","uLLezvm","y3ruAw1LB3u","zMLN","CxPJDgy","Ce51zgW","tujwChG","ywjVCNq","AM92uwy","DeX4tgq","vgjHvuS","zM9YrwfJAa","vg5Ktuu","r29vD1i","tKrTzM8","wxLdthG","z3znyui","t3fru0G","C0Xf","BwfW","B2zMBgLUzq","EvzRyNO","y3jLyxrLt2i","BMvJDa","DfLgsgi","yMfSu2nVCgu","vunJC1i","sfviAMe","Avjlr2O","s0ruD2u","EevWvhK","ig1LC3nHz2u","ueDxv2m","zKXcB1a","zvbnsfq","zNjVBu51Bwi","DgrRr2K","CMvXDwLYzwq","swrmv0K","vMTwy3C","zhPoC0G","BMrWB2LUDca","ru9WqLe","t3jnsgm","AxbXwxi","Dg9oDw1Izxi","vLL6wKK","jMPZy2fSBgi","we9OyMi","zxDhrxO","x2rPC3bHDgm","AevYCM9Yrxy","y29TCgXLDgu","q09oveLovuu","uwjAtfu","zNjVBuj5Dgu","Dg9iyxnO","x3bYzwzPEa","EfHwAvC","rvDtvhy","q0Xpu0LorW","BxPIBeO","x2n1CNnVCKy","BhH1BeW","CKPbquu","AgPRrxG","uKfdveu","zKv5Awy","BMvnq0e","q09otKvdveK","t0TpBLe","CKrvDNi","AurPCue","m3WXFdb8nhW","s3Peug4","CMfNzvn5BMm","DhLWzq","quXm","DhbizwfKzxi","sKrOzhK","D2D3CvG","z2vY","zw5NDgG","y3vYC29Yx2y","BKD6vuC","Cw16tgC","x2vUzhbVAw4","u1bABNO","zhrwtMq","zejQDMW","BfrRC3K","DMLJzuLeig8","DuLeyKK","CMvZDwX0","yxbWzw5Kq2G","sLbZuuO","DgfYz2v0","qvHRBwm","y2HHCKnVzgu","yxvOEfu","zsbHihn0CMK","ywXSB2nvBNm","vKDUv0C","sgvusuK","tKjJzxO","q0XusMm","ywnRx2nVzgu","A3v6v0O","BMv4DcGPigm","Dev2zw50","DhjPBq","nJqYqMTPBxDl","CgXOz3K","ve5OBuO","zNjHBwvuExa","AgvHzgvYCW","CMvJzxzPzwq","Cevou2S","yNL0zuXLBMC","vMnOq2m","z2XWzvO","reTNywW","sgfiB2C","x2zVCM1HDeu","Bw95AuW","s25wr28","uMvJB25Uzwm","DMvYC2LVBG","u0nTtLy","Bwv0Ag9K","Ae9Wzw5fDMu","Cu1cv2q","B3bLBKrc","z3zuvhi","z3nwsMe","v1zNr2q","EgTbuKu","AwDHDg9Yt24","ru1jExG","C3rVCcbPBw0","zenWtgu","EuLcuvO","x3bYB3rVy28","y2HLy2Tszwe","vNL0rhq","Bwf4twvZC2e","C3rVCMu","zg1vC0e","pxv0zI04","x2nSzwfYvgK","BgLUzw5V","zhDevLe","mhWXFdn8nhW","zufJAW","AgvHzgvY","zgz3yKq","DxD1AKS","vKP2qNK","x29WDgLVBNm","tNLAywO","BeLbywO","DNjdr3e","q0PRyK8","txrrt0S","DxbNCMfKzw4","yKv0u0C","sfz0uwu","Dgv4Dc9WBge","CM9jqxm","z0Dkq0i","A0vXDLa","Cgf5Bg9Hzeu","uvvWCLe","Efv3BKu","Cvj1Cuy","z1rPBwvVDxq","B1Pxvwy","r09JD2q","z2v0qwXS","rvb3z1e","CMvZzxrdB3u","shjvzvy","Bw9bCfG","uhjPBwfYEuS","AxnszwfKEq","rfnRu3e","vhD4r3u","zK1SyLy","z2vtEw5J","DMfSDwvZ","y09Wzw4","BNLTsKC","x2LUAxrhBg8","tLjjueO","B25JBg9Zzq","B3jRig9MzMW","vfvtEwm","A1r0sem","zxH0ugf5Bg8","BwLUzW","vKzeteu","uhLkr3e","BNrbBMrvCgq","v2vIu29JA2u","D2zOs1u","z3LnEuW","t3bLBKv2zw4","suDjq0O","AxnrB1nby2S","BMrWB2LUDfq","u3jKsM0","zfvwvuG","zNDrC1a","qKPuB28","yuTYAvm","DxnVyMq","uwfLD0y","Bg93","igfYCMf5yNu","uhrVtLa","CMzLDM0","D0f5zwu","u0zwDNu","tNf1sLe","ntu5nZLNr052Eui","x21PBMLoyxy","tM94shy","wKv6yMm","reTtAhC","z2v0u3rVCMe","Cg9PBNrdB24","BMzIChm","reiGzMfPBgu","tfn0Cvu","DgHLBG","CuDyEgO","tg9NsurozxC","AwXSihvZzsa","tfrKEKC","q1P0Dgu","qMzes08","vMvPtva","zLvMrNa","teXjsNC","uw1mwKe","x3nLCuLK","C3vIC3rYAw4","vLbdELy","yNLL","BfbhDhy","CMvTB3zLrxy","x2DLBMvYyxq","rKHYC3y","CxnNr28","zw5HyMXLvhi","Afnqvwu","A2v5CW","yvH2zha","EgX5zfu","Dwfvqw8","tNfhwKC","CMvHzhLtDge","BNPQA3i","r1zWAvy","ywnOzwq","C3bSAwnL","mxW0Fdn8mhW","Cgz1BfO","BMjnrxi","tuP2zKC","zuvdt2q","yxrHlcbKyxq","Bg9NsurozxC","EvrUvgG","shHgALe","CK1Zveq","DxrMofDYAxq","BNvTtxq","sfjQBNy","q3vMBhC","t2H1qwO","C0fczwK","yNL0zxm","C09Qtu0","DwDOze0","CxjPs3q","x3nLBMrby2S","rfDxv3u","AMzKyxi","D3rhrwS","ExzOz3C","tMfTzq","y29UBMvJDgK","zw5JB2rLrNi","EMHmvva","C3vkzhq","BNvgAvi","AxLKAMy","vwfHCui","B1vVDfO","x29UrxjYB3i","BfbXtMu","AMzny3q","AgLNAa","venTBMm","ChLUvhy","CfDKENi","DvjeuwC","BMnVzgLUzW","C3bSAxq","rNr2Axe","AgXlwwO","C2vUza","vKnWu2G","BfLIvha","q29Kzq","ihzHBgLKihm","zwnyA1a","Dg9VigXHCMC","qxnNyKy","y1rXq3C","CM92AwrLihC","qM9kzhC","vNHfEfe","tuvtu0fhrv8","yMLUyxj5vhK","txrgwgm","q1ztt1i","AhviBLm","CNjjqNO","D1fYy0m","C3rYAw5N","AwXpAe0","zw5JB2rPBMC","zcbLCNjVCI4","A2DmtgC","zMLSzw5HBwu","A3bxrui","zMzLCG","twXbs2e","tev4BKy","ru1QzvK","s05eCuy","Dg5Iyxq","DxnXrhy","B0zuDMy","Dg9cExrLC0W","y3HSBwq","y0reuxm","uxftAKS","x1fVu01HBMe","DhDVCMTdAge","x3bPBMC","aaaaaaaaaaa","EuHsCM0","DxL4uvq","ihbYB3rVy28","uKXZy1O","CM92AwrLihy","tNvpD1e","CMvJB25Uzwm","C2v0y3vYC28","EK9KB2O","A2HiyuO","D1PpDLi","tg9JAW","Bg9N","tw9KDwXL","zwXPBhq","DLHQB0m","C0TZCKi","y29Uy2f0","zgrjrcWGzgu","u0Xezvm","C2v0zgi","rNritwW","vvjIDNq","zMrkwfe","rwrlufC","CMvQzwn0","EeLOtgy","qu5iBfC","x3bPBMDmB3m","uw13qwi","C3vnBgm","wKDAs2G","DeLwDwK","y3vYC29YlNm","BfrPBwvVDxq","ENLZCK8","DcbVzIbYyw4","A1PWtxG","x2LZv29YA2u","vufQBeK","rLjptLrjrvi","B25tDg9Wsw0","u3bkwwe","ywWGy3vYC28","suvtx0vsuK8","t1bArg8","s01hD0i","zw5fDMvUDa","tNHVqNK","uKzOrfi","B25ozxr3B3i","B25pCgvU","rffADMm","B25szwnLAxy","uxzdzuS","oxWXmhWWFde","C2vYDMLJzq","DLrAvhq","CNDiwwu","z090B0q","Ae1LC3nHz2u","uK1gC3O","ELDoEKO","A0jYBNa","uKDOtha","Ae5quva","vvzyDNq","wNzvt2m","vuvXANK","EMPVuei","yNvMzMvY","CMrIthG","zgP0sgC","Dg9cExrLC0i","ze9hzMW","yw1L","ufzrtMq","BgHOEMu","EM1QuNK","CMTLCKDSB2i","t2nsqM0","mxWYFdn8nhW","AenSB3nLrxy","Agf0Dge","y3PhvKC","sxv1s3O","uKHctM4","tMrlCeG","Bw1fz2y","AefJA01LC3m","ndu5tvzUELv3","wwLWq0q","BgLTAxq","u3HJCgy","s2LuENy","y2vmENq","rwnnCfu","y2XLyxi","zLrKA3C","A2v0ignVBNm","C2fNzq","DgLTzw91Da","qKzOruC","t0PVswG","ywXS","ihrPBwvVDxq","v2PZEK8","AxbHyui","C2L5wem","y2HnyxHuCMK","BMHmDu8","nxW2Fde","zwnluMe","DgvmB2Djre4","C2v0sxrLBq","EsbJBg9Zzwq","y3vYCMvUDeu","uKDOufG","BvHcDfK","tgLZDgvUzxi","B2zMC2v0","CxjovLq","BMCGzMfPBgu","uw13rue","yKD1Dxy","CvvqwwO","nJiXnvrOB1vQDq","vxjhzMG","yNvlvxq","A0zrwwu","C3jJ","tujmBfi","vfHmruW","BM93","mhWYFdn8mxW","ywDL","v29ABLu","wgryyLG","s1j6C08","DgLTzw91DcW","CufrrhO","x2rYB3bhBg8","CNzHBa","B0THq2u","CxzRDfq","ufzIDKy","rLrhwhC","BwvZC2fNztO","zKLlwfG","AwXLx25HBwu","zgLZCgf0y2G","Afbuvfa","r2vkzNO","ywrKrxzLBNq","wgfoEhK","B3jpBMXPBMu","yuPHzMG","C0DYuKS","yxGGCMv0CMK","s2ruu2C","zw1YBK4","AfzXv1e","uMLODeO","vw9wEK4","nJi4otuYoefsDevqAG","CwXWEMC","AgfZ","Cg9PBNrbBMq","B09muvm","t2rwz1C","zxq9DxrMltG","yxnSreK","ywzL","zxH0zw5ZAw8","BvDbDKW","thblBuS","rwTLD1a","Aw50zwDLCIa","quHeBfO","uxvqzfu"];return Uo=function(){return t},Uo()}function Mt(t){let e=B,r={ipqYr:function(o,c){return o instanceof c},bsKwz:function(o,c){return o(c)},zBhkv:function(o,c){return o(c)},VeiMP:function(o,c){return o!==c}};if(r[e(1154)](t,IDBRequest))return r.bsKwz(Ov,t);if(zo[e(1630)](t))return zo.get(t);let i=r[e(1767)](Bv,t);return r[e(1351)](i,t)&&(zo[e(1716)](t,i),qo[e(1716)](i,t)),i}var ph,dh,lh,Cd,Go,Ad,zo,qo,jo,Yi,uh=hh({"node_modules/idb/build/wrap-idb-value.js"(){let t=B,e={NoWbS:function(r,i){return r instanceof i},lxulL:t(486),hotcI:t(1256),EPwgQ:function(r,i){return r(i)},EYAjA:function(r,i){return r!==i},KWELo:t(784),lPTyp:t(1276),ndsBk:function(r,i){return r===i},wtGEk:function(r,i){return r in i}};ph=(r,i)=>i[t(1076)](o=>r instanceof o),Cd=new WeakMap,Go=new WeakMap,Ad=new WeakMap,zo=new WeakMap,qo=new WeakMap,jo={get(r,i,o){let c=t;if(e.NoWbS(r,IDBTransaction)){if(i===e[c(1173)])return Go[c(1079)](r);if(i===c(685)+c(939))return r[c(685)+c(939)]||Ad[c(1079)](r);if(i===e.hotcI)return o[c(685)+c(939)][1]?void 0:o[c(685)+c(1065)](o["objectSt"+c(939)][0])}return e[c(1289)](Mt,r[i])},set(r,i,o){let c=t;return c(1459)!==c(1123)?(r[i]=o,!0):this[c(1834)]?this[c(1834)][c(1371)+"te"]:this[c(1268)].automaticOpen?this.CONNECTING:this[c(1013)]},has(r,i){let o=t;if(e[o(952)](e[o(496)],e[o(358)]))return e.NoWbS(r,IDBTransaction)&&(e[o(659)](i,e[o(1173)])||i===o(1256))?!0:e[o(1399)](i,r);throw _0x1361e0=_0x4badd0[o(519)],_0x5803af(_0x25f8a6,10,_0x1df5a1[o(519)])}},Yi=r=>qo[t(1079)](r)}}),gh={};Rv(gh,{deleteDB:()=>Fv,openDB:()=>zv,unwrap:()=>Yi,wrap:()=>Mt});function zv(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let l=B,f={NAXpq:function(w,_){return w(_)},LpKmK:function(w,_){return w<<_},EGTmP:function(w,_){return w&_},nfsse:function(w,_){return w&_},khIZt:function(w,_){return w&_},tVHIr:function(w,_){return w<<_},MIdpx:function(w,_){return w(_)},QUprQ:l(1033),CibEk:"versionc"+l(513),rsWEK:function(w,_){return w(_)},aKANo:l(797),hjAhm:l(1274)+l(347),DXYeb:"blocked"},x=indexedDB[l(627)](t,e),p=f[l(1734)](Mt,x);return i&&(f.aKANo!=="wfrMQ"?(_0x8a63be=f[l(1092)](_0x1af9f8,_0x19c79c),_0x59a24e|=f[l(1639)](127&_0x496f18,21),f.EGTmP(128,_0x35589e)&&(_0x275df7=_0x152996(_0x1f83cc),_0x2a3ea1=f.nfsse(127,_0x501e63),f[l(1069)](128,_0x55ff93)&&(_0x375034=f.NAXpq(_0x4ff3bd,_0x20a16f),_0x284547|=f[l(1014)](f.EGTmP(127,_0x17edf5),7)))):x[l(1617)+l(1583)](f.hjAhm,w=>{let _=l;i(f[_(1092)](Mt,x[_(1203)]),w[_(1109)+"on"],w[_(719)+"on"],f.MIdpx(Mt,x[_(1737)+_(626)]))})),r&&x[l(1617)+l(1583)](f.DXYeb,()=>r()),p[l(1344)](w=>{let _=l;c&&w.addEventListener(f[_(1282)],()=>c()),o&&w[_(1617)+_(1583)](f[_(1652)],()=>o())}).catch(()=>{}),p}function Fv(t,{blocked:e}={}){let r=B,i=indexedDB[r(420)+"tabase"](t);return e&&i[r(1617)+r(1583)](r(702),()=>e()),Mt(i)[r(1344)](()=>{})}function fh(t,e){let r=B,i={kriRU:r(648)+"e",OPZDo:r(761),aPxos:function(x,p){return x instanceof p},bhoyu:function(x,p){return x in p},UEqjy:function(x,p){return x===p},NPIRh:function(x,p){return x!==p}};if(!(i.aPxos(t,IDBDatabase)&&!i[r(1661)](e,t)&&i[r(1532)](typeof e,"string")))return;if(Fo[r(1079)](e))return Fo[r(1079)](e);let o=e[r(1818)](/FromIndex$/,""),c=i.NPIRh(e,o),l=wh.includes(o);if(!i[r(1661)](o,(c?IDBIndex:IDBObjectStore).prototype)||!(l||mh[r(972)](o)))return;let f=async function(x,...p){let w=r,_=this[w(1737)+w(626)](x,l?i.kriRU:i[w(1509)]),S=_[w(1256)];return c&&(S=S[w(798)](p.shift())),(await Promise[w(1568)]([S[o](...p),l&&_[w(486)]]))[0]};return Fo[r(1716)](e,f),f}var mh,wh,Fo,Uv=hh({"node_modules/idb/build/index.js"(){let t=B,e={EZENX:t(1598)+t(876),rcoAh:t(1731),lRRoH:t(644),KgSod:"delete",hNIhP:t(1561),EkewP:function(o){return o()},zvJxf:t(1079),NfJMI:t(706),BWVLQ:"getAll",Jgpbd:"getAllKeys",KDTwe:t(1785),nIaQd:function(o,c){return o(c)}},r=e[t(1100)].split("|"),i=0;for(;;){switch(r[i++]){case"0":uh();continue;case"1":wh=[e[t(1063)],e.lRRoH,e[t(1753)],e[t(826)]];continue;case"2":e[t(1640)](uh);continue;case"3":mh=[e.zvJxf,e.NfJMI,e.BWVLQ,e[t(1049)],e[t(1139)]];continue;case"4":e[t(1020)](Nv,o=>({...o,get:(c,l,f)=>fh(c,l)||o[t(1079)](c,l,f),has:(c,l)=>!!fh(c,l)||o[t(1630)](c,l)}));continue;case"5":Fo=new Map;continue}break}}}),Gv={idb:function(t){let e=B,r={TlSSJ:function(i,o){return i|o},titVH:function(i,o){return i&o},neMCA:function(i,o){return i>>o},hPBWY:function(i,o){return i===o},ecKRa:e(783)};t[e(1836)]=Promise[e(466)]()[e(1344)](()=>(Uv(),gh))[e(1344)](function(i){let o=e;if(r[o(331)]("YKxvk",r[o(1576)]))_0x45605f[_0x56ff6f++]=r.TlSSJ(r[o(1683)](r[o(1178)](_0x1cfc3d,18),7),240),_0x2bdef4[_0x4d5f18++]=r[o(1847)](_0x2d5f1d>>12&63,128);else return i})}},xh={};function Nt(t){let e=B,r={ahGsF:e(1262)+"2",kxqVt:function(f,x){return f!==x}},i=r[e(888)].split("|"),o=0;for(;;){switch(i[o++]){case"0":var c=xh[t];continue;case"1":if(r.kxqVt(void 0,c))return c.exports;continue;case"2":return l.exports;case"3":var l=xh[t]={exports:{}};continue;case"4":Gv[t](l,l[e(1836)],Nt);continue}break}}(()=>{let t=B,e={nijpf:function(r,i,o){return r(i,o)},NoDrE:t(1033),hgFav:function(r,i){return r===i}};Nt.d=(r,i)=>{let o=t;if(e[o(1059)](o(930),o(930)))for(var c in i)Nt.o(i,c)&&!Nt.o(r,c)&&Object[o(856)+o(1015)](r,c,{enumerable:!0,get:i[c]});else{let l=ve._options[o(1470)+"tInterce"+o(672)](_0x26c30c,_0x442aaf);ve[o(1160)+o(1546)+o(349)](e[o(991)](_0x5812eb,e[o(1021)],{code:_0x7921fb,reason:_0x3325df,wasClean:!0,willReconnect:l})),l&&ve._connect()}}})(),(()=>{let t=B;Nt.o=(e,r)=>Object.prototype["hasOwnPr"+t(1015)][t(765)](e,r)})(),Nt.r=t=>{let e=M;e(1692)+"d"!=typeof Symbol&&Symbol[e(1885)+"Tag"]&&Object["definePr"+e(1015)](t,Symbol[e(1885)+"Tag"],{value:e(1477)}),Object[e(856)+"operty"](t,e(1668)+"le",{value:!0})};var ke={};(()=>{let t=B,e={suMlc:function(a,n){return a(n)},SIhFu:function(a,n){return a+n},QHkxq:function(a,n){return a+n},XMnSR:function(a,n){return a+n},bbHcW:function(a,n){return a*n},cdZVy:function(a,n,s){return a(n,s)},UHJLk:function(a,n){return a(n)},QvCeK:t(735),yharp:function(a,n){return a==n},VzuwS:t(1658),GxPZu:function(a,n){return a===n},VchCc:t(882),TAzqn:t(1022)+t(1022)+t(1022)+t(1022),XOpVG:"vCIHY",dbpKx:function(a,n){return a<n},bPAIv:function(a,n){return a!==n},qzctf:t(1741),zjoPB:function(a,n){return a!==n},bEtSG:function(a,n){return a-n},oUotZ:function(a,n){return a<n},yvhgw:function(a,n){return a-n},IoHBz:function(a,n){return a===n},hjkEx:function(a,n){return a===n},bhHgW:t(1495),KMGwB:function(a,n){return a<n},GkjtG:function(a,n){return a-n},OdVgW:function(a,n){return a!==n},usobd:function(a,n,s){return a(n,s)},VxExQ:function(a,n){return a||n},XakZX:t(1390),ZhIxs:function(a,n){return a(n)},sAqFj:function(a,n){return a>>>n},XmVVJ:function(a,n){return a&n},xUokq:t(994)+t(1147)+t(455)+t(925),zEmYC:t(994)+t(1147)+t(455)+t(1832),moyiL:function(a){return a()},kEqvP:function(a,n){return a||n},yVxlS:function(a,n){return a!=n},QmwAb:t(1692)+"d",HUKZw:t(834)+t(1342)+"d",fMlbV:"close",fdJXQ:t(627),NRIPJ:"error",znJus:function(a,n){return a(n)},TUyCu:function(a,n){return a|n},LYzQg:function(a,n){return a(n)},DCMKi:"DDfbH",hNPQP:"Chmlm",oqzow:function(a,n){return a!==n},fxUdH:function(a,n,s){return a(n,s)},jyGUF:function(a,n,s){return a(n,s)},Gmzwx:function(a,n,s){return a(n,s)},thRBk:function(a,n){return a!==n},YCRTR:t(718),mXBtY:function(a,n,s){return a(n,s)},eQlaC:function(a,n){return a(n)},zOdoj:function(a,n,s){return a(n,s)},nsOCj:function(a,n){return a(n)},hJdFl:t(709),oKaCe:function(a,n,s){return a(n,s)},YiqaC:function(a,n,s){return a(n,s)},RoRHG:t(1693),olnUN:function(a,n,s){return a(n,s)},moApX:function(a,n){return a!==n},iiRiy:function(a,n){return a!==n},LkGFL:"GmTWc",SpmuX:function(a,n){return a===n},oSqzH:t(1825),BoJdw:function(a,n,s){return a(n,s)},lwzcz:function(a,n){return a===n},KRzsO:t(351),jVZdp:t(564),qwQjV:function(a,n,s){return a(n,s)},wMNiI:function(a,n){return a(n)},QDFxn:function(a,n,s){return a(n,s)},BFhEG:function(a,n){return a(n)},RSXnC:function(a,n,s){return a(n,s)},nGTUI:"LKyMx",qGXxj:function(a,n){return a(n)},ugBoc:function(a,n,s){return a(n,s)},lQoel:function(a,n,s){return a(n,s)},uPvfe:function(a,n,s){return a(n,s)},VxlDH:function(a,n){return a(n)},dAiBN:function(a,n,s){return a(n,s)},colVL:function(a,n){return a===n},KzDPn:"Missing "+t(1147)+t(455)+t(1765),EWSTv:t(994)+"required"+t(455)+t(1520),KdTSg:"Missing "+t(1147)+t(455)+t(1239),jUlyi:t(1545)+"0",lkoMV:t(558),FubyG:function(a,n){return a!==n},AcaCF:t(1655),mPhFu:function(a,n){return a(n)},wBaGu:function(a,n){return a+n},QypMO:t(975)+t(321)+"pe: ",PVQNd:function(a,n){return a>>n},IwwCc:function(a,n){return a>=n},kapjX:function(a,n){return a===n},nPxho:function(a,n){return a>n},stwvD:function(a,n){return a>=n},rrIBz:function(a,n){return a+n},Bkeqf:function(a,n){return a>n},nDtju:function(a,n){return a>n},hVrPe:function(a,n){return a+n},vrCGq:"Read pas"+t(1663),FKdsf:function(a,n){return a+n},BxZUh:function(a,n,s){return a(n,s)},eECOd:function(a,n){return a<n},PGWWc:function(a,n){return a&n},haOWr:function(a,n){return a+n},KNDqF:function(a,n){return a|n},kHJaB:function(a,n){return a<<n},GDJxs:function(a,n){return a&n},rRxHE:function(a,n){return a&n},wZOvR:t(852),pWdzr:function(a,n){return a(n)},RGhPX:function(a,n){return a==n},RGhLp:function(a,n){return a&n},mhkEq:function(a,n){return a>=n},bGuuv:function(a,n){return a+n},Mnppj:function(a,n){return a&n},zUTmB:function(a,n){return a|n},gIrtD:function(a,n){return a<<n},buKUt:function(a,n){return a<<n},ADZbt:function(a,n){return a>=n},MPNaY:function(a,n){return a<=n},Luqeu:function(a,n){return a(n)},VPCzV:function(a,n){return a+n},BftCu:function(a,n){return a+n},oZWUf:function(a,n){return a!==n},aJafh:function(a,n){return a<<n},RHBNn:function(a,n){return a<<n},LXHTn:function(a,n){return a|n},rVRWV:function(a,n){return a&n},RxUAv:function(a,n){return a&n},UrGfh:function(a,n){return a>>n},HNGtJ:function(a,n){return a+n},yAUKV:function(a,n){return a&n},VBehN:function(a,n){return a+n},SUMYg:function(a,n){return a===n},icdwA:t(1600),AyPrp:function(a,n){return a<n},ePMHT:function(a,n){return a-n},VSnGm:function(a,n){return a<n},Xyoxp:function(a,n,s){return a(n,s)},LTdzG:function(a,n){return a<n},GhZiD:function(a,n){return a<n},vLvbH:function(a,n){return a<n},eYGjC:function(a,n){return a|n},FjtzW:function(a,n){return a&n},qHLLJ:function(a,n){return a!==n},GBbkU:"BfDKO",JDhdy:function(a,n){return a|n},pXfOw:t(1677),UVXvt:function(a,n){return a|n},MwpRP:function(a,n){return a&n},DxXjO:function(a,n){return a&n},ciYfZ:t(894),lYbTp:function(a,n){return a!==n},LyqAy:t(732),VytDt:"eSmmV",WQfVx:function(a,n){return a(n)},GBUup:function(a,n){return a&n},CJkbO:function(a,n,s){return a(n,s)},qsgGo:t(1052),ZEzbc:t(1130),kudKQ:t(811),uwujK:t(526),yVkbz:t(1531),BtGdx:function(a,n){return a(n)},kFQYe:function(a,n){return a&n},rQSYR:function(a,n){return a(n)},wiFYB:function(a,n){return a<<n},QyQzC:function(a,n){return a&n},Qccml:function(a,n){return a&n},gmAew:function(a,n){return a(n)},LStqU:function(a,n){return a<<n},CZFQS:function(a,n){return a&n},wGtkG:function(a,n){return a===n},ttZwp:t(805),BVxsX:function(a,n){return a&n},vQOqq:t(1407),dDLTW:t(1513),vPbaS:function(a,n){return a&n},AHDlZ:function(a,n){return a&n},lTksy:function(a,n){return a<<n},NDmfo:function(a,n){return a>>>n},ymdcZ:function(a,n){return a<<n},tLxLd:function(a,n){return a>>>n},GABrE:function(a,n){return a>>>n},WNYMQ:function(a,n){return a|n},jePEE:function(a,n){return a>>>n},rWKPC:function(a,n){return a===n},UEkeS:function(a,n){return a<n},lIAaj:function(a,n){return a<n},rycGq:function(a,n,s){return a(n,s)},GOcwd:function(a,n){return a>>>n},cTqCw:function(a,n){return a+n},DxVfN:function(a,n){return a+n},EDBND:function(a,n){return a|n},aiEXF:function(a,n){return a>>>n},jHzfs:function(a,n){return a>>>n},xEpTy:function(a,n){return a+n},oyMTL:function(a,n){return a!==n},xLsJR:function(a,n){return a&n},FGuei:function(a,n){return a>>>n},gjqUw:function(a,n){return a+n},MANKH:function(a,n){return a+n},LoRMX:function(a,n){return a!==n},vejJX:function(a,n){return a>>>n},VPfyL:function(a,n){return a+n},FTWjo:function(a,n){return a|n},TwxGu:function(a,n){return a>>>n},XaNxy:function(a,n){return a>>>n},inkyI:function(a,n){return a|n},FJMAy:function(a,n){return a&n},rUEkD:function(a,n){return a(n)},VihCL:function(a,n){return a|n},MDjcG:function(a,n){return a|n},sABei:function(a,n){return a<<n},xlydU:function(a,n){return a|n},ytgrl:function(a,n){return a|n},uKbPT:function(a,n){return a<<n},fEyif:function(a,n){return a<<n},nlyaz:function(a,n){return a|n},Twygv:function(a,n){return a|n},DkPxF:function(a,n){return a<<n},uKlYL:function(a,n){return a<<n},UaaqB:function(a,n){return a===n},RMFsz:function(a,n){return a|n},DFopq:function(a,n){return a|n},ESLNZ:function(a,n){return a<<n},iKHrl:function(a,n){return a>>>n},Xgqha:function(a,n){return a|n},pfulZ:function(a,n){return a|n},MlAKa:function(a,n){return a<<n},QzrXQ:function(a,n){return a<<n},AXkmc:function(a,n){return a&n},liQcm:function(a,n){return a&n},qVpHk:function(a,n){return a(n)},EMjeY:function(a,n){return a>=n},xxnJT:function(a,n){return a%n},ukHyx:function(a,n){return a|n},ToaOF:function(a,n){return a+n},FBWch:function(a,n){return a*n},CglmQ:function(a,n){return a*n},hlKYj:function(a,n){return a>>>n},HQRZM:function(a,n){return a===n},nqvdn:function(a,n){return a&n},cmkkl:function(a,n){return a&n},nBgpZ:function(a,n){return a>>>n},BPYxE:function(a,n){return a&n},QNgXr:function(a,n){return a+n},MCghr:function(a,n){return a+n},GNidQ:function(a,n){return a+n},glpeZ:function(a,n){return a>>>n},mbXLh:function(a,n){return a|n},YycVg:function(a,n){return a===n},LrNrG:t(365),OJrVY:function(a,n){return a===n},coete:function(a,n){return a===n},UeKSM:function(a,n){return a===n},juQlo:function(a,n){return a===n},CMHbm:function(a,n){return a&n},HaHog:function(a,n){return a&n},zEgjW:function(a,n){return a>>>n},suJdt:function(a,n){return a&n},IdLWI:function(a,n){return a>>>n},qvktT:function(a,n){return a&n},scHkc:function(a,n){return a>>>n},CVJyI:function(a,n){return a&n},cCkVc:function(a,n){return a&n},TUSyc:t(1621),iNWad:t(1541),QJVdq:"5|4|1|0|3|2",huHnS:"MESSAGE_ERROR",CZtte:t(541)+"OR",hgyrY:t(1179)+"NG_ERROR",CXsPr:t(1900)+t(1699),SVvUz:t(1675),MBVpx:t(1068)+t(1575),bNkcg:function(a,n){return a instanceof n},FnrfQ:t(410)+t(820),TTHpd:t(410)+t(820)+t(422)+t(1258),hDxqx:t(1441),mmEgf:t(387)+"e",SLDeS:"binary",CRZIR:function(a,n,s,d){return a(n,s,d)},pDGRf:function(a,n){return a!==n},oAUUe:t(1478),pkvKI:function(a,n){return a===n},rfevm:function(a,n){return a|n},dCpLe:function(a,n){return a<<n},Vixoq:function(a,n){return a|n},qMBWd:function(a,n){return a|n},aslDI:function(a,n){return a<<n},nzjkr:t(1859),BuwyR:function(a,n){return a+n},katlF:function(a,n){return a<n},DgWUa:t(1653),osnAn:function(a,n){return a(n)},WKWnY:"unknown "+t(1096),kjVxT:function(a,n){return a!==n},kzhlt:t(1490),GaEsg:"Cmlwc",mOjZu:function(a,n){return a!==n},tdSSz:t(1862),BoDyf:function(a,n,s){return a(n,s)},eYjQy:"fbatD",dzNsH:t(1423),bGPMg:function(a,n){return a>=n},hqEAw:function(a,n){return a-n},cEJkZ:function(a,n){return a===n},TAwSa:function(a,n){return a!==n},LzKUs:"vTZTt",PyJGq:function(a,n){return a instanceof n},fTvki:t(613)+"d error.",TndME:function(a,n){return a===n},bjIWB:function(a,n){return a<n},NoxHv:function(a,n){return a===n},fCYUY:function(a,n){return a===n},sOjMM:t(1060),EWrQO:t(430),SpJYa:"ping_onc"+t(657)+"s",OpEfN:"success",hxynv:function(a,n){return a===n},AAOPu:function(a,n){return a===n},GSLRi:t(1610),QaewF:function(a,n){return a>>>n},syFPl:function(a,n){return a>>>n},qDbIa:function(a,n){return a>>>n},bVTbJ:t(468),vtaVf:function(a,n){return a+n},WXbrm:function(a,n){return a===n},AoQvd:t(1680),nhLuO:function(a,n){return a===n},roIAs:t(1394),dmUsA:t(1585),HGXJl:"DXSuO",jvpsf:t(1719),fjPdh:t(1760),PCLbU:function(a,n){return a||n},ymvIK:function(a,n){return a!=n},YnCxo:t(1376)+"2",XPkmv:function(a,n){return a||n},RLscZ:"blocked",wwXzc:function(a,n){return a(n)},yIBQZ:function(a,n){return a===n},MtQOK:t(831),FvpwT:t(528),NbdGY:t(1218)+t(1042)+t(553)+t(1678)+"process",IlPYV:function(a,n){return a!==n},rQnyt:function(a,n){return a(n)},RTfhu:function(a,n){return a<n},pjnAM:function(a,n){return a===n},OfMJV:t(1469),ROtyJ:function(a,n){return a===n},Cwvem:function(a,n){return a&n},XUjKc:function(a,n){return a-n},AiRar:function(a,n){return a&n},AErTy:function(a,n){return a!==n},SltUh:t(355),YipCD:function(a,n){return a|n},uLdHC:function(a,n){return a|n},RYDeS:function(a,n){return a<<n},ZiWSp:function(a,n){return a&n},pENSk:function(a,n){return a&n},nymJG:function(a,n){return a&n},tVJCU:function(a,n){return a>>n},vypTU:function(a,n){return a===n},eiIJf:function(a,n){return a===n},vXjoC:function(a,n){return a+n},ewGEz:t(752)+t(1733),VUoAE:function(a,n){return a+n},kuzWJ:function(a,n){return a>>n},fIKXX:function(a,n){return a&n},TXkpx:function(a,n){return a|n},WwDFi:function(a,n){return a&n},CkLvB:function(a,n){return a>>n},EKRUF:function(a,n){return a>>n},PIpSX:function(a,n){return a|n},srfbQ:function(a,n,s,d){return a(n,s,d)},IuuKz:function(a,n){return a instanceof n},BJToo:function(a,n){return a!=n},qRuqF:function(a,n){return a!=n},wSeuK:function(a,n){return a==n},XBLJy:t(1277)+t(720)+t(1634),crPCl:function(a,n){return a(n)},zmckP:function(a,n){return a+n},CGvIO:function(a,n){return a+n},MhOAR:t(584),UJiMc:t(1651),HrUeV:"uEfmk",siWvK:"script",oGBKp:t(937)+t(623),hJBXR:t(1157)+"ack=fron"+t(1649)+"P",nQKVA:t(841),HwHkg:"itwcd",EZPBq:function(a,n){return a|n},khHaJ:function(a,n){return a|n},miRaM:function(a,n){return a<<n},jwJtn:function(a,n){return a<n},ZkEmW:function(a,n){return a<=n},msjuY:function(a,n){return a(n)},bzkBW:"crpEm",CDncz:"0|3|6|7|2|4|5|1",zEPzw:"close, w"+t(647)+"ce not i"+t(352)+"ed",Xpzwq:function(a,n){return a===n},IfkCa:function(a,n){return a===n},gGJCB:t(1090)+t(703)+t(1579),ruoSg:t(817),YGolU:function(a){return a()},FLitJ:t(1246),UCcsR:t(1214),KzRZz:"NiJxK",KiAHx:t(1194),lTHRe:function(a,n){return a&n},yhQyd:function(a,n){return a>>>n},qmzLg:function(a,n){return a&n},dBjvl:"kIhlr",ZBoxE:function(a,n){return a!==n},PtoNP:t(1102),mzblJ:t(1369),qyctG:function(a,n){return a||n},OqQSH:function(a,n){return a||n},usqDv:function(a,n){return a(n)},tBGxW:function(a,n){return a&n},osNgt:function(a,n){return a&n},lPqNe:function(a,n){return a<<n},qDXYH:"QuPdU",tunqG:function(a,n){return a&n},jdfCp:function(a,n){return a>>>n},nkGKK:function(a,n){return a>>>n},gvTTr:"EOpBQ",ofhXC:function(a,n){return a>n},QbZLU:t(1641)+t(1428)+"e",WRpzw:function(a,n){return a>=n},XKrxA:t(1120),rJAAE:function(a,n){return a||n},gCfcv:"ping_onc"+t(583)+"t",LLIJw:function(a,n,s){return a(n,s)},zZuuH:function(a,n){return a===n},zpmWg:t(454),MRofr:function(a,n){return a===n},JkQuV:function(a,n){return a||n},spgjE:function(a,n){return a!=n},aLFEJ:function(a,n){return a!=n},WDcVs:function(a,n,s){return a(n,s)},HlPzy:t(346),hQMfQ:t(992)+"id",nOvju:function(a,n){return a(n)},gKIdh:function(a,n,s){return a(n,s)},CLTJc:function(a,n){return a!==n},BHIeu:t(954),ceLzt:t(1470)+"t",ilOhM:"start",keuhn:"EdrLx",TXLEL:t(1404),lrrCx:function(a,n,s){return a(n,s)},htDAn:function(a,n,s){return a(n,s)},wTwhP:t(1455),knUBW:"lkGSJ",vkJVW:t(1686),RTNlL:function(a,n,s){return a(n,s)},exTIV:function(a,n){return a===n},Pbqiz:t(1798),PZSqD:function(a,n){return a(n)},HIpbS:t(1659)+t(857),jytQH:function(a,n,s,d){return a(n,s,d)},djYHD:t(1659)+t(1851)+"ck",RzJvg:t(1659)+"er_ack_msgid",gvMaB:function(a,n,s,d){return a(n,s,d)},pnpvc:function(a,n){return a&&n},nUVwk:t(1216),ESKee:t(1858),wAyee:function(a,n){return a(n)},TkCad:function(a,n){return a instanceof n},MJvfG:function(a,n){return a instanceof n},fBhrI:function(a,n,s,d){return a(n,s,d)},djycV:function(a,n){return a+n},JPsQJ:function(a,n){return a&n},hPCAl:function(a,n){return a>>>n},OJEGw:function(a,n){return a(n)},VFYFR:function(a,n){return a+n},MZSIA:function(a,n){return a+n},umLLA:function(a,n){return a+n},KeceK:"index ou"+t(1500)+t(551),vcnVK:t(830),NqGZG:function(a,n){return a>=n},kArDR:t(884),HUHja:function(a,n){return a&n},YTqqa:function(a,n,s,d){return a(n,s,d)},Sxcpf:function(a,n){return a>>>n},IqyRH:function(a,n){return a&n},QpKDM:function(a,n){return a<n},FwOmv:function(a,n){return a>>n},GeJfz:t(779),dfwbD:t(1458),LpqIK:function(a,n){return a+n},SDJGi:function(a,n){return a+n},mUuYt:function(a,n){return a|n},dYAUt:function(a,n){return a|n},TfCmT:function(a,n){return a|n},jfdar:function(a,n){return a<<n},diZwy:function(a,n){return a+n},MBLlR:function(a,n){return a<<n},NyZaj:function(a,n){return a|n},dOGfl:function(a,n){return a+n},fQwma:function(a,n){return a<<n},GBqaL:function(a,n){return a<<n},aOwlc:function(a,n){return a+n},BODlw:function(a,n){return a+n},mldOh:function(a,n){return a&n},Hbrny:function(a,n){return a>>>n},jnGGW:function(a,n){return a>>>n},yHRrm:function(a,n){return a&n},fOPuy:function(a,n){return a+n},GAsuT:function(a,n){return a&n},DSkSq:function(a,n){return a+n},rlweD:function(a,n,s){return a(n,s)},OJoIh:function(a,n,s){return a(n,s)},WibUz:function(a,n){return a===n},HTJEs:t(1089),VfFgy:t(1519)+"|8|7|2|1"+t(377)+"3",DWWWu:function(a,n){return a>>>n},xtzJY:function(a,n){return a&n},ipaaB:function(a,n){return a>>>n},VMboI:function(a,n){return a<n},OBJJv:function(a,n){return a<<n},otcYT:function(a,n){return a&n},plhgy:function(a,n){return a<n},oAPIF:t(819)+"|5|6|4|9|7|3|8",CAgXK:function(a,n,s,d){return a(n,s,d)},nuFiR:t(1264),HfIRd:t(1497)+t(1747),oAllt:t(1869)+t(892),gtNJm:"service",VxDui:function(a,n,s,d){return a(n,s,d)},dwDVQ:function(a,n){return a(n)},livxo:t(1193)+t(1613),OCaup:t(400),mgTeV:function(a,n){return a+n},yrSYp:t(1740)+t(527),ZLoXr:function(a,n,s){return a(n,s)},vFuQk:t(1660)+"ame",WiRUq:t(432)+"1",RejZz:"roQGh",JViub:t(606),sEpFQ:t(638)+"rValues",dbXFB:function(a){return a()},WrROI:function(a,n){return a+n},WjZOx:"http",iobFQ:function(a,n){return a!==n},HYGgu:t(1484),rSPIM:function(a,n){return a|n},hSPUe:function(a,n){return a<<n},OrMHc:function(a,n){return a(n)},olzvr:"gIepy",czqrN:"dkTPl",YHXBX:t(1471)+"r",ymdvy:function(a,n){return a>n},AjRbb:function(a,n){return a&n},MWDMF:function(a,n){return a||n},LtTaX:t(1856),NHgRD:t(1115),ojmGm:t(716),CjsvA:t(1659)+t(699),gGEZN:t(1659)+t(837),mLiYP:t(1703)+"s",FNQOM:function(a,n,s){return a(n,s)},wgwqX:t(1025)+t(548)+"ue",tCNYZ:function(a){return a()},rDggi:function(a,n){return a>n},xXYQC:function(a,n){return a+n},PmcYz:function(a){return a()},HxFjQ:function(a,n){return a===n},vCaEB:t(1488),npomd:function(a,n){return a===n},WJBvq:function(a){return a()},DKgal:function(a,n){return a!==n},TMXmF:function(a,n){return a-n},jfMct:"uLkrY",RMOfr:function(a,n,s){return a(n,s)},CxOix:function(a){return a()},qsBAX:function(a){return a()},eIDrb:function(a,n){return a===n},cMnuA:t(1759),BwJfz:function(a,n,s,d){return a(n,s,d)},SFVvu:function(a,n,s){return a(n,s)},aIVHc:function(a,n,s){return a(n,s)},KZEfO:t(1358),NZaKf:function(a,n){return a!==n},CgqsI:function(a,n,s){return a(n,s)},GCJpY:t(734),HeTII:"CONTINUE",EcMpU:t(315)+t(1431)+"s params, WebSoc"+t(1563)+t(360)+t(639)+"ined",NcwIX:function(a,n){return a!==n},tdkGi:function(a,n){return a(n)},ckxMQ:"BchHi",TCmnc:function(a,n){return a==n},lDAcv:t(1730),xkPZk:t(578),BTYwt:t(577)+"d",czGVG:function(a,n,s){return a(n,s)},RhLGe:"web",sBree:"fws_1.0.0",aodwp:function(a,n){return a>>n},emrnN:t(379)+"3|2",rSExO:function(a,n){return a>>n},PxBFw:function(a,n){return a|n},vdnyw:function(a,n){return a+n},RvwlX:function(a,n){return a|n},djtHg:function(a,n){return a===n},cbYMS:function(a,n){return a||n},QmwEA:function(a,n,s){return a(n,s)},URbvt:function(a,n){return a!==n},Unjmn:t(906),gVuvJ:function(a,n){return a(n)},xhXIB:t(1440),BLhob:"AuQSP",GVpiV:function(a,n){return a(n)},LVwew:function(a,n){return a(n)},OKOnQ:t(1504)+">",AHbDx:function(a,n){return a*n},MGFnw:function(a,n){return a===n},feBqy:function(a,n,s){return a(n,s)},InHbe:function(a,n){return a!==n},MFKOb:t(524),yMQZv:t(1565),WfjUK:function(a,n,s){return a(n,s)},NQDQX:t(1477),tnbat:t(1668)+"le",VCmYI:"VjaGd",ZYioT:function(a,n){return a<=n},AebQj:function(a,n){return a-n},BjYVo:function(a,n){return a>>n},NxoBy:t(343),rMsTD:"XyOAD",SrkTK:t(1603)+t(746)+t(1810)+"g",fUfFp:function(a,n){return a===n},IjbYQ:t(1788),ELYrz:function(a,n){return a(n)},WjszO:t(1615),lhRzt:t(816)+"3",trDsR:t(1671)+"4",hybCe:function(a,n,s){return a(n,s)},bTEbx:t(859)+"ay, netw"+t(1305)+"ine",VRQNX:function(a,n){return a===n},dVCJA:t(414),nbMEr:"ack",pchkA:t(376),YsvBr:t(871),KiTzv:"ngKME",VcyhE:t(1625),cLKya:function(a,n){return a|n},IGICJ:function(a,n){return a|n},TFHnw:function(a,n){return a<<n},uEZlB:function(a,n){return a<<n},zTPoN:t(768),RcnNf:t(656)+"2|7|4|1",eCPsT:function(a,n){return a===n},GGptq:function(a,n){return a!=n},dlTlM:function(a,n){return a instanceof n},ZRQjn:function(a,n){return a(n)},JrPIn:t(315)+"rovide a"+t(1426)+t(1747),SnmJV:function(a,n){return a===n},AsgbF:"sent",qlpzg:function(a,n){return a<n},pUbSL:t(1032),ANHlW:function(a,n){return a!==n},XwbPx:t(1011)+t(704)+"ing",ToaZx:function(a,n){return a===n},NTtUx:t(687),fLBoP:function(a,n){return a===n},qCfYF:t(425),VFDLE:t(910),JkRMi:"1|0|2|3|4",OeCSE:function(a,n){return a&n},Niboi:function(a,n){return a>>>n},numMt:function(a,n){return a|n},QvEGJ:function(a,n){return a<n},eboOU:function(a,n,s,d){return a(n,s,d)},bUnYY:function(a,n){return a!==n},Bkpin:t(1463),tIcYz:function(a,n){return a*n},DnpQC:function(a,n){return a*n},pynTv:function(a,n){return a===n},NDlRo:t(938),auHku:function(a,n){return a===n},TOUQX:function(a,n){return a!=n},EiTyJ:function(a,n){return a!=n},FkRKT:function(a,n){return a===n},vtIgL:"Object",pDOAn:function(a,n){return a===n},siyXC:"Dedicate"+t(701)+"lobalScope",bgMHX:function(a,n){return a!=n},okfOu:function(a,n){return a===n},xgItI:function(a,n){return a!=n},fCOXn:function(a,n){return a===n},kpWEB:"SharedWo"+t(1543)+t(674),MyBIv:function(a,n){return a===n},jeXOw:t(1877)+t(1024)+t(1135),tngDE:function(a,n){return a===n},OcRBm:function(a,n){return a===n},Taprp:t(679)+"qos__"};Nt.r(ke),Nt.d(ke,{FWS:()=>Xp,CustomErrorEvent:()=>$d,createCloseEvent:()=>xt,ReconnectEvent:()=>Kd,createErrorEvent:()=>at,decodedFrame:()=>Qt,createOpenEvent:()=>Qd,CustomCloseEvent:()=>Vd,createReconnectEvent:()=>aa,FrontierMessageEvent:()=>Yd,encodeFrame:()=>Bt,createMessageEvent:()=>Xd,OpenEvent:()=>Zd,ErrorCode:()=>tn,Event:()=>Zn,MessageEvent:()=>Jd});let r="";function i(a=""){let n=t,s="02",d=""+Date[n(1597)](),u=r||(r=e[n(1494)](x,a)),h=Math[n(650)]().toString(16)[n(329)](-6);return e[n(538)](e[n(538)](e[n(1849)](s,d),u),h)}function o(){let a=t;return e.XMnSR(e[a(844)](1e4,Date[a(1597)]()),Math.floor(1e4*Math.random()))}function c(a){let n=t;if(n(822)!==n(822))_0x3b6085[n(1797)][n(1714)+"ild"](_0x245c52);else return e.XMnSR(Array(8).join("0"),e[n(1713)](parseInt,a,10).toString(2)).slice(-8)}function l(a){let n=t;return(e.UHJLk(Array,4).join("0")+e[n(1713)](parseInt,a,2)[n(1885)](16))[n(329)](-4)}function f(a){let n=t,s=a[n(1419)](/\./).map(h=>c(h)),d=[];return d[0]=e.suMlc(l,s[0]+s[1]),d[1]=e.UHJLk(l,e.SIhFu(s[2],s[3])),[e[n(1518)],n(735),e.QvCeK,"0000",e[n(1518)],n(584),d[0],d[1]].join("")}function x(a){let n=t;if(e[n(624)](n(1562),e[n(1229)]))_0x395715=_0x2f625a&&e[n(547)](n(437),_0x212e2f[n(433)])?e[n(591)]:n(1730),_0x1d9f84=_0x2fc17d[n(1818)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),_0x3a7665=/^wss(.*:\/\/)/.test(_0x26d15b)?_0x2c0676:""+_0x50150d+_0x7d75f8;else{let s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[n(1799)](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]))/.test(a);return s?f(a):d?e[n(1494)](p,a):e.TAzqn}}function p(a){let n=t,s="",d=[],u=0,h=0,g=!0,b=n(735);if(a[n(579)]("::")>-1)if(n(452)!==e[n(1794)])this[n(880)+n(383)]=_0x49ed29,this[n(1785)]=0;else{let m=a.split("::");for(let A=0;e.dbpKx(A,m[n(519)]);A++)if(e[n(897)](e[n(1114)],"apuOe")){let P=this[n(1196)+n(828)]?.[n(1750)+n(549)+"nt"]();this[n(812)](n(693)+P+n(1569)),this[n(1809)+n(328)](1001,n(1603)+n(746)+n(1810)+"g",!0)}else{let P=m[A];if(P[n(579)](":")>0){let U=P[n(1419)](":");g&&(u=U[n(519)]),h+=U[n(519)];for(let H=0;e[n(594)](H,U.length);H++)if(e[n(1533)](4,U[H][n(519)])){let Y=b.substring(0,e[n(1275)](4,U[H][n(519)])),qe=Y.concat(U[H]);d[n(1774)](qe)}else d.push(U[H]);g=!1}else{if(e[n(897)](4,P[n(519)])){let U=b[n(1356)+"g"](0,4-P[n(519)]),H=U[n(1481)](P);d[n(1774)](H)}else d[n(1774)](P);g&&(u+=1),h+=1,g=!1}}let T="";for(let A=0;e[n(1409)](A,e[n(1400)](8,h));A++)T=T.concat(b);for(let A=0;A<d[n(519)];A++)e[n(491)](A,u)?e[n(1175)](n(1495),e.bhHgW)?(s=s[n(1481)](T),s=s[n(1481)](d[A])):this[n(456)+n(396)]():s=s[n(1481)](d[A]);return s}{let m=a.split(":");for(let T=0;e[n(1510)](T,m[n(519)]);T++){let A=m[T];if(e[n(1533)](4,m[T].length)){let P=b[n(1356)+"g"](0,e[n(1054)](4,m[T].length)),U=P[n(1481)](A);s=s[n(1481)](U)}else s=s[n(1481)](A)}return s}}function w(a,n){let s=t,d=a[s(925)];e[s(1633)](void 0,d)&&(he(n,10),e[s(1325)](j,n,d));let u=a.value;e[s(1533)](void 0,u)&&(he(n,18),j(n,u))}function _(a){let n=t,s={kZpMx:function(d,u){return e[M(1433)](d,u)}};if(e.OdVgW(e.XakZX,e[n(1790)])){let d=this[n(678)][n(1093)](this[n(1167)]),u=_0x477428[n(1711)](s[n(1501)](d,"{}"));return u[_0x4803a3]=void 0,this._qosDB[n(1578)](this[n(1167)],_0x33671d[n(748)+"y"](u))}else{let d={};e:for(;!e[n(1735)](V,a);){let u=e.ZhIxs(xe,a);switch(e[n(893)](u,3)){case 0:break e;case 1:d.key=N(a,e.UHJLk(xe,a));break;case 2:d[n(1832)]=N(a,e[n(341)](xe,a));break;default:e[n(1325)](R,a,e[n(689)](7,u))}}if(d[n(925)]===void 0)throw new Error(e.xUokq);if(d.value===void 0)throw new Error(e[n(406)]);return d}}function S(a){let n=t,s=e[n(1234)](D);return e[n(1713)](y,a,s),e[n(1735)](z,s)}function y(a,n){let s=t,d={qCFrx:function(u,h){return e.TUyCu(u,h)},TOdEv:function(u,h){return u|h},zXoxp:function(u,h){return u&h},nfcOr:function(u,h){return u>>h},KfAuo:function(u,h){return e[M(911)](u,h)}};if(e.DCMKi===e[s(1529)]){let u=0,h=[];for(;e[s(594)](u,_0x27fc70.byteLength);){let{offset:g}=_0x2b8947(_0x4ec545,u);u=g;let b={cursor_name:"",cursor:0,service:0},{value:m,offset:T}=e[s(1325)](_0x198f2f,_0x44045d,u);b[s(1520)]=m,u=T;let{value:A,offset:P}=_0x15933a(_0xe4af63,u);u=P,b[s(1660)+s(1539)]=_0x368607(_0x25c93e,u,u+A),u+=A;let{value:U,offset:H}=_0x54f638(_0xd1babf,u);b[s(669)]=U.toNumber(),u=H,h.push(b)}return h}else{let u=a[s(673)];e[s(494)](void 0,u)&&(e[s(562)](he,n,8),ft(n,u));let h=a[s(1765)];e[s(1533)](void 0,h)&&(e[s(1704)](he,n,16),e[s(600)](ft,n,h));let g=a[s(1520)];e[s(494)](void 0,g)&&(e[s(966)](e[s(472)],"OagHp")?(e.mXBtY(he,n,24),e[s(1582)](ft,n,e.eQlaC(O,g))):(_0x46d07b[_0x26a433++]=d[s(712)](_0x4d53df>>12,224),_0x2c16a4[_0x1cabfa++]=d.TOdEv(d[s(1679)](d[s(1043)](_0x51414a,6),63),128),_0x304599[_0x2c097d++]=d[s(1679)](63,_0x4bb188)|128));let b=a[s(1239)];b!==void 0&&(e.cdZVy(he,n,32),e[s(1472)](ft,n,e[s(1717)](O,b)));let m=a.headers;if(e.zjoPB(void 0,m))for(let je of m)if(e[s(897)](s(1684),e[s(902)])){e[s(1607)](he,n,42);let zt=e[s(1234)](D);w(je,zt),e.YiqaC(he,n,zt[s(1556)]),$(n,zt),e[s(911)](L,zt)}else _0x1e140c+=d[s(1857)](_0x1f2ce4,_0x1eb5e9),_0xca06b0++;let T=a[s(1281)+"ncoding"];if(e.thRBk(void 0,T))if(s(1693)===e[s(1830)])e[s(1724)](he,n,50),j(n,T);else{if(e[s(1280)](_0x38d737,_0x4abdfd))return new _0x100945(_0x1c1c82,_0x3c3e20);if(e[s(1433)](_0xe3f102,_0x3d9a69)&&e.yVxlS(s(1692)+"d",typeof _0x30a323))return new _0x2df8b1(_0x54a883,_0x30dcbf);if(e[s(1433)](_0x14fc5c,_0x3dc28f)&&e[s(1493)]!=typeof _0x39bddf)return new _0x3718be(_0x1f5d31,_0x4750e2);throw new _0x2ded81(e[s(1880)])}let A=a[s(668)+"ype"];if(e.moApX(void 0,A))if(e[s(983)](e[s(1694)],e.LkGFL)){let je=_0x2c64d8[s(708)]();return je?(je[s(1584)]=je[s(1556)]=0,je):{bytes:new _0x463f2f(64),offset:0,limit:0}}else e.jyGUF(he,n,58),e[s(1472)](j,n,A);let P=a.payload;if(e[s(1533)](void 0,P))if(e.SpmuX("tjaxL",e[s(1902)])){let je=(s(1183)+"2").split("|"),zt=0;for(;;){switch(je[zt++]){case"0":this[s(1834)][s(1360)+s(386)+s(895)](e[s(1297)],this._onClose);continue;case"1":this[s(1834)][s(1360)+"entListe"+s(895)](e.fdJXQ,this[s(312)]);continue;case"2":this._ws["removeEv"+s(386)+"ner"](e[s(1303)],this._onError);continue;case"3":if(!this[s(1834)])return;continue;case"4":this[s(1834)]["removeEv"+s(386)+s(895)]("message",this[s(714)+"ge"]);continue}break}}else e.BoJdw(he,n,66),he(n,P.length),e[s(562)](oe,n,P);let U=a[s(1346)];U!==void 0&&(he(n,74),e[s(600)](j,n,U));let H=a[s(1781)+s(1309)];if(H!==void 0){if(e[s(621)](e[s(1602)],e.jVZdp))return e.znJus(_0x4bd7f9,_0x41bbf1);e[s(1724)](he,n,82),j(n,H)}let Y=a[s(1673)];e.OdVgW(void 0,Y)&&(e.mXBtY(he,n,90),e[s(1607)](j,n,Y));let qe=a.frameType;qe!==void 0&&(e[s(480)](he,n,96),e.olnUN(ft,n,e[s(911)](O,qe)))}}function v(a){let n=t;return e[n(1735)](I,e[n(821)](F,a))}function I(a){let n=t,s={lXrhH:n(1757),SlaHZ:function(u,h,g){return e[n(1666)](u,h,g)}},d={};e:for(;!e[n(998)](V,a);){let u=e[n(1566)](xe,a);switch(e[n(893)](u,3)){case 0:break e;case 1:d[n(673)]=vt(a,!0);break;case 2:d[n(1765)]=e.RSXnC(vt,a,!0);break;case 3:d.service=e[n(1566)](xe,a);break;case 4:d[n(1239)]=xe(a);break;case 5:if(e[n(966)](e.nGTUI,n(978))){let h=e[n(1345)](C,a);(d[n(1225)]||(d[n(1225)]=[]))[n(1774)](e[n(1735)](_,a)),a[n(1556)]=h;break}else this[n(521)](s.lXrhH,s[n(348)](_0x22dc02,s.lXrhH,{message:this[n(1233)+"rrorMess"+n(1599)](_0x3143d2)}));case 6:d.payloadEncoding=e[n(1867)](N,a,e[n(1566)](xe,a));break;case 7:d[n(668)+"ype"]=e[n(1432)](N,a,xe(a));break;case 8:d.payload=e.lQoel(ie,a,e.suMlc(xe,a));break;case 9:d[n(1346)]=e[n(1738)](N,a,e.BFhEG(xe,a));break;case 10:d[n(1781)+"ming"]=e[n(1713)](N,a,e[n(1717)](xe,a));break;case 11:d[n(1673)]=e[n(1607)](N,a,e[n(821)](xe,a));break;case 12:d.frameType=e[n(995)](xe,a);break;default:e[n(1736)](R,a,e[n(689)](7,u))}}if(e[n(1779)](void 0,d[n(673)]))throw new Error(n(994)+"required"+n(455)+n(673));if(e[n(491)](void 0,d[n(1765)]))throw new Error(e[n(1184)]);if(e[n(491)](void 0,d.service))throw new Error(e[n(1169)]);if(e[n(1779)](void 0,d.method))throw new Error(e[n(1623)]);return d}function C(a){let n=t,s=e[n(821)](xe,a),d=a[n(1556)];return a[n(1556)]=a[n(1584)]+s,d}function R(a,n){let s=t;if(e[s(1064)](e[s(1039)],e.AcaCF)){let d=e[s(344)][s(1419)]("|"),u=0;for(;;){switch(d[u++]){case"0":this[s(1834)]["addEvent"+s(1583)](e[s(1303)],this._onError);continue;case"1":if(!this[s(1834)])return;continue;case"2":this._ws[s(1617)+"Listener"](s(627),this[s(312)]);continue;case"3":this._ws[s(1617)+"Listener"]("close",this[s(790)]);continue;case"4":this[s(1834)][s(1617)+s(1583)](e[s(571)],this[s(714)+"ge"]);continue}break}}else switch(n){case 0:for(;128&e[s(995)](se,a););break;case 2:e[s(600)](J,a,e[s(1875)](xe,a));break;case 5:e.RSXnC(J,a,4);break;case 1:e[s(1325)](J,a,8);break;default:throw new Error(e.wBaGu(e.QypMO,n))}}function O(a){let n=t;return a|=0,{low:a,high:e[n(1540)](a,31),unsigned:e[n(333)](a,0)}}let E=[];function D(){let a=t,n=E[a(708)]();return n?(n[a(1584)]=n[a(1556)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function L(a){E[t(1774)](a)}function F(a){return{bytes:a,offset:0,limit:a.length}}function z(a){let n=t,s=a[n(1392)],d=a[n(1556)];return e[n(1816)](s.length,d)?s:s.subarray(0,d)}function J(a,n){let s=t;if(e[s(729)](e[s(538)](a[s(1584)],n),a[s(1556)]))throw new Error(s(1826)+"t limit");a[s(1584)]+=n}function V(a){let n=t;return e[n(863)](a[n(1584)],a.limit)}function te(a,n){let s=t,d=a[s(1392)],u=a[s(1584)],h=a[s(1556)],g=e[s(1439)](u,n);if(e[s(1843)](g,d[s(519)])){let b=new Uint8Array(2*g);b.set(d),a[s(1392)]=b}return a[s(1584)]=g,e.nDtju(g,h)&&(a.limit=g),u}function Z(a,n){let s=t,d=a[s(1584)];if(e[s(1041)](d,n)>a[s(1556)])throw new Error(e[s(1271)]);return a[s(1584)]+=n,d}function ie(a,n){let s=t,d=Z(a,n);return a[s(1392)][s(391)](d,e[s(1082)](d,n))}function oe(a,n){let s=t,d=e[s(562)](te,a,n[s(519)]);a[s(1392)].set(n,d)}function N(a,n){let s=t,d=e[s(481)](Z,a,n),u=String[s(697)+s(1425)],h=a.bytes,g="\uFFFD",b="";for(let m=0;e.eECOd(m,n);m++){let T=h[e[s(1439)](m,d)],A,P,U,H;e[s(1816)](e[s(1142)](128,T),0)?b+=u(T):(224&T)===192?e[s(412)](m,1)>=n?b+=g:(A=h[e[s(1439)](e.FKdsf(m,d),1)],e.OdVgW(192&A,128)?b+=g:(H=e.KNDqF(e[s(684)](e[s(592)](31,T),6),e.rRxHE(63,A)),H<128?b+=g:e[s(1064)](e.wZOvR,e[s(1474)])?this[s(678)]?.[s(710)](_0x3d1206[s(992)+"id"]):(b+=e[s(1416)](u,H),m++))):e[s(1581)](e[s(1528)](240,T),224)?e.mhkEq(m+2,n)?b+=g:(A=h[e[s(1849)](m+d,1)],P=h[e.bGuuv(m,d)+2],e[s(366)](e.zUTmB(A,e[s(1775)](P,8)),49344)!==32896?b+=g:(H=e[s(692)](e.KNDqF(e.buKUt(15&T,12),e[s(592)](63,A)<<6),63&P),e[s(1510)](H,2048)||e.ADZbt(H,55296)&&e.MPNaY(H,57343)?b+=g:(b+=e[s(785)](u,H),m+=2))):e[s(1581)](248&T,240)?e[s(1357)](m,3)>=n?b+=g:(A=h[m+d+1],P=h[e[s(585)](e[s(949)](m,d),2)],U=h[e.QHkxq(m+d,3)],e[s(1286)](e[s(689)](e[s(1873)](A,e[s(1620)](P,8))|e.RHBNn(U,16),12632256),8421504)?b+=g:(H=e[s(661)](e[s(1620)](e[s(792)](7,T),18)|e.aJafh(63&A,12)|(63&P)<<6,e.RxUAv(63,U)),H<65536||e.nDtju(H,1114111)?b+=g:(H-=65536,b+=u(e[s(1591)](H,10)+55296,e[s(1803)](e[s(853)](1023,H),56320)),m+=3))):b+=g}return b}function j(a,n){let s=t,d={hMugP:function(u,h){return e.QHkxq(u,h)},zysrO:function(u,h){return e[M(726)](u,h)},SCIGL:function(u){return u()}};if(e[s(588)]("qrFgC",e.icdwA))return this[s(619)].readyState;{let u=n[s(519)],h=0;for(let m=0;e[s(1835)](m,u);m++){let T=n[s(1208)+"At"](m);T>=55296&&e.MPNaY(T,56319)&&e.wBaGu(m,1)<u&&(T=e.ePMHT((T<<10)+n[s(1208)+"At"](++m),56613888)),h+=e[s(1835)](T,128)?1:e[s(1380)](T,2048)?2:e.VSnGm(T,65536)?3:4}e[s(1724)](he,a,h);let g=e.Xyoxp(te,a,h),b=a[s(1392)];for(let m=0;e[s(1348)](m,u);m++){let T=n[s(1208)+"At"](m);if(e.mhkEq(T,55296)&&T<=56319&&e.GhZiD(m+1,u)&&(T=e[s(1144)](e[s(1592)](T,10)+n.charCodeAt(++m),56613888)),e[s(764)](T,128))b[g++]=T;else{if(T<2048)b[g++]=e.eYGjC(e.FjtzW(e[s(1540)](T,6),31),192);else if(e[s(743)](e[s(476)],s(1350))){let A=_0x378b10.length&&_0x2a0f1d[0];if(A instanceof _0xe0cdae)throw A;let P=new _0x48f922(d.hMugP(s(613)+s(1444),A?d[s(1499)](" (",A[s(558)])+")":""));throw P[s(885)]=A,A}else e[s(1835)](T,65536)?b[g++]=e[s(1189)](e[s(1528)](T>>12,15),224):e[s(823)]==="HpFDQ"?(b[g++]=e.UVXvt(e.MwpRP(T>>18,7),240),b[g++]=e[s(475)](T>>12,63)|128):(_0x69a24f(),YEnIDH[s(441)](_0x412805)),b[g++]=e[s(1873)](e[s(689)](e[s(1540)](T,6),63),128);b[g++]=e[s(1821)](63,T)|128}}}}function $(a,n){let s=t,d=e[s(1738)](te,a,n[s(1556)]),u=a.bytes,h=n.bytes;for(let g=0,b=n[s(1556)];e[s(715)](g,b);g++)u[g+d]=h[g]}function se(a){let n=t;return a[n(1392)][e[n(481)](Z,a,1)]}function Ye(a,n){let s=t;if(e[s(971)]!=="jJZkN"){let d=e[s(1432)](te,a,1);a[s(1392)][d]=n}else this[s(521)](e.lkoMV,e[s(480)](_0xada62b,e[s(571)],{..._0x556de8}))}function xe(a){let n=t;if(e[n(1424)](e[n(655)],e[n(1254)])){let s=0,d=0,u;do u=e.WQfVx(se,a),s<32&&(d|=e.gIrtD(e.RGhLp(127,u),s)),s+=7;while(e.GBUup(128,u));return d}else _0x4a332c.log(_0x5ecdbb)}function he(a,n){let s=t;for(n>>>=0;e[s(364)](n,128);)e[s(1272)](Ye,a,e[s(1873)](127&n,128)),n>>>=7;Ye(a,n)}function vt(a,n){let s=t;if(e[s(1131)]!==e[s(1131)])this[s(1876)+"er"]&&_0x5413a1[s(1617)+s(1583)](e.qsgGo,this[s(1036)+"nLine"]),this._isBrowser&&_0x2ae50e[s(1617)+s(1583)](e[s(1337)],this["_handleO"+s(933)]),this[s(1876)+"er"]&&_0x24329[s(1617)+"Listener"](e[s(474)],this["_handleP"+s(653)]),this[s(1876)+"er"]&&_0x3df8d4[s(1617)+s(1583)](e.uwujK,this[s(367)+s(339)]);else{let d=0,u=0,h=0,g;return g=e[s(394)](se,a),d=e[s(1593)](127,g),e.MwpRP(128,g)&&(g=e.rQSYR(se,a),d|=e[s(637)](e[s(404)](127,g),7),e[s(1762)](128,g)&&(g=se(a),d|=e[s(1620)](127&g,14),e.PGWWc(128,g)&&(g=e[s(392)](se,a),d|=e[s(1343)](e[s(1142)](127,g),21),e[s(1762)](128,g)&&(g=e[s(1717)](se,a),u=e[s(366)](127,g),e.CZFQS(128,g)&&(e[s(654)]("NwiRP",e.ttZwp)?(this[s(521)](e[s(571)],_0x3ff1bb),this.onmessage&&this.onmessage(_0x2f1367)):(g=e[s(998)](se,a),u|=e[s(492)](127,g)<<7,128&g&&(e[s(596)]!==e[s(1899)]?(g=se(a),u|=e[s(1343)](e[s(1528)](127,g),14),128&g&&(g=se(a),u|=e.kHJaB(e[s(369)](127,g),21),e.AHDlZ(128,g)&&(g=e[s(911)](se,a),h=e[s(475)](127,g),128&g&&(g=e.gmAew(se,a),h|=e[s(1200)](127&g,7))))):_0x80e235[s(1774)](_0x1edc4a)))))))),{low:d|e[s(1200)](u,28),high:e[s(1720)](e.NDmfo(u,4),e.ymdcZ(h,24)),unsigned:n}}}function ft(a,n){let s=t,d=e[s(1119)](n[s(1327)],0),u=e.GABrE(e.WNYMQ(e[s(1831)](n[s(1327)],28),n[s(1413)]<<4),0),h=e[s(1119)](n[s(1413)],24),g=e.SpmuX(0,h)?e.rWKPC(0,u)?d<16384?e.vLvbH(d,128)?1:2:d<2097152?3:4:u<16384?e.vLvbH(u,128)?5:6:e[s(976)](u,2097152)?7:8:e[s(1270)](h,128)?9:10,b=e.rycGq(te,a,g),m=a[s(1392)];switch(g){case 10:m[b+9]=e[s(1287)](h,7)&1;case 9:m[e.cTqCw(b,8)]=e.iiRiy(9,g)?e[s(1530)](128,h):127&h;case 8:m[e[s(485)](b,7)]=e.OdVgW(8,g)?e[s(1766)](e[s(878)](u,21),128):e[s(366)](e.jHzfs(u,21),127);case 7:m[e[s(1140)](b,6)]=e[s(1633)](7,g)?e[s(1766)](u>>>14,128):e[s(1142)](u>>>14,127);case 6:m[e[s(485)](b,5)]=e.oyMTL(6,g)?e.EDBND(u>>>7,128):e[s(762)](e.FGuei(u,7),127);case 5:m[e.gjqUw(b,4)]=e.thRBk(5,g)?e.eYGjC(128,u):127&u;case 4:m[e[s(1045)](b,3)]=e[s(1884)](4,g)?e.EDBND(e[s(681)](d,21),128):e[s(1119)](d,21)&127;case 3:m[e[s(482)](b,2)]=e[s(1286)](3,g)?e[s(1769)](e[s(681)](d,14),128):e[s(1296)](d,14)&127;case 2:m[e[s(1041)](b,1)]=e[s(1884)](2,g)?e[s(1618)](d,7)|128:e[s(893)](d,7)&127;case 1:m[b]=g!==1?e[s(1690)](128,d):e[s(945)](127,d)}}function Qt(a){return e.ZhIxs(v,a)}function Bt(a){return e[t(1029)](S,a)}let en=65536,Kr=e[t(1789)],me=e[t(767)](en,en),Ae=e.DnpQC(me,me),Yn=Ae/2,De=String[t(319)+"e"][t(1208)+"At"];class fe{constructor(n,s,d){let u=t;this.isLong=!0,this.low=e[u(429)](0,n),this[u(1413)]=0|s,this[u(875)]=!!d}static[t(744)](n){return n&&n.isLong===!0}static[t(566)](n,s,d){return new fe(n,s,d)}static[t(1165)+"s"](n,s,d){let u=t;return d?fe.fromBytesLE(n,s):fe[u(1165)+u(970)](n,s)}static[t(1165)+t(1128)](n,s){let d=t;return new fe(e[d(1873)](e.MDjcG(e[d(661)](n[0],e[d(1391)](n[1],8)),e[d(1620)](n[2],16)),n[3]<<24),e[d(1368)](e[d(915)](n[4],e.wiFYB(n[5],8)),e[d(1620)](n[6],16))|n[7]<<24,s)}static[t(1165)+t(970)](n,s){let d=t;return new fe(e.KNDqF(e[d(512)](n[4],24)|e[d(1620)](n[5],16),e[d(1177)](n[6],8))|n[7],e.nlyaz(e[d(517)](n[0]<<24,e.DkPxF(n[1],16)),e[d(931)](n[2],8))|n[3],s)}static[t(368)](n){let s=t;return e[s(1408)](n,Kr)?Wd:new fe(e[s(1119)](e[s(1525)](e[s(550)](e.VihCL(De.call(n,0),e.ESLNZ(De[s(765)](n,1),8)),e[s(512)](De.call(n,2),16)),e[s(1343)](De[s(765)](n,3),24)),0),e[s(756)](e.Xgqha(e[s(1377)](e[s(1525)](De[s(765)](n,4),e[s(1449)](De[s(765)](n,5),8)),e[s(1200)](De[s(765)](n,6),16)),e[s(1896)](De[s(765)](n,7),24)),0),!0)}[t(1166)](){let n=t;return String["fromChar"+n(1425)](255&this[n(1327)],e[n(1287)](this[n(1327)],8)&255,e[n(378)](this[n(1327)]>>>16,255),e[n(1124)](this[n(1327)],24),255&this[n(1413)],e[n(1207)](e.jHzfs(this[n(1413)],8),255),e.liQcm(this[n(1413)]>>>16,255),e[n(681)](this[n(1413)],24))}static fromNumber(n,s=!0){let d=t;if(e.qVpHk(isNaN,n))return s?lp:Wd;if(s){if(e[d(1451)](n,Ae))return fp}else{if(e[d(920)](n,-Yn))return xp;if(e[d(949)](n,1)>=Yn)return up}return fe[d(566)](e[d(1058)](n,me)|0,e.ukHyx(n/me,0),s)}toNumber(){let n=t;return this[n(875)]?e[n(1086)](e.FBWch(this[n(1413)]>>>0,me),e.jHzfs(this[n(1327)],0)):e.CglmQ(this[n(1413)],me)+e[n(1421)](this[n(1327)],0)}isZero(){let n=t;return e[n(1700)](0,this[n(1413)])&&this[n(1327)]===0}[t(644)](n){let s=t;fe[s(744)](n)||(n=fe[s(1145)+"er"](n));let d=e.GABrE(this[s(1413)],16),u=e.nqvdn(65535,this[s(1413)]),h=e[s(878)](this[s(1327)],16),g=65535&this[s(1327)],b=e[s(848)](n[s(1413)],16),m=e.cmkkl(65535,n[s(1413)]),T=e.nBgpZ(n[s(1327)],16),A=e.BPYxE(65535,n[s(1327)]),P=0,U=0,H=0,Y=0;return Y+=e[s(1864)](g,A),H+=Y>>>16,Y&=65535,H+=e[s(1745)](h,T),U+=e[s(681)](H,16),H&=65535,U+=e[s(636)](u,m),P+=e[s(1230)](U,16),U&=65535,P+=e[s(1041)](d,b),P&=65535,fe.fromBits(e[s(517)](e[s(1775)](H,16),Y),e[s(1009)](e[s(1550)](P,16),U),this[s(875)])}equals(n){let s=t,d={jCyKr:s(1033)};if(e[s(1726)](s(365),e[s(751)]))return fe.isLong(n)||(n=fe[s(1145)+"er"](n)),this[s(875)]!==n[s(875)]&&e.colVL(e[s(681)](this[s(1413)],31),1)&&e[s(393)](e.iKHrl(n[s(1413)],31),1)?!1:e.coete(this[s(1413)],n[s(1413)])&&e[s(1175)](this[s(1327)],n[s(1327)]);this[s(521)](d[s(1066)],_0x290642(d.jCyKr,{..._0x5e3e13}))}addOne(){let n=t;return e[n(589)](-1,this[n(1327)])&&e.juQlo(-1,this[n(1413)])?fe[n(566)](0,0,this[n(875)]):e[n(621)](-1,this[n(1327)])?fe[n(566)](0,e[n(1101)](this.high,1),this[n(875)]):fe[n(566)](e[n(482)](this[n(1327)],1),this.high,this[n(875)])}toBytes(n){let s=t;return n?this[s(1456)+"E"]():this[s(1537)+"E"]()}[t(1456)+"E"](){let n=t,s=this[n(1413)],d=this[n(1327)];return[e[n(997)](255,d),e[n(439)](e[n(1421)](d,8),255),e[n(1232)](e.hlKYj(d,16),255),e[n(1034)](d,24),255&s,e[n(1405)](s>>>8,255),e[n(366)](s>>>16,255),s>>>24]}[t(1537)+"E"](){let n=t,s=this[n(1413)],d=this.low;return[e[n(1148)](s,24),e[n(1608)](e[n(982)](s,16),255),e[n(1037)](e.iKHrl(s,8),255),e[n(592)](255,s),e[n(434)](d,24),e[n(449)](e[n(1421)](d,16),255),e[n(378)](e.hlKYj(d,8),255),255&d]}}let Wd=new fe(0,0,!1),lp=new fe(0,0,!0),up=fe.fromBits(-1,2147483647,!1),fp=fe[t(566)](-1,-1,!0),xp=fe[t(566)](0,-2147483648,!1);var tn=(function(a){let n=t;if(e[n(1292)](e[n(1306)],e[n(576)])){let s=e.QJVdq[n(1419)]("|"),d=0;for(;;){switch(s[d++]){case"0":a[a[n(1434)+"ERROR"]=5004]=e[n(1438)];continue;case"1":a[a["MAX_RETR"+n(1508)+"R"]=5003]=n(789)+"IES_ERROR";continue;case"2":return a;case"3":a[a[e[n(1349)]]=5005]=e[n(1349)];continue;case"4":a[a[e[n(464)]]=5002]=e.hgyrY;continue;case"5":a[a[e.CXsPr]=5001]=e[n(935)];continue}break}}else return e[n(364)](this[n(1785)],this["maxLossC"+n(383)])})({});class Zn{constructor(n){let s=t;this[s(1186)]=n,this[s(1206)]=null}}class Kd extends Zn{constructor(n,s){let d=t;super(n),this[d(558)]=s&&s[d(558)]||null}}class $d extends Zn{constructor(n,s){let d=t;if(e[d(654)](e[d(1755)],e[d(1755)])){let u=e[d(1116)][d(1419)]("|"),h=0;for(;;){switch(u[h++]){case"0":super(n);continue;case"1":this.code=s&&s.code||5001;continue;case"2":this.error=s&&s.error||null;continue;case"3":this[d(427)]=s&&s[d(427)]||0;continue;case"4":this[d(1446)]=s&&s[d(1446)]||"";continue;case"5":this[d(1260)]=s&&s[d(1260)]||0;continue;case"6":this[d(558)]=s&&s[d(558)]||"";continue}break}}else this["_miniNav"+d(1247)+d(1813)]=_0x6f86,_0x2b39b7?this[d(1036)+"nLine"]():this[d(1036)+d(933)]()}}class Vd extends Zn{constructor(n,s){let d=t;super(n),this.code=s&&s[d(716)]||0,this.reason=s&&s[d(1096)]||"",this[d(310)]=s&&s[d(310)]||!1,this[d(695)+d(773)]=s&&s["willReco"+d(773)]||!1}}class Jd extends Zn{constructor(n,s){let d=t;super(n),this[d(397)]=s&&s[d(397)]||null}}class Yd extends Jd{constructor(n,s){let d=t,u={itkKb:function(h,g){return e[M(943)](h,g)},HRjnv:e[d(663)],ezQBa:e.TTHpd,tMCFC:e[d(1870)],KnZPa:e[d(1552)],kNUmn:e[d(1483)],qAQDz:function(h,g,b,m){return e[d(504)](h,g,b,m)}};if(e[d(529)](e[d(1806)],d(1478))){let h=u[d(483)](this[d(1268)][d(1281)+d(1418)],_0x4bf922)?{force:!!this[d(1268)][d(1281)+"ncoding"].force,encoding:this[d(1268)][d(1281)+d(1418)].encoding?this[d(1268)][d(1281)+d(1418)].encoding[d(1818)](/\s/g,"")[d(723)+d(742)]():""}:{force:!1,encoding:this[d(1268)][d(1281)+d(1418)]?this[d(1268)][d(1281)+d(1418)].replace(/\s/g,"")[d(723)+d(742)]():""},g=_0x1cb1e0[d(1281)+d(1418)]?_0x399ef6[d(1281)+d(1418)].replace(/\s/g,"")[d(723)+d(742)]():"",b=this[d(1268)][d(668)+"ype"]instanceof _0x482a51?{force:!!this._options["payloadT"+d(471)].force,type:this._options["payloadT"+d(471)][d(1186)]?this[d(1268)].payloadType[d(1186)][d(1818)](/\s/g,"")[d(723)+d(742)]():""}:{force:!1,type:this[d(1268)][d(668)+"ype"]?this[d(1268)][d(668)+d(471)][d(1818)](/\s/g,"")["toLowerC"+d(742)]():""},m=_0x1bc405[d(668)+d(471)]?_0x44c3b4[d(668)+"ype"][d(1818)](/\s/g,"")[d(723)+d(742)]():"",T=b[d(1866)]?b[d(1186)]:m||b.type,A=h.force?h[d(1443)]:g||h.encoding,P=[d(1277)+d(720)+"et=utf-8",u[d(1388)],u[d(774)],u[d(1664)]],U=[u[d(556)],u[d(1010)]];this._options[d(1364)+d(554)+d(1308)+"ad"]&&P[d(972)](T)&&(!A||U[d(972)](A))?_0x495565[d(634)+"oad"]=u[d(1604)](_0x2d8bba,_0x1c017f[d(1705)],0,_0x3f79c5.payload.byteLength):_0x4b02f6[d(634)+d(1886)]=""}else super(n),this.data=s&&s[d(397)]||null,this.message=s&&s[d(558)]||null}}class Zd extends Zn{constructor(n,s){let d=t;super(n),this.data=s&&s[d(397)]||null}}function at(a,{message:n,code:s,error:d}){let u=t;return e.nzjkr!==e[u(1372)]?e[u(776)](_0x1a3e2f,_0x226040)?_0x37dd42:new _0x589166(e[u(681)](e[u(1815)](e.rfevm(_0x272722[u(765)](_0x39f789,0)|e[u(1200)](_0x16cc3d.call(_0x4f0c25,1),8),e[u(1250)](_0xa9068b[u(765)](_0x56ee53,2),16)),_0x1cdd28[u(765)](_0x44ad81,3)<<24),0),e[u(982)](e[u(1696)](e[u(1452)](e[u(1241)](_0x54156d[u(765)](_0x4cea20,4),e[u(1449)](_0x16d9e4.call(_0x150a7f,5),8)),e[u(1635)](_0x12388f[u(765)](_0x2d7bc5,6),16)),_0x34857b[u(765)](_0x5cacb3,7)<<24),0),!0):new $d(a,{message:n,code:s,error:d})}function xt(a,{code:n,reason:s,wasClean:d,willReconnect:u}){return new Vd(a,{code:n,reason:s,wasClean:d,willReconnect:u})}function Xd(a,{data:n,message:s}){return new Yd(a,{data:n,message:s})}function Qd(a,{data:n}){let s=t;if(e[s(1292)](s(1653),e[s(1662)])){let d=_0x37e06b[s(1208)+"At"](_0x2aec6d);e[s(1451)](d,55296)&&d<=56319&&e[s(1380)](_0x4c4827+1,_0x5db9ea)&&(d=e.bEtSG(e[s(567)](d<<10,_0x4b2d20.charCodeAt(++_0x553956)),56613888)),_0x327c41+=e[s(715)](d,128)?1:e[s(1067)](d,2048)?2:e[s(803)](d,65536)?3:4}else return new Zd(a,{data:n})}function aa(a,{message:n}){return new Kd(a,{message:n})}class el{constructor(n,s){let d=t;e[d(864)](e[d(1676)],e.GaEsg)?(this[d(747)+"s"]=n,this[d(511)+"es"]=s,this[d(665)+d(374)]=0,this[d(1580)+d(1319)+d(477)+"t"]=0):(_0x3f8b64[d(691)+d(1047)]=void 0,e.osnAn(_0x3ec314,e[d(1645)]))}[t(1893)+"pointConfig"](){let n=t;if(e[n(611)](e.tdSSz,e[n(336)]))return _0x1b8756.errMsg||_0x125a54.errNo?(n(1611)+" "+(_0x1b9af7[n(405)]||"")+n(575)+(_0x1b73a6[n(457)]||""))[n(1220)]():_0x18a9b1.stringify(_0x5831a5);this[n(665)+n(374)]=0,this[n(1580)+n(1319)+n(477)+"t"]=0}[t(1903)+"es"](){let n=t;if(e[n(1837)]===e[n(1150)]){let s=e[n(1736)](_0x35b721,e.NRIPJ,{message:this[n(1233)+"rrorMess"+n(1599)](_0x5bdc96)});this[n(521)](e[n(1303)],s);let d=e[n(590)](_0x191632,e[n(1297)],{reason:this[n(1233)+n(1772)+n(1599)](_0x8545c3)});this[n(521)](e[n(1297)],d)}else this[n(1580)+n(1319)+n(477)+"t"]=0}[t(1750)+t(549)+"nt"](){let n=t;return this[n(747)+"s"][this[n(665)+n(374)]]}[t(1750)+t(549)+t(1761)+t(383)](){let n=t;return this[n(1580)+"ndpointT"+n(477)+"t"]}checkReachMaxTries(){let n=t;return!!(e.bGPMg(this["currentI"+n(374)],this.endpoints[n(519)])||this[n(665)+n(374)]===e[n(462)](this[n(747)+"s"][n(519)],1)&&e[n(989)](this[n(1580)+n(1319)+n(477)+"t"],this[n(511)+"es"]))}[t(690)+t(682)+t(380)+t(987)+t(1071)](){let n=t;return e[n(1581)](this[n(665)+n(374)],this.endpoints[n(519)])?!0:this[n(1580)+"ndpointTriesCount"]>this[n(511)+"es"]}[t(839)+t(1084)+t(1631)+"UpdateCo"+t(984)](){let n=t;return this[n(1580)+"ndpointT"+n(477)+"t"]=1,this[n(665)+n(374)]++,this[n(747)+"s"][this["currentI"+n(374)]]}[t(1750)+"ntEndpoi"+t(1312)+t(860)](){let n=t;return this[n(1580)+"ndpointTriesCount"]++,this[n(1750)+n(549)+"nt"]()}}let Xn=(e[t(501)](e[t(1493)],typeof globalThis)&&e[t(1415)](e.NDlRo,globalThis["construc"+t(1792)][t(892)])||e.spgjE(e[t(1493)],typeof window)&&e[t(1710)](e.NDlRo,window[t(883)+t(1792)][t(892)]))&&e[t(451)](e[t(1493)],typeof document),Cn=e[t(988)](t(1692)+"d",typeof globalThis)&&(e[t(916)](e.vtIgL,globalThis[t(883)+"tor"][t(892)])||e.pDOAn(e[t(1572)],globalThis.constructor[t(892)]))&&e.bgMHX(t(1692)+"d",typeof tt),$r=(e.ymvIK(e.QmwAb,typeof globalThis)&&e[t(946)](e[t(847)],globalThis[t(883)+t(1792)][t(892)])||e[t(1493)]==typeof globalThis||e[t(921)](e.QmwAb,typeof globalThis)&&!!globalThis.WeixinJSBridge)&&e[t(1493)]!=typeof wx,Vr=e[t(1323)](t(1692)+"d",typeof globalThis)&&(e[t(1048)](t(630)+t(701)+t(750)+"pe",globalThis["construc"+t(1792)][t(892)])||e[t(1447)]===globalThis[t(883)+t(1792)][t(892)]||e.MyBIv(e.jeXOw,globalThis[t(883)+t(1792)][t(892)]))&&e[t(1493)]!=typeof self,hp=e[t(921)]("undefined",typeof globalThis)&&e.tngDE(e.vtIgL,globalThis[t(883)+t(1792)].name)&&e.xgItI(t(1692)+"d",typeof global)&&e[t(1544)](e.vtIgL,global[t(883)+"tor"][t(892)])&&e[t(1004)](e[t(1493)],typeof process)&&!!process[t(1237)];class ca{constructor(){let n=t;if(e[n(1095)](e[n(868)],n(1521)))return new _0x396378(_0x557ccf,{data:_0x3eff23,message:_0x43665b});this[n(913)+"rs"]={}}[t(521)](n,...s){let d=t,u=this[d(913)+"rs"][n];if(u)u[d(329)]()[d(1121)](h=>h.fn[d(1072)](h.ctx,s));else if(e[d(866)](d(1757),n)&&!this[d(322)]){let h=s[d(519)]&&s[0];if(e[d(1311)](h,Error))throw h;let g=new Error(e.hVrPe(e[d(484)],h?e[d(1588)](e[d(1140)](" (",h[d(558)]),")"):""));throw g[d(885)]=h,h}return this}[t(1822)](n,s){let d=t;if(e[d(1122)](void 0,n))this[d(913)+"rs"]={};else if(e[d(1779)](void 0,s))this[d(913)+"rs"][n]=null;else{let u=this[d(913)+"rs"][n];if(u)for(let h=0;e[d(415)](h,u[d(519)]);)u[h].fn===s?u[d(1375)](h,1):++h}return this}on(n,s,d){let u=t;return(this[u(913)+"rs"][n]||(this[u(913)+"rs"][n]=[])).push({fn:s,ctx:d||this}),this}}class pp extends ca{[t(1233)+t(1772)+t(1599)](n){let s=t;return n.errMsg||n[s(457)]?(s(1611)+" "+(n.errMsg||"")+s(575)+(n[s(457)]||""))[s(1220)]():JSON[s(748)+"y"](n)}constructor(n,s,d){let u=t;if(u(574)==="sYBsR")super(),this[u(619)]=null,$r&&wx[u(955)+u(569)]&&(this._socket=wx[u(955)+u(569)]({url:n,protocols:s,header:d,fail:this["_createS"+u(1003)+u(707)][u(770)](this),success:this[u(409)+u(846)+u(565)+u(1845)][u(770)](this)})),Cn&&tt[u(955)+u(569)]&&(this._socket=tt["connectS"+u(569)]({url:n,protocols:s,header:d,fail:this[u(409)+u(1003)+u(707)][u(770)](this),success:this[u(409)+u(846)+u(565)+u(1845)].bind(this)}));else{let{pingInterval:h,pingFrequency:g}=this[u(1268)];if((e[u(1336)]("hi",_0x986e99[u(397)])&&e[u(582)](e.sOjMM,g)||e[u(1689)]===g)&&(this[u(904)+u(493)](),this[u(521)](e.SpJYa,e[u(1110)]),this[u(446)+u(1285)+"Id"]=_0x5b65fd(this[u(1462)].bind(this),h)),e[u(625)]("hi",_0x33d8c3[u(397)]))return;try{e[u(504)](_0x331a76,this,_0x5ee0cb,[_0x4002d3,_0x459c78,_0x3f3282,_0x516547,_0x1d67b1,_0x1338c4])}catch(b){let m=_0x226da3(e[u(1303)],{message:b[u(558)],code:_0x4a4cd8[u(1434)+u(1061)],error:b});this[u(1160)+u(1161)+u(349)](m)}}}[t(409)+t(846)+t(565)+"ler"](){let n=t;Promise[n(466)]()[n(1344)](()=>{this[n(827)+"steners"]()})}[t(409)+t(1003)+t(707)](n){let s=t;Promise[s(466)]()[s(1344)](()=>{let d=s,u=at(e[d(1303)],{message:this["_formatE"+d(1772)+"age"](n)});this[d(521)](e[d(1303)],u);let h=xt(e[d(1297)],{reason:this[d(1233)+d(1772)+d(1599)](n)});this[d(521)](e.fMlbV,h)})}[t(827)+t(1786)](){let n=t,s={YSsfe:function(d,u){return e[M(1326)](d,u)},sPijO:function(d,u){return e.jePEE(d,u)},sMUJJ:function(d,u){return e[M(1642)](d,u)},vXdrq:function(d,u){return e[M(615)](d,u)},BAONK:function(d,u){return e[M(366)](d,u)},TNhmJ:function(d,u){return e[M(567)](d,u)},MCfsg:function(d,u){return e.qDbIa(d,u)},UwPjf:function(d,u){return e[M(1140)](d,u)},dsoit:function(d,u){return d|u},tDDpf:function(d,u){return d<<u},XOhbb:function(d,u){return e[M(1175)](d,u)},VYzZI:e.bVTbJ,CGRcQ:e[n(1297)],tQNiV:function(d,u,h){return d(u,h)},PihCB:e[n(1303)],nyTck:function(d,u,h){return d(u,h)}};this[n(619)][n(1515)](d=>{let u=n;this[u(521)]("open",Qd(u(627),{...d,data:d[u(405)]||""}))}),this._socket[n(508)](d=>{let u=n;if(s[u(1158)](s.VYzZI,s[u(1156)]))this[u(521)](s[u(981)],s[u(686)](xt,s[u(981)],{...d}));else{_0x148714[u(744)](_0x34d8e1)||(_0x3428a1=_0x42589a[u(1145)+"er"](_0x55f9d3));let h=EyPkQs.YSsfe(this[u(1413)],16),g=65535&this[u(1413)],b=EyPkQs[u(1887)](this[u(1327)],16),m=EyPkQs[u(962)](65535,this[u(1327)]),T=EyPkQs[u(810)](_0x337668[u(1413)],16),A=EyPkQs[u(962)](65535,_0x2205b1.high),P=EyPkQs[u(384)](_0x3f54fa.low,16),U=EyPkQs[u(385)](65535,_0x296ae6.low),H=0,Y=0,qe=0,je=0;return je+=EyPkQs.TNhmJ(m,U),qe+=EyPkQs.MCfsg(je,16),je&=65535,qe+=EyPkQs[u(1223)](b,P),Y+=EyPkQs[u(810)](qe,16),qe&=65535,Y+=EyPkQs[u(1223)](g,A),H+=Y>>>16,Y&=65535,H+=EyPkQs[u(771)](h,T),H&=65535,_0x4b2020[u(566)](EyPkQs[u(1007)](EyPkQs[u(442)](qe,16),je),H<<16|Y,this.unsigned)}}),this[n(619)][n(373)+"e"](d=>{let u=n,h={znZwc:function(g,b,m){return e[M(480)](g,b,m)},kgLLg:e[u(1297)]};if(e.AAOPu(e[u(713)],e[u(713)]))this[u(521)](e[u(571)],Xd(u(558),{...d}));else{let g=this["_endpoin"+u(828)]?.[u(1750)+u(549)+"nt"]();this[u(1160)+u(1546)+u(349)](h[u(1848)](_0x93efed,h[u(1445)],{code:_0x4c3c47.code,reason:u(1402)+"ng faile"+u(350)+u(488)+"n, hostn"+u(563)+g})),this[u(1196)+"tManager"]?.[u(1893)+u(1340)+u(1113)](),this["_pingLos"+u(858)]?.[u(1290)+u(914)]();return}}),this[n(619)].onError(d=>{let u=n;this.emit(s.PihCB,s[u(1026)](at,s[u(1833)],{...d,message:d.errMsg||""}))})}[t(1422)](n){let s=t,d={JwwHA:e[s(1303)],KLVyJ:function(u,h,g){return e[s(562)](u,h,g)}};if(n instanceof Uint8Array){let u=n[s(1534)][s(329)](n[s(1748)+"et"],e[s(428)](n[s(1228)+"th"],n.byteOffset));this[s(619)]&&this[s(619)][s(1422)]({data:u,fail:h=>{let g=s;this[g(521)](d[g(1027)],d.KLVyJ(at,d[g(1027)],{message:this[g(1233)+"rrorMess"+g(1599)](h)}))}})}else this[s(619)]&&this[s(619)][s(1422)]({data:n,fail:u=>{let h=s;this[h(521)](e[h(1303)],e[h(1325)](at,e[h(1303)],{message:this["_formatE"+h(1772)+h(1599)](u)}))}})}close(n,s){let d=t;e[d(318)](e[d(1647)],d(1680))?this._socket&&this[d(619)][d(1033)]({code:n,reason:s}):_0x56a1a2[d(1476)](_0x1ac509)}[t(1617)+t(1583)](n,s){this.on(n,s)}["removeEv"+t(386)+t(895)](n,s){this.off(n,s)}get[t(1371)+"te"](){let n=t,s={OJgRy:function(d,u){return d===u}};return e[n(1574)](e[n(1278)],e[n(1278)])?this._socket.readyState:_0x3c0eec&&ReEvfa.OJgRy(!0,_0xab91fd[n(744)])}get[t(1435)+"pe"](){let n=t;return this[n(619)][n(1435)+"pe"]}set binaryType(n){}get url(){let n=t;if(e[n(1257)]!==n(1744))return this[n(619)][n(969)];this[n(1729)+n(788)]()}get[t(433)](){return this[t(619)].protocol}get[t(1637)+"ns"](){let n=t;if(e.HGXJl==="HyqEQ")this[n(1822)](_0x563d48,_0x916df8);else return this[n(619)][n(1637)+"ns"]}get["buffered"+t(1874)](){return 0}}function gp(a,n){let s=t,d={UJxCP:function(u,h){return u<h},KmMvQ:function(u,h){return u===h}};if(e[s(326)]===e[s(1891)]){let u=this[s(913)+"rs"][_0x254740];if(u)for(let h=0;ibEmHI[s(325)](h,u[s(519)]);)ibEmHI[s(1056)](u[h].fn,_0x2711fa)?u[s(1375)](h,1):++h}else{if(n)return new n(a[s(969)],a.protocol);if($r||Cn)return new pp(a[s(969)],a[s(433)],a.headers);if(e.PCLbU(Xn,Vr)&&e[s(501)](s(1692)+"d",typeof WebSocket)&&WebSocket)return new WebSocket(a[s(969)],a[s(433)+"s"])}}function mp(a){let n=t,s=e[n(1002)][n(1419)]("|"),d=0;for(;;){switch(s[d++]){case"0":if(e[n(1882)](Xn,Vr)&&e[n(1890)](e.QmwAb,typeof WebSocket)&&WebSocket)return!0;continue;case"1":if(a)return!0;continue;case"2":return!1;case"3":if(Cn&&tt["connectS"+n(569)])return!0;continue;case"4":if($r&&wx["connectS"+n(569)])return!0;continue}break}}function tl(a,n,s){let d=t;if(e.IlPYV("RCALL",d(381))){let u=_0x4824a6["deleteDa"+d(845)](_0x26a2d9);return _0x4f12b9&&u[d(1617)+d(1583)](PtvMwI[d(1467)],()=>_0x36444d()),PtvMwI.wwXzc(_0x24b82c,u)[d(1344)](()=>{})}else{let u=-1;async function h(g){let b=d,m={DoXqm:e[b(1297)]};if(e[b(1251)](e[b(1273)],e.FvpwT))this[b(521)](m[b(1062)],_0x41f613),this[b(1304)]&&this[b(1304)](_0x1f5149);else return g<=u?Promise[b(1489)](new Error(e[b(1077)])):(u=g,g===s[b(519)]?Promise[b(466)]():s[g][b(770)](a)(n,h[b(770)](null,e[b(949)](g,1))))}e[d(666)](h,0)}}function nl(a){let n=t,s=0,d=0;for(let u=0;e[n(540)](u,a.length);++u)if(e.pjnAM(e[n(503)],n(1469)))d=a[n(1208)+"At"](u),e[n(1510)](d,128)?s+=1:d<2048?s+=2:e[n(316)](e.CMHbm(64512,d),55296)&&e.OJrVY(64512&a[n(1208)+"At"](e[n(1430)](u,1)),56320)?(++u,s+=4):s+=3;else return new _0x36e873(_0x8c6172,{message:_0xaecf98});return s}function rl(a,n,s){let d=t,u={xEfRA:function(g,b){return g>>>b},MIyvY:function(g,b){return e[M(423)](g,b)},UAjlI:function(g,b){return e[M(475)](g,b)},ToLaU:function(g,b){return g>>>b},auhxU:function(g,b){return g>>>b},qriKt:function(g,b){return g>>>b},bjYdW:function(g,b){return e[M(1762)](g,b)}};if(e[d(415)](e[d(595)](s,n),1))return"";let h="";for(let g=n;e[d(1348)](g,s);){let b=a[g++];if(b<=127)h+=String["fromChar"+d(1425)](b);else if(e[d(863)](b,192)&&b<224)h+=String[d(697)+d(1425)](e[d(550)](e[d(1620)](31&b,6),e[d(960)](63,a[g++])));else if(b>=224&&e[d(976)](b,240))h+=String[d(697)+d(1425)](e.LXHTn((15&b)<<12|(63&a[g++])<<6,63&a[g++]));else if(b>=240)if(e[d(1707)](e[d(1108)],d(1542))){let m=e.XUjKc(e[d(1555)](e[d(1046)](e[d(1330)]((7&b)<<18,e[d(1111)](e.ZiWSp(63,a[g++]),12)),e[d(1227)](63,a[g++])<<6),e[d(1301)](63,a[g++])),65536);h+=String[d(697)+d(1425)](55296+(m>>10)),h+=String[d(697)+d(1425)](e[d(412)](56320,e[d(960)](1023,m)))}else{let m=this[d(1413)],T=this[d(1327)];return[tJIMsX.xEfRA(m,24),tJIMsX[d(618)](m>>>16,255),tJIMsX[d(1503)](tJIMsX[d(403)](m,8),255),255&m,tJIMsX[d(1209)](T,24),tJIMsX[d(1395)](T,16)&255,tJIMsX[d(1503)](tJIMsX[d(967)](T,8),255),tJIMsX.bjYdW(255,T)]}}return h}function da(a,n,s){let d=t,u=s,h,g;for(let b=0;e.GhZiD(b,a[d(519)]);++b)if(h=a.charCodeAt(b),e[d(1409)](h,128))n[s++]=h;else if(h<2048)n[s++]=e[d(1690)](e.tVJCU(h,6),192),n[s++]=e.YipCD(e[d(1405)](63,h),128);else if(e[d(1702)](e[d(945)](64512,h),55296)&&e.eiIJf(64512&(g=a[d(1208)+"At"](e[d(1479)](b,1))),56320)){let m=e[d(1159)][d(1419)]("|"),T=0;for(;;){switch(m[T++]){case"0":n[s++]=e.rfevm(e[d(1540)](h,18),240);continue;case"1":h=e[d(1906)](65536+e.lTksy(1023&h,10),e[d(1528)](1023,g));continue;case"2":n[s++]=e[d(1525)](e[d(1217)](h,12)&63,128);continue;case"3":n[s++]=e[d(661)](e[d(1612)](63,h),128);continue;case"4":++b;continue;case"5":n[s++]=e[d(510)](e.WwDFi(e.CkLvB(h,6),63),128);continue}break}}else n[s++]=e.EKRUF(h,12)|224,n[s++]=e[d(1452)](e.suJdt(h>>6,63),128),n[s++]=e[d(854)](63&h,128);return e.XUjKc(s,u)}async function il(a){let n=t;if(e[n(1870)]==typeof a){let s=new Uint8Array(e.wMNiI(nl,a));return e[n(487)](da,a,s,0),s}return e[n(1549)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a.buffer,a[n(1748)+"et"],a[n(1228)+"th"])}function wp(a){let n=t;try{return e[n(1323)](e.hDxqx,typeof a)&&(a instanceof ArrayBuffer||a[n(1534)]&&a.buffer instanceof ArrayBuffer)||e[n(1284)](e[n(1870)],typeof a)?"":(JSON[n(1711)](a),e[n(663)])}catch{return e.wSeuK(e[n(1870)],typeof a)?e.XBLJy:""}}let _p=(a,n)=>{let s=t;if(e.NoxHv(e.UJiMc,e[s(1291)])){let d=_0x175f6d[s(1419)](/\./)[s(1129)](g=>_0x1faf35(g)),u=[];return u[0]=e.crPCl(_0x25062f,e.zmckP(d[0],d[1])),u[1]=e.rUEkD(_0x5d63d8,e.CGvIO(d[2],d[3])),[e[s(1518)],e[s(1518)],e[s(1518)],e[s(1518)],e.QvCeK,e[s(1035)],u[0],u[1]][s(676)]("")}else switch(a){case s(1793):case s(622):return{[s(617)+a]:1,"x-tt-env":n};default:return{}}};class yp{constructor(n){let s=t;this[s(880)+s(383)]=n,this.count=0}[t(973)](){let n=t;this[n(1785)]++}[t(1253)+t(1070)+"nt"](){let n=t;return e[n(1451)](this[n(1785)],this[n(880)+n(383)])}[t(1290)+"nter"](n=0){let s=t;this[s(880)+s(383)]=n,this[s(1785)]=0}}async function Ep(a){let n=t,s={HViDI:function(d,u){return d(u)},NquJQ:e[n(1645)],lqWzt:e[n(382)],xhhyq:e[n(1838)],uIDbI:function(d,u){return e[n(1803)](d,u)},qQQHL:n(1791),zwfuL:e.hJBXR};return new Promise(d=>{let u=n,h={tIVui:"unknown reason"};if(!Xn)return s[u(1796)](d,s[u(1333)]);try{let g=document[u(340)+u(809)](s[u(1016)]);window[u(691)+u(1047)]=b=>{let m=u;document[m(1797)]["removeCh"+m(1808)](g),window["frontier"+m(1047)]=void 0,d(b&&b[m(671)]||h[m(1496)])},g[u(1186)]=s.xhhyq,g[u(1594)]=s[u(1202)](a[u(1818)](/^ws/,s[u(317)]),s[u(722)]);try{document.body[u(1204)+u(1808)](g)}catch{document[u(1797)][u(1714)+u(1808)](g)}}catch{window[u(691)+"JSONP"]=void 0,d(u(801)+u(1096))}})}function nn(a,n,s){let d=t;return!!a?.[d(345)](u=>u[d(925)]===n&&u[d(1832)]===s)}function Qn(a,n){let s=t;return a?.[s(345)](d=>d[s(925)]===n)?.[s(1832)]}let la=null;async function bp(){let a=t;return la||(la=Promise[a(466)]()[a(1344)](Nt[a(770)](Nt,a(438)))),la}class vp extends ca{constructor(n,s){let d=t;super(),this[d(738)]=n,this[d(942)]=s,this[d(678)]=void 0,this[d(700)+d(818)]=null}async[t(1242)](){await this[t(395)]()}async[t(395)](){let n=t;if(!this._qosDB){if(this[n(700)+n(818)])return this["_initPro"+n(818)];try{let s=this[n(738)],d=this[n(942)];this[n(700)+"mise"]=(async()=>{let u=n,{openDB:h}=await bp();this[u(678)]=await e.CRZIR(h,u(691)+"_"+s,1,{upgrade(g){let b=u;g[b(1132)+b(1681)+"e"](s,{keyPath:d})}})})(),await this[n(700)+n(818)]}catch(s){e[n(966)](e[n(525)],e[n(525)])?_0x18af8a[n(1476)](_0x442071):console[n(1476)](s)}finally{e[n(520)]!==e[n(520)]?this[n(733)+"T"]?_0x288b12[n(1514)+n(1723)+n(513)](({isConnected:s})=>{let d=n;this[d(1335)+"igatorOn"+d(1813)]=s,s?this[d(1036)+d(490)]():this[d(1036)+d(933)]()}):this[n(1853)+"X"]&&_0x3b4bbe[n(1514)+n(1723)+"hange"](({isConnected:s})=>{let d=n;this["_miniNav"+d(1247)+"line"]=s,s?this[d(1036)+d(490)]():this[d(1036)+d(933)]()}):this[n(700)+n(818)]=null}}}async[t(1079)](n){let s=t;try{return await this._init(),this[s(678)]?.[s(1079)](this[s(738)],n)}catch(d){e[s(983)](e[s(737)],e[s(737)])?(_0x4ba6a3=e[s(727)](e[s(1473)](e[s(1646)](15&_0x3a7931,12),e[s(1405)](63,_0x45053f)<<6),63&_0x4284d6),e[s(1012)](_0x591d54,2048)||e[s(333)](_0x1428fa,55296)&&e[s(401)](_0x1eb739,57343)?_0x4a1cf7+=_0xe5240c:(_0x94e5fc+=e[s(711)](_0x35314d,_0x4e8367),_0x554752+=2)):console[s(1476)](d)}}async set(n,s){let d=t;return await this[d(395)](),this._qosDB?.put(this[d(738)],n)}async[t(710)](n){let s=t,d={vcSoG:function(u,h,g,b){return u(h,g,b)},QBbuc:function(u,h,g,b){return e[M(504)](u,h,g,b)},qCDMW:e[s(1732)],IXnhU:function(u,h){return u&&h},xUwnE:function(u){return e[s(1743)](u)}};if(e[s(909)]!=="xkARE"){let{enableAutoAck:u}=this[s(1268)],h=d[s(1784)](_0x1cd773,_0x4f6c95.message[s(1225)],s(353),"1"),g=d[s(730)](_0x400c61,_0xa548df[s(558)].headers,d[s(1846)],"1"),b=_0x12c6bd[s(765)](this,_0x3251e8);if(d[s(1909)](u,h)){let{SeqID:m,LogID:T,service:A,LogIDNew:P,method:U}=_0x18bdec[s(558)];this[s(1396)]({SeqID:m,LogID:T,LogIDNew:P,service:A,method:U,headers:[{key:"is_ack",value:"1"},{key:s(332),value:P||""},{key:s(1216),value:"0"}]})}g&&!b.isQoSAck&&this._dispatchAckMessageEvent(_0x2c08cf),d[s(1283)](_0x2ce536)}else try{if(e[s(529)](e[s(1136)],e[s(1136)])){let u=e[s(1654)][s(1419)]("|"),h=0;for(;;){switch(u[h++]){case"0":this[s(907)+s(1829)]=!0;continue;case"1":this[s(879)+s(1313)+"t"](_0x19e520,_0x1e9d71);continue;case"2":this[s(1460)+s(1191)]?.[s(1895)]();continue;case"3":this[s(1259)+s(769)]();continue;case"4":if(!this[s(1834)])return void this[s(812)](e.zEPzw);continue;case"5":if(e[s(705)](this._ws[s(1371)+"te"],this.CLOSED)||e[s(633)](this[s(1834)][s(1371)+"te"],this[s(1170)]))return void this[s(812)](e[s(1279)]);continue;case"6":this._clearPingTimer();continue;case"7":this[s(1605)+"balEvent"+s(1583)]();continue}break}}else return await this[s(395)](),this[s(678)]?.[s(408)](this._dbName,n)}catch(u){console.log(u)}}async[t(1561)](){let n=t;try{return await this[n(395)](),this[n(678)]?.[n(1561)](this[n(738)])}catch(s){console[n(1476)](s)}}async[t(1366)](){let n=t;if(e[n(314)]===e.KiAHx)_0x40048c=e.VzuwS,_0x617e6f=_0x59946e[n(1818)](/(^http)((?:[s]*:\/\/))/,""),_0x4fb94b=/(^ws)((?:[s]*:\/\/))/.test(_0x4b7224)?_0x26ef3b:""+_0x5e8e83+_0x4fdecd;else return await this[n(395)](),this._qosDB?.getAllKeys(this[n(738)])}async[t(1288)](){let n=t;return n(1134)!==e[n(1199)]?(await this._init(),this[n(678)]?.getAll(this[n(738)])):_0x5835d5[n(697)+n(1425)](e.AiRar(255,this[n(1327)]),e[n(1037)](this[n(1327)]>>>8,255),e.lTHRe(e.yhQyd(this[n(1327)],16),255),this[n(1327)]>>>24,e[n(1195)](255,this[n(1413)]),e[n(1685)](e[n(1034)](this[n(1413)],8),255),this.high>>>16&255,this.high>>>24)}async[t(1895)](){let n=t,s={FHrsv:e[n(1487)]};if(e[n(777)](e[n(1329)],"pPqeF"))try{this[n(678)]?.[n(1033)](),this[n(678)]=void 0}catch(d){if(e[n(1171)]==="uaUAo")console[n(1476)](d);else return this._qosDB?.del(_0x33b69b)}else this[n(521)](s[n(1362)],_0x58cca6),this[n(631)]&&this[n(631)](_0x55333d)}get[t(1294)](){let n=t;try{return!!this[n(678)]}catch(s){return console.log(s),!1}}}class Sp{constructor(n,s){let d=t;this._DBName=n,this._pathKey=s,this[d(678)]=localStorage}async[t(1242)](){}get _prefix(){let n=t;return n(691)+"_"+this[n(1687)]}async[t(1079)](n){let s=t,d=this[s(678)][s(1093)](this[s(1167)]);return JSON.parse(e.qyctG(d,"{}"))[n]}async[t(1716)](n,s){let d=t,u=this[d(678)][d(1093)](this[d(1167)]),h=JSON[d(1711)](u||"{}");return h[s||n[this[d(1073)]]]=n,this[d(678)][d(1578)](this._prefix,JSON.stringify(h)),s||n[this._pathKey]}async del(n){let s=t,d=this[s(678)][s(1093)](this[s(1167)]),u=JSON[s(1711)](e[s(1127)](d,"{}"));return u[n]=void 0,this[s(678)][s(1578)](this._prefix,JSON[s(748)+"y"](u))}async clear(){let n=t,s={MFdzW:function(d,u){return e[M(1454)](d,u)},oNjvR:function(d,u){return e[M(492)](d,u)},Tswdw:function(d,u){return e[M(1827)](d,u)},hsHtE:function(d,u){return e[M(1550)](d,u)},kZGaj:function(d,u){return e[M(1674)](d,u)},QQAhk:function(d,u){return e[M(392)](d,u)},HKPRx:function(d,u){return e[M(1411)](d,u)},rumQz:function(d,u){return d&u}};if(e[n(966)](e[n(1648)],n(1643)))_0xf0b07a=lZWAWS.MFdzW(_0x318728,_0x5c42b1),_0x4c3f56|=lZWAWS[n(667)](127,_0x4498b8)<<14,lZWAWS.Tswdw(128,_0x510357)&&(_0x3f6373=lZWAWS[n(1708)](_0x507ef1,_0x2b81d3),_0x4af4df|=lZWAWS[n(518)](lZWAWS.oNjvR(127,_0x79500f),21),lZWAWS.kZGaj(128,_0x56845c)&&(_0x562c0b=lZWAWS.QQAhk(_0x557abc,_0x300aea),_0x4d5e5b=127&_0x4d978e,128&_0x554330&&(_0x319f06=_0x32a415(_0x8809cd),_0x15e9ff|=lZWAWS[n(855)](lZWAWS[n(1787)](127,_0x4c71a3),7))));else return this[n(678)].clear()}async[t(1366)](){let n=t,s=this[n(678)][n(1093)](this._prefix),d=JSON[n(1711)](e[n(1127)](s,"{}"));return Object.keys(d)}async[t(1288)](){let n=t,s=this[n(678)][n(1093)](this[n(1167)]),d=JSON[n(1711)](e[n(1280)](s,"{}"));return Object[n(1299)](d)}[t(1895)](){return Promise.resolve()}get[t(1294)](){return!!this[t(678)]}}class Ip{constructor(n,s){let d=t;this[d(1687)]=n,this[d(1073)]=s,this[d(678)]=Cn?tt:$r?wx:null}async openDB(){}get[t(1167)](){return t(691)+"_"+this._DBName}async[t(1079)](n){let s=t,d={jovQf:function(u,h){return e[M(1421)](u,h)},RihtJ:function(u,h){return e[M(1045)](u,h)},ICcHU:function(u,h){return e[M(530)](u,h)},fmGZR:function(u,h){return e[M(1287)](u,h)},pcnLd:function(u,h){return u+h},lYlNR:function(u,h){return e[M(1872)](u,h)},FRxuA:function(u,h){return e[M(949)](u,h)},uixtZ:function(u,h){return e[M(1709)](u,h)},gxpEa:function(u,h){return e[M(681)](u,h)},EMIyx:function(u,h){return e[M(1479)](u,h)},nVQqb:function(u,h){return e[M(614)](u,h)},lKbzJ:function(u,h){return u&h}};if(e.kjVxT(s(1152),e[s(1243)])){let u=_0x38481e[s(1327)],h=_0x1b4c2b.high;return _0x2d0f87[_0x27182c]=d[s(1118)](h,24),_0x563883[d[s(1626)](_0x48c37d,1)]=d.ICcHU(d.fmGZR(h,16),255),_0x5420e6[d[s(1044)](_0x41042e,2)]=d[s(1103)](d[s(959)](h,8),255),_0x31d20f[d[s(815)](_0x106d81,3)]=d[s(1103)](255,h),_0x55cdb7[d[s(799)](_0x52ae10,4)]=d.gxpEa(u,24),_0x595941[_0x32dedc+5]=d[s(1103)](u>>>16,255),_0x38b741[d[s(1248)](_0x38cec2,6)]=d[s(1103)](d[s(1783)](u,8),255),_0x58644e[d[s(1626)](_0x19fe9f,7)]=d.lKbzJ(255,u),_0x2eeb1b+=8,_0x317fbe}else{let u=this[s(678)][s(1339)+s(1298)](this._prefix);return JSON[s(1711)](u||"{}")[n]}}async[t(1716)](n,s){let d=t,u=this._qosDB[d(1339)+"geSync"](this[d(1167)]),h=JSON.parse(e[d(1127)](u,"{}"));return h[s||n[this[d(1073)]]]=n,this[d(678)][d(932)+d(1298)](this._prefix,JSON[d(748)+"y"](h)),s||n[this._pathKey]}async[t(710)](n){let s=t,d={DbxcQ:function(u,h){return e[M(838)](u,h)},fMIkr:e[s(1164)],fbNSr:function(u,h){return e[s(497)](u,h)},DmpWD:function(u,h){return e[s(873)](u,h)},lPGtv:function(u,h){return u+h}};if(e[s(786)](s(956),e[s(643)])){if(d[s(996)](_0x1c3160,_0x424e19))throw new _0x9e7b0f(d.fMIkr);let u=3;for(;d.fbNSr(u,0);){let h=d[s(1855)](255,_0x381303);_0x1b7f8(h,_0x2c871d,d[s(1359)](_0x158c89,u)),_0x882f25>>>=8,u--}return _0x33c913+4}else{let u=this[s(678)][s(1339)+s(1298)](this[s(1167)]),h=JSON[s(1711)](e.rJAAE(u,"{}"));return h[n]=void 0,this[s(678)]["setStora"+s(1298)](this[s(1167)],JSON[s(748)+"y"](h))}}async[t(1561)](){let n=t;return this._qosDB[n(965)+n(1185)]()}async keys(){let n=t,s={tKYei:function(d,u){return e[M(911)](d,u)},ywtWh:e.SpJYa,wBZta:e[n(652)],nIzZE:function(d,u,h){return e[n(1353)](d,u,h)}};if(e[n(1078)](e[n(677)],e[n(677)])){let d=this[n(678)][n(1339)+n(628)+"nc"](this[n(1167)]),u=JSON[n(1711)](e[n(1773)](d,"{}"));return Object[n(1366)](u)}else return new _0x4d6dd5((d,u)=>{let h=n,g={hPbAD:function(T,A){return s.tKYei(T,A)},VvnUs:h(1565),uyxQT:s[h(795)],PYumW:s[h(534)]};this[h(904)+h(493)](),this[h(446)+h(1285)+"Id"]=s.nIzZE(_0x6b50f2,this[h(1462)][h(770)](this),this[h(1268)][h(598)+h(1606)]);let b=()=>{let T=h;d(T(421)),this[T(1822)](T(870)+"e_success",b),this[T(1822)](T(870)+T(583)+"t",m)},m=()=>{let T=h;g[T(807)](u,g[T(1842)]),this.off(g[T(1465)],b),this.off(g[T(1665)],m)};this.on(s[h(795)],b),this.on(s[h(534)],m),this[h(1462)]()})}async[t(1288)](){let n=t,s=this._qosDB[n(1339)+n(628)+"nc"](this._prefix),d=JSON.parse(e[n(1280)](s,"{}"));return Object.values(d)}[t(1895)](){let n=t;if(e[n(1099)](n(1338),n(1338)))return Promise.resolve();this[n(733)+"T"]||this[n(1853)+"X"]?this[n(320)+"etWorkCh"+n(499)]():this[n(1876)+"er"]&&this[n(1302)+n(990)+"Listener"]()}get[t(1294)](){return!!this._qosDB}}function sl(a,n){let s=t;if(e.JkQuV(Cn,Cn))return new Ip(a,n);if(e[s(1773)](Xn,Vr)&&e[s(791)](e[s(1493)],typeof indexedDB))return new vp(a,n);if((Xn||Vr)&&e[s(1004)](e.QmwAb,typeof localStorage))return new Sp(a,n);throw new Error(e[s(1880)])}class Ap{constructor(){let n=t;this[n(456)+n(1498)+"Id"]=null,this[n(456)+"l"]=36e5,this[n(678)]=e[n(964)](sl,e[n(362)],e.hQMfQ)}async[t(456)+t(396)](){let n=t;e.nOvju(clearInterval,this[n(456)+n(1498)+"Id"]),this["_interva"+n(1498)+"Id"]=e[n(1656)](setInterval,()=>{let s=n;this[s(1729)+s(788)]()},this[n(456)+"l"])}async[t(1242)](){let n=t,s={wUiZV:function(d,u,h){return e[M(1432)](d,u,h)},EypQN:e[n(1559)],wLYGC:e[n(1442)]};await this._qosDB[n(1242)]()[n(1344)](()=>{let d=n;if(e[d(1215)](e[d(929)],e.BHIeu)){let u=s[d(940)](_0x408e41,s[d(887)],{message:s[d(645)]});this[d(802)+"econnect"]&&this["onStartR"+d(704)](u)}else this[d(456)+d(396)]()})}async[t(1729)+t(788)](){let n=t;(await this._qosDB?.getAll()||[])[n(680)](({timestamp:u})=>u<Date[n(1597)]())[n(1121)](u=>{let h=n;this[h(678)]?.[h(710)](u[h(992)+"id"])})}async[t(710)](n){let s=t,d={UBrvW:function(u,h,g,b){return e.CRZIR(u,h,g,b)}};if(e[s(705)](e[s(586)],e[s(1596)])){let u=new _0x51c77a(_0x1e79b6(_0xbf0984));return iCpsmX[s(431)](_0x10a9ba,_0x1fa4cc,u,0),u}else return this[s(678)]?.[s(710)](n)}async[t(1716)](n,s){let d=t;if(e[d(316)](e[d(1739)],e[d(1904)]))e[d(1908)](_0x11213b,_0x3ebe46,58),e.htDAn(_0x3e57d4,_0x1bb622,_0x10a972);else return this[d(678)]?.[d(1716)]({message_id:n,timestamp:s})}async[t(1079)](n){let s=t;if(e[s(1215)](s(1686),e.vkJVW))this[s(913)+"rs"]={};else return this._qosDB?.[s(1079)](n)}async[t(1895)](){let n=t,s={WVgGd:function(d,u,h){return e[M(418)](d,u,h)},aXvdp:e[n(1297)]};if(e.exTIV(e[n(1057)],n(515))){let d=this[n(1196)+n(828)]?.[n(1750)+n(549)+"nt"]();this[n(1160)+n(1546)+"ent"](s[n(1245)](_0xe10618,s[n(1367)],{code:1006,reason:n(693)+d+(n(1569)+n(461)+n(794)+n(1374)),wasClean:!0}))}else e[n(664)](clearInterval,this["_interva"+n(1498)+"Id"]),await this._qosDB?.closeDB()}get[t(1294)](){return this[t(678)]?.isReady}}function ua(a){let n=t,s=!!this._options.enableQoS;if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let d=e[n(487)](nn,a[n(558)][n(1225)],e[n(635)],"2"),u=d&&e[n(934)](nn,a.message.headers,e[n(620)],"1"),h=d&&e[n(504)](nn,a[n(558)][n(1225)],n(1659)+n(977)+"k","1"),g=h?Qn(a[n(558)][n(1225)],e[n(1718)])?.[n(1419)](",")[n(680)](Boolean)||[]:[];return{enabled:s,isQoSMessage:d,isQoSAck:u,isAckCleanupMessage:h,ackMsgIds:g}}async function ol(){let a=t;return this[a(1460)+a(1191)]||(this._QoSManager=new Ap),this[a(1460)+"ger"][a(1294)]||await this[a(1460)+"ger"].openDB(),this[a(1460)+a(1191)]}async function Cp(a,n){let s=t,{enableAutoAck:d}=this[s(1268)],u=e[s(1126)](nn,a[s(558)][s(1225)],s(353),"1"),h=nn(a[s(558)][s(1225)],e[s(1732)],"1"),g=ua[s(765)](this,a);if(e[s(1800)](d,u)){let{SeqID:b,LogID:m,service:T,LogIDNew:A,method:P}=a[s(558)];this[s(1396)]({SeqID:b,LogID:m,LogIDNew:A,service:T,method:P,headers:[{key:s(817),value:"1"},{key:s(332),value:A||""},{key:e.nUVwk,value:"0"}]})}h&&!g[s(1318)]&&this[s(1160)+s(1553)+s(662)](a),n()}async function Tp(a,n){let s=t;this[s(812)](e[s(447)],a.message),n()}async function kp(a,n){let s=t,d=e[s(1331)](Qt,await e[s(1331)](il,a.data));try{if(e.TkCad(d[s(1705)],Uint8Array)){let u=e[s(1549)](this[s(1268)]["payloadE"+s(1418)],Object)?{force:!!this[s(1268)][s(1281)+s(1418)].force,encoding:this._options[s(1281)+"ncoding"][s(1443)]?this[s(1268)][s(1281)+s(1418)][s(1443)][s(1818)](/\s/g,"")[s(723)+s(742)]():""}:{force:!1,encoding:this[s(1268)].payloadEncoding?this[s(1268)][s(1281)+s(1418)][s(1818)](/\s/g,"")[s(723)+"ase"]():""},h=d[s(1281)+"ncoding"]?d["payloadE"+s(1418)][s(1818)](/\s/g,"")[s(723)+s(742)]():"",g=e[s(1379)](this[s(1268)][s(668)+s(471)],Object)?{force:!!this[s(1268)][s(668)+s(471)][s(1866)],type:this[s(1268)][s(668)+s(471)][s(1186)]?this[s(1268)][s(668)+s(471)][s(1186)][s(1818)](/\s/g,"")[s(723)+s(742)]():""}:{force:!1,type:this[s(1268)][s(668)+s(471)]?this[s(1268)][s(668)+"ype"][s(1818)](/\s/g,"")[s(723)+"ase"]():""},b=d[s(668)+s(471)]?d[s(668)+s(471)].replace(/\s/g,"").toLowerCase():"",m=g[s(1866)]?g[s(1186)]:b||g[s(1186)],T=u.force?u[s(1443)]:h||u[s(1443)],A=[e[s(851)],e[s(663)],"applicat"+s(820)+s(422)+s(1258),s(1441)],P=["none_none",e[s(1483)]];this[s(1268)][s(1364)+s(554)+"extPayload"]&&A.includes(m)&&(!T||P[s(972)](T))?d[s(634)+s(1886)]=e.fBhrI(rl,d[s(1705)],0,d[s(1705)][s(1228)+"th"]):d["textPayl"+s(1886)]=""}else d.textPayload=""}catch(u){d[s(634)+s(1886)]="",console.log(u)}a[s(558)]=d,e[s(1234)](n)}function Rp(a,n,s){let d=t,u={cmxHP:function(T,A){return e.katlF(T,A)},FjHHM:function(T,A){return e[M(998)](T,A)},BRlDY:function(T,A){return T>A},WjgOy:function(T,A){return e.djycV(T,A)},QnQXQ:function(T,A){return e[M(1205)](T,A)},CrVoB:function(T,A){return e[M(1046)](T,A)}},h=s||8192,g=e[d(610)](h,1),b=null,m=h;return function(T){let A=d;if(u[A(1850)](T,1)||T>g)return u.FjHHM(a,T);u[A(1104)](u.WjgOy(m,T),h)&&(b=a(h),m=0);let P=n[A(765)](b,m,m+=T);return u[A(1670)](7,m)&&(m=u[A(371)](u.CrVoB(7,m),1)),P}}let Dp=4294967295;function Pp(a,n,s){let d=t;return e[d(605)](RangeError,e.SIhFu(e[d(1907)](e[d(1006)](e.HNGtJ(e[d(450)](e.KeceK,a),d(1807)),e[d(1773)](n,1)),e[d(1698)]),s))}function Op(a,n,s){let d=t,u={PfecG:function(g,b){return g+b}};if(s>Dp)throw new Error(d(1641)+"too large");let h=3;for(;e[d(1370)](h,0);)if(e[d(866)](e.kArDR,d(884))){let g=e[d(1137)](255,s);e.YTqqa(xa,g,a,e[d(450)](n,h)),s>>>=8,h--}else _0x338cac[_0x27a1e4[_0x78bf77][d(1660)+d(1539)]]=_0x1b7142(_0x475c77[_0x3ffdd7][d(1660)+d(1539)]),_0x2dfa93+=u.PfecG(14,_0x4ef678[_0x2d2d47[_0x3cff82][d(1660)+d(1539)]]);return e[d(1849)](n,4)}function Lp(a,n){let s=t,d=0,u=n,h=n+4;for(;u<h;){let{value:g,offset:b}=e.RTNlL(fa,a,u);u=b,d=e[s(1557)](d<<8,0),d+=g}return{value:d,offset:h}}function Np(a,n,s){let d=t,u={RhOXa:function(h,g){return e[M(1525)](h,g)},MBIad:function(h,g){return e[M(692)](h,g)},gWiiI:function(h,g){return e[M(1205)](h,g)},GZOVV:function(h,g){return h<<g},kBrnp:function(h,g){return e[M(445)](h,g)},ecXkP:function(h,g){return h&g},RwPvv:function(h,g){return e[M(416)](h,g)},iqNNa:function(h,g,b){return e[M(1432)](h,g,b)},dUVUH:function(h,g){return e[M(399)](h,g)},cIWoW:function(h,g){return e.GNidQ(h,g)}};if(e[d(1707)](e[d(1616)],e[d(1265)]))return a?e.AyPrp(a[d(519)],40)?e[d(629)](da(a,n,s),s):n[d(1386)+"e"]?e.LpqIK(n[d(1386)+"e"](a,s),s):n[d(602)]?e[d(506)](n[d(602)](a,s),s):da(a,n,s)+s:s;_0x2a841a=KgVmxm.RhOXa(KgVmxm.MBIad(KgVmxm.gWiiI(7,_0x5d57e1)<<18,KgVmxm[d(758)](KgVmxm[d(1527)](63,_0x386e89),12)),KgVmxm[d(758)](KgVmxm[d(1427)](63,_0x667fe0),6))|KgVmxm[d(1427)](63,_0xea23ff),KgVmxm[d(1055)](_0x1e7645,65536)||_0x3b1610>1114111?_0x42787b+=_0x275536:(_0x1d776b-=65536,_0x526556+=KgVmxm.iqNNa(_0x2bcd5d,KgVmxm[d(1321)](_0x53c196,10)+55296,KgVmxm[d(941)](1023&_0x3bceb4,56320)),_0x49c1dd+=3)}function Mp(a,n){let s=t,d=new fe(e.mUuYt(e.dYAUt(e.TfCmT(e[s(1398)](a[n+4],24),a[e.diZwy(n,5)]<<16),e[s(1595)](a[e[s(1045)](n,6)],8)),a[e[s(1439)](n,7)]),e[s(1269)](e[s(637)](a[e[s(1538)](n,0)],24)|e[s(881)](a[e.QNgXr(n,1)],16)|e[s(426)](a[e[s(363)](n,2)],8),a[n+3]),!0);return n+=8,{value:d,offset:e.BftCu(n,8)}}function Bp(a,n,s){let d=t,u=a[d(1327)],h=a.high;return n[s]=e[d(1119)](h,24),n[e[d(865)](s,1)]=e.mldOh(e[d(1326)](h,16),255),n[e.QHkxq(s,2)]=e[d(1715)](e[d(1017)](h,8),255),n[e[d(1745)](s,3)]=255&h,n[e[d(629)](s,4)]=e[d(436)](u,24),n[s+5]=e[d(530)](e.jnGGW(u,16),255),n[s+6]=e[d(1464)](e[d(434)](u,8),255),n[e.fOPuy(s,7)]=e[d(1608)](255,u),s+=8,s}function fa(a,n){let s=t;return a.readUInt8?{value:a[s(1828)+"8"](n),offset:n+1}:{value:e[s(908)](255,a[n]),offset:e[s(1295)](n,1)}}function xa(a,n,s){let d=t;if(e[d(459)](e.HTJEs,"NrmGA"))return n.writeUint8?n[d(1019)+"t8"](a,s):n[s]=e[d(603)](255,a),s+1;e[d(1824)](_0x21693a,_0x1f4124,16),e.OJoIh(_0x2a0a1e,_0x2dccc6,_0x14d80b)}let zp=function(a){return new Uint8Array(a)},Fp=e.QmwAb!=typeof Buffer?Buffer[t(1211)+t(1636)]:e[t(1908)](Rp,zp,Uint8Array[t(319)+"e"][t(391)]);(()=>{let a=t,n={UdMHo:e[a(724)],gOtoD:function(d,u){return e[a(1397)](d,u)},ERKTE:function(d,u){return d<<u},sKsrB:function(d,u){return e[a(1841)](d,u)},vScFq:function(d,u){return d|u},IuTtx:function(d,u){return e[a(1571)](d,u)},QsLUG:function(d,u){return e[a(1672)](d,u)},DigDv:function(d,u,h,g){return d(u,h,g)},rDUvr:function(d,u){return e[a(741)](d,u)},HnodO:function(d,u){return e[a(1841)](d,u)},AtMJq:function(d,u){return d>>>u},XJLie:function(d,u){return e.NyZaj(d,u)},MsqOT:function(d,u){return e[a(449)](d,u)},yeKBh:function(d,u){return e.otcYT(d,u)}},s=4294967295;return function(d,u,h=!0){let g=a,b=n.UdMHo[g(1419)]("|"),m=0;for(;;){switch(b[m++]){case"0":s=n[g(1523)](s|n[g(357)](n.sKsrB(127,d[u]),7),0);continue;case"1":if(d[u++]<128)return{value:h?s:n[g(498)](0,s),offset:u};continue;case"2":s=n[g(398)](s|n[g(357)](n[g(1480)](127,d[u]),21),0);continue;case"3":return{value:h?s:n[g(498)](0,s),offset:u};case"4":if(n[g(877)](d[u++],128))return{value:h?s:0|s,offset:u};continue;case"5":if((u+=5)>d[g(519)])throw u=d[g(519)],n[g(327)](Pp,u,10,d[g(519)]);continue;case"6":s=n[g(1523)](s|n[g(1181)](n.HnodO(15,d[u]),28),0);continue;case"7":if(d[u++]<128)return{value:h?s:n[g(498)](0,s),offset:u};continue;case"8":s=n[g(469)](n.XJLie(s,n[g(531)](127,d[u])<<14),0);continue;case"9":s=n[g(1523)](n.yeKBh(127,d[u]),0);continue;case"10":if(n[g(877)](d[u++],128))return{value:h?s:n[g(498)](0,s),offset:u};continue;case"11":if(n[g(877)](d[u++],128))return{value:h?s:n[g(498)](0,s),offset:u};continue}break}}})();let Up=16,ha=32;function Gp(a){let n=t,s=0,d={};for(let u=0;e.plhgy(u,a[n(519)]);u++)d[a[u]["cursor_n"+n(1539)]]=nl(a[u][n(1660)+n(1539)]),s+=e[n(538)](14,d[a[u]["cursor_n"+n(1539)]]);return[s,d]}function al(a,n,s){let d=t,[u,h]=e[d(785)](Gp,a),g=e[d(1261)](Fp,u),b=0;return a.forEach(m=>{let T=d,A=e.oAPIF[T(1419)]("|"),P=0;for(;;){switch(A[P++]){case"0":b=e[T(593)](xa,0,g,b);continue;case"1":console.log(e[T(1406)],b);continue;case"2":console.log(e[T(478)],m,m[T(1520)]);continue;case"3":b=Bp(fe[T(1145)+"er"](m[T(669)]||n),g,b);continue;case"4":console[T(1476)](e[T(944)],b);continue;case"5":console.log(e[T(516)],b);continue;case"6":b=e[T(919)](xa,h[m["cursor_n"+T(1539)]],g,b);continue;case"7":console[T(1476)](T(892),b);continue;case"8":console.log("curvalue",b);continue;case"9":b=e[T(593)](Np,m[T(1660)+T(1539)],g,b);continue;case"10":b=Op(g,b,m[T(1520)]||0);continue}break}}),{frameType:ha,headers:[{key:e.livxo,value:s}],payload:g}}function qp(a){let n=t;if(e.OCaup!==n(400))return n(691)+"_"+this._DBName;{let s=0,d=[];for(;e[n(715)](s,a[n(1228)+"th"]);){let{offset:u}=e[n(1738)](fa,a,s);s=u;let h={cursor_name:"",cursor:0,service:0},{value:g,offset:b}=e[n(1432)](Lp,a,s);h[n(1520)]=g,s=b;let{value:m,offset:T}=fa(a,s);s=T,h[n(1660)+"ame"]=rl(a,s,e[n(640)](s,m)),s+=m;let{value:A,offset:P}=Mp(a,s);h[n(669)]=A[n(1155)](),s=P,d[n(1774)](h)}return d}}function jp(){let a=t;return{frameType:ha,headers:[{key:e[a(1075)],value:e[a(440)]}],payload:void 0}}class Hp{constructor(n,s,d){let u=t;this[u(522)+"ameSpace"]=n,this[u(1172)+u(552)]=s,this[u(698)+u(948)]=d,this[u(678)]=e[u(419)](sl,this[u(522)+"ameSpace"],e.vFuQk)}async[t(1242)](){let n=t,s={dkJzD:e[n(1820)]};if(e.RejZz===e.JViub){if(!this._connectLock){let d=s.dkJzD[n(1419)]("|"),u=0;for(;;){switch(d[u++]){case"0":this[n(907)+n(1829)]=!1;continue;case"1":this._connect();continue;case"2":this["_pingLos"+n(858)]?.[n(1290)+"nter"]();continue;case"3":this._isInit=!0;continue;case"4":this[n(1196)+n(828)]?.["resetEnd"+n(1340)+n(1113)]();continue}break}}}else await this[n(678)][n(1242)]()}async[t(1706)+"rs"](){let n=t;if(!this[n(678)][n(1294)])return;let s=this[n(698)+n(948)],d=await this[n(678)][n(1288)]();switch(console[n(1476)](e[n(413)],d),s){case n(1187):return d&&d[n(519)]?e.CRZIR(al,d,0,this[n(1172)+n(552)]):void 0;case"INSTANT":return;case n(1163):return d&&d[n(519)]?e.fBhrI(al,d,0,this[n(1172)+n(552)]):e.dbXFB(jp)}}async[t(1716)](n,s,d){let u=t;if(e[u(1751)]("odNur","pJwXz"))return console.log(e.HYGgu,n,s,d),this[u(678)][u(1716)]({cursor_name:n,cursor:s,service:d});{let h={cAYYt:function(b,m){return b(m)},juZVq:e[u(1645)]},g=_0x1d5d07["createEl"+u(809)](e[u(382)]);_0xaa718f[u(691)+u(1047)]=b=>{let m=u;_0x2568ad[m(1797)][m(1714)+m(1808)](g),_0x1ef2f5[m(691)+"JSONP"]=void 0,h[m(1081)](_0x30f2a7,b&&b[m(671)]||h[m(905)])},g.type=e[u(1838)],g.src=e[u(759)](_0x1b878b[u(1818)](/^ws/,e[u(886)]),e[u(601)]);try{_0x27d393[u(1797)][u(1204)+"ild"](g)}catch{_0x19c389.body["removeCh"+u(1808)](g)}}}async[t(1051)+"rs"](n){let s=t,d={FrkYU:function(h,g){return e.rSPIM(h,g)},mWAvL:function(h,g){return e[M(1377)](h,g)},pTocw:function(h,g){return e[M(637)](h,g)},RfuCz:function(h,g){return h|g},fItvm:function(h,g){return e[M(1365)](h,g)}},u=e[s(1153)](qp,n);for(let h of u)if(e[s(570)]!==e.czqrN)console[s(1476)](e[s(1901)],u),await this[s(678)][s(1716)](h);else return new _0x41a792(syuqpW[s(460)](syuqpW.mWAvL(_0xb9a4e7[0],_0x1a2583[1]<<8),syuqpW[s(542)](_0x3e3e17[2],16))|syuqpW[s(542)](_0x247a41[3],24),syuqpW[s(460)](syuqpW[s(1638)](syuqpW[s(311)](_0x6e1117[4],syuqpW.pTocw(_0x349675[5],8)),syuqpW[s(670)](_0x298ec2[6],16)),syuqpW[s(542)](_0x44f458[7],24)),_0x4492ff)}async[t(1079)](n){let s=t;return(await this[s(678)].get(n))?.[s(669)]}async[t(1895)](){let n=t;await this[n(678)][n(1895)]()}["updateCu"+t(1088)+t(1401)](n){let s=t;this[s(1172)+s(552)]=n}get[t(1294)](){let n=t;return this._qosDB[n(1294)]}}let Wp=e.Taprp;async function cl(a){let n=t,s={dtVNd:function(b,m){return b<m},THKFe:function(b,m){return e[M(1106)](b,m)},BEYbT:function(b,m){return e[M(995)](b,m)},VWlgx:function(b,m){return e[M(533)](b,m)},CJVxc:function(b,m){return e[M(759)](b,m)},TZBlS:function(b,m){return b|m},zDWag:function(b,m){return b||m}};if(!this[n(1268)][n(370)+"S"])return null;let{aID:d,fpID:u,messageStrategy:h}=this[n(1268)],g=e[n(502)](a,Wp);try{if(this[n(953)+n(922)])if(e[n(1095)](e.LtTaX,n(545)))a&&this["_cursorM"+n(922)][n(544)+n(1088)+n(1401)](a);else{let b=ImkWkv[n(1650)](_0x2d2822,8192),m=b>>>1,T=null,A=b;return function(P){let U=n;if(ImkWkv[U(1198)](P,1)||ImkWkv.THKFe(P,m))return ImkWkv.BEYbT(_0x4c8753,P);A+P>b&&(T=_0x56213f(b),A=0);let H=_0x2ad69b[U(765)](T,A,A+=P);return ImkWkv[U(923)](7,A)&&(A=ImkWkv.CJVxc(ImkWkv[U(903)](7,A),1)),H}}else this["_cursorM"+n(922)]=new Hp(u+"_"+d+"_"+g,g,h);return this[n(953)+n(922)][n(1294)]||await this[n(953)+n(922)][n(1242)](),this[n(953)+n(922)]}catch{return e.NHgRD===e[n(323)]?null:this[n(1834)]?this[n(1834)][n(433)]:""}}async function Kp(a,n){let s=t,d=e[s(593)](nn,a[s(558)][s(1225)],e.ojmGm,"-1"),u=nn(a.message[s(1225)],e[s(1732)],"1"),h=Qn(a[s(558)][s(1225)],e.CjsvA),g=e.gmAew(Number,e[s(590)](Qn,a[s(558)][s(1225)],e.gGEZN))||0,b=ua[s(765)](this,a),m=nn(a.message[s(1225)],e.mLiYP,"2"),T=Qn(a.message[s(1225)],s(1025)+s(1005)+"e"),A=Number(e[s(354)](Qn,a[s(558)][s(1225)],e[s(1190)]));if(b[s(1318)])return e.tCNYZ(n);let P=b[s(849)+s(1564)]?await ol[s(765)](this):null;if(e[s(1843)](a.message[s(1520)],0)&&u&&!d||e[s(862)](a[s(558)].service,0)){if(h&&b.isQoSMessage&&P)return!!!await P.get(h)&&(this[s(1160)+s(1524)+s(1038)](a),await P[s(1716)](h,e[s(1771)](Date[s(1597)](),g))),e[s(411)](n);if(m){let U=await cl[s(765)](this);if(!U)return this["_dispatc"+s(1524)+s(1038)](a),e.PmcYz(n);let H=await U[s(1079)](T)??-1;if(H<A)this[s(1160)+"hMessageEvent"](a),U[s(1716)](T,A,a[s(558)][s(1520)]);else throw new Error(s(1226)+s(1141)+s(342)+A+(s(900)+s(330)+s(1507)+"r ")+H);return n()}return this[s(1160)+s(1524)+s(1038)](a),n()}}async function $p(a,n){let s=t,d=ua[s(765)](this,a);if(!d[s(849)+"sage"])return n();let u=await ol.call(this);if(d["isAckCle"+s(835)+s(1599)]&&d[s(435)+"s"].length)for(let h of d[s(435)+"s"])await u[s(710)](h);e[s(1234)](n)}async function Vp(a,n){let s=t,d={bSDPp:function(u){return e.moyiL(u)},ZtGBr:function(u,h){return u(h)}};if(e[s(1384)](e[s(1898)],s(1627))){let u=QMKHtc[s(1854)](_0x32591d);return _0x5b0441(_0x5c5f4c,u),QMKHtc[s(1881)](_0x3533e6,u)}else{let u=e[s(917)](a[s(558)][s(1224)+"e"],Up),h=e[s(491)](a[s(558)][s(1224)+"e"],ha);if(!u&&!h)return e.WJBvq(n);let g=Qn(a.message[s(1225)],e[s(1075)]);if(!g)return e[s(411)](n);let b=await cl[s(765)](this,g);if(!b)return e[s(832)](n);if(u){let m=await b.getCursors(),T={frameType:m?.[s(1224)+"e"],SeqID:fe.fromNumber(this._seqId++),LogID:fe.fromNumber(this._options[s(927)+s(1053)]()),service:9e3,method:5,headers:m?.[s(1225)],payload:m?.payload},A=S(T);this._ws&&this[s(1834)].readyState&&this[s(1834)][s(1422)](A)}if(h){let m=a[s(558)][s(1705)];m&&b[s(1051)+"rs"](m)}}}let Jp=async function(a,n){let s=t,d={qUPYj:function(u,h){return e[M(1231)](u,h)},WjXOM:function(u,h){return e[M(536)](u,h)}};if(s(573)===e[s(1412)]){let u=_0x538e7c[_0x45bc09];if(SpgkpU[s(1589)](4,_0x4fabde[_0x2f136f][s(519)])){let h=_0xad4e2[s(1356)+"g"](0,SpgkpU[s(1878)](4,_0x219460[_0x4e36f1].length)),g=h[s(1481)](u);_0x52de10=_0x53a167[s(1481)](g)}else _0x32db82=_0x1497a9[s(1481)](u)}else this._isInit=!1,e[s(1454)](clearTimeout,this["_connect"+s(572)+s(1105)]),e.tCNYZ(n)},Yp=async function(a,n){let s=t;if(!this[s(1834)]||e[s(1533)](this[s(1834)][s(1371)+"te"],this.OPEN))return e.tCNYZ(n);let{pingInterval:d}=this[s(1268)];this[s(1196)+s(828)]?.[s(1893)+s(1340)+s(1113)]();for(let h=0;e[s(1409)](h,this[s(698)+s(313)].length);h++){let g=this[s(698)+"Queue"][h];if(e[s(1175)](this[s(1834)][s(1371)+"te"],this[s(1080)])&&e.pDGRf(null,g))this[s(1834)]&&this[s(1834)][s(1422)](g),this[s(698)+s(313)][h]=null;else break}this[s(698)+s(313)]=this[s(698)+"Queue"][s(680)](h=>!!h),this[s(446)+s(1285)+"Id"]=e[s(1819)](setTimeout,()=>this[s(1462)](),d),this[s(1160)+s(1240)+"nt"](a),this[s(1876)+"er"]&&this[s(1834)]&&(this[s(1834)].binaryType=this._binaryType);let u=this[s(1196)+"tManager"]?.["getCurre"+s(549)+"nt"]();this[s(812)](s(1888)+u+s(597)),e[s(604)](n)},Zp=async function(a,n){let s=t,d=this["_endpoin"+s(828)]?.[s(1750)+s(549)+"nt"]();this[s(812)]("open "+d),e[s(840)](n)};class Xp extends ca{constructor(n){let s=t,d={kXKZq:function(b,m){return e[M(633)](b,m)},cxlmd:e[s(1393)],kTtHC:e[s(1689)],pReWR:e[s(1506)],JZhGB:e.OpEfN,VWrOR:function(b,m,T){return b(m,T)},KJeeM:function(b,m,T,A){return e[s(504)](b,m,T,A)}};super(),this[s(1335)+s(1247)+s(1813)]=!0,this[s(1876)+"er"]=Xn,this[s(1085)]=hp,this._isMiniTT=Cn,this._isMiniWX=$r,this[s(1502)+"r"]=Vr,this[s(698)+s(313)]=[],this[s(1196)+s(828)]=null,this[s(907)+s(1829)]=!1,this[s(985)+"ype"]="arraybuf"+s(753),this[s(390)+"Lock"]=!1,this["_connect"+s(572)+"utId"]=null,this[s(1749)+"ctTimeou"+s(1758)]=null,this[s(446)+s(1285)+"Id"]=null,this._seqId=0,this[s(999)]=!1,this._url="",this[s(1460)+s(1191)]=null,this._cursorManager=null,this[s(1492)+s(858)]=null,this._protocols=e[s(1754)],this.CLOSED=3,this.CONNECTING=0,this[s(1080)]=1,this[s(1170)]=2,this[s(312)]=b=>{let m=s;try{if(e.eIDrb(e[m(980)],e[m(980)]))e[m(1657)](tl,this,b,[Jp,Yp,Zp]);else return this._qosDB["clearSto"+m(1185)]()}catch(T){let A=e[m(1332)](at,m(1757),{message:T[m(558)],code:tn.OPEN_ERROR,error:T});this[m(1160)+m(1161)+m(349)](A)}},this[s(714)+"ge"]=async b=>{let m=s,{pingInterval:T,pingFrequency:A}=this[m(1268)];if((d[m(993)]("hi",b[m(397)])&&d[m(993)](d[m(1457)],A)||d[m(1307)]===A)&&(this["_clearPi"+m(493)](),this[m(521)](d[m(901)],d[m(539)]),this[m(446)+m(1285)+"Id"]=d[m(775)](setTimeout,this[m(1462)][m(770)](this),T)),!d[m(993)]("hi",b[m(397)]))try{d.KJeeM(tl,this,b,[kp,Cp,$p,Vp,Kp,Tp])}catch(P){let U=d.VWrOR(at,"error",{message:P.message,code:tn[m(1434)+m(1061)],error:P});this[m(1160)+"hErrorEv"+m(349)](U)}},this[s(1410)]=b=>{let m=s,T=this[m(1196)+m(828)]?.[m(1253)+m(1573)+"es"](),A=this[m(1196)+"tManager"]?.["getCurre"+m(549)+"nt"]();if(T&&!b[m(558)]){let P=m(693)+A+(" fail, m"+m(1622)+"es reached");this[m(1160)+"hErrorEvent"](at(m(1757),{message:P,code:tn[m(789)+m(1508)+"R"],error:b}));return}this[m(1834)]&&this[m(1834)][m(1371)+"te"]===this[m(1080)]&&this["_disconn"+m(328)](),this[m(1160)+m(1161)+m(349)](e[m(590)](at,e.NRIPJ,{message:b[m(558)],code:tn[m(1900)+m(1699)],error:b}))},this._onClose=async b=>{let m=s;this[m(1259)+m(769)](),this[m(904)+m(493)](),this["_removeW"+m(470)+"rs"](),this[m(1834)]=null,this[m(390)+m(1475)]=!1;let T=this["_endpoin"+m(828)]?.[m(1253)+"chMaxTries"]();if(!T&&this[m(495)+m(1619)]()&&!this[m(907)+m(1829)]){let A=this[m(1196)+m(828)]?.[m(1750)+m(549)+"nt"](),P=this._options[m(1470)+m(1889)+m(672)](b[m(716)],b[m(1096)]);this["_dispatc"+m(1546)+m(349)](e[m(1724)](xt,e[m(1297)],{code:1006,reason:b.reason||"connecti"+m(1586)+m(350)+m(488)+m(1777)+m(563)+A,willReconnect:P})),P&&this[m(390)]();return}if(b[m(716)]!==1e3&&this[m(907)+m(1829)]){this[m(1160)+m(1546)+"ent"](e[m(974)](xt,e[m(1297)],{code:1e3,reason:e[m(559)]})),this[m(1196)+"tManager"]?.[m(1893)+m(1340)+"fig"](),this[m(1492)+"sCounter"]?.[m(1290)+m(914)]();return}if(e[m(546)](1e3,b.code)&&T){let A=this[m(1196)+m(828)]?.[m(1750)+"ntEndpoint"](),P=b[m(1096)];P||(P=await Ep(this[m(957)])),P="connecti"+m(1586)+m(1840)+P+(m(616)+"me: ")+A+(m(461)+m(794)+m(1374)),this[m(1160)+m(1546)+m(349)](xt("close",{code:b[m(716)],reason:P}));let U="connect "+A+(" fail, max retri"+m(1905)+"ed");this["_dispatc"+m(1161)+m(349)](at(e[m(1303)],{message:U,code:tn[m(789)+m(1508)+"R"]})),this[m(1196)+m(828)]?.["resetEndpointCon"+m(1113)](),this[m(1492)+m(858)]?.[m(1290)+m(914)]();return}if(e[m(1533)](1e3,b.code)&&!b[m(1096)]){let A=this["_endpoin"+m(828)]?.[m(1750)+m(549)+"nt"]();this[m(1160)+m(1546)+m(349)](e[m(642)](xt,m(1033),{code:b[m(716)],reason:m(1402)+"ng faile"+m(350)+m(488)+m(1777)+m(563)+A})),this[m(1196)+m(828)]?.["resetEnd"+m(1340)+m(1113)](),this[m(1492)+m(858)]?.[m(1290)+"nter"]();return}this[m(1160)+"hCloseEv"+m(349)](b),this[m(1196)+"tManager"]?.["resetEnd"+m(1340)+m(1113)](),this[m(1492)+m(858)]?.["resetCou"+m(914)]()},this[s(1304)]=null,this.onerror=null,this[s(688)+"e"]=null,this.onopen=null,this["onStartR"+s(704)]=null,this[s(1517)+s(1263)]=null,this[s(1505)+s(660)+s(1879)+"ct"]=null,this[s(1036)+s(490)]=this[s(1036)+s(490)][s(770)](this),this["_handleO"+s(933)]=this[s(1036)+s(933)].bind(this),this[s(367)+s(653)]=this[s(367)+s(653)][s(770)](this),this[s(367)+s(339)]=this[s(367)+"ageShow"][s(770)](this),this[s(1268)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength: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(1689)],pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(1213)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:u,ws:h}=n,g=Array[s(1742)](u)?u:e[s(1581)](e[s(1870)],typeof u)?[u]:[];if(!g||e[s(393)](0,g[s(519)]))throw new Error(s(315)+s(1468)+"alid url");if(!e[s(1735)](mp,h))throw new Error(e[s(1560)]);Object[s(1050)](this[s(1268)],n),this[s(1196)+s(828)]=new el(g,this[s(1268)][s(511)+"es"]),this[s(1492)+s(858)]=new yp(this[s(1268)][s(1795)+s(561)]),this[s(1268)][s(787)+"cOpen"]&&(this[s(999)]=!0,this[s(390)]()),this[s(1268)][s(1763)+s(1461)+s(829)]&&(this[s(733)+"T"]||this[s(1853)+"X"]?this[s(320)+"etWorkCh"+s(499)]():this[s(1876)+"er"]&&this["_initGlo"+s(990)+s(1583)]())}[t(1036)+t(490)](){let n=t;this[n(1268)][n(407)+n(417)+n(1133)]||this._readyClosed||this[n(780)+n(704)]()}_handleOffLine(){let n=t;this[n(879)+n(1313)+"t"]();let s=e[n(1704)](aa,e.ceLzt,{message:n(1249)+"ediately"+n(1823)+"ct"});this[n(1505)+"mediatel"+n(1879)+"ct"]&&this[n(1505)+n(660)+"yReconnect"](s)}[t(1302)+t(990)+t(1583)](){let n=t;this._isBrowser&&window[n(1617)+n(1583)](e.qsgGo,this[n(1036)+"nLine"]),this[n(1876)+"er"]&&window["addEvent"+n(1583)](e[n(1337)],this[n(1036)+n(933)]),this._isBrowser&&window["addEvent"+n(1583)](e.kudKQ,this[n(367)+n(653)]),this[n(1876)+"er"]&&window[n(1617)+n(1583)](n(526),this[n(367)+n(339)])}[t(1605)+"balEvent"+t(1583)](){let n=t;this[n(1876)+"er"]&&window[n(1360)+n(386)+n(895)](e[n(1363)],this["_handleO"+n(490)]),this[n(1876)+"er"]&&window[n(1360)+n(386)+n(895)](e[n(1337)],this[n(1036)+n(933)]),this[n(1876)+"er"]&&window["removeEv"+n(386)+n(895)](e[n(474)],this[n(367)+n(653)]),this[n(1876)+"er"]&&window["removeEv"+n(386)+n(895)](e[n(1266)],this[n(367)+"ageShow"])}[t(367)+"ageHide"](n){let s=t;!n[s(356)+"d"]&&(this._isBrowser&&window[s(1360)+s(386)+s(895)](e.kudKQ,this["_handleP"+s(653)]),this._isBrowser&&window[s(1360)+"entListener"](e[s(1266)],this[s(367)+s(339)]),this[s(1033)]()),this[s(1876)+"er"]&&window["removeEventListe"+s(895)](e[s(1363)],this[s(1036)+"nLine"]),this[s(1876)+"er"]&&window[s(1360)+s(386)+s(895)](e[s(1337)],this._handleOffLine)}_handlePageShow(n){let s=t;n[s(356)+"d"]&&(this[s(495)+s(1619)]()&&(!this[s(1834)]||this[s(1834)][s(1371)+"te"]!==this[s(1080)]||e.NcwIX(this._ws[s(1371)+"te"],this.CONNECTING))&&this[s(1036)+s(490)](),this[s(1876)+"er"]&&window["addEvent"+s(1583)](s(1052),this[s(1036)+s(490)]),this._isBrowser&&window["addEvent"+s(1583)](e.ZEzbc,this._handleOffLine))}async[t(1361)+t(872)](n){let s=t,{fpID:d,deviceID:u,bddID:h,ttwID:g,accessKey:b,aID:m,customParams:T={},enableAutoAck:A,enableQoS:P,QoSLevel:U,env:H}=this[s(1268)],Y,qe,je;this[s(1876)+"er"]||this[s(1853)+"X"]||this[s(733)+"T"]?e[s(654)](e[s(467)],e[s(467)])?(Y=location&&e[s(1414)](s(437),location.protocol)?e[s(591)]:e[s(889)],qe=n[s(1818)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),je=/^wss(.*:\/\/)/[s(1799)](n)?n:""+Y+qe):(_0x42dd7a+=e[s(1146)](_0x502692,_0x169aa3),_0xe99ddc+=2):(Y=e[s(591)],qe=n.replace(/(^http)((?:[s]*:\/\/))/,""),je=/(^ws)((?:[s]*:\/\/))/[s(1799)](qe)?qe:""+Y+qe);let zt=h?s(731):g?e[s(986)]:e[s(760)],dl=h||g||u;if(!dl||!zt)throw new Error(s(315)+s(1812)+s(1482)+s(1201)+"r ttwID");let Qp=e[s(547)](s(465),typeof T)?await e[s(1743)](T):T,eg=H?e[s(1548)](_p,H[s(936)],H[s(1721)]):{},pa=Object[s(1050)]({device_platform:e[s(507)],version_code:e[s(361)],access_key:b,fpid:d,aid:m,[zt]:dl,xsack:A?1:0,xaack:A?1:0,xsqos:P?1:0,qos_level:P?U:void 0,qos_sdk_version:2,...eg},Qp),tg=Object[s(1366)](pa)[s(334)]((ga,ma)=>pa[ma]!==void 0?""+ga+(ga?"&":"?")+ma+"="+pa[ma]:ga,"");return je+s(1107)+tg}async[t(390)](){let n=t,s={xNbaQ:function(d,u){return e[M(505)](d,u)},OfQOx:function(d,u){return d&u},xVjgC:function(d,u){return e.Xpzwq(d,u)},dvLrh:function(d,u){return e[M(1803)](d,u)},GkNgp:e[n(1624)],jfUmO:function(d,u){return d|u},mjoru:function(d,u){return e[n(854)](d,u)},tjoKA:function(d,u){return e.rSExO(d,u)},ySPVG:function(d,u){return e.PxBFw(d,u)},KnVGo:function(d,u){return e.rfevm(d,u)},wfhKU:function(d,u){return e.vdnyw(d,u)},pWCSn:function(d,u){return e[n(1646)](d,u)},bShAR:function(d,u){return e.zUTmB(d,u)},yTnTh:function(d,u){return e.RvwlX(d,u)}};if(!(this[n(390)+n(1475)]||this[n(907)+n(1829)])){this._connectLock=!0;try{let d=this["_endpoin"+n(828)]?.[n(690)+n(682)+n(380)+n(987)+"tries"](),{timeoutInterval:u}=this[n(1268)];if(d){let g=this[n(1196)+n(828)]?.[n(1750)+n(549)+"nt"](),b=this[n(1196)+n(828)]?.["replaceBackupEnd"+n(1631)+"UpdateCo"+n(984)](),m=this[n(1196)+n(828)]?.[n(1750)+n(549)+n(1761)+n(383)]();if(b)if(e[n(1536)](n(555),n(555))){let T=n(693)+g+(" timeout"+n(461)+n(794)+n(675)+n(1347)+"backup e"+n(1151))+b+(n(891)+"y"),A=e[n(481)](at,e.NRIPJ,{message:T,code:tn[n(789)+n(1508)+"R"]});this._debug(T),this[n(1160)+n(1161)+n(349)](A),this[n(957)]=await this._generateUrl(b),this[n(812)]("connect "+b+" "+m+" times"),this[n(1697)+"sListeners"]()}else if(_0x401e81=_0x4c6961[n(1208)+"At"](_0x2b71cc),_0x3679c4<128)_0x353426[_0x4bcffd++]=_0x3dd2aa;else if(_0x353f6b<2048)_0x17d835[_0x11a8cd++]=BpjCju[n(453)](_0x2c2842,6)|192,_0x4d7718[_0x4786c4++]=BpjCju.OfQOx(63,_0x310880)|128;else if(BpjCju.xVjgC(64512&_0x1c735f,55296)&&BpjCju[n(1682)](BpjCju[n(543)](64512,_0x7b87b=_0x5be929.charCodeAt(BpjCju.dvLrh(_0x57e917,1))),56320)){let T=BpjCju[n(1863)].split("|"),A=0;for(;;){switch(T[A++]){case"0":_0x53c75c[_0x1bea28++]=BpjCju[n(1801)](_0x107499>>18,240);continue;case"1":_0x52b65c[_0x211347++]=BpjCju.mjoru(BpjCju.tjoKA(_0x4813ba,12)&63,128);continue;case"2":_0x1c49f6[_0x547025++]=BpjCju[n(683)](BpjCju[n(543)](63,_0x5932a5),128);continue;case"3":_0x128891[_0x16609b++]=BpjCju[n(1235)](BpjCju.OfQOx(BpjCju[n(658)](_0x2b3bf3,6),63),128);continue;case"4":_0x356577=BpjCju[n(1314)](65536,BpjCju[n(924)](1023&_0xb7a0fa,10))+BpjCju[n(543)](1023,_0x330cf2);continue;case"5":++_0x26a2b0;continue}break}}else _0x605cd4[_0x25ddb6++]=BpjCju[n(1031)](BpjCju[n(658)](_0x68c7a8,12),224),_0x496823[_0x2c9f58++]=BpjCju[n(1852)](BpjCju.OfQOx(BpjCju[n(658)](_0x14d816,6),63),128),_0x31bb15[_0x3b01cb++]=BpjCju[n(1383)](BpjCju.OfQOx(63,_0x3db590),128);else{let T="connect "+g+(n(1569)+", max retries reached");this._debug(T),this["_dispatc"+n(1161)+"ent"](at(e[n(1303)],{message:T,code:tn["MAX_RETR"+n(1508)+"R"]}));return}}else{let g=this[n(1196)+n(828)]?.[n(1750)+n(549)+n(1312)+n(860)](),b=this[n(1196)+"tManager"]?.[n(1750)+"ntEndpoi"+n(1761)+n(383)]();this[n(957)]=await this[n(1361)+n(872)](e.cbYMS(g,"")),this[n(812)](n(693)+g+" "+b+n(1778)),this[n(1697)+"sListeners"]()}if(this[n(999)])this[n(999)]=!1;else{let g=e.qwQjV(aa,e[n(1559)],{message:n(968)});this[n(802)+n(704)]&&this[n(802)+"econnect"](g)}let h=this["_endpoin"+n(828)]?.[n(1750)+n(549)+n(1761)+"ount"]()||0;e.rDggi(h,1)&&await this[n(1712)](h-1),this._debug("connecting url: "+this[n(957)]+(n(1466)+n(375))+this[n(1252)+"ls"]),this[n(1834)]=e.BoDyf(gp,{url:this[n(957)],protocols:[this._protocols],headers:this[n(1268)][n(1087)+"ramParams"][n(1074)+n(1188)]},this[n(1268)].ws),(this[n(1876)+"er"]||this[n(1502)+"r"])&&this[n(1834)]&&(this[n(1834)][n(1435)+"pe"]=this[n(985)+n(471)]),this[n(827)+"steners"](),this[n(390)+n(572)+"utId"]=e[n(1567)](setTimeout,this[n(532)+"ut"][n(770)](this),u)}catch(d){throw this._connectLock=!1,d}}}[t(1259)+t(769)](){let n=t;e[n(1486)](e.Unjmn,e[n(335)])?(e[n(1587)](_0x4943ee,_0x2a22ac,18),e.jyGUF(_0x1884fb,_0x35632c,_0x314b11)):(e[n(825)](clearTimeout,this[n(390)+"ionTimeo"+n(1105)]),this[n(390)+n(572)+n(1105)]=null)}[t(904)+"ngTimer"](){let n=t,s={Wuwut:function(d,u,h){return e[M(1738)](d,u,h)},PvRuP:e[n(1303)]};if(e[n(749)]!==e[n(581)])e[n(1373)](clearTimeout,this[n(446)+n(1285)+"Id"]),e[n(509)](clearTimeout,this[n(1749)+"ctTimeou"+n(1758)]),this[n(446)+n(1285)+"Id"]=null,this[n(1749)+n(1112)+n(1758)]=null;else{let d=this[n(1196)+n(828)]?.[n(1253)+n(1573)+"es"](),u=this[n(1196)+n(828)]?.[n(1750)+n(549)+"nt"]();if(d&&!_0x44e98d[n(558)]){let h=n(693)+u+(n(1811)+n(1622)+"es reached");this[n(1160)+n(1161)+n(349)](_0x363f07(n(1757),{message:h,code:_0x2f001a["MAX_RETR"+n(1508)+"R"],error:_0x5a0323}));return}this._ws&&this[n(1834)][n(1371)+"te"]===this[n(1080)]&&this[n(1809)+n(328)](),this[n(1160)+n(1161)+n(349)](mEmaNw[n(1008)](_0x2bfcf0,mEmaNw.PvRuP,{message:_0x1b6e91[n(558)],code:_0x4c6fa1[n(1900)+n(1699)],error:_0x23d0d1}))}}[t(812)](...n){let s=t;this[s(1268)][s(754)]&&console.log[s(1072)](console,[e[s(1180)],...n])}["_getInte"+t(1844)+"e"](n){let s=t,{initReconnectInterval:d,maxReconnectInterval:u,reconnectIntervalGrowFactor:h}=this[s(1268)],g=e[s(1865)](d,Math[s(963)](h,e[s(462)](n,1)));return e[s(1106)](g,u)?u:g}_ping(){let n=t;if(this[n(1834)]&&e[n(1770)](this[n(1834)][n(1371)+"te"],this[n(1179)+"NG"])){this[n(904)+n(493)](),this[n(446)+n(1285)+"Id"]=e.feBqy(setTimeout,this[n(1462)][n(770)](this),this[n(1268)][n(598)+n(1606)]);return}if(!this._ws||e.InHbe(this[n(1834)][n(1371)+"te"],this[n(1080)]))return void this[n(780)+n(704)]();this[n(1834)]&&this[n(1834)].send("hi"),this[n(1749)+n(1112)+n(1758)]=e[n(354)](setTimeout,this[n(780)+"econnect"+n(1860)].bind(this),this[n(1268)][n(607)+n(1768)+n(824)])}[t(780)+t(704)+t(1860)](){let n=t;if(e[n(632)]!==n(1632))this[n(1492)+"sCounter"]?.[n(973)](),this[n(521)]("ping_once_timeout",e[n(646)]),this[n(1492)+"sCounter"]?.[n(1253)+n(1070)+"nt"]()?this[n(780)+"econnect"]():this[n(1462)]();else return _0x11f27a[_0x3f7bd5]=_0x96205a,!0}[t(495)+t(1619)](){let n=t;return this[n(733)+"T"]||this[n(1853)+"X"]?this[n(1335)+n(1247)+n(1813)]:(this[n(1876)+"er"]||this[n(1502)+"r"])&&this._options[n(1763)+n(1461)+n(829)]?navigator[n(800)]:!0}_handleReconnect(){let n=t;!this[n(495)+n(1619)]()||this[n(907)+n(1829)]||(this["_endpoin"+n(828)]?.[n(1893)+"pointConfig"](),this[n(1492)+n(858)]?.[n(1290)+n(914)](),this[n(1834)]?this[n(1809)+n(328)](1001,n(859)+n(814)+n(1470)+n(843)+n(1776),!0):this[n(390)]())}[t(320)+t(389)+t(499)](){let n=t;this._isMiniTT?tt[n(1514)+"kStatusC"+n(513)](({isConnected:s})=>{let d=n;this[d(1335)+"igatorOn"+d(1813)]=s,s?this[d(1036)+d(490)]():this[d(1036)+d(933)]()}):this[n(1853)+"X"]&&wx[n(1514)+n(1723)+n(513)](({isConnected:s})=>{let d=n;this[d(1335)+"igatorOn"+d(1813)]=s,s?this[d(1036)+"nLine"]():this["_handleO"+d(933)]()})}_wait(n){let s=t,d={ftkbU:e.NQDQX,jZWhd:e[s(1453)]};if(e.VCmYI===s(424)){let u={QmLZA:gChIzn[s(1695)],DQZvc:gChIzn.jZWhd};_0x2b0aa4.r=h=>{let g=s;g(1692)+"d"!=typeof _0x3ad524&&_0x17fe8e[g(1885)+g(1746)]&&_0xb9093[g(856)+"operty"](h,_0x2fd584[g(1885)+"Tag"],{value:u[g(1354)]}),_0x132e14[g(856)+g(1015)](h,u[g(1516)],{value:!0})}}else return new Promise(u=>{let h=s;e[h(869)](setTimeout,u,this["_getInte"+h(1844)+"e"](n))})}[t(1809)+t(328)](n=1e3,s="",d=!1){let u=t;this[u(1834)]&&this[u(879)+u(1313)+"t"](n,s,d)}[t(532)+"ut"](){let n=t,s={cdTIR:function(d,u){return e[M(947)](d,u)},owpAp:function(d,u){return e[M(1222)](d,u)},yogpt:function(d,u){return e.AebQj(d,u)},fYZgo:function(d,u){return e[M(1479)](d,u)},dwEpB:function(d,u){return d<<u},EDaKP:function(d,u){return e[M(423)](d,u)},gTcHh:function(d,u){return e[M(523)](d,u)},SCmNV:function(d,u){return e[M(976)](d,u)},gsVJa:function(d,u){return e[M(1815)](d,u)},pPgEk:function(d,u){return e.XmVVJ(d,u)},YwJsc:function(d,u){return e.EKRUF(d,u)}};if(e[n(546)](e[n(1512)],e[n(1385)])){let d=this[n(1196)+n(828)]?.getCurrentEndpoint();this._debug(n(693)+d+n(1569)),this[n(1809)+n(328)](1001,e.SrkTK,!0)}else{let d=_0x10872b[n(1208)+"At"](_0x375c74);d>=55296&&CmOAPv.cdTIR(d,56319)&&CmOAPv[n(874)](_0x431988+1,_0x570c99)&&(d=CmOAPv[n(337)](CmOAPv[n(1097)](CmOAPv[n(728)](d,10),_0x18f343.charCodeAt(++_0x44c723)),56613888)),CmOAPv[n(874)](d,128)?_0x3290ff[_0x1b54dc++]=d:(d<2048?_0x16c3a2[_0xb470f8++]=CmOAPv[n(1091)](CmOAPv[n(1782)](d,6),31)|192:(CmOAPv[n(1238)](d,65536)?_0x5cdef9[_0x5ea31a++]=CmOAPv[n(1244)](CmOAPv.pPgEk(CmOAPv[n(1782)](d,12),15),224):(_0x3a5ca4[_0xdf64ae++]=CmOAPv[n(1244)](d>>18&7,240),_0x1e1a4e[_0x55320b++]=CmOAPv[n(725)](d,12)&63|128),_0x449df6[_0x1c38fa++]=CmOAPv[n(1244)](CmOAPv.pPgEk(CmOAPv[n(725)](d,6),63),128)),_0x34bf61[_0x22be3b++]=CmOAPv[n(1244)](63&d,128))}}[t(1396)](n){let s=t,d=Bt(n);this._ws&&e[s(1352)](this[s(1834)][s(1371)+"te"],this[s(1080)])&&(this[s(1834)]&&this._ws[s(1422)](d),this[s(812)](e[s(489)],n))}[t(1697)+t(470)+"rs"](){let n=t;if(e[n(393)](e[n(1570)],e[n(1570)])){let s=e.lhRzt[n(1419)]("|"),d=0;for(;;){switch(s[d++]){case"0":if(!this[n(1834)])return;continue;case"1":this[n(1834)][n(1360)+n(386)+n(895)](e[n(1297)],this[n(790)]);continue;case"2":this._ws[n(1360)+n(386)+n(895)](e[n(1487)],this[n(312)]);continue;case"3":this._ws[n(1360)+"entListener"](e[n(1303)],this[n(1410)]);continue;case"4":this[n(1834)][n(1360)+n(386)+n(895)](e.lkoMV,this[n(714)+"ge"]);continue}break}}else return e[n(1430)](e[n(1018)](_0x21fc74,4).join("0"),e[n(1472)](_0xa9862d,_0x1e165b,2).toString(16))[n(329)](-4)}[t(827)+t(1786)](){let n=t,s=e[n(448)][n(1419)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1834)][n(1617)+"Listener"](e[n(1487)],this[n(312)]);continue;case"1":if(!this[n(1834)])return;continue;case"2":this[n(1834)]["addEvent"+n(1583)](e[n(571)],this[n(714)+"ge"]);continue;case"3":this[n(1834)][n(1617)+n(1583)](e.fMlbV,this._onClose);continue;case"4":this[n(1834)][n(1617)+"Listener"](e[n(1303)],this[n(1410)]);continue}break}}[t(694)+t(1752)](n=1e3,s=""){let d=t;try{this[d(1834)]&&this[d(1834)][d(1033)](n,s)}catch{}}[t(879)+"WebSocket"](n=1e3,s="",d=!1){let u=t;if(this[u(904)+"ngTimer"](),this[u(1259)+"mer"](),this[u(1697)+u(470)+"rs"](),this._wsInstanceClose(1e3,s),this[u(390)+"Lock"]=!1,d&&this[u(495)+u(1619)]()&&!this[u(907)+"osed"]){if(this._endpointManager?.[u(1253)+u(1573)+"es"]()){let g=this[u(1196)+u(828)]?.[u(1750)+u(549)+"nt"]();this[u(1160)+u(1546)+"ent"](xt(e.fMlbV,{code:1006,reason:u(693)+g+(u(1569)+", max re"+u(794)+u(1374)),wasClean:!0}))}else{let g=this[u(1268)][u(1470)+u(1889)+u(672)](n,s);this[u(1160)+"hCloseEv"+u(349)](e[u(1040)](xt,u(1033),{code:n,reason:s,wasClean:!0,willReconnect:g})),g&&this[u(390)]()}return}this[u(495)+u(1619)]()||this._readyClosed?this[u(1160)+u(1546)+u(349)](xt(e[u(1297)],{code:n,reason:u(1358)})):this["_dispatchCloseEv"+u(349)](e[u(1867)](xt,u(1033),{code:1006,reason:e[u(1688)]})),this[u(1834)]=null,this[u(1196)+u(828)]?.[u(1893)+"pointCon"+u(1113)](),this[u(1492)+u(858)]?.[u(1290)+"nter"]()}[t(1160)+t(1240)+"nt"](n){let s=t;this[s(521)](s(627),n),this[s(631)]&&this.onopen(n)}[t(1160)+"hMessage"+t(1038)](n){let s=t;if(e[s(1644)](e[s(651)],e[s(651)]))this[s(521)](e[s(571)],n),this.onmessage&&this[s(688)+"e"](n);else return _0xd85722(_0x49674)}[t(1160)+"hAckMess"+t(662)](n){let s=t;this[s(521)](e[s(1378)],n),this["onReceiv"+s(1263)]&&this["onReceiv"+s(1263)](n)}["_dispatchErrorEv"+t(349)](n){let s=t;this[s(521)](e.NRIPJ,n),this[s(322)]&&this[s(322)](n)}[t(1160)+"hCloseEvent"](n){let s=t;this[s(521)](e[s(1297)],n),this[s(1304)]&&this.onclose(n)}get binaryType(){let n=t;return this._ws?this[n(1834)][n(1435)+"pe"]:this["_binaryT"+n(471)]}set[t(1435)+"pe"](n){let s=t;this._binaryType=n,this[s(1834)]&&(this[s(1834)][s(1435)+"pe"]=n)}get[t(479)+"nt"](){let n=t;return this[n(1196)+n(828)]?.[n(1750)+n(549)+"ntTriesC"+n(383)]()||0}get[t(1861)+"Amount"](){let n=t;if(e[n(491)](e[n(1839)],n(376))){let s=this[n(698)+n(313)][n(334)]((d,u)=>(d+=u&&u[n(1228)+"th"]||0,d),0);return e.GNidQ(s,this[n(1834)]?this[n(1834)][n(1861)+"Amount"]:0)}else return this[n(678)][n(1561)]()}get extensions(){let n=t;return e.YsvBr==="ZXBrX"?this._ws?this[n(1834)][n(1637)+"ns"]:"":_0x1984af[n(685)+n(939)][1]?void 0:_0x4ea247[n(685)+n(1065)](_0x39cbca[n(685)+n(939)][0])}get protocol(){let n=t;return this._ws?this[n(1834)].protocol:""}get readyState(){let n=t;return this[n(1834)]?this._ws.readyState:this[n(1268)][n(787)+n(1300)]?this[n(1179)+"NG"]:this[n(1013)]}get[t(969)](){let n=t;if(e.HQRZM(e[n(1558)],e.VcyhE))_0x19e333.log(_0x2bd674);else return this[n(1834)]?this[n(1834)][n(969)]:this[n(957)]}close(n=1e3,s){let d=t,u={YjjOY:function(h,g){return e.cLKya(h,g)},HeGlU:function(h,g){return e[M(1317)](h,g)},CVSOR:function(h,g){return h<<g},oMCiz:function(h,g){return e[M(1907)](h,g)},iHqcf:function(h,g){return e.TFHnw(h,g)},RACTE:function(h,g){return h+g},qEUoe:function(h,g){return e[M(585)](h,g)},iRKGj:function(h,g){return h+g},aKriS:function(h,g){return h|g},iDiqA:function(h,g){return e[M(1473)](h,g)},rRgNw:function(h,g){return e[M(850)](h,g)},SeYKp:function(h,g){return h+g}};if(e[d(1702)](e[d(890)],d(766))){let h=new _0x4b38c4(AITvOJ[d(861)](AITvOJ[d(608)](AITvOJ[d(1437)](_0x2f6f1d[AITvOJ.oMCiz(_0x42a42e,4)],24),AITvOJ[d(1883)](_0x35ee42[AITvOJ[d(1176)](_0x491efd,5)],16))|AITvOJ[d(1883)](_0x20f4d2[AITvOJ[d(1894)](_0x2ff8da,6)],8),_0x26bb51[AITvOJ[d(1138)](_0x74448b,7)]),AITvOJ[d(1324)](AITvOJ[d(1182)](AITvOJ[d(1883)](_0x4ba2a8[AITvOJ[d(1138)](_0x30d245,0)],24)|AITvOJ.rRgNw(_0x25a179[AITvOJ.oMCiz(_0x548aab,1)],16),AITvOJ[d(1437)](_0x418b46[AITvOJ.iRKGj(_0x91c86b,2)],8)),_0x4d3782[AITvOJ[d(833)](_0x1874e9,3)]),!0);return _0x5e9020+=8,{value:h,offset:_0x31e09e+8}}else{let h=e[d(950)][d(1419)]("|"),g=0;for(;;){switch(h[g++]){case"0":this["_clearTi"+d(769)]();continue;case"1":this[d(879)+"WebSocket"](n,s);continue;case"2":this[d(1460)+"ger"]?.[d(1895)]();continue;case"3":this["_dropGlo"+d(990)+"Listener"]();continue;case"4":if(e.eCPsT(this._ws[d(1371)+"te"],this[d(1013)])||this[d(1834)].readyState===this[d(1170)])return void this._debug(e[d(1279)]);continue;case"5":this[d(907)+"osed"]=!0;continue;case"6":this["_clearPi"+d(493)]();continue;case"7":if(!this._ws)return void this[d(812)](e.zEPzw);continue}break}}}async[t(1422)](n,s){let d=t;if(n==null)throw new Error(d(315)+d(721)+d(867)+d(1381)+"a must b"+d(1210)+d(1667)+d(1328)+d(1448));e.RGhPX(d(388),typeof n)&&(n=JSON[d(748)+"y"](n)),e[d(1727)](e[d(1870)],typeof n)&&!e[d(1814)](n,ArrayBuffer)&&!(n.buffer&&n.buffer instanceof ArrayBuffer)&&(n=JSON[d(748)+"y"](n));let u=await il(n),h=e[d(1871)](wp,n),{method:g=0,service:b=this[d(1268)][d(1520)],logID:m=this._options["logIDGen"+d(1053)](),headers:T=this[d(1268)][d(1225)],payloadEncoding:A=this[d(1268)]["payloadE"+d(1418)],payloadType:P=this[d(1268)][d(668)+d(471)],logIDNew:U=this[d(1268)][d(1382)+"Config"]["enableAu"+d(898)+d(1577)+"ew"]?e[d(1871)](i,this[d(1268)][d(1382)+d(444)].userIp):""}=e[d(324)](s,{});if(!b)throw new Error(e.JrPIn);let H={SeqID:fe.fromNumber(this[d(1355)]++),LogID:fe[d(1145)+"er"](m),service:b,method:g,headers:T,payloadEncoding:e[d(1549)](A,Object)?A.encoding?A[d(1443)]:"":A,payloadType:e[d(943)](P,Object)?P[d(1186)]?P[d(1186)]:h:P||h,payload:u,LogIDNew:U},Y=e[d(1566)](Bt,H);return this[d(1834)]&&e[d(612)](this[d(1834)][d(1371)+"te"],this[d(1080)])?(this[d(1834)]&&this[d(1834)][d(1422)](Y),this._debug(e[d(1429)],H)):e[d(1629)](this[d(698)+d(313)].length,this[d(1268)][d(1255)+d(1e3)+d(1192)])?(this[d(698)+d(313)][d(1774)](Y),this._debug(e[d(1764)],H)):(this[d(698)+d(313)][d(641)](),this[d(698)+"Queue"][d(1774)](Y)),{seqID:this._seqId,logID:m,logIDNew:U}}async[t(1470)+"t"](n){let s=t,d={Junmj:e.NRIPJ},{url:u}=e[s(1174)](n,{}),h=Array[s(1742)](u)?u:e[s(547)](s(1441),typeof u)?[u]:[];n&&Object[s(1050)](this[s(1268)],n),h&&h[s(519)]?this[s(1196)+s(828)]=new el(h,this._options[s(511)+"es"]):this[s(1196)+"tManager"]?.[s(1893)+"pointCon"+s(1113)](),this._pingLossCounter?.[s(1290)+"nter"](this[s(1268)]["pingLoss"+s(561)]),this[s(907)+s(1829)]=!1,this[s(1834)]&&e[s(1491)](this[s(1834)].readyState,this[s(1013)])?this[s(1809)+s(328)](1e3,e[s(1083)],!0):e[s(740)](e.NTtUx,e.NTtUx)?(this[s(999)]=!0,this._connect()):(this.emit(QMBPEV[s(926)],_0x4be43f),this[s(322)]&&this[s(322)](_0x126e99))}async[t(755)](){let n=t;if(!this[n(390)+"Lock"])if(e[n(1143)](e.qCfYF,e[n(1310)]))this[n(700)+n(818)]=null;else{let s=e.JkRMi[n(1419)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1492)+n(858)]?.[n(1290)+n(914)]();continue;case"1":this[n(1196)+n(828)]?.resetEndpointConfig();continue;case"2":this["_readyCl"+n(1829)]=!1;continue;case"3":this[n(999)]=!0;continue;case"4":this[n(390)]();continue}break}}}[t(1617)+t(1583)](n,s){this.on(n,s)}[t(1614)+t(1038)](n){let s=t,{type:d}=n;this[s(521)](d,n)}[t(1360)+t(386)+"ner"](n,s){this[t(1822)](n,s)}pingOnce(){let n=t,s={tQuXf:function(d,u){return e[M(1037)](d,u)},pPKFh:function(d,u){return d|u},ywlkw:function(d,u){return e.jfdar(d,u)},KzVvt:function(d,u){return e[M(782)](d,u)},VGnWG:function(d,u){return e.Niboi(d,u)},EGyCd:function(d,u){return e[M(1387)](d,u)},kWTut:function(d,u){return e[M(1348)](d,u)},qYYlQ:function(d,u){return e[M(1030)](d,u)},LExnF:function(d,u,h,g){return e[M(696)](d,u,h,g)},BUPPU:function(d,u){return e[M(739)](d,u)},FtHMl:n(808),rdbLx:n(870)+n(657)+"s",DLKsS:e[n(652)]};return new Promise((d,u)=>{let h=n;this[h(904)+"ngTimer"](),this[h(446)+h(1285)+"Id"]=setTimeout(this[h(1462)][h(770)](this),this[h(1268)].pingInterval);let g=()=>{let m=h,T={qdrhQ:function(A,P){return s[M(599)](A,P)},ECLHi:function(A,P){return s.pPKFh(A,P)},jiRTA:function(A,P){return s.ywlkw(A,P)},UgFiR:function(A,P){return s[M(813)](A,P)},tErri:function(A,P){return A<P},AjBmU:function(A,P){return s[M(1212)](A,P)},xsYSK:function(A,P){return s[M(763)](A,P)},NdKpH:function(A,P){return A<<P},iIVZi:function(A,P){return s[M(979)](A,P)},kxGBe:function(A,P){return A>>>P},Cuflw:function(A,P){return A|P},SrdJm:function(A,P){return A&P},ikxwU:function(A,P){return s[M(473)](A,P)},IkQnQ:function(A,P){return s[M(1212)](A,P)},NabIB:function(A,P){return s.pPKFh(A,P)},EtUkw:function(A,P){return s[M(1722)](A,P)},IFeBp:function(A,P){return s.qYYlQ(A,P)},qPIzx:function(A,P,U,H){return s[M(1450)](A,P,U,H)}};if(s[m(500)](s[m(1485)],m(808))){let A=4294967295;return function(P,U,H=!0){let Y=m;if(A=GrBagD.qdrhQ(127,P[U])>>>0,P[U++]<128)return{value:H?A:GrBagD[Y(757)](0,A),offset:U};if(A=(A|GrBagD[Y(1691)](GrBagD.UgFiR(127,P[U]),7))>>>0,GrBagD[Y(1756)](P[U++],128))return{value:H?A:0|A,offset:U};if(A=GrBagD[Y(912)](GrBagD[Y(537)](A,GrBagD[Y(1551)](127&P[U],14)),0),P[U++]<128)return{value:H?A:GrBagD[Y(899)](0,A),offset:U};if(A=GrBagD[Y(372)](GrBagD[Y(1389)](A,GrBagD[Y(1691)](GrBagD[Y(1320)](127,P[U]),21)),0),GrBagD[Y(568)](P[U++],128))return{value:H?A:0|A,offset:U};if(A=GrBagD[Y(338)](GrBagD[Y(918)](A,GrBagD.EtUkw(GrBagD[Y(1320)](15,P[U]),28)),0),GrBagD[Y(804)](P[U++],128))return{value:H?A:0|A,offset:U};if((U+=5)>P.length)throw U=P.length,GrBagD.qPIzx(_0x440600,U,10,P[Y(519)]);return{value:H?A:0|A,offset:U}}}else d(m(421)),this.off(s[m(1535)],g),this[m(1822)]("ping_once_timeout",b)},b=()=>{let m=h;u(m(1565)),this[m(1822)]("ping_onc"+m(657)+"s",g),this.off(s[m(402)],b)};this.on(s[h(1535)],g),this.on(s[h(402)],b),this[h(1462)]()})}}})(),ve["CustomCl"+B(1023)]=ke[B(1001)+"oseEvent"],ve["CustomEr"+B(772)]=ke.CustomErrorEvent,ve[B(1817)+"e"]=ke[B(1817)+"e"],ve[B(1038)]=ke[B(1038)],ve[B(514)]=ke[B(514)],ve[B(1728)+B(649)+B(793)]=ke[B(1728)+B(649)+"vent"],ve[B(649)+B(793)]=ke[B(649)+"vent"],ve[B(1316)+"t"]=ke[B(1316)+"t"],ve["Reconnec"+B(1219)]=ke["Reconnec"+B(1219)],ve[B(1780)+B(1023)]=ke[B(1780)+B(1023)],ve[B(1868)+B(772)]=ke.createErrorEvent,ve[B(587)+B(928)+"nt"]=ke["createMe"+B(928)+"nt"],ve[B(745)+B(1511)]=ke[B(745)+B(1511)],ve[B(535)+B(951)+B(793)]=ke[B(535)+B(951)+B(793)],ve[B(1669)+B(557)]=ke["decodedF"+B(557)],ve[B(1403)+B(1539)]=ke[B(1403)+B(1539)];for(Bo in ke)[B(1001)+"oseEvent","CustomErrorEvent",B(1817)+"e",B(1038),B(514),"Frontier"+B(649)+B(793),B(649)+B(793),B(1316)+"t",B(1236)+B(1219),B(1780)+"oseEvent",B(1868)+B(772),B(587)+B(928)+"nt","createOp"+B(1511),B(535)+"connectEvent",B(1669)+B(557),B(1403)+B(1539)].indexOf(Bo)===-1&&(ve[Bo]=ke[Bo]);var Bo;Object[B(856)+B(1015)](ve,B(1668)+"le",{value:!0})});import{existsSync as aS,openSync as cS}from"node:fs";import{mkdir as dS}from"node:fs/promises";import{dirname as lS}from"node:path";import{fileURLToPath as uS}from"node:url";function xS(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Pd(t=Q()){return aS(t.libEntry)?t.libEntry:uS(new URL("../index.ts",import.meta.url))}async function kh(t={}){let e=t.paths??Q(),r=t.entryOverride??Pd(e),i=xS(e,process.env.COZE_BRIDGE_LOG_MODE);await dS(lS(i),{recursive:!0});let o=cS(i,"a"),l=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],f=nt(process.execPath,l,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[Qi]:"1"}});if(f.unref(),typeof f.pid!="number")throw new Error("failed to spawn daemon (no pid)");return fS.info("daemon spawned",{pid:f.pid,entry:r}),{pid:f.pid,entry:r}}var fS,Qi,Vo=Ze(()=>{"use strict";Kt();ne();Pe();fS=q("spawn-daemon"),Qi="COZE_BRIDGE_DAEMON"});import{spawn as o2}from"node:child_process";import{mkdir as a2,unlink as c2,writeFile as d2}from"node:fs/promises";import{dirname as l2,join as u2}from"node:path";function Hr(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function f2(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Hr(r)}</key>
21
+ <string>${Hr(i)}</string>`).join(`
22
22
  `);return e?`
23
23
  <key>EnvironmentVariables</key>
24
24
  <dict>
25
25
  ${e}
26
- </dict>`:""}function c1(t,e){return new Promise((r,i)=>{let o=t1(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",u=>{c+=u.toString("utf8")}),o.on("error",i),o.on("close",u=>{u===0?r():i(new Error(`${t} ${e.join(" ")} exited ${u}: ${c.trim()}`))})})}var Wr,ns,na,qd,Vh=Je(()=>{"use strict";ne();Wr=q("supervisor.launchd"),ns="ai.coze.bridge",na=c1,qd={platform:"darwin",renderConfig(t){return`<?xml version="1.0" encoding="UTF-8"?>
26
+ </dict>`:""}function x2(t,e){return new Promise((r,i)=>{let o=o2(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 jr,ts,ta,Gd,Jh=Ze(()=>{"use strict";ne();jr=q("supervisor.launchd"),ts="ai.coze.bridge",ta=x2,Gd={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>${ns}</string>
31
+ <string>${ts}</string>
32
32
  <key>ProgramArguments</key>
33
33
  <array>
34
- <string>${Kr(t.nodeBin)}</string>
35
- <string>${Kr(t.entry)}</string>
34
+ <string>${Hr(t.nodeBin)}</string>
35
+ <string>${Hr(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>${Kr(t.logFile)}</string>
45
+ <string>${Hr(t.logFile)}</string>
46
46
  <key>StandardErrorPath</key>
47
- <string>${Kr(t.logFile)}</string>${a1(t.env)}
47
+ <string>${Hr(t.logFile)}</string>${f2(t.env)}
48
48
  </dict>
49
49
  </plist>
50
- `},configPath(t){return o1(t.homeDir,"Library","LaunchAgents",`${ns}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await n1(s1(i),{recursive:!0}),await i1(i,this.renderConfig(t),"utf8"),Wr.info("plist written",{plistPath:i,activate:r}),!r)return;await na("launchctl",["unload","-w",i]).catch(c=>Wr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await na("launchctl",["load","-w",i]),Wr.info("launchd job loaded",{label:ns});let o=process.getuid?.()??0;await na("launchctl",["kickstart","-k",`gui/${o}/${ns}`]),Wr.info("launchd job kickstarted",{label:ns,uid:o})},async uninstall(t){let e=this.configPath(t);await na("launchctl",["unload","-w",e]).catch(r=>Wr.warn("launchctl unload failed (ignored)",{err:String(r)})),await r1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),Wr.info("launchd job removed",{plistPath:e})}}});import{spawn as d1}from"node:child_process";import{mkdir as u1,unlink as l1,writeFile as f1}from"node:fs/promises";import{dirname as x1,join as Yh}from"node:path";function ia(t,e){return t.isRoot?e:["--user",...e]}function p1(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
- `):""}function sa(t,e){return new Promise((r,i)=>{let o=d1(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",u=>{c+=u.toString("utf8")}),o.on("error",i),o.on("close",u=>{u===0?r():i(new Error(`${t} ${e.join(" ")} exited ${u}: ${c.trim()}`))})})}var ra,$r,h1,Gd,Zh=Je(()=>{"use strict";ne();ra=q("supervisor.systemd"),$r="coze-bridge.service",h1="/etc/systemd/system";Gd={platform:"linux",renderConfig(t){let e=t.isRoot?"multi-user.target":"default.target";return`[Unit]
50
+ `},configPath(t){return u2(t.homeDir,"Library","LaunchAgents",`${ts}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await a2(l2(i),{recursive:!0}),await d2(i,this.renderConfig(t),"utf8"),jr.info("plist written",{plistPath:i,activate:r}),!r)return;await ta("launchctl",["unload","-w",i]).catch(c=>jr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await ta("launchctl",["load","-w",i]),jr.info("launchd job loaded",{label:ts});let o=process.getuid?.()??0;await ta("launchctl",["kickstart","-k",`gui/${o}/${ts}`]),jr.info("launchd job kickstarted",{label:ts,uid:o})},async uninstall(t){let e=this.configPath(t);await ta("launchctl",["unload","-w",e]).catch(r=>jr.warn("launchctl unload failed (ignored)",{err:String(r)})),await c2(e).catch(r=>{if(r.code!=="ENOENT")throw r}),jr.info("launchd job removed",{plistPath:e})}}});import{spawn as h2}from"node:child_process";import{mkdir as p2,unlink as g2,writeFile as m2}from"node:fs/promises";import{dirname as w2,join as Yh}from"node:path";function ra(t,e){return t.isRoot?e:["--user",...e]}function y2(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
+ `):""}function ia(t,e){return new Promise((r,i)=>{let o=h2(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 na,Wr,_2,qd,Zh=Ze(()=>{"use strict";ne();na=q("supervisor.systemd"),Wr="coze-bridge.service",_2="/etc/systemd/system";qd={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
- ${p1(t.env)}
62
+ ${y2(t.env)}
63
63
  [Install]
64
64
  WantedBy=${e}
65
- `},configPath(t){return t.isRoot?Yh(h1,$r):Yh(t.homeDir,".config","systemd","user",$r)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await u1(x1(i),{recursive:!0}),await f1(i,this.renderConfig(t),"utf8"),ra.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await sa("systemctl",ia(t,["daemon-reload"])),await sa("systemctl",ia(t,r?["enable","--now",$r]:["enable",$r])),ra.info("systemd unit enabled",{unitName:$r,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await sa("systemctl",ia(t,["disable","--now",$r])).catch(r=>ra.warn("systemctl disable failed (ignored)",{err:String(r)})),await l1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await sa("systemctl",ia(t,["daemon-reload"])).catch(()=>{}),ra.info("systemd unit removed",{unitPath:e})}}});import{spawn as g1}from"node:child_process";import{join as m1}from"node:path";function Jh(t,e){return new Promise((r,i)=>{let o=g1(t,e,{stdio:["ignore","pipe","pipe"],shell:!1}),c="";o.stderr?.on("data",u=>{c+=u.toString("utf8")}),o.on("error",i),o.on("close",u=>{u===0?r():i(new Error(`${t} ${e.join(" ")} exited ${u}: ${c.trim()}`))})})}var Hd,oa,jd,Xh=Je(()=>{"use strict";ne();Hd=q("supervisor.taskscheduler"),oa="CozeBridge",jd={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
65
+ `},configPath(t){return t.isRoot?Yh(_2,Wr):Yh(t.homeDir,".config","systemd","user",Wr)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await p2(w2(i),{recursive:!0}),await m2(i,this.renderConfig(t),"utf8"),na.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await ia("systemctl",ra(t,["daemon-reload"])),await ia("systemctl",ra(t,r?["enable","--now",Wr]:["enable",Wr])),na.info("systemd unit enabled",{unitName:Wr,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await ia("systemctl",ra(t,["disable","--now",Wr])).catch(r=>na.warn("systemctl disable failed (ignored)",{err:String(r)})),await g2(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await ia("systemctl",ra(t,["daemon-reload"])).catch(()=>{}),na.info("systemd unit removed",{unitPath:e})}}});import{spawn as E2}from"node:child_process";import{join as b2}from"node:path";function Xh(t,e){return new Promise((r,i)=>{let o=E2(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 jd,sa,Hd,Qh=Ze(()=>{"use strict";ne();jd=q("supervisor.taskscheduler"),sa="CozeBridge",Hd={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,48 +86,48 @@ WantedBy=${e}
86
86
  </Exec>
87
87
  </Actions>
88
88
  </Task>
89
- `},configPath(t){return m1(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",oa,"/TR",r,"/RU",t.userName,"/F"]),Hd.info("task scheduler entry created",{task:oa,logFile:t.logFile})},async uninstall(t){await Jh("schtasks",["/Delete","/TN",oa,"/F"]).catch(e=>Hd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Hd.info("task scheduler entry removed",{task:oa})}}});var Qh={};ya(Qh,{buildContext:()=>v1,getSupervisor:()=>y1,launchdSupervisor:()=>qd,systemdSupervisor:()=>Gd,taskSchedulerSupervisor:()=>jd});import{homedir as w1,userInfo as _1}from"node:os";function y1(t=process.platform){switch(t){case"darwin":return qd;case"linux":return Gd;case"win32":return jd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function E1(){let t={};for(let e of b1){let r=process.env[e];r&&(t[e]=r)}return t}function v1(){let t=X();return{nodeBin:process.execPath,entry:Pd(t),logFile:t.logFile,homeDir:w1(),userName:_1().username,isRoot:process.getuid?.()===0,env:E1()}}var b1,ep=Je(()=>{"use strict";Oe();Yo();Vh();Zh();Xh();b1=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ne();rn();var bu=q("acp-installer-warmup"),Ig=["claude-code","codex"];async function Eu(t={}){let e=t.ensure??sr,i=(await Promise.allSettled(Ig.map(async o=>{let c=await e(o);bu.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&bu.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))})}an();ne();import{readdir as Gg}from"node:fs/promises";import{mkdir as Iu,readFile as Ug,writeFile as Tu}from"node:fs/promises";import{join as Ta}from"node:path";var qg={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function cr(t,e,r){await Iu(t,{recursive:!0});let i=qg[e],o=Ta(t,i);return await Tu(o,r??"","utf8"),o}async function Ca(t,e,r){let i=Ta(t,".claude");await Iu(i,{recursive:!0});let o=Ta(i,"settings.local.json"),c={};try{let f=await Ug(o,"utf8"),x=JSON.parse(f);typeof x=="object"&&x!==null&&!Array.isArray(x)&&(c=x)}catch{}let u=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")u.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!r)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");u.defaultMode===void 0&&(u.defaultMode=r)}return c.permissions=u,await Tu(o,JSON.stringify(c,null,2),"utf8"),o}var $e=q("agent-detail-sync"),Hg=6e4,jg=5*6e4,hs=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await Gg(r)}catch(o){$e.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}$e.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Me(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){$e.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(u){$e.warn("detail sync failed for agent, skipping",{agentId:o,err:String(u)})}}})),$e.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){$e.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){$e.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Me(e,this.opts.paths);if(!i){$e.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(x){$e.warn("detail RPC failed, using local data",{agentId:e,err:String(x)});let p=this.retryQueue.get(e),m=p?Math.min(p.currentDelay*2,jg):Hg;this.retryQueue.set(e,{dueAt:Date.now()+m,currentDelay:m});return}if(o.agentId&&o.agentId!==e){$e.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,u=!1;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,u=!0);let f=!1;if(o.deployType==="cloud"&&i.deployType!=="cloud"?($e.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,f=!0):o.deployType&&$e.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){$e.debug("detail sync: no diff",{agentId:e});return}await Qe(i,this.opts.paths),$e.info("detail sync: config updated",{agentId:e,identityChanged:u,agentName:i.agentName}),f?(await this.opts.agentManager.createAgent({agentId:e,framework:i.framework,_meta:{cozeDeployType:"cloud"},cozeIdentity:i.cozeIdentity,model:i.model}),$e.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):u&&(await cr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var Vf=Ft(ol(),1);import{lstat as Gc,mkdir as Hc,readFile as jf,readdir as S_,rm as A_,stat as I_,writeFile as jc}from"node:fs/promises";import{dirname as T_,join as Dt,normalize as C_,relative as $c,resolve as Wc,sep as Wf}from"node:path";import{Readable as Kf}from"node:stream";import{pipeline as $f}from"node:stream/promises";import fm from"events";import et from"fs";import{EventEmitter as Tc}from"node:events";import ql from"node:stream";import{StringDecoder as xm}from"node:string_decoder";import jl from"node:path";import yr from"node:fs";import{dirname as Im,parse as Tm}from"path";import{EventEmitter as Nm}from"events";import cc from"assert";import{Buffer as qn}from"buffer";import*as ll from"zlib";import Mm from"zlib";import{posix as xr}from"node:path";import{basename as dw}from"node:path";import Ks from"fs";import Ct from"fs";import wl from"path";import{win32 as bw}from"node:path";import Al from"path";import of from"node:fs";import zw from"node:assert";import{randomBytes as af}from"node:crypto";import re from"node:fs";import Ne from"node:path";import cf from"fs";import to from"node:fs";import bi from"node:path";import st from"node:fs";import Ww from"node:fs/promises";import Ys from"node:path";import{join as _f}from"node:path";import it from"node:fs";import Ef from"node:path";var um=Object.defineProperty,lm=(t,e)=>{for(var r in e)um(t,r,{get:e[r],enumerable:!0})},al=typeof process=="object"&&process?process:{stdout:null,stderr:null},hm=t=>!!t&&typeof t=="object"&&(t instanceof jn||t instanceof ql||pm(t)||gm(t)),pm=t=>!!t&&typeof t=="object"&&t instanceof Tc&&typeof t.pipe=="function"&&t.pipe!==ql.Writable.prototype.pipe,gm=t=>!!t&&typeof t=="object"&&t instanceof Tc&&typeof t.write=="function"&&typeof t.end=="function",Ut=Symbol("EOF"),qt=Symbol("maybeEmitEnd"),dn=Symbol("emittedEnd"),_s=Symbol("emittingEnd"),ii=Symbol("emittedError"),ys=Symbol("closed"),cl=Symbol("read"),bs=Symbol("flush"),dl=Symbol("flushChunk"),ht=Symbol("encoding"),fr=Symbol("decoder"),Be=Symbol("flowing"),si=Symbol("paused"),mr=Symbol("resume"),ze=Symbol("buffer"),Ve=Symbol("pipes"),Fe=Symbol("bufferLength"),La=Symbol("bufferPush"),Es=Symbol("bufferShift"),Ke=Symbol("objectMode"),Se=Symbol("destroyed"),Na=Symbol("error"),Ma=Symbol("emitData"),ul=Symbol("emitEnd"),Ba=Symbol("emitEnd2"),At=Symbol("async"),za=Symbol("abort"),vs=Symbol("aborted"),oi=Symbol("signal"),Pn=Symbol("dataListeners"),rt=Symbol("discarded"),ai=t=>Promise.resolve().then(t),mm=t=>t(),wm=t=>t==="end"||t==="finish"||t==="prefinish",_m=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,ym=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Gl=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[mr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},bm=class extends Gl{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)}},Em=t=>!!t.objectMode,vm=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",jn=class extends Tc{[Be]=!1;[si]=!1;[Ve]=[];[ze]=[];[Ke];[ht];[At];[fr];[Ut]=!1;[dn]=!1;[_s]=!1;[ys]=!1;[ii]=null;[Fe]=0;[Se]=!1;[oi];[vs]=!1;[Pn]=0;[rt]=!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");Em(e)?(this[Ke]=!0,this[ht]=null):vm(e)?(this[ht]=e.encoding,this[Ke]=!1):(this[Ke]=!1,this[ht]=null),this[At]=!!e.async,this[fr]=this[ht]?new xm(this[ht]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[ze]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Ve]});let{signal:r}=e;r&&(this[oi]=r,r.aborted?this[za]():r.addEventListener("abort",()=>this[za]()))}get bufferLength(){return this[Fe]}get encoding(){return this[ht]}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[Ke]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[At]}set async(t){this[At]=this[At]||!!t}[za](){this[vs]=!0,this.emit("abort",this[oi]?.reason),this.destroy(this[oi]?.reason)}get aborted(){return this[vs]}set aborted(t){}write(t,e,r){if(this[vs])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[At]?ai:mm;if(!this[Ke]&&!Buffer.isBuffer(t)){if(ym(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(_m(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Ke]?(this[Be]&&this[Fe]!==0&&this[bs](!0),this[Be]?this.emit("data",t):this[La](t),this[Fe]!==0&&this.emit("readable"),r&&i(r),this[Be]):t.length?(typeof t=="string"&&!(e===this[ht]&&!this[fr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[ht]&&(t=this[fr].write(t)),this[Be]&&this[Fe]!==0&&this[bs](!0),this[Be]?this.emit("data",t):this[La](t),this[Fe]!==0&&this.emit("readable"),r&&i(r),this[Be]):(this[Fe]!==0&&this.emit("readable"),r&&i(r),this[Be])}read(t){if(this[Se])return null;if(this[rt]=!1,this[Fe]===0||t===0||t&&t>this[Fe])return this[qt](),null;this[Ke]&&(t=null),this[ze].length>1&&!this[Ke]&&(this[ze]=[this[ht]?this[ze].join(""):Buffer.concat(this[ze],this[Fe])]);let e=this[cl](t||null,this[ze][0]);return this[qt](),e}[cl](t,e){if(this[Ke])this[Es]();else{let r=e;t===r.length||t===null?this[Es]():typeof r=="string"?(this[ze][0]=r.slice(t),e=r.slice(0,t),this[Fe]-=t):(this[ze][0]=r.subarray(t),e=r.subarray(0,t),this[Fe]-=t)}return this.emit("data",e),!this[ze].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[Be]||!this[si])&&this[qt](),this}[mr](){this[Se]||(!this[Pn]&&!this[Ve].length&&(this[rt]=!0),this[si]=!1,this[Be]=!0,this.emit("resume"),this[ze].length?this[bs]():this[Ut]?this[qt]():this.emit("drain"))}resume(){return this[mr]()}pause(){this[Be]=!1,this[si]=!0,this[rt]=!1}get destroyed(){return this[Se]}get flowing(){return this[Be]}get paused(){return this[si]}[La](t){this[Ke]?this[Fe]+=1:this[Fe]+=t.length,this[ze].push(t)}[Es](){return this[Ke]?this[Fe]-=1:this[Fe]-=this[ze][0].length,this[ze].shift()}[bs](t=!1){do;while(this[dl](this[Es]())&&this[ze].length);!t&&!this[ze].length&&!this[Ut]&&this.emit("drain")}[dl](t){return this.emit("data",t),this[Be]}pipe(t,e){if(this[Se])return t;this[rt]=!1;let r=this[dn];return e=e||{},t===al.stdout||t===al.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[Ve].push(e.proxyErrors?new bm(this,t,e):new Gl(this,t,e)),this[At]?ai(()=>this[mr]()):this[mr]()),t}unpipe(t){let e=this[Ve].find(r=>r.dest===t);e&&(this[Ve].length===1?(this[Be]&&this[Pn]===0&&(this[Be]=!1),this[Ve]=[]):this[Ve].splice(this[Ve].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[rt]=!1,this[Pn]++,!this[Ve].length&&!this[Be]&&this[mr]();else if(t==="readable"&&this[Fe]!==0)super.emit("readable");else if(wm(t)&&this[dn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[ii]){let i=e;this[At]?ai(()=>i.call(this,this[ii])):i.call(this,this[ii])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Pn]=this.listeners("data").length,this[Pn]===0&&!this[rt]&&!this[Ve].length&&(this[Be]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Pn]=0,!this[rt]&&!this[Ve].length&&(this[Be]=!1)),e}get emittedEnd(){return this[dn]}[qt](){!this[_s]&&!this[dn]&&!this[Se]&&this[ze].length===0&&this[Ut]&&(this[_s]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[ys]&&this.emit("close"),this[_s]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Se&&this[Se])return!1;if(t==="data")return!this[Ke]&&!r?!1:this[At]?(ai(()=>this[Ma](r)),!0):this[Ma](r);if(t==="end")return this[ul]();if(t==="close"){if(this[ys]=!0,!this[dn]&&!this[Se])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[ii]=r,super.emit(Na,r);let o=!this[oi]||this.listeners("error").length?super.emit("error",r):!1;return this[qt](),o}else if(t==="resume"){let o=super.emit("resume");return this[qt](),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[qt](),i}[Ma](t){for(let r of this[Ve])r.dest.write(t)===!1&&this.pause();let e=this[rt]?!1:super.emit("data",t);return this[qt](),e}[ul](){return this[dn]?!1:(this[dn]=!0,this.readable=!1,this[At]?(ai(()=>this[Ba]()),!0):this[Ba]())}[Ba](){if(this[fr]){let e=this[fr].end();if(e){for(let r of this[Ve])r.dest.write(e);this[rt]||super.emit("data",e)}}for(let e of this[Ve])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Ke]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[Ke]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[Ke])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[ht]?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[rt]=!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",u),this.off("end",f),this.off(Se,x),e(),o(p)},u=p=>{this.off("error",c),this.off("end",f),this.off(Se,x),this.pause(),i({value:p,done:!!this[Ut]})},f=()=>{this.off("error",c),this.off("data",u),this.off(Se,x),e(),i({done:!0,value:void 0})},x=()=>c(new Error("stream destroyed"));return new Promise((p,m)=>{o=m,i=p,this.once(Se,x),this.once("error",c),this.once("end",f),this.once("data",u)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[rt]=!1;let t=!1,e=()=>(this.pause(),this.off(Na,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(Na,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[rt]=!0,this[ze].length=0,this[Fe]=0;let e=this;return typeof e.close=="function"&&!this[ys]&&e.close(),t?this.emit("error",t):this.emit(Se),this}static get isStream(){return hm}},Sm=et.writev,_n=Symbol("_autoClose"),wt=Symbol("_close"),ci=Symbol("_ended"),de=Symbol("_fd"),Fa=Symbol("_finished"),Wt=Symbol("_flags"),Ua=Symbol("_flush"),oc=Symbol("_handleChunk"),ac=Symbol("_makeBuf"),_i=Symbol("_mode"),Ss=Symbol("_needDrain"),Er=Symbol("_onerror"),vr=Symbol("_onopen"),qa=Symbol("_onread"),wr=Symbol("_onwrite"),yn=Symbol("_open"),mt=Symbol("_path"),hn=Symbol("_pos"),It=Symbol("_queue"),_r=Symbol("_read"),Ga=Symbol("_readSize"),jt=Symbol("_reading"),di=Symbol("_remain"),Ha=Symbol("_size"),Ls=Symbol("_write"),On=Symbol("_writing"),Ns=Symbol("_defaultFlag"),Un=Symbol("_errored"),Cc=class extends jn{[Un]=!1;[de];[mt];[Ga];[jt]=!1;[Ha];[di];[_n];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[Un]=!1,this[de]=typeof e.fd=="number"?e.fd:void 0,this[mt]=t,this[Ga]=e.readSize||16*1024*1024,this[jt]=!1,this[Ha]=typeof e.size=="number"?e.size:1/0,this[di]=this[Ha],this[_n]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[de]=="number"?this[_r]():this[yn]()}get fd(){return this[de]}get path(){return this[mt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[yn](){et.open(this[mt],"r",(t,e)=>this[vr](t,e))}[vr](t,e){t?this[Er](t):(this[de]=e,this.emit("open",e),this[_r]())}[ac](){return Buffer.allocUnsafe(Math.min(this[Ga],this[di]))}[_r](){if(!this[jt]){this[jt]=!0;let t=this[ac]();if(t.length===0)return process.nextTick(()=>this[qa](null,0,t));et.read(this[de],t,0,t.length,null,(e,r,i)=>this[qa](e,r,i))}}[qa](t,e,r){this[jt]=!1,t?this[Er](t):this[oc](e,r)&&this[_r]()}[wt](){if(this[_n]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,et.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[Er](t){this[jt]=!0,this[wt](),this.emit("error",t)}[oc](t,e){let r=!1;return this[di]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[di]<=0)&&(r=!1,this[wt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[de]=="number"&&this[_r](),!1;case"error":return this[Un]?!1:(this[Un]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Am=class extends Cc{[yn](){let t=!0;try{this[vr](null,et.openSync(this[mt],"r")),t=!1}finally{t&&this[wt]()}}[_r](){let t=!0;try{if(!this[jt]){this[jt]=!0;do{let e=this[ac](),r=e.length===0?0:et.readSync(this[de],e,0,e.length,null);if(!this[oc](r,e))break}while(!0);this[jt]=!1}t=!1}finally{t&&this[wt]()}}[wt](){if(this[_n]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,et.closeSync(t),this.emit("close")}}},Zs=class extends fm{readable=!1;writable=!0;[Un]=!1;[On]=!1;[ci]=!1;[It]=[];[Ss]=!1;[mt];[_i];[_n];[de];[Ns];[Wt];[Fa]=!1;[hn];constructor(t,e){e=e||{},super(e),this[mt]=t,this[de]=typeof e.fd=="number"?e.fd:void 0,this[_i]=e.mode===void 0?438:e.mode,this[hn]=typeof e.start=="number"?e.start:void 0,this[_n]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[hn]!==void 0?"r+":"w";this[Ns]=e.flags===void 0,this[Wt]=e.flags===void 0?r:e.flags,this[de]===void 0&&this[yn]()}emit(t,...e){if(t==="error"){if(this[Un])return!1;this[Un]=!0}return super.emit(t,...e)}get fd(){return this[de]}get path(){return this[mt]}[Er](t){this[wt](),this[On]=!0,this.emit("error",t)}[yn](){et.open(this[mt],this[Wt],this[_i],(t,e)=>this[vr](t,e))}[vr](t,e){this[Ns]&&this[Wt]==="r+"&&t&&t.code==="ENOENT"?(this[Wt]="w",this[yn]()):t?this[Er](t):(this[de]=e,this.emit("open",e),this[On]||this[Ua]())}end(t,e){return t&&this.write(t,e),this[ci]=!0,!this[On]&&!this[It].length&&typeof this[de]=="number"&&this[wr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[ci]?(this.emit("error",new Error("write() after end()")),!1):this[de]===void 0||this[On]||this[It].length?(this[It].push(t),this[Ss]=!0,!1):(this[On]=!0,this[Ls](t),!0)}[Ls](t){et.write(this[de],t,0,t.length,this[hn],(e,r)=>this[wr](e,r))}[wr](t,e){t?this[Er](t):(this[hn]!==void 0&&typeof e=="number"&&(this[hn]+=e),this[It].length?this[Ua]():(this[On]=!1,this[ci]&&!this[Fa]?(this[Fa]=!0,this[wt](),this.emit("finish")):this[Ss]&&(this[Ss]=!1,this.emit("drain"))))}[Ua](){if(this[It].length===0)this[ci]&&this[wr](null,0);else if(this[It].length===1)this[Ls](this[It].pop());else{let t=this[It];this[It]=[],Sm(this[de],t,this[hn],(e,r)=>this[wr](e,r))}}[wt](){if(this[_n]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,et.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Hl=class extends Zs{[yn](){let t;if(this[Ns]&&this[Wt]==="r+")try{t=et.openSync(this[mt],this[Wt],this[_i])}catch(e){if(e?.code==="ENOENT")return this[Wt]="w",this[yn]();throw e}else t=et.openSync(this[mt],this[Wt],this[_i]);this[vr](null,t)}[wt](){if(this[_n]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,et.closeSync(t),this.emit("close")}}[Ls](t){let e=!0;try{this[wr](null,et.writeSync(this[de],t,0,t.length,this[hn])),e=!1}finally{if(e)try{this[wt]()}catch{}}}},Cm=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),Rm=t=>!!t.sync&&!!t.file,km=t=>!t.sync&&!!t.file,Dm=t=>!!t.sync&&!t.file,Pm=t=>!t.sync&&!t.file,Om=t=>!!t.file,Lm=t=>Cm.get(t)||t,Rc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=Lm(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ci=(t,e,r,i,o)=>Object.assign((c=[],u,f)=>{Array.isArray(c)&&(u=c,c={}),typeof u=="function"&&(f=u,u=void 0),u=u?Array.from(u):[];let x=Rc(c);if(o?.(x,u),Rm(x)){if(typeof f=="function")throw new TypeError("callback not supported for sync tar functions");return t(x,u)}else if(km(x)){let p=e(x,u);return f?p.then(()=>f(),f):p}else if(Dm(x)){if(typeof f=="function")throw new TypeError("callback not supported for sync tar functions");return r(x,u)}else if(Pm(x)){if(typeof f=="function")throw new TypeError("callback only supported with file option");return i(x,u)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),Bm=Mm.constants||{ZLIB_VERNUM:4736},kt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},Bm)),zm=qn.concat,fl=Object.getOwnPropertyDescriptor(qn,"concat"),Fm=t=>t,ja=fl?.writable===!0||fl?.set!==void 0?t=>{qn.concat=t?Fm:zm}:t=>{},Gn=Symbol("_superWrite"),As=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"}},Wa=Symbol("flushFlag"),kc=class extends jn{#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 ll[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new ll[e](t)}catch(r){throw new As(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 As(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return cc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(qn.alloc(0),{[Wa]: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}[Gn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=qn.from(t,e)),this.#e)return;cc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},ja(!0);let u;try{let x=typeof t[Wa]=="number"?t[Wa]:this.#r;u=this.#t._processChunk(t,x),ja(!1)}catch(x){ja(!1),this.#o(new As(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 As(x,this.write)));let f;if(u)if(Array.isArray(u)&&u.length>0){let x=u[0];f=this[Gn](qn.from(x));for(let p=1;p<u.length;p++)f=this[Gn](u[p])}else f=this[Gn](qn.from(u));return r&&r(),f}},Wl=class extends kc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||kt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||kt.Z_FINISH,t.fullFlushFlag=kt.Z_FULL_FLUSH,super(t,e),this.#e=t.level,this.#n=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==t||this.#n!==e){this.flush(kt.Z_SYNC_FLUSH),cc(this.handle,"zlib binding closed");let r=this.handle.flush;this.handle.flush=(i,o)=>{typeof i=="function"&&(o=i,i=this.flushFlag),this.flush(i),o?.()};try{this.handle.params(t,e)}finally{this.handle.flush=r}this.handle&&(this.#e=t,this.#n=e)}}}},Um=class extends Wl{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Gn](t){return this.#e?(this.#e=!1,t[9]=255,super[Gn](t)):super[Gn](t)}},qm=class extends Wl{constructor(t){super(t,"Unzip")}},Kl=class extends kc{constructor(t,e){t=t||{},t.flush=t.flush||kt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||kt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=kt.BROTLI_OPERATION_FLUSH,super(t,e)}},Gm=class extends Kl{constructor(t){super(t,"BrotliCompress")}},Hm=class extends Kl{constructor(t){super(t,"BrotliDecompress")}},$l=class extends kc{constructor(t,e){t=t||{},t.flush=t.flush||kt.ZSTD_e_continue,t.finishFlush=t.finishFlush||kt.ZSTD_e_end,t.fullFlushFlag=kt.ZSTD_e_flush,super(t,e)}},jm=class extends $l{constructor(t){super(t,"ZstdCompress")}},Wm=class extends $l{constructor(t){super(t,"ZstdDecompress")}},Km=(t,e)=>{if(Number.isSafeInteger(t))t<0?Vm(t,e):$m(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},$m=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},Vm=(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]=Vl(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Yl(o))}},Ym=t=>{let e=t[0],r=e===128?Jm(t.subarray(1,t.length)):e===255?Zm(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},Zm=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),u;i?u=Vl(c):c===0?u=c:(i=!0,u=Yl(c)),u!==0&&(r-=u*Math.pow(256,e-o-1))}return r},Jm=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},Vl=t=>(255^t)&255,Yl=t=>(255^t)+1&255,Xm={};lm(Xm,{code:()=>Dc,isCode:()=>Ms,isName:()=>Qm,name:()=>Js,normalFsTypes:()=>Zl});var Ms=t=>Js.has(t),Qm=t=>Dc.has(t),Zl=new Set(["0","","1","2","3","4","5","6","7","D"]),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"]]),Dc=new Map(Array.from(Js).map(t=>[t[1],t[0]])),Hn=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");let o=Ln(t,e+156,1),c=Zl.has(o),u=c?r:void 0,f=c?i:void 0;if(this.path=u?.path??Ln(t,e,100),this.mode=u?.mode??f?.mode??pn(t,e+100,8),this.uid=u?.uid??f?.uid??pn(t,e+108,8),this.gid=u?.gid??f?.gid??pn(t,e+116,8),this.size=u?.size??f?.size??pn(t,e+124,12),this.mtime=u?.mtime??f?.mtime??Ka(t,e+136,12),this.cksum=pn(t,e+148,12),f&&this.#n(f,!0),u&&this.#n(u),Ms(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Ln(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=u?.uname??f?.uname??Ln(t,e+265,32),this.gname=u?.gname??f?.gname??Ln(t,e+297,32),this.devmaj=u?.devmaj??f?.devmaj??pn(t,e+329,8)??0,this.devmin=u?.devmin??f?.devmin??pn(t,e+337,8)??0,t[e+475]!==0){let p=Ln(t,e+345,155);this.path=p+"/"+this.path}else{let p=Ln(t,e+345,130);p&&(this.path=p+"/"+this.path),this.atime=r?.atime??i?.atime??Ka(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Ka(t,e+488,12)}let x=256;for(let p=e;p<e+148;p++)x+=t[p];for(let p=e+156;p<e+512;p++)x+=t[p];this.cksumValid=x===this.cksum,this.cksum===void 0&&x===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=ew(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Nn(t,e,100,o)||this.needPax,this.needPax=gn(t,e+100,8,this.mode)||this.needPax,this.needPax=gn(t,e+108,8,this.uid)||this.needPax,this.needPax=gn(t,e+116,8,this.gid)||this.needPax,this.needPax=gn(t,e+124,12,this.size)||this.needPax,this.needPax=$a(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Nn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Nn(t,e+265,32,this.uname)||this.needPax,this.needPax=Nn(t,e+297,32,this.gname)||this.needPax,this.needPax=gn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=gn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Nn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=Nn(t,e+345,155,c)||this.needPax:(this.needPax=Nn(t,e+345,130,c)||this.needPax,this.needPax=$a(t,e+476,12,this.atime)||this.needPax,this.needPax=$a(t,e+488,12,this.ctime)||this.needPax);let u=256;for(let f=e;f<e+148;f++)u+=t[f];for(let f=e+156;f<e+512;f++)u+=t[f];return this.cksum=u,gn(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(Dc.get(t));if(Ms(e)||e==="Unsupported")this.#e=e;else if(Ms(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},ew=(t,e)=>{let r=t,i="",o,c=xr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=xr.dirname(r),r=xr.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=xr.join(xr.basename(i),r),i=xr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Ln=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Ka=(t,e,r)=>tw(pn(t,e,r)),tw=t=>t===void 0?void 0:new Date(t*1e3),pn=(t,e,r)=>Number(t[e])&128?Ym(t.subarray(e,e+r)):rw(t,e,r),nw=t=>isNaN(t)?void 0:t,rw=(t,e,r)=>nw(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),iw={12:8589934591,8:2097151},gn=(t,e,r,i)=>i===void 0?!1:i>iw[r]||i<0?(Km(i,t.subarray(e,e+r)),!0):(sw(t,e,r,i),!1),sw=(t,e,r,i)=>t.write(ow(i,r),e,r,"ascii"),ow=(t,e)=>aw(Math.floor(t).toString(8),e),aw=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",$a=(t,e,r,i)=>i===void 0?!1:gn(t,e,r,i.getTime()/1e3),cw=new Array(156).join("\0"),Nn=(t,e,r,i)=>i===void 0?!1:(t.write(i+cw,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),Ws=class Jl{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 Hn({path:("PaxHeader/"+dw(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),u=Math.floor(Math.log(c)/Math.log(10))+1;return c+u>=Math.pow(10,u)&&(u+=1),u+c+o}static parse(e,r,i=!1){return new Jl(uw(lw(e),r),i)}},uw=(t,e)=>e?Object.assign({},e,t):t,lw=t=>t.replace(/\n$/,"").split(`
91
- `).reduce(fw,Object.create(null)),fw=(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"),u=i.join("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(u)*1e3):/^[0-9]+$/.test(u)?+u:u,t},xw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,J=xw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),hw=class extends jn{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,r){switch(super({}),this.pause(),this.extended=e,this.globalExtended=r,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=J(t.path),this.mode=t.mode,this.mode&&(this.mode=this.mode&4095),this.uid=t.uid,this.gid=t.gid,this.uname=t.uname,this.gname=t.gname,this.size=this.remain,this.mtime=t.mtime,this.atime=t.atime,this.ctime=t.ctime,this.linkpath=t.linkpath?J(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#e(e),r&&this.#e(r,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let r=this.remain,i=this.blockRemain;return this.remain=Math.max(0,r-e),this.blockRemain=Math.max(0,i-e),this.ignore?!0:r>=e?super.write(t):super.write(t.subarray(0,r))}#e(t,e=!1){t.path&&(t.path=J(t.path)),t.linkpath&&(t.linkpath=J(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},Xs=(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))},pw=1024*1024,dc=Buffer.from([31,139]),uc=Buffer.from([40,181,47,253]),gw=Math.max(dc.length,uc.length),ct=Symbol("state"),Mn=Symbol("writeEntry"),Gt=Symbol("readEntry"),Va=Symbol("nextEntry"),xl=Symbol("processEntry"),Tt=Symbol("extendedHeader"),ui=Symbol("globalExtendedHeader"),un=Symbol("meta"),hl=Symbol("emitMeta"),pe=Symbol("buffer"),Ht=Symbol("queue"),ln=Symbol("ended"),Ya=Symbol("emittedEnd"),Bn=Symbol("emit"),Ce=Symbol("unzip"),Is=Symbol("consumeChunk"),Ts=Symbol("consumeChunkSub"),Za=Symbol("consumeBody"),pl=Symbol("consumeMeta"),gl=Symbol("consumeHeader"),li=Symbol("consuming"),Ja=Symbol("bufferConcat"),Cs=Symbol("maybeEnd"),hr=Symbol("writing"),fn=Symbol("aborted"),Rs=Symbol("onDone"),zn=Symbol("sawValidEntry"),ks=Symbol("sawNullBlock"),Ds=Symbol("sawEOF"),ml=Symbol("closeStream"),mw=()=>!0,Ti=class extends Nm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Ht]=[];[pe];[Gt];[Mn];[ct]="begin";[un]="";[Tt];[ui];[ln]=!1;[Ce];[fn]=!1;[zn];[ks]=!1;[Ds]=!1;[hr]=!1;[li]=!1;[Ya]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Rs,()=>{(this[ct]==="begin"||this[zn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Rs,t.ondone):this.on(Rs,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||pw,this.filter=typeof t.filter=="function"?t.filter:mw;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[ml]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){Xs(this,t,e,r)}[gl](t,e){this[zn]===void 0&&(this[zn]=!1);let r;try{r=new Hn(t,e,this[Tt],this[ui])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[ks]?(this[Ds]=!0,this[ct]==="begin"&&(this[ct]="header"),this[Bn]("eof")):(this[ks]=!0,this[Bn]("nullBlock"));else if(this[ks]=!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[Mn]=new hw(r,this[Tt],this[ui]);if(!this[zn])if(o.remain){let c=()=>{o.invalid||(this[zn]=!0)};o.on("end",c)}else this[zn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Bn]("ignoredEntry",o),this[ct]="ignore",o.resume()):o.size>0&&(this[un]="",o.on("data",c=>this[un]+=c),this[ct]="meta"):(this[Tt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Bn]("ignoredEntry",o),this[ct]=o.remain?"ignore":"header",o.resume()):(o.remain?this[ct]="body":(this[ct]="header",o.end()),this[Gt]?this[Ht].push(o):(this[Ht].push(o),this[Va]())))}}}[ml](){queueMicrotask(()=>this.emit("close"))}[xl](t){let e=!0;if(!t)this[Gt]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[Gt]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Va]()),e=!1);return e}[Va](){do;while(this[xl](this[Ht].shift()));if(this[Ht].length===0){let t=this[Gt];!t||t.flowing||t.size===t.remain?this[hr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Za](t,e){let r=this[Mn];if(!r)throw new Error("attempt to consume body without entry??");let i=r.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return r.write(o),r.blockRemain||(this[ct]="header",this[Mn]=void 0,r.end()),o.length}[pl](t,e){let r=this[Mn],i=this[Za](t,e);return!this[Mn]&&r&&this[hl](r),i}[Bn](t,e,r){this[Ht].length===0&&!this[Gt]?this.emit(t,e,r):this[Ht].push([t,e,r])}[hl](t){switch(this[Bn]("meta",this[un]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Tt]=Ws.parse(this[un],this[Tt],!1);break;case"GlobalExtendedHeader":this[ui]=Ws.parse(this[un],this[ui],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Tt]??Object.create(null);this[Tt]=e,e.path=this[un].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Tt]||Object.create(null);this[Tt]=e,e.linkpath=this[un].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[fn]=!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[fn])return r?.(),!1;if((this[Ce]===void 0||this.brotli===void 0&&this[Ce]===!1)&&t){if(this[pe]&&(t=Buffer.concat([this[pe],t]),this[pe]=void 0),t.length<gw)return this[pe]=t,r?.(),!0;for(let u=0;this[Ce]===void 0&&u<dc.length;u++)t[u]!==dc[u]&&(this[Ce]=!1);let o=!1;if(this[Ce]===!1&&this.zstd!==!1){o=!0;for(let u=0;u<uc.length;u++)if(t[u]!==uc[u]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Ce]===!1&&c)if(t.length<512)if(this[ln])this.brotli=!0;else return this[pe]=t,r?.(),!0;else try{new Hn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Ce]===void 0||this[Ce]===!1&&(this.brotli||o)){let u=this[ln];this[ln]=!1,this[Ce]=this[Ce]===void 0?new qm({}):o?new Wm({}):new Hm({}),this[Ce].on("data",x=>this[Is](x)),this[Ce].on("error",x=>this.abort(x)),this[Ce].on("end",()=>{this[ln]=!0,this[Is]()}),this[hr]=!0;let f=!!this[Ce][u?"end":"write"](t);return this[hr]=!1,r?.(),f}}this[hr]=!0,this[Ce]?this[Ce].write(t):this[Is](t),this[hr]=!1;let i=this[Ht].length>0?!1:this[Gt]?this[Gt].flowing:!0;return!i&&this[Ht].length===0&&this[Gt]?.once("drain",()=>this.emit("drain")),r?.(),i}[Ja](t){t&&!this[fn]&&(this[pe]=this[pe]?Buffer.concat([this[pe],t]):t)}[Cs](){if(this[ln]&&!this[Ya]&&!this[fn]&&!this[li]){this[Ya]=!0;let t=this[Mn];if(t&&t.blockRemain){let e=this[pe]?this[pe].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[pe]&&t.write(this[pe]),t.end()}this[Bn](Rs)}}[Is](t){if(this[li]&&t)this[Ja](t);else if(!t&&!this[pe])this[Cs]();else if(t){if(this[li]=!0,this[pe]){this[Ja](t);let e=this[pe];this[pe]=void 0,this[Ts](e)}else this[Ts](t);for(;this[pe]&&this[pe]?.length>=512&&!this[fn]&&!this[Ds];){let e=this[pe];this[pe]=void 0,this[Ts](e)}this[li]=!1}(!this[pe]||this[ln])&&this[Cs]()}[Ts](t){let e=0,r=t.length;for(;e+512<=r&&!this[fn]&&!this[Ds];)switch(this[ct]){case"begin":case"header":this[gl](t,e),e+=512;break;case"ignore":case"body":e+=this[Za](t,e);break;case"meta":e+=this[pl](t,e);break;default:throw new Error("invalid state: "+this[ct])}e<r&&(this[pe]=this[pe]?Buffer.concat([t.subarray(e),this[pe]]):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[fn]||(this[Ce]?(t&&this[Ce].write(t),this[Ce].end()):(this[ln]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Cs]())),this}},yi=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)},ww=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},Xl=(t,e)=>{let r=new Map(e.map(c=>[yi(c),!0])),i=t.filter,o=(c,u="")=>{let f=u||Tm(c).root||".",x;if(c===f)x=!1;else{let p=r.get(c);x=p!==void 0?p:o(Im(c),f)}return r.set(c,x),x};t.filter=i?(c,u)=>i(c,u)&&o(yi(c)):c=>o(yi(c))},_w=t=>{let e=new Ti(t),r=t.file,i;try{i=yr.openSync(r,"r");let o=yr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let u=Buffer.allocUnsafe(o.size),f=yr.readSync(i,u,0,o.size,0);e.end(f===u.byteLength?u:u.subarray(0,f))}else{let u=0,f=Buffer.allocUnsafe(c);for(;u<o.size;){let x=yr.readSync(i,f,0,c,u);if(x===0)break;u+=x,e.write(f.subarray(0,x))}e.end()}}finally{if(typeof i=="number")try{yr.closeSync(i)}catch{}}},yw=(t,e)=>{let r=new Ti(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,u)=>{r.on("error",u),r.on("end",c),yr.stat(o,(f,x)=>{if(f)u(f);else{let p=new Cc(o,{readSize:i,size:x.size});p.on("error",u),p.pipe(r)}})})},Sr=Ci(_w,yw,t=>new Ti(t),t=>new Ti(t),(t,e)=>{e?.length&&Xl(t,e),t.noResume||ww(t)}),Ql=(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:Ew,parse:_l}=bw,Pc=t=>{let e="",r=_l(t);for(;Ew(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=_l(t)}return[e,t]},Qs=["|","<",">","?",":"],Oc=Qs.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),vw=new Map(Qs.map((t,e)=>[t,Oc[e]])),Sw=new Map(Oc.map((t,e)=>[t,Qs[e]])),yl=t=>Qs.reduce((e,r)=>e.split(r).join(vw.get(r)),t),Aw=t=>Oc.reduce((e,r)=>e.split(r).join(Sw.get(r)),t),ef=(t,e)=>e?(t=J(t).replace(/^\.(\/|$)/,""),yi(e)+"/"+t):J(t),Iw=16*1024*1024,bl=Symbol("process"),El=Symbol("file"),vl=Symbol("directory"),lc=Symbol("symlink"),Sl=Symbol("hardlink"),fi=Symbol("header"),Bs=Symbol("read"),fc=Symbol("lstat"),zs=Symbol("onlstat"),xc=Symbol("onread"),hc=Symbol("onreadlink"),pc=Symbol("openfile"),gc=Symbol("onopenfile"),mn=Symbol("close"),$s=Symbol("mode"),mc=Symbol("awaitDrain"),Xa=Symbol("ondrain"),Rt=Symbol("prefix"),tf=class extends jn{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=Rc(e);super(),this.path=J(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||Iw,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=J(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?J(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,u]=Pc(this.path);c&&typeof u=="string"&&(this.path=u,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Aw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=J(r.absolute||wl.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[zs](o):this[fc]()}warn(t,e,r={}){return Xs(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[fc](){Ct.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[zs](e)})}[zs](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=Rw(t),this.emit("stat",t),this[bl]()}[bl](){switch(this.type){case"File":return this[El]();case"Directory":return this[vl]();case"SymbolicLink":return this[lc]();default:return this.end()}}[$s](t){return Ql(t,this.type==="Directory",this.portable)}[Rt](t){return ef(t,this.prefix)}[fi](){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 Hn({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this[$s](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 Ws({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)}[vl](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[fi](),this.end()}[lc](){Ct.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[hc](e)})}[hc](t){this.linkpath=J(t),this[fi](),this.end()}[Sl](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=J(wl.relative(this.cwd,t)),this.stat.size=0,this[fi](),this.end()}[El](){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[Sl](e);this.linkCache.set(t,this.absolute)}if(this[fi](),this.stat.size===0)return this.end();this[pc]()}[pc](){Ct.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[gc](e)})}[gc](t){if(this.fd=t,this.#e)return this[mn]();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[Bs]()}[Bs](){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,u)=>{if(c)return this[mn](()=>this.emit("error",c));this[xc](u)})}[mn](t=()=>{}){this.fd!==void 0&&Ct.close(this.fd,t)}[xc](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[mn](()=>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[mn](()=>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[Xa]():this[mc](()=>this[Xa]())}[mc](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)}[Xa](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[mn](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[Bs]()}},Tw=class extends tf{sync=!0;[fc](){this[zs](Ct.lstatSync(this.absolute))}[lc](){this[hc](Ct.readlinkSync(this.absolute))}[pc](){this[gc](Ct.openSync(this.absolute,"r"))}[Bs](){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 u=Ct.readSync(e,r,i,o,c);this[xc](u),t=!1}finally{if(t)try{this[mn](()=>{})}catch{}}}[mc](t){t()}[mn](t=()=>{}){this.fd!==void 0&&Ct.closeSync(this.fd),t()}},Cw=class extends jn{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 Xs(this,t,e,r)}constructor(t,e={}){let r=Rc(e);super(),this.preservePaths=!!r.preservePaths,this.portable=!!r.portable,this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.onWriteEntry=r.onWriteEntry,this.readEntry=t;let{type:i}=t;if(i==="Unsupported")throw new Error("writing entry that should be ignored");this.type=i,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=r.prefix,this.path=J(t.path),this.mode=t.mode!==void 0?this[$s](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?J(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[u,f]=Pc(this.path);u&&typeof f=="string"&&(this.path=f,o=u)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Hn({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 Ws({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 ef(t,this.prefix)}[$s](t){return Ql(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}},Rw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",kw=class br{tail;head;length=0;static create(e=[]){return new br(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++)Pw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)Ow(this,e[r]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,r=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,r.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,r=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,r.list=void 0,this.length--,e}forEach(e,r){r=r||this;for(let i=this.head,o=0;i;o++)e.call(r,i.value,o,this),i=i.next}forEachReverse(e,r){r=r||this;for(let i=this.tail,o=this.length-1;i;o--)e.call(r,i.value,o,this),i=i.prev}get(e){let r=0,i=this.head;for(;i&&r<e;r++)i=i.next;if(r===e&&i)return i.value}getReverse(e){let r=0,i=this.tail;for(;i&&r<e;r++)i=i.prev;if(r===e&&i)return i.value}map(e,r){r=r||this;let i=new br;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 br;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 br;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 br;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 u=0;o&&u<e;u++)o=o.next;let c=[];for(let u=0;o&&u<r;u++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let u of i)o=Dw(this,o,u);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 Dw(t,e,r){let i=e,o=e?e.next:t.head,c=new Lc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function Pw(t,e){t.tail=new Lc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function Ow(t,e){t.head=new Lc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Lc=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}},Il=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Tl=Buffer.alloc(1024),Fs=Symbol("onStat"),xi=Symbol("ended"),pt=Symbol("queue"),hi=Symbol("pendingLinks"),xn=Symbol("current"),Fn=Symbol("process"),pi=Symbol("processing"),Ps=Symbol("processJob"),gt=Symbol("jobs"),Qa=Symbol("jobDone"),Us=Symbol("addFSEntry"),Cl=Symbol("addTarEntry"),wc=Symbol("stat"),_c=Symbol("readdir"),qs=Symbol("onreaddir"),Gs=Symbol("pipe"),Rl=Symbol("entry"),ec=Symbol("entryOpt"),Hs=Symbol("writeEntryClass"),nf=Symbol("write"),tc=Symbol("ondrain"),eo=class extends jn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Hs];onWriteEntry;[pt];[hi]=new Map;[gt]=0;[pi]=!1;[xi]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=J(t.prefix||""),this.linkCache=t.linkCache||new Map,this.statCache=t.statCache||new Map,this.readdirCache=t.readdirCache||new Map,this.onWriteEntry=t.onWriteEntry,this[Hs]=tf,typeof t.onwarn=="function"&&this.on("warn",t.onwarn),this.portable=!!t.portable,t.gzip||t.brotli||t.zstd){if((t.gzip?1:0)+(t.brotli?1:0)+(t.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(t.gzip&&(typeof t.gzip!="object"&&(t.gzip={}),this.portable&&(t.gzip.portable=!0),this.zip=new Um(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new Gm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new jm(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[tc]()),this.on("resume",()=>e.resume())}else this.on("drain",this[tc]);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[pt]=new kw,this[gt]=0,this.jobs=Number(t.jobs)||4,this[pi]=!1,this[xi]=!1}[nf](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[xi]=!0,this[Fn](),r&&r(),this}write(t){if(this[xi])throw new Error("write after end");return typeof t=="string"?this[Us](t):this[Cl](t),this.flowing}[Cl](t){let e=J(Al.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Il(t.path,e);r.entry=new Cw(t,this[ec](r)),r.entry.on("end",()=>this[Qa](r)),this[gt]+=1,this[pt].push(r)}this[Fn]()}[Us](t){let e=J(Al.resolve(this.cwd,t));this[pt].push(new Il(t,e)),this[Fn]()}[wc](t){t.pending=!0,this[gt]+=1;let e=this.follow?"stat":"lstat";Ks[e](t.absolute,(r,i)=>{t.pending=!1,this[gt]-=1,r?this.emit("error",r):this[Fs](t,i)})}[Fs](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[xn])this[Ps](t);else{let r=`${e.dev}:${e.ino}`,i=this[hi].get(r);i?i.push(t):this[hi].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Fn]()}[_c](t){t.pending=!0,this[gt]+=1,Ks.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[gt]-=1,e)return this.emit("error",e);this[qs](t,r)})}[qs](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Fn]()}[Fn](){if(!this[pi]){this[pi]=!0;for(let t=this[pt].head;t&&this[gt]<this.jobs;t=t.next)if(this[Ps](t.value),t.value.ignore){let e=t.next;this[pt].removeNode(t),t.next=e}this[pi]=!1,this[xi]&&this[pt].length===0&&this[gt]===0&&(this.zip?this.zip.end(Tl):(super.write(Tl),super.end()))}}get[xn](){return this[pt]&&this[pt].head&&this[pt].head.value}[Qa](t){this[pt].shift(),this[gt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[hi].get(r);if(i){this[hi].delete(r);for(let o of i)o.pending=!1,this[Ps](o)}}this[Fn]()}[Ps](t){if(t.pending&&t.pendingLink&&t===this[xn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[xn]&&!t.piped&&this[Gs](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Fs](t,e):this[wc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[qs](t,e):this[_c](t),!t.readdir)return}if(t.entry=this[Rl](t),!t.entry){t.ignore=!0;return}t===this[xn]&&!t.piped&&this[Gs](t)}}}[ec](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}}[Rl](t){this[gt]+=1;try{return new this[Hs](t.path,this[ec](t)).on("end",()=>this[Qa](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[tc](){this[xn]&&this[xn].entry&&this[xn].entry.resume()}[Gs](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Us](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={}){Xs(this,t,e,r)}},Nc=class extends eo{sync=!0;constructor(t){super(t),this[Hs]=Tw}pause(){}resume(){}[wc](t){let e=this.follow?"statSync":"lstatSync";this[Fs](t,Ks[e](t.absolute))}[_c](t){this[qs](t,Ks.readdirSync(t.absolute))}[Gs](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Us](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[nf](i)})}},Lw=(t,e)=>{let r=new Nc(t),i=new Hl(t.file,{mode:t.mode||438});r.pipe(i),rf(r,e)},Nw=(t,e)=>{let r=new eo(t),i=new Zs(t.file,{mode:t.mode||438});r.pipe(i);let o=new Promise((c,u)=>{i.on("error",u),i.on("close",c),r.on("error",u)});return sf(r,e).catch(c=>r.emit("error",c)),o},rf=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Sr({file:jl.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},sf=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Sr({file:jl.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},Mw=(t,e)=>{let r=new Nc(t);return rf(r,e),r},Bw=(t,e)=>{let r=new eo(t);return sf(r,e).catch(i=>r.emit("error",i)),r},sA=Ci(Lw,Nw,Mw,Bw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),Fw=process.env.__FAKE_PLATFORM__||process.platform,df=Fw==="win32",{O_CREAT:uf,O_NOFOLLOW:kl,O_TRUNC:lf,O_WRONLY:ff}=cf.constants,xf=Number(process.env.__FAKE_FS_O_FILENAME__)||cf.constants.UV_FS_O_FILEMAP||0,Uw=df&&!!xf,qw=512*1024,Gw=xf|lf|uf|ff,Dl=!df&&typeof kl=="number"?kl|lf|uf|ff:null,hf=Dl!==null?()=>Dl:Uw?t=>t<qw?Gw:"w":()=>"w",yc=(t,e,r)=>{try{return to.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},Vs=(t,e,r,i)=>{to.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},Hw=(t,e,r,i,o)=>{if(e.isDirectory())pf(bi.resolve(t,e.name),r,i,c=>{if(c)return o(c);let u=bi.resolve(t,e.name);Vs(u,r,i,o)});else{let c=bi.resolve(t,e.name);Vs(c,r,i,o)}},pf=(t,e,r,i)=>{to.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 Vs(t,e,r,i);let u=c.length,f=null,x=p=>{if(!f){if(p)return i(f=p);if(--u===0)return Vs(t,e,r,i)}};for(let p of c)Hw(t,p,e,r,x)})},jw=(t,e,r,i)=>{e.isDirectory()&&gf(bi.resolve(t,e.name),r,i),yc(bi.resolve(t,e.name),r,i)},gf=(t,e,r)=>{let i;try{i=to.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return yc(t,e,r);throw c}for(let o of i)jw(t,o,e,r);return yc(t,e,r)},mf=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"}},no=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"}},Kw=(t,e)=>{st.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new mf(t,r?.code||"ENOTDIR")),e(r)})},$w=(t,e,r)=>{t=J(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,u=e.uid,f=e.gid,x=typeof u=="number"&&typeof f=="number"&&(u!==e.processUid||f!==e.processGid),p=e.preserve,m=e.unlink,_=J(e.cwd),S=(v,A)=>{v?r(v):A&&x?pf(A,u,f,I=>S(I)):c?st.chmod(t,o,r):r()};if(t===_)return Kw(t,S);if(p)return Ww.mkdir(t,{mode:o,recursive:!0}).then(v=>S(null,v??void 0),S);let y=J(Ys.relative(_,t)).split("/");bc(_,y,o,m,_,void 0,S)},bc=(t,e,r,i,o,c,u)=>{if(e.length===0)return u(null,c);let f=e.shift(),x=J(Ys.resolve(t+"/"+f));st.mkdir(x,r,wf(x,e,r,i,o,c,u))},wf=(t,e,r,i,o,c,u)=>f=>{f?st.lstat(t,(x,p)=>{if(x)x.path=x.path&&J(x.path),u(x);else if(p.isDirectory())bc(t,e,r,i,o,c,u);else if(i)st.unlink(t,m=>{if(m)return u(m);st.mkdir(t,r,wf(t,e,r,i,o,c,u))});else{if(p.isSymbolicLink())return u(new no(t,t+"/"+e.join("/")));u(f)}}):(c=c||t,bc(t,e,r,i,o,c,u))},Vw=t=>{let e=!1,r;try{e=st.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new mf(t,r??"ENOTDIR")}},Yw=(t,e)=>{t=J(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,u=e.gid,f=typeof c=="number"&&typeof u=="number"&&(c!==e.processUid||u!==e.processGid),x=e.preserve,p=e.unlink,m=J(e.cwd),_=v=>{v&&f&&gf(v,c,u),o&&st.chmodSync(t,i)};if(t===m)return Vw(m),_();if(x)return _(st.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=J(Ys.relative(m,t)).split("/"),y;for(let v=S.shift(),A=m;v&&(A+="/"+v);v=S.shift()){A=J(Ys.resolve(A));try{st.mkdirSync(A,i),y=y||A}catch{let I=st.lstatSync(A);if(I.isDirectory())continue;if(p){st.unlinkSync(A),st.mkdirSync(A,i),y=y||A;continue}else if(I.isSymbolicLink())return new no(A,A+"/"+S.join("/"))}}return _(y)},nc=Object.create(null),Pl=1e4,pr=new Set,Zw=t=>{pr.has(t)?pr.delete(t):nc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),pr.add(t);let e=nc[t],r=pr.size-Pl;if(r>Pl/10){for(let i of pr)if(pr.delete(i),delete nc[i],--r<=0)break}return e},Jw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Xw=Jw==="win32",Qw=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=_f(i,r)),e.push(r||"/"),e},[]),e_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=Xw?["win32 parallelization disabled"]:t.map(i=>yi(_f(Zw(i))));let r=new Set(t.map(i=>Qw(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 u=this.#e.get(c);if(!u||u?.[0]!==t)continue;let f=u[1];if(!f){this.#e.delete(c);continue}if(u.shift(),typeof f=="function")o.add(f);else for(let x of f)o.add(x)}for(let c of i){let u=this.#e.get(c),f=u?.[0];if(!(!u||!(f instanceof Set)))if(f.size===1&&u.length===1){this.#e.delete(c);continue}else if(f.size===1){u.shift();let x=u[0];typeof x=="function"&&o.add(x)}else f.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},t_=()=>process.umask(),Ol=Symbol("onEntry"),Ec=Symbol("checkFs"),Ll=Symbol("checkFs2"),vc=Symbol("isReusable"),dt=Symbol("makeFs"),Sc=Symbol("file"),Ac=Symbol("directory"),js=Symbol("link"),Nl=Symbol("symlink"),Ml=Symbol("hardlink"),wi=Symbol("ensureNoSymlink"),Bl=Symbol("unsupported"),zl=Symbol("checkPath"),rc=Symbol("stripAbsolutePath"),wn=Symbol("mkdir"),Ue=Symbol("onError"),Os=Symbol("pending"),Fl=Symbol("pend"),gr=Symbol("unpend"),ic=Symbol("ended"),sc=Symbol("maybeClose"),Ic=Symbol("skip"),Ei=Symbol("doChown"),vi=Symbol("uid"),Si=Symbol("gid"),Ai=Symbol("checkedCwd"),n_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ii=n_==="win32",r_=1024,i_=(t,e)=>{if(!Ii)return re.unlink(t,e);let r=t+".DELETE."+af(16).toString("hex");re.rename(t,r,i=>{if(i)return e(i);re.unlink(r,e)})},s_=t=>{if(!Ii)return re.unlinkSync(t);let e=t+".DELETE."+af(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},Ul=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Mc=class extends Ti{[ic]=!1;[Ai]=!1;[Os]=0;reservations=new e_;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[ic]=!0,this[sc]()},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:r_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Ii,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=J(Ne.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:t_():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[Ol](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[sc](){this[ic]&&this[Os]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[rc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Pc(r),u=c.replaceAll(/\\/g,"/").split("/");if(u.includes("..")||Ii&&/^[a-z]:\.\.$/i.test(u[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let f=Ne.posix.dirname(t.path),x=Ne.posix.normalize(Ne.posix.join(f,u.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}[zl](t){let e=J(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=J(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}r.splice(0,this.strip),t.path=r.join("/")}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[rc](t,"path")||!this[rc](t,"linkpath"))return!1;if(t.absolute=Ne.isAbsolute(t.path)?J(Ne.resolve(t.path)):J(Ne.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:J(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=Ne.win32.parse(String(t.absolute));t.absolute=i+yl(String(t.absolute).slice(i.length));let{root:o}=Ne.win32.parse(t.path);t.path=o+yl(t.path.slice(o.length))}return!0}[Ol](t){if(!this[zl](t))return t.resume();switch(zw.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[Ec](t);default:return this[Bl](t)}}[Ue](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[gr](),e.resume())}[wn](t,e,r){$w(J(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},r)}[Ei](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}[vi](t){return Ul(this.uid,t.uid,this.processUid)}[Si](t){return Ul(this.gid,t.gid,this.processGid)}[Sc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Zs(String(t.absolute),{flags:hf(t.size),mode:r,autoClose:!1});i.on("error",f=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[Ue](f,t),e()});let o=1,c=f=>{if(f){i.fd&&re.close(i.fd,()=>{}),this[Ue](f,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,x=>{x?this[Ue](x,t):this[gr](),e()})};i.on("finish",()=>{let f=String(t.absolute),x=i.fd;if(typeof x=="number"&&t.mtime&&!this.noMtime){o++;let p=t.atime||new Date,m=t.mtime;re.futimes(x,p,m,_=>_?re.utimes(f,p,m,S=>c(S&&_)):c())}if(typeof x=="number"&&this[Ei](t)){o++;let p=this[vi](t),m=this[Si](t);typeof p=="number"&&typeof m=="number"&&re.fchown(x,p,m,_=>_?re.chown(f,p,m,S=>c(S&&_)):c())}c()});let u=this.transform&&this.transform(t)||t;u!==t&&(u.on("error",f=>{this[Ue](f,t),e()}),t.pipe(u)),u.pipe(i)}[Ac](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[wn](String(t.absolute),r,i=>{if(i){this[Ue](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[gr](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[Ei](t)&&(o++,re.chown(String(t.absolute),Number(this[vi](t)),Number(this[Si](t)),c)),c()})}[Bl](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Nl](t,e){let r=J(Ne.relative(this.cwd,Ne.resolve(Ne.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[wi](t,this.cwd,r,()=>this[js](t,String(t.linkpath),"symlink",e),i=>{this[Ue](i,t),e()})}[Ml](t,e){let r=J(Ne.resolve(this.cwd,String(t.linkpath))),i=J(String(t.linkpath)).split("/");this[wi](t,this.cwd,i,()=>this[js](t,r,"link",e),o=>{this[Ue](o,t),e()})}[wi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let u=Ne.resolve(e,c);re.lstat(u,(f,x)=>{if(f)return i();if(x?.isSymbolicLink())return o(new no(u,Ne.resolve(u,r.join("/"))));this[wi](t,u,r,i,o)})}[Fl](){this[Os]++}[gr](){this[Os]--,this[sc]()}[Ic](t){this[gr](),t.resume()}[vc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Ii}[Ec](t){this[Fl]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Ll](t,r))}[Ll](t,e){let r=u=>{e(u)},i=()=>{this[wn](this.cwd,this.dmode,u=>{if(u){this[Ue](u,t),r();return}this[Ai]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let u=J(Ne.dirname(String(t.absolute)));if(u!==this.cwd)return this[wn](u,this.dmode,f=>{if(f){this[Ue](f,t),r();return}c()})}c()},c=()=>{re.lstat(String(t.absolute),(u,f)=>{if(f&&(this.keep||this.newer&&f.mtime>(t.mtime??f.mtime))){this[Ic](t),r();return}if(u||this[vc](t,f))return this[dt](null,t,r);if(f.isDirectory()){if(t.type==="Directory"){let x=this.chmod&&t.mode&&(f.mode&4095)!==t.mode,p=m=>this[dt](m??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[dt](x??null,t,r))}if(t.absolute===this.cwd)return this[dt](null,t,r);i_(String(t.absolute),x=>this[dt](x??null,t,r))})};this[Ai]?o():i()}[dt](t,e,r){if(t){this[Ue](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[Sc](e,r);case"Link":return this[Ml](e,r);case"SymbolicLink":return this[Nl](e,r);case"Directory":case"GNUDumpDir":return this[Ac](e,r)}}[js](t,e,r,i){re[r](e,String(t.absolute),o=>{o?this[Ue](o,t):(this[gr](),t.resume()),i()})}},gi=t=>{try{return[null,t()]}catch(e){return[e,null]}},yf=class extends Mc{sync=!0;[dt](t,e){return super[dt](t,e,()=>{})}[Ec](t){if(!this[Ai]){let o=this[wn](this.cwd,this.dmode);if(o)return this[Ue](o,t);this[Ai]=!0}if(t.absolute!==this.cwd){let o=J(Ne.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[wn](o,this.dmode);if(c)return this[Ue](c,t)}}let[e,r]=gi(()=>re.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Ic](t);if(e||this[vc](t,r))return this[dt](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[u]=c?gi(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[dt](u,t)}let[o]=gi(()=>re.rmdirSync(String(t.absolute)));this[dt](o,t)}let[i]=t.absolute===this.cwd?[]:gi(()=>s_(String(t.absolute)));this[dt](i,t)}[Sc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=u=>{let f;try{re.closeSync(o)}catch(x){f=x}(u||f)&&this[Ue](u||f,t),e()},o;try{o=re.openSync(String(t.absolute),hf(t.size),r)}catch(u){return i(u)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",u=>this[Ue](u,t)),t.pipe(c)),c.on("data",u=>{try{re.writeSync(o,u,0,u.length)}catch(f){i(f)}}),c.on("end",()=>{let u=null;if(t.mtime&&!this.noMtime){let f=t.atime||new Date,x=t.mtime;try{re.futimesSync(o,f,x)}catch(p){try{re.utimesSync(String(t.absolute),f,x)}catch{u=p}}}if(this[Ei](t)){let f=this[vi](t),x=this[Si](t);try{re.fchownSync(o,Number(f),Number(x))}catch(p){try{re.chownSync(String(t.absolute),Number(f),Number(x))}catch{u=u||p}}}i(u)})}[Ac](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[wn](String(t.absolute),r);if(i){this[Ue](i,t),e();return}if(t.mtime&&!this.noMtime)try{re.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[Ei](t))try{re.chownSync(String(t.absolute),Number(this[vi](t)),Number(this[Si](t)))}catch{}e(),t.resume()}[wn](t,e){try{return Yw(J(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(r){return r}}[wi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let u of r){c=Ne.resolve(c,u);let[f,x]=gi(()=>re.lstatSync(c));if(f)return i();if(x.isSymbolicLink())return o(new no(c,Ne.resolve(e,r.join("/"))))}i()}[js](t,e,r,i){let o=`${r}Sync`;try{re[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[Ue](c,t)}}},o_=t=>{let e=new yf(t),r=t.file,i=of.statSync(r),o=t.maxReadSize||16*1024*1024;new Am(r,{readSize:o,size:i.size}).pipe(e)},a_=(t,e)=>{let r=new Mc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,u)=>{r.on("error",u),r.on("close",c),of.stat(o,(f,x)=>{if(f)u(f);else{let p=new Cc(o,{readSize:i,size:x.size});p.on("error",u),p.pipe(r)}})})},bf=Ci(o_,a_,t=>new yf(t),t=>new Mc(t),(t,e)=>{e?.length&&Xl(t,e)}),c_=(t,e)=>{let r=new Nc(t),i=!0,o,c;try{try{o=it.openSync(t.file,"r+")}catch(x){if(x?.code==="ENOENT")o=it.openSync(t.file,"w+");else throw x}let u=it.fstatSync(o),f=Buffer.alloc(512);e:for(c=0;c<u.size;c+=512){for(let m=0,_=0;m<512;m+=_){if(_=it.readSync(o,f,m,f.length-m,c+m),c===0&&f[0]===31&&f[1]===139)throw new Error("cannot append to compressed archives");if(!_)break e}let x=new Hn(f);if(!x.cksumValid)break;let p=512*Math.ceil((x.size||0)/512);if(c+p+512>u.size)break;c+=p,t.mtimeCache&&x.mtime&&t.mtimeCache.set(String(x.path),x.mtime)}i=!1,d_(t,r,c,o,e)}finally{if(i)try{it.closeSync(o)}catch{}}},d_=(t,e,r,i,o)=>{let c=new Hl(t.file,{fd:i,start:r});e.pipe(c),l_(e,o)},u_=(t,e)=>{e=Array.from(e);let r=new eo(t),i=(o,c,u)=>{let f=(S,y)=>{S?it.close(o,v=>u(S)):u(null,y)},x=0;if(c===0)return f(null,0);let p=0,m=Buffer.alloc(512),_=(S,y)=>{if(S||y===void 0)return f(S);if(p+=y,p<512&&y)return it.read(o,m,p,m.length-p,x+p,_);if(x===0&&m[0]===31&&m[1]===139)return f(new Error("cannot append to compressed archives"));if(p<512)return f(null,x);let v=new Hn(m);if(!v.cksumValid)return f(null,x);let A=512*Math.ceil((v.size??0)/512);if(x+A+512>c||(x+=A+512,x>=c))return f(null,x);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),p=0,it.read(o,m,0,512,x,_)};it.read(o,m,0,512,x,_)};return new Promise((o,c)=>{r.on("error",c);let u="r+",f=(x,p)=>{if(x&&x.code==="ENOENT"&&u==="r+")return u="w+",it.open(t.file,u,f);if(x||!p)return c(x);it.fstat(p,(m,_)=>{if(m)return it.close(p,()=>c(m));i(p,_.size,(S,y)=>{if(S)return c(S);let v=new Zs(t.file,{fd:p,start:y});r.pipe(v),v.on("error",c),v.on("close",o),f_(r,e)})})};it.open(t.file,u,f)})},l_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Sr({file:Ef.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},f_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Sr({file:Ef.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},mi=Ci(c_,u_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!Om(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")}),yA=Ci(mi.syncFile,mi.asyncFile,mi.syncNoFile,mi.asyncNoFile,(t,e=[])=>{mi.validate?.(t,e),x_(t)}),x_=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))};an();var _t={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",UPGRADE:"_agent/upgrade",DELETE:"_agent/delete"};function ro(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function vf(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function io(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Sf(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function Af(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function Ar(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Kt();We();ne();Oe();We();function bn(t,e){if(ro(t)!=="cloud")throw new C("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Ri(t){return t.startsWith("http://")||t.startsWith("https://")}function so(t){return t.endsWith("/")?t.slice(0,-1):t}We();ne();var oo="1008033",Rf="1289";var kf="pbbp2",Df="https://www.coze.cn",Pf="/api/coze_claw/resource/get_frontier_key",b_="https://www.coze.cn",E_="wss://frontier.coze.cn";function ao(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??b_}function Of(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??E_}function Ir(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 Di(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var ki=q("handshake");async function Bc(t){let e=ao(t.endpoint),r=t.timeoutMs??1e4,i=`${so(e)}${Pf}?aid=${encodeURIComponent(oo)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...Ir(t.ppeOverride)},c=new AbortController,u=setTimeout(()=>c.abort(),r);ki.info("frontier key handshake",{base:e});try{let f=await fetch(i,{method:"GET",headers:o,signal:c.signal}),x=f.headers.get("x-tt-logid")??"",p=f.headers.get("x-tt-trace-id")??"";if(!f.ok){let v=await f.text().catch(()=>"");throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${f.status} logid=${x}: ${v.slice(0,200)}`)}let m=await f.json();if(m.code!==void 0&&m.code!==0)throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${m.code} msg=${m.msg??"-"} logid=${x}`);let _=m.data??{},S=typeof _.access_key=="string"&&_.access_key||typeof _.accessKey=="string"&&_.accessKey||void 0,y=typeof _.device_id=="string"&&_.device_id||typeof _.deviceId=="string"&&_.deviceId||void 0;if(!S||!y){let v=JSON.stringify(m).slice(0,500);throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${x}: ${v}`)}return ki.info("handshake ok",{remoteDeviceId:y,logid:x,traceId:p}),{accessKey:S,deviceId:y}}catch(f){if(f instanceof C)throw ki.error("handshake failed (bridge error)",{base:e,message:f.message,code:f.code}),f;if(f.name==="AbortError")throw ki.warn("handshake timeout",{base:e,timeoutMs:r}),new C("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:f});let x=f.cause;throw ki.error("handshake error",{base:e,message:f instanceof Error?f.message:String(f),errno:x?.code,syscall:x?.syscall,cause:String(f).slice(0,300)}),new C("UPSTREAM_HANDSHAKE_FAILED",String(f),{cause:f})}finally{clearTimeout(u)}}var zc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",yt="auto",Lf=15e4;function Nf(t){return{model:Fc(t.model)??yt,...t.modelToken?{modelToken:t.modelToken}:{}}}function Mf(t){return!t||t===yt}var v_=new Set(["auto","\u81EA\u52A8"]);function Fc(t){let e=t?.trim();if(e)return v_.has(e.toLowerCase())?yt:e}function Bf(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=zc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||yt;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,e.CLAUDE_CODE_ATTRIBUTION_HEADER="0",t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else Mf(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function zf(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||yt}"`):Mf(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="${zc}/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??Lf;e.push("-c",`model_context_window=${r}`)}return e}function Ff(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function Uc(t,e){let{ttEnv:r,usePpe:i}=Di(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Uf(t,e,r){if(!t.modelToken)return{};let i=Uc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,u])=>`${c}:${u}`).join(`
92
- `)}}function qc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function qf(t,e,r){if(!t.modelToken)return null;let i=t.model||yt,o=Uc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let u={baseUrl:`${zc}/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??Lf,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(u.headers=o),u}function Gf(t,e,r){if(!t.modelToken)return[];let i=Uc(e,r),o=[];for(let[c,u]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${u}"`);return o}var Ae=q("agent-handlers"),Hf=5*1024*1024,R_=1,k_=6,D_=new Set(["node_modules",".git",".coze","dist","build",".next"]),P_=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,O_=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,L_=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function N_(t){let e=t?.trim();return e?L_.test(e)||O_.test(e)?e:(Ae.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function M_(t){return new Promise((e,r)=>{let i=nt("npx",t,{detached:!0,stdio:"ignore",windowsHide:!0}),o=!1,c=u=>{o||(o=!0,u?r(u):e(i.pid??0))};i.once("spawn",()=>{i.unref(),c()}),i.once("error",u=>c(u))})}var co=class{constructor(e){this.opts=e}opts;async listSkills(e){bn(e._meta,"_agent/listSkills");let r=Ar(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Xe(r).workspace,c=i?.skills??[],u=[];for(let f of c){let x=Dt(o,f.relPath,"SKILL.md");await I_(x).then(m=>m.isFile()).catch(()=>!1)&&u.push(q_(f))}return{skills:u}}async addSkills(e){let r=Ar(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],u=new Map(c.map((x,p)=>[x.skillId,p])),f=[];for(let x of o){let p=await Vc({agentId:r,workspace:i.workspace,framework:i.framework,skill:x});Yc(c,u,p),f.push(x)}return await fs(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:f}}async removeSkills(e){bn(e._meta,"_agent/removeSkills");let r=Ar(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],u=[];for(let f of c){if(!o.has(f.skillId)){u.push(f);continue}let x=Dt(i.workspace,f.relPath);await A_(x,{recursive:!0,force:!0}),Ae.info("skill removed",{agentId:r,skillId:f.skillId,relPath:f.relPath})}return await fs(r,u),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 u=c.acpSessionId;if(u&&i.activeTriggers.has(u)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,Ae.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:u});continue}let x=c.downstream;c.downstream=void 0,Ae.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:u}),x.stop(r).catch(p=>Ae.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 Ae.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await Me(r);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Ae.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await cr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Ae.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 Qe(i),Ae.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async upgradeBridge(e){let r=e.agentId||e._meta?.cozeAgentId;if(!r)throw new C("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await Me(r))throw new C("AGENT_NOT_FOUND",`agent not found: ${r}`);let o=["-y"];e.registry&&Ri(e.registry)&&o.push(`--registry=${e.registry}`);let c=N_(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let u=e._meta?.cozeEnv;u&&P_.test(u)&&o.push("--env",u);let f=await M_(o);return Ae.info("_agent/upgrade: spawned bridge upgrade process",{agentId:r,pid:f,targetVersion:c,currentVersion:e.currentVersion??"",reason:e.reason??""}),{ok:!0,accepted:!0,pid:f,message:"bridge upgrade started"}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new C("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Me(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Qe(i),Ae.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}):(Ae.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(bn(e._meta,"_agent/switchModel"),!e.agentId)throw new C("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Fc(e.model)??yt,i=await Me(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 Qe(i),Ae.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Ae.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(u=>Ae.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(u)}));let c=[];for(let[u,f]of o.allSessionQueues())c.push(f.enqueue(async()=>{let x=o.sessions.get(u);x?.downstream&&(await x.downstream.stop(`switchModel: ${r}`).catch(()=>{}),x.downstream=void 0)}));return await Promise.all(c),Ae.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(bn(e._meta,_t.RESET),!e.agentId)throw new C("IPC_BAD_REQUEST",`${_t.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,_t.RESET),await this.runDetailSync(e.agentId,_t.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),Ae.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,u]of i.sessions)o.set(c,{modelToken:u.modelToken,tokenGeneratedAt:u.tokenGeneratedAt});await ni(e,o)}async clearPersistedAcpSessionIds(e){let r=await Me(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 Qe(r)}async repairAgent(e){if(bn(e._meta,_t.REPAIR),!e.agentId)throw new C("IPC_BAD_REQUEST",`${_t.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new C("IPC_BAD_REQUEST",`${_t.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){Ae.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,_t.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){Ae.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Ae.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){bn(e._meta,"_agent/getFileTree");let r=e._meta,i=Ar(r),o=await this.resolveWorkspace(i),c=e.filePath??"",u=this.safeJoin(o,c),f=await Gc(u).catch(()=>null);if(!f)throw new C("IPC_BAD_REQUEST",`path not found: ${c}`);if(f.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await ti(u,o))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let x=X_(e.depth);return f.isDirectory()?{tree:await J_(o,u,c,x)}:{tree:[{name:Q_(c),path:Zf(c||"."),isDir:!1,size:f.size,modifiedAt:Math.floor(f.mtimeMs)}]}}async getFileContent(e){bn(e._meta,"_agent/getFileContent");let r=Ar(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 Gc(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 ti(o,i))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Hf)throw new C("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Hf})`);let u=await jf(o);return u.includes(0)?{content:u.toString("base64"),encoding:"base64",size:c.size}:{content:u.toString("utf8"),encoding:"utf-8",size:c.size}}async resolveWorkspace(e){let r=this.opts.agents.get(e);return r?r.workspace:(await Me(e).catch(()=>null))?.workspace??Xe(e).workspace}safeJoin(e,r){let i=Wc(e,r||"."),o=$c(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Wf}`))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return Me(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 B_(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 z_(t){return t==="claude-code"?Dt(".claude","skills"):Dt(".agents","skills")}var F_=3e4,U_=50*1024*1024,Tr=3e4;async function Vc(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,u=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!u)throw new C("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let f=B_(o.skillName),x=z_(i),p=Dt(x,f),m=Dt(r,p);if(await Hc(m,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");Pi(S.length),await jc(Dt(m,"SKILL.md"),S,"utf8")}else{let S=await G_(o.downloadUrl);j_(S)?await V_(S,m):W_(S)?await K_(S,m):await jc(Dt(m,"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 Ae.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:p,source:c?"content":"downloadUrl"}),_}function Yc(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 q_(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 G_(t){if(!t)throw new C("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Pi(e);let r=H_(t);return Pi(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await jf(e);return Pi(r.length),r}if(Ri(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),F_);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 Pi(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 Pi(t){if(t>U_)throw new C("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function H_(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 j_(t){return t.length>=2&&t[0]===31&&t[1]===139}function W_(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 Kc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function K_(t,e){let r,i;try{r=new Vf.default(t),i=r.getEntries()}catch(u){throw new C("IPC_BAD_REQUEST",`zip parse failed: ${u.message}`,{cause:u})}for(let u of i){let f=u.entryName;if(!f||Kc(f))continue;if(f.startsWith("/")||/^[A-Za-z]:[\\/]/.test(f))throw new C("IPC_BAD_REQUEST",`zip entry absolute path: ${f}`);if(f.split(/[/\\]/).some(p=>p===".."))throw new C("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${f}`);let x=u.header.attr>>>16&61440;if(x!==0&&x!==32768&&x!==16384)throw new C("IPC_BAD_REQUEST",`zip entry kind 0x${x.toString(16)} not allowed (symlink/hardlink/special): ${f}`)}let o=$_(i),c=Wc(e);for(let u of i){if(Kc(u.entryName))continue;let f=u.entryName;if(o&&f.startsWith(o)&&(f=f.slice(o.length)),!f)continue;let x=Wc(e,f),p=$c(c,x);if(p.startsWith("..")||p==="..")throw new C("IPC_BAD_REQUEST",`zip entry escapes destDir: ${f}`);if(u.isDirectory){await Hc(x,{recursive:!0});continue}await Hc(T_(x),{recursive:!0});let m;try{m=u.getData()}catch(_){throw new C("IPC_BAD_REQUEST",`zip entry getData failed (${u.entryName}): ${_.message}`,{cause:_})}await jc(x,m)}}function $_(t){let e;for(let r of t){let i=r.entryName;if(!i||Kc(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 V_(t,e){await Y_(t);let r=bf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new C("IPC_BAD_REQUEST",`tar extract timeout (${Tr}ms)`))},Tr);try{await $f(Kf.from(t),r)}catch(c){throw c instanceof C?c:i?new C("IPC_BAD_REQUEST",`tar extract timeout (${Tr}ms)`):new C("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function Y_(t){let e=[],r=Sr({onReadEntry:c=>{let u=c.path,f=c.type;if(f!=="File"&&f!=="Directory"){e.push(`tar entry kind '${f}' not allowed (symlink/hardlink/special): ${u.slice(0,100)}`);return}if(u.startsWith("/")||u.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(u)){e.push(`tar entry absolute path: ${u}`);return}u.split(/[/\\]/).some(p=>p==="..")&&e.push(`tar entry contains '..': ${u}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new C("IPC_BAD_REQUEST",`tar list timeout (${Tr}ms)`))},Tr);try{await $f(Kf.from(t),r)}catch(c){throw i?new C("IPC_BAD_REQUEST",`tar list timeout (${Tr}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 Z_=5e3;async function J_(t,e,r,i){return Yf(t,e,r,i,{count:0})}async function Yf(t,e,r,i,o){if(i<=0)return[];let c;try{c=await S_(e,{withFileTypes:!0})}catch{return[]}let u=[];for(let f of c){if(D_.has(f.name)||f.isSymbolicLink())continue;if(o.count>=Z_){u.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let x=Dt(e,f.name),p=C_(Dt(r,f.name)),m=null;try{m=await Gc(x)}catch{continue}if(m.isSymbolicLink())continue;o.count++;let _={name:f.name,path:Zf($c(t,x)),isDir:m.isDirectory(),size:m.size,modifiedAt:Math.floor(m.mtimeMs)};m.isDirectory()&&i>1&&(_.children=await Yf(t,x,p,i-1,o)),u.push(_)}return u.sort((f,x)=>f.isDir!==x.isDir?f.isDir?-1:1:f.name.localeCompare(x.name)),u}function X_(t){return!t||t<=0?R_:Math.min(t,k_)}function Q_(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function Zf(t){return t.split(Wf).join("/")}ne();import{readFileSync as NI}from"node:fs";import{dirname as BI,join as zI}from"node:path";import{fileURLToPath as UI}from"node:url";var Cr="0.1.104-alpha.13";var En=q("agent-health-reporter"),ey=1e4,Oi=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??ey}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()}),En.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),En.info("heartbeat stopped"))}async tick(){if(this.inFlight){En.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){En.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let r=[];for(let u of this.opts.core.agents.values()){let f=ty(u);if(!f)continue;let x={agentId:u.agentId,status:f};u.patToken&&(x.patToken=u.patToken),u.accountId&&(x.accountId=u.accountId),r.push(x)}if(r.length===0)return;let i={agents:r,bridgeVersion:Cr,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(u){En.warn("heartbeat batch send failed",{count:r.length,err:String(u)})}let c=o?.authFailures;if(c&&c.length>0&&(En.warn("heartbeat received authFailures from cloud",{count:c.length,agentIds:c.map(u=>u.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(c)}catch(u){En.warn("onAuthFailures callback failed (ignored)",{err:String(u)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){En.warn("onTickEnd hook failed",{err:String(r)})}}};function ty(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}an();import{mkdir as td,rm as Ky,stat as $y}from"node:fs/promises";import{homedir as Vy}from"node:os";import{join as S0}from"node:path";rn();import{existsSync as hy}from"node:fs";import{release as py}from"node:os";import{basename as gy,isAbsolute as my}from"node:path";function Li(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Rr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function kr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function vn(t,e){return{jsonrpc:"2.0",id:t,error:e}}We();var uo=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,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32022};function Jf(t){return"method"in t&&"id"in t&&t.id!==void 0}function Xf(t){return"method"in t&&!("id"in t)}function lo(t){return!("method"in t)&&"id"in t}var ny={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,METHOD_NOT_FOUND:Q.METHOD_NOT_FOUND,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,OPERATION_NOT_ALLOWED_FOR_CLOUD:Q.OPERATION_NOT_ALLOWED_FOR_CLOUD,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 ry(t){if(t!=null)return t instanceof Error?{name:t.name,message:Ni(t.message)}:typeof t=="string"?Ni(t):typeof t=="object"?sy(t):t}var iy=[[/\/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 Ni(t){let e=t;for(let[r,i]of iy)e=e.replace(r,i);return e}function sy(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Ni(i):e[r]=i;return e}function Mi(t){if(t instanceof C){let e=ry(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:ny[t.code]??Q.INTERNAL_ERROR,message:Ni(t.message),data:r}}return{code:Q.INTERNAL_ERROR,message:Ni(t instanceof Error?t.message:String(t))}}function Qf(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:u,...f}=e;c=f}return new C(r,o,{retriable:e?.retriable??!1,cause:c})}function t0(t){return`${JSON.stringify(t)}
93
- `}var e0=10*1024*1024,fo=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>e0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${e0} 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(u){this.onError?.({line:c,error:u})}}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 r0={"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","session/set_mode":"session.setMode",initialize:"initialize"},JI=Object.fromEntries(Object.entries(r0).map(([t,e])=>[e,t])),oy={"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"],"session.setMode":["agentId","sessionId"],"agent.pair":[],initialize:[]},Dr=class{seq=0;next(e,r){this.seq+=1;let i=r0[e]??ay(e),o=oy[i]??[],c=[i,String(this.seq)];if(o.length>0){let u=o.map(x=>n0(r?.[x]??"")),f=cy(u).join(":");f&&c.push(f)}else r&&Object.values(r).some(u=>u)&&c.push(Object.values(r).filter(Boolean).map(u=>n0(String(u))).join(":"));return c.join("_")}reset(){this.seq=0}};function ay(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function n0(t){return t.replace(/[:_\s]+/g,"-")}function cy(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}on();import{readFileSync as dy}from"node:fs";var uy=384;async function Zc(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await ar(t.agentEnvFile,r,{mode:uy})}function Jc(t){try{let e=JSON.parse(dy(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function i0(t,e,r={},i=o=>o){return{...i({...t,...Jc(e)}),...r}}Kt();nr();We();ne();Oe();import{execFileSync as ly,spawnSync as fy}from"node:child_process";function Bi(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function zi(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),fy("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var Xc=new Set;function s0(t){typeof t=="number"&&t>0&&Xc.add(t)}function o0(t){typeof t=="number"&&Xc.delete(t)}function a0(){for(let t of Xc)zi(t,"SIGKILL")}var Pr="coze-bridge-daemon";function c0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return ly("pgrep",["-U",String(o),"-f",Pr],{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 d0(t,e){if(t.length===0)return;let r=e?.killFn??zi,i=e?.isAliveFn??Bi,o=e?.sleepFn??(f=>new Promise(x=>setTimeout(x,f))),c=e?.graceMs??3e3,u=e?.pollMs??100;for(let f of t)r(f,"SIGTERM");for(let f=0;f<c&&t.some(x=>i(x));f+=u)await o(Math.min(u,c-f));for(let f of t)i(f)&&r(f,"SIGKILL")}var xy=[{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 u0(t,e){if(!e)return null;for(let r of xy)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function l0(t,e){return u0(t,e)}function f0(t,e){return u0(t,e)}function Or(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 x0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let p=t.suspendedMs+o,m=r-t.startedAt-p;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Or(m,t.firstFrameSeen,e)}}let c=r-t.startedAt-t.suspendedMs,u=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=u?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Or(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Or(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Or(c,!1,e)}}var h0=je("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),wy=200,_y=40,yy=je("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),by=je("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),Ey=je("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),vy=je("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),Sy=je("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Ay=je("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),p0=500;function Iy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=p0?t:`${e.slice(0,p0)}...<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 g0(t){try{return hy(t)}catch{return}}function Cy(t,e){return{platform:process.platform,osRelease:py(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:my(e.command)?g0(e.command):void 0,cwd:e.cwd,cwdExists:g0(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=${gy(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Pt=class{constructor(e){this.opts=e;this.log=q(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new fo({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Dr;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=i0(process.env,this.opts.agentEnvFile??X().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=nt(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,s0(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>wy&&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,o0(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 f of this.decoder.flush())this.dispatch(f)}catch(f){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(f)})}this.failAllPending(this.buildExitError(o,c));for(let f of this.exitHandlers)f(o,c)}),i.on("error",o=>{let c=o,u=Cy(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(r).length});this.log.error("child error",{err:String(o),diag:u}),this.failAllPending(new C("AGENT_SPAWN_FAILED",Ry(c,u),{cause:u}))}),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()));zi(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||zi(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:Sy,phase2GateMs:yy,livenessWindowMs:by,absoluteMaxMs:Ey,approvalMaxMs:Ay,suspendThresholdMs:vy,...r};return this.call("session/prompt",e,h0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Rr("session/cancel",e))}setSessionMode(e){return this.call("session/set_mode",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(kr(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(vn(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=h0,o){if(!this.child||this.stopped)return Promise.reject(new C("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),u=Li(c,e,r),f=(()=>{if(typeof r!="object"||r===null)return;let x=r.sessionId;return typeof x=="string"?x:void 0})();return new Promise((x,p)=>{let m={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:Or(0,!1,o),sessionId:f};m.promptTimeout=S;let y=()=>{let v={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=x0(v,S.cfg,A),R=D=>{S.armedAt=A,S.expectedIntervalMs=D,m.timer=setTimeout(y,D)};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}:{}}),R(I.rearmMs);return}if(I.action==="continue"){R(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 C("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new C("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 C("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};m.timer=setTimeout(y,S.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(m.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,m);try{this.writeFrame(u)}catch(_){m.timer&&clearTimeout(m.timer),this.pending.delete(c),p(_)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new C("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(t0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(lo(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:Iy(e.result)}),r.resolve(e.result));return}if(Xf(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(Jf(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 u=typeof i.status=="string"?i.status:void 0,f=u==="completed"||u==="failed"||u==="cancelled";o==="tool_call"&&!f?e.activeToolCalls.add(c):f&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(vn(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(vn(e.id,Mi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=Qf(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=f0(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(_y).join(`
96
- `),o=l0(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 ky(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 xo=class extends Pt{framework="claude-code";constructor(e){let{command:r,args:i}=ei("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 ky(e)}};rn();import{mkdtempSync as Dy,rmSync as Py}from"node:fs";import{tmpdir as Oy}from"node:os";import{join as Ly}from"node:path";var ho=class extends Pt{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=ei("codex",e.command,i),u=e.isolateCodexHome?Dy(Ly(Oy(),"coze-bridge-codex-home-")):void 0,f=u?{...e.env??{},CODEX_HOME:u}:e.env,x={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...f?{env:f}:{}};super(x),this.authMethodId=e.authMethodId,this.codexHomeDir=u}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{}}};We();var Ny=3e4,Lr=class extends Pt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},Ny))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new C("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var m0=["default","acceptEdits","plan","auto","bypassPermissions"],w0=["read-only","auto","full-access"];function Sn(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return m0.includes(e);case"codex":return w0.includes(e);case"openclaw":return!1}}function Qc(t){switch(t){case"claude-code":return m0.join("/");case"codex":return w0.join("/");case"openclaw":return""}}on();We();ne();Oe();function ed(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}rn();var An=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 po=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 An,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)Fi(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 Fi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function $t(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Kt();ne();import{constants as _0}from"node:fs";import{access as My}from"node:fs/promises";import{delimiter as By,join as zy}from"node:path";var bt=q("framework-detector"),y0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},Fy=[".exe",".cmd",".bat",".ps1"],Wn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??nt,access:e.access??My}}async detect(e){let r=y0[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,u]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),f={path:i,version:c};return u&&(f.defaultAgent=u),f}async detectAll(){let e=await Promise.all(Object.keys(y0).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(By).filter(Boolean),i=this.env.platform==="win32"?["",...Fy]:[""];for(let o of r)for(let c of i){let u=zy(o,e+c);if(await this.isExecutable(u))return u}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?_0.F_OK:_0.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(u=>u?.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 u=JSON.parse(c[0]);typeof u.gateway?.port=="number"&&(o.port=u.gateway.port),typeof u.service?.runtime?.status=="string"&&(o.runtime=u.service.runtime.status),!i&&typeof u.rpc?.error=="string"&&(o.detail=u.rpc.error)}catch(u){bt.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(u)})}return o}async probeVersion(e,r=[]){let i=await this.runProbe(e,[...r,"--version"]);return i&&(qy(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,u,f=x=>{c||(c=!0,u&&clearTimeout(u),i(x))};try{let x=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});u=setTimeout(()=>{x.kill("SIGKILL"),f(null)},15e3),x.stdout?.on("data",p=>{o+=p.toString("utf8")}),x.on("error",()=>f(null)),x.on("close",p=>f({code:p,stdout:o}))}catch{f(null)}})}},Uy=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function qy(t){return t.replace(Uy,"")}import{homedir as Gy}from"node:os";import{join as Hy}from"node:path";on();Kt();nr();We();ne();async function v0(){let t=Hy(Gy(),".openclaw/openclaw.json");return(await or(t))?.gateway?.auth?.token??""}var b0=q("openclaw.config"),jy=[0,5e3,5e3],Wy=je("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),E0="models.providers.",go="agents.defaults.models",mo=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new An;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??jy,this.cliTimeoutMs=e.cliTimeoutMs??Wy}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(u=>setTimeout(u,c));try{return await r()}catch(u){i=u,b0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(u)})}}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=nt(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",u=!1,f=p=>{u||(u=!0,clearTimeout(x),p())};o.stderr?.on("data",p=>{c+=p.toString("utf8")});let x=setTimeout(()=>{f(()=>{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=>f(()=>i(p))),o.on("close",p=>f(()=>{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){b0.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",`${E0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${E0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${go}[${e}]`,()=>this.runCli(["config","set",go,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${go}[${e}]`,`${go}.${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 ue=q("agent-manager"),rd="acceptEdits",T0="full-access",C0="read-only";function Yy(t){switch(t){case"read-only":return["-c",'sandbox_mode="read-only"',"-c",'approval_policy="on-request"'];case"auto":return["-c",'sandbox_mode="workspace-write"',"-c",'approval_policy="on-failure"'];case"full-access":return["-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"']}}var Zy=(t,e,r,i,o,c,u,f,x,p)=>{switch(t){case"claude-code":{let m={...o?{...Bf(o),...Uf(o,u,f)}:{},...x??{},IS_SANDBOX:"1"};return new xo({cwd:r,env:m,agentId:i})}case"codex":{let m=o?[...zf(o),...Gf(o,u,f)]:[],_=T0;p!==void 0&&(Sn("codex",p)?_=p:ue.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:p}));let S=[...m,...Yy(_)],y={...o?Ff(o):{},...x??{}},v=!!o;return new ho({cwd:r,agentId:i,...S.length>0?{extraArgs:S}:{},...Object.keys(y).length>0?{env:y}:{},...v?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Lr({command:e,cwd:r,agentId:i,...c?{sessionName:ed(c)}:{}})}};function nd(t){return t==="claude-code"||t==="codex"}function Jy(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(Xy(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
89
+ `},configPath(t){return b2(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 Xh("schtasks",["/Create","/SC","ONLOGON","/TN",sa,"/TR",r,"/RU",t.userName,"/F"]),jd.info("task scheduler entry created",{task:sa,logFile:t.logFile})},async uninstall(t){await Xh("schtasks",["/Delete","/TN",sa,"/F"]).catch(e=>jd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),jd.info("task scheduler entry removed",{task:sa})}}});var ep={};_a(ep,{buildContext:()=>T2,getSupervisor:()=>I2,launchdSupervisor:()=>Gd,systemdSupervisor:()=>qd,taskSchedulerSupervisor:()=>Hd});import{homedir as v2,userInfo as S2}from"node:os";function I2(t=process.platform){switch(t){case"darwin":return Gd;case"linux":return qd;case"win32":return Hd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function C2(){let t={};for(let e of A2){let r=process.env[e];r&&(t[e]=r)}return t}function T2(){let t=Q();return{nodeBin:process.execPath,entry:Pd(t),logFile:t.logFile,homeDir:v2(),userName:S2().username,isRoot:process.getuid?.()===0,env:C2()}}var A2,tp=Ze(()=>{"use strict";Pe();Vo();Jh();Zh();Qh();A2=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ne();rn();var El=q("acp-installer-warmup"),Tg=["claude-code","codex"];async function bl(t={}){let e=t.ensure??rr,i=(await Promise.allSettled(Tg.map(async o=>{let c=await e(o);El.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&El.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))})}sn();ne();import{readdir as Gg}from"node:fs/promises";import{mkdir as Tl,readFile as Fg,writeFile as kl}from"node:fs/promises";import{join as Aa}from"node:path";var Ug={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function or(t,e,r){await Tl(t,{recursive:!0});let i=Ug[e],o=Aa(t,i);return await kl(o,r??"","utf8"),o}async function Ca(t,e,r){let i=Aa(t,".claude");await Tl(i,{recursive:!0});let o=Aa(i,"settings.local.json"),c={};try{let f=await Fg(o,"utf8"),x=JSON.parse(f);typeof x=="object"&&x!==null&&!Array.isArray(x)&&(c=x)}catch{}let l=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")l.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!r)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");l.defaultMode===void 0&&(l.defaultMode=r)}return c.permissions=l,await kl(o,JSON.stringify(c,null,2),"utf8"),o}var Ve=q("agent-detail-sync"),qg=6e4,jg=5*6e4,fs=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await Gg(r)}catch(o){Ve.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}Ve.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Ne(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Ve.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(l){Ve.warn("detail sync failed for agent, skipping",{agentId:o,err:String(l)})}}})),Ve.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){Ve.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){Ve.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Ne(e,this.opts.paths);if(!i){Ve.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(x){Ve.warn("detail RPC failed, using local data",{agentId:e,err:String(x)});let p=this.retryQueue.get(e),w=p?Math.min(p.currentDelay*2,jg):qg;this.retryQueue.set(e,{dueAt:Date.now()+w,currentDelay:w});return}if(o.agentId&&o.agentId!==e){Ve.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,l=!1;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);let f=!1;if(o.deployType==="cloud"&&i.deployType!=="cloud"?(Ve.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,f=!0):o.deployType&&Ve.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Ve.debug("detail sync: no diff",{agentId:e});return}await Qe(i,this.opts.paths),Ve.info("detail sync: config updated",{agentId:e,identityChanged:l,agentName:i.agentName}),f?(await this.opts.agentManager.createAgent({agentId:e,framework:i.framework,_meta:{cozeDeployType:"cloud"},cozeIdentity:i.cozeIdentity,model:i.model}),Ve.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):l&&(await or(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var Yf=Ft(cu(),1);import{lstat as Gc,mkdir as qc,readFile as Kf,readdir as v_,rm as S_,stat as I_,writeFile as jc}from"node:fs/promises";import{dirname as A_,join as Dt,normalize as C_,relative as Kc,resolve as Hc,sep as $f}from"node:path";import{Readable as Vf}from"node:stream";import{pipeline as Jf}from"node:stream/promises";import um from"events";import et from"fs";import{EventEmitter as Ac}from"node:events";import ju from"node:stream";import{StringDecoder as fm}from"node:string_decoder";import Ku from"node:path";import wr from"node:fs";import{dirname as Im,parse as Am}from"path";import{EventEmitter as Lm}from"events";import ac from"assert";import{Buffer as Fn}from"buffer";import*as xu from"zlib";import Nm from"zlib";import{posix as ur}from"node:path";import{basename as cw}from"node:path";import Hs from"fs";import Tt from"fs";import yu from"path";import{win32 as yw}from"node:path";import Cu from"path";import cf from"node:fs";import Bw from"node:assert";import{randomBytes as df}from"node:crypto";import re from"node:fs";import Le from"node:path";import lf from"fs";import Qs from"node:fs";import yi from"node:path";import st from"node:fs";import Hw from"node:fs/promises";import $s from"node:path";import{join as Ef}from"node:path";import it from"node:fs";import Sf from"node:path";var dm=Object.defineProperty,lm=(t,e)=>{for(var r in e)dm(t,r,{get:e[r],enumerable:!0})},du=typeof process=="object"&&process?process:{stdout:null,stderr:null},xm=t=>!!t&&typeof t=="object"&&(t instanceof qn||t instanceof ju||hm(t)||pm(t)),hm=t=>!!t&&typeof t=="object"&&t instanceof Ac&&typeof t.pipe=="function"&&t.pipe!==ju.Writable.prototype.pipe,pm=t=>!!t&&typeof t=="object"&&t instanceof Ac&&typeof t.write=="function"&&typeof t.end=="function",Ut=Symbol("EOF"),Gt=Symbol("maybeEmitEnd"),an=Symbol("emittedEnd"),ms=Symbol("emittingEnd"),ri=Symbol("emittedError"),ws=Symbol("closed"),lu=Symbol("read"),_s=Symbol("flush"),uu=Symbol("flushChunk"),ht=Symbol("encoding"),lr=Symbol("decoder"),Me=Symbol("flowing"),ii=Symbol("paused"),pr=Symbol("resume"),Be=Symbol("buffer"),Je=Symbol("pipes"),ze=Symbol("bufferLength"),Oa=Symbol("bufferPush"),ys=Symbol("bufferShift"),$e=Symbol("objectMode"),Se=Symbol("destroyed"),La=Symbol("error"),Na=Symbol("emitData"),fu=Symbol("emitEnd"),Ma=Symbol("emitEnd2"),It=Symbol("async"),Ba=Symbol("abort"),Es=Symbol("aborted"),si=Symbol("signal"),Rn=Symbol("dataListeners"),rt=Symbol("discarded"),oi=t=>Promise.resolve().then(t),gm=t=>t(),mm=t=>t==="end"||t==="finish"||t==="prefinish",wm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,_m=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Hu=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[pr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},ym=class extends Hu{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)}},Em=t=>!!t.objectMode,bm=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",qn=class extends Ac{[Me]=!1;[ii]=!1;[Je]=[];[Be]=[];[$e];[ht];[It];[lr];[Ut]=!1;[an]=!1;[ms]=!1;[ws]=!1;[ri]=null;[ze]=0;[Se]=!1;[si];[Es]=!1;[Rn]=0;[rt]=!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");Em(e)?(this[$e]=!0,this[ht]=null):bm(e)?(this[ht]=e.encoding,this[$e]=!1):(this[$e]=!1,this[ht]=null),this[It]=!!e.async,this[lr]=this[ht]?new fm(this[ht]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Be]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Je]});let{signal:r}=e;r&&(this[si]=r,r.aborted?this[Ba]():r.addEventListener("abort",()=>this[Ba]()))}get bufferLength(){return this[ze]}get encoding(){return this[ht]}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[$e]}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}[Ba](){this[Es]=!0,this.emit("abort",this[si]?.reason),this.destroy(this[si]?.reason)}get aborted(){return this[Es]}set aborted(t){}write(t,e,r){if(this[Es])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[It]?oi:gm;if(!this[$e]&&!Buffer.isBuffer(t)){if(_m(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(wm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[$e]?(this[Me]&&this[ze]!==0&&this[_s](!0),this[Me]?this.emit("data",t):this[Oa](t),this[ze]!==0&&this.emit("readable"),r&&i(r),this[Me]):t.length?(typeof t=="string"&&!(e===this[ht]&&!this[lr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[ht]&&(t=this[lr].write(t)),this[Me]&&this[ze]!==0&&this[_s](!0),this[Me]?this.emit("data",t):this[Oa](t),this[ze]!==0&&this.emit("readable"),r&&i(r),this[Me]):(this[ze]!==0&&this.emit("readable"),r&&i(r),this[Me])}read(t){if(this[Se])return null;if(this[rt]=!1,this[ze]===0||t===0||t&&t>this[ze])return this[Gt](),null;this[$e]&&(t=null),this[Be].length>1&&!this[$e]&&(this[Be]=[this[ht]?this[Be].join(""):Buffer.concat(this[Be],this[ze])]);let e=this[lu](t||null,this[Be][0]);return this[Gt](),e}[lu](t,e){if(this[$e])this[ys]();else{let r=e;t===r.length||t===null?this[ys]():typeof r=="string"?(this[Be][0]=r.slice(t),e=r.slice(0,t),this[ze]-=t):(this[Be][0]=r.subarray(t),e=r.subarray(0,t),this[ze]-=t)}return this.emit("data",e),!this[Be].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[Me]||!this[ii])&&this[Gt](),this}[pr](){this[Se]||(!this[Rn]&&!this[Je].length&&(this[rt]=!0),this[ii]=!1,this[Me]=!0,this.emit("resume"),this[Be].length?this[_s]():this[Ut]?this[Gt]():this.emit("drain"))}resume(){return this[pr]()}pause(){this[Me]=!1,this[ii]=!0,this[rt]=!1}get destroyed(){return this[Se]}get flowing(){return this[Me]}get paused(){return this[ii]}[Oa](t){this[$e]?this[ze]+=1:this[ze]+=t.length,this[Be].push(t)}[ys](){return this[$e]?this[ze]-=1:this[ze]-=this[Be][0].length,this[Be].shift()}[_s](t=!1){do;while(this[uu](this[ys]())&&this[Be].length);!t&&!this[Be].length&&!this[Ut]&&this.emit("drain")}[uu](t){return this.emit("data",t),this[Me]}pipe(t,e){if(this[Se])return t;this[rt]=!1;let r=this[an];return e=e||{},t===du.stdout||t===du.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[Je].push(e.proxyErrors?new ym(this,t,e):new Hu(this,t,e)),this[It]?oi(()=>this[pr]()):this[pr]()),t}unpipe(t){let e=this[Je].find(r=>r.dest===t);e&&(this[Je].length===1?(this[Me]&&this[Rn]===0&&(this[Me]=!1),this[Je]=[]):this[Je].splice(this[Je].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[rt]=!1,this[Rn]++,!this[Je].length&&!this[Me]&&this[pr]();else if(t==="readable"&&this[ze]!==0)super.emit("readable");else if(mm(t)&&this[an])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[ri]){let i=e;this[It]?oi(()=>i.call(this,this[ri])):i.call(this,this[ri])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Rn]=this.listeners("data").length,this[Rn]===0&&!this[rt]&&!this[Je].length&&(this[Me]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Rn]=0,!this[rt]&&!this[Je].length&&(this[Me]=!1)),e}get emittedEnd(){return this[an]}[Gt](){!this[ms]&&!this[an]&&!this[Se]&&this[Be].length===0&&this[Ut]&&(this[ms]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[ws]&&this.emit("close"),this[ms]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Se&&this[Se])return!1;if(t==="data")return!this[$e]&&!r?!1:this[It]?(oi(()=>this[Na](r)),!0):this[Na](r);if(t==="end")return this[fu]();if(t==="close"){if(this[ws]=!0,!this[an]&&!this[Se])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[ri]=r,super.emit(La,r);let o=!this[si]||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}[Na](t){for(let r of this[Je])r.dest.write(t)===!1&&this.pause();let e=this[rt]?!1:super.emit("data",t);return this[Gt](),e}[fu](){return this[an]?!1:(this[an]=!0,this.readable=!1,this[It]?(oi(()=>this[Ma]()),!0):this[Ma]())}[Ma](){if(this[lr]){let e=this[lr].end();if(e){for(let r of this[Je])r.dest.write(e);this[rt]||super.emit("data",e)}}for(let e of this[Je])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[$e]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[$e]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[$e])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[ht]?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[rt]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[Ut])return e();let i,o,c=p=>{this.off("data",l),this.off("end",f),this.off(Se,x),e(),o(p)},l=p=>{this.off("error",c),this.off("end",f),this.off(Se,x),this.pause(),i({value:p,done:!!this[Ut]})},f=()=>{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",f),this.once("data",l)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[rt]=!1;let t=!1,e=()=>(this.pause(),this.off(La,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(La,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[rt]=!0,this[Be].length=0,this[ze]=0;let e=this;return typeof e.close=="function"&&!this[ws]&&e.close(),t?this.emit("error",t):this.emit(Se),this}static get isStream(){return xm}},vm=et.writev,mn=Symbol("_autoClose"),wt=Symbol("_close"),ai=Symbol("_ended"),de=Symbol("_fd"),za=Symbol("_finished"),Wt=Symbol("_flags"),Fa=Symbol("_flush"),sc=Symbol("_handleChunk"),oc=Symbol("_makeBuf"),wi=Symbol("_mode"),bs=Symbol("_needDrain"),yr=Symbol("_onerror"),Er=Symbol("_onopen"),Ua=Symbol("_onread"),gr=Symbol("_onwrite"),wn=Symbol("_open"),mt=Symbol("_path"),fn=Symbol("_pos"),At=Symbol("_queue"),mr=Symbol("_read"),Ga=Symbol("_readSize"),Ht=Symbol("_reading"),ci=Symbol("_remain"),qa=Symbol("_size"),Ps=Symbol("_write"),Dn=Symbol("_writing"),Os=Symbol("_defaultFlag"),zn=Symbol("_errored"),Cc=class extends qn{[zn]=!1;[de];[mt];[Ga];[Ht]=!1;[qa];[ci];[mn];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[zn]=!1,this[de]=typeof e.fd=="number"?e.fd:void 0,this[mt]=t,this[Ga]=e.readSize||16*1024*1024,this[Ht]=!1,this[qa]=typeof e.size=="number"?e.size:1/0,this[ci]=this[qa],this[mn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[de]=="number"?this[mr]():this[wn]()}get fd(){return this[de]}get path(){return this[mt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[wn](){et.open(this[mt],"r",(t,e)=>this[Er](t,e))}[Er](t,e){t?this[yr](t):(this[de]=e,this.emit("open",e),this[mr]())}[oc](){return Buffer.allocUnsafe(Math.min(this[Ga],this[ci]))}[mr](){if(!this[Ht]){this[Ht]=!0;let t=this[oc]();if(t.length===0)return process.nextTick(()=>this[Ua](null,0,t));et.read(this[de],t,0,t.length,null,(e,r,i)=>this[Ua](e,r,i))}}[Ua](t,e,r){this[Ht]=!1,t?this[yr](t):this[sc](e,r)&&this[mr]()}[wt](){if(this[mn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,et.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[yr](t){this[Ht]=!0,this[wt](),this.emit("error",t)}[sc](t,e){let r=!1;return this[ci]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[ci]<=0)&&(r=!1,this[wt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[de]=="number"&&this[mr](),!1;case"error":return this[zn]?!1:(this[zn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Sm=class extends Cc{[wn](){let t=!0;try{this[Er](null,et.openSync(this[mt],"r")),t=!1}finally{t&&this[wt]()}}[mr](){let t=!0;try{if(!this[Ht]){this[Ht]=!0;do{let e=this[oc](),r=e.length===0?0:et.readSync(this[de],e,0,e.length,null);if(!this[sc](r,e))break}while(!0);this[Ht]=!1}t=!1}finally{t&&this[wt]()}}[wt](){if(this[mn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,et.closeSync(t),this.emit("close")}}},Vs=class extends um{readable=!1;writable=!0;[zn]=!1;[Dn]=!1;[ai]=!1;[At]=[];[bs]=!1;[mt];[wi];[mn];[de];[Os];[Wt];[za]=!1;[fn];constructor(t,e){e=e||{},super(e),this[mt]=t,this[de]=typeof e.fd=="number"?e.fd:void 0,this[wi]=e.mode===void 0?438:e.mode,this[fn]=typeof e.start=="number"?e.start:void 0,this[mn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[fn]!==void 0?"r+":"w";this[Os]=e.flags===void 0,this[Wt]=e.flags===void 0?r:e.flags,this[de]===void 0&&this[wn]()}emit(t,...e){if(t==="error"){if(this[zn])return!1;this[zn]=!0}return super.emit(t,...e)}get fd(){return this[de]}get path(){return this[mt]}[yr](t){this[wt](),this[Dn]=!0,this.emit("error",t)}[wn](){et.open(this[mt],this[Wt],this[wi],(t,e)=>this[Er](t,e))}[Er](t,e){this[Os]&&this[Wt]==="r+"&&t&&t.code==="ENOENT"?(this[Wt]="w",this[wn]()):t?this[yr](t):(this[de]=e,this.emit("open",e),this[Dn]||this[Fa]())}end(t,e){return t&&this.write(t,e),this[ai]=!0,!this[Dn]&&!this[At].length&&typeof this[de]=="number"&&this[gr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[ai]?(this.emit("error",new Error("write() after end()")),!1):this[de]===void 0||this[Dn]||this[At].length?(this[At].push(t),this[bs]=!0,!1):(this[Dn]=!0,this[Ps](t),!0)}[Ps](t){et.write(this[de],t,0,t.length,this[fn],(e,r)=>this[gr](e,r))}[gr](t,e){t?this[yr](t):(this[fn]!==void 0&&typeof e=="number"&&(this[fn]+=e),this[At].length?this[Fa]():(this[Dn]=!1,this[ai]&&!this[za]?(this[za]=!0,this[wt](),this.emit("finish")):this[bs]&&(this[bs]=!1,this.emit("drain"))))}[Fa](){if(this[At].length===0)this[ai]&&this[gr](null,0);else if(this[At].length===1)this[Ps](this[At].pop());else{let t=this[At];this[At]=[],vm(this[de],t,this[fn],(e,r)=>this[gr](e,r))}}[wt](){if(this[mn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,et.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Wu=class extends Vs{[wn](){let t;if(this[Os]&&this[Wt]==="r+")try{t=et.openSync(this[mt],this[Wt],this[wi])}catch(e){if(e?.code==="ENOENT")return this[Wt]="w",this[wn]();throw e}else t=et.openSync(this[mt],this[Wt],this[wi]);this[Er](null,t)}[wt](){if(this[mn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,et.closeSync(t),this.emit("close")}}[Ps](t){let e=!0;try{this[gr](null,et.writeSync(this[de],t,0,t.length,this[fn])),e=!1}finally{if(e)try{this[wt]()}catch{}}}},Cm=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),Tm=t=>!!t.sync&&!!t.file,km=t=>!t.sync&&!!t.file,Rm=t=>!!t.sync&&!t.file,Dm=t=>!t.sync&&!t.file,Pm=t=>!!t.file,Om=t=>Cm.get(t)||t,Tc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=Om(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ci=(t,e,r,i,o)=>Object.assign((c=[],l,f)=>{Array.isArray(c)&&(l=c,c={}),typeof l=="function"&&(f=l,l=void 0),l=l?Array.from(l):[];let x=Tc(c);if(o?.(x,l),Tm(x)){if(typeof f=="function")throw new TypeError("callback not supported for sync tar functions");return t(x,l)}else if(km(x)){let p=e(x,l);return f?p.then(()=>f(),f):p}else if(Rm(x)){if(typeof f=="function")throw new TypeError("callback not supported for sync tar functions");return r(x,l)}else if(Dm(x)){if(typeof f=="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}),Mm=Nm.constants||{ZLIB_VERNUM:4736},Rt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},Mm)),Bm=Fn.concat,hu=Object.getOwnPropertyDescriptor(Fn,"concat"),zm=t=>t,ja=hu?.writable===!0||hu?.set!==void 0?t=>{Fn.concat=t?zm:Bm}:t=>{},Un=Symbol("_superWrite"),vs=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"}},Ha=Symbol("flushFlag"),kc=class extends qn{#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 xu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new xu[e](t)}catch(r){throw new vs(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 vs(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return ac(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Fn.alloc(0),{[Ha]: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}[Un](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Fn.from(t,e)),this.#e)return;ac(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},ja(!0);let l;try{let x=typeof t[Ha]=="number"?t[Ha]:this.#r;l=this.#t._processChunk(t,x),ja(!1)}catch(x){ja(!1),this.#o(new vs(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 vs(x,this.write)));let f;if(l)if(Array.isArray(l)&&l.length>0){let x=l[0];f=this[Un](Fn.from(x));for(let p=1;p<l.length;p++)f=this[Un](l[p])}else f=this[Un](Fn.from(l));return r&&r(),f}},$u=class extends kc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Rt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Rt.Z_FINISH,t.fullFlushFlag=Rt.Z_FULL_FLUSH,super(t,e),this.#e=t.level,this.#n=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==t||this.#n!==e){this.flush(Rt.Z_SYNC_FLUSH),ac(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)}}}},Fm=class extends $u{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Un](t){return this.#e?(this.#e=!1,t[9]=255,super[Un](t)):super[Un](t)}},Um=class extends $u{constructor(t){super(t,"Unzip")}},Vu=class extends kc{constructor(t,e){t=t||{},t.flush=t.flush||Rt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Rt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Rt.BROTLI_OPERATION_FLUSH,super(t,e)}},Gm=class extends Vu{constructor(t){super(t,"BrotliCompress")}},qm=class extends Vu{constructor(t){super(t,"BrotliDecompress")}},Ju=class extends kc{constructor(t,e){t=t||{},t.flush=t.flush||Rt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Rt.ZSTD_e_end,t.fullFlushFlag=Rt.ZSTD_e_flush,super(t,e)}},jm=class extends Ju{constructor(t){super(t,"ZstdCompress")}},Hm=class extends Ju{constructor(t){super(t,"ZstdDecompress")}},Wm=(t,e)=>{if(Number.isSafeInteger(t))t<0?$m(t,e):Km(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Km=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},$m=(t,e)=>{e[0]=255;var r=!1;t=t*-1;for(var i=e.length;i>1;i--){var o=t&255;t=Math.floor(t/256),r?e[i-1]=Yu(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Zu(o))}},Vm=t=>{let e=t[0],r=e===128?Ym(t.subarray(1,t.length)):e===255?Jm(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},Jm=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),l;i?l=Yu(c):c===0?l=c:(i=!0,l=Zu(c)),l!==0&&(r-=l*Math.pow(256,e-o-1))}return r},Ym=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},Yu=t=>(255^t)&255,Zu=t=>(255^t)+1&255,Zm={};lm(Zm,{code:()=>Rc,isCode:()=>Ls,isName:()=>Xm,name:()=>Js,normalFsTypes:()=>Xu});var Ls=t=>Js.has(t),Xm=t=>Rc.has(t),Xu=new Set(["0","","1","2","3","4","5","6","7","D"]),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"]]),Rc=new Map(Array.from(Js).map(t=>[t[1],t[0]])),Gn=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");let o=Pn(t,e+156,1),c=Xu.has(o),l=c?r:void 0,f=c?i:void 0;if(this.path=l?.path??Pn(t,e,100),this.mode=l?.mode??f?.mode??xn(t,e+100,8),this.uid=l?.uid??f?.uid??xn(t,e+108,8),this.gid=l?.gid??f?.gid??xn(t,e+116,8),this.size=l?.size??f?.size??xn(t,e+124,12),this.mtime=l?.mtime??f?.mtime??Wa(t,e+136,12),this.cksum=xn(t,e+148,12),f&&this.#n(f,!0),l&&this.#n(l),Ls(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Pn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=l?.uname??f?.uname??Pn(t,e+265,32),this.gname=l?.gname??f?.gname??Pn(t,e+297,32),this.devmaj=l?.devmaj??f?.devmaj??xn(t,e+329,8)??0,this.devmin=l?.devmin??f?.devmin??xn(t,e+337,8)??0,t[e+475]!==0){let p=Pn(t,e+345,155);this.path=p+"/"+this.path}else{let p=Pn(t,e+345,130);p&&(this.path=p+"/"+this.path),this.atime=r?.atime??i?.atime??Wa(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Wa(t,e+488,12)}let x=256;for(let p=e;p<e+148;p++)x+=t[p];for(let p=e+156;p<e+512;p++)x+=t[p];this.cksumValid=x===this.cksum,this.cksum===void 0&&x===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=Qm(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=On(t,e,100,o)||this.needPax,this.needPax=hn(t,e+100,8,this.mode)||this.needPax,this.needPax=hn(t,e+108,8,this.uid)||this.needPax,this.needPax=hn(t,e+116,8,this.gid)||this.needPax,this.needPax=hn(t,e+124,12,this.size)||this.needPax,this.needPax=Ka(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=On(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=On(t,e+265,32,this.uname)||this.needPax,this.needPax=On(t,e+297,32,this.gname)||this.needPax,this.needPax=hn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=hn(t,e+337,8,this.devmin)||this.needPax,this.needPax=On(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=On(t,e+345,155,c)||this.needPax:(this.needPax=On(t,e+345,130,c)||this.needPax,this.needPax=Ka(t,e+476,12,this.atime)||this.needPax,this.needPax=Ka(t,e+488,12,this.ctime)||this.needPax);let l=256;for(let f=e;f<e+148;f++)l+=t[f];for(let f=e+156;f<e+512;f++)l+=t[f];return this.cksum=l,hn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:Js.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Rc.get(t));if(Ls(e)||e==="Unsupported")this.#e=e;else if(Ls(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Qm=(t,e)=>{let r=t,i="",o,c=ur.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=ur.dirname(r),r=ur.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=ur.join(ur.basename(i),r),i=ur.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Pn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Wa=(t,e,r)=>ew(xn(t,e,r)),ew=t=>t===void 0?void 0:new Date(t*1e3),xn=(t,e,r)=>Number(t[e])&128?Vm(t.subarray(e,e+r)):nw(t,e,r),tw=t=>isNaN(t)?void 0:t,nw=(t,e,r)=>tw(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),rw={12:8589934591,8:2097151},hn=(t,e,r,i)=>i===void 0?!1:i>rw[r]||i<0?(Wm(i,t.subarray(e,e+r)),!0):(iw(t,e,r,i),!1),iw=(t,e,r,i)=>t.write(sw(i,r),e,r,"ascii"),sw=(t,e)=>ow(Math.floor(t).toString(8),e),ow=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Ka=(t,e,r,i)=>i===void 0?!1:hn(t,e,r,i.getTime()/1e3),aw=new Array(156).join("\0"),On=(t,e,r,i)=>i===void 0?!1:(t.write(i+aw,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),js=class Qu{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 Gn({path:("PaxHeader/"+cw(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 Qu(dw(lw(e),r),i)}},dw=(t,e)=>e?Object.assign({},e,t):t,lw=t=>t.replace(/\n$/,"").split(`
91
+ `).reduce(uw,Object.create(null)),uw=(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},fw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,X=fw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),xw=class extends qn{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=X(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?X(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=X(t.path)),t.linkpath&&(t.linkpath=X(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},Ys=(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))},hw=1024*1024,cc=Buffer.from([31,139]),dc=Buffer.from([40,181,47,253]),pw=Math.max(cc.length,dc.length),ct=Symbol("state"),Ln=Symbol("writeEntry"),qt=Symbol("readEntry"),$a=Symbol("nextEntry"),pu=Symbol("processEntry"),Ct=Symbol("extendedHeader"),di=Symbol("globalExtendedHeader"),cn=Symbol("meta"),gu=Symbol("emitMeta"),pe=Symbol("buffer"),jt=Symbol("queue"),dn=Symbol("ended"),Va=Symbol("emittedEnd"),Nn=Symbol("emit"),Te=Symbol("unzip"),Ss=Symbol("consumeChunk"),Is=Symbol("consumeChunkSub"),Ja=Symbol("consumeBody"),mu=Symbol("consumeMeta"),wu=Symbol("consumeHeader"),li=Symbol("consuming"),Ya=Symbol("bufferConcat"),As=Symbol("maybeEnd"),fr=Symbol("writing"),ln=Symbol("aborted"),Cs=Symbol("onDone"),Mn=Symbol("sawValidEntry"),Ts=Symbol("sawNullBlock"),ks=Symbol("sawEOF"),_u=Symbol("closeStream"),gw=()=>!0,Ai=class extends Lm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[jt]=[];[pe];[qt];[Ln];[ct]="begin";[cn]="";[Ct];[di];[dn]=!1;[Te];[ln]=!1;[Mn];[Ts]=!1;[ks]=!1;[fr]=!1;[li]=!1;[Va]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Cs,()=>{(this[ct]==="begin"||this[Mn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Cs,t.ondone):this.on(Cs,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||hw,this.filter=typeof t.filter=="function"?t.filter:gw;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[_u]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){Ys(this,t,e,r)}[wu](t,e){this[Mn]===void 0&&(this[Mn]=!1);let r;try{r=new Gn(t,e,this[Ct],this[di])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Ts]?(this[ks]=!0,this[ct]==="begin"&&(this[ct]="header"),this[Nn]("eof")):(this[Ts]=!0,this[Nn]("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[Ln]=new xw(r,this[Ct],this[di]);if(!this[Mn])if(o.remain){let c=()=>{o.invalid||(this[Mn]=!0)};o.on("end",c)}else this[Mn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Nn]("ignoredEntry",o),this[ct]="ignore",o.resume()):o.size>0&&(this[cn]="",o.on("data",c=>this[cn]+=c),this[ct]="meta"):(this[Ct]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Nn]("ignoredEntry",o),this[ct]=o.remain?"ignore":"header",o.resume()):(o.remain?this[ct]="body":(this[ct]="header",o.end()),this[qt]?this[jt].push(o):(this[jt].push(o),this[$a]())))}}}[_u](){queueMicrotask(()=>this.emit("close"))}[pu](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[$a]()),e=!1);return e}[$a](){do;while(this[pu](this[jt].shift()));if(this[jt].length===0){let t=this[qt];!t||t.flowing||t.size===t.remain?this[fr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Ja](t,e){let r=this[Ln];if(!r)throw new Error("attempt to consume body without entry??");let i=r.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return r.write(o),r.blockRemain||(this[ct]="header",this[Ln]=void 0,r.end()),o.length}[mu](t,e){let r=this[Ln],i=this[Ja](t,e);return!this[Ln]&&r&&this[gu](r),i}[Nn](t,e,r){this[jt].length===0&&!this[qt]?this.emit(t,e,r):this[jt].push([t,e,r])}[gu](t){switch(this[Nn]("meta",this[cn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Ct]=js.parse(this[cn],this[Ct],!1);break;case"GlobalExtendedHeader":this[di]=js.parse(this[cn],this[di],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Ct]??Object.create(null);this[Ct]=e,e.path=this[cn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Ct]||Object.create(null);this[Ct]=e,e.linkpath=this[cn].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[ln]=!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[ln])return r?.(),!1;if((this[Te]===void 0||this.brotli===void 0&&this[Te]===!1)&&t){if(this[pe]&&(t=Buffer.concat([this[pe],t]),this[pe]=void 0),t.length<pw)return this[pe]=t,r?.(),!0;for(let l=0;this[Te]===void 0&&l<cc.length;l++)t[l]!==cc[l]&&(this[Te]=!1);let o=!1;if(this[Te]===!1&&this.zstd!==!1){o=!0;for(let l=0;l<dc.length;l++)if(t[l]!==dc[l]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Te]===!1&&c)if(t.length<512)if(this[dn])this.brotli=!0;else return this[pe]=t,r?.(),!0;else try{new Gn(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[dn];this[dn]=!1,this[Te]=this[Te]===void 0?new Um({}):o?new Hm({}):new qm({}),this[Te].on("data",x=>this[Ss](x)),this[Te].on("error",x=>this.abort(x)),this[Te].on("end",()=>{this[dn]=!0,this[Ss]()}),this[fr]=!0;let f=!!this[Te][l?"end":"write"](t);return this[fr]=!1,r?.(),f}}this[fr]=!0,this[Te]?this[Te].write(t):this[Ss](t),this[fr]=!1;let i=this[jt].length>0?!1:this[qt]?this[qt].flowing:!0;return!i&&this[jt].length===0&&this[qt]?.once("drain",()=>this.emit("drain")),r?.(),i}[Ya](t){t&&!this[ln]&&(this[pe]=this[pe]?Buffer.concat([this[pe],t]):t)}[As](){if(this[dn]&&!this[Va]&&!this[ln]&&!this[li]){this[Va]=!0;let t=this[Ln];if(t&&t.blockRemain){let e=this[pe]?this[pe].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[pe]&&t.write(this[pe]),t.end()}this[Nn](Cs)}}[Ss](t){if(this[li]&&t)this[Ya](t);else if(!t&&!this[pe])this[As]();else if(t){if(this[li]=!0,this[pe]){this[Ya](t);let e=this[pe];this[pe]=void 0,this[Is](e)}else this[Is](t);for(;this[pe]&&this[pe]?.length>=512&&!this[ln]&&!this[ks];){let e=this[pe];this[pe]=void 0,this[Is](e)}this[li]=!1}(!this[pe]||this[dn])&&this[As]()}[Is](t){let e=0,r=t.length;for(;e+512<=r&&!this[ln]&&!this[ks];)switch(this[ct]){case"begin":case"header":this[wu](t,e),e+=512;break;case"ignore":case"body":e+=this[Ja](t,e);break;case"meta":e+=this[mu](t,e);break;default:throw new Error("invalid state: "+this[ct])}e<r&&(this[pe]=this[pe]?Buffer.concat([t.subarray(e),this[pe]]):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[ln]||(this[Te]?(t&&this[Te].write(t),this[Te].end()):(this[dn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[As]())),this}},_i=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)},mw=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},ef=(t,e)=>{let r=new Map(e.map(c=>[_i(c),!0])),i=t.filter,o=(c,l="")=>{let f=l||Am(c).root||".",x;if(c===f)x=!1;else{let p=r.get(c);x=p!==void 0?p:o(Im(c),f)}return r.set(c,x),x};t.filter=i?(c,l)=>i(c,l)&&o(_i(c)):c=>o(_i(c))},ww=t=>{let e=new Ai(t),r=t.file,i;try{i=wr.openSync(r,"r");let o=wr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let l=Buffer.allocUnsafe(o.size),f=wr.readSync(i,l,0,o.size,0);e.end(f===l.byteLength?l:l.subarray(0,f))}else{let l=0,f=Buffer.allocUnsafe(c);for(;l<o.size;){let x=wr.readSync(i,f,0,c,l);if(x===0)break;l+=x,e.write(f.subarray(0,x))}e.end()}}finally{if(typeof i=="number")try{wr.closeSync(i)}catch{}}},_w=(t,e)=>{let r=new Ai(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("end",c),wr.stat(o,(f,x)=>{if(f)l(f);else{let p=new Cc(o,{readSize:i,size:x.size});p.on("error",l),p.pipe(r)}})})},br=Ci(ww,_w,t=>new Ai(t),t=>new Ai(t),(t,e)=>{e?.length&&ef(t,e),t.noResume||mw(t)}),tf=(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:Ew,parse:Eu}=yw,Dc=t=>{let e="",r=Eu(t);for(;Ew(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=Eu(t)}return[e,t]},Zs=["|","<",">","?",":"],Pc=Zs.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),bw=new Map(Zs.map((t,e)=>[t,Pc[e]])),vw=new Map(Pc.map((t,e)=>[t,Zs[e]])),bu=t=>Zs.reduce((e,r)=>e.split(r).join(bw.get(r)),t),Sw=t=>Pc.reduce((e,r)=>e.split(r).join(vw.get(r)),t),nf=(t,e)=>e?(t=X(t).replace(/^\.(\/|$)/,""),_i(e)+"/"+t):X(t),Iw=16*1024*1024,vu=Symbol("process"),Su=Symbol("file"),Iu=Symbol("directory"),lc=Symbol("symlink"),Au=Symbol("hardlink"),ui=Symbol("header"),Ns=Symbol("read"),uc=Symbol("lstat"),Ms=Symbol("onlstat"),fc=Symbol("onread"),xc=Symbol("onreadlink"),hc=Symbol("openfile"),pc=Symbol("onopenfile"),pn=Symbol("close"),Ws=Symbol("mode"),gc=Symbol("awaitDrain"),Za=Symbol("ondrain"),kt=Symbol("prefix"),rf=class extends qn{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=Tc(e);super(),this.path=X(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||Iw,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=X(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?X(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]=Dc(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=X(r.absolute||yu.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[Ms](o):this[uc]()}warn(t,e,r={}){return Ys(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[uc](){Tt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Ms](e)})}[Ms](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=Tw(t),this.emit("stat",t),this[vu]()}[vu](){switch(this.type){case"File":return this[Su]();case"Directory":return this[Iu]();case"SymbolicLink":return this[lc]();default:return this.end()}}[Ws](t){return tf(t,this.type==="Directory",this.portable)}[kt](t){return nf(t,this.prefix)}[ui](){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 Gn({path:this[kt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[kt](this.linkpath):this.linkpath,mode:this[Ws](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 js({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)}[Iu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[ui](),this.end()}[lc](){Tt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[xc](e)})}[xc](t){this.linkpath=X(t),this[ui](),this.end()}[Au](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=X(yu.relative(this.cwd,t)),this.stat.size=0,this[ui](),this.end()}[Su](){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[Au](e);this.linkCache.set(t,this.absolute)}if(this[ui](),this.stat.size===0)return this.end();this[hc]()}[hc](){Tt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[pc](e)})}[pc](t){if(this.fd=t,this.#e)return this[pn]();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");Tt.read(t,e,r,i,o,(c,l)=>{if(c)return this[pn](()=>this.emit("error",c));this[fc](l)})}[pn](t=()=>{}){this.fd!==void 0&&Tt.close(this.fd,t)}[fc](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[pn](()=>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[pn](()=>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[Za]():this[gc](()=>this[Za]())}[gc](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)}[Za](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[pn](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]()}},Aw=class extends rf{sync=!0;[uc](){this[Ms](Tt.lstatSync(this.absolute))}[lc](){this[xc](Tt.readlinkSync(this.absolute))}[hc](){this[pc](Tt.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=Tt.readSync(e,r,i,o,c);this[fc](l),t=!1}finally{if(t)try{this[pn](()=>{})}catch{}}}[gc](t){t()}[pn](t=()=>{}){this.fd!==void 0&&Tt.closeSync(this.fd),t()}},Cw=class extends qn{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 Ys(this,t,e,r)}constructor(t,e={}){let r=Tc(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=X(t.path),this.mode=t.mode!==void 0?this[Ws](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?X(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[l,f]=Dc(this.path);l&&typeof f=="string"&&(this.path=f,o=l)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Gn({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 js({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 nf(t,this.prefix)}[Ws](t){return tf(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}},Tw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",kw=class _r{tail;head;length=0;static create(e=[]){return new _r(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++)Dw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)Pw(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 _r;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 _r;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 _r;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 _r;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=Rw(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 Rw(t,e,r){let i=e,o=e?e.next:t.head,c=new Oc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function Dw(t,e){t.tail=new Oc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function Pw(t,e){t.head=new Oc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Oc=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}},Tu=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},ku=Buffer.alloc(1024),Bs=Symbol("onStat"),fi=Symbol("ended"),pt=Symbol("queue"),xi=Symbol("pendingLinks"),un=Symbol("current"),Bn=Symbol("process"),hi=Symbol("processing"),Rs=Symbol("processJob"),gt=Symbol("jobs"),Xa=Symbol("jobDone"),zs=Symbol("addFSEntry"),Ru=Symbol("addTarEntry"),mc=Symbol("stat"),wc=Symbol("readdir"),Fs=Symbol("onreaddir"),Us=Symbol("pipe"),Du=Symbol("entry"),Qa=Symbol("entryOpt"),Gs=Symbol("writeEntryClass"),sf=Symbol("write"),ec=Symbol("ondrain"),Xs=class extends qn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Gs];onWriteEntry;[pt];[xi]=new Map;[gt]=0;[hi]=!1;[fi]=!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=X(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[Gs]=rf,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 Fm(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new Gm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new jm(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[ec]()),this.on("resume",()=>e.resume())}else this.on("drain",this[ec]);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[pt]=new kw,this[gt]=0,this.jobs=Number(t.jobs)||4,this[hi]=!1,this[fi]=!1}[sf](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[fi]=!0,this[Bn](),r&&r(),this}write(t){if(this[fi])throw new Error("write after end");return typeof t=="string"?this[zs](t):this[Ru](t),this.flowing}[Ru](t){let e=X(Cu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Tu(t.path,e);r.entry=new Cw(t,this[Qa](r)),r.entry.on("end",()=>this[Xa](r)),this[gt]+=1,this[pt].push(r)}this[Bn]()}[zs](t){let e=X(Cu.resolve(this.cwd,t));this[pt].push(new Tu(t,e)),this[Bn]()}[mc](t){t.pending=!0,this[gt]+=1;let e=this.follow?"stat":"lstat";Hs[e](t.absolute,(r,i)=>{t.pending=!1,this[gt]-=1,r?this.emit("error",r):this[Bs](t,i)})}[Bs](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[un])this[Rs](t);else{let r=`${e.dev}:${e.ino}`,i=this[xi].get(r);i?i.push(t):this[xi].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Bn]()}[wc](t){t.pending=!0,this[gt]+=1,Hs.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[gt]-=1,e)return this.emit("error",e);this[Fs](t,r)})}[Fs](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Bn]()}[Bn](){if(!this[hi]){this[hi]=!0;for(let t=this[pt].head;t&&this[gt]<this.jobs;t=t.next)if(this[Rs](t.value),t.value.ignore){let e=t.next;this[pt].removeNode(t),t.next=e}this[hi]=!1,this[fi]&&this[pt].length===0&&this[gt]===0&&(this.zip?this.zip.end(ku):(super.write(ku),super.end()))}}get[un](){return this[pt]&&this[pt].head&&this[pt].head.value}[Xa](t){this[pt].shift(),this[gt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[xi].get(r);if(i){this[xi].delete(r);for(let o of i)o.pending=!1,this[Rs](o)}}this[Bn]()}[Rs](t){if(t.pending&&t.pendingLink&&t===this[un]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[un]&&!t.piped&&this[Us](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Bs](t,e):this[mc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[Fs](t,e):this[wc](t),!t.readdir)return}if(t.entry=this[Du](t),!t.entry){t.ignore=!0;return}t===this[un]&&!t.piped&&this[Us](t)}}}[Qa](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}}[Du](t){this[gt]+=1;try{return new this[Gs](t.path,this[Qa](t)).on("end",()=>this[Xa](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[ec](){this[un]&&this[un].entry&&this[un].entry.resume()}[Us](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[zs](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={}){Ys(this,t,e,r)}},Lc=class extends Xs{sync=!0;constructor(t){super(t),this[Gs]=Aw}pause(){}resume(){}[mc](t){let e=this.follow?"statSync":"lstatSync";this[Bs](t,Hs[e](t.absolute))}[wc](t){this[Fs](t,Hs.readdirSync(t.absolute))}[Us](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[zs](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[sf](i)})}},Ow=(t,e)=>{let r=new Lc(t),i=new Wu(t.file,{mode:t.mode||438});r.pipe(i),of(r,e)},Lw=(t,e)=>{let r=new Xs(t),i=new Vs(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 af(r,e).catch(c=>r.emit("error",c)),o},of=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?br({file:Ku.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},af=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await br({file:Ku.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},Nw=(t,e)=>{let r=new Lc(t);return of(r,e),r},Mw=(t,e)=>{let r=new Xs(t);return af(r,e).catch(i=>r.emit("error",i)),r},lI=Ci(Ow,Lw,Nw,Mw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),zw=process.env.__FAKE_PLATFORM__||process.platform,uf=zw==="win32",{O_CREAT:ff,O_NOFOLLOW:Pu,O_TRUNC:xf,O_WRONLY:hf}=lf.constants,pf=Number(process.env.__FAKE_FS_O_FILENAME__)||lf.constants.UV_FS_O_FILEMAP||0,Fw=uf&&!!pf,Uw=512*1024,Gw=pf|xf|ff|hf,Ou=!uf&&typeof Pu=="number"?Pu|xf|ff|hf:null,gf=Ou!==null?()=>Ou:Fw?t=>t<Uw?Gw:"w":()=>"w",_c=(t,e,r)=>{try{return Qs.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},Ks=(t,e,r,i)=>{Qs.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},qw=(t,e,r,i,o)=>{if(e.isDirectory())mf(yi.resolve(t,e.name),r,i,c=>{if(c)return o(c);let l=yi.resolve(t,e.name);Ks(l,r,i,o)});else{let c=yi.resolve(t,e.name);Ks(c,r,i,o)}},mf=(t,e,r,i)=>{Qs.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 Ks(t,e,r,i);let l=c.length,f=null,x=p=>{if(!f){if(p)return i(f=p);if(--l===0)return Ks(t,e,r,i)}};for(let p of c)qw(t,p,e,r,x)})},jw=(t,e,r,i)=>{e.isDirectory()&&wf(yi.resolve(t,e.name),r,i),_c(yi.resolve(t,e.name),r,i)},wf=(t,e,r)=>{let i;try{i=Qs.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return _c(t,e,r);throw c}for(let o of i)jw(t,o,e,r);return _c(t,e,r)},_f=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"}},eo=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"}},Ww=(t,e)=>{st.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new _f(t,r?.code||"ENOTDIR")),e(r)})},Kw=(t,e,r)=>{t=X(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,l=e.uid,f=e.gid,x=typeof l=="number"&&typeof f=="number"&&(l!==e.processUid||f!==e.processGid),p=e.preserve,w=e.unlink,_=X(e.cwd),S=(v,I)=>{v?r(v):I&&x?mf(I,l,f,C=>S(C)):c?st.chmod(t,o,r):r()};if(t===_)return Ww(t,S);if(p)return Hw.mkdir(t,{mode:o,recursive:!0}).then(v=>S(null,v??void 0),S);let y=X($s.relative(_,t)).split("/");yc(_,y,o,w,_,void 0,S)},yc=(t,e,r,i,o,c,l)=>{if(e.length===0)return l(null,c);let f=e.shift(),x=X($s.resolve(t+"/"+f));st.mkdir(x,r,yf(x,e,r,i,o,c,l))},yf=(t,e,r,i,o,c,l)=>f=>{f?st.lstat(t,(x,p)=>{if(x)x.path=x.path&&X(x.path),l(x);else if(p.isDirectory())yc(t,e,r,i,o,c,l);else if(i)st.unlink(t,w=>{if(w)return l(w);st.mkdir(t,r,yf(t,e,r,i,o,c,l))});else{if(p.isSymbolicLink())return l(new eo(t,t+"/"+e.join("/")));l(f)}}):(c=c||t,yc(t,e,r,i,o,c,l))},$w=t=>{let e=!1,r;try{e=st.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new _f(t,r??"ENOTDIR")}},Vw=(t,e)=>{t=X(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,l=e.gid,f=typeof c=="number"&&typeof l=="number"&&(c!==e.processUid||l!==e.processGid),x=e.preserve,p=e.unlink,w=X(e.cwd),_=v=>{v&&f&&wf(v,c,l),o&&st.chmodSync(t,i)};if(t===w)return $w(w),_();if(x)return _(st.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=X($s.relative(w,t)).split("/"),y;for(let v=S.shift(),I=w;v&&(I+="/"+v);v=S.shift()){I=X($s.resolve(I));try{st.mkdirSync(I,i),y=y||I}catch{let C=st.lstatSync(I);if(C.isDirectory())continue;if(p){st.unlinkSync(I),st.mkdirSync(I,i),y=y||I;continue}else if(C.isSymbolicLink())return new eo(I,I+"/"+S.join("/"))}}return _(y)},tc=Object.create(null),Lu=1e4,xr=new Set,Jw=t=>{xr.has(t)?xr.delete(t):tc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),xr.add(t);let e=tc[t],r=xr.size-Lu;if(r>Lu/10){for(let i of xr)if(xr.delete(i),delete tc[i],--r<=0)break}return e},Yw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Zw=Yw==="win32",Xw=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=Ef(i,r)),e.push(r||"/"),e},[]),Qw=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=Zw?["win32 parallelization disabled"]:t.map(i=>_i(Ef(Jw(i))));let r=new Set(t.map(i=>Xw(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let l=this.#e.get(c);if(!l||l?.[0]!==t)continue;let f=l[1];if(!f){this.#e.delete(c);continue}if(l.shift(),typeof f=="function")o.add(f);else for(let x of f)o.add(x)}for(let c of i){let l=this.#e.get(c),f=l?.[0];if(!(!l||!(f instanceof Set)))if(f.size===1&&l.length===1){this.#e.delete(c);continue}else if(f.size===1){l.shift();let x=l[0];typeof x=="function"&&o.add(x)}else f.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},e_=()=>process.umask(),Nu=Symbol("onEntry"),Ec=Symbol("checkFs"),Mu=Symbol("checkFs2"),bc=Symbol("isReusable"),dt=Symbol("makeFs"),vc=Symbol("file"),Sc=Symbol("directory"),qs=Symbol("link"),Bu=Symbol("symlink"),zu=Symbol("hardlink"),mi=Symbol("ensureNoSymlink"),Fu=Symbol("unsupported"),Uu=Symbol("checkPath"),nc=Symbol("stripAbsolutePath"),gn=Symbol("mkdir"),Fe=Symbol("onError"),Ds=Symbol("pending"),Gu=Symbol("pend"),hr=Symbol("unpend"),rc=Symbol("ended"),ic=Symbol("maybeClose"),Ic=Symbol("skip"),Ei=Symbol("doChown"),bi=Symbol("uid"),vi=Symbol("gid"),Si=Symbol("checkedCwd"),t_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ii=t_==="win32",n_=1024,r_=(t,e)=>{if(!Ii)return re.unlink(t,e);let r=t+".DELETE."+df(16).toString("hex");re.rename(t,r,i=>{if(i)return e(i);re.unlink(r,e)})},i_=t=>{if(!Ii)return re.unlinkSync(t);let e=t+".DELETE."+df(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},qu=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Nc=class extends Ai{[rc]=!1;[Si]=!1;[Ds]=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[rc]=!0,this[ic]()},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:n_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Ii,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=X(Le.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:e_():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[Nu](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[ic](){this[rc]&&this[Ds]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[nc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Dc(r),l=c.replaceAll(/\\/g,"/").split("/");if(l.includes("..")||Ii&&/^[a-z]:\.\.$/i.test(l[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let f=Le.posix.dirname(t.path),x=Le.posix.normalize(Le.posix.join(f,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}[Uu](t){let e=X(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=X(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[nc](t,"path")||!this[nc](t,"linkpath"))return!1;if(t.absolute=Le.isAbsolute(t.path)?X(Le.resolve(t.path)):X(Le.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:X(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}=Le.win32.parse(String(t.absolute));t.absolute=i+bu(String(t.absolute).slice(i.length));let{root:o}=Le.win32.parse(t.path);t.path=o+bu(t.path.slice(o.length))}return!0}[Nu](t){if(!this[Uu](t))return t.resume();switch(Bw.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[Ec](t);default:return this[Fu](t)}}[Fe](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[hr](),e.resume())}[gn](t,e,r){Kw(X(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)}[Ei](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}[bi](t){return qu(this.uid,t.uid,this.processUid)}[vi](t){return qu(this.gid,t.gid,this.processGid)}[vc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Vs(String(t.absolute),{flags:gf(t.size),mode:r,autoClose:!1});i.on("error",f=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[Fe](f,t),e()});let o=1,c=f=>{if(f){i.fd&&re.close(i.fd,()=>{}),this[Fe](f,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,x=>{x?this[Fe](x,t):this[hr](),e()})};i.on("finish",()=>{let f=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(f,p,w,S=>c(S&&_)):c())}if(typeof x=="number"&&this[Ei](t)){o++;let p=this[bi](t),w=this[vi](t);typeof p=="number"&&typeof w=="number"&&re.fchown(x,p,w,_=>_?re.chown(f,p,w,S=>c(S&&_)):c())}c()});let l=this.transform&&this.transform(t)||t;l!==t&&(l.on("error",f=>{this[Fe](f,t),e()}),t.pipe(l)),l.pipe(i)}[Sc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[gn](String(t.absolute),r,i=>{if(i){this[Fe](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[hr](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[Ei](t)&&(o++,re.chown(String(t.absolute),Number(this[bi](t)),Number(this[vi](t)),c)),c()})}[Fu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Bu](t,e){let r=X(Le.relative(this.cwd,Le.resolve(Le.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[mi](t,this.cwd,r,()=>this[qs](t,String(t.linkpath),"symlink",e),i=>{this[Fe](i,t),e()})}[zu](t,e){let r=X(Le.resolve(this.cwd,String(t.linkpath))),i=X(String(t.linkpath)).split("/");this[mi](t,this.cwd,i,()=>this[qs](t,r,"link",e),o=>{this[Fe](o,t),e()})}[mi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let l=Le.resolve(e,c);re.lstat(l,(f,x)=>{if(f)return i();if(x?.isSymbolicLink())return o(new eo(l,Le.resolve(l,r.join("/"))));this[mi](t,l,r,i,o)})}[Gu](){this[Ds]++}[hr](){this[Ds]--,this[ic]()}[Ic](t){this[hr](),t.resume()}[bc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Ii}[Ec](t){this[Gu]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Mu](t,r))}[Mu](t,e){let r=l=>{e(l)},i=()=>{this[gn](this.cwd,this.dmode,l=>{if(l){this[Fe](l,t),r();return}this[Si]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let l=X(Le.dirname(String(t.absolute)));if(l!==this.cwd)return this[gn](l,this.dmode,f=>{if(f){this[Fe](f,t),r();return}c()})}c()},c=()=>{re.lstat(String(t.absolute),(l,f)=>{if(f&&(this.keep||this.newer&&f.mtime>(t.mtime??f.mtime))){this[Ic](t),r();return}if(l||this[bc](t,f))return this[dt](null,t,r);if(f.isDirectory()){if(t.type==="Directory"){let x=this.chmod&&t.mode&&(f.mode&4095)!==t.mode,p=w=>this[dt](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[dt](x??null,t,r))}if(t.absolute===this.cwd)return this[dt](null,t,r);r_(String(t.absolute),x=>this[dt](x??null,t,r))})};this[Si]?o():i()}[dt](t,e,r){if(t){this[Fe](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[vc](e,r);case"Link":return this[zu](e,r);case"SymbolicLink":return this[Bu](e,r);case"Directory":case"GNUDumpDir":return this[Sc](e,r)}}[qs](t,e,r,i){re[r](e,String(t.absolute),o=>{o?this[Fe](o,t):(this[hr](),t.resume()),i()})}},pi=t=>{try{return[null,t()]}catch(e){return[e,null]}},bf=class extends Nc{sync=!0;[dt](t,e){return super[dt](t,e,()=>{})}[Ec](t){if(!this[Si]){let o=this[gn](this.cwd,this.dmode);if(o)return this[Fe](o,t);this[Si]=!0}if(t.absolute!==this.cwd){let o=X(Le.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[gn](o,this.dmode);if(c)return this[Fe](c,t)}}let[e,r]=pi(()=>re.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Ic](t);if(e||this[bc](t,r))return this[dt](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[l]=c?pi(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[dt](l,t)}let[o]=pi(()=>re.rmdirSync(String(t.absolute)));this[dt](o,t)}let[i]=t.absolute===this.cwd?[]:pi(()=>i_(String(t.absolute)));this[dt](i,t)}[vc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=l=>{let f;try{re.closeSync(o)}catch(x){f=x}(l||f)&&this[Fe](l||f,t),e()},o;try{o=re.openSync(String(t.absolute),gf(t.size),r)}catch(l){return i(l)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",l=>this[Fe](l,t)),t.pipe(c)),c.on("data",l=>{try{re.writeSync(o,l,0,l.length)}catch(f){i(f)}}),c.on("end",()=>{let l=null;if(t.mtime&&!this.noMtime){let f=t.atime||new Date,x=t.mtime;try{re.futimesSync(o,f,x)}catch(p){try{re.utimesSync(String(t.absolute),f,x)}catch{l=p}}}if(this[Ei](t)){let f=this[bi](t),x=this[vi](t);try{re.fchownSync(o,Number(f),Number(x))}catch(p){try{re.chownSync(String(t.absolute),Number(f),Number(x))}catch{l=l||p}}}i(l)})}[Sc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[gn](String(t.absolute),r);if(i){this[Fe](i,t),e();return}if(t.mtime&&!this.noMtime)try{re.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[Ei](t))try{re.chownSync(String(t.absolute),Number(this[bi](t)),Number(this[vi](t)))}catch{}e(),t.resume()}[gn](t,e){try{return Vw(X(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}}[mi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let l of r){c=Le.resolve(c,l);let[f,x]=pi(()=>re.lstatSync(c));if(f)return i();if(x.isSymbolicLink())return o(new eo(c,Le.resolve(e,r.join("/"))))}i()}[qs](t,e,r,i){let o=`${r}Sync`;try{re[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[Fe](c,t)}}},s_=t=>{let e=new bf(t),r=t.file,i=cf.statSync(r),o=t.maxReadSize||16*1024*1024;new Sm(r,{readSize:o,size:i.size}).pipe(e)},o_=(t,e)=>{let r=new Nc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("close",c),cf.stat(o,(f,x)=>{if(f)l(f);else{let p=new Cc(o,{readSize:i,size:x.size});p.on("error",l),p.pipe(r)}})})},vf=Ci(s_,o_,t=>new bf(t),t=>new Nc(t),(t,e)=>{e?.length&&ef(t,e)}),a_=(t,e)=>{let r=new Lc(t),i=!0,o,c;try{try{o=it.openSync(t.file,"r+")}catch(x){if(x?.code==="ENOENT")o=it.openSync(t.file,"w+");else throw x}let l=it.fstatSync(o),f=Buffer.alloc(512);e:for(c=0;c<l.size;c+=512){for(let w=0,_=0;w<512;w+=_){if(_=it.readSync(o,f,w,f.length-w,c+w),c===0&&f[0]===31&&f[1]===139)throw new Error("cannot append to compressed archives");if(!_)break e}let x=new Gn(f);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,c_(t,r,c,o,e)}finally{if(i)try{it.closeSync(o)}catch{}}},c_=(t,e,r,i,o)=>{let c=new Wu(t.file,{fd:i,start:r});e.pipe(c),l_(e,o)},d_=(t,e)=>{e=Array.from(e);let r=new Xs(t),i=(o,c,l)=>{let f=(S,y)=>{S?it.close(o,v=>l(S)):l(null,y)},x=0;if(c===0)return f(null,0);let p=0,w=Buffer.alloc(512),_=(S,y)=>{if(S||y===void 0)return f(S);if(p+=y,p<512&&y)return it.read(o,w,p,w.length-p,x+p,_);if(x===0&&w[0]===31&&w[1]===139)return f(new Error("cannot append to compressed archives"));if(p<512)return f(null,x);let v=new Gn(w);if(!v.cksumValid)return f(null,x);let I=512*Math.ceil((v.size??0)/512);if(x+I+512>c||(x+=I+512,x>=c))return f(null,x);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),p=0,it.read(o,w,0,512,x,_)};it.read(o,w,0,512,x,_)};return new Promise((o,c)=>{r.on("error",c);let l="r+",f=(x,p)=>{if(x&&x.code==="ENOENT"&&l==="r+")return l="w+",it.open(t.file,l,f);if(x||!p)return c(x);it.fstat(p,(w,_)=>{if(w)return it.close(p,()=>c(w));i(p,_.size,(S,y)=>{if(S)return c(S);let v=new Vs(t.file,{fd:p,start:y});r.pipe(v),v.on("error",c),v.on("close",o),u_(r,e)})})};it.open(t.file,l,f)})},l_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?br({file:Sf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},u_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await br({file:Sf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},gi=Ci(a_,d_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!Pm(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")}),II=Ci(gi.syncFile,gi.asyncFile,gi.syncNoFile,gi.asyncNoFile,(t,e=[])=>{gi.validate?.(t,e),f_(t)}),f_=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))};sn();var _t={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",UPGRADE:"_agent/upgrade",DELETE:"_agent/delete"};function to(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function If(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function no(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Af(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function Cf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function vr(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Kt();Ke();ne();Pe();Ke();function _n(t,e){if(to(t)!=="cloud")throw new k("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Ti(t){return t.startsWith("http://")||t.startsWith("https://")}function ro(t){return t.endsWith("/")?t.slice(0,-1):t}Ke();ne();var io="1008033",Df="1289";var Pf="pbbp2",Of="https://www.coze.cn",Lf="/api/coze_claw/resource/get_frontier_key",y_="https://www.coze.cn",E_="wss://frontier.coze.cn";function so(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??y_}function Nf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??E_}function Sr(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 Ri(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var ki=q("handshake");async function Mc(t){let e=so(t.endpoint),r=t.timeoutMs??1e4,i=`${ro(e)}${Lf}?aid=${encodeURIComponent(io)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...Sr(t.ppeOverride)},c=new AbortController,l=setTimeout(()=>c.abort(),r);ki.info("frontier key handshake",{base:e});try{let f=await fetch(i,{method:"GET",headers:o,signal:c.signal}),x=f.headers.get("x-tt-logid")??"",p=f.headers.get("x-tt-trace-id")??"";if(!f.ok){let v=await f.text().catch(()=>"");throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${f.status} logid=${x}: ${v.slice(0,200)}`)}let w=await f.json();if(w.code!==void 0&&w.code!==0)throw new k("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,y=typeof _.device_id=="string"&&_.device_id||typeof _.deviceId=="string"&&_.deviceId||void 0;if(!S||!y){let v=JSON.stringify(w).slice(0,500);throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${x}: ${v}`)}return ki.info("handshake ok",{remoteDeviceId:y,logid:x,traceId:p}),{accessKey:S,deviceId:y}}catch(f){if(f instanceof k)throw ki.error("handshake failed (bridge error)",{base:e,message:f.message,code:f.code}),f;if(f.name==="AbortError")throw ki.warn("handshake timeout",{base:e,timeoutMs:r}),new k("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:f});let x=f.cause;throw ki.error("handshake error",{base:e,message:f instanceof Error?f.message:String(f),errno:x?.code,syscall:x?.syscall,cause:String(f).slice(0,300)}),new k("UPSTREAM_HANDSHAKE_FAILED",String(f),{cause:f})}finally{clearTimeout(l)}}var Bc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",yt="auto",Mf=15e4;function Bf(t){return{model:zc(t.model)??yt,...t.modelToken?{modelToken:t.modelToken}:{}}}function zf(t){return!t||t===yt}var b_=new Set(["auto","\u81EA\u52A8"]);function zc(t){let e=t?.trim();if(e)return b_.has(e.toLowerCase())?yt:e}function Ff(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Bc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||yt;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,e.CLAUDE_CODE_ATTRIBUTION_HEADER="0",t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else zf(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Uf(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||yt}"`):zf(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="${Bc}/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??Mf;e.push("-c",`model_context_window=${r}`)}return e}function Gf(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function Fc(t,e){let{ttEnv:r,usePpe:i}=Ri(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function qf(t,e,r){if(!t.modelToken)return{};let i=Fc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,l])=>`${c}:${l}`).join(`
92
+ `)}}function Uc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function jf(t,e,r){if(!t.modelToken)return null;let i=t.model||yt,o=Fc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let l={baseUrl:`${Bc}/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??Mf,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(l.headers=o),l}function Hf(t,e,r){if(!t.modelToken)return[];let i=Fc(e,r),o=[];for(let[c,l]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${l}"`);return o}var Ie=q("agent-handlers"),Wf=5*1024*1024,T_=1,k_=6,R_=new Set(["node_modules",".git",".coze","dist","build",".next"]),D_=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,P_=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,O_=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function L_(t){let e=t?.trim();return e?O_.test(e)||P_.test(e)?e:(Ie.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function N_(t){return new Promise((e,r)=>{let i=nt("npx",t,{detached:!0,stdio:"ignore",windowsHide:!0}),o=!1,c=l=>{o||(o=!0,l?r(l):e(i.pid??0))};i.once("spawn",()=>{i.unref(),c()}),i.once("error",l=>c(l))})}var oo=class{constructor(e){this.opts=e}opts;async listSkills(e){_n(e._meta,"_agent/listSkills");let r=vr(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Xe(r).workspace,c=i?.skills??[],l=[];for(let f of c){let x=Dt(o,f.relPath,"SKILL.md");await I_(x).then(w=>w.isFile()).catch(()=>!1)&&l.push(U_(f))}return{skills:l}}async addSkills(e){let r=vr(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],l=new Map(c.map((x,p)=>[x.skillId,p])),f=[];for(let x of o){let p=await $c({agentId:r,workspace:i.workspace,framework:i.framework,skill:x});Vc(c,l,p),f.push(x)}return await ls(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:f}}async removeSkills(e){_n(e._meta,"_agent/removeSkills");let r=vr(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],l=[];for(let f of c){if(!o.has(f.skillId)){l.push(f);continue}let x=Dt(i.workspace,f.relPath);await S_(x,{recursive:!0,force:!0}),Ie.info("skill removed",{agentId:r,skillId:f.skillId,relPath:f.relPath})}return await ls(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,Ie.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,Ie.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l}),x.stop(r).catch(p=>Ie.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 Ie.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await Ne(r);if(!i)throw new k("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Ie.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await or(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Ie.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new k("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Qe(i),Ie.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async upgradeBridge(e){let r=e.agentId||e._meta?.cozeAgentId;if(!r)throw new k("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await Ne(r))throw new k("AGENT_NOT_FOUND",`agent not found: ${r}`);let o=["-y"];e.registry&&Ti(e.registry)&&o.push(`--registry=${e.registry}`);let c=L_(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let l=e._meta?.cozeEnv;l&&D_.test(l)&&o.push("--env",l);let f=await N_(o);return Ie.info("_agent/upgrade: spawned bridge upgrade process",{agentId:r,pid:f,targetVersion:c,currentVersion:e.currentVersion??"",reason:e.reason??""}),{ok:!0,accepted:!0,pid:f,message:"bridge upgrade started"}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new k("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Ne(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Qe(i),Ie.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}):(Ie.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(_n(e._meta,"_agent/switchModel"),!e.agentId)throw new k("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=zc(e.model)??yt,i=await Ne(e.agentId);if(!i)throw new k("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Qe(i),Ie.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Ie.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=>Ie.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(l)}));let c=[];for(let[l,f]of o.allSessionQueues())c.push(f.enqueue(async()=>{let x=o.sessions.get(l);x?.downstream&&(await x.downstream.stop(`switchModel: ${r}`).catch(()=>{}),x.downstream=void 0)}));return await Promise.all(c),Ie.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(_n(e._meta,_t.RESET),!e.agentId)throw new k("IPC_BAD_REQUEST",`${_t.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,_t.RESET),await this.runDetailSync(e.agentId,_t.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),Ie.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 ti(e,o)}async clearPersistedAcpSessionIds(e){let r=await Ne(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 Qe(r)}async repairAgent(e){if(_n(e._meta,_t.REPAIR),!e.agentId)throw new k("IPC_BAD_REQUEST",`${_t.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new k("IPC_BAD_REQUEST",`${_t.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){Ie.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,_t.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){Ie.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Ie.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){_n(e._meta,"_agent/getFileTree");let r=e._meta,i=vr(r),o=await this.resolveWorkspace(i),c=e.filePath??"",l=this.safeJoin(o,c),f=await Gc(l).catch(()=>null);if(!f)throw new k("IPC_BAD_REQUEST",`path not found: ${c}`);if(f.isSymbolicLink())throw new k("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await ei(l,o))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let x=Z_(e.depth);return f.isDirectory()?{tree:await Y_(o,l,c,x)}:{tree:[{name:X_(c),path:Xf(c||"."),isDir:!1,size:f.size,modifiedAt:Math.floor(f.mtimeMs)}]}}async getFileContent(e){_n(e._meta,"_agent/getFileContent");let r=vr(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new k("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await Gc(o).catch(()=>null);if(!c||!c.isFile())throw new k("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new k("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await ei(o,i))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Wf)throw new k("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Wf})`);let l=await Kf(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 Ne(e).catch(()=>null))?.workspace??Xe(e).workspace}safeJoin(e,r){let i=Hc(e,r||"."),o=Kc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${$f}`))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return Ne(e)}async requireAgentCfg(e){let r=await this.loadAgentCfg(e);if(!r)throw new k("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function M_(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new k("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new k("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function B_(t){return t==="claude-code"?Dt(".claude","skills"):Dt(".agents","skills")}var z_=3e4,F_=50*1024*1024,Ir=3e4;async function $c(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new k("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 k("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let f=M_(o.skillName),x=B_(i),p=Dt(x,f),w=Dt(r,p);if(await qc(w,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");Di(S.length),await jc(Dt(w,"SKILL.md"),S,"utf8")}else{let S=await G_(o.downloadUrl);j_(S)?await $_(S,w):H_(S)?await W_(S,w):await jc(Dt(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 Ie.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:p,source:c?"content":"downloadUrl"}),_}function Vc(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 U_(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 G_(t){if(!t)throw new k("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Di(e);let r=q_(t);return Di(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await Kf(e);return Di(r.length),r}if(Ti(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),z_);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new k("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 k("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Di(t){if(t>F_)throw new k("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function q_(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new k("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 j_(t){return t.length>=2&&t[0]===31&&t[1]===139}function H_(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 Wc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function W_(t,e){let r,i;try{r=new Yf.default(t),i=r.getEntries()}catch(l){throw new k("IPC_BAD_REQUEST",`zip parse failed: ${l.message}`,{cause:l})}for(let l of i){let f=l.entryName;if(!f||Wc(f))continue;if(f.startsWith("/")||/^[A-Za-z]:[\\/]/.test(f))throw new k("IPC_BAD_REQUEST",`zip entry absolute path: ${f}`);if(f.split(/[/\\]/).some(p=>p===".."))throw new k("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${f}`);let x=l.header.attr>>>16&61440;if(x!==0&&x!==32768&&x!==16384)throw new k("IPC_BAD_REQUEST",`zip entry kind 0x${x.toString(16)} not allowed (symlink/hardlink/special): ${f}`)}let o=K_(i),c=Hc(e);for(let l of i){if(Wc(l.entryName))continue;let f=l.entryName;if(o&&f.startsWith(o)&&(f=f.slice(o.length)),!f)continue;let x=Hc(e,f),p=Kc(c,x);if(p.startsWith("..")||p==="..")throw new k("IPC_BAD_REQUEST",`zip entry escapes destDir: ${f}`);if(l.isDirectory){await qc(x,{recursive:!0});continue}await qc(A_(x),{recursive:!0});let w;try{w=l.getData()}catch(_){throw new k("IPC_BAD_REQUEST",`zip entry getData failed (${l.entryName}): ${_.message}`,{cause:_})}await jc(x,w)}}function K_(t){let e;for(let r of t){let i=r.entryName;if(!i||Wc(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 $_(t,e){await V_(t);let r=vf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new k("IPC_BAD_REQUEST",`tar extract timeout (${Ir}ms)`))},Ir);try{await Jf(Vf.from(t),r)}catch(c){throw c instanceof k?c:i?new k("IPC_BAD_REQUEST",`tar extract timeout (${Ir}ms)`):new k("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function V_(t){let e=[],r=br({onReadEntry:c=>{let l=c.path,f=c.type;if(f!=="File"&&f!=="Directory"){e.push(`tar entry kind '${f}' not allowed (symlink/hardlink/special): ${l.slice(0,100)}`);return}if(l.startsWith("/")||l.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(l)){e.push(`tar entry absolute path: ${l}`);return}l.split(/[/\\]/).some(p=>p==="..")&&e.push(`tar entry contains '..': ${l}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new k("IPC_BAD_REQUEST",`tar list timeout (${Ir}ms)`))},Ir);try{await Jf(Vf.from(t),r)}catch(c){throw i?new k("IPC_BAD_REQUEST",`tar list timeout (${Ir}ms)`):new k("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new k("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var J_=5e3;async function Y_(t,e,r,i){return Zf(t,e,r,i,{count:0})}async function Zf(t,e,r,i,o){if(i<=0)return[];let c;try{c=await v_(e,{withFileTypes:!0})}catch{return[]}let l=[];for(let f of c){if(R_.has(f.name)||f.isSymbolicLink())continue;if(o.count>=J_){l.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let x=Dt(e,f.name),p=C_(Dt(r,f.name)),w=null;try{w=await Gc(x)}catch{continue}if(w.isSymbolicLink())continue;o.count++;let _={name:f.name,path:Xf(Kc(t,x)),isDir:w.isDirectory(),size:w.size,modifiedAt:Math.floor(w.mtimeMs)};w.isDirectory()&&i>1&&(_.children=await Zf(t,x,p,i-1,o)),l.push(_)}return l.sort((f,x)=>f.isDir!==x.isDir?f.isDir?-1:1:f.name.localeCompare(x.name)),l}function Z_(t){return!t||t<=0?T_:Math.min(t,k_)}function X_(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function Xf(t){return t.split($f).join("/")}ne();import{readFileSync as UA}from"node:fs";import{dirname as qA,join as jA}from"node:path";import{fileURLToPath as WA}from"node:url";var Ar="0.1.104-alpha.14";var yn=q("agent-health-reporter"),Q_=1e4,Pi=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??Q_}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()}),yn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),yn.info("heartbeat stopped"))}async tick(){if(this.inFlight){yn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){yn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let r=[];for(let l of this.opts.core.agents.values()){let f=ey(l);if(!f)continue;let x={agentId:l.agentId,status:f};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:Ar,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(l){yn.warn("heartbeat batch send failed",{count:r.length,err:String(l)})}let c=o?.authFailures;if(c&&c.length>0&&(yn.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){yn.warn("onAuthFailures callback failed (ignored)",{err:String(l)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){yn.warn("onTickEnd hook failed",{err:String(r)})}}};function ey(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}sn();import{chmod as Wy,mkdir as go,rm as Ky,stat as $y,writeFile as Vy}from"node:fs/promises";import{homedir as Jy}from"node:os";import{join as A0}from"node:path";rn();import{existsSync as xy}from"node:fs";import{release as hy}from"node:os";import{basename as py,isAbsolute as gy}from"node:path";function Oi(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Cr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Tr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function En(t,e){return{jsonrpc:"2.0",id:t,error:e}}Ke();var ao=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,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32022};function Qf(t){return"method"in t&&"id"in t&&t.id!==void 0}function e0(t){return"method"in t&&!("id"in t)}function co(t){return!("method"in t)&&"id"in t}var ty={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,METHOD_NOT_FOUND:ee.METHOD_NOT_FOUND,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,OPERATION_NOT_ALLOWED_FOR_CLOUD:ee.OPERATION_NOT_ALLOWED_FOR_CLOUD,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 ny(t){if(t!=null)return t instanceof Error?{name:t.name,message:Li(t.message)}:typeof t=="string"?Li(t):typeof t=="object"?iy(t):t}var ry=[[/\/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 Li(t){let e=t;for(let[r,i]of ry)e=e.replace(r,i);return e}function iy(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Li(i):e[r]=i;return e}function Ni(t){if(t instanceof k){let e=ny(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:ty[t.code]??ee.INTERNAL_ERROR,message:Li(t.message),data:r}}return{code:ee.INTERNAL_ERROR,message:Li(t instanceof Error?t.message:String(t))}}function t0(t){let e=t.data,r=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:l,...f}=e;c=f}return new k(r,o,{retriable:e?.retriable??!1,cause:c})}function r0(t){return`${JSON.stringify(t)}
93
+ `}var n0=10*1024*1024,lo=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>n0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${n0} 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 s0={"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","session/set_mode":"session.setMode",initialize:"initialize"},nC=Object.fromEntries(Object.entries(s0).map(([t,e])=>[e,t])),sy={"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"],"session.setMode":["agentId","sessionId"],"agent.pair":[],initialize:[]},kr=class{seq=0;next(e,r){this.seq+=1;let i=s0[e]??oy(e),o=sy[i]??[],c=[i,String(this.seq)];if(o.length>0){let l=o.map(x=>i0(r?.[x]??"")),f=ay(l).join(":");f&&c.push(f)}else r&&Object.values(r).some(l=>l)&&c.push(Object.values(r).filter(Boolean).map(l=>i0(String(l))).join(":"));return c.join("_")}reset(){this.seq=0}};function oy(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function i0(t){return t.replace(/[:_\s]+/g,"-")}function ay(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}Qr();import{readFileSync as cy}from"node:fs";var dy=384;async function Jc(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await sr(t.agentEnvFile,r,{mode:dy})}function Yc(t){try{let e=JSON.parse(cy(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function o0(t,e,r={},i=o=>o){return{...i({...t,...Yc(e)}),...r}}Kt();er();Ke();ne();Pe();import{execFileSync as ly,spawnSync as uy}from"node:child_process";function Mi(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function Bi(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),uy("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var Zc=new Set;function a0(t){typeof t=="number"&&t>0&&Zc.add(t)}function c0(t){typeof t=="number"&&Zc.delete(t)}function d0(){for(let t of Zc)Bi(t,"SIGKILL")}var Rr="coze-bridge-daemon";function l0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return ly("pgrep",["-U",String(o),"-f",Rr],{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 u0(t,e){if(t.length===0)return;let r=e?.killFn??Bi,i=e?.isAliveFn??Mi,o=e?.sleepFn??(f=>new Promise(x=>setTimeout(x,f))),c=e?.graceMs??3e3,l=e?.pollMs??100;for(let f of t)r(f,"SIGTERM");for(let f=0;f<c&&t.some(x=>i(x));f+=l)await o(Math.min(l,c-f));for(let f of t)i(f)&&r(f,"SIGKILL")}var fy=[{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 f0(t,e){if(!e)return null;for(let r of fy)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function x0(t,e){return f0(t,e)}function h0(t,e){return f0(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 p0(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 g0=We("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),my=200,wy=40,_y=We("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),yy=We("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),Ey=We("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),by=We("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),vy=We("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Sy=We("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),m0=500;function Iy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=m0?t:`${e.slice(0,m0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Ay(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 w0(t){try{return xy(t)}catch{return}}function Cy(t,e){return{platform:process.platform,osRelease:hy(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:gy(e.command)?w0(e.command):void 0,cwd:e.cwd,cwdExists:w0(e.cwd),envKeys:e.envKeys}}function Ty(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${py(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Pt=class{constructor(e){this.opts=e;this.log=q(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new lo({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new kr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new k("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=o0(process.env,this.opts.agentEnvFile??Q().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=nt(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,a0(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>my&&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,c0(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 f of this.decoder.flush())this.dispatch(f)}catch(f){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(f)})}this.failAllPending(this.buildExitError(o,c));for(let f of this.exitHandlers)f(o,c)}),i.on("error",o=>{let c=o,l=Cy(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 k("AGENT_SPAWN_FAILED",Ty(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()));Bi(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Bi(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:vy,phase2GateMs:_y,livenessWindowMs:yy,absoluteMaxMs:Ey,approvalMaxMs:Sy,suspendThresholdMs:by,...r};return this.call("session/prompt",e,g0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Cr("session/cancel",e))}setSessionMode(e){return this.call("session/set_mode",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(Tr(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(En(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=g0,o){if(!this.child||this.stopped)return Promise.reject(new k("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),l=Oi(c,e,r),f=(()=>{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:f};w.promptTimeout=S;let y=()=>{let v={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},I=this.now(),C=p0(v,S.cfg,I),R=O=>{S.armedAt=I,S.expectedIntervalMs=O,w.timer=setTimeout(y,O)};if(C.action==="suspend"){S.suspendedMs+=C.suspendedDeltaMs,S.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:C.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),R(C.rearmMs);return}if(C.action==="continue"){R(C.rearmMs);return}this.pending.delete(c),C.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:C.awaitingApproval,...S.sessionId?{sessionId:S.sessionId}:{}}),p(C.awaitingApproval?new k("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new k("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 k("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};w.timer=setTimeout(y,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 k("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 k("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(r0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(co(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 k("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:Iy(e.result)}),r.resolve(e.result));return}if(e0(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(Qf(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,f=l==="completed"||l==="failed"||l==="cancelled";o==="tool_call"&&!f?e.activeToolCalls.add(c):f&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(En(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(En(e.id,Ni(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=t0(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=h0(this.framework,Ay(e));return i?new k(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 k("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(wy).join(`
96
+ `),o=x0(this.framework,i);return o?new k(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new k("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 ky(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 uo=class extends Pt{framework="claude-code";constructor(e){let{command:r,args:i}=Xr("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 ky(e)}};rn();import{mkdtempSync as Ry,rmSync as Dy}from"node:fs";import{tmpdir as Py}from"node:os";import{join as Oy}from"node:path";var fo=class extends Pt{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=Xr("codex",e.command,i),l=e.isolateCodexHome?Ry(Oy(Py(),"coze-bridge-codex-home-")):void 0,f=l?{...e.env??{},CODEX_HOME:l}:e.env,x={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...f?{env:f}:{}};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{Dy(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};Ke();var Ly=3e4,Pr=class extends Pt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},Ly))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new k("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var _0=["default","acceptEdits","plan","auto","bypassPermissions"],y0=["read-only","auto","full-access"];function bn(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return _0.includes(e);case"codex":return y0.includes(e);case"openclaw":return!1}}function Xc(t){switch(t){case"claude-code":return _0.join("/");case"codex":return y0.join("/");case"openclaw":return""}}Ke();ne();Pe();function Qc(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}rn();var vn=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 xo=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 vn,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)zi(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 zi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function $t(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Kt();ne();import{constants as E0}from"node:fs";import{access as Ny}from"node:fs/promises";import{delimiter as My,join as By}from"node:path";var Et=q("framework-detector"),b0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},zy=[".exe",".cmd",".bat",".ps1"],jn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??nt,access:e.access??Ny}}async detect(e){let r=b0[e],i=await this.which(r);if(!i)return Et.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,l]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),f={path:i,version:c};return l&&(f.defaultAgent=l),f}async detectAll(){let e=await Promise.all(Object.keys(b0).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(My).filter(Boolean),i=this.env.platform==="win32"?["",...zy]:[""];for(let o of r)for(let c of i){let l=By(o,e+c);if(await this.isExecutable(l))return l}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?E0.F_OK:E0.X_OK;return await this.env.access(e,r),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let r=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!r)return Et.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return Et.warn("openclaw default agent probe: non-zero exit",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)}),null;let i=r.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return Et.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:r.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return Et.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(l=>l?.isDefault===!0);return c?!c.id||!c.workspace?(Et.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(Et.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return Et.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let r=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!r)return Et.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||Et.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let l=JSON.parse(c[0]);typeof l.gateway?.port=="number"&&(o.port=l.gateway.port),typeof l.service?.runtime?.status=="string"&&(o.runtime=l.service.runtime.status),!i&&typeof l.rpc?.error=="string"&&(o.detail=l.rpc.error)}catch(l){Et.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(l)})}return o}async probeVersion(e,r=[]){let i=await this.runProbe(e,[...r,"--version"]);return i&&(Uy(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,l,f=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"),f(null)},15e3),x.stdout?.on("data",p=>{o+=p.toString("utf8")}),x.on("error",()=>f(null)),x.on("close",p=>f({code:p,stdout:o}))}catch{f(null)}})}},Fy=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function Uy(t){return t.replace(Fy,"")}import{homedir as Gy}from"node:os";import{join as qy}from"node:path";Kt();er();Ke();Qr();ne();async function I0(){let t=qy(Gy(),".openclaw/openclaw.json");return(await ir(t))?.gateway?.auth?.token??""}var v0=q("openclaw.config"),jy=[0,5e3,5e3],Hy=We("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),S0="models.providers.",ho="agents.defaults.models",po=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new vn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??jy,this.cliTimeoutMs=e.cliTimeoutMs??Hy}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,v0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(l)})}}throw new k("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=nt(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",l=!1,f=p=>{l||(l=!0,clearTimeout(x),p())};o.stderr?.on("data",p=>{c+=p.toString("utf8")});let x=setTimeout(()=>{f(()=>{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=>f(()=>i(p))),o.on("close",p=>f(()=>{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){v0.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",`${S0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${S0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${ho}[${e}]`,()=>this.runCli(["config","set",ho,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${ho}[${e}]`,`${ho}.${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 le=q("agent-manager"),td="acceptEdits",k0="full-access",R0="read-only";function Yy(t){switch(t){case"read-only":return["-c",'sandbox_mode="read-only"',"-c",'approval_policy="on-request"'];case"auto":return["-c",'sandbox_mode="workspace-write"',"-c",'approval_policy="on-failure"'];case"full-access":return["-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"']}}var Zy=(t,e,r,i,o,c,l,f,x,p)=>{switch(t){case"claude-code":{let w={...o?{...Ff(o),...qf(o,l,f)}:{},...x??{},IS_SANDBOX:"1"};return new uo({cwd:r,env:w,agentId:i})}case"codex":{let w=o?[...Uf(o),...Hf(o,l,f)]:[],_=k0;p!==void 0&&(bn("codex",p)?_=p:le.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:p}));let S=[...w,...Yy(_)],y={...o?Gf(o):{},...x??{}},v=!!o;return new fo({cwd:r,agentId:i,...S.length>0?{extraArgs:S}:{},...Object.keys(y).length>0?{env:y}:{},...v?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Pr({command:e,cwd:r,agentId:i,...c?{sessionName:Qc(c)}:{}})}};function ed(t){return t==="claude-code"||t==="codex"}function Xy(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(Qy(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
97
97
  `)}
98
- `}function Xy(t){if(t.includes(`
99
- `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var Qy={path:"",version:"cloud-deployed"},A0="openclaw_gateway_unavailable",eb="openclaw_default_agent_missing";function I0(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 tb={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},nb=6e4,wo=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??Zy,this.createTimeoutMs=e.createTimeoutMs??nb,this.detectorFactory=e.detectorFactory??(()=>new Wn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new mo({command:r})),this.openclawConfigDir=e.openclawConfigDir??S0(Vy(),".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=>{ue.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=S0(e,".env");if(await $y(r).then(c=>c.isFile()).catch(()=>!1)){ue.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}let o=Jy({...process.env,...Jc(this.paths.agentEnvFile)});await sn(r,o,{mode:384}),ue.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),ue.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=await Me(e.agentId,this.paths).catch(()=>null),o=ro(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let c=this.registry.get(e.agentId);if(c){if(c.framework!==e.framework)throw new C("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")ue.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(R=>ue.warn("dispose stale agent failed (ignored)",{err:String(R)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")ue.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(R=>ue.warn("dispose drifted agent failed (ignored)",{err:String(R)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){ue.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let R=await Me(e.agentId,this.paths).catch(()=>null);R&&(R.patToken=e.patToken,await Qe(R,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){ue.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let R=await Me(e.agentId,this.paths).catch(()=>null);R&&(R.modelInfo=e.modelInfo,await Qe(R,this.paths))}return ue.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!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 f=Xe(e.agentId,this.paths),x=o?"cloud":"local",p=e.framework==="openclaw"&&x==="local",m;p&&!r?.revive&&(m=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let _=m??(p?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),S=e.workspace??_??f.workspace,y=new AbortController,v=setTimeout(()=>y.abort(new C("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),A,I=!1;try{o&&nd(e.framework)&&await sr(e.framework,y.signal);let R=()=>{if(y.signal.aborted)throw y.signal.reason instanceof Error?y.signal.reason:new C("AGENT_TIMEOUT","_agent/create aborted")};await td(f.root,{recursive:!0}),await td(S,{recursive:!0}),await td(f.logs,{recursive:!0}),R(),p||await cr(S,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(x==="cloud"?await Ca(S,"cloud"):await Ca(S,"local",rd)),R();let D=i,E=Nf({model:e.model??D?.model}),k=vf(e._meta)??D?.accountId,P=e.patToken??D?.patToken,F=x==="cloud"?e.modelInfo??D?.modelInfo:void 0;if(A=new po({agentId:e.agentId,framework:e.framework,workspace:S,model:E.model??yt,deployType:x,...k?{accountId:k}:{},...P?{patToken:P}:{},...F?{modelInfo:F}:{}}),A.status="ok",D?.sessions){let $=x==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[Z,ie]of Object.entries(D.sessions)){let oe={acpSessionId:ie.acpSessionId,modelToken:ie.modelToken,tokenGeneratedAt:ie.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};$?ie.permissionMode===void 0?(oe.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",ue.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:Z,framework:e.framework,fallback:oe.permissionMode})):Sn(e.framework,ie.permissionMode)?oe.permissionMode=ie.permissionMode:ue.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:Z,framework:e.framework,value:ie.permissionMode}):ie.permissionMode!==void 0&&ue.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:Z,framework:e.framework,deployType:x}),ie.cozeGroupId&&(oe.cozeGroupId=ie.cozeGroupId),A.sessions.set(Z,oe)}let te=Object.keys(D.sessions).length;te>0&&ue.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:te})}this.registry.register(A),I=!0;let z={agentId:e.agentId,framework:e.framework,workspace:S,cozeIdentity:e.cozeIdentity,createdAt:D?.createdAt??Date.now(),sessions:D?.sessions??{},model:E.model};x==="cloud"&&(z.deployType="cloud"),k&&(z.accountId=k),P&&(z.patToken=P),F&&(z.modelInfo=F),D?.skills&&(z.skills=D.skills),D?.agentName&&(z.agentName=D.agentName),D?.description&&(z.description=D.description),e.framework==="openclaw"&&x==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,S)):ue.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let Y=e.initialSkills??[];if(Y.length>0){let $=[...z.skills??[]],te=new Map($.map((oe,L)=>[oe.skillId,L])),Z=await Promise.allSettled(Y.map(oe=>Vc({agentId:e.agentId,workspace:S,framework:e.framework,skill:oe}))),ie=0;for(let[oe,L]of Z.entries()){let G=Y[oe];G&&(L.status==="fulfilled"?(Yc($,te,L.value),ie++):ue.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:G.skillId,skillName:G.skillName,err:String(L.reason)}))}ie>0&&(z.skills=$,ue.info("initialSkills installed",{agentId:e.agentId,installed:ie,requested:Y.length}))}return await Qe(z,this.paths),ue.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:x}),{ok:!0,agentId:e.agentId,workspace:S,framework:e.framework}}catch(R){throw ue.error("agent create failed, rolling back",{agentId:e.agentId,err:String(R)}),I&&A&&(await A.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Ky(f.root,{recursive:!0,force:!0}).catch(D=>ue.warn("rm agent dir failed (ignored)",{err:String(D)})),R instanceof C?R:new C("AGENT_SPAWN_FAILED",String(R),{cause:R})}finally{clearTimeout(v)}}async spawnSessionDownstream(e,r,i,o,c){let f=this.config.frameworksCache?.[e.framework];if(!f)if(e.deployType==="cloud"&&nd(e.framework))f=Qy;else throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);nd(e.framework)&&!ds(e.framework)&&(ue.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await sr(e.framework));let x=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,p;if(e.framework==="openclaw")p=await this.buildOpenclawDownstream({session:e,modelConfig:x,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:f.path});else{let m=e.sessions.get(i),_=$t(e)?m?.permissionMode??T0:"full-access";p=this.factory(e.framework,f.path,e.workspace,e.agentId,x,i,o,c,this.buildBinShimPathEnv(),_)}try{return await p.start(),await p.initialize(tb),p}catch(m){let _=p instanceof Pt?p.getStderrTail():[];throw _.length>0&&ue.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:m instanceof C?m.code:"unknown",recentStderr:_}),await p.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,f.path,m)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new C("AGENT_ENV_NOT_READY",I0(o),{cause:{reason:A0}})}catch(o){ue.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof C?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};ue.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 ue.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:eb}})}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",I0(r),{cause:{reason:A0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:u,command:f}=e,x=ed(o);if(r.deployType==="local"){let S=await this.ensureOpenclawDefaultAgent();return new Lr({command:f,cwd:S.workspace,agentId:S.id,sessionName:x})}let p=await v0(),m=i?qf(i,c,u):null,_;if(m){let S=qc(o),v=m.models[0]?.id??yt,A=`${S}/${v}`;if(!this.ensuredProviders.has(A)){let I=this.getOpenclawConfig();await I.ensureProvider(S,m),await I.addModelToAllowlist(A),this.ensuredProviders.add(A)}_=A}return new Lr({command:f,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=qc(i),c=`${o}/${e.model}`,u=!0;try{await r.removeProvider(o)}catch(f){u=!1,ue.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(f)})}try{await r.removeModelFromAllowlist(c)}catch(f){u=!1,ue.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(f)})}u&&this.ensuredProviders.delete(c)}}};import{randomUUID as O0}from"node:crypto";import{promises as ub}from"node:fs";import{basename as L0}from"node:path";We();ne();import{promises as ib}from"node:fs";import{basename as sb}from"node:path";var R0=q("file-upload"),ob="/api/coze_claw/file/agent_upload",ab=6e4;async function k0(t,e={}){let i=`${so(ao(e.handshakeBase))}${ob}`,o=e.timeoutMs??ab,c=await ib.readFile(t.path),u=new FormData;u.append("agent_id",t.agentId),u.append("session_id",t.sessionId),u.append("file_name",t.name),u.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let f={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...Ir(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},x=new AbortController,p=setTimeout(()=>x.abort(),o);R0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let m=await fetch(i,{method:"POST",headers:f,body:u,signal:x.signal}),_=m.headers.get("x-tt-logid")??"";if(!m.ok){let v=await m.text().catch(()=>"");throw new C("UPLOAD_FAILED",`upload HTTP ${m.status} logid=${_}: ${v.slice(0,200)}`)}let S=await m.json();if(S.code!==void 0&&S.code!==0)throw new C("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${_}`);let y=S.data?.file?.file_url;if(!y)throw new C("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${_}: ${JSON.stringify(S).slice(0,200)}`);return R0.info("file upload ok",{uri:y,logid:_}),{uri:y}}catch(m){throw m instanceof C?m:m.name==="AbortError"?new C("UPLOAD_FAILED",`upload timeout (${o}ms) for ${sb(t.path)}`):new C("UPLOAD_FAILED",String(m),{cause:m})}finally{clearTimeout(p)}}We();ne();import{extname as cb}from"node:path";var db={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".svg":"image/svg+xml",".bmp":"image/bmp",".ico":"image/x-icon",".heic":"image/heic",".heif":"image/heif",".pdf":"application/pdf",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".txt":"text/plain",".md":"text/markdown",".markdown":"text/markdown",".json":"application/json",".yaml":"text/yaml",".yml":"text/yaml",".csv":"text/csv",".html":"text/html",".htm":"text/html",".xml":"application/xml",".log":"text/plain",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".tgz":"application/gzip",".mp3":"audio/mpeg",".wav":"audio/wav",".mp4":"video/mp4",".mov":"video/quicktime",".webm":"video/webm"};async function D0(t){let e=cb(t).toLowerCase();return db[e]??"application/octet-stream"}Oe();var _o=q("agent-send"),P0=50*1024*1024;function N0(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 M0(t,e,r,i,o,c){let f;for(let x=0;x<=2;x++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(p){f=p,x<2&&(_o.warn("sendAgentFileUpdate failed, retrying",{attempt:x+1,err:String(p)}),await new Promise(m=>setTimeout(m,5e3)))}throw new C("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(f)}`,{cause:f})}async function B0(t,e){let{session:r,runtime:i}=N0(e.core,t.agentId,t.sessionId);if(!await ti(t.path,r.workspace))throw new C("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await ub.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>P0)throw new C("FILE_TOO_LARGE",`${o.size} bytes > limit ${P0}`);let c=await D0(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 u=t.name??L0(t.path),f;try{f=await k0({patToken:r.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:u,sizeBytes:o.size,...r.accountId?{accountId:r.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(p){throw _o.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 x={sessionUpdate:"agent_file",messageId:O0(),content:{type:t.kind==="image"?"image":"resource",uri:f.uri,mimeType:c,name:u,sizeBytes:o.size,...f.fileId!==void 0?{fileId:f.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await M0(e,r,i,t.sessionId,x,"agent file uploaded to cloud but sendAgentFileUpdate failed"),_o.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:u,bytes:o.size,mime:c,uri:f.uri}),{ok:!0,uri:f.uri,bytes:o.size,mimeType:c,...f.fileId!==void 0?{fileId:f.fileId}:{}}}async function z0(t,e){let{session:r,runtime:i}=N0(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??L0(t.path),c={sessionUpdate:"group_file",messageId:O0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await M0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),_o.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 F0(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 u=r[c]??0,f=i[c]??0;if(u<f)return!0;if(u>f)return!1}return!1}rn();Kt();ne();var Ot=q("coze-cli-installer"),U0="@coze/cli@latest",lb="coze",q0="0.1.8",fb=5e3,xb=5e3,hb=9e4,G0=1e4,Ui=null,yo=!1;async function id(t,e={}){if(yo)return;if(Ui)return Ui;let r=e.exec??Cf;return Ui=(async()=>{try{let i=await pb(lb,r),o=!1;if(i){let u=await gb(r);if(u===void 0)Ot.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(F0(u,q0))Ot.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:u,min:q0}),o=!0;else{Ot.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:u}),yo=!0;return}}let c=o?"upgrade-only":"full";Ot.info("coze-cli install start",{package:U0,mode:c});try{await r("npm",["i","-g","--prefer-online",U0],{timeout:hb,maxBuffer:10*1024*1024}),Ot.info("coze-cli install ok")}catch(u){Ot.warn("coze-cli install failed (skip subsequent steps)",{err:String(u)});return}if(o){yo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:G0}),Ot.info("coze config set xTTEnv ok",{env:t.env})}catch(u){Ot.warn("coze config set failed (continue to auth login)",{err:String(u)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:G0}),Ot.info("coze auth login ok")}catch(u){Ot.warn("coze auth login failed",{err:String(u)});return}yo=!0}finally{Ui=null}})(),Ui}async function pb(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:fb});return Ia(i)}catch{return}}async function gb(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:xb});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}on();Oe();var mb=10*6e4;function H0(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?mb:e}function bo(t){return or(t??X().configFile)}function qi(t,e){return ar(e??X().configFile,t)}import{randomBytes as Bb}from"node:crypto";nr();We();ne();import{createReadStream as wb}from"node:fs";import{mkdir as _b,readFile as yb,realpath as bb,stat as Eb,writeFile as vb}from"node:fs/promises";import{basename as Sb,dirname as sd,isAbsolute as Ab,join as Ib,relative as Tb,resolve as j0,sep as Cb}from"node:path";import{createInterface as Rb}from"node:readline";var K0=q("fs-rpc"),Gi=je("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function $0(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Gi)throw new C("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Gi} bytes`);let i=await Y0(t.path,e);return await _b(sd(i),{recursive:!0}),await vb(i,t.content,"utf8"),K0.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function V0(t,e){let r=await Y0(t.path,e),i=await Eb(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Gi&&!o)throw new C("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Gi} bytes`);let c;if(o&&i.size>Gi)c=await kb(r,t.line??1,t.limit);else{let u=await yb(r,"utf8");if(o){let f=u.split(`
98
+ `}function Qy(t){if(t.includes(`
99
+ `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var eE={path:"",version:"cloud-deployed"},C0="openclaw_gateway_unavailable",tE="openclaw_default_agent_missing";function T0(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 nE={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},rE=6e4,mo=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??Zy,this.createTimeoutMs=e.createTimeoutMs??rE,this.detectorFactory=e.detectorFactory??(()=>new jn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new po({command:r})),this.openclawConfigDir=e.openclawConfigDir??A0(Jy(),".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 k("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=>{le.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=A0(e,".env");if(await $y(r).then(c=>c.isFile()).catch(()=>!1)){le.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}await go(e,{recursive:!0});let o=Xy({...process.env,...Yc(this.paths.agentEnvFile)});if(await Vy(r,o,"utf8"),process.platform!=="win32")try{await Wy(r,384)}catch(c){le.warn("chmod ~/.openclaw/.env to 0600 failed (ignored)",{err:String(c)})}le.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),le.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new k("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new k("IPC_BAD_REQUEST","framework required");let i=await Ne(e.agentId,this.paths).catch(()=>null),o=to(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let c=this.registry.get(e.agentId);if(c){if(c.framework!==e.framework)throw new k("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")le.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(R=>le.warn("dispose stale agent failed (ignored)",{err:String(R)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")le.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(R=>le.warn("dispose drifted agent failed (ignored)",{err:String(R)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){le.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let R=await Ne(e.agentId,this.paths).catch(()=>null);R&&(R.patToken=e.patToken,await Qe(R,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){le.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let R=await Ne(e.agentId,this.paths).catch(()=>null);R&&(R.modelInfo=e.modelInfo,await Qe(R,this.paths))}return le.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new k("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let f=Xe(e.agentId,this.paths),x=o?"cloud":"local",p=e.framework==="openclaw"&&x==="local",w;p&&!r?.revive&&(w=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let _=w??(p?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),S=e.workspace??_??f.workspace,y=new AbortController,v=setTimeout(()=>y.abort(new k("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),I,C=!1;try{o&&ed(e.framework)&&await rr(e.framework,y.signal);let R=()=>{if(y.signal.aborted)throw y.signal.reason instanceof Error?y.signal.reason:new k("AGENT_TIMEOUT","_agent/create aborted")};await go(f.root,{recursive:!0}),await go(S,{recursive:!0}),await go(f.logs,{recursive:!0}),R(),p||await or(S,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(x==="cloud"?await Ca(S,"cloud"):await Ca(S,"local",td)),R();let O=i,E=Bf({model:e.model??O?.model}),D=If(e._meta)??O?.accountId,L=e.patToken??O?.patToken,F=x==="cloud"?e.modelInfo??O?.modelInfo:void 0;if(I=new xo({agentId:e.agentId,framework:e.framework,workspace:S,model:E.model??yt,deployType:x,...D?{accountId:D}:{},...L?{patToken:L}:{},...F?{modelInfo:F}:{}}),I.status="ok",O?.sessions){let V=x==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[Z,ie]of Object.entries(O.sessions)){let oe={acpSessionId:ie.acpSessionId,modelToken:ie.modelToken,tokenGeneratedAt:ie.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};V?ie.permissionMode===void 0?(oe.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",le.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:Z,framework:e.framework,fallback:oe.permissionMode})):bn(e.framework,ie.permissionMode)?oe.permissionMode=ie.permissionMode:le.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:Z,framework:e.framework,value:ie.permissionMode}):ie.permissionMode!==void 0&&le.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:Z,framework:e.framework,deployType:x}),ie.cozeGroupId&&(oe.cozeGroupId=ie.cozeGroupId),I.sessions.set(Z,oe)}let te=Object.keys(O.sessions).length;te>0&&le.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:te})}this.registry.register(I),C=!0;let z={agentId:e.agentId,framework:e.framework,workspace:S,cozeIdentity:e.cozeIdentity,createdAt:O?.createdAt??Date.now(),sessions:O?.sessions??{},model:E.model};x==="cloud"&&(z.deployType="cloud"),D&&(z.accountId=D),L&&(z.patToken=L),F&&(z.modelInfo=F),O?.skills&&(z.skills=O.skills),O?.agentName&&(z.agentName=O.agentName),O?.description&&(z.description=O.description),e.framework==="openclaw"&&x==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,S)):le.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let J=e.initialSkills??[];if(J.length>0){let V=[...z.skills??[]],te=new Map(V.map((oe,N)=>[oe.skillId,N])),Z=await Promise.allSettled(J.map(oe=>$c({agentId:e.agentId,workspace:S,framework:e.framework,skill:oe}))),ie=0;for(let[oe,N]of Z.entries()){let j=J[oe];j&&(N.status==="fulfilled"?(Vc(V,te,N.value),ie++):le.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:j.skillId,skillName:j.skillName,err:String(N.reason)}))}ie>0&&(z.skills=V,le.info("initialSkills installed",{agentId:e.agentId,installed:ie,requested:J.length}))}return await Qe(z,this.paths),le.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:x}),{ok:!0,agentId:e.agentId,workspace:S,framework:e.framework}}catch(R){throw le.error("agent create failed, rolling back",{agentId:e.agentId,err:String(R)}),C&&I&&(await I.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Ky(f.root,{recursive:!0,force:!0}).catch(O=>le.warn("rm agent dir failed (ignored)",{err:String(O)})),R instanceof k?R:new k("AGENT_SPAWN_FAILED",String(R),{cause:R})}finally{clearTimeout(v)}}async spawnSessionDownstream(e,r,i,o,c){let f=this.config.frameworksCache?.[e.framework];if(!f)if(e.deployType==="cloud"&&ed(e.framework))f=eE;else throw new k("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);ed(e.framework)&&!as(e.framework)&&(le.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await rr(e.framework));let x=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,p;if(e.framework==="openclaw")p=await this.buildOpenclawDownstream({session:e,modelConfig:x,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:f.path});else{let w=e.sessions.get(i),_=$t(e)?w?.permissionMode??k0:"full-access";p=this.factory(e.framework,f.path,e.workspace,e.agentId,x,i,o,c,this.buildBinShimPathEnv(),_)}try{return await p.start(),await p.initialize(nE),p}catch(w){let _=p instanceof Pt?p.getStderrTail():[];throw _.length>0&&le.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:w instanceof k?w.code:"unknown",recentStderr:_}),await p.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,f.path,w)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new k("AGENT_ENV_NOT_READY",T0(o),{cause:{reason:C0}})}catch(o){le.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof k?i:new k("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};le.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 le.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 k("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:tE}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new k("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new k("AGENT_ENV_NOT_READY",T0(r),{cause:{reason:C0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:l,command:f}=e,x=Qc(o);if(r.deployType==="local"){let S=await this.ensureOpenclawDefaultAgent();return new Pr({command:f,cwd:S.workspace,agentId:S.id,sessionName:x})}let p=await I0(),w=i?jf(i,c,l):null,_;if(w){let S=Uc(o),v=w.models[0]?.id??yt,I=`${S}/${v}`;if(!this.ensuredProviders.has(I)){let C=this.getOpenclawConfig();await C.ensureProvider(S,w),await C.addModelToAllowlist(I),this.ensuredProviders.add(I)}_=I}return new Pr({command:f,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=Uc(i),c=`${o}/${e.model}`,l=!0;try{await r.removeProvider(o)}catch(f){l=!1,le.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(f)})}try{await r.removeModelFromAllowlist(c)}catch(f){l=!1,le.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(f)})}l&&this.ensuredProviders.delete(c)}}};import{randomUUID as N0}from"node:crypto";import{promises as uE}from"node:fs";import{basename as M0}from"node:path";Ke();ne();import{promises as sE}from"node:fs";import{basename as oE}from"node:path";var D0=q("file-upload"),aE="/api/coze_claw/file/agent_upload",cE=6e4;async function P0(t,e={}){let i=`${ro(so(e.handshakeBase))}${aE}`,o=e.timeoutMs??cE,c=await sE.readFile(t.path),l=new FormData;l.append("agent_id",t.agentId),l.append("session_id",t.sessionId),l.append("file_name",t.name),l.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let f={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...Sr(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},x=new AbortController,p=setTimeout(()=>x.abort(),o);D0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let w=await fetch(i,{method:"POST",headers:f,body:l,signal:x.signal}),_=w.headers.get("x-tt-logid")??"";if(!w.ok){let v=await w.text().catch(()=>"");throw new k("UPLOAD_FAILED",`upload HTTP ${w.status} logid=${_}: ${v.slice(0,200)}`)}let S=await w.json();if(S.code!==void 0&&S.code!==0)throw new k("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${_}`);let y=S.data?.file?.file_url;if(!y)throw new k("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${_}: ${JSON.stringify(S).slice(0,200)}`);return D0.info("file upload ok",{uri:y,logid:_}),{uri:y}}catch(w){throw w instanceof k?w:w.name==="AbortError"?new k("UPLOAD_FAILED",`upload timeout (${o}ms) for ${oE(t.path)}`):new k("UPLOAD_FAILED",String(w),{cause:w})}finally{clearTimeout(p)}}Ke();ne();import{extname as dE}from"node:path";var lE={".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 O0(t){let e=dE(t).toLowerCase();return lE[e]??"application/octet-stream"}Pe();var wo=q("agent-send"),L0=50*1024*1024;function B0(t,e,r){let i=t.get(e);if(!i)throw new k("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new k("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new k("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function z0(t,e,r,i,o,c){let f;for(let x=0;x<=2;x++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(p){f=p,x<2&&(wo.warn("sendAgentFileUpdate failed, retrying",{attempt:x+1,err:String(p)}),await new Promise(w=>setTimeout(w,5e3)))}throw new k("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(f)}`,{cause:f})}async function F0(t,e){let{session:r,runtime:i}=B0(e.core,t.agentId,t.sessionId);if(!await ei(t.path,r.workspace))throw new k("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await uE.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new k("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>L0)throw new k("FILE_TOO_LARGE",`${o.size} bytes > limit ${L0}`);let c=await O0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new k("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new k("UPSTREAM_NOT_READY","cloud WS not connected");let l=t.name??M0(t.path),f;try{f=await P0({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 wo.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:p instanceof k?p.code:"UNKNOWN",message:p instanceof Error?p.message:String(p)}),p}let x={sessionUpdate:"agent_file",messageId:N0(),content:{type:t.kind==="image"?"image":"resource",uri:f.uri,mimeType:c,name:l,sizeBytes:o.size,...f.fileId!==void 0?{fileId:f.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await z0(e,r,i,t.sessionId,x,"agent file uploaded to cloud but sendAgentFileUpdate failed"),wo.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:l,bytes:o.size,mime:c,uri:f.uri}),{ok:!0,uri:f.uri,bytes:o.size,mimeType:c,...f.fileId!==void 0?{fileId:f.fileId}:{}}}async function U0(t,e){let{session:r,runtime:i}=B0(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new k("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new k("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??M0(t.path),c={sessionUpdate:"group_file",messageId:N0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await z0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),wo.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 G0(t,e){let r=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(r.length,i.length);for(let c=0;c<o;c++){let l=r[c]??0,f=i[c]??0;if(l<f)return!0;if(l>f)return!1}return!1}rn();Kt();ne();var Ot=q("coze-cli-installer"),q0="@coze/cli@latest",fE="coze",j0="0.1.8",xE=5e3,hE=5e3,pE=9e4,H0=1e4,Fi=null,_o=!1;async function nd(t,e={}){if(_o)return;if(Fi)return Fi;let r=e.exec??Rf;return Fi=(async()=>{try{let i=await gE(fE,r),o=!1;if(i){let l=await mE(r);if(l===void 0)Ot.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(G0(l,j0))Ot.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:l,min:j0}),o=!0;else{Ot.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:l}),_o=!0;return}}let c=o?"upgrade-only":"full";Ot.info("coze-cli install start",{package:q0,mode:c});try{await r("npm",["i","-g","--prefer-online",q0],{timeout:pE,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){_o=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:H0}),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:H0}),Ot.info("coze auth login ok")}catch(l){Ot.warn("coze auth login failed",{err:String(l)});return}_o=!0}finally{Fi=null}})(),Fi}async function gE(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:xE});return Ia(i)}catch{return}}async function mE(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:hE});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}Qr();Pe();var wE=10*6e4;function W0(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?wE:e}function yo(t){return ir(t??Q().configFile)}function Ui(t,e){return sr(e??Q().configFile,t)}import{randomBytes as zE}from"node:crypto";er();Ke();ne();import{createReadStream as _E}from"node:fs";import{mkdir as yE,readFile as EE,realpath as bE,stat as vE,writeFile as SE}from"node:fs/promises";import{basename as IE,dirname as rd,isAbsolute as AE,join as CE,relative as TE,resolve as K0,sep as kE}from"node:path";import{createInterface as RE}from"node:readline";var V0=q("fs-rpc"),Gi=We("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function J0(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Gi)throw new k("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Gi} bytes`);let i=await Z0(t.path,e);return await yE(rd(i),{recursive:!0}),await SE(i,t.content,"utf8"),V0.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function Y0(t,e){let r=await Z0(t.path,e),i=await vE(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Gi&&!o)throw new k("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Gi} bytes`);let c;if(o&&i.size>Gi)c=await DE(r,t.line??1,t.limit);else{let l=await EE(r,"utf8");if(o){let f=l.split(`
100
100
  `),x=Math.max(0,(t.line??1)-1),p=typeof t.limit=="number"?x+t.limit:void 0;c=f.slice(x,p).join(`
101
- `)}else c=u}return K0.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function kb(t,e,r){let i=Rb({input:wb(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,u=[],f=0;try{for await(let x of i)if(f>=o&&f<c&&u.push(x),f++,f>=c)break}finally{i.close()}return u.join(`
102
- `)}async function Y0(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([W0(j0(e)),W0(j0(t))]),o=Tb(r,i);if(Db(o,Cb,Ab(o)))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function Db(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function W0(t){let e=[],r=t;for(;r!==sd(r);)try{let i=await bb(r);return e.length?Ib(i,...e.reverse()):i}catch{e.push(Sb(r)),r=sd(r)}return t}ne();var Z0=q("prompt-multimodal"),J0=10*1024*1024,Pb=15e3,Ob=6;async function X0(t){let e=new Array(t.length),r=0;async function i(){for(;r<t.length;){let c=r++,u=t[c];u!==void 0&&(e[c]=await Lb(u))}}let o=Array.from({length:Math.min(Ob,t.length)},()=>i());return await Promise.all(o),e}function Q0(t){return t.some(e=>e.type==="image")}async function Lb(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Ri(e.uri))return t;try{let{buf:r,contentType:i}=await Mb(e.uri),o=e.mimeType||Nb(i)||"application/octet-stream";return Z0.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 Z0.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function Nb(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function Mb(t){let e=new AbortController,r=setTimeout(()=>e.abort(),Pb);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>J0)throw new Error(`image too large: ${o.byteLength} bytes (max ${J0})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}an();We();ne();var W=q("core"),zb=3e4,Fb=/^(boe|ppe)_[A-Za-z0-9_-]+$/,Ub="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",qb="\u5BA1\u6279\u5DF2\u8D85\u65F6",Gb=3e4,Eo=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Dr;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=H0(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(),W.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){W.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),W.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){W.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)&&W.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,u)=>{W.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:u}),Fi(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){W.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(vn(o,{code:Q.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(u=>W.debug("send error response to upstream failed (ignored)",{err:String(u)}));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)){W.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(lo(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&&Fb.test(i)?this.currentCozeEnv=i:i&&W.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}`):W.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(kr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(kr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(kr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,Q.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):W.warn("drop unknown notification",{method:e.method})}catch(o){W.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(vn(r,Mi(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"||e.method==="session/set_mode"||!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,m=io(r._meta);return W.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,x,c,Ub,p,m)}}let u=Date.now(),f=!1;try{let x=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return f=!0,x}finally{W.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-u,ok:f})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=Af(i);switch(r){case"session/new":{let c=Hb();return W.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return W.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,u=c.sessionId;if(!u)throw new C("IPC_BAD_REQUEST","session/prompt: missing sessionId");let f=$t(e)?Sf(i._meta):void 0;if(f!==void 0&&!Sn(e.framework,f))throw new C("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${f}; allowed: ${Qc(e.framework)}`);let x=await this.ensureRuntime(e,u);if(f!==void 0&&x.permissionMode===void 0&&(x.permissionMode=f,await this.persistSessionMapping(e)),x.replySeq=0,await this.ensureDownstream(e,u,x),!x.downstream||!x.acpSessionId)throw new C("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(f!==void 0&&x.permissionMode!==void 0&&x.permissionMode!==f){let S=x.permissionMode;x.permissionMode=f,await this.persistSessionMapping(e);try{await x.downstream.setSessionMode({sessionId:x.acpSessionId,modeId:f})}catch(y){throw x.permissionMode=S,await this.persistSessionMapping(e).catch(()=>{}),y}}let p=i._meta?.cozeTriggerMsgId;p?e.activeTriggers.set(x.acpSessionId,p):e.activeTriggers.delete(x.acpSessionId);let m=io(i._meta);if(m?e.activeGroupIds.set(x.acpSessionId,m):e.activeGroupIds.delete(x.acpSessionId),m&&x.cozeGroupId!==m&&(x.cozeGroupId=m,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&Q0(c.prompt))throw new C("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let _=await X0(c.prompt);try{let S=await x.downstream.sessionPrompt({...c,sessionId:x.acpSessionId,prompt:_});return x.lastActiveAt=Date.now(),S}catch(S){if(S instanceof C&&S.code==="AGENT_APPROVAL_TIMEOUT"){let y=x.pendingPermission;y&&(y.downstream.respondAgentRequest(y.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(y.upstreamId),x.pendingPermission=void 0);let v=x.acpSessionId,A=v?e.activeTriggers.get(v):void 0,I=v?e.activeGroupIds.get(v):void 0;return W.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:u}),await this.synthesizePromptReply(e,x,u,qb,A,I)}throw S}finally{if(e.activeTriggers.delete(x.acpSessionId),e.activeGroupIds.delete(x.acpSessionId),x.pendingPermission=void 0,x.reloadAfterTurn){x.reloadAfterTurn=!1;let S=x.downstream;S&&(x.downstream=void 0,W.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:u,acpId:x.acpSessionId}),S.stop("reload-after-turn").catch(y=>W.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:u,err:String(y)})))}else x.downstream?.isAlive()&&this.armIdleTimer(e,u,x)}}case"session/cancel":{let u=o.sessionId;if(!u)throw new C("IPC_BAD_REQUEST","session/cancel: missing sessionId");let f=e.sessions.get(u);if(e.hasSessionQueue(u)){let x=e.getSessionQueue(u);x.size>0&&(W.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:u,queuedCount:x.size}),x.dispose(new C("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${u}`)))}return f?.downstream?.isAlive()&&f.acpSessionId&&await f.downstream.sessionCancel({sessionId:f.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,u=c.sessionId,f=c.modeId,x=io(i._meta);if(!u)throw new C("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!$t(e))throw e.framework==="openclaw"?new C("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new C("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!Sn(e.framework,f))throw new C("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(f)}; allowed: ${Qc(e.framework)}`);if(x)return await this.handleGroupSetMode(e,x,f);let p=e.sessions.get(u)??await this.ensureRuntime(e,u);if(p.permissionMode===f)return{};let m=p.permissionMode;if(p.permissionMode=f,await this.persistSessionMapping(e),p.downstream?.isAlive()&&p.acpSessionId)try{await p.downstream.setSessionMode({sessionId:p.acpSessionId,modeId:f})}catch(_){throw p.permissionMode=m,await this.persistSessionMapping(e).catch(()=>{}),_}else W.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:u,modeId:f});return{}}default:throw new C("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async handleGroupSetMode(e,r,i){let o=[];for(let[u,f]of e.sessions)f.cozeGroupId===r&&f.permissionMode!==i&&o.push({cloudId:u,runtime:f,oldMode:f.permissionMode});if(o.length===0)return W.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i}),{};W.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i,targets:o.length});for(let u of o)u.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let u of o){let f=u.runtime.downstream,x=u.runtime.acpSessionId;f?.isAlive()&&x&&c.push({downstream:f,acpSessionId:x,oldMode:u.oldMode,runtime:u.runtime})}for(let u of c)try{await u.downstream.setSessionMode({sessionId:u.acpSessionId,modeId:i})}catch(f){for(let x of o)x.runtime.permissionMode=x.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),f}return{}}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 $t(e)&&(c.permissionMode=e.framework==="claude-code"?rd:C0),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(_t.GEN_MODEL_TOKEN,i,Gb);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(Fi(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,u=i.spawnFailCount??0,f=i.spawnFailedAt??0;if(u>=o&&Date.now()-f<c)throw new C("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${u} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-f))/1e3)}s`);let x;try{x=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(p){throw i.spawnFailCount=u+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(W.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}),W.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(p){W.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(p)}),i.acpSessionId=void 0;let m=await x.sessionNew({cwd:e.workspace});i.acpSessionId=m.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 W.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}if(x.afterSessionEstablished&&i.acpSessionId&&await x.afterSessionEstablished(i.acpSessionId),$t(e)&&i.acpSessionId&&i.permissionMode)try{await x.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(p){W.warn("post-spawn set_mode failed, framework using its own startup default",{framework:e.framework,agentId:e.agentId,cloudId:r,mode:i.permissionMode,err:String(p)})}}armIdleTimer(e,r,i){if(Fi(i),this.isRuntimeBusy(e,i)){W.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)){W.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}W.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=>W.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 u=e.activeTriggers.get(r.acpSessionId);u&&(c.cozeTriggerMsgId=u);let f=e.activeGroupIds.get(r.acpSessionId);f&&(c.cozeGroupId=f)}await this.upstream.send(Rr("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,u){let f={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(f.cozeTriggerMsgId=c),u&&(f.cozeGroupId=u),await this.upstream.send(Rr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:f})).catch(x=>W.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){W.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){W.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(Kb(r)){W.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let u=r.update;if(u&&typeof u=="object"&&u.sessionUpdate==="current_mode_update"&&$t(e)){let m=u.currentModeId;Sn(e.framework,m)&&c.permissionMode!==m?(c.permissionMode=m,this.persistSessionMapping(e).catch(_=>W.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(_)}))):typeof m=="string"&&!Sn(e.framework,m)&&W.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:m})}let f={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},x=e.activeTriggers.get(i);x&&(f.cozeTriggerMsgId=x);let p=e.activeGroupIds.get(i);p&&(f.cozeGroupId=p),this.upstream.send(Rr("session/update",{...r,sessionId:o,_meta:f})).catch(m=>W.warn("forward update failed",{agentId:e.agentId,err:String(m)}))}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}W.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??{},u=await $0(c,o);r.respondAgentRequest(i.id,u)}else{let c=i.params??{},u=await V0(c,o);r.respondAgentRequest(i.id,u)}}catch(o){W.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Mi(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},f=c.sessionId,x=f?e.activeTriggers.get(f):void 0,p={cozeAgentId:e.agentId};x&&(p.cozeTriggerMsgId=x);let m=f?e.activeGroupIds.get(f):void 0;m&&(p.cozeGroupId=m);let _=f?this.reverseSessionId(e,f):void 0,S=_?e.sessions.get(_):void 0;S&&(S.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let y={...c,..._?{sessionId:_}:{},_meta:p};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:_}),W.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:f,cloudSessionId:_,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(v=>({optionId:v.optionId,kind:v.kind,name:v.name}))}),this.upstream.send(Li(o,"session/request_permission",y)).catch(v=>{this.pendingUpstream.delete(o),W.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?(W.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"&&jb(e.result,o),W.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 uo(e.error)):i.value.resolve(e.result);return}W.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),u=e.get(c);if(u)return W.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:u,key:c}}}sendRequest(e,r,i=zb){let o=this.upstreamIds.next(e);return new Promise((c,u)=>{let f=setTimeout(()=>{this.pendingBridge.delete(o),u(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:u,timer:f}),this.upstream.send(Li(o,e,r)).catch(x=>{let p=this.pendingBridge.get(o);p&&(clearTimeout(p.timer),this.pendingBridge.delete(o)),u(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),o.permissionMode&&$t(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await ni(e.agentId,r,this.paths)}catch(r){W.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(vn(e,{code:r,message:i,data:{bridgeVersion:Cr}}))}};function Hb(){return Bb(16).toString("hex")}function jb(t,e){if(!t||typeof t!="object"){W.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){W.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"){W.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")&&W.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var Wb=["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 Kb(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 Wb.some(c=>o.startsWith(c))}on();ne();Oe();import{randomBytes as $b}from"node:crypto";import{createServer as Vb}from"node:http";var Yb=1e6,ex=q("ipc"),vo=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=$b(32).toString("hex");let e=Vb((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(),ex.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 sn(this.paths.portFile,String(this.port)),await sn(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Hi(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Hi(r,404,{error:"not found"});return}let u=null;if(e.method==="POST")try{u=await Zb(e)}catch(f){Hi(r,400,{error:"invalid json",detail:String(f)});return}try{let f=await c.handler(u,e);Hi(r,200,f??{ok:!0})}catch(f){ex.error("IPC handler failed",{key:o,err:String(f)}),Hi(r,500,{error:f instanceof Error?f.message:String(f)})}}};function Hi(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function Zb(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>Yb)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}import"node:module";var mv=Ft(Zx(),1),wv=Ft(Po(),1),_v=Ft(Br(),1),yv=Ft(gd(),1),bv=Ft(_d(),1),Ev=Ft(Ad(),1),sh=Ft(Mo(),1),vv=Ft(ih(),1);var oh=sh.default;We();ne();var{FWS:Fv}=mh(),ke=q("upstream.frontier"),_h="application/json",yh="none",Uv=15e3;function qv(t){class e extends oh{constructor(i){super(i,kf,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>ke.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(hu("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 u=Buffer.from(c.slice(0,128)).toString("hex");ke.debug("WS raw frame out",{bytes:c.byteLength,headHex:u})}catch(c){ke.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var Xi=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){ke.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Df,...Ir(this.opts.ppeOverride)},r=qv(e),i=Of(this.opts.urlOverride),o={url:i,ws:r,fpID:Rf,aID:oo,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:_h,force:!0},payloadEncoding:{encoding:yh,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new Fv(o),u=!1,f=null,x,p,m=new Promise((y,v)=>{x=y,p=v}),_=y=>{u||(u=!0,f&&(clearTimeout(f),f=null),y?p(y):x())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let y=this.openCount===1;ke.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:y,openCount:this.openCount}),y&&_();for(let v of this.connectHandlers)Promise.resolve(v({initial:y})).catch(A=>ke.warn("onConnect handler threw (ignored)",{err:String(A)}))},c.onclose=y=>{this.opened=!1,ke.info("frontier closed",{code:y.code,reason:y.reason,willReconnect:y.willReconnect})},c.onerror=y=>{ke.warn("frontier error",{code:y.code,msg:y.message}),_(new C("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${y.code} msg=${y.message??""}`))},c.onmessage=y=>this.handleMessage(y),this.fws=c;let S=this.opts.openTimeoutMs??Uv;f=setTimeout(()=>{_(new C("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${S}ms (handshake or upgrade slow)`))},S),await c.connect();try{await m}catch(y){try{c.close(1e3,"open failed")}catch(v){ke.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,y}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){ke.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw ke.warn("frontier send refused: upstream not started",{method:i}),new C("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let f=Date.now();throw f-this.lastSendRefusedLogAt>1e3?(ke.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:r.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=f,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new 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;bh(c)||ke.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:_h,payloadEncoding:yh})}catch(f){throw ke.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(f)}),new C("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(f)}`,{cause:f})}}onFrame(e){this.handler=e}onConnect(e){this.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){ke.debug("drop non-adapter frontier frame",{service:r});return}let i=jv(e);if(!i){ke.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){ke.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(u){ke.warn("frontier message JSON parse failed",{err:String(u),head:i.slice(0,80)});return}let c=o;bh(c)||ke.info("frontier frame in",{logid:Hv(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:Gv(i)}),Promise.resolve(this.handler(o)).catch(u=>ke.warn("frontier frame handler threw",{err:String(u)}))}};function bh(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Eh=2e3;function Gv(t){return t.length<=Eh?t:`${t.slice(0,Eh)}...<truncated, total ${t.length} chars>`}function Hv(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function jv(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 Rd=q("upstream.switchable"),Wo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;Rd.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 Rd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>Rd.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 kd=q("upstream"),Hr=class{handler=null;async start(){kd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){kd.info("NoopUpstream stopped",{reason:e})}async send(e){kd.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();on();ne();Oe();import{promises as Wv}from"node:fs";var vh=q("pat-token-store");async function Ko(t=X()){try{let r=(await Wv.readFile(t.patTokenFile,"utf8")).trim();return r.length===0?(vh.warn("pat-token exists but empty (treating as missing; likely interrupted write)",{path:t.patTokenFile}),null):r}catch(e){let r=e?.code;return r!=="ENOENT"&&vh.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function Qi(t,e=X()){if(!t)throw new Error("writePatToken: empty patToken");await sn(e.patTokenFile,t,{mode:384})}Oe();Oe();import{promises as $o}from"node:fs";import{join as Kv}from"node:path";function $v(t,e){return`#!/bin/sh
101
+ `)}else c=l}return V0.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function DE(t,e,r){let i=RE({input:_E(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,l=[],f=0;try{for await(let x of i)if(f>=o&&f<c&&l.push(x),f++,f>=c)break}finally{i.close()}return l.join(`
102
+ `)}async function Z0(t,e){if(typeof t!="string"||t.length===0)throw new k("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([$0(K0(e)),$0(K0(t))]),o=TE(r,i);if(PE(o,kE,AE(o)))throw new k("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 $0(t){let e=[],r=t;for(;r!==rd(r);)try{let i=await bE(r);return e.length?CE(i,...e.reverse()):i}catch{e.push(IE(r)),r=rd(r)}return t}ne();var X0=q("prompt-multimodal"),Q0=10*1024*1024,OE=15e3,LE=6;async function ex(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 NE(l))}}let o=Array.from({length:Math.min(LE,t.length)},()=>i());return await Promise.all(o),e}function tx(t){return t.some(e=>e.type==="image")}async function NE(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Ti(e.uri))return t;try{let{buf:r,contentType:i}=await BE(e.uri),o=e.mimeType||ME(i)||"application/octet-stream";return X0.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 X0.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function ME(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function BE(t){let e=new AbortController,r=setTimeout(()=>e.abort(),OE);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>Q0)throw new Error(`image too large: ${o.byteLength} bytes (max ${Q0})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}sn();Ke();ne();var K=q("core"),FE=3e4,UE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,GE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",qE="\u5BA1\u6279\u5DF2\u8D85\u65F6",jE=3e4,Eo=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new kr;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=W0(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}),zi(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(En(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 k("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(co(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&&UE.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(Tr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Tr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Tr(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(En(r,Ni(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new k("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new k("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new k("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new k("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"||e.method==="session/set_mode"||!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=no(r._meta);return K.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,x,c,GE,p,w)}}let l=Date.now(),f=!1;try{let x=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return f=!0,x}finally{K.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-l,ok:f})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=Cf(i);switch(r){case"session/new":{let c=HE();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 k("IPC_BAD_REQUEST","session/prompt: missing sessionId");let f=$t(e)?Af(i._meta):void 0;if(f!==void 0&&!bn(e.framework,f))throw new k("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${f}; allowed: ${Xc(e.framework)}`);let x=await this.ensureRuntime(e,l);if(f!==void 0&&x.permissionMode===void 0&&(x.permissionMode=f,await this.persistSessionMapping(e)),x.replySeq=0,await this.ensureDownstream(e,l,x),!x.downstream||!x.acpSessionId)throw new k("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(f!==void 0&&x.permissionMode!==void 0&&x.permissionMode!==f){let S=x.permissionMode;x.permissionMode=f,await this.persistSessionMapping(e);try{await x.downstream.setSessionMode({sessionId:x.acpSessionId,modeId:f})}catch(y){throw x.permissionMode=S,await this.persistSessionMapping(e).catch(()=>{}),y}}let p=i._meta?.cozeTriggerMsgId;p?e.activeTriggers.set(x.acpSessionId,p):e.activeTriggers.delete(x.acpSessionId);let w=no(i._meta);if(w?e.activeGroupIds.set(x.acpSessionId,w):e.activeGroupIds.delete(x.acpSessionId),w&&x.cozeGroupId!==w&&(x.cozeGroupId=w,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&tx(c.prompt))throw new k("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let _=await ex(c.prompt);try{let S=await x.downstream.sessionPrompt({...c,sessionId:x.acpSessionId,prompt:_});return x.lastActiveAt=Date.now(),S}catch(S){if(S instanceof k&&S.code==="AGENT_APPROVAL_TIMEOUT"){let y=x.pendingPermission;y&&(y.downstream.respondAgentRequest(y.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(y.upstreamId),x.pendingPermission=void 0);let v=x.acpSessionId,I=v?e.activeTriggers.get(v):void 0,C=v?e.activeGroupIds.get(v):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,x,l,qE,I,C)}throw S}finally{if(e.activeTriggers.delete(x.acpSessionId),e.activeGroupIds.delete(x.acpSessionId),x.pendingPermission=void 0,x.reloadAfterTurn){x.reloadAfterTurn=!1;let S=x.downstream;S&&(x.downstream=void 0,K.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:l,acpId:x.acpSessionId}),S.stop("reload-after-turn").catch(y=>K.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:l,err:String(y)})))}else x.downstream?.isAlive()&&this.armIdleTimer(e,l,x)}}case"session/cancel":{let l=o.sessionId;if(!l)throw new k("IPC_BAD_REQUEST","session/cancel: missing sessionId");let f=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 k("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${l}`)))}return f?.downstream?.isAlive()&&f.acpSessionId&&await f.downstream.sessionCancel({sessionId:f.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,l=c.sessionId,f=c.modeId,x=no(i._meta);if(!l)throw new k("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!$t(e))throw e.framework==="openclaw"?new k("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new k("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!bn(e.framework,f))throw new k("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(f)}; allowed: ${Xc(e.framework)}`);if(x)return await this.handleGroupSetMode(e,x,f);let p=e.sessions.get(l)??await this.ensureRuntime(e,l);if(p.permissionMode===f)return{};let w=p.permissionMode;if(p.permissionMode=f,await this.persistSessionMapping(e),p.downstream?.isAlive()&&p.acpSessionId)try{await p.downstream.setSessionMode({sessionId:p.acpSessionId,modeId:f})}catch(_){throw p.permissionMode=w,await this.persistSessionMapping(e).catch(()=>{}),_}else K.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:l,modeId:f});return{}}default:throw new k("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async handleGroupSetMode(e,r,i){let o=[];for(let[l,f]of e.sessions)f.cozeGroupId===r&&f.permissionMode!==i&&o.push({cloudId:l,runtime:f,oldMode:f.permissionMode});if(o.length===0)return K.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i}),{};K.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i,targets:o.length});for(let l of o)l.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let l of o){let f=l.runtime.downstream,x=l.runtime.acpSessionId;f?.isAlive()&&x&&c.push({downstream:f,acpSessionId:x,oldMode:l.oldMode,runtime:l.runtime})}for(let l of c)try{await l.downstream.setSessionMode({sessionId:l.acpSessionId,modeId:i})}catch(f){for(let x of o)x.runtime.permissionMode=x.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),f}return{}}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 $t(e)&&(c.permissionMode=e.framework==="claude-code"?td:R0),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(_t.GEN_MODEL_TOKEN,i,jE);if(!o?.modelToken)throw new k("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof k&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new k("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(zi(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new k("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,l=i.spawnFailCount??0,f=i.spawnFailedAt??0;if(l>=o&&Date.now()-f<c)throw new k("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${l} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-f))/1e3)}s`);let 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}if(x.afterSessionEstablished&&i.acpSessionId&&await x.afterSessionEstablished(i.acpSessionId),$t(e)&&i.acpSessionId&&i.permissionMode)try{await x.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(p){K.warn("post-spawn set_mode failed, framework using its own startup default",{framework:e.framework,agentId:e.agentId,cloudId:r,mode:i.permissionMode,err:String(p)})}}armIdleTimer(e,r,i){if(zi(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 f=e.activeGroupIds.get(r.acpSessionId);f&&(c.cozeGroupId=f)}await this.upstream.send(Cr("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,l){let f={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(f.cozeTriggerMsgId=c),l&&(f.cozeGroupId=l),await this.upstream.send(Cr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:f})).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($E(r)){K.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let l=r.update;if(l&&typeof l=="object"&&l.sessionUpdate==="current_mode_update"&&$t(e)){let w=l.currentModeId;bn(e.framework,w)&&c.permissionMode!==w?(c.permissionMode=w,this.persistSessionMapping(e).catch(_=>K.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(_)}))):typeof w=="string"&&!bn(e.framework,w)&&K.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:w})}let f={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},x=e.activeTriggers.get(i);x&&(f.cozeTriggerMsgId=x);let p=e.activeGroupIds.get(i);p&&(f.cozeGroupId=p),this.upstream.send(Cr("session/update",{...r,sessionId:o,_meta:f})).catch(w=>K.warn("forward update failed",{agentId:e.agentId,err:String(w)}))}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 J0(c,o);r.respondAgentRequest(i.id,l)}else{let c=i.params??{},l=await Y0(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,Ni(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},f=c.sessionId,x=f?e.activeTriggers.get(f):void 0,p={cozeAgentId:e.agentId};x&&(p.cozeTriggerMsgId=x);let w=f?e.activeGroupIds.get(f):void 0;w&&(p.cozeGroupId=w);let _=f?this.reverseSessionId(e,f):void 0,S=_?e.sessions.get(_):void 0;S&&(S.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let y={...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:f,cloudSessionId:_,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(v=>({optionId:v.optionId,kind:v.kind,name:v.name}))}),this.upstream.send(Oi(o,"session/request_permission",y)).catch(v=>{this.pendingUpstream.delete(o),K.error("forward permission request failed",{agentId:e.agentId,err:String(v)}),r.respondAgentRequestError(i.id,{code:ee.INTERNAL_ERROR,message:`upstream send failed: ${String(v)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let r=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(r){this.pendingUpstream.delete(r.key);let o=r.value;this.clearPendingPermissionFor(o),e.error?(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"&&WE(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 ao(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=FE){let o=this.upstreamIds.next(e);return new Promise((c,l)=>{let f=setTimeout(()=>{this.pendingBridge.delete(o),l(new k("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:l,timer:f}),this.upstream.send(Oi(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),o.permissionMode&&$t(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await ti(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(En(e,{code:r,message:i,data:{bridgeVersion:Ar}}))}};function HE(){return zE(16).toString("hex")}function WE(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 KE=["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 $E(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 KE.some(c=>o.startsWith(c))}ne();Pe();import{randomBytes as VE}from"node:crypto";import{chmod as JE,mkdir as YE,writeFile as nx}from"node:fs/promises";import{createServer as ZE}from"node:http";import{dirname as XE}from"node:path";var QE=1e6,id=q("ipc"),bo=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??Q()}async start(){this.token=VE(32).toString("hex");let e=ZE((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(),id.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 YE(XE(this.paths.portFile),{recursive:!0}),await nx(this.paths.portFile,String(this.port),"utf8"),await nx(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await JE(this.paths.tokenFile,384)}catch(e){id.warn("chmod token file failed (non-POSIX?)",{err:String(e)})}}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){qi(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){qi(r,404,{error:"not found"});return}let l=null;if(e.method==="POST")try{l=await eb(e)}catch(f){qi(r,400,{error:"invalid json",detail:String(f)});return}try{let f=await c.handler(l,e);qi(r,200,f??{ok:!0})}catch(f){id.error("IPC handler failed",{key:o,err:String(f)}),qi(r,500,{error:f instanceof Error?f.message:String(f)})}}};function qi(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function eb(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>QE)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}import"node:module";var Ev=Ft(Xx(),1),bv=Ft(Do(),1),vv=Ft(Nr(),1),Sv=Ft(pd(),1),Iv=Ft(wd(),1),Av=Ft(Sd(),1),ah=Ft(No(),1),Cv=Ft(oh(),1);var ch=ah.default;Ke();ne();var{FWS:jv}=_h(),Re=q("upstream.frontier"),Eh="application/json",bh="none",Hv=15e3;function Wv(t){class e extends ch{constructor(i){super(i,Pf,{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(hl("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 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){Re.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Of,...Sr(this.opts.ppeOverride)},r=Wv(e),i=Nf(this.opts.urlOverride),o={url:i,ws:r,fpID:Df,aID:io,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Eh,force:!0},payloadEncoding:{encoding:bh,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new jv(o),l=!1,f=null,x,p,w=new Promise((y,v)=>{x=y,p=v}),_=y=>{l||(l=!0,f&&(clearTimeout(f),f=null),y?p(y):x())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let y=this.openCount===1;Re.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:y,openCount:this.openCount}),y&&_();for(let v of this.connectHandlers)Promise.resolve(v({initial:y})).catch(I=>Re.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=y=>{this.opened=!1,Re.info("frontier closed",{code:y.code,reason:y.reason,willReconnect:y.willReconnect})},c.onerror=y=>{Re.warn("frontier error",{code:y.code,msg:y.message}),_(new k("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${y.code} msg=${y.message??""}`))},c.onmessage=y=>this.handleMessage(y),this.fws=c;let S=this.opts.openTimeoutMs??Hv;f=setTimeout(()=>{_(new k("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${S}ms (handshake or upgrade slow)`))},S),await c.connect();try{await w}catch(y){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,y}}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 k("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let f=Date.now();throw f-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=f,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new k("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;vh(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:Eh,payloadEncoding:bh})}catch(f){throw Re.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(f)}),new k("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(f)}`,{cause:f})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){Re.debug("drop non-adapter frontier frame",{service:r});return}let i=Vv(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;vh(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:Kv(i)}),Promise.resolve(this.handler(o)).catch(l=>Re.warn("frontier frame handler threw",{err:String(l)}))}};function vh(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Sh=2e3;function Kv(t){return t.length<=Sh?t:`${t.slice(0,Sh)}...<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 Vv(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 Td=q("upstream.switchable"),Ho=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;Td.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 Td.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>Td.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 kd=q("upstream"),Gr=class{handler=null;async start(){kd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){kd.info("NoopUpstream stopped",{reason:e})}async send(e){kd.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};Ke();ne();ne();Pe();import{promises as Rd}from"node:fs";import{dirname as Jv}from"node:path";var Yv=q("pat-token-store");async function Wo(t=Q()){try{let r=(await Rd.readFile(t.patTokenFile,"utf8")).trim();return r.length>0?r:null}catch(e){let r=e?.code;return r!=="ENOENT"&&Yv.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function Xi(t,e=Q()){if(!t)throw new Error("writePatToken: empty patToken");await Rd.mkdir(Jv(e.patTokenFile),{recursive:!0}),await Rd.writeFile(e.patTokenFile,t,{encoding:"utf8",mode:384})}Pe();Pe();import{promises as Ko}from"node:fs";import{join as Zv}from"node:path";function Xv(t,e){return`#!/bin/sh
103
103
  exec ${JSON.stringify(e)} ${JSON.stringify(t)} "$@"
104
- `}function Vv(t,e){return`@echo off\r
104
+ `}function Qv(t,e){return`@echo off\r
105
105
  "${e}" "${t}" %*\r
106
- `}async function Sh(t,e=X()){let r=e.binDir;await $o.mkdir(r,{recursive:!0});let i=Kv(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?Vv(t,o):$v(t,o);return await $o.readFile(i,"utf8").catch(()=>null)===c||(await $o.writeFile(i,c,"utf8"),process.platform!=="win32"&&await $o.chmod(i,493)),r}ne();Oe();import{execSync as Ah}from"node:child_process";import{readFileSync as Ih,unlinkSync as Yv}from"node:fs";import{mkdir as Zv,open as Jv,readFile as Th,unlink as Dd,writeFile as Xv}from"node:fs/promises";import{dirname as Qv}from"node:path";var eS=q("single-instance"),tS=t=>new Promise(e=>setTimeout(e,t)),Vo=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??X().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:r=>Bi(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&&eS.warn("removing stale pid file",{stalePid:i}),await Xv(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 Th(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Dd(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 Th(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 Zv(Qv(r),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await Jv(r,"wx")}catch(c){if(c.code!=="EEXIST")throw c;let u=await this.readPidFrom(r);if(u!==null&&u!==this.selfPid&&this.probe.isAlive(u)){await tS(this.claimLockIntervalMs);continue}await Dd(r).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Dd(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=Ih(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes(Pr)||r.includes("lib/index.js"))}catch{}try{let r=Ah(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes(Pr)||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=Ah(`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{Ih(this.pidFile,"utf8").trim()===String(this.selfPid)&&Yv(this.pidFile)}catch{}})}};Yo();ne();var Jn=q("daemon.upstream-watchdog"),dS=12e4,uS=9e5,lS=3e4;function Od(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Zo=class{constructor(e){this.opts=e;this.softMs=e.softMs??Od("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",dS),this.hardMs=e.hardMs??Od("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",uS),this.intervalMs=e.intervalMs??Od("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",lS),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?.(),Jn.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&&Jn.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&&Jn.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,Jn.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){Jn.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,Jn.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>Jn.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=q("daemon");async function kh(){let t=X();if(process.env.COZE_BRIDGE_LOG_MODE!=="legacy"){fu({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:L=>Xe(L,t).logs,listAgentIds:()=>us(t)});try{let{writeFileSync:L}=await import("node:fs");L(t.logFile,`\u8FD0\u884C\u65E5\u5FD7\u5DF2\u8FC1\u79FB\u5230 dated \u6587\u4EF6, \u6B64\u6587\u4EF6 (bridge.log) \u4E0D\u518D\u5199\u5165\u8FD0\u884C\u65E5\u5FD7\u3002
106
+ `}async function Ih(t,e=Q()){let r=e.binDir;await Ko.mkdir(r,{recursive:!0});let i=Zv(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?Qv(t,o):Xv(t,o);return await Ko.readFile(i,"utf8").catch(()=>null)===c||(await Ko.writeFile(i,c,"utf8"),process.platform!=="win32"&&await Ko.chmod(i,493)),r}ne();Pe();import{execSync as Ah}from"node:child_process";import{readFileSync as Ch,unlinkSync as eS}from"node:fs";import{mkdir as tS,open as nS,readFile as Th,unlink as Dd,writeFile as rS}from"node:fs/promises";import{dirname as iS}from"node:path";var sS=q("single-instance"),oS=t=>new Promise(e=>setTimeout(e,t)),$o=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??Q().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:r=>Mi(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&&sS.warn("removing stale pid file",{stalePid:i}),await rS(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 Th(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Dd(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 Th(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 tS(iS(r),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await nS(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 oS(this.claimLockIntervalMs);continue}await Dd(r).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Dd(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=Ch(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes(Rr)||r.includes("lib/index.js"))}catch{}try{let r=Ah(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes(Rr)||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=Ah(`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{Ch(this.pidFile,"utf8").trim()===String(this.selfPid)&&eS(this.pidFile)}catch{}})}};Vo();ne();var Jn=q("daemon.upstream-watchdog"),hS=12e4,pS=9e5,gS=3e4;function Od(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Jo=class{constructor(e){this.opts=e;this.softMs=e.softMs??Od("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",hS),this.hardMs=e.hardMs??Od("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",pS),this.intervalMs=e.intervalMs??Od("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",gS),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?.(),Jn.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&&Jn.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&&Jn.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,Jn.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){Jn.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,Jn.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>Jn.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 W=q("daemon");async function Dh(){let t=Q();if(process.env.COZE_BRIDGE_LOG_MODE!=="legacy"){fl({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:N=>Xe(N,t).logs,listAgentIds:()=>cs(t)});try{let{writeFileSync:N}=await import("node:fs");N(t.logFile,`\u8FD0\u884C\u65E5\u5FD7\u5DF2\u8FC1\u79FB\u5230 dated \u6587\u4EF6, \u6B64\u6587\u4EF6 (bridge.log) \u4E0D\u518D\u5199\u5165\u8FD0\u884C\u65E5\u5FD7\u3002
107
107
  \u8BF7\u67E5\u770B: ${t.bridgeLogsDir}/bridge-<YYYY-MM-DD>.log
108
108
  \u6216\u4F7F\u7528: coze-bridge log [-f] [--lines N]
109
- `)}catch{}}let e=new Vo({processTitle:Pr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await bo(),o=i??{};cs({pid:process.pid}),H.info(i?"loaded bridge config":"initialized bridge config");let c=new Wo(new Hr),u=null,f=new Eo({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(L,G,K,se)=>{if(!u)throw new Error("agentManager not ready");return u.spawnSessionDownstream(L,G,K,se)}}),x=new wo({paths:t,config:o,registry:f});u=x;let p,m,_=null,S={},y,v=null,A=null,I=null,R=new An;function D(L,G){return R.enqueue(()=>k(L,G))}function E(){A||(A=new Zo({isConnected:()=>c.isConnected(),forceReconnect:()=>I?D(I,{force:!0}):void 0,onFatal:L=>{if(process.env[es]==="1"){H.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:L});return}H.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:L}),process.exit(1)}})),A.start()}async function k(L,G){let K=L,se=K?.privatecode;if(!se)throw new C("IPC_BAD_REQUEST","/connect requires privatecode");let Ye=Di(K.env),xe=K.handshake_url,he=K.frontier_url,vt=Rh(K.env,xe,he);if(I=K,!G?.force&&p===se&&m===vt){let me=await fS(t);return f.agents.size===0&&me?(H.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),Xo(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!==se,Qt=m!==void 0&&m!==vt,Bt=ft||Qt,en=await Bc({privatecode:se,...xe?{endpoint:xe}:{},ppeOverride:Ye});if(Bt){H.warn("connect config switched, resetting agents",{pcChanged:ft,envChanged:Qt,previousPc:p?Jo(p):"",nextPc:Jo(se)});for(let me of[...f.agents.values()])await me.dispose("connect config switch").catch(()=>{}),f.agents.delete(me.agentId);f.disconnectedAgents.size>0&&(H.info("clearing disconnectedAgents set on connect config switch",{count:f.disconnectedAgents.size}),f.disconnectedAgents.clear()),await c.swap(new Hr,"connect switch").catch(()=>{})}_=en.deviceId,cs({deviceId:_,pid:process.pid}),id({patToken:se,env:K.env}).catch(me=>H.warn("coze-cli setup error (ignored)",{err:String(me)}));let Vr=new Xi({handshake:en,privatecode:se,...he?{urlOverride:he}:{},ppeOverride:Ye,getPatTokenForAgent:me=>f.agents.get(me)?.patToken});return await c.swap(Vr,"connect"),p=se,m=vt,S=Ye,y=xe,K.mock_scenario!==void 0&&(f.setMockScenario(K.mock_scenario),H.info("mock scenario set",{scenario:K.mock_scenario})),v||(v=new Oi({core:f,getDeviceId:()=>_??"",onTickEnd:()=>z.retryPending().catch(me=>H.warn("detailSync.retryPending failed (ignored)",{err:String(me)})),onAuthFailures:Y})),v.start(),E(),Bt&&Xo(t,x).catch(me=>H.warn("post-connect-switch auto-revive error (ignored)",{err:String(me)})),Qi(se,t).catch(me=>H.warn("writePatToken after /connect failed (ignored)",{err:String(me)})),H.info("/connect: WS established",{deviceId:_}),{ok:!0,note:"connected"}}f.registerExtension("_agent/create",async L=>x.createAgent(L.params)),f.registerExtension("_agent/health",async()=>({ok:!0}));let P={},F=new co({agents:f.agents,disposeAndMarkDisconnected:async(L,G)=>{let K=f.agents.get(L);if(K){await x.cleanupOpenclawSessionProviders(K).catch(Ye=>H.warn("cleanup openclaw providers failed (ignored)",{agentId:L,err:String(Ye)}));let se=!0;try{await K.dispose(`disconnect: ${G}`)}catch(Ye){se=!1,H.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:L,err:String(Ye)}),K.status="error"}se&&(K.status="disconnected",f.unregister(L),f.disconnectedAgents.add(L))}else f.disconnectedAgents.add(L)},detailSyncer:async L=>{if(!P.ref)throw new Error("agent-detail-sync not initialized yet");await P.ref.syncOne(L)},cleanupOpenclawProviders:async L=>{await x.cleanupOpenclawSessionProviders(L)},openclawRepair:async(L,G)=>{await x.openclawRepair(L,G)},isRuntimePendingPermission:L=>f.hasPendingPermissionFor(L)});f.registerExtension("_agent/listSkills",L=>F.listSkills(L.params)),f.registerExtension("_agent/addSkills",L=>F.addSkills(L.params)),f.registerExtension("_agent/removeSkills",L=>F.removeSkills(L.params)),f.registerExtension("_agent/getFileTree",L=>F.getFileTree(L.params)),f.registerExtension("_agent/getFileContent",L=>F.getFileContent(L.params)),f.registerExtension("_agent/update",L=>F.updateAgent(L.params)),f.registerExtension("_agent/disconnect",L=>F.disconnectAgent(L.params)),f.registerExtension("_agent/switchModel",L=>F.switchModel(L.params)),f.registerExtension("_agent/reset",L=>F.resetAgent(L.params)),f.registerExtension("_agent/repair",L=>F.repairAgent(L.params)),f.registerExtension("_agent/upgrade",L=>F.upgradeBridge(L.params));let z=new hs({paths:t,handlers:F,agentManager:x,sendDetail:L=>f.sendRequest("_agent/detail",L)});P.ref=z;let Y=async L=>{await Promise.allSettled(L.map(async G=>{try{await F.disconnectAgent({agentId:G.agentId,reason:`auth_failure: code=${G.code} ${G.message}`}),H.info("agent disconnected due to auth failure from heartbeat response",{agentId:G.agentId,code:G.code,message:G.message})}catch(K){H.warn("disconnect during authFailure handling failed (ignored)",{agentId:G.agentId,err:String(K)})}}))};c.onConnect(({initial:L})=>{H.info("frontier upstream connected, triggering detail sync",{initial:L}),z.syncAll(L?"initial-connect":"reconnect").catch(G=>H.warn("detail sync top-level error (ignored)",{err:String(G)}))});let $=new vo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let L=f.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[es]==="1"?"manual":"supervisor",agents:[...f.agents.keys()],deviceId:_??"",frameworksCache:o.frameworksCache??{},...L?{mockScenario:L}:{}}}},{method:"POST",path:"/pair",handler:async L=>{let G=L,K=G?.privatecode,se=G?.pairing_code;if(!K||!se)throw new C("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Ye=Di(G.env),xe=G.handshake_url,he=G.frontier_url,vt=Rh(G.env,xe,he),ft=!!p&&p!==K,Qt=m!==void 0&&m!==vt,Bt=ft||Qt,en=await Bc({privatecode:K,...xe?{endpoint:xe}:{},ppeOverride:Ye});if(Bt){H.warn("pair config switched, resetting agents",{pcChanged:ft,envChanged:Qt,previousPc:p?Jo(p):"",nextPc:Jo(K),previousEnvKey:m??"",nextEnvKey:vt});for(let Ie of[...f.agents.values()])await Ie.dispose("pair config switch").catch(()=>{}),f.agents.delete(Ie.agentId);f.disconnectedAgents.size>0&&(H.info("clearing disconnectedAgents set on pair config switch",{count:f.disconnectedAgents.size}),f.disconnectedAgents.clear()),await c.swap(new Hr,"pair switch").catch(()=>{})}_=en.deviceId,cs({deviceId:_,pid:process.pid}),id({patToken:K,env:G.env}).catch(Ie=>H.warn("coze-cli setup error (ignored)",{err:String(Ie)}));let Vr=new Xi({handshake:en,privatecode:K,...he?{urlOverride:he}:{},ppeOverride:Ye,getPatTokenForAgent:Ie=>f.agents.get(Ie)?.patToken});await c.swap(Vr,"pair");try{let Ie=new Wn;o.frameworksCache=await Ie.detectAll(),await qi(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 me=Object.keys(o.frameworksCache??{});try{let Ie=await f.sendRequest("_agent/pair",{pairCode:se,patToken:K,frameworks:me,_meta:{cozeDeviceId:_}});H.info("_agent/pair ok",{pairResult:Ie}),p=K,m=vt,S=Ye,y=xe,G.mock_scenario!==void 0&&(f.setMockScenario(G.mock_scenario),H.info("mock scenario set",{scenario:G.mock_scenario})),Qi(K,t).catch(De=>H.warn("writePatToken after /pair failed (ignored)",{err:String(De)})),v||(v=new Oi({core:f,getDeviceId:()=>_??"",onTickEnd:()=>z.retryPending().catch(De=>H.warn("detailSync.retryPending failed (ignored)",{err:String(De)})),onAuthFailures:Y})),v.start(),E(),Bt&&Xo(t,x).catch(De=>H.warn("post-pair-switch auto-revive error (ignored)",{err:String(De)}));let Xn;return G.agent_id&&(Xn=await hS(G.agent_id,t,x,De=>f.sendRequest("_agent/detail",De),K).catch(De=>(H.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",...Xn?{agent:Xn}:{}}}catch(Ie){return H.error("_agent/pair failed",{err:String(Ie)}),{ok:!1,note:`pair failed: ${String(Ie)}`}}}},{method:"POST",path:"/connect",handler:L=>D(L)},{method:"POST",path:"/_agent/create",handler:async L=>{let G=L;return{ok:!0,result:await x.createAgent(G)}}},{method:"POST",path:"/agent/send",handler:async L=>{let G=L;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 K=G;return await(K.groupFile?z0:B0)(K,{core:f,patToken:p,handshakeBase:y,ppeOverride:S})}catch(K){if(K instanceof C)return{ok:!1,code:K.code,message:K.message};throw K}}},{method:"POST",path:"/reload",handler:async L=>{let G=L?.agent_id,K=await f.reloadAgents(G);return H.info("IPC /reload: recycled agent subprocesses",{agentId:G??"(all)",recycled:K}),{ok:!0,recycled:K}}},{method:"POST",path:"/shutdown",handler:async()=>(H.info("IPC /shutdown received"),setImmediate(()=>{oe.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:te,token:Z}=await $.start();try{await Sh(t.libEntry,t)}catch(L){H.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(L)})}await f.start(),pS({paths:t,core:f,agentManager:x,detectAll:async()=>(o.frameworksCache=await new Wn().detectAll(),await qi(o),o.frameworksCache)}).catch(L=>H.warn("startup warmup error (ignored)",{err:String(L)})),Eu().then(async()=>{let{probeAcpVersion:L}=await Promise.resolve().then(()=>(rn(),yu));for(let G of["claude-code","codex"]){let K=await L(G);K&&H.info("acp wrapper version",{framework:G,version:K})}}).catch(L=>H.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(L)}));let ie=null,oe={port:te,token:Z,core:f,ipc:$,shutdown(L){return ie||(H.info("daemon shutdown",{reason:L}),ie=(async()=>{v?.stop(),A?.stop(),await f.stop(L),await $.stop(),await e.release()})(),ie)}};for(let L of["SIGTERM","SIGINT"])process.on(L,()=>{oe.shutdown(L).then(()=>process.exit(0))});return process.on("exit",()=>a0()),process.on("unhandledRejection",L=>{H.error("unhandledRejection",{reason:L instanceof Error?L.message:String(L),stack:L instanceof Error?L.stack:void 0})}),process.on("uncaughtException",L=>{H.error("uncaughtException (will exit, supervisor will restart)",{message:L.message,stack:L.stack,name:L.name});try{process.stderr.write(`FATAL uncaughtException: ${L.stack??L.message}
110
- `)}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"}),gS({cliSpawned:process.env[es]==="1",readPatToken:()=>Ko(t),connect:D}).catch(L=>H.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(L)})),oe}async function fS(t){return us(t).length>0}function Jo(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function Rh(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function xS(t,e){let r=us(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(an(),xs));for(let c of r){await o(c,t).catch(u=>H.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(u)}));try{let u=await i(c,t);u?.disconnectedAt&&(e.disconnectedAgents.add(c),H.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:u.disconnectedAt,reason:u.disconnectReason??""}))}catch(u){H.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(u)})}}}async function hS(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(an(),xs)),u=await c(t,e);if(u){H.info("--agent-id: local config found, reconnecting",{agentId:t,framework:u.framework,hadDisconnect:!!u.disconnectedAt});let m=Dh(u),_={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...m?{_meta:m}:{}};return await r.createAgent(_),{ok:!0,agentId:t,note:u.disconnectedAt?"revived from local config":"connected from local config"}}H.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let f=await i({_meta:{cozeAgentId:t}});if(!f.framework)throw new 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 x={agentId:f.agentId,framework:f.framework,...f.cozeIdentity?{cozeIdentity:f.cozeIdentity}:{},...f.model?{model:f.model}:{},...o?{patToken:o}:{},...f.deployType?{_meta:{cozeDeployType:f.deployType}}:{}};await r.createAgent(x);let p=f.deployType==="cloud"&&f.framework==="openclaw";return{ok:!0,agentId:t,note:p?"cloud agent acknowledged":"created from cloud detail"}}async function pS(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 xS(t.paths,t.core).catch(r=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(r)})),await Xo(t.paths,t.agentManager).catch(r=>e.warn("auto-revive top-level error (ignored)",{err:String(r)}))}async function Xo(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(()=>(an(),xs));H.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,u=0;for(let f of i){let x;try{x=await o(f,t)}catch(p){H.warn("auto-revive: load config failed (skipping)",{agentId:f,err:String(p)}),u+=1;continue}if(!x){u+=1;continue}if(x.disconnectedAt){H.info("auto-revive: skip disconnected agent",{agentId:f,disconnectedAt:x.disconnectedAt}),u+=1;continue}try{H.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:f,framework:x.framework});let p=Dh(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:f,framework:x.framework,err:String(p)}),u+=1}}return H.info("auto-revive: done",{revived:c,skipped:u,total:i.length}),{revived:c,skipped:u,total:i.length}}async function gS(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 Dh(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}Yo();Oe();import{readFile as Ph}from"node:fs/promises";var Xt=class{paths;constructor(e){this.paths=e??X()}async probe(e=1e3){let r=await Qo(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:wS(i)}}}async request(e){let r=await Qo(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,u=setTimeout(()=>c.abort(),r.timeoutMs??5e3);try{let f=await fetch(`http://127.0.0.1:${e.port}${r.path}`,{method:r.method,headers:o,body:i?JSON.stringify(r.body):void 0,signal:c.signal}),x=await f.text();return{status:f.status,body:mS(x)}}finally{clearTimeout(u)}}};async function Qo(t){try{let[e,r]=await Promise.all([Ph(t.portFile,"utf8"),Ph(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 mS(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function wS(t){return t instanceof Error?t.message:String(t)}Kt();ne();nr();import{spawn as _S}from"node:child_process";import{userInfo as Lh}from"node:os";var Ld="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",yS=new Set(["bash","zsh","sh","dash","ksh"]),Oh=je("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),bS=2e3;function ES(t,e=Ld){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 u of o.split(`
111
- `)){let f=u.indexOf("=");f<=0||(c[u.slice(0,f)]=u.slice(f+1))}return c}function vS(){let t=(process.env.SHELL??"").trim()||(Lh().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return yS.has(e)?t:null}function SS(t){return new Promise(e=>{let r=`printf '%s' '${Ld}'; env; printf '%s' '${Ld}'`,i;try{i=_S(t,["-ilc",r],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??Lh().homedir}})}catch{e(null);return}let o="",c=!1,u=m=>{try{i.pid&&process.kill(-i.pid,m)}catch{}},f=m=>{c||(c=!0,clearTimeout(x),clearTimeout(p),e(m))};i.stdout?.on("data",m=>{o+=m.toString("utf8")}),i.on("error",()=>f(null)),i.on("close",()=>f(o.length>0?o:null));let x=setTimeout(()=>u("SIGTERM"),Oh),p=setTimeout(()=>{u("SIGKILL"),f(o.length>0?o:null)},Oh+bS)})}async function Nd(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let r=vS();if(!r)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??SS)(r);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=ES(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}Oe();function Cn(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],u=!1;for(let f of e){if(c===f){i=t[o+1],o+=1,u=!0;break}if(c.startsWith(`${f}=`)){i=c.slice(f.length+1),u=!0;break}}u||r.push(c)}return{value:i,rest:r}}rn();import{chmod as AS,copyFile as Nh,mkdir as Bh,readFile as ea,rename as Mh,rm as Md,stat as zh,writeFile as IS}from"node:fs/promises";import{homedir as yk}from"node:os";import{dirname as TS,join as jr,resolve as Bd,sep as ts}from"node:path";import{fileURLToPath as CS}from"node:url";Kt();ne();Oe();var zd=q("dist-install");function RS(t){let e=CS(t),r=TS(e),i=`${ts}src${ts}`;if(r.includes(i)||r.endsWith(`${ts}src${ts}cli`))return null;let o=Bd(r,"index.js"),c=Bd(r,"..","package.json");return{dist:o,pkgJson:c}}async function Ud(t={}){let e=t.paths??X(),r=RS(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,u;try{let S=JSON.parse(await ea(o,"utf8"));c=S.version??"unknown",u=S.dependencies??{}}catch(S){return zd.warn("cannot read source package.json,skip dist install",{err:String(S)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(S)}`}}let f=Qr.map(S=>`${S}@${u[S]??"latest"}`),x=await bo(e.configFile)??{},p=x.libVersion,m=await ea(e.libEntry).then(()=>!0).catch(()=>!1),_=p===c;if(_&&m&&await Fd(e))return{kind:"already-current",libVersion:c};if(!_||!m){await Bh(e.libDir,{recursive:!0}),await Nh(i,e.libEntry),await Nh(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let S=Bd(e.libDir,"package.json"),y=`${JSON.stringify({type:"module"},null,2)}
112
- `;await ea(S,"utf8").catch(()=>null)!==y&&await IS(S,y)}return(!_||!await Fd(e))&&await(t.installWrappers??kS)(e,f),x.libVersion=c,await qi(x,e.configFile),zd.info("dist installed",{libEntry:e.libEntry,fromVersion:p,toVersion:c}),_&&m?{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 Fd(t){for(let e of Qr){let r=jr(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await zh(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function kS(t,e){await OS(t.installLock,async()=>{if(await Fd(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${ts}.staging-${process.pid}-${r}`,o=jr(i,"node_modules"),c=jr(t.libDir,"node_modules");try{await Bh(i,{recursive:!0}),await DS(e,i),await PS(o);let u=`${c}.trash-${r}`;await Mh(c,u).catch(()=>{}),await Mh(o,c),await Md(u,{recursive:!0,force:!0}).catch(()=>{}),zd.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await Md(i,{recursive:!0,force:!0}).catch(()=>{})}})}function DS(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=nt("npm",r,{stdio:["ignore","pipe","pipe"]}),u="";c.stderr?.on("data",x=>{u.length<8192&&(u+=x.toString("utf8"))});let f=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",x=>{clearTimeout(f),o(new Error(`spawn npm failed: ${String(x)}`))}),c.once("close",x=>{clearTimeout(f),x===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${x}: ${u.trim().slice(0,2e3)}`))})})}async function PS(t){for(let e of Qr){let r=jr(t,...e.split("/")),i=JSON.parse(await ea(jr(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=jr(t,".bin",o),u=await zh(c);process.platform!=="win32"&&!(u.mode&73)&&await AS(c,u.mode|73).catch(()=>{})}}async function OS(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 Md(t,{force:!0}).catch(()=>{})}}Ea();ne();Oe();import{closeSync as Uh,fstatSync as qh,openSync as Gh,readFileSync as LS,readSync as NS,readdirSync as MS,statSync as BS}from"node:fs";import{join as ta}from"node:path";var zS=new Set(["debug","info","warn","error"]);function Hh(t){let e=t,r=Cn(e,"--agent-id");e=r.rest;let i=Cn(e,"--date");e=i.rest;let o=Cn(e,"-n","--lines");e=o.rest;let c=Cn(e,"--level");e=c.rest;let u=Cn(e,"--grep");e=u.rest;let f=o.value===void 0?200:Number(o.value),x=Number.isInteger(f)&&f>=0?f:200,p=c.value&&zS.has(c.value)?c.value:void 0,m={lines:x,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(m.agentId=r.value),i.value&&(m.date=i.value),p&&(m.level=p),u.value&&(m.grep=u.value),m}function FS(t,e){return t.agentId?ta(Xe(t.agentId,e).logs,rr("agent",t.date)):ta(e.bridgeLogsDir,rr("bridge",t.date))}function US(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function qS(t,e){let r;try{r=MS(t)}catch{return[]}let i=[];for(let o of r){let c=ba(o,e);if(!c)continue;let u=0;try{u=BS(ta(t,o)).size}catch{}i.push({file:ta(t,o),date:c,size:u})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function jh(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"&&!pu(r,e.level))return!1}return!0}var Fh={debug:"90",info:"36",warn:"33",error:"31"},GS=new Set(["ts","level","module","msg"]);function HS(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function Wh(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=HS(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&Fh[o]&&(c=`\x1B[${Fh[o]}m${c}\x1B[0m`);let u=typeof r.module=="string"?r.module:"",f=typeof r.msg=="string"?r.msg:"",x=Object.entries(r).filter(([p])=>!GS.has(p)).map(([p,m])=>` ${p}=${typeof m=="string"?m:JSON.stringify(m)}`).join("");return`${i} ${c} ${u} ${f}${x}`}function jS(t,e,r){let c=LS(t,"utf8").split(`
113
- `).filter(u=>u.length>0).filter(u=>jh(u,{level:e.level,grep:e.grep}));for(let u of US(c,e.lines))process.stdout.write(`${Wh(u,{raw:e.raw,color:r})}
114
- `)}async function Kh(t,e){let r=e.paths??X(),i=process.stdout.isTTY===!0;if(t.list){let u=t.agentId?Xe(t.agentId,r).logs:r.bridgeLogsDir,f=t.agentId?"agent":"bridge",x=qS(u,f);if(x.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${u}
109
+ `)}catch{}}let e=new $o({processTitle:Rr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await yo(),o=i??{};os({pid:process.pid}),W.info(i?"loaded bridge config":"initialized bridge config");let c=new Ho(new Gr),l=null,f=new Eo({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(N,j,$,se)=>{if(!l)throw new Error("agentManager not ready");return l.spawnSessionDownstream(N,j,$,se)}}),x=new mo({paths:t,config:o,registry:f});l=x;let p,w,_=null,S={},y,v=null,I=null,C=null,R=new vn;function O(N,j){return R.enqueue(()=>D(N,j))}function E(){I||(I=new Jo({isConnected:()=>c.isConnected(),forceReconnect:()=>C?O(C,{force:!0}):void 0,onFatal:N=>{if(process.env[Qi]==="1"){W.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:N});return}W.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:N}),process.exit(1)}})),I.start()}async function D(N,j){let $=N,se=$?.privatecode;if(!se)throw new k("IPC_BAD_REQUEST","/connect requires privatecode");let Ye=Ri($.env),xe=$.handshake_url,he=$.frontier_url,vt=Rh($.env,xe,he);if(C=$,!j?.force&&p===se&&w===vt){let me=await mS(t);return f.agents.size===0&&me?(W.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),Zo(t,x).catch(Ae=>W.warn("connect-noop auto-revive error (ignored)",{err:String(Ae)}))):W.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let ft=!!p&&p!==se,Qt=w!==void 0&&w!==vt,Bt=ft||Qt,en=await Mc({privatecode:se,...xe?{endpoint:xe}:{},ppeOverride:Ye});if(Bt){W.warn("connect config switched, resetting agents",{pcChanged:ft,envChanged:Qt,previousPc:p?Yo(p):"",nextPc:Yo(se)});for(let me of[...f.agents.values()])await me.dispose("connect config switch").catch(()=>{}),f.agents.delete(me.agentId);f.disconnectedAgents.size>0&&(W.info("clearing disconnectedAgents set on connect config switch",{count:f.disconnectedAgents.size}),f.disconnectedAgents.clear()),await c.swap(new Gr,"connect switch").catch(()=>{})}_=en.deviceId,os({deviceId:_,pid:process.pid}),nd({patToken:se,env:$.env}).catch(me=>W.warn("coze-cli setup error (ignored)",{err:String(me)}));let Kr=new Zi({handshake:en,privatecode:se,...he?{urlOverride:he}:{},ppeOverride:Ye,getPatTokenForAgent:me=>f.agents.get(me)?.patToken});return await c.swap(Kr,"connect"),p=se,w=vt,S=Ye,y=xe,$.mock_scenario!==void 0&&(f.setMockScenario($.mock_scenario),W.info("mock scenario set",{scenario:$.mock_scenario})),v||(v=new Pi({core:f,getDeviceId:()=>_??"",onTickEnd:()=>z.retryPending().catch(me=>W.warn("detailSync.retryPending failed (ignored)",{err:String(me)})),onAuthFailures:J})),v.start(),E(),Bt&&Zo(t,x).catch(me=>W.warn("post-connect-switch auto-revive error (ignored)",{err:String(me)})),Xi(se,t).catch(me=>W.warn("writePatToken after /connect failed (ignored)",{err:String(me)})),W.info("/connect: WS established",{deviceId:_}),{ok:!0,note:"connected"}}f.registerExtension("_agent/create",async N=>x.createAgent(N.params)),f.registerExtension("_agent/health",async()=>({ok:!0}));let L={},F=new oo({agents:f.agents,disposeAndMarkDisconnected:async(N,j)=>{let $=f.agents.get(N);if($){await x.cleanupOpenclawSessionProviders($).catch(Ye=>W.warn("cleanup openclaw providers failed (ignored)",{agentId:N,err:String(Ye)}));let se=!0;try{await $.dispose(`disconnect: ${j}`)}catch(Ye){se=!1,W.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:N,err:String(Ye)}),$.status="error"}se&&($.status="disconnected",f.unregister(N),f.disconnectedAgents.add(N))}else f.disconnectedAgents.add(N)},detailSyncer:async N=>{if(!L.ref)throw new Error("agent-detail-sync not initialized yet");await L.ref.syncOne(N)},cleanupOpenclawProviders:async N=>{await x.cleanupOpenclawSessionProviders(N)},openclawRepair:async(N,j)=>{await x.openclawRepair(N,j)},isRuntimePendingPermission:N=>f.hasPendingPermissionFor(N)});f.registerExtension("_agent/listSkills",N=>F.listSkills(N.params)),f.registerExtension("_agent/addSkills",N=>F.addSkills(N.params)),f.registerExtension("_agent/removeSkills",N=>F.removeSkills(N.params)),f.registerExtension("_agent/getFileTree",N=>F.getFileTree(N.params)),f.registerExtension("_agent/getFileContent",N=>F.getFileContent(N.params)),f.registerExtension("_agent/update",N=>F.updateAgent(N.params)),f.registerExtension("_agent/disconnect",N=>F.disconnectAgent(N.params)),f.registerExtension("_agent/switchModel",N=>F.switchModel(N.params)),f.registerExtension("_agent/reset",N=>F.resetAgent(N.params)),f.registerExtension("_agent/repair",N=>F.repairAgent(N.params)),f.registerExtension("_agent/upgrade",N=>F.upgradeBridge(N.params));let z=new fs({paths:t,handlers:F,agentManager:x,sendDetail:N=>f.sendRequest("_agent/detail",N)});L.ref=z;let J=async N=>{await Promise.allSettled(N.map(async j=>{try{await F.disconnectAgent({agentId:j.agentId,reason:`auth_failure: code=${j.code} ${j.message}`}),W.info("agent disconnected due to auth failure from heartbeat response",{agentId:j.agentId,code:j.code,message:j.message})}catch($){W.warn("disconnect during authFailure handling failed (ignored)",{agentId:j.agentId,err:String($)})}}))};c.onConnect(({initial:N})=>{W.info("frontier upstream connected, triggering detail sync",{initial:N}),z.syncAll(N?"initial-connect":"reconnect").catch(j=>W.warn("detail sync top-level error (ignored)",{err:String(j)}))});let V=new bo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let N=f.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[Qi]==="1"?"manual":"supervisor",agents:[...f.agents.keys()],deviceId:_??"",frameworksCache:o.frameworksCache??{},...N?{mockScenario:N}:{}}}},{method:"POST",path:"/pair",handler:async N=>{let j=N,$=j?.privatecode,se=j?.pairing_code;if(!$||!se)throw new k("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Ye=Ri(j.env),xe=j.handshake_url,he=j.frontier_url,vt=Rh(j.env,xe,he),ft=!!p&&p!==$,Qt=w!==void 0&&w!==vt,Bt=ft||Qt,en=await Mc({privatecode:$,...xe?{endpoint:xe}:{},ppeOverride:Ye});if(Bt){W.warn("pair config switched, resetting agents",{pcChanged:ft,envChanged:Qt,previousPc:p?Yo(p):"",nextPc:Yo($),previousEnvKey:w??"",nextEnvKey:vt});for(let Ae of[...f.agents.values()])await Ae.dispose("pair config switch").catch(()=>{}),f.agents.delete(Ae.agentId);f.disconnectedAgents.size>0&&(W.info("clearing disconnectedAgents set on pair config switch",{count:f.disconnectedAgents.size}),f.disconnectedAgents.clear()),await c.swap(new Gr,"pair switch").catch(()=>{})}_=en.deviceId,os({deviceId:_,pid:process.pid}),nd({patToken:$,env:j.env}).catch(Ae=>W.warn("coze-cli setup error (ignored)",{err:String(Ae)}));let Kr=new Zi({handshake:en,privatecode:$,...he?{urlOverride:he}:{},ppeOverride:Ye,getPatTokenForAgent:Ae=>f.agents.get(Ae)?.patToken});await c.swap(Kr,"pair");try{let Ae=new jn;o.frameworksCache=await Ae.detectAll(),await Ui(o),W.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ae){W.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ae)})}let me=Object.keys(o.frameworksCache??{});try{let Ae=await f.sendRequest("_agent/pair",{pairCode:se,patToken:$,frameworks:me,_meta:{cozeDeviceId:_}});W.info("_agent/pair ok",{pairResult:Ae}),p=$,w=vt,S=Ye,y=xe,j.mock_scenario!==void 0&&(f.setMockScenario(j.mock_scenario),W.info("mock scenario set",{scenario:j.mock_scenario})),Xi($,t).catch(De=>W.warn("writePatToken after /pair failed (ignored)",{err:String(De)})),v||(v=new Pi({core:f,getDeviceId:()=>_??"",onTickEnd:()=>z.retryPending().catch(De=>W.warn("detailSync.retryPending failed (ignored)",{err:String(De)})),onAuthFailures:J})),v.start(),E(),Bt&&Zo(t,x).catch(De=>W.warn("post-pair-switch auto-revive error (ignored)",{err:String(De)}));let Yn;return j.agent_id&&(Yn=await _S(j.agent_id,t,x,De=>f.sendRequest("_agent/detail",De),$).catch(De=>(W.error("--agent-id ensureAgent failed",{agentId:j.agent_id,err:String(De)}),{ok:!1,agentId:j.agent_id??"",note:String(De)}))),{ok:!0,note:"paired with cloud",...Yn?{agent:Yn}:{}}}catch(Ae){return W.error("_agent/pair failed",{err:String(Ae)}),{ok:!1,note:`pair failed: ${String(Ae)}`}}}},{method:"POST",path:"/connect",handler:N=>O(N)},{method:"POST",path:"/_agent/create",handler:async N=>{let j=N;return{ok:!0,result:await x.createAgent(j)}}},{method:"POST",path:"/agent/send",handler:async N=>{let j=N;if(!j?.agentId||!j?.sessionId||!j?.kind||!j?.path)throw new k("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!p)throw new k("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let $=j;return await($.groupFile?U0:F0)($,{core:f,patToken:p,handshakeBase:y,ppeOverride:S})}catch($){if($ instanceof k)return{ok:!1,code:$.code,message:$.message};throw $}}},{method:"POST",path:"/reload",handler:async N=>{let j=N?.agent_id,$=await f.reloadAgents(j);return W.info("IPC /reload: recycled agent subprocesses",{agentId:j??"(all)",recycled:$}),{ok:!0,recycled:$}}},{method:"POST",path:"/shutdown",handler:async()=>(W.info("IPC /shutdown received"),setImmediate(()=>{oe.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:te,token:Z}=await V.start();try{await Ih(t.libEntry,t)}catch(N){W.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(N)})}await f.start(),yS({paths:t,core:f,agentManager:x,detectAll:async()=>(o.frameworksCache=await new jn().detectAll(),await Ui(o),o.frameworksCache)}).catch(N=>W.warn("startup warmup error (ignored)",{err:String(N)})),bl().then(async()=>{let{probeAcpVersion:N}=await Promise.resolve().then(()=>(rn(),yl));for(let j of["claude-code","codex"]){let $=await N(j);$&&W.info("acp wrapper version",{framework:j,version:$})}}).catch(N=>W.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(N)}));let ie=null,oe={port:te,token:Z,core:f,ipc:V,shutdown(N){return ie||(W.info("daemon shutdown",{reason:N}),ie=(async()=>{v?.stop(),I?.stop(),await f.stop(N),await V.stop(),await e.release()})(),ie)}};for(let N of["SIGTERM","SIGINT"])process.on(N,()=>{oe.shutdown(N).then(()=>process.exit(0))});return process.on("exit",()=>d0()),process.on("unhandledRejection",N=>{W.error("unhandledRejection",{reason:N instanceof Error?N.message:String(N),stack:N instanceof Error?N.stack:void 0})}),process.on("uncaughtException",N=>{W.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}
110
+ `)}catch{}process.exit(1)}),W.info("daemon ready",{port:te,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),ES({cliSpawned:process.env[Qi]==="1",readPatToken:()=>Wo(t),connect:O}).catch(N=>W.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(N)})),oe}async function mS(t){return cs(t).length>0}function Yo(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function Rh(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function wS(t,e){let r=cs(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(sn(),us));for(let c of r){await o(c,t).catch(l=>W.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(l)}));try{let l=await i(c,t);l?.disconnectedAt&&(e.disconnectedAgents.add(c),W.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:l.disconnectedAt,reason:l.disconnectReason??""}))}catch(l){W.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(l)})}}}async function _S(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(sn(),us)),l=await c(t,e);if(l){W.info("--agent-id: local config found, reconnecting",{agentId:t,framework:l.framework,hadDisconnect:!!l.disconnectedAt});let w=Ph(l),_={agentId:l.agentId,framework:l.framework,...l.cozeIdentity?{cozeIdentity:l.cozeIdentity}:{},...l.model?{model:l.model}:{},...o?{patToken:o}:{},...w?{_meta:w}:{}};return await r.createAgent(_),{ok:!0,agentId:t,note:l.disconnectedAt?"revived from local config":"connected from local config"}}W.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let f=await i({_meta:{cozeAgentId:t}});if(!f.framework)throw new k("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:f.agentId,framework:f.framework,...f.cozeIdentity?{cozeIdentity:f.cozeIdentity}:{},...f.model?{model:f.model}:{},...o?{patToken:o}:{},...f.deployType?{_meta:{cozeDeployType:f.deployType}}:{}};await r.createAgent(x);let p=f.deployType==="cloud"&&f.framework==="openclaw";return{ok:!0,agentId:t,note:p?"cloud agent acknowledged":"created from cloud detail"}}async function yS(t){let e=t.logger??W;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 wS(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(()=>(sn(),us));W.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,l=0;for(let f of i){let x;try{x=await o(f,t)}catch(p){W.warn("auto-revive: load config failed (skipping)",{agentId:f,err:String(p)}),l+=1;continue}if(!x){l+=1;continue}if(x.disconnectedAt){W.info("auto-revive: skip disconnected agent",{agentId:f,disconnectedAt:x.disconnectedAt}),l+=1;continue}try{W.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:f,framework:x.framework});let p=Ph(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){W.warn("auto-revive: createAgent failed (skipping)",{agentId:f,framework:x.framework,err:String(p)}),l+=1}}return W.info("auto-revive: done",{revived:c,skipped:l,total:i.length}),{revived:c,skipped:l,total:i.length}}async function ES(t){let e=t.logger??W;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 Ph(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}Vo();Pe();import{readFile as Oh}from"node:fs/promises";var Xt=class{paths;constructor(e){this.paths=e??Q()}async probe(e=1e3){let r=await Xo(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:vS(i)}}}async request(e){let r=await Xo(this.paths);if(!r)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(r,e)}async fetch(e,r){let i=r.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,l=setTimeout(()=>c.abort(),r.timeoutMs??5e3);try{let f=await fetch(`http://127.0.0.1:${e.port}${r.path}`,{method:r.method,headers:o,body:i?JSON.stringify(r.body):void 0,signal:c.signal}),x=await f.text();return{status:f.status,body:bS(x)}}finally{clearTimeout(l)}}};async function Xo(t){try{let[e,r]=await Promise.all([Oh(t.portFile,"utf8"),Oh(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 bS(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function vS(t){return t instanceof Error?t.message:String(t)}Kt();ne();er();import{spawn as SS}from"node:child_process";import{userInfo as Nh}from"node:os";var Ld="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",IS=new Set(["bash","zsh","sh","dash","ksh"]),Lh=We("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),AS=2e3;function CS(t,e=Ld){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(`
111
+ `)){let f=l.indexOf("=");f<=0||(c[l.slice(0,f)]=l.slice(f+1))}return c}function TS(){let t=(process.env.SHELL??"").trim()||(Nh().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return IS.has(e)?t:null}function kS(t){return new Promise(e=>{let r=`printf '%s' '${Ld}'; env; printf '%s' '${Ld}'`,i;try{i=SS(t,["-ilc",r],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??Nh().homedir}})}catch{e(null);return}let o="",c=!1,l=w=>{try{i.pid&&process.kill(-i.pid,w)}catch{}},f=w=>{c||(c=!0,clearTimeout(x),clearTimeout(p),e(w))};i.stdout?.on("data",w=>{o+=w.toString("utf8")}),i.on("error",()=>f(null)),i.on("close",()=>f(o.length>0?o:null));let x=setTimeout(()=>l("SIGTERM"),Lh),p=setTimeout(()=>{l("SIGKILL"),f(o.length>0?o:null)},Lh+AS)})}async function Nd(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let r=TS();if(!r)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??kS)(r);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=CS(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}Pe();function An(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],l=!1;for(let f of e){if(c===f){i=t[o+1],o+=1,l=!0;break}if(c.startsWith(`${f}=`)){i=c.slice(f.length+1),l=!0;break}}l||r.push(c)}return{value:i,rest:r}}rn();import{chmod as RS,copyFile as Mh,mkdir as zh,readFile as Qo,rename as Bh,rm as Md,stat as Fh,writeFile as DS}from"node:fs/promises";import{homedir as I3}from"node:os";import{dirname as PS,join as qr,resolve as Bd,sep as es}from"node:path";import{fileURLToPath as OS}from"node:url";Kt();ne();Pe();var zd=q("dist-install");function LS(t){let e=OS(t),r=PS(e),i=`${es}src${es}`;if(r.includes(i)||r.endsWith(`${es}src${es}cli`))return null;let o=Bd(r,"index.js"),c=Bd(r,"..","package.json");return{dist:o,pkgJson:c}}async function Ud(t={}){let e=t.paths??Q(),r=LS(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 Qo(o,"utf8"));c=S.version??"unknown",l=S.dependencies??{}}catch(S){return zd.warn("cannot read source package.json,skip dist install",{err:String(S)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(S)}`}}let f=Zr.map(S=>`${S}@${l[S]??"latest"}`),x=await yo(e.configFile)??{},p=x.libVersion,w=await Qo(e.libEntry).then(()=>!0).catch(()=>!1),_=p===c;if(_&&w&&await Fd(e))return{kind:"already-current",libVersion:c};if(!_||!w){await zh(e.libDir,{recursive:!0}),await Mh(i,e.libEntry),await Mh(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let S=Bd(e.libDir,"package.json"),y=`${JSON.stringify({type:"module"},null,2)}
112
+ `;await Qo(S,"utf8").catch(()=>null)!==y&&await DS(S,y)}return(!_||!await Fd(e))&&await(t.installWrappers??NS)(e,f),x.libVersion=c,await Ui(x,e.configFile),zd.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 Fd(t){for(let e of Zr){let r=qr(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await Fh(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function NS(t,e){await zS(t.installLock,async()=>{if(await Fd(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${es}.staging-${process.pid}-${r}`,o=qr(i,"node_modules"),c=qr(t.libDir,"node_modules");try{await zh(i,{recursive:!0}),await MS(e,i),await BS(o);let l=`${c}.trash-${r}`;await Bh(c,l).catch(()=>{}),await Bh(o,c),await Md(l,{recursive:!0,force:!0}).catch(()=>{}),zd.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await Md(i,{recursive:!0,force:!0}).catch(()=>{})}})}function MS(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=nt("npm",r,{stdio:["ignore","pipe","pipe"]}),l="";c.stderr?.on("data",x=>{l.length<8192&&(l+=x.toString("utf8"))});let f=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",x=>{clearTimeout(f),o(new Error(`spawn npm failed: ${String(x)}`))}),c.once("close",x=>{clearTimeout(f),x===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${x}: ${l.trim().slice(0,2e3)}`))})})}async function BS(t){for(let e of Zr){let r=qr(t,...e.split("/")),i=JSON.parse(await Qo(qr(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=qr(t,".bin",o),l=await Fh(c);process.platform!=="win32"&&!(l.mode&73)&&await RS(c,l.mode|73).catch(()=>{})}}async function zS(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 Md(t,{force:!0}).catch(()=>{})}}Ea();ne();Pe();import{closeSync as Gh,fstatSync as qh,openSync as jh,readFileSync as FS,readSync as US,readdirSync as GS,statSync as qS}from"node:fs";import{join as ea}from"node:path";var jS=new Set(["debug","info","warn","error"]);function Hh(t){let e=t,r=An(e,"--agent-id");e=r.rest;let i=An(e,"--date");e=i.rest;let o=An(e,"-n","--lines");e=o.rest;let c=An(e,"--level");e=c.rest;let l=An(e,"--grep");e=l.rest;let f=o.value===void 0?200:Number(o.value),x=Number.isInteger(f)&&f>=0?f:200,p=c.value&&jS.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 HS(t,e){return t.agentId?ea(Xe(t.agentId,e).logs,tr("agent",t.date)):ea(e.bridgeLogsDir,tr("bridge",t.date))}function WS(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function KS(t,e){let r;try{r=GS(t)}catch{return[]}let i=[];for(let o of r){let c=ya(o,e);if(!c)continue;let l=0;try{l=qS(ea(t,o)).size}catch{}i.push({file:ea(t,o),date:c,size:l})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function Wh(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"&&!pl(r,e.level))return!1}return!0}var Uh={debug:"90",info:"36",warn:"33",error:"31"},$S=new Set(["ts","level","module","msg"]);function VS(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function Kh(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=VS(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&Uh[o]&&(c=`\x1B[${Uh[o]}m${c}\x1B[0m`);let l=typeof r.module=="string"?r.module:"",f=typeof r.msg=="string"?r.msg:"",x=Object.entries(r).filter(([p])=>!$S.has(p)).map(([p,w])=>` ${p}=${typeof w=="string"?w:JSON.stringify(w)}`).join("");return`${i} ${c} ${l} ${f}${x}`}function JS(t,e,r){let c=FS(t,"utf8").split(`
113
+ `).filter(l=>l.length>0).filter(l=>Wh(l,{level:e.level,grep:e.grep}));for(let l of WS(c,e.lines))process.stdout.write(`${Kh(l,{raw:e.raw,color:r})}
114
+ `)}async function $h(t,e){let r=e.paths??Q(),i=process.stdout.isTTY===!0;if(t.list){let l=t.agentId?Xe(t.agentId,r).logs:r.bridgeLogsDir,f=t.agentId?"agent":"bridge",x=KS(l,f);if(x.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${l}
115
115
  `),1;for(let p of x)process.stdout.write(`${p.date} ${(p.size/1024).toFixed(1)}KB ${p.file}
116
- `);return 0}let o=t.date??kn(new Date),c=FS({agentId:t.agentId,date:o},r);try{jS(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
116
+ `);return 0}let o=t.date??Tn(new Date),c=HS({agentId:t.agentId,date:o},r);try{JS(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
117
117
  \u7528 'coze-bridge log${t.agentId?` --agent-id ${t.agentId}`:""} --list' \u770B\u6709\u54EA\u4E9B\u65E5\u671F\u3002
118
118
  (legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${r.logFile})
119
- `),1}return t.follow&&await $S(c,t,i),0}var WS=500;function KS(t){try{let e=Gh(t,"r");try{return qh(e).size}finally{Uh(e)}}catch{return 0}}async function $S(t,e,r){let i=KS(t),o="",c=!1,u=()=>{c=!0};process.on("SIGINT",u);try{for(;!c;){let f="";try{let x=Gh(t,"r");try{let p=qh(x).size;if(p>i){let m=Buffer.allocUnsafe(p-i),_=NS(x,m,0,m.length,i);f=m.subarray(0,_).toString("utf8"),i+=_}}finally{Uh(x)}}catch{}if(f){let x=(o+f).split(`
120
- `);o=x.pop()??"";for(let p of x)p.length>0&&jh(p,{level:e.level,grep:e.grep})&&process.stdout.write(`${Wh(p,{raw:e.raw,color:r})}
121
- `)}await new Promise(x=>setTimeout(x,WS))}}finally{process.off("SIGINT",u)}}import{basename as VS,resolve as YS}from"node:path";Oe();var ZS=9e4,JS={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,OPERATION_NOT_ALLOWED_FOR_CLOUD:1,METHOD_NOT_FOUND:1,AGENT_DEPENDENCY_INSTALL_FAILED:1,AGENT_APPROVAL_TIMEOUT:1,AGENT_ENV_NOT_READY:1};function XS(t){return JS[t]??1}async function $h(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>
119
+ `),1}return t.follow&&await XS(c,t,i),0}var YS=500;function ZS(t){try{let e=jh(t,"r");try{return qh(e).size}finally{Gh(e)}}catch{return 0}}async function XS(t,e,r){let i=ZS(t),o="",c=!1,l=()=>{c=!0};process.on("SIGINT",l);try{for(;!c;){let f="";try{let x=jh(t,"r");try{let p=qh(x).size;if(p>i){let w=Buffer.allocUnsafe(p-i),_=US(x,w,0,w.length,i);f=w.subarray(0,_).toString("utf8"),i+=_}}finally{Gh(x)}}catch{}if(f){let x=(o+f).split(`
120
+ `);o=x.pop()??"";for(let p of x)p.length>0&&Wh(p,{level:e.level,grep:e.grep})&&process.stdout.write(`${Kh(p,{raw:e.raw,color:r})}
121
+ `)}await new Promise(x=>setTimeout(x,YS))}}finally{process.off("SIGINT",l)}}import{basename as QS,resolve as e2}from"node:path";Pe();var t2=9e4,n2={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,OPERATION_NOT_ALLOWED_FOR_CLOUD:1,METHOD_NOT_FOUND:1,AGENT_DEPENDENCY_INSTALL_FAILED:1,AGENT_APPROVAL_TIMEOUT:1,AGENT_ENV_NOT_READY:1};function r2(t){return n2[t]??1}async function Vh(t,e={}){let r=e.paths??Q();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>
122
122
  `),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.
123
- `),3;let i=await Qo(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.
124
- `),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:YS(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 QS(i,"/agent/send",o,ZS)}catch(u){return process.stderr.write(`Error: daemon IPC failed: ${u instanceof Error?u.message:String(u)}
123
+ `),3;let i=await Xo(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.
124
+ `),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:e2(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 i2(i,"/agent/send",o,t2)}catch(l){return process.stderr.write(`Error: daemon IPC failed: ${l instanceof Error?l.message:String(l)}
125
125
  `),4}if(!c.ok)return process.stderr.write(`Error: ${c.code}: ${c.message}
126
- `),XS(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
127
- `);else{let u=t.name??VS(o.path);if(t.groupFile){let f=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${u} (uri=${f})
128
- `)}else process.stdout.write(`Sent ${t.kind} ${u} (${e1(c.bytes)})
129
- `)}return 0}async function QS(t,e,r,i){let o=new AbortController,c=setTimeout(()=>o.abort(),i);try{let u=await fetch(`http://127.0.0.1:${t.port}${e}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"content-type":"application/json"},body:JSON.stringify(r),signal:o.signal}),f=await u.text(),x=f?JSON.parse(f):null;return x&&typeof x=="object"&&"ok"in x?x:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${u.status}): ${f.slice(0,200)}`}}finally{clearTimeout(c)}}function e1(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var np=q("cli");function Ge(t,e){let{value:r,rest:i}=Cn(t,e);return{value:r,rest:i}}function aa(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
130
- `)}function S1(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:D}=Ge(e.slice(1),"--agent-id");return D?{mode:"reload",agentId:D}:{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 A1(e.slice(1));if(e[0]==="log")return{mode:"log",...Hh(e.slice(1))};if(e[0]==="connect")return I1(e.slice(1));if(e.includes("--status"))return aa("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return aa("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return aa("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return aa("--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}=Ge(r,"--pat-token");r=o;let{value:c,rest:u}=Ge(r,"--pair-code");r=u;let{value:f,rest:x}=Ge(r,"--env");r=x;let{value:p,rest:m}=Ge(r,"--handshake-url");r=m;let{value:_,rest:S}=Ge(r,"--frontier-url");r=S;let{value:y,rest:v}=Ge(r,"--mock-scenario");r=v;let{value:A}=Ge(r,"--agent-id"),I=r.includes("--skip-rebuild-env");if(!i||!c)return{mode:"help"};let R={mode:"pair",privatecode:i,pairingCode:c};return f&&(R.env=f),p&&(R.handshakeUrl=p),_&&(R.frontierUrl=_),y&&(R.mockScenario=y),A&&(R.agentId=A),I&&(R.skipRebuildEnv=!0),R}function A1(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}=Ge(i,"--caption");i=c;let{value:u,rest:f}=Ge(i,"--name");i=f;let{value:x,rest:p}=Ge(i,"--agent-id");i=p;let{value:m,rest:_}=Ge(i,"--session-id");i=_;let{value:S,rest:y}=Ge(i,"--mime");i=y;let v=i.includes("--group-file");i=i.filter(R=>R!=="--group-file");let A=i.includes("--json"),I={mode:"send",kind:e,path:r,json:A};return o&&(I.caption=o),u&&(I.name=u),x&&(I.agentId=x),m&&(I.sessionId=m),v&&(I.groupFile=!0),S&&(I.mimeType=S),I}function I1(t){let e=t,{value:r,rest:i}=Ge(e,"--pat-token");e=i;let{value:o,rest:c}=Ge(e,"--env");e=c;let{value:u,rest:f}=Ge(e,"--handshake-url");e=f;let{value:x,rest:p}=Ge(e,"--frontier-url");e=p;let{value:m,rest:_}=Ge(e,"--mock-scenario");e=_;let S=e.includes("--skip-rebuild-env"),y={mode:"connect"};return r&&(y.privatecode=r),o&&(y.env=o),u&&(y.handshakeUrl=u),x&&(y.frontierUrl=x),m&&(y.mockScenario=m),S&&(y.skipRebuildEnv=!0),y}var T1=`
126
+ `),r2(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
127
+ `);else{let l=t.name??QS(o.path);if(t.groupFile){let f=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${l} (uri=${f})
128
+ `)}else process.stdout.write(`Sent ${t.kind} ${l} (${s2(c.bytes)})
129
+ `)}return 0}async function i2(t,e,r,i){let o=new AbortController,c=setTimeout(()=>o.abort(),i);try{let l=await fetch(`http://127.0.0.1:${t.port}${e}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"content-type":"application/json"},body:JSON.stringify(r),signal:o.signal}),f=await l.text(),x=f?JSON.parse(f):null;return x&&typeof x=="object"&&"ok"in x?x:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${l.status}): ${f.slice(0,200)}`}}finally{clearTimeout(c)}}function s2(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var rp=q("cli");function Ge(t,e){let{value:r,rest:i}=An(t,e);return{value:r,rest:i}}function oa(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
130
+ `)}function k2(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}=Ge(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 R2(e.slice(1));if(e[0]==="log")return{mode:"log",...Hh(e.slice(1))};if(e[0]==="connect")return D2(e.slice(1));if(e.includes("--status"))return oa("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return oa("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return oa("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return oa("--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}=Ge(r,"--pat-token");r=o;let{value:c,rest:l}=Ge(r,"--pair-code");r=l;let{value:f,rest:x}=Ge(r,"--env");r=x;let{value:p,rest:w}=Ge(r,"--handshake-url");r=w;let{value:_,rest:S}=Ge(r,"--frontier-url");r=S;let{value:y,rest:v}=Ge(r,"--mock-scenario");r=v;let{value:I}=Ge(r,"--agent-id"),C=r.includes("--skip-rebuild-env");if(!i||!c)return{mode:"help"};let R={mode:"pair",privatecode:i,pairingCode:c};return f&&(R.env=f),p&&(R.handshakeUrl=p),_&&(R.frontierUrl=_),y&&(R.mockScenario=y),I&&(R.agentId=I),C&&(R.skipRebuildEnv=!0),R}function R2(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}=Ge(i,"--caption");i=c;let{value:l,rest:f}=Ge(i,"--name");i=f;let{value:x,rest:p}=Ge(i,"--agent-id");i=p;let{value:w,rest:_}=Ge(i,"--session-id");i=_;let{value:S,rest:y}=Ge(i,"--mime");i=y;let v=i.includes("--group-file");i=i.filter(R=>R!=="--group-file");let I=i.includes("--json"),C={mode:"send",kind:e,path:r,json:I};return o&&(C.caption=o),l&&(C.name=l),x&&(C.agentId=x),w&&(C.sessionId=w),v&&(C.groupFile=!0),S&&(C.mimeType=S),C}function D2(t){let e=t,{value:r,rest:i}=Ge(e,"--pat-token");e=i;let{value:o,rest:c}=Ge(e,"--env");e=c;let{value:l,rest:f}=Ge(e,"--handshake-url");e=f;let{value:x,rest:p}=Ge(e,"--frontier-url");e=p;let{value:w,rest:_}=Ge(e,"--mock-scenario");e=_;let S=e.includes("--skip-rebuild-env"),y={mode:"connect"};return r&&(y.privatecode=r),o&&(y.env=o),l&&(y.handshakeUrl=l),x&&(y.frontierUrl=x),w&&(y.mockScenario=w),S&&(y.skipRebuildEnv=!0),y}var P2=`
131
131
  coze-bridge - local bridge daemon for cloud Agent Service
132
132
 
133
133
  Pair (paste from cloud UI; start/reuse daemon and deliver pair-code):
@@ -208,57 +208,57 @@ Deprecated flags (still work, but emit a warning; will be removed in a future re
208
208
 
209
209
  Internal:
210
210
  <node> <entry> --daemon daemon mode (OS supervisor only)
211
- `.trimStart();async function rp(t=process.argv,e={}){let r=S1(t);switch(r.mode){case"help":return process.stdout.write(T1),0;case"version":return process.stdout.write(`${Cr}
212
- `),0;case"daemon":{try{await kh()}catch(i){return np.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return C1(e);case"stop":return sp(e);case"reload":return D1(r.agentId,e);case"log":return Kh(r,e);case"update":return R1(e);case"purge":return P1(e);case"service-install":return O1(e);case"service-uninstall":return L1(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),N1(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),M1(r.privatecode,e,i,r.skipRebuildEnv)}case"send":return $h({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 ip(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 C1(t){let e=t.paths??X(),r=new Xt(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
213
- `),1;if(i.kind==="stale")return await ip(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
211
+ `.trimStart();async function ip(t=process.argv,e={}){let r=k2(t);switch(r.mode){case"help":return process.stdout.write(P2),0;case"version":return process.stdout.write(`${Ar}
212
+ `),0;case"daemon":{try{await Dh()}catch(i){return rp.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return O2(e);case"stop":return op(e);case"reload":return M2(r.agentId,e);case"log":return $h(r,e);case"update":return L2(e);case"purge":return B2(e);case"service-install":return z2(e);case"service-uninstall":return F2(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),U2(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),G2(r.privatecode,e,i,r.skipRebuildEnv)}case"send":return Vh({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 sp(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 O2(t){let e=t.paths??Q(),r=new Xt(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
213
+ `),1;if(i.kind==="stale")return await sp(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
214
214
  `),1;let o=await r.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
215
215
  ${JSON.stringify(o.body,null,2)}
216
- `),0}async function sp(t){let e=t.paths??X(),r=new Xt(e),i=t.daemonSweep??(async()=>{let x=c0();return await d0(x),x}),o=async()=>{t.skipProcessKill||await i(e)},c=await rs(t),u=!1;if(c)try{await c.uninstall(),u=!0}catch(x){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(x)}
217
- `)}let f=await r.probe();if(f.kind==="not-running")return await o(),process.stdout.write(u?`coze-bridge: stopped
216
+ `),0}async function op(t){let e=t.paths??Q(),r=new Xt(e),i=t.daemonSweep??(async()=>{let x=l0();return await u0(x),x}),o=async()=>{t.skipProcessKill||await i(e)},c=await ns(t),l=!1;if(c)try{await c.uninstall(),l=!0}catch(x){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(x)}
217
+ `)}let f=await r.probe();if(f.kind==="not-running")return await o(),process.stdout.write(l?`coze-bridge: stopped
218
218
  `:`coze-bridge: not running
219
- `),0;if(f.kind==="stale")return await ip(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
219
+ `),0;if(f.kind==="stale")return await sp(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
220
220
  `),0;try{return await r.request({method:"POST",path:"/shutdown"}),await o(),process.stdout.write(`coze-bridge: stopped
221
221
  `),0}catch(x){return(await r.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
222
222
  `),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(x)}
223
- `),1)}}async function R1(t){return await sp(t),(t.spawnNpx??k1)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function k1(t){return new Promise(e=>{let r=nt("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)}
224
- `),e(1)})})}async function D1(t,e){let r=new Xt(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
223
+ `),1)}}async function L2(t){return await op(t),(t.spawnNpx??N2)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function N2(t){return new Promise(e=>{let r=nt("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)}
224
+ `),e(1)})})}async function M2(t,e){let r=new Xt(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
225
225
  `),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)
226
226
  `):process.stdout.write(`coze-bridge: reloaded ${c.length} agent(s): ${c.join(", ")||"(none)"}
227
227
  `),0}return process.stderr.write(`coze-bridge: reload failed: ${JSON.stringify(o.body)}
228
228
  `),1}catch(o){return process.stderr.write(`coze-bridge: reload failed: ${String(o)}
229
- `),1}}async function rs(t){if(t.supervisor){let c=t.supervisor,u={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:f=>c.install(u,f),uninstall:()=>c.uninstall(u)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>(ep(),Qh)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function op(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??Ch,o=t.waitTimeoutMs??15e3,c=t.sleep??z1,u=t.paths??X(),f=await rs(t);if(f&&(f.platform==="darwin"||f.platform==="linux")){try{await f.install({activate:!0});let x=await tp(e,o,c);if(x.kind==="connected")return x;St(u.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:o})}catch(x){St(u.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(x)})}St(u.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:f.platform}),await f.uninstall().catch(()=>{}),await B1(u.pidFile,c)}else f&&await f.install({activate:!1}).catch(x=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(x)}
229
+ `),1}}async function ns(t){if(t.supervisor){let c=t.supervisor,l={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:f=>c.install(l,f),uninstall:()=>c.uninstall(l)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>(tp(),ep)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function ap(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??kh,o=t.waitTimeoutMs??15e3,c=t.sleep??j2,l=t.paths??Q(),f=await ns(t);if(f&&(f.platform==="darwin"||f.platform==="linux")){try{await f.install({activate:!0});let x=await np(e,o,c);if(x.kind==="connected")return x;St(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){St(l.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(x)})}St(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:f.platform}),await f.uninstall().catch(()=>{}),await q2(l.pidFile,c)}else f&&await f.install({activate:!1}).catch(x=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(x)}
230
230
  `));return process.stdout.write(`coze-bridge: starting daemon...
231
- `),await i({paths:t.paths}),tp(e,o,c)}async function P1(t){let e=new Xt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
232
- `);try{await e.request({method:"POST",path:"/shutdown"})}catch(u){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(u)}
233
- `)}await new Promise(u=>setTimeout(u,500))}let i=await rs(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
234
- `)}catch(u){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(u)}
235
- `)}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}
236
- `)}catch(u){return process.stderr.write(`coze-bridge: remove failed: ${String(u)}
231
+ `),await i({paths:t.paths}),np(e,o,c)}async function B2(t){let e=new Xt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
232
+ `);try{await e.request({method:"POST",path:"/shutdown"})}catch(l){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(l)}
233
+ `)}await new Promise(l=>setTimeout(l,500))}let i=await ns(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
234
+ `)}catch(l){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(l)}
235
+ `)}let o=t.paths??Q(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
236
+ `)}catch(l){return process.stderr.write(`coze-bridge: remove failed: ${String(l)}
237
237
  `),1}return process.stdout.write(`coze-bridge: purged (agents workspaces preserved under ~/.coze/agents)
238
- `),0}async function O1(t){let e=await rs(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
238
+ `),0}async function z2(t){let e=await ns(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
239
239
  `),await e.install(),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
240
240
  `),0}catch(r){return process.stderr.write(`coze-bridge: service install failed: ${String(r)}
241
- `),1}}async function L1(t){let e=await rs(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
241
+ `),1}}async function F2(t){let e=await ns(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
242
242
  `),0}catch(r){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(r)}
243
- `),1}}async function ap(t,e,r){if(e)return St(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await r();return i.kind==="ok"?(St(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(St(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)
244
- `),St(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function N1(t,e,r,i={},o,c){let u=new Xt(r.paths),f=r.paths??X(),x=await ap(f,c,r.reconstructEnv??Nd);if(await Zc(f,x).catch(_=>St(f.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(_)})),!r.skipDistInstall){let _=await Ud({paths:r.paths});_.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${_.fromVersion} \u2192 ${_.toVersion}
245
- `),(await u.probe()).kind==="connected"&&(await u.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(y=>setTimeout(y,500)))):_.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${_.libVersion}
246
- `)}let p=await op(r,u);if(p.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${p.kind}
247
- `),1;let m={privatecode:t,pairing_code:e};i.env&&(m.env=i.env),i.handshakeUrl&&(m.handshake_url=i.handshakeUrl),i.frontierUrl&&(m.frontier_url=i.frontierUrl),i.mockScenario&&(m.mock_scenario=i.mockScenario),o&&(m.agent_id=o);try{let _=await u.request({method:"POST",path:"/pair",body:m,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}
243
+ `),1}}async function cp(t,e,r){if(e)return St(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await r();return i.kind==="ok"?(St(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(St(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)
244
+ `),St(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function U2(t,e,r,i={},o,c){let l=new Xt(r.paths),f=r.paths??Q(),x=await cp(f,c,r.reconstructEnv??Nd);if(await Jc(f,x).catch(_=>St(f.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(_)})),!r.skipDistInstall){let _=await Ud({paths:r.paths});_.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${_.fromVersion} \u2192 ${_.toVersion}
245
+ `),(await l.probe()).kind==="connected"&&(await l.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(y=>setTimeout(y,500)))):_.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${_.libVersion}
246
+ `)}let p=await ap(r,l);if(p.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${p.kind}
247
+ `),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}
248
248
  `),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"
249
249
  `),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(_.body)}
250
250
  `),1}catch(_){return process.stderr.write(`coze-bridge: pair failed: ${String(_)}
251
- `),1}}async function M1(t,e,r={},i){let o=e.paths??X(),c=t??await Ko(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 u=new Xt(e.paths),f=await ap(o,i,e.reconstructEnv??Nd);if(await Zc(o,f).catch(m=>St(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(m)})),!e.skipDistInstall){let m=await Ud({paths:e.paths});m.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${m.fromVersion} \u2192 ${m.toVersion}
252
- `),(await u.probe()).kind==="connected"&&(await u.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(S=>setTimeout(S,500)))):m.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${m.libVersion}
253
- `)}let x=await op(e,u);if(x.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${x.kind}
254
- `),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 m=await u.request({method:"POST",path:"/connect",body:p,timeoutMs:35e3});return m.status===200&&m.body?.ok?(process.stdout.write(`coze-bridge: connected (${m.body.note??"ok"})
255
- `),t!==void 0&&await Qi(c,o).catch(_=>np.warn("writePatToken after connect failed (ignored)",{err:String(_)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(m.body)}
256
- `),1)}catch(m){return process.stderr.write(`coze-bridge: connect failed: ${String(m)}
257
- `),1}}async function tp(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 B1(t,e,r=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let c=0;c<r;c++){let u;try{u=await o(t,"utf8")}catch{return}let f=Number.parseInt(u.trim(),10);if(!Number.isFinite(f)||f<=0||!Bi(f))return;await e(i)}}function z1(t){return new Promise(e=>setTimeout(e,t))}ne();function F1(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 cp(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=F1(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
251
+ `),1}}async function G2(t,e,r={},i){let o=e.paths??Q(),c=t??await Wo(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 Xt(e.paths),f=await cp(o,i,e.reconstructEnv??Nd);if(await Jc(o,f).catch(w=>St(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(w)})),!e.skipDistInstall){let w=await Ud({paths:e.paths});w.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${w.fromVersion} \u2192 ${w.toVersion}
252
+ `),(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}
253
+ `)}let x=await ap(e,l);if(x.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${x.kind}
254
+ `),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"})
255
+ `),await Xi(c,o).catch(_=>rp.warn("writePatToken after connect failed (ignored)",{err:String(_)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(w.body)}
256
+ `),1)}catch(w){return process.stderr.write(`coze-bridge: connect failed: ${String(w)}
257
+ `),1}}async function np(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 q2(t,e,r=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let c=0;c<r;c++){let l;try{l=await o(t,"utf8")}catch{return}let f=Number.parseInt(l.trim(),10);if(!Number.isFinite(f)||f<=0||!Mi(f))return;await e(i)}}function j2(t){return new Promise(e=>setTimeout(e,t))}ne();function H2(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 dp(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=H2(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
258
258
  `),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
259
259
  \u5347\u7EA7\u5B8C\u540E\u9700\u8981\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u91CD\u65B0\u8FDE\u63A5:
260
260
  npx -y coze-bridge@latest stop
261
261
  npx -y coze-bridge@latest connect
262
262
 
263
- `)}cp();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&xu("warn");rp(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
263
+ `)}dp();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&xl("warn");ip(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
264
264
  `),process.exit(1)});