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

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 +86 -86
  2. package/package.json +2 -2
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 Sa=Object.defineProperty;var rg=Object.getOwnPropertyDescriptor;var ig=Object.getOwnPropertyNames;var sg=Object.getPrototypeOf,og=Object.prototype.hasOwnProperty;var pe=(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 it=(t,e)=>()=>(t&&(e=t(t=0)),e);var ue=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Ia=(t,e)=>{for(var r in e)Sa(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&&Sa(t,o,{get:()=>e[o],enumerable:!(i=rg(e,o))||i.enumerable});return t};var qt=(t,e,r)=>(r=t!=null?ng(sg(t)):{},ag(e||!t||!t.__esModule?Sa(r,"default",{value:t,enumerable:!0}):r,t));function Ye(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var ar=it(()=>{"use strict"});import{createWriteStream as cg,mkdirSync as dg,readdirSync as lg,unlinkSync as ug}from"node:fs";import{join as fl}from"node:path";function Nn(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function cr(t,e){return`${t}-${e}.log`}function Aa(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[d,u,f]=c.split("-").map(Number);return Date.UTC(d??0,(u??1)-1,f??1)};return Math.floor((i(e)-i(t))/864e5)>r}function cs(t,e,r,i){let o;try{o=lg(t)}catch{return}for(let c of o){let d=Aa(c,e);if(d&&fg(d,r,i))try{ug(fl(t,c))}catch{}}}var ti,Ta=it(()=>{"use strict";ti=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>Nn(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(fl(this.dir,cr(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&&cs(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 hg,mkdirSync as xg}from"node:fs";import{join as pg}from"node:path";function xl(t){let e=t.retentionDays??wg,r=t.clock??(()=>Nn(new Date));ls={bridgeSink:new ti(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new ti(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();cs(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])cs(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 pl(t){Ra=t}function gl(t){return dr[Ra]<=dr[t]}function ml(t,e){let r=dr[t];return r===void 0?!0:r>=dr[e]}function us(t){hl={...t}}function wl(t){let e=(u,f=2)=>String(u).padStart(f,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),d=e(o%60);return`${Nn(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${d}`}function Ct(t,e,r,i,o){try{let c=`${JSON.stringify({ts:wl(new Date),level:e,module:r,msg:i,...o})}
11
+ `;xg(t,{recursive:!0}),hg(pg(t,cr("bridge",Nn(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 ds(t,e,r,i,o){if(dr[t]<dr[Ra])return;let c=`${JSON.stringify({ts:wl(new Date),level:t,module:e,msg:r,...hl,...i})}
12
+ `;if(ls){let d=yg(o,i),u=d?_g(ls,d):ls.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?mg.write(c):gg.write(c)}function G(t,e){return{debug:(r,i)=>ds("debug",t,r,i,e),info:(r,i)=>ds("info",t,r,i,e),warn:(r,i)=>ds("warn",t,r,i,e),error:(r,i)=>ds("error",t,r,i,e),child:r=>G(`${t}.${r}`,e),forAgent:r=>G(t,r)}}var dr,Ra,gg,mg,hl,wg,ls,se=it(()=>{"use strict";ar();Ta();dr={debug:10,info:20,warn:30,error:40},Ra=(()=>{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,hl={},wg=Ye("COZE_BRIDGE_LOG_RETENTION_DAYS",30),ls=null});var R,Xe=it(()=>{"use strict";R=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 El={};Ia(El,{ACP_WRAPPER_NPM_PACKAGES:()=>ri,_resetAcpInstallerForTests:()=>Ag,_setBinaryPathCacheForTests:()=>Tg,buildAcpSpawn:()=>ii,ensureAcpInstalled:()=>lr,getAcpBinaryPath:()=>fs,pickWhichLine:()=>Da,probeAcpVersion:()=>Ig,resolveAcpCommand:()=>bl});import{readFileSync as _l}from"node:fs";import{createRequire as bg}from"node:module";import{dirname as Eg,resolve as vg}from"node:path";function Da(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=yl.resolve(`${t.npmPackage}/package.json`),r=Eg(e),i=JSON.parse(_l(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 lr(t,e){let r=Ca[t];if(!r)throw new R("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=ni.get(t);if(i)return i;try{let o=Sg(r);return ni.set(t,o),ka.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw ka.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 R("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=Ca[t];if(e)try{let r=yl.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(_l(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){ka.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function fs(t){return ni.get(t)}function bl(t,e){if(e)return e;let r=fs(t);if(!r)throw new R("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return r}function ii(t,e,r){if(e)return{command:e,args:[...r]};let i=bl(t);return{command:process.execPath,args:[i,...r]}}function Ag(){ni.clear()}function Tg(t,e){ni.set(t,e)}var ka,Ca,ri,yl,ni,dn=it(()=>{"use strict";Xe();se();ka=G("agents.acp-installer"),Ca={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@agentclientprotocol/codex-acp",binary:"codex-acp"}},ri=Object.values(Ca).filter(t=>t!==void 0).map(t=>t.npmPackage),yl=bg(import.meta.url),ni=new Map});import{chmod as kg,mkdir as Cg,readFile as Dg,rename as Pg,rm as Og,writeFile as Lg}from"node:fs/promises";import{dirname as Ng}from"node:path";async function ur(t){try{let e=await Dg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function ln(t,e,r){await Cg(Ng(t),{recursive:!0});let i=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{await Lg(i,e,{encoding:"utf8",mode:r?.mode}),await Pg(i,t),r?.mode!==void 0&&await kg(t,r.mode)}catch(o){throw await Og(i,{force:!0}).catch(()=>{}),o}}async function fr(t,e,r){await ln(t,`${JSON.stringify(e,null,2)}
14
+ `,r)}var un=it(()=>{"use strict"});import{promises as Il,readdirSync as Mg}from"node:fs";import{homedir as Bg}from"node:os";import{sep as Fg,join as Pe,resolve as Al}from"node:path";function ne(t){let e=t??Bg(),r=Pe(e,".coze"),i=Pe(r,"bridge"),o=Pe(i,"lib"),c=Pe(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Pe(o,"index.js"),binDir:Pe(i,"bin"),pidFile:Pe(i,"bridge.pid"),portFile:Pe(i,"bridge.port"),tokenFile:Pe(i,"bridge.token"),patTokenFile:Pe(i,"pat-token"),agentEnvFile:Pe(i,"agent-env.json"),logFile:Pe(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Pe(c,"daemon-stdio.log"),installLock:Pe(i,"install.lock"),configFile:Pe(i,"config.json"),agentsRoot:Pe(r,"agents")}}function st(t,e=ne()){let r=Pe(e.agentsRoot,t);return{root:r,config:Pe(r,"config.json"),workspace:Pe(r,"workspace"),logs:Pe(r,"logs")}}function hs(t=ne()){try{return Mg(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function si(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+Fg)}var Fe=it(()=>{"use strict"});var gs={};Ia(gs,{AGENT_CONFIG_FILE_MODE:()=>xs,enforceAgentConfigMode:()=>Gg,loadAgentConfig:()=>ze,persistAgentSessions:()=>oi,persistAgentSkills:()=>ps,saveAgentConfig:()=>Je});import{chmod as zg,stat as Ug}from"node:fs/promises";function ze(t,e){return ur(st(t,e).config)}function Je(t,e){return fr(st(t.agentId,e).config,t,{mode:xs})}async function Gg(t,e){if(process.platform==="win32")return;let r=st(t,e).config;try{let i=await Ug(r);if(!i.isFile())return;let o=i.mode&511;o!==xs&&(await zg(r,xs),Tl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Tl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function oi(t,e,r){let i=await ze(t,r);i&&(i.sessions=Object.fromEntries(e),await Je(i,r))}async function ps(t,e,r){let i=await ze(t,r);i&&(i.skills=e,await Je(i,r))}var Tl,xs,fn=it(()=>{"use strict";un();se();Fe();Tl=G("agent-config"),xs=384});var La=ue((R2,Cl)=>{Cl.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 ws=ue(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 $g(t){return function(...e){return e.length&&(t=t.replace(/\{(\d)\}/g,(r,i)=>e[i]||"")),new Error("ADM-ZIP: "+t)}}for(let t of Object.keys(Dl))Pl[t]=$g(Dl[t])});var Bl=ue((C2,Ml)=>{var Vg=pe("fs"),Ue=pe("path"),Ol=La(),Jg=ws(),Zg=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 Te(t){this.sep=Ue.sep,this.fs=Vg,Ll(t)&&Ll(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Ml.exports=Te;Te.prototype.makeDir=function(t){let e=this;function r(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var d;try{d=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(d&&d.isFile())throw Jg.FILE_IN_THE_WAY(`"${o}"`)}})}r(t)};Te.prototype.writeFileTo=function(t,e,r,i){let o=this;if(o.fs.existsSync(t)){if(!r)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var d=Ue.dirname(t);o.fs.existsSync(d)||o.makeDir(d);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};Te.prototype.writeFileToAsync=function(t,e,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(d){if(d&&!r)return o(!1);c.fs.stat(t,function(u,f){if(d&&f.isDirectory())return o(!1);var x=Ue.dirname(t);c.fs.exists(x,function(g){g||c.makeDir(x),c.fs.open(t,"w",438,function(w,S){w?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(_,b){c.fs.write(b,e,0,e.length,0,function(){c.fs.close(b,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):S?c.fs.write(S,e,0,e.length,0,function(){c.fs.close(S,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};Te.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let d=[];return e.fs.readdirSync(i).forEach(function(u){let f=Ue.join(i,u),x=e.fs.statSync(f);(!o||o.test(f))&&d.push(Ue.normalize(f)+(x.isDirectory()?e.sep:"")),x.isDirectory()&&c&&(d=d.concat(r(f,o,c)))}),d}return r(t,void 0,!0)};Te.prototype.findFilesAsync=function(t,e){let r=this,i=[];r.fs.readdir(t,function(o,c){if(o)return e(o);let d=c.length;if(!d)return e(null,i);c.forEach(function(u){u=Ue.join(t,u),r.fs.stat(u,function(f,x){if(f)return e(f);x&&(i.push(Ue.normalize(u)+(x.isDirectory()?r.sep:"")),x.isDirectory()?r.findFilesAsync(u,function(g,w){if(g)return e(g);i=i.concat(w),--d||e(null,i)}):--d||e(null,i))})})})};Te.prototype.getAttributes=function(){};Te.prototype.setAttributes=function(){};Te.crc32update=function(t,e){return Nl[(t^e)&255]^t>>>8};Te.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,r=-1;for(let i=0;i<e;)r=Te.crc32update(r,t[i++]);return~r>>>0};Te.methodToString=function(t){switch(t){case Ol.STORED:return"STORED ("+t+")";case Ol.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Te.canonical=function(t){if(!t)return"";let e=Ue.posix.normalize("/"+t.split("\\").join("/"));return Ue.join(".",e)};Te.zipnamefix=function(t){if(!t)return"";let e=Ue.posix.normalize("/"+t.split("\\").join("/"));return Ue.posix.join(".",e)};Te.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]};Te.sanitize=function(t,e){t=Ue.resolve(Ue.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Ue.normalize(Ue.join(t,r.slice(i,o).join(Ue.sep)));if(c.indexOf(t)===0)return c}return Ue.normalize(Ue.join(t,Ue.basename(e)))};Te.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};Te.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};Te.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)};Te.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};Te.isWin=Zg;Te.crcTable=Nl});var zl=ue((D2,Fl)=>{var Yg=pe("path");Fl.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 Gl=ue((P2,Ul)=>{Ul.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var pr=ue((O2,xr)=>{xr.exports=Bl();xr.exports.Constants=La();xr.exports.Errors=ws();xr.exports.FileAttr=zl();xr.exports.decoder=Gl()});var jl=ue((L2,Hl)=>{var hn=pr(),z=hn.Constants;Hl.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,d=0,u=0,f=0,x=0,g=0,w=0,S=0,_=0,b=0;t|=hn.isWin?2560:768,r|=z.FLG_EFS;let I={extraLen:0},T=y=>Math.max(0,y)>>>0,k=y=>Math.max(0,y)&65535,D=y=>Math.max(0,y)&255;return o=hn.fromDate2DOS(new Date),{get made(){return t},set made(y){t=y},get version(){return e},set version(y){e=y},get flags(){return r},set flags(y){r=y},get flags_efs(){return(r&z.FLG_EFS)>0},set flags_efs(y){y?r|=z.FLG_EFS:r&=~z.FLG_EFS},get flags_desc(){return(r&z.FLG_DESC)>0},set flags_desc(y){y?r|=z.FLG_DESC:r&=~z.FLG_DESC},get method(){return i},set method(y){switch(y){case z.STORED:this.version=10;case z.DEFLATED:default:this.version=20}i=y},get time(){return hn.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=hn.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=T(y)},get timeHighByte(){return D(o>>>8)},get crc(){return c},set crc(y){c=T(y)},get compressedSize(){return d},set compressedSize(y){d=T(y)},get size(){return u},set size(y){u=T(y)},get fileNameLength(){return f},set fileNameLength(y){f=y},get extraLength(){return x},set extraLength(y){x=y},get extraLocalLength(){return I.extraLen},set extraLocalLength(y){I.extraLen=y},get commentLength(){return g},set commentLength(y){g=y},get diskNumStart(){return w},set diskNumStart(y){w=T(y)},get inAttr(){return S},set inAttr(y){S=T(y)},get attr(){return _},set attr(y){_=T(y)},get fileAttr(){return(_||0)>>16&4095},get offset(){return b},set offset(y){b=T(y)},get encrypted(){return(r&z.FLG_ENC)===z.FLG_ENC},get centralHeaderSize(){return z.CENHDR+f+x+g},get realDataOffset(){return b+z.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(y){var C=y.slice(b,b+z.LOCHDR);if(C.readUInt32LE(0)!==z.LOCSIG)throw hn.Errors.INVALID_LOC();I.version=C.readUInt16LE(z.LOCVER),I.flags=C.readUInt16LE(z.LOCFLG),I.flags_desc=(I.flags&z.FLG_DESC)>0,I.method=C.readUInt16LE(z.LOCHOW),I.time=C.readUInt32LE(z.LOCTIM),I.crc=C.readUInt32LE(z.LOCCRC),I.compressedSize=C.readUInt32LE(z.LOCSIZ),I.size=C.readUInt32LE(z.LOCLEN),I.fnameLen=C.readUInt16LE(z.LOCNAM),I.extraLen=C.readUInt16LE(z.LOCEXT);let P=b+z.LOCHDR+I.fnameLen,F=P+I.extraLen;return y.slice(P,F)},loadFromBinary:function(y){if(y.length!==z.CENHDR||y.readUInt32LE(0)!==z.CENSIG)throw hn.Errors.INVALID_CEN();t=y.readUInt16LE(z.CENVEM),e=y.readUInt16LE(z.CENVER),r=y.readUInt16LE(z.CENFLG),i=y.readUInt16LE(z.CENHOW),o=y.readUInt32LE(z.CENTIM),c=y.readUInt32LE(z.CENCRC),d=y.readUInt32LE(z.CENSIZ),u=y.readUInt32LE(z.CENLEN),f=y.readUInt16LE(z.CENNAM),x=y.readUInt16LE(z.CENEXT),g=y.readUInt16LE(z.CENCOM),w=y.readUInt16LE(z.CENDSK),S=y.readUInt16LE(z.CENATT),_=y.readUInt32LE(z.CENATX),b=y.readUInt32LE(z.CENOFF)},localHeaderToBinary:function(){var y=Buffer.alloc(z.LOCHDR);return y.writeUInt32LE(z.LOCSIG,0),y.writeUInt16LE(e,z.LOCVER),y.writeUInt16LE(r,z.LOCFLG),y.writeUInt16LE(i,z.LOCHOW),y.writeUInt32LE(o,z.LOCTIM),y.writeUInt32LE(c,z.LOCCRC),y.writeUInt32LE(d,z.LOCSIZ),y.writeUInt32LE(u,z.LOCLEN),y.writeUInt16LE(f,z.LOCNAM),y.writeUInt16LE(I.extraLen,z.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(z.CENHDR+f+x+g);return y.writeUInt32LE(z.CENSIG,0),y.writeUInt16LE(t,z.CENVEM),y.writeUInt16LE(e,z.CENVER),y.writeUInt16LE(r,z.CENFLG),y.writeUInt16LE(i,z.CENHOW),y.writeUInt32LE(o,z.CENTIM),y.writeUInt32LE(c,z.CENCRC),y.writeUInt32LE(d,z.CENSIZ),y.writeUInt32LE(u,z.CENLEN),y.writeUInt16LE(f,z.CENNAM),y.writeUInt16LE(x,z.CENEXT),y.writeUInt16LE(g,z.CENCOM),y.writeUInt16LE(w,z.CENDSK),y.writeUInt16LE(S,z.CENATT),y.writeUInt32LE(_,z.CENATX),y.writeUInt32LE(b,z.CENOFF),y},toJSON:function(){let y=function(C){return C+" bytes"};return{made:t,version:e,flags:r,method:hn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(d),size:y(u),fileNameLength:y(f),extraLength:y(x),commentLength:y(g),diskNumStart:w,inAttr:S,attr:_,offset:b,centralHeaderSize:y(z.CENHDR+f+x+g)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Wl=ue((N2,ql)=>{var gr=pr(),ve=gr.Constants;ql.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 ve.ENDHDR+o},loadFromBinary:function(c){if((c.length!==ve.ENDHDR||c.readUInt32LE(0)!==ve.ENDSIG)&&(c.length<ve.ZIP64HDR||c.readUInt32LE(0)!==ve.ZIP64SIG))throw gr.Errors.INVALID_END();c.readUInt32LE(0)===ve.ENDSIG?(t=c.readUInt16LE(ve.ENDSUB),e=c.readUInt16LE(ve.ENDTOT),r=c.readUInt32LE(ve.ENDSIZ),i=c.readUInt32LE(ve.ENDOFF),o=c.readUInt16LE(ve.ENDCOM)):(t=gr.readBigUInt64LE(c,ve.ZIP64SUB),e=gr.readBigUInt64LE(c,ve.ZIP64TOT),r=gr.readBigUInt64LE(c,ve.ZIP64SIZE),i=gr.readBigUInt64LE(c,ve.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(ve.ENDHDR+o);return c.writeUInt32LE(ve.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,ve.ENDSUB),c.writeUInt16LE(e,ve.ENDTOT),c.writeUInt32LE(r,ve.ENDSIZ),c.writeUInt32LE(i,ve.ENDOFF),c.writeUInt16LE(o,ve.ENDCOM),c.fill(" ",ve.ENDHDR),c},toJSON:function(){let c=function(d,u){let f=d.toString(16).toUpperCase();for(;f.length<u;)f="0"+f;return"0x"+f};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Ma=ue(Na=>{Na.EntryHeader=jl();Na.MainHeader=Wl()});var $l=ue((B2,Kl)=>{Kl.exports=function(t){var e=pe("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],d=0;o.on("data",function(u){c.push(u),d+=u.length}),o.on("end",function(){var u=Buffer.alloc(d),f=0;u.fill(0);for(var x=0;x<c.length;x++){var g=c[x];g.copy(u,f),f+=g.length}i&&i(u)}),o.end(t)}}}});var Jl=ue((F2,Vl)=>{var Xg=+(process.versions?process.versions.node:"").split(".")[0]||0;Vl.exports=function(t,e){var r=pe("zlib");let i=Xg>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),d=[],u=0;c.on("data",function(f){d.push(f),u+=f.length}),c.on("end",function(){var f=Buffer.alloc(u),x=0;f.fill(0);for(var g=0;g<d.length;g++){var w=d[g];w.copy(f,x),x+=w.length}o&&o(f)}),c.end(t)}}}});var eu=ue((z2,Ql)=>{"use strict";var{randomFillSync:Zl}=pe("crypto"),Qg=ws(),em=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,Yl=(t,e)=>em[(t^e)&255]^t>>>8,ai=()=>typeof Zl=="function"?Zl(Buffer.alloc(12)):ai.node();ai.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 _s={genSalt:ai};function ys(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])}ys.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Yl(e[0],t),e[1]+=e[0]&255,e[1]=Xl(e[1],134775813)+1,e[2]=Yl(e[2],e[1]>>>24),t};ys.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Xl(t,t^1)>>8&255};function tm(t){let e=new ys(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 nm(t){let e=new ys(t);return function(r,i,o=0){i||(i=Buffer.alloc(r.length));for(let c of r){let d=e.next();i[o++]=c^d,e.updateKeys(c)}return i}}function rm(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=tm(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Qg.WRONG_PASSWORD();return i(t.slice(12))}function im(t){Buffer.isBuffer(t)&&t.length>=12?_s.genSalt=function(){return t.slice(0,12)}:t==="node"?_s.genSalt=ai.node:_s.genSalt=ai}function sm(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=nm(r),c=_s.genSalt();c[11]=e.crc>>>24&255,i&&(c[10]=e.crc>>>16&255);let d=Buffer.alloc(t.length+12);return o(c,d),o(t,d,12)}Ql.exports={decrypt:rm,encrypt:sm,_salter:im}});var tu=ue(bs=>{bs.Deflater=$l();bs.Inflater=Jl();bs.ZipCrypto=eu()});var Fa=ue((G2,nu)=>{var fe=pr(),om=Ma(),Re=fe.Constants,Ba=tu();nu.exports=function(t,e){var r=new om.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,d=null,u=Buffer.alloc(0),f=Buffer.alloc(0),x=!0;let g=t,w=typeof g.decoder=="object"?g.decoder:fe.decoder;x=w.hasOwnProperty("efs")?w.efs:!1;function S(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(f=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function _(y){if(!r.flags_desc&&!r.localHeader.flags_desc){if(fe.crc32(y)!==r.localHeader.crc)return!1}else{let C={},P=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(P)==Re.LOCSIG||e.readUInt32LE(P)==Re.CENSIG)throw fe.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(P)==Re.EXTSIG)C.crc=e.readUInt32LE(P+Re.EXTCRC),C.compressedSize=e.readUInt32LE(P+Re.EXTSIZ),C.size=e.readUInt32LE(P+Re.EXTLEN);else if(e.readUInt16LE(P+12)===19280)C.crc=e.readUInt32LE(P+Re.EXTCRC-4),C.compressedSize=e.readUInt32LE(P+Re.EXTSIZ-4),C.size=e.readUInt32LE(P+Re.EXTLEN-4);else throw fe.Errors.DESCRIPTOR_UNKNOWN();if(C.compressedSize!==r.compressedSize||C.size!==r.size||C.crc!==r.crc)throw fe.Errors.DESCRIPTOR_FAULTY();if(fe.crc32(y)!==C.crc)return!1}return!0}function b(y,C,P){if(typeof C>"u"&&typeof y=="string"&&(P=y,y=void 0),c)return y&&C&&C(Buffer.alloc(0),fe.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var F=S();if(F.length===0)return y&&C&&C(F),F;if(r.encrypted){if(typeof P!="string"&&!Buffer.isBuffer(P))throw fe.Errors.INVALID_PASS_PARAM();F=Ba.ZipCrypto.decrypt(F,r,P)}var M=Buffer.alloc(r.size);switch(r.method){case fe.Constants.STORED:if(F.copy(M),_(M))return y&&C&&C(M),M;throw y&&C&&C(M,fe.Errors.BAD_CRC()),fe.Errors.BAD_CRC();case fe.Constants.DEFLATED:var Y=new Ba.Inflater(F,r.size);if(y)Y.inflateAsync(function(J){J.copy(J,0),C&&(_(J)?C(J):C(J,fe.Errors.BAD_CRC()))});else{if(Y.inflate(M).copy(M,0),!_(M))throw fe.Errors.BAD_CRC(`"${w.decode(i)}"`);return M}break;default:throw y&&C&&C(Buffer.alloc(0),fe.Errors.UNKNOWN_METHOD()),fe.Errors.UNKNOWN_METHOD()}}function I(y,C){if((!d||!d.length)&&Buffer.isBuffer(e))return y&&C&&C(S()),S();if(d.length&&!c){var P;switch(r.method){case fe.Constants.STORED:return r.compressedSize=r.size,P=Buffer.alloc(d.length),d.copy(P),y&&C&&C(P),P;default:case fe.Constants.DEFLATED:var F=new Ba.Deflater(d);if(y)F.deflateAsync(function(Y){P=Buffer.alloc(Y.length),r.compressedSize=Y.length,Y.copy(P),C&&C(P)});else{var M=F.deflate();return r.compressedSize=M.length,M}F=null;break}}else if(y&&C)C(Buffer.alloc(0));else return Buffer.alloc(0)}function T(y,C){return fe.readBigUInt64LE(y,C)}function k(y){try{for(var C=0,P,F,M;C+4<y.length;)P=y.readUInt16LE(C),C+=2,F=y.readUInt16LE(C),C+=2,M=y.slice(C,C+F),C+=F,Re.ID_ZIP64===P&&D(M)}catch{throw fe.Errors.EXTRA_FIELD_PARSE_ERROR()}}function D(y){var C,P,F,M;y.length>=Re.EF_ZIP64_SCOMP&&(C=T(y,Re.EF_ZIP64_SUNCOMP),r.size===Re.EF_ZIP64_OR_32&&(r.size=C)),y.length>=Re.EF_ZIP64_RHO&&(P=T(y,Re.EF_ZIP64_SCOMP),r.compressedSize===Re.EF_ZIP64_OR_32&&(r.compressedSize=P)),y.length>=Re.EF_ZIP64_DSN&&(F=T(y,Re.EF_ZIP64_RHO),r.offset===Re.EF_ZIP64_OR_32&&(r.offset=F)),y.length>=Re.EF_ZIP64_DSN+4&&(M=y.readUInt32LE(Re.EF_ZIP64_DSN),r.diskNumStart===Re.EF_ZIP64_OR_16&&(r.diskNumStart=M))}return{get entryName(){return w.decode(i)},get rawEntryName(){return i},set entryName(y){i=fe.toBuffer(y,w.encode);var C=i[i.length-1];c=C===47||C===92,r.fileNameLength=i.length},get efs(){return typeof x=="function"?x(this.entryName):x},get extra(){return u},set extra(y){u=y,r.extraLength=y.length,k(y)},get comment(){return w.decode(o)},set comment(y){if(o=fe.toBuffer(y,w.encode),r.commentLength=o.length,o.length>65535)throw fe.Errors.COMMENT_TOO_LONG()},get name(){var y=w.decode(i);return c?y.substr(y.length-1).split("/").pop():y.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(y){I(!0,y)},setData:function(y){d=fe.toBuffer(y,fe.decoder.encode),!c&&d.length?(r.size=d.length,r.method=fe.Constants.DEFLATED,r.crc=fe.crc32(y),r.changed=!0):r.method=fe.Constants.STORED},getData:function(y){return r.changed?d:b(!1,null,y)},getDataAsync:function(y,C){r.changed?y(d):b(!0,y,C)},set attr(y){r.attr=y},get attr(){return r.attr},set header(y){r.loadFromBinary(y)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=u.length;var y=r.centralHeaderToBinary(),C=fe.Constants.CENHDR;return i.copy(y,C),C+=i.length,u.copy(y,C),C+=r.extraLength,o.copy(y,C),y},packLocalHeader:function(){let y=0;r.flags_efs=this.efs,r.extraLocalLength=f.length;let C=r.localHeaderToBinary(),P=Buffer.alloc(C.length+i.length+r.extraLocalLength);return C.copy(P,y),y+=C.length,i.copy(P,y),y+=i.length,f.copy(P,y),y+=f.length,P},toJSON:function(){let y=function(C){return"<"+(C&&C.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:y(e),data:y(d)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var su=ue((H2,iu)=>{var ru=Fa(),am=Ma(),Ze=pr();iu.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new am.MainHeader,d=!1,u=null;let f=new Set,x=e,{noSort:g,decoder:w}=x;t?b(x.readEntries):d=!0;function S(){let T=new Set;for(let k of Object.keys(i)){let D=k.split("/");if(D.pop(),!!D.length)for(let y=0;y<D.length;y++){let C=D.slice(0,y+1).join("/")+"/";T.add(C)}}for(let k of T)if(!(k in i)){let D=new ru(x);D.entryName=k,D.attr=16,D.temporary=!0,r.push(D),i[D.entryName]=D,f.add(D)}}function _(){if(d=!0,i={},c.diskEntries>(t.length-c.offset)/Ze.Constants.CENHDR)throw Ze.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var T=c.offset,k=0;k<r.length;k++){var D=T,y=new ru(x,t);y.header=t.slice(D,D+=Ze.Constants.CENHDR),y.entryName=t.slice(D,D+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(D,D+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(D,D+y.header.commentLength)),T+=y.header.centralHeaderSize,r[k]=y,i[y.entryName]=y}f.clear(),S()}function b(T){var k=t.length-Ze.Constants.ENDHDR,D=Math.max(0,k-65535),y=D,C=t.length,P=-1,F=0;for(typeof x.trailingSpace=="boolean"&&x.trailingSpace&&(D=0),k;k>=y;k--)if(t[k]===80){if(t.readUInt32LE(k)===Ze.Constants.ENDSIG){P=k,F=k,C=k+Ze.Constants.ENDHDR,y=k-Ze.Constants.END64HDR;continue}if(t.readUInt32LE(k)===Ze.Constants.END64SIG){y=D;continue}if(t.readUInt32LE(k)===Ze.Constants.ZIP64SIG){P=k,C=k+Ze.readBigUInt64LE(t,k+Ze.Constants.ZIP64SIZE)+Ze.Constants.ZIP64LEAD;break}}if(P==-1)throw Ze.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(P,C)),c.commentLength&&(o=t.slice(F+Ze.Constants.ENDHDR)),T&&_()}function I(){r.length>1&&!g&&r.sort((T,k)=>T.entryName.toLowerCase().localeCompare(k.entryName.toLowerCase()))}return{get entries(){return d||_(),r.filter(T=>!f.has(T))},get comment(){return w.decode(o)},set comment(T){o=Ze.toBuffer(T,w.encode),c.commentLength=o.length},getEntryCount:function(){return d?r.length:c.diskEntries},forEach:function(T){this.entries.forEach(T)},getEntry:function(T){return d||_(),i[T]||null},setEntry:function(T){d||_(),r.push(T),i[T.entryName]=T,c.totalEntries=r.length},deleteFile:function(T,k=!0){d||_();let D=i[T];this.getEntryChildren(D,k).map(C=>C.entryName).forEach(this.deleteEntry)},deleteEntry:function(T){d||_();let k=i[T],D=r.indexOf(k);D>=0&&(r.splice(D,1),delete i[T],c.totalEntries=r.length)},getEntryChildren:function(T,k=!0){if(d||_(),typeof T=="object")if(T.isDirectory&&k){let D=[],y=T.entryName;for(let C of r)C.entryName.startsWith(y)&&D.push(C);return D}else return[T];return[]},getChildCount:function(T){if(T&&T.isDirectory){let k=this.getEntryChildren(T);return k.includes(T)?k.length-1:k.length}return 0},compressToBuffer:function(){d||_(),I();let T=[],k=[],D=0,y=0;c.size=0,c.offset=0;let C=0;for(let M of this.entries){let Y=M.getCompressedData();M.header.offset=y;let J=M.packLocalHeader(),ie=J.length+Y.length;y+=ie,T.push(J),T.push(Y);let Q=M.packCentralHeader();k.push(Q),c.size+=Q.length,D+=ie+Q.length,C++}D+=c.mainHeaderSize,c.offset=y,c.totalEntries=C,y=0;let P=Buffer.alloc(D);for(let M of T)M.copy(P,y),y+=M.length;for(let M of k)M.copy(P,y),y+=M.length;let F=c.toBinary();return o&&o.copy(F,Ze.Constants.ENDHDR),F.copy(P,y),t=P,d=!1,P},toAsyncBuffer:function(T,k,D,y){try{d||_(),I();let C=[],P=[],F=0,M=0,Y=0;c.size=0,c.offset=0;let J=function(ie){if(ie.length>0){let Q=ie.shift(),ce=Q.entryName+Q.extra.toString();D&&D(ce),Q.getCompressedDataAsync(function(le){y&&y(ce),Q.header.offset=M;let O=Q.packLocalHeader(),H=O.length+le.length;M+=H,C.push(O),C.push(le);let K=Q.packCentralHeader();P.push(K),c.size+=K.length,F+=H+K.length,Y++,J(ie)})}else{F+=c.mainHeaderSize,c.offset=M,c.totalEntries=Y,M=0;let Q=Buffer.alloc(F);C.forEach(function(le){le.copy(Q,M),M+=le.length}),P.forEach(function(le){le.copy(Q,M),M+=le.length});let ce=c.toBinary();o&&o.copy(ce,Ze.Constants.ENDHDR),ce.copy(Q,M),t=Q,d=!1,T(Q)}};J(Array.from(this.entries))}catch(C){k(C)}}}}});var cu=ue((j2,au)=>{var Ie=pr(),Se=pe("path"),cm=Fa(),dm=su(),Mn=(...t)=>Ie.findLast(t,e=>typeof e=="boolean"),ou=(...t)=>Ie.findLast(t,e=>typeof e=="string"),lm=(...t)=>Ie.findLast(t,e=>typeof e=="function"),um={noSort:!1,readEntries:!1,method:Ie.Constants.NONE,fs:null};au.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),um);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=Ie.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new Ie(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=Ie.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=Ie.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw Ie.Errors.INVALID_FILENAME();let c=new dm(r,i),{canonical:d,sanitize:u,zipnamefix:f}=Ie;function x(_){if(_&&c){var b;if(typeof _=="string"&&(b=c.getEntry(Se.posix.normalize(_))),typeof _=="object"&&typeof _.entryName<"u"&&typeof _.header<"u"&&(b=c.getEntry(_.entryName)),b)return b}return null}function g(_){let{join:b,normalize:I,sep:T}=Se.posix;return b(Se.isAbsolute(_)?"/":".",I(T+_.split("\\").join(T)+T))}function w(_){return _ instanceof RegExp?(function(b){return function(I){return b.test(I)}})(_):typeof _!="function"?()=>!0:_}let S=(_,b)=>{let I=b.slice(-1);return I=I===o.sep?o.sep:"",Se.relative(_,b)+I};return{readFile:function(_,b){var I=x(_);return I&&I.getData(b)||null},childCount:function(_){let b=x(_);if(b)return c.getChildCount(b)},readFileAsync:function(_,b){var I=x(_);I?I.getDataAsync(b):b(null,"getEntry failed for:"+_)},readAsText:function(_,b){var I=x(_);if(I){var T=I.getData();if(T&&T.length)return T.toString(b||"utf8")}return""},readAsTextAsync:function(_,b,I){var T=x(_);T?T.getDataAsync(function(k,D){if(D){b(k,D);return}k&&k.length?b(k.toString(I||"utf8")):b("")}):b("")},deleteFile:function(_,b=!0){var I=x(_);I&&c.deleteFile(I.entryName,b)},deleteEntry:function(_){var b=x(_);b&&c.deleteEntry(b.entryName)},addZipComment:function(_){c.comment=_},getZipComment:function(){return c.comment||""},addZipEntryComment:function(_,b){var I=x(_);I&&(I.comment=b)},getZipEntryComment:function(_){var b=x(_);return b&&b.comment||""},updateFile:function(_,b){var I=x(_);I&&I.setData(b)},addLocalFile:function(_,b,I,T){if(o.fs.existsSync(_)){b=b?g(b):"";let k=Se.win32.basename(Se.win32.normalize(_));b+=I||k;let D=o.fs.statSync(_),y=D.isFile()?o.fs.readFileSync(_):Buffer.alloc(0);D.isDirectory()&&(b+=o.sep),this.addFile(b,y,T,D)}else throw Ie.Errors.FILE_NOT_FOUND(_)},addLocalFileAsync:function(_,b){_=typeof _=="object"?_:{localPath:_};let I=Se.resolve(_.localPath),{comment:T}=_,{zipPath:k,zipName:D}=_,y=this;o.fs.stat(I,function(C,P){if(C)return b(C,!1);k=k?g(k):"";let F=Se.win32.basename(Se.win32.normalize(I));if(k+=D||F,P.isFile())o.fs.readFile(I,function(M,Y){return M?b(M,!1):(y.addFile(k,Y,T,P),setImmediate(b,void 0,!0))});else if(P.isDirectory())return k+=o.sep,y.addFile(k,Buffer.alloc(0),T,P),setImmediate(b,void 0,!0)})},addLocalFolder:function(_,b,I){if(I=w(I),b=b?g(b):"",_=Se.normalize(_),o.fs.existsSync(_)){let T=o.findFiles(_),k=this;if(T.length)for(let D of T){let y=Se.join(b,S(_,D));I(y)&&k.addLocalFile(D,Se.dirname(y))}}else throw Ie.Errors.FILE_NOT_FOUND(_)},addLocalFolderAsync:function(_,b,I,T){T=w(T),I=I?g(I):"",_=Se.normalize(_);var k=this;o.fs.open(_,"r",function(D){if(D&&D.code==="ENOENT")b(void 0,Ie.Errors.FILE_NOT_FOUND(_));else if(D)b(void 0,D);else{var y=o.findFiles(_),C=-1,P=function(){if(C+=1,C<y.length){var F=y[C],M=S(_,F).split("\\").join("/");M=M.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),T(M)?o.fs.stat(F,function(Y,J){Y&&b(void 0,Y),J.isFile()?o.fs.readFile(F,function(ie,Q){ie?b(void 0,ie):(k.addFile(I+M,Q,"",J),P())}):(k.addFile(I+M+"/",Buffer.alloc(0),"",J),P())}):process.nextTick(()=>{P()})}else b(!0,void 0)};P()}})},addLocalFolderAsync2:function(_,b){let I=this;_=typeof _=="object"?_:{localPath:_},localPath=Se.resolve(g(_.localPath));let{zipPath:T,filter:k,namefix:D}=_;k instanceof RegExp?k=(function(P){return function(F){return P.test(F)}})(k):typeof k!="function"&&(k=function(){return!0}),T=T?g(T):"",D=="latin1"&&(D=P=>P.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof D!="function"&&(D=P=>P);let y=P=>Se.join(T,D(S(localPath,P))),C=P=>Se.win32.basename(Se.win32.normalize(D(P)));o.fs.open(localPath,"r",function(P){P&&P.code==="ENOENT"?b(void 0,Ie.Errors.FILE_NOT_FOUND(localPath)):P?b(void 0,P):o.findFilesAsync(localPath,function(F,M){if(F)return b(F);M=M.filter(Y=>k(y(Y))),M.length||b(void 0,!1),setImmediate(M.reverse().reduce(function(Y,J){return function(ie,Q){if(ie||Q===!1)return setImmediate(Y,ie,!1);I.addLocalFileAsync({localPath:J,zipPath:Se.dirname(y(J)),zipName:C(J)},Y)}},b))})})},addLocalFolderPromise:function(_,b){return new Promise((I,T)=>{this.addLocalFolderAsync2(Object.assign({localPath:_},b),(k,D)=>{k&&T(k),D&&I(this)})})},addFile:function(_,b,I,T){_=f(_);let k=x(_),D=k!=null;D||(k=new cm(i),k.entryName=_),k.comment=I||"";let y=typeof T=="object"&&T instanceof o.fs.Stats;y&&(k.header.time=T.mtime);var C=k.isDirectory?16:0;let P=k.isDirectory?16384:32768;return y?P|=4095&T.mode:typeof T=="number"?P|=4095&T:P|=k.isDirectory?493:420,C=(C|P<<16)>>>0,k.attr=C,k.setData(b),D||c.setEntry(k),k},getEntries:function(_){return c.password=_,c?c.entries:[]},getEntry:function(_){return x(_)},getEntryCount:function(){return c.getEntryCount()},forEach:function(_){return c.forEach(_)},extractEntryTo:function(_,b,I,T,k,D){T=Mn(!1,T),k=Mn(!1,k),I=Mn(!0,I),D=ou(k,D);var y=x(_);if(!y)throw Ie.Errors.NO_ENTRY();var C=d(y.entryName),P=u(b,D&&!y.isDirectory?D:I?C:Se.basename(C));if(y.isDirectory){var F=c.getEntryChildren(y);return F.forEach(function(J){if(J.isDirectory)return;var ie=J.getData();if(!ie)throw Ie.Errors.CANT_EXTRACT_FILE();var Q=d(J.entryName),ce=u(b,I?Q:Se.basename(Q));let le=k?J.header.fileAttr:void 0;o.writeFileTo(ce,ie,T,le)}),!0}var M=y.getData(c.password);if(!M)throw Ie.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(P)&&!T)throw Ie.Errors.CANT_OVERRIDE();let Y=k?_.header.fileAttr:void 0;return o.writeFileTo(P,M,T,Y),!0},test:function(_){if(!c)return!1;for(var b in c.entries)try{if(b.isDirectory)continue;var I=c.entries[b].getData(_);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(_,b,I,T){if(I=Mn(!1,I),T=ou(I,T),b=Mn(!1,b),!c)throw Ie.Errors.NO_ZIP();c.entries.forEach(function(k){var D=u(_,d(k.entryName));if(k.isDirectory){o.makeDir(D);return}var y=k.getData(T);if(!y)throw Ie.Errors.CANT_EXTRACT_FILE();let C=I?k.header.fileAttr:void 0;o.writeFileTo(D,y,b,C);try{o.fs.utimesSync(D,k.header.time,k.header.time)}catch{throw Ie.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(_,b,I,T){if(T=lm(b,I,T),I=Mn(!1,I),b=Mn(!1,b),!T)return new Promise((P,F)=>{this.extractAllToAsync(_,b,I,function(M){M?F(M):P(this)})});if(!c){T(Ie.Errors.NO_ZIP());return}_=Se.resolve(_);let k=P=>u(_,Se.normalize(d(P.entryName))),D=(P,F)=>new Error(P+': "'+F+'"'),y=[],C=[];c.entries.forEach(P=>{P.isDirectory?y.push(P):C.push(P)});for(let P of y){let F=k(P),M=I?P.header.fileAttr:void 0;try{o.makeDir(F),M&&o.fs.chmodSync(F,M),o.fs.utimesSync(F,P.header.time,P.header.time)}catch{T(D("Unable to create folder",F))}}C.reverse().reduce(function(P,F){return function(M){if(M)P(M);else{let Y=Se.normalize(d(F.entryName)),J=u(_,Y);F.getDataAsync(function(ie,Q){if(Q)P(Q);else if(!ie)P(Ie.Errors.CANT_EXTRACT_FILE());else{let ce=I?F.header.fileAttr:void 0;o.writeFileToAsync(J,ie,b,ce,function(le){le||P(D("Unable to write file",J)),o.fs.utimes(J,F.header.time,F.header.time,function(O){O?P(D("Unable to set times",J)):P()})})}})}}},T)()},writeZip:function(_,b){if(arguments.length===1&&typeof _=="function"&&(b=_,_=""),!_&&i.filename&&(_=i.filename),!!_){var I=c.compressToBuffer();if(I){var T=o.writeFileTo(_,I,!0);typeof b=="function"&&b(T?null:new Error("failed"),"")}}},writeZipPromise:function(_,b){let{overwrite:I,perm:T}=Object.assign({overwrite:!0},b);return new Promise((k,D)=>{!_&&i.filename&&(_=i.filename),_||D("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let C=P=>P?k(P):D("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(_,y,I,T,C)},D)})},toBufferPromise:function(){return new Promise((_,b)=>{c.toAsyncBuffer(_,b)})},toBuffer:function(_,b,I,T){return typeof _=="function"?(c.toAsyncBuffer(_,b,I,T),null):c.compressToBuffer()}}}});import{execFile as m_,spawn as w_,spawnSync as aA}from"node:child_process";import{promisify as __}from"node:util";function b_(t){if(process.platform!=="win32")return!1;if(Rf.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(Rf,"").toLowerCase();return y_.has(r)}function kf(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return b_(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function at(t,e=[],r={}){return w_(t,e,kf(t,r))}function Cf(t,e=[],r={}){return E_(t,e,kf(t,r))}var y_,Rf,E_,Yt=it(()=>{"use strict";y_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Rf=/\.(cmd|bat|ps1)$/i;E_=__(m_)});var Qt=ue((Uk,ah)=>{"use strict";var sh=["nodebuffer","arraybuffer","fragments"],oh=typeof Blob<"u";oh&&sh.push("blob");ah.exports={BINARY_TYPES:sh,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:oh,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var Vi=ue((Gk,ko)=>{"use strict";var{EMPTY_BUFFER:eE}=Qt(),dd=Buffer[Symbol.species];function tE(t,e){if(t.length===0)return eE;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 dd(r.buffer,r.byteOffset,i):r}function ch(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function dh(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function nE(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function ld(t){if(ld.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new dd(t):ArrayBuffer.isView(t)?e=new dd(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),ld.readOnly=!1),e}ko.exports={concat:tE,mask:ch,toArrayBuffer:nE,toBuffer:ld,unmask:dh};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=pe("bufferutil");ko.exports.mask=function(e,r,i,o,c){c<48?ch(e,r,i,o,c):t.mask(e,r,i,o,c)},ko.exports.unmask=function(e,r){e.length<32?dh(e,r):t.unmask(e,r)}}catch{}});var fh=ue((Hk,uh)=>{"use strict";var lh=Symbol("kDone"),ud=Symbol("kRun"),fd=class{constructor(e){this[lh]=()=>{this.pending--,this[ud]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[ud]()}[ud](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[lh])}}};uh.exports=fd});var Gr=ue((jk,gh)=>{"use strict";var Ji=pe("zlib"),hh=Vi(),rE=fh(),{kStatusCode:xh}=Qt(),iE=Buffer[Symbol.species],sE=Buffer.from([0,0,255,255]),Do=Symbol("permessage-deflate"),en=Symbol("total-length"),zr=Symbol("callback"),Dn=Symbol("buffers"),Ur=Symbol("error"),Co,hd=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,!Co){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Co=new rE(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[zr];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){Co.add(o=>{this._decompress(e,r,(c,d)=>{o(),i(c,d)})})}compress(e,r,i){Co.add(o=>{this._compress(e,r,(c,d)=>{o(),i(c,d)})})}_decompress(e,r,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,d=typeof this.params[c]!="number"?Ji.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Ji.createInflateRaw({...this._options.zlibInflateOptions,windowBits:d}),this._inflate[Do]=this,this._inflate[en]=0,this._inflate[Dn]=[],this._inflate.on("error",aE),this._inflate.on("data",ph)}this._inflate[zr]=i,this._inflate.write(e),r&&this._inflate.write(sE),this._inflate.flush(()=>{let c=this._inflate[Ur];if(c){this._inflate.close(),this._inflate=null,i(c);return}let d=hh.concat(this._inflate[Dn],this._inflate[en]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[en]=0,this._inflate[Dn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,d)})}_compress(e,r,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,d=typeof this.params[c]!="number"?Ji.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Ji.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:d}),this._deflate[en]=0,this._deflate[Dn]=[],this._deflate.on("data",oE)}this._deflate[zr]=i,this._deflate.write(e),this._deflate.flush(Ji.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=hh.concat(this._deflate[Dn],this._deflate[en]);r&&(c=new iE(c.buffer,c.byteOffset,c.length-4)),this._deflate[zr]=null,this._deflate[en]=0,this._deflate[Dn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};gh.exports=hd;function oE(t){this[Dn].push(t),this[en]+=t.length}function ph(t){if(this[en]+=t.length,this[Do]._maxPayload<1||this[en]<=this[Do]._maxPayload){this[Dn].push(t);return}this[Ur]=new RangeError("Max payload size exceeded"),this[Ur].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Ur][xh]=1009,this.removeListener("data",ph),this.reset()}function aE(t){if(this[Do]._inflate=null,this[Ur]){this[zr](this[Ur]);return}t[xh]=1007,this[zr](t)}});var Hr=ue((qk,Po)=>{"use strict";var{isUtf8:mh}=pe("buffer"),{hasBlob:cE}=Qt(),dE=[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 lE(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function xd(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 uE(t){return cE&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Po.exports={isBlob:uE,isValidStatusCode:lE,isValidUTF8:xd,tokenChars:dE};if(mh)Po.exports.isValidUTF8=function(t){return t.length<24?xd(t):mh(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=pe("utf-8-validate");Po.exports.isValidUTF8=function(e){return e.length<32?xd(e):t(e)}}catch{}});var _d=ue((Wk,Sh)=>{"use strict";var{Writable:fE}=pe("stream"),wh=Gr(),{BINARY_TYPES:hE,EMPTY_BUFFER:_h,kStatusCode:xE,kWebSocket:pE}=Qt(),{concat:pd,toArrayBuffer:gE,unmask:mE}=Vi(),{isValidStatusCode:wE,isValidUTF8:yh}=Hr(),Oo=Buffer[Symbol.species],pt=0,bh=1,Eh=2,vh=3,gd=4,md=5,Lo=6,wd=class extends fE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||hE[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=e.maxBufferedChunks|0,this._maxFragments=e.maxFragments|0,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[pE]=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=pt}_write(e,r,i){if(this._opcode===8&&this._state==pt)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 Oo(i.buffer,i.byteOffset+e,i.length-e),new Oo(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 Oo(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 pt:this.getInfo(e);break;case bh:this.getPayloadLength16(e);break;case Eh:this.getPayloadLength64(e);break;case vh:this.getMask();break;case gd:this.getData(e);break;case md:case Lo: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[wh.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=bh:this._payloadLength===127?this._state=Eh: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=vh:this._state=gd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=gd}getData(e){let r=_h;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&&mE(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=md,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[wh.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let d=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(d);return}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let d=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");r(d);return}this._fragments.push(c)}this.dataMessage(r),this._state===pt&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=pt;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=pd(i,r):this._binaryType==="arraybuffer"?o=gE(pd(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=pt):(this._state=Lo,setImmediate(()=>{this.emit("message",o,!0),this._state=pt,this.startLoop(e)}))}else{let o=pd(i,r);if(!this._skipUTF8Validation&&!yh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===md||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=pt):(this._state=Lo,setImmediate(()=>{this.emit("message",o,!1),this._state=pt,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,_h),this.end();else{let i=e.readUInt16BE(0);if(!wE(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Oo(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!yh(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=pt;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=pt):(this._state=Lo,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=pt,this.startLoop(r)}))}createError(e,r,i,o,c){this._loop=!1,this._errored=!0;let d=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(d,this.createError),d.code=c,d[xE]=o,d}};Sh.exports=wd});var Ed=ue(($k,Th)=>{"use strict";var{Duplex:Kk}=pe("stream"),{randomFillSync:_E}=pe("crypto"),{types:{isUint8Array:yE}}=pe("util"),Ih=Gr(),{EMPTY_BUFFER:bE,kWebSocket:EE,NOOP:vE}=Qt(),{isBlob:jr,isValidStatusCode:SE}=Hr(),{mask:Ah,toBuffer:Yn}=Vi(),gt=Symbol("kByteLength"),IE=Buffer.alloc(4),No=8*1024,Xn,qr=No,Rt=0,AE=1,TE=2,yd=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=Rt,this.onerror=vE,this[EE]=void 0}static frame(e,r){let i,o=!1,c=2,d=!1;r.mask&&(i=r.maskBuffer||IE,r.generateMask?r.generateMask(i):(qr===No&&(Xn===void 0&&(Xn=Buffer.alloc(No)),_E(Xn,0,No),qr=0),i[0]=Xn[qr++],i[1]=Xn[qr++],i[2]=Xn[qr++],i[3]=Xn[qr++]),d=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||d)&&r[gt]!==void 0?u=r[gt]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!d);let f=u;u>=65536?(c+=8,f=127):u>125&&(c+=2,f=126);let x=Buffer.allocUnsafe(o?u+c:c);return x[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(x[0]|=64),x[1]=f,f===126?x.writeUInt16BE(u,2):f===127&&(x[2]=x[3]=0,x.writeUIntBE(u,4,6)),r.mask?(x[1]|=128,x[c-4]=i[0],x[c-3]=i[1],x[c-2]=i[2],x[c-1]=i[3],d?[x,e]:o?(Ah(e,i,x,c,u),[x]):(Ah(e,i,e,0,u),[x,e])):[x,e]}close(e,r,i,o){let c;if(e===void 0)c=bE;else{if(typeof e!="number"||!SE(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(r);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");if(c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof r=="string")c.write(r,2);else if(yE(r))c.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let d={[gt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==Rt?this.enqueue([this.dispatch,c,!1,d,o]):this.sendFrame(t.frame(c,d),o)}ping(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):jr(e)?(o=e.size,c=!1):(e=Yn(e),o=e.length,c=Yn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[gt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};jr(e)?this._state!==Rt?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==Rt?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}pong(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):jr(e)?(o=e.size,c=!1):(e=Yn(e),o=e.length,c=Yn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[gt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};jr(e)?this._state!==Rt?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==Rt?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}send(e,r,i){let o=this._extensions[Ih.extensionName],c=r.binary?2:1,d=r.compress,u,f;typeof e=="string"?(u=Buffer.byteLength(e),f=!1):jr(e)?(u=e.size,f=!1):(e=Yn(e),u=e.length,f=Yn.readOnly),this._firstFragment?(this._firstFragment=!1,d&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(d=u>=o._threshold),this._compress=d):(d=!1,c=0),r.fin&&(this._firstFragment=!0);let x={[gt]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:f,rsv1:d};jr(e)?this._state!==Rt?this.enqueue([this.getBlobData,e,this._compress,x,i]):this.getBlobData(e,this._compress,x,i):this._state!==Rt?this.enqueue([this.dispatch,e,this._compress,x,i]):this.dispatch(e,this._compress,x,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[gt],this._state=TE,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(bd,this,u,o);return}this._bufferedBytes-=i[gt];let d=Yn(c);r?this.dispatch(d,r,i,o):(this._state=Rt,this.sendFrame(t.frame(d,i),o),this.dequeue())}).catch(c=>{process.nextTick(RE,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Ih.extensionName];this._bufferedBytes+=i[gt],this._state=AE,c.compress(e,i.fin,(d,u)=>{if(this._socket.destroyed){let f=new Error("The socket was closed while data was being compressed");bd(this,f,o);return}this._bufferedBytes-=i[gt],this._state=Rt,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===Rt&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][gt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][gt],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)}};Th.exports=yd;function bd(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 RE(t,e,r){bd(t,e,r),t.onerror(e)}});var Mh=ue((Vk,Nh)=>{"use strict";var{kForOnEventAttribute:Zi,kListener:vd}=Qt(),Rh=Symbol("kCode"),kh=Symbol("kData"),Ch=Symbol("kError"),Dh=Symbol("kMessage"),Ph=Symbol("kReason"),Wr=Symbol("kTarget"),Oh=Symbol("kType"),Lh=Symbol("kWasClean"),tn=class{constructor(e){this[Wr]=null,this[Oh]=e}get target(){return this[Wr]}get type(){return this[Oh]}};Object.defineProperty(tn.prototype,"target",{enumerable:!0});Object.defineProperty(tn.prototype,"type",{enumerable:!0});var Qn=class extends tn{constructor(e,r={}){super(e),this[Rh]=r.code===void 0?0:r.code,this[Ph]=r.reason===void 0?"":r.reason,this[Lh]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Rh]}get reason(){return this[Ph]}get wasClean(){return this[Lh]}};Object.defineProperty(Qn.prototype,"code",{enumerable:!0});Object.defineProperty(Qn.prototype,"reason",{enumerable:!0});Object.defineProperty(Qn.prototype,"wasClean",{enumerable:!0});var Kr=class extends tn{constructor(e,r={}){super(e),this[Ch]=r.error===void 0?null:r.error,this[Dh]=r.message===void 0?"":r.message}get error(){return this[Ch]}get message(){return this[Dh]}};Object.defineProperty(Kr.prototype,"error",{enumerable:!0});Object.defineProperty(Kr.prototype,"message",{enumerable:!0});var Yi=class extends tn{constructor(e,r={}){super(e),this[kh]=r.data===void 0?null:r.data}get data(){return this[kh]}};Object.defineProperty(Yi.prototype,"data",{enumerable:!0});var kE={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Zi]&&o[vd]===e&&!o[Zi])return;let i;if(t==="message")i=function(c,d){let u=new Yi("message",{data:d?c:c.toString()});u[Wr]=this,Mo(e,this,u)};else if(t==="close")i=function(c,d){let u=new Qn("close",{code:c,reason:d.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Wr]=this,Mo(e,this,u)};else if(t==="error")i=function(c){let d=new Kr("error",{error:c,message:c.message});d[Wr]=this,Mo(e,this,d)};else if(t==="open")i=function(){let c=new tn("open");c[Wr]=this,Mo(e,this,c)};else return;i[Zi]=!!r[Zi],i[vd]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[vd]===e&&!r[Zi]){this.removeListener(t,r);break}}};Nh.exports={CloseEvent:Qn,ErrorEvent:Kr,Event:tn,EventTarget:kE,MessageEvent:Yi};function Mo(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Bo=ue((Jk,Bh)=>{"use strict";var{tokenChars:Xi}=Hr();function Ut(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function CE(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,d,u,f=-1,x=-1,g=-1,w=0;for(;w<t.length;w++)if(x=t.charCodeAt(w),d===void 0)if(g===-1&&Xi[x]===1)f===-1&&(f=w);else if(w!==0&&(x===32||x===9))g===-1&&f!==-1&&(g=w);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w);let _=t.slice(f,g);x===44?(Ut(e,_,r),r=Object.create(null)):d=_,f=g=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);else if(u===void 0)if(g===-1&&Xi[x]===1)f===-1&&(f=w);else if(x===32||x===9)g===-1&&f!==-1&&(g=w);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w),Ut(r,t.slice(f,g),!0),x===44&&(Ut(e,d,r),r=Object.create(null),d=void 0),f=g=-1}else if(x===61&&f!==-1&&g===-1)u=t.slice(f,w),f=g=-1;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(o){if(Xi[x]!==1)throw new SyntaxError(`Unexpected character at index ${w}`);f===-1?f=w:i||(i=!0),o=!1}else if(c)if(Xi[x]===1)f===-1&&(f=w);else if(x===34&&f!==-1)c=!1,g=w;else if(x===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(x===34&&t.charCodeAt(w-1)===61)c=!0;else if(g===-1&&Xi[x]===1)f===-1&&(f=w);else if(f!==-1&&(x===32||x===9))g===-1&&(g=w);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w);let _=t.slice(f,g);i&&(_=_.replace(/\\/g,""),i=!1),Ut(r,u,_),x===44&&(Ut(e,d,r),r=Object.create(null),d=void 0),u=void 0,f=g=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);if(f===-1||c||x===32||x===9)throw new SyntaxError("Unexpected end of input");g===-1&&(g=w);let S=t.slice(f,g);return d===void 0?Ut(e,S,r):(u===void 0?Ut(r,S,!0):i?Ut(r,u,S.replace(/\\/g,"")):Ut(r,u,S),Ut(e,d,r)),e}function DE(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(i=>[e].concat(Object.keys(i).map(o=>{let c=i[o];return Array.isArray(c)||(c=[c]),c.map(d=>d===!0?o:`${o}=${d}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Bh.exports={format:DE,parse:CE}});var Go=ue((Xk,Jh)=>{"use strict";var PE=pe("events"),OE=pe("https"),LE=pe("http"),Uh=pe("net"),NE=pe("tls"),{randomBytes:ME,createHash:BE}=pe("crypto"),{Duplex:Zk,Readable:Yk}=pe("stream"),{URL:Sd}=pe("url"),Pn=Gr(),FE=_d(),zE=Ed(),{isBlob:UE}=Hr(),{BINARY_TYPES:Fh,CLOSE_TIMEOUT:GE,EMPTY_BUFFER:Fo,GUID:HE,kForOnEventAttribute:Id,kListener:jE,kStatusCode:qE,kWebSocket:Ke,NOOP:Gh}=Qt(),{EventTarget:{addEventListener:WE,removeEventListener:KE}}=Mh(),{format:$E,parse:VE}=Bo(),{toBuffer:JE}=Vi(),Hh=Symbol("kAborted"),Ad=[8,13],nn=["CONNECTING","OPEN","CLOSING","CLOSED"],ZE=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,be=class t extends PE{constructor(e,r,i){super(),this._binaryType=Fh[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Fo,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]),jh(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Fh.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 FE({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 zE(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[Ke]=this,c[Ke]=this,e[Ke]=this,o.on("conclude",QE),o.on("drain",ev),o.on("error",tv),o.on("message",nv),o.on("ping",rv),o.on("pong",iv),c.onerror=sv,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Kh),e.on("data",Uo),e.on("end",$h),e.on("error",Vh),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[Pn.extensionName]&&this._extensions[Pn.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){ut(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())}),Wh(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){Td(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Fo,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){Td(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Fo,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){Td(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[Pn.extensionName]||(o.compress=!1),this._sender.send(e||Fo,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){ut(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(be,"CONNECTING",{enumerable:!0,value:nn.indexOf("CONNECTING")});Object.defineProperty(be.prototype,"CONNECTING",{enumerable:!0,value:nn.indexOf("CONNECTING")});Object.defineProperty(be,"OPEN",{enumerable:!0,value:nn.indexOf("OPEN")});Object.defineProperty(be.prototype,"OPEN",{enumerable:!0,value:nn.indexOf("OPEN")});Object.defineProperty(be,"CLOSING",{enumerable:!0,value:nn.indexOf("CLOSING")});Object.defineProperty(be.prototype,"CLOSING",{enumerable:!0,value:nn.indexOf("CLOSING")});Object.defineProperty(be,"CLOSED",{enumerable:!0,value:nn.indexOf("CLOSED")});Object.defineProperty(be.prototype,"CLOSED",{enumerable:!0,value:nn.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(be.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(be.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Id])return e[jE];return null},set(e){for(let r of this.listeners(t))if(r[Id]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[Id]:!0})}})});be.prototype.addEventListener=WE;be.prototype.removeEventListener=KE;Jh.exports=be;function jh(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:GE,protocolVersion:Ad[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,!Ad.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Ad.join(", ")})`);let c;if(e instanceof Sd)c=e;else try{c=new Sd(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let d=c.protocol==="wss:",u=c.protocol==="ws+unix:",f;if(c.protocol!=="ws:"&&!d&&!u?f=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?f="The URL's pathname is empty":c.hash&&(f="The URL contains a fragment identifier"),f){let I=new SyntaxError(f);if(t._redirects===0)throw I;zo(t,I);return}let x=d?443:80,g=ME(16).toString("base64"),w=d?OE.request:LE.request,S=new Set,_;if(o.createConnection=o.createConnection||(d?XE:YE),o.defaultPort=o.defaultPort||x,o.port=c.port||x,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":g,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(_=new Pn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=$E({[Pn.extensionName]:_.offer()})),r.length){for(let I of r){if(typeof I!="string"||!ZE.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}`),u){let I=o.path.split(":");o.socketPath=I[0],o.path=I[1]}let b;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=d,t._originalHostOrSocketPath=u?o.socketPath:c.host;let I=i&&i.headers;if(i={...i,headers:{}},I)for(let[T,k]of Object.entries(I))i.headers[T.toLowerCase()]=k}else if(t.listenerCount("redirect")===0){let I=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!I||t._originalSecure&&!d)&&(delete o.headers.authorization,delete o.headers.cookie,I||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),b=t._req=w(o),t._redirects&&t.emit("redirect",t.url,b)}else b=t._req=w(o);o.timeout&&b.on("timeout",()=>{ut(t,b,"Opening handshake has timed out")}),b.on("error",I=>{b===null||b[Hh]||(b=t._req=null,zo(t,I))}),b.on("response",I=>{let T=I.headers.location,k=I.statusCode;if(T&&o.followRedirects&&k>=300&&k<400){if(++t._redirects>o.maxRedirects){ut(t,b,"Maximum redirects exceeded");return}b.abort();let D;try{D=new Sd(T,e)}catch{let C=new SyntaxError(`Invalid URL: ${T}`);zo(t,C);return}jh(t,D,r,i)}else t.emit("unexpected-response",b,I)||ut(t,b,`Unexpected server response: ${I.statusCode}`)}),b.on("upgrade",(I,T,k)=>{if(t.emit("upgrade",I),t.readyState!==be.CONNECTING)return;b=t._req=null;let D=I.headers.upgrade;if(D===void 0||D.toLowerCase()!=="websocket"){ut(t,T,"Invalid Upgrade header");return}let y=BE("sha1").update(g+HE).digest("base64");if(I.headers["sec-websocket-accept"]!==y){ut(t,T,"Invalid Sec-WebSocket-Accept header");return}let C=I.headers["sec-websocket-protocol"],P;if(C!==void 0?S.size?S.has(C)||(P="Server sent an invalid subprotocol"):P="Server sent a subprotocol but none was requested":S.size&&(P="Server sent no subprotocol"),P){ut(t,T,P);return}C&&(t._protocol=C);let F=I.headers["sec-websocket-extensions"];if(F!==void 0){if(!_){ut(t,T,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let M;try{M=VE(F)}catch{ut(t,T,"Invalid Sec-WebSocket-Extensions header");return}let Y=Object.keys(M);if(Y.length!==1||Y[0]!==Pn.extensionName){ut(t,T,"Server indicated an extension that was not requested");return}try{_.accept(M[Pn.extensionName])}catch{ut(t,T,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[Pn.extensionName]=_}t.setSocket(T,k,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(b,t):b.end()}function zo(t,e){t._readyState=be.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function YE(t){return t.path=t.socketPath,Uh.connect(t)}function XE(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Uh.isIP(t.host)?"":t.host),NE.connect(t)}function ut(t,e,r){t._readyState=be.CLOSING;let i=new Error(r);Error.captureStackTrace(i,ut),e.setHeader?(e[Hh]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(zo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Td(t,e,r){if(e){let i=UE(e)?e.size:JE(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${nn[t.readyState]})`);process.nextTick(r,i)}}function QE(t,e){let r=this[Ke];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Ke]!==void 0&&(r._socket.removeListener("data",Uo),process.nextTick(qh,r._socket),t===1005?r.close():r.close(t,e))}function ev(){let t=this[Ke];t.isPaused||t._socket.resume()}function tv(t){let e=this[Ke];e._socket[Ke]!==void 0&&(e._socket.removeListener("data",Uo),process.nextTick(qh,e._socket),e.close(t[qE])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function zh(){this[Ke].emitClose()}function nv(t,e){this[Ke].emit("message",t,e)}function rv(t){let e=this[Ke];e._autoPong&&e.pong(t,!this._isServer,Gh),e.emit("ping",t)}function iv(t){this[Ke].emit("pong",t)}function qh(t){t.resume()}function sv(t){let e=this[Ke];e.readyState!==be.CLOSED&&(e.readyState===be.OPEN&&(e._readyState=be.CLOSING,Wh(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Wh(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Kh(){let t=this[Ke];if(this.removeListener("close",Kh),this.removeListener("data",Uo),this.removeListener("end",$h),t._readyState=be.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[Ke]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",zh),t._receiver.on("finish",zh))}function Uo(t){this[Ke]._receiver.write(t)||this.pause()}function $h(){let t=this[Ke];t._readyState=be.CLOSING,t._receiver.end(),this.end()}function Vh(){let t=this[Ke];this.removeListener("error",Vh),this.on("error",Gh),t&&(t._readyState=be.CLOSING,this.destroy())}});var Qh=ue((eC,Xh)=>{"use strict";var Qk=Go(),{Duplex:ov}=pe("stream");function Zh(t){t.emit("close")}function av(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Yh(t){this.removeListener("error",Yh),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function cv(t,e){let r=!0,i=new ov({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,d){let u=!d&&i._readableState.objectMode?c.toString():c;i.push(u)||t.pause()}),t.once("error",function(c){i.destroyed||(r=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick(Zh,i);return}let d=!1;t.once("error",function(f){d=!0,c(f)}),t.once("close",function(){d||c(o),process.nextTick(Zh,i)}),r&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,d){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,d)});return}t.send(o,d)},i.on("end",av),i.on("error",Yh),i}Xh.exports=cv});var Rd=ue((tC,ex)=>{"use strict";var{tokenChars:dv}=Hr();function lv(t){let e=new Set,r=-1,i=-1,o=0;for(o;o<t.length;o++){let d=t.charCodeAt(o);if(i===-1&&dv[d]===1)r===-1&&(r=o);else if(o!==0&&(d===32||d===9))i===-1&&r!==-1&&(i=o);else if(d===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let u=t.slice(r,i);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);e.add(u),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(r,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}ex.exports={parse:lv}});var ax=ue((rC,ox)=>{"use strict";var uv=pe("events"),Ho=pe("http"),{Duplex:nC}=pe("stream"),{createHash:fv}=pe("crypto"),tx=Bo(),er=Gr(),hv=Rd(),xv=Go(),{CLOSE_TIMEOUT:pv,GUID:gv,kWebSocket:mv}=Qt(),wv=/^[+/0-9A-Za-z]{22}==$/,nx=0,rx=1,sx=2,kd=class extends uv{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:pv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:xv,...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=Ho.createServer((i,o)=>{let c=Ho.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=_v(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(o,c,d)=>{this.handleUpgrade(o,c,d,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=nx}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===sx){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Qi,this);return}if(e&&this.once("close",e),this._state!==rx)if(this._state=rx,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(Qi,this):process.nextTick(Qi,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{Qi(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,o){r.on("error",ix);let c=e.headers["sec-websocket-key"],d=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){tr(this,e,r,405,"Invalid HTTP method");return}if(d===void 0||d.toLowerCase()!=="websocket"){tr(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!wv.test(c)){tr(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){tr(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){es(r,400);return}let f=e.headers["sec-websocket-protocol"],x=new Set;if(f!==void 0)try{x=hv.parse(f)}catch{tr(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let g=e.headers["sec-websocket-extensions"],w={};if(this.options.perMessageDeflate&&g!==void 0){let S=new er({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let _=tx.parse(g);_[er.extensionName]&&(S.accept(_[er.extensionName]),w[er.extensionName]=S)}catch{tr(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let S={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(S,(_,b,I,T)=>{if(!_)return es(r,b||401,I,T);this.completeUpgrade(w,c,x,e,r,i,o)});return}if(!this.options.verifyClient(S))return es(r,401)}this.completeUpgrade(w,c,x,e,r,i,o)}completeUpgrade(e,r,i,o,c,d,u){if(!c.readable||!c.writable)return c.destroy();if(c[mv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>nx)return es(c,503);let x=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${fv("sha1").update(r+gv).digest("base64")}`],g=new this.options.WebSocket(null,void 0,this.options);if(i.size){let w=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;w&&(x.push(`Sec-WebSocket-Protocol: ${w}`),g._protocol=w)}if(e[er.extensionName]){let w=e[er.extensionName].params,S=tx.format({[er.extensionName]:[w]});x.push(`Sec-WebSocket-Extensions: ${S}`),g._extensions=e}this.emit("headers",x,o),c.write(x.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",ix),g.setSocket(c,d,{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(g),g.on("close",()=>{this.clients.delete(g),this._shouldEmitClose&&!this.clients.size&&process.nextTick(Qi,this)})),u(g,o)}};ox.exports=kd;function _v(t,e){for(let r of Object.keys(e))t.on(r,e[r]);return function(){for(let i of Object.keys(e))t.removeListener(i,e[i])}}function Qi(t){t._state=sx,t.emit("close")}function ix(){this.destroy()}function es(t,e,r,i){r=r||Ho.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} ${Ho.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 tr(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let d=new Error(o);Error.captureStackTrace(d,tr),t.emit("wsClientError",d,r,e)}else es(r,i,o,c)}});var bx=ue(Ne=>{"use strict";function Ko(){let t=["Ahr6t0W","B09huvm","v0HMrgu","vwP4zuK","ter5zLm","x2LUDgvYDMe","uLHcswO","D24GCMvHC28","yuTpzgK","B25VCgvU","C3rVCMu","AxnbCNjHEq","r3Les2u","wLzJzxK","y3jLyxrLt3a","tLPIB3m","x2DLDeLUDgu","uM9YAwG","BMv3vMvYC2K","CMvXDwLYzwq","Dg9hzw5LCMe","wMnNDKm","zNvUy3rPB24","u2PUrM0","x2rYB3bhBg8","tLvewNi","vw5Oyw5KBgu","Bwf4uMv0CMK","AgXSwLi","rxfUA24","BeXXz2K","Bw1ZrwK","zKHPwgy","Cgf5Bg9Hza","wM9uA24","yNrwEMm","DcbVzIbYyw4","Dg9Y","DNb0Cha","twX1Eeu","zcWG","CwDivMu","x29Ut3bLBG","y3vYCMvUDeu","y21jr0C","C09JsgW","BgTIuKC","tuvtu0fhrv8","Eu51CNO","y29SBM8","AvbprLC","y2HLy2TdDxi","t1Hmthu","B1rLvgq","x2XPC3rLBMu","rMveyxK","BuPVyvC","EwXnvLq","su5tvefova","CgLUz0XVC3m","AgLNAa","CMLLC0nVDw4","EfvZzuvUDG","x3DZ","x2nYzwf0zvm","AwXLx25HBwu","DKPWCMG","vwT6y2q","yxnL","sMHnv0u","C3vJy2vZCW","Aw5KzxG","CNzHBa","rw5Ztfu","Du5PtuS","AhfQt1y","vwfREMi","BMCGB3iGyw4","uNjyAxi","uxzqCM8","wxzxz3m","B0XTv2i","v2n2Cvy","DfrMy0K","B3bLBG","BMvY","AePcsuy","CYbWyxjHBxm","D2LSBfjLy28","ihjLy29UBMu","CMvUDevUzha","y0Tere4","tLLYChm","Dg9oDw1Izxi","yKDguLy","tufyx1jfvfi","uMvJB25Uzwm","zgvSzxrLrge","wLjRDee","v3zzq3C","yM9KEq","y3vYDMfSDwu","v2TwAfK","Avrcz00","AfzhCui","tuTMtfO","Dw50","t2vXEKm","AKH3quu","ywXS","BMCGDxjSoIa","tg9MEva","q1zvyMK","ExHxCwm","yMfJA3vWigu","qwjRzeG","CgXmu1O","Cg93","z2vjBMzVu3K","rfPyzfa","Cen2ywK","rMrTAxu","DxrVuMvJB24","rvDeBg0","z0jhyvK","t09Kve0","wgXwt0W","rKLYAui","qMruzuK","y29UBMvJDeu","y2XVC2veqG","t1bftL9fuLi","rgvWuxq","uuruBei","u2fxy3O","BMDuAw1LCG","Aw5ou0G","u0PiBxO","CMvQzwn0","DuPJu1O","zwvKzwq","AgvKtwf4uMu","t3v1rwG","B2LUs3K","mxWZFdb8nhW","x0rctMfTzq","C2HPzNq","yNnUrNC","id4G","CuPpqMq","zxjFCw9Zx2e","Dxr6qKW","CMPutgm","Cgf5Bg9Hzeu","BIWGAg9ZDg4","x3vYBa","BwvZ","surqBfG","vuz5z0G","Dhzwt3C","BfnHr0O","Axnby2TdBgu","BM5qrha","B25tDg9Wsw0","zKTovLO","CKf1Aei","wuvAu2W","zxHWB3j0CW","v0zJCfq","uLjotNm","yuDjzvm","vezpteq","rvrrugq","Aw9nugO","uK93uLe","zuLLtLG","qNLVAhG","D3vwruK","t2LYtMO","D1zHyve","zNjVBuHHC2G","ywzL","Bhb1zMK","v3rRtu8","Dxrjza","wgz5B1m","ign1CNnVCIa","t1bftG","sKDst2q","x3bPBMDqB24","x2LUAxrhBg8","rwTOBfy","wLfdq04","mNWX","EgPLrKi","Dg9iyxnO","zMzvveW","qNbRtMe","yLDXrfe","DMvYC2LVBMm","B25nzxnZywC","B1DPy2q","B25LCNjVCG","q3vZDg9Trxi","zgv2AwnLx2K","Dgv4DfbHEwW","tentD0S","qxvLCKK","rKfVA2K","BNHete4","zxq9DxrMltG","ALbSvNm","EgXTDLK","DhvAvNG","BMPoEg8","tw14CKW","igfYCMf5yNu","Bwnqswm","DhLWzq","CMP2t2W","CMvZzxrfBMq","s1bkv0y","x3bYzwzPEa","igzPzwXKoIa","ywX3yxLZ","AwXK","A2v0ignVBNm","CMvHzhLtDge","y3j1vxa","s2HIANO","Chv0","EKTytgm","sePQvMW","DxjS","AeryD2O","zLnQww4","AgftqMO","zw5HyMXLuw8","yxbWBgLJyxq","BeTHyvC","DgvlqK4","yxGGCMv0CMK","B2XKvMvYC2K","u3rYyxrLz3K","sLnptLa","wvjHCwS","x2rPC3bHDgm","y2vZC0HHBMq","sKPNv1a","BM5ZBhu","Cg9W","ANrlC28","B0zivLa","uhHsvKW","AxvJzwC","sg1rD3a","vwzywhy","zwn0","x3bYB3rVy28","BgvY","Aw5N","s0vMzKO","mZKZmJa4rKniz3DU","zMfjy1K","tLziEvy","BK53swK","vLjhzNO","B3vUDa","DNjUqwC","Defuvge","DxPnvhC","CuHsCMC","rfLHsvy","BLz5v0G","yNrmzgW","u2vXsuq","vunhtvO","y29UBMvJDfm","uNL5EMC","C0n1rvq","y2rRExC","zNjVDKW","ywDLrxzLBNq","BvbzvKi","n3W0Fdf8m3W","DMrTANm","yxnZAwDU","r0nYr2q","zuvWvLu","AM9PBG","zff2EMu","ihzHBgLKigq","BNniteG","BK1WBMu","lcbOB3n0BMe","q29UzMLN","svjLrgy","qLz4wei","yLP0s0e","ENHuEu8","zw50","sMH1u3y","C3rYAw5N","B2Puy2i","z2vrDwv1zuW","DgvmB2Djre4","y3jLyxrLt2i","EufJyMS","txnrswi","C2vUzf9Hy2S","ywr2yw5Jzq","ChjVDg9JB2W","CNjVCK1LC3m","CwrYrNm","s2Tutui","yxnYr2S","BM9Uzv9UB24","Aezywha","v1bMAfu","DK94uLC","wMHhBxa","tgLZDgvUzxi","zgvMAw5Luhi","z2v0qwXS","wKHQwve","uNH3y0e","CMvWBgfJzui","y2XLyxi","z2v0","BwvXDg4","DLn3EuS","ru96EgO","wwHUCwC","Ag9PyvO","Dev2zw50","A1bMsMi","sgzQrwi","ywXSzwqGBxu","wuf4CfO","ysbTDxn0igi","x1fVu01HBMe","DgHLBG","zhvgtxC","y3HmueK","BwvZC2fNzq","x3nLCuLK","EKnuDKW","y3vYC29YlNm","B3vvrg0","BxnKCxy","ihzHBgLKihm","yxbWBhK","BKXPBMu","y3vYCMvUDeK","C3jJ","yNHbq3O","zw5fDMvUDa","z1HwB3G","ELjqzLO","zNjVBuj5Dgu","CLrrvfC","x21LC3nHz2u","uLDqv3e","y2HnyxHdB3u","zNjVBunOyxi","CKT6BwO","AgvHzgvYCW","DgLTzw91DcW","BMfTzq","uuLIEgW","swPQChK","vMP4Cwu","vgfN","yxHpyLO","C2vYDMLJzq","wujPswO","vgLssNC","t0vxDhi","BgLbBfO","C2v0zgi","AvHkExK","BMvLzf9Hy2S","zKnIvgW","zenTt2m","B3nLrxzLBNq","zfjbu2q","tg9JAW","C2XPy2u","B2zMBgLUzq","r1rMs28","CMfTzq","thnMy3u","DK11te8","uw1jueC","q3rKv3m","y29UBMvJDca","ChvZAa","x3bPBMC","wxf4t0m","wK1Tvwu","quzwuNq","y09Wzw4","BwLZzq","v1jctMC","qKfytg8","s1HvC1q","B3jpBMXPBMu","wKnby0e","CM92AwrLige","v2fAsuW","CMvWBgfJzq","rKzswe4","BNrfBMrWB2K","AxnrB1nnzxm","DgLTzw91Da","q3fotMi","Efrurw52","CM92AwrLihy","tgT0ugq","zgf0yq","C2v0q3vYC28","uKTvqwO","zw5HyMXLvhi","wwvIueq","Dg9cExrLC0i","z01uA2K","veHSBMm","A2v5","zw1LBNq","BMrLEa","D3jPDgu","vwfvruK","zg9Uzq","vgjYsuS","q29Kzq","BfL4r3y","zw50zwqGDhK","zwj4sMW","BeHHBMrSzxi","A3zMDLe","rwDtB2y","AeL4sui","ChnXBw0","x2rLC3rYB3K","x2LZv29YA2u","CMvTB3zLq2G","C09nwLC","zw5KCg9PBNq","sKDXywq","surju3q","C3r5CMG","ufrYDxa","sMTgAKe","AfzmrNq","Ee5dyuO","C2v0y3vYC28","tg9NsurozxC","EKjQzxG","mtu4nZu0nZHMAwPywum","B3nwCfu","C2vUza","Cvrrse8","B25mAw5L","v0Drq28","ywDLu2HVDW","x2LZtwLUAvq","yM1yENm","t2DzyK0","te1uuMm","x2HHBMrSzu8","CNnVCKzPBgu","BNvTyMvY","nvrIqLbosW","Ae9Wzw5fDMu","BezSDxnO","yuvhCKS","BfzSBuK","B25szwnLAxy","rMT1AMi","Bwf4twvZC2e","txnbAwG","x2n1CNnVCK0","wK5xqvu","x3DHAxq","t0HREwe","BNrbBMrvCgq","uvvyqLa","r2vRrLO","s3jPD2y","D0jRv1e","A3ntBu0","CMvJzxzPzwq","yw92Dxu","EsbJBg9Zzwq","ywrKrxzLBNq","zxjFywnRx20","AxvMwfO","qw1VDw50","zxrxB3jRq2G","u2TPCcbWyxm","B2XsDvO","EKXNzfa","rhPTuwC","C1ztCNC","CNDnr0m","ExvNweO","tMTUyMS","D21kAem","Bwf4tg9ZC0m","DxnLCKLW","zw5XDwv1zq","AK1dvhy","rvffseO","sgDhEw4","DhjPzxmGCMu","s2D6rNe","Euv1y1K","zxfAAfm","BuP1Dhi","ENvLCuC","ywWGy3vYC28","DeLK","wgHWq1u","B0z5v2u","vwncz2q","BMCGzMfPBgu","sgTRz0m","v1D5zgO","uLfyCNC","ywXSq3vYC28","x29UugfNzu4","BhjdzxG","yMLUyxj5","B3jLtMfTzxm","nNWZFdf8n3W","BgLZDgvUtMu","C29YDa","Eu92A1O","A1vQugu","zeLnyu0","BwL4tw8","vxzvB3i","vMvpA00","t1rgweS","AKfsA2y","y1n0ueW","Eenms00","u2vRu3y","C1fPELa","zuX5wMW","y2zxyNi","wMP5u1y","v2rOzfi","mNWWFdr8mxW","x2jPBMfYEvq","Aw1JCMe","txjJwem","C1HLvem","wxvuzKC","vgnNAfy","y3jLyxrLq2W","wM1eAMy","yxbwr0C","CMvZDwX0","wgXsC1i","Bg9N","rM1yy1G","EeH4A3q","r25QA0i","B3bLBKrc","Aw1fChy","uNLLyu4","qLvQu2q","zNjHBwvuExa","A3DZEuG","z2v0q3vYC28","AhDfq2y","CM92AwrLigi","qLDOvxe","s2fICKK","CeLtuhG","s0HIyK8","ruLswvC","v2vIu29JA2u","u05Nzee","thPlEfu","ruXPr3K","zMLSDgvY","rKvJEM8","D2fZq2XLyw4","Dgv4Dc9WBge","x2n1CNnVCKy","sNHiEfm","qvfzvhO","ywDL","qLnJC2G","wLnYrfi","z2v0q3vYCMu","ENL6AKe","uxHvwKi","vNDtBeW","y29TCgXLDgu","C3bSAxq","mdaWma","zuvTvxu","Dhr3Awq","BMfpz1i","BgTsqNi","y2fSBa","ihrPBwvZ","z3Lsqui","yw1Lu3bHy2u","zgLZywjSzue","zfjeBeO","qKzMCwm","Ee1XCuO","Dw5KzwzPBMu","wMvtwwy","AxnAzxjV","x3bPBMDmB3m","C2fNzq","qwfZANO","DfDjuve","zNLwvue","Bwv0Ag9K","sffsCvC","y3vYC29Y","v0nxEuW","uLjpuG","uxvLDwu","sNPsqwG","rhHHse0","wg1yCLK","Cg9PBNrdB24","DhjHBNnHy3q","u05dBKq","y2f0yNG","BwvKAwf0zwW","wNPsq2y","uLnTBMq","x3DZsw5ZDge","q013yuy","y2HHCKnVzgu","vhHrrwy","Aw5JBhvKzxm","Ec1TC2CTCw8","CNzHBfzHBhu","vhP5EhK","AvPOwe4","rfb0wLG","EefqBwK","vwDHyNq","x3nLBMrby2S","B2zMC2v0","y29UC3rYDwm","CuDmuKi","nty2m0jvA0DyCa","B2zM","qvvsAKq","zKjXC2G","q1bVy0i","C3zvt2G","qNPNq1a","vhvVuLC","q3zmtwK","wNjbtNm","Dhjlre4","zxj2AwnL","u2HHCMvKv28","wNPst1G","CgLUz0LUDgu","ywXSB2nvBNm","u05bwMq","x3fVC0rc","EfjNwfG","uNPJvuu","qKzrzNO","Aw5KzxHpzG","A3LJuLC","BMvssfi","CMvTB3zLrxy","BeTrBgq","y29Kzq","BgLUzq","DeLsDuu","BgvUz3rO","A0DfCNu","B3jRig9MzMW","yNL0zuXLBMC","mtu4mZqZnKTvvuf1wa","AePUvMG","sM5ozKu","zgf5r0W","ENrVCxK","r3Lyrhq","z2u6ia","zNPprKG","zgvJB2rLzey","aaaaaaaaaaa","ywrKq291BNq","B25Uzwn0Aw4","v2LJt00","weTMDMG","BgT2Beq","EhvYCfG","x25HDMLNyxq","n3W2Fdv8ohW","B1zir2y","q1z6y1e","EwDJseK","rvfft1G","zfrSAwW","C3juv2y","ren6tuq","Dg9tDhjPBMC","zwnVBM5Ly3q","Dg9cExrLCW","AxmGDw5Kzwy","wuvXs3y","uwLHBMe","C2v0","q0nJtfq","CNbVqLO","Dw5ZAwDUzwq","Aw50zwDLCIa","t3z1Bfa","zNjVBujPDhm","twPmy0G","y2XVC2u","u1b2uNm","sNbQAwy","DvHsyKG","tKHpEMq","v25wuLO","vfDqy2G","ihrPBwvVDxq","CgfYC2u","AxnszwfKEq","zNjVBNrPzxi","D2vI","DuXtuge","DhbizwfKzxi","v3HzuKG","EKrUs3K","yKXSvLi","ENzMshi","CgfkAMG","vuzzr0G","C3DTC0e","wffpwuS","DfLxvKW","EwPYDLu","CK1KCKm","B3bLCNr5","Dg9mB3DLCKm","vKfcy3e","tLbRyuq","zMzLCG","x2DLBMvYyxq","A2rAB04","DMfSDwvZ","BKPKs2m","EhDsvLO","EgLZCwy","zeLLywq","rxbMr2G","zMzmAw5L","x2LUAxrqCM8","zM9qEK8","BwHpt3i","AevYCM9Yrxy","DfvAyMO","z29PBMCGyxC","x0vysvnu","AxjLza","s3HVBKC","DvjcBxe","B21bB3u","Agf1uwy","teLOqMm","x29WDgLVBNm","x29Uq2XVC2u","CMvZB2X2zq","sxPrrMe","BMnVzgLUzW","s3ros1G","x2n1CNnVCK4","svnItwe","zuLSvM4","CMvHzhDYAxq","C2j4Aue","Ag9Auey","q09otKvdveK","C3nHz2vfDMu","ChnPrLi","C3rHCNq","zxmGCMvHy2G","CfrcyxG","zvbitgG","v3fuy0y","DgHHBIbSB2m","Bg9IywXty28","DKHnyKu","y2f0y2G","AhviyxK","s3LYAeC","suP1CKC","sKD4DLK","nNWWFdv8mG","x2rItMfTzq","vfjJqvK","zwPMz2O","x2nSzwfYugK","rgnfC3G","y0fAyNq","vgTHvxi","rxzLBNq","mhW1Fdn8nhW","wKTqweG","Bfjqzeq","uxDUC2e","EvLdDLu","uePYDvG","BujwEhK","DfHTCfq","ywTsCfG","AgPVAe0","mhW0Fdn8mxW","tMfTzq","vuHtthK","CgXLyxnLiha","sfz5Cem","BLPVz08","tg9Nsuq","teLhsu4","tfjYt2K","AMXPv1m","CMDlDK8","twTmAwq","B1jQq3y","twDTDKS","Aw9Ul2PZB24","yw5Nzq","tKHMEue","y3ruAw1LB3u","CMzbDwW","txjdwgy","C3rLBMvYCW","B25dBg9Zzq","DeLUDgvYy2u","qwL2BM0","te9urMG","q0LesuO","AxnrB1nby2S","vNbsAfO","qwHnCuW","BNruCMLLC0m","qKzHzMW","C2v0sxrLBq","zuXzuxK","B2THD2m","ywLqwfa","C0ndzNa","ze5xqNO","z2vtEw5J","zhPrvha","q09oveLovuu","AenSB3nLrxy","EMDkANm","zxjFDhrS","BMnLq2XVC2u","wuLQAKq","ENnQBgi","sMvTCwe","t0vpzvq","yLvVzhi","suvtx0vsuK8","BfzgwKC","tKfusvzfx0u","zxjFCw9Z","tw9Suxm","CNnVCL9Uyw0","zv9ZDwnJzxm","sLrHChm","u2Lbt1y","zMPhEMG","vw5nuuO","ntG3ntG4u2PMtwfK","DcbSAw1PDa","CfrNwvG","AxnmB25N","x2HHBMrSzva","y3rcALa","yNvMzMvYzwq","yMP0B3C","vhjcvva","ufHYrhi","thbuyuK","igzHAwWSig0","y29UBMvJDgK","AgfZt3DUuhi","DMfS","zxjYB3i","DeL3DMu","vfztzKy","wvDHwem","CMrYu3O","sK1Lvwe","CM92AwrLihC","tenms3G","B25tDgfYDfi","Ce5qtxq","Awrgy24","zw5JB2rPBMC","sLLvwwC","wgvVvwG","ALn0D3m","vuP4u1m","zxfyrLC","q3LVq3K","Chnds2S","tKDFrvjst1i","Ae1LC3nHz2u","qu1Xrei","A0TuD2O","uxHzDM4","zLDvEfq","yuzYzxK","tvnru1e","z05qwvm","uhvVzg0","uM5kvMG","B01Vz1u","CeDxAK4","r3bSsxi","x29UrxjYB3i","ANrdEKG","qNvYyxu","DhjPBq","BxP2vwG","CgLUz1rPBwu","tvLOEgK","z2rwyKO","Dg9VigXHCMC","uuLHCxG","mhWX","BffKBLi","rhjAq0G","s3Dzt0m","uuHdyNu","r3fLzfe","yxKSig5LDhC","wfDPBha","uLzNsuG","C3vIC3rYAw4","vwvSC3u","rvjst1i","wvfYtwS","v2vPEgLUsLm","CMLJv0C","q3ftz1m","yxv0BW","uhnNAgm","txz1B3y","BgTpweC","D3LWChy","Eg10Bgy","y29Uy2f0","x2LUAxq","y3vYC29Yx24","vKDLvKG","Aw47y2HHCNm","CMvHzg9UBhK","ywnRDxbfBMq","zMXVB3i","BfHqwge","ALbgqKu","A0LeEgG","AgvHzgvY","wu9jrMe","Dvrnq2K","AfPcswC","uhjPBwfYEuS","EwfyB3C","u1fbDgC","uuvmCge","vKfZuxK","ANjrBeG","AhLUzeK","rxjYqM8","B2nRzxq","uvD2uu8","Bg9NsurozxC","Bg9Nsurhzw4","teLxqNu","whLUBwS","jMPZy2fSBgi","CMvZzxrdB3u","C3rYAw5NAwy","uwLXq1O","yxbWzw5Kq2G","zvvYBa","yw5Hz2vY","B2fK","z2ngsMi","AMnSq1i","CKHpzfu","rMryAei","sMXrzeK","C0nVDw50zxi","Bfjwu3K","x3nVy2TLDa","y3HsEvu","ENjNuui","q0Xpu0LorW","B2nRzxrtDwm","zw5NDgG","uwrnwMO","ywnRx2LK","zwrPyxrLBhK","BezwA1a","vu1pD20","C2jZAgC","tMTnrg0","BML0AwfSAxO","sMvSww4","t2fmDwO","zMTfvfq","rwjOyKi","CgvUB20","Cezlt2K","txv0DfK","yNH6vMS","rKLmrv9ot1q","svPnsfO","zgrLD3C","Aw9U","C1j5Evi","tKDly3K","r2nvwxm","C0jNrNe","ugDPugu","yNL0zu9MzNm","wfHOyuG","rhj5D0i","B2nRzxrgywK","uwPXsKu","Ahrdve0","ELfqteq","x2nSzwfYvgK","uM9PsvG","CgrtEva","AhnqD1y","EhPtsxG","lcbTyxGGCMu","uNjbEKW","BwLUAvbYB2C","wefcB2O","yuTswMC","AxnFywnR","we5btNm","CMvKDwnL","CMPWqu8","BMrWB2LUDca","Aw5L","r2vlBKe","swTHExi","A1n0yxr1C0m","B25pCgvU","wg1fDNG","yNvMzMvY","z1nkue8","Bwj5Cfe","s0vmzNy","z2v0sxrLBq","A01Mwge","lcbxzwjtB2m","CM9YrxzLBNq","Cg9PBNrbBMq","wxn1Euy","twLZC2LUzYa","DgvxwMC","v1PyzKq","t1DvEeW","DxbKyxrLq3u","B2jQzwn0u3q","vw9cDNO","BMrWB2LUDfq","DMfSDwu","sgnZB0q","shrcqNa","zMLUza","ihbYB3rVy28","uvLWv2C","rNjVBNrPzxi","yxnJCMLWDa","sgTuEvK","zxjFAxnFywm","Eezzrvy","zxf1ywXZ","AwXLtMfTzq","yw1L","uMHeufm","EwLqs1K","BfrPBwvVDxq","v2r4z3e","q0LxvwW","BwvZC2fNzv8","r0fKt1q","DKP3Bva","vM9pEwe","A3HtB2e","zvbnCLa","DhrREgG","CgfNzwHPzgu","yNHtDfa","qwTdAwC","v3LlDeO","D3jPDgvvAw4","B25JBg9Zzq","CxrmBg0","uu1JANe","BgLHs3C","zufJAW","CgLUz19VBMm","B3nLza","Cw9Zx18","s21Zsxa","CMfTugfYyw0","CMv0CNLdB3u","yuPOruC","A1DKsum","mNWXFdeW","q3DZrMu","zMzMzG","vwLktMO","B3jRzxjhBg8","rgXHDMy","C05gBNi","q2n3t0G","zhjmu1G","vM9kCxq","twTmqNq","uLf5Cvq","t3bLBKv2zw4","ChbL","zMLN","twvZC2fNzuu","twHVtKO","s3bksvi","y29UDgLUDwu","yMfSrxzLBNq","x2TLEvbHDgG","ze1dA2O","vg9WDwC","ywjVCNq","Dg9cExrLC0W","EvjLy29UBMu","x3jLy29UBMu","x194x21Zz18","AKDpCgS","wLvcCfy","wNjPshK","yuLWv3O","qK1erg8","vhHnEvO","tNP1tgS","tfrhs2y","ywnR","refgCxK","Eu1VDLe","EhDAC0W","y3DzAuq","yNPeChG","z0D3wfG","se9JvvO","DhDVCMTdAge","CMfUzg9T","BMDLza","u2Lswuq","BuHpy20","zw50tgLZDgu","x2nVBM5Ly3q","yLP6Ewm","tgPuAfK","BwfW","DgvZDa","y1vRzw0","z0j3rwK","BMv4DcGPigm","u05iALe","DhPLCwq","uMjMwhK","zNDZxZeUmc4","DuTbuNq","x2LZtwLUAvC","B3jL","zKLpBvG","Ef9MCM9UDgK","ExbL","ChrVCG","AKnMExy","tNDptgy","x21PBMLoyxy","ywnRx2nVzgu","y2vqCLm","y3jLyxrLrxi","vxbKyxrLq28","svjJEgi","y29UDgv4Da","suvRyLq","y2HLy2Tszwe","r3jLyuq","nxW4FdD8nNW","D3Dewum","zNjVBu51Bwi","AwrI","CMvHzfvjBNq","Aw5Lza","ugX6Dgy","ChjVDg90Exa","vMHpwNm","zxjYtxnN","zLvnwK8","x2rPC2nVBM4","y2XLyxjtDg8","whrrBgm","y3r4","CgfNzxnOB3C","Bwu6ia","o2nOyxjZzxq","veXqsu4","tMTTzwS","Bg93","uMvHzcbWyxm","B25ozxr3B3i","rwjhq1K","AKDxu0e","s2jyquW","B3bLBIa","x2rLyNvN","B25fCNjVCG","Aw9UvgLTzw8","zgneENO","nde0nJG2wuDiqK1p","B25TzxnZywC","BM93","B3vUvee","zgvIDwC","BxnN","qNjPzgDL","u1DcuLK","ignVzgu6ia","u2TIEuS","ywDLsgLKzq","refjsvK","BK1ZDLK","vKrJs2C","DMXREwO","x2HHBMrSzvi","zfvuzLi","A2zuBuO","CNnxy2C","sxb5vhO","z2v0qwXSs2u","vfjjru0","rxjYB3jdB2q","DMvUDa","CgvYC2LZDgu","D3nZoI8V","C2vUzeu","ugTczum","r3j0rMS","ExHQEgO","DuHAwxC","rwjWtMC","yMLUyxj5vhK","y3jLyxrLtwu","Ahr0Chm6","zhflrMG","CMvJB25Uzwm","qvDeuKe","q2vQr2u","CM9XCNK","BNrLCG","DMvYC2LVBG","vhruyNq","rMzNvKi","tNvHBuK","x2fKzfDZtgK","tKLZs2C","zv90Aw1LB3u","vLPqqKO","BMjnwwO","BwfUDwfSihi","twrcBw8","rLngseu","v2LUzg93","EuXfyxK","u3PRtfO","yxv0B21HDgK","swfptfe","vNzir0S","z2Hct2S","DgT1Evq","v0Ddz2O","mtKZnKnOr1rvrq","yLncsgu","DMvY","t2jQzwn0","tfrRwgO","zMnsz2K","ywXPzcb1CMW","q0PKzMe","vw5PBxbSzw0","BMvJDa","y3jLyxrLuMu","C0XPC3rLBMu","vMjLDgC","BeDIvhK","BfjPv2S","yxrLq291BNq","uvLvDuu","sxb3rw8","CKD5EhO","yvrkswy","zw1PDa","AfzZzvm","x2vUzhbVAw4","uNLrwNa","EhPYA0S","ANLAqui","x2LZsw5PDa","DhrQAMi","x2LZqNjVD3m","yxzpDeG","v09eu3y","BwvY","zw5JB2rLrNi","r3zdCgq","ru5Zvei","ywnOzwq","DxrMofDYAxq","yNH0re8","vhjPExy","C2v0u3rVCMe","DwDWC0O","tK9st1i","wgjezhm","z3zKD2W","C3vIyxjYyxK","q3vZDg9Tq2W","Dw5RBM93BIa","B2LUDfjLywm","s3nXquK","DNHuvNO","vhf5u04","zMLSzw5HBwu","DgfIyxnL","r2PWvfq","vwPPAxq","DgH3zMy","wfv2quu","ExHdsfi","r1fvC00","vNHmqw0","y21Prxi","pxv0zI04","Cgf5Bg9Hzfq","rLneAhC","q0vNyNq","Au5ND0q","CNjJuNC","yurlrMO","C1jUuMu","DgHhv0u","zM9YrwfJAa","tgTvwMO","yMrnqNu","zgvSzxrL","rvnov3e","DgfKtMi","y2XVC2uSihC","Dw5puM4","B3LXywO","mJmXnZuZnKnbs2jxDq","B1nNzKi","yvb6uMy","CMvHC29U","Dez5ww0","sLzrBKC","BMPwsMe","A0jkD2m","B3L6z0e","yMDmq1G","quDYy1G","uuzxEvy","BgLUzw5V","ELPYA00","yLj6Cfy","EML2sMC","nxWWFdj8nhW","BwvZC2fNztO","zM9Yy2u","A2vNA0i","rMnpq1q","BgLTAxq","vfnWAwy","DhjPzxm","CMvJzwL2zwq","CgjICdi","ALPcA3O","rxPizwG","q2j2CKG","A2v5CW","vgLTzw91Da","z1zLq0e","vxLdtfC","yw1LoIa","AgDvvgi","zu1zreW","yMXVy2TLza","BxnNsuq","AwDHDg9Yt24","vfLQsfi","x19LC01Vzhu","z2vY","tNnyt2K","wfbwvgm","BNLcAxy","u3LyugO","zgvS","zxH0zw5ZAw8","zNLSuxO","y291BNq","DfbLz04","BMvhzfu","Ec1TC2CTy3u","AgfZ","AefJA01LC3m","sK5hvgq","DgLUzYbZzxi","zw5HyMXLqxu","uvLKD3u","B0LqBuC","zvryqxG","vhn0BuC","De1HBMfNzxi","AK9TqMi","BNzuDg8","EhrTrem","zcWGDw5RBM8","x29UtwvZC2e","zxjHDg9Y","sK5JrKi","zxjYtM8","yMLUza","rKzjs08","AgfUz2u","txnPq2q","icSG","Cfreruy","uxbiEM4","txrsBeq","ExDICgK","CunsuKm","AuHrzLa","B2ryD00","Bfvivw8","z1rPBwvVDxq","q0Xpu0ve","tfj6A0q","ugT1zM0","qxr3D24","reLhBeq","wfnpvKe","C2vYDMvYvgK","z2v0u3rVCMe","ywrK","uLreBw8","vgHjwMO","x2zVCM1HDeu","CMTLCKDSB2i","sgHluhG","x3jLBw92zvC","n3W4Fdv8oxW","C2vUDa","yMzjA04","uLPdCLa","BuT6Au4","y2HnyxHuCMK","CenhuNC","rLLgvM8","AuL3sue","C0jf","yxKSihrYEsa","AgPiuhK","AwDSrKm","CKrXt0K","r2fSq0i","Cwr2s0G","BhPyD1C","zsbHihn0CMK","Aw1LCYbPBIa","DwTqEe8","ywnRtxnNswq","mdaWmdaWmda","Bxvrt2m","tuTWqw4","y2uGBM90igK","AffWrfi","B1zQqxu","BwXIChy","tfvLBfG","zMX1C2HfEha","BwHRree","CIb0DhDjra","z3DAse0","x3jLywr5q2W","CxzryMi","zw9Uugi","BM9cEhm","Eur4A2S","AuPjEge","uw1Puve","yNL0zxm","x3bHDgHlzxK","vwTzs2G","AhPXv0y","BxfgCwe"];return Ko=function(){return t},Ko()}var B=j;(function(t,e){let r=j,i=t();for(;;)try{if(-parseInt(r(806))/1+-parseInt(r(1163))/2+-parseInt(r(608))/3+-parseInt(r(181))/4*(-parseInt(r(391))/5)+parseInt(r(1304))/6+-parseInt(r(575))/7*(parseInt(r(1225))/8)+parseInt(r(377))/9===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(Ko,729979);var Tv=Object[B(241)+B(672)],Rv=Object["getOwnPropertyNa"+B(1605)],px=(t,e)=>function(){return t&&(e=(0,t[{GyDKe:function(c,d){return c(d)}}[B(1461)](Rv,t)[0]])(t=0)),e},kv=(t,e)=>{let r=B,i={WaZIL:function(c,d,u,f){return c(d,u,f)}};for(var o in e)i[r(328)](Tv,t,o,{get:e[o],enumerable:!0})};function Cv(){return lx||(lx=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Dv(){let t=B;return ux||(ux=[IDBCursor[t(1139)+"e"][t(229)],IDBCursor[t(1139)+"e"][t(1069)],IDBCursor.prototype[t(1069)+t(901)+"ey"]])}function Pv(t){let e=B,r={EbpNg:function(o,c){return o===c},BHskq:e(1698),Plztf:"success",sVSrw:"error",RhDPS:function(o,c){return o(c)},XlRsR:function(o){return o()},dePwK:function(o,c){return o===c},nyBiv:e(431),TvcHq:function(o){return o()},sRyyR:function(o,c){return o!==c},VZPBJ:e(1394),pNPMt:e(742),Pkufm:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let d=e,u={KbXAL:function(w,S){return r.dePwK(w,S)},TstmG:r[d(1348)],zgJjs:function(w,S){return w(S)},DzmQg:function(w){return r.TvcHq(w)}},f=()=>{let w=d;r[w(1194)]("nnslu",r.BHskq)?(t[w(599)+w(1100)+w(1534)](r.Plztf,x),t[w(599)+w(1100)+"ner"](r[w(422)],g)):this[w(930)]&&this[w(930)][w(647)]({code:_0xba4fa9,reason:_0x103fdb})},x=()=>{let w=d;u[w(1157)](u[w(1365)],u[w(1365)])?(u[w(787)](o,u[w(787)](Ht,t[w(482)])),u[w(421)](f)):_0x2fa0b7.log(_0x2a29d5)},g=()=>{let w=d;r[w(1021)](c,t.error),r[w(483)](f)};t[d(413)+d(240)](r[d(1138)],x),t["addEvent"+d(240)](r[d(422)],g)});return i[e(260)](o=>{let c=e;if(r[c(956)](r[c(1211)],r[c(830)]))r[c(1391)](o,IDBCursor)&&Dd.set(o,t);else{let d={uJcSZ:function(u,f){return u(f)}};return function(u,...f){let x=c,g=_0x5a65f7.call(d[x(1588)](_0x5dac94,this),u,...f);return _0x1f30bb[x(639)](g,u.sort?u[x(455)]():[u]),d[x(1588)](_0x1a55d5,g)}}})[e(722)](()=>{}),Vo.set(i,t),i}function Ov(t){let e=B,r={kFEfQ:function(o,c){return o>c},ErevU:function(o,c){return o+c},JAMys:function(o,c,d){return o(c,d)},bRzpV:function(o,c){return o===c},mJutr:e(882),SQAtg:e(821),dIMaM:function(o){return o()},XlVOL:"AbortError",HRRMI:e(605),fjGzh:e(1074)};if($o.has(t))return;let i=new Promise((o,c)=>{let d=e,u={PIRkO:function(f,x,g){return r.JAMys(f,x,g)},RnJVh:function(f,x){return f|x},ZUADH:function(f,x){return f&x},mhkDA:function(f,x){return r.bRzpV(f,x)},RoiIX:r[d(437)],QVNOK:d(520),UJxSS:r.SQAtg,eonPb:function(f){return r[d(458)](f)},XfyoS:function(f,x){return f(x)},dRASd:r[d(1575)]};if(r[d(1318)](r.HRRMI,d(605))){let f=()=>{let w=d;u[w(1434)](u[w(969)],u.RoiIX)?(t[w(599)+"entListener"](u.QVNOK,x),t["removeEv"+w(1100)+w(1534)](u[w(836)],g),t["removeEv"+w(1100)+w(1534)](w(1074),g)):(u.PIRkO(_0x4f0a56,_0x2e2b38,u[w(850)](u.ZUADH(127,_0x48584d),128)),_0x56a248>>>=7)},x=()=>{u[d(1439)](o),u.eonPb(f)},g=()=>{let w=d;u[w(1634)](c,t[w(821)]||new DOMException(u[w(304)],u[w(304)])),u[w(1439)](f)};t[d(413)+d(240)]("complete",x),t["addEvent"+d(240)](r[d(903)],g),t[d(413)+d(240)](r[d(804)],g)}else{if(r.kFEfQ(r.ErevU(_0x53bbed[d(572)],_0x4503eb),_0x26f640.limit))throw new _0x44877e(d(418)+d(807));_0x5d5fd6[d(572)]+=_0x3a48c3}});$o[e(639)](t,i)}function Lv(t){Jo={IMPck:function(r,i){return r(i)}}.IMPck(t,Jo)}function Nv(t){let e=B,r={KELfv:e(254),Qiana:function(i,o){return i(o)},BzgCP:function(i,o){return i(o)},tzFjU:function(i,o){return i===o},nfLVx:e(1621),Puodm:e(816),GQUsM:function(i,o){return i&o},BpkNa:function(i,o){return i&o},SjnFm:function(i,o){return i>>>o},TkaUr:function(i,o){return i>>>o},IIuWZ:function(i,o){return i>>>o},WxYRH:function(i,o){return i>>>o},Jpjif:function(i,o){return i===o},MsiCd:function(i,o){return i(o)},kIDxh:function(i,o){return i===o},cxRyU:function(i,o){return i in o},ODafT:"objectSt"+e(452),YqxOC:function(i){return i()}};return r[e(896)](t,IDBDatabase[e(1139)+"e"]["transact"+e(955)])&&!r[e(931)](r.ODafT,IDBTransaction[e(1139)+"e"])?function(i,...o){let c=e;if(c(1449)===r[c(992)])throw this[c(1101)+c(305)]=!1,_0x1e7dee;{let d=t[c(527)](r.Qiana(ts,this),i,...o);return Cd[c(639)](d,i[c(455)]?i[c(455)]():[i]),Ht(d)}}:r[e(317)](Dv)[e(563)](t)?function(...i){let o=e;if(r.tzFjU(r.nfLVx,r[o(849)]))r[o(581)](_0x2c03db,this["_connect"+o(1161)+"utId"]),this[o(1101)+o(1161)+o(1633)]=null;else return t.apply(ts(this),i),r[o(638)](Ht,Dd[o(247)](this))}:function(...i){let o=e;return r[o(649)]("UTioa",o(593))?_0x582323["fromChar"+o(353)](r[o(1283)](255,this[o(1152)]),r[o(1646)](this[o(1152)]>>>8,255),r[o(1472)](this[o(1152)],16)&255,r[o(734)](this[o(1152)],24),r[o(1646)](255,this[o(1509)]),r.GQUsM(r.IIuWZ(this[o(1509)],8),255),r[o(1646)](this[o(1509)]>>>16,255),r[o(661)](this.high,24)):r.BzgCP(Ht,t.apply(r[o(1378)](ts,this),i))}}function Mv(t){let e=B,r={uLSPa:function(i,o){return i===o},SzkLZ:e(1471),rjpAO:function(i,o){return i(o)},bZzyc:function(i,o){return i instanceof o},UvUor:function(i,o){return i(o)},sOMZW:function(i,o,c){return i(o,c)}};return r[e(659)](typeof t,r[e(1218)])?r[e(981)](Nv,t):(r[e(1102)](t,IDBTransaction)&&r[e(460)](Ov,t),r[e(365)](gx,t,Cv())?new Proxy(t,Jo):t)}function Ht(t){let e=B,r={EWDlm:function(o,c){return o(c)},yAcbk:function(o,c){return o!==c}};if(t instanceof IDBRequest)return r[e(1572)](Pv,t);if(qo[e(1357)](t))return qo.get(t);let i=r[e(1572)](Mv,t);return r[e(226)](i,t)&&(qo.set(t,i),Vo[e(639)](i,t)),i}var gx,lx,ux,Dd,$o,Cd,qo,Vo,Jo,ts,fx=px({"node_modules/idb/build/wrap-idb-value.js"(){let t=B,e={dIead:function(r,i){return r>=i},BgYEA:function(r,i){return r&i},lUHUo:function(r,i){return r|i},okawc:function(r,i){return r<<i},ZHjYQ:function(r,i){return r&i},iHQfP:function(r,i){return r<<i},UkYKh:function(r,i){return r&i},xtmDC:function(r,i){return r|i},FdXhB:function(r,i){return r&i},lVFZG:function(r,i){return r&i},UyCLW:function(r,i){return r+i},TtTbt:function(r,i){return r>>i},KmsIp:t(351),bxtDO:function(r,i){return r===i},eMYDL:function(r,i){return r!==i},fkETT:"WByjj",XWilp:t(430),catbx:function(r,i){return r===i},wwDYC:t(1459),VoJqt:function(r,i){return r(i)},CtdWs:function(r,i){return r instanceof i},fKNVZ:function(r,i){return r===i},HmQwp:function(r,i){return r in i}};gx=(r,i)=>i.some(o=>r instanceof o),Dd=new WeakMap,$o=new WeakMap,Cd=new WeakMap,qo=new WeakMap,Vo=new WeakMap,Jo={get(r,i,o){let c=t,d={LRzkD:function(u,f){return e[j(683)](u,f)},EIVIk:function(u,f){return e.BgYEA(u,f)},rKzmj:function(u,f){return e[j(1387)](u,f)},sNFnr:function(u,f){return e[j(779)](u,f)},OuuEh:function(u,f){return e[j(243)](u,f)},sOcHl:function(u,f){return e[j(1385)](u,f)},tYWVL:function(u,f){return u&f},lpufi:function(u,f){return e[j(1446)](u,f)},imcra:function(u,f){return u-f},zCTvL:function(u,f){return e[j(1369)](u,f)},xzSIx:function(u,f){return e.xtmDC(u,f)},QpHzn:function(u,f){return u<<f},RQyqT:function(u,f){return e[j(926)](u,f)},MrcXC:function(u,f){return e[j(796)](u,f)},SNgdA:function(u,f){return e[j(1336)](u,f)},mlbpv:function(u,f){return e[j(1205)](u,f)},lLqgi:function(u,f){return u+f}};if(r instanceof IDBTransaction){if(i===e[c(1046)])return $o[c(247)](r);if(e[c(1262)](i,c(1004)+c(452))){if(e[c(1339)](e[c(946)],e[c(871)]))return r[c(1004)+"oreNames"]||Cd.get(r);{let u=_0x5692d7[_0x17d95c++];if(u<=127)_0x1330a5+=_0x2fdacb["fromChar"+c(353)](u);else if(d[c(1390)](u,192)&&u<224)_0x343cae+=_0x5398d[c(283)+"Code"]((31&u)<<6|d.EIVIk(63,_0x4cfa0b[_0x4e4edd++]));else if(d[c(1390)](u,224)&&u<240)_0x46d00f+=_0x319c9c[c(283)+c(353)](d[c(284)](d[c(284)](d[c(1057)](d[c(1591)](15,u),12),d[c(1494)](d[c(669)](63,_0x5f5c99[_0x5f3cc5++]),6)),d[c(1631)](63,_0x531764[_0x28c05d++])));else if(d[c(1390)](u,240)){let f=d[c(474)](d[c(265)](d[c(972)](d[c(284)](d[c(1381)](d.RQyqT(7,u),18),(63&_0x563fbe[_0x25045c++])<<12),d.QpHzn(d[c(475)](63,_0x11f2f5[_0x1641e4++]),6)),d[c(1062)](63,_0x19dc89[_0x5f06b0++])),65536);_0x2818a9+=_0x51b297.fromCharCode(d[c(503)](55296,d[c(1431)](f,10))),_0x454cdd+=_0x163cea[c(283)+c(353)](d[c(1479)](56320,d[c(669)](1023,f)))}}}if(e[c(555)](i,e[c(1133)]))return o[c(1004)+c(452)][1]?void 0:o[c(1004)+c(1115)](o[c(1004)+c(452)][0])}return e[c(1060)](Ht,r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return e[o(313)](r,IDBTransaction)&&(e[o(1613)](i,e.KmsIp)||e[o(555)](i,e[o(1133)]))?!0:e[o(174)](i,r)}},ts=r=>Vo[t(247)](r)}}),mx={};kv(mx,{deleteDB:()=>Fv,openDB:()=>Bv,unwrap:()=>ts,wrap:()=>Ht});function Bv(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let d=B,u={WkVhY:function(g,w,S,_,b){return g(w,S,_,b)},XNANs:function(g,w){return g(w)},MKfLZ:d(647),WODSv:"upgraden"+d(1589)},f=indexedDB[d(1533)](t,e),x=u.XNANs(Ht,f);return i&&f[d(413)+d(240)](u[d(1255)],g=>{let w=d;u[w(1551)](i,u[w(979)](Ht,f.result),g[w(1691)+"on"],g[w(1467)+"on"],u.XNANs(Ht,f[w(553)+w(955)]))}),r&&f[d(413)+d(240)](d(1340),()=>r()),x.then(g=>{let w=d;c&&g[w(413)+w(240)](u[w(1554)],()=>c()),o&&g["addEvent"+w(240)](w(1648)+w(1377),()=>o())})[d(722)](()=>{}),x}function Fv(t,{blocked:e}={}){let r=B,i={ELiGy:function(c,d){return c(d)}},o=indexedDB[r(1546)+r(1277)](t);return e&&o[r(413)+"Listener"](r(1340),()=>e()),i[r(505)](Ht,o).then(()=>{})}function hx(t,e){let r=B,i={NgKOV:function(f,x,g){return f(x,g)},xlSGb:function(f,x,g){return f(x,g)},jOmBb:r(708)+"e",wTsAZ:r(891),ounTA:function(f,x){return f instanceof x},mHHDl:function(f,x){return f in x},LTGKf:function(f,x){return f!==x},sQizP:function(f,x){return f in x}};if(!(i[r(1166)](t,IDBDatabase)&&!i.mHHDl(e,t)&&typeof e===r(221)))if(i[r(1086)](r(499),r(499)))i.NgKOV(_0x5dfd8c,_0x31bff4,66),i.xlSGb(_0x157ab8,_0x40747b,_0x39c519[r(604)]),i.xlSGb(_0x558277,_0x5ae966,_0x431086);else return;if(Wo[r(247)](e))return Wo[r(247)](e);let o=e[r(329)](/FromIndex$/,""),c=i.LTGKf(e,o),d=yx[r(563)](o);if(!i[r(467)](o,(c?IDBIndex:IDBObjectStore)[r(1139)+"e"])||!(d||_x[r(563)](o)))return;let u=async function(f,...x){let g=r,w=this["transact"+g(955)](f,d?i[g(1367)]:i.wTsAZ),S=w[g(1459)];return c&&(S=S[g(1520)](x[g(1595)]())),(await Promise[g(1558)]([S[o](...x),d&&w.done]))[0]};return Wo.set(e,u),u}var _x,yx,Wo,zv=px({"node_modules/idb/build/index.js"(){let t=B,e={wyppv:"4|3|5|2|"+t(864),JhuSv:function(o,c){return o(c)},tMKzL:t(1679),nvTto:t(1397),rAuhB:t(1298),hoiaZ:t(246),RyQZp:function(o){return o()},yoSQQ:t(247),SnmNg:"getKey",ejfgj:t(242),gdVbJ:t(1353)},r=e[t(884)][t(521)]("|"),i=0;for(;;){switch(r[i++]){case"0":Wo=new Map;continue;case"1":e[t(220)](Lv,o=>({...o,get:(c,d,u)=>hx(c,d)||o[t(247)](c,d,u),has:(c,d)=>!!hx(c,d)||o[t(1357)](c,d)}));continue;case"2":yx=[e.tMKzL,e[t(1368)],e[t(1614)],e[t(252)]];continue;case"3":e[t(1248)](fx);continue;case"4":e[t(1248)](fx);continue;case"5":_x=[e.yoSQQ,e.SnmNg,e[t(730)],t(1183)+"ys",e[t(861)]];continue}break}}}),Uv={idb:function(t){let e=B;t[e(1616)]=Promise.resolve()[e(260)](()=>(zv(),mx))[e(260)](function(r){return r})}},xx={};function Gt(t){let e=B,r={kfTmJ:e(1593)+"2",AbkdH:function(u,f){return u!==f}},i=r[e(1180)].split("|"),o=0;for(;;){switch(i[o++]){case"0":var c=xx[t]={exports:{}};continue;case"1":var d=xx[t];continue;case"2":return c.exports;case"3":if(r[e(1564)](void 0,d))return d.exports;continue;case"4":Uv[t](c,c[e(1616)],Gt);continue}break}}(()=>{let t=B,e={MdBmo:"open",byGVb:function(r,i,o){return r(i,o)},NPkaD:function(r,i){return r===i},jCfyv:"CvJDw",muQOc:t(274)};Gt.d=(r,i)=>{let o=t,c={thGWE:e[o(1214)],INKZx:function(u,f,x){return e.byGVb(u,f,x)}};if(e[o(675)](e[o(1120)],e[o(1426)]))Ne.emit(c[o(1294)],c.INKZx(_0x31481e,c[o(1294)],{..._0x302113,data:_0x534258[o(1141)]||""}));else for(var d in i)Gt.o(i,d)&&!Gt.o(r,d)&&Object["definePr"+o(672)](r,d,{enumerable:!0,get:i[d]})}})(),(()=>{let t=B;Gt.o=(e,r)=>Object[t(1139)+"e"][t(819)+t(672)][t(527)](e,r)})(),(()=>{let t=B,e={pdSyP:function(r,i){return r!=i},MchkV:"undefined",SkbyK:"Module",RbfXy:t(1344)+"le"};Gt.r=r=>{let i=t;e[i(970)](e.MchkV,typeof Symbol)&&Symbol[i(633)+"Tag"]&&Object[i(241)+i(672)](r,Symbol["toString"+i(291)],{value:e[i(1172)]}),Object[i(241)+"operty"](r,e[i(1111)],{value:!0})}})();function j(t,e){t=t-171;let r=Ko(),i=r[t];if(j.TXzoYt===void 0){var o=function(f){let x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",g="",w="";for(let S=0,_,b,I=0;b=f.charAt(I++);~b&&(_=S%4?_*64+b:b,S++%4)?g+=String.fromCharCode(255&_>>(-2*S&6)):0)b=x.indexOf(b);for(let S=0,_=g.length;S<_;S++)w+="%"+("00"+g.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(w)};j.tIhWrp=o,j.HSYyun={},j.TXzoYt=!0}let c=r[0],d=t+c,u=j.HSYyun[d];return u?i=u:(i=j.tIhWrp(i),j.HSYyun[d]=i),i}var Le={};(()=>{let t=B,e={jrQlH:t(918),kKTwj:function(a,n){return a(n)},zrgQB:function(a,n){return a+n},lRiWk:function(a,n){return a+n},UHSLy:function(a,n){return a<n},VABcq:function(a,n){return a&n},kdZoN:function(a,n){return a|n},bmXzs:function(a,n){return a>>n},nJdKc:function(a,n){return a&n},TRIEM:function(a,n){return a>>n},zivJg:function(a,n){return a|n},paJjh:function(a,n){return a&n},YQrMk:function(a,n){return a>>n},FSDhw:function(a,n){return a|n},zyzjA:function(a,n){return a===n},oFyWe:"lZjHF",hIxIB:"sUqXb",LIGIN:function(a,n){return a*n},cmIGG:function(a,n){return a+n},GqedQ:function(a,n,s){return a(n,s)},fWUxT:function(a,n,s){return a(n,s)},LUelX:function(a,n){return a(n)},mHOcm:t(522),tUZbj:t(1053),jliWS:function(a,n){return a(n)},ebxJl:function(a,n){return a(n)},fhjWM:t(1425)+t(1425)+t(1425)+"00000000",uRBmq:function(a,n){return a instanceof n},qHRrg:function(a,n){return a===n},hsPwV:t(351),GeKnA:function(a,n){return a===n},Ryyzg:t(1459),ylMVT:function(a,n){return a in n},EgSof:function(a,n){return a instanceof n},KpJIR:function(a,n){return a!=n},ugpsJ:t(1687)+t(760),jARkf:function(a,n){return a<n},vbZFs:function(a,n){return a>n},ROwRQ:function(a,n){return a<n},rzgvO:function(a,n){return a>n},WWWMu:t(1296),RrXir:function(a,n){return a!==n},AuerI:t(1383),oSgfB:"pZnBB",ZjySV:function(a,n){return a<n},fUMZO:function(a,n){return a!==n},dMCkj:function(a,n){return a-n},gXVox:t(1271)+t(1307),eIlVn:function(a,n,s){return a(n,s)},svUOh:function(a,n){return a!==n},QFWyV:t(803),achDR:t(792),HgGyn:function(a,n,s){return a(n,s)},BAXLo:function(a,n,s){return a(n,s)},xHxkt:function(a,n){return a(n)},WdhdR:function(a,n){return a!==n},iXJyy:"LAtJA",Nknbk:function(a,n){return a>>>n},BUjSd:function(a,n,s){return a(n,s)},Rorih:function(a,n){return a(n)},VhOZs:function(a,n,s){return a(n,s)},noBxs:function(a,n){return a(n)},FcOCT:function(a,n,s){return a(n,s)},ZXuox:function(a,n){return a===n},EpfGh:t(999)+t(1468)+t(1672)+"key",srTWf:function(a){return a()},QvPro:function(a,n,s){return a(n,s)},JNGTd:function(a,n,s){return a(n,s)},CJdfa:function(a,n){return a&n},TuoRW:function(a,n,s,l){return a(n,s,l)},CkwZj:"yxCHR",nNwIi:function(a,n){return a!==n},lNkdj:"bBWeg",GjpTT:function(a,n,s){return a(n,s)},huHay:function(a,n){return a!==n},NHfyA:function(a,n,s){return a(n,s)},CIDIJ:function(a,n){return a!==n},HVnOf:function(a,n,s){return a(n,s)},hJnVh:function(a,n){return a!==n},neGdU:function(a,n){return a!==n},Zuvle:"glbVD",QELpa:function(a,n,s){return a(n,s)},omAou:function(a,n){return a(n)},HJjVl:function(a,n){return a!==n},ygcHI:t(1331),pTgYX:function(a,n,s){return a(n,s)},hqjOV:function(a,n,s){return a(n,s)},zBjex:function(a,n){return a!==n},Ehsrd:t(872),ouUDm:function(a,n,s){return a(n,s)},BjfQq:function(a,n,s){return a(n,s)},rpoBZ:function(a,n){return a!==n},imEpv:"fgzIa",EZPdR:function(a,n,s){return a(n,s)},TRcAY:function(a,n,s){return a(n,s)},CCcLT:function(a,n,s){return a(n,s)},RKUAj:function(a,n,s){return a(n,s)},TFOLD:function(a,n){return a===n},zxTyO:t(1697),akRpX:function(a,n){return a(n)},vdmjs:function(a,n){return a(n)},kegkB:function(a,n){return a(n)},ENsTB:function(a,n){return a(n)},YOIFa:function(a,n,s){return a(n,s)},SaWcz:t(999)+"required"+t(1672)+t(194),mJoaW:function(a,n){return a===n},ojTcb:t(999)+t(1468)+t(1672)+t(752),qtLlm:"Missing "+t(1468)+" field: "+t(543),yEucY:function(a,n){return a(n)},Ukzcd:function(a,n){return a+n},xisqf:t(1233)+t(355)+"pe: ",xFYEV:function(a,n){return a>=n},ctBjP:function(a,n){return a===n},aDKFj:function(a,n){return a>n},rGyxz:t(418)+t(807),oyzgA:function(a,n){return a+n},wqyfy:function(a,n){return a>n},tEtPJ:function(a,n,s){return a(n,s)},LofyP:function(a,n){return a+n},pCvai:function(a,n,s){return a(n,s)},TiRJw:function(a,n,s){return a(n,s)},cruUp:t(647),YuTfG:function(a,n,s){return a(n,s)},xMqqJ:function(a,n){return a===n},hjohM:function(a,n){return a(n)},NUDZr:function(a,n){return a===n},IzQFa:function(a,n){return a&n},PJruX:function(a,n){return a+n},jtCzH:function(a,n){return a(n)},dUTfR:function(a,n){return a==n},gerjJ:function(a,n){return a+n},yOvkZ:function(a,n){return a+n},foPzO:function(a,n){return a+n},eLYQy:function(a,n){return a<<n},utzBL:t(373),sendE:function(a,n){return a<<n},iNgwD:function(a,n){return a&n},bLlVR:function(a,n){return a&n},Byohx:function(a,n){return a<n},YebPD:function(a,n){return a>=n},SNAZd:function(a,n){return a<=n},ztoqy:function(a,n){return a==n},Khbjz:function(a,n){return a&n},vOxRW:function(a,n){return a===n},QmIPG:"dEUQu",EQEOX:function(a,n){return a+n},KabrI:function(a,n){return a+n},lrCex:function(a,n){return a&n},sCuET:function(a,n){return a<<n},SyXPj:function(a,n){return a|n},VGeVH:function(a,n){return a|n},QjqJE:function(a,n){return a&n},gGwXX:function(a,n){return a>n},lKaaW:function(a,n,s){return a(n,s)},aovuu:function(a,n){return a+n},CqNNb:function(a,n,s){return a(n,s)},aKOdi:function(a,n){return a<n},uXRbH:function(a,n){return a>=n},uHZYw:function(a,n){return a<n},QIbxl:function(a,n){return a<n},TSpif:function(a,n,s){return a(n,s)},mjjEJ:function(a,n){return a<n},KEffJ:function(a,n){return a<=n},eJvaM:function(a,n){return a<n},gNPYS:function(a,n){return a<<n},LjThY:t(900),TtDBu:t(367),sBgFq:function(a,n){return a|n},GreaD:function(a,n){return a===n},naOgR:t(977),SekSv:function(a,n){return a<n},gJeOx:function(a,n){return a>>n},TYjHR:function(a,n){return a&n},QYUuE:function(a,n){return a&n},XUvAE:function(a,n){return a>>n},KzqYC:function(a,n){return a<n},jZBkz:function(a,n){return a!==n},FfgVB:"Dimvc",OEOeT:function(a,n){return a<n},vJprh:"IobDl",fBqsh:function(a,n,s){return a(n,s)},neRHR:function(a,n,s){return a(n,s)},iIwIA:function(a,n,s){return a(n,s)},vJwmP:t(821),vSwyK:function(a,n,s){return a(n,s)},hjHPy:function(a,n){return a|n},HvYoY:function(a,n){return a|n},BFafl:function(a,n){return a<<n},btLdl:function(a,n){return a<<n},RSmnd:function(a,n){return a+n},Eqnkn:function(a,n,s){return a(n,s)},Oygwv:t(666),kwsyH:function(a,n){return a(n)},Gytws:function(a,n){return a&n},njVJa:function(a,n){return a&n},dCmOc:"GZuBy",cePrS:function(a,n){return a&n},uhQiu:function(a,n){return a===n},BScsh:t(844),tFyYm:function(a,n){return a&n},tIwve:t(1279),qdvKH:function(a,n){return a&n},SNHjQ:t(1252),SQrsS:function(a,n){return a(n)},YBiIj:function(a,n){return a&n},iJKIk:function(a,n){return a&n},ZQCCN:t(954),yDxkk:function(a,n){return a(n)},IEkbT:function(a,n){return a&n},JnNfE:function(a,n){return a(n)},Ijjpy:function(a,n){return a&n},IMrAY:function(a,n){return a<<n},TxQEf:function(a,n){return a|n},qJOBd:function(a,n){return a===n},mmsEi:function(a,n){return a<n},MluxE:function(a,n){return a<n},Lsfcu:function(a,n){return a<n},iDfMr:function(a,n,s){return a(n,s)},psCKk:function(a,n){return a!==n},fzOFH:function(a,n){return a|n},DrywB:function(a,n){return a&n},wuVEI:function(a,n){return a&n},WcvqV:function(a,n){return a>>>n},ioMPj:function(a,n){return a|n},QdMZj:function(a,n){return a>>>n},Xynmk:function(a,n){return a&n},RxwcA:function(a,n){return a!==n},meqtn:function(a,n){return a!==n},bOiLs:function(a,n){return a>>>n},QxUZB:function(a,n){return a+n},pGjnd:function(a,n){return a|n},ZmDjf:function(a,n){return a>>>n},OgYbM:function(a,n){return a!==n},XlixA:function(a,n){return a|n},unORn:function(a,n){return a|n},wBkWQ:function(a,n){return a|n},Fdmiu:t(236),WRBNg:"gnaRO",bZtKA:function(a,n){return a|n},fCbTl:function(a,n){return a<<n},yYCvU:function(a,n){return a|n},eqXFW:function(a,n){return a<<n},yLEay:function(a,n){return a<<n},qEMFr:function(a,n){return a|n},LMTRc:function(a,n){return a|n},oTeTd:function(a,n){return a|n},XeoUh:function(a,n){return a|n},pTDEF:function(a,n){return a<<n},yiPKY:function(a,n){return a<<n},NKCVO:function(a,n){return a===n},OaLuj:function(a,n){return a|n},VeOkM:function(a,n){return a|n},QmiQQ:function(a,n){return a<<n},GkcqY:function(a,n){return a<<n},LIWBu:function(a,n){return a>>>n},hVseS:function(a,n){return a&n},lGbTy:function(a,n){return a>>>n},hoZPF:function(a,n){return a&n},DepQt:function(a,n){return a>=n},zsjlb:function(a,n){return a+n},NzuLk:function(a,n){return a%n},WbIDn:function(a,n){return a/n},iPXxi:function(a,n){return a>>>n},WGCgj:function(a,n){return a&n},DAFqy:function(a,n){return a+n},rPaZr:function(a,n){return a+n},gwTeo:function(a,n){return a>>>n},zRPfZ:function(a,n){return a+n},RzcUE:function(a,n){return a>>>n},cxLPI:function(a,n){return a|n},NlvEi:function(a,n){return a|n},ofiEs:function(a,n){return a<<n},TgwcP:function(a,n){return a>>>n},WkOHW:function(a,n){return a===n},zrFeY:function(a,n){return a===n},vxTVz:function(a,n){return a===n},IpwEo:function(a,n){return a+n},Cmsuv:function(a,n){return a+n},LDyfS:function(a,n){return a===n},ukPxO:t(1098),kvmaZ:"miFoo",WGGCl:function(a,n){return a&n},lFVkP:function(a,n){return a&n},hauQf:function(a,n){return a>>>n},bfIkN:function(a,n){return a>>>n},teWZg:function(a,n){return a>>>n},FmXcX:function(a,n){return a>>>n},OvulP:function(a,n){return a&n},UfXXv:function(a,n){return a>>>n},qjHaa:function(a,n){return a>>>n},DfjfF:t(736)+t(1642),NYrps:t(797)+t(547),gwZHM:t(1580)+"OR",YRaqk:"MAX_RETR"+t(795)+"R",HfjEb:t(1496)+t(875),lRPdD:t(711)+t(840),SPvRs:t(300),qgHVe:function(a,n){return a&&n},gvdwl:t(978),GCrGd:t(937),bxzVk:t(1123),FAoki:function(a){return a()},xwRVZ:function(a,n){return a!==n},Uakzb:t(337),ZNYIs:"eVUWP",CbvrH:t(429),ZMmUe:function(a,n){return a!==n},Aivnm:t(1497),aEGrK:function(a,n){return a===n},hVGqB:function(a,n){return a-n},nMsvY:function(a,n){return a===n},cStPL:function(a,n){return a>n},mqFqa:function(a,n){return a!==n},RoKzL:t(292),xurpX:t(927),EbGCY:function(a,n){return a===n},DRROB:function(a,n){return a+n},lRVSy:"xIhiH",XtQlc:t(967),XABoj:function(a,n){return a<n},MkLBt:function(a,n){return a===n},YsuyF:function(a,n){return a===n},PXrDr:function(a,n){return a===n},yxWqc:t(1004)+t(452),ZCAcA:function(a,n){return a(n)},NHOzd:t(962),Fkujb:function(a,n,s){return a(n,s)},gcFJb:t(1533),dTlil:function(a,n,s){return a(n,s)},Vbetg:function(a,n,s){return a(n,s)},DYaIV:t(263),IJurG:function(a,n,s){return a(n,s)},NsXOi:function(a,n){return a!==n},JGROd:t(709),cAZbt:t(1384),LIhBc:"online",cmiEr:t(307),ZrANs:t(1033),lkbRG:t(1147),hDXwj:function(a,n){return a!==n},bdMBu:t(853),IReDf:function(a,n){return a||n},IpyTz:function(a,n){return a||n},xzrkK:t(535)+"d",AWDRA:function(a,n){return a||n},BdTeI:t(1108)+t(256)+"ltiple t"+t(1422)+"process",yjrvU:function(a,n){return a<n},styrh:function(a,n){return a===n},fvzRM:function(a,n){return a&n},uTMCi:function(a,n){return a+n},ugcxZ:function(a,n){return a<=n},ghBOk:function(a,n){return a|n},gaSCI:function(a,n){return a<<n},OCDFM:function(a,n){return a&n},AMqDB:function(a,n){return a>=n},ZNWAU:function(a,n){return a|n},HkTyY:function(a,n){return a>=n},lkOXG:t(1107),Gtupb:function(a,n){return a|n},bGFRV:function(a,n){return a<<n},oSsAx:function(a,n){return a<<n},rDqOI:function(a,n){return a&n},uKARt:function(a,n){return a+n},liAlZ:function(a,n){return a+n},Nkmek:function(a,n){return a&n},jGOpk:function(a,n){return a<n},WgDVj:function(a,n){return a|n},CyoCy:function(a,n){return a|n},SWBRY:function(a,n){return a&n},tuZVx:function(a,n){return a&n},kBJwc:function(a,n){return a===n},bzDpx:t(1320)+"3|1",CPocB:function(a,n){return a&n},htCTM:function(a,n){return a|n},NwOLf:function(a,n){return a|n},RZCrP:function(a,n){return a+n},IaOLQ:function(a,n){return a>>n},fHiXf:function(a,n){return a&n},mhOOr:function(a,n){return a-n},oinKy:function(a,n){return a==n},PkBeC:"sMdOt",cwYiD:function(a,n,s,l){return a(n,s,l)},dRDlJ:function(a,n){return a instanceof n},AFVRt:function(a,n){return a!=n},MSQSQ:"string",KsqAI:t(1064),JGxvY:function(a,n){return a===n},ZlhKu:t(947),WZXfD:t(443),WicOM:function(a,n){return a(n)},VxLAm:"AbortError",sbshg:function(a){return a()},faIcY:"script",JzRAh:"text/jav"+t(1014),FFRXN:"http",mbypQ:function(a,n){return a!==n},JTaps:"uyBmu",XmEvx:function(a){return a()},KtNKX:function(a,n,s,l){return a(n,s,l)},UoBvz:t(1132)+"4|3|9|0|"+t(1051),ePMrP:function(a,n,s,l){return a(n,s,l)},DCzMD:"service-"+t(287),iufXZ:t(1550),OfSpC:function(a,n){return a===n},kxSoa:t(209),dNWBz:"axLbH",MuttY:function(a,n){return a!==n},vlkyj:t(994),rjTLc:t(406),oFHVP:t(515),eRtjJ:t(577),TVSfF:function(a,n){return a!==n},erXcA:"TbrIK",JelYn:"DjBTt",GalCB:function(a,n){return a|n},HcsoD:function(a,n){return a===n},VRGfz:t(1347),olRuZ:function(a,n){return a||n},ZcgvC:function(a,n){return a||n},HQRqW:function(a,n){return a==n},rgKvO:t(1197),apVGG:t(1188),lYxGv:"ws://",ZRktA:t(1191),hQNvh:function(a,n){return a||n},AMeOr:function(a,n){return a!==n},KwYOC:t(662),NOROR:function(a,n){return a!==n},drLSX:t(1306),yMovQ:function(a,n){return a||n},eLyZl:function(a,n){return a||n},TLPIN:"qos",Ugabt:t(1026)+"id",oyqaj:function(a,n){return a!==n},Uelsu:t(199),vHMbE:function(a,n){return a===n},UaUEI:t(574),QHCbu:t(1090),IRcxb:t(560),Psghc:t(1117)+t(798),fMGCI:t(1117)+t(1599)+"ck",xjeFB:t(1117)+t(1016)+"k",mKziN:function(a,n,s){return a(n,s)},uNiMK:t(1117)+t(414)+"sgid",SNCnD:function(a,n,s,l){return a(n,s,l)},UFygH:function(a,n){return a||n},zZrkM:function(a){return a()},UpuWH:t(371),OuTWH:function(a,n){return a(n)},aJhEG:t(509)+t(890)+"et=utf-8",DPhSq:"applicat"+t(760)+t(1149)+t(1286),nnPDp:t(235)+"e",nMpne:function(a,n){return a>n},eEmUu:function(a,n){return a|n},ddYRw:function(a,n){return a||n},BWhUq:function(a,n){return a(n)},pTBax:function(a,n){return a+n},lVlmI:function(a,n){return a+n},rcCgp:function(a,n){return a+n},psiFR:"index ou"+t(1485)+t(614),AEmDm:t(1597),OWUxL:function(a,n){return a>n},aUEjj:t(643)+t(862)+"e",ricWG:function(a,n){return a&n},LnfcJ:function(a,n){return a+n},mixMo:function(a,n,s){return a(n,s)},duFMw:function(a,n){return a>>>n},jyZAB:function(a,n){return a|n},xDTps:function(a,n){return a|n},LOTFh:function(a,n){return a+n},CqSgS:function(a,n){return a<<n},qdrFs:function(a,n){return a+n},hzqWF:function(a,n){return a<<n},haSBj:function(a,n){return a<<n},oMogU:function(a,n){return a<<n},hyndI:function(a,n){return a+n},piIZs:function(a,n){return a>>>n},raoxX:function(a,n){return a&n},FEczo:function(a,n){return a>>>n},WCWyL:function(a,n){return a&n},hgUTb:function(a,n){return a+n},lKQld:function(a,n){return a&n},OOdTM:function(a,n){return a>>>n},zLgdP:function(a,n){return a+n},kvfvQ:function(a,n){return a&n},KxonG:function(a,n){return a&n},lzXwW:function(a,n){return a+n},sCCfp:t(1650),zueqG:t(1658),ffUTL:"9|2|11|4|10|1|3|"+t(625)+"0",THlnc:function(a,n){return a|n},WnVRZ:function(a,n){return a<n},zvfHr:function(a,n){return a&n},ZUBpV:function(a,n){return a<n},btVzc:function(a,n){return a|n},kycRW:function(a,n){return a>n},AHGYA:function(a,n){return a|n},hwECf:function(a,n){return a|n},pcFnM:function(a,n){return a<<n},JMeUa:function(a,n){return a<n},QYpWg:function(a,n){return a!==n},LRrOi:t(990),iZhXN:t(1404)+"2|3|10|1|4|0|6",bqOLx:"service",enEek:"name",rjvOl:"header",fDxFa:t(266)+"ervice",BFfqc:function(a,n,s,l){return a(n,s,l)},fXoAH:function(a,n,s,l){return a(n,s,l)},JFIxc:"zpKwf",FYFVo:"cursor_f"+t(1514),ZKPXH:function(a,n,s){return a(n,s)},hQpDR:function(a,n,s){return a(n,s)},DedFu:function(a,n){return a(n)},HOcUZ:t(1116),QIaqx:t(1647),CEgbt:function(a,n){return a<n},IlEDl:"micbk",fLsXt:"UzIYE",mzvUh:function(a,n,s){return a(n,s)},eEpVU:function(a,n,s,l){return a(n,s,l)},MsAih:t(952)+t(692),eTXAx:"hxAeL",frovL:t(888)+t(1020),OirNj:t(448)+"rValues",LCLKx:"ALL",DcEsx:t(1507),mMUOY:t(785),XhpCU:t(611),XygMu:t(298),CejGe:function(a,n){return a(n)},bxStP:t(374)+"r",Atwwn:t(1301)+"s instan"+t(1428)+t(943)+"ed",PgiPe:function(a,n){return a===n},PTrup:"close, ws alread"+t(412),tvVOw:t(985),Dlavf:function(a,n,s){return a(n,s)},lQdnR:"pGWjN",bgLCX:function(a,n){return a||n},pCGRw:t(1035),eXysn:t(601),oLmWb:function(a,n,s){return a(n,s)},VoOya:t(1117)+"er_msgid",avOtH:function(a,n,s){return a(n,s)},rHOdU:t(564)+"s",xAPmi:function(a,n,s){return a(n,s)},quXCk:"x-msg-cursor_value",cKDDN:function(a,n){return a>n},ePHLh:function(a,n){return a+n},AtMul:function(a,n){return a<n},dsANT:function(a){return a()},goHmV:t(1293),Kriwf:function(a,n){return a!==n},DrZCH:t(1615),ZVcey:function(a,n){return a===n},RrAzL:function(a,n){return a&&n},PUpKn:function(a){return a()},ttkxh:function(a,n,s){return a(n,s)},vMuLO:function(a){return a()},HhKPx:function(a,n){return a(n)},YIjjD:function(a,n,s){return a(n,s)},dzQTp:function(a,n){return a!==n},vrnAg:function(a,n){return a===n},ThIZj:t(1050),HRnvD:"RrxjE",QMcjq:function(a,n,s){return a(n,s)},mxrcM:function(a){return a()},tXmpT:function(a,n){return a(n)},WyKtJ:function(a,n){return a!==n},oiuIa:t(1081),MrCXf:function(a,n,s){return a(n,s)},penom:function(a,n,s){return a(n,s)},yoDhQ:t(1438),JYUYg:function(a,n){return a&n},UMOwm:function(a,n){return a<<n},JxHxS:function(a,n){return a&n},RNplE:function(a,n){return a===n},WqTcF:t(465),wmJhC:t(1043)+t(801)+"s",UDWDX:t(1300),Qwnsa:function(a,n,s){return a(n,s)},smRVg:function(a,n){return a*n},KHbbO:function(a,n,s){return a(n,s)},iPOFW:function(a,n){return a!==n},FFIKO:"xaJMM",liaKw:"arraybuffer",HkkgC:t(1329),xmtlf:function(a,n){return a/n},LTkXj:t(880),GibxX:t(749)+t(336)+t(1231),jPlVs:function(a,n){return a(n)},Topug:"please p"+t(827)+t(1536)+t(995)+t(1675)+"tructor "+t(636)+t(1137),WAGRH:function(a,n,s){return a(n,s)},XmXrY:"reconnect",WZBvw:function(a,n){return a!==n},rLEpJ:t(524),xnHxd:t(1653)+"d",roiKH:t(749)+t(496)+"ddID, deviceID o"+t(1435),oIPmG:t(1471),ISbMa:function(a){return a()},Wdxgq:function(a,n,s){return a(n,s)},VHhqv:t(658),wVaaQ:t(1112)+"0",VvHGK:function(a,n){return a!==n},iTBgM:t(1532),UQrTQ:function(a,n,s){return a(n,s)},EIRYW:function(a,n,s){return a(n,s)},PxRVL:t(714),MjLcH:function(a,n){return a>n},KXUsT:function(a,n){return a-n},DAIIY:function(a,n,s){return a(n,s)},MYhxi:function(a,n,s){return a(n,s)},CVUbi:function(a,n){return a(n)},Burau:"FRONTIER>",ZoTkn:function(a,n){return a===n},HtBBp:"ping_onc"+t(1210)+"t",jclCR:t(333),sqJig:"going away, try "+t(1199)+"ting ser"+t(1227),AQYTz:t(805),rwMGC:t(758),cUkem:t(378),ksSmM:t(942),jStws:t(1416),GcUYs:t(228),NZbos:t(472)+"3",VDcKg:"4|3|0|2|1",GnjkB:"success",TcghV:function(a,n){return a!==n},TrBUP:t(1258),NVHyV:t(691)+t(870)+t(606)+t(983),rrcRw:t(1087),inNSH:function(a,n){return a===n},vOCOv:function(a,n,s){return a(n,s)},MgmvK:t(749)+"rovide a"+t(210)+"ata, dat"+t(258)+t(1421)+t(1526)+t(1665)+t(676),MYloq:function(a,n){return a==n},BMDDo:t(390),rdrSz:function(a,n){return a!=n},WHfDe:function(a,n){return a instanceof n},SPgbq:function(a,n){return a(n)},DvcDV:function(a,n){return a(n)},rMdrC:function(a,n){return a instanceof n},QYdwu:function(a,n){return a===n},YUmSF:t(1405),PEgMm:function(a,n){return a<n},ykxoQ:t(1556),fesqN:function(a,n){return a||n},dcDzz:"4|1|3|0|2",hllZR:function(a){return a()},lZnyI:t(653),eqZhS:"aKSvj",QZPVF:function(a,n){return a!==n},OEWtr:t(490),rxAfg:function(a,n){return a*n},nsHLH:function(a,n){return a/n},FnOlo:t(1216),OHkya:function(a,n){return a===n},oOGQS:function(a,n){return a===n},VwSlL:t(1228),RXBIj:"DedicatedWorkerG"+t(720)+"pe",aiPXP:function(a,n){return a===n},Citbt:function(a,n){return a==n},AGrcX:function(a,n){return a!=n},MsQIb:function(a,n){return a===n},CIWUl:"ServiceW"+t(1055)+"balScope",ZeSYf:function(a,n){return a!=n},asrGk:function(a,n){return a!=n}};Gt.r(Le),Gt.d(Le,{FWS:()=>tg,CustomErrorEvent:()=>Zd,createCloseEvent:()=>wt,ReconnectEvent:()=>Jd,createErrorEvent:()=>ft,decodedFrame:()=>sn,createOpenEvent:()=>nl,CustomCloseEvent:()=>Yd,createReconnectEvent:()=>ha,FrontierMessageEvent:()=>Qd,encodeFrame:()=>jt,createMessageEvent:()=>tl,OpenEvent:()=>el,ErrorCode:()=>an,Event:()=>ir,MessageEvent:()=>Xd});let r="";function i(a=""){let n=t;if(e[n(906)]===e[n(906)]){let l=""+Date.now(),h=r||(r=e.kKTwj(f,a)),m=Math[n(1096)]()[n(633)](16)[n(306)](-6);return e[n(932)](e[n(1239)](e.zrgQB("02",l),h),m)}else this["currentI"+n(348)]=0,this[n(1492)+n(1006)+n(1510)+"t"]=0}function o(){let a=t,n={NuamI:function(s,l){return e[j(748)](s,l)},GTfKo:function(s,l){return e[j(674)](s,l)},msdqv:function(s,l){return s>>l},fcRgi:function(s,l){return e[j(678)](s,l)},WWydj:function(s,l){return e[j(674)](s,l)},zKXLc:function(s,l){return e.bmXzs(s,l)},oVHGf:function(s,l){return e[j(680)](s,l)},psqmm:function(s,l){return e.TRIEM(s,l)},mPYVB:function(s,l){return e[j(1319)](s,l)},uqMsB:function(s,l){return e[j(665)](s,l)},nVyWH:function(s,l){return e[j(876)](s,l)},FIriB:function(s,l){return e.FSDhw(s,l)}};if(e.zyzjA(e[a(442)],e[a(360)]))n[a(1207)](_0x6e1065,2048)?_0x2359ba[_0x256b76++]=n[a(308)](n[a(268)](_0x43e9fa,6),31)|192:(n[a(1207)](_0xe454f4,65536)?_0x218082[_0x4e1b25++]=n[a(1230)](n[a(446)](n[a(268)](_0x16213b,12),15),224):(_0x5a015f[_0x3dc129++]=n[a(1230)](n[a(1680)](_0x26cc70,18)&7,240),_0x46acb8[_0x1c6e28++]=n[a(626)](n[a(361)](_0x27ddd7,12),63)|128),_0x29b86c[_0x251757++]=n[a(202)](n.uqMsB(n[a(192)](_0x2b4f30,6),63),128)),_0x2edddf[_0x342b8a++]=n[a(1576)](n[a(626)](63,_0x1450f7),128);else return e[a(932)](e.LIGIN(1e4,Date[a(1165)]()),Math[a(893)](1e4*Math[a(1096)]()))}function c(a){let n=t;return e.cmIGG(e[n(843)](Array,8)[n(208)]("0"),e[n(869)](parseInt,a,10).toString(2)).slice(-8)}function d(a){let n=t;return e[n(1493)](e[n(843)](Array,4)[n(208)]("0"),e[n(845)](parseInt,a,2)[n(633)](16))[n(306)](-4)}function u(a){let n=t,s=a[n(521)](/\./)[n(1104)](m=>c(m)),l=[];return l[0]=e[n(843)](d,e[n(1493)](s[0],s[1])),l[1]=e.LUelX(d,e[n(1493)](s[2],s[3])),[e.mHOcm,e.mHOcm,n(522),e[n(1099)],"0000",e[n(690)],l[0],l[1]][n(208)]("")}function f(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(1105)](a),l=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[n(1105)](a);return s?e.jliWS(u,a):l?e.ebxJl(x,a):e.fhjWM}function x(a){let n=t,s={gMTki:n(221),gBGaY:function(A,L){return e[n(359)](A,L)},DPtZX:function(A,L){return e[n(1068)](A,L)},rTQTW:e[n(1265)],tzeqd:function(A,L){return e[n(463)](A,L)},lkRBr:function(A,L){return e.kdZoN(A,L)},IDPlX:function(A,L){return e[n(665)](A,L)},IDISt:function(A,L){return A>>L},QMRBI:function(A,L){return e[n(678)](A,L)},cfWbr:function(A,L){return A&L},plLSZ:function(A,L){return e.TRIEM(A,L)},XQOYK:function(A,L){return e.FSDhw(A,L)},fylQz:function(A,L){return e[n(876)](A,L)}},l="",h=[],m=0,v=0,E=!0,p=n(522);if(e.vbZFs(a.indexOf("::"),-1)){let A=a[n(521)]("::");for(let N=0;e[n(1623)](N,A[n(604)]);N++){let U=A[N];if(e.rzgvO(U[n(596)](":"),0)){if(n(949)===e.WWWMu)return s[n(344)]!=typeof _0x374b74&&(s.gBGaY(_0x1f2e89,_0x20c65b)||_0x4b7958[n(989)]&&s[n(1573)](_0x32b6ca[n(989)],_0x457c06))||s[n(568)](s[n(344)],typeof _0xbb0bb6)?"":(_0x4e43f6.parse(_0x26e009),s[n(279)]);{let Z=U[n(521)](":");E&&(m=Z[n(604)]),v+=Z[n(604)];for(let X=0;X<Z.length;X++)if(e[n(1527)](4,Z[X][n(604)])){let Ve=p[n(873)+"g"](0,4-Z[X][n(604)]),te=Ve[n(886)](Z[X]);h[n(315)](te)}else h[n(315)](Z[X]);E=!1}}else if(e[n(190)](e[n(1656)],n(290)))s[n(1110)](_0xde6afa,65536)?_0x52a254[_0x1eed81++]=s[n(526)](s[n(1606)](s[n(368)](_0x146519,12),15),224):(_0x47bc02[_0x549b13++]=s.QMRBI(s.IDPlX(_0x34e253>>18,7),240),_0x1906cf[_0x5cb64d++]=s[n(469)](s[n(1565)](_0x1233f0,12),63)|128),_0xfc2165[_0x56bbce++]=s[n(668)](s[n(469)](s[n(1352)](_0x2c8b2c,6),63),128);else{if(U[n(604)]!==4){let Z=p[n(873)+"g"](0,4-U[n(604)]),X=Z[n(886)](U);h[n(315)](X)}else h[n(315)](U);E&&(m+=1),v+=1,E=!1}}let L="";for(let N=0;e[n(463)](N,8-v);N++)L=L[n(886)](p);for(let N=0;N<h.length;N++)if(e[n(190)](N,m))if(e.oSgfB===e[n(1305)])l=l[n(886)](L),l=l[n(886)](h[N]);else return spPegF[n(695)](_0x44f321,_0x10666a)&&(spPegF[n(190)](_0x133914,spPegF[n(971)])||spPegF[n(984)](_0x58b916,spPegF[n(197)]))?!0:spPegF[n(1506)](_0x2ad7ce,_0x362696);else l=l.concat(h[N]);return l}{let A=a[n(521)](":");for(let L=0;e.ZjySV(L,A[n(604)]);L++){let N=A[L];if(e[n(1142)](4,A[L][n(604)])){let U=p[n(873)+"g"](0,e[n(1072)](4,A[L].length)),Z=U[n(886)](N);l=l[n(886)](Z)}else l=l.concat(N)}return l}}function g(a,n){let s=t,l=a[s(346)];e[s(1142)](void 0,l)&&(we(n,10),e[s(707)](H,n,l));let h=a.value;e.svUOh(void 0,h)&&(e[s(1142)](e[s(1315)],e.achDR)?(e[s(432)](we,n,18),e[s(323)](H,n,h)):(_0x42d867["frontier"+s(1693)]=void 0,_0x46e87b(e[s(276)])))}function w(a){let n=t,s={jGWSA:function(h,m){return e[j(190)](h,m)},AwssQ:function(h,m){return e[j(932)](h,m)}},l={};e:for(;!e[n(486)](J,a);){if(e[n(471)](e[n(299)],e[n(299)]))return this[n(1152)]===-1&&s[n(1156)](-1,this[n(1509)])?_0x46b2fb[n(645)](0,0,this.unsigned):this.low===-1?_0x2a894d[n(645)](0,this.high+1,this[n(642)]):_0x3be1ae[n(645)](s.AwssQ(this[n(1152)],1),this[n(1509)],this[n(642)]);{let h=e[n(843)](me,a);switch(e.Nknbk(h,3)){case 0:break e;case 1:l[n(346)]=e[n(491)](O,a,e[n(1466)](me,a));break;case 2:l[n(1007)]=e[n(1140)](O,a,e[n(1440)](me,a));break;default:e.FcOCT(k,a,7&h)}}}if(e.ZXuox(void 0,l[n(346)]))throw new Error(e[n(684)]);if(e.GeKnA(void 0,l[n(1007)]))throw new Error("Missing "+n(1468)+" field: "+n(1007));return l}function S(a){let n=t,s=e.srTWf(C);return e[n(1528)](_,a,s),M(s)}function _(a,n){let s=t,l={TDSkt:function(h,m,v){return e[j(1324)](h,m,v)},tIRuE:function(h,m,v){return e.JNGTd(h,m,v)},vptpp:function(h,m){return h|m},iJIxa:function(h,m){return e[j(665)](h,m)},JhMWE:function(h,m){return h<m},MkLid:function(h,m){return e.FSDhw(h,m)},LTaDF:function(h,m){return h<<m},ZzRCf:function(h,m){return e[j(674)](h,m)},QzaAp:function(h,m){return e[j(425)](h,m)},teKBN:function(h,m){return e[j(1232)](h,m)},GfabH:function(h,m,v,E){return e.TuoRW(h,m,v,E)}};if(s(1282)===e.CkwZj){let h=a[s(194)];if(e.nNwIi(void 0,h))if(e.lNkdj===s(902)){if(!this[s(624)+s(325)]()||this[s(1437)+"osed"])return;this[s(1247)+s(1366)]?.["resetEnd"+s(552)+"fig"](),this._pingLossCounter?.[s(916)+s(1203)](),this[s(1512)]?this[s(1143)+"ect"](1001,s(691)+s(1414)+s(1199)+s(1360)+"ver",!0):this[s(1101)]()}else we(n,8),e[s(1278)](mt,n,h);let m=a[s(752)];e.huHay(void 0,m)&&(e[s(762)](we,n,16),e[s(1359)](mt,n,m));let v=a[s(293)];e.CIDIJ(void 0,v)&&(e.HVnOf(we,n,24),mt(n,D(v)));let E=a[s(543)];e[s(609)](void 0,E)&&(e[s(1355)](e.Zuvle,e.Zuvle)?_0x197069[s(639)](_0x1a3330,_0x3f2faf):(e.GjpTT(we,n,32),e[s(904)](mt,n,e[s(696)](D,E))));let p=a[s(285)];if(e.HJjVl(void 0,p))for(let te of p)if(e.qHRrg(e[s(628)],e.ygcHI)){e[s(845)](we,n,42);let ae=e[s(631)](C);e[s(491)](g,te,ae),e.pTgYX(we,n,ae[s(1325)]),e.hqjOV(K,n,ae),e[s(1466)](P,ae)}else l.TDSkt(_0x31a694,_0x241055,50),l[s(603)](_0x45a6a5,_0x168995,_0x2af988);let A=a[s(1602)+s(703)];e[s(376)](void 0,A)&&(we(n,50),H(n,A));let L=a["payloadT"+s(1118)];if(L!==void 0){if(s(872)!==e.Ehsrd)return _0x1fb0aa.objectStoreNames||_0x5cd48b[s(247)](_0x343ad8);e[s(869)](we,n,58),H(n,L)}let N=a.payload;e.hJnVh(void 0,N)&&(we(n,66),e[s(267)](we,n,N[s(604)]),e.BjfQq(le,n,N));let U=a[s(375)];e[s(1681)](void 0,U)&&(e[s(1324)](we,n,74),e.fWUxT(H,n,U));let Z=a.serverTiming;if(e[s(1142)](void 0,Z))if(e[s(641)](e[s(489)],e[s(489)])){let te={njNxo:function(V,$){return V>>>$},aTJIf:function(V,$){return V<$},NIsKg:function(V,$){return l[s(1487)](V,$)},EOzxj:function(V,$){return l[s(1442)](V,$)},VpRhZ:function(V,$){return l[s(1518)](V,$)},ZhGmp:function(V,$){return l[s(757)](V,$)},NGKcy:function(V,$){return l.LTaDF(V,$)},DZXdP:function(V,$){return l[s(557)](V,$)},QWvQO:function(V,$){return l.QzaAp(V,$)},BFQfz:function(V,$){return V|$},QgJZc:function(V,$){return l[s(557)](V,$)},JVQnG:function(V,$){return l[s(757)](V,$)},AywWB:function(V,$){return l[s(1689)](V,$)},qTQHO:function(V,$,De,_e){return l.GfabH(V,$,De,_e)}},ae=4294967295;return function(V,$,De=!0){let _e=s;if(ae=te.njNxo(127&V[$],0),te[_e(1244)](V[$++],128))return{value:De?ae:te[_e(1209)](0,ae),offset:$};if(ae=te[_e(1663)](te[_e(1209)](ae,te[_e(250)](127,V[$])<<7),0),te[_e(773)](V[$++],128))return{value:De?ae:te[_e(239)](0,ae),offset:$};if(ae=te[_e(1663)](ae|te[_e(957)](te[_e(1568)](127,V[$]),14),0),V[$++]<128)return{value:De?ae:te.ZhGmp(0,ae),offset:$};if(ae=te[_e(910)](te[_e(595)](ae,te.NGKcy(te.QgJZc(127,V[$]),21)),0),V[$++]<128)return{value:De?ae:0|ae,offset:$};if(ae=te[_e(910)](te[_e(1309)](ae,te.AywWB(15,V[$])<<28),0),V[$++]<128)return{value:De?ae:te[_e(595)](0,ae),offset:$};if(($+=5)>V.length)throw $=V[_e(604)],te[_e(380)](_0x227977,$,10,V.length);return{value:De?ae:0|ae,offset:$}}}else e[s(762)](we,n,82),e.EZPdR(H,n,Z);let X=a[s(1341)];e.zBjex(void 0,X)&&(we(n,90),e[s(729)](H,n,X));let Ve=a.frameType;e[s(1527)](void 0,Ve)&&(e[s(640)](we,n,96),e[s(340)](mt,n,D(Ve)))}else this[s(576)](_0x540393,_0x3db891)}function b(a){let n=t;return e[n(755)](I,e[n(356)](F,a))}function I(a){let n=t,s={};e:for(;!J(a);)if(e[n(1620)](e[n(218)],e[n(218)])){let l=e.xHxkt(me,a);switch(e[n(425)](l,3)){case 0:break e;case 1:s.SeqID=kt(a,!0);break;case 2:s.LogID=kt(a,!0);break;case 3:s[n(293)]=e[n(696)](me,a);break;case 4:s[n(543)]=me(a);break;case 5:{let h=e.akRpX(T,a);(s.headers||(s[n(285)]=[])).push(e.vdmjs(w,a)),a[n(1325)]=h;break}case 6:s[n(1602)+n(703)]=O(a,e[n(744)](me,a));break;case 7:s[n(1287)+n(1118)]=e[n(1140)](O,a,e.noBxs(me,a));break;case 8:s[n(1482)]=ce(a,e.kegkB(me,a));break;case 9:s[n(375)]=e[n(869)](O,a,me(a));break;case 10:s[n(1395)+"ming"]=e[n(491)](O,a,e[n(1259)](me,a));break;case 11:s[n(1341)]=e[n(898)](O,a,e[n(204)](me,a));break;case 12:s.frameType=e.kKTwj(me,a);break;default:k(a,7&l)}}else return this._ws?this[n(1512)].extensions:"";if(e[n(517)](void 0,s[n(194)]))throw new Error(e[n(1583)]);if(e[n(1505)](void 0,s.LogID))throw new Error(e[n(222)]);if(s[n(293)]===void 0)throw new Error(n(999)+n(1468)+n(1672)+n(293));if(e[n(984)](void 0,s[n(543)]))throw new Error(e[n(1039)]);return s}function T(a){let n=t,s=me(a),l=a[n(1325)];return a[n(1325)]=e[n(1239)](a.offset,s),l}function k(a,n){let s=t;switch(n){case 0:for(;e[s(674)](128,e.vdmjs(de,a)););break;case 2:Y(a,e[s(435)](me,a));break;case 5:e.QvPro(Y,a,4);break;case 1:e[s(707)](Y,a,8);break;default:throw new Error(e[s(1516)](e[s(682)],n))}}function D(a){let n=t;return a|=0,{low:a,high:e[n(1184)](a,31),unsigned:e[n(1017)](a,0)}}let y=[];function C(){let a=t,n=y[a(1699)]();return n?(n[a(572)]=n[a(1325)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function P(a){y[t(315)](a)}function F(a){return{bytes:a,offset:0,limit:a[t(604)]}}function M(a){let n=t,s=a[n(1444)],l=a[n(1325)];return e[n(811)](s.length,l)?s:s.subarray(0,l)}function Y(a,n){let s=t;if(e[s(1292)](a[s(572)]+n,a[s(1325)]))throw new Error(e[s(1243)]);a[s(572)]+=n}function J(a){let n=t;return e[n(580)](n(504),n(504))?{bytes:_0x17ad76,offset:0,limit:_0x1a1abe[n(604)]}:e[n(1017)](a[n(572)],a[n(1325)])}function ie(a,n){let s=t,l=a.bytes,h=a.offset,m=a.limit,v=e[s(1312)](h,n);if(v>l.length){let E=new Uint8Array(e[s(753)](2,v));E[s(639)](l),a[s(1444)]=E}return a.offset=v,e.wqyfy(v,m)&&(a[s(1325)]=v),h}function Q(a,n){let s=t,l=a.offset;if(l+n>a[s(1325)])throw new Error(s(1153)+"t limit");return a[s(572)]+=n,l}function ce(a,n){let s=t,l=e.tEtPJ(Q,a,n);return a[s(1444)].subarray(l,e[s(1560)](l,n))}function le(a,n){let s=t,l=e[s(1569)](ie,a,n.length);a[s(1444)][s(639)](n,l)}function O(a,n){let s=t,l={KgzFq:function(A,L,N){return e[j(845)](A,L,N)},Tzauk:function(A,L,N){return A(L,N)},AhMqL:function(A,L,N,U){return e[j(582)](A,L,N,U)},VcHMN:function(A,L){return A+L},WPfhU:function(A,L,N){return e[j(295)](A,L,N)},rfAul:e.cruUp},h=e[s(477)](Q,a,n),m=String[s(283)+s(353)],v=a.bytes,E="\uFFFD",p="";for(let A=0;A<n;A++){let L=v[A+h],N,U,Z,X;if(e.xMqqJ(e.paJjh(128,L),0))p+=e[s(745)](m,L);else if(e[s(1474)](e[s(702)](224,L),192))e.xFYEV(e[s(741)](A,1),n)?p+=E:(N=v[e[s(1516)](A,h)+1],e.RrXir(192&N,128)?p+=E:(X=(31&L)<<6|e.VABcq(63,N),X<128?p+=E:(p+=e[s(855)](m,X),A++)));else if(e[s(1179)](240&L,224))if(A+2>=n)p+=E;else if(N=v[e.gerjJ(A+h,1)],U=v[e[s(456)](e[s(687)](A,h),2)],e[s(184)](e[s(1319)](N,e[s(778)](U,8))&49344,32896))p+=E;else if(e[s(376)](e[s(1600)],e.utzBL)){let{offset:Ve}=l[s(434)](_0x59c386,_0x34604f,_0x121a50);_0x57ed48=Ve;let te={cursor_name:"",cursor:0,service:0},{value:ae,offset:V}=l[s(434)](_0xdd1e3a,_0x3789b1,_0x33745d);te[s(293)]=ae,_0x3c6e75=V;let{value:$,offset:De}=l.Tzauk(_0x5dce8a,_0x66a77a,_0x47eb90);_0xf09de=De,te[s(888)+s(1020)]=l[s(774)](_0x5550c1,_0x2f0ec4,_0x2e3daa,l.VcHMN(_0x50082b,$)),_0x42d68a+=$;let{value:_e,offset:ba}=l[s(237)](_0x4e140a,_0x5104da,_0xfebcbb);te[s(545)]=_e[s(1542)](),_0x4d8f47=ba,_0x36108f.push(te)}else X=e[s(1288)]((15&L)<<12,e[s(1189)](e[s(1290)](63,N),6))|e.bLlVR(63,U),e[s(1625)](X,2048)||e[s(342)](X,55296)&&e[s(591)](X,57343)?p+=E:(p+=m(X),A+=2);else e.ztoqy(e[s(1678)](248,L),240)?e[s(1017)](e[s(1239)](A,3),n)?p+=E:e[s(238)](s(637),e[s(312)])?this[s(1245)](l.rfAul,_0x4dc200(l[s(764)],{..._0x54517f})):(N=v[e[s(629)](A,h)+1],U=v[A+h+2],Z=v[e[s(1516)](e[s(498)](A,h),3)],e[s(771)](e.lrCex(e[s(1319)](e[s(678)](N,e[s(198)](U,8)),e[s(1189)](Z,16)),12632256),8421504)?p+=E:(X=e[s(1349)](e[s(889)](e[s(1288)](e[s(965)](7,L)<<18,e[s(680)](63,N)<<12),e[s(198)](e.lrCex(63,U),6)),63&Z),X<65536||e[s(1093)](X,1114111)?p+=E:(X-=65536,p+=e[s(1688)](m,e.aovuu(e[s(385)](X,10),55296),e.Ukzcd(e.VABcq(1023,X),56320)),A+=3))):p+=E}return p}function H(a,n){let s=t,l={OTFXK:function(p,A,L){return e[j(334)](p,A,L)},GyXDt:function(p,A){return p+A}},h=n[s(604)],m=0;for(let p=0;e[s(1457)](p,h);p++){let A=n[s(561)+"At"](p);e[s(650)](A,55296)&&e[s(591)](A,56319)&&e[s(470)](e[s(498)](p,1),h)&&(A=e[s(1072)](e[s(456)](A<<10,n[s(561)+"At"](++p)),56613888)),m+=e[s(1193)](A,128)?1:A<2048?2:e[s(288)](A,65536)?3:4}e[s(267)](we,a,m);let v=e[s(1326)](ie,a,m),E=a[s(1444)];for(let p=0;e.mjjEJ(p,h);p++){let A=n.charCodeAt(p);if(A>=55296&&e[s(180)](A,56319)&&e.eJvaM(e[s(741)](p,1),h)&&(A=e.gNPYS(A,10)+n[s(561)+"At"](++p)-56613888),e[s(463)](A,128))E[v++]=A;else if(e[s(1103)]!==e.TtDBu){if(e[s(463)](A,2048))E[v++]=e[s(959)](e[s(674)](e[s(1184)](A,6),31),192);else if(e.GreaD(s(1299),e[s(525)])){let L=fGQVSQ[s(462)](_0x7840c4,_0x213911,_0xd23323);return _0x3f3523[s(1444)][s(1269)](L,fGQVSQ[s(613)](L,_0x593fb7))}else e[s(466)](A,65536)?E[v++]=e.gJeOx(A,12)&15|224:(E[v++]=e[s(1349)](e[s(385)](A,18)&7,240),E[v++]=e[s(678)](e.TYjHR(e[s(1184)](A,12),63),128)),E[v++]=e[s(1319)](e[s(1241)](e[s(1281)](A,6),63),128);E[v++]=e[s(889)](63&A,128)}else return 0}}function K(a,n){let s=t,l=e.fWUxT(ie,a,n[s(1325)]),h=a.bytes,m=n.bytes;for(let v=0,E=n[s(1325)];e.KzqYC(v,E);v++)h[e[s(411)](v,l)]=m[v]}function de(a){let n=t;return a.bytes[e[n(477)](Q,a,1)]}function rt(a,n){let s=t,l=ie(a,1);a[s(1444)][l]=n}function me(a){let n=t;if(e[n(1330)](e[n(1206)],e[n(1206)]))_0x250ffb-=65536,_0x21597d+=_0x53a629(e[n(1560)](e[n(1281)](_0x3d224b,10),55296),e[n(1290)](1023,_0xd0b7fd)+56320),_0x4cab5d+=3;else{let s=0,l=0,h;do h=e[n(755)](de,a),e[n(793)](s,32)&&(l|=e[n(778)](127&h,s)),s+=7;while(128&h);return l}}function we(a,n){let s=t;if(e[s(1515)]!==s(216)){for(n>>>=0;e[s(342)](n,128);)e[s(578)](rt,a,e[s(1288)](e[s(674)](127,n),128)),n>>>=7;e[s(598)](rt,a,n)}else e.TuoRW(_0xc50e48,this,_0x13f0b0,[_0x1c2234,_0x4228a4,_0x482481])}function kt(a,n){let s=t,l={ZzROX:e[s(1677)],YWaXC:s(1648)+s(1377)};if(e[s(1681)](s(666),e.Oygwv)){let h=e[s(1412)](_0x387132,e[s(1028)],{message:this[s(1400)+"rrorMess"+s(513)](_0x179859)});this[s(1245)](e[s(1028)],h);let m=e[s(249)](_0x5632e4,e[s(1677)],{reason:this["_formatE"+s(231)+s(513)](_0x52748b)});this[s(1245)](e[s(1677)],m)}else{let h=0,m=0,v=0,E;if(E=e[s(493)](de,a),h=e.Gytws(127,E),128&E&&(E=e[s(1432)](de,a),h|=e[s(778)](127&E,7),e[s(1310)](128,E)))if(e.qHRrg(e[s(302)],e[s(302)])){if(E=e[s(1323)](de,a),h|=e[s(198)](127&E,14),e[s(1124)](128,E))if(e.uhQiu(e[s(514)],e[s(514)])){if(E=e[s(744)](de,a),h|=e[s(848)](127&E,21),128&E&&(E=de(a),m=e[s(1308)](127,E),e[s(965)](128,E))){if(e[s(1131)](e[s(822)],s(1393)))return _0x30e6bc?this[s(1075)+"E"]():this[s(343)+"E"]();E=e[s(435)](de,a),m|=e[s(778)](127&E,7),e[s(1419)](128,E)&&(s(831)!==e[s(1109)]?(E=e.SQrsS(de,a),m|=e[s(294)](127,E)<<14,e.iJKIk(128,E)&&(e[s(238)](e[s(1641)],e[s(1641)])?(E=e[s(493)](de,a),m|=e[s(778)](127&E,21),e[s(1308)](128,E)&&(E=e[s(1441)](de,a),v=e.IEkbT(127,E),e[s(1241)](128,E)&&(E=e[s(610)](de,a),v|=e[s(1189)](e[s(289)](127,E),7)))):(_0x48b322=e[s(1323)](_0x3f0e33,_0x30d920),_0xcf1164=0))):(_0x5e94f3&&_0x3aad56[s(413)+s(240)](CeAlpt[s(588)],()=>_0x3109cc()),_0x5e4687&&_0x50f6c6[s(413)+"Listener"](CeAlpt[s(824)],()=>_0x3238d9())))}}else{let p=e[s(1415)](e[s(678)](e.HvYoY((7&_0x22fa27)<<18,e[s(776)](e[s(702)](63,_0x1cdc34[_0x1616e2++]),12)),e[s(193)](e[s(702)](63,_0x362fee[_0xb0801c++]),6)),e[s(450)](63,_0x35dc33[_0x100722++]))-65536;_0x30cade+=_0x121212["fromChar"+s(353)](e[s(558)](55296,e[s(385)](p,10))),_0x7b415f+=_0x441289[s(283)+s(353)](56320+e[s(674)](1023,p))}}else e[s(1326)](_0x5a9e0b,_0x46a013,10),e[s(1478)](_0xb922fe,_0xb45a84,_0xc767ee);return{low:e[s(678)](h,e[s(1189)](m,28)),high:e.kdZoN(m>>>4,e.IMrAY(v,24)),unsigned:n}}}function mt(a,n){let s=t,l=e[s(425)](n[s(1152)],0),h=e[s(562)](n[s(1152)]>>>28,n[s(1509)]<<4)>>>0,m=n[s(1509)]>>>24,v=m===0?e[s(1598)](0,h)?e[s(1625)](l,16384)?e[s(1480)](l,128)?1:2:e[s(466)](l,2097152)?3:4:e[s(1488)](h,16384)?e[s(470)](h,128)?5:6:e[s(310)](h,2097152)?7:8:m<128?9:10,E=e.iDfMr(ie,a,v),p=a[s(1444)];switch(v){case 10:p[E+9]=e[s(425)](m,7)&1;case 9:p[e[s(1312)](E,8)]=e[s(839)](9,v)?128|m:127&m;case 8:p[e.EQEOX(E,7)]=e[s(723)](8,v)?e[s(615)](e[s(425)](h,21),128):e[s(963)](h>>>21,127);case 7:p[E+6]=e[s(580)](7,v)?e[s(889)](h>>>14,128):e[s(1626)](e[s(1531)](h,14),127);case 6:p[E+5]=v!==6?e[s(1622)](e.QdMZj(h,7),128):e.Xynmk(e.Nknbk(h,7),127);case 5:p[e[s(558)](E,4)]=e[s(244)](5,v)?128|h:e.Ijjpy(127,h);case 4:p[E+3]=e[s(248)](4,v)?e[s(1288)](e[s(1531)](l,21),128):e.iNgwD(e[s(425)](l,21),127);case 3:p[E+2]=e[s(1142)](3,v)?e[s(889)](e.bOiLs(l,14),128):l>>>14&127;case 2:p[e[s(518)](E,1)]=e.RxwcA(2,v)?e.pGjnd(l>>>7,128):e.Ijjpy(e.ZmDjf(l,7),127);case 1:p[E]=e[s(386)](1,v)?e.XlixA(128,l):e[s(702)](127,l)}}function sn(a){return e[t(493)](b,a)}function jt(a){return e[t(744)](S,a)}let on=65536,Xr=t(617),Ee=e.rxAfg(on,on),Ce=Ee*Ee,rr=e[t(211)](Ce,2),Be=String[t(1139)+"e"][t(561)+"At"];class ge{constructor(n,s,l){let h=t;this[h(809)]=!0,this.low=e[h(1302)](0,n),this.high=e.wBkWQ(0,s),this[h(642)]=!!l}static isLong(n){let s=t;return n&&e[s(238)](!0,n[s(809)])}static[t(645)](n,s,l){let h=t;return e[h(1570)]===e[h(322)]?this._socket[h(1682)]:new ge(n,s,l)}static[t(278)+"s"](n,s,l){let h=t;return l?ge[h(278)+"sLE"](n,s):ge[h(278)+h(1413)](n,s)}static fromBytesLE(n,s){let l=t;return new ge(e[l(217)](e.zivJg(e[l(889)](n[0],e[l(778)](n[1],8)),e[l(778)](n[2],16)),e[l(301)](n[3],24)),e.VGeVH(e[l(740)](n[4],e[l(837)](n[5],8)),e[l(778)](n[6],16))|e[l(1217)](n[7],24),s)}static[t(278)+"sBE"](n,s){let l=t;return new ge(e.qEMFr(e[l(387)](e[l(778)](n[4],24),e[l(837)](n[5],16)),n[6]<<8)|n[7],e[l(1502)](e[l(834)](e[l(1380)](n[0],24)|e[l(193)](n[1],16),e[l(1022)](n[2],8)),n[3]),s)}static[t(1629)](n){let s=t;return e.NKCVO(n,Xr)?Vd:new ge(e[s(480)](e.zivJg(e[s(945)](e[s(461)](Be[s(527)](n,0),e[s(1443)](Be[s(527)](n,1),8)),e.GkcqY(Be.call(n,2),16)),e[s(778)](Be[s(527)](n,3),24)),0),e[s(913)](e[s(1288)](Be[s(527)](n,4),e.GkcqY(Be[s(527)](n,5),8))|Be[s(527)](n,6)<<16|e[s(198)](Be[s(527)](n,7),24),0),!0)}[t(1644)](){let n=t;return String.fromCharCode(e[n(1246)](255,this[n(1152)]),e[n(425)](this[n(1152)],8)&255,e[n(1129)](e[n(1238)](this.low,16),255),e[n(1238)](this[n(1152)],24),e[n(710)](255,this[n(1509)]),e[n(425)](this[n(1509)],8)&255,e[n(680)](e.LIWBu(this.high,16),255),e[n(936)](this.high,24))}static[t(1134)+"er"](n,s=!0){let l=t;if(isNaN(n))return s?hp:Vd;if(s){if(e[l(1581)](n,Ce))return pp}else{if(e.KEffJ(n,-rr))return gp;if(e[l(342)](e[l(791)](n,1),rr))return xp}return ge[l(645)](e[l(1085)](n,Ee)|0,e.wBkWQ(e.WbIDn(n,Ee),0),s)}[t(1542)](){let n=t;return this[n(642)]?e.KabrI(e[n(753)](e.iPXxi(this[n(1509)],0),Ee),e[n(936)](this[n(1152)],0)):e.LofyP(this[n(1509)]*Ee,e[n(1531)](this[n(1152)],0))}[t(537)](){let n=t;return e[n(1598)](0,this.high)&&this[n(1152)]===0}[t(1397)](n){let s=t;ge.isLong(n)||(n=ge.fromNumber(n));let l=e.WcvqV(this[s(1509)],16),h=e[s(1224)](65535,this[s(1509)]),m=this[s(1152)]>>>16,v=e[s(1419)](65535,this[s(1152)]),E=e.lGbTy(n[s(1509)],16),p=e.TYjHR(65535,n[s(1509)]),A=n[s(1152)]>>>16,L=65535&n[s(1152)],N=0,U=0,Z=0,X=0;return X+=e[s(1088)](v,L),Z+=e[s(425)](X,16),X&=65535,Z+=e.rPaZr(m,A),U+=e.gwTeo(Z,16),Z&=65535,U+=e[s(277)](h,p),N+=e.RzcUE(U,16),U&=65535,N+=l+E,N&=65535,ge.fromBits(e[s(262)](e.eqXFW(Z,16),X),e.NlvEi(e.ofiEs(N,16),U),this[s(642)])}[t(1018)](n){let s=t;return ge[s(809)](n)||(n=ge[s(1134)+"er"](n)),e[s(248)](this[s(642)],n.unsigned)&&e.TgwcP(this.high,31)===1&&e.WkOHW(n[s(1509)]>>>31,1)?!1:e.zrFeY(this.high,n[s(1509)])&&e[s(1505)](this[s(1152)],n[s(1152)])}addOne(){let n=t;return this[n(1152)]===-1&&e[n(1274)](-1,this[n(1509)])?ge.fromBits(0,0,this[n(642)]):e[n(1620)](-1,this.low)?ge.fromBits(0,e.IpwEo(this[n(1509)],1),this[n(642)]):ge[n(645)](e.Cmsuv(this[n(1152)],1),this[n(1509)],this[n(642)])}[t(635)](n){let s=t;return n?this[s(1075)+"E"]():this[s(343)+"E"]()}toBytesLE(){let n=t,s={iuceg:function(l,h){return e.cmIGG(l,h)},wqflq:n(522)};if(e[n(1453)](e[n(1423)],e.kvmaZ)){let l=_0x483023.split(/\./)[n(1104)](v=>_0x3eab27(v)),h=[];return h[0]=_0x364a88(mkVeVy.iuceg(l[0],l[1])),h[1]=_0x236c5d(mkVeVy[n(173)](l[2],l[3])),[n(522),n(522),mkVeVy.wqflq,mkVeVy.wqflq,n(522),n(1053),h[0],h[1]].join("")}else{let l=this[n(1509)],h=this[n(1152)];return[e.WGGCl(255,h),e[n(1310)](e[n(594)](h,8),255),e[n(939)](e[n(697)](h,16),255),e[n(1406)](h,24),e[n(914)](255,l),e[n(1e3)](l,8)&255,e[n(665)](e[n(485)](l,16),255),l>>>24]}}[t(343)+"E"](){let n=t,s=this.high,l=this[n(1152)];return[e.WcvqV(s,24),e[n(480)](s,16)&255,e.QjqJE(e.WcvqV(s,8),255),e.OvulP(255,s),e[n(175)](l,24),e.WGCgj(e.QdMZj(l,16),255),e[n(965)](e.qjHaa(l,8),255),e.CJdfa(255,l)]}}let Vd=new ge(0,0,!1),hp=new ge(0,0,!0),xp=ge[t(645)](-1,2147483647,!1),pp=ge[t(645)](-1,-1,!0),gp=ge[t(645)](0,-2147483648,!1);var an=(function(a){let n=t,s=e.DfjfF.split("|"),l=0;for(;;){switch(s[l++]){case"0":a[a[e[n(1541)]]=5001]=e[n(1541)];continue;case"1":return a;case"2":a[a[e[n(1436)]]=5005]=e[n(1436)];continue;case"3":a[a[e[n(1694)]]=5003]=e[n(1694)];continue;case"4":a[a[e[n(255)]]=5004]=e[n(255)];continue;case"5":a[a[e[n(738)]]=5002]=e[n(738)];continue}break}})({});class ir{constructor(n){let s=t;if(e[s(681)](e[s(1525)],e.ZNYIs))this.type=n,this.target=null;else{let{enableAutoAck:l}=this._options,h=e[s(582)](_0x23d56d,_0x23e4ea[s(263)][s(285)],e[s(648)],"1"),m=_0x54232a(_0x50aff8[s(263)][s(285)],s(978),"1"),v=_0x1c6085[s(527)](this,_0x5077e9);if(e[s(1490)](l,h)){let{SeqID:E,LogID:p,service:A,LogIDNew:L,method:N}=_0x28f995.message;this._sendAck({SeqID:E,LogID:p,LogIDNew:L,service:A,method:N,headers:[{key:e[s(1268)],value:"1"},{key:e[s(206)],value:L||""},{key:e[s(951)],value:"0"}]})}m&&!v.isQoSAck&&this[s(1695)+s(1358)+s(201)](_0x3cbe72),e[s(1657)](_0x5c3844)}}}class Jd extends ir{constructor(n,s){let l=t;e[l(318)](e[l(769)],e[l(769)])?(this["_message"+l(548)][l(315)](_0x2e9cbb),this[l(1159)](e[l(1332)],_0x42b063)):(super(n),this[l(263)]=s&&s[l(263)]||null)}}class Zd extends ir{constructor(n,s){let l=t;super(n),this[l(821)]=s&&s[l(821)]||null,this[l(1498)]=s&&s[l(1498)]||0,this[l(1276)]=s&&s[l(1276)]||"",this[l(1316)]=s&&s[l(1316)]||0,this[l(263)]=s&&s[l(263)]||"",this.code=s&&s[l(601)]||5001}}class Yd extends ir{constructor(n,s){let l=t;super(n),this[l(601)]=s&&s.code||0,this.reason=s&&s[l(1307)]||"",this.wasClean=s&&s[l(508)]||!1,this.willReconnect=s&&s[l(1537)+"nnect"]||!1}}class Xd extends ir{constructor(n,s){let l=t;super(n),this[l(338)]=s&&s[l(338)]||null}}class Qd extends Xd{constructor(n,s){let l=t;super(n),this.data=s&&s[l(338)]||null,this[l(263)]=s&&s[l(263)]||null}}class el extends ir{constructor(n,s){let l=t;super(n),this[l(338)]=s&&s[l(338)]||null}}function ft(a,{message:n,code:s,error:l}){return new Zd(a,{message:n,code:s,error:l})}function wt(a,{code:n,reason:s,wasClean:l,willReconnect:h}){return new Yd(a,{code:n,reason:s,wasClean:l,willReconnect:h})}function tl(a,{data:n,message:s}){return new Qd(a,{data:n,message:s})}function nl(a,{data:n}){return new el(a,{data:n})}function ha(a,{message:n}){return new Jd(a,{message:n})}class rl{constructor(n,s){let l=t;this[l(366)+"s"]=n,this[l(1476)+"es"]=s,this[l(272)+"ndex"]=0,this[l(1492)+l(1006)+l(1510)+"t"]=0}[t(1669)+"pointCon"+t(1065)](){let n=t;this[n(272)+n(348)]=0,this[n(1492)+n(1006)+n(1510)+"t"]=0}resetTries(){let n=t;this[n(1492)+n(1006)+n(1510)+"t"]=0}[t(516)+"ntEndpoint"](){let n=t;return this[n(366)+"s"][this[n(272)+"ndex"]]}[t(516)+t(331)+"ntTriesC"+t(186)](){let n=t;return this[n(1492)+n(1006)+n(1510)+"t"]}[t(1130)+"chMaxTries"](){let n=t;return!!(this[n(272)+n(348)]>=this.endpoints.length||e[n(394)](this[n(272)+n(348)],e[n(1553)](this.endpoints[n(604)],1))&&e.nMsvY(this[n(1492)+n(1006)+n(1510)+"t"],this[n(1476)+"es"]))}[t(1500)+t(1539)+t(1272)+t(1590)+t(1327)](){let n=t;return e[n(612)](this[n(272)+n(348)],this[n(366)+"s"][n(604)])?!0:e[n(464)](this[n(1492)+n(1006)+n(1510)+"t"],this[n(1476)+"es"])}[t(245)+"ackupEnd"+t(997)+t(1126)+t(1555)](){let n=t;return this[n(1492)+n(1006)+"riesCount"]=1,this[n(272)+n(348)]++,this[n(366)+"s"][this[n(272)+n(348)]]}[t(516)+t(331)+t(404)+t(1240)](){let n=t;if(e[n(1448)](e.RoKzL,e[n(623)]))return this["currentE"+n(1006)+"riesCount"]++,this[n(516)+n(331)+"nt"]();{let s=this[n(1247)+"tManager"]?.[n(516)+n(331)+"nt"](),l=this[n(699)][n(1199)+n(768)+n(1119)](_0x2d2890[n(601)],_0x5946b9[n(1307)]);this[n(1695)+n(786)+n(219)](e.TRcAY(_0x25ffd9,n(647),{code:1006,reason:_0x4d29a8[n(1307)]||n(818)+n(444)+n(1370)+"wn reason, hostn"+n(1337)+s,willReconnect:l})),l&&this._connect();return}}}let sr=(e.xzrkK!=typeof globalThis&&e.FnOlo===globalThis[t(573)+t(1486)][t(287)]||e.xzrkK!=typeof window&&e[t(403)](t(1216),window[t(573)+"tor"][t(287)]))&&e[t(319)]("undefined",typeof document),Ln=e[t(319)](e[t(1249)],typeof globalThis)&&(e[t(1450)](e[t(519)],globalThis[t(573)+t(1486)][t(287)])||e[t(1455)]===globalThis["construc"+t(1486)].name)&&e[t(1068)](e[t(1249)],typeof tt),Qr=(e[t(1249)]!=typeof globalThis&&e[t(780)](e[t(519)],globalThis["construc"+t(1486)][t(287)])||e.Citbt(e.xzrkK,typeof globalThis)||e[t(1249)]!=typeof globalThis&&!!globalThis[t(877)+t(1169)])&&e.AGrcX(e[t(1249)],typeof wx),ei=e.AFVRt("undefined",typeof globalThis)&&(e[t(227)](e[t(1455)],globalThis[t(573)+"tor"][t(287)])||e.JGxvY(t(587)+t(1401)+"alScope",globalThis[t(573)+"tor"][t(287)])||e[t(1025)]===globalThis[t(573)+"tor"][t(287)])&&e[t(1314)](t(535)+"d",typeof self),mp=typeof globalThis<"u"&&e[t(519)]===globalThis["construc"+t(1486)][t(287)]&&e[t(536)](e[t(1249)],typeof global)&&e[t(190)](e[t(519)],global.constructor.name)&&e.asrGk(e[t(1249)],typeof process)&&!!process[t(1204)];class xa{constructor(){let n=t;this[n(1503)+"rs"]={}}[t(1245)](n,...s){let l=t,h=this[l(1503)+"rs"][n];if(h)h[l(306)]().forEach(m=>m.fn[l(270)](m[l(1146)],s));else if(e[l(1155)](e[l(1028)],n)&&!this.onerror){let m=s[l(604)]&&s[0];if(e[l(695)](m,Error))throw m;let v=new Error(l(1475)+"d error."+(m?e.DRROB(e.zrgQB(" (",m.message),")"):""));throw v[l(1128)]=m,m}return this}[t(576)](n,s){let l=t;if(e[l(534)](void 0,n))this[l(1503)+"rs"]={};else if(e[l(1155)](void 0,s))this[l(1503)+"rs"][n]=null;else if(e[l(929)]!==e[l(1145)]){let h=this._listeners[n];if(h)for(let m=0;e.XABoj(m,h[l(604)]);)e[l(1061)](h[m].fn,s)?h.splice(m,1):++m}else return this[l(592)][l(656)];return this}on(n,s,l){let h=t;return(this[h(1503)+"rs"][n]||(this._listeners[n]=[]))[h(315)]({fn:s,ctx:l||this}),this}}class wp extends xa{[t(1400)+t(231)+t(513)](n){let s=t;return n.errMsg||n.errNo?(s(1321)+" "+(n[s(1141)]||"")+s(1171)+(n[s(1374)]||""))[s(857)]():JSON[s(917)+"y"](n)}constructor(n,s,l){let h=t;super(),this[h(930)]=null,Qr&&wx["connectS"+h(909)]&&(this._socket=wx[h(196)+h(909)]({url:n,protocols:s,header:l,fail:this[h(1513)+h(964)+"lHandler"][h(1375)](this),success:this[h(1513)+"ocketSuc"+h(1696)+h(178)].bind(this)})),Ln&&tt[h(196)+h(909)]&&(this[h(930)]=tt[h(196)+"ocket"]({url:n,protocols:s,header:l,fail:this[h(1513)+h(964)+h(357)].bind(this),success:this[h(1513)+h(934)+"cessHand"+h(178)][h(1375)](this)}))}[t(1513)+t(934)+t(1696)+t(178)](){let n=t;Promise[n(701)]().then(()=>{let s=n;this[s(1208)+s(766)]()})}[t(1513)+t(964)+t(357)](n){let s=t,l={Aasjz:function(h,m){return e[j(998)](h,m)},EkhlV:function(h,m){return e[j(815)](h,m)},KkTMB:e[s(1562)],lkvlD:function(h,m){return e[s(326)](h,m)},CpfQh:e[s(651)],XbDds:function(h,m,v){return h(m,v)},CVzcQ:e[s(1028)],SJHmz:function(h,m,v){return e[s(397)](h,m,v)},LCSwK:e[s(1677)]};Promise[s(701)]()[s(260)](()=>{let h=s;if(l.CpfQh===l.CpfQh){let m=l[h(1267)](ft,l[h(627)],{message:this[h(1400)+h(231)+h(513)](n)});this[h(1245)](l[h(627)],m);let v=l[h(1586)](wt,l[h(1655)],{reason:this[h(1400)+"rrorMess"+h(513)](n)});this.emit(h(647),v)}else{if(_0x5f3158 instanceof _0x415e61){if(coQpJV[h(540)](_0x4646af,h(351)))return _0x1a7a0a[h(247)](_0xcfd10);if(coQpJV[h(1640)](_0x3b401f,coQpJV[h(233)]))return _0x531316["objectSt"+h(452)]||_0x2bf37a[h(247)](_0x5a7364);if(coQpJV[h(1640)](_0x4e23dc,h(1459)))return _0x589e38[h(1004)+"oreNames"][1]?void 0:_0x5c4247[h(1004)+"ore"](_0x2c41bc[h(1004)+"oreNames"][0])}return coQpJV[h(622)](_0x69181d,_0x4d81bd[_0x4b11c3])}})}[t(1208)+"steners"](){let n=t,s={KyrhG:e[n(1028)],jBSDu:function(l,h,m){return e[n(1412)](l,h,m)}};this[n(930)][n(987)](l=>{let h=n;this[h(1245)](e.gcFJb,e[h(630)](nl,e[h(923)],{...l,data:l[h(1141)]||""}))}),this[n(930)][n(767)](l=>{let h=n;this[h(1245)](e[h(1677)],e[h(1237)](wt,e[h(1677)],{...l}))}),this[n(930)][n(1649)+"e"](l=>{let h=n;this[h(1245)](e[h(191)],e[h(725)](tl,h(263),{...l}))}),this[n(930)][n(1160)](l=>{let h=n;this.emit(s[h(724)],s.jBSDu(ft,s.KyrhG,{...l,message:l[h(1141)]||""}))})}[t(379)](n){let s=t;if(e[s(359)](n,Uint8Array))if(e[s(1346)](e[s(1637)],e[s(733)])){let l=n[s(989)][s(306)](n.byteOffset,e[s(932)](n[s(607)+"th"],n.byteOffset));this[s(930)]&&this[s(930)][s(379)]({data:l,fail:h=>{let m=s;this[m(1245)](e.vJwmP,ft(e[m(1028)],{message:this[m(1400)+m(231)+m(513)](h)}))}})}else return!!_0x19e9b7?.[s(1010)](l=>l[s(346)]===_0x183156&&l[s(1007)]===_0x455195);else this._socket&&this[s(930)][s(379)]({data:n,fail:l=>{let h=s;this[h(1245)]("error",ft(h(821),{message:this["_formatE"+h(231)+"age"](l)}))}})}close(n,s){let l=t;this._socket&&this._socket[l(647)]({code:n,reason:s})}addEventListener(n,s){this.on(n,s)}[t(599)+t(1100)+t(1534)](n,s){this[t(576)](n,s)}get[t(1676)+"te"](){let n=t;return this[n(930)][n(1676)+"te"]}get[t(1195)+"pe"](){let n=t;return this[n(930)][n(1195)+"pe"]}set[t(1195)+"pe"](n){}get url(){let n=t;if(e[n(1683)](e[n(1297)],n(1501)))return this[n(930)][n(1682)];this[n(1253)+"er"]&&_0x22be55[n(599)+n(1100)+n(1534)](e[n(698)],this[n(388)+n(271)]),this[n(1253)+"er"]&&_0x20cc19[n(599)+n(1100)+n(1534)](e[n(1285)],this[n(388)+n(685)]),this[n(1253)+"er"]&&_0x516fbe[n(599)+"entListe"+n(1534)](e[n(584)],this[n(810)+"ageHide"]),this[n(1253)+"er"]&&_0x567c4d[n(599)+n(1100)+n(1534)](e[n(1495)],this._handlePageShow)}get[t(230)](){return this[t(930)].protocol}get[t(1351)+"ns"](){let n=t;return this._socket[n(1351)+"ns"]}get[t(812)+t(416)](){return 0}}function _p(a,n){let s=t;if(e[s(723)](s(794),s(1386))){if(n)return new n(a[s(1682)],a[s(230)]);if(e[s(215)](Qr,Ln))return new wp(a[s(1682)],a[s(230)],a[s(285)]);if(e[s(1182)](sr,ei)&&e[s(1249)]!=typeof WebSocket&&WebSocket)return new WebSocket(a[s(1682)],a[s(230)+"s"])}else this.endpoints=_0x178141,this[s(1476)+"es"]=_0x4ba781,this[s(272)+"ndex"]=0,this[s(1492)+"ndpointT"+s(1510)+"t"]=0}function yp(a){let n=t;return!!(a||Qr&&wx[n(196)+n(909)]||Ln&&tt["connectS"+n(909)]||e[n(1200)](sr,ei)&&e[n(1068)](e.xzrkK,typeof WebSocket)&&WebSocket)}function il(a,n,s){let l=-1;async function h(m){let v=j;return e[v(180)](m,l)?Promise[v(1587)](new Error(e[v(1577)])):(l=m,m===s[v(604)]?Promise[v(701)]():s[m].bind(a)(n,h.bind(null,e[v(741)](m,1))))}h(0)}function sl(a){let n=t,s=0,l=0;for(let h=0;h<a[n(604)];++h)l=a[n(561)+"At"](h),e[n(976)](l,128)?s+=1:e[n(670)](l,2048)?s+=2:e[n(1474)](e[n(1343)](64512,l),55296)&&e[n(369)](e.fvzRM(64512,a[n(561)+"At"](e[n(899)](h,1))),56320)?(++h,s+=4):s+=3;return s}function ol(a,n,s){let l=t;if(e[l(470)](s-n,1))return"";let h="";for(let m=n;e.XABoj(m,s);){let v=a[m++];if(e.ugcxZ(v,127))h+=String[l(283)+l(353)](v);else if(e[l(1017)](v,192)&&e.uHZYw(v,224))h+=String[l(283)+"Code"](e[l(1222)](e.gaSCI(e.OCDFM(31,v),6),63&a[m++]));else if(e[l(842)](v,224)&&e[l(1193)](v,240))h+=String[l(283)+"Code"](e.ZNWAU(e[l(945)](e[l(1217)](15&v,12),(63&a[m++])<<6),63&a[m++]));else if(e[l(1015)](v,240))if(e[l(1175)](e[l(883)],e.lkOXG)){let E=e[l(1072)](e[l(945)](e[l(401)](e.Gtupb(e.bGFRV(e[l(1129)](7,v),18),e[l(1241)](63,a[m++])<<12),e.oSsAx(e[l(1417)](63,a[m++]),6)),63&a[m++]),65536);h+=String[l(283)+l(353)](e[l(1113)](55296,e[l(385)](E,10))),h+=String[l(283)+"Code"](e[l(297)](56320,e[l(1151)](1023,E)))}else this[l(1122)+l(1342)+l(602)]=_0x4ebabc,_0x454afb?this[l(388)+"nLine"]():this[l(388)+"ffLine"]()}return h}function pa(a,n,s){let l=t,h=s,m,v;for(let E=0;e[l(1079)](E,a.length);++E)if(m=a[l(561)+"At"](E),m<128)n[s++]=m;else if(e[l(1623)](m,2048))n[s++]=e.WgDVj(m>>6,192),n[s++]=e[l(838)](e[l(1170)](63,m),128);else if(e.PXrDr(e[l(1662)](64512,m),55296)&&e.kBJwc(64512&(v=a[l(561)+"At"](e.LofyP(E,1))),56320)){let p=e[l(1092)][l(521)]("|"),A=0;for(;;){switch(p[A++]){case"0":++E;continue;case"1":n[s++]=e[l(579)](63,m)|128;continue;case"2":n[s++]=e[l(1622)](e[l(1184)](m,18),240);continue;case"3":n[s++]=e[l(966)](e[l(876)](m,6)&63,128);continue;case"4":n[s++]=e[l(1121)](e[l(644)](e[l(1184)](m,12),63),128);continue;case"5":m=e[l(1407)](e[l(791)](65536,e[l(914)](1023,m)<<10),e[l(965)](1023,v));continue}break}}else n[s++]=e[l(1319)](e[l(1220)](m,12),224),n[s++]=e[l(1481)](m>>6,63)|128,n[s++]=e.LMTRc(e[l(663)](63,m),128);return e[l(688)](s,h)}async function al(a){let n=t;if(e[n(1592)]("string",typeof a))if(n(424)!==e[n(1190)]){let s=new Uint8Array(sl(a));return e[n(1091)](pa,a,s,0),s}else return this._ws?this[n(1512)].url:this[n(1604)];return e[n(532)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(989)],a[n(961)+"et"],a[n(607)+"th"])}function bp(a){let n=t;try{return n(221)!=typeof a&&(a instanceof ArrayBuffer||a[n(989)]&&a[n(989)]instanceof ArrayBuffer)||e[n(319)](e.MSQSQ,typeof a)?"":(JSON[n(655)](a),"applicat"+n(760))}catch{return e.MSQSQ==typeof a?n(509)+n(890)+n(1659):""}}let Ep=(a,n)=>{let s=t;switch(a){case"boe":case e[s(1273)]:return{["x-use-"+a]:1,"x-tt-env":n};default:return{}}};class vp{constructor(n){let s=t;this["maxLossC"+s(186)]=n,this[s(1353)]=0}[t(618)](){let n=t;this[n(1353)]++}[t(1130)+t(282)+"nt"](){let n=t;return this[n(1353)]>=this[n(427)+"ount"]}[t(916)+t(1203)](n=0){let s=t;if(e[s(726)](e.ZlhKu,e[s(1001)]))return _0x2020d5[s(701)]();this.maxLossCount=n,this[s(1353)]=0}}async function Sp(a){return new Promise(n=>{let s=j,l={VUpEb:function(h,m){return e[j(620)](h,m)},KPJWF:e[s(276)],zjKkg:e[s(1284)],FeDay:function(h){return e[s(941)](h)}};if(!sr)return e[s(620)](n,e.gXVox);try{let h=document["createEl"+s(347)](e[s(182)]);window[s(657)+s(1693)]=m=>{let v=s;document[v(1549)][v(364)+"ild"](h),window["frontier"+v(1693)]=void 0,l.VUpEb(n,m&&m[v(1168)]||l[v(1670)])},h[s(1667)]=e[s(549)],h[s(273)]=e[s(932)](a.replace(/^ws/,e[s(330)]),s(915)+"ack=frontierJSONP");try{document[s(1549)][s(919)+s(1674)](h)}catch{e[s(991)]("Yhnqg",s(251))?(_0x3c7d18(_0x1ea439[s(821)]||new _0x299c5a("AbortError",GhNUDO.zjKkg)),GhNUDO[s(1504)](_0x1fb0d7)):document[s(1549)][s(364)+s(1674)](h)}}catch{window[s(657)+"JSONP"]=void 0,e[s(493)](n,e.gXVox)}})}function cn(a,n,s){let l=t;return!!a?.[l(1010)](h=>h[l(346)]===n&&h[l(1007)]===s)}function or(a,n){let s=t;return a?.find(l=>l[s(346)]===n)?.value}let ga=null;async function Ip(){let a=t;return ga||(ga=Promise[a(701)]()[a(260)](Gt[a(1375)](Gt,a(1135)))),ga}class Ap extends xa{constructor(n,s){let l=t;super(),this[l(728)]=n,this[l(1071)]=s,this._qosDB=void 0,this[l(686)+l(321)]=null}async[t(488)](){await this[t(887)]()}async[t(887)](){let n=t,s={mcPIc:e[n(1005)],WFcpT:function(l,h,m,v){return e.ePMrP(l,h,m,v)},GAdOT:"name",RTDmo:function(l,h,m,v){return e[n(1031)](l,h,m,v)},bjtow:function(l,h,m,v){return e[n(582)](l,h,m,v)},hVLFt:e[n(632)],SSlox:e[n(415)]};if(e.OfSpC(e[n(1030)],e[n(782)])){let l=s[n(1666)].split("|"),h=0;for(;;){switch(l[h++]){case"0":_0x1a1954=s[n(1617)](_0x2fe18,_0x328523[n(888)+n(1020)],_0x445c9e,_0x12639d);continue;case"1":_0x4e50a2=s[n(1617)](_0x80acdf,_0x548f6e[n(1134)+"er"](_0x5bc663.cursor||_0x5685f1),_0x323b1b,_0x84ec13);continue;case"2":_0xecf185[n(484)](s[n(1027)],_0x571481);continue;case"3":_0xc92b5f=s[n(1398)](_0x269a32,_0x4111fd[_0x3aae19["cursor_n"+n(1020)]],_0x42f31f,_0x36b499);continue;case"4":_0x5649ea[n(484)](n(293),_0x283849);continue;case"5":_0x498b21[n(484)](n(266)+n(586),_0x357c21,_0x14cac8[n(293)]);continue;case"6":_0xfd48fc=s.WFcpT(_0x879eb4,_0x2f0df9,_0x367eb0,_0x13614b.service||0);continue;case"7":_0x39bf0a.log(n(897),_0x31937e);continue;case"8":_0x404f57=s[n(813)](_0x1f0f31,0,_0x3ebffa,_0x22f853);continue;case"9":_0x5f5a02[n(484)](s[n(372)],_0x249b52);continue;case"10":_0x4c3d99.log(s.SSlox,_0x1db9f8);continue}break}}else{if(this[n(592)])return;if(this["_initPro"+n(321)])return this[n(686)+n(321)];try{let l=this[n(728)],h=this._keyPath;this["_initPro"+n(321)]=(async()=>{let m=n;if(e[m(726)](e[m(802)],m(1192)))return this[m(592)]?.[m(639)]({message_id:_0x181d26,timestamp:_0x2f1b45});{let{openDB:v}=await e[m(988)](Ip);this[m(592)]=await e.KtNKX(v,"frontier_"+l,1,{upgrade(E){E[m(225)+"jectStore"](l,{keyPath:h})}})}})(),await this[n(686)+n(321)]}catch(l){if(e[n(950)](e[n(1177)],e[n(1601)]))console[n(484)](l);else return new _0x131444(_0x4fc96,{message:_0x368b81,code:_0x335856,error:_0x530a93})}finally{this[n(686)+n(321)]=null}}}async[t(247)](n){let s=t;try{return await this._init(),this[s(592)]?.[s(247)](this[s(728)],n)}catch(l){e[s(171)]===e.oFHVP?console[s(484)](l):(this[s(1122)+"igatorOn"+s(602)]=_0x1b10d2,_0x238295?this[s(388)+s(271)]():this[s(388)+s(685)]())}}async[t(639)](n,s){let l=t,h={GiYFJ:function(m,v){return e.DepQt(m,v)}};if(l(1215)===e.eRtjJ){if(OjIatS.GiYFJ(_0x1658fc,_0xcd1b1d))return _0xfe5767}else return await this[l(887)](),this[l(592)]?.[l(1679)](this._dbName,n)}async del(n){let s=t;try{return await this[s(887)](),this._qosDB?.[s(1298)](this[s(728)],n)}catch(l){e[s(823)](e.erXcA,s(352))?(this[s(1512)]&&this[s(1512)][s(379)](_0x4a43de),this["_message"+s(548)][_0x161b39]=null):console[s(484)](l)}}async[t(246)](){let n=t;try{return await this[n(887)](),this[n(592)]?.[n(246)](this[n(728)])}catch(s){console[n(484)](s)}}async keys(){let n=t;return await this[n(887)](),this[n(592)]?.getAllKeys(this[n(728)])}async[t(242)](){let n=t;return await this[n(887)](),this[n(592)]?.[n(242)](this._dbName)}async[t(1579)](){let n=t;try{this[n(592)]?.[n(647)](),this._qosDB=void 0}catch(s){console[n(484)](s)}}get[t(656)](){let n=t;try{return!!this[n(592)]}catch(s){return e.aEGrK(e[n(944)],n(457))?_0x54751c.bytes[_0x2a00e0(_0x3d3973,1)]:(console.log(s),!1)}}}class Tp{constructor(n,s){let l=t;this._DBName=n,this[l(1445)]=s,this[l(592)]=localStorage}async[t(488)](){}get[t(1671)](){let n=t;return n(657)+"_"+this[n(1594)]}async[t(247)](n){let s=t,l=this._qosDB[s(993)](this[s(1671)]);return JSON[s(655)](e[s(1182)](l,"{}"))[n]}async[t(639)](n,s){let l=t,h=this._qosDB[l(993)](this[l(1671)]),m=JSON.parse(e[l(215)](h,"{}"));return m[s||n[this[l(1445)]]]=n,this[l(592)][l(777)](this[l(1671)],JSON[l(917)+"y"](m)),s||n[this[l(1445)]]}async del(n){let s=t,l=this[s(592)][s(993)](this[s(1671)]),h=JSON[s(655)](l||"{}");return h[n]=void 0,this[s(592)][s(777)](this[s(1671)],JSON[s(917)+"y"](h))}async[t(246)](){let n=t;return this[n(592)][n(246)]()}async[t(1333)](){let n=t,s=this[n(592)][n(993)](this._prefix),l=JSON[n(655)](e[n(215)](s,"{}"));return Object[n(1333)](l)}async[t(242)](){let n=t,s=this._qosDB.getItem(this[n(1671)]),l=JSON[n(655)](e[n(1200)](s,"{}"));return Object[n(679)](l)}[t(1579)](){return Promise[t(701)]()}get[t(656)](){let n=t,s={bSBHe:function(l,h){return e[j(1418)](l,h)},bsnFw:function(l,h){return l|h}};if(e[n(1008)](n(1347),e[n(185)]))return!!this[n(592)];this[n(809)]=!0,this.low=AJsPiW[n(1226)](0,_0x3b7cda),this[n(1509)]=AJsPiW[n(1596)](0,_0xe16a5f),this[n(642)]=!!_0x30aa84}}class Rp{constructor(n,s){let l=t;this[l(1594)]=n,this[l(1445)]=s,this[l(592)]=Ln?tt:Qr?wx:null}async[t(488)](){}get[t(1671)](){let n=t;return n(657)+"_"+this[n(1594)]}async[t(247)](n){let s=t,l=this[s(592)][s(1396)+s(783)](this[s(1671)]);return JSON[s(655)](l||"{}")[n]}async set(n,s){let l=t,h=this[l(592)][l(1396)+l(783)](this._prefix),m=JSON.parse(e[l(419)](h,"{}"));return m[s||n[this[l(1445)]]]=n,this[l(592)]["setStora"+l(783)](this[l(1671)],JSON[l(917)+"y"](m)),s||n[this[l(1445)]]}async[t(1350)](n){let s=t,l=this[s(592)]["getStora"+s(783)](this[s(1671)]),h=JSON[s(655)](e[s(1470)](l,"{}"));return h[n]=void 0,this[s(592)][s(1264)+s(783)](this._prefix,JSON[s(917)+"y"](h))}async[t(246)](){let n=t;return this[n(592)][n(1144)+"rageSync"]()}async[t(1333)](){let n=t;if(e[n(1547)]!==n(1263)){let s=this[n(592)][n(1396)+n(1567)+"nc"](this[n(1671)]),l=JSON[n(655)](e.hQNvh(s,"{}"));return Object[n(1333)](l)}else _0x105487=_0x3fc725&&e[n(544)](e[n(756)],_0x43b066[n(230)])?e[n(481)]:e.lYxGv,_0x26478c=_0xa6da54[n(329)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),_0x1c4e6f=/^wss(.*:\/\/)/[n(1105)](_0x28cae9)?_0x1e18b3:""+_0x135ac4+_0x3f4b06}async getAll(){let n=t,s=this[n(592)][n(1396)+n(1567)+"nc"](this._prefix),l=JSON[n(655)](s||"{}");return Object.values(l)}[t(1579)](){return Promise[t(701)]()}get[t(656)](){let n=t,s={OsPyK:function(l,h){return l(h)},YAxpZ:function(l,h){return e.uTMCi(l,h)}};if(e.AMeOr(n(1373),e[n(867)]))return!!this._qosDB;{let l=MbEZlj.OsPyK(_0x1e9ae7,_0x450cf2),h=_0x4840ab.limit;return _0x47ea2c[n(1325)]=MbEZlj[n(257)](_0xb005c6[n(572)],l),h}}}function cl(a,n){let s=t;if(e[s(1266)](s(953),e[s(1059)])){if(Ln||Ln)return new Rp(a,n);if(e[s(1089)](sr,ei)&&e.AFVRt(s(535)+"d",typeof indexedDB))return new Ap(a,n);if(e[s(468)](sr,ei)&&s(535)+"d"!=typeof localStorage)return new Tp(a,n);throw new Error("init QoSDB failed")}else return!0}class kp{constructor(){let n=t;if(e.RxwcA(n(476),n(476)))return this[n(272)+"ndex"]>=this[n(366)+"s"][n(604)]||this[n(272)+n(348)]===this.endpoints[n(604)]-1&&this["currentE"+n(1006)+n(1510)+"t"]===this[n(1476)+"es"];this[n(1454)+n(1023)+"Id"]=null,this[n(1454)+"l"]=36e5,this._qosDB=e.EZPdR(cl,e[n(1150)],e[n(570)])}async["_interva"+t(393)](){let n=t;clearInterval(this[n(1454)+"lTimeoutId"]),this[n(1454)+n(1023)+"Id"]=setInterval(()=>{this["flushExp"+n(693)]()},this[n(1454)+"l"])}async[t(488)](){let n=t,s={gVeCA:function(l,h){return e[j(1480)](l,h)},dqKFh:function(l,h){return l!==h}};if(e[n(1303)]("cdkyw",e[n(874)])){let l=_0x4967ff.split(":");_0x35ca26&&(_0x70c7ee=l[n(604)]),_0x59887e+=l[n(604)];for(let h=0;HEVkPM[n(1335)](h,l.length);h++)if(HEVkPM[n(1198)](4,l[h][n(604)])){let m=_0x5cd6bc[n(873)+"g"](0,4-l[h][n(604)]),v=m[n(886)](l[h]);_0x41bc07[n(315)](v)}else _0x9ec205[n(315)](l[h]);_0xa4dd09=!1}else await this[n(592)][n(488)]().then(()=>{let l=n;this[l(1454)+l(393)]()})}async[t(1433)+"ired"](){let n=t,s={LOKiF:function(m,v){return e[j(721)](m,v)},Tzyxy:e[n(350)]};(await this[n(592)]?.[n(242)]()||[])[n(506)](({timestamp:m})=>m<Date[n(1165)]())[n(1295)](m=>{let v=n;if(s.LOKiF(s[v(566)],s.Tzyxy))this[v(592)]?.del(m[v(1026)+"id"]);else try{this[v(1512)]&&this[v(1512)][v(647)](_0x52c258,_0x121bac)}catch{}})}async del(n){let s=t;return this[s(592)]?.[s(1350)](n)}async set(n,s){let l=t;return e[l(1330)](l(1090),e[l(868)])?((this._listeners[_0x3cf350]||(this[l(1503)+"rs"][_0x4f98b3]=[]))[l(315)]({fn:_0x276107,ctx:_0x59b195||this}),this):this[l(592)]?.set({message_id:n,timestamp:s})}async[t(247)](n){let s=t;return this[s(592)]?.[s(247)](n)}async[t(1579)](){let n=t;if(e[n(984)](e[n(1127)],n(560)))e[n(1323)](clearInterval,this[n(1454)+n(1023)+"Id"]),await this[n(592)]?.closeDB();else return _0x5d3260[_0x1fc787]=_0x224441,!0}get[t(656)](){return this[t(592)]?.isReady}}function ma(a){let n=t,s=!!this[n(699)].enableQoS;if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=cn(a[n(263)][n(285)],e[n(881)],"2"),h=l&&e.cwYiD(cn,a.message[n(285)],e.fMGCI,"1"),m=l&&e[n(582)](cn,a[n(263)][n(285)],e[n(1643)],"1"),v=m?e[n(1408)](or,a.message[n(285)],e[n(1523)])?.[n(521)](",")[n(506)](Boolean)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:h,isAckCleanupMessage:m,ackMsgIds:v}}async function dl(){let a=t;return this["_QoSMana"+a(1345)]||(this[a(259)+"ger"]=new kp),this["_QoSMana"+a(1345)][a(656)]||await this[a(259)+"ger"][a(488)](),this[a(259)+a(1345)]}async function Cp(a,n){let s=t,{enableAutoAck:l}=this[s(699)],h=e[s(554)](cn,a[s(263)][s(285)],e[s(648)],"1"),m=cn(a[s(263)][s(285)],e.gvdwl,"1"),v=ma.call(this,a);if(e[s(1490)](l,h)){let{SeqID:E,LogID:p,service:A,LogIDNew:L,method:N}=a[s(263)];this[s(571)]({SeqID:E,LogID:p,LogIDNew:L,service:A,method:N,headers:[{key:e[s(1268)],value:"1"},{key:e[s(206)],value:e.UFygH(L,"")},{key:s(1123),value:"0"}]})}m&&!v[s(772)]&&this[s(1695)+s(1358)+s(201)](a),e[s(1317)](n)}async function Dp(a,n){let s=t;e.UpuWH!==s(541)?(this[s(1159)](s(1328),a[s(263)]),e[s(631)](n)):(this._isInit=!0,this[s(1101)]())}async function Pp(a,n){let s=t,l=e.OuTWH(sn,await e[s(1432)](al,a.data));try{if(e[s(532)](l[s(1482)],Uint8Array)){let h=e[s(532)](this[s(699)][s(1602)+s(703)],Object)?{force:!!this[s(699)]["payloadE"+s(703)].force,encoding:this[s(699)][s(1602)+s(703)][s(832)]?this[s(699)][s(1602)+"ncoding"].encoding.replace(/\s/g,"")[s(673)+s(1517)]():""}:{force:!1,encoding:this[s(699)]["payloadE"+s(703)]?this[s(699)][s(1602)+s(703)][s(329)](/\s/g,"")[s(673)+"ase"]():""},m=l[s(1602)+"ncoding"]?l[s(1602)+s(703)][s(329)](/\s/g,"")[s(673)+s(1517)]():"",v=this[s(699)][s(1287)+s(1118)]instanceof Object?{force:!!this[s(699)]["payloadT"+s(1118)][s(1322)],type:this._options[s(1287)+s(1118)][s(1667)]?this[s(699)][s(1287)+s(1118)][s(1667)].replace(/\s/g,"")[s(673)+s(1517)]():""}:{force:!1,type:this._options[s(1287)+"ype"]?this[s(699)][s(1287)+s(1118)].replace(/\s/g,"").toLowerCase():""},E=l[s(1287)+"ype"]?l[s(1287)+s(1118)][s(329)](/\s/g,"").toLowerCase():"",p=v.force?v[s(1667)]:E||v[s(1667)],A=h[s(1322)]?h[s(832)]:m||h[s(832)],L=[e[s(1049)],e[s(1265)],e.DPhSq,s(221)],N=[e[s(1611)],s(451)];this._options[s(341)+"ansformTextPayload"]&&L[s(563)](p)&&(!A||N[s(563)](A))?l["textPayl"+s(922)]=ol(l[s(1482)],0,l[s(1482)][s(607)+"th"]):l[s(1654)+s(922)]=""}else l[s(1654)+"oad"]=""}catch(h){l[s(1654)+s(922)]="",console.log(h)}a[s(263)]=l,e[s(1317)](n)}function Op(a,n,s){let l={CwsFe:function(p,A){return e.gGwXX(p,A)},xlmvY:function(p,A){return p(A)},uzMTw:function(p,A){return e[j(212)](p,A)},NpMAu:function(p,A){return e[j(1323)](p,A)},tkuyT:function(p,A){return e.rDqOI(p,A)},Okbtn:function(p,A){return e[j(1242)](p,A)},fyVUA:function(p,A){return e[j(523)](p,A)}},h=e.ddYRw(s,8192),m=h>>>1,v=null,E=h;return function(p){let A=j;if(p<1||l[A(1052)](p,m))return l[A(1661)](a,p);l[A(189)](E+p,h)&&(v=l.NpMAu(a,h),E=0);let L=n[A(527)](v,E,E+=p);return l[A(1223)](7,E)&&(E=l.Okbtn(l[A(542)](7,E),1)),L}}let Lp=4294967295;function Np(a,n,s){let l=t;return e[l(497)](RangeError,e.pTBax(e[l(395)](e.rcCgp(e[l(713)],a),l(1379))+(n||1)+e.AEmDm,s))}function Mp(a,n,s){let l=t;if(e[l(1002)](s,Lp))throw new Error(e.aUEjj);let h=3;for(;e[l(842)](h,0);){let m=e[l(878)](255,s);e.TuoRW(_a,m,a,e.LnfcJ(n,h)),s>>>=8,h--}return n+4}function Bp(a,n){let s=t,l=0,h=n,m=e[s(395)](n,4);for(;e[s(310)](h,m);){let{value:v,offset:E}=e[s(459)](wa,a,h);h=E,l=e[s(261)](l<<8,0),l+=v}return{value:l,offset:m}}function Fp(a,n,s){let l=t,h=(l(746)+"2")[l(521)]("|"),m=0;for(;;){switch(h[m++]){case"0":if(!a)return s;continue;case"1":if(n[l(349)])return e.RSmnd(n[l(349)](a,s),s);continue;case"2":return pa(a,n,s)+s;case"3":if(n[l(1261)+"e"])return e.rPaZr(n[l(1261)+"e"](a,s),s);continue;case"4":if(e[l(748)](a.length,40))return e.uTMCi(pa(a,n,s),s);continue}break}}function zp(a,n){let s=t,l=new ge(e[s(1250)](e.bZtKA(e.xDTps(e.yLEay(a[e[s(770)](n,4)],24),e[s(879)](a[e[s(716)](n,5)],16)),a[e[s(232)](n,6)]<<8),a[n+7]),e.cxLPI(e[s(1502)](e.hzqWF(a[e[s(1088)](n,0)],24),e[s(1685)](a[n+1],16))|e[s(851)](a[n+2],8),a[e[s(907)](n,3)]),!0);return n+=8,{value:l,offset:e[s(716)](n,8)}}function Up(a,n,s){let l=t,h=a[l(1152)],m=a[l(1509)];return n[s]=e.piIZs(m,24),n[e.DAFqy(s,1)]=e.raoxX(e[l(507)](m,16),255),n[s+2]=e[l(546)](m>>>8,255),n[e[l(1338)](s,3)]=255&m,n[s+4]=e[l(1406)](h,24),n[s+5]=e[l(600)](e[l(1574)](h,16),255),n[e[l(420)](s,6)]=e[l(358)](h>>>8,255),n[e[l(899)](s,7)]=e[l(694)](255,h),s+=8,s}function wa(a,n){let s=t;return a[s(1136)+"8"]?{value:a[s(1136)+"8"](n),offset:n+1}:{value:255&a[n],offset:e[s(1420)](n,1)}}function _a(a,n,s){let l=t;return n[l(1037)+"t8"]?n[l(1037)+"t8"](a,s):n[s]=e[l(1170)](255,a),s+1}let Gp=function(a){return new Uint8Array(a)},Hp=e[t(234)](e[t(1249)],typeof Buffer)?Buffer[t(590)+t(1630)]:e[t(1524)](Op,Gp,Uint8Array.prototype[t(1269)]),jp=16,ya=32;function qp(a){let n=t,s=0,l={};for(let h=0;e[n(826)](h,a[n(604)]);h++)e[n(1012)]("gSJPO",e[n(754)])?_0x557c6a(this,_0xb932c6,[_0x28f287,_0x1889cf,_0x5361e2,_0x5c1e50,_0x1661a2,_0x15b857]):(l[a[h][n(888)+n(1020)]]=sl(a[h].cursor_name),s+=14+l[a[h][n(888)+n(1020)]]);return[s,l]}function ll(a,n,s){let l=t;if(e.JFIxc!==e.JFIxc){let h=_0x31dfed[l(1699)]();return h?(h[l(572)]=h.limit=0,h):{bytes:new _0x242cef(64),offset:0,limit:0}}else{let[h,m]=qp(a),v=e[l(744)](Hp,h),E=0;return a[l(1295)](p=>{let A=l,L=e[A(567)][A(521)]("|"),N=0;for(;;){switch(L[N++]){case"0":E=e[A(1091)](Up,ge[A(1134)+"er"](p.cursor||n),v,E);continue;case"1":E=e[A(1031)](Fp,p[A(888)+A(1020)],v,E);continue;case"2":console.log(e.bqOLx,E);continue;case"3":E=_a(m[p.cursor_name],v,E);continue;case"4":console[A(484)](e.enEek,E);continue;case"5":console[A(484)](e[A(1668)],E);continue;case"6":console[A(484)](e.iufXZ,E);continue;case"7":console[A(484)](e.fDxFa,p,p[A(293)]);continue;case"8":E=e[A(533)](_a,0,v,E);continue;case"9":E=e.fXoAH(Mp,v,E,p[A(293)]||0);continue;case"10":console[A(484)](e[A(632)],E);continue}break}}),{frameType:ya,headers:[{key:e.FYFVo,value:s}],payload:v}}}function Wp(a){let n=t,s={dWRGY:function(l,h,m){return l(h,m)}};if(e[n(1311)](e[n(1094)],e[n(863)])){this["_clearPi"+n(1584)](),this["_pingPon"+n(1388)+"Id"]=s.dWRGY(_0x30ac92,this[n(316)].bind(this),this[n(699)][n(589)+n(1521)]);return}else{let l=0,h=[];for(;e[n(1289)](l,a[n(607)+"th"]);)if(e.TFOLD(e.IlEDl,e.fLsXt)){e[n(737)](_0x1ee9a7,_0x1b0a18,42);let m=_0xa9bdc5();e[n(334)](_0x4ef581,_0x2d4ef7,m),e[n(1429)](_0x7a7401,_0x497f9d,m[n(1325)]),_0x1a42c7(_0x141e58,m),e.DedFu(_0x2721f8,m)}else{let{offset:m}=wa(a,l);l=m;let v={cursor_name:"",cursor:0,service:0},{value:E,offset:p}=e[n(858)](Bp,a,l);v[n(293)]=E,l=p;let{value:A,offset:L}=e.YuTfG(wa,a,l);l=L,v["cursor_n"+n(1020)]=e[n(207)](ol,a,l,e.lzXwW(l,A)),l+=A;let{value:N,offset:U}=e[n(598)](zp,a,l);v[n(545)]=N[n(1542)](),l=U,h[n(315)](v)}return h}}function Kp(){let a=t;return{frameType:ya,headers:[{key:e[a(1411)],value:e[a(399)]}],payload:void 0}}class $p{constructor(n,s,l){let h=t;h(447)!==e[h(1364)]?(this[h(705)+h(530)]=n,this[h(510)+h(1019)]=s,this["_message"+h(1692)]=l,this[h(592)]=cl(this[h(705)+h(530)],e[h(200)])):(this._DBName=_0x4c0c9d,this._pathKey=_0x1d8d43,this._qosDB=_0xada74a?_0x52fd41:_0x412c91?_0x1f0901:null)}async openDB(){let n=t;await this[n(592)][n(488)]()}async[t(494)+"rs"](){let n=t;if(!this[n(592)][n(656)])return;let s=this._messageStrategy,l=await this._qosDB.getAll();switch(console[n(484)](e[n(1627)],l),s){case e[n(828)]:return l&&l[n(604)]?e[n(704)](ll,l,0,this[n(510)+"ileName"]):void 0;case e[n(732)]:return;case e.mMUOY:return l&&l.length?e.TuoRW(ll,l,0,this[n(510)+n(1019)]):e[n(988)](Kp)}}async[t(639)](n,s,l){let h=t;if(e[h(1474)](h(188),e[h(441)]))this[h(1253)+"er"]&&_0x4b7f45[h(599)+h(1100)+h(1534)](e.ZrANs,this[h(810)+h(1173)]),this._isBrowser&&_0x3d1381[h(599)+"entListe"+h(1534)](e[h(1495)],this[h(810)+h(383)]),this[h(647)]();else return console[h(484)](e.XygMu,n,s,l),this[h(592)][h(639)]({cursor_name:n,cursor:s,service:l})}async[t(339)+"rs"](n){let s=t,l=e[s(1201)](Wp,n);for(let h of l)console.log(e[s(1034)],l),await this[s(592)][s(639)](h)}async[t(247)](n){let s=t;return(await this[s(592)][s(247)](n))?.[s(545)]}async[t(1579)](){let n=t;await this[n(592)][n(1579)]()}[t(1003)+"rsorFileName"](n){let s=t;if(e[s(1683)](e[s(1608)],e.tvVOw)){let l=(s(453)+"4|0|5|2")[s(521)]("|"),h=0;for(;;){switch(l[h++]){case"0":if(!this[s(1512)])return void this[s(1159)](e[s(1392)]);continue;case"1":this[s(731)+s(1584)]();continue;case"2":this["_destroy"+s(502)+"t"](_0x1ae4b9,_0x5a0c36);continue;case"3":this._clearTimer();continue;case"4":this[s(259)+s(1345)]?.closeDB();continue;case"5":if(e[s(1061)](this._ws[s(1676)+"te"],this[s(1389)])||e[s(960)](this[s(1512)][s(1676)+"te"],this.CLOSING))return void this[s(1159)](e[s(370)]);continue;case"6":this._readyClosed=!0;continue;case"7":this[s(1473)+s(1070)+s(240)]();continue}break}}else this[s(510)+s(1019)]=n}get isReady(){let n=t;return this[n(592)][n(656)]}}let Vp=t(1078)+t(1045);async function ul(a){let n=t,s={thwff:function(l,h,m){return e[j(1056)](l,h,m)},fZGFF:e[n(1677)]};if(e[n(865)]===n(852)){if(!this[n(699)][n(1686)+"S"])return null;let{aID:l,fpID:h,messageStrategy:m}=this[n(699)],v=e[n(1313)](a,Vp);try{return this[n(400)+n(921)]?a&&this[n(400)+n(921)][n(1003)+n(389)+n(747)](a):this[n(400)+"anager"]=new $p(h+"_"+l+"_"+v,v,m),this[n(400)+n(921)].isReady||await this[n(400)+n(921)].openDB(),this[n(400)+n(921)]}catch{return null}}else{let l=this[n(1247)+"tManager"]?.getCurrentEndpoint();this[n(1695)+n(786)+"ent"](s[n(1280)](_0x3eb225,s.fZGFF,{code:_0x1cb8b3[n(601)],reason:"connecti"+n(444)+n(1370)+n(1456)+n(1603)+"ame: "+l})),this[n(1247)+n(1366)]?.[n(1669)+n(552)+"fig"](),this[n(538)+"sCounter"]?.[n(916)+n(1203)]();return}}async function Jp(a,n){let s=t;if(e[s(1410)]!==e[s(1410)])_0x4957d2.persisted&&(this[s(624)+s(325)]()&&(!this._ws||e[s(244)](this[s(1512)][s(1676)+"te"],this[s(1636)])||this._ws[s(1676)+"te"]!==this[s(711)+"NG"])&&this["_handleO"+s(271)](),this._isBrowser&&_0x41be50[s(413)+s(240)](e.LIhBc,this._handleOnLine),this[s(1253)+"er"]&&_0xd0bcd9["addEvent"+s(240)](e[s(1285)],this[s(388)+s(685)]));else{let l=e.BFfqc(cn,a[s(263)][s(285)],e.eXysn,"-1"),h=e[s(1091)](cn,a.message[s(285)],e[s(1268)],"1"),m=e[s(1530)](or,a[s(263)][s(285)],e[s(1029)]),v=Number(e[s(1254)](or,a[s(263)].headers,s(1117)+s(788)))||0,E=ma[s(527)](this,a),p=e[s(1091)](cn,a[s(263)][s(285)],e[s(925)],"2"),A=e[s(569)](or,a[s(263)][s(285)],s(1356)+s(800)+"e"),L=e.OuTWH(Number,e.iIwIA(or,a[s(263)][s(285)],e.quXCk));if(E.isQoSAck)return e[s(1657)](n);let N=E[s(332)+s(539)]?await dl[s(527)](this):null;if(e[s(1540)](a[s(263)][s(293)],0)&&h&&!l||e.gGwXX(a[s(263)][s(293)],0)){if(m&&E["isQoSMes"+s(539)]&&N)return!!!await N[s(247)](m)&&(this[s(1695)+s(841)+s(735)](a),await N.set(m,e[s(717)](Date.now(),v))),n();if(p){let U=await ul[s(527)](this);if(!U)return this[s(1695)+s(841)+"Event"](a),n();let Z=await U.get(A)??-1;if(e.AtMul(Z,L))this[s(1695)+s(841)+s(735)](a),U.set(A,L,a[s(263)].service);else throw new Error(s(410)+" message"+s(1635)+L+(" larger "+s(719)+s(439)+"r ")+Z);return n()}return this["_dispatchMessage"+s(735)](a),e.dsANT(n)}}}async function Zp(a,n){let s=t;if(s(281)!==e.goHmV){let l=ma[s(527)](this,a);if(!l[s(332)+"sage"])return n();let h=await dl[s(527)](this);if(l[s(1610)+"anupMess"+s(513)]&&l[s(1424)+"s"][s(604)])for(let m of l[s(1424)+"s"])await h[s(1350)](m);e[s(1317)](n)}else _0x3904db&&this["_cursorM"+s(921)][s(1003)+s(389)+s(747)](_0x2b9c60)}async function Yp(a,n){let s=t;if(e[s(238)](s(1615),e[s(866)])){let l=a[s(263)].frameType===jp,h=e[s(1462)](a[s(263)][s(492)+"e"],ya);if(e[s(974)](!l,!h))return e.PUpKn(n);let m=e[s(1032)](or,a[s(263)][s(285)],e[s(1411)]);if(!m)return e[s(631)](n);let v=await ul[s(527)](this,m);if(!v)return e[s(311)](n);if(l){let E=await v.getCursors(),p={frameType:E?.[s(492)+"e"],SeqID:ge.fromNumber(this[s(264)]++),LogID:ge.fromNumber(this[s(699)][s(912)+"erator"]()),service:9e3,method:5,headers:E?.headers,payload:E?.[s(1482)]},A=e[s(855)](S,p);this[s(1512)]&&this[s(1512)][s(1676)+"te"]&&this[s(1512)][s(379)](A)}if(h){let E=a.message.payload;E&&v[s(339)+"rs"](E)}}else this[s(624)+s(325)]()&&(!this[s(1512)]||e[s(407)](this._ws[s(1676)+"te"],this[s(1636)])||e.huHay(this[s(1512)][s(1676)+"te"],this.CONNECTING))&&this[s(388)+s(271)](),this._isBrowser&&_0x18a997["addEvent"+s(240)]("online",this["_handleO"+s(271)]),this._isBrowser&&_0x4388e4[s(413)+s(240)](e[s(1285)],this["_handleO"+s(685)])}let Xp=async function(a,n){let s=t;this[s(1251)]=!1,e[s(1402)](clearTimeout,this["_connect"+s(1161)+s(1633)]),n()},Qp=async function(a,n){let s=t;if(!this._ws||e[s(784)](this[s(1512)][s(1676)+"te"],this.OPEN))return n();let{pingInterval:l}=this[s(699)];this._endpointManager?.[s(1669)+s(552)+s(1065)]();for(let m=0;e[s(1625)](m,this[s(280)+s(548)][s(604)]);m++){let v=this[s(280)+s(548)][m];if(e[s(187)](this._ws[s(1676)+"te"],this[s(1636)])&&e[s(248)](null,v))if(e[s(1399)]!==e.HRnvD)this[s(1512)]&&this._ws.send(v),this[s(280)+s(548)][m]=null;else{let E=this[s(1247)+"tManager"]?.[s(516)+s(331)+"nt"]();this["_dispatc"+s(786)+s(219)](e[s(790)](_0x25c8ab,e[s(1677)],{code:1006,reason:s(314)+E+(s(654)+s(973)+s(433)+"ached"),wasClean:!0}))}else break}this["_message"+s(548)]=this[s(280)+s(548)][s(506)](m=>!!m),this[s(1638)+"gTimeoutId"]=e[s(1040)](setTimeout,()=>this._ping(),l),this[s(1695)+s(392)+"nt"](a),this[s(1253)+"er"]&&this[s(1512)]&&(this._ws[s(1195)+"pe"]=this[s(473)+s(1118)]);let h=this["_endpoin"+s(1366)]?.[s(516)+s(331)+"nt"]();this[s(1159)](s(1158)+h+" success"),n()},eg=async function(a,n){let s=t,l=this[s(1247)+s(1366)]?.[s(516)+s(331)+"nt"]();this[s(1159)](s(1158)+l),e.mxrcM(n)};class tg extends xa{constructor(n){let s=t,l={gyRAB:function(E,p,A,L){return E(p,A,L)},RRNNs:function(E,p){return e[j(1155)](E,p)},FrvJP:e.yoDhQ,UjxeI:e[s(1028)],CvLMi:function(E,p){return e[s(486)](E,p)},fSjYn:function(E,p){return e[s(963)](E,p)},HVypC:function(E,p){return e[s(833)](E,p)},rsWcg:function(E,p){return e[s(940)](E,p)},nbMYj:function(E,p){return e[s(511)](E,p)},MolQs:function(E,p){return e.RNplE(E,p)},tPegN:s(1673),CcwOH:function(E,p){return E===p},TxMyZ:e[s(718)],MtRlD:e[s(426)],lSaGJ:s(1519),YvWgs:function(E,p,A){return e[s(1326)](E,p,A)},oVjAu:e.UDWDX,uLAoI:function(E,p,A){return e[s(739)](E,p,A)},MmxrL:function(E,p){return e.smRVg(E,p)},WtkMO:s(647),GVfbC:function(E,p){return E!==p},HJGdL:function(E,p,A){return e[s(500)](E,p,A)},eIeNX:"bye",QDTlB:function(E,p){return e[s(1499)](E,p)},jHwAE:function(E,p){return e[s(376)](E,p)},DxaHM:"FgsWC",JLCCx:e[s(1376)]};super(),this["_miniNav"+s(1342)+"line"]=!0,this[s(1253)+"er"]=sr,this._isNode=mp,this[s(384)+"T"]=Ln,this[s(1114)+"X"]=Qr,this[s(363)+"r"]=ei,this._messageQueue=[],this[s(1247)+s(1366)]=null,this[s(1437)+s(1044)]=!1,this[s(473)+s(1118)]=e[s(1041)],this[s(1101)+s(305)]=!1,this["_connect"+s(1161)+s(1633)]=null,this[s(1077)+"ctTimeou"+s(440)]=null,this._pingPongTimeoutId=null,this[s(264)]=0,this._isInit=!1,this._url="",this["_QoSMana"+s(1345)]=null,this[s(400)+"anager"]=null,this[s(538)+"sCounter"]=null,this._protocols=e[s(445)],this[s(1389)]=3,this[s(711)+"NG"]=0,this.OPEN=1,this.CLOSING=2,this._onOpen=E=>{let p=s;try{l[p(529)](il,this,E,[Xp,Qp,eg])}catch(A){if(l[p(1618)](l.FrvJP,p(894)))return!!this._qosDB;{let L=ft(l[p(1452)],{message:A[p(263)],code:an[p(1580)+"OR"],error:A});this[p(1695)+p(689)+p(219)](L)}}},this[s(1371)+"ge"]=async E=>{let p=s,A={TqySN:function(U,Z){return l[j(583)](U,Z)},QUXBP:function(U,Z){return l[j(1181)](U,Z)},EnsLU:function(U,Z){return l[j(1212)](U,Z)}},{pingInterval:L,pingFrequency:N}=this[p(699)];if((l[p(799)]("hi",E[p(338)])&&l[p(1354)]===N||l[p(1058)](p(880),N))&&(l[p(799)](p(465),l[p(1084)])?(this[p(731)+p(1584)](),this[p(1245)](l[p(1382)],l[p(1609)]),this[p(1638)+p(1388)+"Id"]=l[p(1529)](setTimeout,this._ping[p(1375)](this),L)):(_0x46ee26=cQiXEJ[p(1275)](_0x56b538,_0xfe13e),_0x1d6294|=cQiXEJ[p(405)](cQiXEJ[p(1522)](127,_0x1d724),7))),E[p(338)]!=="hi")try{p(751)===l[p(1430)]?(_0x347eda=nYITPU[p(583)](_0x39dc66,_0x134701),_0x47e950=nYITPU[p(1684)](127,_0x3e6565),nYITPU[p(750)](128,_0x2273fb)&&(_0x2533d1=nYITPU.CvLMi(_0x529d48,_0x2b18c4),_0x45f86a|=nYITPU[p(1181)](127&_0x2d6d6c,7))):l[p(529)](il,this,E,[Pp,Cp,Zp,Yp,Jp,Dp])}catch(U){let Z=l.uLAoI(ft,l.UjxeI,{message:U[p(263)],code:an.MESSAGE_ERROR,error:U});this[p(1695)+p(689)+p(219)](Z)}},this[s(854)]=E=>{let p=s,A={aFrey:function(L,N){return e[j(743)](L,N)},swmsA:function(L,N){return e[j(1466)](L,N)}};if(e[p(1036)](p(1081),e.oiuIa)){let L=_0x1696b3[p(527)](VCKxYh[p(846)](_0x461f48,this),_0x378864,..._0x2479e4);return _0x1d12ab[p(639)](L,_0x30afa5[p(455)]?_0x12d46e[p(455)]():[_0x4475cb]),VCKxYh[p(667)](_0x270b8f,L)}else{let L=this[p(1247)+"tManager"]?.[p(1130)+p(1409)+"es"](),N=this["_endpoin"+p(1366)]?.[p(516)+p(331)+"nt"]();if(L&&!E[p(263)]){let U=p(314)+N+(" fail, max retri"+p(715)+"ed");this["_dispatc"+p(689)+"ent"](e[p(765)](ft,e[p(1028)],{message:U,code:an[p(1544)+"IES_ERROR"],error:E}));return}this[p(1512)]&&e[p(811)](this[p(1512)].readyState,this[p(1636)])&&this[p(1143)+p(176)](),this[p(1695)+p(689)+p(219)](e[p(948)](ft,e[p(1028)],{message:E[p(263)],code:an[p(797)+p(547)],error:E}))}},this._onClose=async E=>{let p=s,A={aIpWz:function(N,U){return l[j(1664)](N,U)}};this[p(968)+p(1256)](),this[p(731)+p(1584)](),this[p(1403)+p(1236)+"rs"](),this[p(1512)]=null,this[p(1101)+p(305)]=!1;let L=this[p(1247)+p(1366)]?.["checkRea"+p(1409)+"es"]();if(!L&&this[p(624)+p(325)]()&&!this[p(1437)+p(1044)]){let N=this[p(1247)+"tManager"]?.[p(516)+"ntEndpoint"](),U=this._options[p(1199)+p(768)+"ptor"](E.code,E[p(1307)]);this[p(1695)+"hCloseEv"+p(219)](wt(l[p(1632)],{code:1006,reason:E.reason||"connecting faile"+p(1370)+p(1456)+p(1603)+p(1337)+N,willReconnect:U})),U&&this[p(1101)]();return}if(l.GVfbC(1e3,E[p(601)])&&this[p(1437)+p(1044)]){this._dispatchCloseEvent(l.HJGdL(wt,l[p(1632)],{code:1e3,reason:l[p(1624)]})),this[p(1247)+p(1366)]?.["resetEnd"+p(552)+p(1065)](),this[p(538)+p(928)]?.[p(916)+p(1203)]();return}if(l[p(1582)](1e3,E[p(601)])&&L){let N=this[p(1247)+p(1366)]?.[p(516)+"ntEndpoint"](),U=E[p(1307)];U||(U=await Sp(this[p(1604)])),U="connecti"+p(444)+p(1489)+U+(p(213)+p(1148))+N+(p(973)+p(433)+p(1260)),this["_dispatc"+p(786)+"ent"](wt(p(647),{code:E[p(601)],reason:U}));let Z=p(314)+N+(p(817)+p(1690)+"es reached");this[p(1695)+p(689)+"ent"](ft(p(821),{message:Z,code:an[p(1544)+"IES_ERROR"]})),this[p(1247)+p(1366)]?.["resetEnd"+p(552)+p(1065)](),this["_pingLos"+p(928)]?.[p(916)+p(1203)]();return}if(l[p(1557)](1e3,E[p(601)])&&!E[p(1307)])if(l[p(1582)](l[p(550)],l.JLCCx)){let N=this[p(1247)+p(1366)]?.[p(516)+p(331)+"nt"]();this["_dispatc"+p(786)+p(219)](wt(l[p(1632)],{code:E[p(601)],reason:p(818)+p(444)+p(1370)+p(1456)+p(1603)+p(1337)+N})),this[p(1247)+p(1366)]?.[p(1669)+p(552)+p(1065)](),this[p(538)+p(928)]?.[p(916)+p(1203)]();return}else{let N=new _0x32d864(jEMfIE[p(1082)](2,_0x39b8aa));N[p(639)](_0x363652),_0x297108[p(1444)]=N}this[p(1695)+p(786)+p(219)](E),this[p(1247)+p(1366)]?.[p(1669)+p(552)+p(1065)](),this[p(538)+p(928)]?.[p(916)+"nter"]()},this[s(1038)]=null,this.onerror=null,this[s(1164)+"e"]=null,this.onopen=null,this[s(829)+s(634)]=null,this[s(396)+s(1042)]=null,this["onStopIm"+s(556)+s(1076)+"ct"]=null,this[s(388)+s(271)]=this._handleOnLine[s(1375)](this),this["_handleO"+s(685)]=this["_handleO"+s(685)][s(1375)](this),this[s(810)+"ageHide"]=this["_handleP"+s(1173)].bind(this),this[s(810)+s(383)]=this[s(810)+s(383)][s(1375)](this),this[s(699)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(885)](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(1229)],pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:s(785),env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:h,ws:m}=n,v=Array[s(1460)](h)?h:e[s(1179)](e[s(847)],typeof h)?[h]:[];if(!v||v[s(604)]===0)throw new Error(e.GibxX);if(!e[s(1660)](yp,m))throw new Error(e[s(1073)]);Object[s(205)](this._options,n),this[s(1247)+s(1366)]=new rl(v,this[s(699)][s(1476)+"es"]),this[s(538)+s(928)]=new vp(this._options[s(1508)+"Count"]),this[s(699)]["automati"+s(320)]&&(this[s(1251)]=!0,this._connect()),this[s(699)][s(454)+s(1095)+s(1097)]&&(this._isMiniTT||this[s(1114)+"X"]?this[s(449)+"etWorkChange"]():this[s(1253)+"er"]&&this[s(1639)+s(1070)+s(240)]())}[t(388)+t(271)](){let n=t;this._options[n(531)+n(1571)+n(1234)]||this[n(1437)+n(1044)]||this[n(1178)+n(634)]()}[t(388)+t(685)](){let n=t;this._destroyWebSocket();let s=e.WAGRH(ha,e[n(551)],{message:"stop imm"+n(938)+n(1538)+"ct"});this[n(1612)+n(556)+n(1076)+"ct"]&&this[n(1612)+"mediatel"+n(1076)+"ct"](s)}[t(1639)+t(1070)+"Listener"](){let n=t;this._isBrowser&&window[n(413)+n(240)](e[n(698)],this[n(388)+n(271)]),this[n(1253)+"er"]&&window[n(413)+"Listener"](e[n(1285)],this[n(388)+"ffLine"]),this[n(1253)+"er"]&&window[n(413)+n(240)](e[n(584)],this[n(810)+n(1173)]),this[n(1253)+"er"]&&window["addEvent"+n(240)](e[n(1495)],this._handlePageShow)}[t(1473)+t(1070)+t(240)](){let n=t;this._isBrowser&&window[n(599)+"entListener"](e.LIhBc,this[n(388)+n(271)]),this[n(1253)+"er"]&&window[n(599)+"entListe"+n(1534)](e[n(1285)],this["_handleO"+n(685)]),this[n(1253)+"er"]&&window[n(599)+n(1100)+"ner"](e[n(584)],this[n(810)+"ageHide"]),this._isBrowser&&window["removeEv"+n(1100)+"ner"](e[n(1495)],this[n(810)+"ageShow"])}[t(810)+"ageHide"](n){let s=t;!n[s(1187)+"d"]&&(this._isBrowser&&window[s(599)+s(1100)+s(1534)](e[s(584)],this[s(810)+s(1173)]),this[s(1253)+"er"]&&window[s(599)+s(1100)+s(1534)](e[s(1495)],this[s(810)+s(383)]),this.close()),this[s(1253)+"er"]&&window[s(599)+"entListe"+s(1534)]("online",this["_handleO"+s(271)]),this[s(1253)+"er"]&&window[s(599)+s(1100)+s(1534)](e[s(1285)],this[s(388)+"ffLine"])}_handlePageShow(n){let s=t;n.persisted&&(this[s(624)+"orOnline"]()&&(!this[s(1512)]||e.WZBvw(this[s(1512)][s(1676)+"te"],this[s(1636)])||this._ws.readyState!==this[s(711)+"NG"])&&this[s(388)+s(271)](),this[s(1253)+"er"]&&window[s(413)+"Listener"](e[s(698)],this[s(388)+s(271)]),this[s(1253)+"er"]&&window[s(413)+s(240)](e[s(1285)],this[s(388)+"ffLine"]))}async[t(677)+"eUrl"](n){let s=t,{fpID:l,deviceID:h,bddID:m,ttwID:v,accessKey:E,aID:p,customParams:A={},enableAutoAck:L,enableQoS:N,QoSLevel:U,env:Z}=this[s(699)],X,Ve,te;this[s(1253)+"er"]||this[s(1114)+"X"]||this[s(384)+"T"]?(X=location&&e.rgKvO==location[s(230)]?e[s(481)]:e[s(354)],Ve=n.replace(/((^ws)|(^http))((?:[s]*:\/\/))/,""),te=/^wss(.*:\/\/)/.test(n)?n:""+X+Ve):(X=e[s(481)],Ve=n[s(329)](/(^http)((?:[s]*:\/\/))/,""),te=/(^ws)((?:[s]*:\/\/))/.test(Ve)?Ve:""+X+Ve);let ae=m?"bd_did":v?e.rLEpJ:e.xnHxd,V=m||v||h;if(e[s(1607)](!V,!ae))throw new Error(e.roiKH);let $=e[s(1179)](e[s(1363)],typeof A)?await e[s(706)](A):A,De=Z?e.Wdxgq(Ep,Z[s(1511)],Z[s(335)]):{},_e=Object[s(205)]({device_platform:e.VHhqv,version_code:e[s(1628)],access_key:E,fpid:l,aid:p,[ae]:V,xsack:L?1:0,xaack:L?1:0,xsqos:N?1:0,qos_level:N?U:void 0,qos_sdk_version:2,...De},$),ba=Object[s(1333)](_e)[s(980)]((Ea,va)=>_e[va]!==void 0?""+Ea+(Ea?"&":"?")+va+"="+_e[va]:Ea,"");return te+"/ws/v2"+ba}async[t(1101)](){let n=t;if(!(this[n(1101)+"Lock"]||this[n(1437)+n(1044)])){this[n(1101)+n(305)]=!0;try{if(e[n(1221)](e[n(1552)],e[n(1552)]))return this[n(592)][n(246)]();{let s=this._endpointManager?.[n(1500)+"rentEndpointReac"+n(1590)+"tries"](),{timeoutInterval:l}=this[n(699)];if(s){let m=this[n(1247)+n(1366)]?.[n(516)+"ntEndpoint"](),v=this["_endpoin"+n(1366)]?.["replaceB"+n(892)+n(997)+"UpdateCo"+n(1555)](),E=this._endpointManager?.[n(516)+n(331)+"ntTriesC"+n(186)]();if(v){let p=n(314)+m+(n(654)+n(973)+n(433)+"ached, will use "+n(1563)+n(982))+v+" to retry",A=e[n(845)](ft,e[n(1028)],{message:p,code:an[n(1544)+n(795)+"R"]});this[n(1159)](p),this[n(1695)+n(689)+n(219)](A),this[n(1604)]=await this[n(677)+n(920)](v),this._debug(n(314)+v+" "+E+n(528)),this[n(1403)+n(1236)+"rs"]()}else{let p="connect "+m+(" timeout, max re"+n(433)+n(1260));this[n(1159)](p),this[n(1695)+n(689)+"ent"](e.UQrTQ(ft,e.vJwmP,{message:p,code:an[n(1544)+n(795)+"R"]}));return}}else{let m=this[n(1247)+"tManager"]?.["getCurre"+n(331)+n(404)+"ateCount"](),v=this[n(1247)+"tManager"]?.["getCurre"+n(331)+"ntTriesC"+n(186)]();this[n(1604)]=await this._generateUrl(e[n(1089)](m,"")),this[n(1159)](n(314)+m+" "+v+n(528)),this[n(1403)+n(1236)+"rs"]()}if(this._isInit)this[n(1251)]=!1;else{let m=e[n(501)](ha,e.XmXrY,{message:e[n(172)]});this[n(829)+n(634)]&&this[n(829)+n(634)](m)}let h=this["_endpoin"+n(1366)]?.[n(516)+"ntEndpoi"+n(775)+"ount"]()||0;e[n(646)](h,1)&&await this[n(402)](e[n(324)](h,1)),this[n(1159)](n(818)+n(1559)+this[n(1604)]+(n(1011)+"ls: ")+this[n(177)+"ls"]),this[n(1512)]=e[n(1174)](_p,{url:this[n(1604)],protocols:[this[n(177)+"ls"]],headers:this[n(699)][n(975)+n(1047)+"s"]["customHt"+n(660)]},this[n(699)].ws),(this._isBrowser||this[n(363)+"r"])&&this[n(1512)]&&(this._ws.binaryType=this[n(473)+n(1118)]),this[n(1208)+n(766)](),this[n(1101)+"ionTimeo"+n(1633)]=e[n(860)](setTimeout,this._onTimeout[n(1375)](this),l)}}catch(s){throw this[n(1101)+n(305)]=!1,s}}}_clearTimer(){let n=t;clearTimeout(this[n(1101)+n(1161)+n(1633)]),this["_connect"+n(1161)+n(1633)]=null}["_clearPi"+t(1584)](){let n=t;e[n(1561)](clearTimeout,this[n(1638)+n(1388)+"Id"]),clearTimeout(this[n(1077)+n(763)+n(440)]),this[n(1638)+"gTimeoutId"]=null,this[n(1077)+n(763)+"tId"]=null}[t(1159)](...n){let s=t;this[s(699)][s(1167)]&&console[s(484)][s(270)](console,[e[s(856)],...n])}[t(1465)+t(565)+"e"](n){let s=t,{initReconnectInterval:l,maxReconnectInterval:h,reconnectIntervalGrowFactor:m}=this[s(699)],v=e.smRVg(l,Math[s(1566)](m,e[s(1553)](n,1)));return e.aDKFj(v,h)?h:v}[t(316)](){let n=t;if(this[n(1512)]&&e[n(1483)](this[n(1512)][n(1676)+"te"],this[n(711)+"NG"])){this[n(731)+n(1584)](),this[n(1638)+n(1388)+"Id"]=setTimeout(this[n(316)][n(1375)](this),this[n(699)][n(589)+n(1521)]);return}if(!this[n(1512)]||this[n(1512)].readyState!==this[n(1636)])return void this["_handleR"+n(634)]();this[n(1512)]&&this[n(1512)][n(379)]("hi"),this[n(1077)+n(763)+n(440)]=setTimeout(this[n(1178)+n(634)+n(1334)][n(1375)](this),this._options[n(859)+"outInter"+n(820)])}[t(1178)+t(634)+t(1334)](){let n=t;this["_pingLos"+n(928)]?.addCount(),this.emit(e.HtBBp,e[n(924)]),this[n(538)+"sCounter"]?.["checkRea"+n(282)+"nt"]()?this["_handleR"+n(634)]():this._ping()}[t(624)+t(325)](){let n=t;return this[n(384)+"T"]||this[n(1114)+"X"]?this[n(1122)+n(1342)+"line"]:(this[n(1253)+"er"]||this[n(363)+"r"])&&this._options[n(454)+n(1095)+"nged"]?navigator[n(381)]:!0}[t(1178)+t(634)](){let n=t;!this[n(624)+"orOnline"]()||this[n(1437)+"osed"]||(this[n(1247)+"tManager"]?.["resetEnd"+n(552)+n(1065)](),this[n(538)+n(928)]?.[n(916)+n(1203)](),this[n(1512)]?this[n(1143)+n(176)](1001,e.sqJig,!0):this[n(1101)]())}[t(449)+t(417)+t(761)](){let n=t,s={VAsQy:e[n(512)]};if(e.RNplE(e[n(423)],e[n(1106)]))return _0xf37323||(_0x2d8934=_0xaac776.resolve().then(_0x34f6f2.bind(_0x5aece7,n(1135)))),_0x4e178d;this._isMiniTT?tt[n(1154)+n(986)+n(1377)](({isConnected:l})=>{let h=n;this[h(1122)+h(1342)+h(602)]=l,l?this[h(388)+h(271)]():this[h(388)+"ffLine"]()}):this[n(1114)+"X"]&&wx[n(1154)+n(986)+n(1377)](({isConnected:l})=>{let h=n;if(s[h(905)]!==s[h(905)])return _0x3fba17;this["_miniNav"+h(1342)+h(602)]=l,l?this[h(388)+h(271)]():this._handleOffLine()})}_wait(n){let s={ErrBo:function(l,h,m){return e[j(904)](l,h,m)}};return new Promise(l=>{let h=j;s[h(908)](setTimeout,l,this[h(1465)+"rvalValue"](n))})}[t(1143)+t(176)](n=1e3,s="",l=!1){this._ws&&this._destroyWebSocket(n,s,l)}_onTimeout(){let n=t,s=this[n(1247)+n(1366)]?.[n(516)+"ntEndpoint"]();this[n(1159)]("connect "+s+n(654)),this[n(1143)+n(176)](1001,n(286)+" try rec"+n(619)+"g",!0)}[t(571)](n){let s=t,l=jt(n);if(this._ws&&e.qHRrg(this[s(1512)][s(1676)+"te"],this.OPEN))if(e[s(409)]===e[s(835)]){if(this[s(1247)+s(1366)]?.[s(1130)+"chMaxTries"]()){let m=this[s(1247)+s(1366)]?.[s(516)+s(331)+"nt"]();this[s(1695)+s(786)+"ent"](e[s(1024)](_0x4dd506,e[s(1677)],{code:1006,reason:s(314)+m+(" timeout"+s(973)+"tries re"+s(1260)),wasClean:!0}))}else{let m=this[s(699)][s(1199)+s(768)+s(1119)](_0x2f5c4c,_0x31e634);this[s(1695)+"hCloseEv"+s(219)](_0x51d2d5(e[s(1677)],{code:_0x308eb1,reason:_0xd10e1e,wasClean:!0,willReconnect:m})),m&&this._connect()}return}else this[s(1512)]&&this._ws[s(379)](l),this[s(1159)](e[s(958)],n)}[t(1403)+t(1236)+"rs"](){let n=t,s=e[n(1464)][n(521)]("|"),l=0;for(;;){switch(s[l++]){case"0":this[n(1512)]["removeEventListe"+n(1534)](e[n(923)],this[n(1491)]);continue;case"1":this[n(1512)][n(599)+n(1100)+n(1534)](e[n(191)],this[n(1371)+"ge"]);continue;case"2":if(!this._ws)return;continue;case"3":this[n(1512)][n(599)+n(1100)+n(1534)](e.vJwmP,this[n(854)]);continue;case"4":this[n(1512)][n(599)+n(1100)+n(1534)](e[n(1677)],this[n(700)]);continue}break}}[t(1208)+"steners"](){let n=t,s=e[n(1176)].split("|"),l=0;for(;;){switch(s[l++]){case"0":this[n(1512)][n(413)+n(240)](e.cruUp,this[n(700)]);continue;case"1":this[n(1512)][n(413)+n(240)](e[n(1028)],this._onError);continue;case"2":this[n(1512)][n(413)+n(240)](e[n(191)],this[n(1371)+"ge"]);continue;case"3":this[n(1512)]["addEvent"+n(240)](n(1533),this[n(1491)]);continue;case"4":if(!this._ws)return;continue}break}}[t(559)+t(789)](n=1e3,s=""){try{this._ws&&this._ws.close(n,s)}catch{}}[t(362)+"WebSocket"](n=1e3,s="",l=!1){let h=t;if(e[h(478)](h(1258),e[h(814)]))_0x3c22e6[h(599)+h(1100)+"ner"](spPegF[h(487)],_0x50a83c),_0x1a1e70[h(599)+h(1100)+"ner"](spPegF[h(1028)],_0x4bea4b);else{if(this[h(731)+"ngTimer"](),this[h(968)+"mer"](),this._removeWsListeners(),this[h(559)+"nceClose"](1e3,s),this[h(1101)+h(305)]=!1,l&&this["_navigat"+h(325)]()&&!this._readyClosed){if(this[h(1247)+h(1366)]?.[h(1130)+h(1409)+"es"]()){let v=this["_endpoin"+h(1366)]?.[h(516)+h(331)+"nt"]();this[h(1695)+h(786)+h(219)](e[h(808)](wt,e[h(1677)],{code:1006,reason:h(314)+v+(" timeout"+h(973)+h(433)+"ached"),wasClean:!0}))}else{let v=this[h(699)][h(1199)+"tInterce"+h(1119)](n,s);this[h(1695)+h(786)+h(219)](wt(e[h(1677)],{code:n,reason:s,wasClean:!0,willReconnect:v})),v&&this._connect()}return}this[h(624)+h(325)]()||this[h(1437)+h(1044)]?this[h(1695)+h(786)+h(219)](e.KHbbO(wt,e.cruUp,{code:n,reason:"bye"})):this[h(1695)+h(786)+h(219)](wt(e[h(1677)],{code:1006,reason:e[h(183)]})),this[h(1512)]=null,this[h(1247)+"tManager"]?.[h(1669)+h(552)+h(1065)](),this["_pingLos"+h(928)]?.[h(916)+h(1203)]()}}[t(1695)+t(392)+"nt"](n){let s=t;this[s(1245)]("open",n),this[s(1458)]&&this[s(1458)](n)}[t(1695)+"hMessage"+t(735)](n){let s=t;this[s(1245)](e.DYaIV,n),this[s(1164)+"e"]&&this.onmessage(n)}[t(1695)+t(1358)+t(201)](n){let s=t;this[s(1245)](e[s(1291)],n),this[s(396)+s(1042)]&&this["onReceiv"+s(1042)](n)}[t(1695)+t(689)+"ent"](n){let s=t;this.emit(e[s(1028)],n),this[s(1651)]&&this.onerror(n)}[t(1695)+"hCloseEv"+t(219)](n){let s=t;this[s(1245)](e[s(1677)],n),this[s(1038)]&&this[s(1038)](n)}get[t(1195)+"pe"](){let n=t;return this[n(1512)]?this[n(1512)].binaryType:this[n(473)+n(1118)]}set[t(1195)+"pe"](n){let s=t;this[s(473)+"ype"]=n,this[s(1512)]&&(this[s(1512)][s(1195)+"pe"]=n)}get[t(1048)+"nt"](){let n=t;return this["_endpoin"+n(1366)]?.["getCurre"+n(331)+n(775)+n(186)]()||0}get[t(812)+t(416)](){let n=t;return this["_message"+n(548)][n(980)]((l,h)=>(l+=h&&h[n(607)+"th"]||0,l),0)+(this[n(1512)]?this[n(1512)][n(812)+n(416)]:0)}get[t(1351)+"ns"](){let n=t;return this[n(1512)]?this[n(1512)][n(1351)+"ns"]:""}get protocol(){let n=t;return this[n(1512)]?this[n(1512)][n(230)]:""}get[t(1676)+"te"](){let n=t;return this[n(1512)]?this[n(1512)][n(1676)+"te"]:this._options[n(1219)+n(320)]?this.CONNECTING:this[n(1389)]}get url(){let n=t;return this._ws?this._ws[n(1682)]:this[n(1604)]}[t(647)](n=1e3,s){let l=t,h=(l(203)+l(727))[l(521)]("|"),m=0;for(;;){switch(h[m++]){case"0":if(!this[l(1512)])return void this[l(1159)](e.Atwwn);continue;case"1":this["_clearPi"+l(1584)]();continue;case"2":this[l(362)+l(502)+"t"](n,s);continue;case"3":this["_dropGlo"+l(1070)+l(240)]();continue;case"4":this[l(968)+l(1256)]();continue;case"5":if(e[l(721)](this[l(1512)][l(1676)+"te"],this[l(1389)])||e[l(1585)](this._ws.readyState,this[l(933)]))return void this._debug(e[l(370)]);continue;case"6":this[l(259)+"ger"]?.[l(1579)]();continue;case"7":this[l(1437)+l(1044)]=!0;continue}break}}async[t(379)](n,s){let l=t,h={clddS:function(te,ae,V){return e.vOCOv(te,ae,V)}};if(e.HQRqW(null,n))throw new Error(e[l(759)]);e.MYloq(e[l(1083)],typeof n)&&(n=JSON[l(917)+"y"](n)),e[l(825)](e[l(847)],typeof n)&&!(n instanceof ArrayBuffer)&&!(n[l(989)]&&e[l(1451)](n[l(989)],ArrayBuffer))&&(n=JSON[l(917)+"y"](n));let m=await e.SPgbq(al,n),v=e[l(610)](bp,n),{method:E=0,service:p=this[l(699)][l(293)],logID:A=this._options[l(912)+l(1372)](),headers:L=this[l(699)][l(285)],payloadEncoding:N=this[l(699)][l(1602)+l(703)],payloadType:U=this[l(699)][l(1287)+l(1118)],logIDNew:Z=this[l(699)][l(911)+l(214)][l(1361)+l(1469)+l(224)+"ew"]?e.DvcDV(i,this[l(699)][l(911)+l(214)][l(428)]):""}=e[l(1470)](s,{});if(!p)throw new Error("please p"+l(327)+l(269)+l(586));let X={SeqID:ge[l(1134)+"er"](this[l(264)]++),LogID:ge[l(1134)+"er"](A),service:p,method:E,headers:L,payloadEncoding:e[l(671)](N,Object)?N[l(832)]?N[l(832)]:"":N,payloadType:U instanceof Object?U[l(1667)]?U[l(1667)]:v:U||v,payload:m,LogIDNew:Z},Ve=e[l(1201)](jt,X);if(this[l(1512)]&&e[l(1362)](this._ws[l(1676)+"te"],this[l(1636)]))this._ws&&this[l(1512)][l(379)](Ve),this[l(1159)](e.YUmSF,X);else if(e.PEgMm(this["_message"+l(548)].length,this[l(699)][l(398)+l(223)+l(935)]))if(e.MkLBt("OeqzC",e.ykxoQ))this[l(280)+l(548)][l(315)](Ve),this[l(1159)](e[l(1332)],X);else{let te=EuBAcE.clddS(_0x7348b2,_0x4b9d7f,1);_0x308b61.bytes[te]=_0x576f09}else this["_message"+l(548)][l(1595)](),this[l(280)+"Queue"][l(315)](Ve);return{seqID:this[l(264)],logID:A,logIDNew:Z}}async[t(1199)+"t"](n){let s=t,{url:l}=e.fesqN(n,{}),h=Array[s(1460)](l)?l:s(221)==typeof l?[l]:[];n&&Object[s(205)](this[s(699)],n),h&&h[s(604)]?this[s(1247)+"tManager"]=new rl(h,this[s(699)][s(1476)+"es"]):this[s(1247)+s(1366)]?.[s(1669)+s(552)+"fig"](),this[s(538)+s(928)]?.[s(916)+s(1203)](this[s(699)][s(1508)+"Count"]),this[s(1437)+s(1044)]=!1,this[s(1512)]&&this._ws[s(1676)+"te"]!==this[s(1389)]?this[s(1143)+"ect"](1e3,s(1213)+"econnect"+s(179),!0):(this[s(1251)]=!0,this._connect())}async connect(){let n=t;if(!this[n(1101)+n(305)]){let s=e[n(1162)][n(521)]("|"),l=0;for(;;){switch(s[l++]){case"0":this._isInit=!0;continue;case"1":this[n(538)+n(928)]?.[n(916)+"nter"]();continue;case"2":this._connect();continue;case"3":this["_readyCl"+n(1044)]=!1;continue;case"4":this[n(1247)+n(1366)]?.[n(1669)+n(552)+n(1065)]();continue}break}}}[t(413)+t(240)](n,s){this.on(n,s)}dispatchEvent(n){let{type:s}=n;this.emit(s,n)}[t(599)+t(1100)+"ner"](n,s){this[t(576)](n,s)}pingOnce(){let n=t,s={WGQCo:e[n(426)],WvYCw:function(l){return e[n(1477)](l)},aGIeS:function(l,h){return l!==h},roqry:e.lZnyI,jPFBE:e[n(436)],UCGMZ:function(l,h,m){return e[n(948)](l,h,m)},trKDN:e[n(1009)]};if(e.QZPVF(e[n(296)],"RPmHK"))return new Promise((l,h)=>{let m=n,v={MKpAn:function(E,p){return E(p)},anWLJ:m(1519),hJBIF:s[m(382)],XKfvh:"ping_onc"+m(1210)+"t",jtKso:function(E){return s[m(1548)](E)}};if(s[m(1619)](s[m(1202)],s[m(895)])){this[m(731)+m(1584)](),this["_pingPon"+m(1388)+"Id"]=s[m(195)](setTimeout,this[m(316)].bind(this),this._options[m(589)+"rval"]);let E=()=>{let A=m;v[A(1427)](l,v.anWLJ),this[A(576)](v[A(1535)],E),this[A(576)](v[A(621)],p)},p=()=>{let A=m;v[A(1427)](h,A(333)),this.off(A(1043)+A(801)+"s",E),this[A(576)](v.XKfvh,p)};this.on(s[m(382)],E),this.on(s[m(585)],p),this._ping()}else{let E=this["_endpoin"+m(1366)]?.[m(516)+"ntEndpoint"]();this[m(1159)](m(1158)+E),ESIpjw[m(1700)](_0x4eb81b)}});this._isMiniTT?_0x46e120[n(1154)+n(986)+n(1377)](({isConnected:l})=>{let h=n;this[h(1122)+h(1342)+h(602)]=l,l?this[h(388)+"nLine"]():this["_handleO"+h(685)]()}):this._isMiniWX&&_0x2d22f1["onNetworkStatusC"+n(1377)](({isConnected:l})=>{let h=n;this[h(1122)+"igatorOnline"]=l,l?this[h(388)+h(271)]():this[h(388)+"ffLine"]()})}}})(),Ne[B(1270)+B(303)]=Le[B(1270)+B(303)],Ne[B(1652)+"rorEvent"]=Le[B(1652)+B(996)],Ne[B(1185)+"e"]=Le.ErrorCode,Ne[B(735)]=Le[B(735)],Ne.FWS=Le.FWS,Ne["FrontierMessageE"+B(1186)]=Le[B(1013)+B(1066)+B(1186)],Ne["MessageE"+B(1186)]=Le[B(1066)+B(1186)],Ne[B(1063)+"t"]=Le[B(1063)+"t"],Ne["Reconnec"+B(253)]=Le[B(1545)+"tEvent"],Ne[B(479)+"oseEvent"]=Le[B(479)+B(303)],Ne[B(1125)+"rorEvent"]=Le[B(1125)+B(996)],Ne[B(1196)+B(712)+"nt"]=Le["createMe"+B(712)+"nt"],Ne[B(1463)+B(275)]=Le[B(1463)+B(275)],Ne[B(1235)+B(1578)+B(1186)]=Le["createRe"+B(1578)+"vent"],Ne[B(616)+B(309)]=Le[B(616)+B(309)],Ne[B(1257)+B(1020)]=Le[B(1257)+B(1020)];for(jo in Le)[B(1270)+"oseEvent",B(1652)+"rorEvent",B(1185)+"e",B(735),"FWS",B(1013)+"MessageEvent",B(1066)+B(1186),"OpenEvent",B(1545)+B(253),B(479)+"oseEvent",B(1125)+"rorEvent",B(1196)+B(712)+"nt","createOp"+B(275),"createReconnectE"+B(1186),"decodedFrame",B(1257)+B(1020)][B(596)](jo)===-1&&(Ne[jo]=Le[jo]);var jo;Object.defineProperty(Ne,B(1344)+"le",{value:!0})});import{existsSync as sS,openSync as oS}from"node:fs";import{mkdir as aS}from"node:fs/promises";import{dirname as cS}from"node:path";import{fileURLToPath as dS}from"node:url";function uS(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Nd(t=ne()){return sS(t.libEntry)?t.libEntry:dS(new URL("../index.ts",import.meta.url))}async function Px(t={}){let e=t.paths??ne(),r=t.entryOverride??Nd(e),i=uS(e,process.env.COZE_BRIDGE_LOG_MODE);await aS(cS(i),{recursive:!0});let o=oS(i,"a"),d=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=at(process.execPath,d,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[is]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return lS.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var lS,is,ea=it(()=>{"use strict";Yt();se();Fe();lS=G("spawn-daemon"),is="COZE_BRIDGE_DAEMON"});import{spawn as s1}from"node:child_process";import{mkdir as o1,unlink as a1,writeFile as c1}from"node:fs/promises";import{dirname as d1,join as l1}from"node:path";function Zr(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function u1(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Zr(r)}</key>
21
+ <string>${Zr(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 f1(t,e){return new Promise((r,i)=>{let o=s1(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var Jr,os,aa,qd,Xx=it(()=>{"use strict";se();Jr=G("supervisor.launchd"),os="ai.coze.bridge",aa=f1,qd={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>${os}</string>
32
32
  <key>ProgramArguments</key>
33
33
  <array>
34
- <string>${Kr(t.nodeBin)}</string>
35
- <string>${Kr(t.entry)}</string>
34
+ <string>${Zr(t.nodeBin)}</string>
35
+ <string>${Zr(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>${Zr(t.logFile)}</string>
46
46
  <key>StandardErrorPath</key>
47
- <string>${Kr(t.logFile)}</string>${a1(t.env)}
47
+ <string>${Zr(t.logFile)}</string>${u1(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 l1(t.homeDir,"Library","LaunchAgents",`${os}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await o1(d1(i),{recursive:!0}),await c1(i,this.renderConfig(t),"utf8"),Jr.info("plist written",{plistPath:i,activate:r}),!r)return;await aa("launchctl",["unload","-w",i]).catch(c=>Jr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await aa("launchctl",["load","-w",i]),Jr.info("launchd job loaded",{label:os});let o=process.getuid?.()??0;await aa("launchctl",["kickstart","-k",`gui/${o}/${os}`]),Jr.info("launchd job kickstarted",{label:os,uid:o})},async uninstall(t){let e=this.configPath(t);await aa("launchctl",["unload","-w",e]).catch(r=>Jr.warn("launchctl unload failed (ignored)",{err:String(r)})),await a1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),Jr.info("launchd job removed",{plistPath:e})}}});import{spawn as h1}from"node:child_process";import{mkdir as x1,unlink as p1,writeFile as g1}from"node:fs/promises";import{dirname as m1,join as Qx}from"node:path";function da(t,e){return t.isRoot?e:["--user",...e]}function _1(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
+ `):""}function la(t,e){return new Promise((r,i)=>{let o=h1(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var ca,Yr,w1,Wd,ep=it(()=>{"use strict";se();ca=G("supervisor.systemd"),Yr="coze-bridge.service",w1="/etc/systemd/system";Wd={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
+ ${_1(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?Qx(w1,Yr):Qx(t.homeDir,".config","systemd","user",Yr)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await x1(m1(i),{recursive:!0}),await g1(i,this.renderConfig(t),"utf8"),ca.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await la("systemctl",da(t,["daemon-reload"])),await la("systemctl",da(t,r?["enable","--now",Yr]:["enable",Yr])),ca.info("systemd unit enabled",{unitName:Yr,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await la("systemctl",da(t,["disable","--now",Yr])).catch(r=>ca.warn("systemctl disable failed (ignored)",{err:String(r)})),await p1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await la("systemctl",da(t,["daemon-reload"])).catch(()=>{}),ca.info("systemd unit removed",{unitPath:e})}}});import{spawn as y1}from"node:child_process";import{join as b1}from"node:path";function tp(t,e){return new Promise((r,i)=>{let o=y1(t,e,{stdio:["ignore","pipe","pipe"],shell:!1}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var Kd,ua,$d,np=it(()=>{"use strict";se();Kd=G("supervisor.taskscheduler"),ua="CozeBridge",$d={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 b1(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 tp("schtasks",["/Create","/SC","ONLOGON","/TN",ua,"/TR",r,"/RU",t.userName,"/F"]),Kd.info("task scheduler entry created",{task:ua,logFile:t.logFile})},async uninstall(t){await tp("schtasks",["/Delete","/TN",ua,"/F"]).catch(e=>Kd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Kd.info("task scheduler entry removed",{task:ua})}}});var rp={};Ia(rp,{buildContext:()=>T1,getSupervisor:()=>S1,launchdSupervisor:()=>qd,systemdSupervisor:()=>Wd,taskSchedulerSupervisor:()=>$d});import{homedir as E1,userInfo as v1}from"node:os";function S1(t=process.platform){switch(t){case"darwin":return qd;case"linux":return Wd;case"win32":return $d;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function A1(){let t={};for(let e of I1){let r=process.env[e];r&&(t[e]=r)}return t}function T1(){let t=ne();return{nodeBin:process.execPath,entry:Nd(t),logFile:t.logFile,homeDir:E1(),userName:v1().username,isRoot:process.getuid?.()===0,env:A1()}}var I1,ip=it(()=>{"use strict";Fe();ea();Xx();ep();np();I1=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});se();dn();var vl=G("acp-installer-warmup"),Rg=["claude-code","codex"];async function Sl(t={}){let e=t.ensure??lr,i=(await Promise.allSettled(Rg.map(async o=>{let c=await e(o);vl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&vl.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))})}fn();se();import{readdir as qg}from"node:fs/promises";import{mkdir as Rl,readFile as Hg,writeFile as kl}from"node:fs/promises";import{join as Pa}from"node:path";var jg={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function hr(t,e,r){await Rl(t,{recursive:!0});let i=jg[e],o=Pa(t,i);return await kl(o,r??"","utf8"),o}async function Oa(t,e,r){let i=Pa(t,".claude");await Rl(i,{recursive:!0});let o=Pa(i,"settings.local.json"),c={};try{let u=await Hg(o,"utf8"),f=JSON.parse(u);typeof f=="object"&&f!==null&&!Array.isArray(f)&&(c=f)}catch{}let d=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")d.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!r)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");d.defaultMode===void 0&&(d.defaultMode=r)}return c.permissions=d,await kl(o,JSON.stringify(c,null,2),"utf8"),o}var et=G("agent-detail-sync"),Wg=6e4,Kg=5*6e4,ms=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await qg(r)}catch(o){et.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}et.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await ze(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){et.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(d){et.warn("detail sync failed for agent, skipping",{agentId:o,err:String(d)})}}})),et.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),r=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&r.push(i);if(r.length!==0){et.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){et.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await ze(e,this.opts.paths);if(!i){et.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(f){et.warn("detail RPC failed, using local data",{agentId:e,err:String(f)});let x=this.retryQueue.get(e),g=x?Math.min(x.currentDelay*2,Kg):Wg;this.retryQueue.set(e,{dueAt:Date.now()+g,currentDelay:g});return}if(o.agentId&&o.agentId!==e){et.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,d=!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,d=!0);let u=!1;if(o.deployType==="cloud"&&i.deployType!=="cloud"?(et.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&et.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){et.debug("detail sync: no diff",{agentId:e});return}await Je(i,this.opts.paths),et.info("detail sync: config updated",{agentId:e,identityChanged:d,agentName:i.agentName}),u?(await this.opts.agentManager.createAgent({agentId:e,framework:i.framework,_meta:{cozeDeployType:"cloud"},cozeIdentity:i.cozeIdentity,model:i.model}),et.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):d&&(await hr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var Yf=qt(cu(),1);import{lstat as $c,mkdir as Vc,readFile as Kf,readdir as A_,rm as $f,stat as T_,writeFile as Jc}from"node:fs/promises";import{dirname as R_,join as At,normalize as k_,relative as Xc,resolve as Zc,sep as Vf}from"node:path";import{Readable as Jf}from"node:stream";import{pipeline as Zf}from"node:stream/promises";import xm from"events";import ot from"fs";import{EventEmitter as Pc}from"node:events";import ju from"node:stream";import{StringDecoder as pm}from"node:string_decoder";import Ku from"node:path";import Ir from"node:fs";import{dirname as Rm,parse as km}from"path";import{EventEmitter as Bm}from"events";import hc from"assert";import{Buffer as Kn}from"buffer";import*as hu from"zlib";import Fm from"zlib";import{posix as wr}from"node:path";import{basename as uw}from"node:path";import Js from"fs";import Lt from"fs";import yu from"path";import{win32 as vw}from"node:path";import Tu from"path";import cf from"node:fs";import Uw from"node:assert";import{randomBytes as df}from"node:crypto";import oe from"node:fs";import Ge from"node:path";import lf from"fs";import io from"node:fs";import Ii from"node:path";import lt from"node:fs";import $w from"node:fs/promises";import Xs from"node:path";import{join as bf}from"node:path";import dt from"node:fs";import Sf from"node:path";var fm=Object.defineProperty,hm=(t,e)=>{for(var r in e)fm(t,r,{get:e[r],enumerable:!0})},du=typeof process=="object"&&process?process:{stdout:null,stderr:null},gm=t=>!!t&&typeof t=="object"&&(t instanceof Jn||t instanceof ju||mm(t)||wm(t)),mm=t=>!!t&&typeof t=="object"&&t instanceof Pc&&typeof t.pipe=="function"&&t.pipe!==ju.Writable.prototype.pipe,wm=t=>!!t&&typeof t=="object"&&t instanceof Pc&&typeof t.write=="function"&&typeof t.end=="function",Wt=Symbol("EOF"),Kt=Symbol("maybeEmitEnd"),xn=Symbol("emittedEnd"),Es=Symbol("emittingEnd"),ci=Symbol("emittedError"),vs=Symbol("closed"),lu=Symbol("read"),Ss=Symbol("flush"),uu=Symbol("flushChunk"),_t=Symbol("encoding"),mr=Symbol("decoder"),He=Symbol("flowing"),di=Symbol("paused"),Er=Symbol("resume"),je=Symbol("buffer"),nt=Symbol("pipes"),qe=Symbol("bufferLength"),za=Symbol("bufferPush"),Is=Symbol("bufferShift"),Qe=Symbol("objectMode"),ke=Symbol("destroyed"),Ua=Symbol("error"),Ga=Symbol("emitData"),fu=Symbol("emitEnd"),Ha=Symbol("emitEnd2"),Dt=Symbol("async"),ja=Symbol("abort"),As=Symbol("aborted"),li=Symbol("signal"),Bn=Symbol("dataListeners"),ct=Symbol("discarded"),ui=t=>Promise.resolve().then(t),_m=t=>t(),ym=t=>t==="end"||t==="finish"||t==="prefinish",bm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,Em=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),qu=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[Er](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},vm=class extends qu{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)}},Sm=t=>!!t.objectMode,Im=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Jn=class extends Pc{[He]=!1;[di]=!1;[nt]=[];[je]=[];[Qe];[_t];[Dt];[mr];[Wt]=!1;[xn]=!1;[Es]=!1;[vs]=!1;[ci]=null;[qe]=0;[ke]=!1;[li];[As]=!1;[Bn]=0;[ct]=!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");Sm(e)?(this[Qe]=!0,this[_t]=null):Im(e)?(this[_t]=e.encoding,this[Qe]=!1):(this[Qe]=!1,this[_t]=null),this[Dt]=!!e.async,this[mr]=this[_t]?new pm(this[_t]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[je]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[nt]});let{signal:r}=e;r&&(this[li]=r,r.aborted?this[ja]():r.addEventListener("abort",()=>this[ja]()))}get bufferLength(){return this[qe]}get encoding(){return this[_t]}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[Qe]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[Dt]}set async(t){this[Dt]=this[Dt]||!!t}[ja](){this[As]=!0,this.emit("abort",this[li]?.reason),this.destroy(this[li]?.reason)}get aborted(){return this[As]}set aborted(t){}write(t,e,r){if(this[As])return!1;if(this[Wt])throw new Error("write after end");if(this[ke])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[Dt]?ui:_m;if(!this[Qe]&&!Buffer.isBuffer(t)){if(Em(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(bm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Qe]?(this[He]&&this[qe]!==0&&this[Ss](!0),this[He]?this.emit("data",t):this[za](t),this[qe]!==0&&this.emit("readable"),r&&i(r),this[He]):t.length?(typeof t=="string"&&!(e===this[_t]&&!this[mr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[_t]&&(t=this[mr].write(t)),this[He]&&this[qe]!==0&&this[Ss](!0),this[He]?this.emit("data",t):this[za](t),this[qe]!==0&&this.emit("readable"),r&&i(r),this[He]):(this[qe]!==0&&this.emit("readable"),r&&i(r),this[He])}read(t){if(this[ke])return null;if(this[ct]=!1,this[qe]===0||t===0||t&&t>this[qe])return this[Kt](),null;this[Qe]&&(t=null),this[je].length>1&&!this[Qe]&&(this[je]=[this[_t]?this[je].join(""):Buffer.concat(this[je],this[qe])]);let e=this[lu](t||null,this[je][0]);return this[Kt](),e}[lu](t,e){if(this[Qe])this[Is]();else{let r=e;t===r.length||t===null?this[Is]():typeof r=="string"?(this[je][0]=r.slice(t),e=r.slice(0,t),this[qe]-=t):(this[je][0]=r.subarray(t),e=r.subarray(0,t),this[qe]-=t)}return this.emit("data",e),!this[je].length&&!this[Wt]&&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[Wt]=!0,this.writable=!1,(this[He]||!this[di])&&this[Kt](),this}[Er](){this[ke]||(!this[Bn]&&!this[nt].length&&(this[ct]=!0),this[di]=!1,this[He]=!0,this.emit("resume"),this[je].length?this[Ss]():this[Wt]?this[Kt]():this.emit("drain"))}resume(){return this[Er]()}pause(){this[He]=!1,this[di]=!0,this[ct]=!1}get destroyed(){return this[ke]}get flowing(){return this[He]}get paused(){return this[di]}[za](t){this[Qe]?this[qe]+=1:this[qe]+=t.length,this[je].push(t)}[Is](){return this[Qe]?this[qe]-=1:this[qe]-=this[je][0].length,this[je].shift()}[Ss](t=!1){do;while(this[uu](this[Is]())&&this[je].length);!t&&!this[je].length&&!this[Wt]&&this.emit("drain")}[uu](t){return this.emit("data",t),this[He]}pipe(t,e){if(this[ke])return t;this[ct]=!1;let r=this[xn];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[nt].push(e.proxyErrors?new vm(this,t,e):new qu(this,t,e)),this[Dt]?ui(()=>this[Er]()):this[Er]()),t}unpipe(t){let e=this[nt].find(r=>r.dest===t);e&&(this[nt].length===1?(this[He]&&this[Bn]===0&&(this[He]=!1),this[nt]=[]):this[nt].splice(this[nt].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[ct]=!1,this[Bn]++,!this[nt].length&&!this[He]&&this[Er]();else if(t==="readable"&&this[qe]!==0)super.emit("readable");else if(ym(t)&&this[xn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[ci]){let i=e;this[Dt]?ui(()=>i.call(this,this[ci])):i.call(this,this[ci])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Bn]=this.listeners("data").length,this[Bn]===0&&!this[ct]&&!this[nt].length&&(this[He]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Bn]=0,!this[ct]&&!this[nt].length&&(this[He]=!1)),e}get emittedEnd(){return this[xn]}[Kt](){!this[Es]&&!this[xn]&&!this[ke]&&this[je].length===0&&this[Wt]&&(this[Es]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[vs]&&this.emit("close"),this[Es]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==ke&&this[ke])return!1;if(t==="data")return!this[Qe]&&!r?!1:this[Dt]?(ui(()=>this[Ga](r)),!0):this[Ga](r);if(t==="end")return this[fu]();if(t==="close"){if(this[vs]=!0,!this[xn]&&!this[ke])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[ci]=r,super.emit(Ua,r);let o=!this[li]||this.listeners("error").length?super.emit("error",r):!1;return this[Kt](),o}else if(t==="resume"){let o=super.emit("resume");return this[Kt](),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[Kt](),i}[Ga](t){for(let r of this[nt])r.dest.write(t)===!1&&this.pause();let e=this[ct]?!1:super.emit("data",t);return this[Kt](),e}[fu](){return this[xn]?!1:(this[xn]=!0,this.readable=!1,this[Dt]?(ui(()=>this[Ha]()),!0):this[Ha]())}[Ha](){if(this[mr]){let e=this[mr].end();if(e){for(let r of this[nt])r.dest.write(e);this[ct]||super.emit("data",e)}}for(let e of this[nt])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Qe]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[Qe]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[Qe])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[_t]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(ke,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[ct]=!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[Wt])return e();let i,o,c=x=>{this.off("data",d),this.off("end",u),this.off(ke,f),e(),o(x)},d=x=>{this.off("error",c),this.off("end",u),this.off(ke,f),this.pause(),i({value:x,done:!!this[Wt]})},u=()=>{this.off("error",c),this.off("data",d),this.off(ke,f),e(),i({done:!0,value:void 0})},f=()=>c(new Error("stream destroyed"));return new Promise((x,g)=>{o=g,i=x,this.once(ke,f),this.once("error",c),this.once("end",u),this.once("data",d)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[ct]=!1;let t=!1,e=()=>(this.pause(),this.off(Ua,e),this.off(ke,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(Ua,e),this.once(ke,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[ke])return t?this.emit("error",t):this.emit(ke),this;this[ke]=!0,this[ct]=!0,this[je].length=0,this[qe]=0;let e=this;return typeof e.close=="function"&&!this[vs]&&e.close(),t?this.emit("error",t):this.emit(ke),this}static get isStream(){return gm}},Am=ot.writev,Sn=Symbol("_autoClose"),vt=Symbol("_close"),fi=Symbol("_ended"),he=Symbol("_fd"),qa=Symbol("_finished"),Zt=Symbol("_flags"),Wa=Symbol("_flush"),uc=Symbol("_handleChunk"),fc=Symbol("_makeBuf"),vi=Symbol("_mode"),Ts=Symbol("_needDrain"),Tr=Symbol("_onerror"),Rr=Symbol("_onopen"),Ka=Symbol("_onread"),vr=Symbol("_onwrite"),In=Symbol("_open"),Et=Symbol("_path"),_n=Symbol("_pos"),Pt=Symbol("_queue"),Sr=Symbol("_read"),$a=Symbol("_readSize"),Jt=Symbol("_reading"),hi=Symbol("_remain"),Va=Symbol("_size"),Bs=Symbol("_write"),Fn=Symbol("_writing"),Fs=Symbol("_defaultFlag"),Wn=Symbol("_errored"),Oc=class extends Jn{[Wn]=!1;[he];[Et];[$a];[Jt]=!1;[Va];[hi];[Sn];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[Wn]=!1,this[he]=typeof e.fd=="number"?e.fd:void 0,this[Et]=t,this[$a]=e.readSize||16*1024*1024,this[Jt]=!1,this[Va]=typeof e.size=="number"?e.size:1/0,this[hi]=this[Va],this[Sn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[he]=="number"?this[Sr]():this[In]()}get fd(){return this[he]}get path(){return this[Et]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[In](){ot.open(this[Et],"r",(t,e)=>this[Rr](t,e))}[Rr](t,e){t?this[Tr](t):(this[he]=e,this.emit("open",e),this[Sr]())}[fc](){return Buffer.allocUnsafe(Math.min(this[$a],this[hi]))}[Sr](){if(!this[Jt]){this[Jt]=!0;let t=this[fc]();if(t.length===0)return process.nextTick(()=>this[Ka](null,0,t));ot.read(this[he],t,0,t.length,null,(e,r,i)=>this[Ka](e,r,i))}}[Ka](t,e,r){this[Jt]=!1,t?this[Tr](t):this[uc](e,r)&&this[Sr]()}[vt](){if(this[Sn]&&typeof this[he]=="number"){let t=this[he];this[he]=void 0,ot.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[Tr](t){this[Jt]=!0,this[vt](),this.emit("error",t)}[uc](t,e){let r=!1;return this[hi]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[hi]<=0)&&(r=!1,this[vt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[he]=="number"&&this[Sr](),!1;case"error":return this[Wn]?!1:(this[Wn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Tm=class extends Oc{[In](){let t=!0;try{this[Rr](null,ot.openSync(this[Et],"r")),t=!1}finally{t&&this[vt]()}}[Sr](){let t=!0;try{if(!this[Jt]){this[Jt]=!0;do{let e=this[fc](),r=e.length===0?0:ot.readSync(this[he],e,0,e.length,null);if(!this[uc](r,e))break}while(!0);this[Jt]=!1}t=!1}finally{t&&this[vt]()}}[vt](){if(this[Sn]&&typeof this[he]=="number"){let t=this[he];this[he]=void 0,ot.closeSync(t),this.emit("close")}}},Qs=class extends xm{readable=!1;writable=!0;[Wn]=!1;[Fn]=!1;[fi]=!1;[Pt]=[];[Ts]=!1;[Et];[vi];[Sn];[he];[Fs];[Zt];[qa]=!1;[_n];constructor(t,e){e=e||{},super(e),this[Et]=t,this[he]=typeof e.fd=="number"?e.fd:void 0,this[vi]=e.mode===void 0?438:e.mode,this[_n]=typeof e.start=="number"?e.start:void 0,this[Sn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[_n]!==void 0?"r+":"w";this[Fs]=e.flags===void 0,this[Zt]=e.flags===void 0?r:e.flags,this[he]===void 0&&this[In]()}emit(t,...e){if(t==="error"){if(this[Wn])return!1;this[Wn]=!0}return super.emit(t,...e)}get fd(){return this[he]}get path(){return this[Et]}[Tr](t){this[vt](),this[Fn]=!0,this.emit("error",t)}[In](){ot.open(this[Et],this[Zt],this[vi],(t,e)=>this[Rr](t,e))}[Rr](t,e){this[Fs]&&this[Zt]==="r+"&&t&&t.code==="ENOENT"?(this[Zt]="w",this[In]()):t?this[Tr](t):(this[he]=e,this.emit("open",e),this[Fn]||this[Wa]())}end(t,e){return t&&this.write(t,e),this[fi]=!0,!this[Fn]&&!this[Pt].length&&typeof this[he]=="number"&&this[vr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[fi]?(this.emit("error",new Error("write() after end()")),!1):this[he]===void 0||this[Fn]||this[Pt].length?(this[Pt].push(t),this[Ts]=!0,!1):(this[Fn]=!0,this[Bs](t),!0)}[Bs](t){ot.write(this[he],t,0,t.length,this[_n],(e,r)=>this[vr](e,r))}[vr](t,e){t?this[Tr](t):(this[_n]!==void 0&&typeof e=="number"&&(this[_n]+=e),this[Pt].length?this[Wa]():(this[Fn]=!1,this[fi]&&!this[qa]?(this[qa]=!0,this[vt](),this.emit("finish")):this[Ts]&&(this[Ts]=!1,this.emit("drain"))))}[Wa](){if(this[Pt].length===0)this[fi]&&this[vr](null,0);else if(this[Pt].length===1)this[Bs](this[Pt].pop());else{let t=this[Pt];this[Pt]=[],Am(this[he],t,this[_n],(e,r)=>this[vr](e,r))}}[vt](){if(this[Sn]&&typeof this[he]=="number"){let t=this[he];this[he]=void 0,ot.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Wu=class extends Qs{[In](){let t;if(this[Fs]&&this[Zt]==="r+")try{t=ot.openSync(this[Et],this[Zt],this[vi])}catch(e){if(e?.code==="ENOENT")return this[Zt]="w",this[In]();throw e}else t=ot.openSync(this[Et],this[Zt],this[vi]);this[Rr](null,t)}[vt](){if(this[Sn]&&typeof this[he]=="number"){let t=this[he];this[he]=void 0,ot.closeSync(t),this.emit("close")}}[Bs](t){let e=!0;try{this[vr](null,ot.writeSync(this[he],t,0,t.length,this[_n])),e=!1}finally{if(e)try{this[vt]()}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"]]),Dm=t=>!!t.sync&&!!t.file,Pm=t=>!t.sync&&!!t.file,Om=t=>!!t.sync&&!t.file,Lm=t=>!t.sync&&!t.file,Nm=t=>!!t.file,Mm=t=>Cm.get(t)||t,Lc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=Mm(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Pi=(t,e,r,i,o)=>Object.assign((c=[],d,u)=>{Array.isArray(c)&&(d=c,c={}),typeof d=="function"&&(u=d,d=void 0),d=d?Array.from(d):[];let f=Lc(c);if(o?.(f,d),Dm(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(f,d)}else if(Pm(f)){let x=e(f,d);return u?x.then(()=>u(),u):x}else if(Om(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(f,d)}else if(Lm(f)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(f,d)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),zm=Fm.constants||{ZLIB_VERNUM:4736},Mt=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},zm)),Um=Kn.concat,xu=Object.getOwnPropertyDescriptor(Kn,"concat"),Gm=t=>t,Ja=xu?.writable===!0||xu?.set!==void 0?t=>{Kn.concat=t?Gm:Um}:t=>{},$n=Symbol("_superWrite"),Rs=class extends Error{code;errno;constructor(t,e){super("zlib: "+t.message,{cause:t}),this.code=t.code,this.errno=t.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+t.message,Error.captureStackTrace(this,e??this.constructor)}get name(){return"ZlibError"}},Za=Symbol("flushFlag"),Nc=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 hu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new hu[e](t)}catch(r){throw new Rs(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 Rs(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return hc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Kn.alloc(0),{[Za]:t})))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(r)}get ended(){return this.#n}[$n](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Kn.from(t,e)),this.#e)return;hc(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 d;try{let f=typeof t[Za]=="number"?t[Za]:this.#r;d=this.#t._processChunk(t,f),Ja(!1)}catch(f){Ja(!1),this.#o(new Rs(f,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",f=>this.#o(new Rs(f,this.write)));let u;if(d)if(Array.isArray(d)&&d.length>0){let f=d[0];u=this[$n](Kn.from(f));for(let x=1;x<d.length;x++)u=this[$n](d[x])}else u=this[$n](Kn.from(d));return r&&r(),u}},$u=class extends Nc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Mt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Mt.Z_FINISH,t.fullFlushFlag=Mt.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(Mt.Z_SYNC_FLUSH),hc(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)}}}},Hm=class extends $u{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[$n](t){return this.#e?(this.#e=!1,t[9]=255,super[$n](t)):super[$n](t)}},jm=class extends $u{constructor(t){super(t,"Unzip")}},Vu=class extends Nc{constructor(t,e){t=t||{},t.flush=t.flush||Mt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Mt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Mt.BROTLI_OPERATION_FLUSH,super(t,e)}},qm=class extends Vu{constructor(t){super(t,"BrotliCompress")}},Wm=class extends Vu{constructor(t){super(t,"BrotliDecompress")}},Ju=class extends Nc{constructor(t,e){t=t||{},t.flush=t.flush||Mt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Mt.ZSTD_e_end,t.fullFlushFlag=Mt.ZSTD_e_flush,super(t,e)}},Km=class extends Ju{constructor(t){super(t,"ZstdCompress")}},$m=class extends Ju{constructor(t){super(t,"ZstdDecompress")}},Vm=(t,e)=>{if(Number.isSafeInteger(t))t<0?Zm(t,e):Jm(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Jm=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},Zm=(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]=Zu(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Yu(o))}},Ym=t=>{let e=t[0],r=e===128?Qm(t.subarray(1,t.length)):e===255?Xm(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},Xm=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),d;i?d=Zu(c):c===0?d=c:(i=!0,d=Yu(c)),d!==0&&(r-=d*Math.pow(256,e-o-1))}return r},Qm=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},Zu=t=>(255^t)&255,Yu=t=>(255^t)+1&255,ew={};hm(ew,{code:()=>Mc,isCode:()=>zs,isName:()=>tw,name:()=>eo,normalFsTypes:()=>Xu});var zs=t=>eo.has(t),tw=t=>Mc.has(t),Xu=new Set(["0","","1","2","3","4","5","6","7","D"]),eo=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"]]),Mc=new Map(Array.from(eo).map(t=>[t[1],t[0]])),Vn=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=zn(t,e+156,1),c=Xu.has(o),d=c?r:void 0,u=c?i:void 0;if(this.path=d?.path??zn(t,e,100),this.mode=d?.mode??u?.mode??yn(t,e+100,8),this.uid=d?.uid??u?.uid??yn(t,e+108,8),this.gid=d?.gid??u?.gid??yn(t,e+116,8),this.size=d?.size??u?.size??yn(t,e+124,12),this.mtime=d?.mtime??u?.mtime??Ya(t,e+136,12),this.cksum=yn(t,e+148,12),u&&this.#n(u,!0),d&&this.#n(d),zs(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=zn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=d?.uname??u?.uname??zn(t,e+265,32),this.gname=d?.gname??u?.gname??zn(t,e+297,32),this.devmaj=d?.devmaj??u?.devmaj??yn(t,e+329,8)??0,this.devmin=d?.devmin??u?.devmin??yn(t,e+337,8)??0,t[e+475]!==0){let x=zn(t,e+345,155);this.path=x+"/"+this.path}else{let x=zn(t,e+345,130);x&&(this.path=x+"/"+this.path),this.atime=r?.atime??i?.atime??Ya(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Ya(t,e+488,12)}let f=256;for(let x=e;x<e+148;x++)f+=t[x];for(let x=e+156;x<e+512;x++)f+=t[x];this.cksumValid=f===this.cksum,this.cksum===void 0&&f===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=nw(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Un(t,e,100,o)||this.needPax,this.needPax=bn(t,e+100,8,this.mode)||this.needPax,this.needPax=bn(t,e+108,8,this.uid)||this.needPax,this.needPax=bn(t,e+116,8,this.gid)||this.needPax,this.needPax=bn(t,e+124,12,this.size)||this.needPax,this.needPax=Xa(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Un(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Un(t,e+265,32,this.uname)||this.needPax,this.needPax=Un(t,e+297,32,this.gname)||this.needPax,this.needPax=bn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=bn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Un(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=Un(t,e+345,155,c)||this.needPax:(this.needPax=Un(t,e+345,130,c)||this.needPax,this.needPax=Xa(t,e+476,12,this.atime)||this.needPax,this.needPax=Xa(t,e+488,12,this.ctime)||this.needPax);let d=256;for(let u=e;u<e+148;u++)d+=t[u];for(let u=e+156;u<e+512;u++)d+=t[u];return this.cksum=d,bn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:eo.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Mc.get(t));if(zs(e)||e==="Unsupported")this.#e=e;else if(zs(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},nw=(t,e)=>{let r=t,i="",o,c=wr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=wr.dirname(r),r=wr.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=wr.join(wr.basename(i),r),i=wr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},zn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Ya=(t,e,r)=>rw(yn(t,e,r)),rw=t=>t===void 0?void 0:new Date(t*1e3),yn=(t,e,r)=>Number(t[e])&128?Ym(t.subarray(e,e+r)):sw(t,e,r),iw=t=>isNaN(t)?void 0:t,sw=(t,e,r)=>iw(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),ow={12:8589934591,8:2097151},bn=(t,e,r,i)=>i===void 0?!1:i>ow[r]||i<0?(Vm(i,t.subarray(e,e+r)),!0):(aw(t,e,r,i),!1),aw=(t,e,r,i)=>t.write(cw(i,r),e,r,"ascii"),cw=(t,e)=>dw(Math.floor(t).toString(8),e),dw=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Xa=(t,e,r,i)=>i===void 0?!1:bn(t,e,r,i.getTime()/1e3),lw=new Array(156).join("\0"),Un=(t,e,r,i)=>i===void 0?!1:(t.write(i+lw,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),Vs=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 Vn({path:("PaxHeader/"+uw(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:r,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(o),o.write(e,512,r,"utf8");for(let c=r+512;c<o.length;c++)o[c]=0;return o}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let r=this[e],i=r instanceof Date?r.getTime()/1e3:r,o=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+i+`
90
+ `,c=Buffer.byteLength(o),d=Math.floor(Math.log(c)/Math.log(10))+1;return c+d>=Math.pow(10,d)&&(d+=1),d+c+o}static parse(e,r,i=!1){return new Qu(fw(hw(e),r),i)}},fw=(t,e)=>e?Object.assign({},e,t):t,hw=t=>t.replace(/\n$/,"").split(`
91
+ `).reduce(xw,Object.create(null)),xw=(t,e)=>{let r=parseInt(e,10);if(r!==Buffer.byteLength(e)+1)return t;e=e.slice((r+" ").length);let i=e.split("="),o=i.shift();if(!o)return t;let c=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),d=i.join("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(d)*1e3):/^[0-9]+$/.test(d)?+d:d,t},pw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,ee=pw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),gw=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=ee(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?ee(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=ee(t.path)),t.linkpath&&(t.linkpath=ee(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},to=(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))},mw=1024*1024,xc=Buffer.from([31,139]),pc=Buffer.from([40,181,47,253]),ww=Math.max(xc.length,pc.length),ht=Symbol("state"),Gn=Symbol("writeEntry"),$t=Symbol("readEntry"),Qa=Symbol("nextEntry"),pu=Symbol("processEntry"),Ot=Symbol("extendedHeader"),xi=Symbol("globalExtendedHeader"),pn=Symbol("meta"),gu=Symbol("emitMeta"),ye=Symbol("buffer"),Vt=Symbol("queue"),gn=Symbol("ended"),ec=Symbol("emittedEnd"),Hn=Symbol("emit"),Oe=Symbol("unzip"),ks=Symbol("consumeChunk"),Cs=Symbol("consumeChunkSub"),tc=Symbol("consumeBody"),mu=Symbol("consumeMeta"),wu=Symbol("consumeHeader"),pi=Symbol("consuming"),nc=Symbol("bufferConcat"),Ds=Symbol("maybeEnd"),_r=Symbol("writing"),mn=Symbol("aborted"),Ps=Symbol("onDone"),jn=Symbol("sawValidEntry"),Os=Symbol("sawNullBlock"),Ls=Symbol("sawEOF"),_u=Symbol("closeStream"),_w=()=>!0,Di=class extends Bm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Vt]=[];[ye];[$t];[Gn];[ht]="begin";[pn]="";[Ot];[xi];[gn]=!1;[Oe];[mn]=!1;[jn];[Os]=!1;[Ls]=!1;[_r]=!1;[pi]=!1;[ec]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Ps,()=>{(this[ht]==="begin"||this[jn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Ps,t.ondone):this.on(Ps,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||mw,this.filter=typeof t.filter=="function"?t.filter:_w;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={}){to(this,t,e,r)}[wu](t,e){this[jn]===void 0&&(this[jn]=!1);let r;try{r=new Vn(t,e,this[Ot],this[xi])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Os]?(this[Ls]=!0,this[ht]==="begin"&&(this[ht]="header"),this[Hn]("eof")):(this[Os]=!0,this[Hn]("nullBlock"));else if(this[Os]=!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[Gn]=new gw(r,this[Ot],this[xi]);if(!this[jn])if(o.remain){let c=()=>{o.invalid||(this[jn]=!0)};o.on("end",c)}else this[jn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Hn]("ignoredEntry",o),this[ht]="ignore",o.resume()):o.size>0&&(this[pn]="",o.on("data",c=>this[pn]+=c),this[ht]="meta"):(this[Ot]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Hn]("ignoredEntry",o),this[ht]=o.remain?"ignore":"header",o.resume()):(o.remain?this[ht]="body":(this[ht]="header",o.end()),this[$t]?this[Vt].push(o):(this[Vt].push(o),this[Qa]())))}}}[_u](){queueMicrotask(()=>this.emit("close"))}[pu](t){let e=!0;if(!t)this[$t]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[$t]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Qa]()),e=!1);return e}[Qa](){do;while(this[pu](this[Vt].shift()));if(this[Vt].length===0){let t=this[$t];!t||t.flowing||t.size===t.remain?this[_r]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[tc](t,e){let r=this[Gn];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[ht]="header",this[Gn]=void 0,r.end()),o.length}[mu](t,e){let r=this[Gn],i=this[tc](t,e);return!this[Gn]&&r&&this[gu](r),i}[Hn](t,e,r){this[Vt].length===0&&!this[$t]?this.emit(t,e,r):this[Vt].push([t,e,r])}[gu](t){switch(this[Hn]("meta",this[pn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Ot]=Vs.parse(this[pn],this[Ot],!1);break;case"GlobalExtendedHeader":this[xi]=Vs.parse(this[pn],this[xi],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Ot]??Object.create(null);this[Ot]=e,e.path=this[pn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Ot]||Object.create(null);this[Ot]=e,e.linkpath=this[pn].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[mn]=!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[mn])return r?.(),!1;if((this[Oe]===void 0||this.brotli===void 0&&this[Oe]===!1)&&t){if(this[ye]&&(t=Buffer.concat([this[ye],t]),this[ye]=void 0),t.length<ww)return this[ye]=t,r?.(),!0;for(let d=0;this[Oe]===void 0&&d<xc.length;d++)t[d]!==xc[d]&&(this[Oe]=!1);let o=!1;if(this[Oe]===!1&&this.zstd!==!1){o=!0;for(let d=0;d<pc.length;d++)if(t[d]!==pc[d]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Oe]===!1&&c)if(t.length<512)if(this[gn])this.brotli=!0;else return this[ye]=t,r?.(),!0;else try{new Vn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Oe]===void 0||this[Oe]===!1&&(this.brotli||o)){let d=this[gn];this[gn]=!1,this[Oe]=this[Oe]===void 0?new jm({}):o?new $m({}):new Wm({}),this[Oe].on("data",f=>this[ks](f)),this[Oe].on("error",f=>this.abort(f)),this[Oe].on("end",()=>{this[gn]=!0,this[ks]()}),this[_r]=!0;let u=!!this[Oe][d?"end":"write"](t);return this[_r]=!1,r?.(),u}}this[_r]=!0,this[Oe]?this[Oe].write(t):this[ks](t),this[_r]=!1;let i=this[Vt].length>0?!1:this[$t]?this[$t].flowing:!0;return!i&&this[Vt].length===0&&this[$t]?.once("drain",()=>this.emit("drain")),r?.(),i}[nc](t){t&&!this[mn]&&(this[ye]=this[ye]?Buffer.concat([this[ye],t]):t)}[Ds](){if(this[gn]&&!this[ec]&&!this[mn]&&!this[pi]){this[ec]=!0;let t=this[Gn];if(t&&t.blockRemain){let e=this[ye]?this[ye].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[ye]&&t.write(this[ye]),t.end()}this[Hn](Ps)}}[ks](t){if(this[pi]&&t)this[nc](t);else if(!t&&!this[ye])this[Ds]();else if(t){if(this[pi]=!0,this[ye]){this[nc](t);let e=this[ye];this[ye]=void 0,this[Cs](e)}else this[Cs](t);for(;this[ye]&&this[ye]?.length>=512&&!this[mn]&&!this[Ls];){let e=this[ye];this[ye]=void 0,this[Cs](e)}this[pi]=!1}(!this[ye]||this[gn])&&this[Ds]()}[Cs](t){let e=0,r=t.length;for(;e+512<=r&&!this[mn]&&!this[Ls];)switch(this[ht]){case"begin":case"header":this[wu](t,e),e+=512;break;case"ignore":case"body":e+=this[tc](t,e);break;case"meta":e+=this[mu](t,e);break;default:throw new Error("invalid state: "+this[ht])}e<r&&(this[ye]=this[ye]?Buffer.concat([t.subarray(e),this[ye]]):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[mn]||(this[Oe]?(t&&this[Oe].write(t),this[Oe].end()):(this[gn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Ds]())),this}},Si=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)},yw=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=>[Si(c),!0])),i=t.filter,o=(c,d="")=>{let u=d||km(c).root||".",f;if(c===u)f=!1;else{let x=r.get(c);f=x!==void 0?x:o(Rm(c),u)}return r.set(c,f),f};t.filter=i?(c,d)=>i(c,d)&&o(Si(c)):c=>o(Si(c))},bw=t=>{let e=new Di(t),r=t.file,i;try{i=Ir.openSync(r,"r");let o=Ir.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let d=Buffer.allocUnsafe(o.size),u=Ir.readSync(i,d,0,o.size,0);e.end(u===d.byteLength?d:d.subarray(0,u))}else{let d=0,u=Buffer.allocUnsafe(c);for(;d<o.size;){let f=Ir.readSync(i,u,0,c,d);if(f===0)break;d+=f,e.write(u.subarray(0,f))}e.end()}}finally{if(typeof i=="number")try{Ir.closeSync(i)}catch{}}},Ew=(t,e)=>{let r=new Di(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("end",c),Ir.stat(o,(u,f)=>{if(u)d(u);else{let x=new Oc(o,{readSize:i,size:f.size});x.on("error",d),x.pipe(r)}})})},kr=Pi(bw,Ew,t=>new Di(t),t=>new Di(t),(t,e)=>{e?.length&&ef(t,e),t.noResume||yw(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:Sw,parse:bu}=vw,Bc=t=>{let e="",r=bu(t);for(;Sw(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=bu(t)}return[e,t]},no=["|","<",">","?",":"],Fc=no.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),Iw=new Map(no.map((t,e)=>[t,Fc[e]])),Aw=new Map(Fc.map((t,e)=>[t,no[e]])),Eu=t=>no.reduce((e,r)=>e.split(r).join(Iw.get(r)),t),Tw=t=>Fc.reduce((e,r)=>e.split(r).join(Aw.get(r)),t),nf=(t,e)=>e?(t=ee(t).replace(/^\.(\/|$)/,""),Si(e)+"/"+t):ee(t),Rw=16*1024*1024,vu=Symbol("process"),Su=Symbol("file"),Iu=Symbol("directory"),gc=Symbol("symlink"),Au=Symbol("hardlink"),gi=Symbol("header"),Us=Symbol("read"),mc=Symbol("lstat"),Gs=Symbol("onlstat"),wc=Symbol("onread"),_c=Symbol("onreadlink"),yc=Symbol("openfile"),bc=Symbol("onopenfile"),En=Symbol("close"),Zs=Symbol("mode"),Ec=Symbol("awaitDrain"),rc=Symbol("ondrain"),Nt=Symbol("prefix"),rf=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=Lc(e);super(),this.path=ee(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||Rw,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=ee(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?ee(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,d]=Bc(this.path);c&&typeof d=="string"&&(this.path=d,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Tw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=ee(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[Gs](o):this[mc]()}warn(t,e,r={}){return to(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[mc](){Lt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Gs](e)})}[Gs](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=Dw(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[gc]();default:return this.end()}}[Zs](t){return tf(t,this.type==="Directory",this.portable)}[Nt](t){return nf(t,this.prefix)}[gi](){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 Vn({path:this[Nt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Nt](this.linkpath):this.linkpath,mode:this[Zs](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new Vs({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[Nt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Nt](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[gi](),this.end()}[gc](){Lt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[_c](e)})}[_c](t){this.linkpath=ee(t),this[gi](),this.end()}[Au](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=ee(yu.relative(this.cwd,t)),this.stat.size=0,this[gi](),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[gi](),this.stat.size===0)return this.end();this[yc]()}[yc](){Lt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[bc](e)})}[bc](t){if(this.fd=t,this.#e)return this[En]();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[Us]()}[Us](){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");Lt.read(t,e,r,i,o,(c,d)=>{if(c)return this[En](()=>this.emit("error",c));this[wc](d)})}[En](t=()=>{}){this.fd!==void 0&&Lt.close(this.fd,t)}[wc](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[En](()=>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[En](()=>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[rc]():this[Ec](()=>this[rc]())}[Ec](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)}[rc](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[En](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[Us]()}},kw=class extends rf{sync=!0;[mc](){this[Gs](Lt.lstatSync(this.absolute))}[gc](){this[_c](Lt.readlinkSync(this.absolute))}[yc](){this[bc](Lt.openSync(this.absolute,"r"))}[Us](){let t=!0;try{let{fd:e,buf:r,offset:i,length:o,pos:c}=this;if(e===void 0||r===void 0)throw new Error("fd and buf must be set in READ method");let d=Lt.readSync(e,r,i,o,c);this[wc](d),t=!1}finally{if(t)try{this[En](()=>{})}catch{}}}[Ec](t){t()}[En](t=()=>{}){this.fd!==void 0&&Lt.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 to(this,t,e,r)}constructor(t,e={}){let r=Lc(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=ee(t.path),this.mode=t.mode!==void 0?this[Zs](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?ee(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[d,u]=Bc(this.path);d&&typeof u=="string"&&(this.path=u,o=d)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Vn({path:this[Nt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Nt](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 Vs({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[Nt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Nt](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)}[Nt](t){return nf(t,this.prefix)}[Zs](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}},Dw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",Pw=class Ar{tail;head;length=0;static create(e=[]){return new Ar(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++)Lw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)Nw(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 Ar;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 Ar;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 Ar;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 Ar;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.length,c=this.tail;for(;c&&o>r;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,r=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let d=0;o&&d<e;d++)o=o.next;let c=[];for(let d=0;o&&d<r;d++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let d of i)o=Ow(this,o,d);return c}reverse(){let e=this.head,r=this.tail;for(let i=e;i;i=i.prev){let o=i.prev;i.prev=i.next,i.next=o}return this.head=r,this.tail=e,this}};function Ow(t,e,r){let i=e,o=e?e.next:t.head,c=new zc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function Lw(t,e){t.tail=new zc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function Nw(t,e){t.head=new zc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var zc=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}},Ru=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),Hs=Symbol("onStat"),mi=Symbol("ended"),yt=Symbol("queue"),wi=Symbol("pendingLinks"),wn=Symbol("current"),qn=Symbol("process"),_i=Symbol("processing"),Ns=Symbol("processJob"),bt=Symbol("jobs"),ic=Symbol("jobDone"),js=Symbol("addFSEntry"),Cu=Symbol("addTarEntry"),vc=Symbol("stat"),Sc=Symbol("readdir"),qs=Symbol("onreaddir"),Ws=Symbol("pipe"),Du=Symbol("entry"),sc=Symbol("entryOpt"),Ks=Symbol("writeEntryClass"),sf=Symbol("write"),oc=Symbol("ondrain"),ro=class extends Jn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Ks];onWriteEntry;[yt];[wi]=new Map;[bt]=0;[_i]=!1;[mi]=!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=ee(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[Ks]=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 Hm(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new qm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new Km(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[oc]()),this.on("resume",()=>e.resume())}else this.on("drain",this[oc]);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[yt]=new Pw,this[bt]=0,this.jobs=Number(t.jobs)||4,this[_i]=!1,this[mi]=!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[mi]=!0,this[qn](),r&&r(),this}write(t){if(this[mi])throw new Error("write after end");return typeof t=="string"?this[js](t):this[Cu](t),this.flowing}[Cu](t){let e=ee(Tu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Ru(t.path,e);r.entry=new Cw(t,this[sc](r)),r.entry.on("end",()=>this[ic](r)),this[bt]+=1,this[yt].push(r)}this[qn]()}[js](t){let e=ee(Tu.resolve(this.cwd,t));this[yt].push(new Ru(t,e)),this[qn]()}[vc](t){t.pending=!0,this[bt]+=1;let e=this.follow?"stat":"lstat";Js[e](t.absolute,(r,i)=>{t.pending=!1,this[bt]-=1,r?this.emit("error",r):this[Hs](t,i)})}[Hs](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[wn])this[Ns](t);else{let r=`${e.dev}:${e.ino}`,i=this[wi].get(r);i?i.push(t):this[wi].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[qn]()}[Sc](t){t.pending=!0,this[bt]+=1,Js.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[bt]-=1,e)return this.emit("error",e);this[qs](t,r)})}[qs](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[qn]()}[qn](){if(!this[_i]){this[_i]=!0;for(let t=this[yt].head;t&&this[bt]<this.jobs;t=t.next)if(this[Ns](t.value),t.value.ignore){let e=t.next;this[yt].removeNode(t),t.next=e}this[_i]=!1,this[mi]&&this[yt].length===0&&this[bt]===0&&(this.zip?this.zip.end(ku):(super.write(ku),super.end()))}}get[wn](){return this[yt]&&this[yt].head&&this[yt].head.value}[ic](t){this[yt].shift(),this[bt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[wi].get(r);if(i){this[wi].delete(r);for(let o of i)o.pending=!1,this[Ns](o)}}this[qn]()}[Ns](t){if(t.pending&&t.pendingLink&&t===this[wn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[wn]&&!t.piped&&this[Ws](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Hs](t,e):this[vc](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[Sc](t),!t.readdir)return}if(t.entry=this[Du](t),!t.entry){t.ignore=!0;return}t===this[wn]&&!t.piped&&this[Ws](t)}}}[sc](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[bt]+=1;try{return new this[Ks](t.path,this[sc](t)).on("end",()=>this[ic](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[oc](){this[wn]&&this[wn].entry&&this[wn].entry.resume()}[Ws](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[js](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={}){to(this,t,e,r)}},Uc=class extends ro{sync=!0;constructor(t){super(t),this[Ks]=kw}pause(){}resume(){}[vc](t){let e=this.follow?"statSync":"lstatSync";this[Hs](t,Js[e](t.absolute))}[Sc](t){this[qs](t,Js.readdirSync(t.absolute))}[Ws](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[js](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)})}},Mw=(t,e)=>{let r=new Uc(t),i=new Wu(t.file,{mode:t.mode||438});r.pipe(i),of(r,e)},Bw=(t,e)=>{let r=new ro(t),i=new Qs(t.file,{mode:t.mode||438});r.pipe(i);let o=new Promise((c,d)=>{i.on("error",d),i.on("close",c),r.on("error",d)});return af(r,e).catch(c=>r.emit("error",c)),o},of=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?kr({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 kr({file:Ku.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},Fw=(t,e)=>{let r=new Uc(t);return of(r,e),r},zw=(t,e)=>{let r=new ro(t);return af(r,e).catch(i=>r.emit("error",i)),r},dI=Pi(Mw,Bw,Fw,zw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),Gw=process.env.__FAKE_PLATFORM__||process.platform,uf=Gw==="win32",{O_CREAT:ff,O_NOFOLLOW:Pu,O_TRUNC:hf,O_WRONLY:xf}=lf.constants,pf=Number(process.env.__FAKE_FS_O_FILENAME__)||lf.constants.UV_FS_O_FILEMAP||0,Hw=uf&&!!pf,jw=512*1024,qw=pf|hf|ff|xf,Ou=!uf&&typeof Pu=="number"?Pu|hf|ff|xf:null,gf=Ou!==null?()=>Ou:Hw?t=>t<jw?qw:"w":()=>"w",Ic=(t,e,r)=>{try{return io.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},Ys=(t,e,r,i)=>{io.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},Ww=(t,e,r,i,o)=>{if(e.isDirectory())mf(Ii.resolve(t,e.name),r,i,c=>{if(c)return o(c);let d=Ii.resolve(t,e.name);Ys(d,r,i,o)});else{let c=Ii.resolve(t,e.name);Ys(c,r,i,o)}},mf=(t,e,r,i)=>{io.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 Ys(t,e,r,i);let d=c.length,u=null,f=x=>{if(!u){if(x)return i(u=x);if(--d===0)return Ys(t,e,r,i)}};for(let x of c)Ww(t,x,e,r,f)})},Kw=(t,e,r,i)=>{e.isDirectory()&&wf(Ii.resolve(t,e.name),r,i),Ic(Ii.resolve(t,e.name),r,i)},wf=(t,e,r)=>{let i;try{i=io.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return Ic(t,e,r);throw c}for(let o of i)Kw(t,o,e,r);return Ic(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"}},so=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"}},Vw=(t,e)=>{lt.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new _f(t,r?.code||"ENOTDIR")),e(r)})},Jw=(t,e,r)=>{t=ee(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,d=e.uid,u=e.gid,f=typeof d=="number"&&typeof u=="number"&&(d!==e.processUid||u!==e.processGid),x=e.preserve,g=e.unlink,w=ee(e.cwd),S=(b,I)=>{b?r(b):I&&f?mf(I,d,u,T=>S(T)):c?lt.chmod(t,o,r):r()};if(t===w)return Vw(t,S);if(x)return $w.mkdir(t,{mode:o,recursive:!0}).then(b=>S(null,b??void 0),S);let _=ee(Xs.relative(w,t)).split("/");Ac(w,_,o,g,w,void 0,S)},Ac=(t,e,r,i,o,c,d)=>{if(e.length===0)return d(null,c);let u=e.shift(),f=ee(Xs.resolve(t+"/"+u));lt.mkdir(f,r,yf(f,e,r,i,o,c,d))},yf=(t,e,r,i,o,c,d)=>u=>{u?lt.lstat(t,(f,x)=>{if(f)f.path=f.path&&ee(f.path),d(f);else if(x.isDirectory())Ac(t,e,r,i,o,c,d);else if(i)lt.unlink(t,g=>{if(g)return d(g);lt.mkdir(t,r,yf(t,e,r,i,o,c,d))});else{if(x.isSymbolicLink())return d(new so(t,t+"/"+e.join("/")));d(u)}}):(c=c||t,Ac(t,e,r,i,o,c,d))},Zw=t=>{let e=!1,r;try{e=lt.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new _f(t,r??"ENOTDIR")}},Yw=(t,e)=>{t=ee(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,d=e.gid,u=typeof c=="number"&&typeof d=="number"&&(c!==e.processUid||d!==e.processGid),f=e.preserve,x=e.unlink,g=ee(e.cwd),w=b=>{b&&u&&wf(b,c,d),o&&lt.chmodSync(t,i)};if(t===g)return Zw(g),w();if(f)return w(lt.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=ee(Xs.relative(g,t)).split("/"),_;for(let b=S.shift(),I=g;b&&(I+="/"+b);b=S.shift()){I=ee(Xs.resolve(I));try{lt.mkdirSync(I,i),_=_||I}catch{let T=lt.lstatSync(I);if(T.isDirectory())continue;if(x){lt.unlinkSync(I),lt.mkdirSync(I,i),_=_||I;continue}else if(T.isSymbolicLink())return new so(I,I+"/"+S.join("/"))}}return w(_)},ac=Object.create(null),Lu=1e4,yr=new Set,Xw=t=>{yr.has(t)?yr.delete(t):ac[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),yr.add(t);let e=ac[t],r=yr.size-Lu;if(r>Lu/10){for(let i of yr)if(yr.delete(i),delete ac[i],--r<=0)break}return e},Qw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,e_=Qw==="win32",t_=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=bf(i,r)),e.push(r||"/"),e},[]),n_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=e_?["win32 parallelization disabled"]:t.map(i=>Si(bf(Xw(i))));let r=new Set(t.map(i=>t_(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let d=this.#e.get(c);if(!d||d?.[0]!==t)continue;let u=d[1];if(!u){this.#e.delete(c);continue}if(d.shift(),typeof u=="function")o.add(u);else for(let f of u)o.add(f)}for(let c of i){let d=this.#e.get(c),u=d?.[0];if(!(!d||!(u instanceof Set)))if(u.size===1&&d.length===1){this.#e.delete(c);continue}else if(u.size===1){d.shift();let f=d[0];typeof f=="function"&&o.add(f)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},r_=()=>process.umask(),Nu=Symbol("onEntry"),Tc=Symbol("checkFs"),Mu=Symbol("checkFs2"),Rc=Symbol("isReusable"),xt=Symbol("makeFs"),kc=Symbol("file"),Cc=Symbol("directory"),$s=Symbol("link"),Bu=Symbol("symlink"),Fu=Symbol("hardlink"),Ei=Symbol("ensureNoSymlink"),zu=Symbol("unsupported"),Uu=Symbol("checkPath"),cc=Symbol("stripAbsolutePath"),vn=Symbol("mkdir"),We=Symbol("onError"),Ms=Symbol("pending"),Gu=Symbol("pend"),br=Symbol("unpend"),dc=Symbol("ended"),lc=Symbol("maybeClose"),Dc=Symbol("skip"),Ai=Symbol("doChown"),Ti=Symbol("uid"),Ri=Symbol("gid"),ki=Symbol("checkedCwd"),i_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ci=i_==="win32",s_=1024,o_=(t,e)=>{if(!Ci)return oe.unlink(t,e);let r=t+".DELETE."+df(16).toString("hex");oe.rename(t,r,i=>{if(i)return e(i);oe.unlink(r,e)})},a_=t=>{if(!Ci)return oe.unlinkSync(t);let e=t+".DELETE."+df(16).toString("hex");oe.renameSync(t,e),oe.unlinkSync(e)},Hu=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Gc=class extends Di{[dc]=!1;[ki]=!1;[Ms]=0;reservations=new n_;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[dc]=!0,this[lc]()},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:s_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Ci,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=ee(Ge.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:r_():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)}[lc](){this[dc]&&this[Ms]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[cc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Bc(r),d=c.replaceAll(/\\/g,"/").split("/");if(d.includes("..")||Ci&&/^[a-z]:\.\.$/i.test(d[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let u=Ge.posix.dirname(t.path),f=Ge.posix.normalize(Ge.posix.join(u,d.join("/")));if(f.startsWith("../")||f==="..")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=ee(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=ee(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[cc](t,"path")||!this[cc](t,"linkpath"))return!1;if(t.absolute=Ge.isAbsolute(t.path)?ee(Ge.resolve(t.path)):ee(Ge.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:ee(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}=Ge.win32.parse(String(t.absolute));t.absolute=i+Eu(String(t.absolute).slice(i.length));let{root:o}=Ge.win32.parse(t.path);t.path=o+Eu(t.path.slice(o.length))}return!0}[Nu](t){if(!this[Uu](t))return t.resume();switch(Uw.equal(typeof t.absolute,"string"),t.type){case"Directory":case"GNUDumpDir":t.mode&&(t.mode=t.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[Tc](t);default:return this[zu](t)}}[We](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[br](),e.resume())}[vn](t,e,r){Jw(ee(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)}[Ai](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}[Ti](t){return Hu(this.uid,t.uid,this.processUid)}[Ri](t){return Hu(this.gid,t.gid,this.processGid)}[kc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Qs(String(t.absolute),{flags:gf(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&oe.close(i.fd,()=>{}),i.write=()=>!0,this[We](u,t),e()});let o=1,c=u=>{if(u){i.fd&&oe.close(i.fd,()=>{}),this[We](u,t),e();return}--o===0&&i.fd!==void 0&&oe.close(i.fd,f=>{f?this[We](f,t):this[br](),e()})};i.on("finish",()=>{let u=String(t.absolute),f=i.fd;if(typeof f=="number"&&t.mtime&&!this.noMtime){o++;let x=t.atime||new Date,g=t.mtime;oe.futimes(f,x,g,w=>w?oe.utimes(u,x,g,S=>c(S&&w)):c())}if(typeof f=="number"&&this[Ai](t)){o++;let x=this[Ti](t),g=this[Ri](t);typeof x=="number"&&typeof g=="number"&&oe.fchown(f,x,g,w=>w?oe.chown(u,x,g,S=>c(S&&w)):c())}c()});let d=this.transform&&this.transform(t)||t;d!==t&&(d.on("error",u=>{this[We](u,t),e()}),t.pipe(d)),d.pipe(i)}[Cc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[vn](String(t.absolute),r,i=>{if(i){this[We](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[br](),t.resume())};t.mtime&&!this.noMtime&&(o++,oe.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[Ai](t)&&(o++,oe.chown(String(t.absolute),Number(this[Ti](t)),Number(this[Ri](t)),c)),c()})}[zu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Bu](t,e){let r=ee(Ge.relative(this.cwd,Ge.resolve(Ge.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[Ei](t,this.cwd,r,()=>this[$s](t,String(t.linkpath),"symlink",e),i=>{this[We](i,t),e()})}[Fu](t,e){let r=ee(Ge.resolve(this.cwd,String(t.linkpath))),i=ee(String(t.linkpath)).split("/");this[Ei](t,this.cwd,i,()=>this[$s](t,r,"link",e),o=>{this[We](o,t),e()})}[Ei](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let d=Ge.resolve(e,c);oe.lstat(d,(u,f)=>{if(u)return i();if(f?.isSymbolicLink())return o(new so(d,Ge.resolve(d,r.join("/"))));this[Ei](t,d,r,i,o)})}[Gu](){this[Ms]++}[br](){this[Ms]--,this[lc]()}[Dc](t){this[br](),t.resume()}[Rc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Ci}[Tc](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=d=>{e(d)},i=()=>{this[vn](this.cwd,this.dmode,d=>{if(d){this[We](d,t),r();return}this[ki]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let d=ee(Ge.dirname(String(t.absolute)));if(d!==this.cwd)return this[vn](d,this.dmode,u=>{if(u){this[We](u,t),r();return}c()})}c()},c=()=>{oe.lstat(String(t.absolute),(d,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Dc](t),r();return}if(d||this[Rc](t,u))return this[xt](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let f=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,x=g=>this[xt](g??null,t,r);return f?oe.chmod(String(t.absolute),Number(t.mode),x):x()}if(t.absolute!==this.cwd)return oe.rmdir(String(t.absolute),f=>this[xt](f??null,t,r))}if(t.absolute===this.cwd)return this[xt](null,t,r);o_(String(t.absolute),f=>this[xt](f??null,t,r))})};this[ki]?o():i()}[xt](t,e,r){if(t){this[We](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[kc](e,r);case"Link":return this[Fu](e,r);case"SymbolicLink":return this[Bu](e,r);case"Directory":case"GNUDumpDir":return this[Cc](e,r)}}[$s](t,e,r,i){oe[r](e,String(t.absolute),o=>{o?this[We](o,t):(this[br](),t.resume()),i()})}},yi=t=>{try{return[null,t()]}catch(e){return[e,null]}},Ef=class extends Gc{sync=!0;[xt](t,e){return super[xt](t,e,()=>{})}[Tc](t){if(!this[ki]){let o=this[vn](this.cwd,this.dmode);if(o)return this[We](o,t);this[ki]=!0}if(t.absolute!==this.cwd){let o=ee(Ge.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[vn](o,this.dmode);if(c)return this[We](c,t)}}let[e,r]=yi(()=>oe.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Dc](t);if(e||this[Rc](t,r))return this[xt](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[d]=c?yi(()=>{oe.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[xt](d,t)}let[o]=yi(()=>oe.rmdirSync(String(t.absolute)));this[xt](o,t)}let[i]=t.absolute===this.cwd?[]:yi(()=>a_(String(t.absolute)));this[xt](i,t)}[kc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=d=>{let u;try{oe.closeSync(o)}catch(f){u=f}(d||u)&&this[We](d||u,t),e()},o;try{o=oe.openSync(String(t.absolute),gf(t.size),r)}catch(d){return i(d)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",d=>this[We](d,t)),t.pipe(c)),c.on("data",d=>{try{oe.writeSync(o,d,0,d.length)}catch(u){i(u)}}),c.on("end",()=>{let d=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,f=t.mtime;try{oe.futimesSync(o,u,f)}catch(x){try{oe.utimesSync(String(t.absolute),u,f)}catch{d=x}}}if(this[Ai](t)){let u=this[Ti](t),f=this[Ri](t);try{oe.fchownSync(o,Number(u),Number(f))}catch(x){try{oe.chownSync(String(t.absolute),Number(u),Number(f))}catch{d=d||x}}}i(d)})}[Cc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[vn](String(t.absolute),r);if(i){this[We](i,t),e();return}if(t.mtime&&!this.noMtime)try{oe.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[Ai](t))try{oe.chownSync(String(t.absolute),Number(this[Ti](t)),Number(this[Ri](t)))}catch{}e(),t.resume()}[vn](t,e){try{return Yw(ee(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}}[Ei](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let d of r){c=Ge.resolve(c,d);let[u,f]=yi(()=>oe.lstatSync(c));if(u)return i();if(f.isSymbolicLink())return o(new so(c,Ge.resolve(e,r.join("/"))))}i()}[$s](t,e,r,i){let o=`${r}Sync`;try{oe[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[We](c,t)}}},c_=t=>{let e=new Ef(t),r=t.file,i=cf.statSync(r),o=t.maxReadSize||16*1024*1024;new Tm(r,{readSize:o,size:i.size}).pipe(e)},d_=(t,e)=>{let r=new Gc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("close",c),cf.stat(o,(u,f)=>{if(u)d(u);else{let x=new Oc(o,{readSize:i,size:f.size});x.on("error",d),x.pipe(r)}})})},vf=Pi(c_,d_,t=>new Ef(t),t=>new Gc(t),(t,e)=>{e?.length&&ef(t,e)}),l_=(t,e)=>{let r=new Uc(t),i=!0,o,c;try{try{o=dt.openSync(t.file,"r+")}catch(f){if(f?.code==="ENOENT")o=dt.openSync(t.file,"w+");else throw f}let d=dt.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<d.size;c+=512){for(let g=0,w=0;g<512;g+=w){if(w=dt.readSync(o,u,g,u.length-g,c+g),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!w)break e}let f=new Vn(u);if(!f.cksumValid)break;let x=512*Math.ceil((f.size||0)/512);if(c+x+512>d.size)break;c+=x,t.mtimeCache&&f.mtime&&t.mtimeCache.set(String(f.path),f.mtime)}i=!1,u_(t,r,c,o,e)}finally{if(i)try{dt.closeSync(o)}catch{}}},u_=(t,e,r,i,o)=>{let c=new Wu(t.file,{fd:i,start:r});e.pipe(c),h_(e,o)},f_=(t,e)=>{e=Array.from(e);let r=new ro(t),i=(o,c,d)=>{let u=(S,_)=>{S?dt.close(o,b=>d(S)):d(null,_)},f=0;if(c===0)return u(null,0);let x=0,g=Buffer.alloc(512),w=(S,_)=>{if(S||_===void 0)return u(S);if(x+=_,x<512&&_)return dt.read(o,g,x,g.length-x,f+x,w);if(f===0&&g[0]===31&&g[1]===139)return u(new Error("cannot append to compressed archives"));if(x<512)return u(null,f);let b=new Vn(g);if(!b.cksumValid)return u(null,f);let I=512*Math.ceil((b.size??0)/512);if(f+I+512>c||(f+=I+512,f>=c))return u(null,f);t.mtimeCache&&b.mtime&&t.mtimeCache.set(String(b.path),b.mtime),x=0,dt.read(o,g,0,512,f,w)};dt.read(o,g,0,512,f,w)};return new Promise((o,c)=>{r.on("error",c);let d="r+",u=(f,x)=>{if(f&&f.code==="ENOENT"&&d==="r+")return d="w+",dt.open(t.file,d,u);if(f||!x)return c(f);dt.fstat(x,(g,w)=>{if(g)return dt.close(x,()=>c(g));i(x,w.size,(S,_)=>{if(S)return c(S);let b=new Qs(t.file,{fd:x,start:_});r.pipe(b),b.on("error",c),b.on("close",o),x_(r,e)})})};dt.open(t.file,d,u)})},h_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?kr({file:Sf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},x_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await kr({file:Sf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},bi=Pi(l_,f_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!Nm(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")}),SI=Pi(bi.syncFile,bi.asyncFile,bi.syncNoFile,bi.asyncNoFile,(t,e=[])=>{bi.validate?.(t,e),p_(t)}),p_=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))};fn();var St={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 oo(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function If(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function ao(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 Tf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function Cr(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Yt();Xe();se();Fe();Xe();function An(t,e){if(oo(t)!=="cloud")throw new R("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Oi(t){return t.startsWith("http://")||t.startsWith("https://")}function co(t){return t.endsWith("/")?t.slice(0,-1):t}import{readFileSync as pA}from"node:fs";import{dirname as mA,join as wA}from"node:path";import{fileURLToPath as yA}from"node:url";var Bt="0.1.104-alpha.7";Xe();se();var lo="1008033",Df="1289";var Pf="pbbp2",Of="https://www.coze.cn",Lf="/api/coze_claw/resource/get_frontier_key",v_="https://www.coze.cn",S_="wss://frontier.coze.cn";function uo(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??v_}function Nf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??S_}function Dr(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 Ni(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Li=G("handshake");async function Hc(t){let e=uo(t.endpoint),r=t.timeoutMs??1e4,i=`${co(e)}${Lf}?aid=${encodeURIComponent(lo)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...Dr(t.ppeOverride)},c=new AbortController,d=setTimeout(()=>c.abort(),r);Li.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),f=u.headers.get("x-tt-logid")??"",x=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let b=await u.text().catch(()=>"");throw new R("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${f}: ${b.slice(0,200)}`)}let g=await u.json();if(g.code!==void 0&&g.code!==0)throw new R("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${g.code} msg=${g.msg??"-"} logid=${f}`);let w=g.data??{},S=typeof w.access_key=="string"&&w.access_key||typeof w.accessKey=="string"&&w.accessKey||void 0,_=typeof w.device_id=="string"&&w.device_id||typeof w.deviceId=="string"&&w.deviceId||void 0;if(!S||!_){let b=JSON.stringify(g).slice(0,500);throw new R("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${f}: ${b}`)}return Li.info("handshake ok",{remoteDeviceId:_,logid:f,traceId:x}),{accessKey:S,deviceId:_}}catch(u){if(u instanceof R)throw Li.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Li.warn("handshake timeout",{base:e,timeoutMs:r}),new R("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let f=u.cause;throw Li.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:f?.code,syscall:f?.syscall,cause:String(u).slice(0,300)}),new R("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(d)}}var jc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",It="auto",Mf=15e4;function Bf(t){return{model:qc(t.model)??It,...t.modelToken?{modelToken:t.modelToken}:{}}}function Ff(t){return!t||t===It}var I_=new Set(["auto","\u81EA\u52A8"]);function qc(t){let e=t?.trim();if(e)return I_.has(e.toLowerCase())?It:e}function zf(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=jc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||It;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 Ff(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Uf(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||It}"`):Ff(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="${jc}/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 Wc(t,e){let{ttEnv:r,usePpe:i}=Ni(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Hf(t,e,r){if(!t.modelToken)return{};let i=Wc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,d])=>`${c}:${d}`).join(`
92
+ `)}}function Kc(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||It,o=Wc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let d={baseUrl:`${jc}/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&&(d.headers=o),d}function qf(t,e,r){if(!t.modelToken)return[];let i=Wc(e,r),o=[];for(let[c,d]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${d}"`);return o}var Ae=G("agent-handlers"),Wf=5*1024*1024,C_=1,D_=6,P_=new Set(["node_modules",".git",".coze","dist","build",".next"]),O_=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,L_=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,N_=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function M_(t){let e=t?.trim();return e?N_.test(e)||L_.test(e)?e:(Ae.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function B_(t){return new Promise((e,r)=>{let i=at("npx",t,{detached:!0,stdio:"ignore",windowsHide:!0}),o=!1,c=d=>{o||(o=!0,d?r(d):e(i.pid??0))};i.once("spawn",()=>{i.unref(),c()}),i.once("error",d=>c(d))})}var fo=class{constructor(e){this.opts=e}opts;async listSkills(e){An(e._meta,"_agent/listSkills");let r=Cr(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??st(r).workspace,c=i?.skills??[],d=[];for(let u of c){let f=At(o,u.relPath,"SKILL.md");await T_(f).then(g=>g.isFile()).catch(()=>!1)&&d.push(H_(u))}return{skills:d}}async addSkills(e){let r=Cr(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],d=new Map(c.map((f,x)=>[f.skillId,x])),u=[];for(let f of o){let x=await ho({agentId:r,workspace:i.workspace,framework:i.framework,skill:f});xo(c,d,x),u.push(f)}return await ps(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){An(e._meta,"_agent/removeSkills");let r=Cr(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],d=[];for(let u of c){if(!o.has(u.skillId)){d.push(u);continue}let f=At(i.workspace,u.relPath);await $f(f,{recursive:!0,force:!0}),Ae.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await ps(r,d),this.reloadAgentSessions(r,"skills-removed"),{ok:!0}}reloadAgentSessionsPublic(e,r){this.reloadAgentSessions(e,r)}reloadAgentSessions(e,r){let i=this.opts.agents.get(e);if(i)for(let[o,c]of i.sessions){if(!c.downstream)continue;let d=c.acpSessionId;if(d&&i.activeTriggers.has(d)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,Ae.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d});continue}let f=c.downstream;c.downstream=void 0,Ae.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d}),f.stop(r).catch(x=>Ae.warn("downstream stop failed during reload (ignored)",{reason:r,agentId:e,cloudId:o,err:String(x)}))}}isRuntimePendingPermission(e){let r=this.opts.isRuntimePendingPermission;return!r||!e.downstream?!1:r(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return Ae.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await ze(r);if(!i)throw new R("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 hr(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 R("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Je(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 R("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await ze(r))throw new R("AGENT_NOT_FOUND",`agent not found: ${r}`);let o=["-y"];e.registry&&Oi(e.registry)&&o.push(`--registry=${e.registry}`);let c=M_(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let d=e._meta?.cozeEnv;d&&O_.test(d)&&o.push("--env",d);let u=await B_(o);return Ae.info("_agent/upgrade: spawned bridge upgrade process",{agentId:r,pid:u,targetVersion:c,currentVersion:e.currentVersion??"",reason:e.reason??""}),{ok:!0,accepted:!0,pid:u,message:"bridge upgrade started"}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new R("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await ze(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Je(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(An(e._meta,"_agent/switchModel"),!e.agentId)throw new R("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=qc(e.model)??It,i=await ze(e.agentId);if(!i)throw new R("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Je(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(d=>Ae.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(d)}));let c=[];for(let[d,u]of o.allSessionQueues())c.push(u.enqueue(async()=>{let f=o.sessions.get(d);f?.downstream&&(await f.downstream.stop(`switchModel: ${r}`).catch(()=>{}),f.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(An(e._meta,St.RESET),!e.agentId)throw new R("IPC_BAD_REQUEST",`${St.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,St.RESET),await this.runDetailSync(e.agentId,St.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,d]of i.sessions)o.set(c,{modelToken:d.modelToken,tokenGeneratedAt:d.tokenGeneratedAt});await oi(e,o)}async clearPersistedAcpSessionIds(e){let r=await ze(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 Je(r)}async repairAgent(e){if(An(e._meta,St.REPAIR),!e.agentId)throw new R("IPC_BAD_REQUEST",`${St.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new R("IPC_BAD_REQUEST",`${St.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,St.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){An(e._meta,"_agent/getFileTree");let r=e._meta,i=Cr(r),o=await this.resolveWorkspace(i),c=e.filePath??"",d=this.safeJoin(o,c),u=await $c(d).catch(()=>null);if(!u)throw new R("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new R("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await si(d,o))throw new R("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let f=ey(e.depth);return u.isDirectory()?{tree:await Q_(o,d,c,f)}:{tree:[{name:ty(c),path:e0(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){An(e._meta,"_agent/getFileContent");let r=Cr(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new R("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await $c(o).catch(()=>null);if(!c||!c.isFile())throw new R("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new R("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await si(o,i))throw new R("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Wf)throw new R("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Wf})`);let d=await Kf(o);return d.includes(0)?{content:d.toString("base64"),encoding:"base64",size:c.size}:{content:d.toString("utf8"),encoding:"utf-8",size:c.size}}async resolveWorkspace(e){let r=this.opts.agents.get(e);return r?r.workspace:(await ze(e).catch(()=>null))?.workspace??st(e).workspace}safeJoin(e,r){let i=Zc(e,r||"."),o=Xc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Vf}`))throw new R("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return ze(e)}async requireAgentCfg(e){let r=await this.loadAgentCfg(e);if(!r)throw new R("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function F_(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new R("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new R("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function z_(t){return t==="claude-code"?At(".claude","skills"):At(".agents","skills")}var U_=3e4,G_=50*1024*1024,Pr=3e4;async function ho(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new R("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,d=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!d)throw new R("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=F_(o.skillName),f=z_(i),x=At(f,u),g=At(r,x);if(await Vc(g,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");Mi(S.length),await Jc(At(g,"SKILL.md"),S,"utf8")}else{let S=await q_(o.downloadUrl);K_(S)?await Z_(S,g):$_(S)?await V_(S,g):await Jc(At(g,"SKILL.md"),S.toString("utf8"),"utf8")}let w={skillId:o.skillId,skillName:o.skillName,relPath:x,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return Ae.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:x,source:c?"content":"downloadUrl"}),w}function xo(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 H_(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}:{}}}function j_(t){return{skillId:t.skillId,skillName:t.skillName,...t.downloadUrl?{downloadUrl:t.downloadUrl}:{},...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 Xf(t,e){let r=await ze(t,e);if(!r)return{status:"skipped",count:0};if(r.disconnectedAt)return{status:"skipped",count:0};let i=Bt,o=r.skillsRefreshedForVersion;if(o===i)return{status:"noop",count:0};if(!o)return r.skillsRefreshedForVersion=i,await Je(r,e),{status:"seeded",count:0};let c=[...r.skills??[]],d=new Map(c.map((g,w)=>[g.skillId,w])),u=c.filter(g=>g.builtin===!0&&!!g.downloadUrl);if(u.length===0)return r.skillsRefreshedForVersion=i,await Je(r,e),{status:"noop",count:0};let f=0,x=0;for(let g of u)try{await $f(At(r.workspace,g.relPath),{recursive:!0,force:!0});let w=await ho({agentId:t,workspace:r.workspace,framework:r.framework,skill:j_(g)});xo(c,d,w),f+=1}catch(w){x+=1,Ae.warn("refresh builtin skill failed (skipping)",{agentId:t,skillId:g.skillId,skillName:g.skillName,err:String(w)})}return r.skills=c,x===0&&(r.skillsRefreshedForVersion=i),await Je(r,e),Ae.info("builtin skills refreshed after bridge upgrade",{agentId:t,from:o,to:i,ok:f,failed:x}),{status:"refreshed",count:f}}async function q_(t){if(!t)throw new R("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Mi(e);let r=W_(t);return Mi(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await Kf(e);return Mi(r.length),r}if(Oi(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),U_);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new R("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Mi(o.byteLength),Buffer.from(o)}finally{clearTimeout(r)}}throw new R("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Mi(t){if(t>G_)throw new R("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function W_(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new R("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 K_(t){return t.length>=2&&t[0]===31&&t[1]===139}function $_(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 Yc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function V_(t,e){let r,i;try{r=new Yf.default(t),i=r.getEntries()}catch(d){throw new R("IPC_BAD_REQUEST",`zip parse failed: ${d.message}`,{cause:d})}for(let d of i){let u=d.entryName;if(!u||Yc(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new R("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(x=>x===".."))throw new R("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let f=d.header.attr>>>16&61440;if(f!==0&&f!==32768&&f!==16384)throw new R("IPC_BAD_REQUEST",`zip entry kind 0x${f.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=J_(i),c=Zc(e);for(let d of i){if(Yc(d.entryName))continue;let u=d.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let f=Zc(e,u),x=Xc(c,f);if(x.startsWith("..")||x==="..")throw new R("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(d.isDirectory){await Vc(f,{recursive:!0});continue}await Vc(R_(f),{recursive:!0});let g;try{g=d.getData()}catch(w){throw new R("IPC_BAD_REQUEST",`zip entry getData failed (${d.entryName}): ${w.message}`,{cause:w})}await Jc(f,g)}}function J_(t){let e;for(let r of t){let i=r.entryName;if(!i||Yc(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 Z_(t,e){await Y_(t);let r=vf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new R("IPC_BAD_REQUEST",`tar extract timeout (${Pr}ms)`))},Pr);try{await Zf(Jf.from(t),r)}catch(c){throw c instanceof R?c:i?new R("IPC_BAD_REQUEST",`tar extract timeout (${Pr}ms)`):new R("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function Y_(t){let e=[],r=kr({onReadEntry:c=>{let d=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' not allowed (symlink/hardlink/special): ${d.slice(0,100)}`);return}if(d.startsWith("/")||d.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(d)){e.push(`tar entry absolute path: ${d}`);return}d.split(/[/\\]/).some(x=>x==="..")&&e.push(`tar entry contains '..': ${d}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new R("IPC_BAD_REQUEST",`tar list timeout (${Pr}ms)`))},Pr);try{await Zf(Jf.from(t),r)}catch(c){throw i?new R("IPC_BAD_REQUEST",`tar list timeout (${Pr}ms)`):new R("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new R("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var X_=5e3;async function Q_(t,e,r,i){return Qf(t,e,r,i,{count:0})}async function Qf(t,e,r,i,o){if(i<=0)return[];let c;try{c=await A_(e,{withFileTypes:!0})}catch{return[]}let d=[];for(let u of c){if(P_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=X_){d.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let f=At(e,u.name),x=k_(At(r,u.name)),g=null;try{g=await $c(f)}catch{continue}if(g.isSymbolicLink())continue;o.count++;let w={name:u.name,path:e0(Xc(t,f)),isDir:g.isDirectory(),size:g.size,modifiedAt:Math.floor(g.mtimeMs)};g.isDirectory()&&i>1&&(w.children=await Qf(t,f,x,i-1,o)),d.push(w)}return d.sort((u,f)=>u.isDir!==f.isDir?u.isDir?-1:1:u.name.localeCompare(f.name)),d}function ey(t){return!t||t<=0?C_:Math.min(t,D_)}function ty(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function e0(t){return t.split(Vf).join("/")}se();var Tn=G("agent-health-reporter"),ny=1e4,ry=3,Bi=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??ny,this.livenessFailureThreshold=e.livenessFailureThreshold??ry}opts;timer=null;inFlight=!1;unsubscribeRegister=null;intervalMs;livenessFailureThreshold;consecutiveFailures=0;isLivenessLost(){return this.consecutiveFailures>=this.livenessFailureThreshold}start(){this.timer||(this.timer=setInterval(()=>{this.tick()},this.intervalMs),this.timer.unref?.(),this.unsubscribeRegister=this.opts.core.onAgentRegister(()=>{this.tick()}),Tn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),Tn.info("heartbeat stopped"))}async tick(){if(this.inFlight){Tn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){this.consecutiveFailures=0,Tn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let r=[];for(let d of this.opts.core.agents.values()){let u=iy(d);if(!u)continue;let f={agentId:d.agentId,status:u};d.patToken&&(f.patToken=d.patToken),d.accountId&&(f.accountId=d.accountId),r.push(f)}if(r.length===0){this.consecutiveFailures=0;return}let i={agents:r,bridgeVersion:Bt,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3),this.consecutiveFailures=0}catch(d){this.consecutiveFailures+=1,Tn.warn("heartbeat batch send failed",{count:r.length,consecutiveFailures:this.consecutiveFailures,err:String(d)})}let c=o?.authFailures;if(c&&c.length>0&&(Tn.warn("heartbeat received authFailures from cloud",{count:c.length,agentIds:c.map(d=>d.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(c)}catch(d){Tn.warn("onAuthFailures callback failed (ignored)",{err:String(d)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){Tn.warn("onTickEnd hook failed",{err:String(r)})}}};function iy(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}fn();import{mkdir as id,rm as Jy,stat as Zy}from"node:fs/promises";import{homedir as Yy}from"node:os";import{join as R0}from"node:path";dn();import{existsSync as my}from"node:fs";import{release as wy}from"node:os";import{basename as _y,isAbsolute as yy}from"node:path";function Fi(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Or(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Lr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function Rn(t,e){return{jsonrpc:"2.0",id:t,error:e}}Xe();var po=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)}},re={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 t0(t){return"method"in t&&"id"in t&&t.id!==void 0}function n0(t){return"method"in t&&!("id"in t)}function go(t){return!("method"in t)&&"id"in t}var sy={AGENT_NOT_FOUND:re.AGENT_NOT_FOUND,AGENT_BUSY:re.AGENT_BUSY,AGENT_DISCONNECTED:re.AGENT_DISCONNECTED,AGENT_TIMEOUT:re.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:re.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:re.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:re.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:re.INTERNAL_ERROR,BRIDGE_INTERNAL:re.INTERNAL_ERROR,IPC_AUTH_FAILED:re.INTERNAL_ERROR,IPC_BAD_REQUEST:re.INVALID_REQUEST,METHOD_NOT_FOUND:re.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:re.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:re.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:re.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:re.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:re.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:re.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:re.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:re.FILE_TOO_LARGE,UNSUPPORTED_MIME:re.UNSUPPORTED_MIME,UPLOAD_FAILED:re.UPLOAD_FAILED,UPSTREAM_NOT_READY:re.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:re.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:re.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:re.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:re.AGENT_ENV_NOT_READY};function oy(t){if(t!=null)return t instanceof Error?{name:t.name,message:zi(t.message)}:typeof t=="string"?zi(t):typeof t=="object"?cy(t):t}var ay=[[/\/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 zi(t){let e=t;for(let[r,i]of ay)e=e.replace(r,i);return e}function cy(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=zi(i):e[r]=i;return e}function Ui(t){if(t instanceof R){let e=oy(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:sy[t.code]??re.INTERNAL_ERROR,message:zi(t.message),data:r}}return{code:re.INTERNAL_ERROR,message:zi(t instanceof Error?t.message:String(t))}}function r0(t){let e=t.data,r=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:d,...u}=e;c=u}return new R(r,o,{retriable:e?.retriable??!1,cause:c})}function s0(t){return`${JSON.stringify(t)}
93
+ `}var i0=10*1024*1024,mo=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>i0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${i0} bytes`)}),[]}let r=this.buffer.split(`
94
+ `);this.buffer=r.pop()??"";let i=[];for(let o of r){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(d){this.onError?.({line:c,error:d})}}return i}flush(){if(!this.buffer)return[];let e=this.buffer.replace(/\r$/,"").trim();if(this.buffer="",!e)return[];try{return[JSON.parse(e)]}catch(r){return this.onError?.({line:e,error:r}),[]}}};var a0={"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"},nT=Object.fromEntries(Object.entries(a0).map(([t,e])=>[e,t])),dy={"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:[]},Nr=class{seq=0;next(e,r){this.seq+=1;let i=a0[e]??ly(e),o=dy[i]??[],c=[i,String(this.seq)];if(o.length>0){let d=o.map(f=>o0(r?.[f]??"")),u=uy(d).join(":");u&&c.push(u)}else r&&Object.values(r).some(d=>d)&&c.push(Object.values(r).filter(Boolean).map(d=>o0(String(d))).join(":"));return c.join("_")}reset(){this.seq=0}};function ly(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function o0(t){return t.replace(/[:_\s]+/g,"-")}function uy(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}un();import{readFileSync as fy}from"node:fs";var hy=384;async function Qc(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await fr(t.agentEnvFile,r,{mode:hy})}function ed(t){try{let e=JSON.parse(fy(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function c0(t,e,r={},i=o=>o){return{...i({...t,...ed(e)}),...r}}Yt();ar();Xe();se();Fe();import{execFileSync as xy,spawnSync as py}from"node:child_process";function Gi(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function Hi(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),py("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var td=new Set;function d0(t){typeof t=="number"&&t>0&&td.add(t)}function l0(t){typeof t=="number"&&td.delete(t)}function u0(){for(let t of td)Hi(t,"SIGKILL")}var Mr="coze-bridge-daemon";function f0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return xy("pgrep",["-U",String(o),"-f",Mr],{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 h0(t,e){if(t.length===0)return;let r=e?.killFn??Hi,i=e?.isAliveFn??Gi,o=e?.sleepFn??(u=>new Promise(f=>setTimeout(f,u))),c=e?.graceMs??3e3,d=e?.pollMs??100;for(let u of t)r(u,"SIGTERM");for(let u=0;u<c&&t.some(f=>i(f));u+=d)await o(Math.min(d,c-u));for(let u of t)i(u)&&r(u,"SIGKILL")}var gy=[{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|agentclientprotocol)\/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|codex-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 x0(t,e){if(!e)return null;for(let r of gy)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function p0(t,e){return x0(t,e)}function g0(t,e){return x0(t,e)}function Br(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 m0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let x=t.suspendedMs+o,g=r-t.startedAt-x;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Br(g,t.firstFrameSeen,e)}}let c=r-t.startedAt-t.suspendedMs,d=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=d?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Br(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Br(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Br(c,!1,e)}}var w0=Ye("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),by=200,Ey=40,vy=Ye("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),Sy=Ye("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),Iy=Ye("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),Ay=Ye("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),Ty=Ye("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Ry=Ye("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),_0=500;function ky(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=_0?t:`${e.slice(0,_0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Cy(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 y0(t){try{return my(t)}catch{return}}function Dy(t,e){return{platform:process.platform,osRelease:wy(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:yy(e.command)?y0(e.command):void 0,cwd:e.cwd,cwdExists:y0(e.cwd),envKeys:e.envKeys}}function Py(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${_y(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Ft=class{constructor(e){this.opts=e;this.log=G(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new mo({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Nr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new R("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=c0(process.env,this.opts.agentEnvFile??ne().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=at(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,d0(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>by&&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,l0(i.pid),(o!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:c,recentStderr:[...this.stderrRing]});try{for(let u of this.decoder.flush())this.dispatch(u)}catch(u){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(u)})}this.failAllPending(this.buildExitError(o,c));for(let u of this.exitHandlers)u(o,c)}),i.on("error",o=>{let c=o,d=Dy(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(r).length});this.log.error("child error",{err:String(o),diag:d}),this.failAllPending(new R("AGENT_SPAWN_FAILED",Py(c,d),{cause:d}))}),this.log.info("downstream started",{command:this.opts.command,pid:i.pid,cwd:this.opts.cwd})}async stop(e){if(!this.child||this.stopped)return;this.stopped=!0,this.stopReason=e??"stopped",this.log.info("downstream stopping",{reason:e});let r=this.child,i=new Promise(c=>r.once("exit",()=>c()));Hi(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Hi(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:Ty,phase2GateMs:vy,livenessWindowMs:Sy,absoluteMaxMs:Iy,approvalMaxMs:Ry,suspendThresholdMs:Ay,...r};return this.call("session/prompt",e,w0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Or("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(Lr(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(Rn(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=w0,o){if(!this.child||this.stopped)return Promise.reject(new R("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),d=Fi(c,e,r),u=(()=>{if(typeof r!="object"||r===null)return;let f=r.sessionId;return typeof f=="string"?f:void 0})();return new Promise((f,x)=>{let g={resolve:f,reject:x,timer:null,method:e,promptTimeout:null};if(o){let w=this.now(),S={cfg:o,startedAt:w,lastActivityAt:w,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:w,expectedIntervalMs:Br(0,!1,o),sessionId:u};g.promptTimeout=S;let _=()=>{let b={startedAt:S.startedAt,lastActivityAt:S.lastActivityAt,firstFrameSeen:S.firstFrameSeen,hasActiveTool:S.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:S.suspendedMs,armedAt:S.armedAt,expectedIntervalMs:S.expectedIntervalMs},I=this.now(),T=m0(b,S.cfg,I),k=D=>{S.armedAt=I,S.expectedIntervalMs=D,g.timer=setTimeout(_,D)};if(T.action==="suspend"){S.suspendedMs+=T.suspendedDeltaMs,S.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:T.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),k(T.rearmMs);return}if(T.action==="continue"){k(T.rearmMs);return}this.pending.delete(c),T.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:T.awaitingApproval,...S.sessionId?{sessionId:S.sessionId}:{}}),x(T.awaitingApproval?new R("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new R("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}:{}}),x(new R("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};g.timer=setTimeout(_,S.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(g.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),x(new R("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,g);try{this.writeFrame(d)}catch(w){g.timer&&clearTimeout(g.timer),this.pending.delete(c),x(w)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new R("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(s0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(go(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 R("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:ky(e.result)}),r.resolve(e.result));return}if(n0(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(t0(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 d=typeof i.status=="string"?i.status:void 0,u=d==="completed"||d==="failed"||d==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(Rn(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(Rn(e.id,Ui(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=r0(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=g0(this.framework,Cy(e));return i?new R(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 R("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(Ey).join(`
96
+ `),o=p0(this.framework,i);return o?new R(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new R("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 Oy(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 wo=class extends Ft{framework="claude-code";constructor(e){let{command:r,args:i}=ii("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 Oy(e)}};dn();import{mkdtempSync as Ly,rmSync as Ny}from"node:fs";import{tmpdir as My}from"node:os";import{join as By}from"node:path";var _o=class extends Ft{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=ii("codex",e.command,i),d=e.isolateCodexHome?Ly(By(My(),"coze-bridge-codex-home-")):void 0,u=d?{...e.env??{},CODEX_HOME:d}:e.env,f={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(f),this.authMethodId=e.authMethodId,this.codexHomeDir=d}async initialize(e){let r=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),r}async stop(e){if(await super.stop(e),this.codexHomeDir)try{Ny(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};Xe();var Fy=3e4,Fr=class extends Ft{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}`}]},Fy))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new R("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var b0=["default","acceptEdits","plan","auto","bypassPermissions"],E0=["read-only","auto","full-access"];function kn(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return b0.includes(e);case"codex":return E0.includes(e);case"openclaw":return!1}}function nd(t){switch(t){case"claude-code":return b0.join("/");case"codex":return E0.join("/");case"openclaw":return""}}un();Xe();se();Fe();function rd(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}dn();var Cn=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 yo=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 Cn,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)ji(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 ji(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function Xt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Yt();se();import{constants as v0}from"node:fs";import{access as zy}from"node:fs/promises";import{delimiter as Uy,join as Gy}from"node:path";var Tt=G("framework-detector"),S0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},Hy=[".exe",".cmd",".bat",".ps1"],Zn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??at,access:e.access??zy}}async detect(e){let r=S0[e],i=await this.which(r);if(!i)return Tt.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,d]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return d&&(u.defaultAgent=d),u}async detectAll(){let e=await Promise.all(Object.keys(S0).map(async i=>[i,await this.detect(i)])),r={};for(let[i,o]of e)o&&(r[i]=o);return r}async which(e){let r=this.env.pathEnv.split(Uy).filter(Boolean),i=this.env.platform==="win32"?["",...Hy]:[""];for(let o of r)for(let c of i){let d=Gy(o,e+c);if(await this.isExecutable(d))return d}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?v0.F_OK:v0.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 Tt.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return Tt.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 Tt.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 Tt.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(d=>d?.isDefault===!0);return c?!c.id||!c.workspace?(Tt.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}:(Tt.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return Tt.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 Tt.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||Tt.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let d=JSON.parse(c[0]);typeof d.gateway?.port=="number"&&(o.port=d.gateway.port),typeof d.service?.runtime?.status=="string"&&(o.runtime=d.service.runtime.status),!i&&typeof d.rpc?.error=="string"&&(o.detail=d.rpc.error)}catch(d){Tt.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(d)})}return o}async probeVersion(e,r=[]){let i=await this.runProbe(e,[...r,"--version"]);return i&&(qy(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,d,u=f=>{c||(c=!0,d&&clearTimeout(d),i(f))};try{let f=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});d=setTimeout(()=>{f.kill("SIGKILL"),u(null)},15e3),f.stdout?.on("data",x=>{o+=x.toString("utf8")}),f.on("error",()=>u(null)),f.on("close",x=>u({code:x,stdout:o}))}catch{u(null)}})}},jy=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function qy(t){return t.replace(jy,"")}import{homedir as Wy}from"node:os";import{join as Ky}from"node:path";un();Yt();ar();Xe();se();async function T0(){let t=Ky(Wy(),".openclaw/openclaw.json");return(await ur(t))?.gateway?.auth?.token??""}var I0=G("openclaw.config"),$y=[0,5e3,5e3],Vy=Ye("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),A0="models.providers.",bo="agents.defaults.models",Eo=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new Cn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??$y,this.cliTimeoutMs=e.cliTimeoutMs??Vy}async withRetry(e,r){let i;for(let o=0;o<this.retryDelaysMs.length;o++){let c=this.retryDelaysMs[o]??0;c>0&&await new Promise(d=>setTimeout(d,c));try{return await r()}catch(d){i=d,I0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(d)})}}throw new R("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=at(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",d=!1,u=x=>{d||(d=!0,clearTimeout(f),x())};o.stderr?.on("data",x=>{c+=x.toString("utf8")});let f=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);f.unref(),o.on("error",x=>u(()=>i(x))),o.on("close",x=>u(()=>{x===0?r():i(new Error(`exit ${x}: ${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){I0.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",`${A0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${A0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${bo}[${e}]`,()=>this.runCli(["config","set",bo,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${bo}[${e}]`,`${bo}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var xe=G("agent-manager"),od="bypassPermissions",D0="full-access",P0="full-access";function Xy(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 Qy=(t,e,r,i,o,c,d,u,f,x)=>{switch(t){case"claude-code":{let g={...o?{...zf(o),...Hf(o,d,u)}:{},...f??{},IS_SANDBOX:"1"};return new wo({cwd:r,env:g,agentId:i})}case"codex":{let g=o?[...Uf(o),...qf(o,d,u)]:[],w=D0;x!==void 0&&(kn("codex",x)?w=x:xe.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:x}));let S=[...g,...Xy(w)],_={...o?Gf(o):{},...f??{}},b=!!o;return new _o({cwd:r,agentId:i,...S.length>0?{extraArgs:S}:{},...Object.keys(_).length>0?{env:_}:{},...b?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Fr({command:e,cwd:r,agentId:i,...c?{sessionName:rd(c)}:{}})}};function sd(t){return t==="claude-code"||t==="codex"}function eb(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(tb(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(`
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
98
+ `}function tb(t){if(t.includes(`
99
+ `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var nb={path:"",version:"cloud-deployed"},k0="openclaw_gateway_unavailable",rb="openclaw_default_agent_missing";function C0(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 ib={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},sb=6e4,vo=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??Qy,this.createTimeoutMs=e.createTimeoutMs??sb,this.detectorFactory=e.detectorFactory??(()=>new Zn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new Eo({command:r})),this.openclawConfigDir=e.openclawConfigDir??R0(Yy(),".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 R("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{xe.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=R0(e,".env");if(await Zy(r).then(c=>c.isFile()).catch(()=>!1)){xe.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}let o=eb({...process.env,...ed(this.paths.agentEnvFile)});await ln(r,o,{mode:384}),xe.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),xe.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new R("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new R("IPC_BAD_REQUEST","framework required");let i=await ze(e.agentId,this.paths).catch(()=>null),o=oo(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 R("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")xe.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(k=>xe.warn("dispose stale agent failed (ignored)",{err:String(k)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")xe.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(k=>xe.warn("dispose drifted agent failed (ignored)",{err:String(k)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){xe.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let k=await ze(e.agentId,this.paths).catch(()=>null);k&&(k.patToken=e.patToken,await Je(k,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){xe.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let k=await ze(e.agentId,this.paths).catch(()=>null);k&&(k.modelInfo=e.modelInfo,await Je(k,this.paths))}return xe.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 R("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=st(e.agentId,this.paths),f=o?"cloud":"local",x=e.framework==="openclaw"&&f==="local",g;x&&!r?.revive&&(g=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let w=g??(x?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),S=e.workspace??w??u.workspace,_=new AbortController,b=setTimeout(()=>_.abort(new R("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),I,T=!1;try{o&&sd(e.framework)&&await lr(e.framework,_.signal);let k=()=>{if(_.signal.aborted)throw _.signal.reason instanceof Error?_.signal.reason:new R("AGENT_TIMEOUT","_agent/create aborted")};await id(u.root,{recursive:!0}),await id(S,{recursive:!0}),await id(u.logs,{recursive:!0}),k(),x||await hr(S,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(f==="cloud"?await Oa(S,"cloud"):await Oa(S,"local",od)),k();let D=i,y=Bf({model:e.model??D?.model}),C=If(e._meta)??D?.accountId,P=e.patToken??D?.patToken,F=f==="cloud"?e.modelInfo??D?.modelInfo:void 0;if(I=new yo({agentId:e.agentId,framework:e.framework,workspace:S,model:y.model??It,deployType:f,...C?{accountId:C}:{},...P?{patToken:P}:{},...F?{modelInfo:F}:{}}),I.status="ok",D?.sessions){let J=f==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[Q,ce]of Object.entries(D.sessions)){let le={acpSessionId:ce.acpSessionId,modelToken:ce.modelToken,tokenGeneratedAt:ce.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};J?ce.permissionMode===void 0?(le.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",xe.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:Q,framework:e.framework,fallback:le.permissionMode})):kn(e.framework,ce.permissionMode)?le.permissionMode=ce.permissionMode:xe.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:Q,framework:e.framework,value:ce.permissionMode}):ce.permissionMode!==void 0&&xe.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:Q,framework:e.framework,deployType:f}),ce.cozeGroupId&&(le.cozeGroupId=ce.cozeGroupId),I.sessions.set(Q,le)}let ie=Object.keys(D.sessions).length;ie>0&&xe.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:ie})}this.registry.register(I),T=!0;let M={agentId:e.agentId,framework:e.framework,workspace:S,cozeIdentity:e.cozeIdentity,createdAt:D?.createdAt??Date.now(),sessions:D?.sessions??{},model:y.model};f==="cloud"&&(M.deployType="cloud"),C&&(M.accountId=C),P&&(M.patToken=P),F&&(M.modelInfo=F),D?.skills&&(M.skills=D.skills),D?.agentName&&(M.agentName=D.agentName),D?.description&&(M.description=D.description),M.skillsRefreshedForVersion=D?.skillsRefreshedForVersion??Bt,e.framework==="openclaw"&&f==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,S)):xe.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 J=[...M.skills??[]],ie=new Map(J.map((le,O)=>[le.skillId,O])),Q=await Promise.allSettled(Y.map(le=>ho({agentId:e.agentId,workspace:S,framework:e.framework,skill:le}))),ce=0;for(let[le,O]of Q.entries()){let H=Y[le];H&&(O.status==="fulfilled"?(xo(J,ie,O.value),ce++):xe.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:H.skillId,skillName:H.skillName,err:String(O.reason)}))}ce>0&&(M.skills=J,xe.info("initialSkills installed",{agentId:e.agentId,installed:ce,requested:Y.length}))}return await Je(M,this.paths),xe.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:f}),{ok:!0,agentId:e.agentId,workspace:S,framework:e.framework}}catch(k){throw xe.error("agent create failed, rolling back",{agentId:e.agentId,err:String(k)}),T&&I&&(await I.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Jy(u.root,{recursive:!0,force:!0}).catch(D=>xe.warn("rm agent dir failed (ignored)",{err:String(D)})),k instanceof R?k:new R("AGENT_SPAWN_FAILED",String(k),{cause:k})}finally{clearTimeout(b)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&sd(e.framework))u=nb;else throw new R("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);sd(e.framework)&&!fs(e.framework)&&(xe.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await lr(e.framework));let f=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,x;if(e.framework==="openclaw")x=await this.buildOpenclawDownstream({session:e,modelConfig:f,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path});else{let g=e.sessions.get(i),w=Xt(e)?g?.permissionMode??D0:"full-access";x=this.factory(e.framework,u.path,e.workspace,e.agentId,f,i,o,c,this.buildBinShimPathEnv(),w)}try{return await x.start(),await x.initialize(ib),x}catch(g){let w=x instanceof Ft?x.getStderrTail():[];throw w.length>0&&xe.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:g instanceof R?g.code:"unknown",recentStderr:w}),await x.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,g)}}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 R("AGENT_ENV_NOT_READY",C0(o),{cause:{reason:k0}})}catch(o){xe.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof R?i:new R("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};xe.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return xe.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new R("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:rb}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new R("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new R("AGENT_ENV_NOT_READY",C0(r),{cause:{reason:k0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:d,command:u}=e,f=rd(o);if(r.deployType==="local"){let S=await this.ensureOpenclawDefaultAgent();return new Fr({command:u,cwd:S.workspace,agentId:S.id,sessionName:f})}let x=await T0(),g=i?jf(i,c,d):null,w;if(g){let S=Kc(o),b=g.models[0]?.id??It,I=`${S}/${b}`;if(!this.ensuredProviders.has(I)){let T=this.getOpenclawConfig();await T.ensureProvider(S,g),await T.addModelToAllowlist(I),this.ensuredProviders.add(I)}w=I}return new Fr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:f,...x?{gatewayToken:x}:{},...w?{slashModelOnStart:w}:{}})}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=Kc(i),c=`${o}/${e.model}`,d=!0;try{await r.removeProvider(o)}catch(u){d=!1,xe.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){d=!1,xe.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}d&&this.ensuredProviders.delete(c)}}};import{randomUUID as B0}from"node:crypto";import{promises as hb}from"node:fs";import{basename as F0}from"node:path";Xe();se();import{promises as ab}from"node:fs";import{basename as cb}from"node:path";var O0=G("file-upload"),db="/api/coze_claw/file/agent_upload",lb=6e4;async function L0(t,e={}){let i=`${co(uo(e.handshakeBase))}${db}`,o=e.timeoutMs??lb,c=await ab.readFile(t.path),d=new FormData;d.append("agent_id",t.agentId),d.append("session_id",t.sessionId),d.append("file_name",t.name),d.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let u={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...Dr(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},f=new AbortController,x=setTimeout(()=>f.abort(),o);O0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let g=await fetch(i,{method:"POST",headers:u,body:d,signal:f.signal}),w=g.headers.get("x-tt-logid")??"";if(!g.ok){let b=await g.text().catch(()=>"");throw new R("UPLOAD_FAILED",`upload HTTP ${g.status} logid=${w}: ${b.slice(0,200)}`)}let S=await g.json();if(S.code!==void 0&&S.code!==0)throw new R("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${w}`);let _=S.data?.file?.file_url;if(!_)throw new R("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${w}: ${JSON.stringify(S).slice(0,200)}`);return O0.info("file upload ok",{uri:_,logid:w}),{uri:_}}catch(g){throw g instanceof R?g:g.name==="AbortError"?new R("UPLOAD_FAILED",`upload timeout (${o}ms) for ${cb(t.path)}`):new R("UPLOAD_FAILED",String(g),{cause:g})}finally{clearTimeout(x)}}Xe();se();import{extname as ub}from"node:path";var fb={".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 N0(t){let e=ub(t).toLowerCase();return fb[e]??"application/octet-stream"}Fe();var So=G("agent-send"),M0=50*1024*1024;function z0(t,e,r){let i=t.get(e);if(!i)throw new R("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new R("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new R("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function U0(t,e,r,i,o,c){let u;for(let f=0;f<=2;f++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(x){u=x,f<2&&(So.warn("sendAgentFileUpdate failed, retrying",{attempt:f+1,err:String(x)}),await new Promise(g=>setTimeout(g,5e3)))}throw new R("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function G0(t,e){let{session:r,runtime:i}=z0(e.core,t.agentId,t.sessionId);if(!await si(t.path,r.workspace))throw new R("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await hb.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new R("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>M0)throw new R("FILE_TOO_LARGE",`${o.size} bytes > limit ${M0}`);let c=await N0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new R("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new R("UPSTREAM_NOT_READY","cloud WS not connected");let d=t.name??F0(t.path),u;try{u=await L0({patToken:r.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:d,sizeBytes:o.size,...r.accountId?{accountId:r.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(x){throw So.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:x instanceof R?x.code:"UNKNOWN",message:x instanceof Error?x.message:String(x)}),x}let f={sessionUpdate:"agent_file",messageId:B0(),content:{type:t.kind==="image"?"image":"resource",uri:u.uri,mimeType:c,name:d,sizeBytes:o.size,...u.fileId!==void 0?{fileId:u.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await U0(e,r,i,t.sessionId,f,"agent file uploaded to cloud but sendAgentFileUpdate failed"),So.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:d,bytes:o.size,mime:c,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:c,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function H0(t,e){let{session:r,runtime:i}=z0(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new R("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new R("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??F0(t.path),c={sessionUpdate:"group_file",messageId:B0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await U0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),So.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 j0(t,e){let r=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(r.length,i.length);for(let c=0;c<o;c++){let d=r[c]??0,u=i[c]??0;if(d<u)return!0;if(d>u)return!1}return!1}dn();Yt();se();var zt=G("coze-cli-installer"),q0="@coze/cli@latest",xb="coze",W0="0.1.8",pb=5e3,gb=5e3,mb=9e4,K0=1e4,qi=null,Io=!1;async function ad(t,e={}){if(Io)return;if(qi)return qi;let r=e.exec??Cf;return qi=(async()=>{try{let i=await wb(xb,r),o=!1;if(i){let d=await _b(r);if(d===void 0)zt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(j0(d,W0))zt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:d,min:W0}),o=!0;else{zt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:d}),Io=!0;return}}let c=o?"upgrade-only":"full";zt.info("coze-cli install start",{package:q0,mode:c});try{await r("npm",["i","-g","--prefer-online",q0],{timeout:mb,maxBuffer:10*1024*1024}),zt.info("coze-cli install ok")}catch(d){zt.warn("coze-cli install failed (skip subsequent steps)",{err:String(d)});return}if(o){Io=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:K0}),zt.info("coze config set xTTEnv ok",{env:t.env})}catch(d){zt.warn("coze config set failed (continue to auth login)",{err:String(d)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:K0}),zt.info("coze auth login ok")}catch(d){zt.warn("coze auth login failed",{err:String(d)});return}Io=!0}finally{qi=null}})(),qi}async function wb(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:pb});return Da(i)}catch{return}}async function _b(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:gb});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}un();Fe();var yb=10*6e4;function $0(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?yb:e}function Ao(t){return ur(t??ne().configFile)}function Wi(t,e){return fr(e??ne().configFile,t)}import{randomBytes as Ub}from"node:crypto";ar();Xe();se();import{createReadStream as bb}from"node:fs";import{mkdir as Eb,readFile as vb,realpath as Sb,stat as Ib,writeFile as Ab}from"node:fs/promises";import{basename as Tb,dirname as cd,isAbsolute as Rb,join as kb,relative as Cb,resolve as V0,sep as Db}from"node:path";import{createInterface as Pb}from"node:readline";var Z0=G("fs-rpc"),Ki=Ye("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function Y0(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Ki)throw new R("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Ki} bytes`);let i=await Q0(t.path,e);return await Eb(cd(i),{recursive:!0}),await Ab(i,t.content,"utf8"),Z0.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function X0(t,e){let r=await Q0(t.path,e),i=await Ib(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Ki&&!o)throw new R("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Ki} bytes`);let c;if(o&&i.size>Ki)c=await Ob(r,t.line??1,t.limit);else{let d=await vb(r,"utf8");if(o){let u=d.split(`
100
+ `),f=Math.max(0,(t.line??1)-1),x=typeof t.limit=="number"?f+t.limit:void 0;c=u.slice(f,x).join(`
101
+ `)}else c=d}return Z0.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function Ob(t,e,r){let i=Pb({input:bb(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,d=[],u=0;try{for await(let f of i)if(u>=o&&u<c&&d.push(f),u++,u>=c)break}finally{i.close()}return d.join(`
102
+ `)}async function Q0(t,e){if(typeof t!="string"||t.length===0)throw new R("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([J0(V0(e)),J0(V0(t))]),o=Cb(r,i);if(Lb(o,Db,Rb(o)))throw new R("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function Lb(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function J0(t){let e=[],r=t;for(;r!==cd(r);)try{let i=await Sb(r);return e.length?kb(i,...e.reverse()):i}catch{e.push(Tb(r)),r=cd(r)}return t}se();var eh=G("prompt-multimodal"),th=10*1024*1024,Nb=15e3,Mb=6;async function nh(t){let e=new Array(t.length),r=0;async function i(){for(;r<t.length;){let c=r++,d=t[c];d!==void 0&&(e[c]=await Bb(d))}}let o=Array.from({length:Math.min(Mb,t.length)},()=>i());return await Promise.all(o),e}function rh(t){return t.some(e=>e.type==="image")}async function Bb(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Oi(e.uri))return t;try{let{buf:r,contentType:i}=await zb(e.uri),o=e.mimeType||Fb(i)||"application/octet-stream";return eh.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 eh.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function Fb(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function zb(t){let e=new AbortController,r=setTimeout(()=>e.abort(),Nb);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>th)throw new Error(`image too large: ${o.byteLength} bytes (max ${th})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}fn();Xe();se();var W=G("core"),Gb=3e4,Hb=/^(boe|ppe)_[A-Za-z0-9_-]+$/,jb="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",qb="\u5BA1\u6279\u5DF2\u8D85\u65F6",Wb=3e4,To=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Nr;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=$0(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,d)=>{W.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:d}),ji(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(Rn(o,{code:re.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(d=>W.debug("send error response to upstream failed (ignored)",{err:String(d)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:re.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:re.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 R("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(go(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&&Hb.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,re.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(Lr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Lr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Lr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,re.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(Rn(r,Ui(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new R("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new R("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new R("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new R("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 f=o.sessions.get(c);if(f?.pendingPermission){let x=r._meta?.cozeTriggerMsgId,g=ao(r._meta);return W.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,f,c,jb,x,g)}}let d=Date.now(),u=!1;try{let f=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,f}finally{W.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-d,ok:u})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=Tf(i);switch(r){case"session/new":{let c=Kb();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,d=c.sessionId;if(!d)throw new R("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=Xt(e)?Af(i._meta):void 0;if(u!==void 0&&!kn(e.framework,u))throw new R("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${nd(e.framework)}`);let f=await this.ensureRuntime(e,d);if(u!==void 0&&f.permissionMode===void 0&&(f.permissionMode=u,await this.persistSessionMapping(e)),f.replySeq=0,await this.ensureDownstream(e,d,f),!f.downstream||!f.acpSessionId)throw new R("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&f.permissionMode!==void 0&&f.permissionMode!==u){let S=f.permissionMode;f.permissionMode=u,await this.persistSessionMapping(e);try{await f.downstream.setSessionMode({sessionId:f.acpSessionId,modeId:u})}catch(_){throw f.permissionMode=S,await this.persistSessionMapping(e).catch(()=>{}),_}}let x=i._meta?.cozeTriggerMsgId;x?e.activeTriggers.set(f.acpSessionId,x):e.activeTriggers.delete(f.acpSessionId);let g=ao(i._meta);if(g?e.activeGroupIds.set(f.acpSessionId,g):e.activeGroupIds.delete(f.acpSessionId),g&&f.cozeGroupId!==g&&(f.cozeGroupId=g,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&rh(c.prompt))throw new R("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let w=await nh(c.prompt);try{let S=await f.downstream.sessionPrompt({...c,sessionId:f.acpSessionId,prompt:w});return f.lastActiveAt=Date.now(),S}catch(S){if(S instanceof R&&S.code==="AGENT_APPROVAL_TIMEOUT"){let _=f.pendingPermission;_&&(_.downstream.respondAgentRequest(_.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(_.upstreamId),f.pendingPermission=void 0);let b=f.acpSessionId,I=b?e.activeTriggers.get(b):void 0,T=b?e.activeGroupIds.get(b):void 0;return W.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:d}),await this.synthesizePromptReply(e,f,d,qb,I,T)}throw S}finally{if(e.activeTriggers.delete(f.acpSessionId),e.activeGroupIds.delete(f.acpSessionId),f.pendingPermission=void 0,f.reloadAfterTurn){f.reloadAfterTurn=!1;let S=f.downstream;S&&(f.downstream=void 0,W.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:d,acpId:f.acpSessionId}),S.stop("reload-after-turn").catch(_=>W.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:d,err:String(_)})))}else f.downstream?.isAlive()&&this.armIdleTimer(e,d,f)}}case"session/cancel":{let d=o.sessionId;if(!d)throw new R("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(d);if(e.hasSessionQueue(d)){let f=e.getSessionQueue(d);f.size>0&&(W.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:d,queuedCount:f.size}),f.dispose(new R("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${d}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,d=c.sessionId,u=c.modeId,f=ao(i._meta);if(!d)throw new R("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Xt(e))throw e.framework==="openclaw"?new R("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new R("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!kn(e.framework,u))throw new R("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${nd(e.framework)}`);if(f)return await this.handleGroupSetMode(e,f,u);let x=e.sessions.get(d)??await this.ensureRuntime(e,d);if(x.permissionMode===u)return{};let g=x.permissionMode;if(x.permissionMode=u,await this.persistSessionMapping(e),x.downstream?.isAlive()&&x.acpSessionId)try{await x.downstream.setSessionMode({sessionId:x.acpSessionId,modeId:u})}catch(w){throw x.permissionMode=g,await this.persistSessionMapping(e).catch(()=>{}),w}else W.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:d,modeId:u});return{}}default:throw new R("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async handleGroupSetMode(e,r,i){let o=[];for(let[d,u]of e.sessions)u.cozeGroupId===r&&u.permissionMode!==i&&o.push({cloudId:d,runtime:u,oldMode:u.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 d of o)d.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let d of o){let u=d.runtime.downstream,f=d.runtime.acpSessionId;u?.isAlive()&&f&&c.push({downstream:u,acpSessionId:f,oldMode:d.oldMode,runtime:d.runtime})}for(let d of c)try{await d.downstream.setSessionMode({sessionId:d.acpSessionId,modeId:i})}catch(u){for(let f of o)f.runtime.permissionMode=f.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),u}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 Xt(e)&&(c.permissionMode=e.framework==="claude-code"?od:P0),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(St.GEN_MODEL_TOKEN,i,Wb);if(!o?.modelToken)throw new R("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof R&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new R("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(ji(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new R("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,d=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(d>=o&&Date.now()-u<c)throw new R("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${d} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let f;try{f=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(x){throw i.spawnFailCount=d+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(W.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),x}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=f,this.attachRuntimeHooks(e,r,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await f.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),W.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(x){W.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(x)}),i.acpSessionId=void 0;let g=await f.sessionNew({cwd:e.workspace});i.acpSessionId=g.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let x=await f.sessionNew({cwd:e.workspace});i.acpSessionId=x.sessionId,await this.persistSessionMapping(e)}}catch(x){throw W.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(x)}),await f.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,x}if(f.afterSessionEstablished&&i.acpSessionId&&await f.afterSessionEstablished(i.acpSessionId),Xt(e)&&i.acpSessionId&&i.permissionMode)try{await f.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(x){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(x)})}}armIdleTimer(e,r,i){if(ji(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 d=e.activeTriggers.get(r.acpSessionId);d&&(c.cozeTriggerMsgId=d);let u=e.activeGroupIds.get(r.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Or("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,d){let u={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(u.cozeTriggerMsgId=c),d&&(u.cozeGroupId=d),await this.upstream.send(Or("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(f=>W.warn("synthesizePromptReply update send failed (ignored)",{err:String(f)})),{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(Jb(r)){W.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let d=r.update;if(d&&typeof d=="object"&&d.sessionUpdate==="current_mode_update"&&Xt(e)){let g=d.currentModeId;kn(e.framework,g)&&c.permissionMode!==g?(c.permissionMode=g,this.persistSessionMapping(e).catch(w=>W.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(w)}))):typeof g=="string"&&!kn(e.framework,g)&&W.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:g})}let u={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},f=e.activeTriggers.get(i);f&&(u.cozeTriggerMsgId=f);let x=e.activeGroupIds.get(i);x&&(u.cozeGroupId=x),this.upstream.send(Or("session/update",{...r,sessionId:o,_meta:u})).catch(g=>W.warn("forward update failed",{agentId:e.agentId,err:String(g)}))}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:re.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},d=await Y0(c,o);r.respondAgentRequest(i.id,d)}else{let c=i.params??{},d=await X0(c,o);r.respondAgentRequest(i.id,d)}}catch(o){W.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Ui(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,f=u?e.activeTriggers.get(u):void 0,x={cozeAgentId:e.agentId};f&&(x.cozeTriggerMsgId=f);let g=u?e.activeGroupIds.get(u):void 0;g&&(x.cozeGroupId=g);let w=u?this.reverseSessionId(e,u):void 0,S=w?e.sessions.get(w):void 0;S&&(S.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let _={...c,...w?{sessionId:w}:{},_meta:x};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:w}),W.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:w,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(b=>({optionId:b.optionId,kind:b.kind,name:b.name}))}),this.upstream.send(Fi(o,"session/request_permission",_)).catch(b=>{this.pendingUpstream.delete(o),W.error("forward permission request failed",{agentId:e.agentId,err:String(b)}),r.respondAgentRequestError(i.id,{code:re.INTERNAL_ERROR,message:`upstream send failed: ${String(b)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let r=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(r){this.pendingUpstream.delete(r.key);let o=r.value;this.clearPendingPermissionFor(o),e.error?(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"&&$b(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 po(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),d=e.get(c);if(d)return W.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:d,key:c}}}sendRequest(e,r,i=Gb){let o=this.upstreamIds.next(e);return new Promise((c,d)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),d(new R("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:d,timer:u}),this.upstream.send(Fi(o,e,r)).catch(f=>{let x=this.pendingBridge.get(o);x&&(clearTimeout(x.timer),this.pendingBridge.delete(o)),d(f)})})}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&&Xt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await oi(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(Rn(e,{code:r,message:i,data:{bridgeVersion:Bt}}))}};function Kb(){return Ub(16).toString("hex")}function $b(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 Vb=["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 Jb(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 Vb.some(c=>o.startsWith(c))}un();se();Fe();import{randomBytes as Zb}from"node:crypto";import{createServer as Yb}from"node:http";var Xb=1e6,ih=G("ipc"),Ro=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??ne()}async start(){this.token=Zb(32).toString("hex");let e=Yb((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(),ih.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 ln(this.paths.portFile,String(this.port)),await ln(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){$i(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){$i(r,404,{error:"not found"});return}let d=null;if(e.method==="POST")try{d=await Qb(e)}catch(u){$i(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(d,e);$i(r,200,u??{ok:!0})}catch(u){ih.error("IPC handler failed",{key:o,err:String(u)}),$i(r,500,{error:u instanceof Error?u.message:String(u)})}}};function $i(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function Qb(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>Xb)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 yv=qt(Qh(),1),bv=qt(Bo(),1),Ev=qt(Gr(),1),vv=qt(_d(),1),Sv=qt(Ed(),1),Iv=qt(Rd(),1),cx=qt(Go(),1),Av=qt(ax(),1);var dx=cx.default;Xe();se();var{FWS:Hv}=bx(),Me=G("upstream.frontier"),vx="application/json",Sx="none",jv=15e3;function qv(t){class e extends dx{constructor(i){super(i,Pf,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>Me.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(gl("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let d=Buffer.from(c.slice(0,128)).toString("hex");Me.debug("WS raw frame out",{bytes:c.byteLength,headHex:d})}catch(c){Me.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var ns=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){Me.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Of,...Dr(this.opts.ppeOverride)},r=qv(e),i=Nf(this.opts.urlOverride),o={url:i,ws:r,fpID:Df,aID:lo,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:vx,force:!0},payloadEncoding:{encoding:Sx,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new Hv(o),d=!1,u=null,f,x,g=new Promise((_,b)=>{f=_,x=b}),w=_=>{d||(d=!0,u&&(clearTimeout(u),u=null),_?x(_):f())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let _=this.openCount===1;Me.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:_,openCount:this.openCount}),_&&w();for(let b of this.connectHandlers)Promise.resolve(b({initial:_})).catch(I=>Me.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=_=>{this.opened=!1,Me.info("frontier closed",{code:_.code,reason:_.reason,willReconnect:_.willReconnect})},c.onerror=_=>{Me.warn("frontier error",{code:_.code,msg:_.message}),w(new R("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${_.code} msg=${_.message??""}`))},c.onmessage=_=>this.handleMessage(_),this.fws=c;let S=this.opts.openTimeoutMs??jv;u=setTimeout(()=>{w(new R("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${S}ms (handshake or upgrade slow)`))},S),await c.connect();try{await g}catch(_){try{c.close(1e3,"open failed")}catch(b){Me.warn("fws close during start failure threw (ignored)",{err:String(b)})}throw this.fws=null,this.opened=!1,_}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){Me.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw Me.warn("frontier send refused: upstream not started",{method:i}),new R("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let u=Date.now();throw u-this.lastSendRefusedLogAt>1e3?(Me.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:r.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=u,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new R("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;Ix(c)||Me.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:vx,payloadEncoding:Sx})}catch(u){throw Me.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new R("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){Me.debug("drop non-adapter frontier frame",{service:r});return}let i=$v(e);if(!i){Me.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){Me.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(d){Me.warn("frontier message JSON parse failed",{err:String(d),head:i.slice(0,80)});return}let c=o;Ix(c)||Me.info("frontier frame in",{logid:Kv(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:Wv(i)}),Promise.resolve(this.handler(o)).catch(d=>Me.warn("frontier frame handler threw",{err:String(d)}))}};function Ix(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Ax=2e3;function Wv(t){return t.length<=Ax?t:`${t.slice(0,Ax)}...<truncated, total ${t.length} chars>`}function Kv(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function $v(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}}se();var Pd=G("upstream.switchable"),Zo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;Pd.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 Pd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>Pd.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()}};se();var Od=G("upstream"),$r=class{handler=null;async start(){Od.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Od.info("NoopUpstream stopped",{reason:e})}async send(e){Od.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)}};Xe();se();un();se();Fe();import{promises as Vv}from"node:fs";var Tx=G("pat-token-store");async function Yo(t=ne()){try{let r=(await Vv.readFile(t.patTokenFile,"utf8")).trim();return r.length===0?(Tx.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"&&Tx.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function rs(t,e=ne()){if(!t)throw new Error("writePatToken: empty patToken");await ln(e.patTokenFile,t,{mode:384})}Fe();Fe();import{promises as Xo}from"node:fs";import{join as Jv}from"node:path";function Zv(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 Yv(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 Rx(t,e=ne()){let r=e.binDir;await Xo.mkdir(r,{recursive:!0});let i=Jv(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?Yv(t,o):Zv(t,o);return await Xo.readFile(i,"utf8").catch(()=>null)===c||(await Xo.writeFile(i,c,"utf8"),process.platform!=="win32"&&await Xo.chmod(i,493)),r}se();Fe();import{execSync as kx}from"node:child_process";import{readFileSync as Cx,unlinkSync as Xv}from"node:fs";import{mkdir as Qv,open as eS,readFile as Dx,unlink as Ld,writeFile as tS}from"node:fs/promises";import{dirname as nS}from"node:path";var rS=G("single-instance"),iS=t=>new Promise(e=>setTimeout(e,t)),Qo=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??ne().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:r=>Gi(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&&rS.warn("removing stale pid file",{stalePid:i}),await tS(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 Dx(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Ld(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 Dx(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 Qv(nS(r),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await eS(r,"wx")}catch(c){if(c.code!=="EEXIST")throw c;let d=await this.readPidFrom(r);if(d!==null&&d!==this.selfPid&&this.probe.isAlive(d)){await iS(this.claimLockIntervalMs);continue}await Ld(r).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Ld(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=Cx(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes(Mr)||r.includes("lib/index.js"))}catch{}try{let r=kx(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes(Mr)||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=kx(`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{Cx(this.pidFile,"utf8").trim()===String(this.selfPid)&&Xv(this.pidFile)}catch{}})}};ea();se();var nr=G("daemon.upstream-watchdog"),fS=12e4,hS=9e5,xS=3e4;function Md(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var ta=class{constructor(e){this.opts=e;this.softMs=e.softMs??Md("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",fS),this.hardMs=e.hardMs??Md("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",hS),this.intervalMs=e.intervalMs??Md("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",xS),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?.(),nr.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&&nr.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&&nr.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,nr.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){nr.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,nr.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>nr.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var q=G("daemon");async function Lx(){let t=ne();if(process.env.COZE_BRIDGE_LOG_MODE!=="legacy"){xl({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:O=>st(O,t).logs,listAgentIds:()=>hs(t)});try{let{writeFileSync:O}=await import("node:fs");O(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}
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}
109
+ `)}catch{}}let e=new Qo({processTitle:Mr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await Ao(),o=i??{};us({pid:process.pid}),q.info(i?"loaded bridge config":"initialized bridge config");let c=new Zo(new $r),d=null,u=new To({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(O,H,K,de)=>{if(!d)throw new Error("agentManager not ready");return d.spawnSessionDownstream(O,H,K,de)}}),f=new vo({paths:t,config:o,registry:u});d=f;let x,g,w=null,S={},_,b=null,I=null,T=null,k=new Cn;function D(O,H){return k.enqueue(()=>C(O,H))}function y(){I||(I=new ta({isConnected:()=>c.isConnected()&&!(b?.isLivenessLost()??!1),forceReconnect:()=>T?D(T,{force:!0}):void 0,onFatal:O=>{if(process.env[is]==="1"){q.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:O});return}q.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:O}),process.exit(1)}})),I.start()}async function C(O,H){let K=O,de=K?.privatecode;if(!de)throw new R("IPC_BAD_REQUEST","/connect requires privatecode");let rt=Ni(K.env),me=K.handshake_url,we=K.frontier_url,kt=Ox(K.env,me,we);if(T=K,!H?.force&&x===de&&g===kt){let Ee=await pS(t);return u.agents.size===0&&Ee?(q.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),ra(t,f).catch(Ce=>q.warn("connect-noop auto-revive error (ignored)",{err:String(Ce)}))):q.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let mt=!!x&&x!==de,sn=g!==void 0&&g!==kt,jt=mt||sn,on=await Hc({privatecode:de,...me?{endpoint:me}:{},ppeOverride:rt});if(jt){q.warn("connect config switched, resetting agents",{pcChanged:mt,envChanged:sn,previousPc:x?na(x):"",nextPc:na(de)});for(let Ee of[...u.agents.values()])await Ee.dispose("connect config switch").catch(()=>{}),u.agents.delete(Ee.agentId);u.disconnectedAgents.size>0&&(q.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new $r,"connect switch").catch(()=>{})}w=on.deviceId,us({deviceId:w,pid:process.pid}),ad({patToken:de,env:K.env}).catch(Ee=>q.warn("coze-cli setup error (ignored)",{err:String(Ee)}));let Xr=new ns({handshake:on,privatecode:de,...we?{urlOverride:we}:{},ppeOverride:rt,getPatTokenForAgent:Ee=>u.agents.get(Ee)?.patToken});return await c.swap(Xr,"connect"),x=de,g=kt,S=rt,_=me,K.mock_scenario!==void 0&&(u.setMockScenario(K.mock_scenario),q.info("mock scenario set",{scenario:K.mock_scenario})),b||(b=new Bi({core:u,getDeviceId:()=>w??"",onTickEnd:()=>M.retryPending().catch(Ee=>q.warn("detailSync.retryPending failed (ignored)",{err:String(Ee)})),onAuthFailures:Y})),b.start(),y(),jt&&ra(t,f).catch(Ee=>q.warn("post-connect-switch auto-revive error (ignored)",{err:String(Ee)})),rs(de,t).catch(Ee=>q.warn("writePatToken after /connect failed (ignored)",{err:String(Ee)})),q.info("/connect: WS established",{deviceId:w}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async O=>f.createAgent(O.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let P={},F=new fo({agents:u.agents,disposeAndMarkDisconnected:async(O,H)=>{let K=u.agents.get(O);if(K){await f.cleanupOpenclawSessionProviders(K).catch(rt=>q.warn("cleanup openclaw providers failed (ignored)",{agentId:O,err:String(rt)}));let de=!0;try{await K.dispose(`disconnect: ${H}`)}catch(rt){de=!1,q.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:O,err:String(rt)}),K.status="error"}de&&(K.status="disconnected",u.unregister(O),u.disconnectedAgents.add(O))}else u.disconnectedAgents.add(O)},detailSyncer:async O=>{if(!P.ref)throw new Error("agent-detail-sync not initialized yet");await P.ref.syncOne(O)},cleanupOpenclawProviders:async O=>{await f.cleanupOpenclawSessionProviders(O)},openclawRepair:async(O,H)=>{await f.openclawRepair(O,H)},isRuntimePendingPermission:O=>u.hasPendingPermissionFor(O)});u.registerExtension("_agent/listSkills",O=>F.listSkills(O.params)),u.registerExtension("_agent/addSkills",O=>F.addSkills(O.params)),u.registerExtension("_agent/removeSkills",O=>F.removeSkills(O.params)),u.registerExtension("_agent/getFileTree",O=>F.getFileTree(O.params)),u.registerExtension("_agent/getFileContent",O=>F.getFileContent(O.params)),u.registerExtension("_agent/update",O=>F.updateAgent(O.params)),u.registerExtension("_agent/disconnect",O=>F.disconnectAgent(O.params)),u.registerExtension("_agent/switchModel",O=>F.switchModel(O.params)),u.registerExtension("_agent/reset",O=>F.resetAgent(O.params)),u.registerExtension("_agent/repair",O=>F.repairAgent(O.params)),u.registerExtension("_agent/upgrade",O=>F.upgradeBridge(O.params));let M=new ms({paths:t,handlers:F,agentManager:f,sendDetail:O=>u.sendRequest("_agent/detail",O)});P.ref=M;let Y=async O=>{await Promise.allSettled(O.map(async H=>{try{await F.disconnectAgent({agentId:H.agentId,reason:`auth_failure: code=${H.code} ${H.message}`}),q.info("agent disconnected due to auth failure from heartbeat response",{agentId:H.agentId,code:H.code,message:H.message})}catch(K){q.warn("disconnect during authFailure handling failed (ignored)",{agentId:H.agentId,err:String(K)})}}))};c.onConnect(({initial:O})=>{q.info("frontier upstream connected, triggering detail sync",{initial:O}),M.syncAll(O?"initial-connect":"reconnect").catch(H=>q.warn("detail sync top-level error (ignored)",{err:String(H)}))});let J=new Ro({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let O=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[is]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:w??"",frameworksCache:o.frameworksCache??{},...O?{mockScenario:O}:{}}}},{method:"POST",path:"/pair",handler:async O=>{let H=O,K=H?.privatecode,de=H?.pairing_code;if(!K||!de)throw new R("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let rt=Ni(H.env),me=H.handshake_url,we=H.frontier_url,kt=Ox(H.env,me,we),mt=!!x&&x!==K,sn=g!==void 0&&g!==kt,jt=mt||sn,on=await Hc({privatecode:K,...me?{endpoint:me}:{},ppeOverride:rt});if(jt){q.warn("pair config switched, resetting agents",{pcChanged:mt,envChanged:sn,previousPc:x?na(x):"",nextPc:na(K),previousEnvKey:g??"",nextEnvKey:kt});for(let Ce of[...u.agents.values()])await Ce.dispose("pair config switch").catch(()=>{}),u.agents.delete(Ce.agentId);u.disconnectedAgents.size>0&&(q.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new $r,"pair switch").catch(()=>{})}w=on.deviceId,us({deviceId:w,pid:process.pid}),ad({patToken:K,env:H.env}).catch(Ce=>q.warn("coze-cli setup error (ignored)",{err:String(Ce)}));let Xr=new ns({handshake:on,privatecode:K,...we?{urlOverride:we}:{},ppeOverride:rt,getPatTokenForAgent:Ce=>u.agents.get(Ce)?.patToken});await c.swap(Xr,"pair");try{let Ce=new Zn;o.frameworksCache=await Ce.detectAll(),await Wi(o),q.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ce){q.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ce)})}let Ee=Object.keys(o.frameworksCache??{});try{let Ce=await u.sendRequest("_agent/pair",{pairCode:de,patToken:K,frameworks:Ee,_meta:{cozeDeviceId:w}});q.info("_agent/pair ok",{pairResult:Ce}),x=K,g=kt,S=rt,_=me,H.mock_scenario!==void 0&&(u.setMockScenario(H.mock_scenario),q.info("mock scenario set",{scenario:H.mock_scenario})),rs(K,t).catch(Be=>q.warn("writePatToken after /pair failed (ignored)",{err:String(Be)})),b||(b=new Bi({core:u,getDeviceId:()=>w??"",onTickEnd:()=>M.retryPending().catch(Be=>q.warn("detailSync.retryPending failed (ignored)",{err:String(Be)})),onAuthFailures:Y})),b.start(),y(),jt&&ra(t,f).catch(Be=>q.warn("post-pair-switch auto-revive error (ignored)",{err:String(Be)}));let rr;return H.agent_id&&(rr=await mS(H.agent_id,t,f,Be=>u.sendRequest("_agent/detail",Be),K).catch(Be=>(q.error("--agent-id ensureAgent failed",{agentId:H.agent_id,err:String(Be)}),{ok:!1,agentId:H.agent_id??"",note:String(Be)}))),{ok:!0,note:"paired with cloud",...rr?{agent:rr}:{}}}catch(Ce){return q.error("_agent/pair failed",{err:String(Ce)}),{ok:!1,note:`pair failed: ${String(Ce)}`}}}},{method:"POST",path:"/connect",handler:O=>D(O)},{method:"POST",path:"/_agent/create",handler:async O=>{let H=O;return{ok:!0,result:await f.createAgent(H)}}},{method:"POST",path:"/agent/send",handler:async O=>{let H=O;if(!H?.agentId||!H?.sessionId||!H?.kind||!H?.path)throw new R("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!x)throw new R("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let K=H;return await(K.groupFile?H0:G0)(K,{core:u,patToken:x,handshakeBase:_,ppeOverride:S})}catch(K){if(K instanceof R)return{ok:!1,code:K.code,message:K.message};throw K}}},{method:"POST",path:"/reload",handler:async O=>{let H=O?.agent_id,K=await u.reloadAgents(H);return q.info("IPC /reload: recycled agent subprocesses",{agentId:H??"(all)",recycled:K}),{ok:!0,recycled:K}}},{method:"POST",path:"/shutdown",handler:async()=>(q.info("IPC /shutdown received"),setImmediate(()=>{le.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:ie,token:Q}=await J.start();try{await Rx(t.libEntry,t)}catch(O){q.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(O)})}await u.start(),wS({paths:t,core:u,agentManager:f,detectAll:async()=>(o.frameworksCache=await new Zn().detectAll(),await Wi(o),o.frameworksCache)}).catch(O=>q.warn("startup warmup error (ignored)",{err:String(O)})),Sl().then(async()=>{let{probeAcpVersion:O}=await Promise.resolve().then(()=>(dn(),El));for(let H of["claude-code","codex"]){let K=await O(H);K&&q.info("acp wrapper version",{framework:H,version:K})}}).catch(O=>q.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(O)}));let ce=null,le={port:ie,token:Q,core:u,ipc:J,shutdown(O){return ce||(q.info("daemon shutdown",{reason:O}),ce=(async()=>{b?.stop(),I?.stop(),await u.stop(O),await J.stop(),await e.release()})(),ce)}};for(let O of["SIGTERM","SIGINT"])process.on(O,()=>{le.shutdown(O).then(()=>process.exit(0))});return process.on("exit",()=>u0()),process.on("unhandledRejection",O=>{q.error("unhandledRejection",{reason:O instanceof Error?O.message:String(O),stack:O instanceof Error?O.stack:void 0})}),process.on("uncaughtException",O=>{q.error("uncaughtException (will exit, supervisor will restart)",{message:O.message,stack:O.stack,name:O.name});try{process.stderr.write(`FATAL uncaughtException: ${O.stack??O.message}
110
+ `)}catch{}process.exit(1)}),q.info("daemon ready",{port:ie,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),yS({cliSpawned:process.env[is]==="1",readPatToken:()=>Yo(t),connect:D}).catch(O=>q.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(O)})),le}async function pS(t){return hs(t).length>0}function na(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function Ox(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function gS(t,e){let r=hs(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(fn(),gs));for(let c of r){await o(c,t).catch(d=>q.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(d)}));try{let d=await i(c,t);d?.disconnectedAt&&(e.disconnectedAgents.add(c),q.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:d.disconnectedAt,reason:d.disconnectReason??""}))}catch(d){q.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(d)})}}}async function mS(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(fn(),gs)),d=await c(t,e);if(d){q.info("--agent-id: local config found, reconnecting",{agentId:t,framework:d.framework,hadDisconnect:!!d.disconnectedAt});let g=Nx(d),w={agentId:d.agentId,framework:d.framework,...d.cozeIdentity?{cozeIdentity:d.cozeIdentity}:{},...d.model?{model:d.model}:{},...o?{patToken:o}:{},...g?{_meta:g}:{}};return await r.createAgent(w),{ok:!0,agentId:t,note:d.disconnectedAt?"revived from local config":"connected from local config"}}q.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let u=await i({_meta:{cozeAgentId:t}});if(!u.framework)throw new R("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 f={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...u.deployType?{_meta:{cozeDeployType:u.deployType}}:{}};await r.createAgent(f);let x=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:x?"cloud agent acknowledged":"created from cloud detail"}}async function wS(t){let e=t.logger??q;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 gS(t.paths,t.core).catch(r=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(r)})),await ra(t.paths,t.agentManager).catch(r=>e.warn("auto-revive top-level error (ignored)",{err:String(r)})),await _S(t.paths).catch(r=>e.warn("builtin skill refresh top-level error (ignored)",{err:String(r)}))}async function ra(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(()=>(fn(),gs));q.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,d=0;for(let u of i){let f;try{f=await o(u,t)}catch(x){q.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(x)}),d+=1;continue}if(!f){d+=1;continue}if(f.disconnectedAt){q.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:f.disconnectedAt}),d+=1;continue}try{q.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:f.framework});let x=Nx(f);await e.createAgent({agentId:f.agentId,framework:f.framework,...f.cozeIdentity?{cozeIdentity:f.cozeIdentity}:{},...f.model?{model:f.model}:{},...x?{_meta:x}:{}},{revive:!0}),c+=1}catch(x){q.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:f.framework,err:String(x)}),d+=1}}return q.info("auto-revive: done",{revived:c,skipped:d,total:i.length}),{revived:c,skipped:d,total:i.length}}async function _S(t){let{readdir:e}=await import("node:fs/promises"),r;try{r=await e(t.agentsRoot)}catch{return{refreshed:0,total:0}}if(r.length===0)return{refreshed:0,total:0};let i=0;for(let o of r)try{(await Xf(o,t)).status==="refreshed"&&(i+=1)}catch(c){q.warn("refresh builtin skills failed (skipping agent)",{agentId:o,err:String(c)})}return i>0&&q.info("builtin skills refresh on startup done",{refreshed:i,total:r.length}),{refreshed:i,total:r.length}}async function yS(t){let e=t.logger??q;if(t.cliSpawned)return"skipped-cli";let r=await t.readPatToken();return r?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:r}).catch(i=>e.warn("startup auto-connect failed (staying idle)",{err:String(i)})),"connecting"):(e.info("no stored PAT, skip startup auto-connect"),"skipped-no-pat")}function Nx(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}ea();Fe();import{readFile as Mx}from"node:fs/promises";var rn=class{paths;constructor(e){this.paths=e??ne()}async probe(e=1e3){let r=await ia(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:ES(i)}}}async request(e){let r=await ia(this.paths);if(!r)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(r,e)}async fetch(e,r){let i=r.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,d=setTimeout(()=>c.abort(),r.timeoutMs??5e3);try{let u=await fetch(`http://127.0.0.1:${e.port}${r.path}`,{method:r.method,headers:o,body:i?JSON.stringify(r.body):void 0,signal:c.signal}),f=await u.text();return{status:u.status,body:bS(f)}}finally{clearTimeout(d)}}};async function ia(t){try{let[e,r]=await Promise.all([Mx(t.portFile,"utf8"),Mx(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 ES(t){return t instanceof Error?t.message:String(t)}Yt();se();ar();import{spawn as vS}from"node:child_process";import{userInfo as Fx}from"node:os";var Bd="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",SS=new Set(["bash","zsh","sh","dash","ksh"]),Bx=Ye("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),IS=2e3;function AS(t,e=Bd){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 d of o.split(`
111
+ `)){let u=d.indexOf("=");u<=0||(c[d.slice(0,u)]=d.slice(u+1))}return c}function TS(){let t=(process.env.SHELL??"").trim()||(Fx().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return SS.has(e)?t:null}function RS(t){return new Promise(e=>{let r=`printf '%s' '${Bd}'; env; printf '%s' '${Bd}'`,i;try{i=vS(t,["-ilc",r],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??Fx().homedir}})}catch{e(null);return}let o="",c=!1,d=g=>{try{i.pid&&process.kill(-i.pid,g)}catch{}},u=g=>{c||(c=!0,clearTimeout(f),clearTimeout(x),e(g))};i.stdout?.on("data",g=>{o+=g.toString("utf8")}),i.on("error",()=>u(null)),i.on("close",()=>u(o.length>0?o:null));let f=setTimeout(()=>d("SIGTERM"),Bx),x=setTimeout(()=>{d("SIGKILL"),u(o.length>0?o:null)},Bx+IS)})}async function Fd(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??RS)(r);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=AS(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}Fe();function On(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],d=!1;for(let u of e){if(c===u){i=t[o+1],o+=1,d=!0;break}if(c.startsWith(`${u}=`)){i=c.slice(u.length+1),d=!0;break}}d||r.push(c)}return{value:i,rest:r}}dn();import{chmod as kS,copyFile as zx,mkdir as Gx,readFile as sa,rename as Ux,rm as zd,stat as Hx,writeFile as CS}from"node:fs/promises";import{homedir as AD}from"node:os";import{dirname as DS,join as Vr,resolve as Ud,sep as ss}from"node:path";import{fileURLToPath as PS}from"node:url";Yt();se();Fe();var Gd=G("dist-install");function OS(t){let e=PS(t),r=DS(e),i=`${ss}src${ss}`;if(r.includes(i)||r.endsWith(`${ss}src${ss}cli`))return null;let o=Ud(r,"index.js"),c=Ud(r,"..","package.json");return{dist:o,pkgJson:c}}async function jd(t={}){let e=t.paths??ne(),r=OS(import.meta.url),i=t.sourceDist??r?.dist,o=t.sourcePackageJson??r?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,d;try{let S=JSON.parse(await sa(o,"utf8"));c=S.version??"unknown",d=S.dependencies??{}}catch(S){return Gd.warn("cannot read source package.json,skip dist install",{err:String(S)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(S)}`}}let u=ri.map(S=>`${S}@${d[S]??"latest"}`),f=await Ao(e.configFile)??{},x=f.libVersion,g=await sa(e.libEntry).then(()=>!0).catch(()=>!1),w=x===c;if(w&&g&&await Hd(e))return{kind:"already-current",libVersion:c};if(!w||!g){await Gx(e.libDir,{recursive:!0}),await zx(i,e.libEntry),await zx(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let S=Ud(e.libDir,"package.json"),_=`${JSON.stringify({type:"module"},null,2)}
112
+ `;await sa(S,"utf8").catch(()=>null)!==_&&await CS(S,_)}return(!w||!await Hd(e))&&await(t.installWrappers??LS)(e,u),f.libVersion=c,await Wi(f,e.configFile),Gd.info("dist installed",{libEntry:e.libEntry,fromVersion:x,toVersion:c}),w&&g?{kind:"already-current",libVersion:c}:x?{kind:"version-changed",fromVersion:x,toVersion:c,libEntry:e.libEntry}:{kind:"first-install",libVersion:c,libEntry:e.libEntry}}async function Hd(t){for(let e of ri){let r=Vr(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await Hx(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function LS(t,e){await BS(t.installLock,async()=>{if(await Hd(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${ss}.staging-${process.pid}-${r}`,o=Vr(i,"node_modules"),c=Vr(t.libDir,"node_modules");try{await Gx(i,{recursive:!0}),await NS(e,i),await MS(o);let d=`${c}.trash-${r}`;await Ux(c,d).catch(()=>{}),await Ux(o,c),await zd(d,{recursive:!0,force:!0}).catch(()=>{}),Gd.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await zd(i,{recursive:!0,force:!0}).catch(()=>{})}})}function NS(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=at("npm",r,{stdio:["ignore","pipe","pipe"]}),d="";c.stderr?.on("data",f=>{d.length<8192&&(d+=f.toString("utf8"))});let u=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",f=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(f)}`))}),c.once("close",f=>{clearTimeout(u),f===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${f}: ${d.trim().slice(0,2e3)}`))})})}async function MS(t){for(let e of ri){let r=Vr(t,...e.split("/")),i=JSON.parse(await sa(Vr(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=Vr(t,".bin",o),d=await Hx(c);process.platform!=="win32"&&!(d.mode&73)&&await kS(c,d.mode|73).catch(()=>{})}}async function BS(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 zd(t,{force:!0}).catch(()=>{})}}Ta();se();Fe();import{closeSync as qx,fstatSync as Wx,openSync as Kx,readFileSync as FS,readSync as zS,readdirSync as US,statSync as GS}from"node:fs";import{join as oa}from"node:path";var HS=new Set(["debug","info","warn","error"]);function $x(t){let e=t,r=On(e,"--agent-id");e=r.rest;let i=On(e,"--date");e=i.rest;let o=On(e,"-n","--lines");e=o.rest;let c=On(e,"--level");e=c.rest;let d=On(e,"--grep");e=d.rest;let u=o.value===void 0?200:Number(o.value),f=Number.isInteger(u)&&u>=0?u:200,x=c.value&&HS.has(c.value)?c.value:void 0,g={lines:f,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(g.agentId=r.value),i.value&&(g.date=i.value),x&&(g.level=x),d.value&&(g.grep=d.value),g}function jS(t,e){return t.agentId?oa(st(t.agentId,e).logs,cr("agent",t.date)):oa(e.bridgeLogsDir,cr("bridge",t.date))}function qS(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function WS(t,e){let r;try{r=US(t)}catch{return[]}let i=[];for(let o of r){let c=Aa(o,e);if(!c)continue;let d=0;try{d=GS(oa(t,o)).size}catch{}i.push({file:oa(t,o),date:c,size:d})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function Vx(t,e){if(e.grep&&!t.includes(e.grep))return!1;if(e.level){let r;try{r=JSON.parse(t).level}catch{return!0}if(typeof r=="string"&&!ml(r,e.level))return!1}return!0}var jx={debug:"90",info:"36",warn:"33",error:"31"},KS=new Set(["ts","level","module","msg"]);function $S(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function Jx(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=$S(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&jx[o]&&(c=`\x1B[${jx[o]}m${c}\x1B[0m`);let d=typeof r.module=="string"?r.module:"",u=typeof r.msg=="string"?r.msg:"",f=Object.entries(r).filter(([x])=>!KS.has(x)).map(([x,g])=>` ${x}=${typeof g=="string"?g:JSON.stringify(g)}`).join("");return`${i} ${c} ${d} ${u}${f}`}function VS(t,e,r){let c=FS(t,"utf8").split(`
113
+ `).filter(d=>d.length>0).filter(d=>Vx(d,{level:e.level,grep:e.grep}));for(let d of qS(c,e.lines))process.stdout.write(`${Jx(d,{raw:e.raw,color:r})}
114
+ `)}async function Zx(t,e){let r=e.paths??ne(),i=process.stdout.isTTY===!0;if(t.list){let d=t.agentId?st(t.agentId,r).logs:r.bridgeLogsDir,u=t.agentId?"agent":"bridge",f=WS(d,u);if(f.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${d}
115
+ `),1;for(let x of f)process.stdout.write(`${x.date} ${(x.size/1024).toFixed(1)}KB ${x.file}
116
+ `);return 0}let o=t.date??Nn(new Date),c=jS({agentId:t.agentId,date:o},r);try{VS(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 YS(c,t,i),0}var JS=500;function ZS(t){try{let e=Kx(t,"r");try{return Wx(e).size}finally{qx(e)}}catch{return 0}}async function YS(t,e,r){let i=ZS(t),o="",c=!1,d=()=>{c=!0};process.on("SIGINT",d);try{for(;!c;){let u="";try{let f=Kx(t,"r");try{let x=Wx(f).size;if(x>i){let g=Buffer.allocUnsafe(x-i),w=zS(f,g,0,g.length,i);u=g.subarray(0,w).toString("utf8"),i+=w}}finally{qx(f)}}catch{}if(u){let f=(o+u).split(`
120
+ `);o=f.pop()??"";for(let x of f)x.length>0&&Vx(x,{level:e.level,grep:e.grep})&&process.stdout.write(`${Jx(x,{raw:e.raw,color:r})}
121
+ `)}await new Promise(f=>setTimeout(f,JS))}}finally{process.off("SIGINT",d)}}import{basename as XS,resolve as QS}from"node:path";Fe();var e1=9e4,t1={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 n1(t){return t1[t]??1}async function Yx(t,e={}){let r=e.paths??ne();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 ia(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:QS(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 r1(i,"/agent/send",o,e1)}catch(d){return process.stderr.write(`Error: daemon IPC failed: ${d instanceof Error?d.message:String(d)}
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
+ `),n1(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
127
+ `);else{let d=t.name??XS(o.path);if(t.groupFile){let u=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${d} (uri=${u})
128
+ `)}else process.stdout.write(`Sent ${t.kind} ${d} (${i1(c.bytes)})
129
+ `)}return 0}async function r1(t,e,r,i){let o=new AbortController,c=setTimeout(()=>o.abort(),i);try{let d=await fetch(`http://127.0.0.1:${t.port}${e}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"content-type":"application/json"},body:JSON.stringify(r),signal:o.signal}),u=await d.text(),f=u?JSON.parse(u):null;return f&&typeof f=="object"&&"ok"in f?f:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${d.status}): ${u.slice(0,200)}`}}finally{clearTimeout(c)}}function i1(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var op=G("cli");function $e(t,e){let{value:r,rest:i}=On(t,e);return{value:r,rest:i}}function fa(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
130
+ `)}function R1(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}=$e(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 k1(e.slice(1));if(e[0]==="log")return{mode:"log",...$x(e.slice(1))};if(e[0]==="connect")return C1(e.slice(1));if(e.includes("--status"))return fa("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return fa("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return fa("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return fa("--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}=$e(r,"--pat-token");r=o;let{value:c,rest:d}=$e(r,"--pair-code");r=d;let{value:u,rest:f}=$e(r,"--env");r=f;let{value:x,rest:g}=$e(r,"--handshake-url");r=g;let{value:w,rest:S}=$e(r,"--frontier-url");r=S;let{value:_,rest:b}=$e(r,"--mock-scenario");r=b;let{value:I}=$e(r,"--agent-id"),T=r.includes("--skip-rebuild-env");if(!i||!c)return{mode:"help"};let k={mode:"pair",privatecode:i,pairingCode:c};return u&&(k.env=u),x&&(k.handshakeUrl=x),w&&(k.frontierUrl=w),_&&(k.mockScenario=_),I&&(k.agentId=I),T&&(k.skipRebuildEnv=!0),k}function k1(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}=$e(i,"--caption");i=c;let{value:d,rest:u}=$e(i,"--name");i=u;let{value:f,rest:x}=$e(i,"--agent-id");i=x;let{value:g,rest:w}=$e(i,"--session-id");i=w;let{value:S,rest:_}=$e(i,"--mime");i=_;let b=i.includes("--group-file");i=i.filter(k=>k!=="--group-file");let I=i.includes("--json"),T={mode:"send",kind:e,path:r,json:I};return o&&(T.caption=o),d&&(T.name=d),f&&(T.agentId=f),g&&(T.sessionId=g),b&&(T.groupFile=!0),S&&(T.mimeType=S),T}function C1(t){let e=t,{value:r,rest:i}=$e(e,"--pat-token");e=i;let{value:o,rest:c}=$e(e,"--env");e=c;let{value:d,rest:u}=$e(e,"--handshake-url");e=u;let{value:f,rest:x}=$e(e,"--frontier-url");e=x;let{value:g,rest:w}=$e(e,"--mock-scenario");e=w;let S=e.includes("--skip-rebuild-env"),_={mode:"connect"};return r&&(_.privatecode=r),o&&(_.env=o),d&&(_.handshakeUrl=d),f&&(_.frontierUrl=f),g&&(_.mockScenario=g),S&&(_.skipRebuildEnv=!0),_}var D1=`
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 ap(t=process.argv,e={}){let r=R1(t);switch(r.mode){case"help":return process.stdout.write(D1),0;case"version":return process.stdout.write(`${Bt}
212
+ `),0;case"daemon":{try{await Lx()}catch(i){return op.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return P1(e);case"stop":return dp(e);case"reload":return N1(r.agentId,e);case"log":return Zx(r,e);case"update":return O1(e);case"purge":return M1(e);case"service-install":return B1(e);case"service-uninstall":return F1(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),z1(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),U1(r.privatecode,e,i,r.skipRebuildEnv)}case"send":return Yx({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 cp(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 P1(t){let e=t.paths??ne(),r=new rn(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 cp(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 dp(t){let e=t.paths??ne(),r=new rn(e),i=t.daemonSweep??(async()=>{let f=f0();return await h0(f),f}),o=async()=>{t.skipProcessKill||await i(e)},c=await as(t),d=!1;if(c)try{await c.uninstall(),d=!0}catch(f){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(f)}
217
+ `)}let u=await r.probe();if(u.kind==="not-running")return await o(),process.stdout.write(d?`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(u.kind==="stale")return await cp(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
- `),0}catch(x){return(await r.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
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)
221
+ `),0}catch(f){return(await r.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
222
+ `),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(f)}
223
+ `),1)}}async function O1(t){return await dp(t),(t.spawnNpx??L1)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function L1(t){return new Promise(e=>{let r=at("npx",t,{stdio:"inherit"});r.on("exit",i=>e(i??1)),r.on("error",i=>{process.stderr.write(`coze-bridge: spawn npx failed: ${String(i)}
224
+ `),e(1)})})}async function N1(t,e){let r=new rn(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 as(t){if(t.supervisor){let c=t.supervisor,d={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:u=>c.install(d,u),uninstall:()=>c.uninstall(d)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>(ip(),rp)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function lp(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??Px,o=t.waitTimeoutMs??15e3,c=t.sleep??H1,d=t.paths??ne(),u=await as(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let f=await sp(e,o,c);if(f.kind==="connected")return f;Ct(d.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:o})}catch(f){Ct(d.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(f)})}Ct(d.bridgeLogsDir,"warn","cli","\u79FB\u9664\u5F00\u673A\u81EA\u542F\u914D\u7F6E (supervisor \u63A5\u7BA1\u672A\u6210\u529F, \u56DE\u9000\u624B\u52A8 spawn; \u4E0B\u6B21\u91CD\u542F\u4E0D\u518D\u81EA\u542F, \u9700\u91CD\u65B0 service install)",{platform:u.platform}),await u.uninstall().catch(()=>{}),await G1(d.pidFile,c)}else u&&await u.install({activate:!1}).catch(f=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(f)}
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}),sp(e,o,c)}async function M1(t){let e=new rn(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(d){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(d)}
233
+ `)}await new Promise(d=>setTimeout(d,500))}let i=await as(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
234
+ `)}catch(d){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(d)}
235
+ `)}let o=t.paths??ne(),{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(d){return process.stderr.write(`coze-bridge: remove failed: ${String(d)}
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 B1(t){let e=await as(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 F1(t){let e=await as(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 up(t,e,r){if(e)return Ct(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await r();return i.kind==="ok"?(Ct(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(Ct(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
+ `),Ct(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function z1(t,e,r,i={},o,c){let d=new rn(r.paths),u=r.paths??ne(),f=await up(u,c,r.reconstructEnv??Fd);if(await Qc(u,f).catch(w=>Ct(u.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(w)})),!r.skipDistInstall){let w=await jd({paths:r.paths});w.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${w.fromVersion} \u2192 ${w.toVersion}
245
+ `),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(_=>setTimeout(_,500)))):w.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${w.libVersion}
246
+ `)}let x=await lp(r,d);if(x.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${x.kind}
247
+ `),1;let g={privatecode:t,pairing_code:e};i.env&&(g.env=i.env),i.handshakeUrl&&(g.handshake_url=i.handshakeUrl),i.frontierUrl&&(g.frontier_url=i.frontierUrl),i.mockScenario&&(g.mock_scenario=i.mockScenario),o&&(g.agent_id=o);try{let w=await d.request({method:"POST",path:"/pair",body:g,timeoutMs:35e3});if(w.status===200&&w.body?.ok){let S=w.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
- `),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(_.body)}
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
249
+ `),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(w.body)}
250
+ `),1}catch(w){return process.stderr.write(`coze-bridge: pair failed: ${String(w)}
251
+ `),1}}async function U1(t,e,r={},i){let o=e.paths??ne(),c=t??await Yo(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 d=new rn(e.paths),u=await up(o,i,e.reconstructEnv??Fd);if(await Qc(o,u).catch(g=>Ct(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(g)})),!e.skipDistInstall){let g=await jd({paths:e.paths});g.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${g.fromVersion} \u2192 ${g.toVersion}
252
+ `),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(S=>setTimeout(S,500)))):g.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${g.libVersion}
253
+ `)}let f=await lp(e,d);if(f.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${f.kind}
254
+ `),1;let x={privatecode:c};r.env&&(x.env=r.env),r.handshakeUrl&&(x.handshake_url=r.handshakeUrl),r.frontierUrl&&(x.frontier_url=r.frontierUrl),r.mockScenario&&(x.mock_scenario=r.mockScenario);try{let g=await d.request({method:"POST",path:"/connect",body:x,timeoutMs:35e3});return g.status===200&&g.body?.ok?(process.stdout.write(`coze-bridge: connected (${g.body.note??"ok"})
255
+ `),t!==void 0&&await rs(c,o).catch(w=>op.warn("writePatToken after connect failed (ignored)",{err:String(w)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(g.body)}
256
+ `),1)}catch(g){return process.stderr.write(`coze-bridge: connect failed: ${String(g)}
257
+ `),1}}async function sp(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 G1(t,e,r=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let c=0;c<r;c++){let d;try{d=await o(t,"utf8")}catch{return}let u=Number.parseInt(d.trim(),10);if(!Number.isFinite(u)||u<=0||!Gi(u))return;await e(i)}}function H1(t){return new Promise(e=>setTimeout(e,t))}se();function j1(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 fp(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=j1(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
+ `)}fp();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&pl("warn");ap(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)});