coze-bridge 0.1.102 → 0.1.103-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +79 -84
  2. package/package.json +4 -3
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 Vp=Object.create;var wa=Object.defineProperty;var Jp=Object.getOwnPropertyDescriptor;var Zp=Object.getOwnPropertyNames;var Yp=Object.getPrototypeOf,Xp=Object.prototype.hasOwnProperty;var ce=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Je=(t,e)=>()=>(t&&(e=t(t=0)),e);var ie=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),_a=(t,e)=>{for(var r in e)wa(t,r,{get:e[r],enumerable:!0})},Qp=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Zp(e))!Xp.call(t,o)&&o!==r&&wa(t,o,{get:()=>e[o],enumerable:!(i=Jp(e,o))||i.enumerable});return t};var St=(t,e,r)=>(r=t!=null?Vp(Yp(t)):{},Qp(e||!t||!t.__esModule?wa(r,"default",{value:t,enumerable:!0}):r,t));function Ge(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Xn=Je(()=>{"use strict"});import{createWriteStream as eg,mkdirSync as tg,readdirSync as ng,unlinkSync as rg}from"node:fs";import{join as ad}from"node:path";function An(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function Qn(t,e){return`${t}-${e}.log`}function ya(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function ig(t,e,r){let i=c=>{let[l,u,f]=c.split("-").map(Number);return Date.UTC(l??0,(u??1)-1,f??1)};return Math.floor((i(e)-i(t))/864e5)>r}function ts(t,e,r,i){let o;try{o=ng(t)}catch{return}for(let c of o){let l=ya(c,e);if(l&&ig(l,r,i))try{rg(ad(t,c))}catch{}}}var Vr,Ea=Je(()=>{"use strict";Vr=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>An(new Date))}dir;prefix;opts;currentDate;stream;clock;write(e){let r=this.clock();r!==this.currentDate&&this.rotate(r),this.stream?.write(e)}rotate(e){this.stream?.end();try{tg(this.dir,{recursive:!0});let r=eg(ad(this.dir,Qn(this.prefix,e)),{flags:"a"});r.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
8
+ var Vp=Object.create;var ma=Object.defineProperty;var Yp=Object.getOwnPropertyDescriptor;var Zp=Object.getOwnPropertyNames;var Xp=Object.getPrototypeOf,Qp=Object.prototype.hasOwnProperty;var de=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ve=(t,e)=>()=>(t&&(e=t(t=0)),e);var se=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),wa=(t,e)=>{for(var r in e)ma(t,r,{get:e[r],enumerable:!0})},eg=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Zp(e))!Qp.call(t,o)&&o!==r&&ma(t,o,{get:()=>e[o],enumerable:!(i=Yp(e,o))||i.enumerable});return t};var St=(t,e,r)=>(r=t!=null?Vp(Xp(t)):{},eg(e||!t||!t.__esModule?ma(r,"default",{value:t,enumerable:!0}):r,t));function Ye(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Kr=Ve(()=>{"use strict"});import{createWriteStream as tg,mkdirSync as ng,readdirSync as rg,unlinkSync as ig}from"node:fs";import{join as al}from"node:path";function An(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function Xn(t,e){return`${t}-${e}.log`}function _a(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function sg(t,e,r){let i=c=>{let[l,u,h]=c.split("-").map(Number);return Date.UTC(l??0,(u??1)-1,h??1)};return Math.floor((i(e)-i(t))/864e5)>r}function Qi(t,e,r,i){let o;try{o=rg(t)}catch{return}for(let c of o){let l=_a(c,e);if(l&&sg(l,r,i))try{ig(al(t,c))}catch{}}}var $r,ya=Ve(()=>{"use strict";$r=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>An(new Date))}dir;prefix;opts;currentDate;stream;clock;write(e){let r=this.clock();r!==this.currentDate&&this.rotate(r),this.stream?.write(e)}rotate(e){this.stream?.end();try{ng(this.dir,{recursive:!0});let r=tg(al(this.dir,Xn(this.prefix,e)),{flags:"a"});r.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
9
9
  `)),this.stream=r}catch(r){process.stderr.write(`[log-sink] rotate failed: ${String(r)}
10
- `),this.stream=void 0;return}this.currentDate!==void 0&&ts(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 sg,mkdirSync as og}from"node:fs";import{join as ag}from"node:path";function ld(t){let e=t.retentionDays??dg,r=t.clock??(()=>An(new Date));rs={bridgeSink:new Vr(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new Vr(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();ts(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])ts(t.agentLogsDir(o),"agent",i,e)}function ug(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function dd(t){ba=t}function ud(t){return er[ba]<=er[t]}function fd(t,e){let r=er[t];return r===void 0?!0:r>=er[e]}function is(t){cd={...t}}function hd(t){let e=(u,f=2)=>String(u).padStart(f,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),l=e(o%60);return`${An(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${l}`}function It(t,e,r,i,o){try{let c=`${JSON.stringify({ts:hd(new Date),level:e,module:r,msg:i,...o})}
11
- `;og(t,{recursive:!0}),sg(ag(t,Qn("bridge",An(new Date))),c)}catch{}}function fg(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function ns(t,e,r,i,o){if(er[t]<er[ba])return;let c=`${JSON.stringify({ts:hd(new Date),level:t,module:e,msg:r,...cd,...i})}
12
- `;if(rs){let l=fg(o,i),u=l?ug(rs,l):rs.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?lg.write(c):cg.write(c)}function H(t,e){return{debug:(r,i)=>ns("debug",t,r,i,e),info:(r,i)=>ns("info",t,r,i,e),warn:(r,i)=>ns("warn",t,r,i,e),error:(r,i)=>ns("error",t,r,i,e),child:r=>H(`${t}.${r}`,e),forAgent:r=>H(t,r)}}var er,ba,cg,lg,cd,dg,rs,ee=Je(()=>{"use strict";Xn();Ea();er={debug:10,info:20,warn:30,error:40},ba=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),cg=process.stdout,lg=process.stderr,cd={},dg=Ge("COZE_BRIDGE_LOG_RETENTION_DAYS",30),rs=null});var C,We=Je(()=>{"use strict";C=class extends Error{code;retriable;cause;constructor(e,r,i){super(r),this.name="BridgeError",this.code=e,this.retriable=i?.retriable??!1,i?.cause!==void 0&&(this.cause=i.cause)}}});var md={};_a(md,{ACP_WRAPPER_NPM_PACKAGES:()=>Zr,_resetAcpInstallerForTests:()=>wg,_setBinaryPathCacheForTests:()=>_g,buildAcpSpawn:()=>Yr,ensureAcpInstalled:()=>tr,getAcpBinaryPath:()=>ss,pickWhichLine:()=>Ia,probeAcpVersion:()=>mg,resolveAcpCommand:()=>gd});import{readFileSync as xd}from"node:fs";import{createRequire as hg}from"node:module";import{dirname as xg,resolve as pg}from"node:path";function Ia(t){let e=t.split(/\r?\n/).map(i=>i.trim()).filter(Boolean);if(e.length===0)return;if(process.platform!=="win32")return e[0];let r=i=>e.find(o=>o.toLowerCase().endsWith(i));return r(".cmd")??r(".exe")??r(".bat")??r(".ps1")??e[0]}function gg(t){let e=pd.resolve(`${t.npmPackage}/package.json`),r=xg(e),i=JSON.parse(xd(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 pg(r,o)}async function tr(t,e){let r=Sa[t];if(!r)throw new C("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=Jr.get(t);if(i)return i;try{let o=gg(r);return Jr.set(t,o),va.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw va.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:r.npmPackage,err:String(o)}),new C("AGENT_DEPENDENCY_INSTALL_FAILED",[`ACP wrapper \u672A\u5C31\u7EEA: ${r.npmPackage} (framework=${t})`,"\u8BE5 wrapper \u968F coze-bridge \u4E00\u8D77\u5B89\u88C5 (\u56FA\u5316\u5230 ~/.coze/bridge/lib/node_modules)\u3002","\u8BF7\u91CD\u8DD1 `coze-bridge pair` / `connect` \u89E6\u53D1\u56FA\u5316\u5B89\u88C5; \u82E5\u4ECD\u5931\u8D25, \u68C0\u67E5\u7F51\u7EDC / npm \u7F13\u5B58\u3002"].join(`
13
- `),{cause:o})}}async function mg(t){let e=Sa[t];if(e)try{let r=pd.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(xd(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){va.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function ss(t){return Jr.get(t)}function gd(t,e){if(e)return e;let r=ss(t);if(!r)throw new C("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return r}function Yr(t,e,r){if(e)return{command:e,args:[...r]};let i=gd(t);return{command:process.execPath,args:[i,...r]}}function wg(){Jr.clear()}function _g(t,e){Jr.set(t,e)}var va,Sa,Zr,pd,Jr,nn=Je(()=>{"use strict";We();ee();va=H("agents.acp-installer"),Sa={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},Zr=Object.values(Sa).filter(t=>t!==void 0).map(t=>t.npmPackage),pd=hg(import.meta.url),Jr=new Map});import{chmod as Eg,mkdir as bg,readFile as vg,rename as yd,writeFile as Ed}from"node:fs/promises";import{dirname as Sg}from"node:path";async function nr(t){try{let e=await vg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function rr(t,e,r){await bg(Sg(t),{recursive:!0});let i=`${JSON.stringify(e,null,2)}
14
- `,o=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{r?.mode!==void 0?await Ed(o,i,{encoding:"utf8",mode:r.mode}):await Ed(o,i,"utf8"),await yd(o,t),r?.mode!==void 0&&await Eg(t,r.mode)}catch(c){await yd(o,o).catch(()=>{});let{rm:l}=await import("node:fs/promises");throw await l(o,{force:!0}).catch(()=>{}),c}}var Xr=Je(()=>{"use strict"});import{promises as bd,readdirSync as Ig}from"node:fs";import{homedir as Ag}from"node:os";import{sep as Tg,join as Ae,resolve as vd}from"node:path";function X(t){let e=t??Ag(),r=Ae(e,".coze"),i=Ae(r,"bridge"),o=Ae(i,"lib"),c=Ae(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Ae(o,"index.js"),binDir:Ae(i,"bin"),pidFile:Ae(i,"bridge.pid"),portFile:Ae(i,"bridge.port"),tokenFile:Ae(i,"bridge.token"),patTokenFile:Ae(i,"pat-token"),agentEnvFile:Ae(i,"agent-env.json"),logFile:Ae(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Ae(c,"daemon-stdio.log"),installLock:Ae(i,"install.lock"),configFile:Ae(i,"config.json"),agentsRoot:Ae(r,"agents")}}function Ze(t,e=X()){let r=Ae(e.agentsRoot,t);return{root:r,config:Ae(r,"config.json"),workspace:Ae(r,"workspace"),logs:Ae(r,"logs")}}function os(t=X()){try{return Ig(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function Qr(t,e){let r=await bd.realpath(vd(t)).catch(()=>null);if(!r)return!1;let i=await bd.realpath(vd(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+Tg)}var ke=Je(()=>{"use strict"});var ls={};_a(ls,{AGENT_CONFIG_FILE_MODE:()=>as,enforceAgentConfigMode:()=>Dg,loadAgentConfig:()=>He,persistAgentSessions:()=>ei,persistAgentSkills:()=>cs,saveAgentConfig:()=>Ye});import{chmod as Cg,stat as Rg}from"node:fs/promises";function He(t,e){return nr(Ze(t,e).config)}function Ye(t,e){return rr(Ze(t.agentId,e).config,t,{mode:as})}async function Dg(t,e){if(process.platform==="win32")return;let r=Ze(t,e).config;try{let i=await Rg(r);if(!i.isFile())return;let o=i.mode&511;o!==as&&(await Cg(r,as),Sd.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Sd.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function ei(t,e,r){let i=await He(t,r);i&&(i.sessions=Object.fromEntries(e),await Ye(i,r))}async function cs(t,e,r){let i=await He(t,r);i&&(i.skills=e,await Ye(i,r))}var Sd,as,rn=Je(()=>{"use strict";Xr();ee();ke();Sd=H("agent-config"),as=384});var Ta=ie((u2,Cd)=>{Cd.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 us=ie(Dd=>{var Rd={INVALID_LOC:"Invalid LOC header (bad signature)",INVALID_CEN:"Invalid CEN header (bad signature)",INVALID_END:"Invalid END header (bad signature)",DESCRIPTOR_NOT_EXIST:"No descriptor present",DESCRIPTOR_UNKNOWN:"Unknown descriptor format",DESCRIPTOR_FAULTY:"Descriptor data is malformed",NO_DATA:"Nothing to decompress",BAD_CRC:"CRC32 checksum failed {0}",FILE_IN_THE_WAY:"There is a file in the way: {0}",UNKNOWN_METHOD:"Invalid/unsupported compression method",AVAIL_DATA:"inflate::Available inflate data did not terminate",INVALID_DISTANCE:"inflate::Invalid literal/length or distance code in fixed or dynamic block",TO_MANY_CODES:"inflate::Dynamic block code description: too many length or distance codes",INVALID_REPEAT_LEN:"inflate::Dynamic block code description: repeat more than specified lengths",INVALID_REPEAT_FIRST:"inflate::Dynamic block code description: repeat lengths with no first length",INCOMPLETE_CODES:"inflate::Dynamic block code description: code lengths codes incomplete",INVALID_DYN_DISTANCE:"inflate::Dynamic block code description: invalid distance code lengths",INVALID_CODES_LEN:"inflate::Dynamic block code description: invalid literal/length code lengths",INVALID_STORE_BLOCK:"inflate::Stored block length did not match one's complement",INVALID_BLOCK_TYPE:"inflate::Invalid block type (type == 3)",CANT_EXTRACT_FILE:"Could not extract the file",CANT_OVERRIDE:"Target file already exists",DISK_ENTRY_TOO_LARGE:"Number of disk entries is too large",NO_ZIP:"No zip file was loaded",NO_ENTRY:"Entry doesn't exist",DIRECTORY_CONTENT_ERROR:"A directory cannot have content",FILE_NOT_FOUND:'File not found: "{0}"',NOT_IMPLEMENTED:"Not implemented",INVALID_FILENAME:"Invalid filename",INVALID_FORMAT:"Invalid or unsupported zip format. No END header found",INVALID_PASS_PARAM:"Incompatible password parameter",WRONG_PASSWORD:"Wrong Password",COMMENT_TOO_LONG:"Comment is too long",EXTRA_FIELD_PARSE_ERROR:"Extra field parsing error"};function Ng(t){return function(...e){return e.length&&(t=t.replace(/\{(\d)\}/g,(r,i)=>e[i]||"")),new Error("ADM-ZIP: "+t)}}for(let t of Object.keys(Rd))Dd[t]=Ng(Rd[t])});var Nd=ie((h2,Ld)=>{var Mg=ce("fs"),Pe=ce("path"),kd=Ta(),Bg=us(),Fg=typeof process=="object"&&process.platform==="win32",Pd=t=>typeof t=="object"&&t!==null,Od=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 ye(t){this.sep=Pe.sep,this.fs=Mg,Pd(t)&&Pd(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Ld.exports=ye;ye.prototype.makeDir=function(t){let e=this;function r(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var l;try{l=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(l&&l.isFile())throw Bg.FILE_IN_THE_WAY(`"${o}"`)}})}r(t)};ye.prototype.writeFileTo=function(t,e,r,i){let o=this;if(o.fs.existsSync(t)){if(!r)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var l=Pe.dirname(t);o.fs.existsSync(l)||o.makeDir(l);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};ye.prototype.writeFileToAsync=function(t,e,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(l){if(l&&!r)return o(!1);c.fs.stat(t,function(u,f){if(l&&f.isDirectory())return o(!1);var x=Pe.dirname(t);c.fs.exists(x,function(m){m||c.makeDir(x),c.fs.open(t,"w",438,function(w,b){w?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(p,_){c.fs.write(_,e,0,e.length,0,function(){c.fs.close(_,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):b?c.fs.write(b,e,0,e.length,0,function(){c.fs.close(b,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};ye.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let l=[];return e.fs.readdirSync(i).forEach(function(u){let f=Pe.join(i,u),x=e.fs.statSync(f);(!o||o.test(f))&&l.push(Pe.normalize(f)+(x.isDirectory()?e.sep:"")),x.isDirectory()&&c&&(l=l.concat(r(f,o,c)))}),l}return r(t,void 0,!0)};ye.prototype.findFilesAsync=function(t,e){let r=this,i=[];r.fs.readdir(t,function(o,c){if(o)return e(o);let l=c.length;if(!l)return e(null,i);c.forEach(function(u){u=Pe.join(t,u),r.fs.stat(u,function(f,x){if(f)return e(f);x&&(i.push(Pe.normalize(u)+(x.isDirectory()?r.sep:"")),x.isDirectory()?r.findFilesAsync(u,function(m,w){if(m)return e(m);i=i.concat(w),--l||e(null,i)}):--l||e(null,i))})})})};ye.prototype.getAttributes=function(){};ye.prototype.setAttributes=function(){};ye.crc32update=function(t,e){return Od[(t^e)&255]^t>>>8};ye.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,r=-1;for(let i=0;i<e;)r=ye.crc32update(r,t[i++]);return~r>>>0};ye.methodToString=function(t){switch(t){case kd.STORED:return"STORED ("+t+")";case kd.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};ye.canonical=function(t){if(!t)return"";let e=Pe.posix.normalize("/"+t.split("\\").join("/"));return Pe.join(".",e)};ye.zipnamefix=function(t){if(!t)return"";let e=Pe.posix.normalize("/"+t.split("\\").join("/"));return Pe.posix.join(".",e)};ye.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]};ye.sanitize=function(t,e){t=Pe.resolve(Pe.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Pe.normalize(Pe.join(t,r.slice(i,o).join(Pe.sep)));if(c.indexOf(t)===0)return c}return Pe.normalize(Pe.join(t,Pe.basename(e)))};ye.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};ye.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};ye.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)};ye.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};ye.isWin=Fg;ye.crcTable=Od});var Bd=ie((x2,Md)=>{var zg=ce("path");Md.exports=function(t,{fs:e}){var r=t||"",i=c(),o=null;function c(){return{directory:!1,readonly:!1,hidden:!1,executable:!1,mtime:0,atime:0}}return r&&e.existsSync(r)?(o=e.statSync(r),i.directory=o.isDirectory(),i.mtime=o.mtime,i.atime=o.atime,i.executable=(73&o.mode)!==0,i.readonly=(128&o.mode)===0,i.hidden=zg.basename(r)[0]==="."):console.warn("Invalid path: "+r),{get directory(){return i.directory},get readOnly(){return i.readonly},get hidden(){return i.hidden},get mtime(){return i.mtime},get atime(){return i.atime},get executable(){return i.executable},decodeAttributes:function(){},encodeAttributes:function(){},toJSON:function(){return{path:r,isDirectory:i.directory,isReadOnly:i.readonly,isHidden:i.hidden,isExecutable:i.executable,mTime:i.mtime,aTime:i.atime}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var zd=ie((p2,Fd)=>{Fd.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var or=ie((g2,sr)=>{sr.exports=Nd();sr.exports.Constants=Ta();sr.exports.Errors=us();sr.exports.FileAttr=Bd();sr.exports.decoder=zd()});var Hd=ie((m2,Ud)=>{var sn=or(),z=sn.Constants;Ud.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,l=0,u=0,f=0,x=0,m=0,w=0,b=0,p=0,_=0;t|=sn.isWin?2560:768,r|=z.FLG_EFS;let S={extraLen:0},A=E=>Math.max(0,E)>>>0,T=E=>Math.max(0,E)&65535,D=E=>Math.max(0,E)&255;return o=sn.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&z.FLG_EFS)>0},set flags_efs(E){E?r|=z.FLG_EFS:r&=~z.FLG_EFS},get flags_desc(){return(r&z.FLG_DESC)>0},set flags_desc(E){E?r|=z.FLG_DESC:r&=~z.FLG_DESC},get method(){return i},set method(E){switch(E){case z.STORED:this.version=10;case z.DEFLATED:default:this.version=20}i=E},get time(){return sn.fromDOS2Date(this.timeval)},set time(E){E=new Date(E),this.timeval=sn.fromDate2DOS(E)},get timeval(){return o},set timeval(E){o=A(E)},get timeHighByte(){return D(o>>>8)},get crc(){return c},set crc(E){c=A(E)},get compressedSize(){return l},set compressedSize(E){l=A(E)},get size(){return u},set size(E){u=A(E)},get fileNameLength(){return f},set fileNameLength(E){f=E},get extraLength(){return x},set extraLength(E){x=E},get extraLocalLength(){return S.extraLen},set extraLocalLength(E){S.extraLen=E},get commentLength(){return m},set commentLength(E){m=E},get diskNumStart(){return w},set diskNumStart(E){w=A(E)},get inAttr(){return b},set inAttr(E){b=A(E)},get attr(){return p},set attr(E){p=A(E)},get fileAttr(){return(p||0)>>16&4095},get offset(){return _},set offset(E){_=A(E)},get encrypted(){return(r&z.FLG_ENC)===z.FLG_ENC},get centralHeaderSize(){return z.CENHDR+f+x+m},get realDataOffset(){return _+z.LOCHDR+S.fnameLen+S.extraLen},get localHeader(){return S},loadLocalHeaderFromBinary:function(E){var k=E.slice(_,_+z.LOCHDR);if(k.readUInt32LE(0)!==z.LOCSIG)throw sn.Errors.INVALID_LOC();S.version=k.readUInt16LE(z.LOCVER),S.flags=k.readUInt16LE(z.LOCFLG),S.flags_desc=(S.flags&z.FLG_DESC)>0,S.method=k.readUInt16LE(z.LOCHOW),S.time=k.readUInt32LE(z.LOCTIM),S.crc=k.readUInt32LE(z.LOCCRC),S.compressedSize=k.readUInt32LE(z.LOCSIZ),S.size=k.readUInt32LE(z.LOCLEN),S.fnameLen=k.readUInt16LE(z.LOCNAM),S.extraLen=k.readUInt16LE(z.LOCEXT);let P=_+z.LOCHDR+S.fnameLen,B=P+S.extraLen;return E.slice(P,B)},loadFromBinary:function(E){if(E.length!==z.CENHDR||E.readUInt32LE(0)!==z.CENSIG)throw sn.Errors.INVALID_CEN();t=E.readUInt16LE(z.CENVEM),e=E.readUInt16LE(z.CENVER),r=E.readUInt16LE(z.CENFLG),i=E.readUInt16LE(z.CENHOW),o=E.readUInt32LE(z.CENTIM),c=E.readUInt32LE(z.CENCRC),l=E.readUInt32LE(z.CENSIZ),u=E.readUInt32LE(z.CENLEN),f=E.readUInt16LE(z.CENNAM),x=E.readUInt16LE(z.CENEXT),m=E.readUInt16LE(z.CENCOM),w=E.readUInt16LE(z.CENDSK),b=E.readUInt16LE(z.CENATT),p=E.readUInt32LE(z.CENATX),_=E.readUInt32LE(z.CENOFF)},localHeaderToBinary:function(){var E=Buffer.alloc(z.LOCHDR);return E.writeUInt32LE(z.LOCSIG,0),E.writeUInt16LE(e,z.LOCVER),E.writeUInt16LE(r,z.LOCFLG),E.writeUInt16LE(i,z.LOCHOW),E.writeUInt32LE(o,z.LOCTIM),E.writeUInt32LE(c,z.LOCCRC),E.writeUInt32LE(l,z.LOCSIZ),E.writeUInt32LE(u,z.LOCLEN),E.writeUInt16LE(f,z.LOCNAM),E.writeUInt16LE(S.extraLen,z.LOCEXT),E},centralHeaderToBinary:function(){var E=Buffer.alloc(z.CENHDR+f+x+m);return E.writeUInt32LE(z.CENSIG,0),E.writeUInt16LE(t,z.CENVEM),E.writeUInt16LE(e,z.CENVER),E.writeUInt16LE(r,z.CENFLG),E.writeUInt16LE(i,z.CENHOW),E.writeUInt32LE(o,z.CENTIM),E.writeUInt32LE(c,z.CENCRC),E.writeUInt32LE(l,z.CENSIZ),E.writeUInt32LE(u,z.CENLEN),E.writeUInt16LE(f,z.CENNAM),E.writeUInt16LE(x,z.CENEXT),E.writeUInt16LE(m,z.CENCOM),E.writeUInt16LE(w,z.CENDSK),E.writeUInt16LE(b,z.CENATT),E.writeUInt32LE(p,z.CENATX),E.writeUInt32LE(_,z.CENOFF),E},toJSON:function(){let E=function(k){return k+" bytes"};return{made:t,version:e,flags:r,method:sn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:E(l),size:E(u),fileNameLength:E(f),extraLength:E(x),commentLength:E(m),diskNumStart:w,inAttr:b,attr:p,offset:_,centralHeaderSize:E(z.CENHDR+f+x+m)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Gd=ie((w2,qd)=>{var ar=or(),me=ar.Constants;qd.exports=function(){var t=0,e=0,r=0,i=0,o=0;return{get diskEntries(){return t},set diskEntries(c){t=e=c},get totalEntries(){return e},set totalEntries(c){e=t=c},get size(){return r},set size(c){r=c},get offset(){return i},set offset(c){i=c},get commentLength(){return o},set commentLength(c){o=c},get mainHeaderSize(){return me.ENDHDR+o},loadFromBinary:function(c){if((c.length!==me.ENDHDR||c.readUInt32LE(0)!==me.ENDSIG)&&(c.length<me.ZIP64HDR||c.readUInt32LE(0)!==me.ZIP64SIG))throw ar.Errors.INVALID_END();c.readUInt32LE(0)===me.ENDSIG?(t=c.readUInt16LE(me.ENDSUB),e=c.readUInt16LE(me.ENDTOT),r=c.readUInt32LE(me.ENDSIZ),i=c.readUInt32LE(me.ENDOFF),o=c.readUInt16LE(me.ENDCOM)):(t=ar.readBigUInt64LE(c,me.ZIP64SUB),e=ar.readBigUInt64LE(c,me.ZIP64TOT),r=ar.readBigUInt64LE(c,me.ZIP64SIZE),i=ar.readBigUInt64LE(c,me.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(me.ENDHDR+o);return c.writeUInt32LE(me.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,me.ENDSUB),c.writeUInt16LE(e,me.ENDTOT),c.writeUInt32LE(r,me.ENDSIZ),c.writeUInt32LE(i,me.ENDOFF),c.writeUInt16LE(o,me.ENDCOM),c.fill(" ",me.ENDHDR),c},toJSON:function(){let c=function(l,u){let f=l.toString(16).toUpperCase();for(;f.length<u;)f="0"+f;return"0x"+f};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Ra=ie(Ca=>{Ca.EntryHeader=Hd();Ca.MainHeader=Gd()});var Wd=ie((y2,jd)=>{jd.exports=function(t){var e=ce("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],l=0;o.on("data",function(u){c.push(u),l+=u.length}),o.on("end",function(){var u=Buffer.alloc(l),f=0;u.fill(0);for(var x=0;x<c.length;x++){var m=c[x];m.copy(u,f),f+=m.length}i&&i(u)}),o.end(t)}}}});var $d=ie((E2,Kd)=>{var Ug=+(process.versions?process.versions.node:"").split(".")[0]||0;Kd.exports=function(t,e){var r=ce("zlib");let i=Ug>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),l=[],u=0;c.on("data",function(f){l.push(f),u+=f.length}),c.on("end",function(){var f=Buffer.alloc(u),x=0;f.fill(0);for(var m=0;m<l.length;m++){var w=l[m];w.copy(f,x),x+=w.length}o&&o(f)}),c.end(t)}}}});var Xd=ie((b2,Yd)=>{"use strict";var{randomFillSync:Vd}=ce("crypto"),Hg=us(),qg=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}),Zd=(t,e)=>Math.imul(t,e)>>>0,Jd=(t,e)=>qg[(t^e)&255]^t>>>8,ti=()=>typeof Vd=="function"?Vd(Buffer.alloc(12)):ti.node();ti.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 fs={genSalt:ti};function hs(t){let e=Buffer.isBuffer(t)?t:Buffer.from(t);this.keys=new Uint32Array([305419896,591751049,878082192]);for(let r=0;r<e.length;r++)this.updateKeys(e[r])}hs.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Jd(e[0],t),e[1]+=e[0]&255,e[1]=Zd(e[1],134775813)+1,e[2]=Jd(e[2],e[1]>>>24),t};hs.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Zd(t,t^1)>>8&255};function Gg(t){let e=new hs(t);return function(r){let i=Buffer.alloc(r.length),o=0;for(let c of r)i[o++]=e.updateKeys(c^e.next());return i}}function jg(t){let e=new hs(t);return function(r,i,o=0){i||(i=Buffer.alloc(r.length));for(let c of r){let l=e.next();i[o++]=c^l,e.updateKeys(c)}return i}}function Wg(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Gg(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Hg.WRONG_PASSWORD();return i(t.slice(12))}function Kg(t){Buffer.isBuffer(t)&&t.length>=12?fs.genSalt=function(){return t.slice(0,12)}:t==="node"?fs.genSalt=ti.node:fs.genSalt=ti}function $g(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=jg(r),c=fs.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)}Yd.exports={decrypt:Wg,encrypt:$g,_salter:Kg}});var Qd=ie(xs=>{xs.Deflater=Wd();xs.Inflater=$d();xs.ZipCrypto=Xd()});var ka=ie((S2,eu)=>{var se=or(),Vg=Ra(),Ee=se.Constants,Da=Qd();eu.exports=function(t,e){var r=new Vg.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,l=null,u=Buffer.alloc(0),f=Buffer.alloc(0),x=!0;let m=t,w=typeof m.decoder=="object"?m.decoder:se.decoder;x=w.hasOwnProperty("efs")?w.efs:!1;function b(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(f=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function p(E){if(!r.flags_desc&&!r.localHeader.flags_desc){if(se.crc32(E)!==r.localHeader.crc)return!1}else{let k={},P=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(P)==Ee.LOCSIG||e.readUInt32LE(P)==Ee.CENSIG)throw se.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(P)==Ee.EXTSIG)k.crc=e.readUInt32LE(P+Ee.EXTCRC),k.compressedSize=e.readUInt32LE(P+Ee.EXTSIZ),k.size=e.readUInt32LE(P+Ee.EXTLEN);else if(e.readUInt16LE(P+12)===19280)k.crc=e.readUInt32LE(P+Ee.EXTCRC-4),k.compressedSize=e.readUInt32LE(P+Ee.EXTSIZ-4),k.size=e.readUInt32LE(P+Ee.EXTLEN-4);else throw se.Errors.DESCRIPTOR_UNKNOWN();if(k.compressedSize!==r.compressedSize||k.size!==r.size||k.crc!==r.crc)throw se.Errors.DESCRIPTOR_FAULTY();if(se.crc32(E)!==k.crc)return!1}return!0}function _(E,k,P){if(typeof k>"u"&&typeof E=="string"&&(P=E,E=void 0),c)return E&&k&&k(Buffer.alloc(0),se.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var B=b();if(B.length===0)return E&&k&&k(B),B;if(r.encrypted){if(typeof P!="string"&&!Buffer.isBuffer(P))throw se.Errors.INVALID_PASS_PARAM();B=Da.ZipCrypto.decrypt(B,r,P)}var N=Buffer.alloc(r.size);switch(r.method){case se.Constants.STORED:if(B.copy(N),p(N))return E&&k&&k(N),N;throw E&&k&&k(N,se.Errors.BAD_CRC()),se.Errors.BAD_CRC();case se.Constants.DEFLATED:var $=new Da.Inflater(B,r.size);if(E)$.inflateAsync(function(W){W.copy(W,0),k&&(p(W)?k(W):k(W,se.Errors.BAD_CRC()))});else{if($.inflate(N).copy(N,0),!p(N))throw se.Errors.BAD_CRC(`"${w.decode(i)}"`);return N}break;default:throw E&&k&&k(Buffer.alloc(0),se.Errors.UNKNOWN_METHOD()),se.Errors.UNKNOWN_METHOD()}}function S(E,k){if((!l||!l.length)&&Buffer.isBuffer(e))return E&&k&&k(b()),b();if(l.length&&!c){var P;switch(r.method){case se.Constants.STORED:return r.compressedSize=r.size,P=Buffer.alloc(l.length),l.copy(P),E&&k&&k(P),P;default:case se.Constants.DEFLATED:var B=new Da.Deflater(l);if(E)B.deflateAsync(function($){P=Buffer.alloc($.length),r.compressedSize=$.length,$.copy(P),k&&k(P)});else{var N=B.deflate();return r.compressedSize=N.length,N}B=null;break}}else if(E&&k)k(Buffer.alloc(0));else return Buffer.alloc(0)}function A(E,k){return se.readBigUInt64LE(E,k)}function T(E){try{for(var k=0,P,B,N;k+4<E.length;)P=E.readUInt16LE(k),k+=2,B=E.readUInt16LE(k),k+=2,N=E.slice(k,k+B),k+=B,Ee.ID_ZIP64===P&&D(N)}catch{throw se.Errors.EXTRA_FIELD_PARSE_ERROR()}}function D(E){var k,P,B,N;E.length>=Ee.EF_ZIP64_SCOMP&&(k=A(E,Ee.EF_ZIP64_SUNCOMP),r.size===Ee.EF_ZIP64_OR_32&&(r.size=k)),E.length>=Ee.EF_ZIP64_RHO&&(P=A(E,Ee.EF_ZIP64_SCOMP),r.compressedSize===Ee.EF_ZIP64_OR_32&&(r.compressedSize=P)),E.length>=Ee.EF_ZIP64_DSN&&(B=A(E,Ee.EF_ZIP64_RHO),r.offset===Ee.EF_ZIP64_OR_32&&(r.offset=B)),E.length>=Ee.EF_ZIP64_DSN+4&&(N=E.readUInt32LE(Ee.EF_ZIP64_DSN),r.diskNumStart===Ee.EF_ZIP64_OR_16&&(r.diskNumStart=N))}return{get entryName(){return w.decode(i)},get rawEntryName(){return i},set entryName(E){i=se.toBuffer(E,w.encode);var k=i[i.length-1];c=k===47||k===92,r.fileNameLength=i.length},get efs(){return typeof x=="function"?x(this.entryName):x},get extra(){return u},set extra(E){u=E,r.extraLength=E.length,T(E)},get comment(){return w.decode(o)},set comment(E){if(o=se.toBuffer(E,w.encode),r.commentLength=o.length,o.length>65535)throw se.Errors.COMMENT_TOO_LONG()},get name(){var E=w.decode(i);return c?E.substr(E.length-1).split("/").pop():E.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return S(!1,null)},getCompressedDataAsync:function(E){S(!0,E)},setData:function(E){l=se.toBuffer(E,se.decoder.encode),!c&&l.length?(r.size=l.length,r.method=se.Constants.DEFLATED,r.crc=se.crc32(E),r.changed=!0):r.method=se.Constants.STORED},getData:function(E){return r.changed?l:_(!1,null,E)},getDataAsync:function(E,k){r.changed?E(l):_(!0,E,k)},set attr(E){r.attr=E},get attr(){return r.attr},set header(E){r.loadFromBinary(E)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=u.length;var E=r.centralHeaderToBinary(),k=se.Constants.CENHDR;return i.copy(E,k),k+=i.length,u.copy(E,k),k+=r.extraLength,o.copy(E,k),E},packLocalHeader:function(){let E=0;r.flags_efs=this.efs,r.extraLocalLength=f.length;let k=r.localHeaderToBinary(),P=Buffer.alloc(k.length+i.length+r.extraLocalLength);return k.copy(P,E),E+=k.length,i.copy(P,E),E+=i.length,f.copy(P,E),E+=f.length,P},toJSON:function(){let E=function(k){return"<"+(k&&k.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:E(e),data:E(l)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var ru=ie((I2,nu)=>{var tu=ka(),Jg=Ra(),qe=or();nu.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new Jg.MainHeader,l=!1,u=null;let f=new Set,x=e,{noSort:m,decoder:w}=x;t?_(x.readEntries):l=!0;function b(){let A=new Set;for(let T of Object.keys(i)){let D=T.split("/");if(D.pop(),!!D.length)for(let E=0;E<D.length;E++){let k=D.slice(0,E+1).join("/")+"/";A.add(k)}}for(let T of A)if(!(T in i)){let D=new tu(x);D.entryName=T,D.attr=16,D.temporary=!0,r.push(D),i[D.entryName]=D,f.add(D)}}function p(){if(l=!0,i={},c.diskEntries>(t.length-c.offset)/qe.Constants.CENHDR)throw qe.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var A=c.offset,T=0;T<r.length;T++){var D=A,E=new tu(x,t);E.header=t.slice(D,D+=qe.Constants.CENHDR),E.entryName=t.slice(D,D+=E.header.fileNameLength),E.header.extraLength&&(E.extra=t.slice(D,D+=E.header.extraLength)),E.header.commentLength&&(E.comment=t.slice(D,D+E.header.commentLength)),A+=E.header.centralHeaderSize,r[T]=E,i[E.entryName]=E}f.clear(),b()}function _(A){var T=t.length-qe.Constants.ENDHDR,D=Math.max(0,T-65535),E=D,k=t.length,P=-1,B=0;for(typeof x.trailingSpace=="boolean"&&x.trailingSpace&&(D=0),T;T>=E;T--)if(t[T]===80){if(t.readUInt32LE(T)===qe.Constants.ENDSIG){P=T,B=T,k=T+qe.Constants.ENDHDR,E=T-qe.Constants.END64HDR;continue}if(t.readUInt32LE(T)===qe.Constants.END64SIG){E=D;continue}if(t.readUInt32LE(T)===qe.Constants.ZIP64SIG){P=T,k=T+qe.readBigUInt64LE(t,T+qe.Constants.ZIP64SIZE)+qe.Constants.ZIP64LEAD;break}}if(P==-1)throw qe.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(P,k)),c.commentLength&&(o=t.slice(B+qe.Constants.ENDHDR)),A&&p()}function S(){r.length>1&&!m&&r.sort((A,T)=>A.entryName.toLowerCase().localeCompare(T.entryName.toLowerCase()))}return{get entries(){return l||p(),r.filter(A=>!f.has(A))},get comment(){return w.decode(o)},set comment(A){o=qe.toBuffer(A,w.encode),c.commentLength=o.length},getEntryCount:function(){return l?r.length:c.diskEntries},forEach:function(A){this.entries.forEach(A)},getEntry:function(A){return l||p(),i[A]||null},setEntry:function(A){l||p(),r.push(A),i[A.entryName]=A,c.totalEntries=r.length},deleteFile:function(A,T=!0){l||p();let D=i[A];this.getEntryChildren(D,T).map(k=>k.entryName).forEach(this.deleteEntry)},deleteEntry:function(A){l||p();let T=i[A],D=r.indexOf(T);D>=0&&(r.splice(D,1),delete i[A],c.totalEntries=r.length)},getEntryChildren:function(A,T=!0){if(l||p(),typeof A=="object")if(A.isDirectory&&T){let D=[],E=A.entryName;for(let k of r)k.entryName.startsWith(E)&&D.push(k);return D}else return[A];return[]},getChildCount:function(A){if(A&&A.isDirectory){let T=this.getEntryChildren(A);return T.includes(A)?T.length-1:T.length}return 0},compressToBuffer:function(){l||p(),S();let A=[],T=[],D=0,E=0;c.size=0,c.offset=0;let k=0;for(let N of this.entries){let $=N.getCompressedData();N.header.offset=E;let W=N.packLocalHeader(),ne=W.length+$.length;E+=ne,A.push(W),A.push($);let Y=N.packCentralHeader();T.push(Y),c.size+=Y.length,D+=ne+Y.length,k++}D+=c.mainHeaderSize,c.offset=E,c.totalEntries=k,E=0;let P=Buffer.alloc(D);for(let N of A)N.copy(P,E),E+=N.length;for(let N of T)N.copy(P,E),E+=N.length;let B=c.toBinary();return o&&o.copy(B,qe.Constants.ENDHDR),B.copy(P,E),t=P,l=!1,P},toAsyncBuffer:function(A,T,D,E){try{l||p(),S();let k=[],P=[],B=0,N=0,$=0;c.size=0,c.offset=0;let W=function(ne){if(ne.length>0){let Y=ne.shift(),ve=Y.entryName+Y.extra.toString();D&&D(ve),Y.getCompressedDataAsync(function(he){E&&E(ve),Y.header.offset=N;let O=Y.packLocalHeader(),q=O.length+he.length;N+=q,k.push(O),k.push(he);let j=Y.packCentralHeader();P.push(j),c.size+=j.length,B+=q+j.length,$++,W(ne)})}else{B+=c.mainHeaderSize,c.offset=N,c.totalEntries=$,N=0;let Y=Buffer.alloc(B);k.forEach(function(he){he.copy(Y,N),N+=he.length}),P.forEach(function(he){he.copy(Y,N),N+=he.length});let ve=c.toBinary();o&&o.copy(ve,qe.Constants.ENDHDR),ve.copy(Y,N),t=Y,l=!1,A(Y)}};W(Array.from(this.entries))}catch(k){T(k)}}}}});var ou=ie((A2,su)=>{var _e=or(),we=ce("path"),Zg=ka(),Yg=ru(),Tn=(...t)=>_e.findLast(t,e=>typeof e=="boolean"),iu=(...t)=>_e.findLast(t,e=>typeof e=="string"),Xg=(...t)=>_e.findLast(t,e=>typeof e=="function"),Qg={noSort:!1,readEntries:!1,method:_e.Constants.NONE,fs:null};su.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),Qg);t&&typeof t=="object"&&(t instanceof Uint8Array||(Object.assign(i,t),t=i.input?i.input:void 0,i.input&&delete i.input),Buffer.isBuffer(t)&&(r=t,i.method=_e.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new _e(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=_e.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=_e.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw _e.Errors.INVALID_FILENAME();let c=new Yg(r,i),{canonical:l,sanitize:u,zipnamefix:f}=_e;function x(p){if(p&&c){var _;if(typeof p=="string"&&(_=c.getEntry(we.posix.normalize(p))),typeof p=="object"&&typeof p.entryName<"u"&&typeof p.header<"u"&&(_=c.getEntry(p.entryName)),_)return _}return null}function m(p){let{join:_,normalize:S,sep:A}=we.posix;return _(we.isAbsolute(p)?"/":".",S(A+p.split("\\").join(A)+A))}function w(p){return p instanceof RegExp?(function(_){return function(S){return _.test(S)}})(p):typeof p!="function"?()=>!0:p}let b=(p,_)=>{let S=_.slice(-1);return S=S===o.sep?o.sep:"",we.relative(p,_)+S};return{readFile:function(p,_){var S=x(p);return S&&S.getData(_)||null},childCount:function(p){let _=x(p);if(_)return c.getChildCount(_)},readFileAsync:function(p,_){var S=x(p);S?S.getDataAsync(_):_(null,"getEntry failed for:"+p)},readAsText:function(p,_){var S=x(p);if(S){var A=S.getData();if(A&&A.length)return A.toString(_||"utf8")}return""},readAsTextAsync:function(p,_,S){var A=x(p);A?A.getDataAsync(function(T,D){if(D){_(T,D);return}T&&T.length?_(T.toString(S||"utf8")):_("")}):_("")},deleteFile:function(p,_=!0){var S=x(p);S&&c.deleteFile(S.entryName,_)},deleteEntry:function(p){var _=x(p);_&&c.deleteEntry(_.entryName)},addZipComment:function(p){c.comment=p},getZipComment:function(){return c.comment||""},addZipEntryComment:function(p,_){var S=x(p);S&&(S.comment=_)},getZipEntryComment:function(p){var _=x(p);return _&&_.comment||""},updateFile:function(p,_){var S=x(p);S&&S.setData(_)},addLocalFile:function(p,_,S,A){if(o.fs.existsSync(p)){_=_?m(_):"";let T=we.win32.basename(we.win32.normalize(p));_+=S||T;let D=o.fs.statSync(p),E=D.isFile()?o.fs.readFileSync(p):Buffer.alloc(0);D.isDirectory()&&(_+=o.sep),this.addFile(_,E,A,D)}else throw _e.Errors.FILE_NOT_FOUND(p)},addLocalFileAsync:function(p,_){p=typeof p=="object"?p:{localPath:p};let S=we.resolve(p.localPath),{comment:A}=p,{zipPath:T,zipName:D}=p,E=this;o.fs.stat(S,function(k,P){if(k)return _(k,!1);T=T?m(T):"";let B=we.win32.basename(we.win32.normalize(S));if(T+=D||B,P.isFile())o.fs.readFile(S,function(N,$){return N?_(N,!1):(E.addFile(T,$,A,P),setImmediate(_,void 0,!0))});else if(P.isDirectory())return T+=o.sep,E.addFile(T,Buffer.alloc(0),A,P),setImmediate(_,void 0,!0)})},addLocalFolder:function(p,_,S){if(S=w(S),_=_?m(_):"",p=we.normalize(p),o.fs.existsSync(p)){let A=o.findFiles(p),T=this;if(A.length)for(let D of A){let E=we.join(_,b(p,D));S(E)&&T.addLocalFile(D,we.dirname(E))}}else throw _e.Errors.FILE_NOT_FOUND(p)},addLocalFolderAsync:function(p,_,S,A){A=w(A),S=S?m(S):"",p=we.normalize(p);var T=this;o.fs.open(p,"r",function(D){if(D&&D.code==="ENOENT")_(void 0,_e.Errors.FILE_NOT_FOUND(p));else if(D)_(void 0,D);else{var E=o.findFiles(p),k=-1,P=function(){if(k+=1,k<E.length){var B=E[k],N=b(p,B).split("\\").join("/");N=N.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),A(N)?o.fs.stat(B,function($,W){$&&_(void 0,$),W.isFile()?o.fs.readFile(B,function(ne,Y){ne?_(void 0,ne):(T.addFile(S+N,Y,"",W),P())}):(T.addFile(S+N+"/",Buffer.alloc(0),"",W),P())}):process.nextTick(()=>{P()})}else _(!0,void 0)};P()}})},addLocalFolderAsync2:function(p,_){let S=this;p=typeof p=="object"?p:{localPath:p},localPath=we.resolve(m(p.localPath));let{zipPath:A,filter:T,namefix:D}=p;T instanceof RegExp?T=(function(P){return function(B){return P.test(B)}})(T):typeof T!="function"&&(T=function(){return!0}),A=A?m(A):"",D=="latin1"&&(D=P=>P.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof D!="function"&&(D=P=>P);let E=P=>we.join(A,D(b(localPath,P))),k=P=>we.win32.basename(we.win32.normalize(D(P)));o.fs.open(localPath,"r",function(P){P&&P.code==="ENOENT"?_(void 0,_e.Errors.FILE_NOT_FOUND(localPath)):P?_(void 0,P):o.findFilesAsync(localPath,function(B,N){if(B)return _(B);N=N.filter($=>T(E($))),N.length||_(void 0,!1),setImmediate(N.reverse().reduce(function($,W){return function(ne,Y){if(ne||Y===!1)return setImmediate($,ne,!1);S.addLocalFileAsync({localPath:W,zipPath:we.dirname(E(W)),zipName:k(W)},$)}},_))})})},addLocalFolderPromise:function(p,_){return new Promise((S,A)=>{this.addLocalFolderAsync2(Object.assign({localPath:p},_),(T,D)=>{T&&A(T),D&&S(this)})})},addFile:function(p,_,S,A){p=f(p);let T=x(p),D=T!=null;D||(T=new Zg(i),T.entryName=p),T.comment=S||"";let E=typeof A=="object"&&A instanceof o.fs.Stats;E&&(T.header.time=A.mtime);var k=T.isDirectory?16:0;let P=T.isDirectory?16384:32768;return E?P|=4095&A.mode:typeof A=="number"?P|=4095&A:P|=T.isDirectory?493:420,k=(k|P<<16)>>>0,T.attr=k,T.setData(_),D||c.setEntry(T),T},getEntries:function(p){return c.password=p,c?c.entries:[]},getEntry:function(p){return x(p)},getEntryCount:function(){return c.getEntryCount()},forEach:function(p){return c.forEach(p)},extractEntryTo:function(p,_,S,A,T,D){A=Tn(!1,A),T=Tn(!1,T),S=Tn(!0,S),D=iu(T,D);var E=x(p);if(!E)throw _e.Errors.NO_ENTRY();var k=l(E.entryName),P=u(_,D&&!E.isDirectory?D:S?k:we.basename(k));if(E.isDirectory){var B=c.getEntryChildren(E);return B.forEach(function(W){if(W.isDirectory)return;var ne=W.getData();if(!ne)throw _e.Errors.CANT_EXTRACT_FILE();var Y=l(W.entryName),ve=u(_,S?Y:we.basename(Y));let he=T?W.header.fileAttr:void 0;o.writeFileTo(ve,ne,A,he)}),!0}var N=E.getData(c.password);if(!N)throw _e.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(P)&&!A)throw _e.Errors.CANT_OVERRIDE();let $=T?p.header.fileAttr:void 0;return o.writeFileTo(P,N,A,$),!0},test:function(p){if(!c)return!1;for(var _ in c.entries)try{if(_.isDirectory)continue;var S=c.entries[_].getData(p);if(!S)return!1}catch{return!1}return!0},extractAllTo:function(p,_,S,A){if(S=Tn(!1,S),A=iu(S,A),_=Tn(!1,_),!c)throw _e.Errors.NO_ZIP();c.entries.forEach(function(T){var D=u(p,l(T.entryName));if(T.isDirectory){o.makeDir(D);return}var E=T.getData(A);if(!E)throw _e.Errors.CANT_EXTRACT_FILE();let k=S?T.header.fileAttr:void 0;o.writeFileTo(D,E,_,k);try{o.fs.utimesSync(D,T.header.time,T.header.time)}catch{throw _e.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(p,_,S,A){if(A=Xg(_,S,A),S=Tn(!1,S),_=Tn(!1,_),!A)return new Promise((P,B)=>{this.extractAllToAsync(p,_,S,function(N){N?B(N):P(this)})});if(!c){A(_e.Errors.NO_ZIP());return}p=we.resolve(p);let T=P=>u(p,we.normalize(l(P.entryName))),D=(P,B)=>new Error(P+': "'+B+'"'),E=[],k=[];c.entries.forEach(P=>{P.isDirectory?E.push(P):k.push(P)});for(let P of E){let B=T(P),N=S?P.header.fileAttr:void 0;try{o.makeDir(B),N&&o.fs.chmodSync(B,N),o.fs.utimesSync(B,P.header.time,P.header.time)}catch{A(D("Unable to create folder",B))}}k.reverse().reduce(function(P,B){return function(N){if(N)P(N);else{let $=we.normalize(l(B.entryName)),W=u(p,$);B.getDataAsync(function(ne,Y){if(Y)P(Y);else if(!ne)P(_e.Errors.CANT_EXTRACT_FILE());else{let ve=S?B.header.fileAttr:void 0;o.writeFileToAsync(W,ne,_,ve,function(he){he||P(D("Unable to write file",W)),o.fs.utimes(W,B.header.time,B.header.time,function(O){O?P(D("Unable to set times",W)):P()})})}})}}},A)()},writeZip:function(p,_){if(arguments.length===1&&typeof p=="function"&&(_=p,p=""),!p&&i.filename&&(p=i.filename),!!p){var S=c.compressToBuffer();if(S){var A=o.writeFileTo(p,S,!0);typeof _=="function"&&_(A?null:new Error("failed"),"")}}},writeZipPromise:function(p,_){let{overwrite:S,perm:A}=Object.assign({overwrite:!0},_);return new Promise((T,D)=>{!p&&i.filename&&(p=i.filename),p||D("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(E=>{let k=P=>P?T(P):D("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(p,E,S,A,k)},D)})},toBufferPromise:function(){return new Promise((p,_)=>{c.toAsyncBuffer(p,_)})},toBuffer:function(p,_,S,A){return typeof p=="function"?(c.toAsyncBuffer(p,_,S,A),null):c.compressToBuffer()}}}});import{execFile as G_,spawn as j_,spawnSync as zA}from"node:child_process";import{promisify as W_}from"node:util";function $_(t){if(process.platform!=="win32")return!1;if(t0.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(t0,"").toLowerCase();return K_.has(r)}function n0(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return $_(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function at(t,e=[],r={}){return j_(t,e,n0(t,r))}function r0(t,e=[],r={}){return V_(t,e,n0(t,r))}var K_,t0,V_,yn=Je(()=>{"use strict";K_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),t0=/\.(cmd|bat|ps1)$/i;V_=W_(G_)});var oh=ie(xe=>{"use strict";var L=U;(function(t,e){let r=U,i=t();for(;;)try{if(parseInt(r(465))/1*(parseInt(r(513))/2)+parseInt(r(1783))/3+parseInt(r(1202))/4+parseInt(r(819))/5*(-parseInt(r(808))/6)+parseInt(r(1681))/7+parseInt(r(1018))/8+-parseInt(r(419))/9===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(So,127462);var zE=Object["definePr"+L(562)],UE=Object[L(1384)+L(1726)+L(1883)],th=(t,e)=>function(){return t&&(e=(0,t[UE(t)[0]])(t=0)),e},HE=(t,e)=>{let r=L,i={kVROj:function(c,l,u,f){return c(l,u,f)}};for(var o in e)i[r(574)](zE,t,o,{get:e[o],enumerable:!0})};function qE(){return Z0||(Z0=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function GE(){let t=L;return Y0||(Y0=[IDBCursor[t(1763)+"e"].advance,IDBCursor[t(1763)+"e"][t(1427)],IDBCursor.prototype["continue"+t(1330)+"ey"]])}function So(){let t=["tgTMDNu","v1rYEhe","CuziwuO","B0zrrhu","z1b6DM4","DhbizwfKzxi","CMDYshG","BxnN","shzytee","uufUrgy","EfvZzuvUDG","yufzzuu","Eu9UEg0","sMjntKi","zxn0ywe","EwvcCwm","x2n1CNnVCKy","AKjLzK8","A0nKCKy","ywnOzwq","q1bTBM4","DMvY","BNzxBvy","mhWX","C3jJ","x21LC3nHz2u","sxzqEfi","ENHHsem","B3vUDa","vKrQtue","CgP4tum","ywrZCM8","x29UvgLTzw8","CvDWB04","C2vYDMLJzq","z2v0u3rVCMe","zxj2AwnL","shH0vvG","z2v0sxrLBq","v2LUzg93","y3jLyxrLuMu","zMXVB3i","qw1iEfu","zuLQEwu","ExnrBuu","B3vzqMO","CMrvy3a","zhb4yNG","Ef9MCM9UDgK","zxH0ugf5Bg8","wLbhsKu","sKjXBNG","yNbwvKW","wfzHBgm","shzVALm","veXzrfe","rKLyyvG","vNvdALy","uhrOB2G","BwvZC2fNzv8","rhPJA24","Cg1nDM4","AuPmvgO","wK9PsLu","wxnsEuG","wg1QwKu","vuHWD0O","vNDZz1e","sMnxBLy","zxHWB3j0CW","sKz6seK","BwnqAhK","s21ou3q","AKTRtxe","seTOrLm","zw5NDgG","u2LHsvO","x2LUAxrhBg8","B3bLBKrc","x2LUAxrqCM8","q09otKvdveK","BMCGzMfPBgu","DMDQrM4","mhW3Fdj8nhW","v0D6yxC","zKTzBg4","x3jLywr5q2W","C2vUDa","z2u6ia","Bezzufi","igzHAwWSig0","x2rYB3bhBg8","qwjcveu","C3rVCcbPBw0","sg5Ar04","y3n6zMG","sfjxCLi","vgDxz2K","ndy2nJq4z2P2vKTs","EwXRBu8","zLPzz0O","tNfnthG","x2zVCM1HDeu","tfP2sxK","yLn5vu4","qwjVCNrfCNi","zMvY","u2fVDMG","A2TSq28","u2vYDMLJzvC","Bwf4twvZC2e","BMv4DcGPigm","wLjABgu","B2jeDwm","r0TYzKq","D1rNr1m","A2f4AMu","vw5Wvgq","vgLQBMu","yLDmrwu","ref4v04","vLLYzvO","Efrurw52","CgfYC2u","BgLUzw5V","zgXnCuS","sxbpvgu","tgzPBxm","ywjoree","AhHxDxm","zvzHrwm","D3nMzM4","AhjUBwK","wuTQBui","rxjYB3jdB2q","Cgn3C1q","sKjIqNq","rMfIsMK","zwnQCwe","ywrKt25L","vvvZwui","wfHKBgq","AgzLz0q","B3bLCNr5tMe","B3nLrxzLBNq","BvfvCuK","Ce92CMu","BMv3vMvYC2K","r1Hny3i","s3rxEeq","CunHCuC","sMD3vLG","EM16s3m","x2n1CNnVCK0","CNnVCL9Uyw0","B25JBg9Zzq","D2LMquS","CxbUALO","CwPQvuS","DgLTzw91Da","zMzLCG","yNLL","D2XSy1u","yM9L","y29TCgXLDgu","su9hvuy","DeLK","DcbSAw1PDa","r2DywLG","Dg9Y","vw5Oyw5KBgu","wePNyvK","y2fSBa","yMLUza","zgvIDwC","sLfStw0","DcbVzIbYyw4","qvfnzeW","suPttem","C2vUzf9Hy2S","ChjVDg90Exa","r2nIB0S","x3fVC0rc","CMvWBgfJzq","uLPwsvO","zNDZxZeUmc4","Axnby2TdBgu","tMTjDNO","Dg1YzKC","twf1rxq","x3jLy29UBMu","sM9xzwK","v3LyqwC","mdaWma","zxjFAxnFywm","tg1hDMe","CMvTB3zLrxy","DMnAAgi","yuPYs1C","CK12zLu","ntG3ntaYu1LUD3bX","lcbTyxGGCMu","BgvuvwO","rgrTvhC","AKrVvLG","suvtx0vsuK8","y29Kzq","sxzTD3C","Aw1LCYbPBIa","BeHHBMrSzxi","wLzqCuW","v0XdBwO","B1jtzNe","y0fervq","B2zMBgLUzq","rMD6BNy","qu56Agq","AMHcCLm","tvDrDfq","x3jLBw92zvC","uuLXAvG","vfbgENq","CMvZzxruCMK","BgLUzq","CxPOsw0","wKLjz3K","zw50zwqGDhK","DxbKyxrLq3u","zw5KCg9PBNq","vgfbuxa","AwLkq3q","tKDFrvjst1i","B3nLza","rKf4qM8","wgfJyuy","ChLtANa","B3jAtLm","thrzuLy","Bg9IywXty28","svjjsey","BK1pqM4","CMvHC29U","DefOueC","Dg9oDw1Izxi","Axb4EgS","zeDoshu","zKDrDxK","BfrPBwvVDxq","sLfnzMS","zufJAW","rgvKAwnHDgu","ywDLrxzLBNq","DMfSDwu","v3Lnv3m","Cur5B2S","BMHzDMK","sLnptLa","sfrquwu","B2jQzwn0u3q","sNfoAMK","sLjnrw4","EwDpvwG","zeDoqM8","t0fQt2e","CNnVCL92ywW","D0Tusum","C0nVDw50zxi","x2rPC3bHDgm","EundDu8","C3bSAwnL","sgfAtfq","A2v5CW","CMvTB3zLq2G","zxmGCMvHy2G","yNL0zxm","BMDLza","uuHitNq","sxPiC00","EKzryMq","C0Xf","EeLAD3a","CgLUz0LUDgu","u2HHCMvKv28","ufv5sgS","qNbusLq","ve92BeO","z2vjBMzVu3K","rwDiq1O","Dg9cExrLC0W","CMPXA28","BKXPBMu","CMvZDwX0","CgjICdi","y2XVC2u","zhDJvvm","DhjHBNnHy3q","CfbltuG","tLfJDgy","EKP6Efu","u0ruq2C","BwvZ","BgLZDgvUtMu","DvLVAxC","zgvJB2rLzey","sfLkCKm","zfPiuue","A3fMD20","AwDHDg9Yt24","q0PRv3C","BMnVzgLUzW","x2n1CNnVCK4","BvbPCNG","igzPzwXKoIa","vgLTzw91Da","seHZqMK","DMXUt0S","D24GCMvHC28","x2LZtwLUAvC","B3jLtMfTzxm","DNbIu0y","Ae1LC3nHz2u","EgzgC3O","Ae5Lv2O","m3W1Fdr8mhW","x2LUDgvYDMe","Bg9N","x0vysvnu","yw51Ce1LC3m","zw5HyMXLuw8","tKrKrwO","tfrlv20","DgfIyxnL","y0nUz2m","q0DOtfu","BxHZq0W","yNvMzMvY","mZa4nJq1mvjOy3zxAW","DK9KAgq","yxbWBgLJyxq","uu5XrLm","x2LZqNjVD3m","zcWG","Ehv1ANm","B1DPu3a","se9xww4","x29UugfNzu4","C2v0y3vYC28","A1n0yxr1C0m","Bg9NsurozxC","se9swem","A1bwt3K","Dw52EfK","Cevlu1m","yxbWBhK","B2zM","C2PVyum","D2zYseG","tevtvKi","t2r4tuG","zg5mC1u","Au1ey3O","y3vYCMvUDeK","BfDIEfy","D09ht0O","zgf0yq","zMLSDgvY","x2LZtM9Kzq","BNruCMLLC0m","ueX2tvC","tMfTzq","ru9AvMO","zsbHihn0CMK","ig1LC3nHz2u","zw5JB2rPBMC","C0T5vgq","y3jLyxrLtwu","uxHmzMu","CeDpz2y","ANfhsuO","zKHZrMe","BNvXqKG","oxWYFdeW","mJu3ovDzwNvfyq","C0LbwNy","ChrVCG","sg5JCgK","wMLnCMO","B25SAw5L","rvjst1i","Dw5KzwzPBMu","C3rHCNq","zcbLCNjVCI4","Dw50","uw1cAe4","vvPhseu","CvLyyM4","txLhqLK","B1nrCwW","yw5ZzM9YBvq","sNDgAKu","m3WYFdb8nhW","swDOq2e","zNjVBNrPzxi","ChjVDg9JB2W","zunrvve","x2LUAxq","yvbnq24","rLDt","ywT4zKO","rfftvwG","zMXOtKO","wLLowfa","t1vpuhq","twzdzMW","q1vOu20","D3jPDgu","DgvmB2Djre4","tgjrDNy","qNjPzgDL","DeLUDgvYy2u","y2vuAum","BvfWtum","uMvJB25Uzwm","C2jfrxG","tvb1Ceq","veXZA20","z2v0q3vYCMu","DhHSwg8","zK5rDhm","uLfSDNy","mJz3rwfWyLy","yxP6Cgu","zhzxCxK","AuzjDNG","BKfrDwe","C3rYAw5NAwy","y3jLyxrLq2W","CYbHBhjLywq","tufyx1jfvfi","sKrsAgu","y2fcBfC","t2fVD2y","B3jRig9MzMW","z3DoyxO","wKzutfO","B25pCgvU","EeX0uhi","vvjjq0e","AvzICMq","twv3zhe","uenHAvO","vxHUC3a","ALfrCw8","veXorK8","yvjZCMC","Dg9hzw5LCMe","Aw50zwDLCIa","Ec11C2uT","DxH4ufO","B2Pfz04","uNveBue","x29Ut3bLBG","vvfxwgS","y3vYDMfSDwu","AK9NuMm","CLfmtgK","y3vZDg9Tshq","ywnOzwqSihC","Bwf4uMv0CMK","CvPwAhu","ohW3Fdf8nNW","z29PBMCGyxC","D0zKEuG","DgLUzYbZzxi","tgTvqui","uK5rrhe","DvjOruK","Dhr3Awq","DvjvueO","B3bLCNr5","yLb3A2K","BgvUz3rO","tffAEw8","Dw9gtM0","t0zewei","B3bLBG","q0z3DLO","tKDWy3K","C2fNzq","B2T3rKK","wNfnsKm","A1zst2O","twzxD2G","t0HhDgW","ENHAzuW","DvPfEhG","rhniqKG","q1Dlt1O","zw5fDMvUDa","suPWDLi","B3ffq3i","yMrFzgLK","yxzbEuW","AfDvqMe","Cg9W","Cgu6ia","zMzMzG","tvbSufu","qMfAsKW","BNrbBMrvCgq","tM90zLa","BwfVCxu","ANDXCe4","ChvZAa","C2v0","BMvJDa","zNjVBu51Bwi","z09eq0e","sMLuuMG","wuTNBfi","BxvjB1a","sKHszge","AefJA01LC3m","EuDlB2i","yMLUyxj5","EMLcENa","Cg53DxG","zxbiDKK","C1fvvNC","DwvQDfe","teHSteu","Ec1TC2CTy3u","B2zMC2v0","o2nOyxjZzxq","Aw9UvgLTzw8","sfH2tLu","ALzjtu4","B2LUDfjLywm","mdaWmdaWmda","u2Tsvhq","x3bPBMDqB24","ruHsCfK","CLHMBha","serkDxq","AxnrB1nby2S","tvP6q2C","vwzvu2K","EgfgC0S","Dg9tDhjPBMC","z21yzhC","ywrK","D3jPDgvvAw4","x0rctMfTzq","B25nzxnZywC","txrnzem","x29UtwvZC2e","zM9YrwfJAa","x3DZ","B3jRzxjhBg8","t2jQzwn0","suDotuW","BwfUDwfSihi","u0TYDgq","t21wqwy","zM9Yy2u","Ahr0Ca","tgLZDgvUzxi","CfzNwhC","y2f3whK","sgXtBeG","tunSr2e","x3bYzwzPEa","B25TzxnZywC","id4G","x3bHDgHlzxK","CMv0CNLdB3u","B25fCNjVCG","q3vZDg9Tq2W","twnhBxG","s21IrMy","t3fru3K","A3zoB0O","v2npt1K","CMfUzg9T","zxjFDhrS","rwPcsfK","uxDRsw0","zMX1C2HfEha","r0jYBu4","y2f0y2G","uNvVvwq","y0vZDhi","DKLnvM8","wgToB0K","D21pDva","AevYCM9Yrxy","A2Txtg4","vKfZq2W","zvPNwem","B2fK","y3vYC29YlNm","B1veEgO","yMXVy2TLza","wu5VvMS","zKvREKC","D2vI","zxjFCw9Z","ww5rqKq","EuTruwW","z0fezMu","ANzQExe","vw5PBxbSzw0","vxbKyxrLq28","C2HPzNq","sfzcz2i","B2nRzxrgywK","rw9dz24","ywnRx2LK","yufgr3e","B3bbqxe","wgvAqxO","zePSu0G","zfL6B3e","v3bVq3q","rgXQzwW","z3DMvfm","D3jNzey","ywHuEuK","y2HHCKnVzgu","qvz0BNG","wwPJtMu","zgvMAw5Luhi","u3H0Egu","uhHitNm","r3D6DwW","q291BNq","mhWXFdr8mNW","x3nLBMrby2S","BM5Ly3q","CMfTzq","qMPmqwW","DfrLChC","ruHdtwu","BgLTAxq","y3frz2S","ww55wvm","x2rLyNvN","vgfdAg8","ihjLy29UBMu","vK93q3a","Aw5KzxG","Aw5Lza","ihrVihjLDhi","B2Xwwfa","BwvZC2fNzq","Dg5lt24","z2HJCxG","DhjPzxmGCMu","txLXq0u","q21ZzKi","q3vZDg9Trxi","q21HyLC","zvfNvwO","rhfytKC","BvPgwM4","zNjHBwvuExa","x3bPBMDmB3m","DNzRsLu","C3vIC3rYAw4","CNzHBa","BMXnD3e","DMHPzxm","CM92AwrLihy","x29Uq2XVC2u","ihzHBgLKigq","BKDTEhm","whbkDM0","ywXS","x2HHBMrSzva","ywr3EuC","x3bPBMC","y0PQsvO","DKrwEe8","ihzHBgLKihm","AwfAuMK","BhfJtxu","tg9Nsuq","twLZC2LUzYa","zgLZywjSzue","CNH5rKC","zKP5q0e","zgrswg8","vK5mqNi","v3fOque","zfLJC2q","AKTOrge","DNzsAwW","rKnWr0u","uLjpuG","v05Rq1O","ywXSB2nvBNm","wNL1Bfu","CNjVCK1LC3m","x29UrxjYB3i","CMvXDwLYzwq","r2T1Agy","u2XezLq","yxnJCMLWDa","C2v0zgi","x2DLDeLUDgu","zMLN","EhLKtgS","Bg9Nsurhzw4","lcbOB3n0BMe","B3jL","shvhCKO","BgjHvfq","sNr0zKi","x3DZsw5ZDge","vLzKEK0","x2LZsw5PDa","vMvwthG","EKXerue","ywjVCNq","x2DLBMvYyxq","mJKWntm4tuPxvuX2","BgLKDfa","CMvJzwL2zwq","Eezrt1q","vfnIEvC","qMTxwuS","x25HDMLNyxq","BxfKv2K","Ce9fugq","sM10ChC","DMLJzuLeig8","mtvfu2PMyuq","C1Hvq0i","zgvSzxrL","A2TwqK0","CLnZt3K","ruHJsM4","Cw1pwvO","r0Hkqva","tg9JAW","vLr3r00","CMvZzxrdB3u","rxHdzLm","qvvMCLO","tLzhuwC","vMTKBw0","zg9REKm","CgXLyxnLiha","s3zKDNO","quXm","BwLZzq","z1fYBeW","AwXLx25HBwu","C3bSAxq","AKvpzMW","AxjLza","y29UBMvJDfm","CgvYC2LZDgu","DK9gBxe","zhDKDgm","Bfvwu1a","wMXWywW","tNPPs0m","CMvHzg9UBhK","AefczwS","vMrOAKW","CgfNzxnOB3C","CM1gExa","zgvS","Cg9PBNrdB24","Ewvxrwi","zMrRCg4","CMvJB25Uzwm","yxbWzw5Kq2G","z09prxG","AvzMAgy","svzdCxC","CgLUz0XVC3m","DMTNrKO","yxKSihrYEsa","rxzLBNq","CLLpBee","BgzMzxq","wM1srxe","wvrZsKS","y3jLyxrLt3a","ihrYEsbYzwm","x2rPC2nVBM4","Bhvbuw4","DMvYC2LVBMm","DhLWzq","BLfky3i","DKLsA0S","yw1wsxO","y29UBMvJDgK","Dg9cExrLCW","BMrLEa","qKnLvw8","B25VCgvU","u0LSsxq","BIWGAg9ZDg4","y29SBM8","CNzwuuq","zgv6u0i","zw50","tujcsMm","uKHKEgi","EvziB1u","yuTorwu","AeLWv3e","y2XLyxi","ChfUvNe","x3nLCuLK","A3rtvLO","tuzWswe","B3brs2S","yuP5wKC","tLL0AgG","q2Hxwwe","Ehfeuuu","BwvLs3e","yM9KEq","B0fJCKe","sLPlvw8","uwvTB1q","zhfpsuW","rvHhD0W","wwTfu3a","AxnrB1nnzxm","r1LPA1e","CMvUDevUzha","ze5ADLK","r1jYs3m","ve1zCLm","Dgv4Dc9Qyxy","Dg9cExrLC0i","yxnL","v2rWvwq","ENLtzvy","uufMy3u","EhbPsuy","D2fZq2XLyw4","CMvQzwn0","qvfbrMW","uwrSDMG","Denlthi","D1vrDui","t1bftG","yxrLq291BNq","Chv0","yxnZAwDU","rKrAqLa","CM92AwrLigi","u09su0e","Bg51Buu","txPXCwC","zLvWqui","A25Izxi","v2vIu29JA2u","C2v0sxrLBq","CvjYs3y","y2HnyxHuCMK","AgfUz2u","y1D4ruG","BMDuAw1LCG","zgvWDgK","y2uGBM90igK","A2LyCfe","qLHRuLq","r21lyMm","AxnbCNjHEq","u3rYyxrLz3K","wevVsLu","EwnNrwm","C2vYDMvYvgK","AuferMy","zw50tgLZDgu","ExrUy20","x2rItMfTzq","wNr0BM4","BLzYuu4","C29Tzq","DhDVCMTdAge","zMLSzw5HBwu","DMf4t3K","BwzbBhe","Bwv0Ag9K","zLn2tvm","uMPADe0","y09Wzw4","D3bSqKK","yMfJA3vWigu","Du1mBuC","tg9NsurozxC","AwDNrKC","u3vjque","twvZC2fNzuu","CMnrD2i","C3nHz2vfDMu","yxv0B21HDgK","Dgv4DfbHEwW","D2HIzhK","x2nSzwfYvgK","tKfusvzfx0u","q3rxz00","AKr3Dvi","B3v0sw50zxi","C3rLBMvYCW","zuHAzK0","y2HLy2Tszwe","ufbzr0y","vLb2rxa","Eg90Axm","icSG","y2LvzKC","weDwuhm","Dev2zw50","D1b2r0O","vMDUAwq","zLfItvi","CMvHzhLtDge","A0fRv1C","zxq9DxrMltG","D0HMrvi","Dwz5r3C","CM92AwrLige","A2vKr3i","se9Xuei","tfbiBe0","zNjVBuj5Dgu","mtCXmtq0ogzqzNzzzW","Ewfor2W","rw52uva","Aw5JBhvKzxm","C2DPza","Bvjquem","tNbVB08","AgPOrhe","y0j3t3i","qwjmvgm","uvfdALu","CeTpww4","yKX4uKO","tg1utxi","tg9WD2C","BwTyAKC","rNnhEM8","tfj0z0C","BgXxweG","y2vZC0HHBMq","yxv0BW","DMPwDKO","Dvr4qM0","CgDoqvO","vfPNBuS","BMnLq2XVC2u","B25szwnLAxy","yNL0zuXLBMC","v2Xwvg0","Dwj0Dgm","B25ozxr3B3i","ywnRpwzYB24","y29UC3rYDwm","BfbotNK","AxnszwfKEq","uvflzwC","AvHjve4","rKr2z0G","y3vYC29Yx24","zcWGDw5RBM8","Dgv4Dc9WBge","x2rLC3rYB3K","sxf0Bwi","t0PIte0","BKHfteC","Agfbwvq","vePiv3G","sgztrg0","u2vXsuq","twnHsha","yw1L","x2LZv29YA2u","qND4EK8","AvvLA3C","EK1JrwC","uMvHzcbWyxm","D3HgAfi","r1PUC08","x1fVu01HBMe","rxDnB0C","D3nZoI8V","Ag5iwuq","C3vIyxjYyxK","C2nYAxb0","vKTsuvu","wLrLzLO","BurAqMK","ywnRtxnNswq","DhjPzxm","BNvTyMvY","zgvSzxrLrge","yw1LoIa","tNnZDuK","A2zxzM4","zhP6C1O","yw5Hz2vY","BwLUAvbYB2C","qvH4A3u","B1vgvuW","zMzmAw5L","ruX0vge","AKHWsuW","vKDksMy","yw1Lu3bHy2u","zMLUza","ANr4DKW","BNbZDeu","AKHeuvK","zg1ny0m","D1btEw0","mxWYFda","swDPrhK","v0TMtxm","ywDL","Cgf5Bg9Hzeu","veTNA2u","Cgf5Bg9Hzfq","rfbOzw4","DMfSDwvZ","sKHJC1m","CMLLC0nVDw4","nxWXFdb8nhW","zM5eyKW","A2v5","AenSB3nLrxy","quzcvwG","Dw5ZAwDUzwq","z1rPBwvVDxq","wePoAvy","BwH2rei","AxmGDw5Kzwy","v2vPEgLUsLm","EhfSDxm","ueDlu2e","ve96z0m","BMCGB3iGyw4","AfjntNO","zwrPyxrLBhK","EMroC04","Eu9uAgG","EsbJBg9Zzwq","m3W0Fdz8nxW","wwPZDKe","BMrWB2LUDfq","Aw5KzxHpzG","twDstMq","ugH4qxu","CgLUz09Uy2u","Ae9Wzw5fDMu","zwn0","uMDvBNO","tufwuw8","AKrYrue","whv6rfe","B1PfyMC","AwTtEMW","CLDMDuS","zgrjrcWGzgu","uvPtrKW","BwfW","BMrWB2LUDca","zw5JB2rLrNi","AgvHzgvYCW","ywXPzcb1CMW","B2XKvMvYC2K","qw1SDKq","D3rurNu","AMHzy00","AgfZt3DUuhi","B25dBg9Zzq","yMLiwg4","r09rreW","uuvxque","wMH0suS","t2vNz1m","ywWGy3vYC28","vMrqteG","A2zkwwe","v29iBuu","A3rMEuG","t1rhuKy","weLLvNC","BMCGDxjSoIa","AxnAzxjV","CMvKDwnL","BNrfBMrWB2K","B25LCNjVCG","wNf4rxu","r2X6rwG","qxbyENm","AenYu3e","mxW1Fdn8nG","ywTIDwW","sxrRCxO","qNziCxC","C2vUza","DgHHBIbSB2m","z2v0qwXSs2u","C3rVCMu","AxfHq2y","B1PiBfa","x2nYzwf0zvm","seHMENm","vuPMufq","ndiYodu2q2jsEM5o","y3vYC29Y","DM9Vsum","BefHtw4","zu1jthy","DxrMofDYAxq","DvnRq3u","qw1VDw50","C2nSte4","ihrPBwvZ","txbTqNe","vwXMywq","B2nRzxq","CIb0DhDjra","rxbvyK0","q09oveLovuu","quH0wwu","uxvXBuC","ihrPBwvVDxq","vgfN","BhrPCgXLihq","rfD0Cxu","zv9ZDwnJzxm","Bvv2t0y","qLruuNm","zMHzzfu","wLbeAKe","yNvMzMvYzwq","ywnRx2nVzgu","BMfTzq","z2v0q3vYC28","Aw9Ul2PZB24","CKPWs24","y3r4","A3z6q3e","BuXWtui","tgvWAgm","qKLRq0O","C3bzyKq","DMvUDa","sNHlrwq","q0Xpu0ve","AMLUDgi","ww52t1G","DgLTzw91DcW","x2fKzfDZtgK","CgLUz1rPBwu","u3nMtNi","zxjFCw9Zx2e","DvHrCfG","m3WWFdf8mNW","sMPXEKG","reiGzMfPBgu","zKDVAg4","Buvqree","vMv6Ehu","Dg9iyxnO","Dhj1y3rVCIa","wMHhBgm","BezSDxnO","y2XVC2uSihC","Aw47y2HHCNm","Ec1TC2CTCw8","zKP3Ae0","ign1CNnVCIa","BM9Uzv9UB24","Bu9zqxy","yuT3DLC","uNP4D1a","Dxrjza","EgLjqvC","sfbuwLm","qM5Yzxq","zg9Uzq","rwflz3O","zMjRAxe","r3LKEKq","ysbTDxn0igi","z2vrDwv1zuW","x29WDgLVBNm","vLL5vw8","DM5fDLG","txvHDwG","BNfUrg4","DgrrsNq","CNzHBfzHBhu","t1bftL9fuLi","C2v0q3vYC28","z2vY","uxHLuwi","zw1PDa","Dw5RBM93BIa","D3bLyNK","AgfZ","zNjVBujPDhm","C2njuhe","BMvY","Dg9XALi","vgjOAK4","rgjAvLe","BuLQyw8","zNjVBuHHC2G","CMvHzhDYAxq","C1vNz1K","y3vYCMvUDeu","DeHssey","EKnyBfu","BNrLCG","AxDLyK4","qNbQqLe","BgvY","AgTHAwO","yxGGCMv0CMK","rxLVuKe","x2vUzhbVAw4","vxDMvMS","yKP3sMC","sLbXwLO","y29UBMvJDa","C2XPy2u","y3jLyxrLrxi","De1HBMfNzxi","zxjYtxnN","D2zXDum","C2v0u3rVCMe","Dg9mB3DLCKm","r295BLK","sw9yAxi","uhjPBwfYEuS","ChjVy2vZCW","uu1JqLy","BwvY","u1nms3C","EwDuzxq","D01Otxa","uxvLDwu","u3bbrxO","CMTLCKDSB2i","x3bYB3rVy28","B2nRzxrtDwm","C3n3C3e","ywDLu2HVDW","CePgDhK","zv90Aw1LB3u","EuD3CeO","x2LZtwLUAvq","x2HHBMrSzu8","rKLYuvK","t2LJDLK","CgLUz19VBMm","ALHTsMm","B25tDg9Wsw0","t215s0O","yxHsyuW","wM1sEMS","Bwf4tg9ZC0m","BvvJtfC","vKPsC2K","wwnjyKC","BMTRCgm","DurPCKm","z2v0","uM9ZvhK","DNPrDhO","sNrIrue","zfDVCMTLCKC","vLLZC3y","AwXLtMfTzq","CKfVrKC","EungvwS","shn4wfm","Bg93","sMzdu1y","tuL3y3K","CYbWyxjHBxm","BML0AwfSAxO","BvLoEgu","zxH0zw5ZAw8","ChbL","x21PBMLoyxy","AfHOqxq","wgP0vLu","z2v0t3DUuhi","BunqAva","shz3v1u","vw1Zyu4","sNjwzMu","zu9YBKu","uhn3sKy","B25Uzwn0Aw4","A1PfyKK","uunzEfG","CgfNzwHPzgu","uMPYr1u","Eu5rqxu","Cg9PBNrbBMq","AePQAum","ywDLsgLKzq","uwHcwNe","C2vYDMLJzs0","rezfyNu","mNWWFdr8m3W","yuDky1a","t3rdB2u","BhDOCNi","DKXjCK4","ru9Zrgi","uLD1Ahq","A1zXweW","r3P5Bhy","C29YDa","sxfJBfK","surjAhm","C3zLDwS","EeLJvui","Aw1byLe","CMvZB2X2zq","B2rJvwK","rwzvv08","rfLPA3a","Eurusxa","s09JzvO","yMfSrxzLBNq","ywfyr2m","vNz1vMe","y29UDgLUDwu","D09rBNq","mNW0Fdv8m3W","z2vtEw5J","x2nSzwfYugK","Aw5KzxGGB3u","B25mAw5L","uKvnCha","EKPjv2i","EvjLy29UBMu","zxjYB3i","v1rOChi","qKLNvfO","BgnLsgC","B3jpBMXPBMu","C0jf","x2XPC3rLBMu","yNL0zu9MzNm","y3ruAw1LB3u","CgT3svG","BgPNqKm","x3vYBa","CNrZD3G","DxjS","x3nVy2TLDa","zw5HyMXLvhi","ugXss3q","zw1LBNq","x19LC01Vzhu","DvH6s2y","uKnMv1a","x2jPBMfYEvq","ugzZzK8","A3vnq1K","qvDzBKe","AMvJDfn0B3i","zxrxB3jRq2G","A2nnu2O","AwXK","wNfKwKW","wfDir2u","BK1xDNC","zKDvBKy","t3bLBKv2zw4","vgvZELC","vujRv0i","AxnmB25N","A2nyt08","q0zcDe4","z2v0qwXS","Aw9U","EuLVwMC","weLsvLK","A09oCxq","ywnR","y29Uy2f0","rg5euhC","BNbIv3K","CMvHzfvjBNq","CfHKvei","rNjVBNrPzxi","zxjFBxnNAwq","wufAuve","rKjAEMO","C1Lytvq","Eezes2i","zvzrCg8","Euzxwxa","ywzL","B21lCvG","CYbPBNn0yw4","x2HHBMrSzvi","y2HLy2TdDxi","y2XVC2veqG","ywrKrxzLBNq","BxP5rM8","CfDKwvi","BxnNsuq","B0Tqwfm","y2HnyxHdB3u","q29UzMLN","uLnYB3K","z3rpv3K","zvrcvxi","EuHpyw4","ywrKq291BNq","y29UBMvJDca","zxjYtM8","z2v0s2v5","Aw5L","C0XPC3rLBMu","AgnvrNq","AgLNAa","sMLUANq","DgvZDa","v0LWD1q","DKHUy3a","zNjVBunOyxi","teLXENK","B3bLBIa","reHjv3C","AgvKtwf4uMu","yMLUyxj5vhK","AKv2t0K","tMTJz08","x2nVBM5Ly3q","yuziEMe","y0jUEwy","CMrPruW","D3m6lY8","t29Lq3y","Cxjtt0S","DxbNCMfKzw4","rNb6EKm","CMvZzxrfBMq","y291BNq","DxrVuMvJB24","y3jLyxrLt2i","CKzKwLy","Aunqr1m","ExbL","y29UBMvJDeu","vNrZtuC","x3DHAxq","Ag1st2m","DMr5z1m","uvPUv2i","AM9PBG","DgHLBG","CM9YrxzLBNq","v3bRD1m","yxKSig5LDhC","D2LSBfjLy28","yw5Nzq","zw5XDwv1zq","yxrHlcbKyxq","rfPJwKC","BM93","ywnRDxbfBMq","zvvYBa","q0Xpu0LorW","ywTcuNa","C3vJy2vZCW","y2Pgq1q","zwnVBM5Ly3q","sg9Xvxa","Aw5N","Agr2y2m","DKH4t2y","tuvtu0fhrv8","q29Kzq","BwLUzW","vfnLs0q","Cgf5Bg9Hza","D0HzuNq","u1jJswi"];return So=function(){return t},So()}function jE(t){let e=L,r={TOzgC:"success",MClGa:function(o,c){return o(c)},VJRsi:function(o){return o()},HrJdP:function(o,c){return o(c)},eGpRW:e(1437),eJLSi:function(o,c){return o(c)},kPVOy:function(o,c){return o!==c},FtIQu:e(1819),nmoCX:e(1204)},i=new Promise((o,c)=>{let l=e,u=()=>{let m=U;t[m(1779)+m(964)+m(1298)](r[m(1132)],f),t[m(1779)+"entListe"+m(1298)](m(1437),x)},f=()=>{let m=U;r[m(653)](o,r[m(653)](Mt,t[m(1874)])),r[m(1359)](u)},x=()=>{let m=U;r.HrJdP(c,t[m(1437)]),r[m(1359)](u)};t[l(1501)+l(649)]("success",f),t[l(1501)+l(649)](r.eGpRW,x)});return i[e(1555)](o=>{let c=e,l={VhlqM:function(u,f){return r.eJLSi(u,f)},NfSQC:function(u,f){return u+f}};if(o instanceof IDBCursor)if(r[c(433)](r.FtIQu,r.nmoCX))il[c(597)](o,t);else{let f=""+_0x1cce39[c(1564)](),x=_0x3a654e||(_0xd7d99=l.VhlqM(_0x41144a,_0x12f8c5)),m=_0xf3e304[c(666)]()[c(631)](16)[c(1321)](-6);return l.NfSQC("02"+f+x,m)}})[e(672)](()=>{}),Ao[e(597)](i,t),i}function WE(t){let e=L,r={wtTFu:function(o,c){return o>>>c},mYNxe:function(o,c){return o|c},xIcUB:function(o,c){return o<<c},XacaF:function(o,c){return o===c},Pthoh:function(o,c){return o<c},eOrnE:function(o,c){return o<c},MIwcy:function(o,c){return o<c},IOGUF:function(o,c){return o<c},sjoaC:function(o,c){return o!==c},xIZwp:function(o,c){return o+c},cCngc:function(o,c){return o>>>c},eMILv:function(o,c){return o!==c},sXUCB:function(o,c){return o+c},VVdzM:function(o,c){return o>>>c},kuMCY:function(o,c){return o&c},ysdLS:function(o,c){return o>>>c},DqXNG:function(o,c){return o+c},EaFnX:function(o,c){return o!==c},npstE:function(o,c){return o&c},JHRda:function(o,c){return o!==c},BvHqw:e(1595),QSVEt:"hxDEr",OeggS:e(1688)+"or",fJyCA:function(o){return o()},vkgFJ:e(1437),ZGMNu:e(806)};if(Io.has(t))return;let i=new Promise((o,c)=>{let l=e,u={fSvMS:l(806),eZgXC:function(w){return r[l(773)](w)}},f=()=>{let w=l;t[w(1779)+w(964)+w(1298)]("complete",x),t[w(1779)+w(964)+"ner"](w(1437),m),t[w(1779)+w(964)+w(1298)](u[w(975)],m)},x=()=>{let w=l;u[w(681)](o),u[w(681)](f)},m=()=>{let w=l,b={UfUSi:function(p,_){return r[U(1164)](p,_)},HoqUp:function(p,_){return r[U(1378)](p,_)},wrgdF:function(p,_){return r[U(1416)](p,_)},HDJut:function(p,_){return r[U(1164)](p,_)},eIjye:function(p,_){return r[U(1817)](p,_)},TeszW:function(p,_){return r[U(1817)](p,_)},EftCS:function(p,_){return r[U(1641)](p,_)},PUyHk:function(p,_){return r[U(1389)](p,_)},lceHg:function(p,_){return r[U(1375)](p,_)},nduPb:function(p,_){return r[U(1748)](p,_)},yKufL:function(p,_){return r.MIwcy(p,_)},USbsS:function(p,_,S){return p(_,S)},WyXAg:function(p,_){return p&_},zdNsN:function(p,_){return p+_},akElY:function(p,_){return r[U(438)](p,_)},MBBJc:function(p,_){return r[U(1863)](p,_)},WlVTm:function(p,_){return p!==_},aFHza:function(p,_){return r[U(1915)](p,_)},SlDfT:function(p,_){return p&_},hIpWq:function(p,_){return r[U(1206)](p,_)},dJlSH:function(p,_){return p>>>_},kqfwm:function(p,_){return p>>>_},cqQgk:function(p,_){return r[U(820)](p,_)},hJjiC:function(p,_){return r[U(802)](p,_)},fdkpn:function(p,_){return r[U(1460)](p,_)},wTgGS:function(p,_){return r.ysdLS(p,_)},JgwVX:function(p,_){return r[U(746)](p,_)},vnEvX:function(p,_){return p!==_},CPmnn:function(p,_){return r[U(1378)](p,_)},eiEAs:function(p,_){return r.eMILv(p,_)},QemoT:function(p,_){return r.wtTFu(p,_)},CUhSm:function(p,_){return p|_},eVQpo:function(p,_){return r.EaFnX(p,_)},QuqmG:function(p,_){return r.ysdLS(p,_)},XWHGe:function(p,_){return r[U(1104)](p,_)},xfFsz:function(p,_){return p&_}};if(r[w(604)](r[w(1192)],r.QSVEt))c(t.error||new DOMException(r[w(1172)],r[w(1172)])),f();else{let p=_0x224c63[w(1373)]>>>0,_=b.UfUSi(b[w(1572)](b[w(629)](_0x582c68[w(1373)],28),b[w(709)](_0x53ecb1[w(1519)],4)),0),S=b[w(626)](_0xd5ba49[w(1519)],24),A=b[w(1626)](0,S)?b[w(1471)](0,_)?b.EftCS(p,16384)?b[w(1866)](p,128)?1:2:b[w(1440)](p,2097152)?3:4:b.nduPb(_,16384)?b.lceHg(_,128)?5:6:_<2097152?7:8:b.yKufL(S,128)?9:10,T=b.USbsS(_0x13ae0a,_0x39b692,A),D=_0x1a38bc[w(1857)];switch(A){case 10:D[T+9]=b[w(1775)](b.UfUSi(S,7),1);case 9:D[b[w(1136)](T,8)]=b.akElY(9,A)?b[w(1572)](128,S):b[w(1775)](127,S);case 8:D[b.MBBJc(T,7)]=b[w(1046)](8,A)?b[w(1533)](_,21)|128:b[w(789)](_>>>21,127);case 7:D[b[w(893)](T,6)]=b[w(897)](7,A)?b[w(704)](_,14)|128:b[w(1775)](b[w(1889)](_,14),127);case 6:D[b[w(727)](T,5)]=A!==6?b[w(1572)](b[w(1398)](_,7),128):b[w(859)](b[w(1698)](_,7),127);case 5:D[b[w(1734)](T,4)]=b[w(1283)](5,A)?b[w(1603)](128,_):b.fdkpn(127,_);case 4:D[b[w(893)](T,3)]=b.eiEAs(4,A)?b[w(1572)](b.kqfwm(p,21),128):b[w(912)](p,21)&127;case 3:D[b[w(1734)](T,2)]=A!==3?b[w(497)](b[w(1398)](p,14),128):b[w(1775)](p>>>14,127);case 2:D[T+1]=b[w(1493)](2,A)?b[w(1572)](b[w(1219)](p,7),128):b[w(1467)](b.aFHza(p,7),127);case 1:D[T]=b.eVQpo(1,A)?b[w(1572)](128,p):b[w(1904)](127,p)}}};t["addEvent"+l(649)](l(1747),x),t[l(1501)+"Listener"](r[l(866)],m),t[l(1501)+l(649)](r.ZGMNu,m)});Io[e(597)](t,i)}function KE(t){To={NkfWk:function(r,i){return r(i)}}.NkfWk(t,To)}function $E(t){let e=L,r={GKrfD:function(i,o){return i(o)},GRrKs:function(i,o){return i(o)},Oaowf:function(i,o,c,l){return i(o,c,l)},MrxpK:e(1631)+e(1250)+"ck",pPKMH:function(i,o,c,l){return i(o,c,l)},Tszej:e(1631)+e(1777)+"k",UUsYB:function(i,o,c){return i(o,c)},JrVfe:e(1631)+"er_ack_msgid",QidWG:function(i,o){return i===o},QAfcu:e(1579),lFYPR:function(i,o){return i in o},kfJYa:"objectSt"+e(1901),jDwuR:function(i){return i()}};return t===IDBDatabase.prototype[e(1878)+e(1477)]&&!r[e(1672)](r[e(1175)],IDBTransaction[e(1763)+"e"])?function(i,...o){let c=e,l=t.call(Hi(this),i,...o);return rl[c(597)](l,i[c(1412)]?i[c(1412)]():[i]),Mt(l)}:r[e(993)](GE)[e(1021)](t)?function(...i){let o=e;return t[o(436)](r[o(1697)](Hi,this),i),r[o(920)](Mt,il[o(1363)](this))}:function(...i){let o=e,c={zMcEg:"x_fronti"+o(689),dokzC:function(l,u,f,x){return r[o(524)](l,u,f,x)},QHHNt:r.MrxpK,hcUFt:function(l,u,f,x){return r[o(1879)](l,u,f,x)},ZRZle:r.Tszej,TLNFO:function(l,u,f){return r[o(1723)](l,u,f)},mEQNf:r[o(1388)]};if(r.QidWG(r[o(927)],r[o(927)]))return r[o(920)](Mt,t[o(436)](r.GKrfD(Hi,this),i));{let l=!!this[o(1281)][o(1911)+"S"];if(!l)return{enabled:l,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let u=_0x21c5d7(_0x321f9e.message[o(1160)],c[o(1072)],"2"),f=u&&c[o(834)](_0x5d55a6,_0x3375ad[o(737)][o(1160)],c[o(1859)],"1"),x=u&&c[o(1518)](_0x519d02,_0x370109.message[o(1160)],c[o(1695)],"1"),m=x?c[o(536)](_0x30df0f,_0x51462a[o(737)][o(1160)],c.mEQNf)?.split(",")[o(448)](_0x3b689d)||[]:[];return{enabled:l,isQoSMessage:u,isQoSAck:f,isAckCleanupMessage:x,ackMsgIds:m}}}}function VE(t){let e=L,r={rcQwb:function(i,o){return i===o},deCPE:"function",jqGIJ:function(i,o){return i(o)},HvwWU:function(i,o){return i instanceof o},vpbSF:function(i,o){return i(o)},fZYgJ:function(i,o,c){return i(o,c)},JbMNB:function(i){return i()}};return r[e(985)](typeof t,r.deCPE)?r[e(461)]($E,t):(r[e(1386)](t,IDBTransaction)&&r[e(1902)](WE,t),r[e(1683)](nh,t,r[e(1596)](qE))?new Proxy(t,To):t)}function Mt(t){let e=L,r={PPYGF:function(o,c){return o instanceof c},WKfMs:function(o,c){return o(c)}};if(r[e(998)](t,IDBRequest))return r[e(1110)](jE,t);if(bo.has(t))return bo[e(1363)](t);let i=r[e(1110)](VE,t);return i!==t&&(bo[e(597)](t,i),Ao[e(597)](i,t)),i}var nh,Z0,Y0,il,Io,rl,bo,Ao,To,Hi,X0=th({"node_modules/idb/build/wrap-idb-value.js"(){let t=L,e={Itkqz:function(r,i){return r===i},VYyUo:t(1841)+t(1901),hrnmi:"hmROc",LtYRV:t(1196),ouYBj:function(r,i,o){return r(i,o)},FjBdy:function(r,i){return r!==i},fNQts:t(664),DFEbu:t(1374),JBqnx:function(r,i){return r instanceof i},QMcBV:t(1275),XWXYF:function(r,i){return r in i}};nh=(r,i)=>i[t(969)](o=>r instanceof o),il=new WeakMap,Io=new WeakMap,rl=new WeakMap,bo=new WeakMap,Ao=new WeakMap,To={get(r,i,o){let c=t;if(r instanceof IDBTransaction){if(e[c(1191)](i,c(1275)))return Io.get(r);if(e[c(1191)](i,e[c(1282)])){if(e[c(1191)](c(1551),e[c(1715)]))return r["objectSt"+c(1901)]||rl[c(1363)](r);_0x3af18b[c(1908)](_0x304a69)}if(i===e[c(1820)])return o[c(1841)+c(1901)][1]?void 0:o[c(1841)+c(797)](o[c(1841)+c(1901)][0])}return Mt(r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t,c={ZIIgy:function(l,u,f){return e[U(1628)](l,u,f)}};if(e.FjBdy(e[o(511)],e[o(1402)]))return e[o(1634)](r,IDBTransaction)&&(e[o(1191)](i,e[o(1332)])||e[o(1191)](i,e[o(1820)]))?!0:e.XWXYF(i,r);_0x41d5b6(_0x228122,8),c[o(1808)](_0x4542b4,_0x3fdf46,_0x29c0e6)}},Hi=r=>Ao[t(1363)](r)}}),rh={};HE(rh,{deleteDB:()=>ZE,openDB:()=>JE,unwrap:()=>Hi,wrap:()=>Mt});function JE(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let l=L,u={Kvdvz:function(m,w){return m(w)},QqsZd:function(m,w){return m(w)},KmNSt:function(m,w){return m<<w},kVqXL:function(m,w){return m&w},DbZVQ:function(m,w){return m(w)},HsxXS:function(m,w){return m<<w},MpmBq:function(m,w){return m===w},RgUnz:"Retlt",Iilbs:"osMId",dezSB:l(877)+"hange",VGJJf:l(1539)+"eeded",GZnsO:l(685)},f=indexedDB[l(568)](t,e),x=Mt(f);return i&&f[l(1501)+l(649)](u[l(1100)],m=>{let w=l;i(u[w(836)](Mt,f[w(1874)]),m[w(1162)+"on"],m[w(1730)+"on"],Mt(f["transact"+w(1477)]))}),r&&f[l(1501)+l(649)](u[l(1075)],()=>r()),x[l(1555)](m=>{let w=l,b={HPTZS:function(p,_){return u.QqsZd(p,_)},ktSVZ:function(p,_){return u[U(1655)](p,_)},LZvIy:function(p,_){return u[U(1410)](p,_)},tdQJt:function(p,_){return u[U(1410)](p,_)},KmbFf:function(p,_){return p<<_},lWbxV:function(p,_){return p&_},BCeUo:function(p,_){return u[U(1301)](p,_)},lwhrr:function(p,_){return u[U(1410)](p,_)},ktfyH:function(p,_){return u[U(1372)](p,_)}};u[w(1212)](u[w(1148)],u.Iilbs)?(_0x1f48d5=b[w(1273)](_0x33e37d,_0x41d1ce),_0x1ca3d5|=b[w(901)](b[w(1686)](127,_0x4ed4e6),14),b[w(1286)](128,_0x7d6931)&&(_0x285cdb=b[w(1273)](_0x2a78db,_0xd70a1d),_0x1edc98|=b[w(662)](b.lWbxV(127,_0x1f9774),21),b[w(445)](128,_0x2fb8f8)&&(_0x3d6fdd=b[w(885)](_0x2df126,_0x5c8b9a),_0x41aae5=b[w(1286)](127,_0x2ecdae),b[w(1406)](128,_0x5885c1)&&(_0x1040a8=b[w(1273)](_0x49b644,_0x48da9b),_0x449f90|=b[w(1177)](127&_0x3acda9,7))))):(c&&m["addEvent"+w(649)](w(1876),()=>c()),o&&m[w(1501)+w(649)](u[w(891)],()=>o()))})[l(672)](()=>{}),x}function U(t,e){t=t-417;let r=So(),i=r[t];if(U.hHsaFa===void 0){var o=function(f){let x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",m="",w="";for(let b=0,p,_,S=0;_=f.charAt(S++);~_&&(p=b%4?p*64+_:_,b++%4)?m+=String.fromCharCode(255&p>>(-2*b&6)):0)_=x.indexOf(_);for(let b=0,p=m.length;b<p;b++)w+="%"+("00"+m.charCodeAt(b).toString(16)).slice(-2);return decodeURIComponent(w)};U.OxcoTn=o,U.OLGnZP={},U.hHsaFa=!0}let c=r[0],l=t+c,u=U.OLGnZP[l];return u?i=u:(i=U.OxcoTn(i),U.OLGnZP[l]=i),i}function ZE(t,{blocked:e}={}){let r=L,i={HKhFS:r(685),EwMoG:function(c,l){return c(l)}},o=indexedDB[r(1088)+r(1914)](t);return e&&o[r(1501)+r(649)](i[r(1657)],()=>e()),i[r(1077)](Mt,o)[r(1555)](()=>{})}function Q0(t,e){let r=L,i={HjSlW:r(1304)+"e",tTepw:r(851),pOvre:function(f,x){return f instanceof x},mfAlq:function(f,x){return f in x},TOvlJ:function(f,x){return f===x}};if(!(i[r(1729)](t,IDBDatabase)&&!i[r(973)](e,t)&&i[r(1868)](typeof e,"string")))return;if(vo[r(1363)](e))return vo[r(1363)](e);let o=e.replace(/FromIndex$/,""),c=e!==o,l=sh[r(1021)](o);if(!i[r(973)](o,(c?IDBIndex:IDBObjectStore)[r(1763)+"e"])||!(l||ih[r(1021)](o)))return;let u=async function(f,...x){let m=r,w=this[m(1878)+m(1477)](f,l?i.HjSlW:i[m(724)]),b=w[m(1196)];return c&&(b=b[m(733)](x[m(696)]())),(await Promise[m(760)]([b[o](...x),l&&w.done]))[0]};return vo.set(e,u),u}var ih,sh,vo,YE=th({"node_modules/idb/build/index.js"(){let t=L,e={Iqtmb:function(r){return r()},ziBzp:t(1363),QxLfe:t(1476),zmzKs:t(1195)+"ys",UXYDW:t(1542),akBRp:t(937),zIXnx:t(633),BjLAl:t(821),ZhtIK:function(r,i){return r(i)}};e[t(1060)](X0),X0(),ih=[e[t(608)],t(1515),e[t(459)],e[t(1735)],e.UXYDW],sh=[e[t(1568)],e.zIXnx,e[t(723)],t(898)],vo=new Map,e[t(1171)](KE,r=>({...r,get:(i,o,c)=>Q0(i,o)||r.get(i,o,c),has:(i,o)=>!!Q0(i,o)||r[t(1295)](i,o)}))}}),XE={idb:function(t){let e=L;t[e(1652)]=Promise[e(1418)]()[e(1555)](()=>(YE(),rh))[e(1555)](function(r){return r})}},eh={};function Nt(t){let e=L,r={JttfB:e(719)+"3",CmabW:function(u,f){return u!==f}},i=r[e(800)].split("|"),o=0;for(;;){switch(i[o++]){case"0":var c=eh[t];continue;case"1":if(r[e(744)](void 0,c))return c[e(1652)];continue;case"2":XE[t](l,l[e(1652)],Nt);continue;case"3":return l[e(1652)];case"4":var l=eh[t]={exports:{}};continue}break}}Nt.d=(t,e)=>{let r=U;for(var i in e)Nt.o(e,i)&&!Nt.o(t,i)&&Object[r(714)+"operty"](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=L;Nt.o=(e,r)=>Object[t(1763)+"e"][t(1166)+t(562)][t(1755)](e,r)})(),(()=>{let t={oUDxj:"undefined",fDubC:"Module"};Nt.r=e=>{let r=U;t[r(684)]!=typeof Symbol&&Symbol[r(631)+"Tag"]&&Object[r(714)+r(562)](e,Symbol["toString"+r(1221)],{value:t.fDubC}),Object[r(714)+r(562)](e,r(1455)+"le",{value:!0})}})();var Ce={};(()=>{let t=L,e={epHvI:function(a,n){return a+n},tHRHF:function(a,n){return a+n},xotis:function(a,n){return a*n},NQctf:function(a,n){return a(n)},BkWYK:function(a,n,s){return a(n,s)},VNLBr:function(a,n,s){return a(n,s)},dZHQA:function(a,n){return a+n},jvjyq:t(1776),vLIrN:t(589),mLpMB:"00000000"+t(621)+t(621)+t(621),HaZLT:function(a,n){return a>n},maoqu:function(a,n){return a&n},PhxAu:function(a,n){return a+n},WLCmj:function(a,n){return a>n},SiaIZ:function(a,n){return a<n},rWfuK:function(a,n){return a!==n},LtDAk:"rOeoe",GgXZX:t(1782),wllcU:function(a,n){return a-n},VtsMG:function(a,n){return a===n},ycgEc:function(a,n){return a!==n},YsRyH:t(1300),JPqZZ:function(a,n){return a!==n},MtMdC:function(a,n,s){return a(n,s)},RuDmA:function(a,n,s){return a(n,s)},lbaTT:function(a,n){return a(n)},FIrQY:function(a,n){return a(n)},YcIbG:function(a,n,s){return a(n,s)},ZOiJU:function(a,n){return a&n},qZVhu:function(a,n){return a===n},ENZpT:t(770)+"required"+t(1895)+"key",Ulfad:t(770)+t(787)+t(1895)+t(1835),cBnyf:"kxlwX",kzpeP:function(a){return a()},EofgV:t(1569),LHlLE:"error",EpUbM:function(a,n){return a(n)},pGOgf:t(516),WTrxq:function(a,n,s){return a(n,s)},OoeCv:function(a,n){return a!==n},aJrKW:function(a,n,s){return a(n,s)},nMOBn:function(a,n,s){return a(n,s)},TLYDQ:function(a,n,s){return a(n,s)},pWdYR:function(a,n,s){return a(n,s)},DAxWN:function(a,n){return a!==n},mxsCL:function(a,n){return a(n)},ljgBC:function(a){return a()},HTPQe:function(a,n){return a!==n},Gwzul:t(1149),EgHCZ:function(a,n,s){return a(n,s)},yoYgh:function(a,n,s){return a(n,s)},MgRNd:function(a,n){return a!==n},fGQuy:t(1648),ZPDjA:function(a,n,s){return a(n,s)},RNQDq:function(a,n,s){return a(n,s)},Lopwg:function(a,n,s){return a(n,s)},OmyKJ:function(a,n,s){return a(n,s)},jXmJc:function(a,n){return a>=n},XNdjJ:function(a,n){return a!==n},wPSym:t(804),jSqVp:"AjgMb",oUFUL:function(a,n){return a(n)},VbeDu:function(a,n,s){return a(n,s)},QIqiX:function(a,n){return a(n)},mCPiP:function(a,n,s){return a(n,s)},eCQUQ:function(a,n){return a(n)},wHfER:function(a,n){return a(n)},oqECr:function(a,n,s){return a(n,s)},yCFUk:"Missing required"+t(1895)+t(1066),UEMnF:t(770)+t(787)+t(1895)+t(769),qpnjZ:"Missing "+t(787)+t(1895)+t(1617),mhvDB:t(770)+t(787)+t(1895)+t(974),GHJAP:function(a,n){return a+n},XjtVU:function(a,n){return a(n)},dqOIL:function(a,n,s){return a(n,s)},uSkCu:t(694)+t(1809)+t(588),IvPxR:function(a,n){return a>>n},ecjqa:function(a,n){return a>=n},uejtQ:function(a,n){return a===n},oZEbg:function(a,n){return a+n},adsro:"Skip past limit",scIPq:function(a,n){return a*n},LmGva:function(a,n){return a>n},opQKk:function(a,n){return a===n},flhNJ:t(1305),uRUPJ:function(a,n){return a+n},wplBI:"idb",GOQDL:function(a,n){return a===n},lAaMn:function(a,n){return a&n},DqCIA:function(a,n){return a(n)},oSQql:function(a,n){return a===n},fGohn:function(a,n){return a!==n},xLbdY:function(a,n){return a!==n},Lfims:function(a,n){return a|n},LRtgG:function(a,n){return a<<n},GyZcm:function(a,n){return a&n},EOZVj:function(a,n){return a<n},pJFty:function(a,n){return a==n},NkcgO:function(a,n){return a+n},UJfPT:function(a,n){return a&n},FIXaX:function(a,n){return a<<n},mkXjG:function(a,n){return a&n},CFwvZ:function(a,n){return a+n},OHGtl:function(a,n){return a+n},QhBZq:function(a,n){return a+n},ufyGw:function(a,n){return a+n},IGNML:function(a,n){return a<<n},LIqzy:function(a,n){return a!==n},lidtP:"JDRhe",oRSfq:function(a,n){return a|n},akbul:function(a,n){return a|n},OTGRF:function(a,n){return a<<n},BIkCJ:function(a,n){return a&n},aGJcP:function(a,n){return a&n},wOGOJ:function(a,n){return a<n},Hncpi:t(575),xFDKb:function(a,n){return a+n},rgrHx:function(a,n){return a&n},WcOOY:function(a,n){return a+n},YnyYS:function(a,n){return a!==n},ZqMJC:"bWjyR",HVBgb:function(a,n){return a<=n},ZFTLZ:function(a,n){return a+n},ipxxk:function(a,n){return a+n},wmOuP:function(a,n){return a<<n},JxKEd:function(a,n){return a<n},yDTIp:function(a,n,s){return a(n,s)},AQAFl:function(a,n){return a<n},ygTet:function(a,n){return a-n},Jmtpw:function(a,n){return a<n},NotfP:function(a,n){return a|n},iJLTj:function(a,n){return a>>n},XGVPs:function(a,n){return a>>n},nQJcr:function(a,n){return a|n},FDZBP:function(a,n){return a&n},rAoFG:function(a,n){return a|n},adwyG:function(a,n){return a&n},zFQbd:t(710),dGNBo:t(1198),ZqxEu:function(a,n){return a+n},ApXzs:"is_ack",YnvOX:t(700),mUcLW:function(a,n){return a||n},VKRQU:t(1230),IGtoV:function(a,n){return a===n},MYQdT:t(1040),dYcsd:t(1026),fGUnF:t(1236),jOgRc:function(a,n){return a(n)},GmKbc:function(a,n){return a<<n},mqdWi:function(a,n){return a|n},hdvcc:function(a,n){return a&n},hfegD:"close",jHDQY:function(a){return a()},iggFG:function(a,n){return a(n)},JiTRh:function(a,n){return a<<n},IqclY:function(a,n){return a&n},DPhen:function(a,n){return a!==n},kCdrF:t(646),xuujs:function(a,n){return a&n},ZmRzk:function(a,n){return a&n},ylkmO:function(a,n){return a(n)},UmsaN:function(a,n){return a&n},meeKq:t(825),ELtTa:t(896),FDvgH:function(a,n){return a(n)},VuCjV:function(a,n){return a&n},TaCho:function(a,n){return a===n},KJPgE:t(1459),SkRTt:t(1527),vdygS:function(a,n){return a(n)},xJbMf:function(a,n){return a&n},WGzaw:function(a,n){return a&n},nqnDn:function(a,n){return a|n},zxZeL:function(a,n){return a<<n},XIeVw:function(a,n){return a>>>n},bLxRJ:function(a,n,s){return a(n,s)},llWXH:t(1453),lffet:function(a,n){return a>>>n},cmrCa:function(a,n){return a|n},CWKOZ:function(a,n){return a>>>n},Vezxu:function(a,n){return a===n},YAZQQ:function(a,n){return a===n},sclLN:function(a,n){return a<n},MFpIa:function(a,n){return a<n},Lephc:function(a,n){return a>>>n},HXvNU:function(a,n){return a+n},nAQua:function(a,n){return a|n},DZcZG:function(a,n){return a+n},yOThh:function(a,n){return a!==n},vgjFn:function(a,n){return a|n},gtOWy:function(a,n){return a>>>n},Ivmww:function(a,n){return a|n},BpTJT:function(a,n){return a!==n},ygOUh:function(a,n){return a|n},cADET:function(a,n){return a&n},gwNaz:function(a,n){return a+n},UnpTd:function(a,n){return a>>>n},EOsDb:function(a,n){return a+n},RERRi:function(a,n){return a!==n},RuoUd:function(a,n){return a|n},mIjao:function(a,n){return a>>>n},fHsFa:function(a,n){return a&n},iiJCt:function(a,n){return a>>>n},rSsOy:function(a,n){return a!==n},SsfNr:function(a,n){return a|n},nhYvi:t(850),jKkMq:function(a,n){return a|n},kkWLn:function(a,n){return a|n},uZExx:function(a,n){return a+n},FBZzj:t(1073)+t(1750),JBbBt:function(a,n){return a===n},hxWus:"TORmE",GYikQ:function(a,n){return a|n},BIgTZ:function(a,n){return a<<n},CmsfB:function(a,n){return a|n},Mewdq:function(a,n){return a|n},mzyFo:function(a,n){return a|n},dnLsU:function(a,n){return a|n},fUpAB:function(a,n){return a<<n},EfUWO:function(a,n){return a===n},kcMSj:function(a,n){return a>>>n},yGKob:function(a,n){return a|n},obDuc:function(a,n){return a<<n},vjVvJ:function(a,n){return a<<n},gOOEx:function(a,n){return a|n},aPMCn:function(a,n){return a|n},wPvGJ:function(a,n){return a&n},Ahnuo:function(a,n){return a>>>n},sYXMT:function(a,n){return a&n},WIpwT:t(747),qWpoN:t(590),JjqzH:"SgVAE",eTBUr:function(a,n){return a>=n},zxaHC:function(a,n){return a%n},lUVSP:function(a,n){return a||n},FabJi:function(a,n){return a!==n},kedGr:t(1860),okwFI:function(a,n){return a+n},aaXGc:function(a,n){return a>>>n},KOceZ:function(a,n){return a>>>n},pqnVq:function(a,n){return a*n},qjjUK:function(a,n){return a===n},fhYdU:function(a,n){return a>>>n},XIRVY:function(a,n){return a>>>n},xpiIF:function(a,n){return a+n},pVgXw:function(a,n){return a+n},LQZyo:function(a,n){return a>>>n},LmTMr:function(a,n){return a|n},LPHlM:function(a,n){return a<<n},HvojS:function(a,n){return a===n},ceTiC:function(a,n){return a>>>n},qrSOK:function(a,n){return a>>>n},vaxOy:function(a,n){return a===n},kLIlF:function(a,n){return a===n},Muauh:function(a,n){return a+n},RCfWP:function(a,n){return a&n},qYUQa:function(a,n){return a&n},hXhAt:function(a,n){return a&n},wHYRt:function(a,n){return a>>>n},LESVB:function(a,n){return a>>>n},zJzxU:function(a,n){return a>>>n},mEPDA:function(a,n){return a>>>n},dmMcC:function(a,n){return a&n},estaa:function(a,n){return a>>>n},SsEDu:"MAX_RETR"+t(1788)+"R",ZYNXP:"CONNECTI"+t(1814),Gkuhf:t(1288)+"OR",hABek:t(1576)+t(471),jVIMN:"NATIVE_E"+t(781),uoFNm:t(1678),HOqPB:function(a,n){return a===n},gwfTS:function(a,n){return a===n},urbvN:"iuyKo",WoHmE:t(1041),EXGwL:function(a,n){return a==n},GoynY:function(a,n){return a===n},gADfe:function(a,n){return a instanceof n},iADFf:t(1753)+t(474),rJpKn:function(a,n){return a===n},tAhPG:"vhies",YKglR:function(a,n){return a===n},yIpyR:function(a,n,s){return a(n,s)},rXflp:function(a,n,s){return a(n,s)},unvxY:"message",qFHYJ:t(568),vcZhb:function(a,n,s){return a(n,s)},HfSDm:t(1613),HkQFJ:"KNxBc",HOWYn:t(472)+"d",HuGrJ:function(a,n){return a!=n},TaAQp:function(a,n){return a<=n},TKgke:function(a,n){return a===n},qzhIm:function(a,n){return a===n},ANqRU:function(a,n){return a&n},aKwvW:function(a,n){return a+n},PLvMW:function(a,n){return a<n},AXxku:function(a,n){return a<n},nxrgN:function(a,n){return a===n},XJgaY:"NVGQg",AmlvD:function(a,n){return a|n},kAkWW:function(a,n){return a>=n},xiIAW:function(a,n){return a|n},rvVQD:function(a,n){return a<<n},WqhAA:function(a,n){return a&n},zBngX:function(a,n){return a&n},TSbyW:function(a,n){return a-n},XuzDQ:function(a,n){return a|n},AbBTE:function(a,n){return a|n},opAAq:function(a,n){return a&n},cEstr:function(a,n){return a<<n},ZVPqL:function(a,n){return a&n},eHZfM:function(a,n){return a&n},fKYln:function(a,n){return a>>n},qYXbn:function(a,n){return a&n},MyGBY:function(a,n){return a&n},knber:function(a,n){return a===n},IoXir:function(a,n){return a+n},ssspf:function(a,n){return a<<n},vvkJU:function(a,n){return a&n},kiXpQ:function(a,n){return a>>n},HvXLA:function(a,n){return a|n},ojEgN:function(a,n){return a>>n},JqNji:function(a,n){return a|n},RjrGU:function(a,n){return a&n},Vgnid:function(a,n){return a+n},mUvOF:function(a,n){return a+n},IgiDy:function(a,n){return a+n},NYthh:function(a,n){return a+n},oKPXS:function(a,n){return a!==n},uXzKf:function(a,n){return a&n},VYssv:function(a,n){return a|n},VYreZ:function(a,n){return a|n},wxFhR:function(a,n){return a<<n},zCXlU:function(a,n){return a<<n},URICA:function(a,n){return a|n},QRyXU:function(a,n){return a|n},JoWei:function(a,n){return a|n},AVtnx:function(a,n){return a<<n},eVaEc:function(a,n){return a&n},oFQDu:function(a,n){return a<<n},QQCjU:function(a,n){return a&n},yCCuO:function(a,n){return a>n},MZzCg:function(a,n,s){return a(n,s)},sswsq:function(a,n){return a&n},OJbLM:"close, w"+t(1497)+t(954)+t(1377)+"ed",ZPGJE:function(a,n){return a===n},XDIzA:function(a,n){return a!==n},BwxzO:t(703),VTwGM:"string",DWtqu:t(1063),EyoRA:function(a,n){return a(n)},mQUqI:function(a,n,s,d){return a(n,s,d)},pkwIX:function(a,n){return a!=n},bPwki:function(a,n){return a!=n},jhBrS:t(1058)+t(1263)+t(1010),amVIz:t(1746),hRMNz:t(1380),ELbuD:function(a,n){return a!==n},kZEbI:t(1772),omKqX:function(a,n){return a(n)},NpooO:t(1293)+t(1824),rYOlA:function(a,n){return a+n},sIAZv:function(a,n){return a<=n},hjhDq:"rMEih",TLskm:function(a,n,s,d){return a(n,s,d)},YNoVk:"offline",PCaiZ:"MBqaL",DdmTw:t(1311),wsffn:"tYIEh",ghcqx:function(a,n,s,d){return a(n,s,d)},dzzsZ:t(1882),GcboK:function(a,n,s){return a(n,s)},TvhSi:function(a,n){return a<<n},ytncm:t(713),nGmxs:"mrwOQ",dLSFJ:function(a,n,s){return a(n,s)},SvkrA:t(967),NkIvz:function(a,n){return a===n},VvuVa:t(663),AHtYe:function(a,n){return a!==n},NDdEj:t(948),IJpvR:function(a,n){return a||n},ESMWn:"AbortError",bpVVL:function(a,n){return a===n},jwqpN:t(745),nkkpc:function(a,n){return a||n},VPvEp:function(a,n){return a!==n},axJEQ:t(1170),yNQAu:t(1731),GBrmN:function(a,n){return a||n},fJwhM:function(a,n){return a||n},tMaVM:function(a,n){return a||n},dwdtc:function(a,n){return a||n},caBlW:"init QoS"+t(1254)+"d",YUvFT:"qos",jyJIL:"message_id",iUekw:function(a,n,s){return a(n,s)},Qdlvh:function(a,n){return a&n},uuoUC:function(a,n){return a+n},JZKUo:t(1270),gJHgI:"InWAD",HORXC:"FIAtA",MyqCE:function(a,n,s,d){return a(n,s,d)},biHXn:"x_fronti"+t(689),wfrHH:t(1631)+t(1250)+"ck",RQlvv:"x_frontier_is_ack",pnwux:function(a,n,s){return a(n,s)},xaFsK:"need_ack",SRcIb:function(a,n){return a&&n},zDvBd:function(a){return a()},yFWYp:t(810),MfCfl:function(a,n){return a<<n},VDjMA:function(a,n){return a<<n},yVHoU:function(a,n){return a(n)},Fgznv:t(1630),rFdZV:function(a,n){return a instanceof n},sQUVw:function(a,n){return a instanceof n},SpAEz:t(421)+t(1233),IpOTe:t(421)+t(1233)+t(616)+"=utf-8",HlSlH:t(1267)+"e",hWUBa:t(607),jKhDa:function(a,n){return a<n},Dljel:function(a,n){return a(n)},wfquC:function(a,n){return a(n)},PGKSa:function(a,n){return a+n},NNOIL:t(1432)+t(1759)+t(1671),vAGtj:t(1001),WorZp:t(656),wpeby:t(1351)+t(1224)+"s",iXITN:t(1351)+t(1345)+"t",VUckq:function(a,n){return a>=n},dwcUS:t(645),bJwJg:function(a,n,s,d){return a(n,s,d)},TJHWx:function(a,n){return a+n},wFdyH:function(a,n){return a+n},UHpwJ:function(a,n){return a<n},tOaBf:function(a,n){return a+n},pKOYn:function(a,n,s,d){return a(n,s,d)},GlzEh:function(a,n){return a|n},dvWqy:function(a,n){return a|n},qByYD:function(a,n){return a+n},dNZvY:function(a,n){return a<<n},lnumE:function(a,n){return a+n},Lkfvu:function(a,n){return a+n},RzUCT:function(a,n){return a+n},lgExY:function(a,n){return a+n},VPMog:function(a,n){return a>>>n},JFzHI:function(a,n){return a+n},XDNfa:function(a,n){return a+n},oFZSp:function(a,n){return a>>>n},jRvNy:function(a,n){return a+n},zfCyl:t(1403)+"1",rmFyp:t(1120),yHOan:function(a,n){return a&n},luAQn:function(a,n){return a&n},lIilm:function(a,n,s){return a(n,s)},XPQCD:function(a,n){return a&n},acClP:function(a,n){return a<n},GydzD:function(a,n){return a|n},ChWYa:function(a,n){return a|n},VdhjL:function(a,n){return a&n},yIoZg:function(a,n){return a|n},Sxtxe:function(a,n){return a|n},QNqFS:function(a,n){return a!==n},jDrEA:t(1836),DNbwS:t(951),dGNHu:function(a,n){return a(n)},hCrSq:"xpEeI",whbdy:t(1906)+t(553)+t(464),RWuht:function(a,n,s,d){return a(n,s,d)},vOFmq:t(1401)+"name",vIMVo:t(683)+t(1619),wMhMp:"header",gODCA:function(a,n,s,d){return a(n,s,d)},Tijne:function(a,n,s,d){return a(n,s,d)},uxxPZ:t(1231),Bnret:t(546),zLDEA:function(a,n){return a(n)},qDyok:"cursor_f"+t(840),hkaij:function(a,n){return a!==n},uYoiw:t(716),xydLk:function(a,n,s,d){return a(n,s,d)},eesJm:function(a,n){return a+n},McaHp:"FILE_NOT"+t(1909),Hzgnu:function(a,n,s){return a(n,s)},WpoCt:t(1056)+t(1068),cjFCT:"allCursorValues",EHRpY:t(837),QwkIm:"INSTANT",JwFjE:function(a){return a()},wuDzu:t(791),LkUAB:t(429)+"r",CxKYz:function(a,n){return a||n},nMWvw:function(a,n){return a===n},JQlMm:t(1174),Gzylv:t(960),bwnLB:t(1789),QxeQb:t(1631)+t(1488),pXdTB:function(a,n){return a(n)},nHELG:function(a,n,s){return a(n,s)},wifAK:t(1631)+t(667),VAsCl:function(a,n,s,d){return a(n,s,d)},uMLmG:t(1264)+"s",WThpr:function(a,n,s){return a(n,s)},ZwDix:function(a,n,s){return a(n,s)},odcUi:t(614)+t(1847)+"ue",sKyTd:function(a,n){return a>n},XOuoS:function(a,n){return a===n},kfWfn:t(1702),aAYeE:t(1466),iCPGS:function(a){return a()},RHdxb:function(a){return a()},toqjR:t(1090),pIwqF:function(a,n){return a&&n},HYJrC:function(a){return a()},fQbMR:function(a,n,s){return a(n,s)},VwsgQ:function(a){return a()},abNDA:function(a){return a()},CGhLU:t(854),BWUOP:t(1079),vOdhd:function(a){return a()},etSyO:function(a,n){return a!==n},zDaxA:"ssuMU",JrPqa:t(1117),jintb:function(a){return a()},vSjmq:function(a,n,s){return a(n,s)},rdiEL:function(a,n,s){return a(n,s)},AQMdL:t(1744),HnZGN:function(a,n){return a!==n},FUoMe:function(a,n,s){return a(n,s)},XJNiV:function(a,n){return a<n},iMDcz:function(a,n){return a|n},DNPHW:function(a,n){return a&n},jDoVX:function(a,n){return a&n},rdUcp:function(a,n){return a|n},Dzckn:function(a,n){return a&n},YnQBD:function(a,n){return a&n},vzQtz:function(a,n){return a===n},bXAjv:function(a,n){return a===n},ubttc:"always",QAnDf:function(a,n){return a!==n},IJSLC:"arraybuf"+t(1689),wUQuB:function(a,n){return a/n},xFQOT:t(1038),WdpUd:t(1217),uXQpX:t(835)+t(755)+t(1161),Jinjt:function(a,n){return a(n)},OUOPt:"please provide w"+t(1376)+", WebSocket cons"+t(1259)+t(1128)+t(734),FvIPI:function(a,n,s){return a(n,s)},REMpp:t(860)+"t",UBkWB:t(1676)+t(1135)+t(731)+"ct",PswJF:"online",EnvQP:t(1394),uRhEI:function(a,n,s,d){return a(n,s,d)},LSYHc:t(1644),nnXQX:t(764),EaKgz:function(a,n){return a===n},xqlus:t(1051),SIlIt:"jHpIL",HHsBi:function(a,n){return a!==n},BMGyh:function(a,n){return a!==n},imAbQ:function(a,n){return a==n},npbWy:"https:",DsHBH:t(1536),Zlpal:function(a,n){return a!==n},xrnNS:"NTSol",MWQtT:"wss://",oAcrA:t(584),jhYcM:t(560),YEzKQ:"device_id",QFDVv:t(835)+t(940)+t(1155)+t(818)+t(1215),NGpcy:"function",EZmBq:t(1768)+"0",hNeWj:function(a,n,s){return a(n,s)},tCKLr:function(a,n,s){return a(n,s)},DnDPw:function(a,n,s){return a(n,s)},Ebjeg:t(907),XPgrp:t(1846),QZSFL:function(a,n,s){return a(n,s)},FCpGE:t(473),xLtPr:function(a,n){return a-n},TPFzt:function(a,n){return a(n)},LTKWm:function(a,n){return a(n)},aRsrg:"FRONTIER>",kaxje:function(a,n){return a>n},uDirC:function(a,n){return a===n},ikSzl:t(1742),SuIAA:function(a,n){return a===n},JQMfk:t(699),VDtsV:t(738),mQpMC:t(554)+t(867)+t(860)+t(556)+t(1604),gmXdw:function(a,n,s){return a(n,s)},WNkCZ:function(a,n){return a===n},YkESp:t(926),mcPhy:t(1252)+"4",iqaCf:function(a,n){return a===n},XpJvm:function(a,n){return a!==n},vDVxO:"GaAdj",qHclt:t(871),YTsJK:t(1762),jQQqo:t(483)+"1",XkNoI:t(1651),smxYa:function(a,n,s){return a(n,s)},vvRil:function(a,n,s){return a(n,s)},nvWmV:t(554)+"ay, netw"+t(525)+t(1516),AmHxU:function(a,n){return a===n},txlXo:t(1196),ddRXo:function(a,n){return a!==n},HxtUX:t(992),JRMEn:"amvUG",Mypju:t(1481),aJyZG:function(a,n){return a<n},spYbD:"jtxvL",gPzvn:t(1666)+t(1189),LbQvv:function(a,n){return a===n},pcwsT:t(1262)+t(520)+"y closed",LSBSL:t(1087),BXkRT:function(a,n){return a(n)},DYikp:t(835)+t(1013)+t(766)+t(1619),lqcMu:function(a,n){return a===n},AbLTc:t(1670),EjBHY:t(441),jEvOI:t(1561),SoHcX:function(a,n){return a||n},CFBtN:function(a,n){return a==n},pySjp:t(644)+t(1571)+t(1573),IghCa:"xTWge",kklCo:"4|2|3|1|0",wOQnt:function(a,n){return a!==n},ZhGlc:t(830),RjZtM:function(a,n){return a*n},fbkiq:t(1622),azzpe:function(a,n){return a!=n},AWYnA:t(642),UQWXk:function(a,n){return a===n},kcXOO:t(1833)+"dWorkerG"+t(1821)+"pe",iVfhf:function(a,n){return a==n},YKjmB:function(a,n){return a!=n},rjqko:function(a,n){return a!=n},pOEPd:function(a,n){return a===n},oWiSp:function(a,n){return a===n},KtWxD:function(a,n){return a===n},iwebN:function(a,n){return a!=n},IRIHF:function(a,n){return a!=n}};Nt.r(Ce),Nt.d(Ce,{FWS:()=>Kp,CustomErrorEvent:()=>Wl,createCloseEvent:()=>ut,ReconnectEvent:()=>jl,createErrorEvent:()=>it,decodedFrame:()=>Xt,createOpenEvent:()=>Yl,CustomCloseEvent:()=>Kl,createReconnectEvent:()=>sa,FrontierMessageEvent:()=>Vl,encodeFrame:()=>Ft,createMessageEvent:()=>Zl,OpenEvent:()=>Jl,ErrorCode:()=>en,Event:()=>Jn,MessageEvent:()=>$l});let r="";function i(a=""){let n=t,s="02",d=""+Date[n(1564)](),h=r||(r=f(a)),y=Math[n(666)]()[n(631)](16)[n(1321)](-6);return e[n(610)](e[n(1307)](e[n(1307)](s,d),h),y)}function o(){let a=t;return 1e4*Date[a(1564)]()+Math[a(1624)](e[a(1e3)](1e4,Math[a(666)]()))}function c(a){let n=t;return e[n(610)](e.NQctf(Array,8)[n(1554)]("0"),e[n(813)](parseInt,a,10)[n(631)](2)).slice(-8)}function l(a){let n=t;return e[n(1307)](e[n(1880)](Array,4).join("0"),e[n(775)](parseInt,a,2).toString(16))[n(1321)](-4)}function u(a){let n=t,s=a[n(841)](/\./)[n(1157)](y=>c(y)),d=[];return d[0]=l(e[n(1888)](s[0],s[1])),d[1]=l(e[n(610)](s[2],s[3])),[e[n(693)],e[n(693)],e[n(693)],e.jvjyq,e[n(693)],e[n(1407)],d[0],d[1]].join("")}function f(a){let n=t,s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/.test(a),d=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[n(1521)](a);return s?u(a):d?e[n(1880)](x,a):e[n(1237)]}function x(a){let n=t,s="",d=[],h=0,y=0,v=!0,I=n(1776);if(e.WLCmj(a[n(1142)]("::"),-1)){let g=a[n(841)]("::");for(let M=0;e[n(1659)](M,g[n(564)]);M++){let F=g[M];if(F[n(1142)](":")>0){let J=F[n(841)](":");v&&(h=J.length),y+=J[n(564)];for(let V=0;V<J.length;V++)if(e[n(1154)](4,J[V][n(564)]))if(e.LtDAk===e[n(1751)]){if(_0x54f017<1||e[n(1853)](_0x1b09ec,_0xb170f0))return e[n(1880)](_0x3eff8a,_0x1081bd);e[n(610)](_0x5392a9,_0x4f3807)>_0x1f953c&&(_0xa86d1c=e[n(1880)](_0x40cdd0,_0x3df29b),_0x4ff969=0);let Ie=_0x39bf55.call(_0x5eec1b,_0x5a8752,_0x39da1a+=_0x13f41e);return e.maoqu(7,_0x20dcf0)&&(_0x685986=e[n(1144)](7|_0x339a25,1)),Ie}else{let Ie=I[n(751)+"g"](0,e[n(1745)](4,J[V][n(564)])),ft=Ie.concat(J[V]);d[n(596)](ft)}else d[n(596)](J[V]);v=!1}else{if(F[n(564)]!==4){let J=I[n(751)+"g"](0,4-F.length),V=J[n(1482)](F);d.push(V)}else d[n(596)](F);v&&(h+=1),y+=1,v=!1}}let R="";for(let M=0;e[n(1659)](M,8-y);M++)R=R[n(1482)](I);for(let M=0;e.SiaIZ(M,d.length);M++)e.VtsMG(M,h)&&(s=s[n(1482)](R)),s=s[n(1482)](d[M]);return s}{let g=a[n(841)](":");for(let R=0;e[n(1659)](R,g[n(564)]);R++)if(e[n(961)](e[n(1647)],e[n(1647)])){let{type:M}=_0x2a17a5;this[n(1292)](M,_0x126195)}else{let M=g[R];if(e[n(1319)](4,g[R][n(564)])){let F=I[n(751)+"g"](0,e[n(1745)](4,g[R][n(564)])),J=F[n(1482)](M);s=s[n(1482)](J)}else s=s[n(1482)](M)}return s}}function m(a,n){let s=t,d=a[s(1121)];d!==void 0&&(e[s(637)](ue,n,10),q(n,d));let h=a.value;h!==void 0&&(ue(n,18),e[s(543)](q,n,h))}function w(a){let n=t,s={};e:for(;!e.lbaTT(W,a);){let d=e[n(1349)](de,a);switch(d>>>3){case 0:break e;case 1:s[n(1121)]=e[n(1360)](O,a,e[n(799)](de,a));break;case 2:s.value=O(a,de(a));break;default:T(a,e[n(1646)](7,d))}}if(e[n(552)](void 0,s[n(1121)]))throw new Error(e.ENZpT);if(e[n(552)](void 0,s[n(1835)]))throw new Error(e[n(1213)]);return s}function b(a){let n=t;if(e[n(1534)]===e[n(1534)]){let s=e.kzpeP(k);return e.MtMdC(p,a,s),N(s)}else{let s=n(1513)+_0x5454ae+(n(1673)+"ax retri"+n(1856)+"ed");this[n(1850)+n(678)+"ent"](e[n(813)](_0x5a0763,"error",{message:s,code:_0x219973["MAX_RETR"+n(1788)+"R"],error:_0x3201bf}));return}}function p(a,n){let s=t,d={Mzqqg:e.EofgV,olVXP:e[s(613)],Uxnsp:function(zt,ht,$r,ha,xa){return zt(ht,$r,ha,xa)},akxfJ:function(zt,ht){return e[s(1216)](zt,ht)}},h=a[s(1066)];e[s(961)](void 0,h)&&(e.qZVhu(e[s(460)],e[s(460)])?(ue(n,8),e[s(1584)](dt,n,h)):this[s(1765)]?.del(_0x3c5202[s(1642)+"id"]));let y=a[s(769)];e[s(1537)](void 0,y)&&(e[s(1781)](ue,n,16),e[s(1823)](dt,n,y));let v=a[s(1617)];e[s(1154)](void 0,v)&&(e[s(1638)](ue,n,24),e[s(1503)](dt,n,e[s(1880)](D,v)));let I=a[s(974)];e[s(1703)](void 0,I)&&(ue(n,32),e[s(1638)](dt,n,e[s(417)](D,I)));let g=a[s(1160)];if(e[s(1537)](void 0,g))for(let zt of g){ue(n,42);let ht=e.ljgBC(k);m(zt,ht),ue(n,ht[s(726)]),e[s(1781)](j,n,ht),e[s(799)](P,ht)}let R=a[s(1112)+"ncoding"];e[s(1840)](void 0,R)&&(ue(n,50),e[s(1503)](q,n,R));let M=a["payloadT"+s(1547)];e[s(1703)](void 0,M)&&(e[s(1584)](ue,n,58),q(n,M));let F=a[s(1580)];F!==void 0&&(e.Gwzul!==e[s(717)]?(_0x2e8415[s(1779)+s(964)+s(1298)](jlFIqa[s(943)],_0xf2ff49),_0x4eaa76[s(1779)+"entListe"+s(1298)](jlFIqa[s(736)],_0x3b2517)):(e[s(1503)](ue,n,66),e[s(1870)](ue,n,F.length),e.yoYgh(he,n,F)));let J=a.LogIDNew;e.JPqZZ(void 0,J)&&(e[s(1143)](e.fGQuy,e[s(1829)])?jlFIqa[s(534)](_0x42885f,jlFIqa[s(491)](_0x2e1781,_0x59730d[s(1874)]),_0x3fa824.oldVersion,_0x104b11.newVersion,_0x3241e6(_0x55a52f.transaction)):(e[s(1228)](ue,n,74),e[s(558)](q,n,J)));let V=a[s(962)+s(1578)];V!==void 0&&(e[s(1360)](ue,n,82),e[s(1781)](q,n,V));let Ie=a[s(1504)];e[s(1319)](void 0,Ie)&&(e[s(1032)](ue,n,90),q(n,Ie));let ft=a.frameType;ft!==void 0&&(e[s(1354)](ue,n,96),e[s(558)](dt,n,D(ft)))}function _(a){let n=t,s={sveuk:function(d,h){return e[U(1352)](d,h)}};return e.XNdjJ(e[n(1107)],n(804))?s[n(1415)](this.count,this["maxLossC"+n(1611)]):e[n(1349)](S,e[n(417)](B,a))}function S(a){let n=t;if(n(1733)!==e.jSqVp){let s={};e:for(;!e[n(1096)](W,a);){let d=de(a);switch(d>>>3){case 0:break e;case 1:s.SeqID=e[n(1870)](vt,a,!0);break;case 2:s[n(769)]=e.VbeDu(vt,a,!0);break;case 3:s[n(1617)]=e[n(1880)](de,a);break;case 4:s[n(974)]=e[n(1803)](de,a);break;case 5:{let h=e[n(1880)](A,a);(s.headers||(s[n(1160)]=[]))[n(596)](w(a)),a[n(726)]=h;break}case 6:s.payloadEncoding=e.TLYDQ(O,a,e[n(1803)](de,a));break;case 7:s[n(1114)+n(1547)]=O(a,de(a));break;case 8:s[n(1580)]=e.mCPiP(ve,a,e[n(417)](de,a));break;case 9:s[n(981)]=O(a,e[n(487)](de,a));break;case 10:s["serverTi"+n(1578)]=O(a,e.wHfER(de,a));break;case 11:s[n(1504)]=O(a,de(a));break;case 12:s[n(748)+"e"]=e[n(1880)](de,a);break;default:e.oqECr(T,a,e[n(594)](7,d))}}if(e.VtsMG(void 0,s.SeqID))throw new Error(e[n(1371)]);if(s.LogID===void 0)throw new Error(e.UEMnF);if(s.service===void 0)throw new Error(e[n(1740)]);if(e[n(552)](void 0,s.method))throw new Error(e[n(1127)]);return s}else _0x2ce3a6[n(1908)](_0x216a4e)}function A(a){let n=t,s=de(a),d=a[n(726)];return a[n(726)]=e[n(826)](a[n(615)],s),d}function T(a,n){let s=t;switch(n){case 0:for(;e.maoqu(128,e[s(1803)](re,a)););break;case 2:$(a,e[s(1383)](de,a));break;case 5:e[s(813)]($,a,4);break;case 1:e.dqOIL($,a,8);break;default:throw new Error(e[s(1208)]+n)}}function D(a){let n=t;return a|=0,{low:a,high:e[n(1609)](a,31),unsigned:e[n(1721)](a,0)}}let E=[];function k(){let a=t,n=E[a(587)]();return n?(n[a(615)]=n[a(726)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function P(a){E[t(596)](a)}function B(a){return{bytes:a,offset:0,limit:a[t(564)]}}function N(a){let n=t,s=a[n(1857)],d=a[n(726)];return e[n(612)](s[n(564)],d)?s:s[n(1080)](0,d)}function $(a,n){let s=t;if(e[s(1152)](a[s(615)],n)>a[s(726)])throw new Error(e[s(1614)]);a[s(615)]+=n}function W(a){let n=t;return e[n(1352)](a.offset,a[n(726)])}function ne(a,n){let s=t,d=a[s(1857)],h=a[s(615)],y=a.limit,v=e[s(826)](h,n);if(v>d.length){let I=new Uint8Array(e[s(1297)](2,v));I[s(597)](d),a[s(1857)]=I}return a.offset=v,e.LmGva(v,y)&&(a[s(726)]=v),h}function Y(a,n){let s=t;if(e[s(903)](s(1305),e[s(493)])){let d=a[s(615)];if(e[s(1778)](e[s(1888)](d,n),a.limit))throw new Error("Read pas"+s(1750));return a[s(615)]+=n,d}else return new _0x5f2d14(_0x3e3ed6,{message:_0x229d55,code:_0x631f3c,error:_0x21b667})}function ve(a,n){let s=t,d=e[s(1823)](Y,a,n);return a[s(1857)][s(1080)](d,e[s(561)](d,n))}function he(a,n){let s=t,d=e[s(1032)](ne,a,n.length);a[s(1857)][s(597)](n,d)}function O(a,n){let s=t,d=e[s(1360)](Y,a,n),h=String[s(1524)+s(1577)],y=a.bytes,v="\uFFFD",I="";for(let g=0;e[s(1659)](g,n);g++){let R=y[e[s(561)](g,d)],M,F,J,V;if(e[s(1169)](e[s(1205)](128,R),0))I+=e.DqCIA(h,R);else if(e[s(480)](224&R,192))if(e.dZHQA(g,1)>=n)I+=v;else if(e[s(1255)](s(687),"vdQmg"))M=y[e[s(610)](e[s(610)](g,d),1)],e.xLbdY(e.maoqu(192,M),128)?I+=v:(V=e.Lfims(e.LRtgG(e.GyZcm(31,R),6),e[s(1205)](63,M)),e[s(453)](V,128)?I+=v:(I+=e[s(799)](h,V),g++));else return _0x2479b9||(_0x54aee8=_0x1019b7.resolve()[s(1555)](_0x379a75[s(1756)](_0x7d6f7f,e[s(978)]))),_0x20b612;else if(e.pJFty(e[s(1205)](240,R),224))e[s(1352)](e[s(1531)](g,2),n)?I+=v:(M=y[e.tHRHF(e.PhxAu(g,d),1)],F=y[e[s(826)](g+d,2)],e[s(1201)](e[s(1710)](M,F<<8),49344)!==32896?I+=v:(V=e.FIXaX(15&R,12)|(63&M)<<6|63&F,e[s(1659)](V,2048)||e[s(1721)](V,55296)&&V<=57343?I+=v:(I+=e[s(1349)](h,V),g+=2)));else if(e[s(1344)](e[s(1033)](248,R),240))if(e[s(569)](g,3)>=n)I+=v;else if(M=y[e[s(576)](g,d)+1],F=y[e[s(1400)](e.ufyGw(g,d),2)],J=y[e[s(1888)](g,d)+3],e[s(1143)](e[s(1033)](e[s(1710)](e[s(1710)](M,e[s(643)](F,8)),e[s(1035)](J,16)),12632256),8421504))I+=v;else if(e[s(1525)](s(522),e[s(809)]))e[s(1385)](_0x780948,_0x1cb30a,82),e[s(1032)](_0x4643f0,_0x2d4a29,_0x317e6e);else if(V=e.oRSfq(e.oRSfq(e[s(1190)](e[s(1639)](e.lAaMn(7,R),18),e.OTGRF(e[s(1239)](63,M),12)),e.IGNML(e[s(1033)](63,F),6)),e[s(1404)](63,J)),e[s(446)](V,65536)||V>1114111)I+=v;else if(e[s(1525)](s(477),e[s(468)]))V-=65536,I+=h(e[s(1609)](V,10)+55296,e[s(1492)](e[s(1589)](1023,V),56320)),g+=3;else return"frontier_"+this[s(635)];else I+=v}return I}function q(a,n){let s=t,d=n[s(564)],h=0;for(let I=0;I<d;I++)if(e[s(728)](e[s(573)],s(1480))){let g=n[s(711)+"At"](I);g>=55296&&e[s(697)](g,56319)&&e[s(446)](e[s(527)](I,1),d)&&(g=e[s(1745)](e[s(1827)](e.wmOuP(g,10),n[s(711)+"At"](++I)),56613888)),h+=e.SiaIZ(g,128)?1:g<2048?2:e.JxKEd(g,65536)?3:4}else{let g=0,R={};for(let M=0;e.wOGOJ(M,_0x53a164[s(564)]);M++)R[_0x58c332[M][s(1056)+"ame"]]=e[s(1803)](_0x1efc15,_0xce02a8[M][s(1056)+s(1068)]),g+=e[s(665)](14,R[_0x3af03e[M][s(1056)+s(1068)]]);return[g,R]}e[s(1422)](ue,a,h);let y=e.YcIbG(ne,a,h),v=a[s(1857)];for(let I=0;e[s(931)](I,d);I++){let g=n[s(711)+"At"](I);g>=55296&&g<=56319&&e[s(446)](e[s(1144)](I,1),d)&&(g=e.ygTet(e[s(1152)](e[s(1639)](g,10),n[s(711)+"At"](++I)),56613888)),g<128?v[y++]=g:(e.Jmtpw(g,2048)?v[y++]=e[s(593)](e[s(1645)](g,6)&31,192):(e[s(817)](g,65536)?v[y++]=e[s(1710)](e.XGVPs(g,12)&15,224):(v[y++]=e[s(879)](e[s(1201)](e.IvPxR(g,18),7),240),v[y++]=e[s(1795)](e[s(939)](e[s(1003)](g,12),63),128)),v[y++]=e[s(1370)](e[s(762)](e[s(1003)](g,6),63),128)),v[y++]=e[s(1710)](63&g,128))}}function j(a,n){let s=t,d={gQrlL:function(h,y,v){return e.EgHCZ(h,y,v)}};if(e.VtsMG(e[s(1861)],e[s(1845)]))return new _0x1b4748(h=>{let y=s;d[y(839)](_0x440a0a,h,this[y(792)+y(1287)+"e"](_0x241a8f))});{let h=e[s(913)](ne,a,n[s(726)]),y=a[s(1857)],v=n[s(1857)];for(let I=0,g=n.limit;e[s(446)](I,g);I++)y[e[s(1185)](I,h)]=v[I]}}function re(a){return a.bytes[Y(a,1)]}function Ve(a,n){let s=t,d=e.BkWYK(ne,a,1);a[s(1857)][d]=n}function de(a){let n=t;if(e.IGtoV(n(1040),e.MYQdT)){let s=0,d=0,h;do if(e[n(777)]!==e[n(1469)])h=e.jOgRc(re,a),e[n(446)](s,32)&&(d|=e.GmKbc(127&h,s)),s+=7;else return this[n(1765)]?.set({message_id:_0x375e8f,timestamp:_0x371def});while(128&h);return d}else{let{SeqID:s,LogID:d,service:h,LogIDNew:y,method:v}=_0x1539b1[n(737)];this[n(720)]({SeqID:s,LogID:d,LogIDNew:y,service:h,method:v,headers:[{key:e.ApXzs,value:"1"},{key:e.YnvOX,value:e[n(1358)](y,"")},{key:e.VKRQU,value:"0"}]})}}function ue(a,n){let s=t;for(n>>>=0;e[s(1721)](n,128);)Ve(a,e[s(815)](e[s(1574)](127,n),128)),n>>>=7;e[s(558)](Ve,a,n)}function vt(a,n){let s=t,d={mPirx:function(g,R,M){return g(R,M)},IDIhs:e[s(1725)],RSroy:function(g){return e.jHDQY(g)}},h=0,y=0,v=0,I;if(I=e[s(1880)](re,a),h=e[s(1239)](127,I),e[s(1033)](128,I)&&(I=e[s(982)](re,a),h|=e.FIXaX(e[s(1589)](127,I),7),128&I&&(I=e[s(1383)](re,a),h|=e[s(601)](e[s(1413)](127,I),14),128&I))){if(e.DPhen(e[s(1601)],e[s(1601)]))_0x182f2c=_0xba3f89(_0x5633b1),_0x53d29d=0;else if(I=e[s(1011)](re,a),h|=e.JiTRh(e.xuujs(127,I),21),e[s(1356)](128,I)&&(I=e.ylkmO(re,a),y=127&I,e[s(1387)](128,I)))if(e[s(908)]===e[s(1098)]){let g={XXdld:"error",nmVjr:function(R,M,F){return d[s(1894)](R,M,F)},muIoP:d[s(1414)]};_0x3d10ba.resolve()[s(1555)](()=>{let R=s,M=_0x3be1ec(g[R(1724)],{message:this[R(1685)+R(785)+"age"](_0xfa1870)});this[R(1292)](g[R(1724)],M);let F=g.nmVjr(_0x3fa04b,g.muIoP,{reason:this[R(1685)+R(785)+"age"](_0x2166e7)});this[R(1292)](g[R(603)],F)})}else I=e[s(1055)](re,a),y|=e[s(1178)](127&I,7),e.VuCjV(128,I)&&(I=e.mxsCL(re,a),y|=e[s(1640)](127,I)<<14,128&I&&(e[s(730)](e.KJPgE,e[s(622)])?(RXjqfO[s(1508)](_0x6d499e),RXjqfO[s(1508)](_0x22f355)):(I=e[s(1552)](re,a),y|=(127&I)<<21,e[s(425)](128,I)&&(I=re(a),v=e.xJbMf(127,I),128&I&&(I=e.FIrQY(re,a),v|=e[s(601)](e[s(1667)](127,I),7))))))}return{low:e[s(1285)](h,e[s(577)](y,28)),high:e[s(1190)](e[s(1179)](y,4),v<<24),unsigned:n}}function dt(a,n){let s=t,d={vHncp:function(h){return e.jHDQY(h)},FAxBo:function(h,y,v){return e[U(1030)](h,y,v)},ZiMrj:function(h,y){return h(y)}};if(e[s(1036)]===e[s(1036)]){let h=e[s(870)](n[s(1373)],0),y=e.lffet(e.cmrCa(e[s(580)](n[s(1373)],28),e[s(1035)](n.high,4)),0),v=e.lffet(n[s(1519)],24),I=e.Vezxu(0,v)?e.YAZQQ(0,y)?e.sclLN(h,16384)?e[s(902)](h,128)?1:2:e[s(453)](h,2097152)?3:4:y<16384?y<128?5:6:e.JxKEd(y,2097152)?7:8:e[s(446)](v,128)?9:10,g=e.VNLBr(ne,a,I),R=a[s(1857)];switch(I){case 10:R[e[s(1307)](g,9)]=e[s(1201)](e[s(1238)](v,7),1);case 9:R[e[s(618)](g,8)]=e[s(1143)](9,I)?e[s(517)](128,v):127&v;case 8:R[e[s(1563)](g,7)]=e[s(1137)](8,I)?e[s(1665)](y>>>21,128):e.aGJcP(e[s(1509)](y,21),127);case 7:R[e[s(826)](g,6)]=I!==7?e[s(1790)](e.Lephc(y,14),128):e[s(1509)](y,14)&127;case 6:R[e[s(610)](g,5)]=e[s(961)](6,I)?e.lffet(y,7)|128:e[s(939)](e[s(1179)](y,7),127);case 5:R[e[s(826)](g,4)]=e[s(1867)](5,I)?e[s(1844)](128,y):127&y;case 4:R[g+3]=I!==4?e[s(1179)](h,21)|128:e[s(1796)](e[s(1509)](h,21),127);case 3:R[e[s(526)](g,2)]=e.LIqzy(3,I)?e.nQJcr(e[s(1700)](h,14),128):e.WGzaw(e[s(580)](h,14),127);case 2:R[e[s(1408)](g,1)]=e.RERRi(2,I)?e[s(673)](e[s(1302)](h,7),128):e[s(462)](e[s(1813)](h,7),127);case 1:R[g]=e[s(823)](1,I)?e[s(1249)](128,h):127&h}}else{let h=HbkkMT[s(1523)](_0x3fad58);return HbkkMT[s(1816)](_0x1ac263,_0x6cabd0,h),HbkkMT[s(469)](_0x4722a3,h)}}function Xt(a){return e.wHfER(_,a)}function Ft(a){return e[t(1011)](b,a)}let Qt=65536,jr="\0\0\0\0\0\0\0\0",ge=e[t(976)](Qt,Qt),Se=e.xotis(ge,ge),Vn=e.wUQuB(Se,2),De=String[t(1763)+"e"][t(711)+"At"];class ae{constructor(n,s,d){let h=t;if(e.qZVhu(e[h(1838)],"ZJWuQ")){let y=e.RuDmA(_0x526f90,_0x57f92a,_0x38ba11[h(726)]),v=_0x4a0b76[h(1857)],I=_0x586c2b[h(1857)];for(let g=0,R=_0x3fb7dd[h(726)];e.MFpIa(g,R);g++)v[g+y]=I[g]}else this[h(1473)]=!0,this[h(1373)]=e[h(1656)](0,n),this[h(1519)]=e[h(679)](0,s),this[h(1124)]=!!d}static[t(1473)](n){let s=t,d={leTUj:function(h,y){return h>y},sVeDu:function(h,y){return e[U(578)](h,y)},IVCqw:e[s(1490)]};if(e[s(1719)](s(701),e[s(1712)])){let h=_0x3fa2a0[s(615)];if(VSHsHi[s(1785)](VSHsHi.sVeDu(h,_0x37d176),_0x2c6b7d[s(726)]))throw new _0x4308ee(VSHsHi[s(864)]);return _0x2ccde5[s(615)]+=_0x491748,h}else return n&&e[s(1489)](!0,n[s(1473)])}static fromBits(n,s,d){return new ae(n,s,d)}static[t(1017)+"s"](n,s,d){let h=t;return d?ae[h(1017)+h(1862)](n,s):ae[h(1017)+h(1442)](n,s)}static[t(1017)+t(1862)](n,s){let d=t;return new ae(e[d(917)](e[d(879)](e.jKkMq(n[0],e[d(1639)](n[1],8)),n[2]<<16),e[d(1439)](n[3],24)),e[d(742)](e[d(1190)](e[d(532)](n[4],e[d(957)](n[5],8)),n[6]<<16),n[7]<<24),s)}static[t(1017)+t(1442)](n,s){let d=t;return new ae(e.mzyFo(n[4]<<24,n[5]<<16)|e[d(677)](n[6],8)|n[7],e[d(1370)](e.dnLsU(n[0]<<24,e[d(944)](n[1],16)),n[2]<<8)|n[3],s)}static[t(1303)](n){let s=t;return e[s(1420)](n,jr)?Gl:new ae(e[s(1464)](e[s(606)](e[s(742)](e[s(1502)](De.call(n,0),e[s(1696)](De[s(1755)](n,1),8)),e[s(1039)](De.call(n,2),16)),De[s(1755)](n,3)<<24),0),e[s(1700)](e[s(862)](e[s(489)](De[s(1755)](n,4),De[s(1755)](n,5)<<8)|e.OTGRF(De[s(1755)](n,6),16),De.call(n,7)<<24),0),!0)}[t(1258)](){let n=t;return String[n(1524)+"Code"](e[n(1413)](255,this.low),e[n(1005)](e[n(1238)](this[n(1373)],8),255),e.Ahnuo(this[n(1373)],16)&255,e[n(870)](this[n(1373)],24),e.sYXMT(255,this.high),e[n(1205)](this[n(1519)]>>>8,255),e[n(1491)](e[n(1813)](this[n(1519)],16),255),e[n(580)](this[n(1519)],24))}static[t(599)+"er"](n,s=!0){let d=t;if(isNaN(n))return s?ip:Gl;if(s){if(e[d(1522)]===e[d(1616)])this[d(803)]=!0,this[d(1532)]();else if(n>=Se)return op}else if(e[d(1253)]===e.JjqzH){if(e[d(697)](n,-Vn))return ap;if(e[d(1510)](e[d(526)](n,1),Vn))return sp}else{let h=this[d(1765)][d(1618)+d(1430)](this._prefix),y=_0x41108b[d(1706)](h||"{}");return y[_0x283f6e]=void 0,this[d(1765)][d(1326)+"geSync"](this[d(654)],_0x3cf5e1[d(518)+"y"](y))}return ae[d(1296)](e[d(1795)](e[d(1610)](n,ge),0),n/ge|0,s)}[t(1826)](){let n=t;if(e[n(1720)](e[n(1014)],e.kedGr)){let s=this._qosDB.getItem(this[n(654)]),d=_0x4d704e[n(1706)](e[n(848)](s,"{}"));return d[_0x3b6ee3]=void 0,this[n(1765)].setItem(this[n(654)],_0x3eec53[n(518)+"y"](d))}else return this.unsigned?e[n(572)](e[n(1297)](e[n(1425)](this.high,0),ge),e[n(1423)](this[n(1373)],0)):e[n(899)](this[n(1519)],ge)+e[n(1423)](this[n(1373)],0)}[t(1181)](){let n=t;return e[n(903)](0,this[n(1519)])&&e[n(1741)](0,this[n(1373)])}[t(633)](n){let s=t;ae[s(1473)](n)||(n=ae[s(599)+"er"](n));let d=this.high>>>16,h=e.maoqu(65535,this[s(1519)]),y=e[s(1227)](this[s(1373)],16),v=65535&this.low,I=e[s(1479)](n[s(1519)],16),g=e.GyZcm(65535,n[s(1519)]),R=e[s(1227)](n.low,16),M=e.ZOiJU(65535,n[s(1373)]),F=0,J=0,V=0,Ie=0;return Ie+=e[s(928)](v,M),V+=e[s(1238)](Ie,16),Ie&=65535,V+=e[s(650)](y,R),J+=V>>>16,V&=65535,J+=e[s(561)](h,g),F+=e[s(565)](J,16),J&=65535,F+=e[s(1152)](d,I),F&=65535,ae[s(1296)](e[s(1031)](e[s(1016)](V,16),Ie),e[s(1016)](F,16)|J,this[s(1124)])}equals(n){let s=t;return ae[s(1473)](n)||(n=ae[s(599)+"er"](n)),e[s(1720)](this[s(1124)],n[s(1124)])&&e[s(1637)](e[s(503)](this[s(1519)],31),1)&&e[s(1538)](n[s(1519)],31)===1?!1:this[s(1519)]===n[s(1519)]&&e[s(972)](this.low,n[s(1373)])}[t(1722)](){let n=t;return e.kLIlF(-1,this[n(1373)])&&this.high===-1?ae[n(1296)](0,0,this[n(1124)]):e.VtsMG(-1,this[n(1373)])?ae.fromBits(0,e.Muauh(this[n(1519)],1),this[n(1124)]):ae[n(1296)](this.low+1,this.high,this[n(1124)])}[t(883)](n){let s=t;return n?this[s(1871)+"E"]():this[s(923)+"E"]()}[t(1871)+"E"](){let n=t,s=this[n(1519)],d=this[n(1373)];return[e[n(1457)](255,d),e.qYUQa(d>>>8,255),e[n(594)](e[n(503)](d,16),255),d>>>24,e[n(1382)](255,s),e[n(1457)](e[n(1581)](s,8),255),e[n(1796)](e[n(565)](s,16),255),e.LESVB(s,24)]}[t(923)+"E"](){let n=t,s=this[n(1519)],d=this[n(1373)];return[e[n(580)](s,24),e[n(1005)](e[n(1881)](s,16),255),e[n(1201)](e[n(1813)](s,8),255),255&s,e[n(1256)](d,24),d>>>16&255,e[n(1106)](e.estaa(d,8),255),255&d]}}let Gl=new ae(0,0,!1),ip=new ae(0,0,!0),sp=ae[t(1296)](-1,2147483647,!1),op=ae[t(1296)](-1,-1,!0),ap=ae[t(1296)](0,-2147483648,!1);var en=(function(a){let n=t,s=(n(1119)+"3|2")[n(841)]("|"),d=0;for(;;){switch(s[d++]){case"0":a[a[n(521)+n(1788)+"R"]=5003]=e.SsEDu;continue;case"1":a[a[n(1663)+n(1814)]=5002]=e[n(494)];continue;case"2":return a;case"3":a[a[e.Gkuhf]=5005]=e[n(788)];continue;case"4":a[a[n(1576)+"ERROR"]=5004]=e[n(852)];continue;case"5":a[a[e[n(619)]]=5001]=e[n(619)];continue}break}})({});class Jn{constructor(n){let s=t;this[s(878)]=n,this.target=null}}class jl extends Jn{constructor(n,s){let d=t;super(n),this[d(737)]=s&&s[d(737)]||null}}class Wl extends Jn{constructor(n,s){let d=t,h=(d(1139)+d(1108))[d(841)]("|"),y=0;for(;;){switch(h[y++]){case"0":this[d(1789)]=s&&s.code||5001;continue;case"1":this[d(1707)]=s&&s[d(1707)]||0;continue;case"2":this[d(737)]=s&&s.message||"";continue;case"3":super(n);continue;case"4":this.error=s&&s[d(1437)]||null;continue;case"5":this.filename=s&&s[d(971)]||"";continue;case"6":this[d(889)]=s&&s.colno||0;continue}break}}}class Kl extends Jn{constructor(n,s){let d=t;super(n),this[d(1789)]=s&&s[d(1789)]||0,this[d(1824)]=s&&s[d(1824)]||"",this[d(929)]=s&&s[d(929)]||!1,this[d(1559)+d(721)]=s&&s[d(1559)+d(721)]||!1}}class $l extends Jn{constructor(n,s){let d=t;super(n),this.data=s&&s[d(447)]||null}}class Vl extends $l{constructor(n,s){let d=t;super(n),this[d(447)]=s&&s.data||null,this[d(737)]=s&&s.message||null}}class Jl extends Jn{constructor(n,s){let d=t;super(n),this[d(447)]=s&&s[d(447)]||null}}function it(a,{message:n,code:s,error:d}){let h=t;return e.JPqZZ(h(1627),e[h(566)])?new Wl(a,{message:n,code:s,error:d}):this[h(1347)+"T"]||this[h(1900)+"X"]?this[h(1381)+h(1890)+"line"]:(this._isBrowser||this[h(1069)+"r"])&&this[h(1281)][h(1884)+"tworkChanged"]?_0x19ad55[h(1433)]:!0}function ut(a,{code:n,reason:s,wasClean:d,willReconnect:h}){return new Kl(a,{code:n,reason:s,wasClean:d,willReconnect:h})}function Zl(a,{data:n,message:s}){return new Vl(a,{data:n,message:s})}function Yl(a,{data:n}){return new Jl(a,{data:n})}function sa(a,{message:n}){return new jl(a,{message:n})}class Xl{constructor(n,s){let d=t;this[d(1811)+"s"]=n,this[d(551)+"es"]=s,this[d(444)+d(884)]=0,this[d(1306)+"ndpointT"+d(1118)+"t"]=0}[t(1541)+t(857)+t(793)](){let n=t;this.currentIndex=0,this[n(1306)+n(1141)+"riesCount"]=0}[t(1805)+"es"](){this.currentEndpointTriesCount=0}[t(509)+t(1183)+"nt"](){let n=t;return this[n(1811)+"s"][this[n(444)+"ndex"]]}["getCurre"+t(1183)+"ntTriesC"+t(1611)](){let n=t;return this[n(1306)+"ndpointT"+n(1118)+"t"]}["checkRea"+t(949)+"es"](){let n=t;return!!(e.jXmJc(this[n(444)+n(884)],this[n(1811)+"s"][n(564)])||this[n(444)+n(884)]===this[n(1811)+"s"][n(564)]-1&&e[n(1015)](this[n(1306)+n(1141)+n(1118)+"t"],this[n(551)+"es"]))}[t(1499)+"rentEndpointReac"+t(1528)+t(1086)](){let n=t;return e[n(708)](e.urbvN,e[n(1176)])?new _0x3c153f(_0x206be7,{data:_0x39ea57}):e[n(914)](this[n(444)+n(884)],this.endpoints[n(564)])?!0:e[n(1778)](this[n(1306)+n(1141)+n(1118)+"t"],this[n(551)+"es"])}["replaceB"+t(1565)+t(1397)+t(695)+t(475)](){let n=t;return this[n(1306)+n(1141)+"riesCount"]=1,this[n(444)+n(884)]++,this.endpoints[this["currentI"+n(884)]]}["getCurre"+t(1183)+"ntAndUpd"+t(936)](){let n=t;return this[n(1306)+"ndpointT"+n(1118)+"t"]++,this["getCurre"+n(1183)+"nt"]()}}let Zn=(e.HuGrJ(e[t(427)],typeof globalThis)&&e.gwfTS(e[t(1277)],globalThis[t(1050)+t(1752)][t(1231)])||e[t(427)]!=typeof window&&e[t(1635)](e[t(1277)],window[t(1050)+"tor"][t(1231)]))&&e[t(427)]!=typeof document,In=e.azzpe(e[t(427)],typeof globalThis)&&(e[t(1257)](e.AWYnA,globalThis[t(1050)+t(1752)].name)||e[t(545)](e[t(1474)],globalThis[t(1050)+"tor"][t(1231)]))&&e[t(798)](e[t(427)],typeof tt),Wr=(e.pkwIX(e.HOWYn,typeof globalThis)&&e[t(1461)]===globalThis[t(1050)+t(1752)][t(1231)]||e[t(863)]("undefined",typeof globalThis)||e[t(427)]!=typeof globalThis&&!!globalThis[t(1129)+t(501)])&&e[t(1716)](e.HOWYn,typeof wx),Kr=e[t(1872)](e.HOWYn,typeof globalThis)&&(e[t(816)]("Dedicate"+t(1367)+t(1821)+"pe",globalThis[t(1050)+t(1752)][t(1231)])||e[t(426)](t(1865)+t(1339)+"alScope",globalThis[t(1050)+t(1752)][t(1231)])||e[t(1732)](t(1692)+t(641)+"balScope",globalThis[t(1050)+"tor"].name))&&e[t(514)](t(472)+"d",typeof self),cp=e[t(1310)](e.HOWYn,typeof globalThis)&&e[t(1365)](e[t(1461)],globalThis[t(1050)+t(1752)].name)&&e[t(798)](e[t(427)],typeof global)&&e[t(1461)]===global[t(1050)+"tor"][t(1231)]&&e[t(514)](e.HOWYn,typeof process)&&!!process.version;class oa{constructor(){let n=t;this[n(1443)+"rs"]={}}[t(1292)](n,...s){let d=t,h=this[d(1443)+"rs"][n];if(h)h[d(1321)]().forEach(y=>y.fn.apply(y[d(1235)],s));else if(e[d(1328)](e[d(613)],n)&&!this.onerror){let y=s[d(564)]&&s[0];if(e.gADfe(y,Error))throw y;let v=new Error(e[d(963)]+(y?e[d(527)](" (",y.message)+")":""));throw v.context=y,y}return this}[t(437)](n,s){let d=t;if(e.uejtQ(void 0,n))this[d(1443)+"rs"]={};else if(e[d(1234)](void 0,s))this[d(1443)+"rs"][n]=null;else{if(d(1317)==="rduBP")return this[d(1765)]?.[d(1052)];{let h=this[d(1443)+"rs"][n];if(h)for(let y=0;y<h.length;)h[y].fn===s?h[d(1852)](y,1):++y}}return this}on(n,s,d){let h=t,y={yeBqc:function(v,I,g){return v(I,g)},ppAGW:function(v,I){return e[U(417)](v,I)}};if(e[h(1489)](h(754),e[h(1825)]))return(this._listeners[n]||(this._listeners[n]=[])).push({fn:s,ctx:d||this}),this;_0x3aa55b(_0x2520d3,96),VAsBmE[h(1598)](_0x532bcd,_0x1d1196,VAsBmE.ppAGW(_0x370c72,_0xfca4fc))}}class lp extends oa{[t(1685)+"rrorMess"+t(1111)](n){let s=t;return n[s(1324)]||n[s(1514)]?("message: "+(n[s(1324)]||"")+" code: "+(n.errNo||"")).trim():JSON[s(518)+"y"](n)}constructor(n,s,d){let h=t;super(),this[h(1451)]=null,Wr&&wx[h(844)+h(1214)]&&(this[h(1451)]=wx[h(844)+h(1214)]({url:n,protocols:s,header:d,fail:this[h(1199)+h(698)+"lHandler"][h(1756)](this),success:this[h(1199)+h(1341)+h(1037)+h(1312)].bind(this)})),In&&tt[h(844)+"ocket"]&&(this[h(1451)]=tt[h(844)+h(1214)]({url:n,protocols:s,header:d,fail:this[h(1199)+"ocketFai"+h(1792)][h(1756)](this),success:this[h(1199)+h(1341)+h(1037)+h(1312)][h(1756)](this)}))}[t(1199)+"ocketSuc"+t(1037)+t(1312)](){let n=t,s={LdUka:function(d,h){return e[U(602)](d,h)}};Promise.resolve()[n(1555)](()=>{let d=n;if(s.LdUka(d(1042),d(1042)))this[d(1247)+d(995)]();else return _0x48bb7f.resolve()})}[t(1199)+"ocketFai"+t(1792)](n){let s=t;Promise[s(1418)]()[s(1555)](()=>{let d=s,h=e.nMOBn(it,"error",{message:this[d(1685)+d(785)+d(1111)](n)});this[d(1292)](e[d(613)],h);let y=e[d(1030)](ut,e[d(1725)],{reason:this["_formatE"+d(785)+d(1111)](n)});this[d(1292)](d(1876),y)})}["_addWsLi"+t(995)](){let n=t,s={vlnOK:function(d,h,y){return e[U(543)](d,h,y)},yeWEb:e[n(1585)],nlMwq:e[n(613)]};this._socket[n(528)](d=>{let h=n;this[h(1292)](h(568),s.vlnOK(Yl,s[h(858)],{...d,data:d[h(1324)]||""}))}),this[n(1451)][n(1167)](d=>{let h=n;this.emit(e[h(1725)],e.yIpyR(ut,e.hfegD,{...d}))}),this._socket[n(636)+"e"](d=>{let h=n;this[h(1292)](h(737),e[h(625)](Zl,e[h(434)],{...d}))}),this[n(1451)][n(659)](d=>{let h=n;this.emit(s[h(753)],s[h(1898)](it,"error",{...d,message:d.errMsg||""}))})}send(n){let s=t,d={SORSA:"error",jEOfl:function(h,y,v){return e[U(1780)](h,y,v)}};if(e.gADfe(n,Uint8Array)){let h=n.buffer[s(1321)](n[s(1444)+"et"],n[s(1045)+"th"]+n[s(1444)+"et"]);this[s(1451)]&&this._socket[s(1193)]({data:h,fail:y=>{let v=s;this[v(1292)](e[v(613)],it(e[v(613)],{message:this["_formatE"+v(785)+v(1111)](y)}))}})}else this[s(1451)]&&this[s(1451)][s(1193)]({data:n,fail:h=>{let y=s;this[y(1292)](d[y(941)],d[y(842)](it,d.SORSA,{message:this[y(1685)+y(785)+y(1111)](h)}))}})}[t(1876)](n,s){let d=t;this[d(1451)]&&this[d(1451)][d(1876)]({code:n,reason:s})}[t(1501)+t(649)](n,s){this.on(n,s)}[t(1779)+"entListe"+t(1298)](n,s){this[t(437)](n,s)}get[t(1008)+"te"](){return this[t(1451)].readyState}get[t(1529)+"pe"](){let n=t;return this[n(1451)][n(1529)+"pe"]}set[t(1529)+"pe"](n){}get url(){let n=t;return this[n(1451)][n(1450)]}get[t(486)](){return this._socket.protocol}get[t(1379)+"ns"](){let n=t;if(e[n(1143)](e[n(1065)],e.HkQFJ))return this[n(1451)][n(1379)+"ns"];this._DBName=_0x2b2f2c,this._pathKey=_0x2d7ecb,this[n(1765)]=_0x57b351}get[t(1229)+t(1209)](){return 0}}function dp(a,n){let s=t;if(n)return new n(a[s(1450)],a[s(486)]);if(e[s(1358)](Wr,In))return new lp(a.url,a[s(486)],a[s(1160)]);if(e.lUVSP(Zn,Kr)&&e[s(427)]!=typeof WebSocket&&WebSocket)return new WebSocket(a[s(1450)],a.protocols)}function up(a){let n=t;return!!(a||Wr&&wx.connectSocket||In&&tt[n(844)+n(1214)]||e[n(1358)](Zn,Kr)&&e[n(798)]("undefined",typeof WebSocket)&&WebSocket)}function Ql(a,n,s){let d=t,h={vHxOf:function(I,g){return e[U(1812)](I,g)},yLXKx:d(1694)+"alled mu"+d(1222)+d(1791)+d(1331),BTTRs:function(I,g){return e[d(1113)](I,g)}},y=-1;async function v(I){let g=d;return h[g(1575)](I,y)?Promise[g(930)](new Error(h.yLXKx)):(y=I,h[g(1226)](I,s.length)?Promise[g(1418)]():s[I][g(1756)](a)(n,v[g(1756)](null,I+1)))}e[d(1349)](v,0)}function ed(a){let n=t,s=0,d=0;for(let h=0;e[n(931)](h,a[n(564)]);++h)d=a[n(711)+"At"](h),e[n(1659)](d,128)?s+=1:e[n(1210)](d,2048)?s+=2:e[n(1807)](64512&d,55296)&&e.ANqRU(64512,a[n(711)+"At"](e[n(1269)](h,1)))===56320?(++h,s+=4):s+=3;return s}function td(a,n,s){let d=t,h={mOYAv:function(v,I,g){return e.MtMdC(v,I,g)},yaNGl:function(v,I,g){return v(I,g)}};if(e[d(451)](e[d(1745)](s,n),1))return"";let y="";for(let v=n;e[d(1095)](v,s);)if(e.nxrgN(e[d(1754)],d(832))){let I=a[v++];if(e[d(697)](I,127))y+=String[d(1524)+"Code"](I);else if(e.jXmJc(I,192)&&e.SiaIZ(I,224))y+=String[d(1524)+"Code"](e.AmlvD(e[d(594)](31,I)<<6,63&a[v++]));else if(e[d(1009)](I,224)&&I<240)y+=String[d(1524)+d(1577)](e[d(517)](e[d(1272)](e[d(1439)](e[d(1796)](15,I),12),e[d(890)](e[d(776)](63,a[v++]),6)),e.zBngX(63,a[v++])));else if(I>=240){let g=e[d(812)](e[d(1151)](e[d(1675)](e[d(1696)](e[d(702)](7,I),18)|e[d(674)](e[d(1404)](63,a[v++]),12),e[d(1793)](63,a[v++])<<6),e[d(996)](63,a[v++])),65536);y+=String[d(1524)+d(1577)](55296+e[d(1645)](g,10)),y+=String[d(1524)+d(1577)](56320+(1023&g))}}else UYtLaR[d(1268)](_0x1dcc14,_0x1f206f,66),UYtLaR[d(1019)](_0x16adbc,_0x327eaa,_0x69a383[d(564)]),UYtLaR[d(1019)](_0x2c4fe7,_0x34617e,_0x1fe65d);return y}function aa(a,n,s){let d=t,h=s,y,v;for(let I=0;e.AQAFl(I,a[d(564)]);++I)if(y=a[d(711)+"At"](I),e[d(1242)](y,128))n[s++]=y;else if(e.sclLN(y,2048))n[s++]=e[d(442)](e[d(1668)](y,6),192),n[s++]=e[d(1151)](e[d(478)](63,y),128);else if(e[d(1489)](e[d(479)](64512,y),55296)&&e[d(945)](e[d(762)](64512,v=a.charCodeAt(e[d(1329)](I,1))),56320)){let g=(d(1429)+d(1606))[d(841)]("|"),R=0;for(;;){switch(g[R++]){case"0":n[s++]=e.SsfNr(e[d(1201)](y>>6,63),128);continue;case"1":n[s++]=63&y|128;continue;case"2":y=e[d(1144)](65536+e.ssspf(e.dmMcC(1023,y),10),e[d(750)](1023,v));continue;case"3":n[s++]=e[d(750)](e[d(955)](y,12),63)|128;continue;case"4":++I;continue;case"5":n[s++]=e[d(1163)](e.fKYln(y,18),240);continue}break}}else n[s++]=e[d(1591)](y>>12,224),n[s++]=e[d(776)](e[d(542)](y,6),63)|128,n[s++]=e[d(1842)](e[d(1395)](63,y),128);return e.wllcU(s,h)}async function nd(a){let n=t;if(e.XDIzA(e[n(1070)],"XeZAz"))_0x205ab2=_0x3f87b6[e[n(1006)](e[n(1225)](_0x39be38,_0x25d8b3),1)],_0x2253cc=_0x318401[_0x1bd6aa+_0x33be50+2],_0x48a41f=_0x451d3d[e[n(1109)](e[n(905)](_0x39b023,_0x55a68f),3)],e[n(1505)](e[n(1456)](e[n(1368)](e[n(1704)](_0x3b87c2,e[n(1074)](_0x3c8d16,8)),e[n(1308)](_0x35e376,16)),12632256),8421504)?_0x1cdaf3+=_0x7d39c1:(_0x3f0624=e[n(530)](e.QRyXU(e[n(1774)](e[n(1439)](7&_0x1c76b1,18),e[n(712)](e[n(1713)](63,_0x2f33cd),12)),e[n(1586)](63&_0x2abc3f,6)),e[n(1028)](63,_0x780a94)),e[n(1659)](_0x57dc84,65536)||e[n(1851)](_0x4cc412,1114111)?_0x129ee1+=_0x2750d9:(_0x579632-=65536,_0xcb2c2a+=e[n(628)](_0x1ac987,e.fKYln(_0x39724b,10)+55296,e[n(1408)](e[n(1342)](1023,_0x3100d4),56320)),_0x147824+=3));else{if(e[n(1344)](e[n(828)],typeof a))if(e[n(1328)](e[n(1223)],e[n(1223)])){let s=new Uint8Array(e[n(1315)](ed,a));return e[n(1728)](aa,a,s,0),s}else{if(this[n(1669)+n(1815)]=!0,this[n(990)+n(1333)](),this[n(1431)+n(952)](),this[n(1674)+n(1424)+n(649)](),this["_QoSMana"+n(1290)]?.[n(1500)](),!this[n(640)])return void this[n(729)](e[n(1061)]);if(e[n(945)](this._ws[n(1008)+"te"],this[n(1243)])||e[n(1633)](this[n(640)][n(1008)+"te"],this[n(1567)]))return void this[n(729)](n(1262)+n(520)+n(1138));this["_destroy"+n(946)+"t"](_0x156bec,_0x87360b)}return e[n(692)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(418)],a.byteOffset,a[n(1045)+"th"])}}function fp(a){let n=t;try{return e[n(1446)](e.VTwGM,typeof a)&&(e[n(692)](a,ArrayBuffer)||a[n(418)]&&e[n(692)](a[n(418)],ArrayBuffer))||e[n(563)](e.VTwGM,typeof a)?"":(JSON[n(1706)](a),n(421)+"ion/json")}catch{return e[n(914)](e.VTwGM,typeof a)?e[n(1800)]:""}}let hp=(a,n)=>{let s=t;switch(a){case e[s(881)]:case e[s(1134)]:return{[s(540)+a]:1,"x-tt-env":n};default:return{}}};class xp{constructor(n){let s=t;this[s(1357)+s(1611)]=n,this[s(1542)]=0}[t(1512)](){let n=t;e.ELbuD(n(1772),e[n(1392)])||this[n(1542)]++}["checkRea"+t(1506)+"nt"](){let n=t;return this[n(1542)]>=this[n(1357)+n(1611)]}[t(829)+t(1309)](n=0){let s=t;this[s(1357)+s(1611)]=n,this.count=0}}async function pp(a){let n=t,s={IHbOy:function(d,h){return d(h)},FpzzC:function(d,h){return e[U(1496)](d,h)},dlMqK:e[n(1024)],QZnWb:n(1081),McGmx:function(d,h){return e[n(869)](d,h)},eWKWm:function(d,h){return e.XjtVU(d,h)}};return new Promise(d=>{let h=n,y={YjsvA:function(v,I){return s.IHbOy(v,I)}};if(!Zn)return s[h(1540)](d,s[h(1708)]);try{let v=document["createEl"+h(1454)](s[h(1553)]);window[h(485)+h(1839)]=I=>{let g=h;document[g(909)][g(1855)+g(1465)](v),window["frontier"+g(1839)]=void 0,y[g(1140)](d,I&&I[g(1590)]||g(1293)+g(1824))},v[h(878)]=h(922)+h(790),v[h(1607)]=s[h(661)](a.replace(/^ws/,h(648)),"&jscallb"+h(1049)+"tierJSONP");try{document[h(909)][h(861)+"ild"](v)}catch{document[h(909)][h(1855)+h(1465)](v)}}catch{window[h(485)+h(1839)]=void 0,s.eWKWm(d,s[h(1708)])}})}function tn(a,n,s){return!!a?.[t(1102)](h=>h.key===n&&h.value===s)}function Yn(a,n){let s=t;return a?.[s(1102)](d=>d[s(1121)]===n)?.value}let ca=null;async function gp(){let a=t;if(e[a(823)](e[a(1025)],e[a(1025)])){if(e[a(466)](_0x160a9c,-_0x52f17c))return _0x207339;if(e[a(1352)](_0x2e06f2+1,_0x321e18))return _0x1c6f02}else return ca||(ca=Promise[a(1418)]().then(Nt[a(1756)](Nt,e[a(978)]))),ca}class mp extends oa{constructor(n,s){let d=t;super(),this._dbName=n,this._keyPath=s,this[d(1765)]=void 0,this[d(1662)+d(838)]=null}async[t(1661)](){await this[t(488)]()}async[t(488)](){let n=t,s={JtbEA:function(d){return d()},rtswx:function(d,h,y,v){return e.TLskm(d,h,y,v)},tmrfG:function(d,h){return e[U(1840)](d,h)},yGwpJ:function(d,h){return d!==h},QmBhN:e[n(686)]};if(e[n(1115)](e[n(533)],e[n(1786)])){if(this._qosDB)return;if(this[n(1662)+n(838)])return this[n(1662)+n(838)];try{let d=this[n(966)],h=this._keyPath;this[n(1662)+n(838)]=(async()=>{let y=n,{openDB:v}=await s[y(1366)](gp);this[y(1765)]=await s[y(1449)](v,y(485)+"_"+d,1,{upgrade(I){I[y(1544)+"jectStore"](d,{keyPath:h})}})})(),await this["_initPro"+n(838)]}catch(d){console[n(1908)](d)}finally{this["_initPro"+n(838)]=null}}else this["_navigat"+n(1441)]()&&(!this[n(640)]||s[n(1771)](this[n(640)][n(1008)+"te"],this[n(935)])||s[n(1346)](this._ws[n(1008)+"te"],this[n(1663)+"NG"]))&&this[n(1348)+n(1873)](),this[n(423)+"er"]&&_0x4e2404[n(1501)+n(649)](n(470),this[n(1348)+n(1873)]),this[n(423)+"er"]&&_0x5e75a3[n(1501)+n(649)](s[n(476)],this[n(1348)+n(1097)])}async[t(1363)](n){let s=t;try{return await this._init(),this[s(1765)]?.get(this[s(966)],n)}catch(d){console[s(1908)](d)}}async[t(597)](n,s){let d=t;return await this[d(488)](),this._qosDB?.[d(937)](this[d(966)],n)}async del(n){let s=t;try{return await this[s(488)](),this[s(1765)]?.[s(821)](this[s(966)],n)}catch(d){console.log(d)}}async[t(898)](){let n=t;try{if(e[n(1714)]!=="pujRO")return await this[n(488)](),this[n(1765)]?.[n(898)](this[n(966)]);_0x582a10["createOb"+n(1462)+"e"](_0x2dddbe,{keyPath:_0x5212ca})}catch(s){console[n(1908)](s)}}async[t(1854)](){let n=t;if(e[n(1092)]!==e[n(1092)]){let s=e[n(1796)](255,_0x5d9a9a);e[n(739)](_0x5e7d69,s,_0x31afcf,e.dZHQA(_0x38ce63,_0x2e1310)),_0x38770e>>>=8,_0x2aa883--}else return await this[n(488)](),this[n(1765)]?.[n(1195)+"ys"](this[n(966)])}async[t(1476)](){let n=t;return await this._init(),this._qosDB?.[n(1476)](this[n(966)])}async[t(1500)](){let n=t,s={zJIWb:function(d,h,y){return e[U(1764)](d,h,y)},abkjv:function(d,h){return e[U(1813)](d,h)},QCYxX:function(d,h){return e.TvhSi(d,h)}};try{this[n(1765)]?.close(),this[n(1765)]=void 0}catch(d){if(e[n(1328)](e[n(965)],e[n(758)])){let{value:h,offset:y}=s[n(1435)](_0x524b3b,_0x39c308,_0x11e057);_0x2d25fe=y,_0x172f80=s.abkjv(s[n(1393)](_0x33dc71,8),0),_0x8aacae+=h}else console.log(d)}}get[t(1052)](){let n=t;try{return!!this[n(1765)]}catch(s){return console.log(s),!1}}}class wp{constructor(n,s){let d=t;e.SvkrA!==d(1799)?(this[d(635)]=n,this._pathKey=s,this[d(1765)]=localStorage):(e.dLSFJ(_0x37716d,_0x393884,18),_0x35d4d6(_0x4fd27c,_0x2f7d21))}async[t(1661)](){}get[t(654)](){return t(485)+"_"+this._DBName}async[t(1363)](n){let s=t,d=this[s(1765)][s(1621)](this[s(654)]);return JSON[s(1706)](d||"{}")[n]}async[t(597)](n,s){let d=t,h=this[d(1765)][d(1621)](this[d(654)]),y=JSON.parse(h||"{}");return y[s||n[this._pathKey]]=n,this[d(1765)][d(947)](this[d(654)],JSON[d(518)+"y"](y)),s||n[this[d(657)]]}async[t(856)](n){let s=t;if(e[s(1770)](e[s(1426)],e.VvuVa)){let d=this._qosDB.getItem(this._prefix),h=JSON.parse(e.lUVSP(d,"{}"));return h[n]=void 0,this[s(1765)][s(947)](this[s(654)],JSON[s(518)+"y"](h))}else return new _0x561301(_0xbcd927,{code:_0x16120e,reason:_0x24d69b,wasClean:_0x1ab8c5,willReconnect:_0x211e86})}async clear(){let n=t;return this._qosDB[n(898)]()}async keys(){let n=t,s=this[n(1765)][n(1621)](this[n(654)]),d=JSON[n(1706)](e.lUVSP(s,"{}"));return Object[n(1854)](d)}async getAll(){let n=t;if(e[n(1218)](e[n(1912)],"etfRx")){let s=this[n(1765)][n(1621)](this._prefix),d=JSON[n(1706)](e[n(582)](s,"{}"));return Object[n(1116)](d)}else{let s=e[n(487)](_0x43ff14,_0x3b0e0c);this._ws&&e[n(1420)](this[n(640)].readyState,this[n(935)])&&(this[n(640)]&&this._ws[n(1193)](s),this[n(729)](n(1762),_0xfb7a5b))}}[t(1500)](){return Promise.resolve()}get isReady(){return!!this[t(1765)]}}class _p{constructor(n,s){let d=t,h={aAnRF:function(y,v){return y(v)},CJkWw:e.ESMWn,OFDXB:function(y){return y()}};e[d(1635)](e.jwqpN,e[d(595)])?(this[d(635)]=n,this._pathKey=s,this[d(1765)]=In?tt:Wr?wx:null):(fIepRU.aAnRF(_0x37461c,_0x47dde2[d(1437)]||new _0x6f47b7(fIepRU.CJkWw,fIepRU[d(1891)])),fIepRU[d(567)](_0x281769))}async[t(1661)](){}get[t(654)](){let n=t;return n(485)+"_"+this[n(635)]}async[t(1363)](n){let s=t,d=this[s(1765)][s(1618)+s(1430)](this[s(654)]);return JSON[s(1706)](e[s(1361)](d,"{}"))[n]}async set(n,s){let d=t;if(e[d(999)](e.axJEQ,e[d(1396)])){let h=this[d(1765)]["getStora"+d(1430)](this[d(654)]),y=JSON[d(1706)](e.mUcLW(h,"{}"));return y[s||n[this[d(657)]]]=n,this[d(1765)]["setStora"+d(1430)](this[d(654)],JSON[d(518)+"y"](y)),s||n[this[d(657)]]}else this[d(1662)+d(838)]=null}async[t(856)](n){let s=t,d=this._qosDB[s(1618)+s(1430)](this[s(654)]),h=JSON.parse(e[s(582)](d,"{}"));return h[n]=void 0,this[s(1765)][s(1326)+s(1430)](this[s(654)],JSON[s(518)+"y"](h))}async[t(898)](){return this._qosDB.clearStorageSync()}async[t(1854)](){let n=t,s=this[n(1765)]["getStora"+n(1869)+"nc"](this[n(654)]),d=JSON[n(1706)](e[n(671)](s,"{}"));return Object.keys(d)}async[t(1476)](){let n=t,s=this._qosDB.getStorageInfoSync(this[n(654)]),d=JSON.parse(e[n(582)](s,"{}"));return Object.values(d)}[t(1500)](){return Promise[t(1418)]()}get[t(1052)](){return!!this[t(1765)]}}function rd(a,n){let s=t;if(e[s(1265)](In,In))return new _p(a,n);if(e.tMaVM(Zn,Kr)&&e[s(563)](e[s(427)],typeof indexedDB))return new mp(a,n);if(e[s(847)](Zn,Kr)&&e[s(427)]!=typeof localStorage)return new wp(a,n);throw new Error(e[s(523)])}class yp{constructor(){let n=t;this[n(1907)+n(1830)+"Id"]=null,this[n(1907)+"l"]=36e5,this[n(1765)]=e.TLYDQ(rd,e.YUvFT,e.jyJIL)}async[t(1907)+"lFlush"](){let n=t;e[n(547)](clearInterval,this[n(1907)+n(1830)+"Id"]),this[n(1907)+n(1830)+"Id"]=e[n(1071)](setInterval,()=>{this[n(670)+"ired"]()},this[n(1907)+"l"])}async[t(1661)](){let n=t;await this[n(1765)][n(1661)]()[n(1555)](()=>{let s=n;this[s(1907)+s(1261)]()})}async["flushExp"+t(843)](){let n=t;(await this[n(1765)]?.[n(1476)]()||[]).filter(({timestamp:h})=>h<Date[n(1564)]()).forEach(h=>{let y=n;this._qosDB?.[y(856)](h[y(1642)+"id"])})}async del(n){let s=t;return e[s(1115)](e[s(911)],e.gJHgI)?this._qosDB?.del(n):(_0x2ab356[s(634)+"t8"]?_0xeaf295[s(634)+"t8"](_0x547289,_0xef5502):_0x48c898[_0x4f73b9]=e[s(932)](255,_0x1628e8),e.uuoUC(_0xa52f13,1))}async set(n,s){let d=t;return this[d(1765)]?.[d(597)]({message_id:n,timestamp:s})}async[t(1363)](n){return this[t(1765)]?.get(n)}async[t(1500)](){let n=t;clearInterval(this["_interva"+n(1830)+"Id"]),await this[n(1765)]?.[n(1500)]()}get[t(1052)](){let n=t;return this._qosDB?.[n(1052)]}}function la(a){let n=t;if(e[n(999)](e[n(432)],e[n(432)]))return this[n(1811)+"s"][this[n(444)+n(884)]];{let s=!!this[n(1281)][n(1911)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let d=e[n(741)](tn,a[n(737)][n(1160)],e[n(1168)],"2"),h=d&&e[n(739)](tn,a[n(737)][n(1160)],e[n(439)],"1"),y=d&&tn(a[n(737)][n(1160)],e[n(512)],"1"),v=y?e[n(609)](Yn,a[n(737)].headers,n(1631)+"er_ack_m"+n(1022))?.split(",")[n(448)](Boolean)||[]:[];return{enabled:s,isQoSMessage:d,isQoSAck:h,isAckCleanupMessage:y,ackMsgIds:v}}}async function id(){let a=t;return this[a(1076)+"ger"]||(this._QoSManager=new yp),this[a(1076)+a(1290)][a(1052)]||await this[a(1076)+"ger"].openDB(),this["_QoSMana"+a(1290)]}async function Ep(a,n){let s=t,{enableAutoAck:d}=this._options,h=e[s(739)](tn,a.message[s(1160)],e[s(630)],"1"),y=tn(a[s(737)][s(1160)],e[s(1187)],"1"),v=la.call(this,a);if(e[s(1582)](d,h)){let{SeqID:I,LogID:g,service:R,LogIDNew:M,method:F}=a[s(737)];this[s(720)]({SeqID:I,LogID:g,LogIDNew:M,service:R,method:F,headers:[{key:"is_ack",value:"1"},{key:e[s(1245)],value:M||""},{key:e[s(1082)],value:"0"}]})}y&&!v[s(627)]&&this[s(1850)+s(605)+s(1834)](a),e.zDvBd(n)}async function bp(a,n){let s=t;this._debug(e[s(1494)],a.message),n()}async function vp(a,n){let s=t,d=e[s(487)](Xt,await e.yVHoU(nd,a.data));try{if(e[s(1137)](s(1684),e[s(1798)]))if(d[s(1580)]instanceof Uint8Array){let h=e.rFdZV(this._options[s(1112)+"ncoding"],Object)?{force:!!this._options[s(1112)+s(1892)][s(647)],encoding:this._options.payloadEncoding[s(456)]?this[s(1281)][s(1112)+s(1892)][s(456)].replace(/\s/g,"")[s(1327)+s(924)]():""}:{force:!1,encoding:this._options[s(1112)+s(1892)]?this[s(1281)][s(1112)+"ncoding"][s(1766)](/\s/g,"")["toLowerC"+s(924)]():""},y=d["payloadE"+s(1892)]?d[s(1112)+s(1892)][s(1766)](/\s/g,"")[s(1327)+s(924)]():"",v=e[s(611)](this._options[s(1114)+s(1547)],Object)?{force:!!this[s(1281)]["payloadT"+s(1547)][s(647)],type:this._options[s(1114)+"ype"][s(878)]?this[s(1281)][s(1114)+"ype"][s(878)][s(1766)](/\s/g,"")[s(1327)+"ase"]():""}:{force:!1,type:this[s(1281)][s(1114)+s(1547)]?this[s(1281)][s(1114)+"ype"][s(1766)](/\s/g,"")[s(1327)+s(924)]():""},I=d[s(1114)+s(1547)]?d["payloadT"+s(1547)][s(1766)](/\s/g,"")[s(1327)+"ase"]():"",g=v[s(647)]?v[s(878)]:I||v[s(878)],R=h[s(647)]?h[s(456)]:y||h[s(456)],M=[e[s(1800)],e[s(1338)],e[s(1709)],e[s(828)]],F=[e[s(652)],e[s(586)]];this[s(1281)][s(1452)+s(481)+s(1632)+"ad"]&&M[s(1021)](g)&&(!R||F.includes(R))?d[s(988)+s(682)]=e.mQUqI(td,d[s(1580)],0,d.payload[s(1045)+"th"]):d["textPayl"+s(682)]=""}else d[s(988)+s(682)]="";else return e[s(1113)](_0x30582e,_0x3e5112)?_0x4b15c4:new _0x2260d9(e[s(1597)](e[s(1163)](_0x497dc5[s(1755)](_0x14eb89,0)|e[s(1639)](_0x44eddd[s(1755)](_0x166f78,1),8)|e.TvhSi(_0x73d06a[s(1755)](_0x1a77ab,2),16),_0x561c99[s(1755)](_0x554322,3)<<24),0),e[s(1581)](e.gOOEx(_0xb4563d[s(1755)](_0x6c66e6,4)|e[s(1016)](_0x59c087[s(1755)](_0x552294,5),8),e[s(496)](_0x9c5bf8[s(1755)](_0x4891da,6),16))|e[s(1612)](_0x412d55[s(1755)](_0x5b96d8,7),24),0),!0)}catch(h){d.textPayload="",console[s(1908)](h)}a.message=d,e[s(1105)](n)}function Sp(a,n,s){let d=t,h=e[d(1358)](s,8192),y=h>>>1,v=null,I=h;return function(g){let R=d;if(e[R(778)](g,1)||e[R(1794)](g,y))return e[R(487)](a,g);e[R(1152)](I,g)>h&&(v=e[R(707)](a,h),I=0);let M=n.call(v,I,I+=g);return e[R(594)](7,I)&&(I=e[R(1563)](e[R(442)](7,I),1)),M}}let Ip=4294967295;function Ap(a,n,s){let d=t;return e[d(1325)](RangeError,e[d(1408)](e[d(1131)](e[d(1185)](e.IgiDy(e.NNOIL,a),e.vAGtj),e.dwdtc(n,1))+e.WorZp,s))}function Tp(a,n,s){let d=t;if(e.LmGva(s,Ip))throw new Error(d(539)+"too large");let h=3;for(;e.VUckq(h,0);)if(e[d(1218)](e[d(1877)],e[d(1877)]))e[d(417)](_0xf3631b,d(1742)),this.off(e.wpeby,_0x2c6fda),this.off(e[d(1054)],_0xfba3a9);else{let y=e[d(594)](255,s);e[d(1318)](ua,y,a,e[d(1064)](n,h)),s>>>=8,h--}return e[d(555)](n,4)}function Cp(a,n){let s=t,d=0,h=n,y=n+4;for(;e.Jmtpw(h,y);){let{value:v,offset:I}=da(a,h);h=I,d=e[s(1813)](e.ssspf(d,8),0),d+=v}return{value:d,offset:y}}function Rp(a,n,s){let d=t;return a?e[d(1649)](a[d(564)],40)?e.tOaBf(e[d(508)](aa,a,n,s),s):n[d(1207)+"e"]?e[d(1888)](n[d(1207)+"e"](a,s),s):n[d(498)]?n[d(498)](a,s)+s:e[d(869)](e[d(1029)](aa,a,n,s),s):s}function Dp(a,n){let s=t,d=new ae(e[s(1186)](e[s(515)](a[n+4]<<24,a[n+5]<<16),e[s(1039)](a[e.qByYD(n,6)],8))|a[e[s(527)](n,7)],e[s(530)](e[s(515)](e[s(919)](a[e[s(1284)](n,0)],24),e[s(674)](a[e[s(942)](n,1)],16)),a[n+2]<<8)|a[e[s(1583)](n,3)],!0);return n+=8,{value:d,offset:e.RzUCT(n,8)}}function kp(a,n,s){let d=t,h=a[d(1373)],y=a[d(1519)];return n[s]=e[d(1227)](y,24),n[e.aKwvW(s,1)]=e[d(440)](y,16)&255,n[e.lgExY(s,2)]=e.sswsq(e.VPMog(y,8),255),n[e[d(1653)](s,3)]=255&y,n[e[d(610)](s,4)]=e.UnpTd(h,24),n[e.XDNfa(s,5)]=e.WGzaw(e.oFZSp(h,16),255),n[e.jRvNy(s,6)]=e[d(565)](h,8)&255,n[e[d(1012)](s,7)]=255&h,s+=8,s}function da(a,n){let s=t,d={HRWrR:e.zfCyl};if(e[s(1840)](e[s(855)],e[s(855)])){let v=d[s(1679)][s(841)]("|"),I=0;for(;;){switch(v[I++]){case"0":if(h!==void 0)return h[s(1652)];continue;case"1":return y[s(1652)];case"2":var h=_0x1a2885[_0x2b580c];continue;case"3":_0x40e166[_0x107a9e](y,y[s(1652)],_0x33c6f4);continue;case"4":var y=_0x29b052[_0xa8abdc]={exports:{}};continue}break}}else return a.readUInt8?{value:a[s(1485)+"8"](n),offset:e[s(610)](n,1)}:{value:e[s(1511)](255,a[n]),offset:e[s(1888)](n,1)}}function ua(a,n,s){let d=t;return n[d(634)+"t8"]?n[d(634)+"t8"](a,s):n[s]=e[d(876)](255,a),e[d(665)](s,1)}let Pp=function(a){return new Uint8Array(a)},Op=e[t(1822)](t(472)+"d",typeof Buffer)?Buffer[t(783)+t(1495)]:Sp(Pp,Uint8Array[t(1763)+"e"][t(1080)]);(()=>{let a=t,n={HHfzs:function(s,d){return e.XPQCD(s,d)},DQSUh:function(s,d){return e[U(1210)](s,d)},AFBUh:function(s,d){return e[U(862)](s,d)},cawXy:function(s,d){return s>>>d},TgWgi:function(s,d){return e[U(1696)](s,d)},TMYrS:function(s,d){return e.acClP(s,d)},AUfrZ:function(s,d){return e[U(1278)](s,d)},mDZBi:function(s,d){return e[U(906)](s,d)},RosTy:function(s,d){return s&d},SSLKw:function(s,d){return e[U(853)](s,d)},OtCoe:function(s,d){return s<d},Vkdmm:function(s,d){return e[U(1478)](s,d)},nVrQN:function(s,d){return s<<d},WpkwS:function(s,d){return e[U(715)](s,d)},xwibZ:function(s,d){return e.HaZLT(s,d)},mRPPC:function(s,d){return e[U(422)](s,d)},RZVIZ:e[a(1150)],EHCMe:function(s,d,h,y){return s(d,h,y)},iaZRi:function(s,d){return e[a(593)](s,d)}};if(e[a(1637)](e.DNbwS,a(951))){let s=4294967295;return function(d,h,y=!0){let v=a;if(s=n[v(1200)](127,d[h])>>>0,n[v(492)](d[h++],128))return{value:y?s:n[v(1123)](0,s),offset:h};if(s=n[v(651)](s|n[v(1680)](n[v(1200)](127,d[h]),7),0),n[v(921)](d[h++],128))return{value:y?s:n[v(831)](0,s),offset:h};if(s=n[v(651)](n[v(1084)](s,n[v(1680)](n[v(1364)](127,d[h]),14)),0),n[v(921)](d[h++],128))return{value:y?s:n[v(1084)](0,s),offset:h};if(s=(s|n[v(1680)](n[v(1334)](127,d[h]),21))>>>0,n[v(1405)](d[h++],128))return{value:y?s:n[v(1084)](0,s),offset:h};if(s=n[v(833)](s,n[v(968)](n.HHfzs(15,d[h]),28))>>>0,d[h++]<128)return{value:y?s:n[v(1557)](0,s),offset:h};if(n.xwibZ(h+=5,d.length)){if(n[v(1023)](n[v(1767)],n[v(1767)]))return null;throw h=d[v(564)],n[v(725)](Ap,h,10,d[v(564)])}return{value:y?s:n[v(767)](0,s),offset:h}}}else xe[a(1431)+a(952)](),xe[a(1292)](e[a(1294)],a(1569)),xe[a(623)+a(1125)+"Id"]=e.lIilm(_0x333dac,xe[a(763)][a(1756)](xe),_0x1429a5)})();let Lp=16,fa=32;function Np(a){let n=t,s=0,d={};for(let h=0;h<a[n(564)];h++)d[a[h][n(1056)+n(1068)]]=e[n(1828)](ed,a[h][n(1056)+"ame"]),s+=14+d[a[h][n(1056)+n(1068)]];return[s,d]}function sd(a,n,s){let d=t,[h,y]=e[d(805)](Np,a),v=e.omKqX(Op,h),I=0;return a[d(639)](g=>{let R=d;if(e[R(1420)](e[R(1188)],e[R(1188)])){let M=e[R(989)][R(841)]("|"),F=0;for(;;){switch(M[F++]){case"0":I=e[R(1409)](Tp,v,I,g[R(1617)]||0);continue;case"1":console[R(1908)](e[R(846)],I);continue;case"2":I=kp(ae.fromNumber(g[R(1203)]||n),v,I);continue;case"3":console[R(1908)](e[R(675)],g,g[R(1617)]);continue;case"4":console[R(1908)](e[R(1336)],I);continue;case"5":I=e[R(600)](ua,0,v,I);continue;case"6":I=e[R(1701)](Rp,g[R(1056)+R(1068)],v,I);continue;case"7":I=e[R(739)](ua,y[g["cursor_n"+R(1068)]],v,I);continue;case"8":console[R(1908)](R(1617),I);continue;case"9":console.log(e[R(541)],I);continue;case"10":console[R(1908)](e[R(1274)],I);continue}break}}else this._isMiniTT?_0x260513["onNetwor"+R(430)+"hange"](({isConnected:M})=>{let F=R;this[F(1381)+F(1890)+F(1806)]=M,M?this[F(1348)+"nLine"]():this[F(1348)+F(1097)]()}):this._isMiniWX&&_0x3477a2[R(1048)+R(430)+R(950)](({isConnected:M})=>{let F=R;this[F(1381)+F(1890)+F(1806)]=M,M?this[F(1348)+"nLine"]():this["_handleO"+F(1097)]()})}),{frameType:fa,headers:[{key:e[d(1837)],value:s}],payload:v}}function Mp(a){let n=t,s=0,d=[];for(;e.MFpIa(s,a[n(1045)+"th"]);)if(e[n(1313)](e[n(1885)],n(691))){let{offset:h}=da(a,s);s=h;let y={cursor_name:"",cursor:0,service:0},{value:v,offset:I}=e[n(1032)](Cp,a,s);y[n(1617)]=v,s=I;let{value:g,offset:R}=da(a,s);s=R,y["cursor_n"+n(1068)]=e[n(794)](td,a,s,e.eesJm(s,g)),s+=g;let{value:M,offset:F}=e[n(1638)](Dp,a,s);y.cursor=M.toNumber(),s=F,d[n(596)](y)}else return this[n(1306)+n(1141)+n(1118)+"t"];return d}function Bp(){let a=t;return{frameType:fa,headers:[{key:e[a(1837)],value:e[a(1067)]}],payload:void 0}}class Fp{constructor(n,s,d){let h=t;this[h(1893)+h(1101)]=n,this["_cursorF"+h(1369)]=s,this[h(1608)+h(959)]=d,this[h(1765)]=e.Hzgnu(rd,this[h(1893)+h(1101)],e[h(706)])}async openDB(){let n=t;await this[n(1765)][n(1661)]()}async[t(1232)+"rs"](){let n=t;if(!this[n(1765)][n(1052)])return;let s=this["_message"+n(959)],d=await this[n(1765)][n(1476)]();switch(console[n(1908)](e[n(1570)],d),s){case e[n(624)]:return d&&d[n(564)]?e[n(794)](sd,d,0,this["_cursorF"+n(1369)]):void 0;case e[n(669)]:return;case"CONTINUE":return d&&d[n(564)]?e.MyqCE(sd,d,0,this[n(1599)+"ileName"]):e.JwFjE(Bp)}}async set(n,s,d){let h=t;return console.log(e.wuDzu,n,s,d),this[h(1765)][h(597)]({cursor_name:n,cursor:s,service:d})}async[t(1289)+"rs"](n){let s=t,d=e.jOgRc(Mp,n);for(let h of d)console[s(1908)](e[s(557)],d),await this._qosDB[s(597)](h)}async[t(1363)](n){let s=t;return(await this._qosDB[s(1363)](n))?.[s(1203)]}async[t(1500)](){let n=t;await this[n(1765)][n(1500)]()}[t(1810)+"rsorFile"+t(452)](n){let s=t;this[s(1599)+s(1369)]=n}get isReady(){let n=t;return this[n(1765)][n(1052)]}}let zp="__x_msg_qos__";async function od(a){let n=t,s={avAyL:n(1437)};if(!this._options[n(1911)+"S"])return null;let{aID:d,fpID:h,messageStrategy:y}=this._options,v=e.CxKYz(a,zp);try{return this[n(1736)+n(1093)]?e[n(1468)](e[n(1758)],e[n(1411)])?(this[n(1292)](s[n(585)],_0xa7319b),this[n(1184)]&&this[n(1184)](_0x58fbe1)):a&&this[n(1736)+"anager"][n(1810)+"rsorFileName"](a):this[n(1736)+n(1093)]=new Fp(h+"_"+d+"_"+v,v,y),this[n(1736)+n(1093)][n(1052)]||await this[n(1736)+n(1093)].openDB(),this._cursorManager}catch{return null}}async function Up(a,n){let s=t,d=tn(a[s(737)][s(1160)],e.bwnLB,"-1"),h=tn(a[s(737)].headers,e[s(1187)],"1"),y=e.vcZhb(Yn,a[s(737)][s(1160)],e[s(1291)]),v=e[s(1486)](Number,e[s(1062)](Yn,a[s(737)].headers,e[s(1739)]))||0,I=la.call(this,a),g=e[s(680)](tn,a[s(737)][s(1160)],e[s(980)],"2"),R=e[s(1438)](Yn,a.message[s(1160)],"x-msg-cu"+s(1737)+"e"),M=Number(e.ZwDix(Yn,a[s(737)][s(1160)],e[s(1419)]));if(I[s(627)])return e[s(1447)](n);let F=I.isQoSMessage?await id[s(1755)](this):null;if(e[s(1794)](a[s(737)].service,0)&&h&&!d||e[s(457)](a[s(737)][s(1617)],0)){if(y&&I["isQoSMes"+s(571)]&&F)if(e.XOuoS(e[s(1091)],e[s(1594)]))_0x49cc53[s(1418)]()[s(1555)](()=>{this["_addWsLi"+s(995)]()});else return!!!await F[s(1363)](y)&&(this[s(1850)+s(1903)+"Event"](a),await F.set(y,e[s(1307)](Date[s(1564)](),v))),e[s(1546)](n);if(g){let J=await od.call(this);if(!J)return this["_dispatc"+s(1903)+s(868)](a),e.iCPGS(n);let V=await J[s(1363)](R)??-1;if(e.SiaIZ(V,M))this[s(1850)+s(1903)+s(868)](a),J[s(597)](R,M,a[s(737)][s(1617)]);else throw new Error("recevied"+s(455)+s(1266)+M+(" larger "+s(1194)+s(1173)+"r ")+V);return n()}return this["_dispatc"+s(1903)+s(868)](a),e[s(894)](n)}}async function Hp(a,n){let s=t;if(e.XNdjJ(e[s(1299)],e[s(1299)]))return this[s(1306)+s(1141)+"riesCount"]++,this[s(509)+s(1183)+"nt"]();{let d=la.call(this,a);if(!d[s(916)+"sage"])return e[s(482)](n);let h=await id[s(1755)](this);if(d[s(1769)+s(1910)+s(1111)]&&d[s(1085)+"s"][s(564)])for(let y of d[s(1085)+"s"])await h[s(856)](y);e.ljgBC(n)}}async function qp(a,n){let s=t,d=a[s(737)][s(748)+"e"]===Lp,h=a[s(737)][s(748)+"e"]===fa;if(e.pIwqF(!d,!h))return e.HYJrC(n);let y=e[s(1007)](Yn,a.message[s(1160)],e[s(1837)]);if(!y)return e[s(1887)](n);let v=await od.call(this,y);if(!v)return e[s(1650)](n);if(d){let I=await v[s(1232)+"rs"](),g={frameType:I?.[s(748)+"e"],SeqID:ae[s(599)+"er"](this[s(900)]++),LogID:ae.fromNumber(this[s(1281)][s(795)+"erator"]()),service:9e3,method:5,headers:I?.[s(1160)],payload:I?.[s(1580)]},R=e[s(1349)](b,g);this[s(640)]&&this._ws.readyState&&this._ws.send(R)}if(h){let I=a[s(737)].payload;I&&v[s(1289)+"rs"](I)}}let Gp=async function(a,n){let s=t;this[s(803)]=!1,e[s(1682)](clearTimeout,this["_connect"+s(617)+s(1271)]),e[s(1711)](n)},jp=async function(a,n){let s=t,d={EHcJn:"error",earUc:function(h,y,v){return e[U(583)](h,y,v)},bbaEd:s(1876),yGUKO:e[s(686)],Saovh:e[s(1916)]};if(e[s(903)](e.BWUOP,s(1079))){if(!this[s(640)]||e[s(1313)](this._ws[s(1008)+"te"],this[s(935)]))return e[s(420)](n);let{pingInterval:h}=this[s(1281)];this[s(1316)+s(1323)]?.[s(1541)+s(857)+s(793)]();for(let v=0;e[s(453)](v,this[s(1608)+s(1337)][s(564)]);v++){let I=this[s(1608)+"Queue"][v];if(this[s(640)][s(1008)+"te"]===this[s(935)]&&e.etSyO(null,I))if(e.TKgke(e.zDaxA,e.JrPqa)){let g=_0x5acd12(WFMheS[s(824)],{message:this[s(1685)+s(785)+"age"](_0x535468)});this[s(1292)](WFMheS[s(824)],g);let R=WFMheS.earUc(_0xa6c2d0,WFMheS.bbaEd,{reason:this["_formatE"+s(785)+s(1111)](_0x218f79)});this[s(1292)]("close",R)}else this[s(640)]&&this[s(640)][s(1193)](I),this[s(1608)+s(1337)][v]=null;else break}this[s(1608)+s(1337)]=this[s(1608)+"Queue"][s(448)](v=>!!v),this[s(623)+s(1125)+"Id"]=e.bLxRJ(setTimeout,()=>this[s(763)](),h),this[s(1850)+"hOpenEvent"](a),this._isBrowser&&this._ws&&(this._ws.binaryType=this[s(1458)+s(1547)]);let y=this[s(1316)+s(1323)]?.["getCurre"+s(1183)+"nt"]();this[s(729)](s(1526)+y+" success"),e[s(420)](n)}else this[s(423)+"er"]&&_0x4b6ffc[s(1779)+s(964)+s(1298)](s(470),this[s(1348)+s(1873)]),this._isBrowser&&_0x55b553[s(1779)+"entListe"+s(1298)](d.yGUKO,this[s(1348)+s(1097)]),this[s(423)+"er"]&&_0x436b2b[s(1779)+s(964)+s(1298)](s(1394),this[s(761)+"ageHide"]),this[s(423)+"er"]&&_0x4a198d[s(1779)+s(964)+s(1298)](d[s(1690)],this["_handleP"+s(1343)])},Wp=async function(a,n){let s=t,d=this[s(1316)+s(1323)]?.[s(509)+s(1183)+"nt"]();this[s(729)](s(1526)+d),e[s(1244)](n)};class Kp extends oa{constructor(n){let s=t,d={QQKeg:function(h,y){return e.vzQtz(h,y)},iVbrd:function(h,y){return e.bXAjv(h,y)},bKoOp:e[s(1047)],pEKSS:s(1038),jBefO:s(1351)+s(1224)+"s",VOwCp:"success",kkVBM:function(h,y){return h===y},nuqBH:function(h,y,v){return h(y,v)},FsGzo:e[s(613)],depti:function(h,y){return h===y},dYzoq:function(h,y,v){return h(y,v)}};if(e[s(1592)](s(772),"oZOML")){super(),this[s(1381)+s(1890)+s(1806)]=!0,this[s(423)+"er"]=Zn,this[s(449)]=cp,this[s(1347)+"T"]=In,this[s(1900)+"X"]=Wr,this[s(1069)+"r"]=Kr,this._messageQueue=[],this["_endpoin"+s(1323)]=null,this["_readyCl"+s(1815)]=!1,this[s(1458)+s(1547)]=e[s(1761)],this[s(1532)+s(827)]=!1,this["_connectionTimeo"+s(1271)]=null,this[s(1773)+s(1445)+"tId"]=null,this["_pingPon"+s(1125)+"Id"]=null,this[s(900)]=0,this[s(803)]=!1,this._url="",this[s(1076)+s(1290)]=null,this[s(1736)+s(1093)]=null,this[s(749)+"sCounter"]=null,this._protocols=s(1875),this[s(1243)]=3,this[s(1663)+"NG"]=0,this.OPEN=1,this[s(1567)]=2,this[s(544)]=I=>{let g=s;try{Ql(this,I,[Gp,jp,Wp])}catch(R){let M=e.vSjmq(it,g(1437),{message:R[g(737)],code:en[g(1288)+"OR"],error:R});this[g(1850)+g(678)+g(892)](M)}},this._onMessage=async I=>{let g=s,{pingInterval:R,pingFrequency:M}=this[g(1281)];if((d[g(1053)]("hi",I[g(447)])&&d[g(531)](d.bKoOp,M)||d[g(435)]===M)&&(this[g(1431)+g(952)](),this[g(1292)](d[g(1600)],d[g(732)]),this[g(623)+g(1125)+"Id"]=setTimeout(this[g(763)][g(1756)](this),R)),!d[g(822)]("hi",I[g(447)]))try{Ql(this,I,[vp,Ep,Hp,qp,Up,bp])}catch(F){let J=d[g(463)](it,d[g(1034)],{message:F[g(737)],code:en[g(1576)+g(471)],error:F});this["_dispatc"+g(678)+g(892)](J)}},this[s(786)]=I=>{let g=s,R=this[g(1316)+g(1323)]?.[g(997)+g(949)+"es"](),M=this[g(1316)+g(1323)]?.["getCurre"+g(1183)+"nt"]();if(R&&!I[g(737)]){let F=g(1513)+M+(g(1673)+"ax retri"+g(1856)+"ed");this[g(1850)+g(678)+"ent"](d[g(463)](it,d.FsGzo,{message:F,code:en[g(521)+g(1788)+"R"],error:I}));return}this[g(640)]&&d[g(953)](this[g(640)][g(1008)+"te"],this[g(935)])&&this[g(875)+g(1147)](),this["_dispatchErrorEv"+g(892)](d[g(705)](it,d[g(1034)],{message:I[g(737)],code:en[g(991)+g(781)],error:I}))},this[s(756)]=async I=>{let g=s;this[g(990)+g(1333)](),this[g(1431)+g(952)](),this._removeWsListeners(),this[g(640)]=null,this[g(1532)+"Lock"]=!1;let R=this[g(1316)+g(1323)]?.[g(997)+"chMaxTries"]();if(!R&&this["_navigat"+g(1441)]()&&!this[g(1669)+g(1815)]){let M=this["_endpoin"+g(1323)]?.[g(509)+g(1183)+"nt"](),F=this[g(1281)][g(860)+g(502)+g(467)](I[g(1789)],I[g(1824)]);this[g(1850)+g(1122)+g(892)](e[g(1535)](ut,e.hfegD,{code:1006,reason:I[g(1824)]||g(882)+g(1664)+g(1057)+g(1899)+g(888)+g(1089)+M,willReconnect:F})),F&&this[g(1532)]();return}if(e[g(728)](1e3,I[g(1789)])&&this["_readyCl"+g(1815)]){this[g(1850)+g(1122)+g(892)](ut(e[g(1725)],{code:1e3,reason:e.AQMdL})),this[g(1316)+"tManager"]?.[g(1541)+"pointCon"+g(793)](),this["_pingLos"+g(1849)]?.[g(829)+g(1309)]();return}if(e[g(1677)](1e3,I[g(1789)])&&R){let M=this[g(1316)+g(1323)]?.[g(509)+g(1183)+"nt"](),F=I[g(1824)];F||(F=await e[g(895)](pp,this[g(1448)])),F=g(882)+g(1664)+g(424)+F+(g(796)+"me: ")+M+(g(1784)+g(740)+g(1602)),this["_dispatc"+g(1122)+g(892)](e.FUoMe(ut,g(1876),{code:I[g(1789)],reason:F}));let J=g(1513)+M+(g(1673)+g(1314)+"es reached");this[g(1850)+g(678)+g(892)](e[g(1823)](it,e[g(613)],{message:J,code:en[g(521)+g(1788)+"R"]})),this[g(1316)+"tManager"]?.[g(1541)+g(857)+g(793)](),this[g(749)+g(1849)]?.["resetCou"+g(1309)]();return}if(e.AHtYe(1e3,I[g(1789)])&&!I[g(1824)]){let M=this[g(1316)+g(1323)]?.[g(509)+g(1183)+"nt"]();this[g(1850)+"hCloseEv"+g(892)](ut(g(1876),{code:I[g(1789)],reason:g(882)+g(1664)+g(1057)+"wn reason, hostname: "+M})),this[g(1316)+g(1323)]?.[g(1541)+g(857)+g(793)](),this[g(749)+g(1849)]?.[g(829)+g(1309)]();return}this[g(1850)+"hCloseEv"+g(892)](I),this[g(1316)+g(1323)]?.[g(1541)+g(857)+g(793)](),this[g(749)+"sCounter"]?.[g(829)+g(1309)]()},this.onclose=null,this[s(1184)]=null,this[s(655)+"e"]=null,this[s(886)]=null,this.onStartReconnect=null,this[s(1044)+"eAck"]=null,this[s(1353)+"mediatel"+s(1436)+"ct"]=null,this[s(1348)+"nLine"]=this[s(1348)+s(1873)][s(1756)](this),this._handleOffLine=this[s(1348)+"ffLine"][s(1756)](this),this[s(761)+s(1399)]=this[s(761)+s(1399)][s(1756)](this),this[s(761)+s(1343)]=this[s(761)+s(1343)][s(1756)](this),this[s(1281)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(934)](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(811)],pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(925)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:h,ws:y}=n,v=Array[s(958)](h)?h:e[s(1344)](e[s(828)],typeof h)?[h]:[];if(!v||e[s(1549)](0,v[s(564)]))throw new Error(e[s(1251)]);if(!e[s(1520)](up,y))throw new Error(e[s(495)]);Object[s(938)](this[s(1281)],n),this[s(1316)+s(1323)]=new Xl(v,this[s(1281)][s(551)+"es"]),this["_pingLos"+s(1849)]=new xp(this._options[s(865)+s(718)]),this._options[s(987)+s(977)]&&(this[s(803)]=!0,this[s(1532)]()),this._options[s(1884)+s(970)+s(1858)]&&(this[s(1347)+"T"]||this[s(1900)+"X"]?this[s(428)+s(1463)+s(1560)]():this._isBrowser&&this["_initGlo"+s(1424)+"Listener"]())}else e[s(1126)](_0x22c837,65536)?_0x338a1a[_0x518fee++]=e[s(443)](e.DNPHW(e[s(1609)](_0xc5f3cc,12),15),224):(_0x5293f4[_0x4a2eba++]=e[s(1787)](e[s(1609)](_0x1b7dd5,18),7)|240,_0x531be9[_0x205abd++]=e[s(1629)](e[s(1643)](_0x6de0c2>>12,63),128)),_0x1f18e5[_0x1666cc++]=e.dvWqy(e[s(690)](e.fKYln(_0xc2a4d4,6),63),128)}[t(1348)+t(1873)](){let n=t;this[n(1281)][n(771)+n(1543)+n(598)]||this[n(1669)+n(1815)]||this._handleReconnect()}[t(1348)+"ffLine"](){let n=t;this[n(1059)+n(946)+"t"]();let s=e.FvIPI(sa,e.REMpp,{message:e[n(1472)]});this[n(1353)+"mediatel"+n(1436)+"ct"]&&this["onStopImmediatel"+n(1436)+"ct"](s)}[t(1660)+t(1424)+t(649)](){let n=t;this[n(423)+"er"]&&window[n(1501)+"Listener"](e[n(1390)],this[n(1348)+n(1873)]),this._isBrowser&&window["addEvent"+n(649)](n(1797),this[n(1348)+n(1097)]),this[n(423)+"er"]&&window[n(1501)+n(649)](e.EnvQP,this[n(761)+n(1399)]),this._isBrowser&&window[n(1501)+n(649)](e[n(1916)],this[n(761)+n(1343)])}_dropGlobalEventListener(){let n=t;this[n(423)+"er"]&&window[n(1779)+n(964)+"ner"](n(470),this[n(1348)+n(1873)]),this[n(423)+"er"]&&window[n(1779)+"entListener"]("offline",this[n(1348)+n(1097)]),this[n(423)+"er"]&&window[n(1779)+"entListe"+n(1298)](e[n(1020)],this[n(761)+n(1399)]),this[n(423)+"er"]&&window[n(1779)+n(964)+"ner"](e[n(1916)],this["_handleP"+n(1343)])}[t(761)+"ageHide"](n){let s=t;if(e[s(1365)](e.LSYHc,e.nnXQX))this.emit(e.LHlLE,e[s(1870)](_0x525630,e.LHlLE,{message:this[s(1685)+s(785)+s(1111)](_0x5c0ee6)}));else{if(!n[s(845)+"d"])if(e[s(1276)](e[s(1130)],"EUJZE"))try{e[s(559)](_0x115027,this,_0x437616,[_0xfba7e5,_0x32bd9f,_0x1ae02b])}catch(d){let h=_0x555000(e[s(613)],{message:d[s(737)],code:_0x50abec[s(1288)+"OR"],error:d});this[s(1850)+s(678)+s(892)](h)}else this[s(423)+"er"]&&window[s(1779)+s(964)+s(1298)](e[s(1020)],this[s(761)+"ageHide"]),this._isBrowser&&window["removeEventListe"+s(1298)](s(854),this[s(761)+s(1343)]),this[s(1876)]();this[s(423)+"er"]&&window.removeEventListener("online",this[s(1348)+"nLine"]),this[s(423)+"er"]&&window[s(1779)+s(964)+s(1298)](e[s(686)],this[s(1348)+s(1097)])}}[t(761)+t(1343)](n){let s=t;e[s(999)](e[s(887)],s(1099))?_0x795e7e[s(1908)](_0x4d4169):n[s(845)+"d"]&&(this["_navigat"+s(1441)]()&&(!this[s(640)]||e[s(1897)](this._ws[s(1008)+"te"],this[s(935)])||e.BMGyh(this[s(640)][s(1008)+"te"],this.CONNECTING))&&this[s(1348)+"nLine"](),this[s(423)+"er"]&&window[s(1501)+s(649)](e[s(1390)],this["_handleO"+s(1873)]),this[s(423)+"er"]&&window.addEventListener(s(1797),this["_handleO"+s(1097)]))}async[t(807)+t(1566)](n){let s=t,{fpID:d,deviceID:h,bddID:y,ttwID:v,accessKey:I,aID:g,customParams:R={},enableAutoAck:M,enableQoS:F,QoSLevel:J,env:V}=this[s(1281)],Ie,ft,zt;if(this[s(423)+"er"]||this[s(1900)+"X"]||this[s(1347)+"T"])Ie=location&&e[s(1417)](e[s(1484)],location[s(486)])?s(1078):e[s(579)],ft=n[s(1766)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),zt=/^wss(.*:\/\/)/.test(n)?n:""+Ie+ft;else if(e[s(849)](e.xrnNS,s(1083)))Ie=e[s(1801)],ft=n[s(1766)](/(^http)((?:[s]*:\/\/))/,""),zt=/(^ws)((?:[s]*:\/\/))/[s(1521)](ft)?ft:""+Ie+ft;else return!!this[s(1765)];let ht=y?e[s(910)]:v?e[s(1165)]:e.YEzKQ,$r=y||v||h;if(e[s(1265)](!$r,!ht))throw new Error(e.QFDVv);let ha=e[s(570)]==typeof R?await e[s(1105)](R):R,xa=V?e[s(775)](hp,V[s(1593)],V[s(1705)]):{},pa=Object[s(938)]({device_platform:s(688),version_code:e.EZmBq,access_key:I,fpid:d,aid:g,[ht]:$r,xsack:M?1:0,xaack:M?1:0,xsqos:F?1:0,qos_level:F?J:void 0,qos_sdk_version:2,...xa},ha),$p=Object[s(1854)](pa)[s(1182)]((ga,ma)=>pa[ma]!==void 0?""+ga+(ga?"&":"?")+ma+"="+pa[ma]:ga,"");return zt+"/ws/v2"+$p}async[t(1532)](){let n=t;if(!(this[n(1532)+"Lock"]||this[n(1669)+n(1815)])){this["_connect"+n(827)]=!0;try{let s=this[n(1316)+n(1323)]?.[n(1499)+n(918)+n(620)+n(1528)+n(1086)](),{timeoutInterval:d}=this[n(1281)];if(s){let y=this[n(1316)+n(1323)]?.[n(509)+"ntEndpoint"](),v=this[n(1316)+n(1323)]?.["replaceBackupEndpointAnd"+n(695)+n(475)](),I=this[n(1316)+"tManager"]?.[n(509)+"ntEndpointTriesC"+n(1611)]();if(v){let g="connect "+y+(n(1220)+n(1784)+n(740)+n(550)+"ill use "+n(979)+n(1158))+v+(n(735)+"y"),R=e.DnDPw(it,e[n(613)],{message:g,code:en[n(521)+"IES_ERROR"]});this[n(729)](g),this[n(1850)+n(678)+n(892)](R),this._url=await this[n(807)+n(1566)](v),this[n(729)]("connect "+v+" "+I+" times"),this[n(1802)+n(1517)+"rs"]()}else{let g=n(1513)+y+(n(1220)+n(1784)+n(740)+n(1602));this[n(729)](g),this[n(1850)+n(678)+n(892)](e[n(1584)](it,n(1437),{message:g,code:en[n(521)+n(1788)+"R"]}));return}}else{let y=this[n(1316)+n(1323)]?.[n(509)+n(1183)+n(592)+"ateCount"](),v=this._endpointManager?.[n(509)+n(1183)+n(450)+n(1611)]();this[n(1448)]=await this[n(807)+n(1566)](e.mUcLW(y,"")),this[n(729)]("connect "+y+" "+v+n(1211)),this[n(1802)+n(1517)+"rs"]()}if(this[n(803)])this._isInit=!1;else if(e.Ebjeg!==e.XPgrp){let y=e[n(1156)](sa,e[n(1434)],{message:e[n(780)]});this["onStartR"+n(1571)]&&this["onStartR"+n(1571)](y)}else{if(this[n(1431)+"ngTimer"](),this[n(990)+n(1333)](),this[n(1802)+n(1517)+"rs"](),this[n(801)+"nceClose"](1e3,_0x15b27a),this[n(1532)+n(827)]=!1,_0x4a64a7&&this[n(814)+n(1441)]()&&!this["_readyCl"+n(1815)]){if(this[n(1316)+n(1323)]?.[n(997)+n(949)+"es"]()){let v=this[n(1316)+n(1323)]?.["getCurre"+n(1183)+"nt"]();this[n(1850)+n(1122)+n(892)](e[n(1905)](_0x2c7e02,e.hfegD,{code:1006,reason:n(1513)+v+(n(1220)+", max re"+n(740)+n(1602)),wasClean:!0}))}else{let v=this[n(1281)]["reconnectInterce"+n(467)](_0xb9c9b8,_0x147e93);this[n(1850)+"hCloseEv"+n(892)](e[n(933)](_0x525b4d,e[n(1725)],{code:_0x3ef452,reason:_0x30c4e3,wasClean:!0,willReconnect:v})),v&&this._connect()}return}this[n(814)+n(1441)]()||this[n(1669)+n(1815)]?this[n(1850)+"hCloseEvent"](e[n(1483)](_0x348f97,e[n(1725)],{code:_0x2988b4,reason:"bye"})):this[n(1850)+n(1122)+n(892)](e.fQbMR(_0x551ec0,e[n(1725)],{code:1006,reason:"going aw"+n(1558)+n(525)+n(1516)})),this[n(640)]=null,this[n(1316)+n(1323)]?.[n(1541)+"pointConfig"](),this[n(749)+"sCounter"]?.[n(829)+n(1309)]()}let h=this[n(1316)+n(1323)]?.[n(509)+n(1183)+n(450)+n(1611)]()||0;e[n(1778)](h,1)&&await this[n(1550)](e[n(529)](h,1)),this[n(729)](n(882)+n(1180)+this[n(1448)]+" protocols: "+this._protocols),this[n(640)]=dp({url:this._url,protocols:[this[n(1340)+"ls"]],headers:this[n(1281)][n(1094)+"ramParams"][n(549)+n(1588)]},this[n(1281)].ws),(this[n(423)+"er"]||this[n(1069)+"r"])&&this._ws&&(this[n(640)][n(1529)+"pe"]=this._binaryType),this[n(1247)+n(995)](),this[n(1532)+"ionTimeo"+n(1271)]=setTimeout(this[n(1615)+"ut"].bind(this),d)}catch(s){throw this[n(1532)+"Lock"]=!1,s}}}[t(990)+t(1333)](){let n=t;e[n(895)](clearTimeout,this["_connect"+n(617)+n(1271)]),this["_connectionTimeo"+n(1271)]=null}[t(1431)+t(952)](){let n=t;e[n(1804)](clearTimeout,this[n(623)+n(1125)+"Id"]),e[n(1913)](clearTimeout,this["_reconnectTimeou"+n(1749)]),this["_pingPon"+n(1125)+"Id"]=null,this[n(1773)+n(1445)+"tId"]=null}_debug(...n){let s=t;this[s(1281)][s(1757)]&&console[s(1908)].apply(console,[e[s(537)],...n])}[t(792)+t(1287)+"e"](n){let s=t,{initReconnectInterval:d,maxReconnectInterval:h,reconnectIntervalGrowFactor:y}=this[s(1281)],v=d*Math.pow(y,e[s(1335)](n,1));return e[s(1699)](v,h)?h:v}[t(763)](){let n=t;if(this[n(640)]&&e[n(1362)](this[n(640)][n(1008)+"te"],this.CONNECTING)){this["_clearPi"+n(952)](),this[n(623)+n(1125)+"Id"]=setTimeout(this[n(763)][n(1756)](this),this[n(1281)]["pingInte"+n(752)]);return}if(!this[n(640)]||e[n(422)](this[n(640)][n(1008)+"te"],this.OPEN))return void this[n(1498)+n(1571)]();this[n(640)]&&this[n(640)][n(1193)]("hi"),this[n(1773)+n(1445)+n(1749)]=e[n(1483)](setTimeout,this[n(1498)+"econnectTimeout"][n(1756)](this),this[n(1281)][n(1248)+n(994)+"val"])}[t(1498)+"econnect"+t(1896)](){let n=t;this[n(749)+n(1849)]?.[n(1512)](),this.emit(n(1351)+n(1345)+"t",e[n(1153)]),this[n(749)+n(1849)]?.[n(997)+"chMaxCount"]()?this[n(1498)+n(1571)]():this._ping()}_navigatorOnline(){let n=t;return e[n(983)](e[n(1831)],e.VDtsV)?new _0x344905(_0x22bbbe,_0x261ab7,_0x5d09d1):this[n(1347)+"T"]||this[n(1900)+"X"]?this[n(1381)+n(1890)+n(1806)]:(this[n(423)+"er"]||this[n(1069)+"r"])&&this[n(1281)][n(1884)+n(970)+n(1858)]?navigator[n(1433)]:!0}[t(1498)+t(1571)](){let n=t;!this[n(814)+n(1441)]()||this[n(1669)+"osed"]||(this[n(1316)+"tManager"]?.[n(1541)+n(857)+n(793)](),this["_pingLos"+n(1849)]?.[n(829)+n(1309)](),this._ws?this[n(875)+n(1147)](1001,e[n(504)],!0):this._connect())}[t(428)+t(1463)+t(1560)](){let n=t;this[n(1347)+"T"]?tt[n(1048)+"kStatusC"+n(950)](({isConnected:s})=>{let d=n;this[d(1381)+d(1890)+d(1806)]=s,s?this["_handleO"+d(1873)]():this[d(1348)+d(1097)]()}):this[n(1900)+"X"]&&wx["onNetwor"+n(430)+n(950)](({isConnected:s})=>{let d=n;this[d(1381)+d(1890)+d(1806)]=s,s?this["_handleO"+d(1873)]():this[d(1348)+d(1097)]()})}_wait(n){let s=t,d={OicvY:e[s(613)],axRaL:function(h,y,v){return h(y,v)}};if(e[s(782)](e[s(915)],e[s(915)]))return new Promise(h=>{e[s(632)](setTimeout,h,this._getIntervalValue(n))});{let h=_0xf1b080[s(418)][s(1321)](_0x4fa077[s(1444)+"et"],_0x382b1b.byteLength+_0x31e556.byteOffset);this[s(1451)]&&this[s(1451)][s(1193)]({data:h,fail:y=>{let v=s;this[v(1292)](MFVhxQ[v(1350)],MFVhxQ[v(1355)](_0x49356e,MFVhxQ.OicvY,{message:this[v(1685)+v(785)+v(1111)](y)}))}})}}_disconnect(n=1e3,s="",d=!1){let h=t;this[h(640)]&&this[h(1059)+h(946)+"t"](n,s,d)}[t(1615)+"ut"](){let n=t,s=this["_endpoin"+n(1323)]?.[n(509)+"ntEndpoint"]();this[n(729)]("connect "+s+n(1220)),this[n(875)+n(1147)](1001,n(1246)+n(874)+n(1391)+"g",!0)}[t(720)](n){let s=t,d=Ft(n);if(this[s(640)]&&e[s(1197)](this[s(640)][s(1008)+"te"],this[s(935)]))if(e[s(759)](e[s(765)],e.qHclt))this[s(640)]&&this[s(640)].send(d),this[s(729)](e[s(872)],n);else{let h=e[s(1654)].split("|"),y=0;for(;;){switch(h[y++]){case"0":this[s(749)+s(1849)]?.[s(829)+s(1309)]();continue;case"1":this[s(1669)+"osed"]=!1;continue;case"2":this[s(803)]=!0;continue;case"3":this[s(1316)+s(1323)]?.["resetEnd"+s(857)+s(793)]();continue;case"4":this[s(1532)]();continue}break}}}["_removeW"+t(1517)+"rs"](){let n=t;this[n(640)]&&(this[n(640)][n(1779)+n(964)+"ner"](e[n(1585)],this[n(544)]),this[n(640)][n(1779)+n(964)+n(1298)](e.hfegD,this._onClose),this._ws[n(1779)+n(964)+n(1298)](e[n(434)],this[n(638)+"ge"]),this._ws[n(1779)+n(964)+"ner"](n(1437),this[n(786)]))}["_addWsLi"+t(995)](){let n=t,s=e[n(535)][n(841)]("|"),d=0;for(;;){switch(s[d++]){case"0":this._ws[n(1501)+"Listener"](e[n(1725)],this[n(756)]);continue;case"1":this[n(640)].addEventListener(e[n(613)],this._onError);continue;case"2":this[n(640)]["addEvent"+n(649)](e.qFHYJ,this[n(544)]);continue;case"3":if(!this[n(640)])return;continue;case"4":this[n(640)][n(1501)+n(649)](n(737),this[n(638)+"ge"]);continue}break}}[t(801)+"nceClose"](n=1e3,s=""){let d=t;try{if(e[d(730)]("JcWnV",e[d(676)]))this[d(640)]&&this[d(640)][d(1876)](n,s);else return _0x3ea671(_0x53538c)}catch{}}_destroyWebSocket(n=1e3,s="",d=!1){let h=t;if(this[h(1431)+h(952)](),this[h(990)+h(1333)](),this[h(1802)+h(1517)+"rs"](),this[h(801)+h(1043)](1e3,s),this[h(1532)+"Lock"]=!1,d&&this[h(814)+h(1441)]()&&!this[h(1669)+h(1815)]){if(this[h(1316)+h(1323)]?.[h(997)+h(949)+"es"]()){let v=this[h(1316)+h(1323)]?.["getCurre"+h(1183)+"nt"]();this["_dispatchCloseEv"+h(892)](e.rXflp(ut,e[h(1725)],{code:1006,reason:h(1513)+v+(" timeout"+h(1784)+h(740)+h(1602)),wasClean:!0}))}else{let v=this[h(1281)][h(860)+h(502)+"ptor"](n,s);this[h(1850)+"hCloseEv"+h(892)](e.smxYa(ut,e[h(1725)],{code:n,reason:s,wasClean:!0,willReconnect:v})),v&&this[h(1532)]()}return}this[h(814)+h(1441)]()||this[h(1669)+"osed"]?this[h(1850)+h(1122)+h(892)](e[h(779)](ut,"close",{code:n,reason:e[h(1760)]})):this[h(1850)+h(1122)+"ent"](ut(e[h(1725)],{code:1006,reason:e[h(1605)]})),this[h(640)]=null,this[h(1316)+"tManager"]?.[h(1541)+h(857)+h(793)](),this[h(749)+h(1849)]?.resetCounter()}[t(1850)+t(1146)+"nt"](n){let s=t,d={bSyUN:function(h,y){return e[U(1545)](h,y)},rQLLi:function(h,y){return e[U(1625)](h,y)},sbEEx:s(1275),wKTIC:e[s(510)],TrJbQ:function(h,y){return h in y}};if(e[s(774)](e[s(1620)],e[s(1843)]))this[s(1292)](s(568),n),this[s(886)]&&this[s(886)](n);else return zQHnrM[s(1687)](_0x2e565c,_0x5972ba)&&(zQHnrM[s(548)](_0x376fd1,zQHnrM[s(506)])||_0xcba253===zQHnrM[s(1848)])?!0:zQHnrM.TrJbQ(_0x58fb6c,_0x1f4072)}[t(1850)+t(1903)+"Event"](n){let s=t;this[s(1292)](e[s(434)],n),this.onmessage&&this.onmessage(n)}[t(1850)+"hAckMess"+t(1834)](n){let s=t;this[s(1292)](e.Mypju,n),this[s(1044)+s(1832)]&&this[s(1044)+s(1832)](n)}[t(1850)+t(678)+t(892)](n){let s=t;this[s(1292)](e.LHlLE,n),this[s(1184)]&&this.onerror(n)}[t(1850)+"hCloseEv"+t(892)](n){let s=t;this.emit(e[s(1725)],n),this.onclose&&this[s(1738)](n)}get binaryType(){let n=t;return this[n(640)]?this[n(640)][n(1529)+"pe"]:this[n(1458)+n(1547)]}set[t(1529)+"pe"](n){let s=t;this[s(1458)+s(1547)]=n,this[s(640)]&&(this._ws[s(1529)+"pe"]=n)}get[t(658)+"nt"](){let n=t;return this[n(1316)+n(1323)]?.["getCurre"+n(1183)+n(450)+"ount"]()||0}get[t(1229)+t(1209)](){let n=t,s=this[n(1608)+n(1337)][n(1182)]((d,h)=>(d+=h&&h[n(1045)+"th"]||0,d),0);return e[n(928)](s,this[n(640)]?this[n(640)][n(1229)+"Amount"]:0)}get[t(1379)+"ns"](){let n=t;return this[n(640)]?this._ws[n(1379)+"ns"]:""}get protocol(){let n=t;return this[n(640)]?this[n(640)][n(486)]:""}get[t(1008)+"te"](){let n=t;return this[n(640)]?this[n(640)][n(1008)+"te"]:this[n(1281)][n(987)+n(977)]?this[n(1663)+"NG"]:this[n(1243)]}get url(){let n=t,s={ciUfG:function(d,h){return e[U(904)](d,h)},smqAN:function(d,h){return e.opQKk(d,h)},XValc:function(d,h){return d&h},vIRkK:function(d,h){return d+h}};if(e[n(1240)]===n(1103))return this[n(640)]?this[n(640)][n(1450)]:this._url;{let d=0,h=0;for(let y=0;BEWyut.ciUfG(y,_0x14e43d[n(564)]);++y)h=_0x3a56a3[n(711)+"At"](y),h<128?d+=1:BEWyut[n(1002)](h,2048)?d+=2:BEWyut.smqAN(BEWyut[n(1636)](64512,h),55296)&&BEWyut.XValc(64512,_0x24b543[n(711)+"At"](BEWyut[n(880)](y,1)))===56320?(++y,d+=4):d+=3;return d}}[t(1876)](n=1e3,s){let d=t,h=e[d(1587)][d(841)]("|"),y=0;for(;;){switch(h[y++]){case"0":this[d(1669)+d(1815)]=!0;continue;case"1":this[d(1076)+"ger"]?.closeDB();continue;case"2":this[d(1431)+d(952)]();continue;case"3":if(e[d(500)](this[d(640)][d(1008)+"te"],this.CLOSED)||this[d(640)][d(1008)+"te"]===this[d(1567)])return void this._debug(e[d(1718)]);continue;case"4":this[d(1674)+d(1424)+d(649)]();continue;case"5":if(!this._ws)return void this[d(729)](e[d(1061)]);continue;case"6":this["_destroy"+d(946)+"t"](n,s);continue;case"7":this[d(990)+d(1333)]();continue}break}}async[t(1193)](n,s){let d=t;if(n==null)throw new Error(d(835)+d(1013)+d(757)+d(1562)+d(1279)+d(454)+d(1133)+" arraybu"+d(1743));e[d(1417)](e.LSBSL,typeof n)&&(n=JSON[d(518)+"y"](n)),e[d(828)]!=typeof n&&!e[d(692)](n,ArrayBuffer)&&!(n[d(418)]&&e[d(692)](n[d(418)],ArrayBuffer))&&(n=JSON[d(518)+"y"](n));let h=await e[d(1486)](nd,n),y=e[d(956)](fp,n),{method:v=0,service:I=this[d(1281)].service,logID:g=this[d(1281)].logIDGenerator(),headers:R=this[d(1281)][d(1160)],payloadEncoding:M=this[d(1281)][d(1112)+d(1892)],payloadType:F=this[d(1281)][d(1114)+d(1547)],logIDNew:J=this[d(1281)][d(431)+"Config"]["enableAu"+d(538)+d(499)+"ew"]?i(this[d(1281)]["logIDNew"+d(1507)].userIp):""}=s||{};if(!I)throw new Error(e[d(1421)]);let V={SeqID:ae[d(599)+"er"](this[d(900)]++),LogID:ae[d(599)+"er"](g),service:I,method:v,headers:R,payloadEncoding:e[d(692)](M,Object)?M[d(456)]?M.encoding:"":M,payloadType:e.sQUVw(F,Object)?F[d(878)]?F[d(878)]:y:F||y,payload:h,LogIDNew:J},Ie=e[d(1486)](Ft,V);return this[d(640)]&&e[d(768)](this[d(640)].readyState,this[d(935)])?(this[d(640)]&&this[d(640)].send(Ie),this[d(729)](e[d(1027)],V)):this[d(1608)+d(1337)].length<this._options[d(1693)+d(1280)+d(1658)]?e[d(1505)](e[d(668)],e[d(668)])?(cCZFtz[d(1383)](_0x36f5d5,_0x250cd7[d(1437)]),_0x54f8ca()):(this["_message"+d(1337)][d(596)](Ie),this[d(729)](e[d(1530)],V)):(this["_message"+d(1337)][d(696)](),this[d(1608)+d(1337)].push(Ie)),{seqID:this._seqId,logID:g,logIDNew:J}}async[t(860)+"t"](n){let s=t,{url:d}=e.SoHcX(n,{}),h=Array.isArray(d)?d:e[s(1475)](e[s(828)],typeof d)?[d]:[];n&&Object.assign(this[s(1281)],n),h&&h[s(564)]?this[s(1316)+s(1323)]=new Xl(h,this[s(1281)].maxRetries):this[s(1316)+"tManager"]?.["resetEndpointCon"+s(793)](),this._pingLossCounter?.["resetCou"+s(1309)](this[s(1281)][s(865)+s(718)]),this._readyClosed=!1,this._ws&&this[s(640)][s(1008)+"te"]!==this[s(1243)]?this[s(875)+s(1147)](1e3,e[s(1818)],!0):(this[s(803)]=!0,this._connect())}async[t(1320)](){let n=t;if(e[n(945)](e[n(484)],e[n(484)])){if(!this["_connect"+n(827)]){let s=e[n(1691)][n(841)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1532)]();continue;case"1":this[n(803)]=!0;continue;case"2":this[n(749)+n(1849)]?.[n(829)+"nter"]();continue;case"3":this["_readyCl"+n(1815)]=!1;continue;case"4":this[n(1316)+n(1323)]?.[n(1541)+n(857)+n(793)]();continue}break}}}else return new _0x546cac(_0x2a1181,{message:_0x10908a})}[t(1501)+"Listener"](n,s){this.on(n,s)}["dispatch"+t(868)](n){let{type:s}=n;this.emit(s,n)}[t(1779)+"entListe"+t(1298)](n,s){let d=t;if(e[d(1428)](d(784),e[d(1260)]))this[d(437)](n,s);else{if(e.LmGva(e[d(618)](_0x34a176[d(615)],_0x572095),_0x539e4e[d(726)]))throw new _0x62acee(e.adsro);_0x345c6b[d(615)]+=_0x3fbbbc}}[t(1145)](){let n=t,s={BaZJL:function(d,h){return e[U(1011)](d,h)},qDCpq:e[n(1153)],MPupD:e[n(1054)]};return new Promise((d,h)=>{let y=n,v={VIaNP:y(1351)+y(1224)+"s",HNaJP:y(1351)+"e_timeout"};this["_clearPi"+y(952)](),this[y(623)+"gTimeoutId"]=setTimeout(this[y(763)][y(1756)](this),this[y(1281)][y(1864)+"rval"]);let I=()=>{let R=y;d("success"),this[R(437)](v.VIaNP,I),this.off(v.HNaJP,g)},g=()=>{let R=y;s[R(591)](h,s.qDCpq),this[R(437)](R(1351)+R(1224)+"s",I),this[R(437)](s[R(507)],g)};this.on(e.wpeby,I),this.on(e[y(1054)],g),this[y(763)]()})}}})(),xe[L(660)+L(1727)]=Ce.CustomCloseEvent,xe[L(743)+"rorEvent"]=Ce["CustomEr"+L(1556)],xe[L(1717)+"e"]=Ce[L(1717)+"e"],xe[L(868)]=Ce[L(868)],xe[L(490)]=Ce.FWS,xe[L(1487)+L(984)+"vent"]=Ce["Frontier"+L(984)+L(1241)],xe[L(984)+L(1241)]=Ce[L(984)+"vent"],xe[L(1470)+"t"]=Ce[L(1470)+"t"],xe[L(505)+L(1004)]=Ce[L(505)+"tEvent"],xe.createCloseEvent=Ce[L(519)+"oseEvent"],xe.createErrorEvent=Ce[L(1322)+"rorEvent"],xe[L(458)+"ssageEvent"]=Ce[L(458)+L(986)+"nt"],xe["createOp"+L(581)]=Ce[L(873)+L(581)],xe[L(1623)+L(1548)+L(1241)]=Ce[L(1623)+L(1548)+L(1241)],xe[L(1886)+L(722)]=Ce[L(1886)+"rame"],xe[L(1159)+"ame"]=Ce[L(1159)+L(1068)];for(Eo in Ce)[L(660)+L(1727),L(743)+L(1556),L(1717)+"e",L(868),"FWS",L(1487)+L(984)+L(1241),L(984)+L(1241),L(1470)+"t",L(505)+L(1004),L(519)+L(1727),L(1322)+"rorEvent",L(458)+L(986)+"nt",L(873)+L(581),L(1623)+L(1548)+L(1241),L(1886)+"rame",L(1159)+L(1068)].indexOf(Eo)===-1&&(xe[Eo]=Ce[Eo]);var Eo;Object[L(714)+L(562)](xe,L(1455)+"le",{value:!0})});var $t=ie((gR,lh)=>{"use strict";var ah=["nodebuffer","arraybuffer","fragments"],ch=typeof Blob<"u";ch&&ah.push("blob");lh.exports={BINARY_TYPES:ah,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:ch,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var qi=ie((mR,Co)=>{"use strict";var{EMPTY_BUFFER:QE}=$t(),sl=Buffer[Symbol.species];function eb(t,e){if(t.length===0)return QE;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 sl(r.buffer,r.byteOffset,i):r}function dh(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function uh(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function tb(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function ol(t){if(ol.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new sl(t):ArrayBuffer.isView(t)?e=new sl(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),ol.readOnly=!1),e}Co.exports={concat:eb,mask:dh,toArrayBuffer:tb,toBuffer:ol,unmask:uh};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=ce("bufferutil");Co.exports.mask=function(e,r,i,o,c){c<48?dh(e,r,i,o,c):t.mask(e,r,i,o,c)},Co.exports.unmask=function(e,r){e.length<32?uh(e,r):t.unmask(e,r)}}catch{}});var xh=ie((wR,hh)=>{"use strict";var fh=Symbol("kDone"),al=Symbol("kRun"),cl=class{constructor(e){this[fh]=()=>{this.pending--,this[al]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[al]()}[al](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[fh])}}};hh.exports=cl});var Or=ie((_R,wh)=>{"use strict";var Gi=ce("zlib"),ph=qi(),nb=xh(),{kStatusCode:gh}=$t(),rb=Buffer[Symbol.species],ib=Buffer.from([0,0,255,255]),Do=Symbol("permessage-deflate"),Vt=Symbol("total-length"),kr=Symbol("callback"),bn=Symbol("buffers"),Pr=Symbol("error"),Ro,ll=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,!Ro){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Ro=new nb(r)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[kr];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,i=e.find(o=>!(r.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>o.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!o.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(i.server_no_context_takeover=!0),r.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(i.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?i.client_max_window_bits=r.clientMaxWindowBits:(i.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(i=>{let o=r[i];if(o.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(o=o[0],i==="client_max_window_bits"){if(o!==!0){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else if(i==="server_max_window_bits"){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(o!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=o})}),e}decompress(e,r,i){Ro.add(o=>{this._decompress(e,r,(c,l)=>{o(),i(c,l)})})}compress(e,r,i){Ro.add(o=>{this._compress(e,r,(c,l)=>{o(),i(c,l)})})}_decompress(e,r,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?Gi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Gi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:l}),this._inflate[Do]=this,this._inflate[Vt]=0,this._inflate[bn]=[],this._inflate.on("error",ob),this._inflate.on("data",mh)}this._inflate[kr]=i,this._inflate.write(e),r&&this._inflate.write(ib),this._inflate.flush(()=>{let c=this._inflate[Pr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let l=ph.concat(this._inflate[bn],this._inflate[Vt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Vt]=0,this._inflate[bn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,l)})}_compress(e,r,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?Gi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Gi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:l}),this._deflate[Vt]=0,this._deflate[bn]=[],this._deflate.on("data",sb)}this._deflate[kr]=i,this._deflate.write(e),this._deflate.flush(Gi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=ph.concat(this._deflate[bn],this._deflate[Vt]);r&&(c=new rb(c.buffer,c.byteOffset,c.length-4)),this._deflate[kr]=null,this._deflate[Vt]=0,this._deflate[bn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};wh.exports=ll;function sb(t){this[bn].push(t),this[Vt]+=t.length}function mh(t){if(this[Vt]+=t.length,this[Do]._maxPayload<1||this[Vt]<=this[Do]._maxPayload){this[bn].push(t);return}this[Pr]=new RangeError("Max payload size exceeded"),this[Pr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Pr][gh]=1009,this.removeListener("data",mh),this.reset()}function ob(t){if(this[Do]._inflate=null,this[Pr]){this[kr](this[Pr]);return}t[gh]=1007,this[kr](t)}});var Lr=ie((yR,ko)=>{"use strict";var{isUtf8:_h}=ce("buffer"),{hasBlob:ab}=$t(),cb=[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 lb(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function dl(t){let e=t.length,r=0;for(;r<e;)if((t[r]&128)===0)r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return!1;r+=2}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return!1;r+=3}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return!1;r+=4}else return!1;return!0}function db(t){return ab&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}ko.exports={isBlob:db,isValidStatusCode:lb,isValidUTF8:dl,tokenChars:cb};if(_h)ko.exports.isValidUTF8=function(t){return t.length<24?dl(t):_h(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=ce("utf-8-validate");ko.exports.isValidUTF8=function(e){return e.length<32?dl(e):t(e)}}catch{}});var pl=ie((ER,Ah)=>{"use strict";var{Writable:ub}=ce("stream"),yh=Or(),{BINARY_TYPES:fb,EMPTY_BUFFER:Eh,kStatusCode:hb,kWebSocket:xb}=$t(),{concat:ul,toArrayBuffer:pb,unmask:gb}=qi(),{isValidStatusCode:mb,isValidUTF8:bh}=Lr(),Po=Buffer[Symbol.species],ct=0,vh=1,Sh=2,Ih=3,fl=4,hl=5,Oo=6,xl=class extends ub{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||fb[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[xb]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=ct}_write(e,r,i){if(this._opcode===8&&this._state==ct)return i();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new Po(i.buffer,i.byteOffset+e,i.length-e),new Po(i.buffer,i.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let i=this._buffers[0],o=r.length-e;e>=i.length?r.set(this._buffers.shift(),o):(r.set(new Uint8Array(i.buffer,i.byteOffset,e),o),this._buffers[0]=new Po(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case ct:this.getInfo(e);break;case vh:this.getPayloadLength16(e);break;case Sh:this.getPayloadLength64(e);break;case Ih:this.getMask();break;case fl:this.getData(e);break;case hl:case Oo:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if((r[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(r[0]&64)===64;if(i&&!this._extensions[yh.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=vh:this._payloadLength===127?this._state=Sh: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=Ih:this._state=fl}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=fl}getData(e){let r=Eh;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&&gb(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=hl,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[yh.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let l=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(l);return}this._fragments.push(c)}this.dataMessage(r),this._state===ct&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=ct;return}let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=ul(i,r):this._binaryType==="arraybuffer"?o=pb(ul(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=ct):(this._state=Oo,setImmediate(()=>{this.emit("message",o,!0),this._state=ct,this.startLoop(e)}))}else{let o=ul(i,r);if(!this._skipUTF8Validation&&!bh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===hl||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=ct):(this._state=Oo,setImmediate(()=>{this.emit("message",o,!1),this._state=ct,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,Eh),this.end();else{let i=e.readUInt16BE(0);if(!mb(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Po(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!bh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(c);return}this._loop=!1,this.emit("conclude",i,o),this.end()}this._state=ct;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=ct):(this._state=Oo,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=ct,this.startLoop(r)}))}createError(e,r,i,o,c){this._loop=!1,this._errored=!0;let l=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(l,this.createError),l.code=c,l[hb]=o,l}};Ah.exports=xl});var wl=ie((vR,Rh)=>{"use strict";var{Duplex:bR}=ce("stream"),{randomFillSync:wb}=ce("crypto"),Th=Or(),{EMPTY_BUFFER:_b,kWebSocket:yb,NOOP:Eb}=$t(),{isBlob:Nr,isValidStatusCode:bb}=Lr(),{mask:Ch,toBuffer:qn}=qi(),lt=Symbol("kByteLength"),vb=Buffer.alloc(4),Lo=8*1024,Gn,Mr=Lo,bt=0,Sb=1,Ib=2,gl=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=bt,this.onerror=Eb,this[yb]=void 0}static frame(e,r){let i,o=!1,c=2,l=!1;r.mask&&(i=r.maskBuffer||vb,r.generateMask?r.generateMask(i):(Mr===Lo&&(Gn===void 0&&(Gn=Buffer.alloc(Lo)),wb(Gn,0,Lo),Mr=0),i[0]=Gn[Mr++],i[1]=Gn[Mr++],i[2]=Gn[Mr++],i[3]=Gn[Mr++]),l=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||l)&&r[lt]!==void 0?u=r[lt]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!l);let f=u;u>=65536?(c+=8,f=127):u>125&&(c+=2,f=126);let x=Buffer.allocUnsafe(o?u+c:c);return x[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(x[0]|=64),x[1]=f,f===126?x.writeUInt16BE(u,2):f===127&&(x[2]=x[3]=0,x.writeUIntBE(u,4,6)),r.mask?(x[1]|=128,x[c-4]=i[0],x[c-3]=i[1],x[c-2]=i[2],x[c-1]=i[3],l?[x,e]:o?(Ch(e,i,x,c,u),[x]):(Ch(e,i,e,0,u),[x,e])):[x,e]}close(e,r,i,o){let c;if(e===void 0)c=_b;else{if(typeof e!="number"||!bb(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(r);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof r=="string"?c.write(r,2):c.set(r,2)}}let l={[lt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==bt?this.enqueue([this.dispatch,c,!1,l,o]):this.sendFrame(t.frame(c,l),o)}ping(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Nr(e)?(o=e.size,c=!1):(e=qn(e),o=e.length,c=qn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[lt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Nr(e)?this._state!==bt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==bt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}pong(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Nr(e)?(o=e.size,c=!1):(e=qn(e),o=e.length,c=qn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[lt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Nr(e)?this._state!==bt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==bt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}send(e,r,i){let o=this._extensions[Th.extensionName],c=r.binary?2:1,l=r.compress,u,f;typeof e=="string"?(u=Buffer.byteLength(e),f=!1):Nr(e)?(u=e.size,f=!1):(e=qn(e),u=e.length,f=qn.readOnly),this._firstFragment?(this._firstFragment=!1,l&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(l=u>=o._threshold),this._compress=l):(l=!1,c=0),r.fin&&(this._firstFragment=!0);let x={[lt]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:f,rsv1:l};Nr(e)?this._state!==bt?this.enqueue([this.getBlobData,e,this._compress,x,i]):this.getBlobData(e,this._compress,x,i):this._state!==bt?this.enqueue([this.dispatch,e,this._compress,x,i]):this.dispatch(e,this._compress,x,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[lt],this._state=Ib,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(ml,this,u,o);return}this._bufferedBytes-=i[lt];let l=qn(c);r?this.dispatch(l,r,i,o):(this._state=bt,this.sendFrame(t.frame(l,i),o),this.dequeue())}).catch(c=>{process.nextTick(Ab,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Th.extensionName];this._bufferedBytes+=i[lt],this._state=Sb,c.compress(e,i.fin,(l,u)=>{if(this._socket.destroyed){let f=new Error("The socket was closed while data was being compressed");ml(this,f,o);return}this._bufferedBytes-=i[lt],this._state=bt,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===bt&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][lt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][lt],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};Rh.exports=gl;function ml(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 Ab(t,e,r){ml(t,e,r),t.onerror(e)}});var Fh=ie((SR,Bh)=>{"use strict";var{kForOnEventAttribute:ji,kListener:_l}=$t(),Dh=Symbol("kCode"),kh=Symbol("kData"),Ph=Symbol("kError"),Oh=Symbol("kMessage"),Lh=Symbol("kReason"),Br=Symbol("kTarget"),Nh=Symbol("kType"),Mh=Symbol("kWasClean"),Jt=class{constructor(e){this[Br]=null,this[Nh]=e}get target(){return this[Br]}get type(){return this[Nh]}};Object.defineProperty(Jt.prototype,"target",{enumerable:!0});Object.defineProperty(Jt.prototype,"type",{enumerable:!0});var jn=class extends Jt{constructor(e,r={}){super(e),this[Dh]=r.code===void 0?0:r.code,this[Lh]=r.reason===void 0?"":r.reason,this[Mh]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Dh]}get reason(){return this[Lh]}get wasClean(){return this[Mh]}};Object.defineProperty(jn.prototype,"code",{enumerable:!0});Object.defineProperty(jn.prototype,"reason",{enumerable:!0});Object.defineProperty(jn.prototype,"wasClean",{enumerable:!0});var Fr=class extends Jt{constructor(e,r={}){super(e),this[Ph]=r.error===void 0?null:r.error,this[Oh]=r.message===void 0?"":r.message}get error(){return this[Ph]}get message(){return this[Oh]}};Object.defineProperty(Fr.prototype,"error",{enumerable:!0});Object.defineProperty(Fr.prototype,"message",{enumerable:!0});var Wi=class extends Jt{constructor(e,r={}){super(e),this[kh]=r.data===void 0?null:r.data}get data(){return this[kh]}};Object.defineProperty(Wi.prototype,"data",{enumerable:!0});var Tb={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[ji]&&o[_l]===e&&!o[ji])return;let i;if(t==="message")i=function(c,l){let u=new Wi("message",{data:l?c:c.toString()});u[Br]=this,No(e,this,u)};else if(t==="close")i=function(c,l){let u=new jn("close",{code:c,reason:l.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Br]=this,No(e,this,u)};else if(t==="error")i=function(c){let l=new Fr("error",{error:c,message:c.message});l[Br]=this,No(e,this,l)};else if(t==="open")i=function(){let c=new Jt("open");c[Br]=this,No(e,this,c)};else return;i[ji]=!!r[ji],i[_l]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[_l]===e&&!r[ji]){this.removeListener(t,r);break}}};Bh.exports={CloseEvent:jn,ErrorEvent:Fr,Event:Jt,EventTarget:Tb,MessageEvent:Wi};function No(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Mo=ie((IR,zh)=>{"use strict";var{tokenChars:Ki}=Lr();function Bt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function Cb(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,l,u,f=-1,x=-1,m=-1,w=0;for(;w<t.length;w++)if(x=t.charCodeAt(w),l===void 0)if(m===-1&&Ki[x]===1)f===-1&&(f=w);else if(w!==0&&(x===32||x===9))m===-1&&f!==-1&&(m=w);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);m===-1&&(m=w);let p=t.slice(f,m);x===44?(Bt(e,p,r),r=Object.create(null)):l=p,f=m=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);else if(u===void 0)if(m===-1&&Ki[x]===1)f===-1&&(f=w);else if(x===32||x===9)m===-1&&f!==-1&&(m=w);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);m===-1&&(m=w),Bt(r,t.slice(f,m),!0),x===44&&(Bt(e,l,r),r=Object.create(null),l=void 0),f=m=-1}else if(x===61&&f!==-1&&m===-1)u=t.slice(f,w),f=m=-1;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(o){if(Ki[x]!==1)throw new SyntaxError(`Unexpected character at index ${w}`);f===-1?f=w:i||(i=!0),o=!1}else if(c)if(Ki[x]===1)f===-1&&(f=w);else if(x===34&&f!==-1)c=!1,m=w;else if(x===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(x===34&&t.charCodeAt(w-1)===61)c=!0;else if(m===-1&&Ki[x]===1)f===-1&&(f=w);else if(f!==-1&&(x===32||x===9))m===-1&&(m=w);else if(x===59||x===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);m===-1&&(m=w);let p=t.slice(f,m);i&&(p=p.replace(/\\/g,""),i=!1),Bt(r,u,p),x===44&&(Bt(e,l,r),r=Object.create(null),l=void 0),u=void 0,f=m=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);if(f===-1||c||x===32||x===9)throw new SyntaxError("Unexpected end of input");m===-1&&(m=w);let b=t.slice(f,m);return l===void 0?Bt(e,b,r):(u===void 0?Bt(r,b,!0):i?Bt(r,u,b.replace(/\\/g,"")):Bt(r,u,b),Bt(e,l,r)),e}function Rb(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(i=>[e].concat(Object.keys(i).map(o=>{let c=i[o];return Array.isArray(c)||(c=[c]),c.map(l=>l===!0?o:`${o}=${l}`).join("; ")})).join("; ")).join(", ")}).join(", ")}zh.exports={format:Rb,parse:Cb}});var Uo=ie((CR,Yh)=>{"use strict";var Db=ce("events"),kb=ce("https"),Pb=ce("http"),qh=ce("net"),Ob=ce("tls"),{randomBytes:Lb,createHash:Nb}=ce("crypto"),{Duplex:AR,Readable:TR}=ce("stream"),{URL:yl}=ce("url"),vn=Or(),Mb=pl(),Bb=wl(),{isBlob:Fb}=Lr(),{BINARY_TYPES:Uh,CLOSE_TIMEOUT:zb,EMPTY_BUFFER:Bo,GUID:Ub,kForOnEventAttribute:El,kListener:Hb,kStatusCode:qb,kWebSocket:ze,NOOP:Gh}=$t(),{EventTarget:{addEventListener:Gb,removeEventListener:jb}}=Fh(),{format:Wb,parse:Kb}=Mo(),{toBuffer:$b}=qi(),jh=Symbol("kAborted"),bl=[8,13],Zt=["CONNECTING","OPEN","CLOSING","CLOSED"],Vb=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,pe=class t extends Db{constructor(e,r,i){super(),this._binaryType=Uh[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Bo,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),Wh(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Uh.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 Mb({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new Bb(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[ze]=this,c[ze]=this,e[ze]=this,o.on("conclude",Yb),o.on("drain",Xb),o.on("error",Qb),o.on("message",ev),o.on("ping",tv),o.on("pong",nv),c.onerror=rv,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Vh),e.on("data",zo),e.on("end",Jh),e.on("error",Zh),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[vn.extensionName]&&this._extensions[vn.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){rt(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),$h(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){vl(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Bo,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){vl(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Bo,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){vl(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[vn.extensionName]||(o.compress=!1),this._sender.send(e||Bo,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){rt(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(pe,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(pe.prototype,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(pe,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(pe.prototype,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(pe,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(pe.prototype,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(pe,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});Object.defineProperty(pe.prototype,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(pe.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(pe.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[El])return e[Hb];return null},set(e){for(let r of this.listeners(t))if(r[El]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[El]:!0})}})});pe.prototype.addEventListener=Gb;pe.prototype.removeEventListener=jb;Yh.exports=pe;function Wh(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:zb,protocolVersion:bl[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,!bl.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${bl.join(", ")})`);let c;if(e instanceof yl)c=e;else try{c=new yl(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:",f;if(c.protocol!=="ws:"&&!l&&!u?f=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?f="The URL's pathname is empty":c.hash&&(f="The URL contains a fragment identifier"),f){let S=new SyntaxError(f);if(t._redirects===0)throw S;Fo(t,S);return}let x=l?443:80,m=Lb(16).toString("base64"),w=l?kb.request:Pb.request,b=new Set,p;if(o.createConnection=o.createConnection||(l?Zb:Jb),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&&(p=new vn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=Wb({[vn.extensionName]:p.offer()})),r.length){for(let S of r){if(typeof S!="string"||!Vb.test(S)||b.has(S))throw new SyntaxError("An invalid or duplicated subprotocol was specified");b.add(S)}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 S=o.path.split(":");o.socketPath=S[0],o.path=S[1]}let _;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=l,t._originalHostOrSocketPath=u?o.socketPath:c.host;let S=i&&i.headers;if(i={...i,headers:{}},S)for(let[A,T]of Object.entries(S))i.headers[A.toLowerCase()]=T}else if(t.listenerCount("redirect")===0){let S=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!S||t._originalSecure&&!l)&&(delete o.headers.authorization,delete o.headers.cookie,S||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),_=t._req=w(o),t._redirects&&t.emit("redirect",t.url,_)}else _=t._req=w(o);o.timeout&&_.on("timeout",()=>{rt(t,_,"Opening handshake has timed out")}),_.on("error",S=>{_===null||_[jh]||(_=t._req=null,Fo(t,S))}),_.on("response",S=>{let A=S.headers.location,T=S.statusCode;if(A&&o.followRedirects&&T>=300&&T<400){if(++t._redirects>o.maxRedirects){rt(t,_,"Maximum redirects exceeded");return}_.abort();let D;try{D=new yl(A,e)}catch{let k=new SyntaxError(`Invalid URL: ${A}`);Fo(t,k);return}Wh(t,D,r,i)}else t.emit("unexpected-response",_,S)||rt(t,_,`Unexpected server response: ${S.statusCode}`)}),_.on("upgrade",(S,A,T)=>{if(t.emit("upgrade",S),t.readyState!==pe.CONNECTING)return;_=t._req=null;let D=S.headers.upgrade;if(D===void 0||D.toLowerCase()!=="websocket"){rt(t,A,"Invalid Upgrade header");return}let E=Nb("sha1").update(m+Ub).digest("base64");if(S.headers["sec-websocket-accept"]!==E){rt(t,A,"Invalid Sec-WebSocket-Accept header");return}let k=S.headers["sec-websocket-protocol"],P;if(k!==void 0?b.size?b.has(k)||(P="Server sent an invalid subprotocol"):P="Server sent a subprotocol but none was requested":b.size&&(P="Server sent no subprotocol"),P){rt(t,A,P);return}k&&(t._protocol=k);let B=S.headers["sec-websocket-extensions"];if(B!==void 0){if(!p){rt(t,A,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let N;try{N=Kb(B)}catch{rt(t,A,"Invalid Sec-WebSocket-Extensions header");return}let $=Object.keys(N);if($.length!==1||$[0]!==vn.extensionName){rt(t,A,"Server indicated an extension that was not requested");return}try{p.accept(N[vn.extensionName])}catch{rt(t,A,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[vn.extensionName]=p}t.setSocket(A,T,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(_,t):_.end()}function Fo(t,e){t._readyState=pe.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Jb(t){return t.path=t.socketPath,qh.connect(t)}function Zb(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=qh.isIP(t.host)?"":t.host),Ob.connect(t)}function rt(t,e,r){t._readyState=pe.CLOSING;let i=new Error(r);Error.captureStackTrace(i,rt),e.setHeader?(e[jh]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Fo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function vl(t,e,r){if(e){let i=Fb(e)?e.size:$b(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Zt[t.readyState]})`);process.nextTick(r,i)}}function Yb(t,e){let r=this[ze];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[ze]!==void 0&&(r._socket.removeListener("data",zo),process.nextTick(Kh,r._socket),t===1005?r.close():r.close(t,e))}function Xb(){let t=this[ze];t.isPaused||t._socket.resume()}function Qb(t){let e=this[ze];e._socket[ze]!==void 0&&(e._socket.removeListener("data",zo),process.nextTick(Kh,e._socket),e.close(t[qb])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Hh(){this[ze].emitClose()}function ev(t,e){this[ze].emit("message",t,e)}function tv(t){let e=this[ze];e._autoPong&&e.pong(t,!this._isServer,Gh),e.emit("ping",t)}function nv(t){this[ze].emit("pong",t)}function Kh(t){t.resume()}function rv(t){let e=this[ze];e.readyState!==pe.CLOSED&&(e.readyState===pe.OPEN&&(e._readyState=pe.CLOSING,$h(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function $h(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Vh(){let t=this[ze];if(this.removeListener("close",Vh),this.removeListener("data",zo),this.removeListener("end",Jh),t._readyState=pe.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[ze]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Hh),t._receiver.on("finish",Hh))}function zo(t){this[ze]._receiver.write(t)||this.pause()}function Jh(){let t=this[ze];t._readyState=pe.CLOSING,t._receiver.end(),this.end()}function Zh(){let t=this[ze];this.removeListener("error",Zh),this.on("error",Gh),t&&(t._readyState=pe.CLOSING,this.destroy())}});var tx=ie((DR,ex)=>{"use strict";var RR=Uo(),{Duplex:iv}=ce("stream");function Xh(t){t.emit("close")}function sv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Qh(t){this.removeListener("error",Qh),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function ov(t,e){let r=!0,i=new iv({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,l){let u=!l&&i._readableState.objectMode?c.toString():c;i.push(u)||t.pause()}),t.once("error",function(c){i.destroyed||(r=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick(Xh,i);return}let l=!1;t.once("error",function(f){l=!0,c(f)}),t.once("close",function(){l||c(o),process.nextTick(Xh,i)}),r&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,l){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,l)});return}t.send(o,l)},i.on("end",sv),i.on("error",Qh),i}ex.exports=ov});var Sl=ie((kR,nx)=>{"use strict";var{tokenChars:av}=Lr();function cv(t){let e=new Set,r=-1,i=-1,o=0;for(o;o<t.length;o++){let l=t.charCodeAt(o);if(i===-1&&av[l]===1)r===-1&&(r=o);else if(o!==0&&(l===32||l===9))i===-1&&r!==-1&&(i=o);else if(l===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let u=t.slice(r,i);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);e.add(u),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(r,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}nx.exports={parse:cv}});var lx=ie((OR,cx)=>{"use strict";var lv=ce("events"),Ho=ce("http"),{Duplex:PR}=ce("stream"),{createHash:dv}=ce("crypto"),rx=Mo(),Wn=Or(),uv=Sl(),fv=Uo(),{CLOSE_TIMEOUT:hv,GUID:xv,kWebSocket:pv}=$t(),gv=/^[+/0-9A-Za-z]{22}==$/,ix=0,sx=1,ax=2,Il=class extends lv{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:hv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:fv,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=Ho.createServer((i,o)=>{let c=Ho.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=mv(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=ix}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===ax){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick($i,this);return}if(e&&this.once("close",e),this._state!==sx)if(this._state=sx,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick($i,this):process.nextTick($i,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{$i(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,o){r.on("error",ox);let c=e.headers["sec-websocket-key"],l=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Kn(this,e,r,405,"Invalid HTTP method");return}if(l===void 0||l.toLowerCase()!=="websocket"){Kn(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!gv.test(c)){Kn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){Kn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Vi(r,400);return}let f=e.headers["sec-websocket-protocol"],x=new Set;if(f!==void 0)try{x=uv.parse(f)}catch{Kn(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let m=e.headers["sec-websocket-extensions"],w={};if(this.options.perMessageDeflate&&m!==void 0){let b=new Wn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let p=rx.parse(m);p[Wn.extensionName]&&(b.accept(p[Wn.extensionName]),w[Wn.extensionName]=b)}catch{Kn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let b={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(b,(p,_,S,A)=>{if(!p)return Vi(r,_||401,S,A);this.completeUpgrade(w,c,x,e,r,i,o)});return}if(!this.options.verifyClient(b))return Vi(r,401)}this.completeUpgrade(w,c,x,e,r,i,o)}completeUpgrade(e,r,i,o,c,l,u){if(!c.readable||!c.writable)return c.destroy();if(c[pv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>ix)return Vi(c,503);let x=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${dv("sha1").update(r+xv).digest("base64")}`],m=new this.options.WebSocket(null,void 0,this.options);if(i.size){let w=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;w&&(x.push(`Sec-WebSocket-Protocol: ${w}`),m._protocol=w)}if(e[Wn.extensionName]){let w=e[Wn.extensionName].params,b=rx.format({[Wn.extensionName]:[w]});x.push(`Sec-WebSocket-Extensions: ${b}`),m._extensions=e}this.emit("headers",x,o),c.write(x.concat(`\r
10
+ `),this.stream=void 0;return}this.currentDate!==void 0&&Qi(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 og,mkdirSync as ag}from"node:fs";import{join as cg}from"node:path";function dl(t){let e=t.retentionDays??ug,r=t.clock??(()=>An(new Date));ts={bridgeSink:new $r(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new $r(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();Qi(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])Qi(t.agentLogsDir(o),"agent",i,e)}function fg(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function ll(t){Ea=t}function ul(t){return Qn[Ea]<=Qn[t]}function fl(t,e){let r=Qn[t];return r===void 0?!0:r>=Qn[e]}function ns(t){cl={...t}}function hl(t){let e=(u,h=2)=>String(u).padStart(h,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),l=e(o%60);return`${An(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${l}`}function er(t,e,r,i,o){try{let c=`${JSON.stringify({ts:hl(new Date),level:e,module:r,msg:i,...o})}
11
+ `;ag(t,{recursive:!0}),og(cg(t,Xn("bridge",An(new Date))),c)}catch{}}function hg(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function es(t,e,r,i,o){if(Qn[t]<Qn[Ea])return;let c=`${JSON.stringify({ts:hl(new Date),level:t,module:e,msg:r,...cl,...i})}
12
+ `;if(ts){let l=hg(o,i),u=l?fg(ts,l):ts.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?lg.write(c):dg.write(c)}function U(t,e){return{debug:(r,i)=>es("debug",t,r,i,e),info:(r,i)=>es("info",t,r,i,e),warn:(r,i)=>es("warn",t,r,i,e),error:(r,i)=>es("error",t,r,i,e),child:r=>U(`${t}.${r}`,e),forAgent:r=>U(t,r)}}var Qn,Ea,dg,lg,cl,ug,ts,ne=Ve(()=>{"use strict";Kr();ya();Qn={debug:10,info:20,warn:30,error:40},Ea=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),dg=process.stdout,lg=process.stderr,cl={},ug=Ye("COZE_BRIDGE_LOG_RETENTION_DAYS",30),ts=null});var C,We=Ve(()=>{"use strict";C=class extends Error{code;retriable;cause;constructor(e,r,i){super(r),this.name="BridgeError",this.code=e,this.retriable=i?.retriable??!1,i?.cause!==void 0&&(this.cause=i.cause)}}});var ml={};wa(ml,{ACP_WRAPPER_NPM_PACKAGES:()=>Vr,_resetAcpInstallerForTests:()=>_g,_setBinaryPathCacheForTests:()=>yg,buildAcpSpawn:()=>Yr,ensureAcpInstalled:()=>tr,getAcpBinaryPath:()=>rs,pickWhichLine:()=>Sa,probeAcpVersion:()=>wg,resolveAcpCommand:()=>gl});import{readFileSync as xl}from"node:fs";import{createRequire as xg}from"node:module";import{dirname as pg,resolve as gg}from"node:path";function Sa(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 mg(t){let e=pl.resolve(`${t.npmPackage}/package.json`),r=pg(e),i=JSON.parse(xl(e,"utf8")),o=typeof i.bin=="string"?i.bin:i.bin?.[t.binary];if(!o)throw new Error(`${t.npmPackage} package.json \u7F3A bin[${t.binary}]`);return gg(r,o)}async function tr(t,e){let r=va[t];if(!r)throw new C("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=Jr.get(t);if(i)return i;try{let o=mg(r);return Jr.set(t,o),ba.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw ba.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:r.npmPackage,err:String(o)}),new C("AGENT_DEPENDENCY_INSTALL_FAILED",[`ACP wrapper \u672A\u5C31\u7EEA: ${r.npmPackage} (framework=${t})`,"\u8BE5 wrapper \u968F coze-bridge \u4E00\u8D77\u5B89\u88C5 (\u56FA\u5316\u5230 ~/.coze/bridge/lib/node_modules)\u3002","\u8BF7\u91CD\u8DD1 `coze-bridge pair` / `connect` \u89E6\u53D1\u56FA\u5316\u5B89\u88C5; \u82E5\u4ECD\u5931\u8D25, \u68C0\u67E5\u7F51\u7EDC / npm \u7F13\u5B58\u3002"].join(`
13
+ `),{cause:o})}}async function wg(t){let e=va[t];if(e)try{let r=pl.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(xl(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){ba.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function rs(t){return Jr.get(t)}function gl(t,e){if(e)return e;let r=rs(t);if(!r)throw new C("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return r}function Yr(t,e,r){if(e)return{command:e,args:[...r]};let i=gl(t);return{command:process.execPath,args:[i,...r]}}function _g(){Jr.clear()}function yg(t,e){Jr.set(t,e)}var ba,va,Vr,pl,Jr,tn=Ve(()=>{"use strict";We();ne();ba=U("agents.acp-installer"),va={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},Vr=Object.values(va).filter(t=>t!==void 0).map(t=>t.npmPackage),pl=xg(import.meta.url),Jr=new Map});import{chmod as bg,mkdir as vg,readFile as Sg,rename as yl,writeFile as El}from"node:fs/promises";import{dirname as Ig}from"node:path";async function nr(t){try{let e=await Sg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function rr(t,e,r){await vg(Ig(t),{recursive:!0});let i=`${JSON.stringify(e,null,2)}
14
+ `,o=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{r?.mode!==void 0?await El(o,i,{encoding:"utf8",mode:r.mode}):await El(o,i,"utf8"),await yl(o,t),r?.mode!==void 0&&await bg(t,r.mode)}catch(c){await yl(o,o).catch(()=>{});let{rm:l}=await import("node:fs/promises");throw await l(o,{force:!0}).catch(()=>{}),c}}var Zr=Ve(()=>{"use strict"});import{promises as bl,readdirSync as Ag}from"node:fs";import{homedir as Tg}from"node:os";import{sep as Cg,join as Ie,resolve as vl}from"node:path";function Q(t){let e=t??Tg(),r=Ie(e,".coze"),i=Ie(r,"bridge"),o=Ie(i,"lib"),c=Ie(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Ie(o,"index.js"),binDir:Ie(i,"bin"),pidFile:Ie(i,"bridge.pid"),portFile:Ie(i,"bridge.port"),tokenFile:Ie(i,"bridge.token"),patTokenFile:Ie(i,"pat-token"),agentEnvFile:Ie(i,"agent-env.json"),logFile:Ie(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Ie(c,"daemon-stdio.log"),installLock:Ie(i,"install.lock"),configFile:Ie(i,"config.json"),agentsRoot:Ie(r,"agents")}}function Ze(t,e=Q()){let r=Ie(e.agentsRoot,t);return{root:r,config:Ie(r,"config.json"),workspace:Ie(r,"workspace"),logs:Ie(r,"logs")}}function is(t=Q()){try{return Ag(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function Xr(t,e){let r=await bl.realpath(vl(t)).catch(()=>null);if(!r)return!1;let i=await bl.realpath(vl(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+Cg)}var ke=Ve(()=>{"use strict"});var as={};wa(as,{AGENT_CONFIG_FILE_MODE:()=>ss,enforceAgentConfigMode:()=>kg,loadAgentConfig:()=>qe,persistAgentSessions:()=>Qr,persistAgentSkills:()=>os,saveAgentConfig:()=>Xe});import{chmod as Rg,stat as Dg}from"node:fs/promises";function qe(t,e){return nr(Ze(t,e).config)}function Xe(t,e){return rr(Ze(t.agentId,e).config,t,{mode:ss})}async function kg(t,e){if(process.platform==="win32")return;let r=Ze(t,e).config;try{let i=await Dg(r);if(!i.isFile())return;let o=i.mode&511;o!==ss&&(await Rg(r,ss),Sl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Sl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function Qr(t,e,r){let i=await qe(t,r);i&&(i.sessions=Object.fromEntries(e),await Xe(i,r))}async function os(t,e,r){let i=await qe(t,r);i&&(i.skills=e,await Xe(i,r))}var Sl,ss,nn=Ve(()=>{"use strict";Zr();ne();ke();Sl=U("agent-config"),ss=384});var Ta=se((d2,Tl)=>{Tl.exports={LOCHDR:30,LOCSIG:67324752,LOCVER:4,LOCFLG:6,LOCHOW:8,LOCTIM:10,LOCCRC:14,LOCSIZ:18,LOCLEN:22,LOCNAM:26,LOCEXT:28,EXTSIG:134695760,EXTHDR:16,EXTCRC:4,EXTSIZ:8,EXTLEN:12,CENHDR:46,CENSIG:33639248,CENVEM:4,CENVER:6,CENFLG:8,CENHOW:10,CENTIM:12,CENCRC:16,CENSIZ:20,CENLEN:24,CENNAM:28,CENEXT:30,CENCOM:32,CENDSK:34,CENATT:36,CENATX:38,CENOFF:42,ENDHDR:22,ENDSIG:101010256,ENDSUB:8,ENDTOT:10,ENDSIZ:12,ENDOFF:16,ENDCOM:20,END64HDR:20,END64SIG:117853008,END64START:4,END64OFF:8,END64NUMDISKS:16,ZIP64SIG:101075792,ZIP64HDR:56,ZIP64LEAD:12,ZIP64SIZE:4,ZIP64VEM:12,ZIP64VER:14,ZIP64DSK:16,ZIP64DSKDIR:20,ZIP64SUB:24,ZIP64TOT:32,ZIP64SIZB:40,ZIP64OFF:48,ZIP64EXTRA:56,STORED:0,SHRUNK:1,REDUCED1:2,REDUCED2:3,REDUCED3:4,REDUCED4:5,IMPLODED:6,DEFLATED:8,ENHANCED_DEFLATED:9,PKWARE:10,BZIP2:12,LZMA:14,IBM_TERSE:18,IBM_LZ77:19,AES_ENCRYPT:99,FLG_ENC:1,FLG_COMP1:2,FLG_COMP2:4,FLG_DESC:8,FLG_ENH:16,FLG_PATCH:32,FLG_STR:64,FLG_EFS:2048,FLG_MSK:4096,FILE:2,BUFFER:1,NONE:0,EF_ID:0,EF_SIZE:2,ID_ZIP64:1,ID_AVINFO:7,ID_PFS:8,ID_OS2:9,ID_NTFS:10,ID_OPENVMS:12,ID_UNIX:13,ID_FORK:14,ID_PATCH:15,ID_X509_PKCS7:20,ID_X509_CERTID_F:21,ID_X509_CERTID_C:22,ID_STRONGENC:23,ID_RECORD_MGT:24,ID_X509_PKCS7_RL:25,ID_IBM1:101,ID_IBM2:102,ID_POSZIP:18064,EF_ZIP64_OR_32:4294967295,EF_ZIP64_OR_16:65535,EF_ZIP64_SUNCOMP:0,EF_ZIP64_SCOMP:8,EF_ZIP64_RHO:16,EF_ZIP64_DSN:24}});var ds=se(Rl=>{var Cl={INVALID_LOC:"Invalid LOC header (bad signature)",INVALID_CEN:"Invalid CEN header (bad signature)",INVALID_END:"Invalid END header (bad signature)",DESCRIPTOR_NOT_EXIST:"No descriptor present",DESCRIPTOR_UNKNOWN:"Unknown descriptor format",DESCRIPTOR_FAULTY:"Descriptor data is malformed",NO_DATA:"Nothing to decompress",BAD_CRC:"CRC32 checksum failed {0}",FILE_IN_THE_WAY:"There is a file in the way: {0}",UNKNOWN_METHOD:"Invalid/unsupported compression method",AVAIL_DATA:"inflate::Available inflate data did not terminate",INVALID_DISTANCE:"inflate::Invalid literal/length or distance code in fixed or dynamic block",TO_MANY_CODES:"inflate::Dynamic block code description: too many length or distance codes",INVALID_REPEAT_LEN:"inflate::Dynamic block code description: repeat more than specified lengths",INVALID_REPEAT_FIRST:"inflate::Dynamic block code description: repeat lengths with no first length",INCOMPLETE_CODES:"inflate::Dynamic block code description: code lengths codes incomplete",INVALID_DYN_DISTANCE:"inflate::Dynamic block code description: invalid distance code lengths",INVALID_CODES_LEN:"inflate::Dynamic block code description: invalid literal/length code lengths",INVALID_STORE_BLOCK:"inflate::Stored block length did not match one's complement",INVALID_BLOCK_TYPE:"inflate::Invalid block type (type == 3)",CANT_EXTRACT_FILE:"Could not extract the file",CANT_OVERRIDE:"Target file already exists",DISK_ENTRY_TOO_LARGE:"Number of disk entries is too large",NO_ZIP:"No zip file was loaded",NO_ENTRY:"Entry doesn't exist",DIRECTORY_CONTENT_ERROR:"A directory cannot have content",FILE_NOT_FOUND:'File not found: "{0}"',NOT_IMPLEMENTED:"Not implemented",INVALID_FILENAME:"Invalid filename",INVALID_FORMAT:"Invalid or unsupported zip format. No END header found",INVALID_PASS_PARAM:"Incompatible password parameter",WRONG_PASSWORD:"Wrong Password",COMMENT_TOO_LONG:"Comment is too long",EXTRA_FIELD_PARSE_ERROR:"Extra field parsing error"};function Bg(t){return function(...e){return e.length&&(t=t.replace(/\{(\d)\}/g,(r,i)=>e[i]||"")),new Error("ADM-ZIP: "+t)}}for(let t of Object.keys(Cl))Rl[t]=Bg(Cl[t])});var Ll=se((u2,Ol)=>{var Fg=de("fs"),Pe=de("path"),Dl=Ta(),zg=ds(),Ug=typeof process=="object"&&process.platform==="win32",kl=t=>typeof t=="object"&&t!==null,Pl=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function Ee(t){this.sep=Pe.sep,this.fs=Fg,kl(t)&&kl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Ol.exports=Ee;Ee.prototype.makeDir=function(t){let e=this;function r(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var l;try{l=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(l&&l.isFile())throw zg.FILE_IN_THE_WAY(`"${o}"`)}})}r(t)};Ee.prototype.writeFileTo=function(t,e,r,i){let o=this;if(o.fs.existsSync(t)){if(!r)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var l=Pe.dirname(t);o.fs.existsSync(l)||o.makeDir(l);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};Ee.prototype.writeFileToAsync=function(t,e,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(l){if(l&&!r)return o(!1);c.fs.stat(t,function(u,h){if(l&&h.isDirectory())return o(!1);var x=Pe.dirname(t);c.fs.exists(x,function(w){w||c.makeDir(x),c.fs.open(t,"w",438,function(_,S){_?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(E,v){c.fs.write(v,e,0,e.length,0,function(){c.fs.close(v,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):S?c.fs.write(S,e,0,e.length,0,function(){c.fs.close(S,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};Ee.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let l=[];return e.fs.readdirSync(i).forEach(function(u){let h=Pe.join(i,u),x=e.fs.statSync(h);(!o||o.test(h))&&l.push(Pe.normalize(h)+(x.isDirectory()?e.sep:"")),x.isDirectory()&&c&&(l=l.concat(r(h,o,c)))}),l}return r(t,void 0,!0)};Ee.prototype.findFilesAsync=function(t,e){let r=this,i=[];r.fs.readdir(t,function(o,c){if(o)return e(o);let l=c.length;if(!l)return e(null,i);c.forEach(function(u){u=Pe.join(t,u),r.fs.stat(u,function(h,x){if(h)return e(h);x&&(i.push(Pe.normalize(u)+(x.isDirectory()?r.sep:"")),x.isDirectory()?r.findFilesAsync(u,function(w,_){if(w)return e(w);i=i.concat(_),--l||e(null,i)}):--l||e(null,i))})})})};Ee.prototype.getAttributes=function(){};Ee.prototype.setAttributes=function(){};Ee.crc32update=function(t,e){return Pl[(t^e)&255]^t>>>8};Ee.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,r=-1;for(let i=0;i<e;)r=Ee.crc32update(r,t[i++]);return~r>>>0};Ee.methodToString=function(t){switch(t){case Dl.STORED:return"STORED ("+t+")";case Dl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Ee.canonical=function(t){if(!t)return"";let e=Pe.posix.normalize("/"+t.split("\\").join("/"));return Pe.join(".",e)};Ee.zipnamefix=function(t){if(!t)return"";let e=Pe.posix.normalize("/"+t.split("\\").join("/"));return Pe.posix.join(".",e)};Ee.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let r=t.length>>>0;for(let i=r-1;i>=0;i--)if(e(t[i],i,t))return t[i]};Ee.sanitize=function(t,e){t=Pe.resolve(Pe.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Pe.normalize(Pe.join(t,r.slice(i,o).join(Pe.sep)));if(c.indexOf(t)===0)return c}return Pe.normalize(Pe.join(t,Pe.basename(e)))};Ee.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};Ee.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};Ee.fromDOS2Date=function(t){return new Date((t>>25&127)+1980,Math.max((t>>21&15)-1,0),Math.max(t>>16&31,1),t>>11&31,t>>5&63,(t&31)<<1)};Ee.fromDate2DOS=function(t){let e=0,r=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),r=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|r};Ee.isWin=Ug;Ee.crcTable=Pl});var Ml=se((f2,Nl)=>{var Hg=de("path");Nl.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=Hg.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 Fl=se((h2,Bl)=>{Bl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var or=se((x2,sr)=>{sr.exports=Ll();sr.exports.Constants=Ta();sr.exports.Errors=ds();sr.exports.FileAttr=Ml();sr.exports.decoder=Fl()});var Ul=se((p2,zl)=>{var rn=or(),z=rn.Constants;zl.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,l=0,u=0,h=0,x=0,w=0,_=0,S=0,E=0,v=0;t|=rn.isWin?2560:768,r|=z.FLG_EFS;let A={extraLen:0},I=y=>Math.max(0,y)>>>0,R=y=>Math.max(0,y)&65535,L=y=>Math.max(0,y)&255;return o=rn.fromDate2DOS(new Date),{get made(){return t},set made(y){t=y},get version(){return e},set version(y){e=y},get flags(){return r},set flags(y){r=y},get flags_efs(){return(r&z.FLG_EFS)>0},set flags_efs(y){y?r|=z.FLG_EFS:r&=~z.FLG_EFS},get flags_desc(){return(r&z.FLG_DESC)>0},set flags_desc(y){y?r|=z.FLG_DESC:r&=~z.FLG_DESC},get method(){return i},set method(y){switch(y){case z.STORED:this.version=10;case z.DEFLATED:default:this.version=20}i=y},get time(){return rn.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=rn.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=I(y)},get timeHighByte(){return L(o>>>8)},get crc(){return c},set crc(y){c=I(y)},get compressedSize(){return l},set compressedSize(y){l=I(y)},get size(){return u},set size(y){u=I(y)},get fileNameLength(){return h},set fileNameLength(y){h=y},get extraLength(){return x},set extraLength(y){x=y},get extraLocalLength(){return A.extraLen},set extraLocalLength(y){A.extraLen=y},get commentLength(){return w},set commentLength(y){w=y},get diskNumStart(){return _},set diskNumStart(y){_=I(y)},get inAttr(){return S},set inAttr(y){S=I(y)},get attr(){return E},set attr(y){E=I(y)},get fileAttr(){return(E||0)>>16&4095},get offset(){return v},set offset(y){v=I(y)},get encrypted(){return(r&z.FLG_ENC)===z.FLG_ENC},get centralHeaderSize(){return z.CENHDR+h+x+w},get realDataOffset(){return v+z.LOCHDR+A.fnameLen+A.extraLen},get localHeader(){return A},loadLocalHeaderFromBinary:function(y){var D=y.slice(v,v+z.LOCHDR);if(D.readUInt32LE(0)!==z.LOCSIG)throw rn.Errors.INVALID_LOC();A.version=D.readUInt16LE(z.LOCVER),A.flags=D.readUInt16LE(z.LOCFLG),A.flags_desc=(A.flags&z.FLG_DESC)>0,A.method=D.readUInt16LE(z.LOCHOW),A.time=D.readUInt32LE(z.LOCTIM),A.crc=D.readUInt32LE(z.LOCCRC),A.compressedSize=D.readUInt32LE(z.LOCSIZ),A.size=D.readUInt32LE(z.LOCLEN),A.fnameLen=D.readUInt16LE(z.LOCNAM),A.extraLen=D.readUInt16LE(z.LOCEXT);let k=v+z.LOCHDR+A.fnameLen,N=k+A.extraLen;return y.slice(k,N)},loadFromBinary:function(y){if(y.length!==z.CENHDR||y.readUInt32LE(0)!==z.CENSIG)throw rn.Errors.INVALID_CEN();t=y.readUInt16LE(z.CENVEM),e=y.readUInt16LE(z.CENVER),r=y.readUInt16LE(z.CENFLG),i=y.readUInt16LE(z.CENHOW),o=y.readUInt32LE(z.CENTIM),c=y.readUInt32LE(z.CENCRC),l=y.readUInt32LE(z.CENSIZ),u=y.readUInt32LE(z.CENLEN),h=y.readUInt16LE(z.CENNAM),x=y.readUInt16LE(z.CENEXT),w=y.readUInt16LE(z.CENCOM),_=y.readUInt16LE(z.CENDSK),S=y.readUInt16LE(z.CENATT),E=y.readUInt32LE(z.CENATX),v=y.readUInt32LE(z.CENOFF)},localHeaderToBinary:function(){var y=Buffer.alloc(z.LOCHDR);return y.writeUInt32LE(z.LOCSIG,0),y.writeUInt16LE(e,z.LOCVER),y.writeUInt16LE(r,z.LOCFLG),y.writeUInt16LE(i,z.LOCHOW),y.writeUInt32LE(o,z.LOCTIM),y.writeUInt32LE(c,z.LOCCRC),y.writeUInt32LE(l,z.LOCSIZ),y.writeUInt32LE(u,z.LOCLEN),y.writeUInt16LE(h,z.LOCNAM),y.writeUInt16LE(A.extraLen,z.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(z.CENHDR+h+x+w);return y.writeUInt32LE(z.CENSIG,0),y.writeUInt16LE(t,z.CENVEM),y.writeUInt16LE(e,z.CENVER),y.writeUInt16LE(r,z.CENFLG),y.writeUInt16LE(i,z.CENHOW),y.writeUInt32LE(o,z.CENTIM),y.writeUInt32LE(c,z.CENCRC),y.writeUInt32LE(l,z.CENSIZ),y.writeUInt32LE(u,z.CENLEN),y.writeUInt16LE(h,z.CENNAM),y.writeUInt16LE(x,z.CENEXT),y.writeUInt16LE(w,z.CENCOM),y.writeUInt16LE(_,z.CENDSK),y.writeUInt16LE(S,z.CENATT),y.writeUInt32LE(E,z.CENATX),y.writeUInt32LE(v,z.CENOFF),y},toJSON:function(){let y=function(D){return D+" bytes"};return{made:t,version:e,flags:r,method:rn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(l),size:y(u),fileNameLength:y(h),extraLength:y(x),commentLength:y(w),diskNumStart:_,inAttr:S,attr:E,offset:v,centralHeaderSize:y(z.CENHDR+h+x+w)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var ql=se((g2,Hl)=>{var ar=or(),we=ar.Constants;Hl.exports=function(){var t=0,e=0,r=0,i=0,o=0;return{get diskEntries(){return t},set diskEntries(c){t=e=c},get totalEntries(){return e},set totalEntries(c){e=t=c},get size(){return r},set size(c){r=c},get offset(){return i},set offset(c){i=c},get commentLength(){return o},set commentLength(c){o=c},get mainHeaderSize(){return we.ENDHDR+o},loadFromBinary:function(c){if((c.length!==we.ENDHDR||c.readUInt32LE(0)!==we.ENDSIG)&&(c.length<we.ZIP64HDR||c.readUInt32LE(0)!==we.ZIP64SIG))throw ar.Errors.INVALID_END();c.readUInt32LE(0)===we.ENDSIG?(t=c.readUInt16LE(we.ENDSUB),e=c.readUInt16LE(we.ENDTOT),r=c.readUInt32LE(we.ENDSIZ),i=c.readUInt32LE(we.ENDOFF),o=c.readUInt16LE(we.ENDCOM)):(t=ar.readBigUInt64LE(c,we.ZIP64SUB),e=ar.readBigUInt64LE(c,we.ZIP64TOT),r=ar.readBigUInt64LE(c,we.ZIP64SIZE),i=ar.readBigUInt64LE(c,we.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(we.ENDHDR+o);return c.writeUInt32LE(we.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,we.ENDSUB),c.writeUInt16LE(e,we.ENDTOT),c.writeUInt32LE(r,we.ENDSIZ),c.writeUInt32LE(i,we.ENDOFF),c.writeUInt16LE(o,we.ENDCOM),c.fill(" ",we.ENDHDR),c},toJSON:function(){let c=function(l,u){let h=l.toString(16).toUpperCase();for(;h.length<u;)h="0"+h;return"0x"+h};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Ra=se(Ca=>{Ca.EntryHeader=Ul();Ca.MainHeader=ql()});var jl=se((w2,Gl)=>{Gl.exports=function(t){var e=de("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],l=0;o.on("data",function(u){c.push(u),l+=u.length}),o.on("end",function(){var u=Buffer.alloc(l),h=0;u.fill(0);for(var x=0;x<c.length;x++){var w=c[x];w.copy(u,h),h+=w.length}i&&i(u)}),o.end(t)}}}});var Kl=se((_2,Wl)=>{var qg=+(process.versions?process.versions.node:"").split(".")[0]||0;Wl.exports=function(t,e){var r=de("zlib");let i=qg>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),l=[],u=0;c.on("data",function(h){l.push(h),u+=h.length}),c.on("end",function(){var h=Buffer.alloc(u),x=0;h.fill(0);for(var w=0;w<l.length;w++){var _=l[w];_.copy(h,x),x+=_.length}o&&o(h)}),c.end(t)}}}});var Zl=se((y2,Yl)=>{"use strict";var{randomFillSync:$l}=de("crypto"),Gg=ds(),jg=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}),Vl=(t,e)=>Math.imul(t,e)>>>0,Jl=(t,e)=>jg[(t^e)&255]^t>>>8,ei=()=>typeof $l=="function"?$l(Buffer.alloc(12)):ei.node();ei.node=()=>{let t=Buffer.alloc(12),e=t.length;for(let r=0;r<e;r++)t[r]=Math.random()*256&255;return t};var ls={genSalt:ei};function us(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])}us.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Jl(e[0],t),e[1]+=e[0]&255,e[1]=Vl(e[1],134775813)+1,e[2]=Jl(e[2],e[1]>>>24),t};us.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Vl(t,t^1)>>8&255};function Wg(t){let e=new us(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 Kg(t){let e=new us(t);return function(r,i,o=0){i||(i=Buffer.alloc(r.length));for(let c of r){let l=e.next();i[o++]=c^l,e.updateKeys(c)}return i}}function $g(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Wg(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Gg.WRONG_PASSWORD();return i(t.slice(12))}function Jg(t){Buffer.isBuffer(t)&&t.length>=12?ls.genSalt=function(){return t.slice(0,12)}:t==="node"?ls.genSalt=ei.node:ls.genSalt=ei}function Vg(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Kg(r),c=ls.genSalt();c[11]=e.crc>>>24&255,i&&(c[10]=e.crc>>>16&255);let l=Buffer.alloc(t.length+12);return o(c,l),o(t,l,12)}Yl.exports={decrypt:$g,encrypt:Vg,_salter:Jg}});var Xl=se(fs=>{fs.Deflater=jl();fs.Inflater=Kl();fs.ZipCrypto=Zl()});var ka=se((b2,Ql)=>{var oe=or(),Yg=Ra(),be=oe.Constants,Da=Xl();Ql.exports=function(t,e){var r=new Yg.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,l=null,u=Buffer.alloc(0),h=Buffer.alloc(0),x=!0;let w=t,_=typeof w.decoder=="object"?w.decoder:oe.decoder;x=_.hasOwnProperty("efs")?_.efs:!1;function S(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(h=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function E(y){if(!r.flags_desc&&!r.localHeader.flags_desc){if(oe.crc32(y)!==r.localHeader.crc)return!1}else{let D={},k=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(k)==be.LOCSIG||e.readUInt32LE(k)==be.CENSIG)throw oe.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(k)==be.EXTSIG)D.crc=e.readUInt32LE(k+be.EXTCRC),D.compressedSize=e.readUInt32LE(k+be.EXTSIZ),D.size=e.readUInt32LE(k+be.EXTLEN);else if(e.readUInt16LE(k+12)===19280)D.crc=e.readUInt32LE(k+be.EXTCRC-4),D.compressedSize=e.readUInt32LE(k+be.EXTSIZ-4),D.size=e.readUInt32LE(k+be.EXTLEN-4);else throw oe.Errors.DESCRIPTOR_UNKNOWN();if(D.compressedSize!==r.compressedSize||D.size!==r.size||D.crc!==r.crc)throw oe.Errors.DESCRIPTOR_FAULTY();if(oe.crc32(y)!==D.crc)return!1}return!0}function v(y,D,k){if(typeof D>"u"&&typeof y=="string"&&(k=y,y=void 0),c)return y&&D&&D(Buffer.alloc(0),oe.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var N=S();if(N.length===0)return y&&D&&D(N),N;if(r.encrypted){if(typeof k!="string"&&!Buffer.isBuffer(k))throw oe.Errors.INVALID_PASS_PARAM();N=Da.ZipCrypto.decrypt(N,r,k)}var B=Buffer.alloc(r.size);switch(r.method){case oe.Constants.STORED:if(N.copy(B),E(B))return y&&D&&D(B),B;throw y&&D&&D(B,oe.Errors.BAD_CRC()),oe.Errors.BAD_CRC();case oe.Constants.DEFLATED:var V=new Da.Inflater(N,r.size);if(y)V.inflateAsync(function(J){J.copy(J,0),D&&(E(J)?D(J):D(J,oe.Errors.BAD_CRC()))});else{if(V.inflate(B).copy(B,0),!E(B))throw oe.Errors.BAD_CRC(`"${_.decode(i)}"`);return B}break;default:throw y&&D&&D(Buffer.alloc(0),oe.Errors.UNKNOWN_METHOD()),oe.Errors.UNKNOWN_METHOD()}}function A(y,D){if((!l||!l.length)&&Buffer.isBuffer(e))return y&&D&&D(S()),S();if(l.length&&!c){var k;switch(r.method){case oe.Constants.STORED:return r.compressedSize=r.size,k=Buffer.alloc(l.length),l.copy(k),y&&D&&D(k),k;default:case oe.Constants.DEFLATED:var N=new Da.Deflater(l);if(y)N.deflateAsync(function(V){k=Buffer.alloc(V.length),r.compressedSize=V.length,V.copy(k),D&&D(k)});else{var B=N.deflate();return r.compressedSize=B.length,B}N=null;break}}else if(y&&D)D(Buffer.alloc(0));else return Buffer.alloc(0)}function I(y,D){return oe.readBigUInt64LE(y,D)}function R(y){try{for(var D=0,k,N,B;D+4<y.length;)k=y.readUInt16LE(D),D+=2,N=y.readUInt16LE(D),D+=2,B=y.slice(D,D+N),D+=N,be.ID_ZIP64===k&&L(B)}catch{throw oe.Errors.EXTRA_FIELD_PARSE_ERROR()}}function L(y){var D,k,N,B;y.length>=be.EF_ZIP64_SCOMP&&(D=I(y,be.EF_ZIP64_SUNCOMP),r.size===be.EF_ZIP64_OR_32&&(r.size=D)),y.length>=be.EF_ZIP64_RHO&&(k=I(y,be.EF_ZIP64_SCOMP),r.compressedSize===be.EF_ZIP64_OR_32&&(r.compressedSize=k)),y.length>=be.EF_ZIP64_DSN&&(N=I(y,be.EF_ZIP64_RHO),r.offset===be.EF_ZIP64_OR_32&&(r.offset=N)),y.length>=be.EF_ZIP64_DSN+4&&(B=y.readUInt32LE(be.EF_ZIP64_DSN),r.diskNumStart===be.EF_ZIP64_OR_16&&(r.diskNumStart=B))}return{get entryName(){return _.decode(i)},get rawEntryName(){return i},set entryName(y){i=oe.toBuffer(y,_.encode);var D=i[i.length-1];c=D===47||D===92,r.fileNameLength=i.length},get efs(){return typeof x=="function"?x(this.entryName):x},get extra(){return u},set extra(y){u=y,r.extraLength=y.length,R(y)},get comment(){return _.decode(o)},set comment(y){if(o=oe.toBuffer(y,_.encode),r.commentLength=o.length,o.length>65535)throw oe.Errors.COMMENT_TOO_LONG()},get name(){var y=_.decode(i);return c?y.substr(y.length-1).split("/").pop():y.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return A(!1,null)},getCompressedDataAsync:function(y){A(!0,y)},setData:function(y){l=oe.toBuffer(y,oe.decoder.encode),!c&&l.length?(r.size=l.length,r.method=oe.Constants.DEFLATED,r.crc=oe.crc32(y),r.changed=!0):r.method=oe.Constants.STORED},getData:function(y){return r.changed?l:v(!1,null,y)},getDataAsync:function(y,D){r.changed?y(l):v(!0,y,D)},set attr(y){r.attr=y},get attr(){return r.attr},set header(y){r.loadFromBinary(y)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=u.length;var y=r.centralHeaderToBinary(),D=oe.Constants.CENHDR;return i.copy(y,D),D+=i.length,u.copy(y,D),D+=r.extraLength,o.copy(y,D),y},packLocalHeader:function(){let y=0;r.flags_efs=this.efs,r.extraLocalLength=h.length;let D=r.localHeaderToBinary(),k=Buffer.alloc(D.length+i.length+r.extraLocalLength);return D.copy(k,y),y+=D.length,i.copy(k,y),y+=i.length,h.copy(k,y),y+=h.length,k},toJSON:function(){let y=function(D){return"<"+(D&&D.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:y(e),data:y(l)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var nu=se((v2,tu)=>{var eu=ka(),Zg=Ra(),Ge=or();tu.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new Zg.MainHeader,l=!1,u=null;let h=new Set,x=e,{noSort:w,decoder:_}=x;t?v(x.readEntries):l=!0;function S(){let I=new Set;for(let R of Object.keys(i)){let L=R.split("/");if(L.pop(),!!L.length)for(let y=0;y<L.length;y++){let D=L.slice(0,y+1).join("/")+"/";I.add(D)}}for(let R of I)if(!(R in i)){let L=new eu(x);L.entryName=R,L.attr=16,L.temporary=!0,r.push(L),i[L.entryName]=L,h.add(L)}}function E(){if(l=!0,i={},c.diskEntries>(t.length-c.offset)/Ge.Constants.CENHDR)throw Ge.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var I=c.offset,R=0;R<r.length;R++){var L=I,y=new eu(x,t);y.header=t.slice(L,L+=Ge.Constants.CENHDR),y.entryName=t.slice(L,L+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(L,L+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(L,L+y.header.commentLength)),I+=y.header.centralHeaderSize,r[R]=y,i[y.entryName]=y}h.clear(),S()}function v(I){var R=t.length-Ge.Constants.ENDHDR,L=Math.max(0,R-65535),y=L,D=t.length,k=-1,N=0;for(typeof x.trailingSpace=="boolean"&&x.trailingSpace&&(L=0),R;R>=y;R--)if(t[R]===80){if(t.readUInt32LE(R)===Ge.Constants.ENDSIG){k=R,N=R,D=R+Ge.Constants.ENDHDR,y=R-Ge.Constants.END64HDR;continue}if(t.readUInt32LE(R)===Ge.Constants.END64SIG){y=L;continue}if(t.readUInt32LE(R)===Ge.Constants.ZIP64SIG){k=R,D=R+Ge.readBigUInt64LE(t,R+Ge.Constants.ZIP64SIZE)+Ge.Constants.ZIP64LEAD;break}}if(k==-1)throw Ge.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(k,D)),c.commentLength&&(o=t.slice(N+Ge.Constants.ENDHDR)),I&&E()}function A(){r.length>1&&!w&&r.sort((I,R)=>I.entryName.toLowerCase().localeCompare(R.entryName.toLowerCase()))}return{get entries(){return l||E(),r.filter(I=>!h.has(I))},get comment(){return _.decode(o)},set comment(I){o=Ge.toBuffer(I,_.encode),c.commentLength=o.length},getEntryCount:function(){return l?r.length:c.diskEntries},forEach:function(I){this.entries.forEach(I)},getEntry:function(I){return l||E(),i[I]||null},setEntry:function(I){l||E(),r.push(I),i[I.entryName]=I,c.totalEntries=r.length},deleteFile:function(I,R=!0){l||E();let L=i[I];this.getEntryChildren(L,R).map(D=>D.entryName).forEach(this.deleteEntry)},deleteEntry:function(I){l||E();let R=i[I],L=r.indexOf(R);L>=0&&(r.splice(L,1),delete i[I],c.totalEntries=r.length)},getEntryChildren:function(I,R=!0){if(l||E(),typeof I=="object")if(I.isDirectory&&R){let L=[],y=I.entryName;for(let D of r)D.entryName.startsWith(y)&&L.push(D);return L}else return[I];return[]},getChildCount:function(I){if(I&&I.isDirectory){let R=this.getEntryChildren(I);return R.includes(I)?R.length-1:R.length}return 0},compressToBuffer:function(){l||E(),A();let I=[],R=[],L=0,y=0;c.size=0,c.offset=0;let D=0;for(let B of this.entries){let V=B.getCompressedData();B.header.offset=y;let J=B.packLocalHeader(),te=J.length+V.length;y+=te,I.push(J),I.push(V);let $=B.packCentralHeader();R.push($),c.size+=$.length,L+=te+$.length,D++}L+=c.mainHeaderSize,c.offset=y,c.totalEntries=D,y=0;let k=Buffer.alloc(L);for(let B of I)B.copy(k,y),y+=B.length;for(let B of R)B.copy(k,y),y+=B.length;let N=c.toBinary();return o&&o.copy(N,Ge.Constants.ENDHDR),N.copy(k,y),t=k,l=!1,k},toAsyncBuffer:function(I,R,L,y){try{l||E(),A();let D=[],k=[],N=0,B=0,V=0;c.size=0,c.offset=0;let J=function(te){if(te.length>0){let $=te.shift(),ce=$.entryName+$.extra.toString();L&&L(ce),$.getCompressedDataAsync(function(pe){y&&y(ce),$.header.offset=B;let O=$.packLocalHeader(),H=O.length+pe.length;B+=H,D.push(O),D.push(pe);let K=$.packCentralHeader();k.push(K),c.size+=K.length,N+=H+K.length,V++,J(te)})}else{N+=c.mainHeaderSize,c.offset=B,c.totalEntries=V,B=0;let $=Buffer.alloc(N);D.forEach(function(pe){pe.copy($,B),B+=pe.length}),k.forEach(function(pe){pe.copy($,B),B+=pe.length});let ce=c.toBinary();o&&o.copy(ce,Ge.Constants.ENDHDR),ce.copy($,B),t=$,l=!1,I($)}};J(Array.from(this.entries))}catch(D){R(D)}}}}});var su=se((S2,iu)=>{var ye=or(),_e=de("path"),Xg=ka(),Qg=nu(),Tn=(...t)=>ye.findLast(t,e=>typeof e=="boolean"),ru=(...t)=>ye.findLast(t,e=>typeof e=="string"),em=(...t)=>ye.findLast(t,e=>typeof e=="function"),tm={noSort:!1,readEntries:!1,method:ye.Constants.NONE,fs:null};iu.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),tm);t&&typeof t=="object"&&(t instanceof Uint8Array||(Object.assign(i,t),t=i.input?i.input:void 0,i.input&&delete i.input),Buffer.isBuffer(t)&&(r=t,i.method=ye.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new ye(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=ye.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=ye.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw ye.Errors.INVALID_FILENAME();let c=new Qg(r,i),{canonical:l,sanitize:u,zipnamefix:h}=ye;function x(E){if(E&&c){var v;if(typeof E=="string"&&(v=c.getEntry(_e.posix.normalize(E))),typeof E=="object"&&typeof E.entryName<"u"&&typeof E.header<"u"&&(v=c.getEntry(E.entryName)),v)return v}return null}function w(E){let{join:v,normalize:A,sep:I}=_e.posix;return v(_e.isAbsolute(E)?"/":".",A(I+E.split("\\").join(I)+I))}function _(E){return E instanceof RegExp?(function(v){return function(A){return v.test(A)}})(E):typeof E!="function"?()=>!0:E}let S=(E,v)=>{let A=v.slice(-1);return A=A===o.sep?o.sep:"",_e.relative(E,v)+A};return{readFile:function(E,v){var A=x(E);return A&&A.getData(v)||null},childCount:function(E){let v=x(E);if(v)return c.getChildCount(v)},readFileAsync:function(E,v){var A=x(E);A?A.getDataAsync(v):v(null,"getEntry failed for:"+E)},readAsText:function(E,v){var A=x(E);if(A){var I=A.getData();if(I&&I.length)return I.toString(v||"utf8")}return""},readAsTextAsync:function(E,v,A){var I=x(E);I?I.getDataAsync(function(R,L){if(L){v(R,L);return}R&&R.length?v(R.toString(A||"utf8")):v("")}):v("")},deleteFile:function(E,v=!0){var A=x(E);A&&c.deleteFile(A.entryName,v)},deleteEntry:function(E){var v=x(E);v&&c.deleteEntry(v.entryName)},addZipComment:function(E){c.comment=E},getZipComment:function(){return c.comment||""},addZipEntryComment:function(E,v){var A=x(E);A&&(A.comment=v)},getZipEntryComment:function(E){var v=x(E);return v&&v.comment||""},updateFile:function(E,v){var A=x(E);A&&A.setData(v)},addLocalFile:function(E,v,A,I){if(o.fs.existsSync(E)){v=v?w(v):"";let R=_e.win32.basename(_e.win32.normalize(E));v+=A||R;let L=o.fs.statSync(E),y=L.isFile()?o.fs.readFileSync(E):Buffer.alloc(0);L.isDirectory()&&(v+=o.sep),this.addFile(v,y,I,L)}else throw ye.Errors.FILE_NOT_FOUND(E)},addLocalFileAsync:function(E,v){E=typeof E=="object"?E:{localPath:E};let A=_e.resolve(E.localPath),{comment:I}=E,{zipPath:R,zipName:L}=E,y=this;o.fs.stat(A,function(D,k){if(D)return v(D,!1);R=R?w(R):"";let N=_e.win32.basename(_e.win32.normalize(A));if(R+=L||N,k.isFile())o.fs.readFile(A,function(B,V){return B?v(B,!1):(y.addFile(R,V,I,k),setImmediate(v,void 0,!0))});else if(k.isDirectory())return R+=o.sep,y.addFile(R,Buffer.alloc(0),I,k),setImmediate(v,void 0,!0)})},addLocalFolder:function(E,v,A){if(A=_(A),v=v?w(v):"",E=_e.normalize(E),o.fs.existsSync(E)){let I=o.findFiles(E),R=this;if(I.length)for(let L of I){let y=_e.join(v,S(E,L));A(y)&&R.addLocalFile(L,_e.dirname(y))}}else throw ye.Errors.FILE_NOT_FOUND(E)},addLocalFolderAsync:function(E,v,A,I){I=_(I),A=A?w(A):"",E=_e.normalize(E);var R=this;o.fs.open(E,"r",function(L){if(L&&L.code==="ENOENT")v(void 0,ye.Errors.FILE_NOT_FOUND(E));else if(L)v(void 0,L);else{var y=o.findFiles(E),D=-1,k=function(){if(D+=1,D<y.length){var N=y[D],B=S(E,N).split("\\").join("/");B=B.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),I(B)?o.fs.stat(N,function(V,J){V&&v(void 0,V),J.isFile()?o.fs.readFile(N,function(te,$){te?v(void 0,te):(R.addFile(A+B,$,"",J),k())}):(R.addFile(A+B+"/",Buffer.alloc(0),"",J),k())}):process.nextTick(()=>{k()})}else v(!0,void 0)};k()}})},addLocalFolderAsync2:function(E,v){let A=this;E=typeof E=="object"?E:{localPath:E},localPath=_e.resolve(w(E.localPath));let{zipPath:I,filter:R,namefix:L}=E;R instanceof RegExp?R=(function(k){return function(N){return k.test(N)}})(R):typeof R!="function"&&(R=function(){return!0}),I=I?w(I):"",L=="latin1"&&(L=k=>k.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof L!="function"&&(L=k=>k);let y=k=>_e.join(I,L(S(localPath,k))),D=k=>_e.win32.basename(_e.win32.normalize(L(k)));o.fs.open(localPath,"r",function(k){k&&k.code==="ENOENT"?v(void 0,ye.Errors.FILE_NOT_FOUND(localPath)):k?v(void 0,k):o.findFilesAsync(localPath,function(N,B){if(N)return v(N);B=B.filter(V=>R(y(V))),B.length||v(void 0,!1),setImmediate(B.reverse().reduce(function(V,J){return function(te,$){if(te||$===!1)return setImmediate(V,te,!1);A.addLocalFileAsync({localPath:J,zipPath:_e.dirname(y(J)),zipName:D(J)},V)}},v))})})},addLocalFolderPromise:function(E,v){return new Promise((A,I)=>{this.addLocalFolderAsync2(Object.assign({localPath:E},v),(R,L)=>{R&&I(R),L&&A(this)})})},addFile:function(E,v,A,I){E=h(E);let R=x(E),L=R!=null;L||(R=new Xg(i),R.entryName=E),R.comment=A||"";let y=typeof I=="object"&&I instanceof o.fs.Stats;y&&(R.header.time=I.mtime);var D=R.isDirectory?16:0;let k=R.isDirectory?16384:32768;return y?k|=4095&I.mode:typeof I=="number"?k|=4095&I:k|=R.isDirectory?493:420,D=(D|k<<16)>>>0,R.attr=D,R.setData(v),L||c.setEntry(R),R},getEntries:function(E){return c.password=E,c?c.entries:[]},getEntry:function(E){return x(E)},getEntryCount:function(){return c.getEntryCount()},forEach:function(E){return c.forEach(E)},extractEntryTo:function(E,v,A,I,R,L){I=Tn(!1,I),R=Tn(!1,R),A=Tn(!0,A),L=ru(R,L);var y=x(E);if(!y)throw ye.Errors.NO_ENTRY();var D=l(y.entryName),k=u(v,L&&!y.isDirectory?L:A?D:_e.basename(D));if(y.isDirectory){var N=c.getEntryChildren(y);return N.forEach(function(J){if(J.isDirectory)return;var te=J.getData();if(!te)throw ye.Errors.CANT_EXTRACT_FILE();var $=l(J.entryName),ce=u(v,A?$:_e.basename($));let pe=R?J.header.fileAttr:void 0;o.writeFileTo(ce,te,I,pe)}),!0}var B=y.getData(c.password);if(!B)throw ye.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(k)&&!I)throw ye.Errors.CANT_OVERRIDE();let V=R?E.header.fileAttr:void 0;return o.writeFileTo(k,B,I,V),!0},test:function(E){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var A=c.entries[v].getData(E);if(!A)return!1}catch{return!1}return!0},extractAllTo:function(E,v,A,I){if(A=Tn(!1,A),I=ru(A,I),v=Tn(!1,v),!c)throw ye.Errors.NO_ZIP();c.entries.forEach(function(R){var L=u(E,l(R.entryName));if(R.isDirectory){o.makeDir(L);return}var y=R.getData(I);if(!y)throw ye.Errors.CANT_EXTRACT_FILE();let D=A?R.header.fileAttr:void 0;o.writeFileTo(L,y,v,D);try{o.fs.utimesSync(L,R.header.time,R.header.time)}catch{throw ye.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(E,v,A,I){if(I=em(v,A,I),A=Tn(!1,A),v=Tn(!1,v),!I)return new Promise((k,N)=>{this.extractAllToAsync(E,v,A,function(B){B?N(B):k(this)})});if(!c){I(ye.Errors.NO_ZIP());return}E=_e.resolve(E);let R=k=>u(E,_e.normalize(l(k.entryName))),L=(k,N)=>new Error(k+': "'+N+'"'),y=[],D=[];c.entries.forEach(k=>{k.isDirectory?y.push(k):D.push(k)});for(let k of y){let N=R(k),B=A?k.header.fileAttr:void 0;try{o.makeDir(N),B&&o.fs.chmodSync(N,B),o.fs.utimesSync(N,k.header.time,k.header.time)}catch{I(L("Unable to create folder",N))}}D.reverse().reduce(function(k,N){return function(B){if(B)k(B);else{let V=_e.normalize(l(N.entryName)),J=u(E,V);N.getDataAsync(function(te,$){if($)k($);else if(!te)k(ye.Errors.CANT_EXTRACT_FILE());else{let ce=A?N.header.fileAttr:void 0;o.writeFileToAsync(J,te,v,ce,function(pe){pe||k(L("Unable to write file",J)),o.fs.utimes(J,N.header.time,N.header.time,function(O){O?k(L("Unable to set times",J)):k()})})}})}}},I)()},writeZip:function(E,v){if(arguments.length===1&&typeof E=="function"&&(v=E,E=""),!E&&i.filename&&(E=i.filename),!!E){var A=c.compressToBuffer();if(A){var I=o.writeFileTo(E,A,!0);typeof v=="function"&&v(I?null:new Error("failed"),"")}}},writeZipPromise:function(E,v){let{overwrite:A,perm:I}=Object.assign({overwrite:!0},v);return new Promise((R,L)=>{!E&&i.filename&&(E=i.filename),E||L("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let D=k=>k?R(k):L("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(E,y,A,I,D)},L)})},toBufferPromise:function(){return new Promise((E,v)=>{c.toAsyncBuffer(E,v)})},toBuffer:function(E,v,A,I){return typeof E=="function"?(c.toAsyncBuffer(E,v,A,I),null):c.compressToBuffer()}}}});import{execFile as K_,spawn as $_,spawnSync as BA}from"node:child_process";import{promisify as J_}from"node:util";function Y_(t){if(process.platform!=="win32")return!1;if(t0.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(t0,"").toLowerCase();return V_.has(r)}function n0(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 dt(t,e=[],r={}){return $_(t,e,n0(t,r))}function r0(t,e=[],r={}){return Z_(t,e,n0(t,r))}var V_,t0,Z_,_n=Ve(()=>{"use strict";V_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),t0=/\.(cmd|bat|ps1)$/i;Z_=J_(K_)});var ch=se(Ne=>{"use strict";var M=q;(function(t,e){let r=q,i=t();for(;;)try{if(-parseInt(r(1558))/1+parseInt(r(1360))/2+-parseInt(r(1794))/3*(parseInt(r(1800))/4)+parseInt(r(1084))/5+parseInt(r(1542))/6+-parseInt(r(1693))/7+-parseInt(r(1513))/8===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(So,265877);var qE=Object.defineProperty,GE=Object["getOwnPr"+M(559)+M(969)],rh=(t,e)=>function(){return t&&(e=(0,t[{aFRrA:function(o,c){return o(c)}}.aFRrA(GE,t)[0]])(t=0)),e},jE=(t,e)=>{let r={VoIJj:function(o,c,l,u){return o(c,l,u)}};for(var i in e)r.VoIJj(qE,t,i,{get:e[i],enumerable:!0})};function WE(){return X0||(X0=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function KE(){let t=M;return Q0||(Q0=[IDBCursor[t(1503)+"e"].advance,IDBCursor[t(1503)+"e"][t(1556)],IDBCursor[t(1503)+"e"][t(1556)+t(1285)+"ey"]])}function $E(t){let e=M,r={gBbnN:e(972),GpEbP:e(1259),ortgw:function(o,c){return o(c)},alOqE:"error"},i=new Promise((o,c)=>{let l=e,u={apyQY:r[l(1546)],XBzmL:r[l(1561)],jBiwX:function(_,S){return r[l(679)](_,S)},AWpuo:function(_,S){return _(S)},igcNn:function(_){return _()}},h=()=>{let _=l;t[_(1729)+_(1246)+"ner"](u[_(1809)],x),t[_(1729)+_(1246)+"ner"]("error",w)},x=()=>{let _=l;if(u[_(406)]!==_(520))u.jBiwX(o,u[_(490)](Nt,t[_(1022)])),u[_(1710)](h);else return _0x44f359},w=()=>{let _=l;u.AWpuo(c,t.error),u[_(1710)](h)};t[l(1780)+l(514)](l(972),x),t[l(1780)+l(514)](r[l(1540)],w)});return i[e(957)](o=>{o instanceof IDBCursor&&sd.set(o,t)})[e(430)](()=>{}),Ao[e(986)](i,t),i}function So(){let t=["Afvft0O","shLMy3e","vKjduu0","yKHkuMW","CMvHzhLtDge","x0vysvnu","v2D5z1C","AMP5rM4","v2LUzg93","q29UzMLN","uvDpDgS","Aw5Lza","BwvKAwf0zwW","Exr4tvO","Bg9gEvy","Efrurw52","uuXwuwW","wg5iAha","BMDuAw1LCG","ze1rquK","wKj1AgW","BejqwM0","t09oAw8","DMTXvvm","y29UC3rYDwm","rxv5C0i","yw5Hz2vY","Aw1gyxG","ywnOzwq","v1bjq0O","u0Xcv3m","B25szwnLAxy","shvoqxi","EgDUCeS","CMvJB25Uzwm","DevjtKu","Dgfmqxm","DxnzDe8","yw1L","sePovLy","EfvZzuvUDG","Cu5qtKC","u0ngrMq","t1bftL9fuLi","CNnVCKzPBgu","Ec1TC2CTy3u","q0Xpu0ve","CMTLCKDSB2i","rg5WquO","ywXSq3vYC28","Ahr0Chm6","qxH0wue","BwLUAvbYB2C","yMfbyMu","B3jL","BMnVzgLUzW","Bhm6ia","turkrva","BMnLq2XVC2u","quXm","x2LUAxrhBg8","A0XpuwC","y0juqvC","x2XPC3rLBMu","C3rHCNq","wuXvsMS","qwLesLy","vfbWs1C","s1fiBxi","zgvIDwC","x2LZv29YA2u","B3bLBKrc","BMvJDa","BwvY","x2TLEvbHDgG","DMvYC2LVBMm","x3nLCuLK","uNj4q2K","ChjVDg90Exa","D2vI","DhjPzxm","A2v5CW","vgLWtK0","C3rYAw5N","Aw9U","Dhrhs1G","yK5Ts3y","uhfXs0G","mJC5mZi2nhrxzgLsCq","uxbUDfe","v2znqum","twvZC2fNzuu","zxb6Beq","AwXLtMfTzq","D3jPDgvvAw4","z2v0","BIWGAg9ZDg4","EujYC0S","Cg9PBNrbBMq","uhfsrg0","A3fpr1y","mxW0Fdy","DvjQwui","v0zuENa","ign1CNnVCIa","qK51wMi","x2rPC3bHDgm","u2nSuvm","yxrLq291BNq","zMLSDgvY","CMfTugfYyw0","AwXSihvZzsa","ywXvExG","rgvKAwnHDgu","zwz5rvi","ywXpCuu","Dw5RBM93BIa","mJaXndKWmNvABK9WBq","BwTXthe","rxL4C3C","Bg9N","z0jIBK4","wM9MA24","ANPMv3O","ELLqB2O","B3bLCNr5","zgv2AwnLx2K","zwPwzuu","y2vZC0HHBMq","u0j0sxm","tuvtu0fhrv8","y29UDgLUDwu","qvHkyMm","mZaZmdm2z2nUDfnO","zxjFywnRx20","tNvMCxq","r3bfyLa","suv3s2i","vw9eruy","BMCGB3iGyw4","u0nstg4","x21LC3nHz2u","C2LVu2S","x3jLy29UBMu","BwLjt1m","A0vuBLO","sLnptLa","CM92AwrLigi","DhjPzxmGCMu","u2HHCMvKv28","rufkCfe","Dufmzxm","u2vYDMLJzvC","C2DMquC","uLzywgi","tKrLrxu","BM5Ly3q","AwDfDvO","y3vYCMvUDeK","y2HLy2TdDxi","AgLyDeG","uLzNwKq","ChjVDg9JB2W","B25pCgvU","vfHzthm","weXmq1a","s2H1wK0","tuXXvhi","yuzjA1y","mNWWFdf8nhW","ufDXEuy","BxnN","zwrgzwq","vffODgO","y2XVC2uSihC","y3vYC29Yx2y","twLZC2LUzYa","rwnlqw0","tfn2su4","q3zlBhK","r2Pqwu4","sMz5Axm","Cgf5Bg9Hza","Agj2uNC","vxHNv1G","uvnTsKK","q09otKvdveK","u3rYyxrLz3K","CLDlt3K","CKjkzha","qwfZC1O","A2v5","zvvYBa","B0zlvMi","B25fCNjVCG","DufJwfG","tMPMCw4","zLfeCgS","A0TbqK8","zw5JB2rLrNi","tffsq08","rg9quu0","EKHSA3K","q2fnrvm","x2fKzfDZtgK","v1fTEue","D21LthG","Aw5N","Cg93","whPSwuO","DMDqrLq","tfv5DM4","DLHwy2i","Dg1oveu","werIvMW","uKzIzuq","r21tC1m","zNzMAeK","y3jLyxrLuMu","B2LUDfjLywm","y2n5su8","rwfgtgK","weDnBuO","DgvjEhu","y01JB1m","qMPtrvq","Dg9oDw1Izxi","AwrI","CM92AwrLige","DMfSDwu","BNnWtxe","B3jOzue","u25YwgS","vgfN","vuv0D0G","ELH1sK4","ELP3Bxi","tK9gzeW","mxWZ","C2v0zgi","x2LUAxq","zNjVBujPDhm","Ee1Hvw4","DLzJCfm","CMfUzg9T","s0v6Cgi","zwrPyxrLBhK","oxWWFdj8mxW","CMfNzvn5BMm","uLLTC0W","AMXxB0C","x2HHBMrSzu8","reiGzMfPBgu","x29UugfNzu4","BvLqDwG","z3ruwLO","sezHAvK","y29UBMvJDca","C3vIC3rYAw4","zw5HyMXLqxu","D0fiAM8","BwfW","zu1JDxK","wKjKy08","Dw5KzwzPBMu","CNzHBa","sKPczNi","qwPoAxq","odm5ntfsvhDfDvG","x3jLBw92zvC","ihrYEsbYzwm","A3nwruO","zcWG","B25SAw5L","ze91Ceq","z2vrDwv1zuW","wwf5DM4","x2nSzwfYvgK","AhfWEhG","DMvUDa","wfvmyuS","shzcrue","r1v1BMC","zw5fDMvUDa","yxKSig5LDhC","AwDJtM4","D29kAvK","t2jsq0m","zxjFAxnFywm","x2zVCM1HDeu","zgzdseO","AezdrLu","ruzcBu4","yLDvzLu","A1HxyM8","wvr2sKO","C3rVCMu","t2PvBhC","x2LZtM9Kzq","r0Hiv0i","wvnLu3e","wvn0wMG","DuzNAeS","rfHHC2O","CMvTB3zLrxy","zePMy3K","x2n1CNnVCK0","vgXmzha","u0jswfO","D0vQsfG","tezJzNO","zhLpwLy","Cvn2uhu","B2zMC2v0","yw1Ur0O","B2nRzxq","z2u6ia","z01ZqxO","Ec11C2uT","EvDNsuS","zxnwvha","x2LUDgvYDMe","wvbMAva","zxj2AwnL","q291BNq","z05JsxO","Fdr8mxWZFde","CgDIz08","rgjeBhC","ywDLu2HVDW","DMDqu00","u3zuy2W","Bg9Nsurhzw4","A29UDgu","yxbWBgLJyxq","B25ozxr3B3i","z2zfshy","uwD6zva","zhHtsLu","AgfvDwG","A3jKsuS","B3nLza","sxzKzfO","CwLUBK0","t1DVCuy","t2jQzwn0","BM9Uzv9UB24","BNrLCG","y29Kzq","A0Xnywu","se9TB1G","Eu5vs3C","s2f6tK8","BNH2A0y","yw5Nzq","ywrKrxzLBNq","CxPevgi","x29UtwvZC2e","x19LC01Vzhu","CeTiwg8","C1LAA08","y3jLyxrLq2W","tLf0Ahq","ysbTDxn0igi","AxnrB1nby2S","v1jZu0W","EMX3Bue","ExH1BwK","BwXLEKy","mJy0m0ffrMDTCa","zgvMAw5Luhi","CMvKDwnL","zxjFBxnNAwq","zw9ZwMq","t2T5Cxy","mtyWngrwzevSqq","uLfOveS","sLHiEgK","DMvYC2LVBG","CgfYC2u","CgfNzxnOB3C","BgLTAxq","DwnfA0C","Aw5KzxGGB3u","yxb5uvK","oxW3Fdz8mta","v1PvDxq","A1nPwxu","Fdn8nhW2","sefOs3y","tuzQuMW","zM9YrwfJAa","Exv3C0m","x2rLyNvN","Dhr3Awq","x2HHBMrSzva","wujjAgC","x0rctMfTzq","zvj5uNa","y0TkzuC","A1jTuKe","AvnHv3O","qNjPzgDL","zxjYtxnN","zNDZxZeUmc4","D1zMy2O","ru9kA0S","yMXVy2TLza","z2v0q3vYC28","pxv0zI04","z1LUBeC","B25Uzwn0Aw4","zMzLCG","ChbtuMS","BLDVs2K","Cu1AExG","x25HDMLNyxq","yNL0zu9MzNm","tw9KDwXL","x2LUAxrqCM8","C2nYAxb0","tNnwtK8","q2f6teq","z2j2ExG","z1rUDwO","zgrjrcWGzgu","ihn1y2nLC3m","Dhbcsvm","ufvjweC","yNL0zxm","Du9or0q","Dvndy2O","y3ruAw1LB3u","whfQuuq","zffkqu4","thLUwNi","zxbPwfa","C2v0u3rVCMe","tKvizve","r3rlDhy","DMPsD2S","CgLUz0XVC3m","AgvHzgvY","yMrFzgLK","sMPUq2q","EMXdt24","BMvRCNC","reD0sfO","Awnmq3u","AwTSr00","B1zduvq","B25TzxnZywC","rujysNO","rvjLDwK","ywDL","ywrKCgW","A0TmEK4","EKfAtu0","zufJAW","rNniBhC","vxfMENK","te9Aweq","BhfSvKq","zgvS","ENfzyLu","C2vYDMLJzq","Ec1TC2CTCw8","tw9Huva","yNPfB0m","mNW1","ywDLrxzLBNq","s2XKu2O","x3bPBMDmB3m","BMXsz3a","ugHWt1i","ChvZAa","Ahr0Ca","ANPjrfO","D0HtENm","DhLWzq","n3W4FdeWFdu","AM9yrfO","DgHHBIbSB2m","y09Wzw4","sLPcwuC","CgLUz1rPBwu","tfDoshG","DufsEgW","AMrmsey","AuXAEva","re9bt2K","B25JBg9Zzq","Aw47y2HHCNm","CNzHBfzHBhu","DefntK4","ywnOzwqSihC","B1vNu3e","DxHZDfi","B3bLBIa","sgzKuu4","tLnxBMq","DhDVCMTdAge","CMzuswm","DKPwEhq","AMnrzMK","yNL0zuXLBMC","zMLN","ywrK","zMzmAw5L","ignVzgu6ia","uMf4qLi","wej6BuW","uuHjwvK","vKHKsMu","svvNqNC","BeHHBMrSzxi","Dev2zw50","AxjsCLu","B3PuzMS","ugzHuNq","qwfdyu4","B2zM","D2jpDhm","y29UDgv4Da","sNvVBwO","B25VCgvU","BMHcvvO","B3bLBG","Bg93","txHWy3a","DKL5s0K","rwrpqLO","sfjRt2q","t2j0D1C","mdaWmdaWmda","y2f0y2G","mxWWFdj8nhW","yu9qBxC","z3DKruC","wwXzENi","rxzzrhG","qLbHAgq","t0fqwwu","DgLTzw91Da","zxHWB3j0CW","BeLOwxq","s1vRtg4","B2nRzxrgywK","rejJC00","zxH0ugf5Bg8","r2DXD3G","qw1VDw50","BuPdrLa","yuTKEKK","AurlrKC","CNjVCK1LC3m","z2v0u3rVCMe","y29Uy2f0","z1rPBwvVDxq","yw1nuum","DxPVC0O","zcbLCNjVCI4","m3WYFdf8mhW","zgXABM0","s1fkDxu","DxPLEeG","yNvMzMvY","re9JuKK","veDNBM8","vwXABhK","yxnZAwDU","De1HBMfNzxi","rvfXEw4","tgXcvMu","ywXS","tvnbD1e","yxv0BW","v1DdyNq","yMfSu2nVCgu","vwDMBKq","DwDezfm","yMfJA3vWigu","ugvZsee","wfHAAgi","u0LgCKq","sKPYyMG","r0PvsKq","u3nXCwK","sLfvr2O","qMDHsMe","A0T3y3y","r0nczwG","wwLLCe0","C25jBMG","tMfTzq","qvDWDw8","x2LZqNjVD3m","Dg9iyxnO","uxPvCeC","B2P3Aw4","igzHAwWSig0","rxjJswe","EenUDfm","AeHZBM8","B25LCNjVCG","uxPYswe","C0zZAgG","DhbizwfKzxi","Ef9MCM9UDgK","tg5lr3y","tg9JAW","Cw9Zx18","C0XPC3rLBMu","ufbms3e","yKX5tva","qvHfq2W","mxW0Fdj8m3W","qwjVCNrfCNi","rhfyvxe","tgLZDgvUzxi","z0f6rK0","rhz6qLa","B2PdBha","sNHtz1K","B25tDg9Wsw0","thLLsxu","DxnLCKLW","wNPkBM4","CuH4Cwe","vfzJseS","BwfZr3q","uMvHzcbWyxm","x3DZ","CMfTzq","yw1Lu3bHy2u","DvjotvO","yw5ZzM9YBvq","DeLUDgvYy2u","C0jf","vMnkqui","o2nOyxjZzxq","ywnR","zMXVB3i","sePNwLG","ue9gvNa","AxnrB1nnzxm","zuv6v3K","qKjZwgy","ChrVCG","Cw9Z","ywnRx2LK","txrlDgy","veXVuMC","rLDt","x2vUzhbVAw4","B0ftEgW","rhvZyve","uuHvtei","BNPlAK8","zMLUza","CMvJzxzPzwq","DLbACKu","D1ziuvi","rwnwtMC","B3bLCNr5tMe","ihzHBgLKihm","Dw5ZAwDUzwq","twvkz3C","rhHXrwu","Bfvhvxi","BePQDNu","DgLUzYbZzxi","x3nLBMrby2S","CuToy3y","y3vZDg9Tshq","ywXPzcb1CMW","DxbKyxrLq3u","AefJA01LC3m","uMvJB25Uzwm","t2v4zeK","vNHxChm","su5LBhi","AgnzB3G","y291BNq","CgLUz19VBMm","AwXLx25HBwu","B0fhzei","x3jLywr5q2W","rNjVBNrPzxi","A2HzvMi","DxDOv3m","BMrWB2LUDfq","C3rYAw5NAwy","EM9SyLK","Bwf4tg9ZC0m","CLbmEwu","Aw5gBhy","rhjmt0S","x3bHDgHlzxK","zMr5wM4","ExfyDu0","yuPqyLq","zfLsCMS","BwvZC2fNztO","x29WDgLVBNm","wg9ryvu","AxnAzxjV","wwPItLq","x3DHAxq","qwXrDw0","tufyx1jfvfi","Ee9wAeK","rKLmrv9ot1q","BwLZzq","q1nQAfm","DMPny3C","Bwf4twvZC2e","DgfYz2v0","CgXLyxnLiha","v2XeAMi","AenSB3nLrxy","DgrYwuW","yMvqCMO","B2XPBMu","ywzL","Fdj8mhW4Fdu","B1zgyNO","y29SBM8","Dg9cExrLC0W","zMzMzG","C3bSAwnL","Bwu6ia","rLv0Cey","AuHHs2S","yNfgs0u","tNbRC24","t2Dethy","DhjHBNnHy3q","Bg9NsurozxC","y3vYDMfSDwu","BwrVC0C","B3nLrxzLBNq","wwvyAui","ihrPBwvVDxq","CKPKzfm","ywrKq291BNq","tNzurhC","DuzJB1y","swr1ueu","Dg9tDhjPBMC","vuXsAhe","Bwzit2O","twnPr2y","tu93tei","tgXVvvK","we1YsK8","DMfSDwvZ","tLjhBge","rhfhwei","yxjYyxLIDwy","wfvPEhq","wvHUwem","v09Nvhu","vffnEK0","igXHCMDLCIa","B3jRzxjhBg8","BeHjD2O","u2HsBfK","wKDdAuq","uxvLDwu","t3bLBKv2zw4","uLr1rgy","CYbPBNn0yw4","vMHesxu","zwnVBM5Ly3q","qu1Uv1q","s1nNzue","zwvpuuy","BNv5s0m","AuneyLy","Be1MswK","C29YDa","suvtx0vsuK8","EsbJBg9Zzwq","B3j0z3C","Evjhsfe","yuTMCgq","ywLzz1G","BfjtENe","sfnzDMG","ywrKt25L","wuHkBg8","zxq9DxrMltG","zgXTtvK","C2v0sxrLBq","DMvY","CYbHBhjLywq","z2HozgW","vKLhAfu","z2vtEw5J","rLbVDgi","DNDkCwu","BNrfBMrWB2K","yKLiq3u","AxmGDw5Kzwy","vgLTzw91Da","ALvzCfG","v1jmz1K","rxjYB3jdB2q","vevxCvC","x29UvgLTzw8","EgfKDfO","wfDYAg8","CMfREuG","CMvJzwL2zwq","yxKSihrYEsa","BgLZDgvUtMu","BeLNwxq","vxbsCNe","zw50","ANDkuee","q0rVtKe","CerXvha","B2fK","qwrXzK8","yNjVqxy","seLfseu","BKL3Bg4","wLjmt20","Ae1LC3nHz2u","r2rUwKK","suP5Bee","rMPxru8","DNHvDgW","tg9Nsuq","tMrHAg0","x29Uq2XVC2u","qvDVt08","BwLUzW","z2v0qwXS","EMv3sg8","wLLwzhK","CNnVCL92ywW","Dg9mB3DLCKm","CMvZzxrfBMq","x3bPBMDqB24","BML0AwfSAxO","nxWY","BezSDxnO","ruvwBKm","DwTXtK8","zNjVBuj5Dgu","CMv0CNLdB3u","BwD5AwC","zxjFDhrS","BgLUzq","vevVreK","DeDuAKy","yxv0B21HDgK","AMTHEM8","y2XVC2u","vMzcBei","whDsvgy","CurTAei","y3z4wu8","AvHqCeG","ihzHBgLKigq","whDXuwm","CMvHC29U","DgfIyxnL","DwfnDLq","AMvJDfn0B3i","C0Hsuvy","uLfgshC","sgDxvgC","ywHTwK0","Cg9PBNrdB24","yNDxs3m","qu91rw8","B3jLtMfTzxm","suDvwKG","y3jLyxrLt2i","uhnjquO","vwfWug0","DgLLCKPtt04","jMPZy2fSBgi","qLH0BuC","AwDHDg9Yt24","x21PBMLoyxy","BfrPBwvVDxq","zsbHihn0CMK","rNPSuwW","BKXAuxK","Du9kvKO","BLHhzKC","rerIEwm","vvPYCMq","D3HJquy","r3DywLa","Bwner1C","yKnRB3G","vff3r3q","zNLrCwO","Bwv0Ag9K","BLDzBg8","Be1zBMi","ywjVCNq","BgvUz3rO","tg9NsurozxC","CgLUz09Uy2u","rwHUt1i","CK9uuxK","yxGGCMv0CMK","sLjuCMe","CKrPyNi","CMvTB3zLq2G","v05ztLO","x2LZtwLUAvq","zwn0","yMjQBgG","y3rxtvK","tMn1EuG","qKzsBKi","x2n1CNnVCKy","zxjFCw9Zx2e","y2LpCNi","vxjHCgG","DKrXq0m","s2nuCMW","uvDPsfa","z2vjBMzVu3K","tgfwzKO","DhDXAgi","C3jJ","ufziseC","BeLRwMe","r2DArei","BgLUzw5V","qxHzD2y","y3r4","t2z0C0W","mxW0Fdn8mhW","B3zmB04","tKjSvvO","q2fACei","B2nRzxrtDwm","y2HHCKnVzgu","CMvUDevUzha","D1DAvLm","Aw5JBhvKzxm","AgDjEMe","zvrvr28","BK1NAhC","B3jRig9MzMW","BwfUDwfSihi","CwrJuvK","tvPeDeO","BMCGzMfPBgu","AKHKyNO","CNrHsxi","C2jQuM8","C2vYDMvYvgK","EwHcv2m","s0DeB2G","CM9YrxzLBNq","CLf5DMK","vwj4rgG","D3m6lY8","y29UBMvJDa","mdaWma","ALDpq28","DK9lyMq","AhHhDeq","tNrbu1u","zM9Yy2u","nhWZFdb8mxW","AxnbCNjHEq","ihjLy29UBMu","ExbpD1G","yxbWBhK","zfDHqwK","ufnADxu","z2v0q3vYCMu","x3nVy2TLDa","Aw9wzva","zMLSzw5HBwu","ihrPBwvZ","Bwf4uMv0CMK","te1mzw8","EKXVCLa","AM9PBG","EgHhAKG","Auf4vwC","CgvYC2LZDgu","qNPwwwS","u0nZwxO","uePvr24","tKfusvzfx0u","DxrMofDYAxq","zw5XDwv1zq","tLjWvuK","q0v1y1O","CYbWyxjHBxm","qKfVzMq","zxfnv1K","t3HmBhu","sNPrrhG","x2rItMfTzq","wuHVtfq","Ae9Wzw5fDMu","EhPhvge","AxLYAM4","A216uhu","EhLHrgC","yMLUza","AgfUz2u","zgvJB2rLzey","quLbCfe","t1bftG","D1nQwu8","vxbKyxrLq28","rMvSBuq","wMTutgm","zKDkqKm","BefXy3a","zwvKzwq","EuLLuwG","zw5JB2rPBMC","EhnSy0u","tKHKA3K","BuzpCva","vKfAq1m","zvj0v1G","rvjst1i","tujJDLe","t3HrA0m","yMfOv0y","ywXSB2nvBNm","DcbSAw1PDa","sMjqrgm","whvNs0y","Ahfyqw8","tfvxq3i","zg9Uzq","uwjswfm","zvHkDwK","uLfNsLa","swfStwy","zurrrMq","wKv1ruC","EeLjwLu","wwLwC0S","uK1NvwW","x3bPBMC","q3vZDg9Trxi","x194x21Zz18","z01Quxu","y2HnyxHdB3u","C3rLBMvYCW","Dxrjza","txDHEeu","z3z0ruC","DgHLBG","rwP1zhK","wgnVyLK","vwjXAMW","zg9wuNu","y2XVC2veqG","CgLUz0LUDgu","AxjLza","DgvmB2Djre4","qxrrz2G","x3DZsw5ZDge","sNj1q1K","BwvZ","v2nWs1m","q0Xpu0LorW","C3vJy2vZCW","BwvZC2fNzq","uNbtv0K","ww5VDLG","yvLTzg8","rhHLy0q","tuP6veS","zNjHBwvuExa","sfvYD2i","rND3EwK","ugP4tMm","wxDprNe","q3vZDg9Tq2W","C0nVDw50zxi","C2v0","DeLK","DxrVuMvJB24","x2rPC2nVBM4","CMvZzxrdB3u","EM1XCMi","wu56BMK","zxrxB3jRq2G","Efj3zMe","Dw9Vs3q","Dg9cExrLCW","BMvY","AxnszwfKEq","Cgf5Bg9Hzfq","D24GCMvHC28","Cg9W","DMLJzuLeig8","y29UBMvJDgK","vfjQtwu","y3jLyxrLrwW","Efb2DKO","Dgv4DfbHEwW","tKHOAMi","re5JDwy","BwvZC2fNzv8","yNvMzMvYzwq","B25dBg9Zzq","zwvVC3C","z0zLz3u","wwPwCu0","B2zMBgLUzq","sefUB0G","zxf1ywXZ","C0Xf","turhqNC","wgXOyNm","CMvZDwX0","teviwKO","zgf0yq","x2nSzwfYugK","DvPkB2S","l3DZl3yY","yLv5uxq","se1rCNm","BMrLEa","yNL2B2u","BuHuAfe","s2nPqwW","Chv0","DgLTzw91DcW","DLbosgO","C2DPza","t25OD1K","CxPerxC","yxbWzw5Kq2G","C2zJthG","tfvKz08","zNbZA2C","A3rzuNe","vgDywM8","yM9L","DhjPBq","yM9KEq","C1fbDwO","B3jzDNC","EffMvNK","swTWr04","zxmGCMvHy2G","vLbjyNi","x2DLBMvYyxq","zNjVBNrPzxi","t0rLrw4","BNrbBMrvCgq","v0vsswG","u2rsthe","x3fVC0rc","AgvHzgvYCW","sMXIDwu","yKL0sM0","y2XLyxi","q2vwyLe","Aw5KzxHpzG","wwDvAwy","y2fSBa","C3nHz2vfDMu","CuLNEuK","yvzlqKS","CMvHzhDYAxq","y093r24","v0fOz1G","ywXty29Wzq","y3vYC29Y","D2fZq2XLyw4","q3jLtuu","DvzdCeG","tgrItKK","y3jLyxrLtwu","y0HuzKy","mJy1mti0nvrrtLfyEG","zv9ZDwnJzxm","tg1hzLq","x29UrxjYB3i","B3jpBMXPBMu","tgrVsgS","suLiBhm","BhjPuNi","D3nZoI8V","DMfS","vungCgq","x2LZsw5PDa","Cg12s2K","AwXK","D3jPDgu","tefMqLi","BM93","ENfpCeS","sM5hCvq","x3vYBa","B1HXsNu","A1HWDeu","ywnRDxbfBMq","ELbTBvq","q09oveLovuu","q29Kzq","ugzzCKC","DMDrzxq","CMvHzfvjBNq","u2L5Ee4","uNfWD3i","C3vIyxjYyxK","CMfcrw0","B0LxwwS","B2jQzwn0u3q","DLzeAee","shL5Efi","zLfrAxy","D2HirvC","BNruCMLLC0m","AvfHCeG","BKXPBMu","AMHetM4","zw1PDa","BMv4DcGPigm","rwLQC1G","Dxjqze0","Cg9mB0O","x1fVu01HBMe","z29PBMCGyxC","re9wDey","AvzQDhu","tLbtC0y","BxnNsuq","ihbYB3rVy28","zw5KCg9PBNq","ChP3vLe","D2LSBfjLy28","CxDkEKy","DfDhEu4","C2zes2q","y0nyDwu","C29Tzq","y29UBMvJDfm","yw1LoIa","z2v0sxrLBq","D3HmqxC","x2n1CNnVCK4","B25tDgfYDfi","q2PXy0O","n3W1Fdb8mxW","x2HHBMrSzvi","A1fPvvK","ALnjDgS","C2fNzq","ywDLsgLKzq","teHcBva","AevYCM9Yrxy","zgLZywjSzue","z2vY","yKfoBeS","tunlyuC","BMjjzey","v0vHyuq","Aw1lu28","CMvZB2X2zq","wvvOsuW","rgn4svq","B3vUDa","DuHWCue","t05OBeC","s0r5D3O","rgngrK4","z2v0s2v5","EvbXyNK","C1vRsfm","tw14EhC","BhzSCwK","EKnLDgC","CMvZzxruCMK","BePeAKK","DLfTvKu","BMfTzq","uejXuei","yuXzuvm","zgvSzxrLrge","v2vIu29JA2u","s0H5zuO","AK5stfC","A2HbEfK","zw50zwqGDhK","C2vUza","C0rXCeW","id4G","zeXhrhq","vLnWu3G","nhWZFdf8mhW","CM92AwrLihy","y3jLyxrLt3a","sfLpuM8","zNjVBu51Bwi","ig1LC3nHz2u","zvrXBve","AxnFywnR","Ag1PuuS","thHmq1O","y3vYCMvUDeu","vMDose8","AgDzCeq","zw5HyMXLuw8","ywWGy3vYC28","yxnAD0W","tNDbrNK","tNn6qMC","CgjICdi","yxnL","C2DSuMS","y3vYC29Yx24","zufyu2u","qwzVENO","svvgv3O","rMXlwhy","CePUvhK","DgvZDa","CgfNzwHPzgu","EwLVCKW","DKfIyvu","Eejbrxu","ywfqv1e","lcbTyxGGCMu","zNvUy3rPB24","Bfn5BMy","Dg9Y","zMD4EMi","u2vXsuq","wM1gv0m","x2rLC3rYB3K","Dhjktxe","DK1YsLC","rg5OExe","zxjHDg9Y","wgfOyNu","zw50tgLZDgu","BhDQyLm","zNH5tLm","m3W1Fdb8mNW","uMDjvKW","uvj3tgi","EKroA0u","uML0A2G","DgPAvgq","qKLJzgm","A05tC2y","r3PdCKm","vhvSyuu","ufD1BLu","r3DetM4","rLPprwW","EunJsxe","BgvY","r3PPtfu","AuXYEfK","Axn2sKO","ChbL","AxnmB25N","zw5NDgG","wuPcr3y","Aw9Ul2PZB24","yNHuu2S","vNH4v0y","BePntgi","uLnYDg8","D1D1sNq","q2H5wgi","ywnRtxnNswq","su5tvefova","q3nmC0q","Eg9LqKO","zcWGDw5RBM8","C3bSAxq","y1v3thC","uhjPBwfYEuS","AgvKtwf4uMu","quXpqwO","AKHVrwy","x3bYB3rVy28","qxfmzNu","t2zSAMS","y3jLyxrLrxi","x3bYzwzPEa","C2vUzf9Hy2S","DhjHvgK","CvvrvKO","zxjFCw9Z","rgzcv0G","x29Ut3bLBG","z3ngsK4","wfbbqwe","y2vQD20","y3vYC29YlNm","BMv3vMvYC2K","wLPht3q","y2HLy2Tszwe","B25ywwe","DxjS","zgLZCgf0y2G","CvbWtu8","C2TIDuO","Axnby2TdBgu","zevYvKO","D29ewgi","Eff2thO","AgLNAa","C2vsEMi","s0Xuv2u","A0LTrwy","rKnvCwm","rMDPBwW","Dg9cExrLC0i","DwXZqwK","igfYCMf5yNu","CMvWBgfJzui","zNjVBunOyxi","B2XKvMvYC2K","CMLLC0nVDw4","DxDvEwO","CwTkAxu","EvjLy29UBMu","Dw50","zxjYtM8","zfnfDKu","yxrHlcbKyxq","CuLOreC","qLLmAu8","Ewvyy2K","icSG","yMLUyxj5vhK","zv90Aw1LB3u","y2HnyxHuCMK","uLrNtw8","DK9RvgC","rxzLBNq","ExbL","se9LBxe","zxH0zw5ZAw8","vNLovLa","DvzVz0W","A3rSvKq","sK5pqKS","Dgz2B3C","uLjpuG","Dg9VigXHCMC","x2nYzwf0zvm","DNvby2y","uxrdr2y","y29UBMvJDeu","odm0ntu4C3fmrKvK","C2v0q3vYC28","zejyAKG","CM92AwrLihC","zxjYB3i","vuzuA0u","BwzIsxK","EevtqLq","vwfAwNa","zw5HyMXLvhi","CefKtwO","CfLwCNq","ENjnv3q","m3WXFdj8nhW","AufLr2O","v0XSy3e","C2XPy2u","twTXrgy","CMvHzg9UBhK","AwHgyLm","sxnQq2W","yMj0wKy","CMvWBgfJzq","x2DLDeLUDgu","Dg9hzw5LCMe","rLbfu08","zLnfrxu","EKTjswu","x2rYB3bhBg8","x2nVBM5Ly3q","wwXND0e","x2jPBMfYEvq","yMfSrxzLBNq","EuznquS","y2XLyxjtDg8","DxbNCMfKzw4","C2vYDMLJzs0","y0DWBfC","qxzKs3q","q1PotLO","BMDLza","y29TCgXLDgu","Ewn4Ce8","rhjTsxq","v0nlvLe","Evn0zNe","vuLNu1q","uungu0C","C2HPzNq","y2uGBM90igK","rLjptLrjrvi","sLHgsw0","BMXosNu","Cgf5Bg9Hzeu","aaaaaaaaaaa","z2v0qwXSs2u","zMX1C2HfEha","CxLKrha","CMvXDwLYzwq","Aw9UvgLTzw8","CKnrqLq","BvjPrLe","igzPzwXKoIa","y0vJr2q","x2LZtwLUAvC"];return So=function(){return t},So()}function JE(t){let e=M,r={vgPSM:"complete",PhpOR:"error",gbvyx:e(801),yhBWc:function(o,c){return o(c)},lJMLb:e(512)+"or",vVDhA:function(o){return o()},fxECO:e(860),WWCbt:function(o){return o()},WcpKS:function(o){return o()}};if(Io.has(t))return;let i=new Promise((o,c)=>{let l=e,u={yPqby:r.fxECO,TPpKW:function(_){return r[q(472)](_)},ZYVdy:function(_){return r[q(970)](_)}},h=()=>{let _=q;t[_(1729)+_(1246)+"ner"](r[_(1755)],x),t[_(1729)+_(1246)+_(997)](r.PhpOR,w),t[_(1729)+_(1246)+_(997)](r[_(1848)],w)},x=()=>{let _=q;if(u[_(1178)]===_(860))u[_(1492)](o),u[_(736)](h);else return this[_(878)].url},w=()=>{let _=q;r[_(857)](c,t[_(1364)]||new DOMException(_(512)+"or",r[_(1274)])),r[_(1119)](h)};t[l(1780)+l(514)](r.vgPSM,x),t[l(1780)+l(514)](r[l(369)],w),t.addEventListener(r[l(1848)],w)});Io[e(986)](t,i)}function VE(t){To={rJyRw:function(r,i){return r(i)}}.rJyRw(t,To)}function YE(t){let e=M,r={nlNJu:function(i,o){return i(o)},NwAFy:function(i,o){return i(o)},WBGPh:function(i,o){return i!==o},kImEf:"pLaai",Afozz:"QPXUX",DrmIt:function(i,o){return i(o)},VSpSx:function(i,o){return i(o)},eRyRp:function(i,o){return i===o},TeAty:function(i,o){return i in o},aiYgX:e(1118)+e(774),wWZVS:function(i){return i()}};return r[e(1823)](t,IDBDatabase[e(1503)+"e"][e(632)+e(1509)])&&!r.TeAty(r[e(682)],IDBTransaction[e(1503)+"e"])?function(i,...o){let c=e,l=t.call(r[c(1412)](zi,this),i,...o);return id.set(l,i[c(676)]?i[c(676)]():[i]),r[c(1216)](Nt,l)}:r[e(843)](KE).includes(t)?function(...i){let o=e;if(r.WBGPh(r[o(1319)],r[o(1223)]))return t.apply(r[o(1403)](zi,this),i),r[o(1199)](Nt,sd[o(1520)](this));throw this[o(1389)+o(505)]=!1,_0x464358}:function(...i){let o=e;return r[o(1403)](Nt,t.apply(r[o(1403)](zi,this),i))}}function ZE(t){let e=M,r={aFIkV:e(1234),IJylA:function(i,o){return i(o)},HRkOd:function(i,o){return i instanceof o},FUvtG:function(i,o){return i(o)},PBqPB:function(i){return i()}};return typeof t===r[e(1593)]?r[e(726)](YE,t):(r[e(427)](t,IDBTransaction)&&r.FUvtG(JE,t),ih(t,r[e(1187)](WE))?new Proxy(t,To):t)}function Nt(t){let e=M,r={icLCu:function(o,c){return o instanceof c},eDQFd:function(o,c){return o(c)},bzEoC:function(o,c){return o!==c}};if(r[e(343)](t,IDBRequest))return r[e(943)]($E,t);if(bo.has(t))return bo[e(1520)](t);let i=r[e(943)](ZE,t);return r[e(363)](i,t)&&(bo.set(t,i),Ao[e(986)](i,t)),i}var ih,X0,Q0,sd,Io,id,bo,Ao,To,zi,eh=rh({"node_modules/idb/build/wrap-idb-value.js"(){let t=M,e={kXWbo:function(r,i){return r instanceof i},JjnCd:function(r,i){return r===i},nekrw:t(938),vAbaU:t(1721)};ih=(r,i)=>i[t(1146)](o=>r instanceof o),sd=new WeakMap,Io=new WeakMap,id=new WeakMap,bo=new WeakMap,Ao=new WeakMap,To={get(r,i,o){let c=t;if(e[c(1719)](r,IDBTransaction)){if(e[c(339)](i,e[c(341)]))return Io[c(1520)](r);if(e[c(339)](i,c(1118)+c(774)))return r[c(1118)+c(774)]||id[c(1520)](r);if(e[c(339)](i,e[c(1230)]))return o[c(1118)+"oreNames"][1]?void 0:o["objectSt"+c(1479)](o[c(1118)+c(774)][0])}return Nt(r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return e[o(1719)](r,IDBTransaction)&&(e.JjnCd(i,o(938))||e[o(339)](i,e[o(1230)]))?!0:i in r}},zi=r=>Ao[t(1520)](r)}}),sh={};jE(sh,{deleteDB:()=>QE,openDB:()=>XE,unwrap:()=>zi,wrap:()=>Nt});function XE(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let l=M,u={TQwGt:l(579)+"e_timeout",BYLiO:"timeout",QWiHP:function(w,_){return w!==_},VhDIu:l(1191),wbOts:function(w,_,S,E,v){return w(_,S,E,v)},UIgST:l(755),gMsAz:function(w,_){return w(_)},VNvgR:function(w,_){return w!==_},aYmdo:"xslcE",VHdJe:l(1832)},h=indexedDB[l(422)](t,e),x=u[l(1742)](Nt,h);return i&&(u.VNvgR(l(923),u[l(976)])?(this[l(367)+"sCounter"]?.addCount(),this[l(1127)](u[l(796)],u[l(1337)]),this["_pingLos"+l(985)]?.["checkRea"+l(952)+"nt"]()?this[l(1155)+l(669)]():this._ping()):h[l(1780)+l(514)](l(1395)+l(920),w=>{let _=l;u[_(824)](u.VhDIu,u[_(668)])?_0x5a632f[_(439)]=_0x1558c3.resolve()[_(957)](()=>(_0x2e5093(),_0x1a2022))[_(957)](function(S){return S}):u[_(417)](i,Nt(h[_(1022)]),w[_(1327)+"on"],w[_(1304)+"on"],Nt(h[_(632)+"ion"]))})),r&&h.addEventListener(u[l(408)],()=>r()),x.then(w=>{let _=l;c&&w[_(1780)+"Listener"](u[_(1406)],()=>c()),o&&w[_(1780)+"Listener"](_(1500)+"hange",()=>o())}).catch(()=>{}),x}function QE(t,{blocked:e}={}){let r=M,i={hgIza:r(1832),mfbIy:function(c,l){return c(l)}},o=indexedDB[r(1189)+r(764)](t);return e&&o[r(1780)+r(514)](i[r(845)],()=>e()),i[r(1366)](Nt,o)[r(957)](()=>{})}function th(t,e){let r=M,i={YUNhw:r(1073)+"e",YPfiP:function(h,x){return h in x},Jlbue:function(h,x){return h===x},skbsG:r(1508),HOemq:function(h,x){return h!==x}};if(!(t instanceof IDBDatabase&&!i[r(1747)](e,t)&&i[r(1063)](typeof e,i.skbsG)))return;if(vo[r(1520)](e))return vo[r(1520)](e);let o=e.replace(/FromIndex$/,""),c=i[r(1347)](e,o),l=ah.includes(o);if(!(o in(c?IDBIndex:IDBObjectStore)[r(1503)+"e"])||!(l||oh[r(844)](o)))return;let u=async function(h,...x){let w=r,_=this[w(632)+w(1509)](h,l?i.YUNhw:w(1378)),S=_[w(1721)];return c&&(S=S.index(x[w(1408)]())),(await Promise[w(469)]([S[o](...x),l&&_[w(938)]]))[0]};return vo[r(986)](e,u),u}var oh,ah,vo,eb=rh({"node_modules/idb/build/index.js"(){let t=M,e={TVcHK:t(870)+t(742),snInh:t(1520),aSkTC:t(1177),xadtZ:"getAllKeys",NRGla:t(578),bxTSk:t(1034),woDXb:"add",RSvev:"delete",cMcoS:function(o){return o()}},r=e[t(524)][t(1283)]("|"),i=0;for(;;){switch(r[i++]){case"0":oh=[e[t(488)],e.aSkTC,"getAll",e[t(706)],e[t(652)]];continue;case"1":ah=[e[t(1272)],e[t(1314)],e.RSvev,t(1065)];continue;case"2":VE(o=>({...o,get:(c,l,u)=>th(c,l)||o[t(1520)](c,l,u),has:(c,l)=>!!th(c,l)||o.has(c,l)}));continue;case"3":e[t(1649)](eh);continue;case"4":e.cMcoS(eh);continue;case"5":vo=new Map;continue}break}}}),tb={idb:function(t){let e=M,r={rciDI:e(1764)};t[e(439)]=Promise.resolve()[e(957)](()=>(eb(),sh))[e(957)](function(i){let o=e;return r.rciDI===o(1764)?i:((this[o(1488)+"rs"][_0x59cd0a]||(this[o(1488)+"rs"][_0x376432]=[]))[o(370)]({fn:_0x403b1c,ctx:_0x2dd139||this}),this)})}},nh={};function q(t,e){t=t-337;let r=So(),i=r[t];if(q.RFOrtT===void 0){var o=function(h){let x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",w="",_="";for(let S=0,E,v,A=0;v=h.charAt(A++);~v&&(E=S%4?E*64+v:v,S++%4)?w+=String.fromCharCode(255&E>>(-2*S&6)):0)v=x.indexOf(v);for(let S=0,E=w.length;S<E;S++)_+="%"+("00"+w.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(_)};q.HBUpHe=o,q.mNfemE={},q.RFOrtT=!0}let c=r[0],l=t+c,u=q.mNfemE[l];return u?i=u:(i=q.HBUpHe(i),q.mNfemE[l]=i),i}function Lt(t){let e=M,r={tfvow:e(1373)+"0",qydDp:function(u,h){return u!==h}},i=r[e(1353)][e(1283)]("|"),o=0;for(;;){switch(i[o++]){case"0":return c[e(439)];case"1":if(r[e(1417)](void 0,l))return l.exports;continue;case"2":var c=nh[t]={exports:{}};continue;case"3":var l=nh[t];continue;case"4":tb[t](c,c[e(439)],Lt);continue}break}}Lt.d=(t,e)=>{let r=q;for(var i in e)Lt.o(e,i)&&!Lt.o(t,i)&&Object[r(1795)+r(1550)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=M;Lt.o=(e,r)=>Object.prototype["hasOwnPr"+t(1550)][t(1069)](e,r)})(),(()=>{let t=M,e={kXptE:function(r,i){return r!=i},hgYpD:t(1843),uVogL:t(1783)+"le"};Lt.r=r=>{let i=t;e[i(1105)](i(1689)+"d",typeof Symbol)&&Symbol[i(644)+i(1658)]&&Object[i(1795)+i(1550)](r,Symbol.toStringTag,{value:e[i(1212)]}),Object["definePr"+i(1550)](r,e[i(1350)],{value:!0})}})();var Te={};(()=>{let t=M,e={Mmxxw:function(a,n){return a(n)},yeXci:function(a,n){return a+n},UoDEF:function(a,n){return a===n},LUyvn:function(a,n,s){return a(n,s)},Juomj:function(a,n){return a!==n},cOwGn:t(1131),CazLD:t(1160),QHULB:function(a,n){return a*n},LxLCZ:function(a,n){return a+n},HIEHE:function(a,n,s){return a(n,s)},NGfBg:t(1739),VIGhU:t(1735),EQqyn:t(864),AdqfO:t(624),nIMfp:"00000000"+t(429)+"00000000"+t(429),kmzPu:function(a,n){return a<n},HyyxR:function(a,n){return a-n},Jfyis:function(a,n){return a>=n},ChyXb:function(a,n){return a<n},BAofd:function(a,n){return a|n},vxUtl:function(a,n){return a<<n},HFaiY:function(a,n){return a&n},CSjhS:function(a,n){return a&n},TulaE:function(a,n){return a&n},ulsAi:function(a,n){return a|n},EaFLi:function(a,n){return a<<n},ppSRk:function(a,n){return a&n},yxumi:function(a,n){return a&n},zlCOn:function(a,n){return a&n},dWaAi:function(a,n){return a+n},yiorL:function(a,n){return a>>n},urPdM:function(a,n){return a+n},sDqpL:function(a,n){return a>n},uRjYB:function(a,n){return a!==n},BXtmG:function(a,n){return a-n},kKwcv:function(a,n){return a-n},uFcoV:function(a,n){return a<n},GlIZu:"pPXeX",PsIAJ:function(a,n){return a<n},WfMAC:function(a){return a()},lUGUr:t(1849),qDmhB:function(a,n,s){return a(n,s)},AXJbc:function(a,n,s){return a(n,s)},JnMQy:t(1537),kNSsf:function(a,n,s){return a(n,s)},ocHpM:t(1046),HJonR:"ppe",asZwL:function(a,n){return a(n)},rakyH:function(a,n){return a===n},OjUlw:t(956),qzDEw:function(a,n){return a>>>n},rBJdp:function(a,n){return a(n)},AaCaN:function(a,n){return a===n},uONGD:t(1601)+"required"+t(1422)+t(1616),DfBWH:function(a){return a()},jwJPA:function(a,n,s){return a(n,s)},LloUY:function(a,n){return a!==n},traTi:function(a,n,s){return a(n,s)},wbgZT:function(a,n,s){return a(n,s)},UFTkE:function(a,n){return a(n)},yRGHQ:function(a,n){return a!==n},XMrJO:function(a,n){return a(n)},ejVeE:function(a,n,s){return a(n,s)},igEuZ:function(a,n,s){return a(n,s)},aKdzI:function(a,n,s){return a(n,s)},skbuJ:function(a,n){return a(n)},GwXZP:function(a,n){return a!==n},GHHWB:function(a,n,s){return a(n,s)},SIFrD:function(a,n,s){return a(n,s)},eRtWX:t(1790),oVCQT:function(a,n){return a!==n},CvKly:function(a,n,s){return a(n,s)},kRmRA:function(a,n,s){return a(n,s)},XwqQc:function(a,n){return a(n)},gtTZZ:function(a,n){return a(n)},gwdEG:function(a,n){return a(n)},dyOZV:function(a,n,s){return a(n,s)},hqXAo:function(a,n){return a(n)},aJPbT:function(a,n){return a===n},vOKbd:"Missing "+t(1418)+t(1422)+t(1238),jHdbz:"Missing required"+t(1422)+t(360),fSEEu:function(a,n){return a(n)},MDJEP:function(a,n){return a+n},MwaxE:"success",bbtZF:"ping_onc"+t(1341)+"t",nXGfG:function(a,n){return a(n)},uFghK:function(a,n){return a(n)},JXFIm:function(a,n,s){return a(n,s)},atECx:"Unimplem"+t(1194)+"pe: ",LBiwt:t(1599)+t(667)+t(1409)+t(741)+"ed",GzCrC:"close, ws alread"+t(678),uSCcj:t(432),EOJkK:t(1447),WPICJ:t(653),RgIVL:function(a,n){return a+n},yIeQh:"Skip past limit",FsHlw:t(1807),TlLdp:function(a,n){return a+n},XqjQD:function(a,n){return a>n},vjRwk:"TfvIX",BFRnB:function(a,n){return a*n},qNPNG:t(526)+t(933),ojwin:function(a,n,s){return a(n,s)},BIcdc:t(755),WlDjb:t(1364),EAJpQ:function(a,n){return a(n)},cBTAW:function(a,n){return a(n)},Ggqwx:function(a,n){return a+n},irRrU:function(a,n){return a&n},uwUyj:function(a,n){return a===n},wkmPK:t(1761),zKIIe:function(a,n){return a==n},yCcIq:function(a,n){return a+n},EijsX:function(a,n){return a+n},tdrYL:function(a,n){return a|n},hHsno:function(a,n){return a&n},bHJRl:function(a,n){return a<<n},YJBGv:function(a,n){return a&n},raBEm:function(a,n){return a<n},KldSj:function(a,n){return a<=n},rDibr:"MaEmr",zHlky:function(a,n){return a&n},nlRgp:function(a,n){return a>=n},YHoLT:"hOnVD",vgQet:function(a,n){return a+n},zLorP:function(a,n){return a+n},AOuEo:function(a,n){return a+n},wEjHX:function(a,n){return a!==n},YUhIL:function(a,n){return a<<n},ZBdcO:function(a,n){return a|n},khAxY:function(a,n){return a&n},ZCeBz:function(a,n){return a>n},ZGCiD:function(a,n){return a+n},mYPuh:function(a,n){return a>=n},FelmD:function(a,n){return a+n},WympD:function(a,n){return a<<n},efyER:function(a,n){return a<n},sioSk:function(a,n,s){return a(n,s)},isvJJ:function(a,n){return a===n},QbRXS:t(1762),PSZuu:function(a,n){return a<=n},trJMq:function(a,n){return a+n},cGplW:function(a,n){return a+n},pDqTp:function(a,n){return a|n},MZDtJ:function(a,n){return a&n},hcYox:function(a,n){return a>>n},fGJBC:function(a,n){return a<n},vjMcw:function(a,n){return a|n},YeXiB:function(a,n){return a>>n},CreME:function(a,n){return a>>n},woJiY:function(a,n){return a>>n},XLLCP:function(a,n){return a|n},VPIbr:function(a,n){return a===n},YHJlo:t(1232),DOAOi:function(a,n){return a+n},GwDNn:function(a,n,s){return a(n,s)},mfHOj:function(a,n){return a(n)},DnpAJ:function(a,n,s){return a(n,s)},bqFKE:function(a,n){return a|n},EcVNg:function(a,n){return a&n},sYZkO:function(a,n,s){return a(n,s)},lMYnb:function(a,n){return a||n},uRNMZ:function(a,n){return a(n)},lJDjI:function(a,n){return a+n},LUWCr:function(a,n,s){return a(n,s)},JbPDc:function(a,n){return a>>>n},lIhYt:function(a,n){return a(n)},UaZZp:function(a,n){return a&n},teIxu:function(a,n){return a&n},QHIYY:t(1247),uzexH:"rUVBU",Xlhbs:function(a,n){return a(n)},NRpUI:function(a,n){return a&n},GUung:function(a,n){return a&n},yfvNQ:function(a,n){return a(n)},AxYwf:function(a,n){return a&n},wVfcj:function(a,n){return a===n},qGPYh:t(513),iLZyP:"KTwYE",LmGfT:function(a,n){return a(n)},LeRYd:function(a,n){return a<<n},HJgZX:function(a,n){return a&n},ODeEn:function(a,n){return a(n)},eosZd:function(a,n){return a&n},RQFHw:function(a,n){return a!==n},AvdKt:"ZgyiB",VcJAB:function(a,n){return a(n)},TfSmw:function(a,n){return a<<n},SvTcl:function(a,n){return a&n},lqlVD:function(a,n){return a|n},EvYDx:function(a,n){return a<<n},FCUqc:function(a,n){return a|n},kKLzN:function(a,n){return a>>>n},bbjlh:function(a,n){return a<<n},zolbY:function(a,n){return a>>>n},jjyFn:function(a,n){return a>>>n},cvxYO:function(a,n){return a|n},ozTfk:function(a,n){return a<<n},WQmyA:function(a,n){return a>>>n},TXYLs:function(a,n){return a===n},OxQkC:function(a,n){return a<n},YbYVH:function(a,n){return a<n},xBAEu:function(a,n){return a<n},ULRhq:function(a,n,s){return a(n,s)},SiyxN:function(a,n){return a+n},zDNkE:function(a,n){return a&n},dYRrk:function(a,n){return a+n},LynZr:function(a,n){return a>>>n},FPotb:function(a,n){return a+n},jHoEf:function(a,n){return a|n},NEHeQ:function(a,n){return a>>>n},mFOqP:function(a,n){return a>>>n},zmqrb:function(a,n){return a|n},sglRk:function(a,n){return a&n},ezuSl:function(a,n){return a>>>n},fDwqy:function(a,n){return a!==n},YnovX:function(a,n){return a|n},inFlv:function(a,n){return a+n},LUdgO:function(a,n){return a|n},QSmJI:function(a,n){return a>>>n},YXnXC:function(a,n){return a&n},CZNNZ:function(a,n){return a+n},miIOS:function(a,n){return a!==n},WFTzp:function(a,n){return a|n},mJCFP:function(a,n){return a&n},ciOrr:function(a,n){return a|n},rtaIr:function(a,n){return a===n},vuAcf:t(1490),QRwLb:function(a,n){return a|n},zPmmT:function(a,n){return a|n},ZRLOm:function(a,n){return a<<n},jzfWz:function(a,n){return a<<n},eXJui:function(a,n){return a<<n},masGt:function(a,n){return a|n},QWOtk:function(a,n){return a<<n},oIWYk:function(a,n){return a===n},TEoDI:function(a,n){return a<<n},fQDpk:function(a,n){return a>>>n},LQRCO:function(a,n){return a|n},DOVtF:function(a,n){return a<<n},qPpMO:function(a,n){return a&n},TRjMe:function(a,n){return a&n},EBXJz:function(a,n){return a>>>n},sUkHS:function(a,n){return a&n},loFyV:function(a,n){return a>>>n},eeosw:function(a,n){return a>>>n},wSjYO:function(a,n){return a&n},Eyxsw:function(a,n){return a&n},vBQvq:function(a,n){return a+n},sQAuj:function(a,n){return a|n},iDKFG:function(a,n){return a/n},pAdMj:function(a,n){return a!=n},NsVNO:t(1508),bLyMP:function(a,n){return a instanceof n},xESBT:function(a,n){return a!==n},bNmKv:t(1150),Nufqt:function(a,n){return a*n},YlYzr:function(a,n){return a>>>n},YTvJJ:function(a,n){return a*n},xgnpK:function(a,n){return a+n},ypOwX:function(a,n){return a>>>n},HUrwb:function(a,n){return a+n},NtASU:function(a,n){return a<<n},zqYbU:function(a,n){return a<<n},UbxDh:function(a,n){return a!==n},GJUJD:function(a,n){return a===n},uMdvb:function(a,n){return a===n},wAHjo:function(a,n){return a===n},Uraph:function(a,n){return a===n},Dnhyq:function(a,n){return a===n},hxGtD:function(a,n){return a===n},NPSsF:function(a,n){return a+n},JRTra:t(1698),iQapH:t(1016),uALes:function(a,n){return a===n},dEHga:t(815),Ssqqi:t(630),taEln:function(a,n){return a===n},xMaUn:t(1143),QLVQl:t(1226),NSWnd:function(a,n){return a&n},AtQgh:function(a,n){return a>>>n},YBIhg:function(a,n){return a&n},xRwfa:function(a,n){return a&n},mRiFQ:function(a,n){return a>>>n},zZwmr:function(a,n){return a>>>n},Ritkh:function(a,n){return a>>>n},Ejudy:function(a,n){return a>>>n},DxqEe:function(a,n){return a&n},DcFFN:function(a,n){return a&n},wxcAF:t(1555)+t(928),AjNit:t(892)+t(1354),nuyKC:"OPEN_ERROR",Mxpcp:"MAX_RETRIES_ERROR",epiXP:t(1611)+"NG_ERROR",lBPZm:t(1249)+t(1526),tEINE:t(1594)+"3",iLrxY:function(a,n){return a|n},JQUGj:t(1334),lSynf:t(770),dxSJU:function(a,n){return a>n},DbDlw:function(a,n){return a+n},SCFFd:function(a,n){return a!==n},KQJuu:t(752),aKfpd:t(1380),GCBeh:function(a){return a()},vIyKI:function(a,n){return a(n)},HJNVV:t(767),eZmEw:function(a,n){return a+n},gsFJN:function(a,n){return a<<n},vgPFT:function(a,n){return a|n},VBCQM:function(a,n){return a&n},ALOAj:function(a,n){return a!==n},wHSzs:t(1091),jcQfi:t(839),vJVxt:function(a,n){return a-n},xzGTa:function(a,n){return a>n},KQHmr:"text/pla"+t(387)+t(687),vwJqe:t(787),JzQDx:t(757),Yayvn:function(a,n){return a instanceof n},bWUfU:function(a,n){return a+n},YjVqM:"Unhandle"+t(456),eMcuy:function(a,n){return a===n},ShRlY:function(a,n){return a<n},DGtHZ:function(a,n){return a>>>n},tQpXo:function(a,n){return a&n},tpBIS:function(a,n){return a>>>n},dlZnm:function(a,n){return a>>>n},DXasj:function(a,n){return a|n},imFax:t(574),jlWoG:t(725),gMjQu:function(a,n){return a===n},OAPYe:t(392),IalMf:function(a,n,s){return a(n,s)},XDbVl:t(422),iHaKk:function(a,n,s){return a(n,s)},nIwln:function(a,n,s){return a(n,s)},IUgBw:t(822),vVcpS:function(a,n){return a+n},xhGjH:t(1689)+"d",TtiWV:t(1404),imKSo:t(1438),aCDGJ:"3|0|1|4|2",rWKOy:function(a,n){return a+n},rCQBT:t(1805),gNcIz:t(1580),akcOE:function(a,n){return a<n},cCXue:function(a,n){return a===n},dBXjH:function(a,n){return a&n},UEtwH:function(a,n){return a===n},bUyQt:function(a,n){return a<n},gTXbu:function(a,n){return a<n},jNRLW:function(a,n){return a>=n},NIYDh:function(a,n){return a|n},JyqcB:function(a,n){return a<<n},UapPm:function(a,n){return a&n},aLYQS:function(a,n){return a<<n},kVQsB:function(a,n){return a&n},EdOBZ:function(a,n){return a>=n},nisSj:function(a,n){return a<<n},MciGf:function(a,n){return a<<n},LAfBR:function(a,n){return a&n},nhBUZ:function(a,n){return a<<n},dErVJ:function(a,n){return a&n},YeluO:function(a,n){return a<n},dqTfN:function(a,n){return a>>n},ZGLhd:function(a,n){return a|n},kWHKi:function(a,n){return a&n},UZWgm:function(a,n){return a&n},tmNTE:function(a,n){return a+n},LfqXu:"2|5|1|0|3|4",epzlD:function(a,n){return a|n},iyrjn:function(a,n){return a|n},azvsn:function(a,n){return a+n},cKqUx:function(a,n){return a<<n},YiepM:function(a,n){return a&n},HRAiC:function(a,n){return a|n},PqqKH:function(a,n){return a&n},zrMWt:function(a,n){return a>>n},mHThQ:function(a,n){return a&n},dJfcy:function(a,n){return a==n},JJBfr:function(a,n){return a!==n},SLBWs:"golqH",GziLU:"gQYdF",AqLfu:t(1615),DcxIT:t(1839),FPESO:function(a,n,s,d){return a(n,s,d)},XzlYJ:t(1799),xPvvJ:function(a,n){return a==n},VAZCS:function(a,n){return a===n},sgfAG:t(471),cEcGd:t(579)+"e_success",KKDFB:function(a,n,s){return a(n,s)},qIhDG:t(542),bItJm:function(a,n){return a===n},DOcRI:t(581),oFKVb:function(a,n){return a&n},LMLeo:function(a,n){return a&n},vRKEc:function(a,n){return a>>>n},BPahd:function(a,n){return a(n)},FzlQl:t(1541)+"reason",AlQum:t(1845),xQfVy:"text/javascript",cUwLw:function(a,n){return a===n},QtCGf:t(1448),WZUut:function(a,n){return a<n},oUgSq:function(a,n){return a|n},TgXZo:function(a,n){return a>>n},RpSWI:function(a,n){return a|n},XPAAa:function(a,n){return a===n},fvfhI:function(a,n){return a&n},yjyHq:"4|5|0|2|"+t(1663),RMgUl:function(a,n){return a|n},byvoe:function(a,n){return a&n},FIoFs:function(a,n){return a>>n},edFed:function(a,n){return a>>n},HvBEA:function(a,n){return a|n},kETnZ:function(a,n){return a&n},amMQC:function(a,n){return a<<n},PqRDm:function(a,n){return a|n},dOupD:function(a,n){return a>>n},jhjUv:function(a,n){return a&n},OgDLv:t(1043),UZrrd:function(a,n){return a===n},LhWFG:function(a,n){return a+n},yuwsC:"sSOeQ",zdjKH:"sbjRo",rfTIc:function(a,n,s,d){return a(n,s,d)},DNcuf:function(a,n){return a<n},ghNdl:function(a,n){return a<n},kqOGV:function(a,n){return a+n},oVFbz:"PqKdH",nWYlo:t(1478),FVxvQ:t(627),vMrJW:t(1445),MJzTK:"1|0|4|2|3",gYnlG:function(a,n){return a===n},aHaBQ:t(523),uaMvT:t(1291),qMZyx:function(a,n){return a||n},izPyc:function(a,n){return a||n},DoPQM:function(a,n,s,d){return a(n,s,d)},KGDoh:t(503)+"er_qos_ack",YSeSq:function(a,n,s,d){return a(n,s,d)},orYvw:t(503)+t(1713)+"k",OWoqF:"x_fronti"+t(1559)+t(1037),NkPea:t(1017),NQtht:t(553),RQhTK:function(a,n){return a||n},YlgwA:function(a,n){return a||n},uAcXX:t(1585),KVIxo:t(1203),BWXKe:"UJoRA",XWrho:function(a,n){return a||n},vPZrE:function(a,n){return a!=n},jWySu:"message_id",UpRrq:function(a,n,s){return a(n,s)},PesHA:function(a,n){return a(n)},tjZTd:t(1712),PJUGn:"yuPpC",broAv:t(518),jlOoj:function(a,n){return a(n)},WLlcq:function(a,n,s){return a(n,s)},RVXXb:function(a,n){return a===n},IUFWz:t(1351),RdABU:t(503)+t(1297),OxLlu:function(a,n,s,d){return a(n,s,d)},ycxpO:function(a,n,s,d){return a(n,s,d)},fgxzb:"need_ack",whHEW:function(a,n){return a&&n},HXPxS:"ack_code",LlBVe:function(a,n){return a instanceof n},doVRu:function(a,n){return a instanceof n},IkpGN:function(a,n){return a instanceof n},WJwEZ:t(1759)+t(1271),gFegu:"application/json"+t(535)+t(1834),knkGy:t(1771)+"e",VfBlB:function(a,n,s,d){return a(n,s,d)},cKJeG:t(1096),yStfq:function(a,n){return a<n},XGMmJ:function(a,n){return a|n},YNzni:function(a,n){return a>>>n},NOFdL:function(a,n){return a(n)},GrJhf:function(a,n){return a+n},pzwVQ:function(a,n){return a+n},AWoOO:function(a,n){return a+n},FZOEl:t(1808)+"t of ran"+t(1741),PUIXG:t(1339),HSYvh:t(1197),VvFqi:"integer "+t(1355)+"e",ihFbS:function(a,n){return a+n},uZJok:function(a,n){return a<<n},JZBYG:t(431)+"3",DDbyc:function(a,n){return a<n},hUEOJ:function(a,n){return a+n},hNOVr:function(a,n){return a+n},CEucZ:function(a,n,s,d){return a(n,s,d)},SQkdy:function(a,n){return a+n},Fgiml:function(a,n){return a===n},ukqNO:t(382),MLqTr:function(a,n){return a|n},jdLHF:function(a,n){return a+n},HgWTg:function(a,n){return a<<n},YStZh:function(a,n){return a+n},EtljY:function(a,n){return a|n},xOVhI:function(a,n){return a|n},YgUif:function(a,n){return a<<n},HAhKv:function(a,n){return a+n},UxgWX:function(a,n){return a+n},ovLoN:function(a,n){return a+n},DqEtr:function(a,n){return a&n},ktYRq:function(a,n){return a>>>n},uVCpH:function(a,n){return a+n},kSiYu:function(a,n){return a+n},iCDbV:function(a,n){return a>>>n},WgygW:t(1245),AiDJV:function(a,n){return a&n},SBtIs:t(414),QpntQ:t(1810)+t(620)+t(1751)+"1",NNzfY:function(a,n){return a|n},rgYyG:function(a,n){return a<n},KLTWe:function(a,n){return a<<n},ZdkOW:function(a,n){return a>n},XUixt:function(a,n){return a|n},EReui:function(a,n){return a<n},BgaJa:function(a,n){return a|n},TEWqW:function(a,n){return a<n},dLGDt:function(a,n){return a(n)},qzDTb:function(a,n){return a+n},OWQqP:t(337),GqPUe:"service",NHhjb:function(a,n){return a(n)},mdosG:"cursor_f"+t(580),wmeLx:function(a,n,s){return a(n,s)},xplAU:function(a,n,s,d){return a(n,s,d)},fNHTN:function(a,n,s){return a(n,s)},TQMzM:t(607)+t(1430),JRnmu:"cursor_name",bePrj:t(1474)+"rValues",BkXUa:t(1484),oASxl:function(a,n,s,d){return a(n,s,d)},SVpyu:t(1279),DrLOK:t(1108),YiVsK:t(1664),seGXd:function(a,n){return a(n)},YjbNT:function(a,n){return a!==n},BNuZb:"wYndl",ZmFWC:t(981),Uqfzy:function(a,n){return a||n},KhuZM:function(a,n){return a===n},FlKXv:t(1737),uYkaE:t(823),nbIdF:function(a,n,s,d){return a(n,s,d)},ObtwW:t(503)+t(1797),MFjRl:function(a,n){return a(n)},JJrbh:function(a,n,s){return a(n,s)},hmiQK:function(a,n,s,d){return a(n,s,d)},esVTp:t(361)+"s",nspMq:t(1470)+"rsor_name",ZkTLc:"x-msg-cu"+t(737)+"ue",VxWps:function(a,n){return a>n},SkdWX:function(a,n){return a>n},DBcsM:function(a,n){return a+n},NBlUZ:t(1302),kmaDh:function(a,n){return a<n},sSLKm:function(a){return a()},XnHhp:function(a){return a()},RrxCi:function(a){return a()},AXECl:function(a,n){return a===n},NHdky:function(a,n){return a===n},GgZDB:function(a,n){return a(n)},konte:function(a){return a()},QzrIa:function(a,n){return a!==n},zqOpK:function(a,n){return a<n},tvqoB:function(a){return a()},UCFpd:function(a){return a()},KDywz:function(a,n){return a===n},CaMES:function(a,n){return a===n},SCsYz:"always",PWqyF:function(a,n,s){return a(n,s)},PVHHG:t(1217),lPJvQ:function(a,n,s,d){return a(n,s,d)},WNYNZ:function(a,n,s){return a(n,s)},ioVeP:function(a,n,s){return a(n,s)},yHqlw:function(a,n){return a!==n},Ndahm:"bye",xyaDg:function(a,n){return a!==n},UiQsw:function(a,n,s){return a(n,s)},wVHQR:function(a,n){return a(n)},POFVp:function(a,n){return a&n},SCRLn:function(a,n){return a&n},waPxr:function(a,n){return a&n},fQQiv:function(a,n){return a==n},uzosJ:function(a,n){return a===n},aVKBK:t(613)+t(1201)+t(570),CsLsD:function(a,n){return a&n},LWNHx:function(a,n){return a<<n},hVpcy:t(1173),DUuYn:function(a,n,s){return a(n,s)},MCKaG:t(1459)+"t",JnGqT:"stop imm"+t(1671)+t(872)+"ct",XoQaU:function(a,n){return a!==n},WRLgY:function(a,n){return a!==n},PEkDo:function(a,n,s){return a(n,s)},TQhtj:function(a,n){return a!==n},DtciD:t(775),TipNM:"kqdpd",LdoHk:t(1092),RQgJP:"UrhCE",RTgMo:t(1777),krdIK:t(1819),LEHZJ:t(1551)+"d",eTqmQ:function(a,n){return a||n},GtKtv:t(613)+t(1572)+t(1850)+t(1002)+"r ttwID",RaxBR:function(a,n){return a==n},lRSzq:function(a){return a()},lJjvu:t(1504),mlezF:t(1829)+"0",khYVb:function(a,n){return a||n},rKcQN:function(a,n){return a!==n},iSKqZ:t(1640),zAZMM:function(a,n,s){return a(n,s)},lHIwj:t(441),SBRXZ:t(1110),DvzBP:t(1489),JXHxi:function(a,n){return a-n},tHETD:function(a,n,s){return a(n,s)},NvTDw:function(a,n,s){return a(n,s)},ieWGi:function(a,n){return a(n)},yFMAK:t(1410)+">",bwWKs:function(a,n){return a*n},VxxWF:function(a,n){return a>n},IEwKb:function(a,n){return a!==n},nMghw:function(a,n,s){return a(n,s)},xMntK:function(a,n){return a!==n},LdbNI:t(585),Hdefo:t(1133)+t(710)+t(1459)+t(566)+t(690),Lhfyy:function(a,n){return a>>>n},rLIAC:function(a,n){return a>>>n},UgfnD:function(a,n){return a&n},rPLye:function(a,n){return a!==n},pYVrt:t(1164),seRzb:t(639),HOmoX:t(1035)+t(1695)+t(1836)+"g",eEzWy:function(a,n){return a===n},mkqLq:t(457)+"4",ZZGOt:t(973),iXPpH:t(816),BClcx:t(595),AxtYA:"nNLSC",eAXSe:t(1623),SdRLq:t(576),UlZly:function(a,n,s){return a(n,s)},addpl:function(a,n,s){return a(n,s)},XULaK:"going aw"+t(1709)+t(848)+"ine",vQmVE:t(536),iklGM:function(a,n){return a===n},jhDNn:"LaVfJ",cLobz:t(1135),xgvEl:t(727),ONhlG:t(1154)+"3|6|4|2",xfKhB:t(613)+t(1653)+t(761)+t(1335)+t(1788)+t(785)+t(1564)+t(1324)+t(1837),IIHls:function(a,n){return a!=n},QzUpG:function(a,n){return a instanceof n},cHTfF:function(a,n){return a||n},TGgno:"please p"+t(1653)+t(560)+t(1748),CeVbQ:function(a,n){return a instanceof n},BzVYk:function(a,n){return a(n)},MkqDf:function(a,n){return a===n},iRYpz:"sent",pKHXo:function(a,n){return a<n},lAqcp:t(894),tAMNN:function(a,n){return a!==n},lvlqi:t(849)+t(669)+t(1632),RVgZD:t(511)+"0",VyNVP:t(517),zlwmA:function(a,n,s,d,f){return a(n,s,d,f)},onXYa:function(a,n){return a(n)},GmSsS:function(a,n){return a===n},vOkTg:t(1029),iAxUg:t(438),MRmIz:function(a,n){return a*n},OftsL:function(a,n){return a!=n},hqpxx:t(1433),fyQqj:function(a,n){return a!=n},sfcLx:"Object",mgyig:t(1538)+"dWorkerGlobalScope",ErcIa:function(a,n){return a!=n},qkJiu:function(a,n){return a==n},KEzpb:function(a,n){return a!=n},bSAKW:function(a,n){return a!=n},qKNcv:t(1577)+t(660)+t(473),OnhwY:function(a,n){return a!=n},WAhgX:t(950)+t(506)};Lt.r(Te),Lt.d(Te,{FWS:()=>Wp,CustomErrorEvent:()=>Gd,createCloseEvent:()=>ht,ReconnectEvent:()=>qd,createErrorEvent:()=>ot,decodedFrame:()=>Zt,createOpenEvent:()=>Vd,CustomCloseEvent:()=>jd,createReconnectEvent:()=>sa,FrontierMessageEvent:()=>Kd,encodeFrame:()=>Bt,createMessageEvent:()=>Jd,OpenEvent:()=>$d,ErrorCode:()=>Qt,Event:()=>Vn,MessageEvent:()=>Wd});let r="";function i(a=""){let n=t,s="02",d=""+Date.now(),f=r||(r=e[n(1180)](h,a)),g=Math[n(1669)]().toString(16).slice(-6);return e[n(1338)](s,d)+f+g}function o(){let a=t,n={dMQAI:function(s,d){return e[q(1563)](s,d)},YIWNy:function(s,d,f){return e[q(1636)](s,d,f)},JgdcF:function(s,d){return e[q(419)](s,d)},IduPE:function(s,d,f){return e[q(1636)](s,d,f)}};if(e[a(419)](e[a(1074)],e[a(1847)]))return 1e4*Date.now()+Math[a(537)](e[a(552)](1e4,Math[a(1669)]()));if(this[a(527)]&&n[a(1444)](this[a(527)][a(1429)+"te"],this[a(1611)+"NG"])){this[a(1025)+a(1443)](),this[a(740)+"gTimeoutId"]=n.YIWNy(_0x22b276,this._ping.bind(this),this._options[a(963)+"rval"]);return}if(!this._ws||n.JgdcF(this[a(527)].readyState,this[a(913)]))return void this[a(1155)+a(669)]();this[a(527)]&&this[a(527)][a(1195)]("hi"),this["_reconne"+a(1857)+a(987)]=n[a(643)](_0x506c2a,this["_handleReconnect"+a(700)][a(909)](this),this[a(599)][a(380)+"outInter"+a(1093)])}function c(a){let n=t;return e.LxLCZ(Array(8)[n(885)]("0"),e[n(721)](parseInt,a,10)[n(644)](2))[n(1376)](-8)}function l(a){let n=t;return e[n(1209)](e[n(1180)](Array,4).join("0"),parseInt(a,2)[n(644)](16))[n(1376)](-4)}function u(a){let n=t;if(e[n(419)](e.NGfBg,e[n(693)])){let s=a[n(1283)](/\./)[n(1686)](g=>c(g)),d=[];return d[0]=e[n(1180)](l,e[n(1338)](s[0],s[1])),d[1]=e.Mmxxw(l,e.yeXci(s[2],s[3])),[e.EQqyn,n(864),"0000",n(864),e.EQqyn,e[n(719)],d[0],d[1]][n(885)]("")}else this[n(1629)+n(953)]()}function h(a){let n=t,s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[n(1227)](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?u(a):d?e[n(1180)](x,a):e.nIMfp}function x(a){let n=t,s="",d=[],f=0,g=0,m=!0,b=e[n(467)];if(e[n(1196)](a[n(1067)]("::"),-1)){let p=a[n(1283)]("::");for(let P=0;e[n(1277)](P,p[n(802)]);P++){let F=p[P];if(F.indexOf(":")>0){let G=F[n(1283)](":");m&&(f=G.length),g+=G[n(802)];for(let Z=0;e.kmzPu(Z,G.length);Z++)if(e[n(1527)](4,G[Z][n(802)])){let Y=b.substring(0,e[n(781)](4,G[Z][n(802)])),De=Y[n(452)](G[Z]);d.push(De)}else d[n(370)](G[Z]);m=!1}else{if(e[n(1527)](4,F[n(802)])){let G=b[n(1683)+"g"](0,e[n(485)](4,F.length)),Z=G[n(452)](F);d[n(370)](Z)}else d.push(F);m&&(f+=1),g+=1,m=!1}}let T="";for(let P=0;e[n(907)](P,e[n(1120)](8,g));P++)T=T.concat(b);for(let P=0;e[n(642)](P,d[n(802)]);P++)e[n(1563)](P,f)&&(s=s[n(452)](T)),s=s[n(452)](d[P]);return s}if(e[n(1563)](n(1715),e.GlIZu)){if(e.kmzPu(e[n(1120)](_0x1bacd4,_0x457a80),1))return"";let p="";for(let T=_0x57f8cc;e[n(907)](T,_0x449103);){let P=_0x4d1632[T++];if(P<=127)p+=_0x4f600c[n(1326)+n(1109)](P);else if(e[n(1606)](P,192)&&e.ChyXb(P,224))p+=_0x43e01d[n(1326)+n(1109)](e[n(898)](e[n(728)](e[n(1681)](31,P),6),63&_0x394656[T++]));else if(P>=224&&P<240)p+=_0xc61891["fromChar"+n(1109)](e[n(898)](e[n(609)](15,P)<<12,e[n(728)](63&_0x2e1f93[T++],6))|e.TulaE(63,_0xa1140f[T++]));else if(e.Jfyis(P,240)){let F=e[n(1120)](e[n(898)](e[n(1323)](e[n(1646)](e.HFaiY(7,P),18),e.EaFLi(e[n(1838)](63,_0x412273[T++]),12)),e.vxUtl(e[n(1792)](63,_0x5de75c[T++]),6))|e[n(340)](63,_0x13effa[T++]),65536);p+=_0x5f20b4[n(1326)+"Code"](e[n(875)](55296,e[n(1229)](F,10))),p+=_0x570b17[n(1326)+n(1109)](e[n(1130)](56320,e[n(1681)](1023,F)))}}return p}else{let p=a.split(":");for(let T=0;e[n(777)](T,p[n(802)]);T++){let P=p[T];if(e.uRjYB(4,p[T][n(802)])){let F=b.substring(0,e[n(1120)](4,p[T][n(802)])),G=F.concat(P);s=s.concat(G)}else s=s[n(452)](P)}return s}}function w(a,n){let s=t,d={dQJAN:function(m,b){return e[q(1180)](m,b)},HRULD:function(m){return e.WfMAC(m)}},f=a.key;if(f!==void 0)if(e[s(1563)](e[s(564)],e[s(564)]))e.qDmhB(he,n,10),e[s(1557)](H,n,f);else return 0;let g=a[s(1654)];e.Juomj(void 0,g)&&(s(1157)!==e.JnMQy?(he(n,18),e.kNSsf(H,n,g)):(this[s(1095)]=!1,d[s(1859)](_0x4a14ea,this[s(1389)+s(1419)+"utId"]),d.HRULD(_0x143145)))}function _(a){let n=t,s={};e:for(;!e.asZwL(J,a);)if(e[n(708)](e[n(1722)],"gvtEG")){let d=e[n(1180)](fe,a);switch(e.qzDEw(d,3)){case 0:break e;case 1:s[n(1616)]=O(a,e.Mmxxw(fe,a));break;case 2:s[n(1654)]=e[n(721)](O,a,e[n(1614)](fe,a));break;default:R(a,e[n(1838)](7,d))}}else switch(_0x42951b){case e.ocHpM:case e.HJonR:return{[n(1743)+_0x445b9c]:1,"x-tt-env":_0x1bbaa3};default:return{}}if(e[n(415)](void 0,s[n(1616)]))throw new Error(e[n(1855)]);if(e[n(708)](void 0,s[n(1654)]))throw new Error("Missing required"+n(1422)+"value");return s}function S(a){let n=t,s=e[n(1298)](D);return e[n(721)](E,a,s),B(s)}function E(a,n){let s=t,d=a[s(1238)];e[s(1527)](void 0,d)&&(e[s(1557)](he,n,8),e[s(715)](ft,n,d));let f=a.LogID;e.Juomj(void 0,f)&&(he(n,16),ft(n,f));let g=a.service;e[s(649)](void 0,g)&&(e[s(1295)](he,n,24),e.wbgZT(ft,n,e.UFTkE(L,g)));let m=a[s(798)];e[s(680)](void 0,m)&&(e[s(1557)](he,n,32),e[s(1256)](ft,n,e.XMrJO(L,m)));let b=a[s(1062)];if(e[s(649)](void 0,b))for(let De of b){he(n,42);let je=D();e[s(1552)](w,De,je),e[s(1582)](he,n,je.limit),e.aKdzI(K,n,je),e[s(1311)](k,je)}let p=a[s(1413)+s(1480)];e.uRjYB(void 0,p)&&(he(n,50),H(n,p));let T=a[s(999)+s(1346)];e[s(793)](void 0,T)&&(e[s(1724)](he,n,58),e[s(1582)](H,n,T));let P=a.payload;e[s(649)](void 0,P)&&(e[s(479)](he,n,66),he(n,P[s(802)]),pe(n,P));let F=a[s(803)];e[s(680)](void 0,F)&&(s(1602)===e[s(927)]?(_0x5320c1-=65536,_0x58297a+=e[s(1256)](_0x4d4961,e.yiorL(_0xbffd80,10)+55296,e.urPdM(e.yxumi(1023,_0x55d152),56320)),_0x3f0403+=3):(he(n,74),H(n,F)));let G=a[s(856)+s(733)];G!==void 0&&(e[s(1724)](he,n,82),e[s(448)](H,n,G));let Z=a[s(1137)];e[s(345)](void 0,Z)&&(he(n,90),H(n,Z));let Y=a[s(979)+"e"];Y!==void 0&&(e[s(1604)](he,n,96),e[s(1825)](ft,n,e[s(762)](L,Y)))}function v(a){let n=t;return e[n(1680)](A,e[n(1215)](N,a))}function A(a){let n=t,s={};e:for(;!e[n(1680)](J,a);){let d=e[n(1680)](fe,a);switch(e[n(1039)](d,3)){case 0:break e;case 1:s[n(1238)]=e[n(1724)](vt,a,!0);break;case 2:s[n(729)]=e[n(1552)](vt,a,!0);break;case 3:s[n(360)]=e[n(433)](fe,a);break;case 4:s[n(798)]=e[n(650)](fe,a);break;case 5:{let f=e[n(762)](I,a);(s.headers||(s[n(1062)]=[]))[n(370)](_(a)),a[n(1806)]=f;break}case 6:s[n(1413)+n(1480)]=O(a,e[n(1614)](fe,a));break;case 7:s[n(999)+n(1346)]=e.SIFrD(O,a,fe(a));break;case 8:s[n(1607)]=e[n(1736)](ce,a,e[n(936)](fe,a));break;case 9:s.LogIDNew=O(a,e[n(433)](fe,a));break;case 10:s[n(856)+"ming"]=O(a,e[n(1365)](fe,a));break;case 11:s[n(1137)]=e[n(1582)](O,a,fe(a));break;case 12:s[n(979)+"e"]=e.rBJdp(fe,a);break;default:e[n(1552)](R,a,7&d)}}if(e[n(596)](void 0,s.SeqID))throw new Error(e[n(866)]);if(e[n(708)](void 0,s[n(729)]))throw new Error(n(1601)+n(1418)+n(1422)+n(729));if(s[n(360)]===void 0)throw new Error(e[n(853)]);if(e[n(1563)](void 0,s.method))throw new Error(n(1601)+"required"+n(1422)+"method");return s}function I(a){let n=t,s=e[n(1386)](fe,a),d=a[n(1806)];return a[n(1806)]=e.MDJEP(a[n(1738)],s),d}function R(a,n){let s=t;if(e.yRGHQ(s(1605),"WnOZU"))switch(n){case 0:for(;128&e[s(789)](ie,a););break;case 2:V(a,e[s(1727)](fe,a));break;case 5:e[s(1411)](V,a,4);break;case 1:e[s(721)](V,a,8);break;default:throw new Error(e.dWaAi(e.atECx,n))}else _0x518fe1(e[s(955)]),this[s(416)](s(579)+s(1085)+"s",_0x2a3053),this[s(416)](e[s(1381)],_0x284ee3)}function L(a){let n=t;return a|=0,{low:a,high:e[n(1229)](a,31),unsigned:a>=0}}let y=[];function D(){let a=t;if(e[a(1856)]!==e[a(1831)]){let n=y[a(1001)]();return n?(n[a(1738)]=n[a(1806)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}else{if(this[a(582)+"osed"]=!0,this[a(1702)+"mer"](),this[a(1025)+"ngTimer"](),this[a(1388)+a(1392)+a(514)](),this[a(1132)+a(1163)]?.[a(962)](),!this[a(527)])return void this[a(1818)](e.LBiwt);if(this[a(527)].readyState===this[a(1471)]||this[a(527)][a(1429)+"te"]===this.CLOSING)return void this._debug(e[a(1257)]);this[a(1240)+a(1190)+"t"](_0x2f48e6,_0x2d2a11)}}function k(a){let n=t,s={qUQVJ:function(d,f,g){return d(f,g)}};if(e[n(1454)]===n(899))return new _0x3a3bda(d=>{let f=n;s[f(1296)](_0x1df2a6,d,this[f(1383)+f(388)+"e"](_0x2ab444))});y[n(370)](a)}function N(a){return{bytes:a,offset:0,limit:a[t(802)]}}function B(a){let n=t,s=a[n(1854)],d=a.limit;return e[n(708)](s[n(802)],d)?s:s[n(1115)](0,d)}function V(a,n){let s=t;if(e[s(1196)](e[s(1250)](a[s(1738)],n),a.limit))throw new Error(e[s(921)]);a.offset+=n}function J(a){let n=t;return e[n(1606)](a[n(1738)],a[n(1806)])}function te(a,n){let s=t;if(e.LloUY(e[s(354)],e.FsHlw))return this[s(1210)+s(586)+s(1328)+"t"]++,this[s(877)+s(697)+"nt"]();{let d=a.bytes,f=a[s(1738)],g=a.limit,m=e[s(1732)](f,n);if(e[s(1858)](m,d[s(802)]))if(e[s(1865)]===e[s(1865)]){let b=new Uint8Array(e[s(817)](2,m));b[s(986)](d),a[s(1854)]=b}else return this[s(878)][s(1587)];return a[s(1738)]=m,e.XqjQD(m,g)&&(a.limit=m),f}}function $(a,n){let s=t,d=a[s(1738)];if(e[s(1858)](d+n,a[s(1806)]))throw new Error(e[s(1466)]);return a[s(1738)]+=n,d}function ce(a,n){let s=t,d=e[s(1825)]($,a,n);return a[s(1854)][s(1115)](d,d+n)}function pe(a,n){let s=t,d=te(a,n[s(802)]);a.bytes.set(n,d)}function O(a,n){let s=t,d={RTuDf:function(T,P){return e[q(1575)](T,P)}},f=$(a,n),g=String[s(1326)+s(1109)],m=a[s(1854)],b="\uFFFD",p="";for(let T=0;e[s(907)](T,n);T++){let P=m[e[s(1732)](T,f)],F,G,Z,Y;if((128&P)===0)p+=e[s(1487)](g,P);else if(e.CSjhS(224,P)===192)if(e[s(1482)](T,1)>=n)p+=b;else if(F=m[e.Ggqwx(T+f,1)],e[s(793)](e.irRrU(192,F),128))p+=b;else if(Y=e.BAofd(e[s(1646)](31&P,6),63&F),Y<128)p+=b;else if(e[s(1329)](e.wkmPK,s(1761)))p+=g(Y),T++;else{let De=this[s(599)]["reconnec"+s(532)+s(543)](_0xed66e2,_0x35c887);this[s(1531)+s(615)+s(714)](e[s(494)](_0x4234bd,e[s(1255)],{code:_0x3d4ca6,reason:_0x235138,wasClean:!0,willReconnect:De})),De&&this._connect()}else if(e[s(1387)](e[s(1681)](240,P),224))if(e[s(1606)](e[s(1262)](T,2),n))p+=b;else if(F=m[e.yCcIq(T+f,1)],G=m[e[s(1129)](T,f)+2],(e[s(898)](F,e[s(1646)](G,8))&49344)!==32896)p+=b;else if(Y=e.BAofd(e.tdrYL(e[s(728)](e[s(498)](15,P),12),e[s(1428)](e[s(1270)](63,F),6)),e[s(412)](63,G)),e[s(1116)](Y,2048)||e[s(1606)](Y,55296)&&e[s(366)](Y,57343))p+=b;else if(e[s(809)]!=="nhytc")p+=e[s(1180)](g,Y),T+=2;else return _0x4e29d3(rYcMus[s(666)](_0x371fca,_0x239996));else if(e[s(1387)](e[s(1627)](248,P),240))if(e[s(368)](e.yCcIq(T,3),n))p+=b;else if(e.YHoLT===e[s(903)])F=m[e[s(1111)](T+f,1)],G=m[e[s(875)](e.zLorP(T,f),2)],Z=m[e[s(773)](T+f,3)],e[s(1734)](e[s(898)](F|e[s(728)](G,8),e[s(1170)](Z,16))&12632256,8421504)?p+=b:(Y=e.ZBdcO(e[s(1170)](e[s(1681)](7,P),18),e[s(1646)](e[s(609)](63,F),12))|e[s(1193)](63,G)<<6|63&Z,e[s(1116)](Y,65536)||e.ZCeBz(Y,1114111)?p+=b:(Y-=65536,p+=g(e[s(1130)](Y>>10,55296),e[s(663)](e[s(412)](1023,Y),56320)),T+=3));else{let De=_0x2177a7(e[s(614)],{message:_0xbcc380[s(973)],code:_0x194ff4[s(1468)+"OR"],error:_0x1abdfc});this[s(1531)+s(1161)+s(714)](De)}else p+=b}return p}function H(a,n){let s=t,d={BjSET:function(p,T){return p-T}},f=n[s(802)],g=0;for(let p=0;e[s(642)](p,f);p++){let T=n[s(841)+"At"](p);e[s(1679)](T,55296)&&e[s(366)](T,56319)&&e[s(773)](p,1)<f&&(T=e.HyyxR(e[s(916)](e.WympD(T,10),n[s(841)+"At"](++p)),56613888)),g+=e.raBEm(T,128)?1:e[s(1539)](T,2048)?2:e[s(1277)](T,65536)?3:4}e[s(721)](he,a,g);let m=e[s(1567)](te,a,g),b=a[s(1854)];for(let p=0;p<f;p++)if(e.isvJJ(e[s(939)],e.QbRXS)){let T=n[s(841)+"At"](p);T>=55296&&e[s(876)](T,56319)&&e[s(1539)](e[s(1241)](p,1),f)&&(T=e[s(1120)](e[s(1397)](T<<10,n[s(841)+"At"](++p)),56613888)),T<128?b[m++]=T:(T<2048?b[m++]=e.pDqTp(e[s(851)](e.hcYox(T,6),31),192):(e[s(918)](T,65536)?b[m++]=e[s(610)](T>>12&15,224):(b[m++]=e[s(610)](e.CSjhS(e.YeXiB(T,18),7),240),b[m++]=e[s(610)](e[s(1792)](e[s(1079)](T,12),63),128)),b[m++]=e[s(1270)](e.woJiY(T,6),63)|128),b[m++]=e[s(1590)](63&T,128))}else{let{initReconnectInterval:T,maxReconnectInterval:P,reconnectIntervalGrowFactor:F}=this[s(599)],G=T*_0x155db8[s(1633)](F,d[s(1650)](_0x5b032e,1));return G>P?P:G}}function K(a,n){let s=t;if(e.VPIbr(e[s(686)],e[s(686)])){let d=e[s(1411)](te,a,n[s(1806)]),f=a[s(1854)],g=n.bytes;for(let m=0,b=n[s(1806)];e.ChyXb(m,b);m++)f[e[s(385)](m,d)]=g[m]}else return new _0x117b9b(_0x1302b2,{message:_0x462843})}function ie(a){let n=t;return a[n(1854)][e[n(1260)]($,a,1)]}function Je(a,n){let s=te(a,1);a.bytes[s]=n}function fe(a){let n=t,s=0,d=0,f;do f=e[n(646)](ie,a),e.PsIAJ(s,32)&&(d|=e[n(1258)](127,f)<<s),s+=7;while(e[n(1193)](128,f));return d}function he(a,n){let s=t;for(n>>>=0;n>=128;)e[s(1473)](Je,a,e.bqFKE(e[s(558)](127,n),128)),n>>>=7;e[s(1785)](Je,a,n)}function vt(a,n){let s=t,d={XugKF:function(p,T){return e[q(530)](p,T)},decHz:function(p,T){return e[q(1129)](p,T)},xIIZU:function(p,T){return e[q(1184)](p,T)},kLMae:function(p,T){return p<T},EuysB:function(p,T,P){return e[q(937)](p,T,P)},SsOVs:function(p,T){return e[q(934)](p,T)},QCFSG:function(p,T){return p<<T}},f=0,g=0,m=0,b;if(b=e[s(440)](ie,a),f=e[s(1193)](127,b),e[s(1368)](128,b)&&(b=ie(a),f|=e[s(1428)](127&b,7),e.teIxu(128,b))){if(e[s(407)]===e[s(460)]){let p=dCXxzL[s(935)](_0xee06fd,_0x44f884),T=_0x27fe7c.limit;return _0x163bf7.limit=dCXxzL.decHz(_0xf1aedb[s(1738)],p),T}else if(b=e[s(1021)](ie,a),f|=e[s(895)](127,b)<<14,e[s(1707)](128,b)&&(b=e.yfvNQ(ie,a),f|=e.WympD(e[s(833)](127,b),21),e[s(1368)](128,b)&&(b=ie(a),g=127&b,e[s(1193)](128,b)&&(b=e[s(1365)](ie,a),g|=(127&b)<<7,e[s(1627)](128,b))))){if(e.wVfcj(e.qGPYh,e[s(384)])){let p=this[s(1061)][s(1149)](this[s(1293)]),T=_0x558ab5[s(1804)](e[s(800)](p,"{}"));return _0x2f37a8[s(651)](T)}else if(b=e[s(1086)](ie,a),g|=e.LeRYd(127&b,14),e[s(538)](128,b)&&(b=e.ODeEn(ie,a),g|=(127&b)<<21,e[s(1798)](128,b)))if(e[s(768)]("ZgyiB",e[s(1398)])){let p=0,T=_0xb6a07f,P=d[s(945)](_0x25ad8d,4);for(;d[s(1774)](T,P);){let{value:F,offset:G}=d[s(1450)](_0x4957bd,_0x2f6c30,T);T=G,p=d.SsOVs(d[s(1407)](p,8),0),p+=F}return{value:p,offset:P}}else b=e[s(534)](ie,a),m=e[s(1368)](127,b),128&b&&(b=ie(a),m|=e.TfSmw(e[s(1756)](127,b),7))}}return{low:e[s(357)](f,e[s(435)](g,28)),high:e[s(1320)](e[s(351)](g,4),e[s(814)](m,24)),unsigned:n}}function ft(a,n){let s=t,d=e[s(588)](n[s(423)],0),f=e.jjyFn(e[s(759)](e[s(934)](n[s(423)],28),e[s(413)](n[s(1316)],4)),0),g=e[s(1630)](n[s(1316)],24),m=e[s(1266)](0,g)?e[s(1589)](0,f)?d<16384?e[s(777)](d,128)?1:2:e[s(930)](d,2097152)?3:4:e.YbYVH(f,16384)?e[s(777)](f,128)?5:6:e[s(1231)](f,2097152)?7:8:e[s(918)](g,128)?9:10,b=e[s(645)](te,a,m),p=a[s(1854)];switch(m){case 10:p[b+9]=e.zlCOn(g>>>7,1);case 9:p[e[s(1113)](b,8)]=m!==9?e[s(629)](128,g):e[s(1252)](127,g);case 8:p[e[s(597)](b,7)]=m!==8?e[s(610)](e.LynZr(f,21),128):e.zDNkE(f>>>21,127);case 7:p[e.FPotb(b,6)]=e.yRGHQ(7,m)?e[s(1288)](e[s(1863)](f,14),128):e[s(925)](f,14)&127;case 6:p[b+5]=e[s(419)](6,m)?e[s(991)](f>>>7,128):e[s(1220)](e.ezuSl(f,7),127);case 5:p[e[s(884)](b,4)]=e.fDwqy(5,m)?e.YnovX(128,f):e[s(1258)](127,f);case 4:p[e.inFlv(b,3)]=e[s(649)](4,m)?e[s(1042)](e[s(925)](d,21),128):e[s(833)](e[s(1610)](d,21),127);case 3:p[e[s(445)](b,2)]=m!==3?e[s(759)](d>>>14,128):e.YXnXC(d>>>14,127);case 2:p[e.CZNNZ(b,1)]=e.miIOS(2,m)?e[s(1528)](d>>>7,128):e[s(447)](d>>>7,127);case 1:p[b]=e[s(680)](1,m)?128|d:e[s(1648)](127,d)}}function Zt(a){return e[t(1086)](v,a)}function Bt(a){return e.asZwL(S,a)}let Xt=65536,Gr=t(1414),me=e[t(1560)](Xt,Xt),Se=e.MRmIz(me,me),Jn=Se/2,Re=String[t(1503)+"e"][t(841)+"At"];class ue{constructor(n,s,d){let f=t;this[f(1268)]=!0,this[f(423)]=e[f(1528)](0,n),this.high=e[f(820)](0,s),this[f(561)]=!!d}static[t(1268)](n){let s=t;return e[s(854)](e[s(1357)],s(1490))?n&&e[s(415)](!0,n.isLong):this[s(1061)]?.del(_0x448da2)}static[t(1666)](n,s,d){return new ue(n,s,d)}static[t(746)+"s"](n,s,d){let f=t;return d?ue[f(746)+f(1019)](n,s):ue["fromByte"+f(533)](n,s)}static fromBytesLE(n,s){let d=t;return new ue(e[d(629)](n[0]|n[1]<<8,n[2]<<16)|n[3]<<24,e[d(1251)](e[d(1107)](e[d(1107)](n[4],e[d(723)](n[5],8)),e[d(1548)](n[6],16)),e[d(940)](n[7],24)),s)}static fromBytesBE(n,s){let d=t;return new ue(e[d(616)](e[d(940)](n[4],24),n[5]<<16)|n[6]<<8|n[7],e[d(1042)](e[d(717)](e[d(525)](n[0]<<24,n[1]<<16),e[d(1435)](n[2],8)),n[3]),s)}static fromHash(n){let s=t;return e[s(1117)](n,Gr)?Hd:new ue(e[s(1610)](Re[s(1069)](n,0)|Re[s(1069)](n,1)<<8|e[s(751)](Re.call(n,2),16)|Re[s(1069)](n,3)<<24,0),e.fQDpk(e[s(1625)](Re[s(1069)](n,4),Re[s(1069)](n,5)<<8)|e[s(1548)](Re[s(1069)](n,6),16)|e[s(1134)](Re.call(n,7),24),0),!0)}[t(492)](){let n=t;return String[n(1326)+n(1109)](e[n(1310)](255,this[n(423)]),e[n(1004)](e[n(347)](this[n(423)],8),255),e[n(1179)](e[n(1439)](this[n(423)],16),255),e[n(1013)](this.low,24),e[n(656)](255,this[n(1316)]),e[n(914)](e[n(925)](this.high,8),255),e[n(1544)](e[n(1863)](this[n(1316)],16),255),e[n(1610)](this[n(1316)],24))}static[t(1204)+"er"](n,s=!0){let d=t;if(isNaN(n))return s?rp:Hd;if(s){if(n>=Se)return sp}else{if(e[d(366)](n,-Jn))return op;if(e[d(368)](e.vBQvq(n,1),Jn))return ip}return ue[d(1666)](e[d(1049)](n%me,0),e.iDKFG(n,me)|0,s)}[t(1651)](){let n=t;return e[n(1367)](n(1510),e[n(1511)])?this[n(561)]?e.Ggqwx(e[n(1560)](e.kKLzN(this[n(1316)],0),me),e[n(434)](this.low,0)):e[n(1720)](this[n(1316)],me)+e.NEHeQ(this[n(423)],0):e[n(1370)](e.NsVNO,typeof _0x859b04)&&(_0x432f34 instanceof _0x1f2d48||_0x52b5cf[n(461)]&&e[n(509)](_0x23b3ce.buffer,_0x6df54a))||e.pAdMj(e.NsVNO,typeof _0x34b6ba)?"":(_0x2ecec9[n(1804)](_0x48a260),n(1759)+n(1271))}[t(601)](){let n=t;return this[n(1316)]===0&&e[n(1329)](0,this.low)}[t(402)](n){let s=t;ue[s(1268)](n)||(n=ue[s(1204)+"er"](n));let d=e[s(1039)](this[s(1316)],16),f=e[s(1310)](65535,this[s(1316)]),g=this[s(423)]>>>16,m=e[s(1270)](65535,this[s(423)]),b=e[s(925)](n[s(1316)],16),p=e[s(498)](65535,n[s(1316)]),T=n[s(423)]>>>16,P=65535&n[s(423)],F=0,G=0,Z=0,Y=0;return Y+=m+P,Z+=Y>>>16,Y&=65535,Z+=e[s(1458)](g,T),G+=e[s(873)](Z,16),Z&=65535,G+=e[s(980)](f,p),F+=e.YlYzr(G,16),G&=65535,F+=e[s(773)](d,b),F&=65535,ue[s(1666)](e[s(975)](e[s(868)](Z,16),Y),e[s(359)](F,16)|G,this[s(561)])}[t(1018)](n){let s=t;return ue[s(1268)](n)||(n=ue[s(1204)+"er"](n)),e[s(861)](this[s(561)],n[s(561)])&&e[s(481)](e[s(347)](this[s(1316)],31),1)&&e.uMdvb(e[s(1610)](n[s(1316)],31),1)?!1:e[s(1685)](this[s(1316)],n[s(1316)])&&e[s(821)](this[s(423)],n[s(423)])}[t(685)](){let n=t;return e[n(1054)](-1,this[n(423)])&&e[n(1243)](-1,this[n(1316)])?ue[n(1666)](0,0,this[n(561)]):e[n(867)](-1,this[n(423)])?ue.fromBits(0,e[n(1136)](this[n(1316)],1),this.unsigned):ue[n(1666)](this[n(423)]+1,this[n(1316)],this[n(561)])}[t(996)](n){let s=t;if(e[s(1576)](e.dEHga,e[s(482)]))this[s(491)+"er"]&&_0x226d43["addEvent"+s(514)](e[s(808)],this[s(1676)+s(1125)]),this[s(491)+"er"]&&_0x884c02[s(1780)+s(514)](e[s(1124)],this[s(1676)+s(403)]),this[s(491)+"er"]&&_0x3afc28[s(1780)+s(514)](s(1228),this[s(1820)+s(1159)]),this[s(491)+"er"]&&_0x1b139d[s(1780)+"Listener"](s(1805),this[s(1820)+s(1754)]);else return n?this[s(623)+"E"]():this.toBytesBE()}[t(623)+"E"](){let n=t;if(!e.taEln(e[n(1667)],e[n(1441)])){let s=this[n(1316)],d=this[n(423)];return[255&d,e[n(1368)](e[n(1622)](d,8),255),e[n(395)](e.loFyV(d,16),255),e[n(966)](d,24),e[n(1821)](255,s),e[n(994)](e[n(1421)](s,8),255),e.zZwmr(s,16)&255,e[n(1253)](s,24)]}}[t(1322)+"E"](){let n=t,s=this[n(1316)],d=this[n(423)];return[e[n(958)](s,24),e[n(1860)](s,16)&255,s>>>8&255,e[n(412)](255,s),e[n(1039)](d,24),e[n(563)](d>>>16,255),e[n(1176)](d>>>8,255),e[n(1838)](255,d)]}}let Hd=new ue(0,0,!1),rp=new ue(0,0,!0),ip=ue[t(1666)](-1,2147483647,!1),sp=ue.fromBits(-1,-1,!0),op=ue[t(1666)](0,-2147483648,!1);var Qt=(function(a){let n=t,s=(n(836)+n(364))[n(1283)]("|"),d=0;for(;;){switch(s[d++]){case"0":a[a[e[n(792)]]=5004]=e.wxcAF;continue;case"1":a[a[e.AjNit]=5001]=e[n(1692)];continue;case"2":a[a[e[n(673)]]=5005]=e[n(673)];continue;case"3":a[a[e[n(424)]]=5003]=e[n(424)];continue;case"4":a[a[e.epiXP]=5002]=e[n(1861)];continue;case"5":return a}break}})({});class Vn{constructor(n){let s=t;this[s(374)]=n,this[s(612)]=null}}class qd extends Vn{constructor(n,s){let d=t;super(n),this[d(973)]=s&&s[d(973)]||null}}class Gd extends Vn{constructor(n,s){let d=t,f=e[d(1446)].split("|"),g=0;for(;;){switch(f[g++]){case"0":this[d(622)]=s&&s[d(622)]||0;continue;case"1":this[d(832)]=s&&s[d(832)]||0;continue;case"2":this[d(880)]=s&&s[d(880)]||"";continue;case"3":super(n);continue;case"4":this[d(973)]=s&&s.message||"";continue;case"5":this[d(1364)]=s&&s.error||null;continue;case"6":this[d(1773)]=s&&s[d(1773)]||5001;continue}break}}}class jd extends Vn{constructor(n,s){let d=t,f=e[d(1460)][d(1283)]("|"),g=0;for(;;){switch(f[g++]){case"0":this.code=s&&s.code||0;continue;case"1":this[d(763)]=s&&s.reason||"";continue;case"2":super(n);continue;case"3":this[d(1141)+d(1581)]=s&&s["willReco"+d(1581)]||!1;continue;case"4":this[d(1078)]=s&&s.wasClean||!1;continue}break}}}class Wd extends Vn{constructor(n,s){let d=t;super(n),this.data=s&&s[d(1024)]||null}}class Kd extends Wd{constructor(n,s){let d=t,f={uOJVJ:function(g,m){return e[q(1265)](g,m)},eeOQF:function(g,m){return e[q(1711)](g,m)},MeJgw:function(g,m){return e.teIxu(g,m)}};e[d(483)]===e[d(1235)]?(_0x140a3f[_0x53994b++]=f[d(788)](f[d(672)](_0x5750a8,6),192),_0x1d831b[_0xbd4fcd++]=f[d(788)](f[d(562)](63,_0x152ee4),128)):(super(n),this[d(1024)]=s&&s[d(1024)]||null,this[d(973)]=s&&s[d(973)]||null)}}class $d extends Vn{constructor(n,s){let d=t;super(n),this[d(1024)]=s&&s[d(1024)]||null}}function ot(a,{message:n,code:s,error:d}){return new Gd(a,{message:n,code:s,error:d})}function ht(a,{code:n,reason:s,wasClean:d,willReconnect:f}){return new jd(a,{code:n,reason:s,wasClean:d,willReconnect:f})}function Jd(a,{data:n,message:s}){return new Kd(a,{data:n,message:s})}function Vd(a,{data:n}){return new $d(a,{data:n})}function sa(a,{message:n}){let s=t,d={PPLKq:function(f,g){return e[q(1763)](f,g)},FFWwb:function(f,g){return e[q(1753)](f,g)},EEVnC:e.yIeQh};if(e[s(1467)](e[s(459)],e[s(681)]))return new qd(a,{message:n});if(cWHvVX[s(508)](cWHvVX.FFWwb(_0x292f0c[s(1738)],_0x1e44c9),_0x1042bb[s(1806)]))throw new _0x308cdc(cWHvVX[s(744)]);_0x2a0fa2[s(1738)]+=_0x21574d}class Yd{constructor(n,s){let d=t;this[d(1139)+"s"]=n,this.maxRetries=s,this[d(1583)+d(1030)]=0,this[d(1210)+d(586)+d(1328)+"t"]=0}[t(739)+t(771)+t(401)](){let n=t;this[n(1583)+n(1030)]=0,this[n(1210)+n(586)+n(1328)+"t"]=0}[t(1183)+"es"](){let n=t,s={yBrsK:function(d){return e.GCBeh(d)},Hyfcq:function(d,f){return e[q(425)](d,f)}};if(e[n(1329)](n(850),e[n(1464)])){let d=PQZZWH[n(1522)](_0x3ed144);return _0x306c26(_0xc693fe,d),PQZZWH[n(1426)](_0x195581,d)}else this[n(1210)+"ndpointT"+n(1328)+"t"]=0}[t(877)+"ntEndpoint"](){let n=t,s={HuNAr:function(d,f){return e.eZmEw(d,f)},Ubqjl:function(d,f){return e[q(1300)](d,f)},ZWcDO:function(d,f){return e[q(1635)](d,f)},DxecD:function(d,f){return d<<f},JxmvI:function(d,f){return e.VBCQM(d,f)},usYtO:function(d,f){return d&f},SPLwY:function(d,f){return d>=f},bBfpa:function(d,f){return d<=f}};if(e[n(1287)](e[n(373)],e[n(399)]))return this[n(1139)+"s"][this[n(1583)+n(1030)]];_0x8e2a77=_0x379712[PHTlwp[n(1457)](PHTlwp[n(1457)](_0x2fa31b,_0x25fa75),1)],_0xd3d09a=_0x5dbf8d[_0x589fbc+_0x508074+2],((_0x51bbe7|PHTlwp[n(960)](_0xffe86,8))&49344)!==32896?_0x2915d6+=_0x16f453:(_0x46067d=PHTlwp.ZWcDO(PHTlwp[n(977)](15&_0x2ef6e7,12),PHTlwp.JxmvI(63,_0x47e36f)<<6)|PHTlwp[n(1462)](63,_0xeb9dea),_0x3b9f4c<2048||PHTlwp.SPLwY(_0xdf791,55296)&&PHTlwp.bBfpa(_0x10f83d,57343)?_0x24038e+=_0x2f12d1:(_0x22f97e+=_0x209739(_0x5e9693),_0x11cc01+=2))}["getCurre"+t(697)+"ntTriesCount"](){let n=t;return this["currentE"+n(586)+n(1328)+"t"]}[t(1306)+t(1342)+"es"](){let n=t;return!!(this["currentI"+n(1030)]>=this[n(1139)+"s"][n(802)]||e.GJUJD(this[n(1583)+n(1030)],e[n(398)](this[n(1139)+"s"][n(802)],1))&&this["currentEndpointT"+n(1328)+"t"]===this.maxRetries)}["checkCur"+t(842)+t(1644)+t(1286)+t(1505)](){let n=t;return this[n(1583)+n(1030)]==this[n(1139)+"s"][n(802)]?!0:e[n(905)](this[n(1210)+"ndpointT"+n(1328)+"t"],this[n(882)+"es"])}["replaceB"+t(1106)+"pointAndUpdateCo"+t(1332)](){let n=t;return this[n(1210)+n(586)+n(1328)+"t"]=1,this[n(1583)+n(1030)]++,this.endpoints[this[n(1583)+"ndex"]]}["getCurrentEndpoi"+t(1058)+t(1533)](){let n=t;return this[n(1210)+n(586)+n(1328)+"t"]++,this[n(877)+"ntEndpoint"]()}}let Yn=(e[t(835)](e[t(886)],typeof globalThis)&&e[t(1703)]===globalThis[t(1449)+t(1236)][t(1186)]||e[t(556)](e[t(886)],typeof window)&&e[t(1054)](e[t(1703)],window[t(1449)+t(1236)][t(1186)]))&&e[t(1090)](e[t(886)],typeof document),In=e[t(797)](e[t(886)],typeof globalThis)&&(e[t(1687)](e[t(1041)],globalThis.constructor[t(1186)])||e[t(748)]===globalThis[t(1449)+t(1236)][t(1186)])&&e.OftsL(e[t(886)],typeof tt),jr=(e[t(496)](e[t(886)],typeof globalThis)&&e[t(344)](e[t(1041)],globalThis["construc"+t(1236)][t(1186)])||e[t(1330)]("undefined",typeof globalThis)||e[t(1670)](e[t(886)],typeof globalThis)&&!!globalThis["WeixinJS"+t(1827)])&&e.bSAKW(e[t(886)],typeof wx),Wr=e[t(1370)](e[t(886)],typeof globalThis)&&(e[t(1591)](e[t(748)],globalThis[t(1449)+t(1236)].name)||t(1574)+t(1472)+t(1076)===globalThis[t(1449)+t(1236)].name||e[t(924)](e[t(568)],globalThis[t(1449)+t(1236)][t(1186)]))&&e[t(886)]!=typeof self,ap=e[t(886)]!=typeof globalThis&&t(1770)===globalThis[t(1449)+t(1236)][t(1186)]&&t(1689)+"d"!=typeof global&&e[t(1041)]===global[t(1449)+t(1236)][t(1186)]&&e[t(1038)]("undefined",typeof process)&&!!process[t(1803)];class oa{constructor(){let n=t;this[n(1488)+"rs"]={}}[t(1127)](n,...s){let d=t,f={jzIDZ:e[d(1846)],AHNqh:e.KQHmr};if(e[d(1569)](e[d(696)],e[d(901)])){let g=this._listeners[n];if(g)g[d(1376)]()[d(1816)](m=>m.fn[d(874)](m[d(834)],s));else if(e[d(821)](e[d(614)],n)&&!this[d(499)]){let m=s[d(802)]&&s[0];if(e.Yayvn(m,Error))throw m;let b=new Error(e[d(1718)](e[d(1015)],m?" ("+m[d(973)]+")":""));throw b[d(418)]=m,m}return this}else return f[d(372)]==typeof _0x767652?f.AHNqh:""}[t(416)](n,s){let d=t;if(e[d(1687)](void 0,n))this[d(1488)+"rs"]={};else if(e[d(1589)](void 0,s))this._listeners[n]=null;else{let f=this[d(1488)+"rs"][n];if(f)for(let g=0;e[d(662)](g,f[d(802)]);)f[g].fn===s?f[d(625)](g,1):++g}return this}on(n,s,d){let f=t;return(this[f(1488)+"rs"][n]||(this[f(1488)+"rs"][n]=[])).push({fn:s,ctx:d||this}),this}}class cp extends oa{["_formatE"+t(450)+t(349)](n){let s=t;return n[s(1828)]||n[s(1333)]?(s(598)+" "+(n.errMsg||"")+" code: "+(n[s(1333)]||""))[s(1047)]():JSON.stringify(n)}constructor(n,s,d){let f=t;if(e[f(1452)]!==e[f(1675)])super(),this[f(878)]=null,jr&&wx[f(1147)+f(1740)]&&(this[f(878)]=wx[f(1147)+f(1740)]({url:n,protocols:s,header:d,fail:this[f(1356)+"ocketFai"+f(410)][f(909)](this),success:this[f(1356)+f(840)+"cessHand"+f(1263)][f(909)](this)})),In&&tt[f(1147)+f(1740)]&&(this[f(878)]=tt[f(1147)+f(1740)]({url:n,protocols:s,header:d,fail:this[f(1356)+f(442)+f(410)].bind(this),success:this[f(1356)+f(840)+f(1553)+"ler"].bind(this)}));else{_0x1b84ad[f(1268)](_0x5b43a6)||(_0x487f64=_0x40a1ac[f(1204)+"er"](_0x4a3799));let g=e[f(342)](this[f(1316)],16),m=e[f(563)](65535,this[f(1316)]),b=e[f(1439)](this[f(423)],16),p=65535&this[f(423)],T=e[f(1610)](_0x39cb16[f(1316)],16),P=65535&_0x953803.high,F=e.zolbY(_0x5a257c[f(423)],16),G=e.tQpXo(65535,_0x579e90[f(423)]),Z=0,Y=0,De=0,je=0;return je+=p+G,De+=e[f(934)](je,16),je&=65535,De+=e.xgnpK(b,F),Y+=e[f(1852)](De,16),De&=65535,Y+=e[f(1753)](m,P),Z+=e[f(458)](Y,16),Y&=65535,Z+=e.yCcIq(g,T),Z&=65535,_0x4c9659[f(1666)](e[f(975)](De<<16,je),e[f(1728)](e[f(751)](Z,16),Y),this.unsigned)}}["_createS"+t(840)+t(1553)+t(1263)](){let n=t,s={oline:function(d,f){return e.gMjQu(d,f)},MBcvQ:e[n(437)]};Promise[n(1169)]().then(()=>{let d=n;if(s[d(618)](s[d(929)],s[d(929)]))this[d(1629)+d(953)]();else return d(1056)+"_"+this[d(1822)]})}[t(1356)+t(442)+"lHandler"](n){let s=t,d={MOwLB:e[s(614)],DrmqK:function(f,g,m){return e[s(942)](f,g,m)},Rqpwr:e.BIcdc};Promise[s(1169)]().then(()=>{let f=s,g=ot(d[f(648)],{message:this[f(1714)+f(450)+f(349)](n)});this[f(1127)](f(1364),g);let m=d.DrmqK(ht,d[f(1114)],{reason:this[f(1714)+f(450)+f(349)](n)});this[f(1127)](d[f(1114)],m)})}[t(1629)+t(953)](){let n=t,s={yNUKw:"message"};this[n(878)][n(1588)](d=>{let f=n;this[f(1127)](f(422),Vd(e.XDbVl,{...d,data:d.errMsg||""}))}),this[n(878)][n(1012)](d=>{let f=n;this[f(1127)](e[f(1255)],ht(e.BIcdc,{...d}))}),this._socket.onMessage(d=>{let f=n;this[f(1127)](f(973),Jd(s[f(1776)],{...d}))}),this[n(878)][n(1619)](d=>{let f=n;this[f(1127)](e.WlDjb,e[f(628)](ot,f(1364),{...d,message:d.errMsg||""}))})}send(n){let s=t,d={vPNHj:s(1364),taLAs:function(f,g,m){return e[s(722)](f,g,m)}};if(e[s(1467)](e[s(409)],s(1716)))if(e[s(1701)](n,Uint8Array)){let f=n[s(461)][s(1376)](n[s(1842)+"et"],e[s(1668)](n[s(400)+"th"],n.byteOffset));this._socket&&this[s(878)][s(1195)]({data:f,fail:g=>{let m=s;this[m(1127)](e[m(614)],ot(e[m(614)],{message:this["_formatErrorMess"+m(349)](g)}))}})}else this[s(878)]&&this._socket.send({data:n,fail:f=>{let g=s;this[g(1127)](d[g(1036)],d[g(1461)](ot,d[g(1036)],{message:this[g(1714)+g(450)+g(349)](f)}))}});else this[s(783)+s(782)+s(750)]=_0x3706ee,_0x515fbe?this[s(1676)+s(1125)]():this["_handleO"+s(403)]()}[t(755)](n,s){let d=t;this[d(878)]&&this._socket[d(755)]({code:n,reason:s})}[t(1780)+t(514)](n,s){this.on(n,s)}[t(1729)+t(1246)+t(997)](n,s){this[t(416)](n,s)}get readyState(){let n=t;return this._socket[n(1429)+"te"]}get[t(1340)+"pe"](){let n=t;return this[n(878)][n(1340)+"pe"]}set[t(1340)+"pe"](n){}get[t(1308)](){return this[t(878)].url}get[t(1587)](){let n=t;return this[n(878)][n(1587)]}get[t(1348)+"ns"](){let n=t;return this._socket[n(1348)+"ns"]}get["buffered"+t(446)](){return 0}}function dp(a,n){let s=t;if(n)return new n(a.url,a[s(1587)]);if(e.lMYnb(jr,In))return new cp(a[s(1308)],a[s(1587)],a.headers);if(e[s(800)](Yn,Wr)&&e[s(886)]!=typeof WebSocket&&WebSocket)return new WebSocket(a[s(1308)],a[s(1587)+"s"])}function lp(a){let n=t;if(e.RQFHw(e.TtiWV,e[n(1168)])){let s=e.aCDGJ[n(1283)]("|"),d=0;for(;;){switch(s[d++]){case"0":if(jr&&wx["connectS"+n(1740)])return!0;continue;case"1":if(In&&tt[n(1147)+n(1740)])return!0;continue;case"2":return!1;case"3":if(a)return!0;continue;case"4":if(e[n(800)](Yn,Wr)&&e.pAdMj(e[n(886)],typeof WebSocket)&&WebSocket)return!0;continue}break}}else this[n(1391)+n(1346)]=_0x7fd417,this[n(527)]&&(this._ws[n(1340)+"pe"]=_0x32ce06)}function Zd(a,n,s){let d=t,f={aHbxz:function(b,p){return b<=p},MQXfj:function(b,p){return e[q(1613)](b,p)}},g=-1;async function m(b){let p=q;return f.aHbxz(b,g)?Promise.reject(new Error(p(1128)+"alled multiple times in process")):(g=b,b===s[p(802)]?Promise[p(1169)]():s[b][p(909)](a)(n,m[p(909)](null,f.MQXfj(b,1))))}e[d(534)](m,0)}function Xd(a){let n=t,s=0,d=0;for(let f=0;f<a[n(802)];++f)e.uRjYB(e[n(1750)],n(1660))?(d=a[n(841)+"At"](f),e.akcOE(d,128)?s+=1:e[n(662)](d,2048)?s+=2:e[n(1145)](e[n(1362)](64512,d),55296)&&e[n(1659)](64512&a[n(841)+"At"](e.Ggqwx(f,1)),56320)?(++f,s+=4):s+=3):(this[n(491)+"er"]&&_0x54d6af[n(1729)+n(1246)+n(997)](e.JRTra,this["_handleO"+n(1125)]),this[n(491)+"er"]&&_0x49c146[n(1729)+n(1246)+n(997)](e[n(1124)],this[n(1676)+n(403)]),this[n(491)+"er"]&&_0x1aef30[n(1729)+n(1246)+n(997)](n(1228),this[n(1820)+n(1159)]),this[n(491)+"er"]&&_0x4599af[n(1729)+n(1246)+n(997)](e[n(1420)],this[n(1820)+"ageShow"]));return s}function Qd(a,n,s){let d=t;if(e[d(1028)](s-n,1))return"";let f="";for(let g=n;e.gTXbu(g,s);){let m=a[g++];if(e.PSZuu(m,127))f+=String[d(1326)+"Code"](m);else if(e[d(1192)](m,192)&&e[d(642)](m,224))f+=String[d(1326)+"Code"](e.NIYDh(e.JyqcB(e[d(1270)](31,m),6),e.sglRk(63,a[g++])));else if(e.mYPuh(m,224)&&e[d(777)](m,240))f+=String["fromChar"+d(1109)](e.XLLCP(e[d(1323)](e[d(778)](15,m)<<12,e[d(1188)](e.kVQsB(63,a[g++]),6)),e[d(851)](63,a[g++])));else if(e[d(426)](m,240)){let b=e[d(485)](e[d(1107)](e.nisSj(e[d(412)](7,m),18)|e[d(647)](e[d(1099)](63,a[g++]),12),e[d(421)](e[d(563)](63,a[g++]),6))|e[d(1313)](63,a[g++]),65536);f+=String[d(1326)+d(1109)](55296+e.YeXiB(b,10)),f+=String.fromCharCode(e[d(875)](56320,1023&b))}}return f}function aa(a,n,s){let d=t,f=s,g,m;for(let b=0;e[d(918)](b,a.length);++b)if(g=a[d(841)+"At"](b),e.YeluO(g,128))n[s++]=g;else if(g<2048)n[s++]=e.dqTfN(g,6)|192,n[s++]=e.ZGLhd(63&g,128);else if(e.kWHKi(64512,g)===55296&&e.UZWgm(64512,m=a[d(841)+"At"](e[d(1638)](b,1)))===56320){let p=e.LfqXu[d(1283)]("|"),T=0;for(;;){switch(p[T++]){case"0":n[s++]=e[d(1517)](e.CSjhS(e[d(1079)](g,12),63),128);continue;case"1":n[s++]=e[d(906)](e[d(1229)](g,18),240);continue;case"2":g=e.LxLCZ(e.azvsn(65536,e.cKqUx(e[d(487)](1023,g),10)),e[d(412)](1023,m));continue;case"3":n[s++]=e.HRAiC(e[d(577)](g,6)&63,128);continue;case"4":n[s++]=e[d(1512)](63,g)|128;continue;case"5":++b;continue}break}}else n[s++]=e[d(991)](e[d(1372)](g,12),224),n[s++]=e[d(1032)](g>>6,63)|128,n[s++]=e[d(1320)](63&g,128);return e[d(398)](s,f)}async function el(a){let n=t;if(e[n(1691)](e[n(1455)],e[n(1264)])){if(e[n(1387)](e[n(1846)],typeof a))if(e.ALOAj(e[n(1290)],e[n(1171)])){let s=new Uint8Array(e[n(1057)](Xd,a));return e[n(1385)](aa,a,s,0),s}else this.endpoints=_0x53849a,this[n(882)+"es"]=_0x784601,this[n(1583)+"ndex"]=0,this.currentEndpointTriesCount=0;return e[n(509)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(461)],a[n(1842)+"et"],a.byteLength)}else return e[n(1730)](this[n(1583)+"ndex"],this[n(1139)+"s"][n(802)])?!0:e.sDqpL(this["currentE"+n(586)+n(1328)+"t"],this.maxRetries)}function up(a){let n=t;try{return e[n(1370)](e[n(1846)],typeof a)&&(a instanceof ArrayBuffer||a.buffer&&a[n(461)]instanceof ArrayBuffer)||e[n(1846)]!=typeof a?"":(JSON.parse(a),n(1759)+n(1271))}catch{if(e.uRjYB(e[n(1634)],e.XzlYJ))for(var s in _0x190972)_0x3ec8e6.o(_0x254e97,s)&&!_0x19439c.o(_0x24fd25,s)&&_0x1ab875[n(1795)+"operty"](_0x11070c,s,{enumerable:!0,get:_0x357242[s]});else return e[n(1006)](n(1508),typeof a)?e.KQHmr:""}}let fp=(a,n)=>{let s=t;switch(a){case e.ocHpM:case s(1267):return{["x-use-"+a]:1,"x-tt-env":n};default:return{}}};class hp{constructor(n){let s=t,d={ZzJnn:function(f,g){return f===g},ElUkg:function(f,g){return e.VAZCS(f,g)},JruCY:e[s(1578)],erZDZ:e.cEcGd,mAMWq:function(f,g,m,b){return e[s(1385)](f,g,m,b)},twqhb:function(f,g,m){return e.KKDFB(f,g,m)}};if(e[s(1336)]!==e[s(1336)]){let{pingInterval:f,pingFrequency:g}=this[s(599)];if((d[s(522)]("hi",_0x48f179.data)&&d.ElUkg("always",g)||d[s(522)](d[s(968)],g))&&(this[s(1025)+s(1443)](),this[s(1127)](d.erZDZ,s(972)),this[s(740)+s(453)+"Id"]=_0x15d168(this[s(948)][s(909)](this),f)),d.ElUkg("hi",_0x3a991d[s(1024)]))return;try{d.mAMWq(_0x2364d7,this,_0xa87788,[_0x42ddff,_0x27f97b,_0x5abd0e,_0x14b7fa,_0x5850b0,_0x117475])}catch(m){let b=d[s(827)](_0x1298f1,s(1364),{message:m[s(973)],code:_0x5900de[s(1555)+"ERROR"],error:m});this[s(1531)+s(1161)+s(714)](b)}}else this["maxLossC"+s(1172)]=n,this.count=0}[t(640)](){let n=t,s={jkazo:function(d,f,g){return e.jwJPA(d,f,g)},NEhbM:function(d,f){return e[q(1064)](d,f)},jWOCo:e[n(614)]};if(n(1486)===e[n(462)]){let d=this[n(549)+"tManager"]?.[n(1306)+"chMaxTries"](),f=this[n(549)+"tManager"]?.[n(877)+n(697)+"nt"]();if(d&&!_0x2a53d5[n(973)]){let g=n(1682)+f+(n(495)+n(807)+"es reached");this[n(1531)+"hErrorEv"+n(714)](s[n(754)](_0x2d56a5,n(1364),{message:g,code:_0x576ea0[n(605)+n(677)+"R"],error:_0x3172c6}));return}this[n(527)]&&s.NEhbM(this[n(527)][n(1429)+"te"],this[n(913)])&&this[n(989)+n(813)](),this["_dispatc"+n(1161)+"ent"](_0x3a689d(s[n(865)],{message:_0x33f127.message,code:_0x28b3a3["NATIVE_E"+n(1354)],error:_0x11bd0f}))}else this[n(578)]++}[t(1306)+"chMaxCount"](){let n=t;return this[n(578)]>=this["maxLossC"+n(1172)]}[t(990)+t(1772)](n=0){let s=t;this[s(589)+s(1172)]=n,this[s(578)]=0}}async function xp(a){let n=t,s={WERIh:function(d,f){return e[q(1618)](d,f)},nxvkF:function(d,f){return e[q(1863)](d,f)},jAwaD:function(d,f){return e[q(883)](d,f)},bIHCu:function(d,f){return e.vRKEc(d,f)},lIgYt:function(d,f){return d>>>f},XXZhb:function(d,f){return e[q(762)](d,f)},qIgyI:function(d,f){return e[q(436)](d,f)},SclQS:e[n(786)],BKCML:e[n(604)],zCetg:e[n(1051)],fdyZn:n(780)+"ack=fron"+n(779)+"P"};if(e[n(1284)](n(1608),e[n(1358)])){let d=this[n(1316)],f=this[n(423)];return[veHAwY.WERIh(255,f),veHAwY[n(1778)](f,8)&255,veHAwY[n(1059)](veHAwY.nxvkF(f,16),255),f>>>24,veHAwY[n(1059)](255,d),veHAwY.jAwaD(veHAwY[n(698)](d,8),255),veHAwY.WERIh(veHAwY[n(1778)](d,16),255),veHAwY[n(712)](d,24)]}else return new Promise(d=>{let f=n,g={uooKt:function(m,b){return s[q(478)](m,b)}};if(!Yn)return s[f(1071)](d,s[f(1532)]);try{let m=document[f(1005)+"ement"](s.BKCML);window["frontier"+f(1571)]=b=>{let p=f;document[p(1048)][p(810)+p(1097)](m),window[p(1056)+p(1571)]=void 0,g[p(995)](d,b&&b[p(1596)]||"unknown "+p(763))},m.type=s[f(1182)],m[f(828)]=a[f(1382)](/^ws/,f(371))+s[f(594)];try{document.body[f(1040)+f(1097)](m)}catch{document[f(1048)][f(810)+f(1097)](m)}}catch{window[f(1056)+f(1571)]=void 0,s.qIgyI(d,s[f(1532)])}})}function en(a,n,s){let d=t;if(e[d(631)]===d(1043))return!!a?.[d(554)](f=>f[d(1616)]===n&&f[d(1654)]===s);if(_0x4929a5=_0x2cd339[d(841)+"At"](_0x17e42c),_0x4ddc39<128)_0x522557[_0x309520++]=_0x2c9c5f;else if(e[d(1811)](_0x5d4bb7,2048))_0x4c4ee3[_0x3f57da++]=e[d(391)](e[d(1045)](_0x5b701f,6),192),_0x4e0b56[_0x1db33f++]=e[d(974)](e[d(1792)](63,_0x3c9977),128);else if(e[d(1301)](e[d(1427)](64512,_0x1cedac),55296)&&e.fvfhI(64512,_0x353bbd=_0xd39e19[d(841)+"At"](_0x21ce77+1))===56320){let f=e.yjyHq[d(1283)]("|"),g=0;for(;;){switch(f[g++]){case"0":_0x48f4c4[_0x362365++]=e[d(717)](e[d(637)](_0x536199,18),240);continue;case"1":_0x5b030a[_0x36f9f5++]=e[d(947)](e[d(1031)](e.FIoFs(_0xd190ca,6),63),128);continue;case"2":_0x2364eb[_0x35d4de++]=e.bqFKE(e[d(1642)](e[d(1597)](_0x7e5eab,12),63),128);continue;case"3":_0x41d7ac[_0x5ef8cc++]=e[d(1706)](e[d(1570)](63,_0x1f014b),128);continue;case"4":_0x2163e6=e[d(1718)](e[d(445)](65536,e[d(454)](e[d(1512)](1023,_0x33f59d),10)),1023&_0x233603);continue;case"5":++_0x30e46c;continue}break}}else _0x24fc99[_0x56a28a++]=e[d(1524)](e[d(1045)](_0x360d36,12),224),_0x58f217[_0x144ad6++]=e[d(1688)](e.YXnXC(e[d(1699)](_0x4703c4,6),63),128),_0x1face2[_0x1e2496++]=e[d(1042)](e.jhjUv(63,_0x1c1dc0),128)}function Zn(a,n){let s=t;return a?.find(d=>d[s(1616)]===n)?.[s(1654)]}let ca=null;async function pp(){let a=t;return ca||(ca=Promise[a(1169)]()[a(957)](Lt[a(909)](Lt,a(1652)))),ca}class gp extends oa{constructor(n,s){let d=t,f={TLoRg:function(g,m){return e[q(791)](g,m)},jUYpX:e[d(614)],WOgTu:function(g,m){return e[d(509)](g,m)},IvddZ:e[d(1015)],LOZXD:function(g,m){return e.LhWFG(g,m)}};if(e[d(1685)](d(362),e[d(1817)])){let g=this[d(1488)+"rs"][_0x22a5d7];if(g)g.slice()[d(1816)](m=>m.fn[d(874)](m[d(834)],_0x35fc40));else if(oossHG[d(547)](oossHG[d(701)],_0x2a457a)&&!this[d(499)]){let m=_0x372b26[d(802)]&&_0x2515b5[0];if(oossHG[d(657)](m,_0x301edb))throw m;let b=new _0xd2c608(oossHG[d(1767)]+(m?oossHG[d(356)](oossHG[d(356)](" (",m[d(973)]),")"):""));throw b[d(418)]=m,m}return this}else super(),this[d(902)]=n,this[d(1499)]=s,this._qosDB=void 0,this[d(1844)+d(608)]=null}async[t(1496)](){await this[t(1665)]()}async[t(1665)](){let n=t,s={MSAwQ:function(d,f){return e[q(1311)](d,f)},ZEuEG:"unknown "+n(763),MhRke:e.zdjKH,iSaWz:function(d){return e[n(1298)](d)},iAeGj:function(d,f,g,m){return e[n(397)](d,f,g,m)}};if(!this[n(1061)]){if(this["_initPro"+n(608)])return this["_initPro"+n(608)];try{let d=this[n(902)],f=this[n(1499)];this[n(1844)+"mise"]=(async()=>{let g=n,m={WyciN:function(b,p){return s[q(470)](b,p)},VgNHO:s[g(944)]};if(s.MhRke===g(855)){let{openDB:b}=await s[g(1826)](pp);this[g(1061)]=await s[g(1374)](b,g(1056)+"_"+d,1,{upgrade(p){let T=g;p[T(776)+T(766)+"e"](d,{keyPath:f})}})}else _0x2b9249["frontier"+g(1571)]=void 0,pemvXj.WyciN(_0x49a8fa,pemvXj[g(1211)])})(),await this[n(1844)+n(608)]}catch(d){console.log(d)}finally{this[n(1844)+n(608)]=null}}}async[t(1520)](n){let s=t;try{return await this[s(1665)](),this[s(1061)]?.get(this[s(902)],n)}catch(d){console[s(1545)](d)}}async set(n,s){let d=t;return await this[d(1665)](),this._qosDB?.[d(1034)](this._dbName,n)}async[t(358)](n){let s=t;try{if(e[s(1284)](e.oVFbz,e[s(621)]))return await this[s(1665)](),this[s(1061)]?.delete(this[s(902)],n);_0x12421d=_0x42d152[s(841)+"At"](_0x1a168c),e[s(1009)](_0xcb3f18,128)?_0x42b68f+=1:e[s(692)](_0x578fea,2048)?_0x5cfc51+=2:(64512&_0x5ac095)===55296&&e[s(821)](64512&_0x6d9633[s(841)+"At"](e[s(1525)](_0x1577cd,1)),56320)?(++_0x2e2467,_0x2e6db5+=4):_0x1f6d0c+=3}catch(d){console[s(1545)](d)}}async[t(1065)](){let n=t;try{return await this[n(1665)](),this._qosDB?.[n(1065)](this[n(902)])}catch(s){console[n(1545)](s)}}async[t(1506)](){let n=t;return e[n(799)]===e.FVxvQ?this[n(1061)][n(1394)+n(1673)]():(await this[n(1665)](),this[n(1061)]?.[n(1415)+"ys"](this._dbName))}async[t(734)](){let n=t;return await this[n(1665)](),this[n(1061)]?.[n(734)](this[n(902)])}async[t(962)](){let n=t;try{this[n(1061)]?.close(),this[n(1061)]=void 0}catch(s){console[n(1545)](s)}}get[t(998)](){let n=t;try{return!!this[n(1061)]}catch(s){return e[n(649)](e[n(1242)],n(1445))?_0x564de0[n(1828)]||_0x361ac6[n(1333)]?(n(598)+" "+(_0x5d3f5e[n(1828)]||"")+n(404)+(_0xc6ecfe[n(1333)]||""))[n(1047)]():_0x36e618.stringify(_0x3a9536):(console.log(s),!1)}}}class mp{constructor(n,s){let d=t;this[d(1822)]=n,this[d(593)]=s,this[d(1061)]=localStorage}async[t(1496)](){}get _prefix(){let n=t;if(e[n(1835)](e.aHaBQ,e[n(765)])){let s=e[n(978)][n(1283)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(527)][n(1780)+n(514)](e[n(1639)],this[n(1299)]);continue;case"1":if(!this[n(527)])return;continue;case"2":this[n(527)]["addEvent"+n(514)]("message",this._onMessage);continue;case"3":this._ws[n(1780)+"Listener"](n(1364),this[n(1087)]);continue;case"4":this._ws["addEvent"+n(514)](e[n(1255)],this._onClose);continue}break}}else return n(1056)+"_"+this[n(1822)]}async[t(1520)](n){let s=t,d=this[s(1061)].getItem(this._prefix);return JSON[s(1804)](e[s(800)](d,"{}"))[n]}async set(n,s){let d=t,f=this[d(1061)][d(1149)](this[d(1293)]),g=JSON.parse(f||"{}");return g[s||n[this[d(593)]]]=n,this._qosDB[d(689)](this[d(1293)],JSON[d(587)+"y"](g)),s||n[this._pathKey]}async[t(358)](n){let s=t,d=this._qosDB.getItem(this[s(1293)]),f=JSON[s(1804)](e[s(800)](d,"{}"));return f[n]=void 0,this[s(1061)].setItem(this[s(1293)],JSON[s(587)+"y"](f))}async[t(1065)](){let n=t;return this[n(1061)][n(1065)]()}async[t(1506)](){let n=t,s=this._qosDB.getItem(this[n(1293)]),d=JSON[n(1804)](e[n(1840)](s,"{}"));return Object[n(1506)](d)}async[t(734)](){let n=t,s=this[n(1061)][n(1149)](this._prefix),d=JSON.parse(e.izPyc(s,"{}"));return Object[n(651)](d)}[t(962)](){return Promise.resolve()}get isReady(){return!!this._qosDB}}class wp{constructor(n,s){let d=t;if(e.NkPea===e[d(1787)]){let f=!!this[d(599)][d(1213)+"S"];if(!f)return{enabled:f,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let g=e[d(1626)](_0x16a0aa,_0x4d632c[d(973)].headers,"x_fronti"+d(1297),"2"),m=g&&e[d(1385)](_0x10ff07,_0x16ebec[d(973)][d(1062)],e[d(858)],"1"),b=g&&e[d(1725)](_0xa34091,_0x1920e5[d(973)][d(1062)],e[d(1050)],"1"),p=b?e[d(1411)](_0x2ef2b5,_0x1e9324[d(973)][d(1062)],e[d(1769)])?.[d(1283)](",")[d(1534)](_0x1a3f67)||[]:[];return{enabled:f,isQoSMessage:g,isQoSAck:m,isAckCleanupMessage:b,ackMsgIds:p}}else this._DBName=n,this[d(593)]=s,this[d(1061)]=In?tt:jr?wx:null}async[t(1496)](){}get[t(1293)](){let n=t;return n(1056)+"_"+this[n(1822)]}async get(n){let s=t,d=this[s(1061)][s(451)+s(694)](this[s(1293)]);return JSON[s(1804)](e[s(1801)](d,"{}"))[n]}async set(n,s){let d=t,f=this[d(1061)][d(451)+d(694)](this[d(1293)]),g=JSON[d(1804)](f||"{}");return g[s||n[this[d(593)]]]=n,this[d(1061)][d(1862)+d(694)](this[d(1293)],JSON[d(587)+"y"](g)),s||n[this[d(593)]]}async[t(358)](n){let s=t,d=this[s(1061)][s(451)+s(694)](this[s(1293)]),f=JSON.parse(e.RQhTK(d,"{}"));return f[n]=void 0,this[s(1061)]["setStora"+s(694)](this._prefix,JSON[s(587)+"y"](f))}async clear(){let n=t;return this[n(1061)]["clearSto"+n(1673)]()}async[t(1506)](){let n=t,s=this._qosDB["getStora"+n(825)+"nc"](this[n(1293)]),d=JSON[n(1804)](e[n(1390)](s,"{}"));return Object.keys(d)}async getAll(){let n=t,s=this[n(1061)].getStorageInfoSync(this[n(1293)]),d=JSON[n(1804)](s||"{}");return Object[n(651)](d)}closeDB(){return Promise[t(1169)]()}get[t(998)](){let n=t;return e[n(926)](e[n(1620)],e[n(1620)])?!!this[n(1061)]:this[n(527)]?this._ws[n(1348)+"ns"]:""}}function tl(a,n){let s=t;if(e[s(1691)](e.KVIxo,e.BWXKe)){if(e.qMZyx(In,In))return new wp(a,n);if(e[s(707)](Yn,Wr)&&e[s(1370)](e[s(886)],typeof indexedDB))return new gp(a,n);if((Yn||Wr)&&e[s(556)](e[s(886)],typeof localStorage))return new mp(a,n);throw new Error("init QoS"+s(1677)+"d")}else _0x6a99c(_0x53f490,90),e[s(494)](_0x1a74e0,_0x4a2bf6,_0x120b97)}class _p{constructor(){let n=t;this._intervalTimeoutId=null,this._interval=36e5,this[n(1061)]=e.wbgZT(tl,n(544),e.jWySu)}async[t(1746)+t(743)](){let n=t;clearInterval(this[n(1746)+n(784)+"Id"]),this[n(1746)+n(784)+"Id"]=e[n(713)](setInterval,()=>{let s=n;this[s(1416)+s(964)]()},this[n(1746)+"l"])}async[t(1496)](){let n=t;await this[n(1061)].openDB()[n(957)](()=>{let s=n;this[s(1746)+s(743)]()})}async[t(1416)+t(964)](){let n=t,s={mcDGW:function(d,f){return e[q(477)](d,f)},XgkOH:function(d,f){return e[q(951)](d,f)},RSrto:e[n(1254)]};if(e[n(1284)](e.PJUGn,e[n(891)]))(await this[n(1061)]?.[n(734)]()||[]).filter(({timestamp:g})=>g<Date[n(1100)]())[n(1816)](g=>{let m=n,b={DrDLm:function(p,T){return s[q(794)](p,T)},DusaQ:function(p,T){return p===T}};if(s.XgkOH(m(716),s[m(1275)])){let p=b.DrDLm(_0x14907a,_0x16e844);this[m(527)]&&b[m(551)](this[m(527)].readyState,this[m(913)])&&(this._ws&&this[m(527)].send(p),this._debug(m(1294),_0x548188))}else this[m(1061)]?.[m(358)](g[m(1010)+"id"])});else return _0x42c2d6?.[n(554)](d=>d.key===_0x4de4c1)?.[n(1654)]}async[t(358)](n){let s=t;return this[s(1061)]?.[s(358)](n)}async set(n,s){let d=t;return this[d(1061)]?.[d(986)]({message_id:n,timestamp:s})}async[t(1520)](n){let s=t;if(e.gMjQu(e[s(720)],e.broAv))return this[s(1061)]?.[s(1520)](n);{let{type:d}=_0x2cd3e1;this[s(1127)](d,_0x5e5009)}}async[t(962)](){let n=t;e.jlOoj(clearInterval,this[n(1746)+n(784)+"Id"]),await this._qosDB?.[n(962)]()}get[t(998)](){let n=t;return this._qosDB?.[n(998)]}}function da(a){let n=t,s={joXDZ:function(d,f,g){return e[q(1375)](d,f,g)},xoeBJ:e.WlDjb};if(e[n(1579)](e[n(1224)],e[n(1224)])){let d=!!this[n(599)][n(1213)+"S"];if(!d)return{enabled:d,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let f=e.YSeSq(en,a.message.headers,e.RdABU,"2"),g=f&&en(a[n(973)][n(1062)],n(503)+n(819)+"ck","1"),m=f&&e[n(900)](en,a[n(973)][n(1062)],e[n(1050)],"1"),b=m?e.WLlcq(Zn,a[n(973)][n(1062)],n(503)+n(1559)+n(1037))?.split(",").filter(Boolean)||[]:[];return{enabled:d,isQoSMessage:f,isQoSAck:g,isAckCleanupMessage:m,ackMsgIds:b}}else{let d=s[n(376)](_0x1a52f1,s[n(1281)],{message:_0x354c34[n(973)],code:_0x247da5[n(1555)+"ERROR"],error:_0x5a1760});this[n(1531)+n(1161)+"ent"](d)}}async function nl(){let a=t;return this[a(1132)+a(1163)]||(this[a(1132)+a(1163)]=new _p),this._QoSManager[a(998)]||await this[a(1132)+"ger"][a(1496)](),this._QoSManager}async function yp(a,n){let s=t,{enableAutoAck:d}=this._options,f=e[s(1402)](en,a[s(973)][s(1062)],e[s(1237)],"1"),g=e[s(1402)](en,a[s(973)][s(1062)],s(1207),"1"),m=da[s(1069)](this,a);if(e[s(1122)](d,f)){let{SeqID:b,LogID:p,service:T,LogIDNew:P,method:F}=a[s(973)];this[s(567)]({SeqID:b,LogID:p,LogIDNew:P,service:T,method:F,headers:[{key:"is_ack",value:"1"},{key:s(545),value:e[s(800)](P,"")},{key:e.HXPxS,value:"0"}]})}g&&!m[s(1789)]&&this["_dispatc"+s(572)+s(365)](a),n()}async function Ep(a,n){let s=t;this[s(1818)](s(709),a.message),e[s(1298)](n)}async function bp(a,n){let s=t,d=Zt(await e.yfvNQ(el,a.data));try{if(e[s(468)](d[s(1607)],Uint8Array)){let f=e[s(961)](this[s(599)][s(1413)+s(1480)],Object)?{force:!!this[s(599)][s(1413)+s(1480)][s(869)],encoding:this[s(599)].payloadEncoding[s(922)]?this._options[s(1413)+s(1480)][s(922)].replace(/\s/g,"")[s(738)+s(1219)]():""}:{force:!1,encoding:this[s(599)][s(1413)+s(1480)]?this[s(599)]["payloadE"+s(1480)][s(1382)](/\s/g,"")[s(738)+s(1219)]():""},g=d[s(1413)+s(1480)]?d.payloadEncoding[s(1382)](/\s/g,"")[s(738)+"ase"]():"",m=e[s(1052)](this._options[s(999)+"ype"],Object)?{force:!!this._options[s(999)+"ype"][s(869)],type:this[s(599)]["payloadT"+s(1346)][s(374)]?this[s(599)][s(999)+"ype"][s(374)][s(1382)](/\s/g,"").toLowerCase():""}:{force:!1,type:this._options[s(999)+s(1346)]?this[s(599)].payloadType.replace(/\s/g,"")[s(738)+"ase"]():""},b=d[s(999)+s(1346)]?d[s(999)+s(1346)][s(1382)](/\s/g,"")[s(738)+s(1219)]():"",p=m.force?m[s(374)]:b||m[s(374)],T=f[s(869)]?f[s(922)]:g||f[s(922)],P=[e[s(1493)],e.WJwEZ,e[s(1014)],e[s(1846)]],F=[e.knkGy,"binary"];this[s(599)][s(1369)+s(531)+s(444)+"ad"]&&P[s(844)](p)&&(!T||F[s(844)](T))?d[s(1007)+"oad"]=e[s(756)](Qd,d[s(1607)],0,d[s(1607)][s(400)+"th"]):d[s(1007)+s(718)]=""}else d[s(1007)+s(718)]=""}catch(f){d[s(1007)+s(718)]="",console.log(f)}a[s(973)]=d,n()}function vp(a,n,s){let d=t,f=e[d(1801)](s,8192),g=e[d(992)](f,1),m=null,b=f;return function(p){let T=d;if(e[T(854)](e.cKJeG,e[T(1824)])){if(e[T(1405)](p,1)||p>g)return a(p);e[T(1196)](b+p,f)&&(m=e[T(1487)](a,f),b=0);let P=n[T(1069)](m,b,b+=p);return e[T(1648)](7,b)&&(b=e[T(1647)](7,b)+1),P}else return!!this._qosDB}}let Sp=4294967295;function Ip(a,n,s){let d=t;return e[d(1662)](RangeError,e[d(445)](e.ZGCiD(e.GrJhf(e[d(1140)](e[d(732)](e[d(1261)],a),e[d(1853)]),n||1),e[d(684)]),s))}function Ap(a,n,s){let d=t;if(e.ZCeBz(s,Sp))throw new Error(e.VvFqi);let f=3;for(;e[d(368)](f,0);){let g=e[d(1179)](255,s);ua(g,a,e[d(591)](n,f)),s>>>=8,f--}return e.urPdM(n,4)}function Tp(a,n){let s=t,d=0,f=n,g=e[s(1379)](n,4);for(;e.PsIAJ(f,g);){let{value:m,offset:b}=e[s(937)](la,a,f);f=b,d=e[s(1622)](e[s(1026)](d,8),0),d+=m}return{value:d,offset:g}}function Cp(a,n,s){let d=t,f=e[d(379)][d(1283)]("|"),g=0;for(;;){switch(f[g++]){case"0":if(e[d(790)](a[d(802)],40))return e[d(1425)](e[d(1385)](aa,a,n,s),s);continue;case"1":if(!a)return s;continue;case"2":if(n[d(893)+"e"])return e.MDJEP(n[d(893)+"e"](a,s),s);continue;case"3":return e.hNOVr(e[d(896)](aa,a,n,s),s);case"4":if(n[d(1098)])return e.SQkdy(n[d(1098)](a,s),s);continue}break}}function Rp(a,n){let s=t;if(e[s(1321)](e.ukqNO,e[s(745)])){let d=new ue(e[s(1107)](e[s(1592)](e.aLYQS(a[e[s(383)](n,4)],24),e.TEoDI(a[e[s(1399)](n,5)],16))|e[s(769)](a[n+6],8),a[e[s(1726)](n,7)]),e.EtljY(e.sQAuj(e[s(606)](e[s(1068)](a[e[s(1814)](n,0)],24),e[s(435)](a[e[s(1753)](n,1)],16)),a[e[s(1609)](n,2)]<<8),a[e[s(695)](n,3)]),!0);return n+=8,{value:d,offset:e[s(837)](n,8)}}else return _0x5c210e[s(1545)](_0x453dbf),!1}function Dp(a,n,s){let d=t,f=a[d(423)],g=a[d(1316)];return n[s]=g>>>24,n[e[d(1397)](s,1)]=e.DqEtr(e[d(1044)](g,16),255),n[s+2]=e[d(1432)](g,8)&255,n[e[d(383)](s,3)]=e[d(1707)](255,g),n[e[d(1080)](s,4)]=e[d(1432)](f,24),n[s+5]=f>>>16&255,n[e[d(1812)](s,6)]=e[d(1179)](e[d(674)](f,8),255),n[e[d(773)](s,7)]=e[d(1821)](255,f),s+=8,s}function la(a,n){let s=t,d={oXqJu:e[s(1255)],psLZn:function(f,g,m){return e[s(448)](f,g,m)}};if(e.LloUY(s(1245),e[s(1431)]))this[s(1127)](eVSJJb[s(1104)],eVSJJb.psLZn(_0xe89d95,eVSJJb.oXqJu,{..._0x2c7998}));else return a[s(1112)+"8"]?{value:a.readUInt8(n),offset:e[s(1638)](n,1)}:{value:e[s(1491)](255,a[n]),offset:n+1}}function ua(a,n,s){let d=t;return n[d(1519)+"t8"]?n.writeUint8(a,s):n[s]=e.mJCFP(255,a),e[d(1812)](s,1)}let kp=function(a){let n=t,s={OaHcG:function(f,g,m,b){return e.CEucZ(f,g,m,b)}};if(e[n(1554)]===e[n(1554)])return new Uint8Array(a);for(var d in _0x36de49)KANfWz.OaHcG(_0x214dcd,_0x4de27b,d,{get:_0x4b3a10[d],enumerable:!0})},Pp=e.xhGjH!=typeof Buffer?Buffer[t(932)+t(619)]:e[t(758)](vp,kp,Uint8Array[t(1503)+"e"].subarray);(()=>{let a=t,n={AMnWT:e[a(1514)],lMfIi:function(d,f){return e.NNzfY(d,f)},Njfqn:function(d,f){return e.rgYyG(d,f)},bahWF:function(d,f){return e[a(1013)](d,f)},pgbgO:function(d,f){return d|f},xCntS:function(d,f){return e[a(1318)](d,f)},qinnM:function(d,f){return e[a(1792)](d,f)},rOTQy:function(d,f){return e.ZdkOW(d,f)},dlmMY:function(d,f){return e.cvxYO(d,f)},SHQAb:function(d,f){return e.ppSRk(d,f)},ccyIO:function(d,f){return e[a(1539)](d,f)},bCkox:function(d,f){return e[a(655)](d,f)},zewHo:function(d,f){return e[a(1646)](d,f)},fbTYU:function(d,f){return e[a(1427)](d,f)},TNGAO:function(d,f){return e[a(348)](d,f)},UWZAQ:function(d,f){return e.VBCQM(d,f)},lIkZa:function(d,f){return e[a(484)](d,f)},eTUGo:function(d,f){return d|f}},s=4294967295;return function(d,f,g=!0){let m=a,b=n[m(670)].split("|"),p=0;for(;;){switch(b[p++]){case"0":if(d[f++]<128)return{value:g?s:n[m(675)](0,s),offset:f};continue;case"1":if(n[m(1621)](d[f++],128))return{value:g?s:0|s,offset:f};continue;case"2":s=n[m(931)](n[m(1752)](s,n[m(497)](n[m(1768)](127,d[f]),14)),0);continue;case"3":if(n[m(806)](f+=5,d[m(802)]))throw f=d[m(802)],Ip(f,10,d.length);continue;case"4":s=n[m(931)](n[m(688)](s,n.SHQAb(15,d[f])<<28),0);continue;case"5":if(n[m(1645)](d[f++],128))return{value:g?s:n[m(795)](0,s),offset:f};continue;case"6":s=n[m(931)](n[m(675)](s,n[m(735)](n.fbTYU(127,d[f]),7)),0);continue;case"7":if(n.TNGAO(d[f++],128))return{value:g?s:n[m(688)](0,s),offset:f};continue;case"8":s=n[m(1752)](s,(127&d[f])<<21)>>>0;continue;case"9":s=n[m(931)](n.UWZAQ(127,d[f]),0);continue;case"10":if(d[f++]<128)return{value:g?s:n[m(830)](0,s),offset:f};continue;case"11":return{value:g?s:n[m(846)](0,s),offset:f}}break}}})();let Op=16,fa=32;function Lp(a){let n=t,s=0,d={};for(let f=0;e[n(704)](f,a[n(802)]);f++)d[a[f][n(1221)+n(1463)]]=e[n(1198)](Xd,a[f][n(1221)+n(1463)]),s+=e[n(1781)](14,d[a[f][n(1221)+"ame"]]);return[s,d]}function rl(a,n,s){let d=t,f={Zofkn:d(1672)+d(375)+d(1813),EDIFu:function(T,P,F,G){return T(P,F,G)},EFBmN:function(T,P,F,G){return T(P,F,G)},WEaaD:e.OWQqP,qwJzF:e.GqPUe,yWgIK:function(T,P,F,G){return T(P,F,G)},MFOtW:d(1303)+d(1748)},[g,m]=Lp(a),b=e[d(1008)](Pp,g),p=0;return a[d(1816)](T=>{let P=d,F=f[P(1547)][P(1283)]("|"),G=0;for(;;){switch(F[G++]){case"0":p=f.EDIFu(ua,0,b,p);continue;case"1":p=f[P(1717)](Ap,b,p,T[P(360)]||0);continue;case"2":console.log(f[P(1167)],p);continue;case"3":console[P(1545)]("name",p);continue;case"4":p=f.EDIFu(Dp,ue[P(1204)+"er"](T[P(1077)]||n),b,p);continue;case"5":p=f.EFBmN(Cp,T[P(1221)+"ame"],b,p);continue;case"6":console.log(P(634),p);continue;case"7":console[P(1545)](f[P(1142)],p);continue;case"8":p=f[P(1744)](ua,m[T["cursor_n"+P(1463)]],b,p);continue;case"9":console[P(1545)](f.MFOtW,T,T.service);continue;case"10":console.log(P(1396)+P(1186),p);continue}break}}),{frameType:fa,headers:[{key:e[d(635)],value:s}],payload:b}}function Np(a){let n=t,s=0,d=[];for(;s<a[n(400)+"th"];){let{offset:f}=la(a,s);s=f;let g={cursor_name:"",cursor:0,service:0},{value:m,offset:b}=e[n(1631)](Tp,a,s);g[n(360)]=m,s=b;let{value:p,offset:T}=e[n(942)](la,a,s);s=T,g[n(1221)+"ame"]=e.xplAU(Qd,a,s,e.azvsn(s,p)),s+=p;let{value:P,offset:F}=e.fNHTN(Rp,a,s);g.cursor=P.toNumber(),s=F,d[n(370)](g)}return d}function Mp(){let a=t;return{frameType:fa,headers:[{key:e[a(635)],value:e[a(658)]}],payload:void 0}}class Bp{constructor(n,s,d){let f=t;this[f(1151)+"ameSpace"]=n,this[f(818)+f(1518)]=s,this["_message"+f(1612)]=d,this[f(1061)]=e[f(1295)](tl,this[f(1151)+f(529)],e.JRnmu)}async[t(1496)](){await this[t(1061)].openDB()}async[t(1833)+"rs"](){let n=t;if(!this[n(1061)][n(998)])return;let s=this[n(1566)+"Strategy"],d=await this[n(1061)][n(734)]();switch(console[n(1545)](e[n(617)],d),s){case e.BkXUa:return d&&d[n(802)]?e[n(550)](rl,d,0,this["_cursorF"+n(1518)]):void 0;case e.SVpyu:return;case e[n(592)]:return d&&d.length?rl(d,0,this[n(818)+"ileName"]):e[n(486)](Mp)}}async set(n,s,d){return console.log(e[t(946)],n,s,d),this._qosDB.set({cursor_name:n,cursor:s,service:d})}async setCursors(n){let s=t,d=e.seGXd(Np,n);for(let f of d)console[s(1545)]("setcursor",d),await this[s(1061)][s(986)](f)}async[t(1520)](n){let s=t;return(await this._qosDB[s(1520)](n))?.[s(1077)]}async closeDB(){let n=t;await this._qosDB[n(962)]()}[t(571)+"rsorFile"+t(489)](n){let s=t;if(e.YjbNT(e[s(1530)],e[s(1239)]))this[s(818)+"ileName"]=n;else return this[s(1061)][s(1065)]()}get[t(998)](){return this[t(1061)].isReady}}let Fp=e[t(1075)];async function il(a){let n=t;if(!this[n(599)][n(1213)+"S"])return null;let{aID:s,fpID:d,messageStrategy:f}=this._options,g=e[n(355)](a,Fp);try{return this[n(1731)+n(1451)]?a&&this["_cursorM"+n(1451)]["updateCu"+n(1469)+"Name"](a):this[n(1731)+n(1451)]=new Bp(d+"_"+s+"_"+g,g,f),this._cursorManager[n(998)]||await this[n(1731)+"anager"][n(1496)](),this[n(1731)+n(1451)]}catch{return e[n(1591)](e[n(1225)],e.uYkaE)?(_0x4763c9[n(1545)](n(1664),_0x39fd51,_0x3a1df,_0x4e7ca5),this[n(1061)][n(986)]({cursor_name:_0x47a065,cursor:_0x1ab71b,service:_0x5a0d4f})):null}}async function zp(a,n){let s=t,d={lOrEb:function(Z,Y){return Z(Y)}},f=e[s(1166)](en,a.message[s(1062)],s(1773),"-1"),g=e[s(900)](en,a[s(973)][s(1062)],"is_ack","1"),m=e[s(1375)](Zn,a[s(973)].headers,e[s(428)]),b=e[s(1815)](Number,e[s(480)](Zn,a[s(973)][s(1062)],s(503)+s(749)))||0,p=da.call(this,a),T=e[s(1208)](en,a.message.headers,e[s(1745)],"2"),P=Zn(a[s(973)].headers,e[s(1655)]),F=e[s(762)](Number,Zn(a.message[s(1062)],e[s(917)]));if(p.isQoSAck)return n();let G=p["isQoSMes"+s(1158)]?await nl[s(1069)](this):null;if(e[s(575)](a[s(973)][s(360)],0)&&g&&!f||e.SkdWX(a[s(973)][s(360)],0)){if(m&&p[s(540)+s(1158)]&&G)return!!!await G.get(m)&&(this._dispatchMessageEvent(a),await G.set(m,e[s(443)](Date.now(),b))),e.DfBWH(n);if(T)if(e[s(838)]!==e[s(838)])_0x2b215a+=zwEAVW.lOrEb(_0x458d4c,_0x7a1e46),_0x49e78f++;else{let Z=await il[s(1069)](this);if(!Z)return this[s(1531)+s(724)+"Event"](a),n();let Y=await Z.get(P)??-1;if(e.kmaDh(Y,F))this[s(1531)+s(724)+s(1345)](a),Z[s(986)](P,F,a[s(973)][s(360)]);else throw new Error(s(555)+s(1205)+s(1529)+F+(s(659)+s(377)+s(1214)+"r ")+Y);return e.WfMAC(n)}return this["_dispatchMessage"+s(1345)](a),e.sSLKm(n)}}async function Up(a,n){let s=t,d=da[s(1069)](this,a);if(!d[s(540)+s(1158)])return e.XnHhp(n);let f=await nl.call(this);if(d[s(1312)+"anupMess"+s(349)]&&d.ackMsgIds[s(802)])for(let g of d[s(1278)+"s"])await f[s(358)](g);e[s(1502)](n)}async function Hp(a,n){let s=t,d=e[s(510)](a[s(973)][s(979)+"e"],Op),f=e.NHdky(a[s(973)].frameType,fa);if(!d&&!f)return e[s(1515)](n);let g=Zn(a[s(973)].headers,s(1600)+"ile_name");if(!g)return n();let m=await il.call(this,g);if(!m)return e[s(1298)](n);if(d){let b=await m[s(1833)+"rs"](),p={frameType:b?.[s(979)+"e"],SeqID:ue.fromNumber(this[s(1501)]++),LogID:ue[s(1204)+"er"](this[s(599)]["logIDGen"+s(1244)]()),service:9e3,method:5,headers:b?.headers,payload:b?.[s(1607)]},T=e[s(831)](S,p);this[s(527)]&&this[s(527)][s(1429)+"te"]&&this._ws[s(1195)](T)}if(f){let b=a.message.payload;b&&m[s(1361)+"rs"](b)}}let qp=async function(a,n){let s=t;this[s(1095)]=!1,clearTimeout(this[s(1389)+s(1419)+s(954)]),e[s(1758)](n)},Gp=async function(a,n){let s=t;if(!this[s(527)]||e[s(500)](this[s(527)].readyState,this[s(913)]))return e[s(1442)](n);let{pingInterval:d}=this[s(599)];this[s(549)+s(466)]?.["resetEnd"+s(771)+s(401)]();for(let g=0;e[s(1101)](g,this[s(1566)+s(664)][s(802)]);g++){let m=this[s(1566)+"Queue"][g];if(e.Fgiml(this[s(527)][s(1429)+"te"],this[s(913)])&&m!==null)this[s(527)]&&this[s(527)][s(1195)](m),this[s(1566)+s(664)][g]=null;else break}this[s(1566)+s(664)]=this[s(1566)+"Queue"].filter(g=>!!g),this[s(740)+s(453)+"Id"]=e[s(480)](setTimeout,()=>this._ping(),d),this[s(1531)+s(904)+"nt"](a),this[s(491)+"er"]&&this[s(527)]&&(this._ws.binaryType=this[s(1391)+s(1346)]);let f=this[s(549)+"tManager"]?.[s(877)+"ntEndpoint"]();this[s(1818)]("open "+f+s(1851)),e.tvqoB(n)},jp=async function(a,n){let s=t,d=this[s(549)+s(466)]?.[s(877)+s(697)+"nt"]();this[s(1818)](s(393)+d),e.UCFpd(n)};class Wp extends oa{constructor(n){let s=t,d={EhnOR:function(f,g){return e[q(557)](f,g)},orheA:function(f,g){return f<<g},gAzFM:function(f,g){return e[q(539)](f,g)},KTJbx:function(f,g){return e[q(1565)](f,g)},HfdQN:function(f,g){return e.waPxr(f,g)}};{super(),this["_miniNav"+s(782)+s(750)]=!0,this[s(491)+"er"]=Yn,this[s(1723)]=ap,this._isMiniTT=In,this[s(1424)+"X"]=jr,this[s(1495)+"r"]=Wr,this["_message"+s(664)]=[],this[s(549)+s(466)]=null,this[s(582)+s(1766)]=!1,this[s(1391)+s(1346)]=s(654)+"fer",this[s(1389)+s(505)]=!1,this[s(1389)+s(1419)+s(954)]=null,this["_reconnectTimeou"+s(987)]=null,this["_pingPon"+s(453)+"Id"]=null,this[s(1501)]=0,this[s(1095)]=!1,this[s(1103)]="",this["_QoSMana"+s(1163)]=null,this._cursorManager=null,this[s(367)+"sCounter"]=null,this._protocols=s(1218),this.CLOSED=3,this[s(1611)+"NG"]=0,this[s(913)]=1,this[s(971)]=2,this[s(1299)]=b=>{let p=s;try{Zd(this,b,[qp,Gp,jp])}catch(T){let P=e[p(1552)](ot,e[p(614)],{message:T[p(973)],code:Qt[p(1468)+"OR"],error:T});this[p(1531)+p(1161)+p(714)](P)}},this[s(1782)+"ge"]=async b=>{let p=s,{pingInterval:T,pingFrequency:P}=this[p(599)];if((e[p(1175)]("hi",b[p(1024)])&&e[p(1628)](e[p(890)],P)||p(471)===P)&&(this[p(1025)+p(1443)](),this.emit(e[p(1423)],e[p(955)]),this[p(740)+p(453)+"Id"]=e[p(1595)](setTimeout,this._ping[p(909)](this),T)),b[p(1024)]!=="hi")try{e[p(680)](e[p(829)],e[p(829)])?(_0x54fe82=TPQZUr[p(805)](_0x3d931d,_0xe7f79e),_0x410d19|=TPQZUr[p(1656)](TPQZUr[p(515)](127,_0x5ef145),21),TPQZUr.KTJbx(128,_0x4249f)&&(_0x52b50b=TPQZUr[p(805)](_0x1a7ee5,_0x4965a1),_0x6b008d=TPQZUr.KTJbx(127,_0x3c67af),TPQZUr[p(394)](128,_0x511759)&&(_0x4d8a1a=TPQZUr[p(805)](_0x162715,_0x2e5d2e),_0xd78df9|=TPQZUr[p(394)](127,_0x9fc222)<<7))):e.lPJvQ(Zd,this,b,[bp,yp,Up,Hp,zp,Ep])}catch(F){let G=e[p(811)](ot,e[p(614)],{message:F[p(973)],code:Qt.MESSAGE_ERROR,error:F});this[p(1531)+"hErrorEvent"](G)}},this[s(1087)]=b=>{let p=s,T=this[p(549)+p(466)]?.["checkRea"+p(1342)+"es"](),P=this[p(549)+p(466)]?.[p(877)+p(697)+"nt"]();if(T&&!b.message){let F="connect "+P+(p(495)+"ax retri"+p(1053)+"ed");this["_dispatc"+p(1161)+p(714)](e[p(879)](ot,e[p(614)],{message:F,code:Qt[p(605)+p(677)+"R"],error:b}));return}this[p(527)]&&e[p(596)](this._ws[p(1429)+"te"],this.OPEN)&&this[p(989)+p(813)](),this["_dispatchErrorEv"+p(714)](ot(e[p(614)],{message:b[p(973)],code:Qt["NATIVE_E"+p(1354)],error:b}))},this[s(731)]=async b=>{let p=s;this[p(1702)+"mer"](),this[p(1025)+"ngTimer"](),this[p(1694)+p(507)+"rs"](),this[p(527)]=null,this[p(1389)+"Lock"]=!1;let T=this[p(549)+p(466)]?.[p(1306)+p(1342)+"es"]();if(!T&&this[p(1841)+p(1088)]()&&!this[p(582)+p(1766)]){let P=this[p(549)+p(466)]?.[p(877)+p(697)+"nt"](),F=this[p(599)][p(1459)+p(532)+p(543)](b[p(1773)],b[p(763)]);this[p(1531)+p(615)+"ent"](e[p(1785)](ht,"close",{code:1006,reason:b[p(763)]||"connecting faile"+p(1282)+p(1e3)+p(1521)+p(1148)+P,willReconnect:F})),F&&this[p(1389)]();return}if(e.yHqlw(1e3,b[p(1773)])&&this[p(582)+p(1766)]){this[p(1531)+p(615)+"ent"](ht(e[p(1255)],{code:1e3,reason:e[p(730)]})),this[p(549)+p(466)]?.[p(739)+p(771)+"fig"](),this["_pingLos"+p(985)]?.[p(990)+"nter"]();return}if(e[p(908)](1e3,b.code)&&T)if(e[p(602)]("YjUBz",p(1637))){let P=this["_endpoin"+p(466)]?.["getCurre"+p(697)+"nt"](),F=b[p(763)];F||(F=await e[p(436)](xp,this._url)),F="connecti"+p(852)+p(1697)+F+(", hostna"+p(626))+P+(p(1233)+p(1573)+p(1453)),this["_dispatchCloseEv"+p(714)](e.UiQsw(ht,e[p(1255)],{code:b[p(1773)],reason:F}));let G="connect "+P+(" fail, m"+p(807)+p(1053)+"ed");this["_dispatchErrorEv"+p(714)](e.CvKly(ot,e[p(614)],{message:G,code:Qt[p(605)+p(677)+"R"]})),this[p(549)+p(466)]?.[p(739)+"pointCon"+p(401)](),this["_pingLos"+p(985)]?.[p(990)+p(1772)]();return}else{let P=this._qosDB.getItem(this[p(1293)]),F=_0x1145e2.parse(P||"{}");return _0x22e908.keys(F)}if(e[p(680)](1e3,b.code)&&!b[p(763)]){let P=this[p(549)+p(466)]?.[p(877)+p(697)+"nt"]();this[p(1531)+p(615)+p(714)](e[p(715)](ht,e[p(1255)],{code:b[p(1773)],reason:p(1003)+"ng faile"+p(1282)+"wn reaso"+p(1521)+p(1148)+P})),this["_endpoin"+p(466)]?.[p(739)+p(771)+p(401)](),this._pingLossCounter?.[p(990)+p(1772)]();return}this[p(1531)+"hCloseEv"+p(714)](b),this[p(549)+p(466)]?.resetEndpointConfig(),this._pingLossCounter?.[p(990)+p(1772)]()},this.onclose=null,this[s(499)]=null,this[s(346)+"e"]=null,this[s(420)]=null,this[s(1152)+s(669)]=null,this[s(1456)+"eAck"]=null,this[s(519)+s(1437)+s(1331)+"ct"]=null,this[s(1676)+s(1125)]=this[s(1676)+"nLine"][s(909)](this),this[s(1676)+"ffLine"]=this["_handleO"+s(403)].bind(this),this["_handleP"+s(1159)]=this[s(1820)+s(1159)].bind(this),this[s(1820)+"ageShow"]=this["_handleP"+s(1754)][s(909)](this),this._options={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(449)](1,0),service:0,logIDGenerator:o,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:s(471),pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(592)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:g}=n,m=Array[s(871)](f)?f:e.fQQiv(e[s(1846)],typeof f)?[f]:[];if(!m||e[s(455)](0,m[s(802)]))throw new Error(e[s(1072)]);if(!e[s(1575)](lp,g))throw new Error(s(613)+s(1363)+s(897)+", WebSocket constructor "+s(699)+s(1436));Object.assign(this[s(599)],n),this._endpointManager=new Yd(m,this[s(599)][s(882)+"es"]),this[s(367)+s(985)]=new hp(this[s(599)][s(1866)+s(1749)]),this._options[s(753)+s(378)]&&(this[s(1095)]=!0,this[s(1389)]()),this[s(599)]["listenNe"+s(396)+s(1400)]&&(this[s(812)+"T"]||this[s(1424)+"X"]?this[s(1678)+s(993)+s(1779)]():this[s(491)+"er"]&&this["_initGlobalEvent"+s(514)]())}}[t(1676)+t(1125)](){let n=t;this._options[n(1162)+n(988)+n(1497)]||this[n(582)+n(1766)]||this[n(1155)+"econnect"]()}[t(1676)+t(403)](){let n=t;if(e.Dnhyq(n(1603),e.hVpcy))_0x4bb273=_0x45f3d(_0x2c7ccc),_0x4afae3=127&_0x50a3cb,e[n(1280)](128,_0x4e0c53)&&(_0x191b58=_0x20e675(_0x2ce083),_0xf190c8|=e[n(381)](127&_0x20dcbd,7));else{this[n(1240)+n(1190)+"t"]();let s=e.DUuYn(sa,e[n(1165)],{message:e[n(1102)]});this["onStopIm"+n(1437)+n(1331)+"ct"]&&this[n(519)+n(1437)+n(1331)+"ct"](s)}}[t(1485)+t(1392)+t(514)](){let n=t;this[n(491)+"er"]&&window[n(1780)+n(514)](e[n(808)],this[n(1676)+n(1125)]),this[n(491)+"er"]&&window[n(1780)+n(514)](e.iQapH,this["_handleO"+n(403)]),this[n(491)+"er"]&&window["addEvent"+n(514)]("pagehide",this[n(1820)+n(1159)]),this[n(491)+"er"]&&window[n(1780)+"Listener"](e[n(1420)],this[n(1820)+"ageShow"])}[t(1388)+t(1392)+t(514)](){let n=t;this[n(491)+"er"]&&window[n(1729)+n(1246)+"ner"](e.JRTra,this[n(1676)+"nLine"]),this._isBrowser&&window.removeEventListener(e[n(1124)],this[n(1676)+"ffLine"]),this[n(491)+"er"]&&window[n(1729)+n(1246)+n(997)]("pagehide",this[n(1820)+n(1159)]),this._isBrowser&&window["removeEv"+n(1246)+n(997)](e[n(1420)],this[n(1820)+"ageShow"])}[t(1820)+t(1159)](n){let s=t;!n[s(888)+"d"]&&(this._isBrowser&&window[s(1729)+"entListe"+s(997)](s(1228),this[s(1820)+s(1159)]),this._isBrowser&&window[s(1729)+"entListener"](e.rCQBT,this[s(1820)+"ageShow"]),this.close()),this[s(491)+"er"]&&window[s(1729)+s(1246)+"ner"](e[s(808)],this[s(1676)+"nLine"]),this[s(491)+"er"]&&window["removeEv"+s(1246)+s(997)](s(1016),this["_handleO"+s(403)])}["_handleP"+t(1754)](n){let s=t;n.persisted&&(this[s(1841)+s(1088)]()&&(!this[s(527)]||e.XoQaU(this[s(527)][s(1429)+"te"],this.OPEN)||e[s(702)](this._ws[s(1429)+"te"],this[s(1611)+"NG"]))&&this[s(1676)+s(1125)](),this._isBrowser&&window[s(1780)+s(514)](s(1698),this[s(1676)+s(1125)]),this._isBrowser&&window[s(1780)+s(514)](e.iQapH,this[s(1676)+s(403)]))}async[t(1055)+"eUrl"](n){let s=t,d={MtKtf:e[s(1255)]};if(e[s(1598)](e.DtciD,e[s(1507)])){let{fpID:f,deviceID:g,bddID:m,ttwID:b,accessKey:p,aID:T,customParams:P={},enableAutoAck:F,enableQoS:G,QoSLevel:Z,env:Y}=this[s(599)],De,je,ha;this[s(491)+"er"]||this[s(1424)+"X"]||this[s(812)+"T"]?(De=location&&e[s(1121)](s(1475),location[s(1587)])?e[s(1089)]:s(862),je=n[s(1382)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),ha=/^wss(.*:\/\/)/[s(1227)](n)?n:""+De+je):e[s(1830)](e[s(941)],e[s(1343)])?(_0x2b362b(_0x4c6716,96),e.PEkDo(_0x3b4a58,_0x33e8b2,e[s(1365)](_0x1176af,_0x5de00e))):(De=s(1092),je=n[s(1382)](/(^http)((?:[s]*:\/\/))/,""),ha=/(^ws)((?:[s]*:\/\/))/[s(1227)](je)?je:""+De+je);let sl=m?s(338):b?e[s(1765)]:e[s(1023)],ol=m||b||g;if(e[s(1206)](!ol,!sl))throw new Error(e[s(1864)]);let Kp=e[s(405)]("function",typeof P)?await e[s(683)](P):P,$p=Y?e[s(811)](fp,Y[s(1465)],Y[s(1440)]):{},xa=Object[s(465)]({device_platform:e[s(565)],version_code:e[s(1793)],access_key:p,fpid:f,aid:T,[sl]:ol,xsack:F?1:0,xaack:F?1:0,xsqos:G?1:0,qos_level:G?Z:void 0,qos_sdk_version:2,...$p},Kp),Jp=Object.keys(xa).reduce((pa,ga)=>xa[ga]!==void 0?""+pa+(pa?"&":"?")+ga+"="+xa[ga]:pa,"");return ha+s(1027)+Jp}else{let f=this["_endpoin"+s(466)]?.["getCurre"+s(697)+"nt"]();this[s(1531)+"hCloseEv"+s(714)](_0x4bd96d(d[s(546)],{code:1006,reason:s(1682)+f+(" timeout"+s(1233)+s(1573)+s(1453)),wasClean:!0}))}}async[t(1389)](){let n=t,s={zYPoj:function(d,f){return e[q(584)](d,f)}};if(!(this[n(1389)+"Lock"]||this[n(582)+n(1766)])){this["_connect"+n(505)]=!0;try{let d=this[n(549)+n(466)]?.[n(1584)+n(842)+n(1644)+n(1286)+"tries"](),{timeoutInterval:f}=this._options;if(d)if(e.rKcQN(e.iSKqZ,"XSQSN")){let m=this[n(549)+n(466)]?.[n(877)+n(697)+"nt"](),b=this[n(549)+n(466)]?.[n(1325)+n(1106)+n(1523)+n(915)+n(1332)](),p=this[n(549)+n(466)]?.[n(877)+"ntEndpoi"+n(1123)+n(1172)]();if(b){let T="connect "+m+(" timeout"+n(1233)+"tries re"+n(390)+n(1536)+n(476)+"ndpoint ")+b+" to retry",P=e[n(352)](ot,"error",{message:T,code:Qt["MAX_RETR"+n(677)+"R"]});this._debug(T),this["_dispatchErrorEv"+n(714)](P),this._url=await this[n(1055)+n(1617)](b),this[n(1818)](n(1682)+b+" "+p+" times"),this["_removeW"+n(507)+"rs"]()}else{let T=n(1682)+m+(n(638)+", max re"+n(1573)+n(1453));this._debug(T),this["_dispatchErrorEv"+n(714)](ot(n(1364),{message:T,code:Qt[n(605)+n(677)+"R"]}));return}}else _0x22c3c8[n(1545)](_0xd144a1);else if(e[n(1301)](e[n(661)],e[n(1733)])){let m=this._qosDB[n(451)+n(825)+"nc"](this[n(1293)]),b=_0x989532[n(1804)](LYszUo[n(1549)](m,"{}"));return _0x1da2ec[n(1506)](b)}else{let m=this[n(549)+n(466)]?.[n(877)+n(697)+"ntAndUpd"+n(1533)](),b=this["_endpoin"+n(466)]?.[n(877)+n(697)+"ntTriesC"+n(1172)]();this._url=await this[n(1055)+"eUrl"](m||""),this[n(1818)](n(1682)+m+" "+b+n(881)),this[n(1694)+"sListeners"]()}if(this[n(1095)])this._isInit=!1;else{let m=e[n(758)](sa,e[n(1165)],{message:e[n(516)]});this[n(1152)+n(669)]&&this.onStartReconnect(m)}let g=this[n(549)+n(466)]?.[n(877)+n(697)+"ntTriesC"+n(1172)]()||0;e[n(905)](g,1)&&await this[n(603)](e[n(1802)](g,1)),this[n(1818)](n(1003)+"ng url: "+this[n(1103)]+(n(1138)+n(1481))+this[n(1289)+"ls"]),this[n(527)]=e.tHETD(dp,{url:this._url,protocols:[this._protocols],headers:this[n(599)][n(1477)+n(1535)+"s"][n(569)+n(502)]},this[n(599)].ws),(this[n(491)+"er"]||this[n(1495)+"r"])&&this._ws&&(this[n(527)].binaryType=this[n(1391)+"ype"]),this[n(1629)+"steners"](),this[n(1389)+"ionTimeoutId"]=e[n(641)](setTimeout,this[n(705)+"ut"][n(909)](this),f)}catch(d){throw this[n(1389)+n(505)]=!1,d}}}[t(1702)+"mer"](){let n=t;clearTimeout(this[n(1389)+n(1419)+n(954)]),this[n(1389)+n(1419)+"utId"]=null}[t(1025)+t(1443)](){let n=t;e.ieWGi(clearTimeout,this[n(740)+n(453)+"Id"]),e[n(425)](clearTimeout,this[n(1568)+"ctTimeoutId"]),this["_pingPon"+n(453)+"Id"]=null,this["_reconne"+n(1857)+n(987)]=null}[t(1818)](...n){let s=t;this[s(599)][s(1494)]&&console[s(1545)].apply(console,[e[s(1393)],...n])}["_getInte"+t(388)+"e"](n){let s=t,{initReconnectInterval:d,maxReconnectInterval:f,reconnectIntervalGrowFactor:g}=this[s(599)],m=e[s(772)](d,Math.pow(g,e.JXHxi(n,1)));return e[s(1273)](m,f)?f:m}[t(948)](){let n=t;if(this._ws&&e[n(1576)](this._ws.readyState,this[n(1611)+"NG"])){this._clearPingTimer(),this[n(740)+n(453)+"Id"]=e[n(1582)](setTimeout,this[n(948)].bind(this),this[n(599)][n(963)+n(1690)]);return}if(!this[n(527)]||e[n(1562)](this[n(527)][n(1429)+"te"],this.OPEN))return void this["_handleR"+n(669)]();this[n(527)]&&this._ws[n(1195)]("hi"),this[n(1568)+"ctTimeou"+n(987)]=e[n(847)](setTimeout,this[n(1155)+n(669)+"Timeout"][n(909)](this),this[n(599)][n(380)+"outInterval"])}["_handleR"+t(669)+"Timeout"](){let n=t;this[n(367)+n(985)]?.[n(640)](),this.emit(e[n(1381)],n(438)),this[n(367)+n(985)]?.["checkRea"+n(952)+"nt"]()?this[n(1155)+n(669)]():this[n(948)]()}[t(1841)+t(1088)](){let n=t;if(e.xMntK(n(585),e[n(1081)]))this[n(1210)+n(586)+n(1328)+"t"]=0;else return this[n(812)+"T"]||this[n(1424)+"X"]?this[n(783)+"igatorOnline"]:(this[n(491)+"er"]||this._isWorker)&&this[n(599)][n(711)+"tworkCha"+n(1400)]?navigator.onLine:!0}["_handleR"+t(669)](){let n=t;!this[n(1841)+n(1088)]()||this[n(582)+n(1766)]||(this[n(549)+n(466)]?.["resetEnd"+n(771)+n(401)](),this["_pingLos"+n(985)]?.["resetCou"+n(1772)](),this[n(527)]?this[n(989)+n(813)](1001,e.Hdefo,!0):this[n(1389)]())}["_onPageN"+t(993)+t(1779)](){let n=t;this[n(812)+"T"]?tt[n(1760)+"kStatusC"+n(910)](({isConnected:s})=>{let d=n,f={wWuJt:function(g,m){return e.Lhfyy(g,m)},MDGBw:function(g,m){return g&m},SFfyH:function(g,m){return e[q(1860)](g,m)},xQvLz:function(g,m){return e.rLIAC(g,m)},CjqcJ:function(g,m){return e.NSWnd(g,m)},JlqCh:function(g,m){return e[q(1220)](g,m)},KciAl:function(g,m){return e[q(1661)](g,m)},OnpeI:function(g,m){return e[q(474)](g,m)}};if(e[d(590)](e[d(1371)],e[d(1371)])){let g=this[d(1316)],m=this[d(423)];return[kRIjpP[d(1276)](g,24),kRIjpP[d(1020)](kRIjpP.SFfyH(g,16),255),kRIjpP[d(1020)](g>>>8,255),kRIjpP[d(1020)](255,g),kRIjpP[d(1315)](m,24),kRIjpP[d(1153)](kRIjpP[d(1276)](m,16),255),kRIjpP.JlqCh(kRIjpP[d(1033)](m,8),255),kRIjpP.OnpeI(255,m)]}else this[d(783)+d(782)+d(750)]=s,s?this[d(1676)+d(1125)]():this[d(1676)+"ffLine"]()}):this[n(1424)+"X"]&&wx[n(1760)+"kStatusC"+n(910)](({isConnected:s})=>{let d=n,f={lTbwT:d(579)+d(1085)+"s",hwJrz:e[d(955)],KSgeA:function(g,m,b){return g(m,b)}};e[d(1317)]!==e[d(1317)]?(this[d(1025)+d(1443)](),this.emit(FxhqEB.lTbwT,FxhqEB.hwJrz),this[d(740)+d(453)+"Id"]=FxhqEB[d(671)](_0x4f2348,this[d(948)][d(909)](this),_0x25fcdd)):(this[d(783)+"igatorOnline"]=s,s?this._handleOnLine():this[d(1676)+d(403)]())})}[t(603)](n){let s={JNOBK:function(d,f,g){return e.igEuZ(d,f,g)}};return new Promise(d=>{let f=q;s[f(1352)](setTimeout,d,this[f(1383)+f(388)+"e"](n))})}[t(989)+t(813)](n=1e3,s="",d=!1){let f=t;this[f(527)]&&this["_destroy"+f(1190)+"t"](n,s,d)}_onTimeout(){let n=t,s=this["_endpoin"+n(466)]?.["getCurre"+n(697)+"nt"]();this[n(1818)](n(1682)+s+" timeout"),this[n(989)+"ect"](1001,e[n(1775)],!0)}_sendAck(n){let s=t,d=Bt(n);this[s(527)]&&e[s(541)](this[s(527)][s(1429)+"te"],this[s(913)])&&(this[s(527)]&&this[s(527)].send(d),this[s(1818)](s(1294),n))}[t(1694)+t(507)+"rs"](){let n=t,s=e[n(1543)].split("|"),d=0;for(;;){switch(s[d++]){case"0":this._ws[n(1729)+"entListe"+n(997)](e.ZZGOt,this[n(1782)+"ge"]);continue;case"1":this[n(527)][n(1729)+n(1246)+"ner"](e[n(1255)],this[n(731)]);continue;case"2":this[n(527)]["removeEv"+n(1246)+n(997)](e.XDbVl,this[n(1299)]);continue;case"3":if(!this[n(527)])return;continue;case"4":this[n(527)][n(1729)+"entListe"+n(997)](n(1364),this._onError);continue}break}}[t(1629)+t(953)](){let n=t;if(e[n(760)]!==e.BClcx){let s=(n(1200)+"2")[n(1283)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(527)]["addEvent"+n(514)](e[n(1305)],this[n(1782)+"ge"]);continue;case"1":this[n(527)][n(1780)+"Listener"](e[n(1255)],this._onClose);continue;case"2":this[n(527)][n(1780)+n(514)](e[n(614)],this._onError);continue;case"3":this[n(527)][n(1780)+n(514)](e[n(1639)],this[n(1299)]);continue;case"4":if(!this[n(527)])return;continue}break}}else this[n(1822)]=_0x406010,this[n(593)]=_0x3c34ac,this[n(1061)]=_0xa3c283}[t(967)+t(1483)](n=1e3,s=""){let d=t;try{this[d(527)]&&this._ws[d(755)](n,s)}catch{}}[t(1240)+t(1190)+"t"](n=1e3,s="",d=!1){let f=t;if(e[f(600)](e[f(1476)],e[f(1222)])){if(this[f(1025)+f(1443)](),this._clearTimer(),this[f(1694)+f(507)+"rs"](),this[f(967)+f(1483)](1e3,s),this[f(1389)+"Lock"]=!1,d&&this["_navigat"+f(1088)]()&&!this[f(582)+"osed"]){if(this[f(549)+f(466)]?.["checkRea"+f(1342)+"es"]())if(e[f(1060)]!==e[f(1060)])_0x1e2712.body[f(810)+f(1097)](_0x11ff58);else{let m=this[f(549)+f(466)]?.getCurrentEndpoint();this[f(1531)+f(615)+f(714)](e[f(464)](ht,e[f(1255)],{code:1006,reason:f(1682)+m+(f(638)+f(1233)+f(1573)+f(1453)),wasClean:!0}))}else{let m=this._options[f(1459)+f(532)+f(543)](n,s);this["_dispatc"+f(615)+f(714)](e[f(713)](ht,e[f(1255)],{code:n,reason:s,wasClean:!0,willReconnect:m})),m&&this[f(1389)]()}return}this[f(1841)+f(1088)]()||this["_readyCl"+f(1766)]?this[f(1531)+"hCloseEv"+f(714)](e[f(350)](ht,e[f(1255)],{code:n,reason:e[f(730)]})):this[f(1531)+f(615)+f(714)](ht(e.BIcdc,{code:1006,reason:e[f(1705)]})),this[f(527)]=null,this["_endpoin"+f(466)]?.["resetEnd"+f(771)+"fig"](),this[f(367)+f(985)]?.[f(990)+"nter"]()}else fsFEaw[f(789)](_0x12b3ed,_0x338ce0.error),fsFEaw.RrxCi(_0x20d9f5)}[t(1531)+t(904)+"nt"](n){let s=t;this[s(1127)](e[s(1639)],n),this[s(420)]&&this[s(420)](n)}[t(1531)+t(724)+t(1345)](n){let s=t;this[s(1127)](e[s(1305)],n),this.onmessage&&this[s(346)+"e"](n)}["_dispatc"+t(572)+"ageEvent"](n){let s=t;this[s(1127)](e[s(1185)],n),this[s(1456)+s(353)]&&this[s(1456)+s(353)](n)}[t(1531)+t(1161)+t(714)](n){let s=t;this[s(1127)]("error",n),this[s(499)]&&this.onerror(n)}["_dispatc"+t(615)+t(714)](n){let s=t;this[s(1127)](e[s(1255)],n),this[s(386)]&&this[s(386)](n)}get[t(1340)+"pe"](){let n=t;return this[n(527)]?this[n(527)][n(1340)+"pe"]:this._binaryType}set[t(1340)+"pe"](n){let s=t;this[s(1391)+s(1346)]=n,this[s(527)]&&(this._ws.binaryType=n)}get[t(747)+"nt"](){let n=t;return this[n(549)+n(466)]?.[n(877)+"ntEndpoi"+n(1123)+"ount"]()||0}get["buffered"+t(446)](){let n=t;return e.iklGM(e[n(1126)],n(826))?this[n(1566)+"Queue"][n(1796)]((d,f)=>(d+=f&&f[n(400)+"th"]||0,d),0)+(this[n(527)]?this._ws[n(1011)+n(446)]:0):this[n(527)]?this[n(527)].readyState:this[n(599)]["automati"+n(378)]?this[n(1611)+"NG"]:this[n(1471)]}get[t(1348)+"ns"](){let n=t,s={AIApQ:n(1401),ksVEJ:n(1364),EZgkq:function(d){return e[n(683)](d)},kQiUY:function(d){return e[n(1094)](d)}};if(e[n(602)](e.cLobz,e.xgvEl))return this[n(527)]?this[n(527)][n(1348)+"ns"]:"";{let d={hOMNz:function(b,p){return b(p)},RYmsL:n(512)+"or",ugDdS:function(b){let p=n;return NXTWSD[p(1156)](b)}},f=()=>{let b=n;_0xeb9bcd[b(1729)+b(1246)+"ner"](NXTWSD[b(912)],g),_0x28c3df[b(1729)+b(1246)+"ner"](NXTWSD[b(1696)],m),_0x465749[b(1729)+"entListe"+b(997)]("abort",m)},g=()=>{_0x2f5953(),NXTWSD.EZgkq(f)},m=()=>{let b=n;d.hOMNz(_0x18ef43,_0x1d2e68[b(1364)]||new _0x104c8f(d[b(1674)],d[b(1674)])),d[b(475)](f)};_0x4f6f39["addEvent"+n(514)](NXTWSD.AIApQ,g),_0xe31afa[n(1780)+n(514)](NXTWSD[n(1696)],m),_0x517d6c[n(1780)+n(514)]("abort",m)}}get[t(1587)](){let n=t;return this[n(527)]?this[n(527)][n(1587)]:""}get[t(1429)+"te"](){let n=t;return this._ws?this[n(527)].readyState:this[n(599)][n(753)+n(378)]?this[n(1611)+"NG"]:this[n(1471)]}get[t(1308)](){let n=t;return this[n(527)]?this._ws[n(1308)]:this[n(1103)]}[t(755)](n=1e3,s){let d=t,f=e[d(1174)][d(1283)]("|"),g=0;for(;;){switch(f[g++]){case"0":this._clearPingTimer();continue;case"1":this[d(1388)+d(1392)+d(514)]();continue;case"2":this[d(1240)+d(1190)+"t"](n,s);continue;case"3":this[d(1132)+"ger"]?.[d(962)]();continue;case"4":if(e[d(1301)](this._ws[d(1429)+"te"],this.CLOSED)||e.uwUyj(this._ws.readyState,this[d(971)]))return void this[d(1818)](d(1599)+d(691)+"y closed");continue;case"5":this[d(1702)+d(1498)]();continue;case"6":if(!this[d(527)])return void this[d(1818)]("close, w"+d(667)+d(1409)+d(741)+"ed");continue;case"7":this[d(582)+d(1766)]=!0;continue}break}}async send(n,s){let d=t;if(e[d(1730)](null,n))throw new Error(e.xfKhB);e[d(1730)]("number",typeof n)&&(n=JSON[d(587)+"y"](n)),e[d(1090)](e[d(1846)],typeof n)&&!e[d(493)](n,ArrayBuffer)&&!(n[d(461)]&&e[d(509)](n[d(461)],ArrayBuffer))&&(n=JSON[d(587)+"y"](n));let f=await e.Mmxxw(el,n),g=up(n),{method:m=0,service:b=this[d(599)][d(360)],logID:p=this[d(599)][d(1757)+"erator"](),headers:T=this[d(599)].headers,payloadEncoding:P=this[d(599)]["payloadE"+d(1480)],payloadType:F=this[d(599)][d(999)+d(1346)],logIDNew:G=this[d(599)][d(633)+d(1434)][d(1684)+d(1384)+d(965)+"ew"]?i(this[d(599)][d(633)+d(1434)][d(521)]):""}=e[d(1083)](s,{});if(!b)throw new Error(e[d(463)]);let Z={SeqID:ue[d(1204)+"er"](this[d(1501)]++),LogID:ue[d(1204)+"er"](p),service:b,method:m,headers:T,payloadEncoding:e[d(1066)](P,Object)?P[d(922)]?P[d(922)]:"":P,payloadType:e[d(1066)](F,Object)?F[d(374)]?F[d(374)]:g:F||g,payload:f,LogIDNew:G},Y=e[d(889)](Bt,Z);return this[d(527)]&&e[d(1377)](this[d(527)][d(1429)+"te"],this[d(913)])?(this[d(527)]&&this[d(527)][d(1195)](Y),this[d(1818)](e.iRYpz,Z)):e[d(1784)](this[d(1566)+d(664)].length,this[d(599)][d(611)+d(1700)+d(1269)])?(this[d(1566)+d(664)][d(370)](Y),this[d(1818)](e[d(919)],Z)):(this[d(1566)+d(664)][d(1408)](),this[d(1566)+d(664)].push(Y)),{seqID:this[d(1501)],logID:p,logIDNew:G}}async[t(1459)+"t"](n){let s=t,{url:d}=n||{},f=Array[s(871)](d)?d:e[s(1846)]==typeof d?[d]:[];n&&Object[s(465)](this[s(599)],n),f&&f[s(802)]?this[s(549)+s(466)]=new Yd(f,this._options[s(882)+"es"]):this[s(549)+s(466)]?.["resetEndpointCon"+s(401)](),this[s(367)+s(985)]?.[s(990)+s(1772)](this._options[s(1866)+"Count"]),this["_readyCl"+s(1766)]=!1,this._ws&&e[s(389)](this[s(527)][s(1429)+"te"],this[s(1471)])?this[s(989)+s(813)](1e3,e[s(1181)],!0):(this[s(1095)]=!0,this[s(1389)]())}async[t(863)](){let n=t;if(!this[n(1389)+n(505)]){let s=e[n(1586)].split("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1389)]();continue;case"1":this[n(549)+n(466)]?.[n(739)+"pointConfig"]();continue;case"2":this[n(582)+n(1766)]=!1;continue;case"3":this[n(1095)]=!0;continue;case"4":this[n(367)+n(985)]?.["resetCou"+n(1772)]();continue}break}}}["addEvent"+t(514)](n,s){let d=t;if(e[d(793)](e.VyNVP,e[d(1349)]))return this[d(1061)]?.[d(1520)](_0x1961e5);this.on(n,s)}[t(1309)+"Event"](n){let{type:s}=n;this.emit(s,n)}[t(1729)+t(1246)+t(997)](n,s){let d=t;if(e[d(1641)](e[d(1344)],d(1029)))this[d(416)](n,s);else{let f={xgKqc:function(g,m,b,p,T){let P=d;return fsFEaw[P(1791)](g,m,b,p,T)},fxyNS:function(g,m){let b=d;return fsFEaw[b(1307)](g,m)},sfDKd:function(g,m){return g(m)}};_0x5be3cf[d(1780)+d(514)]("upgraden"+d(920),g=>{let m=d;f.xgKqc(_0x446af3,f[m(1248)](_0xbbe68e,_0x4987e0.result),g[m(1327)+"on"],g[m(1304)+"on"],f[m(1144)](_0x5abe0f,_0xa5747a[m(632)+m(1509)]))})}}[t(804)](){let n=t,s={kDYTd:e[n(1423)],XcobY:e.bbtZF,LnKGv:e[n(887)],SnrXk:function(d,f,g){return d(f,g)}};return new Promise((d,f)=>{let g=n,m={PjxNc:s.kDYTd,sFshh:s[g(959)],YwOFq:s[g(504)]};this[g(1025)+"ngTimer"](),this[g(740)+"gTimeoutId"]=s[g(1657)](setTimeout,this[g(948)].bind(this),this[g(599)]["pingInte"+g(1690)]);let b=()=>{let T=g;d(T(972)),this[T(416)](m[T(982)],b),this[T(416)](m[T(501)],p)},p=()=>{let T=g;f(m[T(983)]),this[T(416)](m[T(982)],b),this[T(416)](m[T(501)],p)};this.on(s.kDYTd,b),this.on(s.XcobY,p),this._ping()})}}})(),Ne[M(984)+M(636)]=Te[M(984)+M(636)],Ne["CustomEr"+M(859)]=Te[M(949)+M(859)],Ne[M(703)+"e"]=Te.ErrorCode,Ne[M(1345)]=Te.Event,Ne[M(548)]=Te[M(548)],Ne[M(583)+M(1516)+M(1704)]=Te[M(583)+M(1516)+M(1704)],Ne[M(1516)+M(1704)]=Te[M(1516)+M(1704)],Ne[M(665)+"t"]=Te[M(665)+"t"],Ne["Reconnec"+M(411)]=Te[M(573)+M(411)],Ne[M(1786)+M(636)]=Te["createCl"+M(636)],Ne["createEr"+M(859)]=Te[M(1292)+M(859)],Ne[M(1082)+M(1070)+"nt"]=Te.createMessageEvent,Ne[M(1202)+M(1708)]=Te[M(1202)+"enEvent"],Ne[M(1643)+M(1359)+"vent"]=Te[M(1643)+M(1359)+"vent"],Ne[M(911)+M(528)]=Te["decodedF"+M(528)],Ne["encodeFr"+M(1463)]=Te[M(1624)+"ame"];for(Eo in Te)["CustomCl"+M(636),"CustomEr"+M(859),M(703)+"e",M(1345),"FWS",M(583)+M(1516)+M(1704),"MessageE"+M(1704),M(665)+"t",M(573)+M(411),"createCloseEvent",M(1292)+M(859),M(1082)+"ssageEvent",M(1202)+"enEvent","createRe"+M(1359)+M(1704),M(911)+M(528),M(1624)+M(1463)][M(1067)](Eo)===-1&&(Ne[Eo]=Te[Eo]);var Eo;Object["definePr"+M(1550)](Ne,"__esModule",{value:!0})});var Kt=se((_R,uh)=>{"use strict";var dh=["nodebuffer","arraybuffer","fragments"],lh=typeof Blob<"u";lh&&dh.push("blob");uh.exports={BINARY_TYPES:dh,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:lh,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var Ui=se((yR,Co)=>{"use strict";var{EMPTY_BUFFER:nb}=Kt(),od=Buffer[Symbol.species];function rb(t,e){if(t.length===0)return nb;if(t.length===1)return t[0];let r=Buffer.allocUnsafe(e),i=0;for(let o=0;o<t.length;o++){let c=t[o];r.set(c,i),i+=c.length}return i<e?new od(r.buffer,r.byteOffset,i):r}function fh(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function hh(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function ib(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function ad(t){if(ad.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new od(t):ArrayBuffer.isView(t)?e=new od(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),ad.readOnly=!1),e}Co.exports={concat:rb,mask:fh,toArrayBuffer:ib,toBuffer:ad,unmask:hh};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=de("bufferutil");Co.exports.mask=function(e,r,i,o,c){c<48?fh(e,r,i,o,c):t.mask(e,r,i,o,c)},Co.exports.unmask=function(e,r){e.length<32?hh(e,r):t.unmask(e,r)}}catch{}});var gh=se((ER,ph)=>{"use strict";var xh=Symbol("kDone"),cd=Symbol("kRun"),dd=class{constructor(e){this[xh]=()=>{this.pending--,this[cd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[cd]()}[cd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[xh])}}};ph.exports=dd});var Pr=se((bR,yh)=>{"use strict";var Hi=de("zlib"),mh=Ui(),sb=gh(),{kStatusCode:wh}=Kt(),ob=Buffer[Symbol.species],ab=Buffer.from([0,0,255,255]),Do=Symbol("permessage-deflate"),$t=Symbol("total-length"),Dr=Symbol("callback"),bn=Symbol("buffers"),kr=Symbol("error"),Ro,ld=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,!Ro){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Ro=new sb(r)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[Dr];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,i=e.find(o=>!(r.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>o.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!o.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(i.server_no_context_takeover=!0),r.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(i.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?i.client_max_window_bits=r.clientMaxWindowBits:(i.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(i=>{let o=r[i];if(o.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(o=o[0],i==="client_max_window_bits"){if(o!==!0){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else if(i==="server_max_window_bits"){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(o!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=o})}),e}decompress(e,r,i){Ro.add(o=>{this._decompress(e,r,(c,l)=>{o(),i(c,l)})})}compress(e,r,i){Ro.add(o=>{this._compress(e,r,(c,l)=>{o(),i(c,l)})})}_decompress(e,r,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?Hi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Hi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:l}),this._inflate[Do]=this,this._inflate[$t]=0,this._inflate[bn]=[],this._inflate.on("error",db),this._inflate.on("data",_h)}this._inflate[Dr]=i,this._inflate.write(e),r&&this._inflate.write(ab),this._inflate.flush(()=>{let c=this._inflate[kr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let l=mh.concat(this._inflate[bn],this._inflate[$t]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[$t]=0,this._inflate[bn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,l)})}_compress(e,r,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?Hi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Hi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:l}),this._deflate[$t]=0,this._deflate[bn]=[],this._deflate.on("data",cb)}this._deflate[Dr]=i,this._deflate.write(e),this._deflate.flush(Hi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=mh.concat(this._deflate[bn],this._deflate[$t]);r&&(c=new ob(c.buffer,c.byteOffset,c.length-4)),this._deflate[Dr]=null,this._deflate[$t]=0,this._deflate[bn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};yh.exports=ld;function cb(t){this[bn].push(t),this[$t]+=t.length}function _h(t){if(this[$t]+=t.length,this[Do]._maxPayload<1||this[$t]<=this[Do]._maxPayload){this[bn].push(t);return}this[kr]=new RangeError("Max payload size exceeded"),this[kr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[kr][wh]=1009,this.removeListener("data",_h),this.reset()}function db(t){if(this[Do]._inflate=null,this[kr]){this[Dr](this[kr]);return}t[wh]=1007,this[Dr](t)}});var Or=se((vR,ko)=>{"use strict";var{isUtf8:Eh}=de("buffer"),{hasBlob:lb}=Kt(),ub=[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 fb(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function ud(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 hb(t){return lb&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}ko.exports={isBlob:hb,isValidStatusCode:fb,isValidUTF8:ud,tokenChars:ub};if(Eh)ko.exports.isValidUTF8=function(t){return t.length<24?ud(t):Eh(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=de("utf-8-validate");ko.exports.isValidUTF8=function(e){return e.length<32?ud(e):t(e)}}catch{}});var gd=se((SR,Ch)=>{"use strict";var{Writable:xb}=de("stream"),bh=Pr(),{BINARY_TYPES:pb,EMPTY_BUFFER:vh,kStatusCode:gb,kWebSocket:mb}=Kt(),{concat:fd,toArrayBuffer:wb,unmask:_b}=Ui(),{isValidStatusCode:yb,isValidUTF8:Sh}=Or(),Po=Buffer[Symbol.species],lt=0,Ih=1,Ah=2,Th=3,hd=4,xd=5,Oo=6,pd=class extends xb{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||pb[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[mb]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=lt}_write(e,r,i){if(this._opcode===8&&this._state==lt)return i();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){i(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new Po(i.buffer,i.byteOffset+e,i.length-e),new Po(i.buffer,i.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let i=this._buffers[0],o=r.length-e;e>=i.length?r.set(this._buffers.shift(),o):(r.set(new Uint8Array(i.buffer,i.byteOffset,e),o),this._buffers[0]=new Po(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case lt:this.getInfo(e);break;case Ih:this.getPayloadLength16(e);break;case Ah:this.getPayloadLength64(e);break;case Th:this.getMask();break;case hd:this.getData(e);break;case xd:case Oo:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if((r[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(r[0]&64)===64;if(i&&!this._extensions[bh.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=Ih:this._payloadLength===127?this._state=Ah:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let r=this.consume(8),i=r.readUInt32BE(0);if(i>Math.pow(2,21)-1){let o=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(o);return}this._payloadLength=i*Math.pow(2,32)+r.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let r=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(r);return}this._masked?this._state=Th:this._state=hd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=hd}getData(e){let r=vh;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&&_b(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=xd,this.decompress(r,e);return}if(r.length){if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let i=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(i);return}this._messageLength=this._totalPayloadLength,this._fragments.push(r)}this.dataMessage(e)}decompress(e,r){this._extensions[bh.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let l=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(l);return}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let l=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");r(l);return}this._fragments.push(c)}this.dataMessage(r),this._state===lt&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=lt;return}let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=fd(i,r):this._binaryType==="arraybuffer"?o=wb(fd(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=lt):(this._state=Oo,setImmediate(()=>{this.emit("message",o,!0),this._state=lt,this.startLoop(e)}))}else{let o=fd(i,r);if(!this._skipUTF8Validation&&!Sh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===xd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=lt):(this._state=Oo,setImmediate(()=>{this.emit("message",o,!1),this._state=lt,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,vh),this.end();else{let i=e.readUInt16BE(0);if(!yb(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Po(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!Sh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(c);return}this._loop=!1,this.emit("conclude",i,o),this.end()}this._state=lt;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=lt):(this._state=Oo,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=lt,this.startLoop(r)}))}createError(e,r,i,o,c){this._loop=!1,this._errored=!0;let l=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(l,this.createError),l.code=c,l[gb]=o,l}};Ch.exports=pd});var _d=se((AR,kh)=>{"use strict";var{Duplex:IR}=de("stream"),{randomFillSync:Eb}=de("crypto"),{types:{isUint8Array:bb}}=de("util"),Rh=Pr(),{EMPTY_BUFFER:vb,kWebSocket:Sb,NOOP:Ib}=Kt(),{isBlob:Lr,isValidStatusCode:Ab}=Or(),{mask:Dh,toBuffer:qn}=Ui(),ut=Symbol("kByteLength"),Tb=Buffer.alloc(4),Lo=8*1024,Gn,Nr=Lo,bt=0,Cb=1,Rb=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=bt,this.onerror=Ib,this[Sb]=void 0}static frame(e,r){let i,o=!1,c=2,l=!1;r.mask&&(i=r.maskBuffer||Tb,r.generateMask?r.generateMask(i):(Nr===Lo&&(Gn===void 0&&(Gn=Buffer.alloc(Lo)),Eb(Gn,0,Lo),Nr=0),i[0]=Gn[Nr++],i[1]=Gn[Nr++],i[2]=Gn[Nr++],i[3]=Gn[Nr++]),l=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||l)&&r[ut]!==void 0?u=r[ut]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!l);let 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]=r.fin?r.opcode|128:r.opcode,r.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)),r.mask?(x[1]|=128,x[c-4]=i[0],x[c-3]=i[1],x[c-2]=i[2],x[c-1]=i[3],l?[x,e]:o?(Dh(e,i,x,c,u),[x]):(Dh(e,i,e,0,u),[x,e])):[x,e]}close(e,r,i,o){let c;if(e===void 0)c=vb;else{if(typeof e!="number"||!Ab(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(r);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");if(c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof r=="string")c.write(r,2);else if(bb(r))c.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let l={[ut]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==bt?this.enqueue([this.dispatch,c,!1,l,o]):this.sendFrame(t.frame(c,l),o)}ping(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Lr(e)?(o=e.size,c=!1):(e=qn(e),o=e.length,c=qn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ut]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Lr(e)?this._state!==bt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==bt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}pong(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Lr(e)?(o=e.size,c=!1):(e=qn(e),o=e.length,c=qn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ut]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Lr(e)?this._state!==bt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==bt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}send(e,r,i){let o=this._extensions[Rh.extensionName],c=r.binary?2:1,l=r.compress,u,h;typeof e=="string"?(u=Buffer.byteLength(e),h=!1):Lr(e)?(u=e.size,h=!1):(e=qn(e),u=e.length,h=qn.readOnly),this._firstFragment?(this._firstFragment=!1,l&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(l=u>=o._threshold),this._compress=l):(l=!1,c=0),r.fin&&(this._firstFragment=!0);let x={[ut]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:h,rsv1:l};Lr(e)?this._state!==bt?this.enqueue([this.getBlobData,e,this._compress,x,i]):this.getBlobData(e,this._compress,x,i):this._state!==bt?this.enqueue([this.dispatch,e,this._compress,x,i]):this.dispatch(e,this._compress,x,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[ut],this._state=Rb,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(wd,this,u,o);return}this._bufferedBytes-=i[ut];let l=qn(c);r?this.dispatch(l,r,i,o):(this._state=bt,this.sendFrame(t.frame(l,i),o),this.dequeue())}).catch(c=>{process.nextTick(Db,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Rh.extensionName];this._bufferedBytes+=i[ut],this._state=Cb,c.compress(e,i.fin,(l,u)=>{if(this._socket.destroyed){let h=new Error("The socket was closed while data was being compressed");wd(this,h,o);return}this._bufferedBytes-=i[ut],this._state=bt,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===bt&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][ut],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][ut],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};kh.exports=md;function wd(t,e,r){typeof r=="function"&&r(e);for(let i=0;i<t._queue.length;i++){let o=t._queue[i],c=o[o.length-1];typeof c=="function"&&c(e)}}function Db(t,e,r){wd(t,e,r),t.onerror(e)}});var Uh=se((TR,zh)=>{"use strict";var{kForOnEventAttribute:qi,kListener:yd}=Kt(),Ph=Symbol("kCode"),Oh=Symbol("kData"),Lh=Symbol("kError"),Nh=Symbol("kMessage"),Mh=Symbol("kReason"),Mr=Symbol("kTarget"),Bh=Symbol("kType"),Fh=Symbol("kWasClean"),Jt=class{constructor(e){this[Mr]=null,this[Bh]=e}get target(){return this[Mr]}get type(){return this[Bh]}};Object.defineProperty(Jt.prototype,"target",{enumerable:!0});Object.defineProperty(Jt.prototype,"type",{enumerable:!0});var jn=class extends Jt{constructor(e,r={}){super(e),this[Ph]=r.code===void 0?0:r.code,this[Mh]=r.reason===void 0?"":r.reason,this[Fh]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Ph]}get reason(){return this[Mh]}get wasClean(){return this[Fh]}};Object.defineProperty(jn.prototype,"code",{enumerable:!0});Object.defineProperty(jn.prototype,"reason",{enumerable:!0});Object.defineProperty(jn.prototype,"wasClean",{enumerable:!0});var Br=class extends Jt{constructor(e,r={}){super(e),this[Lh]=r.error===void 0?null:r.error,this[Nh]=r.message===void 0?"":r.message}get error(){return this[Lh]}get message(){return this[Nh]}};Object.defineProperty(Br.prototype,"error",{enumerable:!0});Object.defineProperty(Br.prototype,"message",{enumerable:!0});var Gi=class extends Jt{constructor(e,r={}){super(e),this[Oh]=r.data===void 0?null:r.data}get data(){return this[Oh]}};Object.defineProperty(Gi.prototype,"data",{enumerable:!0});var kb={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[qi]&&o[yd]===e&&!o[qi])return;let i;if(t==="message")i=function(c,l){let u=new Gi("message",{data:l?c:c.toString()});u[Mr]=this,No(e,this,u)};else if(t==="close")i=function(c,l){let u=new jn("close",{code:c,reason:l.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Mr]=this,No(e,this,u)};else if(t==="error")i=function(c){let l=new Br("error",{error:c,message:c.message});l[Mr]=this,No(e,this,l)};else if(t==="open")i=function(){let c=new Jt("open");c[Mr]=this,No(e,this,c)};else return;i[qi]=!!r[qi],i[yd]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[yd]===e&&!r[qi]){this.removeListener(t,r);break}}};zh.exports={CloseEvent:jn,ErrorEvent:Br,Event:Jt,EventTarget:kb,MessageEvent:Gi};function No(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Mo=se((CR,Hh)=>{"use strict";var{tokenChars:ji}=Or();function Mt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function Pb(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,l,u,h=-1,x=-1,w=-1,_=0;for(;_<t.length;_++)if(x=t.charCodeAt(_),l===void 0)if(w===-1&&ji[x]===1)h===-1&&(h=_);else if(_!==0&&(x===32||x===9))w===-1&&h!==-1&&(w=_);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${_}`);w===-1&&(w=_);let E=t.slice(h,w);x===44?(Mt(e,E,r),r=Object.create(null)):l=E,h=w=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);else if(u===void 0)if(w===-1&&ji[x]===1)h===-1&&(h=_);else if(x===32||x===9)w===-1&&h!==-1&&(w=_);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${_}`);w===-1&&(w=_),Mt(r,t.slice(h,w),!0),x===44&&(Mt(e,l,r),r=Object.create(null),l=void 0),h=w=-1}else if(x===61&&h!==-1&&w===-1)u=t.slice(h,_),h=w=-1;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(o){if(ji[x]!==1)throw new SyntaxError(`Unexpected character at index ${_}`);h===-1?h=_:i||(i=!0),o=!1}else if(c)if(ji[x]===1)h===-1&&(h=_);else if(x===34&&h!==-1)c=!1,w=_;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(w===-1&&ji[x]===1)h===-1&&(h=_);else if(h!==-1&&(x===32||x===9))w===-1&&(w=_);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${_}`);w===-1&&(w=_);let E=t.slice(h,w);i&&(E=E.replace(/\\/g,""),i=!1),Mt(r,u,E),x===44&&(Mt(e,l,r),r=Object.create(null),l=void 0),u=void 0,h=w=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);if(h===-1||c||x===32||x===9)throw new SyntaxError("Unexpected end of input");w===-1&&(w=_);let S=t.slice(h,w);return l===void 0?Mt(e,S,r):(u===void 0?Mt(r,S,!0):i?Mt(r,u,S.replace(/\\/g,"")):Mt(r,u,S),Mt(e,l,r)),e}function Ob(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(i=>[e].concat(Object.keys(i).map(o=>{let c=i[o];return Array.isArray(c)||(c=[c]),c.map(l=>l===!0?o:`${o}=${l}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Hh.exports={format:Ob,parse:Pb}});var Uo=se((kR,Qh)=>{"use strict";var Lb=de("events"),Nb=de("https"),Mb=de("http"),jh=de("net"),Bb=de("tls"),{randomBytes:Fb,createHash:zb}=de("crypto"),{Duplex:RR,Readable:DR}=de("stream"),{URL:Ed}=de("url"),vn=Pr(),Ub=gd(),Hb=_d(),{isBlob:qb}=Or(),{BINARY_TYPES:qh,CLOSE_TIMEOUT:Gb,EMPTY_BUFFER:Bo,GUID:jb,kForOnEventAttribute:bd,kListener:Wb,kStatusCode:Kb,kWebSocket:Ue,NOOP:Wh}=Kt(),{EventTarget:{addEventListener:$b,removeEventListener:Jb}}=Uh(),{format:Vb,parse:Yb}=Mo(),{toBuffer:Zb}=Ui(),Kh=Symbol("kAborted"),vd=[8,13],Vt=["CONNECTING","OPEN","CLOSING","CLOSED"],Xb=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,ge=class t extends Lb{constructor(e,r,i){super(),this._binaryType=qh[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Bo,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),$h(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){qh.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 Ub({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 Hb(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[Ue]=this,c[Ue]=this,e[Ue]=this,o.on("conclude",tv),o.on("drain",nv),o.on("error",rv),o.on("message",iv),o.on("ping",sv),o.on("pong",ov),c.onerror=av,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Yh),e.on("data",zo),e.on("end",Zh),e.on("error",Xh),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[vn.extensionName]&&this._extensions[vn.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){st(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),Vh(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Sd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Bo,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Sd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Bo,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Sd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[vn.extensionName]||(o.compress=!1),this._sender.send(e||Bo,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){st(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(ge,"CONNECTING",{enumerable:!0,value:Vt.indexOf("CONNECTING")});Object.defineProperty(ge.prototype,"CONNECTING",{enumerable:!0,value:Vt.indexOf("CONNECTING")});Object.defineProperty(ge,"OPEN",{enumerable:!0,value:Vt.indexOf("OPEN")});Object.defineProperty(ge.prototype,"OPEN",{enumerable:!0,value:Vt.indexOf("OPEN")});Object.defineProperty(ge,"CLOSING",{enumerable:!0,value:Vt.indexOf("CLOSING")});Object.defineProperty(ge.prototype,"CLOSING",{enumerable:!0,value:Vt.indexOf("CLOSING")});Object.defineProperty(ge,"CLOSED",{enumerable:!0,value:Vt.indexOf("CLOSED")});Object.defineProperty(ge.prototype,"CLOSED",{enumerable:!0,value:Vt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(ge.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(ge.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[bd])return e[Wb];return null},set(e){for(let r of this.listeners(t))if(r[bd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[bd]:!0})}})});ge.prototype.addEventListener=$b;ge.prototype.removeEventListener=Jb;Qh.exports=ge;function $h(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:Gb,protocolVersion:vd[1],maxBufferedChunks:1048576,maxFragments:131072,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=o.autoPong,t._closeTimeout=o.closeTimeout,!vd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${vd.join(", ")})`);let c;if(e instanceof Ed)c=e;else try{c=new Ed(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 A=new SyntaxError(h);if(t._redirects===0)throw A;Fo(t,A);return}let x=l?443:80,w=Fb(16).toString("base64"),_=l?Nb.request:Mb.request,S=new Set,E;if(o.createConnection=o.createConnection||(l?ev:Qb),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":w,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(E=new vn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=Vb({[vn.extensionName]:E.offer()})),r.length){for(let A of r){if(typeof A!="string"||!Xb.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=l,t._originalHostOrSocketPath=u?o.socketPath:c.host;let A=i&&i.headers;if(i={...i,headers:{}},A)for(let[I,R]of Object.entries(A))i.headers[I.toLowerCase()]=R}else if(t.listenerCount("redirect")===0){let A=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!A||t._originalSecure&&!l)&&(delete o.headers.authorization,delete o.headers.cookie,A||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),v=t._req=_(o),t._redirects&&t.emit("redirect",t.url,v)}else v=t._req=_(o);o.timeout&&v.on("timeout",()=>{st(t,v,"Opening handshake has timed out")}),v.on("error",A=>{v===null||v[Kh]||(v=t._req=null,Fo(t,A))}),v.on("response",A=>{let I=A.headers.location,R=A.statusCode;if(I&&o.followRedirects&&R>=300&&R<400){if(++t._redirects>o.maxRedirects){st(t,v,"Maximum redirects exceeded");return}v.abort();let L;try{L=new Ed(I,e)}catch{let D=new SyntaxError(`Invalid URL: ${I}`);Fo(t,D);return}$h(t,L,r,i)}else t.emit("unexpected-response",v,A)||st(t,v,`Unexpected server response: ${A.statusCode}`)}),v.on("upgrade",(A,I,R)=>{if(t.emit("upgrade",A),t.readyState!==ge.CONNECTING)return;v=t._req=null;let L=A.headers.upgrade;if(L===void 0||L.toLowerCase()!=="websocket"){st(t,I,"Invalid Upgrade header");return}let y=zb("sha1").update(w+jb).digest("base64");if(A.headers["sec-websocket-accept"]!==y){st(t,I,"Invalid Sec-WebSocket-Accept header");return}let D=A.headers["sec-websocket-protocol"],k;if(D!==void 0?S.size?S.has(D)||(k="Server sent an invalid subprotocol"):k="Server sent a subprotocol but none was requested":S.size&&(k="Server sent no subprotocol"),k){st(t,I,k);return}D&&(t._protocol=D);let N=A.headers["sec-websocket-extensions"];if(N!==void 0){if(!E){st(t,I,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let B;try{B=Yb(N)}catch{st(t,I,"Invalid Sec-WebSocket-Extensions header");return}let V=Object.keys(B);if(V.length!==1||V[0]!==vn.extensionName){st(t,I,"Server indicated an extension that was not requested");return}try{E.accept(B[vn.extensionName])}catch{st(t,I,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[vn.extensionName]=E}t.setSocket(I,R,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(v,t):v.end()}function Fo(t,e){t._readyState=ge.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Qb(t){return t.path=t.socketPath,jh.connect(t)}function ev(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=jh.isIP(t.host)?"":t.host),Bb.connect(t)}function st(t,e,r){t._readyState=ge.CLOSING;let i=new Error(r);Error.captureStackTrace(i,st),e.setHeader?(e[Kh]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Fo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Sd(t,e,r){if(e){let i=qb(e)?e.size:Zb(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Vt[t.readyState]})`);process.nextTick(r,i)}}function tv(t,e){let r=this[Ue];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Ue]!==void 0&&(r._socket.removeListener("data",zo),process.nextTick(Jh,r._socket),t===1005?r.close():r.close(t,e))}function nv(){let t=this[Ue];t.isPaused||t._socket.resume()}function rv(t){let e=this[Ue];e._socket[Ue]!==void 0&&(e._socket.removeListener("data",zo),process.nextTick(Jh,e._socket),e.close(t[Kb])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Gh(){this[Ue].emitClose()}function iv(t,e){this[Ue].emit("message",t,e)}function sv(t){let e=this[Ue];e._autoPong&&e.pong(t,!this._isServer,Wh),e.emit("ping",t)}function ov(t){this[Ue].emit("pong",t)}function Jh(t){t.resume()}function av(t){let e=this[Ue];e.readyState!==ge.CLOSED&&(e.readyState===ge.OPEN&&(e._readyState=ge.CLOSING,Vh(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Vh(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Yh(){let t=this[Ue];if(this.removeListener("close",Yh),this.removeListener("data",zo),this.removeListener("end",Zh),t._readyState=ge.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[Ue]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Gh),t._receiver.on("finish",Gh))}function zo(t){this[Ue]._receiver.write(t)||this.pause()}function Zh(){let t=this[Ue];t._readyState=ge.CLOSING,t._receiver.end(),this.end()}function Xh(){let t=this[Ue];this.removeListener("error",Xh),this.on("error",Wh),t&&(t._readyState=ge.CLOSING,this.destroy())}});var rx=se((OR,nx)=>{"use strict";var PR=Uo(),{Duplex:cv}=de("stream");function ex(t){t.emit("close")}function dv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function tx(t){this.removeListener("error",tx),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function lv(t,e){let r=!0,i=new cv({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,l){let u=!l&&i._readableState.objectMode?c.toString():c;i.push(u)||t.pause()}),t.once("error",function(c){i.destroyed||(r=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick(ex,i);return}let l=!1;t.once("error",function(h){l=!0,c(h)}),t.once("close",function(){l||c(o),process.nextTick(ex,i)}),r&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,l){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,l)});return}t.send(o,l)},i.on("end",dv),i.on("error",tx),i}nx.exports=lv});var Id=se((LR,ix)=>{"use strict";var{tokenChars:uv}=Or();function fv(t){let e=new Set,r=-1,i=-1,o=0;for(o;o<t.length;o++){let l=t.charCodeAt(o);if(i===-1&&uv[l]===1)r===-1&&(r=o);else if(o!==0&&(l===32||l===9))i===-1&&r!==-1&&(i=o);else if(l===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let u=t.slice(r,i);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);e.add(u),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(r,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}ix.exports={parse:fv}});var ux=se((MR,lx)=>{"use strict";var hv=de("events"),Ho=de("http"),{Duplex:NR}=de("stream"),{createHash:xv}=de("crypto"),sx=Mo(),Wn=Pr(),pv=Id(),gv=Uo(),{CLOSE_TIMEOUT:mv,GUID:wv,kWebSocket:_v}=Kt(),yv=/^[+/0-9A-Za-z]{22}==$/,ox=0,ax=1,dx=2,Ad=class extends hv{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:1024*1024,maxFragments:128*1024,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:mv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:gv,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=Ho.createServer((i,o)=>{let c=Ho.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=Ev(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=ox}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===dx){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Wi,this);return}if(e&&this.once("close",e),this._state!==ax)if(this._state=ax,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(Wi,this):process.nextTick(Wi,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{Wi(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",cx);let c=e.headers["sec-websocket-key"],l=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Kn(this,e,r,405,"Invalid HTTP method");return}if(l===void 0||l.toLowerCase()!=="websocket"){Kn(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!yv.test(c)){Kn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){Kn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Ki(r,400);return}let h=e.headers["sec-websocket-protocol"],x=new Set;if(h!==void 0)try{x=pv.parse(h)}catch{Kn(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let w=e.headers["sec-websocket-extensions"],_={};if(this.options.perMessageDeflate&&w!==void 0){let S=new Wn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let E=sx.parse(w);E[Wn.extensionName]&&(S.accept(E[Wn.extensionName]),_[Wn.extensionName]=S)}catch{Kn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let S={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(S,(E,v,A,I)=>{if(!E)return Ki(r,v||401,A,I);this.completeUpgrade(_,c,x,e,r,i,o)});return}if(!this.options.verifyClient(S))return Ki(r,401)}this.completeUpgrade(_,c,x,e,r,i,o)}completeUpgrade(e,r,i,o,c,l,u){if(!c.readable||!c.writable)return c.destroy();if(c[_v])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>ox)return Ki(c,503);let x=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${xv("sha1").update(r+wv).digest("base64")}`],w=new this.options.WebSocket(null,void 0,this.options);if(i.size){let _=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;_&&(x.push(`Sec-WebSocket-Protocol: ${_}`),w._protocol=_)}if(e[Wn.extensionName]){let _=e[Wn.extensionName].params,S=sx.format({[Wn.extensionName]:[_]});x.push(`Sec-WebSocket-Extensions: ${S}`),w._extensions=e}this.emit("headers",x,o),c.write(x.concat(`\r
15
15
  `).join(`\r
16
- `)),c.removeListener("error",ox),m.setSocket(c,l,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(m),m.on("close",()=>{this.clients.delete(m),this._shouldEmitClose&&!this.clients.size&&process.nextTick($i,this)})),u(m,o)}};cx.exports=Il;function mv(t,e){for(let r of Object.keys(e))t.on(r,e[r]);return function(){for(let i of Object.keys(e))t.removeListener(i,e[i])}}function $i(t){t._state=ax,t.emit("close")}function ox(){this.destroy()}function Vi(t,e,r,i){r=r||Ho.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${Ho.STATUS_CODES[e]}\r
16
+ `)),c.removeListener("error",cx),w.setSocket(c,l,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxBufferedChunks:this.options.maxBufferedChunks,maxFragments:this.options.maxFragments,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(w),w.on("close",()=>{this.clients.delete(w),this._shouldEmitClose&&!this.clients.size&&process.nextTick(Wi,this)})),u(w,o)}};lx.exports=Ad;function Ev(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 Wi(t){t._state=dx,t.emit("close")}function cx(){this.destroy()}function Ki(t,e,r,i){r=r||Ho.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${Ho.STATUS_CODES[e]}\r
17
17
  `+Object.keys(i).map(o=>`${o}: ${i[o]}`).join(`\r
18
18
  `)+`\r
19
19
  \r
20
- `+r)}function Kn(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let l=new Error(o);Error.captureStackTrace(l,Kn),t.emit("wsClientError",l,r,e)}else Vi(r,i,o,c)}});import{existsSync as Gv,openSync as jv}from"node:fs";import{mkdir as Wv}from"node:fs/promises";import{dirname as Kv}from"node:path";import{fileURLToPath as $v}from"node:url";function Jv(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Dl(t=X()){return Gv(t.libEntry)?t.libEntry:$v(new URL("../index.ts",import.meta.url))}async function vx(t={}){let e=t.paths??X(),r=t.entryOverride??Dl(e),i=Jv(e,process.env.COZE_BRIDGE_LOG_MODE);await Wv(Kv(i),{recursive:!0});let o=jv(i,"a"),l=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=at(process.execPath,l,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[Yi]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return Vv.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var Vv,Yi,Ko=Je(()=>{"use strict";yn();ee();ke();Vv=H("spawn-daemon"),Yi="COZE_BRIDGE_DAEMON"});import{spawn as qS}from"node:child_process";import{mkdir as GS,unlink as jS,writeFile as WS}from"node:fs/promises";import{dirname as KS,join as $S}from"node:path";function qr(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function VS(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${qr(r)}</key>
21
- <string>${qr(i)}</string>`).join(`
20
+ `+r)}function Kn(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let l=new Error(o);Error.captureStackTrace(l,Kn),t.emit("wsClientError",l,r,e)}else Ki(r,i,o,c)}});import{existsSync as Wv,openSync as Kv}from"node:fs";import{mkdir as $v}from"node:fs/promises";import{dirname as Jv}from"node:path";import{fileURLToPath as Vv}from"node:url";function Zv(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Dd(t=Q()){return Wv(t.libEntry)?t.libEntry:Vv(new URL("../index.ts",import.meta.url))}async function Ax(t={}){let e=t.paths??Q(),r=t.entryOverride??Dd(e),i=Zv(e,process.env.COZE_BRIDGE_LOG_MODE);await $v(Jv(i),{recursive:!0});let o=Kv(i,"a"),l=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=dt(process.execPath,l,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[Vi]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return Yv.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var Yv,Vi,Ko=Ve(()=>{"use strict";_n();ne();ke();Yv=U("spawn-daemon"),Vi="COZE_BRIDGE_DAEMON"});import{spawn as US}from"node:child_process";import{mkdir as HS,unlink as qS,writeFile as GS}from"node:fs/promises";import{dirname as jS,join as WS}from"node:path";function Hr(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function KS(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Hr(r)}</key>
21
+ <string>${Hr(i)}</string>`).join(`
22
22
  `);return e?`
23
23
  <key>EnvironmentVariables</key>
24
24
  <dict>
25
25
  ${e}
26
- </dict>`:""}function JS(t,e){return new Promise((r,i)=>{let o=qS(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?r():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var Hr,Qi,Qo,zl,Gx=Je(()=>{"use strict";ee();Hr=H("supervisor.launchd"),Qi="ai.coze.bridge",Qo=JS,zl={platform:"darwin",renderConfig(t){return`<?xml version="1.0" encoding="UTF-8"?>
26
+ </dict>`:""}function $S(t,e){return new Promise((r,i)=>{let o=US(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?r():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var Ur,Zi,Qo,Bd,Gx=Ve(()=>{"use strict";ne();Ur=U("supervisor.launchd"),Zi="ai.coze.bridge",Qo=$S,Bd={platform:"darwin",renderConfig(t){return`<?xml version="1.0" encoding="UTF-8"?>
27
27
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
28
28
  <plist version="1.0">
29
29
  <dict>
30
30
  <key>Label</key>
31
- <string>${Qi}</string>
31
+ <string>${Zi}</string>
32
32
  <key>ProgramArguments</key>
33
33
  <array>
34
- <string>${qr(t.nodeBin)}</string>
35
- <string>${qr(t.entry)}</string>
34
+ <string>${Hr(t.nodeBin)}</string>
35
+ <string>${Hr(t.entry)}</string>
36
36
  <string>--daemon</string>
37
37
  </array>
38
38
  <key>RunAtLoad</key>
@@ -42,13 +42,13 @@ ${e}
42
42
  <key>ThrottleInterval</key>
43
43
  <integer>10</integer>
44
44
  <key>StandardOutPath</key>
45
- <string>${qr(t.logFile)}</string>
45
+ <string>${Hr(t.logFile)}</string>
46
46
  <key>StandardErrorPath</key>
47
- <string>${qr(t.logFile)}</string>${VS(t.env)}
47
+ <string>${Hr(t.logFile)}</string>${KS(t.env)}
48
48
  </dict>
49
49
  </plist>
50
- `},configPath(t){return $S(t.homeDir,"Library","LaunchAgents",`${Qi}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await GS(KS(i),{recursive:!0}),await WS(i,this.renderConfig(t),"utf8"),Hr.info("plist written",{plistPath:i,activate:r}),!r)return;await Qo("launchctl",["unload","-w",i]).catch(c=>Hr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await Qo("launchctl",["load","-w",i]),Hr.info("launchd job loaded",{label:Qi});let o=process.getuid?.()??0;await Qo("launchctl",["kickstart","-k",`gui/${o}/${Qi}`]),Hr.info("launchd job kickstarted",{label:Qi,uid:o})},async uninstall(t){let e=this.configPath(t);await Qo("launchctl",["unload","-w",e]).catch(r=>Hr.warn("launchctl unload failed (ignored)",{err:String(r)})),await jS(e).catch(r=>{if(r.code!=="ENOENT")throw r}),Hr.info("launchd job removed",{plistPath:e})}}});import{spawn as ZS}from"node:child_process";import{mkdir as YS,unlink as XS,writeFile as QS}from"node:fs/promises";import{dirname as e1,join as jx}from"node:path";function ta(t,e){return t.isRoot?e:["--user",...e]}function n1(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
- `):""}function na(t,e){return new Promise((r,i)=>{let o=ZS(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?r():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var ea,Gr,t1,Ul,Wx=Je(()=>{"use strict";ee();ea=H("supervisor.systemd"),Gr="coze-bridge.service",t1="/etc/systemd/system";Ul={platform:"linux",renderConfig(t){let e=t.isRoot?"multi-user.target":"default.target";return`[Unit]
50
+ `},configPath(t){return WS(t.homeDir,"Library","LaunchAgents",`${Zi}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await HS(jS(i),{recursive:!0}),await GS(i,this.renderConfig(t),"utf8"),Ur.info("plist written",{plistPath:i,activate:r}),!r)return;await Qo("launchctl",["unload","-w",i]).catch(c=>Ur.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await Qo("launchctl",["load","-w",i]),Ur.info("launchd job loaded",{label:Zi});let o=process.getuid?.()??0;await Qo("launchctl",["kickstart","-k",`gui/${o}/${Zi}`]),Ur.info("launchd job kickstarted",{label:Zi,uid:o})},async uninstall(t){let e=this.configPath(t);await Qo("launchctl",["unload","-w",e]).catch(r=>Ur.warn("launchctl unload failed (ignored)",{err:String(r)})),await qS(e).catch(r=>{if(r.code!=="ENOENT")throw r}),Ur.info("launchd job removed",{plistPath:e})}}});import{spawn as JS}from"node:child_process";import{mkdir as VS,unlink as YS,writeFile as ZS}from"node:fs/promises";import{dirname as XS,join as jx}from"node:path";function ta(t,e){return t.isRoot?e:["--user",...e]}function e1(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
+ `):""}function na(t,e){return new Promise((r,i)=>{let o=JS(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?r():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var ea,qr,QS,Fd,Wx=Ve(()=>{"use strict";ne();ea=U("supervisor.systemd"),qr="coze-bridge.service",QS="/etc/systemd/system";Fd={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
- ${n1(t.env)}
62
+ ${e1(t.env)}
63
63
  [Install]
64
64
  WantedBy=${e}
65
- `},configPath(t){return t.isRoot?jx(t1,Gr):jx(t.homeDir,".config","systemd","user",Gr)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await YS(e1(i),{recursive:!0}),await QS(i,this.renderConfig(t),"utf8"),ea.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await na("systemctl",ta(t,["daemon-reload"])),await na("systemctl",ta(t,r?["enable","--now",Gr]:["enable",Gr])),ea.info("systemd unit enabled",{unitName:Gr,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await na("systemctl",ta(t,["disable","--now",Gr])).catch(r=>ea.warn("systemctl disable failed (ignored)",{err:String(r)})),await XS(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await na("systemctl",ta(t,["daemon-reload"])).catch(()=>{}),ea.info("systemd unit removed",{unitPath:e})}}});import{spawn as r1}from"node:child_process";import{join as i1}from"node:path";function Kx(t,e){return new Promise((r,i)=>{let o=r1(t,e,{stdio:["ignore","pipe","pipe"],shell:!1}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?r():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var Hl,ra,ql,$x=Je(()=>{"use strict";ee();Hl=H("supervisor.taskscheduler"),ra="CozeBridge",ql={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
65
+ `},configPath(t){return t.isRoot?jx(QS,qr):jx(t.homeDir,".config","systemd","user",qr)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await VS(XS(i),{recursive:!0}),await ZS(i,this.renderConfig(t),"utf8"),ea.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await na("systemctl",ta(t,["daemon-reload"])),await na("systemctl",ta(t,r?["enable","--now",qr]:["enable",qr])),ea.info("systemd unit enabled",{unitName:qr,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await na("systemctl",ta(t,["disable","--now",qr])).catch(r=>ea.warn("systemctl disable failed (ignored)",{err:String(r)})),await YS(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await na("systemctl",ta(t,["daemon-reload"])).catch(()=>{}),ea.info("systemd unit removed",{unitPath:e})}}});import{spawn as t1}from"node:child_process";import{join as n1}from"node:path";function Kx(t,e){return new Promise((r,i)=>{let o=t1(t,e,{stdio:["ignore","pipe","pipe"],shell:!1}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?r():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var zd,ra,Ud,$x=Ve(()=>{"use strict";ne();zd=U("supervisor.taskscheduler"),ra="CozeBridge",Ud={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
66
66
  <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
67
67
  <RegistrationInfo>
68
68
  <Description>Coze Bridge daemon</Description>
@@ -86,45 +86,43 @@ WantedBy=${e}
86
86
  </Exec>
87
87
  </Actions>
88
88
  </Task>
89
- `},configPath(t){return i1(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 Kx("schtasks",["/Create","/SC","ONLOGON","/TN",ra,"/TR",r,"/RU",t.userName,"/F"]),Hl.info("task scheduler entry created",{task:ra,logFile:t.logFile})},async uninstall(t){await Kx("schtasks",["/Delete","/TN",ra,"/F"]).catch(e=>Hl.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Hl.info("task scheduler entry removed",{task:ra})}}});var Vx={};_a(Vx,{buildContext:()=>d1,getSupervisor:()=>a1,launchdSupervisor:()=>zl,systemdSupervisor:()=>Ul,taskSchedulerSupervisor:()=>ql});import{homedir as s1,userInfo as o1}from"node:os";function a1(t=process.platform){switch(t){case"darwin":return zl;case"linux":return Ul;case"win32":return ql;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function l1(){let t={};for(let e of c1){let r=process.env[e];r&&(t[e]=r)}return t}function d1(){let t=X();return{nodeBin:process.execPath,entry:Dl(t),logFile:t.logFile,homeDir:s1(),userName:o1().username,isRoot:process.getuid?.()===0,env:l1()}}var c1,Jx=Je(()=>{"use strict";ke();Ko();Gx();Wx();$x();c1=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ee();nn();var wd=H("acp-installer-warmup"),yg=["claude-code","codex"];async function _d(t={}){let e=t.ensure??tr,i=(await Promise.allSettled(yg.map(async o=>{let c=await e(o);wd.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&wd.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}rn();ee();import{readdir as Pg}from"node:fs/promises";import{mkdir as Id,writeFile as Ad}from"node:fs/promises";import{join as Aa}from"node:path";var kg={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function ir(t,e,r){await Id(t,{recursive:!0});let i=kg[e],o=Aa(t,i);return await Ad(o,r??"","utf8"),o}async function Td(t,e){let r=Aa(t,".claude");await Id(r,{recursive:!0});let i=Aa(r,"settings.local.json"),o={permissions:{defaultMode:"bypassPermissions"}};e==="cloud"&&(o.autoCompactWindow=15e4);let c=JSON.stringify(o,null,2);return await Ad(i,c,"utf8"),i}var Ke=H("agent-detail-sync"),Og=6e4,Lg=5*6e4,ds=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await Pg(r)}catch(o){Ke.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}Ke.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await He(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Ke.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(l){Ke.warn("detail sync failed for agent, skipping",{agentId:o,err:String(l)})}}})),Ke.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){Ke.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){Ke.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await He(e,this.opts.paths);if(!i){Ke.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(f){Ke.warn("detail RPC failed, using local data",{agentId:e,err:String(f)});let x=this.retryQueue.get(e),m=x?Math.min(x.currentDelay*2,Lg):Og;this.retryQueue.set(e,{dueAt:Date.now()+m,currentDelay:m});return}if(o.agentId&&o.agentId!==e){Ke.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"?(Ke.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&Ke.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Ke.debug("detail sync: no diff",{agentId:e});return}await Ye(i,this.opts.paths),Ke.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}),Ke.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):l&&(await ir(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var jf=St(ou(),1);import{lstat as Hc,mkdir as qc,readFile as Uf,readdir as a_,rm as c_,stat as l_,writeFile as Gc}from"node:fs/promises";import{dirname as d_,join as Pt,normalize as u_,relative as Kc,resolve as jc,sep as Hf}from"node:path";import{Readable as qf}from"node:stream";import{pipeline as Gf}from"node:stream/promises";import nm from"events";import Xe from"fs";import{EventEmitter as Ic}from"node:events";import Hu from"node:stream";import{StringDecoder as rm}from"node:string_decoder";import ju from"node:path";import gr from"node:fs";import{dirname as gm,parse as mm}from"path";import{EventEmitter as Im}from"events";import oc from"assert";import{Buffer as Bn}from"buffer";import*as uu from"zlib";import Am from"zlib";import{posix as lr}from"node:path";import{basename as Qm}from"node:path";import qs from"fs";import Rt from"fs";import wu from"path";import{win32 as dw}from"node:path";import Iu from"path";import of from"node:fs";import Tw from"node:assert";import{randomBytes as af}from"node:crypto";import te from"node:fs";import Oe from"node:path";import cf from"fs";import Ys from"node:fs";import _i from"node:path";import nt from"node:fs";import Lw from"node:fs/promises";import Ws from"node:path";import{join as _f}from"node:path";import et from"node:fs";import bf from"node:path";var em=Object.defineProperty,tm=(t,e)=>{for(var r in e)em(t,r,{get:e[r],enumerable:!0})},au=typeof process=="object"&&process?process:{stdout:null,stderr:null},im=t=>!!t&&typeof t=="object"&&(t instanceof Un||t instanceof Hu||sm(t)||om(t)),sm=t=>!!t&&typeof t=="object"&&t instanceof Ic&&typeof t.pipe=="function"&&t.pipe!==Hu.Writable.prototype.pipe,om=t=>!!t&&typeof t=="object"&&t instanceof Ic&&typeof t.write=="function"&&typeof t.end=="function",Ut=Symbol("EOF"),Ht=Symbol("maybeEmitEnd"),on=Symbol("emittedEnd"),ps=Symbol("emittingEnd"),ni=Symbol("emittedError"),gs=Symbol("closed"),cu=Symbol("read"),ms=Symbol("flush"),lu=Symbol("flushChunk"),xt=Symbol("encoding"),cr=Symbol("decoder"),Ne=Symbol("flowing"),ri=Symbol("paused"),hr=Symbol("resume"),Me=Symbol("buffer"),$e=Symbol("pipes"),Be=Symbol("bufferLength"),Pa=Symbol("bufferPush"),ws=Symbol("bufferShift"),je=Symbol("objectMode"),be=Symbol("destroyed"),Oa=Symbol("error"),La=Symbol("emitData"),du=Symbol("emitEnd"),Na=Symbol("emitEnd2"),At=Symbol("async"),Ma=Symbol("abort"),_s=Symbol("aborted"),ii=Symbol("signal"),Cn=Symbol("dataListeners"),Qe=Symbol("discarded"),si=t=>Promise.resolve().then(t),am=t=>t(),cm=t=>t==="end"||t==="finish"||t==="prefinish",lm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,dm=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),qu=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[hr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},um=class extends qu{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,r){super(t,e,r),this.proxyErrors=i=>this.dest.emit("error",i),t.on("error",this.proxyErrors)}},fm=t=>!!t.objectMode,hm=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Un=class extends Ic{[Ne]=!1;[ri]=!1;[$e]=[];[Me]=[];[je];[xt];[At];[cr];[Ut]=!1;[on]=!1;[ps]=!1;[gs]=!1;[ni]=null;[Be]=0;[be]=!1;[ii];[_s]=!1;[Cn]=0;[Qe]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");fm(e)?(this[je]=!0,this[xt]=null):hm(e)?(this[xt]=e.encoding,this[je]=!1):(this[je]=!1,this[xt]=null),this[At]=!!e.async,this[cr]=this[xt]?new rm(this[xt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Me]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[$e]});let{signal:r}=e;r&&(this[ii]=r,r.aborted?this[Ma]():r.addEventListener("abort",()=>this[Ma]()))}get bufferLength(){return this[Be]}get encoding(){return this[xt]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[je]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[At]}set async(t){this[At]=this[At]||!!t}[Ma](){this[_s]=!0,this.emit("abort",this[ii]?.reason),this.destroy(this[ii]?.reason)}get aborted(){return this[_s]}set aborted(t){}write(t,e,r){if(this[_s])return!1;if(this[Ut])throw new Error("write after end");if(this[be])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof e=="function"&&(r=e,e="utf8"),e||(e="utf8");let i=this[At]?si:am;if(!this[je]&&!Buffer.isBuffer(t)){if(dm(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(lm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[je]?(this[Ne]&&this[Be]!==0&&this[ms](!0),this[Ne]?this.emit("data",t):this[Pa](t),this[Be]!==0&&this.emit("readable"),r&&i(r),this[Ne]):t.length?(typeof t=="string"&&!(e===this[xt]&&!this[cr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[xt]&&(t=this[cr].write(t)),this[Ne]&&this[Be]!==0&&this[ms](!0),this[Ne]?this.emit("data",t):this[Pa](t),this[Be]!==0&&this.emit("readable"),r&&i(r),this[Ne]):(this[Be]!==0&&this.emit("readable"),r&&i(r),this[Ne])}read(t){if(this[be])return null;if(this[Qe]=!1,this[Be]===0||t===0||t&&t>this[Be])return this[Ht](),null;this[je]&&(t=null),this[Me].length>1&&!this[je]&&(this[Me]=[this[xt]?this[Me].join(""):Buffer.concat(this[Me],this[Be])]);let e=this[cu](t||null,this[Me][0]);return this[Ht](),e}[cu](t,e){if(this[je])this[ws]();else{let r=e;t===r.length||t===null?this[ws]():typeof r=="string"?(this[Me][0]=r.slice(t),e=r.slice(0,t),this[Be]-=t):(this[Me][0]=r.subarray(t),e=r.subarray(0,t),this[Be]-=t)}return this.emit("data",e),!this[Me].length&&!this[Ut]&&this.emit("drain"),e}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e="utf8"),t!==void 0&&this.write(t,e),r&&this.once("end",r),this[Ut]=!0,this.writable=!1,(this[Ne]||!this[ri])&&this[Ht](),this}[hr](){this[be]||(!this[Cn]&&!this[$e].length&&(this[Qe]=!0),this[ri]=!1,this[Ne]=!0,this.emit("resume"),this[Me].length?this[ms]():this[Ut]?this[Ht]():this.emit("drain"))}resume(){return this[hr]()}pause(){this[Ne]=!1,this[ri]=!0,this[Qe]=!1}get destroyed(){return this[be]}get flowing(){return this[Ne]}get paused(){return this[ri]}[Pa](t){this[je]?this[Be]+=1:this[Be]+=t.length,this[Me].push(t)}[ws](){return this[je]?this[Be]-=1:this[Be]-=this[Me][0].length,this[Me].shift()}[ms](t=!1){do;while(this[lu](this[ws]())&&this[Me].length);!t&&!this[Me].length&&!this[Ut]&&this.emit("drain")}[lu](t){return this.emit("data",t),this[Ne]}pipe(t,e){if(this[be])return t;this[Qe]=!1;let r=this[on];return e=e||{},t===au.stdout||t===au.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[$e].push(e.proxyErrors?new um(this,t,e):new qu(this,t,e)),this[At]?si(()=>this[hr]()):this[hr]()),t}unpipe(t){let e=this[$e].find(r=>r.dest===t);e&&(this[$e].length===1?(this[Ne]&&this[Cn]===0&&(this[Ne]=!1),this[$e]=[]):this[$e].splice(this[$e].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[Qe]=!1,this[Cn]++,!this[$e].length&&!this[Ne]&&this[hr]();else if(t==="readable"&&this[Be]!==0)super.emit("readable");else if(cm(t)&&this[on])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[ni]){let i=e;this[At]?si(()=>i.call(this,this[ni])):i.call(this,this[ni])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Cn]=this.listeners("data").length,this[Cn]===0&&!this[Qe]&&!this[$e].length&&(this[Ne]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Cn]=0,!this[Qe]&&!this[$e].length&&(this[Ne]=!1)),e}get emittedEnd(){return this[on]}[Ht](){!this[ps]&&!this[on]&&!this[be]&&this[Me].length===0&&this[Ut]&&(this[ps]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[gs]&&this.emit("close"),this[ps]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==be&&this[be])return!1;if(t==="data")return!this[je]&&!r?!1:this[At]?(si(()=>this[La](r)),!0):this[La](r);if(t==="end")return this[du]();if(t==="close"){if(this[gs]=!0,!this[on]&&!this[be])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[ni]=r,super.emit(Oa,r);let o=!this[ii]||this.listeners("error").length?super.emit("error",r):!1;return this[Ht](),o}else if(t==="resume"){let o=super.emit("resume");return this[Ht](),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[Ht](),i}[La](t){for(let r of this[$e])r.dest.write(t)===!1&&this.pause();let e=this[Qe]?!1:super.emit("data",t);return this[Ht](),e}[du](){return this[on]?!1:(this[on]=!0,this.readable=!1,this[At]?(si(()=>this[Na]()),!0):this[Na]())}[Na](){if(this[cr]){let e=this[cr].end();if(e){for(let r of this[$e])r.dest.write(e);this[Qe]||super.emit("data",e)}}for(let e of this[$e])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[je]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[je]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[je])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[xt]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(be,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[Qe]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[Ut])return e();let i,o,c=x=>{this.off("data",l),this.off("end",u),this.off(be,f),e(),o(x)},l=x=>{this.off("error",c),this.off("end",u),this.off(be,f),this.pause(),i({value:x,done:!!this[Ut]})},u=()=>{this.off("error",c),this.off("data",l),this.off(be,f),e(),i({done:!0,value:void 0})},f=()=>c(new Error("stream destroyed"));return new Promise((x,m)=>{o=m,i=x,this.once(be,f),this.once("error",c),this.once("end",u),this.once("data",l)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[Qe]=!1;let t=!1,e=()=>(this.pause(),this.off(Oa,e),this.off(be,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(Oa,e),this.once(be,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[be])return t?this.emit("error",t):this.emit(be),this;this[be]=!0,this[Qe]=!0,this[Me].length=0,this[Be]=0;let e=this;return typeof e.close=="function"&&!this[gs]&&e.close(),t?this.emit("error",t):this.emit(be),this}static get isStream(){return im}},xm=Xe.writev,gn=Symbol("_autoClose"),wt=Symbol("_close"),oi=Symbol("_ended"),oe=Symbol("_fd"),Ba=Symbol("_finished"),Wt=Symbol("_flags"),Fa=Symbol("_flush"),ic=Symbol("_handleChunk"),sc=Symbol("_makeBuf"),mi=Symbol("_mode"),ys=Symbol("_needDrain"),wr=Symbol("_onerror"),_r=Symbol("_onopen"),za=Symbol("_onread"),xr=Symbol("_onwrite"),mn=Symbol("_open"),mt=Symbol("_path"),un=Symbol("_pos"),Tt=Symbol("_queue"),pr=Symbol("_read"),Ua=Symbol("_readSize"),jt=Symbol("_reading"),ai=Symbol("_remain"),Ha=Symbol("_size"),Ds=Symbol("_write"),Rn=Symbol("_writing"),ks=Symbol("_defaultFlag"),Mn=Symbol("_errored"),Ac=class extends Un{[Mn]=!1;[oe];[mt];[Ua];[jt]=!1;[Ha];[ai];[gn];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[Mn]=!1,this[oe]=typeof e.fd=="number"?e.fd:void 0,this[mt]=t,this[Ua]=e.readSize||16*1024*1024,this[jt]=!1,this[Ha]=typeof e.size=="number"?e.size:1/0,this[ai]=this[Ha],this[gn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[oe]=="number"?this[pr]():this[mn]()}get fd(){return this[oe]}get path(){return this[mt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[mn](){Xe.open(this[mt],"r",(t,e)=>this[_r](t,e))}[_r](t,e){t?this[wr](t):(this[oe]=e,this.emit("open",e),this[pr]())}[sc](){return Buffer.allocUnsafe(Math.min(this[Ua],this[ai]))}[pr](){if(!this[jt]){this[jt]=!0;let t=this[sc]();if(t.length===0)return process.nextTick(()=>this[za](null,0,t));Xe.read(this[oe],t,0,t.length,null,(e,r,i)=>this[za](e,r,i))}}[za](t,e,r){this[jt]=!1,t?this[wr](t):this[ic](e,r)&&this[pr]()}[wt](){if(this[gn]&&typeof this[oe]=="number"){let t=this[oe];this[oe]=void 0,Xe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[wr](t){this[jt]=!0,this[wt](),this.emit("error",t)}[ic](t,e){let r=!1;return this[ai]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[ai]<=0)&&(r=!1,this[wt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[oe]=="number"&&this[pr](),!1;case"error":return this[Mn]?!1:(this[Mn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},pm=class extends Ac{[mn](){let t=!0;try{this[_r](null,Xe.openSync(this[mt],"r")),t=!1}finally{t&&this[wt]()}}[pr](){let t=!0;try{if(!this[jt]){this[jt]=!0;do{let e=this[sc](),r=e.length===0?0:Xe.readSync(this[oe],e,0,e.length,null);if(!this[ic](r,e))break}while(!0);this[jt]=!1}t=!1}finally{t&&this[wt]()}}[wt](){if(this[gn]&&typeof this[oe]=="number"){let t=this[oe];this[oe]=void 0,Xe.closeSync(t),this.emit("close")}}},Ks=class extends nm{readable=!1;writable=!0;[Mn]=!1;[Rn]=!1;[oi]=!1;[Tt]=[];[ys]=!1;[mt];[mi];[gn];[oe];[ks];[Wt];[Ba]=!1;[un];constructor(t,e){e=e||{},super(e),this[mt]=t,this[oe]=typeof e.fd=="number"?e.fd:void 0,this[mi]=e.mode===void 0?438:e.mode,this[un]=typeof e.start=="number"?e.start:void 0,this[gn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[un]!==void 0?"r+":"w";this[ks]=e.flags===void 0,this[Wt]=e.flags===void 0?r:e.flags,this[oe]===void 0&&this[mn]()}emit(t,...e){if(t==="error"){if(this[Mn])return!1;this[Mn]=!0}return super.emit(t,...e)}get fd(){return this[oe]}get path(){return this[mt]}[wr](t){this[wt](),this[Rn]=!0,this.emit("error",t)}[mn](){Xe.open(this[mt],this[Wt],this[mi],(t,e)=>this[_r](t,e))}[_r](t,e){this[ks]&&this[Wt]==="r+"&&t&&t.code==="ENOENT"?(this[Wt]="w",this[mn]()):t?this[wr](t):(this[oe]=e,this.emit("open",e),this[Rn]||this[Fa]())}end(t,e){return t&&this.write(t,e),this[oi]=!0,!this[Rn]&&!this[Tt].length&&typeof this[oe]=="number"&&this[xr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[oi]?(this.emit("error",new Error("write() after end()")),!1):this[oe]===void 0||this[Rn]||this[Tt].length?(this[Tt].push(t),this[ys]=!0,!1):(this[Rn]=!0,this[Ds](t),!0)}[Ds](t){Xe.write(this[oe],t,0,t.length,this[un],(e,r)=>this[xr](e,r))}[xr](t,e){t?this[wr](t):(this[un]!==void 0&&typeof e=="number"&&(this[un]+=e),this[Tt].length?this[Fa]():(this[Rn]=!1,this[oi]&&!this[Ba]?(this[Ba]=!0,this[wt](),this.emit("finish")):this[ys]&&(this[ys]=!1,this.emit("drain"))))}[Fa](){if(this[Tt].length===0)this[oi]&&this[xr](null,0);else if(this[Tt].length===1)this[Ds](this[Tt].pop());else{let t=this[Tt];this[Tt]=[],xm(this[oe],t,this[un],(e,r)=>this[xr](e,r))}}[wt](){if(this[gn]&&typeof this[oe]=="number"){let t=this[oe];this[oe]=void 0,Xe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Gu=class extends Ks{[mn](){let t;if(this[ks]&&this[Wt]==="r+")try{t=Xe.openSync(this[mt],this[Wt],this[mi])}catch(e){if(e?.code==="ENOENT")return this[Wt]="w",this[mn]();throw e}else t=Xe.openSync(this[mt],this[Wt],this[mi]);this[_r](null,t)}[wt](){if(this[gn]&&typeof this[oe]=="number"){let t=this[oe];this[oe]=void 0,Xe.closeSync(t),this.emit("close")}}[Ds](t){let e=!0;try{this[xr](null,Xe.writeSync(this[oe],t,0,t.length,this[un])),e=!1}finally{if(e)try{this[wt]()}catch{}}}},wm=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"]]),_m=t=>!!t.sync&&!!t.file,ym=t=>!t.sync&&!!t.file,Em=t=>!!t.sync&&!t.file,bm=t=>!t.sync&&!t.file,vm=t=>!!t.file,Sm=t=>wm.get(t)||t,Tc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=Sm(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ai=(t,e,r,i,o)=>Object.assign((c=[],l,u)=>{Array.isArray(c)&&(l=c,c={}),typeof l=="function"&&(u=l,l=void 0),l=l?Array.from(l):[];let f=Tc(c);if(o?.(f,l),_m(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(f,l)}else if(ym(f)){let x=e(f,l);return u?x.then(()=>u(),u):x}else if(Em(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(f,l)}else if(bm(f)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(f,l)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),Tm=Am.constants||{ZLIB_VERNUM:4736},kt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},Tm)),Cm=Bn.concat,fu=Object.getOwnPropertyDescriptor(Bn,"concat"),Rm=t=>t,qa=fu?.writable===!0||fu?.set!==void 0?t=>{Bn.concat=t?Rm:Cm}:t=>{},Fn=Symbol("_superWrite"),Es=class extends Error{code;errno;constructor(t,e){super("zlib: "+t.message,{cause:t}),this.code=t.code,this.errno=t.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+t.message,Error.captureStackTrace(this,e??this.constructor)}get name(){return"ZlibError"}},Ga=Symbol("flushFlag"),Cc=class extends Un{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof uu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new uu[e](t)}catch(r){throw new Es(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 Es(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return oc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Bn.alloc(0),{[Ga]:t})))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(r)}get ended(){return this.#n}[Fn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Bn.from(t,e)),this.#e)return;oc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},qa(!0);let l;try{let f=typeof t[Ga]=="number"?t[Ga]:this.#r;l=this.#t._processChunk(t,f),qa(!1)}catch(f){qa(!1),this.#o(new Es(f,this.write))}finally{this.#t&&(this.#t._handle=i,i.close=o,this.#t.close=c,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",f=>this.#o(new Es(f,this.write)));let u;if(l)if(Array.isArray(l)&&l.length>0){let f=l[0];u=this[Fn](Bn.from(f));for(let x=1;x<l.length;x++)u=this[Fn](l[x])}else u=this[Fn](Bn.from(l));return r&&r(),u}},Wu=class extends Cc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||kt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||kt.Z_FINISH,t.fullFlushFlag=kt.Z_FULL_FLUSH,super(t,e),this.#e=t.level,this.#n=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==t||this.#n!==e){this.flush(kt.Z_SYNC_FLUSH),oc(this.handle,"zlib binding closed");let r=this.handle.flush;this.handle.flush=(i,o)=>{typeof i=="function"&&(o=i,i=this.flushFlag),this.flush(i),o?.()};try{this.handle.params(t,e)}finally{this.handle.flush=r}this.handle&&(this.#e=t,this.#n=e)}}}},Dm=class extends Wu{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Fn](t){return this.#e?(this.#e=!1,t[9]=255,super[Fn](t)):super[Fn](t)}},km=class extends Wu{constructor(t){super(t,"Unzip")}},Ku=class extends Cc{constructor(t,e){t=t||{},t.flush=t.flush||kt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||kt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=kt.BROTLI_OPERATION_FLUSH,super(t,e)}},Pm=class extends Ku{constructor(t){super(t,"BrotliCompress")}},Om=class extends Ku{constructor(t){super(t,"BrotliDecompress")}},$u=class extends Cc{constructor(t,e){t=t||{},t.flush=t.flush||kt.ZSTD_e_continue,t.finishFlush=t.finishFlush||kt.ZSTD_e_end,t.fullFlushFlag=kt.ZSTD_e_flush,super(t,e)}},Lm=class extends $u{constructor(t){super(t,"ZstdCompress")}},Nm=class extends $u{constructor(t){super(t,"ZstdDecompress")}},Mm=(t,e)=>{if(Number.isSafeInteger(t))t<0?Fm(t,e):Bm(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Bm=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},Fm=(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]=Vu(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Ju(o))}},zm=t=>{let e=t[0],r=e===128?Hm(t.subarray(1,t.length)):e===255?Um(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},Um=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),l;i?l=Vu(c):c===0?l=c:(i=!0,l=Ju(c)),l!==0&&(r-=l*Math.pow(256,e-o-1))}return r},Hm=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},Vu=t=>(255^t)&255,Ju=t=>(255^t)+1&255,qm={};tm(qm,{code:()=>Rc,isCode:()=>Ps,isName:()=>Gm,name:()=>$s});var Ps=t=>$s.has(t),Gm=t=>Rc.has(t),$s=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),Rc=new Map(Array.from($s).map(t=>[t[1],t[0]])),zn=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??Dn(t,e,100),this.mode=r?.mode??i?.mode??fn(t,e+100,8),this.uid=r?.uid??i?.uid??fn(t,e+108,8),this.gid=r?.gid??i?.gid??fn(t,e+116,8),this.size=r?.size??i?.size??fn(t,e+124,12),this.mtime=r?.mtime??i?.mtime??ja(t,e+136,12),this.cksum=fn(t,e+148,12),i&&this.#n(i,!0),r&&this.#n(r);let o=Dn(t,e+156,1);if(Ps(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Dn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=r?.uname??i?.uname??Dn(t,e+265,32),this.gname=r?.gname??i?.gname??Dn(t,e+297,32),this.devmaj=r?.devmaj??i?.devmaj??fn(t,e+329,8)??0,this.devmin=r?.devmin??i?.devmin??fn(t,e+337,8)??0,t[e+475]!==0){let l=Dn(t,e+345,155);this.path=l+"/"+this.path}else{let l=Dn(t,e+345,130);l&&(this.path=l+"/"+this.path),this.atime=r?.atime??i?.atime??ja(t,e+476,12),this.ctime=r?.ctime??i?.ctime??ja(t,e+488,12)}let c=256;for(let l=e;l<e+148;l++)c+=t[l];for(let l=e+156;l<e+512;l++)c+=t[l];this.cksumValid=c===this.cksum,this.cksum===void 0&&c===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e||r==="linkpath"&&e||r==="global"))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let r=this.ctime||this.atime?130:155,i=jm(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=kn(t,e,100,o)||this.needPax,this.needPax=hn(t,e+100,8,this.mode)||this.needPax,this.needPax=hn(t,e+108,8,this.uid)||this.needPax,this.needPax=hn(t,e+116,8,this.gid)||this.needPax,this.needPax=hn(t,e+124,12,this.size)||this.needPax,this.needPax=Wa(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=kn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=kn(t,e+265,32,this.uname)||this.needPax,this.needPax=kn(t,e+297,32,this.gname)||this.needPax,this.needPax=hn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=hn(t,e+337,8,this.devmin)||this.needPax,this.needPax=kn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=kn(t,e+345,155,c)||this.needPax:(this.needPax=kn(t,e+345,130,c)||this.needPax,this.needPax=Wa(t,e+476,12,this.atime)||this.needPax,this.needPax=Wa(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,hn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:$s.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Rc.get(t));if(Ps(e)||e==="Unsupported")this.#e=e;else if(Ps(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},jm=(t,e)=>{let r=t,i="",o,c=lr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=lr.dirname(r),r=lr.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=lr.join(lr.basename(i),r),i=lr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Dn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),ja=(t,e,r)=>Wm(fn(t,e,r)),Wm=t=>t===void 0?void 0:new Date(t*1e3),fn=(t,e,r)=>Number(t[e])&128?zm(t.subarray(e,e+r)):$m(t,e,r),Km=t=>isNaN(t)?void 0:t,$m=(t,e,r)=>Km(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),Vm={12:8589934591,8:2097151},hn=(t,e,r,i)=>i===void 0?!1:i>Vm[r]||i<0?(Mm(i,t.subarray(e,e+r)),!0):(Jm(t,e,r,i),!1),Jm=(t,e,r,i)=>t.write(Zm(i,r),e,r,"ascii"),Zm=(t,e)=>Ym(Math.floor(t).toString(8),e),Ym=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Wa=(t,e,r,i)=>i===void 0?!1:hn(t,e,r,i.getTime()/1e3),Xm=new Array(156).join("\0"),kn=(t,e,r,i)=>i===void 0?!1:(t.write(i+Xm,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),Hs=class Zu{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,r=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=r,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return Buffer.allocUnsafe(0);let r=Buffer.byteLength(e),i=512*Math.ceil(1+r/512),o=Buffer.allocUnsafe(i);for(let c=0;c<512;c++)o[c]=0;new zn({path:("PaxHeader/"+Qm(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:r,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(o),o.write(e,512,r,"utf8");for(let c=r+512;c<o.length;c++)o[c]=0;return o}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let r=this[e],i=r instanceof Date?r.getTime()/1e3:r,o=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+i+`
90
- `,c=Buffer.byteLength(o),l=Math.floor(Math.log(c)/Math.log(10))+1;return c+l>=Math.pow(10,l)&&(l+=1),l+c+o}static parse(e,r,i=!1){return new Zu(ew(tw(e),r),i)}},ew=(t,e)=>e?Object.assign({},e,t):t,tw=t=>t.replace(/\n$/,"").split(`
91
- `).reduce(nw,Object.create(null)),nw=(t,e)=>{let r=parseInt(e,10);if(r!==Buffer.byteLength(e)+1)return t;e=e.slice((r+" ").length);let i=e.split("="),o=i.shift();if(!o)return t;let c=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),l=i.join("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(l)*1e3):/^[0-9]+$/.test(l)?+l:l,t},rw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Z=rw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),Yu=class extends Un{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,r){switch(super({}),this.pause(),this.extended=e,this.globalExtended=r,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=Z(t.path),this.mode=t.mode,this.mode&&(this.mode=this.mode&4095),this.uid=t.uid,this.gid=t.gid,this.uname=t.uname,this.gname=t.gname,this.size=this.remain,this.mtime=t.mtime,this.atime=t.atime,this.ctime=t.ctime,this.linkpath=t.linkpath?Z(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#e(e),r&&this.#e(r,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let r=this.remain,i=this.blockRemain;return this.remain=Math.max(0,r-e),this.blockRemain=Math.max(0,i-e),this.ignore?!0:r>=e?super.write(t):super.write(t.subarray(0,r))}#e(t,e=!1){t.path&&(t.path=Z(t.path)),t.linkpath&&(t.linkpath=Z(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},Vs=(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))},iw=1024*1024,ac=Buffer.from([31,139]),cc=Buffer.from([40,181,47,253]),sw=Math.max(ac.length,cc.length),st=Symbol("state"),Pn=Symbol("writeEntry"),qt=Symbol("readEntry"),Ka=Symbol("nextEntry"),hu=Symbol("processEntry"),Ct=Symbol("extendedHeader"),ci=Symbol("globalExtendedHeader"),an=Symbol("meta"),xu=Symbol("emitMeta"),fe=Symbol("buffer"),Gt=Symbol("queue"),cn=Symbol("ended"),$a=Symbol("emittedEnd"),On=Symbol("emit"),Te=Symbol("unzip"),bs=Symbol("consumeChunk"),vs=Symbol("consumeChunkSub"),Va=Symbol("consumeBody"),pu=Symbol("consumeMeta"),gu=Symbol("consumeHeader"),li=Symbol("consuming"),Ja=Symbol("bufferConcat"),Ss=Symbol("maybeEnd"),dr=Symbol("writing"),ln=Symbol("aborted"),Is=Symbol("onDone"),Ln=Symbol("sawValidEntry"),As=Symbol("sawNullBlock"),Ts=Symbol("sawEOF"),mu=Symbol("closeStream"),ow=()=>!0,Ii=class extends Im{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Gt]=[];[fe];[qt];[Pn];[st]="begin";[an]="";[Ct];[ci];[cn]=!1;[Te];[ln]=!1;[Ln];[As]=!1;[Ts]=!1;[dr]=!1;[li]=!1;[$a]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Is,()=>{(this[st]==="begin"||this[Ln]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Is,t.ondone):this.on(Is,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||iw,this.filter=typeof t.filter=="function"?t.filter:ow;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[mu]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){Vs(this,t,e,r)}[gu](t,e){this[Ln]===void 0&&(this[Ln]=!1);let r;try{r=new zn(t,e,this[Ct],this[ci])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[As]?(this[Ts]=!0,this[st]==="begin"&&(this[st]="header"),this[On]("eof")):(this[As]=!0,this[On]("nullBlock"));else if(this[As]=!1,!r.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:r});else if(!r.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:r});else{let i=r.type;if(/^(Symbolic)?Link$/.test(i)&&!r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:r});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:r});else{let o=this[Pn]=new Yu(r,this[Ct],this[ci]);if(!this[Ln])if(o.remain){let c=()=>{o.invalid||(this[Ln]=!0)};o.on("end",c)}else this[Ln]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[On]("ignoredEntry",o),this[st]="ignore",o.resume()):o.size>0&&(this[an]="",o.on("data",c=>this[an]+=c),this[st]="meta"):(this[Ct]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[On]("ignoredEntry",o),this[st]=o.remain?"ignore":"header",o.resume()):(o.remain?this[st]="body":(this[st]="header",o.end()),this[qt]?this[Gt].push(o):(this[Gt].push(o),this[Ka]())))}}}[mu](){queueMicrotask(()=>this.emit("close"))}[hu](t){let e=!0;if(!t)this[qt]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[qt]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Ka]()),e=!1);return e}[Ka](){do;while(this[hu](this[Gt].shift()));if(this[Gt].length===0){let t=this[qt];!t||t.flowing||t.size===t.remain?this[dr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Va](t,e){let r=this[Pn];if(!r)throw new Error("attempt to consume body without entry??");let i=r.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return r.write(o),r.blockRemain||(this[st]="header",this[Pn]=void 0,r.end()),o.length}[pu](t,e){let r=this[Pn],i=this[Va](t,e);return!this[Pn]&&r&&this[xu](r),i}[On](t,e,r){this[Gt].length===0&&!this[qt]?this.emit(t,e,r):this[Gt].push([t,e,r])}[xu](t){switch(this[On]("meta",this[an]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Ct]=Hs.parse(this[an],this[Ct],!1);break;case"GlobalExtendedHeader":this[ci]=Hs.parse(this[an],this[ci],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Ct]??Object.create(null);this[Ct]=e,e.path=this[an].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Ct]||Object.create(null);this[Ct]=e,e.linkpath=this[an].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[ln]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[ln])return r?.(),!1;if((this[Te]===void 0||this.brotli===void 0&&this[Te]===!1)&&t){if(this[fe]&&(t=Buffer.concat([this[fe],t]),this[fe]=void 0),t.length<sw)return this[fe]=t,r?.(),!0;for(let l=0;this[Te]===void 0&&l<ac.length;l++)t[l]!==ac[l]&&(this[Te]=!1);let o=!1;if(this[Te]===!1&&this.zstd!==!1){o=!0;for(let l=0;l<cc.length;l++)if(t[l]!==cc[l]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Te]===!1&&c)if(t.length<512)if(this[cn])this.brotli=!0;else return this[fe]=t,r?.(),!0;else try{new zn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Te]===void 0||this[Te]===!1&&(this.brotli||o)){let l=this[cn];this[cn]=!1,this[Te]=this[Te]===void 0?new km({}):o?new Nm({}):new Om({}),this[Te].on("data",f=>this[bs](f)),this[Te].on("error",f=>this.abort(f)),this[Te].on("end",()=>{this[cn]=!0,this[bs]()}),this[dr]=!0;let u=!!this[Te][l?"end":"write"](t);return this[dr]=!1,r?.(),u}}this[dr]=!0,this[Te]?this[Te].write(t):this[bs](t),this[dr]=!1;let i=this[Gt].length>0?!1:this[qt]?this[qt].flowing:!0;return!i&&this[Gt].length===0&&this[qt]?.once("drain",()=>this.emit("drain")),r?.(),i}[Ja](t){t&&!this[ln]&&(this[fe]=this[fe]?Buffer.concat([this[fe],t]):t)}[Ss](){if(this[cn]&&!this[$a]&&!this[ln]&&!this[li]){this[$a]=!0;let t=this[Pn];if(t&&t.blockRemain){let e=this[fe]?this[fe].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[fe]&&t.write(this[fe]),t.end()}this[On](Is)}}[bs](t){if(this[li]&&t)this[Ja](t);else if(!t&&!this[fe])this[Ss]();else if(t){if(this[li]=!0,this[fe]){this[Ja](t);let e=this[fe];this[fe]=void 0,this[vs](e)}else this[vs](t);for(;this[fe]&&this[fe]?.length>=512&&!this[ln]&&!this[Ts];){let e=this[fe];this[fe]=void 0,this[vs](e)}this[li]=!1}(!this[fe]||this[cn])&&this[Ss]()}[vs](t){let e=0,r=t.length;for(;e+512<=r&&!this[ln]&&!this[Ts];)switch(this[st]){case"begin":case"header":this[gu](t,e),e+=512;break;case"ignore":case"body":e+=this[Va](t,e);break;case"meta":e+=this[pu](t,e);break;default:throw new Error("invalid state: "+this[st])}e<r&&(this[fe]=this[fe]?Buffer.concat([t.subarray(e),this[fe]]):t.subarray(e))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),r&&this.once("finish",r),this[ln]||(this[Te]?(t&&this[Te].write(t),this[Te].end()):(this[cn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Ss]())),this}},wi=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)},aw=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},Xu=(t,e)=>{let r=new Map(e.map(c=>[wi(c),!0])),i=t.filter,o=(c,l="")=>{let u=l||mm(c).root||".",f;if(c===u)f=!1;else{let x=r.get(c);f=x!==void 0?x:o(gm(c),u)}return r.set(c,f),f};t.filter=i?(c,l)=>i(c,l)&&o(wi(c)):c=>o(wi(c))},cw=t=>{let e=new Ii(t),r=t.file,i;try{i=gr.openSync(r,"r");let o=gr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let l=Buffer.allocUnsafe(o.size),u=gr.readSync(i,l,0,o.size,0);e.end(u===l.byteLength?l:l.subarray(0,u))}else{let l=0,u=Buffer.allocUnsafe(c);for(;l<o.size;){let f=gr.readSync(i,u,0,c,l);if(f===0)break;l+=f,e.write(u.subarray(0,f))}e.end()}}finally{if(typeof i=="number")try{gr.closeSync(i)}catch{}}},lw=(t,e)=>{let r=new Ii(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("end",c),gr.stat(o,(u,f)=>{if(u)l(u);else{let x=new Ac(o,{readSize:i,size:f.size});x.on("error",l),x.pipe(r)}})})},yr=Ai(cw,lw,t=>new Ii(t),t=>new Ii(t),(t,e)=>{e?.length&&Xu(t,e),t.noResume||aw(t)}),Qu=(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:uw,parse:_u}=dw,Dc=t=>{let e="",r=_u(t);for(;uw(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=_u(t)}return[e,t]},Js=["|","<",">","?",":"],kc=Js.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),fw=new Map(Js.map((t,e)=>[t,kc[e]])),hw=new Map(kc.map((t,e)=>[t,Js[e]])),yu=t=>Js.reduce((e,r)=>e.split(r).join(fw.get(r)),t),xw=t=>kc.reduce((e,r)=>e.split(r).join(hw.get(r)),t),ef=(t,e)=>e?(t=Z(t).replace(/^\.(\/|$)/,""),wi(e)+"/"+t):Z(t),pw=16*1024*1024,Eu=Symbol("process"),bu=Symbol("file"),vu=Symbol("directory"),lc=Symbol("symlink"),Su=Symbol("hardlink"),di=Symbol("header"),Os=Symbol("read"),dc=Symbol("lstat"),Ls=Symbol("onlstat"),uc=Symbol("onread"),fc=Symbol("onreadlink"),hc=Symbol("openfile"),xc=Symbol("onopenfile"),xn=Symbol("close"),Gs=Symbol("mode"),pc=Symbol("awaitDrain"),Za=Symbol("ondrain"),Dt=Symbol("prefix"),tf=class extends Un{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let r=Tc(e);super(),this.path=Z(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||pw,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=Z(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?Z(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,l]=Dc(this.path);c&&typeof l=="string"&&(this.path=l,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=xw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=Z(r.absolute||wu.resolve(this.cwd,t)),this.path===""&&(this.path="./"),i&&this.warn("TAR_ENTRY_INFO",`stripping ${i} from absolute path`,{entry:this,path:i+this.path});let o=this.statCache.get(this.absolute);o?this[Ls](o):this[dc]()}warn(t,e,r={}){return Vs(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[dc](){Rt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Ls](e)})}[Ls](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=ww(t),this.emit("stat",t),this[Eu]()}[Eu](){switch(this.type){case"File":return this[bu]();case"Directory":return this[vu]();case"SymbolicLink":return this[lc]();default:return this.end()}}[Gs](t){return Qu(t,this.type==="Directory",this.portable)}[Dt](t){return ef(t,this.prefix)}[di](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new zn({path:this[Dt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Dt](this.linkpath):this.linkpath,mode:this[Gs](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 Hs({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)}[vu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[di](),this.end()}[lc](){Rt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[fc](e)})}[fc](t){this.linkpath=Z(t),this[di](),this.end()}[Su](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=Z(wu.relative(this.cwd,t)),this.stat.size=0,this[di](),this.end()}[bu](){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[Su](e);this.linkCache.set(t,this.absolute)}if(this[di](),this.stat.size===0)return this.end();this[hc]()}[hc](){Rt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[xc](e)})}[xc](t){if(this.fd=t,this.#e)return this[xn]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[Os]()}[Os](){let{fd:t,buf:e,offset:r,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");Rt.read(t,e,r,i,o,(c,l)=>{if(c)return this[xn](()=>this.emit("error",c));this[uc](l)})}[xn](t=()=>{}){this.fd!==void 0&&Rt.close(this.fd,t)}[uc](t){if(t<=0&&this.remain>0){let r=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[xn](()=>this.emit("error",r))}if(t>this.remain){let r=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[xn](()=>this.emit("error",r))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let r=t;r<this.length&&t<this.blockRemain;r++)this.buf[r+this.offset]=0,t++,this.remain++;let e=this.offset===0&&t===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+t);this.write(e)?this[Za]():this[pc](()=>this[Za]())}[pc](t){this.once("drain",t)}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this.blockRemain<t.length){let i=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",i)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,r)}[Za](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[xn](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[Os]()}},gw=class extends tf{sync=!0;[dc](){this[Ls](Rt.lstatSync(this.absolute))}[lc](){this[fc](Rt.readlinkSync(this.absolute))}[hc](){this[xc](Rt.openSync(this.absolute,"r"))}[Os](){let t=!0;try{let{fd:e,buf:r,offset:i,length:o,pos:c}=this;if(e===void 0||r===void 0)throw new Error("fd and buf must be set in READ method");let l=Rt.readSync(e,r,i,o,c);this[uc](l),t=!1}finally{if(t)try{this[xn](()=>{})}catch{}}}[pc](t){t()}[xn](t=()=>{}){this.fd!==void 0&&Rt.closeSync(this.fd),t()}},mw=class extends Un{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,r={}){return Vs(this,t,e,r)}constructor(t,e={}){let r=Tc(e);super(),this.preservePaths=!!r.preservePaths,this.portable=!!r.portable,this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.onWriteEntry=r.onWriteEntry,this.readEntry=t;let{type:i}=t;if(i==="Unsupported")throw new Error("writing entry that should be ignored");this.type=i,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=r.prefix,this.path=Z(t.path),this.mode=t.mode!==void 0?this[Gs](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?Z(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[l,u]=Dc(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 zn({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 Hs({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 ef(t,this.prefix)}[Gs](t){return Qu(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}},ww=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",_w=class mr{tail;head;length=0;static create(e=[]){return new mr(e)}constructor(e=[]){for(let r of e)this.push(r)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let r=e.next,i=e.prev;return r&&(r.prev=i),i&&(i.next=r),e===this.head&&(this.head=r),e===this.tail&&(this.tail=i),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,r}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let r=this.head;e.list=this,e.next=r,r&&(r.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let r=this.tail;e.list=this,e.prev=r,r&&(r.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let r=0,i=e.length;r<i;r++)Ew(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)bw(this,e[r]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,r=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,r.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,r=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,r.list=void 0,this.length--,e}forEach(e,r){r=r||this;for(let i=this.head,o=0;i;o++)e.call(r,i.value,o,this),i=i.next}forEachReverse(e,r){r=r||this;for(let i=this.tail,o=this.length-1;i;o--)e.call(r,i.value,o,this),i=i.prev}get(e){let r=0,i=this.head;for(;i&&r<e;r++)i=i.next;if(r===e&&i)return i.value}getReverse(e){let r=0,i=this.tail;for(;i&&r<e;r++)i=i.prev;if(r===e&&i)return i.value}map(e,r){r=r||this;let i=new mr;for(let o=this.head;o;)i.push(e.call(r,o.value,this)),o=o.next;return i}mapReverse(e,r){r=r||this;var i=new mr;for(let o=this.tail;o;)i.push(e.call(r,o.value,this)),o=o.prev;return i}reduce(e,r){let i,o=this.head;if(arguments.length>1)i=r;else if(this.head)o=this.head.next,i=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var c=0;o;c++)i=e(i,o.value,c),o=o.next;return i}reduceReverse(e,r){let i,o=this.tail;if(arguments.length>1)i=r;else if(this.tail)o=this.tail.prev,i=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let c=this.length-1;o;c--)i=e(i,o.value,c),o=o.prev;return i}toArray(){let e=new Array(this.length);for(let r=0,i=this.head;i;r++)e[r]=i.value,i=i.next;return e}toArrayReverse(){let e=new Array(this.length);for(let r=0,i=this.tail;i;r++)e[r]=i.value,i=i.prev;return e}slice(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new mr;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.head,c=0;for(c=0;o&&c<e;c++)o=o.next;for(;o&&c<r;c++,o=o.next)i.push(o.value);return i}sliceReverse(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new mr;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.length,c=this.tail;for(;c&&o>r;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,r=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let l=0;o&&l<e;l++)o=o.next;let c=[];for(let l=0;o&&l<r;l++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let l of i)o=yw(this,o,l);return c}reverse(){let e=this.head,r=this.tail;for(let i=e;i;i=i.prev){let o=i.prev;i.prev=i.next,i.next=o}return this.head=r,this.tail=e,this}};function yw(t,e,r){let i=e,o=e?e.next:t.head,c=new Pc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function Ew(t,e){t.tail=new Pc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function bw(t,e){t.head=new Pc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Pc=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}},Au=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Tu=Buffer.alloc(1024),Ns=Symbol("onStat"),ui=Symbol("ended"),pt=Symbol("queue"),fi=Symbol("queue"),dn=Symbol("current"),Nn=Symbol("process"),hi=Symbol("processing"),Cs=Symbol("processJob"),gt=Symbol("jobs"),Ya=Symbol("jobDone"),Ms=Symbol("addFSEntry"),Cu=Symbol("addTarEntry"),gc=Symbol("stat"),mc=Symbol("readdir"),Bs=Symbol("onreaddir"),Fs=Symbol("pipe"),Ru=Symbol("entry"),Xa=Symbol("entryOpt"),zs=Symbol("writeEntryClass"),nf=Symbol("write"),Qa=Symbol("ondrain"),Zs=class extends Un{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[zs];onWriteEntry;[pt];[fi]=new Map;[gt]=0;[hi]=!1;[ui]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=Z(t.prefix||""),this.linkCache=t.linkCache||new Map,this.statCache=t.statCache||new Map,this.readdirCache=t.readdirCache||new Map,this.onWriteEntry=t.onWriteEntry,this[zs]=tf,typeof t.onwarn=="function"&&this.on("warn",t.onwarn),this.portable=!!t.portable,t.gzip||t.brotli||t.zstd){if((t.gzip?1:0)+(t.brotli?1:0)+(t.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(t.gzip&&(typeof t.gzip!="object"&&(t.gzip={}),this.portable&&(t.gzip.portable=!0),this.zip=new Dm(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new Pm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new Lm(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[Qa]()),this.on("resume",()=>e.resume())}else this.on("drain",this[Qa]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[pt]=new _w,this[gt]=0,this.jobs=Number(t.jobs)||4,this[hi]=!1,this[ui]=!1}[nf](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&this.add(t),this[ui]=!0,this[Nn](),r&&r(),this}write(t){if(this[ui])throw new Error("write after end");return t instanceof Yu?this[Cu](t):this[Ms](t),this.flowing}[Cu](t){let e=Z(Iu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Au(t.path,e);r.entry=new mw(t,this[Xa](r)),r.entry.on("end",()=>this[Ya](r)),this[gt]+=1,this[pt].push(r)}this[Nn]()}[Ms](t){let e=Z(Iu.resolve(this.cwd,t));this[pt].push(new Au(t,e)),this[Nn]()}[gc](t){t.pending=!0,this[gt]+=1;let e=this.follow?"stat":"lstat";qs[e](t.absolute,(r,i)=>{t.pending=!1,this[gt]-=1,r?this.emit("error",r):this[Ns](t,i)})}[Ns](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[dn])this[Cs](t);else{let r=`${e.dev}:${e.ino}`,i=this[fi].get(r);i?i.push(t):this[fi].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Nn]()}[mc](t){t.pending=!0,this[gt]+=1,qs.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[gt]-=1,e)return this.emit("error",e);this[Bs](t,r)})}[Bs](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Nn]()}[Nn](){if(!this[hi]){this[hi]=!0;for(let t=this[pt].head;t&&this[gt]<this.jobs;t=t.next)if(this[Cs](t.value),t.value.ignore){let e=t.next;this[pt].removeNode(t),t.next=e}this[hi]=!1,this[ui]&&this[pt].length===0&&this[gt]===0&&(this.zip?this.zip.end(Tu):(super.write(Tu),super.end()))}}get[dn](){return this[pt]&&this[pt].head&&this[pt].head.value}[Ya](t){this[pt].shift(),this[gt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[fi].get(r);if(i){this[fi].delete(r);for(let o of i)o.pending=!1,this[Cs](o)}}this[Nn]()}[Cs](t){if(t.pending&&t.pendingLink&&t===this[dn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[dn]&&!t.piped&&this[Fs](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Ns](t,e):this[gc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[Bs](t,e):this[mc](t),!t.readdir)return}if(t.entry=this[Ru](t),!t.entry){t.ignore=!0;return}t===this[dn]&&!t.piped&&this[Fs](t)}}}[Xa](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}}[Ru](t){this[gt]+=1;try{return new this[zs](t.path,this[Xa](t)).on("end",()=>this[Ya](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[Qa](){this[dn]&&this[dn].entry&&this[dn].entry.resume()}[Fs](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ms](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={}){Vs(this,t,e,r)}},Oc=class extends Zs{sync=!0;constructor(t){super(t),this[zs]=gw}pause(){}resume(){}[gc](t){let e=this.follow?"statSync":"lstatSync";this[Ns](t,qs[e](t.absolute))}[mc](t){this[Bs](t,qs.readdirSync(t.absolute))}[Fs](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ms](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[nf](i)})}},vw=(t,e)=>{let r=new Oc(t),i=new Gu(t.file,{mode:t.mode||438});r.pipe(i),rf(r,e)},Sw=(t,e)=>{let r=new Zs(t),i=new Ks(t.file,{mode:t.mode||438});r.pipe(i);let o=new Promise((c,l)=>{i.on("error",l),i.on("close",c),r.on("error",l)});return sf(r,e).catch(c=>r.emit("error",c)),o},rf=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?yr({file:ju.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},sf=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await yr({file:ju.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},Iw=(t,e)=>{let r=new Oc(t);return rf(r,e),r},Aw=(t,e)=>{let r=new Zs(t);return sf(r,e).catch(i=>r.emit("error",i)),r},K2=Ai(vw,Sw,Iw,Aw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),Cw=process.env.__FAKE_PLATFORM__||process.platform,lf=Cw==="win32",{O_CREAT:df,O_NOFOLLOW:Du,O_TRUNC:uf,O_WRONLY:ff}=cf.constants,hf=Number(process.env.__FAKE_FS_O_FILENAME__)||cf.constants.UV_FS_O_FILEMAP||0,Rw=lf&&!!hf,Dw=512*1024,kw=hf|uf|df|ff,ku=!lf&&typeof Du=="number"?Du|uf|df|ff:null,xf=ku!==null?()=>ku:Rw?t=>t<Dw?kw:"w":()=>"w",wc=(t,e,r)=>{try{return Ys.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},js=(t,e,r,i)=>{Ys.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},Pw=(t,e,r,i,o)=>{if(e.isDirectory())pf(_i.resolve(t,e.name),r,i,c=>{if(c)return o(c);let l=_i.resolve(t,e.name);js(l,r,i,o)});else{let c=_i.resolve(t,e.name);js(c,r,i,o)}},pf=(t,e,r,i)=>{Ys.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 js(t,e,r,i);let l=c.length,u=null,f=x=>{if(!u){if(x)return i(u=x);if(--l===0)return js(t,e,r,i)}};for(let x of c)Pw(t,x,e,r,f)})},Ow=(t,e,r,i)=>{e.isDirectory()&&gf(_i.resolve(t,e.name),r,i),wc(_i.resolve(t,e.name),r,i)},gf=(t,e,r)=>{let i;try{i=Ys.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return wc(t,e,r);throw c}for(let o of i)Ow(t,o,e,r);return wc(t,e,r)},mf=class extends Error{path;code;syscall="chdir";constructor(t,e){super(`${e}: Cannot cd into '${t}'`),this.path=t,this.code=e}get name(){return"CwdError"}},Xs=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(t,e){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=t,this.path=e}get name(){return"SymlinkError"}},Nw=(t,e)=>{nt.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new mf(t,r?.code||"ENOTDIR")),e(r)})},Mw=(t,e,r)=>{t=Z(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,l=e.uid,u=e.gid,f=typeof l=="number"&&typeof u=="number"&&(l!==e.processUid||u!==e.processGid),x=e.preserve,m=e.unlink,w=Z(e.cwd),b=(_,S)=>{_?r(_):S&&f?pf(S,l,u,A=>b(A)):c?nt.chmod(t,o,r):r()};if(t===w)return Nw(t,b);if(x)return Lw.mkdir(t,{mode:o,recursive:!0}).then(_=>b(null,_??void 0),b);let p=Z(Ws.relative(w,t)).split("/");_c(w,p,o,m,w,void 0,b)},_c=(t,e,r,i,o,c,l)=>{if(e.length===0)return l(null,c);let u=e.shift(),f=Z(Ws.resolve(t+"/"+u));nt.mkdir(f,r,wf(f,e,r,i,o,c,l))},wf=(t,e,r,i,o,c,l)=>u=>{u?nt.lstat(t,(f,x)=>{if(f)f.path=f.path&&Z(f.path),l(f);else if(x.isDirectory())_c(t,e,r,i,o,c,l);else if(i)nt.unlink(t,m=>{if(m)return l(m);nt.mkdir(t,r,wf(t,e,r,i,o,c,l))});else{if(x.isSymbolicLink())return l(new Xs(t,t+"/"+e.join("/")));l(u)}}):(c=c||t,_c(t,e,r,i,o,c,l))},Bw=t=>{let e=!1,r;try{e=nt.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new mf(t,r??"ENOTDIR")}},Fw=(t,e)=>{t=Z(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,l=e.gid,u=typeof c=="number"&&typeof l=="number"&&(c!==e.processUid||l!==e.processGid),f=e.preserve,x=e.unlink,m=Z(e.cwd),w=_=>{_&&u&&gf(_,c,l),o&&nt.chmodSync(t,i)};if(t===m)return Bw(m),w();if(f)return w(nt.mkdirSync(t,{mode:i,recursive:!0})??void 0);let b=Z(Ws.relative(m,t)).split("/"),p;for(let _=b.shift(),S=m;_&&(S+="/"+_);_=b.shift()){S=Z(Ws.resolve(S));try{nt.mkdirSync(S,i),p=p||S}catch{let A=nt.lstatSync(S);if(A.isDirectory())continue;if(x){nt.unlinkSync(S),nt.mkdirSync(S,i),p=p||S;continue}else if(A.isSymbolicLink())return new Xs(S,S+"/"+b.join("/"))}}return w(p)},ec=Object.create(null),Pu=1e4,ur=new Set,zw=t=>{ur.has(t)?ur.delete(t):ec[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),ur.add(t);let e=ec[t],r=ur.size-Pu;if(r>Pu/10){for(let i of ur)if(ur.delete(i),delete ec[i],--r<=0)break}return e},Uw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Hw=Uw==="win32",qw=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=_f(i,r)),e.push(r||"/"),e},[]),Gw=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=Hw?["win32 parallelization disabled"]:t.map(i=>wi(_f(zw(i))));let r=new Set(t.map(i=>qw(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let 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 f of u)o.add(f)}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 f=l[0];typeof f=="function"&&o.add(f)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},jw=()=>process.umask(),Ou=Symbol("onEntry"),yc=Symbol("checkFs"),Lu=Symbol("checkFs2"),Ec=Symbol("isReusable"),ot=Symbol("makeFs"),bc=Symbol("file"),vc=Symbol("directory"),Us=Symbol("link"),Nu=Symbol("symlink"),Mu=Symbol("hardlink"),gi=Symbol("ensureNoSymlink"),Bu=Symbol("unsupported"),Fu=Symbol("checkPath"),tc=Symbol("stripAbsolutePath"),pn=Symbol("mkdir"),Fe=Symbol("onError"),Rs=Symbol("pending"),zu=Symbol("pend"),fr=Symbol("unpend"),nc=Symbol("ended"),rc=Symbol("maybeClose"),Sc=Symbol("skip"),yi=Symbol("doChown"),Ei=Symbol("uid"),bi=Symbol("gid"),vi=Symbol("checkedCwd"),Ww=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Si=Ww==="win32",Kw=1024,$w=(t,e)=>{if(!Si)return te.unlink(t,e);let r=t+".DELETE."+af(16).toString("hex");te.rename(t,r,i=>{if(i)return e(i);te.unlink(r,e)})},Vw=t=>{if(!Si)return te.unlinkSync(t);let e=t+".DELETE."+af(16).toString("hex");te.renameSync(t,e),te.unlinkSync(e)},Uu=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Lc=class extends Ii{[nc]=!1;[vi]=!1;[Rs]=0;reservations=new Gw;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[nc]=!0,this[rc]()},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:Kw,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Si,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=Z(Oe.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:jw():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[Ou](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[rc](){this[nc]&&this[Rs]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[tc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Dc(r),l=c.replaceAll(/\\/g,"/").split("/");if(l.includes("..")||Si&&/^[a-z]:\.\.$/i.test(l[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let u=Oe.posix.dirname(t.path),f=Oe.posix.normalize(Oe.posix.join(u,l.join("/")));if(f.startsWith("../")||f==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:r}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:r})),!0}[Fu](t){let e=Z(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=Z(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}r.splice(0,this.strip),t.path=r.join("/")}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[tc](t,"path")||!this[tc](t,"linkpath"))return!1;if(t.absolute=Oe.isAbsolute(t.path)?Z(Oe.resolve(t.path)):Z(Oe.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:Z(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=Oe.win32.parse(String(t.absolute));t.absolute=i+yu(String(t.absolute).slice(i.length));let{root:o}=Oe.win32.parse(t.path);t.path=o+yu(t.path.slice(o.length))}return!0}[Ou](t){if(!this[Fu](t))return t.resume();switch(Tw.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[yc](t);default:return this[Bu](t)}}[Fe](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[fr](),e.resume())}[pn](t,e,r){Mw(Z(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},r)}[yi](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}[Ei](t){return Uu(this.uid,t.uid,this.processUid)}[bi](t){return Uu(this.gid,t.gid,this.processGid)}[bc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Ks(String(t.absolute),{flags:xf(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&te.close(i.fd,()=>{}),i.write=()=>!0,this[Fe](u,t),e()});let o=1,c=u=>{if(u){i.fd&&te.close(i.fd,()=>{}),this[Fe](u,t),e();return}--o===0&&i.fd!==void 0&&te.close(i.fd,f=>{f?this[Fe](f,t):this[fr](),e()})};i.on("finish",()=>{let u=String(t.absolute),f=i.fd;if(typeof f=="number"&&t.mtime&&!this.noMtime){o++;let x=t.atime||new Date,m=t.mtime;te.futimes(f,x,m,w=>w?te.utimes(u,x,m,b=>c(b&&w)):c())}if(typeof f=="number"&&this[yi](t)){o++;let x=this[Ei](t),m=this[bi](t);typeof x=="number"&&typeof m=="number"&&te.fchown(f,x,m,w=>w?te.chown(u,x,m,b=>c(b&&w)):c())}c()});let l=this.transform&&this.transform(t)||t;l!==t&&(l.on("error",u=>{this[Fe](u,t),e()}),t.pipe(l)),l.pipe(i)}[vc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[pn](String(t.absolute),r,i=>{if(i){this[Fe](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[fr](),t.resume())};t.mtime&&!this.noMtime&&(o++,te.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[yi](t)&&(o++,te.chown(String(t.absolute),Number(this[Ei](t)),Number(this[bi](t)),c)),c()})}[Bu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Nu](t,e){let r=Z(Oe.relative(this.cwd,Oe.resolve(Oe.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[gi](t,this.cwd,r,()=>this[Us](t,String(t.linkpath),"symlink",e),i=>{this[Fe](i,t),e()})}[Mu](t,e){let r=Z(Oe.resolve(this.cwd,String(t.linkpath))),i=Z(String(t.linkpath)).split("/");this[gi](t,this.cwd,i,()=>this[Us](t,r,"link",e),o=>{this[Fe](o,t),e()})}[gi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let l=Oe.resolve(e,c);te.lstat(l,(u,f)=>{if(u)return i();if(f?.isSymbolicLink())return o(new Xs(l,Oe.resolve(l,r.join("/"))));this[gi](t,l,r,i,o)})}[zu](){this[Rs]++}[fr](){this[Rs]--,this[rc]()}[Sc](t){this[fr](),t.resume()}[Ec](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Si}[yc](t){this[zu]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Lu](t,r))}[Lu](t,e){let r=l=>{e(l)},i=()=>{this[pn](this.cwd,this.dmode,l=>{if(l){this[Fe](l,t),r();return}this[vi]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let l=Z(Oe.dirname(String(t.absolute)));if(l!==this.cwd)return this[pn](l,this.dmode,u=>{if(u){this[Fe](u,t),r();return}c()})}c()},c=()=>{te.lstat(String(t.absolute),(l,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Sc](t),r();return}if(l||this[Ec](t,u))return this[ot](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let f=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,x=m=>this[ot](m??null,t,r);return f?te.chmod(String(t.absolute),Number(t.mode),x):x()}if(t.absolute!==this.cwd)return te.rmdir(String(t.absolute),f=>this[ot](f??null,t,r))}if(t.absolute===this.cwd)return this[ot](null,t,r);$w(String(t.absolute),f=>this[ot](f??null,t,r))})};this[vi]?o():i()}[ot](t,e,r){if(t){this[Fe](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[bc](e,r);case"Link":return this[Mu](e,r);case"SymbolicLink":return this[Nu](e,r);case"Directory":case"GNUDumpDir":return this[vc](e,r)}}[Us](t,e,r,i){te[r](e,String(t.absolute),o=>{o?this[Fe](o,t):(this[fr](),t.resume()),i()})}},xi=t=>{try{return[null,t()]}catch(e){return[e,null]}},yf=class extends Lc{sync=!0;[ot](t,e){return super[ot](t,e,()=>{})}[yc](t){if(!this[vi]){let o=this[pn](this.cwd,this.dmode);if(o)return this[Fe](o,t);this[vi]=!0}if(t.absolute!==this.cwd){let o=Z(Oe.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[pn](o,this.dmode);if(c)return this[Fe](c,t)}}let[e,r]=xi(()=>te.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Sc](t);if(e||this[Ec](t,r))return this[ot](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[l]=c?xi(()=>{te.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ot](l,t)}let[o]=xi(()=>te.rmdirSync(String(t.absolute)));this[ot](o,t)}let[i]=t.absolute===this.cwd?[]:xi(()=>Vw(String(t.absolute)));this[ot](i,t)}[bc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=l=>{let u;try{te.closeSync(o)}catch(f){u=f}(l||u)&&this[Fe](l||u,t),e()},o;try{o=te.openSync(String(t.absolute),xf(t.size),r)}catch(l){return i(l)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",l=>this[Fe](l,t)),t.pipe(c)),c.on("data",l=>{try{te.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,f=t.mtime;try{te.futimesSync(o,u,f)}catch(x){try{te.utimesSync(String(t.absolute),u,f)}catch{l=x}}}if(this[yi](t)){let u=this[Ei](t),f=this[bi](t);try{te.fchownSync(o,Number(u),Number(f))}catch(x){try{te.chownSync(String(t.absolute),Number(u),Number(f))}catch{l=l||x}}}i(l)})}[vc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[pn](String(t.absolute),r);if(i){this[Fe](i,t),e();return}if(t.mtime&&!this.noMtime)try{te.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[yi](t))try{te.chownSync(String(t.absolute),Number(this[Ei](t)),Number(this[bi](t)))}catch{}e(),t.resume()}[pn](t,e){try{return Fw(Z(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(r){return r}}[gi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let l of r){c=Oe.resolve(c,l);let[u,f]=xi(()=>te.lstatSync(c));if(u)return i();if(f.isSymbolicLink())return o(new Xs(c,Oe.resolve(e,r.join("/"))))}i()}[Us](t,e,r,i){let o=`${r}Sync`;try{te[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[Fe](c,t)}}},Jw=t=>{let e=new yf(t),r=t.file,i=of.statSync(r),o=t.maxReadSize||16*1024*1024;new pm(r,{readSize:o,size:i.size}).pipe(e)},Zw=(t,e)=>{let r=new Lc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("close",c),of.stat(o,(u,f)=>{if(u)l(u);else{let x=new Ac(o,{readSize:i,size:f.size});x.on("error",l),x.pipe(r)}})})},Ef=Ai(Jw,Zw,t=>new yf(t),t=>new Lc(t),(t,e)=>{e?.length&&Xu(t,e)}),Yw=(t,e)=>{let r=new Oc(t),i=!0,o,c;try{try{o=et.openSync(t.file,"r+")}catch(f){if(f?.code==="ENOENT")o=et.openSync(t.file,"w+");else throw f}let l=et.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<l.size;c+=512){for(let m=0,w=0;m<512;m+=w){if(w=et.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(!w)break e}let f=new zn(u);if(!f.cksumValid)break;let x=512*Math.ceil((f.size||0)/512);if(c+x+512>l.size)break;c+=x,t.mtimeCache&&f.mtime&&t.mtimeCache.set(String(f.path),f.mtime)}i=!1,Xw(t,r,c,o,e)}finally{if(i)try{et.closeSync(o)}catch{}}},Xw=(t,e,r,i,o)=>{let c=new Gu(t.file,{fd:i,start:r});e.pipe(c),e_(e,o)},Qw=(t,e)=>{e=Array.from(e);let r=new Zs(t),i=(o,c,l)=>{let u=(b,p)=>{b?et.close(o,_=>l(b)):l(null,p)},f=0;if(c===0)return u(null,0);let x=0,m=Buffer.alloc(512),w=(b,p)=>{if(b||p===void 0)return u(b);if(x+=p,x<512&&p)return et.read(o,m,x,m.length-x,f+x,w);if(f===0&&m[0]===31&&m[1]===139)return u(new Error("cannot append to compressed archives"));if(x<512)return u(null,f);let _=new zn(m);if(!_.cksumValid)return u(null,f);let S=512*Math.ceil((_.size??0)/512);if(f+S+512>c||(f+=S+512,f>=c))return u(null,f);t.mtimeCache&&_.mtime&&t.mtimeCache.set(String(_.path),_.mtime),x=0,et.read(o,m,0,512,f,w)};et.read(o,m,0,512,f,w)};return new Promise((o,c)=>{r.on("error",c);let l="r+",u=(f,x)=>{if(f&&f.code==="ENOENT"&&l==="r+")return l="w+",et.open(t.file,l,u);if(f||!x)return c(f);et.fstat(x,(m,w)=>{if(m)return et.close(x,()=>c(m));i(x,w.size,(b,p)=>{if(b)return c(b);let _=new Ks(t.file,{fd:x,start:p});r.pipe(_),_.on("error",c),_.on("close",o),t_(r,e)})})};et.open(t.file,l,u)})},e_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?yr({file:bf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},t_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await yr({file:bf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},pi=Ai(Yw,Qw,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!vm(t))throw new TypeError("file is required");if(t.gzip||t.brotli||t.zstd||t.file.endsWith(".br")||t.file.endsWith(".tbr"))throw new TypeError("cannot append to compressed archives");if(!e?.length)throw new TypeError("no paths specified to add/replace")}),aI=Ai(pi.syncFile,pi.asyncFile,pi.syncNoFile,pi.asyncNoFile,(t,e=[])=>{pi.validate?.(t,e),n_(t)}),n_=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(r,i)=>e(r,i)&&!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0)):(r,i)=>!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0))};rn();var _t={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",DELETE:"_agent/delete"};function Qs(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function vf(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function Nc(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Sf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function Er(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}We();ee();ke();We();function Kt(t,e){if(Qs(t)!=="cloud")throw new C("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function eo(t){return t.startsWith("http://")||t.startsWith("https://")}function to(t){return t.endsWith("/")?t.slice(0,-1):t}We();ee();var no="1008033",If="1289";var Af="pbbp2",Tf="https://www.coze.cn",Cf="/api/coze_claw/resource/get_frontier_key",i_="https://www.coze.cn",s_="wss://frontier.coze.cn";function ro(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??i_}function Rf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??s_}function br(t){let e={},r=t?.ttEnv??process.env.COZE_BRIDGE_TT_ENV,i=t?.usePpe??process.env.COZE_BRIDGE_USE_PPE;return r&&(e["x-tt-env"]=r),i&&(e["x-use-ppe"]=i),e}function Ci(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Ti=H("handshake");async function Mc(t){let e=ro(t.endpoint),r=t.timeoutMs??1e4,i=`${to(e)}${Cf}?aid=${encodeURIComponent(no)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...br(t.ppeOverride)},c=new AbortController,l=setTimeout(()=>c.abort(),r);Ti.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),f=u.headers.get("x-tt-logid")??"",x=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let _=await u.text().catch(()=>"");throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${f}: ${_.slice(0,200)}`)}let m=await u.json();if(m.code!==void 0&&m.code!==0)throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${m.code} msg=${m.msg??"-"} logid=${f}`);let w=m.data??{},b=typeof w.access_key=="string"&&w.access_key||typeof w.accessKey=="string"&&w.accessKey||void 0,p=typeof w.device_id=="string"&&w.device_id||typeof w.deviceId=="string"&&w.deviceId||void 0;if(!b||!p){let _=JSON.stringify(m).slice(0,500);throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${f}: ${_}`)}return Ti.info("handshake ok",{remoteDeviceId:p,logid:f,traceId:x}),{accessKey:b,deviceId:p}}catch(u){if(u instanceof C)throw Ti.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Ti.warn("handshake timeout",{base:e,timeoutMs:r}),new C("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let f=u.cause;throw Ti.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:f?.code,syscall:f?.syscall,cause:String(u).slice(0,300)}),new C("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(l)}}var Bc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",yt="auto",Df=15e4;function kf(t){return{model:Fc(t.model)??yt,...t.modelToken?{modelToken:t.modelToken}:{}}}function Pf(t){return!t||t===yt}var o_=new Set(["auto","\u81EA\u52A8"]);function Fc(t){let e=t?.trim();if(e)return o_.has(e.toLowerCase())?yt:e}function Of(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Bc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||yt;e.ANTHROPIC_MODEL=r,e.ANTHROPIC_SMALL_FAST_MODEL=r,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=r,e.ANTHROPIC_DEFAULT_OPUS_MODEL=r,e.ANTHROPIC_DEFAULT_SONNET_MODEL=r,e.CLAUDE_CODE_SUBAGENT_MODEL=r,e.CLAUDE_CODE_ATTRIBUTION_HEADER="0",t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else Pf(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Lf(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||yt}"`):Pf(t.model)||e.push("-c",`model="${t.model}"`),t.modelToken){e.push("-c",'model_providers.coze.name="coze"'),e.push("-c",`model_providers.coze.base_url="${Bc}/v1"`),e.push("-c",'model_providers.coze.env_key="OPENAI_API_KEY"'),e.push("-c",'model_providers.coze.wire_api="responses"'),e.push("-c","model_providers.coze.requires_openai_auth=false"),e.push("-c","model_providers.coze.supports_websockets=false"),e.push("-c",'model_provider="coze"');let r=t.modelInfo?.contextWindow??Df;e.push("-c",`model_context_window=${r}`)}return e}function Nf(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function zc(t,e){let{ttEnv:r,usePpe:i}=Ci(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Mf(t,e,r){if(!t.modelToken)return{};let i=zc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,l])=>`${c}:${l}`).join(`
92
- `)}}function Uc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function Bf(t,e,r){if(!t.modelToken)return null;let i=t.model||yt,o=zc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let l={baseUrl:`${Bc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:[{id:i,name:i,reasoning:!1,input:c,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:t.modelInfo?.contextWindow??Df,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(l.headers=o),l}function Ff(t,e,r){if(!t.modelToken)return[];let i=zc(e,r),o=[];for(let[c,l]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${l}"`);return o}var Le=H("agent-handlers"),zf=5*1024*1024,f_=1,h_=6,x_=new Set(["node_modules",".git",".coze","dist","build",".next"]),io=class{constructor(e){this.opts=e}opts;async listSkills(e){Kt(e._meta,"_agent/listSkills");let r=Er(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Ze(r).workspace,c=i?.skills??[],l=[];for(let u of c){let f=Pt(o,u.relPath,"SKILL.md");await l_(f).then(m=>m.isFile()).catch(()=>!1)&&l.push(__(u))}return{skills:l}}async addSkills(e){Kt(e._meta,"_agent/addSkills");let r=Er(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],l=new Map(c.map((f,x)=>[f.skillId,x])),u=[];for(let f of o){let x=await $c({agentId:r,workspace:i.workspace,framework:i.framework,skill:f});Vc(c,l,x),u.push(f)}return await cs(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){Kt(e._meta,"_agent/removeSkills");let r=Er(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],l=[];for(let u of c){if(!o.has(u.skillId)){l.push(u);continue}let f=Pt(i.workspace,u.relPath);await c_(f,{recursive:!0,force:!0}),Le.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await cs(r,l),this.reloadAgentSessions(r,"skills-removed"),{ok:!0}}reloadAgentSessionsPublic(e,r){this.reloadAgentSessions(e,r)}reloadAgentSessions(e,r){let i=this.opts.agents.get(e);if(i)for(let[o,c]of i.sessions){if(!c.downstream)continue;let l=c.acpSessionId;if(l&&i.activeTriggers.has(l)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,Le.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l});continue}let f=c.downstream;c.downstream=void 0,Le.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l}),f.stop(r).catch(x=>Le.warn("downstream stop failed during reload (ignored)",{reason:r,agentId:e,cloudId:o,err:String(x)}))}}isRuntimePendingPermission(e){let r=this.opts.isRuntimePendingPermission;return!r||!e.downstream?!1:r(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return Le.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await He(r);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Le.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await ir(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Le.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new C("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Ye(i),Le.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new C("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await He(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Ye(i),Le.info("agent disconnected",{agentId:r,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(r,e.reason??"disconnect"),{ok:!0}):(Le.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(Kt(e._meta,"_agent/switchModel"),!e.agentId)throw new C("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Fc(e.model)??yt,i=await He(e.agentId);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Ye(i),Le.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Le.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};o.model=r,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o).catch(l=>Le.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(l)}));let c=[];for(let[l,u]of o.allSessionQueues())c.push(u.enqueue(async()=>{let f=o.sessions.get(l);f?.downstream&&(await f.downstream.stop(`switchModel: ${r}`).catch(()=>{}),f.downstream=void 0)}));return await Promise.all(c),Le.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:r,cloudSessions:c.length}),{ok:!0}}async resetAgent(e){if(Kt(e._meta,_t.RESET),!e.agentId)throw new C("IPC_BAD_REQUEST",`${_t.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,_t.RESET),await this.runDetailSync(e.agentId,_t.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),Le.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(r);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,l]of i.sessions)o.set(c,{modelToken:l.modelToken,tokenGeneratedAt:l.tokenGeneratedAt});await ei(e,o)}async clearPersistedAcpSessionIds(e){let r=await He(e).catch(()=>null);if(!r?.sessions)return;let i=!1;for(let o of Object.values(r.sessions))o.acpSessionId&&(o.acpSessionId=void 0,i=!0);i&&await Ye(r)}async repairAgent(e){if(Kt(e._meta,_t.REPAIR),!e.agentId)throw new C("IPC_BAD_REQUEST",`${_t.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new C("IPC_BAD_REQUEST",`${_t.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){Le.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,_t.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){Le.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Le.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){Kt(e._meta,"_agent/getFileTree");let r=e._meta,i=Er(r),o=await this.resolveWorkspace(i),c=e.filePath??"",l=this.safeJoin(o,c),u=await Hc(l).catch(()=>null);if(!u)throw new C("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await Qr(l,o))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let f=D_(e.depth);return u.isDirectory()?{tree:await R_(o,l,c,f)}:{tree:[{name:k_(c),path:Kf(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){Kt(e._meta,"_agent/getFileContent");let r=Er(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new C("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await Hc(o).catch(()=>null);if(!c||!c.isFile())throw new C("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await Qr(o,i))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>zf)throw new C("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${zf})`);let l=await Uf(o);return l.includes(0)?{content:l.toString("base64"),encoding:"base64",size:c.size}:{content:l.toString("utf8"),encoding:"utf-8",size:c.size}}async resolveWorkspace(e){let r=this.opts.agents.get(e);return r?r.workspace:(await He(e).catch(()=>null))?.workspace??Ze(e).workspace}safeJoin(e,r){let i=jc(e,r||"."),o=Kc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Hf}`))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return He(e)}async requireAgentCfg(e){let r=await this.loadAgentCfg(e);if(!r)throw new C("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function p_(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new C("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new C("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function g_(t){return t==="claude-code"?Pt(".claude","skills"):Pt(".agents","skills")}var m_=3e4,w_=50*1024*1024,vr=3e4;async function $c(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new C("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,l=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!l)throw new C("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=p_(o.skillName),f=g_(i),x=Pt(f,u),m=Pt(r,x);if(await qc(m,{recursive:!0}),c){let b=Buffer.from(o.content,"utf8");Ri(b.length),await Gc(Pt(m,"SKILL.md"),b,"utf8")}else{let b=await y_(o.downloadUrl);b_(b)?await A_(b,m):v_(b)?await S_(b,m):await Gc(Pt(m,"SKILL.md"),b.toString("utf8"),"utf8")}let w={skillId:o.skillId,skillName:o.skillName,relPath:x,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return Le.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:x,source:c?"content":"downloadUrl"}),w}function Vc(t,e,r){let i=e.get(r.skillId);if(i!==void 0){t[i]=r;return}e.set(r.skillId,t.length),t.push(r)}function __(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function y_(t){if(!t)throw new C("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Ri(e);let r=E_(t);return Ri(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await Uf(e);return Ri(r.length),r}if(eo(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),m_);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new C("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Ri(o.byteLength),Buffer.from(o)}finally{clearTimeout(r)}}throw new C("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Ri(t){if(t>w_)throw new C("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function E_(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new C("IPC_BAD_REQUEST","bad data URL");let r=!!e[2],i=e[3]??"";return r?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function b_(t){return t.length>=2&&t[0]===31&&t[1]===139}function v_(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],r=t[3];return e===3&&r===4||e===5&&r===6}function Wc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function S_(t,e){let r,i;try{r=new jf.default(t),i=r.getEntries()}catch(l){throw new C("IPC_BAD_REQUEST",`zip parse failed: ${l.message}`,{cause:l})}for(let l of i){let u=l.entryName;if(!u||Wc(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new C("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(x=>x===".."))throw new C("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let f=l.header.attr>>>16&61440;if(f!==0&&f!==32768&&f!==16384)throw new C("IPC_BAD_REQUEST",`zip entry kind 0x${f.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=I_(i),c=jc(e);for(let l of i){if(Wc(l.entryName))continue;let u=l.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let f=jc(e,u),x=Kc(c,f);if(x.startsWith("..")||x==="..")throw new C("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(l.isDirectory){await qc(f,{recursive:!0});continue}await qc(d_(f),{recursive:!0});let m;try{m=l.getData()}catch(w){throw new C("IPC_BAD_REQUEST",`zip entry getData failed (${l.entryName}): ${w.message}`,{cause:w})}await Gc(f,m)}}function I_(t){let e;for(let r of t){let i=r.entryName;if(!i||Wc(i))continue;let o=i.indexOf("/");if(o<=0)return;let c=i.slice(0,o+1);if(e===void 0)e=c;else if(e!==c)return}return e}async function A_(t,e){await T_(t);let r=Ef({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new C("IPC_BAD_REQUEST",`tar extract timeout (${vr}ms)`))},vr);try{await Gf(qf.from(t),r)}catch(c){throw c instanceof C?c:i?new C("IPC_BAD_REQUEST",`tar extract timeout (${vr}ms)`):new C("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function T_(t){let e=[],r=yr({onReadEntry:c=>{let l=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' not allowed (symlink/hardlink/special): ${l.slice(0,100)}`);return}if(l.startsWith("/")||l.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(l)){e.push(`tar entry absolute path: ${l}`);return}l.split(/[/\\]/).some(x=>x==="..")&&e.push(`tar entry contains '..': ${l}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new C("IPC_BAD_REQUEST",`tar list timeout (${vr}ms)`))},vr);try{await Gf(qf.from(t),r)}catch(c){throw i?new C("IPC_BAD_REQUEST",`tar list timeout (${vr}ms)`):new C("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new C("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var C_=5e3;async function R_(t,e,r,i){return Wf(t,e,r,i,{count:0})}async function Wf(t,e,r,i,o){if(i<=0)return[];let c;try{c=await a_(e,{withFileTypes:!0})}catch{return[]}let l=[];for(let u of c){if(x_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=C_){l.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let f=Pt(e,u.name),x=u_(Pt(r,u.name)),m=null;try{m=await Hc(f)}catch{continue}if(m.isSymbolicLink())continue;o.count++;let w={name:u.name,path:Kf(Kc(t,f)),isDir:m.isDirectory(),size:m.size,modifiedAt:Math.floor(m.mtimeMs)};m.isDirectory()&&i>1&&(w.children=await Wf(t,f,x,i-1,o)),l.push(w)}return l.sort((u,f)=>u.isDir!==f.isDir?u.isDir?-1:1:u.name.localeCompare(f.name)),l}function D_(t){return!t||t<=0?f_:Math.min(t,h_)}function k_(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function Kf(t){return t.split(Hf).join("/")}ee();import{readFileSync as mA}from"node:fs";import{dirname as _A,join as yA}from"node:path";import{fileURLToPath as bA}from"node:url";var Sr="0.1.102";var wn=H("agent-health-reporter"),P_=1e4,Di=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??P_}opts;timer=null;inFlight=!1;unsubscribeRegister=null;intervalMs;start(){this.timer||(this.timer=setInterval(()=>{this.tick()},this.intervalMs),this.timer.unref?.(),this.unsubscribeRegister=this.opts.core.onAgentRegister(()=>{this.tick()}),wn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),wn.info("heartbeat stopped"))}async tick(){if(this.inFlight){wn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){wn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let r=[];for(let l of this.opts.core.agents.values()){let u=O_(l);if(!u)continue;let f={agentId:l.agentId,status:u};l.patToken&&(f.patToken=l.patToken),l.accountId&&(f.accountId=l.accountId),r.push(f)}if(r.length===0)return;let i={agents:r,bridgeVersion:Sr,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(l){wn.warn("heartbeat batch send failed",{count:r.length,err:String(l)})}let c=o?.authFailures;if(c&&c.length>0&&(wn.warn("heartbeat received authFailures from cloud",{count:c.length,agentIds:c.map(l=>l.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(c)}catch(l){wn.warn("onAuthFailures callback failed (ignored)",{err:String(l)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){wn.warn("onTickEnd hook failed",{err:String(r)})}}};function O_(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}rn();import{chmod as Dy,mkdir as xo,rm as ky,stat as Py,writeFile as Oy}from"node:fs/promises";import{homedir as Ly}from"node:os";import{join as E0}from"node:path";nn();import{existsSync as X_}from"node:fs";import{release as Q_}from"node:os";import{basename as ey,isAbsolute as ty}from"node:path";function ki(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Ir(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Ar(t,e){return{jsonrpc:"2.0",id:t,result:e}}function _n(t,e){return{jsonrpc:"2.0",id:t,error:e}}We();var so=class extends Error{code;data;constructor(e){super(`JSON-RPC error code=${e.code} ${e.message}`),this.name="RemoteRpcError",this.code=e.code,e.data!==void 0&&(this.data=e.data)}},Q={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021};function $f(t){return"method"in t&&"id"in t&&t.id!==void 0}function Vf(t){return"method"in t&&!("id"in t)}function oo(t){return!("method"in t)&&"id"in t}var L_={AGENT_NOT_FOUND:Q.AGENT_NOT_FOUND,AGENT_BUSY:Q.AGENT_BUSY,AGENT_DISCONNECTED:Q.AGENT_DISCONNECTED,AGENT_TIMEOUT:Q.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:Q.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:Q.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:Q.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:Q.INTERNAL_ERROR,BRIDGE_INTERNAL:Q.INTERNAL_ERROR,IPC_AUTH_FAILED:Q.INTERNAL_ERROR,IPC_BAD_REQUEST:Q.INVALID_REQUEST,MODEL_TOKEN_GEN_FAILED:Q.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:Q.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:Q.OPERATION_NOT_ALLOWED_FOR_LOCAL,UPSTREAM_DISCONNECTED:Q.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:Q.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:Q.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:Q.FILE_TOO_LARGE,UNSUPPORTED_MIME:Q.UNSUPPORTED_MIME,UPLOAD_FAILED:Q.UPLOAD_FAILED,UPSTREAM_NOT_READY:Q.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:Q.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:Q.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:Q.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:Q.AGENT_ENV_NOT_READY};function N_(t){if(t!=null)return t instanceof Error?{name:t.name,message:Pi(t.message)}:typeof t=="string"?Pi(t):typeof t=="object"?B_(t):t}var M_=[[/\/Users\/[^/\s'"`)]+/g,"/Users/<redacted>"],[/\/home\/[^/\s'"`)]+/g,"/home/<redacted>"],[/[A-Za-z]:\\Users\\[^\\\s'"`)]+/g,"C:\\Users\\<redacted>"],[/(Bearer|Token|Authorization:)\s+[\w._-]+/gi,"$1 <redacted>"],[/\b(sk|pat|ak)[-_][A-Za-z0-9_-]{20,}\b/g,"<redacted-key>"]];function Pi(t){let e=t;for(let[r,i]of M_)e=e.replace(r,i);return e}function B_(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Pi(i):e[r]=i;return e}function Oi(t){if(t instanceof C){let e=N_(t.cause),r={bridgeCode:t.code,retriable:t.retriable};return e!==void 0&&(r.cause=e),e&&typeof e=="object"&&"reason"in e&&typeof e.reason=="string"&&(r.reason=e.reason),{code:L_[t.code]??Q.INTERNAL_ERROR,message:Pi(t.message),data:r}}return{code:Q.INTERNAL_ERROR,message:Pi(t instanceof Error?t.message:String(t))}}function Jf(t){let e=t.data,r=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:l,...u}=e;c=u}return new C(r,o,{retriable:e?.retriable??!1,cause:c})}function Yf(t){return`${JSON.stringify(t)}
93
- `}var Zf=10*1024*1024,ao=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>Zf){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${Zf} bytes`)}),[]}let r=this.buffer.split(`
94
- `);this.buffer=r.pop()??"";let i=[];for(let o of r){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(l){this.onError?.({line:c,error:l})}}return i}flush(){if(!this.buffer)return[];let e=this.buffer.replace(/\r$/,"").trim();if(this.buffer="",!e)return[];try{return[JSON.parse(e)]}catch(r){return this.onError?.({line:e,error:r}),[]}}};var Qf={"session/prompt":"session.prompt","session/cancel":"session.cancel","session/new":"session.new","session/load":"session.load","_agent/create":"agent.create","_agent/health":"agent.health","_agent/pair":"agent.pair","_agent/listSkills":"agent.listSkills","_agent/addSkills":"agent.addSkills","_agent/removeSkills":"agent.removeSkills","_agent/getFileTree":"agent.getFileTree","_agent/getFileContent":"agent.getFileContent","_agent/detail":"agent.detail","_agent/update":"agent.update","_agent/disconnect":"agent.disconnect","_agent/switchModel":"agent.switchModel","_agent/genModelToken":"agent.genModelToken","_agent/reset":"agent.reset","_agent/repair":"agent.repair","session/request_permission":"session.requestPermission",initialize:"initialize"},OA=Object.fromEntries(Object.entries(Qf).map(([t,e])=>[e,t])),F_={"session.prompt":["agentId","triggerMsgId","sessionId"],"session.cancel":["agentId","triggerMsgId","sessionId"],"session.new":["agentId"],"session.load":["agentId"],"agent.create":["agentId"],"agent.health":[],"agent.listSkills":["agentId"],"agent.addSkills":["agentId"],"agent.removeSkills":["agentId"],"agent.getFileTree":["agentId"],"agent.getFileContent":["agentId"],"agent.detail":["agentId"],"agent.update":["agentId"],"agent.disconnect":["agentId"],"agent.switchModel":["agentId"],"agent.genModelToken":["agentId","sessionId"],"agent.reset":["agentId"],"agent.repair":["agentId"],"session.requestPermission":["agentId","sessionId"],"agent.pair":[],initialize:[]},Tr=class{seq=0;next(e,r){this.seq+=1;let i=Qf[e]??z_(e),o=F_[i]??[],c=[i,String(this.seq)];if(o.length>0){let l=o.map(f=>Xf(r?.[f]??"")),u=U_(l).join(":");u&&c.push(u)}else r&&Object.values(r).some(l=>l)&&c.push(Object.values(r).filter(Boolean).map(l=>Xf(String(l))).join(":"));return c.join("_")}reset(){this.seq=0}};function z_(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function Xf(t){return t.replace(/[:_\s]+/g,"-")}function U_(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}Xr();import{readFileSync as H_}from"node:fs";var q_=384;async function Jc(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await rr(t.agentEnvFile,r,{mode:q_})}function Zc(t){try{let e=JSON.parse(H_(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function e0(t,e,r={},i=o=>o){return{...i({...t,...Zc(e)}),...r}}yn();Xn();We();ee();ke();import{execFileSync as J_,spawnSync as Z_}from"node:child_process";function Li(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function Ni(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),Z_("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var Yc=new Set;function i0(t){typeof t=="number"&&t>0&&Yc.add(t)}function s0(t){typeof t=="number"&&Yc.delete(t)}function o0(){for(let t of Yc)Ni(t,"SIGKILL")}var Cr="coze-bridge-daemon";function a0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return J_("pgrep",["-U",String(o),"-f",Cr],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:2e3})}),r;try{r=e()}catch{return[]}let i=process.pid;return r.split(`
95
- `).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function c0(t,e){if(t.length===0)return;let r=e?.killFn??Ni,i=e?.isAliveFn??Li,o=e?.sleepFn??(u=>new Promise(f=>setTimeout(f,u))),c=e?.graceMs??3e3,l=e?.pollMs??100;for(let u of t)r(u,"SIGTERM");for(let u=0;u<c&&t.some(f=>i(f));u+=l)await o(Math.min(l,c-u));for(let u of t)i(u)&&r(u,"SIGKILL")}var Y_=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: (Node binary not found|QCLAW_CLI_NODE_BINARY not set)/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @zed-industries\/codex-acp|optional dependency was not installed|\.resolve is not a function/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"acp_module_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code","codex"],match:/Cannot find module[^\n]*node_modules[\\/]@(agentclientprotocol[\\/]claude-agent-acp|zed-industries[\\/]codex-acp)/i,message:"ACP \u4F9D\u8D56\u672A\u6B63\u786E\u5B89\u88C5 (wrapper \u5165\u53E3\u7F3A\u5931)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u91CD\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"},{reason:"prompt_too_long",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code"],match:/Prompt is too long|bad request: failed to read body: length limit exceeded/i,message:"\u672C\u8F6E\u8F93\u5165\u8FC7\u957F\uFF0C\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u7CBE\u7B80\u8F93\u5165\u6216\u5F00\u542F\u65B0\u4F1A\u8BDD\u540E\u91CD\u8BD5"}];function l0(t,e){if(!e)return null;for(let r of Y_)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function d0(t,e){return l0(t,e)}function u0(t,e){return l0(t,e)}function Rr(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 f0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let x=t.suspendedMs+o,m=r-t.startedAt-x;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Rr(m,t.firstFrameSeen,e)}}let c=r-t.startedAt-t.suspendedMs,l=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=l?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Rr(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Rr(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Rr(c,!1,e)}}var h0=Ge("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),ny=200,ry=40,iy=Ge("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),sy=Ge("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),oy=Ge("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),ay=Ge("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),cy=Ge("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),ly=Ge("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),x0=500;function dy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=x0?t:`${e.slice(0,x0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function uy(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 p0(t){try{return X_(t)}catch{return}}function fy(t,e){return{platform:process.platform,osRelease:Q_(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:ty(e.command)?p0(e.command):void 0,cwd:e.cwd,cwdExists:p0(e.cwd),envKeys:e.envKeys}}function hy(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${ey(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Ot=class{constructor(e){this.opts=e;this.log=H(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new ao({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Tr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new C("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=e0(process.env,this.opts.agentEnvFile??X().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=at(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,i0(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>ny&&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,s0(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=fy(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(r).length});this.log.error("child error",{err:String(o),diag:l}),this.failAllPending(new C("AGENT_SPAWN_FAILED",hy(c,l),{cause:l}))}),this.log.info("downstream started",{command:this.opts.command,pid:i.pid,cwd:this.opts.cwd})}async stop(e){if(!this.child||this.stopped)return;this.stopped=!0,this.stopReason=e??"stopped",this.log.info("downstream stopping",{reason:e});let r=this.child,i=new Promise(c=>r.once("exit",()=>c()));Ni(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Ni(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:cy,phase2GateMs:iy,livenessWindowMs:sy,absoluteMaxMs:oy,approvalMaxMs:ly,suspendThresholdMs:ay,...r};return this.call("session/prompt",e,h0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Ir("session/cancel",e))}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Ar(e,r))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(_n(e,r))}catch(i){this.log.warn("respondAgentRequestError write failed",{id:e,err:String(i)})}}onExit(e){this.exitHandlers.push(e)}call(e,r,i=h0,o){if(!this.child||this.stopped)return Promise.reject(new C("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),l=ki(c,e,r),u=(()=>{if(typeof r!="object"||r===null)return;let f=r.sessionId;return typeof f=="string"?f:void 0})();return new Promise((f,x)=>{let m={resolve:f,reject:x,timer:null,method:e,promptTimeout:null};if(o){let w=this.now(),b={cfg:o,startedAt:w,lastActivityAt:w,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:w,expectedIntervalMs:Rr(0,!1,o),sessionId:u};m.promptTimeout=b;let p=()=>{let _={startedAt:b.startedAt,lastActivityAt:b.lastActivityAt,firstFrameSeen:b.firstFrameSeen,hasActiveTool:b.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:b.suspendedMs,armedAt:b.armedAt,expectedIntervalMs:b.expectedIntervalMs},S=this.now(),A=f0(_,b.cfg,S),T=D=>{b.armedAt=S,b.expectedIntervalMs=D,m.timer=setTimeout(p,D)};if(A.action==="suspend"){b.suspendedMs+=A.suspendedDeltaMs,b.lastActivityAt=S,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:A.suspendedDeltaMs,suspendedMs:b.suspendedMs,...b.sessionId?{sessionId:b.sessionId}:{}}),T(A.rearmMs);return}if(A.action==="continue"){T(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,...b.sessionId?{sessionId:b.sessionId}:{}}),x(A.awaitingApproval?new C("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${b.cfg.approvalMaxMs}ms`):new C("AGENT_TIMEOUT",`${e} timed out after ${b.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...b.sessionId?{sessionId:b.sessionId}:{}}),x(new C("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${b.cfg.livenessWindowMs}ms`)))};m.timer=setTimeout(p,b.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 C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,m);try{this.writeFrame(l)}catch(w){m.timer&&clearTimeout(m.timer),this.pending.delete(c),x(w)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new C("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(Yf(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(oo(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new C("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:dy(e.result)}),r.resolve(e.result));return}if(Vf(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($f(e)){let r=e;try{this.handleAgentRequest(r).catch(i=>this.log.error("agent request handler failed (async)",{method:r.method,err:String(i)}))}catch(i){this.log.warn("handleAgentRequest threw sync, swallowed",{method:r.method,err:String(i)})}}}trackToolCall(e,r){let i=r.update,o=i?.sessionUpdate;if(o!=="tool_call"&&o!=="tool_call_update")return;let c=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!c)return;let l=typeof i.status=="string"?i.status:void 0,u=l==="completed"||l==="failed"||l==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(_n(e.id,{code:-32601,message:`method not handled by Bridge: ${e.method}`}));return}this.inflightAgentRequests.set(e.id,e.method);for(let r of this.agentRequestHandlers)try{await r(e)}catch(i){this.log.error("agentRequestHandler threw",{method:e.method,err:String(i)});try{this.writeFrame(_n(e.id,Oi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=Jf(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=u0(this.framework,uy(e));return i?new C(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):r}buildExitError(e,r){if(this.stopReason!==void 0)return new C("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(ry).join(`
96
- `),o=d0(this.framework,i);return o?new C(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new C("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function xy(t){let e={};for(let[r,i]of Object.entries(t))i!==void 0&&(r.startsWith("CLAUDE")||r==="AI_AGENT"||r==="BAGGAGE"||(e[r]=i));return e}var co=class extends Ot{framework="claude-code";constructor(e){let{command:r,args:i}=Yr("claude-code",e.command,e.args??[]),o={command:r,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o)}sanitizeEnv(e){return xy(e)}};nn();import{mkdtempSync as py,rmSync as gy}from"node:fs";import{tmpdir as my}from"node:os";import{join as wy}from"node:path";var lo=class extends Ot{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=Yr("codex",e.command,i),l=e.isolateCodexHome?py(wy(my(),"coze-bridge-codex-home-")):void 0,u=l?{...e.env??{},CODEX_HOME:l}:e.env,f={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(f),this.authMethodId=e.authMethodId,this.codexHomeDir=l}async initialize(e){let r=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),r}async stop(e){if(await super.stop(e),this.codexHomeDir)try{gy(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};var _y=3e4,Dr=class extends Ot{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}`}]},_y))}get acpSessionName(){return this.sessionName}};We();ee();ke();function Xc(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}nn();var En=class{slots=[];running=!1;closed=!1;disposed=!1;enqueue(e){return this.disposed?Promise.reject(new Error("AsyncQueue disposed")):this.closed?Promise.reject(new Error("AsyncQueue closed")):new Promise((r,i)=>{this.slots.push({task:e,resolve:r,reject:i}),this.drain()})}close(){this.closed=!0}dispose(e=new Error("AsyncQueue disposed")){for(this.disposed=!0,this.closed=!0;this.slots.length>0;)this.slots.shift()?.reject(e)}get size(){return this.slots.length}get isRunning(){return this.running}get isDisposed(){return this.disposed}async drain(){if(!this.running){this.running=!0;try{for(;this.slots.length>0&&!this.disposed;){let e=this.slots.shift();if(!e)break;try{let r=await e.task();e.resolve(r)}catch(r){e.reject(r)}}}finally{this.running=!1}}}};var uo=class{agentId;framework;workspace;deployType;accountId;patToken;modelInfo;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;activeGroupIds=new Map;status="ok";model;lastActiveAt=Date.now();constructor(e){this.agentId=e.agentId,this.framework=e.framework,this.workspace=e.workspace,this.model=e.model,this.deployType=e.deployType??"local",e.accountId&&(this.accountId=e.accountId),e.patToken&&(this.patToken=e.patToken),e.modelInfo&&(this.modelInfo=e.modelInfo)}setPatToken(e){this.patToken=e}setModelInfo(e){this.modelInfo=e}getSessionQueue(e){let r=this.sessionQueues.get(e);return(!r||r.isDisposed)&&(r=new En,this.sessionQueues.set(e,r)),r}allSessionQueues(){return this.sessionQueues.entries()}hasSessionQueue(e){let r=this.sessionQueues.get(e);return!!r&&!r.isDisposed}async dispose(e){this.status="stopped";let r=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let i of this.sessionQueues.values())i.dispose(r);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let r=[];for(let[,i]of this.sessions)Mi(i),i.downstream&&(r.push(i.downstream.stop(e).catch(()=>{})),i.downstream=void 0);await Promise.all(r),this.activeTriggers.clear(),this.activeGroupIds.clear()}};function Mi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}yn();ee();import{constants as g0}from"node:fs";import{access as yy}from"node:fs/promises";import{delimiter as Ey,join as by}from"node:path";var Et=H("framework-detector"),m0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},vy=[".exe",".cmd",".bat",".ps1"],Hn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??at,access:e.access??yy}}async detect(e){let r=m0[e],i=await this.which(r);if(!i)return Et.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,l]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return l&&(u.defaultAgent=l),u}async detectAll(){let e=await Promise.all(Object.keys(m0).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(Ey).filter(Boolean),i=this.env.platform==="win32"?["",...vy]:[""];for(let o of r)for(let c of i){let l=by(o,e+c);if(await this.isExecutable(l))return l}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?g0.F_OK:g0.X_OK;return await this.env.access(e,r),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let r=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!r)return Et.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return Et.warn("openclaw default agent probe: non-zero exit",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)}),null;let i=r.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return Et.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:r.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return Et.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(l=>l?.isDefault===!0);return c?!c.id||!c.workspace?(Et.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(Et.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return Et.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let r=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!r)return Et.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||Et.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let l=JSON.parse(c[0]);typeof l.gateway?.port=="number"&&(o.port=l.gateway.port),typeof l.service?.runtime?.status=="string"&&(o.runtime=l.service.runtime.status),!i&&typeof l.rpc?.error=="string"&&(o.detail=l.rpc.error)}catch(l){Et.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(l)})}return o}async probeVersion(e,r=[]){let i=await this.runProbe(e,[...r,"--version"]);return i&&(Iy(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,l,u=f=>{c||(c=!0,l&&clearTimeout(l),i(f))};try{let f=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});l=setTimeout(()=>{f.kill("SIGKILL"),u(null)},15e3),f.stdout?.on("data",x=>{o+=x.toString("utf8")}),f.on("error",()=>u(null)),f.on("close",x=>u({code:x,stdout:o}))}catch{u(null)}})}},Sy=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function Iy(t){return t.replace(Sy,"")}import{homedir as Ay}from"node:os";import{join as Ty}from"node:path";yn();Xn();We();Xr();ee();async function y0(){let t=Ty(Ay(),".openclaw/openclaw.json");return(await nr(t))?.gateway?.auth?.token??""}var w0=H("openclaw.config"),Cy=[0,5e3,5e3],Ry=Ge("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),_0="models.providers.",fo="agents.defaults.models",ho=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new En;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??Cy,this.cliTimeoutMs=e.cliTimeoutMs??Ry}async withRetry(e,r){let i;for(let o=0;o<this.retryDelaysMs.length;o++){let c=this.retryDelaysMs[o]??0;c>0&&await new Promise(l=>setTimeout(l,c));try{return await r()}catch(l){i=l,w0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(l)})}}throw new C("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=at(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",l=!1,u=x=>{l||(l=!0,clearTimeout(f),x())};o.stderr?.on("data",x=>{c+=x.toString("utf8")});let f=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);f.unref(),o.on("error",x=>u(()=>i(x))),o.on("close",x=>u(()=>{x===0?r():i(new Error(`exit ${x}: ${c.trim().slice(0,500)}`))}))})}async runCliTolerant(e,r){try{await this.runCli(e)}catch(i){let o=String(i);if(r.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,r){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",r])))}catch(i){w0.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",`${_0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${_0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${fo}[${e}]`,()=>this.runCli(["config","set",fo,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${fo}[${e}]`,`${fo}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var le=H("agent-manager"),Ny=(t,e,r,i,o,c,l,u,f)=>{switch(t){case"claude-code":{let x={...o?{...Of(o),...Mf(o,l,u)}:{},...f??{},IS_SANDBOX:"1"};return new co({cwd:r,env:x,agentId:i})}case"codex":{let m=[...o?[...Lf(o),...Ff(o,l,u)]:[],"-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"'],w={...o?Nf(o):{},...f??{}},b=!!o;return new lo({cwd:r,agentId:i,...m.length>0?{extraArgs:m}:{},...Object.keys(w).length>0?{env:w}:{},...b?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Dr({command:e,cwd:r,agentId:i,...c?{sessionName:Xc(c)}:{}})}};function Qc(t){return t==="claude-code"||t==="codex"}function My(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(By(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
89
+ `},configPath(t){return n1(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 Kx("schtasks",["/Create","/SC","ONLOGON","/TN",ra,"/TR",r,"/RU",t.userName,"/F"]),zd.info("task scheduler entry created",{task:ra,logFile:t.logFile})},async uninstall(t){await Kx("schtasks",["/Delete","/TN",ra,"/F"]).catch(e=>zd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),zd.info("task scheduler entry removed",{task:ra})}}});var Jx={};wa(Jx,{buildContext:()=>c1,getSupervisor:()=>s1,launchdSupervisor:()=>Bd,systemdSupervisor:()=>Fd,taskSchedulerSupervisor:()=>Ud});import{homedir as r1,userInfo as i1}from"node:os";function s1(t=process.platform){switch(t){case"darwin":return Bd;case"linux":return Fd;case"win32":return Ud;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function a1(){let t={};for(let e of o1){let r=process.env[e];r&&(t[e]=r)}return t}function c1(){let t=Q();return{nodeBin:process.execPath,entry:Dd(t),logFile:t.logFile,homeDir:r1(),userName:i1().username,isRoot:process.getuid?.()===0,env:a1()}}var o1,Vx=Ve(()=>{"use strict";ke();Ko();Gx();Wx();$x();o1=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ne();tn();var wl=U("acp-installer-warmup"),Eg=["claude-code","codex"];async function _l(t={}){let e=t.ensure??tr,i=(await Promise.allSettled(Eg.map(async o=>{let c=await e(o);wl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&wl.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))})}nn();ne();import{readdir as Lg}from"node:fs/promises";import{mkdir as Il,readFile as Pg,writeFile as Al}from"node:fs/promises";import{join as Ia}from"node:path";var Og={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function ir(t,e,r){await Il(t,{recursive:!0});let i=Og[e],o=Ia(t,i);return await Al(o,r??"","utf8"),o}async function Aa(t,e,r){let i=Ia(t,".claude");await Il(i,{recursive:!0});let o=Ia(i,"settings.local.json"),c={};try{let u=await Pg(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(!r)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");l.defaultMode===void 0&&(l.defaultMode=r)}return c.permissions=l,await Al(o,JSON.stringify(c,null,2),"utf8"),o}var et=U("agent-detail-sync"),Ng=6e4,Mg=5*6e4,cs=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await Lg(r)}catch(o){et.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}et.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await qe(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){et.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(l){et.warn("detail sync failed for agent, skipping",{agentId:o,err:String(l)})}}})),et.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),r=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&r.push(i);if(r.length!==0){et.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){et.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await qe(e,this.opts.paths);if(!i){et.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(u){et.warn("detail RPC failed, using local data",{agentId:e,err:String(u)});let h=this.retryQueue.get(e),x=h?Math.min(h.currentDelay*2,Mg):Ng;this.retryQueue.set(e,{dueAt:Date.now()+x,currentDelay:x});return}if(o.agentId&&o.agentId!==e){et.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,l=!1;if(o.agentName&&o.agentName!==i.agentName&&(i.agentName=o.agentName,c=!0),o.description!==void 0&&o.description!==i.description&&(i.description=o.description,c=!0),o.cozeIdentity&&o.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=o.cozeIdentity,c=!0,l=!0),o.deployType&&et.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){et.debug("detail sync: no diff",{agentId:e});return}await Xe(i,this.opts.paths),et.info("detail sync: config updated",{agentId:e,identityChanged:l,agentName:i.agentName}),l&&(await ir(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var jf=St(su(),1);import{lstat as Uc,mkdir as Hc,readFile as Uf,readdir as l_,rm as u_,stat as f_,writeFile as qc}from"node:fs/promises";import{dirname as h_,join as kt,normalize as x_,relative as Wc,resolve as Gc,sep as Hf}from"node:path";import{Readable as qf}from"node:stream";import{pipeline as Gf}from"node:stream/promises";import im from"events";import Qe from"fs";import{EventEmitter as Ic}from"node:events";import Uu from"node:stream";import{StringDecoder as sm}from"node:string_decoder";import Gu from"node:path";import gr from"node:fs";import{dirname as wm,parse as _m}from"path";import{EventEmitter as Tm}from"events";import oc from"assert";import{Buffer as Bn}from"buffer";import*as lu from"zlib";import Cm from"zlib";import{posix as dr}from"node:path";import{basename as tw}from"node:path";import Us from"fs";import Ct from"fs";import mu from"path";import{win32 as hw}from"node:path";import Su from"path";import sf from"node:fs";import Dw from"node:assert";import{randomBytes as of}from"node:crypto";import re from"node:fs";import Oe from"node:path";import af from"fs";import Vs from"node:fs";import wi from"node:path";import it from"node:fs";import Bw from"node:fs/promises";import Gs from"node:path";import{join as wf}from"node:path";import rt from"node:fs";import Ef from"node:path";var nm=Object.defineProperty,rm=(t,e)=>{for(var r in e)nm(t,r,{get:e[r],enumerable:!0})},ou=typeof process=="object"&&process?process:{stdout:null,stderr:null},om=t=>!!t&&typeof t=="object"&&(t instanceof Un||t instanceof Uu||am(t)||cm(t)),am=t=>!!t&&typeof t=="object"&&t instanceof Ic&&typeof t.pipe=="function"&&t.pipe!==Uu.Writable.prototype.pipe,cm=t=>!!t&&typeof t=="object"&&t instanceof Ic&&typeof t.write=="function"&&typeof t.end=="function",Ft=Symbol("EOF"),zt=Symbol("maybeEmitEnd"),sn=Symbol("emittedEnd"),hs=Symbol("emittingEnd"),ti=Symbol("emittedError"),xs=Symbol("closed"),au=Symbol("read"),ps=Symbol("flush"),cu=Symbol("flushChunk"),xt=Symbol("encoding"),cr=Symbol("decoder"),Me=Symbol("flowing"),ni=Symbol("paused"),hr=Symbol("resume"),Be=Symbol("buffer"),$e=Symbol("pipes"),Fe=Symbol("bufferLength"),Pa=Symbol("bufferPush"),gs=Symbol("bufferShift"),Ke=Symbol("objectMode"),ve=Symbol("destroyed"),Oa=Symbol("error"),La=Symbol("emitData"),du=Symbol("emitEnd"),Na=Symbol("emitEnd2"),It=Symbol("async"),Ma=Symbol("abort"),ms=Symbol("aborted"),ri=Symbol("signal"),Cn=Symbol("dataListeners"),nt=Symbol("discarded"),ii=t=>Promise.resolve().then(t),dm=t=>t(),lm=t=>t==="end"||t==="finish"||t==="prefinish",um=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,fm=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Hu=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[hr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},hm=class extends Hu{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,r){super(t,e,r),this.proxyErrors=i=>this.dest.emit("error",i),t.on("error",this.proxyErrors)}},xm=t=>!!t.objectMode,pm=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Un=class extends Ic{[Me]=!1;[ni]=!1;[$e]=[];[Be]=[];[Ke];[xt];[It];[cr];[Ft]=!1;[sn]=!1;[hs]=!1;[xs]=!1;[ti]=null;[Fe]=0;[ve]=!1;[ri];[ms]=!1;[Cn]=0;[nt]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");xm(e)?(this[Ke]=!0,this[xt]=null):pm(e)?(this[xt]=e.encoding,this[Ke]=!1):(this[Ke]=!1,this[xt]=null),this[It]=!!e.async,this[cr]=this[xt]?new sm(this[xt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Be]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[$e]});let{signal:r}=e;r&&(this[ri]=r,r.aborted?this[Ma]():r.addEventListener("abort",()=>this[Ma]()))}get bufferLength(){return this[Fe]}get encoding(){return this[xt]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[Ke]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[It]}set async(t){this[It]=this[It]||!!t}[Ma](){this[ms]=!0,this.emit("abort",this[ri]?.reason),this.destroy(this[ri]?.reason)}get aborted(){return this[ms]}set aborted(t){}write(t,e,r){if(this[ms])return!1;if(this[Ft])throw new Error("write after end");if(this[ve])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof e=="function"&&(r=e,e="utf8"),e||(e="utf8");let i=this[It]?ii:dm;if(!this[Ke]&&!Buffer.isBuffer(t)){if(fm(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(um(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Ke]?(this[Me]&&this[Fe]!==0&&this[ps](!0),this[Me]?this.emit("data",t):this[Pa](t),this[Fe]!==0&&this.emit("readable"),r&&i(r),this[Me]):t.length?(typeof t=="string"&&!(e===this[xt]&&!this[cr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[xt]&&(t=this[cr].write(t)),this[Me]&&this[Fe]!==0&&this[ps](!0),this[Me]?this.emit("data",t):this[Pa](t),this[Fe]!==0&&this.emit("readable"),r&&i(r),this[Me]):(this[Fe]!==0&&this.emit("readable"),r&&i(r),this[Me])}read(t){if(this[ve])return null;if(this[nt]=!1,this[Fe]===0||t===0||t&&t>this[Fe])return this[zt](),null;this[Ke]&&(t=null),this[Be].length>1&&!this[Ke]&&(this[Be]=[this[xt]?this[Be].join(""):Buffer.concat(this[Be],this[Fe])]);let e=this[au](t||null,this[Be][0]);return this[zt](),e}[au](t,e){if(this[Ke])this[gs]();else{let r=e;t===r.length||t===null?this[gs]():typeof r=="string"?(this[Be][0]=r.slice(t),e=r.slice(0,t),this[Fe]-=t):(this[Be][0]=r.subarray(t),e=r.subarray(0,t),this[Fe]-=t)}return this.emit("data",e),!this[Be].length&&!this[Ft]&&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[Ft]=!0,this.writable=!1,(this[Me]||!this[ni])&&this[zt](),this}[hr](){this[ve]||(!this[Cn]&&!this[$e].length&&(this[nt]=!0),this[ni]=!1,this[Me]=!0,this.emit("resume"),this[Be].length?this[ps]():this[Ft]?this[zt]():this.emit("drain"))}resume(){return this[hr]()}pause(){this[Me]=!1,this[ni]=!0,this[nt]=!1}get destroyed(){return this[ve]}get flowing(){return this[Me]}get paused(){return this[ni]}[Pa](t){this[Ke]?this[Fe]+=1:this[Fe]+=t.length,this[Be].push(t)}[gs](){return this[Ke]?this[Fe]-=1:this[Fe]-=this[Be][0].length,this[Be].shift()}[ps](t=!1){do;while(this[cu](this[gs]())&&this[Be].length);!t&&!this[Be].length&&!this[Ft]&&this.emit("drain")}[cu](t){return this.emit("data",t),this[Me]}pipe(t,e){if(this[ve])return t;this[nt]=!1;let r=this[sn];return e=e||{},t===ou.stdout||t===ou.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[$e].push(e.proxyErrors?new hm(this,t,e):new Hu(this,t,e)),this[It]?ii(()=>this[hr]()):this[hr]()),t}unpipe(t){let e=this[$e].find(r=>r.dest===t);e&&(this[$e].length===1?(this[Me]&&this[Cn]===0&&(this[Me]=!1),this[$e]=[]):this[$e].splice(this[$e].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[nt]=!1,this[Cn]++,!this[$e].length&&!this[Me]&&this[hr]();else if(t==="readable"&&this[Fe]!==0)super.emit("readable");else if(lm(t)&&this[sn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[ti]){let i=e;this[It]?ii(()=>i.call(this,this[ti])):i.call(this,this[ti])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Cn]=this.listeners("data").length,this[Cn]===0&&!this[nt]&&!this[$e].length&&(this[Me]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Cn]=0,!this[nt]&&!this[$e].length&&(this[Me]=!1)),e}get emittedEnd(){return this[sn]}[zt](){!this[hs]&&!this[sn]&&!this[ve]&&this[Be].length===0&&this[Ft]&&(this[hs]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[xs]&&this.emit("close"),this[hs]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==ve&&this[ve])return!1;if(t==="data")return!this[Ke]&&!r?!1:this[It]?(ii(()=>this[La](r)),!0):this[La](r);if(t==="end")return this[du]();if(t==="close"){if(this[xs]=!0,!this[sn]&&!this[ve])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[ti]=r,super.emit(Oa,r);let o=!this[ri]||this.listeners("error").length?super.emit("error",r):!1;return this[zt](),o}else if(t==="resume"){let o=super.emit("resume");return this[zt](),o}else if(t==="finish"||t==="prefinish"){let o=super.emit(t);return this.removeAllListeners(t),o}let i=super.emit(t,...e);return this[zt](),i}[La](t){for(let r of this[$e])r.dest.write(t)===!1&&this.pause();let e=this[nt]?!1:super.emit("data",t);return this[zt](),e}[du](){return this[sn]?!1:(this[sn]=!0,this.readable=!1,this[It]?(ii(()=>this[Na]()),!0):this[Na]())}[Na](){if(this[cr]){let e=this[cr].end();if(e){for(let r of this[$e])r.dest.write(e);this[nt]||super.emit("data",e)}}for(let e of this[$e])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Ke]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[Ke]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[Ke])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[xt]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(ve,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[nt]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[Ft])return e();let i,o,c=x=>{this.off("data",l),this.off("end",u),this.off(ve,h),e(),o(x)},l=x=>{this.off("error",c),this.off("end",u),this.off(ve,h),this.pause(),i({value:x,done:!!this[Ft]})},u=()=>{this.off("error",c),this.off("data",l),this.off(ve,h),e(),i({done:!0,value:void 0})},h=()=>c(new Error("stream destroyed"));return new Promise((x,w)=>{o=w,i=x,this.once(ve,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[nt]=!1;let t=!1,e=()=>(this.pause(),this.off(Oa,e),this.off(ve,e),this.off("end",e),t=!0,{done:!0,value:void 0}),r=()=>{if(t)return e();let i=this.read();return i===null?e():{done:!1,value:i}};return this.once("end",e),this.once(Oa,e),this.once(ve,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[ve])return t?this.emit("error",t):this.emit(ve),this;this[ve]=!0,this[nt]=!0,this[Be].length=0,this[Fe]=0;let e=this;return typeof e.close=="function"&&!this[xs]&&e.close(),t?this.emit("error",t):this.emit(ve),this}static get isStream(){return om}},gm=Qe.writev,pn=Symbol("_autoClose"),wt=Symbol("_close"),si=Symbol("_ended"),ae=Symbol("_fd"),Ba=Symbol("_finished"),Gt=Symbol("_flags"),Fa=Symbol("_flush"),ic=Symbol("_handleChunk"),sc=Symbol("_makeBuf"),gi=Symbol("_mode"),ws=Symbol("_needDrain"),wr=Symbol("_onerror"),_r=Symbol("_onopen"),za=Symbol("_onread"),xr=Symbol("_onwrite"),gn=Symbol("_open"),mt=Symbol("_path"),ln=Symbol("_pos"),At=Symbol("_queue"),pr=Symbol("_read"),Ua=Symbol("_readSize"),qt=Symbol("_reading"),oi=Symbol("_remain"),Ha=Symbol("_size"),Cs=Symbol("_write"),Rn=Symbol("_writing"),Rs=Symbol("_defaultFlag"),Mn=Symbol("_errored"),Ac=class extends Un{[Mn]=!1;[ae];[mt];[Ua];[qt]=!1;[Ha];[oi];[pn];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[Mn]=!1,this[ae]=typeof e.fd=="number"?e.fd:void 0,this[mt]=t,this[Ua]=e.readSize||16*1024*1024,this[qt]=!1,this[Ha]=typeof e.size=="number"?e.size:1/0,this[oi]=this[Ha],this[pn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[ae]=="number"?this[pr]():this[gn]()}get fd(){return this[ae]}get path(){return this[mt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[gn](){Qe.open(this[mt],"r",(t,e)=>this[_r](t,e))}[_r](t,e){t?this[wr](t):(this[ae]=e,this.emit("open",e),this[pr]())}[sc](){return Buffer.allocUnsafe(Math.min(this[Ua],this[oi]))}[pr](){if(!this[qt]){this[qt]=!0;let t=this[sc]();if(t.length===0)return process.nextTick(()=>this[za](null,0,t));Qe.read(this[ae],t,0,t.length,null,(e,r,i)=>this[za](e,r,i))}}[za](t,e,r){this[qt]=!1,t?this[wr](t):this[ic](e,r)&&this[pr]()}[wt](){if(this[pn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Qe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[wr](t){this[qt]=!0,this[wt](),this.emit("error",t)}[ic](t,e){let r=!1;return this[oi]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[oi]<=0)&&(r=!1,this[wt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[ae]=="number"&&this[pr](),!1;case"error":return this[Mn]?!1:(this[Mn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},mm=class extends Ac{[gn](){let t=!0;try{this[_r](null,Qe.openSync(this[mt],"r")),t=!1}finally{t&&this[wt]()}}[pr](){let t=!0;try{if(!this[qt]){this[qt]=!0;do{let e=this[sc](),r=e.length===0?0:Qe.readSync(this[ae],e,0,e.length,null);if(!this[ic](r,e))break}while(!0);this[qt]=!1}t=!1}finally{t&&this[wt]()}}[wt](){if(this[pn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Qe.closeSync(t),this.emit("close")}}},js=class extends im{readable=!1;writable=!0;[Mn]=!1;[Rn]=!1;[si]=!1;[At]=[];[ws]=!1;[mt];[gi];[pn];[ae];[Rs];[Gt];[Ba]=!1;[ln];constructor(t,e){e=e||{},super(e),this[mt]=t,this[ae]=typeof e.fd=="number"?e.fd:void 0,this[gi]=e.mode===void 0?438:e.mode,this[ln]=typeof e.start=="number"?e.start:void 0,this[pn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[ln]!==void 0?"r+":"w";this[Rs]=e.flags===void 0,this[Gt]=e.flags===void 0?r:e.flags,this[ae]===void 0&&this[gn]()}emit(t,...e){if(t==="error"){if(this[Mn])return!1;this[Mn]=!0}return super.emit(t,...e)}get fd(){return this[ae]}get path(){return this[mt]}[wr](t){this[wt](),this[Rn]=!0,this.emit("error",t)}[gn](){Qe.open(this[mt],this[Gt],this[gi],(t,e)=>this[_r](t,e))}[_r](t,e){this[Rs]&&this[Gt]==="r+"&&t&&t.code==="ENOENT"?(this[Gt]="w",this[gn]()):t?this[wr](t):(this[ae]=e,this.emit("open",e),this[Rn]||this[Fa]())}end(t,e){return t&&this.write(t,e),this[si]=!0,!this[Rn]&&!this[At].length&&typeof this[ae]=="number"&&this[xr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[si]?(this.emit("error",new Error("write() after end()")),!1):this[ae]===void 0||this[Rn]||this[At].length?(this[At].push(t),this[ws]=!0,!1):(this[Rn]=!0,this[Cs](t),!0)}[Cs](t){Qe.write(this[ae],t,0,t.length,this[ln],(e,r)=>this[xr](e,r))}[xr](t,e){t?this[wr](t):(this[ln]!==void 0&&typeof e=="number"&&(this[ln]+=e),this[At].length?this[Fa]():(this[Rn]=!1,this[si]&&!this[Ba]?(this[Ba]=!0,this[wt](),this.emit("finish")):this[ws]&&(this[ws]=!1,this.emit("drain"))))}[Fa](){if(this[At].length===0)this[si]&&this[xr](null,0);else if(this[At].length===1)this[Cs](this[At].pop());else{let t=this[At];this[At]=[],gm(this[ae],t,this[ln],(e,r)=>this[xr](e,r))}}[wt](){if(this[pn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Qe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},qu=class extends js{[gn](){let t;if(this[Rs]&&this[Gt]==="r+")try{t=Qe.openSync(this[mt],this[Gt],this[gi])}catch(e){if(e?.code==="ENOENT")return this[Gt]="w",this[gn]();throw e}else t=Qe.openSync(this[mt],this[Gt],this[gi]);this[_r](null,t)}[wt](){if(this[pn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Qe.closeSync(t),this.emit("close")}}[Cs](t){let e=!0;try{this[xr](null,Qe.writeSync(this[ae],t,0,t.length,this[ln])),e=!1}finally{if(e)try{this[wt]()}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"]]),Em=t=>!!t.sync&&!!t.file,bm=t=>!t.sync&&!!t.file,vm=t=>!!t.sync&&!t.file,Sm=t=>!t.sync&&!t.file,Im=t=>!!t.file,Am=t=>ym.get(t)||t,Tc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=Am(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ii=(t,e,r,i,o)=>Object.assign((c=[],l,u)=>{Array.isArray(c)&&(l=c,c={}),typeof l=="function"&&(u=l,l=void 0),l=l?Array.from(l):[];let h=Tc(c);if(o?.(h,l),Em(h)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(h,l)}else if(bm(h)){let x=e(h,l);return u?x.then(()=>u(),u):x}else if(vm(h)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(h,l)}else if(Sm(h)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(h,l)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),Rm=Cm.constants||{ZLIB_VERNUM:4736},Dt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},Rm)),Dm=Bn.concat,uu=Object.getOwnPropertyDescriptor(Bn,"concat"),km=t=>t,qa=uu?.writable===!0||uu?.set!==void 0?t=>{Bn.concat=t?km:Dm}:t=>{},Fn=Symbol("_superWrite"),_s=class extends Error{code;errno;constructor(t,e){super("zlib: "+t.message,{cause:t}),this.code=t.code,this.errno=t.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+t.message,Error.captureStackTrace(this,e??this.constructor)}get name(){return"ZlibError"}},Ga=Symbol("flushFlag"),Cc=class extends Un{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof lu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new lu[e](t)}catch(r){throw new _s(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 _s(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return oc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Bn.alloc(0),{[Ga]:t})))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(r)}get ended(){return this.#n}[Fn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Bn.from(t,e)),this.#e)return;oc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},qa(!0);let l;try{let h=typeof t[Ga]=="number"?t[Ga]:this.#r;l=this.#t._processChunk(t,h),qa(!1)}catch(h){qa(!1),this.#o(new _s(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 _s(h,this.write)));let u;if(l)if(Array.isArray(l)&&l.length>0){let h=l[0];u=this[Fn](Bn.from(h));for(let x=1;x<l.length;x++)u=this[Fn](l[x])}else u=this[Fn](Bn.from(l));return r&&r(),u}},ju=class extends Cc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Dt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Dt.Z_FINISH,t.fullFlushFlag=Dt.Z_FULL_FLUSH,super(t,e),this.#e=t.level,this.#n=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==t||this.#n!==e){this.flush(Dt.Z_SYNC_FLUSH),oc(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)}}}},Pm=class extends ju{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Fn](t){return this.#e?(this.#e=!1,t[9]=255,super[Fn](t)):super[Fn](t)}},Om=class extends ju{constructor(t){super(t,"Unzip")}},Wu=class extends Cc{constructor(t,e){t=t||{},t.flush=t.flush||Dt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Dt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Dt.BROTLI_OPERATION_FLUSH,super(t,e)}},Lm=class extends Wu{constructor(t){super(t,"BrotliCompress")}},Nm=class extends Wu{constructor(t){super(t,"BrotliDecompress")}},Ku=class extends Cc{constructor(t,e){t=t||{},t.flush=t.flush||Dt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Dt.ZSTD_e_end,t.fullFlushFlag=Dt.ZSTD_e_flush,super(t,e)}},Mm=class extends Ku{constructor(t){super(t,"ZstdCompress")}},Bm=class extends Ku{constructor(t){super(t,"ZstdDecompress")}},Fm=(t,e)=>{if(Number.isSafeInteger(t))t<0?Um(t,e):zm(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},zm=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},Um=(t,e)=>{e[0]=255;var r=!1;t=t*-1;for(var i=e.length;i>1;i--){var o=t&255;t=Math.floor(t/256),r?e[i-1]=$u(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Ju(o))}},Hm=t=>{let e=t[0],r=e===128?Gm(t.subarray(1,t.length)):e===255?qm(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},qm=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),l;i?l=$u(c):c===0?l=c:(i=!0,l=Ju(c)),l!==0&&(r-=l*Math.pow(256,e-o-1))}return r},Gm=t=>{for(var e=t.length,r=0,i=e-1;i>-1;i--){var o=Number(t[i]);o!==0&&(r+=o*Math.pow(256,e-i-1))}return r},$u=t=>(255^t)&255,Ju=t=>(255^t)+1&255,jm={};rm(jm,{code:()=>Rc,isCode:()=>Ds,isName:()=>Wm,name:()=>Ws,normalFsTypes:()=>Vu});var Ds=t=>Ws.has(t),Wm=t=>Rc.has(t),Vu=new Set(["0","","1","2","3","4","5","6","7","D"]),Ws=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),Rc=new Map(Array.from(Ws).map(t=>[t[1],t[0]])),zn=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,r,i){Buffer.isBuffer(t)?this.decode(t,e||0,r,i):t&&this.#n(t)}decode(t,e,r,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");let o=Dn(t,e+156,1),c=Vu.has(o),l=c?r:void 0,u=c?i:void 0;if(this.path=l?.path??Dn(t,e,100),this.mode=l?.mode??u?.mode??un(t,e+100,8),this.uid=l?.uid??u?.uid??un(t,e+108,8),this.gid=l?.gid??u?.gid??un(t,e+116,8),this.size=l?.size??u?.size??un(t,e+124,12),this.mtime=l?.mtime??u?.mtime??ja(t,e+136,12),this.cksum=un(t,e+148,12),u&&this.#n(u,!0),l&&this.#n(l),Ds(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Dn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=l?.uname??u?.uname??Dn(t,e+265,32),this.gname=l?.gname??u?.gname??Dn(t,e+297,32),this.devmaj=l?.devmaj??u?.devmaj??un(t,e+329,8)??0,this.devmin=l?.devmin??u?.devmin??un(t,e+337,8)??0,t[e+475]!==0){let x=Dn(t,e+345,155);this.path=x+"/"+this.path}else{let x=Dn(t,e+345,130);x&&(this.path=x+"/"+this.path),this.atime=r?.atime??i?.atime??ja(t,e+476,12),this.ctime=r?.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(([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=Km(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=kn(t,e,100,o)||this.needPax,this.needPax=fn(t,e+100,8,this.mode)||this.needPax,this.needPax=fn(t,e+108,8,this.uid)||this.needPax,this.needPax=fn(t,e+116,8,this.gid)||this.needPax,this.needPax=fn(t,e+124,12,this.size)||this.needPax,this.needPax=Wa(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=kn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=kn(t,e+265,32,this.uname)||this.needPax,this.needPax=kn(t,e+297,32,this.gname)||this.needPax,this.needPax=fn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=fn(t,e+337,8,this.devmin)||this.needPax,this.needPax=kn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=kn(t,e+345,155,c)||this.needPax:(this.needPax=kn(t,e+345,130,c)||this.needPax,this.needPax=Wa(t,e+476,12,this.atime)||this.needPax,this.needPax=Wa(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,fn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:Ws.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Rc.get(t));if(Ds(e)||e==="Unsupported")this.#e=e;else if(Ds(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Km=(t,e)=>{let r=t,i="",o,c=dr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=dr.dirname(r),r=dr.basename(r);do Buffer.byteLength(r)<=100&&Buffer.byteLength(i)<=e?o=[r,i,!1]:Buffer.byteLength(r)>100&&Buffer.byteLength(i)<=e?o=[r.slice(0,99),i,!0]:(r=dr.join(dr.basename(i),r),i=dr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Dn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),ja=(t,e,r)=>$m(un(t,e,r)),$m=t=>t===void 0?void 0:new Date(t*1e3),un=(t,e,r)=>Number(t[e])&128?Hm(t.subarray(e,e+r)):Vm(t,e,r),Jm=t=>isNaN(t)?void 0:t,Vm=(t,e,r)=>Jm(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),Ym={12:8589934591,8:2097151},fn=(t,e,r,i)=>i===void 0?!1:i>Ym[r]||i<0?(Fm(i,t.subarray(e,e+r)),!0):(Zm(t,e,r,i),!1),Zm=(t,e,r,i)=>t.write(Xm(i,r),e,r,"ascii"),Xm=(t,e)=>Qm(Math.floor(t).toString(8),e),Qm=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Wa=(t,e,r,i)=>i===void 0?!1:fn(t,e,r,i.getTime()/1e3),ew=new Array(156).join("\0"),kn=(t,e,r,i)=>i===void 0?!1:(t.write(i+ew,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),zs=class Yu{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 zn({path:("PaxHeader/"+tw(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:r,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(o),o.write(e,512,r,"utf8");for(let c=r+512;c<o.length;c++)o[c]=0;return o}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let r=this[e],i=r instanceof Date?r.getTime()/1e3:r,o=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+i+`
90
+ `,c=Buffer.byteLength(o),l=Math.floor(Math.log(c)/Math.log(10))+1;return c+l>=Math.pow(10,l)&&(l+=1),l+c+o}static parse(e,r,i=!1){return new Yu(nw(rw(e),r),i)}},nw=(t,e)=>e?Object.assign({},e,t):t,rw=t=>t.replace(/\n$/,"").split(`
91
+ `).reduce(iw,Object.create(null)),iw=(t,e)=>{let r=parseInt(e,10);if(r!==Buffer.byteLength(e)+1)return t;e=e.slice((r+" ").length);let i=e.split("="),o=i.shift();if(!o)return t;let c=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),l=i.join("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(l)*1e3):/^[0-9]+$/.test(l)?+l:l,t},sw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,X=sw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),ow=class extends Un{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,r){switch(super({}),this.pause(),this.extended=e,this.globalExtended=r,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=X(t.path),this.mode=t.mode,this.mode&&(this.mode=this.mode&4095),this.uid=t.uid,this.gid=t.gid,this.uname=t.uname,this.gname=t.gname,this.size=this.remain,this.mtime=t.mtime,this.atime=t.atime,this.ctime=t.ctime,this.linkpath=t.linkpath?X(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#e(e),r&&this.#e(r,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let r=this.remain,i=this.blockRemain;return this.remain=Math.max(0,r-e),this.blockRemain=Math.max(0,i-e),this.ignore?!0:r>=e?super.write(t):super.write(t.subarray(0,r))}#e(t,e=!1){t.path&&(t.path=X(t.path)),t.linkpath&&(t.linkpath=X(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},Ks=(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))},aw=1024*1024,ac=Buffer.from([31,139]),cc=Buffer.from([40,181,47,253]),cw=Math.max(ac.length,cc.length),at=Symbol("state"),Pn=Symbol("writeEntry"),Ut=Symbol("readEntry"),Ka=Symbol("nextEntry"),fu=Symbol("processEntry"),Tt=Symbol("extendedHeader"),ai=Symbol("globalExtendedHeader"),on=Symbol("meta"),hu=Symbol("emitMeta"),xe=Symbol("buffer"),Ht=Symbol("queue"),an=Symbol("ended"),$a=Symbol("emittedEnd"),On=Symbol("emit"),Ae=Symbol("unzip"),ys=Symbol("consumeChunk"),Es=Symbol("consumeChunkSub"),Ja=Symbol("consumeBody"),xu=Symbol("consumeMeta"),pu=Symbol("consumeHeader"),ci=Symbol("consuming"),Va=Symbol("bufferConcat"),bs=Symbol("maybeEnd"),lr=Symbol("writing"),cn=Symbol("aborted"),vs=Symbol("onDone"),Ln=Symbol("sawValidEntry"),Ss=Symbol("sawNullBlock"),Is=Symbol("sawEOF"),gu=Symbol("closeStream"),dw=()=>!0,Si=class extends Tm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Ht]=[];[xe];[Ut];[Pn];[at]="begin";[on]="";[Tt];[ai];[an]=!1;[Ae];[cn]=!1;[Ln];[Ss]=!1;[Is]=!1;[lr]=!1;[ci]=!1;[$a]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(vs,()=>{(this[at]==="begin"||this[Ln]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(vs,t.ondone):this.on(vs,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||aw,this.filter=typeof t.filter=="function"?t.filter:dw;let e=t.file&&(t.file.endsWith(".tar.br")||t.file.endsWith(".tbr"));this.brotli=!(t.gzip||t.zstd)&&t.brotli!==void 0?t.brotli:e?void 0:!1;let r=t.file&&(t.file.endsWith(".tar.zst")||t.file.endsWith(".tzst"));this.zstd=!(t.gzip||t.brotli)&&t.zstd!==void 0?t.zstd:r?!0:void 0,this.on("end",()=>this[gu]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){Ks(this,t,e,r)}[pu](t,e){this[Ln]===void 0&&(this[Ln]=!1);let r;try{r=new zn(t,e,this[Tt],this[ai])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Ss]?(this[Is]=!0,this[at]==="begin"&&(this[at]="header"),this[On]("eof")):(this[Ss]=!0,this[On]("nullBlock"));else if(this[Ss]=!1,!r.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:r});else if(!r.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:r});else{let i=r.type;if(/^(Symbolic)?Link$/.test(i)&&!r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:r});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:r});else{let o=this[Pn]=new ow(r,this[Tt],this[ai]);if(!this[Ln])if(o.remain){let c=()=>{o.invalid||(this[Ln]=!0)};o.on("end",c)}else this[Ln]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[On]("ignoredEntry",o),this[at]="ignore",o.resume()):o.size>0&&(this[on]="",o.on("data",c=>this[on]+=c),this[at]="meta"):(this[Tt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[On]("ignoredEntry",o),this[at]=o.remain?"ignore":"header",o.resume()):(o.remain?this[at]="body":(this[at]="header",o.end()),this[Ut]?this[Ht].push(o):(this[Ht].push(o),this[Ka]())))}}}[gu](){queueMicrotask(()=>this.emit("close"))}[fu](t){let e=!0;if(!t)this[Ut]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[Ut]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Ka]()),e=!1);return e}[Ka](){do;while(this[fu](this[Ht].shift()));if(this[Ht].length===0){let t=this[Ut];!t||t.flowing||t.size===t.remain?this[lr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Ja](t,e){let r=this[Pn];if(!r)throw new Error("attempt to consume body without entry??");let i=r.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return r.write(o),r.blockRemain||(this[at]="header",this[Pn]=void 0,r.end()),o.length}[xu](t,e){let r=this[Pn],i=this[Ja](t,e);return!this[Pn]&&r&&this[hu](r),i}[On](t,e,r){this[Ht].length===0&&!this[Ut]?this.emit(t,e,r):this[Ht].push([t,e,r])}[hu](t){switch(this[On]("meta",this[on]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Tt]=zs.parse(this[on],this[Tt],!1);break;case"GlobalExtendedHeader":this[ai]=zs.parse(this[on],this[ai],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Tt]??Object.create(null);this[Tt]=e,e.path=this[on].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Tt]||Object.create(null);this[Tt]=e,e.linkpath=this[on].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[cn]=!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[cn])return r?.(),!1;if((this[Ae]===void 0||this.brotli===void 0&&this[Ae]===!1)&&t){if(this[xe]&&(t=Buffer.concat([this[xe],t]),this[xe]=void 0),t.length<cw)return this[xe]=t,r?.(),!0;for(let l=0;this[Ae]===void 0&&l<ac.length;l++)t[l]!==ac[l]&&(this[Ae]=!1);let o=!1;if(this[Ae]===!1&&this.zstd!==!1){o=!0;for(let l=0;l<cc.length;l++)if(t[l]!==cc[l]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Ae]===!1&&c)if(t.length<512)if(this[an])this.brotli=!0;else return this[xe]=t,r?.(),!0;else try{new zn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Ae]===void 0||this[Ae]===!1&&(this.brotli||o)){let l=this[an];this[an]=!1,this[Ae]=this[Ae]===void 0?new Om({}):o?new Bm({}):new Nm({}),this[Ae].on("data",h=>this[ys](h)),this[Ae].on("error",h=>this.abort(h)),this[Ae].on("end",()=>{this[an]=!0,this[ys]()}),this[lr]=!0;let u=!!this[Ae][l?"end":"write"](t);return this[lr]=!1,r?.(),u}}this[lr]=!0,this[Ae]?this[Ae].write(t):this[ys](t),this[lr]=!1;let i=this[Ht].length>0?!1:this[Ut]?this[Ut].flowing:!0;return!i&&this[Ht].length===0&&this[Ut]?.once("drain",()=>this.emit("drain")),r?.(),i}[Va](t){t&&!this[cn]&&(this[xe]=this[xe]?Buffer.concat([this[xe],t]):t)}[bs](){if(this[an]&&!this[$a]&&!this[cn]&&!this[ci]){this[$a]=!0;let t=this[Pn];if(t&&t.blockRemain){let e=this[xe]?this[xe].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[xe]&&t.write(this[xe]),t.end()}this[On](vs)}}[ys](t){if(this[ci]&&t)this[Va](t);else if(!t&&!this[xe])this[bs]();else if(t){if(this[ci]=!0,this[xe]){this[Va](t);let e=this[xe];this[xe]=void 0,this[Es](e)}else this[Es](t);for(;this[xe]&&this[xe]?.length>=512&&!this[cn]&&!this[Is];){let e=this[xe];this[xe]=void 0,this[Es](e)}this[ci]=!1}(!this[xe]||this[an])&&this[bs]()}[Es](t){let e=0,r=t.length;for(;e+512<=r&&!this[cn]&&!this[Is];)switch(this[at]){case"begin":case"header":this[pu](t,e),e+=512;break;case"ignore":case"body":e+=this[Ja](t,e);break;case"meta":e+=this[xu](t,e);break;default:throw new Error("invalid state: "+this[at])}e<r&&(this[xe]=this[xe]?Buffer.concat([t.subarray(e),this[xe]]):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[cn]||(this[Ae]?(t&&this[Ae].write(t),this[Ae].end()):(this[an]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[bs]())),this}},mi=t=>{let e=t.length-1,r=-1;for(;e>-1&&t.charAt(e)==="/";)r=e,e--;return r===-1?t:t.slice(0,r)},lw=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},Zu=(t,e)=>{let r=new Map(e.map(c=>[mi(c),!0])),i=t.filter,o=(c,l="")=>{let u=l||_m(c).root||".",h;if(c===u)h=!1;else{let x=r.get(c);h=x!==void 0?x:o(wm(c),u)}return r.set(c,h),h};t.filter=i?(c,l)=>i(c,l)&&o(mi(c)):c=>o(mi(c))},uw=t=>{let e=new Si(t),r=t.file,i;try{i=gr.openSync(r,"r");let o=gr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let l=Buffer.allocUnsafe(o.size),u=gr.readSync(i,l,0,o.size,0);e.end(u===l.byteLength?l:l.subarray(0,u))}else{let l=0,u=Buffer.allocUnsafe(c);for(;l<o.size;){let h=gr.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{gr.closeSync(i)}catch{}}},fw=(t,e)=>{let r=new Si(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("end",c),gr.stat(o,(u,h)=>{if(u)l(u);else{let x=new Ac(o,{readSize:i,size:h.size});x.on("error",l),x.pipe(r)}})})},yr=Ii(uw,fw,t=>new Si(t),t=>new Si(t),(t,e)=>{e?.length&&Zu(t,e),t.noResume||lw(t)}),Xu=(t,e,r)=>(t&=4095,r&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t),{isAbsolute:xw,parse:wu}=hw,Dc=t=>{let e="",r=wu(t);for(;xw(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=wu(t)}return[e,t]},$s=["|","<",">","?",":"],kc=$s.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),pw=new Map($s.map((t,e)=>[t,kc[e]])),gw=new Map(kc.map((t,e)=>[t,$s[e]])),_u=t=>$s.reduce((e,r)=>e.split(r).join(pw.get(r)),t),mw=t=>kc.reduce((e,r)=>e.split(r).join(gw.get(r)),t),Qu=(t,e)=>e?(t=X(t).replace(/^\.(\/|$)/,""),mi(e)+"/"+t):X(t),ww=16*1024*1024,yu=Symbol("process"),Eu=Symbol("file"),bu=Symbol("directory"),dc=Symbol("symlink"),vu=Symbol("hardlink"),di=Symbol("header"),ks=Symbol("read"),lc=Symbol("lstat"),Ps=Symbol("onlstat"),uc=Symbol("onread"),fc=Symbol("onreadlink"),hc=Symbol("openfile"),xc=Symbol("onopenfile"),hn=Symbol("close"),Hs=Symbol("mode"),pc=Symbol("awaitDrain"),Ya=Symbol("ondrain"),Rt=Symbol("prefix"),ef=class extends Un{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let r=Tc(e);super(),this.path=X(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||ww,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=X(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?X(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,l]=Dc(this.path);c&&typeof l=="string"&&(this.path=l,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=mw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=X(r.absolute||mu.resolve(this.cwd,t)),this.path===""&&(this.path="./"),i&&this.warn("TAR_ENTRY_INFO",`stripping ${i} from absolute path`,{entry:this,path:i+this.path});let o=this.statCache.get(this.absolute);o?this[Ps](o):this[lc]()}warn(t,e,r={}){return Ks(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[lc](){Ct.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Ps](e)})}[Ps](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=Ew(t),this.emit("stat",t),this[yu]()}[yu](){switch(this.type){case"File":return this[Eu]();case"Directory":return this[bu]();case"SymbolicLink":return this[dc]();default:return this.end()}}[Hs](t){return Xu(t,this.type==="Directory",this.portable)}[Rt](t){return Qu(t,this.prefix)}[di](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new zn({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this[Hs](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)}[bu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[di](),this.end()}[dc](){Ct.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[fc](e)})}[fc](t){this.linkpath=X(t),this[di](),this.end()}[vu](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=X(mu.relative(this.cwd,t)),this.stat.size=0,this[di](),this.end()}[Eu](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){let t=`${this.stat.dev}:${this.stat.ino}`,e=this.linkCache.get(t);if(e?.indexOf(this.cwd)===0)return this[vu](e);this.linkCache.set(t,this.absolute)}if(this[di](),this.stat.size===0)return this.end();this[hc]()}[hc](){Ct.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[xc](e)})}[xc](t){if(this.fd=t,this.#e)return this[hn]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[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");Ct.read(t,e,r,i,o,(c,l)=>{if(c)return this[hn](()=>this.emit("error",c));this[uc](l)})}[hn](t=()=>{}){this.fd!==void 0&&Ct.close(this.fd,t)}[uc](t){if(t<=0&&this.remain>0){let r=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[hn](()=>this.emit("error",r))}if(t>this.remain){let r=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[hn](()=>this.emit("error",r))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let r=t;r<this.length&&t<this.blockRemain;r++)this.buf[r+this.offset]=0,t++,this.remain++;let e=this.offset===0&&t===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+t);this.write(e)?this[Ya]():this[pc](()=>this[Ya]())}[pc](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)}[Ya](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[hn](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[ks]()}},_w=class extends ef{sync=!0;[lc](){this[Ps](Ct.lstatSync(this.absolute))}[dc](){this[fc](Ct.readlinkSync(this.absolute))}[hc](){this[xc](Ct.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 l=Ct.readSync(e,r,i,o,c);this[uc](l),t=!1}finally{if(t)try{this[hn](()=>{})}catch{}}}[pc](t){t()}[hn](t=()=>{}){this.fd!==void 0&&Ct.closeSync(this.fd),t()}},yw=class extends Un{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,r={}){return Ks(this,t,e,r)}constructor(t,e={}){let r=Tc(e);super(),this.preservePaths=!!r.preservePaths,this.portable=!!r.portable,this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.onWriteEntry=r.onWriteEntry,this.readEntry=t;let{type:i}=t;if(i==="Unsupported")throw new Error("writing entry that should be ignored");this.type=i,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=r.prefix,this.path=X(t.path),this.mode=t.mode!==void 0?this[Hs](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?X(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[l,u]=Dc(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 zn({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 Qu(t,this.prefix)}[Hs](t){return Xu(t,this.type==="Directory",this.portable)}write(t,e,r){typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8"));let i=t.length;if(i>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=i,super.write(t,r)}end(t,e,r){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e??"utf8")),r&&this.once("finish",r),t?super.end(t,r):super.end(r),this}},Ew=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",bw=class mr{tail;head;length=0;static create(e=[]){return new mr(e)}constructor(e=[]){for(let r of e)this.push(r)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let r=e.next,i=e.prev;return r&&(r.prev=i),i&&(i.next=r),e===this.head&&(this.head=r),e===this.tail&&(this.tail=i),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,r}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let r=this.head;e.list=this,e.next=r,r&&(r.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let r=this.tail;e.list=this,e.prev=r,r&&(r.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let r=0,i=e.length;r<i;r++)Sw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)Iw(this,e[r]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,r=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,r.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,r=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,r.list=void 0,this.length--,e}forEach(e,r){r=r||this;for(let i=this.head,o=0;i;o++)e.call(r,i.value,o,this),i=i.next}forEachReverse(e,r){r=r||this;for(let i=this.tail,o=this.length-1;i;o--)e.call(r,i.value,o,this),i=i.prev}get(e){let r=0,i=this.head;for(;i&&r<e;r++)i=i.next;if(r===e&&i)return i.value}getReverse(e){let r=0,i=this.tail;for(;i&&r<e;r++)i=i.prev;if(r===e&&i)return i.value}map(e,r){r=r||this;let i=new mr;for(let o=this.head;o;)i.push(e.call(r,o.value,this)),o=o.next;return i}mapReverse(e,r){r=r||this;var i=new mr;for(let o=this.tail;o;)i.push(e.call(r,o.value,this)),o=o.prev;return i}reduce(e,r){let i,o=this.head;if(arguments.length>1)i=r;else if(this.head)o=this.head.next,i=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var c=0;o;c++)i=e(i,o.value,c),o=o.next;return i}reduceReverse(e,r){let i,o=this.tail;if(arguments.length>1)i=r;else if(this.tail)o=this.tail.prev,i=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let c=this.length-1;o;c--)i=e(i,o.value,c),o=o.prev;return i}toArray(){let e=new Array(this.length);for(let r=0,i=this.head;i;r++)e[r]=i.value,i=i.next;return e}toArrayReverse(){let e=new Array(this.length);for(let r=0,i=this.tail;i;r++)e[r]=i.value,i=i.prev;return e}slice(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new mr;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.head,c=0;for(c=0;o&&c<e;c++)o=o.next;for(;o&&c<r;c++,o=o.next)i.push(o.value);return i}sliceReverse(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new mr;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.length,c=this.tail;for(;c&&o>r;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,r=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let l=0;o&&l<e;l++)o=o.next;let c=[];for(let l=0;o&&l<r;l++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let l of i)o=vw(this,o,l);return c}reverse(){let e=this.head,r=this.tail;for(let i=e;i;i=i.prev){let o=i.prev;i.prev=i.next,i.next=o}return this.head=r,this.tail=e,this}};function vw(t,e,r){let i=e,o=e?e.next:t.head,c=new Pc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function Sw(t,e){t.tail=new Pc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function Iw(t,e){t.head=new Pc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Pc=class{list;next;prev;value;constructor(t,e,r,i){this.list=i,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,r?(r.prev=this,this.next=r):this.next=void 0}},Iu=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Au=Buffer.alloc(1024),Os=Symbol("onStat"),li=Symbol("ended"),pt=Symbol("queue"),ui=Symbol("pendingLinks"),dn=Symbol("current"),Nn=Symbol("process"),fi=Symbol("processing"),As=Symbol("processJob"),gt=Symbol("jobs"),Za=Symbol("jobDone"),Ls=Symbol("addFSEntry"),Tu=Symbol("addTarEntry"),gc=Symbol("stat"),mc=Symbol("readdir"),Ns=Symbol("onreaddir"),Ms=Symbol("pipe"),Cu=Symbol("entry"),Xa=Symbol("entryOpt"),Bs=Symbol("writeEntryClass"),tf=Symbol("write"),Qa=Symbol("ondrain"),Js=class extends Un{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Bs];onWriteEntry;[pt];[ui]=new Map;[gt]=0;[fi]=!1;[li]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=X(t.prefix||""),this.linkCache=t.linkCache||new Map,this.statCache=t.statCache||new Map,this.readdirCache=t.readdirCache||new Map,this.onWriteEntry=t.onWriteEntry,this[Bs]=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 Pm(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new Lm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new Mm(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[Qa]()),this.on("resume",()=>e.resume())}else this.on("drain",this[Qa]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[pt]=new bw,this[gt]=0,this.jobs=Number(t.jobs)||4,this[fi]=!1,this[li]=!1}[tf](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&this.add(t),this[li]=!0,this[Nn](),r&&r(),this}write(t){if(this[li])throw new Error("write after end");return typeof t=="string"?this[Ls](t):this[Tu](t),this.flowing}[Tu](t){let e=X(Su.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Iu(t.path,e);r.entry=new yw(t,this[Xa](r)),r.entry.on("end",()=>this[Za](r)),this[gt]+=1,this[pt].push(r)}this[Nn]()}[Ls](t){let e=X(Su.resolve(this.cwd,t));this[pt].push(new Iu(t,e)),this[Nn]()}[gc](t){t.pending=!0,this[gt]+=1;let e=this.follow?"stat":"lstat";Us[e](t.absolute,(r,i)=>{t.pending=!1,this[gt]-=1,r?this.emit("error",r):this[Os](t,i)})}[Os](t,e){if(this.statCache.set(t.absolute,e),t.stat=e,!this.filter(t.path,e))t.ignore=!0;else if(e.isFile()&&e.nlink>1&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync)if(t===this[dn])this[As](t);else{let r=`${e.dev}:${e.ino}`,i=this[ui].get(r);i?i.push(t):this[ui].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Nn]()}[mc](t){t.pending=!0,this[gt]+=1,Us.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[gt]-=1,e)return this.emit("error",e);this[Ns](t,r)})}[Ns](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Nn]()}[Nn](){if(!this[fi]){this[fi]=!0;for(let t=this[pt].head;t&&this[gt]<this.jobs;t=t.next)if(this[As](t.value),t.value.ignore){let e=t.next;this[pt].removeNode(t),t.next=e}this[fi]=!1,this[li]&&this[pt].length===0&&this[gt]===0&&(this.zip?this.zip.end(Au):(super.write(Au),super.end()))}}get[dn](){return this[pt]&&this[pt].head&&this[pt].head.value}[Za](t){this[pt].shift(),this[gt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[ui].get(r);if(i){this[ui].delete(r);for(let o of i)o.pending=!1,this[As](o)}}this[Nn]()}[As](t){if(t.pending&&t.pendingLink&&t===this[dn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[dn]&&!t.piped&&this[Ms](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Os](t,e):this[gc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[Ns](t,e):this[mc](t),!t.readdir)return}if(t.entry=this[Cu](t),!t.entry){t.ignore=!0;return}t===this[dn]&&!t.piped&&this[Ms](t)}}}[Xa](t){return{onwarn:(e,r,i)=>this.warn(e,r,i),noPax:this.noPax,cwd:this.cwd,absolute:t.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[Cu](t){this[gt]+=1;try{return new this[Bs](t.path,this[Xa](t)).on("end",()=>this[Za](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[Qa](){this[dn]&&this[dn].entry&&this[dn].entry.resume()}[Ms](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ls](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={}){Ks(this,t,e,r)}},Oc=class extends Js{sync=!0;constructor(t){super(t),this[Bs]=_w}pause(){}resume(){}[gc](t){let e=this.follow?"statSync":"lstatSync";this[Os](t,Us[e](t.absolute))}[mc](t){this[Ns](t,Us.readdirSync(t.absolute))}[Ms](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ls](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[tf](i)})}},Aw=(t,e)=>{let r=new Oc(t),i=new qu(t.file,{mode:t.mode||438});r.pipe(i),nf(r,e)},Tw=(t,e)=>{let r=new Js(t),i=new js(t.file,{mode:t.mode||438});r.pipe(i);let o=new Promise((c,l)=>{i.on("error",l),i.on("close",c),r.on("error",l)});return rf(r,e).catch(c=>r.emit("error",c)),o},nf=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?yr({file:Gu.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},rf=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await yr({file:Gu.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},Cw=(t,e)=>{let r=new Oc(t);return nf(r,e),r},Rw=(t,e)=>{let r=new Js(t);return rf(r,e).catch(i=>r.emit("error",i)),r},j2=Ii(Aw,Tw,Cw,Rw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),kw=process.env.__FAKE_PLATFORM__||process.platform,cf=kw==="win32",{O_CREAT:df,O_NOFOLLOW:Ru,O_TRUNC:lf,O_WRONLY:uf}=af.constants,ff=Number(process.env.__FAKE_FS_O_FILENAME__)||af.constants.UV_FS_O_FILEMAP||0,Pw=cf&&!!ff,Ow=512*1024,Lw=ff|lf|df|uf,Du=!cf&&typeof Ru=="number"?Ru|lf|df|uf:null,hf=Du!==null?()=>Du:Pw?t=>t<Ow?Lw:"w":()=>"w",wc=(t,e,r)=>{try{return Vs.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},qs=(t,e,r,i)=>{Vs.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},Nw=(t,e,r,i,o)=>{if(e.isDirectory())xf(wi.resolve(t,e.name),r,i,c=>{if(c)return o(c);let l=wi.resolve(t,e.name);qs(l,r,i,o)});else{let c=wi.resolve(t,e.name);qs(c,r,i,o)}},xf=(t,e,r,i)=>{Vs.readdir(t,{withFileTypes:!0},(o,c)=>{if(o){if(o.code==="ENOENT")return i();if(o.code!=="ENOTDIR"&&o.code!=="ENOTSUP")return i(o)}if(o||!c.length)return qs(t,e,r,i);let l=c.length,u=null,h=x=>{if(!u){if(x)return i(u=x);if(--l===0)return qs(t,e,r,i)}};for(let x of c)Nw(t,x,e,r,h)})},Mw=(t,e,r,i)=>{e.isDirectory()&&pf(wi.resolve(t,e.name),r,i),wc(wi.resolve(t,e.name),r,i)},pf=(t,e,r)=>{let i;try{i=Vs.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return wc(t,e,r);throw c}for(let o of i)Mw(t,o,e,r);return wc(t,e,r)},gf=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"}},Ys=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"}},Fw=(t,e)=>{it.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new gf(t,r?.code||"ENOTDIR")),e(r)})},zw=(t,e,r)=>{t=X(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,w=e.unlink,_=X(e.cwd),S=(v,A)=>{v?r(v):A&&h?xf(A,l,u,I=>S(I)):c?it.chmod(t,o,r):r()};if(t===_)return Fw(t,S);if(x)return Bw.mkdir(t,{mode:o,recursive:!0}).then(v=>S(null,v??void 0),S);let E=X(Gs.relative(_,t)).split("/");_c(_,E,o,w,_,void 0,S)},_c=(t,e,r,i,o,c,l)=>{if(e.length===0)return l(null,c);let u=e.shift(),h=X(Gs.resolve(t+"/"+u));it.mkdir(h,r,mf(h,e,r,i,o,c,l))},mf=(t,e,r,i,o,c,l)=>u=>{u?it.lstat(t,(h,x)=>{if(h)h.path=h.path&&X(h.path),l(h);else if(x.isDirectory())_c(t,e,r,i,o,c,l);else if(i)it.unlink(t,w=>{if(w)return l(w);it.mkdir(t,r,mf(t,e,r,i,o,c,l))});else{if(x.isSymbolicLink())return l(new Ys(t,t+"/"+e.join("/")));l(u)}}):(c=c||t,_c(t,e,r,i,o,c,l))},Uw=t=>{let e=!1,r;try{e=it.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new gf(t,r??"ENOTDIR")}},Hw=(t,e)=>{t=X(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,l=e.gid,u=typeof c=="number"&&typeof l=="number"&&(c!==e.processUid||l!==e.processGid),h=e.preserve,x=e.unlink,w=X(e.cwd),_=v=>{v&&u&&pf(v,c,l),o&&it.chmodSync(t,i)};if(t===w)return Uw(w),_();if(h)return _(it.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=X(Gs.relative(w,t)).split("/"),E;for(let v=S.shift(),A=w;v&&(A+="/"+v);v=S.shift()){A=X(Gs.resolve(A));try{it.mkdirSync(A,i),E=E||A}catch{let I=it.lstatSync(A);if(I.isDirectory())continue;if(x){it.unlinkSync(A),it.mkdirSync(A,i),E=E||A;continue}else if(I.isSymbolicLink())return new Ys(A,A+"/"+S.join("/"))}}return _(E)},ec=Object.create(null),ku=1e4,ur=new Set,qw=t=>{ur.has(t)?ur.delete(t):ec[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),ur.add(t);let e=ec[t],r=ur.size-ku;if(r>ku/10){for(let i of ur)if(ur.delete(i),delete ec[i],--r<=0)break}return e},Gw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,jw=Gw==="win32",Ww=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=wf(i,r)),e.push(r||"/"),e},[]),Kw=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=jw?["win32 parallelization disabled"]:t.map(i=>mi(wf(qw(i))));let r=new Set(t.map(i=>Ww(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let l=this.#e.get(c);if(!l||l?.[0]!==t)continue;let u=l[1];if(!u){this.#e.delete(c);continue}if(l.shift(),typeof u=="function")o.add(u);else for(let h of u)o.add(h)}for(let c of i){let l=this.#e.get(c),u=l?.[0];if(!(!l||!(u instanceof Set)))if(u.size===1&&l.length===1){this.#e.delete(c);continue}else if(u.size===1){l.shift();let h=l[0];typeof h=="function"&&o.add(h)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},$w=()=>process.umask(),Pu=Symbol("onEntry"),yc=Symbol("checkFs"),Ou=Symbol("checkFs2"),Ec=Symbol("isReusable"),ct=Symbol("makeFs"),bc=Symbol("file"),vc=Symbol("directory"),Fs=Symbol("link"),Lu=Symbol("symlink"),Nu=Symbol("hardlink"),pi=Symbol("ensureNoSymlink"),Mu=Symbol("unsupported"),Bu=Symbol("checkPath"),tc=Symbol("stripAbsolutePath"),xn=Symbol("mkdir"),ze=Symbol("onError"),Ts=Symbol("pending"),Fu=Symbol("pend"),fr=Symbol("unpend"),nc=Symbol("ended"),rc=Symbol("maybeClose"),Sc=Symbol("skip"),_i=Symbol("doChown"),yi=Symbol("uid"),Ei=Symbol("gid"),bi=Symbol("checkedCwd"),Jw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,vi=Jw==="win32",Vw=1024,Yw=(t,e)=>{if(!vi)return re.unlink(t,e);let r=t+".DELETE."+of(16).toString("hex");re.rename(t,r,i=>{if(i)return e(i);re.unlink(r,e)})},Zw=t=>{if(!vi)return re.unlinkSync(t);let e=t+".DELETE."+of(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},zu=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Lc=class extends Si{[nc]=!1;[bi]=!1;[Ts]=0;reservations=new Kw;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[nc]=!0,this[rc]()},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:Vw,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||vi,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=X(Oe.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:$w():0,this.umask=typeof t.umask=="number"?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.on("entry",e=>this[Pu](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[rc](){this[nc]&&this[Ts]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[tc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Dc(r),l=c.replaceAll(/\\/g,"/").split("/");if(l.includes("..")||vi&&/^[a-z]:\.\.$/i.test(l[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let u=Oe.posix.dirname(t.path),h=Oe.posix.normalize(Oe.posix.join(u,l.join("/")));if(h.startsWith("../")||h==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:r}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:r})),!0}[Bu](t){let e=X(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=X(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}r.splice(0,this.strip),t.path=r.join("/")}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[tc](t,"path")||!this[tc](t,"linkpath"))return!1;if(t.absolute=Oe.isAbsolute(t.path)?X(Oe.resolve(t.path)):X(Oe.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:X(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=Oe.win32.parse(String(t.absolute));t.absolute=i+_u(String(t.absolute).slice(i.length));let{root:o}=Oe.win32.parse(t.path);t.path=o+_u(t.path.slice(o.length))}return!0}[Pu](t){if(!this[Bu](t))return t.resume();switch(Dw.equal(typeof t.absolute,"string"),t.type){case"Directory":case"GNUDumpDir":t.mode&&(t.mode=t.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[yc](t);default:return this[Mu](t)}}[ze](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[fr](),e.resume())}[xn](t,e,r){zw(X(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},r)}[_i](t){return this.forceChown||this.preserveOwner&&(typeof t.uid=="number"&&t.uid!==this.processUid||typeof t.gid=="number"&&t.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[yi](t){return zu(this.uid,t.uid,this.processUid)}[Ei](t){return zu(this.gid,t.gid,this.processGid)}[bc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new js(String(t.absolute),{flags:hf(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[ze](u,t),e()});let o=1,c=u=>{if(u){i.fd&&re.close(i.fd,()=>{}),this[ze](u,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,h=>{h?this[ze](h,t):this[fr](),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,w=t.mtime;re.futimes(h,x,w,_=>_?re.utimes(u,x,w,S=>c(S&&_)):c())}if(typeof h=="number"&&this[_i](t)){o++;let x=this[yi](t),w=this[Ei](t);typeof x=="number"&&typeof w=="number"&&re.fchown(h,x,w,_=>_?re.chown(u,x,w,S=>c(S&&_)):c())}c()});let l=this.transform&&this.transform(t)||t;l!==t&&(l.on("error",u=>{this[ze](u,t),e()}),t.pipe(l)),l.pipe(i)}[vc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[xn](String(t.absolute),r,i=>{if(i){this[ze](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[fr](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[_i](t)&&(o++,re.chown(String(t.absolute),Number(this[yi](t)),Number(this[Ei](t)),c)),c()})}[Mu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Lu](t,e){let r=X(Oe.relative(this.cwd,Oe.resolve(Oe.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[pi](t,this.cwd,r,()=>this[Fs](t,String(t.linkpath),"symlink",e),i=>{this[ze](i,t),e()})}[Nu](t,e){let r=X(Oe.resolve(this.cwd,String(t.linkpath))),i=X(String(t.linkpath)).split("/");this[pi](t,this.cwd,i,()=>this[Fs](t,r,"link",e),o=>{this[ze](o,t),e()})}[pi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let l=Oe.resolve(e,c);re.lstat(l,(u,h)=>{if(u)return i();if(h?.isSymbolicLink())return o(new Ys(l,Oe.resolve(l,r.join("/"))));this[pi](t,l,r,i,o)})}[Fu](){this[Ts]++}[fr](){this[Ts]--,this[rc]()}[Sc](t){this[fr](),t.resume()}[Ec](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!vi}[yc](t){this[Fu]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Ou](t,r))}[Ou](t,e){let r=l=>{e(l)},i=()=>{this[xn](this.cwd,this.dmode,l=>{if(l){this[ze](l,t),r();return}this[bi]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let l=X(Oe.dirname(String(t.absolute)));if(l!==this.cwd)return this[xn](l,this.dmode,u=>{if(u){this[ze](u,t),r();return}c()})}c()},c=()=>{re.lstat(String(t.absolute),(l,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Sc](t),r();return}if(l||this[Ec](t,u))return this[ct](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let h=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,x=w=>this[ct](w??null,t,r);return h?re.chmod(String(t.absolute),Number(t.mode),x):x()}if(t.absolute!==this.cwd)return re.rmdir(String(t.absolute),h=>this[ct](h??null,t,r))}if(t.absolute===this.cwd)return this[ct](null,t,r);Yw(String(t.absolute),h=>this[ct](h??null,t,r))})};this[bi]?o():i()}[ct](t,e,r){if(t){this[ze](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[bc](e,r);case"Link":return this[Nu](e,r);case"SymbolicLink":return this[Lu](e,r);case"Directory":case"GNUDumpDir":return this[vc](e,r)}}[Fs](t,e,r,i){re[r](e,String(t.absolute),o=>{o?this[ze](o,t):(this[fr](),t.resume()),i()})}},hi=t=>{try{return[null,t()]}catch(e){return[e,null]}},_f=class extends Lc{sync=!0;[ct](t,e){return super[ct](t,e,()=>{})}[yc](t){if(!this[bi]){let o=this[xn](this.cwd,this.dmode);if(o)return this[ze](o,t);this[bi]=!0}if(t.absolute!==this.cwd){let o=X(Oe.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[xn](o,this.dmode);if(c)return this[ze](c,t)}}let[e,r]=hi(()=>re.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Sc](t);if(e||this[Ec](t,r))return this[ct](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[l]=c?hi(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ct](l,t)}let[o]=hi(()=>re.rmdirSync(String(t.absolute)));this[ct](o,t)}let[i]=t.absolute===this.cwd?[]:hi(()=>Zw(String(t.absolute)));this[ct](i,t)}[bc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=l=>{let u;try{re.closeSync(o)}catch(h){u=h}(l||u)&&this[ze](l||u,t),e()},o;try{o=re.openSync(String(t.absolute),hf(t.size),r)}catch(l){return i(l)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",l=>this[ze](l,t)),t.pipe(c)),c.on("data",l=>{try{re.writeSync(o,l,0,l.length)}catch(u){i(u)}}),c.on("end",()=>{let l=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,h=t.mtime;try{re.futimesSync(o,u,h)}catch(x){try{re.utimesSync(String(t.absolute),u,h)}catch{l=x}}}if(this[_i](t)){let u=this[yi](t),h=this[Ei](t);try{re.fchownSync(o,Number(u),Number(h))}catch(x){try{re.chownSync(String(t.absolute),Number(u),Number(h))}catch{l=l||x}}}i(l)})}[vc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[xn](String(t.absolute),r);if(i){this[ze](i,t),e();return}if(t.mtime&&!this.noMtime)try{re.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[_i](t))try{re.chownSync(String(t.absolute),Number(this[yi](t)),Number(this[Ei](t)))}catch{}e(),t.resume()}[xn](t,e){try{return Hw(X(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(r){return r}}[pi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let l of r){c=Oe.resolve(c,l);let[u,h]=hi(()=>re.lstatSync(c));if(u)return i();if(h.isSymbolicLink())return o(new Ys(c,Oe.resolve(e,r.join("/"))))}i()}[Fs](t,e,r,i){let o=`${r}Sync`;try{re[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[ze](c,t)}}},Xw=t=>{let e=new _f(t),r=t.file,i=sf.statSync(r),o=t.maxReadSize||16*1024*1024;new mm(r,{readSize:o,size:i.size}).pipe(e)},Qw=(t,e)=>{let r=new Lc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("close",c),sf.stat(o,(u,h)=>{if(u)l(u);else{let x=new Ac(o,{readSize:i,size:h.size});x.on("error",l),x.pipe(r)}})})},yf=Ii(Xw,Qw,t=>new _f(t),t=>new Lc(t),(t,e)=>{e?.length&&Zu(t,e)}),e_=(t,e)=>{let r=new Oc(t),i=!0,o,c;try{try{o=rt.openSync(t.file,"r+")}catch(h){if(h?.code==="ENOENT")o=rt.openSync(t.file,"w+");else throw h}let l=rt.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<l.size;c+=512){for(let w=0,_=0;w<512;w+=_){if(_=rt.readSync(o,u,w,u.length-w,c+w),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!_)break e}let h=new zn(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,t_(t,r,c,o,e)}finally{if(i)try{rt.closeSync(o)}catch{}}},t_=(t,e,r,i,o)=>{let c=new qu(t.file,{fd:i,start:r});e.pipe(c),r_(e,o)},n_=(t,e)=>{e=Array.from(e);let r=new Js(t),i=(o,c,l)=>{let u=(S,E)=>{S?rt.close(o,v=>l(S)):l(null,E)},h=0;if(c===0)return u(null,0);let x=0,w=Buffer.alloc(512),_=(S,E)=>{if(S||E===void 0)return u(S);if(x+=E,x<512&&E)return rt.read(o,w,x,w.length-x,h+x,_);if(h===0&&w[0]===31&&w[1]===139)return u(new Error("cannot append to compressed archives"));if(x<512)return u(null,h);let v=new zn(w);if(!v.cksumValid)return u(null,h);let A=512*Math.ceil((v.size??0)/512);if(h+A+512>c||(h+=A+512,h>=c))return u(null,h);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),x=0,rt.read(o,w,0,512,h,_)};rt.read(o,w,0,512,h,_)};return new Promise((o,c)=>{r.on("error",c);let l="r+",u=(h,x)=>{if(h&&h.code==="ENOENT"&&l==="r+")return l="w+",rt.open(t.file,l,u);if(h||!x)return c(h);rt.fstat(x,(w,_)=>{if(w)return rt.close(x,()=>c(w));i(x,_.size,(S,E)=>{if(S)return c(S);let v=new js(t.file,{fd:x,start:E});r.pipe(v),v.on("error",c),v.on("close",o),i_(r,e)})})};rt.open(t.file,l,u)})},r_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?yr({file:Ef.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},i_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await yr({file:Ef.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},xi=Ii(e_,n_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!Im(t))throw new TypeError("file is required");if(t.gzip||t.brotli||t.zstd||t.file.endsWith(".br")||t.file.endsWith(".tbr"))throw new TypeError("cannot append to compressed archives");if(!e?.length)throw new TypeError("no paths specified to add/replace")}),sI=Ii(xi.syncFile,xi.asyncFile,xi.syncNoFile,xi.asyncNoFile,(t,e=[])=>{xi.validate?.(t,e),s_(t)}),s_=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))};nn();var _t={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",DELETE:"_agent/delete"};function Ai(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function bf(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function Zs(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function vf(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function Sf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function Er(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}We();ne();ke();We();function jt(t,e){if(Ai(t)!=="cloud")throw new C("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Xs(t){return t.startsWith("http://")||t.startsWith("https://")}function Qs(t){return t.endsWith("/")?t.slice(0,-1):t}We();ne();var eo="1008033",If="1289";var Af="pbbp2",Tf="https://www.coze.cn",Cf="/api/coze_claw/resource/get_frontier_key",a_="https://www.coze.cn",c_="wss://frontier.coze.cn";function to(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??a_}function Rf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??c_}function br(t){let e={},r=t?.ttEnv??process.env.COZE_BRIDGE_TT_ENV,i=t?.usePpe??process.env.COZE_BRIDGE_USE_PPE;return r&&(e["x-tt-env"]=r),i&&(e["x-use-ppe"]=i),e}function Ci(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Ti=U("handshake");async function Nc(t){let e=to(t.endpoint),r=t.timeoutMs??1e4,i=`${Qs(e)}${Cf}?aid=${encodeURIComponent(eo)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...br(t.ppeOverride)},c=new AbortController,l=setTimeout(()=>c.abort(),r);Ti.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),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 C("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${h}: ${v.slice(0,200)}`)}let w=await u.json();if(w.code!==void 0&&w.code!==0)throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${w.code} msg=${w.msg??"-"} logid=${h}`);let _=w.data??{},S=typeof _.access_key=="string"&&_.access_key||typeof _.accessKey=="string"&&_.accessKey||void 0,E=typeof _.device_id=="string"&&_.device_id||typeof _.deviceId=="string"&&_.deviceId||void 0;if(!S||!E){let v=JSON.stringify(w).slice(0,500);throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${h}: ${v}`)}return Ti.info("handshake ok",{remoteDeviceId:E,logid:h,traceId:x}),{accessKey:S,deviceId:E}}catch(u){if(u instanceof C)throw Ti.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Ti.warn("handshake timeout",{base:e,timeoutMs:r}),new C("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let h=u.cause;throw Ti.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:h?.code,syscall:h?.syscall,cause:String(u).slice(0,300)}),new C("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(l)}}var Mc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",yt="auto",Df=15e4;function kf(t){return{model:Bc(t.model)??yt,...t.modelToken?{modelToken:t.modelToken}:{}}}function Pf(t){return!t||t===yt}var d_=new Set(["auto","\u81EA\u52A8"]);function Bc(t){let e=t?.trim();if(e)return d_.has(e.toLowerCase())?yt:e}function Of(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Mc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||yt;e.ANTHROPIC_MODEL=r,e.ANTHROPIC_SMALL_FAST_MODEL=r,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=r,e.ANTHROPIC_DEFAULT_OPUS_MODEL=r,e.ANTHROPIC_DEFAULT_SONNET_MODEL=r,e.CLAUDE_CODE_SUBAGENT_MODEL=r,t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else Pf(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Lf(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||yt}"`):Pf(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="${Mc}/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??Df;e.push("-c",`model_context_window=${r}`)}return e}function Nf(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function Fc(t,e){let{ttEnv:r,usePpe:i}=Ci(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Mf(t,e,r){if(!t.modelToken)return{};let i=Fc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,l])=>`${c}:${l}`).join(`
92
+ `)}}function zc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function Bf(t,e,r){if(!t.modelToken)return null;let i=t.model||yt,o=Fc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let l={baseUrl:`${Mc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:[{id:i,name:i,reasoning:!1,input:c,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:t.modelInfo?.contextWindow??Df,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(l.headers=o),l}function Ff(t,e,r){if(!t.modelToken)return[];let i=Fc(e,r),o=[];for(let[c,l]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${l}"`);return o}var Le=U("agent-handlers"),zf=5*1024*1024,p_=1,g_=6,m_=new Set(["node_modules",".git",".coze","dist","build",".next"]),no=class{constructor(e){this.opts=e}opts;async listSkills(e){jt(e._meta,"_agent/listSkills");let r=Er(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Ze(r).workspace,c=i?.skills??[],l=[];for(let u of c){let h=kt(o,u.relPath,"SKILL.md");await f_(h).then(w=>w.isFile()).catch(()=>!1)&&l.push(b_(u))}return{skills:l}}async addSkills(e){jt(e._meta,"_agent/addSkills");let r=Er(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],l=new Map(c.map((h,x)=>[h.skillId,x])),u=[];for(let h of o){let x=await Kc({agentId:r,workspace:i.workspace,framework:i.framework,skill:h});$c(c,l,x),u.push(h)}return await os(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){jt(e._meta,"_agent/removeSkills");let r=Er(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],l=[];for(let u of c){if(!o.has(u.skillId)){l.push(u);continue}let h=kt(i.workspace,u.relPath);await u_(h,{recursive:!0,force:!0}),Le.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await os(r,l),this.reloadAgentSessions(r,"skills-removed"),{ok:!0}}reloadAgentSessionsPublic(e,r){this.reloadAgentSessions(e,r)}reloadAgentSessions(e,r){let i=this.opts.agents.get(e);if(i)for(let[o,c]of i.sessions){if(!c.downstream)continue;let l=c.acpSessionId;if(l&&i.activeTriggers.has(l)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,Le.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l});continue}let h=c.downstream;c.downstream=void 0,Le.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l}),h.stop(r).catch(x=>Le.warn("downstream stop failed during reload (ignored)",{reason:r,agentId:e,cloudId:o,err:String(x)}))}}isRuntimePendingPermission(e){let r=this.opts.isRuntimePendingPermission;return!r||!e.downstream?!1:r(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return Le.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await qe(r);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Le.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await ir(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Le.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new C("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Xe(i),Le.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new C("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await qe(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Xe(i),Le.info("agent disconnected",{agentId:r,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(r,e.reason??"disconnect"),{ok:!0}):(Le.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(jt(e._meta,"_agent/switchModel"),!e.agentId)throw new C("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Bc(e.model)??yt,i=await qe(e.agentId);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Xe(i),Le.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Le.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};o.model=r,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o).catch(l=>Le.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(l)}));let c=[];for(let[l,u]of o.allSessionQueues())c.push(u.enqueue(async()=>{let h=o.sessions.get(l);h?.downstream&&(await h.downstream.stop(`switchModel: ${r}`).catch(()=>{}),h.downstream=void 0)}));return await Promise.all(c),Le.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:r,cloudSessions:c.length}),{ok:!0}}async resetAgent(e){if(jt(e._meta,_t.RESET),!e.agentId)throw new C("IPC_BAD_REQUEST",`${_t.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,_t.RESET),await this.runDetailSync(e.agentId,_t.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),Le.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(r);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,l]of i.sessions)o.set(c,{modelToken:l.modelToken,tokenGeneratedAt:l.tokenGeneratedAt});await Qr(e,o)}async clearPersistedAcpSessionIds(e){let r=await qe(e).catch(()=>null);if(!r?.sessions)return;let i=!1;for(let o of Object.values(r.sessions))o.acpSessionId&&(o.acpSessionId=void 0,i=!0);i&&await Xe(r)}async repairAgent(e){if(jt(e._meta,_t.REPAIR),!e.agentId)throw new C("IPC_BAD_REQUEST",`${_t.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new C("IPC_BAD_REQUEST",`${_t.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){Le.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,_t.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){Le.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Le.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){jt(e._meta,"_agent/getFileTree");let r=e._meta,i=Er(r),o=await this.resolveWorkspace(i),c=e.filePath??"",l=this.safeJoin(o,c),u=await Uc(l).catch(()=>null);if(!u)throw new C("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await Xr(l,o))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let h=O_(e.depth);return u.isDirectory()?{tree:await P_(o,l,c,h)}:{tree:[{name:L_(c),path:Kf(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){jt(e._meta,"_agent/getFileContent");let r=Er(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new C("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await Uc(o).catch(()=>null);if(!c||!c.isFile())throw new C("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await Xr(o,i))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>zf)throw new C("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${zf})`);let l=await Uf(o);return l.includes(0)?{content:l.toString("base64"),encoding:"base64",size:c.size}:{content:l.toString("utf8"),encoding:"utf-8",size:c.size}}async resolveWorkspace(e){let r=this.opts.agents.get(e);return r?r.workspace:(await qe(e).catch(()=>null))?.workspace??Ze(e).workspace}safeJoin(e,r){let i=Gc(e,r||"."),o=Wc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Hf}`))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return qe(e)}async requireAgentCfg(e){let r=await this.loadAgentCfg(e);if(!r)throw new C("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function w_(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new C("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new C("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function __(t){return t==="claude-code"?kt(".claude","skills"):kt(".agents","skills")}var y_=3e4,E_=50*1024*1024,vr=3e4;async function Kc(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new C("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,l=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!l)throw new C("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=w_(o.skillName),h=__(i),x=kt(h,u),w=kt(r,x);if(await Hc(w,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");Ri(S.length),await qc(kt(w,"SKILL.md"),S,"utf8")}else{let S=await v_(o.downloadUrl);I_(S)?await R_(S,w):A_(S)?await T_(S,w):await qc(kt(w,"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 Le.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:x,source:c?"content":"downloadUrl"}),_}function $c(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 b_(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function v_(t){if(!t)throw new C("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Ri(e);let r=S_(t);return Ri(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await Uf(e);return Ri(r.length),r}if(Xs(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),y_);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new C("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Ri(o.byteLength),Buffer.from(o)}finally{clearTimeout(r)}}throw new C("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Ri(t){if(t>E_)throw new C("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function S_(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new C("IPC_BAD_REQUEST","bad data URL");let r=!!e[2],i=e[3]??"";return r?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function I_(t){return t.length>=2&&t[0]===31&&t[1]===139}function A_(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],r=t[3];return e===3&&r===4||e===5&&r===6}function jc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function T_(t,e){let r,i;try{r=new jf.default(t),i=r.getEntries()}catch(l){throw new C("IPC_BAD_REQUEST",`zip parse failed: ${l.message}`,{cause:l})}for(let l of i){let u=l.entryName;if(!u||jc(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new C("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(x=>x===".."))throw new C("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let h=l.header.attr>>>16&61440;if(h!==0&&h!==32768&&h!==16384)throw new C("IPC_BAD_REQUEST",`zip entry kind 0x${h.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=C_(i),c=Gc(e);for(let l of i){if(jc(l.entryName))continue;let u=l.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let h=Gc(e,u),x=Wc(c,h);if(x.startsWith("..")||x==="..")throw new C("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(l.isDirectory){await Hc(h,{recursive:!0});continue}await Hc(h_(h),{recursive:!0});let w;try{w=l.getData()}catch(_){throw new C("IPC_BAD_REQUEST",`zip entry getData failed (${l.entryName}): ${_.message}`,{cause:_})}await qc(h,w)}}function C_(t){let e;for(let r of t){let i=r.entryName;if(!i||jc(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 R_(t,e){await D_(t);let r=yf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new C("IPC_BAD_REQUEST",`tar extract timeout (${vr}ms)`))},vr);try{await Gf(qf.from(t),r)}catch(c){throw c instanceof C?c:i?new C("IPC_BAD_REQUEST",`tar extract timeout (${vr}ms)`):new C("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function D_(t){let e=[],r=yr({onReadEntry:c=>{let l=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' not allowed (symlink/hardlink/special): ${l.slice(0,100)}`);return}if(l.startsWith("/")||l.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(l)){e.push(`tar entry absolute path: ${l}`);return}l.split(/[/\\]/).some(x=>x==="..")&&e.push(`tar entry contains '..': ${l}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new C("IPC_BAD_REQUEST",`tar list timeout (${vr}ms)`))},vr);try{await Gf(qf.from(t),r)}catch(c){throw i?new C("IPC_BAD_REQUEST",`tar list timeout (${vr}ms)`):new C("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new C("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var k_=5e3;async function P_(t,e,r,i){return Wf(t,e,r,i,{count:0})}async function Wf(t,e,r,i,o){if(i<=0)return[];let c;try{c=await l_(e,{withFileTypes:!0})}catch{return[]}let l=[];for(let u of c){if(m_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=k_){l.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let h=kt(e,u.name),x=x_(kt(r,u.name)),w=null;try{w=await Uc(h)}catch{continue}if(w.isSymbolicLink())continue;o.count++;let _={name:u.name,path:Kf(Wc(t,h)),isDir:w.isDirectory(),size:w.size,modifiedAt:Math.floor(w.mtimeMs)};w.isDirectory()&&i>1&&(_.children=await Wf(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 O_(t){return!t||t<=0?p_:Math.min(t,g_)}function L_(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function Kf(t){return t.split(Hf).join("/")}ne();import{readFileSync as pA}from"node:fs";import{dirname as mA,join as wA}from"node:path";import{fileURLToPath as yA}from"node:url";var Sr="0.1.103-alpha.1";var mn=U("agent-health-reporter"),N_=1e4,Di=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??N_}opts;timer=null;inFlight=!1;unsubscribeRegister=null;intervalMs;start(){this.timer||(this.timer=setInterval(()=>{this.tick()},this.intervalMs),this.timer.unref?.(),this.unsubscribeRegister=this.opts.core.onAgentRegister(()=>{this.tick()}),mn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),mn.info("heartbeat stopped"))}async tick(){if(this.inFlight){mn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){mn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let r=[];for(let l of this.opts.core.agents.values()){let u=M_(l);if(!u)continue;let h={agentId:l.agentId,status:u};l.patToken&&(h.patToken=l.patToken),l.accountId&&(h.accountId=l.accountId),r.push(h)}if(r.length===0)return;let i={agents:r,bridgeVersion:Sr,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(l){mn.warn("heartbeat batch send failed",{count:r.length,err:String(l)})}let c=o?.authFailures;if(c&&c.length>0&&(mn.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){mn.warn("onAuthFailures callback failed (ignored)",{err:String(l)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){mn.warn("onTickEnd hook failed",{err:String(r)})}}};function M_(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}nn();import{chmod as Py,mkdir as xo,rm as Oy,stat as Ly,writeFile as Ny}from"node:fs/promises";import{homedir as My}from"node:os";import{join as E0}from"node:path";tn();import{existsSync as ey}from"node:fs";import{release as ty}from"node:os";import{basename as ny,isAbsolute as ry}from"node:path";function ki(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Ir(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Ar(t,e){return{jsonrpc:"2.0",id:t,result:e}}function wn(t,e){return{jsonrpc:"2.0",id:t,error:e}}We();var ro=class extends Error{code;data;constructor(e){super(`JSON-RPC error code=${e.code} ${e.message}`),this.name="RemoteRpcError",this.code=e.code,e.data!==void 0&&(this.data=e.data)}},ee={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32022};function $f(t){return"method"in t&&"id"in t&&t.id!==void 0}function Jf(t){return"method"in t&&!("id"in t)}function io(t){return!("method"in t)&&"id"in t}var B_={AGENT_NOT_FOUND:ee.AGENT_NOT_FOUND,AGENT_BUSY:ee.AGENT_BUSY,AGENT_DISCONNECTED:ee.AGENT_DISCONNECTED,AGENT_TIMEOUT:ee.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:ee.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:ee.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:ee.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:ee.INTERNAL_ERROR,BRIDGE_INTERNAL:ee.INTERNAL_ERROR,IPC_AUTH_FAILED:ee.INTERNAL_ERROR,IPC_BAD_REQUEST:ee.INVALID_REQUEST,METHOD_NOT_FOUND:ee.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:ee.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:ee.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:ee.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:ee.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:ee.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:ee.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:ee.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:ee.FILE_TOO_LARGE,UNSUPPORTED_MIME:ee.UNSUPPORTED_MIME,UPLOAD_FAILED:ee.UPLOAD_FAILED,UPSTREAM_NOT_READY:ee.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:ee.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:ee.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:ee.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:ee.AGENT_ENV_NOT_READY};function F_(t){if(t!=null)return t instanceof Error?{name:t.name,message:Pi(t.message)}:typeof t=="string"?Pi(t):typeof t=="object"?U_(t):t}var z_=[[/\/Users\/[^/\s'"`)]+/g,"/Users/<redacted>"],[/\/home\/[^/\s'"`)]+/g,"/home/<redacted>"],[/[A-Za-z]:\\Users\\[^\\\s'"`)]+/g,"C:\\Users\\<redacted>"],[/(Bearer|Token|Authorization:)\s+[\w._-]+/gi,"$1 <redacted>"],[/\b(sk|pat|ak)[-_][A-Za-z0-9_-]{20,}\b/g,"<redacted-key>"]];function Pi(t){let e=t;for(let[r,i]of z_)e=e.replace(r,i);return e}function U_(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Pi(i):e[r]=i;return e}function Oi(t){if(t instanceof C){let e=F_(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:B_[t.code]??ee.INTERNAL_ERROR,message:Pi(t.message),data:r}}return{code:ee.INTERNAL_ERROR,message:Pi(t instanceof Error?t.message:String(t))}}function Vf(t){let e=t.data,r=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:l,...u}=e;c=u}return new C(r,o,{retriable:e?.retriable??!1,cause:c})}function Zf(t){return`${JSON.stringify(t)}
93
+ `}var Yf=10*1024*1024,so=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>Yf){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${Yf} bytes`)}),[]}let r=this.buffer.split(`
94
+ `);this.buffer=r.pop()??"";let i=[];for(let o of r){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(l){this.onError?.({line:c,error:l})}}return i}flush(){if(!this.buffer)return[];let e=this.buffer.replace(/\r$/,"").trim();if(this.buffer="",!e)return[];try{return[JSON.parse(e)]}catch(r){return this.onError?.({line:e,error:r}),[]}}};var Qf={"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"},kA=Object.fromEntries(Object.entries(Qf).map(([t,e])=>[e,t])),H_={"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:[]},Tr=class{seq=0;next(e,r){this.seq+=1;let i=Qf[e]??q_(e),o=H_[i]??[],c=[i,String(this.seq)];if(o.length>0){let l=o.map(h=>Xf(r?.[h]??"")),u=G_(l).join(":");u&&c.push(u)}else r&&Object.values(r).some(l=>l)&&c.push(Object.values(r).filter(Boolean).map(l=>Xf(String(l))).join(":"));return c.join("_")}reset(){this.seq=0}};function q_(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function Xf(t){return t.replace(/[:_\s]+/g,"-")}function G_(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}Zr();import{readFileSync as j_}from"node:fs";var W_=384;async function Jc(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await rr(t.agentEnvFile,r,{mode:W_})}function Vc(t){try{let e=JSON.parse(j_(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function e0(t,e,r={},i=o=>o){return{...i({...t,...Vc(e)}),...r}}_n();Kr();We();ne();ke();import{spawnSync as X_}from"node:child_process";function oo(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function ao(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),X_("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var Yc=new Set;function i0(t){typeof t=="number"&&t>0&&Yc.add(t)}function s0(t){typeof t=="number"&&Yc.delete(t)}function o0(){for(let t of Yc)ao(t,"SIGKILL")}var Q_=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: Node binary not found/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @zed-industries\/codex-acp|optional dependency was not installed|\.resolve is not a function/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"}];function a0(t,e){if(!e)return null;for(let r of Q_)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function c0(t,e){return a0(t,e)}function d0(t,e){return a0(t,e)}function Cr(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 l0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let x=t.suspendedMs+o,w=r-t.startedAt-x;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Cr(w,t.firstFrameSeen,e)}}let c=r-t.startedAt-t.suspendedMs,l=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=l?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Cr(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Cr(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Cr(c,!1,e)}}var u0=Ye("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),iy=200,sy=40,oy=Ye("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),ay=Ye("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),cy=Ye("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),dy=Ye("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),ly=Ye("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),uy=Ye("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),f0=500;function fy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=f0?t:`${e.slice(0,f0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function hy(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 h0(t){try{return ey(t)}catch{return}}function xy(t,e){return{platform:process.platform,osRelease:ty(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:ry(e.command)?h0(e.command):void 0,cwd:e.cwd,cwdExists:h0(e.cwd),envKeys:e.envKeys}}function py(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${ny(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Pt=class{constructor(e){this.opts=e;this.log=U(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new so({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Tr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new C("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=e0(process.env,this.opts.agentEnvFile??Q().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=dt(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,i0(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>iy&&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,s0(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=xy(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(r).length});this.log.error("child error",{err:String(o),diag:l}),this.failAllPending(new C("AGENT_SPAWN_FAILED",py(c,l),{cause:l}))}),this.log.info("downstream started",{command:this.opts.command,pid:i.pid,cwd:this.opts.cwd})}async stop(e){if(!this.child||this.stopped)return;this.stopped=!0,this.stopReason=e??"stopped",this.log.info("downstream stopping",{reason:e});let r=this.child,i=new Promise(c=>r.once("exit",()=>c()));ao(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||ao(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:ly,phase2GateMs:oy,livenessWindowMs:ay,absoluteMaxMs:cy,approvalMaxMs:uy,suspendThresholdMs:dy,...r};return this.call("session/prompt",e,u0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Ir("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(Ar(e,r))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(wn(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 C("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),l=ki(c,e,r),u=(()=>{if(typeof r!="object"||r===null)return;let h=r.sessionId;return typeof h=="string"?h:void 0})();return new Promise((h,x)=>{let w={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:Cr(0,!1,o),sessionId:u};w.promptTimeout=S;let E=()=>{let v={startedAt:S.startedAt,lastActivityAt:S.lastActivityAt,firstFrameSeen:S.firstFrameSeen,hasActiveTool:S.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:S.suspendedMs,armedAt:S.armedAt,expectedIntervalMs:S.expectedIntervalMs},A=this.now(),I=l0(v,S.cfg,A),R=L=>{S.armedAt=A,S.expectedIntervalMs=L,w.timer=setTimeout(E,L)};if(I.action==="suspend"){S.suspendedMs+=I.suspendedDeltaMs,S.lastActivityAt=A,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:I.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),R(I.rearmMs);return}if(I.action==="continue"){R(I.rearmMs);return}this.pending.delete(c),I.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:I.awaitingApproval,...S.sessionId?{sessionId:S.sessionId}:{}}),x(I.awaitingApproval?new C("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new C("AGENT_TIMEOUT",`${e} timed out after ${S.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...S.sessionId?{sessionId:S.sessionId}:{}}),x(new C("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};w.timer=setTimeout(E,S.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(w.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),x(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,w);try{this.writeFrame(l)}catch(_){w.timer&&clearTimeout(w.timer),this.pending.delete(c),x(_)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new C("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(Zf(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(io(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new C("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:fy(e.result)}),r.resolve(e.result));return}if(Jf(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($f(e)){let r=e;try{this.handleAgentRequest(r).catch(i=>this.log.error("agent request handler failed (async)",{method:r.method,err:String(i)}))}catch(i){this.log.warn("handleAgentRequest threw sync, swallowed",{method:r.method,err:String(i)})}}}trackToolCall(e,r){let i=r.update,o=i?.sessionUpdate;if(o!=="tool_call"&&o!=="tool_call_update")return;let c=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!c)return;let l=typeof i.status=="string"?i.status:void 0,u=l==="completed"||l==="failed"||l==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(wn(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(wn(e.id,Oi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=Vf(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=d0(this.framework,hy(e));return i?new C(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):r}buildExitError(e,r){if(this.stopReason!==void 0)return new C("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(sy).join(`
95
+ `),o=c0(this.framework,i);return o?new C(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new C("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function gy(t){let e={};for(let[r,i]of Object.entries(t))i!==void 0&&(r.startsWith("CLAUDE")||r==="AI_AGENT"||r==="BAGGAGE"||(e[r]=i));return e}var co=class extends Pt{framework="claude-code";constructor(e){let{command:r,args:i}=Yr("claude-code",e.command,e.args??[]),o={command:r,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o)}sanitizeEnv(e){return gy(e)}};tn();import{mkdtempSync as my,rmSync as wy}from"node:fs";import{tmpdir as _y}from"node:os";import{join as yy}from"node:path";var lo=class extends Pt{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=Yr("codex",e.command,i),l=e.isolateCodexHome?my(yy(_y(),"coze-bridge-codex-home-")):void 0,u=l?{...e.env??{},CODEX_HOME:l}:e.env,h={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(h),this.authMethodId=e.authMethodId,this.codexHomeDir=l}async initialize(e){let r=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),r}async stop(e){if(await super.stop(e),this.codexHomeDir)try{wy(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};We();var Ey=3e4,Rr=class extends Pt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},Ey))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new C("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var x0=["default","acceptEdits","plan","auto","bypassPermissions"],p0=["read-only","auto","full-access"];function yn(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return x0.includes(e);case"codex":return p0.includes(e);case"openclaw":return!1}}function Zc(t){switch(t){case"claude-code":return x0.join("/");case"codex":return p0.join("/");case"openclaw":return""}}We();ne();ke();function Xc(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}tn();var En=class{slots=[];running=!1;closed=!1;disposed=!1;enqueue(e){return this.disposed?Promise.reject(new Error("AsyncQueue disposed")):this.closed?Promise.reject(new Error("AsyncQueue closed")):new Promise((r,i)=>{this.slots.push({task:e,resolve:r,reject:i}),this.drain()})}close(){this.closed=!0}dispose(e=new Error("AsyncQueue disposed")){for(this.disposed=!0,this.closed=!0;this.slots.length>0;)this.slots.shift()?.reject(e)}get size(){return this.slots.length}get isRunning(){return this.running}get isDisposed(){return this.disposed}async drain(){if(!this.running){this.running=!0;try{for(;this.slots.length>0&&!this.disposed;){let e=this.slots.shift();if(!e)break;try{let r=await e.task();e.resolve(r)}catch(r){e.reject(r)}}}finally{this.running=!1}}}};var uo=class{agentId;framework;workspace;deployType;accountId;patToken;modelInfo;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;activeGroupIds=new Map;status="ok";model;lastActiveAt=Date.now();constructor(e){this.agentId=e.agentId,this.framework=e.framework,this.workspace=e.workspace,this.model=e.model,this.deployType=e.deployType??"local",e.accountId&&(this.accountId=e.accountId),e.patToken&&(this.patToken=e.patToken),e.modelInfo&&(this.modelInfo=e.modelInfo)}setPatToken(e){this.patToken=e}setModelInfo(e){this.modelInfo=e}getSessionQueue(e){let r=this.sessionQueues.get(e);return(!r||r.isDisposed)&&(r=new En,this.sessionQueues.set(e,r)),r}allSessionQueues(){return this.sessionQueues.entries()}hasSessionQueue(e){let r=this.sessionQueues.get(e);return!!r&&!r.isDisposed}async dispose(e){this.status="stopped";let r=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let i of this.sessionQueues.values())i.dispose(r);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let r=[];for(let[,i]of this.sessions)Li(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 Li(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function Wt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}_n();ne();import{constants as g0}from"node:fs";import{access as by}from"node:fs/promises";import{delimiter as vy,join as Sy}from"node:path";var Et=U("framework-detector"),m0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},Iy=[".exe",".cmd",".bat",".ps1"],Hn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??dt,access:e.access??by}}async detect(e){let r=m0[e],i=await this.which(r);if(!i)return Et.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,l]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return l&&(u.defaultAgent=l),u}async detectAll(){let e=await Promise.all(Object.keys(m0).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(vy).filter(Boolean),i=this.env.platform==="win32"?["",...Iy]:[""];for(let o of r)for(let c of i){let l=Sy(o,e+c);if(await this.isExecutable(l))return l}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?g0.F_OK:g0.X_OK;return await this.env.access(e,r),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let r=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!r)return Et.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return Et.warn("openclaw default agent probe: non-zero exit",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)}),null;let i=r.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return Et.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:r.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return Et.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(l=>l?.isDefault===!0);return c?!c.id||!c.workspace?(Et.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(Et.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return Et.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let r=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!r)return Et.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||Et.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let l=JSON.parse(c[0]);typeof l.gateway?.port=="number"&&(o.port=l.gateway.port),typeof l.service?.runtime?.status=="string"&&(o.runtime=l.service.runtime.status),!i&&typeof l.rpc?.error=="string"&&(o.detail=l.rpc.error)}catch(l){Et.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(l)})}return o}async probeVersion(e,r=[]){let i=await this.runProbe(e,[...r,"--version"]);return i&&(Ty(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,l,u=h=>{c||(c=!0,l&&clearTimeout(l),i(h))};try{let h=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});l=setTimeout(()=>{h.kill("SIGKILL"),u(null)},15e3),h.stdout?.on("data",x=>{o+=x.toString("utf8")}),h.on("error",()=>u(null)),h.on("close",x=>u({code:x,stdout:o}))}catch{u(null)}})}},Ay=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function Ty(t){return t.replace(Ay,"")}import{homedir as Cy}from"node:os";import{join as Ry}from"node:path";_n();Kr();We();Zr();ne();async function y0(){let t=Ry(Cy(),".openclaw/openclaw.json");return(await nr(t))?.gateway?.auth?.token??""}var w0=U("openclaw.config"),Dy=[0,5e3,5e3],ky=Ye("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),_0="models.providers.",fo="agents.defaults.models",ho=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new En;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??Dy,this.cliTimeoutMs=e.cliTimeoutMs??ky}async withRetry(e,r){let i;for(let o=0;o<this.retryDelaysMs.length;o++){let c=this.retryDelaysMs[o]??0;c>0&&await new Promise(l=>setTimeout(l,c));try{return await r()}catch(l){i=l,w0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(l)})}}throw new C("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=dt(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?r():i(new Error(`exit ${x}: ${c.trim().slice(0,500)}`))}))})}async runCliTolerant(e,r){try{await this.runCli(e)}catch(i){let o=String(i);if(r.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,r){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",r])))}catch(i){w0.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",`${_0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${_0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${fo}[${e}]`,()=>this.runCli(["config","set",fo,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${fo}[${e}]`,`${fo}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var le=U("agent-manager"),ed="acceptEdits",S0="full-access",I0="read-only";function By(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 Fy=(t,e,r,i,o,c,l,u,h,x)=>{switch(t){case"claude-code":{let w={...o?{...Of(o),...Mf(o,l,u)}:{},...h??{},IS_SANDBOX:"1"};return new co({cwd:r,env:w,agentId:i})}case"codex":{let w=o?[...Lf(o),...Ff(o,l,u)]:[],_=S0;x!==void 0&&(yn("codex",x)?_=x:le.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:x}));let S=[...w,...By(_)],E={...o?Nf(o):{},...h??{}},v=!!o;return new lo({cwd:r,agentId:i,...S.length>0?{extraArgs:S}:{},...Object.keys(E).length>0?{env:E}:{},...v?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Rr({command:e,cwd:r,agentId:i,...c?{sessionName:Xc(c)}:{}})}};function Qc(t){return t==="claude-code"||t==="codex"}function zy(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(Uy(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
97
96
  `)}
98
- `}function By(t){if(t.includes(`
99
- `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var Fy={path:"",version:"cloud-deployed"},b0="openclaw_gateway_unavailable",zy="openclaw_default_agent_missing";function v0(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 Uy={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},Hy=6e4,po=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;detectorFactory;openclawEnvBootstrapPromise;openclawConfigFactory;openclawConfigDir;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??Ny,this.createTimeoutMs=e.createTimeoutMs??Hy,this.detectorFactory=e.detectorFactory??(()=>new Hn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new ho({command:r})),this.openclawConfigDir=e.openclawConfigDir??E0(Ly(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new C("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{le.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=E0(e,".env");if(await Py(r).then(c=>c.isFile()).catch(()=>!1)){le.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}await xo(e,{recursive:!0});let o=My({...process.env,...Zc(this.paths.agentEnvFile)});if(await Oy(r,o,"utf8"),process.platform!=="win32")try{await Dy(r,384)}catch(c){le.warn("chmod ~/.openclaw/.env to 0600 failed (ignored)",{err:String(c)})}le.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),le.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new C("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new C("IPC_BAD_REQUEST","framework required");let i=await He(e.agentId,this.paths).catch(()=>null),o=Qs(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let c=this.registry.get(e.agentId);if(c){if(c.framework!==e.framework)throw new C("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")le.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(T=>le.warn("dispose stale agent failed (ignored)",{err:String(T)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")le.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(T=>le.warn("dispose drifted agent failed (ignored)",{err:String(T)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){le.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let T=await He(e.agentId,this.paths).catch(()=>null);T&&(T.patToken=e.patToken,await Ye(T,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){le.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let T=await He(e.agentId,this.paths).catch(()=>null);T&&(T.modelInfo=e.modelInfo,await Ye(T,this.paths))}return le.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=Ze(e.agentId,this.paths),f=o?"cloud":"local",x=e.framework==="openclaw"&&f==="local",m;x&&!r?.revive&&(m=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let w=m??(x?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),b=e.workspace??w??u.workspace,p=new AbortController,_=setTimeout(()=>p.abort(new C("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),S,A=!1;try{o&&Qc(e.framework)&&await tr(e.framework,p.signal);let T=()=>{if(p.signal.aborted)throw p.signal.reason instanceof Error?p.signal.reason:new C("AGENT_TIMEOUT","_agent/create aborted")};await xo(u.root,{recursive:!0}),await xo(b,{recursive:!0}),await xo(u.logs,{recursive:!0}),T(),x||await ir(b,e.framework,e.cozeIdentity),e.framework==="claude-code"&&await Td(b,f),T();let D=i,E=kf({model:e.model??D?.model}),k=vf(e._meta)??D?.accountId,P=e.patToken??D?.patToken,B=f==="cloud"?e.modelInfo??D?.modelInfo:void 0;if(S=new uo({agentId:e.agentId,framework:e.framework,workspace:b,model:E.model??yt,deployType:f,...k?{accountId:k}:{},...P?{patToken:P}:{},...B?{modelInfo:B}:{}}),S.status="ok",D?.sessions){for(let[ne,Y]of Object.entries(D.sessions))S.sessions.set(ne,{acpSessionId:Y.acpSessionId,modelToken:Y.modelToken,tokenGeneratedAt:Y.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0});let W=Object.keys(D.sessions).length;W>0&&le.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:W})}this.registry.register(S),A=!0;let N={agentId:e.agentId,framework:e.framework,workspace:b,cozeIdentity:e.cozeIdentity,createdAt:D?.createdAt??Date.now(),sessions:D?.sessions??{},model:E.model};f==="cloud"&&(N.deployType="cloud"),k&&(N.accountId=k),P&&(N.patToken=P),B&&(N.modelInfo=B),D?.skills&&(N.skills=D.skills),D?.agentName&&(N.agentName=D.agentName),D?.description&&(N.description=D.description),e.framework==="openclaw"&&f==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,b)):le.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let $=e.initialSkills??[];if($.length>0){let W=[...N.skills??[]],ne=new Map(W.map((he,O)=>[he.skillId,O])),Y=await Promise.allSettled($.map(he=>$c({agentId:e.agentId,workspace:b,framework:e.framework,skill:he}))),ve=0;for(let[he,O]of Y.entries()){let q=$[he];q&&(O.status==="fulfilled"?(Vc(W,ne,O.value),ve++):le.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:q.skillId,skillName:q.skillName,err:String(O.reason)}))}ve>0&&(N.skills=W,le.info("initialSkills installed",{agentId:e.agentId,installed:ve,requested:$.length}))}return await Ye(N,this.paths),le.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:f}),{ok:!0,agentId:e.agentId,workspace:b,framework:e.framework}}catch(T){throw le.error("agent create failed, rolling back",{agentId:e.agentId,err:String(T)}),A&&S&&(await S.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await ky(u.root,{recursive:!0,force:!0}).catch(D=>le.warn("rm agent dir failed (ignored)",{err:String(D)})),T instanceof C?T:new C("AGENT_SPAWN_FAILED",String(T),{cause:T})}finally{clearTimeout(_)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&Qc(e.framework))u=Fy;else throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);Qc(e.framework)&&!ss(e.framework)&&(le.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await tr(e.framework));let f=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,x;e.framework==="openclaw"?x=await this.buildOpenclawDownstream({session:e,modelConfig:f,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path}):x=this.factory(e.framework,u.path,e.workspace,e.agentId,f,i,o,c,this.buildBinShimPathEnv());try{return await x.start(),await x.initialize(Uy),x}catch(m){let w=x instanceof Ot?x.getStderrTail():[];throw w.length>0&&le.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:m instanceof C?m.code:"unknown",recentStderr:w}),await x.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,m)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new C("AGENT_ENV_NOT_READY",v0(o),{cause:{reason:b0}})}catch(o){le.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof C?i:new C("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};le.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return le.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new C("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:zy}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new C("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new C("AGENT_ENV_NOT_READY",v0(r),{cause:{reason:b0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:l,command:u}=e,f=Xc(o);if(r.deployType==="local"){let b=await this.ensureOpenclawDefaultAgent();return new Dr({command:u,cwd:b.workspace,agentId:b.id,sessionName:f})}let x=await y0(),m=i?Bf(i,c,l):null,w;if(m){let b=Uc(o),_=m.models[0]?.id??yt,S=`${b}/${_}`;if(!this.ensuredProviders.has(S)){let A=this.getOpenclawConfig();await A.ensureProvider(b,m),await A.addModelToAllowlist(S),this.ensuredProviders.add(S)}w=S}return new Dr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:f,...x?{gatewayToken:x}:{},...w?{slashModelOnStart:w}:{}})}async openclawRepair(e,r){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,r)}async cleanupOpenclawSessionProviders(e){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let r=this.openclawConfigCache;for(let i of e.sessions.keys()){let o=Uc(i),c=`${o}/${e.model}`,l=!0;try{await r.removeProvider(o)}catch(u){l=!1,le.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){l=!1,le.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}l&&this.ensuredProviders.delete(c)}}};import{randomUUID as C0}from"node:crypto";import{promises as Jy}from"node:fs";import{basename as R0}from"node:path";We();ee();import{promises as Gy}from"node:fs";import{basename as jy}from"node:path";var S0=H("file-upload"),Wy="/api/coze_claw/file/agent_upload",Ky=6e4;async function I0(t,e={}){let i=`${to(ro(e.handshakeBase))}${Wy}`,o=e.timeoutMs??Ky,c=await Gy.readFile(t.path),l=new FormData;l.append("agent_id",t.agentId),l.append("session_id",t.sessionId),l.append("file_name",t.name),l.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let u={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...br(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},f=new AbortController,x=setTimeout(()=>f.abort(),o);S0.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:f.signal}),w=m.headers.get("x-tt-logid")??"";if(!m.ok){let _=await m.text().catch(()=>"");throw new C("UPLOAD_FAILED",`upload HTTP ${m.status} logid=${w}: ${_.slice(0,200)}`)}let b=await m.json();if(b.code!==void 0&&b.code!==0)throw new C("UPLOAD_FAILED",`upload code=${b.code} msg=${b.msg??"-"} logid=${w}`);let p=b.data?.file?.file_url;if(!p)throw new C("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${w}: ${JSON.stringify(b).slice(0,200)}`);return S0.info("file upload ok",{uri:p,logid:w}),{uri:p}}catch(m){throw m instanceof C?m:m.name==="AbortError"?new C("UPLOAD_FAILED",`upload timeout (${o}ms) for ${jy(t.path)}`):new C("UPLOAD_FAILED",String(m),{cause:m})}finally{clearTimeout(x)}}We();ee();import{extname as $y}from"node:path";var Vy={".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 A0(t){let e=$y(t).toLowerCase();return Vy[e]??"application/octet-stream"}ke();var go=H("agent-send"),T0=50*1024*1024;function D0(t,e,r){let i=t.get(e);if(!i)throw new C("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new C("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new C("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function k0(t,e,r,i,o,c){let u;for(let f=0;f<=2;f++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(x){u=x,f<2&&(go.warn("sendAgentFileUpdate failed, retrying",{attempt:f+1,err:String(x)}),await new Promise(m=>setTimeout(m,5e3)))}throw new C("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function P0(t,e){let{session:r,runtime:i}=D0(e.core,t.agentId,t.sessionId);if(!await Qr(t.path,r.workspace))throw new C("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await Jy.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new C("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>T0)throw new C("FILE_TOO_LARGE",`${o.size} bytes > limit ${T0}`);let c=await A0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new C("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new C("UPSTREAM_NOT_READY","cloud WS not connected");let l=t.name??R0(t.path),u;try{u=await I0({patToken:r.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:l,sizeBytes:o.size,...r.accountId?{accountId:r.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(x){throw go.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:x instanceof C?x.code:"UNKNOWN",message:x instanceof Error?x.message:String(x)}),x}let f={sessionUpdate:"agent_file",messageId:C0(),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 k0(e,r,i,t.sessionId,f,"agent file uploaded to cloud but sendAgentFileUpdate failed"),go.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:l,bytes:o.size,mime:c,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:c,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function O0(t,e){let{session:r,runtime:i}=D0(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new C("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new C("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??R0(t.path),c={sessionUpdate:"group_file",messageId:C0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await k0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),go.info("agent group file sent",{agentId:t.agentId,sessionId:t.sessionId,uri:t.path,name:o,mime:t.mimeType}),{ok:!0,uri:t.path,bytes:0,mimeType:t.mimeType}}function L0(t,e){let r=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(r.length,i.length);for(let c=0;c<o;c++){let l=r[c]??0,u=i[c]??0;if(l<u)return!0;if(l>u)return!1}return!1}nn();yn();ee();var Lt=H("coze-cli-installer"),N0="@coze/cli@latest",Zy="coze",M0="0.1.8",Yy=5e3,Xy=5e3,Qy=9e4,B0=1e4,Bi=null,mo=!1;async function el(t,e={}){if(mo)return;if(Bi)return Bi;let r=e.exec??r0;return Bi=(async()=>{try{let i=await eE(Zy,r),o=!1;if(i){let l=await tE(r);if(l===void 0)Lt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(L0(l,M0))Lt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:l,min:M0}),o=!0;else{Lt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:l}),mo=!0;return}}let c=o?"upgrade-only":"full";Lt.info("coze-cli install start",{package:N0,mode:c});try{await r("npm",["i","-g","--prefer-online",N0],{timeout:Qy,maxBuffer:10*1024*1024}),Lt.info("coze-cli install ok")}catch(l){Lt.warn("coze-cli install failed (skip subsequent steps)",{err:String(l)});return}if(o){mo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:B0}),Lt.info("coze config set xTTEnv ok",{env:t.env})}catch(l){Lt.warn("coze config set failed (continue to auth login)",{err:String(l)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:B0}),Lt.info("coze auth login ok")}catch(l){Lt.warn("coze auth login failed",{err:String(l)});return}mo=!0}finally{Bi=null}})(),Bi}async function eE(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:Yy});return Ia(i)}catch{return}}async function tE(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:Xy});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}Xr();ke();var nE=10*6e4;function F0(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?nE:e}function wo(t){return nr(t??X().configFile)}function Fi(t,e){return rr(e??X().configFile,t)}import{randomBytes as bE}from"node:crypto";Xn();We();ee();import{createReadStream as rE}from"node:fs";import{mkdir as iE,readFile as sE,realpath as oE,stat as aE,writeFile as cE}from"node:fs/promises";import{basename as lE,dirname as tl,isAbsolute as dE,join as uE,relative as fE,resolve as z0,sep as hE}from"node:path";import{createInterface as xE}from"node:readline";var H0=H("fs-rpc"),zi=Ge("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function q0(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>zi)throw new C("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${zi} bytes`);let i=await j0(t.path,e);return await iE(tl(i),{recursive:!0}),await cE(i,t.content,"utf8"),H0.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function G0(t,e){let r=await j0(t.path,e),i=await aE(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>zi&&!o)throw new C("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${zi} bytes`);let c;if(o&&i.size>zi)c=await pE(r,t.line??1,t.limit);else{let l=await sE(r,"utf8");if(o){let u=l.split(`
100
- `),f=Math.max(0,(t.line??1)-1),x=typeof t.limit=="number"?f+t.limit:void 0;c=u.slice(f,x).join(`
101
- `)}else c=l}return H0.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function pE(t,e,r){let i=xE({input:rE(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,l=[],u=0;try{for await(let f of i)if(u>=o&&u<c&&l.push(f),u++,u>=c)break}finally{i.close()}return l.join(`
102
- `)}async function j0(t,e){if(typeof t!="string"||t.length===0)throw new C("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([U0(z0(e)),U0(z0(t))]),o=fE(r,i);if(gE(o,hE,dE(o)))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function gE(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function U0(t){let e=[],r=t;for(;r!==tl(r);)try{let i=await oE(r);return e.length?uE(i,...e.reverse()):i}catch{e.push(lE(r)),r=tl(r)}return t}ee();var W0=H("prompt-multimodal"),K0=10*1024*1024,mE=15e3,wE=6;async function $0(t){let e=new Array(t.length),r=0;async function i(){for(;r<t.length;){let c=r++,l=t[c];l!==void 0&&(e[c]=await _E(l))}}let o=Array.from({length:Math.min(wE,t.length)},()=>i());return await Promise.all(o),e}function V0(t){return t.some(e=>e.type==="image")}async function _E(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!eo(e.uri))return t;try{let{buf:r,contentType:i}=await EE(e.uri),o=e.mimeType||yE(i)||"application/octet-stream";return W0.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 W0.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function yE(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function EE(t){let e=new AbortController,r=setTimeout(()=>e.abort(),mE);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>K0)throw new Error(`image too large: ${o.byteLength} bytes (max ${K0})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}rn();We();ee();var K=H("core"),vE=3e4,SE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,IE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",AE="\u5BA1\u6279\u5DF2\u8D85\u65F6",TE=3e4,_o=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Tr;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=F0(e.bridgeConfig)}registerExtension(e,r){this.extensions[e]=r}getCozeEnv(){return this.currentCozeEnv}getMockScenario(){return this.currentMockScenario}setMockScenario(e){this.currentMockScenario=e&&e.length>0?e:void 0}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),K.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){K.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(r=>r.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}async reloadAgents(e){let r=e?this.agents.has(e)?[e]:[]:[...this.agents.keys()];for(let i of r)await this.agents.get(i)?.killAllRuntimes("reload");return r}get(e){return this.agents.get(e)}register(e){this.agents.set(e.agentId,e),K.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){K.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(i)})}}onAgentRegister(e){return this.registerHandlers.add(e),()=>this.registerHandlers.delete(e)}registerHandlers=new Set;unregister(e){this.agents.delete(e)}reviveIfDisconnected(e){this.disconnectedAgents.delete(e)&&K.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,r,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,l)=>{K.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:l}),Mi(i),i.downstream=void 0,i.replySeq=0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),this.rejectPendingForDownstream(o,"downstream exited")}))}hasPendingPermissionFor(e){for(let r of this.pendingUpstream.values())if(r.downstream===e)return!0;return!1}rejectPendingForDownstream(e,r){let i=[];for(let[o,c]of this.pendingUpstream)c.downstream===e&&i.push(o);if(i.length!==0){K.info("reject pendingUpstream entries (downstream gone)",{reason:r,count:i.length});for(let o of i){let c=this.pendingUpstream.get(o);if(c){this.pendingUpstream.delete(o),this.upstream.send(_n(o,{code:Q.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(l=>K.debug("send error response to upstream failed (ignored)",{err:String(l)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:Q.INTERNAL_ERROR,message:`bridge: ${r}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,r=this.pendingBridge.size;if(!(e===0&&r===0)){K.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:r});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:Q.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new C("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(oo(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let r="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&SE.test(i)?this.currentCozeEnv=i:i&&K.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});try{if(e.method.startsWith("_agent/")){let o=this.extensions[e.method];if(!o){r!==null?await this.sendError(r,Q.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):K.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(Ar(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Ar(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Ar(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,Q.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):K.warn("drop unknown notification",{method:e.method})}catch(o){K.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(_n(r,Oi(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new C("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new C("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new C("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new C("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||!c)return this.dispatchSessionCall(o,e.method,r);if(e.method==="session/prompt"){let f=o.sessions.get(c);if(f?.pendingPermission){let x=r._meta?.cozeTriggerMsgId,m=Nc(r._meta);return K.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,f,c,IE,x,m)}}let l=Date.now(),u=!1;try{let f=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,f}finally{K.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-l,ok:u})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=Sf(i);switch(r){case"session/new":{let c=CE();return K.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return K.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,l=c.sessionId;if(!l)throw new C("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=await this.ensureRuntime(e,l);if(u.replySeq=0,await this.ensureDownstream(e,l,u),!u.downstream||!u.acpSessionId)throw new C("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");let f=i._meta?.cozeTriggerMsgId;f?e.activeTriggers.set(u.acpSessionId,f):e.activeTriggers.delete(u.acpSessionId);let x=Nc(i._meta);if(x?e.activeGroupIds.set(u.acpSessionId,x):e.activeGroupIds.delete(u.acpSessionId),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&V0(c.prompt))throw new C("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let m=await $0(c.prompt);try{let w=await u.downstream.sessionPrompt({...c,sessionId:u.acpSessionId,prompt:m});return u.lastActiveAt=Date.now(),w}catch(w){if(w instanceof C&&w.code==="AGENT_APPROVAL_TIMEOUT"){let b=u.pendingPermission;b&&(b.downstream.respondAgentRequest(b.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(b.upstreamId),u.pendingPermission=void 0);let p=u.acpSessionId,_=p?e.activeTriggers.get(p):void 0,S=p?e.activeGroupIds.get(p):void 0;return K.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:l}),await this.synthesizePromptReply(e,u,l,AE,_,S)}throw w}finally{if(e.activeTriggers.delete(u.acpSessionId),e.activeGroupIds.delete(u.acpSessionId),u.pendingPermission=void 0,u.reloadAfterTurn){u.reloadAfterTurn=!1;let w=u.downstream;w&&(u.downstream=void 0,K.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:l,acpId:u.acpSessionId}),w.stop("reload-after-turn").catch(b=>K.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:l,err:String(b)})))}else u.downstream?.isAlive()&&this.armIdleTimer(e,l,u)}}case"session/cancel":{let l=o.sessionId;if(!l)throw new C("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(l);if(e.hasSessionQueue(l)){let f=e.getSessionQueue(l);f.size>0&&(K.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:l,queuedCount:f.size}),f.dispose(new C("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${l}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}default:throw new C("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async ensureRuntime(e,r){let i=e.sessions.get(r);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,r):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return e.sessions.set(r,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,r){let i={sessionId:r,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(_t.GEN_MODEL_TOKEN,i,TE);if(!o?.modelToken)throw new C("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof C&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new C("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(Mi(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new C("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,l=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(l>=o&&Date.now()-u<c)throw new C("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${l} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let f;try{f=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(x){throw i.spawnFailCount=l+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(K.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),x}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=f,this.attachRuntimeHooks(e,r,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await f.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),K.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(x){K.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(x)}),i.acpSessionId=void 0;let m=await f.sessionNew({cwd:e.workspace});i.acpSessionId=m.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let x=await f.sessionNew({cwd:e.workspace});i.acpSessionId=x.sessionId,await this.persistSessionMapping(e)}}catch(x){throw K.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(x)}),await f.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,x}f.afterSessionEstablished&&i.acpSessionId&&await f.afterSessionEstablished(i.acpSessionId)}armIdleTimer(e,r,i){if(Mi(i),this.isRuntimeBusy(e,i)){K.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:r});return}i.idleTimer=setTimeout(()=>{if(i.idleTimer=void 0,this.isRuntimeBusy(e,i)){K.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}K.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:r});let o=i.downstream;i.downstream=void 0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),o&&o.stop("idle timeout").catch(c=>K.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:r,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,r){if(r.acpSessionId&&e.activeTriggers.has(r.acpSessionId))return!0;let i=r.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,r,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};if(r.acpSessionId){let l=e.activeTriggers.get(r.acpSessionId);l&&(c.cozeTriggerMsgId=l);let u=e.activeGroupIds.get(r.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Ir("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,l){let u={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(u.cozeTriggerMsgId=c),l&&(u.cozeGroupId=l),await this.upstream.send(Ir("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(f=>K.warn("synthesizePromptReply update send failed (ignored)",{err:String(f)})),{stopReason:"end_turn"}}forwardUpdate(e,r){let i=r.sessionId,o=this.reverseSessionId(e,i);if(!o){K.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){K.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(kE(r)){K.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let l={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},u=e.activeTriggers.get(i);u&&(l.cozeTriggerMsgId=u);let f=e.activeGroupIds.get(i);f&&(l.cozeGroupId=f),this.upstream.send(Ir("session/update",{...r,sessionId:o,_meta:l})).catch(x=>K.warn("forward update failed",{agentId:e.agentId,err:String(x)}))}handleAgentRequest(e,r,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,r,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,r,i);return}K.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:Q.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},l=await q0(c,o);r.respondAgentRequest(i.id,l)}else{let c=i.params??{},l=await G0(c,o);r.respondAgentRequest(i.id,l)}}catch(o){K.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Oi(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,f=u?e.activeTriggers.get(u):void 0,x={cozeAgentId:e.agentId};f&&(x.cozeTriggerMsgId=f);let m=u?e.activeGroupIds.get(u):void 0;m&&(x.cozeGroupId=m);let w=u?this.reverseSessionId(e,u):void 0,b=w?e.sessions.get(w):void 0;b&&(b.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let p={...c,...w?{sessionId:w}:{},_meta:x};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:w}),K.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:w,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(_=>({optionId:_.optionId,kind:_.kind,name:_.name}))}),this.upstream.send(ki(o,"session/request_permission",p)).catch(_=>{this.pendingUpstream.delete(o),K.error("forward permission request failed",{agentId:e.agentId,err:String(_)}),r.respondAgentRequestError(i.id,{code:Q.INTERNAL_ERROR,message:`upstream send failed: ${String(_)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let r=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(r){this.pendingUpstream.delete(r.key);let o=r.value;this.clearPendingPermissionFor(o),e.error?(K.info("upstream \u2192 permission response (error)",{agentId:o.agentId,upstreamId:e.id,method:o.method,error:e.error}),o.downstream.respondAgentRequestError(o.agentRequestId,e.error)):(o.method==="session/request_permission"&&RE(e.result,o),K.info("upstream \u2192 permission response (result)",{agentId:o.agentId,upstreamId:e.id,method:o.method,result:e.result}),o.downstream.respondAgentRequest(o.agentRequestId,e.result));return}let i=this.lookupPending(this.pendingBridge,e.id,"bridge");if(i){this.pendingBridge.delete(i.key),clearTimeout(i.value.timer),e.error?i.value.reject(new so(e.error)):i.value.resolve(e.result);return}K.debug("orphan upstream response (no pending)",{id:e.id})}lookupPending(e,r,i){let o=e.get(r);if(o)return{value:o,key:r};if(typeof r=="number"){let c=String(r),l=e.get(c);if(l)return K.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:l,key:c}}}sendRequest(e,r,i=vE){let o=this.upstreamIds.next(e);return new Promise((c,l)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),l(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:l,timer:u}),this.upstream.send(ki(o,e,r)).catch(f=>{let x=this.pendingBridge.get(o);x&&(clearTimeout(x.timer),this.pendingBridge.delete(o)),l(f)})})}async persistSessionMapping(e){if(this.paths)try{let r=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),r.set(i,c)}await ei(e.agentId,r,this.paths)}catch(r){K.warn("persist session mapping failed",{agentId:e.agentId,err:String(r)})}}reverseSessionId(e,r){for(let[i,o]of e.sessions.entries())if(o.acpSessionId===r)return i}sendError(e,r,i){return this.upstream.send(_n(e,{code:r,message:i,data:{bridgeVersion:Sr}}))}};function CE(){return bE(16).toString("hex")}function RE(t,e){if(!t||typeof t!="object"){K.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){K.warn('permission response: top-level "kind" field (D66 historical bug shape)',{agentId:e.agentId,result:t});return}let i=r.outcome;if(!i||typeof i!="object"){K.warn("permission response: missing or non-object outcome field",{agentId:e.agentId,result:t});return}let c=i.outcome;(typeof c!="string"||c!=="selected"&&c!=="cancelled")&&K.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var DE=["Model metadata for `","Falling back from WebSockets to HTTPS transport.","Heads up: Long threads and multiple compactions can cause the model to be less accurate."];function kE(t){let e=t.update;if(e?.sessionUpdate!=="agent_message_chunk")return!1;let r=e.content;if(!r||typeof r!="object")return!1;let i=r;if(i.type!=="text"||typeof i.text!="string")return!1;let{text:o}=i;return DE.some(c=>o.startsWith(c))}ee();ke();import{randomBytes as PE}from"node:crypto";import{chmod as OE,mkdir as LE,writeFile as J0}from"node:fs/promises";import{createServer as NE}from"node:http";import{dirname as ME}from"node:path";var BE=1e6,nl=H("ipc"),yo=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??X()}async start(){this.token=PE(32).toString("hex");let e=NE((i,o)=>{this.dispatch(i,o)});this.server=e,await new Promise((i,o)=>{e.once("error",o),e.listen(0,"127.0.0.1",()=>i())});let r=e.address();if(!r||typeof r!="object")throw new Error("failed to obtain IPC port");return this.port=r.port,await this.persistAuthFiles(),nl.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 LE(ME(this.paths.portFile),{recursive:!0}),await J0(this.paths.portFile,String(this.port),"utf8"),await J0(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await OE(this.paths.tokenFile,384)}catch(e){nl.warn("chmod token file failed (non-POSIX?)",{err:String(e)})}}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Ui(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Ui(r,404,{error:"not found"});return}let l=null;if(e.method==="POST")try{l=await FE(e)}catch(u){Ui(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(l,e);Ui(r,200,u??{ok:!0})}catch(u){nl.error("IPC handler failed",{key:o,err:String(u)}),Ui(r,500,{error:u instanceof Error?u.message:String(u)})}}};function Ui(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function FE(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>BE)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}var mx=St(oh(),1);var wv=St(tx(),1),_v=St(Mo(),1),yv=St(Or(),1),Ev=St(pl(),1),bv=St(wl(),1),vv=St(Sl(),1),dx=St(Uo(),1),Sv=St(lx(),1);var ux=dx.default;We();ee();var Re=H("upstream.frontier"),hx="application/json",xx="none",Av=15e3;function Tv(t){class e extends ux{constructor(i){super(i,Af,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>Re.warn("frontier ws error during teardown (handled, prevents daemon crash)",{err:i instanceof Error?i.message:String(i)}))}close(i,o){this.guardTeardown(),super.close(i,o)}terminate(){this.guardTeardown(),super.terminate()}send(i,...o){if(ud("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let l=Buffer.from(c.slice(0,128)).toString("hex");Re.debug("WS raw frame out",{bytes:c.byteLength,headHex:l})}catch(c){Re.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var Ji=class{constructor(e){this.opts=e}opts;fws=null;handler=null;connectHandlers=[];opened=!1;lastSendRefusedLogAt=0;sendRefusedSuppressed=0;openCount=0;async start(){if(this.fws){Re.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Tf,...br(this.opts.ppeOverride)},r=Tv(e),i=Rf(this.opts.urlOverride),o={url:i,ws:r,fpID:If,aID:no,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:hx,force:!0},payloadEncoding:{encoding:xx,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new mx.FWS(o),l=!1,u=null,f,x,m=new Promise((p,_)=>{f=p,x=_}),w=p=>{l||(l=!0,u&&(clearTimeout(u),u=null),p?x(p):f())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let p=this.openCount===1;Re.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:p,openCount:this.openCount}),p&&w();for(let _ of this.connectHandlers)Promise.resolve(_({initial:p})).catch(S=>Re.warn("onConnect handler threw (ignored)",{err:String(S)}))},c.onclose=p=>{this.opened=!1,Re.info("frontier closed",{code:p.code,reason:p.reason,willReconnect:p.willReconnect})},c.onerror=p=>{Re.warn("frontier error",{code:p.code,msg:p.message}),w(new C("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${p.code} msg=${p.message??""}`))},c.onmessage=p=>this.handleMessage(p),this.fws=c;let b=this.opts.openTimeoutMs??Av;u=setTimeout(()=>{w(new C("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${b}ms (handshake or upgrade slow)`))},b),await c.connect();try{await m}catch(p){try{c.close(1e3,"open failed")}catch(_){Re.warn("fws close during start failure threw (ignored)",{err:String(_)})}throw this.fws=null,this.opened=!1,p}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){Re.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw Re.warn("frontier send refused: upstream not started",{method:i}),new C("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let u=Date.now();throw u-this.lastSendRefusedLogAt>1e3?(Re.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:r.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=u,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new C("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${r.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;px(c)||Re.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:hx,payloadEncoding:xx})}catch(u){throw Re.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new C("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){Re.debug("drop non-adapter frontier frame",{service:r});return}let i=Dv(e);if(!i){Re.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){Re.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(l){Re.warn("frontier message JSON parse failed",{err:String(l),head:i.slice(0,80)});return}let c=o;px(c)||Re.info("frontier frame in",{logid:Rv(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:Cv(i)}),Promise.resolve(this.handler(o)).catch(l=>Re.warn("frontier frame handler threw",{err:String(l)}))}};function px(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var gx=2e3;function Cv(t){return t.length<=gx?t:`${t.slice(0,gx)}...<truncated, total ${t.length} chars>`}function Rv(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function Dv(t){let e=t.message;if(e?.textPayload)return e.textPayload;let r=e?.payload;if(!r)return null;try{return Buffer.from(r).toString("utf8")}catch{return null}}ee();var Al=H("upstream.switchable"),qo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;Al.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 Al.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>Al.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()}};ee();var Tl=H("upstream"),zr=class{handler=null;async start(){Tl.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Tl.info("NoopUpstream stopped",{reason:e})}async send(e){Tl.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};We();ee();ee();ke();import{promises as Cl}from"node:fs";import{dirname as kv}from"node:path";var Pv=H("pat-token-store");async function Go(t=X()){try{let r=(await Cl.readFile(t.patTokenFile,"utf8")).trim();return r.length>0?r:null}catch(e){let r=e?.code;return r!=="ENOENT"&&Pv.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function Zi(t,e=X()){if(!t)throw new Error("writePatToken: empty patToken");await Cl.mkdir(kv(e.patTokenFile),{recursive:!0}),await Cl.writeFile(e.patTokenFile,t,{encoding:"utf8",mode:384})}ke();ke();import{promises as jo}from"node:fs";import{join as Ov}from"node:path";function Lv(t,e){return`#!/bin/sh
97
+ `}function Uy(t){if(t.includes(`
98
+ `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var Hy={path:"",version:"cloud-deployed"},b0="openclaw_gateway_unavailable",qy="openclaw_default_agent_missing";function v0(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 Gy={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},jy=6e4,po=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;detectorFactory;openclawEnvBootstrapPromise;openclawConfigFactory;openclawConfigDir;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??Fy,this.createTimeoutMs=e.createTimeoutMs??jy,this.detectorFactory=e.detectorFactory??(()=>new Hn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new ho({command:r})),this.openclawConfigDir=e.openclawConfigDir??E0(My(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new C("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{le.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=E0(e,".env");if(await Ly(r).then(c=>c.isFile()).catch(()=>!1)){le.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}await xo(e,{recursive:!0});let o=zy({...process.env,...Vc(this.paths.agentEnvFile)});if(await Ny(r,o,"utf8"),process.platform!=="win32")try{await Py(r,384)}catch(c){le.warn("chmod ~/.openclaw/.env to 0600 failed (ignored)",{err:String(c)})}le.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),le.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new C("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new C("IPC_BAD_REQUEST","framework required");let i=Ai(e._meta)==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let o=this.registry.get(e.agentId);if(o){if(o.framework!==e.framework)throw new C("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${o.framework})`);if(o.status==="error")le.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await o.dispose("rebuild after error").catch(I=>le.warn("dispose stale agent failed (ignored)",{err:String(I)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==o.patToken){le.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),o.setPatToken(e.patToken);let I=await qe(e.agentId,this.paths).catch(()=>null);I&&(I.patToken=e.patToken,await Xe(I,this.paths))}if(o.deployType==="cloud"&&e.modelInfo){le.info("updating agent modelInfo on re-create",{agentId:e.agentId}),o.setModelInfo(e.modelInfo);let I=await qe(e.agentId,this.paths).catch(()=>null);I&&(I.modelInfo=e.modelInfo,await Xe(I,this.paths))}return le.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:o.agentId,workspace:o.workspace,framework:o.framework}}}if(!i&&!this.config.frameworksCache?.[e.framework])throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let l=Ze(e.agentId,this.paths),u=Ai(e._meta),h=e.framework==="openclaw"&&u==="local",x;h&&!r?.revive&&(x=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let w=x??(h?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),_=e.workspace??w??l.workspace,S=new AbortController,E=setTimeout(()=>S.abort(new C("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),v,A=!1;try{i&&Qc(e.framework)&&await tr(e.framework,S.signal);let I=()=>{if(S.signal.aborted)throw S.signal.reason instanceof Error?S.signal.reason:new C("AGENT_TIMEOUT","_agent/create aborted")};await xo(l.root,{recursive:!0}),await xo(_,{recursive:!0}),await xo(l.logs,{recursive:!0}),I(),h||await ir(_,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(u==="cloud"?await Aa(_,"cloud"):await Aa(_,"local",ed)),I();let R=await qe(e.agentId,this.paths).catch(()=>null),L=kf({model:e.model??R?.model}),y=bf(e._meta)??R?.accountId,D=e.patToken??R?.patToken,k=u==="cloud"?e.modelInfo??R?.modelInfo:void 0;if(v=new uo({agentId:e.agentId,framework:e.framework,workspace:_,model:L.model??yt,deployType:u,...y?{accountId:y}:{},...D?{patToken:D}:{},...k?{modelInfo:k}:{}}),v.status="ok",R?.sessions){let V=u==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[te,$]of Object.entries(R.sessions)){let ce={acpSessionId:$.acpSessionId,modelToken:$.modelToken,tokenGeneratedAt:$.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};V?$.permissionMode===void 0?(ce.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",le.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:te,framework:e.framework,fallback:ce.permissionMode})):yn(e.framework,$.permissionMode)?ce.permissionMode=$.permissionMode:le.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:te,framework:e.framework,value:$.permissionMode}):$.permissionMode!==void 0&&le.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:te,framework:e.framework,deployType:u}),$.cozeGroupId&&(ce.cozeGroupId=$.cozeGroupId),v.sessions.set(te,ce)}let J=Object.keys(R.sessions).length;J>0&&le.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:J})}this.registry.register(v),A=!0;let N={agentId:e.agentId,framework:e.framework,workspace:_,cozeIdentity:e.cozeIdentity,createdAt:R?.createdAt??Date.now(),sessions:R?.sessions??{},model:L.model};u==="cloud"&&(N.deployType="cloud"),y&&(N.accountId=y),D&&(N.patToken=D),k&&(N.modelInfo=k),R?.skills&&(N.skills=R.skills),R?.agentName&&(N.agentName=R.agentName),R?.description&&(N.description=R.description),e.framework==="openclaw"&&u==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,_)):le.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let B=e.initialSkills??[];if(B.length>0){let V=[...N.skills??[]],J=new Map(V.map((ce,pe)=>[ce.skillId,pe])),te=await Promise.allSettled(B.map(ce=>Kc({agentId:e.agentId,workspace:_,framework:e.framework,skill:ce}))),$=0;for(let[ce,pe]of te.entries()){let O=B[ce];O&&(pe.status==="fulfilled"?($c(V,J,pe.value),$++):le.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:O.skillId,skillName:O.skillName,err:String(pe.reason)}))}$>0&&(N.skills=V,le.info("initialSkills installed",{agentId:e.agentId,installed:$,requested:B.length}))}return await Xe(N,this.paths),le.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:u}),{ok:!0,agentId:e.agentId,workspace:_,framework:e.framework}}catch(I){throw le.error("agent create failed, rolling back",{agentId:e.agentId,err:String(I)}),A&&v&&(await v.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Oy(l.root,{recursive:!0,force:!0}).catch(R=>le.warn("rm agent dir failed (ignored)",{err:String(R)})),I instanceof C?I:new C("AGENT_SPAWN_FAILED",String(I),{cause:I})}finally{clearTimeout(E)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&Qc(e.framework))u=Hy;else throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);Qc(e.framework)&&!rs(e.framework)&&(le.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await tr(e.framework));let h=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,x;if(e.framework==="openclaw")x=await this.buildOpenclawDownstream({session:e,modelConfig:h,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path});else{let w=e.sessions.get(i),_=Wt(e)?w?.permissionMode??S0:"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(Gy),x}catch(w){let _=x instanceof Pt?x.getStderrTail():[];throw _.length>0&&le.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:w instanceof C?w.code:"unknown",recentStderr:_}),await x.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,w)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new C("AGENT_ENV_NOT_READY",v0(o),{cause:{reason:b0}})}catch(o){le.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof C?new C(i.code,i.message,{retriable:i.retriable,cause:i.cause??i}):new C("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};le.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return le.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new C("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:qy}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new C("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new C("AGENT_ENV_NOT_READY",v0(r),{cause:{reason:b0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:l,command:u}=e,h=Xc(o);if(r.deployType==="local"){let S=await this.ensureOpenclawDefaultAgent();return new Rr({command:u,cwd:S.workspace,agentId:S.id,sessionName:h})}let x=await y0(),w=i?Bf(i,c,l):null,_;if(w){let S=zc(o),v=w.models[0]?.id??yt,A=`${S}/${v}`;if(!this.ensuredProviders.has(A)){let I=this.getOpenclawConfig();await I.ensureProvider(S,w),await I.addModelToAllowlist(A),this.ensuredProviders.add(A)}_=A}return new Rr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:h,...x?{gatewayToken:x}:{},..._?{slashModelOnStart:_}:{}})}async openclawRepair(e,r){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,r)}async cleanupOpenclawSessionProviders(e){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let r=this.openclawConfigCache;for(let i of e.sessions.keys()){let o=zc(i),c=`${o}/${e.model}`,l=!0;try{await r.removeProvider(o)}catch(u){l=!1,le.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){l=!1,le.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}l&&this.ensuredProviders.delete(c)}}};import{randomUUID as D0}from"node:crypto";import{promises as Xy}from"node:fs";import{basename as k0}from"node:path";We();ne();import{promises as Ky}from"node:fs";import{basename as $y}from"node:path";var A0=U("file-upload"),Jy="/api/coze_claw/file/agent_upload",Vy=6e4;async function T0(t,e={}){let i=`${Qs(to(e.handshakeBase))}${Jy}`,o=e.timeoutMs??Vy,c=await Ky.readFile(t.path),l=new FormData;l.append("agent_id",t.agentId),l.append("session_id",t.sessionId),l.append("file_name",t.name),l.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let u={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...br(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},h=new AbortController,x=setTimeout(()=>h.abort(),o);A0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let w=await fetch(i,{method:"POST",headers:u,body:l,signal:h.signal}),_=w.headers.get("x-tt-logid")??"";if(!w.ok){let v=await w.text().catch(()=>"");throw new C("UPLOAD_FAILED",`upload HTTP ${w.status} logid=${_}: ${v.slice(0,200)}`)}let S=await w.json();if(S.code!==void 0&&S.code!==0)throw new C("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${_}`);let E=S.data?.file?.file_url;if(!E)throw new C("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${_}: ${JSON.stringify(S).slice(0,200)}`);return A0.info("file upload ok",{uri:E,logid:_}),{uri:E}}catch(w){throw w instanceof C?w:w.name==="AbortError"?new C("UPLOAD_FAILED",`upload timeout (${o}ms) for ${$y(t.path)}`):new C("UPLOAD_FAILED",String(w),{cause:w})}finally{clearTimeout(x)}}We();ne();import{extname as Yy}from"node:path";var Zy={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".svg":"image/svg+xml",".bmp":"image/bmp",".ico":"image/x-icon",".heic":"image/heic",".heif":"image/heif",".pdf":"application/pdf",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".txt":"text/plain",".md":"text/markdown",".markdown":"text/markdown",".json":"application/json",".yaml":"text/yaml",".yml":"text/yaml",".csv":"text/csv",".html":"text/html",".htm":"text/html",".xml":"application/xml",".log":"text/plain",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".tgz":"application/gzip",".mp3":"audio/mpeg",".wav":"audio/wav",".mp4":"video/mp4",".mov":"video/quicktime",".webm":"video/webm"};async function C0(t){let e=Yy(t).toLowerCase();return Zy[e]??"application/octet-stream"}ke();var go=U("agent-send"),R0=50*1024*1024;function P0(t,e,r){let i=t.get(e);if(!i)throw new C("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new C("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new C("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function O0(t,e,r,i,o,c){let u;for(let h=0;h<=2;h++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(x){u=x,h<2&&(go.warn("sendAgentFileUpdate failed, retrying",{attempt:h+1,err:String(x)}),await new Promise(w=>setTimeout(w,5e3)))}throw new C("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function L0(t,e){let{session:r,runtime:i}=P0(e.core,t.agentId,t.sessionId);if(!await Xr(t.path,r.workspace))throw new C("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await Xy.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new C("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>R0)throw new C("FILE_TOO_LARGE",`${o.size} bytes > limit ${R0}`);let c=await C0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new C("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new C("UPSTREAM_NOT_READY","cloud WS not connected");let l=t.name??k0(t.path),u;try{u=await T0({patToken:r.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:l,sizeBytes:o.size,...r.accountId?{accountId:r.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(x){throw go.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:x instanceof C?x.code:"UNKNOWN",message:x instanceof Error?x.message:String(x)}),x}let h={sessionUpdate:"agent_file",messageId:D0(),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 O0(e,r,i,t.sessionId,h,"agent file uploaded to cloud but sendAgentFileUpdate failed"),go.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:l,bytes:o.size,mime:c,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:c,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function N0(t,e){let{session:r,runtime:i}=P0(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new C("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new C("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??k0(t.path),c={sessionUpdate:"group_file",messageId:D0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await O0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),go.info("agent group file sent",{agentId:t.agentId,sessionId:t.sessionId,uri:t.path,name:o,mime:t.mimeType}),{ok:!0,uri:t.path,bytes:0,mimeType:t.mimeType}}function M0(t,e){let r=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(r.length,i.length);for(let c=0;c<o;c++){let l=r[c]??0,u=i[c]??0;if(l<u)return!0;if(l>u)return!1}return!1}tn();_n();ne();var Ot=U("coze-cli-installer"),B0="@coze/cli@latest",Qy="coze",F0="0.1.8",eE=5e3,tE=5e3,nE=9e4,z0=1e4,Ni=null,mo=!1;async function td(t,e={}){if(mo)return;if(Ni)return Ni;let r=e.exec??r0;return Ni=(async()=>{try{let i=await rE(Qy,r),o=!1;if(i){let l=await iE(r);if(l===void 0)Ot.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(M0(l,F0))Ot.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:l,min:F0}),o=!0;else{Ot.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:l}),mo=!0;return}}let c=o?"upgrade-only":"full";Ot.info("coze-cli install start",{package:B0,mode:c});try{await r("npm",["i","-g","--prefer-online",B0],{timeout:nE,maxBuffer:10*1024*1024}),Ot.info("coze-cli install ok")}catch(l){Ot.warn("coze-cli install failed (skip subsequent steps)",{err:String(l)});return}if(o){mo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:z0}),Ot.info("coze config set xTTEnv ok",{env:t.env})}catch(l){Ot.warn("coze config set failed (continue to auth login)",{err:String(l)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:z0}),Ot.info("coze auth login ok")}catch(l){Ot.warn("coze auth login failed",{err:String(l)});return}mo=!0}finally{Ni=null}})(),Ni}async function rE(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:eE});return Sa(i)}catch{return}}async function iE(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:tE});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}Zr();ke();var sE=10*6e4;function U0(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?sE:e}function wo(t){return nr(t??Q().configFile)}function Mi(t,e){return rr(e??Q().configFile,t)}import{randomBytes as IE}from"node:crypto";Kr();We();ne();import{createReadStream as oE}from"node:fs";import{mkdir as aE,readFile as cE,realpath as dE,stat as lE,writeFile as uE}from"node:fs/promises";import{basename as fE,dirname as nd,isAbsolute as hE,join as xE,relative as pE,resolve as H0,sep as gE}from"node:path";import{createInterface as mE}from"node:readline";var G0=U("fs-rpc"),Bi=Ye("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function j0(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Bi)throw new C("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Bi} bytes`);let i=await K0(t.path,e);return await aE(nd(i),{recursive:!0}),await uE(i,t.content,"utf8"),G0.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function W0(t,e){let r=await K0(t.path,e),i=await lE(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Bi&&!o)throw new C("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Bi} bytes`);let c;if(o&&i.size>Bi)c=await wE(r,t.line??1,t.limit);else{let l=await cE(r,"utf8");if(o){let u=l.split(`
99
+ `),h=Math.max(0,(t.line??1)-1),x=typeof t.limit=="number"?h+t.limit:void 0;c=u.slice(h,x).join(`
100
+ `)}else c=l}return G0.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function wE(t,e,r){let i=mE({input:oE(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,l=[],u=0;try{for await(let h of i)if(u>=o&&u<c&&l.push(h),u++,u>=c)break}finally{i.close()}return l.join(`
101
+ `)}async function K0(t,e){if(typeof t!="string"||t.length===0)throw new C("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([q0(H0(e)),q0(H0(t))]),o=pE(r,i);if(_E(o,gE,hE(o)))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function _E(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function q0(t){let e=[],r=t;for(;r!==nd(r);)try{let i=await dE(r);return e.length?xE(i,...e.reverse()):i}catch{e.push(fE(r)),r=nd(r)}return t}ne();var $0=U("prompt-multimodal"),J0=10*1024*1024,yE=15e3,EE=6;async function V0(t){let e=new Array(t.length),r=0;async function i(){for(;r<t.length;){let c=r++,l=t[c];l!==void 0&&(e[c]=await bE(l))}}let o=Array.from({length:Math.min(EE,t.length)},()=>i());return await Promise.all(o),e}function Y0(t){return t.some(e=>e.type==="image")}async function bE(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Xs(e.uri))return t;try{let{buf:r,contentType:i}=await SE(e.uri),o=e.mimeType||vE(i)||"application/octet-stream";return $0.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 $0.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function vE(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function SE(t){let e=new AbortController,r=setTimeout(()=>e.abort(),yE);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new Error(`HTTP ${i.status} ${i.statusText}`);let o=await i.arrayBuffer();if(o.byteLength>J0)throw new Error(`image too large: ${o.byteLength} bytes (max ${J0})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}nn();We();ne();var W=U("core"),AE=3e4,TE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,CE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",RE="\u5BA1\u6279\u5DF2\u8D85\u65F6",DE=3e4,_o=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Tr;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=U0(e.bridgeConfig)}registerExtension(e,r){this.extensions[e]=r}getCozeEnv(){return this.currentCozeEnv}getMockScenario(){return this.currentMockScenario}setMockScenario(e){this.currentMockScenario=e&&e.length>0?e:void 0}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),W.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){W.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(r=>r.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}async reloadAgents(e){let r=e?this.agents.has(e)?[e]:[]:[...this.agents.keys()];for(let i of r)await this.agents.get(i)?.killAllRuntimes("reload");return r}get(e){return this.agents.get(e)}register(e){this.agents.set(e.agentId,e),W.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){W.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(i)})}}onAgentRegister(e){return this.registerHandlers.add(e),()=>this.registerHandlers.delete(e)}registerHandlers=new Set;unregister(e){this.agents.delete(e)}reviveIfDisconnected(e){this.disconnectedAgents.delete(e)&&W.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,r,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,l)=>{W.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:l}),Li(i),i.downstream=void 0,i.replySeq=0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),this.rejectPendingForDownstream(o,"downstream exited")}))}hasPendingPermissionFor(e){for(let r of this.pendingUpstream.values())if(r.downstream===e)return!0;return!1}rejectPendingForDownstream(e,r){let i=[];for(let[o,c]of this.pendingUpstream)c.downstream===e&&i.push(o);if(i.length!==0){W.info("reject pendingUpstream entries (downstream gone)",{reason:r,count:i.length});for(let o of i){let c=this.pendingUpstream.get(o);if(c){this.pendingUpstream.delete(o),this.upstream.send(wn(o,{code:ee.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(l=>W.debug("send error response to upstream failed (ignored)",{err:String(l)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:ee.INTERNAL_ERROR,message:`bridge: ${r}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,r=this.pendingBridge.size;if(!(e===0&&r===0)){W.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:r});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:ee.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new C("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(io(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let r="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&TE.test(i)?this.currentCozeEnv=i:i&&W.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});try{if(e.method.startsWith("_agent/")){let o=this.extensions[e.method];if(!o){r!==null?await this.sendError(r,ee.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):W.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(Ar(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Ar(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Ar(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,ee.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):W.warn("drop unknown notification",{method:e.method})}catch(o){W.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(wn(r,Oi(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new C("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new C("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new C("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new C("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||e.method==="session/set_mode"||!c)return this.dispatchSessionCall(o,e.method,r);if(e.method==="session/prompt"){let h=o.sessions.get(c);if(h?.pendingPermission){let x=r._meta?.cozeTriggerMsgId,w=Zs(r._meta);return W.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,h,c,CE,x,w)}}let l=Date.now(),u=!1;try{let h=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,h}finally{W.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-l,ok:u})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=Sf(i);switch(r){case"session/new":{let c=kE();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 C("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=Wt(e)?vf(i._meta):void 0;if(u!==void 0&&!yn(e.framework,u))throw new C("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${Zc(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 C("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(E){throw h.permissionMode=S,await this.persistSessionMapping(e).catch(()=>{}),E}}let x=i._meta?.cozeTriggerMsgId;x?e.activeTriggers.set(h.acpSessionId,x):e.activeTriggers.delete(h.acpSessionId);let w=Zs(i._meta);if(w?e.activeGroupIds.set(h.acpSessionId,w):e.activeGroupIds.delete(h.acpSessionId),w&&h.cozeGroupId!==w&&(h.cozeGroupId=w,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&Y0(c.prompt))throw new C("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let _=await V0(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 C&&S.code==="AGENT_APPROVAL_TIMEOUT"){let E=h.pendingPermission;E&&(E.downstream.respondAgentRequest(E.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(E.upstreamId),h.pendingPermission=void 0);let v=h.acpSessionId,A=v?e.activeTriggers.get(v):void 0,I=v?e.activeGroupIds.get(v):void 0;return W.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:l}),await this.synthesizePromptReply(e,h,l,RE,A,I)}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(E=>W.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:l,err:String(E)})))}else h.downstream?.isAlive()&&this.armIdleTimer(e,l,h)}}case"session/cancel":{let l=o.sessionId;if(!l)throw new C("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(l);if(e.hasSessionQueue(l)){let h=e.getSessionQueue(l);h.size>0&&(W.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:l,queuedCount:h.size}),h.dispose(new C("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${l}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,l=c.sessionId,u=c.modeId,h=Zs(i._meta);if(!l)throw new C("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Wt(e))throw e.framework==="openclaw"?new C("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new C("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!yn(e.framework,u))throw new C("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${Zc(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 w=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=w,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 C("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async handleGroupSetMode(e,r,i){let o=[];for(let[l,u]of e.sessions)u.cozeGroupId===r&&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:r,modeId:i}),{};W.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i,targets:o.length});for(let 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,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 Wt(e)&&(c.permissionMode=e.framework==="claude-code"?ed:I0),e.sessions.set(r,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,r){let i={sessionId:r,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(_t.GEN_MODEL_TOKEN,i,DE);if(!o?.modelToken)throw new C("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof C&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new C("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(Li(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new C("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,l=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(l>=o&&Date.now()-u<c)throw new C("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${l} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let h;try{h=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(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:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),x}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=h,this.attachRuntimeHooks(e,r,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await h.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),W.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(x){W.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(x)}),i.acpSessionId=void 0;let w=await h.sessionNew({cwd:e.workspace});i.acpSessionId=w.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:r,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),Wt(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:r,mode:i.permissionMode,err:String(x)})}}armIdleTimer(e,r,i){if(Li(i),this.isRuntimeBusy(e,i)){W.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:r});return}i.idleTimer=setTimeout(()=>{if(i.idleTimer=void 0,this.isRuntimeBusy(e,i)){W.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}W.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:r});let o=i.downstream;i.downstream=void 0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),o&&o.stop("idle timeout").catch(c=>W.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:r,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,r){if(r.acpSessionId&&e.activeTriggers.has(r.acpSessionId))return!0;let i=r.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,r,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};if(r.acpSessionId){let l=e.activeTriggers.get(r.acpSessionId);l&&(c.cozeTriggerMsgId=l);let u=e.activeGroupIds.get(r.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Ir("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,l){let u={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(u.cozeTriggerMsgId=c),l&&(u.cozeGroupId=l),await this.upstream.send(Ir("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(h=>W.warn("synthesizePromptReply update send failed (ignored)",{err:String(h)})),{stopReason:"end_turn"}}forwardUpdate(e,r){let i=r.sessionId,o=this.reverseSessionId(e,i);if(!o){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(LE(r)){W.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let l=r.update;if(l&&typeof l=="object"&&l.sessionUpdate==="current_mode_update"&&Wt(e)){let w=l.currentModeId;yn(e.framework,w)&&c.permissionMode!==w?(c.permissionMode=w,this.persistSessionMapping(e).catch(_=>W.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(_)}))):typeof w=="string"&&!yn(e.framework,w)&&W.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:w})}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(Ir("session/update",{...r,sessionId:o,_meta:u})).catch(w=>W.warn("forward update failed",{agentId:e.agentId,err:String(w)}))}handleAgentRequest(e,r,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,r,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,r,i);return}W.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:ee.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},l=await j0(c,o);r.respondAgentRequest(i.id,l)}else{let c=i.params??{},l=await W0(c,o);r.respondAgentRequest(i.id,l)}}catch(o){W.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Oi(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,h=u?e.activeTriggers.get(u):void 0,x={cozeAgentId:e.agentId};h&&(x.cozeTriggerMsgId=h);let w=u?e.activeGroupIds.get(u):void 0;w&&(x.cozeGroupId=w);let _=u?this.reverseSessionId(e,u):void 0,S=_?e.sessions.get(_):void 0;S&&(S.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let E={...c,..._?{sessionId:_}:{},_meta:x};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:_}),W.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:_,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(v=>({optionId:v.optionId,kind:v.kind,name:v.name}))}),this.upstream.send(ki(o,"session/request_permission",E)).catch(v=>{this.pendingUpstream.delete(o),W.error("forward permission request failed",{agentId:e.agentId,err:String(v)}),r.respondAgentRequestError(i.id,{code:ee.INTERNAL_ERROR,message:`upstream send failed: ${String(v)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let r=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(r){this.pendingUpstream.delete(r.key);let o=r.value;this.clearPendingPermissionFor(o),e.error?(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"&&PE(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 ro(e.error)):i.value.resolve(e.result);return}W.debug("orphan upstream response (no pending)",{id:e.id})}lookupPending(e,r,i){let o=e.get(r);if(o)return{value:o,key:r};if(typeof r=="number"){let c=String(r),l=e.get(c);if(l)return W.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:l,key:c}}}sendRequest(e,r,i=AE){let o=this.upstreamIds.next(e);return new Promise((c,l)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),l(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:l,timer:u}),this.upstream.send(ki(o,e,r)).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 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&&Wt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await Qr(e.agentId,r,this.paths)}catch(r){W.warn("persist session mapping failed",{agentId:e.agentId,err:String(r)})}}reverseSessionId(e,r){for(let[i,o]of e.sessions.entries())if(o.acpSessionId===r)return i}sendError(e,r,i){return this.upstream.send(wn(e,{code:r,message:i,data:{bridgeVersion:Sr}}))}};function kE(){return IE(16).toString("hex")}function PE(t,e){if(!t||typeof t!="object"){W.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){W.warn('permission response: top-level "kind" field (D66 historical bug shape)',{agentId:e.agentId,result:t});return}let i=r.outcome;if(!i||typeof i!="object"){W.warn("permission response: missing or non-object outcome field",{agentId:e.agentId,result:t});return}let c=i.outcome;(typeof c!="string"||c!=="selected"&&c!=="cancelled")&&W.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var OE=["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 LE(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 OE.some(c=>o.startsWith(c))}ne();ke();import{randomBytes as NE}from"node:crypto";import{chmod as ME,mkdir as BE,writeFile as Z0}from"node:fs/promises";import{createServer as FE}from"node:http";import{dirname as zE}from"node:path";var UE=1e6,rd=U("ipc"),yo=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??Q()}async start(){this.token=NE(32).toString("hex");let e=FE((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(),rd.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 BE(zE(this.paths.portFile),{recursive:!0}),await Z0(this.paths.portFile,String(this.port),"utf8"),await Z0(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await ME(this.paths.tokenFile,384)}catch(e){rd.warn("chmod token file failed (non-POSIX?)",{err:String(e)})}}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Fi(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Fi(r,404,{error:"not found"});return}let l=null;if(e.method==="POST")try{l=await HE(e)}catch(u){Fi(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(l,e);Fi(r,200,u??{ok:!0})}catch(u){rd.error("IPC handler failed",{key:o,err:String(u)}),Fi(r,500,{error:u instanceof Error?u.message:String(u)})}}};function Fi(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function HE(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>UE)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}var yx=St(ch(),1);var bv=St(rx(),1),vv=St(Mo(),1),Sv=St(Pr(),1),Iv=St(gd(),1),Av=St(_d(),1),Tv=St(Id(),1),fx=St(Uo(),1),Cv=St(ux(),1);var hx=fx.default;We();ne();var Ce=U("upstream.frontier"),px="application/json",gx="none",Dv=15e3;function kv(t){class e extends hx{constructor(i){super(i,Af,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>Ce.warn("frontier ws error during teardown (handled, prevents daemon crash)",{err:i instanceof Error?i.message:String(i)}))}close(i,o){this.guardTeardown(),super.close(i,o)}terminate(){this.guardTeardown(),super.terminate()}send(i,...o){if(ul("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");Ce.debug("WS raw frame out",{bytes:c.byteLength,headHex:l})}catch(c){Ce.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var $i=class{constructor(e){this.opts=e}opts;fws=null;handler=null;connectHandlers=[];opened=!1;lastSendRefusedLogAt=0;sendRefusedSuppressed=0;openCount=0;async start(){if(this.fws){Ce.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Tf,...br(this.opts.ppeOverride)},r=kv(e),i=Rf(this.opts.urlOverride),o={url:i,ws:r,fpID:If,aID:eo,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:px,force:!0},payloadEncoding:{encoding:gx,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new yx.FWS(o),l=!1,u=null,h,x,w=new Promise((E,v)=>{h=E,x=v}),_=E=>{l||(l=!0,u&&(clearTimeout(u),u=null),E?x(E):h())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let E=this.openCount===1;Ce.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:E,openCount:this.openCount}),E&&_();for(let v of this.connectHandlers)Promise.resolve(v({initial:E})).catch(A=>Ce.warn("onConnect handler threw (ignored)",{err:String(A)}))},c.onclose=E=>{this.opened=!1,Ce.info("frontier closed",{code:E.code,reason:E.reason,willReconnect:E.willReconnect})},c.onerror=E=>{Ce.warn("frontier error",{code:E.code,msg:E.message}),_(new C("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${E.code} msg=${E.message??""}`))},c.onmessage=E=>this.handleMessage(E),this.fws=c;let S=this.opts.openTimeoutMs??Dv;u=setTimeout(()=>{_(new C("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${S}ms (handshake or upgrade slow)`))},S),await c.connect();try{await w}catch(E){try{c.close(1e3,"open failed")}catch(v){Ce.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,E}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){Ce.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw Ce.warn("frontier send refused: upstream not started",{method:i}),new C("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let u=Date.now();throw u-this.lastSendRefusedLogAt>1e3?(Ce.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:r.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=u,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new C("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${r.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;mx(c)||Ce.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:px,payloadEncoding:gx})}catch(u){throw Ce.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new C("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){Ce.debug("drop non-adapter frontier frame",{service:r});return}let i=Lv(e);if(!i){Ce.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){Ce.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(l){Ce.warn("frontier message JSON parse failed",{err:String(l),head:i.slice(0,80)});return}let c=o;mx(c)||Ce.info("frontier frame in",{logid:Ov(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:Pv(i)}),Promise.resolve(this.handler(o)).catch(l=>Ce.warn("frontier frame handler threw",{err:String(l)}))}};function mx(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var _x=2e3;function Pv(t){return t.length<=_x?t:`${t.slice(0,_x)}...<truncated, total ${t.length} chars>`}function Ov(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function Lv(t){let e=t.message;if(e?.textPayload)return e.textPayload;let r=e?.payload;if(!r)return null;try{return Buffer.from(r).toString("utf8")}catch{return null}}ne();var Td=U("upstream.switchable"),qo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;Td.info("swap upstream",{reason:r});let i=this.inner;if(this.inner=e,this.handler&&e.onFrame(this.handler),e.onConnect)for(let o of this.connectHandlers)e.onConnect(o);try{await e.start()}catch(o){throw Td.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>Td.warn("previous upstream stop threw (ignored)",{err:String(o)}))}current(){return this.inner}start(){return this.inner.start()}stop(e){return this.inner.stop(e)}send(e){return this.inner.send(e)}onFrame(e){this.handler=e,this.inner.onFrame(e)}onConnect(e){this.connectHandlers.push(e),this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};ne();var Cd=U("upstream"),Fr=class{handler=null;async start(){Cd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Cd.info("NoopUpstream stopped",{reason:e})}async send(e){Cd.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};We();ne();ne();ke();import{promises as Rd}from"node:fs";import{dirname as Nv}from"node:path";var Mv=U("pat-token-store");async function Go(t=Q()){try{let r=(await Rd.readFile(t.patTokenFile,"utf8")).trim();return r.length>0?r:null}catch(e){let r=e?.code;return r!=="ENOENT"&&Mv.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function Ji(t,e=Q()){if(!t)throw new Error("writePatToken: empty patToken");await Rd.mkdir(Nv(e.patTokenFile),{recursive:!0}),await Rd.writeFile(e.patTokenFile,t,{encoding:"utf8",mode:384})}ke();ke();import{promises as jo}from"node:fs";import{join as Bv}from"node:path";function Fv(t,e){return`#!/bin/sh
103
102
  exec ${JSON.stringify(e)} ${JSON.stringify(t)} "$@"
104
- `}function Nv(t,e){return`@echo off\r
103
+ `}function zv(t,e){return`@echo off\r
105
104
  "${e}" "${t}" %*\r
106
- `}async function _x(t,e=X()){let r=e.binDir;await jo.mkdir(r,{recursive:!0});let i=Ov(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?Nv(t,o):Lv(t,o);return await jo.readFile(i,"utf8").catch(()=>null)===c||(await jo.writeFile(i,c,"utf8"),process.platform!=="win32"&&await jo.chmod(i,493)),r}ee();ke();import{execSync as yx}from"node:child_process";import{readFileSync as Ex,unlinkSync as Mv}from"node:fs";import{mkdir as Bv,open as Fv,readFile as bx,unlink as Rl,writeFile as zv}from"node:fs/promises";import{dirname as Uv}from"node:path";var Hv=H("single-instance"),qv=t=>new Promise(e=>setTimeout(e,t)),Wo=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??X().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:r=>Li(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&&Hv.warn("removing stale pid file",{stalePid:i}),await zv(this.pidFile,String(this.selfPid),"utf8"),{kind:"acquired"})});return r.kind==="acquired"&&(this.acquired=!0,this.installCleanupHooks()),r}async release(){if(this.acquired){try{(await bx(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Rl(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 bx(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 Bv(Uv(r),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await Fv(r,"wx")}catch(c){if(c.code!=="EEXIST")throw c;let l=await this.readPidFrom(r);if(l!==null&&l!==this.selfPid&&this.probe.isAlive(l)){await qv(this.claimLockIntervalMs);continue}await Rl(r).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Rl(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=Ex(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes(Cr)||r.includes("lib/index.js"))}catch{}try{let r=yx(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes(Cr)||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=yx(`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{Ex(this.pidFile,"utf8").trim()===String(this.selfPid)&&Mv(this.pidFile)}catch{}})}};Ko();ee();var $n=H("daemon.upstream-watchdog"),Zv=12e4,Yv=9e5,Xv=3e4;function kl(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var $o=class{constructor(e){this.opts=e;this.softMs=e.softMs??kl("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",Zv),this.hardMs=e.hardMs??kl("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",Yv),this.intervalMs=e.intervalMs??kl("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",Xv),this.now=e.now??Date.now}opts;softMs;hardMs;intervalMs;now;timer=null;downSince=null;forcedAt=null;forcing=!1;lastTickAt=null;start(){this.timer||(this.timer=setInterval(()=>this.tick(),this.intervalMs),this.timer.unref?.(),$n.info("upstream watchdog started",{softMs:this.softMs,hardMs:this.hardMs,intervalMs:this.intervalMs}))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null),this.downSince=null,this.forcedAt=null,this.lastTickAt=null}tick(){let e=this.now();if(this.lastTickAt!==null&&e-this.lastTickAt>this.intervalMs*3&&(this.downSince!==null&&$n.warn("upstream watchdog: large tick gap (likely sleep/suspend), resetting downSince",{gapMs:e-this.lastTickAt}),this.downSince=null,this.forcedAt=null),this.lastTickAt=e,this.opts.isConnected()){this.downSince!==null&&$n.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,$n.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){$n.error("upstream watchdog: disconnected too long, exiting for supervisor restart",{downMs:r,hardMs:this.hardMs}),this.opts.onFatal(r);return}r>=this.softMs&&this.shouldForceNow(e)&&(this.forcedAt=e,this.forcing=!0,$n.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>$n.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var G=H("daemon");async function Ix(){let t=X();process.env.COZE_BRIDGE_LOG_MODE!=="legacy"&&ld({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:O=>Ze(O,t).logs,listAgentIds:()=>os(t)});let e=new Wo({processTitle:Cr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await wo(),o=i??{};is({pid:process.pid}),G.info(i?"loaded bridge config":"initialized bridge config");let c=new qo(new zr),l=null,u=new _o({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(O,q,j,re)=>{if(!l)throw new Error("agentManager not ready");return l.spawnSessionDownstream(O,q,j,re)}}),f=new po({paths:t,config:o,registry:u});l=f;let x,m,w=null,b={},p,_=null,S=null,A=null,T=new En;function D(O,q){return T.enqueue(()=>k(O,q))}function E(){S||(S=new $o({isConnected:()=>c.isConnected(),forceReconnect:()=>A?D(A,{force:!0}):void 0,onFatal:O=>{if(process.env[Yi]==="1"){G.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:O});return}G.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:O}),process.exit(1)}})),S.start()}async function k(O,q){let j=O,re=j?.privatecode;if(!re)throw new C("IPC_BAD_REQUEST","/connect requires privatecode");let Ve=Ci(j.env),de=j.handshake_url,ue=j.frontier_url,vt=Sx(j.env,de,ue);if(A=j,!q?.force&&x===re&&m===vt){let ge=await Qv(t);return u.agents.size===0&&ge?(G.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),Jo(t,f).catch(Se=>G.warn("connect-noop auto-revive error (ignored)",{err:String(Se)}))):G.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let dt=!!x&&x!==re,Xt=m!==void 0&&m!==vt,Ft=dt||Xt,Qt=await Mc({privatecode:re,...de?{endpoint:de}:{},ppeOverride:Ve});if(Ft){G.warn("connect config switched, resetting agents",{pcChanged:dt,envChanged:Xt,previousPc:x?Vo(x):"",nextPc:Vo(re)});for(let ge of[...u.agents.values()])await ge.dispose("connect config switch").catch(()=>{}),u.agents.delete(ge.agentId);u.disconnectedAgents.size>0&&(G.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new zr,"connect switch").catch(()=>{})}w=Qt.deviceId,is({deviceId:w,pid:process.pid}),el({patToken:re,env:j.env}).catch(ge=>G.warn("coze-cli setup error (ignored)",{err:String(ge)}));let jr=new Ji({handshake:Qt,privatecode:re,...ue?{urlOverride:ue}:{},ppeOverride:Ve,getPatTokenForAgent:ge=>u.agents.get(ge)?.patToken});return await c.swap(jr,"connect"),x=re,m=vt,b=Ve,p=de,j.mock_scenario!==void 0&&(u.setMockScenario(j.mock_scenario),G.info("mock scenario set",{scenario:j.mock_scenario})),_||(_=new Di({core:u,getDeviceId:()=>w??"",onTickEnd:()=>N.retryPending().catch(ge=>G.warn("detailSync.retryPending failed (ignored)",{err:String(ge)})),onAuthFailures:$})),_.start(),E(),Ft&&Jo(t,f).catch(ge=>G.warn("post-connect-switch auto-revive error (ignored)",{err:String(ge)})),Zi(re,t).catch(ge=>G.warn("writePatToken after /connect failed (ignored)",{err:String(ge)})),G.info("/connect: WS established",{deviceId:w}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async O=>f.createAgent(O.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let P={},B=new io({agents:u.agents,disposeAndMarkDisconnected:async(O,q)=>{let j=u.agents.get(O);if(j){await f.cleanupOpenclawSessionProviders(j).catch(Ve=>G.warn("cleanup openclaw providers failed (ignored)",{agentId:O,err:String(Ve)}));let re=!0;try{await j.dispose(`disconnect: ${q}`)}catch(Ve){re=!1,G.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:O,err:String(Ve)}),j.status="error"}re&&(j.status="disconnected",u.unregister(O),u.disconnectedAgents.add(O))}else u.disconnectedAgents.add(O)},detailSyncer:async O=>{if(!P.ref)throw new Error("agent-detail-sync not initialized yet");await P.ref.syncOne(O)},cleanupOpenclawProviders:async O=>{await f.cleanupOpenclawSessionProviders(O)},openclawRepair:async(O,q)=>{await f.openclawRepair(O,q)},isRuntimePendingPermission:O=>u.hasPendingPermissionFor(O)});u.registerExtension("_agent/listSkills",O=>B.listSkills(O.params)),u.registerExtension("_agent/addSkills",O=>B.addSkills(O.params)),u.registerExtension("_agent/removeSkills",O=>B.removeSkills(O.params)),u.registerExtension("_agent/getFileTree",O=>B.getFileTree(O.params)),u.registerExtension("_agent/getFileContent",O=>B.getFileContent(O.params)),u.registerExtension("_agent/update",O=>B.updateAgent(O.params)),u.registerExtension("_agent/disconnect",O=>B.disconnectAgent(O.params)),u.registerExtension("_agent/switchModel",O=>B.switchModel(O.params)),u.registerExtension("_agent/reset",O=>B.resetAgent(O.params)),u.registerExtension("_agent/repair",O=>B.repairAgent(O.params));let N=new ds({paths:t,handlers:B,agentManager:f,sendDetail:O=>u.sendRequest("_agent/detail",O)});P.ref=N;let $=async O=>{await Promise.allSettled(O.map(async q=>{try{await B.disconnectAgent({agentId:q.agentId,reason:`auth_failure: code=${q.code} ${q.message}`}),G.info("agent disconnected due to auth failure from heartbeat response",{agentId:q.agentId,code:q.code,message:q.message})}catch(j){G.warn("disconnect during authFailure handling failed (ignored)",{agentId:q.agentId,err:String(j)})}}))};c.onConnect(({initial:O})=>{G.info("frontier upstream connected, triggering detail sync",{initial:O}),N.syncAll(O?"initial-connect":"reconnect").catch(q=>G.warn("detail sync top-level error (ignored)",{err:String(q)}))});let W=new yo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let O=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[Yi]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:w??"",frameworksCache:o.frameworksCache??{},...O?{mockScenario:O}:{}}}},{method:"POST",path:"/pair",handler:async O=>{let q=O,j=q?.privatecode,re=q?.pairing_code;if(!j||!re)throw new C("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Ve=Ci(q.env),de=q.handshake_url,ue=q.frontier_url,vt=Sx(q.env,de,ue),dt=!!x&&x!==j,Xt=m!==void 0&&m!==vt,Ft=dt||Xt,Qt=await Mc({privatecode:j,...de?{endpoint:de}:{},ppeOverride:Ve});if(Ft){G.warn("pair config switched, resetting agents",{pcChanged:dt,envChanged:Xt,previousPc:x?Vo(x):"",nextPc:Vo(j),previousEnvKey:m??"",nextEnvKey:vt});for(let Se of[...u.agents.values()])await Se.dispose("pair config switch").catch(()=>{}),u.agents.delete(Se.agentId);u.disconnectedAgents.size>0&&(G.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new zr,"pair switch").catch(()=>{})}w=Qt.deviceId,is({deviceId:w,pid:process.pid}),el({patToken:j,env:q.env}).catch(Se=>G.warn("coze-cli setup error (ignored)",{err:String(Se)}));let jr=new Ji({handshake:Qt,privatecode:j,...ue?{urlOverride:ue}:{},ppeOverride:Ve,getPatTokenForAgent:Se=>u.agents.get(Se)?.patToken});await c.swap(jr,"pair");try{let Se=new Hn;o.frameworksCache=await Se.detectAll(),await Fi(o),G.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Se){G.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Se)})}let ge=Object.keys(o.frameworksCache??{});try{let Se=await u.sendRequest("_agent/pair",{pairCode:re,patToken:j,frameworks:ge,_meta:{cozeDeviceId:w}});G.info("_agent/pair ok",{pairResult:Se}),x=j,m=vt,b=Ve,p=de,q.mock_scenario!==void 0&&(u.setMockScenario(q.mock_scenario),G.info("mock scenario set",{scenario:q.mock_scenario})),Zi(j,t).catch(De=>G.warn("writePatToken after /pair failed (ignored)",{err:String(De)})),_||(_=new Di({core:u,getDeviceId:()=>w??"",onTickEnd:()=>N.retryPending().catch(De=>G.warn("detailSync.retryPending failed (ignored)",{err:String(De)})),onAuthFailures:$})),_.start(),E(),Ft&&Jo(t,f).catch(De=>G.warn("post-pair-switch auto-revive error (ignored)",{err:String(De)}));let Vn;return q.agent_id&&(Vn=await tS(q.agent_id,t,f,De=>u.sendRequest("_agent/detail",De),j).catch(De=>(G.error("--agent-id ensureAgent failed",{agentId:q.agent_id,err:String(De)}),{ok:!1,agentId:q.agent_id??"",note:String(De)}))),{ok:!0,note:"paired with cloud",...Vn?{agent:Vn}:{}}}catch(Se){return G.error("_agent/pair failed",{err:String(Se)}),{ok:!1,note:`pair failed: ${String(Se)}`}}}},{method:"POST",path:"/connect",handler:O=>D(O)},{method:"POST",path:"/_agent/create",handler:async O=>{let q=O;return{ok:!0,result:await f.createAgent(q)}}},{method:"POST",path:"/agent/send",handler:async O=>{let q=O;if(!q?.agentId||!q?.sessionId||!q?.kind||!q?.path)throw new C("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!x)throw new C("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let j=q;return await(j.groupFile?O0:P0)(j,{core:u,patToken:x,handshakeBase:p,ppeOverride:b})}catch(j){if(j instanceof C)return{ok:!1,code:j.code,message:j.message};throw j}}},{method:"POST",path:"/reload",handler:async O=>{let q=O?.agent_id,j=await u.reloadAgents(q);return G.info("IPC /reload: recycled agent subprocesses",{agentId:q??"(all)",recycled:j}),{ok:!0,recycled:j}}},{method:"POST",path:"/shutdown",handler:async()=>(G.info("IPC /shutdown received"),setImmediate(()=>{he.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:ne,token:Y}=await W.start();try{await _x(t.libEntry,t)}catch(O){G.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(O)})}await u.start(),nS({paths:t,core:u,agentManager:f,detectAll:async()=>(o.frameworksCache=await new Hn().detectAll(),await Fi(o),o.frameworksCache)}).catch(O=>G.warn("startup warmup error (ignored)",{err:String(O)})),_d().then(async()=>{let{probeAcpVersion:O}=await Promise.resolve().then(()=>(nn(),md));for(let q of["claude-code","codex"]){let j=await O(q);j&&G.info("acp wrapper version",{framework:q,version:j})}}).catch(O=>G.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(O)}));let ve=null,he={port:ne,token:Y,core:u,ipc:W,shutdown(O){return ve||(G.info("daemon shutdown",{reason:O}),ve=(async()=>{_?.stop(),S?.stop(),await u.stop(O),await W.stop(),await e.release()})(),ve)}};for(let O of["SIGTERM","SIGINT"])process.on(O,()=>{he.shutdown(O).then(()=>process.exit(0))});return process.on("exit",()=>o0()),process.on("unhandledRejection",O=>{G.error("unhandledRejection",{reason:O instanceof Error?O.message:String(O),stack:O instanceof Error?O.stack:void 0})}),process.on("uncaughtException",O=>{G.error("uncaughtException (will exit, supervisor will restart)",{message:O.message,stack:O.stack,name:O.name});try{process.stderr.write(`FATAL uncaughtException: ${O.stack??O.message}
107
- `)}catch{}process.exit(1)}),G.info("daemon ready",{port:ne,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),rS({cliSpawned:process.env[Yi]==="1",readPatToken:()=>Go(t),connect:D}).catch(O=>G.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(O)})),he}async function Qv(t){return os(t).length>0}function Vo(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function Sx(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function eS(t,e){let r=os(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(rn(),ls));for(let c of r){await o(c,t).catch(l=>G.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(l)}));try{let l=await i(c,t);l?.disconnectedAt&&(e.disconnectedAgents.add(c),G.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:l.disconnectedAt,reason:l.disconnectReason??""}))}catch(l){G.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(l)})}}}async function tS(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(rn(),ls)),l=await c(t,e);if(l){G.info("--agent-id: local config found, reconnecting",{agentId:t,framework:l.framework,hadDisconnect:!!l.disconnectedAt});let m=Ax(l),w={agentId:l.agentId,framework:l.framework,...l.cozeIdentity?{cozeIdentity:l.cozeIdentity}:{},...l.model?{model:l.model}:{},...o?{patToken:o}:{},...m?{_meta:m}:{}};return await r.createAgent(w),{ok:!0,agentId:t,note:l.disconnectedAt?"revived from local config":"connected from local config"}}G.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let u=await i({_meta:{cozeAgentId:t}});if(!u.framework)throw new C("AGENT_NOT_FOUND",`agent ${t} \u4E0D\u5728\u672C\u5730; \u4E91\u7AEF _agent/detail \u54CD\u5E94\u7F3A framework \u5B57\u6BB5 (D36 \u534F\u8BAE\u6269\u5C55\u672A\u751F\u6548), \u65E0\u6CD5\u5728\u672C\u673A\u65B0\u5EFA`);let f={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...u.deployType?{_meta:{cozeDeployType:u.deployType}}:{}};await r.createAgent(f);let x=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:x?"cloud agent acknowledged":"created from cloud detail"}}async function nS(t){let e=t.logger??G;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 eS(t.paths,t.core).catch(r=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(r)})),await Jo(t.paths,t.agentManager).catch(r=>e.warn("auto-revive top-level error (ignored)",{err:String(r)}))}async function Jo(t,e){let{readdir:r}=await import("node:fs/promises"),i;try{i=await r(t.agentsRoot)}catch{return{revived:0,skipped:0,total:0}}if(i.length===0)return{revived:0,skipped:0,total:0};let{loadAgentConfig:o}=await Promise.resolve().then(()=>(rn(),ls));G.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,l=0;for(let u of i){let f;try{f=await o(u,t)}catch(x){G.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(x)}),l+=1;continue}if(!f){l+=1;continue}if(f.disconnectedAt){G.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:f.disconnectedAt}),l+=1;continue}try{G.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:f.framework});let x=Ax(f);await e.createAgent({agentId:f.agentId,framework:f.framework,...f.cozeIdentity?{cozeIdentity:f.cozeIdentity}:{},...f.model?{model:f.model}:{},...x?{_meta:x}:{}},{revive:!0}),c+=1}catch(x){G.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:f.framework,err:String(x)}),l+=1}}return G.info("auto-revive: done",{revived:c,skipped:l,total:i.length}),{revived:c,skipped:l,total:i.length}}async function rS(t){let e=t.logger??G;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 Ax(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}Ko();ke();import{readFile as Tx}from"node:fs/promises";var Yt=class{paths;constructor(e){this.paths=e??X()}async probe(e=1e3){let r=await Zo(this.paths);if(!r)return{kind:"not-running"};try{let i=await this.fetch(r,{method:"GET",path:"/status",timeoutMs:e});return i.status===200?{kind:"connected",...r}:{kind:"stale",reason:`unexpected status ${i.status}`}}catch(i){return{kind:"stale",reason:sS(i)}}}async request(e){let r=await Zo(this.paths);if(!r)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(r,e)}async fetch(e,r){let i=r.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,l=setTimeout(()=>c.abort(),r.timeoutMs??5e3);try{let u=await fetch(`http://127.0.0.1:${e.port}${r.path}`,{method:r.method,headers:o,body:i?JSON.stringify(r.body):void 0,signal:c.signal}),f=await u.text();return{status:u.status,body:iS(f)}}finally{clearTimeout(l)}}};async function Zo(t){try{let[e,r]=await Promise.all([Tx(t.portFile,"utf8"),Tx(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 iS(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function sS(t){return t instanceof Error?t.message:String(t)}yn();ee();Xn();import{spawn as oS}from"node:child_process";import{userInfo as Rx}from"node:os";var Pl="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",aS=new Set(["bash","zsh","sh","dash","ksh"]),Cx=Ge("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),cS=2e3;function lS(t,e=Pl){let r=t.indexOf(e);if(r===-1)return null;let i=t.indexOf(e,r+e.length);if(i===-1)return null;let o=t.slice(r+e.length,i),c={};for(let l of o.split(`
108
- `)){let u=l.indexOf("=");u<=0||(c[l.slice(0,u)]=l.slice(u+1))}return c}function dS(){let t=(process.env.SHELL??"").trim()||(Rx().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return aS.has(e)?t:null}function uS(t){return new Promise(e=>{let r=`printf '%s' '${Pl}'; env; printf '%s' '${Pl}'`,i;try{i=oS(t,["-ilc",r],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??Rx().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(f),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 f=setTimeout(()=>l("SIGTERM"),Cx),x=setTimeout(()=>{l("SIGKILL"),u(o.length>0?o:null)},Cx+cS)})}async function Ol(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let r=dS();if(!r)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??uS)(r);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=lS(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}ke();function Sn(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],l=!1;for(let u of e){if(c===u){i=t[o+1],o+=1,l=!0;break}if(c.startsWith(`${u}=`)){i=c.slice(u.length+1),l=!0;break}}l||r.push(c)}return{value:i,rest:r}}nn();import{chmod as fS,copyFile as Dx,mkdir as Px,readFile as Yo,rename as kx,rm as Ll,stat as Ox,writeFile as hS}from"node:fs/promises";import{homedir as QD}from"node:os";import{dirname as xS,join as Ur,resolve as Nl,sep as Xi}from"node:path";import{fileURLToPath as pS}from"node:url";yn();ee();ke();var Ml=H("dist-install");function gS(t){let e=pS(t),r=xS(e),i=`${Xi}src${Xi}`;if(r.includes(i)||r.endsWith(`${Xi}src${Xi}cli`))return null;let o=Nl(r,"index.js"),c=Nl(r,"..","package.json");return{dist:o,pkgJson:c}}async function Fl(t={}){let e=t.paths??X(),r=gS(import.meta.url),i=t.sourceDist??r?.dist,o=t.sourcePackageJson??r?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,l;try{let b=JSON.parse(await Yo(o,"utf8"));c=b.version??"unknown",l=b.dependencies??{}}catch(b){return Ml.warn("cannot read source package.json,skip dist install",{err:String(b)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(b)}`}}let u=Zr.map(b=>`${b}@${l[b]??"latest"}`),f=await wo(e.configFile)??{},x=f.libVersion,m=await Yo(e.libEntry).then(()=>!0).catch(()=>!1),w=x===c;if(w&&m&&await Bl(e))return{kind:"already-current",libVersion:c};if(!w||!m){await Px(e.libDir,{recursive:!0}),await Dx(i,e.libEntry),await Dx(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let b=Nl(e.libDir,"package.json"),p=`${JSON.stringify({type:"module"},null,2)}
109
- `;await Yo(b,"utf8").catch(()=>null)!==p&&await hS(b,p)}return(!w||!await Bl(e))&&await(t.installWrappers??mS)(e,u),f.libVersion=c,await Fi(f,e.configFile),Ml.info("dist installed",{libEntry:e.libEntry,fromVersion:x,toVersion:c}),w&&m?{kind:"already-current",libVersion:c}:x?{kind:"version-changed",fromVersion:x,toVersion:c,libEntry:e.libEntry}:{kind:"first-install",libVersion:c,libEntry:e.libEntry}}async function Bl(t){for(let e of Zr){let r=Ur(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await Ox(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function mS(t,e){await yS(t.installLock,async()=>{if(await Bl(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${Xi}.staging-${process.pid}-${r}`,o=Ur(i,"node_modules"),c=Ur(t.libDir,"node_modules");try{await Px(i,{recursive:!0}),await wS(e,i),await _S(o);let l=`${c}.trash-${r}`;await kx(c,l).catch(()=>{}),await kx(o,c),await Ll(l,{recursive:!0,force:!0}).catch(()=>{}),Ml.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await Ll(i,{recursive:!0,force:!0}).catch(()=>{})}})}function wS(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=at("npm",r,{stdio:["ignore","pipe","pipe"]}),l="";c.stderr?.on("data",f=>{l.length<8192&&(l+=f.toString("utf8"))});let u=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",f=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(f)}`))}),c.once("close",f=>{clearTimeout(u),f===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${f}: ${l.trim().slice(0,2e3)}`))})})}async function _S(t){for(let e of Zr){let r=Ur(t,...e.split("/")),i=JSON.parse(await Yo(Ur(r,"package.json"),"utf8"));if(!i.version)throw new Error(`${e}: package.json \u7F3A version`);let o=typeof i.bin=="string"?e.split("/").pop():Object.keys(i.bin??{})[0];if(!o)throw new Error(`${e}: package.json \u7F3A bin`);let c=Ur(t,".bin",o),l=await Ox(c);process.platform!=="win32"&&!(l.mode&73)&&await fS(c,l.mode|73).catch(()=>{})}}async function yS(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 Ll(t,{force:!0}).catch(()=>{})}}Ea();ee();ke();import{closeSync as Nx,fstatSync as Mx,openSync as Bx,readFileSync as ES,readSync as bS,readdirSync as vS,statSync as SS}from"node:fs";import{join as Xo}from"node:path";var IS=new Set(["debug","info","warn","error"]);function Fx(t){let e=t,r=Sn(e,"--agent-id");e=r.rest;let i=Sn(e,"--date");e=i.rest;let o=Sn(e,"-n","--lines");e=o.rest;let c=Sn(e,"--level");e=c.rest;let l=Sn(e,"--grep");e=l.rest;let u=o.value===void 0?200:Number(o.value),f=Number.isInteger(u)&&u>=0?u:200,x=c.value&&IS.has(c.value)?c.value:void 0,m={lines:f,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(m.agentId=r.value),i.value&&(m.date=i.value),x&&(m.level=x),l.value&&(m.grep=l.value),m}function AS(t,e){return t.agentId?Xo(Ze(t.agentId,e).logs,Qn("agent",t.date)):Xo(e.bridgeLogsDir,Qn("bridge",t.date))}function TS(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function CS(t,e){let r;try{r=vS(t)}catch{return[]}let i=[];for(let o of r){let c=ya(o,e);if(!c)continue;let l=0;try{l=SS(Xo(t,o)).size}catch{}i.push({file:Xo(t,o),date:c,size:l})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function zx(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"&&!fd(r,e.level))return!1}return!0}var Lx={debug:"90",info:"36",warn:"33",error:"31"},RS=new Set(["ts","level","module","msg"]);function DS(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function Ux(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=DS(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&Lx[o]&&(c=`\x1B[${Lx[o]}m${c}\x1B[0m`);let l=typeof r.module=="string"?r.module:"",u=typeof r.msg=="string"?r.msg:"",f=Object.entries(r).filter(([x])=>!RS.has(x)).map(([x,m])=>` ${x}=${typeof m=="string"?m:JSON.stringify(m)}`).join("");return`${i} ${c} ${l} ${u}${f}`}function kS(t,e,r){let c=ES(t,"utf8").split(`
110
- `).filter(l=>l.length>0).filter(l=>zx(l,{level:e.level,grep:e.grep}));for(let l of TS(c,e.lines))process.stdout.write(`${Ux(l,{raw:e.raw,color:r})}
111
- `)}async function Hx(t,e){let r=e.paths??X(),i=process.stdout.isTTY===!0;if(t.list){let l=t.agentId?Ze(t.agentId,r).logs:r.bridgeLogsDir,u=t.agentId?"agent":"bridge",f=CS(l,u);if(f.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${l}
112
- `),1;for(let x of f)process.stdout.write(`${x.date} ${(x.size/1024).toFixed(1)}KB ${x.file}
113
- `);return 0}let o=t.date??An(new Date),c=AS({agentId:t.agentId,date:o},r);try{kS(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
105
+ `}async function Ex(t,e=Q()){let r=e.binDir;await jo.mkdir(r,{recursive:!0});let i=Bv(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?zv(t,o):Fv(t,o);return await jo.readFile(i,"utf8").catch(()=>null)===c||(await jo.writeFile(i,c,"utf8"),process.platform!=="win32"&&await jo.chmod(i,493)),r}ne();ke();import{execSync as bx}from"node:child_process";import{readFileSync as vx,unlinkSync as Uv}from"node:fs";import{mkdir as Hv,readFile as Sx,unlink as Ix,writeFile as qv}from"node:fs/promises";import{dirname as Gv}from"node:path";var jv=U("single-instance"),Wo=class{pidFile;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??Q().pidFile,e.processTitle&&(process.title=e.processTitle)}async acquire(){let e=await this.readExistingPid();return e!==null&&this.isAlive(e)?{kind:"already-running",pid:e}:(e!==null&&(jv.warn("removing stale pid file",{stalePid:e}),await Ix(this.pidFile).catch(()=>{})),await Hv(Gv(this.pidFile),{recursive:!0}),await qv(this.pidFile,String(process.pid),"utf8"),this.acquired=!0,this.installCleanupHooks(),{kind:"acquired"})}async release(){if(this.acquired){try{(await Sx(this.pidFile,"utf8")).trim()===String(process.pid)&&await Ix(this.pidFile)}catch{}this.acquired=!1}}async readExistingPid(){try{let e=await Sx(this.pidFile,"utf8"),r=Number.parseInt(e.trim(),10);return Number.isFinite(r)&&r>0?r:null}catch(e){if(e.code==="ENOENT")return null;throw e}}isAlive(e){return oo(e)?this.matchesDaemonTitle(e):!1}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let r=vx(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes("coze-bridge-daemon")||r.includes("lib/index.js"))}catch{}try{let r=bx(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes("coze-bridge-daemon")||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=bx(`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{vx(this.pidFile,"utf8").trim()===String(process.pid)&&Uv(this.pidFile)}catch{}})}};Ko();ne();var $n=U("daemon.upstream-watchdog"),Xv=12e4,Qv=9e5,eS=3e4;function kd(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var $o=class{constructor(e){this.opts=e;this.softMs=e.softMs??kd("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",Xv),this.hardMs=e.hardMs??kd("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",Qv),this.intervalMs=e.intervalMs??kd("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",eS),this.now=e.now??Date.now}opts;softMs;hardMs;intervalMs;now;timer=null;downSince=null;forcedAt=null;forcing=!1;lastTickAt=null;start(){this.timer||(this.timer=setInterval(()=>this.tick(),this.intervalMs),this.timer.unref?.(),$n.info("upstream watchdog started",{softMs:this.softMs,hardMs:this.hardMs,intervalMs:this.intervalMs}))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null),this.downSince=null,this.forcedAt=null,this.lastTickAt=null}tick(){let e=this.now();if(this.lastTickAt!==null&&e-this.lastTickAt>this.intervalMs*3&&(this.downSince!==null&&$n.warn("upstream watchdog: large tick gap (likely sleep/suspend), resetting downSince",{gapMs:e-this.lastTickAt}),this.downSince=null,this.forcedAt=null),this.lastTickAt=e,this.opts.isConnected()){this.downSince!==null&&$n.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,$n.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){$n.error("upstream watchdog: disconnected too long, exiting for supervisor restart",{downMs:r,hardMs:this.hardMs}),this.opts.onFatal(r);return}r>=this.softMs&&this.shouldForceNow(e)&&(this.forcedAt=e,this.forcing=!0,$n.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>$n.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var j=U("daemon"),tS="coze-bridge-daemon";async function Cx(){let t=Q();process.env.COZE_BRIDGE_LOG_MODE!=="legacy"&&dl({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:O=>Ze(O,t).logs,listAgentIds:()=>is(t)});let e=new Wo({processTitle:tS}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await wo(),o=i??{};ns({pid:process.pid}),j.info(i?"loaded bridge config":"initialized bridge config");let c=new qo(new Fr),l=null,u=new _o({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(O,H,K,ie)=>{if(!l)throw new Error("agentManager not ready");return l.spawnSessionDownstream(O,H,K,ie)}}),h=new po({paths:t,config:o,registry:u});l=h;let x,w,_=null,S={},E,v=null,A=null,I=null,R=new En;function L(O,H){return R.enqueue(()=>D(O,H))}function y(){A||(A=new $o({isConnected:()=>c.isConnected(),forceReconnect:()=>I?L(I,{force:!0}):void 0,onFatal:O=>{if(process.env[Vi]==="1"){j.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:O});return}j.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:O}),process.exit(1)}})),A.start()}async function D(O,H){let K=O,ie=K?.privatecode;if(!ie)throw new C("IPC_BAD_REQUEST","/connect requires privatecode");let Je=Ci(K.env),fe=K.handshake_url,he=K.frontier_url,vt=Tx(K.env,fe,he);if(I=K,!H?.force&&x===ie&&w===vt){let me=await nS(t);return u.agents.size===0&&me?(j.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),Vo(t,h).catch(Se=>j.warn("connect-noop auto-revive error (ignored)",{err:String(Se)}))):j.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let ft=!!x&&x!==ie,Zt=w!==void 0&&w!==vt,Bt=ft||Zt,Xt=await Nc({privatecode:ie,...fe?{endpoint:fe}:{},ppeOverride:Je});if(Bt){j.warn("connect config switched, resetting agents",{pcChanged:ft,envChanged:Zt,previousPc:x?Jo(x):"",nextPc:Jo(ie)});for(let me of[...u.agents.values()])await me.dispose("connect config switch").catch(()=>{}),u.agents.delete(me.agentId);u.disconnectedAgents.size>0&&(j.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Fr,"connect switch").catch(()=>{})}_=Xt.deviceId,ns({deviceId:_,pid:process.pid}),td({patToken:ie,env:K.env}).catch(me=>j.warn("coze-cli setup error (ignored)",{err:String(me)}));let Gr=new $i({handshake:Xt,privatecode:ie,...he?{urlOverride:he}:{},ppeOverride:Je,getPatTokenForAgent:me=>u.agents.get(me)?.patToken});return await c.swap(Gr,"connect"),x=ie,w=vt,S=Je,E=fe,K.mock_scenario!==void 0&&(u.setMockScenario(K.mock_scenario),j.info("mock scenario set",{scenario:K.mock_scenario})),v||(v=new Di({core:u,getDeviceId:()=>_??"",onTickEnd:()=>B.retryPending().catch(me=>j.warn("detailSync.retryPending failed (ignored)",{err:String(me)})),onAuthFailures:V})),v.start(),y(),Bt&&Vo(t,h).catch(me=>j.warn("post-connect-switch auto-revive error (ignored)",{err:String(me)})),Ji(ie,t).catch(me=>j.warn("writePatToken after /connect failed (ignored)",{err:String(me)})),j.info("/connect: WS established",{deviceId:_}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async O=>h.createAgent(O.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let k={},N=new no({agents:u.agents,disposeAndMarkDisconnected:async(O,H)=>{let K=u.agents.get(O);if(K){await h.cleanupOpenclawSessionProviders(K).catch(Je=>j.warn("cleanup openclaw providers failed (ignored)",{agentId:O,err:String(Je)}));let ie=!0;try{await K.dispose(`disconnect: ${H}`)}catch(Je){ie=!1,j.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:O,err:String(Je)}),K.status="error"}ie&&(K.status="disconnected",u.unregister(O),u.disconnectedAgents.add(O))}else u.disconnectedAgents.add(O)},detailSyncer:async O=>{if(!k.ref)throw new Error("agent-detail-sync not initialized yet");await k.ref.syncOne(O)},cleanupOpenclawProviders:async O=>{await h.cleanupOpenclawSessionProviders(O)},openclawRepair:async(O,H)=>{await h.openclawRepair(O,H)},isRuntimePendingPermission:O=>u.hasPendingPermissionFor(O)});u.registerExtension("_agent/listSkills",O=>N.listSkills(O.params)),u.registerExtension("_agent/addSkills",O=>N.addSkills(O.params)),u.registerExtension("_agent/removeSkills",O=>N.removeSkills(O.params)),u.registerExtension("_agent/getFileTree",O=>N.getFileTree(O.params)),u.registerExtension("_agent/getFileContent",O=>N.getFileContent(O.params)),u.registerExtension("_agent/update",O=>N.updateAgent(O.params)),u.registerExtension("_agent/disconnect",O=>N.disconnectAgent(O.params)),u.registerExtension("_agent/switchModel",O=>N.switchModel(O.params)),u.registerExtension("_agent/reset",O=>N.resetAgent(O.params)),u.registerExtension("_agent/repair",O=>N.repairAgent(O.params));let B=new cs({paths:t,handlers:N,sendDetail:O=>u.sendRequest("_agent/detail",O)});k.ref=B;let V=async O=>{await Promise.allSettled(O.map(async H=>{try{await N.disconnectAgent({agentId:H.agentId,reason:`auth_failure: code=${H.code} ${H.message}`}),j.info("agent disconnected due to auth failure from heartbeat response",{agentId:H.agentId,code:H.code,message:H.message})}catch(K){j.warn("disconnect during authFailure handling failed (ignored)",{agentId:H.agentId,err:String(K)})}}))};c.onConnect(({initial:O})=>{j.info("frontier upstream connected, triggering detail sync",{initial:O}),B.syncAll(O?"initial-connect":"reconnect").catch(H=>j.warn("detail sync top-level error (ignored)",{err:String(H)}))});let J=new yo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let O=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[Vi]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:_??"",frameworksCache:o.frameworksCache??{},...O?{mockScenario:O}:{}}}},{method:"POST",path:"/pair",handler:async O=>{let H=O,K=H?.privatecode,ie=H?.pairing_code;if(!K||!ie)throw new C("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Je=Ci(H.env),fe=H.handshake_url,he=H.frontier_url,vt=Tx(H.env,fe,he),ft=!!x&&x!==K,Zt=w!==void 0&&w!==vt,Bt=ft||Zt,Xt=await Nc({privatecode:K,...fe?{endpoint:fe}:{},ppeOverride:Je});if(Bt){j.warn("pair config switched, resetting agents",{pcChanged:ft,envChanged:Zt,previousPc:x?Jo(x):"",nextPc:Jo(K),previousEnvKey:w??"",nextEnvKey:vt});for(let Se of[...u.agents.values()])await Se.dispose("pair config switch").catch(()=>{}),u.agents.delete(Se.agentId);u.disconnectedAgents.size>0&&(j.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Fr,"pair switch").catch(()=>{})}_=Xt.deviceId,ns({deviceId:_,pid:process.pid}),td({patToken:K,env:H.env}).catch(Se=>j.warn("coze-cli setup error (ignored)",{err:String(Se)}));let Gr=new $i({handshake:Xt,privatecode:K,...he?{urlOverride:he}:{},ppeOverride:Je,getPatTokenForAgent:Se=>u.agents.get(Se)?.patToken});await c.swap(Gr,"pair");try{let Se=new Hn;o.frameworksCache=await Se.detectAll(),await Mi(o),j.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Se){j.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Se)})}let me=Object.keys(o.frameworksCache??{});try{let Se=await u.sendRequest("_agent/pair",{pairCode:ie,patToken:K,frameworks:me,_meta:{cozeDeviceId:_}});j.info("_agent/pair ok",{pairResult:Se}),x=K,w=vt,S=Je,E=fe,H.mock_scenario!==void 0&&(u.setMockScenario(H.mock_scenario),j.info("mock scenario set",{scenario:H.mock_scenario})),Ji(K,t).catch(Re=>j.warn("writePatToken after /pair failed (ignored)",{err:String(Re)})),v||(v=new Di({core:u,getDeviceId:()=>_??"",onTickEnd:()=>B.retryPending().catch(Re=>j.warn("detailSync.retryPending failed (ignored)",{err:String(Re)})),onAuthFailures:V})),v.start(),y(),Bt&&Vo(t,h).catch(Re=>j.warn("post-pair-switch auto-revive error (ignored)",{err:String(Re)}));let Jn;return H.agent_id&&(Jn=await iS(H.agent_id,t,h,Re=>u.sendRequest("_agent/detail",Re),K).catch(Re=>(j.error("--agent-id ensureAgent failed",{agentId:H.agent_id,err:String(Re)}),{ok:!1,agentId:H.agent_id??"",note:String(Re)}))),{ok:!0,note:"paired with cloud",...Jn?{agent:Jn}:{}}}catch(Se){return j.error("_agent/pair failed",{err:String(Se)}),{ok:!1,note:`pair failed: ${String(Se)}`}}}},{method:"POST",path:"/connect",handler:O=>L(O)},{method:"POST",path:"/_agent/create",handler:async O=>{let H=O;return{ok:!0,result:await h.createAgent(H)}}},{method:"POST",path:"/agent/send",handler:async O=>{let H=O;if(!H?.agentId||!H?.sessionId||!H?.kind||!H?.path)throw new C("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!x)throw new C("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let K=H;return await(K.groupFile?N0:L0)(K,{core:u,patToken:x,handshakeBase:E,ppeOverride:S})}catch(K){if(K instanceof C)return{ok:!1,code:K.code,message:K.message};throw K}}},{method:"POST",path:"/reload",handler:async O=>{let H=O?.agent_id,K=await u.reloadAgents(H);return j.info("IPC /reload: recycled agent subprocesses",{agentId:H??"(all)",recycled:K}),{ok:!0,recycled:K}}},{method:"POST",path:"/shutdown",handler:async()=>(j.info("IPC /shutdown received"),setImmediate(()=>{pe.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:te,token:$}=await J.start();try{await Ex(t.libEntry,t)}catch(O){j.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(O)})}await u.start(),sS({paths:t,core:u,agentManager:h,detectAll:async()=>(o.frameworksCache=await new Hn().detectAll(),await Mi(o),o.frameworksCache)}).catch(O=>j.warn("startup warmup error (ignored)",{err:String(O)})),_l().then(async()=>{let{probeAcpVersion:O}=await Promise.resolve().then(()=>(tn(),ml));for(let H of["claude-code","codex"]){let K=await O(H);K&&j.info("acp wrapper version",{framework:H,version:K})}}).catch(O=>j.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(O)}));let ce=null,pe={port:te,token:$,core:u,ipc:J,shutdown(O){return ce||(j.info("daemon shutdown",{reason:O}),ce=(async()=>{v?.stop(),A?.stop(),await u.stop(O),await J.stop(),await e.release()})(),ce)}};for(let O of["SIGTERM","SIGINT"])process.on(O,()=>{pe.shutdown(O).then(()=>process.exit(0))});return process.on("exit",()=>o0()),process.on("unhandledRejection",O=>{j.error("unhandledRejection",{reason:O instanceof Error?O.message:String(O),stack:O instanceof Error?O.stack:void 0})}),process.on("uncaughtException",O=>{j.error("uncaughtException (will exit, supervisor will restart)",{message:O.message,stack:O.stack,name:O.name});try{process.stderr.write(`FATAL uncaughtException: ${O.stack??O.message}
106
+ `)}catch{}process.exit(1)}),j.info("daemon ready",{port:te,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),oS({cliSpawned:process.env[Vi]==="1",readPatToken:()=>Go(t),connect:L}).catch(O=>j.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(O)})),pe}async function nS(t){return is(t).length>0}function Jo(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function Tx(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function rS(t,e){let r=is(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(nn(),as));for(let c of r){await o(c,t).catch(l=>j.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(l)}));try{let l=await i(c,t);l?.disconnectedAt&&(e.disconnectedAgents.add(c),j.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:l.disconnectedAt,reason:l.disconnectReason??""}))}catch(l){j.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(l)})}}}async function iS(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(nn(),as)),l=await c(t,e);if(l){j.info("--agent-id: local config found, reconnecting",{agentId:t,framework:l.framework,hadDisconnect:!!l.disconnectedAt});let w={agentId:l.agentId,framework:l.framework,...l.cozeIdentity?{cozeIdentity:l.cozeIdentity}:{},...l.model?{model:l.model}:{},...o?{patToken:o}:{}};return await r.createAgent(w),{ok:!0,agentId:t,note:l.disconnectedAt?"revived from local config":"connected from local config"}}j.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let u=await i({_meta:{cozeAgentId:t}});if(!u.framework)throw new C("AGENT_NOT_FOUND",`agent ${t} \u4E0D\u5728\u672C\u5730; \u4E91\u7AEF _agent/detail \u54CD\u5E94\u7F3A framework \u5B57\u6BB5 (D36 \u534F\u8BAE\u6269\u5C55\u672A\u751F\u6548), \u65E0\u6CD5\u5728\u672C\u673A\u65B0\u5EFA`);let h={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...u.deployType?{_meta:{cozeDeployType:u.deployType}}:{}};await r.createAgent(h);let x=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:x?"cloud agent acknowledged":"created from cloud detail"}}async function sS(t){let e=t.logger??j;try{let r=await t.detectAll();e.info("refreshed frameworks_cache",{detected:Object.keys(r??{})})}catch(r){e.warn("framework detection failed (using cached)",{err:String(r)})}await rS(t.paths,t.core).catch(r=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(r)})),await Vo(t.paths,t.agentManager).catch(r=>e.warn("auto-revive top-level error (ignored)",{err:String(r)}))}async function Vo(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(()=>(nn(),as));j.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,l=0;for(let u of i){let h;try{h=await o(u,t)}catch(x){j.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(x)}),l+=1;continue}if(!h){l+=1;continue}if(h.disconnectedAt){j.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:h.disconnectedAt}),l+=1;continue}try{j.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:h.framework});let x=aS(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){j.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:h.framework,err:String(x)}),l+=1}}return j.info("auto-revive: done",{revived:c,skipped:l,total:i.length}),{revived:c,skipped:l,total:i.length}}async function oS(t){let e=t.logger??j;if(t.cliSpawned)return"skipped-cli";let r=await t.readPatToken();return r?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:r}).catch(i=>e.warn("startup auto-connect failed (staying idle)",{err:String(i)})),"connecting"):(e.info("no stored PAT, skip startup auto-connect"),"skipped-no-pat")}function aS(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}Ko();ke();import{readFile as Rx}from"node:fs/promises";var Yt=class{paths;constructor(e){this.paths=e??Q()}async probe(e=1e3){let r=await Yo(this.paths);if(!r)return{kind:"not-running"};try{let i=await this.fetch(r,{method:"GET",path:"/status",timeoutMs:e});return i.status===200?{kind:"connected",...r}:{kind:"stale",reason:`unexpected status ${i.status}`}}catch(i){return{kind:"stale",reason:dS(i)}}}async request(e){let r=await Yo(this.paths);if(!r)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(r,e)}async fetch(e,r){let i=r.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,l=setTimeout(()=>c.abort(),r.timeoutMs??5e3);try{let u=await fetch(`http://127.0.0.1:${e.port}${r.path}`,{method:r.method,headers:o,body:i?JSON.stringify(r.body):void 0,signal:c.signal}),h=await u.text();return{status:u.status,body:cS(h)}}finally{clearTimeout(l)}}};async function Yo(t){try{let[e,r]=await Promise.all([Rx(t.portFile,"utf8"),Rx(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 cS(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function dS(t){return t instanceof Error?t.message:String(t)}_n();ne();ke();function Sn(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],l=!1;for(let u of e){if(c===u){i=t[o+1],o+=1,l=!0;break}if(c.startsWith(`${u}=`)){i=c.slice(u.length+1),l=!0;break}}l||r.push(c)}return{value:i,rest:r}}tn();import{chmod as lS,copyFile as Dx,mkdir as Px,readFile as Zo,rename as kx,rm as Pd,stat as Ox,writeFile as uS}from"node:fs/promises";import{homedir as XD}from"node:os";import{dirname as fS,join as zr,resolve as Od,sep as Yi}from"node:path";import{fileURLToPath as hS}from"node:url";_n();ne();ke();var Ld=U("dist-install");function xS(t){let e=hS(t),r=fS(e),i=`${Yi}src${Yi}`;if(r.includes(i)||r.endsWith(`${Yi}src${Yi}cli`))return null;let o=Od(r,"index.js"),c=Od(r,"..","package.json");return{dist:o,pkgJson:c}}async function Md(t={}){let e=t.paths??Q(),r=xS(import.meta.url),i=t.sourceDist??r?.dist,o=t.sourcePackageJson??r?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,l;try{let S=JSON.parse(await Zo(o,"utf8"));c=S.version??"unknown",l=S.dependencies??{}}catch(S){return Ld.warn("cannot read source package.json,skip dist install",{err:String(S)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(S)}`}}let u=Vr.map(S=>`${S}@${l[S]??"latest"}`),h=await wo(e.configFile)??{},x=h.libVersion,w=await Zo(e.libEntry).then(()=>!0).catch(()=>!1),_=x===c;if(_&&w&&await Nd(e))return{kind:"already-current",libVersion:c};if(!_||!w){await Px(e.libDir,{recursive:!0}),await Dx(i,e.libEntry),await Dx(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let S=Od(e.libDir,"package.json"),E=`${JSON.stringify({type:"module"},null,2)}
107
+ `;await Zo(S,"utf8").catch(()=>null)!==E&&await uS(S,E)}return(!_||!await Nd(e))&&await(t.installWrappers??pS)(e,u),h.libVersion=c,await Mi(h,e.configFile),Ld.info("dist installed",{libEntry:e.libEntry,fromVersion:x,toVersion:c}),_&&w?{kind:"already-current",libVersion:c}:x?{kind:"version-changed",fromVersion:x,toVersion:c,libEntry:e.libEntry}:{kind:"first-install",libVersion:c,libEntry:e.libEntry}}async function Nd(t){for(let e of Vr){let r=zr(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await Ox(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function pS(t,e){await wS(t.installLock,async()=>{if(await Nd(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${Yi}.staging-${process.pid}-${r}`,o=zr(i,"node_modules"),c=zr(t.libDir,"node_modules");try{await Px(i,{recursive:!0}),await gS(e,i),await mS(o);let l=`${c}.trash-${r}`;await kx(c,l).catch(()=>{}),await kx(o,c),await Pd(l,{recursive:!0,force:!0}).catch(()=>{}),Ld.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await Pd(i,{recursive:!0,force:!0}).catch(()=>{})}})}function gS(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=dt("npm",r,{stdio:["ignore","pipe","pipe"]}),l="";c.stderr?.on("data",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 mS(t){for(let e of Vr){let r=zr(t,...e.split("/")),i=JSON.parse(await Zo(zr(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=zr(t,".bin",o),l=await Ox(c);process.platform!=="win32"&&!(l.mode&73)&&await lS(c,l.mode|73).catch(()=>{})}}async function wS(t,e){let{open:r}=await import("node:fs/promises"),i=!1;for(let o=0;o<60&&!i;o++)try{await(await r(t,"wx")).close(),i=!0}catch{await new Promise(c=>setTimeout(c,500))}try{return await e()}finally{i&&await Pd(t,{force:!0}).catch(()=>{})}}ya();ne();ke();import{closeSync as Nx,fstatSync as Mx,openSync as Bx,readFileSync as _S,readSync as yS,readdirSync as ES,statSync as bS}from"node:fs";import{join as Xo}from"node:path";var vS=new Set(["debug","info","warn","error"]);function Fx(t){let e=t,r=Sn(e,"--agent-id");e=r.rest;let i=Sn(e,"--date");e=i.rest;let o=Sn(e,"-n","--lines");e=o.rest;let c=Sn(e,"--level");e=c.rest;let l=Sn(e,"--grep");e=l.rest;let u=o.value===void 0?200:Number(o.value),h=Number.isInteger(u)&&u>=0?u:200,x=c.value&&vS.has(c.value)?c.value:void 0,w={lines:h,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(w.agentId=r.value),i.value&&(w.date=i.value),x&&(w.level=x),l.value&&(w.grep=l.value),w}function SS(t,e){return t.agentId?Xo(Ze(t.agentId,e).logs,Xn("agent",t.date)):Xo(e.bridgeLogsDir,Xn("bridge",t.date))}function IS(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function AS(t,e){let r;try{r=ES(t)}catch{return[]}let i=[];for(let o of r){let c=_a(o,e);if(!c)continue;let l=0;try{l=bS(Xo(t,o)).size}catch{}i.push({file:Xo(t,o),date:c,size:l})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function zx(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"&&!fl(r,e.level))return!1}return!0}var Lx={debug:"90",info:"36",warn:"33",error:"31"},TS=new Set(["ts","level","module","msg"]);function CS(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function Ux(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=CS(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&Lx[o]&&(c=`\x1B[${Lx[o]}m${c}\x1B[0m`);let l=typeof r.module=="string"?r.module:"",u=typeof r.msg=="string"?r.msg:"",h=Object.entries(r).filter(([x])=>!TS.has(x)).map(([x,w])=>` ${x}=${typeof w=="string"?w:JSON.stringify(w)}`).join("");return`${i} ${c} ${l} ${u}${h}`}function RS(t,e,r){let c=_S(t,"utf8").split(`
108
+ `).filter(l=>l.length>0).filter(l=>zx(l,{level:e.level,grep:e.grep}));for(let l of IS(c,e.lines))process.stdout.write(`${Ux(l,{raw:e.raw,color:r})}
109
+ `)}async function Hx(t,e){let r=e.paths??Q(),i=process.stdout.isTTY===!0;if(t.list){let l=t.agentId?Ze(t.agentId,r).logs:r.bridgeLogsDir,u=t.agentId?"agent":"bridge",h=AS(l,u);if(h.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${l}
110
+ `),1;for(let x of h)process.stdout.write(`${x.date} ${(x.size/1024).toFixed(1)}KB ${x.file}
111
+ `);return 0}let o=t.date??An(new Date),c=SS({agentId:t.agentId,date:o},r);try{RS(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
114
112
  \u7528 'coze-bridge log${t.agentId?` --agent-id ${t.agentId}`:""} --list' \u770B\u6709\u54EA\u4E9B\u65E5\u671F\u3002
115
113
  (legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${r.logFile})
116
- `),1}return t.follow&&await LS(c,t,i),0}var PS=500;function OS(t){try{let e=Bx(t,"r");try{return Mx(e).size}finally{Nx(e)}}catch{return 0}}async function LS(t,e,r){let i=OS(t),o="",c=!1,l=()=>{c=!0};process.on("SIGINT",l);try{for(;!c;){let u="";try{let f=Bx(t,"r");try{let x=Mx(f).size;if(x>i){let m=Buffer.allocUnsafe(x-i),w=bS(f,m,0,m.length,i);u=m.subarray(0,w).toString("utf8"),i+=w}}finally{Nx(f)}}catch{}if(u){let f=(o+u).split(`
117
- `);o=f.pop()??"";for(let x of f)x.length>0&&zx(x,{level:e.level,grep:e.grep})&&process.stdout.write(`${Ux(x,{raw:e.raw,color:r})}
118
- `)}await new Promise(f=>setTimeout(f,PS))}}finally{process.off("SIGINT",l)}}import{basename as NS,resolve as MS}from"node:path";ke();var BS=9e4,FS={PATH_OUTSIDE_WORKSPACE:3,FILE_TOO_LARGE:3,UNSUPPORTED_MIME:3,MODEL_MODALITY_UNSUPPORTED:3,IPC_BAD_REQUEST:3,AGENT_NOT_FOUND:4,IPC_AUTH_FAILED:4,AGENT_DISCONNECTED:5,UPLOAD_FAILED:5,UPSTREAM_NOT_READY:5,UPSTREAM_DISCONNECTED:5,UPSTREAM_HANDSHAKE_FAILED:5,AGENT_BUSY:1,AGENT_SPAWN_FAILED:1,AGENT_TIMEOUT:1,AGENT_FRAME_IDLE_TIMEOUT:1,AGENT_PROTOCOL_ERROR:1,AGENT_TURN_ABORTED:1,BRIDGE_CONFIG_INVALID:1,BRIDGE_INTERNAL:1,MODEL_TOKEN_GEN_FAILED:1,OPERATION_NOT_ALLOWED_FOR_LOCAL:1,AGENT_DEPENDENCY_INSTALL_FAILED:1,AGENT_APPROVAL_TIMEOUT:1,AGENT_ENV_NOT_READY:1};function zS(t){return FS[t]??1}async function qx(t,e={}){let r=e.paths??X();if(!t.agentId||!t.sessionId)return process.stderr.write(`Error: missing --agent-id and/or --session-id. These IDs come from the <coze-context> block injected at the top of each prompt \u2014 extract agentId and sessionId from there and pass them as flags. Example: coze-bridge send image x.png --agent-id <id> --session-id <id>
114
+ `),1}return t.follow&&await PS(c,t,i),0}var DS=500;function kS(t){try{let e=Bx(t,"r");try{return Mx(e).size}finally{Nx(e)}}catch{return 0}}async function PS(t,e,r){let i=kS(t),o="",c=!1,l=()=>{c=!0};process.on("SIGINT",l);try{for(;!c;){let u="";try{let h=Bx(t,"r");try{let x=Mx(h).size;if(x>i){let w=Buffer.allocUnsafe(x-i),_=yS(h,w,0,w.length,i);u=w.subarray(0,_).toString("utf8"),i+=_}}finally{Nx(h)}}catch{}if(u){let h=(o+u).split(`
115
+ `);o=h.pop()??"";for(let x of h)x.length>0&&zx(x,{level:e.level,grep:e.grep})&&process.stdout.write(`${Ux(x,{raw:e.raw,color:r})}
116
+ `)}await new Promise(h=>setTimeout(h,DS))}}finally{process.off("SIGINT",l)}}import{basename as OS,resolve as LS}from"node:path";ke();var NS=9e4,MS={PATH_OUTSIDE_WORKSPACE:3,FILE_TOO_LARGE:3,UNSUPPORTED_MIME:3,MODEL_MODALITY_UNSUPPORTED:3,IPC_BAD_REQUEST:3,AGENT_NOT_FOUND:4,IPC_AUTH_FAILED:4,AGENT_DISCONNECTED:5,UPLOAD_FAILED:5,UPSTREAM_NOT_READY:5,UPSTREAM_DISCONNECTED:5,UPSTREAM_HANDSHAKE_FAILED:5,AGENT_BUSY:1,AGENT_SPAWN_FAILED:1,AGENT_TIMEOUT:1,AGENT_FRAME_IDLE_TIMEOUT:1,AGENT_PROTOCOL_ERROR:1,AGENT_TURN_ABORTED:1,BRIDGE_CONFIG_INVALID:1,BRIDGE_INTERNAL:1,MODEL_TOKEN_GEN_FAILED:1,OPERATION_NOT_ALLOWED_FOR_LOCAL:1,OPERATION_NOT_ALLOWED_FOR_CLOUD:1,METHOD_NOT_FOUND:1,AGENT_DEPENDENCY_INSTALL_FAILED:1,AGENT_APPROVAL_TIMEOUT:1,AGENT_ENV_NOT_READY:1};function BS(t){return MS[t]??1}async function qx(t,e={}){let r=e.paths??Q();if(!t.agentId||!t.sessionId)return process.stderr.write(`Error: missing --agent-id and/or --session-id. These IDs come from the <coze-context> block injected at the top of each prompt \u2014 extract agentId and sessionId from there and pass them as flags. Example: coze-bridge send image x.png --agent-id <id> --session-id <id>
119
117
  `),4;if(t.groupFile&&!t.mimeType)return process.stderr.write(`Error: --group-file requires --mime <mimeType> (e.g. application/pdf, image/png). No local file is read in group-file mode, mime cannot be auto-detected.
120
- `),3;let i=await Zo(r).catch(()=>null);if(!i)return process.stderr.write(`Error: coze-bridge daemon not running (cannot read ${r.portFile} / ${r.tokenFile}). Make sure you are inside an agent session spawned by the daemon.
121
- `),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:MS(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 US(i,"/agent/send",o,BS)}catch(l){return process.stderr.write(`Error: daemon IPC failed: ${l instanceof Error?l.message:String(l)}
118
+ `),3;let i=await Yo(r).catch(()=>null);if(!i)return process.stderr.write(`Error: coze-bridge daemon not running (cannot read ${r.portFile} / ${r.tokenFile}). Make sure you are inside an agent session spawned by the daemon.
119
+ `),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:LS(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 FS(i,"/agent/send",o,NS)}catch(l){return process.stderr.write(`Error: daemon IPC failed: ${l instanceof Error?l.message:String(l)}
122
120
  `),4}if(!c.ok)return process.stderr.write(`Error: ${c.code}: ${c.message}
123
- `),zS(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
124
- `);else{let l=t.name??NS(o.path);if(t.groupFile){let u=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${l} (uri=${u})
125
- `)}else process.stdout.write(`Sent ${t.kind} ${l} (${HS(c.bytes)})
126
- `)}return 0}async function US(t,e,r,i){let o=new AbortController,c=setTimeout(()=>o.abort(),i);try{let l=await fetch(`http://127.0.0.1:${t.port}${e}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"content-type":"application/json"},body:JSON.stringify(r),signal:o.signal}),u=await l.text(),f=u?JSON.parse(u):null;return f&&typeof f=="object"&&"ok"in f?f:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${l.status}): ${u.slice(0,200)}`}}finally{clearTimeout(c)}}function HS(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var Yx=H("cli");function Ue(t,e){let{value:r,rest:i}=Sn(t,e);return{value:r,rest:i}}function ia(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
127
- `)}function u1(t){let e=t.slice(2);if(e.includes("--version")||e.includes("-v"))return{mode:"version"};if(e.includes("--daemon"))return{mode:"daemon"};if(e[0]==="status")return{mode:"status"};if(e[0]==="stop")return{mode:"stop"};if(e[0]==="reload"){let{value:D}=Ue(e.slice(1),"--agent-id");return D?{mode:"reload",agentId:D}:{mode:"reload"}}if(e[0]==="update")return{mode:"update"};if(e[0]==="purge")return{mode:"purge"};if(e[0]==="service")return e[1]==="install"?{mode:"service-install"}:e[1]==="uninstall"?{mode:"service-uninstall"}:{mode:"help"};if(e[0]==="send")return f1(e.slice(1));if(e[0]==="log")return{mode:"log",...Fx(e.slice(1))};if(e[0]==="connect")return h1(e.slice(1));if(e.includes("--status"))return ia("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return ia("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return ia("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return ia("--install-service","coze-bridge service install"),{mode:"service-install"};if(e.includes("--help")||e.includes("-h")||e.length===0)return{mode:"help"};let r=e,{value:i,rest:o}=Ue(r,"--pat-token");r=o;let{value:c,rest:l}=Ue(r,"--pair-code");r=l;let{value:u,rest:f}=Ue(r,"--env");r=f;let{value:x,rest:m}=Ue(r,"--handshake-url");r=m;let{value:w,rest:b}=Ue(r,"--frontier-url");r=b;let{value:p,rest:_}=Ue(r,"--mock-scenario");r=_;let{value:S}=Ue(r,"--agent-id"),A=r.includes("--skip-rebuild-env");if(!i||!c)return{mode:"help"};let T={mode:"pair",privatecode:i,pairingCode:c};return u&&(T.env=u),x&&(T.handshakeUrl=x),w&&(T.frontierUrl=w),p&&(T.mockScenario=p),S&&(T.agentId=S),A&&(T.skipRebuildEnv=!0),T}function f1(t){let e=t[0],r=t[1];if(e!=="image"&&e!=="file")return{mode:"help"};if(!r||r.startsWith("--"))return{mode:"help"};let i=t.slice(2),{value:o,rest:c}=Ue(i,"--caption");i=c;let{value:l,rest:u}=Ue(i,"--name");i=u;let{value:f,rest:x}=Ue(i,"--agent-id");i=x;let{value:m,rest:w}=Ue(i,"--session-id");i=w;let{value:b,rest:p}=Ue(i,"--mime");i=p;let _=i.includes("--group-file");i=i.filter(T=>T!=="--group-file");let S=i.includes("--json"),A={mode:"send",kind:e,path:r,json:S};return o&&(A.caption=o),l&&(A.name=l),f&&(A.agentId=f),m&&(A.sessionId=m),_&&(A.groupFile=!0),b&&(A.mimeType=b),A}function h1(t){let e=t,{value:r,rest:i}=Ue(e,"--pat-token");e=i;let{value:o,rest:c}=Ue(e,"--env");e=c;let{value:l,rest:u}=Ue(e,"--handshake-url");e=u;let{value:f,rest:x}=Ue(e,"--frontier-url");e=x;let{value:m,rest:w}=Ue(e,"--mock-scenario");e=w;let b=e.includes("--skip-rebuild-env"),p={mode:"connect"};return r&&(p.privatecode=r),o&&(p.env=o),l&&(p.handshakeUrl=l),f&&(p.frontierUrl=f),m&&(p.mockScenario=m),b&&(p.skipRebuildEnv=!0),p}var x1=`
121
+ `),BS(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
122
+ `);else{let l=t.name??OS(o.path);if(t.groupFile){let u=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${l} (uri=${u})
123
+ `)}else process.stdout.write(`Sent ${t.kind} ${l} (${zS(c.bytes)})
124
+ `)}return 0}async function FS(t,e,r,i){let o=new AbortController,c=setTimeout(()=>o.abort(),i);try{let l=await fetch(`http://127.0.0.1:${t.port}${e}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"content-type":"application/json"},body:JSON.stringify(r),signal:o.signal}),u=await l.text(),h=u?JSON.parse(u):null;return h&&typeof h=="object"&&"ok"in h?h:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${l.status}): ${u.slice(0,200)}`}}finally{clearTimeout(c)}}function zS(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var Zx=U("cli");function He(t,e){let{value:r,rest:i}=Sn(t,e);return{value:r,rest:i}}function ia(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
125
+ `)}function d1(t){let e=t.slice(2);if(e.includes("--version")||e.includes("-v"))return{mode:"version"};if(e.includes("--daemon"))return{mode:"daemon"};if(e[0]==="status")return{mode:"status"};if(e[0]==="stop")return{mode:"stop"};if(e[0]==="reload"){let{value:R}=He(e.slice(1),"--agent-id");return R?{mode:"reload",agentId:R}:{mode:"reload"}}if(e[0]==="update")return{mode:"update"};if(e[0]==="purge")return{mode:"purge"};if(e[0]==="service")return e[1]==="install"?{mode:"service-install"}:e[1]==="uninstall"?{mode:"service-uninstall"}:{mode:"help"};if(e[0]==="send")return l1(e.slice(1));if(e[0]==="log")return{mode:"log",...Fx(e.slice(1))};if(e[0]==="connect")return u1(e.slice(1));if(e.includes("--status"))return ia("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return ia("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return ia("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return ia("--install-service","coze-bridge service install"),{mode:"service-install"};if(e.includes("--help")||e.includes("-h")||e.length===0)return{mode:"help"};let r=e,{value:i,rest:o}=He(r,"--pat-token");r=o;let{value:c,rest:l}=He(r,"--pair-code");r=l;let{value:u,rest:h}=He(r,"--env");r=h;let{value:x,rest:w}=He(r,"--handshake-url");r=w;let{value:_,rest:S}=He(r,"--frontier-url");r=S;let{value:E,rest:v}=He(r,"--mock-scenario");r=v;let{value:A}=He(r,"--agent-id");if(!i||!c)return{mode:"help"};let I={mode:"pair",privatecode:i,pairingCode:c};return u&&(I.env=u),x&&(I.handshakeUrl=x),_&&(I.frontierUrl=_),E&&(I.mockScenario=E),A&&(I.agentId=A),I}function l1(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}=He(i,"--caption");i=c;let{value:l,rest:u}=He(i,"--name");i=u;let{value:h,rest:x}=He(i,"--agent-id");i=x;let{value:w,rest:_}=He(i,"--session-id");i=_;let{value:S,rest:E}=He(i,"--mime");i=E;let v=i.includes("--group-file");i=i.filter(R=>R!=="--group-file");let A=i.includes("--json"),I={mode:"send",kind:e,path:r,json:A};return o&&(I.caption=o),l&&(I.name=l),h&&(I.agentId=h),w&&(I.sessionId=w),v&&(I.groupFile=!0),S&&(I.mimeType=S),I}function u1(t){let e=t,{value:r,rest:i}=He(e,"--pat-token");e=i;let{value:o,rest:c}=He(e,"--env");e=c;let{value:l,rest:u}=He(e,"--handshake-url");e=u;let{value:h,rest:x}=He(e,"--frontier-url");e=x;let{value:w,rest:_}=He(e,"--mock-scenario");e=_;let S={mode:"connect"};return r&&(S.privatecode=r),o&&(S.env=o),l&&(S.handshakeUrl=l),h&&(S.frontierUrl=h),w&&(S.mockScenario=w),S}var f1=`
128
126
  coze-bridge - local bridge daemon for cloud Agent Service
129
127
 
130
128
  Pair (paste from cloud UI; start/reuse daemon and deliver pair-code):
@@ -187,8 +185,6 @@ Pair flags (optional, per-pair, not persisted):
187
185
  ppe_coze_project mock_conf \u914D\u7F6E (TCC \u9700\u5F00 mock_conf.enabled).
188
186
  --agent-id <id> pair \u540E\u81EA\u52A8 connect \u6307\u5B9A agent \u2014 \u672C\u5730\u5DF2\u6709\u8D70 reconnect/
189
187
  revive, \u6CA1\u6709\u8D70 _agent/detail \u62C9\u4E91\u7AEF\u8BE6\u60C5\u7136\u540E\u672C\u5730\u65B0\u5EFA
190
- --skip-rebuild-env \u4E0D\u8DD1 $SHELL -ilc \u91CD\u5EFA\u767B\u5F55\u73AF\u5883, \u76F4\u63A5\u7528\u5F53\u524D\u8FDB\u7A0B env \u5199
191
- agent-env.json (\u9ED8\u8BA4\u4F1A\u91CD\u5EFA; cloud \u6D3E\u53D1\u5E94\u5E26\u6B64 flag)
192
188
 
193
189
  Example: npx -y coze-bridge --pat-token=sat_xxx --pair-code=xxx --env=ppe_xxx --agent-id=7639628097007927571
194
190
 
@@ -205,57 +201,56 @@ Deprecated flags (still work, but emit a warning; will be removed in a future re
205
201
 
206
202
  Internal:
207
203
  <node> <entry> --daemon daemon mode (OS supervisor only)
208
- `.trimStart();async function Xx(t=process.argv,e={}){let r=u1(t);switch(r.mode){case"help":return process.stdout.write(x1),0;case"version":return process.stdout.write(`${Sr}
209
- `),0;case"daemon":{try{await Ix()}catch(i){return Yx.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return p1(e);case"stop":return ep(e);case"reload":return w1(r.agentId,e);case"log":return Hx(r,e);case"update":return g1(e);case"purge":return _1(e);case"service-install":return y1(e);case"service-uninstall":return E1(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),b1(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),v1(r.privatecode,e,i,r.skipRebuildEnv)}case"send":return qx({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 Qx(t){let{unlink:e}=await import("node:fs/promises");await Promise.all([e(t.pidFile).catch(()=>{}),e(t.portFile).catch(()=>{}),e(t.tokenFile).catch(()=>{})])}async function p1(t){let e=t.paths??X(),r=new Yt(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
204
+ `.trimStart();async function Xx(t=process.argv,e={}){let r=d1(t);switch(r.mode){case"help":return process.stdout.write(f1),0;case"version":return process.stdout.write(`${Sr}
205
+ `),0;case"daemon":{try{await Cx()}catch(i){return Zx.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return h1(e);case"stop":return ep(e);case"reload":return g1(r.agentId,e);case"log":return Hx(r,e);case"update":return x1(e);case"purge":return m1(e);case"service-install":return w1(e);case"service-uninstall":return _1(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),y1(r.privatecode,r.pairingCode,e,i,r.agentId)}case"connect":{let i={};return r.env&&(i.env=r.env),r.handshakeUrl&&(i.handshakeUrl=r.handshakeUrl),r.frontierUrl&&(i.frontierUrl=r.frontierUrl),r.mockScenario&&(i.mockScenario=r.mockScenario),E1(r.privatecode,e,i)}case"send":return qx({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 Qx(t){let{unlink:e}=await import("node:fs/promises");await Promise.all([e(t.pidFile).catch(()=>{}),e(t.portFile).catch(()=>{}),e(t.tokenFile).catch(()=>{})])}async function h1(t){let e=t.paths??Q(),r=new Yt(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
210
206
  `),1;if(i.kind==="stale")return await Qx(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
211
207
  `),1;let o=await r.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
212
208
  ${JSON.stringify(o.body,null,2)}
213
- `),0}async function ep(t){let e=t.paths??X(),r=new Yt(e),i=t.daemonSweep??(async()=>{let f=a0();return await c0(f),f}),o=async()=>{t.skipProcessKill||await i(e)},c=await es(t),l=!1;if(c)try{await c.uninstall(),l=!0}catch(f){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(f)}
214
- `)}let u=await r.probe();if(u.kind==="not-running")return await o(),process.stdout.write(l?`coze-bridge: stopped
209
+ `),0}async function ep(t){let e=t.paths??Q(),r=new Yt(e),i=await Xi(t),o=!1;if(i)try{await i.uninstall(),o=!0}catch(l){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(l)}
210
+ `)}let c=await r.probe();if(c.kind==="not-running")return process.stdout.write(o?`coze-bridge: stopped
215
211
  `:`coze-bridge: not running
216
- `),0;if(u.kind==="stale")return await Qx(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
217
- `),0;try{return await r.request({method:"POST",path:"/shutdown"}),await o(),process.stdout.write(`coze-bridge: stopped
218
- `),0}catch(f){return(await r.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
219
- `),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(f)}
220
- `),1)}}async function g1(t){return await ep(t),(t.spawnNpx??m1)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function m1(t){return new Promise(e=>{let r=at("npx",t,{stdio:"inherit"});r.on("exit",i=>e(i??1)),r.on("error",i=>{process.stderr.write(`coze-bridge: spawn npx failed: ${String(i)}
221
- `),e(1)})})}async function w1(t,e){let r=new Yt(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
212
+ `),0;if(c.kind==="stale")return await Qx(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
213
+ `),0;try{return await r.request({method:"POST",path:"/shutdown"}),process.stdout.write(`coze-bridge: stopped
214
+ `),0}catch(l){return(await r.probe()).kind!=="connected"?(process.stdout.write(`coze-bridge: stopped
215
+ `),0):(process.stdout.write(`coze-bridge: stop failed: ${String(l)}
216
+ `),1)}}async function x1(t){return await ep(t),(t.spawnNpx??p1)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function p1(t){return new Promise(e=>{let r=dt("npx",t,{stdio:"inherit"});r.on("exit",i=>e(i??1)),r.on("error",i=>{process.stderr.write(`coze-bridge: spawn npx failed: ${String(i)}
217
+ `),e(1)})})}async function g1(t,e){let r=new Yt(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
222
218
  `),1;try{let o=await r.request({method:"POST",path:"/reload",body:t?{agent_id:t}:{},timeoutMs:35e3});if(o.status===200&&o.body?.ok){let c=o.body.recycled??[];return t&&c.length===0?process.stdout.write(`coze-bridge: agent ${t} \u65E0\u8FD0\u884C\u4E2D\u5B50\u8FDB\u7A0B\u53EF\u56DE\u6536 (\u672A\u6CE8\u518C / \u5DF2 idle)
223
219
  `):process.stdout.write(`coze-bridge: reloaded ${c.length} agent(s): ${c.join(", ")||"(none)"}
224
220
  `),0}return process.stderr.write(`coze-bridge: reload failed: ${JSON.stringify(o.body)}
225
221
  `),1}catch(o){return process.stderr.write(`coze-bridge: reload failed: ${String(o)}
226
- `),1}}async function es(t){if(t.supervisor){let c=t.supervisor,l={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:u=>c.install(l,u),uninstall:()=>c.uninstall(l)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>(Jx(),Vx)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function tp(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??vx,o=t.waitTimeoutMs??15e3,c=t.sleep??I1,l=t.paths??X(),u=await es(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let f=await Zx(e,o,c);if(f.kind==="connected")return f;It(l.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:o})}catch(f){It(l.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(f)})}It(l.bridgeLogsDir,"warn","cli","\u79FB\u9664\u5F00\u673A\u81EA\u542F\u914D\u7F6E (supervisor \u63A5\u7BA1\u672A\u6210\u529F, \u56DE\u9000\u624B\u52A8 spawn; \u4E0B\u6B21\u91CD\u542F\u4E0D\u518D\u81EA\u542F, \u9700\u91CD\u65B0 service install)",{platform:u.platform}),await u.uninstall().catch(()=>{}),await S1(l.pidFile,c)}else u&&await u.install({activate:!1}).catch(f=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(f)}
222
+ `),1}}async function Xi(t){if(t.supervisor){let c=t.supervisor,l={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:u=>c.install(l,u),uninstall:()=>c.uninstall(l)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>(Vx(),Jx)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function tp(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??Ax,o=t.waitTimeoutMs??15e3,c=t.sleep??v1,l=t.paths??Q(),u=await Xi(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let h=await Yx(e,o,c);if(h.kind==="connected")return h;er(l.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:o})}catch(h){er(l.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(h)})}er(l.bridgeLogsDir,"warn","cli","\u79FB\u9664\u5F00\u673A\u81EA\u542F\u914D\u7F6E (supervisor \u63A5\u7BA1\u672A\u6210\u529F, \u56DE\u9000\u624B\u52A8 spawn; \u4E0B\u6B21\u91CD\u542F\u4E0D\u518D\u81EA\u542F, \u9700\u91CD\u65B0 service install)",{platform:u.platform}),await u.uninstall().catch(()=>{}),await b1(l.pidFile,c)}else u&&await u.install({activate:!1}).catch(h=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(h)}
227
223
  `));return process.stdout.write(`coze-bridge: starting daemon...
228
- `),await i({paths:t.paths}),Zx(e,o,c)}async function _1(t){let e=new Yt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
224
+ `),await i({paths:t.paths}),Yx(e,o,c)}async function m1(t){let e=new Yt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
229
225
  `);try{await e.request({method:"POST",path:"/shutdown"})}catch(l){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(l)}
230
- `)}await new Promise(l=>setTimeout(l,500))}let i=await es(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
226
+ `)}await new Promise(l=>setTimeout(l,500))}let i=await Xi(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
231
227
  `)}catch(l){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(l)}
232
- `)}let o=t.paths??X(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
228
+ `)}let o=t.paths??Q(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
233
229
  `)}catch(l){return process.stderr.write(`coze-bridge: remove failed: ${String(l)}
234
230
  `),1}return process.stdout.write(`coze-bridge: purged (agents workspaces preserved under ~/.coze/agents)
235
- `),0}async function y1(t){let e=await es(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
231
+ `),0}async function w1(t){let e=await Xi(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
236
232
  `),await e.install(),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
237
233
  `),0}catch(r){return process.stderr.write(`coze-bridge: service install failed: ${String(r)}
238
- `),1}}async function E1(t){let e=await es(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
234
+ `),1}}async function _1(t){let e=await Xi(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
239
235
  `),0}catch(r){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(r)}
240
- `),1}}async function np(t,e,r){if(e)return It(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await r();return i.kind==="ok"?(It(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(It(t.bridgeLogsDir,"info","cli","agent-env: rebuild not applicable, use process.env",{reason:i.reason}),process.env):(process.stderr.write(`coze-bridge: \u91CD\u5EFA shell \u73AF\u5883\u5931\u8D25, \u56DE\u9000\u5F53\u524D\u8FDB\u7A0B\u73AF\u5883 (\u53EF\u7528 --skip-rebuild-env \u663E\u5F0F\u8DF3\u8FC7)
241
- `),It(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function b1(t,e,r,i={},o,c){let l=new Yt(r.paths),u=r.paths??X(),f=await np(u,c,r.reconstructEnv??Ol);if(await Jc(u,f).catch(w=>It(u.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(w)})),!r.skipDistInstall){let w=await Fl({paths:r.paths});w.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${w.fromVersion} \u2192 ${w.toVersion}
242
- `),(await l.probe()).kind==="connected"&&(await l.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(p=>setTimeout(p,500)))):w.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${w.libVersion}
243
- `)}let x=await tp(r,l);if(x.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${x.kind}
244
- `),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 w=await l.request({method:"POST",path:"/pair",body:m,timeoutMs:35e3});if(w.status===200&&w.body?.ok){let b=w.body.agent;return b&&!b.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${b.agentId}): ${b.note}
236
+ `),1}}async function y1(t,e,r,i={},o){let c=new Yt(r.paths),l=r.paths??Q();if(await Jc(l).catch(x=>er(l.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(x)})),!r.skipDistInstall){let x=await Md({paths:r.paths});x.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${x.fromVersion} \u2192 ${x.toVersion}
237
+ `),(await c.probe()).kind==="connected"&&(await c.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(_=>setTimeout(_,500)))):x.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${x.libVersion}
238
+ `)}let u=await tp(r,c);if(u.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${u.kind}
239
+ `),1;let h={privatecode:t,pairing_code:e};i.env&&(h.env=i.env),i.handshakeUrl&&(h.handshake_url=i.handshakeUrl),i.frontierUrl&&(h.frontier_url=i.frontierUrl),i.mockScenario&&(h.mock_scenario=i.mockScenario),o&&(h.agent_id=o);try{let x=await c.request({method:"POST",path:"/pair",body:h,timeoutMs:35e3});if(x.status===200&&x.body?.ok){let w=x.body.agent;return w&&!w.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${w.agentId}): ${w.note}
245
240
  `),1):(process.stdout.write(`\u5DF2\u914D\u5BF9\u8FDE\u63A5\u5B8C\u6210\uFF0C\u8BF7\u8FD4\u56DE\u5230 coze \u5E73\u53F0\u4E0A\u70B9\u51FB "\u6211\u5DF2\u6267\u884C"
246
- `),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(w.body)}
247
- `),1}catch(w){return process.stderr.write(`coze-bridge: pair failed: ${String(w)}
248
- `),1}}async function v1(t,e,r={},i){let o=e.paths??X(),c=t??await Go(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 Yt(e.paths),u=await np(o,i,e.reconstructEnv??Ol);if(await Jc(o,u).catch(m=>It(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(m)})),!e.skipDistInstall){let m=await Fl({paths:e.paths});m.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${m.fromVersion} \u2192 ${m.toVersion}
249
- `),(await l.probe()).kind==="connected"&&(await l.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(b=>setTimeout(b,500)))):m.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${m.libVersion}
250
- `)}let f=await tp(e,l);if(f.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${f.kind}
251
- `),1;let x={privatecode:c};r.env&&(x.env=r.env),r.handshakeUrl&&(x.handshake_url=r.handshakeUrl),r.frontierUrl&&(x.frontier_url=r.frontierUrl),r.mockScenario&&(x.mock_scenario=r.mockScenario);try{let 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"})
252
- `),await Zi(c,o).catch(w=>Yx.warn("writePatToken after connect failed (ignored)",{err:String(w)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(m.body)}
253
- `),1)}catch(m){return process.stderr.write(`coze-bridge: connect failed: ${String(m)}
254
- `),1}}async function Zx(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 S1(t,e,r=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let c=0;c<r;c++){let l;try{l=await o(t,"utf8")}catch{return}let u=Number.parseInt(l.trim(),10);if(!Number.isFinite(u)||u<=0||!Li(u))return;await e(i)}}function I1(t){return new Promise(e=>setTimeout(e,t))}ee();function A1(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 rp(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=A1(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
241
+ `),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(x.body)}
242
+ `),1}catch(x){return process.stderr.write(`coze-bridge: pair failed: ${String(x)}
243
+ `),1}}async function E1(t,e,r={}){let i=e.paths??Q(),o=t??await Go(i);if(!o)return process.stderr.write("coze-bridge: \u627E\u4E0D\u5230 patToken \u2014 \u5148\u8DD1\u4E00\u6B21 `coze-bridge --pat-token=<sat_xxx> --pair-code=<xxx>` \u914D\u5BF9, \u6216\u672C\u6B21\u7528 `--pat-token` \u6307\u5B9A\n"),1;let c=new Yt(e.paths);if(await Jc(i).catch(h=>er(i.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(h)})),!e.skipDistInstall){let h=await Md({paths:e.paths});h.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${h.fromVersion} \u2192 ${h.toVersion}
244
+ `),(await c.probe()).kind==="connected"&&(await c.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(w=>setTimeout(w,500)))):h.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${h.libVersion}
245
+ `)}let l=await tp(e,c);if(l.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${l.kind}
246
+ `),1;let u={privatecode:o};r.env&&(u.env=r.env),r.handshakeUrl&&(u.handshake_url=r.handshakeUrl),r.frontierUrl&&(u.frontier_url=r.frontierUrl),r.mockScenario&&(u.mock_scenario=r.mockScenario);try{let h=await c.request({method:"POST",path:"/connect",body:u,timeoutMs:35e3});return h.status===200&&h.body?.ok?(process.stdout.write(`coze-bridge: connected (${h.body.note??"ok"})
247
+ `),await Ji(o,i).catch(x=>Zx.warn("writePatToken after connect failed (ignored)",{err:String(x)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(h.body)}
248
+ `),1)}catch(h){return process.stderr.write(`coze-bridge: connect failed: ${String(h)}
249
+ `),1}}async function Yx(t,e,r){let i=Date.now()+e;for(;Date.now()<i;){let o=await t.probe(500);if(o.kind==="connected")return o;await r(200)}return t.probe(500)}async function b1(t,e,r=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let c=0;c<r;c++){let l;try{l=await o(t,"utf8")}catch{return}let u=Number.parseInt(l.trim(),10);if(!Number.isFinite(u)||u<=0||!oo(u))return;await e(i)}}function v1(t){return new Promise(e=>setTimeout(e,t))}ne();function S1(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 np(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=S1(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
255
250
  `),r(1)):e(`[coze-bridge] \u68C0\u6D4B\u5230 Node.js v${o},\u672C\u9879\u76EE\u63A8\u8350 v20+,\u4F4E\u4E8E v20 \u540E\u7EED\u5347\u7EA7\u53EF\u80FD\u6709\u517C\u5BB9\u95EE\u9898,\u5EFA\u8BAE\u5347\u7EA7\u3002
256
251
  \u5347\u7EA7\u5B8C\u540E\u9700\u8981\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u91CD\u65B0\u8FDE\u63A5:
257
252
  npx -y coze-bridge@latest stop
258
253
  npx -y coze-bridge@latest connect
259
254
 
260
- `)}rp();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&dd("warn");Xx(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
255
+ `)}np();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&ll("warn");Xx(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
261
256
  `),process.exit(1)});