coze-bridge 0.1.98-alpha.0 → 0.1.98-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +81 -81
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5,34 +5,34 @@ import { dirname as __coze_dirname } from 'node:path';
5
5
  const require = __coze_createRequire(import.meta.url);
6
6
  const __filename = __coze_fileURLToPath(import.meta.url);
7
7
  const __dirname = __coze_dirname(__filename);
8
- var Rp=Object.create;var ha=Object.defineProperty;var kp=Object.getOwnPropertyDescriptor;var Op=Object.getOwnPropertyNames;var Pp=Object.getPrototypeOf,Lp=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 Ze=(t,e)=>()=>(t&&(e=t(t=0)),e);var se=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),pa=(t,e)=>{for(var r in e)ha(t,r,{get:e[r],enumerable:!0})},Np=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Op(e))!Lp.call(t,o)&&o!==r&&ha(t,o,{get:()=>e[o],enumerable:!(i=kp(e,o))||i.enumerable});return t};var At=(t,e,r)=>(r=t!=null?Rp(Pp(t)):{},Np(e||!t||!t.__esModule?ha(r,"default",{value:t,enumerable:!0}):r,t));function Ft(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Xi=Ze(()=>{"use strict"});import{createWriteStream as Mp,mkdirSync as Bp,readdirSync as zp,unlinkSync as Fp}from"node:fs";import{join as el}from"node:path";function In(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 ga(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function Up(t,e,r){let i=c=>{let[l,u,x]=c.split("-").map(Number);return Date.UTC(l??0,(u??1)-1,x??1)};return Math.floor((i(e)-i(t))/864e5)>r}function Qi(t,e,r,i){let o;try{o=zp(t)}catch{return}for(let c of o){let l=ga(c,e);if(l&&Up(l,r,i))try{Fp(el(t,c))}catch{}}}var jr,ma=Ze(()=>{"use strict";jr=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>In(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{Bp(this.dir,{recursive:!0});let r=Mp(el(this.dir,Xn(this.prefix,e)),{flags:"a"});r.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
8
+ var Dp=Object.create;var fa=Object.defineProperty;var kp=Object.getOwnPropertyDescriptor;var Op=Object.getOwnPropertyNames;var Pp=Object.getPrototypeOf,Lp=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 Ke=(t,e)=>()=>(t&&(e=t(t=0)),e);var se=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ua=(t,e)=>{for(var r in e)fa(t,r,{get:e[r],enumerable:!0})},Np=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Op(e))!Lp.call(t,o)&&o!==r&&fa(t,o,{get:()=>e[o],enumerable:!(i=kp(e,o))||i.enumerable});return t};var bt=(t,e,r)=>(r=t!=null?Dp(Pp(t)):{},Np(e||!t||!t.__esModule?fa(r,"default",{value:t,enumerable:!0}):r,t));function Mt(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Vi=Ke(()=>{"use strict"});import{createWriteStream as Mp,mkdirSync as Bp,readdirSync as zp,unlinkSync as Fp}from"node:fs";import{join as Xd}from"node:path";function Sn(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function Jn(t,e){return`${t}-${e}.log`}function ha(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function Up(t,e,r){let i=c=>{let[d,f,h]=c.split("-").map(Number);return Date.UTC(d??0,(f??1)-1,h??1)};return Math.floor((i(e)-i(t))/864e5)>r}function Ji(t,e,r,i){let o;try{o=zp(t)}catch{return}for(let c of o){let d=ha(c,e);if(d&&Up(d,r,i))try{Fp(Xd(t,c))}catch{}}}var jr,xa=Ke(()=>{"use strict";jr=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>Sn(new Date))}dir;prefix;opts;currentDate;stream;clock;write(e){let r=this.clock();r!==this.currentDate&&this.rotate(r),this.stream?.write(e)}rotate(e){this.stream?.end();try{Bp(this.dir,{recursive:!0});let r=Mp(Xd(this.dir,Jn(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&&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 Gp,mkdirSync as qp}from"node:fs";import{join as Hp}from"node:path";function nl(t){let e=t.retentionDays??Kp,r=t.clock??(()=>In(new Date));ts={bridgeSink:new jr(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new jr(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();Qi(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])Qi(t.agentLogsDir(o),"agent",i,e)}function $p(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function rl(t){wa=t}function il(t){return Qn[wa]<=Qn[t]}function sl(t,e){let r=Qn[t];return r===void 0?!0:r>=Qn[e]}function ns(t){tl={...t}}function ol(t){let e=(u,x=2)=>String(u).padStart(x,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),l=e(o%60);return`${In(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${l}`}function Wr(t,e,r,i,o){try{let c=`${JSON.stringify({ts:ol(new Date),level:e,module:r,msg:i,...o})}
11
- `;qp(t,{recursive:!0}),Gp(Hp(t,Xn("bridge",In(new Date))),c)}catch{}}function Vp(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[wa])return;let c=`${JSON.stringify({ts:ol(new Date),level:t,module:e,msg:r,...tl,...i})}
12
- `;if(ts){let l=Vp(o,i),u=l?$p(ts,l):ts.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?Wp.write(c):jp.write(c)}function G(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=>G(`${t}.${r}`,e),forAgent:r=>G(t,r)}}var Qn,wa,jp,Wp,tl,Kp,ts,ne=Ze(()=>{"use strict";Xi();ma();Qn={debug:10,info:20,warn:30,error:40},wa=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),jp=process.stdout,Wp=process.stderr,tl={},Kp=Ft("COZE_BRIDGE_LOG_RETENTION_DAYS",30),ts=null});var T,Ke=Ze(()=>{"use strict";T=class extends Error{code;retriable;cause;constructor(e,r,i){super(r),this.name="BridgeError",this.code=e,this.retriable=i?.retriable??!1,i?.cause!==void 0&&(this.cause=i.cause)}}});var ll={};pa(ll,{ACP_WRAPPER_NPM_PACKAGES:()=>$r,_resetAcpInstallerForTests:()=>eg,_setBinaryPathCacheForTests:()=>tg,buildAcpSpawn:()=>Vr,ensureAcpInstalled:()=>er,getAcpBinaryPath:()=>rs,pickWhichLine:()=>Ea,probeAcpVersion:()=>Qp,resolveAcpCommand:()=>dl});import{readFileSync as al}from"node:fs";import{createRequire as Jp}from"node:module";import{dirname as Zp,resolve as Yp}from"node:path";function Ea(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 Xp(t){let e=cl.resolve(`${t.npmPackage}/package.json`),r=Zp(e),i=JSON.parse(al(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 Yp(r,o)}async function er(t,e){let r=ya[t];if(!r)throw new T("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=Kr.get(t);if(i)return i;try{let o=Xp(r);return Kr.set(t,o),_a.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw _a.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:r.npmPackage,err:String(o)}),new T("AGENT_DEPENDENCY_INSTALL_FAILED",[`ACP wrapper \u672A\u5C31\u7EEA: ${r.npmPackage} (framework=${t})`,"\u8BE5 wrapper \u968F coze-bridge \u4E00\u8D77\u5B89\u88C5 (\u56FA\u5316\u5230 ~/.coze/bridge/lib/node_modules)\u3002","\u8BF7\u91CD\u8DD1 `coze-bridge pair` / `connect` \u89E6\u53D1\u56FA\u5316\u5B89\u88C5; \u82E5\u4ECD\u5931\u8D25, \u68C0\u67E5\u7F51\u7EDC / npm \u7F13\u5B58\u3002"].join(`
13
- `),{cause:o})}}async function Qp(t){let e=ya[t];if(e)try{let r=cl.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(al(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){_a.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function rs(t){return Kr.get(t)}function dl(t,e){if(e)return e;let r=rs(t);if(!r)throw new T("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return r}function Vr(t,e,r){if(e)return{command:e,args:[...r]};let i=dl(t);return{command:process.execPath,args:[i,...r]}}function eg(){Kr.clear()}function tg(t,e){Kr.set(t,e)}var _a,ya,$r,cl,Kr,nn=Ze(()=>{"use strict";Ke();ne();_a=G("agents.acp-installer"),ya={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},$r=Object.values(ya).filter(t=>t!==void 0).map(t=>t.npmPackage),cl=Jp(import.meta.url),Kr=new Map});import{chmod as rg,mkdir as ig,readFile as sg,rename as xl,writeFile as hl}from"node:fs/promises";import{dirname as og}from"node:path";async function tr(t){try{let e=await sg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function nr(t,e,r){await ig(og(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 hl(o,i,{encoding:"utf8",mode:r.mode}):await hl(o,i,"utf8"),await xl(o,t),r?.mode!==void 0&&await rg(t,r.mode)}catch(c){await xl(o,o).catch(()=>{});let{rm:l}=await import("node:fs/promises");throw await l(o,{force:!0}).catch(()=>{}),c}}var Jr=Ze(()=>{"use strict"});import{promises as pl,readdirSync as ag}from"node:fs";import{homedir as cg}from"node:os";import{sep as dg,join as Te,resolve as gl}from"node:path";function X(t){let e=t??cg(),r=Te(e,".coze"),i=Te(r,"bridge"),o=Te(i,"lib"),c=Te(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Te(o,"index.js"),binDir:Te(i,"bin"),pidFile:Te(i,"bridge.pid"),portFile:Te(i,"bridge.port"),tokenFile:Te(i,"bridge.token"),patTokenFile:Te(i,"pat-token"),agentEnvFile:Te(i,"agent-env.json"),logFile:Te(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Te(c,"daemon-stdio.log"),installLock:Te(i,"install.lock"),configFile:Te(i,"config.json"),agentsRoot:Te(r,"agents")}}function $e(t,e=X()){let r=Te(e.agentsRoot,t);return{root:r,config:Te(r,"config.json"),workspace:Te(r,"workspace"),logs:Te(r,"logs")}}function is(t=X()){try{return ag(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function Zr(t,e){let r=await pl.realpath(gl(t)).catch(()=>null);if(!r)return!1;let i=await pl.realpath(gl(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+dg)}var Oe=Ze(()=>{"use strict"});var as={};pa(as,{AGENT_CONFIG_FILE_MODE:()=>ss,enforceAgentConfigMode:()=>fg,loadAgentConfig:()=>He,persistAgentSessions:()=>Yr,persistAgentSkills:()=>os,saveAgentConfig:()=>Ye});import{chmod as lg,stat as ug}from"node:fs/promises";function He(t,e){return tr($e(t,e).config)}function Ye(t,e){return nr($e(t.agentId,e).config,t,{mode:ss})}async function fg(t,e){if(process.platform==="win32")return;let r=$e(t,e).config;try{let i=await ug(r);if(!i.isFile())return;let o=i.mode&511;o!==ss&&(await lg(r,ss),ml.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;ml.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function Yr(t,e,r){let i=await He(t,r);i&&(i.sessions=Object.fromEntries(e),await Ye(i,r))}async function os(t,e,r){let i=await He(t,r);i&&(i.skills=e,await Ye(i,r))}var ml,ss,rn=Ze(()=>{"use strict";Jr();ne();Oe();ml=G("agent-config"),ss=384});var va=se((M1,El)=>{El.exports={LOCHDR:30,LOCSIG:67324752,LOCVER:4,LOCFLG:6,LOCHOW:8,LOCTIM:10,LOCCRC:14,LOCSIZ:18,LOCLEN:22,LOCNAM:26,LOCEXT:28,EXTSIG:134695760,EXTHDR:16,EXTCRC:4,EXTSIZ:8,EXTLEN:12,CENHDR:46,CENSIG:33639248,CENVEM:4,CENVER:6,CENFLG:8,CENHOW:10,CENTIM:12,CENCRC:16,CENSIZ:20,CENLEN:24,CENNAM:28,CENEXT:30,CENCOM:32,CENDSK:34,CENATT:36,CENATX:38,CENOFF:42,ENDHDR:22,ENDSIG:101010256,ENDSUB:8,ENDTOT:10,ENDSIZ:12,ENDOFF:16,ENDCOM:20,END64HDR:20,END64SIG:117853008,END64START:4,END64OFF:8,END64NUMDISKS:16,ZIP64SIG:101075792,ZIP64HDR:56,ZIP64LEAD:12,ZIP64SIZE:4,ZIP64VEM:12,ZIP64VER:14,ZIP64DSK:16,ZIP64DSKDIR:20,ZIP64SUB:24,ZIP64TOT:32,ZIP64SIZB:40,ZIP64OFF:48,ZIP64EXTRA:56,STORED:0,SHRUNK:1,REDUCED1:2,REDUCED2:3,REDUCED3:4,REDUCED4:5,IMPLODED:6,DEFLATED:8,ENHANCED_DEFLATED:9,PKWARE:10,BZIP2:12,LZMA:14,IBM_TERSE:18,IBM_LZ77:19,AES_ENCRYPT:99,FLG_ENC:1,FLG_COMP1:2,FLG_COMP2:4,FLG_DESC:8,FLG_ENH:16,FLG_PATCH:32,FLG_STR:64,FLG_EFS:2048,FLG_MSK:4096,FILE:2,BUFFER:1,NONE:0,EF_ID:0,EF_SIZE:2,ID_ZIP64:1,ID_AVINFO:7,ID_PFS:8,ID_OS2:9,ID_NTFS:10,ID_OPENVMS:12,ID_UNIX:13,ID_FORK:14,ID_PATCH:15,ID_X509_PKCS7:20,ID_X509_CERTID_F:21,ID_X509_CERTID_C:22,ID_STRONGENC:23,ID_RECORD_MGT:24,ID_X509_PKCS7_RL:25,ID_IBM1:101,ID_IBM2:102,ID_POSZIP:18064,EF_ZIP64_OR_32:4294967295,EF_ZIP64_OR_16:65535,EF_ZIP64_SUNCOMP:0,EF_ZIP64_SCOMP:8,EF_ZIP64_RHO:16,EF_ZIP64_DSN:24}});var ds=se(vl=>{var bl={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 mg(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(bl))vl[t]=mg(bl[t])});var Cl=se((z1,Tl)=>{var wg=de("fs"),Pe=de("path"),Sl=va(),_g=ds(),yg=typeof process=="object"&&process.platform==="win32",Al=t=>typeof t=="object"&&t!==null,Il=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function be(t){this.sep=Pe.sep,this.fs=wg,Al(t)&&Al(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Tl.exports=be;be.prototype.makeDir=function(t){let e=this;function r(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var l;try{l=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(l&&l.isFile())throw _g.FILE_IN_THE_WAY(`"${o}"`)}})}r(t)};be.prototype.writeFileTo=function(t,e,r,i){let o=this;if(o.fs.existsSync(t)){if(!r)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var l=Pe.dirname(t);o.fs.existsSync(l)||o.makeDir(l);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};be.prototype.writeFileToAsync=function(t,e,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(l){if(l&&!r)return o(!1);c.fs.stat(t,function(u,x){if(l&&x.isDirectory())return o(!1);var p=Pe.dirname(t);c.fs.exists(p,function(w){w||c.makeDir(p),c.fs.open(t,"w",438,function(_,I){_?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)})})})})}):I?c.fs.write(I,e,0,e.length,0,function(){c.fs.close(I,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};be.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let l=[];return e.fs.readdirSync(i).forEach(function(u){let x=Pe.join(i,u),p=e.fs.statSync(x);(!o||o.test(x))&&l.push(Pe.normalize(x)+(p.isDirectory()?e.sep:"")),p.isDirectory()&&c&&(l=l.concat(r(x,o,c)))}),l}return r(t,void 0,!0)};be.prototype.findFilesAsync=function(t,e){let r=this,i=[];r.fs.readdir(t,function(o,c){if(o)return e(o);let l=c.length;if(!l)return e(null,i);c.forEach(function(u){u=Pe.join(t,u),r.fs.stat(u,function(x,p){if(x)return e(x);p&&(i.push(Pe.normalize(u)+(p.isDirectory()?r.sep:"")),p.isDirectory()?r.findFilesAsync(u,function(w,_){if(w)return e(w);i=i.concat(_),--l||e(null,i)}):--l||e(null,i))})})})};be.prototype.getAttributes=function(){};be.prototype.setAttributes=function(){};be.crc32update=function(t,e){return Il[(t^e)&255]^t>>>8};be.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,r=-1;for(let i=0;i<e;)r=be.crc32update(r,t[i++]);return~r>>>0};be.methodToString=function(t){switch(t){case Sl.STORED:return"STORED ("+t+")";case Sl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};be.canonical=function(t){if(!t)return"";let e=Pe.posix.normalize("/"+t.split("\\").join("/"));return Pe.join(".",e)};be.zipnamefix=function(t){if(!t)return"";let e=Pe.posix.normalize("/"+t.split("\\").join("/"));return Pe.posix.join(".",e)};be.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let r=t.length>>>0;for(let i=r-1;i>=0;i--)if(e(t[i],i,t))return t[i]};be.sanitize=function(t,e){t=Pe.resolve(Pe.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Pe.normalize(Pe.join(t,r.slice(i,o).join(Pe.sep)));if(c.indexOf(t)===0)return c}return Pe.normalize(Pe.join(t,Pe.basename(e)))};be.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};be.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};be.fromDOS2Date=function(t){return new Date((t>>25&127)+1980,Math.max((t>>21&15)-1,0),Math.max(t>>16&31,1),t>>11&31,t>>5&63,(t&31)<<1)};be.fromDate2DOS=function(t){let e=0,r=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),r=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|r};be.isWin=yg;be.crcTable=Il});var Rl=se((F1,Dl)=>{var Eg=de("path");Dl.exports=function(t,{fs:e}){var r=t||"",i=c(),o=null;function c(){return{directory:!1,readonly:!1,hidden:!1,executable:!1,mtime:0,atime:0}}return r&&e.existsSync(r)?(o=e.statSync(r),i.directory=o.isDirectory(),i.mtime=o.mtime,i.atime=o.atime,i.executable=(73&o.mode)!==0,i.readonly=(128&o.mode)===0,i.hidden=Eg.basename(r)[0]==="."):console.warn("Invalid path: "+r),{get directory(){return i.directory},get readOnly(){return i.readonly},get hidden(){return i.hidden},get mtime(){return i.mtime},get atime(){return i.atime},get executable(){return i.executable},decodeAttributes:function(){},encodeAttributes:function(){},toJSON:function(){return{path:r,isDirectory:i.directory,isReadOnly:i.readonly,isHidden:i.hidden,isExecutable:i.executable,mTime:i.mtime,aTime:i.atime}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Ol=se((U1,kl)=>{kl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var sr=se((G1,ir)=>{ir.exports=Cl();ir.exports.Constants=va();ir.exports.Errors=ds();ir.exports.FileAttr=Rl();ir.exports.decoder=Ol()});var Ll=se((q1,Pl)=>{var sn=sr(),U=sn.Constants;Pl.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,l=0,u=0,x=0,p=0,w=0,_=0,I=0,E=0,v=0;t|=sn.isWin?2560:768,r|=U.FLG_EFS;let A={extraLen:0},S=y=>Math.max(0,y)>>>0,C=y=>Math.max(0,y)&65535,P=y=>Math.max(0,y)&255;return o=sn.fromDate2DOS(new Date),{get made(){return t},set made(y){t=y},get version(){return e},set version(y){e=y},get flags(){return r},set flags(y){r=y},get flags_efs(){return(r&U.FLG_EFS)>0},set flags_efs(y){y?r|=U.FLG_EFS:r&=~U.FLG_EFS},get flags_desc(){return(r&U.FLG_DESC)>0},set flags_desc(y){y?r|=U.FLG_DESC:r&=~U.FLG_DESC},get method(){return i},set method(y){switch(y){case U.STORED:this.version=10;case U.DEFLATED:default:this.version=20}i=y},get time(){return sn.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=sn.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=S(y)},get timeHighByte(){return P(o>>>8)},get crc(){return c},set crc(y){c=S(y)},get compressedSize(){return l},set compressedSize(y){l=S(y)},get size(){return u},set size(y){u=S(y)},get fileNameLength(){return x},set fileNameLength(y){x=y},get extraLength(){return p},set extraLength(y){p=y},get extraLocalLength(){return A.extraLen},set extraLocalLength(y){A.extraLen=y},get commentLength(){return w},set commentLength(y){w=y},get diskNumStart(){return _},set diskNumStart(y){_=S(y)},get inAttr(){return I},set inAttr(y){I=S(y)},get attr(){return E},set attr(y){E=S(y)},get fileAttr(){return(E||0)>>16&4095},get offset(){return v},set offset(y){v=S(y)},get encrypted(){return(r&U.FLG_ENC)===U.FLG_ENC},get centralHeaderSize(){return U.CENHDR+x+p+w},get realDataOffset(){return v+U.LOCHDR+A.fnameLen+A.extraLen},get localHeader(){return A},loadLocalHeaderFromBinary:function(y){var D=y.slice(v,v+U.LOCHDR);if(D.readUInt32LE(0)!==U.LOCSIG)throw sn.Errors.INVALID_LOC();A.version=D.readUInt16LE(U.LOCVER),A.flags=D.readUInt16LE(U.LOCFLG),A.flags_desc=(A.flags&U.FLG_DESC)>0,A.method=D.readUInt16LE(U.LOCHOW),A.time=D.readUInt32LE(U.LOCTIM),A.crc=D.readUInt32LE(U.LOCCRC),A.compressedSize=D.readUInt32LE(U.LOCSIZ),A.size=D.readUInt32LE(U.LOCLEN),A.fnameLen=D.readUInt16LE(U.LOCNAM),A.extraLen=D.readUInt16LE(U.LOCEXT);let k=v+U.LOCHDR+A.fnameLen,M=k+A.extraLen;return y.slice(k,M)},loadFromBinary:function(y){if(y.length!==U.CENHDR||y.readUInt32LE(0)!==U.CENSIG)throw sn.Errors.INVALID_CEN();t=y.readUInt16LE(U.CENVEM),e=y.readUInt16LE(U.CENVER),r=y.readUInt16LE(U.CENFLG),i=y.readUInt16LE(U.CENHOW),o=y.readUInt32LE(U.CENTIM),c=y.readUInt32LE(U.CENCRC),l=y.readUInt32LE(U.CENSIZ),u=y.readUInt32LE(U.CENLEN),x=y.readUInt16LE(U.CENNAM),p=y.readUInt16LE(U.CENEXT),w=y.readUInt16LE(U.CENCOM),_=y.readUInt16LE(U.CENDSK),I=y.readUInt16LE(U.CENATT),E=y.readUInt32LE(U.CENATX),v=y.readUInt32LE(U.CENOFF)},localHeaderToBinary:function(){var y=Buffer.alloc(U.LOCHDR);return y.writeUInt32LE(U.LOCSIG,0),y.writeUInt16LE(e,U.LOCVER),y.writeUInt16LE(r,U.LOCFLG),y.writeUInt16LE(i,U.LOCHOW),y.writeUInt32LE(o,U.LOCTIM),y.writeUInt32LE(c,U.LOCCRC),y.writeUInt32LE(l,U.LOCSIZ),y.writeUInt32LE(u,U.LOCLEN),y.writeUInt16LE(x,U.LOCNAM),y.writeUInt16LE(A.extraLen,U.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(U.CENHDR+x+p+w);return y.writeUInt32LE(U.CENSIG,0),y.writeUInt16LE(t,U.CENVEM),y.writeUInt16LE(e,U.CENVER),y.writeUInt16LE(r,U.CENFLG),y.writeUInt16LE(i,U.CENHOW),y.writeUInt32LE(o,U.CENTIM),y.writeUInt32LE(c,U.CENCRC),y.writeUInt32LE(l,U.CENSIZ),y.writeUInt32LE(u,U.CENLEN),y.writeUInt16LE(x,U.CENNAM),y.writeUInt16LE(p,U.CENEXT),y.writeUInt16LE(w,U.CENCOM),y.writeUInt16LE(_,U.CENDSK),y.writeUInt16LE(I,U.CENATT),y.writeUInt32LE(E,U.CENATX),y.writeUInt32LE(v,U.CENOFF),y},toJSON:function(){let y=function(D){return D+" bytes"};return{made:t,version:e,flags:r,method:sn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(l),size:y(u),fileNameLength:y(x),extraLength:y(p),commentLength:y(w),diskNumStart:_,inAttr:I,attr:E,offset:v,centralHeaderSize:y(U.CENHDR+x+p+w)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Ml=se((H1,Nl)=>{var or=sr(),we=or.Constants;Nl.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 or.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=or.readBigUInt64LE(c,we.ZIP64SUB),e=or.readBigUInt64LE(c,we.ZIP64TOT),r=or.readBigUInt64LE(c,we.ZIP64SIZE),i=or.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 x=l.toString(16).toUpperCase();for(;x.length<u;)x="0"+x;return"0x"+x};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Aa=se(Sa=>{Sa.EntryHeader=Ll();Sa.MainHeader=Ml()});var zl=se((W1,Bl)=>{Bl.exports=function(t){var e=de("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],l=0;o.on("data",function(u){c.push(u),l+=u.length}),o.on("end",function(){var u=Buffer.alloc(l),x=0;u.fill(0);for(var p=0;p<c.length;p++){var w=c[p];w.copy(u,x),x+=w.length}i&&i(u)}),o.end(t)}}}});var Ul=se((K1,Fl)=>{var bg=+(process.versions?process.versions.node:"").split(".")[0]||0;Fl.exports=function(t,e){var r=de("zlib");let i=bg>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),l=[],u=0;c.on("data",function(x){l.push(x),u+=x.length}),c.on("end",function(){var x=Buffer.alloc(u),p=0;x.fill(0);for(var w=0;w<l.length;w++){var _=l[w];_.copy(x,p),p+=_.length}o&&o(x)}),c.end(t)}}}});var Wl=se(($1,jl)=>{"use strict";var{randomFillSync:Gl}=de("crypto"),vg=ds(),Sg=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=e>>>1^3988292384:e>>>=1;return e>>>0}),Hl=(t,e)=>Math.imul(t,e)>>>0,ql=(t,e)=>Sg[(t^e)&255]^t>>>8,Xr=()=>typeof Gl=="function"?Gl(Buffer.alloc(12)):Xr.node();Xr.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:Xr};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]=ql(e[0],t),e[1]+=e[0]&255,e[1]=Hl(e[1],134775813)+1,e[2]=ql(e[2],e[1]>>>24),t};us.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Hl(t,t^1)>>8&255};function Ag(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 Ig(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 Tg(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Ag(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw vg.WRONG_PASSWORD();return i(t.slice(12))}function Cg(t){Buffer.isBuffer(t)&&t.length>=12?ls.genSalt=function(){return t.slice(0,12)}:t==="node"?ls.genSalt=Xr.node:ls.genSalt=Xr}function Dg(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Ig(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)}jl.exports={decrypt:Tg,encrypt:Dg,_salter:Cg}});var Kl=se(fs=>{fs.Deflater=zl();fs.Inflater=Ul();fs.ZipCrypto=Wl()});var Ta=se((J1,$l)=>{var oe=sr(),Rg=Aa(),ve=oe.Constants,Ia=Kl();$l.exports=function(t,e){var r=new Rg.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,l=null,u=Buffer.alloc(0),x=Buffer.alloc(0),p=!0;let w=t,_=typeof w.decoder=="object"?w.decoder:oe.decoder;p=_.hasOwnProperty("efs")?_.efs:!1;function I(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(x=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function E(y){if(!r.flags_desc&&!r.localHeader.flags_desc){if(oe.crc32(y)!==r.localHeader.crc)return!1}else{let D={},k=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(k)==ve.LOCSIG||e.readUInt32LE(k)==ve.CENSIG)throw oe.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(k)==ve.EXTSIG)D.crc=e.readUInt32LE(k+ve.EXTCRC),D.compressedSize=e.readUInt32LE(k+ve.EXTSIZ),D.size=e.readUInt32LE(k+ve.EXTLEN);else if(e.readUInt16LE(k+12)===19280)D.crc=e.readUInt32LE(k+ve.EXTCRC-4),D.compressedSize=e.readUInt32LE(k+ve.EXTSIZ-4),D.size=e.readUInt32LE(k+ve.EXTLEN-4);else throw oe.Errors.DESCRIPTOR_UNKNOWN();if(D.compressedSize!==r.compressedSize||D.size!==r.size||D.crc!==r.crc)throw oe.Errors.DESCRIPTOR_FAULTY();if(oe.crc32(y)!==D.crc)return!1}return!0}function 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 M=I();if(M.length===0)return y&&D&&D(M),M;if(r.encrypted){if(typeof k!="string"&&!Buffer.isBuffer(k))throw oe.Errors.INVALID_PASS_PARAM();M=Ia.ZipCrypto.decrypt(M,r,k)}var B=Buffer.alloc(r.size);switch(r.method){case oe.Constants.STORED:if(M.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 $=new Ia.Inflater(M,r.size);if(y)$.inflateAsync(function(V){V.copy(V,0),D&&(E(V)?D(V):D(V,oe.Errors.BAD_CRC()))});else{if($.inflate(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(I()),I();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 M=new Ia.Deflater(l);if(y)M.deflateAsync(function($){k=Buffer.alloc($.length),r.compressedSize=$.length,$.copy(k),D&&D(k)});else{var B=M.deflate();return r.compressedSize=B.length,B}M=null;break}}else if(y&&D)D(Buffer.alloc(0));else return Buffer.alloc(0)}function S(y,D){return oe.readBigUInt64LE(y,D)}function C(y){try{for(var D=0,k,M,B;D+4<y.length;)k=y.readUInt16LE(D),D+=2,M=y.readUInt16LE(D),D+=2,B=y.slice(D,D+M),D+=M,ve.ID_ZIP64===k&&P(B)}catch{throw oe.Errors.EXTRA_FIELD_PARSE_ERROR()}}function P(y){var D,k,M,B;y.length>=ve.EF_ZIP64_SCOMP&&(D=S(y,ve.EF_ZIP64_SUNCOMP),r.size===ve.EF_ZIP64_OR_32&&(r.size=D)),y.length>=ve.EF_ZIP64_RHO&&(k=S(y,ve.EF_ZIP64_SCOMP),r.compressedSize===ve.EF_ZIP64_OR_32&&(r.compressedSize=k)),y.length>=ve.EF_ZIP64_DSN&&(M=S(y,ve.EF_ZIP64_RHO),r.offset===ve.EF_ZIP64_OR_32&&(r.offset=M)),y.length>=ve.EF_ZIP64_DSN+4&&(B=y.readUInt32LE(ve.EF_ZIP64_DSN),r.diskNumStart===ve.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 p=="function"?p(this.entryName):p},get extra(){return u},set extra(y){u=y,r.extraLength=y.length,C(y)},get comment(){return _.decode(o)},set comment(y){if(o=oe.toBuffer(y,_.encode),r.commentLength=o.length,o.length>65535)throw oe.Errors.COMMENT_TOO_LONG()},get name(){var y=_.decode(i);return c?y.substr(y.length-1).split("/").pop():y.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return A(!1,null)},getCompressedDataAsync:function(y){A(!0,y)},setData:function(y){l=oe.toBuffer(y,oe.decoder.encode),!c&&l.length?(r.size=l.length,r.method=oe.Constants.DEFLATED,r.crc=oe.crc32(y),r.changed=!0):r.method=oe.Constants.STORED},getData:function(y){return r.changed?l: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=x.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,x.copy(k,y),y+=x.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 Zl=se((Z1,Jl)=>{var Vl=Ta(),kg=Aa(),je=sr();Jl.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new kg.MainHeader,l=!1,u=null;let x=new Set,p=e,{noSort:w,decoder:_}=p;t?v(p.readEntries):l=!0;function I(){let S=new Set;for(let C of Object.keys(i)){let P=C.split("/");if(P.pop(),!!P.length)for(let y=0;y<P.length;y++){let D=P.slice(0,y+1).join("/")+"/";S.add(D)}}for(let C of S)if(!(C in i)){let P=new Vl(p);P.entryName=C,P.attr=16,P.temporary=!0,r.push(P),i[P.entryName]=P,x.add(P)}}function E(){if(l=!0,i={},c.diskEntries>(t.length-c.offset)/je.Constants.CENHDR)throw je.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var S=c.offset,C=0;C<r.length;C++){var P=S,y=new Vl(p,t);y.header=t.slice(P,P+=je.Constants.CENHDR),y.entryName=t.slice(P,P+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(P,P+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(P,P+y.header.commentLength)),S+=y.header.centralHeaderSize,r[C]=y,i[y.entryName]=y}x.clear(),I()}function v(S){var C=t.length-je.Constants.ENDHDR,P=Math.max(0,C-65535),y=P,D=t.length,k=-1,M=0;for(typeof p.trailingSpace=="boolean"&&p.trailingSpace&&(P=0),C;C>=y;C--)if(t[C]===80){if(t.readUInt32LE(C)===je.Constants.ENDSIG){k=C,M=C,D=C+je.Constants.ENDHDR,y=C-je.Constants.END64HDR;continue}if(t.readUInt32LE(C)===je.Constants.END64SIG){y=P;continue}if(t.readUInt32LE(C)===je.Constants.ZIP64SIG){k=C,D=C+je.readBigUInt64LE(t,C+je.Constants.ZIP64SIZE)+je.Constants.ZIP64LEAD;break}}if(k==-1)throw je.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(k,D)),c.commentLength&&(o=t.slice(M+je.Constants.ENDHDR)),S&&E()}function A(){r.length>1&&!w&&r.sort((S,C)=>S.entryName.toLowerCase().localeCompare(C.entryName.toLowerCase()))}return{get entries(){return l||E(),r.filter(S=>!x.has(S))},get comment(){return _.decode(o)},set comment(S){o=je.toBuffer(S,_.encode),c.commentLength=o.length},getEntryCount:function(){return l?r.length:c.diskEntries},forEach:function(S){this.entries.forEach(S)},getEntry:function(S){return l||E(),i[S]||null},setEntry:function(S){l||E(),r.push(S),i[S.entryName]=S,c.totalEntries=r.length},deleteFile:function(S,C=!0){l||E();let P=i[S];this.getEntryChildren(P,C).map(D=>D.entryName).forEach(this.deleteEntry)},deleteEntry:function(S){l||E();let C=i[S],P=r.indexOf(C);P>=0&&(r.splice(P,1),delete i[S],c.totalEntries=r.length)},getEntryChildren:function(S,C=!0){if(l||E(),typeof S=="object")if(S.isDirectory&&C){let P=[],y=S.entryName;for(let D of r)D.entryName.startsWith(y)&&P.push(D);return P}else return[S];return[]},getChildCount:function(S){if(S&&S.isDirectory){let C=this.getEntryChildren(S);return C.includes(S)?C.length-1:C.length}return 0},compressToBuffer:function(){l||E(),A();let S=[],C=[],P=0,y=0;c.size=0,c.offset=0;let D=0;for(let B of this.entries){let $=B.getCompressedData();B.header.offset=y;let V=B.packLocalHeader(),te=V.length+$.length;y+=te,S.push(V),S.push($);let Q=B.packCentralHeader();C.push(Q),c.size+=Q.length,P+=te+Q.length,D++}P+=c.mainHeaderSize,c.offset=y,c.totalEntries=D,y=0;let k=Buffer.alloc(P);for(let B of S)B.copy(k,y),y+=B.length;for(let B of C)B.copy(k,y),y+=B.length;let M=c.toBinary();return o&&o.copy(M,je.Constants.ENDHDR),M.copy(k,y),t=k,l=!1,k},toAsyncBuffer:function(S,C,P,y){try{l||E(),A();let D=[],k=[],M=0,B=0,$=0;c.size=0,c.offset=0;let V=function(te){if(te.length>0){let Q=te.shift(),Ee=Q.entryName+Q.extra.toString();P&&P(Ee),Q.getCompressedDataAsync(function(he){y&&y(Ee),Q.header.offset=B;let O=Q.packLocalHeader(),q=O.length+he.length;B+=q,D.push(O),D.push(he);let j=Q.packCentralHeader();k.push(j),c.size+=j.length,M+=q+j.length,$++,V(te)})}else{M+=c.mainHeaderSize,c.offset=B,c.totalEntries=$,B=0;let Q=Buffer.alloc(M);D.forEach(function(he){he.copy(Q,B),B+=he.length}),k.forEach(function(he){he.copy(Q,B),B+=he.length});let Ee=c.toBinary();o&&o.copy(Ee,je.Constants.ENDHDR),Ee.copy(Q,B),t=Q,l=!1,S(Q)}};V(Array.from(this.entries))}catch(D){C(D)}}}}});var Ql=se((Y1,Xl)=>{var ye=sr(),_e=de("path"),Og=Ta(),Pg=Zl(),Tn=(...t)=>ye.findLast(t,e=>typeof e=="boolean"),Yl=(...t)=>ye.findLast(t,e=>typeof e=="string"),Lg=(...t)=>ye.findLast(t,e=>typeof e=="function"),Ng={noSort:!1,readEntries:!1,method:ye.Constants.NONE,fs:null};Xl.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),Ng);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 Pg(r,i),{canonical:l,sanitize:u,zipnamefix:x}=ye;function p(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:S}=_e.posix;return v(_e.isAbsolute(E)?"/":".",A(S+E.split("\\").join(S)+S))}function _(E){return E instanceof RegExp?(function(v){return function(A){return v.test(A)}})(E):typeof E!="function"?()=>!0:E}let I=(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=p(E);return A&&A.getData(v)||null},childCount:function(E){let v=p(E);if(v)return c.getChildCount(v)},readFileAsync:function(E,v){var A=p(E);A?A.getDataAsync(v):v(null,"getEntry failed for:"+E)},readAsText:function(E,v){var A=p(E);if(A){var S=A.getData();if(S&&S.length)return S.toString(v||"utf8")}return""},readAsTextAsync:function(E,v,A){var S=p(E);S?S.getDataAsync(function(C,P){if(P){v(C,P);return}C&&C.length?v(C.toString(A||"utf8")):v("")}):v("")},deleteFile:function(E,v=!0){var A=p(E);A&&c.deleteFile(A.entryName,v)},deleteEntry:function(E){var v=p(E);v&&c.deleteEntry(v.entryName)},addZipComment:function(E){c.comment=E},getZipComment:function(){return c.comment||""},addZipEntryComment:function(E,v){var A=p(E);A&&(A.comment=v)},getZipEntryComment:function(E){var v=p(E);return v&&v.comment||""},updateFile:function(E,v){var A=p(E);A&&A.setData(v)},addLocalFile:function(E,v,A,S){if(o.fs.existsSync(E)){v=v?w(v):"";let C=_e.win32.basename(_e.win32.normalize(E));v+=A||C;let P=o.fs.statSync(E),y=P.isFile()?o.fs.readFileSync(E):Buffer.alloc(0);P.isDirectory()&&(v+=o.sep),this.addFile(v,y,S,P)}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:S}=E,{zipPath:C,zipName:P}=E,y=this;o.fs.stat(A,function(D,k){if(D)return v(D,!1);C=C?w(C):"";let M=_e.win32.basename(_e.win32.normalize(A));if(C+=P||M,k.isFile())o.fs.readFile(A,function(B,$){return B?v(B,!1):(y.addFile(C,$,S,k),setImmediate(v,void 0,!0))});else if(k.isDirectory())return C+=o.sep,y.addFile(C,Buffer.alloc(0),S,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 S=o.findFiles(E),C=this;if(S.length)for(let P of S){let y=_e.join(v,I(E,P));A(y)&&C.addLocalFile(P,_e.dirname(y))}}else throw ye.Errors.FILE_NOT_FOUND(E)},addLocalFolderAsync:function(E,v,A,S){S=_(S),A=A?w(A):"",E=_e.normalize(E);var C=this;o.fs.open(E,"r",function(P){if(P&&P.code==="ENOENT")v(void 0,ye.Errors.FILE_NOT_FOUND(E));else if(P)v(void 0,P);else{var y=o.findFiles(E),D=-1,k=function(){if(D+=1,D<y.length){var M=y[D],B=I(E,M).split("\\").join("/");B=B.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),S(B)?o.fs.stat(M,function($,V){$&&v(void 0,$),V.isFile()?o.fs.readFile(M,function(te,Q){te?v(void 0,te):(C.addFile(A+B,Q,"",V),k())}):(C.addFile(A+B+"/",Buffer.alloc(0),"",V),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:S,filter:C,namefix:P}=E;C instanceof RegExp?C=(function(k){return function(M){return k.test(M)}})(C):typeof C!="function"&&(C=function(){return!0}),S=S?w(S):"",P=="latin1"&&(P=k=>k.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof P!="function"&&(P=k=>k);let y=k=>_e.join(S,P(I(localPath,k))),D=k=>_e.win32.basename(_e.win32.normalize(P(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(M,B){if(M)return v(M);B=B.filter($=>C(y($))),B.length||v(void 0,!1),setImmediate(B.reverse().reduce(function($,V){return function(te,Q){if(te||Q===!1)return setImmediate($,te,!1);A.addLocalFileAsync({localPath:V,zipPath:_e.dirname(y(V)),zipName:D(V)},$)}},v))})})},addLocalFolderPromise:function(E,v){return new Promise((A,S)=>{this.addLocalFolderAsync2(Object.assign({localPath:E},v),(C,P)=>{C&&S(C),P&&A(this)})})},addFile:function(E,v,A,S){E=x(E);let C=p(E),P=C!=null;P||(C=new Og(i),C.entryName=E),C.comment=A||"";let y=typeof S=="object"&&S instanceof o.fs.Stats;y&&(C.header.time=S.mtime);var D=C.isDirectory?16:0;let k=C.isDirectory?16384:32768;return y?k|=4095&S.mode:typeof S=="number"?k|=4095&S:k|=C.isDirectory?493:420,D=(D|k<<16)>>>0,C.attr=D,C.setData(v),P||c.setEntry(C),C},getEntries:function(E){return c.password=E,c?c.entries:[]},getEntry:function(E){return p(E)},getEntryCount:function(){return c.getEntryCount()},forEach:function(E){return c.forEach(E)},extractEntryTo:function(E,v,A,S,C,P){S=Tn(!1,S),C=Tn(!1,C),A=Tn(!0,A),P=Yl(C,P);var y=p(E);if(!y)throw ye.Errors.NO_ENTRY();var D=l(y.entryName),k=u(v,P&&!y.isDirectory?P:A?D:_e.basename(D));if(y.isDirectory){var M=c.getEntryChildren(y);return M.forEach(function(V){if(V.isDirectory)return;var te=V.getData();if(!te)throw ye.Errors.CANT_EXTRACT_FILE();var Q=l(V.entryName),Ee=u(v,A?Q:_e.basename(Q));let he=C?V.header.fileAttr:void 0;o.writeFileTo(Ee,te,S,he)}),!0}var B=y.getData(c.password);if(!B)throw ye.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(k)&&!S)throw ye.Errors.CANT_OVERRIDE();let $=C?E.header.fileAttr:void 0;return o.writeFileTo(k,B,S,$),!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,S){if(A=Tn(!1,A),S=Yl(A,S),v=Tn(!1,v),!c)throw ye.Errors.NO_ZIP();c.entries.forEach(function(C){var P=u(E,l(C.entryName));if(C.isDirectory){o.makeDir(P);return}var y=C.getData(S);if(!y)throw ye.Errors.CANT_EXTRACT_FILE();let D=A?C.header.fileAttr:void 0;o.writeFileTo(P,y,v,D);try{o.fs.utimesSync(P,C.header.time,C.header.time)}catch{throw ye.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(E,v,A,S){if(S=Lg(v,A,S),A=Tn(!1,A),v=Tn(!1,v),!S)return new Promise((k,M)=>{this.extractAllToAsync(E,v,A,function(B){B?M(B):k(this)})});if(!c){S(ye.Errors.NO_ZIP());return}E=_e.resolve(E);let C=k=>u(E,_e.normalize(l(k.entryName))),P=(k,M)=>new Error(k+': "'+M+'"'),y=[],D=[];c.entries.forEach(k=>{k.isDirectory?y.push(k):D.push(k)});for(let k of y){let M=C(k),B=A?k.header.fileAttr:void 0;try{o.makeDir(M),B&&o.fs.chmodSync(M,B),o.fs.utimesSync(M,k.header.time,k.header.time)}catch{S(P("Unable to create folder",M))}}D.reverse().reduce(function(k,M){return function(B){if(B)k(B);else{let $=_e.normalize(l(M.entryName)),V=u(E,$);M.getDataAsync(function(te,Q){if(Q)k(Q);else if(!te)k(ye.Errors.CANT_EXTRACT_FILE());else{let Ee=A?M.header.fileAttr:void 0;o.writeFileToAsync(V,te,v,Ee,function(he){he||k(P("Unable to write file",V)),o.fs.utimes(V,M.header.time,M.header.time,function(O){O?k(P("Unable to set times",V)):k()})})}})}}},S)()},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 S=o.writeFileTo(E,A,!0);typeof v=="function"&&v(S?null:new Error("failed"),"")}}},writeZipPromise:function(E,v){let{overwrite:A,perm:S}=Object.assign({overwrite:!0},v);return new Promise((C,P)=>{!E&&i.filename&&(E=i.filename),E||P("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let D=k=>k?C(k):P("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(E,y,A,S,D)},P)})},toBufferPromise:function(){return new Promise((E,v)=>{c.toAsyncBuffer(E,v)})},toBuffer:function(E,v,A,S){return typeof E=="function"?(c.toAsyncBuffer(E,v,A,S),null):c.compressToBuffer()}}}});import{execFile as A_,spawn as I_,spawnSync as lI}from"node:child_process";import{promisify as T_}from"node:util";function D_(t){if(process.platform!=="win32")return!1;if($u.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace($u,"").toLowerCase();return C_.has(r)}function Vu(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return D_(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function dt(t,e=[],r={}){return I_(t,e,Vu(t,r))}function Ju(t,e=[],r={}){return R_(t,e,Vu(t,r))}var C_,$u,R_,yn=Ze(()=>{"use strict";C_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),$u=/\.(cmd|bat|ps1)$/i;R_=T_(A_)});var jf=se(Me=>{"use strict";var N=z;function Eo(){let t=["Aw9UvgLTzw8","AxnbCNjHEq","x2LUAxrhBg8","z2vtEw5J","AgvHzgvYCW","yMfSrxzLBNq","sMfeDe8","zcbLCNjVCI4","y1DzEMu","BgLTAxq","q0vnsLa","zuDnAu4","BfnvsuC","tLvKuvi","ruDdsKO","ExbkreG","EwXJsNa","tMfzu2u","B25tDg9Wsw0","q1vqv2C","DhjPBq","C2rOD08","ihrPBwvVDxq","zxjFDhrS","uNHAB1G","u1LMC3C","EefKD0q","icSG","x3nLBMrby2S","q1DoyKm","zw5NDgG","Dw5ZAwDUzwq","DNbuCe4","tvPnEMS","r21QBfi","zw5JB2rPBMC","vvnSz24","y2f0y2G","BfH0z2W","v1HjzuK","rLDt","ywrKq291BNq","zNjVBu51Bwi","x2HHBMrSzva","wwneqLu","wLDuD1i","x29WDgLVBNm","BMrLEa","DM9Hrvy","BefVANK","B3bLBIa","C05IyxK","Cfjkz2u","z0jcy3m","BwfUDwfSihi","BfnoB2i","y3jLyxrLrxi","yxbWBhK","tePqzKi","BMfTzq","q2PeChK","sg1Uqxu","C0fgv1m","AKXRzNm","vevZCLO","vw9QBxe","CwPKDeK","zMLUza","z2vY","u2HPtvG","wgjhsgO","DM5Wzum","EMTiCu8","y3jLyxrLuMu","vLH3zva","yu9uA0e","sxD3qMS","sLfstKm","tuvOExC","C213thq","AKH6B3K","x2nYzwf0zvm","zw50tgLZDgu","C3rVCMu","CwzNwe0","tKDFrvjst1i","y29UBMvJDa","tfzLAgy","yMrFzgLK","vhnvA1m","zvf6u2y","DLvOq2y","AenSB3nLrxy","x2LUAxq","A29bsuC","zMzmAw5L","vgPiywO","D1HmqLC","uxLnrxa","ChbdBfa","yxv0B21HDgK","zxjFAxnFywm","y215vLy","tg9JAW","u1zStha","swH5qMS","AML2wxm","rKLmrv9ot1q","vM16wve","mhWX","zw5KCg9PBNq","zLj1sMu","rwXcAwG","y29UC3rYDwm","zevVCuW","DhjksgO","CM9Ywe4","BNbnt0W","x2TLEvbHDgG","AxfhquG","Avzrz3O","BwvZC2fNzq","DuDiseG","vw5PBxbSzw0","EgvSyue","uNP6zvm","rhnYAK8","Cwz4y1m","EePkre4","CfLSwhC","D2rTD3i","Bg93","sLnptLa","x2LZtwLUAvq","sw5PseG","x2LZsw5PDa","yLvkywO","rNvNu0O","Bu9UrfO","uhziBxm","werMC1C","EfvZzuvUDG","BvnpqLC","tK53yNq","sujWq28","Cg93","CMvTB3zLrxy","Dhr3Awq","yMHuqvG","BMzZr1q","q29WqKO","A1n0yxr1C0m","rNnSCgO","DMXIuw8","Aw1LCYbPBIa","BezyEeu","vvryAKS","swvPquy","CgfYC2u","CK1PC2e","B2X0AgC","BMCGB3iGyw4","DgLUzYbZzxi","BMvLzf9Hy2S","rxvpEwq","mJKZnJa2u2Pcthfe","EvDQvNC","zwHpwha","zgf0yq","AfPvv0y","y2HLy2TdDxi","zMfbwLu","y3vYCMvUDeu","ChjVy2vZCW","Aw9Ul2PZB24","y0jkDui","yNvMzMvYzwq","DMvYC2LVBMm","zNjHBwvuExa","C2vYDMvYvgK","AxPwBvO","z1LSAM4","v2LUzg93","tw9KDwXL","ExbL","Aw50zwDLCIa","rgvdzwK","x2nSzwfYugK","vgnjCge","uhDLsvu","whjAte4","zxjFCw9Zx2e","ywTLvxO","BMnVzgLUzW","yM9KEq","tM5OAum","BxLivhi","qwT4r1i","yxrHlcbKyxq","nhW1Fdn8mxW","A2Hjz2q","twvZC2fNzuu","tKHhvM8","DgfYz2v0","z3jdD1y","Bfn4Age","vuLgt3e","z1DxEuy","C2TAs2e","CNzHBfzHBhu","rfPZA0C","s25qEeW","x3nLCuLK","AvzxzMC","CYbWyxjHBxm","reiGzMfPBgu","q1vuDfa","tu9QsuW","Aw5Lza","BgvUz3rO","q09otKvdveK","wxzXtgC","BMveqwO","CgfNzxnOB3C","tK5TEMm","BwvZC2fNztO","q291BNq","u2DSExu","rvjsAMq","x2LZqNjVD3m","Be1bExK","x0vysvnu","B3bLBKrc","C1fuqNu","CKPKq00","rNjVBNrPzxi","q0DywgO","CgLNveW","yMfJA3vWigu","qwvtqvK","x3nVy2TLDa","ugTHDgy","zeLNALe","Ec1TC2CTCw8","AvfouLO","zgvJB2rLzey","EeziC04","zM5RDey","tgforLG","mvn4whfuCW","rvrNBxK","sefICLK","A0PbBei","t2X5uhG","sLPruNm","zgvSzxrLrge","D1HfrMm","t0zrDwC","x2jPBMfYEvq","rKPewwG","qLvsyKe","vvj3uvm","ruLACLa","CMvUDevUzha","Axnby2TdBgu","CgLUz0LUDgu","sNnZB0m","Bwf4twvZC2e","o2nOyxjZzxq","A0notfq","CgrWDuW","swPHr0y","D3m6lY8","D1z6Agq","EhjeA3G","DhvTvMW","tgDxAeq","ALzxrKi","BNrfBMrWB2K","EhbiyKy","sxrzs0i","v210qu8","zgvS","EKnrD04","rM1nzue","ywXnDvG","m3WXFdr8mhW","CKLMDvG","s0nkwKK","rgLmwfK","AgvNv0C","Buf1zKm","CMvKDwnL","ihrPBwvZ","BNP4zuK","EM1Tuxq","Bg9NsurozxC","DhjPzxmGCMu","C3rVCcbPBw0","yKLfyKu","yNLL","D0rJrwK","C3rLBMvYCW","t0nJANq","vuLeuuW","AgfUz2u","B25dBg9Zzq","Aw5KzxGGB3u","DuTXu3y","BMDLza","x3vYBa","q2XJDwy","BKvZvNm","tg9Nsuq","BMvY","t3jcyMi","DhfHtfu","Ae1LC3nHz2u","uvvlyxi","Efvmuvi","qvferKC","AfnkBfG","x2DLDeLUDgu","EMnRwva","t09qzuO","ihrYEsbYzwm","ExnUvfi","veXeyMq","EgvLq1u","mhW0","BgL2tui","uKr5BeG","wxDhrg4","CMvHC29U","r3D3DfO","se1TBLO","sMvxBK8","q29UzMLN","y29UBMvJDeu","s2vWufi","sKzqDuu","r3rPsvK","BgT4vfe","DLnACwq","EKrirue","BMDuAw1LCG","ue5kzKm","rxzOC2K","B1DezuC","tun5zvy","tePwweG","u0XOEfq","qKrRwMS","ywnRpwzYB24","rxPvy1C","zfDVCMTLCKC","u2TPCcbWyxm","y3vYDMfSDwu","y2HnyxHdB3u","n3W5Fdb8nxW","yMLUyxj5","EhzNAxm","z1rPBwvVDxq","q05jD0K","x2nVBM5Ly3q","zufJAW","wu1Zy0C","mNWZFdr8nxW","z2vdwKi","CNnVCKzPBgu","EsbJBg9Zzwq","x3bYzwzPEa","pxv0zI04","BNruCMLLC0m","CM92AwrLigi","DefWCwG","uKH3t2m","CYbHBhjLywq","nNWWFdj8m3W","A3Losvy","C0XPC3rLBMu","vw5Oyw5KBgu","uhfMwhe","tLLYt0O","BMDgrKy","BMv3vMvYC2K","CMvQzwn0","txn1tvK","vxbKyxrLq28","zfbMu1q","u2LJB0y","y3r4","v3rrB2K","Ahj5t08","r0zPC04","C3vJy2vZCW","BNrbBMrvCgq","uunuB2W","u0rwrhC","DuD6B1O","u25Wqui","Cgf5Bg9Hzeu","CufkEfy","x2HHBMrSzvi","B2zMBgLUzq","CMvWBgfJzq","yvforKW","qwjVCNrfCNi","yNL0zuXLBMC","zg9Uzq","D0zpq24","zxmGCMvHy2G","tu5Swvm","zcWGDw5RBM8","y09Wzw4","sK5js2u","EejfAe4","seznB3q","EfHODem","q3rWANO","ihrVihjLDhi","CMfTzq","y3LiALe","zw5JB2rLrNi","Bwf5v2i","sgjID2q","shbTsfu","DgLLCKPtt04","ChrVCG","z2v0qwXS","BwLUAvbYB2C","A2v0ignVBNm","Aw5KzxHpzG","x2LUDgvYDMe","uw5VAhu","quHLwwu","ig1LC3nHz2u","Ehznwfy","AwDHDg9Yt24","q3DNBuS","y3LtwxC","rg51Dve","u3HSBLO","y3vYC29Yx2y","ChHiwNq","m3W0Fdf8mNW","t1z6DNG","Dw9TAMm","mdaWma","Euzst3m","whDnzwO","t2jQzwn0","s0PuwMi","uxvLDwu","ywvxq2K","C29YDa","zgDKC2y","x2HHBMrSzu8","vgfN","uK5cBKG","r256zM8","C3bSAwnL","Dw5KzwzPBMu","x2DLBMvYyxq","r01xCfy","q0r1te0","t1bftG","q0Xpu0ve","x3bYB3rVy28","BhrPCgXLihq","zK1gwKu","Aw5JBhvKzxm","z2v0qwXSs2u","q0Pmz1a","DhbizwfKzxi","zxjYtxnN","CvrOvwi","ywnRtxnNswq","x2n1CNnVCK0","C2PczeC","DLbzuMO","rMDnDhq","rfLOsuW","B25fCNjVCG","BwzdDKO","x3bPBMC","y29UDgv4Da","ugzrsMq","r0XyExq","EgLQwKW","vM1Owgq","sLbYr0q","zejowu0","wu96AwO","su5tvefova","EvP2vKC","zKjJvfK","tujyvxm","CxLTzNK","x3fVC0rc","AxnAzxjV","tuvTALi","zgzcuKO","vvzrExK","u0jQAMW","zvfYu2K","t2XLBxi","wwDZueu","tLPny3m","AeLiu0C","AgLNAa","ugjAvhy","EgLgywO","vxvuC2q","q3jhC1C","AwXK","id4G","BMnLq2XVC2u","uwrXvee","zxjYtM8","tKv3CgK","rxHPEMS","CMvZzxruCMK","AvL1qxO","suvtx0vsuK8","ywzL","ANfyAhO","y2XVC2veqG","DxrVuMvJB24","uujJDuu","wgDgD0K","Dgv4Dc9WBge","vfHtwLC","C0jf","uwTorMi","AfPpwNK","ndu3mJmZC0j6D1nO","BLzZEge","y3ruAw1LB3u","C3rYAw5NAwy","y2XVC2u","zw5HyMXLuw8","CMv0CNLdB3u","v1fUC2y","x2LZtwLUAvC","AxnmB25N","x3DZsw5ZDge","zNLfwKC","B3jRig9MzMW","C290sMC","s2Dru2e","wM5XvLu","DgTdvgy","zxj2AwnL","CgDzB0y","v0Tluvm","BwLUzW","uhzXwKy","x3bPBMDmB3m","aaaaaaaaaaa","Chv0","z2v0t3DUuhi","EMjes0e","C29Tzq","z0PIuMW","Ae9Wzw5fDMu","Bhm6ia","zMjYvwq","BMf5vK4","ign1CNnVCIa","vfzeC1u","A29Tvhy","z3Pds1q","s2jYCee","C2XPy2u","B2zMC2v0","yM1jsw0","zw5HyMXLqxu","DwrnBgG","y3rtuhy","Dfzzq28","y3vTzhK","CgvYC2LZDgu","BML0AwfSAxO","Cg9W","x21PBMLoyxy","Dg9VigXHCMC","r0r3r3K","tuvtu0fhrv8","CMvZzxrfBMq","ywvgwxu","zw1PDa","CMvJB25Uzwm","DvfVs0u","tKvVEgC","yLHYzwy","AePPv2u","wergwxm","ChjVDg9JB2W","BxnNsuq","txvwzM4","tu9SCvm","zwjMt1O","C2HPzNq","zxjYB3i","CgLUz0XVC3m","CM92AwrLihC","DffosvC","r3fmzeO","q1fewvq","txvqA3y","vgLTzw91Da","CgfNzwHPzgu","AwXSihvZzsa","r2Tcwxe","q2XxD2m","wezTsLG","q25YqMS","uunns1i","rMrxteG","z2zxzuq","BffgqLC","BhLIrvi","ANvhv3G","wwj0y1m","qKrizfq","uxzfu1C","x2rPC2nVBM4","yMfSu2nVCgu","BgLUzw5V","DxjS","BMvJDa","B25mAw5L","zMLSDgvY","x2LUAxrqCM8","C2fHwLO","t2nbuMG","yujND2q","AuLquLe","zMXVB3i","yxnZAwDU","z0zOALa","Dev2zw50","CgjICdi","x2zVCM1HDeu","Efrurw52","y29UBMvJDgK","x29UvgLTzw8","q21Zt0m","rwfLEuS","mdaWmdaWmda","yMrHsKm","mtb1zwrkBfe","s1rlrMW","t1LeDey","q3jIuey","zgvSzxrL","zM9Yy2u","v2vPEgLUsLm","BNPUvfO","x3bPBMDqB24","DMv0z2G","BMCGDxjSoIa","x2rItMfTzq","CMLLC0nVDw4","AgvHzgvY","zxrxB3jRq2G","zwP0whK","B2nRzxrgywK","z09HELK","EePuEgC","x2nSzwfYvgK","vxjkEMu","D2vI","s2nAAKO","CM9YrxzLBNq","BNblCw0","tMXJwhm","AxjLza","ve5msNe","C3bSAxq","zcWG","vvHgrhu","Cw90vhG","u2jxuwy","yxbWBgLJyxq","Dxrjza","ELfHsw0","ywXSB2nvBNm","ruT3A1K","AevYCM9Yrxy","DMfSDwvZ","tLjQyMu","y3jLyxrLt3a","B25ozxr3B3i","CwfXq0q","D24GCMvHC28","B3vUDa","D2fZq2XLyw4","tLfHAKm","CM92AwrLihy","rKrLC3a","wvfbr28","y3jVze4","DNnqCK8","vfDishe","sKj6wKW","ugzSB0S","igXHCMDLCIa","igzPzwXKoIa","Bw1vwhK","Eu1QCxm","zw1LBNq","BgLsAei","CeXAtLu","ywDL","AeXPAuS","A3zgwKO","zMX1C2HfEha","zNDZxZeUmc4","ywXPzcb1CMW","vLDYAfy","lcbOB3n0BMe","vKXRu04","mNWX","qw5xuNO","ihn1y2nLC3m","ChjVDg90Exa","D0DNAxC","twzhyMu","Dg9tDhjPBMC","DeLUDgvYy2u","AgDcDxi","D3nZoI8V","v3b0qLy","Cvr3CwO","ELfTDhi","Cg9PBNrdB24","DxvQrei","CxDPufu","we1Rufu","zu9KCKW","EhjRq1q","zgv2AwnLx2K","rMv0ANa","x19LC01Vzhu","DgHLBG","Cg11t1G","yw1L","s2jny1y","yLzVuxm","B2nRzxrtDwm","q0Xpu0LorW","Dg9mB3DLCKm","DMvUDa","yMLUza","DwDcteK","r3PWswW","ywnRx2nVzgu","veXrDNe","EvLjEhC","BLntBhm","CYbPBNn0yw4","CMvZB2X2zq","yxv0BW","C3rHCNq","BKTfzw4","DgHHBIbSB2m","CvH6Cu4","A1fbAuu","u0nUtfG","wNDesNy","wu5ZDgK","yKnms0C","uND1B2e","y29UBMvJDfm","sMzIswm","zuf0suy","r2H2wK8","zNjVBuHHC2G","zw50","sNLdBgK","rLjptLrjrvi","wLrbq2C","CLPJuKW","y2XLyxjtDg8","ywXty29Wzq","zgzorxC","BgvY","y2rhvxG","B3jLtMfTzxm","wejmuhG","CgXLyxnLiha","uvfeAgC","C2DpC1G","zMLSzw5HBwu","vezOvuK","wM5rq1q","zgrjrcWGzgu","rvzysfK","zwnVBM5Ly3q","mhWZFdr8mNW","AgvKtwf4uMu","zw54wKG","BxzcDLq","t1zuyLi","C2vYDMLJzs0","BwLZzq","zM11y0O","t1L0wvK","q29Jufm","y0fItgi","B2jQzwn0u3q","DNrqBMy","A0XfrwW","wLrAtMy","ihjLy29UBMu","uxz6vNO","ChvNtMC","ENDUCfy","s2ngAu0","yxGGCMv0CMK","EufltM8","q3Dqrei","mxWWFdr8mNW","sunAwNi","Dg9iyxnO","ALHoq00","nZe1odi3vunjANbm","B1zTvMi","C2v0u3rVCMe","wKToCLa","D0jmB0G","B25LCNjVCG","AMzVy08","wNLTExu","ywX3yxLZ","wfLmqKS","t0TtC0i","qw1VDw50","Cunqu0q","q21Ouhq","DeLK","quTQswO","y2fSBa","z0fbqMC","EgrLA3G","BwfW","Cxb5t0W","BIWGAg9ZDg4","z2v0u3rVCMe","tgrUqve","tvbbyMS","x3jLywr5q2W","v2D2qKm","DKTAsK8","r25pEem","r1fhsNi","CIb0DhDjra","Duf6yum","veHJChm","CwnXs2K","zgvIDwC","BMv4DcGPigm","CMvJzxzPzwq","AMvJDfn0B3i","C3vIC3rYAw4","CMXTv3C","wxD0wey","Aw5KzxG","vLjVChy","rg1lqwe","x21LC3nHz2u","x2n1CNnVCK4","x29UrxjYB3i","uvnor1y","uMDtEeS","CMvHzg9UBhK","wgfJEum","u1bABNu","u0HUwhu","q09oveLovuu","DMnqvhm","t1jSuhy","wxruBgi","yuHsvu8","CMvZzxrdB3u","yKHQEwO","B25TzxnZywC","wKT3Cvu","vevstKi","l3DZl3yY","zv9ZDwnJzxm","BM5Ly3q","x29UugfNzu4","r0rYAwe","DxL0z0S","y3vYCMvUDeK","DcbSAw1PDa","txzozKi","x29Uq2XVC2u","vLjvBgy","Dg9hzw5LCMe","C2vYDMLJzq","zw5HyMXLvhi","tg9NsurozxC","BLrtrfe","CNnVCL92ywW","D1z4y2G","tfrovMK","wMjdDhO","y2HLy2Tszwe","zgLVEKK","x3DZ","BhHHEhm","sNnODxC","DgfIyxnL","y2HnyxHuCMK","DhLWzq","DgvZDa","D25vuMK","t3Hmzvu","EM1srvG","AM9PBG","AxnFywnR","zwXpvu0","tufyx1jfvfi","yxjYyxLIDwy","wef1z0S","rxzLBNq","lcbTyxGGCMu","EuX1s2u","yxbWzw5Kq2G","zxjFBxnNAwq","AwXLx25HBwu","DwDWELe","thzlv0y","y2HHCKnVzgu","vLbJAve","Cxjjr1G","zvvYBa","B29UAuG","z29PBMCGyxC","DxnJALO","zNjVBunOyxi","vxPTr08","vu1WvLC","x2XPC3rLBMu","Aw5L","CMfUzg9T","BxPHCge","y291BNq","tMrrEhi","AuH3Dgi","B09yD2u","zMzMzG","r3nZA3e","DcbVzIbYyw4","ywDLsgLKzq","DgjODeS","t1bftL9fuLi","ufDVCNC","y29Uy2f0","z3LRuuu","ywv0vuW","vwjZAeW","teXfDum","DhDVCMTdAge","yw9rA2W","y3jLyxrLt2i","rgvKAwnHDgu","Bg9Nsurhzw4","tgvStxm","AgfZ","CMvXDwLYzwq","CfjJtMW","rNbXtKK","y29SBM8","BNztEfO","x194x21Zz18","y3jLyxrLq2W","q0zZyvK","Dw9myKS","mNW2Fdf8n3W","z2v0q3vYC28","yNL0zxm","sg1XrK8","zxjFywnRx20","wKPdrei","zgfkCeu","y3vYC29Yx24","z0zwqKS","CNzHBa","x1fVu01HBMe","y2z4Cwy","zxbPB3K","qxjSuwi","DMvVzue","BwvZ","tLrTA3a","BhvOEu0","v0LPtKK","DwD2z3q","wLDfAxC","wez3tLq","yuDtvuG","B3jpBMXPBMu","ywnOzwq","veLoC20","BKXPBMu","wwLhq0q","vfPxuwm","DxHnq2q","quXm","rhHMq2C","C2v0sxrLBq","zNjVBujPDhm","x3bHDgHlzxK","tvjXwwq","z2vjBMzVu3K","zxjHDg9Y","qKTgv1e","zgLZywjSzue","quHIAvC","x2rLyNvN","A3PtDxe","t2nXtLq","BhzKv0W","Bg9N","ywDLrxzLBNq","DKrAA00","AwL6Du4","vgXUu0G","ndjIuLfMsMu","zxPRt1K","AgLfDwe","vfrnyKS","DhjHBNnHy3q","ywnOzwqSihC","A2Teuwm","C0fRzwG","wKz1uNa","ywWGy3vYC28","Ec11C2uT","tw5HtuS","DK5zvee","Bwv0Ag9K","revNDhu","tNnluhi","rLDLCK4","yNL0zu9MzNm","BhrXwfe","zwrWrfa","shL5y08","AgfZt3DUuhi","C2v0","zNjVBNrPzxi","ywrKt25L","zu9oEeO","y2XLBhy","CgLUz19VBMm","s2jTA3y","z1LuCwq","ywrKrxzLBNq","whP3swu","AuDUreK","u0n2yLi","v2vIu29JA2u","BwvKAwf0zwW","zNjVBuj5Dgu","EKPAwLe","y3vYC29YlNm","Dfzyrgq","zxrMqNy","Cg9PBNrbBMq","vu9vyuW","B3bLCNr5","AuLoDKK","DMfS","vKPuww8","CuDdsKy","vfrZzwq","zLvizw4","yvzrsxG","CMvHzfvjBNq","Ce9vtxm","B3nLrxzLBNq","BgLZDgvUtMu","De1HBMfNzxi","wgXQzeS","BM9Uzv9UB24","u2HHCMvKv28","suzQzwq","q29Kzq","B25szwnLAxy","B2LUDfjLywm","yKjcAwy","wg9Ls2K","D3jPDgvvAw4","EMfvsuu","DMfSDwu","yw1LoIa","seL5sgy","C2vUzf9Hy2S","yLH6zNO","uMX2r1y","BMrWB2LUDfq","B3bLBG","BhvZs0u","BMXPrw8","s0PXqKC","uxvQBgK","wwHpC3u","B3nLza","yMTqzxe","r0r5tuW","se5Szgu","EfvqAva","zw9trKW","C3vIyxjYyxK","wNj6D1u","vLLLwNO","yunwqvi","BNvTyMvY","y3vYC29Y","ywnR","EvrTrMK","x2n1CNnVCKy","DNLYyM0","t0vvyuq","AKHdyvG","q3vZDg9Tq2W","y2uGBM90igK","rwvVrKO","CMvTB3zLq2G","AKveBwG","uNH2wwu","yxnL","tNjqyu4","Dgv4DfbHEwW","EePfwgO","DxrMofDYAxq","ywrK","twLZC2LUzYa","EMfwA00","rNjnB1i","sLHvsLG","qK5kDhy","CMvHzhLtDge","mJuYouPWtuPdsa","ueTYqw4","tvLyA2K","rfbttgW","A0rLzKe","AunyDw8","AxnszwfKEq","yK1vwwy","zNzpANy","DLPZzuK","AxnrB1nnzxm","yvrkBvm","C2nYAxb0","zg56u1u","BeHHBMrSzxi","tvHfCfm","zv90Aw1LB3u","ALjKqKm","C25ys1a","tKjdCxu","vvDUt28","uw5MsgC","yw1Lu3bHy2u","vLnRs1u","q3jrC1C","AxmGDw5Kzwy","B3bLCNr5tMe","DxbNCMfKzw4","v1DUEMW","u3zLAgi","ALrZC0e","BLLOrwi","mNW0Fdn8mhW","yw5Hz2vY","q3zMy1C","zw16v0i","D1bVCfe","BwLeEem","ufLIz20","vuTprgq","rLDTEvC","x29Ut3bLBG","x3jLBw92zvC","rKzcz3u","BffKtxG","tMfTzq","r3vAvK8","C3Llzhm","v2vPweW","CMTLCKDSB2i","zfLeAvO","nhW1Fdn8ma","Bwf4tg9ZC0m","EvjLy29UBMu","C0zsuxC","z0TtsNq","zw5XDwv1zq","t3v0yxe","yNvMzMvY","y2XVC2uSihC","mZuXmJiXmM5jsKjIzW","y2nVuwG","C3rYAw5N","z2v0sxrLBq","BxfwB3O","wxHNEeW","ALPZwe4","wKzrtLm","x2rPC3bHDgm","ALHcC3i","Cgu6ia","Dw50","vMHYy2e","uMvHzcbWyxm","B25tDgfYDfi","x29UtwvZC2e","uLzlv3a","zw5fDMvUDa","vgLct04","wxrHqxe","B29nuwm","vwvYBgy","yLzzuLe","yw5ZzM9YBvq","uwrJCfm","vxbRufC","B052q1m","DgLTzw91Da","C2v0q3vYC28","BwvY","sNbjqKW","CMvZDwX0","C2fNzq","ywDLu2HVDW","zw50zwqGDhK","Dg9cExrLCW","zNnlywu","vw1QAKy","s2zXshe","uw1nAva","B3Dzrhy","C0Xf","zeXMvwC","r2LctvK","zMLN","C1bSDMe","mte2mZG2ngrftxriCG","y3bTs0G","B2zM","tgLZDgvUzxi","zenOsxq","Bunzzvi","qLD2rNi","yKPKruW","BgLUzq","BMvKC1i","Bu5TzMy","zvv0B0y","DM9gsgO","wfrXAKy","wwfxEu0","AerXwg8","uMvJB25Uzwm","tgH2wva","u3bztum","reDYz3C","qNjPzgDL","t3bLBKv2zw4","y3jLyxrLtwu","tgPxrxC","zxHWB3j0CW","AfDWvMC","BM93","rhP5zwO","B1jMAfm","y2npseG","Aw1ysu4","DKHqwxa","vLfMv20","wK5rzMG","B25VCgvU","zNDTBvO","ChbL","tKfusvzfx0u","v2DLquq","yLbethO","yNzbq0y","AK9Zr2C","B2fK","r3LSuMW","x3jLy29UBMu","ELbLru4","C0vby0q","rwX5DxC","vuD0qvO","wvLsCwm","q0riEfy","rgDfvvC","zMTbAw4","uLjpuG","tuLYB0u","u2jsrMG","wfDuug0","ysbTDxn0igi","A2fIy0q","uhjPBwfYEuS","De1WtLC","DgLTzw91DcW","m3W4Fdf8mNW","wfbjrhq","zNvUy3rPB24","C2vUza","zMzLCG","zgrwD0K","zw93y0G","AfLsrNi","t3jJtKe","uKvNv3u","zNPNveq","BKnZBfK","yM5gBey","vNDzENO","u09JBgu","y1Piv24","x2vUzhbVAw4","AhPbEuy","z2D0y2W","B3jRzxjhBg8","Cw9Z","zhznzfm","De1wCwy","ywjVCNq","vwjxtw0","sfDuyNK","ufHPtMS","ExrfAe8","B2D4sxa","sK1Pwgi","yKLhrKu","DwjvrxC","AMrIwhy","DxbKyxrLq3u","CwvAELu","A2v5","CMXiywe","Aw5N","x25HDMLNyxq","CNjVCK1LC3m","ignVzgu6ia","ALDLvMG","vLbNu0S","zxq9DxrMltG","Dg9Y","v3r4qwi","y3jLyxrLrwW","CMfNzvn5BMm","r1HrvM0","zM9YrwfJAa","rKHJENi","y29UDgLUDwu","zxH0ugf5Bg8","u2vXsuq","zxfos3O","yMLUyxj5vhK","rMnxyue","AefJA01LC3m","z2v0q3vYCMu","BfrPBwvVDxq","A2vSvhe","ELf3B3m","vvfvq2m","ug9cwMW","sxL1EfC","zgvMAw5Luhi","Dhj1y3rVCIa","x2rLC3rYB3K","y2fNuMu","Dg9cExrLC0W","BwvZC2fNzv8","s0Xvuwm","C3nHz2vfDMu","B3v0sw50zxi","DwPKv1K","B2nRzxq","igzHAwWSig0","z2v0","uMjVA0W","EfrfseW","BLL0CKm","yMv6svy","yxKSig5LDhC","x2fKzfDZtgK","Ec1TC2CTy3u","v1nVEum","wgLOqMO","qLPesLm","DhjPzxm","BNrLCG","B25JBg9Zzq","sgPuALO","qNzODeO","Bwf4uMv0CMK","A0DruhO","wM1euxO","B1D2u2S","DwTdvuO","zNritM0","zxH2yMK","y2XLyxi","y29Kzq","yMHjvwO","qwXWvK0","nteYnJa0vwjOtfjb","u1jcz1q","yM9L","Cgf5Bg9Hzfq","AxnrB1nby2S","uuTXzxu","AhHvte8","yMzfrKO","CgLUz09Uy2u","rxjYB3jdB2q","ywnRx2LK","CgfyDuC","shLis1i","r01kr0O","wMveCgi","s0f0tNm","D3HwqKG","vvrgtgy","v1Pbt0K","C2DPza","A0j6C0u","Cgf5Bg9Hza","serduMK","sfLcCvy","ueXvDfO","tw1ZD0O","A0HeAgy","rMLzvwe","A2v5CW","DgTvEeC","zwn0","vLfTBwO","swvyuvu","CxfzBvu","C1vrzM4","Aw9U","B2j1CvK","BfnouuW","zxH0zw5ZAw8","CvDjvMq","vfPmwKS","y2vZC0HHBMq","zvLszxK","wuDoq1a","C0jlEeu","vu5mvu0","mtbXrffOvxu","yw5Nzq","ufPYB0m","y29UBMvJDca","rerKv1u","ChvZAa","CNLYtha","B2DdBu8","AwTND0S","rwLcAKq","B0DnzLe","qLfTvhK","AxPHt2m","mNWXFdn8nhW","qwvVse0","B1rvruq","rerXAvK","wxLkuLG","quPVEKm","CNrlsLq","C0nVDw50zxi","ENj6rMG","B05vDwy","u1Dbv20","zuvTsg8","zwrPyxrLBhK","Dg9cExrLC0i","zxHiq0y","thPYBgm","u2vYDMLJzvC","x2LZv29YA2u","y29TCgXLDgu","qKTvrNO","y2nOA0m","EwHyvgW","BMCGzMfPBgu","qKPdzeC","qxzvtwi","Auvfs1O","rLDKtxa","Ef9MCM9UDgK","zK1RAxO","vNzgrwq","CNbfDK0","qxjYq2u","Bg1vEvm","rvn2s3O","DMvY","u0zYtLG","EMXkDLq","zwPjBK8","zgnysuq","D2Tvu1u","tMrJyNG","CwHtD0C","ANL2sLa","wNbxq0e","zwvKzwq"];return Eo=function(){return t},Eo()}(function(t,e){let r=z,i=t();for(;;)try{if(-parseInt(r(1957))/1*(parseInt(r(1873))/2)+parseInt(r(1011))/3+parseInt(r(1604))/4*(parseInt(r(835))/5)+parseInt(r(1216))/6*(parseInt(r(719))/7)+-parseInt(r(1438))/8+-parseInt(r(1332))/9+-parseInt(r(1650))/10*(parseInt(r(1392))/11)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(Eo,340285);var mE=Object[N(1565)+N(1259)],wE=Object[N(744)+N(1358)+N(1181)],Ff=(t,e)=>function(){return t&&(e=(0,t[{CQDYT:function(c,l){return c(l)}}[N(792)](wE,t)[0]])(t=0)),e},_E=(t,e)=>{let r=N,i={kLEEl:function(c,l,u,x){return c(l,u,x)}};for(var o in e)i[r(997)](mE,t,o,{get:e[o],enumerable:!0})};function yE(){return Lf||(Lf=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function EE(){let t=N;return Nf||(Nf=[IDBCursor.prototype.advance,IDBCursor[t(910)+"e"][t(1551)],IDBCursor[t(910)+"e"][t(1551)+t(1497)+"ey"]])}function bE(t){let e=N,r={bhIUj:function(o,c){return o(c)},AvUMb:function(o){return o()},NenYJ:function(o){return o()},udMlh:function(o,c){return o+c},AQDFG:function(o,c){return o+c},sjTkn:function(o,c){return o&c},JZQRs:function(o,c){return o|c},ZKNrP:function(o,c){return o<<c},fmucJ:function(o,c){return o&c},NaYSe:function(o,c){return o<c},rEDUd:function(o,c){return o(c)},hDqXo:"complete",TZLZK:"error",qeZzU:function(o,c){return o===c},xFHsN:"tzdBL",iINvI:"OBdrq",qfxcS:function(o,c){return o instanceof c},CCmbU:function(o,c){return o!==c},CmsOC:"BqzAO",rMisa:e(1114)},i=new Promise((o,c)=>{let l=e,u={Kjpir:l(578),mNkdP:function(_){return r.NenYJ(_)}},x=()=>{let _=l;t[_(1854)+_(1790)+"ner"](u.Kjpir,p),t[_(1854)+_(1790)+_(497)]("error",w)},p=()=>{o(Mt(t[l(1423)])),u.mNkdP(x)},w=()=>{let _=l;r[_(1602)](c,t[_(787)]),r[_(1687)](x)};t[l(1246)+l(1441)](l(578),p),t[l(1246)+l(1441)](l(787),w)});return i[e(929)](o=>{let c=e;r[c(1534)](r[c(1954)],r[c(1260)])?(_0x4d8f99=_0x244227[r[c(761)](r[c(503)](_0x4f5917,_0x2f7c64),1)],r.sjTkn(192,_0x34d93e)!==128?_0x4dd519+=_0x3188d5:(_0x4a50a0=r[c(1962)](r[c(1014)](r.sjTkn(31,_0x4cbb2f),6),r[c(991)](63,_0x3d21fb)),r[c(1725)](_0x266821,128)?_0x57f04f+=_0x54e0a5:(_0x2aa19b+=r.rEDUd(_0x30a63a,_0x3e3856),_0x51cfa0++))):r[c(1835)](o,IDBCursor)&&(r.CCmbU(r[c(831)],r[c(1867)])?ed.set(o,t):(_0x30883f[c(1854)+"entListe"+c(497)](r[c(1453)],_0x36bf83),_0x532ae1["removeEv"+c(1790)+"ner"](r[c(1644)],_0x41aae7),_0x5f3be9[c(1854)+c(1790)+c(497)](c(1523),_0x260b3f)))})[e(1745)](()=>{}),vo[e(1238)](i,t),i}function vE(t){let e=N,r={komTv:function(o,c){return o!==c},edeaq:e(1681),CEMJP:e(787),GhvZO:e(1523),yWnAD:function(o,c){return o(c)},SpCLe:e(590)+"or",wxVBH:function(o){return o()}};if(bo[e(1156)](t))return;let i=new Promise((o,c)=>{let l=e,u={Clcuf:function(_){return _()},IhyBk:function(_,I){return r.yWnAD(_,I)},yAKNo:r.SpCLe,GiBMY:function(_){return r[z(1620)](_)}},x=()=>{let _=z;r[_(754)](_(1070),"Kuvhw")?(t["removeEv"+_(1790)+_(497)](r.edeaq,p),t[_(1854)+_(1790)+_(497)](r[_(1718)],w),t[_(1854)+"entListe"+_(497)](r.GhvZO,w)):_0x2b3ed3.push(_0x3e33de)},p=()=>{let _=z;u[_(494)](o),u[_(494)](x)},w=()=>{let _=z;u[_(1813)](c,t.error||new DOMException(u.yAKNo,u[_(1005)])),u[_(1435)](x)};t[l(1246)+l(1441)](l(1681),p),t["addEvent"+l(1441)](r[l(1718)],w),t[l(1246)+l(1441)](r[l(961)],w)});bo[e(1238)](t,i)}function SE(t){So={npMOL:function(i,o){return i(o)}}[N(1825)](t,So)}function AE(t){let e=N,r={aVQIx:function(i,o){return i(o)},ddVwI:function(i,o){return i(o)},aCVAR:function(i,o){return i(o)},WIiNI:function(i,o){return i(o)},KyluI:function(i,o){return i in o},aWzDg:e(995)+e(973)};return t===IDBDatabase[e(910)+"e"].transaction&&!r.KyluI(r.aWzDg,IDBTransaction[e(910)+"e"])?function(i,...o){let c=e,l=t[c(1027)](r.aVQIx(Bi,this),i,...o);return Qc[c(1238)](l,i.sort?i[c(638)]():[i]),r[c(1266)](Mt,l)}:EE()[e(654)](t)?function(...i){let o=e;return t[o(1765)](r[o(1266)](Bi,this),i),r[o(1505)](Mt,ed[o(1577)](this))}:function(...i){let o=e;return r[o(1305)](Mt,t.apply(r[o(1184)](Bi,this),i))}}function IE(t){let e=N,r={lGQIc:function(i,o){return i===o},zmmQt:function(i,o){return i(o)},UMpVW:function(i,o){return i instanceof o},QvzVz:function(i,o){return i(o)},wiiBx:function(i,o,c){return i(o,c)},JFPuE:function(i){return i()}};return r.lGQIc(typeof t,"function")?r[e(478)](AE,t):(r[e(1129)](t,IDBTransaction)&&r[e(1e3)](vE,t),r.wiiBx(Uf,t,r[e(523)](yE))?new Proxy(t,So):t)}function Mt(t){let e=N,r={LjWEw:function(o,c){return o instanceof c},CCgnS:function(o,c){return o+c},ZyQQD:e(564)+e(1715),XGUtD:function(o,c){return o+c},MOjIL:function(o,c){return o(c)},iizuN:function(o,c){return o!==c},SYfsw:function(o,c){return o!==c},dBNYM:e(572)};if(t instanceof IDBRequest)return r[e(1925)](bE,t);if(_o[e(1156)](t))return _o[e(1577)](t);let i=IE(t);if(r[e(1214)](i,t))if(r[e(1733)](e(1857),r[e(675)]))_o[e(1238)](t,i),vo[e(1238)](i,t);else{let o=_0x166417[e(1927)]&&_0x2b9858[0];if(r[e(1461)](o,_0x1c5651))throw o;let c=new _0x139d86(r.CCgnS(r.ZyQQD,o?r.XGUtD(" (",o[e(1829)])+")":""));throw c[e(669)]=o,o}return i}var Uf,Lf,Nf,ed,bo,Qc,_o,vo,So,Bi,Mf=Ff({"node_modules/idb/build/wrap-idb-value.js"(){let t=N,e={yFROs:function(r,i){return r instanceof i},eoSFL:function(r,i){return r===i},bBBif:t(1935),geCZB:t(592),ogCmO:function(r,i){return r===i},PfloK:t(995)+t(973),oGMfQ:function(r,i){return r===i},pKFjA:t(1791),Fetjp:function(r,i){return r(i)},luhyM:function(r,i){return r===i},TlnSH:function(r,i){return r in i}};Uf=(r,i)=>i[t(746)](o=>r instanceof o),ed=new WeakMap,bo=new WeakMap,Qc=new WeakMap,_o=new WeakMap,vo=new WeakMap,So={get(r,i,o){let c=t;if(e[c(632)](r,IDBTransaction))if(e[c(1301)](e[c(1279)],c(1935))){if(e[c(1301)](i,e[c(551)]))return bo.get(r);if(e[c(1657)](i,e[c(890)]))return r[c(995)+c(973)]||Qc[c(1577)](r);if(e[c(1660)](i,e.pKFjA))return o[c(995)+c(973)][1]?void 0:o.objectStore(o[c(995)+c(973)][0])}else return _0x3defdb?_0x6365b4[c(1252)+"sLE"](_0x19ba04,_0x58b716):_0x2ca775[c(1252)+c(716)](_0x4e1900,_0x58b730);return e[c(927)](Mt,r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return e.yFROs(r,IDBTransaction)&&(i===e.geCZB||e[o(1183)](i,e.pKFjA))?!0:e[o(1215)](i,r)}},Bi=r=>vo[t(1577)](r)}}),Gf={};_E(Gf,{deleteDB:()=>CE,openDB:()=>TE,unwrap:()=>Bi,wrap:()=>Mt});function TE(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let l=N,u={oVmVb:function(w,_){return w(_)},tVYCo:function(w,_){return w|_},NRjbe:function(w,_){return w|_},gykQE:function(w,_){return w<<_},KepPR:function(w,_){return w<<_},CJLgP:function(w,_){return w===_},FfjfG:l(642),KnPxL:l(723),EGyvC:function(w,_){return w(_)},eQzSf:"blocked"},x=indexedDB[l(1290)](t,e),p=u.EGyvC(Mt,x);return i&&x[l(1246)+l(1441)](l(1359)+l(1707),w=>{let _=l;i(u[_(1012)](Mt,x.result),w.oldVersion,w[_(568)+"on"],Mt(x["transact"+_(1639)]))}),r&&x[l(1246)+l(1441)](u[l(1798)],()=>r()),p.then(w=>{let _=l;if(u[_(656)](u.FfjfG,_(642)))c&&w[_(1246)+"Listener"](u[_(1919)],()=>c()),o&&w[_(1246)+_(1441)](_(1885)+"hange",()=>o());else return new _0x28f8ed(u[_(763)](u[_(875)](_0x224d2c[0],u[_(1146)](_0x272224[1],8))|u[_(522)](_0x2edda8[2],16),_0x4d3d25[3]<<24),u[_(875)](u.NRjbe(_0x1f8b50[4],_0x18c35c[5]<<8)|_0x52275d[6]<<16,u[_(1146)](_0x2af56e[7],24)),_0xadfd4a)})[l(1745)](()=>{}),p}function CE(t,{blocked:e}={}){let r=N,i={hYRFr:"blocked",ItYKB:function(c,l){return c(l)}},o=indexedDB[r(1963)+r(1099)](t);return e&&o[r(1246)+r(1441)](i[r(1507)],()=>e()),i[r(463)](Mt,o).then(()=>{})}function Bf(t,e){let r=N,i={uQoKE:"readwrite",cchkC:r(1060),zaVkM:function(x,p){return x instanceof p},wDcEi:function(x,p){return x in p},JNIKe:r(1394),BNJtv:function(x,p){return x!==p},EzUcW:function(x,p){return x in p},FpqNI:r(1021),MCyeV:r(678)};if(!(i[r(1327)](t,IDBDatabase)&&!i[r(484)](e,t)&&typeof e===i[r(598)]))return;if(yo[r(1577)](e))return yo[r(1577)](e);let o=e.replace(/FromIndex$/,""),c=i[r(1330)](e,o),l=Hf[r(654)](o);if(!i[r(537)](o,(c?IDBIndex:IDBObjectStore)[r(910)+"e"])||!(l||qf.includes(o)))return i[r(1330)](i[r(1159)],i[r(532)])?void 0:this[r(682)][r(1600)]();let u=async function(x,...p){let w=r,_=this[w(1220)+w(1639)](x,l?i[w(776)]:i[w(1683)]),I=_[w(1791)];return c&&(I=I[w(1052)](p[w(786)]())),(await Promise.all([I[o](...p),l&&_[w(592)]]))[0]};return yo[r(1238)](e,u),u}function z(t,e){t=t-442;let r=Eo(),i=r[t];if(z.eRJaJb===void 0){var o=function(x){let p="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",w="",_="";for(let I=0,E,v,A=0;v=x.charAt(A++);~v&&(E=I%4?E*64+v:v,I++%4)?w+=String.fromCharCode(255&E>>(-2*I&6)):0)v=p.indexOf(v);for(let I=0,E=w.length;I<E;I++)_+="%"+("00"+w.charCodeAt(I).toString(16)).slice(-2);return decodeURIComponent(_)};z.ndXtlg=o,z.uDMuBF={},z.eRJaJb=!0}let c=r[0],l=t+c,u=z.uDMuBF[l];return u?i=u:(i=z.ndXtlg(i),z.uDMuBF[l]=i),i}var qf,Hf,yo,DE=Ff({"node_modules/idb/build/index.js"(){let t=N,e={LvKWF:"4|3|0|5|"+t(907),eOdrL:"get",KcFiM:"getKey",pnMwo:t(612),exHCF:t(655)+"ys",gOazY:t(1134),SCvbR:function(o){return o()},LgWhD:t(743),RVKWp:t(839),ClWwc:"clear"},r=e[t(1119)][t(863)]("|"),i=0;for(;;){switch(r[i++]){case"0":qf=[e[t(924)],e[t(1003)],e.pnMwo,e[t(1677)],e[t(852)]];continue;case"1":SE(o=>({...o,get:(c,l,u)=>Bf(c,l)||o[t(1577)](c,l,u),has:(c,l)=>!!Bf(c,l)||o[t(1156)](c,l)}));continue;case"2":yo=new Map;continue;case"3":Mf();continue;case"4":e[t(1249)](Mf);continue;case"5":Hf=[e[t(459)],t(1325),e[t(1408)],e[t(798)]];continue}break}}}),RE={idb:function(t){let e=N,r={MvNfB:function(i,o){return i+o},rIfuX:function(i,o){return i*o},YYRqc:function(i,o){return i!==o},lKjra:e(899)};t[e(1462)]=Promise[e(946)]()[e(929)](()=>(DE(),Gf))[e(929)](function(i){let o=e,c={DEgtu:function(l,u){return l*u},ytEhO:function(l,u){return l>>>u},UmjjF:function(l,u){return r[z(1082)](l,u)},ukCUJ:function(l,u){return r[z(470)](l,u)},tkUxG:function(l,u){return l>>>u}};return r[o(1487)](r.lKjra,o(899))?this[o(1739)]?c[o(1230)](c[o(1527)](this[o(693)],0),_0x3ec508)+c[o(1527)](this[o(1839)],0):c[o(1429)](c[o(1597)](this.high,_0x4db8ba),c[o(1633)](this.low,0)):i})}},zf={};function Nt(t){let e=N,r={VRUlf:e(1007)+"3",sLYXm:function(u,x){return u!==x}},i=r[e(1084)][e(863)]("|"),o=0;for(;;){switch(i[o++]){case"0":if(r.sLYXm(void 0,c))return c[e(1462)];continue;case"1":var c=zf[t];continue;case"2":RE[t](l,l[e(1462)],Nt);continue;case"3":return l[e(1462)];case"4":var l=zf[t]={exports:{}};continue}break}}Nt.d=(t,e)=>{let r=z;for(var i in e)Nt.o(e,i)&&!Nt.o(t,i)&&Object[r(1565)+r(1259)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=N;Nt.o=(e,r)=>Object.prototype[t(1237)+"operty"].call(e,r)})(),(()=>{let t=N,e={GylRl:function(r,i){return r!=i},SbRFh:t(1891),MFwlQ:t(928)+"le"};Nt.r=r=>{let i=t;e[i(1481)](i(645)+"d",typeof Symbol)&&Symbol[i(913)+i(641)]&&Object[i(1565)+i(1259)](r,Symbol[i(913)+i(641)],{value:e[i(1493)]}),Object["definePr"+i(1259)](r,e.MFwlQ,{value:!0})}})();var De={};(()=>{let t=N,e={MYXki:function(a,n){return a===n},ryrLp:t(957),yTmFi:function(a,n){return a(n)},ZWTwR:function(a,n){return a+n},nYtrC:function(a,n){return a+n},saaZZ:function(a,n){return a+n},zDHEA:function(a,n){return a*n},wXLBW:function(a,n){return a*n},cpmKH:function(a,n){return a+n},nYhEb:function(a,n){return a(n)},fzgTD:function(a,n,s){return a(n,s)},sAFWS:function(a,n){return a+n},PvHms:t(631),qThfx:t(1138),uAzaC:function(a,n){return a(n)},tumVl:t(833)+t(833)+t(833)+t(833),imXIN:function(a,n,s,d){return a(n,s,d)},xkMkW:t(1871),pmuOX:function(a,n,s,d){return a(n,s,d)},RcAyA:function(a,n){return a&&n},mOnDZ:function(a,n){return a||n},AJxcQ:t(941),ZeDpb:function(a,n){return a>n},MmswJ:function(a,n){return a!==n},LPyAA:t(1161),VRopv:function(a,n){return a<n},RlvGV:t(1638),OlyPx:function(a,n){return a!==n},KLUQc:function(a,n){return a-n},FugSJ:function(a,n){return a<n},vZseI:function(a,n,s){return a(n,s)},zwnpV:function(a,n,s){return a(n,s)},sgOsX:function(a,n){return a!==n},QsVDI:t(1492),FiYUa:function(a,n){return a(n)},qcqKi:function(a,n){return a(n)},TcIpa:function(a,n,s){return a(n,s)},dEoqL:function(a,n){return a(n)},JeWnO:function(a,n,s){return a(n,s)},ZTZNf:function(a,n){return a&n},MuVfn:function(a,n){return a===n},UTXjK:t(1326)+t(1157)+t(892)+t(1283),GFisN:t(1343),cdGUx:function(a){return a()},OOPeJ:function(a,n,s){return a(n,s)},PXiNk:function(a,n,s){return a(n,s)},mCYeR:function(a,n,s){return a(n,s)},XWTPm:function(a,n){return a(n)},wVzhd:function(a,n){return a!==n},bVoQs:function(a,n,s){return a(n,s)},gKSJt:function(a,n,s){return a(n,s)},iGnDI:function(a,n){return a!==n},pLZNU:t(753),MHOgQ:t(468),ezkOY:function(a,n,s){return a(n,s)},pdpuL:function(a,n,s){return a(n,s)},LelMs:function(a,n){return a!==n},Gsskq:t(1479),efwtO:"hZVdy",iCXuo:function(a,n,s){return a(n,s)},PYbgm:function(a,n){return a!==n},qWWVH:function(a,n,s){return a(n,s)},SBjjl:function(a,n,s){return a(n,s)},exvbi:function(a,n){return a!==n},elOUM:function(a,n){return a!==n},MBXUs:function(a,n){return a(n)},fMFZE:function(a,n){return a>>>n},dChIt:function(a,n,s){return a(n,s)},hxULO:function(a,n,s){return a(n,s)},UzmGO:function(a,n){return a(n)},cWYze:function(a,n){return a(n)},NHGVo:function(a,n){return a(n)},UGtAZ:function(a,n,s){return a(n,s)},Vhrca:function(a,n){return a(n)},BWvFr:function(a,n,s){return a(n,s)},IRlzK:function(a,n,s){return a(n,s)},rorXN:function(a,n){return a&n},UTFLf:function(a,n){return a===n},OYDtF:t(1326)+t(1157)+t(892)+t(1553),paXuG:function(a,n){return a===n},ejInO:"Missing "+t(1157)+t(892)+t(1086),RHKyI:t(1326)+"required field: "+t(1229),Uojmq:function(a,n){return a===n},wrBtT:t(1904),ZwDJv:function(a,n){return a+n},SDVDw:function(a,n,s){return a(n,s)},lQdMx:function(a,n,s){return a(n,s)},XacyC:function(a,n,s){return a(n,s)},dgVgn:t(1831)+t(1426)+t(1402),YtTlb:function(a,n){return a>=n},OrcNA:function(a,n){return a===n},eEmHo:"online",SRBgT:t(795),Qujli:t(1931),PweIU:t(1950),PjORI:function(a,n){return a+n},Qnohu:t(539)+t(1081),UuTsd:t(1405)+t(1081),tApqh:t(1308),IFjed:"WeiXL",kvFZJ:function(a,n,s){return a(n,s)},NYrOJ:function(a,n){return a<n},qTwqj:function(a,n){return a&n},qymfy:function(a,n){return a===n},nVsxa:function(a,n){return a&n},REdks:function(a,n){return a>=n},QnfHg:function(a,n){return a+n},wPopQ:function(a,n){return a&n},SLhxT:function(a,n){return a&n},CnrBk:function(a,n){return a<n},TTsed:function(a,n){return a(n)},bnFlF:function(a,n){return a==n},mfCvJ:function(a,n){return a|n},hryOO:function(a,n){return a<<n},bIGFE:function(a,n){return a<<n},ZnQCT:function(a,n){return a&n},DeCei:function(a,n){return a==n},jXNCM:function(a,n){return a>=n},lybER:function(a,n){return a+n},bezIV:function(a,n){return a!==n},sAkeh:function(a,n){return a&n},olthg:function(a,n){return a|n},CopBJ:function(a,n){return a<<n},iVWfg:function(a,n){return a|n},bXref:function(a,n){return a<<n},yYIxw:function(a,n){return a+n},zkHqO:function(a,n){return a>>n},YOzij:function(a,n){return a===n},GmjlR:t(1434),bvACF:function(a,n){return a<n},ZGszF:function(a,n){return a<=n},uKqSv:function(a,n){return a+n},GnOxC:function(a,n){return a<<n},vsPrO:function(a,n){return a<n},wGgiw:function(a,n,s){return a(n,s)},oNUuf:function(a,n){return a>=n},Lzrlc:function(a,n){return a<=n},OYtYY:function(a,n){return a<n},xTEHL:function(a,n){return a<<n},SWAWm:function(a,n){return a>>n},MEhyw:function(a,n){return a|n},eYRey:function(a,n){return a>>n},ETgmy:function(a,n){return a&n},CocPS:function(a,n){return a&n},mAufC:function(a,n,s){return a(n,s)},MMaFE:function(a,n,s){return a(n,s)},zmREX:function(a,n){return a>>>n},sjBdG:function(a,n){return a>>>n},VPgSK:function(a,n){return a|n},xXhtC:function(a,n){return a<n},uytgK:function(a,n){return a&n},SxlnZ:function(a,n){return a+n},uVluv:function(a,n){return a!==n},uujDB:function(a,n){return a>>>n},PqfXq:function(a,n){return a|n},nznTZ:function(a,n){return a&n},HjTjZ:function(a,n){return a>>>n},UpkPW:function(a,n){return a|n},CDuLM:function(a,n){return a>>>n},JPrGD:function(a,n){return a!==n},fsKae:function(a,n){return a===n},sPlva:"RsBYO",wnURi:function(a,n){return a(n)},PoBZl:function(a,n){return a&n},QmMiP:function(a,n,s){return a(n,s)},FJDYh:function(a,n){return a&n},SpYMC:function(a,n){return a&n},oTUED:function(a,n){return a===n},Pbime:t(695),mqVoz:function(a,n){return a&n},grCwV:function(a,n){return a(n)},aetUL:function(a,n){return a&n},XbpWw:function(a,n){return a&n},tVXDd:function(a,n){return a<<n},QdqTA:function(a,n){return a&n},oWDeG:function(a,n){return a(n)},fwmmZ:function(a,n){return a&n},ltqXQ:t(1466),Outaq:function(a,n){return a&n},cfxqf:function(a,n){return a&n},gPcql:function(a,n){return a>>>n},bIEbE:function(a,n){return a<<n},xvMXV:function(a,n){return a>>>n},QKqeu:function(a,n){return a>>>n},mzapa:function(a,n){return a<n},ezzjD:function(a,n){return a<n},WQnsf:function(a,n){return a&n},uGzoZ:function(a,n){return a>>>n},CWNbC:function(a,n){return a+n},kHDhf:function(a,n){return a|n},oNvCS:function(a,n){return a&n},jXBsr:function(a,n){return a+n},hZOZy:function(a,n){return a!==n},jLkfs:function(a,n){return a&n},FWdMp:function(a,n){return a!==n},kzSuq:function(a,n){return a+n},pOUMs:function(a,n){return a!==n},XwMej:function(a,n){return a>>>n},Fslpj:function(a,n){return a&n},GDyML:function(a,n){return a+n},yhXTl:function(a,n){return a!==n},ERRjd:function(a,n){return a|n},UKODd:function(a,n){return a>>>n},fRuJe:function(a,n){return a!==n},DiLXY:function(a,n){return a!==n},NEoxg:function(a,n){return a|n},LLEuC:function(a,n){return a|n},JssoC:function(a,n){return a===n},gJbRl:function(a,n){return a===n},NUdQR:t(473),YcDBU:t(467),qjdtI:t(787),vwnVm:t(1664),aBgwd:function(a,n){return a|n},ArrCe:function(a,n){return a<<n},VQfWm:function(a,n){return a|n},zrzFh:function(a,n){return a|n},tQNIW:function(a,n){return a<<n},AeSAY:function(a,n){return a|n},ccOHH:function(a,n){return a|n},XrZLN:function(a,n){return a|n},QBcuE:function(a,n){return a<<n},AkxGR:function(a,n){return a|n},BJCdG:function(a,n){return a|n},owYDv:function(a,n){return a&n},MacCZ:function(a,n){return a|n},oOXwe:t(1463),ooniH:function(a,n){return a|n},BZDJS:function(a,n){return a<<n},Svehb:function(a,n){return a<<n},kDefA:function(a,n){return a>>>n},XPIDt:function(a,n){return a&n},ZmJXv:function(a,n){return a>>>n},fyEZG:"juGWx",VJTYo:function(a,n){return a(n)},sNbay:function(a,n){return a|n},xUPiP:t(1720),IeiAF:"LxWht",XljdK:function(a,n){return a>>>n},uoLbK:function(a,n){return a===n},tMpNW:function(a,n){return a===n},gfWeD:"vbhsK",JXUJX:function(a,n){return a>>>n},jEDmh:function(a,n){return a&n},jHzoy:function(a,n){return a&n},izVmZ:function(a,n){return a>>>n},eyhnA:function(a,n){return a>>>n},UbshL:function(a,n){return a|n},khIgd:function(a,n){return a|n},icCdt:function(a,n){return a!==n},ypJDH:function(a,n){return a===n},koAIG:function(a,n){return a===n},OELpQ:function(a,n){return a>>>n},jyvJP:function(a,n){return a===n},hSJlX:function(a,n){return a===n},ccoQh:function(a,n){return a+n},livMB:t(750),syKds:t(1556),iVQgz:function(a,n){return a&n},zQwos:function(a,n){return a&n},vyrbm:function(a,n){return a>>>n},SCnLX:function(a,n){return a>>>n},bkPeq:function(a,n){return a>>>n},QRcUg:function(a,n){return a&n},XoeKi:function(a,n){return a>>>n},smwLt:function(a,n){return a>>>n},XzwIe:function(a,n){return a>>>n},FgMtt:t(550)+t(1817),jWeVh:t(1143)+"OR",kYFtD:t(1475)+t(1491),nzxeI:"MAX_RETR"+t(707)+"R",CvfcW:t(771)+"ERROR",gzCKT:function(a,n,s){return a(n,s)},cySYw:function(a,n){return a===n},USlgn:t(1724),iHwtb:t(984)+"1",YMscG:function(a,n,s){return a(n,s)},KbrpA:t(723),wBLoH:t(745),vbyTX:t(564)+"d error.",zCQwN:"tkCTf",innzK:function(a,n){return a>=n},diozI:function(a,n){return a instanceof n},boSMK:function(a,n){return a+n},MfGbe:function(a,n){return a+n},fBcTY:function(a,n){return a===n},aeWCi:function(a,n){return a===n},hiEua:function(a,n){return a<n},lmUyS:function(a,n){return a|n},ppClP:function(a,n){return a<=n},DDdWU:function(a,n){return a(n)},NnhiC:t(535),pigTL:t(1059),YhOsu:function(a,n,s){return a(n,s)},rmQAX:function(a,n,s){return a(n,s)},DDqiY:"open",ArlQb:function(a,n,s){return a(n,s)},xJEXj:t(1097),izaOc:t(1829),TXSZW:function(a,n){return a instanceof n},VSkKU:function(a,n){return a+n},QUKar:function(a,n){return a===n},GKIRq:t(1525),uceKe:t(1782),Elyuw:function(a,n){return a===n},XAsPS:"gRVZB",sdhwO:t(1932),KAtNs:function(a,n){return a!=n},CmhPt:t(645)+"d",liRhB:function(a,n){return a<=n},SnpAB:t(1046)+"alled mu"+t(652)+t(1862)+t(1881),DYhIL:function(a,n){return a+n},ESvKz:function(a,n){return a<n},mgyPC:function(a,n){return a&n},mayWb:function(a,n){return a+n},khrJv:function(a,n){return a===n},epioy:"ZBwlb",qlOYi:t(1837),PlUID:function(a,n){return a>=n},xrkCT:function(a,n){return a|n},hZUWF:function(a,n){return a&n},etfBv:function(a,n){return a<n},ugvgt:function(a,n){return a&n},EKwkY:function(a,n){return a&n},aoQkl:function(a,n){return a|n},eowcH:function(a,n){return a<<n},hzAyF:function(a,n){return a<<n},PbZTv:function(a,n){return a<n},OlURJ:function(a,n){return a<n},YxgxL:function(a,n){return a>>n},edpDP:function(a,n){return a|n},TEsrZ:function(a,n){return a&n},eqNKz:function(a,n){return a+n},sxqab:t(1907)+"2|0",GwwtZ:function(a,n){return a&n},dgdsf:function(a,n){return a+n},aGxEF:function(a,n){return a+n},YtaAq:function(a,n){return a<<n},mmUXy:function(a,n){return a&n},AHbiW:t(1844),RbokL:function(a,n){return a|n},IjFhw:function(a,n){return a&n},LJVXH:function(a,n){return a>>n},bMUYf:function(a,n){return a|n},OFQug:function(a,n){return a==n},PLUtZ:"string",BtLiS:"text/plain;chars"+t(1543),eUtoF:t(1606),faAZU:t(1474),XBLPx:function(a,n){return a!==n},nxGDu:t(1447),voaEV:t(1382),GMJGJ:"unknown reason",zQmtr:t(1344),EeoFJ:function(a,n){return a+n},KTKFl:"http",ZNQfh:"&jscallb"+t(536)+t(610)+"P",bJdEL:function(a,n){return a+n},qcSjU:function(a,n){return a===n},yZwFt:"QCRWZ",tqaLU:"idb",aGSUH:function(a){return a()},xdekx:t(1299),UQUCc:t(1545),qXzqN:function(a,n){return a===n},xULQR:"uEoRC",CUPWg:function(a,n){return a!==n},TERNB:t(1816),lkxTQ:function(a){return a()},bhTAX:t(703),StbgZ:t(1596),VPciQ:function(a,n){return a||n},TINsm:function(a,n){return a||n},RxvYe:function(a,n){return a||n},dcXID:function(a,n){return a||n},MEmjR:function(a,n){return a!=n},QkNFb:function(a,n,s){return a(n,s)},uomjc:t(1520),zQaIm:t(1570)+"id",rJaTo:function(a,n){return a(n)},miDxC:function(a,n){return a===n},NBCqu:t(1548),sQTBu:function(a,n){return a(n)},zaUIE:function(a,n,s){return a(n,s)},zPeEN:function(a,n,s){return a(n,s)},Kbmkv:t(487),REgWu:function(a,n){return a(n)},JQRNC:t(1690)+"er_qos",XpzkD:"x_fronti"+t(1899)+"ck",Dzyej:t(1690)+t(1809)+"k",SjcKT:t(1690)+t(1170)+t(1623),uBpom:function(a,n){return a>>n},PZroC:function(a,n){return a&n},tbhtK:function(a,n){return a!==n},Exizk:function(a,n,s,d){return a(n,s,d)},XDFYs:t(1107),dUnas:function(a,n){return a||n},XrMYY:function(a){return a()},kgMmN:"received",jZsXN:function(a,n){return a<n},UXFDu:function(a,n){return a instanceof n},XgFwI:function(a,n){return a instanceof n},GuZVO:t(868)+t(1882),CwgmK:"application/json"+t(451)+"=utf-8",AHeYe:t(1273)+"e",xJJDN:t(543),vPYRj:function(a,n,s,d){return a(n,s,d)},IBpCo:function(a,n){return a===n},SxOpZ:function(a,n){return a(n)},MuaKN:function(a,n){return a+n},PfQJd:function(a,n){return a+n},DPSLl:function(a,n){return a+n},SFrNX:function(a,n){return a+n},lusKE:t(490)+t(1140)+"ge: ",KJqBG:t(1735),lEXdw:function(a,n){return a||n},EGCJJ:t(699),rZcRL:function(a,n){return a+n},UbWMm:function(a,n){return a|n},jRdBC:function(a,n){return a<<n},gFVBK:function(a,n){return a<n},DnuuQ:function(a,n){return a(n)},Ctpjz:t(1893)+t(769)+"e",EaeyK:function(a,n){return a>=n},BFFmC:function(a,n){return a!==n},aHRUO:t(1236),CjDpy:function(a,n){return a&n},auumU:function(a,n){return a<n},vSZqd:function(a,n){return a<<n},HMmnZ:function(a,n){return a>>>n},cBSFl:t(956),xeeCU:t(469)+"2",wFOCn:function(a,n){return a<<n},ehOXp:function(a,n){return a+n},JaDtO:function(a,n){return a|n},OrBbb:function(a,n){return a+n},lAojy:function(a,n){return a+n},aOTkA:t(530),XptHw:function(a,n){return a>>>n},cOIWe:function(a,n){return a&n},ZJCDB:function(a,n){return a>>>n},HpmHU:function(a,n){return a+n},IeXQU:function(a,n){return a+n},URwQS:function(a,n){return a&n},MnaMK:function(a,n){return a>>>n},EuOyd:function(a,n){return a+n},jqXhz:function(a,n){return a&n},WmtAO:function(a,n){return a+n},DWtkH:function(a,n){return a>>>n},MsuMY:function(a,n){return a<<n},ElmHC:function(a,n){return a&n},ShiMX:function(a,n){return a<n},xijZL:function(a,n){return a>>>n},XuvpH:function(a,n){return a<<n},fUHen:function(a,n){return a>>>n},Hbbwd:function(a,n){return a|n},SoOef:function(a,n){return a&n},jTssA:function(a,n){return a|n},RHwOc:function(a,n){return a&n},LdnAQ:function(a,n){return a<n},KJTZb:"ctSPv",vlbQo:function(a,n,s,d){return a(n,s,d)},ZbCtz:t(979),FFBgu:function(a,n){return a<n},iYuAz:t(848),YwtXF:t(540),CUTtP:t(1254)+t(736),kJAlB:t(1767),OcARh:function(a,n){return a(n)},kGQPz:t(626)+t(1117),kKwwf:function(a,n){return a<n},rtKJT:function(a,n,s){return a(n,s)},FWerN:function(a,n,s){return a(n,s)},ggtcl:function(a,n,s,d){return a(n,s,d)},OVTbR:t(1173)+t(931),wXEFc:"iUCkC",TjHaj:t(1550),gWVHM:t(1196),PWorw:function(a,n,s,d){return a(n,s,d)},hIHSG:t(677),mvBvT:t(1064),lqOTl:function(a,n){return a<<n},ZWEiw:function(a,n){return a>>n},OEUaD:function(a,n){return a&n},yMjqs:function(a,n){return a===n},ogxIp:"pocuC",bXzfz:"GuUlZ",XbGHj:"setdb",DyUkV:function(a,n){return a(n)},YYKiY:"setcursor",zckYP:function(a,n,s){return a(n,s)},MuPkv:function(a,n){return a===n},GtiIY:t(1245),OCcjt:function(a,n){return a(n)},uscjZ:function(a,n){return a+n},BQmTy:function(a,n){return a/n},qGCJF:t(1659),qwiPU:function(a,n){return a!==n},YwGDn:t(1643),PYPTm:t(1812),KfqHq:function(a,n){return a||n},vHPYp:function(a,n){return a>n},pugNg:function(a,n,s,d){return a(n,s,d)},LJPfB:t(1601),kBzsE:t(1690)+t(1731),YbtcS:t(1951)+"s",ujdWY:function(a,n){return a(n)},UrJze:"x-msg-cu"+t(1090)+"ue",lFXxE:t(1586),UNLUM:t(546),ZFQNS:function(a){return a()},HDCRi:function(a,n){return a===n},cBJuB:"qmplS",tmQlZ:function(a){return a()},emzWB:function(a,n){return a===n},gFhjP:t(1959),VQmmj:function(a,n){return a===n},GPOJb:function(a){return a()},Usxxg:function(a){return a()},RzzeS:function(a,n){return a(n)},XFmJX:t(785),ElBih:function(a,n){return a(n)},EIZrP:function(a,n){return a!==n},yWjVw:function(a,n,s){return a(n,s)},UWFup:function(a){return a()},wDNzA:function(a,n){return a===n},PvqZF:t(1916),EVXHY:function(a,n,s,d){return a(n,s,d)},ZWxyk:t(1019),OVzvx:"auto",daJpE:t(578),bPDLz:function(a,n,s){return a(n,s)},DGrgw:function(a,n){return a===n},xpHbF:function(a,n,s,d){return a(n,s,d)},eINTD:t(1414),clelv:function(a,n,s){return a(n,s)},qAJxV:function(a,n){return a!==n},WgeAD:t(1201),IjaGF:function(a,n,s){return a(n,s)},flDgb:t(483),HyHKR:t(589),CQDLg:t(1682),MNlYS:function(a,n,s){return a(n,s)},CrGsW:function(a,n,s){return a(n,s)},kkDQc:t(826),jdbXv:function(a,n){return a/n},cyHjQ:function(a,n){return a==n},ZFuRp:function(a,n){return a===n},sLIiN:t(975)+t(789)+t(1922)+", WebSoc"+t(614)+t(1566)+t(1357)+t(1926),dvMdS:function(a,n,s){return a(n,s)},cZHWn:"reconnect",xelaA:t(481)+t(1675)+t(999)+"ct",lQFBW:t(1529),cmyVV:t(587),KCJZI:function(a,n){return a!==n},nTSDQ:t(908),XTqjF:function(a,n){return a===n},Zymyu:t(562),rlHaa:t(1611),TTMbK:function(a,n){return a===n},QSNGV:t(1410),VWrhV:"ZfPEu",BKFWQ:t(916),XmKKe:t(455),LaNFX:t(1855),VYeZz:t(926)+"d",qqYmU:function(a,n){return a||n},vNYTA:t(975)+t(557)+t(981)+"viceID o"+t(1041),SOcle:function(a,n){return a==n},veoeA:t(856),QCTol:t(902)+"0",FBiPo:"Dfpef",TdmXY:t(1734),QQDhg:t(948),RDylH:function(a,n){return a>n},vcPTs:function(a,n,s){return a(n,s)},CGXXj:function(a,n,s){return a(n,s)},qCPSD:function(a,n){return a(n)},AbgdU:t(965)+">",GDria:function(a,n){return a|n},hgBur:function(a,n){return a<<n},OcqNT:function(a,n){return a<<n},ikgwK:function(a,n){return a|n},qZDBE:function(a,n){return a<<n},ICZZr:"nvMOi",BFNyT:t(1063),mSOBW:function(a,n){return a>n},gBBcs:function(a,n){return a===n},iweJS:function(a,n){return a!==n},vUhCf:function(a,n){return a||n},cQsXi:t(673),wVxch:t(1243)+t(1348)+"t",YGNCP:t(1419),qrIGX:function(a,n){return a>>>n},kCNLT:function(a,n){return a>>>n},HmnAu:function(a,n){return a>>>n},qhSwG:function(a,n){return a&n},ZrzwU:function(a,n){return a&n},SbWQf:function(a,n){return a&n},ZpWCA:t(1598),WZAOI:t(1125)+"ay, try "+t(775)+t(1870)+t(1697),lXtgl:t(1834),ysnTR:function(a,n){return a!==n},DgEUW:t(1118),iEEKZ:t(1499)+t(508)+"onnecting",rIHSg:function(a,n){return a===n},pRJge:t(1286),sFRQw:function(a,n){return a===n},xrDkx:t(1448),YiGCD:function(a,n){return a(n)},WXIeI:t(686),dfNEw:"HdHIa",nCslY:t(1098),WAzZd:function(a,n,s){return a(n,s)},akeUz:function(a,n,s){return a(n,s)},KLShG:function(a,n,s){return a(n,s)},BDHdT:"sent",AKjIj:"CBjDB",WtQoi:t(1072),dPEzP:function(a,n,s){return a(n,s)},qThUb:function(a,n,s){return a(n,s)},GqLdJ:function(a,n){return a===n},IyuxW:"QTXXG",QvESW:t(1930),zucpf:function(a,n){return a===n},eAtIF:t(1496),pRcNl:t(882),OTaSQ:function(a,n){return a===n},lreBG:t(1929),npKqm:t(1166)+t(1383),zhwna:function(a,n){return a===n},BURbA:t(1391)+t(560)+t(553),WWnzl:t(975)+"rovide a valid d"+t(1906)+t(1495)+"e a stri"+t(1869)+" arraybu"+t(1504),AJozC:function(a,n){return a==n},nWMgN:t(1306),lSxha:t(975)+"rovide a valid s"+t(736),NrPaN:t(1006),jVWFB:"UjMwP",CFsaY:t(1388),UWnOo:t(1641),wdmwr:"manual r"+t(983)+t(1537),ZmDQz:t(1364)+"1",rpEvM:function(a,n){return a===n},LTNVi:"pKDKF",iQNRZ:t(1243)+t(1075)+"s",MOlqS:function(a,n,s){return a(n,s)},kelTq:t(742),WSoyC:t(1890),fbOnQ:function(a,n){return a!=n},enxZH:function(a,n){return a!=n},WptBV:"Object",HIyHf:t(1153)+t(538)+"lobalScope",PNJfC:function(a,n){return a!=n},PoOPd:function(a,n){return a===n},pAiaG:function(a,n){return a!=n},crodN:function(a,n){return a===n},SojQd:t(1679)+t(1519)+t(811),UIFOq:function(a,n){return a!=n},BMJcf:function(a,n){return a===n},gNFHB:t(1162)+"qos__"};Nt.r(De),Nt.d(De,{FWS:()=>Tp,CustomErrorEvent:()=>zd,createCloseEvent:()=>xt,ReconnectEvent:()=>Bd,createErrorEvent:()=>ot,decodedFrame:()=>Xt,createOpenEvent:()=>jd,CustomCloseEvent:()=>Fd,createReconnectEvent:()=>ra,FrontierMessageEvent:()=>Gd,encodeFrame:()=>zt,createMessageEvent:()=>Hd,OpenEvent:()=>qd,ErrorCode:()=>en,Event:()=>Jn,MessageEvent:()=>Ud});let r="";function i(a=""){let n=t;if(e[n(1334)](e[n(1656)],e[n(1656)])){let d=""+Date[n(1464)](),f=r||(r=e[n(1309)](x,a)),g=Math[n(1132)]()[n(913)](16).slice(-6);return e[n(1753)](e.nYtrC("02",d),f)+g}else this._socket&&this._socket[n(723)]({code:_0x3836f8,reason:_0x6a2c2d})}function o(){let a=t;return e[a(818)](e[a(527)](1e4,Date.now()),Math[a(822)](e[a(1805)](1e4,Math[a(1132)]())))}function c(a){let n=t;return e[n(1439)](e[n(1363)](Array,8).join("0"),e[n(1510)](parseInt,a,10)[n(913)](2)).slice(-8)}function l(a){let n=t;return e[n(1580)](e[n(1309)](Array,4)[n(1106)]("0"),e.fzgTD(parseInt,a,2)[n(913)](16))[n(757)](-4)}function u(a){let n=t,s=a.split(/\./)[n(1030)](g=>c(g)),d=[];return d[0]=e[n(1309)](l,e.sAFWS(s[0],s[1])),d[1]=l(s[2]+s[3]),[e[n(1847)],e[n(1847)],e[n(1847)],n(631),e.PvHms,e.qThfx,d[0],d[1]].join("")}function x(a){let n=t,s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[n(1102)](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.uAzaC(p,a):e[n(458)]}function p(a){let n=t,s="",d=[],f=0,g=0,m=!0,b=n(631);if(e[n(1618)](a[n(615)]("::"),-1))if(e[n(1629)](e.LPyAA,n(1043))){let h=a.split("::");for(let L=0;e[n(1053)](L,h.length);L++){let F=h[L];if(e.ZeDpb(F[n(615)](":"),0))if(e[n(1334)](e.RlvGV,e[n(1288)])){let W=F[n(863)](":");m&&(f=W[n(1927)]),g+=W.length;for(let Z=0;e.VRopv(Z,W[n(1927)]);Z++)if(e.OlyPx(4,W[Z][n(1927)])){let J=b[n(1049)+"g"](0,4-W[Z][n(1927)]),fe=J.concat(W[Z]);d[n(1655)](fe)}else d[n(1655)](W[Z]);m=!1}else return _0x3ddbc0[n(758)]>=_0x1ae2be[n(1717)];else{if(F[n(1927)]!==4){let W=b.substring(0,e.KLUQc(4,F[n(1927)])),Z=W.concat(F);d[n(1655)](Z)}else d[n(1655)](F);m&&(f+=1),g+=1,m=!1}}let R="";for(let L=0;e[n(1845)](L,e.KLUQc(8,g));L++)R=R.concat(b);for(let L=0;e[n(1845)](L,d.length);L++)e[n(1334)](L,f)&&(s=s.concat(R)),s=s[n(1145)](d[L]);return s}else{let{enableAutoAck:h}=this._options,R=e.imXIN(_0xbbf8d3,_0x1c57c3[n(1829)][n(1712)],e.xkMkW,"1"),L=e[n(930)](_0x15b108,_0x5ad08e[n(1829)][n(1712)],"is_ack","1"),F=_0x30d7f9[n(1027)](this,_0x5a89c9);if(e.RcAyA(h,R)){let{SeqID:W,LogID:Z,service:J,LogIDNew:fe,method:Se}=_0x367edb[n(1829)];this._sendAck({SeqID:W,LogID:Z,LogIDNew:fe,service:J,method:Se,headers:[{key:n(1107),value:"1"},{key:n(1614),value:e.mOnDZ(fe,"")},{key:e.AJxcQ,value:"0"}]})}L&&!F[n(1608)]&&this[n(1400)+"hAckMess"+n(1212)](_0x53d658),_0x290a44()}{let h=a[n(863)](":");for(let R=0;R<h.length;R++){let L=h[R];if(e[n(1961)](4,h[R][n(1927)])){let F=b[n(1049)+"g"](0,e[n(1571)](4,h[R].length)),W=F[n(1145)](L);s=s[n(1145)](W)}else s=s[n(1145)](L)}return s}}function w(a,n){let s=t,d=a[s(1535)];e[s(1629)](void 0,d)&&(e[s(1341)](ue,n,10),e[s(1002)](q,n,d));let f=a[s(1283)];e.sgOsX(void 0,f)&&(e[s(977)](e.QsVDI,s(1492))?(_0x4f6c2c[_0x4a26ed[_0x3c1b31][s(1173)+"ame"]]=_0x20d292(_0x2b362c[_0x3afff5].cursor_name),_0xb441c5+=14+_0x7a5820[_0x19fe95[_0xa80236][s(1173)+"ame"]]):(ue(n,18),e[s(1510)](q,n,f)))}function _(a){let n=t,s={};e:for(;!e[n(1631)](V,a);){let d=e[n(1044)](le,a);switch(d>>>3){case 0:break e;case 1:s[n(1535)]=e[n(1896)](O,a,e[n(1822)](le,a));break;case 2:s[n(1283)]=e[n(519)](O,a,e[n(1631)](le,a));break;default:C(a,e[n(998)](7,d))}}if(e[n(1334)](void 0,s[n(1535)]))throw new Error(n(1326)+n(1157)+n(892)+n(1535));if(e[n(783)](void 0,s[n(1283)]))throw new Error(e[n(1864)]);return s}function I(a){let n=t,s={VvFEd:function(d,f){return d*f}};if(e[n(977)](e[n(577)],n(1182))){let d=D();return e[n(1002)](E,a,d),B(d)}else return MVzbVJ[n(1692)](1e4,_0x5cab6e[n(1464)]())+_0x556394[n(822)](1e4*_0x4ae75c[n(1132)]())}function E(a,n){let s=t,d={TZWQc:function(Se){return e.cdGUx(Se)},SQszB:function(Se,Qe,ht){return Se(Qe,ht)},VwYzz:function(Se,Qe){return e[z(1042)](Se,Qe)}},f=a[s(1553)];e[s(977)](void 0,f)&&(ue(n,8),e[s(507)](ft,n,f));let g=a[s(496)];e[s(977)](void 0,g)&&(e.zwnpV(ue,n,16),e[s(1896)](ft,n,g));let m=a[s(1086)];e[s(1629)](void 0,m)&&(e.PXiNk(ue,n,24),e.mCYeR(ft,n,e.XWTPm(P,m)));let b=a[s(1229)];b!==void 0&&(ue(n,32),ft(n,P(b)));let h=a[s(1712)];if(h!==void 0)for(let Se of h){e.zwnpV(ue,n,42);let Qe=e[s(972)](D);e[s(1896)](w,Se,Qe),e[s(1002)](ue,n,Qe[s(1717)]),j(n,Qe),k(Qe)}let R=a[s(584)+"ncoding"];e.wVzhd(void 0,R)&&(e[s(933)](ue,n,50),e[s(1387)](q,n,R));let L=a["payloadT"+s(1892)];if(e.iGnDI(void 0,L))if(e[s(1334)](e[s(897)],e.MHOgQ)){let Se=vJirfm[s(1194)](_0x5212d2);return vJirfm.SQszB(_0xb199b3,_0x18968d,Se),vJirfm[s(1513)](_0x5991ef,Se)}else e[s(1217)](ue,n,58),e[s(453)](q,n,L);let F=a[s(1625)];if(F!==void 0)if(e[s(1155)](e[s(1139)],e.efwtO))ue(n,66),ue(n,F[s(1927)]),e[s(1337)](he,n,F);else return!!this[s(682)];let W=a[s(1088)];e[s(1370)](void 0,W)&&(e.qWWVH(ue,n,74),e[s(687)](q,n,W));let Z=a[s(1887)+"ming"];e.LelMs(void 0,Z)&&(e.gKSJt(ue,n,82),e.SBjjl(q,n,Z));let J=a[s(782)];e.exvbi(void 0,J)&&(e.iCXuo(ue,n,90),q(n,J));let fe=a[s(1886)+"e"];e[s(1108)](void 0,fe)&&(e[s(1002)](ue,n,96),e[s(1337)](ft,n,P(fe)))}function v(a){return A(e[t(680)](M,a))}function A(a){let n=t,s={};e:for(;!e[n(1044)](V,a);){let d=le(a);switch(e[n(653)](d,3)){case 0:break e;case 1:s[n(1553)]=e[n(1442)](St,a,!0);break;case 2:s.LogID=e[n(1610)](St,a,!0);break;case 3:s[n(1086)]=e.UzmGO(le,a);break;case 4:s[n(1229)]=e[n(1716)](le,a);break;case 5:{let f=S(a);(s[n(1712)]||(s[n(1712)]=[])).push(e[n(1910)](_,a)),a.limit=f;break}case 6:s["payloadE"+n(1901)]=e[n(1486)](O,a,e[n(680)](le,a));break;case 7:s["payloadT"+n(1892)]=e[n(1486)](O,a,e[n(1404)](le,a));break;case 8:s[n(1625)]=e[n(1444)](Ee,a,le(a));break;case 9:s.LogIDNew=e[n(1443)](O,a,e.NHGVo(le,a));break;case 10:s["serverTi"+n(739)]=O(a,le(a));break;case 11:s[n(782)]=e.IRlzK(O,a,le(a));break;case 12:s[n(1886)+"e"]=le(a);break;default:e[n(1341)](C,a,e[n(1824)](7,d))}}if(e[n(1621)](void 0,s[n(1553)]))throw new Error(e[n(837)]);if(e[n(1615)](void 0,s[n(496)]))throw new Error(n(1326)+n(1157)+n(892)+"LogID");if(e.MYXki(void 0,s.service))throw new Error(e[n(1700)]);if(e[n(1621)](void 0,s[n(1229)]))throw new Error(e.RHKyI);return s}function S(a){let n=t;if(e[n(1773)](n(1904),e.wrBtT)){let s=le(a),d=a.limit;return a[n(1717)]=e[n(954)](a[n(758)],s),d}else this[n(682)]?.[n(723)](),this[n(682)]=void 0}function C(a,n){let s=t;switch(n){case 0:for(;e.rorXN(128,e[s(1042)](ie,a)););break;case 2:e[s(581)]($,a,e[s(1042)](le,a));break;case 5:e[s(1376)]($,a,4);break;case 1:e[s(1061)]($,a,8);break;default:throw new Error(e[s(1770)](e.dgVgn,n))}}function P(a){let n=t;return a|=0,{low:a,high:a>>31,unsigned:e[n(1067)](a,0)}}let y=[];function D(){let a=t,n=y[a(767)]();return n?(n[a(758)]=n[a(1717)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function k(a){y[t(1655)](a)}function M(a){return{bytes:a,offset:0,limit:a[t(1927)]}}function B(a){let n=t,s=a[n(1168)],d=a[n(1717)];return e[n(1508)](s[n(1927)],d)?s:s[n(1302)](0,d)}function $(a,n){let s=t,d={zlJvT:e[s(1674)],gGjqt:"offline",RxZoX:e[s(1605)],voFHj:e[s(1294)]};if(e.Uojmq(e[s(1897)],e[s(1897)])){if(e[s(1618)](e.PjORI(a[s(758)],n),a[s(1717)]))throw new Error(e[s(617)]);a[s(758)]+=n}else this[s(1937)+"er"]&&_0x54a50a["addEvent"+s(1441)](d[s(1699)],this[s(640)+s(1192)]),this._isBrowser&&_0x3cfc85[s(1246)+s(1441)](d.gGjqt,this[s(640)+s(1803)]),this._isBrowser&&_0x380a22[s(1246)+"Listener"](d[s(1732)],this[s(1751)+s(1141)]),this[s(1937)+"er"]&&_0x34cf72[s(1246)+s(1441)](d[s(1450)],this[s(1751)+"ageShow"])}function V(a){return a[t(758)]>=a.limit}function te(a,n){let s=t,d=a[s(1168)],f=a[s(758)],g=a.limit,m=e[s(1753)](f,n);if(m>d[s(1927)]){let b=new Uint8Array(e[s(1805)](2,m));b[s(1238)](d),a.bytes=b}return a[s(758)]=m,e[s(1618)](m,g)&&(a[s(1717)]=m),f}function Q(a,n){let s=t,d=a.offset;if(e[s(1580)](d,n)>a[s(1717)])throw new Error(e[s(696)]);return a[s(758)]+=n,d}function Ee(a,n){let s=t,d=e[s(1337)](Q,a,n);return a.bytes[s(1302)](d,d+n)}function he(a,n){let s=t,d=e[s(507)](te,a,n.length);a[s(1168)][s(1238)](n,d)}function O(a,n){let s=t,d={XYLBK:e.tApqh};if(e[s(1621)](s(1380),e[s(1275)])){let f=e[s(900)](Q,a,n),g=String[s(1127)+s(1276)],m=a[s(1168)],b="\uFFFD",h="";for(let R=0;e[s(566)](R,n);R++){let L=m[e[s(1580)](R,f)],F,W,Z,J;e[s(1508)](e[s(918)](128,L),0)?h+=g(L):e.qymfy(e[s(720)](224,L),192)?e.REdks(R+1,n)?h+=b:(F=m[e[s(1353)](R,f)+1],e[s(456)](e[s(1368)](192,F),128)?h+=b:(J=(31&L)<<6|e.SLhxT(63,F),e[s(800)](J,128)?h+=b:(h+=e[s(1264)](g,J),R++))):e[s(1512)](240&L,224)?e[s(1067)](e[s(1580)](R,2),n)?h+=b:(F=m[R+f+1],W=m[R+f+2],(e[s(667)](F,e[s(576)](W,8))&49344)!==32896?h+=b:(J=e.mfCvJ(e[s(667)](e[s(576)](e[s(918)](15,L),12),e[s(1530)](e[s(720)](63,F),6)),e.ZnQCT(63,W)),e[s(566)](J,2048)||J>=55296&&J<=57343?h+=b:(h+=g(J),R+=2))):e[s(1894)](248&L,240)?e[s(1010)](R+3,n)?h+=b:(F=m[e[s(1580)](e[s(818)](R,f),1)],W=m[R+f+2],Z=m[e.QnfHg(e[s(805)](R,f),3)],e[s(1581)](e[s(1223)](e[s(1868)](e[s(1868)](F,e[s(1858)](W,8)),e.bIGFE(Z,16)),12632256),8421504)?h+=b:(J=e[s(1868)](e.iVWfg(e[s(1858)](7&L,18),e[s(576)](e[s(1368)](63,F),12))|e[s(778)](e.wPopQ(63,W),6),e[s(998)](63,Z)),e[s(800)](J,65536)||J>1114111?h+=b:(J-=65536,h+=e.TcIpa(g,e[s(943)](e[s(1780)](J,10),55296),e[s(1439)](e.ZTZNf(1023,J),56320)),R+=3))):h+=b}return h}else this[s(774)](d[s(1020)],_0x2b6e40),this[s(1277)+"eAck"]&&this["onReceiv"+s(548)](_0x4ed7cc)}function q(a,n){let s=t;if(e[s(676)](e[s(1742)],e[s(1742)])){let d=n[s(1927)],f=0;for(let b=0;e.bvACF(b,d);b++){let h=n[s(1120)+"At"](b);e[s(1010)](h,55296)&&e.ZGszF(h,56319)&&b+1<d&&(h=e.KLUQc(e[s(491)](e[s(1039)](h,10),n[s(1120)+"At"](++b)),56613888)),f+=h<128?1:e[s(887)](h,2048)?2:e[s(1053)](h,65536)?3:4}e[s(911)](ue,a,f);let g=te(a,f),m=a[s(1168)];for(let b=0;e[s(1845)](b,d);b++){let h=n.charCodeAt(b);e[s(1672)](h,55296)&&e[s(1678)](h,56319)&&e.OYtYY(b+1,d)&&(h=e[s(1571)](e[s(1579)](h,10)+n[s(1120)+"At"](++b),56613888)),h<128?m[g++]=h:(e.vsPrO(h,2048)?m[g++]=e.rorXN(e[s(1673)](h,6),31)|192:(e[s(1478)](h,65536)?m[g++]=e[s(1868)](h>>12&15,224):(m[g++]=e[s(1786)](e[s(918)](e[s(1646)](h,18),7),240),m[g++]=e[s(1958)](e[s(1646)](h,12),63)|128),m[g++]=e[s(993)](e[s(1646)](h,6),63)|128),m[g++]=e[s(1868)](e.sAkeh(63,h),128))}}else return _0x598da2?this[s(1569)+"E"]():this[s(1676)+"E"]()}function j(a,n){let s=t,d=te(a,n[s(1717)]),f=a[s(1168)],g=n[s(1168)];for(let m=0,b=n[s(1717)];e[s(566)](m,b);m++)f[m+d]=g[m]}function ie(a){let n=t;return a[n(1168)][e[n(474)](Q,a,1)]}function Je(a,n){let s=t,d=e.MMaFE(te,a,1);a[s(1168)][d]=n}function le(a){let n=t,s={IwwBk:function(d,f){return e.zmREX(d,f)},JpIBL:function(d,f){return e[z(662)](d,f)},FDesp:function(d,f){return e.VPgSK(d,f)},NiWHE:function(d,f){return e[z(1858)](d,f)},TsUkS:function(d,f){return e.sjBdG(d,f)},JyCli:function(d,f){return e[z(1773)](d,f)},zJZZQ:function(d,f){return e[z(566)](d,f)},VLkSN:function(d,f){return e[z(1478)](d,f)},FWmyW:function(d,f){return e[z(601)](d,f)},wHBOx:function(d,f,g){return d(f,g)},nKEen:function(d,f){return e[z(818)](d,f)},WKKQS:function(d,f){return e[z(1079)](d,f)},YNsti:function(d,f){return e[z(625)](d,f)},eQrSi:function(d,f){return e.uVluv(d,f)},tMVqf:function(d,f){return e[z(921)](d,f)},YgsPE:function(d,f){return d+f},YQAGo:function(d,f){return e[z(565)](d,f)},bmIIm:function(d,f){return e[z(842)](d,f)},ZnqVU:function(d,f){return e[z(1591)](d,f)},fkAin:function(d,f){return e.UpkPW(d,f)},FrMoR:function(d,f){return e[z(1591)](d,f)},SPZnu:function(d,f){return e[z(648)](d,f)},HmqFO:function(d,f){return d+f},GzpIl:function(d,f){return e[z(648)](d,f)},fMkiz:function(d,f){return e[z(674)](d,f)}};if(e[n(1428)](e[n(1437)],e[n(1437)])){let d=0,f=0,g;do g=e.wnURi(ie,a),e[n(992)](d,32)&&(f|=e[n(1579)](e[n(1563)](127,g),d)),d+=7;while(128&g);return f}else{let d=s[n(1784)](_0x139df9[n(1839)],0),f=s.JpIBL(s.FDesp(_0x1fa98e[n(1839)]>>>28,s.NiWHE(_0x34fd04[n(693)],4)),0),g=s[n(1797)](_0x2e482c.high,24),m=s[n(964)](0,g)?f===0?s[n(1253)](d,16384)?d<128?1:2:s[n(1253)](d,2097152)?3:4:s[n(906)](f,16384)?s.VLkSN(f,128)?5:6:s[n(906)](f,2097152)?7:8:s[n(1372)](g,128)?9:10,b=s.wHBOx(_0x56a786,_0x1dc324,m),h=_0x4d272f[n(1168)];switch(m){case 10:h[s[n(949)](b,9)]=s[n(738)](s[n(1797)](g,7),1);case 9:h[s.YNsti(b,8)]=s[n(688)](9,m)?s.FDesp(128,g):s[n(738)](127,g);case 8:h[s[n(949)](b,7)]=m!==8?s[n(1797)](f,21)|128:s[n(738)](s[n(1522)](f,21),127);case 7:h[s[n(690)](b,6)]=s.eQrSi(7,m)?s[n(885)](f>>>14,128):s[n(759)](f>>>14,127);case 6:h[b+5]=m!==6?f>>>7|128:s[n(734)](f,7)&127;case 5:h[s[n(949)](b,4)]=s.eQrSi(5,m)?s[n(884)](128,f):s[n(738)](127,f);case 4:h[b+3]=s[n(688)](4,m)?s[n(1490)](s[n(1422)](d,21),128):d>>>21&127;case 3:h[s[n(955)](b,2)]=s[n(688)](3,m)?s[n(884)](s[n(1328)](d,14),128):s[n(1062)](d,14)&127;case 2:h[s[n(1169)](b,1)]=m!==2?s[n(885)](s[n(940)](d,7),128):s[n(1062)](d,7)&127;case 1:h[b]=s[n(1691)](1,m)?s[n(885)](128,d):127&d}}}function ue(a,n){let s=t;for(n>>>=0;n>=128;)e[s(1431)](Je,a,e[s(565)](e[s(1079)](127,n),128)),n>>>=7;e[s(1526)](Je,a,n)}function St(a,n){let s=t,d=0,f=0,g=0,m;if(m=e[s(1044)](ie,a),d=e.nVsxa(127,m),e.FJDYh(128,m)&&(m=e.dEoqL(ie,a),d|=e[s(1530)](e[s(1456)](127,m),7),e[s(1824)](128,m)))if(e[s(1665)](s(695),e.Pbime))m=e.nYhEb(ie,a),d|=e[s(576)](e[s(1396)](127,m),14),e[s(1079)](128,m)&&(m=e[s(1912)](ie,a),d|=e[s(1530)](e[s(1147)](127,m),21),128&m&&(m=ie(a),f=127&m,e.XbpWw(128,m)&&(m=ie(a),f|=e[s(778)](127&m,7),e.SpYMC(128,m)&&(m=e[s(1912)](ie,a),f|=e[s(1255)](e.ZnQCT(127,m),14),e[s(701)](128,m)&&(m=e[s(531)](ie,a),f|=(127&m)<<21,e[s(1473)](128,m)&&(e.qymfy(e[s(1234)],e.ltqXQ)?(m=ie(a),g=e[s(1389)](127,m),e[s(1177)](128,m)&&(m=e[s(1128)](ie,a),g|=e[s(1579)](e[s(442)](127,m),7))):_0x59d8cc[s(1211)](_0x3ef5a6)))))));else try{this[s(682)]?.[s(723)](),this[s(682)]=void 0}catch(b){_0x252299[s(1211)](b)}return{low:d|e[s(1858)](f,28),high:e.gPcql(f,4)|e[s(482)](g,24),unsigned:n}}function ft(a,n){let s=t,d=e.HjTjZ(n[s(1839)],0),f=e[s(620)](n[s(1839)]>>>28|e[s(576)](n[s(693)],4),0),g=e[s(1609)](n[s(693)],24),m=e[s(681)](0,g)?f===0?e[s(887)](d,16384)?d<128?1:2:e[s(601)](d,2097152)?3:4:e[s(1133)](f,16384)?e[s(566)](f,128)?5:6:e.ezzjD(f,2097152)?7:8:g<128?9:10,b=e.SDVDw(te,a,m),h=a.bytes;switch(m){case 10:h[b+9]=e[s(726)](e[s(582)](g,7),1);case 9:h[e.CWNbC(b,8)]=m!==9?e[s(565)](128,g):127&g;case 8:h[e[s(954)](b,7)]=m!==8?e[s(1630)](e[s(1591)](f,21),128):e[s(1418)](e.uujDB(f,21),127);case 7:h[e.jXBsr(b,6)]=e[s(718)](7,m)?f>>>14|128:e[s(1771)](f>>>14,127);case 6:h[b+5]=e[s(1689)](6,m)?e[s(1921)](e[s(582)](f,7),128):e[s(998)](f>>>7,127);case 5:h[e.jXBsr(b,4)]=e.FWdMp(5,m)?e[s(1921)](128,f):127&f;case 4:h[e[s(1208)](b,3)]=e[s(1268)](4,m)?e[s(667)](e.XwMej(d,21),128):e[s(1860)](d>>>21,127);case 3:h[e[s(1298)](b,2)]=e[s(1684)](3,m)?e[s(1936)](e[s(633)](d,14),128):e[s(1389)](e[s(1371)](d,14),127);case 2:h[b+1]=e[s(1819)](2,m)?e.VPgSK(d>>>7,128):e[s(1368)](e[s(662)](d,7),127);case 1:h[b]=e.DiLXY(1,m)?e[s(777)](128,d):127&d}}function Xt(a){return e.MBXUs(v,a)}function zt(a){return I(a)}let Qt=65536,Gr=e[t(1560)],me=e[t(527)](Qt,Qt),Ie=me*me,Vn=Ie/2,ke=String[t(910)+"e"][t(1120)+"At"];class ce{constructor(n,s,d){let f=t;this.isLong=!0,this[f(1839)]=e[f(1542)](0,n),this[f(693)]=e[f(1149)](0,s),this.unsigned=!!d}static[t(728)](n){let s=t;return n&&e[s(449)](!0,n[s(728)])}static[t(1199)](n,s,d){return new ce(n,s,d)}static[t(1252)+"s"](n,s,d){let f=t;if(e[f(747)](e[f(1721)],e[f(1752)]))_0x4955c3(_0x5aef78,32),_0x11ef44(_0x4b5c6,e.qcqKi(_0x3c84bb,_0x534d93));else return d?ce["fromByte"+f(1433)](n,s):ce[f(1252)+f(716)](n,s)}static fromBytesLE(n,s){let d=t,f={nEsVs:function(g,m,b){return e[z(581)](g,m,b)},sQfnr:e[d(1774)],wkUSU:function(g,m){return g+m}};if(e[d(1248)](e.vwnVm,d(1038)))return new ce(e[d(565)](e[d(820)](n[0]|e.ArrCe(n[1],8),e[d(1039)](n[2],16)),e[d(1579)](n[3],24)),e[d(1470)](e[d(565)](e[d(1671)](n[4],e[d(790)](n[5],8)),e[d(1039)](n[6],16)),e[d(778)](n[7],24)),s);{let g=_0x114ec6[d(1390)][d(757)](_0x4bba24[d(1233)+"et"],f[d(1702)](_0x414756[d(591)+"th"],_0x45ebe8[d(1233)+"et"]));this[d(1948)]&&this[d(1948)][d(1503)]({data:g,fail:m=>{let b=d;this[b(774)](b(787),f[b(495)](_0x343a8f,f.sQfnr,{message:this["_formatE"+b(1539)+"age"](m)}))}})}}static[t(1252)+t(716)](n,s){let d=t;return new ce(e[d(1947)](e[d(777)](e.VPgSK(e[d(1039)](n[4],24),e[d(1694)](n[5],16)),n[6]<<8),n[7]),e[d(1467)](e[d(1898)](e[d(712)](n[0],24)|e[d(1579)](n[1],16),n[2]<<8),n[3]),s)}static[t(962)](n){let s=t,d={JfbIc:function(f,g){return e.wPopQ(f,g)},TLQvq:function(f,g){return f>>g},obuqY:function(f,g){return e[z(1905)](f,g)},KbMcV:function(f,g){return e[z(1686)](f,g)},GDwGy:function(f,g){return f+g},xvgis:function(f,g){return e[z(778)](f,g)},XAugK:function(f,g){return e[z(1432)](f,g)},RrSWO:function(f,g){return e.MacCZ(f,g)},lvdWL:function(f,g){return e[z(1079)](f,g)}};if(e[s(1137)]===s(1463))return e[s(1665)](n,Gr)?Md:new ce((e.ooniH(ke[s(1027)](n,0),e[s(1587)](ke.call(n,1),8))|e[s(482)](ke[s(1027)](n,2),16)|e.Svehb(ke[s(1027)](n,3),24))>>>0,e.UKODd(e[s(1417)](e[s(777)](ke[s(1027)](n,4),e.bIEbE(ke[s(1027)](n,5),8)),ke[s(1027)](n,6)<<16)|e[s(576)](ke[s(1027)](n,7),24),0),!0);{let f=("3|5|1|2|"+s(512))[s(863)]("|"),g=0;for(;;){switch(f[g++]){case"0":_0x144615[_0x1be131++]=d.JfbIc(d.TLQvq(_0x1ada03,6),63)|128;continue;case"1":_0xbbd360[_0x5420f1++]=d[s(1640)](_0x15190f>>18,240);continue;case"2":_0x11e2d0[_0x47ef3f++]=d[s(932)](d.JfbIc(d[s(942)](_0x3e368d,12),63),128);continue;case"3":_0x3ff231=d[s(770)](65536+d[s(544)](d[s(959)](1023,_0xccc508),10),d[s(1111)](1023,_0x4f8a03));continue;case"4":_0xa0a1d4[_0x37d12d++]=d.RrSWO(d[s(1210)](63,_0x276f66),128);continue;case"5":++_0x58b616;continue}break}}}[t(1009)](){let n=t;return String.fromCharCode(e[n(918)](255,this.low),e.nznTZ(e[n(1336)](this[n(1839)],8),255),e.nVsxa(e[n(582)](this[n(1839)],16),255),e.zmREX(this[n(1839)],24),e[n(1501)](255,this[n(693)]),e.ZmJXv(this[n(693)],8)&255,e[n(1501)](e[n(662)](this[n(693)],16),255),e[n(1609)](this[n(693)],24))}static fromNumber(n,s=!0){let d=t;if(e[d(1689)](e[d(730)],d(806))){let f=_0x2259c1[d(1049)+"g"](0,e.KLUQc(4,_0x2eafce[_0x27d7df][d(1927)])),g=f[d(1145)](_0x244201);_0x5697b7=_0x6a8fc[d(1145)](g)}else{if(e[d(1262)](isNaN,n))return s?Fh:Md;if(s){if(e[d(1672)](n,Ie))return Gh}else{if(n<=-Vn)return qh;if(e[d(943)](n,1)>=Vn)return Uh}return ce[d(1199)](e[d(1542)](n%me,0),e.sNbay(n/me,0),s)}}toNumber(){let n=t,s={DmKAa:function(d,f){return e[z(1334)](d,f)},GQGJr:function(d,f){return e[z(800)](d,f)},XJmeX:function(d,f){return d===f}};if(e[n(1508)](e[n(1300)],e[n(1865)])){if(s[n(1054)](void 0,_0x2f5762))this[n(1130)+"rs"]={};else if(_0x2fee86===void 0)this[n(1130)+"rs"][_0x3d860f]=null;else{let d=this[n(1130)+"rs"][_0x5dc0de];if(d)for(let f=0;s[n(1040)](f,d.length);)s.XJmeX(d[f].fn,_0xb858d8)?d[n(644)](f,1):++f}return this}else return this[n(1739)]?e[n(1805)](this[n(693)]>>>0,me)+e[n(648)](this[n(1839)],0):e[n(1737)](this[n(693)]*me,e[n(1272)](this[n(1839)],0))}[t(683)](){let n=t;return e[n(1165)](0,this[n(693)])&&e.tMpNW(0,this.low)}[t(1325)](n){let s=t,d={jfocO:function(f,g){return e[z(1846)](f,g)},uxMCd:function(f,g){return f==g},FdWLH:s(1762)+s(983)+s(1537)};if(e[s(1689)](e[s(803)],s(857))){ce[s(728)](n)||(n=ce[s(1750)+"er"](n));let f=e[s(1329)](this[s(693)],16),g=e[s(1318)](65535,this.high),m=this[s(1839)]>>>16,b=e.SpYMC(65535,this.low),h=n[s(693)]>>>16,R=e[s(1788)](65535,n[s(693)]),L=e.JXUJX(n[s(1839)],16),F=65535&n[s(1839)],W=0,Z=0,J=0,fe=0;return fe+=e[s(954)](b,F),J+=e[s(1888)](fe,16),fe&=65535,J+=e[s(1401)](m,L),Z+=J>>>16,J&=65535,Z+=e.yYIxw(g,R),W+=e.eyhnA(Z,16),Z&=65535,W+=e[s(1439)](f,h),W&=65535,ce[s(1199)](e[s(1148)](J<<16,fe),e[s(1908)](e[s(1530)](W,16),Z),this.unsigned)}else{let{url:f}=d[s(1017)](_0x2731cf,{}),g=_0x528a89.isArray(f)?f:d[s(1195)](s(1394),typeof f)?[f]:[];_0xac29dc&&_0x323734.assign(this._options,_0x2942d6),g&&g[s(1927)]?this[s(1516)+"tManager"]=new _0x8d010(g,this[s(1754)][s(1593)+"es"]):this[s(1516)+s(1271)]?.[s(772)+s(920)+s(1436)](),this["_pingLos"+s(1670)]?.[s(1069)+"nter"](this[s(1754)][s(788)+s(1934)]),this._readyClosed=!1,this._ws&&this._ws[s(1331)+"te"]!==this[s(650)]?this[s(810)+s(1634)](1e3,d[s(802)],!0):(this[s(1843)]=!0,this[s(547)]())}}equals(n){let s=t;return ce[s(728)](n)||(n=ce[s(1750)+"er"](n)),e.icCdt(this.unsigned,n[s(1739)])&&e[s(1723)](e[s(1609)](this[s(693)],31),1)&&e[s(1802)](e.OELpQ(n[s(693)],31),1)?!1:e.jyvJP(this[s(693)],n.high)&&e[s(504)](this[s(1839)],n.low)}[t(1240)](){let n=t;return e.qymfy(-1,this[n(1839)])&&this[n(693)]===-1?ce[n(1199)](0,0,this[n(1739)]):e[n(1615)](-1,this[n(1839)])?ce.fromBits(0,e[n(1393)](this.high,1),this[n(1739)]):ce[n(1199)](e[n(818)](this[n(1839)],1),this.high,this[n(1739)])}[t(1427)](n){let s=t;if(e[s(977)](s(1842),e[s(513)]))return n?this[s(1569)+"E"]():this[s(1676)+"E"]();ZXTXGV.VJTYo(_0x99a5ac,_0x2bc6d6[s(787)]),ZXTXGV[s(972)](_0xe1fe74)}[t(1569)+"E"](){let n=t;if(e[n(1248)](e[n(1379)],n(764))){let s=this[n(693)],d=this[n(1839)];return[e[n(1828)](255,d),e[n(1563)](d>>>8,255),e[n(1561)](e[n(1371)](d,16),255),e[n(1371)](d,24),e.aetUL(255,s),e[n(1311)](s,8)&255,e[n(1105)](s,16)&255,e[n(953)](s,24)]}else return this[n(682)]?.[n(1238)]({message_id:_0x479c29,timestamp:_0x2534ae})}[t(1676)+"E"](){let n=t,s=this[n(693)],d=this.low;return[e[n(1105)](s,24),s>>>16&255,e[n(918)](e[n(1297)](s,8),255),e.QRcUg(255,s),e[n(1280)](d,24),e[n(1787)](d,16)&255,e[n(534)](e[n(1247)](d,8),255),e[n(720)](255,d)]}}let Md=new ce(0,0,!1),Fh=new ce(0,0,!0),Uh=ce[t(1199)](-1,2147483647,!1),Gh=ce[t(1199)](-1,-1,!0),qh=ce[t(1199)](0,-2147483648,!1);var en=(function(a){let n=t,s=e[n(664)].split("|"),d=0;for(;;){switch(s[d++]){case"0":a[a[n(1143)+"OR"]=5005]=e[n(1541)];continue;case"1":return a;case"2":a[a[n(1475)+"RROR"]=5001]=e.kYFtD;continue;case"3":a[a[n(1928)+n(1793)]=5002]=n(1928)+"NG_ERROR";continue;case"4":a[a[n(1109)+n(707)+"R"]=5003]=e[n(477)];continue;case"5":a[a[e[n(1366)]]=5004]=e.CvfcW;continue}break}})({});class Jn{constructor(n){let s=t;this[s(1101)]=n,this[s(1911)]=null}}class Bd extends Jn{constructor(n,s){let d=t;super(n),this.message=s&&s[d(1829)]||null}}class zd extends Jn{constructor(n,s){let d=t;if(e[d(623)](e[d(1744)],e[d(1744)])){let f=(d(561)+"5|1|4").split("|"),g=0;for(;;){switch(f[g++]){case"0":this[d(787)]=s&&s[d(787)]||null;continue;case"1":this.message=s&&s[d(1829)]||"";continue;case"2":this[d(1160)]=s&&s[d(1160)]||0;continue;case"3":this[d(978)]=s&&s[d(978)]||"";continue;case"4":this.code=s&&s[d(1601)]||5001;continue;case"5":this[d(812)]=s&&s.lineno||0;continue;case"6":super(n);continue}break}}else e[d(755)](_0x3d3635,_0x10e37d,10),_0x2d4664(_0x44a4fe,_0x33d06c)}}class Fd extends Jn{constructor(n,s){let d=t,f=e[d(1136)][d(863)]("|"),g=0;for(;;){switch(f[g++]){case"0":super(n);continue;case"1":this.willReconnect=s&&s["willReco"+d(1076)]||!1;continue;case"2":this[d(881)]=s&&s.wasClean||!1;continue;case"3":this.code=s&&s[d(1601)]||0;continue;case"4":this[d(516)]=s&&s.reason||"";continue}break}}}class Ud extends Jn{constructor(n,s){let d=t;super(n),this.data=s&&s[d(1876)]||null}}class Gd extends Ud{constructor(n,s){let d=t;super(n),this.data=s&&s[d(1876)]||null,this.message=s&&s.message||null}}class qd extends Jn{constructor(n,s){let d=t;super(n),this[d(1876)]=s&&s[d(1876)]||null}}function ot(a,{message:n,code:s,error:d}){let f=t;if(e[f(504)](f(838),e[f(1015)])){let g=e[f(549)](_0x136649,e[f(1774)],{message:this[f(827)+f(1539)+f(898)](_0x193dc7)});this[f(774)](e[f(1774)],g);let m=e[f(687)](_0x20705d,f(723),{reason:this[f(827)+"rrorMess"+f(898)](_0x1e35de)});this[f(774)](e[f(756)],m)}else return new zd(a,{message:n,code:s,error:d})}function xt(a,{code:n,reason:s,wasClean:d,willReconnect:f}){return new Fd(a,{code:n,reason:s,wasClean:d,willReconnect:f})}function Hd(a,{data:n,message:s}){return new Gd(a,{data:n,message:s})}function jd(a,{data:n}){return new qd(a,{data:n})}function ra(a,{message:n}){return new Bd(a,{message:n})}class Wd{constructor(n,s){let d=t;this[d(1818)+"s"]=n,this[d(1593)+"es"]=s,this[d(1080)+d(1755)]=0,this[d(1880)+"ndpointT"+d(847)+"t"]=0}[t(772)+t(920)+t(1436)](){let n=t;this.currentIndex=0,this["currentEndpointT"+n(847)+"t"]=0}[t(705)+"es"](){let n=t;this["currentE"+n(1289)+n(847)+"t"]=0}["getCurre"+t(461)+"nt"](){let n=t;if(e[n(472)](n(735),e[n(466)])){let s=this[n(1130)+"rs"][_0x1b2048];if(s)s[n(757)]().forEach(d=>d.fn[n(1765)](d[n(574)],_0x210314));else if(e.paXuG("error",_0x385337)&&!this.onerror){let d=_0x3dc73e.length&&_0x5e35c7[0];if(d instanceof _0x259b4a)throw d;let f=new _0x2446c0(e.vbyTX+(d?e[n(491)](" (",d[n(1829)])+")":""));throw f[n(669)]=d,d}return this}else return this[n(1818)+"s"][this[n(1080)+"ndex"]]}[t(1558)+t(461)+"ntTriesCount"](){let n=t;return this[n(1880)+n(1289)+n(847)+"t"]}[t(1094)+t(1100)+"es"](){let n=t;return!!(e.innzK(this[n(1080)+"ndex"],this[n(1818)+"s"][n(1927)])||e[n(1705)](this[n(1080)+n(1755)],e[n(1571)](this[n(1818)+"s"][n(1927)],1))&&this[n(1880)+"ndpointT"+n(847)+"t"]===this[n(1593)+"es"])}[t(1878)+t(446)+t(1278)+t(985)+t(1588)](){let n=t;return this[n(1080)+n(1755)]==this[n(1818)+"s"][n(1927)]?!0:this[n(1880)+n(1289)+n(847)+"t"]>this.maxRetries}["replaceBackupEnd"+t(1257)+t(571)+"unt"](){let n=t;return this[n(1880)+n(1289)+n(847)+"t"]=1,this[n(1080)+n(1755)]++,this[n(1818)+"s"][this[n(1080)+n(1755)]]}["getCurre"+t(461)+t(579)+"ateCount"](){let n=t;return this[n(1880)+n(1289)+n(847)+"t"]++,this[n(1558)+n(461)+"nt"]()}}let Zn=(e[t(1619)](e[t(1024)],typeof globalThis)&&e[t(1773)](e[t(1585)],globalThis[t(1821)+t(1544)][t(1767)])||e.fbOnQ(e.CmhPt,typeof window)&&e[t(1457)](e.WSoyC,window[t(1821)+t(1544)][t(1767)]))&&e[t(986)](e[t(1024)],typeof document),An=e[t(1024)]!=typeof globalThis&&(e[t(917)]===globalThis[t(1821)+t(1544)][t(1767)]||e[t(1285)]===globalThis[t(1821)+t(1544)].name)&&e[t(529)](e.CmhPt,typeof tt),qr=(t(645)+"d"!=typeof globalThis&&e.PoOPd(e[t(917)],globalThis[t(1821)+t(1544)][t(1767)])||e.OFQug(t(645)+"d",typeof globalThis)||e.pAiaG(e[t(1024)],typeof globalThis)&&!!globalThis[t(841)+t(1458)])&&e[t(1619)](e.CmhPt,typeof wx),Hr=e[t(529)](e[t(1024)],typeof globalThis)&&(e[t(1285)]===globalThis[t(1821)+t(1544)].name||e[t(1165)](t(1274)+t(1381)+t(969),globalThis[t(1821)+t(1544)][t(1767)])||e[t(886)](e.SojQd,globalThis[t(1821)+t(1544)][t(1767)]))&&e[t(1024)]!=typeof self,Hh=e[t(1914)](e[t(1024)],typeof globalThis)&&e.BMJcf(e[t(917)],globalThis[t(1821)+t(1544)][t(1767)])&&e.pAiaG(e[t(1024)],typeof global)&&e.BMJcf(t(634),global[t(1821)+t(1544)][t(1767)])&&e[t(1024)]!=typeof process&&!!process.version;class ia{constructor(){let n=t;this[n(1130)+"rs"]={}}[t(774)](n,...s){let d=t,f=this[d(1130)+"rs"][n];if(f)f.slice()[d(1549)](g=>g.fn[d(1765)](g[d(574)],s));else if(e[d(504)](d(787),n)&&!this[d(1016)]){let g=s[d(1927)]&&s[0];if(e[d(1095)](g,Error))throw g;let m=new Error(e.boSMK(d(564)+d(1715),g?e[d(943)](e[d(912)](" (",g[d(1829)]),")"):""));throw m[d(669)]=g,g}return this}[t(1440)](n,s){let d=t;if(e[d(679)](void 0,n))this[d(1130)+"rs"]={};else if(e[d(637)](void 0,s))this[d(1130)+"rs"][n]=null;else{let f=this[d(1130)+"rs"][n];if(f)for(let g=0;e[d(1218)](g,f[d(1927)]);)e[d(1498)](f[g].fn,s)?f.splice(g,1):++g}return this}on(n,s,d){let f=t,g={NlcXs:function(m,b){return e[z(1695)](m,b)},gYljn:function(m,b){return e[z(576)](m,b)},NZMcs:function(m,b){return e.aetUL(m,b)},MXEpS:function(m,b){return m<<b},ZTACg:function(m,b){return m<b},XDfsW:function(m,b){return e[z(1067)](m,b)},oNOpv:function(m,b){return e[z(1807)](m,b)},qqNux:function(m,b){return e[z(1654)](m,b)}};if(e[f(1903)]===e[f(1945)])_0x42e5aa=wWBFHD[f(860)](wWBFHD[f(1889)](wWBFHD.NZMcs(15,_0x5e2dcc),12),wWBFHD[f(1347)](wWBFHD.NZMcs(63,_0x27bda9),6))|wWBFHD[f(691)](63,_0x3b0172),wWBFHD[f(966)](_0x2cbb94,2048)||wWBFHD[f(1848)](_0x163739,55296)&&wWBFHD.oNOpv(_0x49553f,57343)?_0x32c2d2+=_0x1dbe57:(_0x3e82c2+=wWBFHD.qqNux(_0x6f5c07,_0x339fbd),_0x3c86c9+=2);else return(this[f(1130)+"rs"][n]||(this[f(1130)+"rs"][n]=[]))[f(1655)]({fn:s,ctx:d||this}),this}}class jh extends ia{[t(827)+t(1539)+t(898)](n){let s=t;return n[s(658)]||n[s(702)]?(s(1933)+" "+(n[s(658)]||"")+s(1540)+(n.errNo||""))[s(1728)]():JSON[s(722)+"y"](n)}constructor(n,s,d){let f=t;super(),this._socket=null,qr&&wx[f(958)+f(1575)]&&(this._socket=wx[f(958)+f(1575)]({url:n,protocols:s,header:d,fail:this[f(1789)+f(851)+"lHandler"][f(938)](this),success:this["_createS"+f(934)+"cessHand"+f(971)].bind(this)})),An&&tt[f(958)+f(1575)]&&(this._socket=tt[f(958)+f(1575)]({url:n,protocols:s,header:d,fail:this[f(1789)+f(851)+"lHandler"].bind(this),success:this["_createSocketSuc"+f(1645)+f(971)][f(938)](this)}))}[t(1789)+t(934)+t(1645)+t(971)](){let n=t;Promise[n(946)]()[n(929)](()=>{this["_addWsLi"+n(485)]()})}["_createS"+t(851)+t(1346)](n){let s=t;Promise[s(946)]()[s(929)](()=>{let d=s,f=e[d(1443)](ot,e[d(1774)],{message:this["_formatE"+d(1539)+"age"](n)});this.emit(d(787),f);let g=e[d(1295)](xt,e[d(756)],{reason:this[d(827)+"rrorMessage"](n)});this[d(774)](e[d(756)],g)})}["_addWsLi"+t(485)](){let n=t,s={JBzZL:e[n(1666)],qaqCD:function(d,f,g){return e[n(1179)](d,f,g)},jivYs:function(d,f){return e[n(1428)](d,f)},QyMEp:e[n(1323)],BvhtJ:e.izaOc};this[n(1948)].onOpen(d=>{let f=n;this[f(774)](s[f(889)],s[f(878)](jd,s.JBzZL,{...d,data:d.errMsg||""}))}),this._socket[n(489)](d=>{let f=n;this[f(774)](e[f(756)],xt(e[f(756)],{...d}))}),this._socket.onMessage(d=>{let f=n;if(s[f(1814)](s[f(1806)],"lxaxs"))this[f(774)](s[f(1592)],Hd(s[f(1592)],{...d}));else return _0xe2e5c8+=_0x17e8de&&_0x3161e3[f(591)+"th"]||0,_0x3a27af}),this[n(1948)][n(666)](d=>{let f=n;this.emit(e.qjdtI,e.rmQAX(ot,e[f(1774)],{...d,message:d[f(658)]||""}))})}[t(1503)](n){let s=t;if(e[s(715)](n,Uint8Array)){let d=n[s(1390)].slice(n[s(1233)+"et"],e[s(1355)](n[s(591)+"th"],n[s(1233)+"et"]));this[s(1948)]&&this[s(1948)][s(1503)]({data:d,fail:f=>{let g=s;this[g(774)]("error",ot(e[g(1774)],{message:this["_formatE"+g(1539)+"age"](f)}))}})}else this._socket&&this[s(1948)][s(1503)]({data:n,fail:d=>{let f=s;this[f(774)](e[f(1774)],e.PXiNk(ot,e[f(1774)],{message:this[f(827)+f(1539)+f(898)](d)}))}})}[t(723)](n,s){let d=t;this[d(1948)]&&this._socket[d(723)]({code:n,reason:s})}[t(1246)+t(1441)](n,s){this.on(n,s)}[t(1854)+t(1790)+"ner"](n,s){let d=t;e[d(501)](e.GKIRq,e.uceKe)?(this[d(768)+d(621)+d(1446)]=_0x34458f,_0x1e2d61?this[d(640)+"nLine"]():this[d(640)+d(1803)]()):this.off(n,s)}get[t(1331)+"te"](){let n=t;return this[n(1948)][n(1331)+"te"]}get binaryType(){let n=t;return this[n(1948)][n(1555)+"pe"]}set[t(1555)+"pe"](n){}get url(){let n=t;return e[n(1485)](e.XAsPS,e[n(1729)])?this[n(682)][n(1338)]:this[n(1948)][n(813)]}get[t(781)](){return this[t(1948)].protocol}get[t(1642)+"ns"](){return this._socket.extensions}get[t(1884)+"Amount"](){return 0}}function Wh(a,n){let s=t;if(n)return new n(a.url,a[s(781)]);if(qr||An)return new jh(a[s(813)],a[s(781)],a[s(1712)]);if(e[s(1846)](Zn,Hr)&&e.KAtNs(e[s(1024)],typeof WebSocket)&&WebSocket)return new WebSocket(a.url,a.protocols)}function Kh(a){let n=t;return!!(a||qr&&wx["connectS"+n(1575)]||An&&tt["connectS"+n(1575)]||(Zn||Hr)&&e[n(1024)]!=typeof WebSocket&&WebSocket)}function Kd(a,n,s){let d=t,f={ToIbh:function(b,h){return e[z(896)](b,h)},uGHHH:e[d(583)],UOUaL:function(b,h){return e.DYhIL(b,h)}},g=-1;async function m(b){let h=d;return f.ToIbh(b,g)?Promise[h(569)](new Error(f[h(1830)])):(g=b,b===s[h(1927)]?Promise[h(946)]():s[b][h(938)](a)(n,m.bind(null,f[h(1258)](b,1))))}e.oWDeG(m,0)}function $d(a){let n=t,s=0,d=0;for(let f=0;e[n(1696)](f,a[n(1927)]);++f)if(d=a[n(1120)+"At"](f),d<128)s+=1;else if(e[n(1053)](d,2048))s+=2;else if(e[n(1334)](64512&d,55296)&&e.mgyPC(64512,a[n(1120)+"At"](e[n(607)](f,1)))===56320)if(e.khrJv(e[n(1178)],n(1187))){if(!this[n(547)+n(1811)]){let g=(n(1663)+"0")[n(863)]("|"),m=0;for(;;){switch(g[m++]){case"0":this[n(547)]();continue;case"1":this[n(741)+n(1670)]?.["resetCou"+n(1589)]();continue;case"2":this[n(1516)+n(1271)]?.[n(772)+n(920)+n(1436)]();continue;case"3":this[n(1036)+n(1296)]=!1;continue;case"4":this[n(1843)]=!0;continue}break}}}else++f,s+=4;else s+=3;return s}function Vd(a,n,s){let d=t;if(e.PYbgm(d(1837),e.qlOYi))return this[d(1818)+"s"][this["currentI"+d(1755)]];{if(e[d(1571)](s,n)<1)return"";let f="";for(let g=n;e[d(887)](g,s);){let m=a[g++];if(e[d(1807)](m,127))f+=String[d(1127)+"Code"](m);else if(e.PlUID(m,192)&&m<224)f+=String.fromCharCode(e[d(925)](e[d(1877)](31,m)<<6,e[d(1501)](63,a[g++])));else if(e.PlUID(m,224)&&e[d(1256)](m,240))f+=String[d(1127)+d(1276)](e[d(712)](e[d(1561)](15,m),12)|e.ArrCe(e[d(1185)](63,a[g++]),6)|e[d(872)](63,a[g++]));else if(m>=240){let b=e[d(1571)](e[d(1151)](e[d(1506)](e[d(1368)](7,m),18)|e[d(1517)](63&a[g++],12),e[d(1506)](e[d(980)](63,a[g++]),6))|e[d(1177)](63,a[g++]),65536);f+=String[d(1127)+d(1276)](55296+e.zkHqO(b,10)),f+=String[d(1127)+d(1276)](56320+e[d(1877)](1023,b))}}return f}}function sa(a,n,s){let d=t,f={yJuyM:function(h,R){return h<R},CrQsW:function(h,R){return e[z(1716)](h,R)}},g=s,m,b;for(let h=0;e[d(694)](h,a.length);++h)if(m=a[d(1120)+"At"](h),m<128)n[s++]=m;else if(e.OlURJ(m,2048))n[s++]=e[d(1397)](m,6)|192,n[s++]=e[d(1235)](e[d(1456)](63,m),128);else if((64512&m)===55296&&e.MYXki(e[d(1772)](64512,b=a[d(1120)+"At"](e[d(1554)](h,1))),56320)){let R=e.sxqab[d(863)]("|"),L=0;for(;;){switch(R[L++]){case"0":n[s++]=e[d(517)](63,m)|128;continue;case"1":n[s++]=e[d(1646)](m,12)&63|128;continue;case"2":n[s++]=e[d(1786)](e.eYRey(m,6)&63,128);continue;case"3":n[s++]=e[d(1905)](m>>18,240);continue;case"4":m=e[d(639)](e.aGxEF(65536,e[d(1411)](e[d(1563)](1023,m),10)),e[d(893)](1023,b));continue;case"5":++h;continue}break}}else if(e[d(1206)]===e[d(1206)])n[s++]=m>>12|224,n[s++]=e.RbokL(e.IjFhw(e[d(533)](m,6),63),128),n[s++]=e[d(1339)](e[d(720)](63,m),128);else{let R=0,L={};for(let F=0;f.yJuyM(F,_0x631c6e.length);F++)L[_0x42e1c3[F][d(1173)+d(931)]]=f[d(1356)](_0x1f6889,_0x27b309[F][d(1173)+"ame"]),R+=14+L[_0xda0ef1[F]["cursor_n"+d(931)]];return[R,L]}return e[d(1571)](s,g)}async function Jd(a){let n=t;if(e[n(1965)](e[n(1628)],typeof a)){let s=new Uint8Array(e[n(1912)]($d,a));return sa(a,s,0),s}return e[n(1095)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(1390)],a.byteOffset,a[n(591)+"th"])}function $h(a){let n=t;try{return typeof a!="string"&&(a instanceof ArrayBuffer||a[n(1390)]&&a[n(1390)]instanceof ArrayBuffer)||e[n(1628)]!=typeof a?"":(JSON[n(1866)](a),n(868)+"ion/json")}catch{return e[n(1628)]==typeof a?e.BtLiS:""}}let Vh=(a,n)=>{let s=t;switch(a){case e[s(1449)]:case e[s(1879)]:return{[s(1226)+a]:1,"x-tt-env":n};default:return{}}};class Jh{constructor(n){let s=t;this[s(1384)+s(880)]=n,this[s(1134)]=0}[t(1749)](){this.count++}[t(1094)+t(541)+"nt"](){let n=t;return e[n(1010)](this.count,this[n(1384)+n(880)])}["resetCou"+t(1589)](n=0){let s=t,d={Olemr:e[s(1774)],kDZcE:function(f,g,m){return f(g,m)}};e[s(974)](e.nxGDu,e[s(1756)])?(this["maxLossC"+s(880)]=n,this[s(1134)]=0):this[s(774)](SMhsuQ[s(689)],SMhsuQ.kDZcE(_0x2beb1e,SMhsuQ[s(689)],{..._0x23472e,message:_0x7d28ff[s(658)]||""}))}}async function Zh(a){let n={bdaJC:e.GMJGJ};return new Promise(s=>{let d=z;if(!Zn)return e[d(1103)](s,e[d(1617)]);try{let f=document[d(1546)+d(895)](e[d(919)]);window.frontierJSONP=g=>{let m=d;document[m(1902)][m(1317)+"ild"](f),window[m(1239)+m(1840)]=void 0,s(g&&g.msg||n[m(834)])},f.type="text/javascript",f.src=e[d(1316)](a[d(588)](/^ws/,e[d(836)]),e[d(1471)]);try{document[d(1902)][d(1115)+d(698)](f)}catch{document[d(1902)][d(1317)+d(698)](f)}}catch{window[d(1239)+d(1840)]=void 0,e[d(1262)](s,e[d(1617)])}})}function tn(a,n,s){let d=t;return!!a?.[d(1775)](f=>f[d(1535)]===n&&f[d(1283)]===s)}function Yn(a,n){let s=t;return a?.[s(1775)](d=>d[s(1535)]===n)?.[s(1283)]}let oa=null;async function Yh(){let a=t,n={pgYoF:function(s,d){return e.bJdEL(s,d)}};if(e.qcSjU("HNkAb",e.yZwFt)){let s=this[a(1055)+"Queue"].reduce((d,f)=>(d+=f&&f[a(591)+"th"]||0,d),0);return n[a(737)](s,this._ws?this[a(1096)][a(1884)+a(1022)]:0)}else return oa||(oa=Promise[a(946)]()[a(929)](Nt[a(938)](Nt,e[a(499)]))),oa}class Xh extends ia{constructor(n,s){let d=t;super(),this[d(846)]=n,this[d(1826)]=s,this[d(682)]=void 0,this[d(817)+"mise"]=null}async openDB(){await this[t(1801)]()}async[t(1801)](){let n=t,s={HFMot:function(d){return e[z(1188)](d)}};if(e[n(1029)]===e[n(1029)]){if(this[n(682)])return;if(this["_initPro"+n(990)])return this[n(817)+"mise"];try{let d=this[n(846)],f=this[n(1826)];this._initPromise=(async()=>{let g=n,{openDB:m}=await s[g(600)](Yh);this._qosDB=await m(g(1239)+"_"+d,1,{upgrade(b){let h=g;b[h(1152)+h(1048)+"e"](d,{keyPath:f})}})})(),await this[n(817)+n(990)]}catch(d){console[n(1211)](d)}finally{this[n(817)+n(990)]=null}}else{if(_0x849670)return new _0x4fe7b8(_0x57a078[n(813)],_0x3b3d9f.protocol);if(e[n(1846)](_0x5a86c1,_0xd84853))return new _0x4dcc6e(_0x375a44[n(813)],_0x3c8c0c[n(781)],_0x1d2773[n(1712)]);if(e[n(1846)](_0xdb52db,_0x5a73ec)&&n(645)+"d"!=typeof _0xdeea19&&_0x269b0c)return new _0x4e9884(_0x325515[n(813)],_0x19acaa.protocols)}}async[t(1577)](n){let s=t;try{return await this[s(1801)](),this[s(682)]?.[s(1577)](this[s(846)],n)}catch(d){console[s(1211)](d)}}async[t(1238)](n,s){let d=t;return e[d(1562)]===d(1531)?this._socket[d(781)]:(await this[d(1801)](),this[d(682)]?.[d(743)](this._dbName,n))}async del(n){let s=t;try{return await this[s(1801)](),this[s(682)]?.[s(839)](this._dbName,n)}catch(d){console[s(1211)](d)}}async[t(1600)](){let n=t;try{return await this[n(1801)](),this[n(682)]?.[n(1600)](this[n(846)])}catch(s){if(e[n(951)](e[n(502)],e[n(502)]))console[n(1211)](s);else return this[n(1839)]===-1&&this[n(693)]===-1?_0x15458c[n(1199)](0,0,this.unsigned):this[n(1839)]===-1?_0x63b32[n(1199)](0,e[n(665)](this[n(693)],1),this[n(1739)]):_0x430906[n(1199)](this[n(1839)]+1,this[n(693)],this[n(1739)])}}async[t(1632)](){let n=t;return await this[n(1801)](),this[n(682)]?.[n(655)+"ys"](this[n(846)])}async getAll(){let n=t;if(e[n(1727)](e[n(1073)],"jGnhk"))return await this[n(1801)](),this[n(682)]?.getAll(this._dbName);this[n(1384)+n(880)]=_0x4787f0,this[n(1134)]=0}async[t(710)](){let n=t;try{this[n(682)]?.[n(723)](),this[n(682)]=void 0}catch(s){console[n(1211)](s)}}get[t(1338)](){let n=t;try{return!!this._qosDB}catch(s){return console[n(1211)](s),!1}}}class Qh{constructor(n,s){let d=t;this._DBName=n,this[d(1200)]=s,this[d(682)]=localStorage}async[t(1940)](){}get _prefix(){return t(1239)+"_"+this._DBName}async[t(1577)](n){let s=t,d={QCMKR:function(f){return e[z(525)](f)}};if(e[s(1108)](e[s(1856)],s(1066))){let f=this[s(682)][s(1395)](this[s(554)]);return JSON[s(1866)](e[s(1846)](f,"{}"))[n]}else return this[s(1400)+s(500)+s(1112)](_0x3a558e),d[s(801)](_0x431c78)}async[t(1238)](n,s){let d=t,f=this[d(682)].getItem(this[d(554)]),g=JSON[d(1866)](e[d(1846)](f,"{}"));return g[s||n[this[d(1200)]]]=n,this._qosDB[d(1198)](this._prefix,JSON[d(722)+"y"](g)),s||n[this._pathKey]}async[t(465)](n){let s=t,d=this._qosDB[s(1395)](this._prefix),f=JSON[s(1866)](e[s(1846)](d,"{}"));return f[n]=void 0,this._qosDB.setItem(this[s(554)],JSON[s(722)+"y"](f))}async[t(1600)](){let n=t,s={AlpVM:e[n(1774)],GkBYq:function(d,f,g){return d(f,g)},gAABg:function(d,f){return e[n(715)](d,f)}};if(e[n(783)](n(952),e.StbgZ))if(QXJAYT[n(1028)](_0x5c5af8,_0x42e468)){let d=_0x150a9d[n(1390)].slice(_0x5d5bde.byteOffset,_0x27ca0e[n(591)+"th"]+_0x26241a[n(1233)+"et"]);this._socket&&this[n(1948)][n(1503)]({data:d,fail:f=>{let g=n;this.emit(QXJAYT[g(1603)],_0x3633c6(QXJAYT[g(1603)],{message:this[g(827)+g(1539)+g(898)](f)}))}})}else this._socket&&this._socket.send({data:_0x378298,fail:d=>{let f=n;this.emit(f(787),QXJAYT[f(797)](_0x585deb,f(787),{message:this["_formatE"+f(1539)+f(898)](d)}))}});else return this[n(682)].clear()}async[t(1632)](){let n=t,s=this[n(682)][n(1395)](this[n(554)]),d=JSON[n(1866)](s||"{}");return Object.keys(d)}async[t(612)](){let n=t,s=this[n(682)][n(1395)](this[n(554)]),d=JSON[n(1866)](e[n(1121)](s,"{}"));return Object[n(874)](d)}[t(710)](){return Promise.resolve()}get[t(1338)](){return!!this[t(682)]}}class ep{constructor(n,s){let d=t;this._DBName=n,this[d(1200)]=s,this._qosDB=An?tt:qr?wx:null}async[t(1940)](){}get[t(554)](){return t(1239)+"_"+this._DBName}async[t(1577)](n){let s=t,d=this[s(682)][s(1033)+s(1711)](this[s(554)]);return JSON[s(1866)](e.VPciQ(d,"{}"))[n]}async set(n,s){let d=t,f=this[d(682)][d(1033)+d(1711)](this[d(554)]),g=JSON.parse(f||"{}");return g[s||n[this[d(1200)]]]=n,this[d(682)]["setStora"+d(1711)](this[d(554)],JSON[d(722)+"y"](g)),s||n[this[d(1200)]]}async[t(465)](n){let s=t,d=this._qosDB[s(1033)+s(1711)](this[s(554)]),f=JSON[s(1866)](e[s(1191)](d,"{}"));return f[n]=void 0,this[s(682)][s(1013)+s(1711)](this[s(554)],JSON.stringify(f))}async[t(1600)](){let n=t;return this._qosDB[n(968)+n(1547)]()}async[t(1632)](){let n=t,s=this[n(682)][n(1033)+n(1202)+"nc"](this[n(554)]),d=JSON.parse(e[n(1319)](s,"{}"));return Object[n(1632)](d)}async[t(612)](){let n=t,s=this[n(682)]["getStora"+n(1202)+"nc"](this[n(554)]),d=JSON.parse(e[n(1191)](s,"{}"));return Object[n(874)](d)}[t(710)](){return Promise[t(946)]()}get[t(1338)](){return!!this[t(682)]}}function Zd(a,n){let s=t;if(e[s(1701)](An,An))return new ep(a,n);if((Zn||Hr)&&e[s(1619)](e[s(1024)],typeof indexedDB))return new Xh(a,n);if((Zn||Hr)&&e[s(684)](e.CmhPt,typeof localStorage))return new Qh(a,n);throw new Error("init QoS"+s(1923)+"d")}class tp{constructor(){let n=t;this[n(616)+n(1559)+"Id"]=null,this[n(616)+"l"]=36e5,this[n(682)]=e[n(717)](Zd,e[n(630)],e[n(870)])}async[t(616)+"lFlush"](){let n=t,s={TLDbd:function(d,f){return e.rJaTo(d,f)},NdQxr:function(d,f){return e.diozI(d,f)},cAbLb:function(d,f){return d(f)},NsKPr:function(d,f,g){return d(f,g)},CDHxV:function(d){return d()}};if(e[n(1369)](e.NBCqu,e[n(1351)]))e[n(1941)](clearInterval,this["_interva"+n(1559)+"Id"]),this[n(616)+n(1559)+"Id"]=e[n(1282)](setInterval,()=>{this.flushExpired()},this._interval);else return typeof _0x1c0cf9===n(1502)?vYWUmM[n(510)](_0x28f966,_0x1500ff):(vYWUmM[n(1135)](_0x2d9d07,_0x592f19)&&vYWUmM[n(994)](_0x41a1dc,_0x514441),vYWUmM[n(1231)](_0x210bc6,_0x3f9312,vYWUmM[n(1488)](_0x38852c))?new _0x4adbe6(_0x19a998,_0x45b06a):_0x5c23fc)}async[t(1940)](){let n=t,s={rlmWw:function(d,f){return d===f},ngFFF:n(1703)};await this[n(682)][n(1940)]()[n(929)](()=>{let d=n,f={GLXyt:function(g,m){return g(m)}};if(s[d(1050)](s[d(567)],s[d(567)]))this[d(616)+"lFlush"]();else return function(...g){let m=d;return _0x1b21b6[m(1765)](KFYAFn[m(671)](_0x45ea5d,this),g),_0x1a443d(_0x147cbb[m(1577)](this))}})}async[t(901)+t(861)](){let n=t;(await this[n(682)]?.[n(612)]()||[])[n(816)](({timestamp:f})=>f<Date.now())[n(1549)](f=>{let g=n;this[g(682)]?.[g(465)](f[g(1570)+"id"])})}async[t(465)](n){let s=t;return this[s(682)]?.[s(465)](n)}async[t(1238)](n,s){let d=t,f={Uerlf:function(g,m,b){return e[z(1483)](g,m,b)}};if(e[d(1244)]!==e[d(1244)]){let g=XrnfaG[d(1413)](_0x4a7c21,_0x5c404c,1);_0xa6f85e[d(1168)][g]=_0x2bd51d}else return this[d(682)]?.[d(1238)]({message_id:n,timestamp:s})}async[t(1577)](n){let s=t;return this[s(682)]?.[s(1577)](n)}async closeDB(){let n=t;e[n(1509)](clearInterval,this[n(616)+n(1559)+"Id"]),await this[n(682)]?.[n(710)]()}get isReady(){let n=t;return this[n(682)]?.[n(1338)]}}function aa(a){let n=t,s=!!this[n(1754)].enableQoS;if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let d=e.imXIN(tn,a[n(1829)][n(1712)],e[n(1785)],"2"),f=d&&tn(a[n(1829)][n(1712)],e.XpzkD,"1"),g=d&&e.imXIN(tn,a[n(1829)][n(1712)],e[n(1465)],"1"),m=g?Yn(a.message[n(1712)],e.SjcKT)?.[n(863)](",")[n(816)](Boolean)||[]:[];return{enabled:s,isQoSMessage:d,isQoSAck:f,isAckCleanupMessage:g,ackMsgIds:m}}async function Yd(){let a=t;return this[a(1176)+a(1776)]||(this._QoSManager=new tp),this["_QoSMana"+a(1776)][a(1338)]||await this[a(1176)+a(1776)].openDB(),this[a(1176)+a(1776)]}async function np(a,n){let s=t;if(e[s(1142)](s(853),s(853)))_0x113b1a[_0x14c565++]=e[s(1456)](e.uBpom(_0x3389c0,18),7)|240,_0x569a38[_0x50e9e1++]=e[s(1759)](e[s(1652)](e[s(1646)](_0x125f0b,12),63),128);else{let{enableAutoAck:d}=this[s(1754)],f=tn(a[s(1829)].headers,s(1871),"1"),g=e[s(704)](tn,a.message.headers,e.XDFYs,"1"),m=aa[s(1027)](this,a);if(d&&f){let{SeqID:b,LogID:h,service:R,LogIDNew:L,method:F}=a.message;this[s(1736)]({SeqID:b,LogID:h,LogIDNew:L,service:R,method:F,headers:[{key:"is_ack",value:"1"},{key:"ack_id",value:e.dUnas(L,"")},{key:e.AJxcQ,value:"0"}]})}g&&!m[s(1608)]&&this[s(1400)+s(1557)+"ageEvent"](a),e.XrMYY(n)}}async function rp(a,n){let s=t;this[s(1207)](e.kgMmN,a.message),e[s(972)](n)}async function ip(a,n){let s=t,d={fvOjv:function(g,m){return e[z(1398)](g,m)},DxfCg:function(g,m){return e[z(974)](g,m)}},f=Xt(await e[s(1941)](Jd,a[s(1876)]));try{if(e.UXFDu(f[s(1625)],Uint8Array))if(e[s(1689)](s(647),s(1627))){let g=e[s(713)](this._options[s(584)+s(1901)],Object)?{force:!!this[s(1754)][s(584)+s(1901)][s(840)],encoding:this[s(1754)][s(584)+s(1901)][s(1743)]?this[s(1754)]["payloadE"+s(1901)][s(1743)][s(588)](/\s/g,"")[s(936)+"ase"]():""}:{force:!1,encoding:this[s(1754)][s(584)+s(1901)]?this[s(1754)]["payloadE"+s(1901)][s(588)](/\s/g,"")[s(936)+"ase"]():""},m=f.payloadEncoding?f["payloadE"+s(1901)][s(588)](/\s/g,"")[s(936)+s(1320)]():"",b=e[s(715)](this._options[s(1607)+s(1892)],Object)?{force:!!this[s(1754)].payloadType[s(840)],type:this[s(1754)][s(1607)+s(1892)].type?this._options["payloadT"+s(1892)][s(1101)][s(588)](/\s/g,"")["toLowerC"+s(1320)]():""}:{force:!1,type:this[s(1754)][s(1607)+s(1892)]?this[s(1754)][s(1607)+"ype"][s(588)](/\s/g,"")[s(936)+"ase"]():""},h=f["payloadT"+s(1892)]?f[s(1607)+"ype"].replace(/\s/g,"")[s(936)+s(1320)]():"",R=b[s(840)]?b.type:h||b[s(1101)],L=g.force?g[s(1743)]:m||g.encoding,F=[e.BtLiS,e[s(1378)],e[s(622)],e[s(1628)]],W=[e[s(618)],e[s(1836)]];this[s(1754)][s(1087)+"ansformT"+s(1552)+"ad"]&&F.includes(R)&&(!L||W[s(654)](L))?f[s(1322)+s(1480)]=e[s(663)](Vd,f.payload,0,f.payload[s(591)+"th"]):f["textPayl"+s(1480)]=""}else{let g=_0x19b302[s(863)](":");_0x3c67ed&&(_0x2961f9=g[s(1927)]),_0x5f5b02+=g[s(1927)];for(let m=0;ekwTCU[s(1340)](m,g[s(1927)]);m++)if(ekwTCU[s(1197)](4,g[m][s(1927)])){let b=_0x1ec747[s(1049)+"g"](0,4-g[m][s(1927)]),h=b[s(1145)](g[m]);_0x3c8c7e[s(1655)](h)}else _0x16075a.push(g[m]);_0x106c5a=!1}else f[s(1322)+s(1480)]=""}catch(g){f.textPayload="",console.log(g)}a.message=f,e.cdGUx(n)}function sp(a,n,s){let d=t,f={JFYZT:function(R,L){return e[z(1852)](R,L)},gvpzb:d(1213),snXKP:function(R,L){return e.FiYUa(R,L)},nSSls:function(R,L){return e.ZeDpb(R,L)},gWWyF:function(R,L){return e[d(1770)](R,L)},GPRnt:function(R,L){return e[d(1759)](R,L)}},g=s||8192,m=g>>>1,b=null,h=g;return function(R){let L=d;if(f.JFYZT(f.gvpzb,L(1213))){if(R<1||R>m)return f[L(1350)](a,R);f[L(944)](f[L(1915)](h,R),g)&&(b=f[L(1350)](a,g),h=0);let F=n.call(b,h,h+=R);return 7&h&&(h=f[L(1915)](f.GPRnt(7,h),1)),F}else this[L(1384)+L(880)]=_0x7687dd,this[L(1134)]=0}}let op=4294967295;function ap(a,n,s){let d=t;return e.SxOpZ(RangeError,e[d(805)](e.MuaKN(e[d(670)](e[d(1335)](e[d(1698)](e[d(1291)],a),e[d(1293)]),e.lEXdw(n,1)),e[d(1722)]),s))}function cp(a,n,s){let d=t,f={qotTx:function(m,b){return e[z(967)](m,b)},vetgh:function(m,b){return m+b},xDyEI:function(m,b){return e[z(1208)](m,b)},hJiWe:function(m,b){return e[z(1772)](m,b)},mragY:function(m,b){return m<<b},kkwoq:function(m,b){return m|b},FQuHM:function(m,b){return e.UbWMm(m,b)},aeFYu:function(m,b){return e[z(1349)](m,b)},lMAyy:function(m,b){return e[z(1174)](m,b)},KgQSa:function(m,b){return m<=b},DZskG:function(m,b){return e[z(624)](m,b)}};if(s>op)throw new Error(e[d(602)]);let g=3;for(;e[d(832)](g,0);)if(e.BFFmC(e[d(1068)],"HyycO"))_0x547f44=_0x164478[wQxpzX[d(866)](wQxpzX[d(866)](_0x665b9c,_0x5e289a),1)],_0x1cb081=_0x1eb26d[wQxpzX[d(844)](wQxpzX.xDyEI(_0x424237,_0x123b09),2)],wQxpzX[d(779)](_0x48b85f|wQxpzX.mragY(_0x7e2390,8),49344)!==32896?_0x42be74+=_0x1739c3:(_0x129939=wQxpzX.kkwoq(wQxpzX.FQuHM(wQxpzX[d(779)](15,_0x402a67)<<12,wQxpzX[d(773)](63&_0x309c96,6)),wQxpzX[d(779)](63,_0x250a6b)),wQxpzX[d(1938)](_0x25d1d2,2048)||_0x56a12e>=55296&&wQxpzX[d(733)](_0xc282b8,57343)?_0x1b8fe7+=_0x4cc21f:(_0x236d48+=wQxpzX[d(1918)](_0x2df1bd,_0x3988e1),_0x4b09c9+=2));else{let m=e[d(1768)](255,s);e.vPYRj(da,m,a,n+g),s>>>=8,g--}return n+4}function dp(a,n){let s=t,d=0,f=n,g=n+4;for(;e.auumU(f,g);){let{value:m,offset:b}=ca(a,f);f=b,d=e[s(953)](e.vSZqd(d,8),0),d+=m}return{value:d,offset:g}}function lp(a,n,s){let d=t;if(e.cBSFl==="bCLKG"){let f=e[d(511)].split("|"),g=0;for(;;){switch(f[g++]){case"0":if(n.write)return n.write(a,s)+s;continue;case"1":if(a[d(1927)]<40)return e[d(1401)](sa(a,n,s),s);continue;case"2":return e[d(1737)](sa(a,n,s),s);case"3":if(!a)return s;continue;case"4":if(n[d(1324)+"e"])return e[d(1401)](n[d(1324)+"e"](a,s),s);continue}break}}else{let{value:f,offset:g}=_0x5e754f(_0xf3431f,_0x33471f);_0x1347ff=g,_0x206864=e[d(518)](e[d(1349)](_0x2dd9f0,8),0),_0x563e18+=f}}function up(a,n){let s=t,d=new ce(e[s(1124)](e[s(593)](a[n+4],24)|a[e[s(1580)](n,5)]<<16|a[e.saaZZ(n,6)]<<8,a[e[s(1875)](n,7)]),e[s(667)](e[s(1714)](e.hzAyF(a[e.CWNbC(n,0)],24),a[e[s(498)](n,1)]<<16)|e[s(526)](a[n+2],8),a[e[s(954)](n,3)]),!0);return n+=8,{value:d,offset:e[s(1757)](n,8)}}function fp(a,n,s){let d=t,f={QdcpS:function(g,m){return g||m}};if(e[d(1370)](e.aOTkA,e[d(1783)])){let g=this[d(682)][d(1033)+d(1711)](this[d(554)]);return _0x544961[d(1866)](rKONVf[d(1416)](g,"{}"))[_0x3d24a3]}else{let g=a[d(1839)],m=a.high;return n[s]=e.XptHw(m,24),n[e[d(1770)](s,1)]=e.cOIWe(e[d(1171)](m,16),255),n[e[d(1445)](s,2)]=m>>>8&255,n[e[d(609)](s,3)]=e[d(1652)](255,m),n[e[d(967)](s,4)]=g>>>24,n[e[d(1636)](s,5)]=e[d(444)](g>>>16,255),n[e[d(1698)](s,6)]=e[d(1828)](e[d(1227)](g,8),255),n[e[d(1872)](s,7)]=e[d(709)](255,g),s+=8,s}}function ca(a,n){let s=t;return a.readUInt8?{value:a[s(1267)+"8"](n),offset:e[s(464)](n,1)}:{value:e[s(872)](255,a[n]),offset:e[s(1445)](n,1)}}function da(a,n,s){let d=t;return n[d(1281)+"t8"]?n.writeUint8(a,s):n[s]=e[d(1432)](255,a),s+1}let xp=function(a){return new Uint8Array(a)},hp=e[t(1024)]!=typeof Buffer?Buffer[t(871)+t(708)]:e[t(659)](sp,xp,Uint8Array[t(910)+"e"][t(1302)]),pp=16,la=32;function gp(a){let n=t,s={GThGr:n(714)+"in;charset=utf-8",JoxPN:e[n(1378)],Gnzfo:n(868)+n(1882)+n(451)+n(555),nayVN:e[n(1628)],trJHj:e[n(618)],SicoF:function(d,f,g,m){return e.Exizk(d,f,g,m)}};if(n(979)!==e[n(1093)]){let d=this[n(1754)][n(584)+"ncoding"]instanceof _0x2899ce?{force:!!this[n(1754)][n(584)+n(1901)].force,encoding:this[n(1754)][n(584)+n(1901)][n(1743)]?this[n(1754)][n(584)+n(1901)][n(1743)][n(588)](/\s/g,"")[n(936)+"ase"]():""}:{force:!1,encoding:this._options[n(584)+n(1901)]?this._options[n(584)+n(1901)][n(588)](/\s/g,"")[n(936)+n(1320)]():""},f=_0x319eae[n(584)+n(1901)]?_0x4b1ee8[n(584)+"ncoding"][n(588)](/\s/g,"")[n(936)+"ase"]():"",g=this[n(1754)][n(1607)+"ype"]instanceof _0x3e650c?{force:!!this[n(1754)]["payloadT"+n(1892)][n(840)],type:this[n(1754)][n(1607)+"ype"].type?this[n(1754)]["payloadT"+n(1892)][n(1101)][n(588)](/\s/g,"")[n(936)+n(1320)]():""}:{force:!1,type:this._options["payloadT"+n(1892)]?this[n(1754)][n(1607)+n(1892)][n(588)](/\s/g,"")["toLowerC"+n(1320)]():""},m=_0x435904["payloadT"+n(1892)]?_0x43da96[n(1607)+n(1892)].replace(/\s/g,"")[n(936)+n(1320)]():"",b=g[n(840)]?g[n(1101)]:m||g[n(1101)],h=d[n(840)]?d[n(1743)]:f||d.encoding,R=[SKkKlk.GThGr,SKkKlk.JoxPN,SKkKlk[n(643)],SKkKlk[n(751)]],L=[SKkKlk[n(1823)],n(543)];this[n(1754)][n(1087)+n(1415)+"extPayload"]&&R[n(654)](b)&&(!h||L[n(654)](h))?_0x1f45c5[n(1322)+"oad"]=SKkKlk[n(573)](_0x4d3e19,_0x94c63a[n(1625)],0,_0x2285af[n(1625)][n(591)+"th"]):_0x334a6f[n(1322)+n(1480)]=""}else{let d=0,f={};for(let g=0;e[n(1375)](g,a[n(1927)]);g++)f[a[g][n(1173)+n(931)]]=$d(a[g][n(1173)+"ame"]),d+=e[n(491)](14,f[a[g][n(1173)+n(931)]]);return[d,f]}}function Xd(a,n,s){let d=t,[f,g]=e[d(819)](gp,a),m=e.NHGVo(hp,f),b=0;return a[d(1549)](h=>{let R=d,L=(R(542)+R(1500)+"10|4|6")[R(863)]("|"),F=0;for(;;){switch(L[F++]){case"0":console[R(1211)](e[R(706)],b);continue;case"1":console[R(1211)](R(989)+R(1767),b);continue;case"2":b=lp(h[R(1173)+R(931)],m,b);continue;case"3":console[R(1211)](R(1086),b);continue;case"4":b=fp(ce[R(1750)+"er"](h.cursor||n),m,b);continue;case"5":b=e[R(704)](cp,m,b,h[R(1086)]||0);continue;case"6":console[R(1211)](e[R(1051)],b);continue;case"7":console[R(1211)](e[R(1924)],h,h[R(1086)]);continue;case"8":b=e[R(1861)](da,g[h[R(1173)+R(931)]],m,b);continue;case"9":b=da(0,m,b);continue;case"10":console.log(e[R(1960)],b);continue}break}}),{frameType:la,headers:[{key:e[d(1594)],value:s}],payload:m}}function mp(a){let n=t,s=0,d=[];for(;e.kKwwf(s,a[n(591)+"th"]);){let{offset:f}=e[n(911)](ca,a,s);s=f;let g={cursor_name:"",cursor:0,service:0},{value:m,offset:b}=e[n(1669)](dp,a,s);g.service=m,s=b;let{value:h,offset:R}=e[n(1232)](ca,a,s);s=R,g[n(1173)+n(931)]=e[n(1518)](Vd,a,s,s+h),s+=h;let{value:L,offset:F}=up(a,s);g.cursor=L.toNumber(),s=F,d[n(1655)](g)}return d}function wp(){let a=t;return{frameType:la,headers:[{key:e[a(1594)],value:a(1815)+a(1939)}],payload:void 0}}class _p{constructor(n,s,d){let f=t;this[f(1056)+f(1354)]=n,this[f(1310)+"ileName"]=s,this[f(1055)+"Strategy"]=d,this[f(682)]=e[f(1442)](Zd,this[f(1056)+"ameSpace"],e[f(988)])}async openDB(){let n=t;await this[n(682)][n(1940)]()}async getCursors(){let n=t;if(e[n(1964)]!==e[n(1804)]){if(!this[n(682)][n(1338)])return;let s=this[n(1055)+"Strategy"],d=await this[n(682)][n(612)]();switch(console.log("allCursorValues",d),s){case e.gWVHM:return d&&d[n(1927)]?e[n(1144)](Xd,d,0,this[n(1310)+"ileName"]):void 0;case e[n(692)]:return;case e[n(987)]:return d&&d[n(1927)]?Xd(d,0,this[n(1310)+"ileName"]):wp()}}else this[n(1843)]=!0,this[n(547)]()}async[t(1238)](n,s,d){let f=t,g={UlJRD:function(m,b){return e.PqfXq(m,b)},dnzSU:function(m,b){return e.lqOTl(m,b)},LVehf:function(m,b){return e[z(1772)](m,b)},QbGcQ:function(m,b){return m<b},WgvBC:function(m,b){return e[z(1618)](m,b)},vpTpN:function(m,b,h){return m(b,h)},MZMzk:function(m,b){return e[z(1186)](m,b)},ugBLI:function(m,b){return e[z(1393)](m,b)},sotJg:function(m,b){return e[z(1312)](m,b)}};if(e[f(894)](e[f(1528)],e[f(1287)]))_0x9cd3ae=BMffWj.UlJRD(BMffWj[f(1345)](BMffWj.LVehf(7,_0x27585b),18)|BMffWj[f(1345)](63&_0x320b78,12)|BMffWj[f(1795)](63,_0x16b581)<<6,63&_0x127dd2),BMffWj.QbGcQ(_0x4efbd3,65536)||BMffWj[f(1037)](_0x1810d5,1114111)?_0x8d0bb3+=_0x86a324:(_0x1c9a60-=65536,_0x133dd1+=BMffWj[f(1740)](_0x35f85c,BMffWj[f(1741)](_0x2bc4da,10)+55296,BMffWj[f(939)](BMffWj[f(732)](1023,_0x51228f),56320)),_0x5e7ce4+=3);else return console[f(1211)](e[f(1778)],n,s,d),this[f(682)][f(1238)]({cursor_name:n,cursor:s,service:d})}async setCursors(n){let s=t,d=e.DyUkV(mp,n);for(let f of d)console[s(1211)](e.YYKiY,d),await this[s(682)][s(1238)](f)}async get(n){let s=t;return(await this[s(682)].get(n))?.[s(1307)]}async[t(710)](){let n=t;if(e[n(793)](n(1245),e[n(524)]))await this[n(682)][n(710)]();else{let s=this[n(1516)+n(1271)]?.["getCurre"+n(461)+"nt"]();this[n(1400)+n(1800)+n(963)](e[n(506)](_0x3395b1,e[n(756)],{code:1006,reason:n(1653)+s+(n(1730)+n(1113)+n(480)+n(1190)),wasClean:!0}))}}[t(1533)+"rsorFile"+t(1377)](n){let s=t,d={qpyOL:function(f,g){return e[z(486)](f,g)},sEAcD:function(f,g){return e[z(1672)](f,g)},qfgXM:function(f,g){return f<=g},iIPRQ:function(f,g){return e[z(1126)](f,g)},cGoSy:function(f,g){return e[z(1362)](f,g)},vtPnf:function(f,g){return f%g},nQUWp:function(f,g){return e[z(1151)](f,g)},cagRe:function(f,g){return e[z(1661)](f,g)}};if(e[s(1852)](e[s(1263)],e[s(1263)]))this[s(1310)+"ileName"]=n;else{if(ZQZOTz[s(1031)](_0x17a338,_0x2bd5d3))return _0x341c84?_0x1da618:_0x55a858;if(_0xc3c951){if(ZQZOTz[s(1484)](_0x24916d,_0x2824f3))return _0x37a5fe}else{if(ZQZOTz[s(1792)](_0x5ee103,-_0x14dede))return _0x26cb1d;if(ZQZOTz[s(1484)](ZQZOTz[s(821)](_0x37e3e4,1),_0x2b6da3))return _0x30b897}return _0xab4996[s(1199)](ZQZOTz.cGoSy(ZQZOTz[s(996)](_0x18fe7d,_0x2e91dc),0),ZQZOTz.nQUWp(ZQZOTz[s(1568)](_0x3bd77e,_0x12c029),0),_0x4f6f1b)}}get[t(1338)](){let n=t;return this[n(682)][n(1338)]}}let yp=e.gNFHB;async function Qd(a){let n=t,s={kSTKs:function(d,f){return d(f)},rJdCM:function(d){return d()}};if(e[n(922)](e[n(515)],e.PYPTm)){if(!this[n(1754)][n(724)+"S"])return null;let{aID:d,fpID:f,messageStrategy:g}=this[n(1754)],m=e.KfqHq(a,yp);try{return this[n(661)+n(1365)]?a&&this[n(661)+n(1365)][n(1533)+n(552)+n(1377)](a):this["_cursorM"+n(1365)]=new _p(f+"_"+d+"_"+m,m,g),this[n(661)+n(1365)][n(1338)]||await this[n(661)+"anager"][n(1940)](),this[n(661)+n(1365)]}catch{return null}}else _0x149e46(fIeyEG.kSTKs(_0x5e1ad2,_0x5b47d4.result)),fIeyEG[n(1942)](_0xdc9a52)}async function Ep(a,n){let s=t,d={NNwbt:function(Z,J){return e[z(1430)](Z,J)}},f=e[s(1001)](tn,a[s(1829)][s(1712)],e[s(1766)],"-1"),g=e[s(1468)](tn,a[s(1829)][s(1712)],e[s(780)],"1"),m=e[s(1610)](Yn,a[s(1829)][s(1712)],s(1690)+s(1116)),b=e.UzmGO(Number,Yn(a[s(1829)][s(1712)],e[s(1624)]))||0,h=aa[s(1027)](this,a),R=e[s(930)](tn,a[s(1829)][s(1712)],e[s(807)],"2"),L=Yn(a[s(1829)][s(1712)],s(1584)+"rsor_name"),F=e[s(1574)](Number,e[s(1444)](Yn,a[s(1829)][s(1712)],e[s(855)]));if(h[s(1608)])return e[s(525)](n);let W=h[s(1342)+"sage"]?await Yd[s(1027)](this):null;if(a[s(1829)].service>0&&g&&!f||a[s(1829)][s(1086)]>0){if(m&&h.isQoSMessage&&W)return!!!await W[s(1577)](m)&&(this["_dispatchMessage"+s(1112)](a),await W.set(m,e.DYhIL(Date[s(1464)](),b))),n();if(R){let Z=await Qd[s(1027)](this);if(!Z)if(e[s(1863)]===e[s(1649)]){let fe=this[s(682)]["getStora"+s(1202)+"nc"](this[s(554)]),Se=_0x246bc1[s(1866)](Hiekti[s(1851)](fe,"{}"));return _0x3d3e18[s(874)](Se)}else return this[s(1400)+"hMessage"+s(1112)](a),e[s(1399)](n);let J=await Z.get(L)??-1;if(e[s(601)](J,F))if(e[s(1626)](s(1452),e[s(1883)])){let fe=_0x2af5b7[s(1168)],Se=_0x318656[s(758)],Qe=_0xf52ccd[s(1717)],ht=Se+_0x5a4604;if(e[s(1618)](ht,fe.length)){let Yi=new _0x4998ce(2*ht);Yi.set(fe),_0x488f4f[s(1168)]=Yi}return _0x34f4a4[s(758)]=ht,e[s(1469)](ht,Qe)&&(_0x31e67a.limit=ht),Se}else this[s(1400)+s(500)+s(1112)](a),Z[s(1238)](L,F,a[s(1829)][s(1086)]);else throw new Error(s(1047)+s(619)+s(752)+F+(s(891)+s(950)+s(1225)+"r ")+J);return e[s(1188)](n)}return this[s(1400)+s(500)+s(1112)](a),n()}}async function bp(a,n){let s=t,d=aa.call(this,a);if(!d[s(1342)+s(1424)])return e[s(1188)](n);let f=await Yd[s(1027)](this);if(d[s(447)+"anupMess"+s(898)]&&d.ackMsgIds[s(1927)])for(let g of d[s(660)+"s"])await f[s(465)](g);e.tmQlZ(n)}async function vp(a,n){let s=t;if(e[s(1367)]("kgsoc",e[s(824)]))return this[s(1880)+s(1289)+s(847)+"t"];{let d=e.VQmmj(a[s(1829)][s(1886)+"e"],pp),f=e.qcSjU(a.message[s(1886)+"e"],la);if(!d&&!f)return e.GPOJb(n);let g=Yn(a[s(1829)][s(1712)],s(626)+s(1117));if(!g)return e.Usxxg(n);let m=await Qd[s(1027)](this,g);if(!m)return e[s(525)](n);if(d){let b=await m[s(1167)+"rs"](),h={frameType:b?.[s(1886)+"e"],SeqID:ce.fromNumber(this[s(1920)]++),LogID:ce[s(1750)+"er"](this[s(1754)][s(1154)+s(1203)]()),service:9e3,method:5,headers:b?.headers,payload:b?.[s(1625)]},R=e[s(1833)](I,h);this[s(1096)]&&this[s(1096)][s(1331)+"te"]&&this[s(1096)].send(R)}if(f)if(e[s(1248)](e[s(799)],e[s(799)]))this[s(1096)]&&this[s(1096)][s(1503)](_0x3a19d4),this["_message"+s(636)][_0x1a3609]=null;else{let b=a[s(1829)][s(1625)];b&&m[s(1420)+"rs"](b)}}}let Sp=async function(a,n){let s=t;this[s(1843)]=!1,e[s(1820)](clearTimeout,this[s(547)+s(1708)+s(869)]),n()},Ap=async function(a,n){let s=t;if(!this._ws||e[s(445)](this[s(1096)][s(1331)+"te"],this[s(649)]))return e.XrMYY(n);let{pingInterval:d}=this._options;this[s(1516)+s(1271)]?.[s(772)+s(920)+"fig"]();for(let g=0;g<this[s(1055)+s(636)][s(1927)];g++){let m=this._messageQueue[g];if(e[s(1498)](this._ws[s(1331)+"te"],this[s(649)])&&e[s(1599)](null,m))this[s(1096)]&&this._ws[s(1503)](m),this[s(1055)+s(636)][g]=null;else break}this[s(1055)+s(636)]=this[s(1055)+s(636)][s(816)](g=>!!g),this["_pingPon"+s(545)+"Id"]=e[s(1874)](setTimeout,()=>this._ping(),d),this[s(1400)+s(748)+"nt"](a),this[s(1937)+"er"]&&this[s(1096)]&&(this[s(1096)].binaryType=this[s(1966)+s(1892)]);let f=this[s(1516)+"tManager"]?.[s(1558)+s(461)+"nt"]();this[s(1207)](s(1758)+f+s(909)),e.UWFup(n)},Ip=async function(a,n){let s=t,d=this[s(1516)+s(1271)]?.[s(1558)+"ntEndpoint"]();this._debug("open "+d),e[s(1399)](n)};class Tp extends ia{constructor(n){let s=t,d={nliEo:e[s(756)],jHCaX:function(b,h,R){return e[s(697)](b,h,R)},ejtXy:e[s(1774)],dfBRJ:e[s(1666)]};super(),this[s(768)+s(621)+s(1446)]=!0,this[s(1937)+"er"]=Zn,this._isNode=Hh,this[s(1841)+"T"]=An,this._isMiniWX=qr,this._isWorker=Hr,this[s(1055)+s(636)]=[],this[s(1516)+s(1271)]=null,this[s(1036)+"osed"]=!1,this[s(1966)+s(1892)]=s(1110)+"fer",this["_connect"+s(1811)]=!1,this[s(547)+"ionTimeo"+s(869)]=null,this["_reconne"+s(721)+"tId"]=null,this[s(843)+s(545)+"Id"]=null,this[s(1920)]=0,this._isInit=!1,this[s(493)]="",this[s(1176)+s(1776)]=null,this[s(661)+s(1365)]=null,this[s(741)+"sCounter"]=null,this[s(651)+"ls"]=e[s(1222)],this[s(650)]=3,this[s(1928)+"NG"]=0,this[s(649)]=1,this[s(935)]=2,this[s(1373)]=b=>{let h=s;if(e.wDNzA(h(1916),e[h(740)]))try{e[h(982)](Kd,this,b,[Sp,Ap,Ip])}catch(R){let L=e.yWjVw(ot,e[h(1774)],{message:R[h(1829)],code:en.OPEN_ERROR,error:R});this["_dispatc"+h(873)+h(963)](L)}else this[h(774)](d[h(1292)],_0xc5d1e1),this[h(1590)]&&this[h(1590)](_0x310d13)},this[s(1407)+"ge"]=async b=>{let h=s,R={OxLeU:h(1829),lSNob:function(W,Z,J){return e.ezkOY(W,Z,J)}},{pingInterval:L,pingFrequency:F}=this[h(1754)];if((b[h(1876)]==="hi"&&e.ZWxyk===F||e[h(1615)](e[h(629)],F))&&(this["_clearPi"+h(528)](),this[h(774)](h(1243)+h(1075)+"s",e[h(1172)]),this._pingPongTimeoutId=e[h(1477)](setTimeout,this[h(668)][h(938)](this),L)),!e[h(1457)]("hi",b[h(1876)]))try{e[h(462)](Kd,this,b,[ip,np,bp,vp,Ep,rp])}catch(W){if(e.eINTD!==h(923)){let Z=e[h(1242)](ot,e.qjdtI,{message:W[h(1829)],code:en[h(771)+"ERROR"],error:W});this[h(1400)+h(873)+"ent"](Z)}else this[h(774)](IaEdGA[h(1104)],IaEdGA[h(1763)](_0x48cd77,IaEdGA.OxLeU,{..._0x1700de}))}},this[s(1057)]=b=>{let h=s,R=this[h(1516)+h(1271)]?.[h(1094)+h(1100)+"es"](),L=this[h(1516)+h(1271)]?.[h(1558)+h(461)+"nt"]();if(R&&!b[h(1829)]){let F="connect "+L+(h(1576)+"ax retri"+h(594)+"ed");this[h(1400)+"hErrorEv"+h(963)](d[h(1313)](ot,d[h(850)],{message:F,code:en[h(1109)+h(707)+"R"],error:b}));return}this._ws&&this[h(1096)].readyState===this[h(649)]&&this[h(810)+h(1634)](),this[h(1400)+h(873)+h(963)](d[h(1313)](ot,d[h(850)],{message:b.message,code:en[h(1475)+h(1491)],error:b}))},this[s(1083)]=async b=>{let h=s;this[h(854)+h(1421)](),this[h(1895)+h(528)](),this["_removeW"+h(563)+"rs"](),this[h(1096)]=null,this[h(547)+h(1811)]=!1;let R=this["_endpoin"+h(1271)]?.[h(1094)+h(1100)+"es"]();if(!R&&this["_navigat"+h(1189)]()&&!this[h(1036)+"osed"]){let L=this[h(1516)+"tManager"]?.["getCurre"+h(461)+"nt"](),F=this[h(1754)][h(775)+h(914)+h(611)](b[h(1601)],b[h(516)]);this[h(1400)+"hCloseEv"+h(963)](xt(e.KbrpA,{code:1006,reason:b[h(516)]||h(829)+h(1685)+h(596)+h(879)+"n, hostn"+h(1284)+L,willReconnect:F})),F&&this[h(547)]();return}if(b[h(1601)]!==1e3&&this[h(1036)+h(1296)])if(e[h(585)](h(1827),e[h(1476)])){this[h(1400)+h(1800)+"ent"](e[h(454)](xt,h(723),{code:1e3,reason:e.flDgb})),this[h(1516)+h(1271)]?.[h(772)+h(920)+h(1436)](),this[h(741)+"sCounter"]?.[h(1069)+h(1589)]();return}else this[h(774)](d[h(685)],_0x171e3b),this[h(1472)]&&this.onopen(_0x174765);if(e[h(1599)](1e3,b[h(1601)])&&R)if(e[h(472)](e[h(1616)],e.CQDLg)){let L=this[h(1516)+h(1271)]?.[h(1558)+h(461)+"nt"](),F=b[h(516)];F||(F=await e[h(1912)](Zh,this[h(493)])),F=h(829)+h(1685)+h(864)+F+(h(905)+"me: ")+L+(h(1113)+"tries re"+h(1190)),this[h(1400)+h(1800)+h(963)](e[h(453)](xt,e[h(756)],{code:b[h(1601)],reason:F}));let W=h(1653)+L+(h(1576)+h(1004)+h(594)+"ed");this[h(1400)+h(873)+h(963)](e[h(595)](ot,e[h(1774)],{message:W,code:en["MAX_RETR"+h(707)+"R"]})),this[h(1516)+h(1271)]?.["resetEnd"+h(920)+h(1436)](),this[h(741)+h(1670)]?.[h(1069)+h(1589)]();return}else _0x3f3cf0[h(1902)][h(1317)+"ild"](_0xbd7ad);if(e[h(977)](1e3,b[h(1601)])&&!b[h(516)]){let L=this[h(1516)+"tManager"]?.[h(1558)+h(461)+"nt"]();this[h(1400)+h(1800)+h(963)](e[h(1002)](xt,e[h(756)],{code:b[h(1601)],reason:"connecti"+h(1685)+h(596)+"wn reaso"+h(1032)+h(1284)+L})),this["_endpoin"+h(1271)]?.[h(772)+h(920)+h(1436)](),this[h(741)+h(1670)]?.[h(1069)+h(1589)]();return}this[h(1400)+h(1800)+h(963)](b),this[h(1516)+h(1271)]?.[h(772)+h(920)+h(1436)](),this["_pingLos"+h(1670)]?.[h(1069)+h(1589)]()},this[s(1590)]=null,this[s(1016)]=null,this[s(1071)+"e"]=null,this.onopen=null,this["onStartR"+s(983)]=null,this["onReceiv"+s(548)]=null,this[s(1726)+s(1251)+"yReconnect"]=null,this[s(640)+s(1192)]=this[s(640)+s(1192)][s(938)](this),this[s(640)+s(1803)]=this[s(640)+"ffLine"][s(938)](this),this["_handleP"+s(1141)]=this["_handleP"+s(1141)][s(938)](this),this[s(1751)+"ageShow"]=this[s(1751)+"ageShow"].bind(this),this._options={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(1532)](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(947),pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(987)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:g}=n,m=Array[s(1709)](f)?f:e[s(605)](e[s(1628)],typeof f)?[f]:[];if(!m||e[s(1224)](0,m[s(1927)]))throw new Error("please p"+s(883)+s(903));if(!Kh(g))throw new Error(e.sLIiN);Object[s(823)](this._options,n),this[s(1516)+"tManager"]=new Wd(m,this._options[s(1593)+"es"]),this[s(741)+s(1670)]=new Jh(this[s(1754)][s(788)+s(1934)]),this._options["automati"+s(597)]&&(this[s(1843)]=!0,this[s(547)]()),this[s(1754)][s(1270)+s(1150)+s(492)]&&(this[s(1841)+"T"]||this[s(727)+"X"]?this["_onPageN"+s(849)+s(1651)]():this[s(1937)+"er"]&&this[s(1710)+s(1713)+s(1441)]())}[t(640)+t(1192)](){let n=t;this[n(1754)][n(1205)+n(711)+n(814)]||this[n(1036)+"osed"]||this[n(586)+"econnect"]()}["_handleO"+t(1803)](){let n=t;this[n(1567)+n(1250)+"t"]();let s=e[n(1521)](ra,e[n(1515)],{message:e[n(1832)]});this[n(1726)+n(1251)+n(1385)+"ct"]&&this["onStopImmediatel"+n(1385)+"ct"](s)}[t(1710)+t(1713)+t(1441)](){let n=t;e[n(445)](e[n(804)],n(1529))?(this[n(774)](e[n(1774)],_0x1897c3),this[n(1016)]&&this.onerror(_0x13c891)):(this._isBrowser&&window["addEvent"+n(1441)](e[n(1674)],this[n(640)+n(1192)]),this._isBrowser&&window[n(1246)+n(1441)](e[n(1810)],this[n(640)+n(1803)]),this[n(1937)+"er"]&&window[n(1246)+n(1441)](e[n(1605)],this[n(1751)+n(1141)]),this[n(1937)+"er"]&&window[n(1246)+"Listener"](e[n(1294)],this[n(1751)+"ageShow"]))}["_dropGlo"+t(1713)+t(1441)](){let n=t;if(e[n(471)](n(908),e[n(1089)]))return _0x35dc25[n(1168)][_0x3d96ef(_0x41be19,1)];this[n(1937)+"er"]&&window[n(1854)+n(1790)+n(497)](e[n(1674)],this["_handleO"+n(1192)]),this[n(1937)+"er"]&&window[n(1854)+n(1790)+n(497)](n(587),this[n(640)+n(1803)]),this[n(1937)+"er"]&&window[n(1854)+"entListe"+n(497)](e[n(1605)],this._handlePageHide),this[n(1937)+"er"]&&window[n(1854)+n(1790)+n(497)](e.Qujli,this[n(1751)+n(1425)])}[t(1751)+t(1141)](n){let s=t,d={vnpeC:function(f,g){return e.VJTYo(f,g)}};if(!n[s(765)+"d"]){if(e[s(1451)](e[s(1018)],e[s(1536)]))return AutFgj[s(1779)](_0x17e3eb,_0x16deab(_0xcdd1c7));this[s(1937)+"er"]&&window["removeEventListe"+s(497)](s(795),this[s(1751)+s(1141)]),this[s(1937)+"er"]&&window["removeEv"+s(1790)+"ner"](e[s(1294)],this[s(1751)+s(1425)]),this.close()}this[s(1937)+"er"]&&window[s(1854)+"entListe"+s(497)](e[s(1674)],this[s(640)+s(1192)]),this._isBrowser&&window[s(1854)+s(1790)+"ner"](e[s(1810)],this[s(640)+s(1803)])}[t(1751)+t(1425)](n){let s=t;if(e[s(1219)](e[s(1058)],e[s(904)]))return!!this[s(682)];n.persisted&&(this[s(1538)+"orOnline"]()&&(!this[s(1096)]||this._ws[s(1331)+"te"]!==this[s(649)]||this[s(1096)][s(1331)+"te"]!==this[s(1928)+"NG"])&&this[s(640)+"nLine"](),this._isBrowser&&window["addEvent"+s(1441)](e.eEmHo,this[s(640)+s(1192)]),this._isBrowser&&window[s(1246)+s(1441)](e[s(1810)],this["_handleO"+s(1803)]))}async[t(646)+t(1123)](n){let s=t,{fpID:d,deviceID:f,bddID:g,ttwID:m,accessKey:b,aID:h,customParams:R={},enableAutoAck:L,enableQoS:F,QoSLevel:W,env:Z}=this[s(1754)],J,fe,Se;this._isBrowser||this[s(727)+"X"]||this[s(1841)+"T"]?(J=location&&e.bnFlF("https:",location[s(781)])?e[s(1204)]:e.XmKKe,fe=n[s(588)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),Se=/^wss(.*:\/\/)/[s(1102)](n)?n:""+J+fe):(J=e[s(1204)],fe=n.replace(/(^http)((?:[s]*:\/\/))/,""),Se=/(^ws)((?:[s]*:\/\/))/[s(1102)](fe)?fe:""+J+fe);let Qe=g?s(1796):m?e[s(1956)]:e[s(1304)],ht=g||m||f;if(e[s(1637)](!ht,!Qe))throw new Error(e[s(1228)]);let Yi=e[s(1514)](s(1502),typeof R)?await R():R,Cp=Z?e[s(1295)](Vh,Z[s(1849)],Z[s(828)]):{},ua=Object[s(823)]({device_platform:e[s(1180)],version_code:e[s(580)],access_key:b,fpid:d,aid:h,[Qe]:ht,xsack:L?1:0,xaack:L?1:0,xsqos:F?1:0,qos_level:F?W:void 0,qos_sdk_version:2,...Cp},Yi),Dp=Object[s(1632)](ua)[s(475)]((fa,xa)=>ua[xa]!==void 0?""+fa+(fa?"&":"?")+xa+"="+ua[xa]:fa,"");return Se+s(1074)+Dp}async[t(547)](){let n=t;if(!(this["_connect"+n(1811)]||this[n(1036)+n(1296)])){this[n(547)+n(1811)]=!0;try{let s=this[n(1516)+n(1271)]?.[n(1878)+"rentEndp"+n(1278)+n(985)+n(1588)](),{timeoutInterval:d}=this._options;if(s){let g=this[n(1516)+n(1271)]?.[n(1558)+n(461)+"nt"](),m=this[n(1516)+n(1271)]?.["replaceBackupEnd"+n(1257)+n(571)+n(1403)](),b=this[n(1516)+n(1271)]?.[n(1558)+n(461)+n(556)+"ount"]();if(m)if(e.fRuJe(e.FBiPo,e.TdmXY)){let h=n(1653)+g+(n(1730)+n(1113)+"tries re"+n(1221)+n(796)+n(1946)+"ndpoint ")+m+(n(603)+"y"),R=e[n(1521)](ot,"error",{message:h,code:en.MAX_RETRIES_ERROR});this._debug(h),this["_dispatc"+n(873)+n(963)](R),this[n(493)]=await this[n(646)+n(1123)](m),this[n(1207)](n(1653)+m+" "+b+n(476)),this[n(1374)+n(563)+"rs"]()}else this[n(1937)+"er"]&&_0x5bac74[n(1854)+"entListe"+n(497)](e[n(1605)],this[n(1751)+"ageHide"]),this[n(1937)+"er"]&&_0x1f8e42[n(1854)+n(1790)+n(497)](e.Qujli,this[n(1751)+n(1425)]),this.close();else{let h="connect "+g+(" timeout, max re"+n(480)+n(1190));this._debug(h),this["_dispatc"+n(873)+"ent"](ot(n(787),{message:h,code:en[n(1109)+n(707)+"R"]}));return}}else{let g=this._endpointManager?.[n(1558)+n(461)+n(579)+"ateCount"](),m=this[n(1516)+n(1271)]?.[n(1558)+"ntEndpoi"+n(556)+"ount"]();this[n(493)]=await this["_generat"+n(1123)](g||""),this[n(1207)](n(1653)+g+" "+m+n(476)),this[n(1374)+"sListeners"]()}if(this[n(1843)])this[n(1843)]=!1;else{let g=e[n(1002)](ra,e[n(1515)],{message:e[n(976)]});this[n(1406)+n(983)]&&this["onStartR"+n(983)](g)}let f=this[n(1516)+n(1271)]?.[n(1558)+"ntEndpoi"+n(556)+n(880)]()||0;e[n(514)](f,1)&&await this._wait(f-1),this._debug(n(829)+n(845)+this[n(493)]+(" protoco"+n(749))+this[n(651)+"ls"]),this[n(1096)]=e[n(1065)](Wh,{url:this[n(493)],protocols:[this[n(651)+"ls"]],headers:this[n(1754)][n(613)+"ramParams"]["customHt"+n(657)]},this[n(1754)].ws),(this[n(1937)+"er"]||this._isWorker)&&this._ws&&(this._ws[n(1555)+"pe"]=this[n(1966)+"ype"]),this[n(1583)+n(485)](),this[n(547)+"ionTimeo"+n(869)]=e[n(1944)](setTimeout,this[n(830)+"ut"][n(938)](this),d)}catch(s){throw this[n(547)+n(1811)]=!1,s}}}[t(854)+t(1421)](){let n=t;e[n(1716)](clearTimeout,this[n(547)+n(1708)+n(869)]),this[n(547)+n(1708)+n(869)]=null}[t(1895)+t(528)](){let n=t;clearTimeout(this._pingPongTimeoutId),e[n(1023)](clearTimeout,this[n(1482)+"ctTimeou"+n(1025)]),this[n(843)+n(545)+"Id"]=null,this[n(1482)+n(721)+n(1025)]=null}[t(1207)](...n){let s=t;this[s(1754)][s(1045)]&&console.log[s(1765)](console,[e.AbgdU,...n])}[t(505)+t(1917)+"e"](n){let s=t;if(e[s(1008)]!==e.BFNyT){let{initReconnectInterval:d,maxReconnectInterval:f,reconnectIntervalGrowFactor:g}=this[s(1754)],m=d*Math[s(1853)](g,e[s(1571)](n,1));return e[s(1850)](m,f)?f:m}else return e[s(679)](_0x2d22e3,_0x5567b8)?_0x4ee276:new _0x28898b(e[s(653)](e[s(667)](e[s(1078)](e[s(1151)](_0xbe1d95[s(1027)](_0x473742,0),e[s(915)](_0x481e60[s(1027)](_0x544639,1),8)),_0x564081.call(_0x5d6a92,2)<<16),e[s(1209)](_0x4cab34.call(_0x5740fb,3),24)),0),e.XoeKi(e[s(1524)](e[s(1658)](_0xc30466[s(1027)](_0x3a6548,4)|e.qZDBE(_0x334db8[s(1027)](_0x5e12d5,5),8),_0x4a210e.call(_0x3b1ab1,6)<<16),e[s(1361)](_0x2d79bc[s(1027)](_0x1b981a,7),24)),0),!0)}[t(668)](){let n=t;if(this._ws&&e[n(1761)](this[n(1096)][n(1331)+"te"],this.CONNECTING)){this[n(1895)+n(528)](),this[n(843)+n(545)+"Id"]=setTimeout(this._ping.bind(this),this[n(1754)][n(448)+n(1175)]);return}if(!this[n(1096)]||e.iweJS(this._ws[n(1331)+"te"],this.OPEN))return void this[n(586)+"econnect"]();this[n(1096)]&&this[n(1096)][n(1503)]("hi"),this[n(1482)+n(721)+"tId"]=e[n(1179)](setTimeout,this[n(586)+n(983)+n(794)][n(938)](this),this[n(1754)]["pingTime"+n(1573)+n(1261)])}[t(586)+"econnectTimeout"](){let n=t;if(e[n(1370)](e.cQsXi,n(673))){let s=this[n(682)][n(1033)+n(1202)+"nc"](this[n(554)]),d=_0x50ee0f[n(1866)](e[n(1799)](s,"{}"));return _0x147ce3[n(1632)](d)}else this._pingLossCounter?.addCount(),this[n(774)](e.wVxch,e[n(1647)]),this[n(741)+"sCounter"]?.[n(1094)+"chMaxCount"]()?this["_handleR"+n(983)]():this[n(668)]()}[t(1538)+"orOnline"](){let n=t;if(e[n(1219)](e[n(1706)],e.ZpWCA))return this[n(1841)+"T"]||this[n(727)+"X"]?this[n(768)+"igatorOnline"]:(this[n(1937)+"er"]||this[n(1680)+"r"])&&this[n(1754)][n(1270)+n(1150)+n(492)]?navigator[n(815)]:!0;{let s=this[n(693)],d=this[n(1839)];return[e[n(1122)](s,24),e.PZroC(e[n(452)](s,16),255),e[n(1769)](s,8)&255,e[n(1704)](255,s),e.fUHen(d,24),e[n(1303)](e[n(1769)](d,16),255),d>>>8&255,e[n(867)](255,d)]}}_handleReconnect(){let n=t;!this[n(1538)+n(1189)]()||this[n(1036)+n(1296)]||(this[n(1516)+n(1271)]?.["resetEndpointCon"+n(1436)](),this[n(741)+n(1670)]?.[n(1069)+n(1589)](),this[n(1096)]?this[n(810)+n(1634)](1001,e[n(1622)],!0):this[n(547)]())}[t(1077)+"etWorkChange"](){let n=t,s={Pracf:function(d,f){return e[z(1635)](d,f)},gOpNi:n(1412),sBKxE:function(d,f){return d(f)}};if(e[n(637)](e[n(1746)],e[n(1746)]))this._isMiniTT?tt[n(877)+n(1859)+n(488)](({isConnected:d})=>{let f=n;this[f(768)+"igatorOn"+f(1446)]=d,d?this[f(640)+f(1192)]():this["_handleO"+f(1803)]()}):this._isMiniWX&&wx[n(877)+"kStatusC"+n(488)](({isConnected:d})=>{let f=n;if(s.Pracf(s.gOpNi,s.gOpNi))this[f(768)+"igatorOn"+f(1446)]=d,d?this[f(640)+f(1192)]():this[f(640)+f(1803)]();else return _0x5051d6.resolve()});else{let d=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[n(1102)](_0x211bfa),f=/(([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(1102)](_0x3ff578);return d?KKKkhC[n(1648)](_0x3f8902,_0x42e122):f?_0x15a808(_0x427277):n(833)+n(833)+n(833)+n(833)}}_wait(n){return new Promise(s=>{setTimeout(s,this._getIntervalValue(n))})}["_disconn"+t(1634)](n=1e3,s="",d=!1){let f=t;if(e[f(509)](e[f(1489)],e[f(1489)]))this[f(1101)]=_0x1ef0b5,this[f(1911)]=null;else{if(!this[f(1096)])return;this[f(1567)+f(1250)+"t"](n,s,d)}}[t(830)+"ut"](){let n=t,s=this[n(1516)+n(1271)]?.[n(1558)+n(461)+"nt"]();this[n(1207)](n(1653)+s+n(1730)),this[n(810)+n(1634)](1001,e[n(1688)],!0)}_sendAck(n){let s=t,d=zt(n);this[s(1096)]&&e.rIHSg(this[s(1096)].readyState,this.OPEN)&&(this[s(1096)]&&this[s(1096)][s(1503)](d),this[s(1207)](e[s(1760)],n))}_removeWsListeners(){let n=t;if(e[n(1386)](e.xrDkx,e[n(457)])){let s=(n(628)+"0")[n(863)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1096)][n(1854)+n(1790)+n(497)]("error",this[n(1057)]);continue;case"1":this[n(1096)][n(1854)+"entListe"+n(497)](e[n(756)],this[n(1083)]);continue;case"2":this[n(1096)][n(1854)+n(1790)+"ner"](e[n(1662)],this[n(1407)+"ge"]);continue;case"3":if(!this[n(1096)])return;continue;case"4":this[n(1096)]["removeEv"+n(1790)+n(497)](e.DDqiY,this[n(1373)]);continue}break}}else return(this[n(1130)+"rs"][_0x320f82]||(this[n(1130)+"rs"][_0x14149e]=[])).push({fn:_0x2fcdb8,ctx:_0x106d0e||this}),this}[t(1583)+t(485)](){let n=t;this[n(1096)]&&(this[n(1096)][n(1246)+n(1441)](e[n(1666)],this[n(1373)]),this[n(1096)][n(1246)+n(1441)](e[n(756)],this[n(1083)]),this._ws[n(1246)+"Listener"](e[n(1662)],this._onMessage),this[n(1096)].addEventListener(e[n(1774)],this._onError))}[t(729)+t(700)](n=1e3,s=""){let d=t;try{this[d(1096)]&&this[d(1096)][d(723)](n,s)}catch{}}[t(1567)+t(1250)+"t"](n=1e3,s="",d=!1){let f=t;if(e[f(1747)]!==e[f(970)]){if(this[f(1895)+f(528)](),this[f(854)+"mer"](),this[f(1374)+f(563)+"rs"](),this[f(729)+"nceClose"](1e3,s),this["_connect"+f(1811)]=!1,d&&this[f(1538)+f(1189)]()&&!this["_readyCl"+f(1296)]){if(e[f(1511)]!==e[f(1511)])return _0x3c3cca(_0xda9122[f(1765)](ZXTXGV[f(1193)](_0x1f89eb,this),_0x38fb38));if(this[f(1516)+f(1271)]?.[f(1094)+"chMaxTries"]()){let m=this._endpointManager?.[f(1558)+"ntEndpoint"]();this[f(1400)+f(1800)+f(963)](e.WAzZd(xt,"close",{code:1006,reason:f(1653)+m+(f(1730)+f(1113)+"tries re"+f(1190)),wasClean:!0}))}else{let m=this._options[f(775)+"tInterce"+f(611)](n,s);this["_dispatc"+f(1800)+"ent"](e[f(1900)](xt,e[f(756)],{code:n,reason:s,wasClean:!0,willReconnect:m})),m&&this[f(547)]()}return}this["_navigat"+f(1189)]()||this[f(1036)+"osed"]?this[f(1400)+f(1800)+"ent"](e.KLShG(xt,f(723),{code:n,reason:e.flDgb})):this[f(1400)+f(1800)+"ent"](e[f(1065)](xt,e.KbrpA,{code:1006,reason:f(1125)+f(1582)+f(731)+f(1131)})),this[f(1096)]=null,this[f(1516)+"tManager"]?.[f(772)+f(920)+f(1436)](),this[f(741)+f(1670)]?.[f(1069)+f(1589)]()}else return!!this[f(682)]}[t(1400)+t(748)+"nt"](n){let s=t;this.emit(s(1290),n),this.onopen&&this[s(1472)](n)}[t(1400)+t(500)+t(1112)](n){let s=t;this[s(774)](e[s(1662)],n),this[s(1071)+"e"]&&this.onmessage(n)}[t(1400)+"hAckMess"+t(1212)](n){let s=t;this[s(774)](e[s(558)],n),this[s(1277)+"eAck"]&&this.onReceiveAck(n)}[t(1400)+t(873)+t(963)](n){let s=t;e[s(1026)]===e[s(575)]?(this[s(1096)]&&this[s(1096)][s(1503)](_0xf55a41),this[s(1207)](e[s(808)],_0x207d25)):(this.emit(e[s(1774)],n),this[s(1016)]&&this[s(1016)](n))}[t(1400)+t(1800)+t(963)](n){let s=t;this.emit(e[s(756)],n),this[s(1590)]&&this.onclose(n)}get binaryType(){let n=t,s={pxHZt:function(d,f,g){return e.dPEzP(d,f,g)},ixXlc:function(d,f,g){return e.qThUb(d,f,g)}};if(e[n(1386)](n(1035),n(1719)))MssCfL[n(627)](_0x271291,_0x34ec5c,66),_0xe451c2(_0x3030be,_0x13e6de.length),MssCfL.ixXlc(_0x470d47,_0x30afd9,_0x3e0cbb);else return this[n(1096)]?this._ws[n(1555)+"pe"]:this["_binaryT"+n(1892)]}set[t(1555)+"pe"](n){let s=t;this[s(1966)+s(1892)]=n,this[s(1096)]&&(this._ws.binaryType=n)}get[t(725)+"nt"](){let n=t;return this._endpointManager?.["getCurre"+n(461)+n(556)+"ount"]()||0}get[t(1884)+"Amount"](){let n=t;if(e[n(791)](e[n(1564)],e[n(809)])){let s="connect "+_0x5973d9+(" fail, max retri"+n(594)+"ed");this[n(1400)+n(873)+n(963)](_0x38183b("error",{message:s,code:_0x3ac001[n(1109)+n(707)+"R"],error:_0x2c0908}));return}else{let s=this[n(1055)+n(636)][n(475)]((d,f)=>(d+=f&&f.byteLength||0,d),0);return e[n(954)](s,this[n(1096)]?this[n(1096)][n(1884)+n(1022)]:0)}}get[t(1642)+"ns"](){let n=t;return this[n(1096)]?this._ws[n(1642)+"ns"]:""}get[t(781)](){let n=t;return this._ws?this[n(1096)][n(781)]:""}get[t(1331)+"te"](){let n=t;return this[n(1096)]?this[n(1096)][n(1331)+"te"]:this._options[n(1808)+"cOpen"]?this[n(1928)+"NG"]:this[n(650)]}get[t(813)](){let n=t;if(e.zucpf(e[n(960)],e[n(1158)]))++_0x10da43,_0x4830bb+=4;else return this[n(1096)]?this._ws[n(813)]:this[n(493)]}[t(723)](n=1e3,s){let d=t;if(e.OTaSQ(e.lreBG,d(1929))){let f=e[d(859)][d(863)]("|"),g=0;for(;;){switch(f[g++]){case"0":this[d(1567)+d(1250)+"t"](n,s);continue;case"1":this._clearPingTimer();continue;case"2":this[d(1036)+d(1296)]=!0;continue;case"3":if(this[d(1096)][d(1331)+"te"]===this[d(650)]||e.zhwna(this[d(1096)].readyState,this[d(935)]))return void this[d(1207)](e[d(443)]);continue;case"4":this[d(1176)+d(1776)]?.[d(710)]();continue;case"5":if(!this._ws)return void this[d(1207)](d(1391)+d(945)+d(1315)+d(766)+"ed");continue;case"6":this._clearTimer();continue;case"7":this["_dropGlo"+d(1713)+d(1441)]();continue}break}}else return this._socket.extensions}async[t(1503)](n,s){let d=t;if(e[d(1512)](null,n))throw new Error(e[d(1360)]);e[d(1668)](e.nWMgN,typeof n)&&(n=JSON[d(722)+"y"](n)),e.PLUtZ!=typeof n&&!(n instanceof ArrayBuffer)&&!(n.buffer&&n[d(1390)]instanceof ArrayBuffer)&&(n=JSON[d(722)+"y"](n));let f=await e[d(1494)](Jd,n),g=e[d(1910)]($h,n),{method:m=0,service:b=this[d(1754)][d(1086)],logID:h=this[d(1754)][d(1154)+"erator"](),headers:R=this._options[d(1712)],payloadEncoding:L=this[d(1754)][d(584)+d(1901)],payloadType:F=this[d(1754)][d(1607)+"ype"],logIDNew:W=this[d(1754)][d(479)+d(520)][d(760)+d(1085)+"teLogIDNew"]?e[d(1264)](i,this._options["logIDNew"+d(520)].userIp):""}=e.mOnDZ(s,{});if(!b)throw new Error(e[d(1913)]);let Z={SeqID:ce[d(1750)+"er"](this[d(1920)]++),LogID:ce[d(1750)+"er"](h),service:b,method:m,headers:R,payloadEncoding:e[d(865)](L,Object)?L[d(1743)]?L[d(1743)]:"":L,payloadType:e.XgFwI(F,Object)?F[d(1101)]?F.type:g:F||g,payload:f,LogIDNew:W},J=e[d(1044)](zt,Z);if(this[d(1096)]&&this._ws[d(1331)+"te"]===this[d(649)]){if(e[d(1321)]===e[d(460)])return this._ws?this._ws.extensions:"";this._ws&&this[d(1096)].send(J),this[d(1207)](e.BDHdT,Z)}else this[d(1055)+"Queue"][d(1927)]<this[d(1754)][d(450)+"geQueueL"+d(1738)]?(this[d(1055)+"Queue"][d(1655)](J),this[d(1207)](e[d(1164)],Z)):e[d(1352)]!==e[d(1352)]?(this["_dispatc"+d(500)+d(1112)](_0x43912f),_0x31b549[d(1238)](_0x286c99,_0x1a5459,_0x54e3df.message[d(1086)])):(this[d(1055)+d(636)][d(786)](),this[d(1055)+d(636)][d(1655)](J));return{seqID:this._seqId,logID:h,logIDNew:W}}async[t(775)+"t"](n){let s=t,{url:d}=e[s(1701)](n,{}),f=Array.isArray(d)?d:e.bnFlF(e[s(1628)],typeof d)?[d]:[];n&&Object.assign(this[s(1754)],n),f&&f[s(1927)]?this[s(1516)+s(1271)]=new Wd(f,this[s(1754)].maxRetries):this["_endpoin"+s(1271)]?.["resetEnd"+s(920)+s(1436)](),this["_pingLos"+s(1670)]?.[s(1069)+s(1589)](this[s(1754)][s(788)+"Count"]),this._readyClosed=!1,this._ws&&e[s(1370)](this[s(1096)][s(1331)+"te"],this.CLOSED)?this[s(810)+s(1634)](1e3,e[s(1838)],!0):(this[s(1843)]=!0,this[s(547)]())}async[t(1794)](){let n=t;if(!this[n(547)+n(1811)]){let s=e[n(1595)][n(863)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1843)]=!0;continue;case"1":this[n(547)]();continue;case"2":this["_endpoin"+n(1271)]?.[n(772)+n(920)+n(1436)]();continue;case"3":this[n(1036)+n(1296)]=!1;continue;case"4":this[n(741)+n(1670)]?.[n(1069)+n(1589)]();continue}break}}}["addEvent"+t(1441)](n,s){this.on(n,s)}dispatchEvent(n){let s=t;if(e.JPrGD(s(1241),s(1241)))this["_binaryT"+s(1892)]=_0x30d90e,this[s(1096)]&&(this[s(1096)][s(1555)+"pe"]=_0x5d12a4);else{let{type:d}=n;this.emit(d,n)}}[t(1854)+"entListe"+t(497)](n,s){let d=t;e[d(1693)](e[d(1092)],e.LTNVi)?this[d(1440)](n,s):_0x5c9d4d=ZXTXGV[d(1716)](_0x39ea4c,_0x4acba1)}[t(1612)](){let n=t,s={fnktF:e[n(1952)],Pkatf:function(d,f){return e[n(1833)](d,f)},TWHHq:function(d,f,g){return e[n(784)](d,f,g)},IrNrZ:e[n(1091)]};return new Promise((d,f)=>{let g=n,m={PKrAn:function(R,L){return R(L)},LhvYP:g(578),YyJRX:s[g(1955)],xBEhN:g(1243)+g(1348)+"t",TNLJq:function(R,L){return s[g(1949)](R,L)},aMaTK:g(1419)};this[g(1895)+g(528)](),this[g(843)+g(545)+"Id"]=s[g(888)](setTimeout,this[g(668)][g(938)](this),this._options[g(448)+g(1175)]);let b=()=>{let R=g;m[R(1333)](d,m[R(1455)]),this[R(1440)](m[R(1667)],b),this[R(1440)](m[R(599)],h)},h=()=>{let R=g;m[R(862)](f,m.aMaTK),this[R(1440)](m.YyJRX,b),this[R(1440)](R(1243)+"e_timeout",h)};this.on(s.fnktF,b),this.on(s.IrNrZ,h),this[g(668)]()})}}})(),Me[N(1314)+N(1269)]=De[N(1314)+N(1269)],Me["CustomEr"+N(858)]=De.CustomErrorEvent,Me[N(1613)+"e"]=De.ErrorCode,Me[N(1112)]=De[N(1112)],Me[N(1748)]=De[N(1748)],Me[N(1943)+N(1909)+"vent"]=De[N(1943)+N(1909)+N(937)],Me["MessageE"+N(937)]=De["MessageE"+N(937)],Me[N(1459)+"t"]=De.OpenEvent,Me[N(1454)+N(825)]=De["Reconnec"+N(825)],Me["createCl"+N(1269)]=De[N(1163)+N(1269)],Me[N(1764)+N(858)]=De[N(1764)+"rorEvent"],Me[N(1460)+N(1572)+"nt"]=De["createMe"+N(1572)+"nt"],Me["createOp"+N(1409)]=De[N(876)+"enEvent"],Me[N(1781)+"connectE"+N(937)]=De[N(1781)+N(521)+"vent"],Me[N(1953)+N(604)]=De[N(1953)+"rame"],Me[N(606)+N(931)]=De[N(606)+N(931)];for(wo in De)["CustomCl"+N(1269),"CustomEr"+N(858),"ErrorCode",N(1112),N(1748),N(1943)+"MessageE"+N(937),N(1909)+N(937),"OpenEvent","Reconnec"+N(825),N(1163)+N(1269),N(1764)+"rorEvent",N(1460)+N(1572)+"nt","createOpenEvent",N(1781)+N(521)+"vent",N(1953)+N(604),N(606)+N(931)][N(615)](wo)===-1&&(Me[wo]=De[wo]);var wo;Object[N(1565)+N(1259)](Me,N(928)+"le",{value:!0})});var $t=se((M3,$f)=>{"use strict";var Wf=["nodebuffer","arraybuffer","fragments"],Kf=typeof Blob<"u";Kf&&Wf.push("blob");$f.exports={BINARY_TYPES:Wf,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:Kf,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var zi=se((B3,Ao)=>{"use strict";var{EMPTY_BUFFER:kE}=$t(),td=Buffer[Symbol.species];function OE(t,e){if(t.length===0)return kE;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 td(r.buffer,r.byteOffset,i):r}function Vf(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function Jf(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function PE(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function nd(t){if(nd.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new td(t):ArrayBuffer.isView(t)?e=new td(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),nd.readOnly=!1),e}Ao.exports={concat:OE,mask:Vf,toArrayBuffer:PE,toBuffer:nd,unmask:Jf};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=de("bufferutil");Ao.exports.mask=function(e,r,i,o,c){c<48?Vf(e,r,i,o,c):t.mask(e,r,i,o,c)},Ao.exports.unmask=function(e,r){e.length<32?Jf(e,r):t.unmask(e,r)}}catch{}});var Xf=se((z3,Yf)=>{"use strict";var Zf=Symbol("kDone"),rd=Symbol("kRun"),id=class{constructor(e){this[Zf]=()=>{this.pending--,this[rd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[rd]()}[rd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Zf])}}};Yf.exports=id});var Rr=se((F3,nx)=>{"use strict";var Fi=de("zlib"),Qf=zi(),LE=Xf(),{kStatusCode:ex}=$t(),NE=Buffer[Symbol.species],ME=Buffer.from([0,0,255,255]),To=Symbol("permessage-deflate"),Vt=Symbol("total-length"),Cr=Symbol("callback"),bn=Symbol("buffers"),Dr=Symbol("error"),Io,sd=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,!Io){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Io=new LE(r)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[Cr];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,i=e.find(o=>!(r.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>o.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!o.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(i.server_no_context_takeover=!0),r.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(i.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?i.client_max_window_bits=r.clientMaxWindowBits:(i.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(i=>{let o=r[i];if(o.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(o=o[0],i==="client_max_window_bits"){if(o!==!0){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else if(i==="server_max_window_bits"){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(o!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=o})}),e}decompress(e,r,i){Io.add(o=>{this._decompress(e,r,(c,l)=>{o(),i(c,l)})})}compress(e,r,i){Io.add(o=>{this._compress(e,r,(c,l)=>{o(),i(c,l)})})}_decompress(e,r,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?Fi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Fi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:l}),this._inflate[To]=this,this._inflate[Vt]=0,this._inflate[bn]=[],this._inflate.on("error",zE),this._inflate.on("data",tx)}this._inflate[Cr]=i,this._inflate.write(e),r&&this._inflate.write(ME),this._inflate.flush(()=>{let c=this._inflate[Dr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let l=Qf.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"?Fi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Fi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:l}),this._deflate[Vt]=0,this._deflate[bn]=[],this._deflate.on("data",BE)}this._deflate[Cr]=i,this._deflate.write(e),this._deflate.flush(Fi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=Qf.concat(this._deflate[bn],this._deflate[Vt]);r&&(c=new NE(c.buffer,c.byteOffset,c.length-4)),this._deflate[Cr]=null,this._deflate[Vt]=0,this._deflate[bn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};nx.exports=sd;function BE(t){this[bn].push(t),this[Vt]+=t.length}function tx(t){if(this[Vt]+=t.length,this[To]._maxPayload<1||this[Vt]<=this[To]._maxPayload){this[bn].push(t);return}this[Dr]=new RangeError("Max payload size exceeded"),this[Dr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Dr][ex]=1009,this.removeListener("data",tx),this.reset()}function zE(t){if(this[To]._inflate=null,this[Dr]){this[Cr](this[Dr]);return}t[ex]=1007,this[Cr](t)}});var kr=se((U3,Co)=>{"use strict";var{isUtf8:rx}=de("buffer"),{hasBlob:FE}=$t(),UE=[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 GE(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function od(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 qE(t){return FE&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Co.exports={isBlob:qE,isValidStatusCode:GE,isValidUTF8:od,tokenChars:UE};if(rx)Co.exports.isValidUTF8=function(t){return t.length<24?od(t):rx(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=de("utf-8-validate");Co.exports.isValidUTF8=function(e){return e.length<32?od(e):t(e)}}catch{}});var ud=se((G3,lx)=>{"use strict";var{Writable:HE}=de("stream"),ix=Rr(),{BINARY_TYPES:jE,EMPTY_BUFFER:sx,kStatusCode:WE,kWebSocket:KE}=$t(),{concat:ad,toArrayBuffer:$E,unmask:VE}=zi(),{isValidStatusCode:JE,isValidUTF8:ox}=kr(),Do=Buffer[Symbol.species],lt=0,ax=1,cx=2,dx=3,cd=4,dd=5,Ro=6,ld=class extends HE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||jE[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[KE]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=lt}_write(e,r,i){if(this._opcode===8&&this._state==lt)return i();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new Do(i.buffer,i.byteOffset+e,i.length-e),new Do(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 Do(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 ax:this.getPayloadLength16(e);break;case cx:this.getPayloadLength64(e);break;case dx:this.getMask();break;case cd:this.getData(e);break;case dd:case Ro:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if((r[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(r[0]&64)===64;if(i&&!this._extensions[ix.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=ax:this._payloadLength===127?this._state=cx: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=dx:this._state=cd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=cd}getData(e){let r=sx;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&&VE(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=dd,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[ix.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let l=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(l);return}this._fragments.push(c)}this.dataMessage(r),this._state===lt&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=lt;return}let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=ad(i,r):this._binaryType==="arraybuffer"?o=$E(ad(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=lt):(this._state=Ro,setImmediate(()=>{this.emit("message",o,!0),this._state=lt,this.startLoop(e)}))}else{let o=ad(i,r);if(!this._skipUTF8Validation&&!ox(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===dd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=lt):(this._state=Ro,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,sx),this.end();else{let i=e.readUInt16BE(0);if(!JE(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Do(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!ox(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=Ro,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[WE]=o,l}};lx.exports=ld});var hd=se((H3,xx)=>{"use strict";var{Duplex:q3}=de("stream"),{randomFillSync:ZE}=de("crypto"),ux=Rr(),{EMPTY_BUFFER:YE,kWebSocket:XE,NOOP:QE}=$t(),{isBlob:Or,isValidStatusCode:eb}=kr(),{mask:fx,toBuffer:qn}=zi(),ut=Symbol("kByteLength"),tb=Buffer.alloc(4),ko=8*1024,Hn,Pr=ko,vt=0,nb=1,rb=2,fd=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=vt,this.onerror=QE,this[XE]=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):(Pr===ko&&(Hn===void 0&&(Hn=Buffer.alloc(ko)),ZE(Hn,0,ko),Pr=0),i[0]=Hn[Pr++],i[1]=Hn[Pr++],i[2]=Hn[Pr++],i[3]=Hn[Pr++]),l=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||l)&&r[ut]!==void 0?u=r[ut]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!l);let x=u;u>=65536?(c+=8,x=127):u>125&&(c+=2,x=126);let p=Buffer.allocUnsafe(o?u+c:c);return p[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(p[0]|=64),p[1]=x,x===126?p.writeUInt16BE(u,2):x===127&&(p[2]=p[3]=0,p.writeUIntBE(u,4,6)),r.mask?(p[1]|=128,p[c-4]=i[0],p[c-3]=i[1],p[c-2]=i[2],p[c-1]=i[3],l?[p,e]:o?(fx(e,i,p,c,u),[p]):(fx(e,i,e,0,u),[p,e])):[p,e]}close(e,r,i,o){let c;if(e===void 0)c=YE;else{if(typeof e!="number"||!eb(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(r);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof r=="string"?c.write(r,2):c.set(r,2)}}let l={[ut]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==vt?this.enqueue([this.dispatch,c,!1,l,o]):this.sendFrame(t.frame(c,l),o)}ping(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Or(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};Or(e)?this._state!==vt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==vt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}pong(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Or(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};Or(e)?this._state!==vt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==vt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}send(e,r,i){let o=this._extensions[ux.extensionName],c=r.binary?2:1,l=r.compress,u,x;typeof e=="string"?(u=Buffer.byteLength(e),x=!1):Or(e)?(u=e.size,x=!1):(e=qn(e),u=e.length,x=qn.readOnly),this._firstFragment?(this._firstFragment=!1,l&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(l=u>=o._threshold),this._compress=l):(l=!1,c=0),r.fin&&(this._firstFragment=!0);let p={[ut]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:x,rsv1:l};Or(e)?this._state!==vt?this.enqueue([this.getBlobData,e,this._compress,p,i]):this.getBlobData(e,this._compress,p,i):this._state!==vt?this.enqueue([this.dispatch,e,this._compress,p,i]):this.dispatch(e,this._compress,p,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[ut],this._state=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(xd,this,u,o);return}this._bufferedBytes-=i[ut];let l=qn(c);r?this.dispatch(l,r,i,o):(this._state=vt,this.sendFrame(t.frame(l,i),o),this.dequeue())}).catch(c=>{process.nextTick(ib,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[ux.extensionName];this._bufferedBytes+=i[ut],this._state=nb,c.compress(e,i.fin,(l,u)=>{if(this._socket.destroyed){let x=new Error("The socket was closed while data was being compressed");xd(this,x,o);return}this._bufferedBytes-=i[ut],this._state=vt,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===vt&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][ut],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][ut],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};xx.exports=fd;function xd(t,e,r){typeof r=="function"&&r(e);for(let i=0;i<t._queue.length;i++){let o=t._queue[i],c=o[o.length-1];typeof c=="function"&&c(e)}}function ib(t,e,r){xd(t,e,r),t.onerror(e)}});var vx=se((j3,bx)=>{"use strict";var{kForOnEventAttribute:Ui,kListener:pd}=$t(),hx=Symbol("kCode"),px=Symbol("kData"),gx=Symbol("kError"),mx=Symbol("kMessage"),_x=Symbol("kReason"),Lr=Symbol("kTarget"),yx=Symbol("kType"),Ex=Symbol("kWasClean"),Jt=class{constructor(e){this[Lr]=null,this[yx]=e}get target(){return this[Lr]}get type(){return this[yx]}};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[hx]=r.code===void 0?0:r.code,this[_x]=r.reason===void 0?"":r.reason,this[Ex]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[hx]}get reason(){return this[_x]}get wasClean(){return this[Ex]}};Object.defineProperty(jn.prototype,"code",{enumerable:!0});Object.defineProperty(jn.prototype,"reason",{enumerable:!0});Object.defineProperty(jn.prototype,"wasClean",{enumerable:!0});var Nr=class extends Jt{constructor(e,r={}){super(e),this[gx]=r.error===void 0?null:r.error,this[mx]=r.message===void 0?"":r.message}get error(){return this[gx]}get message(){return this[mx]}};Object.defineProperty(Nr.prototype,"error",{enumerable:!0});Object.defineProperty(Nr.prototype,"message",{enumerable:!0});var Gi=class extends Jt{constructor(e,r={}){super(e),this[px]=r.data===void 0?null:r.data}get data(){return this[px]}};Object.defineProperty(Gi.prototype,"data",{enumerable:!0});var sb={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Ui]&&o[pd]===e&&!o[Ui])return;let i;if(t==="message")i=function(c,l){let u=new Gi("message",{data:l?c:c.toString()});u[Lr]=this,Oo(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[Lr]=this,Oo(e,this,u)};else if(t==="error")i=function(c){let l=new Nr("error",{error:c,message:c.message});l[Lr]=this,Oo(e,this,l)};else if(t==="open")i=function(){let c=new Jt("open");c[Lr]=this,Oo(e,this,c)};else return;i[Ui]=!!r[Ui],i[pd]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[pd]===e&&!r[Ui]){this.removeListener(t,r);break}}};bx.exports={CloseEvent:jn,ErrorEvent:Nr,Event:Jt,EventTarget:sb,MessageEvent:Gi};function Oo(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Po=se((W3,Sx)=>{"use strict";var{tokenChars:qi}=kr();function Bt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function ob(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,l,u,x=-1,p=-1,w=-1,_=0;for(;_<t.length;_++)if(p=t.charCodeAt(_),l===void 0)if(w===-1&&qi[p]===1)x===-1&&(x=_);else if(_!==0&&(p===32||p===9))w===-1&&x!==-1&&(w=_);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);w===-1&&(w=_);let E=t.slice(x,w);p===44?(Bt(e,E,r),r=Object.create(null)):l=E,x=w=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);else if(u===void 0)if(w===-1&&qi[p]===1)x===-1&&(x=_);else if(p===32||p===9)w===-1&&x!==-1&&(w=_);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);w===-1&&(w=_),Bt(r,t.slice(x,w),!0),p===44&&(Bt(e,l,r),r=Object.create(null),l=void 0),x=w=-1}else if(p===61&&x!==-1&&w===-1)u=t.slice(x,_),x=w=-1;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(o){if(qi[p]!==1)throw new SyntaxError(`Unexpected character at index ${_}`);x===-1?x=_:i||(i=!0),o=!1}else if(c)if(qi[p]===1)x===-1&&(x=_);else if(p===34&&x!==-1)c=!1,w=_;else if(p===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(p===34&&t.charCodeAt(_-1)===61)c=!0;else if(w===-1&&qi[p]===1)x===-1&&(x=_);else if(x!==-1&&(p===32||p===9))w===-1&&(w=_);else if(p===59||p===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${_}`);w===-1&&(w=_);let E=t.slice(x,w);i&&(E=E.replace(/\\/g,""),i=!1),Bt(r,u,E),p===44&&(Bt(e,l,r),r=Object.create(null),l=void 0),u=void 0,x=w=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);if(x===-1||c||p===32||p===9)throw new SyntaxError("Unexpected end of input");w===-1&&(w=_);let I=t.slice(x,w);return l===void 0?Bt(e,I,r):(u===void 0?Bt(r,I,!0):i?Bt(r,u,I.replace(/\\/g,"")):Bt(r,u,I),Bt(e,l,r)),e}function ab(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(", ")}Sx.exports={format:ab,parse:ob}});var Bo=se((V3,Mx)=>{"use strict";var cb=de("events"),db=de("https"),lb=de("http"),Tx=de("net"),ub=de("tls"),{randomBytes:fb,createHash:xb}=de("crypto"),{Duplex:K3,Readable:$3}=de("stream"),{URL:gd}=de("url"),vn=Rr(),hb=ud(),pb=hd(),{isBlob:gb}=kr(),{BINARY_TYPES:Ax,CLOSE_TIMEOUT:mb,EMPTY_BUFFER:Lo,GUID:wb,kForOnEventAttribute:md,kListener:_b,kStatusCode:yb,kWebSocket:Ge,NOOP:Cx}=$t(),{EventTarget:{addEventListener:Eb,removeEventListener:bb}}=vx(),{format:vb,parse:Sb}=Po(),{toBuffer:Ab}=zi(),Dx=Symbol("kAborted"),wd=[8,13],Zt=["CONNECTING","OPEN","CLOSING","CLOSED"],Ib=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,ge=class t extends cb{constructor(e,r,i){super(),this._binaryType=Ax[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Lo,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]),Rx(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Ax.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 hb({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new pb(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[Ge]=this,c[Ge]=this,e[Ge]=this,o.on("conclude",Db),o.on("drain",Rb),o.on("error",kb),o.on("message",Ob),o.on("ping",Pb),o.on("pong",Lb),c.onerror=Nb,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Px),e.on("data",Mo),e.on("end",Lx),e.on("error",Nx),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())}),Ox(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){_d(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Lo,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){_d(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Lo,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){_d(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||Lo,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:Zt.indexOf("CONNECTING")});Object.defineProperty(ge.prototype,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(ge,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(ge.prototype,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(ge,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(ge.prototype,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(ge,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});Object.defineProperty(ge.prototype,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(ge.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(ge.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[md])return e[_b];return null},set(e){for(let r of this.listeners(t))if(r[md]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[md]:!0})}})});ge.prototype.addEventListener=Eb;ge.prototype.removeEventListener=bb;Mx.exports=ge;function Rx(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:mb,protocolVersion:wd[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,!wd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${wd.join(", ")})`);let c;if(e instanceof gd)c=e;else try{c=new gd(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let l=c.protocol==="wss:",u=c.protocol==="ws+unix:",x;if(c.protocol!=="ws:"&&!l&&!u?x=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?x="The URL's pathname is empty":c.hash&&(x="The URL contains a fragment identifier"),x){let A=new SyntaxError(x);if(t._redirects===0)throw A;No(t,A);return}let p=l?443:80,w=fb(16).toString("base64"),_=l?db.request:lb.request,I=new Set,E;if(o.createConnection=o.createConnection||(l?Cb:Tb),o.defaultPort=o.defaultPort||p,o.port=c.port||p,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":w,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(E=new vn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=vb({[vn.extensionName]:E.offer()})),r.length){for(let A of r){if(typeof A!="string"||!Ib.test(A)||I.has(A))throw new SyntaxError("An invalid or duplicated subprotocol was specified");I.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[S,C]of Object.entries(A))i.headers[S.toLowerCase()]=C}else if(t.listenerCount("redirect")===0){let A=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!A||t._originalSecure&&!l)&&(delete o.headers.authorization,delete o.headers.cookie,A||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),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[Dx]||(v=t._req=null,No(t,A))}),v.on("response",A=>{let S=A.headers.location,C=A.statusCode;if(S&&o.followRedirects&&C>=300&&C<400){if(++t._redirects>o.maxRedirects){st(t,v,"Maximum redirects exceeded");return}v.abort();let P;try{P=new gd(S,e)}catch{let D=new SyntaxError(`Invalid URL: ${S}`);No(t,D);return}Rx(t,P,r,i)}else t.emit("unexpected-response",v,A)||st(t,v,`Unexpected server response: ${A.statusCode}`)}),v.on("upgrade",(A,S,C)=>{if(t.emit("upgrade",A),t.readyState!==ge.CONNECTING)return;v=t._req=null;let P=A.headers.upgrade;if(P===void 0||P.toLowerCase()!=="websocket"){st(t,S,"Invalid Upgrade header");return}let y=xb("sha1").update(w+wb).digest("base64");if(A.headers["sec-websocket-accept"]!==y){st(t,S,"Invalid Sec-WebSocket-Accept header");return}let D=A.headers["sec-websocket-protocol"],k;if(D!==void 0?I.size?I.has(D)||(k="Server sent an invalid subprotocol"):k="Server sent a subprotocol but none was requested":I.size&&(k="Server sent no subprotocol"),k){st(t,S,k);return}D&&(t._protocol=D);let M=A.headers["sec-websocket-extensions"];if(M!==void 0){if(!E){st(t,S,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let B;try{B=Sb(M)}catch{st(t,S,"Invalid Sec-WebSocket-Extensions header");return}let $=Object.keys(B);if($.length!==1||$[0]!==vn.extensionName){st(t,S,"Server indicated an extension that was not requested");return}try{E.accept(B[vn.extensionName])}catch{st(t,S,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[vn.extensionName]=E}t.setSocket(S,C,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(v,t):v.end()}function No(t,e){t._readyState=ge.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Tb(t){return t.path=t.socketPath,Tx.connect(t)}function Cb(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Tx.isIP(t.host)?"":t.host),ub.connect(t)}function st(t,e,r){t._readyState=ge.CLOSING;let i=new Error(r);Error.captureStackTrace(i,st),e.setHeader?(e[Dx]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(No,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function _d(t,e,r){if(e){let i=gb(e)?e.size:Ab(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 Db(t,e){let r=this[Ge];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Ge]!==void 0&&(r._socket.removeListener("data",Mo),process.nextTick(kx,r._socket),t===1005?r.close():r.close(t,e))}function Rb(){let t=this[Ge];t.isPaused||t._socket.resume()}function kb(t){let e=this[Ge];e._socket[Ge]!==void 0&&(e._socket.removeListener("data",Mo),process.nextTick(kx,e._socket),e.close(t[yb])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Ix(){this[Ge].emitClose()}function Ob(t,e){this[Ge].emit("message",t,e)}function Pb(t){let e=this[Ge];e._autoPong&&e.pong(t,!this._isServer,Cx),e.emit("ping",t)}function Lb(t){this[Ge].emit("pong",t)}function kx(t){t.resume()}function Nb(t){let e=this[Ge];e.readyState!==ge.CLOSED&&(e.readyState===ge.OPEN&&(e._readyState=ge.CLOSING,Ox(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Ox(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Px(){let t=this[Ge];if(this.removeListener("close",Px),this.removeListener("data",Mo),this.removeListener("end",Lx),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[Ge]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Ix),t._receiver.on("finish",Ix))}function Mo(t){this[Ge]._receiver.write(t)||this.pause()}function Lx(){let t=this[Ge];t._readyState=ge.CLOSING,t._receiver.end(),this.end()}function Nx(){let t=this[Ge];this.removeListener("error",Nx),this.on("error",Cx),t&&(t._readyState=ge.CLOSING,this.destroy())}});var Ux=se((Z3,Fx)=>{"use strict";var J3=Bo(),{Duplex:Mb}=de("stream");function Bx(t){t.emit("close")}function Bb(){!this.destroyed&&this._writableState.finished&&this.destroy()}function zx(t){this.removeListener("error",zx),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function zb(t,e){let r=!0,i=new Mb({...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(Bx,i);return}let l=!1;t.once("error",function(x){l=!0,c(x)}),t.once("close",function(){l||c(o),process.nextTick(Bx,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",Bb),i.on("error",zx),i}Fx.exports=zb});var yd=se((Y3,Gx)=>{"use strict";var{tokenChars:Fb}=kr();function Ub(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&&Fb[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}Gx.exports={parse:Ub}});var Vx=se((Q3,$x)=>{"use strict";var Gb=de("events"),zo=de("http"),{Duplex:X3}=de("stream"),{createHash:qb}=de("crypto"),qx=Po(),Wn=Rr(),Hb=yd(),jb=Bo(),{CLOSE_TIMEOUT:Wb,GUID:Kb,kWebSocket:$b}=$t(),Vb=/^[+/0-9A-Za-z]{22}==$/,Hx=0,jx=1,Kx=2,Ed=class extends Gb{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:Wb,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:jb,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=zo.createServer((i,o)=>{let c=zo.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=Jb(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=Hx}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===Kx){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Hi,this);return}if(e&&this.once("close",e),this._state!==jx)if(this._state=jx,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(Hi,this):process.nextTick(Hi,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{Hi(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",Wx);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||!Vb.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)){ji(r,400);return}let x=e.headers["sec-websocket-protocol"],p=new Set;if(x!==void 0)try{p=Hb.parse(x)}catch{Kn(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let w=e.headers["sec-websocket-extensions"],_={};if(this.options.perMessageDeflate&&w!==void 0){let I=new Wn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let E=qx.parse(w);E[Wn.extensionName]&&(I.accept(E[Wn.extensionName]),_[Wn.extensionName]=I)}catch{Kn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let I={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(I,(E,v,A,S)=>{if(!E)return ji(r,v||401,A,S);this.completeUpgrade(_,c,p,e,r,i,o)});return}if(!this.options.verifyClient(I))return ji(r,401)}this.completeUpgrade(_,c,p,e,r,i,o)}completeUpgrade(e,r,i,o,c,l,u){if(!c.readable||!c.writable)return c.destroy();if(c[$b])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Hx)return ji(c,503);let p=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${qb("sha1").update(r+Kb).digest("base64")}`],w=new this.options.WebSocket(null,void 0,this.options);if(i.size){let _=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;_&&(p.push(`Sec-WebSocket-Protocol: ${_}`),w._protocol=_)}if(e[Wn.extensionName]){let _=e[Wn.extensionName].params,I=qx.format({[Wn.extensionName]:[_]});p.push(`Sec-WebSocket-Extensions: ${I}`),w._extensions=e}this.emit("headers",p,o),c.write(p.concat(`\r
10
+ `),this.stream=void 0;return}this.currentDate!==void 0&&Ji(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 Gp,mkdirSync as jp}from"node:fs";import{join as Hp}from"node:path";function el(t){let e=t.retentionDays??$p,r=t.clock??(()=>Sn(new Date));Xi={bridgeSink:new jr(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new jr(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();Ji(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])Ji(t.agentLogsDir(o),"agent",i,e)}function Kp(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function tl(t){pa=t}function nl(t){return Yn[pa]<=Yn[t]}function rl(t,e){let r=Yn[t];return r===void 0?!0:r>=Yn[e]}function Qi(t){Qd={...t}}function il(t){let e=(f,h=2)=>String(f).padStart(h,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),d=e(o%60);return`${Sn(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${d}`}function Hr(t,e,r,i,o){try{let c=`${JSON.stringify({ts:il(new Date),level:e,module:r,msg:i,...o})}
11
+ `;jp(t,{recursive:!0}),Gp(Hp(t,Jn("bridge",Sn(new Date))),c)}catch{}}function Zp(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function Yi(t,e,r,i,o){if(Yn[t]<Yn[pa])return;let c=`${JSON.stringify({ts:il(new Date),level:t,module:e,msg:r,...Qd,...i})}
12
+ `;if(Xi){let d=Zp(o,i),f=d?Kp(Xi,d):Xi.bridgeSink;try{f.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?Wp.write(c):qp.write(c)}function G(t,e){return{debug:(r,i)=>Yi("debug",t,r,i,e),info:(r,i)=>Yi("info",t,r,i,e),warn:(r,i)=>Yi("warn",t,r,i,e),error:(r,i)=>Yi("error",t,r,i,e),child:r=>G(`${t}.${r}`,e),forAgent:r=>G(t,r)}}var Yn,pa,qp,Wp,Qd,$p,Xi,ne=Ke(()=>{"use strict";Vi();xa();Yn={debug:10,info:20,warn:30,error:40},pa=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),qp=process.stdout,Wp=process.stderr,Qd={},$p=Mt("COZE_BRIDGE_LOG_RETENTION_DAYS",30),Xi=null});var T,qe=Ke(()=>{"use strict";T=class extends Error{code;retriable;cause;constructor(e,r,i){super(r),this.name="BridgeError",this.code=e,this.retriable=i?.retriable??!1,i?.cause!==void 0&&(this.cause=i.cause)}}});var cl={};ua(cl,{ACP_WRAPPER_NPM_PACKAGES:()=>Wr,_resetAcpInstallerForTests:()=>eg,_setBinaryPathCacheForTests:()=>tg,buildAcpSpawn:()=>$r,ensureAcpInstalled:()=>Xn,getAcpBinaryPath:()=>es,pickWhichLine:()=>wa,probeAcpVersion:()=>Qp,resolveAcpCommand:()=>al});import{readFileSync as sl}from"node:fs";import{createRequire as Vp}from"node:module";import{dirname as Jp,resolve as Yp}from"node:path";function wa(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 Xp(t){let e=ol.resolve(`${t.npmPackage}/package.json`),r=Jp(e),i=JSON.parse(sl(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 Yp(r,o)}async function Xn(t,e){let r=ma[t];if(!r)throw new T("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=qr.get(t);if(i)return i;try{let o=Xp(r);return qr.set(t,o),ga.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw ga.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:r.npmPackage,err:String(o)}),new T("AGENT_DEPENDENCY_INSTALL_FAILED",[`ACP wrapper \u672A\u5C31\u7EEA: ${r.npmPackage} (framework=${t})`,"\u8BE5 wrapper \u968F coze-bridge \u4E00\u8D77\u5B89\u88C5 (\u56FA\u5316\u5230 ~/.coze/bridge/lib/node_modules)\u3002","\u8BF7\u91CD\u8DD1 `coze-bridge pair` / `connect` \u89E6\u53D1\u56FA\u5316\u5B89\u88C5; \u82E5\u4ECD\u5931\u8D25, \u68C0\u67E5\u7F51\u7EDC / npm \u7F13\u5B58\u3002"].join(`
13
+ `),{cause:o})}}async function Qp(t){let e=ma[t];if(e)try{let r=ol.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(sl(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){ga.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function es(t){return qr.get(t)}function al(t,e){if(e)return e;let r=es(t);if(!r)throw new T("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return r}function $r(t,e,r){if(e)return{command:e,args:[...r]};let i=al(t);return{command:process.execPath,args:[i,...r]}}function eg(){qr.clear()}function tg(t,e){qr.set(t,e)}var ga,ma,Wr,ol,qr,en=Ke(()=>{"use strict";qe();ne();ga=G("agents.acp-installer"),ma={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},Wr=Object.values(ma).filter(t=>t!==void 0).map(t=>t.npmPackage),ol=Vp(import.meta.url),qr=new Map});import{chmod as rg,mkdir as ig,readFile as sg,rename as fl,writeFile as ul}from"node:fs/promises";import{dirname as og}from"node:path";async function Qn(t){try{let e=await sg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function er(t,e,r){await ig(og(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 ul(o,i,{encoding:"utf8",mode:r.mode}):await ul(o,i,"utf8"),await fl(o,t),r?.mode!==void 0&&await rg(t,r.mode)}catch(c){await fl(o,o).catch(()=>{});let{rm:d}=await import("node:fs/promises");throw await d(o,{force:!0}).catch(()=>{}),c}}var Kr=Ke(()=>{"use strict"});import{promises as hl,readdirSync as ag}from"node:fs";import{homedir as cg}from"node:os";import{sep as dg,join as Ae,resolve as xl}from"node:path";function Y(t){let e=t??cg(),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=Y()){let r=Ae(e.agentsRoot,t);return{root:r,config:Ae(r,"config.json"),workspace:Ae(r,"workspace"),logs:Ae(r,"logs")}}function ts(t=Y()){try{return ag(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function Zr(t,e){let r=await hl.realpath(xl(t)).catch(()=>null);if(!r)return!1;let i=await hl.realpath(xl(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+dg)}var ke=Ke(()=>{"use strict"});var is={};ua(is,{AGENT_CONFIG_FILE_MODE:()=>ns,enforceAgentConfigMode:()=>ug,loadAgentConfig:()=>Ge,persistAgentSessions:()=>Vr,persistAgentSkills:()=>rs,saveAgentConfig:()=>Ve});import{chmod as lg,stat as fg}from"node:fs/promises";function Ge(t,e){return Qn(Ze(t,e).config)}function Ve(t,e){return er(Ze(t.agentId,e).config,t,{mode:ns})}async function ug(t,e){if(process.platform==="win32")return;let r=Ze(t,e).config;try{let i=await fg(r);if(!i.isFile())return;let o=i.mode&511;o!==ns&&(await lg(r,ns),pl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;pl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function Vr(t,e,r){let i=await Ge(t,r);i&&(i.sessions=Object.fromEntries(e),await Ve(i,r))}async function rs(t,e,r){let i=await Ge(t,r);i&&(i.skills=e,await Ve(i,r))}var pl,ns,tn=Ke(()=>{"use strict";Kr();ne();ke();pl=G("agent-config"),ns=384});var _a=se((NS,yl)=>{yl.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 os=se(El=>{var _l={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 mg(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(_l))El[t]=mg(_l[t])});var Al=se((BS,Il)=>{var wg=de("fs"),Oe=de("path"),bl=_a(),yg=os(),_g=typeof process=="object"&&process.platform==="win32",vl=t=>typeof t=="object"&&t!==null,Sl=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function Ee(t){this.sep=Oe.sep,this.fs=wg,vl(t)&&vl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Il.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 d;try{d=e.fs.statSync(o)}catch(f){if(f.message&&f.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw f}if(d&&d.isFile())throw yg.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 d=Oe.dirname(t);o.fs.existsSync(d)||o.makeDir(d);var f;try{f=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),f=o.fs.openSync(t,"w",438)}if(f)try{o.fs.writeSync(f,e,0,e.length,0)}finally{o.fs.closeSync(f)}return o.fs.chmodSync(t,i||438),!0};Ee.prototype.writeFileToAsync=function(t,e,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(d){if(d&&!r)return o(!1);c.fs.stat(t,function(f,h){if(d&&h.isDirectory())return o(!1);var x=Oe.dirname(t);c.fs.exists(x,function(m){m||c.makeDir(x),c.fs.open(t,"w",438,function(g,A){g?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(w,E){c.fs.write(E,e,0,e.length,0,function(){c.fs.close(E,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):A?c.fs.write(A,e,0,e.length,0,function(){c.fs.close(A,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};Ee.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let d=[];return e.fs.readdirSync(i).forEach(function(f){let h=Oe.join(i,f),x=e.fs.statSync(h);(!o||o.test(h))&&d.push(Oe.normalize(h)+(x.isDirectory()?e.sep:"")),x.isDirectory()&&c&&(d=d.concat(r(h,o,c)))}),d}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 d=c.length;if(!d)return e(null,i);c.forEach(function(f){f=Oe.join(t,f),r.fs.stat(f,function(h,x){if(h)return e(h);x&&(i.push(Oe.normalize(f)+(x.isDirectory()?r.sep:"")),x.isDirectory()?r.findFilesAsync(f,function(m,g){if(m)return e(m);i=i.concat(g),--d||e(null,i)}):--d||e(null,i))})})})};Ee.prototype.getAttributes=function(){};Ee.prototype.setAttributes=function(){};Ee.crc32update=function(t,e){return Sl[(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 bl.STORED:return"STORED ("+t+")";case bl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Ee.canonical=function(t){if(!t)return"";let e=Oe.posix.normalize("/"+t.split("\\").join("/"));return Oe.join(".",e)};Ee.zipnamefix=function(t){if(!t)return"";let e=Oe.posix.normalize("/"+t.split("\\").join("/"));return Oe.posix.join(".",e)};Ee.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let r=t.length>>>0;for(let i=r-1;i>=0;i--)if(e(t[i],i,t))return t[i]};Ee.sanitize=function(t,e){t=Oe.resolve(Oe.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Oe.normalize(Oe.join(t,r.slice(i,o).join(Oe.sep)));if(c.indexOf(t)===0)return c}return Oe.normalize(Oe.join(t,Oe.basename(e)))};Ee.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};Ee.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};Ee.fromDOS2Date=function(t){return new Date((t>>25&127)+1980,Math.max((t>>21&15)-1,0),Math.max(t>>16&31,1),t>>11&31,t>>5&63,(t&31)<<1)};Ee.fromDate2DOS=function(t){let e=0,r=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),r=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|r};Ee.isWin=_g;Ee.crcTable=Sl});var Rl=se((zS,Tl)=>{var Eg=de("path");Tl.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=Eg.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 Dl=se((FS,Cl)=>{Cl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var rr=se((US,nr)=>{nr.exports=Al();nr.exports.Constants=_a();nr.exports.Errors=os();nr.exports.FileAttr=Rl();nr.exports.decoder=Dl()});var Ol=se((GS,kl)=>{var nn=rr(),F=nn.Constants;kl.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,d=0,f=0,h=0,x=0,m=0,g=0,A=0,w=0,E=0;t|=nn.isWin?2560:768,r|=F.FLG_EFS;let I={extraLen:0},S=y=>Math.max(0,y)>>>0,R=y=>Math.max(0,y)&65535,P=y=>Math.max(0,y)&255;return o=nn.fromDate2DOS(new Date),{get made(){return t},set made(y){t=y},get version(){return e},set version(y){e=y},get flags(){return r},set flags(y){r=y},get flags_efs(){return(r&F.FLG_EFS)>0},set flags_efs(y){y?r|=F.FLG_EFS:r&=~F.FLG_EFS},get flags_desc(){return(r&F.FLG_DESC)>0},set flags_desc(y){y?r|=F.FLG_DESC:r&=~F.FLG_DESC},get method(){return i},set method(y){switch(y){case F.STORED:this.version=10;case F.DEFLATED:default:this.version=20}i=y},get time(){return nn.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=nn.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=S(y)},get timeHighByte(){return P(o>>>8)},get crc(){return c},set crc(y){c=S(y)},get compressedSize(){return d},set compressedSize(y){d=S(y)},get size(){return f},set size(y){f=S(y)},get fileNameLength(){return h},set fileNameLength(y){h=y},get extraLength(){return x},set extraLength(y){x=y},get extraLocalLength(){return I.extraLen},set extraLocalLength(y){I.extraLen=y},get commentLength(){return m},set commentLength(y){m=y},get diskNumStart(){return g},set diskNumStart(y){g=S(y)},get inAttr(){return A},set inAttr(y){A=S(y)},get attr(){return w},set attr(y){w=S(y)},get fileAttr(){return(w||0)>>16&4095},get offset(){return E},set offset(y){E=S(y)},get encrypted(){return(r&F.FLG_ENC)===F.FLG_ENC},get centralHeaderSize(){return F.CENHDR+h+x+m},get realDataOffset(){return E+F.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(y){var C=y.slice(E,E+F.LOCHDR);if(C.readUInt32LE(0)!==F.LOCSIG)throw nn.Errors.INVALID_LOC();I.version=C.readUInt16LE(F.LOCVER),I.flags=C.readUInt16LE(F.LOCFLG),I.flags_desc=(I.flags&F.FLG_DESC)>0,I.method=C.readUInt16LE(F.LOCHOW),I.time=C.readUInt32LE(F.LOCTIM),I.crc=C.readUInt32LE(F.LOCCRC),I.compressedSize=C.readUInt32LE(F.LOCSIZ),I.size=C.readUInt32LE(F.LOCLEN),I.fnameLen=C.readUInt16LE(F.LOCNAM),I.extraLen=C.readUInt16LE(F.LOCEXT);let D=E+F.LOCHDR+I.fnameLen,N=D+I.extraLen;return y.slice(D,N)},loadFromBinary:function(y){if(y.length!==F.CENHDR||y.readUInt32LE(0)!==F.CENSIG)throw nn.Errors.INVALID_CEN();t=y.readUInt16LE(F.CENVEM),e=y.readUInt16LE(F.CENVER),r=y.readUInt16LE(F.CENFLG),i=y.readUInt16LE(F.CENHOW),o=y.readUInt32LE(F.CENTIM),c=y.readUInt32LE(F.CENCRC),d=y.readUInt32LE(F.CENSIZ),f=y.readUInt32LE(F.CENLEN),h=y.readUInt16LE(F.CENNAM),x=y.readUInt16LE(F.CENEXT),m=y.readUInt16LE(F.CENCOM),g=y.readUInt16LE(F.CENDSK),A=y.readUInt16LE(F.CENATT),w=y.readUInt32LE(F.CENATX),E=y.readUInt32LE(F.CENOFF)},localHeaderToBinary:function(){var y=Buffer.alloc(F.LOCHDR);return y.writeUInt32LE(F.LOCSIG,0),y.writeUInt16LE(e,F.LOCVER),y.writeUInt16LE(r,F.LOCFLG),y.writeUInt16LE(i,F.LOCHOW),y.writeUInt32LE(o,F.LOCTIM),y.writeUInt32LE(c,F.LOCCRC),y.writeUInt32LE(d,F.LOCSIZ),y.writeUInt32LE(f,F.LOCLEN),y.writeUInt16LE(h,F.LOCNAM),y.writeUInt16LE(I.extraLen,F.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(F.CENHDR+h+x+m);return y.writeUInt32LE(F.CENSIG,0),y.writeUInt16LE(t,F.CENVEM),y.writeUInt16LE(e,F.CENVER),y.writeUInt16LE(r,F.CENFLG),y.writeUInt16LE(i,F.CENHOW),y.writeUInt32LE(o,F.CENTIM),y.writeUInt32LE(c,F.CENCRC),y.writeUInt32LE(d,F.CENSIZ),y.writeUInt32LE(f,F.CENLEN),y.writeUInt16LE(h,F.CENNAM),y.writeUInt16LE(x,F.CENEXT),y.writeUInt16LE(m,F.CENCOM),y.writeUInt16LE(g,F.CENDSK),y.writeUInt16LE(A,F.CENATT),y.writeUInt32LE(w,F.CENATX),y.writeUInt32LE(E,F.CENOFF),y},toJSON:function(){let y=function(C){return C+" bytes"};return{made:t,version:e,flags:r,method:nn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(d),size:y(f),fileNameLength:y(h),extraLength:y(x),commentLength:y(m),diskNumStart:g,inAttr:A,attr:w,offset:E,centralHeaderSize:y(F.CENHDR+h+x+m)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Ll=se((jS,Pl)=>{var ir=rr(),me=ir.Constants;Pl.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 ir.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=ir.readBigUInt64LE(c,me.ZIP64SUB),e=ir.readBigUInt64LE(c,me.ZIP64TOT),r=ir.readBigUInt64LE(c,me.ZIP64SIZE),i=ir.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(d,f){let h=d.toString(16).toUpperCase();for(;h.length<f;)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 ba=se(Ea=>{Ea.EntryHeader=Ol();Ea.MainHeader=Ll()});var Ml=se((qS,Nl)=>{Nl.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=[],d=0;o.on("data",function(f){c.push(f),d+=f.length}),o.on("end",function(){var f=Buffer.alloc(d),h=0;f.fill(0);for(var x=0;x<c.length;x++){var m=c[x];m.copy(f,h),h+=m.length}i&&i(f)}),o.end(t)}}}});var zl=se((WS,Bl)=>{var bg=+(process.versions?process.versions.node:"").split(".")[0]||0;Bl.exports=function(t,e){var r=de("zlib");let i=bg>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),d=[],f=0;c.on("data",function(h){d.push(h),f+=h.length}),c.on("end",function(){var h=Buffer.alloc(f),x=0;h.fill(0);for(var m=0;m<d.length;m++){var g=d[m];g.copy(h,x),x+=g.length}o&&o(h)}),c.end(t)}}}});var Hl=se(($S,jl)=>{"use strict";var{randomFillSync:Fl}=de("crypto"),vg=os(),Sg=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}),Gl=(t,e)=>Math.imul(t,e)>>>0,Ul=(t,e)=>Sg[(t^e)&255]^t>>>8,Jr=()=>typeof Fl=="function"?Fl(Buffer.alloc(12)):Jr.node();Jr.node=()=>{let t=Buffer.alloc(12),e=t.length;for(let r=0;r<e;r++)t[r]=Math.random()*256&255;return t};var as={genSalt:Jr};function cs(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])}cs.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Ul(e[0],t),e[1]+=e[0]&255,e[1]=Gl(e[1],134775813)+1,e[2]=Ul(e[2],e[1]>>>24),t};cs.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Gl(t,t^1)>>8&255};function Ig(t){let e=new cs(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 Ag(t){let e=new cs(t);return function(r,i,o=0){i||(i=Buffer.alloc(r.length));for(let c of r){let d=e.next();i[o++]=c^d,e.updateKeys(c)}return i}}function Tg(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Ig(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw vg.WRONG_PASSWORD();return i(t.slice(12))}function Rg(t){Buffer.isBuffer(t)&&t.length>=12?as.genSalt=function(){return t.slice(0,12)}:t==="node"?as.genSalt=Jr.node:as.genSalt=Jr}function Cg(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Ag(r),c=as.genSalt();c[11]=e.crc>>>24&255,i&&(c[10]=e.crc>>>16&255);let d=Buffer.alloc(t.length+12);return o(c,d),o(t,d,12)}jl.exports={decrypt:Tg,encrypt:Cg,_salter:Rg}});var ql=se(ds=>{ds.Deflater=Ml();ds.Inflater=zl();ds.ZipCrypto=Hl()});var Sa=se((ZS,Wl)=>{var oe=rr(),Dg=ba(),be=oe.Constants,va=ql();Wl.exports=function(t,e){var r=new Dg.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,d=null,f=Buffer.alloc(0),h=Buffer.alloc(0),x=!0;let m=t,g=typeof m.decoder=="object"?m.decoder:oe.decoder;x=g.hasOwnProperty("efs")?g.efs:!1;function A(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(h=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function w(y){if(!r.flags_desc&&!r.localHeader.flags_desc){if(oe.crc32(y)!==r.localHeader.crc)return!1}else{let C={},D=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(D)==be.LOCSIG||e.readUInt32LE(D)==be.CENSIG)throw oe.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(D)==be.EXTSIG)C.crc=e.readUInt32LE(D+be.EXTCRC),C.compressedSize=e.readUInt32LE(D+be.EXTSIZ),C.size=e.readUInt32LE(D+be.EXTLEN);else if(e.readUInt16LE(D+12)===19280)C.crc=e.readUInt32LE(D+be.EXTCRC-4),C.compressedSize=e.readUInt32LE(D+be.EXTSIZ-4),C.size=e.readUInt32LE(D+be.EXTLEN-4);else throw oe.Errors.DESCRIPTOR_UNKNOWN();if(C.compressedSize!==r.compressedSize||C.size!==r.size||C.crc!==r.crc)throw oe.Errors.DESCRIPTOR_FAULTY();if(oe.crc32(y)!==C.crc)return!1}return!0}function E(y,C,D){if(typeof C>"u"&&typeof y=="string"&&(D=y,y=void 0),c)return y&&C&&C(Buffer.alloc(0),oe.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var N=A();if(N.length===0)return y&&C&&C(N),N;if(r.encrypted){if(typeof D!="string"&&!Buffer.isBuffer(D))throw oe.Errors.INVALID_PASS_PARAM();N=va.ZipCrypto.decrypt(N,r,D)}var M=Buffer.alloc(r.size);switch(r.method){case oe.Constants.STORED:if(N.copy(M),w(M))return y&&C&&C(M),M;throw y&&C&&C(M,oe.Errors.BAD_CRC()),oe.Errors.BAD_CRC();case oe.Constants.DEFLATED:var K=new va.Inflater(N,r.size);if(y)K.inflateAsync(function(Z){Z.copy(Z,0),C&&(w(Z)?C(Z):C(Z,oe.Errors.BAD_CRC()))});else{if(K.inflate(M).copy(M,0),!w(M))throw oe.Errors.BAD_CRC(`"${g.decode(i)}"`);return M}break;default:throw y&&C&&C(Buffer.alloc(0),oe.Errors.UNKNOWN_METHOD()),oe.Errors.UNKNOWN_METHOD()}}function I(y,C){if((!d||!d.length)&&Buffer.isBuffer(e))return y&&C&&C(A()),A();if(d.length&&!c){var D;switch(r.method){case oe.Constants.STORED:return r.compressedSize=r.size,D=Buffer.alloc(d.length),d.copy(D),y&&C&&C(D),D;default:case oe.Constants.DEFLATED:var N=new va.Deflater(d);if(y)N.deflateAsync(function(K){D=Buffer.alloc(K.length),r.compressedSize=K.length,K.copy(D),C&&C(D)});else{var M=N.deflate();return r.compressedSize=M.length,M}N=null;break}}else if(y&&C)C(Buffer.alloc(0));else return Buffer.alloc(0)}function S(y,C){return oe.readBigUInt64LE(y,C)}function R(y){try{for(var C=0,D,N,M;C+4<y.length;)D=y.readUInt16LE(C),C+=2,N=y.readUInt16LE(C),C+=2,M=y.slice(C,C+N),C+=N,be.ID_ZIP64===D&&P(M)}catch{throw oe.Errors.EXTRA_FIELD_PARSE_ERROR()}}function P(y){var C,D,N,M;y.length>=be.EF_ZIP64_SCOMP&&(C=S(y,be.EF_ZIP64_SUNCOMP),r.size===be.EF_ZIP64_OR_32&&(r.size=C)),y.length>=be.EF_ZIP64_RHO&&(D=S(y,be.EF_ZIP64_SCOMP),r.compressedSize===be.EF_ZIP64_OR_32&&(r.compressedSize=D)),y.length>=be.EF_ZIP64_DSN&&(N=S(y,be.EF_ZIP64_RHO),r.offset===be.EF_ZIP64_OR_32&&(r.offset=N)),y.length>=be.EF_ZIP64_DSN+4&&(M=y.readUInt32LE(be.EF_ZIP64_DSN),r.diskNumStart===be.EF_ZIP64_OR_16&&(r.diskNumStart=M))}return{get entryName(){return g.decode(i)},get rawEntryName(){return i},set entryName(y){i=oe.toBuffer(y,g.encode);var C=i[i.length-1];c=C===47||C===92,r.fileNameLength=i.length},get efs(){return typeof x=="function"?x(this.entryName):x},get extra(){return f},set extra(y){f=y,r.extraLength=y.length,R(y)},get comment(){return g.decode(o)},set comment(y){if(o=oe.toBuffer(y,g.encode),r.commentLength=o.length,o.length>65535)throw oe.Errors.COMMENT_TOO_LONG()},get name(){var y=g.decode(i);return c?y.substr(y.length-1).split("/").pop():y.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(y){I(!0,y)},setData:function(y){d=oe.toBuffer(y,oe.decoder.encode),!c&&d.length?(r.size=d.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?d:E(!1,null,y)},getDataAsync:function(y,C){r.changed?y(d):E(!0,y,C)},set attr(y){r.attr=y},get attr(){return r.attr},set header(y){r.loadFromBinary(y)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=f.length;var y=r.centralHeaderToBinary(),C=oe.Constants.CENHDR;return i.copy(y,C),C+=i.length,f.copy(y,C),C+=r.extraLength,o.copy(y,C),y},packLocalHeader:function(){let y=0;r.flags_efs=this.efs,r.extraLocalLength=h.length;let C=r.localHeaderToBinary(),D=Buffer.alloc(C.length+i.length+r.extraLocalLength);return C.copy(D,y),y+=C.length,i.copy(D,y),y+=i.length,h.copy(D,y),y+=h.length,D},toJSON:function(){let y=function(C){return"<"+(C&&C.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:y(e),data:y(d)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Zl=se((VS,Kl)=>{var $l=Sa(),kg=ba(),je=rr();Kl.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new kg.MainHeader,d=!1,f=null;let h=new Set,x=e,{noSort:m,decoder:g}=x;t?E(x.readEntries):d=!0;function A(){let S=new Set;for(let R of Object.keys(i)){let P=R.split("/");if(P.pop(),!!P.length)for(let y=0;y<P.length;y++){let C=P.slice(0,y+1).join("/")+"/";S.add(C)}}for(let R of S)if(!(R in i)){let P=new $l(x);P.entryName=R,P.attr=16,P.temporary=!0,r.push(P),i[P.entryName]=P,h.add(P)}}function w(){if(d=!0,i={},c.diskEntries>(t.length-c.offset)/je.Constants.CENHDR)throw je.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var S=c.offset,R=0;R<r.length;R++){var P=S,y=new $l(x,t);y.header=t.slice(P,P+=je.Constants.CENHDR),y.entryName=t.slice(P,P+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(P,P+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(P,P+y.header.commentLength)),S+=y.header.centralHeaderSize,r[R]=y,i[y.entryName]=y}h.clear(),A()}function E(S){var R=t.length-je.Constants.ENDHDR,P=Math.max(0,R-65535),y=P,C=t.length,D=-1,N=0;for(typeof x.trailingSpace=="boolean"&&x.trailingSpace&&(P=0),R;R>=y;R--)if(t[R]===80){if(t.readUInt32LE(R)===je.Constants.ENDSIG){D=R,N=R,C=R+je.Constants.ENDHDR,y=R-je.Constants.END64HDR;continue}if(t.readUInt32LE(R)===je.Constants.END64SIG){y=P;continue}if(t.readUInt32LE(R)===je.Constants.ZIP64SIG){D=R,C=R+je.readBigUInt64LE(t,R+je.Constants.ZIP64SIZE)+je.Constants.ZIP64LEAD;break}}if(D==-1)throw je.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(D,C)),c.commentLength&&(o=t.slice(N+je.Constants.ENDHDR)),S&&w()}function I(){r.length>1&&!m&&r.sort((S,R)=>S.entryName.toLowerCase().localeCompare(R.entryName.toLowerCase()))}return{get entries(){return d||w(),r.filter(S=>!h.has(S))},get comment(){return g.decode(o)},set comment(S){o=je.toBuffer(S,g.encode),c.commentLength=o.length},getEntryCount:function(){return d?r.length:c.diskEntries},forEach:function(S){this.entries.forEach(S)},getEntry:function(S){return d||w(),i[S]||null},setEntry:function(S){d||w(),r.push(S),i[S.entryName]=S,c.totalEntries=r.length},deleteFile:function(S,R=!0){d||w();let P=i[S];this.getEntryChildren(P,R).map(C=>C.entryName).forEach(this.deleteEntry)},deleteEntry:function(S){d||w();let R=i[S],P=r.indexOf(R);P>=0&&(r.splice(P,1),delete i[S],c.totalEntries=r.length)},getEntryChildren:function(S,R=!0){if(d||w(),typeof S=="object")if(S.isDirectory&&R){let P=[],y=S.entryName;for(let C of r)C.entryName.startsWith(y)&&P.push(C);return P}else return[S];return[]},getChildCount:function(S){if(S&&S.isDirectory){let R=this.getEntryChildren(S);return R.includes(S)?R.length-1:R.length}return 0},compressToBuffer:function(){d||w(),I();let S=[],R=[],P=0,y=0;c.size=0,c.offset=0;let C=0;for(let M of this.entries){let K=M.getCompressedData();M.header.offset=y;let Z=M.packLocalHeader(),te=Z.length+K.length;y+=te,S.push(Z),S.push(K);let X=M.packCentralHeader();R.push(X),c.size+=X.length,P+=te+X.length,C++}P+=c.mainHeaderSize,c.offset=y,c.totalEntries=C,y=0;let D=Buffer.alloc(P);for(let M of S)M.copy(D,y),y+=M.length;for(let M of R)M.copy(D,y),y+=M.length;let N=c.toBinary();return o&&o.copy(N,je.Constants.ENDHDR),N.copy(D,y),t=D,d=!1,D},toAsyncBuffer:function(S,R,P,y){try{d||w(),I();let C=[],D=[],N=0,M=0,K=0;c.size=0,c.offset=0;let Z=function(te){if(te.length>0){let X=te.shift(),_e=X.entryName+X.extra.toString();P&&P(_e),X.getCompressedDataAsync(function(he){y&&y(_e),X.header.offset=M;let O=X.packLocalHeader(),j=O.length+he.length;M+=j,C.push(O),C.push(he);let W=X.packCentralHeader();D.push(W),c.size+=W.length,N+=j+W.length,K++,Z(te)})}else{N+=c.mainHeaderSize,c.offset=M,c.totalEntries=K,M=0;let X=Buffer.alloc(N);C.forEach(function(he){he.copy(X,M),M+=he.length}),D.forEach(function(he){he.copy(X,M),M+=he.length});let _e=c.toBinary();o&&o.copy(_e,je.Constants.ENDHDR),_e.copy(X,M),t=X,d=!1,S(X)}};Z(Array.from(this.entries))}catch(C){R(C)}}}}});var Yl=se((JS,Jl)=>{var ye=rr(),we=de("path"),Og=Sa(),Pg=Zl(),In=(...t)=>ye.findLast(t,e=>typeof e=="boolean"),Vl=(...t)=>ye.findLast(t,e=>typeof e=="string"),Lg=(...t)=>ye.findLast(t,e=>typeof e=="function"),Ng={noSort:!1,readEntries:!1,method:ye.Constants.NONE,fs:null};Jl.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),Ng);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 Pg(r,i),{canonical:d,sanitize:f,zipnamefix:h}=ye;function x(w){if(w&&c){var E;if(typeof w=="string"&&(E=c.getEntry(we.posix.normalize(w))),typeof w=="object"&&typeof w.entryName<"u"&&typeof w.header<"u"&&(E=c.getEntry(w.entryName)),E)return E}return null}function m(w){let{join:E,normalize:I,sep:S}=we.posix;return E(we.isAbsolute(w)?"/":".",I(S+w.split("\\").join(S)+S))}function g(w){return w instanceof RegExp?(function(E){return function(I){return E.test(I)}})(w):typeof w!="function"?()=>!0:w}let A=(w,E)=>{let I=E.slice(-1);return I=I===o.sep?o.sep:"",we.relative(w,E)+I};return{readFile:function(w,E){var I=x(w);return I&&I.getData(E)||null},childCount:function(w){let E=x(w);if(E)return c.getChildCount(E)},readFileAsync:function(w,E){var I=x(w);I?I.getDataAsync(E):E(null,"getEntry failed for:"+w)},readAsText:function(w,E){var I=x(w);if(I){var S=I.getData();if(S&&S.length)return S.toString(E||"utf8")}return""},readAsTextAsync:function(w,E,I){var S=x(w);S?S.getDataAsync(function(R,P){if(P){E(R,P);return}R&&R.length?E(R.toString(I||"utf8")):E("")}):E("")},deleteFile:function(w,E=!0){var I=x(w);I&&c.deleteFile(I.entryName,E)},deleteEntry:function(w){var E=x(w);E&&c.deleteEntry(E.entryName)},addZipComment:function(w){c.comment=w},getZipComment:function(){return c.comment||""},addZipEntryComment:function(w,E){var I=x(w);I&&(I.comment=E)},getZipEntryComment:function(w){var E=x(w);return E&&E.comment||""},updateFile:function(w,E){var I=x(w);I&&I.setData(E)},addLocalFile:function(w,E,I,S){if(o.fs.existsSync(w)){E=E?m(E):"";let R=we.win32.basename(we.win32.normalize(w));E+=I||R;let P=o.fs.statSync(w),y=P.isFile()?o.fs.readFileSync(w):Buffer.alloc(0);P.isDirectory()&&(E+=o.sep),this.addFile(E,y,S,P)}else throw ye.Errors.FILE_NOT_FOUND(w)},addLocalFileAsync:function(w,E){w=typeof w=="object"?w:{localPath:w};let I=we.resolve(w.localPath),{comment:S}=w,{zipPath:R,zipName:P}=w,y=this;o.fs.stat(I,function(C,D){if(C)return E(C,!1);R=R?m(R):"";let N=we.win32.basename(we.win32.normalize(I));if(R+=P||N,D.isFile())o.fs.readFile(I,function(M,K){return M?E(M,!1):(y.addFile(R,K,S,D),setImmediate(E,void 0,!0))});else if(D.isDirectory())return R+=o.sep,y.addFile(R,Buffer.alloc(0),S,D),setImmediate(E,void 0,!0)})},addLocalFolder:function(w,E,I){if(I=g(I),E=E?m(E):"",w=we.normalize(w),o.fs.existsSync(w)){let S=o.findFiles(w),R=this;if(S.length)for(let P of S){let y=we.join(E,A(w,P));I(y)&&R.addLocalFile(P,we.dirname(y))}}else throw ye.Errors.FILE_NOT_FOUND(w)},addLocalFolderAsync:function(w,E,I,S){S=g(S),I=I?m(I):"",w=we.normalize(w);var R=this;o.fs.open(w,"r",function(P){if(P&&P.code==="ENOENT")E(void 0,ye.Errors.FILE_NOT_FOUND(w));else if(P)E(void 0,P);else{var y=o.findFiles(w),C=-1,D=function(){if(C+=1,C<y.length){var N=y[C],M=A(w,N).split("\\").join("/");M=M.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),S(M)?o.fs.stat(N,function(K,Z){K&&E(void 0,K),Z.isFile()?o.fs.readFile(N,function(te,X){te?E(void 0,te):(R.addFile(I+M,X,"",Z),D())}):(R.addFile(I+M+"/",Buffer.alloc(0),"",Z),D())}):process.nextTick(()=>{D()})}else E(!0,void 0)};D()}})},addLocalFolderAsync2:function(w,E){let I=this;w=typeof w=="object"?w:{localPath:w},localPath=we.resolve(m(w.localPath));let{zipPath:S,filter:R,namefix:P}=w;R instanceof RegExp?R=(function(D){return function(N){return D.test(N)}})(R):typeof R!="function"&&(R=function(){return!0}),S=S?m(S):"",P=="latin1"&&(P=D=>D.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof P!="function"&&(P=D=>D);let y=D=>we.join(S,P(A(localPath,D))),C=D=>we.win32.basename(we.win32.normalize(P(D)));o.fs.open(localPath,"r",function(D){D&&D.code==="ENOENT"?E(void 0,ye.Errors.FILE_NOT_FOUND(localPath)):D?E(void 0,D):o.findFilesAsync(localPath,function(N,M){if(N)return E(N);M=M.filter(K=>R(y(K))),M.length||E(void 0,!1),setImmediate(M.reverse().reduce(function(K,Z){return function(te,X){if(te||X===!1)return setImmediate(K,te,!1);I.addLocalFileAsync({localPath:Z,zipPath:we.dirname(y(Z)),zipName:C(Z)},K)}},E))})})},addLocalFolderPromise:function(w,E){return new Promise((I,S)=>{this.addLocalFolderAsync2(Object.assign({localPath:w},E),(R,P)=>{R&&S(R),P&&I(this)})})},addFile:function(w,E,I,S){w=h(w);let R=x(w),P=R!=null;P||(R=new Og(i),R.entryName=w),R.comment=I||"";let y=typeof S=="object"&&S instanceof o.fs.Stats;y&&(R.header.time=S.mtime);var C=R.isDirectory?16:0;let D=R.isDirectory?16384:32768;return y?D|=4095&S.mode:typeof S=="number"?D|=4095&S:D|=R.isDirectory?493:420,C=(C|D<<16)>>>0,R.attr=C,R.setData(E),P||c.setEntry(R),R},getEntries:function(w){return c.password=w,c?c.entries:[]},getEntry:function(w){return x(w)},getEntryCount:function(){return c.getEntryCount()},forEach:function(w){return c.forEach(w)},extractEntryTo:function(w,E,I,S,R,P){S=In(!1,S),R=In(!1,R),I=In(!0,I),P=Vl(R,P);var y=x(w);if(!y)throw ye.Errors.NO_ENTRY();var C=d(y.entryName),D=f(E,P&&!y.isDirectory?P:I?C:we.basename(C));if(y.isDirectory){var N=c.getEntryChildren(y);return N.forEach(function(Z){if(Z.isDirectory)return;var te=Z.getData();if(!te)throw ye.Errors.CANT_EXTRACT_FILE();var X=d(Z.entryName),_e=f(E,I?X:we.basename(X));let he=R?Z.header.fileAttr:void 0;o.writeFileTo(_e,te,S,he)}),!0}var M=y.getData(c.password);if(!M)throw ye.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(D)&&!S)throw ye.Errors.CANT_OVERRIDE();let K=R?w.header.fileAttr:void 0;return o.writeFileTo(D,M,S,K),!0},test:function(w){if(!c)return!1;for(var E in c.entries)try{if(E.isDirectory)continue;var I=c.entries[E].getData(w);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(w,E,I,S){if(I=In(!1,I),S=Vl(I,S),E=In(!1,E),!c)throw ye.Errors.NO_ZIP();c.entries.forEach(function(R){var P=f(w,d(R.entryName));if(R.isDirectory){o.makeDir(P);return}var y=R.getData(S);if(!y)throw ye.Errors.CANT_EXTRACT_FILE();let C=I?R.header.fileAttr:void 0;o.writeFileTo(P,y,E,C);try{o.fs.utimesSync(P,R.header.time,R.header.time)}catch{throw ye.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(w,E,I,S){if(S=Lg(E,I,S),I=In(!1,I),E=In(!1,E),!S)return new Promise((D,N)=>{this.extractAllToAsync(w,E,I,function(M){M?N(M):D(this)})});if(!c){S(ye.Errors.NO_ZIP());return}w=we.resolve(w);let R=D=>f(w,we.normalize(d(D.entryName))),P=(D,N)=>new Error(D+': "'+N+'"'),y=[],C=[];c.entries.forEach(D=>{D.isDirectory?y.push(D):C.push(D)});for(let D of y){let N=R(D),M=I?D.header.fileAttr:void 0;try{o.makeDir(N),M&&o.fs.chmodSync(N,M),o.fs.utimesSync(N,D.header.time,D.header.time)}catch{S(P("Unable to create folder",N))}}C.reverse().reduce(function(D,N){return function(M){if(M)D(M);else{let K=we.normalize(d(N.entryName)),Z=f(w,K);N.getDataAsync(function(te,X){if(X)D(X);else if(!te)D(ye.Errors.CANT_EXTRACT_FILE());else{let _e=I?N.header.fileAttr:void 0;o.writeFileToAsync(Z,te,E,_e,function(he){he||D(P("Unable to write file",Z)),o.fs.utimes(Z,N.header.time,N.header.time,function(O){O?D(P("Unable to set times",Z)):D()})})}})}}},S)()},writeZip:function(w,E){if(arguments.length===1&&typeof w=="function"&&(E=w,w=""),!w&&i.filename&&(w=i.filename),!!w){var I=c.compressToBuffer();if(I){var S=o.writeFileTo(w,I,!0);typeof E=="function"&&E(S?null:new Error("failed"),"")}}},writeZipPromise:function(w,E){let{overwrite:I,perm:S}=Object.assign({overwrite:!0},E);return new Promise((R,P)=>{!w&&i.filename&&(w=i.filename),w||P("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let C=D=>D?R(D):P("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(w,y,I,S,C)},P)})},toBufferPromise:function(){return new Promise((w,E)=>{c.toAsyncBuffer(w,E)})},toBuffer:function(w,E,I,S){return typeof w=="function"?(c.toAsyncBuffer(w,E,I,S),null):c.compressToBuffer()}}}});import{execFile as Iy,spawn as Ay,spawnSync as dA}from"node:child_process";import{promisify as Ty}from"node:util";function Cy(t){if(process.platform!=="win32")return!1;if($u.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace($u,"").toLowerCase();return Ry.has(r)}function Ku(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return Cy(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function at(t,e=[],r={}){return Ay(t,e,Ku(t,r))}function Zu(t,e=[],r={}){return Dy(t,e,Ku(t,r))}var Ry,$u,Dy,wn=Ke(()=>{"use strict";Ry=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),$u=/\.(cmd|bat|ps1)$/i;Dy=Ty(Iy)});var H0=se(Se=>{"use strict";var L=ee;(function(t,e){let r=ee,i=t();for(;;)try{if(parseInt(r(335))/1+parseInt(r(264))/2*(parseInt(r(1484))/3)+parseInt(r(1239))/4*(-parseInt(r(803))/5)+parseInt(r(385))/6*(-parseInt(r(270))/7)+-parseInt(r(813))/8+parseInt(r(770))/9+-parseInt(r(1589))/10===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(wo,708940);var gE=Object[L(681)+L(1281)],mE=Object[L(1539)+L(872)+"mes"],z0=(t,e)=>function(){return t&&(e=(0,t[{fRpIf:function(o,c){return o(c)}}.fRpIf(mE,t)[0]])(t=0)),e},wE=(t,e)=>{for(var r in e)gE(t,r,{get:e[r],enumerable:!0})};function yE(){return P0||(P0=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function _E(){let t=L;return L0||(L0=[IDBCursor[t(1201)+"e"].advance,IDBCursor.prototype[t(1187)],IDBCursor.prototype["continue"+t(509)+"ey"]])}function EE(t){let e=L,r={oKGOZ:e(773)+e(802)+e(908),wBLey:function(o,c){return o===c},EQevf:e(730),vTbch:function(o,c){return o(c)},zRdOb:function(o,c){return o(c)},EZpmr:function(o){return o()},hnnWc:function(o,c){return o(c)},jEMAt:function(o,c){return o!==c},IUQtR:e(277),ftQFG:e(1116),HaAkb:e(435),rapSq:e(1186)},i=new Promise((o,c)=>{let d=e,f={NYrBP:function(g,A){return r[ee(1137)](g,A)},GpOZb:function(g,A){return r.jEMAt(g,A)},zaABj:r[d(934)],RGHuv:r.ftQFG,kdzcJ:r[d(1190)],TDsif:r[d(359)],UQDcS:function(g){return g()}},h=()=>{let g=d,A={RsUfp:function(w,E){return f[ee(1609)](w,E)}};if(f[g(696)](f[g(393)],f[g(1048)]))t[g(755)+g(798)+g(1499)](f[g(369)],x),t[g(755)+g(798)+g(1499)](f[g(975)],m);else return A.RsUfp(_0x17376d,A[g(956)](_0x4976fd,_0x4fba82))},x=()=>{let g=d,A={toToX:function(w,E){return w instanceof E},TrPiI:r.oKGOZ,gDKym:g(498)+"ion/json",EFyGO:g(367),UpGNd:g(637)};if(r[g(1580)](r.EQevf,r.EQevf))r[g(1526)](o,r[g(575)](Pt,t.result)),r[g(950)](h);else if(_0x359a2a[g(659)]instanceof _0x2bae60){let w=this[g(506)][g(979)+g(350)]instanceof _0x2791f2?{force:!!this[g(506)][g(979)+g(350)][g(1058)],encoding:this[g(506)]["payloadE"+g(350)][g(341)]?this[g(506)][g(979)+g(350)][g(341)][g(398)](/\s/g,"")[g(1565)+"ase"]():""}:{force:!1,encoding:this[g(506)][g(979)+g(350)]?this[g(506)][g(979)+g(350)][g(398)](/\s/g,"")[g(1565)+g(1348)]():""},E=_0x38accc[g(979)+g(350)]?_0x5dff9e.payloadEncoding.replace(/\s/g,"")[g(1565)+g(1348)]():"",I=A[g(599)](this[g(506)][g(518)+"ype"],_0x2473a3)?{force:!!this[g(506)][g(518)+g(1517)][g(1058)],type:this[g(506)][g(518)+g(1517)][g(819)]?this[g(506)][g(518)+g(1517)][g(819)][g(398)](/\s/g,"")["toLowerC"+g(1348)]():""}:{force:!1,type:this[g(506)][g(518)+g(1517)]?this[g(506)][g(518)+g(1517)].replace(/\s/g,"")["toLowerC"+g(1348)]():""},S=_0x3a7d0f[g(518)+g(1517)]?_0x523aa2["payloadT"+g(1517)][g(398)](/\s/g,"")[g(1565)+"ase"]():"",R=I[g(1058)]?I.type:S||I.type,P=w[g(1058)]?w[g(341)]:E||w[g(341)],y=[A[g(401)],A[g(505)],g(498)+g(1264)+g(809)+g(968),A[g(1362)]],C=["none_none",A.UpGNd];this[g(506)][g(628)+"ansformT"+g(823)+"ad"]&&y[g(1579)](R)&&(!P||C[g(1579)](P))?_0x4d7210[g(878)+g(507)]=_0x4ac20d(_0x3f1183[g(659)],0,_0x2fc215[g(659)][g(1453)+"th"]):_0x46a243[g(878)+g(507)]=""}else _0x2cd6ad[g(878)+g(507)]=""},m=()=>{let g=d;c(t[g(1186)]),f[g(1411)](h)};t["addEvent"+d(1012)](d(435),x),t[d(1330)+d(1012)](r[d(359)],m)});return i[e(538)](o=>{let c=e;o instanceof IDBCursor&&Jc[c(591)](o,t)}).catch(()=>{}),_o[e(591)](i,t),i}function bE(t){let e=L,r={xdmof:"complete",BbbsM:e(1186),gAhvn:e(1172),oivmG:function(o){return o()},eZjJE:e(1102)+"or"};if(yo[e(680)](t))return;let i=new Promise((o,c)=>{let d=e,f=()=>{let m=ee;t[m(755)+m(798)+m(1499)](r[m(261)],h),t["removeEv"+m(798)+"ner"](r[m(1057)],x),t["removeEv"+m(798)+"ner"](r.gAhvn,x)},h=()=>{let m=ee;r[m(1134)](o),r[m(1134)](f)},x=()=>{let m=ee;c(t[m(1186)]||new DOMException("AbortError",r[m(723)])),f()};t[d(1330)+d(1012)](d(1052),h),t[d(1330)+d(1012)](r[d(1057)],x),t[d(1330)+d(1012)](r[d(503)],x)});yo[e(591)](t,i)}function wo(){let t=["AwrI","DwfTuhq","z2v0u3rVCMe","uvbTsxi","vgvwA3q","x2LZqNjVD3m","x2rLC3rYB3K","u2vYDMLJzvC","AMPcu2K","Dvv5Euy","CMvfz1q","B3v0sw50zxi","zgPZyw8","wMf5EwS","ywnRDxbfBMq","s1bgtvu","swHzvuO","wKLfEfm","CgLUz19VBMm","qLzMB0u","A1H5qLy","tu53uxu","BwvZC2fNzv8","D2vI","vwP5tKu","BhDdqxO","zeH6vLm","zNDUAeK","t3zSDMi","BgLZDgvUtMu","q0DIAMG","uLbtBNq","C0Xf","mZzVufjwvuG","y291BNq","z2rfzKi","CYbHBhjLywq","wuPKCgi","DxbYqLO","sK1lsNu","yK9mree","BNDwyMO","senOsxe","AergBg8","Euf0t3C","BMrWB2LUDfq","CMvKDwnL","z21st0m","y2XVC2veqG","zcbLCNjVCI4","sMfWDgC","yMLUza","ihzHBgLKihm","ufzmyuq","AgvKtwf4uMu","rwzNvuq","CfbhAMq","C25drMW","Aw9Ul2PZB24","B25tDgfYDfi","Bvjouhy","tufyx1jfvfi","x3bYzwzPEa","suzQBwu","D3LAr2G","zgf0yq","qKrtt3O","q2zHzMG","ExvcC2e","Dev2zw50","q3npzMK","zxmGCMvHy2G","seHxwMi","uhjrsfu","quTUtfy","B3bLCNr5","C3rHCNq","Ef9MCM9UDgK","BxH2Cvu","DgvmB2Djre4","v2LUzg93","shLuDxC","Bg9NsurozxC","uuDgBxy","CNzHBa","ru1hEKW","ywrKq291BNq","C3vIC3rYAw4","AuPoCeW","vfnWqxi","Au5wzhG","B25LCNjVCG","rhDwAvy","r3LZtMO","v0zlAMW","twvnueS","D2LSBfjLy28","EwH4Ee8","B3jL","A056BeS","qM9uzge","x2LZtM9Kzq","twjbr0S","t1bftG","ihrVihjLDhi","Dhf4t3e","yLzpD1m","suvtx0vsuK8","B25JBg9Zzq","r1bxq1y","q2Xnzgy","vfzAvei","Ec11C2uT","ihn1y2nLC3m","CgLUz1rPBwu","lcbTyxGGCMu","BMDuAw1LCG","yxbWBhK","rw5Yz1i","C3rYAw5NAwy","uhnZEw4","C2vYDMLJzq","Bhm6ia","venXruO","ywrKrxzLBNq","vgr4u2i","x2n1CNnVCKy","ywDLsgLKzq","y3r4","uLjIvxC","s2jOA0O","rxzLBNq","CMvHzg9UBhK","rxf4q0S","BwfUDwfSihi","tgLzzue","v1rwBNy","CMv0CNLdB3u","DwndzLC","A2v0ignVBNm","vhvIveK","reXtANi","yxnL","z1vbr0q","ywnOzwq","tezvCum","x2HHBMrSzu8","C3rVCMu","DgjKDei","C3nHz2vfDMu","CNP6C0K","sNfOq28","t0XZDgC","lcbOB3n0BMe","x2LZsw5PDa","AwrpBey","ruz5r08","vffmzvG","AgvHzgvYCW","weXbzhu","B1boDNC","wfbHveC","Eev0vwO","v2vIu29JA2u","r215qNC","yw1Lu3bHy2u","yxv0BW","z3r6C2O","m3WYFdD8nNW","A3vdu3i","AxzNyMm","ufbWB3C","EfLWs1m","BwDiBKS","y29UBMvJDca","zM9YrwfJAa","teXjEgO","v1HsqLO","vffvAKq","Au9pwwu","wKzsChi","AwDHDg9Yt24","CNjVCK1LC3m","ywnR","B2XttLy","BMfTzq","D3vTqxy","y1Lqrxi","tMrSt3K","tvHjz1G","ChjVy2vZCW","zMzRy3O","Aw9U","CeHdt1q","Cw9Zx18","C2v0zgi","tMfTzq","wuv2tuO","Ag5YrgW","EhrmB2q","Aw5N","su9hrum","AMjIufu","yNvMzMvY","ENPjExa","vvfey1m","zw5fDMvUDa","y0f0t3G","Dw50","CMfTzq","y3LPqNG","DLDjCxi","zcWGDw5RBM8","qw5lueC","CMfTugfYyw0","yKDWtKO","rNjVBNrPzxi","B25pCgvU","BezSDxnO","C2HPzNq","r1jSBMO","ueLcvee","CNnVCL9Uyw0","CNDYshe","x2HHBMrSzvi","tMvoCw4","whzSEhi","D0D4ug4","CMvJzxzPzwq","AvfRr1O","wNn1rey","zvvyEfu","r0LvyKi","ywWGy3vYC28","Fdf8n3W5Fdi","y3jLyxrLrwW","D0TeDuS","vu5Lrxe","CxLkBKm","CMLLC0nVDw4","DhvSC3G","DvjxDuC","mdaWma","zxjFCw9Zx2e","BxnTzfi","txLwDMG","ChrVCG","yNL0zuXLBMC","yw5Nzq","igXHCMDLCIa","qKXdzwu","zMX1C2HfEha","AfvkDuW","wfHtthe","igfYCMf5yNu","EuXYEwu","x3jLy29UBMu","teXRB2i","sNvjvwm","tg9Nsuq","Duz6zeK","B3bLBIa","yMzvrNi","ywDtsNa","q0norgK","ywXS","BMvLzf9Hy2S","CMvHzfvjBNq","tvnzvgW","yMfSu2nVCgu","B2nRzxrtDwm","zhfsB0q","wM5AAg8","t0XgqKW","Dg9cExrLCW","q3Pcse8","vuHzrKu","x3bYB3rVy28","mZi5ota2mvPcuhDdwa","DxfgBMC","qLfyvuy","revZD0i","zNjVBNrPzxi","BePWquG","x2LUAxrqCM8","r1f4C0S","EKjNuuu","DhbizwfKzxi","zurnqMi","s2f5z2C","v3fKB28","y3jLyxrLuMu","AeXZqMG","BMvY","yMfJA3vWigu","yLzRywe","wwzVyui","ChvZAa","tw56D1m","zw50zwqGDhK","CLbLALq","tKfusvzfx0u","AMnVAMG","CMfNzvn5BMm","yxKSig5LDhC","BLv5EeK","EvjLy29UBMu","qMPHz1C","q0PtENC","zMLSzw5HBwu","svL2AeG","ExbL","sgDjt3u","s3Hczxm","rhntzeW","igzHAwWSig0","z2v0s2v5","EKLwC1m","y29Su3m","DMvUDa","DLrIy2G","x2LZv29YA2u","DMfSDwu","BM5Ly3q","qvHLveK","tvjuvuu","EsbJBg9Zzwq","x3bPBMC","Cg5eEMW","Ec1TC2CTCw8","Dw5RBM93BIa","t0zNCLi","tvLUvNe","z2v0t3DUuhi","B0fdAeu","x3DHAxq","uNbTBNK","zMLSDgvY","rLLdBw8","BvHsC0q","mNW0Fde","qMTevKW","rfzsB2K","v2vpsxC","C0fYqxO","BuTgCeW","CM92AwrLihC","DNj1CgC","BML0AwfSAxO","C0XPC3rLBMu","Dgnir1K","AM9wAKO","v2vPEgLUsLm","DMvY","y0Lqvvm","rwLmzLi","txzItvu","x29UugfNzu4","qxvuvvy","Dg9mB3DLCKm","C2XPy2u","BxvPz3y","z0LsueS","yxGGCMv0CMK","x2nYzwf0zvm","tgnACNi","vvnjuKO","AgfZt3DUuhi","ywXSB2nvBNm","zu1srMW","DwHwqMK","swjlDxq","tLjsAxm","Aw5JBhvKzxm","D0jmzxK","AevWBwe","BwvKAwf0zwW","zxjFBxnNAwq","q1L2EvK","tK1iDeG","r3zUBwu","tMvqwgG","ugzQtvG","mtaXotG5mfzevML6EG","z2T6Exu","x2nSzwfYugK","BxHsD1i","De5jzLi","C2vUDa","BuLmv0W","B2zM","Efrurw52","shbgtem","Axnby2TdBgu","yMrFzgLK","EfbMzvC","zMvY","C0jf","u2T4s24","swfiB3q","A2v5CW","uvrbBKe","zKTMBum","tLLYqLa","vM1gEK4","qurhBvu","y1LLB2K","Bg9IywXty28","BervANy","x2HHBMrSzva","yLnzz0q","AunWqxG","ywXSzwqGBxu","AxnbCNjHEq","DKzVEvO","AxnAzxjV","r2vwtxK","y29UDgv4Da","tfbWwKK","y3vYCMvUDeK","tKDFrvjst1i","whH0zKG","uLPPC1a","zMLN","rKTwz0y","yxrHlcbKyxq","CIb0DhDjra","sLnptLa","u2nlCeO","tvjRBxe","yvDbB2C","AejqseS","zMzmAw5L","yw1LoIa","x21LC3nHz2u","t2HgzMK","CMvHC29U","qxD6ENe","Dg9iyxnO","z2v0qwXS","y2HLy2TdDxi","zcWG","qNjdzgK","BMXjB0m","vezrEfi","wuTdtuC","y1vWsKO","rMjqz08","zezcAuu","y2fSBa","r1r6C2C","quDWywK","yNL0zu9MzNm","r1LpAKy","v0jqy3O","mhWZFdr8mta","zNjVBunOyxi","CvfVs3y","EKrJDeG","uNP2Ave","AMTlvw4","CNnuAKO","Aw1LCYbPBIa","D1vSt1O","zxjHDg9Y","BwHTEMK","A0nltvi","C3rVCcbPBw0","uwney2u","zxjFAxnFywm","ihrPBwvZ","Eg5uEwe","CxPRCgG","B3bLBKrc","Euzmrwy","EgrTB2y","y3vYC29Yx24","uMr6Evy","mKPTA1vMyq","zxLUALi","txnyveq","BLLLv1e","zxjFDhrS","B25VCgvU","mtC1n2vgthzuCq","u25JuMm","CMfUzg9T","q2P4weq","vhD1r2O","wxbhzNq","BuTovKG","s0nNs3e","uLjpuG","Cw1nz0e","BKjrC2G","Dxjjy04","CuDKr08","Bwf4twvZC2e","z3HLBve","C3bSAwnL","yMfSrxzLBNq","DgfYz2v0","t2PPDxO","Agnsvxu","ignVzgu6ia","zw1LBNq","zgrSyw4","ihrPBwvVDxq","zvvYBa","DNfkCKS","q2fRugy","x29UvgLTzw8","CNzHBfzHBhu","qLP5Aw0","EufrBhK","BgvUz3rO","v3rUDw8","x2rLyNvN","yxbWzw5Kq2G","q29UzMLN","AMLNBgO","C2DPza","D1fhuKW","AeDLzuK","y3vYC29YlNm","C3LAuLy","uhf4uNG","Aw5L","B3zbEfK","q09otKvdveK","Aw5PDcbrB1m","Chv0","tg9NsurozxC","tgnVCLO","ve1Au3u","AefJA01LC3m","uLbnsuq","DvHTEw4","y3jLyxrLtwu","zwrPyxrLBhK","vhHUqwO","sLDbAxi","vgfN","C2v0y3vYC28","B2LwyNi","B3Pisu8","B2vnD0K","rhDSCu8","rKLmrv9ot1q","nty4nZa3CwPjzKTt","u2z1vNe","A1n0yxr1C0m","uhnKBMi","zfjMs0G","yxDsuu0","zw5JB2rPBMC","u3fAz0S","vvvKzMO","yuvfEM8","Be5MEwW","t3Leve4","yNLL","D2HtBMe","B25TzxnZywC","BMnVzgLUzW","uu14yK8","x2LUDgvYDMe","CMvJzwL2zwq","DvPpCvC","wfDUEue","u1niEfa","u0HTtwm","q1fhywm","CMfWu3e","zNvUy3rPB24","Dg9tDhjPBMC","C1PMq1u","y2HLy2Tszwe","zw50","mhWZFdr8mxW","uw9Zu1q","C3rYAw5N","B25tDg9Wsw0","A2r6y0O","A2LKu28","AxnUCeO","AhzQsNm","DeLK","ufLYCgi","t3nnt2S","Dvv5z2K","swLZAhK","rLjptLrjrvi","ihbYB3rVy28","t2nrug4","B3jRig9MzMW","rNLnCNy","BMDLza","uMvJB25Uzwm","mtGYnffcwNPyEa","CNnVCL92ywW","C3bSAxq","txf0Aee","uK5oveW","DgLTzw91Da","sgnmzNi","CK1cvgi","EMfbqMO","zKDYvfC","zwnVBM5Ly3q","vvDmsxG","DhDrr1q","CMvWBgfJzq","C0Puzwe","DcbSAw1PDa","vhjqAuK","twzuqui","Dfv4wvi","De9YAem","CerzDhu","BNnfr3C","zxjFCw9Z","zgvSzxrLrge","zez0AuG","ALLmsK0","z2vY","v1Lsuwy","s2fbBeq","EML4Dvu","AwXLx25HBwu","CMvZzxruCMK","BM94qvC","ywDLu2HVDW","CgjICdi","x3bHDgHlzxK","Bg93","zufJAW","DMfS","BNvOvKC","sM5As28","ENHbuMm","DMjIthy","z1rPBwvVDxq","rwzMEgu","B216uhy","C25sq2S","C0nVDw50zxi","qxHJz0q","BgLUzq","C3vJy2vZCW","x2zVCM1HDeu","wLHzCxu","x194x21Zz18","v2fHv1G","BxnNsuq","A2v5","whrxrfO","CMvZDwX0","BKXPBMu","x1fVu01HBMe","B2zMBgLUzq","x3DZsw5ZDge","tenJtuS","ufPQy0W","BIWGAg9ZDg4","z2v0qwXSs2u","C0riBLy","CgXLyxnLiha","zvfYuuW","rhLSEgG","De1HBMfNzxi","yxnZAwDU","uNrLCxG","sgHgr0e","BLjRtw4","x2n1CNnVCK4","wKn0DNu","D1btuwK","A29mEwy","z2v0q3vYCMu","y2uGBM90igK","v2rjEuO","r0vfBvy","mxWYFdv8m3W","Dw5ZAwDUzwq","BxnN","DfzAqu8","x29Ut3bLBG","x3fVC0rc","CgLUz0XVC3m","uun3vvm","uxPjA0e","BLPVwuG","zNjVBu51Bwi","uhfhs08","sMjOvM4","D2Tywg8","zMPuAKG","t2Pzrgm","A2j3wwu","BM9Uzv9UB24","EfvZzuvUDG","wxzyDvG","tenRshO","z09jvfu","Bwf4tg9ZC0m","BMnLq2XVC2u","vMHwtg0","AwXLtMfTzq","AuDIzwS","CMvHzhDYAxq","DKLOCvG","yxbWBgLJyxq","zLPrzfy","CNz1uKu","vfjry2O","BNvTyMvY","z0fODM4","CM9YrxzLBNq","z0rlEw0","x29WDgLVBNm","B2fK","qMXeww4","uhjPBwfYEuS","uxvLDwu","BgLTAxq","y2f0y2G","wMzVEuW","z0fTAxi","whHrvfa","z2vrDwv1zuW","uvrtEgS","Cgf5Bg9Hzfq","yKjUBhm","AenSB3nLrxy","D2nYrKm","BfroCwS","CKXqEKi","ig1LC3nHz2u","x2XPC3rLBMu","B25szwnLAxy","twLZC2LUzYa","x29UtwvZC2e","y29Uy2f0","vvLQEvm","x3DZ","rNbwChG","s2DfAKm","EgvWy0i","zgrjrcWGzgu","x0vysvnu","zgvSzxrL","DgHLBG","vgHZrhC","r3DTD3i","C3fAEuO","rxH2t3e","wwvlt0C","sxrXveK","yLbLEvG","DuD2reO","rg9tBgy","vxz1B3C","CwLmwhO","AMPct1G","y3jLyxrLq2W","Efjby3e","DxrVuMvJB24","DeLUDgvYy2u","tK5IswO","EgzHvu4","ANj3ywu","x3bPBMDmB3m","C3rLBMvYCW","ywXSq3vYC28","qMnYyuC","y3DxqLy","vhnmzKy","rwTUBvu","B2nRzxrgywK","tKP1rxi","nhWWFdn8mNW","ugj5t0C","Chv4qvG","tg5ACum","x2n1CNnVCK0","DgHHBIbSB2m","tgLjrLK","DhLNy1m","ELjKt2i","y0njrgW","BMHfAKG","z2j2u0m","sMXyrey","DKXswfa","su5tvefova","Dhr3Awq","Bg9Nsurhzw4","teL0BMu","x3vYBa","Bwv0Ag9K","DMfSDwvZ","DwjAswi","AMTWt0K","AxnrB1nnzxm","C2v0","C2fNzq","s0PHzMy","zxjYtM8","z2vjBMzVu3K","ywnOzwqSihC","ywnRx2nVzgu","x29UrxjYB3i","Dg9uB1G","Dez3DNK","zw5HyMXLuw8","B3nLza","Dg9cExrLC0W","x3jLBw92zvC","y2HnyxHuCMK","rvjst1i","s3nIyMG","we9YvwK","wvHorxK","CuDysvm","tgLdvei","yvLcwuu","yNvMzMvYzwq","Dw5KzwzPBMu","zwvKzwq","B25mAw5L","twvZC2fNzuu","C2nYAxb0","zvr1reO","wxjdr2S","r0vnt0C","Dxvtrfq","C29Tzq","DgLUzYbZzxi","y1HQy04","rgP4DxG","y2XVC2u","zw5HyMXLvhi","zxHXD1O","zgLZCgf0y2G","sfrJyLi","zfDVCMTLCKC","BwvZC2fNztO","q3vZDg9Tq2W","DK9At1i","ruP0A1e","yMLUyxj5","CgfYC2u","wvHnzve","B3z5tum","BMCGB3iGyw4","Egzdyvu","sxDPu1i","y2fbCeC","uvjvzfa","tg9JAW","B3nLrxzLBNq","qwLXDMC","BwLZzq","s1nZuNu","r09QD2u","zwf1rey","AgfUz2u","zwn0","wgjYzgS","CMTLCKDSB2i","ru12rxy","C2vYDMLJzs0","Cgf5Bg9Hza","CMvHzhLtDge","y3jLyxrLrxi","tw1VsLG","qvHkyM0","yM9KEq","x2rPC2nVBM4","DxjS","igzPzwXKoIa","BLnkyvu","x3jLywr5q2W","tvLjt2e","y29SBM8","AgTwz3K","CMvJB25Uzwm","svHSEgG","wNvsquK","C2v0q3vYC28","Aw50zwDLCIa","ywnRpwzYB24","id4G","AgfZ","zgvMAw5Luhi","wujRBhC","icSG","BNrLCG","BwvZC2fNzq","q3vZDg9Trxi","u1jQEee","uwHACNu","EvjgEgC","C25YzLm","nhWW","y29UBMvJDeu","AxjLza","yxnJCMLWDa","uhj3Efa","r3bpwMi","rMHNz1G","DhDVCMTdAge","r0j3yxq","vw5Oyw5KBgu","uMvHzcbWyxm","CKTwyKe","qwDstue","y29UBMvJDgK","q291BNq","BNrfBMrWB2K","CgfRvKO","AwXK","AxmGDw5Kzwy","y29UC3rYDwm","t01kvuK","uw94DfC","Bwu6ia","y2XLyxjtDg8","B25fCNjVCG","y2XVC2uSihC","rxjYB3jdB2q","zvjyExy","C3jJ","x3bPBMDqB24","DgLLCKPtt04","ign1CNnVCIa","zvPQsKu","x2TLEvbHDgG","txnlA3C","z2vtEw5J","uMDuD1a","CgfNzwHPzgu","rM1RvuK","v3vUyui","Cw9Z","CMvUDevUzha","DgLrrxa","DhjPzxmGCMu","uxrVA0W","q0Xpu0LorW","CgvSu1O","AxnszwfKEq","ywXty29Wzq","BNrbBMrvCgq","rMjxtMC","sfPfzM0","wxDwEKi","twr4rfm","yxv0B21HDgK","zgvuz28","zw5HyMXLqxu","z0Dtr1m","B25SAw5L","B2XKvMvYC2K","EurvB2W","qw1VDw50","zunYBge","CgHLDvm","CMvTB3zLrxy","B3bLBG","Dxrjza","x2DLBMvYyxq","AgLNAa","ihzHBgLKigq","y09Wzw4","wMjfzvG","x2LUAxq","rLrZuMi","zgvIDwC","DxrMofDYAxq","zvrMt24","yxjYyxLIDwy","y3vZDg9Tshq","ode4nJm5mwjpA1LpCG","Dxfbywe","zhHQDKW","Dgv4Dc9WBge","CLjHq0C","Aw5KzxHpzG","y0r4quu","AM9ys2O","CxPbEg8","zgvKtuy","shHIuwW","zv9ZDwnJzxm","B3vUDa","Cgu6ia","yxHUzK8","quXIDKG","q09oveLovuu","sLbQAhK","sLrZuvG","ugn1ug8","Efztzwm","zNjVBuHHC2G","BgPOv3a","uK9AqMW","sMv1tNa","u3rYyxrLz3K","q29Kzq","B3v0A3C","zw50tgLZDgu","BgvY","vgzoz1C","vLHiELu","Aw47y2HHCNm","nJaYmJy1Awvvu3zP","t1bftL9fuLi","x2nVBM5Ly3q","y1zdweG","rgvKAwnHDgu","C29YDa","o2nOyxjZzxq","BNruCMLLC0m","D2fZq2XLyw4","BM93","ndG1mZq2ngTWCgLszq","Cg9PBNrdB24","sKLUtfO","Bxrvtwi","zv90Aw1LB3u","r0TnwLi","DhLWzq","BwLUAvbYB2C","uu9kBM8","DMLJzuLeig8","zxH0ugf5Bg8","t3bLBKv2zw4","A1jjsKi","s3PZEKO","ywrK","Du5rCMm","rhHQwMq","CuDpr2m","vNDMwKy","B2LUDfjLywm","z1DqwKm","DuTlq1q","zw1PDa","EvvhvNy","Ahr0Ca","te1jqNm","ANHXDva","rgnmvg4","DfPND3C","CMvXDwLYzwq","x2LZtwLUAvq","EezVBvy","CwjPzey","ywDL","Ec1TC2CTy3u","z2v0","tKL6Dva","Dg9VigXHCMC","zNDZxZeUmc4","y29Kzq","CgLUz09Uy2u","z29PBMCGyxC","svHmDfq","AxnrB1nby2S","wgnVzxy","Aw9UvgLTzw8","z2v0q3vYC28","B1rhwwq","zNjVBujPDhm","rNrnsee","vfvoCwi","uKTuqw8","D2niuwi","A1PezK4","C1jOruK","uMfpuuO","zK1RAw0","z2nzqxO","C0HVwLK","B3bLCNr5tMe","AwjywNi","x2nSzwfYvgK","quXpv0W","thPxCvm","qKjgChi","Dgv4DfbHEwW","zKrPwMu","AxzlwK0","wwDoD2O","A3jZB0S","jMPZy2fSBgi","sKDvB0O","rKnXy1e","zMLUza","ww9JzwC","D3jPDgu","A3vjy0S","rvPQAxy","BhPVyLO","thb2rfK","ufnKs1K","uejfDu4","veLHExq","y2HHCKnVzgu","u3vwufi","zNjVBuj5Dgu","zgvS","y1r3Chu","tKDMtfq","x3nLBMrby2S","wxrXqMK","zxj2AwnL","yw5Hz2vY","CYbWyxjHBxm","DxPfrwO","zxq9DxrMltG","qxz4sum","Cg9W","zw5XDwv1zq","C1vyC3C","wwLHvM0","CgvYC2LZDgu","Ae9Wzw5fDMu","C3vIyxjYyxK","zg9Uzq","zw5KCg9PBNq","DwP4reO","A01KAuC","tKrOA3m","wePYs3O","DxbKyxrLq3u","DxbNCMfKzw4","y0rTAfK","Avf2CNi","A3rLve4","yMLUyxj5vhK","yxKSihrYEsa","Cg93","CeDSDeq","tu9nzvq","vuzrC0O","svvrDfi","Chz5ywm","uuzPCvq","x2rPC3bHDgm","zw5JB2rLrNi","z2v0sxrLBq","BvPlBg4","zLblzMy","seLewuC","CMvZB2X2zq","D2TysNq","r2PLwKm","Dg9Y","Bg9N","AxnmB25N","C2v0u3rVCMe","rvPWBxi","zLfivxC","B2jQzwn0u3q","zgvJB2rLzey","A2HlAu4","ENfzt0K","uNnvzNa","z2u6ia","CgfNzxnOB3C","t25LDfe","l3DZl3yY","shjXwLG","yuv2u1i","t05YCey","qNrXv0q","CgLUz0LUDgu","zxjFywnRx20","rejlALy","pxv0zI04","yvjswKi","EeTcuvy","AhLUwfu","A25HzgO","yKrlqvu","z0Dmzwe","verZAwy","zKvksey","rNLoyLq","CeTqrM8","Cgf5Bg9Hzeu","zMXVB3i","CvflAMO","C0zpBfK","B2H3CuG","y3vYC29Y","AefuCNu","C2LWrvy","BMfAvu0","v2Tdv0O","DhPJrue","EMLcBwu","D3jPDgvvAw4","sLbMy1i","wvDquem","vxbKyxrLq28","zxrxB3jRq2G","CLzHBhvLCW","vfjpwge","sgTiv0W","zxH0zw5ZAw8","tuvtu0fhrv8","Cg9PBNrbBMq","sgfgB2y","vwXXrgW","BMv3vMvYC2K","zuX5zhO","u0r3C0m","sLzkqxy","BMrLEa","u2HHCMvKv28","sKLxAwe","yvPiruy","tgLZDgvUzxi","yxrLq291BNq","v2zWsKO","zxf1ywXZ","mNW3Fdf8mta","uw1tzKC","vgLTzw91Da","BvL6uhq","rMj5Eee","y3vYDMfSDwu","twXRs2K","Efrhzgi","vMPbtMC","s3rUufC","DxnLCKLW","CfPQD2i","mdaWmdaWmda","ihjLy29UBMu","AM9PBG","lcbxzwjtB2m","ohWXmhW0Fda","zxrzvha","x0rctMfTzq","A1zbzwO","B25Uzwn0Aw4","A2fryKG","zxHWB3j0CW","zg5ut3y","AevYCM9Yrxy","BKneDey","ywvpC0W","BeHHBMrSzxi","ihrYEsbYzwm","x19LC01Vzhu","DhjPzxm","yM9L","uKDiDxy","yvLLuK4","rM5oC1i","rgvhEeq","y29TCgXLDgu","CNjMvvC","C1fVt1i","ywDLrxzLBNq","DNj0q1a","qMjIC00","zM9Yy2u","DgPfwvy","x3nLCuLK","ywzL","s2zptw4","rLDHrgS","shbrEfO","A09LEha","ugvYA0G","B0f0C1O","v2vKrM4","CgnIwhe","vNzszMK","ywrKt25L","y01Jtum","y3ruAw1LB3u","uMrJwuC","B25ozxr3B3i","BMvJDa","B3jpBMXPBMu","rhHqB3u","rNnPD28","qvn1CM4","BwvY","tKPJwhC","DwfbDMS","q0jJwM4","q0Xpu0ve","BMv4DcGPigm","r2zkteq","uwnsseu","B3jRzxjhBg8","C2Xlzvi","AMvJDfn0B3i","AMrAwvK","sNP3DeG","BfrPBwvVDxq","zfrABvO","s0LWCKu","t1f5Cgi","BxrIyLy","DgLTzw91DcW","uxrAuhe","x25HDMLNyxq","qwjVCNrfCNi","vePAvu0","DhjPBq","rffVy1C","tMTqrey","Dg9hzw5LCMe","vwvOweS","BMX2tNe","ruXmy2q","x2jPBMfYEvq","q1ndqxu","v3HJzwu","BMCGzMfPBgu","wgvfBve","r1PTBfy","zw1NCM8","zNjHBwvuExa","y3vYCMvUDeu","zgv2AwnLx2K","DgfIyxnL","y29UBMvJDfm","D2PNtKm","C2vUza","wNDMEvi","wKDmENa","D3m6lY8","vhjlvfG","t2jQzwn0","Ae1LC3nHz2u","AwXSihvZzsa","yvLVquu","FdeXFdL8nNW","B2L2BuC","yw51Ce1LC3m","qMTdC2y","Ag5Uv2m","mxW3Fdj8nxW","x2rItMfTzq","CLH0D24","Cwj6zxC","zgXNwhC","x2LZtwLUAvC","B3jLtMfTzxm","tvfLzfe","BfHTugK","D24GCMvHC28","x21PBMLoyxy","rgXSufy","mhW0Fdf8nq","qufywfu","Evj0rfC","Au15tNy","ChjVDg9JB2W","DgvZDa","s1jxtfG","A0LMyMi","u2vXsuq","CYbPBNn0yw4","zvbWDNy","rLDt","CMvQzwn0","AxnFywnR","tNz6t3i","yw1L","Dg9cExrLC0i","CMvZzxrfBMq","x3nVy2TLDa","CM92AwrLihy","ysbTDxn0igi","AwHTCMW","ywjVCNq","x29Uq2XVC2u","y2XLyxi","vg9Vtvy","z1DnzMC","yNfJtfi","BxLqzK8","B2nrt3m","BwLUzW","CMvZzxrdB3u","aaaaaaaaaaa","DhjHBNnHy3q","x2DLDeLUDgu","D1v6vMW","zxjYB3i","y29UDgLUDwu","x2vUzhbVAw4","x2rYB3bhBg8","sgfbA2i","yNL0zxm","BxnKr0S","rK92B2y","CMvTB3zLq2G","x2fKzfDZtgK","y2HnyxHdB3u","zfvis2u","r25XDeC","EgzvyvG","s2DgrgS","ChjVDg90Exa","B2nRzxq","r0jouu8","zxjYtxnN","B2zMC2v0"];return wo=function(){return t},wo()}function vE(t){Eo={jjBSi:function(i,o){return i(o)}}[L(1214)](t,Eo)}function SE(t){let e=L,r={nlvNq:function(i,o){return i&o},nuhVG:function(i,o){return i>>>o},QcDce:function(i,o){return i&o},khKiN:function(i,o){return i>>>o},CBcZn:e(276),mILWL:function(i,o){return i(o)},rsTjJ:function(i,o){return i(o)},jYLJM:function(i,o){return i===o},nSJaU:function(i,o){return i in o},AgmUw:e(952)+e(1144),jFkgL:function(i){return i()},wPWQp:function(i,o){return i===o},snCFl:e(873),kOexp:e(1344)};return r[e(410)](t,IDBDatabase[e(1201)+"e"][e(1183)+e(1398)])&&!r[e(668)](r.AgmUw,IDBTransaction[e(1201)+"e"])?function(i,...o){let c=e;if(r[c(1084)]===r[c(1084)]){let d=t.call(r[c(1595)](Ni,this),i,...o);return Vc[c(591)](d,i[c(808)]?i[c(808)]():[i]),Pt(d)}else return _0x17604b[c(242)+c(796)](r[c(1109)](255,this[c(421)]),r[c(1109)](r[c(424)](this[c(421)],8),255),this[c(421)]>>>16&255,r[c(424)](this[c(421)],24),r.nlvNq(255,this.high),r[c(254)](r.nuhVG(this[c(759)],8),255),this[c(759)]>>>16&255,r[c(954)](this[c(759)],24))}:r.jFkgL(_E).includes(t)?r.wPWQp(r[e(1263)],r[e(1065)])?this[e(531)]?this[e(531)][e(666)]:this[e(585)]:function(...i){return t[e(1323)](r.rsTjJ(Ni,this),i),Pt(Jc.get(this))}:function(...i){let o=e;return r[o(247)](Pt,t[o(1323)](Ni(this),i))}}function IE(t){let e=L,r={QTSxk:function(i,o){return i===o},zqYOI:e(360),IFjme:function(i,o){return i instanceof o},tzcEA:function(i,o){return i(o)},MfTAB:function(i,o,c){return i(o,c)},NnvZQ:function(i){return i()}};return r[e(517)](typeof t,r[e(955)])?SE(t):(r[e(1269)](t,IDBTransaction)&&r[e(989)](bE,t),r[e(402)](F0,t,r.NnvZQ(yE))?new Proxy(t,Eo):t)}function Pt(t){let e=L,r={cUpJJ:function(o,c){return o(c)},uZOqW:function(o,c){return o!==c}};if(t instanceof IDBRequest)return r[e(232)](EE,t);if(go.has(t))return go.get(t);let i=r[e(232)](IE,t);return r[e(354)](i,t)&&(go[e(591)](t,i),_o[e(591)](i,t)),i}var F0,P0,L0,Jc,yo,Vc,go,_o,Eo,Ni,N0=z0({"node_modules/idb/build/wrap-idb-value.js"(){let t=L,e={SHmMc:function(r,i){return r instanceof i},NJcXw:function(r,i){return r===i},mtUMb:t(917),ePjJE:"store",TSpAr:function(r,i){return r===i},JZIwh:"exqwZ",BDSOz:function(r,i){return r(i)},JqhCo:function(r,i){return r===i}};F0=(r,i)=>i[t(623)](o=>r instanceof o),Jc=new WeakMap,yo=new WeakMap,Vc=new WeakMap,go=new WeakMap,_o=new WeakMap,Eo={get(r,i,o){let c=t;if(e[c(357)](r,IDBTransaction)){if(e[c(1082)](i,e[c(816)]))return yo[c(848)](r);if(e[c(1082)](i,c(952)+c(1144)))return r[c(952)+c(1144)]||Vc[c(848)](r);if(i===e.ePjJE){if(e[c(1295)](c(629),e.JZIwh))return o["objectSt"+c(1144)][1]?void 0:o["objectSt"+c(1304)](o[c(952)+c(1144)][0]);_0x14e518(this,_0x33b891,[_0x38f1be,_0x2f28a0,_0x5cbd9b])}}return e[c(1272)](Pt,r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return e[o(357)](r,IDBTransaction)&&(e[o(1082)](i,"done")||e[o(1357)](i,o(1353)))?!0:i in r}},Ni=r=>_o[t(848)](r)}}),U0={};wE(U0,{deleteDB:()=>TE,openDB:()=>AE,unwrap:()=>Ni,wrap:()=>Pt});function AE(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let d=L,f={bqcLR:function(m,g,A,w,E){return m(g,A,w,E)},GmyBw:function(m,g){return m(g)},dedMF:function(m,g){return m(g)},APtdi:"versionc"+d(653),rMVmp:d(924)+d(615),TMZSu:"blocked"},h=indexedDB[d(756)](t,e),x=Pt(h);return i&&h[d(1330)+d(1012)](f.rMVmp,m=>{let g=d;f[g(1177)](i,f[g(1370)](Pt,h[g(443)]),m[g(750)+"on"],m[g(1004)+"on"],f[g(779)](Pt,h[g(1183)+g(1398)]))}),r&&h[d(1330)+"Listener"](f[d(320)],()=>r()),x[d(538)](m=>{let g=d;c&&m[g(1330)+g(1012)](g(627),()=>c()),o&&m["addEvent"+g(1012)](f.APtdi,()=>o())})[d(512)](()=>{}),x}function TE(t,{blocked:e}={}){let r=L,i={wKDuK:"blocked",RNNTL:function(c,d){return c(d)}},o=indexedDB[r(408)+r(1121)](t);return e&&o[r(1330)+r(1012)](i[r(1442)],()=>e()),i[r(389)](Pt,o)[r(538)](()=>{})}function M0(t,e){let r=L,i={gbvSC:function(h,x){return h===x},PqxRx:r(1113),omzPv:r(1616),ihmrl:r(496)+"e",GysNj:r(1338),jkKUn:function(h,x){return h instanceof x},zsZOH:function(h,x){return h in x},PerkH:r(367),mxvqU:function(h,x){return h!==x}};if(!(i[r(246)](t,IDBDatabase)&&!i.zsZOH(e,t)&&i.gbvSC(typeof e,i[r(1066)])))return;if(mo[r(848)](e))return mo[r(848)](e);let o=e.replace(/FromIndex$/,""),c=i[r(1284)](e,o),d=j0[r(1579)](o);if(!i.zsZOH(o,(c?IDBIndex:IDBObjectStore).prototype)||!(d||G0[r(1579)](o)))return;let f=async function(h,...x){let m=r;if(i[m(578)](i[m(312)],i[m(430)]))this[m(1111)+"ype"]=_0x2010cf,this._ws&&(this[m(531)][m(928)+"pe"]=_0x22998d);else{let g=this[m(1183)+"ion"](h,d?i[m(1171)]:i[m(1299)]),A=g[m(1353)];return c&&(A=A.index(x[m(1425)]())),(await Promise[m(1471)]([A[o](...x),d&&g[m(917)]]))[0]}};return mo[r(591)](e,f),f}function ee(t,e){t=t-224;let r=wo(),i=r[t];if(ee.LOeQKl===void 0){var o=function(h){let x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",m="",g="";for(let A=0,w,E,I=0;E=h.charAt(I++);~E&&(w=A%4?w*64+E:E,A++%4)?m+=String.fromCharCode(255&w>>(-2*A&6)):0)E=x.indexOf(E);for(let A=0,w=m.length;A<w;A++)g+="%"+("00"+m.charCodeAt(A).toString(16)).slice(-2);return decodeURIComponent(g)};ee.kCHBlK=o,ee.eGQffc={},ee.LOeQKl=!0}let c=r[0],d=t+c,f=ee.eGQffc[d];return f?i=f:(i=ee.kCHBlK(i),ee.eGQffc[d]=i),i}var G0,j0,mo,RE=z0({"node_modules/idb/build/index.js"(){let t=L,e={KgFDk:function(r){return r()},iHOaO:function(r){return r()},wcHQb:"get",pZjwb:t(1522),naZUM:"getAllKeys",fjTjH:t(1240),NHLLk:t(317),ZsJSu:t(827),wkXJt:t(537),KbhkJ:t(1174),nXqKl:function(r,i){return r(i)}};e[t(1200)](N0),e.iHOaO(N0),G0=[e[t(865)],e[t(1027)],t(225),e[t(987)],e[t(483)]],j0=[e.NHLLk,e.ZsJSu,e[t(944)],e[t(1336)]],mo=new Map,e.nXqKl(vE,r=>({...r,get:(i,o,c)=>M0(i,o)||r.get(i,o,c),has:(i,o)=>!!M0(i,o)||r.has(i,o)}))}}),CE={idb:function(t){let e=L;t[e(1038)]=Promise[e(943)]()[e(538)](()=>(RE(),U0))[e(538)](function(r){return r})}},B0={};function Ot(t){let e=L,r={UWLIx:function(c,d){return c!==d}};var i=B0[t];if(r[e(396)](void 0,i))return i[e(1038)];var o=B0[t]={exports:{}};return CE[t](o,o[e(1038)],Ot),o[e(1038)]}Ot.d=(t,e)=>{let r=ee;for(var i in e)Ot.o(e,i)&&!Ot.o(t,i)&&Object[r(681)+r(1281)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=L;Ot.o=(e,r)=>Object[t(1201)+"e"][t(1573)+"operty"][t(235)](e,r)})(),(()=>{let t=L,e={VvRfi:function(r,i){return r!=i},ukdnx:t(614)+"d",EknmU:"Module",NtGYL:"__esModule"};Ot.r=r=>{let i=t;e[i(1070)](e.ukdnx,typeof Symbol)&&Symbol["toString"+i(328)]&&Object[i(681)+i(1281)](r,Symbol[i(361)+"Tag"],{value:e[i(564)]}),Object[i(681)+"operty"](r,e.NtGYL,{value:!0})}})();var Re={};(()=>{let t=L,e={PZjcL:function(a,n){return a(n)},NMHtH:function(a,n){return a+n},NkPDF:function(a,n,s){return a(n,s)},rrfUW:function(a,n){return a+n},sZfCU:function(a,n){return a(n)},nCDtF:function(a,n){return a+n},OFgrR:"0000",TJZUM:"ffff",yUGVv:t(1028)+"00000000"+t(1028)+"00000000",jbbPU:function(a,n){return a>n},nZoYH:function(a,n){return a<n},BBFpr:function(a,n){return a>n},QPmIr:function(a,n){return a<n},WYRQf:function(a,n){return a!==n},uUygi:function(a,n){return a!==n},KaAlD:function(a,n){return a-n},kMdiG:function(a,n){return a<n},DeGxD:function(a,n){return a===n},ZsuDF:function(a,n){return a===n},AvxIC:"ZmZAy",UwEKf:t(1576),QTAnA:function(a,n){return a!==n},ZwfyR:function(a,n){return a!==n},bOLDA:function(a,n,s){return a(n,s)},ZGLzp:function(a,n,s){return a(n,s)},LcZrr:function(a,n,s){return a(n,s)},AXJbm:t(1052),Gvnme:t(1186),CYvyY:t(1172),kCKMR:function(a){return a()},PcuPo:function(a,n){return a===n},ovyMC:t(1482),YBklw:function(a,n){return a(n)},msdGK:function(a,n){return a>>>n},KtnPW:function(a,n,s){return a(n,s)},CakPf:function(a,n){return a(n)},fwnhI:function(a,n,s){return a(n,s)},koLyf:function(a,n){return a&n},whSna:t(527)+t(842)+" field: "+t(1528),XxtfH:function(a,n,s){return a(n,s)},cDmhY:function(a,n){return a===n},JnZKo:"rzzsI",eDMBb:function(a,n){return a!==n},TfNgW:function(a,n){return a(n)},tiQEp:function(a,n){return a!==n},JlXDF:function(a,n,s){return a(n,s)},cYeoi:function(a,n,s){return a(n,s)},kZDfN:function(a,n){return a(n)},JPjhy:function(a,n){return a!==n},cYPEr:function(a,n){return a!==n},cMcMC:function(a,n,s){return a(n,s)},MOMeT:function(a,n,s){return a(n,s)},ZuRAI:function(a,n){return a!==n},mhmzi:function(a,n,s){return a(n,s)},BjagW:t(963),MNwQu:function(a,n,s){return a(n,s)},GKMZR:function(a,n){return a!==n},hDZip:t(1446),HksEI:"eijnh",LFUqC:function(a,n){return a(n)},dHzVS:function(a,n){return a|n},rwrHq:function(a,n){return a<<n},olSNV:function(a,n){return a<<n},ePpvv:function(a,n){return a&n},Uvuow:function(a,n){return a>n},GfJLD:function(a,n){return a+n},ziBme:function(a,n){return a===n},LCcMK:function(a,n){return a(n)},vrupg:t(854)+t(929)+t(673)+"ting ser"+t(1559),MvZPK:function(a,n){return a!==n},pvyac:"FuLwe",IZErJ:function(a,n){return a(n)},qGOGc:function(a,n){return a(n)},FKVgF:function(a,n,s){return a(n,s)},LCkHz:function(a,n){return a(n)},gGLea:function(a,n,s){return a(n,s)},HaFof:function(a,n){return a(n)},tjEYV:function(a,n,s){return a(n,s)},NGfLT:function(a,n){return a(n)},BVfoE:function(a,n){return a(n)},RPSnt:function(a,n,s){return a(n,s)},gAMPz:t(527)+t(842)+t(667)+t(1465),TQUjD:t(527)+t(842)+" field: "+t(1327),wUzVl:t(527)+t(842)+t(667)+t(586),kbwYe:function(a,n){return a(n)},pDYtu:t(788),ivgbc:function(a,n){return a>=n},gUAGD:function(a,n){return a>n},uprBZ:"Skip pas"+t(400),OJRGe:function(a,n){return a*n},adTNd:t(701)+t(400),ItqTI:function(a,n,s){return a(n,s)},MQedQ:function(a,n,s){return a(n,s)},RzviQ:function(a,n,s){return a(n,s)},gmROC:function(a,n){return a===n},PVLaD:function(a,n){return a&n},RgTwP:function(a,n){return a(n)},qbidF:function(a,n){return a!==n},gkzyu:t(236),iJNpL:t(940),jiglj:function(a,n){return a<<n},BrCdi:function(a,n){return a&n},lwCAz:function(a,n){return a(n)},NePXh:function(a,n){return a==n},NJuEr:function(a,n){return a&n},Djxux:function(a,n){return a+n},VXHzU:function(a,n){return a|n},myPfO:function(a,n){return a<<n},AxcgD:function(a,n){return a&n},qGXIS:function(a,n){return a<=n},nrZwl:function(a,n){return a==n},lJpAH:function(a,n){return a&n},uuSDT:function(a,n){return a+n},sRhEI:function(a,n){return a<<n},LiCTB:function(a,n){return a<<n},gcYAz:function(a,n){return a|n},qmMgA:function(a,n){return a&n},gWPZC:function(a,n){return a&n},TeVkt:function(a,n){return a<n},AKnLV:function(a,n){return a>n},FyMrv:function(a,n,s){return a(n,s)},snrfS:function(a,n){return a+n},pjrYv:function(a,n){return a>>n},cCIDl:function(a,n){return a+n},tNIfR:"text/jav"+t(694),QRUdP:t(837),BIyYG:t(883)+t(678)+t(721)+"P",GnqtG:t(1536)+t(1642),EKGIH:function(a,n){return a<n},YeKOG:t(907),nUyxI:function(a,n){return a<n},xKBQV:function(a,n){return a+n},uqFng:function(a,n){return a<n},MSYTl:function(a,n,s){return a(n,s)},tOrhC:function(a,n){return a>=n},CQGac:function(a,n){return a<n},GYzAd:function(a,n){return a+n},HpFLC:function(a,n){return a-n},IOGEC:function(a,n){return a<n},eTfOn:function(a,n){return a&n},HhFGA:function(a,n){return a<n},TwuGj:function(a,n){return a|n},jkpOI:function(a,n){return a&n},eLydz:"Tscfc",SqZgK:function(a,n){return a|n},BlDYn:function(a,n){return a>>n},kNYPF:function(a,n){return a&n},hLsBh:function(a,n){return a>>n},ZCtvu:function(a,n){return a|n},mtbbV:t(1282),fMkim:t(563),zBgQE:function(a,n){return a(n)},HZEfm:function(a,n){return a<n},yuBsa:function(a,n){return a&n},hBPHK:function(a,n){return a(n)},jyrRD:function(a,n){return a>=n},celQr:function(a,n){return a===n},Cfafh:t(1435),MbAGK:function(a,n,s){return a(n,s)},JPfcR:function(a,n){return a&n},uUyyF:function(a,n){return a===n},BtqWD:"krBDI",tqxOq:function(a,n){return a&n},vLRXP:function(a,n){return a&n},CzBHO:function(a,n){return a(n)},ZnZho:function(a,n){return a&n},CJSzw:function(a,n){return a&n},hEpma:function(a,n){return a===n},wcrFC:"fqHob",nwVbj:function(a,n){return a&n},FYCmo:function(a,n){return a&n},Ovlvb:function(a,n){return a&n},GeVMy:function(a,n){return a>>>n},ljhWp:function(a,n){return a<<n},VhRso:function(a,n){return a|n},HIDYG:function(a,n){return a>>>n},Dylxh:function(a,n){return a<n},sUXsw:function(a,n){return a<n},ypMeK:function(a,n){return a<n},IwiSR:function(a,n){return a<n},RZisP:function(a,n){return a+n},tuvpX:function(a,n){return a&n},AnKPG:function(a,n){return a!==n},kVAej:function(a,n){return a|n},ueSse:function(a,n){return a&n},ADGmU:function(a,n){return a>>>n},emgro:function(a,n){return a+n},uqAaa:function(a,n){return a|n},pnDzl:function(a,n){return a>>>n},EJtkQ:function(a,n){return a&n},yAQly:function(a,n){return a!==n},kIfbb:function(a,n){return a>>>n},dFtiH:function(a,n){return a>>>n},wGxPn:function(a,n){return a+n},EqxCK:function(a,n){return a|n},wjgNC:function(a,n){return a|n},gGSGS:function(a,n){return a&n},LiIFY:function(a,n){return a>>>n},BQXUF:function(a,n){return a!==n},vWIqr:function(a,n){return a|n},IbKut:function(a,n){return a>>>n},xRAcq:function(a,n){return a>>>n},XLAdu:function(a,n){return a|n},dYJDT:function(a,n){return a===n},LnZqC:function(a,n){return a|n},WlfCk:function(a,n){return a<<n},RPMID:function(a,n){return a<<n},mRNPv:function(a,n){return a|n},GYOjF:function(a,n){return a|n},PrwxP:function(a,n){return a|n},vGxjD:function(a,n){return a<<n},OsMOk:function(a,n){return a<<n},HHWZb:function(a,n){return a<<n},lDUjv:function(a,n){return a<<n},Fsiwo:function(a,n){return a<<n},YEvMJ:function(a,n){return a|n},GOjwe:function(a,n){return a<<n},nlIoC:function(a,n){return a>>>n},VeFrC:function(a,n){return a<<n},CjxXD:function(a,n){return a<<n},dUHKe:function(a,n){return a===n},CGbjh:t(1176),bVOwS:function(a,n){return a&n},HTcbR:function(a,n){return a>>>n},FtMHA:function(a,n){return a>>>n},KgEjC:function(a,n){return a>>>n},UehXK:function(a,n){return a>=n},ubZIb:function(a,n){return a+n},SdChX:function(a,n){return a%n},LLkob:function(a,n){return a/n},SkxKn:function(a,n){return a+n},QPTrW:function(a,n){return a>>>n},aYoAE:function(a,n){return a+n},FNFLG:function(a,n){return a*n},JuIUc:function(a,n){return a===n},RaOQJ:function(a,n){return a&n},NdlOy:function(a,n){return a+n},tbdtB:function(a,n){return a+n},DEswB:function(a,n){return a<<n},PqGKO:function(a,n){return a===n},qGdGO:function(a,n){return a>>>n},BkDVL:function(a,n){return a===n},rMBTb:function(a,n){return a+n},xYpKS:function(a,n){return a&n},uamPt:function(a,n){return a>>>n},HChIq:function(a,n){return a>>>n},OjYDc:function(a,n){return a>>>n},NNbIj:t(469)+t(691),sFOlY:t(1507)+t(278),Xvlxr:t(315)+t(1626),iGbek:t(1e3)+"ERROR",rLPzB:"OPEN_ERROR",aeOsL:"MAX_RETR"+t(1313)+"R",xVSec:t(515),mXRsD:t(1206),FmkUI:function(a,n){return a===n},hvjJs:"hEiMV",OnetQ:t(849),wwJRO:t(333),pPGjd:function(a,n){return a>=n},Gwmwr:t(1298),wOwmJ:t(700)+t(1255),JInLZ:function(a,n){return a+n},FhggX:function(a,n){return a===n},sqZyJ:t(231),gEPIb:function(a,n,s){return a(n,s)},jrwae:"close",fQHUw:t(756),TxnAj:function(a,n,s){return a(n,s)},YfoaB:function(a,n){return a!==n},oTGYd:t(1156),eTuDJ:function(a,n,s){return a(n,s)},CSCAu:function(a,n,s){return a(n,s)},pcbXq:function(a,n){return a instanceof n},WfpJJ:"ZvewY",joXKj:t(1083),Wtnuo:t(725),vqJrK:t(1468),lWurA:function(a,n){return a-n},MvbMU:"DxjZd",jxquP:function(a,n){return a||n},BLCee:function(a,n){return a||n},HrqZX:function(a,n){return a!=n},vIhqX:t(614)+"d",isnpJ:function(a,n){return a===n},dRfKH:t(1006),rXtwn:"2|1|3|0|4",DxPou:function(a,n){return a<=n},DVRoi:function(a,n){return a(n)},MYIOa:function(a,n){return a<n},gTQHB:function(a,n){return a===n},USIRJ:function(a,n){return a+n},gtzsj:function(a,n){return a<n},ALbvH:function(a,n){return a<n},OhFfi:function(a,n){return a===n},Ojiuz:t(1276),OyDTN:"fVtzl",oAtsZ:function(a,n){return a<=n},JWZZS:function(a,n){return a>=n},YWPPC:function(a,n){return a&n},wUlOZ:function(a,n){return a&n},sWnFp:function(a,n){return a>=n},IOCcl:function(a,n){return a|n},cyiBx:function(a,n){return a|n},fNWkz:function(a,n){return a<<n},Japtg:function(a,n){return a+n},OMJUI:function(a,n){return a>>n},cVCXH:function(a,n){return a<n},fDiZe:function(a,n){return a|n},Csniy:function(a,n){return a&n},TIayt:function(a,n){return a+n},FTsRb:function(a,n){return a&n},SRjxA:function(a,n){return a&n},xEtUj:function(a,n){return a|n},yDUol:function(a,n){return a|n},KPFMU:function(a,n){return a|n},kidSo:function(a,n){return a&n},SncRc:function(a,n){return a>>n},DsSdL:function(a,n){return a|n},GPWCV:function(a,n){return a-n},JVJAv:function(a,n){return a instanceof n},yRtDW:t(367),Wqdoo:"applicat"+t(1264),dxjvL:"text/pla"+t(802)+t(908),bDKAU:t(1347),WFKjl:"pfQZb",EZjiv:t(1047),TFQxR:"ppe",TVoyG:function(a,n){return a>=n},XtWDZ:t(618),EMvEv:function(a,n){return a+n},LMIBs:function(a,n){return a(n)},jTrBK:t(1102)+"or",NeNqn:function(a){return a()},ffkcz:function(a,n){return a===n},yFLEf:t(794),qyJnC:"blocked",ohwqH:t(1504),FRrJj:t(241)+t(1133)+t(1138)+"8",dsyzA:function(a,n){return a>>>n},XOrUi:function(a,n){return a&n},WkCWJ:function(a,n){return a<n},YtqBi:function(a,n){return a|n},AXeTI:function(a,n){return a|n},UKrgs:function(a,n){return a>>>n},xwABW:function(a,n,s,l){return a(n,s,l)},xfCaU:function(a,n){return a|n},wumAv:function(a,n){return a&n},MsXTD:function(a,n){return a|n},qQoKv:function(a,n){return a===n},LLIxj:t(1542),YrCGk:function(a,n){return a!==n},pheuS:t(945),Awzzq:"CUWhf",TVZTB:function(a,n){return a!==n},TUNqb:t(1426),PPpow:t(1175),SfuVq:t(292),hATru:function(a,n){return a||n},outkw:function(a,n){return a!==n},pKPFo:"jcojh",mxRwR:function(a,n){return a||n},khdBW:function(a,n){return a||n},oiVbr:function(a,n){return a!==n},PYrpb:t(1340)+t(395)+"ing",GEEmV:function(a,n){return a||n},jZhCA:t(501),xycTs:function(a,n){return a||n},aWAog:function(a,n){return a!=n},UJHLZ:function(a,n){return a||n},agSJp:t(316)+"DB failed",ClMdf:function(a,n,s){return a(n,s)},wAODF:t(731),awRQM:t(1228)+"id",UQLeH:function(a,n){return a(n)},QGFmv:function(a,n,s){return a(n,s)},urIcN:function(a,n){return a||n},VwfZF:function(a,n){return a!=n},RHSZY:t(562),WedFn:"VfWnz",tPVQb:function(a,n,s,l){return a(n,s,l)},bBnls:t(1283)+t(1449)+"ck",rKVbA:function(a,n,s,l){return a(n,s,l)},ovAxY:t(1283)+t(255)+"k",DcLTn:t(1283)+t(966)+t(307),pbomt:function(a,n,s,l){return a(n,s,l)},dYLMR:t(1472),aYBYE:"is_ack",NDhks:function(a,n){return a&&n},AwQiW:t(597),dTZmZ:function(a){return a()},QtZPq:function(a,n){return a instanceof n},KfOMn:function(a,n){return a instanceof n},GBwat:t(498)+t(1264)+";charset"+t(968),PIBTA:t(486)+"e",syZRV:t(637),xTGdb:function(a){return a()},FbyxA:function(a,n){return a<n},hUJuL:function(a,n){return a>n},EnrgR:function(a,n){return a+n},LiYeA:function(a,n){return a|n},DMZml:function(a,n){return a(n)},nsEGw:function(a,n){return a+n},Rcljb:function(a,n){return a+n},iQvrr:function(a,n){return a+n},kRIJB:"index out of ran"+t(957),Zayyk:t(677)+t(850)+"e",TdxSb:function(a,n,s,l){return a(n,s,l)},ocQOs:function(a,n){return a+n},KMdsV:function(a,n,s){return a(n,s)},AownE:function(a,n){return a<<n},MmoJX:function(a,n){return a<n},mKFpL:t(1224)+t(781)+"s",ZbEeX:function(a,n){return a!==n},QcRHE:"PbyOG",etYTp:function(a,n){return a|n},wkXXo:function(a,n){return a|n},DSXzN:function(a,n){return a|n},xnTya:function(a,n){return a<<n},YXMeQ:function(a,n){return a+n},hnrDl:function(a,n){return a<<n},NRRis:function(a,n){return a+n},KxBes:function(a,n){return a|n},NvzOr:function(a,n){return a|n},FptpX:function(a,n){return a+n},HkHWL:function(a,n){return a&n},YiaVm:function(a,n){return a&n},ALOWL:function(a,n){return a>>>n},fmIAX:function(a,n){return a+n},adhmB:function(a,n){return a&n},MeMPK:function(a,n){return a+n},lDzIg:function(a,n){return a>>>n},QMxbO:function(a,n){return a&n},uFzdI:function(a,n){return a>>>n},mYzPt:function(a,n){return a>>>n},fGrTW:function(a,n){return a+n},Effxe:function(a,n){return a&n},BZyim:function(a,n){return a+n},ozHIO:function(a,n){return a(n)},huWau:function(a,n){return a+n},XJrKz:t(431),eynjR:function(a,n){return a&n},LcorZ:function(a,n){return a&n},FbPgO:function(a,n){return a>>>n},KzszJ:function(a,n){return a|n},knadj:function(a,n){return a<n},Kaygg:function(a,n){return a>>>n},uXmyn:function(a,n){return a<n},yqtjX:function(a,n,s,l){return a(n,s,l)},Ksbbh:t(1327),GBNQO:function(a,n,s,l){return a(n,s,l)},eCrla:t(1021),aEvSR:"header",JbhVn:function(a,n,s,l){return a(n,s,l)},kaQbH:t(1391),CCNDi:t(310)+t(904),fKfmC:t(658)+t(1391),krsoK:function(a,n,s,l){return a(n,s,l)},LpvDY:function(a,n){return a(n)},oPNvw:function(a,n){return a(n)},ASurn:"cursor_f"+t(415),BoTda:function(a,n){return a<n},ooGiA:t(309),UlqDl:function(a,n,s){return a(n,s)},MqthA:function(a,n,s){return a(n,s)},zixuU:function(a,n){return a+n},tpcuC:t(334)+t(536),WaaWX:t(560)+t(996),nhEjH:"ALL",TCqEJ:t(581),cAtOx:function(a,n,s,l){return a(n,s,l)},YJdpb:function(a,n){return a(n)},GIUbB:function(a,n){return a!==n},nBQsh:"hzoqp",uKKCT:t(1216),RKTAo:t(1401),RdzyV:function(a,n){return a(n)},oeMwI:function(a,n){return a===n},aRRZB:"tryaQ",kXyBV:t(329)+"r",slKeR:function(a,n){return a||n},lTNqk:function(a,n){return a===n},WvZBg:t(1287),JWAir:t(852),msmdR:function(a,n,s){return a(n,s)},xfaUN:t(1283)+t(1583),uGvDJ:function(a,n,s,l){return a(n,s,l)},QzIkA:function(a){return a()},zDctH:"URuxO",GQxsK:t(458),YgNwj:function(a){return a()},jdZYY:function(a){return a()},OLstg:function(a){return a()},OBHBx:function(a){return a()},FnNsR:function(a,n){return a!==n},gdEfB:function(a){return a()},wzEOf:function(a,n){return a<n},IaHot:function(a,n,s){return a(n,s)},FWaDk:t(1395),lXmPi:function(a,n){return a!==n},ZfoyL:function(a,n){return a>=n},VjANg:function(a,n){return a===n},xepcB:t(1372),jhytV:t(435),UUdfj:t(426),bVkaa:t(1421),FyNbT:function(a,n,s){return a(n,s)},pGltD:t(673)+"t",OHnub:function(a,n){return a!==n},iCpAx:t(472),PGyBl:function(a,n){return a!==n},MRkmq:t(347),rvuRE:function(a,n){return a(n)},DoSlf:t(768)+t(1602),caApG:t(419),AgRMA:t(786),noxAW:t(453)+t(1169)+"alid url",qzAxo:t(453)+t(1552)+t(906)+t(1031)+t(1345)+"tructor "+t(709)+"ined",wQGRL:function(a,n,s){return a(n,s)},ZXYqu:t(253)+t(325)+t(1029)+"ct",LItne:t(749),OQypb:t(446),EMGzL:t(728),yRFxg:"pageshow",aYeRN:function(a,n){return a===n},QhZru:t(1459),gIRPK:function(a,n){return a!==n},kuIcK:"https:",kNzlK:"wss://",LzWqS:t(1127),AtpSu:t(1600),KSsRu:t(582),HgIOu:t(1120)+"d",ZZSbr:t(453)+"rovide b"+t(535)+t(822)+t(1632),YvXuX:t(360),pHCOT:t(1229),JzwtH:t(851)+"0",WdIyJ:function(a,n){return a||n},yAtOw:function(a,n,s){return a(n,s)},Xcoev:function(a,n){return a(n)},nYeWQ:"bfwXF",jxVgt:t(344),ZIExS:t(378)+">",IXLtT:t(936),YXNEy:function(a,n){return a>n},DBKjV:t(1224)+"e_timeout",XWnyA:t(390),ukORz:t(716)+t(1242)+"y closed",cXjcN:t(716)+t(1159)+t(466)+t(1554)+"ed",MYnVq:function(a,n){return a===n},TExhb:t(1296),LhnUM:t(1379),joVjJ:function(a,n){return a(n)},Dokad:t(1385),WeOIw:t(1099)+t(1044)+t(1036)+"g",Pssyn:function(a,n){return a(n)},qiLXz:function(a,n){return a===n},IhYUJ:"send_ack",DQocW:t(365)+"2",dFBiE:t(685),eUXxU:function(a,n,s){return a(n,s)},QmSfG:t(854)+t(1510)+t(381)+t(313),ivKZM:function(a,n){return a!==n},xPfeW:t(1550),IXlxh:function(a,n){return a+n},NXmtb:function(a,n,s){return a(n,s)},pakVJ:t(454),ExvOq:function(a,n){return a===n},eRXyv:t(463),SPFDz:function(a,n){return a==n},tnUaS:t(453)+"rovide a"+t(760)+t(1631)+t(1170)+"e a stri"+t(641)+t(1460)+"ffer",TubTI:function(a,n){return a==n},CgYfa:t(502),xYzIZ:function(a,n){return a instanceof n},BcraG:function(a,n){return a(n)},AuTUV:function(a,n){return a(n)},ujxDJ:function(a,n){return a(n)},qQKjj:t(453)+"rovide a"+t(1258)+t(904),FbWNg:function(a,n){return a instanceof n},xtLod:function(a,n){return a instanceof n},OLFBL:t(1594),LAXrt:t(911),iMyNv:function(a,n){return a==n},VhVLm:"KYaqz",kteTN:t(569),qzLmK:function(a,n){return a!==n},djsao:t(397),HxbQl:t(1011),WXRBZ:function(a,n,s){return a(n,s)},FOvof:t(1182),GEMOG:function(a,n){return a*n},FpVpx:function(a,n){return a*n},vbbLv:function(a,n){return a!=n},LGNje:function(a,n){return a===n},QOJno:t(1286),JGUoJ:"Object",hcRUu:t(807)+t(632)+t(1613)+"pe",OowNQ:function(a,n){return a===n},KJaff:function(a,n){return a!=n},vFoyZ:t(1009)+t(656)+t(739),UYjyS:function(a,n){return a===n},VmFzN:t(1213)+t(1089)+t(1475),sHoZY:function(a,n){return a===n},lGFhW:function(a,n){return a===n},WfDjP:function(a,n){return a!=n},ZFRpr:function(a,n){return a!=n},MyVvh:t(438)+t(1400)};Ot.r(Re),Ot.d(Re,{FWS:()=>Ap,CustomErrorEvent:()=>Ld,createCloseEvent:()=>ft,ReconnectEvent:()=>Pd,createErrorEvent:()=>rt,decodedFrame:()=>Vt,createOpenEvent:()=>Ud,CustomCloseEvent:()=>Nd,createReconnectEvent:()=>ea,FrontierMessageEvent:()=>Bd,encodeFrame:()=>Nt,createMessageEvent:()=>Fd,OpenEvent:()=>zd,ErrorCode:()=>Yt,Event:()=>Kn,MessageEvent:()=>Md});let r="";function i(a=""){let n=t,s="02",l=""+Date.now(),u=r||(r=e[n(449)](h,a)),_=Math[n(272)]().toString(16)[n(1566)](-6);return e[n(1585)](s,l)+u+_}function o(){let a=t;return e[a(1585)](1e4*Date[a(812)](),Math[a(980)](1e4*Math[a(272)]()))}function c(a){let n=t;return e[n(1585)](e[n(449)](Array,8).join("0"),e[n(1106)](parseInt,a,10).toString(2))[n(1566)](-8)}function d(a){let n=t;return e[n(1053)](Array(4)[n(1030)]("0"),parseInt(a,2)[n(361)](16))[n(1566)](-4)}function f(a){let n=t,s=a[n(387)](/\./).map(_=>c(_)),l=[];return l[0]=e.sZfCU(d,s[0]+s[1]),l[1]=e.PZjcL(d,e[n(1041)](s[2],s[3])),[e[n(1537)],e[n(1537)],n(1448),"0000",e[n(1537)],e[n(1103)],l[0],l[1]][n(1030)]("")}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(1155)](a),l=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[n(1155)](a);return s?e[n(362)](f,a):l?x(a):e[n(836)]}function x(a){let n=t,s="",l=[],u=0,_=0,v=!0,b=e[n(1537)];if(e[n(1408)](a[n(775)]("::"),-1)){let p=a[n(387)]("::");for(let B=0;e[n(478)](B,p.length);B++){let z=p[B];if(e[n(877)](z[n(775)](":"),0)){let U=z[n(387)](":");v&&(u=U[n(301)]),_+=U[n(301)];for(let H=0;e[n(1209)](H,U[n(301)]);H++)if(e[n(412)](4,U[H][n(301)])){let V=b.substring(0,4-U[H][n(301)]),it=V[n(529)](U[H]);l[n(1503)](it)}else l[n(1503)](U[H]);v=!1}else{if(e[n(376)](4,z.length)){let U=b[n(1293)+"g"](0,e[n(413)](4,z.length)),H=U.concat(z);l[n(1503)](H)}else l[n(1503)](z);v&&(u+=1),_+=1,v=!1}}let k="";for(let B=0;e[n(920)](B,e[n(413)](8,_));B++)k=k.concat(b);for(let B=0;e.QPmIr(B,l[n(301)]);B++)e.DeGxD(B,u)&&(s=s.concat(k)),s=s[n(529)](l[B]);return s}if(e[n(1436)](e[n(909)],e.UwEKf))this[n(474)]?.[n(627)](),this[n(474)]=void 0;else{let p=a[n(387)](":");for(let k=0;k<p.length;k++){let B=p[k];if(e[n(1607)](4,p[k][n(301)])){let z=b[n(1293)+"g"](0,4-p[k][n(301)]),U=z[n(529)](B);s=s.concat(U)}else s=s[n(529)](B)}return s}}function m(a,n){let s=t,l=a[s(441)];e[s(1125)](void 0,l)&&(e[s(1246)](fe,n,10),e[s(1126)](j,n,l));let u=a[s(1528)];u!==void 0&&(e[s(1571)](fe,n,18),j(n,u))}function g(a){let n=t,s={WTVnv:function(l,u){return e[ee(362)](l,u)},UNeEq:n(1102)+"or"};if(e[n(789)](n(1482),e[n(640)])){let l={};e:for(;!Z(a);){let u=e[n(682)](le,a);switch(e[n(1192)](u,3)){case 0:break e;case 1:l[n(441)]=e[n(1025)](O,a,e[n(296)](le,a));break;case 2:l[n(1528)]=e.fwnhI(O,a,e[n(362)](le,a));break;default:R(a,e[n(464)](7,u))}}if(l[n(441)]===void 0)throw new Error(n(527)+n(842)+n(667)+n(441));if(e[n(1436)](void 0,l[n(1528)]))throw new Error(e[n(348)]);return l}else return this[n(1119)+n(1251)+n(1445)+"t"]=1,this[n(1625)+n(1008)]++,this.endpoints[this[n(1625)+n(1008)]]}function A(a){let n=e.kCKMR(C);return w(a,n),e.sZfCU(M,n)}function w(a,n){let s=t;if(e.cDmhY(s(1356),e[s(425)])){let l=a[s(1158)];l!==void 0&&(fe(n,8),e[s(1025)](lt,n,l));let u=a[s(1465)];e[s(1494)](void 0,u)&&(e.ZGLzp(fe,n,16),e[s(1126)](lt,n,u));let _=a.service;e[s(412)](void 0,_)&&(e[s(1025)](fe,n,24),lt(n,e.TfNgW(P,_)));let v=a[s(586)];e.tiQEp(void 0,v)&&(e[s(579)](fe,n,32),lt(n,P(v)));let b=a.headers;if(e[s(1607)](void 0,b))for(let it of b){e[s(1612)](fe,n,42);let Qt=C();e.JlXDF(m,it,Qt),e[s(1627)](fe,n,Qt.limit),W(n,Qt),e[s(866)](D,Qt)}let p=a.payloadEncoding;e[s(787)](void 0,p)&&(e[s(1126)](fe,n,50),e[s(1246)](j,n,p));let k=a[s(518)+s(1517)];e[s(1393)](void 0,k)&&(e.cMcMC(fe,n,58),e[s(932)](j,n,k));let B=a[s(659)];e[s(675)](void 0,B)&&(fe(n,66),e[s(251)](fe,n,B[s(301)]),e[s(579)](he,n,B));let z=a[s(318)];e[s(1393)](void 0,z)&&(e[s(1393)](e[s(1513)],e[s(1513)])?(this[s(531)]&&this[s(531)].send(_0x40d242),this[s(1640)+s(510)][_0x51699f]=null):(fe(n,74),e[s(1227)](j,n,z)));let U=a["serverTi"+s(1180)];e.ZwfyR(void 0,U)&&(fe(n,82),j(n,U));let H=a.msgID;e.WYRQf(void 0,H)&&(e[s(1126)](fe,n,90),e[s(1612)](j,n,H));let V=a[s(1118)+"e"];if(e.JPjhy(void 0,V))if(e[s(818)](e.hDZip,e.HksEI))e.XxtfH(fe,n,96),e.cMcMC(lt,n,e.LFUqC(P,V));else{let it=this[s(1188)+s(456)]?.[s(465)+"ntEndpoint"]();this[s(303)](s(1467)+it),_0x39eb39()}}else{let l=e.XxtfH(_0x246ff4,e[s(1586)],{message:_0xe835f8[s(685)],code:_0x134b69[s(804)+"OR"],error:_0x57da8f});this["_dispatc"+s(1040)+s(364)](l)}}function E(a){let n=t;if(e.ziBme(n(1136),n(1096)))_0x50b5c3=e[n(1232)](e[n(1232)](e[n(1232)](e[n(1429)](7&_0xe82194,18),e[n(1390)](e.ePpvv(63,_0x13551f),12)),e[n(1390)](e.ePpvv(63,_0x47be1e),6)),63&_0x3b955f),_0x3ba4f1<65536||e[n(548)](_0x15efc5,1114111)?_0x55a411+=_0x5a995e:(_0x2df351-=65536,_0x488e6c+=e[n(1627)](_0x4650cc,(_0x2457b4>>10)+55296,e[n(1087)](e.koLyf(1023,_0x22d95d),56320)),_0x4ca85f+=3);else return e.LCcMK(I,e.YBklw(N,a))}function I(a){let n=t,s={};e:for(;!e[n(866)](Z,a);)if(e.MvZPK(n(844),e[n(935)])){let l=e[n(1351)](le,a);switch(e[n(1192)](l,3)){case 0:break e;case 1:s[n(1158)]=e[n(1126)](Et,a,!0);break;case 2:s[n(1465)]=Et(a,!0);break;case 3:s[n(1327)]=e.IZErJ(le,a);break;case 4:s[n(586)]=e[n(362)](le,a);break;case 5:{let u=e.qGOGc(S,a);(s[n(1364)]||(s.headers=[]))[n(1503)](g(a)),a.limit=u;break}case 6:s[n(979)+n(350)]=e[n(1612)](O,a,le(a));break;case 7:s[n(518)+n(1517)]=e[n(1630)](O,a,e[n(489)](le,a));break;case 8:s[n(659)]=_e(a,le(a));break;case 9:s.LogIDNew=e[n(974)](O,a,e.HaFof(le,a));break;case 10:s["serverTi"+n(1180)]=e[n(1059)](O,a,e[n(362)](le,a));break;case 11:s[n(440)]=O(a,e[n(901)](le,a));break;case 12:s[n(1118)+"e"]=e[n(1225)](le,a);break;default:e[n(1237)](R,a,7&l)}}else{if(!this[n(1101)+"orOnline"]()||this[n(669)+"osed"])return;this[n(1188)+n(456)]?.[n(1167)+n(814)+"fig"](),this[n(558)+"sCounter"]?.["resetCou"+n(684)](),this._ws?this[n(665)+"ect"](1001,e[n(1553)],!0):this[n(805)]()}if(e[n(1051)](void 0,s[n(1158)]))throw new Error("Missing "+n(842)+n(667)+n(1158));if(e[n(990)](void 0,s[n(1465)]))throw new Error(e.gAMPz);if(e.DeGxD(void 0,s[n(1327)]))throw new Error(e[n(1384)]);if(e[n(990)](void 0,s[n(586)]))throw new Error(e[n(1185)]);return s}function S(a){let n=t,s=e[n(1351)](le,a),l=a[n(511)];return a.limit=e[n(1041)](a.offset,s),l}function R(a,n){let s=t;switch(n){case 0:for(;e[s(464)](128,ie(a)););break;case 2:e.cMcMC(K,a,e[s(485)](le,a));break;case 5:K(a,4);break;case 1:K(a,8);break;default:throw new Error(e[s(1585)]("Unimplem"+s(1505)+s(783),n))}}function P(a){let n=t;return e[n(405)]!==e[n(405)]?this[n(531)]?this[n(531)].protocol:"":(a|=0,{low:a,high:a>>31,unsigned:e[n(1376)](a,0)})}let y=[];function C(){let a=t,n=y[a(910)]();return n?(n[a(1205)]=n[a(511)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function D(a){y[t(1503)](a)}function N(a){return{bytes:a,offset:0,limit:a[t(301)]}}function M(a){let n=t,s=a[n(1191)],l=a[n(511)];return s[n(301)]===l?s:s.subarray(0,l)}function K(a,n){let s=t;if(e[s(1349)](e[s(1585)](a.offset,n),a.limit))throw new Error(e[s(1244)]);a[s(1205)]+=n}function Z(a){let n=t;return a[n(1205)]>=a[n(511)]}function te(a,n){let s=t,l=a[s(1191)],u=a[s(1205)],_=a.limit,v=u+n;if(v>l[s(301)]){let b=new Uint8Array(e.OJRGe(2,v));b.set(l),a[s(1191)]=b}return a[s(1205)]=v,v>_&&(a[s(511)]=v),u}function X(a,n){let s=t,l=a[s(1205)];if(l+n>a[s(511)])throw new Error(e.adTNd);return a[s(1205)]+=n,l}function _e(a,n){let s=t,l=X(a,n);return a[s(1191)][s(916)](l,l+n)}function he(a,n){let s=t,l=e[s(544)](te,a,n.length);a[s(1191)][s(591)](n,l)}function O(a,n){let s=t,l={gxemQ:function(k,B,z){return e[ee(1145)](k,B,z)}},u=e[s(245)](X,a,n),_=String[s(242)+s(796)],v=a[s(1191)],b="\uFFFD",p="";for(let k=0;e[s(478)](k,n);k++){let B=v[k+u],z,U,H,V;e[s(1253)](e[s(1259)](128,B),0)?p+=e[s(727)](_,B):e[s(925)](e[s(1259)](224,B),192)?e[s(1376)](k+1,n)?p+=b:(z=v[e[s(1087)](k,u)+1],e[s(1125)](e[s(1160)](192,z),128)?p+=b:e[s(845)](e[s(1590)],e[s(1294)])?(V=e[s(306)](e[s(1160)](31,B),6)|e[s(228)](63,z),e[s(478)](V,128)?p+=b:(p+=e[s(1231)](_,V),k++)):(dMApqa[s(284)](_0x2685e9,_0x2a32e3,8),dMApqa[s(284)](_0x38ea73,_0x115380,_0x533deb))):e[s(1587)](e[s(566)](240,B),224)?k+2>=n?p+=b:(z=v[e[s(1585)](k,u)+1],U=v[e[s(626)](e[s(1087)](k,u),2)],e[s(1393)](e.dHzVS(z,U<<8)&49344,32896)?p+=b:(V=e[s(801)](e[s(801)]((15&B)<<12,e.myPfO(63&z,6)),e[s(433)](63,U)),e.QPmIr(V,2048)||e[s(1376)](V,55296)&&e[s(610)](V,57343)?p+=b:(p+=_(V),k+=2))):e.nrZwl(e[s(1489)](248,B),240)?e[s(1376)](e[s(1087)](k,3),n)?p+=b:(z=v[e[s(622)](e[s(626)](k,u),1)],U=v[e[s(1087)](k,u)+2],H=v[e[s(1585)](k+u,3)],e[s(464)](e[s(801)](z|e[s(867)](U,8),e[s(611)](H,16)),12632256)!==8421504?p+=b:(V=e[s(870)](e[s(1390)](7&B,18)|(63&z)<<12|e[s(611)](e[s(279)](63,U),6),e[s(833)](63,H)),e[s(1210)](V,65536)||e[s(1280)](V,1114111)?p+=b:(V-=65536,p+=e[s(382)](_,e[s(690)](e.pjrYv(V,10),55296),e.cCIDl(1023&V,56320)),k+=3))):p+=b}return p}function j(a,n){let s=t,l={qbzew:function(p,k){return e[ee(1225)](p,k)},zIVsS:e.GnqtG},u=n.length,_=0;for(let p=0;e.EKGIH(p,u);p++)if(e.DeGxD(e[s(543)],e.YeKOG)){let k=n.charCodeAt(p);e[s(1376)](k,55296)&&e[s(610)](k,56319)&&e[s(1511)](e[s(970)](p,1),u)&&(k=e[s(690)](k<<10,n.charCodeAt(++p))-56613888),_+=k<128?1:k<2048?2:e[s(1485)](k,65536)?3:4}else this.endpoints=_0x3172b2,this.maxRetries=_0x56d4cd,this[s(1625)+s(1008)]=0,this[s(1119)+s(1251)+s(1445)+"t"]=0;e[s(1474)](fe,a,_);let v=e[s(1474)](te,a,_),b=a[s(1191)];for(let p=0;p<u;p++){let k=n[s(896)+"At"](p);if(e[s(404)](k,55296)&&e[s(610)](k,56319)&&e[s(358)](e.GYzAd(p,1),u)&&(k=e[s(1598)](e[s(1053)](e[s(1390)](k,10),n[s(896)+"At"](++p)),56613888)),k<128)b[v++]=k;else{if(e[s(1407)](k,2048))b[v++]=e[s(801)](e.eTfOn(k>>6,31),192);else{if(e[s(459)](k,65536))b[v++]=e[s(274)](e[s(589)](k>>12,15),224);else if(e[s(1005)]!=="Tscfc"){let B=_0x6d37e7[s(1441)+s(291)](s(618));_0x439007[s(1488)+s(1633)]=z=>{let U=s;_0x71bc17[U(664)]["removeCh"+U(708)](B),_0x2d9025[U(1488)+U(1633)]=void 0,l[U(1141)](_0x1d68b6,z&&z[U(471)]||l[U(1523)])},B.type=e[s(1593)],B[s(719)]=_0x2d121d[s(398)](/^ws/,e.QRUdP)+e.BIyYG;try{_0x33638a[s(664)][s(304)+s(708)](B)}catch{_0x29cc1f[s(664)][s(1194)+s(708)](B)}}else b[v++]=e.SqZgK(e.lJpAH(k>>18,7),240),b[v++]=e[s(1232)](e[s(508)](k,12)&63,128);b[v++]=e.kNYPF(e[s(1498)](k,6),63)|128}b[v++]=e[s(462)](e[s(1259)](63,k),128)}}}function W(a,n){let s=t,l=te(a,n[s(511)]),u=a[s(1191)],_=n[s(1191)];for(let v=0,b=n.limit;e.nZoYH(v,b);v++)u[v+l]=_[v]}function ie(a){let n=t;return a[n(1191)][e[n(1233)](X,a,1)]}function $e(a,n){let s=t,l=e[s(1059)](te,a,1);a.bytes[l]=n}function le(a){let n=t,s={XeEmQ:function(l,u,_){return e.MNwQu(l,u,_)},ROZBl:e[n(1098)]};if(e[n(1051)](n(563),e[n(869)])){let l=0,u=0,_;do _=e[n(1492)](ie,a),e.HZEfm(l,32)&&(u|=e[n(611)](e[n(1274)](127,_),l)),l+=7;while(e.AxcgD(128,_));return u}else{let l=s[n(1115)](_0x4747fd,n(673)+"t",{message:s[n(793)]});this[n(1265)+n(395)]&&this[n(1265)+n(395)](l)}}function fe(a,n){let s=t,l={uRWuG:function(u,_){return e[ee(1637)](u,_)},Iishy:s(1536)+"reason"};for(n>>>=0;e.jyrRD(n,128);)e.celQr(e[s(1273)],e.Cfafh)?(e[s(1308)]($e,a,127&n|128),n>>>=7):(_0x10731c[s(1488)+s(1633)]=void 0,l[s(1447)](_0x245a1a,l[s(377)]));$e(a,n)}function Et(a,n){let s=t,l={cIPUS:function(u,_){return u<<_},jriAn:function(u,_){return e[ee(992)](u,_)}};if(e[s(1215)](e[s(964)],s(1245))){let u=_0x4dff75[s(685)][s(659)];u&&_0x3d0fe7[s(676)+"rs"](u)}else{let u=0,_=0,v=0,b;return b=e[s(296)](ie,a),u=e[s(464)](127,b),128&b&&(b=e[s(830)](ie,a),u|=e[s(833)](127,b)<<7,128&b&&(b=e[s(362)](ie,a),u|=e[s(306)](e[s(1311)](127,b),14),e[s(580)](128,b)&&(b=e[s(1481)](ie,a),u|=e[s(306)](127&b,21),e.ZnZho(128,b)&&(b=e[s(800)](ie,a),_=127&b,e[s(1274)](128,b)&&(b=ie(a),_|=(127&b)<<7,e[s(1514)](128,b)&&(b=ie(a),_|=e[s(1178)](127&b,14),128&b&&(e[s(1581)](e[s(521)],e[s(521)])?(b=ie(a),_|=e[s(611)](e[s(1478)](127,b),21),e[s(1247)](128,b)&&(b=e[s(449)](ie,a),v=e[s(1544)](127,b),128&b&&(b=e[s(1492)](ie,a),v|=e[s(1178)](e[s(1234)](127,b),7)))):(_0xe02660=_0x328604(_0x4f2ba2),_0x39309c|=l[s(1560)](l.jriAn(127,_0x4bc60d),7))))))))),{low:e[s(342)](u,e.olSNV(_,28)),high:e[s(1232)](e.GeVMy(_,4),e[s(792)](v,24)),unsigned:n}}}function lt(a,n){let s=t,l=n[s(421)]>>>0,u=e.GeVMy(e.VhRso(e[s(942)](n[s(421)],28),e[s(867)](n[s(759)],4)),0),_=n[s(759)]>>>24,v=_===0?u===0?e[s(455)](l,16384)?e[s(912)](l,128)?1:2:e.TeVkt(l,2097152)?3:4:e.ypMeK(u,16384)?u<128?5:6:e[s(643)](u,2097152)?7:8:e[s(742)](_,128)?9:10,b=te(a,v),p=a[s(1191)];switch(v){case 10:p[e.RZisP(b,9)]=e.tuvpX(e[s(1622)](_,7),1);case 9:p[b+8]=e[s(1419)](9,v)?e.kVAej(128,_):e.ueSse(127,_);case 8:p[b+7]=e.cYPEr(8,v)?e.VXHzU(e[s(942)](u,21),128):e.qmMgA(e[s(1611)](u,21),127);case 7:p[e[s(1117)](b,6)]=e[s(733)](7,v)?e.uqAaa(e.pnDzl(u,14),128):e[s(636)](e[s(1611)](u,14),127);case 6:p[b+5]=e.yAQly(6,v)?e.kVAej(e[s(1157)](u,7),128):e[s(228)](e.dFtiH(u,7),127);case 5:p[e[s(1433)](b,4)]=e[s(1125)](5,v)?e[s(1339)](128,u):e[s(1311)](127,u);case 4:p[e[s(1041)](b,3)]=e.qbidF(4,v)?e[s(1123)](e.kIfbb(l,21),128):e[s(748)](e.LiIFY(l,21),127);case 3:p[b+2]=e[s(1486)](3,v)?e.vWIqr(e[s(573)](l,14),128):e[s(1489)](e[s(1577)](l,14),127);case 2:p[b+1]=e[s(1607)](2,v)?e[s(870)](e.dFtiH(l,7),128):e[s(1234)](e[s(552)](l,7),127);case 1:p[b]=v!==1?e.VXHzU(128,l):e[s(992)](127,l)}}function Vt(a){return E(a)}function Nt(a){return e[t(830)](A,a)}let Jt=65536,Fr=e[t(1193)],ge=e[t(621)](Jt,Jt),Ie=e[t(532)](ge,ge),$n=e.LLkob(Ie,2),De=String[t(1201)+"e"][t(896)+"At"];class ce{constructor(n,s,l){let u=t;this[u(948)]=!0,this[u(421)]=e[u(1365)](0,n),this[u(759)]=e[u(1365)](0,s),this[u(470)]=!!l}static isLong(n){let s=t;return n&&e.dYJDT(!0,n[s(948)])}static[t(861)](n,s,l){return new ce(n,s,l)}static fromBytes(n,s,l){let u=t;return l?ce[u(898)+u(1238)](n,s):ce[u(898)+u(1603)](n,s)}static[t(898)+t(1238)](n,s){let l=t;return new ce(e.VXHzU(e[l(570)](n[0],e.WlfCk(n[1],8)),e.sRhEI(n[2],16))|e[l(322)](n[3],24),e[l(1266)](e[l(239)](e[l(870)](n[4],e.LiCTB(n[5],8)),n[6]<<16),n[7]<<24),s)}static["fromByte"+t(1603)](n,s){let l=t;return new ce(e[l(695)](e[l(342)](n[4]<<24,e.vGxjD(n[5],16)),e[l(375)](n[6],8))|n[7],e.SqZgK(e[l(1232)](e[l(1278)](n[0],24)|e[l(1614)](n[1],16),e[l(1079)](n[2],8)),n[3]),s)}static[t(791)](n){let s=t;return e[s(1581)](n,Fr)?Od:new ce(e[s(409)](e.ZCtvu(e[s(1403)](e.XLAdu(De.call(n,0),e[s(651)](De[s(235)](n,1),8)),De[s(235)](n,2)<<16),De.call(n,3)<<24),0),e[s(229)](e[s(239)](De.call(n,4)|e.VeFrC(De.call(n,5),8)|e[s(306)](De[s(235)](n,6),16),e[s(273)](De[s(235)](n,7),24)),0),!0)}[t(224)](){let n=t;return e.dUHKe(e[n(1236)],n(1575))?!!this[n(474)]:String[n(242)+n(796)](e[n(767)](255,this[n(421)]),e[n(1312)](e[n(1577)](this[n(421)],8),255),e.nwVbj(e[n(552)](this[n(421)],16),255),this[n(421)]>>>24,e[n(433)](255,this[n(759)]),e[n(748)](e[n(631)](this[n(759)],8),255),e[n(862)](this[n(759)],16)&255,e[n(533)](this[n(759)],24))}static[t(479)+"er"](n,s=!0){let l=t;if(isNaN(n))return s?zx:Od;if(s){if(e[l(1108)](n,Ie))return Ux}else{if(e[l(610)](n,-$n))return Gx;if(e.ubZIb(n,1)>=$n)return Fx}return ce.fromBits(e[l(1365)](e.SdChX(n,ge),0),e.EqxCK(e[l(1463)](n,ge),0),s)}toNumber(){let n=t;return this[n(470)]?e[n(1604)](e.OJRGe(e.QPTrW(this[n(759)],0),ge),this[n(421)]>>>0):e[n(1132)](e.FNFLG(this[n(759)],ge),this[n(421)]>>>0)}[t(1621)](){let n=t;return e[n(1253)](0,this[n(759)])&&e[n(1464)](0,this[n(421)])}[t(827)](n){let s=t;ce[s(948)](n)||(n=ce.fromNumber(n));let l=e[s(1622)](this[s(759)],16),u=e.ZnZho(65535,this.high),_=this[s(421)]>>>16,v=e.RaOQJ(65535,this[s(421)]),b=e[s(1534)](n[s(759)],16),p=e[s(589)](65535,n.high),k=e[s(533)](n[s(421)],16),B=e[s(433)](65535,n[s(421)]),z=0,U=0,H=0,V=0;return V+=v+B,H+=V>>>16,V&=65535,H+=e[s(1394)](_,k),U+=e[s(942)](H,16),H&=65535,U+=e[s(1354)](u,p),z+=e.HIDYG(U,16),U&=65535,z+=e.wGxPn(l,b),z&=65535,ce.fromBits(e[s(771)](e[s(1487)](H,16),V),z<<16|U,this[s(470)])}[t(1015)](n){let s=t;return ce[s(948)](n)||(n=ce.fromNumber(n)),e[s(412)](this[s(470)],n[s(470)])&&e[s(480)](e.qGdGO(this[s(759)],31),1)&&e[s(229)](n.high,31)===1?!1:e[s(1197)](this[s(759)],n[s(759)])&&e[s(1547)](this[s(421)],n[s(421)])}[t(1071)](){let n=t;return this.low===-1&&e[n(1581)](-1,this[n(759)])?ce[n(861)](0,0,this[n(470)]):this[n(421)]===-1?ce[n(861)](0,e[n(588)](this[n(759)],1),this[n(470)]):ce.fromBits(e[n(392)](this[n(421)],1),this[n(759)],this.unsigned)}[t(1480)](n){let s=t;return n?this[s(603)+"E"]():this[s(1166)+"E"]()}[t(603)+"E"](){let n=t,s=this[n(759)],l=this[n(421)];return[e.ZnZho(255,l),l>>>8&255,e[n(1378)](e[n(942)](l,16),255),e[n(1207)](l,24),e[n(868)](255,s),e.ePpvv(e.QPTrW(s,8),255),e.KgEjC(s,16)&255,e[n(573)](s,24)]}[t(1166)+"E"](){let n=t,s=this.high,l=this.low;return[e[n(631)](s,24),e[n(1274)](e.HChIq(s,16),255),s>>>8&255,e[n(833)](255,s),e[n(484)](l,24),e.QPTrW(l,16)&255,e[n(282)](l,8)&255,e.PVLaD(255,l)]}}let Od=new ce(0,0,!1),zx=new ce(0,0,!0),Fx=ce[t(861)](-1,2147483647,!1),Ux=ce.fromBits(-1,-1,!0),Gx=ce.fromBits(0,-2147483648,!1);var Yt=(function(a){let n=t,s=e[n(555)][n(387)]("|"),l=0;for(;;){switch(s[l++]){case"0":return a;case"1":a[a[e[n(982)]]=5001]=e[n(982)];continue;case"2":a[a[e[n(1432)]]=5002]=e[n(1432)];continue;case"3":a[a[e[n(495)]]=5004]=e[n(495)];continue;case"4":a[a[e[n(523)]]=5005]=e[n(523)];continue;case"5":a[a[e[n(1042)]]=5003]=e[n(1042)];continue}break}})({});class Kn{constructor(n){let s=t;this[s(819)]=n,this[s(287)]=null}}class Pd extends Kn{constructor(n,s){let l=t;super(n),this[l(685)]=s&&s[l(685)]||null}}class Ld extends Kn{constructor(n,s){let l=t,u=("3|6|5|0|"+l(1546))[l(387)]("|"),_=0;for(;;){switch(u[_++]){case"0":this[l(1515)]=s&&s[l(1515)]||"";continue;case"1":this[l(852)]=s&&s[l(852)]||5001;continue;case"2":this.lineno=s&&s.lineno||0;continue;case"3":super(n);continue;case"4":this[l(685)]=s&&s[l(685)]||"";continue;case"5":this[l(671)]=s&&s[l(671)]||0;continue;case"6":this[l(1186)]=s&&s[l(1186)]||null;continue}break}}}class Nd extends Kn{constructor(n,s){let l=t;super(n),this.code=s&&s[l(852)]||0,this[l(1642)]=s&&s.reason||"",this[l(811)]=s&&s[l(811)]||!1,this[l(1302)+"nnect"]=s&&s["willReco"+l(1529)]||!1}}class Md extends Kn{constructor(n,s){let l=t;super(n),this[l(1271)]=s&&s[l(1271)]||null}}class Bd extends Md{constructor(n,s){let l=t;super(n),this[l(1271)]=s&&s.data||null,this.message=s&&s[l(685)]||null}}class zd extends Kn{constructor(n,s){let l=t;super(n),this[l(1271)]=s&&s[l(1271)]||null}}function rt(a,{message:n,code:s,error:l}){let u=t;return e[u(790)]!==e[u(790)]?this[u(1168)][u(999)+"ns"]:new Ld(a,{message:n,code:s,error:l})}function ft(a,{code:n,reason:s,wasClean:l,willReconnect:u}){return new Nd(a,{code:n,reason:s,wasClean:l,willReconnect:u})}function Fd(a,{data:n,message:s}){return new Bd(a,{data:n,message:s})}function Ud(a,{data:n}){let s=t,l={YpGft:e[s(1545)]};return e[s(729)](e[s(372)],e[s(959)])?(_0x221990||(_0x12d77d=_0x3e9622[s(943)]().then(_0x3e8a59[s(1257)](_0x3080de,l[s(275)]))),_0x1e6141):new zd(a,{data:n})}function ea(a,{message:n}){return new Pd(a,{message:n})}class Gd{constructor(n,s){let l=t;this.endpoints=n,this.maxRetries=s,this[l(1625)+l(1008)]=0,this["currentE"+l(1251)+"riesCount"]=0}[t(1167)+"pointCon"+t(1629)](){let n=t;this[n(1625)+"ndex"]=0,this[n(1119)+n(1251)+n(1445)+"t"]=0}[t(416)+"es"](){let n=t;this[n(1119)+"ndpointT"+n(1445)+"t"]=0}[t(465)+t(706)+"nt"](){let n=t;return e[n(300)](e.wwJRO,n(399))?this[n(918)+"s"][this["currentI"+n(1008)]]:!!_0x3b71c9?.[n(886)](s=>s[n(441)]===_0x21a036&&s.value===_0x229264)}["getCurre"+t(706)+t(810)+t(782)](){let n=t;return this["currentE"+n(1251)+n(1445)+"t"]}[t(363)+t(605)+"es"](){let n=t;return!!(e[n(1262)](this[n(1625)+"ndex"],this[n(918)+"s"][n(301)])||e[n(1436)](this["currentI"+n(1008)],e[n(413)](this[n(918)+"s"][n(301)],1))&&this["currentE"+n(1251)+n(1445)+"t"]===this.maxRetries)}["checkCurrentEndp"+t(832)+t(1260)+"tries"](){let n=t;return e[n(1587)](this[n(1625)+n(1008)],this[n(918)+"s"][n(301)])?!0:this[n(1119)+n(1251)+"riesCount"]>this.maxRetries}["replaceB"+t(1220)+t(1001)+t(994)+t(1414)](){let n=t;return this[n(1119)+"ndpointT"+n(1445)+"t"]=1,this[n(1625)+"ndex"]++,this[n(918)+"s"][this[n(1625)+n(1008)]]}[t(465)+t(706)+"ntAndUpd"+t(1013)](){let n=t;return this["currentE"+n(1251)+n(1445)+"t"]++,this[n(465)+n(706)+"nt"]()}}let Zn=(e[t(831)](e[t(497)],typeof globalThis)&&e[t(1049)](t(1286),globalThis[t(710)+t(946)][t(1391)])||e[t(427)](t(614)+"d",typeof window)&&e.LGNje(e[t(821)],window[t(710)+"tor"].name))&&e[t(427)](t(614)+"d",typeof document),vn=e[t(1636)](t(614)+"d",typeof globalThis)&&(e[t(884)]===globalThis[t(710)+t(946)][t(1391)]||e.hcRUu===globalThis[t(710)+t(946)][t(1391)])&&e.vbbLv(e.vIhqX,typeof tt),Ur=(e.HrqZX(t(614)+"d",typeof globalThis)&&e.OowNQ(e[t(884)],globalThis[t(710)+t(946)][t(1391)])||e[t(497)]==typeof globalThis||e[t(497)]!=typeof globalThis&&!!globalThis[t(1558)+"Bridge"])&&e[t(593)](t(614)+"d",typeof wx),Gr=e[t(497)]!=typeof globalThis&&(e[t(289)]===globalThis[t(710)+t(946)][t(1391)]||e[t(480)](e[t(1620)],globalThis[t(710)+t(946)].name)||e[t(530)](e[t(1610)],globalThis["construc"+t(946)][t(1391)]))&&e.vIhqX!=typeof self,jx=e[t(497)]!=typeof globalThis&&e[t(871)](e.JGUoJ,globalThis[t(710)+t(946)].name)&&e.VwfZF(t(614)+"d",typeof global)&&e.lGFhW(t(1129),global[t(710)+t(946)][t(1391)])&&e.WfDjP(e.vIhqX,typeof process)&&!!process.version;class ta{constructor(){let n=t;this[n(525)+"rs"]={}}[t(835)](n,...s){let l=t,u=this[l(525)+"rs"][n];if(u)u[l(1566)]()[l(1381)](_=>_.fn[l(1323)](_[l(1334)],s));else if(e[l(789)](e[l(1586)],n)&&!this[l(1297)])if(l(746)===e[l(540)])_0x44812d[l(591)](_0x45fb10,_0x5c944f),_0x6a63bb[l(591)](_0xcef34c,_0x3587a0);else{let _=s.length&&s[0];if(_ instanceof Error)throw _;let v=new Error(e[l(1433)](e.wOwmJ,_?e.NMHtH(e[l(815)](" (",_[l(685)]),")"):""));throw v[l(1623)]=_,_}return this}[t(1596)](n,s){let l=t;if(n===void 0)this._listeners={};else if(e[l(697)](void 0,s))this._listeners[n]=null;else{let u=this[l(525)+"rs"][n];if(u)for(let _=0;e[l(1511)](_,u.length);)e[l(990)](u[_].fn,s)?u[l(285)](_,1):++_}return this}on(n,s,l){let u=t;if(e[u(1125)](e.sqZyJ,e[u(541)])){let _=e[u(1627)](_0x3e2a1b,_0x228ca2,1);_0x55db8d[u(1191)][_]=_0x18cb0d}else return(this[u(525)+"rs"][n]||(this[u(525)+"rs"][n]=[]))[u(1503)]({fn:s,ctx:l||this}),this}}class Hx extends ta{[t(436)+t(1388)+t(846)](n){let s=t;return n[s(1204)]||n.errNo?(s(633)+" "+(n[s(1204)]||"")+s(290)+(n[s(594)]||""))[s(1104)]():JSON.stringify(n)}constructor(n,s,l){let u=t;super(),this[u(1168)]=null,Ur&&wx[u(1122)+u(1202)]&&(this._socket=wx["connectS"+u(1202)]({url:n,protocols:s,header:l,fail:this["_createS"+u(565)+u(1043)].bind(this),success:this[u(1570)+"ocketSuccessHandler"][u(1257)](this)})),vn&&tt["connectS"+u(1202)]&&(this[u(1168)]=tt[u(1122)+u(1202)]({url:n,protocols:s,header:l,fail:this[u(1570)+"ocketFai"+u(1043)][u(1257)](this),success:this[u(1570)+u(1476)+"cessHand"+u(799)][u(1257)](this)}))}[t(1570)+"ocketSuccessHandler"](){let n=t;Promise[n(943)]()[n(538)](()=>{this["_addWsLi"+n(559)]()})}[t(1570)+"ocketFai"+t(1043)](n){let s=t;Promise[s(943)]()[s(538)](()=>{let l=s,u=e[l(1474)](rt,e[l(1586)],{message:this["_formatE"+l(1388)+l(846)](n)});this[l(835)](l(1186),u);let _=e.gEPIb(ft,e[l(557)],{reason:this[l(436)+"rrorMess"+l(846)](n)});this[l(835)](e[l(557)],_)})}[t(1195)+t(559)](){let n=t,s={jjBOX:e[n(951)],OcQPn:function(l,u,_){return e[n(326)](l,u,_)},tcHGY:e.jrwae,NiQuA:function(l,u){return e.hLsBh(l,u)},uSOhd:function(l,u){return e[n(1502)](l,u)},uNQrc:e[n(860)],lzobZ:n(685),MlkKi:e[n(1586)],nAFaO:function(l,u,_){return e[n(619)](l,u,_)}};this[n(1168)][n(1423)](l=>{let u=n;this[u(835)](s[u(550)],s[u(380)](Ud,s[u(550)],{...l,data:l[u(1204)]||""}))}),this._socket.onClose(l=>{let u=n;this[u(835)](s[u(1556)],ft(u(627),{...l}))}),this[n(1168)].onMessage(l=>{let u=n,_={lajgZ:function(v,b){return s.NiQuA(v,b)}};if(s.uSOhd(s[u(828)],u(1156)))return _0x5d10ad|=0,{low:_0x45bac7,high:ccqyQB.lajgZ(_0x1aca4d,31),unsigned:_0x1101f0>=0};this[u(835)](s[u(891)],s[u(380)](Fd,s[u(891)],{...l}))}),this._socket[n(715)](l=>{let u=n;this[u(835)](s[u(1022)],s.nAFaO(rt,s[u(1022)],{...l,message:l[u(1204)]||""}))})}[t(1124)](n){let s=t,l={fEJHF:"error"};if(e.pcbXq(n,Uint8Array)){let u=n[s(1409)][s(1566)](n[s(238)+"et"],e[s(626)](n.byteLength,n[s(238)+"et"]));this[s(1168)]&&this[s(1168)][s(1124)]({data:u,fail:_=>{let v=s;this[v(835)]("error",rt(l[v(976)],{message:this["_formatE"+v(1388)+v(846)](_)}))}})}else this[s(1168)]&&this._socket[s(1124)]({data:n,fail:u=>{let _=s;this[_(835)]("error",e[_(1112)](rt,e.Gvnme,{message:this[_(436)+_(1388)+_(846)](u)}))}})}[t(627)](n,s){let l=t;e.FhggX(e[l(1014)],e[l(777)])?_0x3dbe74.log(_0x88cfcc):this._socket&&this._socket[l(627)]({code:n,reason:s})}["addEvent"+t(1012)](n,s){this.on(n,s)}[t(755)+t(798)+t(1499)](n,s){this[t(1596)](n,s)}get readyState(){let n=t,s={kuCSr:function(l,u){return e[ee(1002)](l,u)},AGpai:function(l,u){return e[ee(1637)](l,u)}};if(e.Wtnuo!==e[n(302)]){let l=_0x38de39[n(235)](qwonXx[n(1375)](_0x5067be,this),_0x449541,..._0x2fb56c);return _0x1e9b72.set(l,_0x3b3eed.sort?_0x909e41[n(808)]():[_0x3abdd7]),qwonXx[n(237)](_0x2cd2a5,l)}else return this[n(1168)][n(660)+"te"]}get binaryType(){let n=t;if(e[n(295)]===e.vqJrK)return this[n(1168)][n(928)+"pe"];{let s=e.kCKMR(_0x276ff0);return e[n(1145)](_0x3ce27b,_0x40e371,s),e[n(489)](_0x1161a6,s)}}set binaryType(n){}get[t(666)](){let n=t;return this._socket[n(666)]}get[t(1154)](){let n=t;return this[n(1168)][n(1154)]}get[t(999)+"ns"](){return this[t(1168)].extensions}get[t(613)+"Amount"](){return 0}}function qx(a,n){let s=t;if(e[s(1502)](s(829),e[s(1562)])){if(e[s(376)](4,_0x47dabe[s(301)])){let l=_0x32b28f[s(1293)+"g"](0,e.lWurA(4,_0x72da9e[s(301)])),u=l.concat(_0x4e044c);_0x122ea2[s(1503)](u)}else _0x30f77b[s(1503)](_0x381caf);_0x16ae03&&(_0x1957b2+=1),_0x9dcf3e+=1,_0x2236d0=!1}else{if(n)return new n(a[s(666)],a[s(1154)]);if(e[s(839)](Ur,vn))return new Hx(a[s(666)],a[s(1154)],a[s(1364)]);if(e[s(1456)](Zn,Gr)&&e[s(961)](e.vIhqX,typeof WebSocket)&&WebSocket)return new WebSocket(a[s(666)],a[s(1154)+"s"])}}function Wx(a){let n=t;if(e[n(371)](e[n(339)],e[n(339)])){let s=e[n(1140)][n(387)]("|"),l=0;for(;;){switch(s[l++]){case"0":if(e[n(839)](Zn,Gr)&&e[n(961)](e[n(497)],typeof WebSocket)&&WebSocket)return!0;continue;case"1":if(Ur&&wx[n(1122)+n(1202)])return!0;continue;case"2":if(a)return!0;continue;case"3":if(vn&&tt[n(1122)+"ocket"])return!0;continue;case"4":return!1}break}}else return this[n(1168)][n(928)+"pe"]}function jd(a,n,s){let l=t,u={cDxAE:function(b,p){return e[ee(1078)](b,p)},dOItJ:l(1086)+l(1618)+"ltiple t"+l(248)+l(1396),FCqcQ:function(b,p){return e[l(1581)](b,p)},bPeyX:function(b,p){return b+p}},_=-1;async function v(b){let p=l;return u[p(776)](b,_)?Promise[p(1162)](new Error(u.dOItJ)):(_=b,u[p(885)](b,s[p(301)])?Promise[p(943)]():s[b][p(1257)](a)(n,v[p(1257)](null,u[p(545)](b,1))))}e[l(1548)](v,0)}function Hd(a){let n=t,s=0,l=0;for(let u=0;e[n(670)](u,a[n(301)]);++u)l=a[n(896)+"At"](u),e[n(1485)](l,128)?s+=1:e.ypMeK(l,2048)?s+=2:e.gTQHB(e[n(464)](64512,l),55296)&&e[n(729)](e[n(868)](64512,a[n(896)+"At"](e[n(1572)](u,1))),56320)?(++u,s+=4):s+=3;return s}function qd(a,n,s){let l=t;if(e[l(1373)](e.HpFLC(s,n),1))return"";let u="";for(let _=n;e[l(785)](_,s);)if(e.OhFfi(e[l(288)],e[l(346)]))this[l(819)]=_0x63d855,this[l(287)]=null;else{let v=a[_++];if(e[l(1067)](v,127))u+=String[l(242)+l(796)](v);else if(e.JWZZS(v,192)&&v<224)u+=String[l(242)+l(796)](e[l(1178)](e[l(1489)](31,v),6)|e[l(993)](63,a[_++]));else if(v>=224&&v<240)u+=String[l(242)+"Code"](e[l(1266)](e[l(1429)](e[l(464)](15,v),12),e[l(1429)](63&a[_++],6))|e[l(249)](63,a[_++]));else if(e.sWnFp(v,240)){let b=e.IOCcl(e[l(1416)]((7&v)<<18,e.fNWkz(63&a[_++],12))|e[l(375)](e[l(1259)](63,a[_++]),6),63&a[_++])-65536;u+=String[l(242)+l(796)](e[l(1256)](55296,e[l(711)](b,10))),u+=String[l(242)+l(796)](e.SkxKn(56320,e.gWPZC(1023,b)))}}return u}function na(a,n,s){let l=t,u=s,_,v;for(let b=0;e[l(806)](b,a[l(301)]);++b)_=a.charCodeAt(b),_<128?n[s++]=_:_<2048?(n[s++]=e[l(508)](_,6)|192,n[s++]=e[l(879)](63&_,128)):e[l(1641)](e.Csniy(64512,_),55296)&&e[l(480)](e.Ovlvb(64512,v=a[l(896)+"At"](e[l(895)](b,1))),56320)?(_=e.TIayt(65536,e.myPfO(e[l(764)](1023,_),10))+e[l(687)](1023,v),++b,n[s++]=e[l(1416)](e[l(711)](_,18),240),n[s++]=e[l(508)](_,12)&63|128,n[s++]=e[l(1368)](e[l(1378)](e.BlDYn(_,6),63),128),n[s++]=e[l(751)](e.vLRXP(63,_),128)):(n[s++]=e[l(1221)](e[l(508)](_,12),224),n[s++]=e[l(1266)](e[l(370)](e[l(271)](_,6),63),128),n[s++]=e[l(1520)](e.yuBsa(63,_),128));return e[l(1315)](s,u)}async function Wd(a){let n=t;if(e[n(1587)]("string",typeof a)){let s=new Uint8Array(Hd(a));return na(a,s,0),s}return e[n(1069)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(1409)],a[n(238)+"et"],a[n(1453)+"th"])}function $x(a){let n=t;try{return n(367)!=typeof a&&(e.JVJAv(a,ArrayBuffer)||a[n(1409)]&&e[n(1069)](a[n(1409)],ArrayBuffer))||e[n(1152)]!=typeof a?"":(JSON[n(638)](a),e[n(1496)])}catch{return e[n(1152)]==typeof a?e[n(772)]:""}}let Kx=(a,n)=>{let s=t;if(e[s(787)](e[s(973)],e[s(1300)]))switch(a){case e[s(890)]:case e[s(230)]:return{[s(1318)+a]:1,"x-tt-env":n};default:return{}}else Se[s(531)]&&Se[s(531)][s(627)](_0x6de4c5,_0x31854a)};class Zx{constructor(n){let s=t;this[s(491)+s(782)]=n,this[s(1240)]=0}addCount(){let n=t;this[n(1240)]++}[t(363)+t(1196)+"nt"](){let n=t;return e.TVoyG(this.count,this[n(491)+n(782)])}[t(1181)+t(684)](n=0){let s=t;this[s(491)+s(782)]=n,this.count=0}}async function Vx(a){let n=t,s={SPIku:function(l,u){return l(u)},Aiqvg:e[n(1198)],cTwpu:e[n(442)],QpzHA:e[n(1593)],RRbUw:function(l,u){return e[n(657)](l,u)},tZgww:e[n(645)],vrtCP:function(l,u){return e[n(838)](l,u)},wyZGh:e.jTrBK,yLrye:function(l){return e.NeNqn(l)}};if(e[n(1397)](e[n(260)],e[n(260)]))return new Promise(l=>{let u=n,_={hynXU:function(v,b){return s.SPIku(v,b)},nZNXA:u(1536)+u(1642)};if(!Zn)return l(s[u(648)]);try{let v=document[u(1441)+u(291)](s[u(900)]);window[u(1488)+"JSONP"]=b=>{let p=u;document[p(664)][p(1194)+"ild"](v),window[p(1488)+p(1633)]=void 0,_[p(971)](l,b&&b[p(471)]||_.nZNXA)},v[u(819)]=s.QpzHA,v[u(719)]=s[u(1335)](a.replace(/^ws/,s[u(841)]),u(883)+"ack=fron"+u(721)+"P");try{document[u(664)][u(304)+u(708)](v)}catch{document[u(664)]["removeCh"+u(708)](v)}}catch{window[u(1488)+u(1633)]=void 0,l(s[u(648)])}});eAdcWC[n(1056)](_0x2de9c8,_0x3e995d.error||new _0x27937a(eAdcWC[n(1270)],eAdcWC[n(1270)])),eAdcWC[n(1461)](_0x494156)}function Xt(a,n,s){let l=t;return!!a?.[l(886)](u=>u[l(441)]===n&&u[l(1528)]===s)}function Vn(a,n){let s=t;return a?.[s(886)](l=>l.key===n)?.[s(1528)]}let ra=null;async function Jx(){let a=t;return ra||(ra=Promise.resolve().then(Ot[a(1257)](Ot,a(1206)))),ra}class Yx extends ta{constructor(n,s){let l=t;super(),this[l(1139)]=n,this[l(724)]=s,this[l(474)]=void 0,this[l(1490)+l(649)]=null}async[t(259)](){await this[t(763)]()}async _init(){let n=t,s={idOlF:function(l){return e[ee(1431)](l)},kBltD:function(l,u,_,v){return l(u,_,v)}};if(!this._qosDB){if(this["_initPro"+n(649)])return this["_initPro"+n(649)];try{let l=this[n(1139)],u=this._keyPath;this[n(1490)+n(649)]=(async()=>{let _=n,{openDB:v}=await s[_(1361)](Jx);this._qosDB=await s.kBltD(v,"frontier_"+l,1,{upgrade(b){b["createOb"+_(1091)+"e"](l,{keyPath:u})}})})(),await this[n(1490)+n(649)]}catch(l){console[n(947)](l)}finally{this["_initPro"+n(649)]=null}}}async[t(848)](n){let s=t;try{return await this._init(),this._qosDB?.[s(848)](this._dbName,n)}catch(l){console[s(947)](l)}}async set(n,s){let l=t;return await this._init(),this._qosDB?.put(this[l(1139)],n)}async[t(899)](n){let s=t,l={QCwUS:e[s(1444)],sQoOR:function(u,_){return u(_)}};try{if(e[s(983)]!==e[s(983)]){let u=_0x195d0e["deleteDa"+s(1121)](_0x43e979);return _0x196ab6&&u[s(1330)+s(1012)](yXYond[s(476)],()=>_0x334c2e()),yXYond[s(1054)](_0x2204ab,u)[s(538)](()=>{})}else return await this[s(763)](),this._qosDB?.[s(537)](this[s(1139)],n)}catch(u){console[s(947)](u)}}async[t(1174)](){let n=t;if(e[n(243)](n(1128),e[n(1382)]))this[n(937)+n(1130)+n(1337)](_0x42508e),_0x21c640.set(_0x3a389f,_0x2a75ac,_0x2bc900[n(685)][n(1327)]);else try{if(e[n(620)](e[n(754)],e[n(1643)]))return await this._init(),this[n(474)]?.[n(1174)](this[n(1139)]);{let s=e.FRrJj[n(387)]("|"),l=0;for(;;){switch(s[l++]){case"0":_0x2767b4=e.dsyzA(e[n(608)](127,_0x32385b[_0x32cfa9]),0);continue;case"1":if(e[n(988)](_0x3e2eee[_0x436500++],128))return{value:_0x219fd6?_0x434a08:e[n(903)](0,_0x356a56),offset:_0x28f1c7};continue;case"2":if(_0xb1b066[_0x453718++]<128)return{value:_0x545f30?_0x306ff4:e[n(1530)](0,_0x25037a),offset:_0x26dbcb};continue;case"3":if(e[n(912)](_0x1edb9a[_0x4e2fb6++],128))return{value:_0x43e207?_0x469f43:0|_0x37d0e1,offset:_0xbf3ffd};continue;case"4":_0xd10bb4=e.UKrgs(e[n(1035)](_0x23e205,e[n(1079)](127&_0x11be0f[_0x91e842],7)),0);continue;case"5":if((_0x1dbdb9+=5)>_0x4830f9[n(301)])throw _0xb4d09d=_0x9fa8be.length,e.xwABW(_0x309e14,_0x1edc6e,10,_0x4b9809[n(301)]);continue;case"6":_0x429c9d=e.dsyzA(_0x1eb1ac|e[n(1278)](e.kNYPF(127,_0x5bf7c1[_0x2520e3]),21),0);continue;case"7":_0x2a2ed7=e.dsyzA(e[n(642)](_0x20a56b,e.fNWkz(e[n(1392)](15,_0xbef3bc[_0x2ee795]),28)),0);continue;case"8":return{value:_0x4b3cc4?_0x31eccb:e[n(239)](0,_0x33d6dd),offset:_0x45edd7};case"9":if(_0xdeab0b[_0x3b341b++]<128)return{value:_0x161243?_0x3cf6e5:0|_0x48d9f7,offset:_0xeaae};continue;case"10":if(e[n(643)](_0x284192[_0x3d3fb3++],128))return{value:_0x3402ea?_0x1fc7c4:e[n(266)](0,_0x100a7a),offset:_0x1c822d};continue;case"11":_0x3e6155=(_0x4670de|e.xYpKS(127,_0x4b1460[_0x12a907])<<14)>>>0;continue}break}}}catch(s){e[n(1317)](e[n(863)],e[n(863)])?(e[n(1072)](_0x52d251,_0x377c73,10),e[n(1233)](_0x34018f,_0x4aeef3,_0x679f4a)):console[n(947)](s)}}async[t(1606)](){let n=t;return await this[n(763)](),this._qosDB?.[n(451)+"ys"](this[n(1139)])}async getAll(){let n=t;return await this[n(763)](),this[n(474)]?.[n(225)](this[n(1139)])}async closeDB(){let n=t;try{this[n(474)]?.[n(627)](),this[n(474)]=void 0}catch(s){console[n(947)](s)}}get[t(738)](){let n=t;try{return!!this[n(474)]}catch(s){return console[n(947)](s),!1}}}class Xx{constructor(n,s){let l=t;this[l(1034)]=n,this[l(420)]=s,this[l(474)]=localStorage}async[t(259)](){}get[t(1268)](){return"frontier_"+this[t(1034)]}async[t(848)](n){let s=t,l={TyTkf:function(u,_){return u(_)}};if(e[s(1377)]!==s(514)){let u=this[s(474)][s(939)](this[s(1268)]);return JSON[s(638)](e[s(1456)](u,"{}"))[n]}else OBLuID.TyTkf(_0x8cc5c2,_0x9e935d.error),_0x28850f()}async[t(591)](n,s){let l=t;if(l(292)===e[l(336)]){let u=this[l(474)].getItem(this[l(1268)]),_=JSON[l(638)](e.hATru(u,"{}"));return _[s||n[this._pathKey]]=n,this._qosDB.setItem(this._prefix,JSON[l(1325)+"y"](_)),s||n[this._pathKey]}else{let u=e.MSYTl(_0x3a5ac1,e[l(1586)],{message:_0x484230[l(685)],code:_0x10b3de.MESSAGE_ERROR,error:_0x41a4d9});this[l(937)+l(1040)+l(364)](u)}}async[t(899)](n){let s=t,l=this[s(474)][s(939)](this[s(1268)]),u=JSON.parse(l||"{}");return u[n]=void 0,this._qosDB.setItem(this[s(1268)],JSON[s(1325)+"y"](u))}async[t(1174)](){return this[t(474)].clear()}async[t(1606)](){let n=t;if(e[n(797)](e[n(978)],n(1508)))return _0x451fff?this[n(603)+"E"]():this[n(1166)+"E"]();{let s=this._qosDB[n(939)](this[n(1268)]),l=JSON[n(638)](e[n(1592)](s,"{}"));return Object[n(1606)](l)}}async[t(225)](){let n=t,s=this._qosDB[n(939)](this[n(1268)]),l=JSON[n(638)](e[n(985)](s,"{}"));return Object[n(587)](l)}closeDB(){let n=t,s={ScKpJ:function(l,u){return e.khdBW(l,u)},RdcYG:function(l,u){return l==u},PSdKY:e.yRtDW,UjyNE:function(l,u){return e[ee(330)](l,u)},pelSZ:e[n(374)]};if(e.ZsuDF(n(1516),n(1516)))return Promise[n(943)]();{let{url:l}=s[n(1634)](_0x57c1b5,{}),u=_0x557daa.isArray(l)?l:s[n(1074)](s[n(893)],typeof l)?[l]:[];_0x1d7562&&_0x4cfb23.assign(this[n(506)],_0x575534),u&&u.length?this[n(1188)+"tManager"]=new _0x2cd93f(u,this._options.maxRetries):this[n(1188)+"tManager"]?.[n(1167)+n(814)+"fig"](),this[n(558)+n(432)]?.["resetCou"+n(684)](this[n(506)][n(475)+n(705)]),this[n(669)+n(602)]=!1,this[n(531)]&&s[n(1230)](this[n(531)][n(660)+"te"],this[n(1085)])?this[n(665)+n(654)](1e3,s[n(737)],!0):(this[n(1360)]=!0,this._connect())}}get[t(738)](){return!!this[t(474)]}}class Qx{constructor(n,s){let l=t;this._DBName=n,this[l(420)]=s,this._qosDB=vn?tt:Ur?wx:null}async[t(259)](){}get[t(1268)](){let n=t;return n(1488)+"_"+this[n(1034)]}async[t(848)](n){let s=t,l=this[s(474)][s(1208)+s(726)](this[s(1268)]);return JSON[s(638)](l||"{}")[n]}async[t(591)](n,s){let l=t,u=this[l(474)].getStorageSync(this[l(1268)]),_=JSON.parse(u||"{}");return _[s||n[this[l(420)]]]=n,this[l(474)][l(949)+"geSync"](this[l(1268)],JSON[l(1325)+"y"](_)),s||n[this[l(420)]]}async[t(899)](n){let s=t,l=this[s(474)][s(1208)+s(726)](this[s(1268)]),u=JSON.parse(e[s(1456)](l,"{}"));return u[n]=void 0,this[s(474)][s(949)+s(726)](this[s(1268)],JSON[s(1325)+"y"](u))}async clear(){let n=t;return this[n(474)][n(714)+n(1509)]()}async keys(){let n=t,s=this._qosDB[n(1208)+"geInfoSync"](this[n(1268)]),l=JSON[n(638)](e[n(468)](s,"{}"));return Object[n(1606)](l)}async[t(225)](){let n=t;if(e[n(697)](n(501),e.jZhCA)){let s=this[n(474)]["getStora"+n(595)+"nc"](this._prefix),l=JSON.parse(e.jxquP(s,"{}"));return Object.values(l)}else{if(!this[n(531)])return;this[n(1212)+n(1369)+"t"](_0x8b2389,_0x2364ab,_0x425757)}}[t(1254)](){return Promise.resolve()}get[t(738)](){return!!this[t(474)]}}function $d(a,n){let s=t;if(e.xycTs(vn,vn))return new Qx(a,n);if((Zn||Gr)&&e[s(1636)](e[s(497)],typeof indexedDB))return new Yx(a,n);if(e.UJHLZ(Zn,Gr)&&s(614)+"d"!=typeof localStorage)return new Xx(a,n);throw new Error(e[s(1469)])}class ep{constructor(){let n=t;this[n(352)+"lTimeoutId"]=null,this._interval=36e5,this._qosDB=e[n(1316)]($d,e.wAODF,e[n(340)])}async["_interva"+t(1424)](){let n=t;e.UQLeH(clearInterval,this._intervalTimeoutId),this[n(352)+n(1094)+"Id"]=e[n(1289)](setInterval,()=>{let s=n;this[s(1457)+s(693)]()},this._interval)}async[t(259)](){let n=t;await this._qosDB.openDB()[n(538)](()=>{this[n(352)+"lFlush"]()})}async["flushExp"+t(693)](){let n=t;(await this[n(474)]?.getAll()||[])[n(1543)](({timestamp:u})=>u<Date.now())[n(1381)](u=>{let _=n;this[_(474)]?.[_(899)](u[_(1228)+"id"])})}async[t(899)](n){let s=t;return this._qosDB?.[s(899)](n)}async[t(591)](n,s){let l=t;return this[l(474)]?.[l(591)]({message_id:n,timestamp:s})}async[t(848)](n){let s=t;return this[s(474)]?.[s(848)](n)}async[t(1254)](){let n=t;e[n(727)](clearInterval,this[n(352)+n(1094)+"Id"]),await this[n(474)]?.[n(1254)]()}get isReady(){let n=t,s={PfjMX:function(l,u){return e[ee(839)](l,u)},LfTIt:function(l,u){return e.urIcN(l,u)},muigv:function(l,u){return e[ee(831)](l,u)},TROXa:e[n(497)]};if(e[n(300)](e.RHSZY,e[n(1068)]))return this[n(474)]?.[n(738)];if(_0x515762)return new _0x19e855(_0x5d513a[n(666)],_0xc757bd[n(1154)]);if(wWeGnK[n(1588)](_0x13bccd,_0x3b79ab))return new _0x2e3deb(_0x10255a[n(666)],_0x1fba96[n(1154)],_0x1f9fde[n(1364)]);if(wWeGnK.LfTIt(_0x163b86,_0x586b31)&&wWeGnK[n(1567)](wWeGnK[n(997)],typeof _0x53c878)&&_0x24ea09)return new _0x3e3bf1(_0x355798[n(666)],_0x292bba[n(1154)+"s"])}}function ia(a){let n=t,s=!!this[n(506)][n(601)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=Xt(a[n(685)][n(1364)],n(1283)+n(407),"2"),u=l&&e.tPVQb(Xt,a.message[n(1364)],e[n(519)],"1"),_=l&&e[n(702)](Xt,a[n(685)][n(1364)],e[n(314)],"1"),v=_?e.ItqTI(Vn,a[n(685)][n(1364)],e[n(840)])?.[n(387)](",")[n(1543)](Boolean)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:u,isAckCleanupMessage:_,ackMsgIds:v}}async function Kd(){let a=t;return this._QoSManager||(this["_QoSMana"+a(411)]=new ep),this[a(445)+"ger"][a(738)]||await this["_QoSMana"+a(411)][a(259)](),this[a(445)+a(411)]}async function tp(a,n){let s=t,{enableAutoAck:l}=this[s(506)],u=e.pbomt(Xt,a[s(685)][s(1364)],e.dYLMR,"1"),_=e[s(702)](Xt,a[s(685)][s(1364)],e.aYBYE,"1"),v=ia[s(235)](this,a);if(e[s(921)](l,u)){let{SeqID:b,LogID:p,service:k,LogIDNew:B,method:z}=a[s(685)];this[s(902)]({SeqID:b,LogID:p,LogIDNew:B,service:k,method:z,headers:[{key:e[s(612)],value:"1"},{key:"ack_id",value:B||""},{key:e.AwQiW,value:"0"}]})}_&&!v[s(856)]&&this[s(937)+s(321)+s(1055)](a),e[s(1095)](n)}async function np(a,n){let s=t;this[s(303)](s(353),a[s(685)]),e[s(1095)](n)}async function rp(a,n){let s=t,l=Vt(await e[s(682)](Wd,a[s(1271)]));try{if(e[s(1069)](l[s(659)],Uint8Array)){let u=e[s(1100)](this[s(506)]["payloadE"+s(350)],Object)?{force:!!this[s(506)]["payloadE"+s(350)][s(1058)],encoding:this[s(506)][s(979)+"ncoding"][s(341)]?this._options[s(979)+s(350)].encoding[s(398)](/\s/g,"")[s(1565)+s(1348)]():""}:{force:!1,encoding:this[s(506)][s(979)+s(350)]?this[s(506)].payloadEncoding[s(398)](/\s/g,"")[s(1565)+"ase"]():""},_=l[s(979)+s(350)]?l.payloadEncoding.replace(/\s/g,"")[s(1565)+"ase"]():"",v=e[s(1062)](this._options[s(518)+s(1517)],Object)?{force:!!this[s(506)][s(518)+s(1517)][s(1058)],type:this[s(506)][s(518)+"ype"].type?this._options["payloadT"+s(1517)][s(819)][s(398)](/\s/g,"")[s(1565)+s(1348)]():""}:{force:!1,type:this[s(506)].payloadType?this._options[s(518)+"ype"][s(398)](/\s/g,"")[s(1565)+"ase"]():""},b=l["payloadT"+s(1517)]?l[s(518)+"ype"][s(398)](/\s/g,"")["toLowerC"+s(1348)]():"",p=v[s(1058)]?v.type:b||v.type,k=u[s(1058)]?u.encoding:_||u.encoding,B=[e[s(772)],e[s(1496)],e[s(699)],e[s(1152)]],z=[e[s(1427)],e[s(311)]];this[s(506)]["enableTransformT"+s(823)+"ad"]&&B[s(1579)](p)&&(!k||z[s(1579)](k))?l[s(878)+s(507)]=qd(l[s(659)],0,l[s(659)].byteLength):l[s(878)+s(507)]=""}else l[s(878)+s(507)]=""}catch(u){l[s(878)+s(507)]="",console[s(947)](u)}a[s(685)]=l,e[s(1023)](n)}function ip(a,n,s){let l=s||8192,u=l>>>1,_=null,v=l;return function(b){let p=ee;if(e[p(1020)](b,1)||e[p(1458)](b,u))return a(b);e.NdlOy(v,b)>l&&(_=e[p(1231)](a,l),v=0);let k=n.call(_,v,v+=b);return 7&v&&(v=e[p(1324)](e[p(1341)](7,v),1)),k}}let sp=4294967295;function op(a,n,s){let l=t;return e.DMZml(RangeError,e[l(406)](e.Rcljb(e[l(1628)](e.snrfS(e[l(926)](e[l(825)],a),l(683)),e[l(281)](n,1)),l(679)),s))}function ap(a,n,s){let l=t;if(s>sp)throw new Error(e[l(1219)]);let u=3;for(;e[l(404)](u,0);){let _=e.tuvpX(255,s);e[l(1331)](oa,_,a,e[l(1179)](n,u)),s>>>=8,u--}return n+4}function cp(a,n){let s=t,l=0,u=n,_=n+4;for(;e[s(912)](u,_);){let{value:v,offset:b}=e.KMdsV(sa,a,u);u=b,l=e[s(1611)](e.AownE(l,8),0),l+=v}return{value:l,offset:_}}function dp(a,n,s){let l=t;return a?e[l(662)](a[l(301)],40)?e[l(576)](e.TdxSb(na,a,n,s),s):n[l(766)+"e"]?e.NMHtH(n[l(766)+"e"](a,s),s):n[l(888)]?n[l(888)](a,s)+s:e[l(576)](na(a,n,s),s):s}function lp(a,n){let s=t;if(e[s(762)](s(568),e[s(1088)]))e.LMIBs(_0x5bee3a,s(390)),this[s(1596)](e[s(1551)],_0x403199),this[s(1596)](s(1224)+s(817)+"t",_0x2e5ef2);else{let l=new ce(e[s(1033)](e[s(482)](e.DSXzN(e[s(257)](a[e[s(639)](n,4)],24),a[n+5]<<16),e[s(1404)](a[e[s(1041)](n,6)],8)),a[e[s(1578)](n,7)]),e[s(1519)](e[s(1164)](e[s(1164)](a[e.FptpX(n,0)]<<24,e[s(257)](a[e.NRRis(n,1)],16)),a[n+2]<<8),a[n+3]),!0);return n+=8,{value:l,offset:e.GYzAd(n,8)}}}function fp(a,n,s){let l=t,u=a.low,_=a[l(759)];return n[s]=e[l(1248)](_,24),n[e.Japtg(s,1)]=e[l(998)](_>>>16,255),n[s+2]=e[l(913)](e[l(875)](_,8),255),n[e.fmIAX(s,3)]=e.adhmB(255,_),n[e[l(1301)](s,4)]=e.lDzIg(u,24),n[e.NdlOy(s,5)]=e[l(351)](e[l(1466)](u,16),255),n[s+6]=e[l(1019)](u,8)&255,n[s+7]=255&u,s+=8,s}function sa(a,n){let s=t;return a[s(1473)+"8"]?{value:a[s(1473)+"8"](n),offset:e[s(394)](n,1)}:{value:e[s(429)](255,a[n]),offset:e.xKBQV(n,1)}}function oa(a,n,s){let l=t;if(e[l(1051)]("snRCk",e[l(922)]))return n[l(991)+"t8"]?n.writeUint8(a,s):n[s]=e[l(265)](255,a),e[l(394)](s,1);{let u=_0x4f790f[l(387)](/\./).map(b=>_0x596d87(b)),_=[];return _[0]=e[l(901)](_0x541fa6,e[l(299)](u[0],u[1])),_[1]=e[l(331)](_0x26f76a,e.huWau(u[2],u[3])),[e[l(1537)],l(1448),e[l(1537)],e[l(1537)],e.OFgrR,e[l(1103)],_[0],_[1]][l(1030)]("")}}let up=function(a){return new Uint8Array(a)},hp=e[t(1386)](t(614)+"d",typeof Buffer)?Buffer[t(1574)+t(1061)]:e[t(382)](ip,up,Uint8Array[t(1201)+"e"].subarray);(()=>{let a=t,n={sipEV:"8|0|9|5|"+a(1016)+"|6|11|3|4",SuVPR:function(l,u){return e[a(1485)](l,u)},AAXXU:function(l,u){return e[a(751)](l,u)},colSs:function(l,u){return l|u},MdxDS:function(l,u){return e[a(319)](l,u)},OfkyH:function(l,u){return e.FbPgO(l,u)},fPKff:function(l,u){return e[a(1278)](l,u)},lNfyl:function(l,u){return e[a(877)](l,u)},TfAgh:function(l,u,_,v){return l(u,_,v)},YwVzB:function(l,u){return e[a(826)](l,u)},MRTUE:function(l,u){return e[a(972)](l,u)},xfUaX:function(l,u){return e[a(1495)](l,u)},kCvgu:function(l,u){return e[a(228)](l,u)},gOITU:function(l,u){return e[a(233)](l,u)},ELLcd:function(l,u){return l<<u},Psdnb:function(l,u){return e[a(323)](l,u)},PUfSc:function(l,u){return e[a(1417)](l,u)}},s=4294967295;return function(l,u,_=!0){let v=a,b=n[v(986)][v(387)]("|"),p=0;for(;;){switch(b[p++]){case"0":if(n[v(897)](l[u++],128))return{value:_?s:n[v(1151)](0,s),offset:u};continue;case"1":s=n[v(1524)](s,n[v(744)](127,l[u])<<21)>>>0;continue;case"2":s=n.OfkyH(n[v(1524)](s,n[v(941)](n[v(744)](127,l[u]),14)),0);continue;case"3":if(n[v(345)](u+=5,l.length))throw u=l.length,n.TfAgh(op,u,10,l[v(301)]);continue;case"4":return{value:_?s:n.YwVzB(0,s),offset:u};case"5":if(n[v(1531)](l[u++],128))return{value:_?s:n[v(1151)](0,s),offset:u};continue;case"6":s=n[v(1199)](s|n[v(744)](15,l[u])<<28,0);continue;case"7":if(l[u++]<128)return{value:_?s:n[v(1524)](0,s),offset:u};continue;case"8":s=n[v(1199)](n.kCvgu(127,l[u]),0);continue;case"9":s=n[v(490)](n[v(743)](s,n[v(1110)](127&l[u],7)),0);continue;case"10":if(n[v(338)](l[u++],128))return{value:_?s:n.PUfSc(0,s),offset:u};continue;case"11":if(n[v(338)](l[u++],128))return{value:_?s:0|s,offset:u};continue}break}}})();let xp=16,aa=32;function pp(a){let n=t,s=0,l={};for(let u=0;u<a[n(301)];u++)l[a[u][n(262)+n(1165)]]=e[n(682)](Hd,a[u][n(262)+n(1165)]),s+=e[n(622)](14,l[a[u][n(262)+n(1165)]]);return[s,l]}function Zd(a,n,s){let l=t,[u,_]=e[l(892)](pp,a),v=e[l(1366)](hp,u),b=0;return a[l(1381)](p=>{let k=l,B=(k(1032)+k(1440)+"|6|5|3")[k(387)]("|"),z=0;for(;;){switch(B[z++]){case"0":b=e.yqtjX(ap,v,b,p.service||0);continue;case"1":console.log(e[k(607)],b);continue;case"2":b=e[k(1203)](dp,p[k(262)+k(1165)],v,b);continue;case"3":console[k(947)](e[k(753)],b);continue;case"4":console[k(947)](e[k(962)],b);continue;case"5":b=e[k(481)](fp,ce.fromNumber(p[k(984)]||n),v,b);continue;case"6":console[k(947)](e[k(1037)],b);continue;case"7":b=oa(_[p[k(262)+k(1165)]],v,b);continue;case"8":console.log(e[k(1470)],p,p[k(1327)]);continue;case"9":console[k(947)](e[k(1608)],b);continue;case"10":b=e[k(882)](oa,0,v,b);continue}break}}),{frameType:aa,headers:[{key:e[l(1080)],value:s}],payload:v}}function gp(a){let n=t,s=0,l=[];for(;e[n(1306)](s,a.byteLength);)if(e.ooGiA!==e.ooGiA)_0x2b75af[n(947)](_0x27c59d);else{let{offset:u}=e[n(1003)](sa,a,s);s=u;let _={cursor_name:"",cursor:0,service:0},{value:v,offset:b}=e[n(619)](cp,a,s);_.service=v,s=b;let{value:p,offset:k}=e[n(388)](sa,a,s);s=k,_[n(262)+n(1165)]=qd(a,s,e[n(414)](s,p)),s+=p;let{value:B,offset:z}=lp(a,s);_[n(984)]=B.toNumber(),s=z,l.push(_)}return l}function mp(){return{frameType:aa,headers:[{key:e.ASurn,value:e.tpcuC}],payload:void 0}}class wp{constructor(n,s,l){let u=t;this[u(461)+u(1371)]=n,this["_cursorF"+u(494)]=s,this[u(1640)+u(795)]=l,this[u(474)]=$d(this[u(461)+u(1371)],u(262)+"ame")}async openDB(){let n=t;await this[n(474)][n(259)]()}async[t(859)+"rs"](){let n=t;if(!this._qosDB[n(738)])return;let s=this[n(1640)+n(795)],l=await this[n(474)].getAll();switch(console[n(947)](e[n(439)],l),s){case e[n(577)]:return l&&l.length?e.pbomt(Zd,l,0,this[n(1332)+"ileName"]):void 0;case e[n(1329)]:return;case"CONTINUE":return l&&l.length?e[n(1413)](Zd,l,0,this[n(1332)+n(494)]):mp()}}async[t(591)](n,s,l){let u=t;if(e[u(1438)](e[u(280)],e[u(834)]))return console[u(947)](e[u(864)],n,s,l),this[u(474)][u(591)]({cursor_name:n,cursor:s,service:l});vOqfzw.YJdpb(_0x4aa7fc,vOqfzw[u(682)](_0x4df379,_0x3c4ebe[u(443)])),_0xea20a2()}async[t(676)+"rs"](n){let s=t,l=e[s(263)](gp,n);for(let u of l)e[s(332)](s(1624),e[s(969)])?(this[s(1148)+s(1387)+s(434)]=_0x2a122b,_0x5abf3f?this[s(1352)+s(444)]():this._handleOffLine()):(console.log(e[s(1226)],l),await this[s(474)][s(591)](u))}async[t(848)](n){let s=t;return(await this._qosDB.get(n))?.[s(984)]}async closeDB(){let n=t;await this[n(474)][n(1254)]()}[t(923)+"rsorFile"+t(1402)](n){let s=t;this[s(1332)+"ileName"]=n}get[t(738)](){return this[t(474)].isReady}}let yp=e[t(1451)];async function Vd(a){let n=t;if(!this[n(506)][n(601)+"S"])return null;let{aID:s,fpID:l,messageStrategy:u}=this._options,_=e.slKeR(a,yp);try{return this[n(571)+n(905)]?a&&this["_cursorM"+n(905)][n(923)+"rsorFileName"](a):this[n(571)+n(905)]=new wp(l+"_"+s+"_"+_,_,u),this[n(571)+n(905)][n(738)]||await this[n(571)+"anager"][n(259)](),this[n(571)+n(905)]}catch{return null}}async function _p(a,n){let s=t,l={QtokL:function(u,_,v,b,p){return u(_,v,b,p)}};if(e[s(522)](s(1287),e.WvZBg)){let u=e[s(481)](Xt,a[s(685)][s(1364)],e[s(327)],"-1"),_=e.pbomt(Xt,a[s(685)][s(1364)],s(1163),"1"),v=e[s(1450)](Vn,a[s(685)][s(1364)],e[s(556)]),b=Number(Vn(a.message[s(1364)],s(1283)+s(268)))||0,p=ia[s(235)](this,a),k=e[s(546)](Xt,a[s(685)].headers,s(1535)+"s","2"),B=Vn(a[s(685)].headers,"x-msg-cu"+s(1428)+"e"),z=e[s(448)](Number,e[s(932)](Vn,a.message[s(1364)],s(847)+s(386)+"ue"));if(p[s(856)])return n();let U=p[s(590)+s(592)]?await Kd[s(235)](this):null;if(a[s(685)][s(1327)]>0&&_&&!u||a[s(685)][s(1327)]>0){if(v&&p[s(590)+s(592)]&&U)return!!!await U[s(848)](v)&&(this[s(937)+s(1130)+"Event"](a),await U[s(591)](v,Date[s(812)]()+b)),e[s(477)](n);if(k){let H=await Vd[s(235)](this);if(!H)return this[s(937)+s(1130)+s(1337)](a),n();let V=await H[s(848)](B)??-1;if(V<z)if(e[s(244)]!==e[s(1491)])this[s(937)+"hMessageEvent"](a),H[s(591)](B,z,a[s(685)].service);else return null;else throw new Error(s(1434)+s(524)+s(722)+z+(s(1455)+s(572)+s(1439)+"r ")+V);return e[s(881)](n)}return this[s(937)+"hMessage"+s(1337)](a),e[s(1092)](n)}}else vVvxGc[s(735)](_0x58169a,_0x2d94d0(_0x52ac9e[s(443)]),_0x59f7da[s(750)+"on"],_0x79c338[s(1004)+"on"],_0x28f79e(_0xb1684f[s(1183)+s(1398)]))}async function Ep(a,n){let s=t,l=ia.call(this,a);if(!l[s(590)+s(592)])return e[s(1358)](n);let u=await Kd[s(235)](this);if(l[s(1599)+s(1135)+s(846)]&&l.ackMsgIds[s(301)])for(let _ of l.ackMsgIds)await u[s(899)](_);e.xTGdb(n)}async function bp(a,n){let s=t,l=a[s(685)][s(1118)+"e"]===xp,u=e[s(1547)](a.message[s(1118)+"e"],aa);if(!l&&!u)return n();let _=e[s(1571)](Vn,a[s(685)][s(1364)],e[s(1080)]);if(!_)return n();let v=await Vd[s(235)](this,_);if(!v)return e[s(1431)](n);if(l){let b=await v[s(859)+"rs"](),p={frameType:b?.[s(1118)+"e"],SeqID:ce[s(479)+"er"](this[s(1060)]++),LogID:ce[s(479)+"er"](this[s(506)][s(583)+s(250)]()),service:9e3,method:5,headers:b?.headers,payload:b?.[s(659)]},k=A(p);this[s(531)]&&this[s(531)][s(660)+"te"]&&this[s(531)][s(1124)](k)}if(u){let b=a[s(685)][s(659)];b&&v.setCursors(b)}}let vp=async function(a,n){let s=t;this._isInit=!1,e[s(1243)](clearTimeout,this[s(805)+"ionTimeo"+s(757)]),e.OBHBx(n)},Sp=async function(a,n){let s=t;if(!this[s(531)]||e[s(1050)](this[s(531)][s(660)+"te"],this[s(1309)]))return e[s(1241)](n);let{pingInterval:l}=this[s(506)];this[s(1188)+s(456)]?.[s(1167)+s(814)+s(1629)]();for(let _=0;e.wzEOf(_,this[s(1640)+"Queue"][s(301)]);_++){let v=this[s(1640)+s(510)][_];if(this[s(531)].readyState===this[s(1309)]&&v!==null)this[s(531)]&&this._ws[s(1124)](v),this[s(1640)+s(510)][_]=null;else break}this[s(1640)+"Queue"]=this[s(1640)+s(510)][s(1543)](_=>!!_),this["_pingPon"+s(428)+"Id"]=e[s(1605)](setTimeout,()=>this[s(1533)](),l),this[s(937)+s(915)+"nt"](a),this[s(1211)+"er"]&&this._ws&&(this[s(531)][s(928)+"pe"]=this[s(1111)+s(1517)]);let u=this[s(1188)+"tManager"]?.["getCurre"+s(706)+"nt"]();this[s(303)]("open "+u+s(1319)),e[s(252)](n)},Ip=async function(a,n){let s=t,l=this[s(1188)+s(456)]?.["getCurre"+s(706)+"nt"]();this[s(303)](s(1467)+l),e.OBHBx(n)};class Ap extends ta{constructor(n){let s=t,l={HpQxZ:function(b,p,k){return e[ee(544)](b,p,k)},dnTOv:function(b,p){return e.PGyBl(b,p)},zzIyp:e[s(557)],nRkMn:e.MRkmq,oAChE:function(b,p){return e[s(1419)](b,p)},hDFlo:function(b,p){return e[s(500)](b,p)},Yoceg:s(1186),hkVgy:function(b,p){return b!==p}};super(),this[s(1148)+s(1387)+"line"]=!0,this[s(1211)+"er"]=Zn,this[s(1307)]=jx,this._isMiniTT=vn,this[s(1143)+"X"]=Ur,this[s(1527)+"r"]=Gr,this[s(1640)+s(510)]=[],this[s(1188)+"tManager"]=null,this[s(669)+s(602)]=!1,this[s(1111)+"ype"]=e[s(547)],this["_connect"+s(646)]=!1,this._connectionTimeoutId=null,this[s(1462)+s(1073)+s(373)]=null,this[s(720)+s(428)+"Id"]=null,this._seqId=0,this[s(1360)]=!1,this[s(585)]="",this[s(445)+s(411)]=null,this[s(571)+s(905)]=null,this[s(558)+s(432)]=null,this._protocols=e[s(644)],this.CLOSED=3,this[s(315)+"NG"]=0,this[s(1309)]=1,this[s(736)]=2,this[s(473)]=b=>{let p=s,k={EfgUD:e[p(1152)],WBPcz:function(z,U){return e[p(1100)](z,U)},ThsDw:e.Wqdoo};if(p(894)!==e[p(1063)])try{if(e[p(1146)](p(574),p(1561)))e.cAtOx(jd,this,b,[vp,Sp,Ip]);else for(var B in _0x192430)_0x15684b.o(_0x2f0c18,B)&&!_0x460309.o(_0x1bed93,B)&&_0x5871e4[p(681)+p(1281)](_0xdfc01,B,{enumerable:!0,get:_0x43b6be[B]})}catch(z){let U=e[p(1605)](rt,e[p(1586)],{message:z[p(685)],code:Yt[p(804)+"OR"],error:z});this[p(937)+p(1040)+"ent"](U)}else return sVksSO[p(1261)]!=typeof _0x49e875&&(sVksSO[p(240)](_0x514385,_0x1151eb)||_0x434dd2.buffer&&_0x25a48d[p(1409)]instanceof _0x1893be)||sVksSO[p(1261)]!=typeof _0x49c492?"":(_0x1605c5.parse(_0x368597),sVksSO[p(539)])},this[s(528)+"ge"]=async b=>{let p=s,k={axnfO:function(U,H){return e[ee(513)](U,H)},JIWia:function(U,H){return U<=H},yhxxO:function(U,H){return U-H},elVKq:function(U,H){return e[ee(1585)](U,H)},tOAds:function(U,H){return U<<H},rRaCG:function(U,H){return e[ee(455)](U,H)}},{pingInterval:B,pingFrequency:z}=this[p(506)];if((e[p(1024)]("hi",b[p(1271)])&&e[p(789)]("always",z)||e[p(534)]===z)&&(this[p(1591)+p(1322)](),this[p(835)](e[p(1551)],e.jhytV),this[p(720)+p(428)+"Id"]=setTimeout(this[p(1533)].bind(this),B)),!e[p(1215)]("hi",b[p(1271)]))try{e[p(343)]!=="glxIY"?e[p(546)](jd,this,b,[rp,tp,Ep,bp,_p,np]):(this[p(1034)]=_0xb9c572,this[p(420)]=_0x5283db,this._qosDB=_0x40b661)}catch(U){if(e[p(1501)]!==e[p(1501)]){let H=_0x4c7a93[p(896)+"At"](_0x233e7d);GPclim[p(784)](H,55296)&&GPclim[p(1010)](H,56319)&&_0x104d8c+1<_0x5c6c69&&(H=GPclim[p(1303)](GPclim.elVKq(GPclim.tOAds(H,10),_0x2b7d8f[p(896)+"At"](++_0x51debd)),56613888)),_0x3e9c1f+=H<128?1:GPclim[p(774)](H,2048)?2:GPclim[p(774)](H,65536)?3:4}else{let H=rt(e[p(1586)],{message:U.message,code:Yt[p(1e3)+p(606)],error:U});this[p(937)+p(1040)+p(364)](H)}}},this[s(598)]=b=>{let p=s,k={dqRoD:function(B,z,U){return e[ee(977)](B,z,U)},Xbrdk:e[p(931)],TQLeX:"stop imm"+p(325)+p(1029)+"ct"};if(e.OHnub(p(472),e[p(1617)])){this[p(1212)+p(1369)+"t"]();let B=k[p(1477)](_0x4e9d55,k[p(655)],{message:k[p(1363)]});this[p(368)+p(1582)+p(1512)+"ct"]&&this["onStopIm"+p(1582)+p(1512)+"ct"](B)}else{let B=this[p(1188)+p(456)]?.[p(363)+p(605)+"es"](),z=this[p(1188)+p(456)]?.[p(465)+"ntEndpoint"]();if(B&&!b[p(685)]){let U=p(1380)+z+(" fail, max retri"+p(1277)+"ed");this[p(937)+p(1040)+p(364)](e[p(1630)](rt,p(1186),{message:U,code:Yt[p(1267)+p(1313)+"R"],error:b}));return}this[p(531)]&&e[p(1197)](this[p(531)][p(660)+"te"],this.OPEN)&&this[p(665)+p(654)](),this[p(937)+"hErrorEvent"](rt(e[p(1586)],{message:b[p(685)],code:Yt[p(1507)+p(278)],error:b}))}},this._onClose=async b=>{let p=s;this._clearTimer(),this[p(1591)+p(1322)](),this[p(604)+p(1555)+"rs"](),this[p(531)]=null,this["_connect"+p(646)]=!1;let k=this[p(1188)+"tManager"]?.["checkRea"+p(605)+"es"]();if(!k&&this["_navigat"+p(1077)]()&&!this[p(669)+p(602)]){let B=this._endpointManager?.[p(465)+"ntEndpoint"](),z=this[p(506)][p(673)+p(554)+p(1452)](b[p(852)],b[p(1642)]);this[p(937)+p(520)+p(364)](l.HpQxZ(ft,p(627),{code:1006,reason:b[p(1642)]||p(704)+p(1114)+p(1418)+"wn reaso"+p(450)+p(1639)+B,willReconnect:z})),z&&this._connect();return}if(l[p(1039)](1e3,b[p(852)])&&this[p(669)+p(602)]){this[p(937)+p(520)+"ent"](ft(l.zzIyp,{code:1e3,reason:l[p(460)]})),this[p(1188)+p(456)]?.[p(1167)+p(814)+p(1629)](),this[p(558)+p(432)]?.[p(1181)+p(684)]();return}if(l[p(1540)](1e3,b.code)&&k){let B=this[p(1188)+"tManager"]?.[p(465)+p(706)+"nt"](),z=b.reason;z||(z=await l[p(1249)](Vx,this[p(585)])),z=p(704)+p(1114)+p(227)+z+(p(1359)+p(713))+B+(p(1321)+p(734)+"ached"),this[p(937)+p(520)+"ent"](ft(l[p(1410)],{code:b[p(852)],reason:z}));let U=p(1380)+B+(p(1521)+p(1569)+p(1277)+"ed");this[p(937)+p(1040)+p(364)](rt(l[p(887)],{message:U,code:Yt[p(1267)+p(1313)+"R"]})),this[p(1188)+p(456)]?.["resetEnd"+p(814)+p(1629)](),this[p(558)+"sCounter"]?.[p(1181)+p(684)]();return}if(l[p(672)](1e3,b[p(852)])&&!b[p(1642)]){let B=this[p(1188)+p(456)]?.[p(465)+p(706)+"nt"]();this[p(937)+p(520)+p(364)](l[p(1064)](ft,l.zzIyp,{code:b.code,reason:"connecti"+p(1114)+"d, unkno"+p(1147)+p(450)+"ame: "+B})),this[p(1188)+p(456)]?.[p(1167)+p(814)+p(1629)](),this[p(558)+p(432)]?.[p(1181)+p(684)]();return}this[p(937)+"hCloseEv"+p(364)](b),this[p(1188)+p(456)]?.[p(1167)+p(814)+"fig"](),this["_pingLos"+p(432)]?.[p(1181)+p(684)]()},this[s(1314)]=null,this[s(1297)]=null,this[s(349)+"e"]=null,this[s(269)]=null,this[s(1265)+s(395)]=null,this[s(526)+"eAck"]=null,this[s(368)+"mediatel"+s(1512)+"ct"]=null,this[s(1352)+s(444)]=this[s(1352)+"nLine"].bind(this),this[s(1352)+s(1638)]=this[s(1352)+s(1638)][s(1257)](this),this[s(1615)+"ageHide"]=this[s(1615)+s(1333)][s(1257)](this),this[s(1615)+s(418)]=this[s(1615)+s(418)][s(1257)](this),this[s(506)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(1463)](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(1372),pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(703)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:u,ws:_}=n,v=Array[s(1619)](u)?u:e[s(1152)]==typeof u?[u]:[];if(!v||v[s(301)]===0)throw new Error(e[s(417)]);if(!e[s(448)](Wx,_))throw new Error(e[s(778)]);Object.assign(this[s(506)],n),this[s(1188)+s(456)]=new Gd(v,this[s(506)].maxRetries),this[s(558)+"sCounter"]=new Zx(this[s(506)]["pingLoss"+s(705)]),this._options[s(745)+s(761)]&&(this[s(1360)]=!0,this[s(805)]()),this._options[s(1235)+s(698)+"nged"]&&(this[s(843)+"T"]||this[s(1143)+"X"]?this[s(1563)+s(995)+s(1454)]():this[s(1211)+"er"]&&this["_initGlobalEvent"+s(1012)]())}[t(1352)+t(444)](){let n=t;this[n(506)]["disableA"+n(553)+n(1076)]||this[n(669)+n(602)]||this[n(1430)+n(395)]()}[t(1352)+t(1638)](){let n=t;this[n(1212)+n(1369)+"t"]();let s=e[n(308)](ea,n(673)+"t",{message:e[n(437)]});this[n(368)+n(1582)+n(1512)+"ct"]&&this[n(368)+"mediatel"+n(1512)+"ct"](s)}["_initGlo"+t(286)+t(1012)](){let n=t;this._isBrowser&&window[n(1330)+"Listener"](e.LItne,this[n(1352)+n(444)]),this._isBrowser&&window[n(1330)+n(1012)](e[n(1097)],this[n(1352)+n(1638)]),this[n(1211)+"er"]&&window[n(1330)+"Listener"](e[n(1291)],this[n(1615)+n(1333)]),this[n(1211)+"er"]&&window[n(1330)+n(1012)](e[n(689)],this[n(1615)+n(418)])}["_dropGlo"+t(286)+"Listener"](){let n=t;this._isBrowser&&window[n(755)+n(798)+n(1499)](e.LItne,this[n(1352)+"nLine"]),this[n(1211)+"er"]&&window[n(755)+n(798)+n(1499)](n(446),this[n(1352)+n(1638)]),this[n(1211)+"er"]&&window[n(755)+"entListe"+n(1499)](e.EMGzL,this[n(1615)+"ageHide"]),this[n(1211)+"er"]&&window[n(755)+n(798)+n(1499)](e.yRFxg,this[n(1615)+"ageShow"])}[t(1615)+t(1333)](n){let s=t;!n[s(914)+"d"]&&(this[s(1211)+"er"]&&window[s(755)+s(798)+s(1499)]("pagehide",this[s(1615)+"ageHide"]),this[s(1211)+"er"]&&window["removeEv"+s(798)+s(1499)](s(958),this[s(1615)+s(418)]),this.close()),this[s(1211)+"er"]&&window[s(755)+"entListe"+s(1499)](e.LItne,this[s(1352)+s(444)]),this[s(1211)+"er"]&&window["removeEv"+s(798)+"ner"](e[s(1097)],this[s(1352)+s(1638)])}[t(1615)+"ageShow"](n){let s=t;e.aYeRN(e[s(688)],e.QhZru)?n[s(914)+"d"]&&(this[s(1101)+"orOnline"]()&&(!this[s(531)]||e[s(1568)](this._ws[s(660)+"te"],this[s(1309)])||e[s(675)](this[s(531)].readyState,this[s(315)+"NG"]))&&this._handleOnLine(),this[s(1211)+"er"]&&window[s(1330)+s(1012)](e[s(584)],this[s(1352)+s(444)]),this[s(1211)+"er"]&&window[s(1330)+s(1012)](e[s(1097)],this[s(1352)+s(1638)])):this[s(1596)](_0x325bbf,_0xf4092f)}async["_generat"+t(294)](n){let s=t,{fpID:l,deviceID:u,bddID:_,ttwID:v,accessKey:b,aID:p,customParams:k={},enableAutoAck:B,enableQoS:z,QoSLevel:U,env:H}=this[s(506)],V,it,Qt;this[s(1211)+"er"]||this[s(1143)+"X"]||this[s(843)+"T"]?(V=location&&e.NePXh(e[s(889)],location[s(1154)])?e[s(1305)]:e[s(876)],it=n[s(398)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),Qt=/^wss(.*:\/\/)/[s(1155)](n)?n:""+V+it):(V=e[s(1305)],it=n.replace(/(^http)((?:[s]*:\/\/))/,""),Qt=/(^ws)((?:[s]*:\/\/))/[s(1155)](it)?it:""+V+it);let Jd=_?e.AtpSu:v?e[s(650)]:e[s(1518)],Yd=_||v||u;if(e[s(1592)](!Yd,!Jd))throw new Error(e.ZZSbr);let Tp=e[s(1587)](e[s(488)],typeof k)?await k():k,Rp=H?e[s(308)](Kx,H[s(487)],H[s(1597)]):{},ca=Object.assign({device_platform:e[s(1399)],version_code:e[s(1093)],access_key:b,fpid:l,aid:p,[Jd]:Yd,xsack:B?1:0,xaack:B?1:0,xsqos:z?1:0,qos_level:z?U:void 0,qos_sdk_version:2,...Rp},Tp),Cp=Object[s(1606)](ca)[s(1252)]((da,la)=>ca[la]!==void 0?""+da+(da?"&":"?")+la+"="+ca[la]:da,"");return Qt+s(960)+Cp}async[t(805)](){let n=t;if(!(this[n(805)+"Lock"]||this._readyClosed)){this[n(805)+n(646)]=!0;try{let s=this[n(1188)+"tManager"]?.[n(226)+n(732)+n(832)+n(1260)+n(1046)](),{timeoutInterval:l}=this[n(506)];if(s){let _=this["_endpoin"+n(456)]?.[n(465)+"ntEndpoint"](),v=this[n(1188)+"tManager"]?.["replaceB"+n(1220)+"pointAnd"+n(994)+"unt"](),b=this["_endpoin"+n(456)]?.[n(465)+n(706)+n(810)+n(782)]();if(v){let p=n(1380)+_+(n(293)+n(1321)+n(734)+n(596)+n(1131)+n(1500)+"ndpoint ")+v+(n(1310)+"y"),k=rt("error",{message:p,code:Yt[n(1267)+n(1313)+"R"]});this[n(303)](p),this["_dispatc"+n(1040)+n(364)](k),this._url=await this[n(758)+n(294)](v),this._debug(n(1380)+v+" "+b+n(256)),this[n(604)+n(1555)+"rs"]()}else{let p=n(1380)+_+(n(293)+n(1321)+n(734)+n(1350));this[n(303)](p),this[n(937)+n(1040)+"ent"](rt(n(1186),{message:p,code:Yt[n(1267)+"IES_ERROR"]}));return}}else{let _=this._endpointManager?.[n(465)+"ntEndpoi"+n(740)+n(1013)](),v=this[n(1188)+n(456)]?.[n(465)+n(706)+n(810)+n(782)]();this[n(585)]=await this[n(758)+n(294)](e[n(467)](_,"")),this[n(303)](n(1380)+_+" "+v+n(256)),this["_removeW"+n(1555)+"rs"]()}if(this[n(1360)])this._isInit=!1;else{let _=e[n(544)](ea,e[n(931)],{message:e[n(1098)]});this[n(1265)+"econnect"]&&this[n(1265)+n(395)](_)}let u=this[n(1188)+n(456)]?.[n(465)+n(706)+"ntTriesC"+n(782)]()||0;e[n(1458)](u,1)&&await this[n(1541)](e[n(1315)](u,1)),this[n(303)](n(704)+"ng url: "+this[n(585)]+(n(379)+n(1328))+this[n(1483)+"ls"]),this[n(531)]=e[n(1250)](qx,{url:this[n(585)],protocols:[this._protocols],headers:this[n(506)][n(820)+n(1420)+"s"][n(769)+n(1493)]},this[n(506)].ws),(this._isBrowser||this[n(1527)+"r"])&&this[n(531)]&&(this[n(531)][n(928)+"pe"]=this[n(1111)+"ype"]),this[n(1195)+n(559)](),this["_connect"+n(858)+n(757)]=e[n(1072)](setTimeout,this._onTimeout[n(1257)](this),l)}catch(s){throw this[n(805)+"Lock"]=!1,s}}}[t(874)+t(1081)](){let n=t;e[n(857)](clearTimeout,this[n(805)+n(858)+"utId"]),this[n(805)+n(858)+n(757)]=null}[t(1591)+t(1322)](){let n=t;e[n(1492)](clearTimeout,this[n(720)+"gTimeoutId"]),clearTimeout(this[n(1462)+n(1073)+n(373)]),this[n(720)+"gTimeoutId"]=null,this[n(1462)+n(1073)+n(373)]=null}[t(303)](...n){let s=t,l={rPejT:e[s(488)],MfLCe:function(u,_){return e[s(1007)](u,_)},tFwvy:function(u,_){return u(_)},fZQdV:function(u,_,v){return u(_,v)}};if(e[s(267)]===e.jxVgt)return typeof _0x304c8e===ZHWfqT[s(1506)]?_0x10aab1(_0x145224):(ZHWfqT.MfLCe(_0x9220a2,_0x41b20a)&&ZHWfqT[s(600)](_0x421a4a,_0x2c3bdb),ZHWfqT[s(499)](_0x41474c,_0x3d52f1,_0x56e414())?new _0x35cb14(_0xf75b56,_0x4cdff9):_0x2ffdc9);this[s(506)][s(765)]&&console[s(947)][s(1323)](console,[e[s(1223)],...n])}_getIntervalValue(n){let s=t;if(e[s(1436)](e[s(855)],s(366)))try{this[s(474)]?.[s(627)](),this[s(474)]=void 0}catch(l){_0x1b130a[s(947)](l)}else{let{initReconnectInterval:l,maxReconnectInterval:u,reconnectIntervalGrowFactor:_}=this._options,v=e.OJRGe(l,Math[s(930)](_,n-1));return e[s(609)](v,u)?u:v}}_ping(){let n=t;if(this._ws&&e[n(522)](this._ws.readyState,this[n(315)+"NG"])){this[n(1591)+"ngTimer"](),this[n(720)+"gTimeoutId"]=e.KMdsV(setTimeout,this._ping[n(1257)](this),this[n(506)][n(965)+n(1290)]);return}if(!this[n(531)]||e[n(300)](this._ws.readyState,this[n(1309)]))return void this[n(1430)+n(395)]();this._ws&&this[n(531)][n(1124)]("hi"),this[n(1462)+n(1073)+n(373)]=setTimeout(this["_handleR"+n(395)+n(1018)][n(1257)](this),this[n(506)][n(1320)+n(1217)+"val"])}[t(1430)+t(395)+t(1018)](){let n=t;this[n(558)+"sCounter"]?.[n(1292)](),this[n(835)](e[n(967)],e.XWnyA),this[n(558)+n(432)]?.[n(363)+n(1196)+"nt"]()?this[n(1430)+n(395)]():this._ping()}["_navigat"+t(1077)](){let n=t;return this[n(843)+"T"]||this[n(1143)+"X"]?this[n(1148)+n(1387)+n(434)]:(this[n(1211)+"er"]||this[n(1527)+"r"])&&this[n(506)][n(1235)+n(698)+n(383)]?navigator[n(616)]:!0}_handleReconnect(){let n=t,s={tUxYR:n(1374)+n(1150),vOZOR:function(l,u){return e[n(1397)](l,u)},sDHnV:e.ukORz,uyHqN:e[n(625)]};if(e[n(1538)](e.TExhb,e.LhnUM)){let l=s[n(403)][n(387)]("|"),u=0;for(;;){switch(l[u++]){case"0":this._QoSManager?.[n(1254)]();continue;case"1":if(s[n(635)](this[n(531)][n(660)+"te"],this[n(1085)])||s.vOZOR(this[n(531)][n(660)+"te"],this[n(736)]))return void this[n(303)](s[n(452)]);continue;case"2":this[n(874)+n(1081)]();continue;case"3":this[n(669)+n(602)]=!0;continue;case"4":if(!this[n(531)])return void this[n(303)](s.uyHqN);continue;case"5":this[n(1212)+n(1369)+"t"](_0x22b238,_0x52186b);continue;case"6":this["_dropGlo"+n(286)+n(1012)]();continue;case"7":this[n(1591)+n(1322)]();continue}break}}else{if(!this["_navigat"+n(1077)]()||this[n(669)+"osed"])return;this._endpointManager?.[n(1167)+n(814)+"fig"](),this["_pingLos"+n(432)]?.[n(1181)+n(684)](),this[n(531)]?this[n(665)+"ect"](1001,n(854)+"ay, try "+n(673)+n(624)+n(1559),!0):this._connect()}}[t(1563)+t(995)+"ange"](){let n=t,s={UFQsJ:e.yRtDW,QoxtW:function(l,u){return e[ee(1557)](l,u)}};if(e.Dokad!==n(1367))this[n(843)+"T"]?tt[n(1075)+n(337)+n(653)](({isConnected:l})=>{let u=n;this[u(1148)+u(1387)+u(434)]=l,l?this["_handleO"+u(444)]():this[u(1352)+u(1638)]()}):this[n(1143)+"X"]&&wx[n(1075)+"kStatusChange"](({isConnected:l})=>{let u=n;this["_miniNav"+u(1387)+u(434)]=l,l?this[u(1352)+u(444)]():this[u(1352)+u(1638)]()});else{if(bFYqQS[n(933)]==typeof _0x2ed1e7){let l=new _0x552e1f(bFYqQS[n(712)](_0x4d881a,_0x11b982));return _0x25ae12(_0x301b19,l,0),l}return _0x53440a instanceof _0x2c4935?new _0x69b92b(_0x1fffac):new _0x4b92e1(_0x44696f[n(1409)],_0x9cc31a[n(238)+"et"],_0x559411[n(1453)+"th"])}}_wait(n){let s={DllPV:function(l,u,_){return l(u,_)}};return new Promise(l=>{let u=ee;s[u(1149)](setTimeout,l,this[u(1184)+u(298)+"e"](n))})}["_disconn"+t(654)](n=1e3,s="",l=!1){let u=t;this[u(531)]&&this[u(1212)+u(1369)+"t"](n,s,l)}[t(297)+"ut"](){let n=t,s=this[n(1188)+n(456)]?.[n(465)+n(706)+"nt"]();this[n(303)](n(1380)+s+n(293)),this[n(665)+n(654)](1001,e[n(1549)],!0)}[t(902)](n){let s=t,l=e[s(1326)](Nt,n);this[s(531)]&&e[s(549)](this[s(531)][s(660)+"te"],this[s(1309)])&&(this[s(531)]&&this[s(531)][s(1124)](l),this[s(303)](e[s(1222)],n))}[t(604)+"sListeners"](){let n=t,s=(n(567)+"1")[n(387)]("|"),l=0;for(;;){switch(s[l++]){case"0":this[n(531)]["removeEv"+n(798)+"ner"](e[n(951)],this[n(473)]);continue;case"1":this._ws[n(755)+n(798)+n(1499)]("error",this[n(598)]);continue;case"2":this._ws[n(755)+n(798)+n(1499)]("message",this[n(528)+"ge"]);continue;case"3":this[n(531)][n(755)+n(798)+"ner"](e[n(557)],this._onClose);continue;case"4":if(!this[n(531)])return;continue}break}}[t(1195)+t(559)](){let n=t,s=e[n(1105)].split("|"),l=0;for(;;){switch(s[l++]){case"0":if(!this[n(531)])return;continue;case"1":this._ws[n(1330)+n(1012)](e[n(234)],this[n(528)+"ge"]);continue;case"2":this._ws.addEventListener(e[n(1586)],this[n(598)]);continue;case"3":this[n(531)][n(1330)+n(1012)](e[n(951)],this[n(473)]);continue;case"4":this[n(531)][n(1330)+n(1012)]("close",this[n(1173)]);continue}break}}["_wsInsta"+t(492)](n=1e3,s=""){let l=t;try{this._ws&&this[l(531)][l(627)](n,s)}catch{}}[t(1212)+t(1369)+"t"](n=1e3,s="",l=!1){let u=t;if(this["_clearPi"+u(1322)](),this._clearTimer(),this[u(604)+u(1555)+"rs"](),this[u(447)+"nceClose"](1e3,s),this[u(805)+u(646)]=!1,l&&this[u(1101)+"orOnline"]()&&!this._readyClosed){if(this[u(1188)+"tManager"]?.[u(363)+"chMaxTries"]()){let v=this._endpointManager?.[u(465)+u(706)+"nt"]();this[u(937)+u(520)+u(364)](e[u(1106)](ft,e[u(557)],{code:1006,reason:u(1380)+v+(u(293)+u(1321)+u(734)+u(1350)),wasClean:!0}))}else{let v=this[u(506)][u(673)+"tInterce"+u(1452)](n,s);this["_dispatc"+u(520)+"ent"](ft(u(627),{code:n,reason:s,wasClean:!0,willReconnect:v})),v&&this[u(805)]()}return}this[u(1101)+u(1077)]()||this[u(669)+u(602)]?this[u(937)+u(520)+u(364)](e[u(1437)](ft,e[u(557)],{code:n,reason:e[u(1635)]})):this["_dispatchCloseEv"+u(364)](e[u(1450)](ft,e.jrwae,{code:1006,reason:e[u(1017)]})),this._ws=null,this[u(1188)+u(456)]?.["resetEndpointCon"+u(1629)](),this[u(558)+u(432)]?.[u(1181)+u(684)]()}_dispatchOpenEvent(n){let s=t;this[s(835)](e[s(951)],n),this[s(269)]&&this.onopen(n)}[t(937)+t(1130)+"Event"](n){let s=t;this[s(835)](e[s(234)],n),this[s(349)+"e"]&&this.onmessage(n)}[t(937)+t(321)+t(1055)](n){let s=t;this[s(835)](s(1389),n),this[s(526)+s(422)]&&this[s(526)+s(422)](n)}["_dispatc"+t(1040)+t(364)](n){let s=t;this[s(835)](e.Gvnme,n),this[s(1297)]&&this[s(1297)](n)}["_dispatc"+t(520)+t(364)](n){let s=t;this[s(835)](e.jrwae,n),this[s(1314)]&&this.onclose(n)}get binaryType(){let n=t;return this[n(531)]?this._ws[n(928)+"pe"]:this[n(1111)+n(1517)]}set[t(928)+"pe"](n){let s=t;this[s(1111)+s(1517)]=n,this[s(531)]&&(this[s(531)][s(928)+"pe"]=n)}get[t(1343)+"nt"](){let n=t;return e[n(880)]("ieDSC",e[n(1601)])?this["_endpoin"+n(456)]?.[n(465)+n(706)+"ntTriesC"+n(782)]()||0:this[n(474)]?.[n(738)]}get[t(613)+"Amount"](){let n=t,s=this[n(1640)+n(510)].reduce((l,u)=>(l+=u&&u[n(1453)+"th"]||0,l),0);return e[n(674)](s,this[n(531)]?this[n(531)][n(613)+n(752)]:0)}get[t(999)+"ns"](){let n=t;return this._ws?this[n(531)][n(999)+"ns"]:""}get[t(1154)](){let n=t;return this[n(531)]?this[n(531)][n(1154)]:""}get[t(660)+"te"](){let n=t;if(e[n(707)]!==e[n(707)]){let s=e.ZGLzp(_0x304bbd,e[n(1586)],{message:this[n(436)+n(1388)+n(846)](_0x237dac)});this[n(835)](n(1186),s);let l=e.NXmtb(_0x2d0d86,e[n(557)],{reason:this[n(436)+n(1388)+n(846)](_0x1608a2)});this[n(835)]("close",l)}else return this[n(531)]?this[n(531)][n(660)+"te"]:this[n(506)].automaticOpen?this[n(315)+"NG"]:this[n(1085)]}get[t(666)](){let n=t;if(e[n(542)]("ErVop",e[n(718)]))e[n(1571)](_0x37cfbf,_0x177ed5,58),_0x4fcf74(_0x1d9685,_0x4d19f4);else return this[n(531)]?this._ws[n(666)]:this._url}[t(627)](n=1e3,s){let l=t,u="2|5|1|3|0|6|7|4"[l(387)]("|"),_=0;for(;;){switch(u[_++]){case"0":this[l(445)+l(411)]?.[l(1254)]();continue;case"1":this[l(1591)+"ngTimer"]();continue;case"2":this[l(669)+"osed"]=!0;continue;case"3":this[l(1189)+l(286)+l(1012)]();continue;case"4":this[l(1212)+l(1369)+"t"](n,s);continue;case"5":this[l(874)+"mer"]();continue;case"6":if(!this._ws)return void this[l(303)](e.cXjcN);continue;case"7":if(this[l(531)][l(660)+"te"]===this[l(1085)]||e.ffkcz(this[l(531)][l(660)+"te"],this.CLOSING))return void this[l(303)]("close, w"+l(1242)+l(1532));continue}break}}async[t(1124)](n,s){let l=t;if(e.SPFDz(null,n))throw new Error(e.tnUaS);e[l(1346)](e.CgYfa,typeof n)&&(n=JSON[l(1325)+"y"](n)),e[l(1636)](e[l(1152)],typeof n)&&!e[l(1007)](n,ArrayBuffer)&&!(n[l(1409)]&&e.xYzIZ(n[l(1409)],ArrayBuffer))&&(n=JSON[l(1325)+"y"](n));let u=await e[l(561)](Wd,n),_=e[l(1564)]($x,n),{method:v=0,service:b=this._options[l(1327)],logID:p=this[l(506)].logIDGenerator(),headers:k=this._options.headers,payloadEncoding:B=this[l(506)].payloadEncoding,payloadType:z=this[l(506)][l(518)+l(1517)],logIDNew:U=this[l(506)]["logIDNew"+l(305)][l(747)+l(1107)+l(1285)+"ew"]?e[l(919)](i,this._options[l(1288)+"Config"][l(1026)]):""}=e[l(1090)](s,{});if(!b)throw new Error(e[l(981)]);let H={SeqID:ce[l(479)+"er"](this._seqId++),LogID:ce[l(479)+"er"](p),service:b,method:v,headers:k,payloadEncoding:e[l(741)](B,Object)?B.encoding?B[l(341)]:"":B,payloadType:e[l(1405)](z,Object)?z[l(819)]?z[l(819)]:_:z||_,payload:u,LogIDNew:U},V=e.NGfLT(Nt,H);return this[l(531)]&&e[l(480)](this[l(531)][l(660)+"te"],this[l(1309)])?(this[l(531)]&&this._ws[l(1124)](V),this[l(303)](e[l(1479)],H)):this[l(1640)+"Queue"].length<this[l(506)][l(283)+l(516)+"ength"]?(this["_message"+l(510)][l(1503)](V),this._debug(e.LAXrt,H)):(this["_message"+l(510)][l(1425)](),this[l(1640)+l(510)][l(1503)](V)),{seqID:this[l(1060)],logID:p,logIDNew:U}}async[t(673)+"t"](n){let s=t,{url:l}=e[s(1090)](n,{}),u=Array.isArray(l)?l:e[s(1153)](e[s(1152)],typeof l)?[l]:[];n&&Object[s(457)](this._options,n),u&&u[s(301)]?this[s(1188)+s(456)]=new Gd(u,this[s(506)].maxRetries):this[s(1188)+s(456)]?.["resetEnd"+s(814)+s(1629)](),this._pingLossCounter?.[s(1181)+s(684)](this._options[s(475)+s(705)]),this[s(669)+s(602)]=!1,this[s(531)]&&this[s(531)][s(660)+"te"]!==this[s(1085)]?this[s(665)+"ect"](1e3,"manual r"+s(395)+s(1406),!0):(this._isInit=!0,this[s(805)]())}async connect(){let n=t;if(!this[n(805)+n(646)])if(e.GIUbB(e[n(493)],e[n(927)]))this[n(1188)+"tManager"]?.[n(1167)+n(814)+n(1629)](),this["_pingLos"+n(432)]?.["resetCou"+n(684)](),this[n(669)+n(602)]=!1,this._isInit=!0,this[n(805)]();else return}[t(1330)+"Listener"](n,s){let l=t;if(e[l(1464)](e[l(1218)],e[l(1218)]))this.on(n,s);else{if(this[l(531)]&&this[l(531)][l(660)+"te"]===this[l(315)+"NG"]){this[l(1591)+l(1322)](),this["_pingPon"+l(428)+"Id"]=e.ItqTI(_0x1e1aa7,this._ping[l(1257)](this),this[l(506)][l(965)+l(1290)]);return}if(!this[l(531)]||e.qzLmK(this[l(531)][l(660)+"te"],this.OPEN))return void this[l(1430)+"econnect"]();this[l(531)]&&this._ws[l(1124)]("hi"),this[l(1462)+l(1073)+l(373)]=e[l(251)](_0x1eb745,this[l(1430)+l(395)+"Timeout"][l(1257)](this),this[l(506)][l(1320)+"outInter"+l(423)])}}[t(630)+"Event"](n){let s=t,{type:l}=n;this[s(835)](l,n)}[t(755)+"entListe"+t(1499)](n,s){let l=t;e.ivKZM(e[l(780)],e[l(780)])?(this[l(835)](l(1186),_0x3285e9),this.onerror&&this[l(1297)](_0x435d8c)):this[l(1596)](n,s)}[t(853)](){return new Promise((n,s)=>{let l=ee,u={PrQHU:function(b,p){return e.BcraG(b,p)},llZCI:l(435),qzkph:e[l(1551)],wovTZ:e[l(967)],SSHxP:e[l(355)]};this[l(1591)+"ngTimer"](),this[l(720)+l(428)+"Id"]=e[l(1383)](setTimeout,this[l(1533)][l(1257)](this),this[l(506)][l(965)+l(1290)]);let _=()=>{let b=l;u[b(1279)](n,u.llZCI),this[b(1596)](u[b(258)],_),this.off(u.wovTZ,v)},v=()=>{let b=l;u[b(1279)](s,u[b(356)]),this[b(1596)](b(1224)+"e_success",_),this[b(1596)](u.wovTZ,v)};this.on(e.mKFpL,_),this.on(e[l(967)],v),this[l(1533)]()})}}})(),Se[L(634)+L(647)]=Re[L(634)+L(647)],Se[L(686)+L(504)]=Re[L(686)+L(504)],Se[L(717)+"e"]=Re[L(717)+"e"],Se[L(1337)]=Re[L(1337)],Se.FWS=Re[L(1161)],Se[L(1422)+L(617)+L(1525)]=Re[L(1422)+"MessageE"+L(1525)],Se["MessageE"+L(1525)]=Re[L(617)+L(1525)],Se[L(824)+"t"]=Re[L(824)+"t"],Se[L(384)+"tEvent"]=Re.ReconnectEvent,Se[L(551)+L(647)]=Re.createCloseEvent,Se[L(661)+L(504)]=Re[L(661)+L(504)],Se[L(324)+L(1355)+"nt"]=Re[L(324)+L(1355)+"nt"],Se["createOp"+L(1412)]=Re["createOp"+L(1412)],Se[L(1497)+L(692)+L(1525)]=Re["createReconnectE"+L(1525)],Se.decodedFrame=Re[L(953)+L(1415)],Se[L(938)+L(1165)]=Re["encodeFr"+L(1165)];for(po in Re)[L(634)+L(647),L(686)+"rorEvent",L(717)+"e","Event",L(1161),L(1422)+L(617)+"vent",L(617)+L(1525),L(824)+"t",L(384)+L(1275),"createCl"+L(647),L(661)+"rorEvent",L(324)+L(1355)+"nt","createOp"+L(1412),L(1497)+L(692)+L(1525),L(953)+"rame","encodeFr"+L(1165)][L(775)](po)===-1&&(Se[po]=Re[po]);var po;Object[L(681)+L(1281)](Se,L(1045)+"le",{value:!0})});var qt=se((NR,$0)=>{"use strict";var q0=["nodebuffer","arraybuffer","fragments"],W0=typeof Blob<"u";W0&&q0.push("blob");$0.exports={BINARY_TYPES:q0,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:W0,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var Mi=se((MR,bo)=>{"use strict";var{EMPTY_BUFFER:DE}=qt(),Yc=Buffer[Symbol.species];function kE(t,e){if(t.length===0)return DE;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 Yc(r.buffer,r.byteOffset,i):r}function K0(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function Z0(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function OE(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function Xc(t){if(Xc.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new Yc(t):ArrayBuffer.isView(t)?e=new Yc(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),Xc.readOnly=!1),e}bo.exports={concat:kE,mask:K0,toArrayBuffer:OE,toBuffer:Xc,unmask:Z0};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=de("bufferutil");bo.exports.mask=function(e,r,i,o,c){c<48?K0(e,r,i,o,c):t.mask(e,r,i,o,c)},bo.exports.unmask=function(e,r){e.length<32?Z0(e,r):t.unmask(e,r)}}catch{}});var Y0=se((BR,J0)=>{"use strict";var V0=Symbol("kDone"),Qc=Symbol("kRun"),ed=class{constructor(e){this[V0]=()=>{this.pending--,this[Qc]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[Qc]()}[Qc](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[V0])}}};J0.exports=ed});var Rr=se((zR,th)=>{"use strict";var Bi=de("zlib"),X0=Mi(),PE=Y0(),{kStatusCode:Q0}=qt(),LE=Buffer[Symbol.species],NE=Buffer.from([0,0,255,255]),So=Symbol("permessage-deflate"),Wt=Symbol("total-length"),Ar=Symbol("callback"),_n=Symbol("buffers"),Tr=Symbol("error"),vo,td=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,!vo){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;vo=new PE(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[Ar];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){vo.add(o=>{this._decompress(e,r,(c,d)=>{o(),i(c,d)})})}compress(e,r,i){vo.add(o=>{this._compress(e,r,(c,d)=>{o(),i(c,d)})})}_decompress(e,r,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,d=typeof this.params[c]!="number"?Bi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Bi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:d}),this._inflate[So]=this,this._inflate[Wt]=0,this._inflate[_n]=[],this._inflate.on("error",BE),this._inflate.on("data",eh)}this._inflate[Ar]=i,this._inflate.write(e),r&&this._inflate.write(NE),this._inflate.flush(()=>{let c=this._inflate[Tr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let d=X0.concat(this._inflate[_n],this._inflate[Wt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Wt]=0,this._inflate[_n]=[],r&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,d)})}_compress(e,r,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,d=typeof this.params[c]!="number"?Bi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Bi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:d}),this._deflate[Wt]=0,this._deflate[_n]=[],this._deflate.on("data",ME)}this._deflate[Ar]=i,this._deflate.write(e),this._deflate.flush(Bi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=X0.concat(this._deflate[_n],this._deflate[Wt]);r&&(c=new LE(c.buffer,c.byteOffset,c.length-4)),this._deflate[Ar]=null,this._deflate[Wt]=0,this._deflate[_n]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};th.exports=td;function ME(t){this[_n].push(t),this[Wt]+=t.length}function eh(t){if(this[Wt]+=t.length,this[So]._maxPayload<1||this[Wt]<=this[So]._maxPayload){this[_n].push(t);return}this[Tr]=new RangeError("Max payload size exceeded"),this[Tr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Tr][Q0]=1009,this.removeListener("data",eh),this.reset()}function BE(t){if(this[So]._inflate=null,this[Tr]){this[Ar](this[Tr]);return}t[Q0]=1007,this[Ar](t)}});var Cr=se((FR,Io)=>{"use strict";var{isUtf8:nh}=de("buffer"),{hasBlob:zE}=qt(),FE=[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 UE(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function nd(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 GE(t){return zE&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Io.exports={isBlob:GE,isValidStatusCode:UE,isValidUTF8:nd,tokenChars:FE};if(nh)Io.exports.isValidUTF8=function(t){return t.length<24?nd(t):nh(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=de("utf-8-validate");Io.exports.isValidUTF8=function(e){return e.length<32?nd(e):t(e)}}catch{}});var ad=se((UR,dh)=>{"use strict";var{Writable:jE}=de("stream"),rh=Rr(),{BINARY_TYPES:HE,EMPTY_BUFFER:ih,kStatusCode:qE,kWebSocket:WE}=qt(),{concat:rd,toArrayBuffer:$E,unmask:KE}=Mi(),{isValidStatusCode:ZE,isValidUTF8:sh}=Cr(),Ao=Buffer[Symbol.species],ct=0,oh=1,ah=2,ch=3,id=4,sd=5,To=6,od=class extends jE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||HE[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[WE]=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 Ao(i.buffer,i.byteOffset+e,i.length-e),new Ao(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 Ao(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 oh:this.getPayloadLength16(e);break;case ah:this.getPayloadLength64(e);break;case ch:this.getMask();break;case id:this.getData(e);break;case sd:case To:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if((r[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(r[0]&64)===64;if(i&&!this._extensions[rh.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=oh: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=ch:this._state=id}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=id}getData(e){let r=ih;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&&KE(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=sd,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[rh.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let d=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(d);return}this._fragments.push(c)}this.dataMessage(r),this._state===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=rd(i,r):this._binaryType==="arraybuffer"?o=$E(rd(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=ct):(this._state=To,setImmediate(()=>{this.emit("message",o,!0),this._state=ct,this.startLoop(e)}))}else{let o=rd(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===sd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=ct):(this._state=To,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,ih),this.end();else{let i=e.readUInt16BE(0);if(!ZE(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Ao(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=ct;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=ct):(this._state=To,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 d=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(d,this.createError),d.code=c,d[qE]=o,d}};dh.exports=od});var ld=se((jR,uh)=>{"use strict";var{Duplex:GR}=de("stream"),{randomFillSync:VE}=de("crypto"),lh=Rr(),{EMPTY_BUFFER:JE,kWebSocket:YE,NOOP:XE}=qt(),{isBlob:Dr,isValidStatusCode:QE}=Cr(),{mask:fh,toBuffer:Un}=Mi(),dt=Symbol("kByteLength"),eb=Buffer.alloc(4),Ro=8*1024,Gn,kr=Ro,_t=0,tb=1,nb=2,cd=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=_t,this.onerror=XE,this[YE]=void 0}static frame(e,r){let i,o=!1,c=2,d=!1;r.mask&&(i=r.maskBuffer||eb,r.generateMask?r.generateMask(i):(kr===Ro&&(Gn===void 0&&(Gn=Buffer.alloc(Ro)),VE(Gn,0,Ro),kr=0),i[0]=Gn[kr++],i[1]=Gn[kr++],i[2]=Gn[kr++],i[3]=Gn[kr++]),d=(i[0]|i[1]|i[2]|i[3])===0,c=6);let f;typeof e=="string"?(!r.mask||d)&&r[dt]!==void 0?f=r[dt]:(e=Buffer.from(e),f=e.length):(f=e.length,o=r.mask&&r.readOnly&&!d);let h=f;f>=65536?(c+=8,h=127):f>125&&(c+=2,h=126);let x=Buffer.allocUnsafe(o?f+c:c);return x[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(x[0]|=64),x[1]=h,h===126?x.writeUInt16BE(f,2):h===127&&(x[2]=x[3]=0,x.writeUIntBE(f,4,6)),r.mask?(x[1]|=128,x[c-4]=i[0],x[c-3]=i[1],x[c-2]=i[2],x[c-1]=i[3],d?[x,e]:o?(fh(e,i,x,c,f),[x]):(fh(e,i,e,0,f),[x,e])):[x,e]}close(e,r,i,o){let c;if(e===void 0)c=JE;else{if(typeof e!="number"||!QE(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let f=Buffer.byteLength(r);if(f>123)throw new RangeError("The message must not be greater than 123 bytes");c=Buffer.allocUnsafe(2+f),c.writeUInt16BE(e,0),typeof r=="string"?c.write(r,2):c.set(r,2)}}let d={[dt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==_t?this.enqueue([this.dispatch,c,!1,d,o]):this.sendFrame(t.frame(c,d),o)}ping(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Dr(e)?(o=e.size,c=!1):(e=Un(e),o=e.length,c=Un.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[dt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Dr(e)?this._state!==_t?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==_t?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}pong(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Dr(e)?(o=e.size,c=!1):(e=Un(e),o=e.length,c=Un.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[dt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Dr(e)?this._state!==_t?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==_t?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}send(e,r,i){let o=this._extensions[lh.extensionName],c=r.binary?2:1,d=r.compress,f,h;typeof e=="string"?(f=Buffer.byteLength(e),h=!1):Dr(e)?(f=e.size,h=!1):(e=Un(e),f=e.length,h=Un.readOnly),this._firstFragment?(this._firstFragment=!1,d&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(d=f>=o._threshold),this._compress=d):(d=!1,c=0),r.fin&&(this._firstFragment=!0);let x={[dt]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:h,rsv1:d};Dr(e)?this._state!==_t?this.enqueue([this.getBlobData,e,this._compress,x,i]):this.getBlobData(e,this._compress,x,i):this._state!==_t?this.enqueue([this.dispatch,e,this._compress,x,i]):this.dispatch(e,this._compress,x,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[dt],this._state=nb,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let f=new Error("The socket was closed while the blob was being read");process.nextTick(dd,this,f,o);return}this._bufferedBytes-=i[dt];let d=Un(c);r?this.dispatch(d,r,i,o):(this._state=_t,this.sendFrame(t.frame(d,i),o),this.dequeue())}).catch(c=>{process.nextTick(rb,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[lh.extensionName];this._bufferedBytes+=i[dt],this._state=tb,c.compress(e,i.fin,(d,f)=>{if(this._socket.destroyed){let h=new Error("The socket was closed while data was being compressed");dd(this,h,o);return}this._bufferedBytes-=i[dt],this._state=_t,i.readOnly=!1,this.sendFrame(t.frame(f,i),o),this.dequeue()})}dequeue(){for(;this._state===_t&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][dt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][dt],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};uh.exports=cd;function dd(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 rb(t,e,r){dd(t,e,r),t.onerror(e)}});var Eh=se((HR,_h)=>{"use strict";var{kForOnEventAttribute:zi,kListener:fd}=qt(),hh=Symbol("kCode"),xh=Symbol("kData"),ph=Symbol("kError"),gh=Symbol("kMessage"),mh=Symbol("kReason"),Or=Symbol("kTarget"),wh=Symbol("kType"),yh=Symbol("kWasClean"),$t=class{constructor(e){this[Or]=null,this[wh]=e}get target(){return this[Or]}get type(){return this[wh]}};Object.defineProperty($t.prototype,"target",{enumerable:!0});Object.defineProperty($t.prototype,"type",{enumerable:!0});var jn=class extends $t{constructor(e,r={}){super(e),this[hh]=r.code===void 0?0:r.code,this[mh]=r.reason===void 0?"":r.reason,this[yh]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[hh]}get reason(){return this[mh]}get wasClean(){return this[yh]}};Object.defineProperty(jn.prototype,"code",{enumerable:!0});Object.defineProperty(jn.prototype,"reason",{enumerable:!0});Object.defineProperty(jn.prototype,"wasClean",{enumerable:!0});var Pr=class extends $t{constructor(e,r={}){super(e),this[ph]=r.error===void 0?null:r.error,this[gh]=r.message===void 0?"":r.message}get error(){return this[ph]}get message(){return this[gh]}};Object.defineProperty(Pr.prototype,"error",{enumerable:!0});Object.defineProperty(Pr.prototype,"message",{enumerable:!0});var Fi=class extends $t{constructor(e,r={}){super(e),this[xh]=r.data===void 0?null:r.data}get data(){return this[xh]}};Object.defineProperty(Fi.prototype,"data",{enumerable:!0});var ib={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[zi]&&o[fd]===e&&!o[zi])return;let i;if(t==="message")i=function(c,d){let f=new Fi("message",{data:d?c:c.toString()});f[Or]=this,Co(e,this,f)};else if(t==="close")i=function(c,d){let f=new jn("close",{code:c,reason:d.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});f[Or]=this,Co(e,this,f)};else if(t==="error")i=function(c){let d=new Pr("error",{error:c,message:c.message});d[Or]=this,Co(e,this,d)};else if(t==="open")i=function(){let c=new $t("open");c[Or]=this,Co(e,this,c)};else return;i[zi]=!!r[zi],i[fd]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[fd]===e&&!r[zi]){this.removeListener(t,r);break}}};_h.exports={CloseEvent:jn,ErrorEvent:Pr,Event:$t,EventTarget:ib,MessageEvent:Fi};function Co(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Do=se((qR,bh)=>{"use strict";var{tokenChars:Ui}=Cr();function Lt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function sb(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,d,f,h=-1,x=-1,m=-1,g=0;for(;g<t.length;g++)if(x=t.charCodeAt(g),d===void 0)if(m===-1&&Ui[x]===1)h===-1&&(h=g);else if(g!==0&&(x===32||x===9))m===-1&&h!==-1&&(m=g);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${g}`);m===-1&&(m=g);let w=t.slice(h,m);x===44?(Lt(e,w,r),r=Object.create(null)):d=w,h=m=-1}else throw new SyntaxError(`Unexpected character at index ${g}`);else if(f===void 0)if(m===-1&&Ui[x]===1)h===-1&&(h=g);else if(x===32||x===9)m===-1&&h!==-1&&(m=g);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${g}`);m===-1&&(m=g),Lt(r,t.slice(h,m),!0),x===44&&(Lt(e,d,r),r=Object.create(null),d=void 0),h=m=-1}else if(x===61&&h!==-1&&m===-1)f=t.slice(h,g),h=m=-1;else throw new SyntaxError(`Unexpected character at index ${g}`);else if(o){if(Ui[x]!==1)throw new SyntaxError(`Unexpected character at index ${g}`);h===-1?h=g:i||(i=!0),o=!1}else if(c)if(Ui[x]===1)h===-1&&(h=g);else if(x===34&&h!==-1)c=!1,m=g;else if(x===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${g}`);else if(x===34&&t.charCodeAt(g-1)===61)c=!0;else if(m===-1&&Ui[x]===1)h===-1&&(h=g);else if(h!==-1&&(x===32||x===9))m===-1&&(m=g);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${g}`);m===-1&&(m=g);let w=t.slice(h,m);i&&(w=w.replace(/\\/g,""),i=!1),Lt(r,f,w),x===44&&(Lt(e,d,r),r=Object.create(null),d=void 0),f=void 0,h=m=-1}else throw new SyntaxError(`Unexpected character at index ${g}`);if(h===-1||c||x===32||x===9)throw new SyntaxError("Unexpected end of input");m===-1&&(m=g);let A=t.slice(h,m);return d===void 0?Lt(e,A,r):(f===void 0?Lt(r,A,!0):i?Lt(r,f,A.replace(/\\/g,"")):Lt(r,f,A),Lt(e,d,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(d=>d===!0?o:`${o}=${d}`).join("; ")})).join("; ")).join(", ")}).join(", ")}bh.exports={format:ob,parse:sb}});var Lo=se((KR,Lh)=>{"use strict";var ab=de("events"),cb=de("https"),db=de("http"),Ih=de("net"),lb=de("tls"),{randomBytes:fb,createHash:ub}=de("crypto"),{Duplex:WR,Readable:$R}=de("stream"),{URL:ud}=de("url"),En=Rr(),hb=ad(),xb=ld(),{isBlob:pb}=Cr(),{BINARY_TYPES:vh,CLOSE_TIMEOUT:gb,EMPTY_BUFFER:ko,GUID:mb,kForOnEventAttribute:hd,kListener:wb,kStatusCode:yb,kWebSocket:Fe,NOOP:Ah}=qt(),{EventTarget:{addEventListener:_b,removeEventListener:Eb}}=Eh(),{format:bb,parse:vb}=Do(),{toBuffer:Sb}=Mi(),Th=Symbol("kAborted"),xd=[8,13],Kt=["CONNECTING","OPEN","CLOSING","CLOSED"],Ib=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,pe=class t extends ab{constructor(e,r,i){super(),this._binaryType=vh[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=ko,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),Rh(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){vh.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 hb({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new xb(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[Fe]=this,c[Fe]=this,e[Fe]=this,o.on("conclude",Rb),o.on("drain",Cb),o.on("error",Db),o.on("message",kb),o.on("ping",Ob),o.on("pong",Pb),c.onerror=Lb,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",kh),e.on("data",Po),e.on("end",Oh),e.on("error",Ph),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[En.extensionName]&&this._extensions[En.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){nt(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())}),Dh(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){pd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||ko,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){pd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||ko,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){pd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[En.extensionName]||(o.compress=!1),this._sender.send(e||ko,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){nt(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:Kt.indexOf("CONNECTING")});Object.defineProperty(pe.prototype,"CONNECTING",{enumerable:!0,value:Kt.indexOf("CONNECTING")});Object.defineProperty(pe,"OPEN",{enumerable:!0,value:Kt.indexOf("OPEN")});Object.defineProperty(pe.prototype,"OPEN",{enumerable:!0,value:Kt.indexOf("OPEN")});Object.defineProperty(pe,"CLOSING",{enumerable:!0,value:Kt.indexOf("CLOSING")});Object.defineProperty(pe.prototype,"CLOSING",{enumerable:!0,value:Kt.indexOf("CLOSING")});Object.defineProperty(pe,"CLOSED",{enumerable:!0,value:Kt.indexOf("CLOSED")});Object.defineProperty(pe.prototype,"CLOSED",{enumerable:!0,value:Kt.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[hd])return e[wb];return null},set(e){for(let r of this.listeners(t))if(r[hd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[hd]:!0})}})});pe.prototype.addEventListener=_b;pe.prototype.removeEventListener=Eb;Lh.exports=pe;function Rh(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:gb,protocolVersion:xd[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,!xd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${xd.join(", ")})`);let c;if(e instanceof ud)c=e;else try{c=new ud(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let d=c.protocol==="wss:",f=c.protocol==="ws+unix:",h;if(c.protocol!=="ws:"&&!d&&!f?h=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:f&&!c.pathname?h="The URL's pathname is empty":c.hash&&(h="The URL contains a fragment identifier"),h){let I=new SyntaxError(h);if(t._redirects===0)throw I;Oo(t,I);return}let x=d?443:80,m=fb(16).toString("base64"),g=d?cb.request:db.request,A=new Set,w;if(o.createConnection=o.createConnection||(d?Tb:Ab),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&&(w=new En({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=bb({[En.extensionName]:w.offer()})),r.length){for(let I of r){if(typeof I!="string"||!Ib.test(I)||A.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");A.add(I)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),f){let I=o.path.split(":");o.socketPath=I[0],o.path=I[1]}let E;if(o.followRedirects){if(t._redirects===0){t._originalIpc=f,t._originalSecure=d,t._originalHostOrSocketPath=f?o.socketPath:c.host;let I=i&&i.headers;if(i={...i,headers:{}},I)for(let[S,R]of Object.entries(I))i.headers[S.toLowerCase()]=R}else if(t.listenerCount("redirect")===0){let I=f?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!I||t._originalSecure&&!d)&&(delete o.headers.authorization,delete o.headers.cookie,I||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),E=t._req=g(o),t._redirects&&t.emit("redirect",t.url,E)}else E=t._req=g(o);o.timeout&&E.on("timeout",()=>{nt(t,E,"Opening handshake has timed out")}),E.on("error",I=>{E===null||E[Th]||(E=t._req=null,Oo(t,I))}),E.on("response",I=>{let S=I.headers.location,R=I.statusCode;if(S&&o.followRedirects&&R>=300&&R<400){if(++t._redirects>o.maxRedirects){nt(t,E,"Maximum redirects exceeded");return}E.abort();let P;try{P=new ud(S,e)}catch{let C=new SyntaxError(`Invalid URL: ${S}`);Oo(t,C);return}Rh(t,P,r,i)}else t.emit("unexpected-response",E,I)||nt(t,E,`Unexpected server response: ${I.statusCode}`)}),E.on("upgrade",(I,S,R)=>{if(t.emit("upgrade",I),t.readyState!==pe.CONNECTING)return;E=t._req=null;let P=I.headers.upgrade;if(P===void 0||P.toLowerCase()!=="websocket"){nt(t,S,"Invalid Upgrade header");return}let y=ub("sha1").update(m+mb).digest("base64");if(I.headers["sec-websocket-accept"]!==y){nt(t,S,"Invalid Sec-WebSocket-Accept header");return}let C=I.headers["sec-websocket-protocol"],D;if(C!==void 0?A.size?A.has(C)||(D="Server sent an invalid subprotocol"):D="Server sent a subprotocol but none was requested":A.size&&(D="Server sent no subprotocol"),D){nt(t,S,D);return}C&&(t._protocol=C);let N=I.headers["sec-websocket-extensions"];if(N!==void 0){if(!w){nt(t,S,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let M;try{M=vb(N)}catch{nt(t,S,"Invalid Sec-WebSocket-Extensions header");return}let K=Object.keys(M);if(K.length!==1||K[0]!==En.extensionName){nt(t,S,"Server indicated an extension that was not requested");return}try{w.accept(M[En.extensionName])}catch{nt(t,S,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[En.extensionName]=w}t.setSocket(S,R,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(E,t):E.end()}function Oo(t,e){t._readyState=pe.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Ab(t){return t.path=t.socketPath,Ih.connect(t)}function Tb(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Ih.isIP(t.host)?"":t.host),lb.connect(t)}function nt(t,e,r){t._readyState=pe.CLOSING;let i=new Error(r);Error.captureStackTrace(i,nt),e.setHeader?(e[Th]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Oo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function pd(t,e,r){if(e){let i=pb(e)?e.size:Sb(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Kt[t.readyState]})`);process.nextTick(r,i)}}function Rb(t,e){let r=this[Fe];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Fe]!==void 0&&(r._socket.removeListener("data",Po),process.nextTick(Ch,r._socket),t===1005?r.close():r.close(t,e))}function Cb(){let t=this[Fe];t.isPaused||t._socket.resume()}function Db(t){let e=this[Fe];e._socket[Fe]!==void 0&&(e._socket.removeListener("data",Po),process.nextTick(Ch,e._socket),e.close(t[yb])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Sh(){this[Fe].emitClose()}function kb(t,e){this[Fe].emit("message",t,e)}function Ob(t){let e=this[Fe];e._autoPong&&e.pong(t,!this._isServer,Ah),e.emit("ping",t)}function Pb(t){this[Fe].emit("pong",t)}function Ch(t){t.resume()}function Lb(t){let e=this[Fe];e.readyState!==pe.CLOSED&&(e.readyState===pe.OPEN&&(e._readyState=pe.CLOSING,Dh(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Dh(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function kh(){let t=this[Fe];if(this.removeListener("close",kh),this.removeListener("data",Po),this.removeListener("end",Oh),t._readyState=pe.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[Fe]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Sh),t._receiver.on("finish",Sh))}function Po(t){this[Fe]._receiver.write(t)||this.pause()}function Oh(){let t=this[Fe];t._readyState=pe.CLOSING,t._receiver.end(),this.end()}function Ph(){let t=this[Fe];this.removeListener("error",Ph),this.on("error",Ah),t&&(t._readyState=pe.CLOSING,this.destroy())}});var zh=se((VR,Bh)=>{"use strict";var ZR=Lo(),{Duplex:Nb}=de("stream");function Nh(t){t.emit("close")}function Mb(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Mh(t){this.removeListener("error",Mh),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function Bb(t,e){let r=!0,i=new Nb({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,d){let f=!d&&i._readableState.objectMode?c.toString():c;i.push(f)||t.pause()}),t.once("error",function(c){i.destroyed||(r=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick(Nh,i);return}let d=!1;t.once("error",function(h){d=!0,c(h)}),t.once("close",function(){d||c(o),process.nextTick(Nh,i)}),r&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,d){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,d)});return}t.send(o,d)},i.on("end",Mb),i.on("error",Mh),i}Bh.exports=Bb});var gd=se((JR,Fh)=>{"use strict";var{tokenChars:zb}=Cr();function Fb(t){let e=new Set,r=-1,i=-1,o=0;for(o;o<t.length;o++){let d=t.charCodeAt(o);if(i===-1&&zb[d]===1)r===-1&&(r=o);else if(o!==0&&(d===32||d===9))i===-1&&r!==-1&&(i=o);else if(d===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let f=t.slice(r,i);if(e.has(f))throw new SyntaxError(`The "${f}" subprotocol is duplicated`);e.add(f),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(r,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}Fh.exports={parse:Fb}});var $h=se((XR,Wh)=>{"use strict";var Ub=de("events"),No=de("http"),{Duplex:YR}=de("stream"),{createHash:Gb}=de("crypto"),Uh=Do(),Hn=Rr(),jb=gd(),Hb=Lo(),{CLOSE_TIMEOUT:qb,GUID:Wb,kWebSocket:$b}=qt(),Kb=/^[+/0-9A-Za-z]{22}==$/,Gh=0,jh=1,qh=2,md=class extends Ub{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:qb,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Hb,...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=No.createServer((i,o)=>{let c=No.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=Zb(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(o,c,d)=>{this.handleUpgrade(o,c,d,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Gh}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===qh){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Gi,this);return}if(e&&this.once("close",e),this._state!==jh)if(this._state=jh,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(Gi,this):process.nextTick(Gi,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{Gi(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",Hh);let c=e.headers["sec-websocket-key"],d=e.headers.upgrade,f=+e.headers["sec-websocket-version"];if(e.method!=="GET"){qn(this,e,r,405,"Invalid HTTP method");return}if(d===void 0||d.toLowerCase()!=="websocket"){qn(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!Kb.test(c)){qn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(f!==13&&f!==8){qn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){ji(r,400);return}let h=e.headers["sec-websocket-protocol"],x=new Set;if(h!==void 0)try{x=jb.parse(h)}catch{qn(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let m=e.headers["sec-websocket-extensions"],g={};if(this.options.perMessageDeflate&&m!==void 0){let A=new Hn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let w=Uh.parse(m);w[Hn.extensionName]&&(A.accept(w[Hn.extensionName]),g[Hn.extensionName]=A)}catch{qn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let A={origin:e.headers[`${f===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(A,(w,E,I,S)=>{if(!w)return ji(r,E||401,I,S);this.completeUpgrade(g,c,x,e,r,i,o)});return}if(!this.options.verifyClient(A))return ji(r,401)}this.completeUpgrade(g,c,x,e,r,i,o)}completeUpgrade(e,r,i,o,c,d,f){if(!c.readable||!c.writable)return c.destroy();if(c[$b])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Gh)return ji(c,503);let x=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Gb("sha1").update(r+Wb).digest("base64")}`],m=new this.options.WebSocket(null,void 0,this.options);if(i.size){let g=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;g&&(x.push(`Sec-WebSocket-Protocol: ${g}`),m._protocol=g)}if(e[Hn.extensionName]){let g=e[Hn.extensionName].params,A=Uh.format({[Hn.extensionName]:[g]});x.push(`Sec-WebSocket-Extensions: ${A}`),m._extensions=e}this.emit("headers",x,o),c.write(x.concat(`\r
15
15
  `).join(`\r
16
- `)),c.removeListener("error",Wx),w.setSocket(c,l,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(w),w.on("close",()=>{this.clients.delete(w),this._shouldEmitClose&&!this.clients.size&&process.nextTick(Hi,this)})),u(w,o)}};$x.exports=Ed;function Jb(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 Hi(t){t._state=Kx,t.emit("close")}function Wx(){this.destroy()}function ji(t,e,r,i){r=r||zo.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${zo.STATUS_CODES[e]}\r
16
+ `)),c.removeListener("error",Hh),m.setSocket(c,d,{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(Gi,this)})),f(m,o)}};Wh.exports=md;function Zb(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 Gi(t){t._state=qh,t.emit("close")}function Hh(){this.destroy()}function ji(t,e,r,i){r=r||No.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} ${No.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 ji(r,i,o,c)}});import{existsSync as _v,openSync as yv}from"node:fs";import{mkdir as Ev}from"node:fs/promises";import{dirname as bv}from"node:path";import{fileURLToPath as vv}from"node:url";function Av(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Ad(t=X()){return _v(t.libEntry)?t.libEntry:vv(new URL("../index.ts",import.meta.url))}async function ch(t={}){let e=t.paths??X(),r=t.entryOverride??Ad(e),i=Av(e,process.env.COZE_BRIDGE_LOG_MODE);await Ev(bv(i),{recursive:!0});let o=yv(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,[$i]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return Sv.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var Sv,$i,jo=Ze(()=>{"use strict";yn();ne();Oe();Sv=G("spawn-daemon"),$i="COZE_BRIDGE_DAEMON"});import{spawn as xS}from"node:child_process";import{mkdir as hS,unlink as pS,writeFile as gS}from"node:fs/promises";import{dirname as mS,join as wS}from"node:path";function Fr(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function _S(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Fr(r)}</key>
21
- <string>${Fr(i)}</string>`).join(`
20
+ `+r)}function qn(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let d=new Error(o);Error.captureStackTrace(d,qn),t.emit("wsClientError",d,r,e)}else ji(r,i,o,c)}});import{existsSync as w1,openSync as y1}from"node:fs";import{mkdir as _1}from"node:fs/promises";import{dirname as E1}from"node:path";import{fileURLToPath as b1}from"node:url";function S1(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Ed(t=Y()){return w1(t.libEntry)?t.libEntry:b1(new URL("../index.ts",import.meta.url))}async function ox(t={}){let e=t.paths??Y(),r=t.entryOverride??Ed(e),i=S1(e,process.env.COZE_BRIDGE_LOG_MODE);await _1(E1(i),{recursive:!0});let o=y1(i,"a"),d=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],f=at(process.execPath,d,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[Wi]:"1"}});if(f.unref(),typeof f.pid!="number")throw new Error("failed to spawn daemon (no pid)");return v1.info("daemon spawned",{pid:f.pid,entry:r}),{pid:f.pid,entry:r}}var v1,Wi,Go=Ke(()=>{"use strict";wn();ne();ke();v1=G("spawn-daemon"),Wi="COZE_BRIDGE_DAEMON"});import{spawn as uv}from"node:child_process";import{mkdir as hv,unlink as xv,writeFile as pv}from"node:fs/promises";import{dirname as gv,join as mv}from"node:path";function Br(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function wv(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Br(r)}</key>
21
+ <string>${Br(i)}</string>`).join(`
22
22
  `);return e?`
23
23
  <key>EnvironmentVariables</key>
24
24
  <dict>
25
25
  ${e}
26
- </dict>`:""}function yS(t,e){return new Promise((r,i)=>{let o=xS(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?r():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var zr,Ji,Yo,Od,Ah=Ze(()=>{"use strict";ne();zr=G("supervisor.launchd"),Ji="ai.coze.bridge",Yo=yS,Od={platform:"darwin",renderConfig(t){return`<?xml version="1.0" encoding="UTF-8"?>
26
+ </dict>`:""}function yv(t,e){return new Promise((r,i)=>{let o=uv(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var Mr,Ki,Zo,Rd,Sx=Ke(()=>{"use strict";ne();Mr=G("supervisor.launchd"),Ki="ai.coze.bridge",Zo=yv,Rd={platform:"darwin",renderConfig(t){return`<?xml version="1.0" encoding="UTF-8"?>
27
27
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
28
28
  <plist version="1.0">
29
29
  <dict>
30
30
  <key>Label</key>
31
- <string>${Ji}</string>
31
+ <string>${Ki}</string>
32
32
  <key>ProgramArguments</key>
33
33
  <array>
34
- <string>${Fr(t.nodeBin)}</string>
35
- <string>${Fr(t.entry)}</string>
34
+ <string>${Br(t.nodeBin)}</string>
35
+ <string>${Br(t.entry)}</string>
36
36
  <string>--daemon</string>
37
37
  </array>
38
38
  <key>RunAtLoad</key>
@@ -42,13 +42,13 @@ ${e}
42
42
  <key>ThrottleInterval</key>
43
43
  <integer>10</integer>
44
44
  <key>StandardOutPath</key>
45
- <string>${Fr(t.logFile)}</string>
45
+ <string>${Br(t.logFile)}</string>
46
46
  <key>StandardErrorPath</key>
47
- <string>${Fr(t.logFile)}</string>${_S(t.env)}
47
+ <string>${Br(t.logFile)}</string>${wv(t.env)}
48
48
  </dict>
49
49
  </plist>
50
- `},configPath(t){return wS(t.homeDir,"Library","LaunchAgents",`${Ji}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await hS(mS(i),{recursive:!0}),await gS(i,this.renderConfig(t),"utf8"),zr.info("plist written",{plistPath:i,activate:r}),!r)return;await Yo("launchctl",["unload","-w",i]).catch(c=>zr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await Yo("launchctl",["load","-w",i]),zr.info("launchd job loaded",{label:Ji});let o=process.getuid?.()??0;await Yo("launchctl",["kickstart","-k",`gui/${o}/${Ji}`]),zr.info("launchd job kickstarted",{label:Ji,uid:o})},async uninstall(t){let e=this.configPath(t);await Yo("launchctl",["unload","-w",e]).catch(r=>zr.warn("launchctl unload failed (ignored)",{err:String(r)})),await pS(e).catch(r=>{if(r.code!=="ENOENT")throw r}),zr.info("launchd job removed",{plistPath:e})}}});import{spawn as ES}from"node:child_process";import{mkdir as bS,unlink as vS,writeFile as SS}from"node:fs/promises";import{dirname as AS,join as Ih}from"node:path";function Qo(t,e){return t.isRoot?e:["--user",...e]}function TS(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
- `):""}function ea(t,e){return new Promise((r,i)=>{let o=ES(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?r():i(new Error(`${t} ${e.join(" ")} exited ${l}: ${c.trim()}`))})})}var Xo,Ur,IS,Pd,Th=Ze(()=>{"use strict";ne();Xo=G("supervisor.systemd"),Ur="coze-bridge.service",IS="/etc/systemd/system";Pd={platform:"linux",renderConfig(t){let e=t.isRoot?"multi-user.target":"default.target";return`[Unit]
50
+ `},configPath(t){return mv(t.homeDir,"Library","LaunchAgents",`${Ki}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await hv(gv(i),{recursive:!0}),await pv(i,this.renderConfig(t),"utf8"),Mr.info("plist written",{plistPath:i,activate:r}),!r)return;await Zo("launchctl",["unload","-w",i]).catch(c=>Mr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await Zo("launchctl",["load","-w",i]),Mr.info("launchd job loaded",{label:Ki});let o=process.getuid?.()??0;await Zo("launchctl",["kickstart","-k",`gui/${o}/${Ki}`]),Mr.info("launchd job kickstarted",{label:Ki,uid:o})},async uninstall(t){let e=this.configPath(t);await Zo("launchctl",["unload","-w",e]).catch(r=>Mr.warn("launchctl unload failed (ignored)",{err:String(r)})),await xv(e).catch(r=>{if(r.code!=="ENOENT")throw r}),Mr.info("launchd job removed",{plistPath:e})}}});import{spawn as _v}from"node:child_process";import{mkdir as Ev,unlink as bv,writeFile as vv}from"node:fs/promises";import{dirname as Sv,join as Ix}from"node:path";function Jo(t,e){return t.isRoot?e:["--user",...e]}function Av(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
+ `):""}function Yo(t,e){return new Promise((r,i)=>{let o=_v(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var Vo,zr,Iv,Cd,Ax=Ke(()=>{"use strict";ne();Vo=G("supervisor.systemd"),zr="coze-bridge.service",Iv="/etc/systemd/system";Cd={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
- ${TS(t.env)}
62
+ ${Av(t.env)}
63
63
  [Install]
64
64
  WantedBy=${e}
65
- `},configPath(t){return t.isRoot?Ih(IS,Ur):Ih(t.homeDir,".config","systemd","user",Ur)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await bS(AS(i),{recursive:!0}),await SS(i,this.renderConfig(t),"utf8"),Xo.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await ea("systemctl",Qo(t,["daemon-reload"])),await ea("systemctl",Qo(t,r?["enable","--now",Ur]:["enable",Ur])),Xo.info("systemd unit enabled",{unitName:Ur,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await ea("systemctl",Qo(t,["disable","--now",Ur])).catch(r=>Xo.warn("systemctl disable failed (ignored)",{err:String(r)})),await vS(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await ea("systemctl",Qo(t,["daemon-reload"])).catch(()=>{}),Xo.info("systemd unit removed",{unitPath:e})}}});import{spawn as CS}from"node:child_process";import{join as DS}from"node:path";function Ch(t,e){return new Promise((r,i)=>{let o=CS(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 Ld,ta,Nd,Dh=Ze(()=>{"use strict";ne();Ld=G("supervisor.taskscheduler"),ta="CozeBridge",Nd={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
65
+ `},configPath(t){return t.isRoot?Ix(Iv,zr):Ix(t.homeDir,".config","systemd","user",zr)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await Ev(Sv(i),{recursive:!0}),await vv(i,this.renderConfig(t),"utf8"),Vo.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await Yo("systemctl",Jo(t,["daemon-reload"])),await Yo("systemctl",Jo(t,r?["enable","--now",zr]:["enable",zr])),Vo.info("systemd unit enabled",{unitName:zr,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await Yo("systemctl",Jo(t,["disable","--now",zr])).catch(r=>Vo.warn("systemctl disable failed (ignored)",{err:String(r)})),await bv(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await Yo("systemctl",Jo(t,["daemon-reload"])).catch(()=>{}),Vo.info("systemd unit removed",{unitPath:e})}}});import{spawn as Tv}from"node:child_process";import{join as Rv}from"node:path";function Tx(t,e){return new Promise((r,i)=>{let o=Tv(t,e,{stdio:["ignore","pipe","pipe"],shell:!1}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var Dd,Xo,kd,Rx=Ke(()=>{"use strict";ne();Dd=G("supervisor.taskscheduler"),Xo="CozeBridge",kd={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
66
66
  <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
67
67
  <RegistrationInfo>
68
68
  <Description>Coze Bridge daemon</Description>
@@ -86,43 +86,43 @@ WantedBy=${e}
86
86
  </Exec>
87
87
  </Actions>
88
88
  </Task>
89
- `},configPath(t){return DS(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 Ch("schtasks",["/Create","/SC","ONLOGON","/TN",ta,"/TR",r,"/RU",t.userName,"/F"]),Ld.info("task scheduler entry created",{task:ta,logFile:t.logFile})},async uninstall(t){await Ch("schtasks",["/Delete","/TN",ta,"/F"]).catch(e=>Ld.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Ld.info("task scheduler entry removed",{task:ta})}}});var Rh={};pa(Rh,{buildContext:()=>NS,getSupervisor:()=>OS,launchdSupervisor:()=>Od,systemdSupervisor:()=>Pd,taskSchedulerSupervisor:()=>Nd});import{homedir as RS,userInfo as kS}from"node:os";function OS(t=process.platform){switch(t){case"darwin":return Od;case"linux":return Pd;case"win32":return Nd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function LS(){let t={};for(let e of PS){let r=process.env[e];r&&(t[e]=r)}return t}function NS(){let t=X();return{nodeBin:process.execPath,entry:Ad(t),logFile:t.logFile,homeDir:RS(),userName:kS().username,isRoot:process.getuid?.()===0,env:LS()}}var PS,kh=Ze(()=>{"use strict";Oe();jo();Ah();Th();Dh();PS=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ne();nn();var ul=G("acp-installer-warmup"),ng=["claude-code","codex"];async function fl(t={}){let e=t.ensure??er,i=(await Promise.allSettled(ng.map(async o=>{let c=await e(o);ul.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&ul.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}rn();ne();import{readdir as hg}from"node:fs/promises";import{mkdir as wl,writeFile as _l}from"node:fs/promises";import{join as ba}from"node:path";var xg={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function rr(t,e,r){await wl(t,{recursive:!0});let i=xg[e],o=ba(t,i);return await _l(o,r??"","utf8"),o}async function yl(t){let e=ba(t,".claude");await wl(e,{recursive:!0});let r=ba(e,"settings.local.json"),i=JSON.stringify({permissions:{defaultMode:"bypassPermissions"}},null,2);return await _l(r,i,"utf8"),r}var et=G("agent-detail-sync"),pg=6e4,gg=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 hg(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 He(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 He(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 x=this.retryQueue.get(e),p=x?Math.min(x.currentDelay*2,gg):pg;this.retryQueue.set(e,{dueAt:Date.now()+p,currentDelay:p});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 Ye(i,this.opts.paths),et.info("detail sync: config updated",{agentId:e,identityChanged:l,agentName:i.agentName}),l&&(await rr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var Mu=At(Ql(),1);import{lstat as Bc,mkdir as zc,readFile as Ou,readdir as Hw,rm as jw,stat as Ww,writeFile as Fc}from"node:fs/promises";import{dirname as Kw,join as Ot,normalize as $w,relative as qc,resolve as Uc,sep as Pu}from"node:path";import{Readable as Lu}from"node:stream";import{pipeline as Nu}from"node:stream/promises";import zg from"events";import Xe from"fs";import{EventEmitter as Ec}from"node:events";import L0 from"node:stream";import{StringDecoder as Fg}from"node:string_decoder";import B0 from"node:path";import pr from"node:fs";import{dirname as Xg,parse as Qg}from"path";import{EventEmitter as am}from"events";import nc from"assert";import{Buffer as Bn}from"buffer";import*as i0 from"zlib";import cm from"zlib";import{posix as cr}from"node:path";import{basename as Nm}from"node:path";import Us from"fs";import Dt from"fs";import u0 from"path";import{win32 as Km}from"node:path";import w0 from"path";import X0 from"node:fs";import dw from"node:assert";import{randomBytes as Q0}from"node:crypto";import re from"node:fs";import Le from"node:path";import eu from"fs";import Js from"node:fs";import gi from"node:path";import it from"node:fs";import gw from"node:fs/promises";import Hs from"node:path";import{join as uu}from"node:path";import rt from"node:fs";import hu from"node:path";var Mg=Object.defineProperty,Bg=(t,e)=>{for(var r in e)Mg(t,r,{get:e[r],enumerable:!0})},e0=typeof process=="object"&&process?process:{stdout:null,stderr:null},Ug=t=>!!t&&typeof t=="object"&&(t instanceof Un||t instanceof L0||Gg(t)||qg(t)),Gg=t=>!!t&&typeof t=="object"&&t instanceof Ec&&typeof t.pipe=="function"&&t.pipe!==L0.Writable.prototype.pipe,qg=t=>!!t&&typeof t=="object"&&t instanceof Ec&&typeof t.write=="function"&&typeof t.end=="function",Ut=Symbol("EOF"),Gt=Symbol("maybeEmitEnd"),on=Symbol("emittedEnd"),xs=Symbol("emittingEnd"),Qr=Symbol("emittedError"),hs=Symbol("closed"),t0=Symbol("read"),ps=Symbol("flush"),n0=Symbol("flushChunk"),pt=Symbol("encoding"),ar=Symbol("decoder"),Be=Symbol("flowing"),ei=Symbol("paused"),fr=Symbol("resume"),ze=Symbol("buffer"),Ve=Symbol("pipes"),Fe=Symbol("bufferLength"),Ca=Symbol("bufferPush"),gs=Symbol("bufferShift"),We=Symbol("objectMode"),Ae=Symbol("destroyed"),Da=Symbol("error"),Ra=Symbol("emitData"),r0=Symbol("emitEnd"),ka=Symbol("emitEnd2"),It=Symbol("async"),Oa=Symbol("abort"),ms=Symbol("aborted"),ti=Symbol("signal"),Cn=Symbol("dataListeners"),nt=Symbol("discarded"),ni=t=>Promise.resolve().then(t),Hg=t=>t(),jg=t=>t==="end"||t==="finish"||t==="prefinish",Wg=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,Kg=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),N0=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[fr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},$g=class extends N0{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)}},Vg=t=>!!t.objectMode,Jg=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Un=class extends Ec{[Be]=!1;[ei]=!1;[Ve]=[];[ze]=[];[We];[pt];[It];[ar];[Ut]=!1;[on]=!1;[xs]=!1;[hs]=!1;[Qr]=null;[Fe]=0;[Ae]=!1;[ti];[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");Vg(e)?(this[We]=!0,this[pt]=null):Jg(e)?(this[pt]=e.encoding,this[We]=!1):(this[We]=!1,this[pt]=null),this[It]=!!e.async,this[ar]=this[pt]?new Fg(this[pt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[ze]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Ve]});let{signal:r}=e;r&&(this[ti]=r,r.aborted?this[Oa]():r.addEventListener("abort",()=>this[Oa]()))}get bufferLength(){return this[Fe]}get encoding(){return this[pt]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[We]}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}[Oa](){this[ms]=!0,this.emit("abort",this[ti]?.reason),this.destroy(this[ti]?.reason)}get aborted(){return this[ms]}set aborted(t){}write(t,e,r){if(this[ms])return!1;if(this[Ut])throw new Error("write after end");if(this[Ae])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof e=="function"&&(r=e,e="utf8"),e||(e="utf8");let i=this[It]?ni:Hg;if(!this[We]&&!Buffer.isBuffer(t)){if(Kg(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(Wg(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[We]?(this[Be]&&this[Fe]!==0&&this[ps](!0),this[Be]?this.emit("data",t):this[Ca](t),this[Fe]!==0&&this.emit("readable"),r&&i(r),this[Be]):t.length?(typeof t=="string"&&!(e===this[pt]&&!this[ar]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[pt]&&(t=this[ar].write(t)),this[Be]&&this[Fe]!==0&&this[ps](!0),this[Be]?this.emit("data",t):this[Ca](t),this[Fe]!==0&&this.emit("readable"),r&&i(r),this[Be]):(this[Fe]!==0&&this.emit("readable"),r&&i(r),this[Be])}read(t){if(this[Ae])return null;if(this[nt]=!1,this[Fe]===0||t===0||t&&t>this[Fe])return this[Gt](),null;this[We]&&(t=null),this[ze].length>1&&!this[We]&&(this[ze]=[this[pt]?this[ze].join(""):Buffer.concat(this[ze],this[Fe])]);let e=this[t0](t||null,this[ze][0]);return this[Gt](),e}[t0](t,e){if(this[We])this[gs]();else{let r=e;t===r.length||t===null?this[gs]():typeof r=="string"?(this[ze][0]=r.slice(t),e=r.slice(0,t),this[Fe]-=t):(this[ze][0]=r.subarray(t),e=r.subarray(0,t),this[Fe]-=t)}return this.emit("data",e),!this[ze].length&&!this[Ut]&&this.emit("drain"),e}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e="utf8"),t!==void 0&&this.write(t,e),r&&this.once("end",r),this[Ut]=!0,this.writable=!1,(this[Be]||!this[ei])&&this[Gt](),this}[fr](){this[Ae]||(!this[Cn]&&!this[Ve].length&&(this[nt]=!0),this[ei]=!1,this[Be]=!0,this.emit("resume"),this[ze].length?this[ps]():this[Ut]?this[Gt]():this.emit("drain"))}resume(){return this[fr]()}pause(){this[Be]=!1,this[ei]=!0,this[nt]=!1}get destroyed(){return this[Ae]}get flowing(){return this[Be]}get paused(){return this[ei]}[Ca](t){this[We]?this[Fe]+=1:this[Fe]+=t.length,this[ze].push(t)}[gs](){return this[We]?this[Fe]-=1:this[Fe]-=this[ze][0].length,this[ze].shift()}[ps](t=!1){do;while(this[n0](this[gs]())&&this[ze].length);!t&&!this[ze].length&&!this[Ut]&&this.emit("drain")}[n0](t){return this.emit("data",t),this[Be]}pipe(t,e){if(this[Ae])return t;this[nt]=!1;let r=this[on];return e=e||{},t===e0.stdout||t===e0.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[Ve].push(e.proxyErrors?new $g(this,t,e):new N0(this,t,e)),this[It]?ni(()=>this[fr]()):this[fr]()),t}unpipe(t){let e=this[Ve].find(r=>r.dest===t);e&&(this[Ve].length===1?(this[Be]&&this[Cn]===0&&(this[Be]=!1),this[Ve]=[]):this[Ve].splice(this[Ve].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[nt]=!1,this[Cn]++,!this[Ve].length&&!this[Be]&&this[fr]();else if(t==="readable"&&this[Fe]!==0)super.emit("readable");else if(jg(t)&&this[on])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[Qr]){let i=e;this[It]?ni(()=>i.call(this,this[Qr])):i.call(this,this[Qr])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Cn]=this.listeners("data").length,this[Cn]===0&&!this[nt]&&!this[Ve].length&&(this[Be]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Cn]=0,!this[nt]&&!this[Ve].length&&(this[Be]=!1)),e}get emittedEnd(){return this[on]}[Gt](){!this[xs]&&!this[on]&&!this[Ae]&&this[ze].length===0&&this[Ut]&&(this[xs]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[hs]&&this.emit("close"),this[xs]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Ae&&this[Ae])return!1;if(t==="data")return!this[We]&&!r?!1:this[It]?(ni(()=>this[Ra](r)),!0):this[Ra](r);if(t==="end")return this[r0]();if(t==="close"){if(this[hs]=!0,!this[on]&&!this[Ae])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[Qr]=r,super.emit(Da,r);let o=!this[ti]||this.listeners("error").length?super.emit("error",r):!1;return this[Gt](),o}else if(t==="resume"){let o=super.emit("resume");return this[Gt](),o}else if(t==="finish"||t==="prefinish"){let o=super.emit(t);return this.removeAllListeners(t),o}let i=super.emit(t,...e);return this[Gt](),i}[Ra](t){for(let r of this[Ve])r.dest.write(t)===!1&&this.pause();let e=this[nt]?!1:super.emit("data",t);return this[Gt](),e}[r0](){return this[on]?!1:(this[on]=!0,this.readable=!1,this[It]?(ni(()=>this[ka]()),!0):this[ka]())}[ka](){if(this[ar]){let e=this[ar].end();if(e){for(let r of this[Ve])r.dest.write(e);this[nt]||super.emit("data",e)}}for(let e of this[Ve])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[We]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[We]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[We])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[pt]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Ae,()=>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[Ut])return e();let i,o,c=p=>{this.off("data",l),this.off("end",u),this.off(Ae,x),e(),o(p)},l=p=>{this.off("error",c),this.off("end",u),this.off(Ae,x),this.pause(),i({value:p,done:!!this[Ut]})},u=()=>{this.off("error",c),this.off("data",l),this.off(Ae,x),e(),i({done:!0,value:void 0})},x=()=>c(new Error("stream destroyed"));return new Promise((p,w)=>{o=w,i=p,this.once(Ae,x),this.once("error",c),this.once("end",u),this.once("data",l)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[nt]=!1;let t=!1,e=()=>(this.pause(),this.off(Da,e),this.off(Ae,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(Da,e),this.once(Ae,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Ae])return t?this.emit("error",t):this.emit(Ae),this;this[Ae]=!0,this[nt]=!0,this[ze].length=0,this[Fe]=0;let e=this;return typeof e.close=="function"&&!this[hs]&&e.close(),t?this.emit("error",t):this.emit(Ae),this}static get isStream(){return Ug}},Zg=Xe.writev,gn=Symbol("_autoClose"),_t=Symbol("_close"),ri=Symbol("_ended"),ae=Symbol("_fd"),Pa=Symbol("_finished"),Wt=Symbol("_flags"),La=Symbol("_flush"),ec=Symbol("_handleChunk"),tc=Symbol("_makeBuf"),hi=Symbol("_mode"),ws=Symbol("_needDrain"),mr=Symbol("_onerror"),wr=Symbol("_onopen"),Na=Symbol("_onread"),xr=Symbol("_onwrite"),mn=Symbol("_open"),wt=Symbol("_path"),un=Symbol("_pos"),Tt=Symbol("_queue"),hr=Symbol("_read"),Ma=Symbol("_readSize"),jt=Symbol("_reading"),ii=Symbol("_remain"),Ba=Symbol("_size"),Cs=Symbol("_write"),Dn=Symbol("_writing"),Ds=Symbol("_defaultFlag"),Mn=Symbol("_errored"),bc=class extends Un{[Mn]=!1;[ae];[wt];[Ma];[jt]=!1;[Ba];[ii];[gn];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[Mn]=!1,this[ae]=typeof e.fd=="number"?e.fd:void 0,this[wt]=t,this[Ma]=e.readSize||16*1024*1024,this[jt]=!1,this[Ba]=typeof e.size=="number"?e.size:1/0,this[ii]=this[Ba],this[gn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[ae]=="number"?this[hr]():this[mn]()}get fd(){return this[ae]}get path(){return this[wt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[mn](){Xe.open(this[wt],"r",(t,e)=>this[wr](t,e))}[wr](t,e){t?this[mr](t):(this[ae]=e,this.emit("open",e),this[hr]())}[tc](){return Buffer.allocUnsafe(Math.min(this[Ma],this[ii]))}[hr](){if(!this[jt]){this[jt]=!0;let t=this[tc]();if(t.length===0)return process.nextTick(()=>this[Na](null,0,t));Xe.read(this[ae],t,0,t.length,null,(e,r,i)=>this[Na](e,r,i))}}[Na](t,e,r){this[jt]=!1,t?this[mr](t):this[ec](e,r)&&this[hr]()}[_t](){if(this[gn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Xe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[mr](t){this[jt]=!0,this[_t](),this.emit("error",t)}[ec](t,e){let r=!1;return this[ii]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[ii]<=0)&&(r=!1,this[_t](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[ae]=="number"&&this[hr](),!1;case"error":return this[Mn]?!1:(this[Mn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Yg=class extends bc{[mn](){let t=!0;try{this[wr](null,Xe.openSync(this[wt],"r")),t=!1}finally{t&&this[_t]()}}[hr](){let t=!0;try{if(!this[jt]){this[jt]=!0;do{let e=this[tc](),r=e.length===0?0:Xe.readSync(this[ae],e,0,e.length,null);if(!this[ec](r,e))break}while(!0);this[jt]=!1}t=!1}finally{t&&this[_t]()}}[_t](){if(this[gn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Xe.closeSync(t),this.emit("close")}}},js=class extends zg{readable=!1;writable=!0;[Mn]=!1;[Dn]=!1;[ri]=!1;[Tt]=[];[ws]=!1;[wt];[hi];[gn];[ae];[Ds];[Wt];[Pa]=!1;[un];constructor(t,e){e=e||{},super(e),this[wt]=t,this[ae]=typeof e.fd=="number"?e.fd:void 0,this[hi]=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[Ds]=e.flags===void 0,this[Wt]=e.flags===void 0?r:e.flags,this[ae]===void 0&&this[mn]()}emit(t,...e){if(t==="error"){if(this[Mn])return!1;this[Mn]=!0}return super.emit(t,...e)}get fd(){return this[ae]}get path(){return this[wt]}[mr](t){this[_t](),this[Dn]=!0,this.emit("error",t)}[mn](){Xe.open(this[wt],this[Wt],this[hi],(t,e)=>this[wr](t,e))}[wr](t,e){this[Ds]&&this[Wt]==="r+"&&t&&t.code==="ENOENT"?(this[Wt]="w",this[mn]()):t?this[mr](t):(this[ae]=e,this.emit("open",e),this[Dn]||this[La]())}end(t,e){return t&&this.write(t,e),this[ri]=!0,!this[Dn]&&!this[Tt].length&&typeof this[ae]=="number"&&this[xr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[ri]?(this.emit("error",new Error("write() after end()")),!1):this[ae]===void 0||this[Dn]||this[Tt].length?(this[Tt].push(t),this[ws]=!0,!1):(this[Dn]=!0,this[Cs](t),!0)}[Cs](t){Xe.write(this[ae],t,0,t.length,this[un],(e,r)=>this[xr](e,r))}[xr](t,e){t?this[mr](t):(this[un]!==void 0&&typeof e=="number"&&(this[un]+=e),this[Tt].length?this[La]():(this[Dn]=!1,this[ri]&&!this[Pa]?(this[Pa]=!0,this[_t](),this.emit("finish")):this[ws]&&(this[ws]=!1,this.emit("drain"))))}[La](){if(this[Tt].length===0)this[ri]&&this[xr](null,0);else if(this[Tt].length===1)this[Cs](this[Tt].pop());else{let t=this[Tt];this[Tt]=[],Zg(this[ae],t,this[un],(e,r)=>this[xr](e,r))}}[_t](){if(this[gn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Xe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},M0=class extends js{[mn](){let t;if(this[Ds]&&this[Wt]==="r+")try{t=Xe.openSync(this[wt],this[Wt],this[hi])}catch(e){if(e?.code==="ENOENT")return this[Wt]="w",this[mn]();throw e}else t=Xe.openSync(this[wt],this[Wt],this[hi]);this[wr](null,t)}[_t](){if(this[gn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Xe.closeSync(t),this.emit("close")}}[Cs](t){let e=!0;try{this[xr](null,Xe.writeSync(this[ae],t,0,t.length,this[un])),e=!1}finally{if(e)try{this[_t]()}catch{}}}},em=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),tm=t=>!!t.sync&&!!t.file,nm=t=>!t.sync&&!!t.file,rm=t=>!!t.sync&&!t.file,im=t=>!t.sync&&!t.file,sm=t=>!!t.file,om=t=>em.get(t)||t,vc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=om(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},vi=(t,e,r,i,o)=>Object.assign((c=[],l,u)=>{Array.isArray(c)&&(l=c,c={}),typeof l=="function"&&(u=l,l=void 0),l=l?Array.from(l):[];let x=vc(c);if(o?.(x,l),tm(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(x,l)}else if(nm(x)){let p=e(x,l);return u?p.then(()=>u(),u):p}else if(rm(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(x,l)}else if(im(x)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(x,l)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),dm=cm.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},dm)),lm=Bn.concat,s0=Object.getOwnPropertyDescriptor(Bn,"concat"),um=t=>t,za=s0?.writable===!0||s0?.set!==void 0?t=>{Bn.concat=t?um:lm}:t=>{},zn=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"}},Fa=Symbol("flushFlag"),Sc=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 i0[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new i0[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 nc(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),{[Fa]:t})))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(r)}get ended(){return this.#n}[zn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Bn.from(t,e)),this.#e)return;nc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},za(!0);let l;try{let x=typeof t[Fa]=="number"?t[Fa]:this.#r;l=this.#t._processChunk(t,x),za(!1)}catch(x){za(!1),this.#o(new _s(x,this.write))}finally{this.#t&&(this.#t._handle=i,i.close=o,this.#t.close=c,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",x=>this.#o(new _s(x,this.write)));let u;if(l)if(Array.isArray(l)&&l.length>0){let x=l[0];u=this[zn](Bn.from(x));for(let p=1;p<l.length;p++)u=this[zn](l[p])}else u=this[zn](Bn.from(l));return r&&r(),u}},z0=class extends Sc{#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),nc(this.handle,"zlib binding closed");let r=this.handle.flush;this.handle.flush=(i,o)=>{typeof i=="function"&&(o=i,i=this.flushFlag),this.flush(i),o?.()};try{this.handle.params(t,e)}finally{this.handle.flush=r}this.handle&&(this.#e=t,this.#n=e)}}}},fm=class extends z0{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[zn](t){return this.#e?(this.#e=!1,t[9]=255,super[zn](t)):super[zn](t)}},xm=class extends z0{constructor(t){super(t,"Unzip")}},F0=class extends Sc{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)}},hm=class extends F0{constructor(t){super(t,"BrotliCompress")}},pm=class extends F0{constructor(t){super(t,"BrotliDecompress")}},U0=class extends Sc{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)}},gm=class extends U0{constructor(t){super(t,"ZstdCompress")}},mm=class extends U0{constructor(t){super(t,"ZstdDecompress")}},wm=(t,e)=>{if(Number.isSafeInteger(t))t<0?ym(t,e):_m(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},_m=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},ym=(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]=G0(o):o===0?e[i-1]=0:(r=!0,e[i-1]=q0(o))}},Em=t=>{let e=t[0],r=e===128?vm(t.subarray(1,t.length)):e===255?bm(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},bm=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),l;i?l=G0(c):c===0?l=c:(i=!0,l=q0(c)),l!==0&&(r-=l*Math.pow(256,e-o-1))}return r},vm=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},G0=t=>(255^t)&255,q0=t=>(255^t)+1&255,Sm={};Bg(Sm,{code:()=>Ac,isCode:()=>Rs,isName:()=>Am,name:()=>Ws});var Rs=t=>Ws.has(t),Am=t=>Ac.has(t),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"]]),Ac=new Map(Array.from(Ws).map(t=>[t[1],t[0]])),Fn=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,r,i){Buffer.isBuffer(t)?this.decode(t,e||0,r,i):t&&this.#n(t)}decode(t,e,r,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");this.path=r?.path??Rn(t,e,100),this.mode=r?.mode??i?.mode??fn(t,e+100,8),this.uid=r?.uid??i?.uid??fn(t,e+108,8),this.gid=r?.gid??i?.gid??fn(t,e+116,8),this.size=r?.size??i?.size??fn(t,e+124,12),this.mtime=r?.mtime??i?.mtime??Ua(t,e+136,12),this.cksum=fn(t,e+148,12),i&&this.#n(i,!0),r&&this.#n(r);let o=Rn(t,e+156,1);if(Rs(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Rn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=r?.uname??i?.uname??Rn(t,e+265,32),this.gname=r?.gname??i?.gname??Rn(t,e+297,32),this.devmaj=r?.devmaj??i?.devmaj??fn(t,e+329,8)??0,this.devmin=r?.devmin??i?.devmin??fn(t,e+337,8)??0,t[e+475]!==0){let l=Rn(t,e+345,155);this.path=l+"/"+this.path}else{let l=Rn(t,e+345,130);l&&(this.path=l+"/"+this.path),this.atime=r?.atime??i?.atime??Ua(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Ua(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=Im(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=kn(t,e,100,o)||this.needPax,this.needPax=xn(t,e+100,8,this.mode)||this.needPax,this.needPax=xn(t,e+108,8,this.uid)||this.needPax,this.needPax=xn(t,e+116,8,this.gid)||this.needPax,this.needPax=xn(t,e+124,12,this.size)||this.needPax,this.needPax=Ga(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=kn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=kn(t,e+265,32,this.uname)||this.needPax,this.needPax=kn(t,e+297,32,this.gname)||this.needPax,this.needPax=xn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=xn(t,e+337,8,this.devmin)||this.needPax,this.needPax=kn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=kn(t,e+345,155,c)||this.needPax:(this.needPax=kn(t,e+345,130,c)||this.needPax,this.needPax=Ga(t,e+476,12,this.atime)||this.needPax,this.needPax=Ga(t,e+488,12,this.ctime)||this.needPax);let l=256;for(let u=e;u<e+148;u++)l+=t[u];for(let u=e+156;u<e+512;u++)l+=t[u];return this.cksum=l,xn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:Ws.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Ac.get(t));if(Rs(e)||e==="Unsupported")this.#e=e;else if(Rs(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Im=(t,e)=>{let r=t,i="",o,c=cr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=cr.dirname(r),r=cr.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=cr.join(cr.basename(i),r),i=cr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Rn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Ua=(t,e,r)=>Tm(fn(t,e,r)),Tm=t=>t===void 0?void 0:new Date(t*1e3),fn=(t,e,r)=>Number(t[e])&128?Em(t.subarray(e,e+r)):Dm(t,e,r),Cm=t=>isNaN(t)?void 0:t,Dm=(t,e,r)=>Cm(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),Rm={12:8589934591,8:2097151},xn=(t,e,r,i)=>i===void 0?!1:i>Rm[r]||i<0?(wm(i,t.subarray(e,e+r)),!0):(km(t,e,r,i),!1),km=(t,e,r,i)=>t.write(Om(i,r),e,r,"ascii"),Om=(t,e)=>Pm(Math.floor(t).toString(8),e),Pm=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Ga=(t,e,r,i)=>i===void 0?!1:xn(t,e,r,i.getTime()/1e3),Lm=new Array(156).join("\0"),kn=(t,e,r,i)=>i===void 0?!1:(t.write(i+Lm,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),Fs=class H0{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,r=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=r,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return Buffer.allocUnsafe(0);let r=Buffer.byteLength(e),i=512*Math.ceil(1+r/512),o=Buffer.allocUnsafe(i);for(let c=0;c<512;c++)o[c]=0;new Fn({path:("PaxHeader/"+Nm(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 H0(Mm(Bm(e),r),i)}},Mm=(t,e)=>e?Object.assign({},e,t):t,Bm=t=>t.replace(/\n$/,"").split(`
91
- `).reduce(zm,Object.create(null)),zm=(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},Fm=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Y=Fm!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),j0=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=Y(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?Y(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=Y(t.path)),t.linkpath&&(t.linkpath=Y(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))},Um=1024*1024,rc=Buffer.from([31,139]),ic=Buffer.from([40,181,47,253]),Gm=Math.max(rc.length,ic.length),at=Symbol("state"),On=Symbol("writeEntry"),qt=Symbol("readEntry"),qa=Symbol("nextEntry"),o0=Symbol("processEntry"),Ct=Symbol("extendedHeader"),si=Symbol("globalExtendedHeader"),an=Symbol("meta"),a0=Symbol("emitMeta"),xe=Symbol("buffer"),Ht=Symbol("queue"),cn=Symbol("ended"),Ha=Symbol("emittedEnd"),Pn=Symbol("emit"),Ce=Symbol("unzip"),ys=Symbol("consumeChunk"),Es=Symbol("consumeChunkSub"),ja=Symbol("consumeBody"),c0=Symbol("consumeMeta"),d0=Symbol("consumeHeader"),oi=Symbol("consuming"),Wa=Symbol("bufferConcat"),bs=Symbol("maybeEnd"),dr=Symbol("writing"),dn=Symbol("aborted"),vs=Symbol("onDone"),Ln=Symbol("sawValidEntry"),Ss=Symbol("sawNullBlock"),As=Symbol("sawEOF"),l0=Symbol("closeStream"),qm=()=>!0,bi=class extends am{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Ht]=[];[xe];[qt];[On];[at]="begin";[an]="";[Ct];[si];[cn]=!1;[Ce];[dn]=!1;[Ln];[Ss]=!1;[As]=!1;[dr]=!1;[oi]=!1;[Ha]=!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||Um,this.filter=typeof t.filter=="function"?t.filter:qm;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[l0]()),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)}[d0](t,e){this[Ln]===void 0&&(this[Ln]=!1);let r;try{r=new Fn(t,e,this[Ct],this[si])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Ss]?(this[As]=!0,this[at]==="begin"&&(this[at]="header"),this[Pn]("eof")):(this[Ss]=!0,this[Pn]("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[On]=new j0(r,this[Ct],this[si]);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[Pn]("ignoredEntry",o),this[at]="ignore",o.resume()):o.size>0&&(this[an]="",o.on("data",c=>this[an]+=c),this[at]="meta"):(this[Ct]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Pn]("ignoredEntry",o),this[at]=o.remain?"ignore":"header",o.resume()):(o.remain?this[at]="body":(this[at]="header",o.end()),this[qt]?this[Ht].push(o):(this[Ht].push(o),this[qa]())))}}}[l0](){queueMicrotask(()=>this.emit("close"))}[o0](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[qa]()),e=!1);return e}[qa](){do;while(this[o0](this[Ht].shift()));if(this[Ht].length===0){let t=this[qt];!t||t.flowing||t.size===t.remain?this[dr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[ja](t,e){let r=this[On];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[On]=void 0,r.end()),o.length}[c0](t,e){let r=this[On],i=this[ja](t,e);return!this[On]&&r&&this[a0](r),i}[Pn](t,e,r){this[Ht].length===0&&!this[qt]?this.emit(t,e,r):this[Ht].push([t,e,r])}[a0](t){switch(this[Pn]("meta",this[an]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Ct]=Fs.parse(this[an],this[Ct],!1);break;case"GlobalExtendedHeader":this[si]=Fs.parse(this[an],this[si],!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[dn]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[dn])return r?.(),!1;if((this[Ce]===void 0||this.brotli===void 0&&this[Ce]===!1)&&t){if(this[xe]&&(t=Buffer.concat([this[xe],t]),this[xe]=void 0),t.length<Gm)return this[xe]=t,r?.(),!0;for(let l=0;this[Ce]===void 0&&l<rc.length;l++)t[l]!==rc[l]&&(this[Ce]=!1);let o=!1;if(this[Ce]===!1&&this.zstd!==!1){o=!0;for(let l=0;l<ic.length;l++)if(t[l]!==ic[l]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Ce]===!1&&c)if(t.length<512)if(this[cn])this.brotli=!0;else return this[xe]=t,r?.(),!0;else try{new Fn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Ce]===void 0||this[Ce]===!1&&(this.brotli||o)){let l=this[cn];this[cn]=!1,this[Ce]=this[Ce]===void 0?new xm({}):o?new mm({}):new pm({}),this[Ce].on("data",x=>this[ys](x)),this[Ce].on("error",x=>this.abort(x)),this[Ce].on("end",()=>{this[cn]=!0,this[ys]()}),this[dr]=!0;let u=!!this[Ce][l?"end":"write"](t);return this[dr]=!1,r?.(),u}}this[dr]=!0,this[Ce]?this[Ce].write(t):this[ys](t),this[dr]=!1;let i=this[Ht].length>0?!1:this[qt]?this[qt].flowing:!0;return!i&&this[Ht].length===0&&this[qt]?.once("drain",()=>this.emit("drain")),r?.(),i}[Wa](t){t&&!this[dn]&&(this[xe]=this[xe]?Buffer.concat([this[xe],t]):t)}[bs](){if(this[cn]&&!this[Ha]&&!this[dn]&&!this[oi]){this[Ha]=!0;let t=this[On];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[Pn](vs)}}[ys](t){if(this[oi]&&t)this[Wa](t);else if(!t&&!this[xe])this[bs]();else if(t){if(this[oi]=!0,this[xe]){this[Wa](t);let e=this[xe];this[xe]=void 0,this[Es](e)}else this[Es](t);for(;this[xe]&&this[xe]?.length>=512&&!this[dn]&&!this[As];){let e=this[xe];this[xe]=void 0,this[Es](e)}this[oi]=!1}(!this[xe]||this[cn])&&this[bs]()}[Es](t){let e=0,r=t.length;for(;e+512<=r&&!this[dn]&&!this[As];)switch(this[at]){case"begin":case"header":this[d0](t,e),e+=512;break;case"ignore":case"body":e+=this[ja](t,e);break;case"meta":e+=this[c0](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[dn]||(this[Ce]?(t&&this[Ce].write(t),this[Ce].end()):(this[cn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[bs]())),this}},pi=t=>{let e=t.length-1,r=-1;for(;e>-1&&t.charAt(e)==="/";)r=e,e--;return r===-1?t:t.slice(0,r)},Hm=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},W0=(t,e)=>{let r=new Map(e.map(c=>[pi(c),!0])),i=t.filter,o=(c,l="")=>{let u=l||Qg(c).root||".",x;if(c===u)x=!1;else{let p=r.get(c);x=p!==void 0?p:o(Xg(c),u)}return r.set(c,x),x};t.filter=i?(c,l)=>i(c,l)&&o(pi(c)):c=>o(pi(c))},jm=t=>{let e=new bi(t),r=t.file,i;try{i=pr.openSync(r,"r");let o=pr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let l=Buffer.allocUnsafe(o.size),u=pr.readSync(i,l,0,o.size,0);e.end(u===l.byteLength?l:l.subarray(0,u))}else{let l=0,u=Buffer.allocUnsafe(c);for(;l<o.size;){let x=pr.readSync(i,u,0,c,l);if(x===0)break;l+=x,e.write(u.subarray(0,x))}e.end()}}finally{if(typeof i=="number")try{pr.closeSync(i)}catch{}}},Wm=(t,e)=>{let r=new bi(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("end",c),pr.stat(o,(u,x)=>{if(u)l(u);else{let p=new bc(o,{readSize:i,size:x.size});p.on("error",l),p.pipe(r)}})})},_r=vi(jm,Wm,t=>new bi(t),t=>new bi(t),(t,e)=>{e?.length&&W0(t,e),t.noResume||Hm(t)}),K0=(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:$m,parse:f0}=Km,Ic=t=>{let e="",r=f0(t);for(;$m(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=f0(t)}return[e,t]},$s=["|","<",">","?",":"],Tc=$s.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),Vm=new Map($s.map((t,e)=>[t,Tc[e]])),Jm=new Map(Tc.map((t,e)=>[t,$s[e]])),x0=t=>$s.reduce((e,r)=>e.split(r).join(Vm.get(r)),t),Zm=t=>Tc.reduce((e,r)=>e.split(r).join(Jm.get(r)),t),$0=(t,e)=>e?(t=Y(t).replace(/^\.(\/|$)/,""),pi(e)+"/"+t):Y(t),Ym=16*1024*1024,h0=Symbol("process"),p0=Symbol("file"),g0=Symbol("directory"),sc=Symbol("symlink"),m0=Symbol("hardlink"),ai=Symbol("header"),ks=Symbol("read"),oc=Symbol("lstat"),Os=Symbol("onlstat"),ac=Symbol("onread"),cc=Symbol("onreadlink"),dc=Symbol("openfile"),lc=Symbol("onopenfile"),hn=Symbol("close"),Gs=Symbol("mode"),uc=Symbol("awaitDrain"),Ka=Symbol("ondrain"),Rt=Symbol("prefix"),V0=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=vc(e);super(),this.path=Y(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||Ym,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=Y(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?Y(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,l]=Ic(this.path);c&&typeof l=="string"&&(this.path=l,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Zm(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=Y(r.absolute||u0.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[Os](o):this[oc]()}warn(t,e,r={}){return Ks(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[oc](){Dt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Os](e)})}[Os](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=ew(t),this.emit("stat",t),this[h0]()}[h0](){switch(this.type){case"File":return this[p0]();case"Directory":return this[g0]();case"SymbolicLink":return this[sc]();default:return this.end()}}[Gs](t){return K0(t,this.type==="Directory",this.portable)}[Rt](t){return $0(t,this.prefix)}[ai](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new Fn({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](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 Fs({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)}[g0](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[ai](),this.end()}[sc](){Dt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[cc](e)})}[cc](t){this.linkpath=Y(t),this[ai](),this.end()}[m0](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=Y(u0.relative(this.cwd,t)),this.stat.size=0,this[ai](),this.end()}[p0](){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[m0](e);this.linkCache.set(t,this.absolute)}if(this[ai](),this.stat.size===0)return this.end();this[dc]()}[dc](){Dt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[lc](e)})}[lc](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");Dt.read(t,e,r,i,o,(c,l)=>{if(c)return this[hn](()=>this.emit("error",c));this[ac](l)})}[hn](t=()=>{}){this.fd!==void 0&&Dt.close(this.fd,t)}[ac](t){if(t<=0&&this.remain>0){let r=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[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[Ka]():this[uc](()=>this[Ka]())}[uc](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)}[Ka](){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]()}},Xm=class extends V0{sync=!0;[oc](){this[Os](Dt.lstatSync(this.absolute))}[sc](){this[cc](Dt.readlinkSync(this.absolute))}[dc](){this[lc](Dt.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=Dt.readSync(e,r,i,o,c);this[ac](l),t=!1}finally{if(t)try{this[hn](()=>{})}catch{}}}[uc](t){t()}[hn](t=()=>{}){this.fd!==void 0&&Dt.closeSync(this.fd),t()}},Qm=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=vc(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=Y(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?Y(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[l,u]=Ic(this.path);l&&typeof u=="string"&&(this.path=u,o=l)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Fn({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 Fs({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 $0(t,this.prefix)}[Gs](t){return K0(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",tw=class gr{tail;head;length=0;static create(e=[]){return new gr(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++)rw(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 gr;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 gr;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 gr;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 gr;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=nw(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 nw(t,e,r){let i=e,o=e?e.next:t.head,c=new Cc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function rw(t,e){t.tail=new Cc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function iw(t,e){t.head=new Cc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Cc=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}},_0=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},y0=Buffer.alloc(1024),Ps=Symbol("onStat"),ci=Symbol("ended"),gt=Symbol("queue"),di=Symbol("queue"),ln=Symbol("current"),Nn=Symbol("process"),li=Symbol("processing"),Is=Symbol("processJob"),mt=Symbol("jobs"),$a=Symbol("jobDone"),Ls=Symbol("addFSEntry"),E0=Symbol("addTarEntry"),fc=Symbol("stat"),xc=Symbol("readdir"),Ns=Symbol("onreaddir"),Ms=Symbol("pipe"),b0=Symbol("entry"),Va=Symbol("entryOpt"),Bs=Symbol("writeEntryClass"),J0=Symbol("write"),Ja=Symbol("ondrain"),Vs=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;[gt];[di]=new Map;[mt]=0;[li]=!1;[ci]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=Y(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]=V0,typeof t.onwarn=="function"&&this.on("warn",t.onwarn),this.portable=!!t.portable,t.gzip||t.brotli||t.zstd){if((t.gzip?1:0)+(t.brotli?1:0)+(t.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(t.gzip&&(typeof t.gzip!="object"&&(t.gzip={}),this.portable&&(t.gzip.portable=!0),this.zip=new fm(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new hm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new gm(t.zstd)),!this.zip)throw new Error("impossible");let e=this.zip;e.on("data",r=>super.write(r)),e.on("end",()=>super.end()),e.on("drain",()=>this[Ja]()),this.on("resume",()=>e.resume())}else this.on("drain",this[Ja]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[gt]=new tw,this[mt]=0,this.jobs=Number(t.jobs)||4,this[li]=!1,this[ci]=!1}[J0](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&this.add(t),this[ci]=!0,this[Nn](),r&&r(),this}write(t){if(this[ci])throw new Error("write after end");return t instanceof j0?this[E0](t):this[Ls](t),this.flowing}[E0](t){let e=Y(w0.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new _0(t.path,e);r.entry=new Qm(t,this[Va](r)),r.entry.on("end",()=>this[$a](r)),this[mt]+=1,this[gt].push(r)}this[Nn]()}[Ls](t){let e=Y(w0.resolve(this.cwd,t));this[gt].push(new _0(t,e)),this[Nn]()}[fc](t){t.pending=!0,this[mt]+=1;let e=this.follow?"stat":"lstat";Us[e](t.absolute,(r,i)=>{t.pending=!1,this[mt]-=1,r?this.emit("error",r):this[Ps](t,i)})}[Ps](t,e){if(this.statCache.set(t.absolute,e),t.stat=e,!this.filter(t.path,e))t.ignore=!0;else if(e.isFile()&&e.nlink>1&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync)if(t===this[ln])this[Is](t);else{let r=`${e.dev}:${e.ino}`,i=this[di].get(r);i?i.push(t):this[di].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Nn]()}[xc](t){t.pending=!0,this[mt]+=1,Us.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[mt]-=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[li]){this[li]=!0;for(let t=this[gt].head;t&&this[mt]<this.jobs;t=t.next)if(this[Is](t.value),t.value.ignore){let e=t.next;this[gt].removeNode(t),t.next=e}this[li]=!1,this[ci]&&this[gt].length===0&&this[mt]===0&&(this.zip?this.zip.end(y0):(super.write(y0),super.end()))}}get[ln](){return this[gt]&&this[gt].head&&this[gt].head.value}[$a](t){this[gt].shift(),this[mt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[di].get(r);if(i){this[di].delete(r);for(let o of i)o.pending=!1,this[Is](o)}}this[Nn]()}[Is](t){if(t.pending&&t.pendingLink&&t===this[ln]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[ln]&&!t.piped&&this[Ms](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Ps](t,e):this[fc](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[xc](t),!t.readdir)return}if(t.entry=this[b0](t),!t.entry){t.ignore=!0;return}t===this[ln]&&!t.piped&&this[Ms](t)}}}[Va](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}}[b0](t){this[mt]+=1;try{return new this[Bs](t.path,this[Va](t)).on("end",()=>this[$a](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[Ja](){this[ln]&&this[ln].entry&&this[ln].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)}},Dc=class extends Vs{sync=!0;constructor(t){super(t),this[Bs]=Xm}pause(){}resume(){}[fc](t){let e=this.follow?"statSync":"lstatSync";this[Ps](t,Us[e](t.absolute))}[xc](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[J0](i)})}},sw=(t,e)=>{let r=new Dc(t),i=new M0(t.file,{mode:t.mode||438});r.pipe(i),Z0(r,e)},ow=(t,e)=>{let r=new Vs(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 Y0(r,e).catch(c=>r.emit("error",c)),o},Z0=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?_r({file:B0.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},Y0=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await _r({file:B0.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},aw=(t,e)=>{let r=new Dc(t);return Z0(r,e),r},cw=(t,e)=>{let r=new Vs(t);return Y0(r,e).catch(i=>r.emit("error",i)),r},m2=vi(sw,ow,aw,cw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),lw=process.env.__FAKE_PLATFORM__||process.platform,tu=lw==="win32",{O_CREAT:nu,O_NOFOLLOW:v0,O_TRUNC:ru,O_WRONLY:iu}=eu.constants,su=Number(process.env.__FAKE_FS_O_FILENAME__)||eu.constants.UV_FS_O_FILEMAP||0,uw=tu&&!!su,fw=512*1024,xw=su|ru|nu|iu,S0=!tu&&typeof v0=="number"?v0|ru|nu|iu:null,ou=S0!==null?()=>S0:uw?t=>t<fw?xw:"w":()=>"w",hc=(t,e,r)=>{try{return Js.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},qs=(t,e,r,i)=>{Js.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},hw=(t,e,r,i,o)=>{if(e.isDirectory())au(gi.resolve(t,e.name),r,i,c=>{if(c)return o(c);let l=gi.resolve(t,e.name);qs(l,r,i,o)});else{let c=gi.resolve(t,e.name);qs(c,r,i,o)}},au=(t,e,r,i)=>{Js.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,x=p=>{if(!u){if(p)return i(u=p);if(--l===0)return qs(t,e,r,i)}};for(let p of c)hw(t,p,e,r,x)})},pw=(t,e,r,i)=>{e.isDirectory()&&cu(gi.resolve(t,e.name),r,i),hc(gi.resolve(t,e.name),r,i)},cu=(t,e,r)=>{let i;try{i=Js.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return hc(t,e,r);throw c}for(let o of i)pw(t,o,e,r);return hc(t,e,r)},du=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"}},Zs=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"}},mw=(t,e)=>{it.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new du(t,r?.code||"ENOTDIR")),e(r)})},ww=(t,e,r)=>{t=Y(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,l=e.uid,u=e.gid,x=typeof l=="number"&&typeof u=="number"&&(l!==e.processUid||u!==e.processGid),p=e.preserve,w=e.unlink,_=Y(e.cwd),I=(v,A)=>{v?r(v):A&&x?au(A,l,u,S=>I(S)):c?it.chmod(t,o,r):r()};if(t===_)return mw(t,I);if(p)return gw.mkdir(t,{mode:o,recursive:!0}).then(v=>I(null,v??void 0),I);let E=Y(Hs.relative(_,t)).split("/");pc(_,E,o,w,_,void 0,I)},pc=(t,e,r,i,o,c,l)=>{if(e.length===0)return l(null,c);let u=e.shift(),x=Y(Hs.resolve(t+"/"+u));it.mkdir(x,r,lu(x,e,r,i,o,c,l))},lu=(t,e,r,i,o,c,l)=>u=>{u?it.lstat(t,(x,p)=>{if(x)x.path=x.path&&Y(x.path),l(x);else if(p.isDirectory())pc(t,e,r,i,o,c,l);else if(i)it.unlink(t,w=>{if(w)return l(w);it.mkdir(t,r,lu(t,e,r,i,o,c,l))});else{if(p.isSymbolicLink())return l(new Zs(t,t+"/"+e.join("/")));l(u)}}):(c=c||t,pc(t,e,r,i,o,c,l))},_w=t=>{let e=!1,r;try{e=it.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new du(t,r??"ENOTDIR")}},yw=(t,e)=>{t=Y(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,l=e.gid,u=typeof c=="number"&&typeof l=="number"&&(c!==e.processUid||l!==e.processGid),x=e.preserve,p=e.unlink,w=Y(e.cwd),_=v=>{v&&u&&cu(v,c,l),o&&it.chmodSync(t,i)};if(t===w)return _w(w),_();if(x)return _(it.mkdirSync(t,{mode:i,recursive:!0})??void 0);let I=Y(Hs.relative(w,t)).split("/"),E;for(let v=I.shift(),A=w;v&&(A+="/"+v);v=I.shift()){A=Y(Hs.resolve(A));try{it.mkdirSync(A,i),E=E||A}catch{let S=it.lstatSync(A);if(S.isDirectory())continue;if(p){it.unlinkSync(A),it.mkdirSync(A,i),E=E||A;continue}else if(S.isSymbolicLink())return new Zs(A,A+"/"+I.join("/"))}}return _(E)},Za=Object.create(null),A0=1e4,lr=new Set,Ew=t=>{lr.has(t)?lr.delete(t):Za[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),lr.add(t);let e=Za[t],r=lr.size-A0;if(r>A0/10){for(let i of lr)if(lr.delete(i),delete Za[i],--r<=0)break}return e},bw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,vw=bw==="win32",Sw=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=uu(i,r)),e.push(r||"/"),e},[]),Aw=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=vw?["win32 parallelization disabled"]:t.map(i=>pi(uu(Ew(i))));let r=new Set(t.map(i=>Sw(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let l=this.#e.get(c);if(!l||l?.[0]!==t)continue;let u=l[1];if(!u){this.#e.delete(c);continue}if(l.shift(),typeof u=="function")o.add(u);else for(let x of u)o.add(x)}for(let c of i){let l=this.#e.get(c),u=l?.[0];if(!(!l||!(u instanceof Set)))if(u.size===1&&l.length===1){this.#e.delete(c);continue}else if(u.size===1){l.shift();let x=l[0];typeof x=="function"&&o.add(x)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},Iw=()=>process.umask(),I0=Symbol("onEntry"),gc=Symbol("checkFs"),T0=Symbol("checkFs2"),mc=Symbol("isReusable"),ct=Symbol("makeFs"),wc=Symbol("file"),_c=Symbol("directory"),zs=Symbol("link"),C0=Symbol("symlink"),D0=Symbol("hardlink"),xi=Symbol("ensureNoSymlink"),R0=Symbol("unsupported"),k0=Symbol("checkPath"),Ya=Symbol("stripAbsolutePath"),pn=Symbol("mkdir"),Ue=Symbol("onError"),Ts=Symbol("pending"),O0=Symbol("pend"),ur=Symbol("unpend"),Xa=Symbol("ended"),Qa=Symbol("maybeClose"),yc=Symbol("skip"),mi=Symbol("doChown"),wi=Symbol("uid"),_i=Symbol("gid"),yi=Symbol("checkedCwd"),Tw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ei=Tw==="win32",Cw=1024,Dw=(t,e)=>{if(!Ei)return re.unlink(t,e);let r=t+".DELETE."+Q0(16).toString("hex");re.rename(t,r,i=>{if(i)return e(i);re.unlink(r,e)})},Rw=t=>{if(!Ei)return re.unlinkSync(t);let e=t+".DELETE."+Q0(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},P0=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Rc=class extends bi{[Xa]=!1;[yi]=!1;[Ts]=0;reservations=new Aw;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(t={}){if(t.ondone=()=>{this[Xa]=!0,this[Qa]()},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:Cw,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Ei,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=Y(Le.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:Iw():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[I0](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[Qa](){this[Xa]&&this[Ts]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[Ya](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Ic(r),l=c.replaceAll(/\\/g,"/").split("/");if(l.includes("..")||Ei&&/^[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=Le.posix.dirname(t.path),x=Le.posix.normalize(Le.posix.join(u,l.join("/")));if(x.startsWith("../")||x==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:r}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:r})),!0}[k0](t){let e=Y(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=Y(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[Ya](t,"path")||!this[Ya](t,"linkpath"))return!1;if(t.absolute=Le.isAbsolute(t.path)?Y(Le.resolve(t.path)):Y(Le.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:Y(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=Le.win32.parse(String(t.absolute));t.absolute=i+x0(String(t.absolute).slice(i.length));let{root:o}=Le.win32.parse(t.path);t.path=o+x0(t.path.slice(o.length))}return!0}[I0](t){if(!this[k0](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[gc](t);default:return this[R0](t)}}[Ue](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[ur](),e.resume())}[pn](t,e,r){ww(Y(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},r)}[mi](t){return this.forceChown||this.preserveOwner&&(typeof t.uid=="number"&&t.uid!==this.processUid||typeof t.gid=="number"&&t.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[wi](t){return P0(this.uid,t.uid,this.processUid)}[_i](t){return P0(this.gid,t.gid,this.processGid)}[wc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new js(String(t.absolute),{flags:ou(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[Ue](u,t),e()});let o=1,c=u=>{if(u){i.fd&&re.close(i.fd,()=>{}),this[Ue](u,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,x=>{x?this[Ue](x,t):this[ur](),e()})};i.on("finish",()=>{let u=String(t.absolute),x=i.fd;if(typeof x=="number"&&t.mtime&&!this.noMtime){o++;let p=t.atime||new Date,w=t.mtime;re.futimes(x,p,w,_=>_?re.utimes(u,p,w,I=>c(I&&_)):c())}if(typeof x=="number"&&this[mi](t)){o++;let p=this[wi](t),w=this[_i](t);typeof p=="number"&&typeof w=="number"&&re.fchown(x,p,w,_=>_?re.chown(u,p,w,I=>c(I&&_)):c())}c()});let l=this.transform&&this.transform(t)||t;l!==t&&(l.on("error",u=>{this[Ue](u,t),e()}),t.pipe(l)),l.pipe(i)}[_c](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[pn](String(t.absolute),r,i=>{if(i){this[Ue](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[ur](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[mi](t)&&(o++,re.chown(String(t.absolute),Number(this[wi](t)),Number(this[_i](t)),c)),c()})}[R0](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[C0](t,e){let r=Y(Le.relative(this.cwd,Le.resolve(Le.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[xi](t,this.cwd,r,()=>this[zs](t,String(t.linkpath),"symlink",e),i=>{this[Ue](i,t),e()})}[D0](t,e){let r=Y(Le.resolve(this.cwd,String(t.linkpath))),i=Y(String(t.linkpath)).split("/");this[xi](t,this.cwd,i,()=>this[zs](t,r,"link",e),o=>{this[Ue](o,t),e()})}[xi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let l=Le.resolve(e,c);re.lstat(l,(u,x)=>{if(u)return i();if(x?.isSymbolicLink())return o(new Zs(l,Le.resolve(l,r.join("/"))));this[xi](t,l,r,i,o)})}[O0](){this[Ts]++}[ur](){this[Ts]--,this[Qa]()}[yc](t){this[ur](),t.resume()}[mc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Ei}[gc](t){this[O0]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[T0](t,r))}[T0](t,e){let r=l=>{e(l)},i=()=>{this[pn](this.cwd,this.dmode,l=>{if(l){this[Ue](l,t),r();return}this[yi]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let l=Y(Le.dirname(String(t.absolute)));if(l!==this.cwd)return this[pn](l,this.dmode,u=>{if(u){this[Ue](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[yc](t),r();return}if(l||this[mc](t,u))return this[ct](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let x=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,p=w=>this[ct](w??null,t,r);return x?re.chmod(String(t.absolute),Number(t.mode),p):p()}if(t.absolute!==this.cwd)return re.rmdir(String(t.absolute),x=>this[ct](x??null,t,r))}if(t.absolute===this.cwd)return this[ct](null,t,r);Dw(String(t.absolute),x=>this[ct](x??null,t,r))})};this[yi]?o():i()}[ct](t,e,r){if(t){this[Ue](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[wc](e,r);case"Link":return this[D0](e,r);case"SymbolicLink":return this[C0](e,r);case"Directory":case"GNUDumpDir":return this[_c](e,r)}}[zs](t,e,r,i){re[r](e,String(t.absolute),o=>{o?this[Ue](o,t):(this[ur](),t.resume()),i()})}},ui=t=>{try{return[null,t()]}catch(e){return[e,null]}},fu=class extends Rc{sync=!0;[ct](t,e){return super[ct](t,e,()=>{})}[gc](t){if(!this[yi]){let o=this[pn](this.cwd,this.dmode);if(o)return this[Ue](o,t);this[yi]=!0}if(t.absolute!==this.cwd){let o=Y(Le.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[pn](o,this.dmode);if(c)return this[Ue](c,t)}}let[e,r]=ui(()=>re.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[yc](t);if(e||this[mc](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?ui(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ct](l,t)}let[o]=ui(()=>re.rmdirSync(String(t.absolute)));this[ct](o,t)}let[i]=t.absolute===this.cwd?[]:ui(()=>Rw(String(t.absolute)));this[ct](i,t)}[wc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=l=>{let u;try{re.closeSync(o)}catch(x){u=x}(l||u)&&this[Ue](l||u,t),e()},o;try{o=re.openSync(String(t.absolute),ou(t.size),r)}catch(l){return i(l)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",l=>this[Ue](l,t)),t.pipe(c)),c.on("data",l=>{try{re.writeSync(o,l,0,l.length)}catch(u){i(u)}}),c.on("end",()=>{let l=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,x=t.mtime;try{re.futimesSync(o,u,x)}catch(p){try{re.utimesSync(String(t.absolute),u,x)}catch{l=p}}}if(this[mi](t)){let u=this[wi](t),x=this[_i](t);try{re.fchownSync(o,Number(u),Number(x))}catch(p){try{re.chownSync(String(t.absolute),Number(u),Number(x))}catch{l=l||p}}}i(l)})}[_c](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[pn](String(t.absolute),r);if(i){this[Ue](i,t),e();return}if(t.mtime&&!this.noMtime)try{re.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[mi](t))try{re.chownSync(String(t.absolute),Number(this[wi](t)),Number(this[_i](t)))}catch{}e(),t.resume()}[pn](t,e){try{return yw(Y(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}}[xi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let l of r){c=Le.resolve(c,l);let[u,x]=ui(()=>re.lstatSync(c));if(u)return i();if(x.isSymbolicLink())return o(new Zs(c,Le.resolve(e,r.join("/"))))}i()}[zs](t,e,r,i){let o=`${r}Sync`;try{re[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[Ue](c,t)}}},kw=t=>{let e=new fu(t),r=t.file,i=X0.statSync(r),o=t.maxReadSize||16*1024*1024;new Yg(r,{readSize:o,size:i.size}).pipe(e)},Ow=(t,e)=>{let r=new Rc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("close",c),X0.stat(o,(u,x)=>{if(u)l(u);else{let p=new bc(o,{readSize:i,size:x.size});p.on("error",l),p.pipe(r)}})})},xu=vi(kw,Ow,t=>new fu(t),t=>new Rc(t),(t,e)=>{e?.length&&W0(t,e)}),Pw=(t,e)=>{let r=new Dc(t),i=!0,o,c;try{try{o=rt.openSync(t.file,"r+")}catch(x){if(x?.code==="ENOENT")o=rt.openSync(t.file,"w+");else throw x}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 x=new Fn(u);if(!x.cksumValid)break;let p=512*Math.ceil((x.size||0)/512);if(c+p+512>l.size)break;c+=p,t.mtimeCache&&x.mtime&&t.mtimeCache.set(String(x.path),x.mtime)}i=!1,Lw(t,r,c,o,e)}finally{if(i)try{rt.closeSync(o)}catch{}}},Lw=(t,e,r,i,o)=>{let c=new M0(t.file,{fd:i,start:r});e.pipe(c),Mw(e,o)},Nw=(t,e)=>{e=Array.from(e);let r=new Vs(t),i=(o,c,l)=>{let u=(I,E)=>{I?rt.close(o,v=>l(I)):l(null,E)},x=0;if(c===0)return u(null,0);let p=0,w=Buffer.alloc(512),_=(I,E)=>{if(I||E===void 0)return u(I);if(p+=E,p<512&&E)return rt.read(o,w,p,w.length-p,x+p,_);if(x===0&&w[0]===31&&w[1]===139)return u(new Error("cannot append to compressed archives"));if(p<512)return u(null,x);let v=new Fn(w);if(!v.cksumValid)return u(null,x);let A=512*Math.ceil((v.size??0)/512);if(x+A+512>c||(x+=A+512,x>=c))return u(null,x);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),p=0,rt.read(o,w,0,512,x,_)};rt.read(o,w,0,512,x,_)};return new Promise((o,c)=>{r.on("error",c);let l="r+",u=(x,p)=>{if(x&&x.code==="ENOENT"&&l==="r+")return l="w+",rt.open(t.file,l,u);if(x||!p)return c(x);rt.fstat(p,(w,_)=>{if(w)return rt.close(p,()=>c(w));i(p,_.size,(I,E)=>{if(I)return c(I);let v=new js(t.file,{fd:p,start:E});r.pipe(v),v.on("error",c),v.on("close",o),Bw(r,e)})})};rt.open(t.file,l,u)})},Mw=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?_r({file:hu.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},Bw=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await _r({file:hu.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},fi=vi(Pw,Nw,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!sm(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")}),O2=vi(fi.syncFile,fi.asyncFile,fi.syncNoFile,fi.asyncNoFile,(t,e=[])=>{fi.validate?.(t,e),zw(t)}),zw=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(r,i)=>e(r,i)&&!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0)):(r,i)=>!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0))};rn();var yt={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",DELETE:"_agent/delete"};function Si(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function pu(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function kc(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function gu(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function yr(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Ke();ne();Oe();Ke();function Kt(t,e){if(Si(t)!=="cloud")throw new T("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Ys(t){return t.startsWith("http://")||t.startsWith("https://")}function Xs(t){return t.endsWith("/")?t.slice(0,-1):t}Ke();ne();var Qs="1008033",mu="1289";var wu="pbbp2",_u="https://www.coze.cn",yu="/api/coze_claw/resource/get_frontier_key",Uw="https://www.coze.cn",Gw="wss://frontier.coze.cn";function eo(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??Uw}function Eu(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??Gw}function Er(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 Ii(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Ai=G("handshake");async function Oc(t){let e=eo(t.endpoint),r=t.timeoutMs??1e4,i=`${Xs(e)}${yu}?aid=${encodeURIComponent(Qs)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...Er(t.ppeOverride)},c=new AbortController,l=setTimeout(()=>c.abort(),r);Ai.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),x=u.headers.get("x-tt-logid")??"",p=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let v=await u.text().catch(()=>"");throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${x}: ${v.slice(0,200)}`)}let w=await u.json();if(w.code!==void 0&&w.code!==0)throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${w.code} msg=${w.msg??"-"} logid=${x}`);let _=w.data??{},I=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(!I||!E){let v=JSON.stringify(w).slice(0,500);throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${x}: ${v}`)}return Ai.info("handshake ok",{remoteDeviceId:E,logid:x,traceId:p}),{accessKey:I,deviceId:E}}catch(u){if(u instanceof T)throw Ai.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Ai.warn("handshake timeout",{base:e,timeoutMs:r}),new T("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let x=u.cause;throw Ai.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:x?.code,syscall:x?.syscall,cause:String(u).slice(0,300)}),new T("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(l)}}var Pc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",Et="auto",bu=2e5;function vu(t){return{model:Lc(t.model)??Et,...t.modelToken?{modelToken:t.modelToken}:{}}}function Su(t){return!t||t===Et}var qw=new Set(["auto","\u81EA\u52A8"]);function Lc(t){let e=t?.trim();if(e)return qw.has(e.toLowerCase())?Et:e}function Au(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Pc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||Et;e.ANTHROPIC_MODEL=r,e.ANTHROPIC_SMALL_FAST_MODEL=r,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=r,e.ANTHROPIC_DEFAULT_OPUS_MODEL=r,e.ANTHROPIC_DEFAULT_SONNET_MODEL=r,e.CLAUDE_CODE_SUBAGENT_MODEL=r,t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else Su(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Iu(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||Et}"`):Su(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="${Pc}/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??bu;e.push("-c",`model_context_window=${r}`)}return e}function Tu(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function Nc(t,e){let{ttEnv:r,usePpe:i}=Ii(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Cu(t,e,r){if(!t.modelToken)return{};let i=Nc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,l])=>`${c}:${l}`).join(`
92
- `)}}function Mc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function Du(t,e,r){if(!t.modelToken)return null;let i=t.model||Et,o=Nc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let l={baseUrl:`${Pc}/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??bu,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(l.headers=o),l}function Ru(t,e,r){if(!t.modelToken)return[];let i=Nc(e,r),o=[];for(let[c,l]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${l}"`);return o}var Ne=G("agent-handlers"),ku=5*1024*1024,Vw=1,Jw=6,Zw=new Set(["node_modules",".git",".coze","dist","build",".next"]),to=class{constructor(e){this.opts=e}opts;async listSkills(e){Kt(e._meta,"_agent/listSkills");let r=yr(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??$e(r).workspace,c=i?.skills??[],l=[];for(let u of c){let x=Ot(o,u.relPath,"SKILL.md");await Ww(x).then(w=>w.isFile()).catch(()=>!1)&&l.push(t_(u))}return{skills:l}}async addSkills(e){Kt(e._meta,"_agent/addSkills");let r=yr(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],l=new Map(c.map((x,p)=>[x.skillId,p])),u=[];for(let x of o){let p=await Hc({agentId:r,workspace:i.workspace,framework:i.framework,skill:x});jc(c,l,p),u.push(x)}return await os(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){Kt(e._meta,"_agent/removeSkills");let r=yr(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],l=[];for(let u of c){if(!o.has(u.skillId)){l.push(u);continue}let x=Ot(i.workspace,u.relPath);await jw(x,{recursive:!0,force:!0}),Ne.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,Ne.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l});continue}let x=c.downstream;c.downstream=void 0,Ne.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l}),x.stop(r).catch(p=>Ne.warn("downstream stop failed during reload (ignored)",{reason:r,agentId:e,cloudId:o,err:String(p)}))}}isRuntimePendingPermission(e){let r=this.opts.isRuntimePendingPermission;return!r||!e.downstream?!1:r(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return Ne.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await He(r);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Ne.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await rr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Ne.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new T("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Ye(i),Ne.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new T("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await He(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Ye(i),Ne.info("agent disconnected",{agentId:r,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(r,e.reason??"disconnect"),{ok:!0}):(Ne.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(Kt(e._meta,"_agent/switchModel"),!e.agentId)throw new T("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Lc(e.model)??Et,i=await He(e.agentId);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Ye(i),Ne.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Ne.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};o.model=r,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o).catch(l=>Ne.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(l)}));let c=[];for(let[l,u]of o.allSessionQueues())c.push(u.enqueue(async()=>{let x=o.sessions.get(l);x?.downstream&&(await x.downstream.stop(`switchModel: ${r}`).catch(()=>{}),x.downstream=void 0)}));return await Promise.all(c),Ne.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:r,cloudSessions:c.length}),{ok:!0}}async resetAgent(e){if(Kt(e._meta,yt.RESET),!e.agentId)throw new T("IPC_BAD_REQUEST",`${yt.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,yt.RESET),await this.runDetailSync(e.agentId,yt.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),Ne.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(r);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,l]of i.sessions)o.set(c,{modelToken:l.modelToken,tokenGeneratedAt:l.tokenGeneratedAt});await Yr(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,yt.REPAIR),!e.agentId)throw new T("IPC_BAD_REQUEST",`${yt.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new T("IPC_BAD_REQUEST",`${yt.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){Ne.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,yt.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){Ne.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Ne.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){Kt(e._meta,"_agent/getFileTree");let r=e._meta,i=yr(r),o=await this.resolveWorkspace(i),c=e.filePath??"",l=this.safeJoin(o,c),u=await Bc(l).catch(()=>null);if(!u)throw new T("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await Zr(l,o))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let x=f_(e.depth);return u.isDirectory()?{tree:await u_(o,l,c,x)}:{tree:[{name:x_(c),path:zu(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){Kt(e._meta,"_agent/getFileContent");let r=yr(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new T("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await Bc(o).catch(()=>null);if(!c||!c.isFile())throw new T("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await Zr(o,i))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>ku)throw new T("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${ku})`);let l=await Ou(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??$e(e).workspace}safeJoin(e,r){let i=Uc(e,r||"."),o=qc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Pu}`))throw new T("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 T("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function Yw(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new T("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new T("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function Xw(t){return t==="claude-code"?Ot(".claude","skills"):Ot(".agents","skills")}var Qw=3e4,e_=50*1024*1024,br=3e4;async function Hc(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new T("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,l=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!l)throw new T("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=Yw(o.skillName),x=Xw(i),p=Ot(x,u),w=Ot(r,p);if(await zc(w,{recursive:!0}),c){let I=Buffer.from(o.content,"utf8");Ti(I.length),await Fc(Ot(w,"SKILL.md"),I,"utf8")}else{let I=await n_(o.downloadUrl);i_(I)?await c_(I,w):s_(I)?await o_(I,w):await Fc(Ot(w,"SKILL.md"),I.toString("utf8"),"utf8")}let _={skillId:o.skillId,skillName:o.skillName,relPath:p,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return Ne.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:p,source:c?"content":"downloadUrl"}),_}function jc(t,e,r){let i=e.get(r.skillId);if(i!==void 0){t[i]=r;return}e.set(r.skillId,t.length),t.push(r)}function t_(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 n_(t){if(!t)throw new T("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Ti(e);let r=r_(t);return Ti(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await Ou(e);return Ti(r.length),r}if(Ys(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),Qw);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new T("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Ti(o.byteLength),Buffer.from(o)}finally{clearTimeout(r)}}throw new T("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Ti(t){if(t>e_)throw new T("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function r_(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new T("IPC_BAD_REQUEST","bad data URL");let r=!!e[2],i=e[3]??"";return r?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function i_(t){return t.length>=2&&t[0]===31&&t[1]===139}function s_(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 Gc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function o_(t,e){let r,i;try{r=new Mu.default(t),i=r.getEntries()}catch(l){throw new T("IPC_BAD_REQUEST",`zip parse failed: ${l.message}`,{cause:l})}for(let l of i){let u=l.entryName;if(!u||Gc(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new T("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(p=>p===".."))throw new T("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let x=l.header.attr>>>16&61440;if(x!==0&&x!==32768&&x!==16384)throw new T("IPC_BAD_REQUEST",`zip entry kind 0x${x.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=a_(i),c=Uc(e);for(let l of i){if(Gc(l.entryName))continue;let u=l.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let x=Uc(e,u),p=qc(c,x);if(p.startsWith("..")||p==="..")throw new T("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(l.isDirectory){await zc(x,{recursive:!0});continue}await zc(Kw(x),{recursive:!0});let w;try{w=l.getData()}catch(_){throw new T("IPC_BAD_REQUEST",`zip entry getData failed (${l.entryName}): ${_.message}`,{cause:_})}await Fc(x,w)}}function a_(t){let e;for(let r of t){let i=r.entryName;if(!i||Gc(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 c_(t,e){await d_(t);let r=xu({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar extract timeout (${br}ms)`))},br);try{await Nu(Lu.from(t),r)}catch(c){throw c instanceof T?c:i?new T("IPC_BAD_REQUEST",`tar extract timeout (${br}ms)`):new T("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function d_(t){let e=[],r=_r({onReadEntry:c=>{let l=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' not allowed (symlink/hardlink/special): ${l.slice(0,100)}`);return}if(l.startsWith("/")||l.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(l)){e.push(`tar entry absolute path: ${l}`);return}l.split(/[/\\]/).some(p=>p==="..")&&e.push(`tar entry contains '..': ${l}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar list timeout (${br}ms)`))},br);try{await Nu(Lu.from(t),r)}catch(c){throw i?new T("IPC_BAD_REQUEST",`tar list timeout (${br}ms)`):new T("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new T("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var l_=5e3;async function u_(t,e,r,i){return Bu(t,e,r,i,{count:0})}async function Bu(t,e,r,i,o){if(i<=0)return[];let c;try{c=await Hw(e,{withFileTypes:!0})}catch{return[]}let l=[];for(let u of c){if(Zw.has(u.name)||u.isSymbolicLink())continue;if(o.count>=l_){l.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let x=Ot(e,u.name),p=$w(Ot(r,u.name)),w=null;try{w=await Bc(x)}catch{continue}if(w.isSymbolicLink())continue;o.count++;let _={name:u.name,path:zu(qc(t,x)),isDir:w.isDirectory(),size:w.size,modifiedAt:Math.floor(w.mtimeMs)};w.isDirectory()&&i>1&&(_.children=await Bu(t,x,p,i-1,o)),l.push(_)}return l.sort((u,x)=>u.isDir!==x.isDir?u.isDir?-1:1:u.name.localeCompare(x.name)),l}function f_(t){return!t||t<=0?Vw:Math.min(t,Jw)}function x_(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function zu(t){return t.split(Pu).join("/")}ne();import{readFileSync as qA}from"node:fs";import{dirname as jA,join as WA}from"node:path";import{fileURLToPath as $A}from"node:url";var vr="0.1.98-alpha.0";var wn=G("agent-health-reporter"),h_=1e4,Ci=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??h_}opts;timer=null;inFlight=!1;unsubscribeRegister=null;intervalMs;start(){this.timer||(this.timer=setInterval(()=>{this.tick()},this.intervalMs),this.timer.unref?.(),this.unsubscribeRegister=this.opts.core.onAgentRegister(()=>{this.tick()}),wn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),wn.info("heartbeat stopped"))}async tick(){if(this.inFlight){wn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){wn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let r=[];for(let l of this.opts.core.agents.values()){let u=p_(l);if(!u)continue;let x={agentId:l.agentId,status:u};l.patToken&&(x.patToken=l.patToken),l.accountId&&(x.accountId=l.accountId),r.push(x)}if(r.length===0)return;let i={agents:r,bridgeVersion:vr,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(l){wn.warn("heartbeat batch send failed",{count:r.length,err:String(l)})}let c=o?.authFailures;if(c&&c.length>0&&(wn.warn("heartbeat received authFailures from cloud",{count:c.length,agentIds:c.map(l=>l.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(c)}catch(l){wn.warn("onAuthFailures callback failed (ignored)",{err:String(l)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){wn.warn("onTickEnd hook failed",{err:String(r)})}}};function p_(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}rn();import{chmod as cy,mkdir as uo,rm as dy,stat as ly,writeFile as uy}from"node:fs/promises";import{homedir as fy}from"node:os";import{join as Vc}from"node:path";nn();import{spawnSync as O_}from"node:child_process";import{existsSync as P_}from"node:fs";import{release as L_}from"node:os";import{basename as N_,isAbsolute as M_}from"node:path";function Di(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Sr(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}}Ke();var no=class extends Error{code;data;constructor(e){super(`JSON-RPC error code=${e.code} ${e.message}`),this.name="RemoteRpcError",this.code=e.code,e.data!==void 0&&(this.data=e.data)}},ee={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021};function Fu(t){return"method"in t&&"id"in t&&t.id!==void 0}function Uu(t){return"method"in t&&!("id"in t)}function ro(t){return!("method"in t)&&"id"in t}var g_={AGENT_NOT_FOUND:ee.AGENT_NOT_FOUND,AGENT_BUSY:ee.AGENT_BUSY,AGENT_DISCONNECTED:ee.AGENT_DISCONNECTED,AGENT_TIMEOUT:ee.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:ee.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:ee.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:ee.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:ee.INTERNAL_ERROR,BRIDGE_INTERNAL:ee.INTERNAL_ERROR,IPC_AUTH_FAILED:ee.INTERNAL_ERROR,IPC_BAD_REQUEST:ee.INVALID_REQUEST,MODEL_TOKEN_GEN_FAILED:ee.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:ee.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:ee.OPERATION_NOT_ALLOWED_FOR_LOCAL,UPSTREAM_DISCONNECTED:ee.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:ee.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:ee.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:ee.FILE_TOO_LARGE,UNSUPPORTED_MIME:ee.UNSUPPORTED_MIME,UPLOAD_FAILED:ee.UPLOAD_FAILED,UPSTREAM_NOT_READY:ee.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:ee.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:ee.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:ee.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:ee.AGENT_ENV_NOT_READY};function m_(t){if(t!=null)return t instanceof Error?{name:t.name,message:Ri(t.message)}:typeof t=="string"?Ri(t):typeof t=="object"?__(t):t}var w_=[[/\/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 Ri(t){let e=t;for(let[r,i]of w_)e=e.replace(r,i);return e}function __(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Ri(i):e[r]=i;return e}function ki(t){if(t instanceof T){let e=m_(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:g_[t.code]??ee.INTERNAL_ERROR,message:Ri(t.message),data:r}}return{code:ee.INTERNAL_ERROR,message:Ri(t instanceof Error?t.message:String(t))}}function Gu(t){let e=t.data,r=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:l,...u}=e;c=u}return new T(r,o,{retriable:e?.retriable??!1,cause:c})}function Hu(t){return`${JSON.stringify(t)}
93
- `}var qu=10*1024*1024,io=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>qu){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${qu} 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 Wu={"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"},iI=Object.fromEntries(Object.entries(Wu).map(([t,e])=>[e,t])),y_={"session.prompt":["agentId","triggerMsgId","sessionId"],"session.cancel":["agentId","triggerMsgId","sessionId"],"session.new":["agentId"],"session.load":["agentId"],"agent.create":["agentId"],"agent.health":[],"agent.listSkills":["agentId"],"agent.addSkills":["agentId"],"agent.removeSkills":["agentId"],"agent.getFileTree":["agentId"],"agent.getFileContent":["agentId"],"agent.detail":["agentId"],"agent.update":["agentId"],"agent.disconnect":["agentId"],"agent.switchModel":["agentId"],"agent.genModelToken":["agentId","sessionId"],"agent.reset":["agentId"],"agent.repair":["agentId"],"session.requestPermission":["agentId","sessionId"],"agent.pair":[],initialize:[]},Ir=class{seq=0;next(e,r){this.seq+=1;let i=Wu[e]??E_(e),o=y_[i]??[],c=[i,String(this.seq)];if(o.length>0){let l=o.map(x=>ju(r?.[x]??"")),u=b_(l).join(":");u&&c.push(u)}else r&&Object.values(r).some(l=>l)&&c.push(Object.values(r).filter(Boolean).map(l=>ju(String(l))).join(":"));return c.join("_")}reset(){this.seq=0}};function E_(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function ju(t){return t.replace(/[:_\s]+/g,"-")}function b_(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}Jr();import{readFileSync as v_}from"node:fs";var S_=384;async function Wc(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await nr(t.agentEnvFile,r,{mode:S_})}function Kc(t){try{let e=JSON.parse(v_(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function Ku(t,e,r={},i=o=>o){return{...i({...t,...Kc(e)}),...r}}yn();Xi();Ke();ne();Oe();var k_=[{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/i,message:"openclaw gateway \u672A\u8FD0\u884C (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2)\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 Zu(t,e){if(!e)return null;for(let r of k_)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}var B_=Ft("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),z_=200,F_=40,U_=Ft("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),G_=Ft("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),q_=Ft("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),Yu=500;function H_(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=Yu?t:`${e.slice(0,Yu)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Xu(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),O_("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}function Qu(t){try{return P_(t)}catch{return}}function j_(t,e){return{platform:process.platform,osRelease:L_(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:M_(e.command)?Qu(e.command):void 0,cwd:e.cwd,cwdExists:Qu(e.cwd),envKeys:e.envKeys}}function W_(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${N_(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Pt=class{constructor(e){this.opts=e;this.log=G(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new io({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Ir;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];sanitizeEnv(e){return e}async start(){if(this.child)throw new T("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=Ku(process.env,this.opts.agentEnvFile??X().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,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>z_&&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,(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=j_(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(r).length});this.log.error("child error",{err:String(o),diag:l}),this.failAllPending(new T("AGENT_SPAWN_FAILED",W_(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()));Xu(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Xu(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=U_,i=G_,o=q_){return this.call("session/prompt",e,r,i,o)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Sr("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=B_,o=0,c=0){if(!this.child||this.stopped)return Promise.reject(new T("AGENT_PROTOCOL_ERROR","downstream not started"));let l=this.idAllocator.next(e),u=Di(l,e,r),x=(()=>{if(typeof r!="object"||r===null)return;let _=r.sessionId;return typeof _=="string"?_:void 0})(),p=i>0&&Number.isFinite(i),w=o>0&&Number.isFinite(o);return new Promise((_,I)=>{let E={resolve:_,reject:I,timer:null,firstUpdateTimer:null,onFirstUpdate:null,method:e},v=Date.now();if(p){let S=()=>{E.timer=setTimeout(()=>{let C=Date.now()-v;if(this.inflightAgentRequests.size>0&&C<c){this.log.debug("hard cap fired but agent request inflight, extending to approval cap",{id:l,method:e,elapsed:C,approvalMaxMs:c,...x?{sessionId:x}:{}}),S();return}this.pending.delete(l),E.firstUpdateTimer&&clearTimeout(E.firstUpdateTimer);let P=this.inflightAgentRequests.size>0;this.log.warn("downstream call timeout",{id:l,method:e,timeoutMs:i,approvalMaxMs:c,awaitingApproval:P,...x?{sessionId:x}:{}}),I(P?new T("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${c}ms`):new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i)};S()}let A=w?()=>{E.firstUpdateTimer&&clearTimeout(E.firstUpdateTimer),E.firstUpdateTimer=setTimeout(()=>{if(this.inflightAgentRequests.size>0){this.log.debug("first-update wait fired but agent request inflight, re-arming",{id:l,method:e,inflight:this.inflightAgentRequests.size,...x?{sessionId:x}:{}}),A?.();return}E.timer&&clearTimeout(E.timer),this.pending.delete(l),this.log.warn("first session/update timeout, rejecting pending call",{id:l,method:e,firstUpdateMs:o,...x?{sessionId:x}:{}}),I(new T("AGENT_FRAME_IDLE_TIMEOUT",`${e} no first session/update within ${o}ms`))},o)}:null;E.onFirstUpdate=w?()=>{E.firstUpdateTimer&&clearTimeout(E.firstUpdateTimer),E.firstUpdateTimer=null,E.onFirstUpdate=null}:null,this.pending.set(l,E),A?.();try{this.writeFrame(u)}catch(S){E.timer&&clearTimeout(E.timer),E.firstUpdateTimer&&clearTimeout(E.firstUpdateTimer),this.pending.delete(l),I(S)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new T("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(Hu(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(ro(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),r.firstUpdateTimer&&clearTimeout(r.firstUpdateTimer),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(Gu(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new T("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:H_(e.result)}),r.resolve(e.result));return}if(Uu(e)){if(e.method==="session/update"){for(let r of this.pending.values())r.onFirstUpdate?.();for(let r of this.updateHandlers)try{Promise.resolve(r(e.params)).catch(i=>this.log.warn("update handler failed (async)",{err:String(i)}))}catch(i){this.log.warn("update handler threw sync, swallowed",{err:String(i)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(Fu(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)})}}}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,ki(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}buildExitError(e,r){if(this.stopReason!==void 0)return new T("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(F_).join(`
95
- `),o=Zu(this.framework,i);return o?new T(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new T("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.firstUpdateTimer&&clearTimeout(r.firstUpdateTimer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function K_(t){let e={};for(let[r,i]of Object.entries(t))i!==void 0&&(r.startsWith("CLAUDE")||r==="AI_AGENT"||r==="BAGGAGE"||(e[r]=i));return e}var so=class extends Pt{framework="claude-code";constructor(e){let{command:r,args:i}=Vr("claude-code",e.command,e.args??[]),o={command:r,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o)}sanitizeEnv(e){return K_(e)}};nn();import{mkdirSync as $_,mkdtempSync as V_,rmSync as J_}from"node:fs";import{tmpdir as Z_}from"node:os";import{join as Y_}from"node:path";var oo=class extends Pt{framework="codex";authMethodId;codexHomeDir;cleanupCodexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=Vr("codex",e.command,i),l=e.isolateCodexHome?e.codexHomeDir??V_(Y_(Z_(),"coze-bridge-codex-home-")):void 0,u=!!l&&!e.codexHomeDir;l&&e.codexHomeDir&&$_(l,{recursive:!0});let x=l?{...e.env??{},CODEX_HOME:l}:e.env,p={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...x?{env:x}:{}};super(p),this.authMethodId=e.authMethodId,this.codexHomeDir=l,this.cleanupCodexHomeDir=u}async initialize(e){let r=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),r}async stop(e){if(await super.stop(e),this.codexHomeDir&&this.cleanupCodexHomeDir)try{J_(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};var X_=3e4,Tr=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.sessionPrompt({sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},X_))}get acpSessionName(){return this.sessionName}};Ke();ne();Oe();function $c(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 ao=class{agentId;framework;workspace;deployType;accountId;patToken;modelInfo;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;activeGroupIds=new Map;status="ok";model;lastActiveAt=Date.now();constructor(e){this.agentId=e.agentId,this.framework=e.framework,this.workspace=e.workspace,this.model=e.model,this.deployType=e.deployType??"local",e.accountId&&(this.accountId=e.accountId),e.patToken&&(this.patToken=e.patToken),e.modelInfo&&(this.modelInfo=e.modelInfo)}setPatToken(e){this.patToken=e}setModelInfo(e){this.modelInfo=e}getSessionQueue(e){let r=this.sessionQueues.get(e);return(!r||r.isDisposed)&&(r=new 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)Oi(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 Oi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}yn();ne();import{constants as ef}from"node:fs";import{access as Q_}from"node:fs/promises";import{delimiter as ey,join as ty}from"node:path";var bt=G("framework-detector"),tf={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},ny=[".exe",".cmd",".bat",".ps1"],Gn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??dt,access:e.access??Q_}}async detect(e){let r=tf[e],i=await this.which(r);if(!i)return bt.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,l]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return l&&(u.defaultAgent=l),u}async detectAll(){let e=await Promise.all(Object.keys(tf).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"?["",...ny]:[""];for(let o of r)for(let c of i){let l=ty(o,e+c);if(await this.isExecutable(l))return l}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?ef.F_OK:ef.X_OK;return await this.env.access(e,r),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let r=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!r)return bt.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return bt.warn("openclaw default agent probe: non-zero exit",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)}),null;let i=r.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return bt.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:r.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return bt.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(l=>l?.isDefault===!0);return c?!c.id||!c.workspace?(bt.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(bt.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return bt.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let r=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!r)return bt.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||bt.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let l=JSON.parse(c[0]);typeof l.gateway?.port=="number"&&(o.port=l.gateway.port),typeof l.service?.runtime?.status=="string"&&(o.runtime=l.service.runtime.status),!i&&typeof l.rpc?.error=="string"&&(o.detail=l.rpc.error)}catch(l){bt.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(l)})}return o}async probeVersion(e,r=[]){let i=await this.runProbe(e,[...r,"--version"]);return i&&(iy(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,l,u=x=>{c||(c=!0,l&&clearTimeout(l),i(x))};try{let x=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});l=setTimeout(()=>{x.kill("SIGKILL"),u(null)},15e3),x.stdout?.on("data",p=>{o+=p.toString("utf8")}),x.on("error",()=>u(null)),x.on("close",p=>u({code:p,stdout:o}))}catch{u(null)}})}},ry=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function iy(t){return t.replace(ry,"")}import{homedir as sy}from"node:os";import{join as oy}from"node:path";yn();Ke();Jr();ne();async function sf(){let t=oy(sy(),".openclaw/openclaw.json");return(await tr(t))?.gateway?.auth?.token??""}var nf=G("openclaw.config"),ay=[0,5e3,5e3],rf="models.providers.",co="agents.defaults.models",lo=class{command;env;retryDelaysMs;queue=new En;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??ay}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,nf.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(l)})}}throw new T("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=dt(this.command,e,{stdio:["ignore","pipe","pipe"],env:this.env}),c="";o.stderr?.on("data",l=>{c+=l.toString("utf8")}),o.on("error",i),o.on("close",l=>{l===0?r():i(new Error(`exit ${l}: ${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){nf.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",`${rf}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${rf}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${co}[${e}]`,()=>this.runCli(["config","set",co,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${co}[${e}]`,`${co}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var pe=G("agent-manager"),xy=(t,e,r,i,o,c,l,u,x,p)=>{switch(t){case"claude-code":{let w={...o?{...Au(o),...Cu(o,l,u)}:{},...x??{},IS_SANDBOX:"1"};return new so({cwd:r,env:w,agentId:i})}case"codex":{let _=[...o?[...Iu(o),...Ru(o,l,u)]:[],"-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"'],I={...o?Tu(o):{},...x??{}},E=!!o;return new oo({cwd:r,agentId:i,..._.length>0?{extraArgs:_}:{},...Object.keys(I).length>0?{env:I}:{},...E?{authMethodId:"openai-api-key",isolateCodexHome:!0,codexHomeDir:p}:{}})}case"openclaw":return new Tr({command:e,cwd:r,agentId:i,...c?{sessionName:$c(c)}:{}})}};function Jc(t){return t==="claude-code"||t==="codex"}function hy(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(py(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
89
+ `},configPath(t){return Rv(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 Tx("schtasks",["/Create","/SC","ONLOGON","/TN",Xo,"/TR",r,"/RU",t.userName,"/F"]),Dd.info("task scheduler entry created",{task:Xo,logFile:t.logFile})},async uninstall(t){await Tx("schtasks",["/Delete","/TN",Xo,"/F"]).catch(e=>Dd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Dd.info("task scheduler entry removed",{task:Xo})}}});var Cx={};ua(Cx,{buildContext:()=>Lv,getSupervisor:()=>kv,launchdSupervisor:()=>Rd,systemdSupervisor:()=>Cd,taskSchedulerSupervisor:()=>kd});import{homedir as Cv,userInfo as Dv}from"node:os";function kv(t=process.platform){switch(t){case"darwin":return Rd;case"linux":return Cd;case"win32":return kd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function Pv(){let t={};for(let e of Ov){let r=process.env[e];r&&(t[e]=r)}return t}function Lv(){let t=Y();return{nodeBin:process.execPath,entry:Ed(t),logFile:t.logFile,homeDir:Cv(),userName:Dv().username,isRoot:process.getuid?.()===0,env:Pv()}}var Ov,Dx=Ke(()=>{"use strict";ke();Go();Sx();Ax();Rx();Ov=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ne();en();var dl=G("acp-installer-warmup"),ng=["claude-code","codex"];async function ll(t={}){let e=t.ensure??Xn,i=(await Promise.allSettled(ng.map(async o=>{let c=await e(o);dl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&dl.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}tn();ne();import{readdir as xg}from"node:fs/promises";import{mkdir as gl,writeFile as ml}from"node:fs/promises";import{join as ya}from"node:path";var hg={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function tr(t,e,r){await gl(t,{recursive:!0});let i=hg[e],o=ya(t,i);return await ml(o,r??"","utf8"),o}async function wl(t){let e=ya(t,".claude");await gl(e,{recursive:!0});let r=ya(e,"settings.local.json"),i=JSON.stringify({permissions:{defaultMode:"bypassPermissions"},env:{CLAUDE_AUTOCOMPACT_PCT_OVERRIDE:"10"}},null,2);return await ml(r,i,"utf8"),r}var Ye=G("agent-detail-sync"),pg=6e4,gg=5*6e4,ss=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await xg(r)}catch(o){Ye.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}Ye.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Ge(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Ye.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(d){Ye.warn("detail sync failed for agent, skipping",{agentId:o,err:String(d)})}}})),Ye.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),r=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&r.push(i);if(r.length!==0){Ye.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){Ye.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Ge(e,this.opts.paths);if(!i){Ye.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(f){Ye.warn("detail RPC failed, using local data",{agentId:e,err:String(f)});let h=this.retryQueue.get(e),x=h?Math.min(h.currentDelay*2,gg):pg;this.retryQueue.set(e,{dueAt:Date.now()+x,currentDelay:x});return}if(o.agentId&&o.agentId!==e){Ye.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,d=!1;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,d=!0),o.deployType&&Ye.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Ye.debug("detail sync: no diff",{agentId:e});return}await Ve(i,this.opts.paths),Ye.info("detail sync: config updated",{agentId:e,identityChanged:d,agentName:i.agentName}),d&&(await tr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var Nu=bt(Yl(),1);import{lstat as Lc,mkdir as Nc,readFile as ku,readdir as Hw,rm as qw,stat as Ww,writeFile as Mc}from"node:fs/promises";import{dirname as $w,join as Ct,normalize as Kw,relative as Fc,resolve as Bc,sep as Ou}from"node:path";import{Readable as Pu}from"node:stream";import{pipeline as Lu}from"node:stream/promises";import zg from"events";import Je from"fs";import{EventEmitter as wc}from"node:events";import Pf from"node:stream";import{StringDecoder as Fg}from"node:string_decoder";import Mf from"node:path";import hr from"node:fs";import{dirname as Xg,parse as Qg}from"path";import{EventEmitter as am}from"events";import Qa from"assert";import{Buffer as Nn}from"buffer";import*as nf from"zlib";import cm from"zlib";import{posix as or}from"node:path";import{basename as Nm}from"node:path";import Bs from"fs";import At from"fs";import lf from"path";import{win32 as $m}from"node:path";import mf from"path";import Yf from"node:fs";import dw from"node:assert";import{randomBytes as Xf}from"node:crypto";import re from"node:fs";import Pe from"node:path";import Qf from"fs";import $s from"node:fs";import xi from"node:path";import et from"node:fs";import gw from"node:fs/promises";import Us from"node:path";import{join as lu}from"node:path";import Qe from"node:fs";import hu from"node:path";var Mg=Object.defineProperty,Bg=(t,e)=>{for(var r in e)Mg(t,r,{get:e[r],enumerable:!0})},Xl=typeof process=="object"&&process?process:{stdout:null,stderr:null},Ug=t=>!!t&&typeof t=="object"&&(t instanceof zn||t instanceof Pf||Gg(t)||jg(t)),Gg=t=>!!t&&typeof t=="object"&&t instanceof wc&&typeof t.pipe=="function"&&t.pipe!==Pf.Writable.prototype.pipe,jg=t=>!!t&&typeof t=="object"&&t instanceof wc&&typeof t.write=="function"&&typeof t.end=="function",Bt=Symbol("EOF"),zt=Symbol("maybeEmitEnd"),rn=Symbol("emittedEnd"),ls=Symbol("emittingEnd"),Yr=Symbol("emittedError"),fs=Symbol("closed"),Ql=Symbol("read"),us=Symbol("flush"),ef=Symbol("flushChunk"),ut=Symbol("encoding"),sr=Symbol("decoder"),Ne=Symbol("flowing"),Xr=Symbol("paused"),lr=Symbol("resume"),Me=Symbol("buffer"),We=Symbol("pipes"),Be=Symbol("bufferLength"),Ia=Symbol("bufferPush"),hs=Symbol("bufferShift"),He=Symbol("objectMode"),ve=Symbol("destroyed"),Aa=Symbol("error"),Ta=Symbol("emitData"),tf=Symbol("emitEnd"),Ra=Symbol("emitEnd2"),vt=Symbol("async"),Ca=Symbol("abort"),xs=Symbol("aborted"),Qr=Symbol("signal"),An=Symbol("dataListeners"),Xe=Symbol("discarded"),ei=t=>Promise.resolve().then(t),Hg=t=>t(),qg=t=>t==="end"||t==="finish"||t==="prefinish",Wg=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,$g=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Lf=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[lr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Kg=class extends Lf{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)}},Zg=t=>!!t.objectMode,Vg=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",zn=class extends wc{[Ne]=!1;[Xr]=!1;[We]=[];[Me]=[];[He];[ut];[vt];[sr];[Bt]=!1;[rn]=!1;[ls]=!1;[fs]=!1;[Yr]=null;[Be]=0;[ve]=!1;[Qr];[xs]=!1;[An]=0;[Xe]=!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");Zg(e)?(this[He]=!0,this[ut]=null):Vg(e)?(this[ut]=e.encoding,this[He]=!1):(this[He]=!1,this[ut]=null),this[vt]=!!e.async,this[sr]=this[ut]?new Fg(this[ut]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Me]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[We]});let{signal:r}=e;r&&(this[Qr]=r,r.aborted?this[Ca]():r.addEventListener("abort",()=>this[Ca]()))}get bufferLength(){return this[Be]}get encoding(){return this[ut]}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[He]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[vt]}set async(t){this[vt]=this[vt]||!!t}[Ca](){this[xs]=!0,this.emit("abort",this[Qr]?.reason),this.destroy(this[Qr]?.reason)}get aborted(){return this[xs]}set aborted(t){}write(t,e,r){if(this[xs])return!1;if(this[Bt])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[vt]?ei:Hg;if(!this[He]&&!Buffer.isBuffer(t)){if($g(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(Wg(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[He]?(this[Ne]&&this[Be]!==0&&this[us](!0),this[Ne]?this.emit("data",t):this[Ia](t),this[Be]!==0&&this.emit("readable"),r&&i(r),this[Ne]):t.length?(typeof t=="string"&&!(e===this[ut]&&!this[sr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[ut]&&(t=this[sr].write(t)),this[Ne]&&this[Be]!==0&&this[us](!0),this[Ne]?this.emit("data",t):this[Ia](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[ve])return null;if(this[Xe]=!1,this[Be]===0||t===0||t&&t>this[Be])return this[zt](),null;this[He]&&(t=null),this[Me].length>1&&!this[He]&&(this[Me]=[this[ut]?this[Me].join(""):Buffer.concat(this[Me],this[Be])]);let e=this[Ql](t||null,this[Me][0]);return this[zt](),e}[Ql](t,e){if(this[He])this[hs]();else{let r=e;t===r.length||t===null?this[hs]():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[Bt]&&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[Bt]=!0,this.writable=!1,(this[Ne]||!this[Xr])&&this[zt](),this}[lr](){this[ve]||(!this[An]&&!this[We].length&&(this[Xe]=!0),this[Xr]=!1,this[Ne]=!0,this.emit("resume"),this[Me].length?this[us]():this[Bt]?this[zt]():this.emit("drain"))}resume(){return this[lr]()}pause(){this[Ne]=!1,this[Xr]=!0,this[Xe]=!1}get destroyed(){return this[ve]}get flowing(){return this[Ne]}get paused(){return this[Xr]}[Ia](t){this[He]?this[Be]+=1:this[Be]+=t.length,this[Me].push(t)}[hs](){return this[He]?this[Be]-=1:this[Be]-=this[Me][0].length,this[Me].shift()}[us](t=!1){do;while(this[ef](this[hs]())&&this[Me].length);!t&&!this[Me].length&&!this[Bt]&&this.emit("drain")}[ef](t){return this.emit("data",t),this[Ne]}pipe(t,e){if(this[ve])return t;this[Xe]=!1;let r=this[rn];return e=e||{},t===Xl.stdout||t===Xl.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[We].push(e.proxyErrors?new Kg(this,t,e):new Lf(this,t,e)),this[vt]?ei(()=>this[lr]()):this[lr]()),t}unpipe(t){let e=this[We].find(r=>r.dest===t);e&&(this[We].length===1?(this[Ne]&&this[An]===0&&(this[Ne]=!1),this[We]=[]):this[We].splice(this[We].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[Xe]=!1,this[An]++,!this[We].length&&!this[Ne]&&this[lr]();else if(t==="readable"&&this[Be]!==0)super.emit("readable");else if(qg(t)&&this[rn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[Yr]){let i=e;this[vt]?ei(()=>i.call(this,this[Yr])):i.call(this,this[Yr])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[An]=this.listeners("data").length,this[An]===0&&!this[Xe]&&!this[We].length&&(this[Ne]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[An]=0,!this[Xe]&&!this[We].length&&(this[Ne]=!1)),e}get emittedEnd(){return this[rn]}[zt](){!this[ls]&&!this[rn]&&!this[ve]&&this[Me].length===0&&this[Bt]&&(this[ls]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[fs]&&this.emit("close"),this[ls]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==ve&&this[ve])return!1;if(t==="data")return!this[He]&&!r?!1:this[vt]?(ei(()=>this[Ta](r)),!0):this[Ta](r);if(t==="end")return this[tf]();if(t==="close"){if(this[fs]=!0,!this[rn]&&!this[ve])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[Yr]=r,super.emit(Aa,r);let o=!this[Qr]||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}[Ta](t){for(let r of this[We])r.dest.write(t)===!1&&this.pause();let e=this[Xe]?!1:super.emit("data",t);return this[zt](),e}[tf](){return this[rn]?!1:(this[rn]=!0,this.readable=!1,this[vt]?(ei(()=>this[Ra]()),!0):this[Ra]())}[Ra](){if(this[sr]){let e=this[sr].end();if(e){for(let r of this[We])r.dest.write(e);this[Xe]||super.emit("data",e)}}for(let e of this[We])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[He]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[He]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[He])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[ut]?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[Xe]=!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[Bt])return e();let i,o,c=x=>{this.off("data",d),this.off("end",f),this.off(ve,h),e(),o(x)},d=x=>{this.off("error",c),this.off("end",f),this.off(ve,h),this.pause(),i({value:x,done:!!this[Bt]})},f=()=>{this.off("error",c),this.off("data",d),this.off(ve,h),e(),i({done:!0,value:void 0})},h=()=>c(new Error("stream destroyed"));return new Promise((x,m)=>{o=m,i=x,this.once(ve,h),this.once("error",c),this.once("end",f),this.once("data",d)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[Xe]=!1;let t=!1,e=()=>(this.pause(),this.off(Aa,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(Aa,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[Xe]=!0,this[Me].length=0,this[Be]=0;let e=this;return typeof e.close=="function"&&!this[fs]&&e.close(),t?this.emit("error",t):this.emit(ve),this}static get isStream(){return Ug}},Jg=Je.writev,xn=Symbol("_autoClose"),gt=Symbol("_close"),ti=Symbol("_ended"),ae=Symbol("_fd"),Da=Symbol("_finished"),jt=Symbol("_flags"),ka=Symbol("_flush"),Ya=Symbol("_handleChunk"),Xa=Symbol("_makeBuf"),ui=Symbol("_mode"),ps=Symbol("_needDrain"),pr=Symbol("_onerror"),gr=Symbol("_onopen"),Oa=Symbol("_onread"),fr=Symbol("_onwrite"),pn=Symbol("_open"),pt=Symbol("_path"),dn=Symbol("_pos"),St=Symbol("_queue"),ur=Symbol("_read"),Pa=Symbol("_readSize"),Gt=Symbol("_reading"),ni=Symbol("_remain"),La=Symbol("_size"),Is=Symbol("_write"),Tn=Symbol("_writing"),As=Symbol("_defaultFlag"),Ln=Symbol("_errored"),yc=class extends zn{[Ln]=!1;[ae];[pt];[Pa];[Gt]=!1;[La];[ni];[xn];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[Ln]=!1,this[ae]=typeof e.fd=="number"?e.fd:void 0,this[pt]=t,this[Pa]=e.readSize||16*1024*1024,this[Gt]=!1,this[La]=typeof e.size=="number"?e.size:1/0,this[ni]=this[La],this[xn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[ae]=="number"?this[ur]():this[pn]()}get fd(){return this[ae]}get path(){return this[pt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[pn](){Je.open(this[pt],"r",(t,e)=>this[gr](t,e))}[gr](t,e){t?this[pr](t):(this[ae]=e,this.emit("open",e),this[ur]())}[Xa](){return Buffer.allocUnsafe(Math.min(this[Pa],this[ni]))}[ur](){if(!this[Gt]){this[Gt]=!0;let t=this[Xa]();if(t.length===0)return process.nextTick(()=>this[Oa](null,0,t));Je.read(this[ae],t,0,t.length,null,(e,r,i)=>this[Oa](e,r,i))}}[Oa](t,e,r){this[Gt]=!1,t?this[pr](t):this[Ya](e,r)&&this[ur]()}[gt](){if(this[xn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Je.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[pr](t){this[Gt]=!0,this[gt](),this.emit("error",t)}[Ya](t,e){let r=!1;return this[ni]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[ni]<=0)&&(r=!1,this[gt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[ae]=="number"&&this[ur](),!1;case"error":return this[Ln]?!1:(this[Ln]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Yg=class extends yc{[pn](){let t=!0;try{this[gr](null,Je.openSync(this[pt],"r")),t=!1}finally{t&&this[gt]()}}[ur](){let t=!0;try{if(!this[Gt]){this[Gt]=!0;do{let e=this[Xa](),r=e.length===0?0:Je.readSync(this[ae],e,0,e.length,null);if(!this[Ya](r,e))break}while(!0);this[Gt]=!1}t=!1}finally{t&&this[gt]()}}[gt](){if(this[xn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Je.closeSync(t),this.emit("close")}}},Gs=class extends zg{readable=!1;writable=!0;[Ln]=!1;[Tn]=!1;[ti]=!1;[St]=[];[ps]=!1;[pt];[ui];[xn];[ae];[As];[jt];[Da]=!1;[dn];constructor(t,e){e=e||{},super(e),this[pt]=t,this[ae]=typeof e.fd=="number"?e.fd:void 0,this[ui]=e.mode===void 0?438:e.mode,this[dn]=typeof e.start=="number"?e.start:void 0,this[xn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[dn]!==void 0?"r+":"w";this[As]=e.flags===void 0,this[jt]=e.flags===void 0?r:e.flags,this[ae]===void 0&&this[pn]()}emit(t,...e){if(t==="error"){if(this[Ln])return!1;this[Ln]=!0}return super.emit(t,...e)}get fd(){return this[ae]}get path(){return this[pt]}[pr](t){this[gt](),this[Tn]=!0,this.emit("error",t)}[pn](){Je.open(this[pt],this[jt],this[ui],(t,e)=>this[gr](t,e))}[gr](t,e){this[As]&&this[jt]==="r+"&&t&&t.code==="ENOENT"?(this[jt]="w",this[pn]()):t?this[pr](t):(this[ae]=e,this.emit("open",e),this[Tn]||this[ka]())}end(t,e){return t&&this.write(t,e),this[ti]=!0,!this[Tn]&&!this[St].length&&typeof this[ae]=="number"&&this[fr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[ti]?(this.emit("error",new Error("write() after end()")),!1):this[ae]===void 0||this[Tn]||this[St].length?(this[St].push(t),this[ps]=!0,!1):(this[Tn]=!0,this[Is](t),!0)}[Is](t){Je.write(this[ae],t,0,t.length,this[dn],(e,r)=>this[fr](e,r))}[fr](t,e){t?this[pr](t):(this[dn]!==void 0&&typeof e=="number"&&(this[dn]+=e),this[St].length?this[ka]():(this[Tn]=!1,this[ti]&&!this[Da]?(this[Da]=!0,this[gt](),this.emit("finish")):this[ps]&&(this[ps]=!1,this.emit("drain"))))}[ka](){if(this[St].length===0)this[ti]&&this[fr](null,0);else if(this[St].length===1)this[Is](this[St].pop());else{let t=this[St];this[St]=[],Jg(this[ae],t,this[dn],(e,r)=>this[fr](e,r))}}[gt](){if(this[xn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Je.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Nf=class extends Gs{[pn](){let t;if(this[As]&&this[jt]==="r+")try{t=Je.openSync(this[pt],this[jt],this[ui])}catch(e){if(e?.code==="ENOENT")return this[jt]="w",this[pn]();throw e}else t=Je.openSync(this[pt],this[jt],this[ui]);this[gr](null,t)}[gt](){if(this[xn]&&typeof this[ae]=="number"){let t=this[ae];this[ae]=void 0,Je.closeSync(t),this.emit("close")}}[Is](t){let e=!0;try{this[fr](null,Je.writeSync(this[ae],t,0,t.length,this[dn])),e=!1}finally{if(e)try{this[gt]()}catch{}}}},em=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),tm=t=>!!t.sync&&!!t.file,nm=t=>!t.sync&&!!t.file,rm=t=>!!t.sync&&!t.file,im=t=>!t.sync&&!t.file,sm=t=>!!t.file,om=t=>em.get(t)||t,_c=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=om(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ei=(t,e,r,i,o)=>Object.assign((c=[],d,f)=>{Array.isArray(c)&&(d=c,c={}),typeof d=="function"&&(f=d,d=void 0),d=d?Array.from(d):[];let h=_c(c);if(o?.(h,d),tm(h)){if(typeof f=="function")throw new TypeError("callback not supported for sync tar functions");return t(h,d)}else if(nm(h)){let x=e(h,d);return f?x.then(()=>f(),f):x}else if(rm(h)){if(typeof f=="function")throw new TypeError("callback not supported for sync tar functions");return r(h,d)}else if(im(h)){if(typeof f=="function")throw new TypeError("callback only supported with file option");return i(h,d)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),dm=cm.constants||{ZLIB_VERNUM:4736},Rt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},dm)),lm=Nn.concat,rf=Object.getOwnPropertyDescriptor(Nn,"concat"),fm=t=>t,Na=rf?.writable===!0||rf?.set!==void 0?t=>{Nn.concat=t?fm:lm}:t=>{},Mn=Symbol("_superWrite"),gs=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"}},Ma=Symbol("flushFlag"),Ec=class extends zn{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof nf[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new nf[e](t)}catch(r){throw new gs(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 gs(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return Qa(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Nn.alloc(0),{[Ma]:t})))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(r)}get ended(){return this.#n}[Mn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Nn.from(t,e)),this.#e)return;Qa(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},Na(!0);let d;try{let h=typeof t[Ma]=="number"?t[Ma]:this.#r;d=this.#t._processChunk(t,h),Na(!1)}catch(h){Na(!1),this.#o(new gs(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 gs(h,this.write)));let f;if(d)if(Array.isArray(d)&&d.length>0){let h=d[0];f=this[Mn](Nn.from(h));for(let x=1;x<d.length;x++)f=this[Mn](d[x])}else f=this[Mn](Nn.from(d));return r&&r(),f}},Bf=class extends Ec{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Rt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Rt.Z_FINISH,t.fullFlushFlag=Rt.Z_FULL_FLUSH,super(t,e),this.#e=t.level,this.#n=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==t||this.#n!==e){this.flush(Rt.Z_SYNC_FLUSH),Qa(this.handle,"zlib binding closed");let r=this.handle.flush;this.handle.flush=(i,o)=>{typeof i=="function"&&(o=i,i=this.flushFlag),this.flush(i),o?.()};try{this.handle.params(t,e)}finally{this.handle.flush=r}this.handle&&(this.#e=t,this.#n=e)}}}},um=class extends Bf{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Mn](t){return this.#e?(this.#e=!1,t[9]=255,super[Mn](t)):super[Mn](t)}},hm=class extends Bf{constructor(t){super(t,"Unzip")}},zf=class extends Ec{constructor(t,e){t=t||{},t.flush=t.flush||Rt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Rt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Rt.BROTLI_OPERATION_FLUSH,super(t,e)}},xm=class extends zf{constructor(t){super(t,"BrotliCompress")}},pm=class extends zf{constructor(t){super(t,"BrotliDecompress")}},Ff=class extends Ec{constructor(t,e){t=t||{},t.flush=t.flush||Rt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Rt.ZSTD_e_end,t.fullFlushFlag=Rt.ZSTD_e_flush,super(t,e)}},gm=class extends Ff{constructor(t){super(t,"ZstdCompress")}},mm=class extends Ff{constructor(t){super(t,"ZstdDecompress")}},wm=(t,e)=>{if(Number.isSafeInteger(t))t<0?_m(t,e):ym(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},ym=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},_m=(t,e)=>{e[0]=255;var r=!1;t=t*-1;for(var i=e.length;i>1;i--){var o=t&255;t=Math.floor(t/256),r?e[i-1]=Uf(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Gf(o))}},Em=t=>{let e=t[0],r=e===128?vm(t.subarray(1,t.length)):e===255?bm(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},bm=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),d;i?d=Uf(c):c===0?d=c:(i=!0,d=Gf(c)),d!==0&&(r-=d*Math.pow(256,e-o-1))}return r},vm=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},Uf=t=>(255^t)&255,Gf=t=>(255^t)+1&255,Sm={};Bg(Sm,{code:()=>bc,isCode:()=>Ts,isName:()=>Im,name:()=>js});var Ts=t=>js.has(t),Im=t=>bc.has(t),js=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),bc=new Map(Array.from(js).map(t=>[t[1],t[0]])),Bn=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,r,i){Buffer.isBuffer(t)?this.decode(t,e||0,r,i):t&&this.#n(t)}decode(t,e,r,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");this.path=r?.path??Rn(t,e,100),this.mode=r?.mode??i?.mode??ln(t,e+100,8),this.uid=r?.uid??i?.uid??ln(t,e+108,8),this.gid=r?.gid??i?.gid??ln(t,e+116,8),this.size=r?.size??i?.size??ln(t,e+124,12),this.mtime=r?.mtime??i?.mtime??Ba(t,e+136,12),this.cksum=ln(t,e+148,12),i&&this.#n(i,!0),r&&this.#n(r);let o=Rn(t,e+156,1);if(Ts(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Rn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=r?.uname??i?.uname??Rn(t,e+265,32),this.gname=r?.gname??i?.gname??Rn(t,e+297,32),this.devmaj=r?.devmaj??i?.devmaj??ln(t,e+329,8)??0,this.devmin=r?.devmin??i?.devmin??ln(t,e+337,8)??0,t[e+475]!==0){let d=Rn(t,e+345,155);this.path=d+"/"+this.path}else{let d=Rn(t,e+345,130);d&&(this.path=d+"/"+this.path),this.atime=r?.atime??i?.atime??Ba(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Ba(t,e+488,12)}let c=256;for(let d=e;d<e+148;d++)c+=t[d];for(let d=e+156;d<e+512;d++)c+=t[d];this.cksumValid=c===this.cksum,this.cksum===void 0&&c===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e||r==="linkpath"&&e||r==="global"))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let r=this.ctime||this.atime?130:155,i=Am(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Cn(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=za(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Cn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Cn(t,e+265,32,this.uname)||this.needPax,this.needPax=Cn(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=Cn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=Cn(t,e+345,155,c)||this.needPax:(this.needPax=Cn(t,e+345,130,c)||this.needPax,this.needPax=za(t,e+476,12,this.atime)||this.needPax,this.needPax=za(t,e+488,12,this.ctime)||this.needPax);let d=256;for(let f=e;f<e+148;f++)d+=t[f];for(let f=e+156;f<e+512;f++)d+=t[f];return this.cksum=d,fn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:js.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(bc.get(t));if(Ts(e)||e==="Unsupported")this.#e=e;else if(Ts(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Am=(t,e)=>{let r=t,i="",o,c=or.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=or.dirname(r),r=or.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=or.join(or.basename(i),r),i=or.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Rn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Ba=(t,e,r)=>Tm(ln(t,e,r)),Tm=t=>t===void 0?void 0:new Date(t*1e3),ln=(t,e,r)=>Number(t[e])&128?Em(t.subarray(e,e+r)):Cm(t,e,r),Rm=t=>isNaN(t)?void 0:t,Cm=(t,e,r)=>Rm(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),Dm={12:8589934591,8:2097151},fn=(t,e,r,i)=>i===void 0?!1:i>Dm[r]||i<0?(wm(i,t.subarray(e,e+r)),!0):(km(t,e,r,i),!1),km=(t,e,r,i)=>t.write(Om(i,r),e,r,"ascii"),Om=(t,e)=>Pm(Math.floor(t).toString(8),e),Pm=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",za=(t,e,r,i)=>i===void 0?!1:fn(t,e,r,i.getTime()/1e3),Lm=new Array(156).join("\0"),Cn=(t,e,r,i)=>i===void 0?!1:(t.write(i+Lm,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),Ms=class jf{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,r=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=r,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return Buffer.allocUnsafe(0);let r=Buffer.byteLength(e),i=512*Math.ceil(1+r/512),o=Buffer.allocUnsafe(i);for(let c=0;c<512;c++)o[c]=0;new Bn({path:("PaxHeader/"+Nm(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:r,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(o),o.write(e,512,r,"utf8");for(let c=r+512;c<o.length;c++)o[c]=0;return o}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let r=this[e],i=r instanceof Date?r.getTime()/1e3:r,o=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+i+`
90
+ `,c=Buffer.byteLength(o),d=Math.floor(Math.log(c)/Math.log(10))+1;return c+d>=Math.pow(10,d)&&(d+=1),d+c+o}static parse(e,r,i=!1){return new jf(Mm(Bm(e),r),i)}},Mm=(t,e)=>e?Object.assign({},e,t):t,Bm=t=>t.replace(/\n$/,"").split(`
91
+ `).reduce(zm,Object.create(null)),zm=(t,e)=>{let r=parseInt(e,10);if(r!==Buffer.byteLength(e)+1)return t;e=e.slice((r+" ").length);let i=e.split("="),o=i.shift();if(!o)return t;let c=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),d=i.join("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(d)*1e3):/^[0-9]+$/.test(d)?+d:d,t},Fm=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,J=Fm!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),Hf=class extends zn{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,r){switch(super({}),this.pause(),this.extended=e,this.globalExtended=r,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=J(t.path),this.mode=t.mode,this.mode&&(this.mode=this.mode&4095),this.uid=t.uid,this.gid=t.gid,this.uname=t.uname,this.gname=t.gname,this.size=this.remain,this.mtime=t.mtime,this.atime=t.atime,this.ctime=t.ctime,this.linkpath=t.linkpath?J(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#e(e),r&&this.#e(r,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let r=this.remain,i=this.blockRemain;return this.remain=Math.max(0,r-e),this.blockRemain=Math.max(0,i-e),this.ignore?!0:r>=e?super.write(t):super.write(t.subarray(0,r))}#e(t,e=!1){t.path&&(t.path=J(t.path)),t.linkpath&&(t.linkpath=J(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},Hs=(t,e,r,i={})=>{t.file&&(i.file=t.file),t.cwd&&(i.cwd=t.cwd),i.code=r instanceof Error&&r.code||e,i.tarCode=e,!t.strict&&i.recoverable!==!1?(r instanceof Error&&(i=Object.assign(r,i),r=r.message),t.emit("warn",e,r,i)):r instanceof Error?t.emit("error",Object.assign(r,i)):t.emit("error",Object.assign(new Error(`${e}: ${r}`),i))},Um=1024*1024,ec=Buffer.from([31,139]),tc=Buffer.from([40,181,47,253]),Gm=Math.max(ec.length,tc.length),st=Symbol("state"),Dn=Symbol("writeEntry"),Ft=Symbol("readEntry"),Fa=Symbol("nextEntry"),sf=Symbol("processEntry"),It=Symbol("extendedHeader"),ri=Symbol("globalExtendedHeader"),sn=Symbol("meta"),of=Symbol("emitMeta"),ue=Symbol("buffer"),Ut=Symbol("queue"),on=Symbol("ended"),Ua=Symbol("emittedEnd"),kn=Symbol("emit"),Te=Symbol("unzip"),ms=Symbol("consumeChunk"),ws=Symbol("consumeChunkSub"),Ga=Symbol("consumeBody"),af=Symbol("consumeMeta"),cf=Symbol("consumeHeader"),ii=Symbol("consuming"),ja=Symbol("bufferConcat"),ys=Symbol("maybeEnd"),ar=Symbol("writing"),an=Symbol("aborted"),_s=Symbol("onDone"),On=Symbol("sawValidEntry"),Es=Symbol("sawNullBlock"),bs=Symbol("sawEOF"),df=Symbol("closeStream"),jm=()=>!0,_i=class extends am{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Ut]=[];[ue];[Ft];[Dn];[st]="begin";[sn]="";[It];[ri];[on]=!1;[Te];[an]=!1;[On];[Es]=!1;[bs]=!1;[ar]=!1;[ii]=!1;[Ua]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(_s,()=>{(this[st]==="begin"||this[On]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(_s,t.ondone):this.on(_s,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||Um,this.filter=typeof t.filter=="function"?t.filter:jm;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[df]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){Hs(this,t,e,r)}[cf](t,e){this[On]===void 0&&(this[On]=!1);let r;try{r=new Bn(t,e,this[It],this[ri])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Es]?(this[bs]=!0,this[st]==="begin"&&(this[st]="header"),this[kn]("eof")):(this[Es]=!0,this[kn]("nullBlock"));else if(this[Es]=!1,!r.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:r});else if(!r.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:r});else{let i=r.type;if(/^(Symbolic)?Link$/.test(i)&&!r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:r});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:r});else{let o=this[Dn]=new Hf(r,this[It],this[ri]);if(!this[On])if(o.remain){let c=()=>{o.invalid||(this[On]=!0)};o.on("end",c)}else this[On]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[kn]("ignoredEntry",o),this[st]="ignore",o.resume()):o.size>0&&(this[sn]="",o.on("data",c=>this[sn]+=c),this[st]="meta"):(this[It]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[kn]("ignoredEntry",o),this[st]=o.remain?"ignore":"header",o.resume()):(o.remain?this[st]="body":(this[st]="header",o.end()),this[Ft]?this[Ut].push(o):(this[Ut].push(o),this[Fa]())))}}}[df](){queueMicrotask(()=>this.emit("close"))}[sf](t){let e=!0;if(!t)this[Ft]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[Ft]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Fa]()),e=!1);return e}[Fa](){do;while(this[sf](this[Ut].shift()));if(this[Ut].length===0){let t=this[Ft];!t||t.flowing||t.size===t.remain?this[ar]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Ga](t,e){let r=this[Dn];if(!r)throw new Error("attempt to consume body without entry??");let i=r.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return r.write(o),r.blockRemain||(this[st]="header",this[Dn]=void 0,r.end()),o.length}[af](t,e){let r=this[Dn],i=this[Ga](t,e);return!this[Dn]&&r&&this[of](r),i}[kn](t,e,r){this[Ut].length===0&&!this[Ft]?this.emit(t,e,r):this[Ut].push([t,e,r])}[of](t){switch(this[kn]("meta",this[sn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[It]=Ms.parse(this[sn],this[It],!1);break;case"GlobalExtendedHeader":this[ri]=Ms.parse(this[sn],this[ri],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[It]??Object.create(null);this[It]=e,e.path=this[sn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[It]||Object.create(null);this[It]=e,e.linkpath=this[sn].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[an]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[an])return r?.(),!1;if((this[Te]===void 0||this.brotli===void 0&&this[Te]===!1)&&t){if(this[ue]&&(t=Buffer.concat([this[ue],t]),this[ue]=void 0),t.length<Gm)return this[ue]=t,r?.(),!0;for(let d=0;this[Te]===void 0&&d<ec.length;d++)t[d]!==ec[d]&&(this[Te]=!1);let o=!1;if(this[Te]===!1&&this.zstd!==!1){o=!0;for(let d=0;d<tc.length;d++)if(t[d]!==tc[d]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Te]===!1&&c)if(t.length<512)if(this[on])this.brotli=!0;else return this[ue]=t,r?.(),!0;else try{new Bn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Te]===void 0||this[Te]===!1&&(this.brotli||o)){let d=this[on];this[on]=!1,this[Te]=this[Te]===void 0?new hm({}):o?new mm({}):new pm({}),this[Te].on("data",h=>this[ms](h)),this[Te].on("error",h=>this.abort(h)),this[Te].on("end",()=>{this[on]=!0,this[ms]()}),this[ar]=!0;let f=!!this[Te][d?"end":"write"](t);return this[ar]=!1,r?.(),f}}this[ar]=!0,this[Te]?this[Te].write(t):this[ms](t),this[ar]=!1;let i=this[Ut].length>0?!1:this[Ft]?this[Ft].flowing:!0;return!i&&this[Ut].length===0&&this[Ft]?.once("drain",()=>this.emit("drain")),r?.(),i}[ja](t){t&&!this[an]&&(this[ue]=this[ue]?Buffer.concat([this[ue],t]):t)}[ys](){if(this[on]&&!this[Ua]&&!this[an]&&!this[ii]){this[Ua]=!0;let t=this[Dn];if(t&&t.blockRemain){let e=this[ue]?this[ue].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[ue]&&t.write(this[ue]),t.end()}this[kn](_s)}}[ms](t){if(this[ii]&&t)this[ja](t);else if(!t&&!this[ue])this[ys]();else if(t){if(this[ii]=!0,this[ue]){this[ja](t);let e=this[ue];this[ue]=void 0,this[ws](e)}else this[ws](t);for(;this[ue]&&this[ue]?.length>=512&&!this[an]&&!this[bs];){let e=this[ue];this[ue]=void 0,this[ws](e)}this[ii]=!1}(!this[ue]||this[on])&&this[ys]()}[ws](t){let e=0,r=t.length;for(;e+512<=r&&!this[an]&&!this[bs];)switch(this[st]){case"begin":case"header":this[cf](t,e),e+=512;break;case"ignore":case"body":e+=this[Ga](t,e);break;case"meta":e+=this[af](t,e);break;default:throw new Error("invalid state: "+this[st])}e<r&&(this[ue]=this[ue]?Buffer.concat([t.subarray(e),this[ue]]):t.subarray(e))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),r&&this.once("finish",r),this[an]||(this[Te]?(t&&this[Te].write(t),this[Te].end()):(this[on]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[ys]())),this}},hi=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)},Hm=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},qf=(t,e)=>{let r=new Map(e.map(c=>[hi(c),!0])),i=t.filter,o=(c,d="")=>{let f=d||Qg(c).root||".",h;if(c===f)h=!1;else{let x=r.get(c);h=x!==void 0?x:o(Xg(c),f)}return r.set(c,h),h};t.filter=i?(c,d)=>i(c,d)&&o(hi(c)):c=>o(hi(c))},qm=t=>{let e=new _i(t),r=t.file,i;try{i=hr.openSync(r,"r");let o=hr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let d=Buffer.allocUnsafe(o.size),f=hr.readSync(i,d,0,o.size,0);e.end(f===d.byteLength?d:d.subarray(0,f))}else{let d=0,f=Buffer.allocUnsafe(c);for(;d<o.size;){let h=hr.readSync(i,f,0,c,d);if(h===0)break;d+=h,e.write(f.subarray(0,h))}e.end()}}finally{if(typeof i=="number")try{hr.closeSync(i)}catch{}}},Wm=(t,e)=>{let r=new _i(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("end",c),hr.stat(o,(f,h)=>{if(f)d(f);else{let x=new yc(o,{readSize:i,size:h.size});x.on("error",d),x.pipe(r)}})})},mr=Ei(qm,Wm,t=>new _i(t),t=>new _i(t),(t,e)=>{e?.length&&qf(t,e),t.noResume||Hm(t)}),Wf=(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:Km,parse:ff}=$m,vc=t=>{let e="",r=ff(t);for(;Km(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=ff(t)}return[e,t]},qs=["|","<",">","?",":"],Sc=qs.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),Zm=new Map(qs.map((t,e)=>[t,Sc[e]])),Vm=new Map(Sc.map((t,e)=>[t,qs[e]])),uf=t=>qs.reduce((e,r)=>e.split(r).join(Zm.get(r)),t),Jm=t=>Sc.reduce((e,r)=>e.split(r).join(Vm.get(r)),t),$f=(t,e)=>e?(t=J(t).replace(/^\.(\/|$)/,""),hi(e)+"/"+t):J(t),Ym=16*1024*1024,hf=Symbol("process"),xf=Symbol("file"),pf=Symbol("directory"),nc=Symbol("symlink"),gf=Symbol("hardlink"),si=Symbol("header"),Rs=Symbol("read"),rc=Symbol("lstat"),Cs=Symbol("onlstat"),ic=Symbol("onread"),sc=Symbol("onreadlink"),oc=Symbol("openfile"),ac=Symbol("onopenfile"),un=Symbol("close"),zs=Symbol("mode"),cc=Symbol("awaitDrain"),Ha=Symbol("ondrain"),Tt=Symbol("prefix"),Kf=class extends zn{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let r=_c(e);super(),this.path=J(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||Ym,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=J(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?J(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,d]=vc(this.path);c&&typeof d=="string"&&(this.path=d,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Jm(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=J(r.absolute||lf.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[Cs](o):this[rc]()}warn(t,e,r={}){return Hs(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[rc](){At.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Cs](e)})}[Cs](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=ew(t),this.emit("stat",t),this[hf]()}[hf](){switch(this.type){case"File":return this[xf]();case"Directory":return this[pf]();case"SymbolicLink":return this[nc]();default:return this.end()}}[zs](t){return Wf(t,this.type==="Directory",this.portable)}[Tt](t){return $f(t,this.prefix)}[si](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new Bn({path:this[Tt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Tt](this.linkpath):this.linkpath,mode:this[zs](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new Ms({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[Tt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Tt](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)}[pf](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[si](),this.end()}[nc](){At.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[sc](e)})}[sc](t){this.linkpath=J(t),this[si](),this.end()}[gf](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=J(lf.relative(this.cwd,t)),this.stat.size=0,this[si](),this.end()}[xf](){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[gf](e);this.linkCache.set(t,this.absolute)}if(this[si](),this.stat.size===0)return this.end();this[oc]()}[oc](){At.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[ac](e)})}[ac](t){if(this.fd=t,this.#e)return this[un]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[Rs]()}[Rs](){let{fd:t,buf:e,offset:r,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");At.read(t,e,r,i,o,(c,d)=>{if(c)return this[un](()=>this.emit("error",c));this[ic](d)})}[un](t=()=>{}){this.fd!==void 0&&At.close(this.fd,t)}[ic](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[un](()=>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[un](()=>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[Ha]():this[cc](()=>this[Ha]())}[cc](t){this.once("drain",t)}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this.blockRemain<t.length){let i=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",i)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,r)}[Ha](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[un](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[Rs]()}},Xm=class extends Kf{sync=!0;[rc](){this[Cs](At.lstatSync(this.absolute))}[nc](){this[sc](At.readlinkSync(this.absolute))}[oc](){this[ac](At.openSync(this.absolute,"r"))}[Rs](){let t=!0;try{let{fd:e,buf:r,offset:i,length:o,pos:c}=this;if(e===void 0||r===void 0)throw new Error("fd and buf must be set in READ method");let d=At.readSync(e,r,i,o,c);this[ic](d),t=!1}finally{if(t)try{this[un](()=>{})}catch{}}}[cc](t){t()}[un](t=()=>{}){this.fd!==void 0&&At.closeSync(this.fd),t()}},Qm=class extends zn{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,r={}){return Hs(this,t,e,r)}constructor(t,e={}){let r=_c(e);super(),this.preservePaths=!!r.preservePaths,this.portable=!!r.portable,this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.onWriteEntry=r.onWriteEntry,this.readEntry=t;let{type:i}=t;if(i==="Unsupported")throw new Error("writing entry that should be ignored");this.type=i,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=r.prefix,this.path=J(t.path),this.mode=t.mode!==void 0?this[zs](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?J(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[d,f]=vc(this.path);d&&typeof f=="string"&&(this.path=f,o=d)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Bn({path:this[Tt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Tt](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 Ms({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[Tt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Tt](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)}[Tt](t){return $f(t,this.prefix)}[zs](t){return Wf(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",tw=class xr{tail;head;length=0;static create(e=[]){return new xr(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++)rw(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 xr;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 xr;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 xr;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 xr;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.length,c=this.tail;for(;c&&o>r;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,r=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let d=0;o&&d<e;d++)o=o.next;let c=[];for(let d=0;o&&d<r;d++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let d of i)o=nw(this,o,d);return c}reverse(){let e=this.head,r=this.tail;for(let i=e;i;i=i.prev){let o=i.prev;i.prev=i.next,i.next=o}return this.head=r,this.tail=e,this}};function nw(t,e,r){let i=e,o=e?e.next:t.head,c=new Ic(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function rw(t,e){t.tail=new Ic(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function iw(t,e){t.head=new Ic(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Ic=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}},wf=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},yf=Buffer.alloc(1024),Ds=Symbol("onStat"),oi=Symbol("ended"),ht=Symbol("queue"),ai=Symbol("queue"),cn=Symbol("current"),Pn=Symbol("process"),ci=Symbol("processing"),vs=Symbol("processJob"),xt=Symbol("jobs"),qa=Symbol("jobDone"),ks=Symbol("addFSEntry"),_f=Symbol("addTarEntry"),dc=Symbol("stat"),lc=Symbol("readdir"),Os=Symbol("onreaddir"),Ps=Symbol("pipe"),Ef=Symbol("entry"),Wa=Symbol("entryOpt"),Ls=Symbol("writeEntryClass"),Zf=Symbol("write"),$a=Symbol("ondrain"),Ws=class extends zn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Ls];onWriteEntry;[ht];[ai]=new Map;[xt]=0;[ci]=!1;[oi]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=J(t.prefix||""),this.linkCache=t.linkCache||new Map,this.statCache=t.statCache||new Map,this.readdirCache=t.readdirCache||new Map,this.onWriteEntry=t.onWriteEntry,this[Ls]=Kf,typeof t.onwarn=="function"&&this.on("warn",t.onwarn),this.portable=!!t.portable,t.gzip||t.brotli||t.zstd){if((t.gzip?1:0)+(t.brotli?1:0)+(t.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(t.gzip&&(typeof t.gzip!="object"&&(t.gzip={}),this.portable&&(t.gzip.portable=!0),this.zip=new um(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new xm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new gm(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[$a]()),this.on("resume",()=>e.resume())}else this.on("drain",this[$a]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[ht]=new tw,this[xt]=0,this.jobs=Number(t.jobs)||4,this[ci]=!1,this[oi]=!1}[Zf](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[oi]=!0,this[Pn](),r&&r(),this}write(t){if(this[oi])throw new Error("write after end");return t instanceof Hf?this[_f](t):this[ks](t),this.flowing}[_f](t){let e=J(mf.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new wf(t.path,e);r.entry=new Qm(t,this[Wa](r)),r.entry.on("end",()=>this[qa](r)),this[xt]+=1,this[ht].push(r)}this[Pn]()}[ks](t){let e=J(mf.resolve(this.cwd,t));this[ht].push(new wf(t,e)),this[Pn]()}[dc](t){t.pending=!0,this[xt]+=1;let e=this.follow?"stat":"lstat";Bs[e](t.absolute,(r,i)=>{t.pending=!1,this[xt]-=1,r?this.emit("error",r):this[Ds](t,i)})}[Ds](t,e){if(this.statCache.set(t.absolute,e),t.stat=e,!this.filter(t.path,e))t.ignore=!0;else if(e.isFile()&&e.nlink>1&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync)if(t===this[cn])this[vs](t);else{let r=`${e.dev}:${e.ino}`,i=this[ai].get(r);i?i.push(t):this[ai].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Pn]()}[lc](t){t.pending=!0,this[xt]+=1,Bs.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[xt]-=1,e)return this.emit("error",e);this[Os](t,r)})}[Os](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Pn]()}[Pn](){if(!this[ci]){this[ci]=!0;for(let t=this[ht].head;t&&this[xt]<this.jobs;t=t.next)if(this[vs](t.value),t.value.ignore){let e=t.next;this[ht].removeNode(t),t.next=e}this[ci]=!1,this[oi]&&this[ht].length===0&&this[xt]===0&&(this.zip?this.zip.end(yf):(super.write(yf),super.end()))}}get[cn](){return this[ht]&&this[ht].head&&this[ht].head.value}[qa](t){this[ht].shift(),this[xt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[ai].get(r);if(i){this[ai].delete(r);for(let o of i)o.pending=!1,this[vs](o)}}this[Pn]()}[vs](t){if(t.pending&&t.pendingLink&&t===this[cn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[cn]&&!t.piped&&this[Ps](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Ds](t,e):this[dc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[Os](t,e):this[lc](t),!t.readdir)return}if(t.entry=this[Ef](t),!t.entry){t.ignore=!0;return}t===this[cn]&&!t.piped&&this[Ps](t)}}}[Wa](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}}[Ef](t){this[xt]+=1;try{return new this[Ls](t.path,this[Wa](t)).on("end",()=>this[qa](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[$a](){this[cn]&&this[cn].entry&&this[cn].entry.resume()}[Ps](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[ks](c+i)});let e=t.entry,r=this.zip;if(!e)throw new Error("cannot pipe without source");r?e.on("data",i=>{r.write(i)||e.pause()}):e.on("data",i=>{super.write(i)||e.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(t,e,r={}){Hs(this,t,e,r)}},Ac=class extends Ws{sync=!0;constructor(t){super(t),this[Ls]=Xm}pause(){}resume(){}[dc](t){let e=this.follow?"statSync":"lstatSync";this[Ds](t,Bs[e](t.absolute))}[lc](t){this[Os](t,Bs.readdirSync(t.absolute))}[Ps](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[ks](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[Zf](i)})}},sw=(t,e)=>{let r=new Ac(t),i=new Nf(t.file,{mode:t.mode||438});r.pipe(i),Vf(r,e)},ow=(t,e)=>{let r=new Ws(t),i=new Gs(t.file,{mode:t.mode||438});r.pipe(i);let o=new Promise((c,d)=>{i.on("error",d),i.on("close",c),r.on("error",d)});return Jf(r,e).catch(c=>r.emit("error",c)),o},Vf=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?mr({file:Mf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},Jf=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await mr({file:Mf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},aw=(t,e)=>{let r=new Ac(t);return Vf(r,e),r},cw=(t,e)=>{let r=new Ws(t);return Jf(r,e).catch(i=>r.emit("error",i)),r},g2=Ei(sw,ow,aw,cw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),lw=process.env.__FAKE_PLATFORM__||process.platform,eu=lw==="win32",{O_CREAT:tu,O_NOFOLLOW:bf,O_TRUNC:nu,O_WRONLY:ru}=Qf.constants,iu=Number(process.env.__FAKE_FS_O_FILENAME__)||Qf.constants.UV_FS_O_FILEMAP||0,fw=eu&&!!iu,uw=512*1024,hw=iu|nu|tu|ru,vf=!eu&&typeof bf=="number"?bf|nu|tu|ru:null,su=vf!==null?()=>vf:fw?t=>t<uw?hw:"w":()=>"w",fc=(t,e,r)=>{try{return $s.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},Fs=(t,e,r,i)=>{$s.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},xw=(t,e,r,i,o)=>{if(e.isDirectory())ou(xi.resolve(t,e.name),r,i,c=>{if(c)return o(c);let d=xi.resolve(t,e.name);Fs(d,r,i,o)});else{let c=xi.resolve(t,e.name);Fs(c,r,i,o)}},ou=(t,e,r,i)=>{$s.readdir(t,{withFileTypes:!0},(o,c)=>{if(o){if(o.code==="ENOENT")return i();if(o.code!=="ENOTDIR"&&o.code!=="ENOTSUP")return i(o)}if(o||!c.length)return Fs(t,e,r,i);let d=c.length,f=null,h=x=>{if(!f){if(x)return i(f=x);if(--d===0)return Fs(t,e,r,i)}};for(let x of c)xw(t,x,e,r,h)})},pw=(t,e,r,i)=>{e.isDirectory()&&au(xi.resolve(t,e.name),r,i),fc(xi.resolve(t,e.name),r,i)},au=(t,e,r)=>{let i;try{i=$s.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return fc(t,e,r);throw c}for(let o of i)pw(t,o,e,r);return fc(t,e,r)},cu=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"}},Ks=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"}},mw=(t,e)=>{et.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new cu(t,r?.code||"ENOTDIR")),e(r)})},ww=(t,e,r)=>{t=J(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,d=e.uid,f=e.gid,h=typeof d=="number"&&typeof f=="number"&&(d!==e.processUid||f!==e.processGid),x=e.preserve,m=e.unlink,g=J(e.cwd),A=(E,I)=>{E?r(E):I&&h?ou(I,d,f,S=>A(S)):c?et.chmod(t,o,r):r()};if(t===g)return mw(t,A);if(x)return gw.mkdir(t,{mode:o,recursive:!0}).then(E=>A(null,E??void 0),A);let w=J(Us.relative(g,t)).split("/");uc(g,w,o,m,g,void 0,A)},uc=(t,e,r,i,o,c,d)=>{if(e.length===0)return d(null,c);let f=e.shift(),h=J(Us.resolve(t+"/"+f));et.mkdir(h,r,du(h,e,r,i,o,c,d))},du=(t,e,r,i,o,c,d)=>f=>{f?et.lstat(t,(h,x)=>{if(h)h.path=h.path&&J(h.path),d(h);else if(x.isDirectory())uc(t,e,r,i,o,c,d);else if(i)et.unlink(t,m=>{if(m)return d(m);et.mkdir(t,r,du(t,e,r,i,o,c,d))});else{if(x.isSymbolicLink())return d(new Ks(t,t+"/"+e.join("/")));d(f)}}):(c=c||t,uc(t,e,r,i,o,c,d))},yw=t=>{let e=!1,r;try{e=et.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new cu(t,r??"ENOTDIR")}},_w=(t,e)=>{t=J(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,d=e.gid,f=typeof c=="number"&&typeof d=="number"&&(c!==e.processUid||d!==e.processGid),h=e.preserve,x=e.unlink,m=J(e.cwd),g=E=>{E&&f&&au(E,c,d),o&&et.chmodSync(t,i)};if(t===m)return yw(m),g();if(h)return g(et.mkdirSync(t,{mode:i,recursive:!0})??void 0);let A=J(Us.relative(m,t)).split("/"),w;for(let E=A.shift(),I=m;E&&(I+="/"+E);E=A.shift()){I=J(Us.resolve(I));try{et.mkdirSync(I,i),w=w||I}catch{let S=et.lstatSync(I);if(S.isDirectory())continue;if(x){et.unlinkSync(I),et.mkdirSync(I,i),w=w||I;continue}else if(S.isSymbolicLink())return new Ks(I,I+"/"+A.join("/"))}}return g(w)},Ka=Object.create(null),Sf=1e4,cr=new Set,Ew=t=>{cr.has(t)?cr.delete(t):Ka[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),cr.add(t);let e=Ka[t],r=cr.size-Sf;if(r>Sf/10){for(let i of cr)if(cr.delete(i),delete Ka[i],--r<=0)break}return e},bw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,vw=bw==="win32",Sw=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=lu(i,r)),e.push(r||"/"),e},[]),Iw=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=vw?["win32 parallelization disabled"]:t.map(i=>hi(lu(Ew(i))));let r=new Set(t.map(i=>Sw(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let d=this.#e.get(c);if(!d||d?.[0]!==t)continue;let f=d[1];if(!f){this.#e.delete(c);continue}if(d.shift(),typeof f=="function")o.add(f);else for(let h of f)o.add(h)}for(let c of i){let d=this.#e.get(c),f=d?.[0];if(!(!d||!(f instanceof Set)))if(f.size===1&&d.length===1){this.#e.delete(c);continue}else if(f.size===1){d.shift();let h=d[0];typeof h=="function"&&o.add(h)}else f.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},Aw=()=>process.umask(),If=Symbol("onEntry"),hc=Symbol("checkFs"),Af=Symbol("checkFs2"),xc=Symbol("isReusable"),ot=Symbol("makeFs"),pc=Symbol("file"),gc=Symbol("directory"),Ns=Symbol("link"),Tf=Symbol("symlink"),Rf=Symbol("hardlink"),fi=Symbol("ensureNoSymlink"),Cf=Symbol("unsupported"),Df=Symbol("checkPath"),Za=Symbol("stripAbsolutePath"),hn=Symbol("mkdir"),ze=Symbol("onError"),Ss=Symbol("pending"),kf=Symbol("pend"),dr=Symbol("unpend"),Va=Symbol("ended"),Ja=Symbol("maybeClose"),mc=Symbol("skip"),pi=Symbol("doChown"),gi=Symbol("uid"),mi=Symbol("gid"),wi=Symbol("checkedCwd"),Tw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,yi=Tw==="win32",Rw=1024,Cw=(t,e)=>{if(!yi)return re.unlink(t,e);let r=t+".DELETE."+Xf(16).toString("hex");re.rename(t,r,i=>{if(i)return e(i);re.unlink(r,e)})},Dw=t=>{if(!yi)return re.unlinkSync(t);let e=t+".DELETE."+Xf(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},Of=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Tc=class extends _i{[Va]=!1;[wi]=!1;[Ss]=0;reservations=new Iw;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[Va]=!0,this[Ja]()},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:Rw,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||yi,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=J(Pe.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:Aw():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[If](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[Ja](){this[Va]&&this[Ss]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[Za](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=vc(r),d=c.replaceAll(/\\/g,"/").split("/");if(d.includes("..")||yi&&/^[a-z]:\.\.$/i.test(d[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let f=Pe.posix.dirname(t.path),h=Pe.posix.normalize(Pe.posix.join(f,d.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}[Df](t){let e=J(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=J(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}r.splice(0,this.strip),t.path=r.join("/")}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[Za](t,"path")||!this[Za](t,"linkpath"))return!1;if(t.absolute=Pe.isAbsolute(t.path)?J(Pe.resolve(t.path)):J(Pe.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:J(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=Pe.win32.parse(String(t.absolute));t.absolute=i+uf(String(t.absolute).slice(i.length));let{root:o}=Pe.win32.parse(t.path);t.path=o+uf(t.path.slice(o.length))}return!0}[If](t){if(!this[Df](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[hc](t);default:return this[Cf](t)}}[ze](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[dr](),e.resume())}[hn](t,e,r){ww(J(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},r)}[pi](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}[gi](t){return Of(this.uid,t.uid,this.processUid)}[mi](t){return Of(this.gid,t.gid,this.processGid)}[pc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Gs(String(t.absolute),{flags:su(t.size),mode:r,autoClose:!1});i.on("error",f=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[ze](f,t),e()});let o=1,c=f=>{if(f){i.fd&&re.close(i.fd,()=>{}),this[ze](f,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,h=>{h?this[ze](h,t):this[dr](),e()})};i.on("finish",()=>{let f=String(t.absolute),h=i.fd;if(typeof h=="number"&&t.mtime&&!this.noMtime){o++;let x=t.atime||new Date,m=t.mtime;re.futimes(h,x,m,g=>g?re.utimes(f,x,m,A=>c(A&&g)):c())}if(typeof h=="number"&&this[pi](t)){o++;let x=this[gi](t),m=this[mi](t);typeof x=="number"&&typeof m=="number"&&re.fchown(h,x,m,g=>g?re.chown(f,x,m,A=>c(A&&g)):c())}c()});let d=this.transform&&this.transform(t)||t;d!==t&&(d.on("error",f=>{this[ze](f,t),e()}),t.pipe(d)),d.pipe(i)}[gc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[hn](String(t.absolute),r,i=>{if(i){this[ze](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[dr](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[pi](t)&&(o++,re.chown(String(t.absolute),Number(this[gi](t)),Number(this[mi](t)),c)),c()})}[Cf](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Tf](t,e){let r=J(Pe.relative(this.cwd,Pe.resolve(Pe.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[fi](t,this.cwd,r,()=>this[Ns](t,String(t.linkpath),"symlink",e),i=>{this[ze](i,t),e()})}[Rf](t,e){let r=J(Pe.resolve(this.cwd,String(t.linkpath))),i=J(String(t.linkpath)).split("/");this[fi](t,this.cwd,i,()=>this[Ns](t,r,"link",e),o=>{this[ze](o,t),e()})}[fi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let d=Pe.resolve(e,c);re.lstat(d,(f,h)=>{if(f)return i();if(h?.isSymbolicLink())return o(new Ks(d,Pe.resolve(d,r.join("/"))));this[fi](t,d,r,i,o)})}[kf](){this[Ss]++}[dr](){this[Ss]--,this[Ja]()}[mc](t){this[dr](),t.resume()}[xc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!yi}[hc](t){this[kf]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Af](t,r))}[Af](t,e){let r=d=>{e(d)},i=()=>{this[hn](this.cwd,this.dmode,d=>{if(d){this[ze](d,t),r();return}this[wi]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let d=J(Pe.dirname(String(t.absolute)));if(d!==this.cwd)return this[hn](d,this.dmode,f=>{if(f){this[ze](f,t),r();return}c()})}c()},c=()=>{re.lstat(String(t.absolute),(d,f)=>{if(f&&(this.keep||this.newer&&f.mtime>(t.mtime??f.mtime))){this[mc](t),r();return}if(d||this[xc](t,f))return this[ot](null,t,r);if(f.isDirectory()){if(t.type==="Directory"){let h=this.chmod&&t.mode&&(f.mode&4095)!==t.mode,x=m=>this[ot](m??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[ot](h??null,t,r))}if(t.absolute===this.cwd)return this[ot](null,t,r);Cw(String(t.absolute),h=>this[ot](h??null,t,r))})};this[wi]?o():i()}[ot](t,e,r){if(t){this[ze](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[pc](e,r);case"Link":return this[Rf](e,r);case"SymbolicLink":return this[Tf](e,r);case"Directory":case"GNUDumpDir":return this[gc](e,r)}}[Ns](t,e,r,i){re[r](e,String(t.absolute),o=>{o?this[ze](o,t):(this[dr](),t.resume()),i()})}},di=t=>{try{return[null,t()]}catch(e){return[e,null]}},fu=class extends Tc{sync=!0;[ot](t,e){return super[ot](t,e,()=>{})}[hc](t){if(!this[wi]){let o=this[hn](this.cwd,this.dmode);if(o)return this[ze](o,t);this[wi]=!0}if(t.absolute!==this.cwd){let o=J(Pe.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[hn](o,this.dmode);if(c)return this[ze](c,t)}}let[e,r]=di(()=>re.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[mc](t);if(e||this[xc](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,[d]=c?di(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ot](d,t)}let[o]=di(()=>re.rmdirSync(String(t.absolute)));this[ot](o,t)}let[i]=t.absolute===this.cwd?[]:di(()=>Dw(String(t.absolute)));this[ot](i,t)}[pc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=d=>{let f;try{re.closeSync(o)}catch(h){f=h}(d||f)&&this[ze](d||f,t),e()},o;try{o=re.openSync(String(t.absolute),su(t.size),r)}catch(d){return i(d)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",d=>this[ze](d,t)),t.pipe(c)),c.on("data",d=>{try{re.writeSync(o,d,0,d.length)}catch(f){i(f)}}),c.on("end",()=>{let d=null;if(t.mtime&&!this.noMtime){let f=t.atime||new Date,h=t.mtime;try{re.futimesSync(o,f,h)}catch(x){try{re.utimesSync(String(t.absolute),f,h)}catch{d=x}}}if(this[pi](t)){let f=this[gi](t),h=this[mi](t);try{re.fchownSync(o,Number(f),Number(h))}catch(x){try{re.chownSync(String(t.absolute),Number(f),Number(h))}catch{d=d||x}}}i(d)})}[gc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[hn](String(t.absolute),r);if(i){this[ze](i,t),e();return}if(t.mtime&&!this.noMtime)try{re.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[pi](t))try{re.chownSync(String(t.absolute),Number(this[gi](t)),Number(this[mi](t)))}catch{}e(),t.resume()}[hn](t,e){try{return _w(J(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(r){return r}}[fi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let d of r){c=Pe.resolve(c,d);let[f,h]=di(()=>re.lstatSync(c));if(f)return i();if(h.isSymbolicLink())return o(new Ks(c,Pe.resolve(e,r.join("/"))))}i()}[Ns](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)}}},kw=t=>{let e=new fu(t),r=t.file,i=Yf.statSync(r),o=t.maxReadSize||16*1024*1024;new Yg(r,{readSize:o,size:i.size}).pipe(e)},Ow=(t,e)=>{let r=new Tc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("close",c),Yf.stat(o,(f,h)=>{if(f)d(f);else{let x=new yc(o,{readSize:i,size:h.size});x.on("error",d),x.pipe(r)}})})},uu=Ei(kw,Ow,t=>new fu(t),t=>new Tc(t),(t,e)=>{e?.length&&qf(t,e)}),Pw=(t,e)=>{let r=new Ac(t),i=!0,o,c;try{try{o=Qe.openSync(t.file,"r+")}catch(h){if(h?.code==="ENOENT")o=Qe.openSync(t.file,"w+");else throw h}let d=Qe.fstatSync(o),f=Buffer.alloc(512);e:for(c=0;c<d.size;c+=512){for(let m=0,g=0;m<512;m+=g){if(g=Qe.readSync(o,f,m,f.length-m,c+m),c===0&&f[0]===31&&f[1]===139)throw new Error("cannot append to compressed archives");if(!g)break e}let h=new Bn(f);if(!h.cksumValid)break;let x=512*Math.ceil((h.size||0)/512);if(c+x+512>d.size)break;c+=x,t.mtimeCache&&h.mtime&&t.mtimeCache.set(String(h.path),h.mtime)}i=!1,Lw(t,r,c,o,e)}finally{if(i)try{Qe.closeSync(o)}catch{}}},Lw=(t,e,r,i,o)=>{let c=new Nf(t.file,{fd:i,start:r});e.pipe(c),Mw(e,o)},Nw=(t,e)=>{e=Array.from(e);let r=new Ws(t),i=(o,c,d)=>{let f=(A,w)=>{A?Qe.close(o,E=>d(A)):d(null,w)},h=0;if(c===0)return f(null,0);let x=0,m=Buffer.alloc(512),g=(A,w)=>{if(A||w===void 0)return f(A);if(x+=w,x<512&&w)return Qe.read(o,m,x,m.length-x,h+x,g);if(h===0&&m[0]===31&&m[1]===139)return f(new Error("cannot append to compressed archives"));if(x<512)return f(null,h);let E=new Bn(m);if(!E.cksumValid)return f(null,h);let I=512*Math.ceil((E.size??0)/512);if(h+I+512>c||(h+=I+512,h>=c))return f(null,h);t.mtimeCache&&E.mtime&&t.mtimeCache.set(String(E.path),E.mtime),x=0,Qe.read(o,m,0,512,h,g)};Qe.read(o,m,0,512,h,g)};return new Promise((o,c)=>{r.on("error",c);let d="r+",f=(h,x)=>{if(h&&h.code==="ENOENT"&&d==="r+")return d="w+",Qe.open(t.file,d,f);if(h||!x)return c(h);Qe.fstat(x,(m,g)=>{if(m)return Qe.close(x,()=>c(m));i(x,g.size,(A,w)=>{if(A)return c(A);let E=new Gs(t.file,{fd:x,start:w});r.pipe(E),E.on("error",c),E.on("close",o),Bw(r,e)})})};Qe.open(t.file,d,f)})},Mw=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?mr({file:hu.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},Bw=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await mr({file:hu.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},li=Ei(Pw,Nw,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!sm(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")}),k2=Ei(li.syncFile,li.asyncFile,li.syncNoFile,li.asyncNoFile,(t,e=[])=>{li.validate?.(t,e),zw(t)}),zw=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(r,i)=>e(r,i)&&!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0)):(r,i)=>!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0))};tn();var mt={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",DELETE:"_agent/delete"};function bi(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function xu(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function Rc(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function pu(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function wr(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}qe();ne();ke();qe();function Ht(t,e){if(bi(t)!=="cloud")throw new T("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Zs(t){return t.startsWith("http://")||t.startsWith("https://")}function Vs(t){return t.endsWith("/")?t.slice(0,-1):t}qe();ne();var Js="1008033",gu="1289";var mu="pbbp2",wu="https://www.coze.cn",yu="/api/coze_claw/resource/get_frontier_key",Uw="https://www.coze.cn",Gw="wss://frontier.coze.cn";function Ys(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??Uw}function _u(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??Gw}function yr(t){let e={},r=t?.ttEnv??process.env.COZE_BRIDGE_TT_ENV,i=t?.usePpe??process.env.COZE_BRIDGE_USE_PPE;return r&&(e["x-tt-env"]=r),i&&(e["x-use-ppe"]=i),e}function Si(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var vi=G("handshake");async function Cc(t){let e=Ys(t.endpoint),r=t.timeoutMs??1e4,i=`${Vs(e)}${yu}?aid=${encodeURIComponent(Js)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...yr(t.ppeOverride)},c=new AbortController,d=setTimeout(()=>c.abort(),r);vi.info("frontier key handshake",{base:e});try{let f=await fetch(i,{method:"GET",headers:o,signal:c.signal}),h=f.headers.get("x-tt-logid")??"",x=f.headers.get("x-tt-trace-id")??"";if(!f.ok){let E=await f.text().catch(()=>"");throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${f.status} logid=${h}: ${E.slice(0,200)}`)}let m=await f.json();if(m.code!==void 0&&m.code!==0)throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${m.code} msg=${m.msg??"-"} logid=${h}`);let g=m.data??{},A=typeof g.access_key=="string"&&g.access_key||typeof g.accessKey=="string"&&g.accessKey||void 0,w=typeof g.device_id=="string"&&g.device_id||typeof g.deviceId=="string"&&g.deviceId||void 0;if(!A||!w){let E=JSON.stringify(m).slice(0,500);throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${h}: ${E}`)}return vi.info("handshake ok",{remoteDeviceId:w,logid:h,traceId:x}),{accessKey:A,deviceId:w}}catch(f){if(f instanceof T)throw vi.error("handshake failed (bridge error)",{base:e,message:f.message,code:f.code}),f;if(f.name==="AbortError")throw vi.warn("handshake timeout",{base:e,timeoutMs:r}),new T("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:f});let h=f.cause;throw vi.error("handshake error",{base:e,message:f instanceof Error?f.message:String(f),errno:h?.code,syscall:h?.syscall,cause:String(f).slice(0,300)}),new T("UPSTREAM_HANDSHAKE_FAILED",String(f),{cause:f})}finally{clearTimeout(d)}}var Dc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",wt="auto",Eu=2e5;function bu(t){return{model:kc(t.model)??wt,...t.modelToken?{modelToken:t.modelToken}:{}}}function vu(t){return!t||t===wt}var jw=new Set(["auto","\u81EA\u52A8"]);function kc(t){let e=t?.trim();if(e)return jw.has(e.toLowerCase())?wt:e}function Su(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Dc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||wt;e.ANTHROPIC_MODEL=r,e.ANTHROPIC_SMALL_FAST_MODEL=r,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=r,e.ANTHROPIC_DEFAULT_OPUS_MODEL=r,e.ANTHROPIC_DEFAULT_SONNET_MODEL=r,e.CLAUDE_CODE_SUBAGENT_MODEL=r,t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else vu(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Iu(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||wt}"`):vu(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="${Dc}/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??Eu;e.push("-c",`model_context_window=${r}`)}return e}function Au(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function Oc(t,e){let{ttEnv:r,usePpe:i}=Si(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Tu(t,e,r){if(!t.modelToken)return{};let i=Oc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,d])=>`${c}:${d}`).join(`
92
+ `)}}function Pc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function Ru(t,e,r){if(!t.modelToken)return null;let i=t.model||wt,o=Oc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let d={baseUrl:`${Dc}/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??Eu,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(d.headers=o),d}function Cu(t,e,r){if(!t.modelToken)return[];let i=Oc(e,r),o=[];for(let[c,d]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${d}"`);return o}var Le=G("agent-handlers"),Du=5*1024*1024,Zw=1,Vw=6,Jw=new Set(["node_modules",".git",".coze","dist","build",".next"]),Xs=class{constructor(e){this.opts=e}opts;async listSkills(e){Ht(e._meta,"_agent/listSkills");let r=wr(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Ze(r).workspace,c=i?.skills??[],d=[];for(let f of c){let h=Ct(o,f.relPath,"SKILL.md");await Ww(h).then(m=>m.isFile()).catch(()=>!1)&&d.push(ty(f))}return{skills:d}}async addSkills(e){Ht(e._meta,"_agent/addSkills");let r=wr(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],d=new Map(c.map((h,x)=>[h.skillId,x])),f=[];for(let h of o){let x=await Uc({agentId:r,workspace:i.workspace,framework:i.framework,skill:h});Gc(c,d,x),f.push(h)}return await rs(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:f}}async removeSkills(e){Ht(e._meta,"_agent/removeSkills");let r=wr(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],d=[];for(let f of c){if(!o.has(f.skillId)){d.push(f);continue}let h=Ct(i.workspace,f.relPath);await qw(h,{recursive:!0,force:!0}),Le.info("skill removed",{agentId:r,skillId:f.skillId,relPath:f.relPath})}return await rs(r,d),this.reloadAgentSessions(r,"skills-removed"),{ok:!0}}reloadAgentSessionsPublic(e,r){this.reloadAgentSessions(e,r)}reloadAgentSessions(e,r){let i=this.opts.agents.get(e);if(i)for(let[o,c]of i.sessions){if(!c.downstream)continue;let d=c.acpSessionId;if(d&&i.activeTriggers.has(d)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,Le.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d});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:d}),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 Ge(r);if(!i)throw new T("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 tr(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 T("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Ve(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 T("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Ge(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Ve(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(Ht(e._meta,"_agent/switchModel"),!e.agentId)throw new T("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=kc(e.model)??wt,i=await Ge(e.agentId);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Ve(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(d=>Le.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(d)}));let c=[];for(let[d,f]of o.allSessionQueues())c.push(f.enqueue(async()=>{let h=o.sessions.get(d);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(Ht(e._meta,mt.RESET),!e.agentId)throw new T("IPC_BAD_REQUEST",`${mt.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,mt.RESET),await this.runDetailSync(e.agentId,mt.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),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,d]of i.sessions)o.set(c,{modelToken:d.modelToken,tokenGeneratedAt:d.tokenGeneratedAt});await Vr(e,o)}async clearPersistedAcpSessionIds(e){let r=await Ge(e).catch(()=>null);if(!r?.sessions)return;let i=!1;for(let o of Object.values(r.sessions))o.acpSessionId&&(o.acpSessionId=void 0,i=!0);i&&await Ve(r)}async repairAgent(e){if(Ht(e._meta,mt.REPAIR),!e.agentId)throw new T("IPC_BAD_REQUEST",`${mt.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new T("IPC_BAD_REQUEST",`${mt.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){Le.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,mt.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){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){Ht(e._meta,"_agent/getFileTree");let r=e._meta,i=wr(r),o=await this.resolveWorkspace(i),c=e.filePath??"",d=this.safeJoin(o,c),f=await Lc(d).catch(()=>null);if(!f)throw new T("IPC_BAD_REQUEST",`path not found: ${c}`);if(f.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await Zr(d,o))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let h=uy(e.depth);return f.isDirectory()?{tree:await fy(o,d,c,h)}:{tree:[{name:hy(c),path:Bu(c||"."),isDir:!1,size:f.size,modifiedAt:Math.floor(f.mtimeMs)}]}}async getFileContent(e){Ht(e._meta,"_agent/getFileContent");let r=wr(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new T("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await Lc(o).catch(()=>null);if(!c||!c.isFile())throw new T("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await Zr(o,i))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Du)throw new T("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Du})`);let d=await ku(o);return d.includes(0)?{content:d.toString("base64"),encoding:"base64",size:c.size}:{content:d.toString("utf8"),encoding:"utf-8",size:c.size}}async resolveWorkspace(e){let r=this.opts.agents.get(e);return r?r.workspace:(await Ge(e).catch(()=>null))?.workspace??Ze(e).workspace}safeJoin(e,r){let i=Bc(e,r||"."),o=Fc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Ou}`))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return Ge(e)}async requireAgentCfg(e){let r=await this.loadAgentCfg(e);if(!r)throw new T("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function Yw(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new T("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new T("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function Xw(t){return t==="claude-code"?Ct(".claude","skills"):Ct(".agents","skills")}var Qw=3e4,ey=50*1024*1024,_r=3e4;async function Uc(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new T("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,d=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!d)throw new T("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let f=Yw(o.skillName),h=Xw(i),x=Ct(h,f),m=Ct(r,x);if(await Nc(m,{recursive:!0}),c){let A=Buffer.from(o.content,"utf8");Ii(A.length),await Mc(Ct(m,"SKILL.md"),A,"utf8")}else{let A=await ny(o.downloadUrl);iy(A)?await cy(A,m):sy(A)?await oy(A,m):await Mc(Ct(m,"SKILL.md"),A.toString("utf8"),"utf8")}let g={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"}),g}function Gc(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 ty(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 ny(t){if(!t)throw new T("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Ii(e);let r=ry(t);return Ii(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await ku(e);return Ii(r.length),r}if(Zs(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),Qw);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new T("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Ii(o.byteLength),Buffer.from(o)}finally{clearTimeout(r)}}throw new T("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Ii(t){if(t>ey)throw new T("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function ry(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new T("IPC_BAD_REQUEST","bad data URL");let r=!!e[2],i=e[3]??"";return r?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function iy(t){return t.length>=2&&t[0]===31&&t[1]===139}function sy(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 zc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function oy(t,e){let r,i;try{r=new Nu.default(t),i=r.getEntries()}catch(d){throw new T("IPC_BAD_REQUEST",`zip parse failed: ${d.message}`,{cause:d})}for(let d of i){let f=d.entryName;if(!f||zc(f))continue;if(f.startsWith("/")||/^[A-Za-z]:[\\/]/.test(f))throw new T("IPC_BAD_REQUEST",`zip entry absolute path: ${f}`);if(f.split(/[/\\]/).some(x=>x===".."))throw new T("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${f}`);let h=d.header.attr>>>16&61440;if(h!==0&&h!==32768&&h!==16384)throw new T("IPC_BAD_REQUEST",`zip entry kind 0x${h.toString(16)} not allowed (symlink/hardlink/special): ${f}`)}let o=ay(i),c=Bc(e);for(let d of i){if(zc(d.entryName))continue;let f=d.entryName;if(o&&f.startsWith(o)&&(f=f.slice(o.length)),!f)continue;let h=Bc(e,f),x=Fc(c,h);if(x.startsWith("..")||x==="..")throw new T("IPC_BAD_REQUEST",`zip entry escapes destDir: ${f}`);if(d.isDirectory){await Nc(h,{recursive:!0});continue}await Nc($w(h),{recursive:!0});let m;try{m=d.getData()}catch(g){throw new T("IPC_BAD_REQUEST",`zip entry getData failed (${d.entryName}): ${g.message}`,{cause:g})}await Mc(h,m)}}function ay(t){let e;for(let r of t){let i=r.entryName;if(!i||zc(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 cy(t,e){await dy(t);let r=uu({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar extract timeout (${_r}ms)`))},_r);try{await Lu(Pu.from(t),r)}catch(c){throw c instanceof T?c:i?new T("IPC_BAD_REQUEST",`tar extract timeout (${_r}ms)`):new T("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function dy(t){let e=[],r=mr({onReadEntry:c=>{let d=c.path,f=c.type;if(f!=="File"&&f!=="Directory"){e.push(`tar entry kind '${f}' not allowed (symlink/hardlink/special): ${d.slice(0,100)}`);return}if(d.startsWith("/")||d.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(d)){e.push(`tar entry absolute path: ${d}`);return}d.split(/[/\\]/).some(x=>x==="..")&&e.push(`tar entry contains '..': ${d}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar list timeout (${_r}ms)`))},_r);try{await Lu(Pu.from(t),r)}catch(c){throw i?new T("IPC_BAD_REQUEST",`tar list timeout (${_r}ms)`):new T("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new T("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var ly=5e3;async function fy(t,e,r,i){return Mu(t,e,r,i,{count:0})}async function Mu(t,e,r,i,o){if(i<=0)return[];let c;try{c=await Hw(e,{withFileTypes:!0})}catch{return[]}let d=[];for(let f of c){if(Jw.has(f.name)||f.isSymbolicLink())continue;if(o.count>=ly){d.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let h=Ct(e,f.name),x=Kw(Ct(r,f.name)),m=null;try{m=await Lc(h)}catch{continue}if(m.isSymbolicLink())continue;o.count++;let g={name:f.name,path:Bu(Fc(t,h)),isDir:m.isDirectory(),size:m.size,modifiedAt:Math.floor(m.mtimeMs)};m.isDirectory()&&i>1&&(g.children=await Mu(t,h,x,i-1,o)),d.push(g)}return d.sort((f,h)=>f.isDir!==h.isDir?f.isDir?-1:1:f.name.localeCompare(h.name)),d}function uy(t){return!t||t<=0?Zw:Math.min(t,Vw)}function hy(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function Bu(t){return t.split(Ou).join("/")}ne();import{readFileSync as GI}from"node:fs";import{dirname as HI,join as qI}from"node:path";import{fileURLToPath as $I}from"node:url";var Er="0.1.98-alpha.2";var gn=G("agent-health-reporter"),xy=1e4,Ai=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??xy}opts;timer=null;inFlight=!1;unsubscribeRegister=null;intervalMs;start(){this.timer||(this.timer=setInterval(()=>{this.tick()},this.intervalMs),this.timer.unref?.(),this.unsubscribeRegister=this.opts.core.onAgentRegister(()=>{this.tick()}),gn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),gn.info("heartbeat stopped"))}async tick(){if(this.inFlight){gn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){gn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let r=[];for(let d of this.opts.core.agents.values()){let f=py(d);if(!f)continue;let h={agentId:d.agentId,status:f};d.patToken&&(h.patToken=d.patToken),d.accountId&&(h.accountId=d.accountId),r.push(h)}if(r.length===0)return;let i={agents:r,bridgeVersion:Er,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(d){gn.warn("heartbeat batch send failed",{count:r.length,err:String(d)})}let c=o?.authFailures;if(c&&c.length>0&&(gn.warn("heartbeat received authFailures from cloud",{count:c.length,agentIds:c.map(d=>d.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(c)}catch(d){gn.warn("onAuthFailures callback failed (ignored)",{err:String(d)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){gn.warn("onTickEnd hook failed",{err:String(r)})}}};function py(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}tn();import{chmod as a_,mkdir as ao,rm as c_,stat as d_,writeFile as l_}from"node:fs/promises";import{homedir as f_}from"node:os";import{join as i0}from"node:path";en();import{spawnSync as Oy}from"node:child_process";import{existsSync as Py}from"node:fs";import{release as Ly}from"node:os";import{basename as Ny,isAbsolute as My}from"node:path";function Ti(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function br(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function vr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function mn(t,e){return{jsonrpc:"2.0",id:t,error:e}}qe();var Qs=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 zu(t){return"method"in t&&"id"in t&&t.id!==void 0}function Fu(t){return"method"in t&&!("id"in t)}function eo(t){return!("method"in t)&&"id"in t}var gy={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 my(t){if(t!=null)return t instanceof Error?{name:t.name,message:Ri(t.message)}:typeof t=="string"?Ri(t):typeof t=="object"?yy(t):t}var wy=[[/\/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 Ri(t){let e=t;for(let[r,i]of wy)e=e.replace(r,i);return e}function yy(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Ri(i):e[r]=i;return e}function Ci(t){if(t instanceof T){let e=my(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:gy[t.code]??Q.INTERNAL_ERROR,message:Ri(t.message),data:r}}return{code:Q.INTERNAL_ERROR,message:Ri(t instanceof Error?t.message:String(t))}}function Uu(t){let e=t.data,r=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:d,...f}=e;c=f}return new T(r,o,{retriable:e?.retriable??!1,cause:c})}function ju(t){return`${JSON.stringify(t)}
93
+ `}var Gu=10*1024*1024,to=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>Gu){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${Gu} bytes`)}),[]}let r=this.buffer.split(`
94
+ `);this.buffer=r.pop()??"";let i=[];for(let o of r){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(d){this.onError?.({line:c,error:d})}}return i}flush(){if(!this.buffer)return[];let e=this.buffer.replace(/\r$/,"").trim();if(this.buffer="",!e)return[];try{return[JSON.parse(e)]}catch(r){return this.onError?.({line:e,error:r}),[]}}};var qu={"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"},rA=Object.fromEntries(Object.entries(qu).map(([t,e])=>[e,t])),_y={"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:[]},Sr=class{seq=0;next(e,r){this.seq+=1;let i=qu[e]??Ey(e),o=_y[i]??[],c=[i,String(this.seq)];if(o.length>0){let d=o.map(h=>Hu(r?.[h]??"")),f=by(d).join(":");f&&c.push(f)}else r&&Object.values(r).some(d=>d)&&c.push(Object.values(r).filter(Boolean).map(d=>Hu(String(d))).join(":"));return c.join("_")}reset(){this.seq=0}};function Ey(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function Hu(t){return t.replace(/[:_\s]+/g,"-")}function by(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}Kr();import{readFileSync as vy}from"node:fs";var Sy=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 er(t.agentEnvFile,r,{mode:Sy})}function Hc(t){try{let e=JSON.parse(vy(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function Wu(t,e,r={},i=o=>o){return{...i({...t,...Hc(e)}),...r}}wn();Vi();qe();ne();ke();var ky=[{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/i,message:"openclaw gateway \u672A\u8FD0\u884C (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2)\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 Vu(t,e){if(!e)return null;for(let r of ky)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}var By=Mt("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),zy=200,Fy=40,Uy=Mt("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),Gy=Mt("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),jy=Mt("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),Ju=500;function Hy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=Ju?t:`${e.slice(0,Ju)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Yu(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),Oy("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}function Xu(t){try{return Py(t)}catch{return}}function qy(t,e){return{platform:process.platform,osRelease:Ly(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:My(e.command)?Xu(e.command):void 0,cwd:e.cwd,cwdExists:Xu(e.cwd),envKeys:e.envKeys}}function Wy(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 Dt=class{constructor(e){this.opts=e;this.log=G(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new to({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Sr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];sanitizeEnv(e){return e}async start(){if(this.child)throw new T("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=Wu(process.env,this.opts.agentEnvFile??Y().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,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>zy&&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,(o!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:c,recentStderr:[...this.stderrRing]});try{for(let f of this.decoder.flush())this.dispatch(f)}catch(f){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(f)})}this.failAllPending(this.buildExitError(o,c));for(let f of this.exitHandlers)f(o,c)}),i.on("error",o=>{let c=o,d=qy(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(r).length});this.log.error("child error",{err:String(o),diag:d}),this.failAllPending(new T("AGENT_SPAWN_FAILED",Wy(c,d),{cause:d}))}),this.log.info("downstream started",{command:this.opts.command,pid:i.pid,cwd:this.opts.cwd})}async stop(e){if(!this.child||this.stopped)return;this.stopped=!0,this.stopReason=e??"stopped",this.log.info("downstream stopping",{reason:e});let r=this.child,i=new Promise(c=>r.once("exit",()=>c()));Yu(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Yu(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=Uy,i=Gy,o=jy){return this.call("session/prompt",e,r,i,o)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(br("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(vr(e,r))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(mn(e,r))}catch(i){this.log.warn("respondAgentRequestError write failed",{id:e,err:String(i)})}}onExit(e){this.exitHandlers.push(e)}call(e,r,i=By,o=0,c=0){if(!this.child||this.stopped)return Promise.reject(new T("AGENT_PROTOCOL_ERROR","downstream not started"));let d=this.idAllocator.next(e),f=Ti(d,e,r),h=(()=>{if(typeof r!="object"||r===null)return;let g=r.sessionId;return typeof g=="string"?g:void 0})(),x=i>0&&Number.isFinite(i),m=o>0&&Number.isFinite(o);return new Promise((g,A)=>{let w={resolve:g,reject:A,timer:null,firstUpdateTimer:null,onFirstUpdate:null,method:e},E=Date.now();if(x){let S=()=>{w.timer=setTimeout(()=>{let R=Date.now()-E;if(this.inflightAgentRequests.size>0&&R<c){this.log.debug("hard cap fired but agent request inflight, extending to approval cap",{id:d,method:e,elapsed:R,approvalMaxMs:c,...h?{sessionId:h}:{}}),S();return}this.pending.delete(d),w.firstUpdateTimer&&clearTimeout(w.firstUpdateTimer);let P=this.inflightAgentRequests.size>0;this.log.warn("downstream call timeout",{id:d,method:e,timeoutMs:i,approvalMaxMs:c,awaitingApproval:P,...h?{sessionId:h}:{}}),A(P?new T("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${c}ms`):new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i)};S()}let I=m?()=>{w.firstUpdateTimer&&clearTimeout(w.firstUpdateTimer),w.firstUpdateTimer=setTimeout(()=>{if(this.inflightAgentRequests.size>0){this.log.debug("first-update wait fired but agent request inflight, re-arming",{id:d,method:e,inflight:this.inflightAgentRequests.size,...h?{sessionId:h}:{}}),I?.();return}w.timer&&clearTimeout(w.timer),this.pending.delete(d),this.log.warn("first session/update timeout, rejecting pending call",{id:d,method:e,firstUpdateMs:o,...h?{sessionId:h}:{}}),A(new T("AGENT_FRAME_IDLE_TIMEOUT",`${e} no first session/update within ${o}ms`))},o)}:null;w.onFirstUpdate=m?()=>{w.firstUpdateTimer&&clearTimeout(w.firstUpdateTimer),w.firstUpdateTimer=null,w.onFirstUpdate=null}:null,this.pending.set(d,w),I?.();try{this.writeFrame(f)}catch(S){w.timer&&clearTimeout(w.timer),w.firstUpdateTimer&&clearTimeout(w.firstUpdateTimer),this.pending.delete(d),A(S)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new T("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(ju(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(eo(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),r.firstUpdateTimer&&clearTimeout(r.firstUpdateTimer),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(Uu(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new T("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:Hy(e.result)}),r.resolve(e.result));return}if(Fu(e)){if(e.method==="session/update"){for(let r of this.pending.values())r.onFirstUpdate?.();for(let r of this.updateHandlers)try{Promise.resolve(r(e.params)).catch(i=>this.log.warn("update handler failed (async)",{err:String(i)}))}catch(i){this.log.warn("update handler threw sync, swallowed",{err:String(i)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(zu(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)})}}}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(mn(e.id,{code:-32601,message:`method not handled by Bridge: ${e.method}`}));return}this.inflightAgentRequests.set(e.id,e.method);for(let r of this.agentRequestHandlers)try{await r(e)}catch(i){this.log.error("agentRequestHandler threw",{method:e.method,err:String(i)});try{this.writeFrame(mn(e.id,Ci(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}buildExitError(e,r){if(this.stopReason!==void 0)return new T("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(Fy).join(`
95
+ `),o=Vu(this.framework,i);return o?new T(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new T("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.firstUpdateTimer&&clearTimeout(r.firstUpdateTimer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function $y(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 no=class extends Dt{framework="claude-code";constructor(e){let{command:r,args:i}=$r("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 $y(e)}};en();import{mkdtempSync as Ky,rmSync as Zy}from"node:fs";import{tmpdir as Vy}from"node:os";import{join as Jy}from"node:path";var ro=class extends Dt{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=$r("codex",e.command,i),d=e.isolateCodexHome?Ky(Jy(Vy(),"coze-bridge-codex-home-")):void 0,f=d?{...e.env??{},CODEX_HOME:d}:e.env,h={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...f?{env:f}:{}};super(h),this.authMethodId=e.authMethodId,this.codexHomeDir=d}async initialize(e){let r=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),r}async stop(e){if(await super.stop(e),this.codexHomeDir)try{Zy(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};var Yy=3e4,Ir=class extends Dt{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.sessionPrompt({sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},Yy))}get acpSessionName(){return this.sessionName}};qe();ne();ke();function qc(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}en();var yn=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 io=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 yn,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)Di(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 Di(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}wn();ne();import{constants as Qu}from"node:fs";import{access as Xy}from"node:fs/promises";import{delimiter as Qy,join as e_}from"node:path";var yt=G("framework-detector"),e0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},t_=[".exe",".cmd",".bat",".ps1"],Fn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??at,access:e.access??Xy}}async detect(e){let r=e0[e],i=await this.which(r);if(!i)return yt.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,d]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),f={path:i,version:c};return d&&(f.defaultAgent=d),f}async detectAll(){let e=await Promise.all(Object.keys(e0).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(Qy).filter(Boolean),i=this.env.platform==="win32"?["",...t_]:[""];for(let o of r)for(let c of i){let d=e_(o,e+c);if(await this.isExecutable(d))return d}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?Qu.F_OK:Qu.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 yt.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return yt.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 yt.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 yt.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(d=>d?.isDefault===!0);return c?!c.id||!c.workspace?(yt.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}:(yt.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return yt.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 yt.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||yt.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let d=JSON.parse(c[0]);typeof d.gateway?.port=="number"&&(o.port=d.gateway.port),typeof d.service?.runtime?.status=="string"&&(o.runtime=d.service.runtime.status),!i&&typeof d.rpc?.error=="string"&&(o.detail=d.rpc.error)}catch(d){yt.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(d)})}return o}async probeVersion(e,r=[]){let i=await this.runProbe(e,[...r,"--version"]);return i&&(r_(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,d,f=h=>{c||(c=!0,d&&clearTimeout(d),i(h))};try{let h=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});d=setTimeout(()=>{h.kill("SIGKILL"),f(null)},15e3),h.stdout?.on("data",x=>{o+=x.toString("utf8")}),h.on("error",()=>f(null)),h.on("close",x=>f({code:x,stdout:o}))}catch{f(null)}})}},n_=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function r_(t){return t.replace(n_,"")}import{homedir as i_}from"node:os";import{join as s_}from"node:path";wn();qe();Kr();ne();async function r0(){let t=s_(i_(),".openclaw/openclaw.json");return(await Qn(t))?.gateway?.auth?.token??""}var t0=G("openclaw.config"),o_=[0,5e3,5e3],n0="models.providers.",so="agents.defaults.models",oo=class{command;env;retryDelaysMs;queue=new yn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??o_}async withRetry(e,r){let i;for(let o=0;o<this.retryDelaysMs.length;o++){let c=this.retryDelaysMs[o]??0;c>0&&await new Promise(d=>setTimeout(d,c));try{return await r()}catch(d){i=d,t0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(d)})}}throw new T("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=at(this.command,e,{stdio:["ignore","pipe","pipe"],env:this.env}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`exit ${d}: ${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){t0.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",`${n0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${n0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${so}[${e}]`,()=>this.runCli(["config","set",so,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${so}[${e}]`,`${so}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var xe=G("agent-manager"),u_=(t,e,r,i,o,c,d,f,h)=>{switch(t){case"claude-code":{let x={...o?{...Su(o),...Tu(o,d,f)}:{},...h??{},IS_SANDBOX:"1"};return new no({cwd:r,env:x,agentId:i})}case"codex":{let m=[...o?[...Iu(o),...Cu(o,d,f)]:[],"-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"'],g={...o?Au(o):{},...h??{}},A=!!o;return new ro({cwd:r,agentId:i,...m.length>0?{extraArgs:m}:{},...Object.keys(g).length>0?{env:g}:{},...A?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Ir({command:e,cwd:r,agentId:i,...c?{sessionName:qc(c)}:{}})}};function Wc(t){return t==="claude-code"||t==="codex"}function h_(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(x_(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
96
96
  `)}
97
- `}function py(t){if(t.includes(`
98
- `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var gy={path:"",version:"cloud-deployed"},of="openclaw_gateway_unavailable",my="openclaw_default_agent_missing";function af(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 wy={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},_y=6e4,fo=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;detectorFactory;openclawEnvBootstrapPromise;openclawConfigFactory;openclawConfigDir;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??xy,this.createTimeoutMs=e.createTimeoutMs??_y,this.detectorFactory=e.detectorFactory??(()=>new Gn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new lo({command:r})),this.openclawConfigDir=e.openclawConfigDir??Vc(fy(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{pe.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=Vc(e,".env");if(await ly(r).then(c=>c.isFile()).catch(()=>!1)){pe.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}await uo(e,{recursive:!0});let o=hy({...process.env,...Kc(this.paths.agentEnvFile)});if(await uy(r,o,"utf8"),process.platform!=="win32")try{await cy(r,384)}catch(c){pe.warn("chmod ~/.openclaw/.env to 0600 failed (ignored)",{err:String(c)})}pe.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),pe.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new T("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new T("IPC_BAD_REQUEST","framework required");let i=Si(e._meta)==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let o=this.registry.get(e.agentId);if(o){if(o.framework!==e.framework)throw new T("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${o.framework})`);if(o.status==="error")pe.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await o.dispose("rebuild after error").catch(S=>pe.warn("dispose stale agent failed (ignored)",{err:String(S)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==o.patToken){pe.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),o.setPatToken(e.patToken);let S=await He(e.agentId,this.paths).catch(()=>null);S&&(S.patToken=e.patToken,await Ye(S,this.paths))}if(o.deployType==="cloud"&&e.modelInfo){pe.info("updating agent modelInfo on re-create",{agentId:e.agentId}),o.setModelInfo(e.modelInfo);let S=await He(e.agentId,this.paths).catch(()=>null);S&&(S.modelInfo=e.modelInfo,await Ye(S,this.paths))}return pe.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:o.agentId,workspace:o.workspace,framework:o.framework}}}if(!i&&!this.config.frameworksCache?.[e.framework])throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let l=$e(e.agentId,this.paths),u=Si(e._meta),x=e.framework==="openclaw"&&u==="local",p;x&&!r?.revive&&(p=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let w=p??(x?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),_=e.workspace??w??l.workspace,I=new AbortController,E=setTimeout(()=>I.abort(new T("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),v,A=!1;try{i&&Jc(e.framework)&&await er(e.framework,I.signal);let S=()=>{if(I.signal.aborted)throw I.signal.reason instanceof Error?I.signal.reason:new T("AGENT_TIMEOUT","_agent/create aborted")};await uo(l.root,{recursive:!0}),await uo(_,{recursive:!0}),await uo(l.logs,{recursive:!0}),S(),x||await rr(_,e.framework,e.cozeIdentity),e.framework==="claude-code"&&await yl(_),S();let C=await He(e.agentId,this.paths).catch(()=>null),P=vu({model:e.model??C?.model}),y=pu(e._meta)??C?.accountId,D=e.patToken??C?.patToken,k=u==="cloud"?e.modelInfo??C?.modelInfo:void 0;if(v=new ao({agentId:e.agentId,framework:e.framework,workspace:_,model:P.model??Et,deployType:u,...y?{accountId:y}:{},...D?{patToken:D}:{},...k?{modelInfo:k}:{}}),v.status="ok",C?.sessions){for(let[V,te]of Object.entries(C.sessions))v.sessions.set(V,{acpSessionId:te.acpSessionId,modelToken:te.modelToken,tokenGeneratedAt:te.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0});let $=Object.keys(C.sessions).length;$>0&&pe.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:$})}this.registry.register(v),A=!0;let M={agentId:e.agentId,framework:e.framework,workspace:_,cozeIdentity:e.cozeIdentity,createdAt:C?.createdAt??Date.now(),sessions:C?.sessions??{},model:P.model};u==="cloud"&&(M.deployType="cloud"),y&&(M.accountId=y),D&&(M.patToken=D),k&&(M.modelInfo=k),C?.skills&&(M.skills=C.skills),C?.agentName&&(M.agentName=C.agentName),C?.description&&(M.description=C.description),e.framework==="openclaw"&&u==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,_)):pe.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 $=[...M.skills??[]],V=new Map($.map((Ee,he)=>[Ee.skillId,he])),te=await Promise.allSettled(B.map(Ee=>Hc({agentId:e.agentId,workspace:_,framework:e.framework,skill:Ee}))),Q=0;for(let[Ee,he]of te.entries()){let O=B[Ee];O&&(he.status==="fulfilled"?(jc($,V,he.value),Q++):pe.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:O.skillId,skillName:O.skillName,err:String(he.reason)}))}Q>0&&(M.skills=$,pe.info("initialSkills installed",{agentId:e.agentId,installed:Q,requested:B.length}))}return await Ye(M,this.paths),pe.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(S){throw pe.error("agent create failed, rolling back",{agentId:e.agentId,err:String(S)}),A&&v&&(await v.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await dy(l.root,{recursive:!0,force:!0}).catch(C=>pe.warn("rm agent dir failed (ignored)",{err:String(C)})),S instanceof T?S:new T("AGENT_SPAWN_FAILED",String(S),{cause:S})}finally{clearTimeout(E)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&Jc(e.framework))u=gy;else throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);Jc(e.framework)&&!rs(e.framework)&&(pe.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await er(e.framework));let x=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,p;e.framework==="openclaw"?p=await this.buildOpenclawDownstream({session:e,modelConfig:x,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path}):p=this.factory(e.framework,u.path,e.workspace,e.agentId,x,i,o,c,this.buildBinShimPathEnv(),e.framework==="codex"&&e.deployType==="cloud"?Vc($e(e.agentId,this.paths).root,"codex-home"):void 0);try{return await p.start(),await p.initialize(wy),p}catch(w){let _=p instanceof Pt?p.getStderrTail():[];throw _.length>0&&pe.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:w instanceof T?w.code:"unknown",recentStderr:_}),await p.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,w)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new T("AGENT_ENV_NOT_READY",af(o),{cause:{reason:of}})}catch(o){pe.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof T?new T(i.code,i.message,{retriable:i.retriable,cause:i.cause??i}):new T("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};pe.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 pe.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new T("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:my}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new T("AGENT_ENV_NOT_READY",af(r),{cause:{reason:of}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:l,command:u}=e,x=$c(o);if(r.deployType==="local"){let I=await this.ensureOpenclawDefaultAgent();return new Tr({command:u,cwd:I.workspace,agentId:I.id,sessionName:x})}let p=await sf(),w=i?Du(i,c,l):null,_;if(w){let I=Mc(o),v=w.models[0]?.id??Et,A=`${I}/${v}`;if(!this.ensuredProviders.has(A)){let S=this.getOpenclawConfig();await S.ensureProvider(I,w),await S.addModelToAllowlist(A),this.ensuredProviders.add(A)}_=A}return new Tr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:x,...p?{gatewayToken:p}:{},..._?{slashModelOnStart:_}:{}})}async openclawRepair(e,r){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,r)}async cleanupOpenclawSessionProviders(e){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let r=this.openclawConfigCache;for(let i of e.sessions.keys()){let o=Mc(i),c=`${o}/${e.model}`,l=!0;try{await r.removeProvider(o)}catch(u){l=!1,pe.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){l=!1,pe.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}l&&this.ensuredProviders.delete(c)}}};import{randomUUID as ff}from"node:crypto";import{promises as Ty}from"node:fs";import{basename as xf}from"node:path";Ke();ne();import{promises as Ey}from"node:fs";import{basename as by}from"node:path";var cf=G("file-upload"),vy="/api/coze_claw/file/agent_upload",Sy=6e4;async function df(t,e={}){let i=`${Xs(eo(e.handshakeBase))}${vy}`,o=e.timeoutMs??Sy,c=await Ey.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",...Er(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},x=new AbortController,p=setTimeout(()=>x.abort(),o);cf.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let w=await fetch(i,{method:"POST",headers:u,body:l,signal:x.signal}),_=w.headers.get("x-tt-logid")??"";if(!w.ok){let v=await w.text().catch(()=>"");throw new T("UPLOAD_FAILED",`upload HTTP ${w.status} logid=${_}: ${v.slice(0,200)}`)}let I=await w.json();if(I.code!==void 0&&I.code!==0)throw new T("UPLOAD_FAILED",`upload code=${I.code} msg=${I.msg??"-"} logid=${_}`);let E=I.data?.file?.file_url;if(!E)throw new T("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${_}: ${JSON.stringify(I).slice(0,200)}`);return cf.info("file upload ok",{uri:E,logid:_}),{uri:E}}catch(w){throw w instanceof T?w:w.name==="AbortError"?new T("UPLOAD_FAILED",`upload timeout (${o}ms) for ${by(t.path)}`):new T("UPLOAD_FAILED",String(w),{cause:w})}finally{clearTimeout(p)}}Ke();ne();import{extname as Ay}from"node:path";var Iy={".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 lf(t){let e=Ay(t).toLowerCase();return Iy[e]??"application/octet-stream"}Oe();var xo=G("agent-send"),uf=50*1024*1024;function hf(t,e,r){let i=t.get(e);if(!i)throw new T("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new T("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new T("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function pf(t,e,r,i,o,c){let u;for(let x=0;x<=2;x++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(p){u=p,x<2&&(xo.warn("sendAgentFileUpdate failed, retrying",{attempt:x+1,err:String(p)}),await new Promise(w=>setTimeout(w,5e3)))}throw new T("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function gf(t,e){let{session:r,runtime:i}=hf(e.core,t.agentId,t.sessionId);if(!await Zr(t.path,r.workspace))throw new T("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await Ty.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new T("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>uf)throw new T("FILE_TOO_LARGE",`${o.size} bytes > limit ${uf}`);let c=await lf(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new T("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let l=t.name??xf(t.path),u;try{u=await df({patToken:r.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:l,sizeBytes:o.size,...r.accountId?{accountId:r.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(p){throw xo.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:p instanceof T?p.code:"UNKNOWN",message:p instanceof Error?p.message:String(p)}),p}let x={sessionUpdate:"agent_file",messageId:ff(),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 pf(e,r,i,t.sessionId,x,"agent file uploaded to cloud but sendAgentFileUpdate failed"),xo.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 mf(t,e){let{session:r,runtime:i}=hf(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new T("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??xf(t.path),c={sessionUpdate:"group_file",messageId:ff(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await pf(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),xo.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 wf(t,e){let r=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(r.length,i.length);for(let c=0;c<o;c++){let l=r[c]??0,u=i[c]??0;if(l<u)return!0;if(l>u)return!1}return!1}nn();yn();ne();var Lt=G("coze-cli-installer"),_f="@coze/cli@latest",Cy="coze",yf="0.1.8",Dy=5e3,Ry=5e3,ky=9e4,Ef=1e4,Pi=null,ho=!1;async function Zc(t,e={}){if(ho)return;if(Pi)return Pi;let r=e.exec??Ju;return Pi=(async()=>{try{let i=await Oy(Cy,r),o=!1;if(i){let l=await Py(r);if(l===void 0)Lt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(wf(l,yf))Lt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:l,min:yf}),o=!0;else{Lt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:l}),ho=!0;return}}let c=o?"upgrade-only":"full";Lt.info("coze-cli install start",{package:_f,mode:c});try{await r("npm",["i","-g","--prefer-online",_f],{timeout:ky,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){ho=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:Ef}),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:Ef}),Lt.info("coze auth login ok")}catch(l){Lt.warn("coze auth login failed",{err:String(l)});return}ho=!0}finally{Pi=null}})(),Pi}async function Oy(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:Dy});return Ea(i)}catch{return}}async function Py(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:Ry});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}Jr();Oe();var Ly=10*6e4;function bf(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?Ly:e}function po(t){return tr(t??X().configFile)}function Li(t,e){return nr(e??X().configFile,t)}import{randomBytes as eE}from"node:crypto";Xi();Ke();ne();import{createReadStream as Ny}from"node:fs";import{mkdir as My,readFile as By,realpath as zy,stat as Fy,writeFile as Uy}from"node:fs/promises";import{basename as Gy,dirname as Yc,isAbsolute as qy,join as Hy,relative as jy,resolve as vf,sep as Wy}from"node:path";import{createInterface as Ky}from"node:readline";var Af=G("fs-rpc"),Ni=Ft("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function If(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Ni)throw new T("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Ni} bytes`);let i=await Cf(t.path,e);return await My(Yc(i),{recursive:!0}),await Uy(i,t.content,"utf8"),Af.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function Tf(t,e){let r=await Cf(t.path,e),i=await Fy(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Ni&&!o)throw new T("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Ni} bytes`);let c;if(o&&i.size>Ni)c=await $y(r,t.line??1,t.limit);else{let l=await By(r,"utf8");if(o){let u=l.split(`
99
- `),x=Math.max(0,(t.line??1)-1),p=typeof t.limit=="number"?x+t.limit:void 0;c=u.slice(x,p).join(`
100
- `)}else c=l}return Af.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function $y(t,e,r){let i=Ky({input:Ny(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,l=[],u=0;try{for await(let x of i)if(u>=o&&u<c&&l.push(x),u++,u>=c)break}finally{i.close()}return l.join(`
101
- `)}async function Cf(t,e){if(typeof t!="string"||t.length===0)throw new T("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([Sf(vf(e)),Sf(vf(t))]),o=jy(r,i);if(Vy(o,Wy,qy(o)))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function Vy(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function Sf(t){let e=[],r=t;for(;r!==Yc(r);)try{let i=await zy(r);return e.length?Hy(i,...e.reverse()):i}catch{e.push(Gy(r)),r=Yc(r)}return t}ne();var Df=G("prompt-multimodal"),Rf=10*1024*1024,Jy=15e3,Zy=6;async function kf(t){let e=new Array(t.length),r=0;async function i(){for(;r<t.length;){let c=r++,l=t[c];l!==void 0&&(e[c]=await Yy(l))}}let o=Array.from({length:Math.min(Zy,t.length)},()=>i());return await Promise.all(o),e}function Of(t){return t.some(e=>e.type==="image")}async function Yy(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Ys(e.uri))return t;try{let{buf:r,contentType:i}=await Qy(e.uri),o=e.mimeType||Xy(i)||"application/octet-stream";return Df.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 Df.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function Xy(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function Qy(t){let e=new AbortController,r=setTimeout(()=>e.abort(),Jy);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>Rf)throw new Error(`image too large: ${o.byteLength} bytes (max ${Rf})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}rn();Ke();ne();var K=G("core"),tE=3e4,nE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,rE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",iE="\u5BA1\u6279\u5DF2\u8D85\u65F6",sE=3e4,go=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Ir;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=bf(e.bridgeConfig)}registerExtension(e,r){this.extensions[e]=r}getCozeEnv(){return this.currentCozeEnv}getMockScenario(){return this.currentMockScenario}setMockScenario(e){this.currentMockScenario=e&&e.length>0?e:void 0}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),K.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){K.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(r=>r.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}async reloadAgents(e){let r=e?this.agents.has(e)?[e]:[]:[...this.agents.keys()];for(let i of r)await this.agents.get(i)?.killAllRuntimes("reload");return r}get(e){return this.agents.get(e)}register(e){this.agents.set(e.agentId,e),K.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){K.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(i)})}}onAgentRegister(e){return this.registerHandlers.add(e),()=>this.registerHandlers.delete(e)}registerHandlers=new Set;unregister(e){this.agents.delete(e)}reviveIfDisconnected(e){this.disconnectedAgents.delete(e)&&K.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,r,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,l)=>{K.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:l}),Oi(i),i.downstream=void 0,i.replySeq=0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),this.rejectPendingForDownstream(o,"downstream exited")}))}hasPendingPermissionFor(e){for(let r of this.pendingUpstream.values())if(r.downstream===e)return!0;return!1}rejectPendingForDownstream(e,r){let i=[];for(let[o,c]of this.pendingUpstream)c.downstream===e&&i.push(o);if(i.length!==0){K.info("reject pendingUpstream entries (downstream gone)",{reason:r,count:i.length});for(let o of i){let c=this.pendingUpstream.get(o);if(c){this.pendingUpstream.delete(o),this.upstream.send(_n(o,{code:ee.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(l=>K.debug("send error response to upstream failed (ignored)",{err:String(l)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:ee.INTERNAL_ERROR,message:`bridge: ${r}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,r=this.pendingBridge.size;if(!(e===0&&r===0)){K.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:r});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:ee.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new T("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(ro(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&&nE.test(i)?this.currentCozeEnv=i:i&&K.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});try{if(e.method.startsWith("_agent/")){let o=this.extensions[e.method];if(!o){r!==null?await this.sendError(r,ee.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):K.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(Ar(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Ar(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Ar(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,ee.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):K.warn("drop unknown notification",{method:e.method})}catch(o){K.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(_n(r,ki(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new T("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new T("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new T("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new T("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||!c)return this.dispatchSessionCall(o,e.method,r);if(e.method==="session/prompt"){let x=o.sessions.get(c);if(x?.pendingPermission){let p=r._meta?.cozeTriggerMsgId,w=kc(r._meta);return K.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,x,c,rE,p,w)}}let l=Date.now(),u=!1;try{let x=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,x}finally{K.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-l,ok:u})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=gu(i);switch(r){case"session/new":{let c=oE();return K.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return K.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,l=c.sessionId;if(!l)throw new T("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=await this.ensureRuntime(e,l);if(u.replySeq=0,await this.ensureDownstream(e,l,u),!u.downstream||!u.acpSessionId)throw new T("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");let x=i._meta?.cozeTriggerMsgId;x?e.activeTriggers.set(u.acpSessionId,x):e.activeTriggers.delete(u.acpSessionId);let p=kc(i._meta);if(p?e.activeGroupIds.set(u.acpSessionId,p):e.activeGroupIds.delete(u.acpSessionId),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&Of(c.prompt))throw new T("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let w=await kf(c.prompt);try{let _=await u.downstream.sessionPrompt({...c,sessionId:u.acpSessionId,prompt:w});return u.lastActiveAt=Date.now(),_}catch(_){if(_ instanceof T&&_.code==="AGENT_APPROVAL_TIMEOUT"){let I=u.pendingPermission;I&&(I.downstream.respondAgentRequest(I.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(I.upstreamId),u.pendingPermission=void 0);let E=u.acpSessionId,v=E?e.activeTriggers.get(E):void 0,A=E?e.activeGroupIds.get(E):void 0;return K.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:l}),await this.synthesizePromptReply(e,u,l,iE,v,A)}throw _}finally{if(e.activeTriggers.delete(u.acpSessionId),e.activeGroupIds.delete(u.acpSessionId),u.pendingPermission=void 0,u.reloadAfterTurn){u.reloadAfterTurn=!1;let _=u.downstream;_&&(u.downstream=void 0,K.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:l,acpId:u.acpSessionId}),_.stop("reload-after-turn").catch(I=>K.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:l,err:String(I)})))}else u.downstream?.isAlive()&&this.armIdleTimer(e,l,u)}}case"session/cancel":{let l=o.sessionId;if(!l)throw new T("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(l);if(e.hasSessionQueue(l)){let x=e.getSessionQueue(l);x.size>0&&(K.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:l,queuedCount:x.size}),x.dispose(new T("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${l}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}default:throw new T("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async ensureRuntime(e,r){let i=e.sessions.get(r);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,r):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return e.sessions.set(r,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,r){let i={sessionId:r,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(yt.GEN_MODEL_TOKEN,i,sE);if(!o?.modelToken)throw new T("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof T&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new T("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(Oi(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new T("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,l=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(l>=o&&Date.now()-u<c)throw new T("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${l} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let x;try{x=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(p){throw i.spawnFailCount=l+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(K.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),p}if(i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=x,this.attachRuntimeHooks(e,r,i),i.acpSessionId){i.loadingSession=!0;try{await x.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),K.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(p){K.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(p)}),i.acpSessionId=void 0;let w=await x.sessionNew({cwd:e.workspace});i.acpSessionId=w.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let p=await x.sessionNew({cwd:e.workspace});i.acpSessionId=p.sessionId,await this.persistSessionMapping(e)}x.afterSessionEstablished&&i.acpSessionId&&await x.afterSessionEstablished(i.acpSessionId)}armIdleTimer(e,r,i){if(Oi(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(Sr("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(Sr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(x=>K.warn("synthesizePromptReply update send failed (ignored)",{err:String(x)})),{stopReason:"end_turn"}}forwardUpdate(e,r){let i=r.sessionId,o=this.reverseSessionId(e,i);if(!o){K.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){K.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(dE(r)){K.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let l={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},u=e.activeTriggers.get(i);u&&(l.cozeTriggerMsgId=u);let x=e.activeGroupIds.get(i);x&&(l.cozeGroupId=x),this.upstream.send(Sr("session/update",{...r,sessionId:o,_meta:l})).catch(p=>K.warn("forward update failed",{agentId:e.agentId,err:String(p)}))}handleAgentRequest(e,r,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,r,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,r,i);return}K.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:ee.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},l=await If(c,o);r.respondAgentRequest(i.id,l)}else{let c=i.params??{},l=await Tf(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,ki(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,x=u?e.activeTriggers.get(u):void 0,p={cozeAgentId:e.agentId};x&&(p.cozeTriggerMsgId=x);let w=u?e.activeGroupIds.get(u):void 0;w&&(p.cozeGroupId=w);let _=u?this.reverseSessionId(e,u):void 0,I=_?e.sessions.get(_):void 0;I&&(I.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let E={...c,..._?{sessionId:_}:{},_meta:p};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:_}),K.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:_,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(v=>({optionId:v.optionId,kind:v.kind,name:v.name}))}),this.upstream.send(Di(o,"session/request_permission",E)).catch(v=>{this.pendingUpstream.delete(o),K.error("forward permission request failed",{agentId:e.agentId,err:String(v)}),r.respondAgentRequestError(i.id,{code:ee.INTERNAL_ERROR,message:`upstream send failed: ${String(v)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let r=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(r){this.pendingUpstream.delete(r.key);let o=r.value;this.clearPendingPermissionFor(o),e.error?(K.info("upstream \u2192 permission response (error)",{agentId:o.agentId,upstreamId:e.id,method:o.method,error:e.error}),o.downstream.respondAgentRequestError(o.agentRequestId,e.error)):(o.method==="session/request_permission"&&aE(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 no(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=tE){let o=this.upstreamIds.next(e);return new Promise((c,l)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),l(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:l,timer:u}),this.upstream.send(Di(o,e,r)).catch(x=>{let p=this.pendingBridge.get(o);p&&(clearTimeout(p.timer),this.pendingBridge.delete(o)),l(x)})})}async persistSessionMapping(e){if(this.paths)try{let r=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),r.set(i,c)}await Yr(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:vr}}))}};function oE(){return eE(16).toString("hex")}function aE(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 cE=["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 dE(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 cE.some(c=>o.startsWith(c))}ne();Oe();import{randomBytes as lE}from"node:crypto";import{chmod as uE,mkdir as fE,writeFile as Pf}from"node:fs/promises";import{createServer as xE}from"node:http";import{dirname as hE}from"node:path";var pE=1e6,Xc=G("ipc"),mo=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??X()}async start(){this.token=lE(32).toString("hex");let e=xE((i,o)=>{this.dispatch(i,o)});this.server=e,await new Promise((i,o)=>{e.once("error",o),e.listen(0,"127.0.0.1",()=>i())});let r=e.address();if(!r||typeof r!="object")throw new Error("failed to obtain IPC port");return this.port=r.port,await this.persistAuthFiles(),Xc.info("IPC listening",{port:this.port}),{port:this.port,token:this.token}}async stop(){let e=this.server;e&&(await new Promise((r,i)=>{e.close(o=>o?i(o):r())}),this.server=null)}async persistAuthFiles(){await fE(hE(this.paths.portFile),{recursive:!0}),await Pf(this.paths.portFile,String(this.port),"utf8"),await Pf(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await uE(this.paths.tokenFile,384)}catch(e){Xc.warn("chmod token file failed (non-POSIX?)",{err:String(e)})}}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Mi(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Mi(r,404,{error:"not found"});return}let l=null;if(e.method==="POST")try{l=await gE(e)}catch(u){Mi(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(l,e);Mi(r,200,u??{ok:!0})}catch(u){Xc.error("IPC handler failed",{key:o,err:String(u)}),Mi(r,500,{error:u instanceof Error?u.message:String(u)})}}};function Mi(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function gE(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>pE)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}var nh=At(jf(),1);var Zb=At(Ux(),1),Yb=At(Po(),1),Xb=At(Rr(),1),Qb=At(ud(),1),ev=At(hd(),1),tv=At(yd(),1),Jx=At(Bo(),1),nv=At(Vx(),1);var Zx=Jx.default;Ke();ne();var Re=G("upstream.frontier"),Xx="application/json",Qx="none",iv=15e3;function sv(t){class e extends Zx{constructor(i){super(i,wu,{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(il("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let l=Buffer.from(c.slice(0,128)).toString("hex");Re.debug("WS raw frame out",{bytes:c.byteLength,headHex:l})}catch(c){Re.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var Wi=class{constructor(e){this.opts=e}opts;fws=null;handler=null;connectHandlers=[];opened=!1;lastSendRefusedLogAt=0;sendRefusedSuppressed=0;openCount=0;async start(){if(this.fws){Re.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:_u,...Er(this.opts.ppeOverride)},r=sv(e),i=Eu(this.opts.urlOverride),o={url:i,ws:r,fpID:mu,aID:Qs,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Xx,force:!0},payloadEncoding:{encoding:Qx,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new nh.FWS(o),l=!1,u=null,x,p,w=new Promise((E,v)=>{x=E,p=v}),_=E=>{l||(l=!0,u&&(clearTimeout(u),u=null),E?p(E):x())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let E=this.openCount===1;Re.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=>Re.warn("onConnect handler threw (ignored)",{err:String(A)}))},c.onclose=E=>{this.opened=!1,Re.info("frontier closed",{code:E.code,reason:E.reason,willReconnect:E.willReconnect})},c.onerror=E=>{Re.warn("frontier error",{code:E.code,msg:E.message}),_(new T("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${E.code} msg=${E.message??""}`))},c.onmessage=E=>this.handleMessage(E),this.fws=c;let I=this.opts.openTimeoutMs??iv;u=setTimeout(()=>{_(new T("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${I}ms (handshake or upgrade slow)`))},I),await c.connect();try{await w}catch(E){try{c.close(1e3,"open failed")}catch(v){Re.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,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){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 T("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 T("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${r.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;eh(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:Xx,payloadEncoding:Qx})}catch(u){throw Re.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new T("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){Re.debug("drop non-adapter frontier frame",{service:r});return}let i=cv(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;eh(c)||Re.info("frontier frame in",{logid:av(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:ov(i)}),Promise.resolve(this.handler(o)).catch(l=>Re.warn("frontier frame handler threw",{err:String(l)}))}};function eh(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var th=2e3;function ov(t){return t.length<=th?t:`${t.slice(0,th)}...<truncated, total ${t.length} chars>`}function av(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function cv(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 bd=G("upstream.switchable"),Fo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;bd.info("swap upstream",{reason:r});let i=this.inner;if(this.inner=e,this.handler&&e.onFrame(this.handler),e.onConnect)for(let o of this.connectHandlers)e.onConnect(o);try{await e.start()}catch(o){throw bd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>bd.warn("previous upstream stop threw (ignored)",{err:String(o)}))}current(){return this.inner}start(){return this.inner.start()}stop(e){return this.inner.stop(e)}send(e){return this.inner.send(e)}onFrame(e){this.handler=e,this.inner.onFrame(e)}onConnect(e){this.connectHandlers.push(e),this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};ne();var vd=G("upstream"),Mr=class{handler=null;async start(){vd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){vd.info("NoopUpstream stopped",{reason:e})}async send(e){vd.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};Ke();ne();ne();Oe();import{promises as Sd}from"node:fs";import{dirname as dv}from"node:path";var lv=G("pat-token-store");async function Uo(t=X()){try{let r=(await Sd.readFile(t.patTokenFile,"utf8")).trim();return r.length>0?r:null}catch(e){let r=e?.code;return r!=="ENOENT"&&lv.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function Ki(t,e=X()){if(!t)throw new Error("writePatToken: empty patToken");await Sd.mkdir(dv(e.patTokenFile),{recursive:!0}),await Sd.writeFile(e.patTokenFile,t,{encoding:"utf8",mode:384})}Oe();Oe();import{promises as Go}from"node:fs";import{join as uv}from"node:path";function fv(t,e){return`#!/bin/sh
97
+ `}function x_(t){if(t.includes(`
98
+ `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var p_={path:"",version:"cloud-deployed"},s0="openclaw_gateway_unavailable",g_="openclaw_default_agent_missing";function o0(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 m_={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},w_=6e4,co=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??u_,this.createTimeoutMs=e.createTimeoutMs??w_,this.detectorFactory=e.detectorFactory??(()=>new Fn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new oo({command:r})),this.openclawConfigDir=e.openclawConfigDir??i0(f_(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{xe.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=i0(e,".env");if(await d_(r).then(c=>c.isFile()).catch(()=>!1)){xe.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}await ao(e,{recursive:!0});let o=h_({...process.env,...Hc(this.paths.agentEnvFile)});if(await l_(r,o,"utf8"),process.platform!=="win32")try{await a_(r,384)}catch(c){xe.warn("chmod ~/.openclaw/.env to 0600 failed (ignored)",{err:String(c)})}xe.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),xe.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new T("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new T("IPC_BAD_REQUEST","framework required");let i=bi(e._meta)==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let o=this.registry.get(e.agentId);if(o){if(o.framework!==e.framework)throw new T("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${o.framework})`);if(o.status==="error")xe.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await o.dispose("rebuild after error").catch(S=>xe.warn("dispose stale agent failed (ignored)",{err:String(S)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==o.patToken){xe.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),o.setPatToken(e.patToken);let S=await Ge(e.agentId,this.paths).catch(()=>null);S&&(S.patToken=e.patToken,await Ve(S,this.paths))}if(o.deployType==="cloud"&&e.modelInfo){xe.info("updating agent modelInfo on re-create",{agentId:e.agentId}),o.setModelInfo(e.modelInfo);let S=await Ge(e.agentId,this.paths).catch(()=>null);S&&(S.modelInfo=e.modelInfo,await Ve(S,this.paths))}return xe.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:o.agentId,workspace:o.workspace,framework:o.framework}}}if(!i&&!this.config.frameworksCache?.[e.framework])throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let d=Ze(e.agentId,this.paths),f=bi(e._meta),h=e.framework==="openclaw"&&f==="local",x;h&&!r?.revive&&(x=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let m=x??(h?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),g=e.workspace??m??d.workspace,A=new AbortController,w=setTimeout(()=>A.abort(new T("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),E,I=!1;try{i&&Wc(e.framework)&&await Xn(e.framework,A.signal);let S=()=>{if(A.signal.aborted)throw A.signal.reason instanceof Error?A.signal.reason:new T("AGENT_TIMEOUT","_agent/create aborted")};await ao(d.root,{recursive:!0}),await ao(g,{recursive:!0}),await ao(d.logs,{recursive:!0}),S(),h||await tr(g,e.framework,e.cozeIdentity),e.framework==="claude-code"&&await wl(g),S();let R=await Ge(e.agentId,this.paths).catch(()=>null),P=bu({model:e.model??R?.model}),y=xu(e._meta)??R?.accountId,C=e.patToken??R?.patToken,D=f==="cloud"?e.modelInfo??R?.modelInfo:void 0;if(E=new io({agentId:e.agentId,framework:e.framework,workspace:g,model:P.model??wt,deployType:f,...y?{accountId:y}:{},...C?{patToken:C}:{},...D?{modelInfo:D}:{}}),E.status="ok",R?.sessions){for(let[Z,te]of Object.entries(R.sessions))E.sessions.set(Z,{acpSessionId:te.acpSessionId,modelToken:te.modelToken,tokenGeneratedAt:te.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0});let K=Object.keys(R.sessions).length;K>0&&xe.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:K})}this.registry.register(E),I=!0;let N={agentId:e.agentId,framework:e.framework,workspace:g,cozeIdentity:e.cozeIdentity,createdAt:R?.createdAt??Date.now(),sessions:R?.sessions??{},model:P.model};f==="cloud"&&(N.deployType="cloud"),y&&(N.accountId=y),C&&(N.patToken=C),D&&(N.modelInfo=D),R?.skills&&(N.skills=R.skills),R?.agentName&&(N.agentName=R.agentName),R?.description&&(N.description=R.description),e.framework==="openclaw"&&f==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,g)):xe.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let M=e.initialSkills??[];if(M.length>0){let K=[...N.skills??[]],Z=new Map(K.map((_e,he)=>[_e.skillId,he])),te=await Promise.allSettled(M.map(_e=>Uc({agentId:e.agentId,workspace:g,framework:e.framework,skill:_e}))),X=0;for(let[_e,he]of te.entries()){let O=M[_e];O&&(he.status==="fulfilled"?(Gc(K,Z,he.value),X++):xe.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:O.skillId,skillName:O.skillName,err:String(he.reason)}))}X>0&&(N.skills=K,xe.info("initialSkills installed",{agentId:e.agentId,installed:X,requested:M.length}))}return await Ve(N,this.paths),xe.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:f}),{ok:!0,agentId:e.agentId,workspace:g,framework:e.framework}}catch(S){throw xe.error("agent create failed, rolling back",{agentId:e.agentId,err:String(S)}),I&&E&&(await E.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await c_(d.root,{recursive:!0,force:!0}).catch(R=>xe.warn("rm agent dir failed (ignored)",{err:String(R)})),S instanceof T?S:new T("AGENT_SPAWN_FAILED",String(S),{cause:S})}finally{clearTimeout(w)}}async spawnSessionDownstream(e,r,i,o,c){let f=this.config.frameworksCache?.[e.framework];if(!f)if(e.deployType==="cloud"&&Wc(e.framework))f=p_;else throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);Wc(e.framework)&&!es(e.framework)&&(xe.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await Xn(e.framework));let h=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:h,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:f.path}):x=this.factory(e.framework,f.path,e.workspace,e.agentId,h,i,o,c,this.buildBinShimPathEnv());try{return await x.start(),await x.initialize(m_),x}catch(m){let g=x instanceof Dt?x.getStderrTail():[];throw g.length>0&&xe.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:m instanceof T?m.code:"unknown",recentStderr:g}),await x.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,f.path,m)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new T("AGENT_ENV_NOT_READY",o0(o),{cause:{reason:s0}})}catch(o){xe.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof T?new T(i.code,i.message,{retriable:i.retriable,cause:i.cause??i}):new T("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};xe.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return xe.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new T("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:g_}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new T("AGENT_ENV_NOT_READY",o0(r),{cause:{reason:s0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:d,command:f}=e,h=qc(o);if(r.deployType==="local"){let A=await this.ensureOpenclawDefaultAgent();return new Ir({command:f,cwd:A.workspace,agentId:A.id,sessionName:h})}let x=await r0(),m=i?Ru(i,c,d):null,g;if(m){let A=Pc(o),E=m.models[0]?.id??wt,I=`${A}/${E}`;if(!this.ensuredProviders.has(I)){let S=this.getOpenclawConfig();await S.ensureProvider(A,m),await S.addModelToAllowlist(I),this.ensuredProviders.add(I)}g=I}return new Ir({command:f,cwd:r.workspace,agentId:r.agentId,sessionName:h,...x?{gatewayToken:x}:{},...g?{slashModelOnStart:g}:{}})}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=Pc(i),c=`${o}/${e.model}`,d=!0;try{await r.removeProvider(o)}catch(f){d=!1,xe.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(f)})}try{await r.removeModelFromAllowlist(c)}catch(f){d=!1,xe.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(f)})}d&&this.ensuredProviders.delete(c)}}};import{randomUUID as f0}from"node:crypto";import{promises as A_}from"node:fs";import{basename as u0}from"node:path";qe();ne();import{promises as __}from"node:fs";import{basename as E_}from"node:path";var a0=G("file-upload"),b_="/api/coze_claw/file/agent_upload",v_=6e4;async function c0(t,e={}){let i=`${Vs(Ys(e.handshakeBase))}${b_}`,o=e.timeoutMs??v_,c=await __.readFile(t.path),d=new FormData;d.append("agent_id",t.agentId),d.append("session_id",t.sessionId),d.append("file_name",t.name),d.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let f={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...yr(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},h=new AbortController,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 m=await fetch(i,{method:"POST",headers:f,body:d,signal:h.signal}),g=m.headers.get("x-tt-logid")??"";if(!m.ok){let E=await m.text().catch(()=>"");throw new T("UPLOAD_FAILED",`upload HTTP ${m.status} logid=${g}: ${E.slice(0,200)}`)}let A=await m.json();if(A.code!==void 0&&A.code!==0)throw new T("UPLOAD_FAILED",`upload code=${A.code} msg=${A.msg??"-"} logid=${g}`);let w=A.data?.file?.file_url;if(!w)throw new T("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${g}: ${JSON.stringify(A).slice(0,200)}`);return a0.info("file upload ok",{uri:w,logid:g}),{uri:w}}catch(m){throw m instanceof T?m:m.name==="AbortError"?new T("UPLOAD_FAILED",`upload timeout (${o}ms) for ${E_(t.path)}`):new T("UPLOAD_FAILED",String(m),{cause:m})}finally{clearTimeout(x)}}qe();ne();import{extname as S_}from"node:path";var I_={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".svg":"image/svg+xml",".bmp":"image/bmp",".ico":"image/x-icon",".heic":"image/heic",".heif":"image/heif",".pdf":"application/pdf",".doc":"application/msword",".docx":"application/vnd.openxmlformats-officedocument.wordprocessingml.document",".xls":"application/vnd.ms-excel",".xlsx":"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",".ppt":"application/vnd.ms-powerpoint",".pptx":"application/vnd.openxmlformats-officedocument.presentationml.presentation",".txt":"text/plain",".md":"text/markdown",".markdown":"text/markdown",".json":"application/json",".yaml":"text/yaml",".yml":"text/yaml",".csv":"text/csv",".html":"text/html",".htm":"text/html",".xml":"application/xml",".log":"text/plain",".zip":"application/zip",".tar":"application/x-tar",".gz":"application/gzip",".tgz":"application/gzip",".mp3":"audio/mpeg",".wav":"audio/wav",".mp4":"video/mp4",".mov":"video/quicktime",".webm":"video/webm"};async function d0(t){let e=S_(t).toLowerCase();return I_[e]??"application/octet-stream"}ke();var lo=G("agent-send"),l0=50*1024*1024;function h0(t,e,r){let i=t.get(e);if(!i)throw new T("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new T("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new T("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function x0(t,e,r,i,o,c){let f;for(let h=0;h<=2;h++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(x){f=x,h<2&&(lo.warn("sendAgentFileUpdate failed, retrying",{attempt:h+1,err:String(x)}),await new Promise(m=>setTimeout(m,5e3)))}throw new T("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(f)}`,{cause:f})}async function p0(t,e){let{session:r,runtime:i}=h0(e.core,t.agentId,t.sessionId);if(!await Zr(t.path,r.workspace))throw new T("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await A_.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new T("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>l0)throw new T("FILE_TOO_LARGE",`${o.size} bytes > limit ${l0}`);let c=await d0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new T("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let d=t.name??u0(t.path),f;try{f=await c0({patToken:r.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:d,sizeBytes:o.size,...r.accountId?{accountId:r.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(x){throw lo.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:x instanceof T?x.code:"UNKNOWN",message:x instanceof Error?x.message:String(x)}),x}let h={sessionUpdate:"agent_file",messageId:f0(),content:{type:t.kind==="image"?"image":"resource",uri:f.uri,mimeType:c,name:d,sizeBytes:o.size,...f.fileId!==void 0?{fileId:f.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await x0(e,r,i,t.sessionId,h,"agent file uploaded to cloud but sendAgentFileUpdate failed"),lo.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:d,bytes:o.size,mime:c,uri:f.uri}),{ok:!0,uri:f.uri,bytes:o.size,mimeType:c,...f.fileId!==void 0?{fileId:f.fileId}:{}}}async function g0(t,e){let{session:r,runtime:i}=h0(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new T("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??u0(t.path),c={sessionUpdate:"group_file",messageId:f0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await x0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),lo.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 d=r[c]??0,f=i[c]??0;if(d<f)return!0;if(d>f)return!1}return!1}en();wn();ne();var kt=G("coze-cli-installer"),w0="@coze/cli@latest",T_="coze",y0="0.1.8",R_=5e3,C_=5e3,D_=9e4,_0=1e4,ki=null,fo=!1;async function $c(t,e={}){if(fo)return;if(ki)return ki;let r=e.exec??Zu;return ki=(async()=>{try{let i=await k_(T_,r),o=!1;if(i){let d=await O_(r);if(d===void 0)kt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(m0(d,y0))kt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:d,min:y0}),o=!0;else{kt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:d}),fo=!0;return}}let c=o?"upgrade-only":"full";kt.info("coze-cli install start",{package:w0,mode:c});try{await r("npm",["i","-g","--prefer-online",w0],{timeout:D_,maxBuffer:10*1024*1024}),kt.info("coze-cli install ok")}catch(d){kt.warn("coze-cli install failed (skip subsequent steps)",{err:String(d)});return}if(o){fo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:_0}),kt.info("coze config set xTTEnv ok",{env:t.env})}catch(d){kt.warn("coze config set failed (continue to auth login)",{err:String(d)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:_0}),kt.info("coze auth login ok")}catch(d){kt.warn("coze auth login failed",{err:String(d)});return}fo=!0}finally{ki=null}})(),ki}async function k_(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:R_});return wa(i)}catch{return}}async function O_(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:C_});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}Kr();ke();var P_=10*6e4;function E0(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?P_:e}function uo(t){return Qn(t??Y().configFile)}function Oi(t,e){return er(e??Y().configFile,t)}import{randomBytes as Q_}from"node:crypto";Vi();qe();ne();import{createReadStream as L_}from"node:fs";import{mkdir as N_,readFile as M_,realpath as B_,stat as z_,writeFile as F_}from"node:fs/promises";import{basename as U_,dirname as Kc,isAbsolute as G_,join as j_,relative as H_,resolve as b0,sep as q_}from"node:path";import{createInterface as W_}from"node:readline";var S0=G("fs-rpc"),Pi=Mt("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function I0(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Pi)throw new T("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Pi} bytes`);let i=await T0(t.path,e);return await N_(Kc(i),{recursive:!0}),await F_(i,t.content,"utf8"),S0.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function A0(t,e){let r=await T0(t.path,e),i=await z_(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Pi&&!o)throw new T("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Pi} bytes`);let c;if(o&&i.size>Pi)c=await $_(r,t.line??1,t.limit);else{let d=await M_(r,"utf8");if(o){let f=d.split(`
99
+ `),h=Math.max(0,(t.line??1)-1),x=typeof t.limit=="number"?h+t.limit:void 0;c=f.slice(h,x).join(`
100
+ `)}else c=d}return S0.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function $_(t,e,r){let i=W_({input:L_(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,d=[],f=0;try{for await(let h of i)if(f>=o&&f<c&&d.push(h),f++,f>=c)break}finally{i.close()}return d.join(`
101
+ `)}async function T0(t,e){if(typeof t!="string"||t.length===0)throw new T("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([v0(b0(e)),v0(b0(t))]),o=H_(r,i);if(K_(o,q_,G_(o)))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function K_(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function v0(t){let e=[],r=t;for(;r!==Kc(r);)try{let i=await B_(r);return e.length?j_(i,...e.reverse()):i}catch{e.push(U_(r)),r=Kc(r)}return t}ne();var R0=G("prompt-multimodal"),C0=10*1024*1024,Z_=15e3,V_=6;async function D0(t){let e=new Array(t.length),r=0;async function i(){for(;r<t.length;){let c=r++,d=t[c];d!==void 0&&(e[c]=await J_(d))}}let o=Array.from({length:Math.min(V_,t.length)},()=>i());return await Promise.all(o),e}function k0(t){return t.some(e=>e.type==="image")}async function J_(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Zs(e.uri))return t;try{let{buf:r,contentType:i}=await X_(e.uri),o=e.mimeType||Y_(i)||"application/octet-stream";return R0.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 R0.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function Y_(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function X_(t){let e=new AbortController,r=setTimeout(()=>e.abort(),Z_);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>C0)throw new Error(`image too large: ${o.byteLength} bytes (max ${C0})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}tn();qe();ne();var $=G("core"),eE=3e4,tE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,nE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",rE="\u5BA1\u6279\u5DF2\u8D85\u65F6",iE=3e4,ho=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Sr;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=E0(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(),$.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){$.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),$.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){$.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)&&$.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,r,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,d)=>{$.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:d}),Di(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){$.info("reject pendingUpstream entries (downstream gone)",{reason:r,count:i.length});for(let o of i){let c=this.pendingUpstream.get(o);if(c){this.pendingUpstream.delete(o),this.upstream.send(mn(o,{code:Q.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(d=>$.debug("send error response to upstream failed (ignored)",{err:String(d)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:Q.INTERNAL_ERROR,message:`bridge: ${r}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,r=this.pendingBridge.size;if(!(e===0&&r===0)){$.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:r});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:Q.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new T("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(eo(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let r="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&tE.test(i)?this.currentCozeEnv=i:i&&$.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}`):$.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(vr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(vr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(vr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,Q.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):$.warn("drop unknown notification",{method:e.method})}catch(o){$.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(mn(r,Ci(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new T("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new T("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new T("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new T("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||!c)return this.dispatchSessionCall(o,e.method,r);if(e.method==="session/prompt"){let h=o.sessions.get(c);if(h?.pendingPermission){let x=r._meta?.cozeTriggerMsgId,m=Rc(r._meta);return $.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,h,c,nE,x,m)}}let d=Date.now(),f=!1;try{let h=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return f=!0,h}finally{$.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-d,ok:f})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=pu(i);switch(r){case"session/new":{let c=sE();return $.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return $.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,d=c.sessionId;if(!d)throw new T("IPC_BAD_REQUEST","session/prompt: missing sessionId");let f=await this.ensureRuntime(e,d);if(f.replySeq=0,await this.ensureDownstream(e,d,f),!f.downstream||!f.acpSessionId)throw new T("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");let h=i._meta?.cozeTriggerMsgId;h?e.activeTriggers.set(f.acpSessionId,h):e.activeTriggers.delete(f.acpSessionId);let x=Rc(i._meta);if(x?e.activeGroupIds.set(f.acpSessionId,x):e.activeGroupIds.delete(f.acpSessionId),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&k0(c.prompt))throw new T("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let m=await D0(c.prompt);try{let g=await f.downstream.sessionPrompt({...c,sessionId:f.acpSessionId,prompt:m});return f.lastActiveAt=Date.now(),g}catch(g){if(g instanceof T&&g.code==="AGENT_APPROVAL_TIMEOUT"){let A=f.pendingPermission;A&&(A.downstream.respondAgentRequest(A.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(A.upstreamId),f.pendingPermission=void 0);let w=f.acpSessionId,E=w?e.activeTriggers.get(w):void 0,I=w?e.activeGroupIds.get(w):void 0;return $.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:d}),await this.synthesizePromptReply(e,f,d,rE,E,I)}throw g}finally{if(e.activeTriggers.delete(f.acpSessionId),e.activeGroupIds.delete(f.acpSessionId),f.pendingPermission=void 0,f.reloadAfterTurn){f.reloadAfterTurn=!1;let g=f.downstream;g&&(f.downstream=void 0,$.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:d,acpId:f.acpSessionId}),g.stop("reload-after-turn").catch(A=>$.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:d,err:String(A)})))}else f.downstream?.isAlive()&&this.armIdleTimer(e,d,f)}}case"session/cancel":{let d=o.sessionId;if(!d)throw new T("IPC_BAD_REQUEST","session/cancel: missing sessionId");let f=e.sessions.get(d);if(e.hasSessionQueue(d)){let h=e.getSessionQueue(d);h.size>0&&($.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:d,queuedCount:h.size}),h.dispose(new T("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${d}`)))}return f?.downstream?.isAlive()&&f.acpSessionId&&await f.downstream.sessionCancel({sessionId:f.acpSessionId}),{ok:!0}}default:throw new T("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async ensureRuntime(e,r){let i=e.sessions.get(r);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,r):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return e.sessions.set(r,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,r){let i={sessionId:r,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(mt.GEN_MODEL_TOKEN,i,iE);if(!o?.modelToken)throw new T("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof T&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new T("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(Di(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new T("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,d=i.spawnFailCount??0,f=i.spawnFailedAt??0;if(d>=o&&Date.now()-f<c)throw new T("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${d} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-f))/1e3)}s`);let h;try{h=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(x){throw i.spawnFailCount=d+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&($.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),x}if(i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=h,this.attachRuntimeHooks(e,r,i),i.acpSessionId){i.loadingSession=!0;try{await h.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),$.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(x){$.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 h.sessionNew({cwd:e.workspace});i.acpSessionId=m.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let x=await h.sessionNew({cwd:e.workspace});i.acpSessionId=x.sessionId,await this.persistSessionMapping(e)}h.afterSessionEstablished&&i.acpSessionId&&await h.afterSessionEstablished(i.acpSessionId)}armIdleTimer(e,r,i){if(Di(i),this.isRuntimeBusy(e,i)){$.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)){$.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}$.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=>$.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:r,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,r){if(r.acpSessionId&&e.activeTriggers.has(r.acpSessionId))return!0;let i=r.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,r,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};if(r.acpSessionId){let d=e.activeTriggers.get(r.acpSessionId);d&&(c.cozeTriggerMsgId=d);let f=e.activeGroupIds.get(r.acpSessionId);f&&(c.cozeGroupId=f)}await this.upstream.send(br("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,d){let f={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(f.cozeTriggerMsgId=c),d&&(f.cozeGroupId=d),await this.upstream.send(br("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:f})).catch(h=>$.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){$.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){$.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(cE(r)){$.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let d={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},f=e.activeTriggers.get(i);f&&(d.cozeTriggerMsgId=f);let h=e.activeGroupIds.get(i);h&&(d.cozeGroupId=h),this.upstream.send(br("session/update",{...r,sessionId:o,_meta:d})).catch(x=>$.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}$.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:Q.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},d=await I0(c,o);r.respondAgentRequest(i.id,d)}else{let c=i.params??{},d=await A0(c,o);r.respondAgentRequest(i.id,d)}}catch(o){$.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Ci(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},f=c.sessionId,h=f?e.activeTriggers.get(f):void 0,x={cozeAgentId:e.agentId};h&&(x.cozeTriggerMsgId=h);let m=f?e.activeGroupIds.get(f):void 0;m&&(x.cozeGroupId=m);let g=f?this.reverseSessionId(e,f):void 0,A=g?e.sessions.get(g):void 0;A&&(A.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let w={...c,...g?{sessionId:g}:{},_meta:x};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:g}),$.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:f,cloudSessionId:g,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(E=>({optionId:E.optionId,kind:E.kind,name:E.name}))}),this.upstream.send(Ti(o,"session/request_permission",w)).catch(E=>{this.pendingUpstream.delete(o),$.error("forward permission request failed",{agentId:e.agentId,err:String(E)}),r.respondAgentRequestError(i.id,{code:Q.INTERNAL_ERROR,message:`upstream send failed: ${String(E)}`})})}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?($.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"&&oE(e.result,o),$.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 Qs(e.error)):i.value.resolve(e.result);return}$.debug("orphan upstream response (no pending)",{id:e.id})}lookupPending(e,r,i){let o=e.get(r);if(o)return{value:o,key:r};if(typeof r=="number"){let c=String(r),d=e.get(c);if(d)return $.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:d,key:c}}}sendRequest(e,r,i=eE){let o=this.upstreamIds.next(e);return new Promise((c,d)=>{let f=setTimeout(()=>{this.pendingBridge.delete(o),d(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:d,timer:f}),this.upstream.send(Ti(o,e,r)).catch(h=>{let x=this.pendingBridge.get(o);x&&(clearTimeout(x.timer),this.pendingBridge.delete(o)),d(h)})})}async persistSessionMapping(e){if(this.paths)try{let r=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),r.set(i,c)}await Vr(e.agentId,r,this.paths)}catch(r){$.warn("persist session mapping failed",{agentId:e.agentId,err:String(r)})}}reverseSessionId(e,r){for(let[i,o]of e.sessions.entries())if(o.acpSessionId===r)return i}sendError(e,r,i){return this.upstream.send(mn(e,{code:r,message:i,data:{bridgeVersion:Er}}))}};function sE(){return Q_(16).toString("hex")}function oE(t,e){if(!t||typeof t!="object"){$.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){$.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"){$.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")&&$.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var aE=["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 cE(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 aE.some(c=>o.startsWith(c))}ne();ke();import{randomBytes as dE}from"node:crypto";import{chmod as lE,mkdir as fE,writeFile as O0}from"node:fs/promises";import{createServer as uE}from"node:http";import{dirname as hE}from"node:path";var xE=1e6,Zc=G("ipc"),xo=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??Y()}async start(){this.token=dE(32).toString("hex");let e=uE((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(),Zc.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 fE(hE(this.paths.portFile),{recursive:!0}),await O0(this.paths.portFile,String(this.port),"utf8"),await O0(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await lE(this.paths.tokenFile,384)}catch(e){Zc.warn("chmod token file failed (non-POSIX?)",{err:String(e)})}}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Li(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Li(r,404,{error:"not found"});return}let d=null;if(e.method==="POST")try{d=await pE(e)}catch(f){Li(r,400,{error:"invalid json",detail:String(f)});return}try{let f=await c.handler(d,e);Li(r,200,f??{ok:!0})}catch(f){Zc.error("IPC handler failed",{key:o,err:String(f)}),Li(r,500,{error:f instanceof Error?f.message:String(f)})}}};function Li(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function pE(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>xE)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}var ex=bt(H0(),1);var Vb=bt(zh(),1),Jb=bt(Do(),1),Yb=bt(Rr(),1),Xb=bt(ad(),1),Qb=bt(ld(),1),e1=bt(gd(),1),Kh=bt(Lo(),1),t1=bt($h(),1);var Zh=Kh.default;qe();ne();var Ce=G("upstream.frontier"),Jh="application/json",Yh="none",r1=15e3;function i1(t){class e extends Zh{constructor(i){super(i,mu,{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(nl("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let d=Buffer.from(c.slice(0,128)).toString("hex");Ce.debug("WS raw frame out",{bytes:c.byteLength,headHex:d})}catch(c){Ce.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var Hi=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:wu,...yr(this.opts.ppeOverride)},r=i1(e),i=_u(this.opts.urlOverride),o={url:i,ws:r,fpID:gu,aID:Js,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Jh,force:!0},payloadEncoding:{encoding:Yh,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new ex.FWS(o),d=!1,f=null,h,x,m=new Promise((w,E)=>{h=w,x=E}),g=w=>{d||(d=!0,f&&(clearTimeout(f),f=null),w?x(w):h())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let w=this.openCount===1;Ce.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:w,openCount:this.openCount}),w&&g();for(let E of this.connectHandlers)Promise.resolve(E({initial:w})).catch(I=>Ce.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=w=>{this.opened=!1,Ce.info("frontier closed",{code:w.code,reason:w.reason,willReconnect:w.willReconnect})},c.onerror=w=>{Ce.warn("frontier error",{code:w.code,msg:w.message}),g(new T("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${w.code} msg=${w.message??""}`))},c.onmessage=w=>this.handleMessage(w),this.fws=c;let A=this.opts.openTimeoutMs??r1;f=setTimeout(()=>{g(new T("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${A}ms (handshake or upgrade slow)`))},A),await c.connect();try{await m}catch(w){try{c.close(1e3,"open failed")}catch(E){Ce.warn("fws close during start failure threw (ignored)",{err:String(E)})}throw this.fws=null,this.opened=!1,w}}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 T("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let f=Date.now();throw f-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=f,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new T("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${r.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;Xh(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:Jh,payloadEncoding:Yh})}catch(f){throw Ce.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(f)}),new T("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(f)}`,{cause:f})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){Ce.debug("drop non-adapter frontier frame",{service:r});return}let i=a1(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(d){Ce.warn("frontier message JSON parse failed",{err:String(d),head:i.slice(0,80)});return}let c=o;Xh(c)||Ce.info("frontier frame in",{logid:o1(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:s1(i)}),Promise.resolve(this.handler(o)).catch(d=>Ce.warn("frontier frame handler threw",{err:String(d)}))}};function Xh(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Qh=2e3;function s1(t){return t.length<=Qh?t:`${t.slice(0,Qh)}...<truncated, total ${t.length} chars>`}function o1(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function a1(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 wd=G("upstream.switchable"),Mo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;wd.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 wd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>wd.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 yd=G("upstream"),Lr=class{handler=null;async start(){yd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){yd.info("NoopUpstream stopped",{reason:e})}async send(e){yd.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)}};qe();ne();ne();ke();import{promises as _d}from"node:fs";import{dirname as c1}from"node:path";var d1=G("pat-token-store");async function Bo(t=Y()){try{let r=(await _d.readFile(t.patTokenFile,"utf8")).trim();return r.length>0?r:null}catch(e){let r=e?.code;return r!=="ENOENT"&&d1.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function qi(t,e=Y()){if(!t)throw new Error("writePatToken: empty patToken");await _d.mkdir(c1(e.patTokenFile),{recursive:!0}),await _d.writeFile(e.patTokenFile,t,{encoding:"utf8",mode:384})}ke();ke();import{promises as zo}from"node:fs";import{join as l1}from"node:path";function f1(t,e){return`#!/bin/sh
102
102
  exec ${JSON.stringify(e)} ${JSON.stringify(t)} "$@"
103
- `}function xv(t,e){return`@echo off\r
103
+ `}function u1(t,e){return`@echo off\r
104
104
  "${e}" "${t}" %*\r
105
- `}async function rh(t,e=X()){let r=e.binDir;await Go.mkdir(r,{recursive:!0});let i=uv(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?xv(t,o):fv(t,o);return await Go.readFile(i,"utf8").catch(()=>null)===c||(await Go.writeFile(i,c,"utf8"),process.platform!=="win32"&&await Go.chmod(i,493)),r}ne();Oe();import{execSync as ih}from"node:child_process";import{readFileSync as sh,unlinkSync as hv}from"node:fs";import{mkdir as pv,readFile as oh,unlink as ah,writeFile as gv}from"node:fs/promises";import{dirname as mv}from"node:path";function qo(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}var wv=G("single-instance"),Ho=class{pidFile;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??X().pidFile,e.processTitle&&(process.title=e.processTitle)}async acquire(){let e=await this.readExistingPid();return e!==null&&this.isAlive(e)?{kind:"already-running",pid:e}:(e!==null&&(wv.warn("removing stale pid file",{stalePid:e}),await ah(this.pidFile).catch(()=>{})),await pv(mv(this.pidFile),{recursive:!0}),await gv(this.pidFile,String(process.pid),"utf8"),this.acquired=!0,this.installCleanupHooks(),{kind:"acquired"})}async release(){if(this.acquired){try{(await oh(this.pidFile,"utf8")).trim()===String(process.pid)&&await ah(this.pidFile)}catch{}this.acquired=!1}}async readExistingPid(){try{let e=await oh(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 qo(e)?this.matchesDaemonTitle(e):!1}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let r=sh(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes("coze-bridge-daemon")||r.includes("lib/index.js"))}catch{}try{let r=ih(`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=ih(`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{sh(this.pidFile,"utf8").trim()===String(process.pid)&&hv(this.pidFile)}catch{}})}};jo();ne();var $n=G("daemon.upstream-watchdog"),Iv=12e4,Tv=9e5,Cv=3e4;function Id(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Wo=class{constructor(e){this.opts=e;this.softMs=e.softMs??Id("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",Iv),this.hardMs=e.hardMs??Id("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",Tv),this.intervalMs=e.intervalMs??Id("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",Cv),this.now=e.now??Date.now}opts;softMs;hardMs;intervalMs;now;timer=null;downSince=null;forcedAt=null;forcing=!1;lastTickAt=null;start(){this.timer||(this.timer=setInterval(()=>this.tick(),this.intervalMs),this.timer.unref?.(),$n.info("upstream watchdog started",{softMs:this.softMs,hardMs:this.hardMs,intervalMs:this.intervalMs}))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null),this.downSince=null,this.forcedAt=null,this.lastTickAt=null}tick(){let e=this.now();if(this.lastTickAt!==null&&e-this.lastTickAt>this.intervalMs*3&&(this.downSince!==null&&$n.warn("upstream watchdog: large tick gap (likely sleep/suspend), resetting downSince",{gapMs:e-this.lastTickAt}),this.downSince=null,this.forcedAt=null),this.lastTickAt=e,this.opts.isConnected()){this.downSince!==null&&$n.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,$n.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){$n.error("upstream watchdog: disconnected too long, exiting for supervisor restart",{downMs:r,hardMs:this.hardMs}),this.opts.onFatal(r);return}r>=this.softMs&&this.shouldForceNow(e)&&(this.forcedAt=e,this.forcing=!0,$n.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>$n.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var H=G("daemon"),Dv="coze-bridge-daemon";async function lh(){let t=X();process.env.COZE_BRIDGE_LOG_MODE!=="legacy"&&nl({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:O=>$e(O,t).logs,listAgentIds:()=>is(t)});let e=new Ho({processTitle:Dv}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await po(),o=i??{};ns({pid:process.pid}),H.info(i?"loaded bridge config":"initialized bridge config");try{let O=new Gn;o.frameworksCache=await O.detectAll(),H.info("refreshed frameworks_cache",{detected:Object.keys(o.frameworksCache)})}catch(O){H.warn("framework detection failed",{err:String(O)})}await Li(o);let c=new Fo(new Mr),l=null,u=new go({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(O,q,j,ie)=>{if(!l)throw new Error("agentManager not ready");return l.spawnSessionDownstream(O,q,j,ie)}});await kv(t,u);let x=new fo({paths:t,config:o,registry:u});l=x;let p,w,_=null,I={},E,v=null,A=null,S=null,C=new En;function P(O,q){return C.enqueue(()=>D(O,q))}function y(){A||(A=new Wo({isConnected:()=>c.isConnected(),forceReconnect:()=>S?P(S,{force:!0}):void 0,onFatal:O=>{if(process.env[$i]==="1"){H.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:O});return}H.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:O}),process.exit(1)}})),A.start()}async function D(O,q){let j=O,ie=j?.privatecode;if(!ie)throw new T("IPC_BAD_REQUEST","/connect requires privatecode");let Je=Ii(j.env),le=j.handshake_url,ue=j.frontier_url,St=dh(j.env,le,ue);if(S=j,!q?.force&&p===ie&&w===St){let me=await Rv(t);return u.agents.size===0&&me?(H.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),$o(t,x).catch(Ie=>H.warn("connect-noop auto-revive error (ignored)",{err:String(Ie)}))):H.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let ft=!!p&&p!==ie,Xt=w!==void 0&&w!==St,zt=ft||Xt,Qt=await Oc({privatecode:ie,...le?{endpoint:le}:{},ppeOverride:Je});if(zt){H.warn("connect config switched, resetting agents",{pcChanged:ft,envChanged:Xt,previousPc:p?Ko(p):"",nextPc:Ko(ie)});for(let me of[...u.agents.values()])await me.dispose("connect config switch").catch(()=>{}),u.agents.delete(me.agentId);u.disconnectedAgents.size>0&&(H.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Mr,"connect switch").catch(()=>{})}_=Qt.deviceId,ns({deviceId:_,pid:process.pid}),Zc({patToken:ie,env:j.env}).catch(me=>H.warn("coze-cli setup error (ignored)",{err:String(me)}));let Gr=new Wi({handshake:Qt,privatecode:ie,...ue?{urlOverride:ue}:{},ppeOverride:Je,getPatTokenForAgent:me=>u.agents.get(me)?.patToken});return await c.swap(Gr,"connect"),p=ie,w=St,I=Je,E=le,j.mock_scenario!==void 0&&(u.setMockScenario(j.mock_scenario),H.info("mock scenario set",{scenario:j.mock_scenario})),v||(v=new Ci({core:u,getDeviceId:()=>_??"",onTickEnd:()=>B.retryPending().catch(me=>H.warn("detailSync.retryPending failed (ignored)",{err:String(me)})),onAuthFailures:$})),v.start(),y(),zt&&$o(t,x).catch(me=>H.warn("post-connect-switch auto-revive error (ignored)",{err:String(me)})),Ki(ie,t).catch(me=>H.warn("writePatToken after /connect failed (ignored)",{err:String(me)})),H.info("/connect: WS established",{deviceId:_}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async O=>x.createAgent(O.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let k={},M=new to({agents:u.agents,disposeAndMarkDisconnected:async(O,q)=>{let j=u.agents.get(O);if(j){await x.cleanupOpenclawSessionProviders(j).catch(Je=>H.warn("cleanup openclaw providers failed (ignored)",{agentId:O,err:String(Je)}));let ie=!0;try{await j.dispose(`disconnect: ${q}`)}catch(Je){ie=!1,H.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:O,err:String(Je)}),j.status="error"}ie&&(j.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 x.cleanupOpenclawSessionProviders(O)},openclawRepair:async(O,q)=>{await x.openclawRepair(O,q)},isRuntimePendingPermission:O=>u.hasPendingPermissionFor(O)});u.registerExtension("_agent/listSkills",O=>M.listSkills(O.params)),u.registerExtension("_agent/addSkills",O=>M.addSkills(O.params)),u.registerExtension("_agent/removeSkills",O=>M.removeSkills(O.params)),u.registerExtension("_agent/getFileTree",O=>M.getFileTree(O.params)),u.registerExtension("_agent/getFileContent",O=>M.getFileContent(O.params)),u.registerExtension("_agent/update",O=>M.updateAgent(O.params)),u.registerExtension("_agent/disconnect",O=>M.disconnectAgent(O.params)),u.registerExtension("_agent/switchModel",O=>M.switchModel(O.params)),u.registerExtension("_agent/reset",O=>M.resetAgent(O.params)),u.registerExtension("_agent/repair",O=>M.repairAgent(O.params));let B=new cs({paths:t,handlers:M,sendDetail:O=>u.sendRequest("_agent/detail",O)});k.ref=B;let $=async O=>{await Promise.allSettled(O.map(async q=>{try{await M.disconnectAgent({agentId:q.agentId,reason:`auth_failure: code=${q.code} ${q.message}`}),H.info("agent disconnected due to auth failure from heartbeat response",{agentId:q.agentId,code:q.code,message:q.message})}catch(j){H.warn("disconnect during authFailure handling failed (ignored)",{agentId:q.agentId,err:String(j)})}}))};c.onConnect(({initial:O})=>{H.info("frontier upstream connected, triggering detail sync",{initial:O}),B.syncAll(O?"initial-connect":"reconnect").catch(q=>H.warn("detail sync top-level error (ignored)",{err:String(q)}))});let V=new mo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let O=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[$i]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:_??"",frameworksCache:o.frameworksCache??{},...O?{mockScenario:O}:{}}}},{method:"POST",path:"/pair",handler:async O=>{let q=O,j=q?.privatecode,ie=q?.pairing_code;if(!j||!ie)throw new T("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Je=Ii(q.env),le=q.handshake_url,ue=q.frontier_url,St=dh(q.env,le,ue),ft=!!p&&p!==j,Xt=w!==void 0&&w!==St,zt=ft||Xt,Qt=await Oc({privatecode:j,...le?{endpoint:le}:{},ppeOverride:Je});if(zt){H.warn("pair config switched, resetting agents",{pcChanged:ft,envChanged:Xt,previousPc:p?Ko(p):"",nextPc:Ko(j),previousEnvKey:w??"",nextEnvKey:St});for(let Ie of[...u.agents.values()])await Ie.dispose("pair config switch").catch(()=>{}),u.agents.delete(Ie.agentId);u.disconnectedAgents.size>0&&(H.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new Mr,"pair switch").catch(()=>{})}_=Qt.deviceId,ns({deviceId:_,pid:process.pid}),Zc({patToken:j,env:q.env}).catch(Ie=>H.warn("coze-cli setup error (ignored)",{err:String(Ie)}));let Gr=new Wi({handshake:Qt,privatecode:j,...ue?{urlOverride:ue}:{},ppeOverride:Je,getPatTokenForAgent:Ie=>u.agents.get(Ie)?.patToken});await c.swap(Gr,"pair");try{let Ie=new Gn;o.frameworksCache=await Ie.detectAll(),await Li(o),H.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ie){H.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ie)})}let me=Object.keys(o.frameworksCache??{});try{let Ie=await u.sendRequest("_agent/pair",{pairCode:ie,patToken:j,frameworks:me,_meta:{cozeDeviceId:_}});H.info("_agent/pair ok",{pairResult:Ie}),p=j,w=St,I=Je,E=le,q.mock_scenario!==void 0&&(u.setMockScenario(q.mock_scenario),H.info("mock scenario set",{scenario:q.mock_scenario})),Ki(j,t).catch(ke=>H.warn("writePatToken after /pair failed (ignored)",{err:String(ke)})),v||(v=new Ci({core:u,getDeviceId:()=>_??"",onTickEnd:()=>B.retryPending().catch(ke=>H.warn("detailSync.retryPending failed (ignored)",{err:String(ke)})),onAuthFailures:$})),v.start(),y(),zt&&$o(t,x).catch(ke=>H.warn("post-pair-switch auto-revive error (ignored)",{err:String(ke)}));let Vn;return q.agent_id&&(Vn=await Ov(q.agent_id,t,x,ke=>u.sendRequest("_agent/detail",ke),j).catch(ke=>(H.error("--agent-id ensureAgent failed",{agentId:q.agent_id,err:String(ke)}),{ok:!1,agentId:q.agent_id??"",note:String(ke)}))),{ok:!0,note:"paired with cloud",...Vn?{agent:Vn}:{}}}catch(Ie){return H.error("_agent/pair failed",{err:String(Ie)}),{ok:!1,note:`pair failed: ${String(Ie)}`}}}},{method:"POST",path:"/connect",handler:O=>P(O)},{method:"POST",path:"/_agent/create",handler:async O=>{let q=O;return{ok:!0,result:await x.createAgent(q)}}},{method:"POST",path:"/agent/send",handler:async O=>{let q=O;if(!q?.agentId||!q?.sessionId||!q?.kind||!q?.path)throw new T("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!p)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let j=q;return await(j.groupFile?mf:gf)(j,{core:u,patToken:p,handshakeBase:E,ppeOverride:I})}catch(j){if(j instanceof T)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 H.info("IPC /reload: recycled agent subprocesses",{agentId:q??"(all)",recycled:j}),{ok:!0,recycled:j}}},{method:"POST",path:"/shutdown",handler:async()=>(H.info("IPC /shutdown received"),setImmediate(()=>{he.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:te,token:Q}=await V.start();try{await rh(t.libEntry,t)}catch(O){H.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(O)})}await u.start(),$o(t,x).catch(O=>H.warn("auto-revive top-level error (ignored)",{err:String(O)})),fl().then(async()=>{let{probeAcpVersion:O}=await Promise.resolve().then(()=>(nn(),ll));for(let q of["claude-code","codex"]){let j=await O(q);j&&H.info("acp wrapper version",{framework:q,version:j})}}).catch(O=>H.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(O)}));let Ee=null,he={port:te,token:Q,core:u,ipc:V,shutdown(O){return Ee||(H.info("daemon shutdown",{reason:O}),Ee=(async()=>{v?.stop(),A?.stop(),await u.stop(O),await V.stop(),await e.release()})(),Ee)}};for(let O of["SIGTERM","SIGINT"])process.on(O,()=>{he.shutdown(O).then(()=>process.exit(0))});return process.on("unhandledRejection",O=>{H.error("unhandledRejection",{reason:O instanceof Error?O.message:String(O),stack:O instanceof Error?O.stack:void 0})}),process.on("uncaughtException",O=>{H.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)}),H.info("daemon ready",{port:te,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),Pv({cliSpawned:process.env[$i]==="1",readPatToken:()=>Uo(t),connect:P}).catch(O=>H.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(O)})),he}async function Rv(t){return is(t).length>0}function Ko(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function dh(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function kv(t,e){let r=is(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(rn(),as));for(let c of r){await o(c,t).catch(l=>H.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(l)}));try{let l=await i(c,t);l?.disconnectedAt&&(e.disconnectedAgents.add(c),H.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:l.disconnectedAt,reason:l.disconnectReason??""}))}catch(l){H.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(l)})}}}async function Ov(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(rn(),as)),l=await c(t,e);if(l){H.info("--agent-id: local config found, reconnecting",{agentId:t,framework:l.framework,hadDisconnect:!!l.disconnectedAt});let w={agentId:l.agentId,framework:l.framework,...l.cozeIdentity?{cozeIdentity:l.cozeIdentity}:{},...l.model?{model:l.model}:{},...o?{patToken:o}:{}};return await r.createAgent(w),{ok:!0,agentId:t,note:l.disconnectedAt?"revived from local config":"connected from local config"}}H.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let u=await i({_meta:{cozeAgentId:t}});if(!u.framework)throw new T("AGENT_NOT_FOUND",`agent ${t} \u4E0D\u5728\u672C\u5730; \u4E91\u7AEF _agent/detail \u54CD\u5E94\u7F3A framework \u5B57\u6BB5 (D36 \u534F\u8BAE\u6269\u5C55\u672A\u751F\u6548), \u65E0\u6CD5\u5728\u672C\u673A\u65B0\u5EFA`);let x={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...u.deployType?{_meta:{cozeDeployType:u.deployType}}:{}};await r.createAgent(x);let p=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:p?"cloud agent acknowledged":"created from cloud detail"}}async function $o(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(),as));H.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,l=0;for(let u of i){let x;try{x=await o(u,t)}catch(p){H.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(p)}),l+=1;continue}if(!x){l+=1;continue}if(x.disconnectedAt){H.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:x.disconnectedAt}),l+=1;continue}try{H.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:x.framework});let p=Lv(x);await e.createAgent({agentId:x.agentId,framework:x.framework,...x.cozeIdentity?{cozeIdentity:x.cozeIdentity}:{},...x.model?{model:x.model}:{},...p?{_meta:p}:{}},{revive:!0}),c+=1}catch(p){H.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:x.framework,err:String(p)}),l+=1}}return H.info("auto-revive: done",{revived:c,skipped:l,total:i.length}),{revived:c,skipped:l,total:i.length}}async function Pv(t){let e=t.logger??H;if(t.cliSpawned)return"skipped-cli";let r=await t.readPatToken();return r?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:r}).catch(i=>e.warn("startup auto-connect failed (staying idle)",{err:String(i)})),"connecting"):(e.info("no stored PAT, skip startup auto-connect"),"skipped-no-pat")}function Lv(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}jo();Oe();import{readFile as uh}from"node:fs/promises";var Yt=class{paths;constructor(e){this.paths=e??X()}async probe(e=1e3){let r=await Vo(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:Mv(i)}}}async request(e){let r=await Vo(this.paths);if(!r)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(r,e)}async fetch(e,r){let i=r.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,l=setTimeout(()=>c.abort(),r.timeoutMs??5e3);try{let u=await fetch(`http://127.0.0.1:${e.port}${r.path}`,{method:r.method,headers:o,body:i?JSON.stringify(r.body):void 0,signal:c.signal}),x=await u.text();return{status:u.status,body:Nv(x)}}finally{clearTimeout(l)}}};async function Vo(t){try{let[e,r]=await Promise.all([uh(t.portFile,"utf8"),uh(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 Nv(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function Mv(t){return t instanceof Error?t.message:String(t)}yn();ne();Oe();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 Bv,copyFile as fh,mkdir as hh,readFile as Jo,rename as xh,rm as Td,stat as ph,writeFile as zv}from"node:fs/promises";import{homedir as pD}from"node:os";import{dirname as Fv,join as Br,resolve as Cd,sep as Vi}from"node:path";import{fileURLToPath as Uv}from"node:url";yn();ne();Oe();var Dd=G("dist-install");function Gv(t){let e=Uv(t),r=Fv(e),i=`${Vi}src${Vi}`;if(r.includes(i)||r.endsWith(`${Vi}src${Vi}cli`))return null;let o=Cd(r,"index.js"),c=Cd(r,"..","package.json");return{dist:o,pkgJson:c}}async function kd(t={}){let e=t.paths??X(),r=Gv(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 I=JSON.parse(await Jo(o,"utf8"));c=I.version??"unknown",l=I.dependencies??{}}catch(I){return Dd.warn("cannot read source package.json,skip dist install",{err:String(I)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(I)}`}}let u=$r.map(I=>`${I}@${l[I]??"latest"}`),x=await po(e.configFile)??{},p=x.libVersion,w=await Jo(e.libEntry).then(()=>!0).catch(()=>!1),_=p===c;if(_&&w&&await Rd(e))return{kind:"already-current",libVersion:c};if(!_||!w){await hh(e.libDir,{recursive:!0}),await fh(i,e.libEntry),await fh(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let I=Cd(e.libDir,"package.json"),E=`${JSON.stringify({type:"module"},null,2)}
107
- `;await Jo(I,"utf8").catch(()=>null)!==E&&await zv(I,E)}return(!_||!await Rd(e))&&await(t.installWrappers??qv)(e,u),x.libVersion=c,await Li(x,e.configFile),Dd.info("dist installed",{libEntry:e.libEntry,fromVersion:p,toVersion:c}),_&&w?{kind:"already-current",libVersion:c}:p?{kind:"version-changed",fromVersion:p,toVersion:c,libEntry:e.libEntry}:{kind:"first-install",libVersion:c,libEntry:e.libEntry}}async function Rd(t){for(let e of $r){let r=Br(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await ph(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function qv(t,e){await Wv(t.installLock,async()=>{if(await Rd(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${Vi}.staging-${process.pid}-${r}`,o=Br(i,"node_modules"),c=Br(t.libDir,"node_modules");try{await hh(i,{recursive:!0}),await Hv(e,i),await jv(o);let l=`${c}.trash-${r}`;await xh(c,l).catch(()=>{}),await xh(o,c),await Td(l,{recursive:!0,force:!0}).catch(()=>{}),Dd.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await Td(i,{recursive:!0,force:!0}).catch(()=>{})}})}function Hv(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=dt("npm",r,{stdio:["ignore","pipe","pipe"]}),l="";c.stderr?.on("data",x=>{l.length<8192&&(l+=x.toString("utf8"))});let u=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",x=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(x)}`))}),c.once("close",x=>{clearTimeout(u),x===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${x}: ${l.trim().slice(0,2e3)}`))})})}async function jv(t){for(let e of $r){let r=Br(t,...e.split("/")),i=JSON.parse(await Jo(Br(r,"package.json"),"utf8"));if(!i.version)throw new Error(`${e}: package.json \u7F3A version`);let o=typeof i.bin=="string"?e.split("/").pop():Object.keys(i.bin??{})[0];if(!o)throw new Error(`${e}: package.json \u7F3A bin`);let c=Br(t,".bin",o),l=await ph(c);process.platform!=="win32"&&!(l.mode&73)&&await Bv(c,l.mode|73).catch(()=>{})}}async function Wv(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 Td(t,{force:!0}).catch(()=>{})}}ma();ne();Oe();import{closeSync as mh,fstatSync as wh,openSync as _h,readFileSync as Kv,readSync as $v,readdirSync as Vv,statSync as Jv}from"node:fs";import{join as Zo}from"node:path";var Zv=new Set(["debug","info","warn","error"]);function yh(t){let e=t,r=Sn(e,"--agent-id");e=r.rest;let i=Sn(e,"--date");e=i.rest;let o=Sn(e,"-n","--lines");e=o.rest;let c=Sn(e,"--level");e=c.rest;let l=Sn(e,"--grep");e=l.rest;let u=o.value===void 0?200:Number(o.value),x=Number.isInteger(u)&&u>=0?u:200,p=c.value&&Zv.has(c.value)?c.value:void 0,w={lines:x,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(w.agentId=r.value),i.value&&(w.date=i.value),p&&(w.level=p),l.value&&(w.grep=l.value),w}function Yv(t,e){return t.agentId?Zo($e(t.agentId,e).logs,Xn("agent",t.date)):Zo(e.bridgeLogsDir,Xn("bridge",t.date))}function Xv(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function Qv(t,e){let r;try{r=Vv(t)}catch{return[]}let i=[];for(let o of r){let c=ga(o,e);if(!c)continue;let l=0;try{l=Jv(Zo(t,o)).size}catch{}i.push({file:Zo(t,o),date:c,size:l})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function Eh(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"&&!sl(r,e.level))return!1}return!0}var gh={debug:"90",info:"36",warn:"33",error:"31"},eS=new Set(["ts","level","module","msg"]);function tS(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function bh(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=tS(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&gh[o]&&(c=`\x1B[${gh[o]}m${c}\x1B[0m`);let l=typeof r.module=="string"?r.module:"",u=typeof r.msg=="string"?r.msg:"",x=Object.entries(r).filter(([p])=>!eS.has(p)).map(([p,w])=>` ${p}=${typeof w=="string"?w:JSON.stringify(w)}`).join("");return`${i} ${c} ${l} ${u}${x}`}function nS(t,e,r){let c=Kv(t,"utf8").split(`
108
- `).filter(l=>l.length>0).filter(l=>Eh(l,{level:e.level,grep:e.grep}));for(let l of Xv(c,e.lines))process.stdout.write(`${bh(l,{raw:e.raw,color:r})}
109
- `)}async function vh(t,e){let r=e.paths??X(),i=process.stdout.isTTY===!0;if(t.list){let l=t.agentId?$e(t.agentId,r).logs:r.bridgeLogsDir,u=t.agentId?"agent":"bridge",x=Qv(l,u);if(x.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${l}
110
- `),1;for(let p of x)process.stdout.write(`${p.date} ${(p.size/1024).toFixed(1)}KB ${p.file}
111
- `);return 0}let o=t.date??In(new Date),c=Yv({agentId:t.agentId,date:o},r);try{nS(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
105
+ `}async function tx(t,e=Y()){let r=e.binDir;await zo.mkdir(r,{recursive:!0});let i=l1(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?u1(t,o):f1(t,o);return await zo.readFile(i,"utf8").catch(()=>null)===c||(await zo.writeFile(i,c,"utf8"),process.platform!=="win32"&&await zo.chmod(i,493)),r}ne();ke();import{execSync as nx}from"node:child_process";import{readFileSync as rx,unlinkSync as h1}from"node:fs";import{mkdir as x1,readFile as ix,unlink as sx,writeFile as p1}from"node:fs/promises";import{dirname as g1}from"node:path";function Fo(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}var m1=G("single-instance"),Uo=class{pidFile;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??Y().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&&(m1.warn("removing stale pid file",{stalePid:e}),await sx(this.pidFile).catch(()=>{})),await x1(g1(this.pidFile),{recursive:!0}),await p1(this.pidFile,String(process.pid),"utf8"),this.acquired=!0,this.installCleanupHooks(),{kind:"acquired"})}async release(){if(this.acquired){try{(await ix(this.pidFile,"utf8")).trim()===String(process.pid)&&await sx(this.pidFile)}catch{}this.acquired=!1}}async readExistingPid(){try{let e=await ix(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 Fo(e)?this.matchesDaemonTitle(e):!1}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let r=rx(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes("coze-bridge-daemon")||r.includes("lib/index.js"))}catch{}try{let r=nx(`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=nx(`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{rx(this.pidFile,"utf8").trim()===String(process.pid)&&h1(this.pidFile)}catch{}})}};Go();ne();var Wn=G("daemon.upstream-watchdog"),I1=12e4,A1=9e5,T1=3e4;function bd(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var jo=class{constructor(e){this.opts=e;this.softMs=e.softMs??bd("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",I1),this.hardMs=e.hardMs??bd("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",A1),this.intervalMs=e.intervalMs??bd("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",T1),this.now=e.now??Date.now}opts;softMs;hardMs;intervalMs;now;timer=null;downSince=null;forcedAt=null;forcing=!1;lastTickAt=null;start(){this.timer||(this.timer=setInterval(()=>this.tick(),this.intervalMs),this.timer.unref?.(),Wn.info("upstream watchdog started",{softMs:this.softMs,hardMs:this.hardMs,intervalMs:this.intervalMs}))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null),this.downSince=null,this.forcedAt=null,this.lastTickAt=null}tick(){let e=this.now();if(this.lastTickAt!==null&&e-this.lastTickAt>this.intervalMs*3&&(this.downSince!==null&&Wn.warn("upstream watchdog: large tick gap (likely sleep/suspend), resetting downSince",{gapMs:e-this.lastTickAt}),this.downSince=null,this.forcedAt=null),this.lastTickAt=e,this.opts.isConnected()){this.downSince!==null&&Wn.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,Wn.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){Wn.error("upstream watchdog: disconnected too long, exiting for supervisor restart",{downMs:r,hardMs:this.hardMs}),this.opts.onFatal(r);return}r>=this.softMs&&this.shouldForceNow(e)&&(this.forcedAt=e,this.forcing=!0,Wn.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>Wn.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var q=G("daemon"),R1="coze-bridge-daemon";async function cx(){let t=Y();process.env.COZE_BRIDGE_LOG_MODE!=="legacy"&&el({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:O=>Ze(O,t).logs,listAgentIds:()=>ts(t)});let e=new Uo({processTitle:R1}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await uo(),o=i??{};Qi({pid:process.pid}),q.info(i?"loaded bridge config":"initialized bridge config");try{let O=new Fn;o.frameworksCache=await O.detectAll(),q.info("refreshed frameworks_cache",{detected:Object.keys(o.frameworksCache)})}catch(O){q.warn("framework detection failed",{err:String(O)})}await Oi(o);let c=new Mo(new Lr),d=null,f=new ho({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(O,j,W,ie)=>{if(!d)throw new Error("agentManager not ready");return d.spawnSessionDownstream(O,j,W,ie)}});await D1(t,f);let h=new co({paths:t,config:o,registry:f});d=h;let x,m,g=null,A={},w,E=null,I=null,S=null,R=new yn;function P(O,j){return R.enqueue(()=>C(O,j))}function y(){I||(I=new jo({isConnected:()=>c.isConnected(),forceReconnect:()=>S?P(S,{force:!0}):void 0,onFatal:O=>{if(process.env[Wi]==="1"){q.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:O});return}q.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:O}),process.exit(1)}})),I.start()}async function C(O,j){let W=O,ie=W?.privatecode;if(!ie)throw new T("IPC_BAD_REQUEST","/connect requires privatecode");let $e=Si(W.env),le=W.handshake_url,fe=W.frontier_url,Et=ax(W.env,le,fe);if(S=W,!j?.force&&x===ie&&m===Et){let ge=await C1(t);return f.agents.size===0&&ge?(q.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),qo(t,h).catch(Ie=>q.warn("connect-noop auto-revive error (ignored)",{err:String(Ie)}))):q.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let lt=!!x&&x!==ie,Vt=m!==void 0&&m!==Et,Nt=lt||Vt,Jt=await Cc({privatecode:ie,...le?{endpoint:le}:{},ppeOverride:$e});if(Nt){q.warn("connect config switched, resetting agents",{pcChanged:lt,envChanged:Vt,previousPc:x?Ho(x):"",nextPc:Ho(ie)});for(let ge of[...f.agents.values()])await ge.dispose("connect config switch").catch(()=>{}),f.agents.delete(ge.agentId);f.disconnectedAgents.size>0&&(q.info("clearing disconnectedAgents set on connect config switch",{count:f.disconnectedAgents.size}),f.disconnectedAgents.clear()),await c.swap(new Lr,"connect switch").catch(()=>{})}g=Jt.deviceId,Qi({deviceId:g,pid:process.pid}),$c({patToken:ie,env:W.env}).catch(ge=>q.warn("coze-cli setup error (ignored)",{err:String(ge)}));let Fr=new Hi({handshake:Jt,privatecode:ie,...fe?{urlOverride:fe}:{},ppeOverride:$e,getPatTokenForAgent:ge=>f.agents.get(ge)?.patToken});return await c.swap(Fr,"connect"),x=ie,m=Et,A=$e,w=le,W.mock_scenario!==void 0&&(f.setMockScenario(W.mock_scenario),q.info("mock scenario set",{scenario:W.mock_scenario})),E||(E=new Ai({core:f,getDeviceId:()=>g??"",onTickEnd:()=>M.retryPending().catch(ge=>q.warn("detailSync.retryPending failed (ignored)",{err:String(ge)})),onAuthFailures:K})),E.start(),y(),Nt&&qo(t,h).catch(ge=>q.warn("post-connect-switch auto-revive error (ignored)",{err:String(ge)})),qi(ie,t).catch(ge=>q.warn("writePatToken after /connect failed (ignored)",{err:String(ge)})),q.info("/connect: WS established",{deviceId:g}),{ok:!0,note:"connected"}}f.registerExtension("_agent/create",async O=>h.createAgent(O.params)),f.registerExtension("_agent/health",async()=>({ok:!0}));let D={},N=new Xs({agents:f.agents,disposeAndMarkDisconnected:async(O,j)=>{let W=f.agents.get(O);if(W){await h.cleanupOpenclawSessionProviders(W).catch($e=>q.warn("cleanup openclaw providers failed (ignored)",{agentId:O,err:String($e)}));let ie=!0;try{await W.dispose(`disconnect: ${j}`)}catch($e){ie=!1,q.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:O,err:String($e)}),W.status="error"}ie&&(W.status="disconnected",f.unregister(O),f.disconnectedAgents.add(O))}else f.disconnectedAgents.add(O)},detailSyncer:async O=>{if(!D.ref)throw new Error("agent-detail-sync not initialized yet");await D.ref.syncOne(O)},cleanupOpenclawProviders:async O=>{await h.cleanupOpenclawSessionProviders(O)},openclawRepair:async(O,j)=>{await h.openclawRepair(O,j)},isRuntimePendingPermission:O=>f.hasPendingPermissionFor(O)});f.registerExtension("_agent/listSkills",O=>N.listSkills(O.params)),f.registerExtension("_agent/addSkills",O=>N.addSkills(O.params)),f.registerExtension("_agent/removeSkills",O=>N.removeSkills(O.params)),f.registerExtension("_agent/getFileTree",O=>N.getFileTree(O.params)),f.registerExtension("_agent/getFileContent",O=>N.getFileContent(O.params)),f.registerExtension("_agent/update",O=>N.updateAgent(O.params)),f.registerExtension("_agent/disconnect",O=>N.disconnectAgent(O.params)),f.registerExtension("_agent/switchModel",O=>N.switchModel(O.params)),f.registerExtension("_agent/reset",O=>N.resetAgent(O.params)),f.registerExtension("_agent/repair",O=>N.repairAgent(O.params));let M=new ss({paths:t,handlers:N,sendDetail:O=>f.sendRequest("_agent/detail",O)});D.ref=M;let K=async O=>{await Promise.allSettled(O.map(async j=>{try{await N.disconnectAgent({agentId:j.agentId,reason:`auth_failure: code=${j.code} ${j.message}`}),q.info("agent disconnected due to auth failure from heartbeat response",{agentId:j.agentId,code:j.code,message:j.message})}catch(W){q.warn("disconnect during authFailure handling failed (ignored)",{agentId:j.agentId,err:String(W)})}}))};c.onConnect(({initial:O})=>{q.info("frontier upstream connected, triggering detail sync",{initial:O}),M.syncAll(O?"initial-connect":"reconnect").catch(j=>q.warn("detail sync top-level error (ignored)",{err:String(j)}))});let Z=new xo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let O=f.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[Wi]==="1"?"manual":"supervisor",agents:[...f.agents.keys()],deviceId:g??"",frameworksCache:o.frameworksCache??{},...O?{mockScenario:O}:{}}}},{method:"POST",path:"/pair",handler:async O=>{let j=O,W=j?.privatecode,ie=j?.pairing_code;if(!W||!ie)throw new T("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let $e=Si(j.env),le=j.handshake_url,fe=j.frontier_url,Et=ax(j.env,le,fe),lt=!!x&&x!==W,Vt=m!==void 0&&m!==Et,Nt=lt||Vt,Jt=await Cc({privatecode:W,...le?{endpoint:le}:{},ppeOverride:$e});if(Nt){q.warn("pair config switched, resetting agents",{pcChanged:lt,envChanged:Vt,previousPc:x?Ho(x):"",nextPc:Ho(W),previousEnvKey:m??"",nextEnvKey:Et});for(let Ie of[...f.agents.values()])await Ie.dispose("pair config switch").catch(()=>{}),f.agents.delete(Ie.agentId);f.disconnectedAgents.size>0&&(q.info("clearing disconnectedAgents set on pair config switch",{count:f.disconnectedAgents.size}),f.disconnectedAgents.clear()),await c.swap(new Lr,"pair switch").catch(()=>{})}g=Jt.deviceId,Qi({deviceId:g,pid:process.pid}),$c({patToken:W,env:j.env}).catch(Ie=>q.warn("coze-cli setup error (ignored)",{err:String(Ie)}));let Fr=new Hi({handshake:Jt,privatecode:W,...fe?{urlOverride:fe}:{},ppeOverride:$e,getPatTokenForAgent:Ie=>f.agents.get(Ie)?.patToken});await c.swap(Fr,"pair");try{let Ie=new Fn;o.frameworksCache=await Ie.detectAll(),await Oi(o),q.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ie){q.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ie)})}let ge=Object.keys(o.frameworksCache??{});try{let Ie=await f.sendRequest("_agent/pair",{pairCode:ie,patToken:W,frameworks:ge,_meta:{cozeDeviceId:g}});q.info("_agent/pair ok",{pairResult:Ie}),x=W,m=Et,A=$e,w=le,j.mock_scenario!==void 0&&(f.setMockScenario(j.mock_scenario),q.info("mock scenario set",{scenario:j.mock_scenario})),qi(W,t).catch(De=>q.warn("writePatToken after /pair failed (ignored)",{err:String(De)})),E||(E=new Ai({core:f,getDeviceId:()=>g??"",onTickEnd:()=>M.retryPending().catch(De=>q.warn("detailSync.retryPending failed (ignored)",{err:String(De)})),onAuthFailures:K})),E.start(),y(),Nt&&qo(t,h).catch(De=>q.warn("post-pair-switch auto-revive error (ignored)",{err:String(De)}));let $n;return j.agent_id&&($n=await k1(j.agent_id,t,h,De=>f.sendRequest("_agent/detail",De),W).catch(De=>(q.error("--agent-id ensureAgent failed",{agentId:j.agent_id,err:String(De)}),{ok:!1,agentId:j.agent_id??"",note:String(De)}))),{ok:!0,note:"paired with cloud",...$n?{agent:$n}:{}}}catch(Ie){return q.error("_agent/pair failed",{err:String(Ie)}),{ok:!1,note:`pair failed: ${String(Ie)}`}}}},{method:"POST",path:"/connect",handler:O=>P(O)},{method:"POST",path:"/_agent/create",handler:async O=>{let j=O;return{ok:!0,result:await h.createAgent(j)}}},{method:"POST",path:"/agent/send",handler:async O=>{let j=O;if(!j?.agentId||!j?.sessionId||!j?.kind||!j?.path)throw new T("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!x)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let W=j;return await(W.groupFile?g0:p0)(W,{core:f,patToken:x,handshakeBase:w,ppeOverride:A})}catch(W){if(W instanceof T)return{ok:!1,code:W.code,message:W.message};throw W}}},{method:"POST",path:"/reload",handler:async O=>{let j=O?.agent_id,W=await f.reloadAgents(j);return q.info("IPC /reload: recycled agent subprocesses",{agentId:j??"(all)",recycled:W}),{ok:!0,recycled:W}}},{method:"POST",path:"/shutdown",handler:async()=>(q.info("IPC /shutdown received"),setImmediate(()=>{he.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:te,token:X}=await Z.start();try{await tx(t.libEntry,t)}catch(O){q.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(O)})}await f.start(),qo(t,h).catch(O=>q.warn("auto-revive top-level error (ignored)",{err:String(O)})),ll().then(async()=>{let{probeAcpVersion:O}=await Promise.resolve().then(()=>(en(),cl));for(let j of["claude-code","codex"]){let W=await O(j);W&&q.info("acp wrapper version",{framework:j,version:W})}}).catch(O=>q.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(O)}));let _e=null,he={port:te,token:X,core:f,ipc:Z,shutdown(O){return _e||(q.info("daemon shutdown",{reason:O}),_e=(async()=>{E?.stop(),I?.stop(),await f.stop(O),await Z.stop(),await e.release()})(),_e)}};for(let O of["SIGTERM","SIGINT"])process.on(O,()=>{he.shutdown(O).then(()=>process.exit(0))});return process.on("unhandledRejection",O=>{q.error("unhandledRejection",{reason:O instanceof Error?O.message:String(O),stack:O instanceof Error?O.stack:void 0})}),process.on("uncaughtException",O=>{q.error("uncaughtException (will exit, supervisor will restart)",{message:O.message,stack:O.stack,name:O.name});try{process.stderr.write(`FATAL uncaughtException: ${O.stack??O.message}
106
+ `)}catch{}process.exit(1)}),q.info("daemon ready",{port:te,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),O1({cliSpawned:process.env[Wi]==="1",readPatToken:()=>Bo(t),connect:P}).catch(O=>q.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(O)})),he}async function C1(t){return ts(t).length>0}function Ho(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function ax(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function D1(t,e){let r=ts(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(tn(),is));for(let c of r){await o(c,t).catch(d=>q.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(d)}));try{let d=await i(c,t);d?.disconnectedAt&&(e.disconnectedAgents.add(c),q.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:d.disconnectedAt,reason:d.disconnectReason??""}))}catch(d){q.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(d)})}}}async function k1(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(tn(),is)),d=await c(t,e);if(d){q.info("--agent-id: local config found, reconnecting",{agentId:t,framework:d.framework,hadDisconnect:!!d.disconnectedAt});let m={agentId:d.agentId,framework:d.framework,...d.cozeIdentity?{cozeIdentity:d.cozeIdentity}:{},...d.model?{model:d.model}:{},...o?{patToken:o}:{}};return await r.createAgent(m),{ok:!0,agentId:t,note:d.disconnectedAt?"revived from local config":"connected from local config"}}q.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let f=await i({_meta:{cozeAgentId:t}});if(!f.framework)throw new T("AGENT_NOT_FOUND",`agent ${t} \u4E0D\u5728\u672C\u5730; \u4E91\u7AEF _agent/detail \u54CD\u5E94\u7F3A framework \u5B57\u6BB5 (D36 \u534F\u8BAE\u6269\u5C55\u672A\u751F\u6548), \u65E0\u6CD5\u5728\u672C\u673A\u65B0\u5EFA`);let h={agentId:f.agentId,framework:f.framework,...f.cozeIdentity?{cozeIdentity:f.cozeIdentity}:{},...f.model?{model:f.model}:{},...o?{patToken:o}:{},...f.deployType?{_meta:{cozeDeployType:f.deployType}}:{}};await r.createAgent(h);let x=f.deployType==="cloud"&&f.framework==="openclaw";return{ok:!0,agentId:t,note:x?"cloud agent acknowledged":"created from cloud detail"}}async function qo(t,e){let{readdir:r}=await import("node:fs/promises"),i;try{i=await r(t.agentsRoot)}catch{return{revived:0,skipped:0,total:0}}if(i.length===0)return{revived:0,skipped:0,total:0};let{loadAgentConfig:o}=await Promise.resolve().then(()=>(tn(),is));q.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,d=0;for(let f of i){let h;try{h=await o(f,t)}catch(x){q.warn("auto-revive: load config failed (skipping)",{agentId:f,err:String(x)}),d+=1;continue}if(!h){d+=1;continue}if(h.disconnectedAt){q.info("auto-revive: skip disconnected agent",{agentId:f,disconnectedAt:h.disconnectedAt}),d+=1;continue}try{q.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:f,framework:h.framework});let x=P1(h);await e.createAgent({agentId:h.agentId,framework:h.framework,...h.cozeIdentity?{cozeIdentity:h.cozeIdentity}:{},...h.model?{model:h.model}:{},...x?{_meta:x}:{}},{revive:!0}),c+=1}catch(x){q.warn("auto-revive: createAgent failed (skipping)",{agentId:f,framework:h.framework,err:String(x)}),d+=1}}return q.info("auto-revive: done",{revived:c,skipped:d,total:i.length}),{revived:c,skipped:d,total:i.length}}async function O1(t){let e=t.logger??q;if(t.cliSpawned)return"skipped-cli";let r=await t.readPatToken();return r?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:r}).catch(i=>e.warn("startup auto-connect failed (staying idle)",{err:String(i)})),"connecting"):(e.info("no stored PAT, skip startup auto-connect"),"skipped-no-pat")}function P1(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}Go();ke();import{readFile as dx}from"node:fs/promises";var Zt=class{paths;constructor(e){this.paths=e??Y()}async probe(e=1e3){let r=await Wo(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:N1(i)}}}async request(e){let r=await Wo(this.paths);if(!r)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(r,e)}async fetch(e,r){let i=r.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,d=setTimeout(()=>c.abort(),r.timeoutMs??5e3);try{let f=await fetch(`http://127.0.0.1:${e.port}${r.path}`,{method:r.method,headers:o,body:i?JSON.stringify(r.body):void 0,signal:c.signal}),h=await f.text();return{status:f.status,body:L1(h)}}finally{clearTimeout(d)}}};async function Wo(t){try{let[e,r]=await Promise.all([dx(t.portFile,"utf8"),dx(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 L1(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function N1(t){return t instanceof Error?t.message:String(t)}wn();ne();ke();function bn(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],d=!1;for(let f of e){if(c===f){i=t[o+1],o+=1,d=!0;break}if(c.startsWith(`${f}=`)){i=c.slice(f.length+1),d=!0;break}}d||r.push(c)}return{value:i,rest:r}}en();import{chmod as M1,copyFile as lx,mkdir as ux,readFile as $o,rename as fx,rm as vd,stat as hx,writeFile as B1}from"node:fs/promises";import{homedir as x3}from"node:os";import{dirname as z1,join as Nr,resolve as Sd,sep as $i}from"node:path";import{fileURLToPath as F1}from"node:url";wn();ne();ke();var Id=G("dist-install");function U1(t){let e=F1(t),r=z1(e),i=`${$i}src${$i}`;if(r.includes(i)||r.endsWith(`${$i}src${$i}cli`))return null;let o=Sd(r,"index.js"),c=Sd(r,"..","package.json");return{dist:o,pkgJson:c}}async function Td(t={}){let e=t.paths??Y(),r=U1(import.meta.url),i=t.sourceDist??r?.dist,o=t.sourcePackageJson??r?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,d;try{let A=JSON.parse(await $o(o,"utf8"));c=A.version??"unknown",d=A.dependencies??{}}catch(A){return Id.warn("cannot read source package.json,skip dist install",{err:String(A)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(A)}`}}let f=Wr.map(A=>`${A}@${d[A]??"latest"}`),h=await uo(e.configFile)??{},x=h.libVersion,m=await $o(e.libEntry).then(()=>!0).catch(()=>!1),g=x===c;if(g&&m&&await Ad(e))return{kind:"already-current",libVersion:c};if(!g||!m){await ux(e.libDir,{recursive:!0}),await lx(i,e.libEntry),await lx(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let A=Sd(e.libDir,"package.json"),w=`${JSON.stringify({type:"module"},null,2)}
107
+ `;await $o(A,"utf8").catch(()=>null)!==w&&await B1(A,w)}return(!g||!await Ad(e))&&await(t.installWrappers??G1)(e,f),h.libVersion=c,await Oi(h,e.configFile),Id.info("dist installed",{libEntry:e.libEntry,fromVersion:x,toVersion:c}),g&&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 Ad(t){for(let e of Wr){let r=Nr(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await hx(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function G1(t,e){await q1(t.installLock,async()=>{if(await Ad(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${$i}.staging-${process.pid}-${r}`,o=Nr(i,"node_modules"),c=Nr(t.libDir,"node_modules");try{await ux(i,{recursive:!0}),await j1(e,i),await H1(o);let d=`${c}.trash-${r}`;await fx(c,d).catch(()=>{}),await fx(o,c),await vd(d,{recursive:!0,force:!0}).catch(()=>{}),Id.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await vd(i,{recursive:!0,force:!0}).catch(()=>{})}})}function j1(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=at("npm",r,{stdio:["ignore","pipe","pipe"]}),d="";c.stderr?.on("data",h=>{d.length<8192&&(d+=h.toString("utf8"))});let f=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",h=>{clearTimeout(f),o(new Error(`spawn npm failed: ${String(h)}`))}),c.once("close",h=>{clearTimeout(f),h===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${h}: ${d.trim().slice(0,2e3)}`))})})}async function H1(t){for(let e of Wr){let r=Nr(t,...e.split("/")),i=JSON.parse(await $o(Nr(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=Nr(t,".bin",o),d=await hx(c);process.platform!=="win32"&&!(d.mode&73)&&await M1(c,d.mode|73).catch(()=>{})}}async function q1(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 vd(t,{force:!0}).catch(()=>{})}}xa();ne();ke();import{closeSync as px,fstatSync as gx,openSync as mx,readFileSync as W1,readSync as $1,readdirSync as K1,statSync as Z1}from"node:fs";import{join as Ko}from"node:path";var V1=new Set(["debug","info","warn","error"]);function yx(t){let e=t,r=bn(e,"--agent-id");e=r.rest;let i=bn(e,"--date");e=i.rest;let o=bn(e,"-n","--lines");e=o.rest;let c=bn(e,"--level");e=c.rest;let d=bn(e,"--grep");e=d.rest;let f=o.value===void 0?200:Number(o.value),h=Number.isInteger(f)&&f>=0?f:200,x=c.value&&V1.has(c.value)?c.value:void 0,m={lines:h,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(m.agentId=r.value),i.value&&(m.date=i.value),x&&(m.level=x),d.value&&(m.grep=d.value),m}function J1(t,e){return t.agentId?Ko(Ze(t.agentId,e).logs,Jn("agent",t.date)):Ko(e.bridgeLogsDir,Jn("bridge",t.date))}function Y1(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function X1(t,e){let r;try{r=K1(t)}catch{return[]}let i=[];for(let o of r){let c=ha(o,e);if(!c)continue;let d=0;try{d=Z1(Ko(t,o)).size}catch{}i.push({file:Ko(t,o),date:c,size:d})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function _x(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"&&!rl(r,e.level))return!1}return!0}var xx={debug:"90",info:"36",warn:"33",error:"31"},Q1=new Set(["ts","level","module","msg"]);function ev(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function Ex(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=ev(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&xx[o]&&(c=`\x1B[${xx[o]}m${c}\x1B[0m`);let d=typeof r.module=="string"?r.module:"",f=typeof r.msg=="string"?r.msg:"",h=Object.entries(r).filter(([x])=>!Q1.has(x)).map(([x,m])=>` ${x}=${typeof m=="string"?m:JSON.stringify(m)}`).join("");return`${i} ${c} ${d} ${f}${h}`}function tv(t,e,r){let c=W1(t,"utf8").split(`
108
+ `).filter(d=>d.length>0).filter(d=>_x(d,{level:e.level,grep:e.grep}));for(let d of Y1(c,e.lines))process.stdout.write(`${Ex(d,{raw:e.raw,color:r})}
109
+ `)}async function bx(t,e){let r=e.paths??Y(),i=process.stdout.isTTY===!0;if(t.list){let d=t.agentId?Ze(t.agentId,r).logs:r.bridgeLogsDir,f=t.agentId?"agent":"bridge",h=X1(d,f);if(h.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${d}
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??Sn(new Date),c=J1({agentId:t.agentId,date:o},r);try{tv(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
112
112
  \u7528 'coze-bridge log${t.agentId?` --agent-id ${t.agentId}`:""} --list' \u770B\u6709\u54EA\u4E9B\u65E5\u671F\u3002
113
113
  (legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${r.logFile})
114
- `),1}return t.follow&&await sS(c,t,i),0}var rS=500;function iS(t){try{let e=_h(t,"r");try{return wh(e).size}finally{mh(e)}}catch{return 0}}async function sS(t,e,r){let i=iS(t),o="",c=!1,l=()=>{c=!0};process.on("SIGINT",l);try{for(;!c;){let u="";try{let x=_h(t,"r");try{let p=wh(x).size;if(p>i){let w=Buffer.allocUnsafe(p-i),_=$v(x,w,0,w.length,i);u=w.subarray(0,_).toString("utf8"),i+=_}}finally{mh(x)}}catch{}if(u){let x=(o+u).split(`
115
- `);o=x.pop()??"";for(let p of x)p.length>0&&Eh(p,{level:e.level,grep:e.grep})&&process.stdout.write(`${bh(p,{raw:e.raw,color:r})}
116
- `)}await new Promise(x=>setTimeout(x,rS))}}finally{process.off("SIGINT",l)}}import{basename as oS,resolve as aS}from"node:path";Oe();var cS=9e4,dS={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 lS(t){return dS[t]??1}async function Sh(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 iv(c,t,i),0}var nv=500;function rv(t){try{let e=mx(t,"r");try{return gx(e).size}finally{px(e)}}catch{return 0}}async function iv(t,e,r){let i=rv(t),o="",c=!1,d=()=>{c=!0};process.on("SIGINT",d);try{for(;!c;){let f="";try{let h=mx(t,"r");try{let x=gx(h).size;if(x>i){let m=Buffer.allocUnsafe(x-i),g=$1(h,m,0,m.length,i);f=m.subarray(0,g).toString("utf8"),i+=g}}finally{px(h)}}catch{}if(f){let h=(o+f).split(`
115
+ `);o=h.pop()??"";for(let x of h)x.length>0&&_x(x,{level:e.level,grep:e.grep})&&process.stdout.write(`${Ex(x,{raw:e.raw,color:r})}
116
+ `)}await new Promise(h=>setTimeout(h,nv))}}finally{process.off("SIGINT",d)}}import{basename as sv,resolve as ov}from"node:path";ke();var av=9e4,cv={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 dv(t){return cv[t]??1}async function vx(t,e={}){let r=e.paths??Y();if(!t.agentId||!t.sessionId)return process.stderr.write(`Error: missing --agent-id and/or --session-id. These IDs come from the <coze-context> block injected at the top of each prompt \u2014 extract agentId and sessionId from there and pass them as flags. Example: coze-bridge send image x.png --agent-id <id> --session-id <id>
117
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.
118
- `),3;let i=await Vo(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:aS(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,cS)}catch(l){return process.stderr.write(`Error: daemon IPC failed: ${l instanceof Error?l.message:String(l)}
118
+ `),3;let i=await Wo(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:ov(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 lv(i,"/agent/send",o,av)}catch(d){return process.stderr.write(`Error: daemon IPC failed: ${d instanceof Error?d.message:String(d)}
120
120
  `),4}if(!c.ok)return process.stderr.write(`Error: ${c.code}: ${c.message}
121
- `),lS(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} (${fS(c.bytes)})
124
- `)}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(),x=u?JSON.parse(u):null;return x&&typeof x=="object"&&"ok"in x?x:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${l.status}): ${u.slice(0,200)}`}}finally{clearTimeout(c)}}function fS(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var Ph=G("cli");function qe(t,e){let{value:r,rest:i}=Sn(t,e);return{value:r,rest:i}}function na(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
125
- `)}function MS(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:C}=qe(e.slice(1),"--agent-id");return C?{mode:"reload",agentId:C}:{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 BS(e.slice(1));if(e[0]==="log")return{mode:"log",...yh(e.slice(1))};if(e[0]==="connect")return zS(e.slice(1));if(e.includes("--status"))return na("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return na("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return na("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return na("--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}=qe(r,"--pat-token");r=o;let{value:c,rest:l}=qe(r,"--pair-code");r=l;let{value:u,rest:x}=qe(r,"--env");r=x;let{value:p,rest:w}=qe(r,"--handshake-url");r=w;let{value:_,rest:I}=qe(r,"--frontier-url");r=I;let{value:E,rest:v}=qe(r,"--mock-scenario");r=v;let{value:A}=qe(r,"--agent-id");if(!i||!c)return{mode:"help"};let S={mode:"pair",privatecode:i,pairingCode:c};return u&&(S.env=u),p&&(S.handshakeUrl=p),_&&(S.frontierUrl=_),E&&(S.mockScenario=E),A&&(S.agentId=A),S}function BS(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}=qe(i,"--caption");i=c;let{value:l,rest:u}=qe(i,"--name");i=u;let{value:x,rest:p}=qe(i,"--agent-id");i=p;let{value:w,rest:_}=qe(i,"--session-id");i=_;let{value:I,rest:E}=qe(i,"--mime");i=E;let v=i.includes("--group-file");i=i.filter(C=>C!=="--group-file");let A=i.includes("--json"),S={mode:"send",kind:e,path:r,json:A};return o&&(S.caption=o),l&&(S.name=l),x&&(S.agentId=x),w&&(S.sessionId=w),v&&(S.groupFile=!0),I&&(S.mimeType=I),S}function zS(t){let e=t,{value:r,rest:i}=qe(e,"--pat-token");e=i;let{value:o,rest:c}=qe(e,"--env");e=c;let{value:l,rest:u}=qe(e,"--handshake-url");e=u;let{value:x,rest:p}=qe(e,"--frontier-url");e=p;let{value:w,rest:_}=qe(e,"--mock-scenario");e=_;let I={mode:"connect"};return r&&(I.privatecode=r),o&&(I.env=o),l&&(I.handshakeUrl=l),x&&(I.frontierUrl=x),w&&(I.mockScenario=w),I}var FS=`
121
+ `),dv(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
122
+ `);else{let d=t.name??sv(o.path);if(t.groupFile){let f=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${d} (uri=${f})
123
+ `)}else process.stdout.write(`Sent ${t.kind} ${d} (${fv(c.bytes)})
124
+ `)}return 0}async function lv(t,e,r,i){let o=new AbortController,c=setTimeout(()=>o.abort(),i);try{let d=await fetch(`http://127.0.0.1:${t.port}${e}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"content-type":"application/json"},body:JSON.stringify(r),signal:o.signal}),f=await d.text(),h=f?JSON.parse(f):null;return h&&typeof h=="object"&&"ok"in h?h:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${d.status}): ${f.slice(0,200)}`}}finally{clearTimeout(c)}}function fv(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var Ox=G("cli");function Ue(t,e){let{value:r,rest:i}=bn(t,e);return{value:r,rest:i}}function Qo(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
125
+ `)}function Nv(t){let e=t.slice(2);if(e.includes("--version")||e.includes("-v"))return{mode:"version"};if(e.includes("--daemon"))return{mode:"daemon"};if(e[0]==="status")return{mode:"status"};if(e[0]==="stop")return{mode:"stop"};if(e[0]==="reload"){let{value:R}=Ue(e.slice(1),"--agent-id");return R?{mode:"reload",agentId:R}:{mode:"reload"}}if(e[0]==="update")return{mode:"update"};if(e[0]==="purge")return{mode:"purge"};if(e[0]==="service")return e[1]==="install"?{mode:"service-install"}:e[1]==="uninstall"?{mode:"service-uninstall"}:{mode:"help"};if(e[0]==="send")return Mv(e.slice(1));if(e[0]==="log")return{mode:"log",...yx(e.slice(1))};if(e[0]==="connect")return Bv(e.slice(1));if(e.includes("--status"))return Qo("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return Qo("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return Qo("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return Qo("--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:d}=Ue(r,"--pair-code");r=d;let{value:f,rest:h}=Ue(r,"--env");r=h;let{value:x,rest:m}=Ue(r,"--handshake-url");r=m;let{value:g,rest:A}=Ue(r,"--frontier-url");r=A;let{value:w,rest:E}=Ue(r,"--mock-scenario");r=E;let{value:I}=Ue(r,"--agent-id");if(!i||!c)return{mode:"help"};let S={mode:"pair",privatecode:i,pairingCode:c};return f&&(S.env=f),x&&(S.handshakeUrl=x),g&&(S.frontierUrl=g),w&&(S.mockScenario=w),I&&(S.agentId=I),S}function Mv(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:d,rest:f}=Ue(i,"--name");i=f;let{value:h,rest:x}=Ue(i,"--agent-id");i=x;let{value:m,rest:g}=Ue(i,"--session-id");i=g;let{value:A,rest:w}=Ue(i,"--mime");i=w;let E=i.includes("--group-file");i=i.filter(R=>R!=="--group-file");let I=i.includes("--json"),S={mode:"send",kind:e,path:r,json:I};return o&&(S.caption=o),d&&(S.name=d),h&&(S.agentId=h),m&&(S.sessionId=m),E&&(S.groupFile=!0),A&&(S.mimeType=A),S}function Bv(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:d,rest:f}=Ue(e,"--handshake-url");e=f;let{value:h,rest:x}=Ue(e,"--frontier-url");e=x;let{value:m,rest:g}=Ue(e,"--mock-scenario");e=g;let A={mode:"connect"};return r&&(A.privatecode=r),o&&(A.env=o),d&&(A.handshakeUrl=d),h&&(A.frontierUrl=h),m&&(A.mockScenario=m),A}var zv=`
126
126
  coze-bridge - local bridge daemon for cloud Agent Service
127
127
 
128
128
  Pair (paste from cloud UI; start/reuse daemon and deliver pair-code):
@@ -201,56 +201,56 @@ Deprecated flags (still work, but emit a warning; will be removed in a future re
201
201
 
202
202
  Internal:
203
203
  <node> <entry> --daemon daemon mode (OS supervisor only)
204
- `.trimStart();async function Lh(t=process.argv,e={}){let r=MS(t);switch(r.mode){case"help":return process.stdout.write(FS),0;case"version":return process.stdout.write(`${vr}
205
- `),0;case"daemon":{try{await lh()}catch(i){return Ph.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return US(e);case"stop":return Mh(e);case"reload":return HS(r.agentId,e);case"log":return vh(r,e);case"update":return GS(e);case"purge":return jS(e);case"service-install":return WS(e);case"service-uninstall":return KS(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),$S(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),VS(r.privatecode,e,i)}case"send":return Sh({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 Nh(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 US(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
206
- `),1;if(i.kind==="stale")return await Nh(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
204
+ `.trimStart();async function Px(t=process.argv,e={}){let r=Nv(t);switch(r.mode){case"help":return process.stdout.write(zv),0;case"version":return process.stdout.write(`${Er}
205
+ `),0;case"daemon":{try{await cx()}catch(i){return Ox.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return Fv(e);case"stop":return Nx(e);case"reload":return jv(r.agentId,e);case"log":return bx(r,e);case"update":return Uv(e);case"purge":return Hv(e);case"service-install":return qv(e);case"service-uninstall":return Wv(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),$v(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),Kv(r.privatecode,e,i)}case"send":return vx({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 Lx(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 Fv(t){let e=t.paths??Y(),r=new Zt(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
206
+ `),1;if(i.kind==="stale")return await Lx(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
207
207
  `),1;let o=await r.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
208
208
  ${JSON.stringify(o.body,null,2)}
209
- `),0}async function Mh(t){let e=t.paths??X(),r=new Yt(e),i=await Zi(t),o=!1;if(i)try{await i.uninstall(),o=!0}catch(l){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(l)}
209
+ `),0}async function Nx(t){let e=t.paths??Y(),r=new Zt(e),i=await Zi(t),o=!1;if(i)try{await i.uninstall(),o=!0}catch(d){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(d)}
210
210
  `)}let c=await r.probe();if(c.kind==="not-running")return process.stdout.write(o?`coze-bridge: stopped
211
211
  `:`coze-bridge: not running
212
- `),0;if(c.kind==="stale")return await Nh(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
212
+ `),0;if(c.kind==="stale")return await Lx(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
213
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 GS(t){return await Mh(t),(t.spawnNpx??qS)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function qS(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 HS(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)
214
+ `),0}catch(d){return(await r.probe()).kind!=="connected"?(process.stdout.write(`coze-bridge: stopped
215
+ `),0):(process.stdout.write(`coze-bridge: stop failed: ${String(d)}
216
+ `),1)}}async function Uv(t){return await Nx(t),(t.spawnNpx??Gv)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function Gv(t){return new Promise(e=>{let r=at("npx",t,{stdio:"inherit"});r.on("exit",i=>e(i??1)),r.on("error",i=>{process.stderr.write(`coze-bridge: spawn npx failed: ${String(i)}
217
+ `),e(1)})})}async function jv(t,e){let r=new Zt(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
218
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)
219
219
  `):process.stdout.write(`coze-bridge: reloaded ${c.length} agent(s): ${c.join(", ")||"(none)"}
220
220
  `),0}return process.stderr.write(`coze-bridge: reload failed: ${JSON.stringify(o.body)}
221
221
  `),1}catch(o){return process.stderr.write(`coze-bridge: reload failed: ${String(o)}
222
- `),1}}async function Zi(t){if(t.supervisor){let c=t.supervisor,l={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:u=>c.install(l,u),uninstall:()=>c.uninstall(l)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>(kh(),Rh)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function Bh(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??ch,o=t.waitTimeoutMs??15e3,c=t.sleep??ZS,l=t.paths??X(),u=await Zi(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let x=await Oh(e,o,c);if(x.kind==="connected")return x;Wr(l.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:o})}catch(x){Wr(l.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(x)})}await u.uninstall().catch(()=>{}),await JS(l.pidFile,c)}else u&&await u.install({activate:!1}).catch(x=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(x)}
222
+ `),1}}async function Zi(t){if(t.supervisor){let c=t.supervisor,d={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:f=>c.install(d,f),uninstall:()=>c.uninstall(d)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>(Dx(),Cx)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function Mx(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??ox,o=t.waitTimeoutMs??15e3,c=t.sleep??Vv,d=t.paths??Y(),f=await Zi(t);if(f&&(f.platform==="darwin"||f.platform==="linux")){try{await f.install({activate:!0});let h=await kx(e,o,c);if(h.kind==="connected")return h;Hr(d.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:o})}catch(h){Hr(d.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(h)})}await f.uninstall().catch(()=>{}),await Zv(d.pidFile,c)}else f&&await f.install({activate:!1}).catch(h=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(h)}
223
223
  `));return process.stdout.write(`coze-bridge: starting daemon...
224
- `),await i({paths:t.paths}),Oh(e,o,c)}async function jS(t){let e=new Yt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
225
- `);try{await e.request({method:"POST",path:"/shutdown"})}catch(l){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(l)}
226
- `)}await new Promise(l=>setTimeout(l,500))}let i=await Zi(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
227
- `)}catch(l){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(l)}
228
- `)}let o=t.paths??X(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
229
- `)}catch(l){return process.stderr.write(`coze-bridge: remove failed: ${String(l)}
224
+ `),await i({paths:t.paths}),kx(e,o,c)}async function Hv(t){let e=new Zt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
225
+ `);try{await e.request({method:"POST",path:"/shutdown"})}catch(d){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(d)}
226
+ `)}await new Promise(d=>setTimeout(d,500))}let i=await Zi(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
227
+ `)}catch(d){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(d)}
228
+ `)}let o=t.paths??Y(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
229
+ `)}catch(d){return process.stderr.write(`coze-bridge: remove failed: ${String(d)}
230
230
  `),1}return process.stdout.write(`coze-bridge: purged (agents workspaces preserved under ~/.coze/agents)
231
- `),0}async function WS(t){let e=await Zi(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
231
+ `),0}async function qv(t){let e=await Zi(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
232
232
  `),await e.install(),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
233
233
  `),0}catch(r){return process.stderr.write(`coze-bridge: service install failed: ${String(r)}
234
- `),1}}async function KS(t){let e=await Zi(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
234
+ `),1}}async function Wv(t){let e=await Zi(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
235
235
  `),0}catch(r){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(r)}
236
- `),1}}async function $S(t,e,r,i={},o){let c=new Yt(r.paths),l=r.paths??X();if(await Wc(l).catch(p=>Wr(l.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(p)})),!r.skipDistInstall){let p=await kd({paths:r.paths});p.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${p.fromVersion} \u2192 ${p.toVersion}
237
- `),(await c.probe()).kind==="connected"&&(await c.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(_=>setTimeout(_,500)))):p.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${p.libVersion}
238
- `)}let u=await Bh(r,c);if(u.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${u.kind}
239
- `),1;let x={privatecode:t,pairing_code:e};i.env&&(x.env=i.env),i.handshakeUrl&&(x.handshake_url=i.handshakeUrl),i.frontierUrl&&(x.frontier_url=i.frontierUrl),i.mockScenario&&(x.mock_scenario=i.mockScenario),o&&(x.agent_id=o);try{let p=await c.request({method:"POST",path:"/pair",body:x,timeoutMs:35e3});if(p.status===200&&p.body?.ok){let w=p.body.agent;return w&&!w.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${w.agentId}): ${w.note}
236
+ `),1}}async function $v(t,e,r,i={},o){let c=new Zt(r.paths),d=r.paths??Y();if(await jc(d).catch(x=>Hr(d.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(x)})),!r.skipDistInstall){let x=await Td({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(g=>setTimeout(g,500)))):x.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${x.libVersion}
238
+ `)}let f=await Mx(r,c);if(f.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${f.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 m=x.body.agent;return m&&!m.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${m.agentId}): ${m.note}
240
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"
241
- `),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(p.body)}
242
- `),1}catch(p){return process.stderr.write(`coze-bridge: pair failed: ${String(p)}
243
- `),1}}async function VS(t,e,r={}){let i=e.paths??X(),o=t??await Uo(i);if(!o)return process.stderr.write("coze-bridge: \u627E\u4E0D\u5230 patToken \u2014 \u5148\u8DD1\u4E00\u6B21 `coze-bridge --pat-token=<sat_xxx> --pair-code=<xxx>` \u914D\u5BF9, \u6216\u672C\u6B21\u7528 `--pat-token` \u6307\u5B9A\n"),1;let c=new Yt(e.paths);if(await Wc(i).catch(x=>Wr(i.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(x)})),!e.skipDistInstall){let x=await kd({paths:e.paths});x.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${x.fromVersion} \u2192 ${x.toVersion}
244
- `),(await c.probe()).kind==="connected"&&(await c.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(w=>setTimeout(w,500)))):x.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${x.libVersion}
245
- `)}let l=await Bh(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 x=await c.request({method:"POST",path:"/connect",body:u,timeoutMs:35e3});return x.status===200&&x.body?.ok?(process.stdout.write(`coze-bridge: connected (${x.body.note??"ok"})
247
- `),await Ki(o,i).catch(p=>Ph.warn("writePatToken after connect failed (ignored)",{err:String(p)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(x.body)}
248
- `),1)}catch(x){return process.stderr.write(`coze-bridge: connect failed: ${String(x)}
249
- `),1}}async function Oh(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 JS(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||!qo(u))return;await e(i)}}function ZS(t){return new Promise(e=>setTimeout(e,t))}ne();function YS(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 zh(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=YS(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 Kv(t,e,r={}){let i=e.paths??Y(),o=t??await Bo(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 Zt(e.paths);if(await jc(i).catch(h=>Hr(i.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(h)})),!e.skipDistInstall){let h=await Td({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(m=>setTimeout(m,500)))):h.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${h.libVersion}
245
+ `)}let d=await Mx(e,c);if(d.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${d.kind}
246
+ `),1;let f={privatecode:o};r.env&&(f.env=r.env),r.handshakeUrl&&(f.handshake_url=r.handshakeUrl),r.frontierUrl&&(f.frontier_url=r.frontierUrl),r.mockScenario&&(f.mock_scenario=r.mockScenario);try{let h=await c.request({method:"POST",path:"/connect",body:f,timeoutMs:35e3});return h.status===200&&h.body?.ok?(process.stdout.write(`coze-bridge: connected (${h.body.note??"ok"})
247
+ `),await qi(o,i).catch(x=>Ox.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 kx(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 Zv(t,e,r=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let c=0;c<r;c++){let d;try{d=await o(t,"utf8")}catch{return}let f=Number.parseInt(d.trim(),10);if(!Number.isFinite(f)||f<=0||!Fo(f))return;await e(i)}}function Vv(t){return new Promise(e=>setTimeout(e,t))}ne();function Jv(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 Bx(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=Jv(t);if(i==="ok")return;let o=t.replace(/^v/,"");i==="fatal"?(e(`[coze-bridge] \u5F53\u524D Node.js \u7248\u672C v${o} \u8FC7\u4F4E,\u65E0\u6CD5\u8FD0\u884C(\u6700\u4F4E v18.4.0,\u63A8\u8350 v20+)\u3002\u8BF7\u5347\u7EA7\u540E\u91CD\u8BD5:https://nodejs.org(\u6216\u7528 nvm/fnm)\u3002
250
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
251
251
  \u5347\u7EA7\u5B8C\u540E\u9700\u8981\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u91CD\u65B0\u8FDE\u63A5:
252
252
  npx -y coze-bridge@latest stop
253
253
  npx -y coze-bridge@latest connect
254
254
 
255
- `)}zh();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&rl("warn");Lh(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
255
+ `)}Bx();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&tl("warn");Px(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
256
256
  `),process.exit(1)});