coze-bridge 0.2.2-alpha.2 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +94 -96
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5,34 +5,34 @@ import { dirname as __coze_dirname } from 'node:path';
5
5
  const require = __coze_createRequire(import.meta.url);
6
6
  const __filename = __coze_fileURLToPath(import.meta.url);
7
7
  const __dirname = __coze_dirname(__filename);
8
- var Lg=Object.create;var Da=Object.defineProperty;var Ng=Object.getOwnPropertyDescriptor;var Mg=Object.getOwnPropertyNames;var Bg=Object.getPrototypeOf,Fg=Object.prototype.hasOwnProperty;var he=(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 nt=(t,e)=>()=>(t&&(e=t(t=0)),e);var de=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Pa=(t,e)=>{for(var r in e)Da(t,r,{get:e[r],enumerable:!0})},zg=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Mg(e))!Fg.call(t,o)&&o!==r&&Da(t,o,{get:()=>e[o],enumerable:!(i=Ng(e,o))||i.enumerable});return t};var Gt=(t,e,r)=>(r=t!=null?Lg(Bg(t)):{},zg(e||!t||!t.__esModule?Da(r,"default",{value:t,enumerable:!0}):r,t));function Ze(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var dr=nt(()=>{"use strict"});import{createWriteStream as Ug,mkdirSync as Hg,readdirSync as Gg,unlinkSync as qg}from"node:fs";import{join as Rl}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 lr(t,e){return`${t}-${e}.log`}function Oa(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function jg(t,e,r){let i=c=>{let[d,u,x]=c.split("-").map(Number);return Date.UTC(d??0,(u??1)-1,x??1)};return Math.floor((i(e)-i(t))/864e5)>r}function xs(t,e,r,i){let o;try{o=Gg(t)}catch{return}for(let c of o){let d=Oa(c,e);if(d&&jg(d,r,i))try{qg(Rl(t,c))}catch{}}}var ii,La=nt(()=>{"use strict";ii=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{Hg(this.dir,{recursive:!0});let r=Ug(Rl(this.dir,lr(this.prefix,e)),{flags:"a"});r.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
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&&xs(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 Wg,mkdirSync as Kg}from"node:fs";import{join as $g}from"node:path";function Pl(t){let e=t.retentionDays??Zg,r=t.clock??(()=>Nn(new Date));ps={bridgeSink:new ii(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new ii(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();xs(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])xs(t.agentLogsDir(o),"agent",i,e)}function Xg(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function Ol(t){Na=t}function Ll(t){return ur[Na]<=ur[t]}function Nl(t,e){let r=ur[t];return r===void 0?!0:r>=ur[e]}function gs(t){Dl={...t}}function Ml(t){let e=(u,x=2)=>String(u).padStart(x,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),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 ut(t,e,r,i,o){try{let c=`${JSON.stringify({ts:Ml(new Date),level:e,module:r,msg:i,...o})}
11
- `;Kg(t,{recursive:!0}),Wg($g(t,lr("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 hs(t,e,r,i,o){if(ur[t]<ur[Na])return;let c=`${JSON.stringify({ts:Ml(new Date),level:t,module:e,msg:r,...Dl,...i})}
12
- `;if(ps){let d=Yg(o,i),u=d?Xg(ps,d):ps.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?Jg.write(c):Vg.write(c)}function j(t,e){return{debug:(r,i)=>hs("debug",t,r,i,e),info:(r,i)=>hs("info",t,r,i,e),warn:(r,i)=>hs("warn",t,r,i,e),error:(r,i)=>hs("error",t,r,i,e),child:r=>j(`${t}.${r}`,e),forAgent:r=>j(t,r)}}var ur,Na,Vg,Jg,Dl,Zg,ps,ie=nt(()=>{"use strict";dr();La();ur={debug:10,info:20,warn:30,error:40},Na=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),Vg=process.stdout,Jg=process.stderr,Dl={},Zg=Ze("COZE_BRIDGE_LOG_RETENTION_DAYS",30),ps=null});var T,$e=nt(()=>{"use strict";T=class extends Error{code;retriable;cause;constructor(e,r,i){super(r),this.name="BridgeError",this.code=e,this.retriable=i?.retriable??!1,i?.cause!==void 0&&(this.cause=i.cause)}}});var Ul={};Pa(Ul,{ACP_WRAPPER_NPM_PACKAGES:()=>ws,_resetAcpInstallerForTests:()=>im,_setBinaryPathCacheForTests:()=>sm,buildAcpSpawn:()=>si,ensureAcpInstalled:()=>xr,getAcpBinaryPath:()=>_s,pickWhichLine:()=>Fa,probeAcpVersion:()=>rm,resolveAcpCommand:()=>zl});import{readFileSync as Bl}from"node:fs";import{createRequire as Qg}from"node:module";import{dirname as em,resolve as tm}from"node:path";function Ba(t){if(t!=="codex")return;let e=process.env.COZE_BRIDGE_CODEX_ACP_BIN?.trim();return e||void 0}function Fa(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 nm(t){let e=Fl.resolve(`${t.npmPackage}/package.json`),r=em(e),i=JSON.parse(Bl(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 tm(r,o)}async function xr(t,e){let r=Ma[t];if(!r)throw new T("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=fr.get(t);if(i)return i;let o=Ba(t);if(o)return fr.set(t,o),ms.info("acp wrapper overridden by env",{framework:t,path:o}),o;try{let c=nm(r);return fr.set(t,c),ms.info("acp wrapper resolved",{framework:t,binary:r.binary,path:c}),c}catch(c){throw ms.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:r.npmPackage,err:String(c)}),new T("AGENT_DEPENDENCY_INSTALL_FAILED",[`ACP wrapper \u672A\u5C31\u7EEA: ${r.npmPackage} (framework=${t})`,"\u8BE5 wrapper \u968F coze-bridge \u4E00\u8D77\u5B89\u88C5 (\u56FA\u5316\u5230 ~/.coze/bridge/lib/node_modules)\u3002","\u8BF7\u91CD\u8DD1 `coze-bridge pair` / `connect` \u89E6\u53D1\u56FA\u5316\u5B89\u88C5; \u82E5\u4ECD\u5931\u8D25, \u68C0\u67E5\u7F51\u7EDC / npm \u7F13\u5B58\u3002"].join(`
13
- `),{cause:c})}}async function rm(t){let e=Ma[t];if(e)try{let r=Fl.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(Bl(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){ms.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function _s(t){return fr.get(t)}function zl(t,e){if(e)return e;let r=Ba(t);if(r)return r;let i=_s(t);if(!i)throw new T("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return i}function si(t,e,r){if(e)return{command:e,args:[...r]};let i=Ba(t);if(i)return{command:i,args:[...r]};let o=zl(t);return{command:process.execPath,args:[o,...r]}}function im(){fr.clear()}function sm(t,e){fr.set(t,e)}var ms,Ma,ws,Fl,fr,an=nt(()=>{"use strict";$e();ie();ms=j("agents.acp-installer"),Ma={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},ws=Object.values(Ma).filter(t=>t!==void 0).map(t=>t.npmPackage),Fl=Qg(import.meta.url),fr=new Map});import{chmod as am,mkdir as cm,readFile as dm,rename as lm,rm as um,writeFile as fm}from"node:fs/promises";import{dirname as xm}from"node:path";async function cn(t){try{let e=await dm(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function dn(t,e,r){await cm(xm(t),{recursive:!0});let i=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{await fm(i,e,{encoding:"utf8",mode:r?.mode}),await lm(i,t),r?.mode!==void 0&&await am(t,r.mode)}catch(o){throw await um(i,{force:!0}).catch(()=>{}),o}}async function ln(t,e,r){await dn(t,`${JSON.stringify(e,null,2)}
14
- `,r)}var un=nt(()=>{"use strict"});import{promises as ql,readdirSync as hm}from"node:fs";import{homedir as pm}from"node:os";import{sep as gm,join as De,resolve as jl}from"node:path";function Y(t){let e=t??pm(),r=De(e,".coze"),i=De(r,"bridge"),o=De(i,"lib"),c=De(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:De(o,"index.js"),binDir:De(i,"bin"),pidFile:De(i,"bridge.pid"),portFile:De(i,"bridge.port"),tokenFile:De(i,"bridge.token"),patTokenFile:De(i,"pat-token"),agentEnvFile:De(i,"agent-env.json"),logFile:De(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:De(c,"daemon-stdio.log"),installLock:De(i,"install.lock"),configFile:De(i,"config.json"),agentsRoot:De(r,"agents")}}function Ve(t,e=Y()){let r=De(e.agentsRoot,t);return{root:r,config:De(r,"config.json"),workspace:De(r,"workspace"),logs:De(r,"logs")}}function ys(t=Y()){try{return hm(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function oi(t,e){let r=await ql.realpath(jl(t)).catch(()=>null);if(!r)return!1;let i=await ql.realpath(jl(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+gm)}var Pe=nt(()=>{"use strict"});var Es={};Pa(Es,{AGENT_CONFIG_FILE_MODE:()=>bs,enforceAgentConfigMode:()=>_m,loadAgentConfig:()=>Oe,persistAgentSessions:()=>ai,persistAgentSkills:()=>ci,saveAgentConfig:()=>Ue});import{chmod as mm,stat as wm}from"node:fs/promises";function Oe(t,e){return cn(Ve(t,e).config)}function Ue(t,e){return ln(Ve(t.agentId,e).config,t,{mode:bs})}async function _m(t,e){if(process.platform==="win32")return;let r=Ve(t,e).config;try{let i=await wm(r);if(!i.isFile())return;let o=i.mode&511;o!==bs&&(await mm(r,bs),Wl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Wl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function ai(t,e,r){let i=await Oe(t,r);i&&(i.sessions=Object.fromEntries(e),await Ue(i,r))}async function ci(t,e,r){let i=await Oe(t,r);i&&(i.skills=e,await Ue(i,r))}var Wl,bs,fn=nt(()=>{"use strict";un();ie();Pe();Wl=j("agent-config"),bs=384});var Ha=de((kA,Vl)=>{Vl.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 Ss=de(Zl=>{var Jl={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 Am(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(Jl))Zl[t]=Am(Jl[t])});var tu=de((CA,eu)=>{var Im=he("fs"),Fe=he("path"),Xl=Ha(),km=Ss(),Tm=typeof process=="object"&&process.platform==="win32",Yl=t=>typeof t=="object"&&t!==null,Ql=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 Ie(t){this.sep=Fe.sep,this.fs=Im,Yl(t)&&Yl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}eu.exports=Ie;Ie.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 km.FILE_IN_THE_WAY(`"${o}"`)}})}r(t)};Ie.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=Fe.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};Ie.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,x){if(d&&x.isDirectory())return o(!1);var h=Fe.dirname(t);c.fs.exists(h,function(p){p||c.makeDir(h),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)})})})})})};Ie.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 x=Fe.join(i,u),h=e.fs.statSync(x);(!o||o.test(x))&&d.push(Fe.normalize(x)+(h.isDirectory()?e.sep:"")),h.isDirectory()&&c&&(d=d.concat(r(x,o,c)))}),d}return r(t,void 0,!0)};Ie.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=Fe.join(t,u),r.fs.stat(u,function(x,h){if(x)return e(x);h&&(i.push(Fe.normalize(u)+(h.isDirectory()?r.sep:"")),h.isDirectory()?r.findFilesAsync(u,function(p,_){if(p)return e(p);i=i.concat(_),--d||e(null,i)}):--d||e(null,i))})})})};Ie.prototype.getAttributes=function(){};Ie.prototype.setAttributes=function(){};Ie.crc32update=function(t,e){return Ql[(t^e)&255]^t>>>8};Ie.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,r=-1;for(let i=0;i<e;)r=Ie.crc32update(r,t[i++]);return~r>>>0};Ie.methodToString=function(t){switch(t){case Xl.STORED:return"STORED ("+t+")";case Xl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Ie.canonical=function(t){if(!t)return"";let e=Fe.posix.normalize("/"+t.split("\\").join("/"));return Fe.join(".",e)};Ie.zipnamefix=function(t){if(!t)return"";let e=Fe.posix.normalize("/"+t.split("\\").join("/"));return Fe.posix.join(".",e)};Ie.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]};Ie.sanitize=function(t,e){t=Fe.resolve(Fe.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Fe.normalize(Fe.join(t,r.slice(i,o).join(Fe.sep)));if(c.indexOf(t)===0)return c}return Fe.normalize(Fe.join(t,Fe.basename(e)))};Ie.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};Ie.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};Ie.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)};Ie.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};Ie.isWin=Tm;Ie.crcTable=Ql});var ru=de((RA,nu)=>{var Cm=he("path");nu.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=Cm.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 su=de((DA,iu)=>{iu.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var gr=de((PA,pr)=>{pr.exports=tu();pr.exports.Constants=Ha();pr.exports.Errors=Ss();pr.exports.FileAttr=ru();pr.exports.decoder=su()});var au=de((OA,ou)=>{var xn=gr(),H=xn.Constants;ou.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,d=0,u=0,x=0,h=0,p=0,_=0,S=0,y=0,v=0;t|=xn.isWin?2560:768,r|=H.FLG_EFS;let A={extraLen:0},k=E=>Math.max(0,E)>>>0,R=E=>Math.max(0,E)&65535,O=E=>Math.max(0,E)&255;return o=xn.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&H.FLG_EFS)>0},set flags_efs(E){E?r|=H.FLG_EFS:r&=~H.FLG_EFS},get flags_desc(){return(r&H.FLG_DESC)>0},set flags_desc(E){E?r|=H.FLG_DESC:r&=~H.FLG_DESC},get method(){return i},set method(E){switch(E){case H.STORED:this.version=10;case H.DEFLATED:default:this.version=20}i=E},get time(){return xn.fromDOS2Date(this.timeval)},set time(E){E=new Date(E),this.timeval=xn.fromDate2DOS(E)},get timeval(){return o},set timeval(E){o=k(E)},get timeHighByte(){return O(o>>>8)},get crc(){return c},set crc(E){c=k(E)},get compressedSize(){return d},set compressedSize(E){d=k(E)},get size(){return u},set size(E){u=k(E)},get fileNameLength(){return x},set fileNameLength(E){x=E},get extraLength(){return h},set extraLength(E){h=E},get extraLocalLength(){return A.extraLen},set extraLocalLength(E){A.extraLen=E},get commentLength(){return p},set commentLength(E){p=E},get diskNumStart(){return _},set diskNumStart(E){_=k(E)},get inAttr(){return S},set inAttr(E){S=k(E)},get attr(){return y},set attr(E){y=k(E)},get fileAttr(){return(y||0)>>16&4095},get offset(){return v},set offset(E){v=k(E)},get encrypted(){return(r&H.FLG_ENC)===H.FLG_ENC},get centralHeaderSize(){return H.CENHDR+x+h+p},get realDataOffset(){return v+H.LOCHDR+A.fnameLen+A.extraLen},get localHeader(){return A},loadLocalHeaderFromBinary:function(E){var D=E.slice(v,v+H.LOCHDR);if(D.readUInt32LE(0)!==H.LOCSIG)throw xn.Errors.INVALID_LOC();A.version=D.readUInt16LE(H.LOCVER),A.flags=D.readUInt16LE(H.LOCFLG),A.flags_desc=(A.flags&H.FLG_DESC)>0,A.method=D.readUInt16LE(H.LOCHOW),A.time=D.readUInt32LE(H.LOCTIM),A.crc=D.readUInt32LE(H.LOCCRC),A.compressedSize=D.readUInt32LE(H.LOCSIZ),A.size=D.readUInt32LE(H.LOCLEN),A.fnameLen=D.readUInt16LE(H.LOCNAM),A.extraLen=D.readUInt16LE(H.LOCEXT);let L=v+H.LOCHDR+A.fnameLen,z=L+A.extraLen;return E.slice(L,z)},loadFromBinary:function(E){if(E.length!==H.CENHDR||E.readUInt32LE(0)!==H.CENSIG)throw xn.Errors.INVALID_CEN();t=E.readUInt16LE(H.CENVEM),e=E.readUInt16LE(H.CENVER),r=E.readUInt16LE(H.CENFLG),i=E.readUInt16LE(H.CENHOW),o=E.readUInt32LE(H.CENTIM),c=E.readUInt32LE(H.CENCRC),d=E.readUInt32LE(H.CENSIZ),u=E.readUInt32LE(H.CENLEN),x=E.readUInt16LE(H.CENNAM),h=E.readUInt16LE(H.CENEXT),p=E.readUInt16LE(H.CENCOM),_=E.readUInt16LE(H.CENDSK),S=E.readUInt16LE(H.CENATT),y=E.readUInt32LE(H.CENATX),v=E.readUInt32LE(H.CENOFF)},localHeaderToBinary:function(){var E=Buffer.alloc(H.LOCHDR);return E.writeUInt32LE(H.LOCSIG,0),E.writeUInt16LE(e,H.LOCVER),E.writeUInt16LE(r,H.LOCFLG),E.writeUInt16LE(i,H.LOCHOW),E.writeUInt32LE(o,H.LOCTIM),E.writeUInt32LE(c,H.LOCCRC),E.writeUInt32LE(d,H.LOCSIZ),E.writeUInt32LE(u,H.LOCLEN),E.writeUInt16LE(x,H.LOCNAM),E.writeUInt16LE(A.extraLen,H.LOCEXT),E},centralHeaderToBinary:function(){var E=Buffer.alloc(H.CENHDR+x+h+p);return E.writeUInt32LE(H.CENSIG,0),E.writeUInt16LE(t,H.CENVEM),E.writeUInt16LE(e,H.CENVER),E.writeUInt16LE(r,H.CENFLG),E.writeUInt16LE(i,H.CENHOW),E.writeUInt32LE(o,H.CENTIM),E.writeUInt32LE(c,H.CENCRC),E.writeUInt32LE(d,H.CENSIZ),E.writeUInt32LE(u,H.CENLEN),E.writeUInt16LE(x,H.CENNAM),E.writeUInt16LE(h,H.CENEXT),E.writeUInt16LE(p,H.CENCOM),E.writeUInt16LE(_,H.CENDSK),E.writeUInt16LE(S,H.CENATT),E.writeUInt32LE(y,H.CENATX),E.writeUInt32LE(v,H.CENOFF),E},toJSON:function(){let E=function(D){return D+" bytes"};return{made:t,version:e,flags:r,method:xn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:E(d),size:E(u),fileNameLength:E(x),extraLength:E(h),commentLength:E(p),diskNumStart:_,inAttr:S,attr:y,offset:v,centralHeaderSize:E(H.CENHDR+x+h+p)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var du=de((LA,cu)=>{var mr=gr(),ve=mr.Constants;cu.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 mr.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=mr.readBigUInt64LE(c,ve.ZIP64SUB),e=mr.readBigUInt64LE(c,ve.ZIP64TOT),r=mr.readBigUInt64LE(c,ve.ZIP64SIZE),i=mr.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 x=d.toString(16).toUpperCase();for(;x.length<u;)x="0"+x;return"0x"+x};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var qa=de(Ga=>{Ga.EntryHeader=au();Ga.MainHeader=du()});var uu=de((MA,lu)=>{lu.exports=function(t){var e=he("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),x=0;u.fill(0);for(var h=0;h<c.length;h++){var p=c[h];p.copy(u,x),x+=p.length}i&&i(u)}),o.end(t)}}}});var xu=de((BA,fu)=>{var Rm=+(process.versions?process.versions.node:"").split(".")[0]||0;fu.exports=function(t,e){var r=he("zlib");let i=Rm>=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(x){d.push(x),u+=x.length}),c.on("end",function(){var x=Buffer.alloc(u),h=0;x.fill(0);for(var p=0;p<d.length;p++){var _=d[p];_.copy(x,h),h+=_.length}o&&o(x)}),c.end(t)}}}});var wu=de((FA,mu)=>{"use strict";var{randomFillSync:hu}=he("crypto"),Dm=Ss(),Pm=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}),gu=(t,e)=>Math.imul(t,e)>>>0,pu=(t,e)=>Pm[(t^e)&255]^t>>>8,di=()=>typeof hu=="function"?hu(Buffer.alloc(12)):di.node();di.node=()=>{let t=Buffer.alloc(12),e=t.length;for(let r=0;r<e;r++)t[r]=Math.random()*256&255;return t};var As={genSalt:di};function Is(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])}Is.prototype.updateKeys=function(t){let e=this.keys;return e[0]=pu(e[0],t),e[1]+=e[0]&255,e[1]=gu(e[1],134775813)+1,e[2]=pu(e[2],e[1]>>>24),t};Is.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return gu(t,t^1)>>8&255};function Om(t){let e=new Is(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 Lm(t){let e=new Is(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 Nm(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Om(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Dm.WRONG_PASSWORD();return i(t.slice(12))}function Mm(t){Buffer.isBuffer(t)&&t.length>=12?As.genSalt=function(){return t.slice(0,12)}:t==="node"?As.genSalt=di.node:As.genSalt=di}function Bm(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Lm(r),c=As.genSalt();c[11]=e.crc>>>24&255,i&&(c[10]=e.crc>>>16&255);let d=Buffer.alloc(t.length+12);return o(c,d),o(t,d,12)}mu.exports={decrypt:Nm,encrypt:Bm,_salter:Mm}});var _u=de(ks=>{ks.Deflater=uu();ks.Inflater=xu();ks.ZipCrypto=wu()});var Wa=de((UA,yu)=>{var le=gr(),Fm=qa(),ke=le.Constants,ja=_u();yu.exports=function(t,e){var r=new Fm.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,d=null,u=Buffer.alloc(0),x=Buffer.alloc(0),h=!0;let p=t,_=typeof p.decoder=="object"?p.decoder:le.decoder;h=_.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(le.crc32(E)!==r.localHeader.crc)return!1}else{let D={},L=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(L)==ke.LOCSIG||e.readUInt32LE(L)==ke.CENSIG)throw le.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(L)==ke.EXTSIG)D.crc=e.readUInt32LE(L+ke.EXTCRC),D.compressedSize=e.readUInt32LE(L+ke.EXTSIZ),D.size=e.readUInt32LE(L+ke.EXTLEN);else if(e.readUInt16LE(L+12)===19280)D.crc=e.readUInt32LE(L+ke.EXTCRC-4),D.compressedSize=e.readUInt32LE(L+ke.EXTSIZ-4),D.size=e.readUInt32LE(L+ke.EXTLEN-4);else throw le.Errors.DESCRIPTOR_UNKNOWN();if(D.compressedSize!==r.compressedSize||D.size!==r.size||D.crc!==r.crc)throw le.Errors.DESCRIPTOR_FAULTY();if(le.crc32(E)!==D.crc)return!1}return!0}function v(E,D,L){if(typeof D>"u"&&typeof E=="string"&&(L=E,E=void 0),c)return E&&D&&D(Buffer.alloc(0),le.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var z=S();if(z.length===0)return E&&D&&D(z),z;if(r.encrypted){if(typeof L!="string"&&!Buffer.isBuffer(L))throw le.Errors.INVALID_PASS_PARAM();z=ja.ZipCrypto.decrypt(z,r,L)}var B=Buffer.alloc(r.size);switch(r.method){case le.Constants.STORED:if(z.copy(B),y(B))return E&&D&&D(B),B;throw E&&D&&D(B,le.Errors.BAD_CRC()),le.Errors.BAD_CRC();case le.Constants.DEFLATED:var X=new ja.Inflater(z,r.size);if(E)X.inflateAsync(function(Z){Z.copy(Z,0),D&&(y(Z)?D(Z):D(Z,le.Errors.BAD_CRC()))});else{if(X.inflate(B).copy(B,0),!y(B))throw le.Errors.BAD_CRC(`"${_.decode(i)}"`);return B}break;default:throw E&&D&&D(Buffer.alloc(0),le.Errors.UNKNOWN_METHOD()),le.Errors.UNKNOWN_METHOD()}}function A(E,D){if((!d||!d.length)&&Buffer.isBuffer(e))return E&&D&&D(S()),S();if(d.length&&!c){var L;switch(r.method){case le.Constants.STORED:return r.compressedSize=r.size,L=Buffer.alloc(d.length),d.copy(L),E&&D&&D(L),L;default:case le.Constants.DEFLATED:var z=new ja.Deflater(d);if(E)z.deflateAsync(function(X){L=Buffer.alloc(X.length),r.compressedSize=X.length,X.copy(L),D&&D(L)});else{var B=z.deflate();return r.compressedSize=B.length,B}z=null;break}}else if(E&&D)D(Buffer.alloc(0));else return Buffer.alloc(0)}function k(E,D){return le.readBigUInt64LE(E,D)}function R(E){try{for(var D=0,L,z,B;D+4<E.length;)L=E.readUInt16LE(D),D+=2,z=E.readUInt16LE(D),D+=2,B=E.slice(D,D+z),D+=z,ke.ID_ZIP64===L&&O(B)}catch{throw le.Errors.EXTRA_FIELD_PARSE_ERROR()}}function O(E){var D,L,z,B;E.length>=ke.EF_ZIP64_SCOMP&&(D=k(E,ke.EF_ZIP64_SUNCOMP),r.size===ke.EF_ZIP64_OR_32&&(r.size=D)),E.length>=ke.EF_ZIP64_RHO&&(L=k(E,ke.EF_ZIP64_SCOMP),r.compressedSize===ke.EF_ZIP64_OR_32&&(r.compressedSize=L)),E.length>=ke.EF_ZIP64_DSN&&(z=k(E,ke.EF_ZIP64_RHO),r.offset===ke.EF_ZIP64_OR_32&&(r.offset=z)),E.length>=ke.EF_ZIP64_DSN+4&&(B=E.readUInt32LE(ke.EF_ZIP64_DSN),r.diskNumStart===ke.EF_ZIP64_OR_16&&(r.diskNumStart=B))}return{get entryName(){return _.decode(i)},get rawEntryName(){return i},set entryName(E){i=le.toBuffer(E,_.encode);var D=i[i.length-1];c=D===47||D===92,r.fileNameLength=i.length},get efs(){return typeof h=="function"?h(this.entryName):h},get extra(){return u},set extra(E){u=E,r.extraLength=E.length,R(E)},get comment(){return _.decode(o)},set comment(E){if(o=le.toBuffer(E,_.encode),r.commentLength=o.length,o.length>65535)throw le.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){d=le.toBuffer(E,le.decoder.encode),!c&&d.length?(r.size=d.length,r.method=le.Constants.DEFLATED,r.crc=le.crc32(E),r.changed=!0):r.method=le.Constants.STORED},getData:function(E){return r.changed?d:v(!1,null,E)},getDataAsync:function(E,D){r.changed?E(d):v(!0,E,D)},set attr(E){r.attr=E},get attr(){return r.attr},set header(E){r.loadFromBinary(E)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=u.length;var E=r.centralHeaderToBinary(),D=le.Constants.CENHDR;return i.copy(E,D),D+=i.length,u.copy(E,D),D+=r.extraLength,o.copy(E,D),E},packLocalHeader:function(){let E=0;r.flags_efs=this.efs,r.extraLocalLength=x.length;let D=r.localHeaderToBinary(),L=Buffer.alloc(D.length+i.length+r.extraLocalLength);return D.copy(L,E),E+=D.length,i.copy(L,E),E+=i.length,x.copy(L,E),E+=x.length,L},toJSON:function(){let E=function(D){return"<"+(D&&D.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:E(e),data:E(d)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var vu=de((HA,Eu)=>{var bu=Wa(),zm=qa(),Je=gr();Eu.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new zm.MainHeader,d=!1,u=null;let x=new Set,h=e,{noSort:p,decoder:_}=h;t?v(h.readEntries):d=!0;function S(){let k=new Set;for(let R of Object.keys(i)){let O=R.split("/");if(O.pop(),!!O.length)for(let E=0;E<O.length;E++){let D=O.slice(0,E+1).join("/")+"/";k.add(D)}}for(let R of k)if(!(R in i)){let O=new bu(h);O.entryName=R,O.attr=16,O.temporary=!0,r.push(O),i[O.entryName]=O,x.add(O)}}function y(){if(d=!0,i={},c.diskEntries>(t.length-c.offset)/Je.Constants.CENHDR)throw Je.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var k=c.offset,R=0;R<r.length;R++){var O=k,E=new bu(h,t);E.header=t.slice(O,O+=Je.Constants.CENHDR),E.entryName=t.slice(O,O+=E.header.fileNameLength),E.header.extraLength&&(E.extra=t.slice(O,O+=E.header.extraLength)),E.header.commentLength&&(E.comment=t.slice(O,O+E.header.commentLength)),k+=E.header.centralHeaderSize,r[R]=E,i[E.entryName]=E}x.clear(),S()}function v(k){var R=t.length-Je.Constants.ENDHDR,O=Math.max(0,R-65535),E=O,D=t.length,L=-1,z=0;for(typeof h.trailingSpace=="boolean"&&h.trailingSpace&&(O=0),R;R>=E;R--)if(t[R]===80){if(t.readUInt32LE(R)===Je.Constants.ENDSIG){L=R,z=R,D=R+Je.Constants.ENDHDR,E=R-Je.Constants.END64HDR;continue}if(t.readUInt32LE(R)===Je.Constants.END64SIG){E=O;continue}if(t.readUInt32LE(R)===Je.Constants.ZIP64SIG){L=R,D=R+Je.readBigUInt64LE(t,R+Je.Constants.ZIP64SIZE)+Je.Constants.ZIP64LEAD;break}}if(L==-1)throw Je.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(L,D)),c.commentLength&&(o=t.slice(z+Je.Constants.ENDHDR)),k&&y()}function A(){r.length>1&&!p&&r.sort((k,R)=>k.entryName.toLowerCase().localeCompare(R.entryName.toLowerCase()))}return{get entries(){return d||y(),r.filter(k=>!x.has(k))},get comment(){return _.decode(o)},set comment(k){o=Je.toBuffer(k,_.encode),c.commentLength=o.length},getEntryCount:function(){return d?r.length:c.diskEntries},forEach:function(k){this.entries.forEach(k)},getEntry:function(k){return d||y(),i[k]||null},setEntry:function(k){d||y(),r.push(k),i[k.entryName]=k,c.totalEntries=r.length},deleteFile:function(k,R=!0){d||y();let O=i[k];this.getEntryChildren(O,R).map(D=>D.entryName).forEach(this.deleteEntry)},deleteEntry:function(k){d||y();let R=i[k],O=r.indexOf(R);O>=0&&(r.splice(O,1),delete i[k],c.totalEntries=r.length)},getEntryChildren:function(k,R=!0){if(d||y(),typeof k=="object")if(k.isDirectory&&R){let O=[],E=k.entryName;for(let D of r)D.entryName.startsWith(E)&&O.push(D);return O}else return[k];return[]},getChildCount:function(k){if(k&&k.isDirectory){let R=this.getEntryChildren(k);return R.includes(k)?R.length-1:R.length}return 0},compressToBuffer:function(){d||y(),A();let k=[],R=[],O=0,E=0;c.size=0,c.offset=0;let D=0;for(let B of this.entries){let X=B.getCompressedData();B.header.offset=E;let Z=B.packLocalHeader(),se=Z.length+X.length;E+=se,k.push(Z),k.push(X);let ee=B.packCentralHeader();R.push(ee),c.size+=ee.length,O+=se+ee.length,D++}O+=c.mainHeaderSize,c.offset=E,c.totalEntries=D,E=0;let L=Buffer.alloc(O);for(let B of k)B.copy(L,E),E+=B.length;for(let B of R)B.copy(L,E),E+=B.length;let z=c.toBinary();return o&&o.copy(z,Je.Constants.ENDHDR),z.copy(L,E),t=L,d=!1,L},toAsyncBuffer:function(k,R,O,E){try{d||y(),A();let D=[],L=[],z=0,B=0,X=0;c.size=0,c.offset=0;let Z=function(se){if(se.length>0){let ee=se.shift(),ae=ee.entryName+ee.extra.toString();O&&O(ae),ee.getCompressedDataAsync(function(ce){E&&E(ae),ee.header.offset=B;let P=ee.packLocalHeader(),q=P.length+ce.length;B+=q,D.push(P),D.push(ce);let $=ee.packCentralHeader();L.push($),c.size+=$.length,z+=q+$.length,X++,Z(se)})}else{z+=c.mainHeaderSize,c.offset=B,c.totalEntries=X,B=0;let ee=Buffer.alloc(z);D.forEach(function(ce){ce.copy(ee,B),B+=ce.length}),L.forEach(function(ce){ce.copy(ee,B),B+=ce.length});let ae=c.toBinary();o&&o.copy(ae,Je.Constants.ENDHDR),ae.copy(ee,B),t=ee,d=!1,k(ee)}};Z(Array.from(this.entries))}catch(D){R(D)}}}}});var Iu=de((GA,Au)=>{var Ae=gr(),Se=he("path"),Um=Wa(),Hm=vu(),Mn=(...t)=>Ae.findLast(t,e=>typeof e=="boolean"),Su=(...t)=>Ae.findLast(t,e=>typeof e=="string"),Gm=(...t)=>Ae.findLast(t,e=>typeof e=="function"),qm={noSort:!1,readEntries:!1,method:Ae.Constants.NONE,fs:null};Au.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),qm);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=Ae.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new Ae(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=Ae.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=Ae.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw Ae.Errors.INVALID_FILENAME();let c=new Hm(r,i),{canonical:d,sanitize:u,zipnamefix:x}=Ae;function h(y){if(y&&c){var v;if(typeof y=="string"&&(v=c.getEntry(Se.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 p(y){let{join:v,normalize:A,sep:k}=Se.posix;return v(Se.isAbsolute(y)?"/":".",A(k+y.split("\\").join(k)+k))}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:"",Se.relative(y,v)+A};return{readFile:function(y,v){var A=h(y);return A&&A.getData(v)||null},childCount:function(y){let v=h(y);if(v)return c.getChildCount(v)},readFileAsync:function(y,v){var A=h(y);A?A.getDataAsync(v):v(null,"getEntry failed for:"+y)},readAsText:function(y,v){var A=h(y);if(A){var k=A.getData();if(k&&k.length)return k.toString(v||"utf8")}return""},readAsTextAsync:function(y,v,A){var k=h(y);k?k.getDataAsync(function(R,O){if(O){v(R,O);return}R&&R.length?v(R.toString(A||"utf8")):v("")}):v("")},deleteFile:function(y,v=!0){var A=h(y);A&&c.deleteFile(A.entryName,v)},deleteEntry:function(y){var v=h(y);v&&c.deleteEntry(v.entryName)},addZipComment:function(y){c.comment=y},getZipComment:function(){return c.comment||""},addZipEntryComment:function(y,v){var A=h(y);A&&(A.comment=v)},getZipEntryComment:function(y){var v=h(y);return v&&v.comment||""},updateFile:function(y,v){var A=h(y);A&&A.setData(v)},addLocalFile:function(y,v,A,k){if(o.fs.existsSync(y)){v=v?p(v):"";let R=Se.win32.basename(Se.win32.normalize(y));v+=A||R;let O=o.fs.statSync(y),E=O.isFile()?o.fs.readFileSync(y):Buffer.alloc(0);O.isDirectory()&&(v+=o.sep),this.addFile(v,E,k,O)}else throw Ae.Errors.FILE_NOT_FOUND(y)},addLocalFileAsync:function(y,v){y=typeof y=="object"?y:{localPath:y};let A=Se.resolve(y.localPath),{comment:k}=y,{zipPath:R,zipName:O}=y,E=this;o.fs.stat(A,function(D,L){if(D)return v(D,!1);R=R?p(R):"";let z=Se.win32.basename(Se.win32.normalize(A));if(R+=O||z,L.isFile())o.fs.readFile(A,function(B,X){return B?v(B,!1):(E.addFile(R,X,k,L),setImmediate(v,void 0,!0))});else if(L.isDirectory())return R+=o.sep,E.addFile(R,Buffer.alloc(0),k,L),setImmediate(v,void 0,!0)})},addLocalFolder:function(y,v,A){if(A=_(A),v=v?p(v):"",y=Se.normalize(y),o.fs.existsSync(y)){let k=o.findFiles(y),R=this;if(k.length)for(let O of k){let E=Se.join(v,S(y,O));A(E)&&R.addLocalFile(O,Se.dirname(E))}}else throw Ae.Errors.FILE_NOT_FOUND(y)},addLocalFolderAsync:function(y,v,A,k){k=_(k),A=A?p(A):"",y=Se.normalize(y);var R=this;o.fs.open(y,"r",function(O){if(O&&O.code==="ENOENT")v(void 0,Ae.Errors.FILE_NOT_FOUND(y));else if(O)v(void 0,O);else{var E=o.findFiles(y),D=-1,L=function(){if(D+=1,D<E.length){var z=E[D],B=S(y,z).split("\\").join("/");B=B.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),k(B)?o.fs.stat(z,function(X,Z){X&&v(void 0,X),Z.isFile()?o.fs.readFile(z,function(se,ee){se?v(void 0,se):(R.addFile(A+B,ee,"",Z),L())}):(R.addFile(A+B+"/",Buffer.alloc(0),"",Z),L())}):process.nextTick(()=>{L()})}else v(!0,void 0)};L()}})},addLocalFolderAsync2:function(y,v){let A=this;y=typeof y=="object"?y:{localPath:y},localPath=Se.resolve(p(y.localPath));let{zipPath:k,filter:R,namefix:O}=y;R instanceof RegExp?R=(function(L){return function(z){return L.test(z)}})(R):typeof R!="function"&&(R=function(){return!0}),k=k?p(k):"",O=="latin1"&&(O=L=>L.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof O!="function"&&(O=L=>L);let E=L=>Se.join(k,O(S(localPath,L))),D=L=>Se.win32.basename(Se.win32.normalize(O(L)));o.fs.open(localPath,"r",function(L){L&&L.code==="ENOENT"?v(void 0,Ae.Errors.FILE_NOT_FOUND(localPath)):L?v(void 0,L):o.findFilesAsync(localPath,function(z,B){if(z)return v(z);B=B.filter(X=>R(E(X))),B.length||v(void 0,!1),setImmediate(B.reverse().reduce(function(X,Z){return function(se,ee){if(se||ee===!1)return setImmediate(X,se,!1);A.addLocalFileAsync({localPath:Z,zipPath:Se.dirname(E(Z)),zipName:D(Z)},X)}},v))})})},addLocalFolderPromise:function(y,v){return new Promise((A,k)=>{this.addLocalFolderAsync2(Object.assign({localPath:y},v),(R,O)=>{R&&k(R),O&&A(this)})})},addFile:function(y,v,A,k){y=x(y);let R=h(y),O=R!=null;O||(R=new Um(i),R.entryName=y),R.comment=A||"";let E=typeof k=="object"&&k instanceof o.fs.Stats;E&&(R.header.time=k.mtime);var D=R.isDirectory?16:0;let L=R.isDirectory?16384:32768;return E?L|=4095&k.mode:typeof k=="number"?L|=4095&k:L|=R.isDirectory?493:420,D=(D|L<<16)>>>0,R.attr=D,R.setData(v),O||c.setEntry(R),R},getEntries:function(y){return c.password=y,c?c.entries:[]},getEntry:function(y){return h(y)},getEntryCount:function(){return c.getEntryCount()},forEach:function(y){return c.forEach(y)},extractEntryTo:function(y,v,A,k,R,O){k=Mn(!1,k),R=Mn(!1,R),A=Mn(!0,A),O=Su(R,O);var E=h(y);if(!E)throw Ae.Errors.NO_ENTRY();var D=d(E.entryName),L=u(v,O&&!E.isDirectory?O:A?D:Se.basename(D));if(E.isDirectory){var z=c.getEntryChildren(E);return z.forEach(function(Z){if(Z.isDirectory)return;var se=Z.getData();if(!se)throw Ae.Errors.CANT_EXTRACT_FILE();var ee=d(Z.entryName),ae=u(v,A?ee:Se.basename(ee));let ce=R?Z.header.fileAttr:void 0;o.writeFileTo(ae,se,k,ce)}),!0}var B=E.getData(c.password);if(!B)throw Ae.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(L)&&!k)throw Ae.Errors.CANT_OVERRIDE();let X=R?y.header.fileAttr:void 0;return o.writeFileTo(L,B,k,X),!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,k){if(A=Mn(!1,A),k=Su(A,k),v=Mn(!1,v),!c)throw Ae.Errors.NO_ZIP();c.entries.forEach(function(R){var O=u(y,d(R.entryName));if(R.isDirectory){o.makeDir(O);return}var E=R.getData(k);if(!E)throw Ae.Errors.CANT_EXTRACT_FILE();let D=A?R.header.fileAttr:void 0;o.writeFileTo(O,E,v,D);try{o.fs.utimesSync(O,R.header.time,R.header.time)}catch{throw Ae.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(y,v,A,k){if(k=Gm(v,A,k),A=Mn(!1,A),v=Mn(!1,v),!k)return new Promise((L,z)=>{this.extractAllToAsync(y,v,A,function(B){B?z(B):L(this)})});if(!c){k(Ae.Errors.NO_ZIP());return}y=Se.resolve(y);let R=L=>u(y,Se.normalize(d(L.entryName))),O=(L,z)=>new Error(L+': "'+z+'"'),E=[],D=[];c.entries.forEach(L=>{L.isDirectory?E.push(L):D.push(L)});for(let L of E){let z=R(L),B=A?L.header.fileAttr:void 0;try{o.makeDir(z),B&&o.fs.chmodSync(z,B),o.fs.utimesSync(z,L.header.time,L.header.time)}catch{k(O("Unable to create folder",z))}}D.reverse().reduce(function(L,z){return function(B){if(B)L(B);else{let X=Se.normalize(d(z.entryName)),Z=u(y,X);z.getDataAsync(function(se,ee){if(ee)L(ee);else if(!se)L(Ae.Errors.CANT_EXTRACT_FILE());else{let ae=A?z.header.fileAttr:void 0;o.writeFileToAsync(Z,se,v,ae,function(ce){ce||L(O("Unable to write file",Z)),o.fs.utimes(Z,z.header.time,z.header.time,function(P){P?L(O("Unable to set times",Z)):L()})})}})}}},k)()},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 k=o.writeFileTo(y,A,!0);typeof v=="function"&&v(k?null:new Error("failed"),"")}}},writeZipPromise:function(y,v){let{overwrite:A,perm:k}=Object.assign({overwrite:!0},v);return new Promise((R,O)=>{!y&&i.filename&&(y=i.filename),y||O("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(E=>{let D=L=>L?R(L):O("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(y,E,A,k,D)},O)})},toBufferPromise:function(){return new Promise((y,v)=>{c.toAsyncBuffer(y,v)})},toBuffer:function(y,v,A,k){return typeof y=="function"?(c.toAsyncBuffer(y,v,A,k),null):c.compressToBuffer()}}}});import{execFile as V_,spawn as J_,spawnSync as ok}from"node:child_process";import{promisify as Z_}from"node:util";function Y_(t){if(process.platform!=="win32")return!1;if(Kf.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(Kf,"").toLowerCase();return X_.has(r)}function $f(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return Y_(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function it(t,e=[],r={}){return J_(t,e,$f(t,r))}function Vf(t,e=[],r={}){return Q_(t,e,$f(t,r))}var X_,Kf,Q_,Jt=nt(()=>{"use strict";X_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Kf=/\.(cmd|bat|ps1)$/i;Q_=Z_(V_)});var Xt=de((WR,Ox)=>{"use strict";var Dx=["nodebuffer","arraybuffer","fragments"],Px=typeof Blob<"u";Px&&Dx.push("blob");Ox.exports={BINARY_TYPES:Dx,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:Px,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var Xi=de((KR,Bo)=>{"use strict";var{EMPTY_BUFFER:ZE}=Xt(),Ad=Buffer[Symbol.species];function XE(t,e){if(t.length===0)return ZE;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 Ad(r.buffer,r.byteOffset,i):r}function Lx(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function Nx(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function YE(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function Id(t){if(Id.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new Ad(t):ArrayBuffer.isView(t)?e=new Ad(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),Id.readOnly=!1),e}Bo.exports={concat:XE,mask:Lx,toArrayBuffer:YE,toBuffer:Id,unmask:Nx};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=he("bufferutil");Bo.exports.mask=function(e,r,i,o,c){c<48?Lx(e,r,i,o,c):t.mask(e,r,i,o,c)},Bo.exports.unmask=function(e,r){e.length<32?Nx(e,r):t.unmask(e,r)}}catch{}});var Fx=de(($R,Bx)=>{"use strict";var Mx=Symbol("kDone"),kd=Symbol("kRun"),Td=class{constructor(e){this[Mx]=()=>{this.pending--,this[kd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[kd]()}[kd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Mx])}}};Bx.exports=Td});var jr=de((VR,Gx)=>{"use strict";var Yi=he("zlib"),zx=Xi(),QE=Fx(),{kStatusCode:Ux}=Xt(),ev=Buffer[Symbol.species],tv=Buffer.from([0,0,255,255]),zo=Symbol("permessage-deflate"),Yt=Symbol("total-length"),Gr=Symbol("callback"),Dn=Symbol("buffers"),qr=Symbol("error"),Fo,Cd=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,!Fo){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Fo=new QE(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[Gr];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){Fo.add(o=>{this._decompress(e,r,(c,d)=>{o(),i(c,d)})})}compress(e,r,i){Fo.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"?Yi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Yi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:d}),this._inflate[zo]=this,this._inflate[Yt]=0,this._inflate[Dn]=[],this._inflate.on("error",rv),this._inflate.on("data",Hx)}this._inflate[Gr]=i,this._inflate.write(e),r&&this._inflate.write(tv),this._inflate.flush(()=>{let c=this._inflate[qr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let d=zx.concat(this._inflate[Dn],this._inflate[Yt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Yt]=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"?Yi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Yi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:d}),this._deflate[Yt]=0,this._deflate[Dn]=[],this._deflate.on("data",nv)}this._deflate[Gr]=i,this._deflate.write(e),this._deflate.flush(Yi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=zx.concat(this._deflate[Dn],this._deflate[Yt]);r&&(c=new ev(c.buffer,c.byteOffset,c.length-4)),this._deflate[Gr]=null,this._deflate[Yt]=0,this._deflate[Dn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};Gx.exports=Cd;function nv(t){this[Dn].push(t),this[Yt]+=t.length}function Hx(t){if(this[Yt]+=t.length,this[zo]._maxPayload<1||this[Yt]<=this[zo]._maxPayload){this[Dn].push(t);return}this[qr]=new RangeError("Max payload size exceeded"),this[qr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[qr][Ux]=1009,this.removeListener("data",Hx),this.reset()}function rv(t){if(this[zo]._inflate=null,this[qr]){this[Gr](this[qr]);return}t[Ux]=1007,this[Gr](t)}});var Wr=de((JR,Uo)=>{"use strict";var{isUtf8:qx}=he("buffer"),{hasBlob:iv}=Xt(),sv=[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 ov(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function Rd(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 av(t){return iv&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Uo.exports={isBlob:av,isValidStatusCode:ov,isValidUTF8:Rd,tokenChars:sv};if(qx)Uo.exports.isValidUTF8=function(t){return t.length<24?Rd(t):qx(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=he("utf-8-validate");Uo.exports.isValidUTF8=function(e){return e.length<32?Rd(e):t(e)}}catch{}});var Nd=de((ZR,Zx)=>{"use strict";var{Writable:cv}=he("stream"),jx=jr(),{BINARY_TYPES:dv,EMPTY_BUFFER:Wx,kStatusCode:lv,kWebSocket:uv}=Xt(),{concat:Dd,toArrayBuffer:fv,unmask:xv}=Xi(),{isValidStatusCode:hv,isValidUTF8:Kx}=Wr(),Ho=Buffer[Symbol.species],pt=0,$x=1,Vx=2,Jx=3,Pd=4,Od=5,Go=6,Ld=class extends cv{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||dv[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[uv]=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();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 Ho(i.buffer,i.byteOffset+e,i.length-e),new Ho(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 Ho(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 $x:this.getPayloadLength16(e);break;case Vx:this.getPayloadLength64(e);break;case Jx:this.getMask();break;case Pd:this.getData(e);break;case Od:case Go: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[jx.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=$x:this._payloadLength===127?this._state=Vx: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=Jx:this._state=Pd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Pd}getData(e){let r=Wx;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&&xv(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=Od,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[jx.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let d=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(d);return}this._fragments.push(c)}this.dataMessage(r),this._state===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=Dd(i,r):this._binaryType==="arraybuffer"?o=fv(Dd(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=pt):(this._state=Go,setImmediate(()=>{this.emit("message",o,!0),this._state=pt,this.startLoop(e)}))}else{let o=Dd(i,r);if(!this._skipUTF8Validation&&!Kx(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===Od||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=pt):(this._state=Go,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,Wx),this.end();else{let i=e.readUInt16BE(0);if(!hv(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Ho(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!Kx(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=Go,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[lv]=o,d}};Zx.exports=Ld});var Fd=de((YR,Qx)=>{"use strict";var{Duplex:XR}=he("stream"),{randomFillSync:pv}=he("crypto"),Xx=jr(),{EMPTY_BUFFER:gv,kWebSocket:mv,NOOP:wv}=Xt(),{isBlob:Kr,isValidStatusCode:_v}=Wr(),{mask:Yx,toBuffer:Qn}=Xi(),gt=Symbol("kByteLength"),yv=Buffer.alloc(4),qo=8*1024,er,$r=qo,At=0,bv=1,Ev=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=At,this.onerror=wv,this[mv]=void 0}static frame(e,r){let i,o=!1,c=2,d=!1;r.mask&&(i=r.maskBuffer||yv,r.generateMask?r.generateMask(i):($r===qo&&(er===void 0&&(er=Buffer.alloc(qo)),pv(er,0,qo),$r=0),i[0]=er[$r++],i[1]=er[$r++],i[2]=er[$r++],i[3]=er[$r++]),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 x=u;u>=65536?(c+=8,x=127):u>125&&(c+=2,x=126);let h=Buffer.allocUnsafe(o?u+c:c);return h[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(h[0]|=64),h[1]=x,x===126?h.writeUInt16BE(u,2):x===127&&(h[2]=h[3]=0,h.writeUIntBE(u,4,6)),r.mask?(h[1]|=128,h[c-4]=i[0],h[c-3]=i[1],h[c-2]=i[2],h[c-1]=i[3],d?[h,e]:o?(Yx(e,i,h,c,u),[h]):(Yx(e,i,e,0,u),[h,e])):[h,e]}close(e,r,i,o){let c;if(e===void 0)c=gv;else{if(typeof e!="number"||!_v(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(r);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof r=="string"?c.write(r,2):c.set(r,2)}}let d={[gt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==At?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):Kr(e)?(o=e.size,c=!1):(e=Qn(e),o=e.length,c=Qn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[gt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Kr(e)?this._state!==At?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==At?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):Kr(e)?(o=e.size,c=!1):(e=Qn(e),o=e.length,c=Qn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[gt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Kr(e)?this._state!==At?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==At?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}send(e,r,i){let o=this._extensions[Xx.extensionName],c=r.binary?2:1,d=r.compress,u,x;typeof e=="string"?(u=Buffer.byteLength(e),x=!1):Kr(e)?(u=e.size,x=!1):(e=Qn(e),u=e.length,x=Qn.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 h={[gt]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:x,rsv1:d};Kr(e)?this._state!==At?this.enqueue([this.getBlobData,e,this._compress,h,i]):this.getBlobData(e,this._compress,h,i):this._state!==At?this.enqueue([this.dispatch,e,this._compress,h,i]):this.dispatch(e,this._compress,h,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[gt],this._state=Ev,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=Qn(c);r?this.dispatch(d,r,i,o):(this._state=At,this.sendFrame(t.frame(d,i),o),this.dequeue())}).catch(c=>{process.nextTick(vv,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Xx.extensionName];this._bufferedBytes+=i[gt],this._state=bv,c.compress(e,i.fin,(d,u)=>{if(this._socket.destroyed){let x=new Error("The socket was closed while data was being compressed");Bd(this,x,o);return}this._bufferedBytes-=i[gt],this._state=At,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===At&&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)}};Qx.exports=Md;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 vv(t,e,r){Bd(t,e,r),t.onerror(e)}});var ch=de((QR,ah)=>{"use strict";var{kForOnEventAttribute:Qi,kListener:zd}=Xt(),eh=Symbol("kCode"),th=Symbol("kData"),nh=Symbol("kError"),rh=Symbol("kMessage"),ih=Symbol("kReason"),Vr=Symbol("kTarget"),sh=Symbol("kType"),oh=Symbol("kWasClean"),Qt=class{constructor(e){this[Vr]=null,this[sh]=e}get target(){return this[Vr]}get type(){return this[sh]}};Object.defineProperty(Qt.prototype,"target",{enumerable:!0});Object.defineProperty(Qt.prototype,"type",{enumerable:!0});var tr=class extends Qt{constructor(e,r={}){super(e),this[eh]=r.code===void 0?0:r.code,this[ih]=r.reason===void 0?"":r.reason,this[oh]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[eh]}get reason(){return this[ih]}get wasClean(){return this[oh]}};Object.defineProperty(tr.prototype,"code",{enumerable:!0});Object.defineProperty(tr.prototype,"reason",{enumerable:!0});Object.defineProperty(tr.prototype,"wasClean",{enumerable:!0});var Jr=class extends Qt{constructor(e,r={}){super(e),this[nh]=r.error===void 0?null:r.error,this[rh]=r.message===void 0?"":r.message}get error(){return this[nh]}get message(){return this[rh]}};Object.defineProperty(Jr.prototype,"error",{enumerable:!0});Object.defineProperty(Jr.prototype,"message",{enumerable:!0});var es=class extends Qt{constructor(e,r={}){super(e),this[th]=r.data===void 0?null:r.data}get data(){return this[th]}};Object.defineProperty(es.prototype,"data",{enumerable:!0});var Sv={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Qi]&&o[zd]===e&&!o[Qi])return;let i;if(t==="message")i=function(c,d){let u=new es("message",{data:d?c:c.toString()});u[Vr]=this,jo(e,this,u)};else if(t==="close")i=function(c,d){let u=new tr("close",{code:c,reason:d.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Vr]=this,jo(e,this,u)};else if(t==="error")i=function(c){let d=new Jr("error",{error:c,message:c.message});d[Vr]=this,jo(e,this,d)};else if(t==="open")i=function(){let c=new Qt("open");c[Vr]=this,jo(e,this,c)};else return;i[Qi]=!!r[Qi],i[zd]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[zd]===e&&!r[Qi]){this.removeListener(t,r);break}}};ah.exports={CloseEvent:tr,ErrorEvent:Jr,Event:Qt,EventTarget:Sv,MessageEvent:es};function jo(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Wo=de((eD,dh)=>{"use strict";var{tokenChars:ts}=Wr();function Bt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function Av(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,d,u,x=-1,h=-1,p=-1,_=0;for(;_<t.length;_++)if(h=t.charCodeAt(_),d===void 0)if(p===-1&&ts[h]===1)x===-1&&(x=_);else if(_!==0&&(h===32||h===9))p===-1&&x!==-1&&(p=_);else if(h===59||h===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);p===-1&&(p=_);let y=t.slice(x,p);h===44?(Bt(e,y,r),r=Object.create(null)):d=y,x=p=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);else if(u===void 0)if(p===-1&&ts[h]===1)x===-1&&(x=_);else if(h===32||h===9)p===-1&&x!==-1&&(p=_);else if(h===59||h===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);p===-1&&(p=_),Bt(r,t.slice(x,p),!0),h===44&&(Bt(e,d,r),r=Object.create(null),d=void 0),x=p=-1}else if(h===61&&x!==-1&&p===-1)u=t.slice(x,_),x=p=-1;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(o){if(ts[h]!==1)throw new SyntaxError(`Unexpected character at index ${_}`);x===-1?x=_:i||(i=!0),o=!1}else if(c)if(ts[h]===1)x===-1&&(x=_);else if(h===34&&x!==-1)c=!1,p=_;else if(h===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(h===34&&t.charCodeAt(_-1)===61)c=!0;else if(p===-1&&ts[h]===1)x===-1&&(x=_);else if(x!==-1&&(h===32||h===9))p===-1&&(p=_);else if(h===59||h===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);p===-1&&(p=_);let y=t.slice(x,p);i&&(y=y.replace(/\\/g,""),i=!1),Bt(r,u,y),h===44&&(Bt(e,d,r),r=Object.create(null),d=void 0),u=void 0,x=p=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);if(x===-1||c||h===32||h===9)throw new SyntaxError("Unexpected end of input");p===-1&&(p=_);let S=t.slice(x,p);return d===void 0?Bt(e,S,r):(u===void 0?Bt(r,S,!0):i?Bt(r,u,S.replace(/\\/g,"")):Bt(r,u,S),Bt(e,d,r)),e}function Iv(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(", ")}dh.exports={format:Iv,parse:Av}});var Jo=de((rD,bh)=>{"use strict";var kv=he("events"),Tv=he("https"),Cv=he("http"),fh=he("net"),Rv=he("tls"),{randomBytes:Dv,createHash:Pv}=he("crypto"),{Duplex:tD,Readable:nD}=he("stream"),{URL:Ud}=he("url"),Pn=jr(),Ov=Nd(),Lv=Fd(),{isBlob:Nv}=Wr(),{BINARY_TYPES:lh,CLOSE_TIMEOUT:Mv,EMPTY_BUFFER:Ko,GUID:Bv,kForOnEventAttribute:Hd,kListener:Fv,kStatusCode:zv,kWebSocket:We,NOOP:xh}=Xt(),{EventTarget:{addEventListener:Uv,removeEventListener:Hv}}=ch(),{format:Gv,parse:qv}=Wo(),{toBuffer:jv}=Xi(),hh=Symbol("kAborted"),Gd=[8,13],en=["CONNECTING","OPEN","CLOSING","CLOSED"],Wv=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,ye=class t extends kv{constructor(e,r,i){super(),this._binaryType=lh[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Ko,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),ph(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){lh.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 Ov({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new Lv(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[We]=this,c[We]=this,e[We]=this,o.on("conclude",Vv),o.on("drain",Jv),o.on("error",Zv),o.on("message",Xv),o.on("ping",Yv),o.on("pong",Qv),c.onerror=eS,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",wh),e.on("data",Vo),e.on("end",_h),e.on("error",yh),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){dt(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())}),mh(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){qd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Ko,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){qd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Ko,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){qd(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||Ko,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){dt(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(ye,"CONNECTING",{enumerable:!0,value:en.indexOf("CONNECTING")});Object.defineProperty(ye.prototype,"CONNECTING",{enumerable:!0,value:en.indexOf("CONNECTING")});Object.defineProperty(ye,"OPEN",{enumerable:!0,value:en.indexOf("OPEN")});Object.defineProperty(ye.prototype,"OPEN",{enumerable:!0,value:en.indexOf("OPEN")});Object.defineProperty(ye,"CLOSING",{enumerable:!0,value:en.indexOf("CLOSING")});Object.defineProperty(ye.prototype,"CLOSING",{enumerable:!0,value:en.indexOf("CLOSING")});Object.defineProperty(ye,"CLOSED",{enumerable:!0,value:en.indexOf("CLOSED")});Object.defineProperty(ye.prototype,"CLOSED",{enumerable:!0,value:en.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(ye.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(ye.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Hd])return e[Fv];return null},set(e){for(let r of this.listeners(t))if(r[Hd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[Hd]:!0})}})});ye.prototype.addEventListener=Uv;ye.prototype.removeEventListener=Hv;bh.exports=ye;function ph(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:Mv,protocolVersion:Gd[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=o.autoPong,t._closeTimeout=o.closeTimeout,!Gd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Gd.join(", ")})`);let c;if(e instanceof Ud)c=e;else try{c=new Ud(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let d=c.protocol==="wss:",u=c.protocol==="ws+unix:",x;if(c.protocol!=="ws:"&&!d&&!u?x=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?x="The URL's pathname is empty":c.hash&&(x="The URL contains a fragment identifier"),x){let A=new SyntaxError(x);if(t._redirects===0)throw A;$o(t,A);return}let h=d?443:80,p=Dv(16).toString("base64"),_=d?Tv.request:Cv.request,S=new Set,y;if(o.createConnection=o.createConnection||(d?$v:Kv),o.defaultPort=o.defaultPort||h,o.port=c.port||h,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":p,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(y=new Pn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=Gv({[Pn.extensionName]:y.offer()})),r.length){for(let A of r){if(typeof A!="string"||!Wv.test(A)||S.has(A))throw new SyntaxError("An invalid or duplicated subprotocol was specified");S.add(A)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),u){let A=o.path.split(":");o.socketPath=A[0],o.path=A[1]}let v;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=d,t._originalHostOrSocketPath=u?o.socketPath:c.host;let A=i&&i.headers;if(i={...i,headers:{}},A)for(let[k,R]of Object.entries(A))i.headers[k.toLowerCase()]=R}else if(t.listenerCount("redirect")===0){let A=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!A||t._originalSecure&&!d)&&(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",()=>{dt(t,v,"Opening handshake has timed out")}),v.on("error",A=>{v===null||v[hh]||(v=t._req=null,$o(t,A))}),v.on("response",A=>{let k=A.headers.location,R=A.statusCode;if(k&&o.followRedirects&&R>=300&&R<400){if(++t._redirects>o.maxRedirects){dt(t,v,"Maximum redirects exceeded");return}v.abort();let O;try{O=new Ud(k,e)}catch{let D=new SyntaxError(`Invalid URL: ${k}`);$o(t,D);return}ph(t,O,r,i)}else t.emit("unexpected-response",v,A)||dt(t,v,`Unexpected server response: ${A.statusCode}`)}),v.on("upgrade",(A,k,R)=>{if(t.emit("upgrade",A),t.readyState!==ye.CONNECTING)return;v=t._req=null;let O=A.headers.upgrade;if(O===void 0||O.toLowerCase()!=="websocket"){dt(t,k,"Invalid Upgrade header");return}let E=Pv("sha1").update(p+Bv).digest("base64");if(A.headers["sec-websocket-accept"]!==E){dt(t,k,"Invalid Sec-WebSocket-Accept header");return}let D=A.headers["sec-websocket-protocol"],L;if(D!==void 0?S.size?S.has(D)||(L="Server sent an invalid subprotocol"):L="Server sent a subprotocol but none was requested":S.size&&(L="Server sent no subprotocol"),L){dt(t,k,L);return}D&&(t._protocol=D);let z=A.headers["sec-websocket-extensions"];if(z!==void 0){if(!y){dt(t,k,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let B;try{B=qv(z)}catch{dt(t,k,"Invalid Sec-WebSocket-Extensions header");return}let X=Object.keys(B);if(X.length!==1||X[0]!==Pn.extensionName){dt(t,k,"Server indicated an extension that was not requested");return}try{y.accept(B[Pn.extensionName])}catch{dt(t,k,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[Pn.extensionName]=y}t.setSocket(k,R,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(v,t):v.end()}function $o(t,e){t._readyState=ye.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Kv(t){return t.path=t.socketPath,fh.connect(t)}function $v(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=fh.isIP(t.host)?"":t.host),Rv.connect(t)}function dt(t,e,r){t._readyState=ye.CLOSING;let i=new Error(r);Error.captureStackTrace(i,dt),e.setHeader?(e[hh]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick($o,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function qd(t,e,r){if(e){let i=Nv(e)?e.size:jv(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${en[t.readyState]})`);process.nextTick(r,i)}}function Vv(t,e){let r=this[We];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[We]!==void 0&&(r._socket.removeListener("data",Vo),process.nextTick(gh,r._socket),t===1005?r.close():r.close(t,e))}function Jv(){let t=this[We];t.isPaused||t._socket.resume()}function Zv(t){let e=this[We];e._socket[We]!==void 0&&(e._socket.removeListener("data",Vo),process.nextTick(gh,e._socket),e.close(t[zv])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function uh(){this[We].emitClose()}function Xv(t,e){this[We].emit("message",t,e)}function Yv(t){let e=this[We];e._autoPong&&e.pong(t,!this._isServer,xh),e.emit("ping",t)}function Qv(t){this[We].emit("pong",t)}function gh(t){t.resume()}function eS(t){let e=this[We];e.readyState!==ye.CLOSED&&(e.readyState===ye.OPEN&&(e._readyState=ye.CLOSING,mh(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function mh(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function wh(){let t=this[We];if(this.removeListener("close",wh),this.removeListener("data",Vo),this.removeListener("end",_h),t._readyState=ye.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[We]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",uh),t._receiver.on("finish",uh))}function Vo(t){this[We]._receiver.write(t)||this.pause()}function _h(){let t=this[We];t._readyState=ye.CLOSING,t._receiver.end(),this.end()}function yh(){let t=this[We];this.removeListener("error",yh),this.on("error",xh),t&&(t._readyState=ye.CLOSING,this.destroy())}});var Ah=de((sD,Sh)=>{"use strict";var iD=Jo(),{Duplex:tS}=he("stream");function Eh(t){t.emit("close")}function nS(){!this.destroyed&&this._writableState.finished&&this.destroy()}function vh(t){this.removeListener("error",vh),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function rS(t,e){let r=!0,i=new tS({...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(Eh,i);return}let d=!1;t.once("error",function(x){d=!0,c(x)}),t.once("close",function(){d||c(o),process.nextTick(Eh,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",nS),i.on("error",vh),i}Sh.exports=rS});var jd=de((oD,Ih)=>{"use strict";var{tokenChars:iS}=Wr();function sS(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&&iS[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}Ih.exports={parse:sS}});var Oh=de((cD,Ph)=>{"use strict";var oS=he("events"),Zo=he("http"),{Duplex:aD}=he("stream"),{createHash:aS}=he("crypto"),kh=Wo(),nr=jr(),cS=jd(),dS=Jo(),{CLOSE_TIMEOUT:lS,GUID:uS,kWebSocket:fS}=Xt(),xS=/^[+/0-9A-Za-z]{22}==$/,Th=0,Ch=1,Dh=2,Wd=class extends oS{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:lS,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:dS,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=Zo.createServer((i,o)=>{let c=Zo.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=hS(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=Th}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===Dh){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(ns,this);return}if(e&&this.once("close",e),this._state!==Ch)if(this._state=Ch,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(ns,this):process.nextTick(ns,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{ns(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,o){r.on("error",Rh);let c=e.headers["sec-websocket-key"],d=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){rr(this,e,r,405,"Invalid HTTP method");return}if(d===void 0||d.toLowerCase()!=="websocket"){rr(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!xS.test(c)){rr(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){rr(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){rs(r,400);return}let x=e.headers["sec-websocket-protocol"],h=new Set;if(x!==void 0)try{h=cS.parse(x)}catch{rr(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let p=e.headers["sec-websocket-extensions"],_={};if(this.options.perMessageDeflate&&p!==void 0){let S=new nr({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let y=kh.parse(p);y[nr.extensionName]&&(S.accept(y[nr.extensionName]),_[nr.extensionName]=S)}catch{rr(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,(y,v,A,k)=>{if(!y)return rs(r,v||401,A,k);this.completeUpgrade(_,c,h,e,r,i,o)});return}if(!this.options.verifyClient(S))return rs(r,401)}this.completeUpgrade(_,c,h,e,r,i,o)}completeUpgrade(e,r,i,o,c,d,u){if(!c.readable||!c.writable)return c.destroy();if(c[fS])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Th)return rs(c,503);let h=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${aS("sha1").update(r+uS).digest("base64")}`],p=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;_&&(h.push(`Sec-WebSocket-Protocol: ${_}`),p._protocol=_)}if(e[nr.extensionName]){let _=e[nr.extensionName].params,S=kh.format({[nr.extensionName]:[_]});h.push(`Sec-WebSocket-Extensions: ${S}`),p._extensions=e}this.emit("headers",h,o),c.write(h.concat(`\r
8
+ var vg=Object.create;var Ea=Object.defineProperty;var Sg=Object.getOwnPropertyDescriptor;var Ig=Object.getOwnPropertyNames;var Ag=Object.getPrototypeOf,Tg=Object.prototype.hasOwnProperty;var ue=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var et=(t,e)=>()=>(t&&(e=t(t=0)),e);var ae=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),va=(t,e)=>{for(var n in e)Ea(t,n,{get:e[n],enumerable:!0})},kg=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ig(e))!Tg.call(t,o)&&o!==n&&Ea(t,o,{get:()=>e[o],enumerable:!(i=Sg(e,o))||i.enumerable});return t};var Ut=(t,e,n)=>(n=t!=null?vg(Ag(t)):{},kg(e||!t||!t.__esModule?Ea(n,"default",{value:t,enumerable:!0}):n,t));function Ve(t,e){let n=process.env[t];if(!n)return e;let i=Number(n);return Number.isFinite(i)&&i>0?i:e}var sr=et(()=>{"use strict"});import{createWriteStream as Rg,mkdirSync as Cg,readdirSync as Pg,unlinkSync as Dg}from"node:fs";import{join as yd}from"node:path";function Dn(t){let e=n=>String(n).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function or(t,e){return`${t}-${e}.log`}function Sa(t,e){let n=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!n||n[1]!==e?null:n[2]??null}function Og(t,e,n){let i=c=>{let[l,u,h]=c.split("-").map(Number);return Date.UTC(l??0,(u??1)-1,h??1)};return Math.floor((i(e)-i(t))/864e5)>n}function ds(t,e,n,i){let o;try{o=Pg(t)}catch{return}for(let c of o){let l=Sa(c,e);if(l&&Og(l,n,i))try{Dg(yd(t,c))}catch{}}}var ni,Ia=et(()=>{"use strict";ni=class{constructor(e,n,i){this.dir=e;this.prefix=n;this.opts=i;this.clock=i.clock??(()=>Dn(new Date))}dir;prefix;opts;currentDate;stream;clock;write(e){let n=this.clock();n!==this.currentDate&&this.rotate(n),this.stream?.write(e)}rotate(e){this.stream?.end();try{Cg(this.dir,{recursive:!0});let n=Rg(yd(this.dir,or(this.prefix,e)),{flags:"a"});n.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
9
+ `)),this.stream=n}catch(n){process.stderr.write(`[log-sink] rotate failed: ${String(n)}
10
+ `),this.stream=void 0;return}this.currentDate!==void 0&&ds(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 Ng,mkdirSync as Lg}from"node:fs";import{join as Mg}from"node:path";function Ed(t){let e=t.retentionDays??zg,n=t.clock??(()=>Dn(new Date));fs={bridgeSink:new ni(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:n}),agentSinks:new Map,makeAgentSink:o=>new ni(t.agentLogsDir(o),"agent",{retentionDays:e,clock:n})};let i=n();ds(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])ds(t.agentLogsDir(o),"agent",i,e)}function Ug(t,e){let n=t.agentSinks.get(e);return n||(n=t.makeAgentSink(e),t.agentSinks.set(e,n)),n}function vd(t){Aa=t}function Sd(t){return ar[Aa]<=ar[t]}function Id(t,e){let n=ar[t];return n===void 0?!0:n>=ar[e]}function hs(t){bd={...t}}function Ad(t){let e=(u,h=2)=>String(u).padStart(h,"0"),n=-t.getTimezoneOffset(),i=n>=0?"+":"-",o=Math.abs(n),c=e(Math.floor(o/60)),l=e(o%60);return`${Dn(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${l}`}function lt(t,e,n,i,o){try{let c=`${JSON.stringify({ts:Ad(new Date),level:e,module:n,msg:i,...o})}
11
+ `;Lg(t,{recursive:!0}),Ng(Mg(t,or("bridge",Dn(new Date))),c)}catch{}}function Gg(t,e){if(t)return t;let n=e?.agentId;return typeof n=="string"&&n.length>0?n:void 0}function us(t,e,n,i,o){if(ar[t]<ar[Aa])return;let c=`${JSON.stringify({ts:Ad(new Date),level:t,module:e,msg:n,...bd,...i})}
12
+ `;if(fs){let l=Gg(o,i),u=l?Ug(fs,l):fs.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?Fg.write(c):Bg.write(c)}function G(t,e){return{debug:(n,i)=>us("debug",t,n,i,e),info:(n,i)=>us("info",t,n,i,e),warn:(n,i)=>us("warn",t,n,i,e),error:(n,i)=>us("error",t,n,i,e),child:n=>G(`${t}.${n}`,e),forAgent:n=>G(t,n)}}var ar,Aa,Bg,Fg,bd,zg,fs,ne=et(()=>{"use strict";sr();Ia();ar={debug:10,info:20,warn:30,error:40},Aa=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),Bg=process.stdout,Fg=process.stderr,bd={},zg=Ve("COZE_BRIDGE_LOG_RETENTION_DAYS",30),fs=null});var T,Ke=et(()=>{"use strict";T=class extends Error{code;retriable;cause;constructor(e,n,i){super(n),this.name="BridgeError",this.code=e,this.retriable=i?.retriable??!1,i?.cause!==void 0&&(this.cause=i.cause)}}});var Cd={};va(Cd,{ACP_WRAPPER_NPM_PACKAGES:()=>xs,_resetAcpInstallerForTests:()=>$g,_setBinaryPathCacheForTests:()=>Vg,buildAcpSpawn:()=>ii,ensureAcpInstalled:()=>cr,getAcpBinaryPath:()=>ps,pickWhichLine:()=>Ra,probeAcpVersion:()=>Kg,resolveAcpCommand:()=>Rd});import{readFileSync as Td}from"node:fs";import{createRequire as qg}from"node:module";import{dirname as Hg,resolve as jg}from"node:path";function Ra(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 n=i=>e.find(o=>o.toLowerCase().endsWith(i));return n(".cmd")??n(".exe")??n(".bat")??n(".ps1")??e[0]}function Wg(t){let e=kd.resolve(`${t.npmPackage}/package.json`),n=Hg(e),i=JSON.parse(Td(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 jg(n,o)}async function cr(t,e){let n=ka[t];if(!n)throw new T("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=ri.get(t);if(i)return i;try{let o=Wg(n);return ri.set(t,o),Ta.info("acp wrapper resolved",{framework:t,binary:n.binary,path:o}),o}catch(o){throw Ta.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:n.npmPackage,err:String(o)}),new T("AGENT_DEPENDENCY_INSTALL_FAILED",[`ACP wrapper \u672A\u5C31\u7EEA: ${n.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 Kg(t){let e=ka[t];if(e)try{let n=kd.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(Td(n,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(n){Ta.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(n)});return}}function ps(t){return ri.get(t)}function Rd(t,e){if(e)return e;let n=ps(t);if(!n)throw new T("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return n}function ii(t,e,n){if(e)return{command:e,args:[...n]};let i=Rd(t);return{command:process.execPath,args:[i,...n]}}function $g(){ri.clear()}function Vg(t,e){ri.set(t,e)}var Ta,ka,xs,kd,ri,on=et(()=>{"use strict";Ke();ne();Ta=G("agents.acp-installer"),ka={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},xs=Object.values(ka).filter(t=>t!==void 0).map(t=>t.npmPackage),kd=qg(import.meta.url),ri=new Map});import{chmod as Zg,mkdir as Yg,readFile as Xg,rename as Qg,rm as em,writeFile as tm}from"node:fs/promises";import{dirname as nm}from"node:path";async function lr(t){try{let e=await Xg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function an(t,e,n){await Yg(nm(t),{recursive:!0});let i=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{await tm(i,e,{encoding:"utf8",mode:n?.mode}),await Qg(i,t),n?.mode!==void 0&&await Zg(t,n.mode)}catch(o){throw await em(i,{force:!0}).catch(()=>{}),o}}async function dr(t,e,n){await an(t,`${JSON.stringify(e,null,2)}
14
+ `,n)}var cn=et(()=>{"use strict"});import{promises as Od,readdirSync as rm}from"node:fs";import{homedir as im}from"node:os";import{sep as sm,join as Te,resolve as Nd}from"node:path";function ee(t){let e=t??im(),n=Te(e,".coze"),i=Te(n,"bridge"),o=Te(i,"lib"),c=Te(i,"logs");return{cozeRoot:n,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(n,"agents")}}function Je(t,e=ee()){let n=Te(e.agentsRoot,t);return{root:n,config:Te(n,"config.json"),workspace:Te(n,"workspace"),logs:Te(n,"logs")}}function gs(t=ee()){try{return rm(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function si(t,e){let n=await Od.realpath(Nd(t)).catch(()=>null);if(!n)return!1;let i=await Od.realpath(Nd(e)).catch(()=>null);if(!i)return!1;let o=process.platform==="win32"?n.toLowerCase():n,c=process.platform==="win32"?i.toLowerCase():i;return o===c||o.startsWith(c+sm)}var Oe=et(()=>{"use strict"});var ws={};va(ws,{AGENT_CONFIG_FILE_MODE:()=>ms,enforceAgentConfigMode:()=>cm,loadAgentConfig:()=>ke,persistAgentSessions:()=>oi,persistAgentSkills:()=>ai,saveAgentConfig:()=>Fe});import{chmod as om,stat as am}from"node:fs/promises";function ke(t,e){return lr(Je(t,e).config)}function Fe(t,e){return dr(Je(t.agentId,e).config,t,{mode:ms})}async function cm(t,e){if(process.platform==="win32")return;let n=Je(t,e).config;try{let i=await am(n);if(!i.isFile())return;let o=i.mode&511;o!==ms&&(await om(n,ms),Ld.warn("agent config mode auto-corrected to 0600",{path:n,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Ld.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:n,err:String(i)})}}async function oi(t,e,n){let i=await ke(t,n);i&&(i.sessions=Object.fromEntries(e),await Fe(i,n))}async function ai(t,e,n){let i=await ke(t,n);i&&(i.skills=e,await Fe(i,n))}var Ld,ms,ln=et(()=>{"use strict";cn();ne();Oe();Ld=G("agent-config"),ms=384});var Da=ae((eI,Fd)=>{Fd.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 ys=ae(Ud=>{var zd={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 xm(t){return function(...e){return e.length&&(t=t.replace(/\{(\d)\}/g,(n,i)=>e[i]||"")),new Error("ADM-ZIP: "+t)}}for(let t of Object.keys(zd))Ud[t]=xm(zd[t])});var Wd=ae((nI,jd)=>{var pm=ue("fs"),Ne=ue("path"),Gd=Da(),gm=ys(),mm=typeof process=="object"&&process.platform==="win32",qd=t=>typeof t=="object"&&t!==null,Hd=new Uint32Array(256).map((t,e)=>{for(let n=0;n<8;n++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function ve(t){this.sep=Ne.sep,this.fs=pm,qd(t)&&qd(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}jd.exports=ve;ve.prototype.makeDir=function(t){let e=this;function n(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var l;try{l=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(l&&l.isFile())throw gm.FILE_IN_THE_WAY(`"${o}"`)}})}n(t)};ve.prototype.writeFileTo=function(t,e,n,i){let o=this;if(o.fs.existsSync(t)){if(!n)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var l=Ne.dirname(t);o.fs.existsSync(l)||o.makeDir(l);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};ve.prototype.writeFileToAsync=function(t,e,n,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(l){if(l&&!n)return o(!1);c.fs.stat(t,function(u,h){if(l&&h.isDirectory())return o(!1);var x=Ne.dirname(t);c.fs.exists(x,function(m){m||c.makeDir(x),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)})})})})})};ve.prototype.findFiles=function(t){let e=this;function n(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let l=[];return e.fs.readdirSync(i).forEach(function(u){let h=Ne.join(i,u),x=e.fs.statSync(h);(!o||o.test(h))&&l.push(Ne.normalize(h)+(x.isDirectory()?e.sep:"")),x.isDirectory()&&c&&(l=l.concat(n(h,o,c)))}),l}return n(t,void 0,!0)};ve.prototype.findFilesAsync=function(t,e){let n=this,i=[];n.fs.readdir(t,function(o,c){if(o)return e(o);let l=c.length;if(!l)return e(null,i);c.forEach(function(u){u=Ne.join(t,u),n.fs.stat(u,function(h,x){if(h)return e(h);x&&(i.push(Ne.normalize(u)+(x.isDirectory()?n.sep:"")),x.isDirectory()?n.findFilesAsync(u,function(m,_){if(m)return e(m);i=i.concat(_),--l||e(null,i)}):--l||e(null,i))})})})};ve.prototype.getAttributes=function(){};ve.prototype.setAttributes=function(){};ve.crc32update=function(t,e){return Hd[(t^e)&255]^t>>>8};ve.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,n=-1;for(let i=0;i<e;)n=ve.crc32update(n,t[i++]);return~n>>>0};ve.methodToString=function(t){switch(t){case Gd.STORED:return"STORED ("+t+")";case Gd.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};ve.canonical=function(t){if(!t)return"";let e=Ne.posix.normalize("/"+t.split("\\").join("/"));return Ne.join(".",e)};ve.zipnamefix=function(t){if(!t)return"";let e=Ne.posix.normalize("/"+t.split("\\").join("/"));return Ne.posix.join(".",e)};ve.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let n=t.length>>>0;for(let i=n-1;i>=0;i--)if(e(t[i],i,t))return t[i]};ve.sanitize=function(t,e){t=Ne.resolve(Ne.normalize(t));for(var n=e.split("/"),i=0,o=n.length;i<o;i++){var c=Ne.normalize(Ne.join(t,n.slice(i,o).join(Ne.sep)));if(c.indexOf(t)===0)return c}return Ne.normalize(Ne.join(t,Ne.basename(e)))};ve.toBuffer=function(e,n){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?n(e):Buffer.alloc(0)};ve.readBigUInt64LE=function(t,e){let n=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+n};ve.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)};ve.fromDate2DOS=function(t){let e=0,n=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),n=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|n};ve.isWin=mm;ve.crcTable=Hd});var $d=ae((rI,Kd)=>{var wm=ue("path");Kd.exports=function(t,{fs:e}){var n=t||"",i=c(),o=null;function c(){return{directory:!1,readonly:!1,hidden:!1,executable:!1,mtime:0,atime:0}}return n&&e.existsSync(n)?(o=e.statSync(n),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=wm.basename(n)[0]==="."):console.warn("Invalid path: "+n),{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:n,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 Jd=ae((iI,Vd)=>{Vd.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var hr=ae((sI,fr)=>{fr.exports=Wd();fr.exports.Constants=Da();fr.exports.Errors=ys();fr.exports.FileAttr=$d();fr.exports.decoder=Jd()});var Yd=ae((oI,Zd)=>{var dn=hr(),z=dn.Constants;Zd.exports=function(){var t=20,e=10,n=0,i=0,o=0,c=0,l=0,u=0,h=0,x=0,m=0,_=0,S=0,y=0,v=0;t|=dn.isWin?2560:768,n|=z.FLG_EFS;let I={extraLen:0},A=b=>Math.max(0,b)>>>0,k=b=>Math.max(0,b)&65535,P=b=>Math.max(0,b)&255;return o=dn.fromDate2DOS(new Date),{get made(){return t},set made(b){t=b},get version(){return e},set version(b){e=b},get flags(){return n},set flags(b){n=b},get flags_efs(){return(n&z.FLG_EFS)>0},set flags_efs(b){b?n|=z.FLG_EFS:n&=~z.FLG_EFS},get flags_desc(){return(n&z.FLG_DESC)>0},set flags_desc(b){b?n|=z.FLG_DESC:n&=~z.FLG_DESC},get method(){return i},set method(b){switch(b){case z.STORED:this.version=10;case z.DEFLATED:default:this.version=20}i=b},get time(){return dn.fromDOS2Date(this.timeval)},set time(b){b=new Date(b),this.timeval=dn.fromDate2DOS(b)},get timeval(){return o},set timeval(b){o=A(b)},get timeHighByte(){return P(o>>>8)},get crc(){return c},set crc(b){c=A(b)},get compressedSize(){return l},set compressedSize(b){l=A(b)},get size(){return u},set size(b){u=A(b)},get fileNameLength(){return h},set fileNameLength(b){h=b},get extraLength(){return x},set extraLength(b){x=b},get extraLocalLength(){return I.extraLen},set extraLocalLength(b){I.extraLen=b},get commentLength(){return m},set commentLength(b){m=b},get diskNumStart(){return _},set diskNumStart(b){_=A(b)},get inAttr(){return S},set inAttr(b){S=A(b)},get attr(){return y},set attr(b){y=A(b)},get fileAttr(){return(y||0)>>16&4095},get offset(){return v},set offset(b){v=A(b)},get encrypted(){return(n&z.FLG_ENC)===z.FLG_ENC},get centralHeaderSize(){return z.CENHDR+h+x+m},get realDataOffset(){return v+z.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(b){var R=b.slice(v,v+z.LOCHDR);if(R.readUInt32LE(0)!==z.LOCSIG)throw dn.Errors.INVALID_LOC();I.version=R.readUInt16LE(z.LOCVER),I.flags=R.readUInt16LE(z.LOCFLG),I.flags_desc=(I.flags&z.FLG_DESC)>0,I.method=R.readUInt16LE(z.LOCHOW),I.time=R.readUInt32LE(z.LOCTIM),I.crc=R.readUInt32LE(z.LOCCRC),I.compressedSize=R.readUInt32LE(z.LOCSIZ),I.size=R.readUInt32LE(z.LOCLEN),I.fnameLen=R.readUInt16LE(z.LOCNAM),I.extraLen=R.readUInt16LE(z.LOCEXT);let O=v+z.LOCHDR+I.fnameLen,B=O+I.extraLen;return b.slice(O,B)},loadFromBinary:function(b){if(b.length!==z.CENHDR||b.readUInt32LE(0)!==z.CENSIG)throw dn.Errors.INVALID_CEN();t=b.readUInt16LE(z.CENVEM),e=b.readUInt16LE(z.CENVER),n=b.readUInt16LE(z.CENFLG),i=b.readUInt16LE(z.CENHOW),o=b.readUInt32LE(z.CENTIM),c=b.readUInt32LE(z.CENCRC),l=b.readUInt32LE(z.CENSIZ),u=b.readUInt32LE(z.CENLEN),h=b.readUInt16LE(z.CENNAM),x=b.readUInt16LE(z.CENEXT),m=b.readUInt16LE(z.CENCOM),_=b.readUInt16LE(z.CENDSK),S=b.readUInt16LE(z.CENATT),y=b.readUInt32LE(z.CENATX),v=b.readUInt32LE(z.CENOFF)},localHeaderToBinary:function(){var b=Buffer.alloc(z.LOCHDR);return b.writeUInt32LE(z.LOCSIG,0),b.writeUInt16LE(e,z.LOCVER),b.writeUInt16LE(n,z.LOCFLG),b.writeUInt16LE(i,z.LOCHOW),b.writeUInt32LE(o,z.LOCTIM),b.writeUInt32LE(c,z.LOCCRC),b.writeUInt32LE(l,z.LOCSIZ),b.writeUInt32LE(u,z.LOCLEN),b.writeUInt16LE(h,z.LOCNAM),b.writeUInt16LE(I.extraLen,z.LOCEXT),b},centralHeaderToBinary:function(){var b=Buffer.alloc(z.CENHDR+h+x+m);return b.writeUInt32LE(z.CENSIG,0),b.writeUInt16LE(t,z.CENVEM),b.writeUInt16LE(e,z.CENVER),b.writeUInt16LE(n,z.CENFLG),b.writeUInt16LE(i,z.CENHOW),b.writeUInt32LE(o,z.CENTIM),b.writeUInt32LE(c,z.CENCRC),b.writeUInt32LE(l,z.CENSIZ),b.writeUInt32LE(u,z.CENLEN),b.writeUInt16LE(h,z.CENNAM),b.writeUInt16LE(x,z.CENEXT),b.writeUInt16LE(m,z.CENCOM),b.writeUInt16LE(_,z.CENDSK),b.writeUInt16LE(S,z.CENATT),b.writeUInt32LE(y,z.CENATX),b.writeUInt32LE(v,z.CENOFF),b},toJSON:function(){let b=function(R){return R+" bytes"};return{made:t,version:e,flags:n,method:dn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:b(l),size:b(u),fileNameLength:b(h),extraLength:b(x),commentLength:b(m),diskNumStart:_,inAttr:S,attr:y,offset:v,centralHeaderSize:b(z.CENHDR+h+x+m)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Qd=ae((aI,Xd)=>{var xr=hr(),ye=xr.Constants;Xd.exports=function(){var t=0,e=0,n=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 n},set size(c){n=c},get offset(){return i},set offset(c){i=c},get commentLength(){return o},set commentLength(c){o=c},get mainHeaderSize(){return ye.ENDHDR+o},loadFromBinary:function(c){if((c.length!==ye.ENDHDR||c.readUInt32LE(0)!==ye.ENDSIG)&&(c.length<ye.ZIP64HDR||c.readUInt32LE(0)!==ye.ZIP64SIG))throw xr.Errors.INVALID_END();c.readUInt32LE(0)===ye.ENDSIG?(t=c.readUInt16LE(ye.ENDSUB),e=c.readUInt16LE(ye.ENDTOT),n=c.readUInt32LE(ye.ENDSIZ),i=c.readUInt32LE(ye.ENDOFF),o=c.readUInt16LE(ye.ENDCOM)):(t=xr.readBigUInt64LE(c,ye.ZIP64SUB),e=xr.readBigUInt64LE(c,ye.ZIP64TOT),n=xr.readBigUInt64LE(c,ye.ZIP64SIZE),i=xr.readBigUInt64LE(c,ye.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(ye.ENDHDR+o);return c.writeUInt32LE(ye.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,ye.ENDSUB),c.writeUInt16LE(e,ye.ENDTOT),c.writeUInt32LE(n,ye.ENDSIZ),c.writeUInt32LE(i,ye.ENDOFF),c.writeUInt16LE(o,ye.ENDCOM),c.fill(" ",ye.ENDHDR),c},toJSON:function(){let c=function(l,u){let h=l.toString(16).toUpperCase();for(;h.length<u;)h="0"+h;return"0x"+h};return{diskEntries:t,totalEntries:e,size:n+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Na=ae(Oa=>{Oa.EntryHeader=Yd();Oa.MainHeader=Qd()});var tu=ae((lI,eu)=>{eu.exports=function(t){var e=ue("zlib"),n={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,n)},deflateAsync:function(i){var o=e.createDeflateRaw(n),c=[],l=0;o.on("data",function(u){c.push(u),l+=u.length}),o.on("end",function(){var u=Buffer.alloc(l),h=0;u.fill(0);for(var x=0;x<c.length;x++){var m=c[x];m.copy(u,h),h+=m.length}i&&i(u)}),o.end(t)}}}});var ru=ae((dI,nu)=>{var _m=+(process.versions?process.versions.node:"").split(".")[0]||0;nu.exports=function(t,e){var n=ue("zlib");let i=_m>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return n.inflateRawSync(t,i)},inflateAsync:function(o){var c=n.createInflateRaw(i),l=[],u=0;c.on("data",function(h){l.push(h),u+=h.length}),c.on("end",function(){var h=Buffer.alloc(u),x=0;h.fill(0);for(var m=0;m<l.length;m++){var _=l[m];_.copy(h,x),x+=_.length}o&&o(h)}),c.end(t)}}}});var cu=ae((uI,au)=>{"use strict";var{randomFillSync:iu}=ue("crypto"),ym=ys(),bm=new Uint32Array(256).map((t,e)=>{for(let n=0;n<8;n++)(e&1)!==0?e=e>>>1^3988292384:e>>>=1;return e>>>0}),ou=(t,e)=>Math.imul(t,e)>>>0,su=(t,e)=>bm[(t^e)&255]^t>>>8,ci=()=>typeof iu=="function"?iu(Buffer.alloc(12)):ci.node();ci.node=()=>{let t=Buffer.alloc(12),e=t.length;for(let n=0;n<e;n++)t[n]=Math.random()*256&255;return t};var bs={genSalt:ci};function Es(t){let e=Buffer.isBuffer(t)?t:Buffer.from(t);this.keys=new Uint32Array([305419896,591751049,878082192]);for(let n=0;n<e.length;n++)this.updateKeys(e[n])}Es.prototype.updateKeys=function(t){let e=this.keys;return e[0]=su(e[0],t),e[1]+=e[0]&255,e[1]=ou(e[1],134775813)+1,e[2]=su(e[2],e[1]>>>24),t};Es.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return ou(t,t^1)>>8&255};function Em(t){let e=new Es(t);return function(n){let i=Buffer.alloc(n.length),o=0;for(let c of n)i[o++]=e.updateKeys(c^e.next());return i}}function vm(t){let e=new Es(t);return function(n,i,o=0){i||(i=Buffer.alloc(n.length));for(let c of n){let l=e.next();i[o++]=c^l,e.updateKeys(c)}return i}}function Sm(t,e,n){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Em(n),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw ym.WRONG_PASSWORD();return i(t.slice(12))}function Im(t){Buffer.isBuffer(t)&&t.length>=12?bs.genSalt=function(){return t.slice(0,12)}:t==="node"?bs.genSalt=ci.node:bs.genSalt=ci}function Am(t,e,n,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=vm(n),c=bs.genSalt();c[11]=e.crc>>>24&255,i&&(c[10]=e.crc>>>16&255);let l=Buffer.alloc(t.length+12);return o(c,l),o(t,l,12)}au.exports={decrypt:Sm,encrypt:Am,_salter:Im}});var lu=ae(vs=>{vs.Deflater=tu();vs.Inflater=ru();vs.ZipCrypto=cu()});var Ma=ae((hI,du)=>{var ce=hr(),Tm=Na(),Se=ce.Constants,La=lu();du.exports=function(t,e){var n=new Tm.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,l=null,u=Buffer.alloc(0),h=Buffer.alloc(0),x=!0;let m=t,_=typeof m.decoder=="object"?m.decoder:ce.decoder;x=_.hasOwnProperty("efs")?_.efs:!1;function S(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(h=n.loadLocalHeaderFromBinary(e),e.slice(n.realDataOffset,n.realDataOffset+n.compressedSize))}function y(b){if(!n.flags_desc&&!n.localHeader.flags_desc){if(ce.crc32(b)!==n.localHeader.crc)return!1}else{let R={},O=n.realDataOffset+n.compressedSize;if(e.readUInt32LE(O)==Se.LOCSIG||e.readUInt32LE(O)==Se.CENSIG)throw ce.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(O)==Se.EXTSIG)R.crc=e.readUInt32LE(O+Se.EXTCRC),R.compressedSize=e.readUInt32LE(O+Se.EXTSIZ),R.size=e.readUInt32LE(O+Se.EXTLEN);else if(e.readUInt16LE(O+12)===19280)R.crc=e.readUInt32LE(O+Se.EXTCRC-4),R.compressedSize=e.readUInt32LE(O+Se.EXTSIZ-4),R.size=e.readUInt32LE(O+Se.EXTLEN-4);else throw ce.Errors.DESCRIPTOR_UNKNOWN();if(R.compressedSize!==n.compressedSize||R.size!==n.size||R.crc!==n.crc)throw ce.Errors.DESCRIPTOR_FAULTY();if(ce.crc32(b)!==R.crc)return!1}return!0}function v(b,R,O){if(typeof R>"u"&&typeof b=="string"&&(O=b,b=void 0),c)return b&&R&&R(Buffer.alloc(0),ce.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var B=S();if(B.length===0)return b&&R&&R(B),B;if(n.encrypted){if(typeof O!="string"&&!Buffer.isBuffer(O))throw ce.Errors.INVALID_PASS_PARAM();B=La.ZipCrypto.decrypt(B,n,O)}var M=Buffer.alloc(n.size);switch(n.method){case ce.Constants.STORED:if(B.copy(M),y(M))return b&&R&&R(M),M;throw b&&R&&R(M,ce.Errors.BAD_CRC()),ce.Errors.BAD_CRC();case ce.Constants.DEFLATED:var V=new La.Inflater(B,n.size);if(b)V.inflateAsync(function($){$.copy($,0),R&&(y($)?R($):R($,ce.Errors.BAD_CRC()))});else{if(V.inflate(M).copy(M,0),!y(M))throw ce.Errors.BAD_CRC(`"${_.decode(i)}"`);return M}break;default:throw b&&R&&R(Buffer.alloc(0),ce.Errors.UNKNOWN_METHOD()),ce.Errors.UNKNOWN_METHOD()}}function I(b,R){if((!l||!l.length)&&Buffer.isBuffer(e))return b&&R&&R(S()),S();if(l.length&&!c){var O;switch(n.method){case ce.Constants.STORED:return n.compressedSize=n.size,O=Buffer.alloc(l.length),l.copy(O),b&&R&&R(O),O;default:case ce.Constants.DEFLATED:var B=new La.Deflater(l);if(b)B.deflateAsync(function(V){O=Buffer.alloc(V.length),n.compressedSize=V.length,V.copy(O),R&&R(O)});else{var M=B.deflate();return n.compressedSize=M.length,M}B=null;break}}else if(b&&R)R(Buffer.alloc(0));else return Buffer.alloc(0)}function A(b,R){return ce.readBigUInt64LE(b,R)}function k(b){try{for(var R=0,O,B,M;R+4<b.length;)O=b.readUInt16LE(R),R+=2,B=b.readUInt16LE(R),R+=2,M=b.slice(R,R+B),R+=B,Se.ID_ZIP64===O&&P(M)}catch{throw ce.Errors.EXTRA_FIELD_PARSE_ERROR()}}function P(b){var R,O,B,M;b.length>=Se.EF_ZIP64_SCOMP&&(R=A(b,Se.EF_ZIP64_SUNCOMP),n.size===Se.EF_ZIP64_OR_32&&(n.size=R)),b.length>=Se.EF_ZIP64_RHO&&(O=A(b,Se.EF_ZIP64_SCOMP),n.compressedSize===Se.EF_ZIP64_OR_32&&(n.compressedSize=O)),b.length>=Se.EF_ZIP64_DSN&&(B=A(b,Se.EF_ZIP64_RHO),n.offset===Se.EF_ZIP64_OR_32&&(n.offset=B)),b.length>=Se.EF_ZIP64_DSN+4&&(M=b.readUInt32LE(Se.EF_ZIP64_DSN),n.diskNumStart===Se.EF_ZIP64_OR_16&&(n.diskNumStart=M))}return{get entryName(){return _.decode(i)},get rawEntryName(){return i},set entryName(b){i=ce.toBuffer(b,_.encode);var R=i[i.length-1];c=R===47||R===92,n.fileNameLength=i.length},get efs(){return typeof x=="function"?x(this.entryName):x},get extra(){return u},set extra(b){u=b,n.extraLength=b.length,k(b)},get comment(){return _.decode(o)},set comment(b){if(o=ce.toBuffer(b,_.encode),n.commentLength=o.length,o.length>65535)throw ce.Errors.COMMENT_TOO_LONG()},get name(){var b=_.decode(i);return c?b.substr(b.length-1).split("/").pop():b.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(b){I(!0,b)},setData:function(b){l=ce.toBuffer(b,ce.decoder.encode),!c&&l.length?(n.size=l.length,n.method=ce.Constants.DEFLATED,n.crc=ce.crc32(b),n.changed=!0):n.method=ce.Constants.STORED},getData:function(b){return n.changed?l:v(!1,null,b)},getDataAsync:function(b,R){n.changed?b(l):v(!0,b,R)},set attr(b){n.attr=b},get attr(){return n.attr},set header(b){n.loadFromBinary(b)},get header(){return n},packCentralHeader:function(){n.flags_efs=this.efs,n.extraLength=u.length;var b=n.centralHeaderToBinary(),R=ce.Constants.CENHDR;return i.copy(b,R),R+=i.length,u.copy(b,R),R+=n.extraLength,o.copy(b,R),b},packLocalHeader:function(){let b=0;n.flags_efs=this.efs,n.extraLocalLength=h.length;let R=n.localHeaderToBinary(),O=Buffer.alloc(R.length+i.length+n.extraLocalLength);return R.copy(O,b),b+=R.length,i.copy(O,b),b+=i.length,h.copy(O,b),b+=h.length,O},toJSON:function(){let b=function(R){return"<"+(R&&R.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:n.toJSON(),compressedData:b(e),data:b(l)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var hu=ae((xI,fu)=>{var uu=Ma(),km=Na(),$e=hr();fu.exports=function(t,e){var n=[],i={},o=Buffer.alloc(0),c=new km.MainHeader,l=!1,u=null;let h=new Set,x=e,{noSort:m,decoder:_}=x;t?v(x.readEntries):l=!0;function S(){let A=new Set;for(let k of Object.keys(i)){let P=k.split("/");if(P.pop(),!!P.length)for(let b=0;b<P.length;b++){let R=P.slice(0,b+1).join("/")+"/";A.add(R)}}for(let k of A)if(!(k in i)){let P=new uu(x);P.entryName=k,P.attr=16,P.temporary=!0,n.push(P),i[P.entryName]=P,h.add(P)}}function y(){if(l=!0,i={},c.diskEntries>(t.length-c.offset)/$e.Constants.CENHDR)throw $e.Errors.DISK_ENTRY_TOO_LARGE();n=new Array(c.diskEntries);for(var A=c.offset,k=0;k<n.length;k++){var P=A,b=new uu(x,t);b.header=t.slice(P,P+=$e.Constants.CENHDR),b.entryName=t.slice(P,P+=b.header.fileNameLength),b.header.extraLength&&(b.extra=t.slice(P,P+=b.header.extraLength)),b.header.commentLength&&(b.comment=t.slice(P,P+b.header.commentLength)),A+=b.header.centralHeaderSize,n[k]=b,i[b.entryName]=b}h.clear(),S()}function v(A){var k=t.length-$e.Constants.ENDHDR,P=Math.max(0,k-65535),b=P,R=t.length,O=-1,B=0;for(typeof x.trailingSpace=="boolean"&&x.trailingSpace&&(P=0),k;k>=b;k--)if(t[k]===80){if(t.readUInt32LE(k)===$e.Constants.ENDSIG){O=k,B=k,R=k+$e.Constants.ENDHDR,b=k-$e.Constants.END64HDR;continue}if(t.readUInt32LE(k)===$e.Constants.END64SIG){b=P;continue}if(t.readUInt32LE(k)===$e.Constants.ZIP64SIG){O=k,R=k+$e.readBigUInt64LE(t,k+$e.Constants.ZIP64SIZE)+$e.Constants.ZIP64LEAD;break}}if(O==-1)throw $e.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(O,R)),c.commentLength&&(o=t.slice(B+$e.Constants.ENDHDR)),A&&y()}function I(){n.length>1&&!m&&n.sort((A,k)=>A.entryName.toLowerCase().localeCompare(k.entryName.toLowerCase()))}return{get entries(){return l||y(),n.filter(A=>!h.has(A))},get comment(){return _.decode(o)},set comment(A){o=$e.toBuffer(A,_.encode),c.commentLength=o.length},getEntryCount:function(){return l?n.length:c.diskEntries},forEach:function(A){this.entries.forEach(A)},getEntry:function(A){return l||y(),i[A]||null},setEntry:function(A){l||y(),n.push(A),i[A.entryName]=A,c.totalEntries=n.length},deleteFile:function(A,k=!0){l||y();let P=i[A];this.getEntryChildren(P,k).map(R=>R.entryName).forEach(this.deleteEntry)},deleteEntry:function(A){l||y();let k=i[A],P=n.indexOf(k);P>=0&&(n.splice(P,1),delete i[A],c.totalEntries=n.length)},getEntryChildren:function(A,k=!0){if(l||y(),typeof A=="object")if(A.isDirectory&&k){let P=[],b=A.entryName;for(let R of n)R.entryName.startsWith(b)&&P.push(R);return P}else return[A];return[]},getChildCount:function(A){if(A&&A.isDirectory){let k=this.getEntryChildren(A);return k.includes(A)?k.length-1:k.length}return 0},compressToBuffer:function(){l||y(),I();let A=[],k=[],P=0,b=0;c.size=0,c.offset=0;let R=0;for(let M of this.entries){let V=M.getCompressedData();M.header.offset=b;let $=M.packLocalHeader(),re=$.length+V.length;b+=re,A.push($),A.push(V);let X=M.packCentralHeader();k.push(X),c.size+=X.length,P+=re+X.length,R++}P+=c.mainHeaderSize,c.offset=b,c.totalEntries=R,b=0;let O=Buffer.alloc(P);for(let M of A)M.copy(O,b),b+=M.length;for(let M of k)M.copy(O,b),b+=M.length;let B=c.toBinary();return o&&o.copy(B,$e.Constants.ENDHDR),B.copy(O,b),t=O,l=!1,O},toAsyncBuffer:function(A,k,P,b){try{l||y(),I();let R=[],O=[],B=0,M=0,V=0;c.size=0,c.offset=0;let $=function(re){if(re.length>0){let X=re.shift(),se=X.entryName+X.extra.toString();P&&P(se),X.getCompressedDataAsync(function(oe){b&&b(se),X.header.offset=M;let C=X.packLocalHeader(),U=C.length+oe.length;M+=U,R.push(C),R.push(oe);let j=X.packCentralHeader();O.push(j),c.size+=j.length,B+=U+j.length,V++,$(re)})}else{B+=c.mainHeaderSize,c.offset=M,c.totalEntries=V,M=0;let X=Buffer.alloc(B);R.forEach(function(oe){oe.copy(X,M),M+=oe.length}),O.forEach(function(oe){oe.copy(X,M),M+=oe.length});let se=c.toBinary();o&&o.copy(se,$e.Constants.ENDHDR),se.copy(X,M),t=X,l=!1,A(X)}};$(Array.from(this.entries))}catch(R){k(R)}}}}});var gu=ae((pI,pu)=>{var Ee=hr(),be=ue("path"),Rm=Ma(),Cm=hu(),On=(...t)=>Ee.findLast(t,e=>typeof e=="boolean"),xu=(...t)=>Ee.findLast(t,e=>typeof e=="string"),Pm=(...t)=>Ee.findLast(t,e=>typeof e=="function"),Dm={noSort:!1,readEntries:!1,method:Ee.Constants.NONE,fs:null};pu.exports=function(t,e){let n=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)&&(n=t,i.method=Ee.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new Ee(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=Ee.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=Ee.Constants.FILE,i.filename=t,n=o.fs.readFileSync(t);else throw Ee.Errors.INVALID_FILENAME();let c=new Cm(n,i),{canonical:l,sanitize:u,zipnamefix:h}=Ee;function x(y){if(y&&c){var v;if(typeof y=="string"&&(v=c.getEntry(be.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:I,sep:A}=be.posix;return v(be.isAbsolute(y)?"/":".",I(A+y.split("\\").join(A)+A))}function _(y){return y instanceof RegExp?(function(v){return function(I){return v.test(I)}})(y):typeof y!="function"?()=>!0:y}let S=(y,v)=>{let I=v.slice(-1);return I=I===o.sep?o.sep:"",be.relative(y,v)+I};return{readFile:function(y,v){var I=x(y);return I&&I.getData(v)||null},childCount:function(y){let v=x(y);if(v)return c.getChildCount(v)},readFileAsync:function(y,v){var I=x(y);I?I.getDataAsync(v):v(null,"getEntry failed for:"+y)},readAsText:function(y,v){var I=x(y);if(I){var A=I.getData();if(A&&A.length)return A.toString(v||"utf8")}return""},readAsTextAsync:function(y,v,I){var A=x(y);A?A.getDataAsync(function(k,P){if(P){v(k,P);return}k&&k.length?v(k.toString(I||"utf8")):v("")}):v("")},deleteFile:function(y,v=!0){var I=x(y);I&&c.deleteFile(I.entryName,v)},deleteEntry:function(y){var v=x(y);v&&c.deleteEntry(v.entryName)},addZipComment:function(y){c.comment=y},getZipComment:function(){return c.comment||""},addZipEntryComment:function(y,v){var I=x(y);I&&(I.comment=v)},getZipEntryComment:function(y){var v=x(y);return v&&v.comment||""},updateFile:function(y,v){var I=x(y);I&&I.setData(v)},addLocalFile:function(y,v,I,A){if(o.fs.existsSync(y)){v=v?m(v):"";let k=be.win32.basename(be.win32.normalize(y));v+=I||k;let P=o.fs.statSync(y),b=P.isFile()?o.fs.readFileSync(y):Buffer.alloc(0);P.isDirectory()&&(v+=o.sep),this.addFile(v,b,A,P)}else throw Ee.Errors.FILE_NOT_FOUND(y)},addLocalFileAsync:function(y,v){y=typeof y=="object"?y:{localPath:y};let I=be.resolve(y.localPath),{comment:A}=y,{zipPath:k,zipName:P}=y,b=this;o.fs.stat(I,function(R,O){if(R)return v(R,!1);k=k?m(k):"";let B=be.win32.basename(be.win32.normalize(I));if(k+=P||B,O.isFile())o.fs.readFile(I,function(M,V){return M?v(M,!1):(b.addFile(k,V,A,O),setImmediate(v,void 0,!0))});else if(O.isDirectory())return k+=o.sep,b.addFile(k,Buffer.alloc(0),A,O),setImmediate(v,void 0,!0)})},addLocalFolder:function(y,v,I){if(I=_(I),v=v?m(v):"",y=be.normalize(y),o.fs.existsSync(y)){let A=o.findFiles(y),k=this;if(A.length)for(let P of A){let b=be.join(v,S(y,P));I(b)&&k.addLocalFile(P,be.dirname(b))}}else throw Ee.Errors.FILE_NOT_FOUND(y)},addLocalFolderAsync:function(y,v,I,A){A=_(A),I=I?m(I):"",y=be.normalize(y);var k=this;o.fs.open(y,"r",function(P){if(P&&P.code==="ENOENT")v(void 0,Ee.Errors.FILE_NOT_FOUND(y));else if(P)v(void 0,P);else{var b=o.findFiles(y),R=-1,O=function(){if(R+=1,R<b.length){var B=b[R],M=S(y,B).split("\\").join("/");M=M.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),A(M)?o.fs.stat(B,function(V,$){V&&v(void 0,V),$.isFile()?o.fs.readFile(B,function(re,X){re?v(void 0,re):(k.addFile(I+M,X,"",$),O())}):(k.addFile(I+M+"/",Buffer.alloc(0),"",$),O())}):process.nextTick(()=>{O()})}else v(!0,void 0)};O()}})},addLocalFolderAsync2:function(y,v){let I=this;y=typeof y=="object"?y:{localPath:y},localPath=be.resolve(m(y.localPath));let{zipPath:A,filter:k,namefix:P}=y;k instanceof RegExp?k=(function(O){return function(B){return O.test(B)}})(k):typeof k!="function"&&(k=function(){return!0}),A=A?m(A):"",P=="latin1"&&(P=O=>O.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof P!="function"&&(P=O=>O);let b=O=>be.join(A,P(S(localPath,O))),R=O=>be.win32.basename(be.win32.normalize(P(O)));o.fs.open(localPath,"r",function(O){O&&O.code==="ENOENT"?v(void 0,Ee.Errors.FILE_NOT_FOUND(localPath)):O?v(void 0,O):o.findFilesAsync(localPath,function(B,M){if(B)return v(B);M=M.filter(V=>k(b(V))),M.length||v(void 0,!1),setImmediate(M.reverse().reduce(function(V,$){return function(re,X){if(re||X===!1)return setImmediate(V,re,!1);I.addLocalFileAsync({localPath:$,zipPath:be.dirname(b($)),zipName:R($)},V)}},v))})})},addLocalFolderPromise:function(y,v){return new Promise((I,A)=>{this.addLocalFolderAsync2(Object.assign({localPath:y},v),(k,P)=>{k&&A(k),P&&I(this)})})},addFile:function(y,v,I,A){y=h(y);let k=x(y),P=k!=null;P||(k=new Rm(i),k.entryName=y),k.comment=I||"";let b=typeof A=="object"&&A instanceof o.fs.Stats;b&&(k.header.time=A.mtime);var R=k.isDirectory?16:0;let O=k.isDirectory?16384:32768;return b?O|=4095&A.mode:typeof A=="number"?O|=4095&A:O|=k.isDirectory?493:420,R=(R|O<<16)>>>0,k.attr=R,k.setData(v),P||c.setEntry(k),k},getEntries:function(y){return c.password=y,c?c.entries:[]},getEntry:function(y){return x(y)},getEntryCount:function(){return c.getEntryCount()},forEach:function(y){return c.forEach(y)},extractEntryTo:function(y,v,I,A,k,P){A=On(!1,A),k=On(!1,k),I=On(!0,I),P=xu(k,P);var b=x(y);if(!b)throw Ee.Errors.NO_ENTRY();var R=l(b.entryName),O=u(v,P&&!b.isDirectory?P:I?R:be.basename(R));if(b.isDirectory){var B=c.getEntryChildren(b);return B.forEach(function($){if($.isDirectory)return;var re=$.getData();if(!re)throw Ee.Errors.CANT_EXTRACT_FILE();var X=l($.entryName),se=u(v,I?X:be.basename(X));let oe=k?$.header.fileAttr:void 0;o.writeFileTo(se,re,A,oe)}),!0}var M=b.getData(c.password);if(!M)throw Ee.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(O)&&!A)throw Ee.Errors.CANT_OVERRIDE();let V=k?y.header.fileAttr:void 0;return o.writeFileTo(O,M,A,V),!0},test:function(y){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var I=c.entries[v].getData(y);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(y,v,I,A){if(I=On(!1,I),A=xu(I,A),v=On(!1,v),!c)throw Ee.Errors.NO_ZIP();c.entries.forEach(function(k){var P=u(y,l(k.entryName));if(k.isDirectory){o.makeDir(P);return}var b=k.getData(A);if(!b)throw Ee.Errors.CANT_EXTRACT_FILE();let R=I?k.header.fileAttr:void 0;o.writeFileTo(P,b,v,R);try{o.fs.utimesSync(P,k.header.time,k.header.time)}catch{throw Ee.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(y,v,I,A){if(A=Pm(v,I,A),I=On(!1,I),v=On(!1,v),!A)return new Promise((O,B)=>{this.extractAllToAsync(y,v,I,function(M){M?B(M):O(this)})});if(!c){A(Ee.Errors.NO_ZIP());return}y=be.resolve(y);let k=O=>u(y,be.normalize(l(O.entryName))),P=(O,B)=>new Error(O+': "'+B+'"'),b=[],R=[];c.entries.forEach(O=>{O.isDirectory?b.push(O):R.push(O)});for(let O of b){let B=k(O),M=I?O.header.fileAttr:void 0;try{o.makeDir(B),M&&o.fs.chmodSync(B,M),o.fs.utimesSync(B,O.header.time,O.header.time)}catch{A(P("Unable to create folder",B))}}R.reverse().reduce(function(O,B){return function(M){if(M)O(M);else{let V=be.normalize(l(B.entryName)),$=u(y,V);B.getDataAsync(function(re,X){if(X)O(X);else if(!re)O(Ee.Errors.CANT_EXTRACT_FILE());else{let se=I?B.header.fileAttr:void 0;o.writeFileToAsync($,re,v,se,function(oe){oe||O(P("Unable to write file",$)),o.fs.utimes($,B.header.time,B.header.time,function(C){C?O(P("Unable to set times",$)):O()})})}})}}},A)()},writeZip:function(y,v){if(arguments.length===1&&typeof y=="function"&&(v=y,y=""),!y&&i.filename&&(y=i.filename),!!y){var I=c.compressToBuffer();if(I){var A=o.writeFileTo(y,I,!0);typeof v=="function"&&v(A?null:new Error("failed"),"")}}},writeZipPromise:function(y,v){let{overwrite:I,perm:A}=Object.assign({overwrite:!0},v);return new Promise((k,P)=>{!y&&i.filename&&(y=i.filename),y||P("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(b=>{let R=O=>O?k(O):P("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(y,b,I,A,R)},P)})},toBufferPromise:function(){return new Promise((y,v)=>{c.toAsyncBuffer(y,v)})},toBuffer:function(y,v,I,A){return typeof y=="function"?(c.toAsyncBuffer(y,v,I,A),null):c.compressToBuffer()}}}});import{execFile as F_,spawn as z_,spawnSync as OA}from"node:child_process";import{promisify as U_}from"node:util";function q_(t){if(process.platform!=="win32")return!1;if(Mf.test(t))return!0;let n=(t.split(/[/\\]/).pop()??t).replace(Mf,"").toLowerCase();return G_.has(n)}function Bf(t,e){if(process.platform!=="win32")return e??{};let n={...e??{}};return q_(t)&&n.shell===void 0&&(n.shell=!0),n.windowsHide===void 0&&(n.windowsHide=!0),n}function rt(t,e=[],n={}){return z_(t,e,Bf(t,n))}function Ff(t,e=[],n={}){return H_(t,e,Bf(t,n))}var G_,Mf,H_,$t=et(()=>{"use strict";G_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Mf=/\.(cmd|bat|ps1)$/i;H_=U_(F_)});var Jt=ae((pC,bh)=>{"use strict";var _h=["nodebuffer","arraybuffer","fragments"],yh=typeof Blob<"u";yh&&_h.push("blob");bh.exports={BINARY_TYPES:_h,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:yh,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var Ji=ae((gC,Co)=>{"use strict";var{EMPTY_BUFFER:bE}=Jt(),hl=Buffer[Symbol.species];function EE(t,e){if(t.length===0)return bE;if(t.length===1)return t[0];let n=Buffer.allocUnsafe(e),i=0;for(let o=0;o<t.length;o++){let c=t[o];n.set(c,i),i+=c.length}return i<e?new hl(n.buffer,n.byteOffset,i):n}function Eh(t,e,n,i,o){for(let c=0;c<o;c++)n[i+c]=t[c]^e[c&3]}function vh(t,e){for(let n=0;n<t.length;n++)t[n]^=e[n&3]}function vE(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function xl(t){if(xl.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new hl(t):ArrayBuffer.isView(t)?e=new hl(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),xl.readOnly=!1),e}Co.exports={concat:EE,mask:Eh,toArrayBuffer:vE,toBuffer:xl,unmask:vh};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=ue("bufferutil");Co.exports.mask=function(e,n,i,o,c){c<48?Eh(e,n,i,o,c):t.mask(e,n,i,o,c)},Co.exports.unmask=function(e,n){e.length<32?vh(e,n):t.unmask(e,n)}}catch{}});var Ah=ae((mC,Ih)=>{"use strict";var Sh=Symbol("kDone"),pl=Symbol("kRun"),gl=class{constructor(e){this[Sh]=()=>{this.pending--,this[pl]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[pl]()}[pl](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Sh])}}};Ih.exports=gl});var Ur=ae((wC,Ch)=>{"use strict";var Zi=ue("zlib"),Th=Ji(),SE=Ah(),{kStatusCode:kh}=Jt(),IE=Buffer[Symbol.species],AE=Buffer.from([0,0,255,255]),Do=Symbol("permessage-deflate"),Zt=Symbol("total-length"),Fr=Symbol("callback"),kn=Symbol("buffers"),zr=Symbol("error"),Po,ml=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,!Po){let n=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Po=new SE(n)}}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[Fr];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let n=this._options,i=e.find(o=>!(n.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(n.serverMaxWindowBits===!1||typeof n.serverMaxWindowBits=="number"&&n.serverMaxWindowBits>o.server_max_window_bits)||typeof n.clientMaxWindowBits=="number"&&!o.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return n.serverNoContextTakeover&&(i.server_no_context_takeover=!0),n.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof n.serverMaxWindowBits=="number"&&(i.server_max_window_bits=n.serverMaxWindowBits),typeof n.clientMaxWindowBits=="number"?i.client_max_window_bits=n.clientMaxWindowBits:(i.client_max_window_bits===!0||n.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let n=e[0];if(this._options.clientNoContextTakeover===!1&&n.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!n.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(n.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&n.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return n}normalizeParams(e){return e.forEach(n=>{Object.keys(n).forEach(i=>{let o=n[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}"`);n[i]=o})}),e}decompress(e,n,i){Po.add(o=>{this._decompress(e,n,(c,l)=>{o(),i(c,l)})})}compress(e,n,i){Po.add(o=>{this._compress(e,n,(c,l)=>{o(),i(c,l)})})}_decompress(e,n,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?Zi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Zi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:l}),this._inflate[Do]=this,this._inflate[Zt]=0,this._inflate[kn]=[],this._inflate.on("error",kE),this._inflate.on("data",Rh)}this._inflate[Fr]=i,this._inflate.write(e),n&&this._inflate.write(AE),this._inflate.flush(()=>{let c=this._inflate[zr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let l=Th.concat(this._inflate[kn],this._inflate[Zt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Zt]=0,this._inflate[kn]=[],n&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,l)})}_compress(e,n,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?Zi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Zi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:l}),this._deflate[Zt]=0,this._deflate[kn]=[],this._deflate.on("data",TE)}this._deflate[Fr]=i,this._deflate.write(e),this._deflate.flush(Zi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=Th.concat(this._deflate[kn],this._deflate[Zt]);n&&(c=new IE(c.buffer,c.byteOffset,c.length-4)),this._deflate[Fr]=null,this._deflate[Zt]=0,this._deflate[kn]=[],n&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};Ch.exports=ml;function TE(t){this[kn].push(t),this[Zt]+=t.length}function Rh(t){if(this[Zt]+=t.length,this[Do]._maxPayload<1||this[Zt]<=this[Do]._maxPayload){this[kn].push(t);return}this[zr]=new RangeError("Max payload size exceeded"),this[zr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[zr][kh]=1009,this.removeListener("data",Rh),this.reset()}function kE(t){if(this[Do]._inflate=null,this[zr]){this[Fr](this[zr]);return}t[kh]=1007,this[Fr](t)}});var Gr=ae((_C,Oo)=>{"use strict";var{isUtf8:Ph}=ue("buffer"),{hasBlob:RE}=Jt(),CE=[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 PE(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function wl(t){let e=t.length,n=0;for(;n<e;)if((t[n]&128)===0)n++;else if((t[n]&224)===192){if(n+1===e||(t[n+1]&192)!==128||(t[n]&254)===192)return!1;n+=2}else if((t[n]&240)===224){if(n+2>=e||(t[n+1]&192)!==128||(t[n+2]&192)!==128||t[n]===224&&(t[n+1]&224)===128||t[n]===237&&(t[n+1]&224)===160)return!1;n+=3}else if((t[n]&248)===240){if(n+3>=e||(t[n+1]&192)!==128||(t[n+2]&192)!==128||(t[n+3]&192)!==128||t[n]===240&&(t[n+1]&240)===128||t[n]===244&&t[n+1]>143||t[n]>244)return!1;n+=4}else return!1;return!0}function DE(t){return RE&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Oo.exports={isBlob:DE,isValidStatusCode:PE,isValidUTF8:wl,tokenChars:CE};if(Ph)Oo.exports.isValidUTF8=function(t){return t.length<24?wl(t):Ph(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=ue("utf-8-validate");Oo.exports.isValidUTF8=function(e){return e.length<32?wl(e):t(e)}}catch{}});var vl=ae((yC,Fh)=>{"use strict";var{Writable:OE}=ue("stream"),Dh=Ur(),{BINARY_TYPES:NE,EMPTY_BUFFER:Oh,kStatusCode:LE,kWebSocket:ME}=Jt(),{concat:_l,toArrayBuffer:BE,unmask:FE}=Ji(),{isValidStatusCode:zE,isValidUTF8:Nh}=Gr(),No=Buffer[Symbol.species],ht=0,Lh=1,Mh=2,Bh=3,yl=4,bl=5,Lo=6,El=class extends OE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||NE[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=e.maxBufferedChunks|0,this._maxFragments=e.maxFragments|0,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[ME]=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=ht}_write(e,n,i){if(this._opcode===8&&this._state==ht)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 No(i.buffer,i.byteOffset+e,i.length-e),new No(i.buffer,i.byteOffset,e)}let n=Buffer.allocUnsafe(e);do{let i=this._buffers[0],o=n.length-e;e>=i.length?n.set(this._buffers.shift(),o):(n.set(new Uint8Array(i.buffer,i.byteOffset,e),o),this._buffers[0]=new No(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return n}startLoop(e){this._loop=!0;do switch(this._state){case ht:this.getInfo(e);break;case Lh:this.getPayloadLength16(e);break;case Mh:this.getPayloadLength64(e);break;case Bh:this.getMask();break;case yl:this.getData(e);break;case bl:case Lo:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let n=this.consume(2);if((n[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=(n[0]&64)===64;if(i&&!this._extensions[Dh.extensionName]){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._fin=(n[0]&128)===128,this._opcode=n[0]&15,this._payloadLength=n[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=(n[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=Lh:this._payloadLength===127?this._state=Mh: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 n=this.consume(8),i=n.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)+n.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 n=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(n);return}this._masked?this._state=Bh:this._state=yl}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=yl}getData(e){let n=Oh;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}n=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&FE(n,this._mask)}if(this._opcode>7){this.controlMessage(n,e);return}if(this._compressed){this._state=bl,this.decompress(n,e);return}if(n.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(n)}this.dataMessage(e)}decompress(e,n){this._extensions[Dh.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return n(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let l=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");n(l);return}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let l=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");n(l);return}this._fragments.push(c)}this.dataMessage(n),this._state===ht&&this.startLoop(n)})}dataMessage(e){if(!this._fin){this._state=ht;return}let n=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=_l(i,n):this._binaryType==="arraybuffer"?o=BE(_l(i,n)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=ht):(this._state=Lo,setImmediate(()=>{this.emit("message",o,!0),this._state=ht,this.startLoop(e)}))}else{let o=_l(i,n);if(!this._skipUTF8Validation&&!Nh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===bl||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=ht):(this._state=Lo,setImmediate(()=>{this.emit("message",o,!1),this._state=ht,this.startLoop(e)}))}}controlMessage(e,n){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,Oh),this.end();else{let i=e.readUInt16BE(0);if(!zE(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");n(c);return}let o=new No(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!Nh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");n(c);return}this._loop=!1,this.emit("conclude",i,o),this.end()}this._state=ht;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=ht):(this._state=Lo,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=ht,this.startLoop(n)}))}createError(e,n,i,o,c){this._loop=!1,this._errored=!0;let l=new e(i?`Invalid WebSocket frame: ${n}`:n);return Error.captureStackTrace(l,this.createError),l.code=c,l[LE]=o,l}};Fh.exports=El});var Al=ae((EC,Gh)=>{"use strict";var{Duplex:bC}=ue("stream"),{randomFillSync:UE}=ue("crypto"),{types:{isUint8Array:GE}}=ue("util"),zh=Ur(),{EMPTY_BUFFER:qE,kWebSocket:HE,NOOP:jE}=Jt(),{isBlob:qr,isValidStatusCode:WE}=Gr(),{mask:Uh,toBuffer:Jn}=Ji(),xt=Symbol("kByteLength"),KE=Buffer.alloc(4),Mo=8*1024,Zn,Hr=Mo,vt=0,$E=1,VE=2,Sl=class t{constructor(e,n,i){this._extensions=n||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=vt,this.onerror=jE,this[HE]=void 0}static frame(e,n){let i,o=!1,c=2,l=!1;n.mask&&(i=n.maskBuffer||KE,n.generateMask?n.generateMask(i):(Hr===Mo&&(Zn===void 0&&(Zn=Buffer.alloc(Mo)),UE(Zn,0,Mo),Hr=0),i[0]=Zn[Hr++],i[1]=Zn[Hr++],i[2]=Zn[Hr++],i[3]=Zn[Hr++]),l=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!n.mask||l)&&n[xt]!==void 0?u=n[xt]:(e=Buffer.from(e),u=e.length):(u=e.length,o=n.mask&&n.readOnly&&!l);let h=u;u>=65536?(c+=8,h=127):u>125&&(c+=2,h=126);let x=Buffer.allocUnsafe(o?u+c:c);return x[0]=n.fin?n.opcode|128:n.opcode,n.rsv1&&(x[0]|=64),x[1]=h,h===126?x.writeUInt16BE(u,2):h===127&&(x[2]=x[3]=0,x.writeUIntBE(u,4,6)),n.mask?(x[1]|=128,x[c-4]=i[0],x[c-3]=i[1],x[c-2]=i[2],x[c-1]=i[3],l?[x,e]:o?(Uh(e,i,x,c,u),[x]):(Uh(e,i,e,0,u),[x,e])):[x,e]}close(e,n,i,o){let c;if(e===void 0)c=qE;else{if(typeof e!="number"||!WE(e))throw new TypeError("First argument must be a valid error code number");if(n===void 0||!n.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(n);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 n=="string")c.write(n,2);else if(GE(n))c.set(n,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let l={[xt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==vt?this.enqueue([this.dispatch,c,!1,l,o]):this.sendFrame(t.frame(c,l),o)}ping(e,n,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):qr(e)?(o=e.size,c=!1):(e=Jn(e),o=e.length,c=Jn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[xt]:o,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};qr(e)?this._state!==vt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==vt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}pong(e,n,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):qr(e)?(o=e.size,c=!1):(e=Jn(e),o=e.length,c=Jn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[xt]:o,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};qr(e)?this._state!==vt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==vt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}send(e,n,i){let o=this._extensions[zh.extensionName],c=n.binary?2:1,l=n.compress,u,h;typeof e=="string"?(u=Buffer.byteLength(e),h=!1):qr(e)?(u=e.size,h=!1):(e=Jn(e),u=e.length,h=Jn.readOnly),this._firstFragment?(this._firstFragment=!1,l&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(l=u>=o._threshold),this._compress=l):(l=!1,c=0),n.fin&&(this._firstFragment=!0);let x={[xt]:u,fin:n.fin,generateMask:this._generateMask,mask:n.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:h,rsv1:l};qr(e)?this._state!==vt?this.enqueue([this.getBlobData,e,this._compress,x,i]):this.getBlobData(e,this._compress,x,i):this._state!==vt?this.enqueue([this.dispatch,e,this._compress,x,i]):this.dispatch(e,this._compress,x,i)}getBlobData(e,n,i,o){this._bufferedBytes+=i[xt],this._state=VE,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(Il,this,u,o);return}this._bufferedBytes-=i[xt];let l=Jn(c);n?this.dispatch(l,n,i,o):(this._state=vt,this.sendFrame(t.frame(l,i),o),this.dequeue())}).catch(c=>{process.nextTick(JE,this,c,o)})}dispatch(e,n,i,o){if(!n){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[zh.extensionName];this._bufferedBytes+=i[xt],this._state=$E,c.compress(e,i.fin,(l,u)=>{if(this._socket.destroyed){let h=new Error("The socket was closed while data was being compressed");Il(this,h,o);return}this._bufferedBytes-=i[xt],this._state=vt,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===vt&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][xt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][xt],this._queue.push(e)}sendFrame(e,n){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],n),this._socket.uncork()):this._socket.write(e[0],n)}};Gh.exports=Sl;function Il(t,e,n){typeof n=="function"&&n(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 JE(t,e,n){Il(t,e,n),t.onerror(e)}});var Zh=ae((vC,Jh)=>{"use strict";var{kForOnEventAttribute:Yi,kListener:Tl}=Jt(),qh=Symbol("kCode"),Hh=Symbol("kData"),jh=Symbol("kError"),Wh=Symbol("kMessage"),Kh=Symbol("kReason"),jr=Symbol("kTarget"),$h=Symbol("kType"),Vh=Symbol("kWasClean"),Yt=class{constructor(e){this[jr]=null,this[$h]=e}get target(){return this[jr]}get type(){return this[$h]}};Object.defineProperty(Yt.prototype,"target",{enumerable:!0});Object.defineProperty(Yt.prototype,"type",{enumerable:!0});var Yn=class extends Yt{constructor(e,n={}){super(e),this[qh]=n.code===void 0?0:n.code,this[Kh]=n.reason===void 0?"":n.reason,this[Vh]=n.wasClean===void 0?!1:n.wasClean}get code(){return this[qh]}get reason(){return this[Kh]}get wasClean(){return this[Vh]}};Object.defineProperty(Yn.prototype,"code",{enumerable:!0});Object.defineProperty(Yn.prototype,"reason",{enumerable:!0});Object.defineProperty(Yn.prototype,"wasClean",{enumerable:!0});var Wr=class extends Yt{constructor(e,n={}){super(e),this[jh]=n.error===void 0?null:n.error,this[Wh]=n.message===void 0?"":n.message}get error(){return this[jh]}get message(){return this[Wh]}};Object.defineProperty(Wr.prototype,"error",{enumerable:!0});Object.defineProperty(Wr.prototype,"message",{enumerable:!0});var Xi=class extends Yt{constructor(e,n={}){super(e),this[Hh]=n.data===void 0?null:n.data}get data(){return this[Hh]}};Object.defineProperty(Xi.prototype,"data",{enumerable:!0});var ZE={addEventListener(t,e,n={}){for(let o of this.listeners(t))if(!n[Yi]&&o[Tl]===e&&!o[Yi])return;let i;if(t==="message")i=function(c,l){let u=new Xi("message",{data:l?c:c.toString()});u[jr]=this,Bo(e,this,u)};else if(t==="close")i=function(c,l){let u=new Yn("close",{code:c,reason:l.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[jr]=this,Bo(e,this,u)};else if(t==="error")i=function(c){let l=new Wr("error",{error:c,message:c.message});l[jr]=this,Bo(e,this,l)};else if(t==="open")i=function(){let c=new Yt("open");c[jr]=this,Bo(e,this,c)};else return;i[Yi]=!!n[Yi],i[Tl]=e,n.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let n of this.listeners(t))if(n[Tl]===e&&!n[Yi]){this.removeListener(t,n);break}}};Jh.exports={CloseEvent:Yn,ErrorEvent:Wr,Event:Yt,EventTarget:ZE,MessageEvent:Xi};function Bo(t,e,n){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,n):t.call(e,n)}});var Fo=ae((SC,Yh)=>{"use strict";var{tokenChars:Qi}=Gr();function Lt(t,e,n){t[e]===void 0?t[e]=[n]:t[e].push(n)}function YE(t){let e=Object.create(null),n=Object.create(null),i=!1,o=!1,c=!1,l,u,h=-1,x=-1,m=-1,_=0;for(;_<t.length;_++)if(x=t.charCodeAt(_),l===void 0)if(m===-1&&Qi[x]===1)h===-1&&(h=_);else if(_!==0&&(x===32||x===9))m===-1&&h!==-1&&(m=_);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${_}`);m===-1&&(m=_);let y=t.slice(h,m);x===44?(Lt(e,y,n),n=Object.create(null)):l=y,h=m=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);else if(u===void 0)if(m===-1&&Qi[x]===1)h===-1&&(h=_);else if(x===32||x===9)m===-1&&h!==-1&&(m=_);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${_}`);m===-1&&(m=_),Lt(n,t.slice(h,m),!0),x===44&&(Lt(e,l,n),n=Object.create(null),l=void 0),h=m=-1}else if(x===61&&h!==-1&&m===-1)u=t.slice(h,_),h=m=-1;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(o){if(Qi[x]!==1)throw new SyntaxError(`Unexpected character at index ${_}`);h===-1?h=_:i||(i=!0),o=!1}else if(c)if(Qi[x]===1)h===-1&&(h=_);else if(x===34&&h!==-1)c=!1,m=_;else if(x===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(x===34&&t.charCodeAt(_-1)===61)c=!0;else if(m===-1&&Qi[x]===1)h===-1&&(h=_);else if(h!==-1&&(x===32||x===9))m===-1&&(m=_);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${_}`);m===-1&&(m=_);let y=t.slice(h,m);i&&(y=y.replace(/\\/g,""),i=!1),Lt(n,u,y),x===44&&(Lt(e,l,n),n=Object.create(null),l=void 0),u=void 0,h=m=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);if(h===-1||c||x===32||x===9)throw new SyntaxError("Unexpected end of input");m===-1&&(m=_);let S=t.slice(h,m);return l===void 0?Lt(e,S,n):(u===void 0?Lt(n,S,!0):i?Lt(n,u,S.replace(/\\/g,"")):Lt(n,u,S),Lt(e,l,n)),e}function XE(t){return Object.keys(t).map(e=>{let n=t[e];return Array.isArray(n)||(n=[n]),n.map(i=>[e].concat(Object.keys(i).map(o=>{let c=i[o];return Array.isArray(c)||(c=[c]),c.map(l=>l===!0?o:`${o}=${l}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Yh.exports={format:XE,parse:YE}});var qo=ae((TC,lx)=>{"use strict";var QE=ue("events"),ev=ue("https"),tv=ue("http"),ex=ue("net"),nv=ue("tls"),{randomBytes:rv,createHash:iv}=ue("crypto"),{Duplex:IC,Readable:AC}=ue("stream"),{URL:kl}=ue("url"),Rn=Ur(),sv=vl(),ov=Al(),{isBlob:av}=Gr(),{BINARY_TYPES:Xh,CLOSE_TIMEOUT:cv,EMPTY_BUFFER:zo,GUID:lv,kForOnEventAttribute:Rl,kListener:dv,kStatusCode:uv,kWebSocket:He,NOOP:tx}=Jt(),{EventTarget:{addEventListener:fv,removeEventListener:hv}}=Zh(),{format:xv,parse:pv}=Fo(),{toBuffer:gv}=Ji(),nx=Symbol("kAborted"),Cl=[8,13],Xt=["CONNECTING","OPEN","CLOSING","CLOSED"],mv=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,we=class t extends QE{constructor(e,n,i){super(),this._binaryType=Xh[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=zo,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,n===void 0?n=[]:Array.isArray(n)||(typeof n=="object"&&n!==null?(i=n,n=[]):n=[n]),rx(this,e,n,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Xh.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,n,i){let o=new sv({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 ov(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[He]=this,c[He]=this,e[He]=this,o.on("conclude",yv),o.on("drain",bv),o.on("error",Ev),o.on("message",vv),o.on("ping",Sv),o.on("pong",Iv),c.onerror=Av,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),n.length>0&&e.unshift(n),e.on("close",ox),e.on("data",Go),e.on("end",ax),e.on("error",cx),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[Rn.extensionName]&&this._extensions[Rn.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,n){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){at(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,n,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),sx(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,n,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=n=void 0):typeof n=="function"&&(i=n,n=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pl(this,e,i);return}n===void 0&&(n=!this._isServer),this._sender.ping(e||zo,n,i)}pong(e,n,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=n=void 0):typeof n=="function"&&(i=n,n=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pl(this,e,i);return}n===void 0&&(n=!this._isServer),this._sender.pong(e||zo,n,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,n,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof n=="function"&&(i=n,n={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Pl(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...n};this._extensions[Rn.extensionName]||(o.compress=!1),this._sender.send(e||zo,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){at(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(we,"CONNECTING",{enumerable:!0,value:Xt.indexOf("CONNECTING")});Object.defineProperty(we.prototype,"CONNECTING",{enumerable:!0,value:Xt.indexOf("CONNECTING")});Object.defineProperty(we,"OPEN",{enumerable:!0,value:Xt.indexOf("OPEN")});Object.defineProperty(we.prototype,"OPEN",{enumerable:!0,value:Xt.indexOf("OPEN")});Object.defineProperty(we,"CLOSING",{enumerable:!0,value:Xt.indexOf("CLOSING")});Object.defineProperty(we.prototype,"CLOSING",{enumerable:!0,value:Xt.indexOf("CLOSING")});Object.defineProperty(we,"CLOSED",{enumerable:!0,value:Xt.indexOf("CLOSED")});Object.defineProperty(we.prototype,"CLOSED",{enumerable:!0,value:Xt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(we.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(we.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Rl])return e[dv];return null},set(e){for(let n of this.listeners(t))if(n[Rl]){this.removeListener(t,n);break}typeof e=="function"&&this.addEventListener(t,e,{[Rl]:!0})}})});we.prototype.addEventListener=fv;we.prototype.removeEventListener=hv;lx.exports=we;function rx(t,e,n,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:cv,protocolVersion:Cl[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,!Cl.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Cl.join(", ")})`);let c;if(e instanceof kl)c=e;else try{c=new kl(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let l=c.protocol==="wss:",u=c.protocol==="ws+unix:",h;if(c.protocol!=="ws:"&&!l&&!u?h=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?h="The URL's pathname is empty":c.hash&&(h="The URL contains a fragment identifier"),h){let I=new SyntaxError(h);if(t._redirects===0)throw I;Uo(t,I);return}let x=l?443:80,m=rv(16).toString("base64"),_=l?ev.request:tv.request,S=new Set,y;if(o.createConnection=o.createConnection||(l?_v:wv),o.defaultPort=o.defaultPort||x,o.port=c.port||x,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":m,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(y=new Rn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=xv({[Rn.extensionName]:y.offer()})),n.length){for(let I of n){if(typeof I!="string"||!mv.test(I)||S.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");S.add(I)}o.headers["Sec-WebSocket-Protocol"]=n.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),u){let I=o.path.split(":");o.socketPath=I[0],o.path=I[1]}let v;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=l,t._originalHostOrSocketPath=u?o.socketPath:c.host;let I=i&&i.headers;if(i={...i,headers:{}},I)for(let[A,k]of Object.entries(I))i.headers[A.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&&!l)&&(delete o.headers.authorization,delete o.headers.cookie,I||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),v=t._req=_(o),t._redirects&&t.emit("redirect",t.url,v)}else v=t._req=_(o);o.timeout&&v.on("timeout",()=>{at(t,v,"Opening handshake has timed out")}),v.on("error",I=>{v===null||v[nx]||(v=t._req=null,Uo(t,I))}),v.on("response",I=>{let A=I.headers.location,k=I.statusCode;if(A&&o.followRedirects&&k>=300&&k<400){if(++t._redirects>o.maxRedirects){at(t,v,"Maximum redirects exceeded");return}v.abort();let P;try{P=new kl(A,e)}catch{let R=new SyntaxError(`Invalid URL: ${A}`);Uo(t,R);return}rx(t,P,n,i)}else t.emit("unexpected-response",v,I)||at(t,v,`Unexpected server response: ${I.statusCode}`)}),v.on("upgrade",(I,A,k)=>{if(t.emit("upgrade",I),t.readyState!==we.CONNECTING)return;v=t._req=null;let P=I.headers.upgrade;if(P===void 0||P.toLowerCase()!=="websocket"){at(t,A,"Invalid Upgrade header");return}let b=iv("sha1").update(m+lv).digest("base64");if(I.headers["sec-websocket-accept"]!==b){at(t,A,"Invalid Sec-WebSocket-Accept header");return}let R=I.headers["sec-websocket-protocol"],O;if(R!==void 0?S.size?S.has(R)||(O="Server sent an invalid subprotocol"):O="Server sent a subprotocol but none was requested":S.size&&(O="Server sent no subprotocol"),O){at(t,A,O);return}R&&(t._protocol=R);let B=I.headers["sec-websocket-extensions"];if(B!==void 0){if(!y){at(t,A,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let M;try{M=pv(B)}catch{at(t,A,"Invalid Sec-WebSocket-Extensions header");return}let V=Object.keys(M);if(V.length!==1||V[0]!==Rn.extensionName){at(t,A,"Server indicated an extension that was not requested");return}try{y.accept(M[Rn.extensionName])}catch{at(t,A,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[Rn.extensionName]=y}t.setSocket(A,k,{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 Uo(t,e){t._readyState=we.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function wv(t){return t.path=t.socketPath,ex.connect(t)}function _v(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=ex.isIP(t.host)?"":t.host),nv.connect(t)}function at(t,e,n){t._readyState=we.CLOSING;let i=new Error(n);Error.captureStackTrace(i,at),e.setHeader?(e[nx]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Uo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Pl(t,e,n){if(e){let i=av(e)?e.size:gv(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(n){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Xt[t.readyState]})`);process.nextTick(n,i)}}function yv(t,e){let n=this[He];n._closeFrameReceived=!0,n._closeMessage=e,n._closeCode=t,n._socket[He]!==void 0&&(n._socket.removeListener("data",Go),process.nextTick(ix,n._socket),t===1005?n.close():n.close(t,e))}function bv(){let t=this[He];t.isPaused||t._socket.resume()}function Ev(t){let e=this[He];e._socket[He]!==void 0&&(e._socket.removeListener("data",Go),process.nextTick(ix,e._socket),e.close(t[uv])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Qh(){this[He].emitClose()}function vv(t,e){this[He].emit("message",t,e)}function Sv(t){let e=this[He];e._autoPong&&e.pong(t,!this._isServer,tx),e.emit("ping",t)}function Iv(t){this[He].emit("pong",t)}function ix(t){t.resume()}function Av(t){let e=this[He];e.readyState!==we.CLOSED&&(e.readyState===we.OPEN&&(e._readyState=we.CLOSING,sx(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function sx(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function ox(){let t=this[He];if(this.removeListener("close",ox),this.removeListener("data",Go),this.removeListener("end",ax),t._readyState=we.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[He]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Qh),t._receiver.on("finish",Qh))}function Go(t){this[He]._receiver.write(t)||this.pause()}function ax(){let t=this[He];t._readyState=we.CLOSING,t._receiver.end(),this.end()}function cx(){let t=this[He];this.removeListener("error",cx),this.on("error",tx),t&&(t._readyState=we.CLOSING,this.destroy())}});var hx=ae((RC,fx)=>{"use strict";var kC=qo(),{Duplex:Tv}=ue("stream");function dx(t){t.emit("close")}function kv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function ux(t){this.removeListener("error",ux),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function Rv(t,e){let n=!0,i=new Tv({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,l){let u=!l&&i._readableState.objectMode?c.toString():c;i.push(u)||t.pause()}),t.once("error",function(c){i.destroyed||(n=!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(dx,i);return}let l=!1;t.once("error",function(h){l=!0,c(h)}),t.once("close",function(){l||c(o),process.nextTick(dx,i)}),n&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,l){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,l)});return}t.send(o,l)},i.on("end",kv),i.on("error",ux),i}fx.exports=Rv});var Dl=ae((CC,xx)=>{"use strict";var{tokenChars:Cv}=Gr();function Pv(t){let e=new Set,n=-1,i=-1,o=0;for(o;o<t.length;o++){let l=t.charCodeAt(o);if(i===-1&&Cv[l]===1)n===-1&&(n=o);else if(o!==0&&(l===32||l===9))i===-1&&n!==-1&&(i=o);else if(l===44){if(n===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let u=t.slice(n,i);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);e.add(u),n=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(n===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(n,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}xx.exports={parse:Pv}});var Ex=ae((DC,bx)=>{"use strict";var Dv=ue("events"),Ho=ue("http"),{Duplex:PC}=ue("stream"),{createHash:Ov}=ue("crypto"),px=Fo(),Xn=Ur(),Nv=Dl(),Lv=qo(),{CLOSE_TIMEOUT:Mv,GUID:Bv,kWebSocket:Fv}=Jt(),zv=/^[+/0-9A-Za-z]{22}==$/,gx=0,mx=1,yx=2,Ol=class extends Dv{constructor(e,n){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:Mv,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=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,n)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=Uv(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(o,c,l)=>{this.handleUpgrade(o,c,l,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=gx}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===yx){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(es,this);return}if(e&&this.once("close",e),this._state!==mx)if(this._state=mx,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(es,this):process.nextTick(es,this);else{let n=this._server;this._removeListeners(),this._removeListeners=this._server=null,n.close(()=>{es(this)})}}shouldHandle(e){if(this.options.path){let n=e.url.indexOf("?");if((n!==-1?e.url.slice(0,n):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,n,i,o){n.on("error",_x);let c=e.headers["sec-websocket-key"],l=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Qn(this,e,n,405,"Invalid HTTP method");return}if(l===void 0||l.toLowerCase()!=="websocket"){Qn(this,e,n,400,"Invalid Upgrade header");return}if(c===void 0||!zv.test(c)){Qn(this,e,n,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){Qn(this,e,n,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){ts(n,400);return}let h=e.headers["sec-websocket-protocol"],x=new Set;if(h!==void 0)try{x=Nv.parse(h)}catch{Qn(this,e,n,400,"Invalid Sec-WebSocket-Protocol header");return}let m=e.headers["sec-websocket-extensions"],_={};if(this.options.perMessageDeflate&&m!==void 0){let S=new Xn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let y=px.parse(m);y[Xn.extensionName]&&(S.accept(y[Xn.extensionName]),_[Xn.extensionName]=S)}catch{Qn(this,e,n,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,(y,v,I,A)=>{if(!y)return ts(n,v||401,I,A);this.completeUpgrade(_,c,x,e,n,i,o)});return}if(!this.options.verifyClient(S))return ts(n,401)}this.completeUpgrade(_,c,x,e,n,i,o)}completeUpgrade(e,n,i,o,c,l,u){if(!c.readable||!c.writable)return c.destroy();if(c[Fv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>gx)return ts(c,503);let x=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Ov("sha1").update(n+Bv).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;_&&(x.push(`Sec-WebSocket-Protocol: ${_}`),m._protocol=_)}if(e[Xn.extensionName]){let _=e[Xn.extensionName].params,S=px.format({[Xn.extensionName]:[_]});x.push(`Sec-WebSocket-Extensions: ${S}`),m._extensions=e}this.emit("headers",x,o),c.write(x.concat(`\r
15
15
  `).join(`\r
16
- `)),c.removeListener("error",Rh),p.setSocket(c,d,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(p),p.on("close",()=>{this.clients.delete(p),this._shouldEmitClose&&!this.clients.size&&process.nextTick(ns,this)})),u(p,o)}};Ph.exports=Wd;function hS(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 ns(t){t._state=Dh,t.emit("close")}function Rh(){this.destroy()}function rs(t,e,r,i){r=r||Zo.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${Zo.STATUS_CODES[e]}\r
16
+ `)),c.removeListener("error",_x),m.setSocket(c,l,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxBufferedChunks:this.options.maxBufferedChunks,maxFragments:this.options.maxFragments,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(m),m.on("close",()=>{this.clients.delete(m),this._shouldEmitClose&&!this.clients.size&&process.nextTick(es,this)})),u(m,o)}};bx.exports=Ol;function Uv(t,e){for(let n of Object.keys(e))t.on(n,e[n]);return function(){for(let i of Object.keys(e))t.removeListener(i,e[i])}}function es(t){t._state=yx,t.emit("close")}function _x(){this.destroy()}function ts(t,e,n,i){n=n||Ho.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(n),...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 rr(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let d=new Error(o);Error.captureStackTrace(d,rr),t.emit("wsClientError",d,r,e)}else rs(r,i,o,c)}});var Kh=de(be=>{"use strict";var N=F;(function(t,e){let r=F,i=t();for(;;)try{if(parseInt(r(1063))/1+parseInt(r(925))/2*(parseInt(r(1503))/3)+parseInt(r(1949))/4*(-parseInt(r(813))/5)+-parseInt(r(1835))/6*(-parseInt(r(595))/7)+parseInt(r(1599))/8+parseInt(r(1562))/9+-parseInt(r(1592))/10===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(ra,923645);var ES=Object["definePr"+N(1416)],vS=Object[N(1472)+N(357)+N(844)],Hh=(t,e)=>function(){return t&&(e=(0,t[{CHSQQ:function(o,c){return o(c)}}.CHSQQ(vS,t)[0]])(t=0)),e},SS=(t,e)=>{let r={PjlKv:function(o,c,d,u){return o(c,d,u)}};for(var i in e)r.PjlKv(ES,t,i,{get:e[i],enumerable:!0})};function AS(){return Mh||(Mh=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function IS(){let t=N;return Bh||(Bh=[IDBCursor.prototype[t(532)],IDBCursor[t(1471)+"e"].continue,IDBCursor[t(1471)+"e"][t(929)+t(935)+"ey"]])}function kS(t){let e=N,r={uAhia:function(o,c){return o(c)},hQwIY:function(o){return o()},LvqvU:function(o){return o()},jgnKp:e(1667),PWijB:e(1035),roaBT:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let d=e,u={PilxB:r[d(832)],rqVdF:r[d(1873)]},x=()=>{let _=d;t[_(1100)+_(1790)+_(1429)](u[_(1689)],h),t["removeEv"+_(1790)+_(1429)](u[_(723)],p)},h=()=>{let _=d;r[_(1166)](o,zt(t[_(847)])),r[_(1976)](x)},p=()=>{let _=d;r[_(1166)](c,t[_(1035)]),r[_(1691)](x)};t[d(1258)+d(1745)](r[d(832)],h),t[d(1258)+"Listener"](r[d(1873)],p)});return i[e(1941)](o=>{let c=e;r[c(911)](o,IDBCursor)&&$d[c(1777)](o,t)})[e(1327)](()=>{}),ta[e(1777)](i,t),i}function TS(t){let e=N,r={WJBWw:e(1076),knHQi:e(1035),agJja:e(786),uabxi:function(o,c){return o(c)},yLaKh:e(1286)+"or"};if(ea[e(1866)](t))return;let i=new Promise((o,c)=>{let d=e,u={EXvvx:function(_,S){return r[F(1073)](_,S)},HVcvi:r[d(1721)],iEirs:function(_){return _()}},x=()=>{let _=d;t[_(1100)+_(1790)+_(1429)](r[_(1082)],h),t[_(1100)+_(1790)+_(1429)](r[_(1432)],p),t["removeEv"+_(1790)+"ner"](r.agJja,p)},h=()=>{o(),x()},p=()=>{let _=d;u[_(1482)](c,t[_(1035)]||new DOMException(_(1286)+"or",u.HVcvi)),u[_(1854)](x)};t[d(1258)+d(1745)](r[d(1082)],h),t[d(1258)+d(1745)](r[d(1432)],p),t[d(1258)+d(1745)](r[d(547)],p)});ea[e(1777)](t,i)}function CS(t){na={iMXnZ:function(i,o){return i(o)}}[N(1579)](t,na)}function RS(t){let e=N,r={ueTBy:function(i,o){return i(o)},kbUbg:function(i,o){return i==o},jRWmq:e(1419),vVJEG:function(i,o,c,d){return i(o,c,d)},nrPWE:function(i,o){return i!==o},clhJT:e(497),JCqZA:function(i,o){return i(o)},wqEAp:function(i,o,c){return i(o,c)},MERZs:function(i,o){return i(o)},GqjAr:function(i,o){return i===o},vHQpz:e(1232),NKjYJ:function(i,o){return i(o)},FfrOV:function(i,o){return i===o},CLwxa:function(i,o){return i in o}};return r[e(763)](t,IDBDatabase.prototype[e(699)+e(1067)])&&!r[e(1088)](e(1222)+e(760),IDBTransaction[e(1471)+"e"])?function(i,...o){let c=e,d=t.call(r[c(790)](is,this),i,...o);return Kd[c(1777)](d,i[c(586)]?i[c(586)]():[i]),zt(d)}:IS()[e(1555)](t)?function(...i){let o=e,c={CrXCp:function(d,u){return r[F(709)](d,u)},kzgDc:r[o(636)],NVctH:function(d,u,x,h){return r[o(1649)](d,u,x,h)},uhAwB:function(d,u){return d instanceof u}};if(r[o(648)](r[o(1960)],r[o(1960)])){if(c[o(391)](c[o(1794)],typeof _0x487cf0)){let d=new _0x1b9ff8(_0x19bbd5(_0x5dc69d));return c[o(1224)](_0x19b592,_0x38181d,d,0),d}return c[o(553)](_0x40ed23,_0x2fca9f)?new _0xbb06b9(_0x1284f7):new _0x2d4702(_0x28fc25[o(1115)],_0x46ff9d[o(1841)+"et"],_0x2501ee[o(1516)+"th"])}else return t[o(1156)](r[o(927)](is,this),i),zt($d.get(this))}:function(...i){let o=e;if(r[o(1582)]("QoaDV",r.vHQpz))return r[o(1895)](zt,t[o(1156)](r[o(790)](is,this),i));{let c=_0x104333();return r[o(1707)](_0x341011,_0x1821c2,c),r[o(1576)](_0xa55e54,c)}}}function DS(t){let e=N,r={FtiRI:function(i,o){return i===o},zCokb:e(746),EMFnj:function(i,o){return i(o)},QtXkA:function(i,o){return i instanceof o},DWHqZ:function(i,o,c){return i(o,c)},YBWXP:function(i){return i()}};return r[e(1195)](typeof t,r[e(670)])?r[e(1201)](RS,t):(r.QtXkA(t,IDBTransaction)&&r[e(1201)](TS,t),r.DWHqZ(Gh,t,r[e(1571)](AS))?new Proxy(t,na):t)}function zt(t){let e=N,r={oCYzY:function(o,c){return o instanceof c},YGcVh:function(o,c){return o(c)},yGyqR:function(o,c){return o(c)},pOTJU:function(o,c){return o!==c},ScoBu:function(o,c){return o!==c},wxCit:e(1220)};if(t instanceof IDBRequest)return r[e(779)](kS,t);if(Yo[e(1866)](t))return Yo.get(t);let i=DS(t);if(r[e(737)](i,t))if(r[e(1898)](r[e(377)],r[e(377)])){if(r.oCYzY(_0x527167,_0x1af3b5))return r[e(708)](_0x38b1d8,_0x33e076);if(_0x5f27f4[e(1866)](_0x54840f))return _0x5c5a46[e(626)](_0x111b70);let o=r[e(779)](_0x2f124e,_0x5bdf11);return r[e(737)](o,_0x33a098)&&(_0x465c0c[e(1777)](_0x5bd76b,o),_0x4c8fdd[e(1777)](o,_0x5662de)),o}else Yo[e(1777)](t,i),ta[e(1777)](i,t);return i}var Gh,Mh,Bh,$d,ea,Kd,Yo,ta,na,is,Fh=Hh({"node_modules/idb/build/wrap-idb-value.js"(){let t=N,e={vLsPm:function(r,i){return r instanceof i},vPoui:function(r,i){return r===i},vjCcT:t(1222)+t(760),hgFQH:function(r,i){return r!==i},tCTkk:t(1913),MnINB:t(1967),fXGQs:"store",SXspv:function(r,i){return r(i)},NOApZ:t(364),KpHAX:function(r,i){return r instanceof i},WkBQl:"done",XqwJI:function(r,i){return r===i},IVLRf:function(r,i){return r in i}};Gh=(r,i)=>i.some(o=>r instanceof o),$d=new WeakMap,ea=new WeakMap,Kd=new WeakMap,Yo=new WeakMap,ta=new WeakMap,na={get(r,i,o){let c=t,d={nRUHQ:c(1791)};if(e[c(665)](r,IDBTransaction)){if(i==="done")return ea[c(626)](r);if(e[c(525)](i,e[c(1014)])){if(e[c(1889)](e[c(1091)],e[c(767)]))return r[c(1222)+c(760)]||Kd[c(626)](r);this._ws&&this[c(1703)][c(1751)](_0x55d5db),this[c(389)](d[c(422)],_0x110104)}if(e[c(525)](i,e[c(1105)]))return o[c(1222)+c(760)][1]?void 0:o.objectStore(o[c(1222)+"oreNames"][0])}return e[c(1940)](zt,r[i])},set(r,i,o){let c=t,d={SWQRb:function(u,x,h){return u(x,h)},cBPXm:c(1978)};if(e[c(525)](e[c(808)],e[c(808)]))return r[i]=o,!0;{let u=this[c(1870)+"tManager"]?.[c(560)+c(573)+"nt"]();this[c(769)+c(1032)+c(1652)](d[c(1491)](_0x204f0b,d[c(1847)],{code:1006,reason:c(1203)+u+(" timeout"+c(644)+c(947)+c(1092)),wasClean:!0}))}},has(r,i){let o=t;return e[o(1545)](r,IDBTransaction)&&(e.vPoui(i,e.WkBQl)||e.XqwJI(i,e[o(1105)]))?!0:e[o(1572)](i,r)}},is=r=>ta.get(r)}}),qh={};SS(qh,{deleteDB:()=>OS,openDB:()=>PS,unwrap:()=>is,wrap:()=>zt});function PS(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let d=N,u={UPQke:function(p,_,S,y,v){return p(_,S,y,v)},hCblN:function(p,_){return p(_)},YUOuT:d(773)+d(785),UCgwh:function(p,_){return p(_)},xvaBD:d(466)+"eeded",Gshyd:"blocked"},x=indexedDB[d(899)](t,e),h=u.UCgwh(zt,x);return i&&x["addEvent"+d(1745)](u[d(1372)],p=>{let _=d;u.UPQke(i,u[_(1174)](zt,x[_(847)]),p.oldVersion,p.newVersion,zt(x[_(699)+_(1067)]))}),r&&x[d(1258)+d(1745)](u.Gshyd,()=>r()),h.then(p=>{let _=d;c&&p[_(1258)+_(1745)](_(1978),()=>c()),o&&p[_(1258)+"Listener"](u[_(1494)],()=>o())})[d(1327)](()=>{}),h}function OS(t,{blocked:e}={}){let r=N,i={vcXPH:"blocked",Ccjmb:function(c,d){return c(d)}},o=indexedDB[r(872)+"tabase"](t);return e&&o[r(1258)+r(1745)](i[r(510)],()=>e()),i[r(1157)](zt,o)[r(1941)](()=>{})}function F(t,e){t=t-348;let r=ra(),i=r[t];if(F.DsrNey===void 0){var o=function(x){let h="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",p="",_="";for(let S=0,y,v,A=0;v=x.charAt(A++);~v&&(y=S%4?y*64+v:v,S++%4)?p+=String.fromCharCode(255&y>>(-2*S&6)):0)v=h.indexOf(v);for(let S=0,y=p.length;S<y;S++)_+="%"+("00"+p.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(_)};F.UcjChS=o,F.xfFnkR={},F.DsrNey=!0}let c=r[0],d=t+c,u=F.xfFnkR[d];return u?i=u:(i=F.UcjChS(i),F.xfFnkR[d]=i),i}function zh(t,e){let r=N,i={xBNet:r(1959)+"e",HGqur:r(1797),widjM:function(x,h){return x instanceof h},paYIu:function(x,h){return x in h},ViIaM:function(x,h){return x===h},CKYHy:r(1419),hPMBQ:function(x,h){return x!==h}};if(!(i[r(851)](t,IDBDatabase)&&!i[r(1573)](e,t)&&i[r(462)](typeof e,i[r(1051)])))return;if(Qo[r(626)](e))return Qo[r(626)](e);let o=e[r(865)](/FromIndex$/,""),c=i.hPMBQ(e,o),d=Wh[r(1555)](o);if(!(o in(c?IDBIndex:IDBObjectStore)[r(1471)+"e"])||!(d||jh[r(1555)](o)))return;let u=async function(x,...h){let p=r,_=this["transact"+p(1067)](x,d?i[p(486)]:i[p(1212)]),S=_[p(1364)];return c&&(S=S[p(1433)](h[p(1468)]())),(await Promise[p(1134)]([S[o](...h),d&&_[p(611)]]))[0]};return Qo[r(1777)](e,u),u}var jh,Wh,Qo,LS=Hh({"node_modules/idb/build/index.js"(){let t=N,e={MbjvF:t(1824)+t(604),iJzMT:function(o){return o()},haoqF:"get",IxzBw:t(1296)+"ys",Wpesm:t(1360),ioptr:t(492),OsglA:t(524),SHZww:t(744),fjvvh:t(749)},r=e[t(1611)][t(1916)]("|"),i=0;for(;;){switch(r[i++]){case"0":e.iJzMT(Fh);continue;case"1":jh=[e[t(1308)],t(1487),"getAll",e.IxzBw,e[t(1765)]];continue;case"2":CS(o=>({...o,get:(c,d,u)=>zh(c,d)||o.get(c,d,u),has:(c,d)=>!!zh(c,d)||o.has(c,d)}));continue;case"3":Qo=new Map;continue;case"4":Wh=[e[t(1022)],e[t(969)],e[t(753)],e[t(752)]];continue;case"5":Fh();continue}break}}}),NS={idb:function(t){let e=N;t.exports=Promise.resolve()[e(1941)](()=>(LS(),qh))[e(1941)](function(r){return r})}},Uh={};function Ft(t){let e=N,r={hcKgQ:function(u,x){return u!==x}},i=(e(1846)+"0")[e(1916)]("|"),o=0;for(;;){switch(i[o++]){case"0":return c.exports;case"1":var c=Uh[t]={exports:{}};continue;case"2":if(r[e(1658)](void 0,d))return d[e(1894)];continue;case"3":NS[t](c,c.exports,Ft);continue;case"4":var d=Uh[t];continue}break}}(()=>{let t=N,e={lvZZl:function(r,i,o){return r(i,o)},vggmi:t(1730)+t(1766),tTCwU:function(r,i){return r!==i},wQVrH:t(1388),yKTVC:t(896)};Ft.d=(r,i)=>{let o=t,c={gZQdI:function(u,x,h){return e[F(1983)](u,x,h)},JskOc:e[o(1694)]};if(e.tTCwU(e[o(934)],e[o(1427)]))for(var d in i)Ft.o(i,d)&&!Ft.o(r,d)&&Object[o(1228)+o(1416)](r,d,{enumerable:!0,get:i[d]});else be[o(1504)+"ameSpace"]=_0x24fa71,be[o(1994)+o(1243)]=_0x18bf4a,be[o(856)+"Strategy"]=_0x3702a0,be[o(1880)]=c[o(2002)](_0x2cc7a4,be[o(1504)+o(1788)],c.JskOc)}})(),(()=>{let t=N;Ft.o=(e,r)=>Object[t(1471)+"e"][t(468)+t(1416)][t(913)](e,r)})(),(()=>{let t=N,e={KTgel:"undefined",aRYHZ:t(672),FuTbb:t(1450)+"le"};Ft.r=r=>{let i=t;e[i(641)]!=typeof Symbol&&Symbol[i(1767)+i(1527)]&&Object[i(1228)+"operty"](r,Symbol["toString"+i(1527)],{value:e[i(2003)]}),Object[i(1228)+i(1416)](r,e[i(518)],{value:!0})}})();var Ne={};(()=>{let t=N,e={VJfwP:function(a,n){return a(n)},HoFxs:function(a,n){return a+n},uzKLB:function(a,n){return a*n},bWLwj:function(a,n,s){return a(n,s)},Cdynf:function(a,n){return a!==n},xkDXG:t(908),uaNrH:function(a,n){return a(n)},lcxXp:function(a,n){return a<<n},TzFNP:function(a,n){return a&n},CsHJA:function(a,n){return a===n},yqTXh:t(1995),FzTNt:function(a,n){return a+n},CFczo:function(a,n){return a(n)},bXLlL:function(a,n){return a+n},rzjTX:t(1165),foOub:function(a,n){return a(n)},dFwkG:t(855)+t(855)+t(855)+"00000000",NYuit:function(a,n){return a&n},vJXyh:function(a,n){return a>>n},VVlwX:function(a,n){return a|n},cjSDA:function(a,n){return a>>n},nndmJ:function(a,n){return a<n},aadIO:function(a,n){return a>n},nTqcj:function(a,n){return a-n},IZMEI:function(a,n){return a!==n},PqSAM:function(a,n){return a===n},WAjyq:t(882),HVwIK:t(803),kfnGb:function(a,n){return a-n},PlBVK:function(a,n){return a<n},MPwAA:function(a,n){return a-n},cnXlS:function(a,n){return a<n},bkhfK:function(a,n){return a===n},UKVMe:t(679),tsDPM:function(a,n){return a!==n},iVyil:function(a,n){return a!==n},tZSbQ:t(1500),kpZql:function(a,n,s){return a(n,s)},itENx:function(a,n){return a(n)},PaYuO:function(a,n){return a>>>n},xasre:function(a,n,s){return a(n,s)},RuvMv:t(574)+t(536)+t(1699)+t(1107),NUgNg:function(a,n){return a&n},WPuuK:function(a,n){return a&n},rJroA:function(a,n){return a>>>n},pNQrq:function(a,n){return a>>>n},PNiDo:function(a,n){return a&n},egSRH:function(a,n){return a>>>n},jpnjb:function(a,n){return a&n},NQQuq:function(a,n){return a&n},naLHE:function(a,n){return a|n},mgNbB:function(a,n){return a|n},CwOMz:function(a,n){return a>>>n},DOKOo:function(a,n){return a<n},jHgZh:function(a,n){return a|n},pUiWK:function(a,n){return a<n},NAJXW:function(a,n){return a|n},qMoEF:function(a,n){return a!==n},RzkIh:t(1079),GxCst:t(979),EHaOE:function(a,n){return a===n},eynXe:function(a,n){return a(n)},FKKYW:function(a,n,s){return a(n,s)},Hzmhy:function(a,n){return a(n)},dfXOJ:function(a,n){return a!==n},uBpFC:function(a,n,s){return a(n,s)},upNUi:function(a,n,s){return a(n,s)},kZnzg:t(1139),WCuqo:"TecKR",nlfOi:function(a,n,s){return a(n,s)},pBBYj:t(381),IlVxi:function(a,n){return a!==n},fgGhM:function(a,n){return a===n},jlXgz:"JrEtk",HRHrI:t(481),JsPWg:function(a,n){return a!==n},uAOMX:t(506),nIqVL:t(1712),Tkfri:function(a,n,s){return a(n,s)},XIHJF:function(a,n,s){return a(n,s)},PIdLr:function(a,n,s){return a(n,s)},toqeH:function(a,n){return a(n)},LaXZO:function(a,n){return a(n)},rAFcz:function(a,n,s){return a(n,s)},QHBJw:function(a,n,s){return a(n,s)},DPHpF:function(a,n){return a(n)},dYgFH:function(a,n){return a(n)},bgIdp:function(a,n,s){return a(n,s)},IPjZg:function(a,n){return a(n)},yCqjh:function(a,n){return a(n)},cIEYG:function(a,n,s){return a(n,s)},YXQKq:function(a,n){return a&n},UkNts:function(a,n){return a===n},MOstx:t(574)+t(536)+t(1699)+"SeqID",peqBH:t(574)+t(536)+t(1699)+t(1271),GNPio:"Missing "+t(536)+t(1699)+t(1128),DdkFE:function(a,n){return a===n},WzzAU:function(a,n){return a(n)},vzyaC:function(a,n){return a+n},gtXIV:function(a,n,s,l){return a(n,s,l)},iGUon:t(1035),uCSwG:function(a,n){return a>=n},jYLRe:t(936),URANL:function(a,n){return a===n},CPQAn:function(a,n){return a+n},YuLXP:"Skip pas"+t(1181),IbJFr:function(a,n){return a>=n},QLtvL:"JvWLg",tpyqi:function(a,n){return a>n},GQFkS:function(a,n){return a*n},staRP:function(a,n){return a>n},TZgQY:function(a,n){return a+n},GmuFq:t(852)+t(1181),mdhri:t(440),teALn:t(806),fiMTo:"pageshow",fsJfO:function(a,n,s){return a(n,s)},raICx:function(a,n){return a&n},oJhMV:function(a,n){return a===n},mkPfN:t(1254),XnjtT:"iwFpm",qkhLo:function(a,n){return a+n},BJqjK:function(a,n){return a==n},nlfLu:function(a,n){return a>=n},gMUUL:function(a,n){return a+n},kHyMR:t(1536),vYbWW:function(a,n){return a&n},pNWnP:function(a,n){return a<<n},MqEfU:function(a,n){return a<<n},pqBwz:function(a,n){return a&n},Pcuom:function(a,n){return a<=n},YfneQ:t(1054),pMeUt:function(a,n){return a&n},TpTpH:function(a,n){return a+n},kFSgm:function(a,n){return a+n},Lgdjg:function(a,n){return a<<n},tZnCN:function(a,n){return a|n},QynpL:function(a,n){return a|n},IJMCt:function(a,n){return a<<n},cueHN:function(a,n){return a&n},WNZCG:function(a,n){return a<<n},akIyN:function(a,n){return a&n},uRdhe:function(a,n){return a&n},fOOpp:function(a,n){return a<n},AssbC:function(a,n){return a>n},yoOrJ:function(a,n){return a+n},mdPWG:function(a,n){return a>>n},NjSVR:function(a,n){return a&n},rSOtp:t(1822)+t(1635)+t(491),IpWQK:t(1561)+t(1486),HvKlI:"applicat"+t(1486)+";charset"+t(1053),fmvyn:t(1419),EstpM:t(1519)+"e",wfrdE:"binary",SQgTR:function(a,n){return a>=n},XyOmx:function(a,n){return a+n},MqmGl:function(a,n){return a<<n},ZVkiq:function(a,n){return a-n},nKRQr:function(a,n){return a<n},lXQrU:function(a,n){return a<n},ZyZqs:function(a,n){return a|n},GjElJ:"HxYFr",DOald:function(a,n){return a<n},JvcVc:function(a,n){return a|n},JWGEN:function(a,n){return a>>n},OAnZb:function(a,n){return a===n},aEeSc:t(1413),QWkpN:function(a,n){return a>>n},PYiOz:function(a,n){return a&n},SMBFL:function(a,n){return a|n},VeRse:function(a,n){return a&n},LarDb:t(789),YyFnf:"MqLRE",ixxpb:t(484),OKAUX:function(a,n){return a!=n},Uhfvq:function(a,n){return a instanceof n},rJXxL:function(a,n){return a instanceof n},PONfr:function(a,n){return a==n},beKtv:function(a,n){return a!==n},jZYDt:t(658),oBDhm:function(a,n){return a&n},msLMz:function(a,n,s){return a(n,s)},KKoIM:function(a,n){return a|n},mifye:function(a,n,s){return a(n,s)},hpejS:function(a,n){return a<n},HMeyB:function(a,n){return a&n},xaqMk:function(a,n){return a===n},qupBi:t(1405),zKgyh:function(a,n){return a<<n},bBdyV:function(a,n){return a&n},VcOeR:t(1498),UoPnT:"lNcxX",ZuTmC:function(a,n){return a(n)},yiaTb:function(a,n){return a&n},YUqPY:function(a,n){return a!==n},cPLkp:"DVpND",wpdVJ:function(a,n){return a(n)},wiOlx:function(a,n){return a<<n},sZkEG:function(a,n){return a|n},MRrPz:function(a,n){return a>>>n},SPyUY:function(a,n){return a<<n},SlEfM:function(a,n){return a>>>n},Flsib:function(a,n){return a|n},YRtpf:function(a,n){return a<n},FsRqG:function(a,n){return a<n},GpZRf:function(a,n){return a<n},aUTsc:function(a,n){return a|n},ESCNY:function(a,n){return a&n},rBhUq:function(a,n){return a+n},beHbQ:function(a,n){return a|n},JxIDJ:function(a,n){return a!==n},fyiPa:function(a,n){return a|n},EzKth:function(a,n){return a>>>n},YiPjG:function(a,n){return a+n},vteot:function(a,n){return a!==n},KofiB:function(a,n){return a|n},PuulT:function(a,n){return a|n},MsPIn:function(a,n){return a&n},HlLjh:function(a,n){return a!==n},cxscv:function(a,n){return a&n},eIBFQ:function(a,n){return a|n},FlWWy:function(a,n){return a&n},aBlTF:function(a,n){return a===n},eLAOf:"XkceS",haVfn:function(a,n){return a|n},hFLyu:function(a,n){return a===n},nlBfR:"gmpFo",JMVQP:function(a,n){return a|n},ziMoD:function(a,n){return a<<n},OiVGh:function(a,n){return a|n},uKLLA:function(a,n){return a|n},nmcLx:function(a,n){return a<<n},XvXVl:function(a,n){return a>>>n},eCGXh:function(a,n){return a|n},OTKav:function(a,n){return a|n},QwFNL:function(a,n){return a<<n},SBqTc:function(a,n){return a>>>n},GMfLa:function(a,n){return a|n},WuERW:function(a,n){return a|n},jJLfl:function(a,n){return a<<n},VkphW:function(a,n){return a>>>n},AQdne:function(a,n){return a&n},oeXFq:function(a,n){return a&n},CCmGn:function(a,n){return a>>>n},YaAAm:function(a,n){return a|n},nvnzG:function(a,n){return a|n},COhfR:function(a,n){return a!==n},ypQfD:"BIRWH",AARDb:function(a,n){return a===n},fWzxb:function(a,n){return a&n},GgPMf:function(a,n){return a&n},YpUbs:function(a,n){return a>>>n},KlimG:function(a,n){return a+n},aPcjg:function(a,n){return a!==n},IgYwe:function(a,n){return a!==n},LqqBx:function(a,n){return a===n},etRLo:function(a,n){return a>>>n},OrjoG:function(a,n){return a===n},DlAFm:function(a,n){return a===n},YVldq:function(a,n){return a+n},zWQkT:function(a,n){return a&n},FcMDP:function(a,n){return a&n},fYsgC:function(a,n){return a>>>n},GTsKT:function(a,n){return a>>>n},EwrEL:function(a,n){return a>>>n},zQqnJ:function(a,n){return a>>>n},fsTFv:function(a,n){return a>>>n},XaFOi:function(a,n){return a&n},DzDqT:function(a,n){return a&n},hykBN:function(a,n){return a&n},Pomif:function(a,n){return a>>>n},cUQuO:t(1865)+"4|2",VONjT:t(1285)+t(930),CjVTd:t(561)+"RROR",tYYop:"MAX_RETR"+t(1261)+"R",jugYw:"OPEN_ERROR",jAfkM:t(1187)+t(1323),SBagc:"1|2|4|0|"+t(1277),ikAVL:function(a,n){return a|n},Spqkj:function(a,n){return a|n},sYejJ:function(a,n){return a<<n},QZgoJ:function(a,n,s){return a(n,s)},TfJeB:function(a,n){return a!==n},AWYFy:"Iybgc",giFIC:t(483),sBvGK:function(a,n){return a>=n},qYiaU:function(a,n){return a===n},DvWKH:function(a,n){return a>n},THhZz:t(1524),sPFfK:function(a,n){return a<n},vOmDM:function(a,n){return a+n},psfWB:function(a,n){return a===n},htfLp:t(1120),GFVXi:function(a,n){return a instanceof n},ZiWeA:"Unhandle"+t(1837),mEFnl:function(a,n){return a===n},aJNRf:function(a,n){return a<n},rdMnY:"rbvid",UKgyy:function(a,n,s){return a(n,s)},eAOpD:"close",kguSd:function(a,n){return a===n},cIYNS:function(a,n){return a instanceof n},VzZKJ:t(899),Iknpl:"qUVVI",NVzAH:t(1532),FXZBR:t(1814),mDZON:"XPyvc",HFJtB:"cursor.s"+t(1344),gqkVI:function(a,n,s,l){return a(n,s,l)},zOvTQ:t(650),aPeZM:t(1128),qahzp:"service-"+t(361),bPYyK:t(361),EIORT:"cursor_file_name",EPROD:function(a,n,s){return a(n,s)},WkcdU:function(a,n){return a===n},wqSRR:function(a,n){return a instanceof n},LXBca:t(729),rSljr:t(1682),lAAUF:function(a,n){return a+n},RaEsl:function(a,n){return a>>n},AeLqo:function(a,n){return a&n},AHNPO:"mnKgT",InRvQ:"PRPdq",XAuGi:"VfSCs",BUHph:function(a,n,s){return a(n,s)},LVISW:function(a,n){return a!==n},Vrauf:t(1769),fnabu:"EvBxi",aueTJ:"2|5|0|3|"+t(455),BIGKH:"get",qhgVs:t(1066),cjMZn:t(1296)+"ys",rbccZ:t(1360),esVQG:function(a,n){return a(n)},MpLkg:function(a){return a()},WUZfM:t(492),ZywsL:t(524),lBYIn:t(744),TaOlg:"clear",fGXCH:t(623),CCjye:function(a,n){return a||n},wxLqL:function(a,n){return a!=n},Hdmxu:t(1821)+"d",kPoHz:t(1459)+"4",AAnKp:function(a,n){return a||n},wswok:function(a,n){return a<=n},zSxDk:t(1176)+"alled mu"+t(1352)+t(1501)+t(1816),zPOyA:function(a,n){return a*n},PWOLF:t(1570),TuUKT:t(1802),jzUPy:function(a,n){return a===n},USgHr:t(1883),AzRqf:"QmgTe",xubUO:function(a,n){return a<n},gQFFr:function(a,n){return a-n},GfPts:function(a,n){return a<=n},dfRrG:function(a,n){return a<<n},MxrKh:function(a,n){return a>=n},MVdls:function(a,n){return a<n},EHyyN:function(a,n){return a<<n},qZdAo:function(a,n){return a&n},anFCx:t(458),pXRbO:function(a,n){return a-n},scKAk:function(a,n){return a|n},jiHee:function(a,n){return a|n},KCkLX:function(a,n){return a&n},ZDJvW:function(a,n){return a<<n},xdZwC:function(a,n){return a&n},SlpIH:function(a,n){return a>>n},ESoPj:t(1511),XHzYI:t(1640),zKzYP:function(a,n){return a<n},wujSc:function(a,n){return a|n},jvzPn:function(a,n){return a|n},Jbypr:function(a,n){return a===n},GhiSc:"5|4|0|1|3|2",jqmlh:function(a,n){return a|n},fzAeM:function(a,n){return a>>n},hiuju:function(a,n){return a+n},eYAmg:function(a,n){return a&n},RIkUM:function(a,n){return a&n},kOQxN:function(a,n){return a&n},zKuWd:function(a,n){return a-n},noQEN:t(1673),zzVim:"text/jav"+t(1593),wpPzw:t(894),VEwur:t(1411)+t(1676)+t(712)+"P",wplKZ:function(a,n){return a===n},zKCwj:t(1189),Kqaqu:t(1276),mOAsp:function(a,n,s,l){return a(n,s,l)},Rraqw:function(a,n){return a instanceof n},PTcmU:function(a){return a()},pHYxB:function(a,n){return a(n)},bAQHv:t(1954),MdqBf:t(1770),hizuR:t(1363),zOtAY:"oLoAO",UHahr:t(978),ZsCNF:function(a,n){return a>=n},kPwch:function(a,n){return a<=n},HfSvf:function(a,n){return a>=n},aBvyt:function(a,n){return a+n},YscPV:function(a,n){return a%n},JXFxF:function(a,n){return a|n},YhbMs:function(a,n){return a===n},rdjsu:t(1042),evGrM:function(a,n){return a>=n},InwLo:t(1126),Wywhp:t(1027)+t(446),rnynG:"ioZYU",tPUHL:t(1124),Lkabj:"oIMHZ",RdRyV:function(a,n){return a!==n},lXnbF:t(754),Mjyub:function(a,n){return a==n},xlCyv:t(530),mCfwd:function(a,n){return a||n},NmScs:function(a,n){return a||n},FzjOv:function(a,n){return a||n},XEgfH:"xDtgR",jKlQD:t(1799)+t(1154)+"t",gvavM:t(1746),uaAvR:t(585),iRzQP:function(a,n){return a||n},ANUVI:function(a,n){return a||n},bvwjf:"x_fronti"+t(1936),FzbvT:t(671)+t(1567)+"ck",yMOkB:t(671)+t(692)+"k",gSVyO:t(1833),aypqs:t(1799)+t(1859)+"s",crcjH:function(a,n){return a!==n},sLtyF:t(1547),lhIKK:"NQezW",wQerl:function(a,n){return a||n},TQqHO:function(a,n,s){return a(n,s)},hFCQA:t(1020)+"id",DLwxs:function(a,n){return a===n},InUeN:t(1078),CZogA:"NOoBz",fIJJC:"bXtTE",vHQar:function(a,n){return a===n},YnIIJ:t(916),vFCan:function(a,n){return a(n)},uFxxQ:"Vnmve",KTVcC:function(a,n,s,l){return a(n,s,l)},YvTGC:t(671)+t(809)+t(619),gmiGR:function(a,n,s,l){return a(n,s,l)},mUuXd:"need_ack",SaJUr:t(1521),iyEAz:function(a,n){return a&&n},lmUTD:t(646),GODTB:t(976),MXBRz:t(1318),IJALS:function(a,n){return a(n)},zIORU:function(a,n,s,l){return a(n,s,l)},KyzlO:t(1111),ozqJG:t(786),bVjLX:function(a,n){return a+n},ihOEL:t(1588),BCnGI:function(a,n){return a(n)},GpBjm:function(a,n){return a&n},SeszQ:function(a,n){return a||n},JWorc:function(a,n){return a(n)},HqfcC:function(a,n){return a+n},tmqbs:function(a,n){return a+n},lJAGe:function(a,n){return a+n},ARtdB:function(a,n){return a+n},bWtcP:t(861)+"t of ran"+t(412),hySlV:" > ",FRjGZ:function(a,n){return a>n},ACUYg:"integer "+t(854)+"e",IvueZ:function(a,n){return a+n},DJmHK:function(a,n){return a<<n},vRfHx:function(a,n){return a>=n},fqVzX:function(a,n){return a|n},LAErC:function(a,n){return a|n},oSjnv:function(a,n){return a<<n},uKJmy:function(a,n){return a+n},FsjkP:function(a,n){return a>>n},igbZa:function(a,n){return a!==n},OFFJD:t(1826),lcneg:"yKvMp",YQvSI:function(a,n){return a+n},TAint:function(a,n,s){return a(n,s)},jhMpC:function(a,n){return a>>>n},NqJXX:function(a,n){return a<n},LuOix:function(a,n,s,l){return a(n,s,l)},FLGcV:function(a,n){return a<<n},Rbyez:function(a,n){return a+n},zcSUD:function(a,n){return a|n},sLxhq:function(a,n){return a|n},vHnyL:function(a,n){return a+n},BsHRQ:function(a,n){return a+n},BAurB:function(a,n){return a&n},uJgNo:function(a,n){return a&n},KfecL:function(a,n){return a>>>n},abbTk:function(a,n){return a+n},JMWYQ:function(a,n){return a&n},LKXOw:function(a,n){return a>>>n},krRTt:function(a,n){return a>>>n},EcTMh:function(a,n){return a&n},lZnbG:function(a){return a()},KfHfO:function(a,n){return a===n},Frjse:t(504),OZgiC:function(a,n){return a+n},bABen:function(a,n){return a+n},HxmDJ:function(a,n){return a&n},WmtSB:function(a,n){return a+n},TzaMl:function(a,n){return a>>>n},SSlth:function(a,n){return a|n},BrLAS:function(a,n){return a|n},jOLEg:function(a,n,s,l){return a(n,s,l)},QIjDK:function(a,n){return a<n},SgqSN:function(a,n){return a+n},jhqCI:"3|7|10|2"+t(1238)+"|0|8|4",pDDAM:t(881),fNkYv:function(a,n,s,l){return a(n,s,l)},ECDnx:function(a,n,s,l){return a(n,s,l)},SAKjL:function(a,n){return a(n)},YgtpB:function(a,n,s){return a(n,s)},YnqVX:function(a,n,s){return a(n,s)},IshkX:function(a,n,s){return a(n,s)},dMoHS:function(a,n,s,l){return a(n,s,l)},eHbvD:function(a,n,s){return a(n,s)},nvzgv:t(1669)+t(777),KtRqg:function(a,n){return a<<n},IDNPL:function(a,n){return a<<n},flDBB:function(a,n){return a+n},uHZrx:t(414),mFRtB:function(a,n,s){return a(n,s)},sJycU:t(1730)+"ame",VeUdg:"AbortError",XLCAx:"dyCJo",AqtEN:t(485)+t(800),eRaOT:t(1800),XcdgP:function(a,n,s,l){return a(n,s,l)},SyHjd:t(1613),AZioQ:t(1739),UobxK:t(798),jRdDJ:"setdb",quPWw:function(a,n){return a(n)},ccgXt:t(436)+"r",JbGCe:function(a,n){return a!==n},XJcAt:"lBfMD",axAry:function(a,n){return a===n},hBWhn:function(a,n){return a instanceof n},PrmLQ:function(a,n){return a(n)},dYGru:function(a,n){return a===n},lrgeb:t(1537),Tvynx:function(a,n){return a+n},eruzW:function(a,n){return a>>>n},Ummwu:function(a,n){return a&n},XkENR:function(a,n){return a<n},GcWnx:function(a,n){return a>>n},VZPAF:function(a,n){return a|n},UphLv:function(a,n){return a>>n},WEYeJ:function(a,n){return a|n},pYkGR:t(1341),ZfQoE:t(671)+t(1878),fgAkY:function(a,n){return a(n)},dPkMD:function(a,n,s){return a(n,s)},spXAH:"x_fronti"+t(1563),fAVWG:function(a,n,s,l){return a(n,s,l)},DkJsY:function(a,n,s){return a(n,s)},VEccL:t(581)+"rsor_name",JGkNn:function(a,n){return a(n)},OHyYC:"TFpmw",QXsBR:t(1397),hEgrI:t(575),zwumd:t(1750),NJHIh:t(990),hwHwu:t(1160),DQLYe:t(1534),xnfvJ:"qcCFQ",JRNXB:t(672),JGdZz:t(589),LySIc:t(1443),AMHLC:function(a,n){return a||n},MXVzE:t(773)+t(785),XUXuQ:function(a,n){return a===n},qBKkG:function(a,n){return a&&n},ozDqI:function(a){return a()},lfbZR:function(a){return a()},nKidy:function(a){return a()},LdZTC:"GYwiv",FjIDK:t(1249),KkExN:function(a,n){return a(n)},VuQKi:t(600),EurpO:t(838),cSquT:function(a,n){return a(n)},vGCFu:function(a,n){return a===n},njvsN:function(a,n){return a>>>n},FRbcg:function(a,n){return a|n},RRwEV:function(a,n){return a<<n},MwEvh:function(a,n){return a<<n},OKthz:function(a,n){return a!==n},hhdyH:t(1779),KlOBk:function(a){return a()},VlaDC:function(a,n){return a<n},JnDha:function(a,n){return a===n},dYPHA:function(a,n,s){return a(n,s)},gAdHs:function(a,n){return a===n},tvltj:t(1211),fxFwZ:"ENNfI",vUUGQ:t(690),keKvl:function(a,n,s){return a(n,s)},UePNx:function(a,n){return a(n)},aOgXN:function(a,n){return a===n},EspBE:t(1809),kbfqb:t(517),MHWCn:function(a,n,s){return a(n,s)},lSQsh:function(a,n,s){return a(n,s)},mbZxI:function(a,n,s){return a(n,s)},IFdQt:t(655)+"fer",AvnZv:t(1606),ZzLJV:"auto",gzBqE:function(a,n){return a==n},CQHXD:t(642)+t(907)+t(1370),wBwZZ:t(642)+t(1288)+t(1848)+t(1546)+t(684)+t(495)+t(1319)+t(1085),KPsbM:t(566),GLKLI:function(a,n){return a<n},srSbb:function(a,n){return a!==n},ZLsgt:t(500),xVhwr:t(441),ttDIZ:function(a,n,s){return a(n,s)},YCyns:t(1495)+t(1927)+t(688)+"ct",bmkyE:function(a,n,s,l,f){return a(n,s,l,f)},OxEsl:function(a,n){return a(n)},qVRzp:t(466)+t(1131),KhYIt:t(1986),zYnoO:t(942),ysVAV:t(1136),JVyNR:function(a,n){return a!==n},YqgqX:function(a,n){return a>>>n},MjBYJ:function(a,n){return a!==n},YSMQq:"cecXW",dNYwz:function(a,n){return a!==n},aTnEN:function(a,n,s){return a(n,s)},Cnmib:function(a,n,s){return a(n,s)},TpQWt:t(799)+t(1782)+"ork offl"+t(1047),IAEbI:t(960),qqUgn:t(735),KowMB:t(1367),lZXmq:t(1630),CuGux:t(1706),dRRzH:t(1332),GAPzV:t(780),aJVLY:t(642)+t(365)+t(1193)+"viceID o"+t(1231),MRhMk:function(a,n){return a==n},CkErM:"function",xgRbx:"web",ZDqcf:t(378)+"0",vnyOY:function(a,n){return a!==n},LTjsU:"nOKEj",bxTRr:t(705),QMIDA:function(a,n,s){return a(n,s)},WpyjF:"RKtGW",Iscby:t(988),uwebt:function(a,n){return a===n},bbIPm:t(654),BpxvC:"XzOEu",BBBaB:t(501)+"t",BgVek:t(1093),GKCof:function(a,n){return a>n},jNsDV:function(a,n){return a-n},dbRvx:function(a,n,s){return a(n,s)},cKUOU:function(a,n){return a(n)},XBnoB:function(a,n){return a(n)},xxqgV:function(a,n){return a(n)},JRhHi:t(1728)+">",OyYmL:function(a,n){return a*n},ikkRW:function(a,n){return a-n},YeGfO:t(675),McTem:function(a,n,s){return a(n,s)},yMrCH:t(799)+t(1775)+t(501)+t(1301)+t(1018),ikjQi:t(887),zULrj:t(1497),WFJPF:function(a,n){return a&n},mxKwG:function(a,n){return a+n},ucSdJ:"UpHjz",LCTxe:t(1141)+t(1074)+t(1434)+"g",PIrta:function(a,n){return a(n)},dsUOy:function(a,n){return a===n},yXmBm:t(673),zewiz:t(1273)+"1",ncxDK:t(1885),OxaTw:t(1829),ZFhog:function(a,n){return a===n},UKlJu:t(1636),wVFsi:t(1374),MWcWy:"WLJBW",aOpBp:"bye",jRnkA:function(a,n){return a||n},IjhPw:function(a,n){return a!=n},mMHQx:"init QoS"+t(1310)+"d",pEwSX:function(a,n){return a===n},IIJwM:t(1929),rygHO:"xzBoO",kORBj:"ack",fIgoi:function(a,n){return a(n)},GBzNV:"cnMhc",jwcae:function(a,n){return a+n},dpOSO:"Jzeuz",VIRnl:t(796)+t(1512),MSmTn:"close, w"+t(459)+"ce not initialized",tjWNy:"please p"+t(901)+t(1632)+t(1226)+t(355)+t(1410)+"ng or an"+t(1943)+"ffer",BafMR:t(1094),raLRM:function(a,n){return a!=n},CpQWg:function(a,n){return a instanceof n},EziPi:"sent",jUzvS:"enqueue",Rfqke:function(a,n){return a||n},ouCWB:function(a,n){return a==n},XjKLA:function(a,n){return a!==n},XtjtJ:t(1666)+t(812)+t(878),zCpdl:t(1183),eCcgl:function(a,n){return a|n},rAqbJ:function(a,n){return a!==n},wqkPM:t(1533),yaqij:"2|7|5|3|"+t(1084),FMuTI:function(a,n){return a===n},cNFUE:t(1705)+t(1404)+t(1925),DJfuI:function(a,n){return a===n},CnRmz:"obTey",KTSqb:t(1713),JcUZN:function(a,n){return a/n},FXRFT:function(a,n){return a!=n},WnzIs:t(999),TINbC:function(a,n){return a!=n},ZrGcY:"Object",vrppG:function(a,n){return a!=n},sEjvJ:t(1969)+t(1050)+t(1704)+"pe",ltiSH:"SharedWo"+t(540)+t(1080),TyZsT:function(a,n){return a===n},jwvQs:function(a,n){return a!=n},ivofP:function(a,n){return a!=n},KTBEJ:function(a,n){return a===n},DDNWA:function(a,n){return a!=n}};Ft.r(Ne),Ft.d(Ne,{FWS:()=>Rg,CustomErrorEvent:()=>hl,createCloseEvent:()=>wt,ReconnectEvent:()=>xl,createErrorEvent:()=>lt,decodedFrame:()=>nn,createOpenEvent:()=>yl,CustomCloseEvent:()=>pl,createReconnectEvent:()=>ya,FrontierMessageEvent:()=>ml,encodeFrame:()=>Ht,createMessageEvent:()=>_l,OpenEvent:()=>wl,ErrorCode:()=>sn,Event:()=>or,MessageEvent:()=>gl});let r="";function i(a=""){let n=t,s="02",l=""+Date[n(1293)](),f=r||(r=e.VJfwP(x,a)),m=Math.random()[n(1767)](16).slice(-6);return e[n(1581)](e[n(1581)](e.HoFxs(s,l),f),m)}function o(){let a=t;return e[a(1581)](e[a(606)](1e4,Date[a(1293)]()),Math.floor(e[a(606)](1e4,Math.random())))}function c(a){let n=t;return e[n(1581)](e[n(1917)](Array,8)[n(1979)]("0"),e[n(370)](parseInt,a,10).toString(2)).slice(-8)}function d(a){let n=t;return e[n(1818)](e[n(390)],n(908))?this[n(1880)][n(1957)+n(1891)]():(e[n(1474)](Array,4)[n(1979)]("0")+parseInt(a,2)[n(1767)](16))[n(523)](-4)}function u(a){let n=t;if(e[n(1058)](e[n(1496)],e[n(1496)])){let s=a[n(1916)](/\./)[n(607)](m=>c(m)),l=[];return l[0]=e[n(1917)](d,e[n(450)](s[0],s[1])),l[1]=e[n(765)](d,e.bXLlL(s[2],s[3])),[n(1165),e[n(1653)],e[n(1653)],e[n(1653)],e[n(1653)],"ffff",l[0],l[1]][n(1979)]("")}else _0x5ce3ee=e.uaNrH(_0xda34e8,_0x4982b6),_0x21d684<32&&(_0x11669f|=e[n(1023)](e[n(1710)](127,_0x53d306),_0x24d8e1)),_0x52f307+=7}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(1624)](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(1624)](a);return s?e[n(1474)](u,a):l?e[n(1331)](h,a):e[n(829)]}function h(a){let n=t,s={poyCf:function(C,I){return C+I},YFGwt:function(C,I){return e[F(1838)](C,I)},bYVjV:function(C,I){return e[F(410)](C,I)},okHja:function(C,I){return e[F(1096)](C,I)},arMNd:function(C,I){return e[F(1710)](C,I)},PuHXz:function(C,I){return e[F(1147)](C,I)},YaTkv:function(C,I){return e.NYuit(C,I)},JtgkJ:function(C,I){return e[F(1147)](C,I)},CakPQ:function(C,I){return e.VVlwX(C,I)}},l="",f=[],m=0,w=0,b=!0,g=e[n(1653)];if(a[n(866)]("::")>-1){let C=a[n(1916)]("::");for(let M=0;e[n(1801)](M,C[n(551)]);M++){let K=C[M];if(e.aadIO(K[n(866)](":"),0)){let J=K.split(":");b&&(m=J[n(551)]),w+=J[n(551)];for(let ne=0;e.nndmJ(ne,J.length);ne++)if(e[n(1818)](4,J[ne][n(551)])){let st=g[n(1121)+"g"](0,e[n(998)](4,J[ne].length)),U=st[n(1163)](J[ne]);f[n(1113)](U)}else f.push(J[ne]);b=!1}else{if(e[n(1369)](4,K.length))if(e[n(1950)](e[n(1648)],e.HVwIK))_0x25f18c=s.poyCf(s[n(1574)](65536,s[n(1642)](1023,_0x22510e)<<10),1023&_0xa6b574),++_0x586a02,_0x3a9610[_0x778479++]=s[n(1059)](_0x56fec8,18)|240,_0x5f5744[_0x99244d++]=s[n(1554)](s[n(922)](s.PuHXz(_0x40caf0,12),63),128),_0x380895[_0x42bd1a++]=s[n(1554)](s[n(862)](s[n(1758)](_0x573a44,6),63),128),_0x342252[_0xcae9a3++]=s[n(1729)](s[n(862)](63,_0x247135),128);else{let J=g.substring(0,e[n(804)](4,K[n(551)])),ne=J[n(1163)](K);f.push(ne)}else f[n(1113)](K);b&&(m+=1),w+=1,b=!1}}let I="";for(let M=0;e[n(805)](M,e[n(1575)](8,w));M++)I=I[n(1163)](g);for(let M=0;e.cnXlS(M,f[n(551)]);M++)e[n(557)](M,m)&&(l=l[n(1163)](I)),l=l[n(1163)](f[M]);return l}if(e[n(1778)]!==n(358)){let C=a[n(1916)](":");for(let I=0;e[n(1801)](I,C[n(551)]);I++){let M=C[I];if(C[I][n(551)]!==4){let K=g[n(1121)+"g"](0,e.MPwAA(4,C[I][n(551)])),J=K[n(1163)](M);l=l[n(1163)](J)}else l=l[n(1163)](M)}return l}else return _0x3fbf6b[n(1964)]()}function p(a,n){let s=t,l=a[s(1107)];if(e[s(1617)](void 0,l))if(e.iVyil(e.tZSbQ,s(1206)))me(n,10),e.bWLwj(q,n,l);else return this[s(1703)]?this[s(1703)][s(1601)+"pe"]:this[s(853)+s(1269)];let f=a[s(703)];e[s(1714)](void 0,f)&&(e[s(1012)](me,n,18),q(n,f))}function _(a){let n=t,s={};e:for(;!e[n(667)](Z,a);){let l=e[n(1474)](ge,a);switch(e[n(366)](l,3)){case 0:break e;case 1:s.key=e[n(564)](P,a,e[n(1474)](ge,a));break;case 2:s[n(703)]=e[n(564)](P,a,ge(a));break;default:R(a,e[n(1710)](7,l))}}if(e[n(1058)](void 0,s[n(1107)]))throw new Error(e[n(1328)]);if(s[n(703)]===void 0)throw new Error(n(574)+n(536)+n(1699)+n(703));return s}function S(a){let n=t,s=D();return e[n(564)](y,a,s),B(s)}function y(a,n){let s=t,l={nJTnV:function(U,G){return e[F(1331)](U,G)},wlIul:function(U,G){return e[F(1023)](U,G)},HWkwu:function(U,G){return e[F(1331)](U,G)},bXDFm:function(U,G){return e[F(1023)](U,G)},ELxUI:function(U,G){return e.NYuit(U,G)},ndGeF:function(U,G){return e[F(669)](U,G)},eBaIs:function(U,G){return U(G)},tqNMQ:function(U,G){return e[F(1192)](U,G)},GoglE:function(U,G){return e[F(1917)](U,G)},YXcAG:function(U,G){return e[F(1006)](U,G)},YqxQk:function(U,G){return U&G},sVXtG:function(U,G){return U>G},AFQmF:function(U,G,Re,fs){return U(G,Re,fs)},uSDRG:function(U,G){return U|G},HrJuO:function(U,G){return e.NYuit(U,G)},ssgxx:function(U,G){return e[F(1604)](U,G)},rGqif:function(U,G){return e[F(687)](U,G)},fucZy:function(U,G){return U<<G},OblYE:function(U,G){return e.CwOMz(U,G)},UVifa:function(U,G){return e.DOKOo(U,G)},OZMXC:function(U,G){return U|G},RiKNq:function(U,G){return e[F(1469)](U,G)},YpEzS:function(U,G){return e.pUiWK(U,G)},seNrM:function(U,G){return e[F(818)](U,G)},zRHpm:function(U,G){return e[F(1559)](U,G)},tDgVd:function(U,G){return U<<G},ttPAR:function(U,G){return e[F(1838)](U,G)}},f=a[s(628)];e[s(1489)](void 0,f)&&(me(n,8),mt(n,f));let m=a[s(1271)];if(m!==void 0)if(e[s(1714)](e[s(954)],e.GxCst))e[s(370)](me,n,16),mt(n,m);else{let U=this[s(1253)],G=this.low;return[e[s(1037)](255,G),e[s(1488)](e[s(366)](G,8),255),e[s(1710)](e[s(1559)](G,16),255),e[s(1006)](G,24),e[s(1838)](255,U),e[s(380)](e[s(839)](U,8),255),e[s(1488)](e[s(839)](U,16),255),U>>>24]}let w=a[s(1128)];w!==void 0&&(e[s(1272)](s(1827),s(1827))?(e[s(370)](me,n,24),mt(n,e[s(707)](O,w))):(_0x388040=l[s(816)](_0xbe7721,_0x41eb3f),_0x435aed|=l[s(1948)](127&_0x38936f,14),128&_0x4fe002&&(_0x5b95f6=l[s(1628)](_0x4d235c,_0x20e681),_0x663c33|=l[s(1874)](l[s(1834)](127,_0x5746e6),21),l.ndGeF(128,_0x46ee0e)&&(_0x5cafdb=l[s(702)](_0xdb0e5d,_0x5ab689),_0x48d69d=l.ndGeF(127,_0xf4b4d1),l[s(408)](128,_0x42e275)&&(_0x1009f1=l[s(1441)](_0x6c03ab,_0x29a053),_0x6c385c|=l[s(408)](127,_0x283837)<<7)))));let b=a[s(1119)];e[s(1818)](void 0,b)&&(e.FKKYW(me,n,32),e[s(1012)](mt,n,e[s(662)](O,b)));let g=a[s(711)];if(g!==void 0)for(let U of g){me(n,42);let G=D();e[s(1012)](p,U,G),e.bWLwj(me,n,G[s(1603)]),e.xasre($,n,G),e[s(1474)](L,G)}let C=a[s(1968)+s(989)];e[s(1448)](void 0,C)&&(e[s(1377)](me,n,50),e[s(1377)](q,n,C));let I=a[s(439)+s(1269)];e.tsDPM(void 0,I)&&(e[s(564)](me,n,58),e.upNUi(q,n,I));let M=a[s(1526)];if(e.qMoEF(void 0,M)){if(e.kZnzg===e[s(576)])return this._socket.extensions;e[s(1012)](me,n,66),e[s(1350)](me,n,M[s(551)]),e[s(1012)](ce,n,M)}let K=a[s(1315)];e[s(1489)](void 0,K)&&(e[s(1058)](e.pBBYj,e[s(1602)])?(e[s(564)](me,n,74),q(n,K)):(this[s(769)+s(756)+s(1499)](_0x333604),_0x5e3f31.set(_0x5b4b2f,_0x4641e6,_0x5024d3.message[s(1128)])));let J=a[s(1385)+s(1101)];if(e[s(404)](void 0,J))if(e[s(956)](e.jlXgz,e.HRHrI)){let U=("5|6|4|7|"+s(1209)+s(387)+"3")[s(1916)]("|"),G=0;for(;;){switch(U[G++]){case"0":_0xdac146=l[s(612)](_0x3b8717|l[s(1684)](15,_0x11cb09[_0x307d46])<<28,0);continue;case"1":if(l[s(820)](_0x30080c+=5,_0x53ceaf[s(551)]))throw _0x121ca8=_0x531edb[s(551)],l[s(514)](_0x3deb2a,_0x24ccd0,10,_0x297a7f[s(551)]);continue;case"2":_0x3295d7=l[s(612)](l.uSDRG(_0x5dc772,l[s(1874)](l[s(409)](127,_0xf066c[_0x33feb0]),14)),0);continue;case"3":return{value:_0x5824d4?_0x351799:l[s(1453)](0,_0xfe854),offset:_0x2f30ea};case"4":_0x5094e2=l.YXcAG(l[s(905)](_0x4e1531,l.fucZy(l.ELxUI(127,_0x552abc[_0x414098]),7)),0);continue;case"5":_0x1e1f91=l[s(1763)](127&_0xb98c7[_0x47371e],0);continue;case"6":if(l.UVifa(_0x44de21[_0x46cb34++],128))return{value:_0xc552f5?_0x14569b:l[s(831)](0,_0x498bf0),offset:_0x27028b};continue;case"7":if(_0x58bcd1[_0x319ec4++]<128)return{value:_0x445715?_0x34402a:l[s(1911)](0,_0x33b7a0),offset:_0x4dd34e};continue;case"8":if(l[s(944)](_0x2fe023[_0x42e4d5++],128))return{value:_0x35dc49?_0x125bb9:l[s(905)](0,_0x417289),offset:_0x58f1c0};continue;case"9":if(_0x24bebf[_0x340da0++]<128)return{value:_0x2df87?_0x5a9a03:l[s(359)](0,_0x11904c),offset:_0x2ec6fb};continue;case"10":_0x3cdeab=l.zRHpm(l.seNrM(_0x3dfb55,l[s(1522)](l.ttPAR(127,_0x594cae[_0x2382e8]),21)),0);continue;case"11":if(l[s(944)](_0x34e2da[_0x394bb7++],128))return{value:_0x44a280?_0x2ee736:0|_0xe785f,offset:_0x58700b};continue}break}}else e[s(1377)](me,n,82),e[s(564)](q,n,J);let ne=a.msgID;ne!==void 0&&(e[s(1506)](e[s(1675)],e[s(784)])?(e[s(1012)](me,n,90),e[s(886)](q,n,ne)):(_0x2b6208(_0x4de6ca,8),e[s(564)](_0x3a73b0,_0x26527e,_0x437bc2)));let st=a[s(1379)+"e"];e[s(1714)](void 0,st)&&(e[s(1937)](me,n,96),e.PIdLr(mt,n,e[s(1474)](O,st)))}function v(a){return A(e.uaNrH(z,a))}function A(a){let n=t,s={};e:for(;!e[n(904)](Z,a);){let l=e.LaXZO(ge,a);switch(l>>>3){case 0:break e;case 1:s[n(628)]=e[n(1040)](It,a,!0);break;case 2:s[n(1271)]=e[n(429)](It,a,!0);break;case 3:s[n(1128)]=ge(a);break;case 4:s.method=e[n(765)](ge,a);break;case 5:{let f=k(a);(s[n(711)]||(s.headers=[]))[n(1113)](e[n(824)](_,a)),a[n(1603)]=f;break}case 6:s[n(1968)+n(989)]=e.Tkfri(P,a,e[n(1305)](ge,a));break;case 7:s[n(439)+n(1269)]=e[n(368)](P,a,e[n(1152)](ge,a));break;case 8:s[n(1526)]=e[n(368)](ae,a,ge(a));break;case 9:s[n(1315)]=e[n(867)](P,a,e.yCqjh(ge,a));break;case 10:s[n(1385)+n(1101)]=e[n(668)](P,a,e[n(1305)](ge,a));break;case 11:s[n(1221)]=e[n(1377)](P,a,e.dYgFH(ge,a));break;case 12:s[n(1379)+"e"]=e[n(1917)](ge,a);break;default:R(a,e[n(731)](7,l))}}if(e[n(1461)](void 0,s[n(628)]))throw new Error(e[n(1523)]);if(e[n(956)](void 0,s[n(1271)]))throw new Error(e[n(1309)]);if(e[n(1950)](void 0,s[n(1128)]))throw new Error(e[n(743)]);if(e.DdkFE(void 0,s[n(1119)]))throw new Error("Missing "+n(536)+" field: "+n(1119));return s}function k(a){let n=t,s=e.WzzAU(ge,a),l=a[n(1603)];return a.limit=e.vzyaC(a[n(663)],s),l}function R(a,n){let s=t;if(s(1336)===s(582))try{e[s(1881)](_0x2b96ba,this,_0x437246,[_0x21e13e,_0x1a57fd,_0x3cc7a7])}catch(l){let f=_0x1a6218(e[s(471)],{message:l[s(1814)],code:_0x7cd86d[s(762)+"OR"],error:l});this[s(769)+s(1662)+s(1652)](f)}else switch(n){case 0:for(;128&e[s(707)](re,a););break;case 2:X(a,ge(a));break;case 5:e[s(1350)](X,a,4);break;case 1:e.nlfOi(X,a,8);break;default:throw new Error(s(1921)+s(1825)+s(741)+n)}}function O(a){let n=t;return a|=0,{low:a,high:e[n(1147)](a,31),unsigned:e[n(1463)](a,0)}}let E=[];function D(){let a=t;if(e.jYLRe!==e[a(700)]){let n=this[a(1880)]["getStora"+a(1130)](this[a(1129)]);return _0x5d2aa7[a(1316)](n||"{}")[_0x22d30d]}else{let n=E.pop();return n?(n[a(663)]=n.limit=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}}function L(a){E[t(1113)](a)}function z(a){return{bytes:a,offset:0,limit:a[t(551)]}}function B(a){let n=t,s=a.bytes,l=a[n(1603)];return e[n(639)](s[n(551)],l)?s:s.subarray(0,l)}function X(a,n){let s=t;if(e.aadIO(e[s(593)](a[s(663)],n),a[s(1603)]))throw new Error(e.YuLXP);a[s(663)]+=n}function Z(a){let n=t;return e[n(1478)](a[n(663)],a[n(1603)])}function se(a,n){let s=t;if(e.QLtvL===e[s(721)]){let l=a[s(1879)],f=a[s(663)],m=a.limit,w=e[s(717)](f,n);if(e.tpyqi(w,l.length)){let b=new Uint8Array(e[s(494)](2,w));b[s(1777)](l),a[s(1879)]=b}return a[s(663)]=w,e.staRP(w,m)&&(a[s(1603)]=w),f}else return{bytes:_0x28a44b,offset:0,limit:_0x6439b3[s(551)]}}function ee(a,n){let s=t,l=a.offset;if(e.staRP(e[s(1422)](l,n),a.limit))throw new Error(e[s(821)]);return a[s(663)]+=n,l}function ae(a,n){let s=t,l=e[s(867)](ee,a,n);return a[s(1879)].subarray(l,e[s(374)](l,n))}function ce(a,n){let s=t,l=e[s(370)](se,a,n.length);a.bytes[s(1777)](n,l)}function P(a,n){let s=t,l=e[s(1016)](ee,a,n),f=String[s(1565)+"Code"],m=a.bytes,w="\uFFFD",b="";for(let g=0;g<n;g++){let C=m[e[s(717)](g,l)],I,M,K,J;e[s(1461)](e[s(649)](128,C),0)?b+=e[s(1917)](f,C):e[s(1716)](e[s(649)](224,C),192)?e.IbJFr(e[s(1581)](g,1),n)?b+=w:e[s(1489)](e[s(713)],e[s(1683)])?(I=m[e[s(1038)](e[s(1581)](g,l),1)],e[s(1489)](e[s(1838)](192,I),128)?b+=w:(J=(31&C)<<6|63&I,J<128?b+=w:(b+=e[s(662)](f,J),g++))):(this[s(1465)+"er"]&&_0x21b2e5["removeEventListe"+s(1429)](e[s(394)],this[s(1639)+s(778)]),this[s(1465)+"er"]&&_0x158078["removeEventListe"+s(1429)]("offline",this._handleOffLine),this[s(1465)+"er"]&&_0x5a378b[s(1100)+s(1790)+"ner"](e[s(1013)],this[s(1055)+"ageHide"]),this[s(1465)+"er"]&&_0x34cff2[s(1100)+s(1790)+"ner"](e.fiMTo,this[s(1055)+s(479)])):e[s(1860)](e[s(1710)](240,C),224)?e[s(1655)](e[s(1528)](g,2),n)?b+=w:e.kHyMR!==s(1536)?_0x486b2f[s(1964)]()[s(1941)](()=>{let ne=s;this[ne(1918)+ne(1896)]()}):(I=m[e[s(450)](g+l,1)],M=m[e[s(1528)](g,l)+2],e[s(1448)](e.vYbWW(e.VVlwX(I,e[s(1262)](M,8)),49344),32896)?b+=w:(J=e.mgNbB(e[s(1096)](e[s(1863)](e[s(1856)](15,C),12),e[s(1488)](63,I)<<6),e[s(1988)](63,M)),e.nndmJ(J,2048)||e[s(1463)](J,55296)&&e[s(592)](J,57343)?b+=w:e.JsPWg(e[s(1302)],s(1787))?(b+=f(J),g+=2):_0x339864[s(973)](_0x56e5e6))):e.pMeUt(248,C)==240?e[s(1478)](e.qkhLo(g,3),n)?b+=w:(I=m[e.TpTpH(g+l,1)],M=m[e[s(1904)](g+l,2)],K=m[g+l+3],e[s(1506)]((e[s(687)](I,M<<8)|e[s(569)](K,16))&12632256,8421504)?b+=w:(J=e[s(1591)](e[s(787)](e[s(385)](e[s(759)](7,C),18),e[s(966)](e[s(511)](63,I),12))|e[s(1023)](e.uRdhe(63,M),6),e[s(400)](63,K)),e.fOOpp(J,65536)||e[s(1672)](J,1114111)?b+=w:(J-=65536,b+=e[s(370)](f,e.yoOrJ(e[s(1564)](J,10),55296),e.NjSVR(1023,J)+56320),g+=3))):b+=w}return b}function q(a,n){let s=t,l={oAVNc:e[s(1620)],JrLEI:e.IpWQK,XRMts:e[s(652)],aWcHZ:e[s(977)],vmiSR:e[s(1678)],NcvKx:e.wfrdE},f=n[s(551)],m=0;for(let C=0;C<f;C++){let I=n[s(1458)+"At"](C);e[s(1430)](I,55296)&&e[s(592)](I,56319)&&e[s(1297)](C+1,f)&&(I=e[s(1575)](e[s(1542)](e[s(1862)](I,10),n[s(1458)+"At"](++C)),56613888)),m+=e[s(1801)](I,128)?1:I<2048?2:I<65536?3:4}e.cIEYG(me,a,m);let w=se(a,m),b=a[s(1879)];for(let C=0;e[s(869)](C,f);C++){let I=n[s(1458)+"At"](C);if(e[s(1430)](I,55296)&&I<=56319&&e[s(1297)](e.HoFxs(C,1),f)&&(I=e[s(537)](e[s(593)](I<<10,n[s(1458)+"At"](++C)),56613888)),e[s(876)](I,128))b[w++]=I;else{if(e.lXQrU(I,2048))b[w++]=e.ZyZqs(e[s(669)](e[s(1564)](I,6),31),192);else if(e[s(1617)]("PHOyO",e[s(627)])){if(e.DOald(I,65536))b[w++]=e[s(1421)](e[s(635)](I,12)&15,224);else if(e[s(1283)]("VgNlf",e[s(386)]))for(var g in _0x540b23)sNhWbS.gtXIV(_0x310880,_0x266e55,g,{get:_0x2c6cd6[g],enumerable:!0});else b[w++]=e[s(1108)](I,18)&7|240,b[w++]=e.jHgZh(e.PYiOz(e[s(1147)](I,12),63),128);b[w++]=e[s(1264)](I>>6&63,128)}else{let M=this[s(1884)][s(1968)+s(989)]instanceof _0x5e2af7?{force:!!this._options[s(1968)+s(989)].force,encoding:this[s(1884)][s(1968)+"ncoding"].encoding?this[s(1884)][s(1968)+s(989)][s(1098)].replace(/\s/g,"").toLowerCase():""}:{force:!1,encoding:this[s(1884)][s(1968)+s(989)]?this[s(1884)]["payloadE"+s(989)][s(865)](/\s/g,"")[s(1697)+s(1197)]():""},K=_0x403f45[s(1968)+"ncoding"]?_0x137ae0[s(1968)+s(989)][s(865)](/\s/g,"")["toLowerC"+s(1197)]():"",J=this[s(1884)][s(439)+s(1269)]instanceof _0x5b7431?{force:!!this[s(1884)][s(439)+s(1269)][s(477)],type:this._options[s(439)+s(1269)][s(1155)]?this[s(1884)][s(439)+s(1269)][s(1155)][s(865)](/\s/g,"")[s(1697)+"ase"]():""}:{force:!1,type:this[s(1884)][s(439)+s(1269)]?this[s(1884)]["payloadT"+s(1269)][s(865)](/\s/g,"")["toLowerC"+s(1197)]():""},ne=_0x522aaf[s(439)+s(1269)]?_0xc123ba[s(439)+s(1269)][s(865)](/\s/g,"")[s(1697)+s(1197)]():"",st=J.force?J[s(1155)]:ne||J[s(1155)],U=M[s(477)]?M[s(1098)]:K||M.encoding,G=[l.oAVNc,l.JrLEI,l[s(1170)],l.aWcHZ],Re=[l[s(1509)],l.NcvKx];this[s(1884)][s(1627)+s(1752)+s(1773)+"ad"]&&G[s(1555)](st)&&(!U||Re[s(1555)](U))?_0x46b6b5.textPayload=_0x1ac6fb(_0x514f01[s(1526)],0,_0x1e46a1[s(1526)].byteLength):_0x55c77f[s(1240)+s(1830)]=""}b[w++]=e.VeRse(63,I)|128}}}function $(a,n){let s=t,l=e[s(1426)](se,a,n[s(1603)]),f=a.bytes,m=n[s(1879)];for(let w=0,b=n[s(1603)];e[s(876)](w,b);w++)f[w+l]=m[w]}function re(a){let n=t;if(e[n(1950)](e.LarDb,e[n(1116)]))return a[n(1879)][ee(a,1)];try{this[n(1880)]?.close(),this._qosDB=void 0}catch(s){_0x1ed5df[n(973)](s)}}function et(a,n){let s=t;if(e[s(1036)]===e[s(653)])return _0x49a0f2(_0x2e2e57);{let l=se(a,1);a[s(1879)][l]=n}}function ge(a){let n=t,s=0,l=0,f;do if(e[n(1981)]("smUst",e.jZYDt))try{return e[n(1695)](e.fmvyn,typeof _0x4e81b8)&&(e[n(1612)](_0x40809c,_0x128e76)||_0xcc733e[n(1115)]&&e[n(348)](_0x2d0c8b[n(1115)],_0x1f6c88))||e[n(977)]!=typeof _0x5e3f6f?"":(_0x23f2d0[n(1316)](_0x1a910b),n(1561)+n(1486))}catch{return e[n(1795)](e[n(977)],typeof _0x444b6c)?e[n(1620)]:""}else f=re(a),s<32&&(l|=e[n(1719)](127,f)<<s),s+=7;while(e.NQQuq(128,f));return l}function me(a,n){let s=t;for(n>>>=0;e.SQgTR(n,128);)e[s(1343)](et,a,e.KKoIM(e[s(649)](127,n),128)),n>>>=7;e[s(2005)](et,a,n)}function It(a,n){let s=t,l={UnuAs:function(g,C,I){return g(C,I)},LixgQ:function(g,C){return e[F(1492)](g,C)},GRBsk:function(g,C){return g+C}},f=0,m=0,w=0,b;if(b=e[s(1152)](re,a),f=e.HMeyB(127,b),e.pqBwz(128,b)&&(b=re(a),f|=e[s(385)](e[s(1965)](127,b),7),128&b))if(e[s(508)](e.qupBi,e[s(1951)])){if(b=e.yCqjh(re,a),f|=e[s(951)](127&b,14),128&b&&(b=e.CFczo(re,a),f|=(127&b)<<21,e[s(465)](128,b))){if(e.VcOeR===e[s(1207)])this["_binaryT"+s(1269)]=_0x4c6278,this[s(1703)]&&(this[s(1703)].binaryType=_0x59e79c);else if(b=e.VJfwP(re,a),m=127&b,e[s(1106)](128,b)&&(b=e.ZuTmC(re,a),m|=(127&b)<<7,e[s(1700)](128,b)&&(b=e[s(1966)](re,a),m|=e[s(1863)](127&b,14),128&b&&(b=e[s(1966)](re,a),m|=e[s(951)](127&b,21),128&b))))if(e[s(830)](s(1299),e[s(1462)]))b=re(a),w=127&b,e[s(380)](128,b)&&(b=e.wpdVJ(re,a),w|=e[s(957)](e[s(669)](127,b),7));else{let g=glgECj[s(1643)](_0x101864,_0x4c4fd9,_0x1906fa[s(1603)]),C=_0x355423.bytes,I=_0x5d9008[s(1879)];for(let M=0,K=_0x2b990d.limit;glgECj.LixgQ(M,K);M++)C[glgECj[s(1317)](M,g)]=I[M]}}}else return new _0x534f89(_0x764773,{message:_0x1bf6ca,code:_0x268da4,error:_0x35e28b});return{low:e.sZkEG(f,e[s(1262)](m,28)),high:e[s(1748)](m,4)|e[s(1869)](w,24),unsigned:n}}function mt(a,n){let s=t,l=e.SlEfM(n.low,0),f=e.PaYuO(e.Flsib(e[s(1559)](n[s(570)],28),e[s(569)](n[s(1253)],4)),0),m=e[s(839)](n[s(1253)],24),w=e[s(1283)](0,m)?e[s(1058)](0,f)?e[s(1553)](l,16384)?e[s(794)](l,128)?1:2:l<2097152?3:4:e[s(1400)](f,16384)?e[s(496)](f,128)?5:6:e[s(794)](f,2097152)?7:8:e.GpZRf(m,128)?9:10,b=e[s(1040)](se,a,w),g=a[s(1879)];switch(w){case 10:g[b+9]=e[s(1559)](m,7)&1;case 9:g[e.FzTNt(b,8)]=e[s(404)](9,w)?e[s(1945)](128,m):e[s(783)](127,m);case 8:g[e[s(1514)](b,7)]=w!==8?e[s(1204)](e[s(1006)](f,21),128):e[s(1559)](f,21)&127;case 7:g[b+6]=e[s(402)](7,w)?e[s(1191)](f>>>14,128):e.WPuuK(e[s(1168)](f,14),127);case 6:g[e[s(591)](b,5)]=e.tsDPM(6,w)?f>>>7|128:e.vYbWW(f>>>7,127);case 5:g[b+4]=e[s(962)](5,w)?e.KofiB(128,f):e[s(400)](127,f);case 4:g[e[s(591)](b,3)]=e[s(1818)](4,w)?e[s(1460)](l>>>21,128):e[s(571)](e.pNQrq(l,21),127);case 3:g[b+2]=e.HlLjh(3,w)?e.CwOMz(l,14)|128:e.cxscv(e.egSRH(l,14),127);case 2:g[e[s(1514)](b,1)]=e[s(402)](2,w)?e[s(1670)](l>>>7,128):l>>>7&127;case 1:g[b]=e[s(1714)](1,w)?e[s(449)](128,l):e[s(732)](127,l)}}function nn(a){let n=t;if(e[n(1688)](e[n(903)],e.eLAOf))return v(a);e[n(668)](_0x29cf35,_0x4a0997,18),_0x5a2a76(_0x25bef7,_0x3d21d8)}function Ht(a){return e[t(824)](S,a)}let rn=65536,ti=e[t(520)],Ee=e[t(494)](rn,rn),Ce=e[t(1970)](Ee,Ee),sr=e[t(1586)](Ce,2),Be=String[t(1471)+"e"][t(1458)+"At"];class xe{constructor(n,s,l){let f=t;this[f(614)]=!0,this[f(570)]=e.QynpL(0,n),this[f(1253)]=e.haVfn(0,s),this[f(645)]=!!l}static[t(614)](n){let s=t;return e[s(1140)](e[s(1987)],e.nlBfR)?n&&n.isLong===!0:_0x3482b8&&e[s(1461)](!0,_0xd46f0[s(614)])}static fromBits(n,s,l){return new xe(n,s,l)}static[t(1326)+"s"](n,s,l){let f=t;return l?xe[f(1326)+"sLE"](n,s):xe[f(1326)+"sBE"](n,s)}static[t(1326)+"sLE"](n,s){let l=t;return new xe(e[l(776)](e.ZyZqs(n[0]|e.MqEfU(n[1],8),e.pNWnP(n[2],16)),e.MqEfU(n[3],24)),e[l(1264)](e[l(1591)](n[4],n[5]<<8),e.ziMoD(n[6],16))|n[7]<<24,s)}static[t(1326)+t(1425)](n,s){let l=t;return new xe(e[l(449)](e[l(1485)](e[l(1191)](n[4]<<24,n[5]<<16),e[l(1447)](n[6],8)),n[7]),e[l(1460)](e[l(375)](e[l(1056)](e[l(1262)](n[0],24),e.pNWnP(n[1],16)),e.nmcLx(n[2],8)),n[3]),s)}static[t(848)](n){let s=t;return e[s(1688)](n,ti)?fl:new xe(e[s(1740)](e[s(578)](e[s(1507)](e[s(1670)](Be[s(913)](n,0),Be[s(913)](n,1)<<8),Be.call(n,2)<<16),e.QwFNL(Be[s(913)](n,3),24)),0),e[s(871)](e[s(528)](e.WuERW(Be[s(913)](n,4)|Be.call(n,5)<<8,e[s(1447)](Be[s(913)](n,6),16)),e[s(1241)](Be[s(913)](n,7),24)),0),!0)}[t(1026)](){let n=t;return String["fromChar"+n(1424)](255&this[n(570)],e[n(1394)](this[n(570)],8)&255,e[n(1748)](this[n(570)],16)&255,this[n(570)]>>>24,e[n(1718)](255,this[n(1253)]),e[n(1810)](e[n(366)](this[n(1253)],8),255),e.oBDhm(e[n(698)](this.high,16),255),e[n(1006)](this[n(1253)],24))}static[t(1644)+"er"](n,s=!0){let l=t;if(isNaN(n))return s?Gp:fl;if(s){if(n>=Ce)return jp}else{if(n<=-sr)return Wp;if(e[l(1463)](e.FzTNt(n,1),sr))return qp}return xe[l(955)](n%Ee|0,e[l(1656)](n/Ee,0),s)}toNumber(){let n=t,s={hhMFt:function(l,f){return e.nvnzG(l,f)},eMyET:function(l,f){return e[F(1810)](l,f)},ZVZpt:function(l,f){return e[F(410)](l,f)}};if(e[n(686)](n(1265),e[n(863)]))_0x26572f[_0x2c793f++]=GKUjfd.hhMFt(_0x2b0cf0>>18&7,240),_0x623ea6[_0x5309d7++]=GKUjfd.eMyET(GKUjfd.ZVZpt(_0x4668f1,12),63)|128;else return this.unsigned?e[n(593)](e[n(494)](this[n(1253)]>>>0,Ee),e[n(1559)](this[n(570)],0)):e[n(1514)](this[n(1253)]*Ee,e[n(366)](this[n(570)],0))}[t(676)](){let n=t;return this[n(1253)]===0&&e.AARDb(0,this[n(570)])}add(n){let s=t;xe[s(614)](n)||(n=xe[s(1644)+"er"](n));let l=e[s(864)](this[s(1253)],16),f=e[s(1977)](65535,this[s(1253)]),m=e[s(1748)](this[s(570)],16),w=e[s(1329)](65535,this[s(570)]),b=e[s(1740)](n[s(1253)],16),g=65535&n[s(1253)],C=e.EzKth(n[s(570)],16),I=e[s(1263)](65535,n.low),M=0,K=0,J=0,ne=0;return ne+=w+I,J+=e[s(1028)](ne,16),ne&=65535,J+=e[s(450)](m,C),K+=J>>>16,J&=65535,K+=e[s(1330)](f,g),M+=e[s(1559)](K,16),K&=65535,M+=e.KlimG(l,b),M&=65535,xe[s(955)](e[s(385)](J,16)|ne,e[s(1656)](M<<16,K),this[s(645)])}[t(354)](n){let s=t;if(e[s(1716)](s(1378),s(1378)))return xe[s(614)](n)||(n=xe[s(1644)+"er"](n)),e[s(404)](this.unsigned,n[s(645)])&&e[s(1558)](e.etRLo(this.high,31),1)&&e[s(557)](n[s(1253)]>>>31,1)?!1:this[s(1253)]===n[s(1253)]&&e[s(1158)](this[s(570)],n[s(570)]);{let l=_0x257c8a.key;e[s(1034)](void 0,l)&&(e[s(886)](_0x10bc19,_0xf8fc70,10),e.kpZql(_0x295820,_0xc771a,l));let f=_0x390a71.value;e.IgYwe(void 0,f)&&(_0x169c23(_0x48f03a,18),_0x4f4c73(_0x256e7c,f))}}addOne(){let n=t;return e[n(1716)](-1,this[n(570)])&&e[n(615)](-1,this[n(1253)])?xe[n(955)](0,0,this.unsigned):e[n(1158)](-1,this[n(570)])?xe[n(955)](0,this[n(1253)]+1,this[n(645)]):xe[n(955)](e[n(1784)](this.low,1),this[n(1253)],this[n(645)])}[t(710)](n){let s=t;return n?this[s(1999)+"E"]():this[s(1961)+"E"]()}[t(1999)+"E"](){let n=t,s=this.high,l=this[n(570)];return[e[n(511)](255,l),e[n(917)](e[n(493)](l,8),255),e[n(1709)](e[n(696)](l,16),255),e[n(1740)](l,24),e[n(380)](255,s),e.AQdne(e[n(1540)](s,8),255),e[n(649)](e[n(793)](s,16),255),e[n(398)](s,24)]}[t(1961)+"E"](){let n=t,s=this[n(1253)],l=this.low;return[e[n(1540)](s,24),e[n(632)](s,16)&255,e[n(1988)](e[n(366)](s,8),255),e[n(915)](255,s),e[n(1740)](l,24),e[n(1402)](l>>>16,255),e[n(1958)](e.Pomif(l,8),255),e[n(1173)](255,l)]}}let fl=new xe(0,0,!1),Gp=new xe(0,0,!0),qp=xe.fromBits(-1,2147483647,!1),jp=xe[t(955)](-1,-1,!0),Wp=xe[t(955)](0,-2147483648,!1);var sn=(function(a){let n=t,s=e[n(982)].split("|"),l=0;for(;;){switch(s[l++]){case"0":a[a[e[n(1196)]]=5004]="MESSAGE_"+n(930);continue;case"1":a[a[e[n(1132)]]=5001]=e[n(1132)];continue;case"2":return a;case"3":a[a.MAX_RETRIES_ERROR=5003]=e[n(452)];continue;case"4":a[a[e[n(1362)]]=5005]="OPEN_ERROR";continue;case"5":a[a[e[n(435)]]=5002]=e[n(435)];continue}break}})({});class or{constructor(n){let s=t;this[s(1155)]=n,this[s(1200)]=null}}class xl extends or{constructor(n,s){let l=t;super(n),this[l(1814)]=s&&s[l(1814)]||null}}class hl extends or{constructor(n,s){let l=t,f=e[l(1381)][l(1916)]("|"),m=0;for(;;){switch(f[m++]){case"0":this[l(1386)]=s&&s.filename||"";continue;case"1":super(n);continue;case"2":this[l(1035)]=s&&s.error||null;continue;case"3":this[l(371)]=s&&s[l(371)]||0;continue;case"4":this[l(972)]=s&&s.colno||0;continue;case"5":this[l(1341)]=s&&s.code||5001;continue;case"6":this[l(1814)]=s&&s[l(1814)]||"";continue}break}}}class pl extends or{constructor(n,s){let l=t;super(n),this[l(1341)]=s&&s[l(1341)]||0,this[l(446)]=s&&s[l(446)]||"",this[l(1150)]=s&&s[l(1150)]||!1,this[l(1057)+l(1853)]=s&&s["willReco"+l(1853)]||!1}}class gl extends or{constructor(n,s){let l=t;super(n),this[l(1030)]=s&&s[l(1030)]||null}}class ml extends gl{constructor(n,s){let l=t;super(n),this[l(1030)]=s&&s.data||null,this[l(1814)]=s&&s[l(1814)]||null}}class wl extends or{constructor(n,s){let l=t;super(n),this.data=s&&s[l(1030)]||null}}function lt(a,{message:n,code:s,error:l}){return new hl(a,{message:n,code:s,error:l})}function wt(a,{code:n,reason:s,wasClean:l,willReconnect:f}){return new pl(a,{code:n,reason:s,wasClean:l,willReconnect:f})}function _l(a,{data:n,message:s}){return new ml(a,{data:n,message:s})}function yl(a,{data:n}){return new wl(a,{data:n})}function ya(a,{message:n}){return new xl(a,{message:n})}class bl{constructor(n,s){let l=t;this[l(1715)+"s"]=n,this[l(1975)+"es"]=s,this[l(1815)+l(987)]=0,this[l(579)+l(1257)+l(826)+"t"]=0}["resetEndpointCon"+t(1520)](){let n=t;this[n(1815)+n(987)]=0,this[n(579)+n(1257)+n(826)+"t"]=0}[t(991)+"es"](){let n=t;this[n(579)+"ndpointT"+n(826)+"t"]=0}["getCurre"+t(573)+"nt"](){let n=t;return this.endpoints[this[n(1815)+n(987)]]}[t(560)+t(573)+t(1928)+t(519)](){let n=t;if(e[n(521)](e[n(1049)],e[n(480)]))return this[n(579)+n(1257)+"riesCount"];_0x5788fe=e.ikAVL(e.Spqkj(e[n(385)](e[n(732)](7,_0x35b94e),18),e.hykBN(63,_0xc0eb7d)<<12)|e.sYejJ(e[n(1329)](63,_0x5a3205),6),63&_0x5bdd8f),e[n(407)](_0x8c9400,65536)||_0x412693>1114111?_0x2109a8+=_0x59dc12:(_0x4fb204-=65536,_0x33e449+=e[n(734)](_0x31ed71,e[n(635)](_0x2c2c76,10)+55296,e.YiPjG(e.AQdne(1023,_0x262254),56320)),_0x417df0+=3)}[t(740)+"chMaxTries"](){let n=t;return!!(e[n(1623)](this[n(1815)+"ndex"],this.endpoints[n(551)])||e[n(1605)](this["currentI"+n(987)],e[n(804)](this.endpoints[n(551)],1))&&e[n(1365)](this["currentE"+n(1257)+n(826)+"t"],this[n(1975)+"es"]))}[t(516)+t(1248)+t(543)+t(1645)+t(470)](){let n=t;return e[n(1860)](this.currentIndex,this[n(1715)+"s"][n(551)])?!0:e[n(828)](this[n(579)+n(1257)+"riesCount"],this[n(1975)+"es"])}[t(505)+t(1260)+t(1449)+t(997)+"unt"](){let n=t;return e[n(962)](e.THhZz,n(1524))?this[n(1870)+n(1033)]?.[n(560)+n(573)+"ntTriesCount"]()||0:(this[n(579)+n(1257)+n(826)+"t"]=1,this[n(1815)+n(987)]++,this[n(1715)+"s"][this[n(1815)+n(987)]])}[t(560)+"ntEndpoi"+t(745)+"ateCount"](){let n=t;return this[n(579)+n(1257)+"riesCount"]++,this[n(560)+"ntEndpoint"]()}}let ar=(e[t(992)](e[t(660)],typeof globalThis)&&e[t(823)](e.WnzIs,globalThis[t(1840)+"tor"][t(361)])||e[t(993)](t(1821)+"d",typeof window)&&e.PqSAM(e.WnzIs,window[t(1840)+t(552)][t(361)]))&&e[t(1580)](e[t(660)],typeof document),Ln=e[t(992)](e[t(660)],typeof globalThis)&&(e[t(1502)](e[t(1210)],globalThis[t(1840)+"tor"][t(361)])||"Dedicate"+t(1050)+t(1704)+"pe"===globalThis.constructor.name)&&e[t(425)](e.Hdmxu,typeof tt),ni=(e[t(992)](e[t(660)],typeof globalThis)&&e[t(1698)](e[t(1210)],globalThis[t(1840)+"tor"].name)||e[t(660)]==typeof globalThis||e[t(992)](e[t(660)],typeof globalThis)&&!!globalThis["WeixinJS"+t(1043)])&&e[t(660)]!=typeof wx,ri=e[t(660)]!=typeof globalThis&&(e.sEjvJ===globalThis[t(1840)+t(552)][t(361)]||e.ltiSH===globalThis["construc"+t(552)][t(361)]||e[t(889)](t(1423)+t(1544)+t(959),globalThis[t(1840)+"tor"][t(361)]))&&e[t(1580)](e.Hdmxu,typeof self),Kp=e.jwvQs(e[t(660)],typeof globalThis)&&e[t(1513)](t(1993),globalThis[t(1840)+t(552)][t(361)])&&e[t(568)](e[t(660)],typeof global)&&e[t(1475)](e[t(1210)],global[t(1840)+t(552)].name)&&e[t(1110)](e.Hdmxu,typeof process)&&!!process[t(475)];class ba{constructor(){this._listeners={}}[t(1314)](n,...s){let l=t,f={XmbEM:function(w,b){return e[F(1618)](w,b)},TrkDG:function(w,b){return w<b},Itofm:function(w,b){return e[F(1158)](w,b)},gCkZy:function(w,b){return e.HMeyB(w,b)},IVgyQ:function(w,b){return e.FlWWy(w,b)},HZgzE:function(w,b){return e[F(1828)](w,b)}},m=this[l(1727)+"rs"][n];if(m)m[l(523)]().forEach(w=>w.fn[l(1156)](w[l(730)],s));else if(e[l(498)](e[l(471)],n)&&!this.onerror)if(e[l(402)](e.htfLp,e[l(1530)])){let w=0,b=0;for(let g=0;f[l(706)](g,_0x372fe9[l(551)]);++g)b=_0x1f9517[l(1458)+"At"](g),f[l(1738)](b,128)?w+=1:b<2048?w+=2:f[l(1836)](f[l(1325)](64512,b),55296)&&f[l(1836)](f[l(1359)](64512,_0x2d0c60[l(1458)+"At"](f.HZgzE(g,1))),56320)?(++g,w+=4):w+=3;return w}else{let w=s[l(551)]&&s[0];if(e.GFVXi(w,Error))throw w;let b=new Error(e[l(593)](e.ZiWeA,w?" ("+w[l(1814)]+")":""));throw b[l(1442)]=w,w}return this}off(n,s){let l=t;if(e[l(1776)](void 0,n))this._listeners={};else if(e[l(1502)](void 0,s))this._listeners[n]=null;else{let f=this._listeners[n];if(f)for(let m=0;e[l(1398)](m,f[l(551)]);)f[m].fn===s?f.splice(m,1):++m}return this}on(n,s,l){let f=t;return(this[f(1727)+"rs"][n]||(this[f(1727)+"rs"][n]=[]))[f(1113)]({fn:s,ctx:l||this}),this}}class $p extends ba{[t(584)+t(1351)+t(1282)](n){let s=t;return e[s(843)]===e[s(843)]?n.errMsg||n[s(1340)]?(s(602)+" "+(n[s(401)]||"")+" code: "+(n[s(1340)]||"")).trim():JSON.stringify(n):_0x47081b[s(401)]||_0x476207[s(1340)]?(s(602)+" "+(_0x46c6a6.errMsg||"")+" code: "+(_0x85f4bb[s(1340)]||""))[s(1654)]():_0x295133[s(1647)+"y"](_0x30cc53)}constructor(n,s,l){let f=t;super(),this[f(1823)]=null,ni&&wx[f(1808)+"ocket"]&&(this[f(1823)]=wx[f(1808)+f(467)]({url:n,protocols:s,header:l,fail:this["_createS"+f(1337)+f(1281)][f(933)](this),success:this[f(367)+f(850)+f(395)+f(1905)][f(933)](this)})),Ln&&tt[f(1808)+f(467)]&&(this[f(1823)]=tt[f(1808)+f(467)]({url:n,protocols:s,header:l,fail:this["_createS"+f(1337)+f(1281)].bind(this),success:this[f(367)+f(850)+"cessHand"+f(1905)][f(933)](this)}))}[t(367)+t(850)+t(395)+"ler"](){Promise.resolve().then(()=>{let n=F;this[n(1918)+n(1896)]()})}[t(367)+"ocketFai"+t(1281)](n){Promise.resolve().then(()=>{let s=F,l=e[s(1455)](lt,e[s(471)],{message:this[s(584)+s(1351)+"age"](n)});this[s(1314)](e.iGUon,l);let f=e[s(1426)](wt,e[s(898)],{reason:this[s(584)+s(1351)+s(1282)](n)});this[s(1314)](e[s(898)],f)})}[t(1918)+t(1896)](){let n=t,s={Gtmhz:e[n(898)]};n(1230)!==e.mDZON?this[n(1918)+n(1896)]():(this._socket[n(1724)](l=>{let f=n,m={afDeT:function(w,b){return e.kguSd(w,b)},lIaMZ:f(1035),RHbuo:function(w,b){return e[f(1923)](w,b)},xDDEP:e.ZiWeA,gTYwy:function(w,b){return e[f(1904)](w,b)}};if(e[f(1034)](f(981),f(1415)))this[f(1314)](e[f(1792)],e[f(1377)](yl,e.VzZKJ,{...l,data:l[f(401)]||""}));else{let w=this[f(1727)+"rs"][_0x14c87f];if(w)w[f(523)]()[f(472)](b=>b.fn[f(1156)](b.ctx,_0x48b3ce));else if(YSQVgK[f(822)](YSQVgK[f(1440)],_0x2ad1b0)&&!this[f(1798)]){let b=_0x314440[f(551)]&&_0x1c6851[0];if(YSQVgK[f(1304)](b,_0x2e1a46))throw b;let g=new _0x6e8b88(YSQVgK[f(529)]+(b?YSQVgK.gTYwy(YSQVgK[f(531)](" (",b[f(1814)]),")"):""));throw g[f(1442)]=b,b}return this}}),this[n(1823)][n(819)](l=>{let f=n;this.emit(s.Gtmhz,wt(s[f(1962)],{...l}))}),this[n(1823)][n(750)+"e"](l=>{let f=n;if(e[f(1058)](e.Iknpl,e[f(356)]))return new _0x2d29d7(_0x2206d4,{code:_0x4f3c98,reason:_0x36f734,wasClean:_0x19c040,willReconnect:_0x17eb92});this.emit(e[f(715)],e[f(668)](_l,e.FXZBR,{...l}))}),this._socket[n(1403)](l=>{let f=n;this[f(1314)](e.iGUon,e[f(1350)](lt,e.iGUon,{...l,message:l[f(401)]||""}))}))}[t(1751)](n){let s=t,l={xTiXL:function(f,m){return e[F(1480)](f,m)},kYhMC:"huJIB",ECMiQ:s(1844),BYldA:e.iGUon,gUTVW:function(f,m,w){return e[s(1040)](f,m,w)}};if(e[s(1789)](n,Uint8Array))if(e[s(1868)]===e[s(1595)]){let f={PJnei:e[s(748)],shklB:function(C,I,M,K){return e[s(1199)](C,I,M,K)},QXDmM:e[s(413)],XhbiA:function(C,I,M,K){return e[s(1199)](C,I,M,K)},znIwJ:e[s(1910)],jIlKT:e.qahzp,kAttT:e[s(1123)]},[m,w]=_0xef77c3(_0x4f2c82),b=_0x227ab7(m),g=0;return _0x158283[s(472)](C=>{let I=s;_0xc2a4a7[I(973)](f[I(549)],C,C.service),g=f[I(1245)](_0x5b5497,0,b,g),_0x41a765.log(f.QXDmM,g),g=f[I(719)](_0x3c438a,b,g,C[I(1128)]||0),_0xa7b12c[I(973)](f.znIwJ,g),g=f[I(1245)](_0x4e8816,w[C["cursor_n"+I(1766)]],b,g),_0x29bb39[I(973)](f[I(1931)],g),g=f[I(1245)](_0x355803,C[I(1730)+I(1766)],b,g),_0x4c4031[I(973)](f.kAttT,g),g=f.shklB(_0x3f2919,_0x59af4b.fromNumber(C[I(457)]||_0x34d95b),b,g),_0xe244d0[I(973)](I(881),g)}),{frameType:_0x287e47,headers:[{key:e[s(369)],value:_0x5e9baf}],payload:b}}else{let f=n[s(1115)].slice(n[s(1841)+"et"],e[s(771)](n.byteLength,n[s(1841)+"et"]));this[s(1823)]&&this[s(1823)][s(1751)]({data:f,fail:m=>{let w=s;l[w(1418)](l[w(583)],l[w(1266)])?this[w(1727)+"rs"]={}:this.emit(l[w(1090)],l[w(1585)](lt,w(1035),{message:this[w(584)+w(1351)+"age"](m)}))}})}else this[s(1823)]&&this[s(1823)][s(1751)]({data:n,fail:f=>{let m=s;this[m(1314)](e.iGUon,e.EPROD(lt,e[m(471)],{message:this[m(584)+m(1351)+"age"](f)}))}})}[t(1978)](n,s){let l=t;this[l(1823)]&&this[l(1823)][l(1978)]({code:n,reason:s})}[t(1258)+t(1745)](n,s){let l=t;e[l(1140)](e[l(949)],e.InRvQ)?(_0x545a73[_0xc68250++]=e.eCGXh(e[l(382)](_0x539496,12),224),_0x300bed[_0x2c37cf++]=e[l(1421)](e[l(1108)](_0x4f343c,6)&63,128),_0x29106c[_0x18426e++]=e[l(616)](e.AeLqo(63,_0x58fbac),128)):this.on(n,s)}[t(1100)+t(1790)+t(1429)](n,s){let l=t;if(e[l(1973)]!==e[l(1973)])return _0x28129f|=0,{low:_0x30201f,high:_0x4ed050>>31,unsigned:_0x29494d>=0};this[l(1311)](n,s)}get readyState(){return this[t(1823)].readyState}get[t(1601)+"pe"](){let n=t;return this[n(1823)][n(1601)+"pe"]}set[t(1601)+"pe"](n){}get[t(499)](){let n=t,s={RrbrN:e.iGUon,rEHqU:function(l,f,m){return e.BUHph(l,f,m)}};if(e[n(1479)](e.Vrauf,e[n(1095)]))return this[n(1823)][n(499)];this[n(1314)](mcogXV[n(1772)],mcogXV[n(1764)](_0x1a6a61,mcogXV.RrbrN,{message:this["_formatE"+n(1351)+n(1282)](_0x105f35)}))}get protocol(){let n=t;if(e.JxIDJ(e[n(1687)],n(701)))return this[n(1823)][n(1333)];{let s=e[n(1535)][n(1916)]("|"),l=0;for(;;){switch(s[l++]){case"0":_0x3e9a0c=[sNhWbS[n(970)],n(1487),sNhWbS.qhgVs,sNhWbS.cjMZn,sNhWbS[n(1493)]];continue;case"1":sNhWbS.esVQG(_0x46747a,f=>({...f,get:(m,w,b)=>_0x12d880(m,w)||f[n(626)](m,w,b),has:(m,w)=>!!_0x4ec180(m,w)||f[n(1866)](m,w)}));continue;case"2":sNhWbS[n(1484)](_0x10d575);continue;case"3":_0x50b4b8=[sNhWbS.WUZfM,sNhWbS[n(1897)],sNhWbS.lBYIn,sNhWbS[n(1357)]];continue;case"4":_0x40f5cb=new _0x169358;continue;case"5":_0x9a68bb();continue}break}}}get[t(1932)+"ns"](){return this[t(1823)].extensions}get bufferedAmount(){return 0}}function Vp(a,n){let s=t;if(n)return new n(a[s(499)],a[s(1333)]);if(e[s(885)](ni,Ln))return new $p(a[s(499)],a[s(1333)],a.headers);if(e[s(885)](ar,ri)&&e[s(948)](e[s(660)],typeof WebSocket)&&WebSocket)return new WebSocket(a[s(499)],a.protocols)}function Jp(a){let n=t,s=e[n(952)].split("|"),l=0;for(;;){switch(s[l++]){case"0":if(Ln&&tt[n(1808)+n(467)])return!0;continue;case"1":if(e[n(1001)](ar,ri)&&e[n(660)]!=typeof WebSocket&&WebSocket)return!0;continue;case"2":if(ni&&wx[n(1808)+n(467)])return!0;continue;case"3":if(a)return!0;continue;case"4":return!1}break}}function El(a,n,s){let l={ShyUS:function(w,b){return e[F(448)](w,b)},DSjFN:e.zSxDk,eNpsl:function(w,b){return e[F(1365)](w,b)},eESdp:function(w,b){return e[F(1577)](w,b)}},f=-1;async function m(w){let b=F;return l.ShyUS(w,f)?Promise.reject(new Error(l[b(1600)])):(f=w,l[b(1569)](w,s[b(551)])?Promise[b(1964)]():s[w][b(933)](a)(n,m.bind(null,l[b(1089)](w,1))))}m(0)}function vl(a){let n=t,s={zDtWn:function(l,f){return e[F(1581)](l,f)},wXKTN:function(l,f){return e[F(828)](l,f)},EVxgy:function(l,f){return e[F(1970)](l,f)}};if(e[n(587)]!==e[n(1428)]){let l=0,f=0;for(let m=0;e[n(928)](m,a[n(551)]);++m)if(e[n(1875)](e[n(747)],e.AzRqf)){let w=_0x11919d[n(1879)],b=_0x209b1e[n(663)],g=_0x3e7f44[n(1603)],C=MQduuq[n(781)](b,_0x50e356);if(MQduuq.wXKTN(C,w[n(551)])){let I=new _0x23ed50(MQduuq[n(1508)](2,C));I.set(w),_0x26777f[n(1879)]=I}return _0x3dda82.offset=C,MQduuq[n(1178)](C,g)&&(_0x458bbe[n(1603)]=C),b}else f=a[n(1458)+"At"](m),e[n(1552)](f,128)?l+=1:e[n(1398)](f,2048)?l+=2:e[n(400)](64512,f)===55296&&e[n(1158)](e[n(511)](64512,a[n(1458)+"At"](e.FzTNt(m,1))),56320)?(++m,l+=4):l+=3;return l}else return _0x10d5b2[_0x46b48f]=_0x138937,!0}function Sl(a,n,s){let l=t;if(e.gQFFr(s,n)<1)return"";let f="";for(let m=n;m<s;){let w=a[m++];if(e[l(1031)](w,127))f+=String[l(1565)+l(1424)](w);else if(e.SQgTR(w,192)&&e[l(876)](w,224))f+=String[l(1565)+"Code"](e[l(1366)](e.dfRrG(31&w,6),e[l(1709)](63,a[m++])));else if(e[l(1313)](w,224)&&e[l(937)](w,240))f+=String[l(1565)+l(1424)](e[l(1810)](15,w)<<12|e.EHyyN(e[l(1700)](63,a[m++]),6)|e[l(643)](63,a[m++]));else if(e[l(1655)](w,240))if(e[l(559)]===l(424))this._socket&&this[l(1823)].close({code:_0x15fdab,reason:_0x4fa1ed});else{let b=e[l(814)](e[l(1358)](e[l(1616)](e[l(1241)](e[l(571)](7,w),18),e[l(849)](63,a[m++])<<12)|e[l(1205)](e[l(791)](63,a[m++]),6),e.oeXFq(63,a[m++])),65536);f+=String[l(1565)+"Code"](e[l(1422)](55296,e.SlpIH(b,10))),f+=String[l(1565)+"Code"](56320+e[l(1856)](1023,b))}}return f}function Ea(a,n,s){let l=t,f={lRALf:e[l(1013)]};if(e[l(2001)]===e[l(1996)])this._isBrowser&&_0x133c58[l(1100)+l(1790)+l(1429)](f.lRALf,this[l(1055)+l(736)]),this._isBrowser&&_0xf0f856[l(1100)+"entListe"+l(1429)](l(469),this[l(1055)+"ageShow"]),this[l(1978)]();else{let m=s,w,b;for(let g=0;g<a[l(551)];++g)if(w=a[l(1458)+"At"](g),w<128)n[s++]=w;else if(e[l(1373)](w,2048))n[s++]=e[l(728)](w>>6,192),n[s++]=e.jvzPn(63&w,128);else if(e[l(1741)](e[l(1700)](64512,w),55296)&&e.OAnZb(e[l(1709)](64512,b=a[l(1458)+"At"](g+1)),56320)){let C=e.GhiSc[l(1916)]("|"),I=0;for(;;){switch(C[I++]){case"0":n[s++]=e[l(1198)](e.QWkpN(w,18),240);continue;case"1":n[s++]=e.jqmlh(e.fzAeM(w,12)&63,128);continue;case"2":n[s++]=63&w|128;continue;case"3":n[s++]=e[l(1214)](w,6)&63|128;continue;case"4":++g;continue;case"5":w=e[l(919)](65536+e[l(1447)](e[l(403)](1023,w),10),e.RIkUM(1023,b));continue}break}}else n[s++]=e[l(1485)](w>>12,224),n[s++]=e[l(963)](w>>6,63)|128,n[s++]=e[l(963)](63,w)|128;return e[l(1048)](s,m)}}async function Al(a){let n=t,s={ogCTe:"unknown "+n(446)};if(e[n(515)](e[n(945)],e[n(1832)])){let l=_0x2686d5[n(1867)+n(1457)](e[n(659)]);_0x1d24cf[n(353)+"JSONP"]=f=>{let m=n;_0x1ea6f5[m(1855)][m(1250)+m(1566)](l),_0x43b07f[m(353)+m(1934)]=void 0,_0x50692b(f&&f.msg||s[m(1871)])},l.type=e.zzVim,l[n(1005)]=e[n(1784)](_0x26353c.replace(/^ws/,e[n(1723)]),e[n(588)]);try{_0x1094f5[n(1855)][n(1989)+n(1566)](l)}catch{_0xa21b3f[n(1855)][n(1250)+"ild"](l)}}else{if(e[n(1795)](e[n(977)],typeof a)){let l=new Uint8Array(e[n(1692)](vl,a));return e[n(1915)](Ea,a,l,0),l}return e.Rraqw(a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a.buffer,a[n(1841)+"et"],a.byteLength)}}function Zp(a){let n=t,s={nCkhI:function(l,f){return e.pHYxB(l,f)},gjAgK:function(l,f){return e[F(1888)](l,f)}};if(n(1954)!==e[n(372)])sNhWbS[n(1152)](_0x15b74c,_0x48d037(_0x5df7ab[n(847)])),sNhWbS.PTcmU(_0x429dc7);else try{if(e[n(1102)]===e[n(775)]){let l=_0x946fd8.substring(0,e[n(998)](4,_0x3949a9.length)),f=l[n(1163)](_0x5560d8);_0x4dd17a[n(1113)](f)}else return e.OKAUX(e[n(977)],typeof a)&&(e[n(1612)](a,ArrayBuffer)||a[n(1115)]&&a[n(1115)]instanceof ArrayBuffer)||e[n(977)]!=typeof a?"":(JSON.parse(a),e[n(1483)])}catch{if(e[n(639)](e[n(695)],n(1720)))s[n(1242)](_0x33e1d2,this._pingPongTimeoutId),s[n(1186)](_0x431c95,this["_reconne"+n(1114)+n(1755)]),this["_pingPon"+n(1151)+"Id"]=null,this["_reconne"+n(1114)+"tId"]=null;else return e[n(977)]==typeof a?e[n(1620)]:""}}let Xp=(a,n)=>{let s=t;switch(a){case s(417):case e[s(1382)]:return{[s(893)+a]:1,"x-tt-env":n};default:return{}}};class Yp{constructor(n){let s=t;this[s(427)+s(519)]=n,this[s(1360)]=0}[t(1306)](){let n=t;this[n(1360)]++}[t(740)+t(558)+"nt"](){let n=t;if(e[n(924)](e.rdjsu,n(1584))){if(e[n(904)](_0x704883,_0x4a8ad8))return _0x1b0a06?_0x48b97e:_0x5bc2e1;if(_0x2b2a9f){if(e.ZsCNF(_0x5e8632,_0x9cd756))return _0x391588}else{if(e[n(1674)](_0x41f679,-_0x24547e))return _0x54a81b;if(e[n(1446)](e[n(1287)](_0x6ae126,1),_0x1476f6))return _0x19db88}return _0x50ef46.fromBits(e[n(1198)](e.YscPV(_0x319a4f,_0x5e8525),0),e.JXFxF(_0x52d200/_0x25b844,0),_0x45d8f6)}else return e[n(1401)](this.count,this[n(427)+n(519)])}[t(965)+t(1872)](n=0){let s=t;this[s(427)+s(519)]=n,this.count=0}}async function Qp(a){let n=t,s={eocoF:e[n(770)],KQsfR:e.Wywhp,Okexl:function(l,f){return e.toqeH(l,f)},PClBX:function(l,f){return e.toqeH(l,f)},QxILp:e.noQEN,jnIvP:e.rnynG,YeeFS:e[n(1693)],tGfxe:e[n(1408)]};return new Promise(l=>{let f=n,m={EdqWe:function(w,b){return s.Okexl(w,b)},OuqtH:s[f(1017)]};if(!ar)return s.PClBX(l,s.KQsfR);try{let w=document[f(1867)+f(1457)](s[f(349)]);window[f(353)+f(1934)]=b=>{let g=f;s[g(1991)]===g(920)?this[g(1703)]&&this[g(1703)].close(_0xf715af,_0x2b92f2):(document[g(1855)][g(1250)+g(1566)](w),window[g(353)+g(1934)]=void 0,l(b&&b[g(463)]||s[g(1017)]))},w[f(1155)]=f(1375)+f(1593),w[f(1005)]=a[f(865)](/^ws/,"http")+(f(1411)+f(1676)+f(712)+"P");try{s[f(1046)]!==s[f(1127)]?document.body[f(1989)+f(1566)](w):(_0x47c54d.body[f(1250)+f(1566)](_0x2f50d4),_0x41c692[f(353)+"JSONP"]=void 0,m[f(512)](_0x2e2575,_0x3a1d4f&&_0x22ab71[f(463)]||m[f(1625)]))}catch{if(s[f(1641)]==="HXHtg")return null;document[f(1855)][f(1250)+f(1566)](w)}}catch{window["frontier"+f(1934)]=void 0,s[f(1744)](l,f(1027)+f(446))}})}function on(a,n,s){let l=t;return!!a?.find(f=>f[l(1107)]===n&&f.value===s)}function cr(a,n){let s=t;return a?.find(l=>l.key===n)?.[s(703)]}let va=null;async function eg(){let a=t;return va||(va=Promise.resolve()[a(1941)](Ft.bind(Ft,a(620)))),va}class tg extends ba{constructor(n,s){let l=t;super(),this[l(1044)]=n,this._keyPath=s,this[l(1880)]=void 0,this[l(1725)+"mise"]=null}async[t(722)](){await this[t(1278)]()}async[t(1278)](){let n=t,s={bAzAD:function(l){return e[F(421)](l)},jKukR:function(l,f,m,w){return e[F(1199)](l,f,m,w)}};if(!this._qosDB){if(this[n(1725)+n(423)])return this[n(1725)+"mise"];try{let l=this._dbName,f=this[n(478)];this[n(1725)+n(423)]=(async()=>{let m=n,{openDB:w}=await s.bAzAD(eg);this[m(1880)]=await s[m(1011)](w,m(353)+"_"+l,1,{upgrade(b){let g=m;b[g(1008)+g(451)+"e"](l,{keyPath:f})}})})(),await this[n(1725)+n(423)]}catch(l){console[n(973)](l)}finally{this["_initPro"+n(423)]=null}}}async[t(626)](n){let s=t;if(!e[s(405)](e[s(1393)],s(754)))try{return await this[s(1278)](),this[s(1880)]?.[s(626)](this[s(1044)],n)}catch(l){console[s(973)](l)}}async set(n,s){let l=t;return await this[l(1278)](),this[l(1880)]?.put(this[l(1044)],n)}async[t(594)](n){let s=t;try{return await this[s(1278)](),this[s(1880)]?.[s(744)](this[s(1044)],n)}catch(l){console[s(973)](l)}}async clear(){let n=t;try{return await this[n(1278)](),this._qosDB?.[n(749)](this[n(1044)])}catch(s){console.log(s)}}async[t(1785)](){let n=t;return await this[n(1278)](),this._qosDB?.[n(1296)+"ys"](this[n(1044)])}async getAll(){let n=t;return await this[n(1278)](),this._qosDB?.getAll(this[n(1044)])}async[t(453)](){let n=t;try{this[n(1880)]?.[n(1978)](),this[n(1880)]=void 0}catch(s){if(e.xlCyv!==e.xlCyv)return e.Mjyub(e[n(977)],typeof _0x2109c5)?e[n(1620)]:"";console.log(s)}}get[t(1159)](){let n=t;try{return!!this[n(1880)]}catch(s){return console[n(973)](s),!1}}}class ng{constructor(n,s){let l=t;this._DBName=n,this[l(1637)]=s,this._qosDB=localStorage}async openDB(){}get[t(1129)](){let n=t;return n(353)+"_"+this[n(1681)]}async[t(626)](n){let s=t,l=this[s(1880)][s(1538)](this[s(1129)]);return JSON.parse(e[s(1001)](l,"{}"))[n]}async[t(1777)](n,s){let l=t,f=this._qosDB.getItem(this[l(1129)]),m=JSON[l(1316)](e[l(1001)](f,"{}"));return m[s||n[this[l(1637)]]]=n,this._qosDB.setItem(this[l(1129)],JSON[l(1647)+"y"](m)),s||n[this[l(1637)]]}async[t(594)](n){let s=t,l=this[s(1880)][s(1538)](this[s(1129)]),f=JSON[s(1316)](e.mCfwd(l,"{}"));return f[n]=void 0,this._qosDB.setItem(this[s(1129)],JSON[s(1647)+"y"](f))}async clear(){return this[t(1880)].clear()}async[t(1785)](){let n=t,s=this._qosDB[n(1538)](this._prefix),l=JSON[n(1316)](e[n(1762)](s,"{}"));return Object[n(1785)](l)}async[t(1066)](){let n=t,s=this[n(1880)][n(1538)](this[n(1129)]),l=JSON.parse(s||"{}");return Object.values(l)}closeDB(){return Promise[t(1964)]()}get[t(1159)](){return!!this[t(1880)]}}class rg{constructor(n,s){let l=t;this[l(1681)]=n,this[l(1637)]=s,this._qosDB=Ln?tt:ni?wx:null}async[t(722)](){}get[t(1129)](){let n=t;return n(353)+"_"+this[n(1681)]}async[t(626)](n){let s=t,l={ELatK:function(f,m){return e[F(1109)](f,m)}};if(e[s(1361)]===e[s(1361)]){let f=this[s(1880)][s(996)+s(1130)](this[s(1129)]);return JSON[s(1316)](e[s(1001)](f,"{}"))[n]}else{let f=this[s(1880)].getItem(this[s(1129)]),m=_0x432922.parse(fmniVl[s(1985)](f,"{}"));return m[_0x5e0c13||_0x21267d[this[s(1637)]]]=_0x56208e,this[s(1880)][s(1851)](this[s(1129)],_0x308cab[s(1647)+"y"](m)),_0x5defb2||_0x126e55[this[s(1637)]]}}async[t(1777)](n,s){let l=t;if(l(1963)===e[l(967)])this[l(1291)+l(1451)]?.addCount(),this[l(1314)](e[l(1125)],e[l(674)]),this._pingLossCounter?.[l(740)+l(558)+"nt"]()?this[l(1671)+l(812)]():this[l(1955)]();else{let f=this._qosDB[l(996)+l(1130)](this._prefix),m=JSON.parse(e[l(1762)](f,"{}"));return m[s||n[this[l(1637)]]]=n,this[l(1880)]["setStora"+l(1130)](this[l(1129)],JSON[l(1647)+"y"](m)),s||n[this[l(1637)]]}}async[t(594)](n){let s=t,l=this[s(1880)][s(996)+s(1130)](this._prefix),f=JSON.parse(e.iRzQP(l,"{}"));return f[n]=void 0,this._qosDB[s(1753)+s(1130)](this._prefix,JSON[s(1647)+"y"](f))}async[t(749)](){let n=t;return this._qosDB[n(1957)+n(1891)]()}async[t(1785)](){let n=t,s=this[n(1880)][n(996)+n(1431)+"nc"](this[n(1129)]),l=JSON[n(1316)](e[n(1109)](s,"{}"));return Object[n(1785)](l)}async[t(1066)](){let n=t,s=this[n(1880)]["getStora"+n(1431)+"nc"](this._prefix),l=JSON[n(1316)](e.ANUVI(s,"{}"));return Object[n(1850)](l)}[t(453)](){return Promise[t(1964)]()}get[t(1159)](){let n=t;if(e[n(962)](e[n(1900)],n(533)))return!!this._qosDB;{let s=!!this[n(1884)][n(1021)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=e[n(1915)](_0x54f4ab,_0x5bcda9[n(1814)][n(711)],e[n(946)],"2"),f=l&&_0x55bf4f(_0x4572eb[n(1814)].headers,e[n(1731)],"1"),m=l&&e[n(1915)](_0x4b03dc,_0x2a68e6.message.headers,e[n(1138)],"1"),w=m?_0x587e26(_0x5c6f98[n(1814)][n(711)],n(671)+n(809)+n(619))?.[n(1916)](",")[n(1984)](_0x29f480)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:f,isAckCleanupMessage:m,ackMsgIds:w}}}}function Il(a,n){let s=t;if(e.crcjH(e[s(550)],e.lhIKK)){if(e[s(1541)](Ln,Ln))return new rg(a,n);if(e[s(1172)](ar,ri)&&e[s(1695)](s(1821)+"d",typeof indexedDB))return new tg(a,n);if(e[s(1541)](ar,ri)&&e[s(1695)](e.Hdmxu,typeof localStorage))return new ng(a,n);throw new Error(s(1353)+s(1310)+"d")}else{let l={PeWCu:function(f,m){return e[s(1305)](f,m)},YWQtk:e[s(1125)],uxibl:function(f,m,w){return e[s(668)](f,m,w)},BHTkI:e[s(1590)]};return new _0x156126((f,m)=>{let w=s,b={jHsiz:function(I,M){return l[F(897)](I,M)},pKaOR:l[w(1806)],jkDQA:w(1799)+"e_success"};this["_clearPi"+w(438)](),this[w(1935)+w(1151)+"Id"]=l[w(1464)](_0x4ba9ad,this[w(1955)][w(933)](this),this[w(1884)]["pingInte"+w(742)]);let g=()=>{let I=w;b[I(720)](f,"success"),this[I(1311)](I(1799)+"e_success",g),this[I(1311)](b.pKaOR,C)},C=()=>{let I=w;b[I(720)](m,"timeout"),this[I(1311)](b[I(657)],g),this[I(1311)]("ping_onc"+I(1154)+"t",C)};this.on(l[w(1677)],g),this.on(l.YWQtk,C),this[w(1955)]()})}}class ig{constructor(){let n=t;e[n(1768)](e[n(716)],e.CZogA)?(this["_interva"+n(873)+"Id"]=null,this[n(1274)+"l"]=36e5,this[n(1880)]=e[n(630)](_0xb23f4e,"qos",e[n(714)])):(this["_interva"+n(873)+"Id"]=null,this[n(1274)+"l"]=36e5,this[n(1880)]=e[n(1377)](Il,"qos",n(1020)+"id"))}async[t(1274)+"lFlush"](){let n=t,s={eZHNp:function(l,f,m){return e[F(1280)](l,f,m)},iVAvQ:function(l,f){return e.xaqMk(l,f)},AFhfF:e[n(572)]};if(e[n(836)](e[n(697)],"FRmLQ")){let l=qBYcUH[n(1470)](_0x5e0eec,_0x580052,_0x1e1691[n(551)]);_0x5199d2[n(1879)][n(1777)](_0x335768,l)}else e[n(707)](clearInterval,this._intervalTimeoutId),this[n(1274)+"lTimeoutId"]=setInterval(()=>{let l=n;s[l(1142)](s.AFhfF,l(430))?this[l(1701)+l(835)]():_0xbc08ed[l(973)](_0xa94757)},this._interval)}async[t(722)](){let n=t;await this[n(1880)][n(722)]()[n(1941)](()=>{this["_interva"+n(1118)]()})}async[t(1701)+t(835)](){let n=t;(await this._qosDB?.[n(1066)]()||[])[n(1984)](({timestamp:f})=>f<Date[n(1293)]()).forEach(f=>{let m=n;this[m(1880)]?.[m(594)](f.message_id)})}async[t(594)](n){let s=t;return this._qosDB?.[s(594)](n)}async[t(1777)](n,s){let l=t;return this[l(1880)]?.[l(1777)]({message_id:n,timestamp:s})}async get(n){let s=t;return this[s(1880)]?.[s(626)](n)}async[t(453)](){let n=t,s={vQwPW:function(l,f){return e[F(419)](l,f)},NMhpv:function(l,f,m){return e[F(1377)](l,f,m)}};e.qMoEF(e[n(1597)],n(693))?(e.eynXe(clearInterval,this[n(1274)+"lTimeoutId"]),await this[n(1880)]?.[n(453)]()):(yzpOrH[n(1024)](_0x4eabc8,this[n(1274)+"lTimeoutId"]),this[n(1274)+n(873)+"Id"]=yzpOrH[n(1180)](_0x59e2ba,()=>{this[n(1701)+"ired"]()},this[n(1274)+"l"]))}get[t(1159)](){return this[t(1880)]?.isReady}}function Sa(a){let n=t,s=!!this[n(1884)][n(1021)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=e[n(1881)](on,a[n(1814)].headers,e.bvwjf,"2"),f=l&&e[n(1881)](on,a.message.headers,e[n(1731)],"1"),m=l&&e[n(392)](on,a[n(1814)][n(711)],"x_fronti"+n(692)+"k","1"),w=m?e.uBpFC(cr,a.message[n(711)],e[n(1861)])?.[n(1916)](",")[n(1984)](Boolean)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:f,isAckCleanupMessage:m,ackMsgIds:w}}async function kl(){let a=t;return this[a(1185)+a(1510)]||(this[a(1185)+a(1510)]=new ig),this[a(1185)+a(1510)].isReady||await this["_QoSMana"+a(1510)].openDB(),this[a(1185)+a(1510)]}async function sg(a,n){let s=t,{enableAutoAck:l}=this[s(1884)],f=e[s(984)](on,a[s(1814)][s(711)],e[s(1003)],"1"),m=on(a[s(1814)][s(711)],e[s(1857)],"1"),w=Sa[s(913)](this,a);if(e.iyEAz(l,f)){let{SeqID:b,LogID:g,service:C,LogIDNew:I,method:M}=a[s(1814)];this._sendAck({SeqID:b,LogID:g,LogIDNew:I,service:C,method:M,headers:[{key:e[s(1857)],value:"1"},{key:e[s(1664)],value:I||""},{key:e[s(555)],value:"0"}]})}m&&!w[s(373)]&&this[s(769)+s(545)+"ageEvent"](a),e[s(1484)](n)}async function og(a,n){let s=t;this._debug(e[s(1208)],a.message),e[s(1484)](n)}async function ag(a,n){let s=t,l={odIBH:function(m,w){return m>=w}},f=e.IJALS(nn,await e[s(667)](Al,a[s(1030)]));try{if(e.GFVXi(f[s(1526)],Uint8Array)){let m=e[s(1923)](this[s(1884)][s(1968)+"ncoding"],Object)?{force:!!this._options[s(1968)+"ncoding"][s(477)],encoding:this[s(1884)][s(1968)+s(989)][s(1098)]?this[s(1884)][s(1968)+s(989)][s(1098)][s(865)](/\s/g,"")[s(1697)+"ase"]():""}:{force:!1,encoding:this[s(1884)][s(1968)+"ncoding"]?this[s(1884)][s(1968)+"ncoding"][s(865)](/\s/g,"")[s(1697)+s(1197)]():""},w=f[s(1968)+s(989)]?f[s(1968)+s(989)][s(865)](/\s/g,"")["toLowerC"+s(1197)]():"",b=e[s(1612)](this[s(1884)][s(439)+"ype"],Object)?{force:!!this[s(1884)][s(439)+s(1269)][s(477)],type:this[s(1884)][s(439)+s(1269)][s(1155)]?this[s(1884)][s(439)+"ype"].type[s(865)](/\s/g,"")[s(1697)+s(1197)]():""}:{force:!1,type:this[s(1884)][s(439)+s(1269)]?this._options[s(439)+s(1269)].replace(/\s/g,"")[s(1697)+s(1197)]():""},g=f[s(439)+s(1269)]?f[s(439)+s(1269)][s(865)](/\s/g,"")[s(1697)+s(1197)]():"",C=b[s(477)]?b[s(1155)]:g||b[s(1155)],I=m.force?m[s(1098)]:w||m.encoding,M=[e.rSOtp,s(1561)+s(1486),s(1561)+s(1486)+s(1972)+s(1053),e.fmvyn],K=[s(1519)+"e",e.wfrdE];this[s(1884)]["enableTransformT"+s(1773)+"ad"]&&M[s(1555)](C)&&(!I||K[s(1555)](I))?f["textPayl"+s(1830)]=e[s(396)](Sl,f[s(1526)],0,f[s(1526)].byteLength):f[s(1240)+s(1830)]=""}else f[s(1240)+s(1830)]=""}catch(m){if(e[s(1369)](e[s(1947)],"RgJvr"))f[s(1240)+s(1830)]="",console[s(973)](m);else if(cmHdUy[s(1161)](_0x34d4e2,_0x12c432))return _0x2ae2bf}a[s(1814)]=f,e[s(1484)](n)}function cg(a,n,s){let l=t,f={bjkzn:l(1035),FtLMh:e.ozqJG,clTte:function(C,I){return C(I)},gWdKn:function(C,I){return e[l(828)](C,I)},dXkXb:function(C,I){return e.bVjLX(C,I)},iUzcG:e[l(968)],AzEgk:function(C,I){return e.BCnGI(C,I)},iXJeB:function(C,I){return e[l(1756)](C,I)},kPKoi:function(C,I){return C|I}},m=e.SeszQ(s,8192),w=m>>>1,b=null,g=m;return function(C){let I=l;if(C<1||C>w)return f[I(1062)](a,C);f[I(950)](f[I(1338)](g,C),m)&&(I(1588)===f[I(640)]?(b=f[I(1417)](a,m),g=0):(_0x2aa387[I(1100)+I(1790)+I(1429)]("complete",_0x41404b),_0x1ad5d2[I(1100)+I(1790)+I(1429)](ZTXcXh[I(609)],_0x5c570d),_0x362083[I(1100)+I(1790)+I(1429)](ZTXcXh[I(1711)],_0xc1bc57)));let M=n.call(b,g,g+=C);return f[I(1177)](7,g)&&(g=f[I(683)](7,g)+1),M}}let dg=4294967295;function lg(a,n,s){let l=t;return e[l(633)](RangeError,e[l(1998)](e.tmqbs(e[l(1793)](e[l(1737)](e[l(1227)],a)," + "),n||1),e.hySlV)+s)}function ug(a,n,s){let l=t;if(e.FRjGZ(s,dg))throw new Error(e[l(603)]);let f=3;for(;e[l(1463)](f,0);){let m=e.uRdhe(255,s);e[l(392)](Ia,m,a,e[l(1828)](n,f)),s>>>=8,f--}return e[l(827)](n,4)}function fg(a,n){let s=t,l={RHTEf:function(f,m){return f<=m},YRkqf:function(f,m){return e[F(1215)](f,m)},lloSg:function(f,m){return e.DJmHK(f,m)},AhJbT:function(f,m){return e[F(917)](f,m)},hHkUF:function(f,m){return e.vRfHx(f,m)},fbGpN:function(f,m){return e[F(1659)](f,m)},LxQfo:function(f,m){return e.LAErC(f,m)},cDheG:function(f,m){return f<<m},quIiT:function(f,m){return e[F(1805)](f,m)},OtgYA:function(f,m){return e[F(1838)](f,m)},IQlGd:function(f,m){return e.ZDJvW(f,m)},RmUYO:function(f,m){return e.ESCNY(f,m)},AnqJQ:function(f,m){return e[F(1914)](f,m)},xEBqf:function(f,m){return e.FsjkP(f,m)}};if(e[s(846)](e[s(694)],e[s(802)])){let f=0,m=n,w=e[s(1626)](n,4);for(;e[s(1398)](m,w);){let{value:b,offset:g}=e.TAint(Aa,a,m);m=g,f=e[s(1045)](e[s(1182)](f,8),0),f+=b}return{value:f,offset:w}}else{let f=_0x566ba8[_0x116129++];if(sopRzV[s(1610)](f,127))_0x704c75+=_0x46c31c[s(1565)+"Code"](f);else if(f>=192&&sopRzV[s(995)](f,224))_0x5acd27+=_0x5c5cca[s(1565)+"Code"](sopRzV[s(1761)](sopRzV.AhJbT(31,f),6)|63&_0x17d6c3[_0x40982f++]);else if(sopRzV[s(860)](f,224)&&f<240)_0x57c249+=_0x5cb7f8.fromCharCode(sopRzV[s(1531)](sopRzV[s(1438)](sopRzV.cDheG(15&f,12),sopRzV.quIiT(sopRzV.AhJbT(63,_0x4d5379[_0x28403f++]),6)),sopRzV[s(1009)](63,_0xbdb953[_0xdb6511++])));else if(sopRzV[s(860)](f,240)){let m=sopRzV[s(1438)](sopRzV[s(1438)](sopRzV[s(1384)](7&f,18),sopRzV[s(1761)](sopRzV[s(1060)](63,_0x31820d[_0xfd1775++]),12))|sopRzV[s(1060)](63,_0x51d436[_0x20326a++])<<6,63&_0x1594df[_0x3a757f++])-65536;_0x3f03eb+=_0x4ebede[s(1565)+s(1424)](sopRzV[s(1473)](55296,sopRzV[s(1225)](m,10))),_0x106312+=_0xed6471["fromChar"+s(1424)](sopRzV[s(1473)](56320,1023&m))}}}function xg(a,n,s){let l=t,f=(l(1781)+"0").split("|"),m=0;for(;;){switch(f[m++]){case"0":return Ea(a,n,s)+s;case"1":if(!a)return s;continue;case"2":if(n.utf8Write)return e[l(1577)](n[l(1525)+"e"](a,s),s);continue;case"3":if(e[l(884)](a[l(551)],40))return e[l(1290)](e.LuOix(Ea,a,n,s),s);continue;case"4":if(n[l(1294)])return e[l(593)](n[l(1294)](a,s),s);continue}break}}function hg(a,n){let s=t,l=new xe(e[s(1096)](e[s(1485)](e[s(1982)](a[e[s(827)](n,4)],24)|e[s(1235)](a[n+5],16),e[s(1023)](a[n+6],8)),a[e.Rbyez(n,7)]),e[s(445)](e[s(1477)](e[s(1869)](a[e.vHnyL(n,0)],24),e[s(1805)](a[n+1],16))|e[s(569)](a[e[s(461)](n,2)],8),a[n+3]),!0);return n+=8,{value:l,offset:e[s(919)](n,8)}}function pg(a,n,s){let l=t,f=a.low,m=a[l(1253)];return n[s]=e[l(1550)](m,24),n[s+1]=e.oBDhm(m>>>16,255),n[e[l(450)](s,2)]=e.BAurB(e[l(493)](m,8),255),n[s+3]=e.uJgNo(255,m),n[e.uKJmy(s,4)]=e.KfecL(f,24),n[e[l(1757)](s,5)]=e[l(1665)](e.LKXOw(f,16),255),n[e[l(1914)](s,6)]=e[l(732)](e[l(825)](f,8),255),n[s+7]=e[l(503)](255,f),s+=8,s}function Aa(a,n){let s=t,l={NCech:function(f){return e[F(596)](f)}};if(e[s(1513)](e[s(376)],e[s(376)]))return a[s(432)+"8"]?{value:a[s(432)+"8"](n),offset:e.OZgiC(n,1)}:{value:e[s(1958)](255,a[n]),offset:e[s(1780)](n,1)};vDCLSW[s(726)](_0x54e8eb),_0x2f6b2c()}function Ia(a,n,s){let l=t;return n[l(1997)+"t8"]?n[l(1997)+"t8"](a,s):n[s]=e[l(621)](255,a),e.WmtSB(s,1)}let gg=function(a){return new Uint8Array(a)},mg=e[t(526)](e[t(660)],typeof Buffer)?Buffer[t(1300)+t(1543)]:cg(gg,Uint8Array[t(1471)+"e"][t(447)]);(()=>{let a=t,n={KlazR:a(664)+a(1926)+"|6|7|10|0",gdwyJ:function(l,f){return e[a(1469)](l,f)},amyln:function(l,f){return l<f},MWZxo:function(l,f){return l|f},GNaEb:function(l,f){return e[a(1104)](l,f)},kmOpz:function(l,f){return e[a(1006)](l,f)},bUhfO:function(l,f){return e[a(666)](l,f)},bSYTC:function(l,f){return e.EHyyN(l,f)},LjhVm:function(l,f){return e[a(571)](l,f)},TFnke:function(l,f){return e.PlBVK(l,f)},mlscA:function(l,f){return l|f},gZMFF:function(l,f){return e[a(1023)](l,f)},tQXXk:function(l,f){return e[a(1638)](l,f)},ZeXMe:function(l,f){return l<<f},ZpZxX:function(l,f){return e.tpyqi(l,f)},XeSMk:function(l,f,m,w){return e.jOLEg(l,f,m,w)},NAAHN:function(l,f){return l|f}},s=4294967295;return function(l,f,m=!0){let w=a,b=n[w(1321)].split("|"),g=0;for(;;){switch(b[g++]){case"0":return{value:m?s:n[w(562)](0,s),offset:f};case"1":if(n[w(1303)](l[f++],128))return{value:m?s:n[w(527)](0,s),offset:f};continue;case"2":s=n[w(914)](127&l[f],0);continue;case"3":s=n[w(656)](n[w(807)](s,n.bSYTC(n[w(1454)](127,l[f]),21)),0);continue;case"4":if(n[w(488)](l[f++],128))return{value:m?s:n[w(562)](0,s),offset:f};continue;case"5":if(n.TFnke(l[f++],128))return{value:m?s:n[w(807)](0,s),offset:f};continue;case"6":s=n[w(1086)](s,n.gZMFF(15&l[f],28))>>>0;continue;case"7":if(n[w(1303)](l[f++],128))return{value:m?s:0|s,offset:f};continue;case"8":s=n.kmOpz(n.tQXXk(s,n[w(1064)](n[w(1454)](127,l[f]),14)),0);continue;case"9":if(l[f++]<128)return{value:m?s:n.bUhfO(0,s),offset:f};continue;case"10":if(n[w(1339)](f+=5,l.length))throw f=l[w(551)],n.XeSMk(lg,f,10,l[w(551)]);continue;case"11":s=n[w(914)](n[w(1614)](s,n[w(1454)](127,l[f])<<7),0);continue}break}}})();let wg=16,ka=32;function _g(a){let n=t,s=0,l={};for(let f=0;e[n(464)](f,a[n(551)]);f++)l[a[f][n(1730)+n(1766)]]=e[n(1717)](vl,a[f][n(1730)+"ame"]),s+=e[n(983)](14,l[a[f][n(1730)+n(1766)]]);return[s,l]}function Tl(a,n,s){let l=t,[f,m]=e[l(399)](_g,a),w=e[l(1811)](mg,f),b=0;return a.forEach(g=>{let C=l,I=e[C(1578)][C(1916)]("|"),M=0;for(;;){switch(I[M++]){case"0":console.log(e[C(1123)],b);continue;case"1":b=xg(g[C(1730)+"ame"],w,b);continue;case"2":b=ug(w,b,g[C(1128)]||0);continue;case"3":console[C(973)](e[C(748)],g,g[C(1128)]);continue;case"4":console.log(e.pDDAM,b);continue;case"5":b=e[C(1122)](Ia,m[g[C(1730)+C(1766)]],w,b);continue;case"6":console[C(973)](e[C(1179)],b);continue;case"7":b=e.ECDnx(Ia,0,w,b);continue;case"8":b=e.ECDnx(pg,xe[C(1644)+"er"](g.cursor||n),w,b);continue;case"9":console[C(973)](e[C(1910)],b);continue;case"10":console[C(973)](e[C(413)],b);continue}break}}),{frameType:ka,headers:[{key:"cursor_f"+l(1284),value:s}],payload:w}}function yg(a){let n=t,s=0,l=[];for(;e[n(407)](s,a.byteLength);){let{offset:f}=e.YgtpB(Aa,a,s);s=f;let m={cursor_name:"",cursor:0,service:0},{value:w,offset:b}=e[n(1390)](fg,a,s);m[n(1128)]=w,s=b;let{value:g,offset:C}=e.IshkX(Aa,a,s);s=C,m["cursor_n"+n(1766)]=e[n(892)](Sl,a,s,e[n(1757)](s,g)),s+=g;let{value:I,offset:M}=e[n(631)](hg,a,s);m.cursor=I[n(1444)](),s=M,l[n(1113)](m)}return l}function bg(){let a=t;return{frameType:ka,headers:[{key:a(384)+a(1284),value:e[a(868)]}],payload:void 0}}class Eg{constructor(n,s,l){let f=t,m={xXkAd:function(w,b){return e[F(1575)](w,b)},eqgKN:function(w,b){return e[F(1191)](w,b)},YnTsm:function(w,b){return w|b},hFQLG:function(w,b){return w<<b},ardOn:function(w,b){return e[F(554)](w,b)},lRiFo:function(w,b){return e[F(817)](w,b)},PFyNR:function(w,b){return e[F(1665)](w,b)},cAQgz:function(w,b){return e[F(1587)](w,b)}};if(e[f(962)](e.uHZrx,e[f(393)])){let w=SdBDBa[f(1162)](SdBDBa.eqgKN(SdBDBa[f(1399)](SdBDBa[f(1722)](7&_0xed20e5,18),SdBDBa[f(681)](63&_0x5e6772[_0xb7bc65++],12))|SdBDBa.lRiFo(63&_0x3068c5[_0x5bbbd0++],6),SdBDBa[f(1594)](63,_0x416f14[_0x46cee8++])),65536);_0x49a0b8+=_0x17bd52[f(1565)+f(1424)](SdBDBa.cAQgz(55296,w>>10)),_0x3865bb+=_0x49175d[f(1565)+f(1424)](56320+(1023&w))}else this[f(1504)+f(1788)]=n,this[f(1994)+f(1243)]=s,this[f(856)+f(1077)]=l,this[f(1880)]=e.mFRtB(Il,this["_cursorN"+f(1788)],e[f(980)])}async[t(722)](){let n=t;e[n(1365)](e[n(1268)],n(1819))?(_0x23040e(_0x5bf978[n(1035)]||new _0x24a2ee(sNhWbS[n(1234)],sNhWbS[n(1234)])),_0x5be07d()):await this[n(1880)][n(722)]()}async[t(931)+"rs"](){let n=t;if(!this[n(1880)][n(1159)])return;let s=this[n(856)+n(1077)],l=await this[n(1880)][n(1066)]();switch(console[n(973)](e[n(1476)],l),s){case e[n(456)]:return l&&l.length?e[n(539)](Tl,l,0,this[n(1994)+n(1243)]):void 0;case e[n(1922)]:return;case e.AZioQ:return l&&l.length?Tl(l,0,this[n(1994)+n(1243)]):bg()}}async[t(1777)](n,s,l){let f=t;return e[f(836)](e.UobxK,e[f(1804)])?(console.log(e.jRdDJ,n,s,l),this._qosDB.set({cursor_name:n,cursor:s,service:l})):"frontier_"+this._DBName}async setCursors(n){let s=t,l=e[s(1560)](yg,n);for(let f of l)console[s(973)](e[s(1726)],l),await this[s(1880)][s(1777)](f)}async[t(626)](n){let s=t,l={ODNJx:function(f,m){return e.WkcdU(f,m)}};if(e[s(1445)](e[s(1217)],s(1557))){let f=_0x566cd4[s(1879)],m=_0x9279e2.limit;return mdFddY[s(1334)](f.length,m)?f:f[s(447)](0,m)}else return(await this[s(1880)].get(n))?.[s(457)]}async closeDB(){await this[t(1880)].closeDB()}["updateCursorFile"+t(442)](n){let s=t;this[s(1994)+s(1243)]=n}get[t(1159)](){return this[t(1880)].isReady}}let vg=t(1279)+"qos__";async function Cl(a){let n=t;if(e[n(900)](e[n(474)],e[n(474)])){if(!this[n(1884)].enableQoS)return null;let{aID:s,fpID:l,messageStrategy:f}=this[n(1884)],m=e[n(1762)](a,vg);try{return this["_cursorM"+n(1622)]?a&&this["_cursorM"+n(1622)]["updateCu"+n(1615)+n(442)](a):this[n(454)+n(1622)]=new Eg(l+"_"+s+"_"+m,m,f),this["_cursorM"+n(1622)].isReady||await this[n(454)+n(1622)][n(722)](),this[n(454)+n(1622)]}catch{return null}}else return sNhWbS[n(1783)](typeof _0x44fe9a,"function")?sNhWbS[n(399)](_0x1f5098,_0x422695):(sNhWbS[n(890)](_0x5014cf,_0xf18cfe)&&sNhWbS[n(902)](_0x49c239,_0x458724),_0x99f075(_0x26a578,sNhWbS[n(596)](_0x4f8376))?new _0x3cf454(_0x3699b6,_0x5e3da1):_0x2a64f2)}async function Sg(a,n){let s=t,l=on(a.message[s(711)],e[s(1732)],"-1"),f=e[s(1122)](on,a[s(1814)][s(711)],s(1521),"1"),m=cr(a.message[s(711)],e[s(1820)]),w=e[s(434)](Number,e[s(1335)](cr,a[s(1814)].headers,e[s(1392)]))||0,b=Sa[s(913)](this,a),g=e[s(1439)](on,a[s(1814)][s(711)],s(1267)+"s","2"),C=e.DkJsY(cr,a[s(1814)][s(711)],e.VEccL),I=e[s(1990)](Number,cr(a[s(1814)][s(711)],s(581)+s(360)+"ue"));if(b[s(373)])return e[s(1484)](n);let M=b[s(1608)+s(1956)]?await kl[s(913)](this):null;if(e[s(1171)](a[s(1814)].service,0)&&f&&!l||e[s(1052)](a.message.service,0)){if(e[s(362)]===e[s(541)])return this[s(1880)]?.[s(594)](_0x2bb6b7);if(m&&b[s(1608)+"sage"]&&M){if(!!!await M[s(626)](m)){if(e.vHQar(e.hEgrI,e[s(1149)]))return this.unsigned?e[s(1904)](e[s(606)](this[s(1253)]>>>0,_0x5d3311),this[s(570)]>>>0):e[s(1974)](e.uzKLB(this[s(1253)],_0xd29bee),e[s(1812)](this[s(570)],0));this["_dispatc"+s(756)+s(1499)](a),await M[s(1777)](m,Date[s(1293)]()+w)}return e[s(421)](n)}if(g){let K=await Cl[s(913)](this);if(!K){if(e[s(830)](e[s(926)],e[s(725)]))return this[s(769)+"hMessage"+s(1499)](a),e[s(1484)](n);{let ne=_0x4afb21[s(551)]&&_0xe14ed6[0];if(e.Uhfvq(ne,_0x5e7108))throw ne;let st=new _0x37c928(e[s(1760)]+(ne?e[s(1780)](" ("+ne[s(1814)],")"):""));throw st.context=ne,ne}}let J=await K.get(C)??-1;if(J<I)e[s(1617)](e.DQLYe,e.xnfvJ)?(this[s(769)+"hMessage"+s(1499)](a),K.set(C,I,a[s(1814)].service)):(e.DOKOo(_0x149ad7,2048)?_0x2759ea[_0x3ef57d++]=e[s(932)](e.mdPWG(_0x36ccad,6),31)|192:(e[s(912)](_0x67395b,65536)?_0x5d468a[_0x2b8c80++]=e[s(1191)](e[s(1756)](e[s(1452)](_0x5c0ae4,12),15),224):(_0x28bc1d[_0x54885a++]=e[s(958)](e[s(1244)](_0x7fe2c0,18)&7,240),_0x24ce14[_0x4cc827++]=e[s(637)](e[s(915)](e[s(437)](_0x5ca3d3,12),63),128)),_0xf1a5f3[_0x1cde24++]=e.WEYeJ(e[s(1244)](_0x109ef9,6)&63,128)),_0x2e5e45[_0x57fc5d++]=e[s(1460)](63&_0x5ad28f,128));else throw new Error("recevied message"+s(1747)+I+(" larger "+s(810)+s(1539)+"r ")+J);return e[s(421)](n)}return this[s(769)+s(756)+s(1499)](a),n()}}async function Ag(a,n){let s=t,l={XZkmU:e[s(660)],MTqny:e[s(1518)],gbceL:s(1450)+"le"};if(e[s(924)](e[s(1942)],e[s(647)]))iOgWTy[s(895)]!=typeof _0x3cd764&&_0x40d36d["toString"+s(1527)]&&_0x3b46a1[s(1228)+s(1416)](_0x3d3db9,_0x2baae1["toString"+s(1527)],{value:iOgWTy.MTqny}),_0x35dfc6[s(1228)+"operty"](_0x26c2fc,iOgWTy[s(598)],{value:!0});else{let f=Sa[s(913)](this,a);if(!f[s(1608)+"sage"])return e[s(421)](n);let m=await kl.call(this);if(f[s(1771)+"anupMess"+s(1282)]&&f[s(1270)+"s"][s(551)])for(let w of f[s(1270)+"s"])await m[s(594)](w);e.lZnbG(n)}}async function Ig(a,n){let s=t,l=e[s(1513)](a[s(1814)][s(1379)+"e"],wg),f=e.XUXuQ(a[s(1814)][s(1379)+"e"],ka);if(e[s(772)](!l,!f))return e[s(874)](n);let m=e.nlfOi(cr,a[s(1814)][s(711)],e[s(369)]);if(!m)return e[s(1952)](n);let w=await Cl[s(913)](this,m);if(!w)return e[s(739)](n);if(l)if(e[s(1505)]===e[s(1556)]){let b=this[s(1880)][s(996)+"geSync"](this[s(1129)]),g=_0x3617f9[s(1316)](e[s(1886)](b,"{}"));return g[_0x455aee]=void 0,this[s(1880)][s(1753)+s(1130)](this[s(1129)],_0x5f2541[s(1647)+"y"](g))}else{let b=await w.getCursors(),g={frameType:b?.[s(1379)+"e"],SeqID:xe[s(1644)+"er"](this[s(1481)]++),LogID:xe[s(1644)+"er"](this._options[s(971)+s(476)]()),service:9e3,method:5,headers:b?.[s(711)],payload:b?.[s(1526)]},C=e[s(1702)](S,g);this[s(1703)]&&this[s(1703)][s(1708)+"te"]&&this[s(1703)][s(1751)](C)}if(f)if(e[s(1383)]!==e[s(1002)]){let b=a[s(1814)][s(1526)];b&&w[s(751)+"rs"](b)}else _0x157eda&&_0x4154be[s(1258)+s(1745)](sNhWbS[s(898)],()=>_0x443095()),_0x31e848&&_0x4e0716[s(1258)+s(1745)](sNhWbS[s(622)],()=>_0x164bed())}let kg=async function(a,n){let s=t;this[s(1407)]=!1,e[s(1223)](clearTimeout,this[s(1143)+"ionTimeo"+s(938)]),n()},Tg=async function(a,n){let s=t,l={lWVvC:function(f,m){return e[F(1698)](f,m)},hdxTD:function(f,m){return e[F(1890)](f,m)},OTFtw:function(f,m){return e[F(1349)](f,m)},fsPwq:function(f,m){return e[F(1007)](f,m)},cAIQq:function(f,m){return e[F(661)](f,m)},eyBay:function(f,m){return e[F(1589)](f,m)},gkVhD:function(f,m){return f<<m},HVvnI:function(f,m){return e[F(1559)](f,m)},qpXsP:function(f,m){return e[F(1589)](f,m)}};if(e[s(1803)](e[s(1749)],s(1779)))return CVxOWT[s(1153)](_0x3611ad,_0x1a00c8)?_0xd8032a:new _0x45c663(CVxOWT[s(941)](CVxOWT[s(1112)](CVxOWT[s(953)](CVxOWT.fsPwq(_0x8c944c.call(_0x262cef,0),CVxOWT[s(1858)](_0x895970[s(913)](_0x569a13,1),8)),CVxOWT[s(906)](_0x45ecc0[s(913)](_0x5a5165,2),16)),CVxOWT[s(1029)](_0x317d3d[s(913)](_0x203544,3),24)),0),CVxOWT[s(994)](CVxOWT[s(953)](CVxOWT[s(1112)](_0x4d83ee.call(_0x34994b,4),CVxOWT[s(1029)](_0x16c30d[s(913)](_0x3023fc,5),8)),CVxOWT[s(1651)](_0x4f6831[s(913)](_0x1c5efa,6),16))|_0x1705d9[s(913)](_0x3ba030,7)<<24,0),!0);{if(!this._ws||this[s(1703)][s(1708)+"te"]!==this.OPEN)return e[s(1679)](n);let{pingInterval:f}=this[s(1884)];this[s(1870)+s(1033)]?.[s(487)+s(1657)+"fig"]();for(let w=0;e[s(910)](w,this[s(856)+"Queue"][s(551)]);w++){let b=this[s(856)+"Queue"][w];if(e.JnDha(this[s(1703)][s(1708)+"te"],this[s(1169)])&&e.igbZa(null,b))this._ws&&this[s(1703)][s(1751)](b),this[s(856)+"Queue"][w]=null;else break}this._messageQueue=this[s(856)+"Queue"][s(1984)](w=>!!w),this["_pingPon"+s(1151)+"Id"]=e.dYPHA(setTimeout,()=>this[s(1955)](),f),this[s(769)+"hOpenEvent"](a),this[s(1465)+"er"]&&this[s(1703)]&&(this._ws[s(1601)+"pe"]=this[s(853)+s(1269)]);let m=this[s(1870)+s(1033)]?.[s(560)+"ntEndpoint"]();this[s(389)](s(727)+m+s(535)),e[s(596)](n)}},Cg=async function(a,n){let s=t;if(e.gAdHs(e.tvltj,s(1211))){let l=this[s(1870)+"tManager"]?.[s(560)+s(573)+"nt"]();this[s(389)](s(727)+l),e.KlOBk(n)}else return!0};class Rg extends ba{constructor(n){let s=t,l={cPIGH:function(b,g,C){return e[F(1144)](b,g,C)},ToxhO:"error",Tkope:function(b,g){return e[F(924)](b,g)},Qsujq:s(940),pcByt:s(1598),zQDXL:e.aypqs,ADKIE:s(1667),AfBfe:s(870)};super(),this["_miniNav"+s(1345)+"line"]=!0,this[s(1465)+"er"]=ar,this[s(605)]=Kp,this[s(985)+"T"]=Ln,this[s(1971)+"X"]=ni,this[s(433)+"r"]=ri,this["_message"+s(792)]=[],this[s(1870)+s(1033)]=null,this["_readyCl"+s(1259)]=!1,this[s(853)+s(1269)]=e.IFdQt,this[s(1143)+s(351)]=!1,this[s(1143)+s(718)+s(938)]=null,this[s(1842)+s(1114)+s(1755)]=null,this["_pingPon"+s(1151)+"Id"]=null,this[s(1481)]=0,this[s(1407)]=!1,this[s(1252)]="",this[s(1185)+"ger"]=null,this[s(454)+s(1622)]=null,this["_pingLos"+s(1451)]=null,this._protocols=e.AvnZv,this.CLOSED=3,this[s(1187)+"NG"]=0,this[s(1169)]=1,this[s(691)]=2,this[s(689)]=b=>{let g=s;try{El(this,b,[kg,Tg,Cg])}catch(C){let I=l[g(1902)](lt,l[g(1348)],{message:C[g(1814)],code:sn[g(762)+"OR"],error:C});this["_dispatc"+g(1662)+"ent"](I)}},this._onMessage=async b=>{let g=s,{pingInterval:C,pingFrequency:I}=this[g(1884)];if((l[g(1004)]("hi",b[g(1030)])&&l[g(1004)](l[g(509)],I)||l[g(1004)](l[g(1629)],I))&&(this[g(444)+"ngTimer"](),this[g(1314)](l[g(1213)],l[g(801)]),this._pingPongTimeoutId=l[g(1902)](setTimeout,this[g(1955)][g(933)](this),C)),!l[g(1004)]("hi",b[g(1030)]))try{El(this,b,[ag,sg,Ag,Ig,Sg,og])}catch(M){if(g(1877)===l[g(1953)]){let K=this["_endpoin"+g(1033)]?.[g(560)+"ntEndpoint"]();this._debug(g(727)+K),_0x37a591()}else{let K=l.cPIGH(lt,l[g(1348)],{message:M[g(1814)],code:sn[g(1285)+g(930)],error:M});this["_dispatc"+g(1662)+g(1652)](K)}}},this[s(1631)]=b=>{let g=s,C={IXeYs:function(I,M){return e[F(348)](I,M)}};if(e[g(615)](e[g(891)],e[g(1920)]))RmXebm[g(1742)](_0x1be3ae,_0x42ede8)&&_0x19b2ee[g(1777)](_0x223317,_0x32f897);else{let I=this[g(1870)+g(1033)]?.checkReachMaxTries(),M=this[g(1870)+"tManager"]?.[g(560)+"ntEndpoint"]();if(I&&!b[g(1814)]){let K=g(1203)+M+(g(1435)+g(1839)+"es reached");this[g(769)+g(1662)+g(1652)](e.keKvl(lt,e[g(471)],{message:K,code:sn[g(1876)+g(1261)+"R"],error:b}));return}this[g(1703)]&&e[g(1502)](this[g(1703)][g(1708)+"te"],this[g(1169)])&&this[g(1924)+"ect"](),this[g(769)+g(1662)+"ent"](e[g(1390)](lt,e[g(471)],{message:b[g(1814)],code:sn[g(561)+g(1395)],error:b}))}},this._onClose=async b=>{let g=s,C={dSGVy:function(I,M){return e.UePNx(I,M)},HiaMa:function(I,M){return I(M)}};if(e[g(502)](e[g(1275)],g(1568)))return this[g(1703)]?this[g(1703)][g(499)]:this[g(1252)];{this[g(1322)+"mer"](),this._clearPingTimer(),this[g(1796)+g(420)+"rs"](),this._ws=null,this[g(1143)+g(351)]=!1;let I=this["_endpoin"+g(1033)]?.[g(740)+g(1347)+"es"]();if(!I&&this[g(1759)+g(677)]()&&!this[g(1774)+"osed"]){let M=this[g(1870)+g(1033)]?.[g(560)+g(573)+"nt"](),K=this[g(1884)][g(501)+g(1292)+g(1930)](b[g(1341)],b[g(446)]);this["_dispatchCloseEv"+g(1652)](wt(e[g(898)],{code:1006,reason:b[g(446)]||g(544)+g(974)+g(1437)+"wn reaso"+g(482)+g(1218)+M,willReconnect:K})),K&&this[g(1143)]();return}if(b[g(1341)]!==1e3&&this[g(1774)+g(1259)])if(e[g(639)](e.kbfqb,g(517))){this["_dispatc"+g(1032)+g(1652)](e[g(1e3)](wt,"close",{code:1e3,reason:g(1849)})),this[g(1870)+"tManager"]?.[g(487)+"pointCon"+g(1520)](),this[g(1291)+g(1451)]?.["resetCou"+g(1872)]();return}else return eYrpKU.dSGVy(_0x2c6946,eYrpKU[g(1117)](_0x11343b,_0x4a88a5));if(e[g(406)](1e3,b[g(1341)])&&I){let M=this._endpointManager?.[g(560)+g(573)+"nt"](),K=b[g(446)];K||(K=await e[g(419)](Qp,this[g(1252)])),K=g(544)+"ng faile"+g(2004)+K+(g(761)+"me: ")+M+(g(644)+g(947)+"ached"),this[g(769)+g(1032)+g(1652)](e[g(1312)](wt,e[g(898)],{code:b[g(1341)],reason:K}));let J="connect "+M+(g(1435)+g(1839)+g(1041)+"ed");this[g(769)+g(1662)+g(1652)](lt(e[g(471)],{message:J,code:sn[g(1876)+g(1261)+"R"]})),this["_endpoin"+g(1033)]?.[g(487)+"pointConfig"](),this[g(1291)+g(1451)]?.[g(965)+"nter"]();return}if(e[g(1621)](1e3,b[g(1341)])&&!b.reason){let M=this["_endpoin"+g(1033)]?.["getCurre"+g(573)+"nt"]();this._dispatchCloseEvent(e[g(415)](wt,g(1978),{code:b.code,reason:g(544)+g(974)+g(1437)+g(1137)+g(482)+g(1218)+M})),this[g(1870)+"tManager"]?.[g(487)+g(1657)+g(1520)](),this["_pingLos"+g(1451)]?.[g(965)+g(1872)]();return}this["_dispatc"+g(1032)+g(1652)](b),this[g(1870)+g(1033)]?.["resetEndpointCon"+g(1520)](),this[g(1291)+g(1451)]?.resetCounter()}},this[s(1164)]=null,this[s(1798)]=null,this[s(837)+"e"]=null,this[s(1650)]=null,this[s(416)+s(812)]=null,this[s(1070)+s(811)]=null,this[s(1490)+s(1255)+"yReconnect"]=null,this._handleOnLine=this[s(1639)+s(778)][s(933)](this),this[s(1639)+s(1980)]=this[s(1639)+"ffLine"][s(933)](this),this[s(1055)+"ageHide"]=this[s(1055)+s(736)].bind(this),this[s(1055)+s(479)]=this[s(1055)+"ageShow"][s(933)](this),this[s(1884)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:1/0,service:0,logIDGenerator:o,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:e[s(1148)],pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e.AZioQ,env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:m}=n,w=Array[s(1342)](f)?f:e[s(1938)](e[s(977)],typeof f)?[f]:[];if(!w||e.jzUPy(0,w[s(551)]))throw new Error(e.CQHXD);if(!e[s(902)](Jp,m))throw new Error(e[s(1356)]);Object[s(624)](this[s(1884)],n),this["_endpoin"+s(1033)]=new bl(w,this[s(1884)][s(1975)+"es"]),this._pingLossCounter=new Yp(this[s(1884)][s(1216)+"Count"]),this[s(1884)]["automati"+s(1146)]&&(e.KPsbM==="qNUHj"?(this[s(1407)]=!0,this._connect()):(_0x43fc11[s(1777)](_0x576f00,_0x527c82),_0xccefb[s(1777)](_0x495ff0,_0x4f1a28))),this[s(1884)]["listenNe"+s(1068)+s(939)]&&(this[s(985)+"T"]||this._isMiniWX?this[s(918)+s(833)+s(1346)]():this._isBrowser&&this[s(986)+s(489)+s(1745)]())}["_handleO"+t(778)](){let n=t;if(e[n(1864)](e.ZLsgt,e[n(397)])){if(this._options[n(1887)+n(1633)+n(909)]||this[n(1774)+n(1259)])return;this["_handleR"+n(812)]()}else{let s=this[n(1727)+"rs"][_0x3ebcf9];if(s)for(let l=0;e[n(1619)](l,s.length);)e[n(1776)](s[l].fn,_0x59482e)?s[n(1466)](l,1):++l}}[t(1639)+t(1980)](){let n=t;this[n(608)+n(1135)+"t"]();let s=e[n(1175)](ya,n(501)+"t",{message:e[n(1903)]});this[n(1490)+n(1255)+n(1065)+"ct"]&&this[n(1490)+n(1255)+n(1065)+"ct"](s)}[t(986)+t(489)+"Listener"](){let n=t;if(e[n(404)](e.KhYIt,e[n(1391)])){let s={rBToA:function(l,f,m,w,b){return sNhWbS.bmkyE(l,f,m,w,b)},HoDft:function(l,f){let m=n;return sNhWbS[m(815)](l,f)}};_0x23093a[n(1258)+n(1745)](sNhWbS[n(1456)],l=>{let f=n;s[f(795)](_0x34039d,s[f(460)](_0x25cc84,_0x486c85[f(847)]),l[f(1661)+"on"],l.newVersion,_0x746cd1(_0x3715e4[f(699)+f(1067)]))})}else this[n(1465)+"er"]&&window[n(1258)+n(1745)](e[n(394)],this._handleOnLine),this._isBrowser&&window["addEvent"+n(1745)](n(942),this._handleOffLine),this._isBrowser&&window[n(1258)+n(1745)](e[n(1013)],this[n(1055)+n(736)]),this[n(1465)+"er"]&&window["addEvent"+n(1745)](e[n(597)],this[n(1055)+n(479)])}[t(1071)+t(489)+"Listener"](){let n=t;this[n(1465)+"er"]&&window[n(1100)+n(1790)+n(1429)](n(440),this[n(1639)+n(778)]),this[n(1465)+"er"]&&window["removeEv"+n(1790)+"ner"](e[n(1899)],this[n(1639)+n(1980)]),this._isBrowser&&window[n(1100)+n(1790)+n(1429)](e[n(1013)],this[n(1055)+n(736)]),this[n(1465)+"er"]&&window["removeEventListe"+n(1429)]("pageshow",this["_handleP"+n(479)])}[t(1055)+t(736)](n){let s=t;e[s(556)]===e[s(556)]?(!n[s(1660)+"d"]&&(this[s(1465)+"er"]&&window[s(1100)+s(1790)+s(1429)](e[s(1013)],this["_handleP"+s(736)]),this[s(1465)+"er"]&&window["removeEv"+s(1790)+"ner"](e[s(597)],this[s(1055)+s(479)]),this[s(1978)]()),this._isBrowser&&window[s(1100)+s(1790)+s(1429)](e.mdhri,this[s(1639)+s(778)]),this._isBrowser&&window.removeEventListener(e[s(1899)],this[s(1639)+s(1980)])):this[s(985)+"T"]?_0x17b551[s(1909)+s(1663)+s(785)](({isConnected:l})=>{let f=s;this[f(1436)+f(1345)+f(1289)]=l,l?this[f(1639)+f(778)]():this["_handleO"+f(1980)]()}):this[s(1971)+"X"]&&_0x34187b[s(1909)+s(1663)+s(785)](({isConnected:l})=>{let f=s;this[f(1436)+f(1345)+f(1289)]=l,l?this[f(1639)+"nLine"]():this["_handleO"+f(1980)]()})}["_handleP"+t(479)](n){let s=t,l={oLcxV:function(f,m){return e.JVyNR(f,m)},qLdMr:function(f,m){return e[F(443)](f,m)},UeBSF:function(f,m){return e[F(580)](f,m)}};if(n.persisted){if(e.MjBYJ(e[s(877)],e[s(877)]))return _0x35b770.isLong(_0xa3559a)||(_0x5966d4=_0x3a8ccb[s(1644)+"er"](_0x1dbc16)),WDjrAz[s(733)](this[s(645)],_0x5141cf[s(645)])&&WDjrAz[s(548)](WDjrAz[s(383)](this[s(1253)],31),1)&&WDjrAz.qLdMr(WDjrAz[s(383)](_0x450c58.high,31),1)?!1:WDjrAz[s(548)](this[s(1253)],_0x4c28be[s(1253)])&&WDjrAz[s(548)](this[s(570)],_0x4a718a.low);this[s(1759)+"orOnline"]()&&(!this._ws||e[s(521)](this[s(1703)][s(1708)+"te"],this[s(1169)])||e[s(1081)](this[s(1703)][s(1708)+"te"],this[s(1187)+"NG"]))&&this[s(1639)+"nLine"](),this[s(1465)+"er"]&&window["addEvent"+s(1745)](e[s(394)],this[s(1639)+s(778)]),this[s(1465)+"er"]&&window[s(1258)+"Listener"](e[s(1899)],this["_handleO"+s(1980)])}}async["_generat"+t(879)](n){let s=t,l={uXUnz:function(f,m,w){return e.msLMz(f,m,w)},xRHYH:e[s(898)],AIxea:function(f,m,w){return e[s(1843)](f,m,w)},Bplwk:function(f,m,w){return e[s(415)](f,m,w)},AwhbH:function(f,m,w){return e[s(613)](f,m,w)},MRbSf:e[s(1906)]};if(e[s(857)]!==e[s(1919)]){let{fpID:f,deviceID:m,bddID:w,ttwID:b,accessKey:g,aID:C,customParams:I={},enableAutoAck:M,enableQoS:K,QoSLevel:J,env:ne}=this[s(1884)],st,U,G;this[s(1465)+"er"]||this._isMiniWX||this[s(985)+"T"]?(st=location&&e[s(1795)](e.KowMB,location[s(1333)])?e[s(1387)]:e[s(1831)],U=n[s(865)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),G=/^wss(.*:\/\/)/[s(1624)](n)?n:""+st+U):(st=e[s(1387)],U=n[s(865)](/(^http)((?:[s]*:\/\/))/,""),G=/(^ws)((?:[s]*:\/\/))/[s(1624)](U)?U:""+st+U);let Re=w?e[s(1892)]:b?e.GAPzV:s(1893)+"d",fs=w||b||m;if(e.FzjOv(!fs,!Re))throw new Error(e[s(1246)]);let Dg=e[s(1015)](e[s(1817)],typeof I)?await e[s(1679)](I):I,Pg=ne?e[s(352)](Xp,ne.xUseEnv,ne.xTTEnv):{},Ta=Object[s(624)]({device_platform:e[s(1380)],version_code:e[s(764)],access_key:g,fpid:f,aid:C,[Re]:fs,xsack:M?1:0,xaack:M?1:0,xsqos:K?1:0,qos_level:K?J:void 0,qos_sdk_version:2,...Pg},Dg),Og=Object.keys(Ta).reduce((Ca,Ra)=>Ta[Ra]!==void 0?""+Ca+(Ca?"&":"?")+Ra+"="+Ta[Ra]:Ca,"");return G+s(1251)+Og}else{if(this[s(444)+"ngTimer"](),this[s(1322)+s(546)](),this["_removeW"+s(420)+"rs"](),this[s(1103)+s(1354)](1e3,_0x42f5ad),this[s(1143)+s(351)]=!1,_0x20bbea&&this[s(1759)+"orOnline"]()&&!this[s(1774)+s(1259)]){if(this[s(1870)+"tManager"]?.[s(740)+"chMaxTries"]()){let m=this[s(1870)+s(1033)]?.[s(560)+s(573)+"nt"]();this[s(769)+s(1032)+s(1652)](l.uXUnz(_0x15adb4,l[s(1188)],{code:1006,reason:s(1203)+m+(" timeout, max retries re"+s(1092)),wasClean:!0}))}else{let m=this[s(1884)][s(501)+s(1292)+s(1930)](_0x49e7b3,_0x412899);this["_dispatc"+s(1032)+"ent"](l.AIxea(_0x148b40,l[s(1188)],{code:_0x2b9953,reason:_0x20cb24,wasClean:!0,willReconnect:m})),m&&this._connect()}return}this[s(1759)+"orOnline"]()||this[s(1774)+"osed"]?this["_dispatc"+s(1032)+"ent"](l.Bplwk(_0x59ac05,l[s(1188)],{code:_0xf82b11,reason:s(1849)})):this[s(769)+s(1032)+s(1652)](l.AwhbH(_0x27c0a8,s(1978),{code:1006,reason:l[s(782)]})),this._ws=null,this[s(1870)+s(1033)]?.[s(487)+s(1657)+s(1520)](),this[s(1291)+s(1451)]?.["resetCou"+s(1872)]()}}async[t(1143)](){let n=t,s={jXBcb:n(1799)+n(1859)+"s",koLMv:n(1667),hIVTE:function(l,f,m){return e[n(1390)](l,f,m)}};if(e[n(888)](e.LTjsU,e[n(724)]))return this[n(1823)][n(499)];if(this["_connect"+n(351)]||this[n(1774)+n(1259)])return;this[n(1143)+n(351)]=!0;try{let l=this[n(1870)+n(1033)]?.[n(516)+n(1248)+n(543)+"hedMaxRetries"](),{timeoutInterval:f}=this._options;if(l){let w=this._endpointManager?.["getCurre"+n(573)+"nt"](),b=this[n(1870)+n(1033)]?.[n(505)+n(1260)+n(1449)+"UpdateCo"+n(1690)](),g=this[n(1870)+"tManager"]?.[n(560)+"ntEndpointTriesC"+n(519)]();if(b){let C=n(1203)+w+(n(1236)+n(644)+"tries re"+n(1414)+"ill use "+n(1202)+n(651))+b+(n(601)+"y"),I=e.mFRtB(lt,e[n(471)],{message:C,code:sn[n(1876)+n(1261)+"R"]});this[n(389)](C),this[n(769)+"hErrorEv"+n(1652)](I),this[n(1252)]=await this[n(350)+"eUrl"](b),this[n(389)](n(1203)+b+" "+g+" times"),this[n(1796)+n(420)+"rs"]()}else if(e[n(629)]===e[n(629)]){let C=n(1203)+w+(n(1236)+", max retries re"+n(1092));this[n(389)](C),this[n(769)+n(1662)+"ent"](e[n(490)](lt,n(1035),{message:C,code:sn[n(1876)+n(1261)+"R"]}));return}else this[n(444)+"ngTimer"](),this[n(1314)](zrLCDu[n(1061)],zrLCDu[n(363)]),this[n(1935)+n(1151)+"Id"]=zrLCDu.hIVTE(_0x40989d,this[n(1955)][n(933)](this),_0x50e531)}else{if(e[n(1406)]===e[n(840)])return this[n(1880)][n(749)]();{let w=this["_endpoin"+n(1033)]?.[n(560)+n(573)+n(745)+n(1908)](),b=this[n(1870)+n(1033)]?.[n(560)+n(573)+n(1928)+"ount"]();this[n(1252)]=await this[n(350)+n(879)](e[n(885)](w,"")),this._debug(n(1203)+w+" "+b+" times"),this[n(1796)+n(420)+"rs"]()}}if(this[n(1407)])this._isInit=!1;else if(e.uwebt(e[n(680)],e[n(411)])){let{type:w}=_0x1ed2fe;this[n(1314)](w,_0x3bf729)}else{let w=e[n(368)](ya,e.BBBaB,{message:e[n(923)]});this[n(416)+n(812)]&&this[n(416)+"econnect"](w)}let m=this["_endpoin"+n(1033)]?.[n(560)+"ntEndpoi"+n(1928)+"ount"]()||0;e[n(883)](m,1)&&await this._wait(e[n(1324)](m,1)),this[n(389)]("connecting url: "+this._url+(" protoco"+n(1882))+this[n(1551)+"ls"]),this[n(1703)]=e[n(964)](Vp,{url:this[n(1252)],protocols:[this[n(1551)+"ls"]],headers:this[n(1884)]["miniProg"+n(845)+"s"][n(1097)+"tpHeader"]},this[n(1884)].ws),(this[n(1465)+"er"]||this[n(433)+"r"])&&this[n(1703)]&&(this[n(1703)][n(1601)+"pe"]=this[n(853)+n(1269)]),this[n(1918)+n(1896)](),this["_connectionTimeo"+n(938)]=setTimeout(this._onTimeout[n(933)](this),f)}catch(l){throw this[n(1143)+n(351)]=!1,l}}["_clearTi"+t(546)](){let n=t;e[n(1734)](clearTimeout,this[n(1143)+n(718)+n(938)]),this["_connect"+n(718)+n(938)]=null}["_clearPi"+t(438)](){let n=t;e[n(577)](clearTimeout,this[n(1935)+n(1151)+"Id"]),e.xxqgV(clearTimeout,this[n(1842)+n(1114)+"tId"]),this[n(1935)+n(1151)+"Id"]=null,this[n(1842)+"ctTimeou"+n(1755)]=null}[t(389)](...n){let s=t;this[s(1884)][s(880)]&&console[s(973)].apply(console,[e[s(704)],...n])}["_getInte"+t(1145)+"e"](n){let s=t,{initReconnectInterval:l,maxReconnectInterval:f,reconnectIntervalGrowFactor:m}=this._options,w=e[s(1813)](l,Math[s(1596)](m,e[s(1320)](n,1)));return w>f?f:w}[t(1955)](){let n=t;if(e.YeGfO!==n(675))_0x5a2410("success"),this[n(1311)](e[n(1590)],_0x252f13),this.off(e.jKlQD,_0x162ce6);else{if(this[n(1703)]&&this[n(1703)][n(1708)+"te"]===this[n(1187)+"NG"]){this[n(444)+n(438)](),this["_pingPon"+n(1151)+"Id"]=e[n(1786)](setTimeout,this[n(1955)][n(933)](this),this[n(1884)][n(1529)+n(742)]);return}if(!this[n(1703)]||e[n(405)](this[n(1703)][n(1708)+"te"],this[n(1169)]))return void this[n(1671)+n(812)]();this[n(1703)]&&this._ws[n(1751)]("hi"),this[n(1842)+"ctTimeou"+n(1755)]=e[n(1845)](setTimeout,this[n(1671)+n(812)+n(1907)][n(933)](this),this[n(1884)][n(1420)+"outInter"+n(1992)])}}[t(1671)+t(812)+t(1907)](){let n=t;this[n(1291)+n(1451)]?.[n(1306)](),this[n(1314)](e.jKlQD,n(1746)),this[n(1291)+"sCounter"]?.[n(740)+"chMaxCount"]()?this[n(1671)+n(812)]():this[n(1955)]()}["_navigat"+t(677)](){let n=t;return this._isMiniTT||this._isMiniWX?this[n(1436)+n(1345)+n(1289)]:(this[n(1465)+"er"]||this[n(433)+"r"])&&this[n(1884)][n(1933)+n(1068)+n(939)]?navigator.onLine:!0}[t(1671)+t(812)](){let n=t;!this[n(1759)+n(677)]()||this[n(1774)+n(1259)]||(this["_endpoin"+n(1033)]?.["resetEnd"+n(1657)+n(1520)](),this[n(1291)+n(1451)]?.[n(965)+"nter"](),this[n(1703)]?this[n(1924)+n(1685)](1001,e[n(1607)],!0):this._connect())}["_onPageN"+t(833)+t(1346)](){let n=t,s={LlpBY:function(l,f){return l!==f},OXQFg:e[n(610)],LGHLN:e.zULrj};this[n(985)+"T"]?tt[n(1909)+n(1663)+n(785)](({isConnected:l})=>{let f=n,m={blypv:function(w,b){return w(b)}};s.LlpBY(s.OXQFg,s[f(1256)])?(this[f(1436)+"igatorOnline"]=l,l?this[f(1639)+f(778)]():this[f(1639)+f(1980)]()):_0x3d5132=LLToSy[f(1939)](_0x561988,_0x31c540)}):this[n(1971)+"X"]&&wx[n(1909)+"kStatusChange"](({isConnected:l})=>{let f=n;this[f(1436)+f(1345)+f(1289)]=l,l?this[f(1639)+f(778)]():this[f(1639)+f(1980)]()})}[t(1355)](n){let s={zrRxV:function(l,f,m){return e[F(1040)](l,f,m)}};return new Promise(l=>{let f=F;s[f(542)](setTimeout,l,this[f(1298)+f(1145)+"e"](n))})}[t(1924)+t(1685)](n=1e3,s="",l=!1){let f=t;this[f(1703)]&&this[f(608)+f(1135)+"t"](n,s,l)}[t(565)+"ut"](){let n=t;if(e[n(1981)](e.ucSdJ,n(1229))){let s=this[n(1870)+n(1033)]?.[n(560)+n(573)+"nt"]();this._debug(n(1203)+s+n(1236)),this[n(1924)+n(1685)](1001,e[n(859)],!0)}else return _0x150aae[n(1997)+"t8"]?_0xfa5513[n(1997)+"t8"](_0x3c7d6b,_0x41231c):_0x137e08[_0x4afefd]=e[n(1069)](255,_0x25d3df),e[n(1389)](_0x45f14f,1)}[t(921)](n){let s=t,l=e[s(2e3)](Ht,n);this[s(1703)]&&e.dsUOy(this._ws.readyState,this[s(1169)])&&(this[s(1703)]&&this[s(1703)].send(l),this._debug(e[s(797)],n))}[t(1796)+t(420)+"rs"](){let n=t,s=e[n(1467)].split("|"),l=0;for(;;){switch(s[l++]){case"0":this[n(1703)][n(1100)+"entListe"+n(1429)](e.VzZKJ,this._onOpen);continue;case"1":this[n(1703)][n(1100)+n(1790)+"ner"](n(1035),this[n(1631)]);continue;case"2":if(!this[n(1703)])return;continue;case"3":this._ws[n(1100)+n(1790)+"ner"](e[n(898)],this._onClose);continue;case"4":this[n(1703)][n(1100)+n(1790)+n(1429)](e[n(715)],this[n(1039)+"ge"]);continue}break}}[t(1918)+t(1896)](){let n=t;if(e[n(1480)](e[n(1396)],e[n(379)]))_0x44f38b[_0x3cdedd[_0x48c5fd]["cursor_n"+n(1766)]]=_0x2e6c83(_0x24978e[_0x496065].cursor_name),_0x21d217+=14+_0x42beb3[_0x464d80[_0x5edfee][n(1730)+n(1766)]];else{if(!this[n(1703)])return;this._ws[n(1258)+n(1745)](e[n(1792)],this[n(689)]),this[n(1703)][n(1258)+n(1745)](n(1978),this[n(1852)]),this._ws[n(1258)+"Listener"](e[n(715)],this[n(1039)+"ge"]),this[n(1703)][n(1258)+"Listener"](e[n(471)],this[n(1631)])}}[t(1103)+t(1354)](n=1e3,s=""){let l=t;if(e[l(426)](e.UKlJu,e[l(774)]))this[l(1407)]=!0,this[l(1143)]();else try{if(e[l(1950)](l(1239),e[l(1680)]))try{return!!this[l(1880)]}catch(f){return _0xa4a10e[l(973)](f),!1}else this[l(1703)]&&this[l(1703)][l(1978)](n,s)}catch{}}[t(608)+t(1135)+"t"](n=1e3,s="",l=!1){let f=t;if(this[f(444)+f(438)](),this[f(1322)+f(546)](),this["_removeW"+f(420)+"rs"](),this["_wsInsta"+f(1354)](1e3,s),this[f(1143)+f(351)]=!1,l&&this[f(1759)+"orOnline"]()&&!this[f(1774)+"osed"]){if(this._endpointManager?.["checkRea"+f(1347)+"es"]()){let w=this[f(1870)+"tManager"]?.[f(560)+"ntEndpoint"]();this[f(769)+"hCloseEv"+f(1652)](wt(e[f(898)],{code:1006,reason:f(1203)+w+(f(1236)+f(644)+f(947)+f(1092)),wasClean:!0}))}else{let w=this[f(1884)][f(501)+f(1292)+f(1930)](n,s);this[f(769)+f(1032)+"ent"](e[f(490)](wt,f(1978),{code:n,reason:s,wasClean:!0,willReconnect:w})),w&&this[f(1143)]()}return}this[f(1759)+f(677)]()||this[f(1774)+f(1259)]?this[f(769)+f(1032)+f(1652)](wt(f(1978),{code:n,reason:e[f(834)]})):this[f(769)+f(1032)+"ent"](wt(f(1978),{code:1006,reason:e[f(1906)]})),this[f(1703)]=null,this[f(1870)+"tManager"]?.[f(487)+f(1657)+f(1520)](),this[f(1291)+"sCounter"]?.["resetCou"+f(1872)]()}[t(769)+t(1219)+"nt"](n){let s=t,l={ozWnA:function(f,m){return e[F(1549)](f,m)},sCilg:function(f,m){return e[F(1580)](f,m)},Lutmv:e[s(660)],eCDpM:function(f,m){return e.wxLqL(f,m)},XfiBl:e[s(617)]};if(e.pEwSX(e[s(682)],s(1929)))this[s(1314)](s(899),n),this[s(1650)]&&this.onopen(n);else{if(CqLcZF[s(1634)](_0x55fdec,_0x523984))return new _0x22a5a2(_0x1f8bd7,_0x493148);if(CqLcZF[s(1634)](_0x32b72f,_0x53e861)&&CqLcZF[s(1944)](CqLcZF[s(522)],typeof _0xc7ccd3))return new _0x30f424(_0x36b2e4,_0x483bac);if(CqLcZF[s(1634)](_0x1039f3,_0x2133ed)&&CqLcZF[s(473)](CqLcZF[s(522)],typeof _0x31bdb0))return new _0x30c528(_0x180767,_0x3c0eba);throw new _0x18996a(CqLcZF[s(1646)])}}[t(769)+"hMessage"+t(1499)](n){let s=t;if(e[s(1733)]===e[s(1733)])this[s(1314)](e.FXZBR,n),this.onmessage&&this[s(837)+"e"](n);else return _0x37d0be[s(973)](e[s(1307)],_0x1d1856,_0x322879,_0x51f79d),this[s(1880)][s(1777)]({cursor_name:_0x234eca,cursor:_0x26d5c7,service:_0x5878a0})}[t(769)+t(545)+t(1807)](n){let s=t;this.emit(e[s(766)],n),this[s(1070)+"eAck"]&&this[s(1070)+s(811)](n)}[t(769)+t(1662)+t(1652)](n){let s=t;this[s(1314)](e[s(471)],n),this[s(1798)]&&this.onerror(n)}[t(769)+t(1032)+t(1652)](n){let s=t;this[s(1314)](e[s(898)],n),this[s(1164)]&&this[s(1164)](n)}get binaryType(){let n=t,s={wjaDx:function(l,f){return e[F(418)](l,f)}};if(e[n(1133)]===e[n(1133)])return this[n(1703)]?this._ws[n(1601)+"pe"]:this["_binaryT"+n(1269)];{let l=_0x1229fa[n(872)+n(567)](_0x2c9556);return _0x1f462b&&l["addEvent"+n(1745)](n(1371),()=>_0x509fb9()),WgtWpI[n(618)](_0x5a7273,l)[n(1941)](()=>{})}}set[t(1601)+"pe"](n){let s=t;this[s(853)+s(1269)]=n,this[s(1703)]&&(this[s(1703)][s(1601)+"pe"]=n)}get retryCount(){let n=t;return this["_endpoin"+n(1033)]?.[n(560)+n(573)+n(1928)+n(519)]()||0}get["buffered"+t(388)](){let n=t,s=this[n(856)+n(792)].reduce((l,f)=>(l+=f&&f[n(1516)+"th"]||0,l),0);return e[n(1736)](s,this[n(1703)]?this[n(1703)][n(1295)+n(388)]:0)}get[t(1932)+"ns"](){let n=t;if(e[n(685)]!==e[n(685)])this["_miniNav"+n(1345)+n(1289)]=_0x10fa6b,_0x176dda?this["_handleO"+n(778)]():this[n(1639)+"ffLine"]();else return this[n(1703)]?this[n(1703)][n(1932)+"ns"]:""}get protocol(){let n=t;return this[n(1703)]?this[n(1703)][n(1333)]:""}get[t(1708)+"te"](){let n=t;return this[n(1703)]?this._ws[n(1708)+"te"]:this[n(1884)][n(1194)+n(1146)]?this[n(1187)+"NG"]:this[n(1901)]}get url(){let n=t;return this[n(1703)]?this._ws[n(499)]:this._url}close(n=1e3,s){let l=t,f=e[l(1237)][l(1916)]("|"),m=0;for(;;){switch(f[m++]){case"0":this[l(1071)+l(489)+"Listener"]();continue;case"1":this[l(1322)+"mer"]();continue;case"2":this[l(608)+l(1135)+"t"](n,s);continue;case"3":this["_QoSMana"+l(1510)]?.[l(453)]();continue;case"4":if(!this._ws)return void this._debug(e[l(625)]);continue;case"5":if(e.Jbypr(this[l(1703)][l(1708)+"te"],this[l(1901)])||this[l(1703)].readyState===this[l(691)])return void this[l(389)]("close, ws alread"+l(1925));continue;case"6":this["_clearPi"+l(438)]();continue;case"7":this["_readyCl"+l(1259)]=!0;continue}break}}async[t(1751)](n,s){let l=t;if(e[l(1015)](null,n))throw new Error(e[l(534)]);e.Mjyub(e[l(1409)],typeof n)&&(n=JSON[l(1647)+"y"](n)),e[l(1110)](l(1419),typeof n)&&!e[l(842)](n,ArrayBuffer)&&!(n[l(1115)]&&n.buffer instanceof ArrayBuffer)&&(n=JSON[l(1647)+"y"](n));let f=await e[l(2e3)](Al,n),m=e[l(1717)](Zp,n),{method:w=0,service:b=this._options.service,logID:g=this._options[l(971)+l(476)](),headers:C=this[l(1884)].headers,payloadEncoding:I=this[l(1884)][l(1968)+l(989)],payloadType:M=this[l(1884)][l(439)+l(1269)],logIDNew:K=this[l(1884)]["logIDNew"+l(1083)]["enableAu"+l(1912)+l(638)+"ew"]?i(this[l(1884)]["logIDNew"+l(1083)][l(1233)]):""}=s||{};if(!b)throw new Error(l(642)+l(901)+l(1517)+l(1344));let J={SeqID:xe[l(1644)+"er"](this[l(1481)]++),LogID:xe[l(1644)+"er"](g),service:b,method:w,headers:C,payloadEncoding:I instanceof Object?I.encoding?I[l(1098)]:"":I,payloadType:e.wqSRR(M,Object)?M.type?M[l(1155)]:m:M||m,payload:f,LogIDNew:K},ne=e.foOub(Ht,J);return this._ws&&this[l(1703)][l(1708)+"te"]===this[l(1169)]?(this._ws&&this[l(1703)].send(ne),this[l(389)](e[l(1072)],J)):e[l(1215)](this[l(856)+l(792)].length,this[l(1884)][l(758)+l(1167)+l(428)])?(this[l(856)+"Queue"][l(1113)](ne),this[l(389)](e[l(755)],J)):(this[l(856)+l(792)][l(1468)](),this["_message"+l(792)][l(1113)](ne)),{seqID:this[l(1481)],logID:g,logIDNew:K}}async[t(501)+"t"](n){let s=t,{url:l}=e.Rfqke(n,{}),f=Array.isArray(l)?l:e[s(507)](s(1419),typeof l)?[l]:[];n&&Object[s(624)](this[s(1884)],n),f&&f[s(551)]?this[s(1870)+s(1033)]=new bl(f,this[s(1884)][s(1975)+"es"]):this[s(1870)+s(1033)]?.[s(487)+"pointCon"+s(1520)](),this["_pingLos"+s(1451)]?.["resetCou"+s(1872)](this[s(1884)][s(1216)+s(1087)]),this[s(1774)+s(1259)]=!1,this[s(1703)]&&e[s(513)](this[s(1703)][s(1708)+"te"],this[s(1901)])?this[s(1924)+s(1685)](1e3,e[s(768)],!0):(this._isInit=!0,this[s(1143)]())}async connect(){let n=t;if(!this[n(1143)+n(351)]){let s="3|2|0|1|4"[n(1916)]("|"),l=0;for(;;){switch(s[l++]){case"0":this[n(1774)+n(1259)]=!1;continue;case"1":this._isInit=!0;continue;case"2":this[n(1291)+n(1451)]?.["resetCou"+n(1872)]();continue;case"3":this._endpointManager?.[n(487)+n(1657)+"fig"]();continue;case"4":this._connect();continue}break}}}addEventListener(n,s){let l=t;if(e.zCpdl==="bpRiy")return _0x3d0522?.find(f=>f.key===_0x4d8274)?.[l(703)];this.on(n,s)}["dispatch"+t(1499)](n){let{type:s}=n;this.emit(s,n)}[t(1100)+t(1790)+t(1429)](n,s){let l=t;e[l(1743)]("phnPk",e.wqkPM)?this.off(n,s):(_0x25e236(_0x51113f,e[l(590)](127&_0x1d24a6,128)),_0x5847ad>>>=7)}[t(1099)](){let n=t,s={SIAev:e[n(678)],nbimX:function(l,f){return e[n(634)](l,f)},RDvwK:e[n(788)],CkhIN:n(1667),FCYjc:e.aypqs,yYFCo:e[n(1125)]};if(e.DJfuI(e[n(1019)],n(1025))){let l=s.SIAev[n(1916)]("|"),f=0;for(;;){switch(l[f++]){case"0":this[n(1185)+n(1510)]?.[n(453)]();continue;case"1":if(this[n(1703)][n(1708)+"te"]===this[n(1901)]||uXOAWd[n(1548)](this[n(1703)][n(1708)+"te"],this.CLOSING))return void this[n(389)](uXOAWd[n(1412)]);continue;case"2":this[n(1774)+"osed"]=!0;continue;case"3":this[n(1071)+n(489)+"Listener"]();continue;case"4":this[n(608)+"WebSocket"](_0x10c9b7,_0x49ff97);continue;case"5":this[n(444)+n(438)]();continue;case"6":if(!this[n(1703)])return void this[n(389)](n(1705)+n(459)+"ce not i"+n(1190)+"ed");continue;case"7":this[n(1322)+n(546)]();continue}break}}else return new Promise((l,f)=>{let m=n,w={ShOIK:s[m(538)],Vcvqe:s.yYFCo};this[m(444)+m(438)](),this[m(1935)+m(1151)+"Id"]=setTimeout(this[m(1955)].bind(this),this[m(1884)].pingInterval);let b=()=>{let C=m;l(s[C(599)]),this[C(1311)](s[C(538)],b),this.off(C(1799)+C(1154)+"t",g)},g=()=>{let C=m;f(C(1746)),this.off(w[C(431)],b),this[C(1311)](w[C(1609)],g)};this.on(s[m(538)],b),this.on(s[m(1583)],g),this[m(1955)]()})}}})(),be[N(1668)+N(563)]=Ne["CustomCl"+N(563)],be[N(757)+N(975)]=Ne[N(757)+"rorEvent"],be[N(1754)+"e"]=Ne.ErrorCode,be[N(1499)]=Ne[N(1499)],be[N(943)]=Ne.FWS,be[N(858)+N(1075)+N(1368)]=Ne[N(858)+N(1075)+N(1368)],be[N(1075)+N(1368)]=Ne[N(1075)+N(1368)],be.OpenEvent=Ne.OpenEvent,be[N(841)+N(1515)]=Ne[N(841)+N(1515)],be[N(1946)+N(563)]=Ne[N(1946)+N(563)],be["createEr"+N(975)]=Ne[N(961)+"rorEvent"],be["createMe"+N(875)+"nt"]=Ne["createMe"+N(875)+"nt"],be["createOp"+N(1735)]=Ne[N(1696)+N(1735)],be[N(1686)+N(1184)+N(1368)]=Ne[N(1686)+"connectE"+N(1368)],be["decodedF"+N(738)]=Ne["decodedF"+N(738)],be[N(1010)+N(1766)]=Ne[N(1010)+N(1766)];for(Xo in Ne)[N(1668)+N(563),N(757)+N(975),N(1754)+"e",N(1499),"FWS",N(858)+N(1075)+N(1368),N(1075)+N(1368),N(1376)+"t",N(841)+N(1515),"createCloseEvent",N(961)+"rorEvent","createMessageEvent",N(1696)+N(1735),N(1686)+N(1184)+N(1368),N(1247)+N(738),N(1010)+N(1766)][N(866)](Xo)===-1&&(be[Xo]=Ne[Xo]);function ra(){let t=["vhbrv3q","vgLTzw91Da","yxrLq291BNq","B25ozxr3B3i","yvbLwK0","uMLltNe","Dg9hzw5LCMe","Avnqufq","DuTkBxK","Bu9bC3a","C3bSAxq","vKPMD1a","x2fKzfDZtgK","Cxfvz24","DLvvr1e","vw5PBxbSzw0","u3LiAMq","y0LztLm","x2rPC2nVBM4","EsbJBg9Zzwq","FdH8nxWZFde","zwrPyxrLBhK","BNruCMLLC0m","uLDbz2q","ChrVCG","AKLSs1q","zxH0zw5ZAw8","BgLZDgvUtMu","sLnptLa","x3bPBMDqB24","zxjFCw9Z","weLisKy","z3PcCuu","yMX5Chy","u1HZChy","DgHLBG","sKDKwNO","igfYCMf5yNu","C0nPBgC","yvvuC2m","y3jLyxrLq2W","s3L6Be8","D2XjDwW","nfngvhz1yG","uhftqu0","CxvWqMK","BgzIwLi","qwzczMu","AgXOBwe","x3bPBMC","C2fNzq","y2XLyxjtDg8","AhLRqK4","CMvHzhDYAxq","y2XOsLq","Dg9cExrLC0i","r3rTAhO","v1bTwMu","CMvZB2X2zq","DvjKAgu","EunXAMG","sNrgsMS","Cgf5Bg9Hzeu","rgvKAwnHDgu","ELbpEue","x2LZtwLUAvC","o2nOyxjZzxq","wef1r2K","vhz5BNG","Bwf4uMv0CMK","Aff3svK","zLD6Egi","y2XVC2u","AM9PBG","zMzmAw5L","yMvlDhy","C1LLAKO","BhzAwMW","zMLSDgvY","ruXHDeS","u1bwCge","BMXczLi","DLLIv1C","yxbWzw5Kq2G","sKDRtM4","zw9JB0y","DMfS","t2jQzwn0","x2n1CNnVCKy","zvDhBMu","weH6wuK","D3jPDgvvAw4","shfMy0m","Dg9cExrLC0W","ueLYDge","rvnVugO","z1PrzeK","yvjzsfO","zcWG","BwLMEwu","CKPyEeW","uxHjtha","x2DLBMvYyxq","tg9JAW","qLviCgG","zNjVBNrPzxi","zxf1ywXZ","ysbTDxn0igi","tLz6quG","B3bLCNr5tMe","CuDJteK","C2voCK0","CNnVCL92ywW","BMfTzq","t0H5wum","A29mtxy","r1L0CMm","CM92AwrLigi","ugfzDu8","x2nYzwf0zvm","yMDjzha","ruLpuLq","yLDmD2O","BgLUzw5V","yKfrshy","AxnrB1nby2S","yLHmBeW","DuTmtee","rNjQC2u","D3HdAxq","zNDZxZeUmc4","t3HHvhC","ue5Prg8","vMrSweG","uMffC2W","vwvcu0y","y3vYC29Yx2y","suPnq3q","yuvLu2m","mxWWFdL8mxW","qw1VDw50","x2rLyNvN","EgTeweC","q3jyq3a","s1rwy0m","DuHACNG","BwrOCMK","y2vZC0HHBMq","EKLpuLu","EfzOD3i","ELfXBKO","u0flAKW","Ce1Lvxq","zxjYtxnN","sNHjreO","zvLbBwC","swXwEgK","uMrsEvy","y3jJAKG","y25yBfm","Dhfotve","shjkDu8","DKPyEwG","qNb4DKm","z2u6ia","EK92vfe","ugPJAgK","BfnrC2G","B25tDgfYDfi","yM9L","zKLNB2K","DKzdyw4","C0XPC3rLBMu","ufrJBvu","BLjvsfe","BwLZzq","zur3y04","DNjWCeC","wKzOB2C","Bwf4tg9ZC0m","zw5NDgG","uuHcsNC","yLH0veu","u2HpsuS","CMvHzfvjBNq","x2LZv29YA2u","zMDbA1K","AKfMA00","C2v0y3vYC28","u2XWsuG","BMDuAw1LCG","Cgf5Bg9Hzfq","B25SAw5L","uvbcu1i","tMfTzq","wfvyDve","x2nSzwfYugK","EMntvuq","CMvHC29U","C3vIyxjYyxK","D3n3B2S","s29MAui","rNPutNq","AMvJDfn0B3i","DfLzB3a","y2XVC2veqG","x2n1CNnVCK0","nhWX","zvjHt1q","y3vYC29Y","teLiuvG","CYbPBNn0yw4","sg9ezNq","qNniuLe","vMLjyu0","BxnN","uuLQreS","yKjKEvy","DxbNCMfKzw4","B2nRzxq","AgfZt3DUuhi","CgfNzxnOB3C","DhjPzxm","AuDvB24","zM9YrwfJAa","zuneCe0","BhjNzwi","DMvYC2LVBG","zxjHDg9Y","zM9Yy2u","x2TLEvbHDgG","ywDLu2HVDW","z2Lgsum","vNL2uw4","BIWGAg9ZDg4","sfvHyw8","swv0u3a","ywXSq3vYC28","Eejozxq","CMvZzxrfBMq","vezUA2u","yMfSrxzLBNq","uu1jree","zxq9DxrMltG","Chv0","zxrstg8","r1fgA1m","Dhj1y3rVCIa","rNnsCuC","AhfysvK","ChnMv0i","DxjS","rKPYtfa","CMvJB25Uzwm","yu9Nwe4","rwnutwG","wfb5tLe","CMvWBgfJzui","AgPmEu0","B3vdv0i","EgfXtwS","uxn1ANe","DMnyueG","ywTjEu4","rwrXv2u","wgPltee","quzrBuy","D3bSs1O","y2HLy2TdDxi","AffQCNa","rNvuyMi","B3vUDa","s1rtCwi","vgzkzui","thv0Bxy","C2XPy2u","ywrK","DLbVDwK","rerov0e","tvDAEg8","r01Mtge","Eererva","yM5hvfG","z1rzD3K","ywr2yw5Jzq","zgTqyvG","DgPxtNK","ihn1y2nLC3m","CMvXDwLYzwq","wLzRAxe","rKnzAMm","wgnKz1a","CMTLCKDSB2i","uvHZqLi","ENjsEfy","B2LUDfjLywm","y29UBMvJDgK","AefJA01LC3m","BwvY","ywDkAMe","CuXKtxi","uePUzwK","C0X0Euy","BgvUz3rO","Dg9Y","DwHbD0i","s3rsCwC","r09evei","Exnwqvy","yMTOzKS","y2HnyxHdB3u","yw5gq3G","z2v0q3vYCMu","tKfusvzfx0u","z2r3EuO","B3nLrxzLBNq","EgfZCMu","x29UvgLTzw8","Cu5vsgO","DgfIyxnL","AxzVzLa","tgDKAMC","Bg93","txnqsw4","zKLksKm","BNrfBMrWB2K","twLZC2LUzYa","AgfKEfi","v0n1Cw8","wejUB0i","zunhwgG","y3vYCMvUDeu","wxfNCvG","Ec1TC2CTy3u","tfrfvLe","A1LOtum","x2zVCM1HDeu","rMLUrfa","C29YDa","ufDptey","vKv3Dxi","A1vmCKi","zunJz2W","wwLqAKC","ugn1B20","q1brqw4","zgvS","otyXmtiXDgTftM95","BfPUyKC","zMLnvg8","z2jJzuW","q2TOsu4","tMT3tgG","ihrVihjLDhi","BwvZC2fNztO","qunvwwC","m3WY","x2LZtM9Kzq","DxPltei","BwfW","x2rLC3rYB3K","yMPREM4","AwTQuwK","zg9Uzq","wvHJquC","q25TAwi","AxnmB25N","rgXbrM0","rMXZAwi","Bu1iuxG","D2PHrhG","C2DPza","AwrI","shHTreO","tvHwEKu","svDxr2S","yxnZAwDU","tvnTvg4","z2v0","r2PfBeO","u2vXsuq","yNHuuNi","vffXse8","zuHIDKq","zNnurNy","sLDVCMm","rK11veK","sLDhru4","ALjxBxe","AwTbvKW","DgvmB2Djre4","vvjbtKW","Avv6y0C","s1rNzwW","CgXLyxnLiha","CvPKqw8","lcbTyxGGCMu","Dw5ZAwDUzwq","ywnRx2LK","thLtswm","BNjqv0u","CMfjq3G","AgvHzgvY","BMrWB2LUDca","shzlBeK","AxH4Cgi","BeTAsxi","yxjYyxLIDwy","A21pChO","AMTeuue","C21vC3q","BM9rru4","sgrTEhu","uLj3rvy","shPTAhK","B2zMC2v0","mNW0FdeXFdK","DKXZug0","u1nSDgG","AxrftNG","y0LfwuC","ANbUAMi","EKnVA2i","Ef9MCM9UDgK","tw9KDwXL","C2vUzf9Hy2S","z3zHDK0","sNHQC04","AxnAzxjV","B3jpBMXPBMu","EwfXAwO","AMPVAKe","yMjjug0","yxjKt24","suLkD00","A1blB2K","A2v0ignVBNm","zhbpu08","q09OzLi","BwDoyKi","ihjLy29UBMu","x29Ut3bLBG","yMfmBgS","q0Xpu0LorW","zxjFAxnFywm","uLbozLC","t0zgsKq","EK90qvK","zLLZz0m","ww5jsuO","q0nTr24","DhjHBNnHy3q","ALLmuMu","rwrpvMy","zujHsxm","DMfSDwu","sLjOsgK","BwTnBK8","wg1Iru0","zxLUwgu","wuDJvMG","A2jvyMC","Dg9cExrLCW","AgvHzgvYCW","DgLLCKPtt04","BwTqzK4","Aezduue","rLHAqLi","sw5vzu4","DNP5yum","Aw9UvgLTzw8","wgHIAue","AKHZAxO","uuX0DKW","B3bLBKrc","CNfwzey","tfrQC1u","AhDiD3u","tKnLy2G","B3bLBIa","D3vQu2m","uejothy","y3r4","wvHrs3e","rMXxv3K","B0XJEfy","uvPNB0O","zgfUDvm","ywDLsgLKzq","Ce9usLu","CMfTzq","BKTPzhK","y2HLy2Tszwe","Cgu6ia","CNzHBa","r05qAw8","zgvSzxrL","BNrbBMrvCgq","zNvUy3rPB24","vvnNshi","sezkDei","y2XLyxi","B25nzxnZywC","C2v0q3vYC28","zMP2DMG","u0HAD3C","uwj4rNu","ALv6DLm","Ae1LC3nHz2u","q3vZDg9Trxi","Bwf4twvZC2e","y3vLse4","B3jLtMfTzxm","lcbOB3n0BMe","t1bftL9fuLi","rMzYt1y","wKrXy2y","q0zJEM8","A09sqMO","tw5jtKi","whrQDeO","x2rPC3bHDgm","sw53tg8","Befbvuy","CujlA0C","DMvYC2LVBMm","D1zgC2K","AgL6Dvi","sK1wuva","x0vysvnu","BKXPBMu","EuD5Cvi","Dhr3Awq","EKr0v24","tvjIu2y","rvndtLK","BKLXvKW","AgfUz2u","ywjVCNq","uxLUCeW","y05gvuu","quvhz1O","DwvuqNK","EgrAD0m","uxvLDwu","rxDYruW","wvj0Cgy","CKjuB0e","n3WXFdz8mhW","EvHTqM0","uefLt2W","z29PBMCGyxC","CLzHBhvLCW","qurlsuu","BgnUzwC","vwXHugO","A2zUr2i","ugXcvKS","CgfNzwHPzgu","yLvOzK8","tK9bCfO","zxjFywnRx20","DgHHBIbSB2m","zufJAW","zwnVBM5Ly3q","oduZnJyYmfLKrNvwBG","CfHsyK8","t3HfC2W","BKPuBLy","suroueW","tKfkwfC","B25dBg9Zzq","C1zyDeC","r211rNe","ywzezvq","sM5eAge","rfbiCey","A3jsvhq","CMLLC0nVDw4","sxz1zvO","rhzxs0G","zez3A0C","wvvXufK","t1Pnwem","AMDUs3a","zxrxB3jRq2G","yu9WqNa","AxjLza","DKHryxi","B25TzxnZywC","wgXeB0S","zwDtuKG","sxnJyNK","uMvJB25Uzwm","q3brv2C","CMrnBLK","BwvZ","CMfTugfYyw0","AwDIwMe","CMvZDwX0","zNjVBuHHC2G","s0nRtfG","B2nRzxrtDwm","D2LKAK0","uMvHzcbWyxm","x2jPBMfYEvq","Dg9VigXHCMC","mdaWmdaWmda","x21LC3nHz2u","suffyKK","rNjVBNrPzxi","tenuEgu","AeHRvuy","Aw5KzxGGB3u","wwfuA3y","ExbrzKq","u2XfzK0","CMvWBgfJzq","Aw5KzxHpzG","DxbovwK","BNz6z3y","CfvPv0S","B2nszxi","u0jXvgm","zgvSzxrLrge","BfrPBwvVDxq","B3PeCuK","C3nHz2vfDMu","BKTsuxi","wvnnuxe","Aw5N","zvvYBa","zgvIDwC","y3vYDMfSDwu","zhrhsNm","r0TdB2y","tNfkwfG","q0nQEwu","vgTMCMK","tgnTAu4","DM55t1K","vhLAC1q","AejxAg4","zNHgD1O","ze1Vsfm","Ec11C2uT","Ahr0Ca","wfPRBvu","AevxA2e","ugvxq3u","zufpCeq","B3bLBG","zfLhCNu","CM92AwrLige","uhjTtfe","zuXbt2y","Dg9XzuG","CKDXAwy","zxLcyxK","CM92AwrLihy","q25ut1i","BMvJDa","vMXHrem","CM9HqLq","wgTftLi","y2fSBa","r05Hrwi","wgfgt2K","BvjuwuK","ELDrA1q","x29UugfNzu4","AgL1ANu","txzsAMG","x3nLBMrby2S","yxjntMq","qMDwzwS","wwHItxm","mJm0ogXrEuDZtq","tKPiswG","sKnXwKe","r3bAuMy","y29UDgLUDwu","rvjst1i","z2v0q3vYC28","vw1TD3u","yMLUza","D1fwCKG","uhjPBwfYEuS","zNLPwK0","tvzKBhm","Dxrjza","BMDLza","ywX3yxLZ","Agr4veq","B2zMBgLUzq","rLDt","wxbfELm","EKTdD2O","yNz3AMy","DhjPzxmGCMu","D3HmCuW","quHoue8","z1DKs24","EKTNEwG","A1bVshO","zNnqD3e","uNPRswG","zNjVBujPDhm","zMDhAe0","D2LpBhG","vLPqquy","yMfSu2nVCgu","AxDorKi","y3jLyxrLrxi","DNrLB3q","A09rEe4","zgjsDNG","CMvZzxrdB3u","v05Aq0C","DwfbDLi","AwHpruW","t3nNBee","qKLhs0G","Bg9Nsurhzw4","y29SBM8","Bg9N","BMCGzMfPBgu","CM9YrxzLBNq","ywnRx2nVzgu","zM12Ew4","ChbL","Dhzlrfa","C0P5y1u","sLzUA2e","y1vrDu8","u2DXu04","z21Pr1i","x2LZtwLUAvq","x2LUAxrhBg8","BMrLEa","BuvHuuW","BMnVzgLUzW","tNzxCuW","CMvZzxruCMK","rLHsrLq","veLoyKm","sfz2BKK","wvjRCwy","z2v0u3rVCMe","vxbKyxrLq28","BLrXy2O","v2LUzg93","sxnOA1G","qufUs3a","rxvYCe8","Bvv1wgq","vgTVCgu","C3jJ","Ce5rCNe","teffCKm","y3jLyxrLt2i","t3rNwue","zw5JB2rLrNi","AKT1A1i","A3bACwW","Dgvbtg4","DMPdy1q","tvjOtwS","zNnkzK8","s1fZzLi","DMvY","q25sBxO","BwvZC2fNzv8","zw5HyMXLuw8","Aw9WDhi","Bgn4wha","DLf3ufC","zhnUExm","Dg9iyxnO","Dw5RBM93BIa","wxbvyNm","z2TwAeq","zgf0yq","r2zqDhm","AenSB3nLrxy","De1HBMfNzxi","yvbJAMC","zxjYB3i","wxLgBMy","tLvNtMC","CwTOtg8","x29UtwvZC2e","CKfgy3O","zxmGCMvHy2G","swziy0m","qNjPzgDL","x2rItMfTzq","AMHnCem","AM5jDLa","Aw5L","EKT1v2q","qvDzrNK","zfDVCMTLCKC","q0TzshK","rLjQr1O","pxv0zI04","tevethG","x2HHBMrSzva","s0TVsu0","D2LSBfjLy28","q3nisKe","yLLwALy","uM1vwu8","ALHcy2i","y2XuDgu","odm1oty3tvz3Ag1o","wMvytwu","EvjLy29UBMu","z2v0qwXS","Aw9U","DhDVCMTdAge","v0zkuey","B25szwnLAxy","x2rYB3bhBg8","rxPPugK","DwfIEgK","ihrYEsbYzwm","twvZC2fNzuu","y29TCgXLDgu","u3rYyxrLz3K","u3nSuLu","vKrqBu8","ywXty29Wzq","ze5zD3O","v0Pcv3C","q29UzMLN","mhW2Fdf8na","Aw5Lza","BwXZy0e","q291BNq","q0X3Ege","zuvtzha","qLLSzee","DenuA2S","ywnOzwq","C3rHCNq","BNvTyMvY","zM5HyNu","vLzSD1G","y3vZDg9Tshq","zw5JB2rPBMC","CgLUz09Uy2u","CMvTB3zLrxy","BwLUzW","twrXqMy","x3DZsw5ZDge","vhPHtwW","zLHhuxm","se1LEui","A2v5","uvDRCe4","rNPQt3y","CMfmuK0","vLvhqNO","t1rgDhC","ChvZAa","y3ruAw1LB3u","yNvMzMvY","tgfYrgi","sgLHtwe","BezSDxnO","Bwv0Ag9K","rNzNru4","C3vIC3rYAw4","zK5Rwxy","yLbzEuS","vejVqLG","AKTSuuq","EMX5wuC","wwvLrLm","C2vYDMLJzq","x3bYzwzPEa","z2vtEw5J","zwvKzwq","q2Pwvgq","r0j6tLy","ywXS","v2vIu29JA2u","tKfRy04","D24GCMvHC28","Eu1pA0i","rMHjuMi","AezmExu","DgLTzw91DcW","AvzbDLe","x2nVBM5Ly3q","BwjAEeK","CNzHBfzHBhu","y09Wzw4","y2Ptree","wNPmsLy","END1Bwq","D2fZq2XLyw4","z1rPBwvVDxq","svbQwMC","BfDwDKm","zv90Aw1LB3u","DhLWzq","yxbWBhK","q2nQBwi","t3jQB0C","AxnszwfKEq","wfjwvMC","B2rjqKG","EfHRqwq","y29Uy2f0","B25JBg9Zzq","mdaWma","DufOAwe","z2vrDwv1zuW","rxPlDgG","t1bftG","wfjnDhm","C3rHuLa","qu5vvKK","y3HZy3y","AenIBe4","DhresvO","BMv4DcGPigm","AvHkzui","D1Hlve4","CwfOENa","tK1OChy","DcbSAw1PDa","rePTseS","ENjjBw0","y29UBMvJDeu","x1fVu01HBMe","z2Pbz0S","q09otKvdveK","EfjiwuG","tuDPvva","BML0AwfSAxO","zNLPuge","tLfrDxe","zgrjrcWGzgu","yxv0B21HDgK","rNrPuKK","vK9oALq","yxnL","C1PRruC","z3fRvKK","DgfYz2v0","ru1gBMO","yMfJA3vWigu","y29UBMvJDca","yMviyLe","wKrkDLC","yK92q2y","vw9qBLq","tvHcuNO","mNW4FdeWFde","wNjhy1K","rNrVtLK","seDXDxi","ELfeweW","zNPbzu0","re9lt28","CgLUz0XVC3m","wePJqxq","yw1LoIa","Ae9Wzw5fDMu","z1rJvKS","BxnNsuq","B2jQzwn0u3q","y1nXDvq","tLzJDeG","EevcCwy","yxrHlcbKyxq","yLD0y1a","zgvMAw5Luhi","C0H1DLu","wfb5DMm","CIb0DhDjra","uw9Hrfy","DxnLCKLW","vMvvzgC","rKXhy1y","ihrPBwvVDxq","vKLsBMW","FdL8nxW2Fde","CgXVrNO","Dgv4DfbHEwW","AKPmzMW","BKnRAeK","AwXLtMfTzq","vxbOthy","C2HRBei","yuPwtfK","zgvJB2rLzey","CMvUDevUzha","ChHxuLK","CMvTB3zLq2G","l3DZl3yY","x3vYBa","AgLNAa","yKDmqum","BwvKAwf0zwW","teDite4","BMrWB2LUDfq","ywrKrxzLBNq","B3nLza","ywnRDxbfBMq","suvtx0vsuK8","Ce5xBLa","vMvsC2u","u01crKW","qKLsv0G","runnAve","Ec1TC2CTCw8","weXdqxG","ExbL","ywnRtxnNswq","tg9Nsuq","ruHHt0u","mNWWFdn8nhW","x2LUDgvYDMe","rxnWqKu","tuvbA2u","m3W2Fdu","x2LUAxq","x194x21Zz18","rvbst0q","BeHHBMrSzxi","ywDL","t0fUwMi","AwXLx25HBwu","tuvtu0fhrv8","qwjVCNrfCNi","yuj2Exq","CM92AwrLihC","BgLUzq","Dg1XyNm","x3bPBMDmB3m","DeLUDgvYy2u","BM93","D3jPDgu","yNvMzMvYzwq","z2v0qwXSs2u","zK9pCha","x2DLDeLUDgu","qKnfCfa","ywXSB2nvBNm","DgLUzYbZzxi","wwzUzve","yw15Bg4","uKHIDw8","zfLNrKG","ywrKq291BNq","ALjKreO","AgfVCuy","CgvXqKG","reiGzMfPBgu","B2zM","tuHxq24","txHYs2G","zw1PDa","tg9NsurozxC","CgfYC2u","r1jcC2S","CMvJzwL2zwq","AxmGDw5Kzwy","AwTRuLC","s2XHELi","x2nSzwfYvgK","tKDFrvjst1i","AK5Zrfy","z0nRwNK","zNjVBuj5Dgu","y2f0y2G","uNv2txy","r2Dqtwy","s2XPBuC","zM9pDwi","yMrFzgLK","ChjVDg9JB2W","t0rosNG","zfbRtuq","uwT1yMC","B2nRzxrgywK","zfHRwgi","wNbAEfG","zxjYtM8","y29Kzq","AxnbCNjHEq","BxnmtxO","zxj2AwnL","AwDHDg9Yt24","yw5Nzq","y2HnyxHuCMK","vg94Ae8","rLjIy2C","BMXMt2K","CNjVCK1LC3m","BhrPCgXLihq","Aw5PDcbrB1m","BMnLq2XVC2u","x3DHAxq","D0j3wLO","vgfpBgC","C2nlqwS","svzNEve","y291BNq","wevNzKG","ANvNwxC","D2vHB3K","C3rVCMu","CvLPyvu","BNzUEKC","Ahr0Chm6","DMvUDa","svPnruK","ywXPzcb1CMW","yMXVy2TLza","EhzHqKq","EKT6wva","tfjAAwC","Dgv4Dc9Qyxy","t3bLBKv2zw4","DujWrKm","t1HLteG","zNjHBwvuExa","EgDsyNG","u0jHz2m","vuHHAhi","vNvrs2K","svfSr2q","C2vYDMvYvgK","zMLSzw5HBwu","BfPyBxe","zNfPuwm","BxHlD0C","ww5XvLG","s2Hzsxq","C3byquG","BfHUyKy","vMTWAfC","uLjpuG","BMn4reS","zMnlugS","yuPouMy","ww5uC20","re9HBgq","zxzhCK0","rhPeCvq","B25fCNjVCG","CYbHBhjLywq","rMLgyuK","v3b5AKy","x2LZsw5PDa","tgTHyMO","qMfMtvi","zsbHihn0CMK","jMPZy2fSBgi","uKr2D0S","shLuEw8","ywnOzwqSihC","D0TIreC","B3bLCNr5","qxPfz2S","EfrPweW","C3rYAw5N","CgLUz1rPBwu","sNzJvMm","vfPNuvK","u2vYDMLJzvC","q29Kzq","C0jf","ueLKthi","EuTuvKm","vhvvs1q","BMvY","u1fNvfi","z2vjBMzVu3K","A25iuwK","Aw5KzxG","B25Uzwn0Aw4","igzHAwWSig0","x21PBMLoyxy","zcWGDw5RBM8","thHrzM8","zKfwv0C","BeLHtvO","r29NBeu","y29UDgv4Da","ugjjqxC","Dg9oDw1Izxi","sMjhq2u","sgztDMy","EMLnB0q","zgzyt0O","Cg9PBNrbBMq","x19LC01Vzhu","C0nVDw50zxi","r2nxBNG","C3nNEhG","tgPOvM0","vuTNExK","CvzsENa","zw1LBNq","y2HHCKnVzgu","m3WYFdb8mxW","uhv1Bfq","vwToDhm","y1bmA3a","DuntD0C","DxHPyMW","x2LZqNjVD3m","C3bSAwnL","EMv3AxO","C2HPzNq","AKHNwMG","zvPitNa","ChjVDg90Exa","z2v0t3DUuhi","qw5XsLe","DwfoCKG","s1rcruO","qxf0ru4","C0X4Ahe","swjkrNi","tfzju1C","v2TJzfu","x3nLCuLK","rvH2DNG","sxbxuuS","txbmA2C","t2Lwr2G","Aw9Ul2PZB24","z2v0s2v5","v1b1DuS","Cu1Vruy","B25tDg9Wsw0","u1DruMi","AhbLALm","CMjJy1O","wvvpDvq","C3rVCcbPBw0","ExfuwgG","ww9uENu","wer3DMS","rxzLBNq","BejwsLO","Aw1LCYbPBIa","rgrRrKu","mZG5n1fhEu1jCW","x2n1CNnVCK4","tgrAvem","sNnqv2C","t1rlyxy","rvz4z3K","DM1Pu1i","z2vY","CffxAgu","m3W0Fdv8mG","s2zizK8","CKjOvxe","Dev2zw50","yNL0zuXLBMC","ihzHBgLKihm","sLjowei","BM9Uzv9UB24","zMLN","AxnFywnR","DerNvMq","tu9ZDhG","uvvTuMK","DxrMofDYAxq","Cgf5Bg9Hza","vgfN","z01vvuW","CgLUz0LUDgu","AhrMtha","zMjhCe4","yM1irK4","Bev3ueu","EuvQwvi","yxvLveO","uwHzywe","Eg5hy3C","z2v0sxrLBq","ywWGy3vYC28","r1rZs1q","D1fLCMW","whLpBxG","ywzL","B3jRzxjhBg8","s3biqvG","lcbxzwjtB2m","s0TKEMy","BMjPBvG","ALjUA0e","q3DptxO","x3bYB3rVy28","EhvIvu8","BfHrCLu","B2TiAMe","Aw5JBhvKzxm","rMPjreS","BejMtuq","thfXqNG","CKPYB0e","Cxvqv3C","yxbWBgLJyxq","mtiWotu4nJvZuNzovha","zxjFDhrS","Bwrqv0C","zNjVBunOyxi","AwXK","zxjFCw9Zx2e","tNr0wKm","zu5WC2W","ANrdu3G","wujxwfa","svzmuMy","Cgfzsxu","Cg95q2y","tvb3que","tuvswNm","vhbuCeG","AMHXq0K","Au1yBLO","swPOuhC","sg9gEhm","r3fQqxi","EvLgq28","DNrxyxq","z1vuvLC","sMnvwK4","zMXeqKi","qLLQEwq","txDfDMG","yxLWCxm","DfPUq04","mJi5mZiXndbpAvfLqwW","yxnJCMLWDa","uez5tLi","CLnSANi","Cg93","Duz4Efe","yxv0BW","mZe2mZa5nKjYB2PRuW","rfnQrK4","yMLUyxj5vhK","CejcwwO","BgLTAxq","BMfmseu","qufsrgi","CgjICdi","Eu1Yq0G","AxnrB1nnzxm","vMn2Cwu","uKHurwy","twjQDKy","vwHMDNe","su5tvefova","tKfbse4","CNnVCKzPBgu","AMLizwu","Dhneue0","C1bgzKS","r0XlteK","CLnpDha","swDzD2u","yw5Hz2vY","C0j2r0S","DgvZDa","t3vXDeG","wvf2u0K","zw5HyMXLvhi","sfDRD3u","CgncExq","D3nZoI8V","x29UrxjYB3i","ihzHBgLKigq","DxrVuMvJB24","B3PxBKe","Aw47y2HHCNm","v3Hvrgu","x3bHDgHlzxK","qNjmqvm","x2HHBMrSzu8","CMjWuLG","DeDMEgu","wuzhD3q","vw51qxm","zNjVBu51Bwi","AgvKtwf4uMu","wgzPqMW","C3rYAw5NAwy","v0fQExe","DLzkruC","B25VCgvU","CxbyC1a","zw50","CNPQvfG","DhjPBq","BMXMthu","wwfbqw0","Cg9PBNrdB24","Agnlz1e","zNfwELG","CgvYC2LZDgu","B2XKvMvYC2K","AevYCM9Yrxy","A1n0yxr1C0m","Bg1vveq","sK1xwve","BwfUDwfSihi","C3vJy2vZCW","q3vZDg9Tq2W","rKLmrv9ot1q","zuLcrLe","x2HHBMrSzvi","qxnZyKm","C2nYAxb0","A1b3y2G","DufptvG","ywnRpwzYB24","qKHuA0K","rxn0Ce0","s2XpqMS","tvDJv3K","x0rctMfTzq","vwjpEem","wg5QDfq","wxf4uwS","zwn0","y3jLyxrLuMu","zKDyq0G","yujSvey","ugLSEei","Dw50","thzXDLu","wNvuBum","DfbvseW","DMDNBwK","t0TbvvG","y3jLyxrLt3a","Dg9mB3DLCKm","DKDdrNu","igzPzwXKoIa","EwLHvgi","zMX1C2HfEha","s2TfEe4","x3DZ","Bg9IywXty28","y2XVC2uSihC","D3m6lY8","D3ffqxa","CMvHzhLtDge","rMnnrfa","vhPgtLa","rNrmtwG","D0jguhm","aaaaaaaaaaa","Avz5AwW","zw5KCg9PBNq","B0POtvy","CeHzEei","qvfKBMu","B0jeAg0","C1DYBMe","EuXHs2G","AezrteC","D3bqENC","B25pCgvU","x2LUAxrqCM8","y2nNwhq","x2XPC3rLBMu","rLjptLrjrvi","q2fRufe","y3vYC29Yx24","rNPIDLq","CfLRr1i","CNLNse8","y0Tvt1u","zw5fDMvUDa","ANDJywu","qvj0zei","vhjRreC","q09oveLovuu","whzyvMW","sMj5Chi","svHLwxm","CKfXyKO","uenSqLG","tgLZDgvUzxi","DgLTzw91Da","ign1CNnVCIa","tvjYuhO","AgHKEuG","zgfouxG","C2vUza","yw5ZzM9YBvq","C2v0u3rVCMe","rxjYB3jdB2q","DeLK","r3bcAM0","ywjIvgS","sNrNA0O","x25HDMLNyxq","wMLxzue","BgXVu2C","tM1ty3m","t2jSwuu","CKviCvu","v3bLC20","yw1L","Dg9tDhjPBMC","reX3Ehm","Exr5B2i","rejOrfq","Axnby2TdBgu","uNjICK4","zxH0ugf5Bg8","x3jLywr5q2W","yxKSihrYEsa","BuvgBMW","C2v0","vuTwtwu","wKj2CLy","yKfczw4","mxWZFdj8nhW","yxKSig5LDhC","yxHbCNK","wvzSzhe","A2v5CW","A2vlDMW","C3vtD0m","yw1Lu3bHy2u","D3ftuLi","zw50tgLZDgu","C2vUDa","vNPAs0O","BePbr2u","A3PNrgm","ue9ozNi","x3jLBw92zvC","CMvHzg9UBhK","B25LCNjVCG","CgLUz19VBMm","quXm","BM5KBuO","y3rfAMi","t0T0AhO","vw9IEeS","B1nQBNy","wvDrDgS","ywDLrxzLBNq","y29UBMvJDfm","zLPtwuG","B2vyrNe","D3bKvKO","zxj1ELC","t3LzBuW","BwvZC2fNzq","y3vYCMvUDeK","ChjVy2vZCW","q2TfCK0","q2r5BMy","C3HAEK0","wMzrB0u","Dw5KzwzPBMu","Dgv4Dc9WBge","x3nVy2TLDa","mhW1Fdf8nhW","zw50zwqGDhK","vu9Pv1a","vgPmrum","DK9Tre0","EgLiu0S","B2fK","q3vhDxG","s3fHCxu","zfr6C1C","ruX4vuK","mZz1vfnishG","sxrVzM0","zcbLCNjVCI4","tLL1Axq","yxGGCMv0CMK","y29UC3rYDwm","yNL0zu9MzNm","x3jLy29UBMu","yvrUru4","yKTTEeS","twnuzw0","nhWYFdf8m3W","y0jqwg0","CYbWyxjHBxm","yNLL","DMfSDwvZ","C2v0sxrLBq","x29Uq2XVC2u","BM5Ly3q","AuvPCNm","yM9KEq","ChfcD3O","u2fkvxi","y0fjuxe","zv9ZDwnJzxm","qKPXAKS","wxzur0m","txfTr2W","txffzLu","C3jtyMi","mxW1Fdn8mhW","AgfZ","y3jLyxrLrwW","tfHcy2e","u1b5vvK","x2vUzhbVAw4","B2Ddvgu","BNrLCG","ufDPAKi","yLHerM0","ANPvuhK","tufyx1jfvfi","wxn3ruG","zxjFBxnNAwq","yNL0zxm","x3fVC0rc","z3rysvy","Bhm6ia","BKnlz3a","x29WDgLVBNm","uLjLEue","qu1item","zgLZywjSzue","zxnwuuC","AgDguuG","BMP2C04","CMfNzvn5BMm","zfjsEKG","zgv2AwnLx2K","zxHWB3j0CW","tKTQwuO","C3rLBMvYCW","wNL3C0W","u2nVqNu","ELLUB08","z1nwEu8","q0Xpu0ve","y1bjr0G","wun5BNm","A0ztz20","BgvY"];return ra=function(){return t},ra()}var Xo;Object[N(1228)+N(1416)](be,N(1450)+"le",{value:!0})});import{existsSync as n1,openSync as r1}from"node:fs";import{mkdir as i1}from"node:fs/promises";import{dirname as s1}from"node:path";import{fileURLToPath as o1}from"node:url";function c1(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Yd(t=Y()){return n1(t.libEntry)?t.libEntry:o1(new URL("../index.ts",import.meta.url))}async function ip(t={}){let e=t.paths??Y(),r=t.entryOverride??Yd(e),i=c1(e,process.env.COZE_BRIDGE_LOG_MODE);await i1(s1(i),{recursive:!0});let o=r1(i,"a"),d=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=it(process.execPath,d,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[as]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return a1.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var a1,as,ca=nt(()=>{"use strict";Jt();ie();Pe();a1=j("spawn-daemon"),as="COZE_BRIDGE_DAEMON"});import{spawn as i2}from"node:child_process";import{mkdir as s2,unlink as o2,writeFile as a2}from"node:fs/promises";import{dirname as c2,join as d2}from"node:path";function Qr(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function l2(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Qr(r)}</key>
21
- <string>${Qr(i)}</string>`).join(`
20
+ `+n)}function Qn(t,e,n,i,o,c){if(t.listenerCount("wsClientError")){let l=new Error(o);Error.captureStackTrace(l,Qn),t.emit("wsClientError",l,n,e)}else ts(n,i,o,c)}});var Lx=ae(Me=>{"use strict";var L=J;(function(t,e){let n=J,i=t();for(;;)try{if(parseInt(n(953))/1*(parseInt(n(1144))/2)+-parseInt(n(1269))/3+parseInt(n(590))/4*(parseInt(n(1139))/5)+parseInt(n(1219))/6+parseInt(n(821))/7*(parseInt(n(730))/8)+-parseInt(n(1130))/9+-parseInt(n(639))/10*(parseInt(n(561))/11)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})($o,574281);var Vv=Object[L(1140)+L(562)],Jv=Object[L(823)+"opertyNa"+L(884)],Cx=(t,e)=>function(){return t&&(e=(0,t[{TEKVw:function(o,c){return o(c)}}.TEKVw(Jv,t)[0]])(t=0)),e},Zv=(t,e)=>{let n={BwMuK:function(o,c,l,u){return o(c,l,u)}};for(var i in e)n.BwMuK(Vv,t,i,{get:e[i],enumerable:!0})};function Yv(){return Ix||(Ix=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function J(t,e){t=t-111;let n=$o(),i=n[t];if(J.MGaXCi===void 0){var o=function(h){let x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",m="",_="";for(let S=0,y,v,I=0;v=h.charAt(I++);~v&&(y=S%4?y*64+v:v,S++%4)?m+=String.fromCharCode(255&y>>(-2*S&6)):0)v=x.indexOf(v);for(let S=0,y=m.length;S<y;S++)_+="%"+("00"+m.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(_)};J.TExbxW=o,J.pvjHzz={},J.MGaXCi=!0}let c=n[0],l=t+c,u=J.pvjHzz[l];return u?i=u:(i=J.TExbxW(i),J.pvjHzz[l]=i),i}function Xv(){let t=L;return Ax||(Ax=[IDBCursor[t(132)+"e"][t(851)],IDBCursor[t(132)+"e"].continue,IDBCursor[t(132)+"e"]["continue"+t(802)+"ey"]])}function Qv(t){let e=L,n={cViGL:e(203),GavvS:e(759),TCBhP:e(417),FtlBi:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let l=e,u={IuCJT:n[l(818)],tDSBT:n[l(537)],sLcIP:function(_,S){return _(S)},WSAdq:function(_){return _()}},h=()=>{let _=l;t[_(992)+_(469)+_(1588)](u[_(888)],x),t[_(992)+_(469)+_(1588)](u.tDSBT,m)},x=()=>{let _=l;u.sLcIP(o,Bt(t.result)),u[_(1121)](h)},m=()=>{let _=l;if(n[_(448)]!=="DYUIb")c(t[_(417)]),h();else return new _0x920dc6(_0x2d72d7,_0x2d0b11,_0x33ddad)};t[l(796)+l(1579)](n[l(818)],x),t[l(796)+l(1579)](n[l(537)],m)});return i[e(1534)](o=>{let c=e;n[c(1072)](o,IDBCursor)&&Ll[c(552)](o,t)}).catch(()=>{}),Jo[e(552)](i,t),i}function $o(){let t=["tNjOr2C","qxrSB3m","Bw9xCwK","z1HWzLy","Ehj6AxO","BMfTzq","yMLUyxj5","BLfmBeq","BxrYBwC","AhjpC00","CgfYC2u","CNHnuui","vNPUBfO","yw5ZzM9YBvq","C2ruqvC","x2rLyNvN","yxbWBhK","mtq0ntmXnM1YqNvhBG","sfbbzfq","DvnZDu0","rwHNAfu","Aw9Ul2PZB24","EvLit2q","C2v0u3rVCMe","uKvVEKu","s09WuxK","zsbHihn0CMK","zxH0zw5ZAw8","AwrNt1m","C2z2z3e","vxfVwui","zKnQv3m","zKjJww8","ueT5EKu","rufvAe8","t3b1tuK","EfLKrMe","Bg9Nsurhzw4","rePrvLC","twLRrvq","B25nzxnZywC","zfnvD3e","D2LSBfjLy28","wgrKswC","ywnOzwqSihC","EfLirMm","CNzHBa","BgLTAxq","zKHOt28","ywPkCeC","BNvTyMvY","t0f0uM0","qvL4DKi","B25Uzwn0Aw4","y2vZC0HHBMq","y3vYC29Yx24","r1zbD1C","tg9TsKO","x3nLCuLK","r0fiBvO","sM1dEvO","sLrxzfm","t1fvA1G","Aw50zwDLCIa","su5tvefova","rgXfq1C","rwPtyuK","zufJAW","su1tseG","CYbPBNn0yw4","DujJweu","DMvUDa","Bujgz1m","A1LPCwq","uNLhsKO","q0L3EfG","r0jdu3G","yKjwEwG","uun1wKC","ywnOzwq","x0vysvnu","BvDMAhO","zw50","x21LC3nHz2u","s1fVsge","wfLhuge","Bg1SvNm","Bwf0ruq","yxv0BW","yMvtAgi","Eu1tvuC","Ehz2u2u","qLLyy0O","DxrMofDYAxq","D2ngB1y","Dg9tDhjPBMC","uMvHzcbWyxm","rMzzCfK","mNW4FdeW","BgHKDxq","y3Pkr2q","yKjqCfq","z1bnEMe","sfLpvMq","s2jIvfC","z2v0u3rVCMe","v2vIu29JA2u","suDHuvG","reiGzMfPBgu","tK52qvG","tKvwy0e","BeXdr3m","BhbSuKK","ihrPBwvZ","zMvY","BKjZELe","BxrKsgK","BNfpteK","zxzzC2K","Cg9W","DxvfCey","ihzHBgLKihm","Ahzgy0u","x2nVBM5Ly3q","vuXXtwy","Eg1sBK0","Cffqvu4","AxnAzxjV","vfvRtKK","wLHluLi","zxmGCMvHy2G","x2n1CNnVCK4","A0zVtfO","zxf1ywXZ","zvjKru4","EwzssMu","uvzsu0O","x3vYBa","zv9ZDwnJzxm","ihrPBwvVDxq","EMnvB1a","CxDiB0K","BerxCei","y29SBM8","rgjnwfO","C2vUzf9Hy2S","vw5Oyw5KBgu","C2XPy2u","Dev2zw50","yw1Lu3bHy2u","z1fHs1C","DNj6t2K","yuTftM4","x3bYzwzPEa","tuv6whO","C2v0sxrLBq","Dw5RBM93BIa","BLfVvfi","rxfPB3y","AK5Tuvi","sKzdA08","vLz6u1a","Aw5JBhvKzxm","CMvKDwnL","y29TCgXLDgu","tMP5s1q","wu55vwm","vM13wxa","AM9PBG","txbYsNC","EhvgtgS","q0rfDvi","zMLSzw5HBwu","zeP1AMW","x2TLEvbHDgG","zxjFAxnFywm","EKLcsKm","ChjVDg9JB2W","BwLUAvbYB2C","rgrPuKq","BMDuAw1LCG","t0vNCKW","ww9jt2q","wwXzse4","q29UzMLN","x3bPBMC","zNzdyM4","uhzhyvy","DKTnwwW","BNruCMLLC0m","svfLrxO","x29Ut3bLBG","tKD4vhu","zefJC00","y3r4","rfHuELK","D2fyyxC","DefWD1y","CM92AwrLigi","yxGGCMv0CMK","zMzLCG","CM10sNK","vhrbBfO","AxnbCNjHEq","rNfzwhC","CxPHDM0","x3jLBw92zvC","x21PBMLoyxy","zNjVBunOyxi","y0T0veu","y2DgExC","z2nssxi","t3b5s1m","vgLTzw91Da","m3WWFdr8mxW","CNHqAhm","ANjcsNC","yxnJCMLWDa","y3vYC29Yx2y","yKHNr3C","zhrpq2O","qu9zBfG","s3rLzhG","zurkDK0","y2f0y2G","B25szwnLAxy","D2jqEK4","qvnpuxO","uxbRtgu","tNHTBfC","BM5Ly3q","ufj5Buq","vffewfy","BxzWBhO","Dhv2veG","EvjLy29UBMu","y3ruAw1LB3u","mNW1","weHdrM4","DMvYC2LVBMm","v3Ppzey","D3jPDgu","CMvHzhDYAxq","vfzWuxG","B25fCNjVCG","AwXK","uxvLDwu","BuLvteO","vfj4zu4","zwvvs0W","AgvHzgvY","y29UBMvJDeu","s0H6EKi","whfvuvu","CgLUz0LUDgu","B25VCgvU","AxvUC3C","BgLZDgvUtMu","AgfUz2u","sxfuDu0","Dg9cExrLC0W","zwnVBM5Ly3q","qLfWCue","CfDwvui","AgvKtwf4uMu","runAsNy","sfjJAMe","DKzUqMq","A1vPAgm","Dvjwyw4","yKneCwi","B01hDue","AefJA01LC3m","x2LUAxq","A0HgCLm","AM9Rsxy","D1fSrM8","CKvtBfC","tMH6s0q","qwTcwva","wvjzwxq","s1PbwuG","DgHLBG","zwrPyxrLBhK","re55u2S","Dfz6yKK","EePdC0e","D0DLvKS","mxW1","y09VBfi","u2vYDMLJzvC","CMXkB0m","BhDnBhK","BLvSsue","t3bLBKv2zw4","wK1mqMS","zw5JB2rLrNi","CgXLyxnLiha","yw5qqxu","D3bKD3e","B2fK","tMfTzq","EePrAK4","r3zYEfG","B25LCNjVCG","vNHjCvm","y3znBMy","BgLUzw5V","DM1Hzu8","zgvS","BgLKAvC","s3DVzKG","ueDcweW","zxq9DxrMltG","t2jQzwn0","zg9Uzq","t1byELi","DxDREKu","wK5eA0S","v21tA0m","x2HHBMrSzvi","yM9L","EfnRDMq","u0n4q28","u3rYyxrLz3K","zNvUy3rPB24","y2Duwum","tgLZDgvUzxi","Cg93","y29UBMvJDgK","y2XVC2uSihC","z3jksw0","y3ngCeq","zw5NDgG","v1rSCe4","B0vKruC","BMvY","CM92AwrLige","BM9Uzv9UB24","zu9wwhm","rNDAseu","zLfKEKW","AxjLza","ywjVCNq","qKvfwMG","vvr0Beu","Cg9PBNrdB24","qLLyBei","DxPnB28","EgXqC3m","DvjuDgu","CLztr1a","uxPMr0G","BgvUz3rO","ANnnrM4","BvHhD04","A1v3v3u","A2v5CW","B2jQzwn0u3q","tLbQAu0","BwvY","qunxvuy","B2nRzxrgywK","CfryCuS","wwvHB2G","ywrUvLa","zfD1wKO","vgXcyNK","txjgBMS","zwn0","x2rLC3rYB3K","AxnrB1nnzxm","tKPpywm","u0PLz1G","nxW5Fdf8mhW","yMLUyxj5vhK","tg9Nsuq","ihrYEsbYzwm","zw5KCg9PBNq","x3bHDgHlzxK","y09QzLC","ChjVDg90Exa","sgnqqxu","rxz4yu0","BNL6r0q","CLzxy0m","C3vIC3rYAw4","Efzczem","vhnZvKG","D24GCMvHC28","B3jpBMXPBMu","q3fqzLK","BLbkDNa","z1vfwK8","wfnoBMW","zNHSqLi","t05XzxG","vMvhz2S","vuXNEgm","vMP2yw0","uKHLu2S","CgfNzxnOB3C","Dxrjza","zMzmAw5L","zuvpzhK","Eu95sLa","CevRze4","wNL1r20","uhDms1e","x29UvgLTzw8","A053B1C","DwPQugq","yNvMzMvY","ExznugG","x2rItMfTzq","zxnVsNu","sxjIzxq","tKDFrvjst1i","CxryqMy","Cgu6ia","zMXVB3i","t3b1twu","vgHzy2i","A0vAsxi","vezmu0W","uLjpuG","tufyx1jfvfi","CMfTzq","rLLSALm","CMvUDevUzha","x2HHBMrSzva","CMLLC0nVDw4","mdaWma","quj2Bui","ignVzgu6ia","Dg1rBgC","mxWZFdb8mNW","zMLN","CLzHBhvLCW","Bwv0Ag9K","z2X5uvi","AMvJDfn0B3i","rKLmrv9ot1q","qvfqDgC","vxzqu0C","x2nYzwf0zvm","CMfTugfYyw0","ywXSq3vYC28","CunVv3a","EhDkvKK","qw9tvwu","x2nSzwfYvgK","q2PADvK","tw1kBhe","z3rJqLa","sw9PtMe","CvHws2e","x2LZtM9Kzq","r25kyK8","z2vjBMzVu3K","y2HHCKnVzgu","C3vIyxjYyxK","nhWYFdn8mhW","CwX2D20","vhPuu0q","zxjFDhrS","tgLtsKy","vxDbCgu","txfMwwq","CeDuq2e","A3DnwLC","zgnkBNO","BNrLCG","yw51Ce1LC3m","EMHUt1y","ENvMtwO","Ae9Wzw5fDMu","CgrfwuC","zwzUvw0","AxHvsKO","B2zMBgLUzq","uwLMCMC","AMTMBLa","EMvMvuC","tLPwwNC","DgPqAfq","yMrFzgLK","uxzqBwu","C2vUDa","BMvJDa","yNL0zuXLBMC","y09Wzw4","DeLUDgvYy2u","sMfpAhy","yxjYyxLIDwy","AxnFywnR","tw1qDNu","wwDrwgW","C3rLBMvYCW","ywTTBwm","wgvsrgS","q3fUBeq","B2P0wK0","zMLUza","sMPJB2O","x2nSzwfYugK","Dvbdz0y","B3vUDa","Dhr3Awq","yu5Az0S","wvDkvwK","C2v0zgi","BxP5Afe","sxrJC1m","x2zVCM1HDeu","vhvhD0m","x3nLBMrby2S","CMvHzhLtDge","tMTptwq","vM5dAeC","Dg9cExrLC0i","rvPjte8","uNbdAKO","y01lBeu","zNjVBujPDhm","y29UDgv4Da","Bvv3Exy","ihn1y2nLC3m","q29Tt3K","rxzLBNq","rxjYB3jdB2q","EKjVsM4","Eu1Tsey","Dw5KzwzPBMu","whj4s3K","CxHXDhq","BwvZC2fNztO","BLviBK8","CgfNzwHPzgu","x2n1CNnVCK0","CNzHBfzHBhu","vLbQwwm","sMHJt1e","v0noCM0","zwnxDMi","zM1YwNG","EgzhyNu","BMCGB3iGyw4","BwTAC0S","DeLyrfG","u2TPCcbWyxm","z2v0sxrLBq","CgvhtNG","ywWGy3vYC28","Bg93","rKDqzMq","B25tDgfYDfi","BKz2BhO","rwLVELy","zv90Aw1LB3u","A29kwwW","y3vYC29Y","zw1LBNq","BNz5t1i","D2fZq2XLyw4","qxPyrgG","Ahr0Ca","D0nTBuW","y29UC3rYDwm","BfbjuvC","x2vUzhbVAw4","C0jf","BKXJCMy","v0zLvu4","rvjst1i","uu5bEKi","vgrerNK","igXHCMDLCIa","wev2Cuq","sgPHyva","AezPBhu","CNnVCKzPBgu","ywXty29Wzq","yKPmChe","yNLL","BuzdrMW","rMXKq3u","rLHwDK0","B1Hdrei","BvzNAuC","Dg9mB3DLCKm","B3nLza","ug9hq3C","EKnNA3G","y1jcD1y","z2v0q3vYCMu","q1v4v0e","ChH1svq","DMvY","DgLTzw91DcW","ue5bAfq","tMnurfe","qwjVCNrfCNi","DhDVCMTdAge","veffvLa","uML0Cw0","C2v0q3vYC28","twfkweS","uNzPsg8","DLz6rgK","DhjPBq","Eu5XveC","ENHXsu4","rvvxALa","rKvkq0q","qKXhzxG","s3nWrMK","q3vZDg9Trxi","zcWGDw5RBM8","zgXABha","x2HHBMrSzu8","AgvHzgvYCW","zw5fDMvUDa","vw5PBxbSzw0","uKTPq0S","C3bSAxq","CKHRDMS","vKjKyvy","CMfNzvn5BMm","y2HnyxHdB3u","vNPvzgq","zuPbz2e","AeHKAuK","Bg9IywXty28","A1PACg4","sejNwKO","zNjluMW","EfvVrhu","veDHs28","yNL0zxm","quz0qMC","Ae1LC3nHz2u","ruDdEKq","AhrqBuq","q1zhqKy","B2nRzxq","yxv0B21HDgK","vKHIAge","Ef9MCM9UDgK","x194x21Zz18","zNDZxZeUmc4","FdD8nNW4","zxjYtxnN","yw5Nzq","zgfite0","rLLgzgG","v1HRu2y","l3DZl3yY","CgLUz19VBMm","vurwCgK","yNvMzMvYzwq","rgvKAwnHDgu","ihrVihjLDhi","txLiB24","CM92AwrLihy","wxjZDfG","zxjYB3i","uLz1r2q","t1bftG","y3jLyxrLtwu","zfHrr2S","zevMwhG","zMn2zwu","sujjwwC","x3bPBMDqB24","B3bLBG","CKTTseG","Aw5Lza","ysbTDxn0igi","uKXUrLq","zgvJB2rLzey","zufWsMu","q2Levfq","y2HnyxHuCMK","q05nu1u","ywDLu2HVDW","BMrLEa","C3rVCMu","C3rVCcbPBw0","BwvZC2fNzv8","BIWGAg9ZDg4","x29UugfNzu4","zMLSDgvY","Eufwugy","CMvHzfvjBNq","CMv0CNLdB3u","sfnyuva","y1zPr0W","yMfSrxzLBNq","Cgf5Bg9Hza","v2nkAgy","tKfjtNq","yuTHBKy","C0jTv2u","Bej5ALi","zxvQCwO","AxmGDw5Kzwy","ihbYB3rVy28","tuPQEeG","EgDVDLa","D3P1uxG","t2vfthy","C3rYAw5N","B25tDg9Wsw0","ChjVy2vZCW","x3jLy29UBMu","suv6veu","ywX3yxLZ","zw50tgLZDgu","z2vtEw5J","ugn5ChC","B2XKvMvYC2K","AwXLx25HBwu","uvPuweC","BMLsDuu","r1r1wfG","vMvlCeW","CeDbBLO","CNnVCL92ywW","wxPssNO","s0DsDK4","yuPfz0C","ig1LC3nHz2u","r2vZsfC","DKzHCM8","Ec1TC2CTCw8","zLH1EKS","BwvKAwf0zwW","CeT6D0e","x3bPBMDmB3m","EeDyu3O","zxjFCw9Z","vwPJEKW","ywDL","Dg9iyxnO","sMHUqNy","zw5JB2rPBMC","yxnZAwDU","zvvYBa","BNzkBhq","DcbSAw1PDa","BxnNsuq","EwzvquK","reXvtfm","vvnmEu4","yxbWBgLJyxq","r2rXsgq","vM1mEhO","Cw9Zx18","y3jLyxrLt2i","z1rPBwvVDxq","uuj0q3i","wvjVwxa","tLPkr1u","BwvZC2fNzq","tuH5sgG","zK9pq2u","B2Tyt2G","AwDHDg9Yt24","CMvXDwLYzwq","wLDUD1C","CKrcqK4","DeTwBvi","CMvZzxrdB3u","Dxf2v1C","B2fbAeS","BMCGDxjSoIa","DxjS","uunLyxq","tuvtu0fhrv8","Bw1Rtvy","sKDQy1C","uM9qCeW","twLZC2LUzYa","su1csei","DLzzuhO","vencAfa","r0rwv1O","D0jIA0O","zxHWB3j0CW","ru1stLm","C2vYDMvYvgK","sKL0s1u","C29Tzq","uw1mzfy","Bwu6ia","swTevw4","t3PStLa","Cwn0EvC","v0TKqwe","suvtx0vsuK8","C2v0","EKDHyxq","q3PZB0C","refbsuG","Agnzzhu","sLHjDKK","ywzL","B3bLBIa","zNvgtLG","oteZDvvjCfHp","B3bLCNr5","lcbTyxGGCMu","DunKCu4","CMvTB3zLq2G","DgnjCM0","yurmA3u","u29cvMu","rfnIyLq","BhLRsNm","re56EeK","C2HmAhe","B2zM","rxbqvfa","ywrK","uNz4yue","y3PMDgK","x2XPC3rLBMu","zw50zwqGDhK","x2LZsw5PDa","q2HOBxu","zNbxr2K","Dhvbs0q","rLf1v1y","svHUv1i","A0j0u2y","B2zMC2v0","Aw5KzxGGB3u","Bwf4tg9ZC0m","mZKYmtjQDxDewxi","y1fOv0K","BMv3vMvYC2K","q0Xpu0LorW","r1nUsuO","ruzzteO","CIb0DhDjra","zwDzAMm","AwjKzfq","uu5rrMO","rM9fAvm","x29UrxjYB3i","C2vUza","Aw5KzxHpzG","y29Uy2f0","sgPmrM8","u3zdsuW","u2vXsuq","Bhv3BLi","C0XPC3rLBMu","y2XLyxjtDg8","CgHMAe8","sxrMreu","twz6DNe","DxzHCva","sgzTqum","B05dsK8","uMfAAee","rMX3vKm","rLDt","rNPwwei","C29YDa","zgvIDwC","C0nVDw50zxi","x3nVy2TLDa","yNL0zu9MzNm","zLv1zeG","vwvjCMq","q2ThD1a","Aw1LCYbPBIa","Dg9cExrLCW","CgvYC2LZDgu","DMDlyxK","uhj5BuS","quXm","mdaWmdaWmda","wLHQwNm","Cw9qB1a","yxrHlcbKyxq","mtiZntKWBuDiDvPP","ru1wAxC","wenTwfC","BNHUv3u","ENLwBg0","Ee1zrLa","ihzHBgLKigq","zermExq","D2rzyNa","ChrVCG","Dgv4DfbHEwW","A1DnuMO","x2rYB3bhBg8","CMvQzwn0","mxWWFdeWFdm","x1fVu01HBMe","zgvSzxrL","y3jLyxrLt3a","x2DLDeLUDgu","zKfuq24","sgPTvwG","r0PyrhC","C3nHz2vfDMu","v2r0ALi","EgPKqvi","zw91wuq","sMf6BKi","C2fNzq","yvDABfi","z2vY","zMvhB2i","y3vYCMvUDeu","svDMvxG","vuveAeq","rgDoshO","q3jqu2G","vxbKyxrLq28","BuPZCLG","qM1YBvm","CwHYCLK","ywrKq291BNq","rxn1s00","wwzrtgi","y2XLyxi","B3nLrxzLBNq","Aw9U","twvZC2fNzuu","y2HLy2TdDxi","D0fxyxq","BMv4DcGPigm","B3jL","BM93","txn3wuy","wwXcuLu","shfiy08","vfH4yxC","y2XVC2u","AxjTywu","y3jLyxrLq2W","zNDrwvO","Dujywfe","B25dBg9Zzq","sgTuEuO","DgvmB2Djre4","zvzfsMu","uwTRy2u","rfrgAwS","rvrJvgu","yMz1t3K","reflENq","CxrYrNq","yNHfz1e","uuPOuwy","rgLduxu","zM9Yy2u","BNrMwxO","yxrLq291BNq","z1LfweK","B3bLBKrc","C3rYAw5NAwy","BwDNAxO","EM5TCKu","y29Kzq","AgfZ","D1rRAeq","sePgB3u","CNnVCL9Uyw0","x3DZ","id4G","B1LkuvC","EwDLEKy","mtzKswLREum","x2jPBMfYEvq","DeLK","x29UtwvZC2e","A2rcDM0","DxbKyxrLq3u","tff3u0O","Ae9xvfe","ywXPzcb1CMW","CgLUz09Uy2u","y0vHyxa","D2r3ve8","oxW1Fdj8nhW","yw5Hz2vY","Chv0","AhDss3O","zxjHDg9Y","t25hthu","y291BNq","DMfS","Dvb2vxO","t0jJwvK","t3zUD3u","Aw47y2HHCNm","A2v5","CeDOqMe","q0TStKG","Dg9Y","yMnPwM8","C3vJy2vZCW","u3zAvfu","D3m6lY8","AwrI","zNPszxm","Auj3rwq","A09ptwu","uMvJB25Uzwm","Bwf4twvZC2e","x2DLBMvYyxq","uu5gDgi","BhH1rMG","quTHs3i","CMvJB25Uzwm","suHivK4","BKXPBMu","BwLZzq","C2vYDMLJzq","sLnptLa","BwDVC24","AvHqBeW","zNjVBuj5Dgu","tMHUq1a","rNPqA3e","BMrWB2LUDfq","qxjlsgS","u2rmAuq","mxWYFdD8ohW","x3jLywr5q2W","C0Xf","AK5hz3O","Bg9NsurozxC","t1bftL9fuLi","ExLhu1i","AevYCM9Yrxy","z29PBMCGyxC","igzHAwWSig0","ywrKrxzLBNq","zvHRuNy","zgf0yq","uw1VDgO","sgj3y3u","EhjIuwm","uhjPBwfYEuS","BwfW","zw5XDwv1zq","y2HLy2Tszwe","EuvJu1y","ywnRtxnNswq","x2LZv29YA2u","y3vZDg9Tshq","AgLNAa","ExbL","zxj2AwnL","yLHosNa","zgf4vg4","yK1rBfy","zhrYDuS","wujrs2W","r2f2DLm","tuj6sKe","tNv5r1O","mJqZmti0n3vIqxnpvq","C3bdvMS","z2v0t3DUuhi","ywLOEhO","zgLZCgf0y2G","q0HMwMS","uwLUzxm","BwfUDwfSihi","EgvhB08","AxnmB25N","Cw9Z","B3jxy1m","y2flwg8","rNjVBNrPzxi","q09otKvdveK","zuHWDhG","CLbnqvO","tvPkDNe","B2zcwM8","Dgv4Dc9WBge","rKX5r1K","CvnZvhK","yMzmz1u","q0LlBNa","yMXVy2TLza","uKzKyuy","rLjptLrjrvi","yufuB2u","Dvf3zLu","AxnszwfKEq","ywr2yw5Jzq","q2HjBM8","y1nYqKW","D2fTEKm","sgvQwLa","rxvcqw0","ywXS","A3rbDei","x2fKzfDZtgK","B25SAw5L","qu54ugK","CM92AwrLihC","Au12vxi","zwDnsgu","vhbHDgG","uLbstMG","sMrgB1a","z2v0qwXSs2u","ELbPA0i","r2j2CK0","t254BMW","tKfusvzfx0u","DMLJzuLeig8","C3jJ","tNvHBvq","AezhvK8","z0LQzgy","zKfsswe","EvrJuhu","DhjPzxm","Cgf5Bg9Hzfq","Dg9oDw1Izxi","DgXyEuC","BwvZ","x19LC01Vzhu","Cxb6teS","BffTDK0","sxvdsLq","DMfSDwu","ihjLy29UBMu","s29xBNe","yM9KEq","uhfmEwe","DhjPzxmGCMu","t3DrrxC","BxbgyKu","wxHSAxe","BvbizfC","D3nUt2C","AenSB3nLrxy","BMzMz0q","r1PtuK8","Dg9HyuW","D01zzMK","mNWZFdb8nhW","mtb8mxW1Fde","vgzgvNi","De1HBMfNzxi","ywXSB2nvBNm","CMvLDvO","B1L5v2e","qw1VDw50","vhz3ru4","t0z0wMe","zNjHBwvuExa","D2HvDgS","x2LZtwLUAvq","z2v0qwXS","qwfNA0q","u01nre8","DhjHBNnHy3q","yNvWCxG","twHzALC","C3rHCNq","Ewrgt0q","EwzRBw0","AwXLtMfTzq","zMX1C2HfEha","DMHQBeO","BxjODhy","CMTLCKDSB2i","Dw5ZAwDUzwq","EgL3zxC","z2v0q3vYC28","sgjQBum","tg9JAW","ign1CNnVCIa","D3jPDgvvAw4","B2nRzxrtDwm","AKz5rMG","zNn5z2K","Ce9Tzva","qvn1DM0","y3vYCMvUDeK","Chn4uMG","sMnwtfy","tg9NsurozxC","B3jLtMfTzxm","zw1PDa","yNHPCg8","uMPXDgu","v3ziB2q","ndK5nNfczKn3yW","EfnOs0G","rxPmANu","Aw5KzxG","tez5uue","B0zjBw8","D2DrCKu","A1n0yxr1C0m","AgD1uNu","ywnRx2nVzgu","ruvcwvK","CwToruW","BeTcCuG","uMPvuM0","t3jtAhi","zgL6zg0","ChvZAa","EenkD0u","ywnRx2LK","CgLUz0XVC3m","CxHlAvi","yxbWzw5Kq2G","teDTt0O","DxbUA08","z1LzCgq","z0XmCwi","lcbxzwjtB2m","x3bYB3rVy28","s2jOshe","qLvktLC","x29Uq2XVC2u","uMrqDhu","EK9LuvG","CgjICdi","x25HDMLNyxq","whLtvw4","BNrhEwW","wLvstwq","sgXkAxm","CMvTB3zLrxy","DgvZDa","DgfYz2v0","zcWG","B25TzxnZywC","qvrhzvy","x3DZsw5ZDge","CMfUzg9T","weDyueS","ueTfAwC","x2LUAxrqCM8","wxHRvem","y29UBMvJDca","EevoEfy","zfDVCMTLCKC","x0rctMfTzq","Dg9hzw5LCMe","CMvZB2X2zq","x2LZqNjVD3m","y3jLyxrLrxi","BgvY","tw9KDwXL","q3vZDg9Tq2W","wMDesM8","DcbVzIbYyw4","DNfiwfe","CMvHC29U","A1PvyNy","Dg92B0e","vgLJDMK","x3fVC0rc","sufQq0C","tfLKrMG","Bwf4uMv0CMK","wMnQtLi","ALfABeS","z2v0","Ec1TC2CTy3u","tKXPv3u","yKrbDMe","x2LZtwLUAvC","tLPYwuy","Bhm6ia","u2XTzu0","CMvWBgfJzui","ALv4tNe","r3Phvxq","C3bSAwnL","wfjIrKC","tg5UAMW","D3D0B2q","DxzAEuq","rfLNv2i","v1biwuO","tgrlrvm","ufbnu2C","C2vYDMLJzs0","Avffshq","vxrAww4","EfLuyw0","BMnVzgLUzW","mhWZFdj8nhW","vgfN","jMPZy2fSBgi","qKfvtgO","EurAse8","vxvrBgS","DgLxsfO","DhbizwfKzxi","vgrny0q","x29WDgLVBNm","wwnuv2K","AKXjAvK","D29yA3C","wNDkBM4","BMXkD2G","Dgv4Dc9Qyxy","t3nSExi","CMvWBgfJzq","x2rPC3bHDgm","rNrSqMK","C2HPzNq","DMfSDwvZ","ug50yM4","Be9Vuee","x2LUAxrhBg8","zMzMzG","zNjVBu51Bwi","CM9YrxzLBNq","v0DUvgy","DMTQCuW","BfLSu2m","Axnby2TdBgu","yMLUza","rwXftee","s2j4D0W","A0Xrv2e","y2fSBa","u0zPyue","wurIENe","shrqrgq","ywDLrxzLBNq","reTSsuy","wLrHuvq","DfLQCK4","BeHHBMrSzxi","nhWZFdj8mhW","r3bMzui","qw9Aq1K","BwLUzW","DgHHBIbSB2m","qMzxvKq","uKj1zNG","CYbWyxjHBxm","DfP5rxq","rg1nALa","uePAtgm","uenNuhe","uvL5D0O","D2ToEfK","CMvZDwX0","uKPlBwW","AwXSihvZzsa","wgvkyNu","A1fNzwi","EePvsKe","B2LUDfjLywm","AgfZt3DUuhi","Efvevvm","v1nbzhe","vw1KB20","qKXAtKq","yLDnCfC","t09rtwK","yLrttfq","yw1LoIa","tKnjDfG","CNjVCK1LC3m","ndi5mZaWmfbVCxDrvq","AMjrvwy","v2LUzg93","BMrWB2LUDca","ENPVDKK","q0rdBvq","ugvWs0C","yxKSig5LDhC","DwnZzvG","mZuWr0HhqNbw","zgvMAw5Luhi","CMvZzxrfBMq","B0LNAfq","zw5HyMXLvhi","ndzfsNr0qu0","ywnRDxbfBMq","s3P0Dxq","shjctNa","q2TNA1m","refzEvq","x2n1CNnVCKy","zxjFywnRx20","vMvjC2m","Cgf5Bg9Hzeu","tw9Trgm","A0rHwNy","qwT1A04","zM9YrwfJAa","r3b4uhG","y21hq2u","C3b4EwC","DKjOuMK","EuT0AuK","yMfSu2nVCgu","vuHuywC","sNnAuuS","x2rPC2nVBM4","txjfrLO","vhjTswW","D0zxv2W","y2LuEfe","s215EeO","C2zUA1i","CMvJzwL2zwq","tNnuugW","u3beDNu","uev0B0G","zLn2DMm","Aw5N","q2jXsvG","yxnL","q2P0wg4","ywnR","qujTzuq","C3nysfi","A3zwr0m","Dw50","uNH0Exm","yw1L","B29KDKG","zuX5DLC","BgvvDKy","ENzRCLG","q291BNq","zgrjrcWGzgu","s1PYy3i","q0DUww4","x2LUDgvYDMe","Aw9UvgLTzw8","B3jRig9MzMW","BMCGzMfPBgu","re9ND1u","CgLUz1rPBwu","ufbfq0y","Cg9PBNrbBMq","B2zRz3q","qKjRtKK","DMvYC2LVBG","zhfhzfe","wM9fAxC","rwDvug0","y29UBMvJDfm","sfjRD2W","AurUweS","B25pCgvU","BNrfBMrWB2K","vwr4ueS","Bg9N","y2XVC2veqG","nJm3odu0mff6swL4DW","EKLTDei","Dfftrw4","q0Xpu0ve","ANbACuu","BezSDxnO","BfrPBwvVDxq","y3jLyxrLuMu","ugLntNO","C2DPza","vvjKr0e","B1Lrtgy","ru1ZD0i","q29Kzq","DMn1t1y","BKTVqum","EsbJBg9Zzwq","wKPxBxy","zNjVBNrPzxi","ywDLsgLKzq","DhLWzq","CNjMAey","BNrbBMrvCgq","igzPzwXKoIa","DxbNCMfKzw4","BMPlEeG","rxbAvgm","B25ozxr3B3i","C2v0y3vYC28","C2furM4","twDIA2q","BgLUzq","tLn2B0e"];return $o=function(){return t},$o()}function e1(t){let e=L,n={uCdqN:e(1416),kdBvm:e(1595),yMmHF:function(o,c){return o!==c},AzXDh:"WAxZa",udeEr:function(o){return o()},hvFcE:"error"};if(Vo[e(722)](t))return;let i=new Promise((o,c)=>{let l=e,u={cQhWI:n[l(564)],pMhcb:n[l(734)],eJAga:function(_,S){return n[l(283)](_,S)},KZAYH:n[l(316)],xvvSe:function(_){return _()},rhQSp:function(_){return n.udeEr(_)},zefUG:function(_,S){return _(S)}},h=()=>{let _=l;t[_(992)+_(469)+_(1588)](u[_(591)],x),t["removeEv"+_(469)+_(1588)]("error",m),t[_(992)+_(469)+_(1588)](u.pMhcb,m)},x=()=>{let _=l;if(u[_(382)](u[_(1533)],_(1423)))u[_(1343)](o),u.rhQSp(h);else return this[_(624)][_(1429)]},m=()=>{let _=l;u[_(234)](c,t[_(417)]||new DOMException("AbortError",_(353)+"or")),u.rhQSp(h)};t[l(796)+"Listener"](n[l(564)],x),t.addEventListener(n[l(1374)],m),t[l(796)+l(1579)](n.kdBvm,m)});Vo[e(552)](t,i)}function t1(t){Zo={RyGJJ:function(i,o){return i(o)}}[L(1326)](t,Zo)}function n1(t){let e=L,n={peGNx:function(i,o){return i(o)},ASOQz:function(i,o){return i(o)},zIBJC:function(i,o){return i(o)},wpdwq:function(i,o,c){return i(o,c)},TdMcD:function(i,o){return i===o},dtOCj:e(1610)+e(948),DAAIH:function(i,o){return i!==o},JdFoP:"xLYFq"};if(n[e(1061)](t,IDBDatabase.prototype[e(921)+e(684)])&&!(n[e(1472)]in IDBTransaction.prototype))return function(i,...o){let c=e,l=t[c(1089)](n[c(303)](ns,this),i,...o);return Nl[c(552)](l,i[c(621)]?i[c(621)]():[i]),Bt(l)};if(Xv()[e(1414)](t)){if(n[e(555)](n[e(867)],e(789)))return function(...i){let o=e;return t[o(1268)](n[o(1479)](ns,this),i),n.zIBJC(Bt,Ll[o(1028)](this))};n[e(1551)](_0x2aa963,_0x3b3b9d,24),_0x3cd5e8(_0x5912de,n[e(303)](_0x310f3a,_0x126a1b))}return function(...i){let o=e;return n[o(303)](Bt,t[o(1268)](n[o(1428)](ns,this),i))}}function r1(t){let e=L,n={pAVvC:e(1577),pEkdN:function(i,o){return i(o)},CMlJk:function(i,o){return i instanceof o},efnUm:function(i){return i()}};return typeof t===n.pAVvC?n[e(157)](n1,t):(n.CMlJk(t,IDBTransaction)&&e1(t),Px(t,n[e(229)](Yv))?new Proxy(t,Zo):t)}function Bt(t){let e=L,n={NjyKT:function(o,c){return o>>>c},cSBea:function(o,c){return o+c},wsnOg:function(o,c){return o&c},wMYfi:function(o,c){return o>>>c},ncjAO:function(o,c){return o>>>c},DdiRD:function(o,c){return o+c},CGnYn:function(o,c){return o>>>c},nBszQ:function(o,c){return o+c},oMGuA:function(o,c){return o&c},YZmQu:function(o,c){return o+c},FXVvM:function(o,c){return o instanceof c},bfuOy:function(o,c){return o(c)},DLULS:function(o,c){return o(c)},QCuZG:function(o,c){return o!==c},JaznB:e(820)};if(n[e(338)](t,IDBRequest))return n[e(707)](Qv,t);if(Wo[e(722)](t))return Wo[e(1028)](t);let i=n[e(504)](r1,t);if(n[e(1330)](i,t))if(n[e(1330)](e(410),n[e(665)]))Wo[e(552)](t,i),Jo[e(552)](i,t);else{let o=_0x1edc31[e(305)],c=_0x1b61a2[e(810)];return _0x35ee22[_0x1010f9]=n[e(1417)](c,24),_0x27cd1b[n.cSBea(_0x532293,1)]=n.wsnOg(n[e(904)](c,16),255),_0x1d80ab[n.cSBea(_0x358931,2)]=n[e(899)](n.ncjAO(c,8),255),_0x4efd46[n[e(1431)](_0x2b7e42,3)]=255&c,_0x578e55[n.cSBea(_0x448913,4)]=n[e(1196)](o,24),_0x26dd46[n[e(1367)](_0x39a9f9,5)]=n[e(1523)](n[e(1196)](o,16),255),_0x30815e[n[e(1431)](_0x4f2b8e,6)]=n.CGnYn(o,8)&255,_0x239daf[n.YZmQu(_0x473f7f,7)]=255&o,_0x1059e3+=8,_0x5a6113}return i}var Px,Ix,Ax,Ll,Vo,Nl,Wo,Jo,Zo,ns,Tx=Cx({"node_modules/idb/build/wrap-idb-value.js"(){let t=L,e={FzPkq:function(n,i){return n||i},WArwJ:function(n,i){return n!==i},pWVUB:"LQPIe",kQgeb:function(n,i){return n instanceof i},PKEig:function(n,i){return n===i},RviHo:t(1567),hrOsM:t(1610)+t(948),Yxliq:t(736),mWfhz:t(438),OAtRm:function(n,i){return n(i)},fSvvc:function(n,i){return n instanceof i},dJujl:function(n,i){return n===i},ANxPi:function(n,i){return n in i}};Px=(n,i)=>i[t(544)](o=>n instanceof o),Ll=new WeakMap,Vo=new WeakMap,Nl=new WeakMap,Wo=new WeakMap,Jo=new WeakMap,Zo={get(n,i,o){let c=t,l={TWpEv:function(u,h){return e[J(782)](u,h)}};if(e.WArwJ(e[c(1515)],"oRHDb")){if(e[c(1116)](n,IDBTransaction)){if(e[c(1001)](i,e[c(359)]))return Vo[c(1028)](n);if(e[c(1001)](i,e[c(1261)])){if(e[c(897)]===c(736))return n[c(1610)+"oreNames"]||Nl.get(n);{let u=this[c(1022)][c(302)](this._prefix),h=_0x25ea29[c(1262)](l.TWpEv(u,"{}"));return h[_0x20e839||_0x2955b2[this._pathKey]]=_0x154b08,this[c(1022)][c(1407)](this._prefix,_0x5950d9.stringify(h)),_0x191bf3||_0x243538[this._pathKey]}}if(e.PKEig(i,e.mWfhz))return o.objectStoreNames[1]?void 0:o[c(1610)+c(689)](o[c(1610)+c(948)][0])}return e[c(1303)](Bt,n[i])}else return!!this._qosDB},set(n,i,o){return n[i]=o,!0},has(n,i){let o=t;return e[o(1177)](n,IDBTransaction)&&(i===e.RviHo||e[o(1425)](i,e[o(1333)]))?!0:e[o(861)](i,n)}},ns=n=>Jo[t(1028)](n)}}),Dx={};Zv(Dx,{deleteDB:()=>s1,openDB:()=>i1,unwrap:()=>ns,wrap:()=>Bt});function i1(t,e,{blocked:n,upgrade:i,blocking:o,terminated:c}={}){let l=L,u={AkukN:function(m,_,S,y,v){return m(_,S,y,v)},JhcOQ:function(m,_){return m(_)},fsygi:function(m,_){return m+_},raaJb:l(1491)+"hange",qZsVD:function(m,_){return m===_},NkOMd:"iDnXK",yfUAI:l(845)},h=indexedDB.open(t,e),x=u[l(293)](Bt,h);if(i)if(u.qZsVD(u[l(269)],l(1213)))h[l(796)+l(1579)](l(1243)+"eeded",m=>{let _=l;u[_(1156)](i,u[_(293)](Bt,h.result),m.oldVersion,m[_(592)+"on"],Bt(h[_(921)+"ion"]))});else return u[l(941)](u[l(293)](_0x4c0244,8)[l(1420)]("0"),_0x4445c5(_0x43ed24,10).toString(2))[l(1399)](-8);return n&&h["addEvent"+l(1579)](u[l(503)],()=>n()),x[l(1534)](m=>{let _=l;c&&m[_(796)+_(1579)](_(695),()=>c()),o&&m.addEventListener(u.raaJb,()=>o())})[l(1476)](()=>{}),x}function s1(t,{blocked:e}={}){let n=L,i={fXuzK:function(c,l){return c(l)}},o=indexedDB.deleteDatabase(t);return e&&o[n(796)+n(1579)](n(845),()=>e()),i[n(487)](Bt,o)[n(1534)](()=>{})}function kx(t,e){let n=L,i={AUONs:n(1173),phfhO:function(h){return h()},csFpD:function(h,x){return h!==x},wCmmL:n(387),DYgWb:n(1494)+"e",NSvoA:function(h,x){return h in x},Kztut:function(h,x){return h===x},NhzKD:function(h,x){return h!==x},cOjfW:function(h,x){return h in x}};if(!(t instanceof IDBDatabase&&!i[n(1251)](e,t)&&i[n(1146)](typeof e,n(463))))return;if(Ko[n(1028)](e))return Ko[n(1028)](e);let o=e[n(1070)](/FromIndex$/,""),c=i[n(1530)](e,o),l=Nx[n(1414)](o);if(!i[n(131)](o,(c?IDBIndex:IDBObjectStore)[n(132)+"e"])||!(l||Ox[n(1414)](o)))return;let u=async function(h,...x){let m=n;if(i[m(1584)](m(387),i[m(318)]))this[m(1267)](i.AUONs,_0x31bddc[m(515)]),i[m(611)](_0x5dc05e);else{let _=this[m(921)+m(684)](h,l?i[m(1044)]:"readonly"),S=_[m(438)];return c&&(S=S[m(956)](x[m(1073)]())),(await Promise[m(857)]([S[o](...x),l&&_[m(1567)]]))[0]}};return Ko[n(552)](e,u),u}var Ox,Nx,Ko,o1=Cx({"node_modules/idb/build/index.js"(){let t=L,e={mrhtv:function(n){return n()},lKBqH:t(1028),xYdFa:"getKey",OrShr:t(918),LYdFh:"getAllKeys",iiJOK:t(744),GZSRO:t(575),sBmWe:t(655),KSZcu:t(682),Hbwcu:function(n,i){return n(i)}};Tx(),e[t(930)](Tx),Ox=[e[t(965)],e[t(1288)],e[t(967)],e[t(1024)],t(748)],Nx=[e.iiJOK,e[t(902)],e[t(454)],e.KSZcu],Ko=new Map,e[t(800)](t1,n=>({...n,get:(i,o,c)=>kx(i,o)||n.get(i,o,c),has:(i,o)=>!!kx(i,o)||n[t(722)](i,o)}))}}),a1={idb:function(t){let e=L;t.exports=Promise[e(1009)]().then(()=>(o1(),Dx)).then(function(n){return n})}},Rx={};function Mt(t){let e=L,n={qkNEL:e(1466)+"2",ElELA:function(u,h){return u!==h}},i=n[e(964)].split("|"),o=0;for(;;){switch(i[o++]){case"0":if(n[e(1086)](void 0,c))return c[e(540)];continue;case"1":a1[t](l,l[e(540)],Mt);continue;case"2":return l[e(540)];case"3":var c=Rx[t];continue;case"4":var l=Rx[t]={exports:{}};continue}break}}(()=>{let t=L,e={eVEJe:function(n,i){return n<i},qpzLK:function(n,i){return n!==i},oYJQW:function(n,i){return n-i},GnJbO:t(116)};Mt.d=(n,i)=>{let o=t;if(e[o(209)]===o(116))for(var c in i)Mt.o(i,c)&&!Mt.o(n,c)&&Object[o(1140)+"operty"](n,c,{enumerable:!0,get:i[c]});else{let l=_0x16e3ba.split(":");for(let u=0;e[o(703)](u,l.length);u++){let h=l[u];if(e[o(886)](4,l[u][o(1605)])){let x=_0x1c032b.substring(0,e[o(728)](4,l[u][o(1605)])),m=x.concat(h);_0x19d87a=_0xee0cf7[o(604)](m)}else _0x16dda8=_0x5d9995.concat(h)}return _0x2f3bbf}}})(),(()=>{let t=L;Mt.o=(e,n)=>Object[t(132)+"e"][t(1119)+t(562)][t(1089)](e,n)})(),(()=>{let t=L,e={bJLpq:function(n,i){return n!=i},QNQFj:t(284)+"d",HtPDd:"Module",iihyw:t(885)+"le"};Mt.r=n=>{let i=t;e[i(334)](e[i(599)],typeof Symbol)&&Symbol[i(1347)+i(1054)]&&Object[i(1140)+i(562)](n,Symbol[i(1347)+i(1054)],{value:e[i(1092)]}),Object[i(1140)+"operty"](n,e.iihyw,{value:!0})}})();var Ce={};(()=>{let t=L,e={HRcja:function(a,r){return a(r)},chFjy:function(a,r){return a+r},ZgDJo:function(a,r){return a+r},ygezF:function(a,r){return a+r},TzTSD:function(a,r,s){return a(r,s)},SlmeM:function(a,r){return a+r},ZwJnn:function(a,r){return a(r)},tVzbI:function(a,r,s){return a(r,s)},EgUPm:t(183),Glfdt:t(1078),KOpQy:function(a,r){return a(r)},aWZlR:function(a,r){return a>r},RvxaA:function(a,r){return a<r},TdDFy:function(a,r){return a!==r},gXpfV:function(a,r){return a-r},RVuGd:function(a,r){return a-r},bMQlV:function(a,r){return a<r},UEDhD:function(a,r){return a===r},pGAnZ:function(a,r){return a!==r},bBPpT:t(1182),UTtlE:function(a,r){return a<r},TuGwC:function(a,r){return a|r},lOoPA:function(a,r){return a|r},FYFdh:function(a,r){return a>>>r},XRbFG:function(a,r){return a|r},vhjlJ:function(a,r){return a<<r},ZcjNR:function(a,r){return a&r},gYYpd:function(a,r){return a&r},woXkw:function(a,r){return a<<r},zyVlm:function(a,r){return a>r},QZTXG:function(a,r){return a>>>r},RLnFT:function(a,r){return a!==r},XSNnl:function(a,r){return a!==r},saTFn:function(a,r,s){return a(r,s)},LomJJ:function(a,r,s){return a(r,s)},lwMly:function(a,r){return a!==r},HkTyJ:t(1185),ZIEwg:function(a,r){return a(r)},eEOdy:function(a,r){return a>>>r},OFtZa:function(a,r){return a===r},XEvqD:t(534)+"required"+t(1242)+t(889),RjURm:function(a,r){return a(r)},XGXPK:function(a,r,s){return a(r,s)},ujjPd:function(a,r,s){return a(r,s)},UjczL:function(a,r){return a!==r},ntGyl:function(a,r,s){return a(r,s)},PvGaV:function(a,r,s){return a(r,s)},lPIQW:function(a,r,s){return a(r,s)},HejZP:function(a,r,s){return a(r,s)},zGaat:function(a,r){return a(r)},RBufx:function(a,r){return a!==r},KZrcr:function(a,r){return a!==r},lykJs:function(a,r){return a!==r},lplRI:"lmqZz",uRtJn:t(1282),WXkSf:function(a,r,s){return a(r,s)},ajJpG:function(a,r,s){return a(r,s)},tuAKD:function(a,r,s){return a(r,s)},JGjcW:t(309),WBCyx:t(626),ydFOD:function(a,r){return a(r)},mBFgS:function(a,r,s){return a(r,s)},xGXSz:function(a,r,s){return a(r,s)},nxnWu:function(a,r){return a(r)},LGmOJ:function(a,r){return a(r)},aihxz:function(a,r,s){return a(r,s)},zhnOV:function(a,r,s){return a(r,s)},hcYdu:function(a,r,s){return a(r,s)},Mgbkd:function(a,r){return a(r)},PqLya:function(a,r){return a(r)},yyGSR:function(a,r){return a&r},MomDc:"Missing required"+t(1242)+t(776),GSnIJ:t(534)+t(520)+t(1242)+t(190),fvCbn:function(a,r){return a(r)},dXQGk:function(a,r){return a(r)},jbQUf:function(a,r,s){return a(r,s)},RMXWo:function(a,r,s){return a(r,s)},OEgrL:t(374)+t(579)+t(170),ABvmB:function(a,r){return a!==r},iMvUr:"GIMmj",IGaQX:function(a,r){return a||r},RoPpL:"string",iunsw:t(828)+"econnect"+t(1178),leUvF:function(a,r){return a!==r},cgFyw:t(577),CqPfY:t(772)+"t",nffgD:t(1463),FYljS:t(417),BAULj:t(1240),daxTn:function(a,r){return a+r},nPJvp:t(301)+t(501),irmae:function(a,r){return a(r)},TfFVr:function(a,r){return a===r},CbqIX:t(521),shLhq:t(1081),BfWVD:function(a,r){return a*r},rDBBN:function(a,r){return a>r},SdLiD:function(a,r){return a&r},zCgkx:function(a,r){return a&r},MZJvq:function(a,r){return a&r},dptrq:function(a,r){return a(r)},ASuvm:function(a,r){return a&r},AQPtg:function(a,r){return a instanceof r},JiXKp:function(a,r){return a!=r},MaJXK:function(a,r){return a===r},YRoYp:function(a,r){return a&r},NZJGU:function(a,r){return a>=r},pdEYG:function(a,r){return a&r},gtcBP:function(a,r){return a|r},kFoLZ:function(a,r){return a<<r},nKoAC:function(a,r){return a==r},Ticvi:function(a,r){return a>=r},bDAva:"zWhaF",MISMj:function(a,r){return a+r},kBtSf:function(a,r){return a+r},FEJCD:function(a,r){return a&r},BEEZh:function(a,r){return a<<r},PCgPq:function(a,r){return a!==r},psxRh:"vqDSh",aJEgG:"qPbfv",DiCQu:function(a,r){return a|r},CIwxX:function(a,r){return a|r},PwLKQ:function(a,r){return a<<r},DlECW:function(a,r){return a&r},tIXDX:function(a,r){return a&r},bxEgQ:function(a,r){return a>=r},mmkMV:function(a,r){return a<=r},tlXyG:t(1057),vFaro:"GAUEJ",Qnvbl:function(a,r){return a(r)},Qifrg:function(a,r){return a==r},HjLFo:function(a,r){return a+r},MBzJA:function(a,r){return a+r},eeUKL:function(a,r){return a+r},ItfDE:function(a,r){return a+r},vcuOV:function(a,r){return a+r},wHMNc:function(a,r){return a!==r},YxkTC:function(a,r){return a|r},YcTWi:function(a,r){return a<<r},niRuE:function(a,r){return a<<r},caKXo:function(a,r){return a|r},TtAlZ:function(a,r){return a&r},NLiWu:function(a,r){return a<<r},Oslyr:function(a,r){return a>>r},ibddT:function(a,r){return a+r},CiDTT:function(a,r,s,d){return a(r,s,d)},kEZIr:function(a,r){return a===r},OzlNP:t(849),pgpCw:t(755),hOWTQ:function(a,r){return a<r},GpxPx:function(a,r){return a+r},jrBJw:function(a,r){return a<<r},rIBrQ:function(a,r,s){return a(r,s)},SpuaS:function(a,r,s){return a(r,s)},vkjqL:function(a,r){return a<=r},ofkgt:function(a,r){return a+r},qlvwm:function(a,r){return a-r},Pntbn:function(a,r){return a+r},iXPlL:t(435),UeIrd:"GEUuA",EUWjP:function(a,r){return a|r},WzOdF:function(a,r){return a>>r},MikET:function(a,r){return a<r},uuEpF:function(a,r){return a&r},lQmvM:function(a,r){return a>>r},zxqIN:function(a,r){return a&r},ZeQUW:function(a,r){return a>>r},ThYcb:function(a,r,s){return a(r,s)},GdqHd:"DeJYx",KbbTW:function(a,r,s){return a(r,s)},MJjxH:function(a,r){return a&r},czefV:function(a,r,s){return a(r,s)},lvGCe:t(213)+"1",GpfeB:function(a,r){return a===r},CzbJL:t(1027),CfFeq:function(a,r){return a&r},znoeC:function(a,r){return a(r)},IFZtu:function(a,r){return a<<r},NAINt:function(a,r){return a<<r},EFYLJ:function(a,r){return a&r},KWxpS:function(a,r){return a(r)},tYjrN:function(a,r){return a(r)},oYyWa:function(a,r){return a&r},VmwYp:function(a,r){return a(r)},sdTAW:function(a,r){return a<<r},uoGee:function(a,r){return a&r},mXGwN:function(a,r){return a|r},Qmotj:function(a,r){return a|r},dAlmZ:function(a,r){return a<<r},Tpath:t(175),HMyaE:"Kcbhz",bWMpW:function(a,r){return a>>>r},DmMjP:function(a,r){return a===r},zufMj:function(a,r){return a<r},rKmHH:function(a,r){return a<r},PKyzE:function(a,r){return a+r},UHTag:function(a,r){return a+r},zyGEZ:function(a,r){return a!==r},TrmIl:function(a,r){return a|r},xgovP:function(a,r){return a&r},xSkvd:function(a,r){return a+r},GVAwW:function(a,r){return a!==r},cvMnf:function(a,r){return a|r},uvaqP:function(a,r){return a>>>r},MmPvu:function(a,r){return a&r},GJXDw:function(a,r){return a&r},ZTaQT:function(a,r){return a>>>r},anPAu:function(a,r){return a+r},WTlpN:function(a,r){return a|r},VznlZ:function(a,r){return a&r},lYlSc:function(a,r){return a+r},ixUJJ:function(a,r){return a!==r},FldCu:function(a,r){return a&r},touvH:function(a,r){return a+r},Ritqm:function(a,r){return a!==r},xjdAR:function(a,r){return a|r},jFyFh:function(a,r){return a|r},aDLku:function(a,r){return a>>>r},hFilu:function(a,r){return a!==r},IHHVN:function(a,r){return a|r},dlZlp:function(a,r){return a&r},CDCmT:function(a,r){return a(r)},nUHnO:function(a,r){return a|r},AkBYP:function(a,r){return a|r},lETvD:function(a,r){return a===r},uzMoo:"XUMqJ",IWfUx:function(a,r){return a|r},PGBXL:function(a,r){return a|r},jNmQR:function(a,r){return a|r},wkNxY:function(a,r){return a|r},TlBby:function(a,r){return a<<r},Ekudw:function(a,r){return a|r},FlwVC:function(a,r){return a<<r},yYHOd:function(a,r){return a<<r},FoEiS:function(a,r){return a<<r},ucseX:function(a,r){return a|r},FzVXB:function(a,r){return a<<r},XeJbu:function(a,r){return a<<r},CrlOO:function(a,r,s){return a(r,s)},fQdzL:function(a,r){return a&r},ciTxQ:function(a,r){return a===r},PrymK:function(a,r){return a===r},OpuMe:function(a,r){return a|r},uRVan:function(a,r){return a|r},LdKES:function(a,r){return a<<r},Ktedx:function(a,r){return a<<r},NuamT:function(a,r){return a|r},ntfYz:function(a,r){return a<<r},Atlos:function(a,r){return a&r},ZxxKm:function(a,r){return a&r},SpDvu:function(a,r){return a&r},yEcSV:function(a,r){return a>>>r},tcIrm:function(a,r){return a>=r},gUEZO:function(a,r){return a+r},XqUQU:function(a,r){return a/r},rVSGP:function(a,r){return a+r},mFCFl:function(a,r){return a*r},gPMza:function(a,r){return a&r},fwQYZ:function(a,r){return a>>>r},NcTDQ:function(a,r){return a+r},qoPoP:function(a,r){return a<<r},ObhQF:t(422),matED:function(a,r){return a!==r},qMtIj:function(a,r){return a===r},yHQwV:function(a,r){return a===r},xJCsA:function(a,r){return a===r},AoZCY:function(a,r){return a===r},koJYl:function(a,r){return a+r},UwApe:function(a,r){return a&r},SMMDO:function(a,r){return a&r},Jjcoj:function(a,r){return a&r},fBcYo:function(a,r){return a>>>r},iVQTq:function(a,r){return a>>>r},jkfnP:function(a,r){return a&r},OOQMi:function(a,r){return a>>>r},IQeEz:function(a,r,s){return a(r,s)},PepKG:"message",oFImo:t(677),BBkNI:t(150),Qkkce:function(a,r){return a>>>r},lByjR:function(a,r){return a&r},eHgmE:function(a,r){return a>>>r},oXCDB:function(a,r){return a&r},qctyW:function(a,r){return a>>>r},BYXlB:"4|0|1|3|"+t(1489),waXaw:t(835)+t(168),Pcypw:t(177)+t(551)+"R",fmrZx:t(791)+"OR",DXTzY:t(530)+t(325),IUyvV:"NATIVE_E"+t(176),HtSQq:function(a,r){return a&r},VzUdd:function(a,r){return a&r},dWuZJ:"tcCvb",DgNHz:"pUnlm",wuGqE:"0|2|1|4|3",YWJUi:function(a,r){return a>=r},NJOac:function(a,r){return a===r},sfvgq:function(a,r){return a+r},zPikB:t(1398)+"d error.",mJsrX:function(a,r){return a+r},HlJis:function(a,r){return a===r},dDLyt:function(a,r){return a===r},mpFbE:function(a,r){return a===r},dSUwq:"QAOjO",UsiIn:function(a,r,s){return a(r,s)},SvZTU:t(695),yfRJe:function(a,r){return a(r)},fARIa:function(a,r){return a!==r},IAjCG:"rxPhs",ComOy:t(426),fxlBR:function(a,r,s){return a(r,s)},oEdEG:t(858),wamzC:function(a,r,s){return a(r,s)},xiwew:function(a,r){return a instanceof r},mPHdW:t(1148),QVRSJ:function(a,r){return a||r},FGPfd:t(284)+"d",dtruK:function(a,r,s,d,f){return a(r,s,d,f)},NZrYF:function(a,r){return a!==r},XHCFn:function(a,r){return a||r},mvplz:t(688)+"alled multiple t"+t(629)+t(465),EZILO:function(a,r){return a<r},xeGoO:function(a,r){return a<r},HfmAC:function(a,r){return a<r},ZXKRR:function(a,r){return a&r},EhghU:function(a,r){return a&r},feGob:function(a,r){return a<r},rESlW:function(a,r){return a|r},EvxaM:function(a,r){return a&r},IkDUn:function(a,r){return a-r},nqOLI:function(a,r){return a&r},EuBAm:function(a,r){return a<<r},BLGex:function(a,r){return a&r},ArKHk:function(a,r){return a>>r},vBhRi:function(a,r){return a<r},fpWGi:function(a,r){return a&r},nFvlz:function(a,r){return a===r},NvFjX:t(1098)+"1|5",UuQlk:function(a,r){return a&r},YDbzq:function(a,r){return a|r},rmtJy:function(a,r){return a&r},MhYjW:function(a,r){return a>>r},ZMNyL:function(a,r){return a>>r},HPAdT:function(a,r){return a+r},gMXmZ:function(a,r){return a<<r},qCoWp:function(a,r){return a&r},jUxNq:function(a,r){return a&r},luwnR:function(a,r){return a>>r},tiWHZ:function(a,r){return a|r},iERUD:function(a,r){return a&r},WmSkC:function(a,r){return a|r},GesHW:function(a,r){return a&r},QzfGH:function(a,r){return a-r},Eqiov:function(a,r){return a(r)},DAYyT:function(a,r){return a!=r},NJXPH:t(1013),VeIsc:t(1328),EMRNS:function(a,r){return a!=r},gIjdf:function(a,r){return a instanceof r},cKtTE:"applicat"+t(1273),UtZYn:function(a,r){return a==r},jsMFn:t(840)+t(753)+t(1565),wzQoD:t(1573),FoCyq:"ppe",KbhHq:function(a,r){return a instanceof r},bCDqb:"unknown "+t(1018),vWOSe:t(1167),uSsuM:t(1280),YzRJz:t(1517),tApwV:function(a,r){return a(r)},pvpHB:function(a,r){return a===r},OpuMI:t(1183),ZJWmv:"FLbbt",GDVWZ:t(762),VVzSP:"3|7|4|6|"+t(125)+t(1350),aKanF:t(1048)+t(1257),QNFtb:t(1257),nQLlD:t(1502),MEzXz:t(776),akmmc:function(a,r,s,d){return a(r,s,d)},eXkRv:t(1563),ZMLBk:function(a,r){return a===r},okXOh:t(1019),NCItX:function(a){return a()},oIbqy:function(a,r){return a===r},eApJe:t(1519),CKlNH:"zduKE",ACWUF:t(659),EGCzD:t(1190),hFGVO:function(a,r){return a(r)},jLIiY:function(a,r,s){return a(r,s)},iSTzU:function(a,r){return a!==r},fzRes:t(1404),YRYYt:t(1412),EMViw:function(a,r){return a>=r},cmGCe:function(a,r){return a===r},NNvAX:t(1536),OeELv:function(a,r){return a||r},gYEXI:function(a,r){return a||r},fATCn:function(a,r){return a||r},pQPUN:function(a,r){return a||r},CHfZk:function(a,r){return a===r},cOolR:t(709),spCVk:function(a,r){return a!=r},qwHoI:"init QoS"+t(1360)+"d",PAnfM:t(831),CIKnp:function(a,r){return a*r},iADAR:function(a,r){return a>>>r},jjfcV:t(841),JXIvI:function(a,r,s){return a(r,s)},OwQEw:t(954),IEgqg:function(a,r){return a!==r},Bwpdg:"sFJTM",TXxaw:function(a,r,s,d){return a(r,s,d)},PoGCw:t(399)+"er_qos_ack",PiMNz:function(a,r,s,d){return a(r,s,d)},NxmlW:t(399)+t(1427)+"k",CjtXn:t(246),sXULO:t(971),xrbQc:function(a,r){return a||r},PJZLc:t(1355),ChIno:t(1173),toaaL:function(a){return a()},GTuXX:t(1256),GBDqR:function(a,r){return a(r)},ZNDkK:t(1590)+"e",KspFi:t(1258),mkZsK:function(a,r){return a<r},esoJu:function(a,r){return a+r},MswYF:function(a,r){return a(r)},KoWnq:function(a,r){return a>>>r},PEtoH:function(a,r){return a<r},DDBsw:function(a,r){return a+r},zcUoP:function(a,r){return a===r},IbkiX:t(1212),RJKml:t(853),SFFff:function(a,r){return a+r},QJhQf:function(a,r){return a+r},nUlIA:function(a,r){return a+r},zOeQX:function(a,r){return a+r},ssXHR:t(588)+t(1016)+"ge: ",ojtZM:t(727),tovoA:function(a,r){return a!==r},MrFnk:t(1349),eHptx:t(1045),lzgva:function(a,r){return a>r},wwtod:t(1315)+"too large",mUhvJ:function(a,r){return a&r},wAWat:function(a,r){return a+r},wdwTO:function(a,r){return a>>>r},zfxmH:t(1053)+"1",qSsTy:function(a,r){return a+r},wbPzN:function(a,r){return a+r},YlYHN:function(a,r,s,d){return a(r,s,d)},XRxVa:function(a,r){return a|r},kLQWa:function(a,r){return a|r},eCkTb:function(a,r){return a|r},tKVmR:function(a,r){return a|r},tWihD:function(a,r){return a<<r},wBbkJ:function(a,r){return a+r},PxPqC:function(a,r){return a<<r},YNyUc:function(a,r){return a+r},wTkhD:function(a,r){return a+r},AFtBg:function(a,r){return a&r},tuvTH:function(a,r){return a+r},fCjWs:function(a,r){return a>>>r},iAJTU:function(a,r){return a&r},GbvrM:function(a,r){return a+r},BAUSI:function(a,r){return a+r},fcvee:function(a,r){return a&r},oEkrw:function(a,r){return a&r},rxMQB:"FRONTIER>",IMBHB:function(a,r){return a>>>r},BfVCv:function(a,r){return a<r},vCMDP:function(a,r){return a<r},hRRfo:t(574),daHLM:function(a,r){return a+r},orWcS:function(a,r){return a+r},fOOCe:function(a,r){return a!==r},HJFou:function(a,r){return a&r},nbOzm:function(a,r){return a>=r},beShb:function(a,r){return a(r)},FqYXw:"bCDFa",BUJNW:function(a,r){return a+r},xlPss:t(742)+t(653)+t(402),VnChG:function(a,r,s,d){return a(r,s,d)},xJQjN:"curvalue",SoBVe:function(a,r){return a(r)},WCNrm:t(1470)+t(473),Lnnjl:function(a,r,s){return a(r,s)},FurmQ:t(864),moWqi:function(a,r,s,d){return a(r,s,d)},yMSUG:t(193)+t(1332),OPXzR:function(a,r,s){return a(r,s)},crvpX:function(a,r){return a===r},VeGgk:"mHZla",sfnkR:function(a,r,s){return a(r,s)},HjaaP:t(1307)+t(1188),hlTVV:t(198)+t(189),dAcsM:"CONTINUE",MXFhn:function(a,r,s,d){return a(r,s,d)},cRBwV:function(a){return a()},rPMAZ:t(262),JmCyZ:t(1247)+"r",MHyHh:t(447),CVGBF:t(1484),FwZHE:function(a,r){return a||r},YoIOd:t(1311),XySUn:t(721),qmbuD:"x_frontier_msgid",NvcJA:function(a,r){return a(r)},oNCJO:function(a,r,s){return a(r,s)},AKDMU:t(399)+t(216),lLCGs:t(486)+"s",iBwEd:t(1029)+t(725)+"e",PPMSg:t(1029)+t(479)+"ue",muelz:function(a){return a()},yfkmm:function(a,r){return a>r},dtzAX:function(a,r){return a+r},eujqj:function(a){return a()},NEVcA:function(a){return a()},SFtcx:function(a,r){return a&&r},eouYD:function(a,r,s){return a(r,s)},yNeNm:function(a){return a()},UVzRu:function(a,r){return a(r)},PPECF:function(a,r){return a!==r},lxuFh:function(a,r){return a===r},EsuKM:function(a,r,s){return a(r,s)},ZXjZs:function(a){return a()},Onxnl:function(a){return a()},YfQLb:function(a,r,s,d){return a(r,s,d)},cVAVY:t(585),mUvKM:function(a,r,s){return a(r,s)},xUoDu:"aPMpb",EpZTc:function(a,r){return a===r},XbtRC:t(409)+t(1390)+"s",HcPAu:function(a,r,s){return a(r,s)},SLPbH:function(a,r){return a!==r},DbMXZ:t(335),wGeVK:t(1591),vKMYl:"QuRFz",yJaDe:function(a,r,s){return a(r,s)},VggnO:t(245)+t(1366),AYxvB:t(986),NMLit:"auto",fuFNX:function(a,r){return a==r},TVpQx:t(1549)+t(415)+t(738),NPjiM:t(1549)+t(862)+t(1105)+t(979)+"ket constructor "+t(457)+t(428),NsTPl:function(a,r){return a!==r},REozE:t(963),wFWWl:t(860),xYHFc:"pagehide",uRTte:t(152),XrxKy:t(231),EMswB:function(a,r){return a===r},CkGwP:function(a,r,s){return a(r,s)},VmLxz:"QdrQf",njKxH:function(a,r){return a!==r},zzovI:t(1567),WFeUN:function(a,r){return a===r},zImtB:t(438),QYywJ:t(1457),bupqx:"https:",XeRDk:"wss://",yOyJP:t(237),RBSwN:t(259),Ovnwu:"device_id",gQaKW:"please p"+t(1450)+t(1194)+t(873)+t(596),SCxCo:"function",uvZyD:function(a){return a()},xENxV:function(a,r,s){return a(r,s)},pOmeP:"web",wSNEY:function(a,r,s){return a(r,s)},wgQrE:function(a,r,s){return a(r,s)},RHeSk:function(a,r,s){return a(r,s)},CzsoG:function(a,r){return a>r},oIghT:function(a,r,s){return a(r,s)},IEzTE:function(a,r,s){return a(r,s)},bciZo:function(a,r){return a(r)},RpCjJ:function(a,r){return a(r)},xmRnM:function(a,r){return a-r},JaOhv:function(a,r){return a>r},tUSvT:function(a,r,s){return a(r,s)},UvPSG:t(913),kDaZv:function(a,r){return a!==r},bTSLT:function(a,r,s){return a(r,s)},QvPme:t(409)+"e_timeout",MmJlq:"timeout",WvHod:"going away, try "+t(772)+"ting ser"+t(349),lItvZ:function(a,r){return a===r},YrstX:"KREMO",ZURMd:t(350)+" try rec"+t(1305)+"g",BLZND:function(a,r){return a(r)},PXwTl:function(a,r){return a===r},VPjYc:t(957),evYsi:t(1397),oYQLf:function(a,r){return a===r},dizdm:t(1171),lmlVs:t(187)+"4",bBVyh:function(a,r){return a===r},mzyhQ:function(a,r){return a===r},ATGeV:t(1147),cgTYC:function(a,r,s){return a(r,s)},mgosn:t(794)+t(1137)+t(1199)+"ine",sHtGl:function(a,r){return a!==r},CrPSh:"hBncH",FQuWV:"jJUTa",OGCHs:function(a,r){return a+r},yJITA:function(a,r){return a===r},reeuZ:t(879),JsZQK:"close, w"+t(1321)+"ce not initialized",VeKpL:t(1582)+"s alread"+t(1235),dSOYv:t(1302),tjolm:function(a,r){return a!=r},yAVPf:function(a,r){return a instanceof r},JItKU:"please p"+t(1589)+t(1373)+t(812),dBUcG:t(239),ZyUVU:t(804),JcVLV:function(a,r){return a===r},kZZpn:function(a,r){return a===r},nLcrf:"PvPTc",xYTam:"2|0|4|1|3",mUwyv:t(905)+t(1540),pKzwA:t(839),YgQXl:function(a,r){return a(r)},SJegX:function(a,r){return a!==r},iQEHt:t(378),SFiaA:"\0\0\0\0\0\0\0\0",okyWj:function(a,r){return a!=r},Rjqte:t(1132),eRdEN:function(a,r){return a!=r},cEaap:t(1566),ItcsS:function(a,r){return a===r},rVWcC:function(a,r){return a!=r},dqGdQ:function(a,r){return a!=r},TGaKo:function(a,r){return a!=r},ONqex:function(a,r){return a!=r},xwJVI:t(412)+"dWorkerG"+t(384)+"pe",XkgNU:"SharedWo"+t(931)+t(333),uxQeG:t(1542)+"orkerGlo"+t(1163),lidiW:function(a,r){return a!=r},egYjc:function(a,r){return a===r},ELdRi:function(a,r){return a!=r},SvCIL:function(a,r){return a!=r},vrzOi:function(a,r){return a!=r},DSbbT:t(400)+t(509)};Mt.r(Ce),Mt.d(Ce,{FWS:()=>_g,CustomErrorEvent:()=>nd,createCloseEvent:()=>gt,ReconnectEvent:()=>td,createErrorEvent:()=>ct,decodedFrame:()=>en,createOpenEvent:()=>cd,CustomCloseEvent:()=>rd,createReconnectEvent:()=>ha,FrontierMessageEvent:()=>sd,encodeFrame:()=>zt,createMessageEvent:()=>ad,OpenEvent:()=>od,ErrorCode:()=>nn,Event:()=>nr,MessageEvent:()=>id});let n="";function i(a=""){let r=t,s="02",d=""+Date[r(690)](),f=n||(n=e[r(1518)](h,a)),g=Math.random().toString(16)[r(1399)](-6);return e.chFjy(e.ZgDJo(e[r(1015)](s,d),f),g)}function o(){let a=t;return e[a(1015)](1e4*Date.now(),Math[a(171)](1e4*Math[a(999)]()))}function c(a){let r=t;return e.ygezF(Array(8)[r(1420)]("0"),e[r(215)](parseInt,a,10)[r(1347)](2))[r(1399)](-8)}function l(a){let r=t;return e[r(1035)](e.ZwJnn(Array,4)[r(1420)]("0"),e.tVzbI(parseInt,a,2)[r(1347)](16))[r(1399)](-4)}function u(a){let r=t,s=a[r(376)](/\./)[r(803)](g=>c(g)),d=[];return d[0]=e.ZwJnn(l,s[0]+s[1]),d[1]=e[r(1066)](l,e[r(1035)](s[2],s[3])),[r(183),e.EgUPm,e[r(1210)],e[r(1210)],e.EgUPm,e.Glfdt,d[0],d[1]].join("")}function h(a){let r=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}/[r(993)](a),d=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/.test(a);return s?e[r(1277)](u,a):d?e[r(1518)](x,a):"0000000000000000"+r(635)+r(635)}function x(a){let r=t,s="",d=[],f=0,g=0,w=!0,E=r(183);if(e[r(667)](a.indexOf("::"),-1)){let p=a[r(376)]("::");for(let N=0;N<p[r(1605)];N++){let F=p[N];if(F[r(603)](":")>0){let H=F[r(376)](":");w&&(f=H[r(1605)]),g+=H[r(1605)];for(let Z=0;e[r(576)](Z,H[r(1605)]);Z++)if(e[r(327)](4,H[Z][r(1605)])){let K=E[r(137)+"g"](0,e.gXpfV(4,H[Z][r(1605)])),Be=K[r(604)](H[Z]);d[r(969)](Be)}else d[r(969)](H[Z]);w=!1}else{if(e[r(327)](4,F[r(1605)])){let H=E.substring(0,e.gXpfV(4,F[r(1605)])),Z=H[r(604)](F);d.push(Z)}else d.push(F);w&&(f+=1),g+=1,w=!1}}let D="";for(let N=0;N<e[r(418)](8,g);N++)D=D[r(604)](E);for(let N=0;e[r(815)](N,d[r(1605)]);N++)e[r(672)](N,f)&&(s=s[r(604)](D)),s=s.concat(d[N]);return s}{let p=a[r(376)](":");for(let D=0;e[r(576)](D,p.length);D++){let N=p[D];if(e[r(478)](4,p[D][r(1605)])){let F=E[r(137)+"g"](0,4-p[D][r(1605)]),H=F[r(604)](N);s=s[r(604)](H)}else s=s[r(604)](N)}return s}}function m(a,r){let s=t;if(e[s(430)](s(916),s(161))){let d=a[s(754)];e[s(145)](void 0,d)&&(e.saTFn(pe,r,10),e[s(1309)](U,r,d));let f=a[s(889)];e[s(1544)](void 0,f)&&(e[s(701)]===e[s(701)]?(e[s(1309)](pe,r,18),U(r,f)):(this[s(949)](e[s(1353)],_0x489656),this[s(1477)+s(1319)]&&this[s(1477)+"eAck"](_0x138bc3)))}else{let d={Irbet:function(g,w){return e[s(1597)](g,w)},qtXBf:function(g,w){return e[s(266)](g,w)},RPRNh:function(g,w){return e[s(815)](g,w)},xfGbu:function(g,w){return e[s(1076)](g,w)},jokIv:function(g,w){return e[s(406)](g,w)},nQoTR:function(g,w){return e[s(1040)](g,w)},xuFLk:function(g,w){return e[s(929)](g,w)},hwRKz:function(g,w){return e[s(1026)](g,w)},fHQSC:function(g,w){return e.lOoPA(g,w)},KYmgF:function(g,w){return e.gYYpd(g,w)},wQlFo:function(g,w){return e.woXkw(g,w)},rHkvk:function(g,w){return e[s(643)](g,w)},qXVKa:function(g,w){return e[s(474)](g,w)}},f=4294967295;return function(g,w,E=!0){let p=s,D=(p(906)+p(786)+"3|6|0|9|4")[p(376)]("|"),N=0;for(;;){switch(D[N++]){case"0":if(d[p(167)](g[w++],128))return{value:E?f:d[p(169)](0,f),offset:w};continue;case"1":if(d.RPRNh(g[w++],128))return{value:E?f:d[p(297)](0,f),offset:w};continue;case"2":f=d[p(1527)](d[p(1409)](f,d[p(1422)](d[p(745)](127,g[w]),14)),0);continue;case"3":if(g[w++]<128)return{value:E?f:d[p(1409)](0,f),offset:w};continue;case"4":return{value:E?f:d[p(297)](0,f),offset:w};case"5":f=d.fHQSC(f,(127&g[w])<<7)>>>0;continue;case"6":f=d[p(297)](f,d[p(1422)](d.KYmgF(15,g[w]),28))>>>0;continue;case"7":if(d[p(866)](g[w++],128))return{value:E?f:0|f,offset:w};continue;case"8":f=d.jokIv(d.xfGbu(f,d[p(1528)](d.KYmgF(127,g[w]),21)),0);continue;case"9":if(d[p(377)](w+=5,g[p(1605)]))throw w=g[p(1605)],_0x32d879(w,10,g[p(1605)]);continue;case"10":f=d[p(207)](127&g[w],0);continue;case"11":if(g[w++]<128)return{value:E?f:d.fHQSC(0,f),offset:w};continue}break}}}}function _(a){let r=t,s={};e:for(;!e.ZIEwg($,a);){let d=e[r(1518)](xe,a);switch(e[r(155)](d,3)){case 0:break e;case 1:s[r(754)]=C(a,xe(a));break;case 2:s[r(889)]=e[r(1309)](C,a,xe(a));break;default:k(a,e[r(1026)](7,d))}}if(e[r(672)](void 0,s[r(754)]))throw new Error(r(534)+r(520)+r(1242)+"key");if(e[r(914)](void 0,s[r(889)]))throw new Error(e[r(329)]);return s}function S(a){let r=t,s=R();return y(a,s),e[r(966)](M,s)}function y(a,r){let s=t,d={QNAzB:function(We){return We()}},f=a[s(607)];e.TdDFy(void 0,f)&&(e[s(1e3)](pe,r,8),e[s(162)](pt,r,f));let g=a[s(127)];e.UjczL(void 0,g)&&(e[s(162)](pe,r,16),pt(r,g));let w=a[s(776)];e[s(430)](void 0,w)&&(pe(r,24),e[s(215)](pt,r,e.ZwJnn(P,w)));let E=a.method;E!==void 0&&(e.ntGyl(pe,r,32),e[s(1439)](pt,r,P(E)));let p=a[s(372)];if(p!==void 0)for(let We of p){e[s(1248)](pe,r,42);let sn=R();e[s(320)](m,We,sn),e[s(1248)](pe,r,sn[s(1299)]),e[s(855)](j,r,sn),e.zGaat(O,sn)}let D=a[s(1153)+s(1052)];e[s(1104)](void 0,D)&&(pe(r,50),e.ntGyl(U,r,D));let N=a["payloadT"+s(811)];e[s(327)](void 0,N)&&(pe(r,58),U(r,N));let F=a[s(450)];e.KZrcr(void 0,F)&&(e.TzTSD(pe,r,66),pe(r,F[s(1605)]),e[s(320)](oe,r,F));let H=a.LogIDNew;e[s(493)](void 0,H)&&(e[s(570)](e[s(1364)],e.uRtJn)?(pe(r,74),e.WXkSf(U,r,H)):(this[s(580)]=!1,_0x39c423(this[s(1375)+s(1198)+s(153)]),d[s(326)](_0x275a64)));let Z=a[s(542)+s(1101)];e[s(327)](void 0,Z)&&(e[s(1439)](pe,r,82),e[s(1439)](U,r,Z));let K=a[s(502)];e[s(570)](void 0,K)&&(e[s(1301)](pe,r,90),U(r,K));let Be=a[s(915)+"e"];Be!==void 0&&(e[s(583)](pe,r,96),e[s(162)](pt,r,e[s(966)](P,Be)))}function v(a){let r=t;return e[r(1518)](I,e[r(1277)](B,a))}function I(a){let r=t,s={};e:for(;!e.zGaat($,a);)if(e[r(532)]===e.WBCyx){let d=this[r(1022)][r(1357)+r(470)](this[r(1405)]);return _0x2b1fd0[r(1262)](d||"{}")[_0x3f81d3]}else{let d=e.ydFOD(xe,a);switch(d>>>3){case 0:break e;case 1:s[r(607)]=e[r(1324)](St,a,!0);break;case 2:s[r(127)]=e[r(491)](St,a,!0);break;case 3:s[r(776)]=xe(a);break;case 4:s.method=e.nxnWu(xe,a);break;case 5:{let f=e.ydFOD(A,a);(s[r(372)]||(s[r(372)]=[]))[r(969)](_(a)),a[r(1299)]=f;break}case 6:s[r(1153)+r(1052)]=C(a,xe(a));break;case 7:s[r(881)+r(811)]=C(a,e[r(975)](xe,a));break;case 8:s[r(450)]=e[r(824)](se,a,xe(a));break;case 9:s[r(947)]=e[r(225)](C,a,e[r(1277)](xe,a));break;case 10:s[r(542)+"ming"]=e[r(556)](C,a,e[r(1249)](xe,a));break;case 11:s[r(502)]=C(a,xe(a));break;case 12:s[r(915)+"e"]=e[r(893)](xe,a);break;default:e.ujjPd(k,a,e[r(792)](7,d))}}if(e[r(914)](void 0,s.SeqID))throw new Error("Missing "+r(520)+r(1242)+r(607));if(s.LogID===void 0)throw new Error(r(534)+r(520)+r(1242)+r(127));if(s.service===void 0)throw new Error(e[r(1154)]);if(s[r(190)]===void 0)throw new Error(e[r(594)]);return s}function A(a){let r=t,s=e.fvCbn(xe,a),d=a[r(1299)];return a[r(1299)]=e.SlmeM(a[r(587)],s),d}function k(a,r){let s=t;switch(r){case 0:for(;e[s(977)](128,e.dXQGk(te,a)););break;case 2:e[s(1131)](V,a,xe(a));break;case 5:V(a,4);break;case 1:e.RMXWo(V,a,8);break;default:throw new Error(e[s(1433)]+r)}}function P(a){let r=t;return e[r(184)](e[r(863)],e[r(863)])?this[r(726)]?this[r(726)].url:this[r(1389)]:(a|=0,{low:a,high:a>>31,unsigned:a>=0})}let b=[];function R(){let a=b.pop();return a?(a.offset=a.limit=0,a):{bytes:new Uint8Array(64),offset:0,limit:0}}function O(a){b[t(969)](a)}function B(a){let r=t,s={AKaKr:function(d,f){return e[J(1359)](d,f)},KQoHa:function(d,f){return d==f},bPXHC:e[r(533)],RaZhA:function(d,f){return e[r(478)](d,f)},UdxPK:e[r(1508)]};if(e[r(1191)](e[r(1462)],r(1560)))return{bytes:a,offset:0,limit:a[r(1605)]};{let{url:d}=s[r(771)](_0x5f9dce,{}),f=_0x202fb1[r(1455)](d)?d:s[r(1336)](s.bPXHC,typeof d)?[d]:[];_0x15cec6&&_0x2b9874[r(498)](this[r(1062)],_0x168bb6),f&&f.length?this[r(321)+"tManager"]=new _0x1b47ef(f,this[r(1062)][r(1025)+"es"]):this[r(321)+r(908)]?.[r(1141)+r(1598)+r(188)](),this[r(490)+"sCounter"]?.[r(524)+"nter"](this[r(1062)][r(972)+"Count"]),this["_readyCl"+r(342)]=!1,this[r(726)]&&s[r(617)](this[r(726)][r(268)+"te"],this.CLOSED)?this["_disconn"+r(120)](1e3,s[r(1216)],!0):(this._isInit=!0,this._connect())}}function M(a){let r=t,s={VirxE:e[r(142)],bHgGw:r(439)+"ediately"+r(890)+"ct"};if(e[r(1544)](e[r(901)],r(813))){let d=a[r(390)],f=a[r(1299)];return d.length===f?d:d[r(212)](0,f)}else{this[r(121)+"WebSocket"]();let d=_0x3b4843(s.VirxE,{message:s[r(1471)]});this[r(464)+"mediatelyReconnect"]&&this[r(464)+r(488)+r(1487)+"ct"](d)}}function V(a,r){let s=t,d={htPmD:function(f,g,w){return f(g,w)},PCcOo:e.FYljS};if(e.UEDhD(e.BAULj,e[s(1056)])){if(e[s(814)](a[s(587)],r)>a[s(1299)])throw new Error(e[s(143)]);a.offset+=r}else{let f="connect "+_0xfc9751+(s(795)+s(1451)+s(1382)+"ed");this[s(1071)+s(793)+s(1334)](d[s(394)](_0x723095,d.PCcOo,{message:f,code:_0x526ed3[s(177)+s(551)+"R"],error:_0x5ec247}));return}}function $(a){let r=t;return a[r(587)]>=a[r(1299)]}function re(a,r){let s=t,d=a[s(390)],f=a[s(587)],g=a[s(1299)],w=e[s(1015)](f,r);if(e[s(643)](w,d[s(1605)]))if(e[s(907)](e[s(1179)],e[s(572)]))e[s(215)](_0x3679d1,_0x28e549,96),_0x3c1eea(_0x4a397a,e[s(696)](_0x564807,_0x54d2d1));else{let E=new Uint8Array(e[s(1103)](2,w));E.set(d),a[s(390)]=E}return a[s(587)]=w,e[s(643)](w,g)&&(a[s(1299)]=w),f}function X(a,r){let s=t,d=a[s(587)];if(e.rDBBN(d+r,a[s(1299)]))throw new Error(s(1348)+s(501));return a[s(587)]+=r,d}function se(a,r){let s=t,d=e[s(491)](X,a,r);return a[s(390)][s(212)](d,e[s(1015)](d,r))}function oe(a,r){let s=t,d=re(a,r.length);a[s(390)][s(552)](r,d)}function C(a,r){let s=t,d={xVBdC:e[s(533)],uhlTD:function(D,N){return D instanceof N},Rxtys:function(D,N){return e[s(194)](D,N)},OnGLu:function(D,N){return e.JiXKp(D,N)},yvMPh:s(506)+s(1273)},f=e[s(1324)](X,a,r),g=String[s(1460)+s(1232)],w=a.bytes,E="\uFFFD",p="";for(let D=0;e[s(815)](D,r);D++){let N=w[D+f],F,H,Z,K;if(e[s(358)](e[s(513)](128,N),0))p+=e[s(893)](g,N);else if((224&N)===192)e[s(514)](D+1,r)?p+=E:(F=w[e[s(1015)](e.ygezF(D,f),1)],e[s(228)](192,F)!==128?p+=E:(K=e[s(205)](e[s(1384)](e[s(1026)](31,N),6),e.ZcjNR(63,F)),e[s(576)](K,128)?p+=E:(p+=g(K),D++)));else if(e[s(1234)](e.ZcjNR(240,N),224))if(e[s(1021)](e[s(729)](D,2),r))p+=E;else if(e[s(493)](s(355),e[s(1031)]))if(F=w[e.ygezF(e[s(1035)](D,f),1)],H=w[e.MISMj(e[s(586)](D,f),2)],e[s(1104)](e[s(365)](F|e[s(1596)](H,8),49344),32896))p+=E;else if(e.PCgPq(e[s(945)],e[s(482)]))if(K=e[s(712)](e[s(1327)](e[s(929)](e[s(365)](15,N),12),e[s(159)](e[s(1317)](63,F),6)),e[s(300)](63,H)),e.bMQlV(K,2048)||e[s(710)](K,55296)&&e[s(531)](K,57343))p+=E;else if(e[s(570)](e[s(883)],e[s(485)]))p+=e.Qnvbl(g,K),D+=2;else{let Be=this[s(810)],We=this[s(305)];return[Be>>>24,e[s(406)](Be,16)&255,e.ZcjNR(e[s(406)](Be,8),255),e.SdLiD(255,Be),e.FYFdh(We,24),e[s(344)](We>>>16,255),e.gYYpd(We>>>8,255),e[s(838)](255,We)]}else _0x3438b1=e.dptrq(_0x10d3a7,_0x94e695),e[s(1597)](_0x1e8f31,32)&&(_0xedf94a|=e[s(1065)](e.ASuvm(127,_0x3c1ed2),_0x7f2fa5)),_0x4f4d44+=7;else return d[s(138)]!=typeof _0x22fa8a&&(d.uhlTD(_0x371246,_0x13b772)||_0x3b1a68.buffer&&d[s(1187)](_0x2608b8[s(163)],_0x1758c1))||d[s(747)](s(463),typeof _0x3bade7)?"":(_0x508540.parse(_0x4f98cb),d[s(164)]);else e[s(232)](e[s(344)](248,N),240)?e.SlmeM(D,3)>=r?p+=E:(F=w[e[s(605)](e[s(819)](D,f),1)],H=w[e[s(1501)](D,f)+2],Z=w[e[s(612)](e[s(1233)](D,f),3)],e.wHMNc((e[s(1003)](F,e[s(1063)](H,8))|e.niRuE(Z,16))&12632256,8421504)?p+=E:(K=e[s(266)](e.caKXo(e[s(1596)](e[s(792)](7,N),18)|e.niRuE(e.TtAlZ(63,F),12),e[s(1030)](e[s(838)](63,H),6)),63&Z),e[s(576)](K,65536)||K>1114111?p+=E:(K-=65536,p+=g(e[s(1233)](e[s(1069)](K,10),55296),e[s(598)](1023&K,56320)),D+=3))):p+=E}return p}function U(a,r){let s=t;if(e[s(174)](e[s(548)],e.pgpCw)){let d=this[s(1335)+s(1498)].reduce((f,g)=>(f+=g&&g[s(241)+"th"]||0,f),0);return e[s(1233)](d,this[s(726)]?this[s(726)][s(411)+s(912)]:0)}else{let d=r.length,f=0;for(let E=0;e[s(737)](E,d);E++){let p=r[s(211)+"At"](E);p>=55296&&p<=56319&&e.UTtlE(e[s(1158)](E,1),d)&&(p=e[s(1255)](e[s(1468)](p,10)+r.charCodeAt(++E),56613888)),f+=e.hOWTQ(p,128)?1:p<2048?2:e[s(1597)](p,65536)?3:4}e.rIBrQ(pe,a,f);let g=e.SpuaS(re,a,f),w=a[s(390)];for(let E=0;e[s(815)](E,d);E++){let p=r[s(211)+"At"](E);if(e[s(710)](p,55296)&&e[s(1082)](p,56319)&&e.UTtlE(e.ofkgt(E,1),d)&&(p=e[s(214)](e[s(1075)](e[s(475)](p,10),r[s(211)+"At"](++E)),56613888)),p<128)w[g++]=p;else if(e[s(1109)](e[s(779)],e[s(627)]))e[s(737)](p,2048)?w[g++]=e.EUWjP(e[s(1454)](e[s(1492)](p,6),31),192):(e[s(1291)](p,65536)?w[g++]=e[s(1372)](e[s(887)](p,12),15)|224:(w[g++]=e[s(205)](e.Oslyr(p,18)&7,240),w[g++]=e[s(1069)](p,12)&63|128),w[g++]=e[s(1327)](e[s(363)](e.ZeQUW(p,6),63),128)),w[g++]=e[s(266)](63&p,128);else{let D=e.YRoYp(255,_0x49a854);e[s(433)](_0x5ce118,D,_0x358a63,e[s(598)](_0x816bce,_0x5b08ba)),_0x564150>>>=8,_0x4ce8ec--}}}}function j(a,r){let s=t,d=e.ajJpG(re,a,r[s(1299)]),f=a[s(390)],g=r[s(390)];for(let w=0,E=r.limit;e[s(1597)](w,E);w++)f[e.ibddT(w,d)]=g[w]}function te(a){return a[t(390)][X(a,1)]}function Qe(a,r){let s=t,d=e[s(173)](re,a,1);a[s(390)][d]=r}function xe(a){let r=t;if(e[r(507)]!==e[r(507)])this[r(580)]=!0,this._connect();else{let s=0,d=0,f;do f=e[r(925)](te,a),s<32&&(d|=(127&f)<<s),s+=7;while(128&f);return d}}function pe(a,r){let s=t;for(r>>>=0;e[s(1021)](r,128);)e[s(1356)](Qe,a,e[s(364)](e[s(459)](127,r),128)),r>>>=7;e.czefV(Qe,a,r)}function St(a,r){let s=t;if(e[s(1099)](e.CzbJL,s(139))){if(!this[s(1375)+"Lock"]){let d=e.lvGCe[s(376)]("|"),f=0;for(;;){switch(d[f++]){case"0":this[s(580)]=!0;continue;case"1":this._connect();continue;case"2":this[s(490)+"sCounter"]?.["resetCou"+s(223)]();continue;case"3":this[s(787)+s(342)]=!1;continue;case"4":this[s(321)+s(908)]?.[s(1141)+"pointCon"+s(188)]();continue}break}}}else{let d=0,f=0,g=0,w;return w=te(a),d=e.CfFeq(127,w),128&w&&(w=e[s(553)](te,a),d|=e[s(792)](127,w)<<7,128&w&&(w=e.znoeC(te,a),d|=e.IFZtu(e[s(513)](127,w),14),128&w&&(w=te(a),d|=e[s(452)](127&w,21),128&w&&(w=te(a),f=127&w,e.EFYLJ(128,w)&&(w=e.KWxpS(te,a),f|=(127&w)<<7,e.DlECW(128,w)&&(w=e[s(1096)](te,a),f|=e[s(1065)](e.FEJCD(127,w),14),128&w&&(w=e[s(696)](te,a),f|=e[s(1063)](e[s(911)](127,w),21),e[s(363)](128,w)&&(w=te(a),g=e[s(365)](127,w),128&w&&(w=e[s(1419)](te,a),g|=e[s(1266)](e.uoGee(127,w),7)))))))))),{low:e[s(1607)](d,f<<28),high:e.Qmotj(f>>>4,e.dAlmZ(g,24)),unsigned:r}}}function pt(a,r){let s=t;if(e[s(493)](e[s(865)],e.HMyaE)){let d=e[s(1124)](r.low,0),f=e.XRbFG(e[s(155)](r.low,28),r[s(810)]<<4)>>>0,g=r[s(810)]>>>24,w=e[s(1107)](0,g)?e[s(907)](0,f)?e[s(737)](d,16384)?e[s(1597)](d,128)?1:2:e[s(226)](d,2097152)?3:4:e[s(427)](f,16384)?e.bMQlV(f,128)?5:6:e.hOWTQ(f,2097152)?7:8:e[s(576)](g,128)?9:10,E=e[s(407)](re,a,w),p=a[s(390)];switch(w){case 10:p[e[s(1285)](E,9)]=e[s(1026)](e[s(474)](g,7),1);case 9:p[e[s(1164)](E,8)]=e.zyGEZ(9,w)?e[s(1168)](128,g):e[s(460)](127,g);case 8:p[e[s(1574)](E,7)]=e[s(1308)](8,w)?e.cvMnf(e[s(614)](f,21),128):e[s(247)](e[s(614)](f,21),127);case 7:p[e[s(1501)](E,6)]=e[s(1191)](7,w)?e[s(1076)](f>>>14,128):e[s(660)](e[s(1095)](f,14),127);case 6:p[e[s(1550)](E,5)]=w!==6?e[s(1586)](e[s(155)](f,7),128):e[s(1264)](e[s(406)](f,7),127);case 5:p[e[s(1083)](E,4)]=e.ixUJJ(5,w)?e[s(799)](128,f):e[s(337)](127,f);case 4:p[e.touvH(E,3)]=e[s(356)](4,w)?e[s(833)](e.uvaqP(d,21),128):e[s(838)](d>>>21,127);case 3:p[e[s(1501)](E,2)]=e[s(1104)](3,w)?e[s(663)](e[s(1095)](d,14),128):e[s(1095)](d,14)&127;case 2:p[e[s(1550)](E,1)]=e[s(478)](2,w)?e[s(940)](e.aDLku(d,7),128):e[s(1095)](d,7)&127;case 1:p[E]=e[s(331)](1,w)?e[s(773)](128,d):e[s(370)](127,d)}}else return this[s(670)+"ndpointT"+s(182)+"t"]=1,this[s(944)+s(437)]++,this[s(129)+"s"][this[s(944)+s(437)]]}function en(a){return v(a)}function zt(a){return e[t(1135)](S,a)}let tn=65536,Yr=e[t(1090)],_e=tn*tn,Ae=e[t(844)](_e,_e),tr=Ae/2,De=String[t(132)+"e"].charCodeAt;class fe{constructor(r,s,d){let f=t;this[f(830)]=!0,this[f(305)]=e[f(288)](0,r),this[f(810)]=e[f(1531)](0,s),this[f(932)]=!!d}static[t(830)](r){let s=t;if(e.lETvD(e[s(1600)],e[s(1600)]))return r&&e[s(672)](!0,r[s(830)]);this[s(1197)+"lFlush"]()}static fromBits(r,s,d){return new fe(r,s,d)}static fromBytes(r,s,d){let f=t;return d?fe[f(780)+f(788)](r,s):fe["fromByte"+f(322)](r,s)}static[t(780)+t(788)](r,s){let d=t;return new fe(e[d(671)](e[d(1564)](r[0],e[d(1063)](r[1],8)),e[d(1063)](r[2],16))|r[3]<<24,e[d(1411)](e[d(1411)](e[d(1111)](r[4],e[d(452)](r[5],8)),e.kFoLZ(r[6],16)),e[d(118)](r[7],24)),s)}static["fromByte"+t(322)](r,s){let d=t;return new fe(e[d(266)](e.Ekudw(e[d(618)](r[4],24),e[d(1274)](r[5],16))|e[d(600)](r[6],8),r[7]),e[d(1003)](e[d(1138)](e[d(620)](r[0],24),e[d(618)](r[1],16))|e[d(1115)](r[2],8),r[3]),s)}static fromHash(r){let s=t,d={qxqtt:function(f,g,w){return e.CrlOO(f,g,w)},kHFrS:function(f,g){return f|g},whhGq:function(f,g){return e[J(1593)](f,g)}};if(e[s(1170)](s(149),s(149)))return e[s(633)](r,Yr)?ed:new fe(e[s(406)](e[s(172)](e[s(1521)](e[s(1558)](De[s(1089)](r,0),e[s(1046)](De[s(1089)](r,1),8)),e[s(618)](De[s(1089)](r,2),16)),e.Ktedx(De[s(1089)](r,3),24)),0),e[s(712)](e[s(875)](e[s(712)](De.call(r,4),e[s(618)](De[s(1089)](r,5),8)),e[s(714)](De.call(r,6),16)),De[s(1089)](r,7)<<24)>>>0,!0);PaNnwG[s(286)](_0x4702a1,_0xa1cd1a,PaNnwG[s(1526)](PaNnwG.whhGq(127,_0x39b464),128)),_0x3a71c6>>>=7}[t(495)](){let r=t;return String["fromChar"+r(1232)](e[r(1253)](255,this[r(305)]),e.ZxxKm(e[r(474)](this[r(305)],8),255),e[r(300)](this[r(305)]>>>16,255),e[r(1095)](this[r(305)],24),e[r(1175)](255,this[r(810)]),e[r(785)](e[r(806)](this[r(810)],8),255),e[r(1095)](this[r(810)],16)&255,e[r(1095)](this[r(810)],24))}static fromNumber(r,s=!0){let d=t;if(e[d(1438)](isNaN,r))return s?Pp:ed;if(s){if(e[d(566)](r,Ae))return Op}else{if(r<=-tr)return Np;if(e[d(514)](e[d(144)](r,1),tr))return Dp}return fe.fromBits(e[d(1531)](r%_e,0),e[d(1505)](r,_e)|0,s)}[t(882)](){let r=t;return this.unsigned?e.UHTag(e[r(1103)](e[r(474)](this[r(810)],0),_e),this[r(305)]>>>0):e[r(1603)](e[r(336)](this[r(810)],_e),this[r(305)]>>>0)}[t(1379)](){let r=t;return e[r(914)](0,this.high)&&e[r(358)](0,this.low)}[t(575)](r){let s=t;fe.isLong(r)||(r=fe[s(1079)+"er"](r));let d=e[s(567)](this.high,16),f=65535&this[s(810)],g=e[s(474)](this.low,16),w=65535&this.low,E=e[s(406)](r[s(810)],16),p=65535&r.high,D=e.bWMpW(r[s(305)],16),N=e[s(1354)](65535,r.low),F=0,H=0,Z=0,K=0;return K+=e[s(598)](w,N),Z+=e[s(698)](K,16),K&=65535,Z+=g+D,H+=Z>>>16,Z&=65535,H+=e[s(1603)](f,p),F+=H>>>16,H&=65535,F+=e[s(352)](d,E),F&=65535,fe[s(275)](e[s(663)](e[s(637)](Z,16),K),e.CIwxX(e[s(620)](F,16),H),this.unsigned)}[t(1385)](r){let s=t;if(s(1223)!==e.ObhQF)return fe.isLong(r)||(r=fe.fromNumber(r)),e[s(1339)](this[s(932)],r.unsigned)&&this[s(810)]>>>31===1&&e.qMtIj(r.high>>>31,1)?!1:this.high===r[s(810)]&&e.PrymK(this[s(305)],r[s(305)]);{let{initReconnectInterval:d,maxReconnectInterval:f,reconnectIntervalGrowFactor:g}=this[s(1062)],w=e[s(336)](d,_0x355bd6[s(1580)](g,e.gXpfV(_0x2d44ae,1)));return e[s(522)](w,f)?f:w}}addOne(){let r=t;return e.yHQwV(-1,this[r(305)])&&e[r(1538)](-1,this.high)?fe[r(275)](0,0,this[r(932)]):e[r(1100)](-1,this.low)?fe[r(275)](0,e[r(1501)](this.high,1),this[r(932)]):fe.fromBits(e[r(311)](this.low,1),this[r(810)],this.unsigned)}[t(630)](r){return r?this[t(1512)+"E"]():this.toBytesBE()}[t(1512)+"E"](){let r=t,s=this[r(810)],d=this.low;return[e[r(218)](255,d),e[r(920)](d>>>8,255),e[r(255)](e[r(1284)](d,16),255),e.iVQTq(d,24),e[r(247)](255,s),e[r(300)](e[r(614)](s,8),255),e[r(233)](e[r(1125)](s,16),255),e[r(155)](s,24)]}[t(271)+"E"](){let r=t;if(e[r(184)](e[r(958)],e[r(1206)])){let s=this[r(810)],d=this[r(305)];return[e[r(704)](s,24),e[r(455)](e[r(1284)](s,16),255),e[r(595)](e.eHgmE(s,8),255),e[r(1253)](255,s),e[r(1284)](d,24),d>>>16&255,e[r(339)](e[r(549)](d,8),255),e.zCgkx(255,d)]}else this[r(949)](r(515),e[r(1442)](_0x2bf2fa,e[r(1136)],{..._0x21178d}))}}let ed=new fe(0,0,!1),Pp=new fe(0,0,!0),Dp=fe[t(275)](-1,2147483647,!1),Op=fe[t(275)](-1,-1,!0),Np=fe[t(275)](0,-2147483648,!1);var nn=(function(a){let r=t,s=e[r(1599)][r(376)]("|"),d=0;for(;;){switch(s[d++]){case"0":a[a[e[r(1448)]]=5002]=e[r(1448)];continue;case"1":a[a[r(177)+r(551)+"R"]=5003]=e[r(471)];continue;case"2":a[a[e[r(296)]]=5005]=e[r(296)];continue;case"3":a[a[e[r(1447)]]=5004]=r(530)+r(325);continue;case"4":a[a[e.IUyvV]=5001]=e.IUyvV;continue;case"5":return a}break}})({});class nr{constructor(r){let s=t;this[s(1239)]=r,this[s(994)]=null}}class td extends nr{constructor(r,s){let d=t;super(r),this[d(515)]=s&&s[d(515)]||null}}class nd extends nr{constructor(r,s){let d=t;super(r),this[d(417)]=s&&s[d(417)]||null,this[d(1395)]=s&&s[d(1395)]||0,this.filename=s&&s[d(1424)]||"",this[d(1559)]=s&&s[d(1559)]||0,this.message=s&&s[d(515)]||"",this[d(721)]=s&&s.code||5001}}class rd extends nr{constructor(r,s){let d=t,f={kUihc:function(g,w){return e.HtSQq(g,w)},lDWpB:function(g,w){return e[J(887)](g,w)},DUKXC:function(g,w){return e.gtcBP(g,w)},CqnlD:function(g,w){return e[J(381)](g,w)}};if(e[d(117)]!==e[d(673)]){let g=e.wuGqE.split("|"),w=0;for(;;){switch(g[w++]){case"0":super(r);continue;case"1":this[d(1018)]=s&&s.reason||"";continue;case"2":this[d(721)]=s&&s[d(721)]||0;continue;case"3":this[d(1294)+d(1482)]=s&&s.willReconnect||!1;continue;case"4":this.wasClean=s&&s[d(315)]||!1;continue}break}}else _0x273629[_0x391505++]=eHNoTV[d(1520)](eHNoTV[d(1394)](_0x1f05bb,18),7)|240,_0x5cbac9[_0x4218bd++]=eHNoTV.DUKXC(eHNoTV[d(252)](_0x5a2265>>12,63),128)}}class id extends nr{constructor(r,s){let d=t;super(r),this[d(798)]=s&&s[d(798)]||null}}class sd extends id{constructor(r,s){let d=t;super(r),this[d(798)]=s&&s[d(798)]||null,this[d(515)]=s&&s[d(515)]||null}}class od extends nr{constructor(r,s){let d=t;super(r),this[d(798)]=s&&s[d(798)]||null}}function ct(a,{message:r,code:s,error:d}){return new nd(a,{message:r,code:s,error:d})}function gt(a,{code:r,reason:s,wasClean:d,willReconnect:f}){return new rd(a,{code:r,reason:s,wasClean:d,willReconnect:f})}function ad(a,{data:r,message:s}){return new sd(a,{data:r,message:s})}function cd(a,{data:r}){return new od(a,{data:r})}function ha(a,{message:r}){return new td(a,{message:r})}class ld{constructor(r,s){let d=t;this.endpoints=r,this[d(1025)+"es"]=s,this[d(944)+d(437)]=0,this[d(670)+d(783)+d(182)+"t"]=0}["resetEnd"+t(1598)+t(188)](){let r=t;this[r(944)+r(437)]=0,this[r(670)+r(783)+r(182)+"t"]=0}resetTries(){let r=t;this[r(670)+r(783)+"riesCount"]=0}getCurrentEndpoint(){let r=t;return this.endpoints[this[r(944)+r(437)]]}[t(346)+"ntEndpointTriesC"+t(258)](){let r=t;return this[r(670)+r(783)+r(182)+"t"]}["checkRea"+t(434)+"es"](){let r=t;return!!(e[r(261)](this[r(944)+r(437)],this[r(129)+"s"][r(1605)])||e[r(1107)](this[r(944)+"ndex"],this[r(129)+"s"][r(1605)]-1)&&this[r(670)+r(783)+r(182)+"t"]===this[r(1025)+"es"])}["checkCur"+t(180)+t(1118)+"hedMaxRe"+t(880)](){let r=t;return this[r(944)+r(437)]==this[r(129)+"s"][r(1605)]?!0:e[r(643)](this[r(670)+r(783)+r(182)+"t"],this.maxRetries)}[t(1036)+t(1145)+t(1204)+t(675)+"unt"](){let r=t;return this["currentEndpointT"+r(182)+"t"]=1,this[r(944)+"ndex"]++,this[r(129)+"s"][this["currentI"+r(437)]]}[t(346)+t(1215)+t(1241)+t(715)](){let r=t;return this[r(670)+"ndpointT"+r(182)+"t"]++,this[r(346)+"ntEndpoint"]()}}let rr=(e.okyWj(e[t(306)],typeof globalThis)&&e[t(951)]===globalThis[t(319)+t(757)][t(1257)]||e[t(306)]!=typeof window&&e.Rjqte===window["construc"+t(757)][t(1257)])&&e[t(822)](e.FGPfd,typeof document),Pn=e[t(1386)](t(284)+"d",typeof globalThis)&&(e[t(826)](e[t(740)],globalThis["construc"+t(757)][t(1257)])||e[t(264)](t(412)+t(1006)+t(384)+"pe",globalThis["construc"+t(757)].name))&&e.DAYyT(e[t(306)],typeof tt),Xr=(e[t(136)](t(284)+"d",typeof globalThis)&&e[t(740)]===globalThis[t(319)+t(757)][t(1257)]||t(284)+"d"==typeof globalThis||e[t(1208)](e[t(306)],typeof globalThis)&&!!globalThis.WeixinJSBridge)&&e[t(389)](e[t(306)],typeof wx),Qr=e.ONqex(e[t(306)],typeof globalThis)&&(e[t(1231)](e[t(200)],globalThis["construc"+t(757)][t(1257)])||e[t(385)](e.XkgNU,globalThis["construc"+t(757)][t(1257)])||e.GpfeB(e.uxQeG,globalThis[t(319)+"tor"].name))&&e[t(147)](e[t(306)],typeof self),Lp=e[t(1562)](e.FGPfd,typeof globalThis)&&e[t(597)](e[t(740)],globalThis[t(319)+t(757)].name)&&e.ELdRi(e[t(306)],typeof global)&&e[t(308)](t(1566),global[t(319)+"tor"][t(1257)])&&e[t(606)](e[t(306)],typeof process)&&!!process[t(1207)];class xa{constructor(){let r=t;this[r(578)+"rs"]={}}emit(r,...s){let d=t,f=this[d(578)+"rs"][r];if(f)f[d(1399)]()[d(1157)](g=>g.fn[d(1268)](g[d(1446)],s));else if(e[d(123)](d(417),r)&&!this[d(1556)]){let g=s[d(1605)]&&s[0];if(e[d(194)](g,Error))throw g;let w=new Error(e[d(1281)](e[d(869)],g?e[d(676)](e[d(1205)](" (",g[d(515)]),")"):""));throw w[d(276)]=g,g}return this}[t(573)](r,s){let d=t;if(e[d(991)](void 0,r))this._listeners={};else if(e[d(646)](void 0,s))this._listeners[r]=null;else{let f=this[d(578)+"rs"][r];if(f)for(let g=0;e[d(226)](g,f[d(1605)]);)e[d(896)](f[g].fn,s)?f[d(1039)](g,1):++g}return this}on(r,s,d){let f=t;return(this[f(578)+"rs"][r]||(this[f(578)+"rs"][r]=[]))[f(969)]({fn:s,ctx:d||this}),this}}class Mp extends xa{[t(265)+t(1129)+"age"](r){let s=t;return s(351)===e[s(1293)]?_0x31faf4[s(1610)+"oreNames"]||_0x5b0e62.get(_0x472baa):r[s(403)]||r.errNo?(s(287)+" "+(r[s(403)]||"")+s(185)+(r.errNo||""))[s(361)]():JSON[s(718)+"y"](r)}constructor(r,s,d){let f=t;super(),this[f(624)]=null,Xr&&wx["connectS"+f(396)]&&(this[f(624)]=wx[f(1211)+f(396)]({url:r,protocols:s,header:d,fail:this[f(196)+f(113)+f(1097)][f(1085)](this),success:this["_createS"+f(939)+f(1306)+f(1012)][f(1085)](this)})),Pn&&tt[f(1211)+f(396)]&&(this._socket=tt.connectSocket({url:r,protocols:s,header:d,fail:this["_createS"+f(113)+f(1097)][f(1085)](this),success:this[f(196)+f(939)+f(1306)+f(1012)][f(1085)](this)}))}[t(196)+t(939)+t(1306)+t(1012)](){Promise.resolve().then(()=>{let r=J;this[r(859)+r(249)]()})}[t(196)+t(113)+t(1097)](r){let s=t;Promise[s(1009)]()[s(1534)](()=>{let d=s,f=e.PvGaV(ct,e[d(179)],{message:this["_formatE"+d(1129)+"age"](r)});this[d(949)](e.FYljS,f);let g=e.UsiIn(gt,e[d(760)],{reason:this[d(265)+d(1129)+d(494)](r)});this[d(949)](d(695),g)})}[t(859)+t(249)](){let r=t,s={czJGd:e.ComOy,pxuIT:function(d,f,g){return e[J(146)](d,f,g)},cqzWq:"message",HbjmC:function(d,f,g){return e[J(1309)](d,f,g)},OQUkX:e[r(179)]};this[r(624)][r(1214)](d=>{let f=r;this[f(949)](s.czJGd,s[f(348)](cd,s[f(1352)],{...d,data:d.errMsg||""}))}),this[r(624)][r(700)](d=>{let f=r,g={kwMZW:function(w,E){return e[J(1387)](w,E)}};if(e[f(878)](f(1467),e[f(1023)])){let w={IMSHH:function(E,p){let D=f;return jPcYhf[D(221)](E,p)},JhnBv:function(E,p){return E(p)}};return function(E,...p){let D=f,N=_0x581e74[D(1089)](w[D(1320)](_0x39c7ec,this),E,...p);return _0x4e85bf[D(552)](N,E[D(621)]?E[D(621)]():[E]),w[D(496)](_0x2395fb,N)}}else this.emit(e[f(760)],e.tuAKD(gt,e[f(760)],{...d}))}),this._socket[r(1292)+"e"](d=>{let f=r;this[f(949)](s.cqzWq,s.HbjmC(ad,f(515),{...d}))}),this._socket[r(1496)](d=>{let f=r;this[f(949)](s[f(1314)],s[f(935)](ct,s[f(1314)],{...d,message:d[f(403)]||""}))})}send(r){let s=t;if(e[s(907)](s(219),s(219)))if(e[s(933)](r,Uint8Array)){let d=r[s(163)][s(1399)](r[s(625)+"et"],r[s(241)+"th"]+r[s(625)+"et"]);this[s(624)]&&this[s(624)][s(602)]({data:d,fail:f=>{let g=s;this[g(949)](g(417),e[g(989)](ct,e[g(179)],{message:this[g(265)+"rrorMessage"](f)}))}})}else this._socket&&this[s(624)][s(602)]({data:r,fail:d=>{let f=s;if(e.UjczL(e[f(1587)],e.oEdEG))return this._qosDB["clearSto"+f(379)]();this.emit(e[f(179)],e[f(854)](ct,e.FYljS,{message:this[f(265)+f(1129)+f(494)](d)}))}});else return _0x5d7b82[s(1610)+s(948)][1]?void 0:_0x1fc24a["objectSt"+s(689)](_0x5a0fce[s(1610)+s(948)][0])}[t(695)](r,s){let d=t;this._socket&&this[d(624)][d(695)]({code:r,reason:s})}[t(796)+t(1579)](r,s){this.on(r,s)}["removeEv"+t(469)+t(1588)](r,s){this[t(573)](r,s)}get readyState(){return this._socket.readyState}get[t(126)+"pe"](){let r=t;return this._socket[r(126)+"pe"]}set[t(126)+"pe"](r){}get[t(528)](){let r=t;return this[r(624)][r(528)]}get protocol(){let r=t,s={XddIg:e[r(179)]};if(e[r(898)]!==e.mPHdW)_0x3da5a0[r(992)+"entListe"+r(1588)](r(759),_0x51d5f4),_0x5697cb[r(992)+"entListe"+r(1588)](XNmHog[r(1295)],_0xf98a5d);else return this._socket[r(1429)]}get[t(1279)+"ns"](){let r=t;return this[r(624)][r(1279)+"ns"]}get[t(411)+"Amount"](){return 0}}function Bp(a,r){let s=t;if(r)return new r(a[s(528)],a.protocol);if(Xr||Pn)return new Mp(a[s(528)],a[s(1429)],a[s(372)]);if(e.QVRSJ(rr,Qr)&&e[s(306)]!=typeof WebSocket&&WebSocket)return new WebSocket(a[s(528)],a[s(1429)+"s"])}function Fp(a){let r=t,s={aAToe:function(d,f,g,w,E){return e[J(816)](d,f,g,w,E)},EzLju:function(d,f){return e[J(1066)](d,f)}};if(e[r(1033)](r(950),r(950)))qoDwEv[r(848)](_0x25c71b,qoDwEv[r(955)](_0x163d4f,_0x468296[r(1112)]),_0x3e9c55[r(472)+"on"],_0x49aee7[r(592)+"on"],_0x1b0b6e(_0x3fae38[r(921)+"ion"]));else{let d="0|3|2|1|4".split("|"),f=0;for(;;){switch(d[f++]){case"0":if(a)return!0;continue;case"1":if(e[r(1490)](rr,Qr)&&e.FGPfd!=typeof WebSocket&&WebSocket)return!0;continue;case"2":if(Pn&&tt[r(1211)+r(396)])return!0;continue;case"3":if(Xr&&wx[r(1211)+r(396)])return!0;continue;case"4":return!1}break}}}function dd(a,r,s){let d=-1;async function f(g){let w=J;return e[w(531)](g,d)?Promise[w(652)](new Error(e[w(1485)])):(d=g,e[w(123)](g,s[w(1605)])?Promise[w(1009)]():s[g][w(1085)](a)(r,f[w(1085)](null,e.lYlSc(g,1))))}f(0)}function ud(a){let r=t,s=0,d=0;for(let f=0;e.EZILO(f,a[r(1605)]);++f)d=a[r(211)+"At"](f),e[r(829)](d,128)?s+=1:e[r(615)](d,2048)?s+=2:e[r(914)](e.MJjxH(64512,d),55296)&&e[r(1381)](64512,a[r(211)+"At"](e[r(1035)](f,1)))===56320?(++f,s+=4):s+=3;return s}function fd(a,r,s){let d=t;if(e.HfmAC(e[d(214)](s,r),1))return"";let f="";for(let g=r;g<s;){let w=a[g++];if(e[d(531)](w,127))f+=String[d(1460)+d(1232)](w);else if(e.Ticvi(w,192)&&e.rKmHH(w,224))f+=String[d(1460)+d(1232)](e.PGBXL(e[d(1030)](31&w,6),e[d(1272)](63,a[g++])));else if(e[d(514)](w,224)&&e[d(669)](w,240))f+=String[d(1460)+d(1232)](e[d(773)](e[d(1529)](e[d(118)](e.EvxaM(15,w),12),e.PwLKQ(e[d(513)](63,a[g++]),6)),e[d(228)](63,a[g++])));else if(e.tcIrm(w,240)){let E=e[d(547)](e.TuGwC(e[d(940)](e[d(833)](e[d(1468)](7&w,18),e[d(1369)](63,a[g++])<<12),e[d(856)](63&a[g++],6)),e[d(366)](63,a[g++])),65536);f+=String[d(1460)+"Code"](e.UHTag(55296,e[d(784)](E,10))),f+=String[d(1460)+d(1232)](e[d(1083)](56320,1023&E))}}return f}function pa(a,r,s){let d=t,f=s,g,w;for(let E=0;e.MikET(E,a.length);++E)if(g=a[d(211)+"At"](E),e.HfmAC(g,128))r[s++]=g;else if(e[d(1161)](g,2048))r[s++]=e[d(663)](e[d(1492)](g,6),192),r[s++]=e.xjdAR(e[d(247)](63,g),128);else if(e[d(582)](64512,g)===55296&&e[d(308)](e[d(370)](64512,w=a[d(211)+"At"](e[d(729)](E,1))),56320)){let p=e.NvFjX[d(376)]("|"),D=0;for(;;){switch(p[D++]){case"0":r[s++]=e.jFyFh(e[d(1058)](g>>12,63),128);continue;case"1":r[s++]=e[d(1091)](e[d(1453)](e[d(923)](g,6),63),128);continue;case"2":r[s++]=e.TuGwC(e.ZMNyL(g,18),240);continue;case"3":++E;continue;case"4":g=e[d(1270)](e[d(1281)](65536,e.gMXmZ(e[d(199)](1023,g),10)),1023&w);continue;case"5":r[s++]=e[d(1037)](63,g)|128;continue}break}}else r[s++]=e.nUHnO(e[d(608)](g,12),224),r[s++]=e[d(1059)](e.iERUD(e[d(1492)](g,6),63),128),r[s++]=e[d(1571)](e[d(484)](63,g),128);return e[d(1604)](s,f)}async function hd(a){let r=t;if(e[r(533)]==typeof a){let s=new Uint8Array(e[r(1410)](ud,a));return pa(a,s,0),s}return a instanceof ArrayBuffer?new Uint8Array(a):new Uint8Array(a[r(163)],a[r(625)+"et"],a[r(241)+"th"])}function zp(a){let r=t,s={CLwzf:function(d,f){return e[J(1149)](d,f)},DJQVW:e[r(306)],nvyOR:e.NJXPH};if(e[r(1152)]===e[r(1152)])try{return e[r(541)](e.RoPpL,typeof a)&&(e[r(194)](a,ArrayBuffer)||a[r(163)]&&e[r(877)](a[r(163)],ArrayBuffer))||r(463)!=typeof a?"":(JSON[r(1262)](a),e.cKtTE)}catch{return e[r(1050)](e.RoPpL,typeof a)?e[r(1606)]:""}else AVDrkW.CLwzf(AVDrkW[r(1290)],typeof _0x5d11a6)&&_0x3d7e9f[r(1347)+"Tag"]&&_0x120881[r(1140)+r(562)](_0x9f2dbb,_0x5e357c[r(1347)+r(1054)],{value:AVDrkW[r(314)]}),_0x5e3b8f[r(1140)+r(562)](_0x36236e,r(885)+"le",{value:!0})}let Up=(a,r)=>{switch(a){case e.wzQoD:case e.FoCyq:return{["x-use-"+a]:1,"x-tt-env":r};default:return{}}};class Gp{constructor(r){let s=t;this[s(589)+"ount"]=r,this[s(748)]=0}[t(679)](){this.count++}[t(805)+t(380)+"nt"](){let r=t;return this[r(748)]>=this[r(589)+"ount"]}[t(524)+t(223)](r=0){let s=t;this["maxLossC"+s(258)]=r,this[s(748)]=0}}async function qp(a){let r=t;if(e[r(480)]==="VdryP")lLLSDy.KbhHq(_0x48ebc6,_0x13f413)&&_0x5266e1.set(_0x2f7333,_0x147167);else return new Promise(s=>{let d=r,f={YlBRU:function(g,w,E){return e[J(162)](g,w,E)},xJUJA:function(g,w){return e[J(430)](g,w)},WKdAa:d(201),HBgZJ:e.bCDqb};if(e[d(1104)](e.vWOSe,e[d(1271)])){if(!rr)return s(e[d(1522)]);try{let g=document["createEl"+d(313)]("script");window[d(1237)+d(777)]=w=>{let E=d;f[E(1117)]("AoSUe",f[E(550)])?(TavjMQ.YlBRU(_0xbd6605,_0x4fe695,82),TavjMQ.YlBRU(_0x2f9ad1,_0x58e77b,_0x7f1566)):(document[E(892)]["removeCh"+E(1497)](g),window[E(1237)+E(777)]=void 0,s(w&&w.msg||f[E(386)]))},g[d(1239)]=d(1068)+d(1469),g[d(874)]=a[d(1070)](/^ws/,d(317))+(d(1055)+"ack=frontierJSONP");try{document[d(892)][d(974)+d(1497)](g)}catch{document[d(892)][d(565)+d(1497)](g)}}catch{window[d(1237)+d(777)]=void 0,e[d(642)](s,d(1408)+d(1018))}}else{let g=TavjMQ[d(692)](_0x3dd193,_0x16c6e3,1);_0x256bf8[d(390)][g]=_0x457e5e}})}function rn(a,r,s){let d=t;if(e.pvpHB(e[d(1287)],e[d(1236)])){let f={vqHXQ:function(g,w){let E=d;return lLLSDy[E(1449)](g,w)}};return function(...g){let w=d;return _0x3b284f[w(1268)](f.vqHXQ(_0x5b40f,this),g),f[w(1017)](_0x4f0a34,_0x2a78e8[w(1028)](this))}}else return!!a?.[d(254)](f=>f[d(754)]===r&&f[d(889)]===s)}function ir(a,r){let s=t;return a?.find(d=>d.key===r)?.[s(889)]}let ga=null;async function Hp(){let a=t;return ga||(ga=Promise.resolve()[a(1534)](Mt.bind(Mt,e[a(538)]))),ga}class jp extends xa{constructor(r,s){let d=t,f={dcJnz:e[d(1413)],MyHon:function(g,w,E,p){return e[d(433)](g,w,E,p)},glyQR:e[d(453)],qKjZr:e[d(769)],xMYFP:e[d(1259)],KGRvN:e[d(1406)],EAUhO:function(g,w,E,p){return g(w,E,p)},WdtjR:function(g,w,E,p){return e[d(250)](g,w,E,p)},cMKlE:"curvalue"};if(e[d(230)](e[d(797)],e[d(797)])){let g=f[d(222)][d(376)]("|"),w=0;for(;;){switch(g[w++]){case"0":_0x58ef41=f.MyHon(_0x45b45a,_0xa484bc[d(1307)+"ame"],_0x16785e,_0x3e6f09);continue;case"1":_0x1e81ab[d(1217)](f[d(191)],_0x2043ed);continue;case"2":_0x51077c[d(1217)](f.qKjZr,_0x11a553);continue;case"3":_0x202c67[d(1217)]("cursor.s"+d(812),_0x1c69c2,_0x52165f[d(776)]);continue;case"4":_0xea1b5b[d(1217)](f[d(644)],_0x3806e3);continue;case"5":_0x56637b[d(1217)](f[d(481)],_0x5e541e);continue;case"6":_0x41b7e7=f[d(414)](_0x1e59bc,_0x12d0be,_0x24b0f1,_0x876b52[d(776)]||0);continue;case"7":_0x22d5d5=_0x3d6967(0,_0x55b5f4,_0x270076);continue;case"8":_0x1ca4c8=f[d(1286)](_0x1869c9,_0x4984a1[d(1079)+"er"](_0x31afc1[d(312)]||_0x4b724f),_0x3ec190,_0xa8894b);continue;case"9":_0x40fba1=f[d(662)](_0x2305cd,_0x57ed05[_0x35be6e[d(1307)+"ame"]],_0x36a53a,_0x23cc74);continue;case"10":_0x61c622[d(1217)](f[d(274)],_0x55279b);continue}break}}else super(),this[d(165)]=r,this[d(1426)]=s,this[d(1022)]=void 0,this[d(1002)+d(775)]=null}async[t(717)](){await this._init()}async _init(){let r=t,s={pTXqK:function(d,f){return e[J(1547)](d,f)},HqHcO:"YBQKl",XCmXW:function(d,f){return e.irmae(d,f)},NZVZw:function(d,f){return e[J(943)](d,f)},uBXXQ:function(d,f){return d<<f},JAyRK:e[r(518)],GzGUt:function(d){return e[r(1128)](d)},OpyKS:function(d,f){return d&f},vVYPz:function(d,f){return e[r(272)](d,f)},ecWvb:function(d,f){return e.NZJGU(d,f)},wcFoV:function(d,f){return d<=f}};if(e.oIbqy(e[r(432)],e[r(432)])){if(this[r(1022)])return;if(this[r(1002)+"mise"])return this[r(1002)+r(775)];try{if(e[r(756)]!==e[r(112)]){let d=this[r(165)],f=this[r(1426)];this[r(1002)+"mise"]=(async()=>{let g=r,w={uwkzE:function(E,p){return s[J(641)](E,p)},oaAhK:function(E,p){return E<<p},mtdHi:function(E,p){return E&p},JTWdS:function(E,p){return s[J(235)](E,p)},aNZgK:function(E,p){return s[J(699)](E,p)}};if(s[g(114)](s.JAyRK,s.JAyRK)){let{openDB:E}=await s[g(1038)](Hp);this[g(1022)]=await E(g(1237)+"_"+d,1,{upgrade(p){let D=g;s[D(114)](s[D(693)],D(817))?p[D(510)+D(192)+"e"](d,{keyPath:f}):(w[D(1569)](_0x7e9e22,this[D(1197)+D(1225)+"Id"]),this["_interva"+D(1225)+"Id"]=_0x3148f6(()=>{let N=D;this[N(928)+N(1594)]()},this[D(1197)+"l"]))}})}else _0x312d94=vsTgWv[g(1569)](_0x543102,_0x17a088),_0x522aaf|=vsTgWv[g(526)](vsTgWv[g(1368)](127,_0x12b1ef),21),vsTgWv[g(1313)](128,_0x53fd60)&&(_0x15bbd4=_0x43f434(_0x25ded6),_0x309b61=vsTgWv[g(1313)](127,_0x2301ad),128&_0xb1a30f&&(_0x28196e=vsTgWv[g(1569)](_0x59985b,_0x18e119),_0x295eaa|=vsTgWv[g(260)](vsTgWv[g(1313)](127,_0x4ebc14),7)))})(),await this["_initPro"+r(775)]}else _0x2bdeb5=lZawSe[r(699)](lZawSe[r(235)](15,_0x23c66e),12)|lZawSe[r(1464)](63,_0x5dbf8d)<<6|63&_0x6a88b0,lZawSe[r(536)](_0x327e3c,2048)||lZawSe[r(295)](_0x491fb7,55296)&&lZawSe[r(1346)](_0x544287,57343)?_0x13a0c9+=_0x24b163:(_0xf7593f+=_0x52ff52(_0x2f864e),_0x31e677+=2)}catch(d){console[r(1217)](d)}finally{this[r(1002)+r(775)]=null}}else this[r(1007)]=_0x589c12,this[r(130)]=_0x4e294e,this[r(1022)]=_0x39d17e}async get(r){let s=t;try{return await this[s(1525)](),this[s(1022)]?.[s(1028)](this[s(165)],r)}catch(d){if(e.PrymK(e[s(393)],"VxeoA"))return;console[s(1217)](d)}}async[t(552)](r,s){let d=t;return await this[d(1525)](),this[d(1022)]?.[d(744)](this._dbName,r)}async[t(1561)](r){let s=t;try{return await this[s(1525)](),this._qosDB?.[s(655)](this[s(165)],r)}catch(d){console[s(1217)](d)}}async clear(){let r=t;try{return await this._init(),this._qosDB?.[r(682)](this[r(165)])}catch(s){console[r(1217)](s)}}async[t(1609)](){let r=t,s={uPCgF:function(d,f){return e[J(876)](d,f)},hTXev:function(d,f,g){return e.jLIiY(d,f,g)}};return e.iSTzU(r(1067),r(1067))?(NphZaZ[r(257)](_0x2fa7f6,4).join("0")+NphZaZ.hTXev(_0x91526,_0x55bf18,2)[r(1347)](16))[r(1399)](-4):(await this[r(1525)](),this[r(1022)]?.[r(868)+"ys"](this[r(165)]))}async[t(918)](){let r=t;return await this[r(1525)](),this._qosDB?.[r(918)](this._dbName)}async[t(1218)](){let r=t,s={Vvxmq:function(d,f){return e[J(174)](d,f)}};if(e[r(493)](e[r(763)],e[r(1532)]))try{this[r(1022)]?.[r(695)](),this._qosDB=void 0}catch(d){console[r(1217)](d)}else return Roqtts.Vvxmq(0,this[r(810)])&&Roqtts.Vvxmq(0,this.low)}get[t(850)](){let r=t;try{return!!this._qosDB}catch(s){return console[r(1217)](s),!1}}}class Wp{constructor(r,s){let d=t;this[d(1007)]=r,this[d(130)]=s,this._qosDB=localStorage}async[t(717)](){}get[t(1405)](){return"frontier_"+this[t(1007)]}async get(r){let s=t;if(e[s(1339)](e[s(1361)],e[s(1361)]))return!!(e[s(640)](this[s(944)+s(437)],this[s(129)+"s"][s(1605)])||this[s(944)+"ndex"]===e[s(1255)](this.endpoints.length,1)&&e[s(1159)](this[s(670)+s(783)+s(182)+"t"],this[s(1025)+"es"]));{let d=this._qosDB[s(302)](this._prefix);return JSON[s(1262)](e[s(462)](d,"{}"))[r]}}async[t(552)](r,s){let d=t,f=this[d(1022)][d(302)](this[d(1405)]),g=JSON[d(1262)](e[d(462)](f,"{}"));return g[s||r[this[d(130)]]]=r,this[d(1022)][d(1407)](this[d(1405)],JSON[d(718)+"y"](g)),s||r[this[d(130)]]}async[t(1561)](r){let s=t,d=this[s(1022)].getItem(this[s(1405)]),f=JSON[s(1262)](e.gYEXI(d,"{}"));return f[r]=void 0,this[s(1022)].setItem(this[s(1405)],JSON[s(718)+"y"](f))}async[t(682)](){let r=t;return this._qosDB[r(682)]()}async keys(){let r=t,s=this._qosDB[r(302)](this[r(1405)]),d=JSON[r(1262)](s||"{}");return Object[r(1609)](d)}async[t(918)](){let r=t,s=this._qosDB[r(302)](this[r(1405)]),d=JSON.parse(e[r(716)](s,"{}"));return Object[r(1074)](d)}closeDB(){return Promise[t(1009)]()}get[t(850)](){return!!this[t(1022)]}}class Kp{constructor(r,s){let d=t;this[d(1007)]=r,this[d(130)]=s,this[d(1022)]=Pn?tt:Xr?wx:null}async[t(717)](){}get[t(1405)](){return t(1237)+"_"+this._DBName}async[t(1028)](r){let s=t,d=this[s(1022)][s(1357)+s(470)](this[s(1405)]);return JSON[s(1262)](e[s(1359)](d,"{}"))[r]}async[t(552)](r,s){let d=t,f=this._qosDB["getStora"+d(470)](this[d(1405)]),g=JSON[d(1262)](e[d(658)](f,"{}"));return g[s||r[this[d(130)]]]=r,this[d(1022)][d(1275)+d(470)](this._prefix,JSON[d(718)+"y"](g)),s||r[this[d(130)]]}async del(r){let s=t,d=this[s(1022)]["getStora"+s(470)](this[s(1405)]),f=JSON[s(1262)](e.OeELv(d,"{}"));return f[r]=void 0,this[s(1022)][s(1275)+s(470)](this[s(1405)],JSON[s(718)+"y"](f))}async[t(682)](){let r=t;return this[r(1022)][r(610)+r(379)]()}async[t(1609)](){let r=t,s=this._qosDB[r(1357)+r(210)+"nc"](this[r(1405)]),d=JSON.parse(e.QVRSJ(s,"{}"));return Object.keys(d)}async getAll(){let r=t,s=this._qosDB[r(1357)+"geInfoSync"](this[r(1405)]),d=JSON[r(1262)](e[r(1378)](s,"{}"));return Object[r(1074)](d)}[t(1218)](){let r=t;if(e[r(826)](e[r(1541)],r(581)))this[r(1239)]=_0x4ee186,this[r(994)]=null;else return Promise[r(1009)]()}get isReady(){return!!this[t(1022)]}}function xd(a,r){let s=t;if(e[s(1388)](Pn,Pn))return new Kp(a,r);if(e[s(1388)](rr,Qr)&&e[s(1149)](e[s(306)],typeof indexedDB))return new jp(a,r);if(e[s(1359)](rr,Qr)&&e[s(822)](e[s(306)],typeof localStorage))return new Wp(a,r);throw new Error(e[s(1393)])}class $p{constructor(){let r=t;this[r(1197)+r(1225)+"Id"]=null,this[r(1197)+"l"]=36e5,this._qosDB=xd(e.PAnfM,r(440)+"id")}async[t(1197)+t(1224)](){let r=t;e[r(421)](clearInterval,this._intervalTimeoutId),this[r(1197)+r(1225)+"Id"]=e[r(557)](setInterval,()=>{let s=r,d={kOOMe:function(f,g){return f+g},bfLgU:function(f,g){return e[J(844)](f,g)},vgKay:function(f,g){return e[J(549)](f,g)},cVQWP:function(f,g){return e.iADAR(f,g)}};if(e.jjfcV===s(841))this[s(928)+s(1594)]();else return this[s(932)]?QEqZMm[s(765)](QEqZMm[s(843)](QEqZMm[s(632)](this.high,0),_0x2b0cea),QEqZMm[s(632)](this[s(305)],0)):this[s(810)]*_0x1228ec+QEqZMm.cVQWP(this[s(305)],0)},this._interval)}async openDB(){let r=t;await this._qosDB[r(717)]().then(()=>{let s=r;this[s(1197)+s(1224)]()})}async[t(928)+t(1594)](){let r=t;(await this[r(1022)]?.[r(918)]()||[])[r(443)](({timestamp:f})=>f<Date[r(690)]()).forEach(f=>{let g=r;if(e[g(672)](e.OwQEw,e[g(895)]))this[g(1022)]?.[g(1561)](f[g(440)+"id"]);else return"frontier_"+this[g(1007)]})}async[t(1561)](r){let s=t;return this._qosDB?.[s(1561)](r)}async set(r,s){return this[t(1022)]?.set({message_id:r,timestamp:s})}async[t(1028)](r){let s=t;return this[s(1022)]?.[s(1028)](r)}async[t(1218)](){let r=t;e.IEgqg("qOHUK",e.Bwpdg)?(e.RjURm(clearInterval,this[r(1197)+r(1225)+"Id"]),await this[r(1022)]?.[r(1218)]()):(this[r(1459)+r(519)+r(1250)]=_0x8aaf12,_0x2b8a70?this["_handleO"+r(774)]():this[r(371)+r(154)]())}get[t(850)](){return this[t(1022)]?.isReady}}function ma(a){let r=t,s=!!this[r(1062)].enableQoS;if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let d=e.TXxaw(rn,a[r(515)][r(372)],"x_fronti"+r(492),"2"),f=d&&e.CiDTT(rn,a[r(515)][r(372)],e[r(343)],"1"),g=d&&e[r(1227)](rn,a[r(515)][r(372)],e[r(1481)],"1"),w=g?ir(a[r(515)][r(372)],r(399)+r(1151)+r(1228))?.[r(376)](",")[r(443)](Boolean)||[]:[];return{enabled:s,isQoSMessage:d,isQoSAck:f,isAckCleanupMessage:g,ackMsgIds:w}}async function pd(){let a=t;return this[a(654)+a(668)]||(this["_QoSMana"+a(668)]=new $p),this[a(654)+a(668)][a(850)]||await this["_QoSMana"+a(668)].openDB(),this[a(654)+a(668)]}async function Vp(a,r){let s=t,{enableAutoAck:d}=this[s(1062)],f=e[s(433)](rn,a[s(515)][s(372)],"need_ack","1"),g=rn(a.message[s(372)],e[s(1181)],"1"),w=ma[s(1089)](this,a);if(d&&f){let{SeqID:E,LogID:p,service:D,LogIDNew:N,method:F}=a[s(515)];this[s(267)]({SeqID:E,LogID:p,LogIDNew:N,service:D,method:F,headers:[{key:e[s(1181)],value:"1"},{key:e.sXULO,value:e[s(801)](N,"")},{key:s(962),value:"0"}]})}g&&!w.isQoSAck&&this[s(1071)+s(1524)+s(1093)](a),e.NCItX(r)}async function Jp(a,r){let s=t;if(e[s(1108)]==="IesZx")return _0x98eaa8+=_0x197e61&&_0x17a078[s(241)+"th"]||0,_0x28ef67;this._debug(e[s(852)],a[s(515)]),e[s(903)](r)}async function Zp(a,r){let s=t,d={KbxwL:function(f,g,w){return f(g,w)}};if(e[s(230)](e[s(476)],"tkHvp")){let f=e.dXQGk(en,await e.GBDqR(hd,a.data));try{if(e.gIjdf(f[s(450)],Uint8Array)){let g=e[s(981)](this[s(1062)][s(1153)+"ncoding"],Object)?{force:!!this[s(1062)][s(1153)+s(1052)].force,encoding:this._options[s(1153)+s(1052)][s(497)]?this[s(1062)].payloadEncoding.encoding.replace(/\s/g,"")[s(341)+s(1180)]():""}:{force:!1,encoding:this[s(1062)][s(1153)+"ncoding"]?this[s(1062)]["payloadE"+s(1052)][s(1070)](/\s/g,"")[s(341)+s(1180)]():""},w=f[s(1153)+"ncoding"]?f[s(1153)+"ncoding"][s(1070)](/\s/g,"")[s(341)+"ase"]():"",E=e[s(877)](this[s(1062)][s(881)+s(811)],Object)?{force:!!this[s(1062)][s(881)+s(811)][s(713)],type:this._options.payloadType[s(1239)]?this._options.payloadType[s(1239)].replace(/\s/g,"")[s(341)+s(1180)]():""}:{force:!1,type:this[s(1062)][s(881)+s(811)]?this._options[s(881)+s(811)].replace(/\s/g,"")[s(341)+s(1180)]():""},p=f[s(881)+s(811)]?f.payloadType[s(1070)](/\s/g,"")["toLowerC"+s(1180)]():"",D=E[s(713)]?E.type:p||E[s(1239)],N=g[s(713)]?g[s(497)]:w||g[s(497)],F=[e[s(1606)],e[s(1461)],"applicat"+s(1273)+";charset=utf-8",e[s(533)]],H=[e[s(1570)],e[s(367)]];this[s(1062)][s(1143)+s(1265)+"extPayload"]&&F.includes(D)&&(!N||H[s(1414)](N))?f["textPayl"+s(1552)]=e[s(1227)](fd,f[s(450)],0,f.payload[s(241)+"th"]):f[s(649)+s(1552)]=""}else f[s(649)+"oad"]=""}catch(g){f[s(649)+s(1552)]="",console.log(g)}a[s(515)]=f,r()}else _0x5d4399(_0xe0315e,50),dVEFed[s(1087)](_0x5891af,_0x3bebb4,_0x9e2e0e)}function Yp(a,r,s){let d=t,f=e[d(462)](s,8192),g=e[d(891)](f,1),w=null,E=f;return function(p){let D=d;if(e[D(299)](p,1)||p>g)return a(p);e.esoJu(E,p)>f&&(w=e[D(691)](a,f),E=0);let N=r.call(w,E,E+=p);return e[D(1264)](7,E)&&(E=e.AkBYP(7,E)+1),N}}let Xp=4294967295;function Qp(a,r,s){let d=t,f={KbuSm:function(g,w){return e[J(1176)](g,w)},nQffP:function(g,w,E){return e[J(1356)](g,w,E)},yNqTG:function(g,w,E){return e[J(1309)](g,w,E)},GvrxX:function(g,w,E,p){return g(w,E,p)},kBHnF:function(g,w){return e.DDBsw(g,w)},upnkO:function(g,w,E){return g(w,E)}};if(e.zcUoP(e.IbkiX,e[d(1113)])){let g=0,w=[];for(;f.KbuSm(g,_0xb5a23[d(241)+"th"]);){let{offset:E}=_0x591fca(_0x48a4ae,g);g=E;let p={cursor_name:"",cursor:0,service:0},{value:D,offset:N}=f.nQffP(_0x437da9,_0xb66865,g);p[d(776)]=D,g=N;let{value:F,offset:H}=f[d(362)](_0x33813d,_0x5c1568,g);g=H,p[d(1307)+d(1188)]=f[d(1555)](_0x5bcda9,_0x42eaef,g,f.kBHnF(g,F)),g+=F;let{value:Z,offset:K}=f[d(976)](_0x5cde89,_0xe71fc9,g);p.cursor=Z[d(882)](),g=K,w[d(969)](p)}return w}else return e.ydFOD(RangeError,e.SFFff(e[d(711)](e[d(1545)](e[d(985)](e[d(166)](e[d(1184)],a)," + "),r||1),e[d(253)]),s))}function eg(a,r,s){let d=t;if(e[d(1020)](e[d(119)],e[d(836)])){if(e.lzgva(s,Xp))throw new Error(e[d(1042)]);let f=3;for(;f>=0;){let g=e.mUhvJ(255,s);e[d(694)](_a,g,a,r+f),s>>>=8,f--}return e.wAWat(r,4)}else this[d(917)+"T"]?_0x220542[d(1246)+d(960)+d(1510)](({isConnected:f})=>{let g=d;this[g(1459)+g(519)+g(1250)]=f,f?this[g(371)+g(774)]():this[g(371)+g(154)]()}):this[d(1032)+"X"]&&_0x41bdfc[d(1246)+d(960)+d(1510)](({isConnected:f})=>{let g=d;this["_miniNav"+g(519)+g(1250)]=f,f?this[g(371)+"nLine"]():this["_handleO"+g(154)]()})}function tg(a,r){let s=t,d=0,f=r,g=r+4;for(;e[s(1176)](f,g);){let{value:w,offset:E}=e[s(1131)](wa,a,f);f=E,d=e[s(741)](e[s(1474)](d,8),0),d+=w}return{value:d,offset:g}}function ng(a,r,s){let d=t,f=e.zfxmH[d(376)]("|"),g=0;for(;;){switch(f[g++]){case"0":if(!a)return s;continue;case"1":return e[d(842)](e[d(1227)](pa,a,r,s),s);case"2":if(r.utf8Write)return e[d(1478)](r[d(1345)+"e"](a,s),s);continue;case"3":if(e.zufMj(a[d(1605)],40))return e[d(1435)](pa,a,r,s)+s;continue;case"4":if(r[d(1493)])return r.write(a,s)+s;continue}break}}function rg(a,r){let s=t,d=new fe(e.XRxVa(e[s(1088)](e[s(1266)](a[r+4],24),a[r+5]<<16)|e.IFZtu(a[r+6],8),a[e[s(687)](r,7)]),e.eCkTb(e[s(523)](e.tWihD(a[e[s(539)](r,0)],24),e[s(118)](a[e[s(676)](r,1)],16))|e.PxPqC(a[r+2],8),a[r+3]),!0);return r+=8,{value:d,offset:e[s(1418)](r,8)}}function ig(a,r,s){let d=t,f=a[d(305)],g=a[d(810)];return r[s]=g>>>24,r[e[d(723)](s,1)]=e[d(391)](g>>>16,255),r[e[d(1486)](s,2)]=e[d(1283)](g,8)&255,r[s+3]=e.iAJTU(255,g),r[e[d(870)](s,4)]=f>>>24,r[e.BAUSI(s,5)]=e.zxqIN(f>>>16,255),r[s+6]=e[d(423)](f>>>8,255),r[e[d(985)](s,7)]=e.oEkrw(255,f),s+=8,s}function wa(a,r){let s=t;return a[s(445)+"8"]?{value:a.readUInt8(r),offset:r+1}:{value:e[s(1454)](255,a[r]),offset:r+1}}function _a(a,r,s){let d=t;return r.writeUint8?r[d(938)+"t8"](a,s):r[s]=e[d(660)](255,a),s+1}let sg=function(a){return new Uint8Array(a)},og=e[t(1403)](t(284)+"d",typeof Buffer)?Buffer[t(909)+t(558)]:Yp(sg,Uint8Array[t(132)+"e"][t(212)]);(()=>{let a=t,r={TUkNI:e[a(1263)],DKlIF:function(s,d){return e[a(535)](s,d)},tjPhT:function(s,d){return e[a(1454)](s,d)},BQpqA:function(s,d){return e.BfVCv(s,d)},Umdom:function(s,d){return e[a(712)](s,d)},yKtiI:function(s,d){return e[a(205)](s,d)},uqvWW:function(s,d){return e[a(1065)](s,d)},nyzGD:function(s,d){return e.uuEpF(s,d)},EjSaI:function(s,d){return e[a(1597)](s,d)},KHzzB:function(s,d){return e[a(1291)](s,d)},VHbha:function(s,d){return e[a(1111)](s,d)},WcJhf:function(s,d){return s>>>d},zBoJn:function(s,d){return e.vCMDP(s,d)},DNzxI:function(s,d){return e[a(833)](s,d)},Yeaoh:function(s,d){return e[a(134)](s,d)},gLLqb:function(s,d){return e[a(667)](s,d)},fizmh:function(s,d){return e[a(174)](s,d)},kUwWu:a(706),ULqMf:e.hRRfo,fHhOo:function(s,d){return s|d},OBcYY:function(s,d){return e[a(405)](s,d)},havbH:function(s,d){return e[a(832)](s,d)},USLyN:function(s,d){return e[a(517)](s,d)},xUDUS:function(s,d){return s|d},qhrrY:function(s,d){return s<<d},wdYbp:function(s,d){return e[a(724)](s,d)},PxCWK:function(s,d){return e.RvxaA(s,d)},NGxTu:function(s,d){return e.nbOzm(s,d)},xCJwE:function(s,d){return e[a(1341)](s,d)}};if(e[a(1099)](e[a(1456)],e[a(1456)])){let s=4294967295;return function(d,f,g=!0){let w=a,E={Mfzvq:r[w(1380)]};if(s=r[w(1094)](r[w(236)](127,d[f]),0),r[w(1514)](d[f++],128))return{value:g?s:r[w(1122)](0,s),offset:f};if(s=r[w(1162)](s,r.uqvWW(r.nyzGD(127,d[f]),7))>>>0,r[w(1318)](d[f++],128))return{value:g?s:r.yKtiI(0,s),offset:f};if(s=r[w(1094)](r[w(1122)](s,r[w(525)](127&d[f],14)),0),r[w(1504)](d[f++],128))return{value:g?s:r[w(398)](0,s),offset:f};if(s=r[w(451)](s|(127&d[f])<<21,0),r[w(282)](d[f++],128))return{value:g?s:r[w(571)](0,s),offset:f};if(s=r.DKlIF(r[w(571)](s,r[w(525)](r[w(115)](15,d[f]),28)),0),d[f++]<128)return{value:g?s:r[w(1122)](0,s),offset:f};if(r[w(978)](f+=5,d.length))if(r.fizmh(r[w(1608)],r[w(1376)]))this[w(1062)][w(622)]&&_0x4bf4ba.log[w(1268)](_0x355ab4,[E[w(613)],..._0x229f0c]);else throw f=d[w(1605)],Qp(f,10,d[w(1605)]);return{value:g?s:r[w(1300)](0,s),offset:f}}}else _0x75e42b=_0x32f0bd[RvvPjR[a(751)](RvvPjR.OBcYY(_0x3e7e50,_0x45ebb4),1)],_0x3cc53d=_0x392b80[RvvPjR[a(751)](RvvPjR.havbH(_0x25cd3,_0x27b329),2)],RvvPjR[a(505)](RvvPjR[a(115)](RvvPjR[a(1120)](_0x1ab1fd,RvvPjR[a(678)](_0x211f8a,8)),49344),32896)?_0x2586ea+=_0x42a08e:(_0x4ab0a6=RvvPjR.fHhOo(RvvPjR[a(1162)](RvvPjR[a(525)](RvvPjR[a(135)](15,_0x2a2167),12),RvvPjR.nyzGD(63,_0x562d7e)<<6),RvvPjR[a(647)](63,_0xc93d24)),RvvPjR.PxCWK(_0x32e0a1,2048)||RvvPjR[a(1444)](_0x38ddc4,55296)&&_0x24d114<=57343?_0x16e09c+=_0x32da23:(_0xf52a1e+=RvvPjR[a(970)](_0x210d2c,_0x2b02fd),_0x735a03+=2))})();let ag=16,ya=32;function cg(a){let r=t,s=0,d={};for(let f=0;e.UTtlE(f,a[r(1605)]);f++)d[a[f].cursor_name]=ud(a[f][r(1307)+"ame"]),s+=e[r(982)](14,d[a[f][r(1307)+r(1188)]]);return[s,d]}function gd(a,r,s){let d=t,f={IBIYg:e[d(1601)],qxKiR:"service",DOgwU:d(1502),RdPtu:function(D,N,F,H){return e[d(270)](D,N,F,H)},BxwHa:e[d(1554)],hHdiI:"cursor.s"+d(812)},[g,w]=cg(a),E=e[d(568)](og,g),p=0;return a[d(1157)](D=>{let N=d,F=f[N(424)].split("|"),H=0;for(;;){switch(F[H++]){case"0":p=_a(w[D.cursor_name],E,p);continue;case"1":console[N(1217)](f[N(973)],p);continue;case"2":console[N(1217)](f[N(1201)],p);continue;case"3":p=f[N(984)](ng,D[N(1307)+N(1188)],E,p);continue;case"4":p=eg(E,p,D[N(776)]||0);continue;case"5":p=_a(0,E,p);continue;case"6":p=f[N(984)](ig,fe[N(1079)+"er"](D[N(312)]||r),E,p);continue;case"7":console[N(1217)]("name",p);continue;case"8":console[N(1217)](f.BxwHa,p);continue;case"9":console.log(f[N(383)],D,D.service);continue;case"10":console[N(1217)](N(1048)+"name",p);continue}break}}),{frameType:ya,headers:[{key:e.WCNrm,value:s}],payload:E}}function lg(a){let r=t,s=0,d=[];for(;e[r(615)](s,a[r(241)+"th"]);)if(e.UjczL(e.FurmQ,"twIEE")){let{offset:f}=wa(a,s);s=f;let g={cursor_name:"",cursor:0,service:0},{value:w,offset:E}=e.RMXWo(tg,a,s);g[r(776)]=w,s=E;let{value:p,offset:D}=e[r(583)](wa,a,s);s=D,g[r(1307)+r(1188)]=e[r(1254)](fd,a,s,e[r(1550)](s,p)),s+=p;let{value:N,offset:F}=rg(a,s);g[r(312)]=N[r(882)](),s=F,d[r(969)](g)}else try{e.VnChG(_0x168bc0,this,_0x27b9d8,[_0x5c5623,_0x319f19,_0x1e4eea])}catch(f){let g=e[r(1041)](_0x2dfca2,e[r(179)],{message:f[r(515)],code:_0x5ae6b9[r(791)+"OR"],error:f});this[r(1071)+r(793)+"ent"](g)}return d}function dg(){let a=t;return{frameType:ya,headers:[{key:"cursor_f"+a(473),value:e[a(1342)]}],payload:void 0}}class ug{constructor(r,s,d){let f=t,g={MprJw:function(w,E){return e[J(331)](w,E)},grJIm:function(w,E,p){return e[J(1568)](w,E,p)},zvkrX:function(w,E,p){return e.ntGyl(w,E,p)}};if(e.crvpX(e[f(148)],e[f(148)]))this[f(1383)+f(1401)]=r,this[f(1150)+f(927)]=s,this[f(1335)+"Strategy"]=d,this[f(1022)]=e[f(1172)](xd,this[f(1383)+f(1401)],e[f(330)]);else{let w=_0x5b6fa9[f(754)];YiXrJa[f(1421)](void 0,w)&&(YiXrJa[f(1583)](_0x42ef3b,_0x57b191,10),_0x39c794(_0x17431f,w));let E=_0x28a12e[f(889)];E!==void 0&&(YiXrJa[f(1192)](_0x248b07,_0x4dcdff,18),YiXrJa[f(1583)](_0x169b63,_0x235a48,E))}}async[t(717)](){await this._qosDB.openDB()}async getCursors(){let r=t;if(!this[r(1022)][r(850)])return;let s=this[r(1335)+r(1576)],d=await this[r(1022)][r(918)]();switch(console[r(1217)](e.hlTVV,d),s){case r(634):return d&&d[r(1605)]?gd(d,0,this["_cursorF"+r(927)]):void 0;case r(1316):return;case e[r(1445)]:return d&&d[r(1605)]?e.MXFhn(gd,d,0,this[r(1150)+r(927)]):e[r(345)](dg)}}async set(r,s,d){let f=t;return console[f(1217)](e[f(837)],r,s,d),this._qosDB.set({cursor_name:r,cursor:s,service:d})}async setCursors(r){let s=t,d=lg(r);for(let f of d)console.log(e[s(1312)],d),await this[s(1022)].set(f)}async[t(1028)](r){let s=t;return(await this[s(1022)].get(r))?.[s(312)]}async[t(1218)](){await this[t(1022)].closeDB()}[t(735)+t(332)+"Name"](r){let s=t;this["_cursorF"+s(927)]=r}get[t(850)](){let r=t;if(e[r(516)]===e[r(395)])this[r(1335)+r(1498)][r(1073)](),this[r(1335)+"Queue"].push(_0x4db0d0);else return this[r(1022)].isReady}}let fg=e[t(569)];async function md(a){let r=t;if(!this[r(1062)].enableQoS)return null;let{aID:s,fpID:d,messageStrategy:f}=this[r(1062)],g=e[r(1592)](a,fg);try{if(e.YoIOd===e[r(1434)])return this[r(290)+"anager"]?a&&this[r(290)+r(743)]["updateCu"+r(332)+r(1553)](a):this[r(290)+r(743)]=new ug(d+"_"+s+"_"+g,g,f),this._cursorManager[r(850)]||await this[r(290)+r(743)].openDB(),this[r(290)+r(743)];{let w=_0x1551f7[r(1371)]();return w?(w[r(587)]=w[r(1299)]=0,w):{bytes:new _0x3d3882(64),offset:0,limit:0}}}catch{return null}}async function hg(a,r){let s=t,d=rn(a[s(515)].headers,e[s(988)],"-1"),f=rn(a[s(515)][s(372)],e.CjtXn,"1"),g=e[s(407)](ir,a.message[s(372)],e.qmbuD),w=e.NvcJA(Number,e.oNCJO(ir,a[s(515)].headers,e.AKDMU))||0,E=ma[s(1089)](this,a),p=e[s(433)](rn,a.message[s(372)],e[s(1363)],"2"),D=ir(a[s(515)][s(372)],e[s(764)]),N=Number(ir(a[s(515)][s(372)],e[s(1047)]));if(E.isQoSAck)return e.muelz(r);let F=E[s(122)+s(666)]?await pd[s(1089)](this):null;if(e.aWZlR(a[s(515)][s(776)],0)&&f&&!d||e[s(926)](a.message[s(776)],0)){if(g&&E[s(122)+s(666)]&&F)return!!!await F[s(1028)](g)&&(this[s(1071)+s(392)+s(280)](a),await F[s(552)](g,e.dtzAX(Date[s(690)](),w))),r();if(p){let H=await md[s(1089)](this);if(!H)return this[s(1071)+s(392)+s(280)](a),e.muelz(r);let Z=await H[s(1028)](D)??-1;if(e.vBhRi(Z,N))this[s(1071)+s(392)+"Event"](a),H[s(552)](D,N,a[s(515)].service);else throw new Error("recevied"+s(483)+s(937)+N+(s(328)+s(1102)+s(304)+"r ")+Z);return e[s(456)](r)}return this[s(1071)+s(392)+s(280)](a),e[s(456)](r)}}async function xg(a,r){let s=t,d=ma[s(1089)](this,a);if(!d[s(122)+s(666)])return e[s(1362)](r);let f=await pd[s(1089)](this);if(d[s(1084)+s(224)+s(494)]&&d[s(807)+"s"][s(1605)])for(let g of d.ackMsgIds)await f[s(1561)](g);r()}async function pg(a,r){let s=t,d=e[s(1392)](a[s(515)].frameType,ag),f=e[s(646)](a[s(515)].frameType,ya);if(e.SFtcx(!d,!f))return e[s(1362)](r);let g=e[s(664)](ir,a[s(515)][s(372)],e[s(294)]);if(!g)return e.yNeNm(r);let w=await md[s(1089)](this,g);if(!w)return e[s(456)](r);if(d){let E=await w[s(934)+"rs"](),p={frameType:E?.[s(915)+"e"],SeqID:fe.fromNumber(this[s(1310)]++),LogID:fe.fromNumber(this[s(1062)].logIDGenerator()),service:9e3,method:5,headers:E?.headers,payload:E?.payload},D=e.UVzRu(S,p);this._ws&&this._ws[s(268)+"te"]&&this._ws[s(602)](D)}if(f){let E=a[s(515)][s(450)];E&&w[s(357)+"rs"](E)}}let gg=async function(a,r){let s=t;this[s(580)]=!1,e.ZIEwg(clearTimeout,this[s(1375)+s(1198)+s(153)]),r()},mg=async function(a,r){let s=t;if(!this[s(726)]||e[s(1203)](this[s(726)][s(268)+"te"],this[s(419)]))return e[s(903)](r);let{pingInterval:d}=this[s(1062)];this[s(321)+"tManager"]?.[s(1141)+s(1598)+s(188)]();for(let g=0;e[s(829)](g,this[s(1335)+s(1498)].length);g++){let w=this[s(1335)+s(1498)][g];if(e.lxuFh(this[s(726)].readyState,this[s(419)])&&w!==null)this[s(726)]&&this[s(726)][s(602)](w),this["_message"+s(1498)][g]=null;else break}this[s(1335)+"Queue"]=this[s(1335)+"Queue"][s(443)](g=>!!g),this[s(425)+s(511)+"Id"]=e[s(680)](setTimeout,()=>this[s(1437)](),d),this._dispatchOpenEvent(a),this[s(1010)+"er"]&&this._ws&&(this[s(726)].binaryType=this["_binaryT"+s(811)]);let f=this["_endpoin"+s(908)]?.[s(346)+s(1215)+"nt"]();this[s(1267)](s(559)+f+s(278)),e[s(636)](r)},wg=async function(a,r){let s=t,d=this[s(321)+s(908)]?.["getCurre"+s(1215)+"nt"]();this[s(1267)]("open "+d),e[s(871)](r)};class _g extends xa{constructor(r){let s=t,d={NhnCP:function(E,p){return e[J(826)](E,p)},RKiCK:e[s(388)],cYPiM:function(E,p){return E===p},IqTuM:s(468),tZyEt:function(E,p){return e[s(1245)](E,p)},pGTCa:e.XbtRC,RFdaF:s(759),BYXcJ:function(E,p,D){return e[s(133)](E,p,D)},TRxeN:function(E,p){return e[s(770)](E,p)},lhdut:function(E,p,D,N){return E(p,D,N)},nvJlt:s(417),vuTue:function(E,p){return e.SLPbH(E,p)},QpkLe:s(347),kYiqd:e.SvZTU,vMJRS:e[s(1396)],vVzDi:e[s(1539)],uTAJE:e[s(1440)],udqZf:function(E,p){return e[s(691)](E,p)},spxyg:function(E,p,D){return e.yJaDe(E,p,D)},NrhGg:function(E,p,D){return E(p,D)}};super(),this[s(1459)+s(519)+s(1250)]=!0,this[s(1010)+"er"]=rr,this[s(208)]=Lp,this[s(917)+"T"]=Pn,this[s(1032)+"X"]=Xr,this[s(808)+"r"]=Qr,this["_message"+s(1498)]=[],this[s(321)+"tManager"]=null,this[s(787)+s(342)]=!1,this[s(731)+s(811)]=e.VggnO,this[s(1375)+s(936)]=!1,this[s(1375)+s(1198)+s(153)]=null,this[s(466)+"ctTimeou"+s(732)]=null,this[s(425)+s(511)+"Id"]=null,this._seqId=0,this[s(580)]=!1,this[s(1389)]="",this._QoSManager=null,this[s(290)+s(743)]=null,this[s(490)+s(623)]=null,this[s(980)+"ls"]=e[s(1304)],this[s(1222)]=3,this[s(835)+"NG"]=0,this.OPEN=1,this[s(593)]=2,this[s(1443)]=E=>{let p=s;try{e[p(681)](dd,this,E,[gg,mg,wg])}catch(D){if(e.RLnFT(p(585),e.cVAVY))return this[p(1022)]?.[p(850)];{let N=e.mUvKM(ct,e[p(179)],{message:D[p(515)],code:nn[p(791)+"OR"],error:D});this[p(1071)+p(793)+"ent"](N)}}},this[s(733)+"ge"]=async E=>{let p=s,D={mggiz:function(N,F){return N>=F}};if(d[p(781)](d[p(375)],d.RKiCK)){let{pingInterval:N,pingFrequency:F}=this._options;if((d.NhnCP("hi",E.data)&&d.cYPiM(d[p(1511)],F)||d[p(1106)](p(1340),F))&&(this[p(256)+p(1432)](),this[p(949)](d[p(220)],d[p(846)]),this[p(425)+p(511)+"Id"]=d[p(1344)](setTimeout,this[p(1437)][p(1085)](this),N)),d[p(1500)]("hi",E[p(798)]))return;try{d[p(1351)](dd,this,E,[Zp,Vp,xg,pg,hg,Jp])}catch(H){let Z=ct(d[p(500)],{message:H.message,code:nn[p(530)+p(325)],error:H});this[p(1071)+"hErrorEv"+p(1334)](Z)}}else return VNXxFP[p(719)](_0x3a7cf9[p(587)],_0xbdb588.limit)},this[s(601)]=E=>{let p=s,D=this["_endpoin"+p(908)]?.[p(805)+p(434)+"es"](),N=this[p(321)+"tManager"]?.getCurrentEndpoint();if(D&&!E[p(515)]){let F=p(1004)+N+(p(795)+p(1451)+p(1382)+"ed");this[p(1071)+p(793)+"ent"](ct(d[p(500)],{message:F,code:nn[p(177)+p(551)+"R"],error:E}));return}this._ws&&this[p(726)][p(268)+"te"]===this[p(419)]&&this["_disconn"+p(120)](),this[p(1071)+"hErrorEv"+p(1334)](d[p(1344)](ct,"error",{message:E[p(515)],code:nn["NATIVE_E"+p(176)],error:E}))},this._onClose=async E=>{let p=s,D={tmQlg:d[p(846)],ZoEiw:p(417),eDJvM:function(N){return N()},PRymD:function(N,F){return N(F)}};if(d.vuTue(d[p(1480)],p(347))){let N={xXNNK:function(K,Be){let We=p;return AYHZrL[We(1483)](K,Be)},mIULJ:function(K){let Be=p;return AYHZrL[Be(1475)](K)}},F=()=>{let K=p;_0x15df2d[K(992)+"entListe"+K(1588)](AYHZrL[K(186)],H),_0x447936["removeEv"+K(469)+K(1588)](AYHZrL[K(1209)],Z)},H=()=>{let K=p;_0x2db59f(_0x174648(_0x36aec3[K(1112)])),AYHZrL.eDJvM(F)},Z=()=>{let K=p;N.xXNNK(_0x14f650,_0x17d9cf[K(417)]),N[K(1499)](F)};_0x24ab7c[p(796)+p(1579)](AYHZrL[p(186)],H),_0x349963[p(796)+p(1579)](AYHZrL[p(1209)],Z)}else{this[p(202)+p(111)](),this["_clearPi"+p(1432)](),this[p(1458)+p(609)+"rs"](),this[p(726)]=null,this._connectLock=!1;let N=this[p(321)+"tManager"]?.[p(805)+p(434)+"es"]();if(!N&&this[p(987)+p(141)]()&&!this[p(787)+p(342)]){let F=this[p(321)+"tManager"]?.[p(346)+p(1215)+"nt"](),H=this[p(1062)][p(772)+p(243)+p(648)](E.code,E.reason);this[p(1071)+"hCloseEv"+p(1334)](d[p(1344)](gt,d.kYiqd,{code:1006,reason:E[p(1018)]||p(1581)+p(1200)+p(369)+p(140)+"n, hostn"+p(1127)+F,willReconnect:H})),H&&this[p(1375)]();return}if(E.code!==1e3&&this[p(787)+p(342)]){this["_dispatc"+p(900)+p(1334)](d[p(1344)](gt,d[p(1325)],{code:1e3,reason:d.vMJRS})),this[p(321)+p(908)]?.[p(1141)+p(1598)+p(188)](),this[p(490)+p(623)]?.["resetCou"+p(223)]();return}if(d.vuTue(1e3,E[p(721)])&&N)if(d[p(360)]===d.uTAJE)this[p(949)](AYHZrL[p(1209)],_0x35fd77(AYHZrL[p(1209)],{message:this[p(265)+p(1129)+p(494)](_0x2a2035)}));else{let F=this[p(321)+p(908)]?.[p(346)+p(1215)+"nt"](),H=E[p(1018)];H||(H=await d.udqZf(qp,this[p(1389)])),H=p(1581)+p(1200)+p(995)+H+(", hostna"+p(546))+F+(", max re"+p(894)+"ached"),this["_dispatc"+p(900)+p(1334)](d[p(1160)](gt,d.kYiqd,{code:E[p(721)],reason:H}));let Z=p(1004)+F+(p(795)+p(1451)+"es reached");this["_dispatc"+p(793)+p(1334)](ct(d[p(500)],{message:Z,code:nn[p(177)+p(551)+"R"]})),this["_endpoin"+p(908)]?.[p(1141)+p(1598)+"fig"](),this[p(490)+p(623)]?.resetCounter();return}if(E.code!==1e3&&!E[p(1018)]){let F=this[p(321)+p(908)]?.[p(346)+p(1215)+"nt"]();this[p(1071)+p(900)+p(1334)](d[p(1252)](gt,d[p(1325)],{code:E[p(721)],reason:p(1581)+p(1200)+"d, unkno"+p(140)+p(441)+p(1127)+F})),this[p(321)+p(908)]?.[p(1141)+"pointCon"+p(188)](),this[p(490)+p(623)]?.[p(524)+p(223)]();return}this[p(1071)+p(900)+"ent"](E),this[p(321)+p(908)]?.[p(1141)+p(1598)+p(188)](),this["_pingLos"+p(623)]?.[p(524)+p(223)]()}},this.onclose=null,this.onerror=null,this.onmessage=null,this[s(1507)]=null,this["onStartR"+s(1513)]=null,this[s(1477)+s(1319)]=null,this["onStopIm"+s(488)+"yReconnect"]=null,this[s(371)+"nLine"]=this[s(371)+"nLine"][s(1085)](this),this[s(371)+"ffLine"]=this._handleOffLine.bind(this),this[s(181)+"ageHide"]=this[s(181)+s(1238)][s(1085)](this),this["_handleP"+s(436)]=this[s(181)+s(436)][s(1085)](this),this[s(1062)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(1505)](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.NMLit,pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(1445)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:g}=r,w=Array.isArray(f)?f:e[s(560)](s(463),typeof f)?[f]:[];if(!w||e[s(896)](0,w[s(1605)]))throw new Error(e[s(1495)]);if(!Fp(g))throw new Error(e[s(1611)]);Object[s(498)](this[s(1062)],r),this["_endpoin"+s(908)]=new ld(w,this._options[s(1025)+"es"]),this[s(490)+s(623)]=new Gp(this[s(1062)].pingLossCount),this[s(1062)][s(397)+"cOpen"]&&(this[s(580)]=!0,this[s(1375)]()),this[s(1062)][s(1509)+s(354)+"nged"]&&(this[s(917)+"T"]||this[s(1032)+"X"]?this[s(442)+"etWorkCh"+s(404)]():this._isBrowser&&this[s(1077)+"balEvent"+s(1579)]())}["_handleO"+t(774)](){let r=t,s={wCjwp:function(d,f){return d===f}};if(e[r(1174)](r(158),r(158))){let d=this[r(578)+"rs"][_0xa777f7];if(d)for(let f=0;f<d[r(1605)];)saBTRs.wCjwp(d[f].fn,_0x568868)?d[r(1039)](f,1):++f}else{if(this[r(1062)]["disableAutoRecon"+r(240)]||this[r(787)+"osed"])return;this[r(1572)+r(1513)]()}}[t(371)+t(154)](){let r=t;if(e[r(1276)]!==e[r(1276)])return this[r(321)+"tManager"]?.["getCurre"+r(1215)+r(1441)+r(258)]()||0;{this[r(121)+r(1358)+"t"]();let s=e[r(1e3)](ha,r(772)+"t",{message:r(439)+r(1535)+" reconnect"});this[r(464)+r(488)+r(1487)+"ct"]&&this["onStopIm"+r(488)+"yReconnect"](s)}}[t(1077)+t(449)+t(1579)](){let r=t;this[r(1010)+"er"]&&window[r(796)+r(1579)](e.wFWWl,this[r(371)+r(774)]),this[r(1010)+"er"]&&window["addEvent"+r(1579)]("offline",this[r(371)+r(154)]),this[r(1010)+"er"]&&window[r(796)+r(1579)](e[r(1297)],this["_handleP"+r(1238)]),this[r(1010)+"er"]&&window[r(796)+r(1579)](e.uRTte,this._handlePageShow)}[t(651)+t(449)+"Listener"](){let r=t;this[r(1010)+"er"]&&window[r(992)+r(469)+r(1588)](e.wFWWl,this[r(371)+r(774)]),this[r(1010)+"er"]&&window[r(992)+r(469)+r(1588)](e.XrxKy,this["_handleO"+r(154)]),this[r(1010)+"er"]&&window[r(992)+"entListe"+r(1588)](r(289),this[r(181)+r(1238)]),this[r(1010)+"er"]&&window[r(992)+"entListener"](r(152),this[r(181)+"ageShow"])}[t(181)+t(1238)](r){let s=t,d={mVgiG:e[s(179)],MuSFs:function(f,g){return e[s(1231)](f,g)},VxIqS:function(f,g,w){return e[s(1064)](f,g,w)}};if(!r[s(631)+"d"])if(e.CHfZk("ZWZAZ","ZWZAZ"))this._isBrowser&&window.removeEventListener(s(289),this[s(181)+s(1238)]),this[s(1010)+"er"]&&window[s(992)+s(469)+"ner"](e[s(1602)],this[s(181)+s(436)]),this.close();else{let f=this[s(321)+s(908)]?.[s(805)+s(434)+"es"](),g=this["_endpoin"+s(908)]?.[s(346)+s(1215)+"nt"]();if(f&&!_0xfeb6ef.message){let w=s(1004)+g+(" fail, m"+s(1451)+s(1382)+"ed");this[s(1071)+s(793)+s(1334)](_0xc44bca(fxyNkY[s(340)],{message:w,code:_0x1b2acc.MAX_RETRIES_ERROR,error:_0x450c46}));return}this[s(726)]&&fxyNkY.MuSFs(this[s(726)][s(268)+"te"],this[s(419)])&&this[s(1166)+s(120)](),this[s(1071)+"hErrorEv"+s(1334)](fxyNkY[s(1557)](_0xa4bfaa,fxyNkY[s(340)],{message:_0x51d548.message,code:_0x475cc8[s(872)+s(176)],error:_0x3d6b89}))}this[s(1010)+"er"]&&window[s(992)+"entListe"+s(1588)](e.wFWWl,this[s(371)+s(774)]),this[s(1010)+"er"]&&window[s(992)+"entListener"](e.XrxKy,this[s(371)+"ffLine"])}[t(181)+t(436)](r){let s=t;e[s(123)](e[s(508)],"QdrQf")?r.persisted&&(this[s(987)+s(141)]()&&(!this._ws||e[s(1244)](this[s(726)][s(268)+"te"],this[s(419)])||this[s(726)][s(268)+"te"]!==this[s(835)+"NG"])&&this[s(371)+"nLine"](),this[s(1010)+"er"]&&window[s(796)+s(1579)](e[s(1169)],this[s(371)+"nLine"]),this[s(1010)+"er"]&&window[s(796)+"Listener"](e[s(285)],this["_handleO"+s(154)])):this[s(949)](e[s(179)],e[s(628)](_0x2cade1,e[s(179)],{..._0x3c763e,message:_0x165a65.errMsg||""}))}async["_generat"+t(499)](r){let s=t,d={QCeat:e[s(1134)],QBtCr:s(1610)+s(948),IoiNa:function(ei,ti){return e[s(324)](ei,ti)},XYGPa:e[s(1220)]},{fpID:f,deviceID:g,bddID:w,ttwID:E,accessKey:p,aID:D,customParams:N={},enableAutoAck:F,enableQoS:H,QoSLevel:Z,env:K}=this[s(1062)],Be,We,sn;if(this[s(1010)+"er"]||this[s(1032)+"X"]||this[s(917)+"T"])if(s(1457)===e[s(1110)])Be=location&&e[s(922)]==location[s(1429)]?e[s(251)]:s(761),We=r[s(1070)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),sn=/^wss(.*:\/\/)/[s(993)](r)?r:""+Be+We;else{if(_0x553116===HvOHlx[s(529)])return _0x3ab93f[s(1028)](_0x420e23);if(_0x561f7e===HvOHlx[s(512)])return _0x3741d3[s(1610)+s(948)]||_0x430538[s(1028)](_0x17c56d);if(HvOHlx[s(206)](_0x4b7ce0,HvOHlx[s(1337)]))return _0x1ee810["objectSt"+s(948)][1]?void 0:_0x20b305["objectSt"+s(689)](_0x48dab3[s(1610)+"oreNames"][0])}else Be=e[s(251)],We=r[s(1070)](/(^http)((?:[s]*:\/\/))/,""),sn=/(^ws)((?:[s]*:\/\/))/[s(993)](We)?We:""+Be+We;let wd=w?e[s(156)]:E?e.RBSwN:e[s(752)],_d=w||E||g;if(e.fATCn(!_d,!wd))throw new Error(e[s(1402)]);let yg=e[s(1575)]==typeof N?await e[s(1043)](N):N,bg=K?e[s(1005)](Up,K.xUseEnv,K.xTTEnv):{},ba=Object[s(498)]({device_platform:e[s(942)],version_code:s(401)+"0",access_key:p,fpid:f,aid:D,[wd]:_d,xsack:F?1:0,xaack:F?1:0,xsqos:H?1:0,qos_level:H?Z:void 0,qos_sdk_version:2,...bg},yg),Eg=Object[s(1609)](ba)[s(1415)]((ei,ti)=>ba[ti]!==void 0?""+ei+(ei?"&":"?")+ti+"="+ba[ti]:ei,"");return sn+s(408)+Eg}async[t(1375)](){let r=t;if(!(this[r(1375)+r(936)]||this[r(787)+r(342)])){this[r(1375)+r(936)]=!0;try{let s=this[r(321)+"tManager"]?.[r(686)+r(180)+r(1118)+r(1516)+"tries"](),{timeoutInterval:d}=this[r(1062)];if(s){let g=this[r(321)+r(908)]?.[r(346)+r(1215)+"nt"](),w=this[r(321)+r(908)]?.[r(1036)+r(1145)+"pointAndUpdateCo"+r(1186)](),E=this["_endpoin"+r(908)]?.["getCurre"+r(1215)+r(1441)+r(258)]();if(w){let p=r(1004)+g+(" timeout"+r(563)+r(894)+r(1296)+r(1114)+"backup e"+r(1133))+w+(r(413)+"y"),D=e.wSNEY(ct,r(417),{message:p,code:nn[r(177)+r(551)+"R"]});this[r(1267)](p),this[r(1071)+"hErrorEv"+r(1334)](D),this[r(1389)]=await this[r(768)+r(499)](w),this[r(1267)](r(1004)+w+" "+E+r(1365)),this["_removeW"+r(609)+"rs"]()}else{let p=r(1004)+g+(" timeout"+r(563)+"tries re"+r(1331));this._debug(p),this["_dispatc"+r(793)+r(1334)](e[r(959)](ct,e[r(179)],{message:p,code:nn["MAX_RETR"+r(551)+"R"]}));return}}else{let g=this[r(321)+r(908)]?.[r(346)+"ntEndpoi"+r(1241)+r(715)](),w=this[r(321)+"tManager"]?.[r(346)+r(1215)+r(1441)+r(258)]();this[r(1389)]=await this[r(768)+r(499)](e.xrbQc(g,"")),this[r(1267)]("connect "+g+" "+w+" times"),this[r(1458)+r(609)+"rs"]()}if(this[r(580)])this[r(580)]=!1;else{let g=e[r(151)](ha,e[r(142)],{message:r(924)});this[r(307)+r(1513)]&&this[r(307)+r(1513)](g)}let f=this["_endpoin"+r(908)]?.[r(346)+r(1215)+r(1441)+r(258)]()||0;e[r(554)](f,1)&&await this._wait(e.QzfGH(f,1)),this._debug("connecti"+r(527)+this[r(1389)]+(r(458)+r(1034))+this._protocols),this[r(726)]=e[r(1142)](Bp,{url:this[r(1389)],protocols:[this[r(980)+"ls"]],headers:this[r(1062)][r(1430)+r(197)+"s"][r(809)+r(1060)]},this._options.ws),(this[r(1010)+"er"]||this[r(808)+"r"])&&this[r(726)]&&(this[r(726)].binaryType=this["_binaryT"+r(811)]),this[r(859)+r(249)](),this["_connectionTimeo"+r(153)]=e[r(467)](setTimeout,this[r(160)+"ut"][r(1085)](this),d)}catch(s){throw this[r(1375)+r(936)]=!1,s}}}[t(202)+t(111)](){let r=t;e[r(758)](clearTimeout,this[r(1375)+r(1198)+r(153)]),this[r(1375)+"ionTimeo"+r(153)]=null}[t(256)+t(1432)](){let r=t;e[r(273)](clearTimeout,this[r(425)+r(511)+"Id"]),e[r(1341)](clearTimeout,this[r(466)+r(1488)+r(732)]),this._pingPongTimeoutId=null,this[r(466)+r(1488)+"tId"]=null}[t(1267)](...r){let s=t;this[s(1062)][s(622)]&&console[s(1217)].apply(console,[s(847)+">",...r])}[t(657)+t(291)+"e"](r){let s=t,{initReconnectInterval:d,maxReconnectInterval:f,reconnectIntervalGrowFactor:g}=this[s(1062)],w=e[s(336)](d,Math[s(1580)](g,e[s(1377)](r,1)));return e[s(244)](w,f)?f:w}_ping(){let r=t;if(e[r(1100)](e[r(195)],e[r(195)])){if(this[r(726)]&&this[r(726)].readyState===this.CONNECTING){this["_clearPi"+r(1432)](),this[r(425)+r(511)+"Id"]=e[r(616)](setTimeout,this[r(1437)][r(1085)](this),this[r(1062)][r(1506)+r(1298)]);return}if(!this._ws||e[r(1155)](this[r(726)].readyState,this[r(419)]))return void this["_handleR"+r(1513)]();this[r(726)]&&this[r(726)][r(602)]("hi"),this[r(466)+"ctTimeou"+r(732)]=e.bTSLT(setTimeout,this["_handleR"+r(1513)+"Timeout"].bind(this),this._options[r(1202)+"outInter"+r(749)])}else{let s=this[r(1062)][r(772)+r(243)+r(648)](_0x33108b,_0xe1177b);this[r(1071)+r(900)+"ent"](e.tUSvT(_0x59edbc,e[r(760)],{code:_0x48e2c4,reason:_0x391638,wasClean:!0,willReconnect:s})),s&&this[r(1375)]()}}[t(1572)+t(1513)+t(1465)](){let r=t;this[r(490)+r(623)]?.[r(679)](),this[r(949)](e[r(238)],e[r(204)]),this[r(490)+r(623)]?.[r(805)+"chMaxCount"]()?this[r(1572)+r(1513)]():this[r(1437)]()}[t(987)+t(141)](){let r=t;return this[r(917)+"T"]||this._isMiniWX?this[r(1459)+"igatorOnline"]:(this[r(1010)+"er"]||this._isWorker)&&this._options[r(1509)+r(354)+"nged"]?navigator.onLine:!0}[t(1572)+t(1513)](){let r=t;!this[r(987)+r(141)]()||this[r(787)+r(342)]||(this[r(321)+r(908)]?.[r(1141)+r(1598)+r(188)](),this[r(490)+r(623)]?.[r(524)+r(223)](),this[r(726)]?this[r(1166)+"ect"](1001,e[r(952)],!0):this._connect())}[t(442)+"etWorkCh"+t(404)](){let r=t,s={uBcXE:function(d,f){return e.lItvZ(d,f)},Qines:e[r(416)]};this._isMiniTT?tt[r(1246)+r(960)+r(1510)](({isConnected:d})=>{let f=r;this[f(1459)+f(519)+"line"]=d,d?this[f(371)+"nLine"]():this[f(371)+f(154)]()}):this._isMiniWX&&wx["onNetwor"+r(960)+r(1510)](({isConnected:d})=>{let f=r;s[f(1322)]("wIBUZ",s[f(827)])?_0x1ed862=_0x39550d(_0x47c3b3):(this[f(1459)+f(519)+"line"]=d,d?this[f(371)+f(774)]():this[f(371)+"ffLine"]())})}_wait(r){return new Promise(s=>{let d=J;setTimeout(s,this[d(657)+d(291)+"e"](r))})}[t(1166)+"ect"](r=1e3,s="",d=!1){let f=t;this[f(726)]&&this[f(121)+f(1358)+"t"](r,s,d)}[t(160)+"ut"](){let r=t,s=this[r(321)+r(908)]?.[r(346)+r(1215)+"nt"]();this[r(1267)](r(1004)+s+r(1391)),this[r(1166)+r(120)](1001,r(350)+r(128)+"onnecting",!0)}[t(267)](r){let s=t,d=e[s(1123)](zt,r);if(this[s(726)]&&e.PXwTl(this[s(726)][s(268)+"te"],this[s(419)]))if(e[s(672)](e[s(292)],e[s(292)]))this[s(726)]&&this[s(726)].send(d),this[s(1267)](e[s(1370)],r);else{let f=this["_endpoin"+s(908)]?.[s(346)+s(1215)+"nt"]();this[s(1267)](s(1004)+f+s(1391)),this["_disconn"+s(120)](1001,e[s(990)],!0)}}[t(1458)+t(609)+"rs"](){let r=t;this[r(726)]&&(this._ws[r(992)+r(469)+r(1588)](e[r(279)],this[r(1443)]),this._ws[r(992)+r(469)+"ner"](r(695),this[r(983)]),this._ws["removeEv"+r(469)+r(1588)](e[r(1136)],this[r(733)+"ge"]),this[r(726)][r(992)+"entListener"](e[r(179)],this[r(601)]))}[t(859)+t(249)](){let r=t;if(e[r(1230)](e.dizdm,e[r(968)])){let s=e[r(1338)].split("|"),d=0;for(;;){switch(s[d++]){case"0":this._ws[r(796)+r(1579)](r(695),this._onClose);continue;case"1":if(!this[r(726)])return;continue;case"2":this[r(726)][r(796)+r(1579)]("message",this[r(733)+"ge"]);continue;case"3":this[r(726)][r(796)+"Listener"](r(426),this[r(1443)]);continue;case"4":this[r(726)][r(796)+r(1579)](e[r(179)],this[r(601)]);continue}break}}else _0x1bb316[r(1009)]()[r(1534)](()=>{this["_addWsLi"+r(249)]()})}[t(998)+"nceClose"](r=1e3,s=""){let d=t;try{this._ws&&this[d(726)][d(695)](r,s)}catch{}}[t(121)+t(1358)+"t"](r=1e3,s="",d=!1){let f=t,g={oodvH:function(w,E,p){return w(E,p)},nTbbN:e[f(142)],DAKzt:f(924),mtrmg:function(w,E){return e[f(493)](w,E)},veHtD:function(w,E){return e[f(174)](w,E)},URdGA:function(w,E){return e[f(891)](w,E)},HmDuS:function(w,E){return e[f(1329)](w,E)},uPvUz:function(w,E){return e[f(263)](w,E)}};if(this[f(256)+f(1432)](),this[f(202)+f(111)](),this._removeWsListeners(),this._wsInstanceClose(1e3,s),this[f(1375)+f(936)]=!1,d&&this[f(987)+f(141)]()&&!this[f(787)+f(342)])if(e.kDaZv(f(1543),e[f(997)])){if(this[f(321)+f(908)]?.[f(805)+f(434)+"es"]())if(f(1221)!==f(1473)){let E=this[f(321)+f(908)]?.[f(346)+f(1215)+"nt"]();this[f(1071)+f(900)+f(1334)](e[f(1578)](gt,e[f(760)],{code:1006,reason:f(1004)+E+(f(1391)+f(563)+f(894)+f(1331)),wasClean:!0}))}else{let E=zhOqSS[f(1189)](_0x24c6ee,zhOqSS.nTbbN,{message:zhOqSS[f(708)]});this.onStartReconnect&&this.onStartReconnect(E)}else{let E=this[f(1062)]["reconnec"+f(243)+"ptor"](r,s);this["_dispatc"+f(900)+f(1334)](e[f(1537)](gt,e[f(760)],{code:r,reason:s,wasClean:!0,willReconnect:E})),E&&this._connect()}return}else return _0x319e5f.isLong(_0x385fba)||(_0x176ffc=_0x2e0acf.fromNumber(_0x10a957)),zhOqSS[f(1260)](this.unsigned,_0x27129f.unsigned)&&zhOqSS.veHtD(zhOqSS[f(1229)](this[f(810)],31),1)&&zhOqSS.HmDuS(zhOqSS[f(1229)](_0xee0de9[f(810)],31),1)?!1:zhOqSS[f(750)](this[f(810)],_0x201122[f(810)])&&zhOqSS[f(750)](this[f(305)],_0x5bb7ed.low);this[f(987)+f(141)]()||this[f(787)+f(342)]?this[f(1071)+f(900)+f(1334)](gt("close",{code:r,reason:e[f(1396)]})):this[f(1071)+f(900)+f(1334)](e[f(1126)](gt,f(695),{code:1006,reason:e[f(778)]})),this._ws=null,this[f(321)+f(908)]?.["resetEndpointCon"+f(188)](),this[f(490)+f(623)]?.[f(524)+"nter"]()}[t(1071)+t(227)+"nt"](r){let s=t;this[s(949)](e[s(279)],r),this.onopen&&this[s(1507)](r)}[t(1071)+t(392)+t(280)](r){let s=t;this[s(949)](e[s(1136)],r),this[s(996)+"e"]&&this[s(996)+"e"](r)}["_dispatc"+t(1524)+"ageEvent"](r){let s=t;this[s(949)](e.bBPpT,r),this[s(1477)+s(1319)]&&this["onReceiv"+s(1319)](r)}["_dispatchErrorEv"+t(1334)](r){let s=t;if(e.sHtGl(e[s(674)],e[s(584)]))this[s(949)](e[s(179)],r),this[s(1556)]&&this[s(1556)](r);else for(var d in _0x27da31)_0x5a9e04.o(_0x91e0e,d)&&!_0xdd8f2c.o(_0x255183,d)&&_0x160cda[s(1140)+s(562)](_0x5d40d8,d,{enumerable:!0,get:_0x4b2a2e[d]})}[t(1071)+"hCloseEv"+t(1334)](r){let s=t;this[s(949)](e[s(760)],r),this.onclose&&this.onclose(r)}get[t(126)+"pe"](){let r=t;return this[r(726)]?this[r(726)].binaryType:this[r(731)+r(811)]}set[t(126)+"pe"](r){let s=t;this[s(731)+s(811)]=r,this[s(726)]&&(this._ws[s(126)+"pe"]=r)}get[t(446)+"nt"](){let r=t;return this[r(321)+r(908)]?.[r(346)+r(1215)+r(1441)+"ount"]()||0}get bufferedAmount(){let r=t,s=this[r(1335)+r(1498)][r(1415)]((d,f)=>(d+=f&&f[r(241)+"th"]||0,d),0);return e.OGCHs(s,this._ws?this[r(726)][r(411)+r(912)]:0)}get[t(1279)+"ns"](){let r=t;return this._ws?this[r(726)][r(1279)+"ns"]:""}get[t(1429)](){let r=t;return this[r(726)]?this[r(726)][r(1429)]:""}get[t(268)+"te"](){let r=t;return this[r(726)]?this[r(726)][r(268)+"te"]:this[r(1062)][r(397)+r(242)]?this[r(835)+"NG"]:this[r(1222)]}get[t(528)](){let r=t;return e.yJITA(e[r(910)],e[r(910)])?this._ws?this[r(726)][r(528)]:this[r(1389)]:this[r(1022)].isReady}[t(695)](r=1e3,s){let d=t;if(this[d(787)+d(342)]=!0,this[d(202)+d(111)](),this[d(256)+d(1432)](),this[d(651)+d(449)+d(1579)](),this[d(654)+"ger"]?.[d(1218)](),!this[d(726)])return void this._debug(e[d(1165)]);if(e[d(1329)](this[d(726)].readyState,this[d(1222)])||this._ws[d(268)+"te"]===this[d(593)])return void this[d(1267)](e[d(477)]);this[d(121)+"WebSocket"](r,s)}async[t(602)](r,s){let d=t;if(r==null)throw new Error("please p"+d(1589)+d(645)+d(638)+d(429)+d(1278)+d(298)+" arraybu"+d(1452));e.dSOYv==typeof r&&(r=JSON[d(718)+"y"](r)),e.tjolm(d(463),typeof r)&&!e[d(444)](r,ArrayBuffer)&&!(r[d(163)]&&r.buffer instanceof ArrayBuffer)&&(r=JSON.stringify(r));let f=await hd(r),g=e[d(925)](zp,r),{method:w=0,service:E=this[d(1062)].service,logID:p=this._options[d(1289)+d(746)](),headers:D=this[d(1062)][d(372)],payloadEncoding:N=this._options[d(1153)+"ncoding"],payloadType:F=this[d(1062)][d(881)+d(811)],logIDNew:H=this._options[d(790)+d(1436)]["enableAu"+d(1008)+d(702)+"ew"]?e[d(553)](i,this[d(1062)]["logIDNew"+d(1436)].userIp):""}=e[d(716)](s,{});if(!E)throw new Error(e[d(543)]);let Z={SeqID:fe[d(1079)+"er"](this[d(1310)]++),LogID:fe[d(1079)+"er"](p),service:E,method:w,headers:D,payloadEncoding:e[d(194)](N,Object)?N.encoding?N[d(497)]:"":N,payloadType:F instanceof Object?F[d(1239)]?F.type:g:F||g,payload:f,LogIDNew:H},K=zt(Z);return this[d(726)]&&this[d(726)][d(268)+"te"]===this[d(419)]?(this[d(726)]&&this[d(726)][d(602)](K),this[d(1267)](e.dBUcG,Z)):this[d(1335)+"Queue"].length<this[d(1062)][d(767)+"geQueueL"+d(1585)]?(this[d(1335)+"Queue"][d(969)](K),this._debug(e.ZyUVU,Z)):(this[d(1335)+d(1498)][d(1073)](),this["_message"+d(1498)][d(969)](K)),{seqID:this[d(1310)],logID:p,logIDNew:H}}async[t(772)+"t"](r){let s=t,d={DTFik:function(w,E){return e[J(946)](w,E)}},{url:f}=r||{},g=Array.isArray(f)?f:e[s(533)]==typeof f?[f]:[];if(r&&Object[s(498)](this[s(1062)],r),g&&g[s(1605)]?this[s(321)+s(908)]=new ld(g,this[s(1062)][s(1025)+"es"]):this[s(321)+s(908)]?.["resetEndpointCon"+s(188)](),this._pingLossCounter?.[s(524)+s(223)](this[s(1062)][s(972)+s(1193)]),this[s(787)+s(342)]=!1,this._ws&&e[s(1195)](this._ws[s(268)+"te"],this[s(1222)]))this[s(1166)+s(120)](1e3,e[s(1508)],!0);else if(e[s(385)](e[s(323)],s(961))){let w=_0x51d4de.bytes,E=_0x4a08cd.limit;return rsaYTV[s(705)](w[s(1605)],E)?w:w.subarray(0,E)}else this._isInit=!0,this[s(1375)]()}async connect(){let r=t;if(!this._connectLock){let s=e[r(1051)][r(376)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[r(490)+r(623)]?.[r(524)+r(223)]();continue;case"1":this._isInit=!0;continue;case"2":this[r(321)+r(908)]?.["resetEnd"+r(1598)+r(188)]();continue;case"3":this[r(1375)]();continue;case"4":this._readyClosed=!1;continue}break}}}[t(796)+t(1579)](r,s){let d=t;if(e.pKzwA===e[d(489)])this.on(r,s);else{let f=e[d(277)].split("|"),g=0;for(;;){switch(f[g++]){case"0":_0x125f07[_0x3771aa["MAX_RETR"+d(551)+"R"]=5003]=e.Pcypw;continue;case"1":_0x3ea062[_0x269744[e.fmrZx]=5005]=e.fmrZx;continue;case"2":_0x18c662[_0x629fca[e.IUyvV]=5001]=d(872)+d(176);continue;case"3":_0x11e3a1[_0x520313[d(835)+d(168)]=5002]=d(835)+"NG_ERROR";continue;case"4":_0x13184f[_0x1f5fbd[e[d(1447)]]=5004]=e[d(1447)];continue;case"5":return _0x5459bb}break}}}[t(825)+"Event"](r){let s=t,{type:d}=r;this[s(949)](d,r)}[t(992)+t(469)+"ner"](r,s){this[t(573)](r,s)}[t(739)](){let r=t,s={QmLdV:function(d,f){return e[J(248)](d,f)},kWMRj:e[r(204)],LiSJF:e[r(238)],wzuQx:r(409)+r(1390)+"s"};if(e[r(124)](e[r(1049)],e.iQEHt))_0x66b54b.log(_0x1f8972);else return new Promise((d,f)=>{let g=r,w={AagkD:function(D,N){return s[J(545)](D,N)},SriNp:"success",znmrE:s[g(650)],INImS:s[g(217)]};this[g(256)+g(1432)](),this[g(425)+"gTimeoutId"]=setTimeout(this._ping.bind(this),this[g(1062)][g(1506)+g(1298)]);let E=()=>{let D=g;w[D(919)](d,w.SriNp),this[D(573)](D(409)+D(1390)+"s",E),this[D(573)]("ping_onc"+D(310)+"t",p)},p=()=>{let D=g;w[D(919)](f,w[D(720)]),this[D(573)](D(409)+D(1390)+"s",E),this[D(573)](w.INImS,p)};this.on(s[g(461)],E),this.on(s.LiSJF,p),this._ping()})}}})(),Me[L(1014)+"oseEvent"]=Ce[L(1014)+L(683)],Me[L(368)+L(1080)]=Ce[L(368)+L(1080)],Me[L(281)+"e"]=Ce[L(281)+"e"],Me[L(280)]=Ce[L(280)],Me[L(619)]=Ce[L(619)],Me["Frontier"+L(685)+L(1323)]=Ce[L(834)+L(685)+L(1323)],Me[L(685)+L(1323)]=Ce[L(685)+L(1323)],Me[L(1546)+"t"]=Ce[L(1546)+"t"],Me[L(766)+L(1400)]=Ce[L(766)+L(1400)],Me["createCl"+L(683)]=Ce[L(697)+L(683)],Me[L(1011)+L(1080)]=Ce[L(1011)+L(1080)],Me[L(420)+L(661)+"nt"]=Ce[L(420)+L(661)+"nt"],Me[L(656)+L(373)]=Ce.createOpenEvent,Me[L(1226)+L(1503)+"vent"]=Ce["createRe"+L(1503)+L(1323)],Me[L(431)+L(178)]=Ce[L(431)+"rame"],Me[L(1548)+"ame"]=Ce[L(1548)+L(1188)];for(jo in Ce)[L(1014)+L(683),L(368)+L(1080),L(281)+"e",L(280),L(619),L(834)+L(685)+L(1323),"MessageEvent",L(1546)+"t",L(766)+L(1400),L(697)+L(683),L(1011)+L(1080),L(420)+L(661)+"nt",L(656)+L(373),L(1226)+L(1503)+L(1323),L(431)+"rame",L(1548)+L(1188)][L(603)](jo)===-1&&(Me[jo]=Ce[jo]);var jo;Object[L(1140)+L(562)](Me,L(885)+"le",{value:!0})});import{existsSync as k1,openSync as R1}from"node:fs";import{mkdir as C1}from"node:fs/promises";import{dirname as P1}from"node:path";import{fileURLToPath as D1}from"node:url";function N1(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Ul(t=ee()){return k1(t.libEntry)?t.libEntry:D1(new URL("../index.ts",import.meta.url))}async function $x(t={}){let e=t.paths??ee(),n=t.entryOverride??Ul(e),i=N1(e,process.env.COZE_BRIDGE_LOG_MODE);await C1(P1(i),{recursive:!0});let o=R1(i,"a"),l=n.endsWith(".ts")?["--import","tsx/esm",n,"--daemon"]:[n,"--daemon"],u=rt(process.execPath,l,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[ss]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return O1.info("daemon spawned",{pid:u.pid,entry:n}),{pid:u.pid,entry:n}}var O1,ss,ta=et(()=>{"use strict";$t();ne();Oe();O1=G("spawn-daemon"),ss="COZE_BRIDGE_DAEMON"});import{spawn as CS}from"node:child_process";import{mkdir as PS,unlink as DS,writeFile as OS}from"node:fs/promises";import{dirname as NS,join as LS}from"node:path";function Jr(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function MS(t){if(!t)return"";let e=Object.entries(t).map(([n,i])=>` <key>${Jr(n)}</key>
21
+ <string>${Jr(i)}</string>`).join(`
22
22
  `);return e?`
23
23
  <key>EnvironmentVariables</key>
24
24
  <dict>
25
25
  ${e}
26
- </dict>`:""}function u2(t,e){return new Promise((r,i)=>{let o=i2(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 Yr,ls,ha,cl,Ip=nt(()=>{"use strict";ie();Yr=j("supervisor.launchd"),ls="ai.coze.bridge",ha=u2,cl={platform:"darwin",renderConfig(t){return`<?xml version="1.0" encoding="UTF-8"?>
26
+ </dict>`:""}function BS(t,e){return new Promise((n,i)=>{let o=CS(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?n():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var Vr,cs,aa,Zl,pp=et(()=>{"use strict";ne();Vr=G("supervisor.launchd"),cs="ai.coze.bridge",aa=BS,Zl={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>${ls}</string>
31
+ <string>${cs}</string>
32
32
  <key>ProgramArguments</key>
33
33
  <array>
34
- <string>${Qr(t.nodeBin)}</string>
35
- <string>${Qr(t.entry)}</string>
34
+ <string>${Jr(t.nodeBin)}</string>
35
+ <string>${Jr(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>${Qr(t.logFile)}</string>
45
+ <string>${Jr(t.logFile)}</string>
46
46
  <key>StandardErrorPath</key>
47
- <string>${Qr(t.logFile)}</string>${l2(t.env)}
47
+ <string>${Jr(t.logFile)}</string>${MS(t.env)}
48
48
  </dict>
49
49
  </plist>
50
- `},configPath(t){return d2(t.homeDir,"Library","LaunchAgents",`${ls}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await s2(c2(i),{recursive:!0}),await a2(i,this.renderConfig(t),"utf8"),Yr.info("plist written",{plistPath:i,activate:r}),!r)return;await ha("launchctl",["unload","-w",i]).catch(c=>Yr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await ha("launchctl",["load","-w",i]),Yr.info("launchd job loaded",{label:ls});let o=process.getuid?.()??0;await ha("launchctl",["kickstart","-k",`gui/${o}/${ls}`]),Yr.info("launchd job kickstarted",{label:ls,uid:o})},async uninstall(t){let e=this.configPath(t);await ha("launchctl",["unload","-w",e]).catch(r=>Yr.warn("launchctl unload failed (ignored)",{err:String(r)})),await o2(e).catch(r=>{if(r.code!=="ENOENT")throw r}),Yr.info("launchd job removed",{plistPath:e})}}});import{spawn as f2}from"node:child_process";import{mkdir as x2,unlink as h2,writeFile as p2}from"node:fs/promises";import{dirname as g2,join as kp}from"node:path";function ga(t,e){return t.isRoot?e:["--user",...e]}function w2(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
- `):""}function ma(t,e){return new Promise((r,i)=>{let o=f2(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 pa,ei,m2,dl,Tp=nt(()=>{"use strict";ie();pa=j("supervisor.systemd"),ei="coze-bridge.service",m2="/etc/systemd/system";dl={platform:"linux",renderConfig(t){let e=t.isRoot?"multi-user.target":"default.target";return`[Unit]
50
+ `},configPath(t){return LS(t.homeDir,"Library","LaunchAgents",`${cs}.plist`)},async install(t,e){let n=e?.activate!==!1,i=this.configPath(t);if(await PS(NS(i),{recursive:!0}),await OS(i,this.renderConfig(t),"utf8"),Vr.info("plist written",{plistPath:i,activate:n}),!n)return;await aa("launchctl",["unload","-w",i]).catch(c=>Vr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await aa("launchctl",["load","-w",i]),Vr.info("launchd job loaded",{label:cs});let o=process.getuid?.()??0;await aa("launchctl",["kickstart","-k",`gui/${o}/${cs}`]),Vr.info("launchd job kickstarted",{label:cs,uid:o})},async uninstall(t){let e=this.configPath(t);await aa("launchctl",["unload","-w",e]).catch(n=>Vr.warn("launchctl unload failed (ignored)",{err:String(n)})),await DS(e).catch(n=>{if(n.code!=="ENOENT")throw n}),Vr.info("launchd job removed",{plistPath:e})}}});import{spawn as FS}from"node:child_process";import{mkdir as zS,unlink as US,writeFile as GS}from"node:fs/promises";import{dirname as qS,join as gp}from"node:path";function la(t,e){return t.isRoot?e:["--user",...e]}function jS(t){return t?Object.entries(t).map(([e,n])=>{let i=n.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
+ `):""}function da(t,e){return new Promise((n,i)=>{let o=FS(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?n():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var ca,Zr,HS,Yl,mp=et(()=>{"use strict";ne();ca=G("supervisor.systemd"),Zr="coze-bridge.service",HS="/etc/systemd/system";Yl={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
- ${w2(t.env)}
62
+ ${jS(t.env)}
63
63
  [Install]
64
64
  WantedBy=${e}
65
- `},configPath(t){return t.isRoot?kp(m2,ei):kp(t.homeDir,".config","systemd","user",ei)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await x2(g2(i),{recursive:!0}),await p2(i,this.renderConfig(t),"utf8"),pa.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await ma("systemctl",ga(t,["daemon-reload"])),await ma("systemctl",ga(t,r?["enable","--now",ei]:["enable",ei])),pa.info("systemd unit enabled",{unitName:ei,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await ma("systemctl",ga(t,["disable","--now",ei])).catch(r=>pa.warn("systemctl disable failed (ignored)",{err:String(r)})),await h2(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await ma("systemctl",ga(t,["daemon-reload"])).catch(()=>{}),pa.info("systemd unit removed",{unitPath:e})}}});import{spawn as _2}from"node:child_process";import{join as y2}from"node:path";function Cp(t,e){return new Promise((r,i)=>{let o=_2(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 ll,wa,ul,Rp=nt(()=>{"use strict";ie();ll=j("supervisor.taskscheduler"),wa="CozeBridge",ul={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
65
+ `},configPath(t){return t.isRoot?gp(HS,Zr):gp(t.homeDir,".config","systemd","user",Zr)},async install(t,e){let n=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await zS(qS(i),{recursive:!0}),await GS(i,this.renderConfig(t),"utf8"),ca.info("systemd unit written",{unitPath:i,mode:o,activate:n}),await da("systemctl",la(t,["daemon-reload"])),await da("systemctl",la(t,n?["enable","--now",Zr]:["enable",Zr])),ca.info("systemd unit enabled",{unitName:Zr,mode:o,activate:n})},async uninstall(t){let e=this.configPath(t);await da("systemctl",la(t,["disable","--now",Zr])).catch(n=>ca.warn("systemctl disable failed (ignored)",{err:String(n)})),await US(e).catch(n=>{if(n.code!=="ENOENT")throw n}),await da("systemctl",la(t,["daemon-reload"])).catch(()=>{}),ca.info("systemd unit removed",{unitPath:e})}}});import{spawn as WS}from"node:child_process";import{join as KS}from"node:path";function wp(t,e){return new Promise((n,i)=>{let o=WS(t,e,{stdio:["ignore","pipe","pipe"],shell:!1}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?n():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var Xl,ua,Ql,_p=et(()=>{"use strict";ne();Xl=G("supervisor.taskscheduler"),ua="CozeBridge",Ql={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,52 +86,50 @@ WantedBy=${e}
86
86
  </Exec>
87
87
  </Actions>
88
88
  </Task>
89
- `},configPath(t){return y2(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 Cp("schtasks",["/Create","/SC","ONLOGON","/TN",wa,"/TR",r,"/RU",t.userName,"/F"]),ll.info("task scheduler entry created",{task:wa,logFile:t.logFile})},async uninstall(t){await Cp("schtasks",["/Delete","/TN",wa,"/F"]).catch(e=>ll.warn("schtasks /Delete failed (ignored)",{err:String(e)})),ll.info("task scheduler entry removed",{task:wa})}}});var Dp={};Pa(Dp,{buildContext:()=>I2,getSupervisor:()=>v2,launchdSupervisor:()=>cl,systemdSupervisor:()=>dl,taskSchedulerSupervisor:()=>ul});import{homedir as b2,userInfo as E2}from"node:os";function v2(t=process.platform){switch(t){case"darwin":return cl;case"linux":return dl;case"win32":return ul;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function A2(){let t={};for(let e of S2){let r=process.env[e];r&&(t[e]=r)}return t}function I2(){let t=Y();return{nodeBin:process.execPath,entry:Yd(t),logFile:t.logFile,homeDir:b2(),userName:E2().username,isRoot:process.getuid?.()===0,env:A2()}}var S2,Pp=nt(()=>{"use strict";Pe();ca();Ip();Tp();Rp();S2=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ie();an();var Hl=j("acp-installer-warmup"),om=["claude-code","codex"];async function Gl(t={}){let e=t.ensure??xr,i=(await Promise.allSettled(om.map(async o=>{let c=await e(o);Hl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&Hl.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();ie();import{readdir as Em}from"node:fs/promises";import{mkdir as Kl,readFile as ym,writeFile as $l}from"node:fs/promises";import{join as za}from"node:path";var bm={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function hr(t,e,r){await Kl(t,{recursive:!0});let i=bm[e],o=za(t,i);return await $l(o,r??"","utf8"),o}async function Ua(t,e,r){let i=za(t,".claude");await Kl(i,{recursive:!0});let o=za(i,"settings.local.json"),c={};try{let u=await ym(o,"utf8"),x=JSON.parse(u);typeof x=="object"&&x!==null&&!Array.isArray(x)&&(c=x)}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 $l(o,JSON.stringify(c,null,2),"utf8"),o}var Ye=j("agent-detail-sync"),vm=6e4,Sm=5*6e4,vs=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await Em(r)}catch(o){Ye.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}Ye.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Oe(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Ye.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(d){Ye.warn("detail sync failed for agent, skipping",{agentId:o,err:String(d)})}}})),Ye.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),r=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&r.push(i);if(r.length!==0){Ye.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){Ye.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Oe(e,this.opts.paths);if(!i){Ye.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(x){Ye.warn("detail RPC failed, using local data",{agentId:e,err:String(x)});let h=this.retryQueue.get(e),p=h?Math.min(h.currentDelay*2,Sm):vm;this.retryQueue.set(e,{dueAt:Date.now()+p,currentDelay:p});return}if(o.agentId&&o.agentId!==e){Ye.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,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"?(Ye.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&Ye.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Ye.debug("detail sync: no diff",{agentId:e});return}await Ue(i,this.opts.paths),Ye.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}),Ye.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 cd=Gt(Iu(),1);import{createHash as ry}from"node:crypto";import{lstat as td,mkdir as nd,readFile as mo,readdir as u0,rm as rd,stat as f0,writeFile as id}from"node:fs/promises";import{homedir as iy}from"node:os";import{dirname as sy,join as _e,normalize as oy,relative as ad,resolve as sd,sep as x0}from"node:path";import{Readable as h0}from"node:stream";import{pipeline as p0}from"node:stream/promises";import Km from"events";import rt from"fs";import{EventEmitter as zc}from"node:events";import cf from"node:stream";import{StringDecoder as $m}from"node:string_decoder";import uf from"node:path";import Ir from"node:fs";import{dirname as ow,parse as aw}from"path";import{EventEmitter as pw}from"events";import yc from"assert";import{Buffer as Kn}from"buffer";import*as Du from"zlib";import gw from"zlib";import{posix as _r}from"node:path";import{basename as qw}from"node:path";import to from"fs";import Rt from"fs";import Fu from"path";import{win32 as e_}from"node:path";import Wu from"path";import If from"node:fs";import m_ from"node:assert";import{randomBytes as kf}from"node:crypto";import oe from"node:fs";import ze from"node:path";import Tf from"fs";import uo from"node:fs";import ki from"node:path";import ct from"node:fs";import S_ from"node:fs/promises";import io from"node:path";import{join as zf}from"node:path";import at from"node:fs";import Gf from"node:path";var jm=Object.defineProperty,Wm=(t,e)=>{for(var r in e)jm(t,r,{get:e[r],enumerable:!0})},ku=typeof process=="object"&&process?process:{stdout:null,stderr:null},Vm=t=>!!t&&typeof t=="object"&&(t instanceof Jn||t instanceof cf||Jm(t)||Zm(t)),Jm=t=>!!t&&typeof t=="object"&&t instanceof zc&&typeof t.pipe=="function"&&t.pipe!==cf.Writable.prototype.pipe,Zm=t=>!!t&&typeof t=="object"&&t instanceof zc&&typeof t.write=="function"&&typeof t.end=="function",qt=Symbol("EOF"),jt=Symbol("maybeEmitEnd"),hn=Symbol("emittedEnd"),Ts=Symbol("emittingEnd"),li=Symbol("emittedError"),Cs=Symbol("closed"),Tu=Symbol("read"),Rs=Symbol("flush"),Cu=Symbol("flushChunk"),_t=Symbol("encoding"),wr=Symbol("decoder"),He=Symbol("flowing"),ui=Symbol("paused"),vr=Symbol("resume"),Ge=Symbol("buffer"),Qe=Symbol("pipes"),qe=Symbol("bufferLength"),Ka=Symbol("bufferPush"),Ds=Symbol("bufferShift"),Xe=Symbol("objectMode"),Te=Symbol("destroyed"),$a=Symbol("error"),Va=Symbol("emitData"),Ru=Symbol("emitEnd"),Ja=Symbol("emitEnd2"),kt=Symbol("async"),Za=Symbol("abort"),Ps=Symbol("aborted"),fi=Symbol("signal"),Bn=Symbol("dataListeners"),ot=Symbol("discarded"),xi=t=>Promise.resolve().then(t),Xm=t=>t(),Ym=t=>t==="end"||t==="finish"||t==="prefinish",Qm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,ew=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),df=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[vr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},tw=class extends df{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)}},nw=t=>!!t.objectMode,rw=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Jn=class extends zc{[He]=!1;[ui]=!1;[Qe]=[];[Ge]=[];[Xe];[_t];[kt];[wr];[qt]=!1;[hn]=!1;[Ts]=!1;[Cs]=!1;[li]=null;[qe]=0;[Te]=!1;[fi];[Ps]=!1;[Bn]=0;[ot]=!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");nw(e)?(this[Xe]=!0,this[_t]=null):rw(e)?(this[_t]=e.encoding,this[Xe]=!1):(this[Xe]=!1,this[_t]=null),this[kt]=!!e.async,this[wr]=this[_t]?new $m(this[_t]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Ge]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Qe]});let{signal:r}=e;r&&(this[fi]=r,r.aborted?this[Za]():r.addEventListener("abort",()=>this[Za]()))}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[Xe]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[kt]}set async(t){this[kt]=this[kt]||!!t}[Za](){this[Ps]=!0,this.emit("abort",this[fi]?.reason),this.destroy(this[fi]?.reason)}get aborted(){return this[Ps]}set aborted(t){}write(t,e,r){if(this[Ps])return!1;if(this[qt])throw new Error("write after end");if(this[Te])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[kt]?xi:Xm;if(!this[Xe]&&!Buffer.isBuffer(t)){if(ew(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(Qm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Xe]?(this[He]&&this[qe]!==0&&this[Rs](!0),this[He]?this.emit("data",t):this[Ka](t),this[qe]!==0&&this.emit("readable"),r&&i(r),this[He]):t.length?(typeof t=="string"&&!(e===this[_t]&&!this[wr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[_t]&&(t=this[wr].write(t)),this[He]&&this[qe]!==0&&this[Rs](!0),this[He]?this.emit("data",t):this[Ka](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[Te])return null;if(this[ot]=!1,this[qe]===0||t===0||t&&t>this[qe])return this[jt](),null;this[Xe]&&(t=null),this[Ge].length>1&&!this[Xe]&&(this[Ge]=[this[_t]?this[Ge].join(""):Buffer.concat(this[Ge],this[qe])]);let e=this[Tu](t||null,this[Ge][0]);return this[jt](),e}[Tu](t,e){if(this[Xe])this[Ds]();else{let r=e;t===r.length||t===null?this[Ds]():typeof r=="string"?(this[Ge][0]=r.slice(t),e=r.slice(0,t),this[qe]-=t):(this[Ge][0]=r.subarray(t),e=r.subarray(0,t),this[qe]-=t)}return this.emit("data",e),!this[Ge].length&&!this[qt]&&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[qt]=!0,this.writable=!1,(this[He]||!this[ui])&&this[jt](),this}[vr](){this[Te]||(!this[Bn]&&!this[Qe].length&&(this[ot]=!0),this[ui]=!1,this[He]=!0,this.emit("resume"),this[Ge].length?this[Rs]():this[qt]?this[jt]():this.emit("drain"))}resume(){return this[vr]()}pause(){this[He]=!1,this[ui]=!0,this[ot]=!1}get destroyed(){return this[Te]}get flowing(){return this[He]}get paused(){return this[ui]}[Ka](t){this[Xe]?this[qe]+=1:this[qe]+=t.length,this[Ge].push(t)}[Ds](){return this[Xe]?this[qe]-=1:this[qe]-=this[Ge][0].length,this[Ge].shift()}[Rs](t=!1){do;while(this[Cu](this[Ds]())&&this[Ge].length);!t&&!this[Ge].length&&!this[qt]&&this.emit("drain")}[Cu](t){return this.emit("data",t),this[He]}pipe(t,e){if(this[Te])return t;this[ot]=!1;let r=this[hn];return e=e||{},t===ku.stdout||t===ku.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[Qe].push(e.proxyErrors?new tw(this,t,e):new df(this,t,e)),this[kt]?xi(()=>this[vr]()):this[vr]()),t}unpipe(t){let e=this[Qe].find(r=>r.dest===t);e&&(this[Qe].length===1?(this[He]&&this[Bn]===0&&(this[He]=!1),this[Qe]=[]):this[Qe].splice(this[Qe].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[ot]=!1,this[Bn]++,!this[Qe].length&&!this[He]&&this[vr]();else if(t==="readable"&&this[qe]!==0)super.emit("readable");else if(Ym(t)&&this[hn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[li]){let i=e;this[kt]?xi(()=>i.call(this,this[li])):i.call(this,this[li])}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[ot]&&!this[Qe].length&&(this[He]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Bn]=0,!this[ot]&&!this[Qe].length&&(this[He]=!1)),e}get emittedEnd(){return this[hn]}[jt](){!this[Ts]&&!this[hn]&&!this[Te]&&this[Ge].length===0&&this[qt]&&(this[Ts]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Cs]&&this.emit("close"),this[Ts]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Te&&this[Te])return!1;if(t==="data")return!this[Xe]&&!r?!1:this[kt]?(xi(()=>this[Va](r)),!0):this[Va](r);if(t==="end")return this[Ru]();if(t==="close"){if(this[Cs]=!0,!this[hn]&&!this[Te])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[li]=r,super.emit($a,r);let o=!this[fi]||this.listeners("error").length?super.emit("error",r):!1;return this[jt](),o}else if(t==="resume"){let o=super.emit("resume");return this[jt](),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[jt](),i}[Va](t){for(let r of this[Qe])r.dest.write(t)===!1&&this.pause();let e=this[ot]?!1:super.emit("data",t);return this[jt](),e}[Ru](){return this[hn]?!1:(this[hn]=!0,this.readable=!1,this[kt]?(xi(()=>this[Ja]()),!0):this[Ja]())}[Ja](){if(this[wr]){let e=this[wr].end();if(e){for(let r of this[Qe])r.dest.write(e);this[ot]||super.emit("data",e)}}for(let e of this[Qe])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Xe]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[Xe]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[Xe])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(Te,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[ot]=!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[qt])return e();let i,o,c=h=>{this.off("data",d),this.off("end",u),this.off(Te,x),e(),o(h)},d=h=>{this.off("error",c),this.off("end",u),this.off(Te,x),this.pause(),i({value:h,done:!!this[qt]})},u=()=>{this.off("error",c),this.off("data",d),this.off(Te,x),e(),i({done:!0,value:void 0})},x=()=>c(new Error("stream destroyed"));return new Promise((h,p)=>{o=p,i=h,this.once(Te,x),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[ot]=!1;let t=!1,e=()=>(this.pause(),this.off($a,e),this.off(Te,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($a,e),this.once(Te,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Te])return t?this.emit("error",t):this.emit(Te),this;this[Te]=!0,this[ot]=!0,this[Ge].length=0,this[qe]=0;let e=this;return typeof e.close=="function"&&!this[Cs]&&e.close(),t?this.emit("error",t):this.emit(Te),this}static get isStream(){return Vm}},iw=rt.writev,Sn=Symbol("_autoClose"),vt=Symbol("_close"),hi=Symbol("_ended"),ue=Symbol("_fd"),Xa=Symbol("_finished"),Vt=Symbol("_flags"),Ya=Symbol("_flush"),wc=Symbol("_handleChunk"),_c=Symbol("_makeBuf"),Ai=Symbol("_mode"),Os=Symbol("_needDrain"),Tr=Symbol("_onerror"),Cr=Symbol("_onopen"),Qa=Symbol("_onread"),Sr=Symbol("_onwrite"),An=Symbol("_open"),Et=Symbol("_path"),_n=Symbol("_pos"),Tt=Symbol("_queue"),Ar=Symbol("_read"),ec=Symbol("_readSize"),$t=Symbol("_reading"),pi=Symbol("_remain"),tc=Symbol("_size"),qs=Symbol("_write"),Fn=Symbol("_writing"),js=Symbol("_defaultFlag"),Wn=Symbol("_errored"),Uc=class extends Jn{[Wn]=!1;[ue];[Et];[ec];[$t]=!1;[tc];[pi];[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[ue]=typeof e.fd=="number"?e.fd:void 0,this[Et]=t,this[ec]=e.readSize||16*1024*1024,this[$t]=!1,this[tc]=typeof e.size=="number"?e.size:1/0,this[pi]=this[tc],this[Sn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[ue]=="number"?this[Ar]():this[An]()}get fd(){return this[ue]}get path(){return this[Et]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[An](){rt.open(this[Et],"r",(t,e)=>this[Cr](t,e))}[Cr](t,e){t?this[Tr](t):(this[ue]=e,this.emit("open",e),this[Ar]())}[_c](){return Buffer.allocUnsafe(Math.min(this[ec],this[pi]))}[Ar](){if(!this[$t]){this[$t]=!0;let t=this[_c]();if(t.length===0)return process.nextTick(()=>this[Qa](null,0,t));rt.read(this[ue],t,0,t.length,null,(e,r,i)=>this[Qa](e,r,i))}}[Qa](t,e,r){this[$t]=!1,t?this[Tr](t):this[wc](e,r)&&this[Ar]()}[vt](){if(this[Sn]&&typeof this[ue]=="number"){let t=this[ue];this[ue]=void 0,rt.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[Tr](t){this[$t]=!0,this[vt](),this.emit("error",t)}[wc](t,e){let r=!1;return this[pi]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[pi]<=0)&&(r=!1,this[vt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[ue]=="number"&&this[Ar](),!1;case"error":return this[Wn]?!1:(this[Wn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},sw=class extends Uc{[An](){let t=!0;try{this[Cr](null,rt.openSync(this[Et],"r")),t=!1}finally{t&&this[vt]()}}[Ar](){let t=!0;try{if(!this[$t]){this[$t]=!0;do{let e=this[_c](),r=e.length===0?0:rt.readSync(this[ue],e,0,e.length,null);if(!this[wc](r,e))break}while(!0);this[$t]=!1}t=!1}finally{t&&this[vt]()}}[vt](){if(this[Sn]&&typeof this[ue]=="number"){let t=this[ue];this[ue]=void 0,rt.closeSync(t),this.emit("close")}}},so=class extends Km{readable=!1;writable=!0;[Wn]=!1;[Fn]=!1;[hi]=!1;[Tt]=[];[Os]=!1;[Et];[Ai];[Sn];[ue];[js];[Vt];[Xa]=!1;[_n];constructor(t,e){e=e||{},super(e),this[Et]=t,this[ue]=typeof e.fd=="number"?e.fd:void 0,this[Ai]=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[js]=e.flags===void 0,this[Vt]=e.flags===void 0?r:e.flags,this[ue]===void 0&&this[An]()}emit(t,...e){if(t==="error"){if(this[Wn])return!1;this[Wn]=!0}return super.emit(t,...e)}get fd(){return this[ue]}get path(){return this[Et]}[Tr](t){this[vt](),this[Fn]=!0,this.emit("error",t)}[An](){rt.open(this[Et],this[Vt],this[Ai],(t,e)=>this[Cr](t,e))}[Cr](t,e){this[js]&&this[Vt]==="r+"&&t&&t.code==="ENOENT"?(this[Vt]="w",this[An]()):t?this[Tr](t):(this[ue]=e,this.emit("open",e),this[Fn]||this[Ya]())}end(t,e){return t&&this.write(t,e),this[hi]=!0,!this[Fn]&&!this[Tt].length&&typeof this[ue]=="number"&&this[Sr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[hi]?(this.emit("error",new Error("write() after end()")),!1):this[ue]===void 0||this[Fn]||this[Tt].length?(this[Tt].push(t),this[Os]=!0,!1):(this[Fn]=!0,this[qs](t),!0)}[qs](t){rt.write(this[ue],t,0,t.length,this[_n],(e,r)=>this[Sr](e,r))}[Sr](t,e){t?this[Tr](t):(this[_n]!==void 0&&typeof e=="number"&&(this[_n]+=e),this[Tt].length?this[Ya]():(this[Fn]=!1,this[hi]&&!this[Xa]?(this[Xa]=!0,this[vt](),this.emit("finish")):this[Os]&&(this[Os]=!1,this.emit("drain"))))}[Ya](){if(this[Tt].length===0)this[hi]&&this[Sr](null,0);else if(this[Tt].length===1)this[qs](this[Tt].pop());else{let t=this[Tt];this[Tt]=[],iw(this[ue],t,this[_n],(e,r)=>this[Sr](e,r))}}[vt](){if(this[Sn]&&typeof this[ue]=="number"){let t=this[ue];this[ue]=void 0,rt.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},lf=class extends so{[An](){let t;if(this[js]&&this[Vt]==="r+")try{t=rt.openSync(this[Et],this[Vt],this[Ai])}catch(e){if(e?.code==="ENOENT")return this[Vt]="w",this[An]();throw e}else t=rt.openSync(this[Et],this[Vt],this[Ai]);this[Cr](null,t)}[vt](){if(this[Sn]&&typeof this[ue]=="number"){let t=this[ue];this[ue]=void 0,rt.closeSync(t),this.emit("close")}}[qs](t){let e=!0;try{this[Sr](null,rt.writeSync(this[ue],t,0,t.length,this[_n])),e=!1}finally{if(e)try{this[vt]()}catch{}}}},cw=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"]]),dw=t=>!!t.sync&&!!t.file,lw=t=>!t.sync&&!!t.file,uw=t=>!!t.sync&&!t.file,fw=t=>!t.sync&&!t.file,xw=t=>!!t.file,hw=t=>cw.get(t)||t,Hc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=hw(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Li=(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 x=Hc(c);if(o?.(x,d),dw(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(x,d)}else if(lw(x)){let h=e(x,d);return u?h.then(()=>u(),u):h}else if(uw(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(x,d)}else if(fw(x)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(x,d)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),mw=gw.constants||{ZLIB_VERNUM:4736},Pt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},mw)),ww=Kn.concat,Pu=Object.getOwnPropertyDescriptor(Kn,"concat"),_w=t=>t,nc=Pu?.writable===!0||Pu?.set!==void 0?t=>{Kn.concat=t?_w:ww}:t=>{},$n=Symbol("_superWrite"),Ls=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"}},rc=Symbol("flushFlag"),Gc=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 Du[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new Du[e](t)}catch(r){throw new Ls(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 Ls(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return yc(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),{[rc]: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;yc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},nc(!0);let d;try{let x=typeof t[rc]=="number"?t[rc]:this.#r;d=this.#t._processChunk(t,x),nc(!1)}catch(x){nc(!1),this.#o(new Ls(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 Ls(x,this.write)));let u;if(d)if(Array.isArray(d)&&d.length>0){let x=d[0];u=this[$n](Kn.from(x));for(let h=1;h<d.length;h++)u=this[$n](d[h])}else u=this[$n](Kn.from(d));return r&&r(),u}},ff=class extends Gc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Pt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Pt.Z_FINISH,t.fullFlushFlag=Pt.Z_FULL_FLUSH,super(t,e),this.#e=t.level,this.#n=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==t||this.#n!==e){this.flush(Pt.Z_SYNC_FLUSH),yc(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)}}}},yw=class extends ff{#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)}},bw=class extends ff{constructor(t){super(t,"Unzip")}},xf=class extends Gc{constructor(t,e){t=t||{},t.flush=t.flush||Pt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Pt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Pt.BROTLI_OPERATION_FLUSH,super(t,e)}},Ew=class extends xf{constructor(t){super(t,"BrotliCompress")}},vw=class extends xf{constructor(t){super(t,"BrotliDecompress")}},hf=class extends Gc{constructor(t,e){t=t||{},t.flush=t.flush||Pt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Pt.ZSTD_e_end,t.fullFlushFlag=Pt.ZSTD_e_flush,super(t,e)}},Sw=class extends hf{constructor(t){super(t,"ZstdCompress")}},Aw=class extends hf{constructor(t){super(t,"ZstdDecompress")}},Iw=(t,e)=>{if(Number.isSafeInteger(t))t<0?Tw(t,e):kw(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},kw=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},Tw=(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]=pf(o):o===0?e[i-1]=0:(r=!0,e[i-1]=gf(o))}},Cw=t=>{let e=t[0],r=e===128?Dw(t.subarray(1,t.length)):e===255?Rw(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},Rw=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),d;i?d=pf(c):c===0?d=c:(i=!0,d=gf(c)),d!==0&&(r-=d*Math.pow(256,e-o-1))}return r},Dw=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},pf=t=>(255^t)&255,gf=t=>(255^t)+1&255,Pw={};Wm(Pw,{code:()=>qc,isCode:()=>Ws,isName:()=>Ow,name:()=>oo});var Ws=t=>oo.has(t),Ow=t=>qc.has(t),oo=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"]]),qc=new Map(Array.from(oo).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");this.path=r?.path??zn(t,e,100),this.mode=r?.mode??i?.mode??yn(t,e+100,8),this.uid=r?.uid??i?.uid??yn(t,e+108,8),this.gid=r?.gid??i?.gid??yn(t,e+116,8),this.size=r?.size??i?.size??yn(t,e+124,12),this.mtime=r?.mtime??i?.mtime??ic(t,e+136,12),this.cksum=yn(t,e+148,12),i&&this.#n(i,!0),r&&this.#n(r);let o=zn(t,e+156,1);if(Ws(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=r?.uname??i?.uname??zn(t,e+265,32),this.gname=r?.gname??i?.gname??zn(t,e+297,32),this.devmaj=r?.devmaj??i?.devmaj??yn(t,e+329,8)??0,this.devmin=r?.devmin??i?.devmin??yn(t,e+337,8)??0,t[e+475]!==0){let d=zn(t,e+345,155);this.path=d+"/"+this.path}else{let d=zn(t,e+345,130);d&&(this.path=d+"/"+this.path),this.atime=r?.atime??i?.atime??ic(t,e+476,12),this.ctime=r?.ctime??i?.ctime??ic(t,e+488,12)}let c=256;for(let d=e;d<e+148;d++)c+=t[d];for(let d=e+156;d<e+512;d++)c+=t[d];this.cksumValid=c===this.cksum,this.cksum===void 0&&c===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e||r==="linkpath"&&e||r==="global"))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let r=this.ctime||this.atime?130:155,i=Lw(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=sc(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=sc(t,e+476,12,this.atime)||this.needPax,this.needPax=sc(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:oo.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(qc.get(t));if(Ws(e)||e==="Unsupported")this.#e=e;else if(Ws(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Lw=(t,e)=>{let r=t,i="",o,c=_r.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=_r.dirname(r),r=_r.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=_r.join(_r.basename(i),r),i=_r.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.*/,""),ic=(t,e,r)=>Nw(yn(t,e,r)),Nw=t=>t===void 0?void 0:new Date(t*1e3),yn=(t,e,r)=>Number(t[e])&128?Cw(t.subarray(e,e+r)):Bw(t,e,r),Mw=t=>isNaN(t)?void 0:t,Bw=(t,e,r)=>Mw(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),Fw={12:8589934591,8:2097151},bn=(t,e,r,i)=>i===void 0?!1:i>Fw[r]||i<0?(Iw(i,t.subarray(e,e+r)),!0):(zw(t,e,r,i),!1),zw=(t,e,r,i)=>t.write(Uw(i,r),e,r,"ascii"),Uw=(t,e)=>Hw(Math.floor(t).toString(8),e),Hw=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",sc=(t,e,r,i)=>i===void 0?!1:bn(t,e,r,i.getTime()/1e3),Gw=new Array(156).join("\0"),Un=(t,e,r,i)=>i===void 0?!1:(t.write(i+Gw,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),eo=class mf{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/"+qw(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 mf(jw(Ww(e),r),i)}},jw=(t,e)=>e?Object.assign({},e,t):t,Ww=t=>t.replace(/\n$/,"").split(`
91
- `).reduce(Kw,Object.create(null)),Kw=(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},$w=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,te=$w!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),wf=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=te(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?te(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=te(t.path)),t.linkpath&&(t.linkpath=te(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},ao=(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))},Vw=1024*1024,bc=Buffer.from([31,139]),Ec=Buffer.from([40,181,47,253]),Jw=Math.max(bc.length,Ec.length),ft=Symbol("state"),Hn=Symbol("writeEntry"),Wt=Symbol("readEntry"),oc=Symbol("nextEntry"),Ou=Symbol("processEntry"),Ct=Symbol("extendedHeader"),gi=Symbol("globalExtendedHeader"),pn=Symbol("meta"),Lu=Symbol("emitMeta"),we=Symbol("buffer"),Kt=Symbol("queue"),gn=Symbol("ended"),ac=Symbol("emittedEnd"),Gn=Symbol("emit"),Le=Symbol("unzip"),Ns=Symbol("consumeChunk"),Ms=Symbol("consumeChunkSub"),cc=Symbol("consumeBody"),Nu=Symbol("consumeMeta"),Mu=Symbol("consumeHeader"),mi=Symbol("consuming"),dc=Symbol("bufferConcat"),Bs=Symbol("maybeEnd"),yr=Symbol("writing"),mn=Symbol("aborted"),Fs=Symbol("onDone"),qn=Symbol("sawValidEntry"),zs=Symbol("sawNullBlock"),Us=Symbol("sawEOF"),Bu=Symbol("closeStream"),Zw=()=>!0,Oi=class extends pw{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Kt]=[];[we];[Wt];[Hn];[ft]="begin";[pn]="";[Ct];[gi];[gn]=!1;[Le];[mn]=!1;[qn];[zs]=!1;[Us]=!1;[yr]=!1;[mi]=!1;[ac]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Fs,()=>{(this[ft]==="begin"||this[qn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Fs,t.ondone):this.on(Fs,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||Vw,this.filter=typeof t.filter=="function"?t.filter:Zw;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[Bu]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){ao(this,t,e,r)}[Mu](t,e){this[qn]===void 0&&(this[qn]=!1);let r;try{r=new Vn(t,e,this[Ct],this[gi])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[zs]?(this[Us]=!0,this[ft]==="begin"&&(this[ft]="header"),this[Gn]("eof")):(this[zs]=!0,this[Gn]("nullBlock"));else if(this[zs]=!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[Hn]=new wf(r,this[Ct],this[gi]);if(!this[qn])if(o.remain){let c=()=>{o.invalid||(this[qn]=!0)};o.on("end",c)}else this[qn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Gn]("ignoredEntry",o),this[ft]="ignore",o.resume()):o.size>0&&(this[pn]="",o.on("data",c=>this[pn]+=c),this[ft]="meta"):(this[Ct]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Gn]("ignoredEntry",o),this[ft]=o.remain?"ignore":"header",o.resume()):(o.remain?this[ft]="body":(this[ft]="header",o.end()),this[Wt]?this[Kt].push(o):(this[Kt].push(o),this[oc]())))}}}[Bu](){queueMicrotask(()=>this.emit("close"))}[Ou](t){let e=!0;if(!t)this[Wt]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[Wt]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[oc]()),e=!1);return e}[oc](){do;while(this[Ou](this[Kt].shift()));if(this[Kt].length===0){let t=this[Wt];!t||t.flowing||t.size===t.remain?this[yr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[cc](t,e){let r=this[Hn];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[ft]="header",this[Hn]=void 0,r.end()),o.length}[Nu](t,e){let r=this[Hn],i=this[cc](t,e);return!this[Hn]&&r&&this[Lu](r),i}[Gn](t,e,r){this[Kt].length===0&&!this[Wt]?this.emit(t,e,r):this[Kt].push([t,e,r])}[Lu](t){switch(this[Gn]("meta",this[pn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Ct]=eo.parse(this[pn],this[Ct],!1);break;case"GlobalExtendedHeader":this[gi]=eo.parse(this[pn],this[gi],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Ct]??Object.create(null);this[Ct]=e,e.path=this[pn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Ct]||Object.create(null);this[Ct]=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[Le]===void 0||this.brotli===void 0&&this[Le]===!1)&&t){if(this[we]&&(t=Buffer.concat([this[we],t]),this[we]=void 0),t.length<Jw)return this[we]=t,r?.(),!0;for(let d=0;this[Le]===void 0&&d<bc.length;d++)t[d]!==bc[d]&&(this[Le]=!1);let o=!1;if(this[Le]===!1&&this.zstd!==!1){o=!0;for(let d=0;d<Ec.length;d++)if(t[d]!==Ec[d]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Le]===!1&&c)if(t.length<512)if(this[gn])this.brotli=!0;else return this[we]=t,r?.(),!0;else try{new Vn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Le]===void 0||this[Le]===!1&&(this.brotli||o)){let d=this[gn];this[gn]=!1,this[Le]=this[Le]===void 0?new bw({}):o?new Aw({}):new vw({}),this[Le].on("data",x=>this[Ns](x)),this[Le].on("error",x=>this.abort(x)),this[Le].on("end",()=>{this[gn]=!0,this[Ns]()}),this[yr]=!0;let u=!!this[Le][d?"end":"write"](t);return this[yr]=!1,r?.(),u}}this[yr]=!0,this[Le]?this[Le].write(t):this[Ns](t),this[yr]=!1;let i=this[Kt].length>0?!1:this[Wt]?this[Wt].flowing:!0;return!i&&this[Kt].length===0&&this[Wt]?.once("drain",()=>this.emit("drain")),r?.(),i}[dc](t){t&&!this[mn]&&(this[we]=this[we]?Buffer.concat([this[we],t]):t)}[Bs](){if(this[gn]&&!this[ac]&&!this[mn]&&!this[mi]){this[ac]=!0;let t=this[Hn];if(t&&t.blockRemain){let e=this[we]?this[we].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[we]&&t.write(this[we]),t.end()}this[Gn](Fs)}}[Ns](t){if(this[mi]&&t)this[dc](t);else if(!t&&!this[we])this[Bs]();else if(t){if(this[mi]=!0,this[we]){this[dc](t);let e=this[we];this[we]=void 0,this[Ms](e)}else this[Ms](t);for(;this[we]&&this[we]?.length>=512&&!this[mn]&&!this[Us];){let e=this[we];this[we]=void 0,this[Ms](e)}this[mi]=!1}(!this[we]||this[gn])&&this[Bs]()}[Ms](t){let e=0,r=t.length;for(;e+512<=r&&!this[mn]&&!this[Us];)switch(this[ft]){case"begin":case"header":this[Mu](t,e),e+=512;break;case"ignore":case"body":e+=this[cc](t,e);break;case"meta":e+=this[Nu](t,e);break;default:throw new Error("invalid state: "+this[ft])}e<r&&(this[we]=this[we]?Buffer.concat([t.subarray(e),this[we]]):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[Le]?(t&&this[Le].write(t),this[Le].end()):(this[gn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Bs]())),this}},Ii=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)},Xw=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},_f=(t,e)=>{let r=new Map(e.map(c=>[Ii(c),!0])),i=t.filter,o=(c,d="")=>{let u=d||aw(c).root||".",x;if(c===u)x=!1;else{let h=r.get(c);x=h!==void 0?h:o(ow(c),u)}return r.set(c,x),x};t.filter=i?(c,d)=>i(c,d)&&o(Ii(c)):c=>o(Ii(c))},Yw=t=>{let e=new Oi(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 x=Ir.readSync(i,u,0,c,d);if(x===0)break;d+=x,e.write(u.subarray(0,x))}e.end()}}finally{if(typeof i=="number")try{Ir.closeSync(i)}catch{}}},Qw=(t,e)=>{let r=new Oi(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,x)=>{if(u)d(u);else{let h=new Uc(o,{readSize:i,size:x.size});h.on("error",d),h.pipe(r)}})})},Rr=Li(Yw,Qw,t=>new Oi(t),t=>new Oi(t),(t,e)=>{e?.length&&_f(t,e),t.noResume||Xw(t)}),yf=(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:t_,parse:zu}=e_,jc=t=>{let e="",r=zu(t);for(;t_(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=zu(t)}return[e,t]},co=["|","<",">","?",":"],Wc=co.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),n_=new Map(co.map((t,e)=>[t,Wc[e]])),r_=new Map(Wc.map((t,e)=>[t,co[e]])),Uu=t=>co.reduce((e,r)=>e.split(r).join(n_.get(r)),t),i_=t=>Wc.reduce((e,r)=>e.split(r).join(r_.get(r)),t),bf=(t,e)=>e?(t=te(t).replace(/^\.(\/|$)/,""),Ii(e)+"/"+t):te(t),s_=16*1024*1024,Hu=Symbol("process"),Gu=Symbol("file"),qu=Symbol("directory"),vc=Symbol("symlink"),ju=Symbol("hardlink"),wi=Symbol("header"),Ks=Symbol("read"),Sc=Symbol("lstat"),$s=Symbol("onlstat"),Ac=Symbol("onread"),Ic=Symbol("onreadlink"),kc=Symbol("openfile"),Tc=Symbol("onopenfile"),En=Symbol("close"),no=Symbol("mode"),Cc=Symbol("awaitDrain"),lc=Symbol("ondrain"),Dt=Symbol("prefix"),Ef=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=Hc(e);super(),this.path=te(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||s_,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=te(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?te(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]=jc(this.path);c&&typeof d=="string"&&(this.path=d,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=i_(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=te(r.absolute||Fu.resolve(this.cwd,t)),this.path===""&&(this.path="./"),i&&this.warn("TAR_ENTRY_INFO",`stripping ${i} from absolute path`,{entry:this,path:i+this.path});let o=this.statCache.get(this.absolute);o?this[$s](o):this[Sc]()}warn(t,e,r={}){return ao(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[Sc](){Rt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[$s](e)})}[$s](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=c_(t),this.emit("stat",t),this[Hu]()}[Hu](){switch(this.type){case"File":return this[Gu]();case"Directory":return this[qu]();case"SymbolicLink":return this[vc]();default:return this.end()}}[no](t){return yf(t,this.type==="Directory",this.portable)}[Dt](t){return bf(t,this.prefix)}[wi](){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[Dt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Dt](this.linkpath):this.linkpath,mode:this[no](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 eo({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[Dt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Dt](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)}[qu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[wi](),this.end()}[vc](){Rt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Ic](e)})}[Ic](t){this.linkpath=te(t),this[wi](),this.end()}[ju](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=te(Fu.relative(this.cwd,t)),this.stat.size=0,this[wi](),this.end()}[Gu](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){let t=`${this.stat.dev}:${this.stat.ino}`,e=this.linkCache.get(t);if(e?.indexOf(this.cwd)===0)return this[ju](e);this.linkCache.set(t,this.absolute)}if(this[wi](),this.stat.size===0)return this.end();this[kc]()}[kc](){Rt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[Tc](e)})}[Tc](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[Ks]()}[Ks](){let{fd:t,buf:e,offset:r,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");Rt.read(t,e,r,i,o,(c,d)=>{if(c)return this[En](()=>this.emit("error",c));this[Ac](d)})}[En](t=()=>{}){this.fd!==void 0&&Rt.close(this.fd,t)}[Ac](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[lc]():this[Cc](()=>this[lc]())}[Cc](t){this.once("drain",t)}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this.blockRemain<t.length){let i=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",i)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,r)}[lc](){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[Ks]()}},o_=class extends Ef{sync=!0;[Sc](){this[$s](Rt.lstatSync(this.absolute))}[vc](){this[Ic](Rt.readlinkSync(this.absolute))}[kc](){this[Tc](Rt.openSync(this.absolute,"r"))}[Ks](){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=Rt.readSync(e,r,i,o,c);this[Ac](d),t=!1}finally{if(t)try{this[En](()=>{})}catch{}}}[Cc](t){t()}[En](t=()=>{}){this.fd!==void 0&&Rt.closeSync(this.fd),t()}},a_=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 ao(this,t,e,r)}constructor(t,e={}){let r=Hc(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=te(t.path),this.mode=t.mode!==void 0?this[no](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?te(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[d,u]=jc(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[Dt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Dt](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 eo({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[Dt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Dt](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)}[Dt](t){return bf(t,this.prefix)}[no](t){return yf(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}},c_=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",d_=class kr{tail;head;length=0;static create(e=[]){return new kr(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++)u_(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)f_(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 kr;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 kr;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 kr;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 kr;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=l_(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 l_(t,e,r){let i=e,o=e?e.next:t.head,c=new Kc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function u_(t,e){t.tail=new Kc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function f_(t,e){t.head=new Kc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Kc=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}},Ku=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},$u=Buffer.alloc(1024),Vs=Symbol("onStat"),_i=Symbol("ended"),yt=Symbol("queue"),yi=Symbol("queue"),wn=Symbol("current"),jn=Symbol("process"),bi=Symbol("processing"),Hs=Symbol("processJob"),bt=Symbol("jobs"),uc=Symbol("jobDone"),Js=Symbol("addFSEntry"),Vu=Symbol("addTarEntry"),Rc=Symbol("stat"),Dc=Symbol("readdir"),Zs=Symbol("onreaddir"),Xs=Symbol("pipe"),Ju=Symbol("entry"),fc=Symbol("entryOpt"),Ys=Symbol("writeEntryClass"),vf=Symbol("write"),xc=Symbol("ondrain"),lo=class extends Jn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Ys];onWriteEntry;[yt];[yi]=new Map;[bt]=0;[bi]=!1;[_i]=!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=te(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[Ys]=Ef,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 yw(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new Ew(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new Sw(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[xc]()),this.on("resume",()=>e.resume())}else this.on("drain",this[xc]);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 d_,this[bt]=0,this.jobs=Number(t.jobs)||4,this[bi]=!1,this[_i]=!1}[vf](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[_i]=!0,this[jn](),r&&r(),this}write(t){if(this[_i])throw new Error("write after end");return t instanceof wf?this[Vu](t):this[Js](t),this.flowing}[Vu](t){let e=te(Wu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Ku(t.path,e);r.entry=new a_(t,this[fc](r)),r.entry.on("end",()=>this[uc](r)),this[bt]+=1,this[yt].push(r)}this[jn]()}[Js](t){let e=te(Wu.resolve(this.cwd,t));this[yt].push(new Ku(t,e)),this[jn]()}[Rc](t){t.pending=!0,this[bt]+=1;let e=this.follow?"stat":"lstat";to[e](t.absolute,(r,i)=>{t.pending=!1,this[bt]-=1,r?this.emit("error",r):this[Vs](t,i)})}[Vs](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[Hs](t);else{let r=`${e.dev}:${e.ino}`,i=this[yi].get(r);i?i.push(t):this[yi].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[jn]()}[Dc](t){t.pending=!0,this[bt]+=1,to.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[bt]-=1,e)return this.emit("error",e);this[Zs](t,r)})}[Zs](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[jn]()}[jn](){if(!this[bi]){this[bi]=!0;for(let t=this[yt].head;t&&this[bt]<this.jobs;t=t.next)if(this[Hs](t.value),t.value.ignore){let e=t.next;this[yt].removeNode(t),t.next=e}this[bi]=!1,this[_i]&&this[yt].length===0&&this[bt]===0&&(this.zip?this.zip.end($u):(super.write($u),super.end()))}}get[wn](){return this[yt]&&this[yt].head&&this[yt].head.value}[uc](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[yi].get(r);if(i){this[yi].delete(r);for(let o of i)o.pending=!1,this[Hs](o)}}this[jn]()}[Hs](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[Xs](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Vs](t,e):this[Rc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[Zs](t,e):this[Dc](t),!t.readdir)return}if(t.entry=this[Ju](t),!t.entry){t.ignore=!0;return}t===this[wn]&&!t.piped&&this[Xs](t)}}}[fc](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}}[Ju](t){this[bt]+=1;try{return new this[Ys](t.path,this[fc](t)).on("end",()=>this[uc](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[xc](){this[wn]&&this[wn].entry&&this[wn].entry.resume()}[Xs](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={}){ao(this,t,e,r)}},$c=class extends lo{sync=!0;constructor(t){super(t),this[Ys]=o_}pause(){}resume(){}[Rc](t){let e=this.follow?"statSync":"lstatSync";this[Vs](t,to[e](t.absolute))}[Dc](t){this[Zs](t,to.readdirSync(t.absolute))}[Xs](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[vf](i)})}},x_=(t,e)=>{let r=new $c(t),i=new lf(t.file,{mode:t.mode||438});r.pipe(i),Sf(r,e)},h_=(t,e)=>{let r=new lo(t),i=new so(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},Sf=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Rr({file:uf.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 Rr({file:uf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},p_=(t,e)=>{let r=new $c(t);return Sf(r,e),r},g_=(t,e)=>{let r=new lo(t);return Af(r,e).catch(i=>r.emit("error",i)),r},cI=Li(x_,h_,p_,g_,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),w_=process.env.__FAKE_PLATFORM__||process.platform,Cf=w_==="win32",{O_CREAT:Rf,O_NOFOLLOW:Zu,O_TRUNC:Df,O_WRONLY:Pf}=Tf.constants,Of=Number(process.env.__FAKE_FS_O_FILENAME__)||Tf.constants.UV_FS_O_FILEMAP||0,__=Cf&&!!Of,y_=512*1024,b_=Of|Df|Rf|Pf,Xu=!Cf&&typeof Zu=="number"?Zu|Df|Rf|Pf:null,Lf=Xu!==null?()=>Xu:__?t=>t<y_?b_:"w":()=>"w",Pc=(t,e,r)=>{try{return uo.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},ro=(t,e,r,i)=>{uo.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},E_=(t,e,r,i,o)=>{if(e.isDirectory())Nf(ki.resolve(t,e.name),r,i,c=>{if(c)return o(c);let d=ki.resolve(t,e.name);ro(d,r,i,o)});else{let c=ki.resolve(t,e.name);ro(c,r,i,o)}},Nf=(t,e,r,i)=>{uo.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 ro(t,e,r,i);let d=c.length,u=null,x=h=>{if(!u){if(h)return i(u=h);if(--d===0)return ro(t,e,r,i)}};for(let h of c)E_(t,h,e,r,x)})},v_=(t,e,r,i)=>{e.isDirectory()&&Mf(ki.resolve(t,e.name),r,i),Pc(ki.resolve(t,e.name),r,i)},Mf=(t,e,r)=>{let i;try{i=uo.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return Pc(t,e,r);throw c}for(let o of i)v_(t,o,e,r);return Pc(t,e,r)},Bf=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"}},fo=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"}},A_=(t,e)=>{ct.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new Bf(t,r?.code||"ENOTDIR")),e(r)})},I_=(t,e,r)=>{t=te(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,d=e.uid,u=e.gid,x=typeof d=="number"&&typeof u=="number"&&(d!==e.processUid||u!==e.processGid),h=e.preserve,p=e.unlink,_=te(e.cwd),S=(v,A)=>{v?r(v):A&&x?Nf(A,d,u,k=>S(k)):c?ct.chmod(t,o,r):r()};if(t===_)return A_(t,S);if(h)return S_.mkdir(t,{mode:o,recursive:!0}).then(v=>S(null,v??void 0),S);let y=te(io.relative(_,t)).split("/");Oc(_,y,o,p,_,void 0,S)},Oc=(t,e,r,i,o,c,d)=>{if(e.length===0)return d(null,c);let u=e.shift(),x=te(io.resolve(t+"/"+u));ct.mkdir(x,r,Ff(x,e,r,i,o,c,d))},Ff=(t,e,r,i,o,c,d)=>u=>{u?ct.lstat(t,(x,h)=>{if(x)x.path=x.path&&te(x.path),d(x);else if(h.isDirectory())Oc(t,e,r,i,o,c,d);else if(i)ct.unlink(t,p=>{if(p)return d(p);ct.mkdir(t,r,Ff(t,e,r,i,o,c,d))});else{if(h.isSymbolicLink())return d(new fo(t,t+"/"+e.join("/")));d(u)}}):(c=c||t,Oc(t,e,r,i,o,c,d))},k_=t=>{let e=!1,r;try{e=ct.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new Bf(t,r??"ENOTDIR")}},T_=(t,e)=>{t=te(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),x=e.preserve,h=e.unlink,p=te(e.cwd),_=v=>{v&&u&&Mf(v,c,d),o&&ct.chmodSync(t,i)};if(t===p)return k_(p),_();if(x)return _(ct.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=te(io.relative(p,t)).split("/"),y;for(let v=S.shift(),A=p;v&&(A+="/"+v);v=S.shift()){A=te(io.resolve(A));try{ct.mkdirSync(A,i),y=y||A}catch{let k=ct.lstatSync(A);if(k.isDirectory())continue;if(h){ct.unlinkSync(A),ct.mkdirSync(A,i),y=y||A;continue}else if(k.isSymbolicLink())return new fo(A,A+"/"+S.join("/"))}}return _(y)},hc=Object.create(null),Yu=1e4,br=new Set,C_=t=>{br.has(t)?br.delete(t):hc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),br.add(t);let e=hc[t],r=br.size-Yu;if(r>Yu/10){for(let i of br)if(br.delete(i),delete hc[i],--r<=0)break}return e},R_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,D_=R_==="win32",P_=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=zf(i,r)),e.push(r||"/"),e},[]),O_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=D_?["win32 parallelization disabled"]:t.map(i=>Ii(zf(C_(i))));let r=new Set(t.map(i=>P_(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 x of u)o.add(x)}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 x=d[0];typeof x=="function"&&o.add(x)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},L_=()=>process.umask(),Qu=Symbol("onEntry"),Lc=Symbol("checkFs"),ef=Symbol("checkFs2"),Nc=Symbol("isReusable"),xt=Symbol("makeFs"),Mc=Symbol("file"),Bc=Symbol("directory"),Qs=Symbol("link"),tf=Symbol("symlink"),nf=Symbol("hardlink"),Si=Symbol("ensureNoSymlink"),rf=Symbol("unsupported"),sf=Symbol("checkPath"),pc=Symbol("stripAbsolutePath"),vn=Symbol("mkdir"),je=Symbol("onError"),Gs=Symbol("pending"),of=Symbol("pend"),Er=Symbol("unpend"),gc=Symbol("ended"),mc=Symbol("maybeClose"),Fc=Symbol("skip"),Ti=Symbol("doChown"),Ci=Symbol("uid"),Ri=Symbol("gid"),Di=Symbol("checkedCwd"),N_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Pi=N_==="win32",M_=1024,B_=(t,e)=>{if(!Pi)return oe.unlink(t,e);let r=t+".DELETE."+kf(16).toString("hex");oe.rename(t,r,i=>{if(i)return e(i);oe.unlink(r,e)})},F_=t=>{if(!Pi)return oe.unlinkSync(t);let e=t+".DELETE."+kf(16).toString("hex");oe.renameSync(t,e),oe.unlinkSync(e)},af=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Vc=class extends Oi{[gc]=!1;[Di]=!1;[Gs]=0;reservations=new O_;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[gc]=!0,this[mc]()},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:M_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Pi,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=te(ze.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:L_():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[Qu](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[mc](){this[gc]&&this[Gs]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[pc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=jc(r),d=c.replaceAll(/\\/g,"/").split("/");if(d.includes("..")||Pi&&/^[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=ze.posix.dirname(t.path),x=ze.posix.normalize(ze.posix.join(u,d.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}[sf](t){let e=te(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=te(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[pc](t,"path")||!this[pc](t,"linkpath"))return!1;if(t.absolute=ze.isAbsolute(t.path)?te(ze.resolve(t.path)):te(ze.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:te(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}=ze.win32.parse(String(t.absolute));t.absolute=i+Uu(String(t.absolute).slice(i.length));let{root:o}=ze.win32.parse(t.path);t.path=o+Uu(t.path.slice(o.length))}return!0}[Qu](t){if(!this[sf](t))return t.resume();switch(m_.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[Lc](t);default:return this[rf](t)}}[je](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[Er](),e.resume())}[vn](t,e,r){I_(te(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)}[Ti](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}[Ci](t){return af(this.uid,t.uid,this.processUid)}[Ri](t){return af(this.gid,t.gid,this.processGid)}[Mc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new so(String(t.absolute),{flags:Lf(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&oe.close(i.fd,()=>{}),i.write=()=>!0,this[je](u,t),e()});let o=1,c=u=>{if(u){i.fd&&oe.close(i.fd,()=>{}),this[je](u,t),e();return}--o===0&&i.fd!==void 0&&oe.close(i.fd,x=>{x?this[je](x,t):this[Er](),e()})};i.on("finish",()=>{let u=String(t.absolute),x=i.fd;if(typeof x=="number"&&t.mtime&&!this.noMtime){o++;let h=t.atime||new Date,p=t.mtime;oe.futimes(x,h,p,_=>_?oe.utimes(u,h,p,S=>c(S&&_)):c())}if(typeof x=="number"&&this[Ti](t)){o++;let h=this[Ci](t),p=this[Ri](t);typeof h=="number"&&typeof p=="number"&&oe.fchown(x,h,p,_=>_?oe.chown(u,h,p,S=>c(S&&_)):c())}c()});let d=this.transform&&this.transform(t)||t;d!==t&&(d.on("error",u=>{this[je](u,t),e()}),t.pipe(d)),d.pipe(i)}[Bc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[vn](String(t.absolute),r,i=>{if(i){this[je](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[Er](),t.resume())};t.mtime&&!this.noMtime&&(o++,oe.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[Ti](t)&&(o++,oe.chown(String(t.absolute),Number(this[Ci](t)),Number(this[Ri](t)),c)),c()})}[rf](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[tf](t,e){let r=te(ze.relative(this.cwd,ze.resolve(ze.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[Si](t,this.cwd,r,()=>this[Qs](t,String(t.linkpath),"symlink",e),i=>{this[je](i,t),e()})}[nf](t,e){let r=te(ze.resolve(this.cwd,String(t.linkpath))),i=te(String(t.linkpath)).split("/");this[Si](t,this.cwd,i,()=>this[Qs](t,r,"link",e),o=>{this[je](o,t),e()})}[Si](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let d=ze.resolve(e,c);oe.lstat(d,(u,x)=>{if(u)return i();if(x?.isSymbolicLink())return o(new fo(d,ze.resolve(d,r.join("/"))));this[Si](t,d,r,i,o)})}[of](){this[Gs]++}[Er](){this[Gs]--,this[mc]()}[Fc](t){this[Er](),t.resume()}[Nc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Pi}[Lc](t){this[of]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[ef](t,r))}[ef](t,e){let r=d=>{e(d)},i=()=>{this[vn](this.cwd,this.dmode,d=>{if(d){this[je](d,t),r();return}this[Di]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let d=te(ze.dirname(String(t.absolute)));if(d!==this.cwd)return this[vn](d,this.dmode,u=>{if(u){this[je](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[Fc](t),r();return}if(d||this[Nc](t,u))return this[xt](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let x=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,h=p=>this[xt](p??null,t,r);return x?oe.chmod(String(t.absolute),Number(t.mode),h):h()}if(t.absolute!==this.cwd)return oe.rmdir(String(t.absolute),x=>this[xt](x??null,t,r))}if(t.absolute===this.cwd)return this[xt](null,t,r);B_(String(t.absolute),x=>this[xt](x??null,t,r))})};this[Di]?o():i()}[xt](t,e,r){if(t){this[je](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[Mc](e,r);case"Link":return this[nf](e,r);case"SymbolicLink":return this[tf](e,r);case"Directory":case"GNUDumpDir":return this[Bc](e,r)}}[Qs](t,e,r,i){oe[r](e,String(t.absolute),o=>{o?this[je](o,t):(this[Er](),t.resume()),i()})}},Ei=t=>{try{return[null,t()]}catch(e){return[e,null]}},Uf=class extends Vc{sync=!0;[xt](t,e){return super[xt](t,e,()=>{})}[Lc](t){if(!this[Di]){let o=this[vn](this.cwd,this.dmode);if(o)return this[je](o,t);this[Di]=!0}if(t.absolute!==this.cwd){let o=te(ze.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[vn](o,this.dmode);if(c)return this[je](c,t)}}let[e,r]=Ei(()=>oe.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Fc](t);if(e||this[Nc](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?Ei(()=>{oe.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[xt](d,t)}let[o]=Ei(()=>oe.rmdirSync(String(t.absolute)));this[xt](o,t)}let[i]=t.absolute===this.cwd?[]:Ei(()=>F_(String(t.absolute)));this[xt](i,t)}[Mc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=d=>{let u;try{oe.closeSync(o)}catch(x){u=x}(d||u)&&this[je](d||u,t),e()},o;try{o=oe.openSync(String(t.absolute),Lf(t.size),r)}catch(d){return i(d)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",d=>this[je](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,x=t.mtime;try{oe.futimesSync(o,u,x)}catch(h){try{oe.utimesSync(String(t.absolute),u,x)}catch{d=h}}}if(this[Ti](t)){let u=this[Ci](t),x=this[Ri](t);try{oe.fchownSync(o,Number(u),Number(x))}catch(h){try{oe.chownSync(String(t.absolute),Number(u),Number(x))}catch{d=d||h}}}i(d)})}[Bc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[vn](String(t.absolute),r);if(i){this[je](i,t),e();return}if(t.mtime&&!this.noMtime)try{oe.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[Ti](t))try{oe.chownSync(String(t.absolute),Number(this[Ci](t)),Number(this[Ri](t)))}catch{}e(),t.resume()}[vn](t,e){try{return T_(te(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}}[Si](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let d of r){c=ze.resolve(c,d);let[u,x]=Ei(()=>oe.lstatSync(c));if(u)return i();if(x.isSymbolicLink())return o(new fo(c,ze.resolve(e,r.join("/"))))}i()}[Qs](t,e,r,i){let o=`${r}Sync`;try{oe[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[je](c,t)}}},z_=t=>{let e=new Uf(t),r=t.file,i=If.statSync(r),o=t.maxReadSize||16*1024*1024;new sw(r,{readSize:o,size:i.size}).pipe(e)},U_=(t,e)=>{let r=new Vc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("close",c),If.stat(o,(u,x)=>{if(u)d(u);else{let h=new Uc(o,{readSize:i,size:x.size});h.on("error",d),h.pipe(r)}})})},Hf=Li(z_,U_,t=>new Uf(t),t=>new Vc(t),(t,e)=>{e?.length&&_f(t,e)}),H_=(t,e)=>{let r=new $c(t),i=!0,o,c;try{try{o=at.openSync(t.file,"r+")}catch(x){if(x?.code==="ENOENT")o=at.openSync(t.file,"w+");else throw x}let d=at.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<d.size;c+=512){for(let p=0,_=0;p<512;p+=_){if(_=at.readSync(o,u,p,u.length-p,c+p),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!_)break e}let x=new Vn(u);if(!x.cksumValid)break;let h=512*Math.ceil((x.size||0)/512);if(c+h+512>d.size)break;c+=h,t.mtimeCache&&x.mtime&&t.mtimeCache.set(String(x.path),x.mtime)}i=!1,G_(t,r,c,o,e)}finally{if(i)try{at.closeSync(o)}catch{}}},G_=(t,e,r,i,o)=>{let c=new lf(t.file,{fd:i,start:r});e.pipe(c),j_(e,o)},q_=(t,e)=>{e=Array.from(e);let r=new lo(t),i=(o,c,d)=>{let u=(S,y)=>{S?at.close(o,v=>d(S)):d(null,y)},x=0;if(c===0)return u(null,0);let h=0,p=Buffer.alloc(512),_=(S,y)=>{if(S||y===void 0)return u(S);if(h+=y,h<512&&y)return at.read(o,p,h,p.length-h,x+h,_);if(x===0&&p[0]===31&&p[1]===139)return u(new Error("cannot append to compressed archives"));if(h<512)return u(null,x);let v=new Vn(p);if(!v.cksumValid)return u(null,x);let A=512*Math.ceil((v.size??0)/512);if(x+A+512>c||(x+=A+512,x>=c))return u(null,x);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),h=0,at.read(o,p,0,512,x,_)};at.read(o,p,0,512,x,_)};return new Promise((o,c)=>{r.on("error",c);let d="r+",u=(x,h)=>{if(x&&x.code==="ENOENT"&&d==="r+")return d="w+",at.open(t.file,d,u);if(x||!h)return c(x);at.fstat(h,(p,_)=>{if(p)return at.close(h,()=>c(p));i(h,_.size,(S,y)=>{if(S)return c(S);let v=new so(t.file,{fd:h,start:y});r.pipe(v),v.on("error",c),v.on("close",o),W_(r,e)})})};at.open(t.file,d,u)})},j_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Rr({file:Gf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},W_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Rr({file:Gf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},vi=Li(H_,q_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!xw(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")}),vI=Li(vi.syncFile,vi.asyncFile,vi.syncNoFile,vi.asyncNoFile,(t,e=[])=>{vi.validate?.(t,e),K_(t)}),K_=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 ht={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",PUBLISH_SKILL:"_agent/publishSkill"};function xo(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function qf(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function ho(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function jf(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function Wf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function Zn(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Jt();$e();ie();Pe();$e();function Dr(t,e){if(xo(t)!=="cloud")throw new T("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Ni(t){return t.startsWith("http://")||t.startsWith("https://")}function Pr(t){return t.endsWith("/")?t.slice(0,-1):t}import{readFileSync as hk}from"node:fs";import{dirname as gk,join as mk}from"node:path";import{fileURLToPath as _k}from"node:url";var Ot="0.2.2-alpha.2";$e();ie();var po="1008033",Jf="1289";var Zf="pbbp2",Xf="https://www.coze.cn",Yf="/api/coze_claw/resource/get_frontier_key",ey="https://www.coze.cn",ty="wss://frontier.coze.cn";function Or(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??ey}function Qf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??ty}function In(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 Bi(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Mi=j("handshake");async function Jc(t){let e=Or(t.endpoint),r=t.timeoutMs??1e4,i=`${Pr(e)}${Yf}?aid=${encodeURIComponent(po)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...In(t.ppeOverride)},c=new AbortController,d=setTimeout(()=>c.abort(),r);Mi.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),x=u.headers.get("x-tt-logid")??"",h=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let v=await u.text().catch(()=>"");throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${x}: ${v.slice(0,200)}`)}let p=await u.json();if(p.code!==void 0&&p.code!==0)throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${p.code} msg=${p.msg??"-"} logid=${x}`);let _=p.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(p).slice(0,500);throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${x}: ${v}`)}return Mi.info("handshake ok",{remoteDeviceId:y,logid:x,traceId:h}),{accessKey:S,deviceId:y}}catch(u){if(u instanceof T)throw Mi.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Mi.warn("handshake timeout",{base:e,timeoutMs:r}),new T("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let x=u.cause;throw Mi.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:x?.code,syscall:x?.syscall,cause:String(u).slice(0,300)}),new T("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(d)}}var Zc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",Lt="auto",go=15e4;function t0(t){return{model:Xc(t.model)??Lt,...t.modelToken?{modelToken:t.modelToken}:{}}}function n0(t){return!t||t===Lt}var ny=new Set(["auto","\u81EA\u52A8"]);function Xc(t){let e=t?.trim();if(e)return ny.has(e.toLowerCase())?Lt:e}function r0(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Zc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||Lt;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 n0(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function i0(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||Lt}"`):n0(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??go;e.push("-c",`model_context_window=${r}`)}return e}function s0(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function Yc(t,e){let{ttEnv:r,usePpe:i}=Bi(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function o0(t,e,r){if(!t.modelToken)return{};let i=Yc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,d])=>`${c}:${d}`).join(`
92
- `)}}function Qc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function ed(t){return t.model||Lt}function e0(t,e,r){return{id:t,name:t,reasoning:!1,input:e,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:r,maxTokens:8192,api:"openai-completions"}}function a0(t,e,r,i){if(!t.modelToken)return null;let o=ed(t),c=Yc(e,r),d=["text"];t.modelInfo?.capabilities?.image===!0&&d.push("image");let u=[e0(o,d,t.modelInfo?.contextWindow??go)],x=new Set([o]);for(let p of i??[])!p||x.has(p)||(x.add(p),u.push(e0(p,["text"],go)));let h={baseUrl:`${Zc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:[{id:o,name:o,reasoning:!1,input:d,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:t.modelInfo?.contextWindow??go,maxTokens:32e3,api:"openai-completions"}]};return Object.keys(c).length>0&&(h.headers=c),h}function c0(t,e,r){if(!t.modelToken)return[];let i=Yc(e,r),o=[];for(let[c,d]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${d}"`);return o}var pe=j("agent-handlers"),d0=5*1024*1024,ay=1,cy=6,dy=new Set(["node_modules",".git",".coze","dist","build",".next"]),ly=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,uy=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,fy=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function xy(t){let e=t?.trim();return e?fy.test(e)||uy.test(e)?e:(pe.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function hy(t){return new Promise((e,r)=>{let i=it("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 wo=class{constructor(e){this.opts=e}opts;async listSkills(e){e._meta;let r=Zn(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Ve(r).workspace,c=i?.skills??[],d=[],u=new Set;for(let x of c){let h=_e(o,x.relPath,"SKILL.md");await f0(h).then(_=>_.isFile()).catch(()=>!1)&&(d.push(yy(x)),u.add(x.relPath))}if(e.scanLocal){let x=i?.framework??"claude-code",h=await gy(r,o,x),p=await my(r,x);for(let _ of[...h,...p])u.has(_.relPath)||(u.add(_.relPath),d.push(_.skill))}return{skills:d}}async addSkills(e){e._meta;let r=Zn(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],d=new Map(c.map((x,h)=>[x.skillId,h])),u=[];for(let x of o){let h=await _o({agentId:r,workspace:i.workspace,framework:i.framework,skill:x});yo(c,d,h),u.push(x)}return await ci(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){e._meta;let r=Zn(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 x=_e(i.workspace,u.relPath);await rd(x,{recursive:!0,force:!0}),pe.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await ci(r,d),this.reloadAgentSessions(r,"skills-removed"),{ok:!0}}async publishSkill(e){e._meta;let r=Zn(e._meta);if(!e.skillName)throw new T("IPC_BAD_REQUEST","_agent/publishSkill: missing skillName");pe.info("_agent/publishSkill start",{agentId:r,skillId:e.skillId??"",skillName:e.skillName,userId:e.userId??"",accountId:e.accountId??""});let i=await this.loadAgentCfg(r),o=i?.workspace??Ve(r).workspace,c=i?.framework??"claude-code",d=e.isGlobal??!1,u=g0(e.skillName),x=await py(o,c,u,d);if(!x){let O=d?"global":"workspace";throw new T("SKILL_NOT_FOUND",`skill not found in ${O}: ${e.skillName} (${u})`)}let{absDir:h,relPath:p}=x,_=_e(h,"SKILL.md"),S=new cd.default;S.addLocalFolder(h,u);let y=S.toBuffer();if(y.length>l0)throw new T("SKILL_ZIP_TOO_LARGE",`skill zip ${y.length} bytes exceeds limit ${l0}`);let v=await mo(_,{encoding:"utf8"}).then(O=>_0(O).description).catch(()=>{}),A={};this.opts.publishSkillToMarketplace?A=await this.opts.publishSkillToMarketplace({zip:y,...e.skillId?{skillId:e.skillId}:{},skillName:e.skillName,...v?{description:v}:{},agentId:r,...e.userId?{userId:e.userId}:{},...e.accountId?{accountId:e.accountId}:{}}):pe.warn("_agent/publishSkill: publishSkillToMarketplace not injected, skip upload",{agentId:r,skillName:e.skillName});let k=A.version??"v1.0",R=A.skillId??e.skillId??w0(r,p);if(i&&!d){let O=i.skills??[],E=O.find(D=>D.relPath===p);E?(E.version=k,E.skillId=R):O.push({skillId:R,skillName:e.skillName,relPath:p,version:k,installedAt:Date.now(),...v?{description:v}:{}}),await ci(r,O)}return pe.info("skill published",{agentId:r,skillName:e.skillName,relPath:p,zipBytes:y.length,skillId:R,version:k}),{ok:!0,skillId:R,version:k}}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,pe.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d});continue}let x=c.downstream;c.downstream=void 0,pe.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d}),x.stop(r).catch(h=>pe.warn("downstream stop failed during reload (ignored)",{reason:r,agentId:e,cloudId:o,err:String(h)}))}}isRuntimePendingPermission(e){let r=this.opts.isRuntimePendingPermission;return!r||!e.downstream?!1:r(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return pe.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await Oe(r);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return pe.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await hr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw pe.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new T("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Ue(i),pe.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 T("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await Oe(r))throw new T("AGENT_NOT_FOUND",`agent not found: ${r}`);let o=["-y"];e.registry&&Ni(e.registry)&&o.push(`--registry=${e.registry}`);let c=xy(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let d=e._meta?.cozeEnv;d&&ly.test(d)&&o.push("--env",d);let u=await hy(o);return pe.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 T("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Oe(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Ue(i),pe.info("agent disconnected",{agentId:r,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(r,e.reason??"disconnect"),{ok:!0}):(pe.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async deleteAgent(e){let r=e.agentId;if(!r)throw new T("IPC_BAD_REQUEST",`${ht.DELETE}: missing agentId`);let i=await Oe(r),o=e._meta?.cozeDeployType==="cloud"||e._meta?.cozeDeployType==="local"?e._meta.cozeDeployType:void 0,c=e.deployType??o??i?.deployType??"local";this.opts.disposeForDelete&&await this.opts.disposeForDelete(r,e.reason??"delete");let d=Ve(r);return c==="cloud"?await rd(d.root,{recursive:!0,force:!0}):i&&(i.deletedAt=Date.now(),i.deleteReason=e.reason??"deleted",await Ue(i)),pe.info("agent deleted",{agentId:r,reason:e.reason??"",deployType:c,configFound:!!i}),{ok:!0}}async switchModel(e){if(Dr(e._meta,"_agent/switchModel"),!e.agentId)throw new T("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Xc(e.model)??Lt,i=await Oe(e.agentId);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Ue(i),pe.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return pe.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};let c=o.model;o.model=r,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o,c).catch(u=>pe.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(u)}));let d=[];for(let[u,x]of o.allSessionQueues())d.push(x.enqueue(async()=>{let h=o.sessions.get(u);h?.downstream&&(await h.downstream.stop(`switchModel: ${r}`).catch(()=>{}),h.downstream=void 0)}));return await Promise.all(d),pe.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:r,cloudSessions:d.length}),{ok:!0}}async resetAgent(e){if(Dr(e._meta,ht.RESET),!e.agentId)throw new T("IPC_BAD_REQUEST",`${ht.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,ht.RESET),await this.runDetailSync(e.agentId,ht.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),pe.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(r);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,d]of i.sessions)o.set(c,{modelToken:d.modelToken,tokenGeneratedAt:d.tokenGeneratedAt});await ai(e,o)}async clearPersistedAcpSessionIds(e){let r=await Oe(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 Ue(r)}async repairAgent(e){if(Dr(e._meta,ht.REPAIR),!e.agentId)throw new T("IPC_BAD_REQUEST",`${ht.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new T("IPC_BAD_REQUEST",`${ht.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){pe.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,ht.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){pe.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){pe.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){Dr(e._meta,"_agent/getFileTree");let r=e._meta,i=Zn(r),o=await this.resolveWorkspace(i),c=e.filePath??"",d=this.safeJoin(o,c),u=await td(d).catch(()=>null);if(!u)throw new T("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await oi(d,o))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let x=Py(e.depth);return u.isDirectory()?{tree:await Dy(o,d,c,x)}:{tree:[{name:Oy(c),path:v0(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){Dr(e._meta,"_agent/getFileContent");let r=Zn(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new T("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await td(o).catch(()=>null);if(!c||!c.isFile())throw new T("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await oi(o,i))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>d0)throw new T("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${d0})`);let d=await mo(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 Oe(e).catch(()=>null))?.workspace??Ve(e).workspace}safeJoin(e,r){let i=sd(e,r||"."),o=ad(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${x0}`))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return Oe(e)}async requireAgentCfg(e){let r=await this.loadAgentCfg(e);if(!r)throw new T("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function g0(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new T("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new T("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function dd(t){return t==="claude-code"?_e(".claude","skills"):_e(".agents","skills")}function m0(t){let e=iy();return t==="claude-code"?[_e(e,".claude","skills")]:t==="codex"?[_e(e,".agents","skills"),_e(e,".codex","skills")]:[_e(e,".agents","skills"),_e(e,".openclaw","skills")]}async function py(t,e,r,i){let o=async c=>f0(_e(c,"SKILL.md")).then(d=>d.isFile()).catch(()=>!1);if(!i){let c=_e(dd(e),r),d=_e(t,c);return await o(d)?{absDir:d,relPath:c}:null}for(let c of m0(e)){let d=_e(c,r);if(await o(d))return{absDir:d,relPath:d}}return null}function w0(t,e){return(ry("sha256").update(`${t}\0${e}`).digest().readBigUInt64BE(0)&0x7fffffffffffffffn).toString()}function _0(t){if(!t.startsWith("---"))return{};let e=t.indexOf(`
93
- ---`,3);if(e<0)return{};let r=t.slice(3,e),i={};for(let o of r.split(`
94
- `)){let c=/^\s*(name|description)\s*:\s*(.+?)\s*$/.exec(o);if(!c||!c[2])continue;let d=c[1],u=c[2].trim();(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))&&(u=u.slice(1,-1)),u&&(i[d]=u)}return i}async function y0(t,e,r,i){let o=await u0(e,{withFileTypes:!0}).catch(()=>null);if(!o)return[];let c=[];for(let d of o){if(!d.isDirectory())continue;let u=d.name,x=_e(r,u),h=_e(e,u,"SKILL.md"),p=await mo(h,{encoding:"utf8"}).catch(()=>null);if(p===null)continue;let _=_0(p);c.push({relPath:x,skill:{skillId:w0(t,x),skillName:_.name||u,..._.description?{description:_.description}:{},...i?{isGlobal:!0}:{}}})}return c}async function gy(t,e,r){let i=dd(r);return y0(t,_e(e,i),i,!1)}async function my(t,e){let r=[],i=new Set;for(let o of m0(e)){let c=await y0(t,o,o,!0);for(let d of c)i.has(d.relPath)||(i.add(d.relPath),r.push(d))}return r}var wy=3e4,_y=50*1024*1024,l0=10*1024*1024,Lr=3e4;async function _o(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new T("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,d=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!d)throw new T("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=g0(o.skillName),x=dd(i),h=_e(x,u),p=_e(r,h);if(await nd(p,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");Fi(S.length),await id(_e(p,"SKILL.md"),S,"utf8")}else{let S=await Ey(o.downloadUrl);Sy(S)?await Ty(S,p):Ay(S)?await Iy(S,p):await id(_e(p,"SKILL.md"),S.toString("utf8"),"utf8")}let _={skillId:o.skillId,skillName:o.skillName,relPath:h,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return pe.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:h,source:c?"content":"downloadUrl"}),_}function yo(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 yy(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 by(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 b0(t,e){let r=await Oe(t,e);if(!r)return{status:"skipped",count:0};if(r.disconnectedAt)return{status:"skipped",count:0};let i=Ot,o=r.skillsRefreshedForVersion;if(o===i)return{status:"noop",count:0};if(!o)return r.skillsRefreshedForVersion=i,await Ue(r,e),{status:"seeded",count:0};let c=[...r.skills??[]],d=new Map(c.map((p,_)=>[p.skillId,_])),u=c.filter(p=>p.builtin===!0&&!!p.downloadUrl);if(u.length===0)return r.skillsRefreshedForVersion=i,await Ue(r,e),{status:"noop",count:0};let x=0,h=0;for(let p of u)try{await rd(_e(r.workspace,p.relPath),{recursive:!0,force:!0});let _=await _o({agentId:t,workspace:r.workspace,framework:r.framework,skill:by(p)});yo(c,d,_),x+=1}catch(_){h+=1,pe.warn("refresh builtin skill failed (skipping)",{agentId:t,skillId:p.skillId,skillName:p.skillName,err:String(_)})}return r.skills=c,h===0&&(r.skillsRefreshedForVersion=i),await Ue(r,e),pe.info("builtin skills refreshed after bridge upgrade",{agentId:t,from:o,to:i,ok:x,failed:h}),{status:"refreshed",count:x}}async function Ey(t){if(!t)throw new T("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Fi(e);let r=vy(t);return Fi(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await mo(e);return Fi(r.length),r}if(Ni(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),wy);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new T("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Fi(o.byteLength),Buffer.from(o)}finally{clearTimeout(r)}}throw new T("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Fi(t){if(t>_y)throw new T("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function vy(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new T("IPC_BAD_REQUEST","bad data URL");let r=!!e[2],i=e[3]??"";return r?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function Sy(t){return t.length>=2&&t[0]===31&&t[1]===139}function Ay(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 od(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function Iy(t,e){let r,i;try{r=new cd.default(t),i=r.getEntries()}catch(d){throw new T("IPC_BAD_REQUEST",`zip parse failed: ${d.message}`,{cause:d})}for(let d of i){let u=d.entryName;if(!u||od(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new T("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(h=>h===".."))throw new T("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let x=d.header.attr>>>16&61440;if(x!==0&&x!==32768&&x!==16384)throw new T("IPC_BAD_REQUEST",`zip entry kind 0x${x.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=ky(i),c=sd(e);for(let d of i){if(od(d.entryName))continue;let u=d.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let x=sd(e,u),h=ad(c,x);if(h.startsWith("..")||h==="..")throw new T("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(d.isDirectory){await nd(x,{recursive:!0});continue}await nd(sy(x),{recursive:!0});let p;try{p=d.getData()}catch(_){throw new T("IPC_BAD_REQUEST",`zip entry getData failed (${d.entryName}): ${_.message}`,{cause:_})}await id(x,p)}}function ky(t){let e;for(let r of t){let i=r.entryName;if(!i||od(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 Ty(t,e){await Cy(t);let r=Hf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar extract timeout (${Lr}ms)`))},Lr);try{await p0(h0.from(t),r)}catch(c){throw c instanceof T?c:i?new T("IPC_BAD_REQUEST",`tar extract timeout (${Lr}ms)`):new T("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function Cy(t){let e=[],r=Rr({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(h=>h==="..")&&e.push(`tar entry contains '..': ${d}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar list timeout (${Lr}ms)`))},Lr);try{await p0(h0.from(t),r)}catch(c){throw i?new T("IPC_BAD_REQUEST",`tar list timeout (${Lr}ms)`):new T("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new T("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var Ry=5e3;async function Dy(t,e,r,i){return E0(t,e,r,i,{count:0})}async function E0(t,e,r,i,o){if(i<=0)return[];let c;try{c=await u0(e,{withFileTypes:!0})}catch{return[]}let d=[];for(let u of c){if(dy.has(u.name)||u.isSymbolicLink())continue;if(o.count>=Ry){d.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let x=_e(e,u.name),h=oy(_e(r,u.name)),p=null;try{p=await td(x)}catch{continue}if(p.isSymbolicLink())continue;o.count++;let _={name:u.name,path:v0(ad(t,x)),isDir:p.isDirectory(),size:p.size,modifiedAt:Math.floor(p.mtimeMs)};p.isDirectory()&&i>1&&(_.children=await E0(t,x,h,i-1,o)),d.push(_)}return d.sort((u,x)=>u.isDir!==x.isDir?u.isDir?-1:1:u.name.localeCompare(x.name)),d}function Py(t){return!t||t<=0?ay:Math.min(t,cy)}function Oy(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function v0(t){return t.split(x0).join("/")}ie();var kn=j("agent-health-reporter"),Ly=1e4,Ny=3,zi=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??Ly,this.livenessFailureThreshold=e.livenessFailureThreshold??Ny}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()}),kn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),kn.info("heartbeat stopped"))}async tick(){if(this.inFlight){kn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){this.consecutiveFailures=0,kn.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=My(d);if(!u)continue;let x={agentId:d.agentId,status:u};d.patToken&&(x.patToken=d.patToken),d.accountId&&(x.accountId=d.accountId),r.push(x)}if(r.length===0){this.consecutiveFailures=0;return}let i={agents:r,bridgeVersion:Ot,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3),this.consecutiveFailures=0}catch(d){this.consecutiveFailures+=1,kn.warn("heartbeat batch send failed",{count:r.length,consecutiveFailures:this.consecutiveFailures,err:String(d)})}let c=o?.authFailures;if(c&&c.length>0&&(kn.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){kn.warn("onAuthFailures callback failed (ignored)",{err:String(d)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){kn.warn("onTickEnd hook failed",{err:String(r)})}}};function My(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}fn();import{mkdir as wd,rm as Kb,stat as $b}from"node:fs/promises";import{homedir as Vb}from"node:os";import{join as _d}from"node:path";an();import{existsSync as Jy}from"node:fs";import{release as Zy}from"node:os";import{basename as Xy,isAbsolute as Yy}from"node:path";function Ui(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Nr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Mr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function Tn(t,e){return{jsonrpc:"2.0",id:t,error:e}}$e();var bo=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,SKILL_NOT_FOUND:-32022,SKILL_ZIP_TOO_LARGE:-32023,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32024};function S0(t){return"method"in t&&"id"in t&&t.id!==void 0}function A0(t){return"method"in t&&!("id"in t)}function Eo(t){return!("method"in t)&&"id"in t}var By={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,SKILL_NOT_FOUND:Q.SKILL_NOT_FOUND,SKILL_ZIP_TOO_LARGE:Q.SKILL_ZIP_TOO_LARGE};function Fy(t){if(t!=null)return t instanceof Error?{name:t.name,message:Hi(t.message)}:typeof t=="string"?Hi(t):typeof t=="object"?Uy(t):t}var zy=[[/\/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 Hi(t){let e=t;for(let[r,i]of zy)e=e.replace(r,i);return e}function Uy(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Hi(i):e[r]=i;return e}function Gi(t){if(t instanceof T){let e=Fy(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:By[t.code]??Q.INTERNAL_ERROR,message:Hi(t.message),data:r}}return{code:Q.INTERNAL_ERROR,message:Hi(t instanceof Error?t.message:String(t))}}function I0(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 T(r,o,{retriable:e?.retriable??!1,cause:c})}function T0(t){return`${JSON.stringify(t)}
95
- `}var k0=10*1024*1024,vo=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>k0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${k0} bytes`)}),[]}let r=this.buffer.split(`
96
- `);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 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"},iT=Object.fromEntries(Object.entries(R0).map(([t,e])=>[e,t])),Hy={"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:[]},Br=class{seq=0;next(e,r){this.seq+=1;let i=R0[e]??Gy(e),o=Hy[i]??[],c=[i,String(this.seq)];if(o.length>0){let d=o.map(x=>C0(r?.[x]??"")),u=qy(d).join(":");u&&c.push(u)}else r&&Object.values(r).some(d=>d)&&c.push(Object.values(r).filter(Boolean).map(d=>C0(String(d))).join(":"));return c.join("_")}reset(){this.seq=0}};function Gy(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function C0(t){return t.replace(/[:_\s]+/g,"-")}function qy(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}un();import{readFileSync as jy}from"node:fs";var Wy=384;async function ld(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await ln(t.agentEnvFile,r,{mode:Wy})}function qi(t){try{let e=JSON.parse(jy(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function So(t,e,r={},i=o=>o){return{...i({...t,...qi(e)}),...r}}Jt();dr();$e();ie();Pe();import{execFileSync as Ky,spawnSync as $y}from"node:child_process";function ji(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function Wi(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),$y("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var ud=new Set;function D0(t){typeof t=="number"&&t>0&&ud.add(t)}function P0(t){typeof t=="number"&&ud.delete(t)}function O0(){for(let t of ud)Wi(t,"SIGKILL")}var Fr="coze-bridge-daemon";function L0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return Ky("pgrep",["-U",String(o),"-f",Fr],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:2e3})}),r;try{r=e()}catch{return[]}let i=process.pid;return r.split(`
97
- `).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function N0(t,e){if(t.length===0)return;let r=e?.killFn??Wi,i=e?.isAliveFn??ji,o=e?.sleepFn??(u=>new Promise(x=>setTimeout(x,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(x=>i(x));u+=d)await o(Math.min(d,c-u));for(let u of t)i(u)&&r(u,"SIGKILL")}var Vy=[{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:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/import\.meta\.resolve is not a function|\.resolve is not a function/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (codex ACP \u9700\u8981 import.meta.resolve)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20 \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/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 M0(t,e){if(!e)return null;for(let r of Vy)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function B0(t,e){return M0(t,e)}function F0(t,e){return M0(t,e)}function zr(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 z0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let h=t.suspendedMs+o,p=r-t.startedAt-h;return{action:"suspend",suspendedDeltaMs:o,rearmMs:zr(p,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:zr(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:zr(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:zr(c,!1,e)}}var U0=Ze("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),Qy=200,eb=40,tb=Ze("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),nb=Ze("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),rb=Ze("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),ib=Ze("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),sb=Ze("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),ob=Ze("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),H0=500;function ab(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=H0?t:`${e.slice(0,H0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function cb(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 Jy(t)}catch{return}}function db(t,e){return{platform:process.platform,osRelease:Zy(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:Yy(e.command)?G0(e.command):void 0,cwd:e.cwd,cwdExists:G0(e.cwd),envKeys:e.envKeys}}function lb(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${Xy(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Nt=class{constructor(e){this.opts=e;this.log=j(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new vo({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Br;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new T("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=So(process.env,this.opts.agentEnvFile??Y().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=it(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>Qy&&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,P0(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=db(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(r).length});this.log.error("child error",{err:String(o),diag:d}),this.failAllPending(new T("AGENT_SPAWN_FAILED",lb(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()));Wi(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Wi(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:sb,phase2GateMs:tb,livenessWindowMs:nb,absoluteMaxMs:rb,approvalMaxMs:ob,suspendThresholdMs:ib,...r};return this.call("session/prompt",e,U0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Nr("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(Mr(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(Tn(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=U0,o){if(!this.child||this.stopped)return Promise.reject(new T("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),d=Ui(c,e,r),u=(()=>{if(typeof r!="object"||r===null)return;let x=r.sessionId;return typeof x=="string"?x:void 0})();return new Promise((x,h)=>{let p={resolve:x,reject:h,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:zr(0,!1,o),sessionId:u};p.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(),k=z0(v,S.cfg,A),R=O=>{S.armedAt=A,S.expectedIntervalMs=O,p.timer=setTimeout(y,O)};if(k.action==="suspend"){S.suspendedMs+=k.suspendedDeltaMs,S.lastActivityAt=A,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:k.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),R(k.rearmMs);return}if(k.action==="continue"){R(k.rearmMs);return}this.pending.delete(c),k.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:k.awaitingApproval,...S.sessionId?{sessionId:S.sessionId}:{}}),h(k.awaitingApproval?new T("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new T("AGENT_TIMEOUT",`${e} timed out after ${S.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...S.sessionId?{sessionId:S.sessionId}:{}}),h(new T("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};p.timer=setTimeout(y,S.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(p.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),h(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,p);try{this.writeFrame(d)}catch(_){p.timer&&clearTimeout(p.timer),this.pending.delete(c),h(_)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new T("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(Eo(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new T("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:ab(e.result)}),r.resolve(e.result));return}if(A0(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(S0(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(Tn(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(Tn(e.id,Gi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=I0(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=F0(this.framework,cb(e));return i?new T(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):r}buildExitError(e,r){if(this.stopReason!==void 0)return new T("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(eb).join(`
98
- `),o=B0(this.framework,i);return o?new T(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new T("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function ub(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 Ao=class extends Nt{framework="claude-code";constructor(e){let{command:r,args:i}=si("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 ub(e)}};an();import{spawn as fb}from"node:child_process";import{closeSync as xb,existsSync as xd,mkdirSync as hb,mkdtempSync as pb,openSync as gb,readFileSync as W0,readSync as mb,readdirSync as wb,rmSync as _b,statSync as yb}from"node:fs";import{homedir as bb,tmpdir as Eb}from"node:os";import{join as Ur}from"node:path";Pe();var hd=9e4,vb=64*1024,Sb=100;function Ab(t){let e=typeof t=="number"?t:typeof t=="string"?Number.parseFloat(t):Number.NaN;return!Number.isFinite(e)||e<=0?hd:Math.max(1,Math.floor(e*1e3))}function Ib(t){let e=typeof t=="number"?t:typeof t=="string"?Number.parseFloat(t):Number.NaN;return!Number.isFinite(e)||e<=0?hd:Math.max(1,Math.floor(e))}function kb(t){if(!t||typeof t!="object"||Array.isArray(t))return;let e={};for(let[r,i]of Object.entries(t))typeof i=="string"&&(e[r]=i);return Object.keys(e).length>0?e:void 0}function q0(t){if(typeof t=="string"&&t.trim())return{command:t,timeoutMs:hd};if(!t||typeof t!="object"||Array.isArray(t))return;let e=t;if(e.type&&e.type!=="command")return;let r=typeof e.command=="string"?e.command.trim():"";if(!r)return;let i=typeof e.working_directory=="string"&&e.working_directory.trim()?e.working_directory.trim():typeof e.cwd=="string"&&e.cwd.trim()?e.cwd.trim():void 0,o=kb(e.env);return{command:r,timeoutMs:e.timeout_ms===void 0?Ab(e.timeout):Ib(e.timeout_ms),...i?{cwd:i}:{},...o?{env:o}:{}}}function fd(t){if(Array.isArray(t))return t.flatMap(i=>fd(i));if(!t||typeof t!="object"){let i=q0(t);return i?[i]:[]}let e=t;if(e.hooks)return fd(e.hooks);let r=q0(e);return r?[r]:[]}function Tb(t){let e=Ur(t,"hooks.json");if(!xd(e))return[];let r=JSON.parse(W0(e,"utf8")),o=r.hooks&&typeof r.hooks=="object"?r.hooks:r;return fd(o.Stop??o.stop)}function Cb(t,e){let r=Ur(t,"sessions");if(!xd(r))return;let i=[],o=c=>{let d;try{d=wb(c,{withFileTypes:!0})}catch{return}for(let u of d){let x=Ur(c,u.name);if(u.isDirectory())o(x);else if(u.isFile()&&u.name.endsWith(".jsonl"))try{i.push({path:x,mtimeMs:yb(x).mtimeMs})}catch{}}};o(r),i.sort((c,d)=>d.mtimeMs-c.mtimeMs);for(let c of i.slice(0,Sb))if(Rb(c.path,e))return c.path;return i[0]?.path}function Rb(t,e){let r;try{r=gb(t,"r");let i=Buffer.alloc(vb),o=mb(r,i,0,i.length,0),c=i.subarray(0,o).toString("utf8");return c.includes(JSON.stringify(e))||c.includes(e)}catch{return!1}finally{if(r!==void 0)try{xb(r)}catch{}}}function Db(t){return qi(t??Y().agentEnvFile)}function Pb(t){let e=t.trim();if(e.length>=2){let r=e[0];if((r==='"'||r==="'")&&e.endsWith(r)){let i=e.slice(1,-1);return r==='"'?i.replace(/\\n/g,`
99
- `).replace(/\\r/g,"\r").replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):i.replace(/\\'/g,"'")}}return e.replace(/\s+#.*$/,"")}function Ob(t){let e={};for(let r of t.split(/\r?\n/)){let i=r.trim();if(!i||i.startsWith("#"))continue;let o=i.startsWith("export ")?i.slice(7).trimStart():i,c=o.indexOf("=");if(c<=0)continue;let d=o.slice(0,c).trim();/^[A-Za-z_][A-Za-z0-9_]*$/.test(d)&&(e[d]=Pb(o.slice(c+1)))}return e}function Lb(t){let e=Ur(t,"cozeloop.env");return xd(e)?Ob(W0(e,"utf8")):{}}function j0(t){let e=t?.trim();return e||void 0}function Nb(t){let e=Db(t.agentEnvFile),r=j0(t.env?.CODEX_HOME??e.CODEX_HOME??process.env.CODEX_HOME);if(r)return r;let i=j0(t.env?.HOME??e.HOME??process.env.HOME)??bb();return Ur(i,".codex")}var Io=class extends Nt{framework="codex";authMethodId;codexHomeDir;cleanupCodexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=si("codex",e.command,i),d=e.isolateCodexHome?e.codexHomeDir??e.env?.CODEX_HOME??pb(Ur(Eb(),"coze-bridge-codex-home-")):Nb(e),u=!!e.isolateCodexHome&&!!d&&!e.codexHomeDir&&e.env?.CODEX_HOME!==d;e.isolateCodexHome&&d&&!u&&hb(d,{recursive:!0});let x=e.isolateCodexHome&&d?{...e.env??{},CODEX_HOME:d}:e.env,h={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...e.agentEnvFile?{agentEnvFile:e.agentEnvFile}:{},...x?{env:x}:{}};super(h),this.authMethodId=e.authMethodId,this.codexHomeDir=d,this.cleanupCodexHomeDir=u}async initialize(e){let r=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),r}async sessionPrompt(e){let r=await super.sessionPrompt(e);return this.runStopHooksBestEffort(e.sessionId).catch(i=>{this.log.warn("codex stop hook unexpected failure",{err:String(i)})}),r}async runStopHooksBestEffort(e){let r=this.codexHomeDir??this.opts.env?.CODEX_HOME;if(!r)return;let i;try{i=Tb(r)}catch(d){this.log.warn("codex stop hook load failed",{codexHomeDir:r,err:String(d)});return}if(i.length===0)return;let o=Cb(r,e),c=JSON.stringify({hook_event_name:"Stop",session_id:e,...o?{transcript_path:o}:{},trigger:"coze-bridge"});await Promise.all(i.map(async d=>{try{await this.runHookCommand(d,c)}catch(u){this.log.warn("codex stop hook failed",{codexHomeDir:r,command:d.command.slice(0,200),err:String(u)})}}))}runHookCommand(e,r){return new Promise((i,o)=>{let c=this.codexHomeDir??this.opts.env?.CODEX_HOME,d=c?Lb(c):{},u=fb(e.command,{cwd:e.cwd??this.opts.cwd,env:So(process.env,this.opts.agentEnvFile??Y().agentEnvFile,{...this.opts.env??{},...d,...e.env??{}}),shell:!0,stdio:["pipe","ignore","pipe"]}),x="",h=setTimeout(()=>{u.kill("SIGTERM"),o(new Error(`hook timed out after ${e.timeoutMs}ms`))},e.timeoutMs);u.stderr?.setEncoding("utf8"),u.stderr?.on("data",p=>{x+=p,x.length>4e3&&(x=x.slice(-4e3))}),u.on("error",p=>{clearTimeout(h),o(p)}),u.on("close",(p,_)=>{if(clearTimeout(h),p===0){i();return}o(new Error(`hook exited code=${p} signal=${_} stderr=${x.slice(-1e3)}`))}),u.stdin.end(`${r}
100
- `)})}async stop(e){if(await super.stop(e),this.codexHomeDir&&this.cleanupCodexHomeDir)try{_b(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};$e();var Mb=3e4,Hr=class extends Nt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},Mb))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new T("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var K0=["default","acceptEdits","plan","auto","bypassPermissions"],$0=["read-only","auto","full-access"];function Cn(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return K0.includes(e);case"codex":return $0.includes(e);case"openclaw":return!1}}function pd(t){switch(t){case"claude-code":return K0.join("/");case"codex":return $0.join("/");case"openclaw":return""}}un();$e();ie();Pe();function gd(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}an();var Rn=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 ko=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 Rn,this.sessionQueues.set(e,r)),r}allSessionQueues(){return this.sessionQueues.entries()}hasSessionQueue(e){let r=this.sessionQueues.get(e);return!!r&&!r.isDisposed}async dispose(e){this.status="stopped";let r=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let i of this.sessionQueues.values())i.dispose(r);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let r=[];for(let[,i]of this.sessions)Ki(i),i.downstream&&(r.push(i.downstream.stop(e).catch(()=>{})),i.downstream=void 0);await Promise.all(r),this.activeTriggers.clear(),this.activeGroupIds.clear()}};function Ki(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function Zt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Jt();ie();import{constants as V0}from"node:fs";import{access as Bb}from"node:fs/promises";import{delimiter as Fb,join as zb}from"node:path";var St=j("framework-detector"),J0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},Ub=[".exe",".cmd",".bat",".ps1"],Xn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??it,access:e.access??Bb}}async detect(e){let r=J0[e],i=await this.which(r);if(!i)return St.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(J0).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(Fb).filter(Boolean),i=this.env.platform==="win32"?["",...Ub]:[""];for(let o of r)for(let c of i){let d=zb(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 St.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return St.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 St.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 St.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?(St.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}:(St.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return St.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 St.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||St.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){St.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&&(Gb(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,d,u=x=>{c||(c=!0,d&&clearTimeout(d),i(x))};try{let x=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});d=setTimeout(()=>{x.kill("SIGKILL"),u(null)},15e3),x.stdout?.on("data",h=>{o+=h.toString("utf8")}),x.on("error",()=>u(null)),x.on("close",h=>u({code:h,stdout:o}))}catch{u(null)}})}},Hb=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function Gb(t){return t.replace(Hb,"")}import{homedir as X0}from"node:os";import{join as Co}from"node:path";un();Jt();dr();$e();ie();async function Y0(){let t=Co(X0(),".openclaw/openclaw.json");return cn(t)}async function Q0(){return(await Y0())?.gateway?.auth?.token??""}var Yn=j("openclaw.config"),qb=[0,5e3,5e3],jb=Ze("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),Z0="models.providers.",To="agents.defaults.models",Wb=["operator.admin","operator.read","operator.write","operator.approvals","operator.pairing"];function md(t,e){if(!Array.isArray(t))return!1;let r=new Set(t);return e.every(i=>r.has(i))}var Ro=class{command;env;retryDelaysMs;cliTimeoutMs;openclawDir;queue=new Rn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??qb,this.cliTimeoutMs=e.cliTimeoutMs??jb,this.openclawDir=e.openclawDir??Co(X0(),".openclaw")}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,Yn.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(d)})}}throw new T("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=it(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",d=!1,u=h=>{d||(d=!0,clearTimeout(x),h())};o.stderr?.on("data",h=>{c+=h.toString("utf8")});let x=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);x.unref(),o.on("error",h=>u(()=>i(h))),o.on("close",h=>u(()=>{h===0?r():i(new Error(`exit ${h}: ${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){Yn.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",`${Z0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${Z0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${To}[${e}]`,()=>this.runCli(["config","set",To,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${To}[${e}]`,`${To}.${e}`)}async getAllowlistModelsForProvider(e){let i=(await Y0())?.agents?.defaults?.models;if(!i||typeof i!="object")return[];let o=`${e}/`,c=[];for(let d of Object.keys(i))d.startsWith(o)&&c.push(d.slice(o.length));return c}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"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}async ensureAcpDeviceScopes(){try{let e=Co(this.openclawDir,"identity","device.json"),i=(await cn(e))?.deviceId?.trim();if(!i)return Yn.debug("openclaw device identity absent, skip acp scope ensure",{identityPath:e}),!1;let o=Co(this.openclawDir,"devices","paired.json"),c=await cn(o),d=c?.[i];if(!c||!d)return Yn.debug("acp device not yet paired, skip scope ensure",{deviceId:i}),!1;let u=[...Wb],x=d.tokens?.operator;return md(d.scopes,u)&&md(d.approvedScopes,u)&&md(x?.scopes,u)?(Yn.debug("acp device already has full operator scopes",{deviceId:i}),!1):(d.scopes=[...u],d.approvedScopes=[...u],x&&(x.scopes=[...u]),await ln(o,c,{mode:384}),Yn.info("acp device scopes upgraded to full operator set (bypass manual approval)",{deviceId:i,scopes:u}),!0)}catch(e){return Yn.warn("ensureAcpDeviceScopes failed (ignored, best-effort)",{err:String(e)}),!1}}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}};var fe=j("agent-manager"),bd="acceptEdits",nx="full-access",rx="read-only";function Jb(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 Zb=(t,e,r,i,o,c,d,u,x,h,p)=>{switch(t){case"claude-code":{let _={...o?{...r0(o),...o0(o,d,u)}:{},...x??{},IS_SANDBOX:"1"};return new Ao({cwd:r,env:_,agentId:i})}case"codex":{let _=o?[...i0(o),...c0(o,d,u)]:[],S=nx;h!==void 0&&(Cn("codex",h)?S=h:fe.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:h}));let y=[..._,...Jb(S)],v={...o?s0(o):{},...x??{}},A=!!o;return new Io({cwd:r,agentId:i,...y.length>0?{extraArgs:y}:{},...Object.keys(v).length>0?{env:v}:{},...A?{authMethodId:"openai-api-key",isolateCodexHome:!0,...p?{codexHomeDir:p}:{}}:{}})}case"openclaw":return new Hr({command:e,cwd:r,agentId:i,...c?{sessionName:gd(c)}:{}})}};function yd(t){return t==="claude-code"||t==="codex"}function Xb(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(Yb(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
89
+ `},configPath(t){return KS(t.homeDir,".coze","bridge","task.xml")},async install(t){let n=`cmd.exe /c ${[`^"${t.nodeBin}^"`,`^"${t.entry}^"`,"--daemon",`>> ^"${t.logFile}^" 2>&1`].join(" ")}`;await wp("schtasks",["/Create","/SC","ONLOGON","/TN",ua,"/TR",n,"/RU",t.userName,"/F"]),Xl.info("task scheduler entry created",{task:ua,logFile:t.logFile})},async uninstall(t){await wp("schtasks",["/Delete","/TN",ua,"/F"]).catch(e=>Xl.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Xl.info("task scheduler entry removed",{task:ua})}}});var yp={};va(yp,{buildContext:()=>XS,getSupervisor:()=>JS,launchdSupervisor:()=>Zl,systemdSupervisor:()=>Yl,taskSchedulerSupervisor:()=>Ql});import{homedir as $S,userInfo as VS}from"node:os";function JS(t=process.platform){switch(t){case"darwin":return Zl;case"linux":return Yl;case"win32":return Ql;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function YS(){let t={};for(let e of ZS){let n=process.env[e];n&&(t[e]=n)}return t}function XS(){let t=ee();return{nodeBin:process.execPath,entry:Ul(t),logFile:t.logFile,homeDir:$S(),userName:VS().username,isRoot:process.getuid?.()===0,env:YS()}}var ZS,bp=et(()=>{"use strict";Oe();ta();pp();mp();_p();ZS=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ne();on();var Pd=G("acp-installer-warmup"),Jg=["claude-code","codex"];async function Dd(t={}){let e=t.ensure??cr,i=(await Promise.allSettled(Jg.map(async o=>{let c=await e(o);Pd.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&Pd.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))})}ln();ne();import{readdir as um}from"node:fs/promises";import{mkdir as Md,readFile as lm,writeFile as Bd}from"node:fs/promises";import{join as Ca}from"node:path";var dm={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function ur(t,e,n){await Md(t,{recursive:!0});let i=dm[e],o=Ca(t,i);return await Bd(o,n??"","utf8"),o}async function Pa(t,e,n){let i=Ca(t,".claude");await Md(i,{recursive:!0});let o=Ca(i,"settings.local.json"),c={};try{let u=await lm(o,"utf8"),h=JSON.parse(u);typeof h=="object"&&h!==null&&!Array.isArray(h)&&(c=h)}catch{}let l=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")l.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!n)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");l.defaultMode===void 0&&(l.defaultMode=n)}return c.permissions=l,await Bd(o,JSON.stringify(c,null,2),"utf8"),o}var Ye=G("agent-detail-sync"),fm=6e4,hm=5*6e4,_s=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let n=this.opts.paths.agentsRoot,i;try{i=await um(n)}catch(o){Ye.info("agents dir not found, skip detail sync",{root:n,err:String(o)});return}Ye.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await ke(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Ye.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(l){Ye.warn("detail sync failed for agent, skipping",{agentId:o,err:String(l)})}}})),Ye.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),n=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&n.push(i);if(n.length!==0){Ye.info("retrying pending detail syncs",{count:n.length});for(let i of n)try{await this.syncOne(i)}catch(o){Ye.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,n){let i=n??await ke(e,this.opts.paths);if(!i){Ye.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(h){Ye.warn("detail RPC failed, using local data",{agentId:e,err:String(h)});let x=this.retryQueue.get(e),m=x?Math.min(x.currentDelay*2,hm):fm;this.retryQueue.set(e,{dueAt:Date.now()+m,currentDelay:m});return}if(o.agentId&&o.agentId!==e){Ye.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,l=!1;o.agentName&&o.agentName!==i.agentName&&(i.agentName=o.agentName,c=!0),o.description!==void 0&&o.description!==i.description&&(i.description=o.description,c=!0),o.cozeIdentity&&o.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=o.cozeIdentity,c=!0,l=!0);let u=!1;if(o.deployType==="cloud"&&i.deployType!=="cloud"?(Ye.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&Ye.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Ye.debug("detail sync: no diff",{agentId:e});return}await Fe(i,this.opts.paths),Ye.info("detail sync: config updated",{agentId:e,identityChanged:l,agentName:i.agentName}),u?(await this.opts.agentManager.createAgent({agentId:e,framework:i.framework,_meta:{cozeDeployType:"cloud"},cozeIdentity:i.cozeIdentity,model:i.model}),Ye.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):l&&(await ur(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var el=Ut(gu(),1);import{createHash as $_}from"node:crypto";import{lstat as $c,mkdir as Vc,readFile as fo,readdir as t0,rm as Jc,stat as n0,writeFile as Zc}from"node:fs/promises";import{homedir as V_}from"node:os";import{dirname as J_,join as me,normalize as Z_,relative as Qc,resolve as Yc,sep as r0}from"node:path";import{Readable as i0}from"node:stream";import{pipeline as s0}from"node:stream/promises";import Lm from"events";import nt from"fs";import{EventEmitter as Cc}from"node:events";import Yu from"node:stream";import{StringDecoder as Mm}from"node:string_decoder";import ef from"node:path";import vr from"node:fs";import{dirname as Jm,parse as Zm}from"path";import{EventEmitter as iw}from"events";import uc from"assert";import{Buffer as Hn}from"buffer";import*as bu from"zlib";import sw from"zlib";import{posix as gr}from"node:path";import{basename as Dw}from"node:path";import Ys from"fs";import kt from"fs";import ku from"path";import{win32 as jw}from"node:path";import Lu from"path";import gf from"node:fs";import a_ from"node:assert";import{randomBytes as mf}from"node:crypto";import ie from"node:fs";import Le from"node:path";import wf from"fs";import oo from"node:fs";import Ai from"node:path";import ot from"node:fs";import x_ from"node:fs/promises";import eo from"node:path";import{join as Rf}from"node:path";import st from"node:fs";import Df from"node:path";var Om=Object.defineProperty,Nm=(t,e)=>{for(var n in e)Om(t,n,{get:e[n],enumerable:!0})},mu=typeof process=="object"&&process?process:{stdout:null,stderr:null},Bm=t=>!!t&&typeof t=="object"&&(t instanceof Kn||t instanceof Yu||Fm(t)||zm(t)),Fm=t=>!!t&&typeof t=="object"&&t instanceof Cc&&typeof t.pipe=="function"&&t.pipe!==Yu.Writable.prototype.pipe,zm=t=>!!t&&typeof t=="object"&&t instanceof Cc&&typeof t.write=="function"&&typeof t.end=="function",Gt=Symbol("EOF"),qt=Symbol("maybeEmitEnd"),un=Symbol("emittedEnd"),Ss=Symbol("emittingEnd"),li=Symbol("emittedError"),Is=Symbol("closed"),wu=Symbol("read"),As=Symbol("flush"),_u=Symbol("flushChunk"),mt=Symbol("encoding"),pr=Symbol("decoder"),ze=Symbol("flowing"),di=Symbol("paused"),yr=Symbol("resume"),Ue=Symbol("buffer"),Xe=Symbol("pipes"),Ge=Symbol("bufferLength"),Ba=Symbol("bufferPush"),Ts=Symbol("bufferShift"),Ze=Symbol("objectMode"),Ie=Symbol("destroyed"),Fa=Symbol("error"),za=Symbol("emitData"),yu=Symbol("emitEnd"),Ua=Symbol("emitEnd2"),It=Symbol("async"),Ga=Symbol("abort"),ks=Symbol("aborted"),ui=Symbol("signal"),Nn=Symbol("dataListeners"),it=Symbol("discarded"),fi=t=>Promise.resolve().then(t),Um=t=>t(),Gm=t=>t==="end"||t==="finish"||t==="prefinish",qm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,Hm=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Xu=class{src;dest;opts;ondrain;constructor(t,e,n){this.src=t,this.dest=e,this.opts=n,this.ondrain=()=>t[yr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},jm=class extends Xu{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,n){super(t,e,n),this.proxyErrors=i=>this.dest.emit("error",i),t.on("error",this.proxyErrors)}},Wm=t=>!!t.objectMode,Km=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Kn=class extends Cc{[ze]=!1;[di]=!1;[Xe]=[];[Ue]=[];[Ze];[mt];[It];[pr];[Gt]=!1;[un]=!1;[Ss]=!1;[Is]=!1;[li]=null;[Ge]=0;[Ie]=!1;[ui];[ks]=!1;[Nn]=0;[it]=!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");Wm(e)?(this[Ze]=!0,this[mt]=null):Km(e)?(this[mt]=e.encoding,this[Ze]=!1):(this[Ze]=!1,this[mt]=null),this[It]=!!e.async,this[pr]=this[mt]?new Mm(this[mt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Ue]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Xe]});let{signal:n}=e;n&&(this[ui]=n,n.aborted?this[Ga]():n.addEventListener("abort",()=>this[Ga]()))}get bufferLength(){return this[Ge]}get encoding(){return this[mt]}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[Ze]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[It]}set async(t){this[It]=this[It]||!!t}[Ga](){this[ks]=!0,this.emit("abort",this[ui]?.reason),this.destroy(this[ui]?.reason)}get aborted(){return this[ks]}set aborted(t){}write(t,e,n){if(this[ks])return!1;if(this[Gt])throw new Error("write after end");if(this[Ie])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof e=="function"&&(n=e,e="utf8"),e||(e="utf8");let i=this[It]?fi:Um;if(!this[Ze]&&!Buffer.isBuffer(t)){if(Hm(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(qm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Ze]?(this[ze]&&this[Ge]!==0&&this[As](!0),this[ze]?this.emit("data",t):this[Ba](t),this[Ge]!==0&&this.emit("readable"),n&&i(n),this[ze]):t.length?(typeof t=="string"&&!(e===this[mt]&&!this[pr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[mt]&&(t=this[pr].write(t)),this[ze]&&this[Ge]!==0&&this[As](!0),this[ze]?this.emit("data",t):this[Ba](t),this[Ge]!==0&&this.emit("readable"),n&&i(n),this[ze]):(this[Ge]!==0&&this.emit("readable"),n&&i(n),this[ze])}read(t){if(this[Ie])return null;if(this[it]=!1,this[Ge]===0||t===0||t&&t>this[Ge])return this[qt](),null;this[Ze]&&(t=null),this[Ue].length>1&&!this[Ze]&&(this[Ue]=[this[mt]?this[Ue].join(""):Buffer.concat(this[Ue],this[Ge])]);let e=this[wu](t||null,this[Ue][0]);return this[qt](),e}[wu](t,e){if(this[Ze])this[Ts]();else{let n=e;t===n.length||t===null?this[Ts]():typeof n=="string"?(this[Ue][0]=n.slice(t),e=n.slice(0,t),this[Ge]-=t):(this[Ue][0]=n.subarray(t),e=n.subarray(0,t),this[Ge]-=t)}return this.emit("data",e),!this[Ue].length&&!this[Gt]&&this.emit("drain"),e}end(t,e,n){return typeof t=="function"&&(n=t,t=void 0),typeof e=="function"&&(n=e,e="utf8"),t!==void 0&&this.write(t,e),n&&this.once("end",n),this[Gt]=!0,this.writable=!1,(this[ze]||!this[di])&&this[qt](),this}[yr](){this[Ie]||(!this[Nn]&&!this[Xe].length&&(this[it]=!0),this[di]=!1,this[ze]=!0,this.emit("resume"),this[Ue].length?this[As]():this[Gt]?this[qt]():this.emit("drain"))}resume(){return this[yr]()}pause(){this[ze]=!1,this[di]=!0,this[it]=!1}get destroyed(){return this[Ie]}get flowing(){return this[ze]}get paused(){return this[di]}[Ba](t){this[Ze]?this[Ge]+=1:this[Ge]+=t.length,this[Ue].push(t)}[Ts](){return this[Ze]?this[Ge]-=1:this[Ge]-=this[Ue][0].length,this[Ue].shift()}[As](t=!1){do;while(this[_u](this[Ts]())&&this[Ue].length);!t&&!this[Ue].length&&!this[Gt]&&this.emit("drain")}[_u](t){return this.emit("data",t),this[ze]}pipe(t,e){if(this[Ie])return t;this[it]=!1;let n=this[un];return e=e||{},t===mu.stdout||t===mu.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,n?e.end&&t.end():(this[Xe].push(e.proxyErrors?new jm(this,t,e):new Xu(this,t,e)),this[It]?fi(()=>this[yr]()):this[yr]()),t}unpipe(t){let e=this[Xe].find(n=>n.dest===t);e&&(this[Xe].length===1?(this[ze]&&this[Nn]===0&&(this[ze]=!1),this[Xe]=[]):this[Xe].splice(this[Xe].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let n=super.on(t,e);if(t==="data")this[it]=!1,this[Nn]++,!this[Xe].length&&!this[ze]&&this[yr]();else if(t==="readable"&&this[Ge]!==0)super.emit("readable");else if(Gm(t)&&this[un])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[li]){let i=e;this[It]?fi(()=>i.call(this,this[li])):i.call(this,this[li])}return n}removeListener(t,e){return this.off(t,e)}off(t,e){let n=super.off(t,e);return t==="data"&&(this[Nn]=this.listeners("data").length,this[Nn]===0&&!this[it]&&!this[Xe].length&&(this[ze]=!1)),n}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Nn]=0,!this[it]&&!this[Xe].length&&(this[ze]=!1)),e}get emittedEnd(){return this[un]}[qt](){!this[Ss]&&!this[un]&&!this[Ie]&&this[Ue].length===0&&this[Gt]&&(this[Ss]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Is]&&this.emit("close"),this[Ss]=!1)}emit(t,...e){let n=e[0];if(t!=="error"&&t!=="close"&&t!==Ie&&this[Ie])return!1;if(t==="data")return!this[Ze]&&!n?!1:this[It]?(fi(()=>this[za](n)),!0):this[za](n);if(t==="end")return this[yu]();if(t==="close"){if(this[Is]=!0,!this[un]&&!this[Ie])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[li]=n,super.emit(Fa,n);let o=!this[ui]||this.listeners("error").length?super.emit("error",n):!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}[za](t){for(let n of this[Xe])n.dest.write(t)===!1&&this.pause();let e=this[it]?!1:super.emit("data",t);return this[qt](),e}[yu](){return this[un]?!1:(this[un]=!0,this.readable=!1,this[It]?(fi(()=>this[Ua]()),!0):this[Ua]())}[Ua](){if(this[pr]){let e=this[pr].end();if(e){for(let n of this[Xe])n.dest.write(e);this[it]||super.emit("data",e)}}for(let e of this[Xe])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Ze]||(t.dataLength=0);let e=this.promise();return this.on("data",n=>{t.push(n),this[Ze]||(t.dataLength+=n.length)}),await e,t}async concat(){if(this[Ze])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[mt]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Ie,()=>e(new Error("stream destroyed"))),this.on("error",n=>e(n)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[it]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let n=this.read();if(n!==null)return Promise.resolve({done:!1,value:n});if(this[Gt])return e();let i,o,c=x=>{this.off("data",l),this.off("end",u),this.off(Ie,h),e(),o(x)},l=x=>{this.off("error",c),this.off("end",u),this.off(Ie,h),this.pause(),i({value:x,done:!!this[Gt]})},u=()=>{this.off("error",c),this.off("data",l),this.off(Ie,h),e(),i({done:!0,value:void 0})},h=()=>c(new Error("stream destroyed"));return new Promise((x,m)=>{o=m,i=x,this.once(Ie,h),this.once("error",c),this.once("end",u),this.once("data",l)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[it]=!1;let t=!1,e=()=>(this.pause(),this.off(Fa,e),this.off(Ie,e),this.off("end",e),t=!0,{done:!0,value:void 0}),n=()=>{if(t)return e();let i=this.read();return i===null?e():{done:!1,value:i}};return this.once("end",e),this.once(Fa,e),this.once(Ie,e),{next:n,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Ie])return t?this.emit("error",t):this.emit(Ie),this;this[Ie]=!0,this[it]=!0,this[Ue].length=0,this[Ge]=0;let e=this;return typeof e.close=="function"&&!this[Is]&&e.close(),t?this.emit("error",t):this.emit(Ie),this}static get isStream(){return Bm}},$m=nt.writev,bn=Symbol("_autoClose"),bt=Symbol("_close"),hi=Symbol("_ended"),le=Symbol("_fd"),qa=Symbol("_finished"),Kt=Symbol("_flags"),Ha=Symbol("_flush"),lc=Symbol("_handleChunk"),dc=Symbol("_makeBuf"),Si=Symbol("_mode"),Rs=Symbol("_needDrain"),Ir=Symbol("_onerror"),Ar=Symbol("_onopen"),ja=Symbol("_onread"),br=Symbol("_onwrite"),En=Symbol("_open"),yt=Symbol("_path"),gn=Symbol("_pos"),At=Symbol("_queue"),Er=Symbol("_read"),Wa=Symbol("_readSize"),Wt=Symbol("_reading"),xi=Symbol("_remain"),Ka=Symbol("_size"),zs=Symbol("_write"),Ln=Symbol("_writing"),Us=Symbol("_defaultFlag"),qn=Symbol("_errored"),Pc=class extends Kn{[qn]=!1;[le];[yt];[Wa];[Wt]=!1;[Ka];[xi];[bn];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[qn]=!1,this[le]=typeof e.fd=="number"?e.fd:void 0,this[yt]=t,this[Wa]=e.readSize||16*1024*1024,this[Wt]=!1,this[Ka]=typeof e.size=="number"?e.size:1/0,this[xi]=this[Ka],this[bn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[le]=="number"?this[Er]():this[En]()}get fd(){return this[le]}get path(){return this[yt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[En](){nt.open(this[yt],"r",(t,e)=>this[Ar](t,e))}[Ar](t,e){t?this[Ir](t):(this[le]=e,this.emit("open",e),this[Er]())}[dc](){return Buffer.allocUnsafe(Math.min(this[Wa],this[xi]))}[Er](){if(!this[Wt]){this[Wt]=!0;let t=this[dc]();if(t.length===0)return process.nextTick(()=>this[ja](null,0,t));nt.read(this[le],t,0,t.length,null,(e,n,i)=>this[ja](e,n,i))}}[ja](t,e,n){this[Wt]=!1,t?this[Ir](t):this[lc](e,n)&&this[Er]()}[bt](){if(this[bn]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,nt.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[Ir](t){this[Wt]=!0,this[bt](),this.emit("error",t)}[lc](t,e){let n=!1;return this[xi]-=t,t>0&&(n=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[xi]<=0)&&(n=!1,this[bt](),super.end()),n}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[le]=="number"&&this[Er](),!1;case"error":return this[qn]?!1:(this[qn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Vm=class extends Pc{[En](){let t=!0;try{this[Ar](null,nt.openSync(this[yt],"r")),t=!1}finally{t&&this[bt]()}}[Er](){let t=!0;try{if(!this[Wt]){this[Wt]=!0;do{let e=this[dc](),n=e.length===0?0:nt.readSync(this[le],e,0,e.length,null);if(!this[lc](n,e))break}while(!0);this[Wt]=!1}t=!1}finally{t&&this[bt]()}}[bt](){if(this[bn]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,nt.closeSync(t),this.emit("close")}}},to=class extends Lm{readable=!1;writable=!0;[qn]=!1;[Ln]=!1;[hi]=!1;[At]=[];[Rs]=!1;[yt];[Si];[bn];[le];[Us];[Kt];[qa]=!1;[gn];constructor(t,e){e=e||{},super(e),this[yt]=t,this[le]=typeof e.fd=="number"?e.fd:void 0,this[Si]=e.mode===void 0?438:e.mode,this[gn]=typeof e.start=="number"?e.start:void 0,this[bn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let n=this[gn]!==void 0?"r+":"w";this[Us]=e.flags===void 0,this[Kt]=e.flags===void 0?n:e.flags,this[le]===void 0&&this[En]()}emit(t,...e){if(t==="error"){if(this[qn])return!1;this[qn]=!0}return super.emit(t,...e)}get fd(){return this[le]}get path(){return this[yt]}[Ir](t){this[bt](),this[Ln]=!0,this.emit("error",t)}[En](){nt.open(this[yt],this[Kt],this[Si],(t,e)=>this[Ar](t,e))}[Ar](t,e){this[Us]&&this[Kt]==="r+"&&t&&t.code==="ENOENT"?(this[Kt]="w",this[En]()):t?this[Ir](t):(this[le]=e,this.emit("open",e),this[Ln]||this[Ha]())}end(t,e){return t&&this.write(t,e),this[hi]=!0,!this[Ln]&&!this[At].length&&typeof this[le]=="number"&&this[br](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[hi]?(this.emit("error",new Error("write() after end()")),!1):this[le]===void 0||this[Ln]||this[At].length?(this[At].push(t),this[Rs]=!0,!1):(this[Ln]=!0,this[zs](t),!0)}[zs](t){nt.write(this[le],t,0,t.length,this[gn],(e,n)=>this[br](e,n))}[br](t,e){t?this[Ir](t):(this[gn]!==void 0&&typeof e=="number"&&(this[gn]+=e),this[At].length?this[Ha]():(this[Ln]=!1,this[hi]&&!this[qa]?(this[qa]=!0,this[bt](),this.emit("finish")):this[Rs]&&(this[Rs]=!1,this.emit("drain"))))}[Ha](){if(this[At].length===0)this[hi]&&this[br](null,0);else if(this[At].length===1)this[zs](this[At].pop());else{let t=this[At];this[At]=[],$m(this[le],t,this[gn],(e,n)=>this[br](e,n))}}[bt](){if(this[bn]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,nt.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Qu=class extends to{[En](){let t;if(this[Us]&&this[Kt]==="r+")try{t=nt.openSync(this[yt],this[Kt],this[Si])}catch(e){if(e?.code==="ENOENT")return this[Kt]="w",this[En]();throw e}else t=nt.openSync(this[yt],this[Kt],this[Si]);this[Ar](null,t)}[bt](){if(this[bn]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,nt.closeSync(t),this.emit("close")}}[zs](t){let e=!0;try{this[br](null,nt.writeSync(this[le],t,0,t.length,this[gn])),e=!1}finally{if(e)try{this[bt]()}catch{}}}},Ym=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"]]),Xm=t=>!!t.sync&&!!t.file,Qm=t=>!t.sync&&!!t.file,ew=t=>!!t.sync&&!t.file,tw=t=>!t.sync&&!t.file,nw=t=>!!t.file,rw=t=>Ym.get(t)||t,Dc=(t={})=>{if(!t)return{};let e={};for(let[n,i]of Object.entries(t)){let o=rw(n);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Oi=(t,e,n,i,o)=>Object.assign((c=[],l,u)=>{Array.isArray(c)&&(l=c,c={}),typeof l=="function"&&(u=l,l=void 0),l=l?Array.from(l):[];let h=Dc(c);if(o?.(h,l),Xm(h)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(h,l)}else if(Qm(h)){let x=e(h,l);return u?x.then(()=>u(),u):x}else if(ew(h)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return n(h,l)}else if(tw(h)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(h,l)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:n,asyncNoFile:i,validate:o}),ow=sw.constants||{ZLIB_VERNUM:4736},Ct=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},ow)),aw=Hn.concat,Eu=Object.getOwnPropertyDescriptor(Hn,"concat"),cw=t=>t,$a=Eu?.writable===!0||Eu?.set!==void 0?t=>{Hn.concat=t?cw:aw}:t=>{},jn=Symbol("_superWrite"),Cs=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"}},Va=Symbol("flushFlag"),Oc=class extends Kn{#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 bu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new bu[e](t)}catch(n){throw new Cs(n,this.constructor)}this.#o=n=>{this.#e||(this.#e=!0,this.close(),this.emit("error",n))},this.#t?.on("error",n=>this.#o(new Cs(n))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return uc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Hn.alloc(0),{[Va]:t})))}end(t,e,n){return typeof t=="function"&&(n=t,e=void 0,t=void 0),typeof e=="function"&&(n=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(n)}get ended(){return this.#n}[jn](t){return super.write(t)}write(t,e,n){if(typeof e=="function"&&(n=e,e="utf8"),typeof t=="string"&&(t=Hn.from(t,e)),this.#e)return;uc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},$a(!0);let l;try{let h=typeof t[Va]=="number"?t[Va]:this.#r;l=this.#t._processChunk(t,h),$a(!1)}catch(h){$a(!1),this.#o(new Cs(h,this.write))}finally{this.#t&&(this.#t._handle=i,i.close=o,this.#t.close=c,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",h=>this.#o(new Cs(h,this.write)));let u;if(l)if(Array.isArray(l)&&l.length>0){let h=l[0];u=this[jn](Hn.from(h));for(let x=1;x<l.length;x++)u=this[jn](l[x])}else u=this[jn](Hn.from(l));return n&&n(),u}},tf=class extends Oc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Ct.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Ct.Z_FINISH,t.fullFlushFlag=Ct.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(Ct.Z_SYNC_FLUSH),uc(this.handle,"zlib binding closed");let n=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=n}this.handle&&(this.#e=t,this.#n=e)}}}},lw=class extends tf{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[jn](t){return this.#e?(this.#e=!1,t[9]=255,super[jn](t)):super[jn](t)}},dw=class extends tf{constructor(t){super(t,"Unzip")}},nf=class extends Oc{constructor(t,e){t=t||{},t.flush=t.flush||Ct.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Ct.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Ct.BROTLI_OPERATION_FLUSH,super(t,e)}},uw=class extends nf{constructor(t){super(t,"BrotliCompress")}},fw=class extends nf{constructor(t){super(t,"BrotliDecompress")}},rf=class extends Oc{constructor(t,e){t=t||{},t.flush=t.flush||Ct.ZSTD_e_continue,t.finishFlush=t.finishFlush||Ct.ZSTD_e_end,t.fullFlushFlag=Ct.ZSTD_e_flush,super(t,e)}},hw=class extends rf{constructor(t){super(t,"ZstdCompress")}},xw=class extends rf{constructor(t){super(t,"ZstdDecompress")}},pw=(t,e)=>{if(Number.isSafeInteger(t))t<0?mw(t,e):gw(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},gw=(t,e)=>{e[0]=128;for(var n=e.length;n>1;n--)e[n-1]=t&255,t=Math.floor(t/256)},mw=(t,e)=>{e[0]=255;var n=!1;t=t*-1;for(var i=e.length;i>1;i--){var o=t&255;t=Math.floor(t/256),n?e[i-1]=sf(o):o===0?e[i-1]=0:(n=!0,e[i-1]=of(o))}},ww=t=>{let e=t[0],n=e===128?yw(t.subarray(1,t.length)):e===255?_w(t):null;if(n===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(n))throw Error("parsed number outside of javascript safe integer range");return n},_w=t=>{for(var e=t.length,n=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),l;i?l=sf(c):c===0?l=c:(i=!0,l=of(c)),l!==0&&(n-=l*Math.pow(256,e-o-1))}return n},yw=t=>{for(var e=t.length,n=0,i=e-1;i>-1;i--){var o=Number(t[i]);o!==0&&(n+=o*Math.pow(256,e-i-1))}return n},sf=t=>(255^t)&255,of=t=>(255^t)+1&255,bw={};Nm(bw,{code:()=>Nc,isCode:()=>Gs,isName:()=>Ew,name:()=>no,normalFsTypes:()=>af});var Gs=t=>no.has(t),Ew=t=>Nc.has(t),af=new Set(["0","","1","2","3","4","5","6","7","D"]),no=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"]]),Nc=new Map(Array.from(no).map(t=>[t[1],t[0]])),Wn=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,n,i){Buffer.isBuffer(t)?this.decode(t,e||0,n,i):t&&this.#n(t)}decode(t,e,n,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");let o=Mn(t,e+156,1),c=af.has(o),l=c?n:void 0,u=c?i:void 0;if(this.path=l?.path??Mn(t,e,100),this.mode=l?.mode??u?.mode??mn(t,e+100,8),this.uid=l?.uid??u?.uid??mn(t,e+108,8),this.gid=l?.gid??u?.gid??mn(t,e+116,8),this.size=l?.size??u?.size??mn(t,e+124,12),this.mtime=l?.mtime??u?.mtime??Ja(t,e+136,12),this.cksum=mn(t,e+148,12),u&&this.#n(u,!0),l&&this.#n(l),Gs(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Mn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=l?.uname??u?.uname??Mn(t,e+265,32),this.gname=l?.gname??u?.gname??Mn(t,e+297,32),this.devmaj=l?.devmaj??u?.devmaj??mn(t,e+329,8)??0,this.devmin=l?.devmin??u?.devmin??mn(t,e+337,8)??0,t[e+475]!==0){let x=Mn(t,e+345,155);this.path=x+"/"+this.path}else{let x=Mn(t,e+345,130);x&&(this.path=x+"/"+this.path),this.atime=n?.atime??i?.atime??Ja(t,e+476,12),this.ctime=n?.ctime??i?.ctime??Ja(t,e+488,12)}let h=256;for(let x=e;x<e+148;x++)h+=t[x];for(let x=e+156;x<e+512;x++)h+=t[x];this.cksumValid=h===this.cksum,this.cksum===void 0&&h===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([n,i])=>!(i==null||n==="path"&&e||n==="linkpath"&&e||n==="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 n=this.ctime||this.atime?130:155,i=vw(this.path||"",n),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Bn(t,e,100,o)||this.needPax,this.needPax=wn(t,e+100,8,this.mode)||this.needPax,this.needPax=wn(t,e+108,8,this.uid)||this.needPax,this.needPax=wn(t,e+116,8,this.gid)||this.needPax,this.needPax=wn(t,e+124,12,this.size)||this.needPax,this.needPax=Za(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Bn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Bn(t,e+265,32,this.uname)||this.needPax,this.needPax=Bn(t,e+297,32,this.gname)||this.needPax,this.needPax=wn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=wn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Bn(t,e+345,n,c)||this.needPax,t[e+475]!==0?this.needPax=Bn(t,e+345,155,c)||this.needPax:(this.needPax=Bn(t,e+345,130,c)||this.needPax,this.needPax=Za(t,e+476,12,this.atime)||this.needPax,this.needPax=Za(t,e+488,12,this.ctime)||this.needPax);let l=256;for(let u=e;u<e+148;u++)l+=t[u];for(let u=e+156;u<e+512;u++)l+=t[u];return this.cksum=l,wn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:no.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Nc.get(t));if(Gs(e)||e==="Unsupported")this.#e=e;else if(Gs(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},vw=(t,e)=>{let n=t,i="",o,c=gr.parse(t).root||".";if(Buffer.byteLength(n)<100)o=[n,i,!1];else{i=gr.dirname(n),n=gr.basename(n);do Buffer.byteLength(n)<=100&&Buffer.byteLength(i)<=e?o=[n,i,!1]:Buffer.byteLength(n)>100&&Buffer.byteLength(i)<=e?o=[n.slice(0,99),i,!0]:(n=gr.join(gr.basename(i),n),i=gr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Mn=(t,e,n)=>t.subarray(e,e+n).toString("utf8").replace(/\0.*/,""),Ja=(t,e,n)=>Sw(mn(t,e,n)),Sw=t=>t===void 0?void 0:new Date(t*1e3),mn=(t,e,n)=>Number(t[e])&128?ww(t.subarray(e,e+n)):Aw(t,e,n),Iw=t=>isNaN(t)?void 0:t,Aw=(t,e,n)=>Iw(parseInt(t.subarray(e,e+n).toString("utf8").replace(/\0.*$/,"").trim(),8)),Tw={12:8589934591,8:2097151},wn=(t,e,n,i)=>i===void 0?!1:i>Tw[n]||i<0?(pw(i,t.subarray(e,e+n)),!0):(kw(t,e,n,i),!1),kw=(t,e,n,i)=>t.write(Rw(i,n),e,n,"ascii"),Rw=(t,e)=>Cw(Math.floor(t).toString(8),e),Cw=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Za=(t,e,n,i)=>i===void 0?!1:wn(t,e,n,i.getTime()/1e3),Pw=new Array(156).join("\0"),Bn=(t,e,n,i)=>i===void 0?!1:(t.write(i+Pw,e,n,"utf8"),i.length!==Buffer.byteLength(i)||i.length>n),Zs=class cf{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,n=!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=n,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 n=Buffer.byteLength(e),i=512*Math.ceil(1+n/512),o=Buffer.allocUnsafe(i);for(let c=0;c<512;c++)o[c]=0;new Wn({path:("PaxHeader/"+Dw(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:n,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,n,"utf8");for(let c=n+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 n=this[e],i=n instanceof Date?n.getTime()/1e3:n,o=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+i+`
90
+ `,c=Buffer.byteLength(o),l=Math.floor(Math.log(c)/Math.log(10))+1;return c+l>=Math.pow(10,l)&&(l+=1),l+c+o}static parse(e,n,i=!1){return new cf(Ow(Nw(e),n),i)}},Ow=(t,e)=>e?Object.assign({},e,t):t,Nw=t=>t.replace(/\n$/,"").split(`
91
+ `).reduce(Lw,Object.create(null)),Lw=(t,e)=>{let n=parseInt(e,10);if(n!==Buffer.byteLength(e)+1)return t;e=e.slice((n+" ").length);let i=e.split("="),o=i.shift();if(!o)return t;let c=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),l=i.join("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(l)*1e3):/^[0-9]+$/.test(l)?+l:l,t},Mw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Q=Mw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),Bw=class extends Kn{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,n){switch(super({}),this.pause(),this.extended=e,this.globalExtended=n,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=Q(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?Q(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#e(e),n&&this.#e(n,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let n=this.remain,i=this.blockRemain;return this.remain=Math.max(0,n-e),this.blockRemain=Math.max(0,i-e),this.ignore?!0:n>=e?super.write(t):super.write(t.subarray(0,n))}#e(t,e=!1){t.path&&(t.path=Q(t.path)),t.linkpath&&(t.linkpath=Q(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([n,i])=>!(i==null||n==="path"&&e))))}},ro=(t,e,n,i={})=>{t.file&&(i.file=t.file),t.cwd&&(i.cwd=t.cwd),i.code=n instanceof Error&&n.code||e,i.tarCode=e,!t.strict&&i.recoverable!==!1?(n instanceof Error&&(i=Object.assign(n,i),n=n.message),t.emit("warn",e,n,i)):n instanceof Error?t.emit("error",Object.assign(n,i)):t.emit("error",Object.assign(new Error(`${e}: ${n}`),i))},Fw=1024*1024,fc=Buffer.from([31,139]),hc=Buffer.from([40,181,47,253]),zw=Math.max(fc.length,hc.length),dt=Symbol("state"),Fn=Symbol("writeEntry"),Ht=Symbol("readEntry"),Ya=Symbol("nextEntry"),vu=Symbol("processEntry"),Tt=Symbol("extendedHeader"),pi=Symbol("globalExtendedHeader"),fn=Symbol("meta"),Su=Symbol("emitMeta"),ge=Symbol("buffer"),jt=Symbol("queue"),hn=Symbol("ended"),Xa=Symbol("emittedEnd"),zn=Symbol("emit"),Re=Symbol("unzip"),Ps=Symbol("consumeChunk"),Ds=Symbol("consumeChunkSub"),Qa=Symbol("consumeBody"),Iu=Symbol("consumeMeta"),Au=Symbol("consumeHeader"),gi=Symbol("consuming"),ec=Symbol("bufferConcat"),Os=Symbol("maybeEnd"),mr=Symbol("writing"),xn=Symbol("aborted"),Ns=Symbol("onDone"),Un=Symbol("sawValidEntry"),Ls=Symbol("sawNullBlock"),Ms=Symbol("sawEOF"),Tu=Symbol("closeStream"),Uw=()=>!0,Di=class extends iw{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[jt]=[];[ge];[Ht];[Fn];[dt]="begin";[fn]="";[Tt];[pi];[hn]=!1;[Re];[xn]=!1;[Un];[Ls]=!1;[Ms]=!1;[mr]=!1;[gi]=!1;[Xa]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Ns,()=>{(this[dt]==="begin"||this[Un]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Ns,t.ondone):this.on(Ns,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||Fw,this.filter=typeof t.filter=="function"?t.filter:Uw;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 n=t.file&&(t.file.endsWith(".tar.zst")||t.file.endsWith(".tzst"));this.zstd=!(t.gzip||t.brotli)&&t.zstd!==void 0?t.zstd:n?!0:void 0,this.on("end",()=>this[Tu]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,n={}){ro(this,t,e,n)}[Au](t,e){this[Un]===void 0&&(this[Un]=!1);let n;try{n=new Wn(t,e,this[Tt],this[pi])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(n.nullBlock)this[Ls]?(this[Ms]=!0,this[dt]==="begin"&&(this[dt]="header"),this[zn]("eof")):(this[Ls]=!0,this[zn]("nullBlock"));else if(this[Ls]=!1,!n.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:n});else if(!n.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:n});else{let i=n.type;if(/^(Symbolic)?Link$/.test(i)&&!n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:n});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:n});else{let o=this[Fn]=new Bw(n,this[Tt],this[pi]);if(!this[Un])if(o.remain){let c=()=>{o.invalid||(this[Un]=!0)};o.on("end",c)}else this[Un]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[zn]("ignoredEntry",o),this[dt]="ignore",o.resume()):o.size>0&&(this[fn]="",o.on("data",c=>this[fn]+=c),this[dt]="meta"):(this[Tt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[zn]("ignoredEntry",o),this[dt]=o.remain?"ignore":"header",o.resume()):(o.remain?this[dt]="body":(this[dt]="header",o.end()),this[Ht]?this[jt].push(o):(this[jt].push(o),this[Ya]())))}}}[Tu](){queueMicrotask(()=>this.emit("close"))}[vu](t){let e=!0;if(!t)this[Ht]=void 0,e=!1;else if(Array.isArray(t)){let[n,...i]=t;this.emit(n,...i)}else this[Ht]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Ya]()),e=!1);return e}[Ya](){do;while(this[vu](this[jt].shift()));if(this[jt].length===0){let t=this[Ht];!t||t.flowing||t.size===t.remain?this[mr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Qa](t,e){let n=this[Fn];if(!n)throw new Error("attempt to consume body without entry??");let i=n.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return n.write(o),n.blockRemain||(this[dt]="header",this[Fn]=void 0,n.end()),o.length}[Iu](t,e){let n=this[Fn],i=this[Qa](t,e);return!this[Fn]&&n&&this[Su](n),i}[zn](t,e,n){this[jt].length===0&&!this[Ht]?this.emit(t,e,n):this[jt].push([t,e,n])}[Su](t){switch(this[zn]("meta",this[fn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Tt]=Zs.parse(this[fn],this[Tt],!1);break;case"GlobalExtendedHeader":this[pi]=Zs.parse(this[fn],this[pi],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Tt]??Object.create(null);this[Tt]=e,e.path=this[fn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Tt]||Object.create(null);this[Tt]=e,e.linkpath=this[fn].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[xn]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,n){if(typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[xn])return n?.(),!1;if((this[Re]===void 0||this.brotli===void 0&&this[Re]===!1)&&t){if(this[ge]&&(t=Buffer.concat([this[ge],t]),this[ge]=void 0),t.length<zw)return this[ge]=t,n?.(),!0;for(let l=0;this[Re]===void 0&&l<fc.length;l++)t[l]!==fc[l]&&(this[Re]=!1);let o=!1;if(this[Re]===!1&&this.zstd!==!1){o=!0;for(let l=0;l<hc.length;l++)if(t[l]!==hc[l]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Re]===!1&&c)if(t.length<512)if(this[hn])this.brotli=!0;else return this[ge]=t,n?.(),!0;else try{new Wn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Re]===void 0||this[Re]===!1&&(this.brotli||o)){let l=this[hn];this[hn]=!1,this[Re]=this[Re]===void 0?new dw({}):o?new xw({}):new fw({}),this[Re].on("data",h=>this[Ps](h)),this[Re].on("error",h=>this.abort(h)),this[Re].on("end",()=>{this[hn]=!0,this[Ps]()}),this[mr]=!0;let u=!!this[Re][l?"end":"write"](t);return this[mr]=!1,n?.(),u}}this[mr]=!0,this[Re]?this[Re].write(t):this[Ps](t),this[mr]=!1;let i=this[jt].length>0?!1:this[Ht]?this[Ht].flowing:!0;return!i&&this[jt].length===0&&this[Ht]?.once("drain",()=>this.emit("drain")),n?.(),i}[ec](t){t&&!this[xn]&&(this[ge]=this[ge]?Buffer.concat([this[ge],t]):t)}[Os](){if(this[hn]&&!this[Xa]&&!this[xn]&&!this[gi]){this[Xa]=!0;let t=this[Fn];if(t&&t.blockRemain){let e=this[ge]?this[ge].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[ge]&&t.write(this[ge]),t.end()}this[zn](Ns)}}[Ps](t){if(this[gi]&&t)this[ec](t);else if(!t&&!this[ge])this[Os]();else if(t){if(this[gi]=!0,this[ge]){this[ec](t);let e=this[ge];this[ge]=void 0,this[Ds](e)}else this[Ds](t);for(;this[ge]&&this[ge]?.length>=512&&!this[xn]&&!this[Ms];){let e=this[ge];this[ge]=void 0,this[Ds](e)}this[gi]=!1}(!this[ge]||this[hn])&&this[Os]()}[Ds](t){let e=0,n=t.length;for(;e+512<=n&&!this[xn]&&!this[Ms];)switch(this[dt]){case"begin":case"header":this[Au](t,e),e+=512;break;case"ignore":case"body":e+=this[Qa](t,e);break;case"meta":e+=this[Iu](t,e);break;default:throw new Error("invalid state: "+this[dt])}e<n&&(this[ge]=this[ge]?Buffer.concat([t.subarray(e),this[ge]]):t.subarray(e))}end(t,e,n){return typeof t=="function"&&(n=t,e=void 0,t=void 0),typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),n&&this.once("finish",n),this[xn]||(this[Re]?(t&&this[Re].write(t),this[Re].end()):(this[hn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Os]())),this}},Ii=t=>{let e=t.length-1,n=-1;for(;e>-1&&t.charAt(e)==="/";)n=e,e--;return n===-1?t:t.slice(0,n)},Gw=t=>{let e=t.onReadEntry;t.onReadEntry=e?n=>{e(n),n.resume()}:n=>n.resume()},lf=(t,e)=>{let n=new Map(e.map(c=>[Ii(c),!0])),i=t.filter,o=(c,l="")=>{let u=l||Zm(c).root||".",h;if(c===u)h=!1;else{let x=n.get(c);h=x!==void 0?x:o(Jm(c),u)}return n.set(c,h),h};t.filter=i?(c,l)=>i(c,l)&&o(Ii(c)):c=>o(Ii(c))},qw=t=>{let e=new Di(t),n=t.file,i;try{i=vr.openSync(n,"r");let o=vr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let l=Buffer.allocUnsafe(o.size),u=vr.readSync(i,l,0,o.size,0);e.end(u===l.byteLength?l:l.subarray(0,u))}else{let l=0,u=Buffer.allocUnsafe(c);for(;l<o.size;){let h=vr.readSync(i,u,0,c,l);if(h===0)break;l+=h,e.write(u.subarray(0,h))}e.end()}}finally{if(typeof i=="number")try{vr.closeSync(i)}catch{}}},Hw=(t,e)=>{let n=new Di(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{n.on("error",l),n.on("end",c),vr.stat(o,(u,h)=>{if(u)l(u);else{let x=new Pc(o,{readSize:i,size:h.size});x.on("error",l),x.pipe(n)}})})},Tr=Oi(qw,Hw,t=>new Di(t),t=>new Di(t),(t,e)=>{e?.length&&lf(t,e),t.noResume||Gw(t)}),df=(t,e,n)=>(t&=4095,n&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t),{isAbsolute:Ww,parse:Ru}=jw,Lc=t=>{let e="",n=Ru(t);for(;Ww(t)||n.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":n.root;t=t.slice(i.length),e+=i,n=Ru(t)}return[e,t]},io=["|","<",">","?",":"],Mc=io.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),Kw=new Map(io.map((t,e)=>[t,Mc[e]])),$w=new Map(Mc.map((t,e)=>[t,io[e]])),Cu=t=>io.reduce((e,n)=>e.split(n).join(Kw.get(n)),t),Vw=t=>Mc.reduce((e,n)=>e.split(n).join($w.get(n)),t),uf=(t,e)=>e?(t=Q(t).replace(/^\.(\/|$)/,""),Ii(e)+"/"+t):Q(t),Jw=16*1024*1024,Pu=Symbol("process"),Du=Symbol("file"),Ou=Symbol("directory"),xc=Symbol("symlink"),Nu=Symbol("hardlink"),mi=Symbol("header"),qs=Symbol("read"),pc=Symbol("lstat"),Hs=Symbol("onlstat"),gc=Symbol("onread"),mc=Symbol("onreadlink"),wc=Symbol("openfile"),_c=Symbol("onopenfile"),_n=Symbol("close"),Xs=Symbol("mode"),yc=Symbol("awaitDrain"),tc=Symbol("ondrain"),Rt=Symbol("prefix"),ff=class extends Kn{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 n=Dc(e);super(),this.path=Q(t),this.portable=!!n.portable,this.maxReadSize=n.maxReadSize||Jw,this.linkCache=n.linkCache||new Map,this.statCache=n.statCache||new Map,this.preservePaths=!!n.preservePaths,this.cwd=Q(n.cwd||process.cwd()),this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.mtime=n.mtime,this.prefix=n.prefix?Q(n.prefix):void 0,this.onWriteEntry=n.onWriteEntry,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let i=!1;if(!this.preservePaths){let[c,l]=Lc(this.path);c&&typeof l=="string"&&(this.path=l,i=c)}this.win32=!!n.win32||process.platform==="win32",this.win32&&(this.path=Vw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=Q(n.absolute||ku.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[Hs](o):this[pc]()}warn(t,e,n={}){return ro(this,t,e,n)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[pc](){kt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Hs](e)})}[Hs](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=Xw(t),this.emit("stat",t),this[Pu]()}[Pu](){switch(this.type){case"File":return this[Du]();case"Directory":return this[Ou]();case"SymbolicLink":return this[xc]();default:return this.end()}}[Xs](t){return df(t,this.type==="Directory",this.portable)}[Rt](t){return uf(t,this.prefix)}[mi](){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 Wn({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this[Xs](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new Zs({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[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)}[Ou](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[mi](),this.end()}[xc](){kt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[mc](e)})}[mc](t){this.linkpath=Q(t),this[mi](),this.end()}[Nu](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=Q(ku.relative(this.cwd,t)),this.stat.size=0,this[mi](),this.end()}[Du](){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[Nu](e);this.linkCache.set(t,this.absolute)}if(this[mi](),this.stat.size===0)return this.end();this[wc]()}[wc](){kt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[_c](e)})}[_c](t){if(this.fd=t,this.#e)return this[_n]();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[qs]()}[qs](){let{fd:t,buf:e,offset:n,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");kt.read(t,e,n,i,o,(c,l)=>{if(c)return this[_n](()=>this.emit("error",c));this[gc](l)})}[_n](t=()=>{}){this.fd!==void 0&&kt.close(this.fd,t)}[gc](t){if(t<=0&&this.remain>0){let n=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[_n](()=>this.emit("error",n))}if(t>this.remain){let n=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[_n](()=>this.emit("error",n))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let n=t;n<this.length&&t<this.blockRemain;n++)this.buf[n+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[tc]():this[yc](()=>this[tc]())}[yc](t){this.once("drain",t)}write(t,e,n){if(typeof e=="function"&&(n=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,n)}[tc](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[_n](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[qs]()}},Zw=class extends ff{sync=!0;[pc](){this[Hs](kt.lstatSync(this.absolute))}[xc](){this[mc](kt.readlinkSync(this.absolute))}[wc](){this[_c](kt.openSync(this.absolute,"r"))}[qs](){let t=!0;try{let{fd:e,buf:n,offset:i,length:o,pos:c}=this;if(e===void 0||n===void 0)throw new Error("fd and buf must be set in READ method");let l=kt.readSync(e,n,i,o,c);this[gc](l),t=!1}finally{if(t)try{this[_n](()=>{})}catch{}}}[yc](t){t()}[_n](t=()=>{}){this.fd!==void 0&&kt.closeSync(this.fd),t()}},Yw=class extends Kn{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,n={}){return ro(this,t,e,n)}constructor(t,e={}){let n=Dc(e);super(),this.preservePaths=!!n.preservePaths,this.portable=!!n.portable,this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.onWriteEntry=n.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=n.prefix,this.path=Q(t.path),this.mode=t.mode!==void 0?this[Xs](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:n.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?Q(t.linkpath):void 0,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let o=!1;if(!this.preservePaths){let[l,u]=Lc(this.path);l&&typeof u=="string"&&(this.path=u,o=l)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Wn({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 Zs({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[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 uf(t,this.prefix)}[Xs](t){return df(t,this.type==="Directory",this.portable)}write(t,e,n){typeof e=="function"&&(n=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,n)}end(t,e,n){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof t=="function"&&(n=t,e=void 0,t=void 0),typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e??"utf8")),n&&this.once("finish",n),t?super.end(t,n):super.end(n),this}},Xw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",Qw=class Sr{tail;head;length=0;static create(e=[]){return new Sr(e)}constructor(e=[]){for(let n of e)this.push(n)}*[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 n=e.next,i=e.prev;return n&&(n.prev=i),i&&(i.next=n),e===this.head&&(this.head=n),e===this.tail&&(this.tail=i),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,n}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let n=this.head;e.list=this,e.next=n,n&&(n.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 n=this.tail;e.list=this,e.prev=n,n&&(n.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let n=0,i=e.length;n<i;n++)t_(this,e[n]);return this.length}unshift(...e){for(var n=0,i=e.length;n<i;n++)n_(this,e[n]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,n=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,n.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,n=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,n.list=void 0,this.length--,e}forEach(e,n){n=n||this;for(let i=this.head,o=0;i;o++)e.call(n,i.value,o,this),i=i.next}forEachReverse(e,n){n=n||this;for(let i=this.tail,o=this.length-1;i;o--)e.call(n,i.value,o,this),i=i.prev}get(e){let n=0,i=this.head;for(;i&&n<e;n++)i=i.next;if(n===e&&i)return i.value}getReverse(e){let n=0,i=this.tail;for(;i&&n<e;n++)i=i.prev;if(n===e&&i)return i.value}map(e,n){n=n||this;let i=new Sr;for(let o=this.head;o;)i.push(e.call(n,o.value,this)),o=o.next;return i}mapReverse(e,n){n=n||this;var i=new Sr;for(let o=this.tail;o;)i.push(e.call(n,o.value,this)),o=o.prev;return i}reduce(e,n){let i,o=this.head;if(arguments.length>1)i=n;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,n){let i,o=this.tail;if(arguments.length>1)i=n;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 n=0,i=this.head;i;n++)e[n]=i.value,i=i.next;return e}toArrayReverse(){let e=new Array(this.length);for(let n=0,i=this.tail;i;n++)e[n]=i.value,i=i.prev;return e}slice(e=0,n=this.length){n<0&&(n+=this.length),e<0&&(e+=this.length);let i=new Sr;if(n<e||n<0)return i;e<0&&(e=0),n>this.length&&(n=this.length);let o=this.head,c=0;for(c=0;o&&c<e;c++)o=o.next;for(;o&&c<n;c++,o=o.next)i.push(o.value);return i}sliceReverse(e=0,n=this.length){n<0&&(n+=this.length),e<0&&(e+=this.length);let i=new Sr;if(n<e||n<0)return i;e<0&&(e=0),n>this.length&&(n=this.length);let o=this.length,c=this.tail;for(;c&&o>n;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,n=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let l=0;o&&l<e;l++)o=o.next;let c=[];for(let l=0;o&&l<n;l++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let l of i)o=e_(this,o,l);return c}reverse(){let e=this.head,n=this.tail;for(let i=e;i;i=i.prev){let o=i.prev;i.prev=i.next,i.next=o}return this.head=n,this.tail=e,this}};function e_(t,e,n){let i=e,o=e?e.next:t.head,c=new Bc(n,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function t_(t,e){t.tail=new Bc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function n_(t,e){t.head=new Bc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Bc=class{list;next;prev;value;constructor(t,e,n,i){this.list=i,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,n?(n.prev=this,this.next=n):this.next=void 0}},Mu=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Bu=Buffer.alloc(1024),js=Symbol("onStat"),wi=Symbol("ended"),wt=Symbol("queue"),_i=Symbol("pendingLinks"),pn=Symbol("current"),Gn=Symbol("process"),yi=Symbol("processing"),Bs=Symbol("processJob"),_t=Symbol("jobs"),nc=Symbol("jobDone"),Ws=Symbol("addFSEntry"),Fu=Symbol("addTarEntry"),bc=Symbol("stat"),Ec=Symbol("readdir"),Ks=Symbol("onreaddir"),$s=Symbol("pipe"),zu=Symbol("entry"),rc=Symbol("entryOpt"),Vs=Symbol("writeEntryClass"),hf=Symbol("write"),ic=Symbol("ondrain"),so=class extends Kn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Vs];onWriteEntry;[wt];[_i]=new Map;[_t]=0;[yi]=!1;[wi]=!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=Q(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[Vs]=ff,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 lw(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new uw(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new hw(t.zstd)),!this.zip)throw new Error("impossible");let e=this.zip;e.on("data",n=>super.write(n)),e.on("end",()=>super.end()),e.on("drain",()=>this[ic]()),this.on("resume",()=>e.resume())}else this.on("drain",this[ic]);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[wt]=new Qw,this[_t]=0,this.jobs=Number(t.jobs)||4,this[yi]=!1,this[wi]=!1}[hf](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,n){return typeof t=="function"&&(n=t,t=void 0),typeof e=="function"&&(n=e,e=void 0),t&&this.add(t),this[wi]=!0,this[Gn](),n&&n(),this}write(t){if(this[wi])throw new Error("write after end");return typeof t=="string"?this[Ws](t):this[Fu](t),this.flowing}[Fu](t){let e=Q(Lu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let n=new Mu(t.path,e);n.entry=new Yw(t,this[rc](n)),n.entry.on("end",()=>this[nc](n)),this[_t]+=1,this[wt].push(n)}this[Gn]()}[Ws](t){let e=Q(Lu.resolve(this.cwd,t));this[wt].push(new Mu(t,e)),this[Gn]()}[bc](t){t.pending=!0,this[_t]+=1;let e=this.follow?"stat":"lstat";Ys[e](t.absolute,(n,i)=>{t.pending=!1,this[_t]-=1,n?this.emit("error",n):this[js](t,i)})}[js](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[pn])this[Bs](t);else{let n=`${e.dev}:${e.ino}`,i=this[_i].get(n);i?i.push(t):this[_i].set(n,[t]),t.pendingLink=!0,t.pending=!0}this[Gn]()}[Ec](t){t.pending=!0,this[_t]+=1,Ys.readdir(t.absolute,(e,n)=>{if(t.pending=!1,this[_t]-=1,e)return this.emit("error",e);this[Ks](t,n)})}[Ks](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Gn]()}[Gn](){if(!this[yi]){this[yi]=!0;for(let t=this[wt].head;t&&this[_t]<this.jobs;t=t.next)if(this[Bs](t.value),t.value.ignore){let e=t.next;this[wt].removeNode(t),t.next=e}this[yi]=!1,this[wi]&&this[wt].length===0&&this[_t]===0&&(this.zip?this.zip.end(Bu):(super.write(Bu),super.end()))}}get[pn](){return this[wt]&&this[wt].head&&this[wt].head.value}[nc](t){this[wt].shift(),this[_t]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let n=`${e.dev}:${e.ino}`,i=this[_i].get(n);if(i){this[_i].delete(n);for(let o of i)o.pending=!1,this[Bs](o)}}this[Gn]()}[Bs](t){if(t.pending&&t.pendingLink&&t===this[pn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[pn]&&!t.piped&&this[$s](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[js](t,e):this[bc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[Ks](t,e):this[Ec](t),!t.readdir)return}if(t.entry=this[zu](t),!t.entry){t.ignore=!0;return}t===this[pn]&&!t.piped&&this[$s](t)}}}[rc](t){return{onwarn:(e,n,i)=>this.warn(e,n,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}}[zu](t){this[_t]+=1;try{return new this[Vs](t.path,this[rc](t)).on("end",()=>this[nc](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[ic](){this[pn]&&this[pn].entry&&this[pn].entry.resume()}[$s](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ws](c+i)});let e=t.entry,n=this.zip;if(!e)throw new Error("cannot pipe without source");n?e.on("data",i=>{n.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,n={}){ro(this,t,e,n)}},Fc=class extends so{sync=!0;constructor(t){super(t),this[Vs]=Zw}pause(){}resume(){}[bc](t){let e=this.follow?"statSync":"lstatSync";this[js](t,Ys[e](t.absolute))}[Ec](t){this[Ks](t,Ys.readdirSync(t.absolute))}[$s](t){let e=t.entry,n=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ws](c+i)}),!e)throw new Error("Cannot pipe without source");n?e.on("data",i=>{n.write(i)}):e.on("data",i=>{super[hf](i)})}},r_=(t,e)=>{let n=new Fc(t),i=new Qu(t.file,{mode:t.mode||438});n.pipe(i),xf(n,e)},i_=(t,e)=>{let n=new so(t),i=new to(t.file,{mode:t.mode||438});n.pipe(i);let o=new Promise((c,l)=>{i.on("error",l),i.on("close",c),n.on("error",l)});return pf(n,e).catch(c=>n.emit("error",c)),o},xf=(t,e)=>{e.forEach(n=>{n.charAt(0)==="@"?Tr({file:ef.resolve(t.cwd,n.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n)}),t.end()},pf=async(t,e)=>{for(let n of e)n.charAt(0)==="@"?await Tr({file:ef.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(n);t.end()},s_=(t,e)=>{let n=new Fc(t);return xf(n,e),n},o_=(t,e)=>{let n=new so(t);return pf(n,e).catch(i=>n.emit("error",i)),n},LI=Oi(r_,i_,s_,o_,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),c_=process.env.__FAKE_PLATFORM__||process.platform,_f=c_==="win32",{O_CREAT:yf,O_NOFOLLOW:Uu,O_TRUNC:bf,O_WRONLY:Ef}=wf.constants,vf=Number(process.env.__FAKE_FS_O_FILENAME__)||wf.constants.UV_FS_O_FILEMAP||0,l_=_f&&!!vf,d_=512*1024,u_=vf|bf|yf|Ef,Gu=!_f&&typeof Uu=="number"?Uu|bf|yf|Ef:null,Sf=Gu!==null?()=>Gu:l_?t=>t<d_?u_:"w":()=>"w",vc=(t,e,n)=>{try{return oo.lchownSync(t,e,n)}catch(i){if(i?.code!=="ENOENT")throw i}},Qs=(t,e,n,i)=>{oo.lchown(t,e,n,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},f_=(t,e,n,i,o)=>{if(e.isDirectory())If(Ai.resolve(t,e.name),n,i,c=>{if(c)return o(c);let l=Ai.resolve(t,e.name);Qs(l,n,i,o)});else{let c=Ai.resolve(t,e.name);Qs(c,n,i,o)}},If=(t,e,n,i)=>{oo.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 Qs(t,e,n,i);let l=c.length,u=null,h=x=>{if(!u){if(x)return i(u=x);if(--l===0)return Qs(t,e,n,i)}};for(let x of c)f_(t,x,e,n,h)})},h_=(t,e,n,i)=>{e.isDirectory()&&Af(Ai.resolve(t,e.name),n,i),vc(Ai.resolve(t,e.name),n,i)},Af=(t,e,n)=>{let i;try{i=oo.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return vc(t,e,n);throw c}for(let o of i)h_(t,o,e,n);return vc(t,e,n)},Tf=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"}},ao=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"}},p_=(t,e)=>{ot.stat(t,(n,i)=>{(n||!i.isDirectory())&&(n=new Tf(t,n?.code||"ENOTDIR")),e(n)})},g_=(t,e,n)=>{t=Q(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,l=e.uid,u=e.gid,h=typeof l=="number"&&typeof u=="number"&&(l!==e.processUid||u!==e.processGid),x=e.preserve,m=e.unlink,_=Q(e.cwd),S=(v,I)=>{v?n(v):I&&h?If(I,l,u,A=>S(A)):c?ot.chmod(t,o,n):n()};if(t===_)return p_(t,S);if(x)return x_.mkdir(t,{mode:o,recursive:!0}).then(v=>S(null,v??void 0),S);let y=Q(eo.relative(_,t)).split("/");Sc(_,y,o,m,_,void 0,S)},Sc=(t,e,n,i,o,c,l)=>{if(e.length===0)return l(null,c);let u=e.shift(),h=Q(eo.resolve(t+"/"+u));ot.mkdir(h,n,kf(h,e,n,i,o,c,l))},kf=(t,e,n,i,o,c,l)=>u=>{u?ot.lstat(t,(h,x)=>{if(h)h.path=h.path&&Q(h.path),l(h);else if(x.isDirectory())Sc(t,e,n,i,o,c,l);else if(i)ot.unlink(t,m=>{if(m)return l(m);ot.mkdir(t,n,kf(t,e,n,i,o,c,l))});else{if(x.isSymbolicLink())return l(new ao(t,t+"/"+e.join("/")));l(u)}}):(c=c||t,Sc(t,e,n,i,o,c,l))},m_=t=>{let e=!1,n;try{e=ot.statSync(t).isDirectory()}catch(i){n=i?.code}finally{if(!e)throw new Tf(t,n??"ENOTDIR")}},w_=(t,e)=>{t=Q(t);let n=e.umask??18,i=e.mode|448,o=(i&n)!==0,c=e.uid,l=e.gid,u=typeof c=="number"&&typeof l=="number"&&(c!==e.processUid||l!==e.processGid),h=e.preserve,x=e.unlink,m=Q(e.cwd),_=v=>{v&&u&&Af(v,c,l),o&&ot.chmodSync(t,i)};if(t===m)return m_(m),_();if(h)return _(ot.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=Q(eo.relative(m,t)).split("/"),y;for(let v=S.shift(),I=m;v&&(I+="/"+v);v=S.shift()){I=Q(eo.resolve(I));try{ot.mkdirSync(I,i),y=y||I}catch{let A=ot.lstatSync(I);if(A.isDirectory())continue;if(x){ot.unlinkSync(I),ot.mkdirSync(I,i),y=y||I;continue}else if(A.isSymbolicLink())return new ao(I,I+"/"+S.join("/"))}}return _(y)},sc=Object.create(null),qu=1e4,wr=new Set,__=t=>{wr.has(t)?wr.delete(t):sc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),wr.add(t);let e=sc[t],n=wr.size-qu;if(n>qu/10){for(let i of wr)if(wr.delete(i),delete sc[i],--n<=0)break}return e},y_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,b_=y_==="win32",E_=t=>t.split("/").slice(0,-1).reduce((e,n)=>{let i=e.at(-1);return i!==void 0&&(n=Rf(i,n)),e.push(n||"/"),e},[]),v_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=b_?["win32 parallelization disabled"]:t.map(i=>Ii(Rf(__(i))));let n=new Set(t.map(i=>E_(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:n,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 n){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(n=>this.#e.get(n)),dirs:[...e.dirs].map(n=>this.#e.get(n))}}check(t){let{paths:e,dirs:n}=this.#s(t);return e.every(i=>i&&i[0]===t)&&n.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:n,dirs:i}=e,o=new Set;for(let c of n){let l=this.#e.get(c);if(!l||l?.[0]!==t)continue;let u=l[1];if(!u){this.#e.delete(c);continue}if(l.shift(),typeof u=="function")o.add(u);else for(let h of u)o.add(h)}for(let c of i){let l=this.#e.get(c),u=l?.[0];if(!(!l||!(u instanceof Set)))if(u.size===1&&l.length===1){this.#e.delete(c);continue}else if(u.size===1){l.shift();let h=l[0];typeof h=="function"&&o.add(h)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},S_=()=>process.umask(),Hu=Symbol("onEntry"),Ic=Symbol("checkFs"),ju=Symbol("checkFs2"),Ac=Symbol("isReusable"),ut=Symbol("makeFs"),Tc=Symbol("file"),kc=Symbol("directory"),Js=Symbol("link"),Wu=Symbol("symlink"),Ku=Symbol("hardlink"),vi=Symbol("ensureNoSymlink"),$u=Symbol("unsupported"),Vu=Symbol("checkPath"),oc=Symbol("stripAbsolutePath"),yn=Symbol("mkdir"),qe=Symbol("onError"),Fs=Symbol("pending"),Ju=Symbol("pend"),_r=Symbol("unpend"),ac=Symbol("ended"),cc=Symbol("maybeClose"),Rc=Symbol("skip"),Ti=Symbol("doChown"),ki=Symbol("uid"),Ri=Symbol("gid"),Ci=Symbol("checkedCwd"),I_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Pi=I_==="win32",A_=1024,T_=(t,e)=>{if(!Pi)return ie.unlink(t,e);let n=t+".DELETE."+mf(16).toString("hex");ie.rename(t,n,i=>{if(i)return e(i);ie.unlink(n,e)})},k_=t=>{if(!Pi)return ie.unlinkSync(t);let e=t+".DELETE."+mf(16).toString("hex");ie.renameSync(t,e),ie.unlinkSync(e)},Zu=(t,e,n)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:n,zc=class extends Di{[ac]=!1;[Ci]=!1;[Fs]=0;reservations=new v_;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[ac]=!0,this[cc]()},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:A_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Pi,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=Q(Le.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:S_():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[Hu](e))}warn(t,e,n={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(n.recoverable=!1),super.warn(t,e,n)}[cc](){this[ac]&&this[Fs]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[oc](t,e){let n=t[e],{type:i}=t;if(!n||this.preservePaths)return!0;let[o,c]=Lc(n),l=c.replaceAll(/\\/g,"/").split("/");if(l.includes("..")||Pi&&/^[a-z]:\.\.$/i.test(l[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:n}),!1;let u=Le.posix.dirname(t.path),h=Le.posix.normalize(Le.posix.join(u,l.join("/")));if(h.startsWith("../")||h==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:n}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:n})),!0}[Vu](t){let e=Q(t.path),n=e.split("/");if(this.strip){if(n.length<this.strip)return!1;if(t.type==="Link"){let i=Q(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}n.splice(0,this.strip),t.path=n.join("/")}if(isFinite(this.maxDepth)&&n.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:n.length,maxDepth:this.maxDepth}),!1;if(!this[oc](t,"path")||!this[oc](t,"linkpath"))return!1;if(t.absolute=Le.isAbsolute(t.path)?Q(Le.resolve(t.path)):Q(Le.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:Q(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=Le.win32.parse(String(t.absolute));t.absolute=i+Cu(String(t.absolute).slice(i.length));let{root:o}=Le.win32.parse(t.path);t.path=o+Cu(t.path.slice(o.length))}return!0}[Hu](t){if(!this[Vu](t))return t.resume();switch(a_.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[Ic](t);default:return this[$u](t)}}[qe](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[_r](),e.resume())}[yn](t,e,n){g_(Q(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},n)}[Ti](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}[ki](t){return Zu(this.uid,t.uid,this.processUid)}[Ri](t){return Zu(this.gid,t.gid,this.processGid)}[Tc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new to(String(t.absolute),{flags:Sf(t.size),mode:n,autoClose:!1});i.on("error",u=>{i.fd&&ie.close(i.fd,()=>{}),i.write=()=>!0,this[qe](u,t),e()});let o=1,c=u=>{if(u){i.fd&&ie.close(i.fd,()=>{}),this[qe](u,t),e();return}--o===0&&i.fd!==void 0&&ie.close(i.fd,h=>{h?this[qe](h,t):this[_r](),e()})};i.on("finish",()=>{let u=String(t.absolute),h=i.fd;if(typeof h=="number"&&t.mtime&&!this.noMtime){o++;let x=t.atime||new Date,m=t.mtime;ie.futimes(h,x,m,_=>_?ie.utimes(u,x,m,S=>c(S&&_)):c())}if(typeof h=="number"&&this[Ti](t)){o++;let x=this[ki](t),m=this[Ri](t);typeof x=="number"&&typeof m=="number"&&ie.fchown(h,x,m,_=>_?ie.chown(u,x,m,S=>c(S&&_)):c())}c()});let l=this.transform&&this.transform(t)||t;l!==t&&(l.on("error",u=>{this[qe](u,t),e()}),t.pipe(l)),l.pipe(i)}[kc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.dmode;this[yn](String(t.absolute),n,i=>{if(i){this[qe](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[_r](),t.resume())};t.mtime&&!this.noMtime&&(o++,ie.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[Ti](t)&&(o++,ie.chown(String(t.absolute),Number(this[ki](t)),Number(this[Ri](t)),c)),c()})}[$u](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Wu](t,e){let n=Q(Le.relative(this.cwd,Le.resolve(Le.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[vi](t,this.cwd,n,()=>this[Js](t,String(t.linkpath),"symlink",e),i=>{this[qe](i,t),e()})}[Ku](t,e){let n=Q(Le.resolve(this.cwd,String(t.linkpath))),i=Q(String(t.linkpath)).split("/");this[vi](t,this.cwd,i,()=>this[Js](t,n,"link",e),o=>{this[qe](o,t),e()})}[vi](t,e,n,i,o){let c=n.shift();if(this.preservePaths||c===void 0)return i();let l=Le.resolve(e,c);ie.lstat(l,(u,h)=>{if(u)return i();if(h?.isSymbolicLink())return o(new ao(l,Le.resolve(l,n.join("/"))));this[vi](t,l,n,i,o)})}[Ju](){this[Fs]++}[_r](){this[Fs]--,this[cc]()}[Rc](t){this[_r](),t.resume()}[Ac](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Pi}[Ic](t){this[Ju]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,n=>this[ju](t,n))}[ju](t,e){let n=l=>{e(l)},i=()=>{this[yn](this.cwd,this.dmode,l=>{if(l){this[qe](l,t),n();return}this[Ci]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let l=Q(Le.dirname(String(t.absolute)));if(l!==this.cwd)return this[yn](l,this.dmode,u=>{if(u){this[qe](u,t),n();return}c()})}c()},c=()=>{ie.lstat(String(t.absolute),(l,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Rc](t),n();return}if(l||this[Ac](t,u))return this[ut](null,t,n);if(u.isDirectory()){if(t.type==="Directory"){let h=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,x=m=>this[ut](m??null,t,n);return h?ie.chmod(String(t.absolute),Number(t.mode),x):x()}if(t.absolute!==this.cwd)return ie.rmdir(String(t.absolute),h=>this[ut](h??null,t,n))}if(t.absolute===this.cwd)return this[ut](null,t,n);T_(String(t.absolute),h=>this[ut](h??null,t,n))})};this[Ci]?o():i()}[ut](t,e,n){if(t){this[qe](t,e),n();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[Tc](e,n);case"Link":return this[Ku](e,n);case"SymbolicLink":return this[Wu](e,n);case"Directory":case"GNUDumpDir":return this[kc](e,n)}}[Js](t,e,n,i){ie[n](e,String(t.absolute),o=>{o?this[qe](o,t):(this[_r](),t.resume()),i()})}},bi=t=>{try{return[null,t()]}catch(e){return[e,null]}},Cf=class extends zc{sync=!0;[ut](t,e){return super[ut](t,e,()=>{})}[Ic](t){if(!this[Ci]){let o=this[yn](this.cwd,this.dmode);if(o)return this[qe](o,t);this[Ci]=!0}if(t.absolute!==this.cwd){let o=Q(Le.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[yn](o,this.dmode);if(c)return this[qe](c,t)}}let[e,n]=bi(()=>ie.lstatSync(String(t.absolute)));if(n&&(this.keep||this.newer&&n.mtime>(t.mtime??n.mtime)))return this[Rc](t);if(e||this[Ac](t,n))return this[ut](null,t);if(n.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(n.mode&4095)!==t.mode,[l]=c?bi(()=>{ie.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ut](l,t)}let[o]=bi(()=>ie.rmdirSync(String(t.absolute)));this[ut](o,t)}let[i]=t.absolute===this.cwd?[]:bi(()=>k_(String(t.absolute)));this[ut](i,t)}[Tc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.fmode,i=l=>{let u;try{ie.closeSync(o)}catch(h){u=h}(l||u)&&this[qe](l||u,t),e()},o;try{o=ie.openSync(String(t.absolute),Sf(t.size),n)}catch(l){return i(l)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",l=>this[qe](l,t)),t.pipe(c)),c.on("data",l=>{try{ie.writeSync(o,l,0,l.length)}catch(u){i(u)}}),c.on("end",()=>{let l=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,h=t.mtime;try{ie.futimesSync(o,u,h)}catch(x){try{ie.utimesSync(String(t.absolute),u,h)}catch{l=x}}}if(this[Ti](t)){let u=this[ki](t),h=this[Ri](t);try{ie.fchownSync(o,Number(u),Number(h))}catch(x){try{ie.chownSync(String(t.absolute),Number(u),Number(h))}catch{l=l||x}}}i(l)})}[kc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[yn](String(t.absolute),n);if(i){this[qe](i,t),e();return}if(t.mtime&&!this.noMtime)try{ie.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[Ti](t))try{ie.chownSync(String(t.absolute),Number(this[ki](t)),Number(this[Ri](t)))}catch{}e(),t.resume()}[yn](t,e){try{return w_(Q(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(n){return n}}[vi](t,e,n,i,o){if(this.preservePaths||n.length===0)return i();let c=e;for(let l of n){c=Le.resolve(c,l);let[u,h]=bi(()=>ie.lstatSync(c));if(u)return i();if(h.isSymbolicLink())return o(new ao(c,Le.resolve(e,n.join("/"))))}i()}[Js](t,e,n,i){let o=`${n}Sync`;try{ie[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[qe](c,t)}}},R_=t=>{let e=new Cf(t),n=t.file,i=gf.statSync(n),o=t.maxReadSize||16*1024*1024;new Vm(n,{readSize:o,size:i.size}).pipe(e)},C_=(t,e)=>{let n=new zc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{n.on("error",l),n.on("close",c),gf.stat(o,(u,h)=>{if(u)l(u);else{let x=new Pc(o,{readSize:i,size:h.size});x.on("error",l),x.pipe(n)}})})},Pf=Oi(R_,C_,t=>new Cf(t),t=>new zc(t),(t,e)=>{e?.length&&lf(t,e)}),P_=(t,e)=>{let n=new Fc(t),i=!0,o,c;try{try{o=st.openSync(t.file,"r+")}catch(h){if(h?.code==="ENOENT")o=st.openSync(t.file,"w+");else throw h}let l=st.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<l.size;c+=512){for(let m=0,_=0;m<512;m+=_){if(_=st.readSync(o,u,m,u.length-m,c+m),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!_)break e}let h=new Wn(u);if(!h.cksumValid)break;let x=512*Math.ceil((h.size||0)/512);if(c+x+512>l.size)break;c+=x,t.mtimeCache&&h.mtime&&t.mtimeCache.set(String(h.path),h.mtime)}i=!1,D_(t,n,c,o,e)}finally{if(i)try{st.closeSync(o)}catch{}}},D_=(t,e,n,i,o)=>{let c=new Qu(t.file,{fd:i,start:n});e.pipe(c),N_(e,o)},O_=(t,e)=>{e=Array.from(e);let n=new so(t),i=(o,c,l)=>{let u=(S,y)=>{S?st.close(o,v=>l(S)):l(null,y)},h=0;if(c===0)return u(null,0);let x=0,m=Buffer.alloc(512),_=(S,y)=>{if(S||y===void 0)return u(S);if(x+=y,x<512&&y)return st.read(o,m,x,m.length-x,h+x,_);if(h===0&&m[0]===31&&m[1]===139)return u(new Error("cannot append to compressed archives"));if(x<512)return u(null,h);let v=new Wn(m);if(!v.cksumValid)return u(null,h);let I=512*Math.ceil((v.size??0)/512);if(h+I+512>c||(h+=I+512,h>=c))return u(null,h);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),x=0,st.read(o,m,0,512,h,_)};st.read(o,m,0,512,h,_)};return new Promise((o,c)=>{n.on("error",c);let l="r+",u=(h,x)=>{if(h&&h.code==="ENOENT"&&l==="r+")return l="w+",st.open(t.file,l,u);if(h||!x)return c(h);st.fstat(x,(m,_)=>{if(m)return st.close(x,()=>c(m));i(x,_.size,(S,y)=>{if(S)return c(S);let v=new to(t.file,{fd:x,start:y});n.pipe(v),v.on("error",c),v.on("close",o),L_(n,e)})})};st.open(t.file,l,u)})},N_=(t,e)=>{e.forEach(n=>{n.charAt(0)==="@"?Tr({file:Df.resolve(t.cwd,n.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n)}),t.end()},L_=async(t,e)=>{for(let n of e)n.charAt(0)==="@"?await Tr({file:Df.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n);t.end()},Ei=Oi(P_,O_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!nw(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")}),ZI=Oi(Ei.syncFile,Ei.asyncFile,Ei.syncNoFile,Ei.asyncNoFile,(t,e=[])=>{Ei.validate?.(t,e),M_(t)}),M_=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(n,i)=>e(n,i)&&!((t.mtimeCache?.get(n)??i.mtime??0)>(i.mtime??0)):(n,i)=>!((t.mtimeCache?.get(n)??i.mtime??0)>(i.mtime??0))};ln();var ft={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",PUBLISH_SKILL:"_agent/publishSkill"};function co(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function Of(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function lo(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Nf(t){let e=t?.permissionMode;if(typeof e!="string")return;let n=e.trim();return n===""?void 0:n}function Lf(t){let{_meta:e,...n}=t;return{stripped:n,meta:e}}function $n(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}$t();Ke();ne();Oe();Ke();function kr(t,e){if(co(t)!=="cloud")throw new T("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Ni(t){return t.startsWith("http://")||t.startsWith("https://")}function Rr(t){return t.endsWith("/")?t.slice(0,-1):t}import{readFileSync as GA}from"node:fs";import{dirname as HA,join as jA}from"node:path";import{fileURLToPath as KA}from"node:url";var Pt="0.2.2";Ke();ne();var uo="1008033",zf="1289";var Uf="pbbp2",Gf="https://www.coze.cn",qf="/api/coze_claw/resource/get_frontier_key",j_="https://www.coze.cn",W_="wss://frontier.coze.cn";function Cr(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??j_}function Hf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??W_}function vn(t){let e={},n=t?.ttEnv??process.env.COZE_BRIDGE_TT_ENV,i=t?.usePpe??process.env.COZE_BRIDGE_USE_PPE;return n&&(e["x-tt-env"]=n),i&&(e["x-use-ppe"]=i),e}function Mi(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Li=G("handshake");async function Uc(t){let e=Cr(t.endpoint),n=t.timeoutMs??1e4,i=`${Rr(e)}${qf}?aid=${encodeURIComponent(uo)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...vn(t.ppeOverride)},c=new AbortController,l=setTimeout(()=>c.abort(),n);Li.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),h=u.headers.get("x-tt-logid")??"",x=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let v=await u.text().catch(()=>"");throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${h}: ${v.slice(0,200)}`)}let m=await u.json();if(m.code!==void 0&&m.code!==0)throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${m.code} msg=${m.msg??"-"} logid=${h}`);let _=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 T("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${h}: ${v}`)}return Li.info("handshake ok",{remoteDeviceId:y,logid:h,traceId:x}),{accessKey:S,deviceId:y}}catch(u){if(u instanceof T)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:n}),new T("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${n}ms)`,{cause:u});let h=u.cause;throw Li.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:h?.code,syscall:h?.syscall,cause:String(u).slice(0,300)}),new T("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(l)}}var qc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",Dt="auto",Gc=15e4;function Wf(t){return{model:Hc(t.model)??Dt,...t.modelToken?{modelToken:t.modelToken}:{}}}function Kf(t){return!t||t===Dt}var K_=new Set(["auto","\u81EA\u52A8"]);function Hc(t){let e=t?.trim();if(e)return K_.has(e.toLowerCase())?Dt:e}function $f(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=qc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let n=t.model||Dt;e.ANTHROPIC_MODEL=n,e.ANTHROPIC_SMALL_FAST_MODEL=n,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=n,e.ANTHROPIC_DEFAULT_OPUS_MODEL=n,e.ANTHROPIC_DEFAULT_SONNET_MODEL=n,e.CLAUDE_CODE_SUBAGENT_MODEL=n,e.CLAUDE_CODE_ATTRIBUTION_HEADER="0",t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else Kf(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Vf(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||Dt}"`):Kf(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="${qc}/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 n=t.modelInfo?.contextWindow??Gc;e.push("-c",`model_context_window=${n}`)}return e}function Jf(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function jc(t,e){let{ttEnv:n,usePpe:i}=Mi(t),o={};return n&&(o["x-tt-env"]=n),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Zf(t,e,n){if(!t.modelToken)return{};let i=jc(e,n);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,l])=>`${c}:${l}`).join(`
92
+ `)}}function Wc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function Kc(t){return t.model||Dt}function jf(t,e,n){return{id:t,name:t,reasoning:!1,input:e,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:n,maxTokens:8192,api:"openai-completions"}}function Yf(t,e,n,i){if(!t.modelToken)return null;let o=Kc(t),c=jc(e,n),l=["text"];t.modelInfo?.capabilities?.image===!0&&l.push("image");let u=[jf(o,l,t.modelInfo?.contextWindow??Gc)],h=new Set([o]);for(let m of i??[])!m||h.has(m)||(h.add(m),u.push(jf(m,["text"],Gc)));let x={baseUrl:`${qc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:u};return Object.keys(c).length>0&&(x.headers=c),x}function Xf(t,e,n){if(!t.modelToken)return[];let i=jc(e,n),o=[];for(let[c,l]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${l}"`);return o}var he=G("agent-handlers"),Qf=5*1024*1024,Y_=1,X_=6,Q_=new Set(["node_modules",".git",".coze","dist","build",".next"]),ey=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,ty=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,ny=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function ry(t){let e=t?.trim();return e?ny.test(e)||ty.test(e)?e:(he.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function iy(t){return new Promise((e,n)=>{let i=rt("npx",t,{detached:!0,stdio:"ignore",windowsHide:!0}),o=!1,c=l=>{o||(o=!0,l?n(l):e(i.pid??0))};i.once("spawn",()=>{i.unref(),c()}),i.once("error",l=>c(l))})}var ho=class{constructor(e){this.opts=e}opts;async listSkills(e){e._meta;let n=$n(e._meta),i=await this.loadAgentCfg(n),o=i?.workspace??Je(n).workspace,c=i?.skills??[],l=[],u=new Set;for(let h of c){let x=me(o,h.relPath,"SKILL.md");await n0(x).then(_=>_.isFile()).catch(()=>!1)&&(l.push(dy(h)),u.add(h.relPath))}if(e.scanLocal){let h=i?.framework??"claude-code",x=await oy(n,o,h),m=await ay(n,h);for(let _ of[...x,...m])u.has(_.relPath)||(u.add(_.relPath),l.push(_.skill))}return{skills:l}}async addSkills(e){e._meta;let n=$n(e._meta),i=await this.requireAgentCfg(n),o=e.skills??[],c=[...i.skills??[]],l=new Map(c.map((h,x)=>[h.skillId,x])),u=[];for(let h of o){let x=await xo({agentId:n,workspace:i.workspace,framework:i.framework,skill:h});po(c,l,x),u.push(h)}return await ai(n,c),this.reloadAgentSessions(n,"skills-added"),{installedSkills:u}}async removeSkills(e){e._meta;let n=$n(e._meta),i=await this.requireAgentCfg(n),o=new Set(e.skillIds??[]),c=i.skills??[],l=[];for(let u of c){if(!o.has(u.skillId)){l.push(u);continue}let h=me(i.workspace,u.relPath);await Jc(h,{recursive:!0,force:!0}),he.info("skill removed",{agentId:n,skillId:u.skillId,relPath:u.relPath})}return await ai(n,l),this.reloadAgentSessions(n,"skills-removed"),{ok:!0}}async publishSkill(e){e._meta;let n=$n(e._meta);if(!e.skillName)throw new T("IPC_BAD_REQUEST","_agent/publishSkill: missing skillName");he.info("_agent/publishSkill start",{agentId:n,skillId:e.skillId??"",skillName:e.skillName,userId:e.userId??"",accountId:e.accountId??""});let i=await this.loadAgentCfg(n),o=i?.workspace??Je(n).workspace,c=i?.framework??"claude-code",l=e.isGlobal??!1,u=o0(e.skillName),h=await sy(o,c,u,l);if(!h){let P=l?"global":"workspace";throw new T("SKILL_NOT_FOUND",`skill not found in ${P}: ${e.skillName} (${u})`)}let{absDir:x,relPath:m}=h,_=me(x,"SKILL.md"),S=new el.default;S.addLocalFolder(x,u);let y=S.toBuffer();if(y.length>e0)throw new T("SKILL_ZIP_TOO_LARGE",`skill zip ${y.length} bytes exceeds limit ${e0}`);let v=await fo(_,{encoding:"utf8"}).then(P=>l0(P).description).catch(()=>{}),I={};this.opts.publishSkillToMarketplace?I=await this.opts.publishSkillToMarketplace({zip:y,...e.skillId?{skillId:e.skillId}:{},skillName:e.skillName,...v?{description:v}:{},agentId:n,...e.userId?{userId:e.userId}:{},...e.accountId?{accountId:e.accountId}:{}}):he.warn("_agent/publishSkill: publishSkillToMarketplace not injected, skip upload",{agentId:n,skillName:e.skillName});let A=I.version??"v1.0",k=I.skillId??e.skillId??c0(n,m);if(i&&!l){let P=i.skills??[],b=P.find(R=>R.relPath===m);b?(b.version=A,b.skillId=k):P.push({skillId:k,skillName:e.skillName,relPath:m,version:A,installedAt:Date.now(),...v?{description:v}:{}}),await ai(n,P)}return he.info("skill published",{agentId:n,skillName:e.skillName,relPath:m,zipBytes:y.length,skillId:k,version:A}),{ok:!0,skillId:k,version:A}}reloadAgentSessionsPublic(e,n){this.reloadAgentSessions(e,n)}reloadAgentSessions(e,n){let i=this.opts.agents.get(e);if(i)for(let[o,c]of i.sessions){if(!c.downstream)continue;let l=c.acpSessionId;if(l&&i.activeTriggers.has(l)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,he.info("downstream busy, scheduling reload after turn",{reason:n,agentId:e,framework:i.framework,cloudId:o,acpId:l});continue}let h=c.downstream;c.downstream=void 0,he.info("killing downstream for workspace reload (idle)",{reason:n,agentId:e,framework:i.framework,cloudId:o,acpId:l}),h.stop(n).catch(x=>he.warn("downstream stop failed during reload (ignored)",{reason:n,agentId:e,cloudId:o,err:String(x)}))}}isRuntimePendingPermission(e){let n=this.opts.isRuntimePendingPermission;return!n||!e.downstream?!1:n(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return he.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let n=e.agentId,i=await ke(n);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${n}`);if(i.cozeIdentity===e.cozeIdentity)return he.info("_agent/update: cozeIdentity unchanged, noop",{agentId:n}),{ok:!0};try{await ur(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw he.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:n,framework:i.framework,workspace:i.workspace,err:String(o)}),new T("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${n}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Fe(i),he.info("_agent/update: cozeIdentity rewritten",{agentId:n,framework:i.framework}),this.reloadAgentSessions(n,"identity-changed"),{ok:!0}}async upgradeBridge(e){let n=e.agentId||e._meta?.cozeAgentId;if(!n)throw new T("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await ke(n))throw new T("AGENT_NOT_FOUND",`agent not found: ${n}`);let o=["-y"];e.registry&&Ni(e.registry)&&o.push(`--registry=${e.registry}`);let c=ry(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let l=e._meta?.cozeEnv;l&&ey.test(l)&&o.push("--env",l);let u=await iy(o);return he.info("_agent/upgrade: spawned bridge upgrade process",{agentId:n,pid:u,targetVersion:c,currentVersion:e.currentVersion??"",reason:e.reason??""}),{ok:!0,accepted:!0,pid:u,message:"bridge upgrade started"}}async disconnectAgent(e){let n=e.agentId;if(!n)throw new T("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await ke(n);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Fe(i),he.info("agent disconnected",{agentId:n,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(n,e.reason??"disconnect"),{ok:!0}):(he.warn("_agent/disconnect: agent not found, ignoring",{agentId:n}),{ok:!0})}async deleteAgent(e){let n=e.agentId;if(!n)throw new T("IPC_BAD_REQUEST",`${ft.DELETE}: missing agentId`);let i=await ke(n),o=e._meta?.cozeDeployType==="cloud"||e._meta?.cozeDeployType==="local"?e._meta.cozeDeployType:void 0,c=e.deployType??o??i?.deployType??"local";this.opts.disposeForDelete&&await this.opts.disposeForDelete(n,e.reason??"delete");let l=Je(n);return c==="cloud"?await Jc(l.root,{recursive:!0,force:!0}):i&&(i.deletedAt=Date.now(),i.deleteReason=e.reason??"deleted",await Fe(i)),he.info("agent deleted",{agentId:n,reason:e.reason??"",deployType:c,configFound:!!i}),{ok:!0}}async switchModel(e){if(kr(e._meta,"_agent/switchModel"),!e.agentId)throw new T("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let n=Hc(e.model)??Dt,i=await ke(e.agentId);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=n,e.modelInfo&&(i.modelInfo=e.modelInfo),await Fe(i),he.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:n,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return he.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};let c=o.model;o.model=n,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o,c).catch(u=>he.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(u)}));let l=[];for(let[u,h]of o.allSessionQueues())l.push(h.enqueue(async()=>{let x=o.sessions.get(u);x?.downstream&&(await x.downstream.stop(`switchModel: ${n}`).catch(()=>{}),x.downstream=void 0)}));return await Promise.all(l),he.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:n,cloudSessions:l.length}),{ok:!0}}async resetAgent(e){if(kr(e._meta,ft.RESET),!e.agentId)throw new T("IPC_BAD_REQUEST",`${ft.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,ft.RESET),await this.runDetailSync(e.agentId,ft.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,n){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),he.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(n);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,l]of i.sessions)o.set(c,{modelToken:l.modelToken,tokenGeneratedAt:l.tokenGeneratedAt});await oi(e,o)}async clearPersistedAcpSessionIds(e){let n=await ke(e).catch(()=>null);if(!n?.sessions)return;let i=!1;for(let o of Object.values(n.sessions))o.acpSessionId&&(o.acpSessionId=void 0,i=!0);i&&await Fe(n)}async repairAgent(e){if(kr(e._meta,ft.REPAIR),!e.agentId)throw new T("IPC_BAD_REQUEST",`${ft.REPAIR}: missing agentId`);let n=await this.loadAgentCfg(e.agentId);if(n&&n.framework!=="openclaw")throw new T("IPC_BAD_REQUEST",`${ft.REPAIR} only allowed for openclaw, got ${n.framework}`);if(n&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,n.workspace)}catch(i){he.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,ft.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,n,i){if(!this.opts.detailSyncer){he.warn("detailSyncer not wired, skipping sync",{method:n,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){he.warn("detail sync failed (ignored)",{method:n,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){kr(e._meta,"_agent/getFileTree");let n=e._meta,i=$n(n),o=await this.resolveWorkspace(i),c=e.filePath??"",l=this.safeJoin(o,c),u=await $c(l).catch(()=>null);if(!u)throw new T("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await si(l,o))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let h=Ey(e.depth);return u.isDirectory()?{tree:await by(o,l,c,h)}:{tree:[{name:vy(c),path:h0(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){kr(e._meta,"_agent/getFileContent");let n=$n(e._meta),i=await this.resolveWorkspace(n);if(!e.filePath)throw new T("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await $c(o).catch(()=>null);if(!c||!c.isFile())throw new T("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await si(o,i))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Qf)throw new T("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Qf})`);let l=await fo(o);return l.includes(0)?{content:l.toString("base64"),encoding:"base64",size:c.size}:{content:l.toString("utf8"),encoding:"utf-8",size:c.size}}async resolveWorkspace(e){let n=this.opts.agents.get(e);return n?n.workspace:(await ke(e).catch(()=>null))?.workspace??Je(e).workspace}safeJoin(e,n){let i=Yc(e,n||"."),o=Qc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${r0}`))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${n}`);return i}loadAgentCfg(e){return ke(e)}async requireAgentCfg(e){let n=await this.loadAgentCfg(e);if(!n)throw new T("AGENT_NOT_FOUND",`no config for agent: ${e}`);return n}};function o0(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new T("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new T("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function tl(t){return t==="claude-code"?me(".claude","skills"):me(".agents","skills")}function a0(t){let e=V_();return t==="claude-code"?[me(e,".claude","skills")]:t==="codex"?[me(e,".agents","skills"),me(e,".codex","skills")]:[me(e,".agents","skills"),me(e,".openclaw","skills")]}async function sy(t,e,n,i){let o=async c=>n0(me(c,"SKILL.md")).then(l=>l.isFile()).catch(()=>!1);if(!i){let c=me(tl(e),n),l=me(t,c);return await o(l)?{absDir:l,relPath:c}:null}for(let c of a0(e)){let l=me(c,n);if(await o(l))return{absDir:l,relPath:l}}return null}function c0(t,e){return($_("sha256").update(`${t}\0${e}`).digest().readBigUInt64BE(0)&0x7fffffffffffffffn).toString()}function l0(t){if(!t.startsWith("---"))return{};let e=t.indexOf(`
93
+ ---`,3);if(e<0)return{};let n=t.slice(3,e),i={};for(let o of n.split(`
94
+ `)){let c=/^\s*(name|description)\s*:\s*(.+?)\s*$/.exec(o);if(!c||!c[2])continue;let l=c[1],u=c[2].trim();(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))&&(u=u.slice(1,-1)),u&&(i[l]=u)}return i}async function d0(t,e,n,i){let o=await t0(e,{withFileTypes:!0}).catch(()=>null);if(!o)return[];let c=[];for(let l of o){if(!l.isDirectory())continue;let u=l.name,h=me(n,u),x=me(e,u,"SKILL.md"),m=await fo(x,{encoding:"utf8"}).catch(()=>null);if(m===null)continue;let _=l0(m);c.push({relPath:h,skill:{skillId:c0(t,h),skillName:_.name||u,..._.description?{description:_.description}:{},...i?{isGlobal:!0}:{}}})}return c}async function oy(t,e,n){let i=tl(n);return d0(t,me(e,i),i,!1)}async function ay(t,e){let n=[],i=new Set;for(let o of a0(e)){let c=await d0(t,o,o,!0);for(let l of c)i.has(l.relPath)||(i.add(l.relPath),n.push(l))}return n}var cy=3e4,ly=50*1024*1024,e0=10*1024*1024,Pr=3e4;async function xo(t){let{agentId:e,workspace:n,framework:i,skill:o}=t;if(!o.skillName)throw new T("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,l=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!l)throw new T("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=o0(o.skillName),h=tl(i),x=me(h,u),m=me(n,x);if(await Vc(m,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");Bi(S.length),await Zc(me(m,"SKILL.md"),S,"utf8")}else{let S=await fy(o.downloadUrl);xy(S)?await wy(S,m):py(S)?await gy(S,m):await Zc(me(m,"SKILL.md"),S.toString("utf8"),"utf8")}let _={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 he.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:x,source:c?"content":"downloadUrl"}),_}function po(t,e,n){let i=e.get(n.skillId);if(i!==void 0){t[i]=n;return}e.set(n.skillId,t.length),t.push(n)}function dy(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 uy(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 u0(t,e){let n=await ke(t,e);if(!n)return{status:"skipped",count:0};if(n.disconnectedAt)return{status:"skipped",count:0};let i=Pt,o=n.skillsRefreshedForVersion;if(o===i)return{status:"noop",count:0};if(!o)return n.skillsRefreshedForVersion=i,await Fe(n,e),{status:"seeded",count:0};let c=[...n.skills??[]],l=new Map(c.map((m,_)=>[m.skillId,_])),u=c.filter(m=>m.builtin===!0&&!!m.downloadUrl);if(u.length===0)return n.skillsRefreshedForVersion=i,await Fe(n,e),{status:"noop",count:0};let h=0,x=0;for(let m of u)try{await Jc(me(n.workspace,m.relPath),{recursive:!0,force:!0});let _=await xo({agentId:t,workspace:n.workspace,framework:n.framework,skill:uy(m)});po(c,l,_),h+=1}catch(_){x+=1,he.warn("refresh builtin skill failed (skipping)",{agentId:t,skillId:m.skillId,skillName:m.skillName,err:String(_)})}return n.skills=c,x===0&&(n.skillsRefreshedForVersion=i),await Fe(n,e),he.info("builtin skills refreshed after bridge upgrade",{agentId:t,from:o,to:i,ok:h,failed:x}),{status:"refreshed",count:h}}async function fy(t){if(!t)throw new T("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Bi(e);let n=hy(t);return Bi(n.length),n}if(t.startsWith("file:")){let e=new URL(t).pathname,n=await fo(e);return Bi(n.length),n}if(Ni(t)){let e=new AbortController,n=setTimeout(()=>e.abort(),cy);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new T("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Bi(o.byteLength),Buffer.from(o)}finally{clearTimeout(n)}}throw new T("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Bi(t){if(t>ly)throw new T("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function hy(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new T("IPC_BAD_REQUEST","bad data URL");let n=!!e[2],i=e[3]??"";return n?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function xy(t){return t.length>=2&&t[0]===31&&t[1]===139}function py(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],n=t[3];return e===3&&n===4||e===5&&n===6}function Xc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function gy(t,e){let n,i;try{n=new el.default(t),i=n.getEntries()}catch(l){throw new T("IPC_BAD_REQUEST",`zip parse failed: ${l.message}`,{cause:l})}for(let l of i){let u=l.entryName;if(!u||Xc(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new T("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(x=>x===".."))throw new T("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let h=l.header.attr>>>16&61440;if(h!==0&&h!==32768&&h!==16384)throw new T("IPC_BAD_REQUEST",`zip entry kind 0x${h.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=my(i),c=Yc(e);for(let l of i){if(Xc(l.entryName))continue;let u=l.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let h=Yc(e,u),x=Qc(c,h);if(x.startsWith("..")||x==="..")throw new T("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(l.isDirectory){await Vc(h,{recursive:!0});continue}await Vc(J_(h),{recursive:!0});let m;try{m=l.getData()}catch(_){throw new T("IPC_BAD_REQUEST",`zip entry getData failed (${l.entryName}): ${_.message}`,{cause:_})}await Zc(h,m)}}function my(t){let e;for(let n of t){let i=n.entryName;if(!i||Xc(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 wy(t,e){await _y(t);let n=Pf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,n.destroy(new T("IPC_BAD_REQUEST",`tar extract timeout (${Pr}ms)`))},Pr);try{await s0(i0.from(t),n)}catch(c){throw c instanceof T?c:i?new T("IPC_BAD_REQUEST",`tar extract timeout (${Pr}ms)`):new T("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function _y(t){let e=[],n=Tr({onReadEntry:c=>{let l=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' not allowed (symlink/hardlink/special): ${l.slice(0,100)}`);return}if(l.startsWith("/")||l.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(l)){e.push(`tar entry absolute path: ${l}`);return}l.split(/[/\\]/).some(x=>x==="..")&&e.push(`tar entry contains '..': ${l}`)}}),i=!1,o=setTimeout(()=>{i=!0,n.destroy(new T("IPC_BAD_REQUEST",`tar list timeout (${Pr}ms)`))},Pr);try{await s0(i0.from(t),n)}catch(c){throw i?new T("IPC_BAD_REQUEST",`tar list timeout (${Pr}ms)`):new T("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new T("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var yy=5e3;async function by(t,e,n,i){return f0(t,e,n,i,{count:0})}async function f0(t,e,n,i,o){if(i<=0)return[];let c;try{c=await t0(e,{withFileTypes:!0})}catch{return[]}let l=[];for(let u of c){if(Q_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=yy){l.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let h=me(e,u.name),x=Z_(me(n,u.name)),m=null;try{m=await $c(h)}catch{continue}if(m.isSymbolicLink())continue;o.count++;let _={name:u.name,path:h0(Qc(t,h)),isDir:m.isDirectory(),size:m.size,modifiedAt:Math.floor(m.mtimeMs)};m.isDirectory()&&i>1&&(_.children=await f0(t,h,x,i-1,o)),l.push(_)}return l.sort((u,h)=>u.isDir!==h.isDir?u.isDir?-1:1:u.name.localeCompare(h.name)),l}function Ey(t){return!t||t<=0?Y_:Math.min(t,X_)}function vy(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function h0(t){return t.split(r0).join("/")}ne();var Sn=G("agent-health-reporter"),Sy=1e4,Iy=3,Fi=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??Sy,this.livenessFailureThreshold=e.livenessFailureThreshold??Iy}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()}),Sn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),Sn.info("heartbeat stopped"))}async tick(){if(this.inFlight){Sn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){this.consecutiveFailures=0,Sn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let n=[];for(let l of this.opts.core.agents.values()){let u=Ay(l);if(!u)continue;let h={agentId:l.agentId,status:u};l.patToken&&(h.patToken=l.patToken),l.accountId&&(h.accountId=l.accountId),n.push(h)}if(n.length===0){this.consecutiveFailures=0;return}let i={agents:n,bridgeVersion:Pt,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3),this.consecutiveFailures=0}catch(l){this.consecutiveFailures+=1,Sn.warn("heartbeat batch send failed",{count:n.length,consecutiveFailures:this.consecutiveFailures,err:String(l)})}let c=o?.authFailures;if(c&&c.length>0&&(Sn.warn("heartbeat received authFailures from cloud",{count:c.length,agentIds:c.map(l=>l.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(c)}catch(l){Sn.warn("onAuthFailures callback failed (ignored)",{err:String(l)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(n){Sn.warn("onTickEnd hook failed",{err:String(n)})}}};function Ay(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}ln();import{mkdir as al,rm as mb,stat as wb}from"node:fs/promises";import{homedir as _b}from"node:os";import{join as q0}from"node:path";on();import{existsSync as zy}from"node:fs";import{release as Uy}from"node:os";import{basename as Gy,isAbsolute as qy}from"node:path";function zi(t,e,n){return n===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:n}}function Dr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Or(t,e){return{jsonrpc:"2.0",id:t,result:e}}function In(t,e){return{jsonrpc:"2.0",id:t,error:e}}Ke();var go=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)}},Y={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,SKILL_NOT_FOUND:-32022,SKILL_ZIP_TOO_LARGE:-32023,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32024};function x0(t){return"method"in t&&"id"in t&&t.id!==void 0}function p0(t){return"method"in t&&!("id"in t)}function mo(t){return!("method"in t)&&"id"in t}var Ty={AGENT_NOT_FOUND:Y.AGENT_NOT_FOUND,AGENT_BUSY:Y.AGENT_BUSY,AGENT_DISCONNECTED:Y.AGENT_DISCONNECTED,AGENT_TIMEOUT:Y.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:Y.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:Y.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:Y.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:Y.INTERNAL_ERROR,BRIDGE_INTERNAL:Y.INTERNAL_ERROR,IPC_AUTH_FAILED:Y.INTERNAL_ERROR,IPC_BAD_REQUEST:Y.INVALID_REQUEST,METHOD_NOT_FOUND:Y.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:Y.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:Y.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:Y.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:Y.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:Y.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:Y.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:Y.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:Y.FILE_TOO_LARGE,UNSUPPORTED_MIME:Y.UNSUPPORTED_MIME,UPLOAD_FAILED:Y.UPLOAD_FAILED,UPSTREAM_NOT_READY:Y.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:Y.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:Y.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:Y.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:Y.AGENT_ENV_NOT_READY,SKILL_NOT_FOUND:Y.SKILL_NOT_FOUND,SKILL_ZIP_TOO_LARGE:Y.SKILL_ZIP_TOO_LARGE};function ky(t){if(t!=null)return t instanceof Error?{name:t.name,message:Ui(t.message)}:typeof t=="string"?Ui(t):typeof t=="object"?Cy(t):t}var Ry=[[/\/Users\/[^/\s'"`)]+/g,"/Users/<redacted>"],[/\/home\/[^/\s'"`)]+/g,"/home/<redacted>"],[/[A-Za-z]:\\Users\\[^\\\s'"`)]+/g,"C:\\Users\\<redacted>"],[/(Bearer|Token|Authorization:)\s+[\w._-]+/gi,"$1 <redacted>"],[/\b(sk|pat|ak)[-_][A-Za-z0-9_-]{20,}\b/g,"<redacted-key>"]];function Ui(t){let e=t;for(let[n,i]of Ry)e=e.replace(n,i);return e}function Cy(t){let e={};for(let[n,i]of Object.entries(t))typeof i=="string"?e[n]=Ui(i):e[n]=i;return e}function Gi(t){if(t instanceof T){let e=ky(t.cause),n={bridgeCode:t.code,retriable:t.retriable};return e!==void 0&&(n.cause=e),e&&typeof e=="object"&&"reason"in e&&typeof e.reason=="string"&&(n.reason=e.reason),{code:Ty[t.code]??Y.INTERNAL_ERROR,message:Ui(t.message),data:n}}return{code:Y.INTERNAL_ERROR,message:Ui(t instanceof Error?t.message:String(t))}}function g0(t){let e=t.data,n=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:l,...u}=e;c=u}return new T(n,o,{retriable:e?.retriable??!1,cause:c})}function w0(t){return`${JSON.stringify(t)}
95
+ `}var m0=10*1024*1024,wo=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>m0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${m0} bytes`)}),[]}let n=this.buffer.split(`
96
+ `);this.buffer=n.pop()??"";let i=[];for(let o of n){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(l){this.onError?.({line:c,error:l})}}return i}flush(){if(!this.buffer)return[];let e=this.buffer.replace(/\r$/,"").trim();if(this.buffer="",!e)return[];try{return[JSON.parse(e)]}catch(n){return this.onError?.({line:e,error:n}),[]}}};var y0={"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"},PT=Object.fromEntries(Object.entries(y0).map(([t,e])=>[e,t])),Py={"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,n){this.seq+=1;let i=y0[e]??Dy(e),o=Py[i]??[],c=[i,String(this.seq)];if(o.length>0){let l=o.map(h=>_0(n?.[h]??"")),u=Oy(l).join(":");u&&c.push(u)}else n&&Object.values(n).some(l=>l)&&c.push(Object.values(n).filter(Boolean).map(l=>_0(String(l))).join(":"));return c.join("_")}reset(){this.seq=0}};function Dy(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function _0(t){return t.replace(/[:_\s]+/g,"-")}function Oy(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}cn();import{readFileSync as Ny}from"node:fs";var Ly=384;async function nl(t,e=process.env){let n={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(n[i]=o);await dr(t.agentEnvFile,n,{mode:Ly})}function rl(t){try{let e=JSON.parse(Ny(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function b0(t,e,n={},i=o=>o){return{...i({...t,...rl(e)}),...n}}$t();sr();Ke();ne();Oe();import{execFileSync as My,spawnSync as By}from"node:child_process";function qi(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 n=["/PID",String(t),"/T"];e==="SIGKILL"&&n.push("/F"),By("taskkill",n,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var il=new Set;function E0(t){typeof t=="number"&&t>0&&il.add(t)}function v0(t){typeof t=="number"&&il.delete(t)}function S0(){for(let t of il)Hi(t,"SIGKILL")}var Lr="coze-bridge-daemon";function I0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return My("pgrep",["-U",String(o),"-f",Lr],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:2e3})}),n;try{n=e()}catch{return[]}let i=process.pid;return n.split(`
97
+ `).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function A0(t,e){if(t.length===0)return;let n=e?.killFn??Hi,i=e?.isAliveFn??qi,o=e?.sleepFn??(u=>new Promise(h=>setTimeout(h,u))),c=e?.graceMs??3e3,l=e?.pollMs??100;for(let u of t)n(u,"SIGTERM");for(let u=0;u<c&&t.some(h=>i(h));u+=l)await o(Math.min(l,c-u));for(let u of t)i(u)&&n(u,"SIGKILL")}var Fy=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: (Node binary not found|QCLAW_CLI_NODE_BINARY not set)/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/import\.meta\.resolve is not a function|\.resolve is not a function/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (codex ACP \u9700\u8981 import.meta.resolve)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20 \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/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 T0(t,e){if(!e)return null;for(let n of Fy)if(!(n.frameworks&&!n.frameworks.includes(t))&&n.match.test(e))return{bridgeCode:n.bridgeCode,reason:n.reason,message:n.message};return null}function k0(t,e){return T0(t,e)}function R0(t,e){return T0(t,e)}function Mr(t,e,n){return!e&&n.firstUpdateMs>0&&t<n.firstUpdateMs?Math.max(1,n.firstUpdateMs-t):t<n.phase2GateMs?Math.max(1,n.phase2GateMs-t):Math.max(1,n.livenessWindowMs)}function C0(t,e,n){let o=n-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let x=t.suspendedMs+o,m=n-t.startedAt-x;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Mr(m,t.firstFrameSeen,e)}}let c=n-t.startedAt-t.suspendedMs,l=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=l?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Mr(c,!0,e)}:n-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Mr(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Mr(c,!1,e)}}var P0=Ve("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),Hy=200,jy=40,Wy=Ve("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),Ky=Ve("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),$y=Ve("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),Vy=Ve("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),Jy=Ve("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Zy=Ve("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),D0=500;function Yy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=D0?t:`${e.slice(0,D0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Xy(t){let e=[];typeof t.message=="string"&&e.push(t.message);let{data:n}=t;if(typeof n=="string")e.push(n);else if(n&&typeof n=="object")try{e.push(JSON.stringify(n))}catch{}return e.join(" ")}function O0(t){try{return zy(t)}catch{return}}function Qy(t,e){return{platform:process.platform,osRelease:Uy(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:qy(e.command)?O0(e.command):void 0,cwd:e.cwd,cwdExists:O0(e.cwd),envKeys:e.envKeys}}function eb(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 Ot=class{constructor(e){this.opts=e;this.log=G(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new wo({onError:n=>this.log.warn("decode line failed",{line:n.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 T("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",n=b0(process.env,this.opts.agentEnvFile??ee().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=rt(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:n,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,E0(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>Hy&&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,v0(i.pid),(o!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:c,recentStderr:[...this.stderrRing]});try{for(let u of this.decoder.flush())this.dispatch(u)}catch(u){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(u)})}this.failAllPending(this.buildExitError(o,c));for(let u of this.exitHandlers)u(o,c)}),i.on("error",o=>{let c=o,l=Qy(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(n).length});this.log.error("child error",{err:String(o),diag:l}),this.failAllPending(new T("AGENT_SPAWN_FAILED",eb(c,l),{cause:l}))}),this.log.info("downstream started",{command:this.opts.command,pid:i.pid,cwd:this.opts.cwd})}async stop(e){if(!this.child||this.stopped)return;this.stopped=!0,this.stopReason=e??"stopped",this.log.info("downstream stopping",{reason:e});let n=this.child,i=new Promise(c=>n.once("exit",()=>c()));Hi(n.pid,"SIGTERM");let o=setTimeout(()=>{n.killed||Hi(n.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,n){let i={firstUpdateMs:Jy,phase2GateMs:Wy,livenessWindowMs:Ky,absoluteMaxMs:$y,approvalMaxMs:Zy,suspendThresholdMs:Vy,...n};return this.call("session/prompt",e,P0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Dr("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,n){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Or(e,n))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,n){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(In(e,n))}catch(i){this.log.warn("respondAgentRequestError write failed",{id:e,err:String(i)})}}onExit(e){this.exitHandlers.push(e)}call(e,n,i=P0,o){if(!this.child||this.stopped)return Promise.reject(new T("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),l=zi(c,e,n),u=(()=>{if(typeof n!="object"||n===null)return;let h=n.sessionId;return typeof h=="string"?h:void 0})();return new Promise((h,x)=>{let m={resolve:h,reject:x,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:Mr(0,!1,o),sessionId:u};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},I=this.now(),A=C0(v,S.cfg,I),k=P=>{S.armedAt=I,S.expectedIntervalMs=P,m.timer=setTimeout(y,P)};if(A.action==="suspend"){S.suspendedMs+=A.suspendedDeltaMs,S.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:A.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),k(A.rearmMs);return}if(A.action==="continue"){k(A.rearmMs);return}this.pending.delete(c),A.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:A.awaitingApproval,...S.sessionId?{sessionId:S.sessionId}:{}}),x(A.awaitingApproval?new T("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new T("AGENT_TIMEOUT",`${e} timed out after ${S.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...S.sessionId?{sessionId:S.sessionId}:{}}),x(new T("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}),x(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,m);try{this.writeFrame(l)}catch(_){m.timer&&clearTimeout(m.timer),this.pending.delete(c),x(_)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new T("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(w0(e),n=>{n&&this.log.warn("stdin write callback err",{err:String(n)})})}dispatch(e){if(mo(e)){let n=e.id!==null?this.pending.get(e.id):void 0;if(!n){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),n.timer&&clearTimeout(n.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:n.method,code:e.error.code,message:e.error.message,data:e.error.data}),n.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:n.method}),n.reject(new T("AGENT_PROTOCOL_ERROR",`${n.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:n.method,result:Yy(e.result)}),n.resolve(e.result));return}if(p0(e)){if(e.method==="session/update"){let n=e.params;for(let i of this.pending.values()){let o=i.promptTimeout;o&&(o.firstFrameSeen=!0,o.lastActivityAt=this.now(),this.trackToolCall(o,n))}for(let i of this.updateHandlers)try{Promise.resolve(i(n)).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(x0(e)){let n=e;try{this.handleAgentRequest(n).catch(i=>this.log.error("agent request handler failed (async)",{method:n.method,err:String(i)}))}catch(i){this.log.warn("handleAgentRequest threw sync, swallowed",{method:n.method,err:String(i)})}}}trackToolCall(e,n){let i=n.update,o=i?.sessionUpdate;if(o!=="tool_call"&&o!=="tool_call_update")return;let c=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!c)return;let l=typeof i.status=="string"?i.status:void 0,u=l==="completed"||l==="failed"||l==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(In(e.id,{code:-32601,message:`method not handled by Bridge: ${e.method}`}));return}this.inflightAgentRequests.set(e.id,e.method);for(let n of this.agentRequestHandlers)try{await n(e)}catch(i){this.log.error("agentRequestHandler threw",{method:e.method,err:String(i)});try{this.writeFrame(In(e.id,Gi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let n=g0(e);if(n.code!=="AGENT_PROTOCOL_ERROR")return n;let i=R0(this.framework,Xy(e));return i?new T(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):n}buildExitError(e,n){if(this.stopReason!==void 0)return new T("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(jy).join(`
98
+ `),o=k0(this.framework,i);return o?new T(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:n,stderrTail:i}}):new T("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${n})`,{cause:{code:e,signal:n,stderrTail:i}})}failAllPending(e){for(let n of this.pending.values())n.timer&&clearTimeout(n.timer),n.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function tb(t){let e={};for(let[n,i]of Object.entries(t))i!==void 0&&(n.startsWith("CLAUDE")||n==="AI_AGENT"||n==="BAGGAGE"||(e[n]=i));return e}var _o=class extends Ot{framework="claude-code";constructor(e){let{command:n,args:i}=ii("claude-code",e.command,e.args??[]),o={command:n,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o)}sanitizeEnv(e){return tb(e)}};on();import{mkdtempSync as nb,rmSync as rb}from"node:fs";import{tmpdir as ib}from"node:os";import{join as sb}from"node:path";var yo=class extends Ot{framework="codex";authMethodId;codexHomeDir;constructor(e){let n=e.args??[],i=e.extraArgs?[...n,...e.extraArgs]:n,{command:o,args:c}=ii("codex",e.command,i),l=e.isolateCodexHome?nb(sb(ib(),"coze-bridge-codex-home-")):void 0,u=l?{...e.env??{},CODEX_HOME:l}:e.env,h={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(h),this.authMethodId=e.authMethodId,this.codexHomeDir=l}async initialize(e){let n=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),n}async stop(e){if(await super.stop(e),this.codexHomeDir)try{rb(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};Ke();var ob=3e4,Br=class extends Ot{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let n=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${n}`];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=n,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}`}]},ob))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new T("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var N0=["default","acceptEdits","plan","auto","bypassPermissions"],L0=["read-only","auto","full-access"];function An(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return N0.includes(e);case"codex":return L0.includes(e);case"openclaw":return!1}}function sl(t){switch(t){case"claude-code":return N0.join("/");case"codex":return L0.join("/");case"openclaw":return""}}cn();Ke();ne();Oe();function ol(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}on();var Tn=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((n,i)=>{this.slots.push({task:e,resolve:n,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 n=await e.task();e.resolve(n)}catch(n){e.reject(n)}}}finally{this.running=!1}}}};var bo=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 n=this.sessionQueues.get(e);return(!n||n.isDisposed)&&(n=new Tn,this.sessionQueues.set(e,n)),n}allSessionQueues(){return this.sessionQueues.entries()}hasSessionQueue(e){let n=this.sessionQueues.get(e);return!!n&&!n.isDisposed}async dispose(e){this.status="stopped";let n=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let i of this.sessionQueues.values())i.dispose(n);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let n=[];for(let[,i]of this.sessions)ji(i),i.downstream&&(n.push(i.downstream.stop(e).catch(()=>{})),i.downstream=void 0);await Promise.all(n),this.activeTriggers.clear(),this.activeGroupIds.clear()}};function ji(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function Vt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}$t();ne();import{constants as M0}from"node:fs";import{access as ab}from"node:fs/promises";import{delimiter as cb,join as lb}from"node:path";var Et=G("framework-detector"),B0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},db=[".exe",".cmd",".bat",".ps1"],Vn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??rt,access:e.access??ab}}async detect(e){let n=B0[e],i=await this.which(n);if(!i)return Et.debug("framework binary not found",{framework:e,bin:n}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,l]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return l&&(u.defaultAgent=l),u}async detectAll(){let e=await Promise.all(Object.keys(B0).map(async i=>[i,await this.detect(i)])),n={};for(let[i,o]of e)o&&(n[i]=o);return n}async which(e){let n=this.env.pathEnv.split(cb).filter(Boolean),i=this.env.platform==="win32"?["",...db]:[""];for(let o of n)for(let c of i){let l=lb(o,e+c);if(await this.isExecutable(l))return l}return null}async isExecutable(e){try{let n=this.env.platform==="win32"?M0.F_OK:M0.X_OK;return await this.env.access(e,n),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let n=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!n)return Et.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(n.code!==0)return Et.warn("openclaw default agent probe: non-zero exit",{path:e,code:n.code,stdoutHead:n.stdout.slice(0,200)}),null;let i=n.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return Et.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:n.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return Et.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(l=>l?.isDefault===!0);return c?!c.id||!c.workspace?(Et.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(Et.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return Et.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let n=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!n)return Et.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=n.code===0;i||Et.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:n.code,stdoutHead:n.stdout.slice(0,200)});let o={reachable:i},c=n.stdout.match(/\{[\s\S]*\}/);if(c)try{let l=JSON.parse(c[0]);typeof l.gateway?.port=="number"&&(o.port=l.gateway.port),typeof l.service?.runtime?.status=="string"&&(o.runtime=l.service.runtime.status),!i&&typeof l.rpc?.error=="string"&&(o.detail=l.rpc.error)}catch(l){Et.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(l)})}return o}async probeVersion(e,n=[]){let i=await this.runProbe(e,[...n,"--version"]);return i&&(fb(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,n){return new Promise(i=>{let o="",c=!1,l,u=h=>{c||(c=!0,l&&clearTimeout(l),i(h))};try{let h=this.env.spawn(e,n,{stdio:["ignore","pipe","pipe"]});l=setTimeout(()=>{h.kill("SIGKILL"),u(null)},15e3),h.stdout?.on("data",x=>{o+=x.toString("utf8")}),h.on("error",()=>u(null)),h.on("close",x=>u({code:x,stdout:o}))}catch{u(null)}})}},ub=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function fb(t){return t.replace(ub,"")}import{homedir as hb}from"node:os";import{join as xb}from"node:path";cn();$t();sr();Ke();ne();async function U0(){let t=xb(hb(),".openclaw/openclaw.json");return lr(t)}async function G0(){return(await U0())?.gateway?.auth?.token??""}var F0=G("openclaw.config"),pb=[0,5e3,5e3],gb=Ve("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),z0="models.providers.",Eo="agents.defaults.models",vo=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new Tn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??pb,this.cliTimeoutMs=e.cliTimeoutMs??gb}async withRetry(e,n){let i;for(let o=0;o<this.retryDelaysMs.length;o++){let c=this.retryDelaysMs[o]??0;c>0&&await new Promise(l=>setTimeout(l,c));try{return await n()}catch(l){i=l,F0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(l)})}}throw new T("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((n,i)=>{let o=rt(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",l=!1,u=x=>{l||(l=!0,clearTimeout(h),x())};o.stderr?.on("data",x=>{c+=x.toString("utf8")});let h=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);h.unref(),o.on("error",x=>u(()=>i(x))),o.on("close",x=>u(()=>{x===0?n():i(new Error(`exit ${x}: ${c.trim().slice(0,500)}`))}))})}async runCliTolerant(e,n){try{await this.runCli(e)}catch(i){let o=String(i);if(n.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,n){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",n])))}catch(i){F0.warn(`${e} failed (best-effort)`,{configPath:n,err:String(i)})}}ensureProvider(e,n){return this.queue.enqueue(()=>this.withRetry(`config set models.providers.${e}`,()=>this.runCli(["config","set",`${z0}${e}`,JSON.stringify(n),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${z0}${e}`)}addModelToAllowlist(e,n){let i={[e]:n?{alias:n}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${Eo}[${e}]`,()=>this.runCli(["config","set",Eo,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${Eo}[${e}]`,`${Eo}.${e}`)}async getAllowlistModelsForProvider(e){let i=(await U0())?.agents?.defaults?.models;if(!i||typeof i!="object")return[];let o=`${e}/`,c=[];for(let l of Object.keys(i))l.startsWith(o)&&c.push(l.slice(o.length));return c}ensureAgent(e,n,i){let o=["agents","add",e,"--workspace",n,"--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 de=G("agent-manager"),ll="acceptEdits",W0="full-access",K0="read-only";function yb(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 bb=(t,e,n,i,o,c,l,u,h,x)=>{switch(t){case"claude-code":{let m={...o?{...$f(o),...Zf(o,l,u)}:{},...h??{},IS_SANDBOX:"1"};return new _o({cwd:n,env:m,agentId:i})}case"codex":{let m=o?[...Vf(o),...Xf(o,l,u)]:[],_=W0;x!==void 0&&(An("codex",x)?_=x:de.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:x}));let S=[...m,...yb(_)],y={...o?Jf(o):{},...h??{}},v=!!o;return new yo({cwd:n,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 Br({command:e,cwd:n,agentId:i,...c?{sessionName:ol(c)}:{}})}};function cl(t){return t==="claude-code"||t==="codex"}function Eb(t){let e=[],n=Object.keys(t).sort();for(let i of n){let o=t[i];o!==void 0&&(vb(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
101
99
  `)}
102
- `}function Yb(t){if(t.includes(`
103
- `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var Qb={path:"",version:"cloud-deployed"},ex="openclaw_gateway_unavailable",eE="openclaw_default_agent_missing";function tx(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 tE={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},nE=6e4,Do=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??Zb,this.createTimeoutMs=e.createTimeoutMs??nE,this.detectorFactory=e.detectorFactory??(()=>new Xn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new Ro({command:r,openclawDir:this.openclawConfigDir})),this.openclawConfigDir=e.openclawConfigDir??_d(Vb(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{fe.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=_d(e,".env");if(await $b(r).then(c=>c.isFile()).catch(()=>!1)){fe.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}let o=Xb({...process.env,...qi(this.paths.agentEnvFile)});await dn(r,o,{mode:384}),fe.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),fe.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new T("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new T("IPC_BAD_REQUEST","framework required");let i=await Oe(e.agentId,this.paths).catch(()=>null),o=xo(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 T("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")fe.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(R=>fe.warn("dispose stale agent failed (ignored)",{err:String(R)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")fe.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(R=>fe.warn("dispose drifted agent failed (ignored)",{err:String(R)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){fe.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let R=await Oe(e.agentId,this.paths).catch(()=>null);R&&(R.patToken=e.patToken,await Ue(R,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){fe.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let R=await Oe(e.agentId,this.paths).catch(()=>null);R&&(R.modelInfo=e.modelInfo,await Ue(R,this.paths))}return fe.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 T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=Ve(e.agentId,this.paths),x=o?"cloud":"local",h=e.framework==="openclaw"&&x==="local",p;h&&!r?.revive&&(p=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let _=p??(h?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),S=e.workspace??_??u.workspace,y=new AbortController,v=setTimeout(()=>y.abort(new T("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),A,k=!1;try{o&&yd(e.framework)&&await xr(e.framework,y.signal);let R=()=>{if(y.signal.aborted)throw y.signal.reason instanceof Error?y.signal.reason:new T("AGENT_TIMEOUT","_agent/create aborted")};await wd(u.root,{recursive:!0}),await wd(S,{recursive:!0}),await wd(u.logs,{recursive:!0}),R(),h||await hr(S,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(x==="cloud"?await Ua(S,"cloud"):await Ua(S,"local",bd)),R();let O=i,E=t0({model:e.model??O?.model}),D=qf(e._meta)??O?.accountId,L=e.patToken??O?.patToken,z=x==="cloud"?e.modelInfo??O?.modelInfo:void 0;if(A=new ko({agentId:e.agentId,framework:e.framework,workspace:S,model:E.model??Lt,deployType:x,...D?{accountId:D}:{},...L?{patToken:L}:{},...z?{modelInfo:z}:{}}),A.status="ok",O?.sessions){let Z=x==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[ee,ae]of Object.entries(O.sessions)){let ce={acpSessionId:ae.acpSessionId,modelToken:ae.modelToken,tokenGeneratedAt:ae.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};Z?ae.permissionMode===void 0?(ce.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",fe.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:ee,framework:e.framework,fallback:ce.permissionMode})):Cn(e.framework,ae.permissionMode)?ce.permissionMode=ae.permissionMode:fe.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:ee,framework:e.framework,value:ae.permissionMode}):ae.permissionMode!==void 0&&fe.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:ee,framework:e.framework,deployType:x}),ae.cozeGroupId&&(ce.cozeGroupId=ae.cozeGroupId),A.sessions.set(ee,ce)}let se=Object.keys(O.sessions).length;se>0&&fe.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:se})}this.registry.register(A),k=!0;let B={agentId:e.agentId,framework:e.framework,workspace:S,cozeIdentity:e.cozeIdentity,createdAt:O?.createdAt??Date.now(),sessions:O?.sessions??{},model:E.model};x==="cloud"&&(B.deployType="cloud"),D&&(B.accountId=D),L&&(B.patToken=L),z&&(B.modelInfo=z),O?.skills&&(B.skills=O.skills),O?.agentName&&(B.agentName=O.agentName),O?.description&&(B.description=O.description),B.skillsRefreshedForVersion=O?.skillsRefreshedForVersion??Ot,e.framework==="openclaw"&&x==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,S)):fe.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let X=e.initialSkills??[];if(X.length>0){let Z=[...B.skills??[]],se=new Map(Z.map((ce,P)=>[ce.skillId,P])),ee=await Promise.allSettled(X.map(ce=>_o({agentId:e.agentId,workspace:S,framework:e.framework,skill:ce}))),ae=0;for(let[ce,P]of ee.entries()){let q=X[ce];q&&(P.status==="fulfilled"?(yo(Z,se,P.value),ae++):fe.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:q.skillId,skillName:q.skillName,err:String(P.reason)}))}ae>0&&(B.skills=Z,fe.info("initialSkills installed",{agentId:e.agentId,installed:ae,requested:X.length}))}return await Ue(B,this.paths),fe.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 fe.error("agent create failed, rolling back",{agentId:e.agentId,err:String(R)}),k&&A&&(await A.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Kb(u.root,{recursive:!0,force:!0}).catch(O=>fe.warn("rm agent dir failed (ignored)",{err:String(O)})),R instanceof T?R:new T("AGENT_SPAWN_FAILED",String(R),{cause:R})}finally{clearTimeout(v)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&yd(e.framework))u=Qb;else throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);yd(e.framework)&&!_s(e.framework)&&(fe.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await xr(e.framework));let x=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,h;if(e.framework==="openclaw")h=await this.buildOpenclawDownstream({session:e,modelConfig:x,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path});else{let p=e.sessions.get(i),_=Zt(e)?p?.permissionMode??nx:"full-access";h=this.factory(e.framework,u.path,e.workspace,e.agentId,x,i,o,c,this.buildBinShimPathEnv(),_,e.framework==="codex"&&e.deployType==="cloud"?_d(Ve(e.agentId,this.paths).root,"codex-home"):void 0)}try{return await h.start(),await h.initialize(tE),h}catch(p){let _=h instanceof Nt?h.getStderrTail():[];throw _.length>0&&fe.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:p instanceof T?p.code:"unknown",recentStderr:_}),await h.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,p)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new T("AGENT_ENV_NOT_READY",tx(o),{cause:{reason:ex}})}catch(o){fe.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof T?i:new T("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};fe.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 fe.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new T("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:eE}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new T("AGENT_ENV_NOT_READY",tx(r),{cause:{reason:ex}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:d,command:u}=e,x=gd(o);if(r.deployType==="local"){let _=await this.ensureOpenclawDefaultAgent();return new Hr({command:u,cwd:_.workspace,agentId:_.id,sessionName:x})}let h=await Q0();try{await this.getOpenclawConfig().ensureAcpDeviceScopes()}catch(_){fe.warn("acp device scope ensure failed (ignored)",{err:String(_)})}let p;if(i?.modelToken){let _=Qc(o),S=ed(i),y=`${_}/${S}`;if(!this.ensuredProviders.has(y)){let v=this.getOpenclawConfig(),A=await v.getAllowlistModelsForProvider(_),k=a0(i,c,d,A);k&&(await v.ensureProvider(_,k),await v.addModelToAllowlist(y),this.ensuredProviders.add(y))}p=y}return new Hr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:x,...h?{gatewayToken:h}:{},...p?{slashModelOnStart:p}:{}})}async openclawRepair(e,r){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,r)}async cleanupOpenclawSessionProviders(e,r){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let i=this.openclawConfigCache,o=r??e.model;for(let c of e.sessions.keys()){let d=Qc(c),u=`${d}/${o}`,x=!0;try{await i.removeProvider(d)}catch(h){x=!1,fe.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:d,err:String(h)})}try{await i.removeModelFromAllowlist(u)}catch(h){x=!1,fe.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:u,err:String(h)})}x&&this.ensuredProviders.delete(u)}}};import{randomUUID as cx}from"node:crypto";import{promises as dE}from"node:fs";import{basename as dx}from"node:path";$e();ie();import{promises as rE}from"node:fs";import{basename as iE}from"node:path";var ix=j("file-upload"),sE="/api/coze_claw/file/agent_upload",oE=6e4;async function sx(t,e={}){let i=`${Pr(Or(e.handshakeBase))}${sE}`,o=e.timeoutMs??oE,c=await rE.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",...In(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},x=new AbortController,h=setTimeout(()=>x.abort(),o);ix.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let p=await fetch(i,{method:"POST",headers:u,body:d,signal:x.signal}),_=p.headers.get("x-tt-logid")??"";if(!p.ok){let v=await p.text().catch(()=>"");throw new T("UPLOAD_FAILED",`upload HTTP ${p.status} logid=${_}: ${v.slice(0,200)}`)}let S=await p.json();if(S.code!==void 0&&S.code!==0)throw new T("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${_}`);let y=S.data?.file?.file_url;if(!y)throw new T("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${_}: ${JSON.stringify(S).slice(0,200)}`);return ix.info("file upload ok",{uri:y,logid:_}),{uri:y}}catch(p){throw p instanceof T?p:p.name==="AbortError"?new T("UPLOAD_FAILED",`upload timeout (${o}ms) for ${iE(t.path)}`):new T("UPLOAD_FAILED",String(p),{cause:p})}finally{clearTimeout(h)}}$e();ie();import{extname as aE}from"node:path";var cE={".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 ox(t){let e=aE(t).toLowerCase();return cE[e]??"application/octet-stream"}Pe();var Po=j("agent-send"),ax=50*1024*1024;function lx(t,e,r){let i=t.get(e);if(!i)throw new T("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new T("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new T("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function ux(t,e,r,i,o,c){let u;for(let x=0;x<=2;x++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(h){u=h,x<2&&(Po.warn("sendAgentFileUpdate failed, retrying",{attempt:x+1,err:String(h)}),await new Promise(p=>setTimeout(p,5e3)))}throw new T("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function fx(t,e){let{session:r,runtime:i}=lx(e.core,t.agentId,t.sessionId);if(!await oi(t.path,r.workspace))throw new T("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await dE.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new T("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>ax)throw new T("FILE_TOO_LARGE",`${o.size} bytes > limit ${ax}`);let c=await ox(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new T("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let d=t.name??dx(t.path),u;try{u=await sx({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(h){throw Po.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:h instanceof T?h.code:"UNKNOWN",message:h instanceof Error?h.message:String(h)}),h}let x={sessionUpdate:"agent_file",messageId:cx(),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 ux(e,r,i,t.sessionId,x,"agent file uploaded to cloud but sendAgentFileUpdate failed"),Po.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 xx(t,e){let{session:r,runtime:i}=lx(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new T("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??dx(t.path),c={sessionUpdate:"group_file",messageId:cx(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await ux(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),Po.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 hx(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}an();Jt();ie();var Mt=j("coze-cli-installer"),px="@coze/cli@latest",lE="coze",gx="0.1.8",uE=5e3,fE=5e3,xE=9e4,mx=1e4,$i=null,Oo=!1;async function vd(t,e={}){if(Oo)return;if($i)return $i;let r=e.exec??Vf;return $i=(async()=>{try{let i=await hE(lE,r),o=!1;if(i){let d=await pE(r);if(d===void 0)Mt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(hx(d,gx))Mt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:d,min:gx}),o=!0;else{Mt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:d}),Oo=!0;return}}let c=o?"upgrade-only":"full";Mt.info("coze-cli install start",{package:px,mode:c});try{await r("npm",["i","-g","--prefer-online",px],{timeout:xE,maxBuffer:10*1024*1024}),Mt.info("coze-cli install ok")}catch(d){Mt.warn("coze-cli install failed (skip subsequent steps)",{err:String(d)});return}if(o){Oo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:mx}),Mt.info("coze config set xTTEnv ok",{env:t.env})}catch(d){Mt.warn("coze config set failed (continue to auth login)",{err:String(d)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:mx}),Mt.info("coze auth login ok")}catch(d){Mt.warn("coze auth login failed",{err:String(d)});return}Oo=!0}finally{$i=null}})(),$i}async function hE(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:uE});return Fa(i)}catch{return}}async function pE(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:fE});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}un();Pe();var gE=10*6e4;function _x(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?gE:e}function Lo(t){return cn(t??Y().configFile)}function Vi(t,e){return ln(e??Y().configFile,t)}import{randomBytes as ME}from"node:crypto";dr();$e();ie();import{createReadStream as mE}from"node:fs";import{mkdir as wE,readFile as _E,realpath as yE,stat as bE,writeFile as EE}from"node:fs/promises";import{basename as vE,dirname as Sd,isAbsolute as SE,join as AE,relative as IE,resolve as yx,sep as kE}from"node:path";import{createInterface as TE}from"node:readline";var Ex=j("fs-rpc"),Ji=Ze("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function vx(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Ji)throw new T("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Ji} bytes`);let i=await Ax(t.path,e);return await wE(Sd(i),{recursive:!0}),await EE(i,t.content,"utf8"),Ex.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function Sx(t,e){let r=await Ax(t.path,e),i=await bE(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Ji&&!o)throw new T("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Ji} bytes`);let c;if(o&&i.size>Ji)c=await CE(r,t.line??1,t.limit);else{let d=await _E(r,"utf8");if(o){let u=d.split(`
104
- `),x=Math.max(0,(t.line??1)-1),h=typeof t.limit=="number"?x+t.limit:void 0;c=u.slice(x,h).join(`
105
- `)}else c=d}return Ex.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function CE(t,e,r){let i=TE({input:mE(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 x of i)if(u>=o&&u<c&&d.push(x),u++,u>=c)break}finally{i.close()}return d.join(`
106
- `)}async function Ax(t,e){if(typeof t!="string"||t.length===0)throw new T("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([bx(yx(e)),bx(yx(t))]),o=IE(r,i);if(RE(o,kE,SE(o)))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function RE(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function bx(t){let e=[],r=t;for(;r!==Sd(r);)try{let i=await yE(r);return e.length?AE(i,...e.reverse()):i}catch{e.push(vE(r)),r=Sd(r)}return t}ie();var Ix=j("prompt-multimodal"),kx=10*1024*1024,DE=15e3,PE=6;async function Tx(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 OE(d))}}let o=Array.from({length:Math.min(PE,t.length)},()=>i());return await Promise.all(o),e}function Cx(t){return t.some(e=>e.type==="image")}async function OE(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Ni(e.uri))return t;try{let{buf:r,contentType:i}=await NE(e.uri),o=e.mimeType||LE(i)||"application/octet-stream";return Ix.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 Ix.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function LE(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function NE(t){let e=new AbortController,r=setTimeout(()=>e.abort(),DE);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>kx)throw new Error(`image too large: ${o.byteLength} bytes (max ${kx})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}fn();$e();ie();var V=j("core"),BE=3e4,FE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,zE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",UE="\u5BA1\u6279\u5DF2\u8D85\u65F6",HE=3e4,No=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Br;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=_x(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(),V.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){V.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),V.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){V.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)&&V.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)=>{V.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:d}),Ki(i),i.downstream=void 0,i.replySeq=0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),this.rejectPendingForDownstream(o,"downstream exited")}))}hasPendingPermissionFor(e){for(let r of this.pendingUpstream.values())if(r.downstream===e)return!0;return!1}rejectPendingForDownstream(e,r){let i=[];for(let[o,c]of this.pendingUpstream)c.downstream===e&&i.push(o);if(i.length!==0){V.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(Tn(o,{code:Q.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(d=>V.debug("send error response to upstream failed (ignored)",{err:String(d)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:Q.INTERNAL_ERROR,message:`bridge: ${r}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,r=this.pendingBridge.size;if(!(e===0&&r===0)){V.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:r});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:Q.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new T("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(Eo(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let r="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&FE.test(i)?this.currentCozeEnv=i:i&&V.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}`):V.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(Mr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Mr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Mr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,Q.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):V.warn("drop unknown notification",{method:e.method})}catch(o){V.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(Tn(r,Gi(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new T("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new T("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new T("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new T("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||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 h=r._meta?.cozeTriggerMsgId,p=ho(r._meta);return V.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,x,c,zE,h,p)}}let d=Date.now(),u=!1;try{let x=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,x}finally{V.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}=Wf(i);switch(r){case"session/new":{let c=GE();return V.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return V.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,d=c.sessionId;if(!d)throw new T("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=Zt(e)?jf(i._meta):void 0;if(u!==void 0&&!Cn(e.framework,u))throw new T("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${pd(e.framework)}`);let x=await this.ensureRuntime(e,d);if(u!==void 0&&x.permissionMode===void 0&&(x.permissionMode=u,await this.persistSessionMapping(e)),x.replySeq=0,await this.ensureDownstream(e,d,x),!x.downstream||!x.acpSessionId)throw new T("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&x.permissionMode!==void 0&&x.permissionMode!==u){let S=x.permissionMode;x.permissionMode=u,await this.persistSessionMapping(e);try{await x.downstream.setSessionMode({sessionId:x.acpSessionId,modeId:u})}catch(y){throw x.permissionMode=S,await this.persistSessionMapping(e).catch(()=>{}),y}}let h=i._meta?.cozeTriggerMsgId;h?e.activeTriggers.set(x.acpSessionId,h):e.activeTriggers.delete(x.acpSessionId);let p=ho(i._meta);if(p?e.activeGroupIds.set(x.acpSessionId,p):e.activeGroupIds.delete(x.acpSessionId),p&&x.cozeGroupId!==p&&(x.cozeGroupId=p,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&Cx(c.prompt))throw new T("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let _=await Tx(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 T&&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,k=v?e.activeGroupIds.get(v):void 0;return V.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:d}),await this.synthesizePromptReply(e,x,d,UE,A,k)}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,V.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:d,acpId:x.acpSessionId}),S.stop("reload-after-turn").catch(y=>V.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:d,err:String(y)})))}else x.downstream?.isAlive()&&this.armIdleTimer(e,d,x)}}case"session/cancel":{let d=o.sessionId;if(!d)throw new T("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(d);if(e.hasSessionQueue(d)){let x=e.getSessionQueue(d);x.size>0&&(V.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:d,queuedCount:x.size}),x.dispose(new T("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,x=ho(i._meta);if(!d)throw new T("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Zt(e))throw e.framework==="openclaw"?new T("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new T("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!Cn(e.framework,u))throw new T("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${pd(e.framework)}`);if(x)return await this.handleGroupSetMode(e,x,u);let h=e.sessions.get(d)??await this.ensureRuntime(e,d);if(h.permissionMode===u)return{};let p=h.permissionMode;if(h.permissionMode=u,await this.persistSessionMapping(e),h.downstream?.isAlive()&&h.acpSessionId)try{await h.downstream.setSessionMode({sessionId:h.acpSessionId,modeId:u})}catch(_){throw h.permissionMode=p,await this.persistSessionMapping(e).catch(()=>{}),_}else V.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:d,modeId:u});return{}}default:throw new T("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 V.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i}),{};V.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,x=d.runtime.acpSessionId;u?.isAlive()&&x&&c.push({downstream:u,acpSessionId:x,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 x of o)x.runtime.permissionMode=x.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 Zt(e)&&(c.permissionMode=e.framework==="claude-code"?bd:rx),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(ht.GEN_MODEL_TOKEN,i,HE);if(!o?.modelToken)throw new T("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof T&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new T("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(Ki(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new T("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,d=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(d>=o&&Date.now()-u<c)throw new T("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${d} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let x;try{x=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(h){throw i.spawnFailCount=d+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(V.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),h}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}),V.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(h){V.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(h)}),i.acpSessionId=void 0;let p=await x.sessionNew({cwd:e.workspace});i.acpSessionId=p.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let h=await x.sessionNew({cwd:e.workspace});i.acpSessionId=h.sessionId,await this.persistSessionMapping(e)}}catch(h){throw V.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(h)}),await x.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,h}if(x.afterSessionEstablished&&i.acpSessionId&&await x.afterSessionEstablished(i.acpSessionId),Zt(e)&&i.acpSessionId&&i.permissionMode)try{await x.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(h){V.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(h)})}}armIdleTimer(e,r,i){if(Ki(i),this.isRuntimeBusy(e,i)){V.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)){V.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}V.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=>V.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(Nr("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(Nr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(x=>V.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){V.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){V.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(WE(r)){V.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"&&Zt(e)){let p=d.currentModeId;Cn(e.framework,p)&&c.permissionMode!==p?(c.permissionMode=p,this.persistSessionMapping(e).catch(_=>V.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(_)}))):typeof p=="string"&&!Cn(e.framework,p)&&V.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:p})}let u={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},x=e.activeTriggers.get(i);x&&(u.cozeTriggerMsgId=x);let h=e.activeGroupIds.get(i);h&&(u.cozeGroupId=h),this.upstream.send(Nr("session/update",{...r,sessionId:o,_meta:u})).catch(p=>V.warn("forward update failed",{agentId:e.agentId,err:String(p)}))}handleAgentRequest(e,r,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,r,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,r,i);return}V.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:Q.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},d=await vx(c,o);r.respondAgentRequest(i.id,d)}else{let c=i.params??{},d=await Sx(c,o);r.respondAgentRequest(i.id,d)}}catch(o){V.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Gi(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,x=u?e.activeTriggers.get(u):void 0,h={cozeAgentId:e.agentId};x&&(h.cozeTriggerMsgId=x);let p=u?e.activeGroupIds.get(u):void 0;p&&(h.cozeGroupId=p);let _=u?this.reverseSessionId(e,u):void 0,S=_?e.sessions.get(_):void 0;S&&(S.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let y={...c,..._?{sessionId:_}:{},_meta:h};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:_}),V.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:_,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(v=>({optionId:v.optionId,kind:v.kind,name:v.name}))}),this.upstream.send(Ui(o,"session/request_permission",y)).catch(v=>{this.pendingUpstream.delete(o),V.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?(V.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"&&qE(e.result,o),V.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 bo(e.error)):i.value.resolve(e.result);return}V.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 V.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:d,key:c}}}sendRequest(e,r,i=BE){let o=this.upstreamIds.next(e);return new Promise((c,d)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),d(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:d,timer:u}),this.upstream.send(Ui(o,e,r)).catch(x=>{let h=this.pendingBridge.get(o);h&&(clearTimeout(h.timer),this.pendingBridge.delete(o)),d(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&&Zt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await ai(e.agentId,r,this.paths)}catch(r){V.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(Tn(e,{code:r,message:i,data:{bridgeVersion:Ot}}))}};function GE(){return ME(16).toString("hex")}function qE(t,e){if(!t||typeof t!="object"){V.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){V.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"){V.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")&&V.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var jE=["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 WE(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 jE.some(c=>o.startsWith(c))}un();ie();Pe();import{randomBytes as KE}from"node:crypto";import{createServer as $E}from"node:http";var VE=1e6,Rx=j("ipc"),Mo=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??Y()}async start(){this.token=KE(32).toString("hex");let e=$E((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(),Rx.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 dn(this.paths.portFile,String(this.port)),await dn(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Zi(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Zi(r,404,{error:"not found"});return}let d=null;if(e.method==="POST")try{d=await JE(e)}catch(u){Zi(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(d,e);Zi(r,200,u??{ok:!0})}catch(u){Rx.error("IPC handler failed",{key:o,err:String(u)}),Zi(r,500,{error:u instanceof Error?u.message:String(u)})}}};function Zi(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function JE(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>VE)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 pS=Gt(Ah(),1),gS=Gt(Wo(),1),mS=Gt(jr(),1),wS=Gt(Nd(),1),_S=Gt(Fd(),1),yS=Gt(jd(),1),Lh=Gt(Jo(),1),bS=Gt(Oh(),1);var Nh=Lh.default;$e();ie();var{FWS:BS}=Kh(),Me=j("upstream.frontier"),Vh="application/json",Jh="none",FS=15e3;function zS(t){class e extends Nh{constructor(i){super(i,Zf,{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(Ll("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let 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 ss=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:Xf,...In(this.opts.ppeOverride)},r=zS(e),i=Qf(this.opts.urlOverride),o={url:i,ws:r,fpID:Jf,aID:po,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Vh,force:!0},payloadEncoding:{encoding:Jh,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new BS(o),d=!1,u=null,x,h,p=new Promise((y,v)=>{x=y,h=v}),_=y=>{d||(d=!0,u&&(clearTimeout(u),u=null),y?h(y):x())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let y=this.openCount===1;Me.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=>Me.warn("onConnect handler threw (ignored)",{err:String(A)}))},c.onclose=y=>{this.opened=!1,Me.info("frontier closed",{code:y.code,reason:y.reason,willReconnect:y.willReconnect})},c.onerror=y=>{Me.warn("frontier error",{code:y.code,msg:y.message}),_(new T("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??FS;u=setTimeout(()=>{_(new T("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${S}ms (handshake or upgrade slow)`))},S),await c.connect();try{await p}catch(y){try{c.close(1e3,"open failed")}catch(v){Me.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){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 T("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 T("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${r.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;Zh(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:Vh,payloadEncoding:Jh})}catch(u){throw Me.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new T("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){Me.debug("drop non-adapter frontier frame",{service:r});return}let i=GS(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;Zh(c)||Me.info("frontier frame in",{logid:HS(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:US(i)}),Promise.resolve(this.handler(o)).catch(d=>Me.warn("frontier frame handler threw",{err:String(d)}))}};function Zh(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Xh=2e3;function US(t){return t.length<=Xh?t:`${t.slice(0,Xh)}...<truncated, total ${t.length} chars>`}function HS(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function GS(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}}$e();ie();var Vd=j("skill-publish"),qS="/api/marketplace/product/skill/publish_with_assets",jS=15e4;async function Yh(t,e={}){let i=`${Pr(Or(e.handshakeBase))}${qS}`,o=e.timeoutMs??jS,c=new FormData;c.append("skill_id",t.skillId??""),c.append("skill_name",t.skillName),c.append("skill_description",t.description??""),c.append("agent_id",t.agentId),c.append("zip_file",new Blob([t.zip],{type:"application/zip"}),"skill.zip");let d={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...In(e.ppeOverride),...t.accountId&&t.accountId!=="0"?{"x-coze-account":t.accountId}:{}},u=new AbortController,x=setTimeout(()=>u.abort(),o);Vd.info("skill publish start",{url:i,method:"POST",form:{skill_id:t.skillId??"",skill_name:t.skillName,skill_description:t.description??"",agent_id:t.agentId,zip_file_bytes:t.zip.length},headers:{...d,Authorization:`Bearer ${t.patToken.slice(0,8)}...`}});try{let h=await fetch(i,{method:"POST",headers:d,body:c,signal:u.signal}),p=h.headers.get("x-tt-logid")??"";if(!h.ok){let y=await h.text().catch(()=>"");throw new T("UPLOAD_FAILED",`skill publish HTTP ${h.status} logid=${p}: ${y.slice(0,200)}`)}let _=await h.json();if(Vd.info("skill publish response",{logid:p,httpStatus:h.status,code:_.code,msg:_.msg,dataSkillId:_.data?.skill_id??"",dataVersion:_.data?.version??""}),_.code!==void 0&&_.code!==0)throw new T("UPLOAD_FAILED",`skill publish code=${_.code} msg=${_.msg??"-"} logid=${p}`);let S={};return _.data?.skill_id!==void 0&&_.data.skill_id!==""&&(S.skillId=String(_.data.skill_id)),_.data?.version&&(S.version=_.data.version),Vd.info("skill publish ok",{logid:p,skillId:S.skillId??"",version:S.version??""}),S}catch(h){throw h instanceof T?h:h.name==="AbortError"?new T("UPLOAD_FAILED",`skill publish timeout (${o}ms): ${t.skillName}`):new T("UPLOAD_FAILED",String(h),{cause:h})}finally{clearTimeout(x)}}ie();var Jd=j("upstream.switchable"),ia=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;Jd.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 Jd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>Jd.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()}};ie();var Zd=j("upstream"),Zr=class{handler=null;async start(){Zd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Zd.info("NoopUpstream stopped",{reason:e})}async send(e){Zd.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)}};$e();ie();un();ie();Pe();import{promises as WS}from"node:fs";var Qh=j("pat-token-store");async function sa(t=Y()){try{let r=(await WS.readFile(t.patTokenFile,"utf8")).trim();return r.length===0?(Qh.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"&&Qh.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function os(t,e=Y()){if(!t)throw new Error("writePatToken: empty patToken");await dn(e.patTokenFile,t,{mode:384})}Pe();Pe();import{promises as oa}from"node:fs";import{join as KS}from"node:path";function $S(t,e){return`#!/bin/sh
100
+ `}function vb(t){if(t.includes(`
101
+ `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var Sb={path:"",version:"cloud-deployed"},H0="openclaw_gateway_unavailable",Ib="openclaw_default_agent_missing";function j0(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 Ab={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},Tb=6e4,So=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??bb,this.createTimeoutMs=e.createTimeoutMs??Tb,this.detectorFactory=e.detectorFactory??(()=>new Vn),this.openclawConfigFactory=e.openclawConfigFactory??(n=>new vo({command:n})),this.openclawConfigDir=e.openclawConfigDir??q0(_b(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{de.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,n=q0(e,".env");if(await wb(n).then(c=>c.isFile()).catch(()=>!1)){de.debug("openclaw .env exists, skip bootstrap",{envFile:n});return}let o=Eb({...process.env,...rl(this.paths.agentEnvFile)});await an(n,o,{mode:384}),de.info("openclaw .env bootstrapped",{envFile:n,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),de.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,n){if(!e.agentId)throw new T("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new T("IPC_BAD_REQUEST","framework required");let i=await ke(e.agentId,this.paths).catch(()=>null),o=co(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 T("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")de.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(k=>de.warn("dispose stale agent failed (ignored)",{err:String(k)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")de.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(k=>de.warn("dispose drifted agent failed (ignored)",{err:String(k)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){de.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let k=await ke(e.agentId,this.paths).catch(()=>null);k&&(k.patToken=e.patToken,await Fe(k,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){de.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let k=await ke(e.agentId,this.paths).catch(()=>null);k&&(k.modelInfo=e.modelInfo,await Fe(k,this.paths))}return de.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 T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=Je(e.agentId,this.paths),h=o?"cloud":"local",x=e.framework==="openclaw"&&h==="local",m;x&&!n?.revive&&(m=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let _=m??(x?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),S=e.workspace??_??u.workspace,y=new AbortController,v=setTimeout(()=>y.abort(new T("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),I,A=!1;try{o&&cl(e.framework)&&await cr(e.framework,y.signal);let k=()=>{if(y.signal.aborted)throw y.signal.reason instanceof Error?y.signal.reason:new T("AGENT_TIMEOUT","_agent/create aborted")};await al(u.root,{recursive:!0}),await al(S,{recursive:!0}),await al(u.logs,{recursive:!0}),k(),x||await ur(S,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(h==="cloud"?await Pa(S,"cloud"):await Pa(S,"local",ll)),k();let P=i,b=Wf({model:e.model??P?.model}),R=Of(e._meta)??P?.accountId,O=e.patToken??P?.patToken,B=h==="cloud"?e.modelInfo??P?.modelInfo:void 0;if(I=new bo({agentId:e.agentId,framework:e.framework,workspace:S,model:b.model??Dt,deployType:h,...R?{accountId:R}:{},...O?{patToken:O}:{},...B?{modelInfo:B}:{}}),I.status="ok",P?.sessions){let $=h==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[X,se]of Object.entries(P.sessions)){let oe={acpSessionId:se.acpSessionId,modelToken:se.modelToken,tokenGeneratedAt:se.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};$?se.permissionMode===void 0?(oe.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",de.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:X,framework:e.framework,fallback:oe.permissionMode})):An(e.framework,se.permissionMode)?oe.permissionMode=se.permissionMode:de.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:X,framework:e.framework,value:se.permissionMode}):se.permissionMode!==void 0&&de.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:X,framework:e.framework,deployType:h}),se.cozeGroupId&&(oe.cozeGroupId=se.cozeGroupId),I.sessions.set(X,oe)}let re=Object.keys(P.sessions).length;re>0&&de.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:re})}this.registry.register(I),A=!0;let M={agentId:e.agentId,framework:e.framework,workspace:S,cozeIdentity:e.cozeIdentity,createdAt:P?.createdAt??Date.now(),sessions:P?.sessions??{},model:b.model};h==="cloud"&&(M.deployType="cloud"),R&&(M.accountId=R),O&&(M.patToken=O),B&&(M.modelInfo=B),P?.skills&&(M.skills=P.skills),P?.agentName&&(M.agentName=P.agentName),P?.description&&(M.description=P.description),M.skillsRefreshedForVersion=P?.skillsRefreshedForVersion??Pt,e.framework==="openclaw"&&h==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,S)):de.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let V=e.initialSkills??[];if(V.length>0){let $=[...M.skills??[]],re=new Map($.map((oe,C)=>[oe.skillId,C])),X=await Promise.allSettled(V.map(oe=>xo({agentId:e.agentId,workspace:S,framework:e.framework,skill:oe}))),se=0;for(let[oe,C]of X.entries()){let U=V[oe];U&&(C.status==="fulfilled"?(po($,re,C.value),se++):de.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:U.skillId,skillName:U.skillName,err:String(C.reason)}))}se>0&&(M.skills=$,de.info("initialSkills installed",{agentId:e.agentId,installed:se,requested:V.length}))}return await Fe(M,this.paths),de.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:h}),{ok:!0,agentId:e.agentId,workspace:S,framework:e.framework}}catch(k){throw de.error("agent create failed, rolling back",{agentId:e.agentId,err:String(k)}),A&&I&&(await I.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await mb(u.root,{recursive:!0,force:!0}).catch(P=>de.warn("rm agent dir failed (ignored)",{err:String(P)})),k instanceof T?k:new T("AGENT_SPAWN_FAILED",String(k),{cause:k})}finally{clearTimeout(v)}}async spawnSessionDownstream(e,n,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&cl(e.framework))u=Sb;else throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);cl(e.framework)&&!ps(e.framework)&&(de.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await cr(e.framework));let h=e.deployType==="cloud"?{model:e.model,modelToken:n,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,x;if(e.framework==="openclaw")x=await this.buildOpenclawDownstream({session:e,modelConfig:h,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path});else{let m=e.sessions.get(i),_=Vt(e)?m?.permissionMode??W0:"full-access";x=this.factory(e.framework,u.path,e.workspace,e.agentId,h,i,o,c,this.buildBinShimPathEnv(),_)}try{return await x.start(),await x.initialize(Ab),x}catch(m){let _=x instanceof Ot?x.getStderrTail():[];throw _.length>0&&de.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:m instanceof T?m.code:"unknown",recentStderr:_}),await x.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,m)}}async resolveSpawnFailure(e,n,i){if(e.framework==="openclaw"&&e.deployType==="local"&&n)try{let o=await this.detectorFactory().probeOpenclawGateway(n);if(!o.reachable)return new T("AGENT_ENV_NOT_READY",j0(o),{cause:{reason:H0}})}catch(o){de.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof T?i:new T("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};de.warn("openclaw default agent stale or missing, attempting lazy re-detect");let n=await this.detectorFactory().detect("openclaw");if(n?.defaultAgent?.id&&n.defaultAgent.workspace)return de.info("openclaw lazy re-detect success",{agentId:n.defaultAgent.id,workspace:n.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=n,{id:n.defaultAgent.id,workspace:n.defaultAgent.workspace};throw new T("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:Ib}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let n=await this.detectorFactory().probeOpenclawGateway(e);if(!n.reachable)throw new T("AGENT_ENV_NOT_READY",j0(n),{cause:{reason:H0}})}async buildOpenclawDownstream(e){let{session:n,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:l,command:u}=e,h=ol(o);if(n.deployType==="local"){let _=await this.ensureOpenclawDefaultAgent();return new Br({command:u,cwd:_.workspace,agentId:_.id,sessionName:h})}let x=await G0(),m;if(i?.modelToken){let _=Wc(o),S=Kc(i),y=`${_}/${S}`;if(!this.ensuredProviders.has(y)){let v=this.getOpenclawConfig(),I=await v.getAllowlistModelsForProvider(_),A=Yf(i,c,l,I);A&&(await v.ensureProvider(_,A),await v.addModelToAllowlist(y),this.ensuredProviders.add(y))}m=y}return new Br({command:u,cwd:n.workspace,agentId:n.agentId,sessionName:h,...x?{gatewayToken:x}:{},...m?{slashModelOnStart:m}:{}})}async openclawRepair(e,n){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,n)}async cleanupOpenclawSessionProviders(e,n){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let i=this.openclawConfigCache,o=n??e.model;for(let c of e.sessions.keys()){let l=Wc(c),u=`${l}/${o}`,h=!0;try{await i.removeProvider(l)}catch(x){h=!1,de.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:l,err:String(x)})}try{await i.removeModelFromAllowlist(u)}catch(x){h=!1,de.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:u,err:String(x)})}h&&this.ensuredProviders.delete(u)}}};import{randomUUID as Y0}from"node:crypto";import{promises as Nb}from"node:fs";import{basename as X0}from"node:path";Ke();ne();import{promises as kb}from"node:fs";import{basename as Rb}from"node:path";var $0=G("file-upload"),Cb="/api/coze_claw/file/agent_upload",Pb=6e4;async function V0(t,e={}){let i=`${Rr(Cr(e.handshakeBase))}${Cb}`,o=e.timeoutMs??Pb,c=await kb.readFile(t.path),l=new FormData;l.append("agent_id",t.agentId),l.append("session_id",t.sessionId),l.append("file_name",t.name),l.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let u={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...vn(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},h=new AbortController,x=setTimeout(()=>h.abort(),o);$0.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:u,body:l,signal:h.signal}),_=m.headers.get("x-tt-logid")??"";if(!m.ok){let v=await m.text().catch(()=>"");throw new T("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 T("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${_}`);let y=S.data?.file?.file_url;if(!y)throw new T("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${_}: ${JSON.stringify(S).slice(0,200)}`);return $0.info("file upload ok",{uri:y,logid:_}),{uri:y}}catch(m){throw m instanceof T?m:m.name==="AbortError"?new T("UPLOAD_FAILED",`upload timeout (${o}ms) for ${Rb(t.path)}`):new T("UPLOAD_FAILED",String(m),{cause:m})}finally{clearTimeout(x)}}Ke();ne();import{extname as Db}from"node:path";var Ob={".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 J0(t){let e=Db(t).toLowerCase();return Ob[e]??"application/octet-stream"}Oe();var Io=G("agent-send"),Z0=50*1024*1024;function Q0(t,e,n){let i=t.get(e);if(!i)throw new T("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new T("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(n);if(!o)throw new T("AGENT_NOT_FOUND",`session=${n} not active in agent=${e}`);return{session:i,runtime:o}}async function eh(t,e,n,i,o,c){let u;for(let h=0;h<=2;h++)try{await t.core.sendAgentFileUpdate(e,n,i,o);return}catch(x){u=x,h<2&&(Io.warn("sendAgentFileUpdate failed, retrying",{attempt:h+1,err:String(x)}),await new Promise(m=>setTimeout(m,5e3)))}throw new T("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function th(t,e){let{session:n,runtime:i}=Q0(e.core,t.agentId,t.sessionId);if(!await si(t.path,n.workspace))throw new T("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${n.workspace}`);let o=await Nb.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new T("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>Z0)throw new T("FILE_TOO_LARGE",`${o.size} bytes > limit ${Z0}`);let c=await J0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new T("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let l=t.name??X0(t.path),u;try{u=await V0({patToken:n.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:l,sizeBytes:o.size,...n.accountId?{accountId:n.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(x){throw Io.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:x instanceof T?x.code:"UNKNOWN",message:x instanceof Error?x.message:String(x)}),x}let h={sessionUpdate:"agent_file",messageId:Y0(),content:{type:t.kind==="image"?"image":"resource",uri:u.uri,mimeType:c,name:l,sizeBytes:o.size,...u.fileId!==void 0?{fileId:u.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await eh(e,n,i,t.sessionId,h,"agent file uploaded to cloud but sendAgentFileUpdate failed"),Io.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:l,bytes:o.size,mime:c,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:c,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function nh(t,e){let{session:n,runtime:i}=Q0(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new T("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??X0(t.path),c={sessionUpdate:"group_file",messageId:Y0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await eh(e,n,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),Io.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 rh(t,e){let n=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(n.length,i.length);for(let c=0;c<o;c++){let l=n[c]??0,u=i[c]??0;if(l<u)return!0;if(l>u)return!1}return!1}on();$t();ne();var Nt=G("coze-cli-installer"),ih="@coze/cli@latest",Lb="coze",sh="0.1.8",Mb=5e3,Bb=5e3,Fb=9e4,oh=1e4,Wi=null,Ao=!1;async function ul(t,e={}){if(Ao)return;if(Wi)return Wi;let n=e.exec??Ff;return Wi=(async()=>{try{let i=await zb(Lb,n),o=!1;if(i){let l=await Ub(n);if(l===void 0)Nt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(rh(l,sh))Nt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:l,min:sh}),o=!0;else{Nt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:l}),Ao=!0;return}}let c=o?"upgrade-only":"full";Nt.info("coze-cli install start",{package:ih,mode:c});try{await n("npm",["i","-g","--prefer-online",ih],{timeout:Fb,maxBuffer:10*1024*1024}),Nt.info("coze-cli install ok")}catch(l){Nt.warn("coze-cli install failed (skip subsequent steps)",{err:String(l)});return}if(o){Ao=!0;return}if(t.env)try{await n("coze",["config","set","xTTEnv",t.env],{timeout:oh}),Nt.info("coze config set xTTEnv ok",{env:t.env})}catch(l){Nt.warn("coze config set failed (continue to auth login)",{err:String(l)})}try{await n("coze",["auth","login","--token",t.patToken],{timeout:oh}),Nt.info("coze auth login ok")}catch(l){Nt.warn("coze auth login failed",{err:String(l)});return}Ao=!0}finally{Wi=null}})(),Wi}async function zb(t,e){let n=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(n,[t],{timeout:Mb});return Ra(i)}catch{return}}async function Ub(t){try{let{stdout:e,stderr:n}=await t("coze",["--version"],{timeout:Bb});return(e||n).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}cn();Oe();var Gb=10*6e4;function ah(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?Gb:e}function To(t){return lr(t??ee().configFile)}function Ki(t,e){return dr(e??ee().configFile,t)}import{randomBytes as aE}from"node:crypto";sr();Ke();ne();import{createReadStream as qb}from"node:fs";import{mkdir as Hb,readFile as jb,realpath as Wb,stat as Kb,writeFile as $b}from"node:fs/promises";import{basename as Vb,dirname as fl,isAbsolute as Jb,join as Zb,relative as Yb,resolve as ch,sep as Xb}from"node:path";import{createInterface as Qb}from"node:readline";var dh=G("fs-rpc"),$i=Ve("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function uh(t,e){let n=Buffer.byteLength(t.content,"utf8");if(n>$i)throw new T("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${n} bytes > limit ${$i} bytes`);let i=await hh(t.path,e);return await Hb(fl(i),{recursive:!0}),await $b(i,t.content,"utf8"),dh.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function fh(t,e){let n=await hh(t.path,e),i=await Kb(n),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>$i&&!o)throw new T("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${$i} bytes`);let c;if(o&&i.size>$i)c=await eE(n,t.line??1,t.limit);else{let l=await jb(n,"utf8");if(o){let u=l.split(`
102
+ `),h=Math.max(0,(t.line??1)-1),x=typeof t.limit=="number"?h+t.limit:void 0;c=u.slice(h,x).join(`
103
+ `)}else c=l}return dh.info("fs/read_text_file ok",{path:n,size:c.length}),{content:c}}async function eE(t,e,n){let i=Qb({input:qb(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof n=="number"?o+n:Number.POSITIVE_INFINITY,l=[],u=0;try{for await(let h of i)if(u>=o&&u<c&&l.push(h),u++,u>=c)break}finally{i.close()}return l.join(`
104
+ `)}async function hh(t,e){if(typeof t!="string"||t.length===0)throw new T("IPC_BAD_REQUEST","path must be a non-empty string");let[n,i]=await Promise.all([lh(ch(e)),lh(ch(t))]),o=Yb(n,i);if(tE(o,Xb,Jb(o)))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function tE(t,e,n){return t===""?!1:n?!0:t===".."||t.startsWith(`..${e}`)}async function lh(t){let e=[],n=t;for(;n!==fl(n);)try{let i=await Wb(n);return e.length?Zb(i,...e.reverse()):i}catch{e.push(Vb(n)),n=fl(n)}return t}ne();var xh=G("prompt-multimodal"),ph=10*1024*1024,nE=15e3,rE=6;async function gh(t){let e=new Array(t.length),n=0;async function i(){for(;n<t.length;){let c=n++,l=t[c];l!==void 0&&(e[c]=await iE(l))}}let o=Array.from({length:Math.min(rE,t.length)},()=>i());return await Promise.all(o),e}function mh(t){return t.some(e=>e.type==="image")}async function iE(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Ni(e.uri))return t;try{let{buf:n,contentType:i}=await oE(e.uri),o=e.mimeType||sE(i)||"application/octet-stream";return xh.info("image uri fetched and inlined",{uri:e.uri,bytes:n.length,mimeType:o}),{type:"image",data:n.toString("base64"),mimeType:o}}catch(n){return xh.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(n)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function sE(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function oE(t){let e=new AbortController,n=setTimeout(()=>e.abort(),nE);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>ph)throw new Error(`image too large: ${o.byteLength} bytes (max ${ph})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(n)}}ln();Ke();ne();var W=G("core"),cE=3e4,lE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,dE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",uE="\u5BA1\u6279\u5DF2\u8D85\u65F6",fE=3e4,ko=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=ah(e.bridgeConfig)}registerExtension(e,n){this.extensions[e]=n}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(n=>n.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}async reloadAgents(e){let n=e?this.agents.has(e)?[e]:[]:[...this.agents.keys()];for(let i of n)await this.agents.get(i)?.killAllRuntimes("reload");return n}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 n of this.registerHandlers)try{n(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,n,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,l)=>{W.info("session runtime exited",{agentId:e.agentId,cloudId:n,code:c,signal:l}),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 n of this.pendingUpstream.values())if(n.downstream===e)return!0;return!1}rejectPendingForDownstream(e,n){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:n,count:i.length});for(let o of i){let c=this.pendingUpstream.get(o);if(c){this.pendingUpstream.delete(o),this.upstream.send(In(o,{code:Y.INTERNAL_ERROR,message:`bridge downstream gone: ${n}`})).catch(l=>W.debug("send error response to upstream failed (ignored)",{err:String(l)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:Y.INTERNAL_ERROR,message:`bridge: ${n}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,n=this.pendingBridge.size;if(!(e===0&&n===0)){W.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:n});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:Y.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new T("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(mo(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let n="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&lE.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){n!==null?await this.sendError(n,Y.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);n!==null&&await this.upstream.send(Or(n,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);n!==null&&await this.upstream.send(Or(n,o));return}if(e.method==="initialize"){n!==null&&await this.upstream.send(Or(n,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}n!==null?await this.sendError(n,Y.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)}),n!==null&&await this.upstream.send(In(n,Gi(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new T("IPC_BAD_REQUEST",`${e.method} requires params`);let n=e.params,i=n._meta?.cozeAgentId;if(!i)throw new T("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new T("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new T("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof n.sessionId=="string"?n.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||e.method==="session/set_mode"||!c)return this.dispatchSessionCall(o,e.method,n);if(e.method==="session/prompt"){let h=o.sessions.get(c);if(h?.pendingPermission){let x=n._meta?.cozeTriggerMsgId,m=lo(n._meta);return W.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,h,c,dE,x,m)}}let l=Date.now(),u=!1;try{let h=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,n));return u=!0,h}finally{W.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-l,ok:u})}}async dispatchSessionCall(e,n,i){e.lastActiveAt=Date.now();let{stripped:o}=Lf(i);switch(n){case"session/new":{let c=hE();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,l=c.sessionId;if(!l)throw new T("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=Vt(e)?Nf(i._meta):void 0;if(u!==void 0&&!An(e.framework,u))throw new T("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${sl(e.framework)}`);let h=await this.ensureRuntime(e,l);if(u!==void 0&&h.permissionMode===void 0&&(h.permissionMode=u,await this.persistSessionMapping(e)),h.replySeq=0,await this.ensureDownstream(e,l,h),!h.downstream||!h.acpSessionId)throw new T("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&h.permissionMode!==void 0&&h.permissionMode!==u){let S=h.permissionMode;h.permissionMode=u,await this.persistSessionMapping(e);try{await h.downstream.setSessionMode({sessionId:h.acpSessionId,modeId:u})}catch(y){throw h.permissionMode=S,await this.persistSessionMapping(e).catch(()=>{}),y}}let x=i._meta?.cozeTriggerMsgId;x?e.activeTriggers.set(h.acpSessionId,x):e.activeTriggers.delete(h.acpSessionId);let m=lo(i._meta);if(m?e.activeGroupIds.set(h.acpSessionId,m):e.activeGroupIds.delete(h.acpSessionId),m&&h.cozeGroupId!==m&&(h.cozeGroupId=m,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&mh(c.prompt))throw new T("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let _=await gh(c.prompt);try{let S=await h.downstream.sessionPrompt({...c,sessionId:h.acpSessionId,prompt:_});return h.lastActiveAt=Date.now(),S}catch(S){if(S instanceof T&&S.code==="AGENT_APPROVAL_TIMEOUT"){let y=h.pendingPermission;y&&(y.downstream.respondAgentRequest(y.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(y.upstreamId),h.pendingPermission=void 0);let v=h.acpSessionId,I=v?e.activeTriggers.get(v):void 0,A=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:l}),await this.synthesizePromptReply(e,h,l,uE,I,A)}throw S}finally{if(e.activeTriggers.delete(h.acpSessionId),e.activeGroupIds.delete(h.acpSessionId),h.pendingPermission=void 0,h.reloadAfterTurn){h.reloadAfterTurn=!1;let S=h.downstream;S&&(h.downstream=void 0,W.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:l,acpId:h.acpSessionId}),S.stop("reload-after-turn").catch(y=>W.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:l,err:String(y)})))}else h.downstream?.isAlive()&&this.armIdleTimer(e,l,h)}}case"session/cancel":{let l=o.sessionId;if(!l)throw new T("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(l);if(e.hasSessionQueue(l)){let h=e.getSessionQueue(l);h.size>0&&(W.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:l,queuedCount:h.size}),h.dispose(new T("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${l}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,l=c.sessionId,u=c.modeId,h=lo(i._meta);if(!l)throw new T("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Vt(e))throw e.framework==="openclaw"?new T("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new T("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!An(e.framework,u))throw new T("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${sl(e.framework)}`);if(h)return await this.handleGroupSetMode(e,h,u);let x=e.sessions.get(l)??await this.ensureRuntime(e,l);if(x.permissionMode===u)return{};let m=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(_){throw x.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:l,modeId:u});return{}}default:throw new T("IPC_BAD_REQUEST",`session method not supported: ${n}`)}}async handleGroupSetMode(e,n,i){let o=[];for(let[l,u]of e.sessions)u.cozeGroupId===n&&u.permissionMode!==i&&o.push({cloudId:l,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:n,modeId:i}),{};W.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:n,modeId:i,targets:o.length});for(let l of o)l.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let l of o){let u=l.runtime.downstream,h=l.runtime.acpSessionId;u?.isAlive()&&h&&c.push({downstream:u,acpSessionId:h,oldMode:l.oldMode,runtime:l.runtime})}for(let l of c)try{await l.downstream.setSessionMode({sessionId:l.acpSessionId,modeId:i})}catch(u){for(let h of o)h.runtime.permissionMode=h.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),u}return{}}async ensureRuntime(e,n){let i=e.sessions.get(n);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,n):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return Vt(e)&&(c.permissionMode=e.framework==="claude-code"?ll:K0),e.sessions.set(n,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,n){let i={sessionId:n,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(ft.GEN_MODEL_TOKEN,i,fE);if(!o?.modelToken)throw new T("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${n})`);return o.modelToken}catch(o){throw o instanceof T&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new T("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,n,i){if(ji(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new T("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,l=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(l>=o&&Date.now()-u<c)throw new T("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${n} spawn failed ${l} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let h;try{h=await this.sessionSpawner(e,i.modelToken,n,this.currentCozeEnv,this.currentMockScenario)}catch(x){throw i.spawnFailCount=l+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(W.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:n,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),x}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=h,this.attachRuntimeHooks(e,n,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await h.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),W.info("session restored via session/load",{agentId:e.agentId,cloudId:n,acpId:i.acpSessionId})}catch(x){W.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:n,acpId:i.acpSessionId,err:String(x)}),i.acpSessionId=void 0;let m=await h.sessionNew({cwd:e.workspace});i.acpSessionId=m.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let x=await h.sessionNew({cwd:e.workspace});i.acpSessionId=x.sessionId,await this.persistSessionMapping(e)}}catch(x){throw W.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:n,acpId:i.acpSessionId,err:String(x)}),await h.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,x}if(h.afterSessionEstablished&&i.acpSessionId&&await h.afterSessionEstablished(i.acpSessionId),Vt(e)&&i.acpSessionId&&i.permissionMode)try{await h.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:n,mode:i.permissionMode,err:String(x)})}}armIdleTimer(e,n,i){if(ji(i),this.isRuntimeBusy(e,i)){W.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:n});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:n}),this.armIdleTimer(e,n,i);return}W.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:n});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:n,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,n){if(n.acpSessionId&&e.activeTriggers.has(n.acpSessionId))return!0;let i=n.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,n,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++n.replySeq};if(n.acpSessionId){let l=e.activeTriggers.get(n.acpSessionId);l&&(c.cozeTriggerMsgId=l);let u=e.activeGroupIds.get(n.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Dr("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,n,i,o,c,l){let u={cozeAgentId:e.agentId,cozeReplySeqID:++n.replySeq};return c&&(u.cozeTriggerMsgId=c),l&&(u.cozeGroupId=l),await this.upstream.send(Dr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(h=>W.warn("synthesizePromptReply update send failed (ignored)",{err:String(h)})),{stopReason:"end_turn"}}forwardUpdate(e,n){let i=n.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(gE(n)){W.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let l=n.update;if(l&&typeof l=="object"&&l.sessionUpdate==="current_mode_update"&&Vt(e)){let m=l.currentModeId;An(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"&&!An(e.framework,m)&&W.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:m})}let u={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},h=e.activeTriggers.get(i);h&&(u.cozeTriggerMsgId=h);let x=e.activeGroupIds.get(i);x&&(u.cozeGroupId=x),this.upstream.send(Dr("session/update",{...n,sessionId:o,_meta:u})).catch(m=>W.warn("forward update failed",{agentId:e.agentId,err:String(m)}))}handleAgentRequest(e,n,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,n,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,n,i);return}W.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),n.respondAgentRequestError(i.id,{code:Y.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,n,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},l=await uh(c,o);n.respondAgentRequest(i.id,l)}else{let c=i.params??{},l=await fh(c,o);n.respondAgentRequest(i.id,l)}}catch(o){W.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),n.respondAgentRequestError(i.id,Gi(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let n=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);n&&(n.pendingPermission=void 0)}forwardPermissionRequest(e,n,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,h=u?e.activeTriggers.get(u):void 0,x={cozeAgentId:e.agentId};h&&(x.cozeTriggerMsgId=h);let m=u?e.activeGroupIds.get(u):void 0;m&&(x.cozeGroupId=m);let _=u?this.reverseSessionId(e,u):void 0,S=_?e.sessions.get(_):void 0;S&&(S.pendingPermission={downstream:n,agentRequestId:i.id,upstreamId:o});let y={...c,..._?{sessionId:_}:{},_meta:x};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:n,method:i.method,cloudSessionId:_}),W.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:_,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(v=>({optionId:v.optionId,kind:v.kind,name:v.name}))}),this.upstream.send(zi(o,"session/request_permission",y)).catch(v=>{this.pendingUpstream.delete(o),W.error("forward permission request failed",{agentId:e.agentId,err:String(v)}),n.respondAgentRequestError(i.id,{code:Y.INTERNAL_ERROR,message:`upstream send failed: ${String(v)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let n=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(n){this.pendingUpstream.delete(n.key);let o=n.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"&&xE(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 go(e.error)):i.value.resolve(e.result);return}W.debug("orphan upstream response (no pending)",{id:e.id})}lookupPending(e,n,i){let o=e.get(n);if(o)return{value:o,key:n};if(typeof n=="number"){let c=String(n),l=e.get(c);if(l)return W.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:n,normalizedId:c}),{value:l,key:c}}}sendRequest(e,n,i=cE){let o=this.upstreamIds.next(e);return new Promise((c,l)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),l(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:l,timer:u}),this.upstream.send(zi(o,e,n)).catch(h=>{let x=this.pendingBridge.get(o);x&&(clearTimeout(x.timer),this.pendingBridge.delete(o)),l(h)})})}async persistSessionMapping(e){if(this.paths)try{let n=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&&Vt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),n.set(i,c)}await oi(e.agentId,n,this.paths)}catch(n){W.warn("persist session mapping failed",{agentId:e.agentId,err:String(n)})}}reverseSessionId(e,n){for(let[i,o]of e.sessions.entries())if(o.acpSessionId===n)return i}sendError(e,n,i){return this.upstream.send(In(e,{code:n,message:i,data:{bridgeVersion:Pt}}))}};function hE(){return aE(16).toString("hex")}function xE(t,e){if(!t||typeof t!="object"){W.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let n=t;if("kind"in n&&!("outcome"in n)){W.warn('permission response: top-level "kind" field (D66 historical bug shape)',{agentId:e.agentId,result:t});return}let i=n.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 pE=["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 gE(t){let e=t.update;if(e?.sessionUpdate!=="agent_message_chunk")return!1;let n=e.content;if(!n||typeof n!="object")return!1;let i=n;if(i.type!=="text"||typeof i.text!="string")return!1;let{text:o}=i;return pE.some(c=>o.startsWith(c))}cn();ne();Oe();import{randomBytes as mE}from"node:crypto";import{createServer as wE}from"node:http";var _E=1e6,wh=G("ipc"),Ro=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(n=>[`${n.method} ${n.path}`,n])),this.paths=e.paths??ee()}async start(){this.token=mE(32).toString("hex");let e=wE((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 n=e.address();if(!n||typeof n!="object")throw new Error("failed to obtain IPC port");return this.port=n.port,await this.persistAuthFiles(),wh.info("IPC listening",{port:this.port}),{port:this.port,token:this.token}}async stop(){let e=this.server;e&&(await new Promise((n,i)=>{e.close(o=>o?i(o):n())}),this.server=null)}async persistAuthFiles(){await an(this.paths.portFile,String(this.port)),await an(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,n){if(e.headers.authorization!==`Bearer ${this.token}`){Vi(n,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Vi(n,404,{error:"not found"});return}let l=null;if(e.method==="POST")try{l=await yE(e)}catch(u){Vi(n,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(l,e);Vi(n,200,u??{ok:!0})}catch(u){wh.error("IPC handler failed",{key:o,err:String(u)}),Vi(n,500,{error:u instanceof Error?u.message:String(u)})}}};function Vi(t,e,n){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(n))}async function yE(t){let e=[],n=0;for await(let o of t){let c=o;if(n+=c.length,n>_E)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 Gv=Ut(hx(),1),qv=Ut(Fo(),1),Hv=Ut(Ur(),1),jv=Ut(vl(),1),Wv=Ut(Al(),1),Kv=Ut(Dl(),1),vx=Ut(qo(),1),$v=Ut(Ex(),1);var Sx=vx.default;Ke();ne();var{FWS:l1}=Lx(),Pe=G("upstream.frontier"),Bx="application/json",Fx="none",d1=15e3;function u1(t){class e extends Sx{constructor(i){super(i,Uf,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>Pe.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(Sd("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let l=Buffer.from(c.slice(0,128)).toString("hex");Pe.debug("WS raw frame out",{bytes:c.byteLength,headHex:l})}catch(c){Pe.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var rs=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){Pe.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Gf,...vn(this.opts.ppeOverride)},n=u1(e),i=Hf(this.opts.urlOverride),o={url:i,ws:n,fpID:zf,aID:uo,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Bx,force:!0},payloadEncoding:{encoding:Fx,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new l1(o),l=!1,u=null,h,x,m=new Promise((y,v)=>{h=y,x=v}),_=y=>{l||(l=!0,u&&(clearTimeout(u),u=null),y?x(y):h())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let y=this.openCount===1;Pe.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:y,openCount:this.openCount}),y&&_();for(let v of this.connectHandlers)Promise.resolve(v({initial:y})).catch(I=>Pe.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=y=>{this.opened=!1,Pe.info("frontier closed",{code:y.code,reason:y.reason,willReconnect:y.willReconnect})},c.onerror=y=>{Pe.warn("frontier error",{code:y.code,msg:y.message}),_(new T("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??d1;u=setTimeout(()=>{_(new T("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){Pe.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,y}}async stop(e){let n=this.fws;if(n){this.fws=null,this.opened=!1;try{n.close(1e3,e??"bridge shutdown")}catch(i){Pe.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let n=this.fws,i=e.method;if(!n)throw Pe.warn("frontier send refused: upstream not started",{method:i}),new T("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let u=Date.now();throw u-this.lastSendRefusedLogAt>1e3?(Pe.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:n.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=u,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new T("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${n.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;zx(c)||Pe.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await n.send(o,{service:33555712,method:1,payloadType:Bx,payloadEncoding:Fx})}catch(u){throw Pe.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new T("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let n=this.opts.getPatTokenForAgent;if(!n)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=n(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let n=e.message?.service;if(n!==33555712){Pe.debug("drop non-adapter frontier frame",{service:n});return}let i=x1(e);if(!i){Pe.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){Pe.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(l){Pe.warn("frontier message JSON parse failed",{err:String(l),head:i.slice(0,80)});return}let c=o;zx(c)||Pe.info("frontier frame in",{logid:h1(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:f1(i)}),Promise.resolve(this.handler(o)).catch(l=>Pe.warn("frontier frame handler threw",{err:String(l)}))}};function zx(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Ux=2e3;function f1(t){return t.length<=Ux?t:`${t.slice(0,Ux)}...<truncated, total ${t.length} chars>`}function h1(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function x1(t){let e=t.message;if(e?.textPayload)return e.textPayload;let n=e?.payload;if(!n)return null;try{return Buffer.from(n).toString("utf8")}catch{return null}}Ke();ne();var Ml=G("skill-publish"),p1="/api/marketplace/product/skill/publish_with_assets",g1=15e4;async function Gx(t,e={}){let i=`${Rr(Cr(e.handshakeBase))}${p1}`,o=e.timeoutMs??g1,c=new FormData;c.append("skill_id",t.skillId??""),c.append("skill_name",t.skillName),c.append("skill_description",t.description??""),c.append("agent_id",t.agentId),c.append("zip_file",new Blob([t.zip],{type:"application/zip"}),"skill.zip");let l={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...vn(e.ppeOverride),...t.accountId&&t.accountId!=="0"?{"x-coze-account":t.accountId}:{}},u=new AbortController,h=setTimeout(()=>u.abort(),o);Ml.info("skill publish start",{url:i,method:"POST",form:{skill_id:t.skillId??"",skill_name:t.skillName,skill_description:t.description??"",agent_id:t.agentId,zip_file_bytes:t.zip.length},headers:{...l,Authorization:`Bearer ${t.patToken.slice(0,8)}...`}});try{let x=await fetch(i,{method:"POST",headers:l,body:c,signal:u.signal}),m=x.headers.get("x-tt-logid")??"";if(!x.ok){let y=await x.text().catch(()=>"");throw new T("UPLOAD_FAILED",`skill publish HTTP ${x.status} logid=${m}: ${y.slice(0,200)}`)}let _=await x.json();if(Ml.info("skill publish response",{logid:m,httpStatus:x.status,code:_.code,msg:_.msg,dataSkillId:_.data?.skill_id??"",dataVersion:_.data?.version??""}),_.code!==void 0&&_.code!==0)throw new T("UPLOAD_FAILED",`skill publish code=${_.code} msg=${_.msg??"-"} logid=${m}`);let S={};return _.data?.skill_id!==void 0&&_.data.skill_id!==""&&(S.skillId=String(_.data.skill_id)),_.data?.version&&(S.version=_.data.version),Ml.info("skill publish ok",{logid:m,skillId:S.skillId??"",version:S.version??""}),S}catch(x){throw x instanceof T?x:x.name==="AbortError"?new T("UPLOAD_FAILED",`skill publish timeout (${o}ms): ${t.skillName}`):new T("UPLOAD_FAILED",String(x),{cause:x})}finally{clearTimeout(h)}}ne();var Bl=G("upstream.switchable"),Yo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,n){if(this.inner===e)return;Bl.info("swap upstream",{reason:n});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 Bl.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(n??"swapped").catch(o=>Bl.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 Fl=G("upstream"),Kr=class{handler=null;async start(){Fl.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Fl.info("NoopUpstream stopped",{reason:e})}async send(e){Fl.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};Ke();ne();cn();ne();Oe();import{promises as m1}from"node:fs";var qx=G("pat-token-store");async function Xo(t=ee()){try{let n=(await m1.readFile(t.patTokenFile,"utf8")).trim();return n.length===0?(qx.warn("pat-token exists but empty (treating as missing; likely interrupted write)",{path:t.patTokenFile}),null):n}catch(e){let n=e?.code;return n!=="ENOENT"&&qx.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:n,message:e.message}),null}}async function is(t,e=ee()){if(!t)throw new Error("writePatToken: empty patToken");await an(e.patTokenFile,t,{mode:384})}Oe();Oe();import{promises as Qo}from"node:fs";import{join as w1}from"node:path";function _1(t,e){return`#!/bin/sh
107
105
  exec ${JSON.stringify(e)} ${JSON.stringify(t)} "$@"
108
- `}function VS(t,e){return`@echo off\r
106
+ `}function y1(t,e){return`@echo off\r
109
107
  "${e}" "${t}" %*\r
110
- `}async function ep(t,e=Y()){let r=e.binDir;await oa.mkdir(r,{recursive:!0});let i=KS(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?VS(t,o):$S(t,o);return await oa.readFile(i,"utf8").catch(()=>null)===c||(await oa.writeFile(i,c,"utf8"),process.platform!=="win32"&&await oa.chmod(i,493)),r}ie();Pe();import{execSync as tp}from"node:child_process";import{readFileSync as np,unlinkSync as JS}from"node:fs";import{mkdir as ZS,open as XS,readFile as rp,unlink as Xd,writeFile as YS}from"node:fs/promises";import{dirname as QS}from"node:path";var e1=j("single-instance"),t1=t=>new Promise(e=>setTimeout(e,t)),aa=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??Y().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:r=>ji(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&&e1.warn("removing stale pid file",{stalePid:i}),await YS(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 rp(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Xd(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 rp(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 ZS(QS(r),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await XS(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 t1(this.claimLockIntervalMs);continue}await Xd(r).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Xd(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=np(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes(Fr)||r.includes("lib/index.js"))}catch{}try{let r=tp(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes(Fr)||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=tp(`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{np(this.pidFile,"utf8").trim()===String(this.selfPid)&&JS(this.pidFile)}catch{}})}};ca();ie();var ir=j("daemon.upstream-watchdog"),d1=12e4,l1=9e5,u1=3e4;function Qd(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var da=class{constructor(e){this.opts=e;this.softMs=e.softMs??Qd("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",d1),this.hardMs=e.hardMs??Qd("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",l1),this.intervalMs=e.intervalMs??Qd("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",u1),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?.(),ir.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&&ir.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&&ir.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,ir.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){ir.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,ir.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>ir.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var W=j("daemon");async function op(){let t=Y();if(process.env.COZE_BRIDGE_LOG_MODE!=="legacy"){Pl({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:P=>Ve(P,t).logs,listAgentIds:()=>ys(t)});try{let{writeFileSync:P}=await import("node:fs");P(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
108
+ `}async function Hx(t,e=ee()){let n=e.binDir;await Qo.mkdir(n,{recursive:!0});let i=w1(n,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?y1(t,o):_1(t,o);return await Qo.readFile(i,"utf8").catch(()=>null)===c||(await Qo.writeFile(i,c,"utf8"),process.platform!=="win32"&&await Qo.chmod(i,493)),n}ne();Oe();import{execSync as jx}from"node:child_process";import{readFileSync as Wx,unlinkSync as b1}from"node:fs";import{mkdir as E1,open as v1,readFile as Kx,unlink as zl,writeFile as S1}from"node:fs/promises";import{dirname as I1}from"node:path";var A1=G("single-instance"),T1=t=>new Promise(e=>setTimeout(e,t)),ea=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??ee().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:n=>qi(n),isDaemon:n=>this.matchesDaemonTitle(n)},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 n=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&&A1.warn("removing stale pid file",{stalePid:i}),await S1(this.pidFile,String(this.selfPid),"utf8"),{kind:"acquired"})});return n.kind==="acquired"&&(this.acquired=!0,this.installCleanupHooks()),n}async release(){if(this.acquired){try{(await Kx(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await zl(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 n=await Kx(e,"utf8"),i=Number.parseInt(n.trim(),10);return Number.isFinite(i)&&i>0?i:null}catch(n){if(n.code==="ENOENT")return null;throw n}}async withClaimLock(e){let n=`${this.pidFile}.lock`;await E1(I1(n),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await v1(n,"wx")}catch(c){if(c.code!=="EEXIST")throw c;let l=await this.readPidFrom(n);if(l!==null&&l!==this.selfPid&&this.probe.isAlive(l)){await T1(this.claimLockIntervalMs);continue}await zl(n).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await zl(n).catch(()=>{})}}throw new Error(`failed to acquire claim lock: ${n} (after ${this.claimLockMaxAttempts} attempts)`)}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let n=Wx(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(n.includes(Lr)||n.includes("lib/index.js"))}catch{}try{let n=jx(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return n.trim()?n.includes(Lr)||n.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=jx(`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{Wx(this.pidFile,"utf8").trim()===String(this.selfPid)&&b1(this.pidFile)}catch{}})}};ta();ne();var er=G("daemon.upstream-watchdog"),L1=12e4,M1=9e5,B1=3e4;function Gl(t,e){let n=process.env[t];if(!n)return e;let i=Number(n);return Number.isFinite(i)&&i>0?i:e}var na=class{constructor(e){this.opts=e;this.softMs=e.softMs??Gl("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",L1),this.hardMs=e.hardMs??Gl("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",M1),this.intervalMs=e.intervalMs??Gl("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",B1),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?.(),er.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&&er.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&&er.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,er.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let n=e-this.downSince;if(n>=this.hardMs){er.error("upstream watchdog: disconnected too long, exiting for supervisor restart",{downMs:n,hardMs:this.hardMs}),this.opts.onFatal(n);return}n>=this.softMs&&this.shouldForceNow(e)&&(this.forcedAt=e,this.forcing=!0,er.warn("upstream watchdog: forcing reconnect",{downMs:n,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>er.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 Jx(){let t=ee();if(process.env.COZE_BRIDGE_LOG_MODE!=="legacy"){Ed({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:C=>Je(C,t).logs,listAgentIds:()=>gs(t)});try{let{writeFileSync:C}=await import("node:fs");C(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
111
109
  \u8BF7\u67E5\u770B: ${t.bridgeLogsDir}/bridge-<YYYY-MM-DD>.log
112
110
  \u6216\u4F7F\u7528: coze-bridge log [-f] [--lines N]
113
- `)}catch{}}let e=new aa({processTitle:Fr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await Lo(),o=i??{};gs({pid:process.pid}),W.info(i?"loaded bridge config":"initialized bridge config");let c=new ia(new Zr),d=null,u=new No({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(P,q,$,re)=>{if(!d)throw new Error("agentManager not ready");return d.spawnSessionDownstream(P,q,$,re)}}),x=new Do({paths:t,config:o,registry:u});d=x;let h,p,_=null,S={},y,v=null,A=null,k=null,R=new Rn;function O(P,q){return R.enqueue(()=>D(P,q))}function E(){A||(A=new da({isConnected:()=>c.isConnected()&&!(v?.isLivenessLost()??!1),forceReconnect:()=>k?O(k,{force:!0}):void 0,onFatal:P=>{if(process.env[as]==="1"){W.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:P});return}W.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:P}),process.exit(1)}})),A.start()}async function D(P,q){let $=P,re=$?.privatecode;if(!re)throw new T("IPC_BAD_REQUEST","/connect requires privatecode");let et=Bi($.env),ge=$.handshake_url,me=$.frontier_url,It=sp($.env,ge,me);if(k=$,!q?.force&&h===re&&p===It){let Ee=await f1(t);return u.agents.size===0&&Ee?(W.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),ua(t,x).catch(Ce=>W.warn("connect-noop auto-revive error (ignored)",{err:String(Ce)}))):W.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let mt=!!h&&h!==re,nn=p!==void 0&&p!==It,Ht=mt||nn,rn=await Jc({privatecode:re,...ge?{endpoint:ge}:{},ppeOverride:et});if(Ht){W.warn("connect config switched, resetting agents",{pcChanged:mt,envChanged:nn,previousPc:h?la(h):"",nextPc:la(re)});for(let Ee of[...u.agents.values()])await Ee.dispose("connect config switch").catch(()=>{}),u.agents.delete(Ee.agentId);u.disconnectedAgents.size>0&&(W.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Zr,"connect switch").catch(()=>{})}_=rn.deviceId,gs({deviceId:_,pid:process.pid}),vd({patToken:re,env:$.env}).catch(Ee=>W.warn("coze-cli setup error (ignored)",{err:String(Ee)}));let ti=new ss({handshake:rn,privatecode:re,...me?{urlOverride:me}:{},ppeOverride:et,getPatTokenForAgent:Ee=>u.agents.get(Ee)?.patToken});return await c.swap(ti,"connect"),h=re,p=It,S=et,y=ge,$.mock_scenario!==void 0&&(u.setMockScenario($.mock_scenario),W.info("mock scenario set",{scenario:$.mock_scenario})),v||(v=new zi({core:u,getDeviceId:()=>_??"",onTickEnd:()=>B.retryPending().catch(Ee=>W.warn("detailSync.retryPending failed (ignored)",{err:String(Ee)})),onAuthFailures:X})),v.start(),E(),Ht&&ua(t,x).catch(Ee=>W.warn("post-connect-switch auto-revive error (ignored)",{err:String(Ee)})),os(re,t).catch(Ee=>W.warn("writePatToken after /connect failed (ignored)",{err:String(Ee)})),W.info("/connect: WS established",{deviceId:_}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async P=>x.createAgent(P.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let L={},z=new wo({agents:u.agents,publishSkillToMarketplace:async P=>{let q=u.agents.get(P.agentId)?.patToken??h;if(!q)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");return Yh({patToken:q,zip:P.zip,...P.skillId?{skillId:P.skillId}:{},skillName:P.skillName,...P.description?{description:P.description}:{},agentId:P.agentId,...P.accountId?{accountId:P.accountId}:{}},{handshakeBase:y,ppeOverride:S})},disposeAndMarkDisconnected:async(P,q)=>{let $=u.agents.get(P);if($){await x.cleanupOpenclawSessionProviders($).catch(et=>W.warn("cleanup openclaw providers failed (ignored)",{agentId:P,err:String(et)}));let re=!0;try{await $.dispose(`disconnect: ${q}`)}catch(et){re=!1,W.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:P,err:String(et)}),$.status="error"}re&&($.status="disconnected",u.unregister(P),u.disconnectedAgents.add(P))}else u.disconnectedAgents.add(P)},disposeForDelete:async(P,q)=>{let $=u.agents.get(P);$&&(await x.cleanupOpenclawSessionProviders($).catch(re=>W.warn("cleanup openclaw providers during delete failed (ignored)",{agentId:P,err:String(re)})),await $.dispose(`delete: ${q}`).catch(re=>W.warn("dispose during delete failed (ignored)",{agentId:P,err:String(re)})),u.unregister(P)),u.disconnectedAgents.delete(P)},detailSyncer:async P=>{if(!L.ref)throw new Error("agent-detail-sync not initialized yet");await L.ref.syncOne(P)},cleanupOpenclawProviders:async(P,q)=>{await x.cleanupOpenclawSessionProviders(P,q)},openclawRepair:async(P,q)=>{await x.openclawRepair(P,q)},isRuntimePendingPermission:P=>u.hasPendingPermissionFor(P)});u.registerExtension("_agent/listSkills",P=>z.listSkills(P.params)),u.registerExtension("_agent/addSkills",P=>z.addSkills(P.params)),u.registerExtension("_agent/removeSkills",P=>z.removeSkills(P.params)),u.registerExtension("_agent/publishSkill",P=>z.publishSkill(P.params)),u.registerExtension("_agent/getFileTree",P=>z.getFileTree(P.params)),u.registerExtension("_agent/getFileContent",P=>z.getFileContent(P.params)),u.registerExtension("_agent/update",P=>z.updateAgent(P.params)),u.registerExtension("_agent/disconnect",P=>z.disconnectAgent(P.params)),u.registerExtension("_agent/switchModel",P=>z.switchModel(P.params)),u.registerExtension("_agent/reset",P=>z.resetAgent(P.params)),u.registerExtension("_agent/repair",P=>z.repairAgent(P.params)),u.registerExtension("_agent/delete",P=>z.deleteAgent(P.params)),u.registerExtension("_agent/upgrade",P=>z.upgradeBridge(P.params));let B=new vs({paths:t,handlers:z,agentManager:x,sendDetail:P=>u.sendRequest("_agent/detail",P)});L.ref=B;let X=async P=>{await Promise.allSettled(P.map(async q=>{try{await z.disconnectAgent({agentId:q.agentId,reason:`auth_failure: code=${q.code} ${q.message}`}),W.info("agent disconnected due to auth failure from heartbeat response",{agentId:q.agentId,code:q.code,message:q.message})}catch($){W.warn("disconnect during authFailure handling failed (ignored)",{agentId:q.agentId,err:String($)})}}))};c.onConnect(({initial:P})=>{W.info("frontier upstream connected, triggering detail sync",{initial:P}),B.syncAll(P?"initial-connect":"reconnect").catch(q=>W.warn("detail sync top-level error (ignored)",{err:String(q)}))});let Z=new Mo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let P=u.getMockScenario();return{running:!0,pid:process.pid,nodeExecPath:process.execPath,nodeVersion:process.version,nodeArch:process.arch,spawnedBy:process.env[as]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:_??"",frameworksCache:o.frameworksCache??{},...P?{mockScenario:P}:{}}}},{method:"POST",path:"/pair",handler:async P=>{let q=P,$=q?.privatecode,re=q?.pairing_code;if(!$||!re)throw new T("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let et=Bi(q.env),ge=q.handshake_url,me=q.frontier_url,It=sp(q.env,ge,me),mt=!!h&&h!==$,nn=p!==void 0&&p!==It,Ht=mt||nn,rn=await Jc({privatecode:$,...ge?{endpoint:ge}:{},ppeOverride:et});if(Ht){W.warn("pair config switched, resetting agents",{pcChanged:mt,envChanged:nn,previousPc:h?la(h):"",nextPc:la($),previousEnvKey:p??"",nextEnvKey:It});for(let Ce of[...u.agents.values()])await Ce.dispose("pair config switch").catch(()=>{}),u.agents.delete(Ce.agentId);u.disconnectedAgents.size>0&&(W.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Zr,"pair switch").catch(()=>{})}_=rn.deviceId,gs({deviceId:_,pid:process.pid}),vd({patToken:$,env:q.env}).catch(Ce=>W.warn("coze-cli setup error (ignored)",{err:String(Ce)}));let ti=new ss({handshake:rn,privatecode:$,...me?{urlOverride:me}:{},ppeOverride:et,getPatTokenForAgent:Ce=>u.agents.get(Ce)?.patToken});await c.swap(ti,"pair");try{let Ce=new Xn;o.frameworksCache=await Ce.detectAll(),await Vi(o),W.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ce){W.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:re,patToken:$,frameworks:Ee,_meta:{cozeDeviceId:_}});W.info("_agent/pair ok",{pairResult:Ce}),h=$,p=It,S=et,y=ge,q.mock_scenario!==void 0&&(u.setMockScenario(q.mock_scenario),W.info("mock scenario set",{scenario:q.mock_scenario})),os($,t).catch(Be=>W.warn("writePatToken after /pair failed (ignored)",{err:String(Be)})),v||(v=new zi({core:u,getDeviceId:()=>_??"",onTickEnd:()=>B.retryPending().catch(Be=>W.warn("detailSync.retryPending failed (ignored)",{err:String(Be)})),onAuthFailures:X})),v.start(),E(),Ht&&ua(t,x).catch(Be=>W.warn("post-pair-switch auto-revive error (ignored)",{err:String(Be)}));let sr;return q.agent_id&&(sr=await h1(q.agent_id,t,x,Be=>u.sendRequest("_agent/detail",Be),$).catch(Be=>(W.error("--agent-id ensureAgent failed",{agentId:q.agent_id,err:String(Be)}),{ok:!1,agentId:q.agent_id??"",note:String(Be)}))),{ok:!0,note:"paired with cloud",...sr?{agent:sr}:{}}}catch(Ce){return W.error("_agent/pair failed",{err:String(Ce)}),{ok:!1,note:`pair failed: ${String(Ce)}`}}}},{method:"POST",path:"/connect",handler:P=>O(P)},{method:"POST",path:"/_agent/create",handler:async P=>{let q=P;return{ok:!0,result:await x.createAgent(q)}}},{method:"POST",path:"/agent/send",handler:async P=>{let q=P;if(!q?.agentId||!q?.sessionId||!q?.kind||!q?.path)throw new T("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!h)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let $=q;return await($.groupFile?xx:fx)($,{core:u,patToken:h,handshakeBase:y,ppeOverride:S})}catch($){if($ instanceof T)return{ok:!1,code:$.code,message:$.message};throw $}}},{method:"POST",path:"/reload",handler:async P=>{let q=P?.agent_id,$=await u.reloadAgents(q);return W.info("IPC /reload: recycled agent subprocesses",{agentId:q??"(all)",recycled:$}),{ok:!0,recycled:$}}},{method:"POST",path:"/shutdown",handler:async()=>(W.info("IPC /shutdown received"),setImmediate(()=>{ce.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:se,token:ee}=await Z.start();try{await ep(t.libEntry,t)}catch(P){W.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(P)})}await u.start(),p1({paths:t,core:u,agentManager:x,detectAll:async()=>(o.frameworksCache=await new Xn().detectAll(),await Vi(o),o.frameworksCache)}).catch(P=>W.warn("startup warmup error (ignored)",{err:String(P)})),Gl().then(async()=>{let{probeAcpVersion:P}=await Promise.resolve().then(()=>(an(),Ul));for(let q of["claude-code","codex"]){let $=await P(q);$&&W.info("acp wrapper version",{framework:q,version:$})}}).catch(P=>W.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(P)}));let ae=null,ce={port:se,token:ee,core:u,ipc:Z,shutdown(P){return ae||(W.info("daemon shutdown",{reason:P}),ae=(async()=>{v?.stop(),A?.stop(),await u.stop(P),await Z.stop(),await e.release()})(),ae)}};for(let P of["SIGTERM","SIGINT"])process.on(P,()=>{ce.shutdown(P).then(()=>process.exit(0))});return process.on("exit",()=>O0()),process.on("unhandledRejection",P=>{W.error("unhandledRejection",{reason:P instanceof Error?P.message:String(P),stack:P instanceof Error?P.stack:void 0})}),process.on("uncaughtException",P=>{W.error("uncaughtException (will exit, supervisor will restart)",{message:P.message,stack:P.stack,name:P.name});try{process.stderr.write(`FATAL uncaughtException: ${P.stack??P.message}
114
- `)}catch{}process.exit(1)}),W.info("daemon ready",{port:se,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),m1({cliSpawned:process.env[as]==="1",readPatToken:()=>sa(t),connect:O}).catch(P=>W.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(P)})),ce}async function f1(t){return ys(t).length>0}function la(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function sp(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function x1(t,e){let r=ys(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(fn(),Es));for(let c of r){await o(c,t).catch(d=>W.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(d)}));try{let d=await i(c,t);d?.deletedAt?(e.disconnectedAgents.add(c),W.info("agent marked deleted on startup",{agentId:c,deletedAt:d.deletedAt,reason:d.deleteReason??""})):d?.disconnectedAt&&(e.disconnectedAgents.add(c),W.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:d.disconnectedAt,reason:d.disconnectReason??""}))}catch(d){W.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(d)})}}}async function h1(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(fn(),Es)),d=await c(t,e);if(d){if(d.deletedAt)throw new T("AGENT_NOT_FOUND",`agent ${t} \u5DF2\u88AB\u5220\u9664 (deletedAt=${d.deletedAt}), \u4E0D\u80FD\u901A\u8FC7 --agent-id \u590D\u6D3B`);W.info("--agent-id: local config found, reconnecting",{agentId:t,framework:d.framework,hadDisconnect:!!d.disconnectedAt});let p=ap(d),_={agentId:d.agentId,framework:d.framework,...d.cozeIdentity?{cozeIdentity:d.cozeIdentity}:{},...d.model?{model:d.model}:{},...o?{patToken:o}:{},...p?{_meta:p}:{}};return await r.createAgent(_),{ok:!0,agentId:t,note:d.disconnectedAt?"revived from local config":"connected from local config"}}W.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let u=await i({_meta:{cozeAgentId:t}});if(!u.framework)throw new T("AGENT_NOT_FOUND",`agent ${t} \u4E0D\u5728\u672C\u5730; \u4E91\u7AEF _agent/detail \u54CD\u5E94\u7F3A framework \u5B57\u6BB5 (D36 \u534F\u8BAE\u6269\u5C55\u672A\u751F\u6548), \u65E0\u6CD5\u5728\u672C\u673A\u65B0\u5EFA`);let x={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...u.deployType?{_meta:{cozeDeployType:u.deployType}}:{}};await r.createAgent(x);let h=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:h?"cloud agent acknowledged":"created from cloud detail"}}async function p1(t){let e=t.logger??W;try{let r=await t.detectAll();e.info("refreshed frameworks_cache",{detected:Object.keys(r??{})})}catch(r){e.warn("framework detection failed (using cached)",{err:String(r)})}await x1(t.paths,t.core).catch(r=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(r)})),await ua(t.paths,t.agentManager).catch(r=>e.warn("auto-revive top-level error (ignored)",{err:String(r)})),await g1(t.paths).catch(r=>e.warn("builtin skill refresh top-level error (ignored)",{err:String(r)}))}async function ua(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(),Es));W.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,d=0;for(let u of i){let x;try{x=await o(u,t)}catch(h){W.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(h)}),d+=1;continue}if(!x){d+=1;continue}if(x.deletedAt){W.info("auto-revive: skip deleted agent",{agentId:u,deletedAt:x.deletedAt}),d+=1;continue}if(x.disconnectedAt){W.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:x.disconnectedAt}),d+=1;continue}try{W.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:x.framework});let h=ap(x);await e.createAgent({agentId:x.agentId,framework:x.framework,...x.cozeIdentity?{cozeIdentity:x.cozeIdentity}:{},...x.model?{model:x.model}:{},...h?{_meta:h}:{}},{revive:!0}),c+=1}catch(h){W.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:x.framework,err:String(h)}),d+=1}}return W.info("auto-revive: done",{revived:c,skipped:d,total:i.length}),{revived:c,skipped:d,total:i.length}}async function g1(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 b0(o,t)).status==="refreshed"&&(i+=1)}catch(c){W.warn("refresh builtin skills failed (skipping agent)",{agentId:o,err:String(c)})}return i>0&&W.info("builtin skills refresh on startup done",{refreshed:i,total:r.length}),{refreshed:i,total:r.length}}async function m1(t){let e=t.logger??W;if(t.cliSpawned)return"skipped-cli";let r=await t.readPatToken();return r?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:r}).catch(i=>e.warn("startup auto-connect failed (staying idle)",{err:String(i)})),"connecting"):(e.info("no stored PAT, skip startup auto-connect"),"skipped-no-pat")}function ap(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}ca();Pe();import{readFile as cp}from"node:fs/promises";var tn=class{paths;constructor(e){this.paths=e??Y()}async probe(e=1e3){let r=await fa(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,body:i.body}:{kind:"stale",reason:`unexpected status ${i.status}`}}catch(i){return{kind:"stale",reason:_1(i)}}}async request(e){let r=await fa(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}),x=await u.text();return{status:u.status,body:w1(x)}}finally{clearTimeout(d)}}};async function fa(t){try{let[e,r]=await Promise.all([cp(t.portFile,"utf8"),cp(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 w1(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function _1(t){return t instanceof Error?t.message:String(t)}Jt();ie();dr();import{spawn as y1}from"node:child_process";import{userInfo as lp}from"node:os";var el="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",b1=new Set(["bash","zsh","sh","dash","ksh"]),dp=Ze("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),E1=2e3;function v1(t,e=el){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(`
115
- `)){let u=d.indexOf("=");u<=0||(c[d.slice(0,u)]=d.slice(u+1))}return c}function S1(){let t=(process.env.SHELL??"").trim()||(lp().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return b1.has(e)?t:null}function A1(t){return new Promise(e=>{let r=`printf '%s' '${el}'; env; printf '%s' '${el}'`,i;try{i=y1(t,["-ilc",r],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??lp().homedir}})}catch{e(null);return}let o="",c=!1,d=p=>{try{i.pid&&process.kill(-i.pid,p)}catch{}},u=p=>{c||(c=!0,clearTimeout(x),clearTimeout(h),e(p))};i.stdout?.on("data",p=>{o+=p.toString("utf8")}),i.on("error",()=>u(null)),i.on("close",()=>u(o.length>0?o:null));let x=setTimeout(()=>d("SIGTERM"),dp),h=setTimeout(()=>{d("SIGKILL"),u(o.length>0?o:null)},dp+E1)})}async function tl(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let r=S1();if(!r)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??A1)(r);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=v1(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}Pe();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}}an();import{chmod as I1,copyFile as up,mkdir as xp,readFile as ds,rename as fp,rm as il,stat as sl,writeFile as k1}from"node:fs/promises";import{homedir as BP}from"node:os";import{dirname as T1,join as Ut,resolve as ol,sep as cs}from"node:path";import{fileURLToPath as C1}from"node:url";Jt();ie();Pe();var Xr=j("dist-install");function hp(){return{darwin:{arm64:"@zed-industries/codex-acp-darwin-arm64",x64:"@zed-industries/codex-acp-darwin-x64"},linux:{arm64:"@zed-industries/codex-acp-linux-arm64",x64:"@zed-industries/codex-acp-linux-x64"},win32:{arm64:"@zed-industries/codex-acp-win32-arm64",x64:"@zed-industries/codex-acp-win32-x64"}}[process.platform]?.[process.arch]}function R1(){return process.platform==="win32"?"codex-acp.exe":"codex-acp"}function D1(t){let e=C1(t),r=T1(e),i=`${cs}src${cs}`;if(r.includes(i)||r.endsWith(`${cs}src${cs}cli`))return null;let o=ol(r,"index.js"),c=ol(r,"..","package.json");return{dist:o,pkgJson:c}}async function al(t={}){let e=t.paths??Y(),r=D1(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 v=JSON.parse(await ds(o,"utf8"));c=v.version??"unknown",d=v.dependencies??{}}catch(v){return Xr.warn("cannot read source package.json,skip dist install",{err:String(v)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(v)}`}}let u=ws.map(v=>({name:v,spec:d[v]??"latest"})),x=u.map(({name:v,spec:A})=>`${v}@${A}`),h=await Lo(e.configFile)??{},p=h.libVersion,_=await ds(e.libEntry).then(()=>!0).catch(()=>!1),S=p===c,y=await pp(e,u);if(S&&_&&y)return{kind:"already-current",libVersion:c};if(!S||!_){await xp(e.libDir,{recursive:!0}),await up(i,e.libEntry),await up(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let v=ol(e.libDir,"package.json"),A=`${JSON.stringify({type:"module"},null,2)}
116
- `;await ds(v,"utf8").catch(()=>null)!==A&&await k1(v,A)}return y||(t.installWrappers?await t.installWrappers(e,x):await O1(e,x,u)),h.libVersion=c,await Vi(h,e.configFile),Xr.info("dist installed",{libEntry:e.libEntry,fromVersion:p,toVersion:c}),S&&_?{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 pp(t,e){for(let r of e){let i=Ut(t.libDir,"node_modules",...r.name.split("/"),"package.json"),o;try{o=JSON.parse(await ds(i,"utf8"))}catch(d){return Xr.warn("wrapper not ready: package.json read failed",{package:r.name,expected:r.spec,pkgJson:i,err:String(d)}),!1}let c=o.version;if(!c)return Xr.warn("wrapper not ready: package.json \u7F3A version",{package:r.name,expected:r.spec,pkgJson:i}),!1;if(!P1(c,r.spec))return Xr.warn("wrapper not ready: installed version does not satisfy expected range",{package:r.name,installed:c,expected:r.spec}),!1}return!!await gp(Ut(t.libDir,"node_modules"))}function P1(t,e){let r=nl(t);if(!r)return!0;let i=e.trim();if(!i||i==="*"||i==="latest")return!0;if(i.startsWith("^")){let c=nl(i.slice(1));if(!c)return!0;if(rl(r,c)<0)return!1;let d=c[0]>0?[c[0]+1,0,0]:c[1]>0?[0,c[1]+1,0]:[0,0,c[2]+1];return rl(r,d)<0}let o=nl(i);return o?rl(r,o)===0:!0}function nl(t){let e=t.match(/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?$/);return e?[Number(e[1]),Number(e[2]??0),Number(e[3]??0)]:null}function rl(t,e){for(let r=0;r<3;r++){let i=(t[r]??0)-(e[r]??0);if(i!==0)return i}return 0}async function O1(t,e,r){await M1(t.installLock,async()=>{if(await pp(t,r))return;let i=Math.random().toString(36).slice(2,10),o=`${t.libDir}${cs}.staging-${process.pid}-${i}`,c=Ut(o,"node_modules"),d=Ut(t.libDir,"node_modules");try{await xp(o,{recursive:!0}),await L1(e,o),await N1(c);let u=`${d}.trash-${i}`;await fp(d,u).catch(()=>{}),await fp(c,d),await il(u,{recursive:!0,force:!0}).catch(()=>{}),Xr.info("wrapper closure installed",{liveNm:d,specs:e})}finally{await il(o,{recursive:!0,force:!0}).catch(()=>{})}})}function L1(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--include=optional","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=it("npm",r,{stdio:["ignore","pipe","pipe"]}),d="";c.stderr?.on("data",x=>{d.length<8192&&(d+=x.toString("utf8"))});let u=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",x=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(x)}`))}),c.once("close",x=>{clearTimeout(u),x===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${x}: ${d.trim().slice(0,2e3)}`))})})}async function N1(t){for(let e of ws){let r=Ut(t,...e.split("/")),i=JSON.parse(await ds(Ut(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=Ut(t,".bin",o),d=await sl(c);process.platform!=="win32"&&!(d.mode&73)&&await I1(c,d.mode|73).catch(()=>{})}if(!await gp(t)){let e=hp()??"<unsupported-platform>";throw new Error(`${e}: \u5F53\u524D\u5E73\u53F0 codex-acp binary \u7F3A\u5931`)}}async function gp(t){let e=hp();if(!e)return!0;let r=Ut(t,...e.split("/")),i=Ut(r,"package.json"),o=Ut(r,"bin",R1()),[c,d]=await Promise.all([sl(i).then(u=>u.isFile()).catch(()=>!1),sl(o).then(u=>u.isFile()).catch(()=>!1)]);return c&&d}async function M1(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 il(t,{force:!0}).catch(()=>{})}}La();ie();Pe();import{closeSync as wp,fstatSync as _p,openSync as yp,readFileSync as B1,readSync as F1,readdirSync as z1,statSync as U1}from"node:fs";import{join as xa}from"node:path";var H1=new Set(["debug","info","warn","error"]);function bp(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),x=Number.isInteger(u)&&u>=0?u:200,h=c.value&&H1.has(c.value)?c.value:void 0,p={lines:x,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(p.agentId=r.value),i.value&&(p.date=i.value),h&&(p.level=h),d.value&&(p.grep=d.value),p}function G1(t,e){return t.agentId?xa(Ve(t.agentId,e).logs,lr("agent",t.date)):xa(e.bridgeLogsDir,lr("bridge",t.date))}function q1(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function j1(t,e){let r;try{r=z1(t)}catch{return[]}let i=[];for(let o of r){let c=Oa(o,e);if(!c)continue;let d=0;try{d=U1(xa(t,o)).size}catch{}i.push({file:xa(t,o),date:c,size:d})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function Ep(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"&&!Nl(r,e.level))return!1}return!0}var mp={debug:"90",info:"36",warn:"33",error:"31"},W1=new Set(["ts","level","module","msg"]);function K1(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function vp(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=K1(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&mp[o]&&(c=`\x1B[${mp[o]}m${c}\x1B[0m`);let d=typeof r.module=="string"?r.module:"",u=typeof r.msg=="string"?r.msg:"",x=Object.entries(r).filter(([h])=>!W1.has(h)).map(([h,p])=>` ${h}=${typeof p=="string"?p:JSON.stringify(p)}`).join("");return`${i} ${c} ${d} ${u}${x}`}function $1(t,e,r){let c=B1(t,"utf8").split(`
117
- `).filter(d=>d.length>0).filter(d=>Ep(d,{level:e.level,grep:e.grep}));for(let d of q1(c,e.lines))process.stdout.write(`${vp(d,{raw:e.raw,color:r})}
118
- `)}async function Sp(t,e){let r=e.paths??Y(),i=process.stdout.isTTY===!0;if(t.list){let d=t.agentId?Ve(t.agentId,r).logs:r.bridgeLogsDir,u=t.agentId?"agent":"bridge",x=j1(d,u);if(x.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${d}
119
- `),1;for(let h of x)process.stdout.write(`${h.date} ${(h.size/1024).toFixed(1)}KB ${h.file}
120
- `);return 0}let o=t.date??Nn(new Date),c=G1({agentId:t.agentId,date:o},r);try{$1(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
111
+ `)}catch{}}let e=new ea({processTitle:Lr}),n=await e.acquire();if(n.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${n.pid})`);let i=await To(),o=i??{};hs({pid:process.pid}),q.info(i?"loaded bridge config":"initialized bridge config");let c=new Yo(new Kr),l=null,u=new ko({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(C,U,j,te)=>{if(!l)throw new Error("agentManager not ready");return l.spawnSessionDownstream(C,U,j,te)}}),h=new So({paths:t,config:o,registry:u});l=h;let x,m,_=null,S={},y,v=null,I=null,A=null,k=new Tn;function P(C,U){return k.enqueue(()=>R(C,U))}function b(){I||(I=new na({isConnected:()=>c.isConnected()&&!(v?.isLivenessLost()??!1),forceReconnect:()=>A?P(A,{force:!0}):void 0,onFatal:C=>{if(process.env[ss]==="1"){q.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:C});return}q.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:C}),process.exit(1)}})),I.start()}async function R(C,U){let j=C,te=j?.privatecode;if(!te)throw new T("IPC_BAD_REQUEST","/connect requires privatecode");let Qe=Mi(j.env),xe=j.handshake_url,pe=j.frontier_url,St=Vx(j.env,xe,pe);if(A=j,!U?.force&&x===te&&m===St){let _e=await F1(t);return u.agents.size===0&&_e?(q.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),ia(t,h).catch(Ae=>q.warn("connect-noop auto-revive error (ignored)",{err:String(Ae)}))):q.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let pt=!!x&&x!==te,en=m!==void 0&&m!==St,zt=pt||en,tn=await Uc({privatecode:te,...xe?{endpoint:xe}:{},ppeOverride:Qe});if(zt){q.warn("connect config switched, resetting agents",{pcChanged:pt,envChanged:en,previousPc:x?ra(x):"",nextPc:ra(te)});for(let _e of[...u.agents.values()])await _e.dispose("connect config switch").catch(()=>{}),u.agents.delete(_e.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 Kr,"connect switch").catch(()=>{})}_=tn.deviceId,hs({deviceId:_,pid:process.pid}),ul({patToken:te,env:j.env}).catch(_e=>q.warn("coze-cli setup error (ignored)",{err:String(_e)}));let Yr=new rs({handshake:tn,privatecode:te,...pe?{urlOverride:pe}:{},ppeOverride:Qe,getPatTokenForAgent:_e=>u.agents.get(_e)?.patToken});return await c.swap(Yr,"connect"),x=te,m=St,S=Qe,y=xe,j.mock_scenario!==void 0&&(u.setMockScenario(j.mock_scenario),q.info("mock scenario set",{scenario:j.mock_scenario})),v||(v=new Fi({core:u,getDeviceId:()=>_??"",onTickEnd:()=>M.retryPending().catch(_e=>q.warn("detailSync.retryPending failed (ignored)",{err:String(_e)})),onAuthFailures:V})),v.start(),b(),zt&&ia(t,h).catch(_e=>q.warn("post-connect-switch auto-revive error (ignored)",{err:String(_e)})),is(te,t).catch(_e=>q.warn("writePatToken after /connect failed (ignored)",{err:String(_e)})),q.info("/connect: WS established",{deviceId:_}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async C=>h.createAgent(C.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let O={},B=new ho({agents:u.agents,publishSkillToMarketplace:async C=>{let U=u.agents.get(C.agentId)?.patToken??x;if(!U)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");return Gx({patToken:U,zip:C.zip,...C.skillId?{skillId:C.skillId}:{},skillName:C.skillName,...C.description?{description:C.description}:{},agentId:C.agentId,...C.accountId?{accountId:C.accountId}:{}},{handshakeBase:y,ppeOverride:S})},disposeAndMarkDisconnected:async(C,U)=>{let j=u.agents.get(C);if(j){await h.cleanupOpenclawSessionProviders(j).catch(Qe=>q.warn("cleanup openclaw providers failed (ignored)",{agentId:C,err:String(Qe)}));let te=!0;try{await j.dispose(`disconnect: ${U}`)}catch(Qe){te=!1,q.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:C,err:String(Qe)}),j.status="error"}te&&(j.status="disconnected",u.unregister(C),u.disconnectedAgents.add(C))}else u.disconnectedAgents.add(C)},disposeForDelete:async(C,U)=>{let j=u.agents.get(C);j&&(await h.cleanupOpenclawSessionProviders(j).catch(te=>q.warn("cleanup openclaw providers during delete failed (ignored)",{agentId:C,err:String(te)})),await j.dispose(`delete: ${U}`).catch(te=>q.warn("dispose during delete failed (ignored)",{agentId:C,err:String(te)})),u.unregister(C)),u.disconnectedAgents.delete(C)},detailSyncer:async C=>{if(!O.ref)throw new Error("agent-detail-sync not initialized yet");await O.ref.syncOne(C)},cleanupOpenclawProviders:async(C,U)=>{await h.cleanupOpenclawSessionProviders(C,U)},openclawRepair:async(C,U)=>{await h.openclawRepair(C,U)},isRuntimePendingPermission:C=>u.hasPendingPermissionFor(C)});u.registerExtension("_agent/listSkills",C=>B.listSkills(C.params)),u.registerExtension("_agent/addSkills",C=>B.addSkills(C.params)),u.registerExtension("_agent/removeSkills",C=>B.removeSkills(C.params)),u.registerExtension("_agent/publishSkill",C=>B.publishSkill(C.params)),u.registerExtension("_agent/getFileTree",C=>B.getFileTree(C.params)),u.registerExtension("_agent/getFileContent",C=>B.getFileContent(C.params)),u.registerExtension("_agent/update",C=>B.updateAgent(C.params)),u.registerExtension("_agent/disconnect",C=>B.disconnectAgent(C.params)),u.registerExtension("_agent/switchModel",C=>B.switchModel(C.params)),u.registerExtension("_agent/reset",C=>B.resetAgent(C.params)),u.registerExtension("_agent/repair",C=>B.repairAgent(C.params)),u.registerExtension("_agent/delete",C=>B.deleteAgent(C.params)),u.registerExtension("_agent/upgrade",C=>B.upgradeBridge(C.params));let M=new _s({paths:t,handlers:B,agentManager:h,sendDetail:C=>u.sendRequest("_agent/detail",C)});O.ref=M;let V=async C=>{await Promise.allSettled(C.map(async U=>{try{await B.disconnectAgent({agentId:U.agentId,reason:`auth_failure: code=${U.code} ${U.message}`}),q.info("agent disconnected due to auth failure from heartbeat response",{agentId:U.agentId,code:U.code,message:U.message})}catch(j){q.warn("disconnect during authFailure handling failed (ignored)",{agentId:U.agentId,err:String(j)})}}))};c.onConnect(({initial:C})=>{q.info("frontier upstream connected, triggering detail sync",{initial:C}),M.syncAll(C?"initial-connect":"reconnect").catch(U=>q.warn("detail sync top-level error (ignored)",{err:String(U)}))});let $=new Ro({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let C=u.getMockScenario();return{running:!0,pid:process.pid,nodeExecPath:process.execPath,nodeVersion:process.version,nodeArch:process.arch,spawnedBy:process.env[ss]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:_??"",frameworksCache:o.frameworksCache??{},...C?{mockScenario:C}:{}}}},{method:"POST",path:"/pair",handler:async C=>{let U=C,j=U?.privatecode,te=U?.pairing_code;if(!j||!te)throw new T("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Qe=Mi(U.env),xe=U.handshake_url,pe=U.frontier_url,St=Vx(U.env,xe,pe),pt=!!x&&x!==j,en=m!==void 0&&m!==St,zt=pt||en,tn=await Uc({privatecode:j,...xe?{endpoint:xe}:{},ppeOverride:Qe});if(zt){q.warn("pair config switched, resetting agents",{pcChanged:pt,envChanged:en,previousPc:x?ra(x):"",nextPc:ra(j),previousEnvKey:m??"",nextEnvKey:St});for(let Ae of[...u.agents.values()])await Ae.dispose("pair config switch").catch(()=>{}),u.agents.delete(Ae.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 Kr,"pair switch").catch(()=>{})}_=tn.deviceId,hs({deviceId:_,pid:process.pid}),ul({patToken:j,env:U.env}).catch(Ae=>q.warn("coze-cli setup error (ignored)",{err:String(Ae)}));let Yr=new rs({handshake:tn,privatecode:j,...pe?{urlOverride:pe}:{},ppeOverride:Qe,getPatTokenForAgent:Ae=>u.agents.get(Ae)?.patToken});await c.swap(Yr,"pair");try{let Ae=new Vn;o.frameworksCache=await Ae.detectAll(),await Ki(o),q.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ae){q.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ae)})}let _e=Object.keys(o.frameworksCache??{});try{let Ae=await u.sendRequest("_agent/pair",{pairCode:te,patToken:j,frameworks:_e,_meta:{cozeDeviceId:_}});q.info("_agent/pair ok",{pairResult:Ae}),x=j,m=St,S=Qe,y=xe,U.mock_scenario!==void 0&&(u.setMockScenario(U.mock_scenario),q.info("mock scenario set",{scenario:U.mock_scenario})),is(j,t).catch(De=>q.warn("writePatToken after /pair failed (ignored)",{err:String(De)})),v||(v=new Fi({core:u,getDeviceId:()=>_??"",onTickEnd:()=>M.retryPending().catch(De=>q.warn("detailSync.retryPending failed (ignored)",{err:String(De)})),onAuthFailures:V})),v.start(),b(),zt&&ia(t,h).catch(De=>q.warn("post-pair-switch auto-revive error (ignored)",{err:String(De)}));let tr;return U.agent_id&&(tr=await U1(U.agent_id,t,h,De=>u.sendRequest("_agent/detail",De),j).catch(De=>(q.error("--agent-id ensureAgent failed",{agentId:U.agent_id,err:String(De)}),{ok:!1,agentId:U.agent_id??"",note:String(De)}))),{ok:!0,note:"paired with cloud",...tr?{agent:tr}:{}}}catch(Ae){return q.error("_agent/pair failed",{err:String(Ae)}),{ok:!1,note:`pair failed: ${String(Ae)}`}}}},{method:"POST",path:"/connect",handler:C=>P(C)},{method:"POST",path:"/_agent/create",handler:async C=>{let U=C;return{ok:!0,result:await h.createAgent(U)}}},{method:"POST",path:"/agent/send",handler:async C=>{let U=C;if(!U?.agentId||!U?.sessionId||!U?.kind||!U?.path)throw new T("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!x)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let j=U;return await(j.groupFile?nh:th)(j,{core:u,patToken:x,handshakeBase:y,ppeOverride:S})}catch(j){if(j instanceof T)return{ok:!1,code:j.code,message:j.message};throw j}}},{method:"POST",path:"/reload",handler:async C=>{let U=C?.agent_id,j=await u.reloadAgents(U);return q.info("IPC /reload: recycled agent subprocesses",{agentId:U??"(all)",recycled:j}),{ok:!0,recycled:j}}},{method:"POST",path:"/shutdown",handler:async()=>(q.info("IPC /shutdown received"),setImmediate(()=>{oe.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:re,token:X}=await $.start();try{await Hx(t.libEntry,t)}catch(C){q.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(C)})}await u.start(),G1({paths:t,core:u,agentManager:h,detectAll:async()=>(o.frameworksCache=await new Vn().detectAll(),await Ki(o),o.frameworksCache)}).catch(C=>q.warn("startup warmup error (ignored)",{err:String(C)})),Dd().then(async()=>{let{probeAcpVersion:C}=await Promise.resolve().then(()=>(on(),Cd));for(let U of["claude-code","codex"]){let j=await C(U);j&&q.info("acp wrapper version",{framework:U,version:j})}}).catch(C=>q.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(C)}));let se=null,oe={port:re,token:X,core:u,ipc:$,shutdown(C){return se||(q.info("daemon shutdown",{reason:C}),se=(async()=>{v?.stop(),I?.stop(),await u.stop(C),await $.stop(),await e.release()})(),se)}};for(let C of["SIGTERM","SIGINT"])process.on(C,()=>{oe.shutdown(C).then(()=>process.exit(0))});return process.on("exit",()=>S0()),process.on("unhandledRejection",C=>{q.error("unhandledRejection",{reason:C instanceof Error?C.message:String(C),stack:C instanceof Error?C.stack:void 0})}),process.on("uncaughtException",C=>{q.error("uncaughtException (will exit, supervisor will restart)",{message:C.message,stack:C.stack,name:C.name});try{process.stderr.write(`FATAL uncaughtException: ${C.stack??C.message}
112
+ `)}catch{}process.exit(1)}),q.info("daemon ready",{port:re,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),H1({cliSpawned:process.env[ss]==="1",readPatToken:()=>Xo(t),connect:P}).catch(C=>q.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(C)})),oe}async function F1(t){return gs(t).length>0}function ra(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function Vx(t,e,n){return`${t??""}|${e??""}|${n??""}`}async function z1(t,e){let n=gs(t);if(n.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(ln(),ws));for(let c of n){await o(c,t).catch(l=>q.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(l)}));try{let l=await i(c,t);l?.deletedAt?(e.disconnectedAgents.add(c),q.info("agent marked deleted on startup",{agentId:c,deletedAt:l.deletedAt,reason:l.deleteReason??""})):l?.disconnectedAt&&(e.disconnectedAgents.add(c),q.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:l.disconnectedAt,reason:l.disconnectReason??""}))}catch(l){q.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(l)})}}}async function U1(t,e,n,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(ln(),ws)),l=await c(t,e);if(l){if(l.deletedAt)throw new T("AGENT_NOT_FOUND",`agent ${t} \u5DF2\u88AB\u5220\u9664 (deletedAt=${l.deletedAt}), \u4E0D\u80FD\u901A\u8FC7 --agent-id \u590D\u6D3B`);q.info("--agent-id: local config found, reconnecting",{agentId:t,framework:l.framework,hadDisconnect:!!l.disconnectedAt});let m=Zx(l),_={agentId:l.agentId,framework:l.framework,...l.cozeIdentity?{cozeIdentity:l.cozeIdentity}:{},...l.model?{model:l.model}:{},...o?{patToken:o}:{},...m?{_meta:m}:{}};return await n.createAgent(_),{ok:!0,agentId:t,note:l.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 T("AGENT_NOT_FOUND",`agent ${t} \u4E0D\u5728\u672C\u5730; \u4E91\u7AEF _agent/detail \u54CD\u5E94\u7F3A framework \u5B57\u6BB5 (D36 \u534F\u8BAE\u6269\u5C55\u672A\u751F\u6548), \u65E0\u6CD5\u5728\u672C\u673A\u65B0\u5EFA`);let h={agentId: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 n.createAgent(h);let x=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:x?"cloud agent acknowledged":"created from cloud detail"}}async function G1(t){let e=t.logger??q;try{let n=await t.detectAll();e.info("refreshed frameworks_cache",{detected:Object.keys(n??{})})}catch(n){e.warn("framework detection failed (using cached)",{err:String(n)})}await z1(t.paths,t.core).catch(n=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(n)})),await ia(t.paths,t.agentManager).catch(n=>e.warn("auto-revive top-level error (ignored)",{err:String(n)})),await q1(t.paths).catch(n=>e.warn("builtin skill refresh top-level error (ignored)",{err:String(n)}))}async function ia(t,e){let{readdir:n}=await import("node:fs/promises"),i;try{i=await n(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(()=>(ln(),ws));q.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,l=0;for(let u of i){let h;try{h=await o(u,t)}catch(x){q.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(x)}),l+=1;continue}if(!h){l+=1;continue}if(h.deletedAt){q.info("auto-revive: skip deleted agent",{agentId:u,deletedAt:h.deletedAt}),l+=1;continue}if(h.disconnectedAt){q.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:h.disconnectedAt}),l+=1;continue}try{q.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:h.framework});let x=Zx(h);await e.createAgent({agentId:h.agentId,framework:h.framework,...h.cozeIdentity?{cozeIdentity:h.cozeIdentity}:{},...h.model?{model:h.model}:{},...x?{_meta:x}:{}},{revive:!0}),c+=1}catch(x){q.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:h.framework,err:String(x)}),l+=1}}return q.info("auto-revive: done",{revived:c,skipped:l,total:i.length}),{revived:c,skipped:l,total:i.length}}async function q1(t){let{readdir:e}=await import("node:fs/promises"),n;try{n=await e(t.agentsRoot)}catch{return{refreshed:0,total:0}}if(n.length===0)return{refreshed:0,total:0};let i=0;for(let o of n)try{(await u0(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:n.length}),{refreshed:i,total:n.length}}async function H1(t){let e=t.logger??q;if(t.cliSpawned)return"skipped-cli";let n=await t.readPatToken();return n?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:n}).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 Zx(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}ta();Oe();import{readFile as Yx}from"node:fs/promises";var Qt=class{paths;constructor(e){this.paths=e??ee()}async probe(e=1e3){let n=await sa(this.paths);if(!n)return{kind:"not-running"};try{let i=await this.fetch(n,{method:"GET",path:"/status",timeoutMs:e});return i.status===200?{kind:"connected",...n,body:i.body}:{kind:"stale",reason:`unexpected status ${i.status}`}}catch(i){return{kind:"stale",reason:W1(i)}}}async request(e){let n=await sa(this.paths);if(!n)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(n,e)}async fetch(e,n){let i=n.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,l=setTimeout(()=>c.abort(),n.timeoutMs??5e3);try{let u=await fetch(`http://127.0.0.1:${e.port}${n.path}`,{method:n.method,headers:o,body:i?JSON.stringify(n.body):void 0,signal:c.signal}),h=await u.text();return{status:u.status,body:j1(h)}}finally{clearTimeout(l)}}};async function sa(t){try{let[e,n]=await Promise.all([Yx(t.portFile,"utf8"),Yx(t.tokenFile,"utf8")]),i=Number.parseInt(e.trim(),10),o=n.trim();return!Number.isFinite(i)||i<=0||!o?null:{port:i,token:o}}catch(e){if(e.code==="ENOENT")return null;throw e}}function j1(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function W1(t){return t instanceof Error?t.message:String(t)}$t();ne();sr();import{spawn as K1}from"node:child_process";import{userInfo as Qx}from"node:os";var ql="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",$1=new Set(["bash","zsh","sh","dash","ksh"]),Xx=Ve("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),V1=2e3;function J1(t,e=ql){let n=t.indexOf(e);if(n===-1)return null;let i=t.indexOf(e,n+e.length);if(i===-1)return null;let o=t.slice(n+e.length,i),c={};for(let l of o.split(`
113
+ `)){let u=l.indexOf("=");u<=0||(c[l.slice(0,u)]=l.slice(u+1))}return c}function Z1(){let t=(process.env.SHELL??"").trim()||(Qx().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return $1.has(e)?t:null}function Y1(t){return new Promise(e=>{let n=`printf '%s' '${ql}'; env; printf '%s' '${ql}'`,i;try{i=K1(t,["-ilc",n],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??Qx().homedir}})}catch{e(null);return}let o="",c=!1,l=m=>{try{i.pid&&process.kill(-i.pid,m)}catch{}},u=m=>{c||(c=!0,clearTimeout(h),clearTimeout(x),e(m))};i.stdout?.on("data",m=>{o+=m.toString("utf8")}),i.on("error",()=>u(null)),i.on("close",()=>u(o.length>0?o:null));let h=setTimeout(()=>l("SIGTERM"),Xx),x=setTimeout(()=>{l("SIGKILL"),u(o.length>0?o:null)},Xx+V1)})}async function Hl(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let n=Z1();if(!n)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??Y1)(n);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=J1(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}Oe();function Cn(t,...e){let n=[],i;for(let o=0;o<t.length;o++){let c=t[o],l=!1;for(let u of e){if(c===u){i=t[o+1],o+=1,l=!0;break}if(c.startsWith(`${u}=`)){i=c.slice(u.length+1),l=!0;break}}l||n.push(c)}return{value:i,rest:n}}on();import{chmod as X1,copyFile as ep,mkdir as np,readFile as as,rename as tp,rm as Kl,stat as $l,writeFile as Q1}from"node:fs/promises";import{homedir as aD}from"node:os";import{dirname as eS,join as Ft,resolve as Vl,sep as os}from"node:path";import{fileURLToPath as tS}from"node:url";$t();ne();Oe();var $r=G("dist-install");function rp(){return{darwin:{arm64:"@zed-industries/codex-acp-darwin-arm64",x64:"@zed-industries/codex-acp-darwin-x64"},linux:{arm64:"@zed-industries/codex-acp-linux-arm64",x64:"@zed-industries/codex-acp-linux-x64"},win32:{arm64:"@zed-industries/codex-acp-win32-arm64",x64:"@zed-industries/codex-acp-win32-x64"}}[process.platform]?.[process.arch]}function nS(){return process.platform==="win32"?"codex-acp.exe":"codex-acp"}function rS(t){let e=tS(t),n=eS(e),i=`${os}src${os}`;if(n.includes(i)||n.endsWith(`${os}src${os}cli`))return null;let o=Vl(n,"index.js"),c=Vl(n,"..","package.json");return{dist:o,pkgJson:c}}async function Jl(t={}){let e=t.paths??ee(),n=rS(import.meta.url),i=t.sourceDist??n?.dist,o=t.sourcePackageJson??n?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,l;try{let v=JSON.parse(await as(o,"utf8"));c=v.version??"unknown",l=v.dependencies??{}}catch(v){return $r.warn("cannot read source package.json,skip dist install",{err:String(v)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(v)}`}}let u=xs.map(v=>({name:v,spec:l[v]??"latest"})),h=u.map(({name:v,spec:I})=>`${v}@${I}`),x=await To(e.configFile)??{},m=x.libVersion,_=await as(e.libEntry).then(()=>!0).catch(()=>!1),S=m===c,y=await ip(e,u);if(S&&_&&y)return{kind:"already-current",libVersion:c};if(!S||!_){await np(e.libDir,{recursive:!0}),await ep(i,e.libEntry),await ep(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let v=Vl(e.libDir,"package.json"),I=`${JSON.stringify({type:"module"},null,2)}
114
+ `;await as(v,"utf8").catch(()=>null)!==I&&await Q1(v,I)}return y||(t.installWrappers?await t.installWrappers(e,h):await sS(e,h,u)),x.libVersion=c,await Ki(x,e.configFile),$r.info("dist installed",{libEntry:e.libEntry,fromVersion:m,toVersion:c}),S&&_?{kind:"already-current",libVersion:c}:m?{kind:"version-changed",fromVersion:m,toVersion:c,libEntry:e.libEntry}:{kind:"first-install",libVersion:c,libEntry:e.libEntry}}async function ip(t,e){for(let n of e){let i=Ft(t.libDir,"node_modules",...n.name.split("/"),"package.json"),o;try{o=JSON.parse(await as(i,"utf8"))}catch(l){return $r.warn("wrapper not ready: package.json read failed",{package:n.name,expected:n.spec,pkgJson:i,err:String(l)}),!1}let c=o.version;if(!c)return $r.warn("wrapper not ready: package.json \u7F3A version",{package:n.name,expected:n.spec,pkgJson:i}),!1;if(!iS(c,n.spec))return $r.warn("wrapper not ready: installed version does not satisfy expected range",{package:n.name,installed:c,expected:n.spec}),!1}return!!await sp(Ft(t.libDir,"node_modules"))}function iS(t,e){let n=jl(t);if(!n)return!0;let i=e.trim();if(!i||i==="*"||i==="latest")return!0;if(i.startsWith("^")){let c=jl(i.slice(1));if(!c)return!0;if(Wl(n,c)<0)return!1;let l=c[0]>0?[c[0]+1,0,0]:c[1]>0?[0,c[1]+1,0]:[0,0,c[2]+1];return Wl(n,l)<0}let o=jl(i);return o?Wl(n,o)===0:!0}function jl(t){let e=t.match(/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?$/);return e?[Number(e[1]),Number(e[2]??0),Number(e[3]??0)]:null}function Wl(t,e){for(let n=0;n<3;n++){let i=(t[n]??0)-(e[n]??0);if(i!==0)return i}return 0}async function sS(t,e,n){await cS(t.installLock,async()=>{if(await ip(t,n))return;let i=Math.random().toString(36).slice(2,10),o=`${t.libDir}${os}.staging-${process.pid}-${i}`,c=Ft(o,"node_modules"),l=Ft(t.libDir,"node_modules");try{await np(o,{recursive:!0}),await oS(e,o),await aS(c);let u=`${l}.trash-${i}`;await tp(l,u).catch(()=>{}),await tp(c,l),await Kl(u,{recursive:!0,force:!0}).catch(()=>{}),$r.info("wrapper closure installed",{liveNm:l,specs:e})}finally{await Kl(o,{recursive:!0,force:!0}).catch(()=>{})}})}function oS(t,e){let n=["install",...t,"--prefix",e,"--omit=dev","--include=optional","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=rt("npm",n,{stdio:["ignore","pipe","pipe"]}),l="";c.stderr?.on("data",h=>{l.length<8192&&(l+=h.toString("utf8"))});let u=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",h=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(h)}`))}),c.once("close",h=>{clearTimeout(u),h===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${h}: ${l.trim().slice(0,2e3)}`))})})}async function aS(t){for(let e of xs){let n=Ft(t,...e.split("/")),i=JSON.parse(await as(Ft(n,"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=Ft(t,".bin",o),l=await $l(c);process.platform!=="win32"&&!(l.mode&73)&&await X1(c,l.mode|73).catch(()=>{})}if(!await sp(t)){let e=rp()??"<unsupported-platform>";throw new Error(`${e}: \u5F53\u524D\u5E73\u53F0 codex-acp binary \u7F3A\u5931`)}}async function sp(t){let e=rp();if(!e)return!0;let n=Ft(t,...e.split("/")),i=Ft(n,"package.json"),o=Ft(n,"bin",nS()),[c,l]=await Promise.all([$l(i).then(u=>u.isFile()).catch(()=>!1),$l(o).then(u=>u.isFile()).catch(()=>!1)]);return c&&l}async function cS(t,e){let{open:n}=await import("node:fs/promises"),i=!1;for(let o=0;o<60&&!i;o++)try{await(await n(t,"wx")).close(),i=!0}catch{await new Promise(c=>setTimeout(c,500))}try{return await e()}finally{i&&await Kl(t,{force:!0}).catch(()=>{})}}Ia();ne();Oe();import{closeSync as ap,fstatSync as cp,openSync as lp,readFileSync as lS,readSync as dS,readdirSync as uS,statSync as fS}from"node:fs";import{join as oa}from"node:path";var hS=new Set(["debug","info","warn","error"]);function dp(t){let e=t,n=Cn(e,"--agent-id");e=n.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 l=Cn(e,"--grep");e=l.rest;let u=o.value===void 0?200:Number(o.value),h=Number.isInteger(u)&&u>=0?u:200,x=c.value&&hS.has(c.value)?c.value:void 0,m={lines:h,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return n.value&&(m.agentId=n.value),i.value&&(m.date=i.value),x&&(m.level=x),l.value&&(m.grep=l.value),m}function xS(t,e){return t.agentId?oa(Je(t.agentId,e).logs,or("agent",t.date)):oa(e.bridgeLogsDir,or("bridge",t.date))}function pS(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function gS(t,e){let n;try{n=uS(t)}catch{return[]}let i=[];for(let o of n){let c=Sa(o,e);if(!c)continue;let l=0;try{l=fS(oa(t,o)).size}catch{}i.push({file:oa(t,o),date:c,size:l})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function up(t,e){if(e.grep&&!t.includes(e.grep))return!1;if(e.level){let n;try{n=JSON.parse(t).level}catch{return!0}if(typeof n=="string"&&!Id(n,e.level))return!1}return!0}var op={debug:"90",info:"36",warn:"33",error:"31"},mS=new Set(["ts","level","module","msg"]);function wS(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function fp(t,e){if(e.raw)return t;let n;try{n=JSON.parse(t)}catch{return t}let i=wS(n.ts),o=typeof n.level=="string"?n.level:"",c=o.toUpperCase().padEnd(5);e.color&&op[o]&&(c=`\x1B[${op[o]}m${c}\x1B[0m`);let l=typeof n.module=="string"?n.module:"",u=typeof n.msg=="string"?n.msg:"",h=Object.entries(n).filter(([x])=>!mS.has(x)).map(([x,m])=>` ${x}=${typeof m=="string"?m:JSON.stringify(m)}`).join("");return`${i} ${c} ${l} ${u}${h}`}function _S(t,e,n){let c=lS(t,"utf8").split(`
115
+ `).filter(l=>l.length>0).filter(l=>up(l,{level:e.level,grep:e.grep}));for(let l of pS(c,e.lines))process.stdout.write(`${fp(l,{raw:e.raw,color:n})}
116
+ `)}async function hp(t,e){let n=e.paths??ee(),i=process.stdout.isTTY===!0;if(t.list){let l=t.agentId?Je(t.agentId,n).logs:n.bridgeLogsDir,u=t.agentId?"agent":"bridge",h=gS(l,u);if(h.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${l}
117
+ `),1;for(let x of h)process.stdout.write(`${x.date} ${(x.size/1024).toFixed(1)}KB ${x.file}
118
+ `);return 0}let o=t.date??Dn(new Date),c=xS({agentId:t.agentId,date:o},n);try{_S(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
121
119
  \u7528 'coze-bridge log${t.agentId?` --agent-id ${t.agentId}`:""} --list' \u770B\u6709\u54EA\u4E9B\u65E5\u671F\u3002
122
- (legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${r.logFile})
123
- `),1}return t.follow&&await Z1(c,t,i),0}var V1=500;function J1(t){try{let e=yp(t,"r");try{return _p(e).size}finally{wp(e)}}catch{return 0}}async function Z1(t,e,r){let i=J1(t),o="",c=!1,d=()=>{c=!0};process.on("SIGINT",d);try{for(;!c;){let u="";try{let x=yp(t,"r");try{let h=_p(x).size;if(h>i){let p=Buffer.allocUnsafe(h-i),_=F1(x,p,0,p.length,i);u=p.subarray(0,_).toString("utf8"),i+=_}}finally{wp(x)}}catch{}if(u){let x=(o+u).split(`
124
- `);o=x.pop()??"";for(let h of x)h.length>0&&Ep(h,{level:e.level,grep:e.grep})&&process.stdout.write(`${vp(h,{raw:e.raw,color:r})}
125
- `)}await new Promise(x=>setTimeout(x,V1))}}finally{process.off("SIGINT",d)}}import{basename as X1,resolve as Y1}from"node:path";Pe();var Q1=9e4,e2={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,SKILL_NOT_FOUND:1,SKILL_ZIP_TOO_LARGE:1};function t2(t){return e2[t]??1}async function Ap(t,e={}){let r=e.paths??Y();if(!t.agentId||!t.sessionId)return process.stderr.write(`Error: missing --agent-id and/or --session-id. These IDs come from the <coze-context> block injected at the top of each prompt \u2014 extract agentId and sessionId from there and pass them as flags. Example: coze-bridge send image x.png --agent-id <id> --session-id <id>
120
+ (legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${n.logFile})
121
+ `),1}return t.follow&&await ES(c,t,i),0}var yS=500;function bS(t){try{let e=lp(t,"r");try{return cp(e).size}finally{ap(e)}}catch{return 0}}async function ES(t,e,n){let i=bS(t),o="",c=!1,l=()=>{c=!0};process.on("SIGINT",l);try{for(;!c;){let u="";try{let h=lp(t,"r");try{let x=cp(h).size;if(x>i){let m=Buffer.allocUnsafe(x-i),_=dS(h,m,0,m.length,i);u=m.subarray(0,_).toString("utf8"),i+=_}}finally{ap(h)}}catch{}if(u){let h=(o+u).split(`
122
+ `);o=h.pop()??"";for(let x of h)x.length>0&&up(x,{level:e.level,grep:e.grep})&&process.stdout.write(`${fp(x,{raw:e.raw,color:n})}
123
+ `)}await new Promise(h=>setTimeout(h,yS))}}finally{process.off("SIGINT",l)}}import{basename as vS,resolve as SS}from"node:path";Oe();var IS=9e4,AS={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,SKILL_NOT_FOUND:1,SKILL_ZIP_TOO_LARGE:1};function TS(t){return AS[t]??1}async function xp(t,e={}){let n=e.paths??ee();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>
126
124
  `),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.
127
- `),3;let i=await fa(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.
128
- `),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:Y1(process.cwd(),t.path),...t.caption?{caption:t.caption}:{},...t.name?{name:t.name}:{},...t.groupFile?{groupFile:!0}:{},...t.mimeType?{mimeType:t.mimeType}:{}},c;try{c=await n2(i,"/agent/send",o,Q1)}catch(d){return process.stderr.write(`Error: daemon IPC failed: ${d instanceof Error?d.message:String(d)}
125
+ `),3;let i=await sa(n).catch(()=>null);if(!i)return process.stderr.write(`Error: coze-bridge daemon not running (cannot read ${n.portFile} / ${n.tokenFile}). Make sure you are inside an agent session spawned by the daemon.
126
+ `),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:SS(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 kS(i,"/agent/send",o,IS)}catch(l){return process.stderr.write(`Error: daemon IPC failed: ${l instanceof Error?l.message:String(l)}
129
127
  `),4}if(!c.ok)return process.stderr.write(`Error: ${c.code}: ${c.message}
130
- `),t2(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
131
- `);else{let d=t.name??X1(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})
132
- `)}else process.stdout.write(`Sent ${t.kind} ${d} (${r2(c.bytes)})
133
- `)}return 0}async function n2(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(),x=u?JSON.parse(u):null;return x&&typeof x=="object"&&"ok"in x?x:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${d.status}): ${u.slice(0,200)}`}}finally{clearTimeout(c)}}function r2(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var Np=j("cli");function Ke(t,e){let{value:r,rest:i}=On(t,e);return{value:r,rest:i}}function _a(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
134
- `)}function k2(t){let e=t.slice(2);if(e.includes("--version")||e.includes("-v"))return{mode:"version"};if(e.includes("--daemon"))return{mode:"daemon"};if(e[0]==="status")return{mode:"status"};if(e[0]==="stop")return{mode:"stop"};if(e[0]==="reload"){let{value:O}=Ke(e.slice(1),"--agent-id");return O?{mode:"reload",agentId:O}:{mode:"reload"}}if(e[0]==="update")return{mode:"update"};if(e[0]==="purge")return{mode:"purge"};if(e[0]==="service")return e[1]==="install"?{mode:"service-install"}:e[1]==="uninstall"?{mode:"service-uninstall"}:{mode:"help"};if(e[0]==="send")return T2(e.slice(1));if(e[0]==="log")return{mode:"log",...bp(e.slice(1))};if(e[0]==="connect")return C2(e.slice(1));if(e.includes("--status"))return _a("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return _a("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return _a("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return _a("--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}=Ke(r,"--pat-token");r=o;let{value:c,rest:d}=Ke(r,"--pair-code");r=d;let{value:u,rest:x}=Ke(r,"--env");r=x;let{value:h,rest:p}=Ke(r,"--handshake-url");r=p;let{value:_,rest:S}=Ke(r,"--frontier-url");r=S;let{value:y,rest:v}=Ke(r,"--mock-scenario");r=v;let{value:A}=Ke(r,"--agent-id"),k=r.includes("--skip-rebuild-env");if(!i||!c)return{mode:"help"};let R={mode:"pair",privatecode:i,pairingCode:c};return u&&(R.env=u),h&&(R.handshakeUrl=h),_&&(R.frontierUrl=_),y&&(R.mockScenario=y),A&&(R.agentId=A),k&&(R.skipRebuildEnv=!0),R}function T2(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}=Ke(i,"--caption");i=c;let{value:d,rest:u}=Ke(i,"--name");i=u;let{value:x,rest:h}=Ke(i,"--agent-id");i=h;let{value:p,rest:_}=Ke(i,"--session-id");i=_;let{value:S,rest:y}=Ke(i,"--mime");i=y;let v=i.includes("--group-file");i=i.filter(R=>R!=="--group-file");let A=i.includes("--json"),k={mode:"send",kind:e,path:r,json:A};return o&&(k.caption=o),d&&(k.name=d),x&&(k.agentId=x),p&&(k.sessionId=p),v&&(k.groupFile=!0),S&&(k.mimeType=S),k}function C2(t){let e=t,{value:r,rest:i}=Ke(e,"--pat-token");e=i;let{value:o,rest:c}=Ke(e,"--env");e=c;let{value:d,rest:u}=Ke(e,"--handshake-url");e=u;let{value:x,rest:h}=Ke(e,"--frontier-url");e=h;let{value:p,rest:_}=Ke(e,"--mock-scenario");e=_;let S=e.includes("--skip-rebuild-env"),y={mode:"connect"};return r&&(y.privatecode=r),o&&(y.env=o),d&&(y.handshakeUrl=d),x&&(y.frontierUrl=x),p&&(y.mockScenario=p),S&&(y.skipRebuildEnv=!0),y}var R2=`
128
+ `),TS(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
129
+ `);else{let l=t.name??vS(o.path);if(t.groupFile){let u=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${l} (uri=${u})
130
+ `)}else process.stdout.write(`Sent ${t.kind} ${l} (${RS(c.bytes)})
131
+ `)}return 0}async function kS(t,e,n,i){let o=new AbortController,c=setTimeout(()=>o.abort(),i);try{let l=await fetch(`http://127.0.0.1:${t.port}${e}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"content-type":"application/json"},body:JSON.stringify(n),signal:o.signal}),u=await l.text(),h=u?JSON.parse(u):null;return h&&typeof h=="object"&&"ok"in h?h:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${l.status}): ${u.slice(0,200)}`}}finally{clearTimeout(c)}}function RS(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var Sp=G("cli");function je(t,e){let{value:n,rest:i}=Cn(t,e);return{value:n,rest:i}}function fa(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
132
+ `)}function QS(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:P}=je(e.slice(1),"--agent-id");return P?{mode:"reload",agentId:P}:{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 e2(e.slice(1));if(e[0]==="log")return{mode:"log",...dp(e.slice(1))};if(e[0]==="connect")return t2(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 n=e,{value:i,rest:o}=je(n,"--pat-token");n=o;let{value:c,rest:l}=je(n,"--pair-code");n=l;let{value:u,rest:h}=je(n,"--env");n=h;let{value:x,rest:m}=je(n,"--handshake-url");n=m;let{value:_,rest:S}=je(n,"--frontier-url");n=S;let{value:y,rest:v}=je(n,"--mock-scenario");n=v;let{value:I}=je(n,"--agent-id"),A=n.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),_&&(k.frontierUrl=_),y&&(k.mockScenario=y),I&&(k.agentId=I),A&&(k.skipRebuildEnv=!0),k}function e2(t){let e=t[0],n=t[1];if(e!=="image"&&e!=="file")return{mode:"help"};if(!n||n.startsWith("--"))return{mode:"help"};let i=t.slice(2),{value:o,rest:c}=je(i,"--caption");i=c;let{value:l,rest:u}=je(i,"--name");i=u;let{value:h,rest:x}=je(i,"--agent-id");i=x;let{value:m,rest:_}=je(i,"--session-id");i=_;let{value:S,rest:y}=je(i,"--mime");i=y;let v=i.includes("--group-file");i=i.filter(k=>k!=="--group-file");let I=i.includes("--json"),A={mode:"send",kind:e,path:n,json:I};return o&&(A.caption=o),l&&(A.name=l),h&&(A.agentId=h),m&&(A.sessionId=m),v&&(A.groupFile=!0),S&&(A.mimeType=S),A}function t2(t){let e=t,{value:n,rest:i}=je(e,"--pat-token");e=i;let{value:o,rest:c}=je(e,"--env");e=c;let{value:l,rest:u}=je(e,"--handshake-url");e=u;let{value:h,rest:x}=je(e,"--frontier-url");e=x;let{value:m,rest:_}=je(e,"--mock-scenario");e=_;let S=e.includes("--skip-rebuild-env"),y={mode:"connect"};return n&&(y.privatecode=n),o&&(y.env=o),l&&(y.handshakeUrl=l),h&&(y.frontierUrl=h),m&&(y.mockScenario=m),S&&(y.skipRebuildEnv=!0),y}var n2=`
135
133
  coze-bridge - local bridge daemon for cloud Agent Service
136
134
 
137
135
  Pair (paste from cloud UI; start/reuse daemon and deliver pair-code):
@@ -212,57 +210,57 @@ Deprecated flags (still work, but emit a warning; will be removed in a future re
212
210
 
213
211
  Internal:
214
212
  <node> <entry> --daemon daemon mode (OS supervisor only)
215
- `.trimStart();async function Mp(t=process.argv,e={}){let r=k2(t);switch(r.mode){case"help":return process.stdout.write(R2),0;case"version":return process.stdout.write(`${Ot}
216
- `),0;case"daemon":{try{await op()}catch(i){return Np.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return D2(e);case"stop":return Fp(e);case"reload":return L2(r.agentId,e);case"log":return Sp(r,e);case"update":return P2(e);case"purge":return M2(e);case"service-install":return B2(e);case"service-uninstall":return F2(e);case"pair":{let i={};return r.env&&(i.env=r.env),r.handshakeUrl&&(i.handshakeUrl=r.handshakeUrl),r.frontierUrl&&(i.frontierUrl=r.frontierUrl),r.mockScenario&&(i.mockScenario=r.mockScenario),z2(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),U2(r.privatecode,e,i,r.skipRebuildEnv)}case"send":return Ap({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 Bp(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 D2(t){let e=t.paths??Y(),r=new tn(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
217
- `),1;if(i.kind==="stale")return await Bp(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
218
- `),1;let o=await r.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
213
+ `.trimStart();async function Ip(t=process.argv,e={}){let n=QS(t);switch(n.mode){case"help":return process.stdout.write(n2),0;case"version":return process.stdout.write(`${Pt}
214
+ `),0;case"daemon":{try{await Jx()}catch(i){return Sp.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return r2(e);case"stop":return Tp(e);case"reload":return o2(n.agentId,e);case"log":return hp(n,e);case"update":return i2(e);case"purge":return c2(e);case"service-install":return l2(e);case"service-uninstall":return d2(e);case"pair":{let i={};return n.env&&(i.env=n.env),n.handshakeUrl&&(i.handshakeUrl=n.handshakeUrl),n.frontierUrl&&(i.frontierUrl=n.frontierUrl),n.mockScenario&&(i.mockScenario=n.mockScenario),u2(n.privatecode,n.pairingCode,e,i,n.agentId,n.skipRebuildEnv)}case"connect":{let i={};return n.env&&(i.env=n.env),n.handshakeUrl&&(i.handshakeUrl=n.handshakeUrl),n.frontierUrl&&(i.frontierUrl=n.frontierUrl),n.mockScenario&&(i.mockScenario=n.mockScenario),f2(n.privatecode,e,i,n.skipRebuildEnv)}case"send":return xp({kind:n.kind,path:n.path,...n.agentId?{agentId:n.agentId}:{},...n.sessionId?{sessionId:n.sessionId}:{},...n.caption?{caption:n.caption}:{},...n.name?{name:n.name}:{},...n.groupFile?{groupFile:!0}:{},...n.mimeType?{mimeType:n.mimeType}:{},json:n.json},e)}}async function Ap(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 r2(t){let e=t.paths??ee(),n=new Qt(e),i=await n.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
215
+ `),1;if(i.kind==="stale")return await Ap(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
216
+ `),1;let o=await n.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
219
217
  ${JSON.stringify(o.body,null,2)}
220
- `),0}async function Fp(t){let e=t.paths??Y(),r=new tn(e),i=t.daemonSweep??(async()=>{let x=L0();return await N0(x),x}),o=async()=>{t.skipProcessKill||await i(e)},c=await us(t),d=!1;if(c)try{await c.uninstall(),d=!0}catch(x){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(x)}
221
- `)}let u=await r.probe();if(u.kind==="not-running")return await o(),process.stdout.write(d?`coze-bridge: stopped
218
+ `),0}async function Tp(t){let e=t.paths??ee(),n=new Qt(e),i=t.daemonSweep??(async()=>{let h=I0();return await A0(h),h}),o=async()=>{t.skipProcessKill||await i(e)},c=await ls(t),l=!1;if(c)try{await c.uninstall(),l=!0}catch(h){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(h)}
219
+ `)}let u=await n.probe();if(u.kind==="not-running")return await o(),process.stdout.write(l?`coze-bridge: stopped
222
220
  `:`coze-bridge: not running
223
- `),0;if(u.kind==="stale")return await Bp(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
224
- `),0;try{return await r.request({method:"POST",path:"/shutdown"}),await o(),process.stdout.write(`coze-bridge: stopped
225
- `),0}catch(x){return(await r.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
226
- `),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(x)}
227
- `),1)}}async function P2(t){return await Fp(t),(t.spawnNpx??O2)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function O2(t){return new Promise(e=>{let r=it("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)}
228
- `),e(1)})})}async function L2(t,e){let r=new tn(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
229
- `),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)
221
+ `),0;if(u.kind==="stale")return await Ap(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
222
+ `),0;try{return await n.request({method:"POST",path:"/shutdown"}),await o(),process.stdout.write(`coze-bridge: stopped
223
+ `),0}catch(h){return(await n.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
224
+ `),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(h)}
225
+ `),1)}}async function i2(t){return await Tp(t),(t.spawnNpx??s2)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function s2(t){return new Promise(e=>{let n=rt("npx",t,{stdio:"inherit"});n.on("exit",i=>e(i??1)),n.on("error",i=>{process.stderr.write(`coze-bridge: spawn npx failed: ${String(i)}
226
+ `),e(1)})})}async function o2(t,e){let n=new Qt(e.paths);if((await n.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
227
+ `),1;try{let o=await n.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)
230
228
  `):process.stdout.write(`coze-bridge: reloaded ${c.length} agent(s): ${c.join(", ")||"(none)"}
231
229
  `),0}return process.stderr.write(`coze-bridge: reload failed: ${JSON.stringify(o.body)}
232
230
  `),1}catch(o){return process.stderr.write(`coze-bridge: reload failed: ${String(o)}
233
- `),1}}async function us(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(()=>(Pp(),Dp)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function zp(t,e){let r=await e.probe(),i=t.waitTimeoutMs??15e3,o=t.sleep??H2,c=t.paths??Y();if(r.kind==="connected"){if(!N2(r.body))return r;ut(c.bridgeLogsDir,"warn","cli","daemon Node \u4E0E\u5F53\u524D CLI \u4E0D\u4E00\u81F4, \u91CD\u542F daemon",{currentNode:process.execPath,currentArch:process.arch,daemon:r.body}),await e.request({method:"POST",path:"/shutdown"}).catch(x=>ut(c.bridgeLogsDir,"warn","cli","restart for Node drift: shutdown failed",{err:String(x)})),await Lp(c.pidFile,o)}let d=t.spawnDaemon??ip,u=await us(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let x=await Op(e,i,o);if(x.kind==="connected")return x;ut(c.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:i})}catch(x){ut(c.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(x)})}ut(c.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 Lp(c.pidFile,o)}else u&&await u.install({activate:!1}).catch(x=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(x)}
231
+ `),1}}async function ls(t){if(t.supervisor){let c=t.supervisor,l={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:u=>c.install(l,u),uninstall:()=>c.uninstall(l)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:n}=await Promise.resolve().then(()=>(bp(),yp)),i=e(),o=n();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function kp(t,e){let n=await e.probe(),i=t.waitTimeoutMs??15e3,o=t.sleep??h2,c=t.paths??ee();if(n.kind==="connected"){if(!a2(n.body))return n;lt(c.bridgeLogsDir,"warn","cli","daemon Node \u4E0E\u5F53\u524D CLI \u4E0D\u4E00\u81F4, \u91CD\u542F daemon",{currentNode:process.execPath,currentArch:process.arch,daemon:n.body}),await e.request({method:"POST",path:"/shutdown"}).catch(h=>lt(c.bridgeLogsDir,"warn","cli","restart for Node drift: shutdown failed",{err:String(h)})),await vp(c.pidFile,o)}let l=t.spawnDaemon??$x,u=await ls(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let h=await Ep(e,i,o);if(h.kind==="connected")return h;lt(c.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:i})}catch(h){lt(c.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(h)})}lt(c.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 vp(c.pidFile,o)}else u&&await u.install({activate:!1}).catch(h=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(h)}
234
232
  `));return process.stdout.write(`coze-bridge: starting daemon...
235
- `),await d({paths:t.paths}),Op(e,i,o)}function N2(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.nodeExecPath!="string"||typeof e.nodeArch!="string"?!1:e.nodeExecPath!==process.execPath||e.nodeArch!==process.arch}async function M2(t){let e=new tn(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
236
- `);try{await e.request({method:"POST",path:"/shutdown"})}catch(d){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(d)}
237
- `)}await new Promise(d=>setTimeout(d,500))}let i=await us(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
238
- `)}catch(d){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(d)}
239
- `)}let o=t.paths??Y(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
240
- `)}catch(d){return process.stderr.write(`coze-bridge: remove failed: ${String(d)}
233
+ `),await l({paths:t.paths}),Ep(e,i,o)}function a2(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.nodeExecPath!="string"||typeof e.nodeArch!="string"?!1:e.nodeExecPath!==process.execPath||e.nodeArch!==process.arch}async function c2(t){let e=new Qt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
234
+ `);try{await e.request({method:"POST",path:"/shutdown"})}catch(l){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(l)}
235
+ `)}await new Promise(l=>setTimeout(l,500))}let i=await ls(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
236
+ `)}catch(l){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(l)}
237
+ `)}let o=t.paths??ee(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
238
+ `)}catch(l){return process.stderr.write(`coze-bridge: remove failed: ${String(l)}
241
239
  `),1}return process.stdout.write(`coze-bridge: purged (agents workspaces preserved under ~/.coze/agents)
242
- `),0}async function B2(t){let e=await us(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
240
+ `),0}async function l2(t){let e=await ls(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
243
241
  `),await e.install(),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
244
- `),0}catch(r){return process.stderr.write(`coze-bridge: service install failed: ${String(r)}
245
- `),1}}async function F2(t){let e=await us(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
246
- `),0}catch(r){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(r)}
247
- `),1}}async function Up(t,e,r){if(e)return ut(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await r();return i.kind==="ok"?(ut(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(ut(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)
248
- `),ut(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function z2(t,e,r,i={},o,c){let d=new tn(r.paths),u=r.paths??Y(),x=await Up(u,c,r.reconstructEnv??tl);if(await ld(u,x).catch(_=>ut(u.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(_)})),!r.skipDistInstall){let _=await al({paths:r.paths});_.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${_.fromVersion} \u2192 ${_.toVersion}
249
- `),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(y=>setTimeout(y,500)))):_.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${_.libVersion}
250
- `)}let h=await zp(r,d);if(h.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${h.kind}
251
- `),1;let p={privatecode:t,pairing_code:e};i.env&&(p.env=i.env),i.handshakeUrl&&(p.handshake_url=i.handshakeUrl),i.frontierUrl&&(p.frontier_url=i.frontierUrl),i.mockScenario&&(p.mock_scenario=i.mockScenario),o&&(p.agent_id=o);try{let _=await d.request({method:"POST",path:"/pair",body:p,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}
242
+ `),0}catch(n){return process.stderr.write(`coze-bridge: service install failed: ${String(n)}
243
+ `),1}}async function d2(t){let e=await ls(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
244
+ `),0}catch(n){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(n)}
245
+ `),1}}async function Rp(t,e,n){if(e)return lt(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await n();return i.kind==="ok"?(lt(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(lt(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)
246
+ `),lt(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function u2(t,e,n,i={},o,c){let l=new Qt(n.paths),u=n.paths??ee(),h=await Rp(u,c,n.reconstructEnv??Hl);if(await nl(u,h).catch(_=>lt(u.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(_)})),!n.skipDistInstall){let _=await Jl({paths:n.paths});_.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${_.fromVersion} \u2192 ${_.toVersion}
247
+ `),(await l.probe()).kind==="connected"&&(await l.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(y=>setTimeout(y,500)))):_.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${_.libVersion}
248
+ `)}let x=await kp(n,l);if(x.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${x.kind}
249
+ `),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 l.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}
252
250
  `),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"
253
251
  `),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(_.body)}
254
252
  `),1}catch(_){return process.stderr.write(`coze-bridge: pair failed: ${String(_)}
255
- `),1}}async function U2(t,e,r={},i){let o=e.paths??Y(),c=t??await sa(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 tn(e.paths),u=await Up(o,i,e.reconstructEnv??tl);if(await ld(o,u).catch(p=>ut(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(p)})),!e.skipDistInstall){let p=await al({paths:e.paths});p.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${p.fromVersion} \u2192 ${p.toVersion}
256
- `),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(S=>setTimeout(S,500)))):p.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${p.libVersion}
257
- `)}let x=await zp(e,d);if(x.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${x.kind}
258
- `),1;let h={privatecode:c};r.env&&(h.env=r.env),r.handshakeUrl&&(h.handshake_url=r.handshakeUrl),r.frontierUrl&&(h.frontier_url=r.frontierUrl),r.mockScenario&&(h.mock_scenario=r.mockScenario);try{let p=await d.request({method:"POST",path:"/connect",body:h,timeoutMs:35e3});return p.status===200&&p.body?.ok?(process.stdout.write(`coze-bridge: connected (${p.body.note??"ok"})
259
- `),t!==void 0&&await os(c,o).catch(_=>Np.warn("writePatToken after connect failed (ignored)",{err:String(_)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(p.body)}
260
- `),1)}catch(p){return process.stderr.write(`coze-bridge: connect failed: ${String(p)}
261
- `),1}}async function Op(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 Lp(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||!ji(u))return;await e(i)}}function H2(t){return new Promise(e=>setTimeout(e,t))}ie();function G2(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 Hp(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=G2(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
262
- `),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
253
+ `),1}}async function f2(t,e,n={},i){let o=e.paths??ee(),c=t??await Xo(o);if(!c)return process.stderr.write("coze-bridge: \u627E\u4E0D\u5230 patToken \u2014 \u5148\u8DD1\u4E00\u6B21 `coze-bridge --pat-token=<sat_xxx> --pair-code=<xxx>` \u914D\u5BF9, \u6216\u672C\u6B21\u7528 `--pat-token` \u6307\u5B9A\n"),1;let l=new Qt(e.paths),u=await Rp(o,i,e.reconstructEnv??Hl);if(await nl(o,u).catch(m=>lt(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(m)})),!e.skipDistInstall){let m=await Jl({paths:e.paths});m.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${m.fromVersion} \u2192 ${m.toVersion}
254
+ `),(await l.probe()).kind==="connected"&&(await l.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}
255
+ `)}let h=await kp(e,l);if(h.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${h.kind}
256
+ `),1;let x={privatecode:c};n.env&&(x.env=n.env),n.handshakeUrl&&(x.handshake_url=n.handshakeUrl),n.frontierUrl&&(x.frontier_url=n.frontierUrl),n.mockScenario&&(x.mock_scenario=n.mockScenario);try{let m=await l.request({method:"POST",path:"/connect",body:x,timeoutMs:35e3});return m.status===200&&m.body?.ok?(process.stdout.write(`coze-bridge: connected (${m.body.note??"ok"})
257
+ `),t!==void 0&&await is(c,o).catch(_=>Sp.warn("writePatToken after connect failed (ignored)",{err:String(_)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(m.body)}
258
+ `),1)}catch(m){return process.stderr.write(`coze-bridge: connect failed: ${String(m)}
259
+ `),1}}async function Ep(t,e,n){let i=Date.now()+e;for(;Date.now()<i;){let o=await t.probe(500);if(o.kind==="connected")return o;await n(200)}return t.probe(500)}async function vp(t,e,n=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let c=0;c<n;c++){let l;try{l=await o(t,"utf8")}catch{return}let u=Number.parseInt(l.trim(),10);if(!Number.isFinite(u)||u<=0||!qi(u))return;await e(i)}}function h2(t){return new Promise(e=>setTimeout(e,t))}ne();function x2(t){let e=/^v?(\d+)(?:\.(\d+))?/.exec(t.trim());if(!e)return"ok";let n=Number(e[1]),i=Number(e[2]??0);return n<18||n===18&&i<4?"fatal":n<20?"warn":"ok"}function Cp(t=process.versions.node,e=i=>{process.stderr.write(i)},n=i=>process.exit(i)){let i=x2(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
260
+ `),n(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
263
261
  \u5347\u7EA7\u5B8C\u540E\u9700\u8981\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u91CD\u65B0\u8FDE\u63A5:
264
262
  npx -y coze-bridge@latest stop
265
263
  npx -y coze-bridge@latest connect
266
264
 
267
- `)}Hp();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&Ol("warn");Mp(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
265
+ `)}Cp();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&vd("warn");Ip(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
268
266
  `),process.exit(1)});