coze-bridge 0.1.104-alpha.21 → 0.1.104-alpha.23

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 +87 -85
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -5,34 +5,34 @@ import { dirname as __coze_dirname } from 'node:path';
5
5
  const require = __coze_createRequire(import.meta.url);
6
6
  const __filename = __coze_fileURLToPath(import.meta.url);
7
7
  const __dirname = __coze_dirname(__filename);
8
- var sg=Object.create;var Ea=Object.defineProperty;var og=Object.getOwnPropertyDescriptor;var ag=Object.getOwnPropertyNames;var cg=Object.getPrototypeOf,dg=Object.prototype.hasOwnProperty;var fe=(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 et=(t,e)=>()=>(t&&(e=t(t=0)),e);var ce=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),va=(t,e)=>{for(var r in e)Ea(t,r,{get:e[r],enumerable:!0})},lg=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ag(e))!dg.call(t,o)&&o!==r&&Ea(t,o,{get:()=>e[o],enumerable:!(i=og(e,o))||i.enumerable});return t};var qt=(t,e,r)=>(r=t!=null?sg(cg(t)):{},lg(e||!t||!t.__esModule?Ea(r,"default",{value:t,enumerable:!0}):r,t));function Ve(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var or=et(()=>{"use strict"});import{createWriteStream as ug,mkdirSync as fg,readdirSync as xg,unlinkSync as hg}from"node:fs";import{join as xl}from"node:path";function Ln(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function ar(t,e){return`${t}-${e}.log`}function Sa(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function pg(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 us(t,e,r,i){let o;try{o=xg(t)}catch{return}for(let c of o){let l=Sa(c,e);if(l&&pg(l,r,i))try{hg(xl(t,c))}catch{}}}var ri,Aa=et(()=>{"use strict";ri=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>Ln(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{fg(this.dir,{recursive:!0});let r=ug(xl(this.dir,ar(this.prefix,e)),{flags:"a"});r.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
8
+ var mg=Object.create;var ba=Object.defineProperty;var wg=Object.getOwnPropertyDescriptor;var _g=Object.getOwnPropertyNames;var yg=Object.getPrototypeOf,Eg=Object.prototype.hasOwnProperty;var le=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var et=(t,e)=>()=>(t&&(e=t(t=0)),e);var oe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),va=(t,e)=>{for(var r in e)ba(t,r,{get:e[r],enumerable:!0})},bg=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of _g(e))!Eg.call(t,o)&&o!==r&&ba(t,o,{get:()=>e[o],enumerable:!(i=wg(e,o))||i.enumerable});return t};var zt=(t,e,r)=>(r=t!=null?mg(yg(t)):{},bg(e||!t||!t.__esModule?ba(r,"default",{value:t,enumerable:!0}):r,t));function Ve(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var rr=et(()=>{"use strict"});import{createWriteStream as vg,mkdirSync as Sg,readdirSync as Ig,unlinkSync as Ag}from"node:fs";import{join as ml}from"node:path";function Cn(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function ir(t,e){return`${t}-${e}.log`}function Sa(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function kg(t,e,r){let i=c=>{let[d,u,f]=c.split("-").map(Number);return Date.UTC(d??0,(u??1)-1,f??1)};return Math.floor((i(e)-i(t))/864e5)>r}function cs(t,e,r,i){let o;try{o=Ig(t)}catch{return}for(let c of o){let d=Sa(c,e);if(d&&kg(d,r,i))try{Ag(ml(t,c))}catch{}}}var Xr,Ia=et(()=>{"use strict";Xr=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>Cn(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{Sg(this.dir,{recursive:!0});let r=vg(ml(this.dir,ir(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&&us(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 gg,mkdirSync as mg}from"node:fs";import{join as wg}from"node:path";function pl(t){let e=t.retentionDays??bg,r=t.clock??(()=>Ln(new Date));xs={bridgeSink:new ri(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new ri(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();us(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])us(t.agentLogsDir(o),"agent",i,e)}function Eg(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function gl(t){Ia=t}function ml(t){return cr[Ia]<=cr[t]}function wl(t,e){let r=cr[t];return r===void 0?!0:r>=cr[e]}function hs(t){hl={...t}}function _l(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`${Ln(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${l}`}function Ct(t,e,r,i,o){try{let c=`${JSON.stringify({ts:_l(new Date),level:e,module:r,msg:i,...o})}
11
- `;mg(t,{recursive:!0}),gg(wg(t,ar("bridge",Ln(new Date))),c)}catch{}}function vg(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function fs(t,e,r,i,o){if(cr[t]<cr[Ia])return;let c=`${JSON.stringify({ts:_l(new Date),level:t,module:e,msg:r,...hl,...i})}
12
- `;if(xs){let l=vg(o,i),u=l?Eg(xs,l):xs.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?yg.write(c):_g.write(c)}function H(t,e){return{debug:(r,i)=>fs("debug",t,r,i,e),info:(r,i)=>fs("info",t,r,i,e),warn:(r,i)=>fs("warn",t,r,i,e),error:(r,i)=>fs("error",t,r,i,e),child:r=>H(`${t}.${r}`,e),forAgent:r=>H(t,r)}}var cr,Ia,_g,yg,hl,bg,xs,re=et(()=>{"use strict";or();Aa();cr={debug:10,info:20,warn:30,error:40},Ia=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),_g=process.stdout,yg=process.stderr,hl={},bg=Ve("COZE_BRIDGE_LOG_RETENTION_DAYS",30),xs=null});var T,Ze=et(()=>{"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 vl={};va(vl,{ACP_WRAPPER_NPM_PACKAGES:()=>si,_resetAcpInstallerForTests:()=>Rg,_setBinaryPathCacheForTests:()=>Dg,buildAcpSpawn:()=>oi,ensureAcpInstalled:()=>dr,getAcpBinaryPath:()=>ps,pickWhichLine:()=>Ra,probeAcpVersion:()=>Tg,resolveAcpCommand:()=>El});import{readFileSync as yl}from"node:fs";import{createRequire as Sg}from"node:module";import{dirname as Ag,resolve as Ig}from"node:path";function Ra(t){let e=t.split(/\r?\n/).map(i=>i.trim()).filter(Boolean);if(e.length===0)return;if(process.platform!=="win32")return e[0];let r=i=>e.find(o=>o.toLowerCase().endsWith(i));return r(".cmd")??r(".exe")??r(".bat")??r(".ps1")??e[0]}function Cg(t){let e=bl.resolve(`${t.npmPackage}/package.json`),r=Ag(e),i=JSON.parse(yl(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 Ig(r,o)}async function dr(t,e){let r=Ta[t];if(!r)throw new T("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=ii.get(t);if(i)return i;try{let o=Cg(r);return ii.set(t,o),Ca.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw Ca.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 Tg(t){let e=Ta[t];if(e)try{let r=bl.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(yl(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){Ca.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function ps(t){return ii.get(t)}function El(t,e){if(e)return e;let r=ps(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 oi(t,e,r){if(e)return{command:e,args:[...r]};let i=El(t);return{command:process.execPath,args:[i,...r]}}function Rg(){ii.clear()}function Dg(t,e){ii.set(t,e)}var Ca,Ta,si,bl,ii,an=et(()=>{"use strict";Ze();re();Ca=H("agents.acp-installer"),Ta={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@agentclientprotocol/codex-acp",binary:"codex-acp"}},si=Object.values(Ta).filter(t=>t!==void 0).map(t=>t.npmPackage),bl=Sg(import.meta.url),ii=new Map});import{chmod as Pg,mkdir as Og,readFile as Lg,rename as Ng,rm as Mg,writeFile as Bg}from"node:fs/promises";import{dirname as zg}from"node:path";async function lr(t){try{let e=await Lg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function cn(t,e,r){await Og(zg(t),{recursive:!0});let i=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{await Bg(i,e,{encoding:"utf8",mode:r?.mode}),await Ng(i,t),r?.mode!==void 0&&await Pg(t,r.mode)}catch(o){throw await Mg(i,{force:!0}).catch(()=>{}),o}}async function ur(t,e,r){await cn(t,`${JSON.stringify(e,null,2)}
14
- `,r)}var dn=et(()=>{"use strict"});import{promises as Il,readdirSync as Fg}from"node:fs";import{homedir as Ug}from"node:os";import{sep as qg,join as Ce,resolve as Cl}from"node:path";function Q(t){let e=t??Ug(),r=Ce(e,".coze"),i=Ce(r,"bridge"),o=Ce(i,"lib"),c=Ce(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Ce(o,"index.js"),binDir:Ce(i,"bin"),pidFile:Ce(i,"bridge.pid"),portFile:Ce(i,"bridge.port"),tokenFile:Ce(i,"bridge.token"),patTokenFile:Ce(i,"pat-token"),agentEnvFile:Ce(i,"agent-env.json"),logFile:Ce(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Ce(c,"daemon-stdio.log"),installLock:Ce(i,"install.lock"),configFile:Ce(i,"config.json"),agentsRoot:Ce(r,"agents")}}function nt(t,e=Q()){let r=Ce(e.agentsRoot,t);return{root:r,config:Ce(r,"config.json"),workspace:Ce(r,"workspace"),logs:Ce(r,"logs")}}function gs(t=Q()){try{return Fg(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function ai(t,e){let r=await Il.realpath(Cl(t)).catch(()=>null);if(!r)return!1;let i=await Il.realpath(Cl(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+qg)}var Le=et(()=>{"use strict"});var _s={};va(_s,{AGENT_CONFIG_FILE_MODE:()=>ms,enforceAgentConfigMode:()=>jg,loadAgentConfig:()=>Fe,persistAgentSessions:()=>ci,persistAgentSkills:()=>ws,saveAgentConfig:()=>rt});import{chmod as Gg,stat as Hg}from"node:fs/promises";function Fe(t,e){return lr(nt(t,e).config)}function rt(t,e){return ur(nt(t.agentId,e).config,t,{mode:ms})}async function jg(t,e){if(process.platform==="win32")return;let r=nt(t,e).config;try{let i=await Hg(r);if(!i.isFile())return;let o=i.mode&511;o!==ms&&(await Gg(r,ms),Tl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Tl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function ci(t,e,r){let i=await Fe(t,r);i&&(i.sessions=Object.fromEntries(e),await rt(i,r))}async function ws(t,e,r){let i=await Fe(t,r);i&&(i.skills=e,await rt(i,r))}var Tl,ms,ln=et(()=>{"use strict";dn();re();Le();Tl=H("agent-config"),ms=384});var Pa=ce((L1,kl)=>{kl.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 bs=ce(Ol=>{var Pl={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 Jg(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(Pl))Ol[t]=Jg(Pl[t])});var zl=ce((M1,Bl)=>{var Xg=fe("fs"),Ne=fe("path"),Ll=Pa(),Yg=bs(),Qg=typeof process=="object"&&process.platform==="win32",Nl=t=>typeof t=="object"&&t!==null,Ml=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=Ne.sep,this.fs=Xg,Nl(t)&&Nl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Bl.exports=Ee;Ee.prototype.makeDir=function(t){let e=this;function r(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var l;try{l=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(l&&l.isFile())throw 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 l=Ne.dirname(t);o.fs.existsSync(l)||o.makeDir(l);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};Ee.prototype.writeFileToAsync=function(t,e,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(l){if(l&&!r)return o(!1);c.fs.stat(t,function(u,x){if(l&&x.isDirectory())return o(!1);var h=Ne.dirname(t);c.fs.exists(h,function(m){m||c.makeDir(h),c.fs.open(t,"w",438,function(E,S){E?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(_,v){c.fs.write(v,e,0,e.length,0,function(){c.fs.close(v,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):S?c.fs.write(S,e,0,e.length,0,function(){c.fs.close(S,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};Ee.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let l=[];return e.fs.readdirSync(i).forEach(function(u){let x=Ne.join(i,u),h=e.fs.statSync(x);(!o||o.test(x))&&l.push(Ne.normalize(x)+(h.isDirectory()?e.sep:"")),h.isDirectory()&&c&&(l=l.concat(r(x,o,c)))}),l}return r(t,void 0,!0)};Ee.prototype.findFilesAsync=function(t,e){let r=this,i=[];r.fs.readdir(t,function(o,c){if(o)return e(o);let l=c.length;if(!l)return e(null,i);c.forEach(function(u){u=Ne.join(t,u),r.fs.stat(u,function(x,h){if(x)return e(x);h&&(i.push(Ne.normalize(u)+(h.isDirectory()?r.sep:"")),h.isDirectory()?r.findFilesAsync(u,function(m,E){if(m)return e(m);i=i.concat(E),--l||e(null,i)}):--l||e(null,i))})})})};Ee.prototype.getAttributes=function(){};Ee.prototype.setAttributes=function(){};Ee.crc32update=function(t,e){return Ml[(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 Ll.STORED:return"STORED ("+t+")";case Ll.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Ee.canonical=function(t){if(!t)return"";let e=Ne.posix.normalize("/"+t.split("\\").join("/"));return Ne.join(".",e)};Ee.zipnamefix=function(t){if(!t)return"";let e=Ne.posix.normalize("/"+t.split("\\").join("/"));return Ne.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=Ne.resolve(Ne.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Ne.normalize(Ne.join(t,r.slice(i,o).join(Ne.sep)));if(c.indexOf(t)===0)return c}return Ne.normalize(Ne.join(t,Ne.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=Qg;Ee.crcTable=Ml});var Ul=ce((B1,Fl)=>{var em=fe("path");Fl.exports=function(t,{fs:e}){var r=t||"",i=c(),o=null;function c(){return{directory:!1,readonly:!1,hidden:!1,executable:!1,mtime:0,atime:0}}return r&&e.existsSync(r)?(o=e.statSync(r),i.directory=o.isDirectory(),i.mtime=o.mtime,i.atime=o.atime,i.executable=(73&o.mode)!==0,i.readonly=(128&o.mode)===0,i.hidden=em.basename(r)[0]==="."):console.warn("Invalid path: "+r),{get directory(){return i.directory},get readOnly(){return i.readonly},get hidden(){return i.hidden},get mtime(){return i.mtime},get atime(){return i.atime},get executable(){return i.executable},decodeAttributes:function(){},encodeAttributes:function(){},toJSON:function(){return{path:r,isDirectory:i.directory,isReadOnly:i.readonly,isHidden:i.hidden,isExecutable:i.executable,mTime:i.mtime,aTime:i.atime}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Gl=ce((z1,ql)=>{ql.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var hr=ce((F1,xr)=>{xr.exports=zl();xr.exports.Constants=Pa();xr.exports.Errors=bs();xr.exports.FileAttr=Ul();xr.exports.decoder=Gl()});var jl=ce((U1,Hl)=>{var un=hr(),q=un.Constants;Hl.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,l=0,u=0,x=0,h=0,m=0,E=0,S=0,_=0,v=0;t|=un.isWin?2560:768,r|=q.FLG_EFS;let A={extraLen:0},I=y=>Math.max(0,y)>>>0,D=y=>Math.max(0,y)&65535,O=y=>Math.max(0,y)&255;return o=un.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&q.FLG_EFS)>0},set flags_efs(y){y?r|=q.FLG_EFS:r&=~q.FLG_EFS},get flags_desc(){return(r&q.FLG_DESC)>0},set flags_desc(y){y?r|=q.FLG_DESC:r&=~q.FLG_DESC},get method(){return i},set method(y){switch(y){case q.STORED:this.version=10;case q.DEFLATED:default:this.version=20}i=y},get time(){return un.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=un.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=I(y)},get timeHighByte(){return O(o>>>8)},get crc(){return c},set crc(y){c=I(y)},get compressedSize(){return l},set compressedSize(y){l=I(y)},get size(){return u},set size(y){u=I(y)},get fileNameLength(){return x},set fileNameLength(y){x=y},get extraLength(){return h},set extraLength(y){h=y},get extraLocalLength(){return A.extraLen},set extraLocalLength(y){A.extraLen=y},get commentLength(){return m},set commentLength(y){m=y},get diskNumStart(){return E},set diskNumStart(y){E=I(y)},get inAttr(){return S},set inAttr(y){S=I(y)},get attr(){return _},set attr(y){_=I(y)},get fileAttr(){return(_||0)>>16&4095},get offset(){return v},set offset(y){v=I(y)},get encrypted(){return(r&q.FLG_ENC)===q.FLG_ENC},get centralHeaderSize(){return q.CENHDR+x+h+m},get realDataOffset(){return v+q.LOCHDR+A.fnameLen+A.extraLen},get localHeader(){return A},loadLocalHeaderFromBinary:function(y){var k=y.slice(v,v+q.LOCHDR);if(k.readUInt32LE(0)!==q.LOCSIG)throw un.Errors.INVALID_LOC();A.version=k.readUInt16LE(q.LOCVER),A.flags=k.readUInt16LE(q.LOCFLG),A.flags_desc=(A.flags&q.FLG_DESC)>0,A.method=k.readUInt16LE(q.LOCHOW),A.time=k.readUInt32LE(q.LOCTIM),A.crc=k.readUInt32LE(q.LOCCRC),A.compressedSize=k.readUInt32LE(q.LOCSIZ),A.size=k.readUInt32LE(q.LOCLEN),A.fnameLen=k.readUInt16LE(q.LOCNAM),A.extraLen=k.readUInt16LE(q.LOCEXT);let L=v+q.LOCHDR+A.fnameLen,U=L+A.extraLen;return y.slice(L,U)},loadFromBinary:function(y){if(y.length!==q.CENHDR||y.readUInt32LE(0)!==q.CENSIG)throw un.Errors.INVALID_CEN();t=y.readUInt16LE(q.CENVEM),e=y.readUInt16LE(q.CENVER),r=y.readUInt16LE(q.CENFLG),i=y.readUInt16LE(q.CENHOW),o=y.readUInt32LE(q.CENTIM),c=y.readUInt32LE(q.CENCRC),l=y.readUInt32LE(q.CENSIZ),u=y.readUInt32LE(q.CENLEN),x=y.readUInt16LE(q.CENNAM),h=y.readUInt16LE(q.CENEXT),m=y.readUInt16LE(q.CENCOM),E=y.readUInt16LE(q.CENDSK),S=y.readUInt16LE(q.CENATT),_=y.readUInt32LE(q.CENATX),v=y.readUInt32LE(q.CENOFF)},localHeaderToBinary:function(){var y=Buffer.alloc(q.LOCHDR);return y.writeUInt32LE(q.LOCSIG,0),y.writeUInt16LE(e,q.LOCVER),y.writeUInt16LE(r,q.LOCFLG),y.writeUInt16LE(i,q.LOCHOW),y.writeUInt32LE(o,q.LOCTIM),y.writeUInt32LE(c,q.LOCCRC),y.writeUInt32LE(l,q.LOCSIZ),y.writeUInt32LE(u,q.LOCLEN),y.writeUInt16LE(x,q.LOCNAM),y.writeUInt16LE(A.extraLen,q.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(q.CENHDR+x+h+m);return y.writeUInt32LE(q.CENSIG,0),y.writeUInt16LE(t,q.CENVEM),y.writeUInt16LE(e,q.CENVER),y.writeUInt16LE(r,q.CENFLG),y.writeUInt16LE(i,q.CENHOW),y.writeUInt32LE(o,q.CENTIM),y.writeUInt32LE(c,q.CENCRC),y.writeUInt32LE(l,q.CENSIZ),y.writeUInt32LE(u,q.CENLEN),y.writeUInt16LE(x,q.CENNAM),y.writeUInt16LE(h,q.CENEXT),y.writeUInt16LE(m,q.CENCOM),y.writeUInt16LE(E,q.CENDSK),y.writeUInt16LE(S,q.CENATT),y.writeUInt32LE(_,q.CENATX),y.writeUInt32LE(v,q.CENOFF),y},toJSON:function(){let y=function(k){return k+" bytes"};return{made:t,version:e,flags:r,method:un.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(l),size:y(u),fileNameLength:y(x),extraLength:y(h),commentLength:y(m),diskNumStart:E,inAttr:S,attr:_,offset:v,centralHeaderSize:y(q.CENHDR+x+h+m)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Kl=ce((q1,Wl)=>{var pr=hr(),_e=pr.Constants;Wl.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 _e.ENDHDR+o},loadFromBinary:function(c){if((c.length!==_e.ENDHDR||c.readUInt32LE(0)!==_e.ENDSIG)&&(c.length<_e.ZIP64HDR||c.readUInt32LE(0)!==_e.ZIP64SIG))throw pr.Errors.INVALID_END();c.readUInt32LE(0)===_e.ENDSIG?(t=c.readUInt16LE(_e.ENDSUB),e=c.readUInt16LE(_e.ENDTOT),r=c.readUInt32LE(_e.ENDSIZ),i=c.readUInt32LE(_e.ENDOFF),o=c.readUInt16LE(_e.ENDCOM)):(t=pr.readBigUInt64LE(c,_e.ZIP64SUB),e=pr.readBigUInt64LE(c,_e.ZIP64TOT),r=pr.readBigUInt64LE(c,_e.ZIP64SIZE),i=pr.readBigUInt64LE(c,_e.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(_e.ENDHDR+o);return c.writeUInt32LE(_e.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,_e.ENDSUB),c.writeUInt16LE(e,_e.ENDTOT),c.writeUInt32LE(r,_e.ENDSIZ),c.writeUInt32LE(i,_e.ENDOFF),c.writeUInt16LE(o,_e.ENDCOM),c.fill(" ",_e.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 La=ce(Oa=>{Oa.EntryHeader=jl();Oa.MainHeader=Kl()});var Vl=ce((H1,$l)=>{$l.exports=function(t){var e=fe("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 h=0;h<c.length;h++){var m=c[h];m.copy(u,x),x+=m.length}i&&i(u)}),o.end(t)}}}});var Jl=ce((j1,Zl)=>{var tm=+(process.versions?process.versions.node:"").split(".")[0]||0;Zl.exports=function(t,e){var r=fe("zlib");let i=tm>=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),h=0;x.fill(0);for(var m=0;m<l.length;m++){var E=l[m];E.copy(x,h),h+=E.length}o&&o(x)}),c.end(t)}}}});var tu=ce((W1,eu)=>{"use strict";var{randomFillSync:Xl}=fe("crypto"),nm=bs(),rm=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}),Ql=(t,e)=>Math.imul(t,e)>>>0,Yl=(t,e)=>rm[(t^e)&255]^t>>>8,di=()=>typeof Xl=="function"?Xl(Buffer.alloc(12)):di.node();di.node=()=>{let t=Buffer.alloc(12),e=t.length;for(let r=0;r<e;r++)t[r]=Math.random()*256&255;return t};var Es={genSalt:di};function vs(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])}vs.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Yl(e[0],t),e[1]+=e[0]&255,e[1]=Ql(e[1],134775813)+1,e[2]=Yl(e[2],e[1]>>>24),t};vs.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Ql(t,t^1)>>8&255};function im(t){let e=new vs(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 sm(t){let e=new vs(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 om(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=im(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw nm.WRONG_PASSWORD();return i(t.slice(12))}function am(t){Buffer.isBuffer(t)&&t.length>=12?Es.genSalt=function(){return t.slice(0,12)}:t==="node"?Es.genSalt=di.node:Es.genSalt=di}function cm(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=sm(r),c=Es.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)}eu.exports={decrypt:om,encrypt:cm,_salter:am}});var nu=ce(Ss=>{Ss.Deflater=Vl();Ss.Inflater=Jl();Ss.ZipCrypto=tu()});var Ma=ce(($1,ru)=>{var de=hr(),dm=La(),ve=de.Constants,Na=nu();ru.exports=function(t,e){var r=new dm.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,l=null,u=Buffer.alloc(0),x=Buffer.alloc(0),h=!0;let m=t,E=typeof m.decoder=="object"?m.decoder:de.decoder;h=E.hasOwnProperty("efs")?E.efs:!1;function S(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(x=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function _(y){if(!r.flags_desc&&!r.localHeader.flags_desc){if(de.crc32(y)!==r.localHeader.crc)return!1}else{let k={},L=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(L)==ve.LOCSIG||e.readUInt32LE(L)==ve.CENSIG)throw de.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(L)==ve.EXTSIG)k.crc=e.readUInt32LE(L+ve.EXTCRC),k.compressedSize=e.readUInt32LE(L+ve.EXTSIZ),k.size=e.readUInt32LE(L+ve.EXTLEN);else if(e.readUInt16LE(L+12)===19280)k.crc=e.readUInt32LE(L+ve.EXTCRC-4),k.compressedSize=e.readUInt32LE(L+ve.EXTSIZ-4),k.size=e.readUInt32LE(L+ve.EXTLEN-4);else throw de.Errors.DESCRIPTOR_UNKNOWN();if(k.compressedSize!==r.compressedSize||k.size!==r.size||k.crc!==r.crc)throw de.Errors.DESCRIPTOR_FAULTY();if(de.crc32(y)!==k.crc)return!1}return!0}function v(y,k,L){if(typeof k>"u"&&typeof y=="string"&&(L=y,y=void 0),c)return y&&k&&k(Buffer.alloc(0),de.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var U=S();if(U.length===0)return y&&k&&k(U),U;if(r.encrypted){if(typeof L!="string"&&!Buffer.isBuffer(L))throw de.Errors.INVALID_PASS_PARAM();U=Na.ZipCrypto.decrypt(U,r,L)}var z=Buffer.alloc(r.size);switch(r.method){case de.Constants.STORED:if(U.copy(z),_(z))return y&&k&&k(z),z;throw y&&k&&k(z,de.Errors.BAD_CRC()),de.Errors.BAD_CRC();case de.Constants.DEFLATED:var Z=new Na.Inflater(U,r.size);if(y)Z.inflateAsync(function(V){V.copy(V,0),k&&(_(V)?k(V):k(V,de.Errors.BAD_CRC()))});else{if(Z.inflate(z).copy(z,0),!_(z))throw de.Errors.BAD_CRC(`"${E.decode(i)}"`);return z}break;default:throw y&&k&&k(Buffer.alloc(0),de.Errors.UNKNOWN_METHOD()),de.Errors.UNKNOWN_METHOD()}}function A(y,k){if((!l||!l.length)&&Buffer.isBuffer(e))return y&&k&&k(S()),S();if(l.length&&!c){var L;switch(r.method){case de.Constants.STORED:return r.compressedSize=r.size,L=Buffer.alloc(l.length),l.copy(L),y&&k&&k(L),L;default:case de.Constants.DEFLATED:var U=new Na.Deflater(l);if(y)U.deflateAsync(function(Z){L=Buffer.alloc(Z.length),r.compressedSize=Z.length,Z.copy(L),k&&k(L)});else{var z=U.deflate();return r.compressedSize=z.length,z}U=null;break}}else if(y&&k)k(Buffer.alloc(0));else return Buffer.alloc(0)}function I(y,k){return de.readBigUInt64LE(y,k)}function D(y){try{for(var k=0,L,U,z;k+4<y.length;)L=y.readUInt16LE(k),k+=2,U=y.readUInt16LE(k),k+=2,z=y.slice(k,k+U),k+=U,ve.ID_ZIP64===L&&O(z)}catch{throw de.Errors.EXTRA_FIELD_PARSE_ERROR()}}function O(y){var k,L,U,z;y.length>=ve.EF_ZIP64_SCOMP&&(k=I(y,ve.EF_ZIP64_SUNCOMP),r.size===ve.EF_ZIP64_OR_32&&(r.size=k)),y.length>=ve.EF_ZIP64_RHO&&(L=I(y,ve.EF_ZIP64_SCOMP),r.compressedSize===ve.EF_ZIP64_OR_32&&(r.compressedSize=L)),y.length>=ve.EF_ZIP64_DSN&&(U=I(y,ve.EF_ZIP64_RHO),r.offset===ve.EF_ZIP64_OR_32&&(r.offset=U)),y.length>=ve.EF_ZIP64_DSN+4&&(z=y.readUInt32LE(ve.EF_ZIP64_DSN),r.diskNumStart===ve.EF_ZIP64_OR_16&&(r.diskNumStart=z))}return{get entryName(){return E.decode(i)},get rawEntryName(){return i},set entryName(y){i=de.toBuffer(y,E.encode);var k=i[i.length-1];c=k===47||k===92,r.fileNameLength=i.length},get efs(){return typeof h=="function"?h(this.entryName):h},get extra(){return u},set extra(y){u=y,r.extraLength=y.length,D(y)},get comment(){return E.decode(o)},set comment(y){if(o=de.toBuffer(y,E.encode),r.commentLength=o.length,o.length>65535)throw de.Errors.COMMENT_TOO_LONG()},get name(){var y=E.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=de.toBuffer(y,de.decoder.encode),!c&&l.length?(r.size=l.length,r.method=de.Constants.DEFLATED,r.crc=de.crc32(y),r.changed=!0):r.method=de.Constants.STORED},getData:function(y){return r.changed?l:v(!1,null,y)},getDataAsync:function(y,k){r.changed?y(l):v(!0,y,k)},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(),k=de.Constants.CENHDR;return i.copy(y,k),k+=i.length,u.copy(y,k),k+=r.extraLength,o.copy(y,k),y},packLocalHeader:function(){let y=0;r.flags_efs=this.efs,r.extraLocalLength=x.length;let k=r.localHeaderToBinary(),L=Buffer.alloc(k.length+i.length+r.extraLocalLength);return k.copy(L,y),y+=k.length,i.copy(L,y),y+=i.length,x.copy(L,y),y+=x.length,L},toJSON:function(){let y=function(k){return"<"+(k&&k.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:y(e),data:y(l)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var ou=ce((V1,su)=>{var iu=Ma(),lm=La(),$e=hr();su.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new lm.MainHeader,l=!1,u=null;let x=new Set,h=e,{noSort:m,decoder:E}=h;t?v(h.readEntries):l=!0;function S(){let I=new Set;for(let D of Object.keys(i)){let O=D.split("/");if(O.pop(),!!O.length)for(let y=0;y<O.length;y++){let k=O.slice(0,y+1).join("/")+"/";I.add(k)}}for(let D of I)if(!(D in i)){let O=new iu(h);O.entryName=D,O.attr=16,O.temporary=!0,r.push(O),i[O.entryName]=O,x.add(O)}}function _(){if(l=!0,i={},c.diskEntries>(t.length-c.offset)/$e.Constants.CENHDR)throw $e.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var I=c.offset,D=0;D<r.length;D++){var O=I,y=new iu(h,t);y.header=t.slice(O,O+=$e.Constants.CENHDR),y.entryName=t.slice(O,O+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(O,O+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(O,O+y.header.commentLength)),I+=y.header.centralHeaderSize,r[D]=y,i[y.entryName]=y}x.clear(),S()}function v(I){var D=t.length-$e.Constants.ENDHDR,O=Math.max(0,D-65535),y=O,k=t.length,L=-1,U=0;for(typeof h.trailingSpace=="boolean"&&h.trailingSpace&&(O=0),D;D>=y;D--)if(t[D]===80){if(t.readUInt32LE(D)===$e.Constants.ENDSIG){L=D,U=D,k=D+$e.Constants.ENDHDR,y=D-$e.Constants.END64HDR;continue}if(t.readUInt32LE(D)===$e.Constants.END64SIG){y=O;continue}if(t.readUInt32LE(D)===$e.Constants.ZIP64SIG){L=D,k=D+$e.readBigUInt64LE(t,D+$e.Constants.ZIP64SIZE)+$e.Constants.ZIP64LEAD;break}}if(L==-1)throw $e.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(L,k)),c.commentLength&&(o=t.slice(U+$e.Constants.ENDHDR)),I&&_()}function A(){r.length>1&&!m&&r.sort((I,D)=>I.entryName.toLowerCase().localeCompare(D.entryName.toLowerCase()))}return{get entries(){return l||_(),r.filter(I=>!x.has(I))},get comment(){return E.decode(o)},set comment(I){o=$e.toBuffer(I,E.encode),c.commentLength=o.length},getEntryCount:function(){return l?r.length:c.diskEntries},forEach:function(I){this.entries.forEach(I)},getEntry:function(I){return l||_(),i[I]||null},setEntry:function(I){l||_(),r.push(I),i[I.entryName]=I,c.totalEntries=r.length},deleteFile:function(I,D=!0){l||_();let O=i[I];this.getEntryChildren(O,D).map(k=>k.entryName).forEach(this.deleteEntry)},deleteEntry:function(I){l||_();let D=i[I],O=r.indexOf(D);O>=0&&(r.splice(O,1),delete i[I],c.totalEntries=r.length)},getEntryChildren:function(I,D=!0){if(l||_(),typeof I=="object")if(I.isDirectory&&D){let O=[],y=I.entryName;for(let k of r)k.entryName.startsWith(y)&&O.push(k);return O}else return[I];return[]},getChildCount:function(I){if(I&&I.isDirectory){let D=this.getEntryChildren(I);return D.includes(I)?D.length-1:D.length}return 0},compressToBuffer:function(){l||_(),A();let I=[],D=[],O=0,y=0;c.size=0,c.offset=0;let k=0;for(let z of this.entries){let Z=z.getCompressedData();z.header.offset=y;let V=z.packLocalHeader(),ne=V.length+Z.length;y+=ne,I.push(V),I.push(Z);let X=z.packCentralHeader();D.push(X),c.size+=X.length,O+=ne+X.length,k++}O+=c.mainHeaderSize,c.offset=y,c.totalEntries=k,y=0;let L=Buffer.alloc(O);for(let z of I)z.copy(L,y),y+=z.length;for(let z of D)z.copy(L,y),y+=z.length;let U=c.toBinary();return o&&o.copy(U,$e.Constants.ENDHDR),U.copy(L,y),t=L,l=!1,L},toAsyncBuffer:function(I,D,O,y){try{l||_(),A();let k=[],L=[],U=0,z=0,Z=0;c.size=0,c.offset=0;let V=function(ne){if(ne.length>0){let X=ne.shift(),se=X.entryName+X.extra.toString();O&&O(se),X.getCompressedDataAsync(function(ae){y&&y(se),X.header.offset=z;let N=X.packLocalHeader(),j=N.length+ae.length;z+=j,k.push(N),k.push(ae);let $=X.packCentralHeader();L.push($),c.size+=$.length,U+=j+$.length,Z++,V(ne)})}else{U+=c.mainHeaderSize,c.offset=z,c.totalEntries=Z,z=0;let X=Buffer.alloc(U);k.forEach(function(ae){ae.copy(X,z),z+=ae.length}),L.forEach(function(ae){ae.copy(X,z),z+=ae.length});let se=c.toBinary();o&&o.copy(se,$e.Constants.ENDHDR),se.copy(X,z),t=X,l=!1,I(X)}};V(Array.from(this.entries))}catch(k){D(k)}}}}});var du=ce((Z1,cu)=>{var be=hr(),ye=fe("path"),um=Ma(),fm=ou(),Nn=(...t)=>be.findLast(t,e=>typeof e=="boolean"),au=(...t)=>be.findLast(t,e=>typeof e=="string"),xm=(...t)=>be.findLast(t,e=>typeof e=="function"),hm={noSort:!1,readEntries:!1,method:be.Constants.NONE,fs:null};cu.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),hm);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=be.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new be(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=be.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=be.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw be.Errors.INVALID_FILENAME();let c=new fm(r,i),{canonical:l,sanitize:u,zipnamefix:x}=be;function h(_){if(_&&c){var v;if(typeof _=="string"&&(v=c.getEntry(ye.posix.normalize(_))),typeof _=="object"&&typeof _.entryName<"u"&&typeof _.header<"u"&&(v=c.getEntry(_.entryName)),v)return v}return null}function m(_){let{join:v,normalize:A,sep:I}=ye.posix;return v(ye.isAbsolute(_)?"/":".",A(I+_.split("\\").join(I)+I))}function E(_){return _ instanceof RegExp?(function(v){return function(A){return v.test(A)}})(_):typeof _!="function"?()=>!0:_}let S=(_,v)=>{let A=v.slice(-1);return A=A===o.sep?o.sep:"",ye.relative(_,v)+A};return{readFile:function(_,v){var A=h(_);return A&&A.getData(v)||null},childCount:function(_){let v=h(_);if(v)return c.getChildCount(v)},readFileAsync:function(_,v){var A=h(_);A?A.getDataAsync(v):v(null,"getEntry failed for:"+_)},readAsText:function(_,v){var A=h(_);if(A){var I=A.getData();if(I&&I.length)return I.toString(v||"utf8")}return""},readAsTextAsync:function(_,v,A){var I=h(_);I?I.getDataAsync(function(D,O){if(O){v(D,O);return}D&&D.length?v(D.toString(A||"utf8")):v("")}):v("")},deleteFile:function(_,v=!0){var A=h(_);A&&c.deleteFile(A.entryName,v)},deleteEntry:function(_){var v=h(_);v&&c.deleteEntry(v.entryName)},addZipComment:function(_){c.comment=_},getZipComment:function(){return c.comment||""},addZipEntryComment:function(_,v){var A=h(_);A&&(A.comment=v)},getZipEntryComment:function(_){var v=h(_);return v&&v.comment||""},updateFile:function(_,v){var A=h(_);A&&A.setData(v)},addLocalFile:function(_,v,A,I){if(o.fs.existsSync(_)){v=v?m(v):"";let D=ye.win32.basename(ye.win32.normalize(_));v+=A||D;let O=o.fs.statSync(_),y=O.isFile()?o.fs.readFileSync(_):Buffer.alloc(0);O.isDirectory()&&(v+=o.sep),this.addFile(v,y,I,O)}else throw be.Errors.FILE_NOT_FOUND(_)},addLocalFileAsync:function(_,v){_=typeof _=="object"?_:{localPath:_};let A=ye.resolve(_.localPath),{comment:I}=_,{zipPath:D,zipName:O}=_,y=this;o.fs.stat(A,function(k,L){if(k)return v(k,!1);D=D?m(D):"";let U=ye.win32.basename(ye.win32.normalize(A));if(D+=O||U,L.isFile())o.fs.readFile(A,function(z,Z){return z?v(z,!1):(y.addFile(D,Z,I,L),setImmediate(v,void 0,!0))});else if(L.isDirectory())return D+=o.sep,y.addFile(D,Buffer.alloc(0),I,L),setImmediate(v,void 0,!0)})},addLocalFolder:function(_,v,A){if(A=E(A),v=v?m(v):"",_=ye.normalize(_),o.fs.existsSync(_)){let I=o.findFiles(_),D=this;if(I.length)for(let O of I){let y=ye.join(v,S(_,O));A(y)&&D.addLocalFile(O,ye.dirname(y))}}else throw be.Errors.FILE_NOT_FOUND(_)},addLocalFolderAsync:function(_,v,A,I){I=E(I),A=A?m(A):"",_=ye.normalize(_);var D=this;o.fs.open(_,"r",function(O){if(O&&O.code==="ENOENT")v(void 0,be.Errors.FILE_NOT_FOUND(_));else if(O)v(void 0,O);else{var y=o.findFiles(_),k=-1,L=function(){if(k+=1,k<y.length){var U=y[k],z=S(_,U).split("\\").join("/");z=z.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),I(z)?o.fs.stat(U,function(Z,V){Z&&v(void 0,Z),V.isFile()?o.fs.readFile(U,function(ne,X){ne?v(void 0,ne):(D.addFile(A+z,X,"",V),L())}):(D.addFile(A+z+"/",Buffer.alloc(0),"",V),L())}):process.nextTick(()=>{L()})}else v(!0,void 0)};L()}})},addLocalFolderAsync2:function(_,v){let A=this;_=typeof _=="object"?_:{localPath:_},localPath=ye.resolve(m(_.localPath));let{zipPath:I,filter:D,namefix:O}=_;D instanceof RegExp?D=(function(L){return function(U){return L.test(U)}})(D):typeof D!="function"&&(D=function(){return!0}),I=I?m(I):"",O=="latin1"&&(O=L=>L.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof O!="function"&&(O=L=>L);let y=L=>ye.join(I,O(S(localPath,L))),k=L=>ye.win32.basename(ye.win32.normalize(O(L)));o.fs.open(localPath,"r",function(L){L&&L.code==="ENOENT"?v(void 0,be.Errors.FILE_NOT_FOUND(localPath)):L?v(void 0,L):o.findFilesAsync(localPath,function(U,z){if(U)return v(U);z=z.filter(Z=>D(y(Z))),z.length||v(void 0,!1),setImmediate(z.reverse().reduce(function(Z,V){return function(ne,X){if(ne||X===!1)return setImmediate(Z,ne,!1);A.addLocalFileAsync({localPath:V,zipPath:ye.dirname(y(V)),zipName:k(V)},Z)}},v))})})},addLocalFolderPromise:function(_,v){return new Promise((A,I)=>{this.addLocalFolderAsync2(Object.assign({localPath:_},v),(D,O)=>{D&&I(D),O&&A(this)})})},addFile:function(_,v,A,I){_=x(_);let D=h(_),O=D!=null;O||(D=new um(i),D.entryName=_),D.comment=A||"";let y=typeof I=="object"&&I instanceof o.fs.Stats;y&&(D.header.time=I.mtime);var k=D.isDirectory?16:0;let L=D.isDirectory?16384:32768;return y?L|=4095&I.mode:typeof I=="number"?L|=4095&I:L|=D.isDirectory?493:420,k=(k|L<<16)>>>0,D.attr=k,D.setData(v),O||c.setEntry(D),D},getEntries:function(_){return c.password=_,c?c.entries:[]},getEntry:function(_){return h(_)},getEntryCount:function(){return c.getEntryCount()},forEach:function(_){return c.forEach(_)},extractEntryTo:function(_,v,A,I,D,O){I=Nn(!1,I),D=Nn(!1,D),A=Nn(!0,A),O=au(D,O);var y=h(_);if(!y)throw be.Errors.NO_ENTRY();var k=l(y.entryName),L=u(v,O&&!y.isDirectory?O:A?k:ye.basename(k));if(y.isDirectory){var U=c.getEntryChildren(y);return U.forEach(function(V){if(V.isDirectory)return;var ne=V.getData();if(!ne)throw be.Errors.CANT_EXTRACT_FILE();var X=l(V.entryName),se=u(v,A?X:ye.basename(X));let ae=D?V.header.fileAttr:void 0;o.writeFileTo(se,ne,I,ae)}),!0}var z=y.getData(c.password);if(!z)throw be.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(L)&&!I)throw be.Errors.CANT_OVERRIDE();let Z=D?_.header.fileAttr:void 0;return o.writeFileTo(L,z,I,Z),!0},test:function(_){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var A=c.entries[v].getData(_);if(!A)return!1}catch{return!1}return!0},extractAllTo:function(_,v,A,I){if(A=Nn(!1,A),I=au(A,I),v=Nn(!1,v),!c)throw be.Errors.NO_ZIP();c.entries.forEach(function(D){var O=u(_,l(D.entryName));if(D.isDirectory){o.makeDir(O);return}var y=D.getData(I);if(!y)throw be.Errors.CANT_EXTRACT_FILE();let k=A?D.header.fileAttr:void 0;o.writeFileTo(O,y,v,k);try{o.fs.utimesSync(O,D.header.time,D.header.time)}catch{throw be.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(_,v,A,I){if(I=xm(v,A,I),A=Nn(!1,A),v=Nn(!1,v),!I)return new Promise((L,U)=>{this.extractAllToAsync(_,v,A,function(z){z?U(z):L(this)})});if(!c){I(be.Errors.NO_ZIP());return}_=ye.resolve(_);let D=L=>u(_,ye.normalize(l(L.entryName))),O=(L,U)=>new Error(L+': "'+U+'"'),y=[],k=[];c.entries.forEach(L=>{L.isDirectory?y.push(L):k.push(L)});for(let L of y){let U=D(L),z=A?L.header.fileAttr:void 0;try{o.makeDir(U),z&&o.fs.chmodSync(U,z),o.fs.utimesSync(U,L.header.time,L.header.time)}catch{I(O("Unable to create folder",U))}}k.reverse().reduce(function(L,U){return function(z){if(z)L(z);else{let Z=ye.normalize(l(U.entryName)),V=u(_,Z);U.getDataAsync(function(ne,X){if(X)L(X);else if(!ne)L(be.Errors.CANT_EXTRACT_FILE());else{let se=A?U.header.fileAttr:void 0;o.writeFileToAsync(V,ne,v,se,function(ae){ae||L(O("Unable to write file",V)),o.fs.utimes(V,U.header.time,U.header.time,function(N){N?L(O("Unable to set times",V)):L()})})}})}}},I)()},writeZip:function(_,v){if(arguments.length===1&&typeof _=="function"&&(v=_,_=""),!_&&i.filename&&(_=i.filename),!!_){var A=c.compressToBuffer();if(A){var I=o.writeFileTo(_,A,!0);typeof v=="function"&&v(I?null:new Error("failed"),"")}}},writeZipPromise:function(_,v){let{overwrite:A,perm:I}=Object.assign({overwrite:!0},v);return new Promise((D,O)=>{!_&&i.filename&&(_=i.filename),_||O("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let k=L=>L?D(L):O("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(_,y,A,I,k)},O)})},toBufferPromise:function(){return new Promise((_,v)=>{c.toAsyncBuffer(_,v)})},toBuffer:function(_,v,A,I){return typeof _=="function"?(c.toAsyncBuffer(_,v,A,I),null):c.compressToBuffer()}}}});import{execFile as y_,spawn as b_,spawnSync as xI}from"node:child_process";import{promisify as E_}from"node:util";function S_(t){if(process.platform!=="win32")return!1;if(Rf.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(Rf,"").toLowerCase();return v_.has(r)}function Df(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return S_(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function st(t,e=[],r={}){return b_(t,e,Df(t,r))}function kf(t,e=[],r={}){return A_(t,e,Df(t,r))}var v_,Rf,A_,Vt=et(()=>{"use strict";v_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Rf=/\.(cmd|bat|ps1)$/i;A_=E_(y_)});var Jt=ce((JR,lx)=>{"use strict";var cx=["nodebuffer","arraybuffer","fragments"],dx=typeof Blob<"u";dx&&cx.push("blob");lx.exports={BINARY_TYPES:cx,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:dx,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var Ji=ce((XR,Do)=>{"use strict";var{EMPTY_BUFFER:oE}=Jt(),ld=Buffer[Symbol.species];function aE(t,e){if(t.length===0)return oE;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 ld(r.buffer,r.byteOffset,i):r}function ux(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function fx(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function cE(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function ud(t){if(ud.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new ld(t):ArrayBuffer.isView(t)?e=new ld(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),ud.readOnly=!1),e}Do.exports={concat:aE,mask:ux,toArrayBuffer:cE,toBuffer:ud,unmask:fx};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=fe("bufferutil");Do.exports.mask=function(e,r,i,o,c){c<48?ux(e,r,i,o,c):t.mask(e,r,i,o,c)},Do.exports.unmask=function(e,r){e.length<32?fx(e,r):t.unmask(e,r)}}catch{}});var px=ce((YR,hx)=>{"use strict";var xx=Symbol("kDone"),fd=Symbol("kRun"),xd=class{constructor(e){this[xx]=()=>{this.pending--,this[fd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[fd]()}[fd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[xx])}}};hx.exports=xd});var qr=ce((QR,yx)=>{"use strict";var Xi=fe("zlib"),gx=Ji(),dE=px(),{kStatusCode:mx}=Jt(),lE=Buffer[Symbol.species],uE=Buffer.from([0,0,255,255]),Po=Symbol("permessage-deflate"),Xt=Symbol("total-length"),Fr=Symbol("callback"),Rn=Symbol("buffers"),Ur=Symbol("error"),ko,hd=class{constructor(e){if(this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._maxPayload=this._options.maxPayload|0,this._isServer=!!this._options.isServer,this._deflate=null,this._inflate=null,this.params=null,!ko){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;ko=new dE(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[Fr];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){ko.add(o=>{this._decompress(e,r,(c,l)=>{o(),i(c,l)})})}compress(e,r,i){ko.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"?Xi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Xi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:l}),this._inflate[Po]=this,this._inflate[Xt]=0,this._inflate[Rn]=[],this._inflate.on("error",xE),this._inflate.on("data",_x)}this._inflate[Fr]=i,this._inflate.write(e),r&&this._inflate.write(uE),this._inflate.flush(()=>{let c=this._inflate[Ur];if(c){this._inflate.close(),this._inflate=null,i(c);return}let l=gx.concat(this._inflate[Rn],this._inflate[Xt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Xt]=0,this._inflate[Rn]=[],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"?Xi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Xi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:l}),this._deflate[Xt]=0,this._deflate[Rn]=[],this._deflate.on("data",fE)}this._deflate[Fr]=i,this._deflate.write(e),this._deflate.flush(Xi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=gx.concat(this._deflate[Rn],this._deflate[Xt]);r&&(c=new lE(c.buffer,c.byteOffset,c.length-4)),this._deflate[Fr]=null,this._deflate[Xt]=0,this._deflate[Rn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};yx.exports=hd;function fE(t){this[Rn].push(t),this[Xt]+=t.length}function _x(t){if(this[Xt]+=t.length,this[Po]._maxPayload<1||this[Xt]<=this[Po]._maxPayload){this[Rn].push(t);return}this[Ur]=new RangeError("Max payload size exceeded"),this[Ur].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Ur][mx]=1009,this.removeListener("data",_x),this.reset()}function xE(t){if(this[Po]._inflate=null,this[Ur]){this[Fr](this[Ur]);return}t[mx]=1007,this[Fr](t)}});var Gr=ce((e3,Oo)=>{"use strict";var{isUtf8:bx}=fe("buffer"),{hasBlob:hE}=Jt(),pE=[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 pd(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 mE(t){return hE&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Oo.exports={isBlob:mE,isValidStatusCode:gE,isValidUTF8:pd,tokenChars:pE};if(bx)Oo.exports.isValidUTF8=function(t){return t.length<24?pd(t):bx(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=fe("utf-8-validate");Oo.exports.isValidUTF8=function(e){return e.length<32?pd(e):t(e)}}catch{}});var yd=ce((t3,Tx)=>{"use strict";var{Writable:wE}=fe("stream"),Ex=qr(),{BINARY_TYPES:_E,EMPTY_BUFFER:vx,kStatusCode:yE,kWebSocket:bE}=Jt(),{concat:gd,toArrayBuffer:EE,unmask:vE}=Ji(),{isValidStatusCode:SE,isValidUTF8:Sx}=Gr(),Lo=Buffer[Symbol.species],xt=0,Ax=1,Ix=2,Cx=3,md=4,wd=5,No=6,_d=class extends wE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||_E[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=e.maxBufferedChunks|0,this._maxFragments=e.maxFragments|0,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[bE]=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=xt}_write(e,r,i){if(this._opcode===8&&this._state==xt)return i();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){i(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new Lo(i.buffer,i.byteOffset+e,i.length-e),new Lo(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 Lo(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 xt:this.getInfo(e);break;case Ax:this.getPayloadLength16(e);break;case Ix:this.getPayloadLength64(e);break;case Cx:this.getMask();break;case md:this.getData(e);break;case wd:case No: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[Ex.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=Ix: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=Cx:this._state=md}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=md}getData(e){let r=vx;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=wd,this.decompress(r,e);return}if(r.length){if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let i=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(i);return}this._messageLength=this._totalPayloadLength,this._fragments.push(r)}this.dataMessage(e)}decompress(e,r){this._extensions[Ex.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let l=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(l);return}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let l=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");r(l);return}this._fragments.push(c)}this.dataMessage(r),this._state===xt&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=xt;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=gd(i,r):this._binaryType==="arraybuffer"?o=EE(gd(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=xt):(this._state=No,setImmediate(()=>{this.emit("message",o,!0),this._state=xt,this.startLoop(e)}))}else{let o=gd(i,r);if(!this._skipUTF8Validation&&!Sx(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===wd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=xt):(this._state=No,setImmediate(()=>{this.emit("message",o,!1),this._state=xt,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,vx),this.end();else{let i=e.readUInt16BE(0);if(!SE(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Lo(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!Sx(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=xt;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=xt):(this._state=No,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=xt,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[yE]=o,l}};Tx.exports=_d});var vd=ce((r3,kx)=>{"use strict";var{Duplex:n3}=fe("stream"),{randomFillSync:AE}=fe("crypto"),{types:{isUint8Array:IE}}=fe("util"),Rx=qr(),{EMPTY_BUFFER:CE,kWebSocket:TE,NOOP:RE}=Jt(),{isBlob:Hr,isValidStatusCode:DE}=Gr(),{mask:Dx,toBuffer:Jn}=Ji(),ht=Symbol("kByteLength"),kE=Buffer.alloc(4),Mo=8*1024,Xn,jr=Mo,At=0,PE=1,OE=2,bd=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=At,this.onerror=RE,this[TE]=void 0}static frame(e,r){let i,o=!1,c=2,l=!1;r.mask&&(i=r.maskBuffer||kE,r.generateMask?r.generateMask(i):(jr===Mo&&(Xn===void 0&&(Xn=Buffer.alloc(Mo)),AE(Xn,0,Mo),jr=0),i[0]=Xn[jr++],i[1]=Xn[jr++],i[2]=Xn[jr++],i[3]=Xn[jr++]),l=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||l)&&r[ht]!==void 0?u=r[ht]:(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 h=Buffer.allocUnsafe(o?u+c:c);return h[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(h[0]|=64),h[1]=x,x===126?h.writeUInt16BE(u,2):x===127&&(h[2]=h[3]=0,h.writeUIntBE(u,4,6)),r.mask?(h[1]|=128,h[c-4]=i[0],h[c-3]=i[1],h[c-2]=i[2],h[c-1]=i[3],l?[h,e]:o?(Dx(e,i,h,c,u),[h]):(Dx(e,i,e,0,u),[h,e])):[h,e]}close(e,r,i,o){let c;if(e===void 0)c=CE;else{if(typeof e!="number"||!DE(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(r);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");if(c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof r=="string")c.write(r,2);else if(IE(r))c.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let l={[ht]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==At?this.enqueue([this.dispatch,c,!1,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):Hr(e)?(o=e.size,c=!1):(e=Jn(e),o=e.length,c=Jn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ht]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Hr(e)?this._state!==At?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==At?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):Hr(e)?(o=e.size,c=!1):(e=Jn(e),o=e.length,c=Jn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ht]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Hr(e)?this._state!==At?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==At?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}send(e,r,i){let o=this._extensions[Rx.extensionName],c=r.binary?2:1,l=r.compress,u,x;typeof e=="string"?(u=Buffer.byteLength(e),x=!1):Hr(e)?(u=e.size,x=!1):(e=Jn(e),u=e.length,x=Jn.readOnly),this._firstFragment?(this._firstFragment=!1,l&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(l=u>=o._threshold),this._compress=l):(l=!1,c=0),r.fin&&(this._firstFragment=!0);let h={[ht]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:x,rsv1:l};Hr(e)?this._state!==At?this.enqueue([this.getBlobData,e,this._compress,h,i]):this.getBlobData(e,this._compress,h,i):this._state!==At?this.enqueue([this.dispatch,e,this._compress,h,i]):this.dispatch(e,this._compress,h,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[ht],this._state=OE,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(Ed,this,u,o);return}this._bufferedBytes-=i[ht];let l=Jn(c);r?this.dispatch(l,r,i,o):(this._state=At,this.sendFrame(t.frame(l,i),o),this.dequeue())}).catch(c=>{process.nextTick(LE,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Rx.extensionName];this._bufferedBytes+=i[ht],this._state=PE,c.compress(e,i.fin,(l,u)=>{if(this._socket.destroyed){let x=new Error("The socket was closed while data was being compressed");Ed(this,x,o);return}this._bufferedBytes-=i[ht],this._state=At,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===At&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][ht],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][ht],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)}};kx.exports=bd;function Ed(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 LE(t,e,r){Ed(t,e,r),t.onerror(e)}});var Ux=ce((i3,Fx)=>{"use strict";var{kForOnEventAttribute:Yi,kListener:Sd}=Jt(),Px=Symbol("kCode"),Ox=Symbol("kData"),Lx=Symbol("kError"),Nx=Symbol("kMessage"),Mx=Symbol("kReason"),Wr=Symbol("kTarget"),Bx=Symbol("kType"),zx=Symbol("kWasClean"),Yt=class{constructor(e){this[Wr]=null,this[Bx]=e}get target(){return this[Wr]}get type(){return this[Bx]}};Object.defineProperty(Yt.prototype,"target",{enumerable:!0});Object.defineProperty(Yt.prototype,"type",{enumerable:!0});var Yn=class extends Yt{constructor(e,r={}){super(e),this[Px]=r.code===void 0?0:r.code,this[Mx]=r.reason===void 0?"":r.reason,this[zx]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Px]}get reason(){return this[Mx]}get wasClean(){return this[zx]}};Object.defineProperty(Yn.prototype,"code",{enumerable:!0});Object.defineProperty(Yn.prototype,"reason",{enumerable:!0});Object.defineProperty(Yn.prototype,"wasClean",{enumerable:!0});var Kr=class extends Yt{constructor(e,r={}){super(e),this[Lx]=r.error===void 0?null:r.error,this[Nx]=r.message===void 0?"":r.message}get error(){return this[Lx]}get message(){return this[Nx]}};Object.defineProperty(Kr.prototype,"error",{enumerable:!0});Object.defineProperty(Kr.prototype,"message",{enumerable:!0});var Qi=class extends Yt{constructor(e,r={}){super(e),this[Ox]=r.data===void 0?null:r.data}get data(){return this[Ox]}};Object.defineProperty(Qi.prototype,"data",{enumerable:!0});var NE={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Yi]&&o[Sd]===e&&!o[Yi])return;let i;if(t==="message")i=function(c,l){let u=new Qi("message",{data:l?c:c.toString()});u[Wr]=this,Bo(e,this,u)};else if(t==="close")i=function(c,l){let u=new Yn("close",{code:c,reason:l.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Wr]=this,Bo(e,this,u)};else if(t==="error")i=function(c){let l=new Kr("error",{error:c,message:c.message});l[Wr]=this,Bo(e,this,l)};else if(t==="open")i=function(){let c=new Yt("open");c[Wr]=this,Bo(e,this,c)};else return;i[Yi]=!!r[Yi],i[Sd]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[Sd]===e&&!r[Yi]){this.removeListener(t,r);break}}};Fx.exports={CloseEvent:Yn,ErrorEvent:Kr,Event:Yt,EventTarget:NE,MessageEvent:Qi};function Bo(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var zo=ce((s3,qx)=>{"use strict";var{tokenChars:es}=Gr();function Bt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function ME(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,l,u,x=-1,h=-1,m=-1,E=0;for(;E<t.length;E++)if(h=t.charCodeAt(E),l===void 0)if(m===-1&&es[h]===1)x===-1&&(x=E);else if(E!==0&&(h===32||h===9))m===-1&&x!==-1&&(m=E);else if(h===59||h===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${E}`);m===-1&&(m=E);let _=t.slice(x,m);h===44?(Bt(e,_,r),r=Object.create(null)):l=_,x=m=-1}else throw new SyntaxError(`Unexpected character at index ${E}`);else if(u===void 0)if(m===-1&&es[h]===1)x===-1&&(x=E);else if(h===32||h===9)m===-1&&x!==-1&&(m=E);else if(h===59||h===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${E}`);m===-1&&(m=E),Bt(r,t.slice(x,m),!0),h===44&&(Bt(e,l,r),r=Object.create(null),l=void 0),x=m=-1}else if(h===61&&x!==-1&&m===-1)u=t.slice(x,E),x=m=-1;else throw new SyntaxError(`Unexpected character at index ${E}`);else if(o){if(es[h]!==1)throw new SyntaxError(`Unexpected character at index ${E}`);x===-1?x=E:i||(i=!0),o=!1}else if(c)if(es[h]===1)x===-1&&(x=E);else if(h===34&&x!==-1)c=!1,m=E;else if(h===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${E}`);else if(h===34&&t.charCodeAt(E-1)===61)c=!0;else if(m===-1&&es[h]===1)x===-1&&(x=E);else if(x!==-1&&(h===32||h===9))m===-1&&(m=E);else if(h===59||h===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${E}`);m===-1&&(m=E);let _=t.slice(x,m);i&&(_=_.replace(/\\/g,""),i=!1),Bt(r,u,_),h===44&&(Bt(e,l,r),r=Object.create(null),l=void 0),u=void 0,x=m=-1}else throw new SyntaxError(`Unexpected character at index ${E}`);if(x===-1||c||h===32||h===9)throw new SyntaxError("Unexpected end of input");m===-1&&(m=E);let S=t.slice(x,m);return l===void 0?Bt(e,S,r):(u===void 0?Bt(r,S,!0):i?Bt(r,u,S.replace(/\\/g,"")):Bt(r,u,S),Bt(e,l,r)),e}function BE(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(", ")}qx.exports={format:BE,parse:ME}});var Go=ce((c3,Qx)=>{"use strict";var zE=fe("events"),FE=fe("https"),UE=fe("http"),jx=fe("net"),qE=fe("tls"),{randomBytes:GE,createHash:HE}=fe("crypto"),{Duplex:o3,Readable:a3}=fe("stream"),{URL:Ad}=fe("url"),Dn=qr(),jE=yd(),WE=vd(),{isBlob:KE}=Gr(),{BINARY_TYPES:Gx,CLOSE_TIMEOUT:$E,EMPTY_BUFFER:Fo,GUID:VE,kForOnEventAttribute:Id,kListener:ZE,kStatusCode:JE,kWebSocket:je,NOOP:Wx}=Jt(),{EventTarget:{addEventListener:XE,removeEventListener:YE}}=Ux(),{format:QE,parse:ev}=zo(),{toBuffer:tv}=Ji(),Kx=Symbol("kAborted"),Cd=[8,13],Qt=["CONNECTING","OPEN","CLOSING","CLOSED"],nv=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,me=class t extends zE{constructor(e,r,i){super(),this._binaryType=Gx[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Fo,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),$x(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Gx.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 jE({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxBufferedChunks:i.maxBufferedChunks,maxFragments:i.maxFragments,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new WE(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[je]=this,c[je]=this,e[je]=this,o.on("conclude",sv),o.on("drain",ov),o.on("error",av),o.on("message",cv),o.on("ping",dv),o.on("pong",lv),c.onerror=uv,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Jx),e.on("data",qo),e.on("end",Xx),e.on("error",Yx),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[Dn.extensionName]&&this._extensions[Dn.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){dt(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),Zx(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Td(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Fo,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Td(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Fo,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Td(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[Dn.extensionName]||(o.compress=!1),this._sender.send(e||Fo,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){dt(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(me,"CONNECTING",{enumerable:!0,value:Qt.indexOf("CONNECTING")});Object.defineProperty(me.prototype,"CONNECTING",{enumerable:!0,value:Qt.indexOf("CONNECTING")});Object.defineProperty(me,"OPEN",{enumerable:!0,value:Qt.indexOf("OPEN")});Object.defineProperty(me.prototype,"OPEN",{enumerable:!0,value:Qt.indexOf("OPEN")});Object.defineProperty(me,"CLOSING",{enumerable:!0,value:Qt.indexOf("CLOSING")});Object.defineProperty(me.prototype,"CLOSING",{enumerable:!0,value:Qt.indexOf("CLOSING")});Object.defineProperty(me,"CLOSED",{enumerable:!0,value:Qt.indexOf("CLOSED")});Object.defineProperty(me.prototype,"CLOSED",{enumerable:!0,value:Qt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(me.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(me.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Id])return e[ZE];return null},set(e){for(let r of this.listeners(t))if(r[Id]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[Id]:!0})}})});me.prototype.addEventListener=XE;me.prototype.removeEventListener=YE;Qx.exports=me;function $x(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:$E,protocolVersion:Cd[1],maxBufferedChunks:1048576,maxFragments:131072,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=o.autoPong,t._closeTimeout=o.closeTimeout,!Cd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Cd.join(", ")})`);let c;if(e instanceof Ad)c=e;else try{c=new Ad(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;Uo(t,A);return}let h=l?443:80,m=GE(16).toString("base64"),E=l?FE.request:UE.request,S=new Set,_;if(o.createConnection=o.createConnection||(l?iv:rv),o.defaultPort=o.defaultPort||h,o.port=c.port||h,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":m,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(_=new Dn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=QE({[Dn.extensionName]:_.offer()})),r.length){for(let A of r){if(typeof A!="string"||!nv.test(A)||S.has(A))throw new SyntaxError("An invalid or duplicated subprotocol was specified");S.add(A)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),u){let A=o.path.split(":");o.socketPath=A[0],o.path=A[1]}let v;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=l,t._originalHostOrSocketPath=u?o.socketPath:c.host;let A=i&&i.headers;if(i={...i,headers:{}},A)for(let[I,D]of Object.entries(A))i.headers[I.toLowerCase()]=D}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=E(o),t._redirects&&t.emit("redirect",t.url,v)}else v=t._req=E(o);o.timeout&&v.on("timeout",()=>{dt(t,v,"Opening handshake has timed out")}),v.on("error",A=>{v===null||v[Kx]||(v=t._req=null,Uo(t,A))}),v.on("response",A=>{let I=A.headers.location,D=A.statusCode;if(I&&o.followRedirects&&D>=300&&D<400){if(++t._redirects>o.maxRedirects){dt(t,v,"Maximum redirects exceeded");return}v.abort();let O;try{O=new Ad(I,e)}catch{let k=new SyntaxError(`Invalid URL: ${I}`);Uo(t,k);return}$x(t,O,r,i)}else t.emit("unexpected-response",v,A)||dt(t,v,`Unexpected server response: ${A.statusCode}`)}),v.on("upgrade",(A,I,D)=>{if(t.emit("upgrade",A),t.readyState!==me.CONNECTING)return;v=t._req=null;let O=A.headers.upgrade;if(O===void 0||O.toLowerCase()!=="websocket"){dt(t,I,"Invalid Upgrade header");return}let y=HE("sha1").update(m+VE).digest("base64");if(A.headers["sec-websocket-accept"]!==y){dt(t,I,"Invalid Sec-WebSocket-Accept header");return}let k=A.headers["sec-websocket-protocol"],L;if(k!==void 0?S.size?S.has(k)||(L="Server sent an invalid subprotocol"):L="Server sent a subprotocol but none was requested":S.size&&(L="Server sent no subprotocol"),L){dt(t,I,L);return}k&&(t._protocol=k);let U=A.headers["sec-websocket-extensions"];if(U!==void 0){if(!_){dt(t,I,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let z;try{z=ev(U)}catch{dt(t,I,"Invalid Sec-WebSocket-Extensions header");return}let Z=Object.keys(z);if(Z.length!==1||Z[0]!==Dn.extensionName){dt(t,I,"Server indicated an extension that was not requested");return}try{_.accept(z[Dn.extensionName])}catch{dt(t,I,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[Dn.extensionName]=_}t.setSocket(I,D,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(v,t):v.end()}function Uo(t,e){t._readyState=me.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function rv(t){return t.path=t.socketPath,jx.connect(t)}function iv(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=jx.isIP(t.host)?"":t.host),qE.connect(t)}function dt(t,e,r){t._readyState=me.CLOSING;let i=new Error(r);Error.captureStackTrace(i,dt),e.setHeader?(e[Kx]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Uo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Td(t,e,r){if(e){let i=KE(e)?e.size:tv(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Qt[t.readyState]})`);process.nextTick(r,i)}}function sv(t,e){let r=this[je];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[je]!==void 0&&(r._socket.removeListener("data",qo),process.nextTick(Vx,r._socket),t===1005?r.close():r.close(t,e))}function ov(){let t=this[je];t.isPaused||t._socket.resume()}function av(t){let e=this[je];e._socket[je]!==void 0&&(e._socket.removeListener("data",qo),process.nextTick(Vx,e._socket),e.close(t[JE])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Hx(){this[je].emitClose()}function cv(t,e){this[je].emit("message",t,e)}function dv(t){let e=this[je];e._autoPong&&e.pong(t,!this._isServer,Wx),e.emit("ping",t)}function lv(t){this[je].emit("pong",t)}function Vx(t){t.resume()}function uv(t){let e=this[je];e.readyState!==me.CLOSED&&(e.readyState===me.OPEN&&(e._readyState=me.CLOSING,Zx(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Zx(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Jx(){let t=this[je];if(this.removeListener("close",Jx),this.removeListener("data",qo),this.removeListener("end",Xx),t._readyState=me.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[je]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Hx),t._receiver.on("finish",Hx))}function qo(t){this[je]._receiver.write(t)||this.pause()}function Xx(){let t=this[je];t._readyState=me.CLOSING,t._receiver.end(),this.end()}function Yx(){let t=this[je];this.removeListener("error",Yx),this.on("error",Wx),t&&(t._readyState=me.CLOSING,this.destroy())}});var rh=ce((l3,nh)=>{"use strict";var d3=Go(),{Duplex:fv}=fe("stream");function eh(t){t.emit("close")}function xv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function th(t){this.removeListener("error",th),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function hv(t,e){let r=!0,i=new fv({...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(eh,i);return}let l=!1;t.once("error",function(x){l=!0,c(x)}),t.once("close",function(){l||c(o),process.nextTick(eh,i)}),r&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,l){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,l)});return}t.send(o,l)},i.on("end",xv),i.on("error",th),i}nh.exports=hv});var Rd=ce((u3,ih)=>{"use strict";var{tokenChars:pv}=Gr();function gv(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&&pv[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}ih.exports={parse:gv}});var uh=ce((x3,lh)=>{"use strict";var mv=fe("events"),Ho=fe("http"),{Duplex:f3}=fe("stream"),{createHash:wv}=fe("crypto"),sh=zo(),Qn=qr(),_v=Rd(),yv=Go(),{CLOSE_TIMEOUT:bv,GUID:Ev,kWebSocket:vv}=Jt(),Sv=/^[+/0-9A-Za-z]{22}==$/,oh=0,ah=1,dh=2,Dd=class extends mv{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:1024*1024,maxFragments:128*1024,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:bv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:yv,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=Ho.createServer((i,o)=>{let c=Ho.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=Av(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=oh}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===dh){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(ts,this);return}if(e&&this.once("close",e),this._state!==ah)if(this._state=ah,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(ts,this):process.nextTick(ts,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{ts(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",ch);let c=e.headers["sec-websocket-key"],l=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){er(this,e,r,405,"Invalid HTTP method");return}if(l===void 0||l.toLowerCase()!=="websocket"){er(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!Sv.test(c)){er(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){er(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){ns(r,400);return}let x=e.headers["sec-websocket-protocol"],h=new Set;if(x!==void 0)try{h=_v.parse(x)}catch{er(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let m=e.headers["sec-websocket-extensions"],E={};if(this.options.perMessageDeflate&&m!==void 0){let S=new Qn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let _=sh.parse(m);_[Qn.extensionName]&&(S.accept(_[Qn.extensionName]),E[Qn.extensionName]=S)}catch{er(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let S={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(S,(_,v,A,I)=>{if(!_)return ns(r,v||401,A,I);this.completeUpgrade(E,c,h,e,r,i,o)});return}if(!this.options.verifyClient(S))return ns(r,401)}this.completeUpgrade(E,c,h,e,r,i,o)}completeUpgrade(e,r,i,o,c,l,u){if(!c.readable||!c.writable)return c.destroy();if(c[vv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>oh)return ns(c,503);let h=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${wv("sha1").update(r+Ev).digest("base64")}`],m=new this.options.WebSocket(null,void 0,this.options);if(i.size){let E=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;E&&(h.push(`Sec-WebSocket-Protocol: ${E}`),m._protocol=E)}if(e[Qn.extensionName]){let E=e[Qn.extensionName].params,S=sh.format({[Qn.extensionName]:[E]});h.push(`Sec-WebSocket-Extensions: ${S}`),m._extensions=e}this.emit("headers",h,o),c.write(h.concat(`\r
10
+ `),this.stream=void 0;return}this.currentDate!==void 0&&cs(this.dir,this.prefix,e,this.opts.retentionDays),this.currentDate=e}close(){this.stream?.end(),this.stream=void 0,this.currentDate=void 0}}});import{appendFileSync as Tg,mkdirSync as Rg}from"node:fs";import{join as Cg}from"node:path";function _l(t){let e=t.retentionDays??Og,r=t.clock??(()=>Cn(new Date));ls={bridgeSink:new Xr(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new Xr(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();cs(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])cs(t.agentLogsDir(o),"agent",i,e)}function Lg(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function yl(t){Aa=t}function El(t){return sr[Aa]<=sr[t]}function bl(t,e){let r=sr[t];return r===void 0?!0:r>=sr[e]}function us(t){wl={...t}}function vl(t){let e=(u,f=2)=>String(u).padStart(f,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),d=e(o%60);return`${Cn(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${d}`}function It(t,e,r,i,o){try{let c=`${JSON.stringify({ts:vl(new Date),level:e,module:r,msg:i,...o})}
11
+ `;Rg(t,{recursive:!0}),Tg(Cg(t,ir("bridge",Cn(new Date))),c)}catch{}}function Ng(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function ds(t,e,r,i,o){if(sr[t]<sr[Aa])return;let c=`${JSON.stringify({ts:vl(new Date),level:t,module:e,msg:r,...wl,...i})}
12
+ `;if(ls){let d=Ng(o,i),u=d?Lg(ls,d):ls.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?Pg.write(c):Dg.write(c)}function q(t,e){return{debug:(r,i)=>ds("debug",t,r,i,e),info:(r,i)=>ds("info",t,r,i,e),warn:(r,i)=>ds("warn",t,r,i,e),error:(r,i)=>ds("error",t,r,i,e),child:r=>q(`${t}.${r}`,e),forAgent:r=>q(t,r)}}var sr,Aa,Dg,Pg,wl,Og,ls,te=et(()=>{"use strict";rr();Ia();sr={debug:10,info:20,warn:30,error:40},Aa=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),Dg=process.stdout,Pg=process.stderr,wl={},Og=Ve("COZE_BRIDGE_LOG_RETENTION_DAYS",30),ls=null});var T,We=et(()=>{"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 kl={};va(kl,{ACP_WRAPPER_NPM_PACKAGES:()=>ei,_resetAcpInstallerForTests:()=>Gg,_setBinaryPathCacheForTests:()=>Hg,buildAcpSpawn:()=>ti,ensureAcpInstalled:()=>or,getAcpBinaryPath:()=>fs,pickWhichLine:()=>Ra,probeAcpVersion:()=>Ug,resolveAcpCommand:()=>Al});import{readFileSync as Sl}from"node:fs";import{createRequire as Mg}from"node:module";import{dirname as Bg,resolve as Fg}from"node:path";function Ra(t){let e=t.split(/\r?\n/).map(i=>i.trim()).filter(Boolean);if(e.length===0)return;if(process.platform!=="win32")return e[0];let r=i=>e.find(o=>o.toLowerCase().endsWith(i));return r(".cmd")??r(".exe")??r(".bat")??r(".ps1")??e[0]}function zg(t){let e=Il.resolve(`${t.npmPackage}/package.json`),r=Bg(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 Fg(r,o)}async function or(t,e){let r=Ta[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=zg(r);return Qr.set(t,o),ka.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw ka.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:r.npmPackage,err:String(o)}),new 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 Ug(t){let e=Ta[t];if(e)try{let r=Il.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){ka.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function fs(t){return Qr.get(t)}function Al(t,e){if(e)return e;let r=fs(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 ti(t,e,r){if(e)return{command:e,args:[...r]};let i=Al(t);return{command:process.execPath,args:[i,...r]}}function Gg(){Qr.clear()}function Hg(t,e){Qr.set(t,e)}var ka,Ta,ei,Il,Qr,rn=et(()=>{"use strict";We();te();ka=q("agents.acp-installer"),Ta={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@agentclientprotocol/codex-acp",binary:"codex-acp"}},ei=Object.values(Ta).filter(t=>t!==void 0).map(t=>t.npmPackage),Il=Mg(import.meta.url),Qr=new Map});import{chmod as jg,mkdir as Wg,readFile as Kg,rename as $g,rm as Vg,writeFile as Yg}from"node:fs/promises";import{dirname as Zg}from"node:path";async function ar(t){try{let e=await Kg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function sn(t,e,r){await Wg(Zg(t),{recursive:!0});let i=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{await Yg(i,e,{encoding:"utf8",mode:r?.mode}),await $g(i,t),r?.mode!==void 0&&await jg(t,r.mode)}catch(o){throw await Vg(i,{force:!0}).catch(()=>{}),o}}async function cr(t,e,r){await sn(t,`${JSON.stringify(e,null,2)}
14
+ `,r)}var on=et(()=>{"use strict"});import{promises as Cl,readdirSync as Jg}from"node:fs";import{homedir as Xg}from"node:os";import{sep as Qg,join as ke,resolve as Dl}from"node:path";function Q(t){let e=t??Xg(),r=ke(e,".coze"),i=ke(r,"bridge"),o=ke(i,"lib"),c=ke(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:ke(o,"index.js"),binDir:ke(i,"bin"),pidFile:ke(i,"bridge.pid"),portFile:ke(i,"bridge.port"),tokenFile:ke(i,"bridge.token"),patTokenFile:ke(i,"pat-token"),agentEnvFile:ke(i,"agent-env.json"),logFile:ke(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:ke(c,"daemon-stdio.log"),installLock:ke(i,"install.lock"),configFile:ke(i,"config.json"),agentsRoot:ke(r,"agents")}}function Ye(t,e=Q()){let r=ke(e.agentsRoot,t);return{root:r,config:ke(r,"config.json"),workspace:ke(r,"workspace"),logs:ke(r,"logs")}}function xs(t=Q()){try{return Jg(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function ni(t,e){let r=await Cl.realpath(Dl(t)).catch(()=>null);if(!r)return!1;let i=await Cl.realpath(Dl(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+Qg)}var Oe=et(()=>{"use strict"});var ps={};va(ps,{AGENT_CONFIG_FILE_MODE:()=>hs,enforceAgentConfigMode:()=>nm,loadAgentConfig:()=>Te,persistAgentSessions:()=>ri,persistAgentSkills:()=>ii,saveAgentConfig:()=>Fe});import{chmod as em,stat as tm}from"node:fs/promises";function Te(t,e){return ar(Ye(t,e).config)}function Fe(t,e){return cr(Ye(t.agentId,e).config,t,{mode:hs})}async function nm(t,e){if(process.platform==="win32")return;let r=Ye(t,e).config;try{let i=await tm(r);if(!i.isFile())return;let o=i.mode&511;o!==hs&&(await em(r,hs),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 ri(t,e,r){let i=await Te(t,r);i&&(i.sessions=Object.fromEntries(e),await Fe(i,r))}async function ii(t,e,r){let i=await Te(t,r);i&&(i.skills=e,await Fe(i,r))}var Pl,hs,an=et(()=>{"use strict";on();te();Oe();Pl=q("agent-config"),hs=384});var Pa=oe((K2,Nl)=>{Nl.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 ms=oe(Bl=>{var Ml={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 cm(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(Ml))Bl[t]=cm(Ml[t])});var Hl=oe((V2,Gl)=>{var dm=le("fs"),Le=le("path"),Fl=Pa(),lm=ms(),um=typeof process=="object"&&process.platform==="win32",zl=t=>typeof t=="object"&&t!==null,Ul=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function be(t){this.sep=Le.sep,this.fs=dm,zl(t)&&zl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Gl.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 d;try{d=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(d&&d.isFile())throw lm.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 d=Le.dirname(t);o.fs.existsSync(d)||o.makeDir(d);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};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(d){if(d&&!r)return o(!1);c.fs.stat(t,function(u,f){if(d&&f.isDirectory())return o(!1);var h=Le.dirname(t);c.fs.exists(h,function(g){g||c.makeDir(h),c.fs.open(t,"w",438,function(w,S){w?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(_,v){c.fs.write(v,e,0,e.length,0,function(){c.fs.close(v,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):S?c.fs.write(S,e,0,e.length,0,function(){c.fs.close(S,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};be.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let d=[];return e.fs.readdirSync(i).forEach(function(u){let f=Le.join(i,u),h=e.fs.statSync(f);(!o||o.test(f))&&d.push(Le.normalize(f)+(h.isDirectory()?e.sep:"")),h.isDirectory()&&c&&(d=d.concat(r(f,o,c)))}),d}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 d=c.length;if(!d)return e(null,i);c.forEach(function(u){u=Le.join(t,u),r.fs.stat(u,function(f,h){if(f)return e(f);h&&(i.push(Le.normalize(u)+(h.isDirectory()?r.sep:"")),h.isDirectory()?r.findFilesAsync(u,function(g,w){if(g)return e(g);i=i.concat(w),--d||e(null,i)}):--d||e(null,i))})})})};be.prototype.getAttributes=function(){};be.prototype.setAttributes=function(){};be.crc32update=function(t,e){return Ul[(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 Fl.STORED:return"STORED ("+t+")";case Fl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};be.canonical=function(t){if(!t)return"";let e=Le.posix.normalize("/"+t.split("\\").join("/"));return Le.join(".",e)};be.zipnamefix=function(t){if(!t)return"";let e=Le.posix.normalize("/"+t.split("\\").join("/"));return Le.posix.join(".",e)};be.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let r=t.length>>>0;for(let i=r-1;i>=0;i--)if(e(t[i],i,t))return t[i]};be.sanitize=function(t,e){t=Le.resolve(Le.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Le.normalize(Le.join(t,r.slice(i,o).join(Le.sep)));if(c.indexOf(t)===0)return c}return Le.normalize(Le.join(t,Le.basename(e)))};be.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};be.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};be.fromDOS2Date=function(t){return new Date((t>>25&127)+1980,Math.max((t>>21&15)-1,0),Math.max(t>>16&31,1),t>>11&31,t>>5&63,(t&31)<<1)};be.fromDate2DOS=function(t){let e=0,r=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),r=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|r};be.isWin=um;be.crcTable=Ul});var jl=oe((Y2,ql)=>{var fm=le("path");ql.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=fm.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 Kl=oe((Z2,Wl)=>{Wl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var ur=oe((J2,lr)=>{lr.exports=Hl();lr.exports.Constants=Pa();lr.exports.Errors=ms();lr.exports.FileAttr=jl();lr.exports.decoder=Kl()});var Vl=oe((X2,$l)=>{var cn=ur(),U=cn.Constants;$l.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,d=0,u=0,f=0,h=0,g=0,w=0,S=0,_=0,v=0;t|=cn.isWin?2560:768,r|=U.FLG_EFS;let I={extraLen:0},A=y=>Math.max(0,y)>>>0,R=y=>Math.max(0,y)&65535,O=y=>Math.max(0,y)&255;return o=cn.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 cn.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=cn.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=A(y)},get timeHighByte(){return O(o>>>8)},get crc(){return c},set crc(y){c=A(y)},get compressedSize(){return d},set compressedSize(y){d=A(y)},get size(){return u},set size(y){u=A(y)},get fileNameLength(){return f},set fileNameLength(y){f=y},get extraLength(){return h},set extraLength(y){h=y},get extraLocalLength(){return I.extraLen},set extraLocalLength(y){I.extraLen=y},get commentLength(){return g},set commentLength(y){g=y},get diskNumStart(){return w},set diskNumStart(y){w=A(y)},get inAttr(){return S},set inAttr(y){S=A(y)},get attr(){return _},set attr(y){_=A(y)},get fileAttr(){return(_||0)>>16&4095},get offset(){return v},set offset(y){v=A(y)},get encrypted(){return(r&U.FLG_ENC)===U.FLG_ENC},get centralHeaderSize(){return U.CENHDR+f+h+g},get realDataOffset(){return v+U.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(y){var C=y.slice(v,v+U.LOCHDR);if(C.readUInt32LE(0)!==U.LOCSIG)throw cn.Errors.INVALID_LOC();I.version=C.readUInt16LE(U.LOCVER),I.flags=C.readUInt16LE(U.LOCFLG),I.flags_desc=(I.flags&U.FLG_DESC)>0,I.method=C.readUInt16LE(U.LOCHOW),I.time=C.readUInt32LE(U.LOCTIM),I.crc=C.readUInt32LE(U.LOCCRC),I.compressedSize=C.readUInt32LE(U.LOCSIZ),I.size=C.readUInt32LE(U.LOCLEN),I.fnameLen=C.readUInt16LE(U.LOCNAM),I.extraLen=C.readUInt16LE(U.LOCEXT);let L=v+U.LOCHDR+I.fnameLen,F=L+I.extraLen;return y.slice(L,F)},loadFromBinary:function(y){if(y.length!==U.CENHDR||y.readUInt32LE(0)!==U.CENSIG)throw cn.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),d=y.readUInt32LE(U.CENSIZ),u=y.readUInt32LE(U.CENLEN),f=y.readUInt16LE(U.CENNAM),h=y.readUInt16LE(U.CENEXT),g=y.readUInt16LE(U.CENCOM),w=y.readUInt16LE(U.CENDSK),S=y.readUInt16LE(U.CENATT),_=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(d,U.LOCSIZ),y.writeUInt32LE(u,U.LOCLEN),y.writeUInt16LE(f,U.LOCNAM),y.writeUInt16LE(I.extraLen,U.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(U.CENHDR+f+h+g);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(d,U.CENSIZ),y.writeUInt32LE(u,U.CENLEN),y.writeUInt16LE(f,U.CENNAM),y.writeUInt16LE(h,U.CENEXT),y.writeUInt16LE(g,U.CENCOM),y.writeUInt16LE(w,U.CENDSK),y.writeUInt16LE(S,U.CENATT),y.writeUInt32LE(_,U.CENATX),y.writeUInt32LE(v,U.CENOFF),y},toJSON:function(){let y=function(C){return C+" bytes"};return{made:t,version:e,flags:r,method:cn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(d),size:y(u),fileNameLength:y(f),extraLength:y(h),commentLength:y(g),diskNumStart:w,inAttr:S,attr:_,offset:v,centralHeaderSize:y(U.CENHDR+f+h+g)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Zl=oe((Q2,Yl)=>{var fr=ur(),_e=fr.Constants;Yl.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 _e.ENDHDR+o},loadFromBinary:function(c){if((c.length!==_e.ENDHDR||c.readUInt32LE(0)!==_e.ENDSIG)&&(c.length<_e.ZIP64HDR||c.readUInt32LE(0)!==_e.ZIP64SIG))throw fr.Errors.INVALID_END();c.readUInt32LE(0)===_e.ENDSIG?(t=c.readUInt16LE(_e.ENDSUB),e=c.readUInt16LE(_e.ENDTOT),r=c.readUInt32LE(_e.ENDSIZ),i=c.readUInt32LE(_e.ENDOFF),o=c.readUInt16LE(_e.ENDCOM)):(t=fr.readBigUInt64LE(c,_e.ZIP64SUB),e=fr.readBigUInt64LE(c,_e.ZIP64TOT),r=fr.readBigUInt64LE(c,_e.ZIP64SIZE),i=fr.readBigUInt64LE(c,_e.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(_e.ENDHDR+o);return c.writeUInt32LE(_e.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,_e.ENDSUB),c.writeUInt16LE(e,_e.ENDTOT),c.writeUInt32LE(r,_e.ENDSIZ),c.writeUInt32LE(i,_e.ENDOFF),c.writeUInt16LE(o,_e.ENDCOM),c.fill(" ",_e.ENDHDR),c},toJSON:function(){let c=function(d,u){let f=d.toString(16).toUpperCase();for(;f.length<u;)f="0"+f;return"0x"+f};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var La=oe(Oa=>{Oa.EntryHeader=Vl();Oa.MainHeader=Zl()});var Xl=oe((tI,Jl)=>{Jl.exports=function(t){var e=le("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],d=0;o.on("data",function(u){c.push(u),d+=u.length}),o.on("end",function(){var u=Buffer.alloc(d),f=0;u.fill(0);for(var h=0;h<c.length;h++){var g=c[h];g.copy(u,f),f+=g.length}i&&i(u)}),o.end(t)}}}});var eu=oe((nI,Ql)=>{var xm=+(process.versions?process.versions.node:"").split(".")[0]||0;Ql.exports=function(t,e){var r=le("zlib");let i=xm>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),d=[],u=0;c.on("data",function(f){d.push(f),u+=f.length}),c.on("end",function(){var f=Buffer.alloc(u),h=0;f.fill(0);for(var g=0;g<d.length;g++){var w=d[g];w.copy(f,h),h+=w.length}o&&o(f)}),c.end(t)}}}});var su=oe((rI,iu)=>{"use strict";var{randomFillSync:tu}=le("crypto"),hm=ms(),pm=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=e>>>1^3988292384:e>>>=1;return e>>>0}),ru=(t,e)=>Math.imul(t,e)>>>0,nu=(t,e)=>pm[(t^e)&255]^t>>>8,si=()=>typeof tu=="function"?tu(Buffer.alloc(12)):si.node();si.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 ws={genSalt:si};function _s(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])}_s.prototype.updateKeys=function(t){let e=this.keys;return e[0]=nu(e[0],t),e[1]+=e[0]&255,e[1]=ru(e[1],134775813)+1,e[2]=nu(e[2],e[1]>>>24),t};_s.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return ru(t,t^1)>>8&255};function gm(t){let e=new _s(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 mm(t){let e=new _s(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 wm(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=gm(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw hm.WRONG_PASSWORD();return i(t.slice(12))}function _m(t){Buffer.isBuffer(t)&&t.length>=12?ws.genSalt=function(){return t.slice(0,12)}:t==="node"?ws.genSalt=si.node:ws.genSalt=si}function ym(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=mm(r),c=ws.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)}iu.exports={decrypt:wm,encrypt:ym,_salter:_m}});var ou=oe(ys=>{ys.Deflater=Xl();ys.Inflater=eu();ys.ZipCrypto=su()});var Ma=oe((sI,au)=>{var ae=ur(),Em=La(),ve=ae.Constants,Na=ou();au.exports=function(t,e){var r=new Em.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,d=null,u=Buffer.alloc(0),f=Buffer.alloc(0),h=!0;let g=t,w=typeof g.decoder=="object"?g.decoder:ae.decoder;h=w.hasOwnProperty("efs")?w.efs:!1;function S(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(f=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function _(y){if(!r.flags_desc&&!r.localHeader.flags_desc){if(ae.crc32(y)!==r.localHeader.crc)return!1}else{let C={},L=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(L)==ve.LOCSIG||e.readUInt32LE(L)==ve.CENSIG)throw ae.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(L)==ve.EXTSIG)C.crc=e.readUInt32LE(L+ve.EXTCRC),C.compressedSize=e.readUInt32LE(L+ve.EXTSIZ),C.size=e.readUInt32LE(L+ve.EXTLEN);else if(e.readUInt16LE(L+12)===19280)C.crc=e.readUInt32LE(L+ve.EXTCRC-4),C.compressedSize=e.readUInt32LE(L+ve.EXTSIZ-4),C.size=e.readUInt32LE(L+ve.EXTLEN-4);else throw ae.Errors.DESCRIPTOR_UNKNOWN();if(C.compressedSize!==r.compressedSize||C.size!==r.size||C.crc!==r.crc)throw ae.Errors.DESCRIPTOR_FAULTY();if(ae.crc32(y)!==C.crc)return!1}return!0}function v(y,C,L){if(typeof C>"u"&&typeof y=="string"&&(L=y,y=void 0),c)return y&&C&&C(Buffer.alloc(0),ae.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var F=S();if(F.length===0)return y&&C&&C(F),F;if(r.encrypted){if(typeof L!="string"&&!Buffer.isBuffer(L))throw ae.Errors.INVALID_PASS_PARAM();F=Na.ZipCrypto.decrypt(F,r,L)}var M=Buffer.alloc(r.size);switch(r.method){case ae.Constants.STORED:if(F.copy(M),_(M))return y&&C&&C(M),M;throw y&&C&&C(M,ae.Errors.BAD_CRC()),ae.Errors.BAD_CRC();case ae.Constants.DEFLATED:var Y=new Na.Inflater(F,r.size);if(y)Y.inflateAsync(function($){$.copy($,0),C&&(_($)?C($):C($,ae.Errors.BAD_CRC()))});else{if(Y.inflate(M).copy(M,0),!_(M))throw ae.Errors.BAD_CRC(`"${w.decode(i)}"`);return M}break;default:throw y&&C&&C(Buffer.alloc(0),ae.Errors.UNKNOWN_METHOD()),ae.Errors.UNKNOWN_METHOD()}}function I(y,C){if((!d||!d.length)&&Buffer.isBuffer(e))return y&&C&&C(S()),S();if(d.length&&!c){var L;switch(r.method){case ae.Constants.STORED:return r.compressedSize=r.size,L=Buffer.alloc(d.length),d.copy(L),y&&C&&C(L),L;default:case ae.Constants.DEFLATED:var F=new Na.Deflater(d);if(y)F.deflateAsync(function(Y){L=Buffer.alloc(Y.length),r.compressedSize=Y.length,Y.copy(L),C&&C(L)});else{var M=F.deflate();return r.compressedSize=M.length,M}F=null;break}}else if(y&&C)C(Buffer.alloc(0));else return Buffer.alloc(0)}function A(y,C){return ae.readBigUInt64LE(y,C)}function R(y){try{for(var C=0,L,F,M;C+4<y.length;)L=y.readUInt16LE(C),C+=2,F=y.readUInt16LE(C),C+=2,M=y.slice(C,C+F),C+=F,ve.ID_ZIP64===L&&O(M)}catch{throw ae.Errors.EXTRA_FIELD_PARSE_ERROR()}}function O(y){var C,L,F,M;y.length>=ve.EF_ZIP64_SCOMP&&(C=A(y,ve.EF_ZIP64_SUNCOMP),r.size===ve.EF_ZIP64_OR_32&&(r.size=C)),y.length>=ve.EF_ZIP64_RHO&&(L=A(y,ve.EF_ZIP64_SCOMP),r.compressedSize===ve.EF_ZIP64_OR_32&&(r.compressedSize=L)),y.length>=ve.EF_ZIP64_DSN&&(F=A(y,ve.EF_ZIP64_RHO),r.offset===ve.EF_ZIP64_OR_32&&(r.offset=F)),y.length>=ve.EF_ZIP64_DSN+4&&(M=y.readUInt32LE(ve.EF_ZIP64_DSN),r.diskNumStart===ve.EF_ZIP64_OR_16&&(r.diskNumStart=M))}return{get entryName(){return w.decode(i)},get rawEntryName(){return i},set entryName(y){i=ae.toBuffer(y,w.encode);var C=i[i.length-1];c=C===47||C===92,r.fileNameLength=i.length},get efs(){return typeof h=="function"?h(this.entryName):h},get extra(){return u},set extra(y){u=y,r.extraLength=y.length,R(y)},get comment(){return w.decode(o)},set comment(y){if(o=ae.toBuffer(y,w.encode),r.commentLength=o.length,o.length>65535)throw ae.Errors.COMMENT_TOO_LONG()},get name(){var y=w.decode(i);return c?y.substr(y.length-1).split("/").pop():y.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(y){I(!0,y)},setData:function(y){d=ae.toBuffer(y,ae.decoder.encode),!c&&d.length?(r.size=d.length,r.method=ae.Constants.DEFLATED,r.crc=ae.crc32(y),r.changed=!0):r.method=ae.Constants.STORED},getData:function(y){return r.changed?d:v(!1,null,y)},getDataAsync:function(y,C){r.changed?y(d):v(!0,y,C)},set attr(y){r.attr=y},get attr(){return r.attr},set header(y){r.loadFromBinary(y)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=u.length;var y=r.centralHeaderToBinary(),C=ae.Constants.CENHDR;return i.copy(y,C),C+=i.length,u.copy(y,C),C+=r.extraLength,o.copy(y,C),y},packLocalHeader:function(){let y=0;r.flags_efs=this.efs,r.extraLocalLength=f.length;let C=r.localHeaderToBinary(),L=Buffer.alloc(C.length+i.length+r.extraLocalLength);return C.copy(L,y),y+=C.length,i.copy(L,y),y+=i.length,f.copy(L,y),y+=f.length,L},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 lu=oe((oI,du)=>{var cu=Ma(),bm=La(),Ke=ur();du.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new bm.MainHeader,d=!1,u=null;let f=new Set,h=e,{noSort:g,decoder:w}=h;t?v(h.readEntries):d=!0;function S(){let A=new Set;for(let R of Object.keys(i)){let O=R.split("/");if(O.pop(),!!O.length)for(let y=0;y<O.length;y++){let C=O.slice(0,y+1).join("/")+"/";A.add(C)}}for(let R of A)if(!(R in i)){let O=new cu(h);O.entryName=R,O.attr=16,O.temporary=!0,r.push(O),i[O.entryName]=O,f.add(O)}}function _(){if(d=!0,i={},c.diskEntries>(t.length-c.offset)/Ke.Constants.CENHDR)throw Ke.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var A=c.offset,R=0;R<r.length;R++){var O=A,y=new cu(h,t);y.header=t.slice(O,O+=Ke.Constants.CENHDR),y.entryName=t.slice(O,O+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(O,O+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(O,O+y.header.commentLength)),A+=y.header.centralHeaderSize,r[R]=y,i[y.entryName]=y}f.clear(),S()}function v(A){var R=t.length-Ke.Constants.ENDHDR,O=Math.max(0,R-65535),y=O,C=t.length,L=-1,F=0;for(typeof h.trailingSpace=="boolean"&&h.trailingSpace&&(O=0),R;R>=y;R--)if(t[R]===80){if(t.readUInt32LE(R)===Ke.Constants.ENDSIG){L=R,F=R,C=R+Ke.Constants.ENDHDR,y=R-Ke.Constants.END64HDR;continue}if(t.readUInt32LE(R)===Ke.Constants.END64SIG){y=O;continue}if(t.readUInt32LE(R)===Ke.Constants.ZIP64SIG){L=R,C=R+Ke.readBigUInt64LE(t,R+Ke.Constants.ZIP64SIZE)+Ke.Constants.ZIP64LEAD;break}}if(L==-1)throw Ke.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(L,C)),c.commentLength&&(o=t.slice(F+Ke.Constants.ENDHDR)),A&&_()}function I(){r.length>1&&!g&&r.sort((A,R)=>A.entryName.toLowerCase().localeCompare(R.entryName.toLowerCase()))}return{get entries(){return d||_(),r.filter(A=>!f.has(A))},get comment(){return w.decode(o)},set comment(A){o=Ke.toBuffer(A,w.encode),c.commentLength=o.length},getEntryCount:function(){return d?r.length:c.diskEntries},forEach:function(A){this.entries.forEach(A)},getEntry:function(A){return d||_(),i[A]||null},setEntry:function(A){d||_(),r.push(A),i[A.entryName]=A,c.totalEntries=r.length},deleteFile:function(A,R=!0){d||_();let O=i[A];this.getEntryChildren(O,R).map(C=>C.entryName).forEach(this.deleteEntry)},deleteEntry:function(A){d||_();let R=i[A],O=r.indexOf(R);O>=0&&(r.splice(O,1),delete i[A],c.totalEntries=r.length)},getEntryChildren:function(A,R=!0){if(d||_(),typeof A=="object")if(A.isDirectory&&R){let O=[],y=A.entryName;for(let C of r)C.entryName.startsWith(y)&&O.push(C);return O}else return[A];return[]},getChildCount:function(A){if(A&&A.isDirectory){let R=this.getEntryChildren(A);return R.includes(A)?R.length-1:R.length}return 0},compressToBuffer:function(){d||_(),I();let A=[],R=[],O=0,y=0;c.size=0,c.offset=0;let C=0;for(let M of this.entries){let Y=M.getCompressedData();M.header.offset=y;let $=M.packLocalHeader(),ne=$.length+Y.length;y+=ne,A.push($),A.push(Y);let J=M.packCentralHeader();R.push(J),c.size+=J.length,O+=ne+J.length,C++}O+=c.mainHeaderSize,c.offset=y,c.totalEntries=C,y=0;let L=Buffer.alloc(O);for(let M of A)M.copy(L,y),y+=M.length;for(let M of R)M.copy(L,y),y+=M.length;let F=c.toBinary();return o&&o.copy(F,Ke.Constants.ENDHDR),F.copy(L,y),t=L,d=!1,L},toAsyncBuffer:function(A,R,O,y){try{d||_(),I();let C=[],L=[],F=0,M=0,Y=0;c.size=0,c.offset=0;let $=function(ne){if(ne.length>0){let J=ne.shift(),ie=J.entryName+J.extra.toString();O&&O(ie),J.getCompressedDataAsync(function(se){y&&y(ie),J.header.offset=M;let D=J.packLocalHeader(),G=D.length+se.length;M+=G,C.push(D),C.push(se);let W=J.packCentralHeader();L.push(W),c.size+=W.length,F+=G+W.length,Y++,$(ne)})}else{F+=c.mainHeaderSize,c.offset=M,c.totalEntries=Y,M=0;let J=Buffer.alloc(F);C.forEach(function(se){se.copy(J,M),M+=se.length}),L.forEach(function(se){se.copy(J,M),M+=se.length});let ie=c.toBinary();o&&o.copy(ie,Ke.Constants.ENDHDR),ie.copy(J,M),t=J,d=!1,A(J)}};$(Array.from(this.entries))}catch(C){R(C)}}}}});var xu=oe((aI,fu)=>{var Ee=ur(),ye=le("path"),vm=Ma(),Sm=lu(),Dn=(...t)=>Ee.findLast(t,e=>typeof e=="boolean"),uu=(...t)=>Ee.findLast(t,e=>typeof e=="string"),Im=(...t)=>Ee.findLast(t,e=>typeof e=="function"),Am={noSort:!1,readEntries:!1,method:Ee.Constants.NONE,fs:null};fu.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),Am);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=Ee.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new Ee(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=Ee.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=Ee.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw Ee.Errors.INVALID_FILENAME();let c=new Sm(r,i),{canonical:d,sanitize:u,zipnamefix:f}=Ee;function h(_){if(_&&c){var v;if(typeof _=="string"&&(v=c.getEntry(ye.posix.normalize(_))),typeof _=="object"&&typeof _.entryName<"u"&&typeof _.header<"u"&&(v=c.getEntry(_.entryName)),v)return v}return null}function g(_){let{join:v,normalize:I,sep:A}=ye.posix;return v(ye.isAbsolute(_)?"/":".",I(A+_.split("\\").join(A)+A))}function w(_){return _ instanceof RegExp?(function(v){return function(I){return v.test(I)}})(_):typeof _!="function"?()=>!0:_}let S=(_,v)=>{let I=v.slice(-1);return I=I===o.sep?o.sep:"",ye.relative(_,v)+I};return{readFile:function(_,v){var I=h(_);return I&&I.getData(v)||null},childCount:function(_){let v=h(_);if(v)return c.getChildCount(v)},readFileAsync:function(_,v){var I=h(_);I?I.getDataAsync(v):v(null,"getEntry failed for:"+_)},readAsText:function(_,v){var I=h(_);if(I){var A=I.getData();if(A&&A.length)return A.toString(v||"utf8")}return""},readAsTextAsync:function(_,v,I){var A=h(_);A?A.getDataAsync(function(R,O){if(O){v(R,O);return}R&&R.length?v(R.toString(I||"utf8")):v("")}):v("")},deleteFile:function(_,v=!0){var I=h(_);I&&c.deleteFile(I.entryName,v)},deleteEntry:function(_){var v=h(_);v&&c.deleteEntry(v.entryName)},addZipComment:function(_){c.comment=_},getZipComment:function(){return c.comment||""},addZipEntryComment:function(_,v){var I=h(_);I&&(I.comment=v)},getZipEntryComment:function(_){var v=h(_);return v&&v.comment||""},updateFile:function(_,v){var I=h(_);I&&I.setData(v)},addLocalFile:function(_,v,I,A){if(o.fs.existsSync(_)){v=v?g(v):"";let R=ye.win32.basename(ye.win32.normalize(_));v+=I||R;let O=o.fs.statSync(_),y=O.isFile()?o.fs.readFileSync(_):Buffer.alloc(0);O.isDirectory()&&(v+=o.sep),this.addFile(v,y,A,O)}else throw Ee.Errors.FILE_NOT_FOUND(_)},addLocalFileAsync:function(_,v){_=typeof _=="object"?_:{localPath:_};let I=ye.resolve(_.localPath),{comment:A}=_,{zipPath:R,zipName:O}=_,y=this;o.fs.stat(I,function(C,L){if(C)return v(C,!1);R=R?g(R):"";let F=ye.win32.basename(ye.win32.normalize(I));if(R+=O||F,L.isFile())o.fs.readFile(I,function(M,Y){return M?v(M,!1):(y.addFile(R,Y,A,L),setImmediate(v,void 0,!0))});else if(L.isDirectory())return R+=o.sep,y.addFile(R,Buffer.alloc(0),A,L),setImmediate(v,void 0,!0)})},addLocalFolder:function(_,v,I){if(I=w(I),v=v?g(v):"",_=ye.normalize(_),o.fs.existsSync(_)){let A=o.findFiles(_),R=this;if(A.length)for(let O of A){let y=ye.join(v,S(_,O));I(y)&&R.addLocalFile(O,ye.dirname(y))}}else throw Ee.Errors.FILE_NOT_FOUND(_)},addLocalFolderAsync:function(_,v,I,A){A=w(A),I=I?g(I):"",_=ye.normalize(_);var R=this;o.fs.open(_,"r",function(O){if(O&&O.code==="ENOENT")v(void 0,Ee.Errors.FILE_NOT_FOUND(_));else if(O)v(void 0,O);else{var y=o.findFiles(_),C=-1,L=function(){if(C+=1,C<y.length){var F=y[C],M=S(_,F).split("\\").join("/");M=M.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),A(M)?o.fs.stat(F,function(Y,$){Y&&v(void 0,Y),$.isFile()?o.fs.readFile(F,function(ne,J){ne?v(void 0,ne):(R.addFile(I+M,J,"",$),L())}):(R.addFile(I+M+"/",Buffer.alloc(0),"",$),L())}):process.nextTick(()=>{L()})}else v(!0,void 0)};L()}})},addLocalFolderAsync2:function(_,v){let I=this;_=typeof _=="object"?_:{localPath:_},localPath=ye.resolve(g(_.localPath));let{zipPath:A,filter:R,namefix:O}=_;R instanceof RegExp?R=(function(L){return function(F){return L.test(F)}})(R):typeof R!="function"&&(R=function(){return!0}),A=A?g(A):"",O=="latin1"&&(O=L=>L.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof O!="function"&&(O=L=>L);let y=L=>ye.join(A,O(S(localPath,L))),C=L=>ye.win32.basename(ye.win32.normalize(O(L)));o.fs.open(localPath,"r",function(L){L&&L.code==="ENOENT"?v(void 0,Ee.Errors.FILE_NOT_FOUND(localPath)):L?v(void 0,L):o.findFilesAsync(localPath,function(F,M){if(F)return v(F);M=M.filter(Y=>R(y(Y))),M.length||v(void 0,!1),setImmediate(M.reverse().reduce(function(Y,$){return function(ne,J){if(ne||J===!1)return setImmediate(Y,ne,!1);I.addLocalFileAsync({localPath:$,zipPath:ye.dirname(y($)),zipName:C($)},Y)}},v))})})},addLocalFolderPromise:function(_,v){return new Promise((I,A)=>{this.addLocalFolderAsync2(Object.assign({localPath:_},v),(R,O)=>{R&&A(R),O&&I(this)})})},addFile:function(_,v,I,A){_=f(_);let R=h(_),O=R!=null;O||(R=new vm(i),R.entryName=_),R.comment=I||"";let y=typeof A=="object"&&A instanceof o.fs.Stats;y&&(R.header.time=A.mtime);var C=R.isDirectory?16:0;let L=R.isDirectory?16384:32768;return y?L|=4095&A.mode:typeof A=="number"?L|=4095&A:L|=R.isDirectory?493:420,C=(C|L<<16)>>>0,R.attr=C,R.setData(v),O||c.setEntry(R),R},getEntries:function(_){return c.password=_,c?c.entries:[]},getEntry:function(_){return h(_)},getEntryCount:function(){return c.getEntryCount()},forEach:function(_){return c.forEach(_)},extractEntryTo:function(_,v,I,A,R,O){A=Dn(!1,A),R=Dn(!1,R),I=Dn(!0,I),O=uu(R,O);var y=h(_);if(!y)throw Ee.Errors.NO_ENTRY();var C=d(y.entryName),L=u(v,O&&!y.isDirectory?O:I?C:ye.basename(C));if(y.isDirectory){var F=c.getEntryChildren(y);return F.forEach(function($){if($.isDirectory)return;var ne=$.getData();if(!ne)throw Ee.Errors.CANT_EXTRACT_FILE();var J=d($.entryName),ie=u(v,I?J:ye.basename(J));let se=R?$.header.fileAttr:void 0;o.writeFileTo(ie,ne,A,se)}),!0}var M=y.getData(c.password);if(!M)throw Ee.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(L)&&!A)throw Ee.Errors.CANT_OVERRIDE();let Y=R?_.header.fileAttr:void 0;return o.writeFileTo(L,M,A,Y),!0},test:function(_){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var I=c.entries[v].getData(_);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(_,v,I,A){if(I=Dn(!1,I),A=uu(I,A),v=Dn(!1,v),!c)throw Ee.Errors.NO_ZIP();c.entries.forEach(function(R){var O=u(_,d(R.entryName));if(R.isDirectory){o.makeDir(O);return}var y=R.getData(A);if(!y)throw Ee.Errors.CANT_EXTRACT_FILE();let C=I?R.header.fileAttr:void 0;o.writeFileTo(O,y,v,C);try{o.fs.utimesSync(O,R.header.time,R.header.time)}catch{throw Ee.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(_,v,I,A){if(A=Im(v,I,A),I=Dn(!1,I),v=Dn(!1,v),!A)return new Promise((L,F)=>{this.extractAllToAsync(_,v,I,function(M){M?F(M):L(this)})});if(!c){A(Ee.Errors.NO_ZIP());return}_=ye.resolve(_);let R=L=>u(_,ye.normalize(d(L.entryName))),O=(L,F)=>new Error(L+': "'+F+'"'),y=[],C=[];c.entries.forEach(L=>{L.isDirectory?y.push(L):C.push(L)});for(let L of y){let F=R(L),M=I?L.header.fileAttr:void 0;try{o.makeDir(F),M&&o.fs.chmodSync(F,M),o.fs.utimesSync(F,L.header.time,L.header.time)}catch{A(O("Unable to create folder",F))}}C.reverse().reduce(function(L,F){return function(M){if(M)L(M);else{let Y=ye.normalize(d(F.entryName)),$=u(_,Y);F.getDataAsync(function(ne,J){if(J)L(J);else if(!ne)L(Ee.Errors.CANT_EXTRACT_FILE());else{let ie=I?F.header.fileAttr:void 0;o.writeFileToAsync($,ne,v,ie,function(se){se||L(O("Unable to write file",$)),o.fs.utimes($,F.header.time,F.header.time,function(D){D?L(O("Unable to set times",$)):L()})})}})}}},A)()},writeZip:function(_,v){if(arguments.length===1&&typeof _=="function"&&(v=_,_=""),!_&&i.filename&&(_=i.filename),!!_){var I=c.compressToBuffer();if(I){var A=o.writeFileTo(_,I,!0);typeof v=="function"&&v(A?null:new Error("failed"),"")}}},writeZipPromise:function(_,v){let{overwrite:I,perm:A}=Object.assign({overwrite:!0},v);return new Promise((R,O)=>{!_&&i.filename&&(_=i.filename),_||O("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let C=L=>L?R(L):O("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(_,y,I,A,C)},O)})},toBufferPromise:function(){return new Promise((_,v)=>{c.toAsyncBuffer(_,v)})},toBuffer:function(_,v,I,A){return typeof _=="function"?(c.toAsyncBuffer(_,v,I,A),null):c.compressToBuffer()}}}});import{execFile as P_,spawn as O_,spawnSync as IA}from"node:child_process";import{promisify as L_}from"node:util";function M_(t){if(process.platform!=="win32")return!1;if(Of.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(Of,"").toLowerCase();return N_.has(r)}function Lf(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return M_(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function rt(t,e=[],r={}){return O_(t,e,Lf(t,r))}function Nf(t,e=[],r={}){return B_(t,e,Lf(t,r))}var N_,Of,B_,Kt=et(()=>{"use strict";N_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Of=/\.(cmd|bat|ps1)$/i;B_=L_(P_)});var Vt=oe((fC,yx)=>{"use strict";var mx=["nodebuffer","arraybuffer","fragments"],_x=typeof Blob<"u";_x&&mx.push("blob");yx.exports={BINARY_TYPES:mx,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:_x,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var Ki=oe((xC,ko)=>{"use strict";var{EMPTY_BUFFER:gb}=Vt(),fd=Buffer[Symbol.species];function mb(t,e){if(t.length===0)return gb;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 fd(r.buffer,r.byteOffset,i):r}function Ex(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function bx(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function wb(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function xd(t){if(xd.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new fd(t):ArrayBuffer.isView(t)?e=new fd(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),xd.readOnly=!1),e}ko.exports={concat:mb,mask:Ex,toArrayBuffer:wb,toBuffer:xd,unmask:bx};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=le("bufferutil");ko.exports.mask=function(e,r,i,o,c){c<48?Ex(e,r,i,o,c):t.mask(e,r,i,o,c)},ko.exports.unmask=function(e,r){e.length<32?bx(e,r):t.unmask(e,r)}}catch{}});var Ix=oe((hC,Sx)=>{"use strict";var vx=Symbol("kDone"),hd=Symbol("kRun"),pd=class{constructor(e){this[vx]=()=>{this.pending--,this[hd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[hd]()}[hd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[vx])}}};Sx.exports=pd});var Fr=oe((pC,Rx)=>{"use strict";var $i=le("zlib"),Ax=Ki(),_b=Ix(),{kStatusCode:kx}=Vt(),yb=Buffer[Symbol.species],Eb=Buffer.from([0,0,255,255]),Ro=Symbol("permessage-deflate"),Yt=Symbol("total-length"),Mr=Symbol("callback"),An=Symbol("buffers"),Br=Symbol("error"),To,gd=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,!To){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;To=new _b(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[Mr];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){To.add(o=>{this._decompress(e,r,(c,d)=>{o(),i(c,d)})})}compress(e,r,i){To.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"?$i.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=$i.createInflateRaw({...this._options.zlibInflateOptions,windowBits:d}),this._inflate[Ro]=this,this._inflate[Yt]=0,this._inflate[An]=[],this._inflate.on("error",vb),this._inflate.on("data",Tx)}this._inflate[Mr]=i,this._inflate.write(e),r&&this._inflate.write(Eb),this._inflate.flush(()=>{let c=this._inflate[Br];if(c){this._inflate.close(),this._inflate=null,i(c);return}let d=Ax.concat(this._inflate[An],this._inflate[Yt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Yt]=0,this._inflate[An]=[],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"?$i.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=$i.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:d}),this._deflate[Yt]=0,this._deflate[An]=[],this._deflate.on("data",bb)}this._deflate[Mr]=i,this._deflate.write(e),this._deflate.flush($i.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=Ax.concat(this._deflate[An],this._deflate[Yt]);r&&(c=new yb(c.buffer,c.byteOffset,c.length-4)),this._deflate[Mr]=null,this._deflate[Yt]=0,this._deflate[An]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};Rx.exports=gd;function bb(t){this[An].push(t),this[Yt]+=t.length}function Tx(t){if(this[Yt]+=t.length,this[Ro]._maxPayload<1||this[Yt]<=this[Ro]._maxPayload){this[An].push(t);return}this[Br]=new RangeError("Max payload size exceeded"),this[Br].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Br][kx]=1009,this.removeListener("data",Tx),this.reset()}function vb(t){if(this[Ro]._inflate=null,this[Br]){this[Mr](this[Br]);return}t[kx]=1007,this[Mr](t)}});var zr=oe((gC,Co)=>{"use strict";var{isUtf8:Cx}=le("buffer"),{hasBlob:Sb}=Vt(),Ib=[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 Ab(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function md(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 kb(t){return Sb&&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:kb,isValidStatusCode:Ab,isValidUTF8:md,tokenChars:Ib};if(Cx)Co.exports.isValidUTF8=function(t){return t.length<24?md(t):Cx(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=le("utf-8-validate");Co.exports.isValidUTF8=function(e){return e.length<32?md(e):t(e)}}catch{}});var bd=oe((mC,Bx)=>{"use strict";var{Writable:Tb}=le("stream"),Dx=Fr(),{BINARY_TYPES:Rb,EMPTY_BUFFER:Px,kStatusCode:Cb,kWebSocket:Db}=Vt(),{concat:wd,toArrayBuffer:Pb,unmask:Ob}=Ki(),{isValidStatusCode:Lb,isValidUTF8:Ox}=zr(),Do=Buffer[Symbol.species],ft=0,Lx=1,Nx=2,Mx=3,_d=4,yd=5,Po=6,Ed=class extends Tb{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||Rb[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=e.maxBufferedChunks|0,this._maxFragments=e.maxFragments|0,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[Db]=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=ft}_write(e,r,i){if(this._opcode===8&&this._state==ft)return i();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){i(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new 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 ft:this.getInfo(e);break;case Lx:this.getPayloadLength16(e);break;case Nx:this.getPayloadLength64(e);break;case Mx:this.getMask();break;case _d:this.getData(e);break;case yd:case Po: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[Dx.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=Lx:this._payloadLength===127?this._state=Nx: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=Mx:this._state=_d}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=_d}getData(e){let r=Px;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}r=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&Ob(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=yd,this.decompress(r,e);return}if(r.length){if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let i=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(i);return}this._messageLength=this._totalPayloadLength,this._fragments.push(r)}this.dataMessage(e)}decompress(e,r){this._extensions[Dx.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let d=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(d);return}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let d=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");r(d);return}this._fragments.push(c)}this.dataMessage(r),this._state===ft&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=ft;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=wd(i,r):this._binaryType==="arraybuffer"?o=Pb(wd(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=ft):(this._state=Po,setImmediate(()=>{this.emit("message",o,!0),this._state=ft,this.startLoop(e)}))}else{let o=wd(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===yd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=ft):(this._state=Po,setImmediate(()=>{this.emit("message",o,!1),this._state=ft,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,Px),this.end();else{let i=e.readUInt16BE(0);if(!Lb(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=ft;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=ft):(this._state=Po,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=ft,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[Cb]=o,d}};Bx.exports=Ed});var Id=oe((_C,Ux)=>{"use strict";var{Duplex:wC}=le("stream"),{randomFillSync:Nb}=le("crypto"),{types:{isUint8Array:Mb}}=le("util"),Fx=Fr(),{EMPTY_BUFFER:Bb,kWebSocket:Fb,NOOP:zb}=Vt(),{isBlob:Ur,isValidStatusCode:Ub}=zr(),{mask:zx,toBuffer:$n}=Ki(),xt=Symbol("kByteLength"),Gb=Buffer.alloc(4),Oo=8*1024,Vn,Gr=Oo,vt=0,Hb=1,qb=2,vd=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=zb,this[Fb]=void 0}static frame(e,r){let i,o=!1,c=2,d=!1;r.mask&&(i=r.maskBuffer||Gb,r.generateMask?r.generateMask(i):(Gr===Oo&&(Vn===void 0&&(Vn=Buffer.alloc(Oo)),Nb(Vn,0,Oo),Gr=0),i[0]=Vn[Gr++],i[1]=Vn[Gr++],i[2]=Vn[Gr++],i[3]=Vn[Gr++]),d=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||d)&&r[xt]!==void 0?u=r[xt]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!d);let f=u;u>=65536?(c+=8,f=127):u>125&&(c+=2,f=126);let h=Buffer.allocUnsafe(o?u+c:c);return h[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(h[0]|=64),h[1]=f,f===126?h.writeUInt16BE(u,2):f===127&&(h[2]=h[3]=0,h.writeUIntBE(u,4,6)),r.mask?(h[1]|=128,h[c-4]=i[0],h[c-3]=i[1],h[c-2]=i[2],h[c-1]=i[3],d?[h,e]:o?(zx(e,i,h,c,u),[h]):(zx(e,i,e,0,u),[h,e])):[h,e]}close(e,r,i,o){let c;if(e===void 0)c=Bb;else{if(typeof e!="number"||!Ub(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(r);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");if(c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof r=="string")c.write(r,2);else if(Mb(r))c.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let d={[xt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==vt?this.enqueue([this.dispatch,c,!1,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):Ur(e)?(o=e.size,c=!1):(e=$n(e),o=e.length,c=$n.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[xt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Ur(e)?this._state!==vt?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==vt?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):Ur(e)?(o=e.size,c=!1):(e=$n(e),o=e.length,c=$n.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[xt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Ur(e)?this._state!==vt?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==vt?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}send(e,r,i){let o=this._extensions[Fx.extensionName],c=r.binary?2:1,d=r.compress,u,f;typeof e=="string"?(u=Buffer.byteLength(e),f=!1):Ur(e)?(u=e.size,f=!1):(e=$n(e),u=e.length,f=$n.readOnly),this._firstFragment?(this._firstFragment=!1,d&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(d=u>=o._threshold),this._compress=d):(d=!1,c=0),r.fin&&(this._firstFragment=!0);let h={[xt]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:f,rsv1:d};Ur(e)?this._state!==vt?this.enqueue([this.getBlobData,e,this._compress,h,i]):this.getBlobData(e,this._compress,h,i):this._state!==vt?this.enqueue([this.dispatch,e,this._compress,h,i]):this.dispatch(e,this._compress,h,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[xt],this._state=qb,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(Sd,this,u,o);return}this._bufferedBytes-=i[xt];let d=$n(c);r?this.dispatch(d,r,i,o):(this._state=vt,this.sendFrame(t.frame(d,i),o),this.dequeue())}).catch(c=>{process.nextTick(jb,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Fx.extensionName];this._bufferedBytes+=i[xt],this._state=Hb,c.compress(e,i.fin,(d,u)=>{if(this._socket.destroyed){let f=new Error("The socket was closed while data was being compressed");Sd(this,f,o);return}this._bufferedBytes-=i[xt],this._state=vt,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===vt&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][xt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][xt],this._queue.push(e)}sendFrame(e,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)}};Ux.exports=vd;function Sd(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 jb(t,e,r){Sd(t,e,r),t.onerror(e)}});var Yx=oe((yC,Vx)=>{"use strict";var{kForOnEventAttribute:Vi,kListener:Ad}=Vt(),Gx=Symbol("kCode"),Hx=Symbol("kData"),qx=Symbol("kError"),jx=Symbol("kMessage"),Wx=Symbol("kReason"),Hr=Symbol("kTarget"),Kx=Symbol("kType"),$x=Symbol("kWasClean"),Zt=class{constructor(e){this[Hr]=null,this[Kx]=e}get target(){return this[Hr]}get type(){return this[Kx]}};Object.defineProperty(Zt.prototype,"target",{enumerable:!0});Object.defineProperty(Zt.prototype,"type",{enumerable:!0});var Yn=class extends Zt{constructor(e,r={}){super(e),this[Gx]=r.code===void 0?0:r.code,this[Wx]=r.reason===void 0?"":r.reason,this[$x]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Gx]}get reason(){return this[Wx]}get wasClean(){return this[$x]}};Object.defineProperty(Yn.prototype,"code",{enumerable:!0});Object.defineProperty(Yn.prototype,"reason",{enumerable:!0});Object.defineProperty(Yn.prototype,"wasClean",{enumerable:!0});var qr=class extends Zt{constructor(e,r={}){super(e),this[qx]=r.error===void 0?null:r.error,this[jx]=r.message===void 0?"":r.message}get error(){return this[qx]}get message(){return this[jx]}};Object.defineProperty(qr.prototype,"error",{enumerable:!0});Object.defineProperty(qr.prototype,"message",{enumerable:!0});var Yi=class extends Zt{constructor(e,r={}){super(e),this[Hx]=r.data===void 0?null:r.data}get data(){return this[Hx]}};Object.defineProperty(Yi.prototype,"data",{enumerable:!0});var Wb={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Vi]&&o[Ad]===e&&!o[Vi])return;let i;if(t==="message")i=function(c,d){let u=new Yi("message",{data:d?c:c.toString()});u[Hr]=this,Lo(e,this,u)};else if(t==="close")i=function(c,d){let u=new Yn("close",{code:c,reason:d.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Hr]=this,Lo(e,this,u)};else if(t==="error")i=function(c){let d=new qr("error",{error:c,message:c.message});d[Hr]=this,Lo(e,this,d)};else if(t==="open")i=function(){let c=new Zt("open");c[Hr]=this,Lo(e,this,c)};else return;i[Vi]=!!r[Vi],i[Ad]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[Ad]===e&&!r[Vi]){this.removeListener(t,r);break}}};Vx.exports={CloseEvent:Yn,ErrorEvent:qr,Event:Zt,EventTarget:Wb,MessageEvent:Yi};function Lo(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var No=oe((EC,Zx)=>{"use strict";var{tokenChars:Zi}=zr();function Nt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function Kb(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,d,u,f=-1,h=-1,g=-1,w=0;for(;w<t.length;w++)if(h=t.charCodeAt(w),d===void 0)if(g===-1&&Zi[h]===1)f===-1&&(f=w);else if(w!==0&&(h===32||h===9))g===-1&&f!==-1&&(g=w);else if(h===59||h===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w);let _=t.slice(f,g);h===44?(Nt(e,_,r),r=Object.create(null)):d=_,f=g=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);else if(u===void 0)if(g===-1&&Zi[h]===1)f===-1&&(f=w);else if(h===32||h===9)g===-1&&f!==-1&&(g=w);else if(h===59||h===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w),Nt(r,t.slice(f,g),!0),h===44&&(Nt(e,d,r),r=Object.create(null),d=void 0),f=g=-1}else if(h===61&&f!==-1&&g===-1)u=t.slice(f,w),f=g=-1;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(o){if(Zi[h]!==1)throw new SyntaxError(`Unexpected character at index ${w}`);f===-1?f=w:i||(i=!0),o=!1}else if(c)if(Zi[h]===1)f===-1&&(f=w);else if(h===34&&f!==-1)c=!1,g=w;else if(h===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(h===34&&t.charCodeAt(w-1)===61)c=!0;else if(g===-1&&Zi[h]===1)f===-1&&(f=w);else if(f!==-1&&(h===32||h===9))g===-1&&(g=w);else if(h===59||h===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w);let _=t.slice(f,g);i&&(_=_.replace(/\\/g,""),i=!1),Nt(r,u,_),h===44&&(Nt(e,d,r),r=Object.create(null),d=void 0),u=void 0,f=g=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);if(f===-1||c||h===32||h===9)throw new SyntaxError("Unexpected end of input");g===-1&&(g=w);let S=t.slice(f,g);return d===void 0?Nt(e,S,r):(u===void 0?Nt(r,S,!0):i?Nt(r,u,S.replace(/\\/g,"")):Nt(r,u,S),Nt(e,d,r)),e}function $b(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(", ")}Zx.exports={format:$b,parse:Kb}});var zo=oe((SC,ch)=>{"use strict";var Vb=le("events"),Yb=le("https"),Zb=le("http"),Qx=le("net"),Jb=le("tls"),{randomBytes:Xb,createHash:Qb}=le("crypto"),{Duplex:bC,Readable:vC}=le("stream"),{URL:kd}=le("url"),kn=Fr(),ev=bd(),tv=Id(),{isBlob:nv}=zr(),{BINARY_TYPES:Jx,CLOSE_TIMEOUT:rv,EMPTY_BUFFER:Mo,GUID:iv,kForOnEventAttribute:Td,kListener:sv,kStatusCode:ov,kWebSocket:qe,NOOP:eh}=Vt(),{EventTarget:{addEventListener:av,removeEventListener:cv}}=Yx(),{format:dv,parse:lv}=No(),{toBuffer:uv}=Ki(),th=Symbol("kAborted"),Rd=[8,13],Jt=["CONNECTING","OPEN","CLOSING","CLOSED"],fv=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,me=class t extends Vb{constructor(e,r,i){super(),this._binaryType=Jx[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Mo,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]),nh(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Jx.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 ev({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxBufferedChunks:i.maxBufferedChunks,maxFragments:i.maxFragments,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new tv(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[qe]=this,c[qe]=this,e[qe]=this,o.on("conclude",pv),o.on("drain",gv),o.on("error",mv),o.on("message",wv),o.on("ping",_v),o.on("pong",yv),c.onerror=Ev,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",sh),e.on("data",Fo),e.on("end",oh),e.on("error",ah),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[kn.extensionName]&&this._extensions[kn.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){at(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),ih(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){Cd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Mo,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){Cd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Mo,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){Cd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[kn.extensionName]||(o.compress=!1),this._sender.send(e||Mo,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){at(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(me,"CONNECTING",{enumerable:!0,value:Jt.indexOf("CONNECTING")});Object.defineProperty(me.prototype,"CONNECTING",{enumerable:!0,value:Jt.indexOf("CONNECTING")});Object.defineProperty(me,"OPEN",{enumerable:!0,value:Jt.indexOf("OPEN")});Object.defineProperty(me.prototype,"OPEN",{enumerable:!0,value:Jt.indexOf("OPEN")});Object.defineProperty(me,"CLOSING",{enumerable:!0,value:Jt.indexOf("CLOSING")});Object.defineProperty(me.prototype,"CLOSING",{enumerable:!0,value:Jt.indexOf("CLOSING")});Object.defineProperty(me,"CLOSED",{enumerable:!0,value:Jt.indexOf("CLOSED")});Object.defineProperty(me.prototype,"CLOSED",{enumerable:!0,value:Jt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(me.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(me.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Td])return e[sv];return null},set(e){for(let r of this.listeners(t))if(r[Td]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[Td]:!0})}})});me.prototype.addEventListener=av;me.prototype.removeEventListener=cv;ch.exports=me;function nh(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:rv,protocolVersion:Rd[1],maxBufferedChunks:1048576,maxFragments:131072,maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=o.autoPong,t._closeTimeout=o.closeTimeout,!Rd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Rd.join(", ")})`);let c;if(e instanceof kd)c=e;else try{c=new kd(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let d=c.protocol==="wss:",u=c.protocol==="ws+unix:",f;if(c.protocol!=="ws:"&&!d&&!u?f=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?f="The URL's pathname is empty":c.hash&&(f="The URL contains a fragment identifier"),f){let I=new SyntaxError(f);if(t._redirects===0)throw I;Bo(t,I);return}let h=d?443:80,g=Xb(16).toString("base64"),w=d?Yb.request:Zb.request,S=new Set,_;if(o.createConnection=o.createConnection||(d?hv:xv),o.defaultPort=o.defaultPort||h,o.port=c.port||h,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":g,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(_=new kn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=dv({[kn.extensionName]:_.offer()})),r.length){for(let I of r){if(typeof I!="string"||!fv.test(I)||S.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");S.add(I)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),u){let I=o.path.split(":");o.socketPath=I[0],o.path=I[1]}let v;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=d,t._originalHostOrSocketPath=u?o.socketPath:c.host;let I=i&&i.headers;if(i={...i,headers:{}},I)for(let[A,R]of Object.entries(I))i.headers[A.toLowerCase()]=R}else if(t.listenerCount("redirect")===0){let I=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!I||t._originalSecure&&!d)&&(delete o.headers.authorization,delete o.headers.cookie,I||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),v=t._req=w(o),t._redirects&&t.emit("redirect",t.url,v)}else v=t._req=w(o);o.timeout&&v.on("timeout",()=>{at(t,v,"Opening handshake has timed out")}),v.on("error",I=>{v===null||v[th]||(v=t._req=null,Bo(t,I))}),v.on("response",I=>{let A=I.headers.location,R=I.statusCode;if(A&&o.followRedirects&&R>=300&&R<400){if(++t._redirects>o.maxRedirects){at(t,v,"Maximum redirects exceeded");return}v.abort();let O;try{O=new kd(A,e)}catch{let C=new SyntaxError(`Invalid URL: ${A}`);Bo(t,C);return}nh(t,O,r,i)}else t.emit("unexpected-response",v,I)||at(t,v,`Unexpected server response: ${I.statusCode}`)}),v.on("upgrade",(I,A,R)=>{if(t.emit("upgrade",I),t.readyState!==me.CONNECTING)return;v=t._req=null;let O=I.headers.upgrade;if(O===void 0||O.toLowerCase()!=="websocket"){at(t,A,"Invalid Upgrade header");return}let y=Qb("sha1").update(g+iv).digest("base64");if(I.headers["sec-websocket-accept"]!==y){at(t,A,"Invalid Sec-WebSocket-Accept header");return}let C=I.headers["sec-websocket-protocol"],L;if(C!==void 0?S.size?S.has(C)||(L="Server sent an invalid subprotocol"):L="Server sent a subprotocol but none was requested":S.size&&(L="Server sent no subprotocol"),L){at(t,A,L);return}C&&(t._protocol=C);let F=I.headers["sec-websocket-extensions"];if(F!==void 0){if(!_){at(t,A,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let M;try{M=lv(F)}catch{at(t,A,"Invalid Sec-WebSocket-Extensions header");return}let Y=Object.keys(M);if(Y.length!==1||Y[0]!==kn.extensionName){at(t,A,"Server indicated an extension that was not requested");return}try{_.accept(M[kn.extensionName])}catch{at(t,A,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[kn.extensionName]=_}t.setSocket(A,R,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(v,t):v.end()}function Bo(t,e){t._readyState=me.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function xv(t){return t.path=t.socketPath,Qx.connect(t)}function hv(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Qx.isIP(t.host)?"":t.host),Jb.connect(t)}function at(t,e,r){t._readyState=me.CLOSING;let i=new Error(r);Error.captureStackTrace(i,at),e.setHeader?(e[th]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Bo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Cd(t,e,r){if(e){let i=nv(e)?e.size:uv(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Jt[t.readyState]})`);process.nextTick(r,i)}}function pv(t,e){let r=this[qe];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[qe]!==void 0&&(r._socket.removeListener("data",Fo),process.nextTick(rh,r._socket),t===1005?r.close():r.close(t,e))}function gv(){let t=this[qe];t.isPaused||t._socket.resume()}function mv(t){let e=this[qe];e._socket[qe]!==void 0&&(e._socket.removeListener("data",Fo),process.nextTick(rh,e._socket),e.close(t[ov])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Xx(){this[qe].emitClose()}function wv(t,e){this[qe].emit("message",t,e)}function _v(t){let e=this[qe];e._autoPong&&e.pong(t,!this._isServer,eh),e.emit("ping",t)}function yv(t){this[qe].emit("pong",t)}function rh(t){t.resume()}function Ev(t){let e=this[qe];e.readyState!==me.CLOSED&&(e.readyState===me.OPEN&&(e._readyState=me.CLOSING,ih(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function ih(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function sh(){let t=this[qe];if(this.removeListener("close",sh),this.removeListener("data",Fo),this.removeListener("end",oh),t._readyState=me.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[qe]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Xx),t._receiver.on("finish",Xx))}function Fo(t){this[qe]._receiver.write(t)||this.pause()}function oh(){let t=this[qe];t._readyState=me.CLOSING,t._receiver.end(),this.end()}function ah(){let t=this[qe];this.removeListener("error",ah),this.on("error",eh),t&&(t._readyState=me.CLOSING,this.destroy())}});var fh=oe((AC,uh)=>{"use strict";var IC=zo(),{Duplex:bv}=le("stream");function dh(t){t.emit("close")}function vv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function lh(t){this.removeListener("error",lh),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function Sv(t,e){let r=!0,i=new bv({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,d){let u=!d&&i._readableState.objectMode?c.toString():c;i.push(u)||t.pause()}),t.once("error",function(c){i.destroyed||(r=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick(dh,i);return}let d=!1;t.once("error",function(f){d=!0,c(f)}),t.once("close",function(){d||c(o),process.nextTick(dh,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",vv),i.on("error",lh),i}uh.exports=Sv});var Dd=oe((kC,xh)=>{"use strict";var{tokenChars:Iv}=zr();function Av(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&&Iv[d]===1)r===-1&&(r=o);else if(o!==0&&(d===32||d===9))i===-1&&r!==-1&&(i=o);else if(d===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let u=t.slice(r,i);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);e.add(u),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(r,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}xh.exports={parse:Av}});var yh=oe((RC,_h)=>{"use strict";var kv=le("events"),Uo=le("http"),{Duplex:TC}=le("stream"),{createHash:Tv}=le("crypto"),hh=No(),Zn=Fr(),Rv=Dd(),Cv=zo(),{CLOSE_TIMEOUT:Dv,GUID:Pv,kWebSocket:Ov}=Vt(),Lv=/^[+/0-9A-Za-z]{22}==$/,ph=0,gh=1,wh=2,Pd=class extends kv{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:1024*1024,maxFragments:128*1024,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:Dv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Cv,...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=Uo.createServer((i,o)=>{let c=Uo.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=Nv(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=ph}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===wh){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Ji,this);return}if(e&&this.once("close",e),this._state!==gh)if(this._state=gh,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(Ji,this):process.nextTick(Ji,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{Ji(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",mh);let c=e.headers["sec-websocket-key"],d=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Jn(this,e,r,405,"Invalid HTTP method");return}if(d===void 0||d.toLowerCase()!=="websocket"){Jn(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!Lv.test(c)){Jn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){Jn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Xi(r,400);return}let f=e.headers["sec-websocket-protocol"],h=new Set;if(f!==void 0)try{h=Rv.parse(f)}catch{Jn(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let g=e.headers["sec-websocket-extensions"],w={};if(this.options.perMessageDeflate&&g!==void 0){let S=new Zn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let _=hh.parse(g);_[Zn.extensionName]&&(S.accept(_[Zn.extensionName]),w[Zn.extensionName]=S)}catch{Jn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let S={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(S,(_,v,I,A)=>{if(!_)return Xi(r,v||401,I,A);this.completeUpgrade(w,c,h,e,r,i,o)});return}if(!this.options.verifyClient(S))return Xi(r,401)}this.completeUpgrade(w,c,h,e,r,i,o)}completeUpgrade(e,r,i,o,c,d,u){if(!c.readable||!c.writable)return c.destroy();if(c[Ov])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>ph)return Xi(c,503);let h=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Tv("sha1").update(r+Pv).digest("base64")}`],g=new this.options.WebSocket(null,void 0,this.options);if(i.size){let w=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;w&&(h.push(`Sec-WebSocket-Protocol: ${w}`),g._protocol=w)}if(e[Zn.extensionName]){let w=e[Zn.extensionName].params,S=hh.format({[Zn.extensionName]:[w]});h.push(`Sec-WebSocket-Extensions: ${S}`),g._extensions=e}this.emit("headers",h,o),c.write(h.concat(`\r
15
15
  `).join(`\r
16
- `)),c.removeListener("error",ch),m.setSocket(c,l,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxBufferedChunks:this.options.maxBufferedChunks,maxFragments:this.options.maxFragments,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(m),m.on("close",()=>{this.clients.delete(m),this._shouldEmitClose&&!this.clients.size&&process.nextTick(ts,this)})),u(m,o)}};lh.exports=Dd;function Av(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 ts(t){t._state=dh,t.emit("close")}function ch(){this.destroy()}function ns(t,e,r,i){r=r||Ho.STATUS_CODES[e],i={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...i},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${Ho.STATUS_CODES[e]}\r
16
+ `)),c.removeListener("error",mh),g.setSocket(c,d,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxBufferedChunks:this.options.maxBufferedChunks,maxFragments:this.options.maxFragments,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(g),g.on("close",()=>{this.clients.delete(g),this._shouldEmitClose&&!this.clients.size&&process.nextTick(Ji,this)})),u(g,o)}};_h.exports=Pd;function Nv(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 Ji(t){t._state=wh,t.emit("close")}function mh(){this.destroy()}function Xi(t,e,r,i){r=r||Uo.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} ${Uo.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 er(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let l=new Error(o);Error.captureStackTrace(l,er),t.emit("wsClientError",l,r,e)}else ns(r,i,o,c)}});var Sh=ce(Be=>{"use strict";var M=G;function $o(){let t=["C2v0y3vYC28","uuH2Cw4","ywjVCNq","DuP2zhO","yMXVy2TLza","AKHJqNC","vLHXy2u","v2zmvNm","ENPIDhi","qvLkA3i","z3vKB2i","zgjqru4","wfvKvKq","zxnMs2u","DMLlu2y","y3jLyxrLtwu","Bhm6ia","mxW2Fdn8mte","ENPfvwu","wvjjAuW","twTKBKW","D2PmvgS","A2v5","x2HHBMrSzvi","qLDZshy","s2HUzgy","mNWXFdb8m3W","qNjPzgDL","zwrPyxrLBhK","BhrPCgXLihq","AxPnDMi","y3jLyxrLrwW","CeLMqxO","BMvJDa","DgHAtuS","wNL4CwO","EvzADue","CKvntwG","vfHcyvK","C0zmug8","rhfNzxm","z2v0q3vYCMu","EvLpyuO","rKHcCMi","CNnVCL9Uyw0","AKjsqMW","ENb2tue","DfLkzuq","Bg9N","ChjVDg9JB2W","BwvZC2fNzq","ywrKrxzLBNq","qwrKvwq","x2LZqNjVD3m","sfLQuhq","C3rYAw5N","zKrevLC","B09qzey","B3nLrxzLBNq","B25LCNjVCG","B25TzxnZywC","uMjtv0G","veD5uNG","ywnRx2nVzgu","lcbTyxGGCMu","zcbLCNjVCI4","o2nOyxjZzxq","zw50tgLZDgu","zvjwyxi","uvPkt3q","EMvyEeW","x2rItMfTzq","yNL0zxm","Dg9tDhjPBMC","yurhuu0","BKHXsgq","q09oveLovuu","DM9QBfK","x21PBMLoyxy","zgvSzxrL","v29bsve","y2fSBa","tgLZDgvUzxi","whn0t1a","sgXXwgy","t1bftG","B2fK","sevntLC","wNbbvMC","v2THBvy","C2nYAxb0","v2jgrxi","ihjLy29UBMu","yNvMzMvYzwq","tKrutLC","yxv0BW","rLjArxG","t1zouue","CezpqNO","AwzTwMi","DgHHBIbSB2m","r1DUD3O","B250vNa","Efrurw52","vwvYEvy","ChbL","rvjst1i","BgLZDgvUtMu","BM9Uzv9UB24","Aw5KzxHpzG","B1vfD0u","t21oB2m","wgLmzKy","zgvS","zNHrqwu","tM5nzuq","z2vjBMzVu3K","ChjVDg90Exa","mJyXsg11sLnP","B2v4svy","BMDLza","wvDksMO","CMfTugfYyw0","Auf4Axa","EhfJqMe","B25VCgvU","AxjLza","BeXPDw8","D3jPDgvvAw4","zw50","veP1C2m","s2ryyuW","z3nsy0i","zgj4tg0","ufDcC0W","qK1Nvxa","zMvY","uNvdDeu","B2fAEuG","CLPZsNm","CxvnDg4","zMLUza","B25ozxr3B3i","qML2sfO","CgLUz09Uy2u","D2fyq2O","ENjnq0m","CKXcz1a","Ec1TC2CTy3u","z0fLvLm","rwDyy1a","BNfzsvG","A3npv24","tuX3uKm","CM92AwrLige","qvflzgO","CMvQzwn0","vgfN","B3bLBG","vgTKy0O","x2nSzwfYvgK","v2n1Axy","whrnsxa","q29Kzq","zNjVBuHHC2G","AK5oB0S","x2LZv29YA2u","AenSB3nLrxy","ueTOzxa","vLvLsg8","yKvfAKq","zM9Yy2u","CMzIz0W","qunvywC","quHit24","Cg9PBNrbBMq","zNjVBuj5Dgu","sK9IzLe","zNvkyxy","z2v0qwXSs2u","q1rLCfm","C2vYDMLJzq","BML0AwfSAxO","zMHzvhu","DhLWzq","y2XLyxi","ELHiCw4","yNL0zuXLBMC","A1n0yxr1C0m","s3rAy04","D2jRAMq","CMvJzxzPzwq","z3zTzwi","u3HOD2e","zw5HyMXLqxu","ihrVihjLDhi","DwPMvw8","B3bLCNr5","sNfguLi","yMHVtwW","EfH4z1e","sMPAvuG","ywLKAeK","z2v0u3rVCMe","y0v2qKi","rhHIyLG","zMzmAw5L","rwnJz2u","txrwCee","Dgf0tLG","tg9JAW","s0jUqKi","tuTyBu4","AwzAwNe","q05Rzwu","CMDmCuS","Aw50zwDLCIa","DxnLCKLW","DNniqLa","B3bLBIa","x3jLy29UBMu","A2Dlq1e","x2n1CNnVCK0","yw1Lu3bHy2u","AunfCvu","DgfYz2v0","DfnAwxG","Dw50","AxnrB1nby2S","q0fhs0q","x3nVy2TLDa","Dw5KzwzPBMu","z09lvhK","Ec1TC2CTCw8","EwvHug4","AMvJDfn0B3i","z2v0q3vYC28","Bwf4uMv0CMK","B2jQzwn0u3q","weXut1a","AgfUz2u","Dg9cExrLC0W","EePXC3C","zw50zwqGDhK","svPHCwC","rMTxveK","rLv6DvG","B2zM","A2v0ignVBNm","B3vUDa","sMn4vMW","Dhj1y3rVCIa","zgrjrcWGzgu","CuXdvNG","ChrVCG","B2LUDfjLywm","zgjsse4","C2DPza","AM9PBG","Aw5Lza","rLHYC24","AuzAq1q","zxrxB3jRq2G","svjJDwS","zufOuwq","zw5RyxG","AKXwr0C","uMLVCMO","ywXSq3vYC28","venlwKy","C3vIyxjYyxK","r2HzENa","vKLPC0W","uK5hswW","Ae9Wzw5fDMu","zvvYBa","C0fpzMG","yMHmExK","CgfYC2u","zNjVBunOyxi","Curcrvy","vvD3AgK","DhLsvfG","Ae1LC3nHz2u","y3vZDg9Tshq","CNPlsLq","DurQAgG","C2vUza","zuP2sgO","CLLmqwG","zKXtvxG","vfvvuKq","qMrpvuq","EhfNEw8","rNLhANi","AgfZ","CgT3ENO","vxzHBeG","rg5Vwwi","s0nxENa","sevTBw8","Bu9YELi","zfj2Auy","uKjctw8","Bg1Mwue","swrgt0S","BgL5tvm","BNvTyMvY","Bg9JyKm","DufOEum","ww50uhy","uMvwuKG","qwnbDeu","z29PBMCGyxC","zwvUu3e","zfLny0C","tMXdrfG","AhrMy0e","t3bLBKv2zw4","suvtx0vsuK8","x0vysvnu","tLHfrvi","swX0vNm","CMvWBgfJzq","AhjQBK0","BuDHr1O","wxL5tgG","ze1st0W","zgvMAw5Luhi","B25fCNjVCG","v3zcwhy","ywXSzwqGBxu","y2rQreC","CNnVCL92ywW","yxnZAwDU","C25HvwW","y1vkt1u","wvbHANC","mNWZFdb8nhW","AK5OtxG","sLjYAKe","vLjuEMO","zfrrz20","x29WDgLVBNm","BMnVzgLUzW","v3PIEeC","Cgfxsvq","BgLUzw5V","zxjFDhrS","x2zVCM1HDeu","wuX6AK8","C29YDa","txDwwfu","AKTuwKi","t2jKyLK","t0ngveS","rMrSvu0","qMLOBKS","u2z1y1a","y2XVC2veqG","Cw9Z","B3nLza","EM1oDfy","CgXLyxnLiha","x2rPC3bHDgm","v2LoEKy","qK9ND3m","Cg93","zNDZxZeUmc4","BxnN","yNL0zu9MzNm","yMfSrxzLBNq","zhHQAuK","sxbUAva","AwDmt1a","CIb0DhDjra","DgvmB2Djre4","rwnXug0","DKnzv0i","A1PbAhm","qw1VDw50","yvHjteK","uLbsEKC","zKrOuLG","rhvMrxu","vuvQC04","DfDmq3e","DMvY","AwXLtMfTzq","wKHvtuC","BhnfCuS","vvnVsei","CMvWBgfJzui","v1nzCgi","t1ntzKG","DgHLBG","y09Wzw4","D2LSBfjLy28","B3jpBMXPBMu","z3vNEhq","AMXzCwy","zwDzBLq","r0rPwMO","s0HrD08","CuLZBfC","CYbWyxjHBxm","Dxrjza","Dg9mB3DLCKm","Dhbtqxu","vxjkBhO","Dg9iyxnO","D0n6sxm","rMvqu04","y29UBMvJDca","BNz1u3K","sw5uyxO","tKDFrvjst1i","wM1gBvu","C3rVCcbPBw0","ihrPBwvZ","Bg9IywXty28","AevYCM9Yrxy","tM55Chm","yuHMDvG","BgrnBwq","Bwf4twvZC2e","vNPKBKe","tMzgz0S","CM9pwMG","wLHqtu4","zfDVCMTLCKC","B2zMBgLUzq","qMj4tgC","CMvHC29U","CfvkqKe","zvjhrKi","y3jLyxrLq2W","ywr2yw5Jzq","BgL0C0G","DMvYC2LVBG","FdD8nxW0Fde","zhfRtLC","BKXZDuu","q1rWBu4","vM9rDuW","q1frtgK","zsbHihn0CMK","uxHmuLC","y3ruAw1LB3u","mte2mtKZmMjxvwvKEq","A3DIsfy","zw5JB2rPBMC","Cu9xzfG","u29ptvy","Ef9MCM9UDgK","zKXjqxa","y3vYCMvUDeK","x2LUAxrhBg8","zKDMCxO","D1Dwvhq","yw5Nzq","DwHLyMy","Cg9gzNC","v1nTCxC","wuLdzuq","qNjsvge","q0LXvLe","vhnlCuq","x3bPBMDqB24","x3jLBw92zvC","Dev2zw50","wMj1r3G","yMLUyxj5vhK","CMvJB25Uzwm","t2viAgm","DhjPzxm","t1PWEMO","whPeAxe","yw5XDgu","x3bYzwzPEa","DxbKyxrLq3u","r2jvDM8","rMfyCwG","DMvUDa","twvZC2fNzuu","r3fstLa","ALzqwLO","u2HHCMvKv28","v3nUBg0","zuXHv0O","AxviAgy","CMvUDevUzha","Ce5yr0O","zxjFCw9Zx2e","ywnRx2LK","BfDAvvi","qKvPDu8","DKrYyMK","Ag1ZAum","D0f5CNa","rgvKAwnHDgu","x2rLC3rYB3K","CMvZzxruCMK","BMrWB2LUDfq","AwDHDg9Yt24","B2nRzxrtDwm","C0rzzhu","x2DLDeLUDgu","icSG","BezSDxnO","DcbVzIbYyw4","v3vOAgO","B3L0rg4","BgLUzq","ywfnDKC","Dfbtufa","B3bOuwG","s2r3shC","ywnOzwqSihC","y3bZsMy","yu9nBNq","veDWsKq","v1fOvM8","x2nVBM5Ly3q","zgvJB2rLzey","Ee5OthK","CMvHzhDYAxq","AejVthC","uKfPB3u","rMz5DeS","A3jRwfC","B25nzxnZywC","vgvbrfK","u1jcv1m","BKLwug0","y3vYC29Yx24","ANb1uMq","uhPKwLy","rgHhEMe","u2vXsuq","Dxf6Bhm","C0rJwuS","C2vYDMLJzs0","x3jLywr5q2W","reXku2K","CvzTrgm","tNPZB1q","uNPxALq","ignVzgu6ia","vw1jDxG","C2XPy2u","rKr3C0q","whvPC1e","x2LZtM9Kzq","A2XpsuC","x25HDMLNyxq","zMLgue0","ig1LC3nHz2u","BKv5q3C","x2DLBMvYyxq","s0XOvuG","rMDbAgW","CejxwKW","CLzHBhvLCW","x29UugfNzu4","AgzRtLK","CLvkyLy","x2HHBMrSzva","sffjtfu","q3jcC3e","Buzovfu","tg9Nsuq","q291BNq","zw5KCg9PBNq","B0LsrMm","zMLSDgvY","Bun2u1m","CNHVqM8","BwLZzq","sxv4BNa","Dw5ZAwDUzwq","Cuvotvi","tfznAg8","Ber3vxe","q2nPsLy","rvjOvwW","yLDcC20","nti5mefUAMXTqG","BMv3vMvYC2K","uxbereC","B0v2Eum","CML4Cva","mdaWmdaWmda","vgPmtwO","quTnDNC","shDXz08","BwLUzW","tNPkA1G","EhvNvKm","BMrLEa","zLvOuvC","vvfzzxK","yxKSig5LDhC","y291BNq","CgPyBeG","CxLLD2i","tLfuteC","mNWWFdr8mxW","z2vrDwv1zuW","r05ktLa","AwXK","yxGGCMv0CMK","q1PgwgW","yKfSENa","tfP3AhC","ywXSB2nvBNm","EvnhCMC","CuvvAK4","AxmGDw5Kzwy","BwvZC2fNzv8","zg9Uzq","yMfoweO","yxDWsgy","z0jTEwG","uuHxB3e","vKH3Bwe","zgvSzxrLrge","tMj5v0y","m3WYFdr8mhW","x3bYB3rVy28","y2XVC2uSihC","BMv4DcGPigm","D3nZoI8V","CMfUzg9T","twH5C2S","AuvIuwe","z1bKs3y","yw1LoIa","u0XAvuK","z3nAwLq","EMDxBLi","yxrLq291BNq","EvLos3u","zNjVBujPDhm","q0Xpu0ve","x2LZsw5PDa","rKzpr1u","C2v0q3vYC28","CMTsyLG","BgLTAxq","AeLjuLq","B1L1BMm","C3vJy2vZCW","vvndqLy","yMLUyxj5","wunxCMq","ihzHBgLKigq","DxrVuMvJB24","CMvHzfvjBNq","rLzut0C","AwHJDg4","yw5Hz2vY","Chv0","DeLK","C3bSAxq","B25tDg9Wsw0","x2LUDgvYDMe","ALjWz3G","vujVA2O","BvzVC0m","z2HkvLa","yw51Ce1LC3m","yvrewMO","zxrmAMS","rvvpz00","v3jrr24","rwfAAu4","DhDVCMTdAge","ve9XzLK","z2v0","qMreA0W","sNzzt2q","tuTArxm","q09Ys20","DMDstNu","Exzms2y","zMzLCG","x3bHDgHlzxK","BeLTBxu","x2LZtwLUAvC","zxjFAxnFywm","A2v5CW","Cg9PBNrdB24","C2HPzNq","vLL0Deu","uwfXs3u","wNHcv0K","r0Tzy0i","C0nVDw50zxi","zv9ZDwnJzxm","zxjFywnRx20","zeXkwu0","BwDPuue","C0XMDgO","q1DMq2i","B0XWr28","Du1kyuS","tgrMEuy","wvP6Bw4","BM5Ly3q","t2jQzwn0","u05Lyxu","yNvMzMvY","q2DsvwC","wvzwv2O","CgLUz19VBMm","rwLXswS","uu9gree","EgPksui","AvzAq3a","sgnODKS","z2Pwv2C","BxvUsKe","ChvZAa","u1ruq2m","AgvHzgvYCW","z2v0s2v5","igXHCMDLCIa","vMrqB1m","B053zgi","y2PNtLq","CMvZzxrfBMq","q2LSAhu","C2vUzf9Hy2S","BKXPBMu","vwTRENi","BgTsENy","yM9L","x3bPBMC","yMfSu2nVCgu","Bwu6ia","x29UtwvZC2e","AvjYCKy","t0vRCfC","rNjVBNrPzxi","qLfVrw8","vvrlrhm","tK9QBe4","sNLVtgC","CwnKBfm","Aw5N","BMCGzMfPBgu","B3jtEgS","Aw5KzxGGB3u","t25zsMe","y29Uy2f0","yxbWBgLJyxq","Dg9cExrLC0i","q3vtANG","vNjlCw0","zuHjwNi","ruvRChy","uwfoEvu","sfDqAui","q01RquS","DuvRu3C","yKjdEhy","BwfW","t2nstLi","x29Uq2XVC2u","reLQqNy","zNvUy3rPB24","yxKSihrYEsa","q3jMAw4","DvDts0C","zufJAW","CgfNzxnOB3C","yxbmz3O","tuTbExe","C3rVCMu","C29QB0K","CgvYC2LZDgu","C3nHz2vfDMu","vevLwuO","CNzHBfzHBhu","x2rLyNvN","ywDLu2HVDW","tLLhCLG","BwHjtxO","ALrezNu","wK9KsKK","tgvVrKG","ywrKq291BNq","BvLfCxG","y3jLyxrLt3a","mty0ndGXmeH1A3jSrW","C0XPC3rLBMu","tKfbBwm","uKLnqK4","twLZC2LUzYa","x2nSzwfYugK","B3bLBKrc","q3fevMy","u21JALm","yNrQvKS","reXotwS","CfvfCKm","ywnR","C0ryAKi","x3vYBa","x2fKzfDZtgK","D1fZDLi","BeHHBMrSzxi","y1r4y2e","BfrPBwvVDxq","mdaWma","C3rYAw5NAwy","EfvZzuvUDG","z3zYAgW","B3v0sw50zxi","x2LUAxrqCM8","qwn4Ehi","sM9gDuS","y29UC3rYDwm","DxrMofDYAxq","B0nyv1y","z2v0qwXS","D2DAuue","zMX1C2HfEha","CMzor3C","B3jLtMfTzxm","z0v4uxO","y1rxu2y","ysbTDxn0igi","C2H6r1q","qK5irKu","vKfHqwm","vfjIq00","y3r4","z2PSB0i","q3vZDg9Trxi","tuTPr20","vNzUC0q","AwXSihvZzsa","AwL3Cxe","whndwem","zLHNz3C","yLrnsLO","zxjYtM8","rMPiu2W","wxbgBK0","ruXnAK4","CMvHzhLtDge","u2vovwm","DgfIyxnL","CMLLC0nVDw4","mJeWnti4nNPbAKDJDG","zgPXt2u","jMPZy2fSBgi","zM9YrwfJAa","AuPlq0W","B2nRzxq","Cfz1uLy","yxbWBhK","CMvZDwX0","DMfSDwu","ywrK","x3nLCuLK","DMvYC2LVBMm","uKHiq1i","yMrFzgLK","rM5LshK","EsbJBg9Zzwq","C2vYDMvYvgK","CwDwz3C","AefJA01LC3m","tg9NsurozxC","EKjcDfi","wuvYvum","wK50zhu","BLHTse4","CYbHBhjLywq","Bvngz04","x194x21Zz18","CMvTB3zLq2G","s2fgAg0","BgvY","quvIA2K","zcWGDw5RBM8","sLbnEgK","wM9HEMS","vLDbu0K","AuHur1K","zfvZvfe","zw1Zvg8","zxH0ugf5Bg8","y2HnyxHuCMK","Bwv0Ag9K","Cu5JrwC","yxDAAwu","t01ur3a","qKPlwK8","EMDoExq","wg9dtwG","yNPzz1q","v0viEMO","EKLJzuq","nteWntzxDMfbqM8","ENzyr08","Dw1MDhm","ruHtq3C","x2rPC2nVBM4","zw5HyMXLuw8","EvfoCKm","rNf6quO","y2Tgv0C","Ahfmuwu","uwD5rKC","CvfdCxC","x2TLEvbHDgG","rLHvBui","yNbqCuG","BMnICfO","y2HLy2Tszwe","DMfSDwvZ","CLnLyNO","Eerwzge","ywX3yxLZ","CeDMuu0","CgfNzwHPzgu","tfvRvu0","x3DZsw5ZDge","qu1ywfq","CvfLAxe","qwjVCNrfCNi","BMrWB2LUDca","x2XPC3rLBMu","x3bPBMDmB3m","CMvJzwL2zwq","zxmGCMvHy2G","A3D4vhu","Axnby2TdBgu","yMzhD0y","q1nlrLu","tKfusvzfx0u","CgLSEgi","AgzWswq","AuzjruW","su5iz0q","AxnmB25N","uLjpuG","yw5ZzM9YBvq","Cvbcr0K","q1rTreu","rfjAsve","z3zOreq","v0ftrva","A0vjCfa","Dgv4Dc9Qyxy","uhHQs3O","Aw9U","v01pDwK","De1HBMfNzxi","rfn0Euu","C0H6qNO","uLL2vgy","zw5HyMXLvhi","uxvLDwu","CMfTzq","Aw5L","B3jRig9MzMW","B0XoDeq","rxHlqNO","u0rZvfO","q3DPq0q","BuzUDMu","CfrzCKG","x21LC3nHz2u","DhjHBNnHy3q","uwvkuwy","v1DVDxa","AxnAzxjV","u2TPCcbWyxm","zw5JB2rLrNi","CgLUz0XVC3m","Cev0vNm","D1LXzNy","y3v4Bfe","yLjezve","ve1OB2q","x2rYB3bhBg8","tNngrLq","rMPbCva","Aw9UvgLTzw8","sxn1rMi","AxnbCNjHEq","wePwC04","CMvXDwLYzwq","shnOEMK","x3nLBMrby2S","ywnRtxnNswq","igfYCMf5yNu","ugLXDe8","ywjTsxm","zu96wMi","CM9YrxzLBNq","ruD6vfC","zezhDNO","BK5Lu2C","zxLfy3m","ruDSqKq","ihrYEsbYzwm","ve93uNi","yxjYyxLIDwy","B25mAw5L","rKfmAeq","BfDJEuO","z0vLueO","zcWG","y2vZC0HHBMq","vLDty3y","Aw1LCYbPBIa","uMvHzcbWyxm","uvjKCLm","reHhz2q","Ec11C2uT","vhnMsgG","Cgfbrey","qM5VD1e","weXdrLy","DgvZDa","y3nlDNO","v2vPEgLUsLm","vKvIrhe","EvjLy29UBMu","vg5UvMK","AxnszwfKEq","DKLkr2K","BM5kD3G","y29UBMvJDfm","nhW1FdD8mW","zxHWB3j0CW","BIWGAg9ZDg4","s3L4wfC","rLPfAfO","y29UBMvJDeu","reX5C3i","Bg9NsurozxC","zgL1Cg0","vwrTEeS","C21gA0G","x3fVC0rc","zNjVBNrPzxi","Cgf5Bg9Hzeu","AxjjAuu","t0jOtLq","BwvY","AgLNAa","rejnqKS","rM1qCKC","ywnOzwq","BhnHsum","y2HHCKnVzgu","A3jjshe","tw9KDwXL","EeLjzg0","zwv2Awi","CfbiwK8","ExbL","BwfUDwfSihi","BKPNu2q","qwrMvxe","ihn1y2nLC3m","nxW5FdeWFda","ru1rufu","vNHhChG","twvNq2S","Evr6zNK","DuTWBNq","rNvizhi","BgnoA0i","C2vUDa","D3bNAfq","wvfVufG","BNrLCG","zeTQz0y","DxjS","ywzOBeq","tufyx1jfvfi","vw5PBxbSzw0","r0zPrfG","x3DZ","twzysNi","wvr2u3q","qLPhAvm","uvrqvxC","ze96r20","zxH0zw5ZAw8","B2TVquK","vg9Vvxm","z2vY","CxfsuKq","CfHszg0","r0rHtu8","Dg9VigXHCMC","qxPpDgi","ywDLsgLKzq","rNj5vxq","zMjtCM8","ywD4yMu","C29Tzq","x2LUAxq","zxjFBxnNAwq","su54EgW","DLLPCwm","u3vqwMK","DhjPzxmGCMu","B0HIqK4","EKjNzgm","q29UzMLN","qLnhEwK","qxv4Dge","u2fHwxm","y2f0y2G","CgLUz1rPBwu","wuT4r04","zxq9DxrMltG","DKD5CfO","BMnLq2XVC2u","AezIwum","DwXvwKy","vuf2Cei","A3zAzuO","BNnVrMW","y0vlzhG","D01QBKy","EKPvA2C","txDNt3a","BMLjAve","EwzKqK0","EwrcBKm","rNHXBvm","x2n1CNnVCKy","v2vIu29JA2u","C2fNzq","B25tDgfYDfi","y3vYCMvUDeu","vevNsvi","y21JEhi","tvjKwMC","x3DHAxq","zMzMzG","BvLdEMK","wNrYAfm","DfPizMy","BNPeseq","tuvtu0fhrv8","AhLlBNe","lcbOB3n0BMe","vNz4D1q","D3jPDgu","zeLit0e","qvrlthK","wNzIChm","qLvtu3C","vuXTAM0","A0fkDgm","CNjyqKe","CwjlwLi","rvDOsMu","l3DZl3yY","verhB00","BgvUz3rO","uhHQB1q","rw1sweq","uvDeuuW","CezAs0O","AwrWqLG","C3rLBMvYCW","r3PSt04","BxnNsuq","CKHRyMi","ywrKt25L","uKHMALC","uKXjEMC","AvPRse8","zxj2AwnL","ChjVy2vZCW","ANvkAKG","quzjAxG","CNzHBa","DwfWzhm","CMzTzfm","AvjOt2K","DNPLs2u","qMXQuue","vfjRtM4","rw1QAuS","DNz3yNu","x2LZtwLUAvq","Cgu6ia","x29Ut3bLBG","t0f3B1y","CMvKDwnL","ywH0Du4","ihbYB3rVy28","A1PQr2y","uu5gtu8","AgHMuNi","u0zuEe8","t0nTwgC","zMLN","vNPIrha","yvbcv0i","AerhCLK","CNjVCK1LC3m","rhfXsvC","ywXPzcb1CMW","ExrMD0C","rgvlqNK","wwHbuxm","CMvTB3zLrxy","ruDStuS","tMfTzq","Dhr3Awq","s3vjwhy","EKzjug8","CKTks3u","z3H2wMS","zfj3uw4","B25szwnLAxy","x2vUzhbVAw4","Ahbmy2m","y3jLyxrLuMu","BuzcC28","ze9bBfK","zxjLDuS","AxnrB1nnzxm","zw1PDa","x29UrxjYB3i","zvH5r2i","CffOu1e","ywXS","r3HTt20","sxPMCLq","Ahr0Ca","Ae5AAhO","v0XRt28","q056weG","zgv1vKS","vuT0Avu","uMvJB25Uzwm","CffisfC","txvHA3O","CwLuC04","y29UDgLUDwu","wKDRAgm","vKzcDxe","vw5Oyw5KBgu","Bg93","x2nYzwf0zvm","z2DJCLG","wM16De0","uLPLBuO","yM9KEq","seTOqNe","CM92AwrLigi","B25dBg9Zzq","Dg9oDw1Izxi","y3jLyxrLrxi","uw9ZvNm","x19LC01Vzhu","Cff1BMm","C0Ljtha","qvjgzKu","uuPbz0y","u1jKAeS","ihrPBwvVDxq","BNruCMLLC0m","A1nIs04","BNrfBMrWB2K","BgLtrfK","D3m6lY8","zwn0","ENv0Eee","zgvIDwC","uurdwuO","ywXty29Wzq","EMz3B1O","rufTB2y","Dgv4Dc9WBge","EhvizMq","D24GCMvHC28","AenKrwW","ALLsBLq","wMPNtKS","tMHuqKi","yvHqqNK","tevcz1q","x1fVu01HBMe","y29UBMvJDgK","sMPYCfa","tvbIELG","zMLSzw5HBwu","ywvIBK8","BLP1BLy","ywDLrxzLBNq","Bwf4tg9ZC0m","C3Pewe0","Dg9Y","zwHbzgi","ywTyq0K","v3Pkr1O","rfvxvvO","r1fkEMO","CMXwt2C","sfLou0S","EuHWAxu","DNnhv2S","rxjYB3jdB2q","zxjYB3i","zxjFCw9Z","qKDUrei","zw1LBNq","q3vZDg9Tq2W","Afryrvi","Efjuqum","Exbwze8","yMfJA3vWigu","uNnYueu","C3rHCNq","rgPKv2q","qwjmvum","Ce9NCMK","EuXlqLe","vhfjr1i","sLLqwMC","DgLTzw91DcW","rfvishG","v2DlB2C","CgrrqxK","yKHtAwu","r1z3Bfq","BMfTzq","D2fZq2XLyw4","su5tvefova","DgLLCKPtt04","ywzL","igzPzwXKoIa","B25SAw5L","BwvZC2fNztO","yMTOtwS","weH2qwC","tuzqyuO","CuTWsxO","wM9dr00","tgjOu3q","z2Xquw4","B2LVAxG","AvLVDgy","q05tA2O","ru9ntxa","Dxbrtwu","B3jRzxjhBg8","y29SBM8","s0Liz3y","EvvpDhK","CKHLsuO","ue5nsNa","AgHzC2e","tMTKrxu","vKjND20","AgfZt3DUuhi","zgTSufa","CgjICdi","B1vdD3u","AM9lyxO","B2rLwwO","CMvZzxrdB3u","AeXYq0m","tuHIr2K","q0D4AeW","EKXKz3G","q09otKvdveK","y3vYC29Yx2y","qw9uwKK","AwrI","vvfNqw0","C3vgq0O","z1rPBwvVDxq","qNnNq0O","zgf0yq","z2v0sxrLBq","wvnHt3e","BfjmvNy","yw1L","yNjvExe","BwvKAwf0zwW","y29TCgXLDgu","rKfWEum","twD1rwm","rK1jsM0","yvb5Cgy","qM9Kr0C","ChDkz0C","x2HHBMrSzu8","CKvVDem","rMvrB0e","veHYENC","r2LPrxm","yvndBMO","DwngCNG","ywnRpwzYB24","sgzzzwu","tMLfsuy","tMLfAMe","EunnBfO","y0Tjveq","CgLUz0LUDgu","yxrHlcbKyxq","A3LWC0O","D0nzzwS","DhjlzMy","DNfUqvO","qvHhu2m","q3rQrw0","rwr6u1C","zKvgwKK","B2nRzxrgywK","zgTjB2e","zKXsAeO","BunfDKe","BfLbB2K","zfrSrxO","zxjYtxnN","DwHlBgm","C2v0sxrLBq","x0rctMfTzq","vhbdy0e","zxzZqLe","mZG3me5XtuDqua","rNjSvLq","DerzueC","y0T1u3a","EurAEgi","B2vmzuq","D0vLrgC","y2uGBM90igK","zxzru1K","rePqAfO","y2XVC2u","Dfjsy1C","yMLUza","CNnVCKzPBgu","mZvxrNr1sfy","zwTjrvm","sMf6uMO","Aw5PDcbrB1m","C3vIC3rYAw4","u1fVueC","qNDzteS","rw93tfa","BMvY","rhPWD0K","wfDHvey","rLDt","CM92AwrLihC","C2v0u3rVCMe","sLD6wLm","B25JBg9Zzq","tLHkywy","uM9xD2y","AgDYvKy","txvKBfi","Aw9Ul2PZB24","DNrTD2i","Avnbv3K","C1nvzxq","uKr2Ewu","tNnkrMS","wvnhv1q","zwvKzwq","y2HnyxHdB3u","qKDut1q","sfrtvuy","ugvivum","zw5fDMvUDa","vgvgz2y","Bg9Nsurhzw4","qMrdDLq","DvHnrKu","Dg9cExrLCW","BMXtuLC","tK1kyxG","Dg9hzw5LCMe","EM9VvMS","Cu14C0G","q1LeD1O","C0Xf","shPtwui","vNfJB1e","DwTWs3u","qK9orMW","zv90Aw1LB3u","vgLTzw91Da","EePlCxi","wffXz3C","CNPlC3a","BM93","DefHBM4","v3vzrgy","B0rArKe","BKvIuui","q0fpDfm","DfvZvNq","DwPjAxC","s1HKtLi","zMXVB3i","uu12EgG","Dgv4DfbHEwW","EvbVEuu","C1POrLe","C2H2AuK","tMLfqLC","rxzLBNq","DMfS","wwTUDKK","BMvLzf9Hy2S","AK1WDeq","B2zMC2v0","zvvJreC","y29Kzq","suXNvvu","BM52Avi","tg1jCKC","qwfHwuG","B25vtxi","BuniDhC","uKXeEhq","CMvHzg9UBhK","B3bLCNr5tMe","z0PkvNK","igzHAwWSig0","Cgf5Bg9Hza","zwnVBM5Ly3q","t1bftL9fuLi","zMLABNy","yMLyAxi","ufD1v3q","q0j6Dvm","vKXut20","qKT1Du0","zNjHBwvuExa","vxzZAvy","sKDdEge","sNfbEhy","uNrTAu8","x2jPBMfYEvq","BMDuAw1LCG","CNfSuwO","zNjVBu51Bwi","z2vtEw5J","AvDQqM0","B25Uzwn0Aw4","sNbiqNO","DfjLsMy","uhjPBwfYEuS","AxbgBvm","wvvzzM4","ELLoAe4","uuTLy0S","m3W1","CNfVzLG","Aw5KzxG","BLHgBhO","BejdAM0","t3nAyKm","mtmZmJLNuwHMAwu","wNPyBhm","DM1vuKi","C0jf","sLnptLa","vxjTseC","DhjPuhG","t2LvAwK","u0fcqxa","v1nLvu8","Afj2Awm","Dw5RBM93BIa","BwvZ","sKXvCNq","v2fjsgq","Aw5JBhvKzxm","B2XKvMvYC2K","B3jL","DeLUDgvYy2u","BNrbBMrvCgq","x29UvgLTzw8","A1jcyLG","Dhf5EfG","Cgf5Bg9Hzfq","EKXpz2K","ywnRDxbfBMq","y3vYC29Y","t3rTA3y","yKr6DgW","tu9xqva","B1HZDgO","yxnL","AgH2s2u","uMP4BeC","AxnFywnR","zNvyvxK","AwXLx25HBwu","CuXxq1m","qxfAzgK","y29UDgv4Da","DLH2Exm","DMrQu0e","veLADMO","zxf1ywXZ","uKj6CNO","u1LpzLm","v3rAwgO","r1n5Cwy","z1bhtwe","v0XWDe8","AuDJwvO","sKPTy24","u2vYDMLJzvC","CMvZB2X2zq","ywDL","A1vRwKy","mtm3otu3uLnzvhnq","AgT5qK8","C3bbALG","BgrxBeS","DNbTDgO","y2rRtMG","uK15EhO","DM5rEKO","rw1mDei","C2v0","m3WXFdH8mNW","DgLUzYbZzxi","tujrA00","wNHkAwu","q1jkuha","yuXsyLK","ENbAy1y","y29UBMvJDa","yxv0B21HDgK","rMLnvwW"];return $o=function(){return t},$o()}(function(t,e){let r=G,i=t();for(;;)try{if(parseInt(r(1821))/1+parseInt(r(775))/2*(-parseInt(r(1959))/3)+-parseInt(r(637))/4+-parseInt(r(983))/5+parseInt(r(1044))/6+-parseInt(r(1642))/7*(-parseInt(r(1095))/8)+parseInt(r(1765))/9*(parseInt(r(1628))/10)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})($o,244335);var Ov=Object[M(516)+"operty"],Lv=Object["getOwnPr"+M(1728)+M(1777)],_h=(t,e)=>function(){return t&&(e=(0,t[{nJgSd:function(c,l){return c(l)}}[M(1258)](Lv,t)[0]])(t=0)),e},Nv=(t,e)=>{let r={HZgbg:function(o,c,l,u){return o(c,l,u)}};for(var i in e)r.HZgbg(Ov,t,i,{get:e[i],enumerable:!0})};function Mv(){return hh||(hh=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Bv(){let t=M;return ph||(ph=[IDBCursor[t(1958)+"e"][t(625)],IDBCursor.prototype[t(1443)],IDBCursor[t(1958)+"e"][t(1443)+t(1754)+"ey"]])}function zv(t){let e=M,r={nBJSv:function(o,c){return o||c},ZjgNK:"success",odeYj:e(1508),hFbYC:function(o,c){return o(c)},zHXrY:function(o){return o()},OBhNT:function(o,c){return o===c},uIXQF:e(918),YSaOq:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let l=e,u={zrMCC:r[l(1483)],CBvQH:r.odeYj,jNNoK:function(x,h){return r[l(1317)](x,h)},jKTZB:function(x,h){return x(h)},QHvqn:function(x){return r.zHXrY(x)},Wuhhj:function(x,h){return x(h)}};if(r[l(1243)](r.uIXQF,l(918))){let x=()=>{let E=l;t[E(1409)+E(1908)+E(1650)](u[E(1987)],h),t[E(1409)+E(1908)+E(1650)](u.CBvQH,m)},h=()=>{let E=l;u[E(2006)](o,u[E(541)](Ft,t[E(1052)])),u[E(1842)](x)},m=()=>{let E=l;u[E(699)](c,t[E(1508)]),x()};t[l(1892)+l(1923)](r[l(1483)],h),t[l(1892)+l(1923)](r[l(1565)],m)}else{let x=this[l(1239)][l(2044)+l(1749)](this._prefix),h=_0x64ee8f[l(2119)](r.nBJSv(x,"{}"));return h[_0x28be0d||_0x5494d8[this[l(875)]]]=_0x39c574,this[l(1239)]["setStora"+l(1749)](this[l(667)],_0x5bf1c2[l(1004)+"y"](h)),_0xb452e8||_0x4376a8[this[l(875)]]}});return i.then(o=>{let c=e;r[c(1581)](o,IDBCursor)&&Pd[c(1830)](o,t)})[e(1311)](()=>{}),Zo[e(1830)](i,t),i}function Fv(t){let e=M,r={SRBWS:e(1643),CSKFU:function(o){return o()},lYAoi:e(1586),CqDVf:e(1508),UtPFA:e(1122)+"or",glPQn:function(o,c){return o!==c},kwxTu:"Myhpd",YknvI:"abort"};if(Vo.has(t))return;let i=new Promise((o,c)=>{let l=e,u={fUhQW:r[l(1620)],IZaqg:r[l(990)],gBmyh:function(x,h){return x(h)},diupm:r.UtPFA,zfwoZ:function(x){return r[l(1131)](x)}};if(r[l(1545)](r[l(1128)],l(498))){let x=()=>{let E=l;t["removeEv"+E(1908)+E(1650)](u[E(788)],h),t[E(1409)+"entListe"+E(1650)](u[E(2085)],m),t["removeEv"+E(1908)+E(1650)](E(1843),m)},h=()=>{let E=l;if(r.SRBWS===r[E(721)])r[E(1131)](o),r[E(1131)](x);else return this[E(1239)]?.isReady},m=()=>{let E=l;u[E(811)](c,t[E(1508)]||new DOMException(u[E(1236)],u[E(1236)])),u[E(1476)](x)};t[l(1892)+l(1923)](l(1586),h),t[l(1892)+"Listener"](l(1508),m),t[l(1892)+l(1923)](r[l(1714)],m)}else this[l(1016)+l(1967)]()});Vo[e(1830)](t,i)}function Uv(t){Jo={umCUB:function(r,i){return r(i)}}.umCUB(t,Jo)}function qv(t){let e=M,r={DUHHx:function(i,o){return i(o)},ggcrX:function(i,o){return i===o},lvnZW:e(1833),MOWAP:"MHMRX",eyEcs:function(i,o){return i>>>o},PNMJp:function(i,o){return i|o},XstOP:function(i,o){return i>>>o},xNhLy:function(i,o){return i===o},dRviF:function(i,o){return i<o},hRvic:function(i,o){return i<o},oOPdF:function(i,o){return i<o},NlCDX:function(i,o,c){return i(o,c)},DzpwI:function(i,o){return i&o},liyMS:function(i,o){return i>>>o},IpniP:function(i,o){return i!==o},JRrjA:function(i,o){return i+o},WaIHd:function(i,o){return i!==o},NkdEu:function(i,o){return i>>>o},dFGvz:function(i,o){return i&o},ySGrg:function(i,o){return i>>>o},aHfuX:function(i,o){return i|o},qLWCS:function(i,o){return i&o},hLrCC:function(i,o){return i|o},ncUOQ:function(i,o){return i&o},AbLUC:function(i,o){return i>>>o},zeXxL:function(i,o){return i!==o},QaqKu:function(i,o){return i|o},OaUqV:function(i,o){return i+o},rqlQj:function(i,o){return i!==o},UmIux:function(i,o){return i|o},KqWqK:function(i,o){return i>>>o},bpPqH:function(i,o){return i>>>o},poFfw:function(i,o){return i!==o},DhGza:function(i,o){return i|o},BOvbc:function(i,o){return i(o)},mFBso:function(i,o){return i(o)},evQSY:function(i,o){return i===o},awpHf:e(2079)+"oreNames",JqAxv:function(i){return i()},jBRBl:function(i,o){return i===o},vDrbi:"OdnLp"};if(r[e(1636)](t,IDBDatabase[e(1958)+"e"].transaction)&&!(r[e(810)]in IDBTransaction.prototype))return function(i,...o){let c=e,l=t[c(1922)](rs(this),i,...o);return kd[c(1830)](l,i[c(539)]?i[c(539)]():[i]),r[c(1526)](Ft,l)};if(r[e(1743)](Bv)[e(1780)](t)){if(r[e(1886)](r[e(685)],r[e(685)]))return function(...i){let o=e;if(r[o(1449)](r.lvnZW,r[o(1794)]))_0x4ea912[o(1818)]().then(()=>{this[o(998)+"steners"]()});else return t.apply(r.DUHHx(rs,this),i),Ft(Pd[o(867)](this))};{let i=r[e(1197)](_0x3dc61d[e(1447)],0),o=r.eyEcs(r.PNMJp(r.XstOP(_0xdac9d[e(1447)],28),_0x4eebf2[e(1245)]<<4),0),c=r[e(1924)](_0x44694d[e(1245)],24),l=r[e(1449)](0,c)?r[e(713)](0,o)?r.dRviF(i,16384)?i<128?1:2:r[e(490)](i,2097152)?3:4:r[e(1775)](o,16384)?o<128?5:6:o<2097152?7:8:r[e(1898)](c,128)?9:10,u=r[e(504)](_0x153118,_0x279b37,l),x=_0x2ace18[e(1913)];switch(l){case 10:x[u+9]=r[e(1651)](r.liyMS(c,7),1);case 9:x[u+8]=r.IpniP(9,l)?r[e(1556)](128,c):127&c;case 8:x[r[e(528)](u,7)]=r[e(1779)](8,l)?r[e(1558)](o,21)|128:r[e(1195)](r[e(804)](o,21),127);case 7:x[r[e(528)](u,6)]=r[e(561)](7,l)?r[e(1556)](r[e(494)](o,14),128):r[e(494)](o,14)&127;case 6:x[r[e(528)](u,5)]=r[e(1779)](6,l)?r[e(611)](r.eyEcs(o,7),128):r[e(1802)](o>>>7,127);case 5:x[u+4]=r[e(561)](5,l)?r[e(1567)](128,o):r.ncUOQ(127,o);case 4:x[r[e(528)](u,3)]=l!==4?r[e(1520)](i,21)|128:r.eyEcs(i,21)&127;case 3:x[u+2]=r[e(1911)](3,l)?r[e(883)](i>>>14,128):i>>>14&127;case 2:x[r.OaUqV(u,1)]=r[e(1747)](2,l)?r[e(737)](r.KqWqK(i,7),128):r[e(1109)](i,7)&127;case 1:x[u]=r[e(650)](1,l)?r[e(726)](128,i):r[e(1802)](127,i)}}}return function(...i){let o=e;return r.BOvbc(Ft,t[o(1051)](r[o(1422)](rs,this),i))}}function Gv(t){let e=M,r={rKJKu:function(i,o){return i===o},BmMCj:"function",jHEvV:function(i,o){return i(o)},mYEqx:function(i,o){return i instanceof o},FjHSl:function(i,o){return i(o)},NLqMr:function(i){return i()}};return r[e(1415)](typeof t,r.BmMCj)?r.jHEvV(qv,t):(r[e(981)](t,IDBTransaction)&&r[e(1037)](Fv,t),yh(t,r.NLqMr(Mv))?new Proxy(t,Jo):t)}function Ft(t){let e=M,r={yTzfy:function(o,c){return o instanceof c},NfFgK:function(o,c){return o(c)},RsrPE:function(o,c){return o!==c}};if(r[e(1265)](t,IDBRequest))return r[e(615)](zv,t);if(Wo[e(483)](t))return Wo[e(867)](t);let i=r[e(615)](Gv,t);return r[e(1517)](i,t)&&(Wo.set(t,i),Zo[e(1830)](i,t)),i}var yh,hh,ph,Pd,Vo,kd,Wo,Zo,Jo,rs,gh=_h({"node_modules/idb/build/wrap-idb-value.js"(){let t=M,e={BsgCJ:function(r,i){return r instanceof i},deuVK:function(r,i){return r===i},DRZIQ:t(808),cmcxr:"objectSt"+t(1018),RPRzG:"store",dklPP:function(r,i){return r(i)},cdjDG:function(r,i){return r instanceof i},HwpkO:function(r,i){return r in i}};yh=(r,i)=>i[t(1298)](o=>r instanceof o),Pd=new WeakMap,Vo=new WeakMap,kd=new WeakMap,Wo=new WeakMap,Zo=new WeakMap,Jo={get(r,i,o){let c=t;if(e[c(1578)](r,IDBTransaction)){if(e[c(1437)](i,e[c(1142)]))return Vo.get(r);if(e[c(1437)](i,e[c(1336)]))return r[c(2079)+c(1018)]||kd[c(867)](r);if(e[c(1437)](i,e.RPRzG))return o[c(2079)+c(1018)][1]?void 0:o["objectSt"+c(1782)](o[c(2079)+c(1018)][0])}return e[c(1561)](Ft,r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return e[o(520)](r,IDBTransaction)&&(i===o(808)||e.deuVK(i,e[o(570)]))?!0:e.HwpkO(i,r)}},rs=r=>Zo[t(867)](r)}}),bh={};function G(t,e){t=t-469;let r=$o(),i=r[t];if(G.LFNLLY===void 0){var o=function(x){let h="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",m="",E="";for(let S=0,_,v,A=0;v=x.charAt(A++);~v&&(_=S%4?_*64+v:v,S++%4)?m+=String.fromCharCode(255&_>>(-2*S&6)):0)v=h.indexOf(v);for(let S=0,_=m.length;S<_;S++)E+="%"+("00"+m.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(E)};G.jAMxzs=o,G.abNwZz={},G.LFNLLY=!0}let c=r[0],l=t+c,u=G.abNwZz[l];return u?i=u:(i=G.jAMxzs(i),G.abNwZz[l]=i),i}Nv(bh,{deleteDB:()=>jv,openDB:()=>Hv,unwrap:()=>rs,wrap:()=>Ft});function Hv(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let l=M,u={XUdVD:function(m,E){return m(E)},wecqv:"close"},x=indexedDB[l(1999)](t,e),h=Ft(x);return i&&x["addEvent"+l(1923)]("upgraden"+l(1669),m=>{let E=l;i(u.XUdVD(Ft,x.result),m[E(1781)+"on"],m[E(776)+"on"],u[E(1853)](Ft,x[E(1166)+E(1148)]))}),r&&x[l(1892)+l(1923)](l(1845),()=>r()),h.then(m=>{let E=l;c&&m[E(1892)+"Listener"](u.wecqv,()=>c()),o&&m[E(1892)+"Listener"](E(1056)+E(2081),()=>o())}).catch(()=>{}),h}function jv(t,{blocked:e}={}){let r=M,i={rSebz:r(1845),YpFnM:function(c,l){return c(l)}},o=indexedDB[r(814)+r(1042)](t);return e&&o.addEventListener(i[r(1113)],()=>e()),i[r(1038)](Ft,o)[r(583)](()=>{})}function mh(t,e){let r=M,i={INxxl:function(x,h){return x!=h},BivHZ:function(x,h){return x instanceof h},Dfuse:"application/json",QWDQL:r(714)+"e",XuisQ:function(x,h){return x in h},RLIzg:function(x,h){return x===h},ArKKh:"string",viKSf:function(x,h){return x!==h},jMptD:r(2097)};if(!(i[r(1984)](t,IDBDatabase)&&!i[r(740)](e,t)&&i[r(1372)](typeof e,i.ArKKh)))return i[r(1855)](i[r(1716)],r(687))?void 0:i[r(1301)]("string",typeof _0x2f4193)&&(i[r(1984)](_0x2d1fe5,_0x205587)||_0x23795f[r(900)]&&i[r(1984)](_0xb642bb[r(900)],_0x3cd5b8))||i[r(1301)](r(1896),typeof _0x372cd0)?"":(_0x2a026b[r(2119)](_0x5592ee),i.Dfuse);if(Ko[r(867)](e))return Ko.get(e);let o=e[r(511)](/FromIndex$/,""),c=i[r(1855)](e,o),l=vh[r(1780)](o);if(!i.XuisQ(o,(c?IDBIndex:IDBObjectStore)[r(1958)+"e"])||!(l||Eh[r(1780)](o)))return;let u=async function(x,...h){let m=r,E=this[m(1166)+m(1148)](x,l?i[m(1363)]:m(1727)),S=E[m(967)];return c&&(S=S[m(1761)](h.shift())),(await Promise[m(1430)]([S[o](...h),l&&E[m(808)]]))[0]};return Ko[r(1830)](e,u),u}var Eh,vh,Ko,Wv=_h({"node_modules/idb/build/index.js"(){let t=M,e={mgiQA:function(r){return r()},CAGKD:t(867),eOzZb:t(914),uKpnt:t(2020)+"ys",RHHCR:"count",pIfAz:t(850),ARFfE:t(1054),vlvwN:"clear",sjEtK:function(r,i){return r(i)}};gh(),e[t(890)](gh),Eh=[e[t(2070)],e[t(1192)],t(1014),e[t(1266)],e[t(1057)]],vh=[e[t(1873)],e[t(1462)],t(1920),e.vlvwN],Ko=new Map,e.sjEtK(Uv,r=>({...r,get:(i,o,c)=>mh(i,o)||r.get(i,o,c),has:(i,o)=>!!mh(i,o)||r[t(483)](i,o)}))}}),Kv={idb:function(t){let e=M;t[e(1229)]=Promise.resolve()[e(583)](()=>(Wv(),bh))[e(583)](function(r){return r})}},wh={};function zt(t){let e=M,r={GDaMO:e(795)+"3"},i=r[e(1291)][e(852)]("|"),o=0;for(;;){switch(i[o++]){case"0":if(c!==void 0)return c[e(1229)];continue;case"1":Kv[t](l,l[e(1229)],zt);continue;case"2":var c=wh[t];continue;case"3":return l.exports;case"4":var l=wh[t]={exports:{}};continue}break}}zt.d=(t,e)=>{let r=G;for(var i in e)zt.o(e,i)&&!zt.o(t,i)&&Object[r(516)+r(2038)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=M;zt.o=(e,r)=>Object[t(1958)+"e"][t(1560)+t(2038)][t(1922)](e,r)})(),(()=>{let t=M,e={etLjk:function(r,i){return r!=i},FVTOG:t(1252),YErUC:t(1459)+"le"};zt.r=r=>{let i=t;e[i(861)]("undefined",typeof Symbol)&&Symbol["toString"+i(1998)]&&Object.defineProperty(r,Symbol[i(1914)+i(1998)],{value:e[i(847)]}),Object[i(516)+i(2038)](r,e[i(1066)],{value:!0})}})();var Re={};(()=>{let t=M,e={SHsjt:function(a,n){return a(n)},XLCFV:function(a,n){return a+n},nqYIX:function(a,n){return a>=n},MFPaJ:function(a,n,s){return a(n,s)},CciJV:function(a,n){return a|n},RBzrz:function(a,n){return a&n},GKYcB:function(a,n){return a===n},oUCwu:t(1306),Znenb:function(a,n){return a*n},NYGrX:function(a,n){return a+n},rxoBo:function(a,n){return a(n)},shzGT:function(a,n){return a+n},QNFMO:function(a,n){return a+n},oytDn:function(a,n){return a&n},BZGiS:function(a,n){return a<<n},jlYqf:function(a,n){return a|n},aXPBy:function(a,n){return a&n},szDXM:function(a,n){return a&n},OmNoc:function(a,n){return a<n},oUEmt:function(a,n){return a<=n},EGlBD:function(a,n){return a!==n},UTKDs:t(1423),yYOaJ:function(a,n){return a(n)},BrRTa:function(a,n){return a(n)},wjLTk:t(1003),OCmXg:function(a,n,s,d){return a(n,s,d)},sDcYK:t(1508),gxvZk:function(a,n){return a===n},uALcO:t(1623),QeJQf:"DzWbY",zFIPo:function(a,n){return a(n)},gExQz:function(a,n){return a(n)},vqnAZ:t(780)+t(780)+t(780)+t(780),nZunV:function(a,n){return a&n},rgLqK:function(a,n){return a<=n},DPpfg:t(819)+t(519)+t(1870)+t(1209)+t(1375),MwgOp:function(a,n){return a===n},FXrsn:function(a,n){return a<n},QRdrS:function(a,n){return a>n},eLaWJ:function(a,n){return a!==n},jVPZZ:function(a,n){return a-n},VqcoQ:function(a,n){return a===n},ELlrP:t(1590),rqofX:t(1369),XiLfF:"ZQSCm",cpsJf:"Umhny",upQMe:function(a,n){return a!==n},FaXqh:function(a,n){return a!==n},hfkNY:function(a,n,s){return a(n,s)},WzbxG:function(a,n){return a!==n},iWjBm:function(a,n,s){return a(n,s)},BGnDB:function(a,n){return a>>>n},FFOGU:function(a,n){return a(n)},dkIoa:function(a,n){return a===n},pOgri:t(987)+t(1185)+t(1536)+"value",oYunc:function(a){return a()},zIceD:function(a,n,s){return a(n,s)},tDYPG:function(a,n){return a(n)},KdXaL:function(a,n){return a-n},WEHzj:function(a,n){return a!==n},qEUjN:t(619),JjZUH:"timeout",aidhI:t(903)+t(887)+"s",BxqUd:function(a,n){return a(n)},FkWTI:t(840),NQTLG:function(a,n,s){return a(n,s)},Ukkzr:function(a,n,s){return a(n,s)},jpuRd:function(a,n){return a!==n},JJmcn:function(a,n){return a!==n},VrciG:t(1704),dTQgm:function(a,n,s){return a(n,s)},KyxXW:function(a,n,s){return a(n,s)},nnviR:function(a){return a()},nXFlz:function(a,n,s){return a(n,s)},CZFXl:function(a,n){return a(n)},abmIs:function(a,n){return a!==n},iFZCT:function(a,n){return a===n},vzeKe:t(582),TnnVi:t(1829),EGzTW:function(a,n,s){return a(n,s)},XvkPb:function(a,n){return a!==n},MLwRC:function(a,n){return a!==n},DxbbX:function(a,n,s){return a(n,s)},eJvHj:function(a,n,s){return a(n,s)},oCXWV:function(a,n){return a!==n},XLTOP:t(1866),lTUBm:t(1349),AzOtb:function(a,n,s){return a(n,s)},SABAp:function(a,n,s){return a(n,s)},UQYey:function(a,n){return a!==n},lQGnz:function(a,n,s){return a(n,s)},UvsiV:function(a,n){return a!==n},IsuFb:function(a,n){return a(n)},DUWUZ:t(1638),FneHy:function(a,n){return a!==n},gvhDD:t(2013),zgNyt:function(a,n){return a(n)},CTmDE:function(a,n,s){return a(n,s)},suFCJ:function(a,n,s){return a(n,s)},IRcuk:function(a,n){return a==n},TdrkI:function(a,n){return a!==n},LUkUM:t(578),bkhMk:t(1744),CNkee:function(a,n){return a===n},ACUag:t(1876),orSxk:function(a,n){return a(n)},baNXJ:function(a,n,s){return a(n,s)},kEIpP:function(a,n,s){return a(n,s)},iEbQa:function(a,n){return a(n)},UWwhi:function(a,n){return a(n)},anShy:function(a,n){return a(n)},SuPZi:function(a,n,s){return a(n,s)},oKozB:function(a,n){return a(n)},eevib:function(a,n){return a(n)},qiTsN:function(a,n,s){return a(n,s)},NMJax:t(987)+t(1185)+t(1536)+t(727),CTepS:t(987)+t(1185)+t(1536)+t(759),ZnhHW:t(987)+t(1185)+t(1536)+t(2022),dYVGu:function(a,n){return a===n},KRxUI:t(987)+t(1185)+t(1536)+t(1085),SPfWx:function(a,n){return a(n)},dRwQn:function(a,n){return a+n},KnsXM:function(a,n){return a&n},PiqtO:function(a,n){return a(n)},VHwma:function(a,n){return a(n)},LbhSt:t(1277)+t(2084)+t(1388),jYhOf:function(a,n){return a>>n},cUJOU:t(1546),ZtrhS:"Wotpr",TRkNn:t(1170)+"t limit",XsCXC:function(a,n){return a>=n},Muakz:function(a,n,s){return a(n,s)},RjxlG:t(961),AdfUq:function(a,n){return a>n},Cilhu:function(a,n){return a+n},kUkZF:"hitWL",pQhSQ:t(1844),lsaIC:function(a,n){return a+n},ldMmd:function(a,n){return a<n},pkwzz:function(a,n){return a+n},VBgwm:function(a,n){return a&n},VrKqm:function(a,n){return a===n},tSZYx:function(a,n){return a+n},hhYsa:function(a,n){return a&n},CGxhL:function(a,n){return a|n},yvLKf:function(a,n){return a<<n},fGfqz:function(a,n){return a&n},JObfQ:function(a,n){return a+n},kZjGf:function(a,n){return a+n},mCEvA:function(a,n){return a+n},psRaw:function(a,n){return a&n},zzEUe:function(a,n){return a<<n},zXHqn:function(a,n){return a|n},MwVXU:function(a,n){return a&n},NiEBW:function(a,n){return a(n)},TGyRx:function(a,n){return a&n},pNXGJ:function(a,n){return a+n},cWCrN:function(a,n){return a+n},DnoYb:function(a,n){return a!==n},OCFTK:function(a,n){return a|n},WSYpb:function(a,n){return a<<n},KHQwO:function(a,n){return a&n},AoTZI:function(a,n){return a&n},hrjnM:function(a,n){return a>n},cEKdx:function(a,n,s){return a(n,s)},RBBMo:function(a,n){return a>>n},kSbKN:function(a,n){return a+n},aPBWB:function(a,n){return a<n},KLhUH:function(a,n){return a<=n},cTWSf:function(a,n,s){return a(n,s)},YZzmn:function(a,n){return a<=n},lRLVv:function(a,n){return a+n},iZkHO:function(a,n){return a-n},zooVk:function(a,n){return a<<n},DhXsg:function(a,n){return a===n},mhIMz:t(1017),tatNX:function(a,n){return a&n},evsBQ:function(a,n){return a&n},CMkAK:function(a,n){return a|n},Zoazk:function(a,n){return a>>n},yLKBQ:function(a,n){return a>>n},zLdgx:function(a,n){return a|n},WkamV:function(a,n){return a<n},hmsiC:function(a,n){return a+n},daCFq:function(a,n,s){return a(n,s)},DgUkt:function(a,n){return a<<n},VWScv:function(a,n){return a<<n},afZyE:function(a,n){return a!==n},fDhRX:t(781),BWnZe:"zBBtR",UvalH:function(a,n){return a<n},GQJzj:function(a,n){return a&n},MRdZg:function(a,n){return a(n)},zYNhN:function(a,n){return a<n},uqzls:function(a){return a()},OZpzj:t(545),RLDxt:function(a,n){return a>=n},apLgz:t(1133),baGkz:"XMdym",kyLpd:function(a,n,s){return a(n,s)},ucFrx:function(a,n){return a|n},rUJbV:function(a,n,s){return a(n,s)},iFIEL:function(a,n){return a(n)},TOwRr:"0|2|9|8|"+t(1858)+t(628)+"0",LeoFH:function(a,n){return a>>>n},ZXPMN:function(a,n){return a&n},XoCMh:function(a,n){return a>>>n},QluyR:function(a,n){return a>>n},LZwhw:t(1799),qDBEV:function(a,n){return a&&n},qbKZR:t(682),vsGWk:function(a,n){return a||n},gMTUl:t(1904),nnJwx:function(a,n){return a>n},gOKTy:function(a,n){return a(n)},YWJJj:function(a,n){return a|n},iSAWy:function(a,n){return a===n},mCvSS:"gKAFX",bQQWY:function(a,n){return a&n},bllsZ:t(1991),cKITD:function(a,n){return a(n)},EAmof:function(a,n){return a&n},qKpIz:function(a,n){return a!==n},ujfUo:t(1342),hqLQe:function(a,n){return a(n)},lImmu:function(a,n){return a&n},BONFl:t(1672),ukpKu:function(a,n){return a(n)},kwbHV:function(a,n){return a<<n},QaNyU:function(a,n){return a&n},dqkNW:function(a,n){return a!==n},HpVeH:"alBsT",iCEqU:t(732),cEvBB:function(a,n){return a&n},XQqgw:function(a,n){return a&n},ypVdO:function(a,n){return a<<n},XuSUY:t(1718),vgRNu:t(1663),NxTyC:function(a,n){return a&n},TJusc:function(a,n){return a!==n},QxLRW:"SyIKz",hVxBk:function(a,n){return a&n},ghJVP:function(a,n){return a|n},YPajw:function(a,n){return a>>>n},ipFmS:function(a,n){return a>>>n},ZzXls:function(a,n){return a|n},gugxt:function(a,n){return a<<n},BEiuO:function(a,n){return a===n},vsHBP:function(a,n){return a<n},AddUd:function(a,n){return a<n},MfXJr:function(a,n){return a<n},vIJGi:function(a,n,s){return a(n,s)},OVNQA:function(a,n){return a+n},WSeUO:function(a,n){return a&n},afhlD:function(a,n){return a!==n},QKecK:function(a,n){return a+n},tUsVt:function(a,n){return a|n},USoHB:function(a,n){return a>>>n},hBoLw:function(a,n){return a>>>n},nNeSg:function(a,n){return a>>>n},pjXlH:function(a,n){return a>>>n},DLNMk:function(a,n){return a|n},ZkhQs:function(a,n){return a+n},BUSSw:function(a,n){return a!==n},BJKZO:function(a,n){return a|n},YICeD:function(a,n){return a>>>n},PNLFg:function(a,n){return a&n},JqFRR:function(a,n){return a|n},pPHZO:function(a,n){return a&n},HVCbD:function(a,n){return a>>>n},MKZEs:function(a,n){return a>>>n},oLpGo:function(a,n){return a>>>n},kypsJ:function(a,n){return a!==n},pEtVs:function(a,n){return a|n},gudob:function(a,n){return a|n},SQoPG:function(a,n){return a<<n},HKhBq:function(a,n){return a|n},ULmjm:function(a,n){return a<<n},AmwEm:function(a,n){return a|n},rYLAh:function(a,n){return a|n},YTvSt:function(a,n){return a<<n},yDZxb:function(a,n){return a===n},fxQAe:function(a,n){return a|n},fLSUx:function(a,n){return a<<n},RHfjW:function(a,n){return a|n},bTMJZ:function(a,n){return a<<n},qENMR:function(a,n){return a>>>n},PKhep:function(a,n){return a>>>n},vVNdo:function(a,n){return a%n},niIiQ:function(a,n){return a|n},AXGSc:function(a,n){return a/n},xIIdm:"PKIWB",USCBV:function(a,n){return a*n},gIMRE:function(a,n){return a(n)},btjVK:t(797),AYJkr:function(a,n){return a===n},iJKCL:function(a,n){return a===n},smFkH:function(a,n){return a&n},gJJVy:function(a,n){return a&n},JPMxi:function(a,n){return a+n},oAGGR:function(a,n){return a>>>n},SFTxO:function(a,n){return a>>>n},EMQPU:function(a,n){return a>>>n},QosVs:function(a,n){return a+n},QOFDA:function(a,n){return a|n},zNQMp:t(642)+t(1509),agxbe:t(642)+t(888)+t(2098),yPoyE:t(1464),lmfYA:function(a,n){return a===n},eXyGb:function(a,n){return a===n},oQVLP:function(a,n){return a===n},Otmkv:function(a,n){return a+n},ZHUMG:"AbortError",oIRFc:"complete",MyXBO:t(1767),BwYLK:function(a,n){return a&n},hDKlf:function(a,n){return a&n},VFBuq:function(a,n){return a&n},MMtMb:function(a,n){return a>>>n},wpghT:function(a,n){return a&n},ZpAVg:t(1132)+t(1138),RIMBN:t(1571)+t(604),tReJf:t(1276)+t(507)+"R",RTQDh:"MESSAGE_"+t(1947),CRfeY:t(1733)+"OR",ifmZb:function(a,n){return a(n)},InTaz:function(a,n){return a&n},ldWlK:function(a,n){return a&n},hpRnm:function(a,n){return a&n},CWfCb:t(1221),NhTBB:t(509),BSGyi:t(1424),snaUl:"bye",munJA:t(501)+t(790)+t(1158)+t(1157),MPbzX:function(a,n){return a!==n},kvZeJ:"jLVGG",wWVTt:function(a,n){return a>n},fiFPM:t(606)+t(1869)+" reconnect",oXstj:function(a,n){return a!==n},GiiEs:t(1797),zCQPD:t(1242),BodGG:t(808),SeNUc:function(a,n){return a===n},csKvz:function(a,n){return a===n},ifZZq:"rixqP",JWzZS:function(a,n){return a(n)},ZoCGM:t(708),ZxJie:function(a,n){return a===n},EUOgM:function(a,n){return a+n},JyoLg:t(1446)+t(1906),VWASI:function(a,n,s){return a(n,s)},DVyFK:function(a,n){return a===n},ckFWG:function(a,n){return a===n},roOZh:function(a,n){return a!==n},IzkgH:t(978),QDCYJ:function(a,n,s){return a(n,s)},bRDeQ:t(1999),rzKJT:t(1891),sDYdu:function(a,n,s){return a(n,s)},DECEz:function(a,n){return a===n},bxLED:"iwIaq",ZZIdm:function(a,n,s){return a(n,s)},MguEc:t(734),AEbki:function(a,n,s){return a(n,s)},oHbBN:t(895),BWsHv:function(a,n){return a instanceof n},xRTAC:function(a,n){return a+n},UrmHG:function(a,n){return a<=n},QgyFG:function(a,n){return a+n},WASEP:function(a,n){return a-n},lBCjm:function(a,n){return a+n},bAlzp:function(a,n){return a<<n},EowLP:t(985),THrzw:t(526)+"1",zzbtr:t(953),zmNtV:t(1523),WWoup:function(a,n){return a(n)},CBzuS:t(1268),OEkpW:t(1613),fhYTu:function(a,n){return a!=n},htfcA:"undefined",jYpvC:function(a,n){return a<=n},QEYNs:function(a,n){return a===n},mFnve:function(a,n){return a<n},nEyCw:function(a,n){return a===n},qLCVx:function(a,n){return a===n},XtMIp:function(a,n){return a&n},YKxGN:function(a,n){return a<n},HEMNW:function(a,n){return a-n},CRJPp:function(a,n){return a<n},kQWNM:function(a,n){return a&n},bWBsm:function(a,n){return a&n},FdlUM:function(a,n){return a>=n},VYgDG:function(a,n){return a<n},MHbGi:function(a,n){return a|n},tWNpb:function(a,n){return a>=n},CuSjx:function(a,n){return a&n},DStyE:function(a,n){return a&n},CYDwZ:function(a,n){return a&n},Ianrh:function(a,n){return a>>n},KPTvH:function(a,n){return a+n},BbxLg:function(a,n){return a&n},GhYzp:function(a,n){return a>>n},SNeau:function(a,n){return a===n},UQgAm:function(a,n){return a&n},NDTNW:"4|2|1|0|"+t(1759),juJjH:function(a,n){return a>>n},CakvD:function(a,n){return a|n},dLJYM:function(a,n){return a<<n},dKjgF:function(a,n){return a>>n},yCMlZ:function(a,n){return a|n},iHTGY:function(a,n){return a>>n},gPdKv:function(a,n){return a|n},xqgyo:function(a,n){return a||n},wyDkx:function(a,n){return a==n},HYNSK:t(767),DLysr:t(662),fcRDX:function(a,n){return a===n},tqDRg:t(1615),YSGWT:function(a,n){return a!=n},Acxxr:t(1896),Auxta:function(a,n){return a instanceof n},EmjiK:function(a,n){return a instanceof n},DMXeo:function(a,n){return a!=n},Hshzi:t(944)+t(1662),DjdWd:t(1478)+"in;chars"+t(1314),uMJaK:function(a,n,s){return a(n,s)},mYCzi:t(470),ytfwG:t(925),IdFOK:t(1946),zhPbr:function(a,n,s){return a(n,s)},HzSYB:t(1153),QTPUw:t(1879),HlqXf:function(a,n){return a(n)},LVMho:t(1776)+t(621),ZcIly:t(1931),Wzldy:t(1146)+"ascript",KHUOe:t(1046)+t(1600)+t(1534)+"P",ILgUU:t(1574),AqZdi:function(a,n){return a===n},VLoNr:t(1735),JpHBz:t(1680),CNSkj:function(a){return a()},QpDDG:function(a,n){return a(n)},vCYWB:function(a,n){return a===n},xPTSD:"PRhDS",BQoEo:"reconnect",rZsJs:t(1518),eQfrM:t(1895),JoFuK:t(1601),RoWwf:"UrJlz",PzdZV:function(a,n){return a<n},HujXf:function(a,n){return a!==n},uXTLu:function(a,n){return a-n},WoAIQ:"Riorj",WuYDf:function(a,n){return a(n)},KBnBB:function(a,n){return a===n},xJqsw:t(1736),ehAdb:t(548),YdBwd:"message_id",wQsvR:"kgUcB",NIOnf:function(a,n){return a||n},VAaAc:function(a,n){return a||n},RAiou:function(a,n){return a||n},EHSCw:t(1644),WzJGZ:function(a,n){return a===n},xLGLZ:t(1396),KuIXv:function(a,n){return a||n},JcxVl:function(a,n){return a!=n},yVZuA:t(1645)+"DB failed",iiwqq:function(a,n){return a>>>n},CIqVQ:function(a,n){return a>>>n},umfts:function(a,n){return a!==n},izMvb:t(1633),BnowQ:t(1269),paWIT:function(a,n){return a===n},nsoFl:t(1621),GqRNP:function(a,n){return a(n)},djqOe:function(a,n){return a+n},xJKqr:function(a,n){return a>>n},xqcBa:function(a,n){return a|n},iRhOi:function(a,n){return a!==n},vXvys:t(2015),XYeqo:"YcJRW",nXmHN:function(a,n){return a(n)},vojlY:function(a){return a()},eRVar:t(1665),VxGpx:t(1444),Mhysk:function(a,n,s,d){return a(n,s,d)},GbUvo:t(642)+t(878)+"k",VCxKj:t(1715),VzdnA:function(a,n){return a>>>n},UEjsN:function(a,n){return a>>>n},litsH:function(a,n){return a>>>n},FRZEx:function(a,n){return a(n)},sDXjB:function(a,n){return a(n)},VYttE:function(a,n){return a(n)},FgAhl:t(1162),ophQh:function(a,n){return a instanceof n},FXUmB:"applicat"+t(1662)+t(1907)+"=utf-8",TGpJD:function(a,n,s,d){return a(n,s,d)},TMhod:"aSCnj",QJAgF:function(a,n){return a!==n},NbyWF:t(1603),wCzIs:function(a,n){return a|n},iGcYZ:function(a,n){return a||n},mVosC:function(a,n){return a+n},CAOtS:function(a,n){return a+n},pVuRV:function(a,n){return a+n},mCHtw:t(941)+t(698)+"ge: ",gvrhl:t(696),fLIAp:" > ",FMIJm:t(2057)+t(1292)+"e",QLyyM:function(a,n){return a===n},VoQuL:t(1390),eHIZr:function(a,n,s,d){return a(n,s,d)},sojoI:function(a,n){return a+n},DHGgd:function(a,n){return a<n},GSyqf:function(a,n){return a>>>n},rlVOg:function(a,n){return a<<n},VdPoS:function(a,n){return a|n},RMyxz:function(a,n){return a&n},YUYfn:function(a,n){return a|n},OsZbC:function(a,n){return a&n},oggzC:t(513),klunZ:function(a,n){return a<n},GzlON:function(a,n){return a+n},qOWdX:function(a,n,s){return a(n,s)},cgaUp:t(1555),EcqPm:function(a,n){return a|n},ZoxjT:function(a,n){return a|n},RQTvb:function(a,n){return a|n},BGTOT:function(a,n){return a<<n},okoAI:function(a,n){return a+n},NiEIF:function(a,n){return a+n},TAyay:function(a,n){return a+n},TsKqD:function(a,n){return a+n},SoRVv:function(a,n){return a|n},FiMUl:function(a,n){return a|n},bDztl:function(a,n){return a<<n},vpmtj:function(a,n){return a<<n},TEgIR:function(a,n){return a+n},lWZUR:function(a,n){return a+n},ydBnC:function(a,n){return a>>>n},GVwlT:function(a,n){return a&n},olQFs:function(a,n){return a+n},QZJOt:function(a,n){return a&n},nvuSy:function(a,n){return a+n},EAMGN:function(a,n){return a>>>n},JvYOd:function(a,n){return a&n},tqyxX:function(a,n){return a>>>n},kZAhs:function(a,n){return a+n},GFiDX:function(a,n){return a|n},Nnyps:function(a,n){return a<<n},OcRNR:function(a,n){return a&n},bfGwF:function(a,n){return a|n},ObdbY:function(a,n){return a<<n},TIZvj:function(a,n){return a&n},xuHfd:function(a,n){return a>>>n},gEePJ:function(a,n){return a<n},SoOMV:function(a,n){return a>>>n},cTxca:function(a,n){return a&n},vYiqc:function(a,n){return a<n},RrPPS:function(a,n){return a|n},jRpgx:function(a,n){return a>n},aKOPN:function(a,n){return a<n},AcAtE:function(a,n){return a(n)},IzfrT:function(a,n){return a+n},pQunc:"cursor.s"+t(1374),thZMK:"header",triPx:t(730)+t(1531),tPSPP:t(1531),hkyBO:"curvalue",JYPZg:"cursor_f"+t(1801),Wcuiv:function(a,n,s){return a(n,s)},sIILp:function(a,n,s,d){return a(n,s,d)},yQNrC:function(a,n){return a!=n},FeQoA:function(a,n){return a!==n},NXJaf:t(733),gjVWg:"FILE_NOT"+t(508),zJUkg:"cursor_n"+t(1583),DYwFI:t(2109)+t(751),GDiZj:"ALL",FePSN:function(a,n,s,d){return a(n,s,d)},ZNtdu:t(1533),AKMvw:t(1917),BdCvT:function(a){return a()},FUzuX:function(a,n,s){return a(n,s)},vvwbu:t(959),YyyLh:function(a,n){return a instanceof n},hDGrY:function(a,n){return a(n)},spAjX:"JSWuW",sZhFQ:t(1629),qPBGI:"kntyY",CrBsq:t(1841)+"r",oexIV:function(a,n){return a===n},tAann:t(710),TRbCM:function(a,n){return a||n},VXqce:t(1719),BljQA:function(a,n,s){return a(n,s)},UQtEO:t(642)+t(1300),LsaeG:t(2074)+"s",oRQGw:t(1989)+t(1885)+"e",bEEjD:function(a){return a()},CQQLi:function(a,n){return a>n},paADF:function(a,n){return a===n},asyKz:t(1973),AFIix:function(a,n){return a+n},sLftj:t(871),aDGQM:function(a){return a()},LEwqX:function(a){return a()},fuXUy:function(a){return a()},tRRcW:t(2031),krIHq:function(a){return a()},xugVC:function(a,n){return a&&n},yeaPn:function(a,n){return a(n)},PxjKz:function(a,n,s){return a(n,s)},emsTo:t(1661),FfytK:function(a,n){return a<n},oaZyH:function(a,n,s){return a(n,s)},BdDkL:function(a){return a()},fPcHe:function(a,n){return a|n},FryUt:function(a,n){return a+n},pFOBz:function(a,n){return a+n},BdOUD:t(2e3),WSmqw:t(1831)+t(1261)+"|7|4|6",HwqgO:function(a,n){return a!==n},Dqges:t(1380),ZbuGx:function(a,n){return a===n},rEMMh:t(1115),CNzXH:t(1936),gvmeb:function(a,n){return a===n},nXPnm:function(a,n,s,d){return a(n,s,d)},YLzjO:t(1584),EaZiN:function(a,n){return a===n},mZKyT:function(a,n,s){return a(n,s)},DufEu:function(a,n){return a===n},QCOwB:function(a,n,s,d){return a(n,s,d)},RKJsa:function(a,n,s){return a(n,s)},kgKCQ:function(a,n){return a>=n},gPGMa:t(2105),mBXcL:t(622),HWPiB:function(a,n){return a!==n},trKff:t(1562),rEotC:function(a,n){return a===n},pTYrH:"please provide v"+t(1405),iuHhf:t(551)+t(1654)+t(593)+", WebSoc"+t(2089)+t(2092)+t(806)+t(2100),zpZcV:"XWozD",MegCk:t(1537),ncbpZ:t(1117),egYnT:t(964),DqqIW:t(499),selMk:function(a,n){return a!==n},RbSWH:"https:",PWBsL:t(820),akXCI:t(1058),pUErC:t(1412),rLBgP:"device_id",qQCqw:t(551)+t(1454)+t(2093)+"viceID o"+t(563),sFLPo:function(a,n){return a==n},epIKg:function(a){return a()},NnMeD:function(a,n,s){return a(n,s)},zKVrO:"web",qqRRD:t(556)+"0",mTLSK:function(a,n){return a!==n},JrtXR:"fMxuA",ATKLy:t(1489),HQILU:function(a,n,s){return a(n,s)},KCWzp:function(a,n){return a===n},INHgD:t(1116),hNZhz:function(a,n){return a>n},RccOP:function(a,n,s){return a(n,s)},DeKBy:function(a,n,s){return a(n,s)},zvXGO:"oqBci",qyewb:"FRONTIER>",awZie:function(a,n){return a===n},AaaYH:function(a,n,s){return a(n,s)},dQPZT:t(501)+t(960)+t(661)+t(1832)+t(575),aLRbY:function(a,n,s){return a(n,s)},TOqfY:t(921),pBWZL:t(816)+"1",QMvxh:function(a,n,s){return a(n,s)},FmPrG:t(1968),NsFFT:t(1943),nRNEW:function(a,n,s){return a(n,s)},IltVs:t(830),jTDfu:t(838),YRIiL:t(1637),YQoPX:function(a,n){return a<n},NOjlN:function(a,n){return a|n},EmRXD:function(a,n){return a&n},OiUii:t(1481),rHZgv:t(1684),PfCvD:function(a,n){return a+n},EErdJ:function(a,n){return a===n},TooUs:function(a,n){return a instanceof n},YhAQs:function(a,n){return a+n},wYqfv:t(1364),TkQOa:t(735),VEGPh:"6|2|1|0|"+t(1228),giTEd:t(818)+"s instan"+t(1635)+t(2023)+"ed",dYMcG:"close, w"+t(1069)+t(1060),QYSjW:function(a,n){return a==n},jzeSZ:t(551)+"rovide a"+t(844)+t(1607)+t(1021)+t(634)+"ng or an"+t(1189)+t(874),XzDiq:t(495),tYJeD:"BKuuM",FDwsD:function(a,n){return a||n},zpXjt:function(a,n){return a!==n},EEkpv:t(1257)+t(1732)+t(938),FIhLQ:t(1867)+"4",KHLSd:function(a,n){return a-n},EWhJe:function(a,n){return a<n},Sxhwa:function(a,n){return a|n},UKtiU:function(a,n){return a<<n},mOrzR:function(a,n){return a&n},dbxLm:function(a,n){return a&n},uAhyC:function(a,n){return a>=n},iNkUj:function(a,n){return a|n},TeADY:function(a,n){return a|n},vuEpX:function(a,n){return a<<n},igLOP:function(a,n){return a<<n},WANBY:function(a,n){return a&n},ExKBz:function(a,n){return a<<n},TDGoM:function(a,n){return a<<n},fLRhJ:function(a,n){return a&n},xjJIB:function(a,n){return a===n},uapds:t(1554),Eccge:t(722),jHcBw:function(a,n){return a||n},WLkOo:"IiIDL",qcdlS:"ping_onc"+t(1691)+"t",cdkNh:"\0\0\0\0\0\0\0\0",uzlVu:function(a,n){return a*n},tUMMH:function(a,n){return a/n},WLptO:function(a,n){return a!=n},fzMKx:"Window",UeryV:function(a,n){return a!=n},zzhHY:function(a,n){return a!=n},QZpLz:function(a,n){return a===n},WrQGn:t(688)+"dWorkerG"+t(608)+"pe",krkXW:function(a,n){return a===n},ihctn:t(898),YCWrd:function(a,n){return a==n},ziXOU:function(a,n){return a!=n},lDwUq:t(675)+"rkerGlob"+t(1475),ZmztM:function(a,n){return a===n},FyGjr:t(1817)+t(1551)+t(927),fiZnv:function(a,n){return a!=n},khDre:t(1071)+"qos__"};zt.r(Re),zt.d(Re,{FWS:()=>ig,CustomErrorEvent:()=>Xd,createCloseEvent:()=>gt,ReconnectEvent:()=>Jd,createErrorEvent:()=>lt,decodedFrame:()=>tn,createOpenEvent:()=>rl,CustomCloseEvent:()=>Yd,createReconnectEvent:()=>ha,FrontierMessageEvent:()=>el,encodeFrame:()=>Ut,createMessageEvent:()=>nl,OpenEvent:()=>tl,ErrorCode:()=>rn,Event:()=>rr,MessageEvent:()=>Qd});let r="";function i(a=""){let n=t,s="02",d=""+Date.now(),f=r||(r=e.SHsjt(x,a)),p=Math.random()[n(1914)](16)[n(738)](-6);return e[n(1217)](e.XLCFV(e.XLCFV(s,d),f),p)}function o(){let a=t,n={VNPyb:function(s,d){return e[G(1992)](s,d)},irzaH:function(s,d,f){return e[G(1541)](s,d,f)},klOIG:function(s,d){return e[G(772)](s,d)},iPytw:function(s,d){return e.RBzrz(s,d)}};if(e[a(885)](a(515),e[a(1563)])){for(_0x46a0bc>>>=0;n.VNPyb(_0xd4afda,128);)n.irzaH(_0x1d3e65,_0x386e0f,n[a(742)](n.iPytw(127,_0x4c1614),128)),_0xe22d29>>>=7;n.irzaH(_0xe4189d,_0x2611e8,_0x2ce057)}else return e.Znenb(1e4,Date[a(1696)]())+Math[a(1705)](e.Znenb(1e4,Math[a(821)]()))}function c(a){let n=t;return e[n(975)](e[n(765)](Array,8).join("0"),parseInt(a,10)[n(1914)](2))[n(738)](-8)}function l(a){let n=t;return(e[n(765)](Array,4)[n(2099)]("0")+e[n(1541)](parseInt,a,2)[n(1914)](16))[n(738)](-4)}function u(a){let n=t;if(e[n(1198)](e[n(934)],e[n(934)]))_0x2c2588=_0x54df33[e.shzGT(e[n(1022)](_0x11f21a,_0x26c730),1)],_0x3da382=_0xf15878[e[n(1395)](_0x197c70,_0xfb21f8)+2],e[n(700)](_0x1804fc|e[n(1282)](_0xa8a419,8),49344)!==32896?_0x5b26b0+=_0x51b9ec:(_0x1177ba=e.jlYqf(e[n(1282)](e.aXPBy(15,_0x8babd8),12)|e[n(1496)](63,_0x4efc4c)<<6,63&_0x1a68a2),e[n(1952)](_0x10ffdf,2048)||e[n(1992)](_0x342815,55296)&&e.oUEmt(_0x41760c,57343)?_0x1faf0c+=_0x1194c8:(_0x485965+=e.rxoBo(_0x3ecb1a,_0x11831b),_0x460220+=2));else{let s=a[n(852)](/\./)[n(955)](p=>c(p)),d=[];return d[0]=e[n(1883)](l,s[0]+s[1]),d[1]=e[n(653)](l,s[2]+s[3]),[e.wjLTk,e[n(1862)],e[n(1862)],n(1003),n(1003),n(1339),d[0],d[1]][n(2099)]("")}}function x(a){let n=t;if(e[n(1416)](e.uALcO,e[n(1167)]))try{e[n(1398)](_0x4fe599,this,_0x5e6778,[_0x59b00d,_0x181984,_0x12e26b])}catch(s){let d=e.MFPaJ(_0x41e257,e[n(729)],{message:s[n(1891)],code:_0x3ac50c.OPEN_ERROR,error:s});this[n(552)+"hErrorEv"+n(1970)](d)}else{let s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[n(1218)](a),d=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[n(1218)](a);return s?e[n(1414)](u,a):d?e[n(1019)](h,a):e[n(1611)]}}function h(a){let n=t,s="",d=[],f=0,p=0,w=!0,b=e[n(1862)];if(a[n(1950)]("::")>-1){let g=a[n(852)]("::");for(let R=0;e[n(2101)](R,g.length);R++){let P=g[R];if(e[n(1211)](P[n(1950)](":"),0)){let F=P[n(852)](":");w&&(f=F[n(1360)]),p+=F[n(1360)];for(let B=0;e[n(1952)](B,F[n(1360)]);B++)if(e[n(677)](4,F[B][n(1360)])){let te=b[n(1646)+"g"](0,4-F[B][n(1360)]),J=te[n(943)](F[B]);d[n(911)](J)}else d.push(F[B]);w=!1}else{if(P[n(1360)]!==4){let F=b[n(1646)+"g"](0,e[n(674)](4,P.length)),B=F[n(943)](P);d[n(911)](B)}else d[n(911)](P);w&&(f+=1),p+=1,w=!1}}let C="";for(let R=0;e[n(1952)](R,8-p);R++)C=C[n(943)](b);for(let R=0;e.OmNoc(R,d[n(1360)]);R++)if(e[n(1688)](R,f))if(e[n(1416)](e.ELlrP,"aPypf"))s=s[n(943)](C),s=s[n(943)](d[R]);else{let P=e.nZunV(255,_0x4e3a35);e[n(1398)](_0x3930e0,P,_0x129aeb,_0x249d7f+_0x3216c6),_0x31d96e>>>=8,_0x4627d8--}else s=s.concat(d[R]);return s}if(e[n(1760)]!==e[n(1953)]){let g=a[n(852)](":");for(let C=0;e[n(1952)](C,g[n(1360)]);C++){if(e[n(1198)](e[n(707)],e[n(707)]))return e[n(2056)](_0x2e7333,_0x566855)?_0x8d629b[n(1997)](new _0x54050f(e.DPpfg)):(_0x31f87f=_0x56462f,e.MwgOp(_0x4ae4d8,_0x47129c[n(1360)])?_0x5843c5[n(1818)]():_0x3d4bb9[_0x4f9720].bind(_0x4c9340)(_0x4b0d52,_0x21dc7c[n(1640)](null,_0x9d02be+1)));{let R=g[C];if(e[n(1550)](4,g[C][n(1360)])){let P=b[n(1646)+"g"](0,4-g[C][n(1360)]),F=P[n(943)](R);s=s[n(943)](F)}else s=s[n(943)](R)}}return s}else _0x1df409.d=(g,C)=>{let R=n;for(var P in C)_0x334d01.o(C,P)&&!_0x6c3ae1.o(g,P)&&_0x4ae4bc[R(516)+R(2038)](g,P,{enumerable:!0,get:C[P]})}}function m(a,n){let s=t,d=a[s(1863)];e.FaXqh(void 0,d)&&(e[s(1541)](pe,n,10),e[s(753)](j,n,d));let f=a[s(1053)];e[s(533)](void 0,f)&&(e.iWjBm(pe,n,18),e[s(753)](j,n,f))}function E(a){let n=t,s={};e:for(;!e.zFIPo(V,a);){let d=e[n(765)](he,a);switch(e.BGnDB(d,3)){case 0:break e;case 1:s[n(1863)]=N(a,e[n(834)](he,a));break;case 2:s[n(1053)]=N(a,e.FFOGU(he,a));break;default:e[n(1541)](D,a,7&d)}}if(s[n(1863)]===void 0)throw new Error(n(987)+n(1185)+" field: "+n(1863));if(e[n(1617)](void 0,s[n(1053)]))throw new Error(e[n(1521)]);return s}function S(a){let n=t,s=e.oYunc(k);return e[n(1094)](_,a,s),e[n(1630)](z,s)}function _(a,n){let s=t,d={wEeDg:function(Pe,Oe){return e.BxqUd(Pe,Oe)},kRBbX:e[s(2086)],KaFhm:e[s(2043)],oEvyC:"ping_onc"+s(1691)+"t"},f=a[s(727)];f!==void 0&&(e[s(794)](pe,n,8),e.Ukkzr(pt,n,f));let p=a[s(759)];e.FaXqh(void 0,p)&&(pe(n,16),e[s(1541)](pt,n,p));let w=a[s(2022)];e.FaXqh(void 0,w)&&(e[s(1750)](pe,n,24),e[s(923)](pt,n,O(w)));let b=a.method;if(e[s(724)](void 0,b))if(e[s(1816)](e.VrciG,s(1704))){let Pe=_0x5211b9[s(1646)+"g"](0,e[s(1972)](4,_0x341c4e[_0x3dea72][s(1360)])),Oe=Pe[s(943)](_0x53e38d[_0x3fffee]);_0x2d3b7c.push(Oe)}else pe(n,32),e[s(530)](pt,n,O(b));let g=a.headers;if(g!==void 0)for(let Pe of g){e[s(1231)](pe,n,42);let Oe=e.nnviR(k);m(Pe,Oe),e[s(1762)](pe,n,Oe[s(837)]),e.dTQgm($,n,Oe),e[s(800)](L,Oe)}let C=a["payloadE"+s(532)];e[s(1191)](void 0,C)&&(e.iFZCT(e[s(1382)],e[s(1223)])?(this["_navigat"+s(586)]()&&(!this[s(1279)]||e[s(1093)](this._ws[s(1040)+"te"],this.OPEN)||e[s(1550)](this[s(1279)][s(1040)+"te"],this.CONNECTING))&&this[s(1593)+"nLine"](),this[s(1894)+"er"]&&_0x448d32[s(1892)+s(1923)](s(1537),this["_handleO"+s(922)]),this._isBrowser&&_0x30630f[s(1892)+s(1923)](e.qEUjN,this[s(1593)+"ffLine"])):(e[s(1750)](pe,n,50),e[s(1194)](j,n,C)));let R=a[s(1788)+s(1256)];e.XvkPb(void 0,R)&&(pe(n,58),j(n,R));let P=a.payload;e[s(1994)](void 0,P)&&(e[s(2046)](pe,n,66),e[s(794)](pe,n,P[s(1360)]),e[s(476)](ae,n,P));let F=a[s(1064)];if(e[s(670)](void 0,F))if(e[s(1013)](e[s(2080)],e.lTUBm))e[s(1293)](pe,n,74),e[s(1773)](j,n,F);else{let Pe={VUeHo:function(Oe,on){return e[s(1883)](Oe,on)},UdmxK:e[s(2042)],nnprj:e.aidhI};return new _0x4bc2c1((Oe,on)=>{let Ke=s,ls={ulUZF:function(ze,ni){return d[G(1634)](ze,ni)},STPLp:d[Ke(1786)]};this[Ke(988)+"ngTimer"](),this[Ke(656)+Ke(1577)+"Id"]=_0x30eaee(this[Ke(926)][Ke(1640)](this),this[Ke(531)][Ke(1606)+Ke(1378)]);let On=()=>{let ze=Ke;ls[ze(1318)](Oe,ls.STPLp),this[ze(2088)](ze(903)+ze(887)+"s",On),this[ze(2088)]("ping_onc"+ze(1691)+"t",ti)},ti=()=>{let ze=Ke;Pe[ze(2010)](on,Pe[ze(1237)]),this.off(Pe.nnprj,On),this[ze(2088)](ze(903)+ze(1691)+"t",ti)};this.on(d[Ke(1073)],On),this.on(d[Ke(778)],ti),this._ping()})}let B=a[s(1061)+s(784)];e[s(789)](void 0,B)&&(e.lQGnz(pe,n,82),j(n,B));let te=a[s(1368)];e.MLwRC(void 0,te)&&(pe(n,90),e[s(1773)](j,n,te));let J=a.frameType;e[s(1741)](void 0,J)&&(e[s(794)](pe,n,96),e.hfkNY(pt,n,e.IsuFb(O,J)))}function v(a){let n=t,s={dOzGm:"error",mSFgN:function(d,f,p){return d(f,p)},XCftc:e[n(1501)]};if(e[n(1059)](e[n(1143)],n(2013)))_0x1c48fb.resolve().then(()=>{let d=n,f=_0x511942(s[d(1284)],{message:this[d(537)+d(1403)+"age"](_0x11f36e)});this[d(1426)](s[d(1284)],f);let p=s[d(1070)](_0x2ec3b0,s.XCftc,{reason:this["_formatE"+d(1403)+d(1819)](_0x47ef54)});this[d(1426)](s.XCftc,p)});else return e[n(1090)](A,e.gExQz(U,a))}function A(a){let n=t,s={SfucP:function(d,f){return e[G(2104)](d,f)},XwlwE:function(d,f){return d>f}};if(e.TdrkI(e[n(1118)],e[n(1539)])){let d={};e:for(;!V(a);)if(e.CNkee(n(1876),e[n(2014)])){let f=e[n(940)](he,a);switch(f>>>3){case 0:break e;case 1:d[n(727)]=e[n(809)](It,a,!0);break;case 2:d[n(759)]=e[n(1145)](It,a,!0);break;case 3:d[n(2022)]=he(a);break;case 4:d[n(1085)]=e[n(823)](he,a);break;case 5:{let p=e[n(469)](I,a);(d[n(913)]||(d[n(913)]=[])).push(e.anShy(E,a)),a[n(837)]=p;break}case 6:d["payloadE"+n(532)]=N(a,e[n(1182)](he,a));break;case 7:d[n(1788)+n(1256)]=e.baNXJ(N,a,e[n(823)](he,a));break;case 8:d.payload=e[n(794)](se,a,he(a));break;case 9:d[n(1064)]=e[n(1303)](N,a,e.oKozB(he,a));break;case 10:d[n(1061)+n(784)]=N(a,e.eevib(he,a));break;case 11:d[n(1368)]=e.NQTLG(N,a,he(a));break;case 12:d[n(1740)+"e"]=e.FFOGU(he,a);break;default:e[n(1442)](D,a,7&f)}}else{if(this[n(1419)+n(1150)]?.[n(1111)+n(1084)+"es"]()){let p=this._endpointManager?.[n(1882)+n(1468)+"nt"]();this[n(552)+n(2008)+n(1970)](e[n(1141)](_0x4cecdf,"close",{code:1006,reason:n(601)+p+(n(1465)+n(1905)+n(1304)+n(1248)),wasClean:!0}))}else{let p=this[n(531)][n(661)+n(1783)+n(2095)](_0x31ec44,_0x2a6e7e);this[n(552)+n(2008)+"ent"](e[n(1576)](_0x788314,"close",{code:_0x1d5936,reason:_0x4fac4c,wasClean:!0,willReconnect:p})),p&&this[n(711)]()}return}if(d.SeqID===void 0)throw new Error(e[n(1681)]);if(e[n(1416)](void 0,d.LogID))throw new Error(e[n(2021)]);if(e[n(2102)](void 0,d[n(2022)]))throw new Error(e.ZnhHW);if(e.dYVGu(void 0,d[n(1085)]))throw new Error(e.KRxUI);return d}else return s[n(546)](this[n(644)+"ndex"],this[n(761)+"s"][n(1360)])?!0:s.XwlwE(this[n(1334)+n(691)+n(1043)+"t"],this[n(2078)+"es"])}function I(a){let n=t,s=e.SPfWx(he,a),d=a.limit;return a[n(837)]=e[n(1417)](a[n(1717)],s),d}function D(a,n){let s=t;switch(n){case 0:for(;e.KnsXM(128,e[s(1190)](oe,a)););break;case 2:Z(a,e[s(813)](he,a));break;case 5:e[s(1750)](Z,a,4);break;case 1:e.KyxXW(Z,a,8);break;default:throw new Error(e[s(1544)]+n)}}function O(a){return a|=0,{low:a,high:e.jYhOf(a,31),unsigned:a>=0}}let y=[];function k(){let a=t,n=y.pop();return n?(n.offset=n[a(837)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function L(a){let n=t;if(e[n(1741)](e[n(524)],e[n(1341)]))y[n(911)](a);else return!!this._qosDB}function U(a){return{bytes:a,offset:0,limit:a[t(1360)]}}function z(a){let n=t,s=a[n(1913)],d=a.limit;return s[n(1360)]===d?s:s[n(2111)](0,d)}function Z(a,n){let s=t;if(e[s(1211)](e[s(975)](a[s(1717)],n),a.limit))throw new Error(e[s(1384)]);a[s(1717)]+=n}function V(a){let n=t;return e[n(1033)](a[n(1717)],a[n(837)])}function ne(a,n){let s=t;if(s(702)!==e[s(1798)]){let d=a[s(1913)],f=a[s(1717)],p=a.limit,w=e.XLCFV(f,n);if(e[s(1211)](w,d.length)){let b=new Uint8Array(2*w);b[s(1830)](d),a.bytes=b}return a[s(1717)]=w,w>p&&(a[s(837)]=w),f}else _0xc177da(_0x51fe43,74),e.Muakz(_0x113529,_0x2124ee,_0x1e9381)}function X(a,n){let s=t,d=a[s(1717)];if(e[s(1259)](e.Cilhu(d,n),a[s(837)]))throw new Error(s(1210)+"t limit");return a[s(1717)]+=n,d}function se(a,n){let s=t;if(e[s(1688)](e[s(1820)],e[s(1429)]))e[s(1541)](_0x33be00,_0x38ba7f,82),_0x111a4f(_0x3a910a,_0x483116);else{let d=X(a,n);return a[s(1913)][s(2111)](d,e.lsaIC(d,n))}}function ae(a,n){let s=t,d=e[s(1441)](ne,a,n.length);a[s(1913)].set(n,d)}function N(a,n){let s=t,d=e[s(1442)](X,a,n),f=String[s(2120)+s(2004)],p=a.bytes,w="\uFFFD",b="";for(let g=0;e[s(612)](g,n);g++){let C=p[e[s(484)](g,d)],R,P,F,B;e[s(2055)](e[s(1559)](128,C),0)?b+=e.oKozB(f,C):e.VrKqm(224&C,192)?e[s(1033)](e[s(2067)](g,1),n)?b+=w:(R=p[e.Cilhu(g+d,1)],e[s(1557)](192,R)!==128?b+=w:(B=e[s(1569)](e[s(873)](e[s(1485)](31,C),6),e[s(646)](63,R)),e[s(612)](B,128)?b+=w:(b+=e[s(1254)](f,B),g++))):e.IRcuk(240&C,224)?e[s(2018)](g,2)>=n?b+=w:(R=p[e.kZjGf(e.mCEvA(g,d),1)],P=p[e[s(1217)](g+d,2)],e[s(1191)](e.psRaw(e[s(772)](R,e[s(1859)](P,8)),49344),32896)?b+=w:(B=e[s(2027)](e.BZGiS(e.psRaw(15,C),12)|e[s(1282)](63&R,6),e[s(540)](63,P)),e.FXrsn(B,2048)||e[s(1992)](B,55296)&&B<=57343?b+=w:(b+=e[s(1711)](f,B),g+=2))):e[s(1903)](248,C)==240?e[s(1022)](g,3)>=n?b+=w:(R=p[e[s(1395)](g+d,1)],P=p[e[s(680)](e[s(484)](g,d),2)],F=p[e.cWCrN(g,d)+3],e[s(486)](e[s(1903)](e[s(1569)](R,e[s(1282)](P,8))|e[s(1859)](F,16),12632256),8421504)?b+=w:(B=e[s(588)](e[s(543)](e[s(581)](7&C,18)|e[s(1282)](e[s(591)](63,R),12),e[s(1859)](e[s(1573)](63,P),6)),63&F),B<65536||e[s(512)](B,1114111)?b+=w:(B-=65536,b+=e.cEKdx(f,e.kZjGf(e[s(491)](B,10),55296),e.kSbKN(e[s(1903)](1023,B),56320)),g+=3))):b+=w}return b}function j(a,n){let s=t,d=n[s(1360)],f=0;for(let b=0;e[s(1401)](b,d);b++){let g=n[s(1250)+"At"](b);g>=55296&&e[s(748)](g,56319)&&e[s(1467)](b,1)<d&&(g=e[s(1972)](e[s(2067)](g<<10,n[s(1250)+"At"](++b)),56613888)),f+=e[s(1952)](g,128)?1:e[s(1952)](g,2048)?2:e[s(1952)](g,65536)?3:4}pe(a,f);let p=e[s(1020)](ne,a,f),w=a[s(1913)];for(let b=0;e[s(1401)](b,d);b++){let g=n[s(1250)+"At"](b);e.XsCXC(g,55296)&&e[s(896)](g,56319)&&e[s(1952)](e[s(1582)](b,1),d)&&(g=e[s(1373)](e[s(1394)](e[s(1683)](g,10),n.charCodeAt(++b)),56613888)),g<128?w[p++]=g:e.DhXsg(s(1017),e[s(976)])?(e[s(1952)](g,2048)?w[p++]=e[s(2050)](g>>6,31)|192:(g<65536?w[p++]=e.evsBQ(g>>12,15)|224:(w[p++]=e[s(952)](e[s(1078)](g,18)&7,240),w[p++]=e[s(1569)](e.KHQwO(e[s(1522)](g,12),63),128)),w[p++]=e.zLdgx(e[s(1903)](g>>6,63),128)),w[p++]=e[s(1485)](63,g)|128):(this[s(552)+s(471)+s(1712)](_0x50e343),_0x56ccc2.set(_0x8908c6,_0x3f18fb,_0x37fa60[s(1891)][s(2022)]))}}function $(a,n){let s=t,d=e.suFCJ(ne,a,n[s(837)]),f=a.bytes,p=n[s(1913)];for(let w=0,b=n[s(837)];e[s(1930)](w,b);w++)f[e[s(686)](w,d)]=p[w]}function oe(a){return a[t(1913)][e.daCFq(X,a,1)]}function Qe(a,n){let s=t,d=e[s(1442)](ne,a,1);a[s(1913)][d]=n}function he(a){let n=t,s={wCYek:function(d,f){return e.zLdgx(d,f)},nLsuE:function(d,f){return d|f},aXILI:function(d,f){return e.DgUkt(d,f)},SmcjS:function(d,f){return e[G(772)](d,f)},CpbPj:function(d,f){return d<<f},oUEwE:function(d,f){return e[G(1683)](d,f)},VzbDp:function(d,f){return e.VWScv(d,f)}};if(e.afZyE("TjLMj",e[n(571)]))this[n(1239)]?.[n(1638)](),this._qosDB=void 0;else{let d=0,f=0,p;do{if(n(1065)!==e.BWnZe)return new _0x2712ea(s[n(1609)](s[n(1609)](s[n(630)](s[n(569)](_0x46c41b[4],24),s[n(569)](_0x4a88da[5],16)),_0x8a7541[6]<<8),_0x121c70[7]),s[n(991)](s.CpbPj(_0x3bf5d5[0],24)|s[n(1951)](_0x41bc8c[1],16)|s[n(1400)](_0x5f437f[2],8),_0x2fe209[3]),_0x427ea4);p=e.tDYPG(oe,a),e[n(485)](d,32)&&(f|=(127&p)<<d),d+=7}while(e[n(1502)](128,p));return f}}function pe(a,n){let s=t,d={pdQAy:function(f){return e.uqzls(f)}};if(e[s(885)](e[s(664)],e[s(664)])){for(n>>>=0;e[s(1726)](n,128);)if(e[s(965)]===e.baGkz){let f=this["_endpoin"+s(1150)]?.[s(1882)+"ntEndpoint"]();this[s(973)](s(2060)+f),d[s(1528)](_0x1bab8d)}else e.kyLpd(Qe,a,e[s(1599)](e[s(1485)](127,n),128)),n>>>=7;e[s(754)](Qe,a,n)}else{let f=0,p=0,w;do w=e[s(1337)](_0x4bc264,_0x1e0af5),e[s(1757)](f,32)&&(p|=e[s(1282)](127&w,f)),f+=7;while(128&w);return p}}function It(a,n){let s=t,d={jNhMx:function(f,p,w){return f(p,w)},gsZZT:e.sDcYK,hfpId:function(f,p){return e[G(1337)](f,p)},BNHFE:function(f,p){return f+p},iAxip:s(1003),FHBrb:s(1339)};if(e[s(1664)](e[s(764)],e.mCvSS)){let f=0,p=0,w=0,b;if(b=e.BrRTa(oe,a),f=e[s(1903)](127,b),e.bQQWY(128,b))if(e[s(670)](e.bllsZ,s(1267))){if(b=e[s(1605)](oe,a),f|=(127&b)<<7,e.EAmof(128,b)){if(e[s(1542)](e[s(2037)],e[s(2037)])){let g=d[s(527)](_0x2b7576,d[s(827)],{message:_0x2db6b4[s(1891)],code:_0x5edbb4[s(1344)+"ERROR"],error:_0x1b7c34});this[s(552)+s(609)+"ent"](g)}else if(b=e[s(1104)](oe,a),f|=(127&b)<<14,e[s(876)](128,b))if(e[s(1690)]===s(1672)){if(b=e[s(1689)](oe,a),f|=e[s(638)](127&b,21),e[s(950)](128,b))if(e[s(629)](e.HpVeH,e[s(2065)])){if(b=oe(a),p=e[s(1627)](127,b),e[s(2045)](128,b)&&(b=oe(a),p|=e[s(1694)](127,b)<<7,e.tatNX(128,b)&&(b=oe(a),p|=e[s(1515)](127&b,14),e[s(591)](128,b)))){if(e.XuSUY===e[s(872)])return e.Cilhu(e[s(1135)](_0x3de964,8)[s(2099)]("0"),e[s(1762)](_0x1e7192,_0x53b4ea,10).toString(2)).slice(-8);if(b=e[s(813)](oe,a),p|=e[s(1282)](e.NxTyC(127,b),21),e.psRaw(128,b)&&(b=e.CZFXl(oe,a),w=e.hhYsa(127,b),e.tatNX(128,b)))if(e[s(1971)](e[s(635)],s(666)))b=e[s(1414)](oe,a),w|=e.hVxBk(127,b)<<7;else{let g={svdFK:e[s(1200)],WfLVs:function(R,P){return e[s(979)](R,P)},KIHgv:function(R,P){return e[s(1573)](R,P)},MtVpA:function(R,P){return e.BGnDB(R,P)},gAeVS:function(R,P){return R|P},NsJFk:function(R,P){return R<<P},eenSq:function(R,P){return e[s(617)](R,P)},VoVTJ:function(R,P){return R<P},WtZXj:function(R,P){return e[s(1091)](R,P)},MFgOj:function(R,P){return e[s(540)](R,P)},qNcEg:function(R,P){return e[s(1599)](R,P)},BMgUp:function(R,P){return e[s(2050)](R,P)},mlHSH:function(R,P){return e[s(772)](R,P)},lSNxH:function(R,P){return e[s(1401)](R,P)}},C=4294967295;return function(R,P,F=!0){let B=s,te=g.svdFK[B(852)]("|"),J=0;for(;;){switch(te[J++]){case"0":C=g[B(1848)](g[B(1553)](127,R[P]),0);continue;case"1":C=g.MtVpA(g[B(1990)](C,g[B(1667)](g[B(502)](127,R[P]),14)),0);continue;case"2":if(g.VoVTJ(R[P++],128))return{value:F?C:g[B(1990)](0,C),offset:P};continue;case"3":C=g[B(2049)](C|g[B(1667)](g[B(502)](127,R[P]),21),0);continue;case"4":if((P+=5)>R.length)throw P=R[B(1360)],_0x31fa92(P,10,R[B(1360)]);continue;case"5":if(R[P++]<128)return{value:F?C:g[B(1990)](0,C),offset:P};continue;case"6":if(R[P++]<128)return{value:F?C:g.gAeVS(0,C),offset:P};continue;case"7":C=g[B(1811)](C|g[B(1667)](g.MFgOj(15,R[P]),28),0);continue;case"8":if(R[P++]<128)return{value:F?C:0|C,offset:P};continue;case"9":C=g[B(1086)](C,g[B(1976)](127,R[P])<<7)>>>0;continue;case"10":return{value:F?C:g.mlHSH(0,C),offset:P};case"11":if(g.lSNxH(R[P++],128))return{value:F?C:0|C,offset:P};continue}break}}}}}else _0x3d5e9c-=65536,_0x4992a4+=e[s(1441)](_0x309b6d,e[s(1394)](e.QluyR(_0x3a5041,10),55296),e[s(1217)](e[s(1903)](1023,_0x13e436),56320)),_0x5a92d8+=3}else{let{enableAutoAck:g}=this[s(531)],C=e.OCmXg(_0xa30a2b,_0x1c3d91.message[s(913)],"need_ack","1"),R=_0x35e9ae(_0x4b131c[s(1891)][s(913)],e.LZwhw,"1"),P=_0x3c6bbf.call(this,_0x4d08f6);if(e[s(2121)](g,C)){let{SeqID:F,LogID:B,service:te,LogIDNew:J,method:Pe}=_0x15edd1.message;this[s(1187)]({SeqID:F,LogID:B,LogIDNew:J,service:te,method:Pe,headers:[{key:e[s(802)],value:"1"},{key:e[s(1356)],value:e[s(1506)](J,"")},{key:e.gMTUl,value:"0"}]})}R&&!P.isQoSAck&&this[s(552)+s(1063)+s(1494)](_0x10f500),_0x2ab378()}}}else{let g=_0x4f8271.split(/\./).map(P=>_0x334aca(P)),C=[];return C[0]=NjYSIp[s(1134)](_0x389550,NjYSIp[s(1023)](g[0],g[1])),C[1]=NjYSIp[s(1134)](_0x3c1790,NjYSIp[s(1023)](g[2],g[3])),[NjYSIp.iAxip,s(1003),NjYSIp.iAxip,NjYSIp[s(1964)],NjYSIp[s(1964)],NjYSIp[s(1884)],C[0],C[1]][s(2099)]("")}return{low:e[s(858)](f,e[s(1683)](p,28)),high:e[s(543)](p>>>4,w<<24),unsigned:n}}else{let f={rzKsp:function(C,R){return e[s(1226)](C,R)},tpSAu:function(C,R){return e[s(2073)](C,R)},FALhD:function(C,R){return e[s(2067)](C,R)},RCLjC:function(C,R){return e[s(1962)](C,R)}},p=e[s(1506)](_0x1d9110,8192),w=e[s(1091)](p,1),b=null,g=p;return function(C){let R=s;if(C<1||f[R(1695)](C,w))return f.tpSAu(_0x3adea2,C);f[R(1203)](g,C)>p&&(b=f[R(596)](_0x23b8ac,p),g=0);let P=_0x196817[R(1922)](b,g,g+=C);return 7&g&&(g=f[R(1203)](f.RCLjC(7,g),1)),P}}}function pt(a,n){let s=t,d=e.YPajw(n.low,0),f=e[s(1755)](e[s(1766)](n[s(1447)]>>>28,e[s(587)](n.high,4)),0),p=e[s(525)](n[s(1245)],24),w=e[s(684)](0,p)?e[s(1617)](0,f)?e[s(1757)](d,16384)?d<128?1:2:d<2097152?3:4:e[s(485)](f,16384)?e[s(2059)](f,128)?5:6:e[s(1893)](f,2097152)?7:8:e[s(1280)](p,128)?9:10,b=e[s(1225)](ne,a,w),g=a[s(1913)];switch(w){case 10:g[e[s(1938)](b,9)]=e[s(1774)](e[s(525)](p,7),1);case 9:g[e[s(1619)](b,8)]=e[s(1275)](9,w)?128|p:e[s(1502)](127,p);case 8:g[e[s(1758)](b,7)]=e[s(533)](8,w)?e[s(1702)](f>>>21,128):e.KHQwO(e[s(1091)](f,21),127);case 7:g[e[s(2067)](b,6)]=w!==7?e[s(858)](e[s(579)](f,14),128):e[s(1477)](e[s(715)](f,14),127);case 6:g[b+5]=w!==6?e[s(1570)](e.nNeSg(f,7),128):e.pjXlH(f,7)&127;case 5:g[b+4]=w!==5?e[s(993)](128,f):127&f;case 4:g[e.ZkhQs(b,3)]=e[s(1352)](4,w)?e[s(1089)](e[s(652)](d,21),128):e.PNLFg(d>>>21,127);case 3:g[b+2]=e[s(1059)](3,w)?e[s(2039)](e[s(979)](d,14),128):e[s(1255)](e.HVCbD(d,14),127);case 2:g[e[s(1217)](b,1)]=e[s(677)](2,w)?e.MKZEs(d,7)|128:e.TGyRx(e[s(893)](d,7),127);case 1:g[b]=e[s(1608)](1,w)?e[s(858)](128,d):e[s(1485)](127,d)}}function tn(a){return e.CZFXl(v,a)}function Ut(a){return S(a)}let nn=65536,Yr=e[t(1826)],we=e.uzlVu(nn,nn),Ie=e[t(841)](we,we),nr=e.tUMMH(Ie,2),ke=String[t(1958)+"e"].charCodeAt;class xe{constructor(n,s,d){let f=t;this[f(1137)]=!0,this.low=e[f(1766)](0,n),this[f(1245)]=e[f(1962)](0,s),this.unsigned=!!d}static[t(1137)](n){let s=t;return n&&e[s(1416)](!0,n[s(1137)])}static[t(831)](n,s,d){return new xe(n,s,d)}static[t(2017)+"s"](n,s,d){let f=t;return d?xe[f(2017)+f(1686)](n,s):xe["fromByte"+f(1768)](n,s)}static[t(2017)+t(1686)](n,s){let d=t;return new xe(e.CMkAK(e[d(1173)](e[d(1851)](n[0],n[1]<<8),e[d(587)](n[2],16)),n[3]<<24),e[d(1962)](n[4]|e.SQoPG(n[5],8)|e[d(638)](n[6],16),n[7]<<24),s)}static[t(2017)+t(1768)](n,s){let d=t;return new xe(e[d(1453)](e[d(1599)](n[4]<<24,e[d(1353)](n[5],16)),n[6]<<8)|n[7],e.AmwEm(e.rYLAh(n[0]<<24,e.YTvSt(n[1],16)),n[2]<<8)|n[3],s)}static[t(2005)](n){let s=t;return e[s(1632)](n,Yr)?Zd:new xe(e[s(1955)](e[s(2039)](ke.call(n,0)|ke[s(1922)](n,1)<<8,e[s(478)](ke.call(n,2),16)),e[s(1281)](ke[s(1922)](n,3),24))>>>0,e.USoHB(e[s(1371)](e[s(1851)](ke.call(n,4),e[s(1647)](ke[s(1922)](n,5),8)),e.bTMJZ(ke[s(1922)](n,6),16))|ke[s(1922)](n,7)<<24,0),!0)}[t(598)](){let n=t;return String["fromChar"+n(2004)](255&this[n(1447)],e.VBgwm(e[n(1755)](this.low,8),255),e.lImmu(e[n(1091)](this[n(1447)],16),255),e[n(769)](this[n(1447)],24),255&this[n(1245)],this[n(1245)]>>>8&255,e[n(2009)](this.high,16)&255,this[n(1245)]>>>24)}static fromNumber(n,s=!0){let d=t;if(isNaN(n))return s?gp:Zd;if(s){if(n>=Ie)return wp}else{if(n<=-nr)return _p;if(n+1>=nr)return mp}return xe[d(831)](e.vVNdo(n,we)|0,e[d(1326)](e[d(1612)](n,we),0),s)}toNumber(){let n=t;if(e.upQMe(e[n(1253)],n(2019)))return this[n(768)]?e[n(525)](this[n(1245)],0)*we+(this[n(1447)]>>>0):e[n(841)](this[n(1245)],we)+e[n(525)](this.low,0);this._ws&&this[n(1279)][n(475)](_0x3797d1),this[n(1165)+n(1155)][_0xb1a92d]=null}[t(1169)](){let n=t,s={uhebf:function(d,f){return e.gIMRE(d,f)}};return e.dkIoa(e.btjVK,e[n(992)])?e[n(1850)](0,this[n(1245)])&&e[n(1048)](0,this[n(1447)]):(_0x525790[n(1051)](rrWPdi.uhebf(_0x3091af,this),_0x3348b7),rrWPdi[n(649)](_0x2d6013,_0x2cc737[n(867)](this)))}add(n){let s=t;xe[s(1137)](n)||(n=xe.fromNumber(n));let d=this[s(1245)]>>>16,f=e[s(1238)](65535,this[s(1245)]),p=e[s(579)](this.low,16),w=65535&this.low,b=e[s(792)](n[s(1245)],16),g=e.gJJVy(65535,n[s(1245)]),C=e[s(1510)](n[s(1447)],16),R=65535&n.low,P=0,F=0,B=0,te=0;return te+=e[s(1077)](w,R),B+=e.oAGGR(te,16),te&=65535,B+=p+C,F+=e[s(1397)](B,16),B&=65535,F+=e[s(1249)](f,g),P+=e[s(1262)](F,16),F&=65535,P+=e[s(1458)](d,b),P&=65535,xe[s(831)](e[s(905)](e[s(587)](B,16),te),e.ghJVP(e[s(478)](P,16),F),this[s(768)])}[t(1808)](n){let s=t,d={iRrrF:function(f,p,w,b){return e[G(1398)](f,p,w,b)},MKXmN:e.zNQMp,sHzBz:function(f,p,w,b){return e[G(1398)](f,p,w,b)},hgrVF:s(642)+s(681)+"ck",JGCxa:e[s(1297)]};if(e[s(885)](e[s(1708)],"TWeCH")){let f=!!this[s(531)][s(1100)+"S"];if(!f)return{enabled:f,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let p=d[s(930)](_0x1ef6ec,_0x1b434b[s(1891)].headers,d[s(2053)],"2"),w=p&&d[s(1152)](_0x181cc6,_0x1ed35f[s(1891)][s(913)],d[s(1660)],"1"),b=p&&d[s(930)](_0x578bac,_0x14398e.message[s(913)],s(642)+s(878)+"k","1"),g=b?_0x3668c4(_0x55a540.message[s(913)],d[s(1742)])?.split(",")[s(763)](_0x2294f7)||[]:[];return{enabled:f,isQoSMessage:p,isQoSAck:w,isAckCleanupMessage:b,ackMsgIds:g}}else return xe[s(1137)](n)||(n=xe.fromNumber(n)),this.unsigned!==n[s(768)]&&e[s(492)](e.MKZEs(this[s(1245)],31),1)&&e[s(1325)](e.qENMR(n[s(1245)],31),1)?!1:e[s(947)](this[s(1245)],n[s(1245)])&&e[s(1048)](this[s(1447)],n.low)}[t(1370)](){let n=t;return e[n(1428)](-1,this.low)&&e[n(1632)](-1,this[n(1245)])?xe[n(831)](0,0,this[n(768)]):e.oQVLP(-1,this[n(1447)])?xe[n(831)](0,e[n(1792)](this[n(1245)],1),this[n(768)]):xe[n(831)](this[n(1447)]+1,this[n(1245)],this[n(768)])}[t(1679)](n){let s=t;return n?this[s(2082)+"E"]():this[s(945)+"E"]()}[t(2082)+"E"](){let n=t,s={UAvpB:e.sDcYK,nzDHD:n(1843),mFNTU:function(d){return e[n(728)](d)},CgRUg:e[n(577)],fDDVW:function(d){return e[n(839)](d)},MKiGm:e[n(762)]};if(e.MyXBO===n(1767)){let d=this.high,f=this[n(1447)];return[e[n(1809)](255,f),e.bQQWY(e[n(1262)](f,8),255),e[n(1729)](e[n(1196)](f,16),255),f>>>24,e[n(1573)](255,d),e[n(1648)](d>>>8,255),d>>>16&255,e[n(2009)](d,24)]}else{let d={vGypZ:function(b,g){return b(g)},locbC:UhoWDN[n(901)],EGlMK:function(b){let g=n;return UhoWDN[g(1897)](b)}},f=()=>{let b=n;_0x34673a[b(1409)+"entListener"](b(1586),p),_0x433623[b(1409)+"entListe"+b(1650)](UhoWDN[b(1319)],w),_0x5005fe["removeEv"+b(1908)+b(1650)](UhoWDN[b(1343)],w)},p=()=>{let b=n;_0x796b84(),UhoWDN[b(758)](f)},w=()=>{let b=n;d[b(1315)](_0x1030ac,_0x330208.error||new _0x85ca19(d[b(496)],d[b(496)])),d[b(1410)](f)};_0x2095ee["addEvent"+n(1923)](UhoWDN[n(1029)],p),_0x5c9156[n(1892)+n(1923)](UhoWDN[n(1319)],w),_0x108bdd[n(1892)+n(1923)](UhoWDN[n(1343)],w)}}[t(945)+"E"](){let n=t,s=this[n(1245)],d=this[n(1447)];return[e[n(870)](s,24),e[n(979)](s,16)&255,e.hDKlf(e[n(1196)](s,8),255),e[n(617)](255,s),d>>>24,e[n(1445)](e.MMtMb(d,16),255),e.wpghT(d>>>8,255),e[n(1270)](255,d)]}}let Zd=new xe(0,0,!1),gp=new xe(0,0,!0),mp=xe.fromBits(-1,2147483647,!1),wp=xe[t(831)](-1,-1,!0),_p=xe[t(831)](0,-2147483648,!1);var rn=(function(a){let n=t;return a[a[e[n(1929)]]=5001]="NATIVE_E"+n(1138),a[a[e[n(986)]]=5002]="CONNECTI"+n(604),a[a[e[n(1753)]]=5003]=e[n(1753)],a[a[e.RTQDh]=5004]=n(1344)+n(1947),a[a[n(1733)+"OR"]=5005]=e.CRfeY,a})({});class rr{constructor(n){let s=t;this[s(2025)]=n,this[s(2066)]=null}}class Jd extends rr{constructor(n,s){let d=t;super(n),this[d(1891)]=s&&s[d(1891)]||null}}class Xd extends rr{constructor(n,s){let d=t;super(n),this[d(1508)]=s&&s[d(1508)]||null,this[d(1552)]=s&&s[d(1552)]||0,this[d(1491)]=s&&s.filename||"",this[d(535)]=s&&s.lineno||0,this.message=s&&s[d(1891)]||"",this[d(1719)]=s&&s[d(1719)]||5001}}class Yd extends rr{constructor(n,s){let d=t;super(n),this[d(1719)]=s&&s[d(1719)]||0,this[d(621)]=s&&s[d(621)]||"",this[d(1532)]=s&&s[d(1532)]||!1,this[d(585)+d(897)]=s&&s[d(585)+d(897)]||!1}}class Qd extends rr{constructor(n,s){let d=t;super(n),this[d(1579)]=s&&s[d(1579)]||null}}class el extends Qd{constructor(n,s){let d=t;super(n),this[d(1579)]=s&&s.data||null,this[d(1891)]=s&&s.message||null}}class tl extends rr{constructor(n,s){let d=t;super(n),this[d(1579)]=s&&s.data||null}}function lt(a,{message:n,code:s,error:d}){let f=t,p={bhLyy:function(w,b){return e[G(1940)](w,b)},XHvAg:function(w,b){return e[G(1282)](w,b)},Wsnlm:function(w,b){return e[G(1255)](w,b)},rrXBA:function(w,b){return e.InTaz(w,b)},lWcyJ:function(w,b){return e[G(1824)](w,b)},AMXXT:function(w,b){return e.hpRnm(w,b)},qQeiq:function(w,b){return e[G(1282)](w,b)},TEeYJ:function(w,b){return w&b}};if(f(1451)===e[f(892)])_0x6739ea=qiAEPS.bhLyy(_0x40b872,_0xcf0a22),_0x583705|=qiAEPS.XHvAg(qiAEPS[f(676)](127,_0x1e236c),14),qiAEPS.rrXBA(128,_0x10ff1e)&&(_0x5729cb=qiAEPS[f(2118)](_0x2b6fc2,_0x1f9198),_0x508c3b|=qiAEPS[f(1540)](qiAEPS[f(676)](127,_0x9bc058),21),qiAEPS[f(1204)](128,_0x2c2fc5)&&(_0x12354e=qiAEPS.bhLyy(_0x1726b9,_0x26723a),_0x562d5a=qiAEPS[f(1355)](127,_0xb4ec57),qiAEPS[f(1120)](128,_0x250bce)&&(_0x2985ae=qiAEPS[f(2118)](_0x201a29,_0x1c72fd),_0x237cd9|=qiAEPS[f(1121)](qiAEPS[f(971)](127,_0x2e3487),7))));else return new Xd(a,{message:n,code:s,error:d})}function gt(a,{code:n,reason:s,wasClean:d,willReconnect:f}){let p=t;return e[p(1191)](e[p(1484)],e[p(1484)])?this[p(1239)]?.[p(1830)]({message_id:_0x146d15,timestamp:_0x48525c}):new Yd(a,{code:n,reason:s,wasClean:d,willReconnect:f})}function nl(a,{data:n,message:s}){return new el(a,{data:n,message:s})}function rl(a,{data:n}){let s=t;if(e[s(1308)]!==e[s(1308)]){let d=_0x476112(_0x3a8cc8,1);_0x637fb0.bytes[d]=_0xf916a3}else return new tl(a,{data:n})}function ha(a,{message:n}){return new Jd(a,{message:n})}class il{constructor(n,s){let d=t;this[d(761)+"s"]=n,this[d(2078)+"es"]=s,this[d(644)+d(787)]=0,this[d(1334)+d(691)+d(1043)+"t"]=0}[t(919)+t(880)+t(1399)](){let n=t;this.currentIndex=0,this[n(1334)+n(691)+n(1043)+"t"]=0}[t(690)+"es"](){let n=t;this[n(1334)+"ndpointT"+n(1043)+"t"]=0}[t(1882)+"ntEndpoint"](){let n=t;return this.endpoints[this[n(644)+n(787)]]}["getCurrentEndpoi"+t(1466)+t(2090)](){let n=t,s={Zvbps:e[n(1501)],TCKZF:e[n(523)],bzYgT:function(d,f,p){return d(f,p)},uXMFE:e.munJA};if(e[n(1490)](e[n(1320)],n(2107))){if(this[n(988)+n(1746)](),this[n(2001)+n(1244)](),this._removeWsListeners(),this["_wsInsta"+n(1316)](1e3,_0x29943d),this[n(711)+n(2051)]=!1,_0x4e5edb&&this[n(743)+n(586)]()&&!this[n(731)+n(549)]){if(this[n(1419)+n(1150)]?.["checkRea"+n(1084)+"es"]()){let f=this[n(1419)+n(1150)]?.["getCurre"+n(1468)+"nt"]();this[n(552)+n(2008)+n(1970)](_0x3d49db(s.Zvbps,{code:1006,reason:n(601)+f+(n(1465)+n(1905)+n(1304)+"ached"),wasClean:!0}))}else{let f=this[n(531)][n(661)+n(1783)+"ptor"](_0x149bc6,_0x5bbf5c);this[n(552)+n(2008)+n(1970)](_0x536502(s[n(1351)],{code:_0x49beb1,reason:_0x3eadb6,wasClean:!0,willReconnect:f})),f&&this._connect()}return}this[n(743)+n(586)]()||this._readyClosed?this[n(552)+n(2008)+n(1970)](_0x135103(s[n(1351)],{code:_0x1b385a,reason:s[n(2110)]})):this[n(552)+n(2008)+"ent"](s[n(1092)](_0x2f534f,s[n(1351)],{code:1006,reason:s[n(1678)]})),this[n(1279)]=null,this["_endpoin"+n(1150)]?.[n(919)+n(880)+"fig"](),this[n(1125)+n(886)]?.[n(1566)+n(1272)]()}else return this[n(1334)+n(691)+"riesCount"]}[t(1111)+t(1084)+"es"](){let n=t;return!!(e.XsCXC(this[n(644)+"ndex"],this[n(761)+"s"][n(1360)])||e[n(1688)](this[n(644)+"ndex"],e[n(674)](this[n(761)+"s"][n(1360)],1))&&this["currentE"+n(691)+n(1043)+"t"]===this[n(2078)+"es"])}["checkCurrentEndp"+t(2096)+"hedMaxRe"+t(663)](){let n=t;return this["currentI"+n(787)]==this.endpoints[n(1360)]?!0:e[n(647)](this[n(1334)+n(691)+"riesCount"],this[n(2078)+"es"])}[t(580)+t(1790)+t(2016)+"UpdateCo"+t(2068)](){let n=t,s={iYotf:e[n(744)]};if(e[n(1795)](e[n(1597)],e.zCQPD))return this[n(1334)+"ndpointT"+n(1043)+"t"]=1,this[n(644)+"ndex"]++,this[n(761)+"s"][this[n(644)+n(787)]];{this[n(689)+n(1331)+"t"]();let d=_0x1f3026(n(661)+"t",{message:s[n(1547)]});this[n(853)+n(1585)+n(1222)+"ct"]&&this[n(853)+"mediatel"+n(1222)+"ct"](d)}}["getCurre"+t(1468)+t(1784)+"ateCount"](){let n=t;if(e.csKvz(e[n(2054)],n(779)))return this["currentE"+n(691)+n(1043)+"t"]++,this["getCurre"+n(1468)+"nt"]();if(_0x46801e===xAOwxb[n(1591)])return _0x30b3a2[n(867)](_0x79139b);if(xAOwxb[n(1416)](_0x203f78,n(2079)+n(1018)))return _0x458d74[n(2079)+n(1018)]||_0x55d320[n(867)](_0x2aca10);if(xAOwxb[n(1041)](_0x5f3e78,"store"))return _0xf0f13b[n(2079)+n(1018)][1]?void 0:_0x4b49f3[n(2079)+n(1782)](_0x95ea05["objectSt"+n(1018)][0])}}let ir=(e.WLptO(t(2072)+"d",typeof globalThis)&&e[t(906)](e.fzMKx,globalThis[t(1011)+t(1497)][t(1531)])||e[t(1945)](e[t(505)],typeof window)&&e[t(2102)](e.fzMKx,window["construc"+t(1497)].name))&&e.zzhHY(e[t(505)],typeof document),Pn=e[t(505)]!=typeof globalThis&&(e.QZpLz(t(898),globalThis.constructor[t(1531)])||e[t(863)]===globalThis[t(1011)+"tor"].name)&&e[t(505)]!=typeof tt,Qr=(e.JcxVl(e[t(505)],typeof globalThis)&&e[t(718)](e[t(848)],globalThis["construc"+t(1497)][t(1531)])||e[t(843)](e[t(505)],typeof globalThis)||e[t(1668)](e[t(505)],typeof globalThis)&&!!globalThis[t(1220)+t(1868)])&&e.ziXOU("undefined",typeof wx),ei=e.htfcA!=typeof globalThis&&(e[t(1219)]("Dedicate"+t(618)+"lobalScope",globalThis[t(1011)+t(1497)][t(1531)])||e[t(771)]===globalThis.constructor[t(1531)]||e[t(1450)](e[t(482)],globalThis[t(1011)+"tor"][t(1531)]))&&e[t(1734)](e.htfcA,typeof self),yp=e[t(1814)](e[t(505)],typeof globalThis)&&e.EErdJ(t(898),globalThis["construc"+t(1497)][t(1531)])&&e[t(2091)](e[t(505)],typeof global)&&e.AqZdi(e[t(848)],global[t(1011)+t(1497)].name)&&e[t(2091)](e[t(505)],typeof process)&&!!process[t(627)];class pa{constructor(){this._listeners={}}[t(1426)](n,...s){let d=t;if(e[d(1543)]!==e[d(1543)]){if(e[d(1893)](_0x20323f,1)||_0x36c2e6>_0x2de055)return _0x5a7a13(_0x42db0c);e[d(1226)](e.JObfQ(_0x3431a4,_0x410f41),_0x4e0cb1)&&(_0x56a037=e[d(1656)](_0x48449c,_0x5d5f2d),_0x206eed=0);let f=_0x38e69d[d(1922)](_0x157a33,_0x526608,_0x61e4b8+=_0x4b1dd8);return e[d(1573)](7,_0x46a1d8)&&(_0x5b8d88=e.cWCrN(e[d(1089)](7,_0x1e17af),1)),f}else{let f=this._listeners[n];if(f)f[d(738)]()[d(1047)](p=>p.fn[d(1051)](p.ctx,s));else if(e[d(1834)](d(1508),n)&&!this[d(1900)]){let p=s[d(1360)]&&s[0];if(p instanceof Error)throw p;let w=new Error(e[d(862)](e.JyoLg,p?e[d(920)](e[d(1938)](" (",p[d(1891)]),")"):""));throw w[d(1804)]=p,p}return this}}[t(2088)](n,s){let d=t,f={PxjoT:function(p,w,b){return e[G(1079)](p,w,b)},bhoMl:e[d(1501)]};if(e.DVyFK(void 0,n))this[d(1124)+"rs"]={};else if(e[d(1103)](void 0,s))this[d(1124)+"rs"][n]=null;else if(e.roOZh(e.IzkgH,"ZOdJI"))this[d(1426)](d(1638),f[d(1361)](_0x222b34,f[d(2040)],{..._0x3f8afa}));else{let p=this[d(1124)+"rs"][n];if(p)for(let w=0;w<p[d(1360)];)e[d(1617)](p[w].fn,s)?p.splice(w,1):++w}return this}on(n,s,d){let f=t;return(this[f(1124)+"rs"][n]||(this[f(1124)+"rs"][n]=[]))[f(911)]({fn:s,ctx:d||this}),this}}class bp extends pa{[t(537)+t(1403)+t(1819)](n){let s=t;return n[s(1622)]||n[s(1036)]?(s(1538)+" "+(n[s(1622)]||"")+s(736)+(n[s(1036)]||"")).trim():JSON[s(1004)+"y"](n)}constructor(n,s,d){let f=t;super(),this[f(2071)]=null,Qr&&wx[f(1227)+f(1049)]&&(this[f(2071)]=wx[f(1227)+f(1049)]({url:n,protocols:s,header:d,fail:this._createSocketFailHandler[f(1640)](this),success:this[f(1448)+f(693)+"cessHand"+f(1074)].bind(this)})),Pn&&tt[f(1227)+"ocket"]&&(this[f(2071)]=tt["connectS"+f(1049)]({url:n,protocols:s,header:d,fail:this[f(1448)+f(1616)+"lHandler"][f(1640)](this),success:this[f(1448)+"ocketSuc"+f(1207)+f(1074)][f(1640)](this)}))}[t(1448)+t(693)+t(1207)+t(1074)](){let n=t;Promise.resolve()[n(583)](()=>{this["_addWsLi"+n(1366)]()})}["_createS"+t(1616)+t(1e3)](n){let s=t;Promise[s(1818)]()[s(583)](()=>{let d=s,f=e[d(1474)](lt,e[d(729)],{message:this[d(537)+"rrorMess"+d(1819)](n)});this[d(1426)](e[d(729)],f);let p=e[d(809)](gt,e.DUWUZ,{reason:this["_formatE"+d(1403)+d(1819)](n)});this[d(1426)](e[d(1501)],p)})}[t(998)+t(1366)](){let n=t,s={PeHUC:e[n(1588)],cKuSp:e[n(1501)],vdjSA:function(d,f,p){return e[n(1075)](d,f,p)}};this[n(2071)].onOpen(d=>{let f=n;this[f(1426)](e[f(1176)],e[f(1225)](rl,f(1999),{...d,data:d[f(1622)]||""}))}),this[n(2071)][n(1455)](d=>{let f=n;if(f(734)===s[f(1673)])this[f(1426)](s[f(1631)],s[f(1806)](gt,s.cKuSp,{...d}));else{let p=this._qosDB[f(2044)+f(1749)](this[f(667)]),w=_0x3c47db.parse(p||"{}");return w[_0x566a7d]=void 0,this[f(1239)].setStorageSync(this[f(667)],_0x14a4a7[f(1004)+"y"](w))}}),this[n(2071)][n(719)+"e"](d=>{let f=n;this.emit(e[f(473)],e[f(694)](nl,e.rzKJT,{...d}))}),this._socket[n(517)](d=>{let f=n;if(e.DECEz("iwIaq",e.bxLED))this.emit(e[f(729)],e.ZZIdm(lt,e.sDcYK,{...d,message:d[f(1622)]||""}));else return this[f(1419)+"tManager"]?.["getCurre"+f(1468)+f(1466)+"ount"]()||0})}send(n){let s=t,d={fbSro:function(f,p){return f!==p},ksOWn:e[s(1305)],EOMMp:e.sDcYK,wMjnF:function(f,p,w){return f(p,w)}};if(e[s(1865)](n,Uint8Array)){let f=n[s(900)][s(738)](n.byteOffset,e[s(1514)](n[s(2028)+"th"],n[s(558)+"et"]));this[s(2071)]&&this._socket.send({data:f,fail:p=>{let w=s;if(d[w(1296)](d[w(1993)],w(962)))this[w(1426)](d[w(1549)],d[w(1323)](lt,w(1508),{message:this[w(537)+w(1403)+"age"](p)}));else return this._socket[w(1890)]}})}else this[s(2071)]&&this[s(2071)][s(475)]({data:n,fail:f=>{let p=s;this.emit(p(1508),e[p(753)](lt,p(1508),{message:this[p(537)+p(1403)+p(1819)](f)}))}})}[t(1638)](n,s){let d=t;this._socket&&this[d(2071)][d(1638)]({code:n,reason:s})}[t(1892)+t(1923)](n,s){let d=t,f={kAJtc:function(p,w){return e.nqYIX(p,w)},mzpSd:function(p,w){return e[G(1770)](p,w)},dxjiI:function(p,w){return e[G(2101)](p,w)},nHqHd:function(p,w){return e[G(1105)](p,w)},OMTGp:function(p,w){return e.WASEP(p,w)},ItjPb:function(p,w){return e[G(1763)](p,w)},nXTaP:function(p,w){return e[G(801)](p,w)}};if(e.VrKqm("KqyHG",e[d(1649)])){let p=_0x27bd7.charCodeAt(_0x24c6cf);wItWYi[d(1354)](p,55296)&&wItWYi.mzpSd(p,56319)&&wItWYi.dxjiI(wItWYi[d(1916)](_0xc99c21,1),_0x22d92a)&&(p=wItWYi[d(1088)](wItWYi.ItjPb(wItWYi.nXTaP(p,10),_0x3358af[d(1250)+"At"](++_0x22ce63)),56613888)),_0xf145c3+=wItWYi[d(560)](p,128)?1:wItWYi.dxjiI(p,2048)?2:wItWYi[d(560)](p,65536)?3:4}else this.on(n,s)}[t(1409)+t(1908)+t(1650)](n,s){this.off(n,s)}get[t(1040)+"te"](){return this._socket.readyState}get binaryType(){let n=t;return this[n(2071)][n(660)+"pe"]}set binaryType(n){}get url(){return this[t(2071)].url}get[t(1890)](){return this[t(2071)].protocol}get[t(1285)+"ns"](){let n=t;return this[n(2071)][n(1285)+"ns"]}get[t(1934)+"Amount"](){let n=t,s={OnYJa:e[n(1596)]};if(e[n(1834)](e[n(1849)],e[n(550)])){let d=s[n(942)][n(852)]("|"),f=0;for(;;){switch(d[f++]){case"0":this[n(731)+"osed"]=!1;continue;case"1":this._connect();continue;case"2":this["_endpoin"+n(1150)]?.["resetEndpointCon"+n(1399)]();continue;case"3":this[n(1125)+n(886)]?.[n(1566)+n(1272)]();continue;case"4":this[n(833)]=!0;continue}break}}else return 0}}function Ep(a,n){let s=t;if(e[s(1737)]!==e[s(931)]){if(n)return new n(a[s(1274)],a.protocol);if(e[s(1506)](Qr,Pn))return new bp(a.url,a[s(1890)],a[s(913)]);if((ir||ei)&&e[s(2024)](e[s(505)],typeof WebSocket)&&WebSocket)return new WebSocket(a[s(1274)],a[s(1890)+"s"])}else _0x3fb939(this[s(656)+s(1577)+"Id"]),e[s(1168)](_0x49a085,this[s(2061)+s(636)+s(851)]),this[s(656)+"gTimeoutId"]=null,this[s(2061)+s(636)+s(851)]=null}function vp(a){let n=t;return!!(a||Qr&&wx[n(1227)+n(1049)]||Pn&&tt[n(1227)+n(1049)]||(ir||ei)&&typeof WebSocket<"u"&&WebSocket)}function sl(a,n,s){let d=t,f={VLTOm:function(b,g){return e.jYpvC(b,g)},lOhIS:d(819)+d(519)+d(1870)+d(1209)+d(1375),VIisL:function(b,g){return e.QEYNs(b,g)}},p=-1;async function w(b){let g=d;return f[g(1738)](b,p)?Promise.reject(new Error(f.lOhIS)):(p=b,f[g(2113)](b,s[g(1360)])?Promise.resolve():s[b].bind(a)(n,w[g(1640)](null,b+1)))}e[d(800)](w,0)}function ol(a){let n=t,s=0,d=0;for(let f=0;e[n(1163)](f,a[n(1360)]);++f)d=a[n(1250)+"At"](f),e[n(612)](d,128)?s+=1:e.vsHBP(d,2048)?s+=2:e[n(746)](e.gJJVy(64512,d),55296)&&e[n(2094)](e[n(2003)](64512,a[n(1250)+"At"](f+1)),56320)?(++f,s+=4):s+=3;return s}function al(a,n,s){let d=t;if(e.YKxGN(e[d(1928)](s,n),1))return"";let f="";for(let p=n;e[d(1952)](p,s);){let w=a[p++];if(e[d(1770)](w,127))f+=String[d(2120)+d(2004)](w);else if(w>=192&&e[d(1835)](w,224))f+=String.fromCharCode(e[d(1702)](e[d(1208)](e.kQWNM(31,w),6),e[d(774)](63,a[p++])));else if(e[d(544)](w,224)&&e.VYgDG(w,240))f+=String["fromChar"+d(2004)](e[d(1568)](e[d(588)](e[d(801)](e.TGyRx(15,w),12),e[d(873)](63&a[p++],6)),e[d(1502)](63,a[p++])));else if(e.tWNpb(w,240)){let b=(e.HKhBq(e.WSYpb(7&w,18)|e[d(946)](63,a[p++])<<12,e[d(1353)](e[d(1151)](63,a[p++]),6))|e[d(1685)](63,a[p++]))-65536;f+=String[d(2120)+d(2004)](55296+e.Ianrh(b,10)),f+=String[d(2120)+d(2004)](e.KPTvH(56320,e[d(620)](1023,b)))}}return f}function ga(a,n,s){let d=t,f=s,p,w;for(let b=0;e[d(1313)](b,a[d(1360)]);++b)if(p=a[d(1250)+"At"](b),e[d(1952)](p,128))n[s++]=p;else if(e[d(1952)](p,2048))n[s++]=e[d(2112)](p,6)|192,n[s++]=e[d(477)](63&p,128);else if(e[d(899)](e.UQgAm(64512,p),55296)&&e.csKvz(e[d(950)](64512,w=a[d(1250)+"At"](e[d(1022)](b,1))),56320)){let g=e[d(1935)][d(852)]("|"),C=0;for(;;){switch(g[C++]){case"0":n[s++]=p>>12&63|128;continue;case"1":n[s++]=e[d(543)](e[d(1376)](p,18),240);continue;case"2":++b;continue;case"3":n[s++]=e.CakvD(e[d(1557)](e[d(491)](p,6),63),128);continue;case"4":p=e[d(1395)](e[d(862)](65536,e[d(889)](1023&p,10)),e[d(1557)](1023,w));continue;case"5":n[s++]=e[d(1962)](63&p,128);continue}break}}else n[s++]=e.CciJV(e[d(1273)](p,12),224),n[s++]=e[d(1604)](e[d(1903)](e[d(1080)](p,6),63),128),n[s++]=e[d(824)](e[d(1445)](63,p),128);return e[d(1928)](s,f)}async function cl(a){let n=t,s={MXcmn:function(d,f){return e.xqgyo(d,f)}};if(e.wyDkx(n(1896),typeof a))if(e.oXstj(e[n(1504)],e[n(1234)])){let d=new Uint8Array(ol(a));return ga(a,d,0),d}else{let d=this._qosDB[n(2044)+"geInfoSync"](this[n(667)]),f=_0x4b74f8[n(2119)](s.MXcmn(d,"{}"));return _0x4bc13a[n(1112)](f)}return a instanceof ArrayBuffer?new Uint8Array(a):new Uint8Array(a[n(900)],a[n(558)+"et"],a.byteLength)}function Sp(a){let n=t,s={JrtMp:function(d,f,p,w){return d(f,p,w)}};try{if(e[n(724)]("fEFZI",e.tqDRg))s.JrtMp(_0x5b29e9,this,_0x496340,[_0x41596d,_0x3273db,_0x1d6326,_0x44d2e2,_0x36fd57,_0x54dab6]);else return e[n(1668)](e[n(1009)],typeof a)&&(e[n(1309)](a,ArrayBuffer)||a[n(900)]&&e.EmjiK(a[n(900)],ArrayBuffer))||e.DMXeo(e[n(1009)],typeof a)?"":(JSON.parse(a),e[n(1186)])}catch{return e[n(1041)](n(1852),n(1587))?e.fcRDX(-1,this[n(1447)])&&e[n(684)](-1,this[n(1245)])?_0x33b6ac.fromBits(0,0,this[n(768)]):this[n(1447)]===-1?_0x377300[n(831)](0,this[n(1245)]+1,this[n(768)]):_0x59d6a5[n(831)](e[n(1394)](this[n(1447)],1),this[n(1245)],this.unsigned):e[n(2104)](e[n(1009)],typeof a)?e[n(1519)]:""}}let Ap=(a,n)=>{let s=t;if(e[s(1325)](e[s(1340)],"tyRTX"))switch(a){case e[s(1406)]:case e[s(493)]:return{[s(1213)+a]:1,"x-tt-env":n};default:return{}}else _0x43503f(_0x51704b,90),e[s(894)](_0xa2ceb4,_0x3bfef8,_0xe0611b)};class Ip{constructor(n){let s=t;this[s(1495)+s(2090)]=n,this[s(791)]=0}[t(980)](){let n=t;e.csKvz(n(1153),e[n(1687)])?this[n(791)]++:e.zhPbr(_0x509db0,_0x54f001,this[n(695)+n(972)+"e"](_0x55de4f))}[t(1111)+t(1670)+"nt"](){let n=t;return e.QTPUw!==e[n(1283)]?new _0x4bd7ec(_0x406035,_0x502b69,_0x4b4d0c):e.XsCXC(this[n(791)],this[n(1495)+n(2090)])}[t(1566)+"nter"](n=0){let s=t;this[s(1495)+"ount"]=n,this.count=0}}async function Cp(a){let n={qgVgw:function(s,d){return e[G(1104)](s,d)}};return new Promise(s=>{let d=G;if(!ir)return e[d(1925)](s,e[d(770)]);try{let f=document[d(1872)+d(1511)](e.ZcIly);window[d(1240)+d(1769)]=p=>{let w=d;document[w(1452)][w(1072)+w(798)](f),window[w(1240)+w(1769)]=void 0,n[w(1062)](s,p&&p[w(557)]||w(1776)+w(621))},f[d(2025)]=e.Wzldy,f.src=e[d(1217)](a[d(511)](/^ws/,d(1433)),e.KHUOe);try{document.body.appendChild(f)}catch{document.body[d(1072)+d(798)](f)}}catch{window[d(1240)+"JSONP"]=void 0,e[d(1168)](s,e.LVMho)}})}function sn(a,n,s){let d=t;return!!a?.[d(1982)](f=>f.key===n&&f[d(1053)]===s)}function sr(a,n){let s=t;return a?.[s(1982)](d=>d.key===n)?.[s(1053)]}let ma=null;async function Tp(){let a=t;return ma||(ma=Promise[a(1818)]().then(zt[a(1640)](zt,e[a(1720)]))),ma}class Rp extends pa{constructor(n,s){let d=t;super(),this[d(1912)]=n,this._keyPath=s,this[d(1239)]=void 0,this[d(1008)+d(766)]=null}async openDB(){let n=t;if(e[n(1803)](e.VLoNr,e[n(1752)]))try{this[n(1279)]&&this[n(1279)][n(1638)](_0x1e9469,_0x42fcfb)}catch{}else await this[n(1299)]()}async[t(1299)](){let n=t;if(!this._qosDB){if(this["_initPro"+n(766)])return this[n(1008)+n(766)];try{let s=this[n(1912)],d=this[n(1107)];this[n(1008)+"mise"]=(async()=>{let f=n,{openDB:p}=await e[f(1548)](Tp);this[f(1239)]=await e[f(1398)](p,f(1240)+"_"+s,1,{upgrade(w){w["createOb"+f(2076)+"e"](s,{keyPath:d})}})})(),await this[n(1008)+"mise"]}catch(s){console[n(1889)](s)}finally{this[n(1008)+"mise"]=null}}}async get(n){let s=t;try{return await this[s(1299)](),this[s(1239)]?.[s(867)](this._dbName,n)}catch(d){console[s(1889)](d)}}async[t(1830)](n,s){let d=t;return await this._init(),this[d(1239)]?.put(this._dbName,n)}async del(n){let s=t,d={kMFXX:function(f,p,w){return f(p,w)},wgZQA:function(f,p){return e[G(777)](f,p)}};try{if(e[s(566)](e.xPTSD,s(1184)))mZSLDw.kMFXX(_0x27523b,_0x542faa,32),_0x4e6dc1(_0x3859d3,mZSLDw[s(1015)](_0x23bd38,_0xce0f56));else return await this[s(1299)](),this[s(1239)]?.delete(this[s(1912)],n)}catch(f){console[s(1889)](f)}}async[t(2026)](){let n=t;try{return await this[n(1299)](),this[n(1239)]?.[n(2026)](this._dbName)}catch(s){if(e.eQfrM!==e[n(1010)])console[n(1889)](s);else{let d=_0x341102(e[n(933)],{message:e[n(1980)]});this[n(1333)+"econnect"]&&this.onStartReconnect(d)}}}async keys(){let n=t;return await this[n(1299)](),this[n(1239)]?.[n(2020)+"ys"](this._dbName)}async getAll(){let n=t;return e[n(1659)]===n(597)?(await this[n(1299)](),this[n(1239)]?.[n(1014)](this._dbName)):this[n(1279)]?this[n(1279)][n(1040)+"te"]:this[n(531)][n(1839)+n(584)]?this.CONNECTING:this[n(832)]}async[t(547)](){let n=t;try{this[n(1239)]?.[n(1638)](),this._qosDB=void 0}catch(s){console[n(1889)](s)}}get isReady(){let n=t;try{return!!this[n(1239)]}catch(s){return console[n(1889)](s),!1}}}class Dp{constructor(n,s){let d=t;this[d(1625)]=n,this[d(875)]=s,this._qosDB=localStorage}async[t(989)](){}get[t(667)](){let n=t;return n(1240)+"_"+this[n(1625)]}async[t(867)](n){let s=t;if(s(2108)!==e[s(1921)]){let d=_0x31ba61.split(":");_0x326db2&&(_0x5c5276=d.length),_0x1b0cb8+=d[s(1360)];for(let f=0;e[s(725)](f,d[s(1360)]);f++)if(e.HujXf(4,d[f][s(1360)])){let p=_0x2c4873[s(1646)+"g"](0,e.uXTLu(4,d[f][s(1360)])),w=p[s(943)](d[f]);_0x4c55b9[s(911)](w)}else _0x22f9dc[s(911)](d[f]);_0x5599c2=!1}else{let d=this[s(1239)][s(1580)](this[s(667)]);return JSON[s(2119)](d||"{}")[n]}}async[t(1830)](n,s){let d=t;if(e[d(2052)](e[d(2083)],e[d(2083)])){let f=this._qosDB[d(1580)](this._prefix),p=JSON.parse(e[d(1506)](f,"{}"));return p[s||n[this[d(875)]]]=n,this._qosDB.setItem(this[d(667)],JSON[d(1004)+"y"](p)),s||n[this[d(875)]]}else _0x244317+=e[d(1698)](_0x4e888a,_0x5b3ea5),_0x320fe4+=2}async[t(1954)](n){let s=t,d=this._qosDB.getItem(this[s(667)]),f=JSON[s(2119)](e[s(1506)](d,"{}"));return f[n]=void 0,this._qosDB[s(1624)](this[s(667)],JSON[s(1004)+"y"](f))}async[t(2026)](){let n=t;return this[n(1239)][n(2026)]()}async[t(879)](){let n=t,s=this[n(1239)].getItem(this[n(667)]),d=JSON[n(2119)](e[n(1506)](s,"{}"));return Object[n(879)](d)}async[t(1014)](){let n=t;if(e[n(1608)](n(574),e[n(999)])){let s=this[n(1239)][n(1580)](this._prefix),d=JSON[n(2119)](e.NIOnf(s,"{}"));return Object[n(1112)](d)}else this._intervalTimeoutId=null,this._interval=36e5,this._qosDB=_0x516b6d(e[n(1498)],e.YdBwd)}[t(547)](){return Promise.resolve()}get[t(1224)](){return!!this[t(1239)]}}class kp{constructor(n,s){let d=t;this[d(1625)]=n,this[d(875)]=s,this[d(1239)]=Pn?tt:Qr?wx:null}async[t(989)](){}get[t(667)](){let n=t;return n(1240)+"_"+this[n(1625)]}async[t(867)](n){let s=t,d=this[s(1239)][s(2044)+s(1749)](this[s(667)]);return JSON[s(2119)](e[s(1024)](d,"{}"))[n]}async[t(1830)](n,s){let d=t,f=this._qosDB[d(2044)+"geSync"](this[d(667)]),p=JSON.parse(e[d(716)](f,"{}"));return p[s||n[this[d(875)]]]=n,this[d(1239)][d(1655)+d(1749)](this[d(667)],JSON[d(1004)+"y"](p)),s||n[this[d(875)]]}async del(n){let s=t;if(e.DhXsg("JazRj",e[s(1098)])){let d=this._qosDB[s(2044)+s(1749)](this[s(667)]),f=JSON[s(2119)](d||"{}");return f[n]=void 0,this._qosDB[s(1655)+s(1749)](this[s(667)],JSON[s(1004)+"y"](f))}else _0x165815[s(1830)](_0x536317,_0x194aab),_0x5ca58d[s(1830)](_0x5c8e49,_0x12c6f0)}async[t(2026)](){return this._qosDB.clearStorageSync()}async[t(879)](){let n=t,s={liSDY:function(d,f){return e[G(1664)](d,f)},sgBUv:function(d,f){return e.mFnve(d,f)},hYeCT:function(d,f){return e[G(1500)](d,f)}};if(e.xLGLZ!=="aOpOX"){let d=this[n(1239)][n(2044)+n(1957)+"nc"](this._prefix),f=JSON[n(2119)](e[n(481)](d,"{}"));return Object[n(879)](f)}else{if(owckPm[n(1469)](void 0,_0x14fc51))this._listeners={};else if(owckPm.liSDY(void 0,_0x323e0d))this[n(1124)+"rs"][_0x32a1ca]=null;else{let d=this[n(1124)+"rs"][_0x480afa];if(d)for(let f=0;owckPm.sgBUv(f,d[n(1360)]);)owckPm.hYeCT(d[f].fn,_0x63eea7)?d.splice(f,1):++f}return this}}async[t(1014)](){let n=t,s=this[n(1239)]["getStora"+n(1957)+"nc"](this[n(667)]),d=JSON.parse(s||"{}");return Object[n(1112)](d)}[t(547)](){return Promise.resolve()}get isReady(){return!!this[t(1239)]}}function dl(a,n){let s=t;if(Pn||Pn)return new kp(a,n);if((ir||ei)&&typeof indexedDB<"u")return new Rp(a,n);if(e[s(1413)](ir,ei)&&e.JcxVl(e[s(505)],typeof localStorage))return new Dp(a,n);throw new Error(e[s(1877)])}class Pp{constructor(){let n=t,s={TpCcA:function(d,f){return e[G(2003)](d,f)},zLOgi:function(d,f){return e[G(1262)](d,f)},zpvMA:function(d,f){return e[G(1032)](d,f)},DIjBv:function(d,f){return d&f},VvnsD:function(d,f){return e[G(654)](d,f)}};if(e[n(1097)](e[n(1871)],n(1633)))return _0x3c4a0c[n(2120)+n(2004)](qGErfW[n(1626)](255,this[n(1447)]),this.low>>>8&255,qGErfW[n(1789)](this[n(1447)],16)&255,qGErfW[n(1887)](this[n(1447)],24),255&this[n(1245)],qGErfW.DIjBv(qGErfW[n(1789)](this[n(1245)],8),255),qGErfW[n(958)](qGErfW[n(1789)](this[n(1245)],16),255),qGErfW[n(1030)](this.high,24));this[n(854)+n(1002)+"Id"]=null,this[n(854)+"l"]=36e5,this[n(1239)]=e[n(1773)](dl,n(548),e.YdBwd)}async _intervalFlush(){let n=t;e[n(534)](e[n(1321)],e[n(1321)])?(e[n(673)](clearInterval,this[n(854)+n(1002)+"Id"]),this[n(854)+n(1002)+"Id"]=setInterval(()=>{let s=n;this[s(1016)+s(1967)]()},this._interval)):(this._ws&&this[n(1279)][n(475)](_0x34277f),this._debug(e[n(1216)],_0x5ceefe))}async[t(989)](){let n=t;await this[n(1239)][n(989)]()[n(583)](()=>{let s=n;this[s(854)+s(697)]()})}async[t(1016)+t(1967)](){let n=t,s={waXCj:function(d,f){return d>=f},RNGIl:function(d,f){return e.YZzmn(d,f)},bHSie:function(d,f){return e[G(1045)](d,f)},EdzSW:function(d,f){return d-f},DBMBK:function(d,f){return e.VWScv(d,f)},RuCtE:function(d,f){return e.FXrsn(d,f)},lkRzv:function(d,f){return e[G(1693)](d,f)},oetdE:function(d,f){return d|f},VvxwT:function(d,f){return d&f},WMOui:function(d,f){return e[G(1965)](d,f)},oLNtD:function(d,f){return e[G(1702)](d,f)},FjAqP:function(d,f){return d>>f}};if(e[n(1381)](e[n(1805)],e.XYeqo))(await this[n(1239)]?.[n(1014)]()||[]).filter(({timestamp:p})=>p<Date[n(1696)]())[n(1047)](p=>{let w=n;this[w(1239)]?.[w(1954)](p[w(807)+"id"])});else{let d=_0x1022b9[n(1250)+"At"](_0x4ece4f);NuJLKx[n(1986)](d,55296)&&NuJLKx[n(2114)](d,56319)&&NuJLKx[n(1529)](_0x8dca9e,1)<_0x575749&&(d=NuJLKx[n(1614)](NuJLKx[n(1246)](d,10)+_0xe3a178[n(1250)+"At"](++_0x34fe99),56613888)),NuJLKx[n(1978)](d,128)?_0xd10e20[_0x2768a2++]=d:(NuJLKx[n(1978)](d,2048)?_0x3bfcf2[_0x160a36++]=NuJLKx[n(924)](d,6)&31|192:(NuJLKx[n(1978)](d,65536)?_0x12fb71[_0x3aa164++]=NuJLKx.oetdE(NuJLKx[n(1347)](d>>12,15),224):(_0x28bd04[_0x169aa4++]=NuJLKx[n(1149)](NuJLKx[n(1347)](NuJLKx[n(924)](d,18),7),240),_0x2e7259[_0x5a274c++]=NuJLKx[n(1159)](NuJLKx[n(1347)](NuJLKx[n(1180)](d,12),63),128)),_0x51f4cd[_0x330fa4++]=NuJLKx[n(1149)](d>>6&63,128)),_0xeba72b[_0x1a7754++]=NuJLKx[n(1159)](NuJLKx[n(1347)](63,d),128))}}async del(n){let s=t;return this._qosDB?.[s(1954)](n)}async set(n,s){let d=t;return this[d(1239)]?.[d(1830)]({message_id:n,timestamp:s})}async[t(867)](n){return this._qosDB?.get(n)}async closeDB(){let n=t;e[n(1068)](clearInterval,this["_interva"+n(1002)+"Id"]),await this[n(1239)]?.[n(547)]()}get[t(1224)](){let n=t;return this[n(1239)]?.[n(1224)]}}function wa(a){let n=t,s={mMYwz:function(d){return e[G(1918)](d)}};if(e[n(2055)](e[n(1909)],e[n(1263)]))_0x521f98(),eGXyhZ.mMYwz(_0xfd88c2);else{let d=!!this[n(531)].enableQoS;if(!d)return{enabled:d,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let f=e[n(822)](sn,a[n(1891)][n(913)],n(642)+"er_qos","2"),p=f&&e[n(822)](sn,a[n(1891)][n(913)],n(642)+n(681)+"ck","1"),w=f&&e[n(1398)](sn,a.message.headers,e[n(669)],"1"),b=w?e[n(894)](sr,a[n(1891)][n(913)],e[n(1297)])?.[n(852)](",")[n(763)](Boolean)||[]:[];return{enabled:d,isQoSMessage:f,isQoSAck:p,isAckCleanupMessage:w,ackMsgIds:b}}}async function ll(){let a=t;return this["_QoSMana"+a(1288)]||(this[a(1487)+a(1288)]=new Pp),this[a(1487)+"ger"].isReady||await this["_QoSMana"+a(1288)][a(989)](),this[a(1487)+a(1288)]}async function Op(a,n){let s=t,{enableAutoAck:d}=this[s(531)],f=e[s(1398)](sn,a[s(1891)][s(913)],e.VCxKj,"1"),p=sn(a[s(1891)].headers,"is_ack","1"),w=wa[s(1922)](this,a);if(e[s(2121)](d,f)){let{SeqID:b,LogID:g,service:C,LogIDNew:R,method:P}=a.message;this[s(1187)]({SeqID:b,LogID:g,LogIDNew:R,service:C,method:P,headers:[{key:e[s(802)],value:"1"},{key:e.qbKZR,value:e.vsGWk(R,"")},{key:e.gMTUl,value:"0"}]})}p&&!w[s(2069)]&&this["_dispatc"+s(1063)+"ageEvent"](a),n()}async function Lp(a,n){let s=t;this[s(973)](s(1126),a[s(1891)]),n()}async function Np(a,n){let s=t,d=e[s(882)](tn,await e.FRZEx(cl,a.data));try{if(e[s(1385)](d[s(1731)],Uint8Array))if(s(1162)===e[s(749)]){let f=e[s(704)](this._options[s(1241)+s(532)],Object)?{force:!!this[s(531)][s(1241)+"ncoding"][s(2012)],encoding:this[s(531)][s(1241)+s(532)].encoding?this[s(531)][s(1241)+s(532)][s(639)][s(511)](/\s/g,"")[s(595)+"ase"]():""}:{force:!1,encoding:this._options[s(1241)+s(532)]?this[s(531)][s(1241)+"ncoding"][s(511)](/\s/g,"")["toLowerC"+s(1796)]():""},p=d[s(1241)+s(532)]?d[s(1241)+s(532)][s(511)](/\s/g,"")[s(595)+"ase"]():"",w=e.EmjiK(this[s(531)][s(1788)+"ype"],Object)?{force:!!this[s(531)][s(1788)+s(1256)].force,type:this[s(531)][s(1788)+"ype"][s(2025)]?this._options["payloadT"+s(1256)][s(2025)].replace(/\s/g,"")["toLowerC"+s(1796)]():""}:{force:!1,type:this[s(531)][s(1788)+"ype"]?this[s(531)][s(1788)+s(1256)][s(511)](/\s/g,"")[s(595)+s(1796)]():""},b=d[s(1788)+s(1256)]?d[s(1788)+s(1256)][s(511)](/\s/g,"")[s(595)+s(1796)]():"",g=w.force?w[s(2025)]:b||w[s(2025)],C=f.force?f[s(639)]:p||f.encoding,R=[e.DjdWd,s(944)+s(1662),e[s(1108)],e[s(1009)]],P=[s(1949)+"e",s(842)];this[s(531)][s(1154)+s(1139)+s(1083)+"ad"]&&R[s(1780)](g)&&(!C||P[s(1780)](C))?d[s(1707)+s(1927)]=e[s(709)](al,d[s(1731)],0,d[s(1731)][s(2028)+"th"]):d[s(1707)+"oad"]=""}else{let f=this[s(1245)],p=this.low;return[f>>>24,e[s(614)](f,16)&255,e[s(540)](e[s(1262)](f,8),255),e[s(1493)](255,f),e[s(573)](p,24),e.XQqgw(p>>>16,255),e[s(1824)](e[s(626)](p,8),255),255&p]}else d[s(1707)+s(1927)]=""}catch(f){if(e[s(1816)](s(1598),e[s(1177)])){let p=_0x29e61c[s(1922)](xAOwxb[s(1937)](_0xce7b62,this),_0x55b714,..._0x455b68);return _0x2403d6[s(1830)](p,_0x2f39f1[s(539)]?_0x41f2f4.sort():[_0x114648]),xAOwxb[s(996)](_0x5ac675,p)}else d[s(1707)+"oad"]="",console[s(1889)](f)}a[s(1891)]=d,e[s(1548)](n)}function Mp(a,n,s){let d=t,f={aTDZj:function(C,R){return C<R},pCUKV:function(C,R){return e.wWVTt(C,R)},RDvye:function(C,R){return e[G(1463)](C,R)},quMtn:e[d(815)],dUsTQ:function(C,R){return e[d(1182)](C,R)},WgKog:function(C,R){return C&R},WvBXv:function(C,R){return e[d(1458)](C,R)},ahtuN:function(C,R){return e[d(599)](C,R)}},p=e[d(1815)](s,8192),w=p>>>1,b=null,g=p;return function(C){let R=d;if(f[R(860)](C,1)||C>w)return a(C);if(f.pCUKV(g+C,p)){if(f[R(1666)](f[R(1981)],f[R(1981)]))throw this[R(711)+R(2051)]=!1,_0x2a64e2;b=f[R(1081)](a,p),g=0}let P=n[R(1922)](b,g,g+=C);return f[R(1527)](7,g)&&(g=f[R(518)](f[R(1392)](7,g),1)),P}}let Bp=4294967295;function zp(a,n,s){let d=t;return e[d(940)](RangeError,e[d(857)](e[d(1701)](e[d(1417)](e[d(1050)](e[d(1725)],a)+e[d(1006)],e[d(1815)](n,1)),e[d(643)]),s))}function Fp(a,n,s){let d=t,f={pwJgG:function(w,b,g){return e.zIceD(w,b,g)}};if(s>Bp)throw new Error(e[d(1589)]);let p=3;for(;p>=0;)if(e.QLyyM(e[d(632)],e.VoQuL)){let w=255&s;e.eHIZr(ya,w,a,e[d(968)](n,p)),s>>>=8,p--}else Kbtkka.pwJgG(_0x28779a,_0xe65372,66),_0xc57c00(_0x36ce31,_0x391169.length),Kbtkka[d(1592)](_0x5753ce,_0x17e2d2,_0x242f61);return e[d(1758)](n,4)}function Up(a,n){let s=t,d=0,f=n,p=n+4;for(;e[s(1212)](f,p);){let{value:w,offset:b}=_a(a,f);f=b,d=e[s(1812)](e[s(1503)](d,8),0),d+=w}return{value:d,offset:p}}function qp(a,n,s){let d=t;if(e[d(1741)](e.oggzC,d(513)))_0x49e864[_0x302752++]=e[d(916)](e[d(1827)](e.RBBMo(_0x30f8c4,18),7),240),_0x1514bd[_0x377180++]=e[d(1756)](e[d(1764)](e.xJKqr(_0x52cbad,12),63),128);else return a?e.klunZ(a[d(1360)],40)?e[d(1758)](e[d(1398)](ga,a,n,s),s):n[d(1012)+"e"]?e.Cilhu(n.utf8Write(a,s),s):n[d(1348)]?e[d(1619)](n.write(a,s),s):e[d(1367)](e[d(822)](ga,a,n,s),s):s}function Gp(a,n){let s=t,d={XWaTF:e[s(2043)],ujIiw:e.FkWTI,ZmFmU:function(f,p,w){return e[s(640)](f,p,w)}};if(e[s(616)](s(1555),e.cgaUp))this[s(988)+s(1746)](),this[s(1426)](d[s(1652)],d[s(1703)]),this["_pingPon"+s(1577)+"Id"]=d[s(605)](_0x4c83b6,this._ping[s(1640)](this),_0x48cee9);else{let f=new xe(e.EcqPm(e.ZoxjT(e.RQTvb(e[s(1671)](a[e[s(1286)](n,4)],24),e[s(1035)](a[e[s(1602)](n,5)],16)),e[s(1035)](a[e.TAyay(n,6)],8)),a[e[s(655)](n,7)]),e.SoRVv(e[s(1840)](e[s(1793)](a[e.pVuRV(n,0)],24),e[s(1282)](a[e[s(1458)](n,1)],16)),e[s(1825)](a[e.QgyFG(n,2)],8))|a[e[s(1335)](n,3)],!0);return n+=8,{value:f,offset:e[s(683)](n,8)}}}function Hp(a,n,s){let d=t,f=a[d(1447)],p=a[d(1245)];return n[s]=e[d(1328)](p,24),n[e.TAyay(s,1)]=e[d(1530)](p>>>16,255),n[e.olQFs(s,2)]=e[d(1910)](p>>>8,255),n[s+3]=e[d(603)](255,p),n[e[d(602)](s,4)]=e.EAMGN(f,24),n[e[d(1763)](s,5)]=e[d(869)](e[d(1787)](f,16),255),n[s+6]=f>>>8&255,n[s+7]=255&f,s+=8,s}function _a(a,n){let s=t;return a.readUInt8?{value:a[s(846)+"8"](n),offset:e[s(567)](n,1)}:{value:e.ZXPMN(255,a[n]),offset:e.dRwQn(n,1)}}function ya(a,n,s){let d=t;return n[d(1969)+"t8"]?n[d(1969)+"t8"](a,s):n[s]=255&a,e[d(1792)](s,1)}let jp=function(a){return new Uint8Array(a)},Wp=e[t(1814)](e[t(505)],typeof Buffer)?Buffer[t(803)+t(1535)]:Mp(jp,Uint8Array[t(1958)+"e"][t(2111)]),Kp=16,ba=32;function $p(a){let n=t,s=0,d={};for(let f=0;e.aKOPN(f,a[n(1360)]);f++)d[a[f].cursor_name]=e[n(500)](ol,a[f]["cursor_n"+n(1583)]),s+=e[n(1432)](14,d[a[f][n(723)+"ame"]]);return[s,d]}function ul(a,n,s){let d=t,[f,p]=$p(a),w=Wp(f),b=0;return a[d(1047)](g=>{let C=d;console[C(1889)](e[C(1460)],g,g[C(2022)]),b=ya(0,w,b),console.log(e[C(1875)],b),b=Fp(w,b,g[C(2022)]||0),console[C(1889)](C(2022),b),b=e.Mhysk(ya,p[g[C(723)+C(1583)]],w,b),console[C(1889)](e[C(1771)],b),b=qp(g["cursor_n"+C(1583)],w,b),console[C(1889)](e[C(703)],b),b=e[C(948)](Hp,xe[C(1748)+"er"](g[C(1791)]||n),w,b),console[C(1889)](e.hkyBO,b)}),{frameType:ba,headers:[{key:e[d(1524)],value:s}],payload:w}}function Vp(a){let n=t,s=0,d=[];for(;e.aKOPN(s,a[n(2028)+"th"]);){let{offset:f}=_a(a,s);s=f;let p={cursor_name:"",cursor:0,service:0},{value:w,offset:b}=Up(a,s);p[n(2022)]=w,s=b;let{value:g,offset:C}=e[n(2002)](_a,a,s);s=C,p[n(723)+n(1583)]=e[n(1461)](al,a,s,s+g),s+=g;let{value:R,offset:P}=e[n(1145)](Gp,a,s);p[n(1791)]=R[n(1456)](),s=P,d[n(911)](p)}return d}function Zp(){let a=t,n={joKaz:function(s,d){return s||d},onUMr:function(s,d){return e[G(1101)](s,d)},KdwHw:e[a(505)]};return e[a(1595)](e[a(1658)],e[a(1658)])?!!(_0x29aeb9||_0x1e2d1c&&_0x4b5dcf[a(1227)+a(1049)]||_0x1b2364&&_0x85e73d[a(1227)+a(1049)]||eZtkSc[a(1564)](_0x44e0a9,_0x3d6804)&&eZtkSc[a(1724)](eZtkSc[a(705)],typeof _0x367da6)&&_0x4b4443):{frameType:ba,headers:[{key:a(1572)+a(1801),value:e[a(909)]}],payload:void 0}}class Jp{constructor(n,s,d){let f=t;this._cursorNameSpace=n,this["_cursorF"+f(576)]=s,this[f(1165)+"Strategy"]=d,this[f(1239)]=dl(this["_cursorN"+f(2064)],e[f(1324)])}async[t(989)](){let n=t;await this[n(1239)][n(989)]()}async[t(2077)+"rs"](){let n=t;if(!this[n(1239)].isReady)return;let s=this[n(1165)+"Strategy"],d=await this[n(1239)].getAll();switch(console[n(1889)](e.DYwFI,d),s){case e[n(590)]:return d&&d[n(1360)]?e.FePSN(ul,d,0,this[n(1330)+n(576)]):void 0;case e[n(1067)]:return;case e[n(782)]:return d&&d.length?e.OCmXg(ul,d,0,this["_cursorF"+n(576)]):e[n(1677)](Zp)}}async[t(1830)](n,s,d){let f=t;return console[f(1889)]("setdb",n,s,d),this[f(1239)][f(1830)]({cursor_name:n,cursor:s,service:d})}async[t(835)+"rs"](n){let s=t,d={hpLcc:function(f,p,w){return e[G(2087)](f,p,w)},NzJkX:function(f,p){return f|p},zutxA:function(f,p){return e[G(1764)](f,p)},TeFgf:e[s(1386)],pgOjC:function(f,p){return e[s(514)](f,p)},KtZcN:function(f,p){return e[s(1402)](f,p)}};if(e[s(1823)]!==e[s(1823)])IsoVnm[s(1420)](_0x43ad0c,_0x299728,IsoVnm[s(785)](IsoVnm[s(1472)](127,_0x3fdfda),128)),_0x23588d>>>=7;else{let f=Vp(n);for(let p of f)if(e.UvsiV(e[s(1709)],e[s(1140)]))console[s(1889)](e[s(757)],f),await this._qosDB[s(1830)](p);else return typeof _0x44d690===IsoVnm[s(1675)]?_0x11af9d(_0x465bd8):(IsoVnm.pgOjC(_0x450527,_0x1661c6)&&IsoVnm[s(2030)](_0x3d37f8,_0x3c356d),_0x4e0954(_0x2ef490,_0x1bfb53())?new _0x7ee16(_0x34de4e,_0x9c71ef):_0x572713)}}async[t(867)](n){let s=t;return(await this[s(1239)].get(n))?.[s(1791)]}async closeDB(){let n=t;await this[n(1239)][n(547)]()}[t(668)+t(1641)+t(1411)](n){let s=t;this[s(1330)+s(576)]=n}get[t(1224)](){let n=t,s={yfdBM:function(d,f){return d(f)}};if(e[n(1960)](e[n(1697)],e[n(1697)]))return this[n(1239)][n(1224)];_0x2b942a["frontier"+n(1769)]=void 0,xwWsby[n(1327)](_0x1596cf,n(1776)+n(621))}}let Xp=e.khDre;async function fl(a){let n=t;if(!this._options[n(1100)+"S"])return null;let{aID:s,fpID:d,messageStrategy:f}=this[n(531)],p=e[n(1025)](a,Xp);try{return this[n(2063)+n(849)]?a&&this[n(2063)+n(849)][n(668)+n(1641)+n(1411)](a):this["_cursorM"+n(849)]=new Jp(d+"_"+s+"_"+p,p,f),this[n(2063)+n(849)][n(1224)]||await this["_cursorM"+n(849)][n(989)](),this[n(2063)+n(849)]}catch{return null}}async function Yp(a,n){let s=t,d=e[s(948)](sn,a[s(1891)][s(913)],e[s(1847)],"-1"),f=e[s(1461)](sn,a.message[s(913)],e[s(802)],"1"),p=e[s(1383)](sr,a[s(1891)][s(913)],e.UQtEO),w=Number(sr(a[s(1891)][s(913)],s(642)+s(536)))||0,b=wa[s(1922)](this,a),g=e[s(822)](sn,a[s(1891)][s(913)],e.LsaeG,"2"),C=sr(a.message[s(913)],e.oRQGw),R=Number(e[s(753)](sr,a[s(1891)][s(913)],s(1989)+s(521)+"ue"));if(b[s(2069)])return e[s(2011)](n);let P=b[s(1425)+s(1332)]?await ll.call(this):null;if(e[s(647)](a[s(1891)][s(2022)],0)&&f&&!d||e[s(633)](a[s(1891)].service,0)){if(e[s(1215)]("YouMt",e.asyKz))return 0;if(p&&b[s(1425)+"sage"]&&P)return!!!await P[s(867)](p)&&(this["_dispatc"+s(471)+s(1712)](a),await P.set(p,e[s(1377)](Date[s(1696)](),w))),e[s(1677)](n);if(g){if(e[s(891)]===s(1942))throw _0x31e631=_0x36f5da[s(1360)],_0xa5f685(_0x34b7b1,10,_0x4158c0[s(1360)]);{let F=await fl[s(1922)](this);if(!F)return this[s(552)+"hMessage"+s(1712)](a),e[s(1915)](n);let B=await F[s(867)](C)??-1;if(e[s(1163)](B,R))this[s(552)+s(471)+s(1712)](a),F[s(1830)](C,R,a[s(1891)].service);else throw new Error(s(2032)+s(745)+" cursor "+R+(s(915)+s(1941)+"al cursor ")+B);return e.LEwqX(n)}}return this["_dispatc"+s(471)+s(1712)](a),e[s(1800)](n)}}async function Qp(a,n){let s=t,d={oNwdb:function(f,p,w){return e.vIJGi(f,p,w)}};if(e[s(1639)]===e[s(1639)]){let f=wa[s(1922)](this,a);if(!f[s(1425)+s(1332)])return e[s(1251)](n);let p=await ll[s(1922)](this);if(f[s(1129)+s(859)+s(1819)]&&f[s(1188)+"s"].length)for(let w of f[s(1188)+"s"])await p[s(1954)](w);e[s(1677)](n)}else _0x3d63b1(_0x37b35a,58),jAUVyU[s(917)](_0x2ba856,_0x4fa828,_0x354da2)}async function eg(a,n){let s=t,d=e[s(1688)](a[s(1891)][s(1740)+"e"],Kp),f=e.GKYcB(a.message.frameType,ba);if(e[s(786)](!d,!f))return n();let p=e[s(1141)](sr,a[s(1891)][s(913)],s(1572)+s(1801));if(!p)return n();let w=await fl.call(this,p);if(!w)return e[s(1915)](n);if(d){let b=await w[s(2077)+"rs"](),g={frameType:b?.[s(1740)+"e"],SeqID:xe.fromNumber(this[s(1055)]++),LogID:xe[s(1748)+"er"](this[s(531)][s(1676)+"erator"]()),service:9e3,method:5,headers:b?.[s(913)],payload:b?.[s(1731)]},C=e[s(2075)](S,g);this[s(1279)]&&this[s(1279)].readyState&&this[s(1279)][s(475)](C)}if(f){let b=a.message[s(1731)];b&&w[s(835)+"rs"](b)}}let tg=async function(a,n){let s=t;if(e.emsTo===e[s(1082)])this[s(833)]=!1,e[s(1190)](clearTimeout,this[s(711)+s(1181)+s(594)]),n();else{if(this[s(1279)]&&this[s(1279)].readyState===this[s(1571)+"NG"]){this[s(988)+s(1746)](),this["_pingPon"+s(1577)+"Id"]=e.PxjKz(_0x47b841,this[s(926)].bind(this),this[s(531)].pingInterval);return}if(!this[s(1279)]||e[s(486)](this[s(1279)][s(1040)+"te"],this[s(1926)]))return void this[s(1864)+s(1732)]();this[s(1279)]&&this[s(1279)].send("hi"),this[s(2061)+s(636)+s(851)]=e[s(530)](_0x34556d,this[s(1864)+s(1732)+s(1692)].bind(this),this[s(531)]["pingTime"+s(1007)+s(1713)])}},ng=async function(a,n){let s=t;if(!this[s(1279)]||e.FaXqh(this[s(1279)][s(1040)+"te"],this[s(1926)]))return e[s(2011)](n);let{pingInterval:d}=this[s(531)];this[s(1419)+"tManager"]?.[s(919)+s(880)+s(1399)]();for(let p=0;e[s(717)](p,this[s(1165)+s(1155)][s(1360)]);p++){let w=this[s(1165)+s(1155)][p];if(this[s(1279)].readyState===this.OPEN&&w!==null)this[s(1279)]&&this[s(1279)][s(475)](w),this[s(1165)+s(1155)][p]=null;else break}this[s(1165)+s(1155)]=this[s(1165)+s(1155)][s(763)](p=>!!p),this._pingPongTimeoutId=e[s(1979)](setTimeout,()=>this[s(926)](),d),this[s(552)+"hOpenEvent"](a),this[s(1894)+"er"]&&this[s(1279)]&&(this[s(1279)][s(660)+"pe"]=this["_binaryT"+s(1256)]);let f=this[s(1419)+s(1150)]?.[s(1882)+s(1468)+"nt"]();this[s(973)]("open "+f+s(1260)),e[s(868)](n)},rg=async function(a,n){let s=t,d={aebnO:function(f,p){return e[G(1458)](f,p)},uDjhh:function(f,p){return f+p},CTpmN:function(f,p){return f!==p},SYOfS:function(f,p){return f&p},xXxgQ:function(f,p){return e[G(1130)](f,p)},JLUrt:function(f,p){return f<<p},iVZCp:function(f,p){return f<<p},rkRbX:function(f,p){return f|p},ERhUl:function(f,p){return e[G(1326)](f,p)},MKAyq:function(f,p){return e.fPcHe(f,p)},hyKnq:function(f,p){return e[G(1557)](f,p)},TsfHh:function(f,p){return f<p},oDZFA:function(f,p){return e[G(1295)](f,p)},UBokj:function(f,p){return e[G(1939)](f,p)}};if(e[s(684)](e[s(480)],e.BdOUD)){let f=this[s(1419)+s(1150)]?.["getCurre"+s(1468)+"nt"]();this._debug("open "+f),e[s(1721)](n)}else _0x31157b=_0x31dd5b[MRDZSc[s(1492)](_0x2dabf3,_0x1e4dab)+1],_0x5f0ac1=_0x366e38[MRDZSc[s(474)](MRDZSc[s(1492)](_0x34434a,_0x53dc13),2)],_0x162fc6=_0x5910fd[MRDZSc[s(474)](_0x58bd82+_0x2f234c,3)],MRDZSc[s(631)](MRDZSc[s(1810)](MRDZSc[s(2041)](_0x2383b6|MRDZSc[s(1778)](_0xe384e4,8),MRDZSc[s(907)](_0x15f9cb,16)),12632256),8421504)?_0x16b922+=_0x2269b1:(_0x525e86=MRDZSc[s(836)](MRDZSc[s(773)](MRDZSc[s(966)](MRDZSc[s(907)](MRDZSc[s(1345)](7,_0x15163c),18),MRDZSc.JLUrt(63&_0x223c0d,12)),MRDZSc[s(1778)](MRDZSc.hyKnq(63,_0x1eb497),6)),MRDZSc[s(1810)](63,_0xe5d236)),MRDZSc[s(1214)](_0x43c3f8,65536)||_0x22840e>1114111?_0x3d22e4+=_0x3ca576:(_0x493f61-=65536,_0x49bd75+=_0x5efef5(MRDZSc[s(1699)](_0x79a16b>>10,55296),MRDZSc[s(856)](MRDZSc.SYOfS(1023,_0x508fab),56320)),_0x5b8e84+=3))};class ig extends pa{constructor(n){let s=t,d={WiNzF:function(b,g){return e[G(572)](b,g)},jYRnT:function(b,g,C,R){return e.QCOwB(b,g,C,R)},ZxBWI:"nNFIH",TUURD:function(b,g,C){return e.RKJsa(b,g,C)},OyzbV:e[s(729)],pQHHW:function(b,g){return b(g)},sNQxs:function(b,g){return e[s(1302)](b,g)},idpBX:function(b,g){return b+g},bBCxv:function(b,g){return e[s(2062)](b,g)},zgWnR:e[s(1813)],ZvzUg:e.mBXcL,BOgws:function(b,g,C){return b(g,C)},FZEhZ:e[s(1501)],sAOfh:e[s(523)],hTXER:function(b,g){return e[s(951)](b,g)},SwdEv:function(b,g,C){return e.sDYdu(b,g,C)},fXggw:function(b,g,C){return e[s(1322)](b,g,C)}};super(),this[s(1919)+s(692)+s(701)]=!0,this[s(1894)+"er"]=ir,this[s(741)]=yp,this._isMiniTT=Pn,this[s(877)+"X"]=Qr,this[s(2007)+"r"]=ei,this[s(1165)+s(1155)]=[],this[s(1419)+"tManager"]=null,this[s(731)+"osed"]=!1,this["_binaryT"+s(1256)]=s(1201)+s(1977),this[s(711)+s(2051)]=!1,this[s(711)+"ionTimeo"+s(594)]=null,this[s(2061)+s(636)+s(851)]=null,this[s(656)+s(1577)+"Id"]=null,this[s(1055)]=0,this[s(833)]=!1,this[s(997)]="",this["_QoSMana"+s(1288)]=null,this[s(2063)+s(849)]=null,this["_pingLos"+s(886)]=null,this[s(817)+"ls"]=e[s(1610)],this[s(832)]=3,this.CONNECTING=0,this[s(1926)]=1,this.CLOSING=2,this[s(1389)]=b=>{let g=s;try{d[g(1482)](sl,this,b,[tg,ng,rg])}catch(C){if(d.WiNzF(g(529),d[g(884)]))return _0xfc59c1&&mHJqAS[g(553)](!0,_0x2d2fd0[g(1137)]);{let R=d.TUURD(lt,d.OyzbV,{message:C[g(1891)],code:rn[g(1733)+"OR"],error:C});this[g(552)+g(609)+"ent"](R)}}},this[s(929)+"ge"]=async b=>{let g=s,C={wWxdV:e[g(651)],nEbQB:function(R,P,F,B){return R(P,F,B)},esfKe:function(R,P,F,B){return R(P,F,B)},SLZUI:function(R,P,F,B){return e[g(948)](R,P,F,B)},GxmOm:e[g(1460)],WbFEr:g(2022),HchvK:e[g(1822)],plAGN:e[g(703)],HEmmo:e[g(1771)]};if(e[g(783)](e[g(1881)],g(1380))){let[R,P]=mHJqAS[g(1440)](_0x4c4874,_0x1b4ae2),F=mHJqAS[g(1440)](_0x55da07,R),B=0;return _0x962050.forEach(te=>{let J=g,Pe=JWnRwW.wWxdV.split("|"),Oe=0;for(;;){switch(Pe[Oe++]){case"0":B=JWnRwW[J(1700)](_0x291a19,te[J(723)+"ame"],F,B);continue;case"1":B=JWnRwW[J(1854)](_0x1f3a8a,0,F,B);continue;case"2":B=JWnRwW[J(826)](_0x716dc9,F,B,te[J(2022)]||0);continue;case"3":_0x1d2b92[J(1889)](JWnRwW[J(1431)],te,te[J(2022)]);continue;case"4":B=JWnRwW[J(1854)](_0x310bac,_0x308795.fromNumber(te[J(1791)]||_0x399fea),F,B);continue;case"5":_0x4758aa[J(1889)](JWnRwW[J(1932)],B);continue;case"6":_0x83af95[J(1889)](JWnRwW[J(908)],B);continue;case"7":_0x3d31b5.log(JWnRwW.plAGN,B);continue;case"8":_0x55315b.log("header",B);continue;case"9":B=JWnRwW.nEbQB(_0x3ebe99,P[te[J(723)+J(1583)]],F,B);continue;case"10":_0x291088[J(1889)](JWnRwW[J(488)],B);continue}break}}),{frameType:_0x490118,headers:[{key:g(1572)+g(1801),value:_0x519b67}],payload:F}}else{let{pingInterval:R,pingFrequency:P}=this[g(531)];if((e.WzJGZ("hi",b[g(1579)])&&e[g(659)](e[g(1878)],P)||e.SeNUc(e[g(1436)],P))&&(this[g(988)+"ngTimer"](),this[g(1426)](e[g(2043)],e[g(2086)]),this[g(656)+"gTimeoutId"]=e.kyLpd(setTimeout,this._ping[g(1640)](this),R)),e[g(2033)]("hi",b[g(1579)]))return;try{e.nXPnm(sl,this,b,[Np,Op,Qp,eg,Yp,Lp])}catch(F){let B=lt(e.sDcYK,{message:F.message,code:rn["MESSAGE_"+g(1947)],error:F});this[g(552)+"hErrorEv"+g(1970)](B)}}},this[s(1427)]=b=>{let g=s,C=this[g(1419)+g(1150)]?.[g(1111)+"chMaxTries"](),R=this[g(1419)+g(1150)]?.[g(1882)+g(1468)+"nt"]();if(C&&!b.message)if(e[g(1325)](g(812),e[g(538)])){let P=_0x303b6a(_0xe4b6b9,_0x795aaa.limit),F=_0x31b833[g(1913)],B=_0x7d723b[g(1913)];for(let te=0,J=_0x3210af[g(837)];mHJqAS.sNQxs(te,J);te++)F[mHJqAS[g(1365)](te,P)]=B[te]}else{let P="connect "+R+(g(1730)+g(799)+"es reached");this[g(552)+"hErrorEv"+g(1970)](e[g(1474)](lt,e[g(729)],{message:P,code:rn[g(1276)+"IES_ERROR"],error:b}));return}this[g(1279)]&&e[g(864)](this._ws.readyState,this[g(1926)])&&this._disconnect(),this[g(552)+g(609)+g(1970)](e.mZKyT(lt,g(1508),{message:b[g(1891)],code:rn[g(1132)+g(1138)],error:b}))},this[s(957)]=async b=>{let g=s,C={nmomU:function(P,F){return d[G(954)](P,F)}};this["_clearTi"+g(1244)](),this["_clearPi"+g(1746)](),this[g(657)+g(984)+"rs"](),this[g(1279)]=null,this[g(711)+g(2051)]=!1;let R=this._endpointManager?.["checkRea"+g(1084)+"es"]();if(!R&&this[g(743)+"orOnline"]()&&!this["_readyCl"+g(549)]){if(d[g(828)]===d.ZvzUg)return BxGjME.nmomU(this.count,this.maxLossCount);{let P=this[g(1419)+g(1150)]?.[g(1882)+g(1468)+"nt"](),F=this[g(531)][g(661)+g(1783)+"ptor"](b.code,b[g(621)]);this[g(552)+"hCloseEv"+g(1970)](d[g(554)](gt,d[g(1232)],{code:1006,reason:b.reason||"connecti"+g(939)+g(1076)+g(1480)+g(1230)+g(825)+P,willReconnect:F})),F&&this[g(711)]();return}}if(b[g(1719)]!==1e3&&this[g(731)+g(549)]){this[g(552)+"hCloseEv"+g(1970)](d[g(479)](gt,d.FZEhZ,{code:1e3,reason:d[g(2117)]})),this[g(1419)+g(1150)]?.[g(919)+g(880)+g(1399)](),this[g(1125)+"sCounter"]?.[g(1566)+g(1272)]();return}if(d[g(1513)](1e3,b[g(1719)])&&R){let P=this["_endpoin"+g(1150)]?.["getCurre"+g(1468)+"nt"](),F=b[g(621)];F||(F=await d[g(1440)](Cp,this._url)),F=g(1488)+g(939)+g(1206)+F+(g(1346)+g(928))+P+", max retries reached",this[g(552)+"hCloseEv"+g(1970)](d.SwdEv(gt,d[g(1232)],{code:b.code,reason:F}));let B=g(601)+P+(g(1730)+"ax retri"+g(1127)+"ed");this[g(552)+g(609)+"ent"](d[g(1034)](lt,g(1508),{message:B,code:rn[g(1276)+"IES_ERROR"]})),this[g(1419)+g(1150)]?.["resetEnd"+g(880)+"fig"](),this._pingLossCounter?.[g(1566)+g(1272)]();return}if(d.hTXER(1e3,b[g(1719)])&&!b[g(621)]){let P=this["_endpoin"+g(1150)]?.[g(1882)+g(1468)+"nt"]();this[g(552)+g(2008)+"ent"](d.fXggw(gt,d[g(1232)],{code:b[g(1719)],reason:g(1488)+g(939)+g(1076)+"wn reaso"+g(1230)+"ame: "+P})),this[g(1419)+g(1150)]?.[g(919)+"pointCon"+g(1399)](),this[g(1125)+g(886)]?.[g(1566)+g(1272)]();return}this[g(552)+g(2008)+g(1970)](b),this[g(1419)+"tManager"]?.[g(919)+"pointCon"+g(1399)](),this[g(1125)+g(886)]?.[g(1566)+g(1272)]()},this[s(1657)]=null,this.onerror=null,this[s(1901)+"e"]=null,this[s(1966)]=null,this[s(1333)+s(1732)]=null,this[s(1418)+s(963)]=null,this[s(853)+"mediatel"+s(1222)+"ct"]=null,this[s(1593)+s(922)]=this[s(1593)+s(922)][s(1640)](this),this["_handleO"+s(2047)]=this["_handleO"+s(2047)][s(1640)](this),this[s(755)+s(1294)]=this["_handleP"+s(1294)][s(1640)](this),this[s(755)+"ageShow"]=this["_handleP"+s(974)].bind(this),this[s(531)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:1/0,service:0,logIDGenerator:o,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:s(1936),pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:"CONTINUE",env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:p}=n,w=Array[s(1183)](f)?f:e.wyDkx(e[s(1009)],typeof f)?[f]:[];if(!w||e[s(1594)](0,w[s(1360)]))throw new Error(e[s(1164)]);if(!vp(p))throw new Error(e[s(678)]);Object[s(522)](this[s(531)],n),this[s(1419)+"tManager"]=new il(w,this[s(531)][s(2078)+"es"]),this[s(1125)+s(886)]=new Ip(this[s(531)][s(1172)+s(760)]),this[s(531)][s(1839)+s(584)]&&(this[s(833)]=!0,this[s(711)]()),this._options[s(1948)+s(865)+s(1961)]&&(this[s(1387)+"T"]||this._isMiniWX?this[s(752)+s(2103)+s(648)]():this[s(1894)+"er"]&&this[s(645)+s(559)+s(1923)]())}[t(1593)+t(922)](){let n=t;this[n(531)]["disableA"+n(845)+n(1874)]||this[n(731)+"osed"]||this[n(1864)+n(1732)]()}[t(1593)+t(2047)](){let n=t;if(e.HWPiB(e[n(1837)],e[n(1837)]))_0x55f0fc[n(1707)+"oad"]="",_0x2f1ce3[n(1889)](_0x59d66f);else{this[n(689)+n(1331)+"t"]();let s=e[n(1147)](ha,e[n(933)],{message:n(606)+n(1869)+n(1933)+"ct"});this[n(853)+n(1585)+n(1222)+"ct"]&&this[n(853)+n(1585)+"yReconnect"](s)}}["_initGlo"+t(559)+t(1923)](){let n=t;this[n(1894)+"er"]&&window["addEvent"+n(1923)](e[n(1264)],this[n(1593)+n(922)]),this[n(1894)+"er"]&&window[n(1892)+"Listener"](e[n(805)],this["_handleO"+n(2047)]),this._isBrowser&&window[n(1892)+n(1923)](e[n(1110)],this[n(755)+n(1294)]),this[n(1894)+"er"]&&window["addEvent"+n(1923)](e.egYnT,this[n(755)+"ageShow"])}["_dropGlo"+t(559)+t(1923)](){let n=t;this[n(1894)+"er"]&&window[n(1409)+"entListe"+n(1650)](n(1537),this[n(1593)+"nLine"]),this[n(1894)+"er"]&&window[n(1409)+n(1908)+n(1650)](e.qEUjN,this[n(1593)+n(2047)]),this._isBrowser&&window[n(1409)+n(1908)+n(1650)](e[n(1110)],this[n(755)+"ageHide"]),this[n(1894)+"er"]&&window["removeEv"+n(1908)+n(1650)](e[n(589)],this[n(755)+n(974)])}[t(755)+"ageHide"](n){let s=t;if(!n[s(969)+"d"])if(e[s(1404)]===e[s(1404)])this[s(1894)+"er"]&&window["removeEv"+s(1908)+s(1650)](e[s(1110)],this["_handleP"+s(1294)]),this[s(1894)+"er"]&&window[s(1409)+s(1908)+s(1650)](e.egYnT,this[s(755)+s(974)]),this[s(1638)]();else return!!this._qosDB;this[s(1894)+"er"]&&window[s(1409)+s(1908)+s(1650)](e[s(1264)],this["_handleO"+s(922)]),this[s(1894)+"er"]&&window["removeEv"+s(1908)+"ner"](s(619),this[s(1593)+s(2047)])}_handlePageShow(n){let s=t;n[s(969)+"d"]&&(this._navigatorOnline()&&(!this[s(1279)]||e.selMk(this._ws[s(1040)+"te"],this[s(1926)])||e.WEHzj(this[s(1279)][s(1040)+"te"],this[s(1571)+"NG"]))&&this[s(1593)+s(922)](),this[s(1894)+"er"]&&window[s(1892)+"Listener"](e[s(1264)],this["_handleO"+s(922)]),this[s(1894)+"er"]&&window[s(1892)+"Listener"](s(619),this[s(1593)+"ffLine"]))}async["_generat"+t(2116)](n){let s=t,{fpID:d,deviceID:f,bddID:p,ttwID:w,accessKey:b,aID:g,customParams:C={},enableAutoAck:R,enableQoS:P,QoSLevel:F,env:B}=this._options,te,J,Pe;this[s(1894)+"er"]||this[s(877)+"X"]||this[s(1387)+"T"]?(te=location&&e[s(2104)](e[s(1902)],location[s(1890)])?e[s(1975)]:s(1470),J=n[s(511)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),Pe=/^wss(.*:\/\/)/[s(1218)](n)?n:""+te+J):(te=e[s(1975)],J=n[s(511)](/(^http)((?:[s]*:\/\/))/,""),Pe=/(^ws)((?:[s]*:\/\/))/[s(1218)](J)?J:""+te+J);let Oe=p?e[s(1499)]:w?e[s(994)]:e[s(1988)],on=p||w||f;if(e[s(1413)](!on,!Oe))throw new Error(e[s(1106)]);let Ke=e[s(1880)](s(959),typeof C)?await e.epIKg(C):C,ls=B?e[s(1956)](Ap,B[s(1005)],B[s(1944)]):{},On=Object[s(522)]({device_platform:e.zKVrO,version_code:e[s(1289)],access_key:b,fpid:d,aid:g,[Oe]:on,xsack:R?1:0,xaack:R?1:0,xsqos:P?1:0,qos_level:P?F:void 0,qos_sdk_version:2,...ls},Ke),ti=Object[s(879)](On)[s(1391)]((ze,ni)=>On[ni]!==void 0?""+ze+(ze?"&":"?")+ni+"="+On[ni]:ze,"");return Pe+s(1358)+ti}async _connect(){let n=t;if(!(this[n(711)+n(2051)]||this[n(731)+n(549)])){this[n(711)+n(2051)]=!0;try{if(e.mTLSK(e.JrtXR,e[n(1350)])){let s=this[n(1419)+n(1150)]?.["checkCur"+n(679)+n(2096)+"hedMaxRe"+n(663)](),{timeoutInterval:d}=this[n(531)];if(s){let p=this[n(1419)+n(1150)]?.[n(1882)+n(1468)+"nt"](),w=this[n(1419)+n(1150)]?.[n(580)+n(1790)+n(2016)+"UpdateCo"+n(2068)](),b=this[n(1419)+n(1150)]?.[n(1882)+n(1468)+n(1466)+n(2090)]();if(w){let g=n(601)+p+(n(1465)+n(1905)+n(1304)+n(706)+n(1031)+n(1516)+n(1123))+w+(n(2036)+"y"),C=e[n(756)](lt,e[n(729)],{message:g,code:rn[n(1276)+n(507)+"R"]});this[n(973)](g),this[n(552)+n(609)+n(1970)](C),this[n(997)]=await this[n(747)+n(2116)](w),this._debug("connect "+w+" "+b+n(607)),this._removeWsListeners()}else{let g=n(601)+p+(" timeout, max re"+n(1304)+"ached");this[n(973)](g),this[n(552)+n(609)+n(1970)](e.RKJsa(lt,e[n(729)],{message:g,code:rn[n(1276)+"IES_ERROR"]}));return}}else{let p=this[n(1419)+n(1150)]?.[n(1882)+"ntEndpoi"+n(1784)+n(829)](),w=this[n(1419)+n(1150)]?.[n(1882)+n(1468)+n(1466)+n(2090)]();this[n(997)]=await this[n(747)+n(2116)](e[n(1024)](p,"")),this[n(973)](n(601)+p+" "+w+n(607)),this[n(657)+n(984)+"rs"]()}if(this._isInit)this._isInit=!1;else if(e[n(487)](n(1116),e[n(1136)])){let p=ha("reconnect",{message:e.rZsJs});this[n(1333)+n(1732)]&&this[n(1333)+n(1732)](p)}else{let p=e.SABAp(_0x3775c8,_0x19f064,_0x4123a8);return _0x32132d[n(1913)][n(2111)](p,e.nvuSy(p,_0x21a8d5))}let f=this["_endpoin"+n(1150)]?.[n(1882)+n(1468)+n(1466)+n(2090)]()||0;e[n(1434)](f,1)&&await this[n(1338)](f-1),this[n(973)](n(1488)+"ng url: "+this[n(997)]+(n(1393)+n(1857))+this._protocols),this._ws=e.RccOP(Ep,{url:this[n(997)],protocols:[this[n(817)+"ls"]],headers:this[n(531)]["miniProg"+n(1963)+"s"][n(472)+"tpHeader"]},this[n(531)].ws),(this._isBrowser||this[n(2007)+"r"])&&this[n(1279)]&&(this[n(1279)][n(660)+"pe"]=this[n(1745)+"ype"]),this[n(998)+n(1366)](),this[n(711)+"ionTimeo"+n(594)]=e[n(1407)](setTimeout,this._onTimeout[n(1640)](this),d)}else{if(e[n(670)](4,_0x39528b[n(1360)])){let s=_0x14115a[n(1646)+"g"](0,e.jVPZZ(4,_0x1c388f[n(1360)])),d=s[n(943)](_0x212ce2);_0x1646d9[n(911)](d)}else _0x3d93b7[n(911)](_0xa7f19);_0x7b88c3&&(_0xd26bd1+=1),_0x3fe7fd+=1,_0x235a87=!1}}catch(s){throw this[n(711)+n(2051)]=!1,s}}}[t(2001)+t(1244)](){let n=t;e[n(1605)](clearTimeout,this[n(711)+n(1181)+"utId"]),this[n(711)+n(1181)+n(594)]=null}[t(988)+t(1746)](){let n=t,s={FxqmS:function(d,f,p,w){return e[G(600)](d,f,p,w)}};e[n(1096)]===n(1861)?hEWkRX[n(1329)](_0x1e18df,this,_0x351346,[_0x41275d,_0x3a62e5,_0x1d58c5]):(clearTimeout(this[n(656)+"gTimeoutId"]),clearTimeout(this[n(2061)+n(636)+"tId"]),this[n(656)+n(1577)+"Id"]=null,this[n(2061)+"ctTimeoutId"]=null)}[t(973)](...n){let s=t;this[s(531)][s(1473)]&&console[s(1889)][s(1051)](console,[e[s(793)],...n])}["_getInte"+t(972)+"e"](n){let s=t,{initReconnectInterval:d,maxReconnectInterval:f,reconnectIntervalGrowFactor:p}=this[s(531)],w=d*Math[s(555)](p,e.KdXaL(n,1));return e[s(1259)](w,f)?f:w}[t(926)](){let n=t;if(this[n(1279)]&&e[n(1087)](this[n(1279)][n(1040)+"te"],this.CONNECTING)){this["_clearPi"+n(1746)](),this[n(656)+"gTimeoutId"]=e[n(1020)](setTimeout,this._ping.bind(this),this._options["pingInte"+n(1378)]);return}if(!this[n(1279)]||e[n(1595)](this._ws.readyState,this[n(1926)]))return void this["_handleR"+n(1732)]();this[n(1279)]&&this[n(1279)][n(475)]("hi"),this["_reconne"+n(636)+n(851)]=e[n(1723)](setTimeout,this[n(1864)+n(1732)+n(1692)][n(1640)](this),this[n(531)][n(1312)+"outInterval"])}["_handleR"+t(1732)+"Timeout"](){let n=t;this[n(1125)+n(886)]?.[n(980)](),this[n(1426)]("ping_onc"+n(1691)+"t",e[n(2042)]),this["_pingLos"+n(886)]?.[n(1111)+n(1670)+"nt"]()?this[n(1864)+n(1732)]():this[n(926)]()}[t(743)+"orOnline"](){let n=t;return this[n(1387)+"T"]||this[n(877)+"X"]?this["_miniNav"+n(692)+n(701)]:(this._isBrowser||this._isWorker)&&this[n(531)]["listenNe"+n(865)+"nged"]?navigator[n(1202)]:!0}[t(1864)+t(1732)](){let n=t;!this[n(743)+"orOnline"]()||this["_readyCl"+n(549)]||(this["_endpoin"+n(1150)]?.[n(919)+n(880)+"fig"](),this[n(1125)+n(886)]?.[n(1566)+"nter"](),this[n(1279)]?this[n(1099)+n(1471)](1001,e.dQPZT,!0):this[n(711)]())}[t(752)+t(2103)+t(648)](){let n=t;this._isMiniTT?tt[n(1983)+n(2029)+"hange"](({isConnected:s})=>{let d=n;this[d(1919)+d(692)+"line"]=s,s?this[d(1593)+d(922)]():this["_handleO"+d(2047)]()}):this[n(877)+"X"]&&wx[n(1983)+"kStatusC"+n(2081)](({isConnected:s})=>{let d=n;this["_miniNav"+d(692)+d(701)]=s,s?this["_handleO"+d(922)]():this[d(1593)+d(2047)]()})}_wait(n){return new Promise(s=>{let d=G;e[d(1836)](setTimeout,s,this[d(695)+d(972)+"e"](n))})}["_disconn"+t(1471)](n=1e3,s="",d=!1){let f=t;this[f(1279)]&&this[f(689)+f(1331)+"t"](n,s,d)}[t(1785)+"ut"](){let n=t,s=this[n(1419)+n(1150)]?.[n(1882)+n(1468)+"nt"]();this._debug(n(601)+s+n(1465)),this["_disconn"+n(1471)](1001,n(1525)+n(1199)+n(1751)+"g",!0)}[t(1187)](n){let s=t,d=e[s(1254)](Ut,n);this[s(1279)]&&e.ZbuGx(this[s(1279)][s(1040)+"te"],this[s(1926)])&&(this[s(1279)]&&this[s(1279)][s(475)](d),this[s(973)](e[s(866)],n))}[t(657)+t(984)+"rs"](){let n=t;this[n(1279)]&&(this[n(1279)][n(1409)+n(1908)+n(1650)](e[n(1176)],this._onOpen),this[n(1279)][n(1409)+"entListe"+n(1650)](e.DUWUZ,this[n(957)]),this._ws[n(1409)+"entListener"](n(1891),this[n(929)+"ge"]),this[n(1279)][n(1409)+n(1908)+"ner"](e[n(729)],this[n(1427)]))}[t(998)+t(1366)](){let n=t,s=e[n(750)][n(852)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1279)][n(1892)+n(1923)](e.rzKJT,this[n(929)+"ge"]);continue;case"1":this._ws[n(1892)+n(1923)](e[n(729)],this[n(1427)]);continue;case"2":this[n(1279)]["addEvent"+n(1923)](e[n(1176)],this[n(1389)]);continue;case"3":if(!this[n(1279)])return;continue;case"4":this._ws[n(1892)+n(1923)](e[n(1501)],this[n(957)]);continue}break}}[t(1119)+t(1316)](n=1e3,s=""){let d=t;try{this[d(1279)]&&this[d(1279)][d(1638)](n,s)}catch{}}["_destroy"+t(1331)+"t"](n=1e3,s="",d=!1){let f=t;if(this[f(988)+f(1746)](),this[f(2001)+"mer"](),this._removeWsListeners(),this._wsInstanceClose(1e3,s),this[f(711)+"Lock"]=!1,d&&this["_navigat"+f(586)]()&&!this[f(731)+f(549)]){if(this["_endpoin"+f(1150)]?.["checkRea"+f(1084)+"es"]()){let w=this["_endpoin"+f(1150)]?.[f(1882)+f(1468)+"nt"]();this["_dispatc"+f(2008)+"ent"](e[f(1706)](gt,f(1638),{code:1006,reason:f(601)+w+(f(1465)+f(1905)+f(1304)+"ached"),wasClean:!0}))}else if(e[f(486)](e[f(1247)],e[f(1179)])){let w=this[f(531)][f(661)+f(1783)+f(2095)](n,s);this["_dispatc"+f(2008)+f(1970)](e[f(1303)](gt,e[f(1501)],{code:n,reason:s,wasClean:!0,willReconnect:w})),w&&this[f(711)]()}else try{return!!this[f(1239)]}catch(w){return _0x570a7d[f(1889)](w),!1}return}this["_navigat"+f(586)]()||this[f(731)+f(549)]?this[f(552)+"hCloseEvent"](e.nRNEW(gt,e[f(1501)],{code:n,reason:e[f(523)]})):this[f(552)+f(2008)+f(1970)](e[f(1075)](gt,e[f(1501)],{code:1006,reason:e[f(910)]})),this[f(1279)]=null,this[f(1419)+"tManager"]?.[f(919)+f(880)+f(1399)](),this[f(1125)+f(886)]?.[f(1566)+f(1272)]()}[t(552)+t(2115)+"nt"](n){let s=t,d={yIeeq:e[s(1110)]};e.JJmcn(e[s(510)],s(830))?(this._isBrowser&&_0x213832[s(1409)+s(1908)+s(1650)](s(1537),this._handleOnLine),this[s(1894)+"er"]&&_0x1c3e15[s(1409)+s(1908)+s(1650)]("offline",this[s(1593)+s(2047)]),this[s(1894)+"er"]&&_0x51afef["removeEv"+s(1908)+s(1650)](xQuggC.yIeeq,this[s(755)+s(1294)]),this[s(1894)+"er"]&&_0x5c7e1c["removeEv"+s(1908)+"ner"](s(964),this["_handleP"+s(974)])):(this[s(1426)](s(1999),n),this[s(1966)]&&this[s(1966)](n))}[t(552)+"hMessageEvent"](n){let s=t;this.emit(e[s(473)],n),this[s(1901)+"e"]&&this[s(1901)+"e"](n)}["_dispatc"+t(1063)+t(1494)](n){let s=t;if(e[s(977)]!==e[s(977)]){let d=this._endpointManager?.[s(1882)+"ntEndpoint"]();this[s(552)+"hCloseEv"+s(1970)](_0xc4da2e(e.DUWUZ,{code:1006,reason:s(601)+d+(s(1465)+s(1905)+s(1304)+s(1248)),wasClean:!0}))}else this[s(1426)](s(995),n),this[s(1418)+s(963)]&&this[s(1418)+s(963)](n)}[t(552)+t(609)+t(1970)](n){let s=t;if(e[s(1860)]===e.YRIiL)this[s(1426)]("error",n),this.onerror&&this[s(1900)](n);else return _0x48dad8|=0,{low:_0x54b280,high:_0x1b123b>>31,unsigned:e.tWNpb(_0x2c8766,0)}}["_dispatc"+t(2008)+t(1970)](n){let s=t;this[s(1426)]("close",n),this[s(1657)]&&this[s(1657)](n)}get[t(660)+"pe"](){let n=t;return this[n(1279)]?this[n(1279)][n(660)+"pe"]:this[n(1745)+n(1256)]}set[t(660)+"pe"](n){let s=t,d={eRGFB:function(f,p){return e[G(1271)](f,p)},LmIrG:function(f,p){return f<p},cuxlQ:function(f,p){return e[G(993)](f,p)},YVVWj:function(f,p){return e.OCFTK(f,p)},FqzAJ:function(f,p){return e[G(869)](f,p)},SDsTZ:function(f,p){return e[G(1522)](f,p)},dBevc:function(f,p){return f|p},SaaYs:function(f,p){return e[G(1729)](f,p)},ELMjN:function(f,p){return e[G(935)](f,p)},enkax:function(f,p){return e[G(1362)](f,p)}};e[s(1097)](e[s(1772)],e.rHZgv)?(this["_binaryT"+s(1256)]=n,this[s(1279)]&&(this[s(1279)].binaryType=n)):(wXSjSP[s(623)](_0x58287b,2048)?_0xf59710[_0x574871++]=_0x306b2b>>6&31|192:(wXSjSP[s(1722)](_0x414b37,65536)?_0x556b1f[_0x24bf3f++]=wXSjSP[s(1175)](_0x584f8f>>12&15,224):(_0x474288[_0x1e7379++]=wXSjSP[s(902)](wXSjSP[s(1102)](_0x4b8849>>18,7),240),_0x5d6090[_0x5af5de++]=wXSjSP[s(1175)](wXSjSP[s(1102)](wXSjSP[s(1161)](_0x5e9ecc,12),63),128)),_0x26cb80[_0x5f0492++]=wXSjSP.dBevc(wXSjSP[s(1310)](_0x5420db>>6,63),128)),_0x24e476[_0xb1057b++]=wXSjSP[s(1039)](wXSjSP[s(2106)](63,_0x5843d2),128))}get retryCount(){let n=t;return this[n(1419)+"tManager"]?.[n(1882)+n(1468)+n(1466)+"ount"]()||0}get[t(1934)+"Amount"](){let n=t,s=this[n(1165)+n(1155)][n(1391)]((d,f)=>(d+=f&&f[n(2028)+"th"]||0,d),0);return e.PfCvD(s,this._ws?this[n(1279)][n(1934)+n(568)]:0)}get[t(1285)+"ns"](){let n=t;return this[n(1279)]?this[n(1279)][n(1285)+"ns"]:""}get[t(1890)](){return this._ws?this._ws.protocol:""}get[t(1040)+"te"](){let n=t,s={EiqIk:function(d,f){return e.EErdJ(d,f)},pXRdm:e[n(729)],vnQzJ:function(d,f){return e[n(1287)](d,f)},iaGLo:function(d,f){return e[n(1408)](d,f)},shviI:e[n(936)]};if(e[n(1174)]!==e.TkQOa)return this[n(1279)]?this._ws[n(1040)+"te"]:this[n(531)][n(1839)+"cOpen"]?this[n(1571)+"NG"]:this[n(832)];{let d=this[n(1124)+"rs"][_0x360742];if(d)d[n(738)]()[n(1047)](f=>f.fn[n(1051)](f[n(1026)],_0x4e5557));else if(hdbwdj[n(904)](hdbwdj[n(1290)],_0x1148f0)&&!this[n(1900)]){let f=_0x22a4e0[n(1360)]&&_0xbf0e61[0];if(hdbwdj[n(1828)](f,_0x4b74c6))throw f;let p=new _0x54bbc4(hdbwdj.iaGLo(hdbwdj[n(1710)],f?hdbwdj.iaGLo(" ("+f.message,")"):""));throw p[n(1804)]=f,f}return this}}get[t(1274)](){let n=t;return this[n(1279)]?this[n(1279)].url:this[n(997)]}[t(1638)](n=1e3,s){let d=t,f=e.VEGPh[d(852)]("|"),p=0;for(;;){switch(f[p++]){case"0":this[d(1178)+d(559)+d(1923)]();continue;case"1":this._clearPingTimer();continue;case"2":this[d(2001)+"mer"]();continue;case"3":this[d(689)+d(1331)+"t"](n,s);continue;case"4":this[d(1487)+d(1288)]?.[d(547)]();continue;case"5":if(!this[d(1279)])return void this[d(973)](e.giTEd);continue;case"6":this[d(731)+d(549)]=!0;continue;case"7":if(e.lmfYA(this[d(1279)][d(1040)+"te"],this[d(832)])||e[d(1103)](this[d(1279)][d(1040)+"te"],this.CLOSING))return void this[d(973)](e[d(503)]);continue}break}}async[t(475)](n,s){let d=t,f={LEBgT:function(Pe,Oe,on){return e[G(1145)](Pe,Oe,on)}};if(e.QYSjW(null,n))throw new Error(e.jzeSZ);e[d(2104)](e[d(665)],typeof n)&&(n=JSON[d(1004)+"y"](n)),e[d(1009)]!=typeof n&&!e[d(1309)](n,ArrayBuffer)&&!(n.buffer&&n[d(900)]instanceof ArrayBuffer)&&(n=JSON[d(1004)+"y"](n));let p=await cl(n),w=e.anShy(Sp,n),{method:b=0,service:g=this[d(531)][d(2022)],logID:C=this[d(531)].logIDGenerator(),headers:R=this[d(531)][d(913)],payloadEncoding:P=this[d(531)][d(1241)+"ncoding"],payloadType:F=this[d(531)][d(1788)+d(1256)],logIDNew:B=this[d(531)].logIDNewConfig[d(2035)+d(1682)+d(564)+"ew"]?e[d(653)](i,this[d(531)][d(1235)+d(1307)][d(2058)]):""}=s||{};if(!g)throw new Error(d(551)+d(1995)+" valid s"+d(1374));let te={SeqID:xe[d(1748)+"er"](this[d(1055)]++),LogID:xe.fromNumber(C),service:g,method:b,headers:R,payloadEncoding:P instanceof Object?P[d(639)]?P.encoding:"":P,payloadType:F instanceof Object?F[d(2025)]?F[d(2025)]:w:F||w,payload:p,LogIDNew:B},J=e[d(1402)](Ut,te);return this[d(1279)]&&this._ws[d(1040)+"te"]===this.OPEN?(this[d(1279)]&&this._ws[d(475)](J),this[d(973)](e[d(1216)],te)):this[d(1165)+"Queue"][d(1360)]<this._options[d(613)+d(796)+"ength"]?e.BEiuO(d(1739),e[d(1888)])?(this["_message"+d(1155)][d(911)](J),this._debug("enqueue",te)):(ZGmwDS[d(1486)](_0x5df1be,_0x3d74b1,10),ZGmwDS[d(1486)](_0xb2cc59,_0x15d27f,_0x499c61)):(this[d(1165)+d(1155)][d(881)](),this[d(1165)+d(1155)][d(911)](J)),{seqID:this[d(1055)],logID:C,logIDNew:B}}async reconnect(n){let s=t,{url:d}=e[s(739)](n,{}),f=Array.isArray(d)?d:e[s(1880)](e[s(1009)],typeof d)?[d]:[];n&&Object[s(522)](this[s(531)],n),f&&f.length?this[s(1419)+"tManager"]=new il(f,this[s(531)][s(2078)+"es"]):this[s(1419)+"tManager"]?.[s(919)+s(880)+s(1399)](),this["_pingLos"+s(886)]?.["resetCou"+s(1272)](this[s(531)][s(1172)+s(760)]),this["_readyCl"+s(549)]=!1,this[s(1279)]&&e.zpXjt(this[s(1279)][s(1040)+"te"],this[s(832)])?this[s(1099)+s(1471)](1e3,e[s(949)],!0):(this[s(833)]=!0,this[s(711)]())}async[t(1838)](){let n=t;if(!this[n(711)+"Lock"]){let s=e.FIhLQ[n(852)]("|"),d=0;for(;;){switch(s[d++]){case"0":this["_readyCl"+n(549)]=!1;continue;case"1":this[n(1125)+n(886)]?.[n(1566)+n(1272)]();continue;case"2":this[n(1419)+n(1150)]?.[n(919)+n(880)+n(1399)]();continue;case"3":this[n(833)]=!0;continue;case"4":this[n(711)]();continue}break}}}addEventListener(n,s){let d=t;if(e[d(906)](e[d(1379)],e[d(2048)])){if(e.KHLSd(_0xe36e2c,_0x11d61c)<1)return"";let f="";for(let p=_0x517c62;p<_0x1c3878;){let w=_0x1c8b7f[p++];if(w<=127)f+=_0x407d28[d(2120)+d(2004)](w);else if(e[d(1992)](w,192)&&e[d(1357)](w,224))f+=_0x30be68["fromChar"+d(2004)](e[d(2034)](e[d(1438)](e[d(489)](31,w),6),e[d(1974)](63,_0x44a708[p++])));else if(e[d(497)](w,224)&&e[d(1835)](w,240))f+=_0x64167a["fromChar"+d(2004)](e.iNkUj(e[d(720)](e.vuEpX(15&w,12),e.igLOP(63&_0x15fde0[p++],6)),e[d(617)](63,_0x5a7fd1[p++])));else if(e[d(1726)](w,240)){let b=e[d(1144)](e[d(824)](e.fxQAe(e[d(562)](e.WANBY(7,w),18),e[d(1160)](e[d(1575)](63,_0x157822[p++]),12)),e[d(1359)](63&_0x251ea9[p++],6))|e[d(1618)](63,_0x4f7abb[p++]),65536);f+=_0x3bca60[d(2120)+"Code"](e[d(1045)](55296,e[d(1273)](b,10))),f+=_0x4cf589[d(2120)+d(2004)](e.cWCrN(56320,e[d(1151)](1023,b)))}}return f}else this.on(n,s)}["dispatch"+t(1712)](n){let s=t;if(e[s(1435)]==="IiIDL"){let{type:d}=n;this.emit(d,n)}else{let d=this._qosDB["getStora"+s(1749)](this[s(667)]);return _0x5d8e00[s(2119)](e[s(1846)](d,"{}"))[_0x39a798]}}[t(1409)+"entListe"+t(1650)](n,s){this[t(2088)](n,s)}[t(1985)](){let n=t,s={STTCc:function(d,f){return d(f)},AQKdj:n(840),Oqgee:e[n(2043)],yHpiu:e[n(937)]};return new Promise((d,f)=>{let p=n,w={xLNlK:function(C,R){return e[G(1883)](C,R)},gjloB:e[p(2042)],xDVda:e[p(2043)],qIslW:e[p(937)]};this[p(988)+p(1746)](),this[p(656)+p(1577)+"Id"]=setTimeout(this[p(926)][p(1640)](this),this._options[p(1606)+p(1378)]);let b=()=>{let C=p;s[C(912)](d,s[C(1996)]),this[C(2088)](s.Oqgee,b),this[C(2088)](s[C(1505)],g)},g=()=>{let C=p;w.xLNlK(f,w[C(1027)]),this[C(2088)](w[C(1114)],b),this[C(2088)](w[C(592)],g)};this.on(e[p(2043)],b),this.on("ping_onc"+p(1691)+"t",g),this._ping()})}}})(),Be[M(1512)+"oseEvent"]=Re[M(1512)+M(1899)],Be[M(1028)+"rorEvent"]=Re["CustomEr"+M(1193)],Be[M(1507)+"e"]=Re[M(1507)+"e"],Be[M(1712)]=Re[M(1712)],Be[M(1653)]=Re[M(1653)],Be[M(932)+M(672)+"vent"]=Re[M(932)+M(672)+"vent"],Be[M(672)+M(671)]=Re[M(672)+M(671)],Be[M(506)+"t"]=Re[M(506)+"t"],Be[M(1439)+M(658)]=Re[M(1439)+M(658)],Be["createCl"+M(1899)]=Re[M(624)+M(1899)],Be[M(1457)+"rorEvent"]=Re[M(1457)+"rorEvent"],Be[M(1856)+M(970)+"nt"]=Re.createMessageEvent,Be[M(982)+M(1674)]=Re[M(982)+M(1674)],Be["createRe"+M(1233)+M(671)]=Re[M(1421)+M(1233)+M(671)],Be[M(712)+M(1156)]=Re[M(712)+"rame"],Be[M(1171)+M(1583)]=Re["encodeFr"+M(1583)];for(jo in Re)[M(1512)+M(1899),M(1028)+M(1193),M(1507)+"e",M(1712),M(1653),M(932)+"MessageE"+M(671),M(672)+M(671),M(506)+"t","Reconnec"+M(658),M(624)+"oseEvent",M(1457)+M(1193),M(1856)+M(970)+"nt",M(982)+M(1674),M(1421)+M(1233)+M(671),"decodedF"+M(1156),"encodeFrame"][M(1950)](jo)===-1&&(Be[jo]=Re[jo]);var jo;Object[M(516)+M(2038)](Be,M(1459)+"le",{value:!0})});import{existsSync as uS,openSync as fS}from"node:fs";import{mkdir as xS}from"node:fs/promises";import{dirname as hS}from"node:path";import{fileURLToPath as pS}from"node:url";function mS(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Md(t=Q()){return uS(t.libEntry)?t.libEntry:pS(new URL("../index.ts",import.meta.url))}async function Nh(t={}){let e=t.paths??Q(),r=t.entryOverride??Md(e),i=mS(e,process.env.COZE_BRIDGE_LOG_MODE);await xS(hS(i),{recursive:!0});let o=fS(i,"a"),l=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=st(process.execPath,l,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[os]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return gS.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var gS,os,ta=et(()=>{"use strict";Vt();re();Le();gS=H("spawn-daemon"),os="COZE_BRIDGE_DAEMON"});import{spawn as l2}from"node:child_process";import{mkdir as u2,unlink as f2,writeFile as x2}from"node:fs/promises";import{dirname as h2,join as p2}from"node:path";function Jr(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function g2(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Jr(r)}</key>
21
- <string>${Jr(i)}</string>`).join(`
20
+ `+r)}function Jn(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let d=new Error(o);Error.captureStackTrace(d,Jn),t.emit("wsClientError",d,r,e)}else Xi(r,i,o,c)}});var Oh=oe(Me=>{"use strict";var B=V;(function(t,e){let r=V,i=t();for(;;)try{if(parseInt(r(1750))/1+-parseInt(r(872))/2*(-parseInt(r(906))/3)+parseInt(r(1612))/4+-parseInt(r(1103))/5+-parseInt(r(453))/6*(-parseInt(r(1830))/7)+-parseInt(r(1183))/8*(-parseInt(r(885))/9)+parseInt(r(1138))/10*(-parseInt(r(941))/11)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(jo,934145);var qv=Object[B(1144)+B(1663)],jv=Object[B(995)+B(1313)+"mes"],Th=(t,e)=>function(){return t&&(e=(0,t[jv(t)[0]])(t=0)),e},Wv=(t,e)=>{for(var r in e)qv(t,r,{get:e[r],enumerable:!0})};function Kv(){return vh||(vh=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function $v(){let t=B;return Sh||(Sh=[IDBCursor[t(1605)+"e"][t(807)],IDBCursor[t(1605)+"e"][t(510)],IDBCursor[t(1605)+"e"]["continue"+t(586)+"ey"]])}function Vv(t){let e=B,r={ERYxX:function(o,c){return o>=c},YTXLZ:function(o,c){return o<=c},NXHjx:function(o,c){return o+c},qiAoj:function(o,c){return o|c},NaPwE:function(o,c){return o%c},jXAaY:function(o,c){return o|c},tkEnW:e(1771),zgXYa:e(1622),klxbd:function(o,c){return o(c)},FzzyF:function(o){return o()},Gvrgy:function(o,c){return o===c},wnvph:e(413),UBCju:function(o,c){return o|c},euSzz:e(1068),ZPVgh:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let d=e,u={zphSO:r[d(1723)],PTAKs:r[d(757)],CbhNA:function(f,h){return r[d(1615)](f,h)},wBdtS:function(f,h){return f(h)},TgeGD:function(f){return r[d(1364)](f)}};if(r[d(1754)](d(413),r[d(557)])){let f=()=>{let w=d;t[w(1328)+w(1455)+w(1616)](u[w(1763)],h),t[w(1328)+w(1455)+"ner"](u[w(922)],g)},h=()=>{let w=d;u.CbhNA(o,u.wBdtS(Bt,t.result)),u[w(1660)](f)},g=()=>{c(t[d(1622)]),f()};t["addEvent"+d(658)](r[d(1723)],h),t[d(1091)+d(658)](r[d(757)],g)}else{if(_0x32cfb5(_0x1da1e6))return _0x57078a?_0x5d47a7:_0x2c9edb;if(_0x5a95a2){if(r.ERYxX(_0x3639cd,_0x46bd7e))return _0x4daa96}else{if(r[d(992)](_0x5ed8e5,-_0x49ae51))return _0x4ba12e;if(r[d(1070)](_0x232f7d,1)>=_0x59a63a)return _0x221aa1}return _0x8346d9[d(1467)](r.qiAoj(r.NaPwE(_0xcfef,_0xb33bca),0),r[d(732)](_0x23b8c2/_0x4b3e3d,0),_0x26ed19)}});return i[e(1877)](o=>{let c=e;r[c(1754)](c(1068),r[c(372)])?r[c(1746)](o,IDBCursor)&&Ld[c(1240)](o,t):(this[c(1321)]=!0,this[c(1828)]=r[c(565)](0,_0xd4acf7),this[c(1701)]=r[c(454)](0,_0x3fcc8a),this[c(397)]=!!_0x26a2e0)}).catch(()=>{}),Ko[e(1240)](i,t),i}function Yv(t){let e=B,r={fukwe:e(1652),eUUPV:"error",nWznW:e(1694),hQMIT:function(o,c){return o(c)},oOVas:e(519)+"or",JSEWQ:function(o){return o()},iyHxD:function(o){return o()}};if(Wo[e(869)](t))return;let i=new Promise((o,c)=>{let d=e,u={XldoR:function(w){return r.iyHxD(w)},kpBJf:function(w){return w()}},f=()=>{let w=V;t["removeEv"+w(1455)+w(1616)](r[w(1474)],h),t["removeEv"+w(1455)+w(1616)](r[w(1878)],g),t["removeEv"+w(1455)+w(1616)](r[w(459)],g)},h=()=>{let w=V;u[w(880)](o),u[w(1184)](f)},g=()=>{let w=V;r[w(482)](c,t[w(1622)]||new DOMException(r.oOVas,r[w(1578)])),r[w(731)](f)};t.addEventListener(r[d(1474)],h),t[d(1091)+d(658)](r[d(1878)],g),t[d(1091)+"Listener"](r[d(459)],g)});Wo[e(1240)](t,i)}function Zv(t){$o=t($o)}function Jv(t){let e=B,r={qPcWP:function(i,o){return i(o)},sbGzW:e(1147),FDXne:function(i){return i()}};return t===IDBDatabase.prototype.transaction&&!(e(1642)+e(1893)in IDBTransaction[e(1605)+"e"])?r[e(1112)]===e(1147)?function(i,...o){let c=e,d=t[c(1258)](Qi(this),i,...o);return Od[c(1240)](d,i[c(1569)]?i[c(1569)]():[i]),r[c(1884)](Bt,d)}:this[e(719)]?.[e(1240)]({message_id:_0x2e4bd7,timestamp:_0x2cfda7}):r.FDXne($v)[e(1173)](t)?function(...i){let o=e;return t[o(799)](Qi(this),i),Bt(Ld[o(1346)](this))}:function(...i){let o=e;return r[o(1884)](Bt,t[o(799)](Qi(this),i))}}function Xv(t){let e=B,r={yFeNb:function(i,o){return i(o)},lMLXr:function(i,o){return i instanceof o},DGqhY:function(i,o,c){return i(o,c)},Pztqg:function(i){return i()}};return typeof t===e(783)?r[e(520)](Jv,t):(r.lMLXr(t,IDBTransaction)&&r[e(520)](Yv,t),r[e(1500)](Rh,t,r[e(1359)](Kv))?new Proxy(t,$o):t)}function Bt(t){let e=B,r={yqMTH:function(o,c){return o instanceof c},dmuPd:function(o,c){return o(c)},drnco:function(o,c){return o!==c}};if(r[e(1209)](t,IDBRequest))return r.dmuPd(Vv,t);if(Ho[e(869)](t))return Ho.get(t);let i=r[e(1459)](Xv,t);return r[e(1833)](i,t)&&(Ho[e(1240)](t,i),Ko[e(1240)](i,t)),i}function jo(){let t=["tgnAz2O","uMvJB25Uzwm","s3bSAw0","BxLmrK0","Chnzsxu","C3vvt3a","sNL1C20","rxzLBNq","ENbOu08","su1Msvi","uNzQAgK","wfvrCMq","BwvZC2fNztO","D2PuC1C","zfDVCMTLCKC","DxnLCKLW","C3vJy2vZCW","AwDHDg9Yt24","zg9Uzq","CMvZB2X2zq","x2rItMfTzq","txD0Cgu","yNvwv3G","vhPKvvi","D1P6yuO","zM1jAhi","wLrWquq","suvtx0vsuK8","qNjPzgDL","yNLL","ueHWyvi","zfbwwNi","B2zM","ywzL","vKrstwy","AeHvB3G","zw9qDfu","whDMrxC","DffVvKS","ywrRsvO","zw5HyMXLqxu","Dg9tDhjPBMC","AuHHBe4","s1Htv1G","r01wy0y","zNjVBu51Bwi","DfL5zu0","sgDisMC","CMfUzg9T","rxrptwq","q3fAtxO","AuPKzvy","tg9NsurozxC","C2vYDMvYvgK","z3HTt08","rMTUs1a","yKDTzKW","u05erfO","C0jf","D1nYsNu","C2v0sxrLBq","x2LUAxrhBg8","D3jPDgvvAw4","x2LZv29YA2u","AxjLza","BwLZzq","u1rXrxa","sfvsDhy","EKnZCxm","Euf4zwi","CMvHC29U","ChDMEMm","EfvZzuvUDG","Bg93","Bwf4uMv0CMK","mtG2nti5weLcsMfZ","BKvRzfm","t2DPAui","zhjUy28","q2zQCfK","D1nLAg4","CMvKDwnL","B1fkvNK","zw50","y2HLy2TdDxi","AevYCM9Yrxy","DNjVsgO","twvLqw8","ywnOzwq","EeDczg0","DgLUzYbZzxi","thnAtfK","DxbKyxrLq3u","ENvjDMi","ywXSzwqGBxu","DxH5ugy","wKDPsxG","zxjFAxnFywm","zNjHBwvuExa","x2LUAxq","shDgwMG","D2HABKu","ug1ftve","yxnZAwDU","ChjVy2vZCW","A0LLqw8","C2fWuKu","CwPUzLG","r3bOwhi","CNnVCKzPBgu","BNbTBey","DwzLCKq","rKvcq1i","C3nHz2vfDMu","zM9YrwfJAa","swXpyLq","C3rYAw5N","zM1Vzhu","Chv0","qvbRChi","A3btqKm","x2rYB3bhBg8","DgHLBG","zvvvufy","BxnNsuq","wfDRz1y","Dw50","ve15wuS","EfnlqNi","CvbJv1a","vMjlwKi","teHetLG","s2jXAuO","y3vYC29Yx24","ruHHB1q","C3rHCNq","C3rLBMvYCW","AxfIBwm","B3jLtMfTzxm","we5nyNm","s1jrD1O","zNDQuum","BNrMuum","Bhm6ia","vfzkAgy","ywDL","AeTYwhG","Cw5ite4","B25pCgvU","EufbyNC","sxjHA1e","reiGzMfPBgu","DhjHBNnHy3q","qMz1B0S","tfb6vvC","De1HBMfNzxi","EK1PquS","zwvOsKy","runst2e","shfOBgS","CgXLyxnLiha","C3b5wM8","BMfTzq","yMPjAgK","C3jJ","wNzkv3m","zxf1ywXZ","vfj3t3O","whrTrgq","AxH4EKW","y2HnyxHuCMK","C2vUza","vK10uMW","zwrPyxrLBhK","CKXdu0S","C3LYrNq","t3j5wLi","zufJAW","zgXcr2S","DMfS","ywXS","BM5Ly3q","Ec11C2uT","zg5UueS","sxbxCve","rLDt","tuD0zK0","CgLUz19VBMm","zxvtENO","x2fKzfDZtgK","zxmGCMvHy2G","BNrfBMrWB2K","Dw5KzwzPBMu","zuzyr0O","yMLUyxj5","twTxCee","BvjrBKK","CNzHBa","rNzHD1a","CeDUrwe","quDqzva","Ee9qD20","DhDVCMTdAge","s2PNuhK","CwPOww0","DMvYC2LVBG","uxDrwMq","vgfN","qMnSB08","vvzdyKq","t1bftG","ugPIqLG","EgvtEue","Dw5ZAwDUzwq","yMXVy2TLza","zgvSzxrL","BgPcyMO","Aw5PDcbrB1m","yNL0zxm","wuztveK","rwjvzxO","v3Hwr2S","wNbOr2y","rfvJse8","zcWGDw5RBM8","CMvZzxrfBMq","AxvtBLq","tgLnwwW","ALz0qwi","yxvxsNm","ywnRx2LK","CNjVCK1LC3m","y29UBMvJDeu","A2TJA1m","wLzmqwC","DMvUDa","y3jLyxrLrxi","B3vUDa","uxLIB1u","x2LZtwLUAvC","yNPIz2O","yM9bv0q","zgzjCKu","x2HHBMrSzu8","DMfSDwvZ","verTyKW","tLPeAgG","ywnRx2nVzgu","veX4Dwi","v1bxt0i","EfLcqu0","BMnVzgLUzW","C2DPza","y1P2ugG","tgrWyKG","s25RENO","AKLeANC","tufyx1jfvfi","z1nyvei","igXHCMDLCIa","y09Wzw4","u2TPCcbWyxm","x3jLywr5q2W","yxGGCMv0CMK","ENvLDgy","EvjLy29UBMu","rKLmrv9ot1q","mxWYFdn8nhW","CMvHzhLtDge","mJeWv1jnBNrv","vujdANu","BIWGAg9ZDg4","u3fADgi","Ahr0Chm6","tw9KDwXL","BLD6BLC","igzPzwXKoIa","BxbcCw8","BePSsM8","BeXzzMW","tg9JAW","uKPfuLa","r25Avu0","yw1LoIa","y2vZC0HHBMq","rurbs2q","zgvSzxrLrge","vfPfzwe","BNbVzhm","BLbtz2S","AfnVt3G","ugTMvwW","ugvIvhC","q25ZCw4","yKHqt0y","y29UDgv4Da","qwXTDwS","Aw9Ul2PZB24","Affnsvq","EvHsAwi","tgvoAKi","DcbSAw1PDa","x3bHDgHlzxK","rwXuA3e","y01Xvw4","vg9Lsfi","wwT4v28","AM1gwhy","x3jLBw92zvC","zw5KCg9PBNq","yNvMzMvY","EffosKe","tuvtu0fhrv8","B25szwnLAxy","C2nYAxb0","shfZAKW","ugrws3C","AxDsz2i","AgfZt3DUuhi","DLj4Aum","ywrKq291BNq","tMXetgy","CMvZDwX0","qw1VDw50","uw1lzhK","CMvJB25Uzwm","y29UDgLUDwu","sLL0t0m","vgXvtfO","Dgv4DfbHEwW","B25fCNjVCG","sLDMANa","y29Uy2f0","u2THCfe","z3rUyNq","qwjVCNrfCNi","EuzLtMi","CMvXDwLYzwq","BMLTBfa","Aw5KzxHpzG","BNrLCG","vhfTsNO","AenSB3nLrxy","zgLZywjSzue","rffcCuq","EhvTt0C","yw5LuKW","uxzZwem","AhvpvKK","y29kCgS","ChrVCG","igfYCMf5yNu","zxH0zw5ZAw8","vLPKCgO","l3DZl3yY","AKr0uwi","CM9YrxzLBNq","AxnszwfKEq","wvHgy0S","CfnuDMO","shn6Exe","Eev5uem","qurUA0G","vfL1DuO","zNjVBuj5Dgu","Dg1QC0K","B2rszu0","q01bBvq","ruP1wKy","C0znyKG","sxnSrM8","ufHRvMS","wLL1Bfi","D252CgG","BxngEfu","D1r5zeq","q0Hnr2u","x2jPBMfYEvq","EwfZv1m","q2fhD0i","DxjS","CwLbB2O","u2vXsuq","tg52wKy","BwLUzW","zNjVBunOyxi","Dgntru4","AMvJDfn0B3i","DcbVzIbYyw4","C3bSAxq","EePRzMK","q0DnEKC","CKPkExi","y3vYC29Yx2y","zwPAEvi","sKzQCfG","vxHpqNq","q29UzMLN","ywX3yxLZ","r0reAhO","y29UBMvJDa","yw5ZzM9YBvq","uhjPBwfYEuS","BwvnBMK","DhD2qwq","Aw9U","y2XVC2veqG","C3vIC3rYAw4","r3HQAKm","ignVzgu6ia","DgLLCKPtt04","D0j6C1e","z3ftBfG","EvH4y1m","q3vZDg9Tq2W","AxnXDwK","q3vZDg9Trxi","r3nxswu","z29Iwxi","yM9krxu","A0jnvgq","yMLUza","Bwf4tg9ZC0m","z1fbzuO","DxHxvwm","AMzhtg0","rxLhAwe","vfjqDuW","BxfrAu4","uxHpy1y","DhPwz1G","vxbKyxrLq28","BNfvyNK","mtb8ohWWFdC","yw5Nzq","x2HHBMrSzvi","t2fUC0K","BfPtAeG","zxjFDhrS","rvz1wwC","x3bPBMC","BNvTyMvY","z2vY","CMvUDevUzha","vvDIBKO","yxP6zLC","x29Ut3bLBG","y3vYDMfSDwu","q29Kzq","C3bSAwnL","EKvPvvq","suLPwgi","DwL1zxi","tgzRuhG","r3POy0u","s1nfteO","CKj4sLO","sefgs1q","CMfNzvn5BMm","ywrKt25L","B3v0sw50zxi","qLHYzfi","mxW0Fdj8m3W","v2TxAfK","ysbTDxn0igi","CKP4ruC","wMLoq0K","zw5JB2rPBMC","C3vIyxjYyxK","sfnOvu0","Cgf5Bg9Hzfq","run6Exy","swXlsgS","BgLUzq","tgLZDgvUzxi","C2vYDMLJzq","wKzPrwy","zMXVB3i","v0ryEeq","uLbXwMy","CfPwv3q","EuPftNu","ChjVDg9JB2W","vev3Bfu","EgXfEwG","mxW1","te1eB00","rLfbuwW","wLHzBLy","zhLKC1O","DgzdzM0","DMDAAvC","yxKSihrYEsa","CgTwEMG","s2r2qNe","y3jLyxrLq2W","rNjVBNrPzxi","q0Xpu0ve","zM9Yy2u","CNHeALO","B1LnrKK","vLzyuw8","zuPct2e","DxbNCMfKzw4","uKHcwfu","rw10ANu","qwDpDNu","zKDAzvG","B3nLrxzLBNq","t1buv2G","vNPjtu0","r0HIEuq","DffOCw4","yxjYyxLIDwy","x2XPC3rLBMu","Dgv4Dc9WBge","x2rPC3bHDgm","DeLK","Cw9ZyLq","yLbJwK0","yw5KAg8","tfrswg0","ALLyuvG","CNnVCL9Uyw0","C2XPy2u","DMLJzuLeig8","CuriCfK","D05PuM4","CKX4Auu","zfrgAxu","B2nRzxq","B25TzxnZywC","uuPHvg0","AfvVBxq","zcbLCNjVCI4","x3fVC0rc","yxrLq291BNq","u0Xtqw8","CezjEM0","rLfyCxe","u2vIvxG","AwHnEee","A1fSy1i","D0zfB3C","EMzLAeq","A0v6CLe","zeXZuNe","sLnfv1e","ALHbyvK","Cg9PBNrdB24","BezSDxnO","Bwv0Ag9K","ENL0Cwe","DvLjy1i","ELLlCMK","x2LZtwLUAvq","AwPAufi","zejNr28","uxvLDwu","D3ztrLK","B25VCgvU","CgLUz1rPBwu","CMvHzg9UBhK","AwXLx25HBwu","B1L2A1O","AxnbCNjHEq","Bg9ws24","Dg9mB3DLCKm","DgvZDa","D2LSBfjLy28","y2uGBM90igK","C3jIv3K","r3PbwMG","EMDywwe","v2vIu29JA2u","q0Tcweq","Cg9W","zKXPAw4","CMnrvLy","uMvHzcbWyxm","r2zRDfm","x3nLCuLK","DK1OqNG","uhLowxq","Aw1LCYbPBIa","lcbOB3n0BMe","DwDRugS","C2DPAxG","Dg95Dei","rfjOwvG","zv90Aw1LB3u","AxnrB1nnzxm","zw5fDMvUDa","BwfW","DwvruwO","CMfTugfYyw0","zNjVBNrPzxi","zgvIDwC","wMreuvq","zNvUy3rPB24","qvjluMm","z2vrDwv1zuW","tuDfufe","rLLjsgW","u3j0zee","zvrwr28","zMX5te0","ihrPBwvZ","twvZC2fNzuu","BgLTAxq","s21kC2q","su5tvefova","EwnPDMm","zcWG","s3nAu1K","yxbWBhK","twz3D1K","uvDNufm","u2zpqLe","pxv0zI04","B2fK","CMfpwhG","ug9cz20","ywr2yw5Jzq","zKHjs1e","Du5Ns1G","BNruCMLLC0m","CMHuv0W","tgj0EK0","CxzbzK4","ALbutfu","Fdn8mNWXmhW","yM9KEq","EgfYsM4","tMjYseS","reHpsfq","CKvsuKm","BwvZC2fNzv8","r2Les2e","v2LpwvC","rKrnDeK","A0DZqxe","sNb4CKm","ihn1y2nLC3m","q2PHAvK","quXm","x2LZqNjVD3m","BfrPBwvVDxq","A0DkB0W","EgHJy3i","B3jL","tMXpCwq","tLbyExy","wLb1yKS","s1z5Bxq","rgHoBhm","tgfdAgS","CM9Vshe","rKzJDva","EvPsDLy","qw1Qy08","u0n4C3i","wxngsNC","Dg9VigXHCMC","zgvS","AxnrB1nby2S","D2j1CxC","v2vPEgLUsLm","rNn6v3e","B0XsCvC","BLDYuuu","qMfWwwi","BuXXC0S","BujKt3G","ywDLu2HVDW","CgfYC2u","Ew9VEha","x3DZsw5ZDge","BMDuAw1LCG","rwX0D1C","x2HHBMrSzva","x2n1CNnVCK4","qKThzvO","z0L4twy","DKX2sK0","AgfZ","zv9ZDwnJzxm","DhjPzxm","mZu5ndy2tujvq1jA","B25dBg9Zzq","Au9zCwC","Dff6AhC","BwvZC2fNzq","FdH8oxWX","uwDsy0e","BKXPBMu","wgXKB1i","n3WWFdv8mta","sNrnu1i","EuXxsui","BgvY","mtK2nJC5n0znAffIwa","x3nLBMrby2S","zgTszLi","BKr3v1e","A09Lrhy","Aw5KzxG","r01OsNu","nhWX","A2j6t0u","AvzlC0S","BMDLza","CgfNzxnOB3C","x3nVy2TLDa","C1n1z3y","quLNBvK","Cw9Z","yxv0BW","sNDJqK4","AKj0sue","y29UBMvJDgK","CMvJzwL2zwq","nNvzrxDJrW","B25rvxq","yw5Hz2vY","BLD2ufe","CNzKvhu","zgnQrfy","x0rctMfTzq","AwXLtMfTzq","z2v0qwXS","yw1mCu8","svzkvwe","svnvz1K","DhjPBq","yMrFzgLK","uwXqzey","Agnktw4","ufrbs3m","uM5UwMi","y3jLyxrLt3a","zxjHDg9Y","A2v5CW","q1nYugi","D3PPvMm","ANfbvee","yNL0zu9MzNm","DgfYz2v0","t1vcuMW","BhDMzKG","sMXOr3u","D3DIvva","whL1u1i","u3zmywW","A1n0yxr1C0m","yxbWzw5Kq2G","v0HSEMu","mtqYnJu5mJjuEMfysgS","vfHAtLa","BMnLq2XVC2u","m3WXFdb8nxW","Dhj1y3rVCIa","wwP4tvq","tvLNtMq","qLLSEuy","Aw5Lza","BM9Uzv9UB24","Cfzfy2i","werrs2e","sLnYDfK","uuDvBwq","z2vjBMzVu3K","AgvHzgvY","y0TvEKm","zgnXrgK","A0TWsMe","z3b4t2u","B2LUDfjLywm","Ce9greC","yunuzuK","yvn3Bey","vNbTB2C","ufPptfm","C2vYDMLJzs0","D3m6lY8","ChP6ChO","z2v0q3vYC28","r0frCNy","C0D3CKS","tMfTzq","BuX0zfa","v3bfzMu","B05IweK","BM93","B25JBg9Zzq","B2zMC2v0","twLZC2LUzYa","BNbwrw4","y2vXsfm","vfbQyNy","u0XSyM0","y3vYCMvUDeu","AgfUz2u","Cw5gv2C","uwHirM8","s1rnEMu","Cfr5wKG","BMrWB2LUDca","wvrytfO","zMLUza","AvzTDLG","z2v0t3DUuhi","D2z3DLO","ru9ItMC","x3bPBMDqB24","z1jyufe","Ae9Wzw5fDMu","uev5ALC","y3vYC29Y","z1biwLK","ywXSq3vYC28","y1nsuhm","zMvY","BgLZDgvUtMu","zu14q3q","q3bms3u","CMPRq3K","uLDfChm","rNzTwvC","yNvxsMW","Dw5RBM93BIa","CMv0CNLdB3u","wgTfEKC","x29UtwvZC2e","twrqDKq","y29Kzq","Cffivxu","y3jLyxrLt2i","y2HLy2Tszwe","quTsBuq","Bg9N","ANbxAuq","z3vVseO","BgvUz3rO","lcbTyxGGCMu","zw5XDwv1zq","B2nRzxrgywK","zw50zwqGDhK","qNnoq24","Cgf5Bg9Hzeu","tvLstve","tvHOq3q","ALffrLC","C2zwrKi","x2nSzwfYugK","rMXJqxu","rhDbrKG","D3j3wxq","shburKe","yKTrseC","zsbHihn0CMK","BfLWEwW","q2nose8","z3nrA3i","Cu16yuy","rwXowuC","DevywNO","D3Hwzwe","ihjLy29UBMu","CIb0DhDjra","AefVzKC","qvbTz2y","vxL6teq","Ae1LC3nHz2u","CwTbrKy","x2nSzwfYvgK","rg1quei","AgvHzgvYCW","svjZEKS","t1bftL9fuLi","qLHlq0e","wNjHwM0","uLPHEeC","r1Pfv2G","ExrOtMu","tfj2yuC","tLHiANG","ueDXz2i","ExbL","zuvHEeW","vuncyue","wvPov2K","CMjLzuC","Eg54Dhy","CMvWBgfJzq","zerTz2O","wLjSzMy","CMfTzq","C0zRuxq","svrWr1K","wgngA0m","EK9yuxC","sKH1B3K","tgvNEMi","q3feywC","zxjYtM8","Dg9cExrLC0W","ywrKrxzLBNq","x2nVBM5Ly3q","DgjKvMe","txHiCNO","C2XRrMS","AevfExi","re1cvfe","CeHmvei","Bg9Nsurhzw4","AeLTsuO","yuvoqKi","ywnRpwzYB24","nty3mZC3mfjsEKHUsa","rLzxELK","nxW0","y29UBMvJDfm","wfjLyva","A1D0qKi","zxjFCw9Z","CxvWDLi","DwL4rKe","C2jhELC","x29Uq2XVC2u","zw5HyMXLvhi","uNDKy2C","ufj1yM8","ywrK","Aen0Aey","Cg9PBNrbBMq","y2XLyxjtDg8","BwvY","ELDQC2C","zuLNrfa","x29UrxjYB3i","CLfhEvK","BgvVwgK","AeHyvxi","B1LyqM4","uwTtChK","CLrHrwC","u1LhzKy","shH4wwG","x2rLC3rYB3K","DhjPzxmGCMu","Cg93","x3DZ","D3DyD1e","mtb1rKL5zfa","BMjnvuq","CMvZzxrdB3u","B2LTAxC","sLnptLa","rw5Wq0O","zgvMAw5Luhi","q09otKvdveK","y3jQDw4","zfjwsfC","vu9MBwu","rgXxEhq","uuLjwvq","wNPsuwi","u3LnEhu","EgDmshi","zgv2AwnLx2K","yMfSu2nVCgu","q1HpuM0","vvbSCw0","tKfACxy","ihbYB3rVy28","q1fiqNa","r1n1AeG","CMvWBgfJzui","B0P2vfG","uMr5uwG","ihrYEsbYzwm","C3rVCcbPBw0","CM92AwrLihC","yKjyBwy","Dg5jz3u","C0TyweS","z2vtEw5J","u1fIu20","Aw5JBhvKzxm","tffiqvO","B25tDgfYDfi","AgnAsxy","rLfsq0i","Eg9uwe0","AuXfChm","DhLWzq","x3jLy29UBMu","y0jNrwC","ohfbCfzyEG","A3bcsMy","CeDpBxm","t0zyufm","se9gseS","q2HAsNq","vfjADxK","EhriBg8","u0z0uKO","DxHvD1y","B3n4y1a","y3jLyxrLtwu","B25ozxr3B3i","qwrNzKS","wgnOvu8","CKjhDwe","tLzhteG","x19LC01Vzhu","B3nLza","s05JqLG","yK1et3y","u0DqBve","nNWWFdu","EuvPrNC","AwPiuLK","yNvMzMvYzwq","ExfnveG","reXXsNe","yw1Lu3bHy2u","B2nRzxrtDwm","AxvftNa","BMTUEhu","uezHAva","rvfzruO","r0LYuwS","uhzey2O","z0f1CMK","Ewf5Cfm","Ce9OELu","seHZz3O","Befkwge","y2XVC2uSihC","BgLUzw5V","DxzgBK4","y29UC3rYDwm","Aw5L","q2n2uwG","qK5HDfm","B3jpBMXPBMu","vNrgyKG","B2zMBgLUzq","qwvqqKK","y3ruAw1LB3u","CM9YDxm","zxHWB3j0CW","z1rPBwvVDxq","AwLWq0W","C2v0","q09oveLovuu","CNnVCL92ywW","y0fhweS","mhWZFdf8nhW","zxjFCw9Zx2e","zgrjrcWGzgu","vevpue4","y3jLyxrLuMu","ueXiD2G","DhPPzNK","vfniDue","yxbWBgLJyxq","zMLSDgvY","wwPqD1O","x21LC3nHz2u","C0Lpt0u","o2nOyxjZzxq","y2fSBa","AvreAw4","D1LHC0e","Bg9NsurozxC","BwfUDwfSihi","zMLSzw5HBwu","AefJA01LC3m","BfLPA2u","AxnAzxjV","CLzHBhvLCW","Aw9UvgLTzw8","qMfXD3q","zMLN","CMvZzxruCMK","sMDdBeu","y3vYCMvUDeK","CMLxAKO","vw1rqwK","svrWBvC","uLzxrfG","x29UugfNzu4","ywjLEK0","ywHHA2G","zxjFywnRx20","DgfIyxnL","z2v0u3rVCMe","qM1Ktwm","Aw5KzxGGB3u","ywvICKK","wMDfBgO","ihrVihjLDhi","zxjYtxnN","zwnVBM5Ly3q","BxnN","vw5PBxbSzw0","zergAxe","swzLy2q","BxvMBMC","AKfmweu","uwzhCfq","z2v0s2v5","x2rPC2nVBM4","Fdf8nxW4Fdy","C2vUDa","yKr2B2G","svnAvhK","q0Xpu0LorW","mdaWma","svDmt0e","uxDisK8","Fdz8nhW5Fde","AM9PBG","Ef9MCM9UDgK","swDqqMu","BhzjshO","B3bLCNr5tMe","sNrpvLG","uuL6B0m","igzHAwWSig0","rxjYB3jdB2q","C2HRquK","qKTNChG","zgf0yq","AxnmB25N","Cgf5Bg9Hza","C0nVDw50zxi","sfnXEKW","tvHMshK","DMfSDwu","z1bXDhu","CMvTB3zLrxy","BvHAyKW","ugTwC24","nhWZFdj8mxW","sg1pAuO","DxrVuMvJB24","CgvYC2LZDgu","D2zmBM0","zLHAq1C","yuX2r00","BMCGDxjSoIa","vMfXEwK","Dvn6AK0","BwvKAwf0zwW","rhDVvvG","wNzpCxy","D2PpBem","x2rLyNvN","z2v0","vhfdBe8","CgLUz0LUDgu","sff6wgu","CKPsq2e","yMLUyxj5vhK","vvHkwee","z2v0q3vYCMu","svjPENu","wKvKBLq","CM92AwrLige","D0rNrhq","yM9L","uhP0CwC","B3DbC0G","B2L0y2i","C29Tzq","DxrMofDYAxq","rNP6Euy","C0Xf","rgz4BMS","uurODxa","sePIwKm","A2v5","wNbiDue","C2vUzf9Hy2S","ChfQzve","ruvkD0q","yw1L","DLfqAKK","uxHUuu0","Dwfcsvy","thvbD2y","DeLUDgvYy2u","A0HYy0O","Fdz8mtb8mNW","sNfItKS","Ec1TC2CTy3u","BKjiy3O","C0XPC3rLBMu","B3bLBKrc","x1fVu01HBMe","wgDQC1q","r0TiyMi","zMX1C2HfEha","nhWY","uLvcqNm","D3jtu2O","s29RqK4","wNf4uvi","senowu8","sw5hDNa","x2vUzhbVAw4","q0LIEMe","svrXu2S","D3nZoI8V","tKfusvzfx0u","u2vYDMLJzvC","DLbcBwO","BMvLzf9Hy2S","yxnJCMLWDa","zhPTsfC","ChvZAa","rvndDfu","z2v0qwXSs2u","Dg9iyxnO","rwrHyxO","ywnRDxbfBMq","ruvUEKi","AxLdA1u","u05QtNu","C2fNzq","r0DSvfe","DMvY","wKveBM0","ChbL","u2nMB0S","DevdAg8","y2rwCu0","CgTZt0m","B25SAw5L","BxDjzhO","CNzHBfzHBhu","q0XOrLi","Dg1Jt04","B2nzywm","qLvJAem","DM1kDey","z2DlAhu","zg1rree","ywDLsgLKzq","teDbz0G","x2LZsw5PDa","z2u6ia","tunLEfO","wvfbEMW","CMvHzfvjBNq","A1L3vLu","uK5JyMy","yuLSrvu","v1bSseG","Fdj8m3W1","qLDIC3G","uhv2z0S","ywnRtxnNswq","z0TWtgq","zMDoq1y","D1nwtwO","A3fRse8","zw50tgLZDgu","uwP5qva","uLjpuG","ig1LC3nHz2u","zg11ugq","uefysKe","v1nytxC","B3bLBIa","x3bYB3rVy28","ywruCNq","DgvmB2Djre4","BfnQrum","zNjVBujPDhm","CgjICdi","AfvYrMK","rgfsqKq","yKzlz0C","Bw5dELK","tKDFrvjst1i","zNvRD2u","mdaWmdaWmda","rM5NELK","uuvNCM4","yuj4q1e","u09hAfa","yMzuzxa","qNPtCK4","AwXK","r0jptve","A3DNwuK","vgvqveC","DhzYsfO","B3DrA24","t2jQzwn0","t1nKww8","yNLfvhy","mhWYFdr8mxW","Aw47y2HHCNm","CMLLC0nVDw4","x0vysvnu","AvLUs2C","vw5Oyw5KBgu","uKngC0W","Ec1TC2CTCw8","B25nzxnZywC","reDXAfK","v3fpBfK","u21JAxy","wMvpALu","qvHkD1O","CNb4wfG","rLjACu8","uNLluvG","wMXAwLi","BvjjDxO","sMnrEMS","x2n1CNnVCK0","yxnL","vMrxtLu","ihrPBwvVDxq","z0HWq1K","rK1qEKO","tvnkwKy","Aw5N","zMHSCxm","x2LUDgvYDMe","CwzHywO","nxWYFdn8mhW","CNfiEwi","ywDLrxzLBNq","sfjTqwm","DM1HveK","Dhzyq0i","CYbWyxjHBxm","wNn4s2G","BevfDxK","AMDnuNy","DgLTzw91Da","zgvJB2rLzey","sNf1DMq","qMfvy1e","zKndCu4","Dev2zw50","BuXSqvq","s0HTENm","BMCGzMfPBgu","tvbnwLy","vKnVDeG","D24GCMvHC28","zw5HyMXLuw8","zvzwvuS","AKHWEgK","BuT1vuq","rNnABLm","yMfJA3vWigu","qw5IDfO","Bwu6ia","uMPdBhy","tvHbAxO","B3bLBG","zw1LBNq","B1fmzKu","DMvYC2LVBMm","wgrhrLm","B25LCNjVCG","yxKSig5LDhC","EgzbsxC","yuDkzNa","AKLZDu4","z1juCuy","EuTQywe","s2jPDuK","C1frBhe","y3PxuuG","C29YDa","Dg9Y","ALrsrLa","BMCGB3iGyw4","aaaaaaaaaaa","BMv3vMvYC2K","x2DLBMvYyxq","CwTIwgW","Cw9Zx18","B09wyxm","rhbYAxe","yxv0B21HDgK","Dhr3Awq","zxrxB3jRq2G","x25HDMLNyxq","sMPvzxu","BMrLEa","z2HNrgq","x2LZtM9Kzq","DM5oBMe","DhD1CeS","x2zVCM1HDeu","ywXPzcb1CMW","DvL0qM8","rxLnrem","y2XVC2u","z2DArMm","z2v0sxrLBq","wuXKBNi","yw51Ce1LC3m","DuDSvuy","nhWXmxWZFdG","r2f3s3q","zwTKDhG","qu5RAeC","Dg9cExrLC0i","ChjVDg90Exa","CgLUz09Uy2u","CvvOuuO","CMrZA1C","zwn0","twnWsuG","s0POruW","nde4mtq3nKfqzfjREa","BNrbBMrvCgq","mxWYFdn8mhW","A2X4yMq","BMvY","rvjst1i","DgXXyLe","wwXzsNG","CMvJzxzPzwq","y2HnyxHdB3u","zxjYB3i","x2DLDeLUDgu","ug5Zs08","tg9Nsuq","CLDcCK8","C3rYAw5NAwy","CgLUz0XVC3m","uNrpANi","Dxrjza","s0Lbsxq","s216uwW","z29PBMCGyxC","C3rVCMu","tgfVAMm","DhbizwfKzxi","x29WDgLVBNm","DeDXEwy","yvnzDgq","B0XdrMK","Dg9hzw5LCMe","B2jQzwn0u3q","Dgvuvxq","zeLduhq","B25tDg9Wsw0","yMfSrxzLBNq","sKjIv0y","zw1PDa","Fdj8nhW2Fdm","A0LYBKi","vhPQCuC","y29TCgXLDgu","Efrurw52","CgfNzwHPzgu","qu51uLC","tuXvshe","thHVr3m","x2nYzwf0zvm","Dg9oDw1Izxi","vgDLr0q","x2LUAxrqCM8","zMzmAw5L","B3bLCNr5","wKTzELO","rw1JDvy","B3jRzxjhBg8","DNnYu24","y3vZDg9Tshq","y29SBM8","zxq9DxrMltG","B09Huem","x2TLEvbHDgG","BMv4DcGPigm","uxHhrvq","CMvQzwn0","yu1equm","BeHHBMrSzxi","x3vYBa","uxrUAgG","r1joC2S","zgXQsgS","yLHms2u","tvLcB1C","D296Dwu","y2XLyxi","ExzYv2q","yxrrzfO","vK9tBfu","zwr3v24","t3bLBKv2zw4","Axnby2TdBgu","AxDsCKG","B25Uzwn0Aw4","ywjVCNq","q291BNq","u3zOuuu","BMrWB2LUDfq","wxnxCvy","qLfzBfq","yLfKELa","AgLNAa","ywnOzwqSihC","r2L2Due","D2vI","vLL6r3u","Dgv4Dc9Qyxy","x2n1CNnVCKy","y2HmAha","x21PBMLoyxy","rLnQteG","zxj2AwnL","tLDzqKy","t3r4wg0","BhnHze4","AeLjEfa","B3byDwy","zw5JB2rLrNi","BxHVtvq","vuHNCvy","B1bgr3G","EfvNAg0","Ew90D1K","DgTfBLC","ze9Izum","Dg9cExrLCW","Ahr0Ca","y29UBMvJDca","x29UvgLTzw8","x3bYzwzPEa","EgTSy2S","vefesKW","v2viuNi","icSG","y3jLyxrLrwW","y3vYC29YlNm","y2HHCKnVzgu","x3bPBMDmB3m","v3L2weC","mNWXFdn8mhW","EeXKrLG","yNL0zuXLBMC","teHdzMe","weXJteK","vKTNy2W","tLPVuNm","wLbwz2G","y291BNq","sw1swvC","ufjrwMW","oda5nZG4CefRvLbl","BeXwA2G","zKrKrxO","B2rbyNq","r3zYz3K"];return jo=function(){return t},jo()}var Rh,vh,Sh,Ld,Wo,Od,Ho,Ko,$o,Qi,Ih=Th({"node_modules/idb/build/wrap-idb-value.js"(){let t=B,e={WeHRr:function(r,i){return r+i},gRTqF:function(r,i){return r|i},hEEyr:function(r,i){return r>>i},NSEFk:function(r,i){return r&i},OgfNN:function(r,i){return r>>i},owQkn:function(r,i){return r===i},XEZpd:"okyeU",dDFiq:t(1700),ZgElj:function(r,i){return r instanceof i},wNiRn:t(1773),zotfn:function(r,i){return r===i},TqmJz:t(1634),npods:function(r,i){return r!==i},gSXTB:t(1215),DhNls:t(1223),qvAfN:function(r,i){return r===i},jIDjw:t(484),HMOia:function(r,i){return r in i}};Rh=(r,i)=>i[t(1362)](o=>r instanceof o),Ld=new WeakMap,Wo=new WeakMap,Od=new WeakMap,Ho=new WeakMap,Ko=new WeakMap,$o={get(r,i,o){let c=t,d={lYpyl:function(u,f){return e[V(1732)](u,f)},eEaxL:function(u,f){return e[V(1564)](u,f)},oYvkZ:function(u,f){return u&f},rJRCa:function(u,f){return e[V(1096)](u,f)},ugkPk:function(u,f){return e.NSEFk(u,f)},lTuxK:function(u,f){return e.OgfNN(u,f)}};if(e[c(1487)](e.XEZpd,e[c(1293)])){let u=_0x5a3542(_0x58d150,_0x480480);return _0x1409b1.bytes[c(652)](u,d[c(1045)](u,_0x20267d))}else{if(e[c(1287)](r,IDBTransaction)){if(e[c(1487)](i,e[c(711)]))return Wo[c(1346)](r);if(e[c(1487)](i,"objectSt"+c(1893)))return r.objectStoreNames||Od.get(r);if(e.zotfn(i,e[c(525)])){if(e[c(472)](e[c(442)],e[c(839)]))return o["objectSt"+c(1893)][1]?void 0:o[c(1642)+"ore"](o[c(1642)+c(1893)][0]);_0xb2a27d[_0x42a195++]=d[c(1073)](d[c(748)](d[c(1350)](_0x57c0b8,18),7),240),_0x2e2194[_0x345faf++]=d[c(1073)](d[c(770)](d.lTuxK(_0x4db71c,12),63),128)}}return Bt(r[i])}},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return e[o(1287)](r,IDBTransaction)&&(i===e[o(711)]||e[o(813)](i,e.TqmJz))?e[o(813)](e.jIDjw,e[o(440)])?!0:this[o(985)+o(1697)+"riesCount"]:e.HMOia(i,r)}},Qi=r=>Ko[t(1346)](r)}}),Ch={};Wv(Ch,{deleteDB:()=>eS,openDB:()=>Qv,unwrap:()=>Qi,wrap:()=>Bt});function Qv(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let d=B,u={tQhqn:function(g,w){return g(w)},FvawP:d(1594),ekdtx:d(1557)+"hange",dObeC:function(g,w){return g(w)},vRxiC:d(687)+"eeded"},f=indexedDB[d(1554)](t,e),h=u[d(1724)](Bt,f);return i&&f[d(1091)+d(658)](u[d(503)],g=>{let w=d;i(u[w(696)](Bt,f[w(506)]),g.oldVersion,g[w(1574)+"on"],Bt(f[w(1907)+w(589)]))}),r&&f[d(1091)+d(658)](d(398),()=>r()),h.then(g=>{let w=d;c&&g[w(1091)+w(658)](u[w(382)],()=>c()),o&&g[w(1091)+w(658)](u[w(1602)],()=>o())}).catch(()=>{}),h}function eS(t,{blocked:e}={}){let r=B,i={ahakh:r(398),GMhJu:function(c,d){return c(d)}},o=indexedDB[r(470)+r(1282)](t);return e&&o[r(1091)+r(658)](i[r(1280)],()=>e()),i[r(891)](Bt,o)[r(1877)](()=>{})}function Ah(t,e){let r=B,i={xeSyA:"readwrite",oinPL:r(746),FYIHl:function(f,h){return f in h},pSJHc:function(f,h){return f===h}};if(!(t instanceof IDBDatabase&&!i[r(787)](e,t)&&i.pSJHc(typeof e,r(1871))))return;if(qo[r(1346)](e))return qo[r(1346)](e);let o=e[r(1078)](/FromIndex$/,""),c=e!==o,d=Ph[r(1173)](o);if(!(o in(c?IDBIndex:IDBObjectStore)[r(1605)+"e"])||!(d||Dh.includes(o)))return;let u=async function(f,...h){let g=r,w=this[g(1907)+g(589)](f,d?i[g(396)]:i.oinPL),S=w[g(1634)];return c&&(S=S[g(890)](h.shift())),(await Promise[g(1935)]([S[o](...h),d&&w[g(1773)]]))[0]};return qo[r(1240)](e,u),u}var Dh,Ph,qo,tS=Th({"node_modules/idb/build/index.js"(){let t=B,e={dLsRq:t(944)+t(1391),sSugv:t(1346),PuvgK:t(1298),vRjsx:t(1747),twIVK:function(o,c){return o(c)},CSrPb:function(o){return o()},kBXgC:t(1117),OWZHp:"delete",MdgNz:t(1685)},r=e[t(730)].split("|"),i=0;for(;;){switch(r[i++]){case"0":Dh=[e[t(898)],e[t(1449)],t(914),"getAllKeys",e.vRjsx];continue;case"1":Ih();continue;case"2":e.twIVK(Zv,o=>({...o,get:(c,d,u)=>Ah(c,d)||o[t(1346)](c,d,u),has:(c,d)=>!!Ah(c,d)||o[t(869)](c,d)}));continue;case"3":e[t(927)](Ih);continue;case"4":qo=new Map;continue;case"5":Ph=["put",e.kBXgC,e.OWZHp,e.MdgNz];continue}break}}}),nS={idb:function(t){let e=B;t.exports=Promise[e(1774)]().then(()=>(tS(),Ch))[e(1877)](function(r){return r})}},kh={};function Mt(t){let e=B,r={kLNnD:e(1491)+"3",ckKIV:function(u,f){return u!==f}},i=r.kLNnD[e(573)]("|"),o=0;for(;;){switch(i[o++]){case"0":var c=kh[t];continue;case"1":nS[t](d,d[e(1237)],Mt);continue;case"2":if(r.ckKIV(void 0,c))return c.exports;continue;case"3":return d[e(1237)];case"4":var d=kh[t]={exports:{}};continue}break}}Mt.d=(t,e)=>{let r=V;for(var i in e)Mt.o(e,i)&&!Mt.o(t,i)&&Object[r(1144)+"operty"](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=B;Mt.o=(e,r)=>Object[t(1605)+"e"][t(502)+"operty"][t(1258)](e,r)})(),(()=>{let t={uferD:function(e,r){return e!=r},EVuYg:"undefined"};Mt.r=e=>{let r=V;t[r(1866)](t[r(623)],typeof Symbol)&&Symbol["toString"+r(391)]&&Object[r(1144)+r(1663)](e,Symbol["toString"+r(391)],{value:r(458)}),Object[r(1144)+"operty"](e,r(1200)+"le",{value:!0})}})();var Ce={};function V(t,e){t=t-366;let r=jo(),i=r[t];if(V.xcimGm===void 0){var o=function(f){let h="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",g="",w="";for(let S=0,_,v,I=0;v=f.charAt(I++);~v&&(_=S%4?_*64+v:v,S++%4)?g+=String.fromCharCode(255&_>>(-2*S&6)):0)v=h.indexOf(v);for(let S=0,_=g.length;S<_;S++)w+="%"+("00"+g.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(w)};V.YKIkll=o,V.FdOkOZ={},V.xcimGm=!0}let c=r[0],d=t+c,u=V.FdOkOZ[d];return u?i=u:(i=V.YKIkll(i),V.FdOkOZ[d]=i),i}(()=>{let t=B,e={npmlF:"is_ack",XgjsT:t(414),cZvPh:function(a,n){return a||n},MXfHy:t(431),wjOlC:function(a,n){return a===n},CQHBp:t(764),ycivc:function(a,n){return a+n},nWrQE:function(a,n){return a*n},oYMFI:function(a,n){return a(n)},cBgEg:function(a,n,s){return a(n,s)},ChZJt:t(1426),ZdDQT:t(1654),hSoOx:t(896),rLxiE:function(a,n){return a===n},gZEou:t(1541),RWEps:function(a,n){return a+n},rTaEg:function(a,n){return a!==n},pDCFg:t(1192),rWBrO:t(1352),QhHFo:function(a,n){return a(n)},ceqHS:function(a,n){return a+n},Dfxnk:function(a,n){return a(n)},DMBTQ:function(a,n){return a+n},abezM:t(1305),ANuRW:"ffff",LTRXm:"ZKYzZ",CpJKo:t(1475)+t(1475)+t(1475)+t(1475),xarJn:t(1402)+t(1457),buVWx:t(1145)+t(1473),SQbSm:"MAX_RETR"+t(1782)+"R",TZEea:t(496)+t(1617),KjgPy:t(1855),NVGLH:function(a,n){return a>n},CcvQh:t(621),JlhGu:t(546),bKQHG:t(1567),HRmAc:t(841),rqHyb:function(a,n){return a<n},ijHRY:function(a,n){return a-n},PRQZl:function(a,n){return a!==n},yaypS:t(1743),spyZo:function(a,n){return a-n},aGJfp:function(a,n){return a<n},bfTep:function(a,n){return a-n},ToeHR:function(a,n){return a===n},QEgrn:function(a,n){return a<n},PEyjW:function(a,n){return a==n},xUghm:t(699)+t(1492)+t(1670),Baqwt:function(a,n){return a!==n},SLSAo:t(723),LHCfa:function(a,n){return a!==n},iwRgb:function(a,n,s){return a(n,s)},oPFGx:function(a,n){return a(n)},Xiavj:function(a,n){return a>>>n},FszWq:function(a,n,s){return a(n,s)},tbdVa:function(a,n,s){return a(n,s)},IrakQ:function(a,n){return a(n)},SNDDZ:function(a,n,s){return a(n,s)},HCNYO:function(a,n){return a&n},gtnbt:t(980)+t(521)+t(460)+t(1369),atQdZ:t(980)+"required"+t(460)+t(1326),tzify:function(a){return a()},BXKCA:function(a,n){return a!==n},LRvaG:function(a,n){return a!==n},JgClE:t(1197),xSKBr:function(a,n,s){return a(n,s)},pFIzm:function(a,n){return a!==n},CMAmT:function(a,n,s){return a(n,s)},DUcHO:function(a,n,s){return a(n,s)},PRubo:function(a,n){return a!==n},dcAKI:function(a,n,s){return a(n,s)},KsZSY:function(a,n){return a!==n},kwgYI:function(a,n){return a===n},tEXZz:t(1041),xoTXM:function(a,n,s){return a(n,s)},YkxWo:function(a,n){return a!==n},iuSnT:function(a,n,s){return a(n,s)},ihMxA:function(a,n){return a(n)},NlOqd:function(a,n){return a|n},IlKHk:function(a,n){return a<<n},ueQQj:function(a,n){return a&n},MYgNd:function(a,n){return a<<n},vgZiW:function(a,n){return a&n},hHXUr:function(a,n){return a<n},FngzY:function(a,n){return a>=n},RJERP:function(a,n){return a<=n},kIrnB:function(a,n){return a===n},WPlHH:"YFnOL",lSjEC:function(a,n){return a(n)},KmJsd:t(1210),leoXi:function(a,n,s){return a(n,s)},wZzaJ:function(a,n){return a(n)},RyKQX:t(1684),dkRfR:function(a,n){return a(n)},JWfjp:function(a,n,s){return a(n,s)},Jquvd:function(a,n){return a(n)},Hqhlk:function(a,n,s){return a(n,s)},mLqsK:function(a,n,s){return a(n,s)},pksOC:function(a,n,s){return a(n,s)},SCxsr:function(a,n){return a(n)},coJpk:function(a,n){return a(n)},LMDoM:function(a,n,s){return a(n,s)},pkVzh:function(a,n){return a===n},uWtBz:"Missing "+t(521)+t(460)+"method",lLVkh:function(a,n){return a(n)},ZEdnT:function(a,n,s){return a(n,s)},NlDLf:function(a,n){return a>>n},lRYfN:t(445)+"t limit",BapYb:"error",lYwhP:t(1694),TEwlU:"Knkzz",huOVI:function(a,n){return a>=n},kEzrQ:function(a,n){return a>n},PnsKO:function(a,n){return a*n},yAxeb:function(a,n){return a>n},dydsZ:t(763)+t(485),BXrdR:t(736),lDYXQ:t(1392),aMDAC:function(a,n){return a<n},gHpCY:function(a,n){return a+n},jIsuN:function(a,n){return a&n},TDmbL:function(a,n){return a>=n},xumOG:function(a,n){return a+n},rpxXX:t(1086),NOFAO:t(857),SvhQE:function(a,n){return a+n},NPXyv:function(a,n){return a==n},oimiw:function(a,n){return a>=n},yEiFw:function(a,n){return a+n},IRszK:function(a,n){return a+n},OryZR:function(a,n){return a&n},EltwW:function(a,n){return a|n},sfVFB:function(a,n){return a<<n},TADJL:function(a,n){return a&n},srbWy:function(a,n){return a<<n},amLqO:function(a,n){return a<=n},WpEfe:function(a,n){return a==n},ZFiEf:function(a,n){return a&n},VtFbH:function(a,n){return a|n},LQHAZ:function(a,n){return a|n},sFkQt:function(a,n){return a<<n},FsZnS:function(a,n){return a|n},oJvTX:function(a,n){return a|n},HShUM:function(a,n){return a<<n},tnIgu:function(a,n){return a<<n},CHMGe:function(a,n){return a&n},BzSrN:function(a,n){return a&n},PdVKw:function(a,n){return a>>n},uiuer:function(a,n){return a+n},iqoHd:function(a,n){return a&n},QmKdy:function(a,n){return a(n)},tECho:function(a,n){return a>=n},KJhEL:function(a,n){return a<n},eVVUK:function(a,n){return a<n},qjhYm:function(a,n,s){return a(n,s)},BNatS:function(a,n){return a>=n},Latba:function(a,n){return a<n},yAAbw:function(a,n){return a<n},HSqzL:function(a,n){return a&n},azzfW:function(a,n){return a!==n},VzIAK:t(662),XWkgV:function(a,n){return a>>n},GzhcE:function(a,n){return a|n},jVtAb:function(a,n){return a&n},boJEu:function(a,n){return a>>n},Vpmog:function(a,n){return a|n},ijZPR:function(a,n){return a&n},rhTWL:function(a,n){return a+n},FEBCR:function(a,n,s){return a(n,s)},bXLKe:function(a,n){return a<<n},EHaoT:function(a,n){return a&n},kHrcJ:function(a,n){return a&n},sKXXK:function(a,n){return a>>>n},syrFt:function(a,n){return a<n},jPTLU:function(a,n){return a|n},JYtOC:function(a,n){return a|n},rERRC:function(a,n){return a<<n},HgHJg:function(a,n){return a<n},Laojc:"0|3|2|4|"+t(669),sapRE:t(1346),DRhYX:t(914),EbUez:t(1747),GhaVb:t(1117),dnnPK:t(399),lFLGx:t(1685),WSXMw:"offline",FVWzY:function(a){return a()},ggKhu:function(a,n,s){return a(n,s)},IMfIR:function(a,n){return a(n)},SqZtb:t(509)+"t",pqjeQ:t(1478),QwQZd:t(771),yasWS:function(a,n){return a&n},crjun:function(a,n){return a(n)},TEOPN:function(a,n){return a&n},LbtzM:function(a,n){return a&n},PmEMQ:function(a,n){return a&n},EyMDC:function(a,n){return a&n},fHIKQ:function(a,n){return a===n},pzzpz:function(a,n){return a<<n},nknxu:function(a,n){return a&n},Edaaz:t(405),OgiiB:function(a,n){return a(n)},QIzoC:function(a,n){return a<<n},Hszyq:function(a,n){return a&n},BQYlT:t(932),sFMbH:"SWtEL",RBski:function(a,n){return a&n},UrDop:function(a,n){return a===n},wTydD:t(1595),IlObT:t(1340),MxHrz:function(a,n){return a<<n},QgRcA:function(a,n){return a|n},IWLOA:function(a,n){return a<<n},fDdEz:function(a,n){return a>>>n},nbMUD:function(a,n){return a>>>n},fLiin:function(a,n){return a===n},QODAA:function(a,n){return a+n},bPcZM:function(a,n){return a>>>n},BsNCn:function(a,n){return a!==n},jTRFP:function(a,n){return a|n},iOYqg:function(a,n){return a!==n},tfCfm:function(a,n){return a>>>n},kQlcR:function(a,n){return a&n},qMzaF:function(a,n){return a>>>n},oOaPC:function(a,n){return a&n},slkFk:function(a,n){return a>>>n},zCsqs:function(a,n){return a+n},ISUgY:function(a,n){return a!==n},uYtBo:function(a,n){return a+n},ZvOqv:function(a,n){return a|n},MLUHq:function(a,n){return a&n},NbrHK:function(a,n){return a>>>n},GAQrv:function(a,n){return a|n},FknKP:function(a,n){return a>>>n},VVXQo:function(a,n){return a!==n},FvmYW:function(a,n){return a|n},hqyuC:function(a,n){return a&n},uxyPf:function(a,n){return a(n)},ntfQC:function(a,n){return a|n},vHTov:function(a,n){return a|n},pAxMQ:function(a,n){return a<<n},xnxtv:function(a,n){return a<<n},cSRPs:function(a,n){return a|n},Rwdcg:function(a,n){return a|n},GzAZh:function(a,n){return a===n},dljHk:function(a,n){return a|n},KTMze:function(a,n){return a<<n},xtHlo:function(a,n){return a>>>n},mDvRf:function(a,n){return a<<n},JFjpX:function(a,n){return a&n},SNjNu:function(a,n){return a>>>n},heiQr:function(a,n){return a&n},aneRL:function(a,n){return a&n},tmcON:function(a,n){return a&n},aCTeI:function(a,n){return a>>>n},HfiLh:function(a,n){return a%n},UOfme:function(a,n){return a>>>n},SOGhP:function(a,n){return a===n},iipCL:function(a,n){return a>>>n},GRNsk:function(a,n){return a>>>n},flyLM:function(a,n){return a&n},gRXPQ:function(a,n){return a&n},LsZLY:function(a,n){return a+n},gPqtu:function(a,n){return a<<n},UVCbD:function(a,n){return a|n},wrSSj:function(a,n){return a!==n},yXxcS:function(a,n){return a>>>n},BKGeZ:function(a,n){return a===n},wYasA:function(a,n){return a===n},jDtQb:function(a,n){return a===n},mufng:function(a,n){return a===n},QxGET:function(a,n){return a+n},McpIH:function(a,n){return a&n},pwfzc:function(a,n){return a&n},wwXwQ:function(a,n){return a>>>n},gPHZY:function(a,n){return a&n},LPzUW:function(a,n){return a>>>n},xEyPC:function(a,n){return a>>>n},lZJbk:function(a,n){return a&n},wjTsW:function(a,n){return a>>>n},QkSpy:function(a,n){return a&n},XtmDd:t(1614)+t(1105),PHpaR:t(1063)+"OR",vSbDE:t(1331)+t(1205),ZEDnm:t(646)+"0",odReM:function(a,n,s){return a(n,s)},KHmzs:"psYIu",CqDag:function(a,n){return a&n},FSjLH:function(a,n){return a&n},qkAFF:function(a,n){return a>>>n},iVKsK:function(a,n){return a>>>n},PvxSg:"HYyYk",zMGqK:t(1274),eMxCt:function(a,n){return a||n},nimlP:function(a){return a()},RjClv:t(1435),AgOvu:function(a,n){return a===n},PByTA:function(a,n){return a==n},uaBIV:t(1496)+t(718),OtxXm:function(a,n){return a+n},GiDKa:function(a,n){return a===n},PLHwh:function(a,n){return a<n},jgMRv:function(a,n){return a>>>n},xhccr:function(a,n){return a&n},Rvjhi:function(a,n){return a&n},jmFXv:function(a,n){return a&n},dBgGo:function(a,n){return a>>>n},oitcb:function(a,n){return a+n},vJFeK:function(a,n){return a<<n},dTFiu:function(a,n){return a|n},EyGia:t(1842),dcjDV:t(1526),zhdkr:t(1918),zYKri:function(a,n,s){return a(n,s)},xfAIw:t(1594),KXSWX:t(1554),jmFhY:function(a,n,s){return a(n,s)},CjaiY:t(876),DHOHT:function(a,n,s){return a(n,s)},XUHed:function(a,n,s){return a(n,s)},STqEp:function(a,n){return a instanceof n},rJxEG:function(a,n){return a!=n},jQEFW:t(1871),iwRrH:function(a,n){return a!=n},KRQwZ:"applicat"+t(481),PXkVk:t(1647),Legzb:t(997),UHgqV:t(710),ZvJWs:function(a,n){return a||n},yotwY:t(376)+"d",ZYulR:function(a,n){return a!=n},eIgDP:function(a,n){return a+n},QIIYT:function(a,n){return a<n},Almuk:function(a,n){return a<n},PjbBX:function(a,n){return a===n},RVWDX:function(a,n){return a&n},GSuhH:function(a,n,s){return a(n,s)},iTDin:function(a,n,s){return a(n,s)},XkEzG:function(a,n){return a+n},xlEyh:t(1899),wSVMj:function(a,n){return a<=n},LGAgH:function(a,n){return a<n},UCBaA:function(a,n){return a<n},TRwOz:function(a,n){return a|n},MSJZF:function(a,n){return a<<n},rorus:function(a,n){return a&n},YgDPD:function(a,n){return a-n},tGqyf:function(a,n){return a|n},IKpWT:function(a,n){return a&n},fdcNk:function(a,n){return a&n},zMiAK:function(a,n){return a<<n},JcQzk:function(a,n){return a+n},ImRYW:function(a,n){return a&n},BcloO:function(a,n){return a<n},MXhCt:function(a,n){return a|n},tpljl:function(a,n){return a&n},WPWOB:function(a,n){return a===n},anhpd:function(a,n){return a&n},AXJwZ:function(a,n){return a&n},kGsAq:t(1522)+t(892),daeJT:function(a,n){return a|n},shkAI:function(a,n){return a|n},PspSK:function(a,n){return a&n},zEiUT:function(a,n){return a>>n},DEtNQ:function(a,n){return a==n},iHalN:function(a,n,s,l){return a(n,s,l)},ehEBp:function(a,n){return a!=n},RPqZf:"sYRLj",uvFnN:function(a,n){return a==n},oZkeY:function(a,n){return a===n},SOhlZ:t(1773),kOeDv:"store",WZFOj:function(a,n){return a in n},AdgfK:function(a,n){return a!==n},PkfUl:t(826),WFOHi:function(a,n){return a>=n},lYike:function(a,n){return a!==n},HqsjL:t(1892),vmJtF:t(1424),APmgf:t(1014)+t(1825),EHWFt:t(498),PvDcj:t(1706)+t(1406),QfGpT:function(a,n){return a+n},yJENu:function(a,n){return a===n},oDjzO:"WwPor",ElNYG:t(432),xLdFX:function(a,n){return a(n)},QwHJO:function(a,n){return a&n},BYlyF:function(a,n){return a&n},pGOms:t(1780),toytB:"idb",GBOMQ:t(1532),RNcbf:function(a,n){return a!==n},wZRtC:"CwUib",andho:t(1110),qnFWg:"GKMgE",adkIZ:t(1516),LxoGs:"boe",JtOVX:function(a,n){return a===n},YLdnr:"oxVMY",EJuZF:"xvfXU",ORpkb:function(a,n){return a+n},eFXGJ:function(a,n){return a>>>n},rvdTu:function(a,n){return a+n},rdskW:function(a,n){return a+n},BuOlP:function(a,n){return a&n},MdPvD:function(a,n){return a+n},NZoRs:function(a,n){return a&n},ECROa:function(a,n){return a>>>n},AtgOU:function(a,n){return a&n},DwAFH:function(a,n){return a>>>n},lKrxP:function(a,n){return a+n},vroHj:function(a,n){return a===n},pxbzA:t(1786),qbFES:function(a,n){return a===n},dakzl:"TeNkp",hCthF:t(1896),Smciv:t(1557)+"hange",fXZCW:function(a,n){return a!==n},mXZbL:t(1469),wDgDt:t(1164),aSwlF:function(a,n){return a||n},osxcP:function(a,n){return a||n},hcJMn:t(671),WamSy:function(a,n){return a||n},lutVl:"going aw"+t(1560)+"ork offl"+t(1228),IgPBe:t(664),jqATA:t(1310)+t(1109),jpWiD:"x_fronti"+t(1245)+"ck",rJJyr:function(a,n,s){return a(n,s)},QyboU:"bcNWc",kYwVU:"tYfqX",oLRqW:function(a,n){return a||n},hIIxP:t(1440),cofmA:"mtwrs",iJdeV:function(a,n){return a||n},npVEn:function(a,n){return a<n},RnnZb:function(a,n){return a===n},eMHqI:function(a,n){return a&n},jYXQX:function(a,n){return a+n},mnCzY:function(a,n){return a!==n},pQHUu:t(958),PebTw:function(a,n){return a||n},zuetf:function(a,n){return a!=n},GivuA:function(a,n){return a||n},InGvp:t(401)+t(1906)+"d",uuJOU:function(a,n){return a(n)},czWQH:function(a,n,s,l){return a(n,s,l)},TzdUR:t(1389),CcNHO:"integer "+t(847)+"e",BKgpx:function(a,n){return a>=n},dfIrE:function(a,n){return a&n},XdGFS:"VQYmS",PyNYt:function(a,n,s,l){return a(n,s,l)},hHUox:"KaBva",CaGwB:function(a,n){return a(n)},iVmvX:function(a,n){return a+n},xQNJA:function(a,n){return a===n},ZraZm:t(678),eJBOa:t(1513),vsrSn:function(a,n,s,l){return a(n,s,l)},TcNiO:"x_frontier_is_ack",ScfoK:t(1310)+t(1281)+t(436),tvXCB:t(582),hUomt:function(a,n){return a===n},GnZUM:t(901),uNgKX:t(1771),byETv:function(a,n){return a===n},wuDCC:function(a,n,s,l){return a(n,s,l)},Cnsqn:function(a,n,s){return a(n,s)},TRPuL:t(837),Ifecd:t(1405),NAZqv:function(a,n){return a&&n},zbQlb:function(a){return a()},dlBGk:t(905),HJbZC:t(1111),gpxOe:t(1198),QlPdF:function(a,n){return a(n)},JtMSR:t(1337),ZpHuA:t(1252)+t(481)+t(1257)+t(803),XwfEw:t(950)+"e",ISZTy:t(378),UxOBt:"BwRiU",bDvoh:t(1367),rLCSK:t(384),kkckS:function(a,n){return a>>>n},ShRKE:t(1733),mpBqo:" > ",GsWIe:function(a,n){return a!==n},Xlvjx:t(1686),wSehn:function(a,n){return a>n},VbKZB:function(a,n){return a>=n},XcFkC:function(a,n){return a&n},fmodu:function(a,n){return a+n},RtOjr:function(a,n,s){return a(n,s)},pOhzU:function(a,n){return a>>>n},rQGyY:function(a,n){return a<<n},kpSBC:function(a,n){return a+n},dumeN:function(a,n){return a+n},Kplim:function(a,n){return a+n},PGqgb:function(a,n){return a+n},lLYfl:function(a,n,s,l){return a(n,s,l)},raOXx:function(a,n){return a|n},LnvZF:function(a,n){return a|n},mKuUD:function(a,n){return a<<n},kbzOE:function(a,n){return a+n},eehJF:function(a,n){return a<<n},kBMTd:function(a,n){return a+n},SlxUP:function(a,n){return a<<n},qkbXl:function(a,n){return a+n},xOPwm:function(a,n){return a|n},FQRCB:function(a,n){return a|n},mqQiN:function(a,n){return a|n},IVJUa:function(a,n){return a<<n},mLlAT:function(a,n,s){return a(n,s)},WHlze:function(a,n,s){return a(n,s)},YsWqV:t(1217),MYAzx:function(a,n){return a>>>n},ITqSk:function(a,n){return a&n},DwoUX:function(a,n){return a+n},ZlZZR:function(a,n){return a+n},OSdYo:function(a,n){return a&n},WKiUO:function(a,n){return a+n},yLgMt:function(a,n){return a&n},BaUcQ:function(a,n){return a&n},bqToW:function(a,n){return a&n},zQMom:t(1600)+"|9|0|1|5"+t(1381)+"7",sGwrK:function(a,n){return a|n},UPlqm:function(a,n){return a>>>n},cMqUn:function(a,n){return a>>>n},KbqiJ:function(a,n){return a|n},ECzyv:function(a,n){return a&n},DaRBD:function(a,n){return a|n},xyoDI:function(a,n){return a|n},SVbBL:function(a,n){return a<<n},QJaTm:function(a,n){return a&n},SyMxu:function(a,n){return a|n},lbRCu:function(a,n){return a!==n},lDUtV:function(a,n){return a<n},hKrXx:t(881)+t(1649)+t(877),RHBXU:function(a,n,s,l){return a(n,s,l)},wuYPL:t(631),aIlEU:t(659),BUchC:function(a,n,s,l){return a(n,s,l)},XDQKa:t(956),fhlqs:t(967)+"name",ncLxD:t(1735)+t(1711),pOFDG:t(1917),wfwvZ:function(a,n,s,l){return a(n,s,l)},SLlbm:t(577)+t(747),hUgXl:function(a,n,s){return a(n,s)},bAPVC:t(450)+t(1494),GQQFs:function(a,n,s){return a(n,s)},pGnEa:t(829),SZozz:t(795),PAXJA:"setdb",nqUby:function(a,n,s){return a(n,s)},fyqtP:function(a,n){return a!==n},HpTFA:t(1714),chLhp:function(a,n){return a(n)},oNbXI:"setcursor",wvSFY:t(1310)+"er_msgid",MkWpA:t(1310)+t(622),uGlUF:function(a,n,s,l){return a(n,s,l)},xJkfi:function(a,n,s){return a(n,s)},rHOTW:t(1383)+t(707)+"e",APkpr:function(a,n){return a(n)},wxVea:t(1383)+t(1242)+"ue",NZDhh:function(a){return a()},xgLHr:function(a,n){return a+n},jfGLm:function(a){return a()},rcQVV:function(a,n){return a<n},PZOLS:function(a){return a()},zOXQw:function(a){return a()},MYRMQ:function(a,n){return a===n},wSrJu:function(a,n,s){return a(n,s)},XNMbs:function(a){return a()},KNcBX:function(a,n){return a(n)},UWbnJ:function(a){return a()},JTOzV:function(a,n){return a<n},KRnCh:function(a,n){return a|n},IIiXb:function(a,n){return a>>>n},WyvXG:function(a,n){return a|n},TePTG:function(a,n){return a<<n},TMyYK:function(a,n){return a&n},QxOcV:function(a,n){return a<n},hImIJ:function(a,n){return a|n},bBXmf:function(a,n){return a>>>n},opXuf:function(a,n){return a|n},AnbtZ:function(a){return a()},TKOwp:function(a,n){return a<n},gAuri:t(1863),cAGXK:t(838),Vaqyi:function(a,n,s){return a(n,s)},BWbsx:function(a){return a()},WkWhY:function(a,n){return a===n},kGJoL:t(1642)+t(1893),VZdpj:function(a,n){return a(n)},JSrtY:t(1360),SvLal:function(a,n,s){return a(n,s)},boAWD:function(a,n){return a(n)},PeNBb:t(1067),XReaP:t(1553),TlULZ:t(371)+t(870)+"s",rxDjZ:function(a,n,s,l){return a(n,s,l)},Dpriq:function(a,n){return a===n},JqbNK:t(1529),ZTpAD:function(a,n){return a===n},CLhFR:function(a,n,s){return a(n,s)},qUhQJ:function(a,n,s){return a(n,s)},aENBB:t(1784),GHbyD:t(1886),KbiuI:t(697)+t(1006),fgNCV:t(1468),QvsXC:function(a,n){return a/n},tIyjp:t(1241),gQAeJ:function(a,n){return a==n},YjxMT:t(1915)+t(1167)+t(1528)+", WebSocket cons"+t(945)+"is undef"+t(949),nWvPQ:t(1166)+"ediately"+t(1052)+"ct",jBtIA:t(1301),lJlJo:function(a,n){return a!==n},wziVc:t(1254),Emtju:t(1521),HHsgz:function(a,n){return a(n)},TqClO:function(a,n,s){return a(n,s)},GDDhz:t(844),EDAKd:t(528),nDwWQ:function(a,n){return a!==n},CGMzG:function(a,n){return a!==n},TRZuy:function(a,n){return a==n},gqSlX:t(457),odAbt:t(968),SGPmQ:t(1486),JjUeu:t(1799),isqui:t(1401),WqOlY:t(919),vnNna:t(1581),hcZIv:t(1915)+"rovide b"+t(1246)+t(709)+t(1053),iLEps:t(783),yooxp:function(a){return a()},JwcBN:function(a,n,s){return a(n,s)},yKjaa:t(1704),Mwtpe:t(1890),LdpbH:function(a,n){return a>n},meMni:function(a,n,s){return a(n,s)},XUQrd:function(a,n){return a===n},ZeOjU:"qmvbS",wBzsQ:"TKibA",vMhBx:"FRONTIER>",gobYr:function(a,n){return a>n},HmOiJ:function(a,n){return a!==n},IpWqQ:t(371)+"e_timeout",wfLnm:t(617)+t(1308)+t(1447),fGZeX:function(a,n,s,l){return a(n,s,l)},fWCrv:function(a,n){return a!==n},MCOHH:"hixea",uiWDi:t(1831),MfwwY:t(1633)+t(676)+t(509)+t(1845)+t(1419),sIOOE:"jgqoN",aaJVn:function(a,n,s){return a(n,s)},mLtdP:"timeout,"+t(1165)+t(1693)+"g",VzIMM:t(1431),rbeeG:t(1371),xGBdm:t(1739)+"4",nPSgk:function(a,n){return a<<n},ZzRQb:t(1409),DmPPB:function(a,n){return a!==n},MGEPQ:t(406),bMDOv:function(a,n,s){return a(n,s)},tcSEN:function(a,n,s){return a(n,s)},YXFcK:function(a,n){return a(n)},ljBbj:function(a,n){return a!==n},hoMiN:"SFtRJ",WiOYW:function(a,n){return a>n},VMtRl:function(a,n){return a+n},YZNWi:t(1026),ITpGY:t(451)+"0",SaffG:function(a,n){return a||n},BmdMc:t(1834),nBHcz:t(1536),kqkHO:t(411),MYBoW:t(1224)+"s instan"+t(754)+"nitialized",onQUt:function(a,n){return a===n},LfkPx:function(a,n){return a===n},HOFHK:"please p"+t(1356)+" valid data, dat"+t(648)+t(1044)+t(1572)+t(535)+"ffer",NWYBF:function(a,n){return a!=n},GxjjC:function(a,n){return a instanceof n},eoPtU:function(a,n){return a instanceof n},whZnE:function(a,n){return a(n)},EQYEJ:function(a,n){return a||n},twvAd:t(1915)+t(1356)+" valid service",LaChk:function(a,n){return a<n},vQPjI:function(a,n){return a===n},HQzXe:t(842),tQzhw:t(1029),alsWY:function(a,n){return a||n},PoBgm:function(a,n){return a!==n},xYBAM:"moNel",CDCuU:t(380),RZaxG:t(990),khAVP:t(1573),ZXYnV:function(a,n){return a===n},dICPt:function(a,n){return a===n},TPjbv:"Window",AKRmD:function(a,n){return a!=n},aSYtd:t(1488),vPBmj:"Dedicate"+t(1769)+"lobalScope",ZRlff:function(a,n){return a==n},CXORm:function(a,n){return a!=n},TXZNP:function(a,n){return a===n},gKpLd:t(1403)+t(1666)+t(1155),qjnfX:function(a,n){return a!=n},iyCkU:function(a,n){return a===n},IJApq:function(a,n){return a!=n},QxnQM:function(a,n){return a!=n},gNKGM:function(a,n,s){return a(n,s)},TzjqG:"__x_msg_"+t(1577)};Mt.r(Ce),Mt.d(Ce,{FWS:()=>hg,CustomErrorEvent:()=>el,createCloseEvent:()=>pt,ReconnectEvent:()=>Qd,createErrorEvent:()=>ct,decodedFrame:()=>Qt,createOpenEvent:()=>ol,CustomCloseEvent:()=>tl,createReconnectEvent:()=>ua,FrontierMessageEvent:()=>rl,encodeFrame:()=>Ft,createMessageEvent:()=>sl,OpenEvent:()=>il,ErrorCode:()=>tn,Event:()=>er,MessageEvent:()=>nl});let r="";function i(a=""){let n=t,s={FlcAu:e[n(1865)],EEJwD:e[n(1388)],OPTWh:function(l,x){return e[n(437)](l,x)},IslFo:e.MXfHy};if(e[n(1344)]("GfktS",e[n(1160)])){let x=""+Date[n(977)](),m=r||(r=f(a)),b=Math[n(1803)]().toString(16).slice(-6);return e[n(796)]("02"+x+m,b)}else{let{SeqID:l,LogID:x,service:m,LogIDNew:b,method:E}=_0x1527e4[n(876)];this[n(886)]({SeqID:l,LogID:x,LogIDNew:b,service:m,method:E,headers:[{key:s[n(1039)],value:"1"},{key:s[n(1373)],value:s[n(693)](b,"")},{key:s[n(554)],value:"0"}]})}}function o(){let a=t;return e[a(796)](e[a(854)](1e4,Date.now()),Math[a(661)](1e4*Math[a(1803)]()))}function c(a){let n=t;return e[n(796)](e[n(684)](Array,8)[n(1309)]("0"),e.cBgEg(parseInt,a,10)[n(1796)](2)).slice(-8)}function d(a){let n=t,s={xklck:e[n(1188)],PkVsn:n(1233),zfehD:e[n(782)],tYyeM:e[n(474)]};if(e[n(712)](e.gZEou,e.gZEou))return e[n(1011)](Array(4)[n(1309)]("0"),parseInt(a,2)[n(1796)](16))[n(708)](-4);this[n(830)+"er"]&&_0x191732[n(1091)+n(658)](s[n(1730)],this[n(427)+n(879)]),this[n(830)+"er"]&&_0x19b851.addEventListener(s[n(1330)],this[n(427)+"ffLine"]),this[n(830)+"er"]&&_0x364f96["addEvent"+n(658)](s[n(728)],this["_handleP"+n(1436)]),this[n(830)+"er"]&&_0x149113[n(1091)+n(658)](s[n(1801)],this[n(864)+"ageShow"])}function u(a){let n=t;if(e[n(1130)](e.pDCFg,e[n(1626)])){let s=a.split(/\./)[n(777)](m=>c(m)),l=[];return l[0]=e[n(988)](d,e[n(982)](s[0],s[1])),l[1]=e[n(1366)](d,e[n(1097)](s[2],s[3])),[e.abezM,e[n(1279)],e[n(1279)],"0000",e[n(1279)],e[n(1655)],l[0],l[1]][n(1309)]("")}else e.cBgEg(_0x55f4cd,_0x3dac2d,32),_0x2a81ad(_0x461e74,e.oYMFI(_0x588a69,_0x153a4d))}function f(a){let n=t,s={YlYJx:function(l,x){return l||x}};if(n(1664)!==e[n(705)]){if(_0x114d8a)return new _0x3c2b42(_0x5d860a[n(564)],_0x256886[n(666)]);if(_0x5ead3d||_0x4f2349)return new _0x2554b3(_0x355a03.url,_0x9e6bf5.protocol,_0x1d2b98.headers);if(s[n(1619)](_0x57db6e,_0x56404d)&&n(376)+"d"!=typeof _0x5b54e8&&_0x11aa11)return new _0x56a78c(_0x209188[n(564)],_0x1bf1ea[n(666)+"s"])}else{let l=/(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(752)](a),x=/(([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(752)](a);return l?e.Dfxnk(u,a):x?e[n(988)](h,a):e.CpJKo}}function h(a){let n=t;if(n(788)!==e[n(387)]){let s="",l=[],x=0,m=0,b=!0,E=e[n(1279)];if(e[n(1199)](a[n(523)]("::"),-1)){let p=a[n(573)]("::");for(let P=0;P<p[n(1027)];P++)if(e[n(712)](e[n(1229)],e[n(934)]))this._socket&&this._socket[n(1594)]({code:_0x5d1180,reason:_0x1c0037});else{let N=p[P];if(e.NVGLH(N[n(523)](":"),0))if(e[n(1043)]!==e[n(1525)]){let z=N[n(573)](":");b&&(x=z[n(1027)]),m+=z[n(1027)];for(let H=0;e[n(1523)](H,z[n(1027)]);H++)if(e.rTaEg(4,z[H].length)){let ge=E.substring(0,e[n(1207)](4,z[H][n(1027)])),Ae=ge.concat(z[H]);l[n(1408)](Ae)}else l[n(1408)](z[H]);b=!1}else return _0x347561[_0x48b833[e[n(817)]]=5001]=e.xarJn,_0x486e9b[_0x270b2a[e[n(1777)]]=5002]=e[n(1777)],_0x4e8818[_0x4bc1db[n(441)+"IES_ERROR"]=5003]=e[n(1172)],_0x246c72[_0x2acba1[e[n(471)]]=5004]=e.TZEea,_0x44e579[_0x4a4a15[n(1063)+"OR"]=5005]=n(1063)+"OR",_0x5d5b34;else if(e[n(1749)](e[n(1220)],e[n(1220)])){let{type:z}=_0x10e896;this[n(1648)](z,_0x142554)}else{if(e[n(1749)](4,N[n(1027)])){let z=E[n(591)+"g"](0,e[n(1916)](4,N[n(1027)])),H=z[n(516)](N);l[n(1408)](H)}else l.push(N);b&&(x+=1),m+=1,b=!1}}let k="";for(let P=0;e[n(1562)](P,e[n(1480)](8,m));P++)k=k[n(516)](E);for(let P=0;P<l[n(1027)];P++)e.ToeHR(P,x)?(s=s.concat(k),s=s.concat(l[P])):s=s[n(516)](l[P]);return s}{let p=a.split(":");for(let k=0;e[n(1477)](k,p[n(1027)]);k++){let P=p[k];if(e[n(1749)](4,p[k][n(1027)])){let N=E[n(591)+"g"](0,e[n(1916)](4,p[k].length)),z=N[n(516)](P);s=s[n(516)](z)}else s=s[n(516)](P)}return s}}else return _0x4c9af2&&(_0x11a106=(0,_0x339c59[_0x68ba9c(_0x5d136f)[0]])(_0x27ee25=0)),_0x5bb3e7}function g(a,n){let s=t,l=a.key;if(e.rTaEg(void 0,l)){if(e[s(1269)](e.SLSAo,e[s(721)]))return e[s(1001)](s(1871),typeof _0x22e643)?e[s(1721)]:"";e[s(1182)](he,n,10),e[s(1182)](G,n,l)}let x=a[s(1326)];e[s(1742)](void 0,x)&&(e[s(1182)](he,n,18),e[s(501)](G,n,x))}function w(a){let n=t,s={};e:for(;!e[n(1366)]($,a);){let l=e.oPFGx(xe,a);switch(e.Xiavj(l,3)){case 0:break e;case 1:s[n(1369)]=e[n(852)](D,a,xe(a));break;case 2:s[n(1326)]=e.tbdVa(D,a,e[n(1905)](xe,a));break;default:e[n(1812)](R,a,e.HCNYO(7,l))}}if(e[n(489)](void 0,s[n(1369)]))throw new Error(e[n(518)]);if(e.wjOlC(void 0,s[n(1326)]))throw new Error(e[n(1687)]);return s}function S(a){let n=t,s=e.tzify(C);return _(a,s),e[n(1905)](M,s)}function _(a,n){let s=t,l=a[s(566)];e.rTaEg(void 0,l)&&(e[s(1093)](he,n,8),e[s(1812)](ht,n,l));let x=a[s(1625)];e[s(1064)](void 0,x)&&(he(n,16),ht(n,x));let m=a.service;e.LRvaG(void 0,m)&&(e[s(489)](e[s(1272)],e[s(1272)])?(he(n,24),e[s(852)](ht,n,e[s(988)](O,m))):(this["_miniNav"+s(1772)+"line"]=_0x157790,_0x1e0187?this[s(427)+s(879)]():this[s(427)+"ffLine"]()));let b=a[s(735)];b!==void 0&&(he(n,32),e[s(1883)](ht,n,e[s(1905)](O,b)));let E=a[s(1061)];if(e[s(722)](void 0,E))for(let Ae of E){he(n,42);let Be=e[s(1250)](C);e[s(501)](g,Ae,Be),he(n,Be.limit),W(n,Be),L(Be)}let p=a[s(1033)+s(435)];e[s(722)](void 0,p)&&(e[s(551)](he,n,50),e[s(407)](G,n,p));let k=a.payloadType;e[s(1742)](void 0,k)&&(e[s(501)](he,n,58),e.DUcHO(G,n,k));let P=a[s(1322)];e[s(1116)](void 0,P)&&(e[s(407)](he,n,66),e[s(852)](he,n,P[s(1027)]),e.dcAKI(se,n,P));let N=a.LogIDNew;e[s(1069)](void 0,N)&&(e[s(1883)](he,n,74),G(n,N));let z=a[s(1808)+s(568)];if(e.KsZSY(void 0,z)){if(e[s(1484)](e[s(1050)],s(702)))return this[s(985)+"ndpointT"+s(1493)+"t"]++,this["getCurre"+s(375)+"nt"]();e[s(1178)](he,n,82),e[s(852)](G,n,z)}let H=a[s(1879)];e[s(490)](void 0,H)&&(he(n,90),e[s(410)](G,n,H));let ge=a[s(1853)+"e"];e.LHCfa(void 0,ge)&&(e[s(1182)](he,n,96),e[s(1812)](ht,n,e[s(1905)](O,ge)))}function v(a){let n=t;return e[n(1366)](I,e[n(725)](F,a))}function I(a){let n=t,s={Qtnhh:function(l,x){return l(x)}};if(e[n(1650)](e[n(1446)],e[n(1446)])){let l={};e:for(;!e[n(1466)]($,a);)if(e[n(1344)]("Lbuxp",e[n(794)]))this[n(606)+n(421)]=_0x216356,this[n(1747)]=0;else{let x=e.ihMxA(xe,a);switch(x>>>3){case 0:break e;case 1:l.SeqID=e[n(1126)](St,a,!0);break;case 2:l[n(1625)]=St(a,!0);break;case 3:l[n(659)]=e[n(725)](xe,a);break;case 4:l[n(735)]=e[n(1779)](xe,a);break;case 5:if(e[n(712)]("wozue",e[n(1507)])){let m=e.dkRfR(A,a);(l[n(1061)]||(l[n(1061)]=[])).push(e[n(684)](w,a)),a.limit=m;break}else _0x450101=s[n(1679)](_0x563ad4,_0x5a24b1),_0x409125=0;case 6:l[n(1033)+n(435)]=D(a,xe(a));break;case 7:l[n(654)+n(1072)]=e[n(515)](D,a,e[n(1534)](xe,a));break;case 8:l[n(1322)]=e[n(1914)](ie,a,e[n(1720)](xe,a));break;case 9:l[n(1807)]=e[n(856)](D,a,e[n(684)](xe,a));break;case 10:l[n(1808)+n(568)]=D(a,e.QhHFo(xe,a));break;case 11:l[n(1879)]=e[n(1425)](D,a,e[n(845)](xe,a));break;case 12:l[n(1853)+"e"]=e[n(533)](xe,a);break;default:e.LMDoM(R,a,e[n(778)](7,x))}}if(e.ToeHR(void 0,l[n(566)]))throw new Error(n(980)+n(521)+n(460)+n(566));if(l[n(1625)]===void 0)throw new Error("Missing "+n(521)+" field: "+n(1625));if(e[n(677)](void 0,l.service))throw new Error(n(980)+"required"+n(460)+n(659));if(e[n(712)](void 0,l[n(735)]))throw new Error(e.uWtBz);return l}else _0xd01f12=e[n(835)](e[n(656)](e[n(778)](15,_0x207e56),12)|e[n(947)](e.vgZiW(63,_0x6161ee),6),e[n(675)](63,_0x68416c)),e[n(1127)](_0x3c8bfd,2048)||e.FngzY(_0x3f0b7e,55296)&&e[n(465)](_0x4b0a65,57343)?_0x2a8655+=_0x27aac4:(_0x142039+=_0xabeff0(_0x45b89d),_0x281281+=2)}function A(a){let n=t,s=e[n(1534)](xe,a),l=a[n(793)];return a.limit=e[n(982)](a[n(979)],s),l}function R(a,n){let s=t;switch(n){case 0:for(;e.HCNYO(128,e[s(1751)](ee,a)););break;case 2:e[s(852)](Y,a,xe(a));break;case 5:e[s(1355)](Y,a,4);break;case 1:e[s(407)](Y,a,8);break;default:throw new Error(s(1292)+s(1031)+"pe: "+n)}}function O(a){let n=t;return a|=0,{low:a,high:e[n(505)](a,31),unsigned:e[n(1476)](a,0)}}let y=[];function C(){let a=t,n=y[a(760)]();return n?(n[a(979)]=n[a(793)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function L(a){y.push(a)}function F(a){return{bytes:a,offset:0,limit:a[t(1027)]}}function M(a){let n=t,s=a[n(402)],l=a[n(793)];return e[n(712)](s[n(1027)],l)?s:s[n(652)](0,l)}function Y(a,n){let s=t;if(e.DMBTQ(a.offset,n)>a[s(793)])throw new Error(e.lRYfN);a[s(979)]+=n}function $(a){let n=t,s={rGbHU:e.BapYb,ElTkq:e.lYwhP};if(e[n(667)]===n(439))return e[n(532)](a[n(979)],a[n(793)]);_0x3e8431["removeEv"+n(1455)+"ner"]("complete",_0x2f50e3),_0x74f445[n(1328)+n(1455)+n(1616)](BCWXkv.rGbHU,_0x173641),_0x3ddad4[n(1328)+n(1455)+n(1616)](BCWXkv[n(487)],_0x5963aa)}function ne(a,n){let s=t,l=a[s(402)],x=a.offset,m=a.limit,b=e[s(1097)](x,n);if(e[s(729)](b,l[s(1027)])){let E=new Uint8Array(e[s(1624)](2,b));E.set(l),a[s(402)]=E}return a.offset=b,e.NVGLH(b,m)&&(a[s(793)]=b),x}function J(a,n){let s=t,l=a[s(979)];if(e[s(1824)](e.RWEps(l,n),a[s(793)]))throw new Error(e[s(673)]);return a[s(979)]+=n,l}function ie(a,n){let s=t;if(e[s(677)](e[s(645)],e.BXrdR)){let l=J(a,n);return a[s(402)][s(652)](l,e[s(1097)](l,n))}else return this[s(1136)]?this._ws[s(666)]:""}function se(a,n){let s=t;if(e.lDYXQ!==e.lDYXQ)this["_dispatc"+s(1057)+"Event"](_0x1889dc),_0x23bed1[s(1240)](_0x25f3ad,_0x22f04a,_0x4ec26e[s(876)][s(659)]);else{let l=ne(a,n[s(1027)]);a.bytes[s(1240)](n,l)}}function D(a,n){let s=t,l=J(a,n),x=String["fromChar"+s(632)],m=a.bytes,b="\uFFFD",E="";for(let p=0;e[s(1676)](p,n);p++){let k=m[e[s(1515)](p,l)],P,N,z,H;e[s(1484)](e[s(675)](128,k),0)?E+=x(k):e[s(1344)](e[s(1563)](224,k),192)?e[s(429)](e.xumOG(p,1),n)?E+=b:e[s(1505)]===e.NOFAO?(this[s(1136)]&&this[s(1136)].send(_0x423b7c),this[s(1255)+s(742)][_0xac2d8d]=null):(P=m[e[s(982)](e[s(1696)](p,l),1)],e[s(1742)](e.HCNYO(192,P),128)?E+=b:(H=e[s(778)](31,k)<<6|e[s(1563)](63,P),H<128?E+=b:(E+=e[s(1534)](x,H),p++))):e[s(836)](e[s(1563)](240,k),224)?e[s(1141)](e[s(1206)](p,2),n)?E+=b:(P=m[e[s(1515)](e[s(1097)](p,l),1)],N=m[e[s(1062)](p,l)+2],e[s(798)](e[s(1931)](P|e[s(947)](N,8),49344),32896)?E+=b:(H=e[s(863)](e.sfVFB(e[s(1731)](15,k),12),e[s(755)](63&P,6))|e[s(1396)](63,N),e[s(1127)](H,2048)||e[s(1476)](H,55296)&&e[s(915)](H,57343)?E+=b:(E+=e[s(1534)](x,H),p+=2))):e[s(975)](e.ZFiEf(248,k),240)?e[s(429)](e[s(529)](p,3),n)?E+=b:(P=m[e[s(1515)](p+l,1)],N=m[e[s(1206)](p,l)+2],z=m[e[s(529)](p,l)+3],e[s(1742)](e[s(1563)](e.VtFbH(e[s(1174)](P,e.sFkQt(N,8)),e[s(755)](z,16)),12632256),8421504)?E+=b:(H=e[s(1548)](e[s(1163)](e.HShUM(7&k,18),e[s(1169)](63&P,12))|e.HShUM(e[s(560)](63,N),6),e[s(1481)](63,z)),e[s(1127)](H,65536)||H>1114111?E+=b:(H-=65536,E+=e[s(551)](x,e[s(500)](H,10)+55296,e[s(636)](e.iqoHd(1023,H),56320)),p+=3))):E+=b}return E}function G(a,n){let s=t,l={Wrhsg:function(p,k){return e[V(508)](p,k)},iYnKg:function(p,k){return p(k)}},x=n.length,m=0;for(let p=0;p<x;p++){let k=n[s(1736)+"At"](p);e[s(1423)](k,55296)&&k<=56319&&e.aGJfp(p+1,x)&&(k=e[s(1062)](e[s(653)](k,10),n[s(1736)+"At"](++p))-56613888),m+=e.KJhEL(k,128)?1:e.eVVUK(k,2048)?2:e[s(1545)](k,65536)?3:4}e[s(1812)](he,a,m);let b=e[s(388)](ne,a,m),E=a[s(402)];for(let p=0;p<x;p++){let k=n.charCodeAt(p);if(e[s(1230)](k,55296)&&k<=56319&&e.Latba(e.uiuer(p,1),x)&&(k=e[s(1207)](e[s(1696)](e[s(1169)](k,10),n[s(1736)+"At"](++p)),56613888)),e.rqHyb(k,128))E[b++]=k;else{if(e[s(1904)](k,2048))E[b++]=e[s(1324)](e.PdVKw(k,6),31)|192;else if(e[s(629)](s(578),e.VzIAK))k<65536?E[b++]=e[s(863)](e[s(1481)](e[s(1880)](k,12),15),224):(E[b++]=e[s(1232)](k>>18&7,240),E[b++]=e[s(638)](e[s(412)](e[s(505)](k,12),63),128)),E[b++]=e[s(863)](e[s(778)](e[s(603)](k,6),63),128);else return function(P,...N){let z=s,H=_0x88ddf7[z(1258)](IIJjPx.Wrhsg(_0x51ff6e,this),P,...N);return _0x2ee696[z(1240)](H,P[z(1569)]?P[z(1569)]():[P]),IIJjPx[z(1495)](_0x3269d7,H)};E[b++]=e[s(965)](e[s(740)](63,k),128)}}}function W(a,n){let s=t,l=ne(a,n[s(793)]),x=a[s(402)],m=n.bytes;for(let b=0,E=n[s(793)];b<E;b++)x[e[s(811)](b,l)]=m[b]}function ee(a){return a.bytes[J(a,1)]}function Qe(a,n){let s=t,l=e[s(1867)](ne,a,1);a[s(402)][l]=n}function xe(a){let n=t,s=0,l=0,x;do x=ee(a),s<32&&(l|=e.bXLKe(e[n(1889)](127,x),s)),s+=7;while(128&x);return l}function he(a,n){let s=t;for(n>>>=0;n>=128;)e[s(670)](Qe,a,e[s(1380)](127,n)|128),n>>>=7;e.dcAKI(Qe,a,n)}function St(a,n){let s=t,l={bGmfL:e[s(782)],jdpCa:e[s(474)],ARKRc:s(1426),YsFJw:e.WSXMw,gzFFy:function(x){return e.FVWzY(x)},mxoMT:function(x,m,b){return e[s(1434)](x,m,b)},adTrt:function(x,m){return e.IMfIR(x,m)},HxxYh:e[s(456)]};if(e[s(1372)]===e[s(390)])e[s(515)](_0x414044,_0x41ce39,74),e[s(670)](_0x1ee593,_0x45a226,_0xf463cb);else{let x=0,m=0,b=0,E;if(E=e[s(1905)](ee,a),x=127&E,e[s(562)](128,E)&&(E=e[s(1146)](ee,a),x|=e.tnIgu(e[s(1247)](127,E),7),e[s(812)](128,E)&&(E=e[s(1466)](ee,a),x|=e[s(1857)](127,E)<<14,e[s(1593)](128,E))))if(e.fHIKQ(s(1640),s(1640))){if(E=e[s(684)](ee,a),x|=e[s(969)](e.BzSrN(127,E),21),128&E&&(E=e[s(887)](ee,a),m=e[s(1214)](127,E),e[s(1857)](128,E)))if(e[s(1344)](e[s(1412)],e.Edaaz)){if(E=e[s(1832)](ee,a),m|=(127&E)<<7,128&E&&(E=ee(a),m|=e[s(1315)](e[s(544)](127,E),14),e[s(1247)](128,E))){if(e[s(1699)]!==s(932))!_0x3ba7ee.persisted&&(this._isBrowser&&_0x4e0469[s(1328)+s(1455)+s(1616)](l[s(1811)],this[s(864)+s(1436)]),this._isBrowser&&_0x336276["removeEventListe"+s(1616)](l.jdpCa,this[s(864)+s(858)]),this[s(1594)]()),this[s(830)+"er"]&&_0x22f30d[s(1328)+s(1455)+s(1616)](l[s(784)],this[s(427)+s(879)]),this[s(830)+"er"]&&_0xa92e3b[s(1328)+"entListener"](l[s(846)],this[s(427)+s(1662)]);else if(E=ee(a),m|=e[s(1324)](127,E)<<21,e.PmEMQ(128,E)){if(e[s(1069)](e[s(553)],e[s(553)]))this[s(1707)+s(913)]=_0x4f1938;else if(E=e[s(1905)](ee,a),b=127&E,e.RBski(128,E))if(e.UrDop(e[s(559)],e[s(1870)])){let p={aebrI:function(P,N){return e.sKXXK(P,N)},TYuuJ:function(P,N){return e[s(1930)](P,N)},kWtBB:function(P,N){return e[s(814)](P,N)},oQJVy:function(P,N){return e[s(1169)](P,N)},wFEow:function(P,N){return e[s(560)](P,N)},AWnOQ:function(P,N){return e[s(1170)](P,N)},BwJyM:function(P,N){return e[s(656)](P,N)},gsQkr:function(P,N){return e[s(511)](P,N)},AHjDc:function(P,N){return e[s(820)](P,N)},SfOBQ:function(P,N){return e.HgHJg(P,N)},ixxzL:function(P,N){return P|N},zWjsg:function(P,N){return P>N}},k=4294967295;return function(P,N,z=!0){let H=s;if(k=p[H(1286)](127&P[N],0),p[H(547)](P[N++],128))return{value:z?k:0|k,offset:N};if(k=p[H(1286)](p[H(1108)](k,p[H(1837)](p[H(727)](127,P[N]),7)),0),P[N++]<128)return{value:z?k:p.kWtBB(0,k),offset:N};if(k=p.AWnOQ(k|p.BwJyM(p.wFEow(127,P[N]),14),0),P[N++]<128)return{value:z?k:p[H(1047)](0,k),offset:N};if(k=(k|p.AHjDc(127&P[N],21))>>>0,p[H(802)](P[N++],128))return{value:z?k:p[H(1924)](0,k),offset:N};if(k=(k|(15&P[N])<<28)>>>0,p.SfOBQ(P[N++],128))return{value:z?k:0|k,offset:N};if(p[H(1122)](N+=5,P.length))throw N=P[H(1027)],_0x3ecdde(N,10,P[H(1027)]);return{value:z?k:p[H(1047)](0,k),offset:N}}}else E=ee(a),b|=e[s(1094)](e[s(660)](127,E),7)}}}else{let p=e[s(1635)][s(573)]("|"),k=0;for(;;){switch(p[k++]){case"0":_0x3dd790();continue;case"1":_0x563747=new _0x2c5b4d;continue;case"2":_0x3218e9=[aSVKSR[s(1861)],"getKey",aSVKSR[s(773)],s(1410)+"ys",aSVKSR[s(404)]];continue;case"3":_0x4d6cff();continue;case"4":_0x4b8ad1=[s(1873),aSVKSR.GhaVb,aSVKSR[s(367)],aSVKSR.lFLGx];continue;case"5":aSVKSR.SCxsr(_0x288e0b,P=>({...P,get:(N,z,H)=>_0x2014ed(N,z)||P[s(1346)](N,z,H),has:(N,z)=>!!_0x47635c(N,z)||P[s(869)](N,z)}));continue}break}}}else{this[s(1133)+s(758)+"t"]();let p=_0xf6dc79(l[s(1132)],{message:s(1166)+s(1928)+s(1052)+"ct"});this[s(1645)+s(1341)+s(449)+"ct"]&&this[s(1645)+s(1341)+"yReconnect"](p)}return{low:e[s(878)](x,e[s(1306)](m,28)),high:m>>>4|e[s(1306)](b,24),unsigned:n}}}function ht(a,n){let s=t,l=e[s(1752)](n.low,0),x=e.fDdEz(e[s(1139)](n[s(1828)],28)|n[s(1701)]<<4,0),m=e[s(1170)](n[s(1701)],24),b=m===0?e[s(761)](0,x)?l<16384?l<128?1:2:l<2097152?3:4:e[s(1562)](x,16384)?x<128?5:6:e[s(1545)](x,2097152)?7:8:e[s(1477)](m,128)?9:10,E=ne(a,b),p=a[s(402)];switch(b){case 10:p[e.QODAA(E,9)]=e[s(544)](e[s(703)](m,7),1);case 9:p[e.RWEps(E,8)]=e.BsNCn(9,b)?e.jTRFP(128,m):127&m;case 8:p[E+7]=e[s(874)](8,b)?e.LQHAZ(e[s(674)](x,21),128):e[s(812)](x>>>21,127);case 7:p[e[s(1515)](E,6)]=b!==7?e.NlOqd(x>>>14,128):e.kQlcR(e[s(1048)](x,14),127);case 6:p[E+5]=b!==6?e[s(1548)](e[s(703)](x,7),128):e.oOaPC(e[s(1095)](x,7),127);case 5:p[e[s(1823)](E,4)]=e[s(917)](5,b)?128|x:e[s(1214)](127,x);case 4:p[e[s(1592)](E,3)]=e[s(1064)](4,b)?e.ZvOqv(l>>>21,128):e[s(1656)](e[s(818)](l,21),127);case 3:p[e[s(982)](E,2)]=e[s(1742)](3,b)?e[s(971)](e[s(674)](l,14),128):e.jIsuN(e[s(1810)](l,14),127);case 2:p[E+1]=e[s(685)](2,b)?e[s(1012)](e[s(1048)](l,7),128):e.hqyuC(l>>>7,127);case 1:p[E]=e[s(1269)](1,b)?e[s(1232)](128,l):127&l}}function Qt(a){return e[t(1850)](v,a)}function Ft(a){return e[t(1905)](S,a)}let en=65536,Yr=e.khAVP,we=e[t(1624)](en,en),Ie=e[t(1624)](we,we),Qn=Ie/2,Pe=String[t(1605)+"e"][t(1736)+"At"];class ue{constructor(n,s,l){let x=t;this[x(1321)]=!0,this[x(1828)]=0|n,this[x(1701)]=e[x(1897)](0,s),this.unsigned=!!l}static[t(1321)](n){let s=t;return n&&e[s(1344)](!0,n[s(1321)])}static[t(1467)](n,s,l){return new ue(n,s,l)}static[t(548)+"s"](n,s,l){let x=t;return l?ue[x(548)+x(1365)](n,s):ue[x(548)+x(1813)](n,s)}static[t(548)+"sLE"](n,s){let l=t;return new ue(e[l(638)](e.vHTov(n[0],e.pAxMQ(n[1],8)),e.xnxtv(n[2],16))|e[l(755)](n[3],24),e.NlOqd(e.cSRPs(n[4]|n[5]<<8,e[l(1077)](n[6],16)),n[7]<<24),s)}static[t(548)+t(1813)](n,s){let l=t;return new ue(e[l(1571)](e[l(511)](e.GAQrv(n[4]<<24,e[l(820)](n[5],16)),n[6]<<8),n[7]),e.JYtOC(e[l(1115)](e[l(1306)](n[0],24)|n[1]<<16,n[2]<<8),n[3]),s)}static fromHash(n){let s=t;return e[s(756)](n,Yr)?Xd:new ue(e[s(1752)](e[s(1681)](e[s(1005)](Pe.call(n,0),Pe[s(1258)](n,1)<<8),e.KTMze(Pe[s(1258)](n,2),16))|e.MYgNd(Pe[s(1258)](n,3),24),0),e.xtHlo(e[s(511)](Pe[s(1258)](n,4)|e[s(1682)](Pe.call(n,5),8)|e[s(820)](Pe.call(n,6),16),e.mDvRf(Pe[s(1258)](n,7),24)),0),!0)}[t(1411)](){let n=t;return String[n(569)+n(632)](e.JFjpX(255,this[n(1828)]),e[n(1416)](this[n(1828)],8)&255,e.heiQr(e.bPcZM(this[n(1828)],16),255),e[n(1810)](this[n(1828)],24),e.aneRL(255,this.high),e[n(1430)](e[n(1752)](this[n(1701)],8),255),e.nknxu(e[n(963)](this.high,16),255),this.high>>>24)}static[t(1800)+"er"](n,s=!0){let l=t;if(e.oYMFI(isNaN,n))return s?Ap:Xd;if(s){if(n>=Ie)return Tp}else{if(n<=-Qn)return Rp;if(e[l(1230)](e[l(1206)](n,1),Qn))return kp}return ue.fromBits(e.HfiLh(n,we)|0,e[l(878)](n/we,0),s)}[t(1659)](){let n=t;return this[n(397)]?e.nWrQE(e.SNjNu(this[n(1701)],0),we)+e.UOfme(this[n(1828)],0):e[n(854)](this[n(1701)],we)+e.slkFk(this[n(1828)],0)}[t(1266)](){let n=t;return this[n(1701)]===0&&e[n(489)](0,this[n(1828)])}[t(1117)](n){let s=t;if(e[s(1479)]("edwWn",s(1689))){ue[s(1321)](n)||(n=ue.fromNumber(n));let l=e[s(1170)](this.high,16),x=65535&this[s(1701)],m=e[s(1239)](this[s(1828)],16),b=e[s(778)](65535,this[s(1828)]),E=e[s(1680)](n[s(1701)],16),p=e[s(790)](65535,n[s(1701)]),k=e[s(1148)](n[s(1828)],16),P=e[s(999)](65535,n[s(1828)]),N=0,z=0,H=0,ge=0;return ge+=e[s(1062)](b,P),H+=ge>>>16,ge&=65535,H+=m+k,z+=e[s(1810)](H,16),H&=65535,z+=e[s(796)](x,p),N+=z>>>16,z&=65535,N+=e[s(1846)](l,E),N&=65535,ue[s(1467)](e[s(878)](e[s(1327)](H,16),ge),e[s(393)](N<<16,z),this[s(397)])}else _0x2116ec(this[s(1092)+s(1268)+"utId"]),this[s(1092)+s(1268)+s(1630)]=null}[t(1921)](n){let s=t;return ue[s(1321)](n)||(n=ue[s(1800)+"er"](n)),e[s(1393)](this.unsigned,n.unsigned)&&e[s(597)](this[s(1701)],31)===1&&e[s(808)](n[s(1701)]>>>31,1)?!1:this[s(1701)]===n.high&&e[s(866)](this[s(1828)],n[s(1828)])}[t(643)](){let n=t;return e[n(1260)](-1,this.low)&&e[n(539)](-1,this.high)?ue[n(1467)](0,0,this.unsigned):e[n(1295)](-1,this[n(1828)])?ue[n(1467)](0,e.QxGET(this[n(1701)],1),this[n(397)]):ue.fromBits(e.yEiFw(this.low,1),this[n(1701)],this.unsigned)}[t(1725)](n){let s=t;return n?this[s(1090)+"E"]():this[s(1604)+"E"]()}[t(1090)+"E"](){let n=t;if(e[n(489)](n(641),n(1276)))_0x4b8512.o=(s,l)=>_0x2c60b9[n(1605)+"e"][n(502)+n(1663)][n(1258)](s,l);else{let s=this.high,l=this[n(1828)];return[e[n(1610)](255,l),e[n(1826)](e[n(1137)](l,8),255),e[n(1003)](e[n(1909)](l,16),255),e[n(545)](l,24),e[n(544)](255,s),e[n(1247)](s>>>8,255),e[n(1610)](e[n(963)](s,16),255),s>>>24]}}[t(1604)+"E"](){let n=t,s=this[n(1701)],l=this[n(1828)];return[e[n(818)](s,24),e.kQlcR(e[n(1148)](s,16),255),e[n(1857)](e[n(597)](s,8),255),e[n(1610)](255,s),l>>>24,e[n(1656)](e.xtHlo(l,16),255),e.lZJbk(e[n(1768)](l,8),255),e[n(1129)](255,l)]}}let Xd=new ue(0,0,!1),Ap=new ue(0,0,!0),kp=ue[t(1467)](-1,2147483647,!1),Tp=ue[t(1467)](-1,-1,!0),Rp=ue[t(1467)](0,-2147483648,!1);var tn=(function(a){let n=t,s=e[n(1923)][n(573)]("|"),l=0;for(;;){switch(s[l++]){case"0":a[a[e.TZEea]=5004]=n(496)+n(1617);continue;case"1":a[a[e.xarJn]=5001]=e[n(817)];continue;case"2":a[a[n(1145)+"NG_ERROR"]=5002]=e[n(1777)];continue;case"3":a[a[n(441)+n(1782)+"R"]=5003]=e[n(1172)];continue;case"4":return a;case"5":a[a[n(1063)+"OR"]=5005]=e[n(1785)];continue}break}})({});class er{constructor(n){let s=t;this[s(1180)]=n,this[s(931)]=null}}class Qd extends er{constructor(n,s){let l=t;super(n),this.message=s&&s[l(876)]||null}}class el extends er{constructor(n,s){let l=t,x=e.vSbDE.split("|"),m=0;for(;;){switch(x[m++]){case"0":this[l(876)]=s&&s[l(876)]||"";continue;case"1":this[l(1263)]=s&&s.filename||"";continue;case"2":this[l(1669)]=s&&s[l(1669)]||0;continue;case"3":this[l(1622)]=s&&s[l(1622)]||null;continue;case"4":super(n);continue;case"5":this[l(1019)]=s&&s[l(1019)]||5001;continue;case"6":this[l(1225)]=s&&s.lineno||0;continue}break}}}class tl extends er{constructor(n,s){let l=t,x=e[l(1420)][l(573)]("|"),m=0;for(;;){switch(x[m++]){case"0":this[l(753)+l(1936)]=s&&s[l(753)+l(1936)]||!1;continue;case"1":super(n);continue;case"2":this[l(1825)]=s&&s[l(1825)]||"";continue;case"3":this.wasClean=s&&s.wasClean||!1;continue;case"4":this[l(1019)]=s&&s.code||0;continue}break}}}class nl extends er{constructor(n,s){let l=t;if(e[l(1484)](l(1759),e[l(1539)]))super(n),this[l(1320)]=s&&s[l(1320)]||null;else{let x=e[l(550)](_0x1ed328,e.BapYb,{message:_0x17e251[l(876)],code:_0x55b173[l(496)+l(1617)],error:_0x1d39fd});this["_dispatc"+l(1840)+l(1838)](x)}}}class rl extends nl{constructor(n,s){let l=t;super(n),this[l(1320)]=s&&s[l(1320)]||null,this[l(876)]=s&&s[l(876)]||null}}class il extends er{constructor(n,s){super(n),this.data=s&&s.data||null}}function ct(a,{message:n,code:s,error:l}){return new el(a,{message:n,code:s,error:l})}function pt(a,{code:n,reason:s,wasClean:l,willReconnect:x}){return new tl(a,{code:n,reason:s,wasClean:l,willReconnect:x})}function sl(a,{data:n,message:s}){return new rl(a,{data:n,message:s})}function ol(a,{data:n}){return new il(a,{data:n})}function ua(a,{message:n}){return new Qd(a,{message:n})}class al{constructor(n,s){let l=t;this.endpoints=n,this[l(1829)+"es"]=s,this["currentI"+l(1585)]=0,this[l(985)+"ndpointTriesCount"]=0}["resetEndpointCon"+t(1270)](){let n=t;if(e.PvxSg!==e.zMGqK)this[n(1273)+n(1585)]=0,this[n(985)+n(1697)+n(1493)+"t"]=0;else{let s=this[n(1701)],l=this[n(1828)];return[e[n(790)](255,l),e[n(1088)](e[n(1139)](l,8),255),e[n(1710)](e[n(703)](l,16),255),e[n(1095)](l,24),e[n(1380)](255,s),e[n(1731)](e.qkAFF(s,8),255),e[n(1731)](s>>>16,255),e[n(894)](s,24)]}}[t(1271)+"es"](){let n=t;this[n(985)+n(1697)+n(1493)+"t"]=0}[t(1353)+t(375)+"nt"](){let n=t;return this.endpoints[this[n(1273)+n(1585)]]}[t(1353)+"ntEndpointTriesC"+t(421)](){let n=t;if(e.wYasA(e.RjClv,e[n(1552)]))return this[n(985)+"ndpointT"+n(1493)+"t"];{let{enableAutoAck:s}=this._options,l=_0x13d308(_0x296cba[n(876)].headers,n(1405),"1"),x=_0x240eb4(_0x5e9db4.message[n(1061)],e.npmlF,"1"),m=_0x3612ab.call(this,_0x37fab5);if(s&&l){let{SeqID:b,LogID:E,service:p,LogIDNew:k,method:P}=_0x593859[n(876)];this._sendAck({SeqID:b,LogID:E,LogIDNew:k,service:p,method:P,headers:[{key:e[n(1865)],value:"1"},{key:e[n(1388)],value:e.eMxCt(k,"")},{key:n(431),value:"0"}]})}x&&!m[n(849)]&&this[n(700)+"hAckMessageEvent"](_0x596d8d),e[n(522)](_0x82aba8)}}[t(1022)+t(1925)+"es"](){let n=t;return!!(e.oimiw(this[n(1273)+"ndex"],this[n(493)+"s"][n(1027)])||this[n(1273)+n(1585)]===this.endpoints.length-1&&e[n(690)](this[n(985)+n(1697)+n(1493)+"t"],this[n(1829)+"es"]))}[t(1839)+t(627)+t(961)+"hedMaxRe"+t(871)](){let n=t;return e.PByTA(this[n(1273)+n(1585)],this[n(493)+"s"][n(1027)])?!0:this[n(985)+n(1697)+n(1493)+"t"]>this[n(1829)+"es"]}[t(1162)+t(1413)+t(1119)+t(615)+t(1881)](){let n=t;return this["currentEndpointT"+n(1493)+"t"]=1,this[n(1273)+n(1585)]++,this[n(493)+"s"][this["currentI"+n(1585)]]}[t(1353)+"ntEndpoi"+t(1613)+t(720)](){let n=t;return this[n(985)+"ndpointT"+n(1493)+"t"]++,this[n(1353)+n(375)+"nt"]()}}let tr=(e[t(448)](e.yotwY,typeof globalThis)&&e[t(672)]("Window",globalThis[t(1227)+t(1570)].name)||e[t(1712)](e[t(1722)],typeof window)&&e[t(1644)](e[t(983)],window.constructor[t(1917)]))&&e[t(1023)](e[t(1722)],typeof document),Rn=e[t(1023)](t(376)+"d",typeof globalThis)&&(e.aSYtd===globalThis[t(1227)+t(1570)][t(1917)]||e[t(1404)]===globalThis[t(1227)+t(1570)][t(1917)])&&e[t(1722)]!=typeof tt,Zr=(e[t(448)](e.yotwY,typeof globalThis)&&t(1488)===globalThis[t(1227)+t(1570)][t(1917)]||e[t(1080)](e[t(1722)],typeof globalThis)||e[t(1722)]!=typeof globalThis&&!!globalThis[t(851)+t(1783)])&&e[t(1156)](e.yotwY,typeof wx),Jr=e[t(448)](e[t(1722)],typeof globalThis)&&(e[t(1404)]===globalThis[t(1227)+"tor"][t(1917)]||e[t(942)]("SharedWorkerGlobalScope",globalThis[t(1227)+t(1570)][t(1917)])||e[t(1781)](e[t(1451)],globalThis[t(1227)+t(1570)][t(1917)]))&&e[t(1862)](e.yotwY,typeof self),Cp=e.yotwY!=typeof globalThis&&e[t(1415)](e[t(1639)],globalThis.constructor[t(1917)])&&e.IJApq(e[t(1722)],typeof global)&&e.aSYtd===global.constructor[t(1917)]&&e[t(1376)](t(376)+"d",typeof process)&&!!process[t(389)];class fa{constructor(){this._listeners={}}emit(n,...s){let l=t,x=this._listeners[n];if(x)x[l(708)]()[l(1869)](m=>m.fn[l(799)](m.ctx,s));else if(e[l(1479)](e[l(855)],n)&&!this[l(1559)]){let m=s[l(1027)]&&s[0];if(m instanceof Error)throw m;let b=new Error(e[l(1696)](e[l(1377)],m?e[l(1713)](" (",m.message)+")":""));throw b[l(479)]=m,m}return this}[t(1787)](n,s){let l=t;if(e[l(1295)](void 0,n))this._listeners={};else if(e[l(822)](void 0,s))this[l(698)+"rs"][n]=null;else{let x=this._listeners[n];if(x)for(let m=0;e.PLHwh(m,x.length);)e[l(539)](x[m].fn,s)?x[l(633)](m,1):++m}return this}on(n,s,l){let x=t;return(this[x(698)+"rs"][n]||(this[x(698)+"rs"][n]=[]))[x(1408)]({fn:s,ctx:l||this}),this}}class Dp extends fa{["_formatE"+t(415)+t(1900)](n){let s=t;return n.errMsg||n[s(1089)]?(s(1767)+" "+(n[s(1289)]||"")+s(593)+(n.errNo||""))[s(918)]():JSON[s(1627)+"y"](n)}constructor(n,s,l){let x=t;if(e.LHCfa(e[x(610)],e[x(610)])){_0x46ed33[x(1321)](_0x9e5979)||(_0x4da5ef=_0x356be0[x(1800)+"er"](_0x14d052));let m=e[x(1531)](this.high,16),b=e[x(833)](65535,this[x(1701)]),E=this[x(1828)]>>>16,p=e[x(1826)](65535,this[x(1828)]),k=_0x3f264b[x(1701)]>>>16,P=e[x(1765)](65535,_0x46b252.high),N=e[x(1139)](_0x527500[x(1828)],16),z=e[x(491)](65535,_0x1414a9[x(1828)]),H=0,ge=0,Ae=0,Be=0;return Be+=p+z,Ae+=e[x(741)](Be,16),Be&=65535,Ae+=e[x(1361)](E,N),ge+=e[x(1137)](Ae,16),Ae&=65535,ge+=b+P,H+=ge>>>16,ge&=65535,H+=m+k,H&=65535,_0x407b8d[x(1467)](e[x(1343)](e.vJFeK(Ae,16),Be),e[x(713)](H<<16,ge),this[x(397)])}else super(),this[x(897)]=null,Zr&&wx[x(1106)+x(714)]&&(this._socket=wx[x(1106)+x(714)]({url:n,protocols:s,header:l,fail:this["_createS"+x(1030)+x(1677)][x(605)](this),success:this["_createS"+x(1212)+x(468)+"ler"][x(605)](this)})),Rn&&tt["connectS"+x(714)]&&(this[x(897)]=tt[x(1106)+"ocket"]({url:n,protocols:s,header:l,fail:this[x(1658)+x(1030)+x(1677)].bind(this),success:this[x(1658)+x(1212)+x(468)+x(884)].bind(this)}))}[t(1658)+"ocketSuc"+t(468)+t(884)](){let n=t,s={HURtv:e[n(1461)],wbuqw:e[n(782)],ZiNCI:function(l,x){return e[n(1742)](l,x)},vkzgo:e[n(911)],GjqFG:e.zhdkr};Promise[n(1774)]().then(()=>{let l=n;s[l(650)](s.vkzgo,s.GjqFG)?this[l(373)+l(1891)]():(this[l(830)+"er"]&&_0x1cee37[l(1328)+l(1455)+l(1616)](l(1426),this[l(427)+"nLine"]),this._isBrowser&&_0x533801[l(1328)+"entListe"+l(1616)](s[l(1822)],this[l(427)+l(1662)]),this[l(830)+"er"]&&_0x222467.removeEventListener(s[l(850)],this[l(864)+l(1436)]),this[l(830)+"er"]&&_0x373731[l(1328)+l(1455)+l(1616)](l(896),this[l(864)+"ageShow"]))})}[t(1658)+t(1030)+t(1677)](n){let s=t,l={oYXBn:function(x,m,b){return e[V(738)](x,m,b)},buWJl:e[s(855)],EEnzB:e[s(1561)]};Promise[s(1774)]().then(()=>{let x=s,m=l[x(1128)](ct,l[x(1013)],{message:this[x(1590)+"rrorMess"+x(1900)](n)});this[x(1648)](x(1622),m);let b=l[x(1128)](pt,l[x(1414)],{reason:this[x(1590)+"rrorMessage"](n)});this.emit(x(1594),b)})}[t(373)+t(1891)](){let n=t,s={gxmOO:e.xfAIw,yXRib:function(l,x,m){return e[V(819)](l,x,m)}};this[n(897)][n(1903)](l=>{let x=n;this[x(1648)](x(1554),ol(e[x(1798)],{...l,data:l[x(1289)]||""}))}),this[n(897)][n(873)](l=>{let x=n;this[x(1648)](s[x(1809)],s[x(483)](pt,s.gxmOO,{...l}))}),this[n(897)][n(1499)+"e"](l=>{let x=n;this.emit(x(876),e.jmFhY(sl,e[x(828)],{...l}))}),this[n(897)][n(514)](l=>{let x=n;this.emit(e[x(855)],e[x(550)](ct,e[x(855)],{...l,message:l[x(1289)]||""}))})}[t(1926)](n){let s=t,l={qnHLN:e.BapYb,AIgmY:function(x,m,b){return e.XUHed(x,m,b)}};if(e[s(1821)](n,Uint8Array)){let x=n[s(494)][s(708)](n[s(930)+"et"],e[s(1713)](n.byteLength,n[s(930)+"et"]));this[s(897)]&&this._socket[s(1926)]({data:x,fail:m=>{let b=s;this[b(1648)](l.qnHLN,l[b(899)](ct,l[b(1902)],{message:this["_formatE"+b(415)+"age"](m)}))}})}else this[s(897)]&&this[s(897)][s(1926)]({data:n,fail:x=>{let m=s;this[m(1648)](m(1622),l.AIgmY(ct,l[m(1902)],{message:this[m(1590)+m(415)+m(1900)](x)}))}})}[t(1594)](n,s){let l=t;this._socket&&this[l(897)][l(1594)]({code:n,reason:s})}[t(1091)+t(658)](n,s){this.on(n,s)}[t(1328)+t(1455)+t(1616)](n,s){let l=t;if(e[l(1650)](l(1647),e[l(555)]))this[l(1787)](n,s);else try{return e[l(649)](e.jQEFW,typeof _0x2de20d)&&(_0x5074a5 instanceof _0x5dcbaf||_0x30766f[l(494)]&&e.STqEp(_0x5361d1.buffer,_0x5e231a))||e[l(1692)](e[l(1036)],typeof _0x155502)?"":(_0x366932[l(859)](_0x362074),e[l(1895)])}catch{return e[l(836)](e[l(1036)],typeof _0x14328f)?e[l(1721)]:""}}get readyState(){let n=t;return this[n(897)][n(452)+"te"]}get[t(1351)+"pe"](){let n=t;return this[n(897)][n(1351)+"pe"]}set[t(1351)+"pe"](n){}get[t(564)](){let n=t;return this[n(897)][n(564)]}get[t(666)](){let n=t;return this[n(897)][n(666)]}get extensions(){let n=t;return e[n(1087)]!=="EObNg"?_0x10c7bf||(_0x3cc11d=[_0x428a6d,_0x53146e,_0x1c358c,_0xd4c774,_0x549eb2]):this._socket[n(536)+"ns"]}get[t(1208)+t(507)](){let n=t;if(e[n(1719)]!==e[n(1719)])this[n(1648)](e[n(855)],e[n(1867)](_0x109862,e[n(855)],{message:this["_formatE"+n(415)+n(1900)](_0x4d011b)}));else return 0}}function Pp(a,n){let s=t;if(n)return new n(a[s(564)],a.protocol);if(e[s(1008)](Zr,Rn))return new Dp(a[s(564)],a[s(666)],a.headers);if(e[s(1920)](tr,Jr)&&e[s(1722)]!=typeof WebSocket&&WebSocket)return new WebSocket(a[s(564)],a[s(666)+"s"])}function Op(a){let n=t;return!!(a||Zr&&wx[n(1106)+n(714)]||Rn&&tt[n(1106)+n(714)]||e[n(1008)](tr,Jr)&&e[n(556)](e[n(1722)],typeof WebSocket)&&WebSocket)}function cl(a,n,s){let l=t,x={yLWIB:function(E,p){return e[V(690)](E,p)},HyVqQ:function(E,p){return e[V(1123)](E,p)}},m=-1;async function b(E){let p=V;return E<=m?Promise[p(1675)](new Error(p(1673)+p(1849)+"ltiple t"+p(768)+p(1859))):(m=E,x[p(883)](E,s.length)?Promise[p(1774)]():s[E].bind(a)(n,b[p(605)](null,x.HyVqQ(E,1))))}e[l(1905)](b,0)}function dl(a){let n=t,s=0,l=0;for(let x=0;e[n(1611)](x,a[n(1027)]);++x)l=a[n(1736)+"At"](x),e[n(1150)](l,128)?s+=1:e[n(480)](l,2048)?s+=2:e[n(395)](e[n(562)](64512,l),55296)&&e[n(1277)](64512,a[n(1736)+"At"](e[n(1696)](x,1)))===56320?(++x,s+=4):s+=3;return s}function ll(a,n,s){let l=t,x={GGlTQ:"error",EnpCJ:function(m,b,E){return e[V(1161)](m,b,E)},ZzzHh:function(m,b,E){return e[V(1259)](m,b,E)},EmcuV:function(m,b){return e[V(1016)](m,b)}};if(e[l(1032)](l(1589),e[l(668)])){if(e[l(1127)](e[l(1207)](s,n),1))return"";let m="";for(let b=n;e[l(1904)](b,s);){let E=a[b++];if(e[l(1453)](E,127))m+=String[l(569)+"Code"](E);else if(e[l(1476)](E,192)&&e.LGAgH(E,224))m+=String[l(569)+l(632)]((31&E)<<6|e[l(726)](63,a[b++]));else if(e[l(532)](E,224)&&e[l(1074)](E,240))m+=String["fromChar"+l(632)](e[l(1922)]((15&E)<<12|e[l(1517)](e.hqyuC(63,a[b++]),6),e[l(1236)](63,a[b++])));else if(e.FngzY(E,240)){let p=e.YgDPD(e[l(1638)](e[l(1897)](e.sfVFB(e.IKpWT(7,E),18),e[l(1082)](e.fdcNk(63,a[b++]),12)),e[l(1911)](63&a[b++],6))|e[l(530)](63,a[b++]),65536);m+=String[l(569)+l(632)](55296+(p>>10)),m+=String[l(569)+l(632)](e[l(1510)](56320,e[l(1748)](1023,p)))}}return m}else if(_0x5cc4ce instanceof _0x44d4f5){let m=_0x48a627[l(494)].slice(_0x44d59a[l(930)+"et"],WQGrYp[l(1665)](_0x4c47d0[l(1741)+"th"],_0x459a01[l(930)+"et"]));this[l(897)]&&this[l(897)][l(1926)]({data:m,fail:b=>{let E=l;this[E(1648)](WQGrYp[E(1418)],WQGrYp[E(1143)](_0x37fb92,WQGrYp[E(1418)],{message:this[E(1590)+E(415)+E(1900)](b)}))}})}else this[l(897)]&&this[l(897)][l(1926)]({data:_0x39ce64,fail:m=>{let b=l;this[b(1648)](WQGrYp.GGlTQ,WQGrYp.ZzzHh(_0x423421,b(1622),{message:this["_formatE"+b(415)+"age"](m)}))}})}function xa(a,n,s){let l=t,x=s,m,b;for(let E=0;e[l(1437)](E,a[l(1027)]);++E)if(m=a.charCodeAt(E),e[l(1904)](m,128))n[s++]=m;else if(e[l(392)](m,2048))n[s++]=e[l(1035)](e[l(500)](m,6),192),n[s++]=e.tGqyf(e.tpljl(63,m),128);else if(e[l(433)](e.anhpd(64512,m),55296)&&e[l(1504)](64512,b=a[l(1736)+"At"](e[l(1674)](E,1)))===56320){let p=e[l(825)][l(573)]("|"),k=0;for(;;){switch(p[k++]){case"0":n[s++]=e[l(1005)](e[l(505)](m,12)&63,128);continue;case"1":n[s++]=63&m|128;continue;case"2":++E;continue;case"3":n[s++]=e.daeJT(e.NlDLf(m,18),240);continue;case"4":n[s++]=e.PdVKw(m,6)&63|128;continue;case"5":m=65536+e[l(1082)](1023&m,10)+e[l(579)](1023,b);continue}break}}else n[s++]=e[l(1318)](e[l(505)](m,12),224),n[s++]=e[l(1163)](e.PspSK(e[l(634)](m,6),63),128),n[s++]=e[l(1638)](63&m,128);return e[l(1207)](s,x)}async function ul(a){let n=t;if(e.DEtNQ(e[n(1036)],typeof a)){let s=new Uint8Array(dl(a));return e[n(1797)](xa,a,s,0),s}return a instanceof ArrayBuffer?new Uint8Array(a):new Uint8Array(a.buffer,a[n(930)+"et"],a.byteLength)}function Lp(a){let n=t;try{return e[n(556)](e[n(1036)],typeof a)&&(a instanceof ArrayBuffer||a[n(494)]&&e[n(1821)](a[n(494)],ArrayBuffer))||e.ehEBp(n(1871),typeof a)?"":(JSON[n(859)](a),e[n(1895)])}catch{if(e[n(663)]===e[n(663)])return e.uvFnN(e[n(1036)],typeof a)?e.xUghm:"";this[n(1520)+n(734)]()}}let Np=(a,n)=>{let s=t;if(e[s(1196)](e[s(475)],e[s(475)]))return aSVKSR[s(1821)](_0x3c29db,_0x4eb03b)&&(aSVKSR.oZkeY(_0x2fdebc,aSVKSR.SOhlZ)||_0x3c76b0===aSVKSR[s(889)])?!0:aSVKSR.WZFOj(_0x16ccf1,_0x105dbf);switch(a){case s(1358):case s(1421):return{["x-use-"+a]:1,"x-tt-env":n};default:return{}}};class Mp{constructor(n){let s=t;this[s(606)+s(421)]=n,this[s(1747)]=0}addCount(){let n=t;this[n(1747)]++}[t(1022)+t(1621)+"nt"](){let n=t;return e.WFOHi(this[n(1747)],this[n(606)+"ount"])}[t(1140)+"nter"](n=0){let s=t;this["maxLossC"+s(421)]=n,this[s(1747)]=0}}async function Bp(a){let n=t,s={KokBN:n(1633)+n(676)+n(509)+n(1845)+n(1419)};return new Promise(l=>{let x=n,m={VCotH:function(b,E){return e[V(533)](b,E)},Jyusm:x(1014)+"reason"};if(e[x(1265)](e[x(499)],e[x(1433)])){if(!tr)return e[x(1764)](l,e.APmgf);try{let b=document[x(1734)+x(1555)](e.EHWFt);window["frontier"+x(1142)]=E=>{let p=x;document[p(816)].removeChild(b),window[p(780)+p(1142)]=void 0,m[p(1542)](l,E&&E[p(1291)]||m[p(1761)])},b[x(1180)]=e[x(1218)],b[x(1919)]=e[x(1297)](a.replace(/^ws/,x(1726)),"&jscallb"+x(1102)+x(594)+"P");try{document[x(816)].appendChild(b)}catch{document[x(816)]["removeCh"+x(1482)](b)}}catch{if(e.yJENu(e.oDjzO,e[x(1049)])){if(!this[x(1583)+x(1231)]()||this[x(446)+x(1201)])return;this[x(1398)+"tManager"]?.["resetEnd"+x(733)+"fig"](),this[x(1737)+x(1323)]?.[x(1140)+x(524)](),this[x(1136)]?this[x(1299)+"ect"](1001,s[x(1394)],!0):this[x(1092)]()}else window[x(780)+x(1142)]=void 0,e[x(1740)](l,e[x(1055)])}}else _0x2b165f[x(816)][x(939)+x(1482)](_0x4256ee)})}function nn(a,n,s){let l=t;return!!a?.[l(993)](x=>x[l(1369)]===n&&x[l(1326)]===s)}function nr(a,n){let s=t;if(e[s(433)](s(801),e[s(1185)]))_0x53b7e8=e[s(656)](e[s(1307)](31,_0x138585),6)|e[s(948)](63,_0x4a07ce),_0x4c7437<128?_0x16979e+=_0x338552:(_0x263bfc+=_0x1d9c0d(_0x104ce6),_0x457d3e++);else return a?.[s(993)](l=>l.key===n)?.[s(1326)]}let ha=null;async function Fp(){let a=t;return ha||(ha=Promise[a(1774)]().then(Mt[a(605)](Mt,e[a(772)]))),ha}class zp extends fa{constructor(n,s){let l=t;super(),this[l(1775)]=n,this[l(1672)]=s,this[l(719)]=void 0,this[l(1661)+l(1820)]=null}async[t(1386)](){await this[t(1854)]()}async _init(){let n=t,s={RCFsL:e[n(1483)],hAofG:function(l,x){return e[n(1444)](l,x)},TMZID:e.wZRtC,TSHuA:e[n(704)]};if(!this[n(719)]){if(this[n(1661)+"mise"])return this._initPromise;try{if(e[n(433)](n(1618),e[n(987)]))this["maxLossC"+n(421)]=_0x57e16e,this[n(1747)]=0;else{let l=this[n(1775)],x=this._keyPath;this[n(1661)+n(1820)]=(async()=>{let m=n;if(s[m(1054)](s.TMZID,s[m(1251)])){let{openDB:b}=await Fp();this[m(719)]=await b(m(780)+"_"+l,1,{upgrade(E){let p=m;E[p(1021)+p(571)+"e"](l,{keyPath:x})}})}else this[m(1737)+m(1323)]?.[m(504)](),this[m(1648)](m(371)+m(774)+"t",s[m(1497)]),this[m(1737)+"sCounter"]?.[m(1022)+m(1621)+"nt"]()?this[m(619)+m(1290)]():this[m(624)]()})(),await this[n(1661)+n(1820)]}}catch(l){if(e[n(629)](e.adkIZ,e[n(1794)]))return e[n(532)](this[n(1747)],this["maxLossC"+n(421)]);console[n(1024)](l)}finally{this[n(1661)+n(1820)]=null}}}async[t(1346)](n){let s=t,l={dmdei:e[s(1657)],EtOMd:"ppe"};try{if(e[s(1314)](e[s(1597)],e[s(552)]))switch(_0x3511d9){case iUtCpT.dmdei:case iUtCpT[s(1804)]:return{[s(366)+_0x45fe13]:1,"x-tt-env":_0x1e6ca9};default:return{}}else return await this[s(1854)](),this._qosDB?.[s(1346)](this._dbName,n)}catch(x){console[s(1024)](x)}}async[t(1240)](n,s){let l=t;if(e[l(1841)](l(620),e.pxbzA)){let x=_0x23f21b.low,m=_0x3c2b83[l(1701)];return _0x4ffec9[_0x44a439]=m>>>24,_0x429809[e.ORpkb(_0x264ca8,1)]=e[l(377)](m,16)&255,_0x5916c1[e[l(910)](_0x2da901,2)]=e[l(1610)](m>>>8,255),_0x1cc28c[e[l(1608)](_0x348c09,3)]=e.BuOlP(255,m),_0x1be15a[e[l(1123)](_0x1a9e97,4)]=x>>>24,_0x2f43e0[e[l(1018)](_0xbb9b25,5)]=e[l(1745)](e[l(1913)](x,16),255),_0x9c87ff[e[l(1062)](_0x43dd00,6)]=e.AtgOU(e.DwAFH(x,8),255),_0x215bef[e.lKrxP(_0x179a3f,7)]=e.kQlcR(255,x),_0x5a0e97+=8,_0x4175d9}else return await this[l(1854)](),this._qosDB?.[l(1873)](this._dbName,n)}async del(n){let s=t;try{return await this[s(1854)](),this[s(719)]?.delete(this[s(1775)],n)}catch(l){console[s(1024)](l)}}async[t(1685)](){let n=t;if(e.qbFES(e.dakzl,e[n(1118)]))return this[n(719)]?.get(_0x4df580);try{return await this[n(1854)](),this[n(719)]?.[n(1685)](this[n(1775)])}catch(s){console.log(s)}}async[t(926)](){let n=t,s={jALXE:e[n(1502)]};if(e.fXZCW(e.mXZbL,e[n(1329)]))_0x5dd941&&_0x144dbc[n(1091)+n(658)](n(1594),()=>_0x584361()),_0x1d592a&&_0x1b0718[n(1091)+"Listener"](KGXIoA[n(1296)],()=>_0x2ee045());else return await this._init(),this[n(719)]?.getAllKeys(this[n(1775)])}async[t(914)](){let n=t;return await this[n(1854)](),this[n(719)]?.[n(914)](this[n(1775)])}async[t(590)](){let n=t;try{this[n(719)]?.[n(1594)](),this[n(719)]=void 0}catch(s){console.log(s)}}get[t(541)](){let n=t;if(e.pkVzh(e[n(1357)],n(558)))this["_navigat"+n(1231)]()&&(!this[n(1136)]||e[n(1336)](this[n(1136)][n(452)+"te"],this[n(394)])||e[n(490)](this[n(1136)].readyState,this.CONNECTING))&&this[n(427)+"nLine"](),this[n(830)+"er"]&&_0x268622[n(1091)+n(658)](e.ChZJt,this[n(427)+"nLine"]),this[n(830)+"er"]&&_0x423bda[n(1091)+n(658)](e[n(1461)],this[n(427)+"ffLine"]);else try{return!!this._qosDB}catch(s){return console[n(1024)](s),!1}}}class Up{constructor(n,s){let l=t;this._DBName=n,this._pathKey=s,this[l(719)]=localStorage}async[t(1386)](){}get[t(1729)](){let n=t;return n(780)+"_"+this[n(912)]}async[t(1346)](n){let s=t,l=this._qosDB[s(1596)](this._prefix);return JSON[s(859)](e[s(964)](l,"{}"))[n]}async set(n,s){let l=t,x=this[l(719)][l(1596)](this[l(1729)]),m=JSON.parse(e.osxcP(x,"{}"));return m[s||n[this[l(486)]]]=n,this[l(719)][l(1815)](this._prefix,JSON.stringify(m)),s||n[this._pathKey]}async[t(848)](n){let s=t;if(e[s(921)]===e[s(921)]){let l=this[s(719)][s(1596)](this[s(1729)]),x=JSON[s(859)](e.WamSy(l,"{}"));return x[n]=void 0,this[s(719)][s(1815)](this._prefix,JSON.stringify(x))}else return _0x42bd31[s(1774)]()}async[t(1685)](){let n=t;return this[n(719)][n(1685)]()}async[t(926)](){let n=t,s=this._qosDB[n(1596)](this[n(1729)]),l=JSON.parse(e[n(1008)](s,"{}"));return Object[n(926)](l)}async[t(914)](){let n=t,s={CIbza:e[n(1561)],ghgDd:function(l,x,m){return e[n(852)](l,x,m)},SYGfF:"bye",muVot:function(l,x,m){return e[n(551)](l,x,m)},bzbgj:e.lutVl};if(e[n(1742)](e[n(1311)],e.IgPBe)){if(this["_clearPi"+n(862)](),this[n(1059)+n(1121)](),this[n(492)+n(1385)+"rs"](),this[n(861)+n(943)](1e3,_0x298fff),this[n(1092)+n(464)]=!1,_0x14d439&&this[n(1583)+n(1231)]()&&!this[n(446)+n(1201)]){if(this[n(1398)+n(1910)]?.["checkRea"+n(1925)+"es"]()){let x=this._endpointManager?.[n(1353)+"ntEndpoint"]();this["_dispatc"+n(526)+n(1838)](_0x3dc8a6(s[n(1399)],{code:1006,reason:n(1727)+x+(" timeout"+n(1028)+n(1134)+n(1843)),wasClean:!0}))}else{let x=this._options[n(509)+n(1379)+n(534)](_0x184be7,_0x39d13e);this[n(700)+n(526)+n(1838)](s.ghgDd(_0x2a6abe,s[n(1399)],{code:_0x52dadd,reason:_0x31d5d,wasClean:!0,willReconnect:x})),x&&this[n(1092)]()}return}this[n(1583)+n(1231)]()||this["_readyCl"+n(1201)]?this[n(700)+n(526)+n(1838)](s[n(1586)](_0x27eb14,s[n(1399)],{code:_0x59fefd,reason:s[n(1131)]})):this[n(700)+n(526)+"ent"](s.muVot(_0xab9369,n(1594),{code:1006,reason:s[n(424)]})),this._ws=null,this["_endpoin"+n(1910)]?.[n(409)+"pointConfig"](),this["_pingLos"+n(1323)]?.[n(1140)+n(524)]()}else{let l=this._qosDB[n(1596)](this[n(1729)]),x=JSON.parse(l||"{}");return Object[n(428)](x)}}[t(590)](){return Promise[t(1774)]()}get isReady(){let n=t,s={pSTvj:function(l,x,m,b){return l(x,m,b)},BfuoK:e[n(929)],mRIuz:e.jpWiD,lwffH:function(l,x,m){return e[n(576)](l,x,m)},rjkCy:n(1310)+n(1281)+n(436)};if(e[n(422)]===e.QyboU)return!!this[n(719)];{let l=!!this[n(1637)][n(1544)+"S"];if(!l)return{enabled:l,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let x=s[n(543)](_0x150b2f,_0x3835bd[n(876)][n(1061)],s[n(1908)],"2"),m=x&&s.pSTvj(_0x30d4f1,_0x1bd769[n(876)][n(1061)],s[n(1509)],"1"),b=x&&_0x1ddf3f(_0x2e9bbc[n(876)][n(1061)],n(1310)+n(1852)+"k","1"),E=b?s[n(933)](_0x28b263,_0x41582b[n(876)][n(1061)],s[n(1010)])?.[n(573)](",")[n(1253)](_0x1f24e2)||[]:[];return{enabled:l,isQoSMessage:x,isQoSAck:m,isAckCleanupMessage:b,ackMsgIds:E}}}}class Gp{constructor(n,s){let l=t,x={vLvJM:function(m,b){return e[V(1314)](m,b)},kKpJa:function(m,b){return e[V(822)](m,b)}};if(e.pFIzm(e[l(1443)],e.kYwVU))return LDcEup[l(868)](0,this[l(1701)])&&LDcEup[l(959)](0,this.low);this._DBName=n,this[l(486)]=s,this[l(719)]=Rn?tt:Zr?wx:null}async[t(1386)](){}get[t(1729)](){return"frontier_"+this[t(912)]}async get(n){let s=t,l=this[s(719)]["getStora"+s(1171)](this[s(1729)]);return JSON.parse(l||"{}")[n]}async set(n,s){let l=t,x=this._qosDB[l(1283)+"geSync"](this[l(1729)]),m=JSON[l(859)](e[l(1008)](x,"{}"));return m[s||n[this[l(486)]]]=n,this[l(719)]["setStora"+l(1171)](this[l(1729)],JSON[l(1627)+"y"](m)),s||n[this[l(486)]]}async del(n){let s=t,l=this._qosDB[s(1283)+s(1171)](this._prefix),x=JSON[s(859)](e[s(853)](l,"{}"));return x[n]=void 0,this[s(719)]["setStora"+s(1171)](this[s(1729)],JSON[s(1627)+"y"](x))}async clear(){let n=t;if(e[n(1715)]===e.cofmA)e[n(551)](_0x1367d5,_0x5336d3,58),e[n(1126)](_0x4e35aa,_0x258638,_0x593aeb);else return this[n(719)][n(1120)+n(642)]()}async[t(926)](){let n=t,s=this[n(719)][n(1283)+n(955)+"nc"](this[n(1729)]),l=JSON[n(859)](e[n(1806)](s,"{}"));return Object[n(926)](l)}async[t(914)](){let n=t,s=this._qosDB[n(1283)+n(955)+"nc"](this._prefix),l=JSON.parse(e[n(1193)](s,"{}"));return Object.values(l)}[t(590)](){let n=t;if(e[n(1472)](e.pQHUu,e[n(1020)])){let s=0,l=0;for(let x=0;e[n(1611)](x,_0x13b6c9[n(1027)]);++x)l=_0x10dd01[n(1736)+"At"](x),e[n(981)](l,128)?s+=1:e[n(1904)](l,2048)?s+=2:e[n(923)](e[n(1593)](64512,l),55296)&&e.eMHqI(64512,_0x36fe0e[n(1736)+"At"](e[n(706)](x,1)))===56320?(++x,s+=4):s+=3;return s}else return Promise[n(1774)]()}get[t(541)](){return!!this._qosDB}}function fl(a,n){let s=t;if(e[s(476)](Rn,Rn))return new Gp(a,n);if(e.oLRqW(tr,Jr)&&e[s(448)](e.yotwY,typeof indexedDB))return new zp(a,n);if(e.GivuA(tr,Jr)&&s(376)+"d"!=typeof localStorage)return new Up(a,n);throw new Error(e[s(1397)])}class Hp{constructor(){let n=t;if(e[n(1650)](n(1744),e[n(1778)])){let s=new _0x510e93(e.uuJOU(_0x19d063,_0x584d67));return e[n(1568)](_0x1b6cfa,_0x50352b,s,0),s}else this[n(1520)+"lTimeoutId"]=null,this._interval=36e5,this._qosDB=e[n(852)](fl,n(900),n(821)+"id")}async _intervalFlush(){let n=t;e.SCxsr(clearInterval,this[n(1520)+n(831)+"Id"]),this[n(1520)+"lTimeoutId"]=e.mLqsK(setInterval,()=>{let s=n;this[s(1390)+s(1819)]()},this[n(1520)+"l"])}async[t(1386)](){let n=t;if(e[n(1749)](e.XdGFS,e[n(1558)])){if(e[n(729)](_0xd2b935,_0x453b00))throw new _0x460ab7(e[n(1046)]);let s=3;for(;e[n(1319)](s,0);){let l=e[n(426)](255,_0x498800);_0x561c87(l,_0x14c835,e.ORpkb(_0x4c2b36,s)),_0x258120>>>=8,s--}return e[n(1097)](_0x133110,4)}else await this[n(719)].openDB()[n(1877)](()=>{let s=n;this[s(1520)+s(734)]()})}async["flushExp"+t(1819)](){let n=t;(await this[n(719)]?.[n(914)]()||[])[n(1253)](({timestamp:x})=>x<Date[n(977)]()).forEach(x=>{let m=n;this[m(719)]?.[m(848)](x.message_id)})}async[t(848)](n){let s=t;return this[s(719)]?.[s(848)](n)}async[t(1240)](n,s){let l=t,x={KmzQl:function(m,b,E,p){return e[V(767)](m,b,E,p)}};if(e[l(490)](e[l(1790)],e[l(1790)]))throw _0x2065b6=_0x12e26d[l(1027)],x[l(1632)](_0x31289d,_0x4b96fe,10,_0x3c40af[l(1027)]);return this._qosDB?.[l(1240)]({message_id:n,timestamp:s})}async[t(1346)](n){let s=t,l={MGtfM:function(x,m){return e[V(563)](x,m)},loVKn:function(x,m){return e[V(994)](x,m)}};if(e[s(495)](e[s(1065)],e[s(686)])){let x=0,m={};for(let b=0;b<_0x558834[s(1027)];b++)m[_0x14aee1[b][s(1888)+s(1374)]]=l[s(370)](_0x318ac1,_0x26c205[b][s(1888)+"ame"]),x+=l[s(750)](14,m[_0x4ab0d1[b][s(1888)+s(1374)]]);return[x,m]}else return this[s(719)]?.[s(1346)](n)}async[t(590)](){let n=t;clearInterval(this["_interva"+n(831)+"Id"]),await this._qosDB?.[n(590)]()}get isReady(){let n=t;return this[n(719)]?.[n(541)]}}function pa(a){let n=t,s=!!this[n(1637)][n(1544)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=nn(a[n(876)][n(1061)],e[n(929)],"2"),x=l&&nn(a[n(876)][n(1061)],e[n(1025)],"1"),m=l&&e[n(1667)](nn,a[n(876)][n(1061)],e.TcNiO,"1"),b=m?e[n(1867)](nr,a[n(876)][n(1061)],e[n(1422)])?.split(",").filter(Boolean)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:x,isAckCleanupMessage:m,ackMsgIds:b}}async function xl(){let a=t;return this["_QoSMana"+a(626)]||(this["_QoSMana"+a(626)]=new Hp),this[a(1387)+a(626)][a(541)]||await this[a(1387)+a(626)][a(1386)](),this[a(1387)+a(626)]}async function qp(a,n){let s=t;if(e[s(1472)](e[s(611)],s(837))){let{pingInterval:l,pingFrequency:x}=this[s(1637)];if((e[s(433)]("hi",_0x2b8ea4[s(1320)])&&e[s(1527)]===x||e[s(717)](e[s(466)],x))&&(this[s(1038)+"ngTimer"](),this[s(1648)](s(371)+s(870)+"s",e.uNgKX),this["_pingPon"+s(1238)+"Id"]=e[s(819)](_0x2ced02,this[s(624)][s(605)](this),l)),e[s(1490)]("hi",_0x1c96a2.data))return;try{e.wuDCC(_0x2fceee,this,_0x3db852,[_0x5dd134,_0x60c882,_0x52fcb7,_0x42ffc3,_0x119bb0,_0x24d773])}catch(m){let b=e[s(477)](_0x578ccb,s(1622),{message:m.message,code:_0x488453[s(496)+"ERROR"],error:m});this["_dispatc"+s(1840)+s(1838)](b)}}else{let{enableAutoAck:l}=this[s(1637)],x=e[s(1797)](nn,a[s(876)].headers,e[s(1294)],"1"),m=nn(a[s(876)][s(1061)],"is_ack","1"),b=pa[s(1258)](this,a);if(e[s(1158)](l,x)){let{SeqID:E,LogID:p,service:k,LogIDNew:P,method:N}=a[s(876)];this._sendAck({SeqID:E,LogID:p,LogIDNew:P,service:k,method:N,headers:[{key:e[s(1865)],value:"1"},{key:e[s(1388)],value:P||""},{key:e[s(1325)],value:"0"}]})}m&&!b[s(849)]&&this[s(700)+s(1264)+s(1524)](a),e.zbQlb(n)}}async function jp(a,n){let s=t;this[s(1345)](e[s(1933)],a.message),e[s(1250)](n)}async function Wp(a,n){let s=t;if(e[s(1472)](e[s(1368)],e[s(960)])){let l=e[s(920)](Qt,await ul(a.data));try{if(e[s(1821)](l.payload,Uint8Array))if(e[s(539)](e.JtMSR,e[s(882)])){let x=this[s(1637)][s(1033)+s(435)]instanceof Object?{force:!!this._options["payloadE"+s(435)].force,encoding:this._options[s(1033)+s(435)][s(651)]?this[s(1637)][s(1033)+s(435)][s(651)][s(1078)](/\s/g,"")[s(751)+"ase"]():""}:{force:!1,encoding:this._options["payloadE"+s(435)]?this[s(1637)][s(1033)+s(435)][s(1078)](/\s/g,"")["toLowerC"+s(1512)]():""},m=l[s(1033)+s(435)]?l["payloadE"+s(435)][s(1078)](/\s/g,"")[s(751)+s(1512)]():"",b=e[s(1821)](this[s(1637)][s(654)+s(1072)],Object)?{force:!!this[s(1637)].payloadType[s(682)],type:this[s(1637)][s(654)+s(1072)][s(1180)]?this._options[s(654)+s(1072)][s(1180)][s(1078)](/\s/g,"")["toLowerC"+s(1512)]():""}:{force:!1,type:this[s(1637)][s(654)+s(1072)]?this[s(1637)][s(654)+s(1072)][s(1078)](/\s/g,"")[s(751)+s(1512)]():""},E=l["payloadT"+s(1072)]?l[s(654)+s(1072)][s(1078)](/\s/g,"")[s(751)+s(1512)]():"",p=b.force?b[s(1180)]:E||b.type,k=x[s(682)]?x[s(651)]:m||x[s(651)],P=[e.xUghm,e[s(1895)],e[s(1370)],"string"],N=[e[s(1792)],e[s(1303)]];this[s(1637)][s(1114)+s(585)+"extPayload"]&&P[s(1173)](p)&&(!k||N[s(1173)](k))?l[s(513)+s(804)]=e[s(1797)](ll,l[s(1322)],0,l[s(1322)][s(1741)+"th"]):l[s(513)+"oad"]=""}else{let x=this._qosDB[s(1283)+s(955)+"nc"](this._prefix),m=_0x54a279[s(859)](x||"{}");return _0x24c508[s(926)](m)}else l[s(513)+s(804)]=""}catch(x){if(e[s(874)](e[s(580)],e[s(580)]))return this[s(1136)]?this[s(1136)][s(564)]:this[s(1678)];l[s(513)+s(804)]="",console[s(1024)](x)}a[s(876)]=l,n()}else++_0x3c677d,_0x627334+=4}function Kp(a,n,s){let l=t,x={pJauI:function(m,b){return m<b},KSELJ:function(m,b){return e[V(1824)](m,b)},eTVGo:function(m,b){return m(b)},iFEuJ:function(m,b){return m+b},CpLKu:function(m,b){return e.CqDag(m,b)},DlWxt:function(m,b){return e[V(1318)](m,b)}};if(e[l(1130)](e[l(1302)],e[l(1929)])){let m=e[l(1920)](s,8192),b=e[l(417)](m,1),E=null,p=m;return function(k){let P=l;if(x.pJauI(k,1)||x[P(639)](k,b))return x[P(789)](a,k);x[P(639)](x.iFEuJ(p,k),m)&&(E=a(m),p=0);let N=n[P(1258)](E,p,p+=k);return x[P(1009)](7,p)&&(p=x.iFEuJ(x[P(1149)](7,p),1)),N}}else this[l(1787)](_0x259cc2,_0x136426)}let $p=4294967295;function Vp(a,n,s){let l=t;return e[l(1779)](RangeError,e[l(1608)](e[l(1823)](e[l(1515)](e.uYtBo(l(1285)+l(572)+l(1439),a)+e.ShRKE,e[l(1703)](n,1)),e[l(461)]),s))}function Yp(a,n,s){let l=t;if(e[l(601)](e.Xlvjx,l(1530))){if(e[l(1835)](s,$p))throw new Error(e.CcNHO);let x=3;for(;e[l(1885)](x,0);){let m=e[l(1084)](255,s);e.vsrSn(ma,m,a,n+x),s>>>=8,x--}return e[l(1872)](n,4)}else{this._clearPingTimer(),this[l(998)+l(1238)+"Id"]=e[l(819)](_0x2a0d00,this._ping[l(605)](this),this[l(1637)][l(1348)+l(381)]);return}}function Zp(a,n){let s=t,l=0,x=n,m=e[s(1206)](n,4);for(;e[s(1523)](x,m);){let{value:b,offset:E}=e[s(1629)](ga,a,x);x=E,l=e[s(1221)](e[s(1125)](l,8),0),l+=b}return{value:l,offset:m}}function Jp(a,n,s){let l=t;return a?e[l(1904)](a[l(1027)],40)?e[l(1875)](e.PyNYt(xa,a,n,s),s):n[l(1363)+"e"]?e.dumeN(n[l(1363)+"e"](a,s),s):n.write?e[l(1757)](n.write(a,s),s):e[l(1071)](e[l(463)](xa,a,n,s),s):s}function Xp(a,n){let s=t,l=new ue(e[s(805)](e.LnvZF(e[s(1547)](a[e[s(893)](n,4)],24),e[s(1912)](a[e[s(604)](n,5)],16)),e.SlxUP(a[e[s(994)](n,6)],8))|a[e[s(1576)](n,7)],e[s(385)](e[s(1177)](e[s(612)](e[s(1037)](a[e[s(1608)](n,0)],24),e[s(916)](a[e.ycivc(n,1)],16)),a[e[s(796)](n,2)]<<8),a[e[s(1576)](n,3)]),!0);return n+=8,{value:l,offset:n+8}}function Qp(a,n,s){let l=t;if(e[l(1490)](e[l(1698)],e[l(1698)])){let x=a[l(1828)],m=a.high;return n[s]=e.MYAzx(m,24),n[e.PGqgb(s,1)]=e[l(1400)](e[l(1058)](m,16),255),n[e[l(1342)](s,2)]=e[l(1710)](e[l(1040)](m,8),255),n[e[l(1508)](s,3)]=e[l(1489)](255,m),n[e.WKiUO(s,4)]=e[l(703)](x,24),n[e.kbzOE(s,5)]=e.yLgMt(e[l(818)](x,16),255),n[e[l(706)](s,6)]=e[l(1535)](x>>>8,255),n[s+7]=255&x,s+=8,s}else{for(_0x2edc0a>>>=0;_0x3f3885>=128;)e[l(1538)](_0x235a59,_0x2f59f0,e[l(1115)](e[l(544)](127,_0x32d4e0),128)),_0x2ae36b>>>=7;e[l(940)](_0xde478c,_0x317055,_0x728fb2)}}function ga(a,n){let s=t;return a[s(1442)+"8"]?{value:a.readUInt8(n),offset:e[s(1071)](n,1)}:{value:e.bqToW(255,a[n]),offset:e[s(1696)](n,1)}}function ma(a,n,s){let l=t;return n[l(1817)+"t8"]?n[l(1817)+"t8"](a,s):n[s]=e[l(1671)](255,a),e[l(1018)](s,1)}let eg=function(a){return new Uint8Array(a)},tg=e[t(1722)]!=typeof Buffer?Buffer["allocUns"+t(1788)]:e.gNKGM(Kp,eg,Uint8Array.prototype.subarray),ng=16,wa=32;function rg(a){let n=t,s={iuENp:function(l,x){return e[V(1207)](l,x)}};if(e.lbRCu("tEwBl",n(936))){let l=0,x={};for(let m=0;e.lDUtV(m,a.length);m++)x[a[m]["cursor_n"+n(1374)]]=e.QlPdF(dl,a[m][n(1888)+n(1374)]),l+=14+x[a[m][n(1888)+n(1374)]];return[l,x]}else{let l=_0x5a654d[n(591)+"g"](0,xPVQxx[n(1213)](4,_0x35dcff[_0x49c08e].length)),x=l[n(516)](_0x3b5b67);_0x4548d9=_0x434c95[n(516)](x)}}function hl(a,n,s){let l=t,[x,m]=e[l(1779)](rg,a),b=tg(x),E=0;return a[l(1869)](p=>{let k=l,P=e[k(1901)][k(573)]("|"),N=0;for(;;){switch(P[N++]){case"0":E=e[k(688)](ma,0,b,E);continue;case"1":console[k(1024)](e.wuYPL,E);continue;case"2":console[k(1024)](e[k(1445)],E);continue;case"3":E=e[k(1432)](Jp,p[k(1888)+k(1374)],b,E);continue;case"4":E=e.BUchC(ma,m[p[k(1888)+"ame"]],b,E);continue;case"5":console.log(e[k(952)],E);continue;case"6":console.log(e[k(1519)],E);continue;case"7":console[k(1024)](e.ncLxD,p,p[k(659)]);continue;case"8":console[k(1024)](e[k(962)],E);continue;case"9":E=e[k(996)](Qp,ue[k(1800)+"er"](p[k(1002)]||n),b,E);continue;case"10":E=e.wfwvZ(Yp,b,E,p.service||0);continue}break}}),{frameType:wa,headers:[{key:e[l(984)],value:s}],payload:b}}function ig(a){let n=t,s=0,l=[];for(;s<a[n(1741)+"th"];){let{offset:x}=e[n(501)](ga,a,s);s=x;let m={cursor_name:"",cursor:0,service:0},{value:b,offset:E}=Zp(a,s);m[n(659)]=b,s=E;let{value:p,offset:k}=e.hUgXl(ga,a,s);s=k,m[n(1888)+n(1374)]=ll(a,s,s+p),s+=p;let{value:P,offset:N}=Xp(a,s);m[n(1002)]=P.toNumber(),s=N,l[n(1408)](m)}return l}function sg(){return{frameType:wa,headers:[{key:e.SLlbm,value:e.bAPVC}],payload:void 0}}class og{constructor(n,s,l){let x=t;this[x(865)+x(1211)]=n,this[x(1707)+"ileName"]=s,this[x(1255)+"Strategy"]=l,this[x(719)]=e.GQQFs(fl,this[x(865)+x(1211)],"cursor_name")}async openDB(){let n=t;await this[n(719)][n(1386)]()}async[t(970)+"rs"](){let n=t;if(!this[n(719)][n(541)])return;let s=this[n(1255)+"Strategy"],l=await this[n(719)].getAll();switch(console.log(n(1004)+n(1267),l),s){case e[n(383)]:return l&&l[n(1027)]?hl(l,0,this["_cursorF"+n(913)]):void 0;case e.SZozz:return;case"CONTINUE":return l&&l[n(1027)]?e.wuDCC(hl,l,0,this[n(1707)+"ileName"]):e.tzify(sg)}}async set(n,s,l){let x=t;return console[x(1024)](e[x(1460)],n,s,l),this[x(719)][x(1240)]({cursor_name:n,cursor:s,service:l})}async setCursors(n){let s=t;if(e.fyqtP("lsadN",e[s(1042)]))return _0x4cddce[s(402)][e[s(616)](_0x4e5087,_0x11c070,1)];{let l=e[s(1708)](ig,n);for(let x of l)console.log(e[s(976)],l),await this[s(719)].set(x)}}async[t(1346)](n){let s=t;return(await this._qosDB[s(1346)](n))?.cursor}async[t(590)](){await this[t(719)].closeDB()}[t(1847)+"rsorFile"+t(973)](n){let s=t;this[s(1707)+s(913)]=n}get[t(541)](){let n=t;return this[n(719)][n(541)]}}let ag=e[t(1651)];async function pl(a){let n=t;if(!this[n(1637)][n(1544)+"S"])return null;let{aID:s,fpID:l,messageStrategy:x}=this[n(1637)],m=e[n(1193)](a,ag);try{return this["_cursorM"+n(908)]?a&&this["_cursorM"+n(908)]["updateCu"+n(1864)+n(973)](a):this[n(1511)+"anager"]=new og(l+"_"+s+"_"+m,m,x),this[n(1511)+"anager"][n(541)]||await this[n(1511)+n(908)][n(1386)](),this["_cursorM"+n(908)]}catch{return null}}async function cg(a,n){let s=t,l=e[s(1797)](nn,a[s(876)][s(1061)],s(1019),"-1"),x=nn(a[s(876)][s(1061)],e[s(1865)],"1"),m=nr(a.message.headers,e[s(743)]),b=Number(nr(a[s(876)][s(1061)],e[s(379)]))||0,E=pa[s(1258)](this,a),p=e[s(1599)](nn,a[s(876)].headers,s(1498)+"s","2"),k=e[s(574)](nr,a[s(876)][s(1061)],e.rHOTW),P=e[s(1874)](Number,e.FEBCR(nr,a[s(876)][s(1061)],e[s(1051)]));if(E.isQoSAck)return e[s(430)](n);let N=E[s(775)+s(1417)]?await xl[s(1258)](this):null;if(e[s(1835)](a.message[s(659)],0)&&x&&!l||a[s(876)][s(659)]>0){if(m&&E[s(775)+s(1417)]&&N)return!!!await N[s(1346)](m)&&(this[s(700)+"hMessage"+s(1762)](a),await N[s(1240)](m,e[s(1153)](Date[s(977)](),b))),e.jfGLm(n);if(p){let z=await pl[s(1258)](this);if(!z)return this[s(700)+s(1057)+s(1762)](a),e[s(1104)](n);let H=await z[s(1346)](k)??-1;if(e[s(762)](H,P))this["_dispatc"+s(1057)+s(1762)](a),z.set(k,P,a[s(876)].service);else throw new Error(s(1620)+s(1458)+" cursor "+P+(s(443)+"than local cursor ")+H);return e[s(609)](n)}return this[s(700)+s(1057)+s(1762)](a),n()}}async function dg(a,n){let s=t,l=pa[s(1258)](this,a);if(!l[s(775)+s(1417)])return e[s(966)](n);let x=await xl[s(1258)](this);if(l[s(1691)+s(1598)+s(1900)]&&l.ackMsgIds[s(1027)])for(let m of l[s(1450)+"s"])await x[s(848)](m);e[s(1085)](n)}async function lg(a,n){let s=t,l=a[s(876)].frameType===ng,x=e[s(1034)](a.message[s(1853)+"e"],wa);if(!l&&!x)return e[s(1104)](n);let m=e.wSrJu(nr,a[s(876)][s(1061)],e[s(984)]);if(!m)return n();let b=await pl[s(1258)](this,m);if(!b)return e[s(1894)](n);if(l){let E=await b[s(970)+"rs"](),p={frameType:E?.[s(1853)+"e"],SeqID:ue[s(1800)+"er"](this[s(765)]++),LogID:ue[s(1800)+"er"](this[s(1637)][s(1099)+s(925)]()),service:9e3,method:5,headers:E?.[s(1061)],payload:E?.[s(1322)]},k=e[s(1202)](S,p);this[s(1136)]&&this[s(1136)][s(452)+"te"]&&this._ws[s(1926)](k)}if(x){let E=a.message.payload;E&&b.setCursors(E)}}let ug=async function(a,n){let s=t;this[s(1438)]=!1,e[s(563)](clearTimeout,this[s(1092)+s(1268)+"utId"]),e[s(628)](n)},fg=async function(a,n){let s=t;if(!this[s(1136)]||this[s(1136)][s(452)+"te"]!==this.OPEN)return e[s(1550)](n);let{pingInterval:l}=this[s(1637)];this[s(1398)+s(1910)]?.[s(409)+s(733)+s(1270)]();for(let m=0;e.TKOwp(m,this[s(1255)+s(742)].length);m++){let b=this[s(1255)+s(742)][m];if(this[s(1136)][s(452)+"te"]===this.OPEN&&e[s(490)](null,b))if(e[s(665)](e[s(1219)],e[s(1243)])){let E=("11|9|0|7"+s(1300)+s(815)+"4").split("|"),p=0;for(;;){switch(E[p++]){case"0":_0x3f752f=(_0x43e3f9|(127&_0x52aa86[_0x3c3f74])<<7)>>>0;continue;case"1":_0x558f21=e[s(1232)](_0x2ea13f,e.SVbBL(e[s(1593)](127,_0x2717f3[_0x4c13a0]),14))>>>0;continue;case"2":if(e.JTOzV(_0x10b9e3[_0x440039++],128))return{value:_0x10e659?_0x6767ea:e.KRnCh(0,_0x4b101a),offset:_0x5349ef};continue;case"3":_0x3c25a8=e[s(635)](e[s(1738)](_0xa85ac9,e[s(1485)](e[s(1882)](15,_0x6eeffe[_0x3db628]),28)),0);continue;case"4":return{value:_0x13eb67?_0x58f764:e[s(393)](0,_0x5b7370),offset:_0x1de35f};case"5":if(e[s(613)](_0xc1a9ae[_0x167b12++],128))return{value:_0x58fdee?_0x2026b0:e[s(612)](0,_0x448c46),offset:_0xb02e9f};continue;case"6":if(_0x5bf69e[_0x305ff6++]<128)return{value:_0x1d278a?_0x466bc0:0|_0x29e989,offset:_0x312278};continue;case"7":if(e[s(1074)](_0x4d5c63[_0x5c277c++],128))return{value:_0x1d4751?_0x156a65:e[s(1100)](0,_0x25a73d),offset:_0xea4e4d};continue;case"8":_0x4ea29a=e[s(1168)](e[s(1716)](_0x17136f,e[s(1169)](127&_0x126022[_0x3bf6e6],21)),0);continue;case"9":if(e[s(1802)](_0x3c312f[_0xdec6c1++],128))return{value:_0x468e45?_0x36754f:0|_0xfdcb9,offset:_0x2d898f};continue;case"10":if(e[s(1824)](_0xf1eb3f+=5,_0x55c387.length))throw _0x1f740a=_0x4c3c7d[s(1027)],_0x5abcd7(_0x55b79f,10,_0x2ed87a[s(1027)]);continue;case"11":_0x11b92a=e[s(545)](127&_0xdbb1fc[_0x4814d3],0);continue}break}}else this[s(1136)]&&this._ws[s(1926)](b),this[s(1255)+s(742)][m]=null;else break}this["_message"+s(742)]=this["_message"+s(742)][s(1253)](m=>!!m),this[s(998)+s(1238)+"Id"]=e[s(1339)](setTimeout,()=>this[s(624)](),l),this[s(700)+s(1e3)+"nt"](a),this[s(830)+"er"]&&this[s(1136)]&&(this[s(1136)][s(1351)+"pe"]=this[s(561)+s(1072)]);let x=this[s(1398)+"tManager"]?.[s(1353)+s(375)+"nt"]();this[s(1345)](s(1462)+x+s(827)),e[s(628)](n)},xg=async function(a,n){let s=t,l=this[s(1398)+s(1910)]?.[s(1353)+s(375)+"nt"]();this[s(1345)](s(1462)+l),e[s(1448)](n)};class hg extends fa{constructor(n){let s=t,l={IRizu:function(E,p){return e[V(425)](E,p)},CqZMz:s(1312),wwbUP:e.PeNBb,teTUt:function(E,p){return e[s(717)](E,p)},Gvexd:function(E,p){return e[s(677)](E,p)},NreHb:function(E,p){return e.RnnZb(E,p)},KIAIt:s(901),rBxJZ:function(E,p){return E!==p},LuAwf:e[s(1107)],ZGiIx:e.TlULZ,YFSTI:"success",bFKgG:function(E,p){return e[s(923)](E,p)},UyzLD:function(E,p,k,P){return e[s(683)](E,p,k,P)},uxWUc:function(E,p){return e[s(1579)](E,p)},bHPOF:e[s(1382)],pHLTB:function(E,p,k){return E(p,k)},VOSlU:function(E,p,k){return E(p,k)},jHpxi:function(E,p){return e[s(1781)](E,p)},VYzGu:function(E,p,k){return e[s(1429)](E,p,k)},tzVgX:e[s(1561)],mwIdz:function(E,p,k){return e[s(1607)](E,p,k)},ANkhG:e[s(1101)],QGUmd:function(E,p){return E!==p},SkapQ:e[s(695)],AePBI:function(E,p,k){return e.tbdVa(E,p,k)}};super(),this[s(1709)+"igatorOn"+s(657)]=!0,this[s(830)+"er"]=tr,this[s(1587)]=Cp,this[s(739)+"T"]=Rn,this[s(423)+"X"]=Zr,this[s(1818)+"r"]=Jr,this[s(1255)+s(742)]=[],this["_endpoin"+s(1910)]=null,this._readyClosed=!1,this[s(561)+s(1072)]=e[s(1566)],this[s(1092)+"Lock"]=!1,this["_connectionTimeo"+s(1630)]=null,this[s(1181)+"ctTimeou"+s(701)]=null,this["_pingPon"+s(1238)+"Id"]=null,this[s(765)]=0,this[s(1438)]=!1,this[s(1678)]="",this[s(1387)+s(626)]=null,this[s(1511)+s(908)]=null,this[s(1737)+s(1323)]=null,this[s(1463)+"ls"]=e[s(1452)],this.CLOSED=3,this.CONNECTING=0,this[s(394)]=1,this[s(1304)]=2,this._onOpen=E=>{let p=s,k={kIeAo:function(P,N){return e.STqEp(P,N)},yZRvV:function(P,N){return e[V(647)](P,N)},nupUV:p(1773),YQAzl:e[p(832)],zuIvb:function(P,N){return e.fLiin(P,N)},ZqxQR:e[p(889)],Aggaw:function(P,N){return e[p(537)](P,N)}};if(e[p(761)](e[p(953)],e[p(953)]))try{e[p(1599)](cl,this,E,[ug,fg,xg])}catch(P){let N=e[p(937)](ct,"error",{message:P.message,code:tn[p(1063)+"OR"],error:P});this["_dispatc"+p(1840)+p(1838)](N)}else{if(fHxdbp[p(1860)](_0x2fc6f4,_0x85bdc0)){if(fHxdbp[p(843)](_0x3ded4a,fHxdbp.nupUV))return _0xfca2b7[p(1346)](_0x4b910d);if(fHxdbp[p(843)](_0x358370,fHxdbp[p(1441)]))return _0x2d3154.objectStoreNames||_0x57abf5[p(1346)](_0x2c9a49);if(fHxdbp[p(1848)](_0x4f2e2f,fHxdbp[p(1395)]))return _0x2d1f02[p(1642)+p(1893)][1]?void 0:_0x34b634[p(1642)+p(834)](_0x386e1d[p(1642)+p(1893)][0])}return fHxdbp.Aggaw(_0x5c43ff,_0x1cfec8[_0x4671e1])}},this._onMessage=async E=>{let p=s;if(l[p(1805)]===l[p(935)])try{this._qosDB?.close(),this[p(719)]=void 0}catch(k){_0x7585bd.log(k)}else{let{pingInterval:k,pingFrequency:P}=this[p(1637)];if((l[p(1643)]("hi",E[p(1320)])&&l.Gvexd(p(582),P)||l.NreHb(l[p(1631)],P))&&(l[p(640)](l[p(1378)],p(1553))?_0x1b3812=PtbIlg[p(1354)](_0x507a2c,_0x29beaf):(this[p(1038)+p(862)](),this[p(1648)](l[p(1851)],l[p(403)]),this[p(998)+p(1238)+"Id"]=setTimeout(this[p(624)][p(605)](this),k))),l[p(1471)]("hi",E.data))return;try{l[p(1056)](cl,this,E,[Wp,qp,dg,lg,cg,jp])}catch(N){if(l[p(608)](l[p(478)],l[p(478)])){let z=l[p(1098)](ct,p(1622),{message:N[p(876)],code:tn["MESSAGE_"+p(1617)],error:N});this[p(700)+p(1840)+p(1838)](z)}else return this[p(1398)+p(1910)]?.[p(1353)+p(375)+p(810)+p(421)]()||0}}},this[s(1124)]=E=>{let p=s,k=this[p(1398)+p(1910)]?.[p(1022)+p(1925)+"es"](),P=this["_endpoin"+p(1910)]?.[p(1353)+p(375)+"nt"]();if(k&&!E.message){let N=p(1727)+P+(" fail, m"+p(447)+p(374)+"ed");this[p(700)+p(1840)+"ent"](l[p(1688)](ct,p(1622),{message:N,code:tn[p(441)+"IES_ERROR"],error:E}));return}this[p(1136)]&&l.jHpxi(this._ws[p(452)+"te"],this[p(394)])&&this[p(1299)+p(1609)](),this[p(700)+p(1840)+p(1838)](ct("error",{message:E[p(876)],code:tn[p(1402)+p(1457)],error:E}))},this[s(1113)]=async E=>{let p=s;this._clearTimer(),this["_clearPi"+p(862)](),this[p(492)+p(1385)+"rs"](),this[p(1136)]=null,this[p(1092)+p(464)]=!1;let k=this[p(1398)+"tManager"]?.["checkRea"+p(1925)+"es"]();if(!k&&this[p(1583)+p(1231)]()&&!this["_readyCl"+p(1201)]){let P=this[p(1398)+p(1910)]?.[p(1353)+p(375)+"nt"](),N=this[p(1637)][p(509)+p(1379)+p(534)](E[p(1019)],E[p(1825)]);this[p(700)+"hCloseEv"+p(1838)](l[p(1705)](pt,l[p(614)],{code:1006,reason:E[p(1825)]||p(904)+p(1540)+p(408)+"wn reaso"+p(455)+p(467)+P,willReconnect:N})),N&&this[p(1092)]();return}if(l[p(640)](1e3,E[p(1019)])&&this[p(446)+p(1201)]){this[p(700)+p(526)+p(1838)](l[p(1427)](pt,l[p(614)],{code:1e3,reason:l[p(1603)]})),this[p(1398)+p(1910)]?.[p(409)+p(733)+"fig"](),this[p(1737)+p(1323)]?.[p(1140)+p(524)]();return}if(l[p(954)](1e3,E[p(1019)])&&k){let P=this[p(1398)+"tManager"]?.[p(1353)+p(375)+"nt"](),N=E[p(1825)];N||(N=await Bp(this[p(1678)])),N="connecti"+p(1540)+p(797)+N+(p(769)+p(1551))+P+(p(1028)+p(1134)+"ached"),this[p(700)+"hCloseEv"+p(1838)](l[p(1705)](pt,l[p(614)],{code:E.code,reason:N}));let z=p(1727)+P+(p(1316)+p(447)+"es reached");this[p(700)+p(1840)+p(1838)](l[p(1098)](ct,"error",{message:z,code:tn[p(441)+p(1782)+"R"]})),this[p(1398)+p(1910)]?.[p(409)+"pointCon"+p(1270)](),this[p(1737)+p(1323)]?.[p(1140)+"nter"]();return}if(E[p(1019)]!==1e3&&!E.reason)if(l[p(1546)](l.SkapQ,l[p(517)])){let P=this._endpointManager?.[p(1353)+p(375)+"nt"]();this["_dispatc"+p(526)+p(1838)](l[p(1234)](pt,p(1594),{code:E[p(1019)],reason:"connecti"+p(1540)+p(408)+p(1543)+p(455)+p(467)+P})),this["_endpoin"+p(1910)]?.[p(409)+p(733)+p(1270)](),this[p(1737)+p(1323)]?.[p(1140)+p(524)]();return}else this[p(561)+p(1072)]=_0x25746b,this._ws&&(this[p(1136)][p(1351)+"pe"]=_0x39470f);this[p(700)+p(526)+p(1838)](E),this[p(1398)+p(1910)]?.[p(409)+p(733)+p(1270)](),this["_pingLos"+p(1323)]?.["resetCou"+p(524)]()},this.onclose=null,this[s(1559)]=null,this[s(715)+"e"]=null,this.onopen=null,this[s(1175)+s(1290)]=null,this[s(497)+s(1932)]=null,this[s(1645)+s(1341)+"yReconnect"]=null,this[s(427)+s(879)]=this[s(427)+s(879)][s(605)](this),this[s(427)+s(1662)]=this["_handleO"+s(1662)][s(605)](this),this[s(864)+"ageHide"]=this["_handleP"+s(1436)][s(605)](this),this[s(864)+s(858)]=this[s(864)+s(858)][s(605)](this),this[s(1637)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(531)](1,0),service:0,logIDGenerator:o,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:e.GnZUM,pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e.tIyjp,env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:x,ws:m}=n,b=Array[s(749)](x)?x:e[s(607)](e[s(1036)],typeof x)?[x]:[];if(!b||e.wYasA(0,b[s(1027)]))throw new Error(s(1915)+"rovide v"+s(1591));if(!Op(m))throw new Error(e[s(946)]);Object.assign(this[s(1637)],n),this[s(1398)+"tManager"]=new al(b,this[s(1637)][s(1829)+"es"]),this["_pingLos"+s(1323)]=new Mp(this[s(1637)][s(1628)+"Count"]),this._options[s(1580)+s(444)]&&(this[s(1438)]=!0,this[s(1092)]()),this[s(1637)]["listenNe"+s(386)+s(895)]&&(this._isMiniTT||this[s(423)+"X"]?this["_onPageN"+s(1582)+s(618)]():this[s(830)+"er"]&&this["_initGlo"+s(1646)+s(658)]())}[t(427)+t(879)](){let n=t;this[n(1637)][n(527)+n(1333)+"nect"]||this["_readyCl"+n(1201)]||this[n(619)+n(1290)]()}[t(427)+"ffLine"](){let n=t;this[n(1133)+n(758)+"t"]();let s=ua(n(509)+"t",{message:e[n(909)]});this[n(1645)+"mediatel"+n(449)+"ct"]&&this[n(1645)+n(1341)+"yReconnect"](s)}[t(1816)+t(1646)+"Listener"](){let n=t;this._isBrowser&&window["addEvent"+n(658)](n(1426),this[n(427)+"nLine"]),this[n(830)+"er"]&&window[n(1091)+"Listener"](n(1233),this._handleOffLine),this[n(830)+"er"]&&window["addEvent"+n(658)](e[n(782)],this[n(864)+"ageHide"]),this[n(830)+"er"]&&window[n(1091)+n(658)](e[n(474)],this[n(864)+"ageShow"])}[t(1876)+t(1646)+t(658)](){let n=t;this[n(830)+"er"]&&window[n(1328)+n(1455)+n(1616)](e[n(1188)],this[n(427)+n(879)]),this[n(830)+"er"]&&window[n(1328)+"entListe"+n(1616)](e.WSXMw,this[n(427)+n(1662)]),this[n(830)+"er"]&&window[n(1328)+"entListener"](e[n(782)],this[n(864)+n(1436)]),this[n(830)+"er"]&&window["removeEv"+n(1455)+n(1616)](n(896),this._handlePageShow)}[t(864)+t(1436)](n){let s=t,l={suUOp:e[s(903)]};!n[s(1334)+"d"]&&(e[s(462)](e[s(928)],e[s(689)])?(this[s(830)+"er"]&&window[s(1328)+s(1455)+s(1616)](e.ZdDQT,this[s(864)+s(1436)]),this[s(830)+"er"]&&window[s(1328)+"entListener"](e[s(474)],this[s(864)+s(858)]),this[s(1594)]()):(this[s(1136)]&&this[s(1136)][s(1926)](_0xddaa25),this[s(1345)](l[s(1760)],_0x12bc7c))),this[s(830)+"er"]&&window[s(1328)+s(1455)+s(1616)](s(1426),this._handleOnLine),this[s(830)+"er"]&&window[s(1328)+s(1455)+"ner"](s(1233),this[s(427)+s(1662)])}[t(864)+t(858)](n){let s=t,l={QjyAP:function(x,m){return e[V(1222)](x,m)},xhiqH:function(x,m,b){return e[V(1347)](x,m,b)}};e[s(677)](e[s(583)],e[s(469)])?(QJsTWN[s(1456)](_0x28b82f,this[s(1520)+s(831)+"Id"]),this[s(1520)+s(831)+"Id"]=QJsTWN.xhiqH(_0x1ec3c9,()=>{let x=s;this[x(1390)+x(1819)]()},this._interval)):n[s(1334)+"d"]&&(this._navigatorOnline()&&(!this[s(1136)]||e[s(888)](this._ws[s(452)+"te"],this[s(394)])||e[s(575)](this[s(1136)][s(452)+"te"],this[s(1145)+"NG"]))&&this[s(427)+s(879)](),this[s(830)+"er"]&&window[s(1091)+s(658)](e[s(1188)],this[s(427)+s(879)]),this[s(830)+"er"]&&window[s(1091)+"Listener"]("offline",this[s(427)+s(1662)]))}async[t(1575)+"eUrl"](n){let s=t,{fpID:l,deviceID:x,bddID:m,ttwID:b,accessKey:E,aID:p,customParams:k={},enableAutoAck:P,enableQoS:N,QoSLevel:z,env:H}=this[s(1637)],ge,Ae,Be;if(this._isBrowser||this._isMiniWX||this[s(739)+"T"])ge=location&&e[s(1189)](e[s(596)],location[s(666)])?s(1401):e[s(1753)],Ae=n[s(1078)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),Be=/^wss(.*:\/\/)/[s(752)](n)?n:""+ge+Ae;else{if(e[s(1204)]===e[s(1584)])return!0;ge=e[s(599)],Ae=n[s(1078)](/(^http)((?:[s]*:\/\/))/,""),Be=/(^ws)((?:[s]*:\/\/))/[s(752)](Ae)?Ae:""+ge+Ae}let os=m?e[s(1501)]:b?e[s(1588)]:s(1154)+"d",as=m||b||x;if(!as||!os)throw new Error(e[s(1176)]);let gl=e[s(1226)](e[s(1179)],typeof k)?await e[s(860)](k):k,pg=H?e[s(902)](Np,H[s(1827)],H[s(1653)]):{},_a=Object[s(1858)]({device_platform:e[s(1565)],version_code:"fws_1.0.0",access_key:E,fpid:l,aid:p,[os]:as,xsack:P?1:0,xaack:P?1:0,xsqos:N?1:0,qos_level:N?z:void 0,qos_sdk_version:2,...pg},gl),gg=Object[s(926)](_a).reduce((ya,Ea)=>_a[Ea]!==void 0?""+ya+(ya?"&":"?")+Ea+"="+_a[Ea]:ya,"");return Be+s(538)+gg}async[t(1092)](){let n=t;if(!(this[n(1092)+n(464)]||this[n(446)+n(1201)])){this[n(1092)+n(464)]=!0;try{let s=this[n(1398)+n(1910)]?.[n(1839)+"rentEndpointReachedMaxRetries"](),{timeoutInterval:l}=this._options;if(s){let m=this[n(1398)+n(1910)]?.[n(1353)+"ntEndpoint"](),b=this[n(1398)+"tManager"]?.["replaceBackupEnd"+n(1119)+n(615)+n(1881)](),E=this[n(1398)+"tManager"]?.[n(1353)+n(375)+n(810)+"ount"]();if(b){let p=n(1727)+m+(n(1514)+n(1028)+n(1134)+n(1702)+"ill use "+n(1549)+n(991))+b+(n(1288)+"y"),k=ct(e[n(855)],{message:p,code:tn["MAX_RETR"+n(1782)+"R"]});this[n(1345)](p),this[n(700)+"hErrorEv"+n(1838)](k),this[n(1678)]=await this[n(1575)+"eUrl"](b),this[n(1345)](n(1727)+b+" "+E+" times"),this["_removeW"+n(1385)+"rs"]()}else{let p=n(1727)+m+(n(1514)+n(1028)+n(1134)+"ached");this[n(1345)](p),this[n(700)+n(1840)+n(1838)](e[n(1178)](ct,e.BapYb,{message:p,code:tn[n(441)+n(1782)+"R"]}));return}}else{let m=this[n(1398)+n(1910)]?.[n(1353)+n(375)+n(1613)+n(720)](),b=this[n(1398)+n(1910)]?.[n(1353)+n(375)+n(810)+n(421)]();this[n(1678)]=await this[n(1575)+"eUrl"](m||""),this._debug(n(1727)+m+" "+b+n(791)),this[n(492)+n(1385)+"rs"]()}if(this[n(1438)])this._isInit=!1;else{let m=e[n(1347)](ua,e.SqZtb,{message:e[n(1776)]});this[n(1175)+n(1290)]&&this[n(1175)+n(1290)](m)}let x=this[n(1398)+n(1910)]?.[n(1353)+n(375)+n(810)+n(421)]()||0;e[n(438)](x,1)&&await this._wait(x-1),this[n(1345)](n(904)+n(1338)+this[n(1678)]+(n(1159)+n(1898))+this._protocols),this[n(1136)]=e[n(587)](Pp,{url:this[n(1678)],protocols:[this._protocols],headers:this[n(1637)]["miniProg"+n(779)+"s"][n(1668)+n(1636)]},this[n(1637)].ws),(this._isBrowser||this[n(1818)+"r"])&&this[n(1136)]&&(this._ws[n(1351)+"pe"]=this[n(561)+n(1072)]),this["_addWsLi"+n(1891)](),this[n(1092)+n(1268)+n(1630)]=e[n(1093)](setTimeout,this[n(1728)+"ut"][n(605)](this),l)}catch(s){if(e[n(1766)](e[n(1503)],e[n(595)]))return this._socket[n(564)];throw this[n(1092)+n(464)]=!1,s}}}[t(1059)+"mer"](){let n=t;e[n(920)](clearTimeout,this[n(1092)+"ionTimeo"+n(1630)]),this[n(1092)+n(1268)+"utId"]=null}[t(1038)+t(862)](){let n=t;clearTimeout(this[n(998)+n(1238)+"Id"]),e[n(1366)](clearTimeout,this["_reconne"+n(1235)+"tId"]),this["_pingPon"+n(1238)+"Id"]=null,this[n(1181)+n(1235)+n(701)]=null}[t(1345)](...n){let s=t;this._options[s(781)]&&console.log.apply(console,[e[s(766)],...n])}[t(1623)+t(1428)+"e"](n){let s=t,{initReconnectInterval:l,maxReconnectInterval:x,reconnectIntervalGrowFactor:m}=this[s(1637)],b=e.nWrQE(l,Math[s(1135)](m,n-1));return e[s(602)](b,x)?x:b}_ping(){let n=t;if(this[n(1136)]&&this._ws[n(452)+"te"]===this[n(1145)+"NG"]){this._clearPingTimer(),this["_pingPon"+n(1238)+"Id"]=setTimeout(this[n(624)][n(605)](this),this._options[n(1348)+n(381)]);return}if(!this[n(1136)]||e[n(1332)](this[n(1136)][n(452)+"te"],this[n(394)]))return void this[n(619)+"econnect"]();this[n(1136)]&&this[n(1136)][n(1926)]("hi"),this["_reconne"+n(1235)+n(701)]=e[n(1814)](setTimeout,this["_handleR"+n(1290)+"Timeout"][n(605)](this),this[n(1637)][n(745)+n(644)+n(1934)])}[t(619)+t(1290)+"Timeout"](){let n=t;this["_pingLos"+n(1323)]?.[n(504)](),this[n(1648)](e[n(368)],e[n(1483)]),this["_pingLos"+n(1323)]?.["checkRea"+n(1621)+"nt"]()?this[n(619)+n(1290)]():this[n(624)]()}[t(1583)+t(1231)](){let n=t,s={UmQAi:e[n(1335)],PAXDW:function(l,x,m,b){return e[n(1599)](l,x,m,b)},FRZqO:e[n(962)],CKBXD:function(l,x,m,b){return e.iHalN(l,x,m,b)},LcZgj:function(l,x,m,b){return e[n(691)](l,x,m,b)},dzmHW:e[n(1445)]};if(e.fWCrv(e.MCOHH,e.uiWDi))return this[n(739)+"T"]||this[n(423)+"X"]?this[n(1709)+"igatorOn"+n(657)]:(this[n(830)+"er"]||this._isWorker)&&this._options[n(1007)+n(386)+n(895)]?navigator.onLine:!0;{let l=s[n(1275)][n(573)]("|"),x=0;for(;;){switch(l[x++]){case"0":_0x3227ef[n(1024)](n(956),_0x5d573f);continue;case"1":_0x3bc107=lGydhZ.PAXDW(_0x17adad,_0x3c9c1e[n(1888)+"ame"],_0x83a835,_0x114d15);continue;case"2":_0x34d651[n(1024)](lGydhZ[n(1506)],_0x2d2319);continue;case"3":_0x360d89=lGydhZ[n(759)](_0x32ee11,_0x47b407[n(1800)+"er"](_0x264caa.cursor||_0x16f887),_0x4bd468,_0x447165);continue;case"4":_0x526f30=lGydhZ[n(1755)](_0x4f3b93,_0x25f68f[_0x3fdf68.cursor_name],_0x8a5763,_0x6016c);continue;case"5":_0x4c2051[n(1024)](n(631),_0x43b114);continue;case"6":_0xf982dd[n(1024)](lGydhZ[n(1407)],_0x1019d9);continue;case"7":_0x1508e0=lGydhZ.PAXDW(_0x21b23d,_0x15b3a0,_0xeea330,_0x25f367[n(659)]||0);continue;case"8":_0xf00747=lGydhZ.CKBXD(_0x279a06,0,_0x34a24c,_0x300d69);continue;case"9":_0x5f457b[n(1024)]("service-"+n(1917),_0x2210bf);continue;case"10":_0x2b2b45[n(1024)]("cursor.s"+n(1711),_0x1c217d,_0x170e1d[n(659)]);continue}break}}}["_handleR"+t(1290)](){let n=t;!this[n(1583)+n(1231)]()||this[n(446)+"osed"]||(this[n(1398)+n(1910)]?.["resetEndpointCon"+n(1270)](),this[n(1737)+n(1323)]?.[n(1140)+n(524)](),this[n(1136)]?this[n(1299)+n(1609)](1001,e[n(800)],!0):this[n(1092)]())}[t(1278)+t(1582)+t(618)](){let n=t;e[n(822)](e[n(1256)],e[n(1256)])?this[n(739)+"T"]?tt[n(1195)+n(938)+n(986)](({isConnected:s})=>{let l=n;this[l(1709)+l(1772)+"line"]=s,s?this[l(427)+l(879)]():this[l(427)+l(1662)]()}):this[n(423)+"X"]&&wx[n(1195)+n(938)+n(986)](({isConnected:s})=>{let l=n;this["_miniNav"+l(1772)+"line"]=s,s?this[l(427)+"nLine"]():this[l(427)+l(1662)]()}):_0x261544[n(1237)]=_0x112664[n(1774)]().then(()=>(_0x42c808(),_0x40cdd4))[n(1877)](function(s){return s})}_wait(n){return new Promise(s=>{let l=V;e.aaJVn(setTimeout,s,this[l(1623)+l(1428)+"e"](n))})}["_disconn"+t(1609)](n=1e3,s="",l=!1){let x=t;this[x(1136)]&&this[x(1133)+x(758)+"t"](n,s,l)}_onTimeout(){let n=t,s=this[n(1398)+n(1910)]?.["getCurre"+n(375)+"nt"]();this._debug(n(1727)+s+n(1514)),this["_disconn"+n(1609)](1001,e[n(974)],!0)}[t(886)](n){let s=t,l=e[s(1779)](Ft,n);if(this[s(1136)]&&this[s(1136)].readyState===this.OPEN)if(e[s(694)]!==s(1431)){let x="3|0|1|4|2"[s(573)]("|"),m=0;for(;;){switch(x[m++]){case"0":this[s(1136)][s(1328)+s(1455)+"ner"](e[s(1798)],this[s(630)]);continue;case"1":this[s(1136)]["removeEv"+s(1455)+"ner"](e[s(1561)],this[s(1113)]);continue;case"2":this._ws[s(1328)+s(1455)+s(1616)](e[s(855)],this[s(1124)]);continue;case"3":if(!this[s(1136)])return;continue;case"4":this[s(1136)][s(1328)+"entListener"](e[s(828)],this[s(1017)+"ge"]);continue}break}}else this[s(1136)]&&this[s(1136)][s(1926)](l),this[s(1345)](e[s(1076)],n)}["_removeW"+t(1385)+"rs"](){let n=t;this[n(1136)]&&(this[n(1136)][n(1328)+n(1455)+n(1616)](n(1554),this[n(630)]),this[n(1136)][n(1328)+n(1455)+n(1616)](e[n(1561)],this[n(1113)]),this[n(1136)][n(1328)+n(1455)+"ner"](e[n(828)],this[n(1017)+"ge"]),this[n(1136)]["removeEv"+n(1455)+"ner"](e[n(855)],this[n(1124)]))}[t(373)+t(1891)](){let n=t,s=e[n(1844)][n(573)]("|"),l=0;for(;;){switch(s[l++]){case"0":this[n(1136)][n(1091)+n(658)](e[n(828)],this[n(1017)+"ge"]);continue;case"1":this[n(1136)][n(1091)+n(658)](e[n(1798)],this._onOpen);continue;case"2":if(!this[n(1136)])return;continue;case"3":this._ws[n(1091)+n(658)](e[n(1561)],this[n(1113)]);continue;case"4":this[n(1136)][n(1091)+n(658)](e.BapYb,this._onError);continue}break}}_wsInstanceClose(n=1e3,s=""){let l=t;try{this[l(1136)]&&this[l(1136)].close(n,s)}catch{}}["_destroy"+t(758)+"t"](n=1e3,s="",l=!1){let x=t;if(e[x(629)](e[x(1151)],e[x(1151)]))_0x22129d[x(513)+x(804)]="",_0x3c21cf[x(1024)](_0x482e61);else{if(this[x(1038)+x(862)](),this[x(1059)+x(1121)](),this[x(492)+x(1385)+"rs"](),this[x(861)+x(943)](1e3,s),this[x(1092)+x(464)]=!1,l&&this[x(1583)+x(1231)]()&&!this[x(446)+"osed"])if(e[x(1060)](e.MGEPQ,e[x(786)])){let m=0,b=_0x4b10a3,E=e.SvhQE(_0x54e121,4);for(;b<E;){let{value:p,offset:k}=e[x(856)](_0x531556,_0x1cd8a5,b);b=k,m=e[x(1190)](e[x(473)](m,8),0),m+=p}return{value:m,offset:E}}else{if(this["_endpoin"+x(1910)]?.[x(1022)+x(1925)+"es"]()){let b=this[x(1398)+x(1910)]?.[x(1353)+x(375)+"nt"]();this[x(700)+x(526)+"ent"](e.qjhYm(pt,x(1594),{code:1006,reason:x(1727)+b+(x(1514)+", max re"+x(1134)+x(1843)),wasClean:!0}))}else{let b=this[x(1637)]["reconnec"+x(1379)+x(534)](n,s);this[x(700)+x(526)+x(1838)](e[x(1883)](pt,e[x(1561)],{code:n,reason:s,wasClean:!0,willReconnect:b})),b&&this[x(1092)]()}return}this[x(1583)+x(1231)]()||this[x(446)+x(1201)]?this[x(700)+x(526)+x(1838)](e[x(1203)](pt,"close",{code:n,reason:e[x(1101)]})):this[x(700)+x(526)+x(1838)](e[x(570)](pt,e[x(1561)],{code:1006,reason:e.lutVl})),this[x(1136)]=null,this["_endpoin"+x(1910)]?.["resetEnd"+x(733)+x(1270)](),this["_pingLos"+x(1323)]?.[x(1140)+"nter"]()}}[t(700)+t(1e3)+"nt"](n){let s=t,l={FDMtI:function(x,m){return e[V(542)](x,m)},SebUx:function(x,m,b){return x(m,b)}};if(e[s(400)](e.hoMiN,s(1191)))return(djYMzg[s(824)](_0x3ad2e7,4)[s(1309)]("0")+djYMzg[s(724)](_0x47c9c2,_0x225246,2)[s(1796)](16))[s(708)](-4);this[s(1648)](e.KXSWX,n),this.onopen&&this[s(744)](n)}[t(700)+"hMessageEvent"](n){let s=t;this[s(1648)](e[s(828)],n),this[s(715)+"e"]&&this[s(715)+"e"](n)}[t(700)+t(1264)+"ageEvent"](n){let s=t;this[s(1648)]("ack",n),this[s(497)+"eAck"]&&this[s(497)+"eAck"](n)}["_dispatc"+t(1840)+t(1838)](n){let s=t;if(e[s(1269)](e[s(1075)],e[s(1075)])){let l=_0x213ad5[s(979)];if(e[s(823)](e[s(1927)](l,_0x9ab0e5),_0x5b914[s(793)]))throw new _0x2d9c5f(e[s(673)]);return _0x3c00dc[s(979)]+=_0x10e240,l}else this[s(1648)](s(1622),n),this[s(1559)]&&this[s(1559)](n)}[t(700)+"hCloseEvent"](n){let s=t;this.emit(e[s(1561)],n),this[s(978)]&&this[s(978)](n)}get[t(1351)+"pe"](){let n=t;return this._ws?this._ws.binaryType:this[n(561)+n(1072)]}set[t(1351)+"pe"](n){let s=t;this["_binaryT"+s(1072)]=n,this[s(1136)]&&(this[s(1136)].binaryType=n)}get[t(1015)+"nt"](){let n=t;return this["_endpoin"+n(1910)]?.[n(1353)+n(375)+n(810)+"ount"]()||0}get[t(1208)+t(507)](){let n=t,s=this[n(1255)+"Queue"][n(1836)]((l,x)=>(l+=x&&x[n(1741)+"th"]||0,l),0);return e[n(1875)](s,this[n(1136)]?this[n(1136)]["buffered"+n(507)]:0)}get[t(536)+"ns"](){let n=t;return this[n(1136)]?this[n(1136)][n(536)+"ns"]:""}get[t(666)](){let n=t,s={GawKt:e[n(1083)],myLFM:function(l,x){return e.SaffG(l,x)},Yedul:function(l,x){return l!=x},tQoVK:e.yotwY};if(e[n(808)](e[n(1284)],e.BmdMc))return this[n(1136)]?this[n(1136)].protocol:"";{let l=s[n(1601)][n(573)]("|"),x=0;for(;;){switch(l[x++]){case"0":return!1;case"1":if(_0x17ab5b)return!0;continue;case"2":if(_0x585cbd&&_0x5d975a[n(1106)+"ocket"])return!0;continue;case"3":if(_0x4b95d1&&_0x3a4a78[n(1106)+n(714)])return!0;continue;case"4":if(XIauBq[n(1758)](_0x3b552e,_0x4c8627)&&XIauBq.Yedul(XIauBq[n(1793)],typeof _0x36ffe9)&&_0x4b7f31)return!0;continue}break}}}get[t(452)+"te"](){let n=t;return this[n(1136)]?this[n(1136)][n(452)+"te"]:this._options[n(1580)+n(444)]?this[n(1145)+"NG"]:this.CLOSED}get url(){let n=t;return e[n(1384)]!==e[n(1454)]?this[n(1136)]?this[n(1136)][n(564)]:this[n(1678)]:0}[t(1594)](n=1e3,s){let l=t;if(this[l(446)+l(1201)]=!0,this[l(1059)+l(1121)](),this[l(1038)+l(862)](),this[l(1876)+l(1646)+l(658)](),this[l(1387)+l(626)]?.[l(590)](),!this[l(1136)])return void this[l(1345)](e[l(1683)]);if(e[l(907)](this._ws.readyState,this[l(681)])||e[l(637)](this[l(1136)][l(452)+"te"],this[l(1304)]))return void this[l(1345)](l(1224)+"s already closed");this["_destroy"+l(758)+"t"](n,s)}async[t(1926)](n,s){let l=t,x={dDmgj:function(Be,os,as){return e[V(574)](Be,os,as)},grkMl:e[l(1561)]};if(n==null)throw new Error(e[l(1187)]);l(625)==typeof n&&(n=JSON[l(1627)+"y"](n)),e.NWYBF(e[l(1036)],typeof n)&&!e[l(592)](n,ArrayBuffer)&&!(n[l(494)]&&e[l(1791)](n[l(494)],ArrayBuffer))&&(n=JSON.stringify(n));let m=await e[l(1856)](ul,n),b=e[l(1856)](Lp,n),{method:E=0,service:p=this._options[l(659)],logID:k=this[l(1637)]["logIDGen"+l(925)](),headers:P=this._options[l(1061)],payloadEncoding:N=this[l(1637)][l(1033)+l(435)],payloadType:z=this._options[l(654)+"ype"],logIDNew:H=this[l(1637)][l(1261)+l(581)][l(1795)+l(1641)+l(1465)+"ew"]?i(this[l(1637)][l(1261)+l(581)][l(1770)]):""}=e[l(1216)](s,{});if(!p)throw new Error(e[l(588)]);let ge={SeqID:ue[l(1800)+"er"](this[l(765)]++),LogID:ue[l(1800)+"er"](k),service:p,method:E,headers:P,payloadEncoding:N instanceof Object?N[l(651)]?N[l(651)]:"":N,payloadType:z instanceof Object?z.type?z[l(1180)]:b:z||b,payload:m,LogIDNew:H},Ae=e[l(1202)](Ft,ge);if(this[l(1136)]&&this[l(1136)][l(452)+"te"]===this.OPEN)this[l(1136)]&&this[l(1136)][l(1926)](Ae),this[l(1345)](e[l(903)],ge);else if(e[l(840)](this[l(1255)+l(742)].length,this._options["maxMessa"+l(785)+"ength"]))if(e[l(1375)]("FFcuP",e[l(1349)]))this[l(1255)+"Queue"][l(1408)](Ae),this[l(1345)](e[l(875)],ge);else{let Be=this[l(1637)][l(509)+l(1379)+l(534)](_0x4af2b0,_0x324c1f);this[l(700)+l(526)+l(1838)](zIpRnC[l(1079)](_0x46cc44,zIpRnC.grkMl,{code:_0x52beeb,reason:_0x3973c,wasClean:!0,willReconnect:Be})),Be&&this[l(1092)]()}else this["_message"+l(742)].shift(),this[l(1255)+"Queue"].push(Ae);return{seqID:this[l(765)],logID:k,logIDNew:H}}async[t(509)+"t"](n){let s=t,{url:l}=e.alsWY(n,{}),x=Array[s(749)](l)?l:e.jQEFW==typeof l?[l]:[];n&&Object[s(1858)](this[s(1637)],n),x&&x[s(1027)]?this[s(1398)+s(1910)]=new al(x,this._options.maxRetries):this[s(1398)+"tManager"]?.["resetEndpointCon"+s(1270)](),this[s(1737)+"sCounter"]?.["resetCou"+s(524)](this[s(1637)][s(1628)+s(1695)]),this[s(446)+"osed"]=!1,this[s(1136)]&&e[s(806)](this[s(1136)][s(452)+"te"],this[s(681)])?this["_disconn"+s(1609)](1e3,s(1262)+s(1290)+s(1518),!0):(this._isInit=!0,this[s(1092)]())}async[t(584)](){let n=t;if(!this[n(1092)+n(464)]){let s=(n(1244)+"2")[n(573)]("|"),l=0;for(;;){switch(s[l++]){case"0":this[n(1398)+n(1910)]?.resetEndpointConfig();continue;case"1":this[n(446)+n(1201)]=!1;continue;case"2":this[n(1092)]();continue;case"3":this[n(1737)+n(1323)]?.[n(1140)+n(524)]();continue;case"4":this[n(1438)]=!0;continue}break}}}["addEvent"+t(658)](n,s){let l=t;e[l(434)]!==e[l(434)]?(e[l(887)](_0x58feb4,e[l(809)]),this[l(1787)]("ping_onc"+l(870)+"s",_0x319474),this[l(1787)](e[l(368)],_0x1a8577)):this.on(n,s)}["dispatch"+t(1762)](n){let s=t,{type:l}=n;this[s(1648)](l,n)}["removeEv"+t(1455)+t(1616)](n,s){let l=t;if(e[l(888)](e.CDCuU,l(1556)))this[l(1787)](n,s);else{let x=e[l(1538)](_0x482319,_0x5620ba,_0x1c8d00[l(1027)]);_0x5a16b7[l(402)][l(1240)](_0xb1cac0,x)}}[t(1606)](){let n=t,s={pVEcb:function(l,x){return l(x)},ZVLAg:e[n(512)],VDRMf:e[n(368)],uYIcR:"timeout",emHsj:function(l,x){return e[n(575)](l,x)},OFXPS:e[n(1066)]};return new Promise((l,x)=>{let m=n,b={cKUzC:function(E,p){return s[V(951)](E,p)},gIxMf:s[m(418)],tmjsI:s[m(1789)],VwOAD:s[m(737)]};if(s.emHsj(m(990),s[m(1186)]))this[m(1747)]++;else{this[m(1038)+"ngTimer"](),this[m(998)+"gTimeoutId"]=setTimeout(this[m(624)].bind(this),this[m(1637)][m(1348)+m(381)]);let E=()=>{let k=m;b[k(957)](l,k(1771)),this[k(1787)](b[k(867)],E),this[k(1787)](b[k(549)],p)},p=()=>{let k=m;b[k(957)](x,b.VwOAD),this.off(b[k(867)],E),this.off(b[k(549)],p)};this.on(s.ZVLAg,E),this.on(s[m(1789)],p),this._ping()}})}}})(),Me[B(598)+B(692)]=Ce[B(598)+"oseEvent"],Me["CustomEr"+B(540)]=Ce[B(600)+"rorEvent"],Me[B(1317)+"e"]=Ce[B(1317)+"e"],Me[B(1762)]=Ce[B(1762)],Me[B(369)]=Ce[B(369)],Me[B(680)+B(792)+B(419)]=Ce[B(680)+B(792)+B(419)],Me[B(792)+B(419)]=Ce[B(792)+B(419)],Me[B(1690)+"t"]=Ce[B(1690)+"t"],Me[B(1756)+B(1537)]=Ce.ReconnectEvent,Me.createCloseEvent=Ce[B(679)+B(692)],Me[B(420)+"rorEvent"]=Ce[B(420)+"rorEvent"],Me["createMe"+B(1868)+"nt"]=Ce["createMe"+B(1868)+"nt"],Me["createOp"+B(776)]=Ce[B(924)+B(776)],Me[B(1248)+B(416)+B(419)]=Ce[B(1248)+"connectEvent"],Me["decodedF"+B(1081)]=Ce[B(1533)+B(1081)],Me[B(1717)+B(1374)]=Ce[B(1717)+B(1374)];for(Go in Ce)[B(598)+"oseEvent",B(600)+B(540),B(1317)+"e",B(1762),B(369),B(680)+B(792)+B(419),"MessageE"+B(419),B(1690)+"t",B(1756)+"tEvent",B(679)+B(692),B(420)+B(540),B(1194)+"ssageEvent",B(924)+B(776),"createReconnectE"+B(419),"decodedF"+B(1081),B(1717)+B(1374)][B(523)](Go)===-1&&(Me[Go]=Ce[Go]);var Go;Object[B(1144)+"operty"](Me,"__esModule",{value:!0})});import{existsSync as vS,openSync as SS}from"node:fs";import{mkdir as IS}from"node:fs/promises";import{dirname as AS}from"node:path";import{fileURLToPath as kS}from"node:url";function RS(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function zd(t=Q()){return vS(t.libEntry)?t.libEntry:kS(new URL("../index.ts",import.meta.url))}async function Wh(t={}){let e=t.paths??Q(),r=t.entryOverride??zd(e),i=RS(e,process.env.COZE_BRIDGE_LOG_MODE);await IS(AS(i),{recursive:!0});let o=SS(i,"a"),d=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=rt(process.execPath,d,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[ns]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return TS.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var TS,ns,Xo=et(()=>{"use strict";Kt();te();Oe();TS=q("spawn-daemon"),ns="COZE_BRIDGE_DAEMON"});import{spawn as v1}from"node:child_process";import{mkdir as S1,unlink as I1,writeFile as A1}from"node:fs/promises";import{dirname as k1,join as T1}from"node:path";function $r(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function R1(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${$r(r)}</key>
21
+ <string>${$r(i)}</string>`).join(`
22
22
  `);return e?`
23
23
  <key>EnvironmentVariables</key>
24
24
  <dict>
25
25
  ${e}
26
- </dict>`:""}function m2(t,e){return new Promise((r,i)=>{let o=l2(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,cs,ca,Wd,tp=et(()=>{"use strict";re();Zr=H("supervisor.launchd"),cs="ai.coze.bridge",ca=m2,Wd={platform:"darwin",renderConfig(t){return`<?xml version="1.0" encoding="UTF-8"?>
26
+ </dict>`:""}function C1(t,e){return new Promise((r,i)=>{let o=v1(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 Kr,is,sa,Vd,up=et(()=>{"use strict";te();Kr=q("supervisor.launchd"),is="ai.coze.bridge",sa=C1,Vd={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>${cs}</string>
31
+ <string>${is}</string>
32
32
  <key>ProgramArguments</key>
33
33
  <array>
34
- <string>${Jr(t.nodeBin)}</string>
35
- <string>${Jr(t.entry)}</string>
34
+ <string>${$r(t.nodeBin)}</string>
35
+ <string>${$r(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>${Jr(t.logFile)}</string>
45
+ <string>${$r(t.logFile)}</string>
46
46
  <key>StandardErrorPath</key>
47
- <string>${Jr(t.logFile)}</string>${g2(t.env)}
47
+ <string>${$r(t.logFile)}</string>${R1(t.env)}
48
48
  </dict>
49
49
  </plist>
50
- `},configPath(t){return p2(t.homeDir,"Library","LaunchAgents",`${cs}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await u2(h2(i),{recursive:!0}),await x2(i,this.renderConfig(t),"utf8"),Zr.info("plist written",{plistPath:i,activate:r}),!r)return;await ca("launchctl",["unload","-w",i]).catch(c=>Zr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await ca("launchctl",["load","-w",i]),Zr.info("launchd job loaded",{label:cs});let o=process.getuid?.()??0;await ca("launchctl",["kickstart","-k",`gui/${o}/${cs}`]),Zr.info("launchd job kickstarted",{label:cs,uid:o})},async uninstall(t){let e=this.configPath(t);await ca("launchctl",["unload","-w",e]).catch(r=>Zr.warn("launchctl unload failed (ignored)",{err:String(r)})),await f2(e).catch(r=>{if(r.code!=="ENOENT")throw r}),Zr.info("launchd job removed",{plistPath:e})}}});import{spawn as w2}from"node:child_process";import{mkdir as _2,unlink as y2,writeFile as b2}from"node:fs/promises";import{dirname as E2,join as np}from"node:path";function la(t,e){return t.isRoot?e:["--user",...e]}function S2(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
- `):""}function ua(t,e){return new Promise((r,i)=>{let o=w2(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 da,Xr,v2,Kd,rp=et(()=>{"use strict";re();da=H("supervisor.systemd"),Xr="coze-bridge.service",v2="/etc/systemd/system";Kd={platform:"linux",renderConfig(t){let e=t.isRoot?"multi-user.target":"default.target";return`[Unit]
50
+ `},configPath(t){return T1(t.homeDir,"Library","LaunchAgents",`${is}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await S1(k1(i),{recursive:!0}),await A1(i,this.renderConfig(t),"utf8"),Kr.info("plist written",{plistPath:i,activate:r}),!r)return;await sa("launchctl",["unload","-w",i]).catch(c=>Kr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await sa("launchctl",["load","-w",i]),Kr.info("launchd job loaded",{label:is});let o=process.getuid?.()??0;await sa("launchctl",["kickstart","-k",`gui/${o}/${is}`]),Kr.info("launchd job kickstarted",{label:is,uid:o})},async uninstall(t){let e=this.configPath(t);await sa("launchctl",["unload","-w",e]).catch(r=>Kr.warn("launchctl unload failed (ignored)",{err:String(r)})),await I1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),Kr.info("launchd job removed",{plistPath:e})}}});import{spawn as D1}from"node:child_process";import{mkdir as P1,unlink as O1,writeFile as L1}from"node:fs/promises";import{dirname as N1,join as fp}from"node:path";function aa(t,e){return t.isRoot?e:["--user",...e]}function B1(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
51
+ `):""}function ca(t,e){return new Promise((r,i)=>{let o=D1(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 oa,Vr,M1,Yd,xp=et(()=>{"use strict";te();oa=q("supervisor.systemd"),Vr="coze-bridge.service",M1="/etc/systemd/system";Yd={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
- ${S2(t.env)}
62
+ ${B1(t.env)}
63
63
  [Install]
64
64
  WantedBy=${e}
65
- `},configPath(t){return t.isRoot?np(v2,Xr):np(t.homeDir,".config","systemd","user",Xr)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await _2(E2(i),{recursive:!0}),await b2(i,this.renderConfig(t),"utf8"),da.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await ua("systemctl",la(t,["daemon-reload"])),await ua("systemctl",la(t,r?["enable","--now",Xr]:["enable",Xr])),da.info("systemd unit enabled",{unitName:Xr,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await ua("systemctl",la(t,["disable","--now",Xr])).catch(r=>da.warn("systemctl disable failed (ignored)",{err:String(r)})),await y2(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await ua("systemctl",la(t,["daemon-reload"])).catch(()=>{}),da.info("systemd unit removed",{unitPath:e})}}});import{spawn as A2}from"node:child_process";import{join as I2}from"node:path";function ip(t,e){return new Promise((r,i)=>{let o=A2(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 $d,fa,Vd,sp=et(()=>{"use strict";re();$d=H("supervisor.taskscheduler"),fa="CozeBridge",Vd={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
65
+ `},configPath(t){return t.isRoot?fp(M1,Vr):fp(t.homeDir,".config","systemd","user",Vr)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await P1(N1(i),{recursive:!0}),await L1(i,this.renderConfig(t),"utf8"),oa.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await ca("systemctl",aa(t,["daemon-reload"])),await ca("systemctl",aa(t,r?["enable","--now",Vr]:["enable",Vr])),oa.info("systemd unit enabled",{unitName:Vr,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await ca("systemctl",aa(t,["disable","--now",Vr])).catch(r=>oa.warn("systemctl disable failed (ignored)",{err:String(r)})),await O1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await ca("systemctl",aa(t,["daemon-reload"])).catch(()=>{}),oa.info("systemd unit removed",{unitPath:e})}}});import{spawn as F1}from"node:child_process";import{join as z1}from"node:path";function hp(t,e){return new Promise((r,i)=>{let o=F1(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 Zd,da,Jd,pp=et(()=>{"use strict";te();Zd=q("supervisor.taskscheduler"),da="CozeBridge",Jd={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
66
66
  <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
67
67
  <RegistrationInfo>
68
68
  <Description>Coze Bridge daemon</Description>
@@ -86,48 +86,50 @@ WantedBy=${e}
86
86
  </Exec>
87
87
  </Actions>
88
88
  </Task>
89
- `},configPath(t){return I2(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 ip("schtasks",["/Create","/SC","ONLOGON","/TN",fa,"/TR",r,"/RU",t.userName,"/F"]),$d.info("task scheduler entry created",{task:fa,logFile:t.logFile})},async uninstall(t){await ip("schtasks",["/Delete","/TN",fa,"/F"]).catch(e=>$d.warn("schtasks /Delete failed (ignored)",{err:String(e)})),$d.info("task scheduler entry removed",{task:fa})}}});var op={};va(op,{buildContext:()=>P2,getSupervisor:()=>R2,launchdSupervisor:()=>Wd,systemdSupervisor:()=>Kd,taskSchedulerSupervisor:()=>Vd});import{homedir as C2,userInfo as T2}from"node:os";function R2(t=process.platform){switch(t){case"darwin":return Wd;case"linux":return Kd;case"win32":return Vd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function k2(){let t={};for(let e of D2){let r=process.env[e];r&&(t[e]=r)}return t}function P2(){let t=Q();return{nodeBin:process.execPath,entry:Md(t),logFile:t.logFile,homeDir:C2(),userName:T2().username,isRoot:process.getuid?.()===0,env:k2()}}var D2,ap=et(()=>{"use strict";Le();ta();tp();rp();sp();D2=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});re();an();var Sl=H("acp-installer-warmup"),kg=["claude-code","codex"];async function Al(t={}){let e=t.ensure??dr,i=(await Promise.allSettled(kg.map(async o=>{let c=await e(o);Sl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&Sl.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}ln();re();import{readdir as $g}from"node:fs/promises";import{mkdir as Rl,readFile as Wg,writeFile as Dl}from"node:fs/promises";import{join as Da}from"node:path";var Kg={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function fr(t,e,r){await Rl(t,{recursive:!0});let i=Kg[e],o=Da(t,i);return await Dl(o,r??"","utf8"),o}async function ka(t,e,r){let i=Da(t,".claude");await Rl(i,{recursive:!0});let o=Da(i,"settings.local.json"),c={};try{let u=await Wg(o,"utf8"),x=JSON.parse(u);typeof x=="object"&&x!==null&&!Array.isArray(x)&&(c=x)}catch{}let l=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")l.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!r)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");l.defaultMode===void 0&&(l.defaultMode=r)}return c.permissions=l,await Dl(o,JSON.stringify(c,null,2),"utf8"),o}var Xe=H("agent-detail-sync"),Vg=6e4,Zg=5*6e4,ys=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await $g(r)}catch(o){Xe.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}Xe.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Fe(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Xe.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(l){Xe.warn("detail sync failed for agent, skipping",{agentId:o,err:String(l)})}}})),Xe.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){Xe.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){Xe.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Fe(e,this.opts.paths);if(!i){Xe.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(x){Xe.warn("detail RPC failed, using local data",{agentId:e,err:String(x)});let h=this.retryQueue.get(e),m=h?Math.min(h.currentDelay*2,Zg):Vg;this.retryQueue.set(e,{dueAt:Date.now()+m,currentDelay:m});return}if(o.agentId&&o.agentId!==e){Xe.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,l=!1;o.agentName&&o.agentName!==i.agentName&&(i.agentName=o.agentName,c=!0),o.description!==void 0&&o.description!==i.description&&(i.description=o.description,c=!0),o.cozeIdentity&&o.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=o.cozeIdentity,c=!0,l=!0);let u=!1;if(o.deployType==="cloud"&&i.deployType!=="cloud"?(Xe.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&Xe.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Xe.debug("detail sync: no diff",{agentId:e});return}await rt(i,this.opts.paths),Xe.info("detail sync: config updated",{agentId:e,identityChanged:l,agentName:i.agentName}),u?(await this.opts.agentManager.createAgent({agentId:e,framework:i.framework,_meta:{cozeDeployType:"cloud"},cozeIdentity:i.cozeIdentity,model:i.model}),Xe.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):l&&(await fr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var Zf=qt(du(),1);import{lstat as Wc,mkdir as Kc,readFile as Wf,readdir as D_,rm as k_,stat as P_,writeFile as $c}from"node:fs/promises";import{dirname as O_,join as Lt,normalize as L_,relative as Jc,resolve as Vc,sep as Kf}from"node:path";import{Readable as $f}from"node:stream";import{pipeline as Vf}from"node:stream/promises";import mm from"events";import it from"fs";import{EventEmitter as Dc}from"node:events";import ju from"node:stream";import{StringDecoder as wm}from"node:string_decoder";import $u from"node:path";import Sr from"node:fs";import{dirname as km,parse as Pm}from"path";import{EventEmitter as Um}from"events";import uc from"assert";import{Buffer as Wn}from"buffer";import*as hu from"zlib";import qm from"zlib";import{posix as mr}from"node:path";import{basename as hw}from"node:path";import Ys from"fs";import kt from"fs";import bu from"path";import{win32 as Iw}from"node:path";import Tu from"path";import df from"node:fs";import Hw from"node:assert";import{randomBytes as lf}from"node:crypto";import ie from"node:fs";import Me from"node:path";import uf from"fs";import ao from"node:fs";import Ci from"node:path";import ct from"node:fs";import Jw from"node:fs/promises";import to from"node:path";import{join as Ef}from"node:path";import at from"node:fs";import Af from"node:path";var pm=Object.defineProperty,gm=(t,e)=>{for(var r in e)pm(t,r,{get:e[r],enumerable:!0})},lu=typeof process=="object"&&process?process:{stdout:null,stderr:null},_m=t=>!!t&&typeof t=="object"&&(t instanceof Vn||t instanceof ju||ym(t)||bm(t)),ym=t=>!!t&&typeof t=="object"&&t instanceof Dc&&typeof t.pipe=="function"&&t.pipe!==ju.Writable.prototype.pipe,bm=t=>!!t&&typeof t=="object"&&t instanceof Dc&&typeof t.write=="function"&&typeof t.end=="function",Gt=Symbol("EOF"),Ht=Symbol("maybeEmitEnd"),fn=Symbol("emittedEnd"),As=Symbol("emittingEnd"),li=Symbol("emittedError"),Is=Symbol("closed"),uu=Symbol("read"),Cs=Symbol("flush"),fu=Symbol("flushChunk"),mt=Symbol("encoding"),gr=Symbol("decoder"),Ue=Symbol("flowing"),ui=Symbol("paused"),br=Symbol("resume"),qe=Symbol("buffer"),Ye=Symbol("pipes"),Ge=Symbol("bufferLength"),Ba=Symbol("bufferPush"),Ts=Symbol("bufferShift"),Je=Symbol("objectMode"),Se=Symbol("destroyed"),za=Symbol("error"),Fa=Symbol("emitData"),xu=Symbol("emitEnd"),Ua=Symbol("emitEnd2"),Tt=Symbol("async"),qa=Symbol("abort"),Rs=Symbol("aborted"),fi=Symbol("signal"),Mn=Symbol("dataListeners"),ot=Symbol("discarded"),xi=t=>Promise.resolve().then(t),Em=t=>t(),vm=t=>t==="end"||t==="finish"||t==="prefinish",Sm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,Am=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Wu=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[br](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Im=class extends Wu{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)}},Cm=t=>!!t.objectMode,Tm=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Vn=class extends Dc{[Ue]=!1;[ui]=!1;[Ye]=[];[qe]=[];[Je];[mt];[Tt];[gr];[Gt]=!1;[fn]=!1;[As]=!1;[Is]=!1;[li]=null;[Ge]=0;[Se]=!1;[fi];[Rs]=!1;[Mn]=0;[ot]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");Cm(e)?(this[Je]=!0,this[mt]=null):Tm(e)?(this[mt]=e.encoding,this[Je]=!1):(this[Je]=!1,this[mt]=null),this[Tt]=!!e.async,this[gr]=this[mt]?new wm(this[mt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[qe]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Ye]});let{signal:r}=e;r&&(this[fi]=r,r.aborted?this[qa]():r.addEventListener("abort",()=>this[qa]()))}get bufferLength(){return this[Ge]}get encoding(){return this[mt]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[Je]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[Tt]}set async(t){this[Tt]=this[Tt]||!!t}[qa](){this[Rs]=!0,this.emit("abort",this[fi]?.reason),this.destroy(this[fi]?.reason)}get aborted(){return this[Rs]}set aborted(t){}write(t,e,r){if(this[Rs])return!1;if(this[Gt])throw new Error("write after end");if(this[Se])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof e=="function"&&(r=e,e="utf8"),e||(e="utf8");let i=this[Tt]?xi:Em;if(!this[Je]&&!Buffer.isBuffer(t)){if(Am(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(Sm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Je]?(this[Ue]&&this[Ge]!==0&&this[Cs](!0),this[Ue]?this.emit("data",t):this[Ba](t),this[Ge]!==0&&this.emit("readable"),r&&i(r),this[Ue]):t.length?(typeof t=="string"&&!(e===this[mt]&&!this[gr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[mt]&&(t=this[gr].write(t)),this[Ue]&&this[Ge]!==0&&this[Cs](!0),this[Ue]?this.emit("data",t):this[Ba](t),this[Ge]!==0&&this.emit("readable"),r&&i(r),this[Ue]):(this[Ge]!==0&&this.emit("readable"),r&&i(r),this[Ue])}read(t){if(this[Se])return null;if(this[ot]=!1,this[Ge]===0||t===0||t&&t>this[Ge])return this[Ht](),null;this[Je]&&(t=null),this[qe].length>1&&!this[Je]&&(this[qe]=[this[mt]?this[qe].join(""):Buffer.concat(this[qe],this[Ge])]);let e=this[uu](t||null,this[qe][0]);return this[Ht](),e}[uu](t,e){if(this[Je])this[Ts]();else{let r=e;t===r.length||t===null?this[Ts]():typeof r=="string"?(this[qe][0]=r.slice(t),e=r.slice(0,t),this[Ge]-=t):(this[qe][0]=r.subarray(t),e=r.subarray(0,t),this[Ge]-=t)}return this.emit("data",e),!this[qe].length&&!this[Gt]&&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[Gt]=!0,this.writable=!1,(this[Ue]||!this[ui])&&this[Ht](),this}[br](){this[Se]||(!this[Mn]&&!this[Ye].length&&(this[ot]=!0),this[ui]=!1,this[Ue]=!0,this.emit("resume"),this[qe].length?this[Cs]():this[Gt]?this[Ht]():this.emit("drain"))}resume(){return this[br]()}pause(){this[Ue]=!1,this[ui]=!0,this[ot]=!1}get destroyed(){return this[Se]}get flowing(){return this[Ue]}get paused(){return this[ui]}[Ba](t){this[Je]?this[Ge]+=1:this[Ge]+=t.length,this[qe].push(t)}[Ts](){return this[Je]?this[Ge]-=1:this[Ge]-=this[qe][0].length,this[qe].shift()}[Cs](t=!1){do;while(this[fu](this[Ts]())&&this[qe].length);!t&&!this[qe].length&&!this[Gt]&&this.emit("drain")}[fu](t){return this.emit("data",t),this[Ue]}pipe(t,e){if(this[Se])return t;this[ot]=!1;let r=this[fn];return e=e||{},t===lu.stdout||t===lu.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[Ye].push(e.proxyErrors?new Im(this,t,e):new Wu(this,t,e)),this[Tt]?xi(()=>this[br]()):this[br]()),t}unpipe(t){let e=this[Ye].find(r=>r.dest===t);e&&(this[Ye].length===1?(this[Ue]&&this[Mn]===0&&(this[Ue]=!1),this[Ye]=[]):this[Ye].splice(this[Ye].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[ot]=!1,this[Mn]++,!this[Ye].length&&!this[Ue]&&this[br]();else if(t==="readable"&&this[Ge]!==0)super.emit("readable");else if(vm(t)&&this[fn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[li]){let i=e;this[Tt]?xi(()=>i.call(this,this[li])):i.call(this,this[li])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Mn]=this.listeners("data").length,this[Mn]===0&&!this[ot]&&!this[Ye].length&&(this[Ue]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Mn]=0,!this[ot]&&!this[Ye].length&&(this[Ue]=!1)),e}get emittedEnd(){return this[fn]}[Ht](){!this[As]&&!this[fn]&&!this[Se]&&this[qe].length===0&&this[Gt]&&(this[As]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Is]&&this.emit("close"),this[As]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Se&&this[Se])return!1;if(t==="data")return!this[Je]&&!r?!1:this[Tt]?(xi(()=>this[Fa](r)),!0):this[Fa](r);if(t==="end")return this[xu]();if(t==="close"){if(this[Is]=!0,!this[fn]&&!this[Se])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[li]=r,super.emit(za,r);let o=!this[fi]||this.listeners("error").length?super.emit("error",r):!1;return this[Ht](),o}else if(t==="resume"){let o=super.emit("resume");return this[Ht](),o}else if(t==="finish"||t==="prefinish"){let o=super.emit(t);return this.removeAllListeners(t),o}let i=super.emit(t,...e);return this[Ht](),i}[Fa](t){for(let r of this[Ye])r.dest.write(t)===!1&&this.pause();let e=this[ot]?!1:super.emit("data",t);return this[Ht](),e}[xu](){return this[fn]?!1:(this[fn]=!0,this.readable=!1,this[Tt]?(xi(()=>this[Ua]()),!0):this[Ua]())}[Ua](){if(this[gr]){let e=this[gr].end();if(e){for(let r of this[Ye])r.dest.write(e);this[ot]||super.emit("data",e)}}for(let e of this[Ye])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Je]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[Je]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[Je])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[mt]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Se,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[ot]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[Gt])return e();let i,o,c=h=>{this.off("data",l),this.off("end",u),this.off(Se,x),e(),o(h)},l=h=>{this.off("error",c),this.off("end",u),this.off(Se,x),this.pause(),i({value:h,done:!!this[Gt]})},u=()=>{this.off("error",c),this.off("data",l),this.off(Se,x),e(),i({done:!0,value:void 0})},x=()=>c(new Error("stream destroyed"));return new Promise((h,m)=>{o=m,i=h,this.once(Se,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[ot]=!1;let t=!1,e=()=>(this.pause(),this.off(za,e),this.off(Se,e),this.off("end",e),t=!0,{done:!0,value:void 0}),r=()=>{if(t)return e();let i=this.read();return i===null?e():{done:!1,value:i}};return this.once("end",e),this.once(za,e),this.once(Se,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Se])return t?this.emit("error",t):this.emit(Se),this;this[Se]=!0,this[ot]=!0,this[qe].length=0,this[Ge]=0;let e=this;return typeof e.close=="function"&&!this[Is]&&e.close(),t?this.emit("error",t):this.emit(Se),this}static get isStream(){return _m}},Rm=it.writev,En=Symbol("_autoClose"),bt=Symbol("_close"),hi=Symbol("_ended"),le=Symbol("_fd"),Ga=Symbol("_finished"),$t=Symbol("_flags"),Ha=Symbol("_flush"),dc=Symbol("_handleChunk"),lc=Symbol("_makeBuf"),Ai=Symbol("_mode"),Ds=Symbol("_needDrain"),Ir=Symbol("_onerror"),Cr=Symbol("_onopen"),ja=Symbol("_onread"),Er=Symbol("_onwrite"),vn=Symbol("_open"),yt=Symbol("_path"),mn=Symbol("_pos"),Rt=Symbol("_queue"),vr=Symbol("_read"),Wa=Symbol("_readSize"),Kt=Symbol("_reading"),pi=Symbol("_remain"),Ka=Symbol("_size"),Us=Symbol("_write"),Bn=Symbol("_writing"),qs=Symbol("_defaultFlag"),jn=Symbol("_errored"),kc=class extends Vn{[jn]=!1;[le];[yt];[Wa];[Kt]=!1;[Ka];[pi];[En];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[jn]=!1,this[le]=typeof e.fd=="number"?e.fd:void 0,this[yt]=t,this[Wa]=e.readSize||16*1024*1024,this[Kt]=!1,this[Ka]=typeof e.size=="number"?e.size:1/0,this[pi]=this[Ka],this[En]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[le]=="number"?this[vr]():this[vn]()}get fd(){return this[le]}get path(){return this[yt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[vn](){it.open(this[yt],"r",(t,e)=>this[Cr](t,e))}[Cr](t,e){t?this[Ir](t):(this[le]=e,this.emit("open",e),this[vr]())}[lc](){return Buffer.allocUnsafe(Math.min(this[Wa],this[pi]))}[vr](){if(!this[Kt]){this[Kt]=!0;let t=this[lc]();if(t.length===0)return process.nextTick(()=>this[ja](null,0,t));it.read(this[le],t,0,t.length,null,(e,r,i)=>this[ja](e,r,i))}}[ja](t,e,r){this[Kt]=!1,t?this[Ir](t):this[dc](e,r)&&this[vr]()}[bt](){if(this[En]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,it.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[Ir](t){this[Kt]=!0,this[bt](),this.emit("error",t)}[dc](t,e){let r=!1;return this[pi]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[pi]<=0)&&(r=!1,this[bt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[le]=="number"&&this[vr](),!1;case"error":return this[jn]?!1:(this[jn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Dm=class extends kc{[vn](){let t=!0;try{this[Cr](null,it.openSync(this[yt],"r")),t=!1}finally{t&&this[bt]()}}[vr](){let t=!0;try{if(!this[Kt]){this[Kt]=!0;do{let e=this[lc](),r=e.length===0?0:it.readSync(this[le],e,0,e.length,null);if(!this[dc](r,e))break}while(!0);this[Kt]=!1}t=!1}finally{t&&this[bt]()}}[bt](){if(this[En]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,it.closeSync(t),this.emit("close")}}},no=class extends mm{readable=!1;writable=!0;[jn]=!1;[Bn]=!1;[hi]=!1;[Rt]=[];[Ds]=!1;[yt];[Ai];[En];[le];[qs];[$t];[Ga]=!1;[mn];constructor(t,e){e=e||{},super(e),this[yt]=t,this[le]=typeof e.fd=="number"?e.fd:void 0,this[Ai]=e.mode===void 0?438:e.mode,this[mn]=typeof e.start=="number"?e.start:void 0,this[En]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[mn]!==void 0?"r+":"w";this[qs]=e.flags===void 0,this[$t]=e.flags===void 0?r:e.flags,this[le]===void 0&&this[vn]()}emit(t,...e){if(t==="error"){if(this[jn])return!1;this[jn]=!0}return super.emit(t,...e)}get fd(){return this[le]}get path(){return this[yt]}[Ir](t){this[bt](),this[Bn]=!0,this.emit("error",t)}[vn](){it.open(this[yt],this[$t],this[Ai],(t,e)=>this[Cr](t,e))}[Cr](t,e){this[qs]&&this[$t]==="r+"&&t&&t.code==="ENOENT"?(this[$t]="w",this[vn]()):t?this[Ir](t):(this[le]=e,this.emit("open",e),this[Bn]||this[Ha]())}end(t,e){return t&&this.write(t,e),this[hi]=!0,!this[Bn]&&!this[Rt].length&&typeof this[le]=="number"&&this[Er](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[hi]?(this.emit("error",new Error("write() after end()")),!1):this[le]===void 0||this[Bn]||this[Rt].length?(this[Rt].push(t),this[Ds]=!0,!1):(this[Bn]=!0,this[Us](t),!0)}[Us](t){it.write(this[le],t,0,t.length,this[mn],(e,r)=>this[Er](e,r))}[Er](t,e){t?this[Ir](t):(this[mn]!==void 0&&typeof e=="number"&&(this[mn]+=e),this[Rt].length?this[Ha]():(this[Bn]=!1,this[hi]&&!this[Ga]?(this[Ga]=!0,this[bt](),this.emit("finish")):this[Ds]&&(this[Ds]=!1,this.emit("drain"))))}[Ha](){if(this[Rt].length===0)this[hi]&&this[Er](null,0);else if(this[Rt].length===1)this[Us](this[Rt].pop());else{let t=this[Rt];this[Rt]=[],Rm(this[le],t,this[mn],(e,r)=>this[Er](e,r))}}[bt](){if(this[En]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,it.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Ku=class extends no{[vn](){let t;if(this[qs]&&this[$t]==="r+")try{t=it.openSync(this[yt],this[$t],this[Ai])}catch(e){if(e?.code==="ENOENT")return this[$t]="w",this[vn]();throw e}else t=it.openSync(this[yt],this[$t],this[Ai]);this[Cr](null,t)}[bt](){if(this[En]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,it.closeSync(t),this.emit("close")}}[Us](t){let e=!0;try{this[Er](null,it.writeSync(this[le],t,0,t.length,this[mn])),e=!1}finally{if(e)try{this[bt]()}catch{}}}},Om=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"]]),Lm=t=>!!t.sync&&!!t.file,Nm=t=>!t.sync&&!!t.file,Mm=t=>!!t.sync&&!t.file,Bm=t=>!t.sync&&!t.file,zm=t=>!!t.file,Fm=t=>Om.get(t)||t,Pc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=Fm(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Li=(t,e,r,i,o)=>Object.assign((c=[],l,u)=>{Array.isArray(c)&&(l=c,c={}),typeof l=="function"&&(u=l,l=void 0),l=l?Array.from(l):[];let x=Pc(c);if(o?.(x,l),Lm(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(x,l)}else if(Nm(x)){let h=e(x,l);return u?h.then(()=>u(),u):h}else if(Mm(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(x,l)}else if(Bm(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}),Gm=qm.constants||{ZLIB_VERNUM:4736},Ot=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},Gm)),Hm=Wn.concat,pu=Object.getOwnPropertyDescriptor(Wn,"concat"),jm=t=>t,$a=pu?.writable===!0||pu?.set!==void 0?t=>{Wn.concat=t?jm:Hm}:t=>{},Kn=Symbol("_superWrite"),ks=class extends Error{code;errno;constructor(t,e){super("zlib: "+t.message,{cause:t}),this.code=t.code,this.errno=t.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+t.message,Error.captureStackTrace(this,e??this.constructor)}get name(){return"ZlibError"}},Va=Symbol("flushFlag"),Oc=class extends Vn{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof hu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new hu[e](t)}catch(r){throw new ks(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 ks(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return uc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Wn.alloc(0),{[Va]: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}[Kn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Wn.from(t,e)),this.#e)return;uc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},$a(!0);let l;try{let x=typeof t[Va]=="number"?t[Va]:this.#r;l=this.#t._processChunk(t,x),$a(!1)}catch(x){$a(!1),this.#o(new ks(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 ks(x,this.write)));let u;if(l)if(Array.isArray(l)&&l.length>0){let x=l[0];u=this[Kn](Wn.from(x));for(let h=1;h<l.length;h++)u=this[Kn](l[h])}else u=this[Kn](Wn.from(l));return r&&r(),u}},Vu=class extends Oc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Ot.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Ot.Z_FINISH,t.fullFlushFlag=Ot.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(Ot.Z_SYNC_FLUSH),uc(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)}}}},Wm=class extends Vu{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Kn](t){return this.#e?(this.#e=!1,t[9]=255,super[Kn](t)):super[Kn](t)}},Km=class extends Vu{constructor(t){super(t,"Unzip")}},Zu=class extends Oc{constructor(t,e){t=t||{},t.flush=t.flush||Ot.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Ot.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Ot.BROTLI_OPERATION_FLUSH,super(t,e)}},$m=class extends Zu{constructor(t){super(t,"BrotliCompress")}},Vm=class extends Zu{constructor(t){super(t,"BrotliDecompress")}},Ju=class extends Oc{constructor(t,e){t=t||{},t.flush=t.flush||Ot.ZSTD_e_continue,t.finishFlush=t.finishFlush||Ot.ZSTD_e_end,t.fullFlushFlag=Ot.ZSTD_e_flush,super(t,e)}},Zm=class extends Ju{constructor(t){super(t,"ZstdCompress")}},Jm=class extends Ju{constructor(t){super(t,"ZstdDecompress")}},Xm=(t,e)=>{if(Number.isSafeInteger(t))t<0?Qm(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)},Qm=(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]=Xu(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Yu(o))}},ew=t=>{let e=t[0],r=e===128?nw(t.subarray(1,t.length)):e===255?tw(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},tw=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),l;i?l=Xu(c):c===0?l=c:(i=!0,l=Yu(c)),l!==0&&(r-=l*Math.pow(256,e-o-1))}return r},nw=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},Xu=t=>(255^t)&255,Yu=t=>(255^t)+1&255,rw={};gm(rw,{code:()=>Lc,isCode:()=>Gs,isName:()=>iw,name:()=>ro,normalFsTypes:()=>Qu});var Gs=t=>ro.has(t),iw=t=>Lc.has(t),Qu=new Set(["0","","1","2","3","4","5","6","7","D"]),ro=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"]]),Lc=new Map(Array.from(ro).map(t=>[t[1],t[0]])),$n=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,r,i){Buffer.isBuffer(t)?this.decode(t,e||0,r,i):t&&this.#n(t)}decode(t,e,r,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");let o=zn(t,e+156,1),c=Qu.has(o),l=c?r:void 0,u=c?i:void 0;if(this.path=l?.path??zn(t,e,100),this.mode=l?.mode??u?.mode??wn(t,e+100,8),this.uid=l?.uid??u?.uid??wn(t,e+108,8),this.gid=l?.gid??u?.gid??wn(t,e+116,8),this.size=l?.size??u?.size??wn(t,e+124,12),this.mtime=l?.mtime??u?.mtime??Za(t,e+136,12),this.cksum=wn(t,e+148,12),u&&this.#n(u,!0),l&&this.#n(l),Gs(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=zn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=l?.uname??u?.uname??zn(t,e+265,32),this.gname=l?.gname??u?.gname??zn(t,e+297,32),this.devmaj=l?.devmaj??u?.devmaj??wn(t,e+329,8)??0,this.devmin=l?.devmin??u?.devmin??wn(t,e+337,8)??0,t[e+475]!==0){let h=zn(t,e+345,155);this.path=h+"/"+this.path}else{let h=zn(t,e+345,130);h&&(this.path=h+"/"+this.path),this.atime=r?.atime??i?.atime??Za(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Za(t,e+488,12)}let x=256;for(let h=e;h<e+148;h++)x+=t[h];for(let h=e+156;h<e+512;h++)x+=t[h];this.cksumValid=x===this.cksum,this.cksum===void 0&&x===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e||r==="linkpath"&&e||r==="global"))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let r=this.ctime||this.atime?130:155,i=sw(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Fn(t,e,100,o)||this.needPax,this.needPax=_n(t,e+100,8,this.mode)||this.needPax,this.needPax=_n(t,e+108,8,this.uid)||this.needPax,this.needPax=_n(t,e+116,8,this.gid)||this.needPax,this.needPax=_n(t,e+124,12,this.size)||this.needPax,this.needPax=Ja(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Fn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Fn(t,e+265,32,this.uname)||this.needPax,this.needPax=Fn(t,e+297,32,this.gname)||this.needPax,this.needPax=_n(t,e+329,8,this.devmaj)||this.needPax,this.needPax=_n(t,e+337,8,this.devmin)||this.needPax,this.needPax=Fn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=Fn(t,e+345,155,c)||this.needPax:(this.needPax=Fn(t,e+345,130,c)||this.needPax,this.needPax=Ja(t,e+476,12,this.atime)||this.needPax,this.needPax=Ja(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,_n(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:ro.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Lc.get(t));if(Gs(e)||e==="Unsupported")this.#e=e;else if(Gs(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},sw=(t,e)=>{let r=t,i="",o,c=mr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=mr.dirname(r),r=mr.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=mr.join(mr.basename(i),r),i=mr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},zn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Za=(t,e,r)=>ow(wn(t,e,r)),ow=t=>t===void 0?void 0:new Date(t*1e3),wn=(t,e,r)=>Number(t[e])&128?ew(t.subarray(e,e+r)):cw(t,e,r),aw=t=>isNaN(t)?void 0:t,cw=(t,e,r)=>aw(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),dw={12:8589934591,8:2097151},_n=(t,e,r,i)=>i===void 0?!1:i>dw[r]||i<0?(Xm(i,t.subarray(e,e+r)),!0):(lw(t,e,r,i),!1),lw=(t,e,r,i)=>t.write(uw(i,r),e,r,"ascii"),uw=(t,e)=>fw(Math.floor(t).toString(8),e),fw=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Ja=(t,e,r,i)=>i===void 0?!1:_n(t,e,r,i.getTime()/1e3),xw=new Array(156).join("\0"),Fn=(t,e,r,i)=>i===void 0?!1:(t.write(i+xw,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),Xs=class ef{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 $n({path:("PaxHeader/"+hw(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 ef(pw(gw(e),r),i)}},pw=(t,e)=>e?Object.assign({},e,t):t,gw=t=>t.replace(/\n$/,"").split(`
91
- `).reduce(mw,Object.create(null)),mw=(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},ww=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Y=ww!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),_w=class extends Vn{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))))}},io=(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))},yw=1024*1024,fc=Buffer.from([31,139]),xc=Buffer.from([40,181,47,253]),bw=Math.max(fc.length,xc.length),ut=Symbol("state"),Un=Symbol("writeEntry"),jt=Symbol("readEntry"),Xa=Symbol("nextEntry"),gu=Symbol("processEntry"),Dt=Symbol("extendedHeader"),gi=Symbol("globalExtendedHeader"),xn=Symbol("meta"),mu=Symbol("emitMeta"),ge=Symbol("buffer"),Wt=Symbol("queue"),hn=Symbol("ended"),Ya=Symbol("emittedEnd"),qn=Symbol("emit"),Te=Symbol("unzip"),Ps=Symbol("consumeChunk"),Os=Symbol("consumeChunkSub"),Qa=Symbol("consumeBody"),wu=Symbol("consumeMeta"),_u=Symbol("consumeHeader"),mi=Symbol("consuming"),ec=Symbol("bufferConcat"),Ls=Symbol("maybeEnd"),wr=Symbol("writing"),pn=Symbol("aborted"),Ns=Symbol("onDone"),Gn=Symbol("sawValidEntry"),Ms=Symbol("sawNullBlock"),Bs=Symbol("sawEOF"),yu=Symbol("closeStream"),Ew=()=>!0,Oi=class extends Um{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Wt]=[];[ge];[jt];[Un];[ut]="begin";[xn]="";[Dt];[gi];[hn]=!1;[Te];[pn]=!1;[Gn];[Ms]=!1;[Bs]=!1;[wr]=!1;[mi]=!1;[Ya]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Ns,()=>{(this[ut]==="begin"||this[Gn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Ns,t.ondone):this.on(Ns,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||yw,this.filter=typeof t.filter=="function"?t.filter:Ew;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[yu]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){io(this,t,e,r)}[_u](t,e){this[Gn]===void 0&&(this[Gn]=!1);let r;try{r=new $n(t,e,this[Dt],this[gi])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Ms]?(this[Bs]=!0,this[ut]==="begin"&&(this[ut]="header"),this[qn]("eof")):(this[Ms]=!0,this[qn]("nullBlock"));else if(this[Ms]=!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[Un]=new _w(r,this[Dt],this[gi]);if(!this[Gn])if(o.remain){let c=()=>{o.invalid||(this[Gn]=!0)};o.on("end",c)}else this[Gn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[qn]("ignoredEntry",o),this[ut]="ignore",o.resume()):o.size>0&&(this[xn]="",o.on("data",c=>this[xn]+=c),this[ut]="meta"):(this[Dt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[qn]("ignoredEntry",o),this[ut]=o.remain?"ignore":"header",o.resume()):(o.remain?this[ut]="body":(this[ut]="header",o.end()),this[jt]?this[Wt].push(o):(this[Wt].push(o),this[Xa]())))}}}[yu](){queueMicrotask(()=>this.emit("close"))}[gu](t){let e=!0;if(!t)this[jt]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[jt]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Xa]()),e=!1);return e}[Xa](){do;while(this[gu](this[Wt].shift()));if(this[Wt].length===0){let t=this[jt];!t||t.flowing||t.size===t.remain?this[wr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Qa](t,e){let r=this[Un];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[ut]="header",this[Un]=void 0,r.end()),o.length}[wu](t,e){let r=this[Un],i=this[Qa](t,e);return!this[Un]&&r&&this[mu](r),i}[qn](t,e,r){this[Wt].length===0&&!this[jt]?this.emit(t,e,r):this[Wt].push([t,e,r])}[mu](t){switch(this[qn]("meta",this[xn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Dt]=Xs.parse(this[xn],this[Dt],!1);break;case"GlobalExtendedHeader":this[gi]=Xs.parse(this[xn],this[gi],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Dt]??Object.create(null);this[Dt]=e,e.path=this[xn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Dt]||Object.create(null);this[Dt]=e,e.linkpath=this[xn].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[pn]=!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[pn])return r?.(),!1;if((this[Te]===void 0||this.brotli===void 0&&this[Te]===!1)&&t){if(this[ge]&&(t=Buffer.concat([this[ge],t]),this[ge]=void 0),t.length<bw)return this[ge]=t,r?.(),!0;for(let l=0;this[Te]===void 0&&l<fc.length;l++)t[l]!==fc[l]&&(this[Te]=!1);let o=!1;if(this[Te]===!1&&this.zstd!==!1){o=!0;for(let l=0;l<xc.length;l++)if(t[l]!==xc[l]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Te]===!1&&c)if(t.length<512)if(this[hn])this.brotli=!0;else return this[ge]=t,r?.(),!0;else try{new $n(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Te]===void 0||this[Te]===!1&&(this.brotli||o)){let l=this[hn];this[hn]=!1,this[Te]=this[Te]===void 0?new Km({}):o?new Jm({}):new Vm({}),this[Te].on("data",x=>this[Ps](x)),this[Te].on("error",x=>this.abort(x)),this[Te].on("end",()=>{this[hn]=!0,this[Ps]()}),this[wr]=!0;let u=!!this[Te][l?"end":"write"](t);return this[wr]=!1,r?.(),u}}this[wr]=!0,this[Te]?this[Te].write(t):this[Ps](t),this[wr]=!1;let i=this[Wt].length>0?!1:this[jt]?this[jt].flowing:!0;return!i&&this[Wt].length===0&&this[jt]?.once("drain",()=>this.emit("drain")),r?.(),i}[ec](t){t&&!this[pn]&&(this[ge]=this[ge]?Buffer.concat([this[ge],t]):t)}[Ls](){if(this[hn]&&!this[Ya]&&!this[pn]&&!this[mi]){this[Ya]=!0;let t=this[Un];if(t&&t.blockRemain){let e=this[ge]?this[ge].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[ge]&&t.write(this[ge]),t.end()}this[qn](Ns)}}[Ps](t){if(this[mi]&&t)this[ec](t);else if(!t&&!this[ge])this[Ls]();else if(t){if(this[mi]=!0,this[ge]){this[ec](t);let e=this[ge];this[ge]=void 0,this[Os](e)}else this[Os](t);for(;this[ge]&&this[ge]?.length>=512&&!this[pn]&&!this[Bs];){let e=this[ge];this[ge]=void 0,this[Os](e)}this[mi]=!1}(!this[ge]||this[hn])&&this[Ls]()}[Os](t){let e=0,r=t.length;for(;e+512<=r&&!this[pn]&&!this[Bs];)switch(this[ut]){case"begin":case"header":this[_u](t,e),e+=512;break;case"ignore":case"body":e+=this[Qa](t,e);break;case"meta":e+=this[wu](t,e);break;default:throw new Error("invalid state: "+this[ut])}e<r&&(this[ge]=this[ge]?Buffer.concat([t.subarray(e),this[ge]]):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[pn]||(this[Te]?(t&&this[Te].write(t),this[Te].end()):(this[hn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Ls]())),this}},Ii=t=>{let e=t.length-1,r=-1;for(;e>-1&&t.charAt(e)==="/";)r=e,e--;return r===-1?t:t.slice(0,r)},vw=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},tf=(t,e)=>{let r=new Map(e.map(c=>[Ii(c),!0])),i=t.filter,o=(c,l="")=>{let u=l||Pm(c).root||".",x;if(c===u)x=!1;else{let h=r.get(c);x=h!==void 0?h:o(km(c),u)}return r.set(c,x),x};t.filter=i?(c,l)=>i(c,l)&&o(Ii(c)):c=>o(Ii(c))},Sw=t=>{let e=new Oi(t),r=t.file,i;try{i=Sr.openSync(r,"r");let o=Sr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let l=Buffer.allocUnsafe(o.size),u=Sr.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=Sr.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{Sr.closeSync(i)}catch{}}},Aw=(t,e)=>{let r=new Oi(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("end",c),Sr.stat(o,(u,x)=>{if(u)l(u);else{let h=new kc(o,{readSize:i,size:x.size});h.on("error",l),h.pipe(r)}})})},Tr=Li(Sw,Aw,t=>new Oi(t),t=>new Oi(t),(t,e)=>{e?.length&&tf(t,e),t.noResume||vw(t)}),nf=(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:Cw,parse:Eu}=Iw,Nc=t=>{let e="",r=Eu(t);for(;Cw(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=Eu(t)}return[e,t]},so=["|","<",">","?",":"],Mc=so.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),Tw=new Map(so.map((t,e)=>[t,Mc[e]])),Rw=new Map(Mc.map((t,e)=>[t,so[e]])),vu=t=>so.reduce((e,r)=>e.split(r).join(Tw.get(r)),t),Dw=t=>Mc.reduce((e,r)=>e.split(r).join(Rw.get(r)),t),rf=(t,e)=>e?(t=Y(t).replace(/^\.(\/|$)/,""),Ii(e)+"/"+t):Y(t),kw=16*1024*1024,Su=Symbol("process"),Au=Symbol("file"),Iu=Symbol("directory"),hc=Symbol("symlink"),Cu=Symbol("hardlink"),wi=Symbol("header"),Hs=Symbol("read"),pc=Symbol("lstat"),js=Symbol("onlstat"),gc=Symbol("onread"),mc=Symbol("onreadlink"),wc=Symbol("openfile"),_c=Symbol("onopenfile"),yn=Symbol("close"),Qs=Symbol("mode"),yc=Symbol("awaitDrain"),tc=Symbol("ondrain"),Pt=Symbol("prefix"),sf=class extends Vn{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=Pc(e);super(),this.path=Y(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||kw,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]=Nc(this.path);c&&typeof l=="string"&&(this.path=l,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Dw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=Y(r.absolute||bu.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[js](o):this[pc]()}warn(t,e,r={}){return io(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[pc](){kt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[js](e)})}[js](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=Lw(t),this.emit("stat",t),this[Su]()}[Su](){switch(this.type){case"File":return this[Au]();case"Directory":return this[Iu]();case"SymbolicLink":return this[hc]();default:return this.end()}}[Qs](t){return nf(t,this.type==="Directory",this.portable)}[Pt](t){return rf(t,this.prefix)}[wi](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new $n({path:this[Pt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Pt](this.linkpath):this.linkpath,mode:this[Qs](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 Xs({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[Pt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Pt](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let t=this.header?.block;if(!t)throw new Error("failed to encode header");super.write(t)}[Iu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[wi](),this.end()}[hc](){kt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[mc](e)})}[mc](t){this.linkpath=Y(t),this[wi](),this.end()}[Cu](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=Y(bu.relative(this.cwd,t)),this.stat.size=0,this[wi](),this.end()}[Au](){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[Cu](e);this.linkCache.set(t,this.absolute)}if(this[wi](),this.stat.size===0)return this.end();this[wc]()}[wc](){kt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[_c](e)})}[_c](t){if(this.fd=t,this.#e)return this[yn]();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[Hs]()}[Hs](){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");kt.read(t,e,r,i,o,(c,l)=>{if(c)return this[yn](()=>this.emit("error",c));this[gc](l)})}[yn](t=()=>{}){this.fd!==void 0&&kt.close(this.fd,t)}[gc](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[yn](()=>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[yn](()=>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[tc]():this[yc](()=>this[tc]())}[yc](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)}[tc](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[yn](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[Hs]()}},Pw=class extends sf{sync=!0;[pc](){this[js](kt.lstatSync(this.absolute))}[hc](){this[mc](kt.readlinkSync(this.absolute))}[wc](){this[_c](kt.openSync(this.absolute,"r"))}[Hs](){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=kt.readSync(e,r,i,o,c);this[gc](l),t=!1}finally{if(t)try{this[yn](()=>{})}catch{}}}[yc](t){t()}[yn](t=()=>{}){this.fd!==void 0&&kt.closeSync(this.fd),t()}},Ow=class extends Vn{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 io(this,t,e,r)}constructor(t,e={}){let r=Pc(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[Qs](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]=Nc(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 $n({path:this[Pt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Pt](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 Xs({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[Pt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Pt](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)}[Pt](t){return rf(t,this.prefix)}[Qs](t){return nf(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}},Lw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",Nw=class Ar{tail;head;length=0;static create(e=[]){return new Ar(e)}constructor(e=[]){for(let r of e)this.push(r)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let r=e.next,i=e.prev;return r&&(r.prev=i),i&&(i.next=r),e===this.head&&(this.head=r),e===this.tail&&(this.tail=i),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,r}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let r=this.head;e.list=this,e.next=r,r&&(r.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let r=this.tail;e.list=this,e.prev=r,r&&(r.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let r=0,i=e.length;r<i;r++)Bw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)zw(this,e[r]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,r=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,r.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,r=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,r.list=void 0,this.length--,e}forEach(e,r){r=r||this;for(let i=this.head,o=0;i;o++)e.call(r,i.value,o,this),i=i.next}forEachReverse(e,r){r=r||this;for(let i=this.tail,o=this.length-1;i;o--)e.call(r,i.value,o,this),i=i.prev}get(e){let r=0,i=this.head;for(;i&&r<e;r++)i=i.next;if(r===e&&i)return i.value}getReverse(e){let r=0,i=this.tail;for(;i&&r<e;r++)i=i.prev;if(r===e&&i)return i.value}map(e,r){r=r||this;let i=new Ar;for(let o=this.head;o;)i.push(e.call(r,o.value,this)),o=o.next;return i}mapReverse(e,r){r=r||this;var i=new Ar;for(let o=this.tail;o;)i.push(e.call(r,o.value,this)),o=o.prev;return i}reduce(e,r){let i,o=this.head;if(arguments.length>1)i=r;else if(this.head)o=this.head.next,i=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var c=0;o;c++)i=e(i,o.value,c),o=o.next;return i}reduceReverse(e,r){let i,o=this.tail;if(arguments.length>1)i=r;else if(this.tail)o=this.tail.prev,i=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let c=this.length-1;o;c--)i=e(i,o.value,c),o=o.prev;return i}toArray(){let e=new Array(this.length);for(let r=0,i=this.head;i;r++)e[r]=i.value,i=i.next;return e}toArrayReverse(){let e=new Array(this.length);for(let r=0,i=this.tail;i;r++)e[r]=i.value,i=i.prev;return e}slice(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new Ar;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.head,c=0;for(c=0;o&&c<e;c++)o=o.next;for(;o&&c<r;c++,o=o.next)i.push(o.value);return i}sliceReverse(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new Ar;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.length,c=this.tail;for(;c&&o>r;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,r=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let 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=Mw(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 Mw(t,e,r){let i=e,o=e?e.next:t.head,c=new Bc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function Bw(t,e){t.tail=new Bc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function zw(t,e){t.head=new Bc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Bc=class{list;next;prev;value;constructor(t,e,r,i){this.list=i,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,r?(r.prev=this,this.next=r):this.next=void 0}},Ru=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Du=Buffer.alloc(1024),Ws=Symbol("onStat"),_i=Symbol("ended"),wt=Symbol("queue"),yi=Symbol("pendingLinks"),gn=Symbol("current"),Hn=Symbol("process"),bi=Symbol("processing"),zs=Symbol("processJob"),_t=Symbol("jobs"),nc=Symbol("jobDone"),Ks=Symbol("addFSEntry"),ku=Symbol("addTarEntry"),bc=Symbol("stat"),Ec=Symbol("readdir"),$s=Symbol("onreaddir"),Vs=Symbol("pipe"),Pu=Symbol("entry"),rc=Symbol("entryOpt"),Zs=Symbol("writeEntryClass"),of=Symbol("write"),ic=Symbol("ondrain"),oo=class extends Vn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Zs];onWriteEntry;[wt];[yi]=new Map;[_t]=0;[bi]=!1;[_i]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=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[Zs]=sf,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 Wm(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new $m(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new Zm(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[ic]()),this.on("resume",()=>e.resume())}else this.on("drain",this[ic]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[wt]=new Nw,this[_t]=0,this.jobs=Number(t.jobs)||4,this[bi]=!1,this[_i]=!1}[of](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&this.add(t),this[_i]=!0,this[Hn](),r&&r(),this}write(t){if(this[_i])throw new Error("write after end");return typeof t=="string"?this[Ks](t):this[ku](t),this.flowing}[ku](t){let e=Y(Tu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Ru(t.path,e);r.entry=new Ow(t,this[rc](r)),r.entry.on("end",()=>this[nc](r)),this[_t]+=1,this[wt].push(r)}this[Hn]()}[Ks](t){let e=Y(Tu.resolve(this.cwd,t));this[wt].push(new Ru(t,e)),this[Hn]()}[bc](t){t.pending=!0,this[_t]+=1;let e=this.follow?"stat":"lstat";Ys[e](t.absolute,(r,i)=>{t.pending=!1,this[_t]-=1,r?this.emit("error",r):this[Ws](t,i)})}[Ws](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[gn])this[zs](t);else{let r=`${e.dev}:${e.ino}`,i=this[yi].get(r);i?i.push(t):this[yi].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Hn]()}[Ec](t){t.pending=!0,this[_t]+=1,Ys.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[_t]-=1,e)return this.emit("error",e);this[$s](t,r)})}[$s](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Hn]()}[Hn](){if(!this[bi]){this[bi]=!0;for(let t=this[wt].head;t&&this[_t]<this.jobs;t=t.next)if(this[zs](t.value),t.value.ignore){let e=t.next;this[wt].removeNode(t),t.next=e}this[bi]=!1,this[_i]&&this[wt].length===0&&this[_t]===0&&(this.zip?this.zip.end(Du):(super.write(Du),super.end()))}}get[gn](){return this[wt]&&this[wt].head&&this[wt].head.value}[nc](t){this[wt].shift(),this[_t]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[yi].get(r);if(i){this[yi].delete(r);for(let o of i)o.pending=!1,this[zs](o)}}this[Hn]()}[zs](t){if(t.pending&&t.pendingLink&&t===this[gn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[gn]&&!t.piped&&this[Vs](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Ws](t,e):this[bc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[$s](t,e):this[Ec](t),!t.readdir)return}if(t.entry=this[Pu](t),!t.entry){t.ignore=!0;return}t===this[gn]&&!t.piped&&this[Vs](t)}}}[rc](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}}[Pu](t){this[_t]+=1;try{return new this[Zs](t.path,this[rc](t)).on("end",()=>this[nc](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[ic](){this[gn]&&this[gn].entry&&this[gn].entry.resume()}[Vs](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={}){io(this,t,e,r)}},zc=class extends oo{sync=!0;constructor(t){super(t),this[Zs]=Pw}pause(){}resume(){}[bc](t){let e=this.follow?"statSync":"lstatSync";this[Ws](t,Ys[e](t.absolute))}[Ec](t){this[$s](t,Ys.readdirSync(t.absolute))}[Vs](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[of](i)})}},Fw=(t,e)=>{let r=new zc(t),i=new Ku(t.file,{mode:t.mode||438});r.pipe(i),af(r,e)},Uw=(t,e)=>{let r=new oo(t),i=new no(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 cf(r,e).catch(c=>r.emit("error",c)),o},af=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Tr({file:$u.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},cf=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Tr({file:$u.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},qw=(t,e)=>{let r=new zc(t);return af(r,e),r},Gw=(t,e)=>{let r=new oo(t);return cf(r,e).catch(i=>r.emit("error",i)),r},pA=Li(Fw,Uw,qw,Gw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),jw=process.env.__FAKE_PLATFORM__||process.platform,ff=jw==="win32",{O_CREAT:xf,O_NOFOLLOW:Ou,O_TRUNC:hf,O_WRONLY:pf}=uf.constants,gf=Number(process.env.__FAKE_FS_O_FILENAME__)||uf.constants.UV_FS_O_FILEMAP||0,Ww=ff&&!!gf,Kw=512*1024,$w=gf|hf|xf|pf,Lu=!ff&&typeof Ou=="number"?Ou|hf|xf|pf:null,mf=Lu!==null?()=>Lu:Ww?t=>t<Kw?$w:"w":()=>"w",vc=(t,e,r)=>{try{return ao.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},eo=(t,e,r,i)=>{ao.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},Vw=(t,e,r,i,o)=>{if(e.isDirectory())wf(Ci.resolve(t,e.name),r,i,c=>{if(c)return o(c);let l=Ci.resolve(t,e.name);eo(l,r,i,o)});else{let c=Ci.resolve(t,e.name);eo(c,r,i,o)}},wf=(t,e,r,i)=>{ao.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 eo(t,e,r,i);let l=c.length,u=null,x=h=>{if(!u){if(h)return i(u=h);if(--l===0)return eo(t,e,r,i)}};for(let h of c)Vw(t,h,e,r,x)})},Zw=(t,e,r,i)=>{e.isDirectory()&&_f(Ci.resolve(t,e.name),r,i),vc(Ci.resolve(t,e.name),r,i)},_f=(t,e,r)=>{let i;try{i=ao.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return vc(t,e,r);throw c}for(let o of i)Zw(t,o,e,r);return vc(t,e,r)},yf=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"}},co=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"}},Xw=(t,e)=>{ct.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new yf(t,r?.code||"ENOTDIR")),e(r)})},Yw=(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),h=e.preserve,m=e.unlink,E=Y(e.cwd),S=(v,A)=>{v?r(v):A&&x?wf(A,l,u,I=>S(I)):c?ct.chmod(t,o,r):r()};if(t===E)return Xw(t,S);if(h)return Jw.mkdir(t,{mode:o,recursive:!0}).then(v=>S(null,v??void 0),S);let _=Y(to.relative(E,t)).split("/");Sc(E,_,o,m,E,void 0,S)},Sc=(t,e,r,i,o,c,l)=>{if(e.length===0)return l(null,c);let u=e.shift(),x=Y(to.resolve(t+"/"+u));ct.mkdir(x,r,bf(x,e,r,i,o,c,l))},bf=(t,e,r,i,o,c,l)=>u=>{u?ct.lstat(t,(x,h)=>{if(x)x.path=x.path&&Y(x.path),l(x);else if(h.isDirectory())Sc(t,e,r,i,o,c,l);else if(i)ct.unlink(t,m=>{if(m)return l(m);ct.mkdir(t,r,bf(t,e,r,i,o,c,l))});else{if(h.isSymbolicLink())return l(new co(t,t+"/"+e.join("/")));l(u)}}):(c=c||t,Sc(t,e,r,i,o,c,l))},Qw=t=>{let e=!1,r;try{e=ct.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new yf(t,r??"ENOTDIR")}},e_=(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,h=e.unlink,m=Y(e.cwd),E=v=>{v&&u&&_f(v,c,l),o&&ct.chmodSync(t,i)};if(t===m)return Qw(m),E();if(x)return E(ct.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=Y(to.relative(m,t)).split("/"),_;for(let v=S.shift(),A=m;v&&(A+="/"+v);v=S.shift()){A=Y(to.resolve(A));try{ct.mkdirSync(A,i),_=_||A}catch{let I=ct.lstatSync(A);if(I.isDirectory())continue;if(h){ct.unlinkSync(A),ct.mkdirSync(A,i),_=_||A;continue}else if(I.isSymbolicLink())return new co(A,A+"/"+S.join("/"))}}return E(_)},sc=Object.create(null),Nu=1e4,_r=new Set,t_=t=>{_r.has(t)?_r.delete(t):sc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),_r.add(t);let e=sc[t],r=_r.size-Nu;if(r>Nu/10){for(let i of _r)if(_r.delete(i),delete sc[i],--r<=0)break}return e},n_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,r_=n_==="win32",i_=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=Ef(i,r)),e.push(r||"/"),e},[]),s_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=r_?["win32 parallelization disabled"]:t.map(i=>Ii(Ef(t_(i))));let r=new Set(t.map(i=>i_(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}},o_=()=>process.umask(),Mu=Symbol("onEntry"),Ac=Symbol("checkFs"),Bu=Symbol("checkFs2"),Ic=Symbol("isReusable"),ft=Symbol("makeFs"),Cc=Symbol("file"),Tc=Symbol("directory"),Js=Symbol("link"),zu=Symbol("symlink"),Fu=Symbol("hardlink"),Si=Symbol("ensureNoSymlink"),Uu=Symbol("unsupported"),qu=Symbol("checkPath"),oc=Symbol("stripAbsolutePath"),bn=Symbol("mkdir"),He=Symbol("onError"),Fs=Symbol("pending"),Gu=Symbol("pend"),yr=Symbol("unpend"),ac=Symbol("ended"),cc=Symbol("maybeClose"),Rc=Symbol("skip"),Ti=Symbol("doChown"),Ri=Symbol("uid"),Di=Symbol("gid"),ki=Symbol("checkedCwd"),a_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Pi=a_==="win32",c_=1024,d_=(t,e)=>{if(!Pi)return ie.unlink(t,e);let r=t+".DELETE."+lf(16).toString("hex");ie.rename(t,r,i=>{if(i)return e(i);ie.unlink(r,e)})},l_=t=>{if(!Pi)return ie.unlinkSync(t);let e=t+".DELETE."+lf(16).toString("hex");ie.renameSync(t,e),ie.unlinkSync(e)},Hu=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Fc=class extends Oi{[ac]=!1;[ki]=!1;[Fs]=0;reservations=new s_;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(t={}){if(t.ondone=()=>{this[ac]=!0,this[cc]()},super(t),this.transform=t.transform,this.chmod=!!t.chmod,typeof t.uid=="number"||typeof t.gid=="number"){if(typeof t.uid!="number"||typeof t.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(t.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=t.uid,this.gid=t.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;this.preserveOwner=t.preserveOwner===void 0&&typeof t.uid!="number"?!!(process.getuid&&process.getuid()===0):!!t.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:c_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Pi,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=Y(Me.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:o_():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[Mu](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[cc](){this[ac]&&this[Fs]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[oc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Nc(r),l=c.replaceAll(/\\/g,"/").split("/");if(l.includes("..")||Pi&&/^[a-z]:\.\.$/i.test(l[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let u=Me.posix.dirname(t.path),x=Me.posix.normalize(Me.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}[qu](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[oc](t,"path")||!this[oc](t,"linkpath"))return!1;if(t.absolute=Me.isAbsolute(t.path)?Y(Me.resolve(t.path)):Y(Me.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}=Me.win32.parse(String(t.absolute));t.absolute=i+vu(String(t.absolute).slice(i.length));let{root:o}=Me.win32.parse(t.path);t.path=o+vu(t.path.slice(o.length))}return!0}[Mu](t){if(!this[qu](t))return t.resume();switch(Hw.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[Ac](t);default:return this[Uu](t)}}[He](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[yr](),e.resume())}[bn](t,e,r){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},r)}[Ti](t){return this.forceChown||this.preserveOwner&&(typeof t.uid=="number"&&t.uid!==this.processUid||typeof t.gid=="number"&&t.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[Ri](t){return Hu(this.uid,t.uid,this.processUid)}[Di](t){return Hu(this.gid,t.gid,this.processGid)}[Cc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new no(String(t.absolute),{flags:mf(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&ie.close(i.fd,()=>{}),i.write=()=>!0,this[He](u,t),e()});let o=1,c=u=>{if(u){i.fd&&ie.close(i.fd,()=>{}),this[He](u,t),e();return}--o===0&&i.fd!==void 0&&ie.close(i.fd,x=>{x?this[He](x,t):this[yr](),e()})};i.on("finish",()=>{let u=String(t.absolute),x=i.fd;if(typeof x=="number"&&t.mtime&&!this.noMtime){o++;let h=t.atime||new Date,m=t.mtime;ie.futimes(x,h,m,E=>E?ie.utimes(u,h,m,S=>c(S&&E)):c())}if(typeof x=="number"&&this[Ti](t)){o++;let h=this[Ri](t),m=this[Di](t);typeof h=="number"&&typeof m=="number"&&ie.fchown(x,h,m,E=>E?ie.chown(u,h,m,S=>c(S&&E)):c())}c()});let l=this.transform&&this.transform(t)||t;l!==t&&(l.on("error",u=>{this[He](u,t),e()}),t.pipe(l)),l.pipe(i)}[Tc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[bn](String(t.absolute),r,i=>{if(i){this[He](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[yr](),t.resume())};t.mtime&&!this.noMtime&&(o++,ie.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[Ti](t)&&(o++,ie.chown(String(t.absolute),Number(this[Ri](t)),Number(this[Di](t)),c)),c()})}[Uu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[zu](t,e){let r=Y(Me.relative(this.cwd,Me.resolve(Me.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[Si](t,this.cwd,r,()=>this[Js](t,String(t.linkpath),"symlink",e),i=>{this[He](i,t),e()})}[Fu](t,e){let r=Y(Me.resolve(this.cwd,String(t.linkpath))),i=Y(String(t.linkpath)).split("/");this[Si](t,this.cwd,i,()=>this[Js](t,r,"link",e),o=>{this[He](o,t),e()})}[Si](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let l=Me.resolve(e,c);ie.lstat(l,(u,x)=>{if(u)return i();if(x?.isSymbolicLink())return o(new co(l,Me.resolve(l,r.join("/"))));this[Si](t,l,r,i,o)})}[Gu](){this[Fs]++}[yr](){this[Fs]--,this[cc]()}[Rc](t){this[yr](),t.resume()}[Ic](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Pi}[Ac](t){this[Gu]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Bu](t,r))}[Bu](t,e){let r=l=>{e(l)},i=()=>{this[bn](this.cwd,this.dmode,l=>{if(l){this[He](l,t),r();return}this[ki]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let l=Y(Me.dirname(String(t.absolute)));if(l!==this.cwd)return this[bn](l,this.dmode,u=>{if(u){this[He](u,t),r();return}c()})}c()},c=()=>{ie.lstat(String(t.absolute),(l,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Rc](t),r();return}if(l||this[Ic](t,u))return this[ft](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let x=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,h=m=>this[ft](m??null,t,r);return x?ie.chmod(String(t.absolute),Number(t.mode),h):h()}if(t.absolute!==this.cwd)return ie.rmdir(String(t.absolute),x=>this[ft](x??null,t,r))}if(t.absolute===this.cwd)return this[ft](null,t,r);d_(String(t.absolute),x=>this[ft](x??null,t,r))})};this[ki]?o():i()}[ft](t,e,r){if(t){this[He](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[Cc](e,r);case"Link":return this[Fu](e,r);case"SymbolicLink":return this[zu](e,r);case"Directory":case"GNUDumpDir":return this[Tc](e,r)}}[Js](t,e,r,i){ie[r](e,String(t.absolute),o=>{o?this[He](o,t):(this[yr](),t.resume()),i()})}},Ei=t=>{try{return[null,t()]}catch(e){return[e,null]}},vf=class extends Fc{sync=!0;[ft](t,e){return super[ft](t,e,()=>{})}[Ac](t){if(!this[ki]){let o=this[bn](this.cwd,this.dmode);if(o)return this[He](o,t);this[ki]=!0}if(t.absolute!==this.cwd){let o=Y(Me.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[bn](o,this.dmode);if(c)return this[He](c,t)}}let[e,r]=Ei(()=>ie.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Rc](t);if(e||this[Ic](t,r))return this[ft](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[l]=c?Ei(()=>{ie.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ft](l,t)}let[o]=Ei(()=>ie.rmdirSync(String(t.absolute)));this[ft](o,t)}let[i]=t.absolute===this.cwd?[]:Ei(()=>l_(String(t.absolute)));this[ft](i,t)}[Cc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=l=>{let u;try{ie.closeSync(o)}catch(x){u=x}(l||u)&&this[He](l||u,t),e()},o;try{o=ie.openSync(String(t.absolute),mf(t.size),r)}catch(l){return i(l)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",l=>this[He](l,t)),t.pipe(c)),c.on("data",l=>{try{ie.writeSync(o,l,0,l.length)}catch(u){i(u)}}),c.on("end",()=>{let l=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,x=t.mtime;try{ie.futimesSync(o,u,x)}catch(h){try{ie.utimesSync(String(t.absolute),u,x)}catch{l=h}}}if(this[Ti](t)){let u=this[Ri](t),x=this[Di](t);try{ie.fchownSync(o,Number(u),Number(x))}catch(h){try{ie.chownSync(String(t.absolute),Number(u),Number(x))}catch{l=l||h}}}i(l)})}[Tc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[bn](String(t.absolute),r);if(i){this[He](i,t),e();return}if(t.mtime&&!this.noMtime)try{ie.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[Ti](t))try{ie.chownSync(String(t.absolute),Number(this[Ri](t)),Number(this[Di](t)))}catch{}e(),t.resume()}[bn](t,e){try{return e_(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}}[Si](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let l of r){c=Me.resolve(c,l);let[u,x]=Ei(()=>ie.lstatSync(c));if(u)return i();if(x.isSymbolicLink())return o(new co(c,Me.resolve(e,r.join("/"))))}i()}[Js](t,e,r,i){let o=`${r}Sync`;try{ie[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[He](c,t)}}},u_=t=>{let e=new vf(t),r=t.file,i=df.statSync(r),o=t.maxReadSize||16*1024*1024;new Dm(r,{readSize:o,size:i.size}).pipe(e)},f_=(t,e)=>{let r=new Fc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("close",c),df.stat(o,(u,x)=>{if(u)l(u);else{let h=new kc(o,{readSize:i,size:x.size});h.on("error",l),h.pipe(r)}})})},Sf=Li(u_,f_,t=>new vf(t),t=>new Fc(t),(t,e)=>{e?.length&&tf(t,e)}),x_=(t,e)=>{let r=new zc(t),i=!0,o,c;try{try{o=at.openSync(t.file,"r+")}catch(x){if(x?.code==="ENOENT")o=at.openSync(t.file,"w+");else throw x}let l=at.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<l.size;c+=512){for(let m=0,E=0;m<512;m+=E){if(E=at.readSync(o,u,m,u.length-m,c+m),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!E)break e}let x=new $n(u);if(!x.cksumValid)break;let h=512*Math.ceil((x.size||0)/512);if(c+h+512>l.size)break;c+=h,t.mtimeCache&&x.mtime&&t.mtimeCache.set(String(x.path),x.mtime)}i=!1,h_(t,r,c,o,e)}finally{if(i)try{at.closeSync(o)}catch{}}},h_=(t,e,r,i,o)=>{let c=new Ku(t.file,{fd:i,start:r});e.pipe(c),g_(e,o)},p_=(t,e)=>{e=Array.from(e);let r=new oo(t),i=(o,c,l)=>{let u=(S,_)=>{S?at.close(o,v=>l(S)):l(null,_)},x=0;if(c===0)return u(null,0);let h=0,m=Buffer.alloc(512),E=(S,_)=>{if(S||_===void 0)return u(S);if(h+=_,h<512&&_)return at.read(o,m,h,m.length-h,x+h,E);if(x===0&&m[0]===31&&m[1]===139)return u(new Error("cannot append to compressed archives"));if(h<512)return u(null,x);let v=new $n(m);if(!v.cksumValid)return u(null,x);let A=512*Math.ceil((v.size??0)/512);if(x+A+512>c||(x+=A+512,x>=c))return u(null,x);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),h=0,at.read(o,m,0,512,x,E)};at.read(o,m,0,512,x,E)};return new Promise((o,c)=>{r.on("error",c);let l="r+",u=(x,h)=>{if(x&&x.code==="ENOENT"&&l==="r+")return l="w+",at.open(t.file,l,u);if(x||!h)return c(x);at.fstat(h,(m,E)=>{if(m)return at.close(h,()=>c(m));i(h,E.size,(S,_)=>{if(S)return c(S);let v=new no(t.file,{fd:h,start:_});r.pipe(v),v.on("error",c),v.on("close",o),m_(r,e)})})};at.open(t.file,l,u)})},g_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Tr({file:Af.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},m_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Tr({file:Af.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},vi=Li(x_,p_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!zm(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")}),DA=Li(vi.syncFile,vi.asyncFile,vi.syncNoFile,vi.asyncNoFile,(t,e=[])=>{vi.validate?.(t,e),w_(t)}),w_=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))};ln();var Et={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",UPGRADE:"_agent/upgrade",DELETE:"_agent/delete"};function lo(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function If(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function uo(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Cf(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function Tf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function Rr(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Vt();Ze();re();Le();Ze();function Sn(t,e){if(lo(t)!=="cloud")throw new T("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Ni(t){return t.startsWith("http://")||t.startsWith("https://")}function fo(t){return t.endsWith("/")?t.slice(0,-1):t}Ze();re();var xo="1008033",Pf="1289";var Of="pbbp2",Lf="https://www.coze.cn",Nf="/api/coze_claw/resource/get_frontier_key",I_="https://www.coze.cn",C_="wss://frontier.coze.cn";function ho(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??I_}function Mf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??C_}function Dr(t){let e={},r=t?.ttEnv??process.env.COZE_BRIDGE_TT_ENV,i=t?.usePpe??process.env.COZE_BRIDGE_USE_PPE;return r&&(e["x-tt-env"]=r),i&&(e["x-use-ppe"]=i),e}function Bi(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Mi=H("handshake");async function Uc(t){let e=ho(t.endpoint),r=t.timeoutMs??1e4,i=`${fo(e)}${Nf}?aid=${encodeURIComponent(xo)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...Dr(t.ppeOverride)},c=new AbortController,l=setTimeout(()=>c.abort(),r);Mi.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),x=u.headers.get("x-tt-logid")??"",h=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let v=await u.text().catch(()=>"");throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${x}: ${v.slice(0,200)}`)}let m=await u.json();if(m.code!==void 0&&m.code!==0)throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${m.code} msg=${m.msg??"-"} logid=${x}`);let E=m.data??{},S=typeof E.access_key=="string"&&E.access_key||typeof E.accessKey=="string"&&E.accessKey||void 0,_=typeof E.device_id=="string"&&E.device_id||typeof E.deviceId=="string"&&E.deviceId||void 0;if(!S||!_){let v=JSON.stringify(m).slice(0,500);throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${x}: ${v}`)}return Mi.info("handshake ok",{remoteDeviceId:_,logid:x,traceId:h}),{accessKey:S,deviceId:_}}catch(u){if(u instanceof T)throw Mi.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Mi.warn("handshake timeout",{base:e,timeoutMs:r}),new T("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let x=u.cause;throw Mi.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:x?.code,syscall:x?.syscall,cause:String(u).slice(0,300)}),new T("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(l)}}var qc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",vt="auto",Bf=15e4;function zf(t){return{model:Gc(t.model)??vt,...t.modelToken?{modelToken:t.modelToken}:{}}}function T_(t){return!t||t===vt}var R_=new Set(["auto","\u81EA\u52A8"]);function Gc(t){let e=t?.trim();if(e)return R_.has(e.toLowerCase())?vt:e}function Ff(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=qc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||vt;e.ANTHROPIC_MODEL=r,e.ANTHROPIC_SMALL_FAST_MODEL=r,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=r,e.ANTHROPIC_DEFAULT_OPUS_MODEL=r,e.ANTHROPIC_DEFAULT_SONNET_MODEL=r,e.CLAUDE_CODE_SUBAGENT_MODEL=r,e.CLAUDE_CODE_ATTRIBUTION_HEADER="0",t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else T_(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Uf(t,e,r){return t.modelToken?{baseUrl:`${qc}/v1`,providerName:"coze",headers:{Authorization:`Bearer ${t.modelToken}`,...Hc(e,r)}}:null}function qf(t){if(!t.modelToken)return{};let e={model:t.model||vt,model_context_window:t.modelInfo?.contextWindow??Bf};return{CODEX_CONFIG:JSON.stringify(e)}}function Hc(t,e){let{ttEnv:r,usePpe:i}=Bi(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Gf(t,e,r){if(!t.modelToken)return{};let i=Hc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,l])=>`${c}:${l}`).join(`
92
- `)}}function jc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function Hf(t,e,r){if(!t.modelToken)return null;let i=t.model||vt,o=Hc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let l={baseUrl:`${qc}/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??Bf,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(l.headers=o),l}var Ae=H("agent-handlers"),jf=5*1024*1024,N_=1,M_=6,B_=new Set(["node_modules",".git",".coze","dist","build",".next"]),z_=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,F_=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,U_=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function q_(t){let e=t?.trim();return e?U_.test(e)||F_.test(e)?e:(Ae.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function G_(t){return new Promise((e,r)=>{let i=st("npx",t,{detached:!0,stdio:"ignore",windowsHide:!0}),o=!1,c=l=>{o||(o=!0,l?r(l):e(i.pid??0))};i.once("spawn",()=>{i.unref(),c()}),i.once("error",l=>c(l))})}var po=class{constructor(e){this.opts=e}opts;async listSkills(e){Sn(e._meta,"_agent/listSkills");let r=Rr(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??nt(r).workspace,c=i?.skills??[],l=[];for(let u of c){let x=Lt(o,u.relPath,"SKILL.md");await P_(x).then(m=>m.isFile()).catch(()=>!1)&&l.push($_(u))}return{skills:l}}async addSkills(e){let r=Rr(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],l=new Map(c.map((x,h)=>[x.skillId,h])),u=[];for(let x of o){let h=await Xc({agentId:r,workspace:i.workspace,framework:i.framework,skill:x});Yc(c,l,h),u.push(x)}return await ws(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){Sn(e._meta,"_agent/removeSkills");let r=Rr(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=Lt(i.workspace,u.relPath);await k_(x,{recursive:!0,force:!0}),Ae.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await ws(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,Ae.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,Ae.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l}),x.stop(r).catch(h=>Ae.warn("downstream stop failed during reload (ignored)",{reason:r,agentId:e,cloudId:o,err:String(h)}))}}isRuntimePendingPermission(e){let r=this.opts.isRuntimePendingPermission;return!r||!e.downstream?!1:r(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return Ae.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await Fe(r);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Ae.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await fr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Ae.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new T("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await rt(i),Ae.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async upgradeBridge(e){let r=e.agentId||e._meta?.cozeAgentId;if(!r)throw new T("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await Fe(r))throw new T("AGENT_NOT_FOUND",`agent not found: ${r}`);let o=["-y"];e.registry&&Ni(e.registry)&&o.push(`--registry=${e.registry}`);let c=q_(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let l=e._meta?.cozeEnv;l&&z_.test(l)&&o.push("--env",l);let u=await G_(o);return Ae.info("_agent/upgrade: spawned bridge upgrade process",{agentId:r,pid:u,targetVersion:c,currentVersion:e.currentVersion??"",reason:e.reason??""}),{ok:!0,accepted:!0,pid:u,message:"bridge upgrade started"}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new T("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Fe(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await rt(i),Ae.info("agent disconnected",{agentId:r,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(r,e.reason??"disconnect"),{ok:!0}):(Ae.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(Sn(e._meta,"_agent/switchModel"),!e.agentId)throw new T("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Gc(e.model)??vt,i=await Fe(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 rt(i),Ae.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Ae.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};o.model=r,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o).catch(l=>Ae.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),Ae.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:r,cloudSessions:c.length}),{ok:!0}}async resetAgent(e){if(Sn(e._meta,Et.RESET),!e.agentId)throw new T("IPC_BAD_REQUEST",`${Et.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,Et.RESET),await this.runDetailSync(e.agentId,Et.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),Ae.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(r);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,l]of i.sessions)o.set(c,{modelToken:l.modelToken,tokenGeneratedAt:l.tokenGeneratedAt});await ci(e,o)}async clearPersistedAcpSessionIds(e){let r=await Fe(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 rt(r)}async repairAgent(e){if(Sn(e._meta,Et.REPAIR),!e.agentId)throw new T("IPC_BAD_REQUEST",`${Et.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new T("IPC_BAD_REQUEST",`${Et.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){Ae.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,Et.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){Ae.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Ae.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){Sn(e._meta,"_agent/getFileTree");let r=e._meta,i=Rr(r),o=await this.resolveWorkspace(i),c=e.filePath??"",l=this.safeJoin(o,c),u=await Wc(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 ai(l,o))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let x=iy(e.depth);return u.isDirectory()?{tree:await ry(o,l,c,x)}:{tree:[{name:sy(c),path:Xf(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){Sn(e._meta,"_agent/getFileContent");let r=Rr(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 Wc(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 ai(o,i))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>jf)throw new T("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${jf})`);let l=await Wf(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 Fe(e).catch(()=>null))?.workspace??nt(e).workspace}safeJoin(e,r){let i=Vc(e,r||"."),o=Jc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Kf}`))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return Fe(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 H_(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 j_(t){return t==="claude-code"?Lt(".claude","skills"):Lt(".agents","skills")}var W_=3e4,K_=50*1024*1024,kr=3e4;async function Xc(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=H_(o.skillName),x=j_(i),h=Lt(x,u),m=Lt(r,h);if(await Kc(m,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");zi(S.length),await $c(Lt(m,"SKILL.md"),S,"utf8")}else{let S=await V_(o.downloadUrl);J_(S)?await ey(S,m):X_(S)?await Y_(S,m):await $c(Lt(m,"SKILL.md"),S.toString("utf8"),"utf8")}let E={skillId:o.skillId,skillName:o.skillName,relPath:h,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return Ae.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:h,source:c?"content":"downloadUrl"}),E}function Yc(t,e,r){let i=e.get(r.skillId);if(i!==void 0){t[i]=r;return}e.set(r.skillId,t.length),t.push(r)}function $_(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function V_(t){if(!t)throw new T("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);zi(e);let r=Z_(t);return zi(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await Wf(e);return zi(r.length),r}if(Ni(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),W_);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 zi(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 zi(t){if(t>K_)throw new T("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function Z_(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 J_(t){return t.length>=2&&t[0]===31&&t[1]===139}function X_(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 Y_(t,e){let r,i;try{r=new Zf.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||Zc(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new T("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(h=>h===".."))throw new T("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let x=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=Q_(i),c=Vc(e);for(let l of i){if(Zc(l.entryName))continue;let u=l.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let x=Vc(e,u),h=Jc(c,x);if(h.startsWith("..")||h==="..")throw new T("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(l.isDirectory){await Kc(x,{recursive:!0});continue}await Kc(O_(x),{recursive:!0});let m;try{m=l.getData()}catch(E){throw new T("IPC_BAD_REQUEST",`zip entry getData failed (${l.entryName}): ${E.message}`,{cause:E})}await $c(x,m)}}function Q_(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 ey(t,e){await ty(t);let r=Sf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar extract timeout (${kr}ms)`))},kr);try{await Vf($f.from(t),r)}catch(c){throw c instanceof T?c:i?new T("IPC_BAD_REQUEST",`tar extract timeout (${kr}ms)`):new T("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function ty(t){let e=[],r=Tr({onReadEntry:c=>{let l=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' not allowed (symlink/hardlink/special): ${l.slice(0,100)}`);return}if(l.startsWith("/")||l.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(l)){e.push(`tar entry absolute path: ${l}`);return}l.split(/[/\\]/).some(h=>h==="..")&&e.push(`tar entry contains '..': ${l}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar list timeout (${kr}ms)`))},kr);try{await Vf($f.from(t),r)}catch(c){throw i?new T("IPC_BAD_REQUEST",`tar list timeout (${kr}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 ny=5e3;async function ry(t,e,r,i){return Jf(t,e,r,i,{count:0})}async function Jf(t,e,r,i,o){if(i<=0)return[];let c;try{c=await D_(e,{withFileTypes:!0})}catch{return[]}let l=[];for(let u of c){if(B_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=ny){l.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let x=Lt(e,u.name),h=L_(Lt(r,u.name)),m=null;try{m=await Wc(x)}catch{continue}if(m.isSymbolicLink())continue;o.count++;let E={name:u.name,path:Xf(Jc(t,x)),isDir:m.isDirectory(),size:m.size,modifiedAt:Math.floor(m.mtimeMs)};m.isDirectory()&&i>1&&(E.children=await Jf(t,x,h,i-1,o)),l.push(E)}return l.sort((u,x)=>u.isDir!==x.isDir?u.isDir?-1:1:u.name.localeCompare(x.name)),l}function iy(t){return!t||t<=0?N_:Math.min(t,M_)}function sy(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function Xf(t){return t.split(Kf).join("/")}re();import{readFileSync as WI}from"node:fs";import{dirname as $I,join as VI}from"node:path";import{fileURLToPath as JI}from"node:url";var Pr="0.1.104-alpha.21";var An=H("agent-health-reporter"),oy=1e4,Fi=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??oy}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()}),An.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),An.info("heartbeat stopped"))}async tick(){if(this.inFlight){An.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){An.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=ay(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:Pr,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(l){An.warn("heartbeat batch send failed",{count:r.length,err:String(l)})}let c=o?.authFailures;if(c&&c.length>0&&(An.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){An.warn("onAuthFailures callback failed (ignored)",{err:String(l)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){An.warn("onTickEnd hook failed",{err:String(r)})}}};function ay(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}ln();import{mkdir as id,rm as tb,stat as nb}from"node:fs/promises";import{homedir as rb}from"node:os";import{join as od}from"node:path";an();import{existsSync as yy}from"node:fs";import{release as by}from"node:os";import{basename as Ey,isAbsolute as vy}from"node:path";function Ui(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Or(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Lr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function In(t,e){return{jsonrpc:"2.0",id:t,error:e}}Ze();var go=class extends Error{code;data;constructor(e){super(`JSON-RPC error code=${e.code} ${e.message}`),this.name="RemoteRpcError",this.code=e.code,e.data!==void 0&&(this.data=e.data)}},ee={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32022};function Yf(t){return"method"in t&&"id"in t&&t.id!==void 0}function Qf(t){return"method"in t&&!("id"in t)}function mo(t){return!("method"in t)&&"id"in t}var cy={AGENT_NOT_FOUND:ee.AGENT_NOT_FOUND,AGENT_BUSY:ee.AGENT_BUSY,AGENT_DISCONNECTED:ee.AGENT_DISCONNECTED,AGENT_TIMEOUT:ee.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:ee.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:ee.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:ee.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:ee.INTERNAL_ERROR,BRIDGE_INTERNAL:ee.INTERNAL_ERROR,IPC_AUTH_FAILED:ee.INTERNAL_ERROR,IPC_BAD_REQUEST:ee.INVALID_REQUEST,METHOD_NOT_FOUND:ee.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:ee.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:ee.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:ee.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:ee.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:ee.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:ee.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:ee.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:ee.FILE_TOO_LARGE,UNSUPPORTED_MIME:ee.UNSUPPORTED_MIME,UPLOAD_FAILED:ee.UPLOAD_FAILED,UPSTREAM_NOT_READY:ee.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:ee.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:ee.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:ee.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:ee.AGENT_ENV_NOT_READY};function dy(t){if(t!=null)return t instanceof Error?{name:t.name,message:qi(t.message)}:typeof t=="string"?qi(t):typeof t=="object"?uy(t):t}var ly=[[/\/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 qi(t){let e=t;for(let[r,i]of ly)e=e.replace(r,i);return e}function uy(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=qi(i):e[r]=i;return e}function Gi(t){if(t instanceof T){let e=dy(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:cy[t.code]??ee.INTERNAL_ERROR,message:qi(t.message),data:r}}return{code:ee.INTERNAL_ERROR,message:qi(t instanceof Error?t.message:String(t))}}function e0(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 n0(t){return`${JSON.stringify(t)}
93
- `}var t0=10*1024*1024,wo=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>t0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${t0} 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 i0={"session/prompt":"session.prompt","session/cancel":"session.cancel","session/new":"session.new","session/load":"session.load","_agent/create":"agent.create","_agent/health":"agent.health","_agent/pair":"agent.pair","_agent/listSkills":"agent.listSkills","_agent/addSkills":"agent.addSkills","_agent/removeSkills":"agent.removeSkills","_agent/getFileTree":"agent.getFileTree","_agent/getFileContent":"agent.getFileContent","_agent/detail":"agent.detail","_agent/update":"agent.update","_agent/disconnect":"agent.disconnect","_agent/switchModel":"agent.switchModel","_agent/genModelToken":"agent.genModelToken","_agent/reset":"agent.reset","_agent/repair":"agent.repair","session/request_permission":"session.requestPermission","session/set_mode":"session.setMode",initialize:"initialize"},aC=Object.fromEntries(Object.entries(i0).map(([t,e])=>[e,t])),fy={"session.prompt":["agentId","triggerMsgId","sessionId"],"session.cancel":["agentId","triggerMsgId","sessionId"],"session.new":["agentId"],"session.load":["agentId"],"agent.create":["agentId"],"agent.health":[],"agent.listSkills":["agentId"],"agent.addSkills":["agentId"],"agent.removeSkills":["agentId"],"agent.getFileTree":["agentId"],"agent.getFileContent":["agentId"],"agent.detail":["agentId"],"agent.update":["agentId"],"agent.disconnect":["agentId"],"agent.switchModel":["agentId"],"agent.genModelToken":["agentId","sessionId"],"agent.reset":["agentId"],"agent.repair":["agentId"],"session.requestPermission":["agentId","sessionId"],"session.setMode":["agentId","sessionId"],"agent.pair":[],initialize:[]},Nr=class{seq=0;next(e,r){this.seq+=1;let i=i0[e]??xy(e),o=fy[i]??[],c=[i,String(this.seq)];if(o.length>0){let l=o.map(x=>r0(r?.[x]??"")),u=hy(l).join(":");u&&c.push(u)}else r&&Object.values(r).some(l=>l)&&c.push(Object.values(r).filter(Boolean).map(l=>r0(String(l))).join(":"));return c.join("_")}reset(){this.seq=0}};function xy(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function r0(t){return t.replace(/[:_\s]+/g,"-")}function hy(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}dn();import{readFileSync as py}from"node:fs";var gy=384;async function Qc(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await ur(t.agentEnvFile,r,{mode:gy})}function ed(t){try{let e=JSON.parse(py(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function s0(t,e,r={},i=o=>o){return{...i({...t,...ed(e)}),...r}}Vt();or();Ze();re();Le();import{execFileSync as my,spawnSync as wy}from"node:child_process";function Hi(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function ji(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),wy("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var td=new Set;function o0(t){typeof t=="number"&&t>0&&td.add(t)}function a0(t){typeof t=="number"&&td.delete(t)}function c0(){for(let t of td)ji(t,"SIGKILL")}var Mr="coze-bridge-daemon";function d0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return my("pgrep",["-U",String(o),"-f",Mr],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:2e3})}),r;try{r=e()}catch{return[]}let i=process.pid;return r.split(`
95
- `).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function l0(t,e){if(t.length===0)return;let r=e?.killFn??ji,i=e?.isAliveFn??Hi,o=e?.sleepFn??(u=>new Promise(x=>setTimeout(x,u))),c=e?.graceMs??3e3,l=e?.pollMs??100;for(let u of t)r(u,"SIGTERM");for(let u=0;u<c&&t.some(x=>i(x));u+=l)await o(Math.min(l,c-u));for(let u of t)i(u)&&r(u,"SIGKILL")}var _y=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: (Node binary not found|QCLAW_CLI_NODE_BINARY not set)/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @(zed-industries|agentclientprotocol)\/codex-acp|optional dependency was not installed|\.resolve is not a function/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"acp_module_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code","codex"],match:/Cannot find module[^\n]*node_modules[\\/]@(agentclientprotocol[\\/](claude-agent-acp|codex-acp)|zed-industries[\\/]codex-acp)/i,message:"ACP \u4F9D\u8D56\u672A\u6B63\u786E\u5B89\u88C5 (wrapper \u5165\u53E3\u7F3A\u5931)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u91CD\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"},{reason:"prompt_too_long",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code"],match:/Prompt is too long|bad request: failed to read body: length limit exceeded/i,message:"\u672C\u8F6E\u8F93\u5165\u8FC7\u957F\uFF0C\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u7CBE\u7B80\u8F93\u5165\u6216\u5F00\u542F\u65B0\u4F1A\u8BDD\u540E\u91CD\u8BD5"}];function u0(t,e){if(!e)return null;for(let r of _y)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function f0(t,e){return u0(t,e)}function x0(t,e){return u0(t,e)}function Br(t,e,r){return!e&&r.firstUpdateMs>0&&t<r.firstUpdateMs?Math.max(1,r.firstUpdateMs-t):t<r.phase2GateMs?Math.max(1,r.phase2GateMs-t):Math.max(1,r.livenessWindowMs)}function h0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let h=t.suspendedMs+o,m=r-t.startedAt-h;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Br(m,t.firstFrameSeen,e)}}let c=r-t.startedAt-t.suspendedMs,l=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=l?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Br(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Br(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Br(c,!1,e)}}var p0=Ve("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),Sy=200,Ay=40,Iy=Ve("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),Cy=Ve("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),Ty=Ve("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),Ry=Ve("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),Dy=Ve("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),ky=Ve("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),g0=500;function Py(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=g0?t:`${e.slice(0,g0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Oy(t){let e=[];typeof t.message=="string"&&e.push(t.message);let{data:r}=t;if(typeof r=="string")e.push(r);else if(r&&typeof r=="object")try{e.push(JSON.stringify(r))}catch{}return e.join(" ")}function m0(t){try{return yy(t)}catch{return}}function Ly(t,e){return{platform:process.platform,osRelease:by(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:vy(e.command)?m0(e.command):void 0,cwd:e.cwd,cwdExists:m0(e.cwd),envKeys:e.envKeys}}function Ny(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${Ey(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Nt=class{constructor(e){this.opts=e;this.log=H(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new wo({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Nr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;spawnEnv={};sanitizeEnv(e){return e}async start(){if(this.child)throw new T("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=s0(process.env,this.opts.agentEnvFile??Q().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o));this.spawnEnv=r;let i=st(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,o0(i.pid),i.stdout?.setEncoding("utf8"),i.stdout?.on("data",o=>{try{for(let c of this.decoder.push(o))this.dispatch(c)}catch(c){this.log.warn("stdout dispatch threw, swallowed to keep daemon alive",{err:String(c)})}}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",o=>{let c=o.trimEnd();this.stderrRing.push(c),this.stderrRing.length>Sy&&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,a0(i.pid),(o!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:c,recentStderr:[...this.stderrRing]});try{for(let u of this.decoder.flush())this.dispatch(u)}catch(u){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(u)})}this.failAllPending(this.buildExitError(o,c));for(let u of this.exitHandlers)u(o,c)}),i.on("error",o=>{let c=o,l=Ly(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",Ny(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()));ji(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||ji(r.pid,"SIGKILL")},5e3);try{await i}finally{clearTimeout(o)}}pid(){return this.child?.pid}isAlive(){return!!this.child&&!this.stopped}getStderrTail(e){return e===void 0?[...this.stderrRing]:this.stderrRing.slice(-e)}initialize(e){return this.call("initialize",e)}sessionNew(e){return this.call("session/new",{mcpServers:[],...e})}sessionLoad(e){return this.call("session/load",{mcpServers:[],...e})}sessionPrompt(e,r){let i={firstUpdateMs:Dy,phase2GateMs:Iy,livenessWindowMs:Cy,absoluteMaxMs:Ty,approvalMaxMs:ky,suspendThresholdMs:Ry,...r};return this.call("session/prompt",e,p0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Or("session/cancel",e))}setSessionMode(e){return this.call("session/set_mode",e)}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Lr(e,r))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(In(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=p0,o){if(!this.child||this.stopped)return Promise.reject(new T("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),l=Ui(c,e,r),u=(()=>{if(typeof r!="object"||r===null)return;let x=r.sessionId;return typeof x=="string"?x:void 0})();return new Promise((x,h)=>{let m={resolve:x,reject:h,timer:null,method:e,promptTimeout:null};if(o){let E=this.now(),S={cfg:o,startedAt:E,lastActivityAt:E,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:E,expectedIntervalMs:Br(0,!1,o),sessionId:u};m.promptTimeout=S;let _=()=>{let v={startedAt:S.startedAt,lastActivityAt:S.lastActivityAt,firstFrameSeen:S.firstFrameSeen,hasActiveTool:S.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:S.suspendedMs,armedAt:S.armedAt,expectedIntervalMs:S.expectedIntervalMs},A=this.now(),I=h0(v,S.cfg,A),D=O=>{S.armedAt=A,S.expectedIntervalMs=O,m.timer=setTimeout(_,O)};if(I.action==="suspend"){S.suspendedMs+=I.suspendedDeltaMs,S.lastActivityAt=A,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:I.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),D(I.rearmMs);return}if(I.action==="continue"){D(I.rearmMs);return}this.pending.delete(c),I.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:I.awaitingApproval,...S.sessionId?{sessionId:S.sessionId}:{}}),h(I.awaitingApproval?new T("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new T("AGENT_TIMEOUT",`${e} timed out after ${S.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...S.sessionId?{sessionId:S.sessionId}:{}}),h(new T("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};m.timer=setTimeout(_,S.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(m.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),h(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,m);try{this.writeFrame(l)}catch(E){m.timer&&clearTimeout(m.timer),this.pending.delete(c),h(E)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new T("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(n0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(mo(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new T("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:Py(e.result)}),r.resolve(e.result));return}if(Qf(e)){if(e.method==="session/update"){let r=e.params;for(let i of this.pending.values()){let o=i.promptTimeout;o&&(o.firstFrameSeen=!0,o.lastActivityAt=this.now(),this.trackToolCall(o,r))}for(let i of this.updateHandlers)try{Promise.resolve(i(r)).catch(o=>this.log.warn("update handler failed (async)",{err:String(o)}))}catch(o){this.log.warn("update handler threw sync, swallowed",{err:String(o)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(Yf(e)){let r=e;try{this.handleAgentRequest(r).catch(i=>this.log.error("agent request handler failed (async)",{method:r.method,err:String(i)}))}catch(i){this.log.warn("handleAgentRequest threw sync, swallowed",{method:r.method,err:String(i)})}}}trackToolCall(e,r){let i=r.update,o=i?.sessionUpdate;if(o!=="tool_call"&&o!=="tool_call_update")return;let c=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!c)return;let l=typeof i.status=="string"?i.status:void 0,u=l==="completed"||l==="failed"||l==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(In(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(In(e.id,Gi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=e0(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=x0(this.framework,Oy(e));return i?new T(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):r}buildExitError(e,r){if(this.stopReason!==void 0)return new T("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(Ay).join(`
96
- `),o=f0(this.framework,i);return o?new T(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new T("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function My(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 _o=class extends Nt{framework="claude-code";constructor(e){let{command:r,args:i}=oi("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 My(e)}};an();import{mkdtempSync as Uy,rmSync as qy}from"node:fs";import{tmpdir as Gy}from"node:os";import{join as Hy}from"node:path";import{readFileSync as _0}from"node:fs";import{homedir as By}from"node:os";import{join as w0}from"node:path";function y0(t){let e=t.CODEX_HOME?.trim()||w0(t.HOME?.trim()||By(),".codex");return w0(e,"config.toml")}function zy(t){let e=null;for(let r=0;r<t.length;r++){let i=t[r];if(e)i===e&&(e=null);else if(i==='"'||i==="'")e=i;else if(i==="#")return t.slice(0,r)}return t}function Fy(t){let e=t.trim();if(e.length>=2){let r=e[0];if((r==='"'||r==="'")&&e[e.length-1]===r)return e.slice(1,-1)}return e}function b0(t){let e={},r={},i=e;for(let o of t.split(/\r?\n/)){let c=zy(o).trim();if(!c)continue;let l=/^\[([^\]]+)\]$/.exec(c);if(l){let h=(l[1]??"").trim(),m=r[h]??{};r[h]=m,i=m;continue}let u=c.indexOf("=");if(u<=0)continue;let x=c.slice(0,u).trim();x&&(i[x]=Fy(c.slice(u+1)))}return{root:e,tables:r}}function E0(t){let e=t.root.model_provider;if(!e||e==="openai")return null;let r=t.tables[`model_providers.${e}`];return r?{providerId:e,baseUrl:r.base_url,envKey:r.env_key,bearerToken:r.experimental_bearer_token}:null}function v0(t){let e;try{e=_0(y0(t),"utf8")}catch{return null}return E0(b0(e))?.providerId??null}function S0(t){let e;try{e=_0(y0(t),"utf8")}catch{return null}let r=E0(b0(e));if(!r?.baseUrl)return null;let i=r.bearerToken||(r.envKey?t[r.envKey]?.trim():void 0);return i?{baseUrl:r.baseUrl,providerName:r.providerId,headers:{Authorization:`Bearer ${i}`}}:null}var yo=class t extends Nt{framework="codex";authRequest;resolveLocalGatewayAuth;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=oi("codex",e.command,i),l=e.isolateCodexHome?Uy(Hy(Gy(),"coze-bridge-codex-home-")):void 0,u=l?{...e.env??{},CODEX_HOME:l}:e.env,x={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(x),this.authRequest=e.authRequest,this.resolveLocalGatewayAuth=e.resolveLocalGatewayAuth??!1,this.codexHomeDir=l}async initialize(e){let r=await super.initialize(e),i=this.authRequest??this.localGatewayAuthRequest();return i&&await this.call("authenticate",i),r}localGatewayAuthRequest(){if(!this.resolveLocalGatewayAuth)return null;let e=S0(this.spawnEnv);return e?(this.log.info("codex local: \u7528 config.toml custom provider \u8D70 gateway \u8BA4\u8BC1",{providerName:e.providerName,baseUrl:e.baseUrl}),{methodId:"gateway",_meta:{gateway:e}}):null}static MODE_ID_MAP={"read-only":"read-only",auto:"agent","full-access":"agent-full-access"};setSessionMode(e){let r=t.MODE_ID_MAP[e.modeId]??e.modeId;return super.setSessionMode({...e,modeId:r})}async stop(e){if(await super.stop(e),this.codexHomeDir)try{qy(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};Ze();var jy=3e4,zr=class extends Nt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},jy))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new T("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var A0=["default","acceptEdits","plan","auto","bypassPermissions"],I0=["read-only","auto","full-access"];function Cn(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return A0.includes(e);case"codex":return I0.includes(e);case"openclaw":return!1}}function nd(t){switch(t){case"claude-code":return A0.join("/");case"codex":return I0.join("/");case"openclaw":return""}}dn();Ze();re();Le();function rd(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}an();var Tn=class{slots=[];running=!1;closed=!1;disposed=!1;enqueue(e){return this.disposed?Promise.reject(new Error("AsyncQueue disposed")):this.closed?Promise.reject(new Error("AsyncQueue closed")):new Promise((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 bo=class{agentId;framework;workspace;deployType;accountId;patToken;modelInfo;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;activeGroupIds=new Map;status="ok";model;lastActiveAt=Date.now();constructor(e){this.agentId=e.agentId,this.framework=e.framework,this.workspace=e.workspace,this.model=e.model,this.deployType=e.deployType??"local",e.accountId&&(this.accountId=e.accountId),e.patToken&&(this.patToken=e.patToken),e.modelInfo&&(this.modelInfo=e.modelInfo)}setPatToken(e){this.patToken=e}setModelInfo(e){this.modelInfo=e}getSessionQueue(e){let r=this.sessionQueues.get(e);return(!r||r.isDisposed)&&(r=new Tn,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)Wi(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 Wi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function Zt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Vt();re();import{constants as C0}from"node:fs";import{access as Wy}from"node:fs/promises";import{delimiter as Ky,join as $y}from"node:path";var St=H("framework-detector"),T0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},Vy=[".exe",".cmd",".bat",".ps1"],Zn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??st,access:e.access??Wy}}async detect(e){let r=T0[e],i=await this.which(r);if(!i)return St.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,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(T0).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(Ky).filter(Boolean),i=this.env.platform==="win32"?["",...Vy]:[""];for(let o of r)for(let c of i){let l=$y(o,e+c);if(await this.isExecutable(l))return l}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?C0.F_OK:C0.X_OK;return await this.env.access(e,r),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let r=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!r)return St.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return St.warn("openclaw default agent probe: non-zero exit",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)}),null;let i=r.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return St.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:r.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return St.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(l=>l?.isDefault===!0);return c?!c.id||!c.workspace?(St.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(St.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return St.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let r=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!r)return St.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||St.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let 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){St.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&&(Jy(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",h=>{o+=h.toString("utf8")}),x.on("error",()=>u(null)),x.on("close",h=>u({code:h,stdout:o}))}catch{u(null)}})}},Zy=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function Jy(t){return t.replace(Zy,"")}import{homedir as Xy}from"node:os";import{join as Yy}from"node:path";dn();Vt();or();Ze();re();async function k0(){let t=Yy(Xy(),".openclaw/openclaw.json");return(await lr(t))?.gateway?.auth?.token??""}var R0=H("openclaw.config"),Qy=[0,5e3,5e3],eb=Ve("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),D0="models.providers.",Eo="agents.defaults.models",vo=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new Tn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??Qy,this.cliTimeoutMs=e.cliTimeoutMs??eb}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,R0.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=st(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",l=!1,u=h=>{l||(l=!0,clearTimeout(x),h())};o.stderr?.on("data",h=>{c+=h.toString("utf8")});let x=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);x.unref(),o.on("error",h=>u(()=>i(h))),o.on("close",h=>u(()=>{h===0?r():i(new Error(`exit ${h}: ${c.trim().slice(0,500)}`))}))})}async runCliTolerant(e,r){try{await this.runCli(e)}catch(i){let o=String(i);if(r.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,r){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",r])))}catch(i){R0.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",`${D0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${D0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${Eo}[${e}]`,()=>this.runCli(["config","set",Eo,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${Eo}[${e}]`,`${Eo}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var ue=H("agent-manager"),ad="bypassPermissions",L0="full-access",N0="full-access";function ib(t){switch(t){case"read-only":return"read-only";case"auto":return"agent";case"full-access":return"agent-full-access"}}var sb=(t,e,r,i,o,c,l,u,x,h)=>{switch(t){case"claude-code":{let m={...o?{...Ff(o),...Gf(o,l,u)}:{},...x??{},IS_SANDBOX:"1"};return new _o({cwd:r,env:m,agentId:i})}case"codex":{let m=L0;h!==void 0&&(Cn("codex",h)?m=h:ue.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:h}));let E=o?null:v0(process.env),S={...o?qf(o):{},INITIAL_AGENT_MODE:ib(m),...process.env.COZE_BRIDGE_CODEX_APP_SERVER_LOGS==="1"?{APP_SERVER_LOGS:od(r,"..","logs","codex-app-server")}:{},...E?{MODEL_PROVIDER:E}:{},...x??{}},_=o?Uf(o,l,u):null,v=_?{methodId:"gateway",_meta:{gateway:_}}:void 0,A=!!o,I=!A&&process.env.COZE_BRIDGE_CODEX_LOCAL_GATEWAY_AUTH==="1";return new yo({cwd:r,agentId:i,...Object.keys(S).length>0?{env:S}:{},...v?{authRequest:v}:{},...A?{isolateCodexHome:!0}:{},...I?{resolveLocalGatewayAuth:!0}:{}})}case"openclaw":return new zr({command:e,cwd:r,agentId:i,...c?{sessionName:rd(c)}:{}})}};function sd(t){return t==="claude-code"||t==="codex"}function ob(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(ab(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
89
+ `},configPath(t){return z1(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 hp("schtasks",["/Create","/SC","ONLOGON","/TN",da,"/TR",r,"/RU",t.userName,"/F"]),Zd.info("task scheduler entry created",{task:da,logFile:t.logFile})},async uninstall(t){await hp("schtasks",["/Delete","/TN",da,"/F"]).catch(e=>Zd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Zd.info("task scheduler entry removed",{task:da})}}});var gp={};va(gp,{buildContext:()=>W1,getSupervisor:()=>H1,launchdSupervisor:()=>Vd,systemdSupervisor:()=>Yd,taskSchedulerSupervisor:()=>Jd});import{homedir as U1,userInfo as G1}from"node:os";function H1(t=process.platform){switch(t){case"darwin":return Vd;case"linux":return Yd;case"win32":return Jd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function j1(){let t={};for(let e of q1){let r=process.env[e];r&&(t[e]=r)}return t}function W1(){let t=Q();return{nodeBin:process.execPath,entry:zd(t),logFile:t.logFile,homeDir:U1(),userName:G1().username,isRoot:process.getuid?.()===0,env:j1()}}var q1,mp=et(()=>{"use strict";Oe();Xo();up();xp();pp();q1=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});te();rn();var Tl=q("acp-installer-warmup"),qg=["claude-code","codex"];async function Rl(t={}){let e=t.ensure??or,i=(await Promise.allSettled(qg.map(async o=>{let c=await e(o);Tl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&Tl.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}an();te();import{readdir as sm}from"node:fs/promises";import{mkdir as Ol,readFile as rm,writeFile as Ll}from"node:fs/promises";import{join as Ca}from"node:path";var im={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function dr(t,e,r){await Ol(t,{recursive:!0});let i=im[e],o=Ca(t,i);return await Ll(o,r??"","utf8"),o}async function Da(t,e,r){let i=Ca(t,".claude");await Ol(i,{recursive:!0});let o=Ca(i,"settings.local.json"),c={};try{let u=await rm(o,"utf8"),f=JSON.parse(u);typeof f=="object"&&f!==null&&!Array.isArray(f)&&(c=f)}catch{}let d=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")d.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!r)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");d.defaultMode===void 0&&(d.defaultMode=r)}return c.permissions=d,await Ll(o,JSON.stringify(c,null,2),"utf8"),o}var Je=q("agent-detail-sync"),om=6e4,am=5*6e4,gs=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await sm(r)}catch(o){Je.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}Je.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Te(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Je.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(d){Je.warn("detail sync failed for agent, skipping",{agentId:o,err:String(d)})}}})),Je.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){Je.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){Je.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Te(e,this.opts.paths);if(!i){Je.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){Je.warn("detail RPC failed, using local data",{agentId:e,err:String(f)});let h=this.retryQueue.get(e),g=h?Math.min(h.currentDelay*2,am):om;this.retryQueue.set(e,{dueAt:Date.now()+g,currentDelay:g});return}if(o.agentId&&o.agentId!==e){Je.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,d=!1;o.agentName&&o.agentName!==i.agentName&&(i.agentName=o.agentName,c=!0),o.description!==void 0&&o.description!==i.description&&(i.description=o.description,c=!0),o.cozeIdentity&&o.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=o.cozeIdentity,c=!0,d=!0);let u=!1;if(o.deployType==="cloud"&&i.deployType!=="cloud"?(Je.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&Je.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Je.debug("detail sync: no diff",{agentId:e});return}await Fe(i,this.opts.paths),Je.info("detail sync: config updated",{agentId:e,identityChanged:d,agentName:i.agentName}),u?(await this.opts.agentManager.createAgent({agentId:e,framework:i.framework,_meta:{cozeDeployType:"cloud"},cozeIdentity:i.cozeIdentity,model:i.model}),Je.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):d&&(await dr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var Xc=zt(xu(),1);import{createHash as H_}from"node:crypto";import{lstat as Wc,mkdir as Kc,readFile as co,readdir as Jf,rm as $c,stat as Vf,writeFile as Vc}from"node:fs/promises";import{dirname as q_,join as $e,normalize as j_,relative as Jc,resolve as Yc,sep as Xf}from"node:path";import{Readable as Qf}from"node:stream";import{pipeline as e0}from"node:stream/promises";import Rm from"events";import nt from"fs";import{EventEmitter as Cc}from"node:events";import Vu from"node:stream";import{StringDecoder as Cm}from"node:string_decoder";import Ju from"node:path";import Er from"node:fs";import{dirname as qm,parse as jm}from"path";import{EventEmitter as Xm}from"events";import uc from"assert";import{Buffer as Gn}from"buffer";import*as wu from"zlib";import Qm from"zlib";import{posix as hr}from"node:path";import{basename as Aw}from"node:path";import Vs from"fs";import Rt from"fs";import Iu from"path";import{win32 as Fw}from"node:path";import Pu from"path";import xf from"node:fs";import t_ from"node:assert";import{randomBytes as hf}from"node:crypto";import re from"node:fs";import Ne from"node:path";import pf from"fs";import ro from"node:fs";import vi from"node:path";import ot from"node:fs";import c_ from"node:fs/promises";import Js from"node:path";import{join as Af}from"node:path";import st from"node:fs";import Rf from"node:path";var km=Object.defineProperty,Tm=(t,e)=>{for(var r in e)km(t,r,{get:e[r],enumerable:!0})},hu=typeof process=="object"&&process?process:{stdout:null,stderr:null},Dm=t=>!!t&&typeof t=="object"&&(t instanceof jn||t instanceof Vu||Pm(t)||Om(t)),Pm=t=>!!t&&typeof t=="object"&&t instanceof Cc&&typeof t.pipe=="function"&&t.pipe!==Vu.Writable.prototype.pipe,Om=t=>!!t&&typeof t=="object"&&t instanceof Cc&&typeof t.write=="function"&&typeof t.end=="function",Ut=Symbol("EOF"),Gt=Symbol("maybeEmitEnd"),dn=Symbol("emittedEnd"),Es=Symbol("emittingEnd"),oi=Symbol("emittedError"),bs=Symbol("closed"),pu=Symbol("read"),vs=Symbol("flush"),gu=Symbol("flushChunk"),gt=Symbol("encoding"),xr=Symbol("decoder"),ze=Symbol("flowing"),ai=Symbol("paused"),wr=Symbol("resume"),Ue=Symbol("buffer"),Xe=Symbol("pipes"),Ge=Symbol("bufferLength"),Ba=Symbol("bufferPush"),Ss=Symbol("bufferShift"),Ze=Symbol("objectMode"),Se=Symbol("destroyed"),Fa=Symbol("error"),za=Symbol("emitData"),mu=Symbol("emitEnd"),Ua=Symbol("emitEnd2"),At=Symbol("async"),Ga=Symbol("abort"),Is=Symbol("aborted"),ci=Symbol("signal"),Pn=Symbol("dataListeners"),it=Symbol("discarded"),di=t=>Promise.resolve().then(t),Lm=t=>t(),Nm=t=>t==="end"||t==="finish"||t==="prefinish",Mm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,Bm=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Yu=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[wr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Fm=class extends Yu{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)}},zm=t=>!!t.objectMode,Um=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",jn=class extends Cc{[ze]=!1;[ai]=!1;[Xe]=[];[Ue]=[];[Ze];[gt];[At];[xr];[Ut]=!1;[dn]=!1;[Es]=!1;[bs]=!1;[oi]=null;[Ge]=0;[Se]=!1;[ci];[Is]=!1;[Pn]=0;[it]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");zm(e)?(this[Ze]=!0,this[gt]=null):Um(e)?(this[gt]=e.encoding,this[Ze]=!1):(this[Ze]=!1,this[gt]=null),this[At]=!!e.async,this[xr]=this[gt]?new Cm(this[gt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Ue]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Xe]});let{signal:r}=e;r&&(this[ci]=r,r.aborted?this[Ga]():r.addEventListener("abort",()=>this[Ga]()))}get bufferLength(){return this[Ge]}get encoding(){return this[gt]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[Ze]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[At]}set async(t){this[At]=this[At]||!!t}[Ga](){this[Is]=!0,this.emit("abort",this[ci]?.reason),this.destroy(this[ci]?.reason)}get aborted(){return this[Is]}set aborted(t){}write(t,e,r){if(this[Is])return!1;if(this[Ut])throw new Error("write after end");if(this[Se])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof e=="function"&&(r=e,e="utf8"),e||(e="utf8");let i=this[At]?di:Lm;if(!this[Ze]&&!Buffer.isBuffer(t)){if(Bm(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(Mm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Ze]?(this[ze]&&this[Ge]!==0&&this[vs](!0),this[ze]?this.emit("data",t):this[Ba](t),this[Ge]!==0&&this.emit("readable"),r&&i(r),this[ze]):t.length?(typeof t=="string"&&!(e===this[gt]&&!this[xr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[gt]&&(t=this[xr].write(t)),this[ze]&&this[Ge]!==0&&this[vs](!0),this[ze]?this.emit("data",t):this[Ba](t),this[Ge]!==0&&this.emit("readable"),r&&i(r),this[ze]):(this[Ge]!==0&&this.emit("readable"),r&&i(r),this[ze])}read(t){if(this[Se])return null;if(this[it]=!1,this[Ge]===0||t===0||t&&t>this[Ge])return this[Gt](),null;this[Ze]&&(t=null),this[Ue].length>1&&!this[Ze]&&(this[Ue]=[this[gt]?this[Ue].join(""):Buffer.concat(this[Ue],this[Ge])]);let e=this[pu](t||null,this[Ue][0]);return this[Gt](),e}[pu](t,e){if(this[Ze])this[Ss]();else{let r=e;t===r.length||t===null?this[Ss]():typeof r=="string"?(this[Ue][0]=r.slice(t),e=r.slice(0,t),this[Ge]-=t):(this[Ue][0]=r.subarray(t),e=r.subarray(0,t),this[Ge]-=t)}return this.emit("data",e),!this[Ue].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[ze]||!this[ai])&&this[Gt](),this}[wr](){this[Se]||(!this[Pn]&&!this[Xe].length&&(this[it]=!0),this[ai]=!1,this[ze]=!0,this.emit("resume"),this[Ue].length?this[vs]():this[Ut]?this[Gt]():this.emit("drain"))}resume(){return this[wr]()}pause(){this[ze]=!1,this[ai]=!0,this[it]=!1}get destroyed(){return this[Se]}get flowing(){return this[ze]}get paused(){return this[ai]}[Ba](t){this[Ze]?this[Ge]+=1:this[Ge]+=t.length,this[Ue].push(t)}[Ss](){return this[Ze]?this[Ge]-=1:this[Ge]-=this[Ue][0].length,this[Ue].shift()}[vs](t=!1){do;while(this[gu](this[Ss]())&&this[Ue].length);!t&&!this[Ue].length&&!this[Ut]&&this.emit("drain")}[gu](t){return this.emit("data",t),this[ze]}pipe(t,e){if(this[Se])return t;this[it]=!1;let r=this[dn];return e=e||{},t===hu.stdout||t===hu.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[Xe].push(e.proxyErrors?new Fm(this,t,e):new Yu(this,t,e)),this[At]?di(()=>this[wr]()):this[wr]()),t}unpipe(t){let e=this[Xe].find(r=>r.dest===t);e&&(this[Xe].length===1?(this[ze]&&this[Pn]===0&&(this[ze]=!1),this[Xe]=[]):this[Xe].splice(this[Xe].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[it]=!1,this[Pn]++,!this[Xe].length&&!this[ze]&&this[wr]();else if(t==="readable"&&this[Ge]!==0)super.emit("readable");else if(Nm(t)&&this[dn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[oi]){let i=e;this[At]?di(()=>i.call(this,this[oi])):i.call(this,this[oi])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Pn]=this.listeners("data").length,this[Pn]===0&&!this[it]&&!this[Xe].length&&(this[ze]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Pn]=0,!this[it]&&!this[Xe].length&&(this[ze]=!1)),e}get emittedEnd(){return this[dn]}[Gt](){!this[Es]&&!this[dn]&&!this[Se]&&this[Ue].length===0&&this[Ut]&&(this[Es]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[bs]&&this.emit("close"),this[Es]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Se&&this[Se])return!1;if(t==="data")return!this[Ze]&&!r?!1:this[At]?(di(()=>this[za](r)),!0):this[za](r);if(t==="end")return this[mu]();if(t==="close"){if(this[bs]=!0,!this[dn]&&!this[Se])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[oi]=r,super.emit(Fa,r);let o=!this[ci]||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}[za](t){for(let r of this[Xe])r.dest.write(t)===!1&&this.pause();let e=this[it]?!1:super.emit("data",t);return this[Gt](),e}[mu](){return this[dn]?!1:(this[dn]=!0,this.readable=!1,this[At]?(di(()=>this[Ua]()),!0):this[Ua]())}[Ua](){if(this[xr]){let e=this[xr].end();if(e){for(let r of this[Xe])r.dest.write(e);this[it]||super.emit("data",e)}}for(let e of this[Xe])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Ze]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[Ze]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[Ze])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[gt]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Se,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[it]=!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=h=>{this.off("data",d),this.off("end",u),this.off(Se,f),e(),o(h)},d=h=>{this.off("error",c),this.off("end",u),this.off(Se,f),this.pause(),i({value:h,done:!!this[Ut]})},u=()=>{this.off("error",c),this.off("data",d),this.off(Se,f),e(),i({done:!0,value:void 0})},f=()=>c(new Error("stream destroyed"));return new Promise((h,g)=>{o=g,i=h,this.once(Se,f),this.once("error",c),this.once("end",u),this.once("data",d)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[it]=!1;let t=!1,e=()=>(this.pause(),this.off(Fa,e),this.off(Se,e),this.off("end",e),t=!0,{done:!0,value:void 0}),r=()=>{if(t)return e();let i=this.read();return i===null?e():{done:!1,value:i}};return this.once("end",e),this.once(Fa,e),this.once(Se,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Se])return t?this.emit("error",t):this.emit(Se),this;this[Se]=!0,this[it]=!0,this[Ue].length=0,this[Ge]=0;let e=this;return typeof e.close=="function"&&!this[bs]&&e.close(),t?this.emit("error",t):this.emit(Se),this}static get isStream(){return Dm}},Gm=nt.writev,_n=Symbol("_autoClose"),yt=Symbol("_close"),li=Symbol("_ended"),ce=Symbol("_fd"),Ha=Symbol("_finished"),Wt=Symbol("_flags"),qa=Symbol("_flush"),dc=Symbol("_handleChunk"),lc=Symbol("_makeBuf"),Ei=Symbol("_mode"),As=Symbol("_needDrain"),vr=Symbol("_onerror"),Sr=Symbol("_onopen"),ja=Symbol("_onread"),_r=Symbol("_onwrite"),yn=Symbol("_open"),_t=Symbol("_path"),hn=Symbol("_pos"),kt=Symbol("_queue"),yr=Symbol("_read"),Wa=Symbol("_readSize"),jt=Symbol("_reading"),ui=Symbol("_remain"),Ka=Symbol("_size"),Ms=Symbol("_write"),On=Symbol("_writing"),Bs=Symbol("_defaultFlag"),Un=Symbol("_errored"),Dc=class extends jn{[Un]=!1;[ce];[_t];[Wa];[jt]=!1;[Ka];[ui];[_n];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[Un]=!1,this[ce]=typeof e.fd=="number"?e.fd:void 0,this[_t]=t,this[Wa]=e.readSize||16*1024*1024,this[jt]=!1,this[Ka]=typeof e.size=="number"?e.size:1/0,this[ui]=this[Ka],this[_n]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[ce]=="number"?this[yr]():this[yn]()}get fd(){return this[ce]}get path(){return this[_t]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[yn](){nt.open(this[_t],"r",(t,e)=>this[Sr](t,e))}[Sr](t,e){t?this[vr](t):(this[ce]=e,this.emit("open",e),this[yr]())}[lc](){return Buffer.allocUnsafe(Math.min(this[Wa],this[ui]))}[yr](){if(!this[jt]){this[jt]=!0;let t=this[lc]();if(t.length===0)return process.nextTick(()=>this[ja](null,0,t));nt.read(this[ce],t,0,t.length,null,(e,r,i)=>this[ja](e,r,i))}}[ja](t,e,r){this[jt]=!1,t?this[vr](t):this[dc](e,r)&&this[yr]()}[yt](){if(this[_n]&&typeof this[ce]=="number"){let t=this[ce];this[ce]=void 0,nt.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[vr](t){this[jt]=!0,this[yt](),this.emit("error",t)}[dc](t,e){let r=!1;return this[ui]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[ui]<=0)&&(r=!1,this[yt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[ce]=="number"&&this[yr](),!1;case"error":return this[Un]?!1:(this[Un]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Hm=class extends Dc{[yn](){let t=!0;try{this[Sr](null,nt.openSync(this[_t],"r")),t=!1}finally{t&&this[yt]()}}[yr](){let t=!0;try{if(!this[jt]){this[jt]=!0;do{let e=this[lc](),r=e.length===0?0:nt.readSync(this[ce],e,0,e.length,null);if(!this[dc](r,e))break}while(!0);this[jt]=!1}t=!1}finally{t&&this[yt]()}}[yt](){if(this[_n]&&typeof this[ce]=="number"){let t=this[ce];this[ce]=void 0,nt.closeSync(t),this.emit("close")}}},Xs=class extends Rm{readable=!1;writable=!0;[Un]=!1;[On]=!1;[li]=!1;[kt]=[];[As]=!1;[_t];[Ei];[_n];[ce];[Bs];[Wt];[Ha]=!1;[hn];constructor(t,e){e=e||{},super(e),this[_t]=t,this[ce]=typeof e.fd=="number"?e.fd:void 0,this[Ei]=e.mode===void 0?438:e.mode,this[hn]=typeof e.start=="number"?e.start:void 0,this[_n]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[hn]!==void 0?"r+":"w";this[Bs]=e.flags===void 0,this[Wt]=e.flags===void 0?r:e.flags,this[ce]===void 0&&this[yn]()}emit(t,...e){if(t==="error"){if(this[Un])return!1;this[Un]=!0}return super.emit(t,...e)}get fd(){return this[ce]}get path(){return this[_t]}[vr](t){this[yt](),this[On]=!0,this.emit("error",t)}[yn](){nt.open(this[_t],this[Wt],this[Ei],(t,e)=>this[Sr](t,e))}[Sr](t,e){this[Bs]&&this[Wt]==="r+"&&t&&t.code==="ENOENT"?(this[Wt]="w",this[yn]()):t?this[vr](t):(this[ce]=e,this.emit("open",e),this[On]||this[qa]())}end(t,e){return t&&this.write(t,e),this[li]=!0,!this[On]&&!this[kt].length&&typeof this[ce]=="number"&&this[_r](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[li]?(this.emit("error",new Error("write() after end()")),!1):this[ce]===void 0||this[On]||this[kt].length?(this[kt].push(t),this[As]=!0,!1):(this[On]=!0,this[Ms](t),!0)}[Ms](t){nt.write(this[ce],t,0,t.length,this[hn],(e,r)=>this[_r](e,r))}[_r](t,e){t?this[vr](t):(this[hn]!==void 0&&typeof e=="number"&&(this[hn]+=e),this[kt].length?this[qa]():(this[On]=!1,this[li]&&!this[Ha]?(this[Ha]=!0,this[yt](),this.emit("finish")):this[As]&&(this[As]=!1,this.emit("drain"))))}[qa](){if(this[kt].length===0)this[li]&&this[_r](null,0);else if(this[kt].length===1)this[Ms](this[kt].pop());else{let t=this[kt];this[kt]=[],Gm(this[ce],t,this[hn],(e,r)=>this[_r](e,r))}}[yt](){if(this[_n]&&typeof this[ce]=="number"){let t=this[ce];this[ce]=void 0,nt.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Zu=class extends Xs{[yn](){let t;if(this[Bs]&&this[Wt]==="r+")try{t=nt.openSync(this[_t],this[Wt],this[Ei])}catch(e){if(e?.code==="ENOENT")return this[Wt]="w",this[yn]();throw e}else t=nt.openSync(this[_t],this[Wt],this[Ei]);this[Sr](null,t)}[yt](){if(this[_n]&&typeof this[ce]=="number"){let t=this[ce];this[ce]=void 0,nt.closeSync(t),this.emit("close")}}[Ms](t){let e=!0;try{this[_r](null,nt.writeSync(this[ce],t,0,t.length,this[hn])),e=!1}finally{if(e)try{this[yt]()}catch{}}}},Wm=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),Km=t=>!!t.sync&&!!t.file,$m=t=>!t.sync&&!!t.file,Vm=t=>!!t.sync&&!t.file,Ym=t=>!t.sync&&!t.file,Zm=t=>!!t.file,Jm=t=>Wm.get(t)||t,Pc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=Jm(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ci=(t,e,r,i,o)=>Object.assign((c=[],d,u)=>{Array.isArray(c)&&(d=c,c={}),typeof d=="function"&&(u=d,d=void 0),d=d?Array.from(d):[];let f=Pc(c);if(o?.(f,d),Km(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(f,d)}else if($m(f)){let h=e(f,d);return u?h.then(()=>u(),u):h}else if(Vm(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(f,d)}else if(Ym(f)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(f,d)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),ew=Qm.constants||{ZLIB_VERNUM:4736},Dt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},ew)),tw=Gn.concat,_u=Object.getOwnPropertyDescriptor(Gn,"concat"),nw=t=>t,$a=_u?.writable===!0||_u?.set!==void 0?t=>{Gn.concat=t?nw:tw}:t=>{},Hn=Symbol("_superWrite"),ks=class extends Error{code;errno;constructor(t,e){super("zlib: "+t.message,{cause:t}),this.code=t.code,this.errno=t.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+t.message,Error.captureStackTrace(this,e??this.constructor)}get name(){return"ZlibError"}},Va=Symbol("flushFlag"),Oc=class extends jn{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof wu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new wu[e](t)}catch(r){throw new ks(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 ks(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return uc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Gn.alloc(0),{[Va]: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}[Hn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Gn.from(t,e)),this.#e)return;uc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},$a(!0);let d;try{let f=typeof t[Va]=="number"?t[Va]:this.#r;d=this.#t._processChunk(t,f),$a(!1)}catch(f){$a(!1),this.#o(new ks(f,this.write))}finally{this.#t&&(this.#t._handle=i,i.close=o,this.#t.close=c,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",f=>this.#o(new ks(f,this.write)));let u;if(d)if(Array.isArray(d)&&d.length>0){let f=d[0];u=this[Hn](Gn.from(f));for(let h=1;h<d.length;h++)u=this[Hn](d[h])}else u=this[Hn](Gn.from(d));return r&&r(),u}},Xu=class extends Oc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Dt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Dt.Z_FINISH,t.fullFlushFlag=Dt.Z_FULL_FLUSH,super(t,e),this.#e=t.level,this.#n=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==t||this.#n!==e){this.flush(Dt.Z_SYNC_FLUSH),uc(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)}}}},rw=class extends Xu{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Hn](t){return this.#e?(this.#e=!1,t[9]=255,super[Hn](t)):super[Hn](t)}},iw=class extends Xu{constructor(t){super(t,"Unzip")}},Qu=class extends Oc{constructor(t,e){t=t||{},t.flush=t.flush||Dt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Dt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Dt.BROTLI_OPERATION_FLUSH,super(t,e)}},sw=class extends Qu{constructor(t){super(t,"BrotliCompress")}},ow=class extends Qu{constructor(t){super(t,"BrotliDecompress")}},ef=class extends Oc{constructor(t,e){t=t||{},t.flush=t.flush||Dt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Dt.ZSTD_e_end,t.fullFlushFlag=Dt.ZSTD_e_flush,super(t,e)}},aw=class extends ef{constructor(t){super(t,"ZstdCompress")}},cw=class extends ef{constructor(t){super(t,"ZstdDecompress")}},dw=(t,e)=>{if(Number.isSafeInteger(t))t<0?uw(t,e):lw(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},lw=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},uw=(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]=tf(o):o===0?e[i-1]=0:(r=!0,e[i-1]=nf(o))}},fw=t=>{let e=t[0],r=e===128?hw(t.subarray(1,t.length)):e===255?xw(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},xw=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),d;i?d=tf(c):c===0?d=c:(i=!0,d=nf(c)),d!==0&&(r-=d*Math.pow(256,e-o-1))}return r},hw=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},tf=t=>(255^t)&255,nf=t=>(255^t)+1&255,pw={};Tm(pw,{code:()=>Lc,isCode:()=>Fs,isName:()=>gw,name:()=>Qs,normalFsTypes:()=>rf});var Fs=t=>Qs.has(t),gw=t=>Lc.has(t),rf=new Set(["0","","1","2","3","4","5","6","7","D"]),Qs=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"]]),Lc=new Map(Array.from(Qs).map(t=>[t[1],t[0]])),qn=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,r,i){Buffer.isBuffer(t)?this.decode(t,e||0,r,i):t&&this.#n(t)}decode(t,e,r,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");let o=Ln(t,e+156,1),c=rf.has(o),d=c?r:void 0,u=c?i:void 0;if(this.path=d?.path??Ln(t,e,100),this.mode=d?.mode??u?.mode??pn(t,e+100,8),this.uid=d?.uid??u?.uid??pn(t,e+108,8),this.gid=d?.gid??u?.gid??pn(t,e+116,8),this.size=d?.size??u?.size??pn(t,e+124,12),this.mtime=d?.mtime??u?.mtime??Ya(t,e+136,12),this.cksum=pn(t,e+148,12),u&&this.#n(u,!0),d&&this.#n(d),Fs(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Ln(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=d?.uname??u?.uname??Ln(t,e+265,32),this.gname=d?.gname??u?.gname??Ln(t,e+297,32),this.devmaj=d?.devmaj??u?.devmaj??pn(t,e+329,8)??0,this.devmin=d?.devmin??u?.devmin??pn(t,e+337,8)??0,t[e+475]!==0){let h=Ln(t,e+345,155);this.path=h+"/"+this.path}else{let h=Ln(t,e+345,130);h&&(this.path=h+"/"+this.path),this.atime=r?.atime??i?.atime??Ya(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Ya(t,e+488,12)}let f=256;for(let h=e;h<e+148;h++)f+=t[h];for(let h=e+156;h<e+512;h++)f+=t[h];this.cksumValid=f===this.cksum,this.cksum===void 0&&f===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e||r==="linkpath"&&e||r==="global"))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let r=this.ctime||this.atime?130:155,i=mw(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Nn(t,e,100,o)||this.needPax,this.needPax=gn(t,e+100,8,this.mode)||this.needPax,this.needPax=gn(t,e+108,8,this.uid)||this.needPax,this.needPax=gn(t,e+116,8,this.gid)||this.needPax,this.needPax=gn(t,e+124,12,this.size)||this.needPax,this.needPax=Za(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Nn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Nn(t,e+265,32,this.uname)||this.needPax,this.needPax=Nn(t,e+297,32,this.gname)||this.needPax,this.needPax=gn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=gn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Nn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=Nn(t,e+345,155,c)||this.needPax:(this.needPax=Nn(t,e+345,130,c)||this.needPax,this.needPax=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 u=e;u<e+148;u++)d+=t[u];for(let u=e+156;u<e+512;u++)d+=t[u];return this.cksum=d,gn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:Qs.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Lc.get(t));if(Fs(e)||e==="Unsupported")this.#e=e;else if(Fs(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},mw=(t,e)=>{let r=t,i="",o,c=hr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=hr.dirname(r),r=hr.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=hr.join(hr.basename(i),r),i=hr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Ln=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Ya=(t,e,r)=>ww(pn(t,e,r)),ww=t=>t===void 0?void 0:new Date(t*1e3),pn=(t,e,r)=>Number(t[e])&128?fw(t.subarray(e,e+r)):yw(t,e,r),_w=t=>isNaN(t)?void 0:t,yw=(t,e,r)=>_w(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),Ew={12:8589934591,8:2097151},gn=(t,e,r,i)=>i===void 0?!1:i>Ew[r]||i<0?(dw(i,t.subarray(e,e+r)),!0):(bw(t,e,r,i),!1),bw=(t,e,r,i)=>t.write(vw(i,r),e,r,"ascii"),vw=(t,e)=>Sw(Math.floor(t).toString(8),e),Sw=(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:gn(t,e,r,i.getTime()/1e3),Iw=new Array(156).join("\0"),Nn=(t,e,r,i)=>i===void 0?!1:(t.write(i+Iw,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),$s=class sf{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 qn({path:("PaxHeader/"+Aw(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 sf(kw(Tw(e),r),i)}},kw=(t,e)=>e?Object.assign({},e,t):t,Tw=t=>t.replace(/\n$/,"").split(`
91
+ `).reduce(Rw,Object.create(null)),Rw=(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},Cw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,X=Cw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),Dw=class extends jn{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,r){switch(super({}),this.pause(),this.extended=e,this.globalExtended=r,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=X(t.path),this.mode=t.mode,this.mode&&(this.mode=this.mode&4095),this.uid=t.uid,this.gid=t.gid,this.uname=t.uname,this.gname=t.gname,this.size=this.remain,this.mtime=t.mtime,this.atime=t.atime,this.ctime=t.ctime,this.linkpath=t.linkpath?X(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#e(e),r&&this.#e(r,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let r=this.remain,i=this.blockRemain;return this.remain=Math.max(0,r-e),this.blockRemain=Math.max(0,i-e),this.ignore?!0:r>=e?super.write(t):super.write(t.subarray(0,r))}#e(t,e=!1){t.path&&(t.path=X(t.path)),t.linkpath&&(t.linkpath=X(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},eo=(t,e,r,i={})=>{t.file&&(i.file=t.file),t.cwd&&(i.cwd=t.cwd),i.code=r instanceof Error&&r.code||e,i.tarCode=e,!t.strict&&i.recoverable!==!1?(r instanceof Error&&(i=Object.assign(r,i),r=r.message),t.emit("warn",e,r,i)):r instanceof Error?t.emit("error",Object.assign(r,i)):t.emit("error",Object.assign(new Error(`${e}: ${r}`),i))},Pw=1024*1024,fc=Buffer.from([31,139]),xc=Buffer.from([40,181,47,253]),Ow=Math.max(fc.length,xc.length),dt=Symbol("state"),Mn=Symbol("writeEntry"),Ht=Symbol("readEntry"),Ja=Symbol("nextEntry"),yu=Symbol("processEntry"),Tt=Symbol("extendedHeader"),fi=Symbol("globalExtendedHeader"),ln=Symbol("meta"),Eu=Symbol("emitMeta"),pe=Symbol("buffer"),qt=Symbol("queue"),un=Symbol("ended"),Xa=Symbol("emittedEnd"),Bn=Symbol("emit"),Re=Symbol("unzip"),Ts=Symbol("consumeChunk"),Rs=Symbol("consumeChunkSub"),Qa=Symbol("consumeBody"),bu=Symbol("consumeMeta"),vu=Symbol("consumeHeader"),xi=Symbol("consuming"),ec=Symbol("bufferConcat"),Cs=Symbol("maybeEnd"),pr=Symbol("writing"),fn=Symbol("aborted"),Ds=Symbol("onDone"),Fn=Symbol("sawValidEntry"),Ps=Symbol("sawNullBlock"),Os=Symbol("sawEOF"),Su=Symbol("closeStream"),Lw=()=>!0,Ri=class extends Xm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[qt]=[];[pe];[Ht];[Mn];[dt]="begin";[ln]="";[Tt];[fi];[un]=!1;[Re];[fn]=!1;[Fn];[Ps]=!1;[Os]=!1;[pr]=!1;[xi]=!1;[Xa]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Ds,()=>{(this[dt]==="begin"||this[Fn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Ds,t.ondone):this.on(Ds,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||Pw,this.filter=typeof t.filter=="function"?t.filter:Lw;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[Su]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){eo(this,t,e,r)}[vu](t,e){this[Fn]===void 0&&(this[Fn]=!1);let r;try{r=new qn(t,e,this[Tt],this[fi])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Ps]?(this[Os]=!0,this[dt]==="begin"&&(this[dt]="header"),this[Bn]("eof")):(this[Ps]=!0,this[Bn]("nullBlock"));else if(this[Ps]=!1,!r.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:r});else if(!r.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:r});else{let i=r.type;if(/^(Symbolic)?Link$/.test(i)&&!r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:r});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:r});else{let o=this[Mn]=new Dw(r,this[Tt],this[fi]);if(!this[Fn])if(o.remain){let c=()=>{o.invalid||(this[Fn]=!0)};o.on("end",c)}else this[Fn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Bn]("ignoredEntry",o),this[dt]="ignore",o.resume()):o.size>0&&(this[ln]="",o.on("data",c=>this[ln]+=c),this[dt]="meta"):(this[Tt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Bn]("ignoredEntry",o),this[dt]=o.remain?"ignore":"header",o.resume()):(o.remain?this[dt]="body":(this[dt]="header",o.end()),this[Ht]?this[qt].push(o):(this[qt].push(o),this[Ja]())))}}}[Su](){queueMicrotask(()=>this.emit("close"))}[yu](t){let e=!0;if(!t)this[Ht]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[Ht]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Ja]()),e=!1);return e}[Ja](){do;while(this[yu](this[qt].shift()));if(this[qt].length===0){let t=this[Ht];!t||t.flowing||t.size===t.remain?this[pr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Qa](t,e){let r=this[Mn];if(!r)throw new Error("attempt to consume body without entry??");let i=r.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return r.write(o),r.blockRemain||(this[dt]="header",this[Mn]=void 0,r.end()),o.length}[bu](t,e){let r=this[Mn],i=this[Qa](t,e);return!this[Mn]&&r&&this[Eu](r),i}[Bn](t,e,r){this[qt].length===0&&!this[Ht]?this.emit(t,e,r):this[qt].push([t,e,r])}[Eu](t){switch(this[Bn]("meta",this[ln]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Tt]=$s.parse(this[ln],this[Tt],!1);break;case"GlobalExtendedHeader":this[fi]=$s.parse(this[ln],this[fi],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Tt]??Object.create(null);this[Tt]=e,e.path=this[ln].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Tt]||Object.create(null);this[Tt]=e,e.linkpath=this[ln].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[fn]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[fn])return r?.(),!1;if((this[Re]===void 0||this.brotli===void 0&&this[Re]===!1)&&t){if(this[pe]&&(t=Buffer.concat([this[pe],t]),this[pe]=void 0),t.length<Ow)return this[pe]=t,r?.(),!0;for(let d=0;this[Re]===void 0&&d<fc.length;d++)t[d]!==fc[d]&&(this[Re]=!1);let o=!1;if(this[Re]===!1&&this.zstd!==!1){o=!0;for(let d=0;d<xc.length;d++)if(t[d]!==xc[d]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Re]===!1&&c)if(t.length<512)if(this[un])this.brotli=!0;else return this[pe]=t,r?.(),!0;else try{new qn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Re]===void 0||this[Re]===!1&&(this.brotli||o)){let d=this[un];this[un]=!1,this[Re]=this[Re]===void 0?new iw({}):o?new cw({}):new ow({}),this[Re].on("data",f=>this[Ts](f)),this[Re].on("error",f=>this.abort(f)),this[Re].on("end",()=>{this[un]=!0,this[Ts]()}),this[pr]=!0;let u=!!this[Re][d?"end":"write"](t);return this[pr]=!1,r?.(),u}}this[pr]=!0,this[Re]?this[Re].write(t):this[Ts](t),this[pr]=!1;let i=this[qt].length>0?!1:this[Ht]?this[Ht].flowing:!0;return!i&&this[qt].length===0&&this[Ht]?.once("drain",()=>this.emit("drain")),r?.(),i}[ec](t){t&&!this[fn]&&(this[pe]=this[pe]?Buffer.concat([this[pe],t]):t)}[Cs](){if(this[un]&&!this[Xa]&&!this[fn]&&!this[xi]){this[Xa]=!0;let t=this[Mn];if(t&&t.blockRemain){let e=this[pe]?this[pe].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[pe]&&t.write(this[pe]),t.end()}this[Bn](Ds)}}[Ts](t){if(this[xi]&&t)this[ec](t);else if(!t&&!this[pe])this[Cs]();else if(t){if(this[xi]=!0,this[pe]){this[ec](t);let e=this[pe];this[pe]=void 0,this[Rs](e)}else this[Rs](t);for(;this[pe]&&this[pe]?.length>=512&&!this[fn]&&!this[Os];){let e=this[pe];this[pe]=void 0,this[Rs](e)}this[xi]=!1}(!this[pe]||this[un])&&this[Cs]()}[Rs](t){let e=0,r=t.length;for(;e+512<=r&&!this[fn]&&!this[Os];)switch(this[dt]){case"begin":case"header":this[vu](t,e),e+=512;break;case"ignore":case"body":e+=this[Qa](t,e);break;case"meta":e+=this[bu](t,e);break;default:throw new Error("invalid state: "+this[dt])}e<r&&(this[pe]=this[pe]?Buffer.concat([t.subarray(e),this[pe]]):t.subarray(e))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),r&&this.once("finish",r),this[fn]||(this[Re]?(t&&this[Re].write(t),this[Re].end()):(this[un]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Cs]())),this}},bi=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)},Nw=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},of=(t,e)=>{let r=new Map(e.map(c=>[bi(c),!0])),i=t.filter,o=(c,d="")=>{let u=d||jm(c).root||".",f;if(c===u)f=!1;else{let h=r.get(c);f=h!==void 0?h:o(qm(c),u)}return r.set(c,f),f};t.filter=i?(c,d)=>i(c,d)&&o(bi(c)):c=>o(bi(c))},Mw=t=>{let e=new Ri(t),r=t.file,i;try{i=Er.openSync(r,"r");let o=Er.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let d=Buffer.allocUnsafe(o.size),u=Er.readSync(i,d,0,o.size,0);e.end(u===d.byteLength?d:d.subarray(0,u))}else{let d=0,u=Buffer.allocUnsafe(c);for(;d<o.size;){let f=Er.readSync(i,u,0,c,d);if(f===0)break;d+=f,e.write(u.subarray(0,f))}e.end()}}finally{if(typeof i=="number")try{Er.closeSync(i)}catch{}}},Bw=(t,e)=>{let r=new Ri(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("end",c),Er.stat(o,(u,f)=>{if(u)d(u);else{let h=new Dc(o,{readSize:i,size:f.size});h.on("error",d),h.pipe(r)}})})},Ir=Ci(Mw,Bw,t=>new Ri(t),t=>new Ri(t),(t,e)=>{e?.length&&of(t,e),t.noResume||Nw(t)}),af=(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:zw,parse:Au}=Fw,Nc=t=>{let e="",r=Au(t);for(;zw(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=Au(t)}return[e,t]},to=["|","<",">","?",":"],Mc=to.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),Uw=new Map(to.map((t,e)=>[t,Mc[e]])),Gw=new Map(Mc.map((t,e)=>[t,to[e]])),ku=t=>to.reduce((e,r)=>e.split(r).join(Uw.get(r)),t),Hw=t=>Mc.reduce((e,r)=>e.split(r).join(Gw.get(r)),t),cf=(t,e)=>e?(t=X(t).replace(/^\.(\/|$)/,""),bi(e)+"/"+t):X(t),qw=16*1024*1024,Tu=Symbol("process"),Ru=Symbol("file"),Cu=Symbol("directory"),hc=Symbol("symlink"),Du=Symbol("hardlink"),hi=Symbol("header"),zs=Symbol("read"),pc=Symbol("lstat"),Us=Symbol("onlstat"),gc=Symbol("onread"),mc=Symbol("onreadlink"),wc=Symbol("openfile"),_c=Symbol("onopenfile"),mn=Symbol("close"),Ys=Symbol("mode"),yc=Symbol("awaitDrain"),tc=Symbol("ondrain"),Ct=Symbol("prefix"),df=class extends jn{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let r=Pc(e);super(),this.path=X(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||qw,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=X(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?X(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,d]=Nc(this.path);c&&typeof d=="string"&&(this.path=d,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Hw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=X(r.absolute||Iu.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[Us](o):this[pc]()}warn(t,e,r={}){return eo(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[pc](){Rt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Us](e)})}[Us](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=Kw(t),this.emit("stat",t),this[Tu]()}[Tu](){switch(this.type){case"File":return this[Ru]();case"Directory":return this[Cu]();case"SymbolicLink":return this[hc]();default:return this.end()}}[Ys](t){return af(t,this.type==="Directory",this.portable)}[Ct](t){return cf(t,this.prefix)}[hi](){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 qn({path:this[Ct](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ct](this.linkpath):this.linkpath,mode:this[Ys](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 $s({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[Ct](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ct](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)}[Cu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[hi](),this.end()}[hc](){Rt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[mc](e)})}[mc](t){this.linkpath=X(t),this[hi](),this.end()}[Du](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=X(Iu.relative(this.cwd,t)),this.stat.size=0,this[hi](),this.end()}[Ru](){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[Du](e);this.linkCache.set(t,this.absolute)}if(this[hi](),this.stat.size===0)return this.end();this[wc]()}[wc](){Rt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[_c](e)})}[_c](t){if(this.fd=t,this.#e)return this[mn]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[zs]()}[zs](){let{fd:t,buf:e,offset:r,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");Rt.read(t,e,r,i,o,(c,d)=>{if(c)return this[mn](()=>this.emit("error",c));this[gc](d)})}[mn](t=()=>{}){this.fd!==void 0&&Rt.close(this.fd,t)}[gc](t){if(t<=0&&this.remain>0){let r=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[mn](()=>this.emit("error",r))}if(t>this.remain){let r=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[mn](()=>this.emit("error",r))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let r=t;r<this.length&&t<this.blockRemain;r++)this.buf[r+this.offset]=0,t++,this.remain++;let e=this.offset===0&&t===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+t);this.write(e)?this[tc]():this[yc](()=>this[tc]())}[yc](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)}[tc](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[mn](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[zs]()}},jw=class extends df{sync=!0;[pc](){this[Us](Rt.lstatSync(this.absolute))}[hc](){this[mc](Rt.readlinkSync(this.absolute))}[wc](){this[_c](Rt.openSync(this.absolute,"r"))}[zs](){let t=!0;try{let{fd:e,buf:r,offset:i,length:o,pos:c}=this;if(e===void 0||r===void 0)throw new Error("fd and buf must be set in READ method");let d=Rt.readSync(e,r,i,o,c);this[gc](d),t=!1}finally{if(t)try{this[mn](()=>{})}catch{}}}[yc](t){t()}[mn](t=()=>{}){this.fd!==void 0&&Rt.closeSync(this.fd),t()}},Ww=class extends jn{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,r={}){return eo(this,t,e,r)}constructor(t,e={}){let r=Pc(e);super(),this.preservePaths=!!r.preservePaths,this.portable=!!r.portable,this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.onWriteEntry=r.onWriteEntry,this.readEntry=t;let{type:i}=t;if(i==="Unsupported")throw new Error("writing entry that should be ignored");this.type=i,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=r.prefix,this.path=X(t.path),this.mode=t.mode!==void 0?this[Ys](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?X(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[d,u]=Nc(this.path);d&&typeof u=="string"&&(this.path=u,o=d)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new qn({path:this[Ct](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ct](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 $s({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[Ct](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ct](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)}[Ct](t){return cf(t,this.prefix)}[Ys](t){return af(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}},Kw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",$w=class br{tail;head;length=0;static create(e=[]){return new br(e)}constructor(e=[]){for(let r of e)this.push(r)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let r=e.next,i=e.prev;return r&&(r.prev=i),i&&(i.next=r),e===this.head&&(this.head=r),e===this.tail&&(this.tail=i),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,r}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let r=this.head;e.list=this,e.next=r,r&&(r.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let r=this.tail;e.list=this,e.prev=r,r&&(r.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let r=0,i=e.length;r<i;r++)Yw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)Zw(this,e[r]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,r=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,r.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,r=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,r.list=void 0,this.length--,e}forEach(e,r){r=r||this;for(let i=this.head,o=0;i;o++)e.call(r,i.value,o,this),i=i.next}forEachReverse(e,r){r=r||this;for(let i=this.tail,o=this.length-1;i;o--)e.call(r,i.value,o,this),i=i.prev}get(e){let r=0,i=this.head;for(;i&&r<e;r++)i=i.next;if(r===e&&i)return i.value}getReverse(e){let r=0,i=this.tail;for(;i&&r<e;r++)i=i.prev;if(r===e&&i)return i.value}map(e,r){r=r||this;let i=new br;for(let o=this.head;o;)i.push(e.call(r,o.value,this)),o=o.next;return i}mapReverse(e,r){r=r||this;var i=new br;for(let o=this.tail;o;)i.push(e.call(r,o.value,this)),o=o.prev;return i}reduce(e,r){let i,o=this.head;if(arguments.length>1)i=r;else if(this.head)o=this.head.next,i=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var c=0;o;c++)i=e(i,o.value,c),o=o.next;return i}reduceReverse(e,r){let i,o=this.tail;if(arguments.length>1)i=r;else if(this.tail)o=this.tail.prev,i=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let c=this.length-1;o;c--)i=e(i,o.value,c),o=o.prev;return i}toArray(){let e=new Array(this.length);for(let r=0,i=this.head;i;r++)e[r]=i.value,i=i.next;return e}toArrayReverse(){let e=new Array(this.length);for(let r=0,i=this.tail;i;r++)e[r]=i.value,i=i.prev;return e}slice(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new br;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.head,c=0;for(c=0;o&&c<e;c++)o=o.next;for(;o&&c<r;c++,o=o.next)i.push(o.value);return i}sliceReverse(e=0,r=this.length){r<0&&(r+=this.length),e<0&&(e+=this.length);let i=new br;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.length,c=this.tail;for(;c&&o>r;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,r=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let 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=Vw(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 Vw(t,e,r){let i=e,o=e?e.next:t.head,c=new Bc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function Yw(t,e){t.tail=new Bc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function Zw(t,e){t.head=new Bc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Bc=class{list;next;prev;value;constructor(t,e,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}},Ou=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Lu=Buffer.alloc(1024),Gs=Symbol("onStat"),pi=Symbol("ended"),mt=Symbol("queue"),gi=Symbol("pendingLinks"),xn=Symbol("current"),zn=Symbol("process"),mi=Symbol("processing"),Ls=Symbol("processJob"),wt=Symbol("jobs"),nc=Symbol("jobDone"),Hs=Symbol("addFSEntry"),Nu=Symbol("addTarEntry"),Ec=Symbol("stat"),bc=Symbol("readdir"),qs=Symbol("onreaddir"),js=Symbol("pipe"),Mu=Symbol("entry"),rc=Symbol("entryOpt"),Ws=Symbol("writeEntryClass"),lf=Symbol("write"),ic=Symbol("ondrain"),no=class extends jn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Ws];onWriteEntry;[mt];[gi]=new Map;[wt]=0;[mi]=!1;[pi]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=X(t.prefix||""),this.linkCache=t.linkCache||new Map,this.statCache=t.statCache||new Map,this.readdirCache=t.readdirCache||new Map,this.onWriteEntry=t.onWriteEntry,this[Ws]=df,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 rw(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new sw(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new aw(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[ic]()),this.on("resume",()=>e.resume())}else this.on("drain",this[ic]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[mt]=new $w,this[wt]=0,this.jobs=Number(t.jobs)||4,this[mi]=!1,this[pi]=!1}[lf](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[pi]=!0,this[zn](),r&&r(),this}write(t){if(this[pi])throw new Error("write after end");return typeof t=="string"?this[Hs](t):this[Nu](t),this.flowing}[Nu](t){let e=X(Pu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Ou(t.path,e);r.entry=new Ww(t,this[rc](r)),r.entry.on("end",()=>this[nc](r)),this[wt]+=1,this[mt].push(r)}this[zn]()}[Hs](t){let e=X(Pu.resolve(this.cwd,t));this[mt].push(new Ou(t,e)),this[zn]()}[Ec](t){t.pending=!0,this[wt]+=1;let e=this.follow?"stat":"lstat";Vs[e](t.absolute,(r,i)=>{t.pending=!1,this[wt]-=1,r?this.emit("error",r):this[Gs](t,i)})}[Gs](t,e){if(this.statCache.set(t.absolute,e),t.stat=e,!this.filter(t.path,e))t.ignore=!0;else if(e.isFile()&&e.nlink>1&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync)if(t===this[xn])this[Ls](t);else{let r=`${e.dev}:${e.ino}`,i=this[gi].get(r);i?i.push(t):this[gi].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[zn]()}[bc](t){t.pending=!0,this[wt]+=1,Vs.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[wt]-=1,e)return this.emit("error",e);this[qs](t,r)})}[qs](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[zn]()}[zn](){if(!this[mi]){this[mi]=!0;for(let t=this[mt].head;t&&this[wt]<this.jobs;t=t.next)if(this[Ls](t.value),t.value.ignore){let e=t.next;this[mt].removeNode(t),t.next=e}this[mi]=!1,this[pi]&&this[mt].length===0&&this[wt]===0&&(this.zip?this.zip.end(Lu):(super.write(Lu),super.end()))}}get[xn](){return this[mt]&&this[mt].head&&this[mt].head.value}[nc](t){this[mt].shift(),this[wt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[gi].get(r);if(i){this[gi].delete(r);for(let o of i)o.pending=!1,this[Ls](o)}}this[zn]()}[Ls](t){if(t.pending&&t.pendingLink&&t===this[xn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[xn]&&!t.piped&&this[js](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Gs](t,e):this[Ec](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[qs](t,e):this[bc](t),!t.readdir)return}if(t.entry=this[Mu](t),!t.entry){t.ignore=!0;return}t===this[xn]&&!t.piped&&this[js](t)}}}[rc](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}}[Mu](t){this[wt]+=1;try{return new this[Ws](t.path,this[rc](t)).on("end",()=>this[nc](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[ic](){this[xn]&&this[xn].entry&&this[xn].entry.resume()}[js](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Hs](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={}){eo(this,t,e,r)}},Fc=class extends no{sync=!0;constructor(t){super(t),this[Ws]=jw}pause(){}resume(){}[Ec](t){let e=this.follow?"statSync":"lstatSync";this[Gs](t,Vs[e](t.absolute))}[bc](t){this[qs](t,Vs.readdirSync(t.absolute))}[js](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Hs](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[lf](i)})}},Jw=(t,e)=>{let r=new Fc(t),i=new Zu(t.file,{mode:t.mode||438});r.pipe(i),uf(r,e)},Xw=(t,e)=>{let r=new no(t),i=new Xs(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 ff(r,e).catch(c=>r.emit("error",c)),o},uf=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Ir({file:Ju.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},ff=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Ir({file:Ju.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},Qw=(t,e)=>{let r=new Fc(t);return uf(r,e),r},e_=(t,e)=>{let r=new no(t);return ff(r,e).catch(i=>r.emit("error",i)),r},kI=Ci(Jw,Xw,Qw,e_,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),n_=process.env.__FAKE_PLATFORM__||process.platform,gf=n_==="win32",{O_CREAT:mf,O_NOFOLLOW:Bu,O_TRUNC:wf,O_WRONLY:_f}=pf.constants,yf=Number(process.env.__FAKE_FS_O_FILENAME__)||pf.constants.UV_FS_O_FILEMAP||0,r_=gf&&!!yf,i_=512*1024,s_=yf|wf|mf|_f,Fu=!gf&&typeof Bu=="number"?Bu|wf|mf|_f:null,Ef=Fu!==null?()=>Fu:r_?t=>t<i_?s_:"w":()=>"w",vc=(t,e,r)=>{try{return ro.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},Zs=(t,e,r,i)=>{ro.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},o_=(t,e,r,i,o)=>{if(e.isDirectory())bf(vi.resolve(t,e.name),r,i,c=>{if(c)return o(c);let d=vi.resolve(t,e.name);Zs(d,r,i,o)});else{let c=vi.resolve(t,e.name);Zs(c,r,i,o)}},bf=(t,e,r,i)=>{ro.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 Zs(t,e,r,i);let d=c.length,u=null,f=h=>{if(!u){if(h)return i(u=h);if(--d===0)return Zs(t,e,r,i)}};for(let h of c)o_(t,h,e,r,f)})},a_=(t,e,r,i)=>{e.isDirectory()&&vf(vi.resolve(t,e.name),r,i),vc(vi.resolve(t,e.name),r,i)},vf=(t,e,r)=>{let i;try{i=ro.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return vc(t,e,r);throw c}for(let o of i)a_(t,o,e,r);return vc(t,e,r)},Sf=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"}},io=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"}},d_=(t,e)=>{ot.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new Sf(t,r?.code||"ENOTDIR")),e(r)})},l_=(t,e,r)=>{t=X(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,d=e.uid,u=e.gid,f=typeof d=="number"&&typeof u=="number"&&(d!==e.processUid||u!==e.processGid),h=e.preserve,g=e.unlink,w=X(e.cwd),S=(v,I)=>{v?r(v):I&&f?bf(I,d,u,A=>S(A)):c?ot.chmod(t,o,r):r()};if(t===w)return d_(t,S);if(h)return c_.mkdir(t,{mode:o,recursive:!0}).then(v=>S(null,v??void 0),S);let _=X(Js.relative(w,t)).split("/");Sc(w,_,o,g,w,void 0,S)},Sc=(t,e,r,i,o,c,d)=>{if(e.length===0)return d(null,c);let u=e.shift(),f=X(Js.resolve(t+"/"+u));ot.mkdir(f,r,If(f,e,r,i,o,c,d))},If=(t,e,r,i,o,c,d)=>u=>{u?ot.lstat(t,(f,h)=>{if(f)f.path=f.path&&X(f.path),d(f);else if(h.isDirectory())Sc(t,e,r,i,o,c,d);else if(i)ot.unlink(t,g=>{if(g)return d(g);ot.mkdir(t,r,If(t,e,r,i,o,c,d))});else{if(h.isSymbolicLink())return d(new io(t,t+"/"+e.join("/")));d(u)}}):(c=c||t,Sc(t,e,r,i,o,c,d))},u_=t=>{let e=!1,r;try{e=ot.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new Sf(t,r??"ENOTDIR")}},f_=(t,e)=>{t=X(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,d=e.gid,u=typeof c=="number"&&typeof d=="number"&&(c!==e.processUid||d!==e.processGid),f=e.preserve,h=e.unlink,g=X(e.cwd),w=v=>{v&&u&&vf(v,c,d),o&&ot.chmodSync(t,i)};if(t===g)return u_(g),w();if(f)return w(ot.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=X(Js.relative(g,t)).split("/"),_;for(let v=S.shift(),I=g;v&&(I+="/"+v);v=S.shift()){I=X(Js.resolve(I));try{ot.mkdirSync(I,i),_=_||I}catch{let A=ot.lstatSync(I);if(A.isDirectory())continue;if(h){ot.unlinkSync(I),ot.mkdirSync(I,i),_=_||I;continue}else if(A.isSymbolicLink())return new io(I,I+"/"+S.join("/"))}}return w(_)},sc=Object.create(null),zu=1e4,gr=new Set,x_=t=>{gr.has(t)?gr.delete(t):sc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),gr.add(t);let e=sc[t],r=gr.size-zu;if(r>zu/10){for(let i of gr)if(gr.delete(i),delete sc[i],--r<=0)break}return e},h_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,p_=h_==="win32",g_=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=Af(i,r)),e.push(r||"/"),e},[]),m_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=p_?["win32 parallelization disabled"]:t.map(i=>bi(Af(x_(i))));let r=new Set(t.map(i=>g_(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let d=this.#e.get(c);if(!d||d?.[0]!==t)continue;let u=d[1];if(!u){this.#e.delete(c);continue}if(d.shift(),typeof u=="function")o.add(u);else for(let f of u)o.add(f)}for(let c of i){let d=this.#e.get(c),u=d?.[0];if(!(!d||!(u instanceof Set)))if(u.size===1&&d.length===1){this.#e.delete(c);continue}else if(u.size===1){d.shift();let f=d[0];typeof f=="function"&&o.add(f)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},w_=()=>process.umask(),Uu=Symbol("onEntry"),Ic=Symbol("checkFs"),Gu=Symbol("checkFs2"),Ac=Symbol("isReusable"),lt=Symbol("makeFs"),kc=Symbol("file"),Tc=Symbol("directory"),Ks=Symbol("link"),Hu=Symbol("symlink"),qu=Symbol("hardlink"),yi=Symbol("ensureNoSymlink"),ju=Symbol("unsupported"),Wu=Symbol("checkPath"),oc=Symbol("stripAbsolutePath"),wn=Symbol("mkdir"),He=Symbol("onError"),Ns=Symbol("pending"),Ku=Symbol("pend"),mr=Symbol("unpend"),ac=Symbol("ended"),cc=Symbol("maybeClose"),Rc=Symbol("skip"),Si=Symbol("doChown"),Ii=Symbol("uid"),Ai=Symbol("gid"),ki=Symbol("checkedCwd"),__=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ti=__==="win32",y_=1024,E_=(t,e)=>{if(!Ti)return re.unlink(t,e);let r=t+".DELETE."+hf(16).toString("hex");re.rename(t,r,i=>{if(i)return e(i);re.unlink(r,e)})},b_=t=>{if(!Ti)return re.unlinkSync(t);let e=t+".DELETE."+hf(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},$u=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,zc=class extends Ri{[ac]=!1;[ki]=!1;[Ns]=0;reservations=new m_;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(t={}){if(t.ondone=()=>{this[ac]=!0,this[cc]()},super(t),this.transform=t.transform,this.chmod=!!t.chmod,typeof t.uid=="number"||typeof t.gid=="number"){if(typeof t.uid!="number"||typeof t.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(t.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=t.uid,this.gid=t.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;this.preserveOwner=t.preserveOwner===void 0&&typeof t.uid!="number"?!!(process.getuid&&process.getuid()===0):!!t.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:y_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Ti,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=X(Ne.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:w_():0,this.umask=typeof t.umask=="number"?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.on("entry",e=>this[Uu](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[cc](){this[ac]&&this[Ns]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[oc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Nc(r),d=c.replaceAll(/\\/g,"/").split("/");if(d.includes("..")||Ti&&/^[a-z]:\.\.$/i.test(d[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let u=Ne.posix.dirname(t.path),f=Ne.posix.normalize(Ne.posix.join(u,d.join("/")));if(f.startsWith("../")||f==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:r}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:r})),!0}[Wu](t){let e=X(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=X(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}r.splice(0,this.strip),t.path=r.join("/")}if(isFinite(this.maxDepth)&&r.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:r.length,maxDepth:this.maxDepth}),!1;if(!this[oc](t,"path")||!this[oc](t,"linkpath"))return!1;if(t.absolute=Ne.isAbsolute(t.path)?X(Ne.resolve(t.path)):X(Ne.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:X(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=Ne.win32.parse(String(t.absolute));t.absolute=i+ku(String(t.absolute).slice(i.length));let{root:o}=Ne.win32.parse(t.path);t.path=o+ku(t.path.slice(o.length))}return!0}[Uu](t){if(!this[Wu](t))return t.resume();switch(t_.equal(typeof t.absolute,"string"),t.type){case"Directory":case"GNUDumpDir":t.mode&&(t.mode=t.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[Ic](t);default:return this[ju](t)}}[He](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[mr](),e.resume())}[wn](t,e,r){l_(X(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},r)}[Si](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}[Ii](t){return $u(this.uid,t.uid,this.processUid)}[Ai](t){return $u(this.gid,t.gid,this.processGid)}[kc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Xs(String(t.absolute),{flags:Ef(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[He](u,t),e()});let o=1,c=u=>{if(u){i.fd&&re.close(i.fd,()=>{}),this[He](u,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,f=>{f?this[He](f,t):this[mr](),e()})};i.on("finish",()=>{let u=String(t.absolute),f=i.fd;if(typeof f=="number"&&t.mtime&&!this.noMtime){o++;let h=t.atime||new Date,g=t.mtime;re.futimes(f,h,g,w=>w?re.utimes(u,h,g,S=>c(S&&w)):c())}if(typeof f=="number"&&this[Si](t)){o++;let h=this[Ii](t),g=this[Ai](t);typeof h=="number"&&typeof g=="number"&&re.fchown(f,h,g,w=>w?re.chown(u,h,g,S=>c(S&&w)):c())}c()});let d=this.transform&&this.transform(t)||t;d!==t&&(d.on("error",u=>{this[He](u,t),e()}),t.pipe(d)),d.pipe(i)}[Tc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[wn](String(t.absolute),r,i=>{if(i){this[He](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[mr](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[Si](t)&&(o++,re.chown(String(t.absolute),Number(this[Ii](t)),Number(this[Ai](t)),c)),c()})}[ju](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Hu](t,e){let r=X(Ne.relative(this.cwd,Ne.resolve(Ne.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[yi](t,this.cwd,r,()=>this[Ks](t,String(t.linkpath),"symlink",e),i=>{this[He](i,t),e()})}[qu](t,e){let r=X(Ne.resolve(this.cwd,String(t.linkpath))),i=X(String(t.linkpath)).split("/");this[yi](t,this.cwd,i,()=>this[Ks](t,r,"link",e),o=>{this[He](o,t),e()})}[yi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let d=Ne.resolve(e,c);re.lstat(d,(u,f)=>{if(u)return i();if(f?.isSymbolicLink())return o(new io(d,Ne.resolve(d,r.join("/"))));this[yi](t,d,r,i,o)})}[Ku](){this[Ns]++}[mr](){this[Ns]--,this[cc]()}[Rc](t){this[mr](),t.resume()}[Ac](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Ti}[Ic](t){this[Ku]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Gu](t,r))}[Gu](t,e){let r=d=>{e(d)},i=()=>{this[wn](this.cwd,this.dmode,d=>{if(d){this[He](d,t),r();return}this[ki]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let d=X(Ne.dirname(String(t.absolute)));if(d!==this.cwd)return this[wn](d,this.dmode,u=>{if(u){this[He](u,t),r();return}c()})}c()},c=()=>{re.lstat(String(t.absolute),(d,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Rc](t),r();return}if(d||this[Ac](t,u))return this[lt](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let f=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,h=g=>this[lt](g??null,t,r);return f?re.chmod(String(t.absolute),Number(t.mode),h):h()}if(t.absolute!==this.cwd)return re.rmdir(String(t.absolute),f=>this[lt](f??null,t,r))}if(t.absolute===this.cwd)return this[lt](null,t,r);E_(String(t.absolute),f=>this[lt](f??null,t,r))})};this[ki]?o():i()}[lt](t,e,r){if(t){this[He](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[kc](e,r);case"Link":return this[qu](e,r);case"SymbolicLink":return this[Hu](e,r);case"Directory":case"GNUDumpDir":return this[Tc](e,r)}}[Ks](t,e,r,i){re[r](e,String(t.absolute),o=>{o?this[He](o,t):(this[mr](),t.resume()),i()})}},wi=t=>{try{return[null,t()]}catch(e){return[e,null]}},kf=class extends zc{sync=!0;[lt](t,e){return super[lt](t,e,()=>{})}[Ic](t){if(!this[ki]){let o=this[wn](this.cwd,this.dmode);if(o)return this[He](o,t);this[ki]=!0}if(t.absolute!==this.cwd){let o=X(Ne.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[wn](o,this.dmode);if(c)return this[He](c,t)}}let[e,r]=wi(()=>re.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Rc](t);if(e||this[Ac](t,r))return this[lt](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[d]=c?wi(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[lt](d,t)}let[o]=wi(()=>re.rmdirSync(String(t.absolute)));this[lt](o,t)}let[i]=t.absolute===this.cwd?[]:wi(()=>b_(String(t.absolute)));this[lt](i,t)}[kc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=d=>{let u;try{re.closeSync(o)}catch(f){u=f}(d||u)&&this[He](d||u,t),e()},o;try{o=re.openSync(String(t.absolute),Ef(t.size),r)}catch(d){return i(d)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",d=>this[He](d,t)),t.pipe(c)),c.on("data",d=>{try{re.writeSync(o,d,0,d.length)}catch(u){i(u)}}),c.on("end",()=>{let d=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,f=t.mtime;try{re.futimesSync(o,u,f)}catch(h){try{re.utimesSync(String(t.absolute),u,f)}catch{d=h}}}if(this[Si](t)){let u=this[Ii](t),f=this[Ai](t);try{re.fchownSync(o,Number(u),Number(f))}catch(h){try{re.chownSync(String(t.absolute),Number(u),Number(f))}catch{d=d||h}}}i(d)})}[Tc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[wn](String(t.absolute),r);if(i){this[He](i,t),e();return}if(t.mtime&&!this.noMtime)try{re.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[Si](t))try{re.chownSync(String(t.absolute),Number(this[Ii](t)),Number(this[Ai](t)))}catch{}e(),t.resume()}[wn](t,e){try{return f_(X(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(r){return r}}[yi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let d of r){c=Ne.resolve(c,d);let[u,f]=wi(()=>re.lstatSync(c));if(u)return i();if(f.isSymbolicLink())return o(new io(c,Ne.resolve(e,r.join("/"))))}i()}[Ks](t,e,r,i){let o=`${r}Sync`;try{re[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[He](c,t)}}},v_=t=>{let e=new kf(t),r=t.file,i=xf.statSync(r),o=t.maxReadSize||16*1024*1024;new Hm(r,{readSize:o,size:i.size}).pipe(e)},S_=(t,e)=>{let r=new zc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("close",c),xf.stat(o,(u,f)=>{if(u)d(u);else{let h=new Dc(o,{readSize:i,size:f.size});h.on("error",d),h.pipe(r)}})})},Tf=Ci(v_,S_,t=>new kf(t),t=>new zc(t),(t,e)=>{e?.length&&of(t,e)}),I_=(t,e)=>{let r=new Fc(t),i=!0,o,c;try{try{o=st.openSync(t.file,"r+")}catch(f){if(f?.code==="ENOENT")o=st.openSync(t.file,"w+");else throw f}let d=st.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<d.size;c+=512){for(let g=0,w=0;g<512;g+=w){if(w=st.readSync(o,u,g,u.length-g,c+g),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!w)break e}let f=new qn(u);if(!f.cksumValid)break;let h=512*Math.ceil((f.size||0)/512);if(c+h+512>d.size)break;c+=h,t.mtimeCache&&f.mtime&&t.mtimeCache.set(String(f.path),f.mtime)}i=!1,A_(t,r,c,o,e)}finally{if(i)try{st.closeSync(o)}catch{}}},A_=(t,e,r,i,o)=>{let c=new Zu(t.file,{fd:i,start:r});e.pipe(c),T_(e,o)},k_=(t,e)=>{e=Array.from(e);let r=new no(t),i=(o,c,d)=>{let u=(S,_)=>{S?st.close(o,v=>d(S)):d(null,_)},f=0;if(c===0)return u(null,0);let h=0,g=Buffer.alloc(512),w=(S,_)=>{if(S||_===void 0)return u(S);if(h+=_,h<512&&_)return st.read(o,g,h,g.length-h,f+h,w);if(f===0&&g[0]===31&&g[1]===139)return u(new Error("cannot append to compressed archives"));if(h<512)return u(null,f);let v=new qn(g);if(!v.cksumValid)return u(null,f);let I=512*Math.ceil((v.size??0)/512);if(f+I+512>c||(f+=I+512,f>=c))return u(null,f);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),h=0,st.read(o,g,0,512,f,w)};st.read(o,g,0,512,f,w)};return new Promise((o,c)=>{r.on("error",c);let d="r+",u=(f,h)=>{if(f&&f.code==="ENOENT"&&d==="r+")return d="w+",st.open(t.file,d,u);if(f||!h)return c(f);st.fstat(h,(g,w)=>{if(g)return st.close(h,()=>c(g));i(h,w.size,(S,_)=>{if(S)return c(S);let v=new Xs(t.file,{fd:h,start:_});r.pipe(v),v.on("error",c),v.on("close",o),R_(r,e)})})};st.open(t.file,d,u)})},T_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Ir({file:Rf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},R_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Ir({file:Rf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},_i=Ci(I_,k_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!Zm(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")}),HI=Ci(_i.syncFile,_i.asyncFile,_i.syncNoFile,_i.asyncNoFile,(t,e=[])=>{_i.validate?.(t,e),C_(t)}),C_=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(r,i)=>e(r,i)&&!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0)):(r,i)=>!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0))};an();var ut={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",UPGRADE:"_agent/upgrade",DELETE:"_agent/delete",PUBLISH_SKILL:"_agent/publishSkill"};function so(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function Cf(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function oo(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Df(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function Pf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function Wn(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Kt();We();te();Oe();We();function Ar(t,e){if(so(t)!=="cloud")throw new T("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Di(t){return t.startsWith("http://")||t.startsWith("https://")}function kr(t){return t.endsWith("/")?t.slice(0,-1):t}import{readFileSync as OA}from"node:fs";import{dirname as NA,join as MA}from"node:path";import{fileURLToPath as FA}from"node:url";var Pt="0.1.104-alpha.23";We();te();var ao="1008033",Mf="1289";var Bf="pbbp2",Ff="https://www.coze.cn",zf="/api/coze_claw/resource/get_frontier_key",F_="https://www.coze.cn",z_="wss://frontier.coze.cn";function Tr(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??F_}function Uf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??z_}function En(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 Oi(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Pi=q("handshake");async function Uc(t){let e=Tr(t.endpoint),r=t.timeoutMs??1e4,i=`${kr(e)}${zf}?aid=${encodeURIComponent(ao)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...En(t.ppeOverride)},c=new AbortController,d=setTimeout(()=>c.abort(),r);Pi.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),f=u.headers.get("x-tt-logid")??"",h=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let v=await u.text().catch(()=>"");throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${f}: ${v.slice(0,200)}`)}let g=await u.json();if(g.code!==void 0&&g.code!==0)throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${g.code} msg=${g.msg??"-"} logid=${f}`);let w=g.data??{},S=typeof w.access_key=="string"&&w.access_key||typeof w.accessKey=="string"&&w.accessKey||void 0,_=typeof w.device_id=="string"&&w.device_id||typeof w.deviceId=="string"&&w.deviceId||void 0;if(!S||!_){let v=JSON.stringify(g).slice(0,500);throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${f}: ${v}`)}return Pi.info("handshake ok",{remoteDeviceId:_,logid:f,traceId:h}),{accessKey:S,deviceId:_}}catch(u){if(u instanceof T)throw Pi.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Pi.warn("handshake timeout",{base:e,timeoutMs:r}),new T("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let f=u.cause;throw Pi.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:f?.code,syscall:f?.syscall,cause:String(u).slice(0,300)}),new T("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(d)}}var Gc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",Et="auto",Gf=15e4;function Hf(t){return{model:Hc(t.model)??Et,...t.modelToken?{modelToken:t.modelToken}:{}}}function U_(t){return!t||t===Et}var G_=new Set(["auto","\u81EA\u52A8"]);function Hc(t){let e=t?.trim();if(e)return G_.has(e.toLowerCase())?Et:e}function qf(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Gc,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,e.CLAUDE_CODE_ATTRIBUTION_HEADER="0",t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else U_(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function jf(t,e,r){return t.modelToken?{baseUrl:`${Gc}/v1`,providerName:"coze",headers:{Authorization:`Bearer ${t.modelToken}`,...qc(e,r)}}:null}function Wf(t){if(!t.modelToken)return{};let e={model:t.model||Et,model_context_window:t.modelInfo?.contextWindow??Gf};return{CODEX_CONFIG:JSON.stringify(e)}}function qc(t,e){let{ttEnv:r,usePpe:i}=Oi(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Kf(t,e,r){if(!t.modelToken)return{};let i=qc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,d])=>`${c}:${d}`).join(`
92
+ `)}}function jc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function $f(t,e,r){if(!t.modelToken)return null;let i=t.model||Et,o=qc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let d={baseUrl:`${Gc}/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??Gf,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(d.headers=o),d}var fe=q("agent-handlers"),Yf=5*1024*1024,W_=1,K_=6,$_=new Set(["node_modules",".git",".coze","dist","build",".next"]),V_=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,Y_=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,Z_=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function J_(t){let e=t?.trim();return e?Z_.test(e)||Y_.test(e)?e:(fe.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function X_(t){return new Promise((e,r)=>{let i=rt("npx",t,{detached:!0,stdio:"ignore",windowsHide:!0}),o=!1,c=d=>{o||(o=!0,d?r(d):e(i.pid??0))};i.once("spawn",()=>{i.unref(),c()}),i.once("error",d=>c(d))})}var lo=class{constructor(e){this.opts=e}opts;async listSkills(e){e._meta;let r=Wn(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Ye(r).workspace,c=i?.skills??[],d=[],u=new Set;for(let f of c){let h=$e(o,f.relPath,"SKILL.md");await Vf(h).then(w=>w.isFile()).catch(()=>!1)&&(d.push(ny(f)),u.add(f.relPath))}if(e.scanLocal){let f=i?.framework??"claude-code",h=await Q_(r,o,f);for(let g of h)u.has(g.relPath)||(u.add(g.relPath),d.push(g.skill))}return{skills:d}}async addSkills(e){e._meta;let r=Wn(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],d=new Map(c.map((f,h)=>[f.skillId,h])),u=[];for(let f of o){let h=await uo({agentId:r,workspace:i.workspace,framework:i.framework,skill:f});fo(c,d,h),u.push(f)}return await ii(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){e._meta;let r=Wn(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],d=[];for(let u of c){if(!o.has(u.skillId)){d.push(u);continue}let f=$e(i.workspace,u.relPath);await $c(f,{recursive:!0,force:!0}),fe.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await ii(r,d),this.reloadAgentSessions(r,"skills-removed"),{ok:!0}}async publishSkill(e){e._meta;let r=Wn(e._meta);if(!e.skillName)throw new T("IPC_BAD_REQUEST","_agent/publishSkill: missing skillName");fe.info("_agent/publishSkill start",{agentId:r,skillId:e.skillId??"",skillName:e.skillName,userId:e.userId??"",accountId:e.accountId??""});let i=await this.loadAgentCfg(r),o=i?.workspace??Ye(r).workspace,c=i?.framework??"claude-code",d=t0(e.skillName),u=$e(Qc(c),d),f=$e(o,u),h=$e(f,"SKILL.md");if(!await Vf(h).then(R=>R.isFile()).catch(()=>!1))throw new T("SKILL_NOT_FOUND",`skill not found locally: ${e.skillName} (${u})`);let w=new Xc.default;w.addLocalFolder(f,d);let S=w.toBuffer();if(S.length>Zf)throw new T("SKILL_ZIP_TOO_LARGE",`skill zip ${S.length} bytes exceeds limit ${Zf}`);let _=await co(h,{encoding:"utf8"}).then(R=>r0(R).description).catch(()=>{}),v={};this.opts.publishSkillToMarketplace?v=await this.opts.publishSkillToMarketplace({zip:S,...e.skillId?{skillId:e.skillId}:{},skillName:e.skillName,..._?{description:_}:{},agentId:r,...e.userId?{userId:e.userId}:{},...e.accountId?{accountId:e.accountId}:{}}):fe.warn("_agent/publishSkill: publishSkillToMarketplace not injected, skip upload",{agentId:r,skillName:e.skillName});let I=v.version??"v1.0",A=v.skillId??e.skillId??n0(r,u);if(i){let R=i.skills??[],O=R.find(y=>y.relPath===u);O?(O.version=I,O.skillId=A):R.push({skillId:A,skillName:e.skillName,relPath:u,version:I,installedAt:Date.now(),..._?{description:_}:{}}),await ii(r,R)}return fe.info("skill published",{agentId:r,skillName:e.skillName,relPath:u,zipBytes:S.length,skillId:A,version:I}),{ok:!0,skillId:A,version:I}}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,fe.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d});continue}let f=c.downstream;c.downstream=void 0,fe.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d}),f.stop(r).catch(h=>fe.warn("downstream stop failed during reload (ignored)",{reason:r,agentId:e,cloudId:o,err:String(h)}))}}isRuntimePendingPermission(e){let r=this.opts.isRuntimePendingPermission;return!r||!e.downstream?!1:r(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return fe.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await Te(r);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return fe.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await dr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw fe.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 Fe(i),fe.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async upgradeBridge(e){let r=e.agentId||e._meta?.cozeAgentId;if(!r)throw new T("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await Te(r))throw new T("AGENT_NOT_FOUND",`agent not found: ${r}`);let o=["-y"];e.registry&&Di(e.registry)&&o.push(`--registry=${e.registry}`);let c=J_(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let d=e._meta?.cozeEnv;d&&V_.test(d)&&o.push("--env",d);let u=await X_(o);return fe.info("_agent/upgrade: spawned bridge upgrade process",{agentId:r,pid:u,targetVersion:c,currentVersion:e.currentVersion??"",reason:e.reason??""}),{ok:!0,accepted:!0,pid:u,message:"bridge upgrade started"}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new T("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Te(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Fe(i),fe.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}):(fe.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async deleteAgent(e){let r=e.agentId;if(!r)throw new T("IPC_BAD_REQUEST",`${ut.DELETE}: missing agentId`);let i=await Te(r),o=e._meta?.cozeDeployType==="cloud"||e._meta?.cozeDeployType==="local"?e._meta.cozeDeployType:void 0,c=e.deployType??o??i?.deployType??"local";this.opts.disposeForDelete&&await this.opts.disposeForDelete(r,e.reason??"delete");let d=Ye(r);return c==="cloud"?await $c(d.root,{recursive:!0,force:!0}):i&&(i.deletedAt=Date.now(),i.deleteReason=e.reason??"deleted",await Fe(i)),fe.info("agent deleted",{agentId:r,reason:e.reason??"",deployType:c,configFound:!!i}),{ok:!0}}async switchModel(e){if(Ar(e._meta,"_agent/switchModel"),!e.agentId)throw new T("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Hc(e.model)??Et,i=await Te(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 Fe(i),fe.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return fe.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=>fe.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(d)}));let c=[];for(let[d,u]of o.allSessionQueues())c.push(u.enqueue(async()=>{let f=o.sessions.get(d);f?.downstream&&(await f.downstream.stop(`switchModel: ${r}`).catch(()=>{}),f.downstream=void 0)}));return await Promise.all(c),fe.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(Ar(e._meta,ut.RESET),!e.agentId)throw new T("IPC_BAD_REQUEST",`${ut.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,ut.RESET),await this.runDetailSync(e.agentId,ut.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),fe.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 ri(e,o)}async clearPersistedAcpSessionIds(e){let r=await Te(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 Fe(r)}async repairAgent(e){if(Ar(e._meta,ut.REPAIR),!e.agentId)throw new T("IPC_BAD_REQUEST",`${ut.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new T("IPC_BAD_REQUEST",`${ut.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){fe.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,ut.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){fe.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){fe.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){Ar(e._meta,"_agent/getFileTree");let r=e._meta,i=Wn(r),o=await this.resolveWorkspace(i),c=e.filePath??"",d=this.safeJoin(o,c),u=await Wc(d).catch(()=>null);if(!u)throw new T("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await ni(d,o))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let f=hy(e.depth);return u.isDirectory()?{tree:await xy(o,d,c,f)}:{tree:[{name:py(c),path:o0(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){Ar(e._meta,"_agent/getFileContent");let r=Wn(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 Wc(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 ni(o,i))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Yf)throw new T("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Yf})`);let d=await co(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 Te(e).catch(()=>null))?.workspace??Ye(e).workspace}safeJoin(e,r){let i=Yc(e,r||"."),o=Jc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Xf}`))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return Te(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 t0(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 Qc(t){return t==="claude-code"?$e(".claude","skills"):$e(".agents","skills")}function n0(t,e){return(H_("sha256").update(`${t}\0${e}`).digest().readBigUInt64BE(0)&0x7fffffffffffffffn).toString()}function r0(t){if(!t.startsWith("---"))return{};let e=t.indexOf(`
93
+ ---`,3);if(e<0)return{};let r=t.slice(3,e),i={};for(let o of r.split(`
94
+ `)){let c=/^\s*(name|description)\s*:\s*(.+?)\s*$/.exec(o);if(!c||!c[2])continue;let d=c[1],u=c[2].trim();(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))&&(u=u.slice(1,-1)),u&&(i[d]=u)}return i}async function Q_(t,e,r){let i=Qc(r),o=$e(e,i),c=await Jf(o,{withFileTypes:!0}).catch(()=>null);if(!c)return[];let d=[];for(let u of c){if(!u.isDirectory())continue;let f=u.name,h=$e(i,f),g=$e(o,f,"SKILL.md"),w=await co(g,{encoding:"utf8"}).catch(()=>null);if(w===null)continue;let S=r0(w);d.push({relPath:h,skill:{skillId:n0(t,h),skillName:S.name||f,...S.description?{description:S.description}:{}}})}return d}var ey=3e4,ty=50*1024*1024,Zf=10*1024*1024,Rr=3e4;async function uo(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new T("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,d=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!d)throw new T("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=t0(o.skillName),f=Qc(i),h=$e(f,u),g=$e(r,h);if(await Kc(g,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");Li(S.length),await Vc($e(g,"SKILL.md"),S,"utf8")}else{let S=await iy(o.downloadUrl);oy(S)?await ly(S,g):ay(S)?await cy(S,g):await Vc($e(g,"SKILL.md"),S.toString("utf8"),"utf8")}let w={skillId:o.skillId,skillName:o.skillName,relPath:h,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return fe.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:h,source:c?"content":"downloadUrl"}),w}function fo(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 ny(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}function ry(t){return{skillId:t.skillId,skillName:t.skillName,...t.downloadUrl?{downloadUrl:t.downloadUrl}:{},...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function i0(t,e){let r=await Te(t,e);if(!r)return{status:"skipped",count:0};if(r.disconnectedAt)return{status:"skipped",count:0};let i=Pt,o=r.skillsRefreshedForVersion;if(o===i)return{status:"noop",count:0};if(!o)return r.skillsRefreshedForVersion=i,await Fe(r,e),{status:"seeded",count:0};let c=[...r.skills??[]],d=new Map(c.map((g,w)=>[g.skillId,w])),u=c.filter(g=>g.builtin===!0&&!!g.downloadUrl);if(u.length===0)return r.skillsRefreshedForVersion=i,await Fe(r,e),{status:"noop",count:0};let f=0,h=0;for(let g of u)try{await $c($e(r.workspace,g.relPath),{recursive:!0,force:!0});let w=await uo({agentId:t,workspace:r.workspace,framework:r.framework,skill:ry(g)});fo(c,d,w),f+=1}catch(w){h+=1,fe.warn("refresh builtin skill failed (skipping)",{agentId:t,skillId:g.skillId,skillName:g.skillName,err:String(w)})}return r.skills=c,h===0&&(r.skillsRefreshedForVersion=i),await Fe(r,e),fe.info("builtin skills refreshed after bridge upgrade",{agentId:t,from:o,to:i,ok:f,failed:h}),{status:"refreshed",count:f}}async function iy(t){if(!t)throw new T("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Li(e);let r=sy(t);return Li(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await co(e);return Li(r.length),r}if(Di(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),ey);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 Li(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 Li(t){if(t>ty)throw new T("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function sy(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 oy(t){return t.length>=2&&t[0]===31&&t[1]===139}function ay(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],r=t[3];return e===3&&r===4||e===5&&r===6}function Zc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function cy(t,e){let r,i;try{r=new Xc.default(t),i=r.getEntries()}catch(d){throw new T("IPC_BAD_REQUEST",`zip parse failed: ${d.message}`,{cause:d})}for(let d of i){let u=d.entryName;if(!u||Zc(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new T("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(h=>h===".."))throw new T("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let f=d.header.attr>>>16&61440;if(f!==0&&f!==32768&&f!==16384)throw new T("IPC_BAD_REQUEST",`zip entry kind 0x${f.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=dy(i),c=Yc(e);for(let d of i){if(Zc(d.entryName))continue;let u=d.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let f=Yc(e,u),h=Jc(c,f);if(h.startsWith("..")||h==="..")throw new T("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(d.isDirectory){await Kc(f,{recursive:!0});continue}await Kc(q_(f),{recursive:!0});let g;try{g=d.getData()}catch(w){throw new T("IPC_BAD_REQUEST",`zip entry getData failed (${d.entryName}): ${w.message}`,{cause:w})}await Vc(f,g)}}function dy(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 ly(t,e){await uy(t);let r=Tf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar extract timeout (${Rr}ms)`))},Rr);try{await e0(Qf.from(t),r)}catch(c){throw c instanceof T?c:i?new T("IPC_BAD_REQUEST",`tar extract timeout (${Rr}ms)`):new T("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function uy(t){let e=[],r=Ir({onReadEntry:c=>{let d=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' not allowed (symlink/hardlink/special): ${d.slice(0,100)}`);return}if(d.startsWith("/")||d.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(d)){e.push(`tar entry absolute path: ${d}`);return}d.split(/[/\\]/).some(h=>h==="..")&&e.push(`tar entry contains '..': ${d}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar list timeout (${Rr}ms)`))},Rr);try{await e0(Qf.from(t),r)}catch(c){throw i?new T("IPC_BAD_REQUEST",`tar list timeout (${Rr}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 fy=5e3;async function xy(t,e,r,i){return s0(t,e,r,i,{count:0})}async function s0(t,e,r,i,o){if(i<=0)return[];let c;try{c=await Jf(e,{withFileTypes:!0})}catch{return[]}let d=[];for(let u of c){if($_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=fy){d.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let f=$e(e,u.name),h=j_($e(r,u.name)),g=null;try{g=await Wc(f)}catch{continue}if(g.isSymbolicLink())continue;o.count++;let w={name:u.name,path:o0(Jc(t,f)),isDir:g.isDirectory(),size:g.size,modifiedAt:Math.floor(g.mtimeMs)};g.isDirectory()&&i>1&&(w.children=await s0(t,f,h,i-1,o)),d.push(w)}return d.sort((u,f)=>u.isDir!==f.isDir?u.isDir?-1:1:u.name.localeCompare(f.name)),d}function hy(t){return!t||t<=0?W_:Math.min(t,K_)}function py(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function o0(t){return t.split(Xf).join("/")}te();var bn=q("agent-health-reporter"),gy=1e4,my=3,Ni=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??gy,this.livenessFailureThreshold=e.livenessFailureThreshold??my}opts;timer=null;inFlight=!1;unsubscribeRegister=null;intervalMs;livenessFailureThreshold;consecutiveFailures=0;isLivenessLost(){return this.consecutiveFailures>=this.livenessFailureThreshold}start(){this.timer||(this.timer=setInterval(()=>{this.tick()},this.intervalMs),this.timer.unref?.(),this.unsubscribeRegister=this.opts.core.onAgentRegister(()=>{this.tick()}),bn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),bn.info("heartbeat stopped"))}async tick(){if(this.inFlight){bn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){this.consecutiveFailures=0,bn.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let r=[];for(let d of this.opts.core.agents.values()){let u=wy(d);if(!u)continue;let f={agentId:d.agentId,status:u};d.patToken&&(f.patToken=d.patToken),d.accountId&&(f.accountId=d.accountId),r.push(f)}if(r.length===0){this.consecutiveFailures=0;return}let i={agents:r,bridgeVersion:Pt,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3),this.consecutiveFailures=0}catch(d){this.consecutiveFailures+=1,bn.warn("heartbeat batch send failed",{count:r.length,consecutiveFailures:this.consecutiveFailures,err:String(d)})}let c=o?.authFailures;if(c&&c.length>0&&(bn.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){bn.warn("onAuthFailures callback failed (ignored)",{err:String(d)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){bn.warn("onTickEnd hook failed",{err:String(r)})}}};function wy(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}an();import{mkdir as sd,rm as fE,stat as xE}from"node:fs/promises";import{homedir as hE}from"node:os";import{join as ad}from"node:path";rn();import{existsSync as Dy}from"node:fs";import{release as Py}from"node:os";import{basename as Oy,isAbsolute as Ly}from"node:path";function Mi(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Cr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Dr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function vn(t,e){return{jsonrpc:"2.0",id:t,error:e}}We();var xo=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)}},Z={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021,SKILL_NOT_FOUND:-32022,SKILL_ZIP_TOO_LARGE:-32023,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32024};function a0(t){return"method"in t&&"id"in t&&t.id!==void 0}function c0(t){return"method"in t&&!("id"in t)}function ho(t){return!("method"in t)&&"id"in t}var _y={AGENT_NOT_FOUND:Z.AGENT_NOT_FOUND,AGENT_BUSY:Z.AGENT_BUSY,AGENT_DISCONNECTED:Z.AGENT_DISCONNECTED,AGENT_TIMEOUT:Z.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:Z.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:Z.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:Z.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:Z.INTERNAL_ERROR,BRIDGE_INTERNAL:Z.INTERNAL_ERROR,IPC_AUTH_FAILED:Z.INTERNAL_ERROR,IPC_BAD_REQUEST:Z.INVALID_REQUEST,METHOD_NOT_FOUND:Z.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:Z.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:Z.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:Z.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:Z.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:Z.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:Z.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:Z.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:Z.FILE_TOO_LARGE,UNSUPPORTED_MIME:Z.UNSUPPORTED_MIME,UPLOAD_FAILED:Z.UPLOAD_FAILED,UPSTREAM_NOT_READY:Z.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:Z.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:Z.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:Z.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:Z.AGENT_ENV_NOT_READY,SKILL_NOT_FOUND:Z.SKILL_NOT_FOUND,SKILL_ZIP_TOO_LARGE:Z.SKILL_ZIP_TOO_LARGE};function yy(t){if(t!=null)return t instanceof Error?{name:t.name,message:Bi(t.message)}:typeof t=="string"?Bi(t):typeof t=="object"?by(t):t}var Ey=[[/\/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 Bi(t){let e=t;for(let[r,i]of Ey)e=e.replace(r,i);return e}function by(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Bi(i):e[r]=i;return e}function Fi(t){if(t instanceof T){let e=yy(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:_y[t.code]??Z.INTERNAL_ERROR,message:Bi(t.message),data:r}}return{code:Z.INTERNAL_ERROR,message:Bi(t instanceof Error?t.message:String(t))}}function d0(t){let e=t.data,r=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:d,...u}=e;c=u}return new T(r,o,{retriable:e?.retriable??!1,cause:c})}function u0(t){return`${JSON.stringify(t)}
95
+ `}var l0=10*1024*1024,po=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>l0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${l0} bytes`)}),[]}let r=this.buffer.split(`
96
+ `);this.buffer=r.pop()??"";let i=[];for(let o of r){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(d){this.onError?.({line:c,error:d})}}return i}flush(){if(!this.buffer)return[];let e=this.buffer.replace(/\r$/,"").trim();if(this.buffer="",!e)return[];try{return[JSON.parse(e)]}catch(r){return this.onError?.({line:e,error:r}),[]}}};var x0={"session/prompt":"session.prompt","session/cancel":"session.cancel","session/new":"session.new","session/load":"session.load","_agent/create":"agent.create","_agent/health":"agent.health","_agent/pair":"agent.pair","_agent/listSkills":"agent.listSkills","_agent/addSkills":"agent.addSkills","_agent/removeSkills":"agent.removeSkills","_agent/getFileTree":"agent.getFileTree","_agent/getFileContent":"agent.getFileContent","_agent/detail":"agent.detail","_agent/update":"agent.update","_agent/disconnect":"agent.disconnect","_agent/switchModel":"agent.switchModel","_agent/genModelToken":"agent.genModelToken","_agent/reset":"agent.reset","_agent/repair":"agent.repair","session/request_permission":"session.requestPermission","session/set_mode":"session.setMode",initialize:"initialize"},bk=Object.fromEntries(Object.entries(x0).map(([t,e])=>[e,t])),vy={"session.prompt":["agentId","triggerMsgId","sessionId"],"session.cancel":["agentId","triggerMsgId","sessionId"],"session.new":["agentId"],"session.load":["agentId"],"agent.create":["agentId"],"agent.health":[],"agent.listSkills":["agentId"],"agent.addSkills":["agentId"],"agent.removeSkills":["agentId"],"agent.getFileTree":["agentId"],"agent.getFileContent":["agentId"],"agent.detail":["agentId"],"agent.update":["agentId"],"agent.disconnect":["agentId"],"agent.switchModel":["agentId"],"agent.genModelToken":["agentId","sessionId"],"agent.reset":["agentId"],"agent.repair":["agentId"],"session.requestPermission":["agentId","sessionId"],"session.setMode":["agentId","sessionId"],"agent.pair":[],initialize:[]},Pr=class{seq=0;next(e,r){this.seq+=1;let i=x0[e]??Sy(e),o=vy[i]??[],c=[i,String(this.seq)];if(o.length>0){let d=o.map(f=>f0(r?.[f]??"")),u=Iy(d).join(":");u&&c.push(u)}else r&&Object.values(r).some(d=>d)&&c.push(Object.values(r).filter(Boolean).map(d=>f0(String(d))).join(":"));return c.join("_")}reset(){this.seq=0}};function Sy(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function f0(t){return t.replace(/[:_\s]+/g,"-")}function Iy(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}on();import{readFileSync as Ay}from"node:fs";var ky=384;async function ed(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await cr(t.agentEnvFile,r,{mode:ky})}function td(t){try{let e=JSON.parse(Ay(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function h0(t,e,r={},i=o=>o){return{...i({...t,...td(e)}),...r}}Kt();rr();We();te();Oe();import{execFileSync as Ty,spawnSync as Ry}from"node:child_process";function zi(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function Ui(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),Ry("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var nd=new Set;function p0(t){typeof t=="number"&&t>0&&nd.add(t)}function g0(t){typeof t=="number"&&nd.delete(t)}function m0(){for(let t of nd)Ui(t,"SIGKILL")}var Or="coze-bridge-daemon";function w0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return Ty("pgrep",["-U",String(o),"-f",Or],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:2e3})}),r;try{r=e()}catch{return[]}let i=process.pid;return r.split(`
97
+ `).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function _0(t,e){if(t.length===0)return;let r=e?.killFn??Ui,i=e?.isAliveFn??zi,o=e?.sleepFn??(u=>new Promise(f=>setTimeout(f,u))),c=e?.graceMs??3e3,d=e?.pollMs??100;for(let u of t)r(u,"SIGTERM");for(let u=0;u<c&&t.some(f=>i(f));u+=d)await o(Math.min(d,c-u));for(let u of t)i(u)&&r(u,"SIGKILL")}var Cy=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: (Node binary not found|QCLAW_CLI_NODE_BINARY not set)/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @(zed-industries|agentclientprotocol)\/codex-acp|optional dependency was not installed|\.resolve is not a function/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"acp_module_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code","codex"],match:/Cannot find module[^\n]*node_modules[\\/]@(agentclientprotocol[\\/](claude-agent-acp|codex-acp)|zed-industries[\\/]codex-acp)/i,message:"ACP \u4F9D\u8D56\u672A\u6B63\u786E\u5B89\u88C5 (wrapper \u5165\u53E3\u7F3A\u5931)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u91CD\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"},{reason:"prompt_too_long",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code"],match:/Prompt is too long|bad request: failed to read body: length limit exceeded/i,message:"\u672C\u8F6E\u8F93\u5165\u8FC7\u957F\uFF0C\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u7CBE\u7B80\u8F93\u5165\u6216\u5F00\u542F\u65B0\u4F1A\u8BDD\u540E\u91CD\u8BD5"}];function y0(t,e){if(!e)return null;for(let r of Cy)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function E0(t,e){return y0(t,e)}function b0(t,e){return y0(t,e)}function Lr(t,e,r){return!e&&r.firstUpdateMs>0&&t<r.firstUpdateMs?Math.max(1,r.firstUpdateMs-t):t<r.phase2GateMs?Math.max(1,r.phase2GateMs-t):Math.max(1,r.livenessWindowMs)}function v0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let h=t.suspendedMs+o,g=r-t.startedAt-h;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Lr(g,t.firstFrameSeen,e)}}let c=r-t.startedAt-t.suspendedMs,d=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=d?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Lr(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Lr(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Lr(c,!1,e)}}var S0=Ve("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),Ny=200,My=40,By=Ve("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),Fy=Ve("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),zy=Ve("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),Uy=Ve("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),Gy=Ve("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Hy=Ve("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),I0=500;function qy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=I0?t:`${e.slice(0,I0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function jy(t){let e=[];typeof t.message=="string"&&e.push(t.message);let{data:r}=t;if(typeof r=="string")e.push(r);else if(r&&typeof r=="object")try{e.push(JSON.stringify(r))}catch{}return e.join(" ")}function A0(t){try{return Dy(t)}catch{return}}function Wy(t,e){return{platform:process.platform,osRelease:Py(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:Ly(e.command)?A0(e.command):void 0,cwd:e.cwd,cwdExists:A0(e.cwd),envKeys:e.envKeys}}function Ky(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${Oy(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Ot=class{constructor(e){this.opts=e;this.log=q(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new po({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Pr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;spawnEnv={};sanitizeEnv(e){return e}async start(){if(this.child)throw new T("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=h0(process.env,this.opts.agentEnvFile??Q().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o));this.spawnEnv=r;let i=rt(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,p0(i.pid),i.stdout?.setEncoding("utf8"),i.stdout?.on("data",o=>{try{for(let c of this.decoder.push(o))this.dispatch(c)}catch(c){this.log.warn("stdout dispatch threw, swallowed to keep daemon alive",{err:String(c)})}}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",o=>{let c=o.trimEnd();this.stderrRing.push(c),this.stderrRing.length>Ny&&this.stderrRing.shift(),this.log.debug("stderr",{text:c})}),i.stdin?.on("error",o=>{this.log.warn("child stdin error",{err:String(o)})}),i.stdout?.on("error",o=>{this.log.warn("child stdout error",{err:String(o)})}),i.stderr?.on("error",o=>{this.log.warn("child stderr error",{err:String(o)})}),i.on("exit",(o,c)=>{this.stopped=!0,g0(i.pid),(o!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:c,recentStderr:[...this.stderrRing]});try{for(let u of this.decoder.flush())this.dispatch(u)}catch(u){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(u)})}this.failAllPending(this.buildExitError(o,c));for(let u of this.exitHandlers)u(o,c)}),i.on("error",o=>{let c=o,d=Wy(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",Ky(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()));Ui(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Ui(r.pid,"SIGKILL")},5e3);try{await i}finally{clearTimeout(o)}}pid(){return this.child?.pid}isAlive(){return!!this.child&&!this.stopped}getStderrTail(e){return e===void 0?[...this.stderrRing]:this.stderrRing.slice(-e)}initialize(e){return this.call("initialize",e)}sessionNew(e){return this.call("session/new",{mcpServers:[],...e})}sessionLoad(e){return this.call("session/load",{mcpServers:[],...e})}sessionPrompt(e,r){let i={firstUpdateMs:Gy,phase2GateMs:By,livenessWindowMs:Fy,absoluteMaxMs:zy,approvalMaxMs:Hy,suspendThresholdMs:Uy,...r};return this.call("session/prompt",e,S0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Cr("session/cancel",e))}setSessionMode(e){return this.call("session/set_mode",e)}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Dr(e,r))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(vn(e,r))}catch(i){this.log.warn("respondAgentRequestError write failed",{id:e,err:String(i)})}}onExit(e){this.exitHandlers.push(e)}call(e,r,i=S0,o){if(!this.child||this.stopped)return Promise.reject(new T("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),d=Mi(c,e,r),u=(()=>{if(typeof r!="object"||r===null)return;let f=r.sessionId;return typeof f=="string"?f:void 0})();return new Promise((f,h)=>{let g={resolve:f,reject:h,timer:null,method:e,promptTimeout:null};if(o){let w=this.now(),S={cfg:o,startedAt:w,lastActivityAt:w,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:w,expectedIntervalMs:Lr(0,!1,o),sessionId:u};g.promptTimeout=S;let _=()=>{let v={startedAt:S.startedAt,lastActivityAt:S.lastActivityAt,firstFrameSeen:S.firstFrameSeen,hasActiveTool:S.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:S.suspendedMs,armedAt:S.armedAt,expectedIntervalMs:S.expectedIntervalMs},I=this.now(),A=v0(v,S.cfg,I),R=O=>{S.armedAt=I,S.expectedIntervalMs=O,g.timer=setTimeout(_,O)};if(A.action==="suspend"){S.suspendedMs+=A.suspendedDeltaMs,S.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:A.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),R(A.rearmMs);return}if(A.action==="continue"){R(A.rearmMs);return}this.pending.delete(c),A.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:A.awaitingApproval,...S.sessionId?{sessionId:S.sessionId}:{}}),h(A.awaitingApproval?new T("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new T("AGENT_TIMEOUT",`${e} timed out after ${S.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...S.sessionId?{sessionId:S.sessionId}:{}}),h(new T("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};g.timer=setTimeout(_,S.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(g.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),h(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,g);try{this.writeFrame(d)}catch(w){g.timer&&clearTimeout(g.timer),this.pending.delete(c),h(w)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new T("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(u0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(ho(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new T("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:qy(e.result)}),r.resolve(e.result));return}if(c0(e)){if(e.method==="session/update"){let r=e.params;for(let i of this.pending.values()){let o=i.promptTimeout;o&&(o.firstFrameSeen=!0,o.lastActivityAt=this.now(),this.trackToolCall(o,r))}for(let i of this.updateHandlers)try{Promise.resolve(i(r)).catch(o=>this.log.warn("update handler failed (async)",{err:String(o)}))}catch(o){this.log.warn("update handler threw sync, swallowed",{err:String(o)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(a0(e)){let r=e;try{this.handleAgentRequest(r).catch(i=>this.log.error("agent request handler failed (async)",{method:r.method,err:String(i)}))}catch(i){this.log.warn("handleAgentRequest threw sync, swallowed",{method:r.method,err:String(i)})}}}trackToolCall(e,r){let i=r.update,o=i?.sessionUpdate;if(o!=="tool_call"&&o!=="tool_call_update")return;let c=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!c)return;let d=typeof i.status=="string"?i.status:void 0,u=d==="completed"||d==="failed"||d==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(vn(e.id,{code:-32601,message:`method not handled by Bridge: ${e.method}`}));return}this.inflightAgentRequests.set(e.id,e.method);for(let r of this.agentRequestHandlers)try{await r(e)}catch(i){this.log.error("agentRequestHandler threw",{method:e.method,err:String(i)});try{this.writeFrame(vn(e.id,Fi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=d0(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=b0(this.framework,jy(e));return i?new T(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):r}buildExitError(e,r){if(this.stopReason!==void 0)return new T("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(My).join(`
98
+ `),o=E0(this.framework,i);return o?new T(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new T("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function $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 go=class extends Ot{framework="claude-code";constructor(e){let{command:r,args:i}=ti("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)}};rn();import{mkdtempSync as Jy,rmSync as Xy}from"node:fs";import{tmpdir as Qy}from"node:os";import{join as eE}from"node:path";import{readFileSync as T0}from"node:fs";import{homedir as Vy}from"node:os";import{join as k0}from"node:path";function R0(t){let e=t.CODEX_HOME?.trim()||k0(t.HOME?.trim()||Vy(),".codex");return k0(e,"config.toml")}function Yy(t){let e=null;for(let r=0;r<t.length;r++){let i=t[r];if(e)i===e&&(e=null);else if(i==='"'||i==="'")e=i;else if(i==="#")return t.slice(0,r)}return t}function Zy(t){let e=t.trim();if(e.length>=2){let r=e[0];if((r==='"'||r==="'")&&e[e.length-1]===r)return e.slice(1,-1)}return e}function C0(t){let e={},r={},i=e;for(let o of t.split(/\r?\n/)){let c=Yy(o).trim();if(!c)continue;let d=/^\[([^\]]+)\]$/.exec(c);if(d){let h=(d[1]??"").trim(),g=r[h]??{};r[h]=g,i=g;continue}let u=c.indexOf("=");if(u<=0)continue;let f=c.slice(0,u).trim();f&&(i[f]=Zy(c.slice(u+1)))}return{root:e,tables:r}}function D0(t){let e=t.root.model_provider;if(!e||e==="openai")return null;let r=t.tables[`model_providers.${e}`];return r?{providerId:e,baseUrl:r.base_url,envKey:r.env_key,bearerToken:r.experimental_bearer_token}:null}function P0(t){let e;try{e=T0(R0(t),"utf8")}catch{return null}return D0(C0(e))?.providerId??null}function O0(t){let e;try{e=T0(R0(t),"utf8")}catch{return null}let r=D0(C0(e));if(!r?.baseUrl)return null;let i=r.bearerToken||(r.envKey?t[r.envKey]?.trim():void 0);return i?{baseUrl:r.baseUrl,providerName:r.providerId,headers:{Authorization:`Bearer ${i}`}}:null}var mo=class t extends Ot{framework="codex";authRequest;resolveLocalGatewayAuth;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=ti("codex",e.command,i),d=e.isolateCodexHome?Jy(eE(Qy(),"coze-bridge-codex-home-")):void 0,u=d?{...e.env??{},CODEX_HOME:d}:e.env,f={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(f),this.authRequest=e.authRequest,this.resolveLocalGatewayAuth=e.resolveLocalGatewayAuth??!1,this.codexHomeDir=d}async initialize(e){let r=await super.initialize(e),i=this.authRequest??this.localGatewayAuthRequest();return i&&await this.call("authenticate",i),r}localGatewayAuthRequest(){if(!this.resolveLocalGatewayAuth)return null;let e=O0(this.spawnEnv);return e?(this.log.info("codex local: \u7528 config.toml custom provider \u8D70 gateway \u8BA4\u8BC1",{providerName:e.providerName,baseUrl:e.baseUrl}),{methodId:"gateway",_meta:{gateway:e}}):null}static MODE_ID_MAP={"read-only":"read-only",auto:"agent","full-access":"agent-full-access"};setSessionMode(e){let r=t.MODE_ID_MAP[e.modeId]??e.modeId;return super.setSessionMode({...e,modeId:r})}async stop(e){if(await super.stop(e),this.codexHomeDir)try{Xy(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};We();var tE=3e4,Nr=class extends Ot{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},tE))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new T("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var L0=["default","acceptEdits","plan","auto","bypassPermissions"],N0=["read-only","auto","full-access"];function Sn(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return L0.includes(e);case"codex":return N0.includes(e);case"openclaw":return!1}}function rd(t){switch(t){case"claude-code":return L0.join("/");case"codex":return N0.join("/");case"openclaw":return""}}on();We();te();Oe();function id(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}rn();var In=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 wo=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 In,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)Gi(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 Gi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function $t(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Kt();te();import{constants as M0}from"node:fs";import{access as nE}from"node:fs/promises";import{delimiter as rE,join as iE}from"node:path";var bt=q("framework-detector"),B0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},sE=[".exe",".cmd",".bat",".ps1"],Kn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??rt,access:e.access??nE}}async detect(e){let r=B0[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,d]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return d&&(u.defaultAgent=d),u}async detectAll(){let e=await Promise.all(Object.keys(B0).map(async i=>[i,await this.detect(i)])),r={};for(let[i,o]of e)o&&(r[i]=o);return r}async which(e){let r=this.env.pathEnv.split(rE).filter(Boolean),i=this.env.platform==="win32"?["",...sE]:[""];for(let o of r)for(let c of i){let d=iE(o,e+c);if(await this.isExecutable(d))return d}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?M0.F_OK:M0.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(d=>d?.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 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){bt.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&&(aE(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,d,u=f=>{c||(c=!0,d&&clearTimeout(d),i(f))};try{let f=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});d=setTimeout(()=>{f.kill("SIGKILL"),u(null)},15e3),f.stdout?.on("data",h=>{o+=h.toString("utf8")}),f.on("error",()=>u(null)),f.on("close",h=>u({code:h,stdout:o}))}catch{u(null)}})}},oE=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function aE(t){return t.replace(oE,"")}import{homedir as cE}from"node:os";import{join as dE}from"node:path";on();Kt();rr();We();te();async function U0(){let t=dE(cE(),".openclaw/openclaw.json");return(await ar(t))?.gateway?.auth?.token??""}var F0=q("openclaw.config"),lE=[0,5e3,5e3],uE=Ve("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),z0="models.providers.",_o="agents.defaults.models",yo=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new In;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??lE,this.cliTimeoutMs=e.cliTimeoutMs??uE}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,F0.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=rt(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",d=!1,u=h=>{d||(d=!0,clearTimeout(f),h())};o.stderr?.on("data",h=>{c+=h.toString("utf8")});let f=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);f.unref(),o.on("error",h=>u(()=>i(h))),o.on("close",h=>u(()=>{h===0?r():i(new Error(`exit ${h}: ${c.trim().slice(0,500)}`))}))})}async runCliTolerant(e,r){try{await this.runCli(e)}catch(i){let o=String(i);if(r.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,r){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",r])))}catch(i){F0.warn(`${e} failed (best-effort)`,{configPath:r,err:String(i)})}}ensureProvider(e,r){return this.queue.enqueue(()=>this.withRetry(`config set models.providers.${e}`,()=>this.runCli(["config","set",`${z0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${z0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${_o}[${e}]`,()=>this.runCli(["config","set",_o,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${_o}[${e}]`,`${_o}.${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 de=q("agent-manager"),cd="bypassPermissions",q0="full-access",j0="full-access";function pE(t){switch(t){case"read-only":return"read-only";case"auto":return"agent";case"full-access":return"agent-full-access"}}var gE=(t,e,r,i,o,c,d,u,f,h)=>{switch(t){case"claude-code":{let g={...o?{...qf(o),...Kf(o,d,u)}:{},...f??{},IS_SANDBOX:"1"};return new go({cwd:r,env:g,agentId:i})}case"codex":{let g=q0;h!==void 0&&(Sn("codex",h)?g=h:de.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:h}));let w=o?null:P0(process.env),S={...o?Wf(o):{},INITIAL_AGENT_MODE:pE(g),...process.env.COZE_BRIDGE_CODEX_APP_SERVER_LOGS==="1"?{APP_SERVER_LOGS:ad(r,"..","logs","codex-app-server")}:{},...w?{MODEL_PROVIDER:w}:{},...f??{}},_=o?jf(o,d,u):null,v=_?{methodId:"gateway",_meta:{gateway:_}}:void 0,I=!!o,A=!I&&process.env.COZE_BRIDGE_CODEX_LOCAL_GATEWAY_AUTH==="1";return new mo({cwd:r,agentId:i,...Object.keys(S).length>0?{env:S}:{},...v?{authRequest:v}:{},...I?{isolateCodexHome:!0}:{},...A?{resolveLocalGatewayAuth:!0}:{}})}case"openclaw":return new Nr({command:e,cwd:r,agentId:i,...c?{sessionName:id(c)}:{}})}};function od(t){return t==="claude-code"||t==="codex"}function mE(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(wE(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
97
99
  `)}
98
- `}function ab(t){if(t.includes(`
99
- `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var cb={path:"",version:"cloud-deployed"},P0="openclaw_gateway_unavailable",db="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 lb={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},ub=6e4,So=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;detectorFactory;openclawEnvBootstrapPromise;openclawConfigFactory;openclawConfigDir;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??sb,this.createTimeoutMs=e.createTimeoutMs??ub,this.detectorFactory=e.detectorFactory??(()=>new Zn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new vo({command:r})),this.openclawConfigDir=e.openclawConfigDir??od(rb(),".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=>{ue.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=od(e,".env");if(await nb(r).then(c=>c.isFile()).catch(()=>!1)){ue.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}let o=ob({...process.env,...ed(this.paths.agentEnvFile)});await cn(r,o,{mode:384}),ue.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),ue.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new T("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new T("IPC_BAD_REQUEST","framework required");let i=await Fe(e.agentId,this.paths).catch(()=>null),o=lo(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let c=this.registry.get(e.agentId);if(c){if(c.framework!==e.framework)throw new T("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")ue.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(D=>ue.warn("dispose stale agent failed (ignored)",{err:String(D)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")ue.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(D=>ue.warn("dispose drifted agent failed (ignored)",{err:String(D)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){ue.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let D=await Fe(e.agentId,this.paths).catch(()=>null);D&&(D.patToken=e.patToken,await rt(D,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){ue.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let D=await Fe(e.agentId,this.paths).catch(()=>null);D&&(D.modelInfo=e.modelInfo,await rt(D,this.paths))}return ue.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=nt(e.agentId,this.paths),x=o?"cloud":"local",h=e.framework==="openclaw"&&x==="local",m;h&&!r?.revive&&(m=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let E=m??(h?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),S=e.workspace??E??u.workspace,_=new AbortController,v=setTimeout(()=>_.abort(new T("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),A,I=!1;try{o&&sd(e.framework)&&await dr(e.framework,_.signal);let D=()=>{if(_.signal.aborted)throw _.signal.reason instanceof Error?_.signal.reason:new T("AGENT_TIMEOUT","_agent/create aborted")};await id(u.root,{recursive:!0}),await id(S,{recursive:!0}),await id(u.logs,{recursive:!0}),D(),h||await fr(S,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(x==="cloud"?await ka(S,"cloud"):await ka(S,"local",ad)),D();let O=i,y=zf({model:e.model??O?.model}),k=If(e._meta)??O?.accountId,L=e.patToken??O?.patToken,U=x==="cloud"?e.modelInfo??O?.modelInfo:void 0;if(A=new bo({agentId:e.agentId,framework:e.framework,workspace:S,model:y.model??vt,deployType:x,...k?{accountId:k}:{},...L?{patToken:L}:{},...U?{modelInfo:U}:{}}),A.status="ok",O?.sessions){let V=x==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[X,se]of Object.entries(O.sessions)){let ae={acpSessionId:se.acpSessionId,modelToken:se.modelToken,tokenGeneratedAt:se.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};V?se.permissionMode===void 0?(ae.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",ue.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:X,framework:e.framework,fallback:ae.permissionMode})):Cn(e.framework,se.permissionMode)?ae.permissionMode=se.permissionMode:ue.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:X,framework:e.framework,value:se.permissionMode}):se.permissionMode!==void 0&&ue.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:X,framework:e.framework,deployType:x}),se.cozeGroupId&&(ae.cozeGroupId=se.cozeGroupId),A.sessions.set(X,ae)}let ne=Object.keys(O.sessions).length;ne>0&&ue.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:ne})}this.registry.register(A),I=!0;let z={agentId:e.agentId,framework:e.framework,workspace:S,cozeIdentity:e.cozeIdentity,createdAt:O?.createdAt??Date.now(),sessions:O?.sessions??{},model:y.model};x==="cloud"&&(z.deployType="cloud"),k&&(z.accountId=k),L&&(z.patToken=L),U&&(z.modelInfo=U),O?.skills&&(z.skills=O.skills),O?.agentName&&(z.agentName=O.agentName),O?.description&&(z.description=O.description),e.framework==="openclaw"&&x==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,S)):ue.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let Z=e.initialSkills??[];if(Z.length>0){let V=[...z.skills??[]],ne=new Map(V.map((ae,N)=>[ae.skillId,N])),X=await Promise.allSettled(Z.map(ae=>Xc({agentId:e.agentId,workspace:S,framework:e.framework,skill:ae}))),se=0;for(let[ae,N]of X.entries()){let j=Z[ae];j&&(N.status==="fulfilled"?(Yc(V,ne,N.value),se++):ue.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:j.skillId,skillName:j.skillName,err:String(N.reason)}))}se>0&&(z.skills=V,ue.info("initialSkills installed",{agentId:e.agentId,installed:se,requested:Z.length}))}return await rt(z,this.paths),ue.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:x}),{ok:!0,agentId:e.agentId,workspace:S,framework:e.framework}}catch(D){throw ue.error("agent create failed, rolling back",{agentId:e.agentId,err:String(D)}),I&&A&&(await A.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await tb(u.root,{recursive:!0,force:!0}).catch(O=>ue.warn("rm agent dir failed (ignored)",{err:String(O)})),D instanceof T?D:new T("AGENT_SPAWN_FAILED",String(D),{cause:D})}finally{clearTimeout(v)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&sd(e.framework))u=cb;else throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);sd(e.framework)&&!ps(e.framework)&&(ue.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await dr(e.framework));let x=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,h;if(e.framework==="openclaw")h=await this.buildOpenclawDownstream({session:e,modelConfig:x,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path});else{let m=e.sessions.get(i),E=Zt(e)?m?.permissionMode??L0:"full-access";h=this.factory(e.framework,u.path,e.workspace,e.agentId,x,i,o,c,this.buildBinShimPathEnv(),E)}try{return await h.start(),await h.initialize(lb),h}catch(m){let E=h instanceof Nt?h.getStderrTail():[];throw E.length>0&&ue.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:m instanceof T?m.code:"unknown",recentStderr:E}),await h.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,m)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new T("AGENT_ENV_NOT_READY",O0(o),{cause:{reason:P0}})}catch(o){ue.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof T?i:new T("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};ue.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return ue.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new 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:db}})}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:P0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:l,command:u}=e,x=rd(o);if(r.deployType==="local"){let S=await this.ensureOpenclawDefaultAgent();return new zr({command:u,cwd:S.workspace,agentId:S.id,sessionName:x})}let h=await k0(),m=i?Hf(i,c,l):null,E;if(m){let S=jc(o),v=m.models[0]?.id??vt,A=`${S}/${v}`;if(!this.ensuredProviders.has(A)){let I=this.getOpenclawConfig();await I.ensureProvider(S,m),await I.addModelToAllowlist(A),this.ensuredProviders.add(A)}E=A}return new zr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:x,...h?{gatewayToken:h}:{},...E?{slashModelOnStart:E}:{}})}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=jc(i),c=`${o}/${e.model}`,l=!0;try{await r.removeProvider(o)}catch(u){l=!1,ue.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){l=!1,ue.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}l&&this.ensuredProviders.delete(c)}}};import{randomUUID as U0}from"node:crypto";import{promises as _b}from"node:fs";import{basename as q0}from"node:path";Ze();re();import{promises as xb}from"node:fs";import{basename as hb}from"node:path";var M0=H("file-upload"),pb="/api/coze_claw/file/agent_upload",gb=6e4;async function B0(t,e={}){let i=`${fo(ho(e.handshakeBase))}${pb}`,o=e.timeoutMs??gb,c=await xb.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",...Dr(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},x=new AbortController,h=setTimeout(()=>x.abort(),o);M0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let m=await fetch(i,{method:"POST",headers:u,body:l,signal:x.signal}),E=m.headers.get("x-tt-logid")??"";if(!m.ok){let v=await m.text().catch(()=>"");throw new T("UPLOAD_FAILED",`upload HTTP ${m.status} logid=${E}: ${v.slice(0,200)}`)}let S=await m.json();if(S.code!==void 0&&S.code!==0)throw new T("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${E}`);let _=S.data?.file?.file_url;if(!_)throw new T("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${E}: ${JSON.stringify(S).slice(0,200)}`);return M0.info("file upload ok",{uri:_,logid:E}),{uri:_}}catch(m){throw m instanceof T?m:m.name==="AbortError"?new T("UPLOAD_FAILED",`upload timeout (${o}ms) for ${hb(t.path)}`):new T("UPLOAD_FAILED",String(m),{cause:m})}finally{clearTimeout(h)}}Ze();re();import{extname as mb}from"node:path";var wb={".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 z0(t){let e=mb(t).toLowerCase();return wb[e]??"application/octet-stream"}Le();var Ao=H("agent-send"),F0=50*1024*1024;function G0(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 H0(t,e,r,i,o,c){let u;for(let x=0;x<=2;x++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(h){u=h,x<2&&(Ao.warn("sendAgentFileUpdate failed, retrying",{attempt:x+1,err:String(h)}),await new Promise(m=>setTimeout(m,5e3)))}throw new T("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function j0(t,e){let{session:r,runtime:i}=G0(e.core,t.agentId,t.sessionId);if(!await ai(t.path,r.workspace))throw new T("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await _b.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>F0)throw new T("FILE_TOO_LARGE",`${o.size} bytes > limit ${F0}`);let c=await z0(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??q0(t.path),u;try{u=await B0({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(h){throw Ao.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:h instanceof T?h.code:"UNKNOWN",message:h instanceof Error?h.message:String(h)}),h}let x={sessionUpdate:"agent_file",messageId:U0(),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 H0(e,r,i,t.sessionId,x,"agent file uploaded to cloud but sendAgentFileUpdate failed"),Ao.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 W0(t,e){let{session:r,runtime:i}=G0(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??q0(t.path),c={sessionUpdate:"group_file",messageId:U0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await H0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),Ao.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 K0(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}an();Vt();re();var Mt=H("coze-cli-installer"),$0="@coze/cli@latest",yb="coze",V0="0.1.8",bb=5e3,Eb=5e3,vb=9e4,Z0=1e4,Ki=null,Io=!1;async function cd(t,e={}){if(Io)return;if(Ki)return Ki;let r=e.exec??kf;return Ki=(async()=>{try{let i=await Sb(yb,r),o=!1;if(i){let l=await Ab(r);if(l===void 0)Mt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(K0(l,V0))Mt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:l,min:V0}),o=!0;else{Mt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:l}),Io=!0;return}}let c=o?"upgrade-only":"full";Mt.info("coze-cli install start",{package:$0,mode:c});try{await r("npm",["i","-g","--prefer-online",$0],{timeout:vb,maxBuffer:10*1024*1024}),Mt.info("coze-cli install ok")}catch(l){Mt.warn("coze-cli install failed (skip subsequent steps)",{err:String(l)});return}if(o){Io=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:Z0}),Mt.info("coze config set xTTEnv ok",{env:t.env})}catch(l){Mt.warn("coze config set failed (continue to auth login)",{err:String(l)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:Z0}),Mt.info("coze auth login ok")}catch(l){Mt.warn("coze auth login failed",{err:String(l)});return}Io=!0}finally{Ki=null}})(),Ki}async function Sb(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:bb});return Ra(i)}catch{return}}async function Ab(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:Eb});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}dn();Le();var Ib=10*6e4;function J0(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?Ib:e}function Co(t){return lr(t??Q().configFile)}function $i(t,e){return ur(e??Q().configFile,t)}import{randomBytes as Kb}from"node:crypto";or();Ze();re();import{createReadStream as Cb}from"node:fs";import{mkdir as Tb,readFile as Rb,realpath as Db,stat as kb,writeFile as Pb}from"node:fs/promises";import{basename as Ob,dirname as dd,isAbsolute as Lb,join as Nb,relative as Mb,resolve as X0,sep as Bb}from"node:path";import{createInterface as zb}from"node:readline";var Q0=H("fs-rpc"),Vi=Ve("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function ex(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Vi)throw new T("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Vi} bytes`);let i=await nx(t.path,e);return await Tb(dd(i),{recursive:!0}),await Pb(i,t.content,"utf8"),Q0.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function tx(t,e){let r=await nx(t.path,e),i=await kb(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Vi&&!o)throw new T("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Vi} bytes`);let c;if(o&&i.size>Vi)c=await Fb(r,t.line??1,t.limit);else{let l=await Rb(r,"utf8");if(o){let u=l.split(`
100
- `),x=Math.max(0,(t.line??1)-1),h=typeof t.limit=="number"?x+t.limit:void 0;c=u.slice(x,h).join(`
101
- `)}else c=l}return Q0.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function Fb(t,e,r){let i=zb({input:Cb(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(`
102
- `)}async function nx(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([Y0(X0(e)),Y0(X0(t))]),o=Mb(r,i);if(Ub(o,Bb,Lb(o)))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function Ub(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function Y0(t){let e=[],r=t;for(;r!==dd(r);)try{let i=await Db(r);return e.length?Nb(i,...e.reverse()):i}catch{e.push(Ob(r)),r=dd(r)}return t}re();var rx=H("prompt-multimodal"),ix=10*1024*1024,qb=15e3,Gb=6;async function sx(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 Hb(l))}}let o=Array.from({length:Math.min(Gb,t.length)},()=>i());return await Promise.all(o),e}function ox(t){return t.some(e=>e.type==="image")}async function Hb(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Ni(e.uri))return t;try{let{buf:r,contentType:i}=await Wb(e.uri),o=e.mimeType||jb(i)||"application/octet-stream";return rx.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 rx.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function jb(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function Wb(t){let e=new AbortController,r=setTimeout(()=>e.abort(),qb);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>ix)throw new Error(`image too large: ${o.byteLength} bytes (max ${ix})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}ln();Ze();re();var K=H("core"),$b=3e4,Vb=/^(boe|ppe)_[A-Za-z0-9_-]+$/,Zb="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",Jb="\u5BA1\u6279\u5DF2\u8D85\u65F6",Xb=3e4,To=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Nr;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=J0(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}),Wi(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(In(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(mo(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&&Vb.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(Lr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Lr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Lr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,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(In(r,Gi(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new T("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new T("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new T("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new T("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||e.method==="session/set_mode"||!c)return this.dispatchSessionCall(o,e.method,r);if(e.method==="session/prompt"){let x=o.sessions.get(c);if(x?.pendingPermission){let h=r._meta?.cozeTriggerMsgId,m=uo(r._meta);return K.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,x,c,Zb,h,m)}}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}=Tf(i);switch(r){case"session/new":{let c=Yb();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=Zt(e)?Cf(i._meta):void 0;if(u!==void 0&&!Cn(e.framework,u))throw new T("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${nd(e.framework)}`);let x=await this.ensureRuntime(e,l);if(u!==void 0&&x.permissionMode===void 0&&(x.permissionMode=u,await this.persistSessionMapping(e)),x.replySeq=0,await this.ensureDownstream(e,l,x),!x.downstream||!x.acpSessionId)throw new T("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&x.permissionMode!==void 0&&x.permissionMode!==u){let S=x.permissionMode;x.permissionMode=u,await this.persistSessionMapping(e);try{await x.downstream.setSessionMode({sessionId:x.acpSessionId,modeId:u})}catch(_){throw x.permissionMode=S,await this.persistSessionMapping(e).catch(()=>{}),_}}let h=i._meta?.cozeTriggerMsgId;h?e.activeTriggers.set(x.acpSessionId,h):e.activeTriggers.delete(x.acpSessionId);let m=uo(i._meta);if(m?e.activeGroupIds.set(x.acpSessionId,m):e.activeGroupIds.delete(x.acpSessionId),m&&x.cozeGroupId!==m&&(x.cozeGroupId=m,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&ox(c.prompt))throw new T("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let E=await sx(c.prompt);try{let S=await x.downstream.sessionPrompt({...c,sessionId:x.acpSessionId,prompt:E});return x.lastActiveAt=Date.now(),S}catch(S){if(S instanceof T&&S.code==="AGENT_APPROVAL_TIMEOUT"){let _=x.pendingPermission;_&&(_.downstream.respondAgentRequest(_.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(_.upstreamId),x.pendingPermission=void 0);let v=x.acpSessionId,A=v?e.activeTriggers.get(v):void 0,I=v?e.activeGroupIds.get(v):void 0;return K.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:l}),await this.synthesizePromptReply(e,x,l,Jb,A,I)}throw S}finally{if(e.activeTriggers.delete(x.acpSessionId),e.activeGroupIds.delete(x.acpSessionId),x.pendingPermission=void 0,x.reloadAfterTurn){x.reloadAfterTurn=!1;let S=x.downstream;S&&(x.downstream=void 0,K.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:l,acpId:x.acpSessionId}),S.stop("reload-after-turn").catch(_=>K.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:l,err:String(_)})))}else x.downstream?.isAlive()&&this.armIdleTimer(e,l,x)}}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}}case"session/set_mode":{let c=o,l=c.sessionId,u=c.modeId,x=uo(i._meta);if(!l)throw new T("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Zt(e))throw e.framework==="openclaw"?new T("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new T("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!Cn(e.framework,u))throw new T("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${nd(e.framework)}`);if(x)return await this.handleGroupSetMode(e,x,u);let h=e.sessions.get(l)??await this.ensureRuntime(e,l);if(h.permissionMode===u)return{};let m=h.permissionMode;if(h.permissionMode=u,await this.persistSessionMapping(e),h.downstream?.isAlive()&&h.acpSessionId)try{await h.downstream.setSessionMode({sessionId:h.acpSessionId,modeId:u})}catch(E){throw h.permissionMode=m,await this.persistSessionMapping(e).catch(()=>{}),E}else K.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:l,modeId:u});return{}}default:throw new T("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async handleGroupSetMode(e,r,i){let o=[];for(let[l,u]of e.sessions)u.cozeGroupId===r&&u.permissionMode!==i&&o.push({cloudId:l,runtime:u,oldMode:u.permissionMode});if(o.length===0)return K.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i}),{};K.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i,targets:o.length});for(let l of o)l.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let l of o){let u=l.runtime.downstream,x=l.runtime.acpSessionId;u?.isAlive()&&x&&c.push({downstream:u,acpSessionId:x,oldMode:l.oldMode,runtime:l.runtime})}for(let l of c)try{await l.downstream.setSessionMode({sessionId:l.acpSessionId,modeId:i})}catch(u){for(let x of o)x.runtime.permissionMode=x.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),u}return{}}async ensureRuntime(e,r){let i=e.sessions.get(r);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,r):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return Zt(e)&&(c.permissionMode=e.framework==="claude-code"?ad:N0),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(Et.GEN_MODEL_TOKEN,i,Xb);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(Wi(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(h){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),h}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=x,this.attachRuntimeHooks(e,r,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await x.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),K.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(h){K.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(h)}),i.acpSessionId=void 0;let m=await x.sessionNew({cwd:e.workspace});i.acpSessionId=m.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let h=await x.sessionNew({cwd:e.workspace});i.acpSessionId=h.sessionId,await this.persistSessionMapping(e)}}catch(h){throw K.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(h)}),await x.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,h}if(x.afterSessionEstablished&&i.acpSessionId&&await x.afterSessionEstablished(i.acpSessionId),Zt(e)&&i.acpSessionId&&i.permissionMode)try{await x.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(h){K.warn("post-spawn set_mode failed, framework using its own startup default",{framework:e.framework,agentId:e.agentId,cloudId:r,mode:i.permissionMode,err:String(h)})}}armIdleTimer(e,r,i){if(Wi(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(Or("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(Or("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(tE(r)){K.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let l=r.update;if(l&&typeof l=="object"&&l.sessionUpdate==="current_mode_update"&&Zt(e)){let m=l.currentModeId;Cn(e.framework,m)&&c.permissionMode!==m?(c.permissionMode=m,this.persistSessionMapping(e).catch(E=>K.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(E)}))):typeof m=="string"&&!Cn(e.framework,m)&&K.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:m})}let u={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},x=e.activeTriggers.get(i);x&&(u.cozeTriggerMsgId=x);let h=e.activeGroupIds.get(i);h&&(u.cozeGroupId=h),this.upstream.send(Or("session/update",{...r,sessionId:o,_meta:u})).catch(m=>K.warn("forward update failed",{agentId:e.agentId,err:String(m)}))}handleAgentRequest(e,r,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,r,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,r,i);return}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 ex(c,o);r.respondAgentRequest(i.id,l)}else{let c=i.params??{},l=await tx(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,Gi(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,x=u?e.activeTriggers.get(u):void 0,h={cozeAgentId:e.agentId};x&&(h.cozeTriggerMsgId=x);let m=u?e.activeGroupIds.get(u):void 0;m&&(h.cozeGroupId=m);let E=u?this.reverseSessionId(e,u):void 0,S=E?e.sessions.get(E):void 0;S&&(S.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let _={...c,...E?{sessionId:E}:{},_meta:h};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:E}),K.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:E,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(v=>({optionId:v.optionId,kind:v.kind,name:v.name}))}),this.upstream.send(Ui(o,"session/request_permission",_)).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"&&Qb(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 go(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=$b){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(Ui(o,e,r)).catch(x=>{let h=this.pendingBridge.get(o);h&&(clearTimeout(h.timer),this.pendingBridge.delete(o)),l(x)})})}async persistSessionMapping(e){if(this.paths)try{let r=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),o.permissionMode&&Zt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await ci(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(In(e,{code:r,message:i,data:{bridgeVersion:Pr}}))}};function Yb(){return Kb(16).toString("hex")}function Qb(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 eE=["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 tE(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 eE.some(c=>o.startsWith(c))}dn();re();Le();import{randomBytes as nE}from"node:crypto";import{createServer as rE}from"node:http";var iE=1e6,ax=H("ipc"),Ro=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??Q()}async start(){this.token=nE(32).toString("hex");let e=rE((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(),ax.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 cn(this.paths.portFile,String(this.port)),await cn(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Zi(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Zi(r,404,{error:"not found"});return}let l=null;if(e.method==="POST")try{l=await sE(e)}catch(u){Zi(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(l,e);Zi(r,200,u??{ok:!0})}catch(u){ax.error("IPC handler failed",{key:o,err:String(u)}),Zi(r,500,{error:u instanceof Error?u.message:String(u)})}}};function Zi(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function sE(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>iE)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}import"node:module";var Iv=qt(rh(),1),Cv=qt(zo(),1),Tv=qt(qr(),1),Rv=qt(yd(),1),Dv=qt(vd(),1),kv=qt(Rd(),1),fh=qt(Go(),1),Pv=qt(uh(),1);var xh=fh.default;Ze();re();var{FWS:Vv}=Sh(),De=H("upstream.frontier"),Ih="application/json",Ch="none",Zv=15e3;function Jv(t){class e extends xh{constructor(i){super(i,Of,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>De.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(ml("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");De.debug("WS raw frame out",{bytes:c.byteLength,headHex:l})}catch(c){De.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var is=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){De.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Lf,...Dr(this.opts.ppeOverride)},r=Jv(e),i=Mf(this.opts.urlOverride),o={url:i,ws:r,fpID:Pf,aID:xo,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Ih,force:!0},payloadEncoding:{encoding:Ch,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new Vv(o),l=!1,u=null,x,h,m=new Promise((_,v)=>{x=_,h=v}),E=_=>{l||(l=!0,u&&(clearTimeout(u),u=null),_?h(_):x())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let _=this.openCount===1;De.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:_,openCount:this.openCount}),_&&E();for(let v of this.connectHandlers)Promise.resolve(v({initial:_})).catch(A=>De.warn("onConnect handler threw (ignored)",{err:String(A)}))},c.onclose=_=>{this.opened=!1,De.info("frontier closed",{code:_.code,reason:_.reason,willReconnect:_.willReconnect})},c.onerror=_=>{De.warn("frontier error",{code:_.code,msg:_.message}),E(new T("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${_.code} msg=${_.message??""}`))},c.onmessage=_=>this.handleMessage(_),this.fws=c;let S=this.opts.openTimeoutMs??Zv;u=setTimeout(()=>{E(new T("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${S}ms (handshake or upgrade slow)`))},S),await c.connect();try{await m}catch(_){try{c.close(1e3,"open failed")}catch(v){De.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,_}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){De.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw De.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?(De.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;Th(c)||De.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:Ih,payloadEncoding:Ch})}catch(u){throw De.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){De.debug("drop non-adapter frontier frame",{service:r});return}let i=Qv(e);if(!i){De.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){De.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(l){De.warn("frontier message JSON parse failed",{err:String(l),head:i.slice(0,80)});return}let c=o;Th(c)||De.info("frontier frame in",{logid:Yv(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:Xv(i)}),Promise.resolve(this.handler(o)).catch(l=>De.warn("frontier frame handler threw",{err:String(l)}))}};function Th(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Rh=2e3;function Xv(t){return t.length<=Rh?t:`${t.slice(0,Rh)}...<truncated, total ${t.length} chars>`}function Yv(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function Qv(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}}re();var Od=H("upstream.switchable"),Xo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;Od.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 Od.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>Od.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()}};re();var Ld=H("upstream"),$r=class{handler=null;async start(){Ld.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Ld.info("NoopUpstream stopped",{reason:e})}async send(e){Ld.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)}};Ze();re();dn();re();Le();import{promises as eS}from"node:fs";var Dh=H("pat-token-store");async function Yo(t=Q()){try{let r=(await eS.readFile(t.patTokenFile,"utf8")).trim();return r.length===0?(Dh.warn("pat-token exists but empty (treating as missing; likely interrupted write)",{path:t.patTokenFile}),null):r}catch(e){let r=e?.code;return r!=="ENOENT"&&Dh.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function ss(t,e=Q()){if(!t)throw new Error("writePatToken: empty patToken");await cn(e.patTokenFile,t,{mode:384})}Le();Le();import{promises as Qo}from"node:fs";import{join as tS}from"node:path";function nS(t,e){return`#!/bin/sh
100
+ `}function wE(t){if(t.includes(`
101
+ `)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var _E={path:"",version:"cloud-deployed"},G0="openclaw_gateway_unavailable",yE="openclaw_default_agent_missing";function H0(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 EE={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},bE=6e4,Eo=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??gE,this.createTimeoutMs=e.createTimeoutMs??bE,this.detectorFactory=e.detectorFactory??(()=>new Kn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new yo({command:r})),this.openclawConfigDir=e.openclawConfigDir??ad(hE(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{de.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=ad(e,".env");if(await xE(r).then(c=>c.isFile()).catch(()=>!1)){de.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}let o=mE({...process.env,...td(this.paths.agentEnvFile)});await sn(r,o,{mode:384}),de.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),de.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new T("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new T("IPC_BAD_REQUEST","framework required");let i=await Te(e.agentId,this.paths).catch(()=>null),o=so(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let c=this.registry.get(e.agentId);if(c){if(c.framework!==e.framework)throw new T("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")de.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(R=>de.warn("dispose stale agent failed (ignored)",{err:String(R)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")de.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(R=>de.warn("dispose drifted agent failed (ignored)",{err:String(R)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){de.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let R=await Te(e.agentId,this.paths).catch(()=>null);R&&(R.patToken=e.patToken,await Fe(R,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){de.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let R=await Te(e.agentId,this.paths).catch(()=>null);R&&(R.modelInfo=e.modelInfo,await Fe(R,this.paths))}return de.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=Ye(e.agentId,this.paths),f=o?"cloud":"local",h=e.framework==="openclaw"&&f==="local",g;h&&!r?.revive&&(g=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let w=g??(h?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),S=e.workspace??w??u.workspace,_=new AbortController,v=setTimeout(()=>_.abort(new T("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),I,A=!1;try{o&&od(e.framework)&&await or(e.framework,_.signal);let R=()=>{if(_.signal.aborted)throw _.signal.reason instanceof Error?_.signal.reason:new T("AGENT_TIMEOUT","_agent/create aborted")};await sd(u.root,{recursive:!0}),await sd(S,{recursive:!0}),await sd(u.logs,{recursive:!0}),R(),h||await dr(S,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(f==="cloud"?await Da(S,"cloud"):await Da(S,"local",cd)),R();let O=i,y=Hf({model:e.model??O?.model}),C=Cf(e._meta)??O?.accountId,L=e.patToken??O?.patToken,F=f==="cloud"?e.modelInfo??O?.modelInfo:void 0;if(I=new wo({agentId:e.agentId,framework:e.framework,workspace:S,model:y.model??Et,deployType:f,...C?{accountId:C}:{},...L?{patToken:L}:{},...F?{modelInfo:F}:{}}),I.status="ok",O?.sessions){let $=f==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[J,ie]of Object.entries(O.sessions)){let se={acpSessionId:ie.acpSessionId,modelToken:ie.modelToken,tokenGeneratedAt:ie.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};$?ie.permissionMode===void 0?(se.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",de.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:J,framework:e.framework,fallback:se.permissionMode})):Sn(e.framework,ie.permissionMode)?se.permissionMode=ie.permissionMode:de.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:J,framework:e.framework,value:ie.permissionMode}):ie.permissionMode!==void 0&&de.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:J,framework:e.framework,deployType:f}),ie.cozeGroupId&&(se.cozeGroupId=ie.cozeGroupId),I.sessions.set(J,se)}let ne=Object.keys(O.sessions).length;ne>0&&de.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:ne})}this.registry.register(I),A=!0;let M={agentId:e.agentId,framework:e.framework,workspace:S,cozeIdentity:e.cozeIdentity,createdAt:O?.createdAt??Date.now(),sessions:O?.sessions??{},model:y.model};f==="cloud"&&(M.deployType="cloud"),C&&(M.accountId=C),L&&(M.patToken=L),F&&(M.modelInfo=F),O?.skills&&(M.skills=O.skills),O?.agentName&&(M.agentName=O.agentName),O?.description&&(M.description=O.description),M.skillsRefreshedForVersion=O?.skillsRefreshedForVersion??Pt,e.framework==="openclaw"&&f==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,S)):de.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let Y=e.initialSkills??[];if(Y.length>0){let $=[...M.skills??[]],ne=new Map($.map((se,D)=>[se.skillId,D])),J=await Promise.allSettled(Y.map(se=>uo({agentId:e.agentId,workspace:S,framework:e.framework,skill:se}))),ie=0;for(let[se,D]of J.entries()){let G=Y[se];G&&(D.status==="fulfilled"?(fo($,ne,D.value),ie++):de.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:G.skillId,skillName:G.skillName,err:String(D.reason)}))}ie>0&&(M.skills=$,de.info("initialSkills installed",{agentId:e.agentId,installed:ie,requested:Y.length}))}return await Fe(M,this.paths),de.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:f}),{ok:!0,agentId:e.agentId,workspace:S,framework:e.framework}}catch(R){throw de.error("agent create failed, rolling back",{agentId:e.agentId,err:String(R)}),A&&I&&(await I.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await fE(u.root,{recursive:!0,force:!0}).catch(O=>de.warn("rm agent dir failed (ignored)",{err:String(O)})),R instanceof T?R:new T("AGENT_SPAWN_FAILED",String(R),{cause:R})}finally{clearTimeout(v)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&od(e.framework))u=_E;else throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);od(e.framework)&&!fs(e.framework)&&(de.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await or(e.framework));let f=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,h;if(e.framework==="openclaw")h=await this.buildOpenclawDownstream({session:e,modelConfig:f,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path});else{let g=e.sessions.get(i),w=$t(e)?g?.permissionMode??q0:"full-access";h=this.factory(e.framework,u.path,e.workspace,e.agentId,f,i,o,c,this.buildBinShimPathEnv(),w)}try{return await h.start(),await h.initialize(EE),h}catch(g){let w=h instanceof Ot?h.getStderrTail():[];throw w.length>0&&de.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:g instanceof T?g.code:"unknown",recentStderr:w}),await h.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,g)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new T("AGENT_ENV_NOT_READY",H0(o),{cause:{reason:G0}})}catch(o){de.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof T?i:new T("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};de.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return de.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:yE}})}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",H0(r),{cause:{reason:G0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:d,command:u}=e,f=id(o);if(r.deployType==="local"){let S=await this.ensureOpenclawDefaultAgent();return new Nr({command:u,cwd:S.workspace,agentId:S.id,sessionName:f})}let h=await U0(),g=i?$f(i,c,d):null,w;if(g){let S=jc(o),v=g.models[0]?.id??Et,I=`${S}/${v}`;if(!this.ensuredProviders.has(I)){let A=this.getOpenclawConfig();await A.ensureProvider(S,g),await A.addModelToAllowlist(I),this.ensuredProviders.add(I)}w=I}return new Nr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:f,...h?{gatewayToken:h}:{},...w?{slashModelOnStart:w}:{}})}async openclawRepair(e,r){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,r)}async cleanupOpenclawSessionProviders(e){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let r=this.openclawConfigCache;for(let i of e.sessions.keys()){let o=jc(i),c=`${o}/${e.model}`,d=!0;try{await r.removeProvider(o)}catch(u){d=!1,de.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){d=!1,de.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}d&&this.ensuredProviders.delete(c)}}};import{randomUUID as Y0}from"node:crypto";import{promises as RE}from"node:fs";import{basename as Z0}from"node:path";We();te();import{promises as vE}from"node:fs";import{basename as SE}from"node:path";var W0=q("file-upload"),IE="/api/coze_claw/file/agent_upload",AE=6e4;async function K0(t,e={}){let i=`${kr(Tr(e.handshakeBase))}${IE}`,o=e.timeoutMs??AE,c=await vE.readFile(t.path),d=new FormData;d.append("agent_id",t.agentId),d.append("session_id",t.sessionId),d.append("file_name",t.name),d.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let u={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...En(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},f=new AbortController,h=setTimeout(()=>f.abort(),o);W0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let g=await fetch(i,{method:"POST",headers:u,body:d,signal:f.signal}),w=g.headers.get("x-tt-logid")??"";if(!g.ok){let v=await g.text().catch(()=>"");throw new T("UPLOAD_FAILED",`upload HTTP ${g.status} logid=${w}: ${v.slice(0,200)}`)}let S=await g.json();if(S.code!==void 0&&S.code!==0)throw new T("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${w}`);let _=S.data?.file?.file_url;if(!_)throw new T("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${w}: ${JSON.stringify(S).slice(0,200)}`);return W0.info("file upload ok",{uri:_,logid:w}),{uri:_}}catch(g){throw g instanceof T?g:g.name==="AbortError"?new T("UPLOAD_FAILED",`upload timeout (${o}ms) for ${SE(t.path)}`):new T("UPLOAD_FAILED",String(g),{cause:g})}finally{clearTimeout(h)}}We();te();import{extname as kE}from"node:path";var TE={".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 $0(t){let e=kE(t).toLowerCase();return TE[e]??"application/octet-stream"}Oe();var bo=q("agent-send"),V0=50*1024*1024;function J0(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 u;for(let f=0;f<=2;f++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(h){u=h,f<2&&(bo.warn("sendAgentFileUpdate failed, retrying",{attempt:f+1,err:String(h)}),await new Promise(g=>setTimeout(g,5e3)))}throw new T("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function Q0(t,e){let{session:r,runtime:i}=J0(e.core,t.agentId,t.sessionId);if(!await ni(t.path,r.workspace))throw new T("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await RE.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>V0)throw new T("FILE_TOO_LARGE",`${o.size} bytes > limit ${V0}`);let c=await $0(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??Z0(t.path),u;try{u=await K0({patToken:r.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:d,sizeBytes:o.size,...r.accountId?{accountId:r.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(h){throw bo.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:h instanceof T?h.code:"UNKNOWN",message:h instanceof Error?h.message:String(h)}),h}let f={sessionUpdate:"agent_file",messageId:Y0(),content:{type:t.kind==="image"?"image":"resource",uri:u.uri,mimeType:c,name:d,sizeBytes:o.size,...u.fileId!==void 0?{fileId:u.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await X0(e,r,i,t.sessionId,f,"agent file uploaded to cloud but sendAgentFileUpdate failed"),bo.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:d,bytes:o.size,mime:c,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:c,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function ex(t,e){let{session:r,runtime:i}=J0(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??Z0(t.path),c={sessionUpdate:"group_file",messageId:Y0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await X0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),bo.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 tx(t,e){let r=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(r.length,i.length);for(let c=0;c<o;c++){let d=r[c]??0,u=i[c]??0;if(d<u)return!0;if(d>u)return!1}return!1}rn();Kt();te();var Lt=q("coze-cli-installer"),nx="@coze/cli@latest",CE="coze",rx="0.1.8",DE=5e3,PE=5e3,OE=9e4,ix=1e4,Hi=null,vo=!1;async function ld(t,e={}){if(vo)return;if(Hi)return Hi;let r=e.exec??Nf;return Hi=(async()=>{try{let i=await LE(CE,r),o=!1;if(i){let d=await NE(r);if(d===void 0)Lt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(tx(d,rx))Lt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:d,min:rx}),o=!0;else{Lt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:d}),vo=!0;return}}let c=o?"upgrade-only":"full";Lt.info("coze-cli install start",{package:nx,mode:c});try{await r("npm",["i","-g","--prefer-online",nx],{timeout:OE,maxBuffer:10*1024*1024}),Lt.info("coze-cli install ok")}catch(d){Lt.warn("coze-cli install failed (skip subsequent steps)",{err:String(d)});return}if(o){vo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:ix}),Lt.info("coze config set xTTEnv ok",{env:t.env})}catch(d){Lt.warn("coze config set failed (continue to auth login)",{err:String(d)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:ix}),Lt.info("coze auth login ok")}catch(d){Lt.warn("coze auth login failed",{err:String(d)});return}vo=!0}finally{Hi=null}})(),Hi}async function LE(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:DE});return Ra(i)}catch{return}}async function NE(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:PE});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}on();Oe();var ME=10*6e4;function sx(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?ME:e}function So(t){return ar(t??Q().configFile)}function qi(t,e){return cr(e??Q().configFile,t)}import{randomBytes as nb}from"node:crypto";rr();We();te();import{createReadStream as BE}from"node:fs";import{mkdir as FE,readFile as zE,realpath as UE,stat as GE,writeFile as HE}from"node:fs/promises";import{basename as qE,dirname as ud,isAbsolute as jE,join as WE,relative as KE,resolve as ox,sep as $E}from"node:path";import{createInterface as VE}from"node:readline";var cx=q("fs-rpc"),ji=Ve("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function dx(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>ji)throw new T("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${ji} bytes`);let i=await ux(t.path,e);return await FE(ud(i),{recursive:!0}),await HE(i,t.content,"utf8"),cx.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function lx(t,e){let r=await ux(t.path,e),i=await GE(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>ji&&!o)throw new T("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${ji} bytes`);let c;if(o&&i.size>ji)c=await YE(r,t.line??1,t.limit);else{let d=await zE(r,"utf8");if(o){let u=d.split(`
102
+ `),f=Math.max(0,(t.line??1)-1),h=typeof t.limit=="number"?f+t.limit:void 0;c=u.slice(f,h).join(`
103
+ `)}else c=d}return cx.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function YE(t,e,r){let i=VE({input:BE(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,d=[],u=0;try{for await(let f of i)if(u>=o&&u<c&&d.push(f),u++,u>=c)break}finally{i.close()}return d.join(`
104
+ `)}async function ux(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([ax(ox(e)),ax(ox(t))]),o=KE(r,i);if(ZE(o,$E,jE(o)))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function ZE(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function ax(t){let e=[],r=t;for(;r!==ud(r);)try{let i=await UE(r);return e.length?WE(i,...e.reverse()):i}catch{e.push(qE(r)),r=ud(r)}return t}te();var fx=q("prompt-multimodal"),xx=10*1024*1024,JE=15e3,XE=6;async function hx(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 QE(d))}}let o=Array.from({length:Math.min(XE,t.length)},()=>i());return await Promise.all(o),e}function px(t){return t.some(e=>e.type==="image")}async function QE(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Di(e.uri))return t;try{let{buf:r,contentType:i}=await tb(e.uri),o=e.mimeType||eb(i)||"application/octet-stream";return fx.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 fx.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function eb(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function tb(t){let e=new AbortController,r=setTimeout(()=>e.abort(),JE);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>xx)throw new Error(`image too large: ${o.byteLength} bytes (max ${xx})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}an();We();te();var K=q("core"),rb=3e4,ib=/^(boe|ppe)_[A-Za-z0-9_-]+$/,sb="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",ob="\u5BA1\u6279\u5DF2\u8D85\u65F6",ab=3e4,Io=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Pr;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=sx(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,d)=>{K.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:d}),Gi(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(vn(o,{code:Z.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(d=>K.debug("send error response to upstream failed (ignored)",{err:String(d)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:Z.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:Z.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(ho(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&&ib.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,Z.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(Dr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Dr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Dr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,Z.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(vn(r,Fi(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new T("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new T("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new T("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new T("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||e.method==="session/set_mode"||!c)return this.dispatchSessionCall(o,e.method,r);if(e.method==="session/prompt"){let f=o.sessions.get(c);if(f?.pendingPermission){let h=r._meta?.cozeTriggerMsgId,g=oo(r._meta);return K.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,f,c,sb,h,g)}}let d=Date.now(),u=!1;try{let f=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,f}finally{K.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-d,ok:u})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=Pf(i);switch(r){case"session/new":{let c=cb();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,d=c.sessionId;if(!d)throw new T("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=$t(e)?Df(i._meta):void 0;if(u!==void 0&&!Sn(e.framework,u))throw new T("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${rd(e.framework)}`);let f=await this.ensureRuntime(e,d);if(u!==void 0&&f.permissionMode===void 0&&(f.permissionMode=u,await this.persistSessionMapping(e)),f.replySeq=0,await this.ensureDownstream(e,d,f),!f.downstream||!f.acpSessionId)throw new T("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&f.permissionMode!==void 0&&f.permissionMode!==u){let S=f.permissionMode;f.permissionMode=u,await this.persistSessionMapping(e);try{await f.downstream.setSessionMode({sessionId:f.acpSessionId,modeId:u})}catch(_){throw f.permissionMode=S,await this.persistSessionMapping(e).catch(()=>{}),_}}let h=i._meta?.cozeTriggerMsgId;h?e.activeTriggers.set(f.acpSessionId,h):e.activeTriggers.delete(f.acpSessionId);let g=oo(i._meta);if(g?e.activeGroupIds.set(f.acpSessionId,g):e.activeGroupIds.delete(f.acpSessionId),g&&f.cozeGroupId!==g&&(f.cozeGroupId=g,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&px(c.prompt))throw new T("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let w=await hx(c.prompt);try{let S=await f.downstream.sessionPrompt({...c,sessionId:f.acpSessionId,prompt:w});return f.lastActiveAt=Date.now(),S}catch(S){if(S instanceof T&&S.code==="AGENT_APPROVAL_TIMEOUT"){let _=f.pendingPermission;_&&(_.downstream.respondAgentRequest(_.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(_.upstreamId),f.pendingPermission=void 0);let v=f.acpSessionId,I=v?e.activeTriggers.get(v):void 0,A=v?e.activeGroupIds.get(v):void 0;return K.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:d}),await this.synthesizePromptReply(e,f,d,ob,I,A)}throw S}finally{if(e.activeTriggers.delete(f.acpSessionId),e.activeGroupIds.delete(f.acpSessionId),f.pendingPermission=void 0,f.reloadAfterTurn){f.reloadAfterTurn=!1;let S=f.downstream;S&&(f.downstream=void 0,K.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:d,acpId:f.acpSessionId}),S.stop("reload-after-turn").catch(_=>K.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:d,err:String(_)})))}else f.downstream?.isAlive()&&this.armIdleTimer(e,d,f)}}case"session/cancel":{let d=o.sessionId;if(!d)throw new T("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(d);if(e.hasSessionQueue(d)){let f=e.getSessionQueue(d);f.size>0&&(K.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:d,queuedCount:f.size}),f.dispose(new T("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${d}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,d=c.sessionId,u=c.modeId,f=oo(i._meta);if(!d)throw new T("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!$t(e))throw e.framework==="openclaw"?new T("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new T("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!Sn(e.framework,u))throw new T("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${rd(e.framework)}`);if(f)return await this.handleGroupSetMode(e,f,u);let h=e.sessions.get(d)??await this.ensureRuntime(e,d);if(h.permissionMode===u)return{};let g=h.permissionMode;if(h.permissionMode=u,await this.persistSessionMapping(e),h.downstream?.isAlive()&&h.acpSessionId)try{await h.downstream.setSessionMode({sessionId:h.acpSessionId,modeId:u})}catch(w){throw h.permissionMode=g,await this.persistSessionMapping(e).catch(()=>{}),w}else K.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:d,modeId:u});return{}}default:throw new T("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async handleGroupSetMode(e,r,i){let o=[];for(let[d,u]of e.sessions)u.cozeGroupId===r&&u.permissionMode!==i&&o.push({cloudId:d,runtime:u,oldMode:u.permissionMode});if(o.length===0)return K.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i}),{};K.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i,targets:o.length});for(let d of o)d.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let d of o){let u=d.runtime.downstream,f=d.runtime.acpSessionId;u?.isAlive()&&f&&c.push({downstream:u,acpSessionId:f,oldMode:d.oldMode,runtime:d.runtime})}for(let d of c)try{await d.downstream.setSessionMode({sessionId:d.acpSessionId,modeId:i})}catch(u){for(let f of o)f.runtime.permissionMode=f.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),u}return{}}async ensureRuntime(e,r){let i=e.sessions.get(r);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,r):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return $t(e)&&(c.permissionMode=e.framework==="claude-code"?cd:j0),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(ut.GEN_MODEL_TOKEN,i,ab);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(Gi(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new T("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,d=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(d>=o&&Date.now()-u<c)throw new T("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${d} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let f;try{f=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(h){throw i.spawnFailCount=d+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(K.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),h}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=f,this.attachRuntimeHooks(e,r,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await f.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),K.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(h){K.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(h)}),i.acpSessionId=void 0;let g=await f.sessionNew({cwd:e.workspace});i.acpSessionId=g.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let h=await f.sessionNew({cwd:e.workspace});i.acpSessionId=h.sessionId,await this.persistSessionMapping(e)}}catch(h){throw K.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(h)}),await f.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,h}if(f.afterSessionEstablished&&i.acpSessionId&&await f.afterSessionEstablished(i.acpSessionId),$t(e)&&i.acpSessionId&&i.permissionMode)try{await f.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(h){K.warn("post-spawn set_mode failed, framework using its own startup default",{framework:e.framework,agentId:e.agentId,cloudId:r,mode:i.permissionMode,err:String(h)})}}armIdleTimer(e,r,i){if(Gi(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 d=e.activeTriggers.get(r.acpSessionId);d&&(c.cozeTriggerMsgId=d);let u=e.activeGroupIds.get(r.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Cr("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,d){let u={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(u.cozeTriggerMsgId=c),d&&(u.cozeGroupId=d),await this.upstream.send(Cr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(f=>K.warn("synthesizePromptReply update send failed (ignored)",{err:String(f)})),{stopReason:"end_turn"}}forwardUpdate(e,r){let i=r.sessionId,o=this.reverseSessionId(e,i);if(!o){K.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){K.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(ub(r)){K.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let d=r.update;if(d&&typeof d=="object"&&d.sessionUpdate==="current_mode_update"&&$t(e)){let g=d.currentModeId;Sn(e.framework,g)&&c.permissionMode!==g?(c.permissionMode=g,this.persistSessionMapping(e).catch(w=>K.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(w)}))):typeof g=="string"&&!Sn(e.framework,g)&&K.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:g})}let u={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},f=e.activeTriggers.get(i);f&&(u.cozeTriggerMsgId=f);let h=e.activeGroupIds.get(i);h&&(u.cozeGroupId=h),this.upstream.send(Cr("session/update",{...r,sessionId:o,_meta:u})).catch(g=>K.warn("forward update failed",{agentId:e.agentId,err:String(g)}))}handleAgentRequest(e,r,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,r,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,r,i);return}K.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:Z.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 dx(c,o);r.respondAgentRequest(i.id,d)}else{let c=i.params??{},d=await lx(c,o);r.respondAgentRequest(i.id,d)}}catch(o){K.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Fi(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,f=u?e.activeTriggers.get(u):void 0,h={cozeAgentId:e.agentId};f&&(h.cozeTriggerMsgId=f);let g=u?e.activeGroupIds.get(u):void 0;g&&(h.cozeGroupId=g);let w=u?this.reverseSessionId(e,u):void 0,S=w?e.sessions.get(w):void 0;S&&(S.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let _={...c,...w?{sessionId:w}:{},_meta:h};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:w}),K.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:w,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(v=>({optionId:v.optionId,kind:v.kind,name:v.name}))}),this.upstream.send(Mi(o,"session/request_permission",_)).catch(v=>{this.pendingUpstream.delete(o),K.error("forward permission request failed",{agentId:e.agentId,err:String(v)}),r.respondAgentRequestError(i.id,{code:Z.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"&&db(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 xo(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),d=e.get(c);if(d)return K.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:d,key:c}}}sendRequest(e,r,i=rb){let o=this.upstreamIds.next(e);return new Promise((c,d)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),d(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:d,timer:u}),this.upstream.send(Mi(o,e,r)).catch(f=>{let h=this.pendingBridge.get(o);h&&(clearTimeout(h.timer),this.pendingBridge.delete(o)),d(f)})})}async persistSessionMapping(e){if(this.paths)try{let r=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),o.permissionMode&&$t(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await ri(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(vn(e,{code:r,message:i,data:{bridgeVersion:Pt}}))}};function cb(){return nb(16).toString("hex")}function db(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 lb=["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 ub(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 lb.some(c=>o.startsWith(c))}on();te();Oe();import{randomBytes as fb}from"node:crypto";import{createServer as xb}from"node:http";var hb=1e6,gx=q("ipc"),Ao=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??Q()}async start(){this.token=fb(32).toString("hex");let e=xb((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(),gx.info("IPC listening",{port:this.port}),{port:this.port,token:this.token}}async stop(){let e=this.server;e&&(await new Promise((r,i)=>{e.close(o=>o?i(o):r())}),this.server=null)}async persistAuthFiles(){await sn(this.paths.portFile,String(this.port)),await sn(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Wi(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Wi(r,404,{error:"not found"});return}let d=null;if(e.method==="POST")try{d=await pb(e)}catch(u){Wi(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(d,e);Wi(r,200,u??{ok:!0})}catch(u){gx.error("IPC handler failed",{key:o,err:String(u)}),Wi(r,500,{error:u instanceof Error?u.message:String(u)})}}};function Wi(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function pb(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>hb)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}import"node:module";var Mv=zt(fh(),1),Bv=zt(No(),1),Fv=zt(Fr(),1),zv=zt(bd(),1),Uv=zt(Id(),1),Gv=zt(Dd(),1),Eh=zt(zo(),1),Hv=zt(yh(),1);var bh=Eh.default;We();te();var{FWS:iS}=Oh(),De=q("upstream.frontier"),Nh="application/json",Mh="none",sS=15e3;function oS(t){class e extends bh{constructor(i){super(i,Bf,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>De.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(El("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");De.debug("WS raw frame out",{bytes:c.byteLength,headHex:d})}catch(c){De.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var es=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){De.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Ff,...En(this.opts.ppeOverride)},r=oS(e),i=Uf(this.opts.urlOverride),o={url:i,ws:r,fpID:Mf,aID:ao,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Nh,force:!0},payloadEncoding:{encoding:Mh,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new iS(o),d=!1,u=null,f,h,g=new Promise((_,v)=>{f=_,h=v}),w=_=>{d||(d=!0,u&&(clearTimeout(u),u=null),_?h(_):f())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let _=this.openCount===1;De.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:_,openCount:this.openCount}),_&&w();for(let v of this.connectHandlers)Promise.resolve(v({initial:_})).catch(I=>De.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=_=>{this.opened=!1,De.info("frontier closed",{code:_.code,reason:_.reason,willReconnect:_.willReconnect})},c.onerror=_=>{De.warn("frontier error",{code:_.code,msg:_.message}),w(new T("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${_.code} msg=${_.message??""}`))},c.onmessage=_=>this.handleMessage(_),this.fws=c;let S=this.opts.openTimeoutMs??sS;u=setTimeout(()=>{w(new T("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${S}ms (handshake or upgrade slow)`))},S),await c.connect();try{await g}catch(_){try{c.close(1e3,"open failed")}catch(v){De.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,_}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){De.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw De.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?(De.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;Bh(c)||De.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:Nh,payloadEncoding:Mh})}catch(u){throw De.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){De.debug("drop non-adapter frontier frame",{service:r});return}let i=dS(e);if(!i){De.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){De.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(d){De.warn("frontier message JSON parse failed",{err:String(d),head:i.slice(0,80)});return}let c=o;Bh(c)||De.info("frontier frame in",{logid:cS(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:aS(i)}),Promise.resolve(this.handler(o)).catch(d=>De.warn("frontier frame handler threw",{err:String(d)}))}};function Bh(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Fh=2e3;function aS(t){return t.length<=Fh?t:`${t.slice(0,Fh)}...<truncated, total ${t.length} chars>`}function cS(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function dS(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}}We();te();var Nd=q("skill-publish"),lS="/api/marketplace/product/skill/publish_with_assets",uS=15e4;async function zh(t,e={}){let i=`${kr(Tr(e.handshakeBase))}${lS}`,o=e.timeoutMs??uS,c=new FormData;c.append("skill_id",t.skillId??""),c.append("skill_name",t.skillName),c.append("skill_description",t.description??""),c.append("agent_id",t.agentId),c.append("zip_file",new Blob([t.zip],{type:"application/zip"}),"skill.zip");let d={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...En(e.ppeOverride),...t.accountId&&t.accountId!=="0"?{"x-coze-account":t.accountId}:{}},u=new AbortController,f=setTimeout(()=>u.abort(),o);Nd.info("skill publish start",{url:i,method:"POST",form:{skill_id:t.skillId??"",skill_name:t.skillName,skill_description:t.description??"",agent_id:t.agentId,zip_file_bytes:t.zip.length},headers:{...d,Authorization:`Bearer ${t.patToken.slice(0,8)}...`}});try{let h=await fetch(i,{method:"POST",headers:d,body:c,signal:u.signal}),g=h.headers.get("x-tt-logid")??"";if(!h.ok){let _=await h.text().catch(()=>"");throw new T("UPLOAD_FAILED",`skill publish HTTP ${h.status} logid=${g}: ${_.slice(0,200)}`)}let w=await h.json();if(Nd.info("skill publish response",{logid:g,httpStatus:h.status,code:w.code,msg:w.msg,dataSkillId:w.data?.skill_id??"",dataVersion:w.data?.version??""}),w.code!==void 0&&w.code!==0)throw new T("UPLOAD_FAILED",`skill publish code=${w.code} msg=${w.msg??"-"} logid=${g}`);let S={};return w.data?.skill_id!==void 0&&w.data.skill_id!==""&&(S.skillId=String(w.data.skill_id)),w.data?.version&&(S.version=w.data.version),Nd.info("skill publish ok",{logid:g,skillId:S.skillId??"",version:S.version??""}),S}catch(h){throw h instanceof T?h:h.name==="AbortError"?new T("UPLOAD_FAILED",`skill publish timeout (${o}ms): ${t.skillName}`):new T("UPLOAD_FAILED",String(h),{cause:h})}finally{clearTimeout(f)}}te();var Md=q("upstream.switchable"),Vo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;Md.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 Md.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>Md.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()}};te();var Bd=q("upstream"),jr=class{handler=null;async start(){Bd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Bd.info("NoopUpstream stopped",{reason:e})}async send(e){Bd.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};We();te();on();te();Oe();import{promises as fS}from"node:fs";var Uh=q("pat-token-store");async function Yo(t=Q()){try{let r=(await fS.readFile(t.patTokenFile,"utf8")).trim();return r.length===0?(Uh.warn("pat-token exists but empty (treating as missing; likely interrupted write)",{path:t.patTokenFile}),null):r}catch(e){let r=e?.code;return r!=="ENOENT"&&Uh.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function ts(t,e=Q()){if(!t)throw new Error("writePatToken: empty patToken");await sn(e.patTokenFile,t,{mode:384})}Oe();Oe();import{promises as Zo}from"node:fs";import{join as xS}from"node:path";function hS(t,e){return`#!/bin/sh
103
105
  exec ${JSON.stringify(e)} ${JSON.stringify(t)} "$@"
104
- `}function rS(t,e){return`@echo off\r
106
+ `}function pS(t,e){return`@echo off\r
105
107
  "${e}" "${t}" %*\r
106
- `}async function kh(t,e=Q()){let r=e.binDir;await Qo.mkdir(r,{recursive:!0});let i=tS(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?rS(t,o):nS(t,o);return await Qo.readFile(i,"utf8").catch(()=>null)===c||(await Qo.writeFile(i,c,"utf8"),process.platform!=="win32"&&await Qo.chmod(i,493)),r}re();Le();import{execSync as Ph}from"node:child_process";import{readFileSync as Oh,unlinkSync as iS}from"node:fs";import{mkdir as sS,open as oS,readFile as Lh,unlink as Nd,writeFile as aS}from"node:fs/promises";import{dirname as cS}from"node:path";var dS=H("single-instance"),lS=t=>new Promise(e=>setTimeout(e,t)),ea=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??Q().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:r=>Hi(r),isDaemon:r=>this.matchesDaemonTitle(r)},e.processTitle&&(process.title=e.processTitle)}async acquire(){let e=await this.readExistingPid();if(e!==null&&e!==this.selfPid&&this.isLiveDaemon(e))return{kind:"already-running",pid:e};let r=await this.withClaimLock(async()=>{let i=await this.readExistingPid();return i!==null&&i!==this.selfPid&&this.isLiveDaemon(i)?{kind:"already-running",pid:i}:(i!==null&&i!==this.selfPid&&dS.warn("removing stale pid file",{stalePid:i}),await aS(this.pidFile,String(this.selfPid),"utf8"),{kind:"acquired"})});return r.kind==="acquired"&&(this.acquired=!0,this.installCleanupHooks()),r}async release(){if(this.acquired){try{(await Lh(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Nd(this.pidFile)}catch{}this.acquired=!1}}isLiveDaemon(e){return this.probe.isAlive(e)&&this.probe.isDaemon(e)}async readExistingPid(){return this.readPidFrom(this.pidFile)}async readPidFrom(e){try{let r=await Lh(e,"utf8"),i=Number.parseInt(r.trim(),10);return Number.isFinite(i)&&i>0?i:null}catch(r){if(r.code==="ENOENT")return null;throw r}}async withClaimLock(e){let r=`${this.pidFile}.lock`;await sS(cS(r),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await oS(r,"wx")}catch(c){if(c.code!=="EEXIST")throw c;let l=await this.readPidFrom(r);if(l!==null&&l!==this.selfPid&&this.probe.isAlive(l)){await lS(this.claimLockIntervalMs);continue}await Nd(r).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Nd(r).catch(()=>{})}}throw new Error(`failed to acquire claim lock: ${r} (after ${this.claimLockMaxAttempts} attempts)`)}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let r=Oh(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes(Mr)||r.includes("lib/index.js"))}catch{}try{let r=Ph(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes(Mr)||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=Ph(`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{Oh(this.pidFile,"utf8").trim()===String(this.selfPid)&&iS(this.pidFile)}catch{}})}};ta();re();var tr=H("daemon.upstream-watchdog"),wS=12e4,_S=9e5,yS=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 na=class{constructor(e){this.opts=e;this.softMs=e.softMs??Bd("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",wS),this.hardMs=e.hardMs??Bd("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",_S),this.intervalMs=e.intervalMs??Bd("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",yS),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?.(),tr.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&&tr.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&&tr.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,tr.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){tr.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,tr.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>tr.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var W=H("daemon");async function Bh(){let t=Q();if(process.env.COZE_BRIDGE_LOG_MODE!=="legacy"){pl({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:N=>nt(N,t).logs,listAgentIds:()=>gs(t)});try{let{writeFileSync:N}=await import("node:fs");N(t.logFile,`\u8FD0\u884C\u65E5\u5FD7\u5DF2\u8FC1\u79FB\u5230 dated \u6587\u4EF6, \u6B64\u6587\u4EF6 (bridge.log) \u4E0D\u518D\u5199\u5165\u8FD0\u884C\u65E5\u5FD7\u3002
108
+ `}async function Gh(t,e=Q()){let r=e.binDir;await Zo.mkdir(r,{recursive:!0});let i=xS(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?pS(t,o):hS(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}te();Oe();import{execSync as Hh}from"node:child_process";import{readFileSync as qh,unlinkSync as gS}from"node:fs";import{mkdir as mS,open as wS,readFile as jh,unlink as Fd,writeFile as _S}from"node:fs/promises";import{dirname as yS}from"node:path";var ES=q("single-instance"),bS=t=>new Promise(e=>setTimeout(e,t)),Jo=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??Q().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:r=>zi(r),isDaemon:r=>this.matchesDaemonTitle(r)},e.processTitle&&(process.title=e.processTitle)}async acquire(){let e=await this.readExistingPid();if(e!==null&&e!==this.selfPid&&this.isLiveDaemon(e))return{kind:"already-running",pid:e};let r=await this.withClaimLock(async()=>{let i=await this.readExistingPid();return i!==null&&i!==this.selfPid&&this.isLiveDaemon(i)?{kind:"already-running",pid:i}:(i!==null&&i!==this.selfPid&&ES.warn("removing stale pid file",{stalePid:i}),await _S(this.pidFile,String(this.selfPid),"utf8"),{kind:"acquired"})});return r.kind==="acquired"&&(this.acquired=!0,this.installCleanupHooks()),r}async release(){if(this.acquired){try{(await jh(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Fd(this.pidFile)}catch{}this.acquired=!1}}isLiveDaemon(e){return this.probe.isAlive(e)&&this.probe.isDaemon(e)}async readExistingPid(){return this.readPidFrom(this.pidFile)}async readPidFrom(e){try{let r=await jh(e,"utf8"),i=Number.parseInt(r.trim(),10);return Number.isFinite(i)&&i>0?i:null}catch(r){if(r.code==="ENOENT")return null;throw r}}async withClaimLock(e){let r=`${this.pidFile}.lock`;await mS(yS(r),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await wS(r,"wx")}catch(c){if(c.code!=="EEXIST")throw c;let d=await this.readPidFrom(r);if(d!==null&&d!==this.selfPid&&this.probe.isAlive(d)){await bS(this.claimLockIntervalMs);continue}await Fd(r).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Fd(r).catch(()=>{})}}throw new Error(`failed to acquire claim lock: ${r} (after ${this.claimLockMaxAttempts} attempts)`)}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let r=qh(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes(Or)||r.includes("lib/index.js"))}catch{}try{let r=Hh(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes(Or)||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=Hh(`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{qh(this.pidFile,"utf8").trim()===String(this.selfPid)&&gS(this.pidFile)}catch{}})}};Xo();te();var Xn=q("daemon.upstream-watchdog"),CS=12e4,DS=9e5,PS=3e4;function Ud(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Qo=class{constructor(e){this.opts=e;this.softMs=e.softMs??Ud("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",CS),this.hardMs=e.hardMs??Ud("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",DS),this.intervalMs=e.intervalMs??Ud("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",PS),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?.(),Xn.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&&Xn.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&&Xn.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,Xn.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){Xn.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,Xn.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>Xn.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var j=q("daemon");async function $h(){let t=Q();if(process.env.COZE_BRIDGE_LOG_MODE!=="legacy"){_l({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:D=>Ye(D,t).logs,listAgentIds:()=>xs(t)});try{let{writeFileSync:D}=await import("node:fs");D(t.logFile,`\u8FD0\u884C\u65E5\u5FD7\u5DF2\u8FC1\u79FB\u5230 dated \u6587\u4EF6, \u6B64\u6587\u4EF6 (bridge.log) \u4E0D\u518D\u5199\u5165\u8FD0\u884C\u65E5\u5FD7\u3002
107
109
  \u8BF7\u67E5\u770B: ${t.bridgeLogsDir}/bridge-<YYYY-MM-DD>.log
108
110
  \u6216\u4F7F\u7528: coze-bridge log [-f] [--lines N]
109
- `)}catch{}}let e=new ea({processTitle:Mr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await Co(),o=i??{};hs({pid:process.pid}),W.info(i?"loaded bridge config":"initialized bridge config");let c=new Xo(new $r),l=null,u=new To({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(N,j,$,oe)=>{if(!l)throw new Error("agentManager not ready");return l.spawnSessionDownstream(N,j,$,oe)}}),x=new So({paths:t,config:o,registry:u});l=x;let h,m,E=null,S={},_,v=null,A=null,I=null,D=new Tn;function O(N,j){return D.enqueue(()=>k(N,j))}function y(){A||(A=new na({isConnected:()=>c.isConnected(),forceReconnect:()=>I?O(I,{force:!0}):void 0,onFatal:N=>{if(process.env[os]==="1"){W.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:N});return}W.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:N}),process.exit(1)}})),A.start()}async function k(N,j){let $=N,oe=$?.privatecode;if(!oe)throw new T("IPC_BAD_REQUEST","/connect requires privatecode");let Qe=Bi($.env),he=$.handshake_url,pe=$.frontier_url,It=Mh($.env,he,pe);if(I=$,!j?.force&&h===oe&&m===It){let we=await bS(t);return u.agents.size===0&&we?(W.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),ia(t,x).catch(Ie=>W.warn("connect-noop auto-revive error (ignored)",{err:String(Ie)}))):W.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let pt=!!h&&h!==oe,tn=m!==void 0&&m!==It,Ut=pt||tn,nn=await Uc({privatecode:oe,...he?{endpoint:he}:{},ppeOverride:Qe});if(Ut){W.warn("connect config switched, resetting agents",{pcChanged:pt,envChanged:tn,previousPc:h?ra(h):"",nextPc:ra(oe)});for(let we of[...u.agents.values()])await we.dispose("connect config switch").catch(()=>{}),u.agents.delete(we.agentId);u.disconnectedAgents.size>0&&(W.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new $r,"connect switch").catch(()=>{})}E=nn.deviceId,hs({deviceId:E,pid:process.pid}),cd({patToken:oe,env:$.env}).catch(we=>W.warn("coze-cli setup error (ignored)",{err:String(we)}));let Yr=new is({handshake:nn,privatecode:oe,...pe?{urlOverride:pe}:{},ppeOverride:Qe,getPatTokenForAgent:we=>u.agents.get(we)?.patToken});return await c.swap(Yr,"connect"),h=oe,m=It,S=Qe,_=he,$.mock_scenario!==void 0&&(u.setMockScenario($.mock_scenario),W.info("mock scenario set",{scenario:$.mock_scenario})),v||(v=new Fi({core:u,getDeviceId:()=>E??"",onTickEnd:()=>z.retryPending().catch(we=>W.warn("detailSync.retryPending failed (ignored)",{err:String(we)})),onAuthFailures:Z})),v.start(),y(),Ut&&ia(t,x).catch(we=>W.warn("post-connect-switch auto-revive error (ignored)",{err:String(we)})),ss(oe,t).catch(we=>W.warn("writePatToken after /connect failed (ignored)",{err:String(we)})),W.info("/connect: WS established",{deviceId:E}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async N=>x.createAgent(N.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let L={},U=new po({agents:u.agents,disposeAndMarkDisconnected:async(N,j)=>{let $=u.agents.get(N);if($){await x.cleanupOpenclawSessionProviders($).catch(Qe=>W.warn("cleanup openclaw providers failed (ignored)",{agentId:N,err:String(Qe)}));let oe=!0;try{await $.dispose(`disconnect: ${j}`)}catch(Qe){oe=!1,W.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:N,err:String(Qe)}),$.status="error"}oe&&($.status="disconnected",u.unregister(N),u.disconnectedAgents.add(N))}else u.disconnectedAgents.add(N)},detailSyncer:async N=>{if(!L.ref)throw new Error("agent-detail-sync not initialized yet");await L.ref.syncOne(N)},cleanupOpenclawProviders:async N=>{await x.cleanupOpenclawSessionProviders(N)},openclawRepair:async(N,j)=>{await x.openclawRepair(N,j)},isRuntimePendingPermission:N=>u.hasPendingPermissionFor(N)});u.registerExtension("_agent/listSkills",N=>U.listSkills(N.params)),u.registerExtension("_agent/addSkills",N=>U.addSkills(N.params)),u.registerExtension("_agent/removeSkills",N=>U.removeSkills(N.params)),u.registerExtension("_agent/getFileTree",N=>U.getFileTree(N.params)),u.registerExtension("_agent/getFileContent",N=>U.getFileContent(N.params)),u.registerExtension("_agent/update",N=>U.updateAgent(N.params)),u.registerExtension("_agent/disconnect",N=>U.disconnectAgent(N.params)),u.registerExtension("_agent/switchModel",N=>U.switchModel(N.params)),u.registerExtension("_agent/reset",N=>U.resetAgent(N.params)),u.registerExtension("_agent/repair",N=>U.repairAgent(N.params)),u.registerExtension("_agent/upgrade",N=>U.upgradeBridge(N.params));let z=new ys({paths:t,handlers:U,agentManager:x,sendDetail:N=>u.sendRequest("_agent/detail",N)});L.ref=z;let Z=async N=>{await Promise.allSettled(N.map(async j=>{try{await U.disconnectAgent({agentId:j.agentId,reason:`auth_failure: code=${j.code} ${j.message}`}),W.info("agent disconnected due to auth failure from heartbeat response",{agentId:j.agentId,code:j.code,message:j.message})}catch($){W.warn("disconnect during authFailure handling failed (ignored)",{agentId:j.agentId,err:String($)})}}))};c.onConnect(({initial:N})=>{W.info("frontier upstream connected, triggering detail sync",{initial:N}),z.syncAll(N?"initial-connect":"reconnect").catch(j=>W.warn("detail sync top-level error (ignored)",{err:String(j)}))});let V=new Ro({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let N=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[os]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:E??"",frameworksCache:o.frameworksCache??{},...N?{mockScenario:N}:{}}}},{method:"POST",path:"/pair",handler:async N=>{let j=N,$=j?.privatecode,oe=j?.pairing_code;if(!$||!oe)throw new T("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Qe=Bi(j.env),he=j.handshake_url,pe=j.frontier_url,It=Mh(j.env,he,pe),pt=!!h&&h!==$,tn=m!==void 0&&m!==It,Ut=pt||tn,nn=await Uc({privatecode:$,...he?{endpoint:he}:{},ppeOverride:Qe});if(Ut){W.warn("pair config switched, resetting agents",{pcChanged:pt,envChanged:tn,previousPc:h?ra(h):"",nextPc:ra($),previousEnvKey:m??"",nextEnvKey:It});for(let Ie of[...u.agents.values()])await Ie.dispose("pair config switch").catch(()=>{}),u.agents.delete(Ie.agentId);u.disconnectedAgents.size>0&&(W.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new $r,"pair switch").catch(()=>{})}E=nn.deviceId,hs({deviceId:E,pid:process.pid}),cd({patToken:$,env:j.env}).catch(Ie=>W.warn("coze-cli setup error (ignored)",{err:String(Ie)}));let Yr=new is({handshake:nn,privatecode:$,...pe?{urlOverride:pe}:{},ppeOverride:Qe,getPatTokenForAgent:Ie=>u.agents.get(Ie)?.patToken});await c.swap(Yr,"pair");try{let Ie=new Zn;o.frameworksCache=await Ie.detectAll(),await $i(o),W.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ie){W.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ie)})}let we=Object.keys(o.frameworksCache??{});try{let Ie=await u.sendRequest("_agent/pair",{pairCode:oe,patToken:$,frameworks:we,_meta:{cozeDeviceId:E}});W.info("_agent/pair ok",{pairResult:Ie}),h=$,m=It,S=Qe,_=he,j.mock_scenario!==void 0&&(u.setMockScenario(j.mock_scenario),W.info("mock scenario set",{scenario:j.mock_scenario})),ss($,t).catch(ke=>W.warn("writePatToken after /pair failed (ignored)",{err:String(ke)})),v||(v=new Fi({core:u,getDeviceId:()=>E??"",onTickEnd:()=>z.retryPending().catch(ke=>W.warn("detailSync.retryPending failed (ignored)",{err:String(ke)})),onAuthFailures:Z})),v.start(),y(),Ut&&ia(t,x).catch(ke=>W.warn("post-pair-switch auto-revive error (ignored)",{err:String(ke)}));let nr;return j.agent_id&&(nr=await vS(j.agent_id,t,x,ke=>u.sendRequest("_agent/detail",ke),$).catch(ke=>(W.error("--agent-id ensureAgent failed",{agentId:j.agent_id,err:String(ke)}),{ok:!1,agentId:j.agent_id??"",note:String(ke)}))),{ok:!0,note:"paired with cloud",...nr?{agent:nr}:{}}}catch(Ie){return W.error("_agent/pair failed",{err:String(Ie)}),{ok:!1,note:`pair failed: ${String(Ie)}`}}}},{method:"POST",path:"/connect",handler:N=>O(N)},{method:"POST",path:"/_agent/create",handler:async N=>{let j=N;return{ok:!0,result:await x.createAgent(j)}}},{method:"POST",path:"/agent/send",handler:async N=>{let j=N;if(!j?.agentId||!j?.sessionId||!j?.kind||!j?.path)throw new T("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!h)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let $=j;return await($.groupFile?W0:j0)($,{core:u,patToken:h,handshakeBase:_,ppeOverride:S})}catch($){if($ instanceof T)return{ok:!1,code:$.code,message:$.message};throw $}}},{method:"POST",path:"/reload",handler:async N=>{let j=N?.agent_id,$=await u.reloadAgents(j);return W.info("IPC /reload: recycled agent subprocesses",{agentId:j??"(all)",recycled:$}),{ok:!0,recycled:$}}},{method:"POST",path:"/shutdown",handler:async()=>(W.info("IPC /shutdown received"),setImmediate(()=>{ae.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:ne,token:X}=await V.start();try{await kh(t.libEntry,t)}catch(N){W.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(N)})}await u.start(),SS({paths:t,core:u,agentManager:x,detectAll:async()=>(o.frameworksCache=await new Zn().detectAll(),await $i(o),o.frameworksCache)}).catch(N=>W.warn("startup warmup error (ignored)",{err:String(N)})),Al().then(async()=>{let{probeAcpVersion:N}=await Promise.resolve().then(()=>(an(),vl));for(let j of["claude-code","codex"]){let $=await N(j);$&&W.info("acp wrapper version",{framework:j,version:$})}}).catch(N=>W.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(N)}));let se=null,ae={port:ne,token:X,core:u,ipc:V,shutdown(N){return se||(W.info("daemon shutdown",{reason:N}),se=(async()=>{v?.stop(),A?.stop(),await u.stop(N),await V.stop(),await e.release()})(),se)}};for(let N of["SIGTERM","SIGINT"])process.on(N,()=>{ae.shutdown(N).then(()=>process.exit(0))});return process.on("exit",()=>c0()),process.on("unhandledRejection",N=>{W.error("unhandledRejection",{reason:N instanceof Error?N.message:String(N),stack:N instanceof Error?N.stack:void 0})}),process.on("uncaughtException",N=>{W.error("uncaughtException (will exit, supervisor will restart)",{message:N.message,stack:N.stack,name:N.name});try{process.stderr.write(`FATAL uncaughtException: ${N.stack??N.message}
110
- `)}catch{}process.exit(1)}),W.info("daemon ready",{port:ne,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),AS({cliSpawned:process.env[os]==="1",readPatToken:()=>Yo(t),connect:O}).catch(N=>W.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(N)})),ae}async function bS(t){return gs(t).length>0}function ra(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function Mh(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function ES(t,e){let r=gs(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(ln(),_s));for(let c of r){await o(c,t).catch(l=>W.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(l)}));try{let l=await i(c,t);l?.disconnectedAt&&(e.disconnectedAgents.add(c),W.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:l.disconnectedAt,reason:l.disconnectReason??""}))}catch(l){W.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(l)})}}}async function vS(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(ln(),_s)),l=await c(t,e);if(l){W.info("--agent-id: local config found, reconnecting",{agentId:t,framework:l.framework,hadDisconnect:!!l.disconnectedAt});let m=zh(l),E={agentId:l.agentId,framework:l.framework,...l.cozeIdentity?{cozeIdentity:l.cozeIdentity}:{},...l.model?{model:l.model}:{},...o?{patToken:o}:{},...m?{_meta:m}:{}};return await r.createAgent(E),{ok:!0,agentId:t,note:l.disconnectedAt?"revived from local config":"connected from local config"}}W.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let u=await i({_meta:{cozeAgentId:t}});if(!u.framework)throw new T("AGENT_NOT_FOUND",`agent ${t} \u4E0D\u5728\u672C\u5730; \u4E91\u7AEF _agent/detail \u54CD\u5E94\u7F3A framework \u5B57\u6BB5 (D36 \u534F\u8BAE\u6269\u5C55\u672A\u751F\u6548), \u65E0\u6CD5\u5728\u672C\u673A\u65B0\u5EFA`);let x={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...u.deployType?{_meta:{cozeDeployType:u.deployType}}:{}};await r.createAgent(x);let h=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:h?"cloud agent acknowledged":"created from cloud detail"}}async function SS(t){let e=t.logger??W;try{let r=await t.detectAll();e.info("refreshed frameworks_cache",{detected:Object.keys(r??{})})}catch(r){e.warn("framework detection failed (using cached)",{err:String(r)})}await ES(t.paths,t.core).catch(r=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(r)})),await ia(t.paths,t.agentManager).catch(r=>e.warn("auto-revive top-level error (ignored)",{err:String(r)}))}async function ia(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(()=>(ln(),_s));W.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(h){W.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(h)}),l+=1;continue}if(!x){l+=1;continue}if(x.disconnectedAt){W.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:x.disconnectedAt}),l+=1;continue}try{W.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:x.framework});let h=zh(x);await e.createAgent({agentId:x.agentId,framework:x.framework,...x.cozeIdentity?{cozeIdentity:x.cozeIdentity}:{},...x.model?{model:x.model}:{},...h?{_meta:h}:{}},{revive:!0}),c+=1}catch(h){W.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:x.framework,err:String(h)}),l+=1}}return W.info("auto-revive: done",{revived:c,skipped:l,total:i.length}),{revived:c,skipped:l,total:i.length}}async function AS(t){let e=t.logger??W;if(t.cliSpawned)return"skipped-cli";let r=await t.readPatToken();return r?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:r}).catch(i=>e.warn("startup auto-connect failed (staying idle)",{err:String(i)})),"connecting"):(e.info("no stored PAT, skip startup auto-connect"),"skipped-no-pat")}function zh(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}ta();Le();import{readFile as Fh}from"node:fs/promises";var en=class{paths;constructor(e){this.paths=e??Q()}async probe(e=1e3){let r=await sa(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:CS(i)}}}async request(e){let r=await sa(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:IS(x)}}finally{clearTimeout(l)}}};async function sa(t){try{let[e,r]=await Promise.all([Fh(t.portFile,"utf8"),Fh(t.tokenFile,"utf8")]),i=Number.parseInt(e.trim(),10),o=r.trim();return!Number.isFinite(i)||i<=0||!o?null:{port:i,token:o}}catch(e){if(e.code==="ENOENT")return null;throw e}}function IS(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function CS(t){return t instanceof Error?t.message:String(t)}Vt();re();or();import{spawn as TS}from"node:child_process";import{userInfo as qh}from"node:os";var zd="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",RS=new Set(["bash","zsh","sh","dash","ksh"]),Uh=Ve("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),DS=2e3;function kS(t,e=zd){let r=t.indexOf(e);if(r===-1)return null;let i=t.indexOf(e,r+e.length);if(i===-1)return null;let o=t.slice(r+e.length,i),c={};for(let l of o.split(`
111
- `)){let u=l.indexOf("=");u<=0||(c[l.slice(0,u)]=l.slice(u+1))}return c}function PS(){let t=(process.env.SHELL??"").trim()||(qh().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return RS.has(e)?t:null}function OS(t){return new Promise(e=>{let r=`printf '%s' '${zd}'; env; printf '%s' '${zd}'`,i;try{i=TS(t,["-ilc",r],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??qh().homedir}})}catch{e(null);return}let o="",c=!1,l=m=>{try{i.pid&&process.kill(-i.pid,m)}catch{}},u=m=>{c||(c=!0,clearTimeout(x),clearTimeout(h),e(m))};i.stdout?.on("data",m=>{o+=m.toString("utf8")}),i.on("error",()=>u(null)),i.on("close",()=>u(o.length>0?o:null));let x=setTimeout(()=>l("SIGTERM"),Uh),h=setTimeout(()=>{l("SIGKILL"),u(o.length>0?o:null)},Uh+DS)})}async function Fd(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let r=PS();if(!r)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??OS)(r);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=kS(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}Le();function kn(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}}an();import{chmod as LS,copyFile as Gh,mkdir as jh,readFile as oa,rename as Hh,rm as Ud,stat as Wh,writeFile as NS}from"node:fs/promises";import{homedir as MD}from"node:os";import{dirname as MS,join as Vr,resolve as qd,sep as as}from"node:path";import{fileURLToPath as BS}from"node:url";Vt();re();Le();var Gd=H("dist-install");function zS(t){let e=BS(t),r=MS(e),i=`${as}src${as}`;if(r.includes(i)||r.endsWith(`${as}src${as}cli`))return null;let o=qd(r,"index.js"),c=qd(r,"..","package.json");return{dist:o,pkgJson:c}}async function jd(t={}){let e=t.paths??Q(),r=zS(import.meta.url),i=t.sourceDist??r?.dist,o=t.sourcePackageJson??r?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,l;try{let S=JSON.parse(await oa(o,"utf8"));c=S.version??"unknown",l=S.dependencies??{}}catch(S){return Gd.warn("cannot read source package.json,skip dist install",{err:String(S)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(S)}`}}let u=si.map(S=>`${S}@${l[S]??"latest"}`),x=await Co(e.configFile)??{},h=x.libVersion,m=await oa(e.libEntry).then(()=>!0).catch(()=>!1),E=h===c;if(E&&m&&await Hd(e))return{kind:"already-current",libVersion:c};if(!E||!m){await jh(e.libDir,{recursive:!0}),await Gh(i,e.libEntry),await Gh(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let S=qd(e.libDir,"package.json"),_=`${JSON.stringify({type:"module"},null,2)}
112
- `;await oa(S,"utf8").catch(()=>null)!==_&&await NS(S,_)}return(!E||!await Hd(e))&&await(t.installWrappers??FS)(e,u),x.libVersion=c,await $i(x,e.configFile),Gd.info("dist installed",{libEntry:e.libEntry,fromVersion:h,toVersion:c}),E&&m?{kind:"already-current",libVersion:c}:h?{kind:"version-changed",fromVersion:h,toVersion:c,libEntry:e.libEntry}:{kind:"first-install",libVersion:c,libEntry:e.libEntry}}async function Hd(t){for(let e of si){let r=Vr(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await Wh(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function FS(t,e){await GS(t.installLock,async()=>{if(await Hd(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${as}.staging-${process.pid}-${r}`,o=Vr(i,"node_modules"),c=Vr(t.libDir,"node_modules");try{await jh(i,{recursive:!0}),await US(e,i),await qS(o);let l=`${c}.trash-${r}`;await Hh(c,l).catch(()=>{}),await Hh(o,c),await Ud(l,{recursive:!0,force:!0}).catch(()=>{}),Gd.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await Ud(i,{recursive:!0,force:!0}).catch(()=>{})}})}function US(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=st("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 qS(t){for(let e of si){let r=Vr(t,...e.split("/")),i=JSON.parse(await oa(Vr(r,"package.json"),"utf8"));if(!i.version)throw new Error(`${e}: package.json \u7F3A version`);let o=typeof i.bin=="string"?e.split("/").pop():Object.keys(i.bin??{})[0];if(!o)throw new Error(`${e}: package.json \u7F3A bin`);let c=Vr(t,".bin",o),l=await Wh(c);process.platform!=="win32"&&!(l.mode&73)&&await LS(c,l.mode|73).catch(()=>{})}}async function GS(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 Ud(t,{force:!0}).catch(()=>{})}}Aa();re();Le();import{closeSync as $h,fstatSync as Vh,openSync as Zh,readFileSync as HS,readSync as jS,readdirSync as WS,statSync as KS}from"node:fs";import{join as aa}from"node:path";var $S=new Set(["debug","info","warn","error"]);function Jh(t){let e=t,r=kn(e,"--agent-id");e=r.rest;let i=kn(e,"--date");e=i.rest;let o=kn(e,"-n","--lines");e=o.rest;let c=kn(e,"--level");e=c.rest;let l=kn(e,"--grep");e=l.rest;let u=o.value===void 0?200:Number(o.value),x=Number.isInteger(u)&&u>=0?u:200,h=c.value&&$S.has(c.value)?c.value:void 0,m={lines:x,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(m.agentId=r.value),i.value&&(m.date=i.value),h&&(m.level=h),l.value&&(m.grep=l.value),m}function VS(t,e){return t.agentId?aa(nt(t.agentId,e).logs,ar("agent",t.date)):aa(e.bridgeLogsDir,ar("bridge",t.date))}function ZS(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function JS(t,e){let r;try{r=WS(t)}catch{return[]}let i=[];for(let o of r){let c=Sa(o,e);if(!c)continue;let l=0;try{l=KS(aa(t,o)).size}catch{}i.push({file:aa(t,o),date:c,size:l})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function Xh(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"&&!wl(r,e.level))return!1}return!0}var Kh={debug:"90",info:"36",warn:"33",error:"31"},XS=new Set(["ts","level","module","msg"]);function YS(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function Yh(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=YS(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&Kh[o]&&(c=`\x1B[${Kh[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(([h])=>!XS.has(h)).map(([h,m])=>` ${h}=${typeof m=="string"?m:JSON.stringify(m)}`).join("");return`${i} ${c} ${l} ${u}${x}`}function QS(t,e,r){let c=HS(t,"utf8").split(`
113
- `).filter(l=>l.length>0).filter(l=>Xh(l,{level:e.level,grep:e.grep}));for(let l of ZS(c,e.lines))process.stdout.write(`${Yh(l,{raw:e.raw,color:r})}
114
- `)}async function Qh(t,e){let r=e.paths??Q(),i=process.stdout.isTTY===!0;if(t.list){let l=t.agentId?nt(t.agentId,r).logs:r.bridgeLogsDir,u=t.agentId?"agent":"bridge",x=JS(l,u);if(x.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${l}
115
- `),1;for(let h of x)process.stdout.write(`${h.date} ${(h.size/1024).toFixed(1)}KB ${h.file}
116
- `);return 0}let o=t.date??Ln(new Date),c=VS({agentId:t.agentId,date:o},r);try{QS(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
111
+ `)}catch{}}let e=new Jo({processTitle:Or}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await So(),o=i??{};us({pid:process.pid}),j.info(i?"loaded bridge config":"initialized bridge config");let c=new Vo(new jr),d=null,u=new Io({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(D,G,W,ee)=>{if(!d)throw new Error("agentManager not ready");return d.spawnSessionDownstream(D,G,W,ee)}}),f=new Eo({paths:t,config:o,registry:u});d=f;let h,g,w=null,S={},_,v=null,I=null,A=null,R=new In;function O(D,G){return R.enqueue(()=>C(D,G))}function y(){I||(I=new Qo({isConnected:()=>c.isConnected()&&!(v?.isLivenessLost()??!1),forceReconnect:()=>A?O(A,{force:!0}):void 0,onFatal:D=>{if(process.env[ns]==="1"){j.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:D});return}j.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:D}),process.exit(1)}})),I.start()}async function C(D,G){let W=D,ee=W?.privatecode;if(!ee)throw new T("IPC_BAD_REQUEST","/connect requires privatecode");let Qe=Oi(W.env),xe=W.handshake_url,he=W.frontier_url,St=Kh(W.env,xe,he);if(A=W,!G?.force&&h===ee&&g===St){let we=await OS(t);return u.agents.size===0&&we?(j.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),ta(t,f).catch(Ie=>j.warn("connect-noop auto-revive error (ignored)",{err:String(Ie)}))):j.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let ht=!!h&&h!==ee,Qt=g!==void 0&&g!==St,Ft=ht||Qt,en=await Uc({privatecode:ee,...xe?{endpoint:xe}:{},ppeOverride:Qe});if(Ft){j.warn("connect config switched, resetting agents",{pcChanged:ht,envChanged:Qt,previousPc:h?ea(h):"",nextPc:ea(ee)});for(let we of[...u.agents.values()])await we.dispose("connect config switch").catch(()=>{}),u.agents.delete(we.agentId);u.disconnectedAgents.size>0&&(j.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new jr,"connect switch").catch(()=>{})}w=en.deviceId,us({deviceId:w,pid:process.pid}),ld({patToken:ee,env:W.env}).catch(we=>j.warn("coze-cli setup error (ignored)",{err:String(we)}));let Yr=new es({handshake:en,privatecode:ee,...he?{urlOverride:he}:{},ppeOverride:Qe,getPatTokenForAgent:we=>u.agents.get(we)?.patToken});return await c.swap(Yr,"connect"),h=ee,g=St,S=Qe,_=xe,W.mock_scenario!==void 0&&(u.setMockScenario(W.mock_scenario),j.info("mock scenario set",{scenario:W.mock_scenario})),v||(v=new Ni({core:u,getDeviceId:()=>w??"",onTickEnd:()=>M.retryPending().catch(we=>j.warn("detailSync.retryPending failed (ignored)",{err:String(we)})),onAuthFailures:Y})),v.start(),y(),Ft&&ta(t,f).catch(we=>j.warn("post-connect-switch auto-revive error (ignored)",{err:String(we)})),ts(ee,t).catch(we=>j.warn("writePatToken after /connect failed (ignored)",{err:String(we)})),j.info("/connect: WS established",{deviceId:w}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async D=>f.createAgent(D.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let L={},F=new lo({agents:u.agents,publishSkillToMarketplace:async D=>{let G=u.agents.get(D.agentId)?.patToken??h;if(!G)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");return zh({patToken:G,zip:D.zip,...D.skillId?{skillId:D.skillId}:{},skillName:D.skillName,...D.description?{description:D.description}:{},agentId:D.agentId,...D.accountId?{accountId:D.accountId}:{}},{handshakeBase:_,ppeOverride:S})},disposeAndMarkDisconnected:async(D,G)=>{let W=u.agents.get(D);if(W){await f.cleanupOpenclawSessionProviders(W).catch(Qe=>j.warn("cleanup openclaw providers failed (ignored)",{agentId:D,err:String(Qe)}));let ee=!0;try{await W.dispose(`disconnect: ${G}`)}catch(Qe){ee=!1,j.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:D,err:String(Qe)}),W.status="error"}ee&&(W.status="disconnected",u.unregister(D),u.disconnectedAgents.add(D))}else u.disconnectedAgents.add(D)},disposeForDelete:async(D,G)=>{let W=u.agents.get(D);W&&(await f.cleanupOpenclawSessionProviders(W).catch(ee=>j.warn("cleanup openclaw providers during delete failed (ignored)",{agentId:D,err:String(ee)})),await W.dispose(`delete: ${G}`).catch(ee=>j.warn("dispose during delete failed (ignored)",{agentId:D,err:String(ee)})),u.unregister(D)),u.disconnectedAgents.delete(D)},detailSyncer:async D=>{if(!L.ref)throw new Error("agent-detail-sync not initialized yet");await L.ref.syncOne(D)},cleanupOpenclawProviders:async D=>{await f.cleanupOpenclawSessionProviders(D)},openclawRepair:async(D,G)=>{await f.openclawRepair(D,G)},isRuntimePendingPermission:D=>u.hasPendingPermissionFor(D)});u.registerExtension("_agent/listSkills",D=>F.listSkills(D.params)),u.registerExtension("_agent/addSkills",D=>F.addSkills(D.params)),u.registerExtension("_agent/removeSkills",D=>F.removeSkills(D.params)),u.registerExtension("_agent/publishSkill",D=>F.publishSkill(D.params)),u.registerExtension("_agent/getFileTree",D=>F.getFileTree(D.params)),u.registerExtension("_agent/getFileContent",D=>F.getFileContent(D.params)),u.registerExtension("_agent/update",D=>F.updateAgent(D.params)),u.registerExtension("_agent/disconnect",D=>F.disconnectAgent(D.params)),u.registerExtension("_agent/switchModel",D=>F.switchModel(D.params)),u.registerExtension("_agent/reset",D=>F.resetAgent(D.params)),u.registerExtension("_agent/repair",D=>F.repairAgent(D.params)),u.registerExtension("_agent/delete",D=>F.deleteAgent(D.params)),u.registerExtension("_agent/upgrade",D=>F.upgradeBridge(D.params));let M=new gs({paths:t,handlers:F,agentManager:f,sendDetail:D=>u.sendRequest("_agent/detail",D)});L.ref=M;let Y=async D=>{await Promise.allSettled(D.map(async G=>{try{await F.disconnectAgent({agentId:G.agentId,reason:`auth_failure: code=${G.code} ${G.message}`}),j.info("agent disconnected due to auth failure from heartbeat response",{agentId:G.agentId,code:G.code,message:G.message})}catch(W){j.warn("disconnect during authFailure handling failed (ignored)",{agentId:G.agentId,err:String(W)})}}))};c.onConnect(({initial:D})=>{j.info("frontier upstream connected, triggering detail sync",{initial:D}),M.syncAll(D?"initial-connect":"reconnect").catch(G=>j.warn("detail sync top-level error (ignored)",{err:String(G)}))});let $=new Ao({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let D=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[ns]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:w??"",frameworksCache:o.frameworksCache??{},...D?{mockScenario:D}:{}}}},{method:"POST",path:"/pair",handler:async D=>{let G=D,W=G?.privatecode,ee=G?.pairing_code;if(!W||!ee)throw new T("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Qe=Oi(G.env),xe=G.handshake_url,he=G.frontier_url,St=Kh(G.env,xe,he),ht=!!h&&h!==W,Qt=g!==void 0&&g!==St,Ft=ht||Qt,en=await Uc({privatecode:W,...xe?{endpoint:xe}:{},ppeOverride:Qe});if(Ft){j.warn("pair config switched, resetting agents",{pcChanged:ht,envChanged:Qt,previousPc:h?ea(h):"",nextPc:ea(W),previousEnvKey:g??"",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&&(j.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new jr,"pair switch").catch(()=>{})}w=en.deviceId,us({deviceId:w,pid:process.pid}),ld({patToken:W,env:G.env}).catch(Ie=>j.warn("coze-cli setup error (ignored)",{err:String(Ie)}));let Yr=new es({handshake:en,privatecode:W,...he?{urlOverride:he}:{},ppeOverride:Qe,getPatTokenForAgent:Ie=>u.agents.get(Ie)?.patToken});await c.swap(Yr,"pair");try{let Ie=new Kn;o.frameworksCache=await Ie.detectAll(),await qi(o),j.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ie){j.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ie)})}let we=Object.keys(o.frameworksCache??{});try{let Ie=await u.sendRequest("_agent/pair",{pairCode:ee,patToken:W,frameworks:we,_meta:{cozeDeviceId:w}});j.info("_agent/pair ok",{pairResult:Ie}),h=W,g=St,S=Qe,_=xe,G.mock_scenario!==void 0&&(u.setMockScenario(G.mock_scenario),j.info("mock scenario set",{scenario:G.mock_scenario})),ts(W,t).catch(Pe=>j.warn("writePatToken after /pair failed (ignored)",{err:String(Pe)})),v||(v=new Ni({core:u,getDeviceId:()=>w??"",onTickEnd:()=>M.retryPending().catch(Pe=>j.warn("detailSync.retryPending failed (ignored)",{err:String(Pe)})),onAuthFailures:Y})),v.start(),y(),Ft&&ta(t,f).catch(Pe=>j.warn("post-pair-switch auto-revive error (ignored)",{err:String(Pe)}));let Qn;return G.agent_id&&(Qn=await NS(G.agent_id,t,f,Pe=>u.sendRequest("_agent/detail",Pe),W).catch(Pe=>(j.error("--agent-id ensureAgent failed",{agentId:G.agent_id,err:String(Pe)}),{ok:!1,agentId:G.agent_id??"",note:String(Pe)}))),{ok:!0,note:"paired with cloud",...Qn?{agent:Qn}:{}}}catch(Ie){return j.error("_agent/pair failed",{err:String(Ie)}),{ok:!1,note:`pair failed: ${String(Ie)}`}}}},{method:"POST",path:"/connect",handler:D=>O(D)},{method:"POST",path:"/_agent/create",handler:async D=>{let G=D;return{ok:!0,result:await f.createAgent(G)}}},{method:"POST",path:"/agent/send",handler:async D=>{let G=D;if(!G?.agentId||!G?.sessionId||!G?.kind||!G?.path)throw new T("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!h)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let W=G;return await(W.groupFile?ex:Q0)(W,{core:u,patToken:h,handshakeBase:_,ppeOverride:S})}catch(W){if(W instanceof T)return{ok:!1,code:W.code,message:W.message};throw W}}},{method:"POST",path:"/reload",handler:async D=>{let G=D?.agent_id,W=await u.reloadAgents(G);return j.info("IPC /reload: recycled agent subprocesses",{agentId:G??"(all)",recycled:W}),{ok:!0,recycled:W}}},{method:"POST",path:"/shutdown",handler:async()=>(j.info("IPC /shutdown received"),setImmediate(()=>{se.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:ne,token:J}=await $.start();try{await Gh(t.libEntry,t)}catch(D){j.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(D)})}await u.start(),MS({paths:t,core:u,agentManager:f,detectAll:async()=>(o.frameworksCache=await new Kn().detectAll(),await qi(o),o.frameworksCache)}).catch(D=>j.warn("startup warmup error (ignored)",{err:String(D)})),Rl().then(async()=>{let{probeAcpVersion:D}=await Promise.resolve().then(()=>(rn(),kl));for(let G of["claude-code","codex"]){let W=await D(G);W&&j.info("acp wrapper version",{framework:G,version:W})}}).catch(D=>j.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(D)}));let ie=null,se={port:ne,token:J,core:u,ipc:$,shutdown(D){return ie||(j.info("daemon shutdown",{reason:D}),ie=(async()=>{v?.stop(),I?.stop(),await u.stop(D),await $.stop(),await e.release()})(),ie)}};for(let D of["SIGTERM","SIGINT"])process.on(D,()=>{se.shutdown(D).then(()=>process.exit(0))});return process.on("exit",()=>m0()),process.on("unhandledRejection",D=>{j.error("unhandledRejection",{reason:D instanceof Error?D.message:String(D),stack:D instanceof Error?D.stack:void 0})}),process.on("uncaughtException",D=>{j.error("uncaughtException (will exit, supervisor will restart)",{message:D.message,stack:D.stack,name:D.name});try{process.stderr.write(`FATAL uncaughtException: ${D.stack??D.message}
112
+ `)}catch{}process.exit(1)}),j.info("daemon ready",{port:ne,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),FS({cliSpawned:process.env[ns]==="1",readPatToken:()=>Yo(t),connect:O}).catch(D=>j.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(D)})),se}async function OS(t){return xs(t).length>0}function ea(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function Kh(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function LS(t,e){let r=xs(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(an(),ps));for(let c of r){await o(c,t).catch(d=>j.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(d)}));try{let d=await i(c,t);d?.deletedAt?(e.disconnectedAgents.add(c),j.info("agent marked deleted on startup",{agentId:c,deletedAt:d.deletedAt,reason:d.deleteReason??""})):d?.disconnectedAt&&(e.disconnectedAgents.add(c),j.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:d.disconnectedAt,reason:d.disconnectReason??""}))}catch(d){j.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(d)})}}}async function NS(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(an(),ps)),d=await c(t,e);if(d){if(d.deletedAt)throw new T("AGENT_NOT_FOUND",`agent ${t} \u5DF2\u88AB\u5220\u9664 (deletedAt=${d.deletedAt}), \u4E0D\u80FD\u901A\u8FC7 --agent-id \u590D\u6D3B`);j.info("--agent-id: local config found, reconnecting",{agentId:t,framework:d.framework,hadDisconnect:!!d.disconnectedAt});let g=Vh(d),w={agentId:d.agentId,framework:d.framework,...d.cozeIdentity?{cozeIdentity:d.cozeIdentity}:{},...d.model?{model:d.model}:{},...o?{patToken:o}:{},...g?{_meta:g}:{}};return await r.createAgent(w),{ok:!0,agentId:t,note:d.disconnectedAt?"revived from local config":"connected from local config"}}j.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let u=await i({_meta:{cozeAgentId:t}});if(!u.framework)throw new 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 f={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...u.deployType?{_meta:{cozeDeployType:u.deployType}}:{}};await r.createAgent(f);let h=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:h?"cloud agent acknowledged":"created from cloud detail"}}async function MS(t){let e=t.logger??j;try{let r=await t.detectAll();e.info("refreshed frameworks_cache",{detected:Object.keys(r??{})})}catch(r){e.warn("framework detection failed (using cached)",{err:String(r)})}await LS(t.paths,t.core).catch(r=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(r)})),await ta(t.paths,t.agentManager).catch(r=>e.warn("auto-revive top-level error (ignored)",{err:String(r)})),await BS(t.paths).catch(r=>e.warn("builtin skill refresh top-level error (ignored)",{err:String(r)}))}async function ta(t,e){let{readdir:r}=await import("node:fs/promises"),i;try{i=await r(t.agentsRoot)}catch{return{revived:0,skipped:0,total:0}}if(i.length===0)return{revived:0,skipped:0,total:0};let{loadAgentConfig:o}=await Promise.resolve().then(()=>(an(),ps));j.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,d=0;for(let u of i){let f;try{f=await o(u,t)}catch(h){j.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(h)}),d+=1;continue}if(!f){d+=1;continue}if(f.deletedAt){j.info("auto-revive: skip deleted agent",{agentId:u,deletedAt:f.deletedAt}),d+=1;continue}if(f.disconnectedAt){j.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:f.disconnectedAt}),d+=1;continue}try{j.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:f.framework});let h=Vh(f);await e.createAgent({agentId:f.agentId,framework:f.framework,...f.cozeIdentity?{cozeIdentity:f.cozeIdentity}:{},...f.model?{model:f.model}:{},...h?{_meta:h}:{}},{revive:!0}),c+=1}catch(h){j.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:f.framework,err:String(h)}),d+=1}}return j.info("auto-revive: done",{revived:c,skipped:d,total:i.length}),{revived:c,skipped:d,total:i.length}}async function BS(t){let{readdir:e}=await import("node:fs/promises"),r;try{r=await e(t.agentsRoot)}catch{return{refreshed:0,total:0}}if(r.length===0)return{refreshed:0,total:0};let i=0;for(let o of r)try{(await i0(o,t)).status==="refreshed"&&(i+=1)}catch(c){j.warn("refresh builtin skills failed (skipping agent)",{agentId:o,err:String(c)})}return i>0&&j.info("builtin skills refresh on startup done",{refreshed:i,total:r.length}),{refreshed:i,total:r.length}}async function FS(t){let e=t.logger??j;if(t.cliSpawned)return"skipped-cli";let r=await t.readPatToken();return r?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:r}).catch(i=>e.warn("startup auto-connect failed (staying idle)",{err:String(i)})),"connecting"):(e.info("no stored PAT, skip startup auto-connect"),"skipped-no-pat")}function Vh(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}Xo();Oe();import{readFile as Yh}from"node:fs/promises";var Xt=class{paths;constructor(e){this.paths=e??Q()}async probe(e=1e3){let r=await na(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:US(i)}}}async request(e){let r=await na(this.paths);if(!r)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(r,e)}async fetch(e,r){let i=r.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,d=setTimeout(()=>c.abort(),r.timeoutMs??5e3);try{let u=await fetch(`http://127.0.0.1:${e.port}${r.path}`,{method:r.method,headers:o,body:i?JSON.stringify(r.body):void 0,signal:c.signal}),f=await u.text();return{status:u.status,body:zS(f)}}finally{clearTimeout(d)}}};async function na(t){try{let[e,r]=await Promise.all([Yh(t.portFile,"utf8"),Yh(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 zS(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function US(t){return t instanceof Error?t.message:String(t)}Kt();te();rr();import{spawn as GS}from"node:child_process";import{userInfo as Jh}from"node:os";var Gd="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",HS=new Set(["bash","zsh","sh","dash","ksh"]),Zh=Ve("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),qS=2e3;function jS(t,e=Gd){let r=t.indexOf(e);if(r===-1)return null;let i=t.indexOf(e,r+e.length);if(i===-1)return null;let o=t.slice(r+e.length,i),c={};for(let d of o.split(`
113
+ `)){let u=d.indexOf("=");u<=0||(c[d.slice(0,u)]=d.slice(u+1))}return c}function WS(){let t=(process.env.SHELL??"").trim()||(Jh().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return HS.has(e)?t:null}function KS(t){return new Promise(e=>{let r=`printf '%s' '${Gd}'; env; printf '%s' '${Gd}'`,i;try{i=GS(t,["-ilc",r],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??Jh().homedir}})}catch{e(null);return}let o="",c=!1,d=g=>{try{i.pid&&process.kill(-i.pid,g)}catch{}},u=g=>{c||(c=!0,clearTimeout(f),clearTimeout(h),e(g))};i.stdout?.on("data",g=>{o+=g.toString("utf8")}),i.on("error",()=>u(null)),i.on("close",()=>u(o.length>0?o:null));let f=setTimeout(()=>d("SIGTERM"),Zh),h=setTimeout(()=>{d("SIGKILL"),u(o.length>0?o:null)},Zh+qS)})}async function Hd(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let r=WS();if(!r)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??KS)(r);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=jS(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}Oe();function Tn(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],d=!1;for(let u of e){if(c===u){i=t[o+1],o+=1,d=!0;break}if(c.startsWith(`${u}=`)){i=c.slice(u.length+1),d=!0;break}}d||r.push(c)}return{value:i,rest:r}}rn();import{chmod as $S,copyFile as Xh,mkdir as ep,readFile as ra,rename as Qh,rm as qd,stat as tp,writeFile as VS}from"node:fs/promises";import{homedir as iP}from"node:os";import{dirname as YS,join as Wr,resolve as jd,sep as rs}from"node:path";import{fileURLToPath as ZS}from"node:url";Kt();te();Oe();var Wd=q("dist-install");function JS(t){let e=ZS(t),r=YS(e),i=`${rs}src${rs}`;if(r.includes(i)||r.endsWith(`${rs}src${rs}cli`))return null;let o=jd(r,"index.js"),c=jd(r,"..","package.json");return{dist:o,pkgJson:c}}async function $d(t={}){let e=t.paths??Q(),r=JS(import.meta.url),i=t.sourceDist??r?.dist,o=t.sourcePackageJson??r?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,d;try{let S=JSON.parse(await ra(o,"utf8"));c=S.version??"unknown",d=S.dependencies??{}}catch(S){return Wd.warn("cannot read source package.json,skip dist install",{err:String(S)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(S)}`}}let u=ei.map(S=>`${S}@${d[S]??"latest"}`),f=await So(e.configFile)??{},h=f.libVersion,g=await ra(e.libEntry).then(()=>!0).catch(()=>!1),w=h===c;if(w&&g&&await Kd(e))return{kind:"already-current",libVersion:c};if(!w||!g){await ep(e.libDir,{recursive:!0}),await Xh(i,e.libEntry),await Xh(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let S=jd(e.libDir,"package.json"),_=`${JSON.stringify({type:"module"},null,2)}
114
+ `;await ra(S,"utf8").catch(()=>null)!==_&&await VS(S,_)}return(!w||!await Kd(e))&&await(t.installWrappers??XS)(e,u),f.libVersion=c,await qi(f,e.configFile),Wd.info("dist installed",{libEntry:e.libEntry,fromVersion:h,toVersion:c}),w&&g?{kind:"already-current",libVersion:c}:h?{kind:"version-changed",fromVersion:h,toVersion:c,libEntry:e.libEntry}:{kind:"first-install",libVersion:c,libEntry:e.libEntry}}async function Kd(t){for(let e of ei){let r=Wr(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await tp(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function XS(t,e){await t1(t.installLock,async()=>{if(await Kd(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${rs}.staging-${process.pid}-${r}`,o=Wr(i,"node_modules"),c=Wr(t.libDir,"node_modules");try{await ep(i,{recursive:!0}),await QS(e,i),await e1(o);let d=`${c}.trash-${r}`;await Qh(c,d).catch(()=>{}),await Qh(o,c),await qd(d,{recursive:!0,force:!0}).catch(()=>{}),Wd.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await qd(i,{recursive:!0,force:!0}).catch(()=>{})}})}function QS(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=rt("npm",r,{stdio:["ignore","pipe","pipe"]}),d="";c.stderr?.on("data",f=>{d.length<8192&&(d+=f.toString("utf8"))});let u=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",f=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(f)}`))}),c.once("close",f=>{clearTimeout(u),f===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${f}: ${d.trim().slice(0,2e3)}`))})})}async function e1(t){for(let e of ei){let r=Wr(t,...e.split("/")),i=JSON.parse(await ra(Wr(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=Wr(t,".bin",o),d=await tp(c);process.platform!=="win32"&&!(d.mode&73)&&await $S(c,d.mode|73).catch(()=>{})}}async function t1(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 qd(t,{force:!0}).catch(()=>{})}}Ia();te();Oe();import{closeSync as rp,fstatSync as ip,openSync as sp,readFileSync as n1,readSync as r1,readdirSync as i1,statSync as s1}from"node:fs";import{join as ia}from"node:path";var o1=new Set(["debug","info","warn","error"]);function op(t){let e=t,r=Tn(e,"--agent-id");e=r.rest;let i=Tn(e,"--date");e=i.rest;let o=Tn(e,"-n","--lines");e=o.rest;let c=Tn(e,"--level");e=c.rest;let d=Tn(e,"--grep");e=d.rest;let u=o.value===void 0?200:Number(o.value),f=Number.isInteger(u)&&u>=0?u:200,h=c.value&&o1.has(c.value)?c.value:void 0,g={lines:f,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(g.agentId=r.value),i.value&&(g.date=i.value),h&&(g.level=h),d.value&&(g.grep=d.value),g}function a1(t,e){return t.agentId?ia(Ye(t.agentId,e).logs,ir("agent",t.date)):ia(e.bridgeLogsDir,ir("bridge",t.date))}function c1(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function d1(t,e){let r;try{r=i1(t)}catch{return[]}let i=[];for(let o of r){let c=Sa(o,e);if(!c)continue;let d=0;try{d=s1(ia(t,o)).size}catch{}i.push({file:ia(t,o),date:c,size:d})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function ap(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"&&!bl(r,e.level))return!1}return!0}var np={debug:"90",info:"36",warn:"33",error:"31"},l1=new Set(["ts","level","module","msg"]);function u1(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function cp(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=u1(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&np[o]&&(c=`\x1B[${np[o]}m${c}\x1B[0m`);let d=typeof r.module=="string"?r.module:"",u=typeof r.msg=="string"?r.msg:"",f=Object.entries(r).filter(([h])=>!l1.has(h)).map(([h,g])=>` ${h}=${typeof g=="string"?g:JSON.stringify(g)}`).join("");return`${i} ${c} ${d} ${u}${f}`}function f1(t,e,r){let c=n1(t,"utf8").split(`
115
+ `).filter(d=>d.length>0).filter(d=>ap(d,{level:e.level,grep:e.grep}));for(let d of c1(c,e.lines))process.stdout.write(`${cp(d,{raw:e.raw,color:r})}
116
+ `)}async function dp(t,e){let r=e.paths??Q(),i=process.stdout.isTTY===!0;if(t.list){let d=t.agentId?Ye(t.agentId,r).logs:r.bridgeLogsDir,u=t.agentId?"agent":"bridge",f=d1(d,u);if(f.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${d}
117
+ `),1;for(let h of f)process.stdout.write(`${h.date} ${(h.size/1024).toFixed(1)}KB ${h.file}
118
+ `);return 0}let o=t.date??Cn(new Date),c=a1({agentId:t.agentId,date:o},r);try{f1(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
117
119
  \u7528 'coze-bridge log${t.agentId?` --agent-id ${t.agentId}`:""} --list' \u770B\u6709\u54EA\u4E9B\u65E5\u671F\u3002
118
120
  (legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${r.logFile})
119
- `),1}return t.follow&&await n2(c,t,i),0}var e2=500;function t2(t){try{let e=Zh(t,"r");try{return Vh(e).size}finally{$h(e)}}catch{return 0}}async function n2(t,e,r){let i=t2(t),o="",c=!1,l=()=>{c=!0};process.on("SIGINT",l);try{for(;!c;){let u="";try{let x=Zh(t,"r");try{let h=Vh(x).size;if(h>i){let m=Buffer.allocUnsafe(h-i),E=jS(x,m,0,m.length,i);u=m.subarray(0,E).toString("utf8"),i+=E}}finally{$h(x)}}catch{}if(u){let x=(o+u).split(`
120
- `);o=x.pop()??"";for(let h of x)h.length>0&&Xh(h,{level:e.level,grep:e.grep})&&process.stdout.write(`${Yh(h,{raw:e.raw,color:r})}
121
- `)}await new Promise(x=>setTimeout(x,e2))}}finally{process.off("SIGINT",l)}}import{basename as r2,resolve as i2}from"node:path";Le();var s2=9e4,o2={PATH_OUTSIDE_WORKSPACE:3,FILE_TOO_LARGE:3,UNSUPPORTED_MIME:3,MODEL_MODALITY_UNSUPPORTED:3,IPC_BAD_REQUEST:3,AGENT_NOT_FOUND:4,IPC_AUTH_FAILED:4,AGENT_DISCONNECTED:5,UPLOAD_FAILED:5,UPSTREAM_NOT_READY:5,UPSTREAM_DISCONNECTED:5,UPSTREAM_HANDSHAKE_FAILED:5,AGENT_BUSY:1,AGENT_SPAWN_FAILED:1,AGENT_TIMEOUT:1,AGENT_FRAME_IDLE_TIMEOUT:1,AGENT_PROTOCOL_ERROR:1,AGENT_TURN_ABORTED:1,BRIDGE_CONFIG_INVALID:1,BRIDGE_INTERNAL:1,MODEL_TOKEN_GEN_FAILED:1,OPERATION_NOT_ALLOWED_FOR_LOCAL:1,OPERATION_NOT_ALLOWED_FOR_CLOUD:1,METHOD_NOT_FOUND:1,AGENT_DEPENDENCY_INSTALL_FAILED:1,AGENT_APPROVAL_TIMEOUT:1,AGENT_ENV_NOT_READY:1};function a2(t){return o2[t]??1}async function ep(t,e={}){let r=e.paths??Q();if(!t.agentId||!t.sessionId)return process.stderr.write(`Error: missing --agent-id and/or --session-id. These IDs come from the <coze-context> block injected at the top of each prompt \u2014 extract agentId and sessionId from there and pass them as flags. Example: coze-bridge send image x.png --agent-id <id> --session-id <id>
121
+ `),1}return t.follow&&await p1(c,t,i),0}var x1=500;function h1(t){try{let e=sp(t,"r");try{return ip(e).size}finally{rp(e)}}catch{return 0}}async function p1(t,e,r){let i=h1(t),o="",c=!1,d=()=>{c=!0};process.on("SIGINT",d);try{for(;!c;){let u="";try{let f=sp(t,"r");try{let h=ip(f).size;if(h>i){let g=Buffer.allocUnsafe(h-i),w=r1(f,g,0,g.length,i);u=g.subarray(0,w).toString("utf8"),i+=w}}finally{rp(f)}}catch{}if(u){let f=(o+u).split(`
122
+ `);o=f.pop()??"";for(let h of f)h.length>0&&ap(h,{level:e.level,grep:e.grep})&&process.stdout.write(`${cp(h,{raw:e.raw,color:r})}
123
+ `)}await new Promise(f=>setTimeout(f,x1))}}finally{process.off("SIGINT",d)}}import{basename as g1,resolve as m1}from"node:path";Oe();var w1=9e4,_1={PATH_OUTSIDE_WORKSPACE:3,FILE_TOO_LARGE:3,UNSUPPORTED_MIME:3,MODEL_MODALITY_UNSUPPORTED:3,IPC_BAD_REQUEST:3,AGENT_NOT_FOUND:4,IPC_AUTH_FAILED:4,AGENT_DISCONNECTED:5,UPLOAD_FAILED:5,UPSTREAM_NOT_READY:5,UPSTREAM_DISCONNECTED:5,UPSTREAM_HANDSHAKE_FAILED:5,AGENT_BUSY:1,AGENT_SPAWN_FAILED:1,AGENT_TIMEOUT:1,AGENT_FRAME_IDLE_TIMEOUT:1,AGENT_PROTOCOL_ERROR:1,AGENT_TURN_ABORTED:1,BRIDGE_CONFIG_INVALID:1,BRIDGE_INTERNAL:1,MODEL_TOKEN_GEN_FAILED:1,OPERATION_NOT_ALLOWED_FOR_LOCAL:1,OPERATION_NOT_ALLOWED_FOR_CLOUD:1,METHOD_NOT_FOUND:1,AGENT_DEPENDENCY_INSTALL_FAILED:1,AGENT_APPROVAL_TIMEOUT:1,AGENT_ENV_NOT_READY:1,SKILL_NOT_FOUND:1,SKILL_ZIP_TOO_LARGE:1};function y1(t){return _1[t]??1}async function lp(t,e={}){let r=e.paths??Q();if(!t.agentId||!t.sessionId)return process.stderr.write(`Error: missing --agent-id and/or --session-id. These IDs come from the <coze-context> block injected at the top of each prompt \u2014 extract agentId and sessionId from there and pass them as flags. Example: coze-bridge send image x.png --agent-id <id> --session-id <id>
122
124
  `),4;if(t.groupFile&&!t.mimeType)return process.stderr.write(`Error: --group-file requires --mime <mimeType> (e.g. application/pdf, image/png). No local file is read in group-file mode, mime cannot be auto-detected.
123
- `),3;let i=await sa(r).catch(()=>null);if(!i)return process.stderr.write(`Error: coze-bridge daemon not running (cannot read ${r.portFile} / ${r.tokenFile}). Make sure you are inside an agent session spawned by the daemon.
124
- `),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:i2(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 c2(i,"/agent/send",o,s2)}catch(l){return process.stderr.write(`Error: daemon IPC failed: ${l instanceof Error?l.message:String(l)}
125
+ `),3;let i=await na(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.
126
+ `),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:m1(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 E1(i,"/agent/send",o,w1)}catch(d){return process.stderr.write(`Error: daemon IPC failed: ${d instanceof Error?d.message:String(d)}
125
127
  `),4}if(!c.ok)return process.stderr.write(`Error: ${c.code}: ${c.message}
126
- `),a2(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
127
- `);else{let l=t.name??r2(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})
128
- `)}else process.stdout.write(`Sent ${t.kind} ${l} (${d2(c.bytes)})
129
- `)}return 0}async function c2(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 d2(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var dp=H("cli");function We(t,e){let{value:r,rest:i}=kn(t,e);return{value:r,rest:i}}function xa(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
130
- `)}function O2(t){let e=t.slice(2);if(e.includes("--version")||e.includes("-v"))return{mode:"version"};if(e.includes("--daemon"))return{mode:"daemon"};if(e[0]==="status")return{mode:"status"};if(e[0]==="stop")return{mode:"stop"};if(e[0]==="reload"){let{value:O}=We(e.slice(1),"--agent-id");return O?{mode:"reload",agentId:O}:{mode:"reload"}}if(e[0]==="update")return{mode:"update"};if(e[0]==="purge")return{mode:"purge"};if(e[0]==="service")return e[1]==="install"?{mode:"service-install"}:e[1]==="uninstall"?{mode:"service-uninstall"}:{mode:"help"};if(e[0]==="send")return L2(e.slice(1));if(e[0]==="log")return{mode:"log",...Jh(e.slice(1))};if(e[0]==="connect")return N2(e.slice(1));if(e.includes("--status"))return xa("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return xa("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return xa("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return xa("--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}=We(r,"--pat-token");r=o;let{value:c,rest:l}=We(r,"--pair-code");r=l;let{value:u,rest:x}=We(r,"--env");r=x;let{value:h,rest:m}=We(r,"--handshake-url");r=m;let{value:E,rest:S}=We(r,"--frontier-url");r=S;let{value:_,rest:v}=We(r,"--mock-scenario");r=v;let{value:A}=We(r,"--agent-id"),I=r.includes("--skip-rebuild-env");if(!i||!c)return{mode:"help"};let D={mode:"pair",privatecode:i,pairingCode:c};return u&&(D.env=u),h&&(D.handshakeUrl=h),E&&(D.frontierUrl=E),_&&(D.mockScenario=_),A&&(D.agentId=A),I&&(D.skipRebuildEnv=!0),D}function L2(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}=We(i,"--caption");i=c;let{value:l,rest:u}=We(i,"--name");i=u;let{value:x,rest:h}=We(i,"--agent-id");i=h;let{value:m,rest:E}=We(i,"--session-id");i=E;let{value:S,rest:_}=We(i,"--mime");i=_;let v=i.includes("--group-file");i=i.filter(D=>D!=="--group-file");let A=i.includes("--json"),I={mode:"send",kind:e,path:r,json:A};return o&&(I.caption=o),l&&(I.name=l),x&&(I.agentId=x),m&&(I.sessionId=m),v&&(I.groupFile=!0),S&&(I.mimeType=S),I}function N2(t){let e=t,{value:r,rest:i}=We(e,"--pat-token");e=i;let{value:o,rest:c}=We(e,"--env");e=c;let{value:l,rest:u}=We(e,"--handshake-url");e=u;let{value:x,rest:h}=We(e,"--frontier-url");e=h;let{value:m,rest:E}=We(e,"--mock-scenario");e=E;let S=e.includes("--skip-rebuild-env"),_={mode:"connect"};return r&&(_.privatecode=r),o&&(_.env=o),l&&(_.handshakeUrl=l),x&&(_.frontierUrl=x),m&&(_.mockScenario=m),S&&(_.skipRebuildEnv=!0),_}var M2=`
128
+ `),y1(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
129
+ `);else{let d=t.name??g1(o.path);if(t.groupFile){let u=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${d} (uri=${u})
130
+ `)}else process.stdout.write(`Sent ${t.kind} ${d} (${b1(c.bytes)})
131
+ `)}return 0}async function E1(t,e,r,i){let o=new AbortController,c=setTimeout(()=>o.abort(),i);try{let d=await fetch(`http://127.0.0.1:${t.port}${e}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"content-type":"application/json"},body:JSON.stringify(r),signal:o.signal}),u=await d.text(),f=u?JSON.parse(u):null;return f&&typeof f=="object"&&"ok"in f?f:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${d.status}): ${u.slice(0,200)}`}}finally{clearTimeout(c)}}function b1(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var _p=q("cli");function je(t,e){let{value:r,rest:i}=Tn(t,e);return{value:r,rest:i}}function la(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
132
+ `)}function K1(t){let e=t.slice(2);if(e.includes("--version")||e.includes("-v"))return{mode:"version"};if(e.includes("--daemon"))return{mode:"daemon"};if(e[0]==="status")return{mode:"status"};if(e[0]==="stop")return{mode:"stop"};if(e[0]==="reload"){let{value:O}=je(e.slice(1),"--agent-id");return O?{mode:"reload",agentId:O}:{mode:"reload"}}if(e[0]==="update")return{mode:"update"};if(e[0]==="purge")return{mode:"purge"};if(e[0]==="service")return e[1]==="install"?{mode:"service-install"}:e[1]==="uninstall"?{mode:"service-uninstall"}:{mode:"help"};if(e[0]==="send")return $1(e.slice(1));if(e[0]==="log")return{mode:"log",...op(e.slice(1))};if(e[0]==="connect")return V1(e.slice(1));if(e.includes("--status"))return la("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return la("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return la("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return la("--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}=je(r,"--pat-token");r=o;let{value:c,rest:d}=je(r,"--pair-code");r=d;let{value:u,rest:f}=je(r,"--env");r=f;let{value:h,rest:g}=je(r,"--handshake-url");r=g;let{value:w,rest:S}=je(r,"--frontier-url");r=S;let{value:_,rest:v}=je(r,"--mock-scenario");r=v;let{value:I}=je(r,"--agent-id"),A=r.includes("--skip-rebuild-env");if(!i||!c)return{mode:"help"};let R={mode:"pair",privatecode:i,pairingCode:c};return u&&(R.env=u),h&&(R.handshakeUrl=h),w&&(R.frontierUrl=w),_&&(R.mockScenario=_),I&&(R.agentId=I),A&&(R.skipRebuildEnv=!0),R}function $1(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}=je(i,"--caption");i=c;let{value:d,rest:u}=je(i,"--name");i=u;let{value:f,rest:h}=je(i,"--agent-id");i=h;let{value:g,rest:w}=je(i,"--session-id");i=w;let{value:S,rest:_}=je(i,"--mime");i=_;let v=i.includes("--group-file");i=i.filter(R=>R!=="--group-file");let I=i.includes("--json"),A={mode:"send",kind:e,path:r,json:I};return o&&(A.caption=o),d&&(A.name=d),f&&(A.agentId=f),g&&(A.sessionId=g),v&&(A.groupFile=!0),S&&(A.mimeType=S),A}function V1(t){let e=t,{value:r,rest:i}=je(e,"--pat-token");e=i;let{value:o,rest:c}=je(e,"--env");e=c;let{value:d,rest:u}=je(e,"--handshake-url");e=u;let{value:f,rest:h}=je(e,"--frontier-url");e=h;let{value:g,rest:w}=je(e,"--mock-scenario");e=w;let S=e.includes("--skip-rebuild-env"),_={mode:"connect"};return r&&(_.privatecode=r),o&&(_.env=o),d&&(_.handshakeUrl=d),f&&(_.frontierUrl=f),g&&(_.mockScenario=g),S&&(_.skipRebuildEnv=!0),_}var Y1=`
131
133
  coze-bridge - local bridge daemon for cloud Agent Service
132
134
 
133
135
  Pair (paste from cloud UI; start/reuse daemon and deliver pair-code):
@@ -208,57 +210,57 @@ Deprecated flags (still work, but emit a warning; will be removed in a future re
208
210
 
209
211
  Internal:
210
212
  <node> <entry> --daemon daemon mode (OS supervisor only)
211
- `.trimStart();async function lp(t=process.argv,e={}){let r=O2(t);switch(r.mode){case"help":return process.stdout.write(M2),0;case"version":return process.stdout.write(`${Pr}
212
- `),0;case"daemon":{try{await Bh()}catch(i){return dp.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return B2(e);case"stop":return fp(e);case"reload":return U2(r.agentId,e);case"log":return Qh(r,e);case"update":return z2(e);case"purge":return q2(e);case"service-install":return G2(e);case"service-uninstall":return H2(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),j2(r.privatecode,r.pairingCode,e,i,r.agentId,r.skipRebuildEnv)}case"connect":{let i={};return r.env&&(i.env=r.env),r.handshakeUrl&&(i.handshakeUrl=r.handshakeUrl),r.frontierUrl&&(i.frontierUrl=r.frontierUrl),r.mockScenario&&(i.mockScenario=r.mockScenario),W2(r.privatecode,e,i,r.skipRebuildEnv)}case"send":return ep({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 up(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 B2(t){let e=t.paths??Q(),r=new en(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
213
- `),1;if(i.kind==="stale")return await up(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
213
+ `.trimStart();async function yp(t=process.argv,e={}){let r=K1(t);switch(r.mode){case"help":return process.stdout.write(Y1),0;case"version":return process.stdout.write(`${Pt}
214
+ `),0;case"daemon":{try{await $h()}catch(i){return _p.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return Z1(e);case"stop":return bp(e);case"reload":return Q1(r.agentId,e);case"log":return dp(r,e);case"update":return J1(e);case"purge":return e2(e);case"service-install":return t2(e);case"service-uninstall":return n2(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),r2(r.privatecode,r.pairingCode,e,i,r.agentId,r.skipRebuildEnv)}case"connect":{let i={};return r.env&&(i.env=r.env),r.handshakeUrl&&(i.handshakeUrl=r.handshakeUrl),r.frontierUrl&&(i.frontierUrl=r.frontierUrl),r.mockScenario&&(i.mockScenario=r.mockScenario),i2(r.privatecode,e,i,r.skipRebuildEnv)}case"send":return lp({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 Ep(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 Z1(t){let e=t.paths??Q(),r=new Xt(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
215
+ `),1;if(i.kind==="stale")return await Ep(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
214
216
  `),1;let o=await r.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
215
217
  ${JSON.stringify(o.body,null,2)}
216
- `),0}async function fp(t){let e=t.paths??Q(),r=new en(e),i=t.daemonSweep??(async()=>{let x=d0();return await l0(x),x}),o=async()=>{t.skipProcessKill||await i(e)},c=await ds(t),l=!1;if(c)try{await c.uninstall(),l=!0}catch(x){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(x)}
217
- `)}let u=await r.probe();if(u.kind==="not-running")return await o(),process.stdout.write(l?`coze-bridge: stopped
218
+ `),0}async function bp(t){let e=t.paths??Q(),r=new Xt(e),i=t.daemonSweep??(async()=>{let f=w0();return await _0(f),f}),o=async()=>{t.skipProcessKill||await i(e)},c=await ss(t),d=!1;if(c)try{await c.uninstall(),d=!0}catch(f){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(f)}
219
+ `)}let u=await r.probe();if(u.kind==="not-running")return await o(),process.stdout.write(d?`coze-bridge: stopped
218
220
  `:`coze-bridge: not running
219
- `),0;if(u.kind==="stale")return await up(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
221
+ `),0;if(u.kind==="stale")return await Ep(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
220
222
  `),0;try{return await r.request({method:"POST",path:"/shutdown"}),await o(),process.stdout.write(`coze-bridge: stopped
221
- `),0}catch(x){return(await r.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
222
- `),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(x)}
223
- `),1)}}async function z2(t){return await fp(t),(t.spawnNpx??F2)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function F2(t){return new Promise(e=>{let r=st("npx",t,{stdio:"inherit"});r.on("exit",i=>e(i??1)),r.on("error",i=>{process.stderr.write(`coze-bridge: spawn npx failed: ${String(i)}
224
- `),e(1)})})}async function U2(t,e){let r=new en(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
223
+ `),0}catch(f){return(await r.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
224
+ `),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(f)}
225
+ `),1)}}async function J1(t){return await bp(t),(t.spawnNpx??X1)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function X1(t){return new Promise(e=>{let r=rt("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)}
226
+ `),e(1)})})}async function Q1(t,e){let r=new Xt(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
225
227
  `),1;try{let o=await r.request({method:"POST",path:"/reload",body:t?{agent_id:t}:{},timeoutMs:35e3});if(o.status===200&&o.body?.ok){let c=o.body.recycled??[];return t&&c.length===0?process.stdout.write(`coze-bridge: agent ${t} \u65E0\u8FD0\u884C\u4E2D\u5B50\u8FDB\u7A0B\u53EF\u56DE\u6536 (\u672A\u6CE8\u518C / \u5DF2 idle)
226
228
  `):process.stdout.write(`coze-bridge: reloaded ${c.length} agent(s): ${c.join(", ")||"(none)"}
227
229
  `),0}return process.stderr.write(`coze-bridge: reload failed: ${JSON.stringify(o.body)}
228
230
  `),1}catch(o){return process.stderr.write(`coze-bridge: reload failed: ${String(o)}
229
- `),1}}async function ds(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(()=>(ap(),op)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function xp(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??Nh,o=t.waitTimeoutMs??15e3,c=t.sleep??$2,l=t.paths??Q(),u=await ds(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let x=await cp(e,o,c);if(x.kind==="connected")return x;Ct(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){Ct(l.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(x)})}Ct(l.bridgeLogsDir,"warn","cli","\u79FB\u9664\u5F00\u673A\u81EA\u542F\u914D\u7F6E (supervisor \u63A5\u7BA1\u672A\u6210\u529F, \u56DE\u9000\u624B\u52A8 spawn; \u4E0B\u6B21\u91CD\u542F\u4E0D\u518D\u81EA\u542F, \u9700\u91CD\u65B0 service install)",{platform:u.platform}),await u.uninstall().catch(()=>{}),await K2(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)}
231
+ `),1}}async function ss(t){if(t.supervisor){let c=t.supervisor,d={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:u=>c.install(d,u),uninstall:()=>c.uninstall(d)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>(mp(),gp)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function vp(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??Wh,o=t.waitTimeoutMs??15e3,c=t.sleep??o2,d=t.paths??Q(),u=await ss(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let f=await wp(e,o,c);if(f.kind==="connected")return f;It(d.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:o})}catch(f){It(d.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(f)})}It(d.bridgeLogsDir,"warn","cli","\u79FB\u9664\u5F00\u673A\u81EA\u542F\u914D\u7F6E (supervisor \u63A5\u7BA1\u672A\u6210\u529F, \u56DE\u9000\u624B\u52A8 spawn; \u4E0B\u6B21\u91CD\u542F\u4E0D\u518D\u81EA\u542F, \u9700\u91CD\u65B0 service install)",{platform:u.platform}),await u.uninstall().catch(()=>{}),await s2(d.pidFile,c)}else u&&await u.install({activate:!1}).catch(f=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(f)}
230
232
  `));return process.stdout.write(`coze-bridge: starting daemon...
231
- `),await i({paths:t.paths}),cp(e,o,c)}async function q2(t){let e=new en(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
232
- `);try{await e.request({method:"POST",path:"/shutdown"})}catch(l){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(l)}
233
- `)}await new Promise(l=>setTimeout(l,500))}let i=await ds(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
234
- `)}catch(l){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(l)}
233
+ `),await i({paths:t.paths}),wp(e,o,c)}async function e2(t){let e=new Xt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
234
+ `);try{await e.request({method:"POST",path:"/shutdown"})}catch(d){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(d)}
235
+ `)}await new Promise(d=>setTimeout(d,500))}let i=await ss(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
236
+ `)}catch(d){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(d)}
235
237
  `)}let o=t.paths??Q(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
236
- `)}catch(l){return process.stderr.write(`coze-bridge: remove failed: ${String(l)}
238
+ `)}catch(d){return process.stderr.write(`coze-bridge: remove failed: ${String(d)}
237
239
  `),1}return process.stdout.write(`coze-bridge: purged (agents workspaces preserved under ~/.coze/agents)
238
- `),0}async function G2(t){let e=await ds(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
240
+ `),0}async function t2(t){let e=await ss(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
239
241
  `),await e.install(),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
240
242
  `),0}catch(r){return process.stderr.write(`coze-bridge: service install failed: ${String(r)}
241
- `),1}}async function H2(t){let e=await ds(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
243
+ `),1}}async function n2(t){let e=await ss(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
242
244
  `),0}catch(r){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(r)}
243
- `),1}}async function hp(t,e,r){if(e)return Ct(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await r();return i.kind==="ok"?(Ct(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(Ct(t.bridgeLogsDir,"info","cli","agent-env: rebuild not applicable, use process.env",{reason:i.reason}),process.env):(process.stderr.write(`coze-bridge: \u91CD\u5EFA shell \u73AF\u5883\u5931\u8D25, \u56DE\u9000\u5F53\u524D\u8FDB\u7A0B\u73AF\u5883 (\u53EF\u7528 --skip-rebuild-env \u663E\u5F0F\u8DF3\u8FC7)
244
- `),Ct(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function j2(t,e,r,i={},o,c){let l=new en(r.paths),u=r.paths??Q(),x=await hp(u,c,r.reconstructEnv??Fd);if(await Qc(u,x).catch(E=>Ct(u.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(E)})),!r.skipDistInstall){let E=await jd({paths:r.paths});E.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${E.fromVersion} \u2192 ${E.toVersion}
245
- `),(await l.probe()).kind==="connected"&&(await l.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(_=>setTimeout(_,500)))):E.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${E.libVersion}
246
- `)}let h=await xp(r,l);if(h.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${h.kind}
247
- `),1;let m={privatecode:t,pairing_code:e};i.env&&(m.env=i.env),i.handshakeUrl&&(m.handshake_url=i.handshakeUrl),i.frontierUrl&&(m.frontier_url=i.frontierUrl),i.mockScenario&&(m.mock_scenario=i.mockScenario),o&&(m.agent_id=o);try{let E=await l.request({method:"POST",path:"/pair",body:m,timeoutMs:35e3});if(E.status===200&&E.body?.ok){let S=E.body.agent;return S&&!S.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${S.agentId}): ${S.note}
245
+ `),1}}async function Sp(t,e,r){if(e)return It(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await r();return i.kind==="ok"?(It(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(It(t.bridgeLogsDir,"info","cli","agent-env: rebuild not applicable, use process.env",{reason:i.reason}),process.env):(process.stderr.write(`coze-bridge: \u91CD\u5EFA shell \u73AF\u5883\u5931\u8D25, \u56DE\u9000\u5F53\u524D\u8FDB\u7A0B\u73AF\u5883 (\u53EF\u7528 --skip-rebuild-env \u663E\u5F0F\u8DF3\u8FC7)
246
+ `),It(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function r2(t,e,r,i={},o,c){let d=new Xt(r.paths),u=r.paths??Q(),f=await Sp(u,c,r.reconstructEnv??Hd);if(await ed(u,f).catch(w=>It(u.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(w)})),!r.skipDistInstall){let w=await $d({paths:r.paths});w.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${w.fromVersion} \u2192 ${w.toVersion}
247
+ `),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(_=>setTimeout(_,500)))):w.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${w.libVersion}
248
+ `)}let h=await vp(r,d);if(h.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${h.kind}
249
+ `),1;let g={privatecode:t,pairing_code:e};i.env&&(g.env=i.env),i.handshakeUrl&&(g.handshake_url=i.handshakeUrl),i.frontierUrl&&(g.frontier_url=i.frontierUrl),i.mockScenario&&(g.mock_scenario=i.mockScenario),o&&(g.agent_id=o);try{let w=await d.request({method:"POST",path:"/pair",body:g,timeoutMs:35e3});if(w.status===200&&w.body?.ok){let S=w.body.agent;return S&&!S.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${S.agentId}): ${S.note}
248
250
  `),1):(process.stdout.write(`\u5DF2\u914D\u5BF9\u8FDE\u63A5\u5B8C\u6210\uFF0C\u8BF7\u8FD4\u56DE\u5230 coze \u5E73\u53F0\u4E0A\u70B9\u51FB "\u6211\u5DF2\u6267\u884C"
249
- `),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(E.body)}
250
- `),1}catch(E){return process.stderr.write(`coze-bridge: pair failed: ${String(E)}
251
- `),1}}async function W2(t,e,r={},i){let o=e.paths??Q(),c=t??await Yo(o);if(!c)return process.stderr.write("coze-bridge: \u627E\u4E0D\u5230 patToken \u2014 \u5148\u8DD1\u4E00\u6B21 `coze-bridge --pat-token=<sat_xxx> --pair-code=<xxx>` \u914D\u5BF9, \u6216\u672C\u6B21\u7528 `--pat-token` \u6307\u5B9A\n"),1;let l=new en(e.paths),u=await hp(o,i,e.reconstructEnv??Fd);if(await Qc(o,u).catch(m=>Ct(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(m)})),!e.skipDistInstall){let m=await jd({paths:e.paths});m.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${m.fromVersion} \u2192 ${m.toVersion}
252
- `),(await l.probe()).kind==="connected"&&(await l.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(S=>setTimeout(S,500)))):m.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${m.libVersion}
253
- `)}let x=await xp(e,l);if(x.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${x.kind}
254
- `),1;let h={privatecode:c};r.env&&(h.env=r.env),r.handshakeUrl&&(h.handshake_url=r.handshakeUrl),r.frontierUrl&&(h.frontier_url=r.frontierUrl),r.mockScenario&&(h.mock_scenario=r.mockScenario);try{let m=await l.request({method:"POST",path:"/connect",body:h,timeoutMs:35e3});return m.status===200&&m.body?.ok?(process.stdout.write(`coze-bridge: connected (${m.body.note??"ok"})
255
- `),t!==void 0&&await ss(c,o).catch(E=>dp.warn("writePatToken after connect failed (ignored)",{err:String(E)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(m.body)}
256
- `),1)}catch(m){return process.stderr.write(`coze-bridge: connect failed: ${String(m)}
257
- `),1}}async function cp(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 K2(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||!Hi(u))return;await e(i)}}function $2(t){return new Promise(e=>setTimeout(e,t))}re();function V2(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 pp(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=V2(t);if(i==="ok")return;let o=t.replace(/^v/,"");i==="fatal"?(e(`[coze-bridge] \u5F53\u524D Node.js \u7248\u672C v${o} \u8FC7\u4F4E,\u65E0\u6CD5\u8FD0\u884C(\u6700\u4F4E v18.4.0,\u63A8\u8350 v20+)\u3002\u8BF7\u5347\u7EA7\u540E\u91CD\u8BD5:https://nodejs.org(\u6216\u7528 nvm/fnm)\u3002
251
+ `),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(w.body)}
252
+ `),1}catch(w){return process.stderr.write(`coze-bridge: pair failed: ${String(w)}
253
+ `),1}}async function i2(t,e,r={},i){let o=e.paths??Q(),c=t??await Yo(o);if(!c)return process.stderr.write("coze-bridge: \u627E\u4E0D\u5230 patToken \u2014 \u5148\u8DD1\u4E00\u6B21 `coze-bridge --pat-token=<sat_xxx> --pair-code=<xxx>` \u914D\u5BF9, \u6216\u672C\u6B21\u7528 `--pat-token` \u6307\u5B9A\n"),1;let d=new Xt(e.paths),u=await Sp(o,i,e.reconstructEnv??Hd);if(await ed(o,u).catch(g=>It(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(g)})),!e.skipDistInstall){let g=await $d({paths:e.paths});g.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${g.fromVersion} \u2192 ${g.toVersion}
254
+ `),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(S=>setTimeout(S,500)))):g.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${g.libVersion}
255
+ `)}let f=await vp(e,d);if(f.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${f.kind}
256
+ `),1;let h={privatecode:c};r.env&&(h.env=r.env),r.handshakeUrl&&(h.handshake_url=r.handshakeUrl),r.frontierUrl&&(h.frontier_url=r.frontierUrl),r.mockScenario&&(h.mock_scenario=r.mockScenario);try{let g=await d.request({method:"POST",path:"/connect",body:h,timeoutMs:35e3});return g.status===200&&g.body?.ok?(process.stdout.write(`coze-bridge: connected (${g.body.note??"ok"})
257
+ `),t!==void 0&&await ts(c,o).catch(w=>_p.warn("writePatToken after connect failed (ignored)",{err:String(w)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(g.body)}
258
+ `),1)}catch(g){return process.stderr.write(`coze-bridge: connect failed: ${String(g)}
259
+ `),1}}async function wp(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 s2(t,e,r=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let c=0;c<r;c++){let d;try{d=await o(t,"utf8")}catch{return}let u=Number.parseInt(d.trim(),10);if(!Number.isFinite(u)||u<=0||!zi(u))return;await e(i)}}function o2(t){return new Promise(e=>setTimeout(e,t))}te();function a2(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 Ip(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=a2(t);if(i==="ok")return;let o=t.replace(/^v/,"");i==="fatal"?(e(`[coze-bridge] \u5F53\u524D Node.js \u7248\u672C v${o} \u8FC7\u4F4E,\u65E0\u6CD5\u8FD0\u884C(\u6700\u4F4E v18.4.0,\u63A8\u8350 v20+)\u3002\u8BF7\u5347\u7EA7\u540E\u91CD\u8BD5:https://nodejs.org(\u6216\u7528 nvm/fnm)\u3002
258
260
  `),r(1)):e(`[coze-bridge] \u68C0\u6D4B\u5230 Node.js v${o},\u672C\u9879\u76EE\u63A8\u8350 v20+,\u4F4E\u4E8E v20 \u540E\u7EED\u5347\u7EA7\u53EF\u80FD\u6709\u517C\u5BB9\u95EE\u9898,\u5EFA\u8BAE\u5347\u7EA7\u3002
259
261
  \u5347\u7EA7\u5B8C\u540E\u9700\u8981\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u91CD\u65B0\u8FDE\u63A5:
260
262
  npx -y coze-bridge@latest stop
261
263
  npx -y coze-bridge@latest connect
262
264
 
263
- `)}pp();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&gl("warn");lp(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
265
+ `)}Ip();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&yl("warn");yp(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
264
266
  `),process.exit(1)});