coze-bridge 0.2.0-alpha.5 → 0.2.0-alpha.6
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.
- package/dist/index.js +78 -78
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,34 +5,34 @@ import { dirname as __coze_dirname } from 'node:path';
|
|
|
5
5
|
const require = __coze_createRequire(import.meta.url);
|
|
6
6
|
const __filename = __coze_fileURLToPath(import.meta.url);
|
|
7
7
|
const __dirname = __coze_dirname(__filename);
|
|
8
|
-
var ng=Object.create;var
|
|
8
|
+
var ng=Object.create;var wa=Object.defineProperty;var rg=Object.getOwnPropertyDescriptor;var ig=Object.getOwnPropertyNames;var sg=Object.getPrototypeOf,og=Object.prototype.hasOwnProperty;var ue=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ze=(t,e)=>()=>(t&&(e=t(t=0)),e);var ae=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),_a=(t,e)=>{for(var r in e)wa(t,r,{get:e[r],enumerable:!0})},ag=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ig(e))!og.call(t,o)&&o!==r&&wa(t,o,{get:()=>e[o],enumerable:!(i=rg(e,o))||i.enumerable});return t};var Ft=(t,e,r)=>(r=t!=null?ng(sg(t)):{},ag(e||!t||!t.__esModule?wa(r,"default",{value:t,enumerable:!0}):r,t));function We(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var er=Ze(()=>{"use strict"});import{createWriteStream as cg,mkdirSync as dg,readdirSync as lg,unlinkSync as ug}from"node:fs";import{join as ll}from"node:path";function kn(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function tr(t,e){return`${t}-${e}.log`}function ya(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function fg(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 rs(t,e,r,i){let o;try{o=lg(t)}catch{return}for(let c of o){let l=ya(c,e);if(l&&fg(l,r,i))try{ug(ll(t,c))}catch{}}}var Jr,ba=Ze(()=>{"use strict";Jr=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>kn(new Date))}dir;prefix;opts;currentDate;stream;clock;write(e){let r=this.clock();r!==this.currentDate&&this.rotate(r),this.stream?.write(e)}rotate(e){this.stream?.end();try{dg(this.dir,{recursive:!0});let r=cg(ll(this.dir,tr(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&&
|
|
11
|
-
`;hg(t,{recursive:!0}),xg(pg(t,
|
|
12
|
-
`;if(
|
|
13
|
-
`),{cause:o})}}async function
|
|
14
|
-
`,o=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{r?.mode!==void 0?await Al(o,i,{encoding:"utf8",mode:r.mode}):await Al(o,i,"utf8"),await Sl(o,t),r?.mode!==void 0&&await Rg(t,r.mode)}catch(c){await Sl(o,o).catch(()=>{});let{rm:l}=await import("node:fs/promises");throw await l(o,{force:!0}).catch(()=>{}),c}}var Xr=Ze(()=>{"use strict"});import{promises as Il,readdirSync as Og}from"node:fs";import{homedir as Lg}from"node:os";import{sep as Ng,join as Te,resolve as Tl}from"node:path";function X(t){let e=t??Lg(),r=Te(e,".coze"),i=Te(r,"bridge"),o=Te(i,"lib"),c=Te(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Te(o,"index.js"),binDir:Te(i,"bin"),pidFile:Te(i,"bridge.pid"),portFile:Te(i,"bridge.port"),tokenFile:Te(i,"bridge.token"),patTokenFile:Te(i,"pat-token"),agentEnvFile:Te(i,"agent-env.json"),logFile:Te(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Te(c,"daemon-stdio.log"),installLock:Te(i,"install.lock"),configFile:Te(i,"config.json"),agentsRoot:Te(r,"agents")}}function Ye(t,e=X()){let r=Te(e.agentsRoot,t);return{root:r,config:Te(r,"config.json"),workspace:Te(r,"workspace"),logs:Te(r,"logs")}}function ds(t=X()){try{return Og(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function Qr(t,e){let r=await Il.realpath(Tl(t)).catch(()=>null);if(!r)return!1;let i=await Il.realpath(Tl(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+Ng)}var Oe=Ze(()=>{"use strict"});var fs={};Ea(fs,{AGENT_CONFIG_FILE_MODE:()=>ls,enforceAgentConfigMode:()=>Fg,loadAgentConfig:()=>Me,persistAgentSessions:()=>ei,persistAgentSkills:()=>us,saveAgentConfig:()=>Xe});import{chmod as Mg,stat as Bg}from"node:fs/promises";function Me(t,e){return rr(Ye(t,e).config)}function Xe(t,e){return ir(Ye(t.agentId,e).config,t,{mode:ls})}async function Fg(t,e){if(process.platform==="win32")return;let r=Ye(t,e).config;try{let i=await Bg(r);if(!i.isFile())return;let o=i.mode&511;o!==ls&&(await Mg(r,ls),Cl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Cl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function ei(t,e,r){let i=await Me(t,r);i&&(i.sessions=Object.fromEntries(e),await Xe(i,r))}async function us(t,e,r){let i=await Me(t,r);i&&(i.skills=e,await Xe(i,r))}var Cl,ls,rn=Ze(()=>{"use strict";Xr();te();Oe();Cl=q("agent-config"),ls=384});var ka=ae((R2,Dl)=>{Dl.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 hs=ae(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 Fl=ae((D2,Bl)=>{var Wg=ue("fs"),Le=ue("path"),Ll=ka(),Kg=hs(),$g=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=Le.sep,this.fs=Wg,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 Kg.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=Le.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,f){if(l&&f.isDirectory())return o(!1);var p=Le.dirname(t);c.fs.exists(p,function(m){m||c.makeDir(p),c.fs.open(t,"w",438,function(b,A){b?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(y,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)})})})})}):A?c.fs.write(A,e,0,e.length,0,function(){c.fs.close(A,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};Ee.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let l=[];return e.fs.readdirSync(i).forEach(function(u){let f=Le.join(i,u),p=e.fs.statSync(f);(!o||o.test(f))&&l.push(Le.normalize(f)+(p.isDirectory()?e.sep:"")),p.isDirectory()&&c&&(l=l.concat(r(f,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=Le.join(t,u),r.fs.stat(u,function(f,p){if(f)return e(f);p&&(i.push(Le.normalize(u)+(p.isDirectory()?r.sep:"")),p.isDirectory()?r.findFilesAsync(u,function(m,b){if(m)return e(m);i=i.concat(b),--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=Le.posix.normalize("/"+t.split("\\").join("/"));return Le.join(".",e)};Ee.zipnamefix=function(t){if(!t)return"";let e=Le.posix.normalize("/"+t.split("\\").join("/"));return Le.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=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)))};Ee.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};Ee.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};Ee.fromDOS2Date=function(t){return new Date((t>>25&127)+1980,Math.max((t>>21&15)-1,0),Math.max(t>>16&31,1),t>>11&31,t>>5&63,(t&31)<<1)};Ee.fromDate2DOS=function(t){let e=0,r=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),r=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|r};Ee.isWin=$g;Ee.crcTable=Ml});var Ul=ae((P2,zl)=>{var Vg=ue("path");zl.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=Vg.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 ql=ae((O2,Gl)=>{Gl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var ar=ae((L2,or)=>{or.exports=Fl();or.exports.Constants=ka();or.exports.Errors=hs();or.exports.FileAttr=Ul();or.exports.decoder=ql()});var jl=ae((N2,Hl)=>{var sn=ar(),U=sn.Constants;Hl.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,l=0,u=0,f=0,p=0,m=0,b=0,A=0,y=0,S=0;t|=sn.isWin?2560:768,r|=U.FLG_EFS;let I={extraLen:0},T=E=>Math.max(0,E)>>>0,R=E=>Math.max(0,E)&65535,D=E=>Math.max(0,E)&255;return o=sn.fromDate2DOS(new Date),{get made(){return t},set made(E){t=E},get version(){return e},set version(E){e=E},get flags(){return r},set flags(E){r=E},get flags_efs(){return(r&U.FLG_EFS)>0},set flags_efs(E){E?r|=U.FLG_EFS:r&=~U.FLG_EFS},get flags_desc(){return(r&U.FLG_DESC)>0},set flags_desc(E){E?r|=U.FLG_DESC:r&=~U.FLG_DESC},get method(){return i},set method(E){switch(E){case U.STORED:this.version=10;case U.DEFLATED:default:this.version=20}i=E},get time(){return sn.fromDOS2Date(this.timeval)},set time(E){E=new Date(E),this.timeval=sn.fromDate2DOS(E)},get timeval(){return o},set timeval(E){o=T(E)},get timeHighByte(){return D(o>>>8)},get crc(){return c},set crc(E){c=T(E)},get compressedSize(){return l},set compressedSize(E){l=T(E)},get size(){return u},set size(E){u=T(E)},get fileNameLength(){return f},set fileNameLength(E){f=E},get extraLength(){return p},set extraLength(E){p=E},get extraLocalLength(){return I.extraLen},set extraLocalLength(E){I.extraLen=E},get commentLength(){return m},set commentLength(E){m=E},get diskNumStart(){return b},set diskNumStart(E){b=T(E)},get inAttr(){return A},set inAttr(E){A=T(E)},get attr(){return y},set attr(E){y=T(E)},get fileAttr(){return(y||0)>>16&4095},get offset(){return S},set offset(E){S=T(E)},get encrypted(){return(r&U.FLG_ENC)===U.FLG_ENC},get centralHeaderSize(){return U.CENHDR+f+p+m},get realDataOffset(){return S+U.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(E){var k=E.slice(S,S+U.LOCHDR);if(k.readUInt32LE(0)!==U.LOCSIG)throw sn.Errors.INVALID_LOC();I.version=k.readUInt16LE(U.LOCVER),I.flags=k.readUInt16LE(U.LOCFLG),I.flags_desc=(I.flags&U.FLG_DESC)>0,I.method=k.readUInt16LE(U.LOCHOW),I.time=k.readUInt32LE(U.LOCTIM),I.crc=k.readUInt32LE(U.LOCCRC),I.compressedSize=k.readUInt32LE(U.LOCSIZ),I.size=k.readUInt32LE(U.LOCLEN),I.fnameLen=k.readUInt16LE(U.LOCNAM),I.extraLen=k.readUInt16LE(U.LOCEXT);let P=S+U.LOCHDR+I.fnameLen,F=P+I.extraLen;return E.slice(P,F)},loadFromBinary:function(E){if(E.length!==U.CENHDR||E.readUInt32LE(0)!==U.CENSIG)throw sn.Errors.INVALID_CEN();t=E.readUInt16LE(U.CENVEM),e=E.readUInt16LE(U.CENVER),r=E.readUInt16LE(U.CENFLG),i=E.readUInt16LE(U.CENHOW),o=E.readUInt32LE(U.CENTIM),c=E.readUInt32LE(U.CENCRC),l=E.readUInt32LE(U.CENSIZ),u=E.readUInt32LE(U.CENLEN),f=E.readUInt16LE(U.CENNAM),p=E.readUInt16LE(U.CENEXT),m=E.readUInt16LE(U.CENCOM),b=E.readUInt16LE(U.CENDSK),A=E.readUInt16LE(U.CENATT),y=E.readUInt32LE(U.CENATX),S=E.readUInt32LE(U.CENOFF)},localHeaderToBinary:function(){var E=Buffer.alloc(U.LOCHDR);return E.writeUInt32LE(U.LOCSIG,0),E.writeUInt16LE(e,U.LOCVER),E.writeUInt16LE(r,U.LOCFLG),E.writeUInt16LE(i,U.LOCHOW),E.writeUInt32LE(o,U.LOCTIM),E.writeUInt32LE(c,U.LOCCRC),E.writeUInt32LE(l,U.LOCSIZ),E.writeUInt32LE(u,U.LOCLEN),E.writeUInt16LE(f,U.LOCNAM),E.writeUInt16LE(I.extraLen,U.LOCEXT),E},centralHeaderToBinary:function(){var E=Buffer.alloc(U.CENHDR+f+p+m);return E.writeUInt32LE(U.CENSIG,0),E.writeUInt16LE(t,U.CENVEM),E.writeUInt16LE(e,U.CENVER),E.writeUInt16LE(r,U.CENFLG),E.writeUInt16LE(i,U.CENHOW),E.writeUInt32LE(o,U.CENTIM),E.writeUInt32LE(c,U.CENCRC),E.writeUInt32LE(l,U.CENSIZ),E.writeUInt32LE(u,U.CENLEN),E.writeUInt16LE(f,U.CENNAM),E.writeUInt16LE(p,U.CENEXT),E.writeUInt16LE(m,U.CENCOM),E.writeUInt16LE(b,U.CENDSK),E.writeUInt16LE(A,U.CENATT),E.writeUInt32LE(y,U.CENATX),E.writeUInt32LE(S,U.CENOFF),E},toJSON:function(){let E=function(k){return k+" bytes"};return{made:t,version:e,flags:r,method:sn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:E(l),size:E(u),fileNameLength:E(f),extraLength:E(p),commentLength:E(m),diskNumStart:b,inAttr:A,attr:y,offset:S,centralHeaderSize:E(U.CENHDR+f+p+m)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Kl=ae((M2,Wl)=>{var cr=ar(),we=cr.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 we.ENDHDR+o},loadFromBinary:function(c){if((c.length!==we.ENDHDR||c.readUInt32LE(0)!==we.ENDSIG)&&(c.length<we.ZIP64HDR||c.readUInt32LE(0)!==we.ZIP64SIG))throw cr.Errors.INVALID_END();c.readUInt32LE(0)===we.ENDSIG?(t=c.readUInt16LE(we.ENDSUB),e=c.readUInt16LE(we.ENDTOT),r=c.readUInt32LE(we.ENDSIZ),i=c.readUInt32LE(we.ENDOFF),o=c.readUInt16LE(we.ENDCOM)):(t=cr.readBigUInt64LE(c,we.ZIP64SUB),e=cr.readBigUInt64LE(c,we.ZIP64TOT),r=cr.readBigUInt64LE(c,we.ZIP64SIZE),i=cr.readBigUInt64LE(c,we.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(we.ENDHDR+o);return c.writeUInt32LE(we.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,we.ENDSUB),c.writeUInt16LE(e,we.ENDTOT),c.writeUInt32LE(r,we.ENDSIZ),c.writeUInt32LE(i,we.ENDOFF),c.writeUInt16LE(o,we.ENDCOM),c.fill(" ",we.ENDHDR),c},toJSON:function(){let c=function(l,u){let f=l.toString(16).toUpperCase();for(;f.length<u;)f="0"+f;return"0x"+f};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Pa=ae(Da=>{Da.EntryHeader=jl();Da.MainHeader=Kl()});var Vl=ae((F2,$l)=>{$l.exports=function(t){var e=ue("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],l=0;o.on("data",function(u){c.push(u),l+=u.length}),o.on("end",function(){var u=Buffer.alloc(l),f=0;u.fill(0);for(var p=0;p<c.length;p++){var m=c[p];m.copy(u,f),f+=m.length}i&&i(u)}),o.end(t)}}}});var Zl=ae((z2,Jl)=>{var Jg=+(process.versions?process.versions.node:"").split(".")[0]||0;Jl.exports=function(t,e){var r=ue("zlib");let i=Jg>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),l=[],u=0;c.on("data",function(f){l.push(f),u+=f.length}),c.on("end",function(){var f=Buffer.alloc(u),p=0;f.fill(0);for(var m=0;m<l.length;m++){var b=l[m];b.copy(f,p),p+=b.length}o&&o(f)}),c.end(t)}}}});var tu=ae((U2,eu)=>{"use strict";var{randomFillSync:Yl}=ue("crypto"),Zg=hs(),Yg=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,Xl=(t,e)=>Yg[(t^e)&255]^t>>>8,ti=()=>typeof Yl=="function"?Yl(Buffer.alloc(12)):ti.node();ti.node=()=>{let t=Buffer.alloc(12),e=t.length;for(let r=0;r<e;r++)t[r]=Math.random()*256&255;return t};var ps={genSalt:ti};function gs(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])}gs.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Xl(e[0],t),e[1]+=e[0]&255,e[1]=Ql(e[1],134775813)+1,e[2]=Xl(e[2],e[1]>>>24),t};gs.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Ql(t,t^1)>>8&255};function Xg(t){let e=new gs(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 Qg(t){let e=new gs(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 em(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Xg(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Zg.WRONG_PASSWORD();return i(t.slice(12))}function tm(t){Buffer.isBuffer(t)&&t.length>=12?ps.genSalt=function(){return t.slice(0,12)}:t==="node"?ps.genSalt=ti.node:ps.genSalt=ti}function nm(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Qg(r),c=ps.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:em,encrypt:nm,_salter:tm}});var nu=ae(ms=>{ms.Deflater=Vl();ms.Inflater=Zl();ms.ZipCrypto=tu()});var La=ae((q2,ru)=>{var ce=ar(),rm=Pa(),be=ce.Constants,Oa=nu();ru.exports=function(t,e){var r=new rm.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,l=null,u=Buffer.alloc(0),f=Buffer.alloc(0),p=!0;let m=t,b=typeof m.decoder=="object"?m.decoder:ce.decoder;p=b.hasOwnProperty("efs")?b.efs:!1;function A(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(f=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function y(E){if(!r.flags_desc&&!r.localHeader.flags_desc){if(ce.crc32(E)!==r.localHeader.crc)return!1}else{let k={},P=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(P)==be.LOCSIG||e.readUInt32LE(P)==be.CENSIG)throw ce.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(P)==be.EXTSIG)k.crc=e.readUInt32LE(P+be.EXTCRC),k.compressedSize=e.readUInt32LE(P+be.EXTSIZ),k.size=e.readUInt32LE(P+be.EXTLEN);else if(e.readUInt16LE(P+12)===19280)k.crc=e.readUInt32LE(P+be.EXTCRC-4),k.compressedSize=e.readUInt32LE(P+be.EXTSIZ-4),k.size=e.readUInt32LE(P+be.EXTLEN-4);else throw ce.Errors.DESCRIPTOR_UNKNOWN();if(k.compressedSize!==r.compressedSize||k.size!==r.size||k.crc!==r.crc)throw ce.Errors.DESCRIPTOR_FAULTY();if(ce.crc32(E)!==k.crc)return!1}return!0}function S(E,k,P){if(typeof k>"u"&&typeof E=="string"&&(P=E,E=void 0),c)return E&&k&&k(Buffer.alloc(0),ce.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var F=A();if(F.length===0)return E&&k&&k(F),F;if(r.encrypted){if(typeof P!="string"&&!Buffer.isBuffer(P))throw ce.Errors.INVALID_PASS_PARAM();F=Oa.ZipCrypto.decrypt(F,r,P)}var M=Buffer.alloc(r.size);switch(r.method){case ce.Constants.STORED:if(F.copy(M),y(M))return E&&k&&k(M),M;throw E&&k&&k(M,ce.Errors.BAD_CRC()),ce.Errors.BAD_CRC();case ce.Constants.DEFLATED:var J=new Oa.Inflater(F,r.size);if(E)J.inflateAsync(function(V){V.copy(V,0),k&&(y(V)?k(V):k(V,ce.Errors.BAD_CRC()))});else{if(J.inflate(M).copy(M,0),!y(M))throw ce.Errors.BAD_CRC(`"${b.decode(i)}"`);return M}break;default:throw E&&k&&k(Buffer.alloc(0),ce.Errors.UNKNOWN_METHOD()),ce.Errors.UNKNOWN_METHOD()}}function I(E,k){if((!l||!l.length)&&Buffer.isBuffer(e))return E&&k&&k(A()),A();if(l.length&&!c){var P;switch(r.method){case ce.Constants.STORED:return r.compressedSize=r.size,P=Buffer.alloc(l.length),l.copy(P),E&&k&&k(P),P;default:case ce.Constants.DEFLATED:var F=new Oa.Deflater(l);if(E)F.deflateAsync(function(J){P=Buffer.alloc(J.length),r.compressedSize=J.length,J.copy(P),k&&k(P)});else{var M=F.deflate();return r.compressedSize=M.length,M}F=null;break}}else if(E&&k)k(Buffer.alloc(0));else return Buffer.alloc(0)}function T(E,k){return ce.readBigUInt64LE(E,k)}function R(E){try{for(var k=0,P,F,M;k+4<E.length;)P=E.readUInt16LE(k),k+=2,F=E.readUInt16LE(k),k+=2,M=E.slice(k,k+F),k+=F,be.ID_ZIP64===P&&D(M)}catch{throw ce.Errors.EXTRA_FIELD_PARSE_ERROR()}}function D(E){var k,P,F,M;E.length>=be.EF_ZIP64_SCOMP&&(k=T(E,be.EF_ZIP64_SUNCOMP),r.size===be.EF_ZIP64_OR_32&&(r.size=k)),E.length>=be.EF_ZIP64_RHO&&(P=T(E,be.EF_ZIP64_SCOMP),r.compressedSize===be.EF_ZIP64_OR_32&&(r.compressedSize=P)),E.length>=be.EF_ZIP64_DSN&&(F=T(E,be.EF_ZIP64_RHO),r.offset===be.EF_ZIP64_OR_32&&(r.offset=F)),E.length>=be.EF_ZIP64_DSN+4&&(M=E.readUInt32LE(be.EF_ZIP64_DSN),r.diskNumStart===be.EF_ZIP64_OR_16&&(r.diskNumStart=M))}return{get entryName(){return b.decode(i)},get rawEntryName(){return i},set entryName(E){i=ce.toBuffer(E,b.encode);var k=i[i.length-1];c=k===47||k===92,r.fileNameLength=i.length},get efs(){return typeof p=="function"?p(this.entryName):p},get extra(){return u},set extra(E){u=E,r.extraLength=E.length,R(E)},get comment(){return b.decode(o)},set comment(E){if(o=ce.toBuffer(E,b.encode),r.commentLength=o.length,o.length>65535)throw ce.Errors.COMMENT_TOO_LONG()},get name(){var E=b.decode(i);return c?E.substr(E.length-1).split("/").pop():E.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(E){I(!0,E)},setData:function(E){l=ce.toBuffer(E,ce.decoder.encode),!c&&l.length?(r.size=l.length,r.method=ce.Constants.DEFLATED,r.crc=ce.crc32(E),r.changed=!0):r.method=ce.Constants.STORED},getData:function(E){return r.changed?l:S(!1,null,E)},getDataAsync:function(E,k){r.changed?E(l):S(!0,E,k)},set attr(E){r.attr=E},get attr(){return r.attr},set header(E){r.loadFromBinary(E)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=u.length;var E=r.centralHeaderToBinary(),k=ce.Constants.CENHDR;return i.copy(E,k),k+=i.length,u.copy(E,k),k+=r.extraLength,o.copy(E,k),E},packLocalHeader:function(){let E=0;r.flags_efs=this.efs,r.extraLocalLength=f.length;let k=r.localHeaderToBinary(),P=Buffer.alloc(k.length+i.length+r.extraLocalLength);return k.copy(P,E),E+=k.length,i.copy(P,E),E+=i.length,f.copy(P,E),E+=f.length,P},toJSON:function(){let E=function(k){return"<"+(k&&k.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:E(e),data:E(l)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var ou=ae((H2,su)=>{var iu=La(),im=Pa(),He=ar();su.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new im.MainHeader,l=!1,u=null;let f=new Set,p=e,{noSort:m,decoder:b}=p;t?S(p.readEntries):l=!0;function A(){let T=new Set;for(let R of Object.keys(i)){let D=R.split("/");if(D.pop(),!!D.length)for(let E=0;E<D.length;E++){let k=D.slice(0,E+1).join("/")+"/";T.add(k)}}for(let R of T)if(!(R in i)){let D=new iu(p);D.entryName=R,D.attr=16,D.temporary=!0,r.push(D),i[D.entryName]=D,f.add(D)}}function y(){if(l=!0,i={},c.diskEntries>(t.length-c.offset)/He.Constants.CENHDR)throw He.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var T=c.offset,R=0;R<r.length;R++){var D=T,E=new iu(p,t);E.header=t.slice(D,D+=He.Constants.CENHDR),E.entryName=t.slice(D,D+=E.header.fileNameLength),E.header.extraLength&&(E.extra=t.slice(D,D+=E.header.extraLength)),E.header.commentLength&&(E.comment=t.slice(D,D+E.header.commentLength)),T+=E.header.centralHeaderSize,r[R]=E,i[E.entryName]=E}f.clear(),A()}function S(T){var R=t.length-He.Constants.ENDHDR,D=Math.max(0,R-65535),E=D,k=t.length,P=-1,F=0;for(typeof p.trailingSpace=="boolean"&&p.trailingSpace&&(D=0),R;R>=E;R--)if(t[R]===80){if(t.readUInt32LE(R)===He.Constants.ENDSIG){P=R,F=R,k=R+He.Constants.ENDHDR,E=R-He.Constants.END64HDR;continue}if(t.readUInt32LE(R)===He.Constants.END64SIG){E=D;continue}if(t.readUInt32LE(R)===He.Constants.ZIP64SIG){P=R,k=R+He.readBigUInt64LE(t,R+He.Constants.ZIP64SIZE)+He.Constants.ZIP64LEAD;break}}if(P==-1)throw He.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(P,k)),c.commentLength&&(o=t.slice(F+He.Constants.ENDHDR)),T&&y()}function I(){r.length>1&&!m&&r.sort((T,R)=>T.entryName.toLowerCase().localeCompare(R.entryName.toLowerCase()))}return{get entries(){return l||y(),r.filter(T=>!f.has(T))},get comment(){return b.decode(o)},set comment(T){o=He.toBuffer(T,b.encode),c.commentLength=o.length},getEntryCount:function(){return l?r.length:c.diskEntries},forEach:function(T){this.entries.forEach(T)},getEntry:function(T){return l||y(),i[T]||null},setEntry:function(T){l||y(),r.push(T),i[T.entryName]=T,c.totalEntries=r.length},deleteFile:function(T,R=!0){l||y();let D=i[T];this.getEntryChildren(D,R).map(k=>k.entryName).forEach(this.deleteEntry)},deleteEntry:function(T){l||y();let R=i[T],D=r.indexOf(R);D>=0&&(r.splice(D,1),delete i[T],c.totalEntries=r.length)},getEntryChildren:function(T,R=!0){if(l||y(),typeof T=="object")if(T.isDirectory&&R){let D=[],E=T.entryName;for(let k of r)k.entryName.startsWith(E)&&D.push(k);return D}else return[T];return[]},getChildCount:function(T){if(T&&T.isDirectory){let R=this.getEntryChildren(T);return R.includes(T)?R.length-1:R.length}return 0},compressToBuffer:function(){l||y(),I();let T=[],R=[],D=0,E=0;c.size=0,c.offset=0;let k=0;for(let M of this.entries){let J=M.getCompressedData();M.header.offset=E;let V=M.packLocalHeader(),ee=V.length+J.length;E+=ee,T.push(V),T.push(J);let Z=M.packCentralHeader();R.push(Z),c.size+=Z.length,D+=ee+Z.length,k++}D+=c.mainHeaderSize,c.offset=E,c.totalEntries=k,E=0;let P=Buffer.alloc(D);for(let M of T)M.copy(P,E),E+=M.length;for(let M of R)M.copy(P,E),E+=M.length;let F=c.toBinary();return o&&o.copy(F,He.Constants.ENDHDR),F.copy(P,E),t=P,l=!1,P},toAsyncBuffer:function(T,R,D,E){try{l||y(),I();let k=[],P=[],F=0,M=0,J=0;c.size=0,c.offset=0;let V=function(ee){if(ee.length>0){let Z=ee.shift(),ie=Z.entryName+Z.extra.toString();D&&D(ie),Z.getCompressedDataAsync(function(oe){E&&E(ie),Z.header.offset=M;let O=Z.packLocalHeader(),H=O.length+oe.length;M+=H,k.push(O),k.push(oe);let $=Z.packCentralHeader();P.push($),c.size+=$.length,F+=H+$.length,J++,V(ee)})}else{F+=c.mainHeaderSize,c.offset=M,c.totalEntries=J,M=0;let Z=Buffer.alloc(F);k.forEach(function(oe){oe.copy(Z,M),M+=oe.length}),P.forEach(function(oe){oe.copy(Z,M),M+=oe.length});let ie=c.toBinary();o&&o.copy(ie,He.Constants.ENDHDR),ie.copy(Z,M),t=Z,l=!1,T(Z)}};V(Array.from(this.entries))}catch(k){R(k)}}}}});var du=ae((j2,cu)=>{var ye=ar(),_e=ue("path"),sm=La(),om=ou(),Cn=(...t)=>ye.findLast(t,e=>typeof e=="boolean"),au=(...t)=>ye.findLast(t,e=>typeof e=="string"),am=(...t)=>ye.findLast(t,e=>typeof e=="function"),cm={noSort:!1,readEntries:!1,method:ye.Constants.NONE,fs:null};cu.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),cm);t&&typeof t=="object"&&(t instanceof Uint8Array||(Object.assign(i,t),t=i.input?i.input:void 0,i.input&&delete i.input),Buffer.isBuffer(t)&&(r=t,i.method=ye.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new ye(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=ye.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=ye.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw ye.Errors.INVALID_FILENAME();let c=new om(r,i),{canonical:l,sanitize:u,zipnamefix:f}=ye;function p(y){if(y&&c){var S;if(typeof y=="string"&&(S=c.getEntry(_e.posix.normalize(y))),typeof y=="object"&&typeof y.entryName<"u"&&typeof y.header<"u"&&(S=c.getEntry(y.entryName)),S)return S}return null}function m(y){let{join:S,normalize:I,sep:T}=_e.posix;return S(_e.isAbsolute(y)?"/":".",I(T+y.split("\\").join(T)+T))}function b(y){return y instanceof RegExp?(function(S){return function(I){return S.test(I)}})(y):typeof y!="function"?()=>!0:y}let A=(y,S)=>{let I=S.slice(-1);return I=I===o.sep?o.sep:"",_e.relative(y,S)+I};return{readFile:function(y,S){var I=p(y);return I&&I.getData(S)||null},childCount:function(y){let S=p(y);if(S)return c.getChildCount(S)},readFileAsync:function(y,S){var I=p(y);I?I.getDataAsync(S):S(null,"getEntry failed for:"+y)},readAsText:function(y,S){var I=p(y);if(I){var T=I.getData();if(T&&T.length)return T.toString(S||"utf8")}return""},readAsTextAsync:function(y,S,I){var T=p(y);T?T.getDataAsync(function(R,D){if(D){S(R,D);return}R&&R.length?S(R.toString(I||"utf8")):S("")}):S("")},deleteFile:function(y,S=!0){var I=p(y);I&&c.deleteFile(I.entryName,S)},deleteEntry:function(y){var S=p(y);S&&c.deleteEntry(S.entryName)},addZipComment:function(y){c.comment=y},getZipComment:function(){return c.comment||""},addZipEntryComment:function(y,S){var I=p(y);I&&(I.comment=S)},getZipEntryComment:function(y){var S=p(y);return S&&S.comment||""},updateFile:function(y,S){var I=p(y);I&&I.setData(S)},addLocalFile:function(y,S,I,T){if(o.fs.existsSync(y)){S=S?m(S):"";let R=_e.win32.basename(_e.win32.normalize(y));S+=I||R;let D=o.fs.statSync(y),E=D.isFile()?o.fs.readFileSync(y):Buffer.alloc(0);D.isDirectory()&&(S+=o.sep),this.addFile(S,E,T,D)}else throw ye.Errors.FILE_NOT_FOUND(y)},addLocalFileAsync:function(y,S){y=typeof y=="object"?y:{localPath:y};let I=_e.resolve(y.localPath),{comment:T}=y,{zipPath:R,zipName:D}=y,E=this;o.fs.stat(I,function(k,P){if(k)return S(k,!1);R=R?m(R):"";let F=_e.win32.basename(_e.win32.normalize(I));if(R+=D||F,P.isFile())o.fs.readFile(I,function(M,J){return M?S(M,!1):(E.addFile(R,J,T,P),setImmediate(S,void 0,!0))});else if(P.isDirectory())return R+=o.sep,E.addFile(R,Buffer.alloc(0),T,P),setImmediate(S,void 0,!0)})},addLocalFolder:function(y,S,I){if(I=b(I),S=S?m(S):"",y=_e.normalize(y),o.fs.existsSync(y)){let T=o.findFiles(y),R=this;if(T.length)for(let D of T){let E=_e.join(S,A(y,D));I(E)&&R.addLocalFile(D,_e.dirname(E))}}else throw ye.Errors.FILE_NOT_FOUND(y)},addLocalFolderAsync:function(y,S,I,T){T=b(T),I=I?m(I):"",y=_e.normalize(y);var R=this;o.fs.open(y,"r",function(D){if(D&&D.code==="ENOENT")S(void 0,ye.Errors.FILE_NOT_FOUND(y));else if(D)S(void 0,D);else{var E=o.findFiles(y),k=-1,P=function(){if(k+=1,k<E.length){var F=E[k],M=A(y,F).split("\\").join("/");M=M.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),T(M)?o.fs.stat(F,function(J,V){J&&S(void 0,J),V.isFile()?o.fs.readFile(F,function(ee,Z){ee?S(void 0,ee):(R.addFile(I+M,Z,"",V),P())}):(R.addFile(I+M+"/",Buffer.alloc(0),"",V),P())}):process.nextTick(()=>{P()})}else S(!0,void 0)};P()}})},addLocalFolderAsync2:function(y,S){let I=this;y=typeof y=="object"?y:{localPath:y},localPath=_e.resolve(m(y.localPath));let{zipPath:T,filter:R,namefix:D}=y;R instanceof RegExp?R=(function(P){return function(F){return P.test(F)}})(R):typeof R!="function"&&(R=function(){return!0}),T=T?m(T):"",D=="latin1"&&(D=P=>P.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof D!="function"&&(D=P=>P);let E=P=>_e.join(T,D(A(localPath,P))),k=P=>_e.win32.basename(_e.win32.normalize(D(P)));o.fs.open(localPath,"r",function(P){P&&P.code==="ENOENT"?S(void 0,ye.Errors.FILE_NOT_FOUND(localPath)):P?S(void 0,P):o.findFilesAsync(localPath,function(F,M){if(F)return S(F);M=M.filter(J=>R(E(J))),M.length||S(void 0,!1),setImmediate(M.reverse().reduce(function(J,V){return function(ee,Z){if(ee||Z===!1)return setImmediate(J,ee,!1);I.addLocalFileAsync({localPath:V,zipPath:_e.dirname(E(V)),zipName:k(V)},J)}},S))})})},addLocalFolderPromise:function(y,S){return new Promise((I,T)=>{this.addLocalFolderAsync2(Object.assign({localPath:y},S),(R,D)=>{R&&T(R),D&&I(this)})})},addFile:function(y,S,I,T){y=f(y);let R=p(y),D=R!=null;D||(R=new sm(i),R.entryName=y),R.comment=I||"";let E=typeof T=="object"&&T instanceof o.fs.Stats;E&&(R.header.time=T.mtime);var k=R.isDirectory?16:0;let P=R.isDirectory?16384:32768;return E?P|=4095&T.mode:typeof T=="number"?P|=4095&T:P|=R.isDirectory?493:420,k=(k|P<<16)>>>0,R.attr=k,R.setData(S),D||c.setEntry(R),R},getEntries:function(y){return c.password=y,c?c.entries:[]},getEntry:function(y){return p(y)},getEntryCount:function(){return c.getEntryCount()},forEach:function(y){return c.forEach(y)},extractEntryTo:function(y,S,I,T,R,D){T=Cn(!1,T),R=Cn(!1,R),I=Cn(!0,I),D=au(R,D);var E=p(y);if(!E)throw ye.Errors.NO_ENTRY();var k=l(E.entryName),P=u(S,D&&!E.isDirectory?D:I?k:_e.basename(k));if(E.isDirectory){var F=c.getEntryChildren(E);return F.forEach(function(V){if(V.isDirectory)return;var ee=V.getData();if(!ee)throw ye.Errors.CANT_EXTRACT_FILE();var Z=l(V.entryName),ie=u(S,I?Z:_e.basename(Z));let oe=R?V.header.fileAttr:void 0;o.writeFileTo(ie,ee,T,oe)}),!0}var M=E.getData(c.password);if(!M)throw ye.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(P)&&!T)throw ye.Errors.CANT_OVERRIDE();let J=R?y.header.fileAttr:void 0;return o.writeFileTo(P,M,T,J),!0},test:function(y){if(!c)return!1;for(var S in c.entries)try{if(S.isDirectory)continue;var I=c.entries[S].getData(y);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(y,S,I,T){if(I=Cn(!1,I),T=au(I,T),S=Cn(!1,S),!c)throw ye.Errors.NO_ZIP();c.entries.forEach(function(R){var D=u(y,l(R.entryName));if(R.isDirectory){o.makeDir(D);return}var E=R.getData(T);if(!E)throw ye.Errors.CANT_EXTRACT_FILE();let k=I?R.header.fileAttr:void 0;o.writeFileTo(D,E,S,k);try{o.fs.utimesSync(D,R.header.time,R.header.time)}catch{throw ye.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(y,S,I,T){if(T=am(S,I,T),I=Cn(!1,I),S=Cn(!1,S),!T)return new Promise((P,F)=>{this.extractAllToAsync(y,S,I,function(M){M?F(M):P(this)})});if(!c){T(ye.Errors.NO_ZIP());return}y=_e.resolve(y);let R=P=>u(y,_e.normalize(l(P.entryName))),D=(P,F)=>new Error(P+': "'+F+'"'),E=[],k=[];c.entries.forEach(P=>{P.isDirectory?E.push(P):k.push(P)});for(let P of E){let F=R(P),M=I?P.header.fileAttr:void 0;try{o.makeDir(F),M&&o.fs.chmodSync(F,M),o.fs.utimesSync(F,P.header.time,P.header.time)}catch{T(D("Unable to create folder",F))}}k.reverse().reduce(function(P,F){return function(M){if(M)P(M);else{let J=_e.normalize(l(F.entryName)),V=u(y,J);F.getDataAsync(function(ee,Z){if(Z)P(Z);else if(!ee)P(ye.Errors.CANT_EXTRACT_FILE());else{let ie=I?F.header.fileAttr:void 0;o.writeFileToAsync(V,ee,S,ie,function(oe){oe||P(D("Unable to write file",V)),o.fs.utimes(V,F.header.time,F.header.time,function(O){O?P(D("Unable to set times",V)):P()})})}})}}},T)()},writeZip:function(y,S){if(arguments.length===1&&typeof y=="function"&&(S=y,y=""),!y&&i.filename&&(y=i.filename),!!y){var I=c.compressToBuffer();if(I){var T=o.writeFileTo(y,I,!0);typeof S=="function"&&S(T?null:new Error("failed"),"")}}},writeZipPromise:function(y,S){let{overwrite:I,perm:T}=Object.assign({overwrite:!0},S);return new Promise((R,D)=>{!y&&i.filename&&(y=i.filename),y||D("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(E=>{let k=P=>P?R(P):D("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(y,E,I,T,k)},D)})},toBufferPromise:function(){return new Promise((y,S)=>{c.toAsyncBuffer(y,S)})},toBuffer:function(y,S,I,T){return typeof y=="function"?(c.toAsyncBuffer(y,S,I,T),null):c.compressToBuffer()}}}});import{execFile as h_,spawn as p_,spawnSync as cI}from"node:child_process";import{promisify as g_}from"node:util";function w_(t){if(process.platform!=="win32")return!1;if(Rf.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(Rf,"").toLowerCase();return m_.has(r)}function kf(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return w_(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function et(t,e=[],r={}){return p_(t,e,kf(t,r))}function Df(t,e=[],r={}){return __(t,e,kf(t,r))}var m_,Rf,__,Wt=Ze(()=>{"use strict";m_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Rf=/\.(cmd|bat|ps1)$/i;__=g_(h_)});var $t=ae((z3,ox)=>{"use strict";var ix=["nodebuffer","arraybuffer","fragments"],sx=typeof Blob<"u";sx&&ix.push("blob");ox.exports={BINARY_TYPES:ix,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:sx,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var qi=ae((U3,So)=>{"use strict";var{EMPTY_BUFFER:tb}=$t(),ad=Buffer[Symbol.species];function nb(t,e){if(t.length===0)return tb;if(t.length===1)return t[0];let r=Buffer.allocUnsafe(e),i=0;for(let o=0;o<t.length;o++){let c=t[o];r.set(c,i),i+=c.length}return i<e?new ad(r.buffer,r.byteOffset,i):r}function ax(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function cx(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function rb(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function cd(t){if(cd.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new ad(t):ArrayBuffer.isView(t)?e=new ad(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),cd.readOnly=!1),e}So.exports={concat:nb,mask:ax,toArrayBuffer:rb,toBuffer:cd,unmask:cx};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=ue("bufferutil");So.exports.mask=function(e,r,i,o,c){c<48?ax(e,r,i,o,c):t.mask(e,r,i,o,c)},So.exports.unmask=function(e,r){e.length<32?cx(e,r):t.unmask(e,r)}}catch{}});var ux=ae((G3,lx)=>{"use strict";var dx=Symbol("kDone"),dd=Symbol("kRun"),ld=class{constructor(e){this[dx]=()=>{this.pending--,this[dd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[dd]()}[dd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[dx])}}};lx.exports=ld});var Lr=ae((q3,px)=>{"use strict";var Hi=ue("zlib"),fx=qi(),ib=ux(),{kStatusCode:xx}=$t(),sb=Buffer[Symbol.species],ob=Buffer.from([0,0,255,255]),Io=Symbol("permessage-deflate"),Vt=Symbol("total-length"),Pr=Symbol("callback"),vn=Symbol("buffers"),Or=Symbol("error"),Ao,ud=class{constructor(e){if(this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._maxPayload=this._options.maxPayload|0,this._isServer=!!this._options.isServer,this._deflate=null,this._inflate=null,this.params=null,!Ao){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Ao=new ib(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[Pr];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,i=e.find(o=>!(r.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>o.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!o.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(i.server_no_context_takeover=!0),r.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(i.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?i.client_max_window_bits=r.clientMaxWindowBits:(i.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(i=>{let o=r[i];if(o.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(o=o[0],i==="client_max_window_bits"){if(o!==!0){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else if(i==="server_max_window_bits"){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(o!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else throw new Error(`Unknown parameter "${i}"`);r[i]=o})}),e}decompress(e,r,i){Ao.add(o=>{this._decompress(e,r,(c,l)=>{o(),i(c,l)})})}compress(e,r,i){Ao.add(o=>{this._compress(e,r,(c,l)=>{o(),i(c,l)})})}_decompress(e,r,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?Hi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Hi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:l}),this._inflate[Io]=this,this._inflate[Vt]=0,this._inflate[vn]=[],this._inflate.on("error",cb),this._inflate.on("data",hx)}this._inflate[Pr]=i,this._inflate.write(e),r&&this._inflate.write(ob),this._inflate.flush(()=>{let c=this._inflate[Or];if(c){this._inflate.close(),this._inflate=null,i(c);return}let l=fx.concat(this._inflate[vn],this._inflate[Vt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Vt]=0,this._inflate[vn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,l)})}_compress(e,r,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,l=typeof this.params[c]!="number"?Hi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Hi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:l}),this._deflate[Vt]=0,this._deflate[vn]=[],this._deflate.on("data",ab)}this._deflate[Pr]=i,this._deflate.write(e),this._deflate.flush(Hi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=fx.concat(this._deflate[vn],this._deflate[Vt]);r&&(c=new sb(c.buffer,c.byteOffset,c.length-4)),this._deflate[Pr]=null,this._deflate[Vt]=0,this._deflate[vn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};px.exports=ud;function ab(t){this[vn].push(t),this[Vt]+=t.length}function hx(t){if(this[Vt]+=t.length,this[Io]._maxPayload<1||this[Vt]<=this[Io]._maxPayload){this[vn].push(t);return}this[Or]=new RangeError("Max payload size exceeded"),this[Or].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Or][xx]=1009,this.removeListener("data",hx),this.reset()}function cb(t){if(this[Io]._inflate=null,this[Or]){this[Pr](this[Or]);return}t[xx]=1007,this[Pr](t)}});var Nr=ae((H3,To)=>{"use strict";var{isUtf8:gx}=ue("buffer"),{hasBlob:db}=$t(),lb=[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 ub(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function fd(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 fb(t){return db&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}To.exports={isBlob:fb,isValidStatusCode:ub,isValidUTF8:fd,tokenChars:lb};if(gx)To.exports.isValidUTF8=function(t){return t.length<24?fd(t):gx(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=ue("utf-8-validate");To.exports.isValidUTF8=function(e){return e.length<32?fd(e):t(e)}}catch{}});var md=ae((j3,Sx)=>{"use strict";var{Writable:xb}=ue("stream"),mx=Lr(),{BINARY_TYPES:hb,EMPTY_BUFFER:_x,kStatusCode:pb,kWebSocket:gb}=$t(),{concat:xd,toArrayBuffer:mb,unmask:wb}=qi(),{isValidStatusCode:_b,isValidUTF8:yx}=Nr(),Co=Buffer[Symbol.species],dt=0,Ex=1,bx=2,vx=3,hd=4,pd=5,Ro=6,gd=class extends xb{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||hb[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[gb]=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=dt}_write(e,r,i){if(this._opcode===8&&this._state==dt)return i();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){i(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new Co(i.buffer,i.byteOffset+e,i.length-e),new Co(i.buffer,i.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let i=this._buffers[0],o=r.length-e;e>=i.length?r.set(this._buffers.shift(),o):(r.set(new Uint8Array(i.buffer,i.byteOffset,e),o),this._buffers[0]=new Co(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case dt:this.getInfo(e);break;case Ex:this.getPayloadLength16(e);break;case bx:this.getPayloadLength64(e);break;case vx:this.getMask();break;case hd:this.getData(e);break;case pd:case Ro:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if((r[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(r[0]&64)===64;if(i&&!this._extensions[mx.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=Ex:this._payloadLength===127?this._state=bx: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=vx:this._state=hd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=hd}getData(e){let r=_x;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&&wb(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=pd,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[mx.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===dt&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=dt;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=xd(i,r):this._binaryType==="arraybuffer"?o=mb(xd(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=dt):(this._state=Ro,setImmediate(()=>{this.emit("message",o,!0),this._state=dt,this.startLoop(e)}))}else{let o=xd(i,r);if(!this._skipUTF8Validation&&!yx(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===pd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=dt):(this._state=Ro,setImmediate(()=>{this.emit("message",o,!1),this._state=dt,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,_x),this.end();else{let i=e.readUInt16BE(0);if(!_b(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Co(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!yx(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=dt;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=dt):(this._state=Ro,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=dt,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[pb]=o,l}};Sx.exports=gd});var yd=ae((K3,Tx)=>{"use strict";var{Duplex:W3}=ue("stream"),{randomFillSync:yb}=ue("crypto"),{types:{isUint8Array:Eb}}=ue("util"),Ax=Lr(),{EMPTY_BUFFER:bb,kWebSocket:vb,NOOP:Sb}=$t(),{isBlob:Mr,isValidStatusCode:Ab}=Nr(),{mask:Ix,toBuffer:Hn}=qi(),lt=Symbol("kByteLength"),Ib=Buffer.alloc(4),ko=8*1024,jn,Br=ko,bt=0,Tb=1,Cb=2,wd=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=bt,this.onerror=Sb,this[vb]=void 0}static frame(e,r){let i,o=!1,c=2,l=!1;r.mask&&(i=r.maskBuffer||Ib,r.generateMask?r.generateMask(i):(Br===ko&&(jn===void 0&&(jn=Buffer.alloc(ko)),yb(jn,0,ko),Br=0),i[0]=jn[Br++],i[1]=jn[Br++],i[2]=jn[Br++],i[3]=jn[Br++]),l=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||l)&&r[lt]!==void 0?u=r[lt]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!l);let f=u;u>=65536?(c+=8,f=127):u>125&&(c+=2,f=126);let p=Buffer.allocUnsafe(o?u+c:c);return p[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(p[0]|=64),p[1]=f,f===126?p.writeUInt16BE(u,2):f===127&&(p[2]=p[3]=0,p.writeUIntBE(u,4,6)),r.mask?(p[1]|=128,p[c-4]=i[0],p[c-3]=i[1],p[c-2]=i[2],p[c-1]=i[3],l?[p,e]:o?(Ix(e,i,p,c,u),[p]):(Ix(e,i,e,0,u),[p,e])):[p,e]}close(e,r,i,o){let c;if(e===void 0)c=bb;else{if(typeof e!="number"||!Ab(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(r);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");if(c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof r=="string")c.write(r,2);else if(Eb(r))c.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let l={[lt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==bt?this.enqueue([this.dispatch,c,!1,l,o]):this.sendFrame(t.frame(c,l),o)}ping(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Mr(e)?(o=e.size,c=!1):(e=Hn(e),o=e.length,c=Hn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[lt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Mr(e)?this._state!==bt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==bt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}pong(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Mr(e)?(o=e.size,c=!1):(e=Hn(e),o=e.length,c=Hn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[lt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Mr(e)?this._state!==bt?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==bt?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}send(e,r,i){let o=this._extensions[Ax.extensionName],c=r.binary?2:1,l=r.compress,u,f;typeof e=="string"?(u=Buffer.byteLength(e),f=!1):Mr(e)?(u=e.size,f=!1):(e=Hn(e),u=e.length,f=Hn.readOnly),this._firstFragment?(this._firstFragment=!1,l&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(l=u>=o._threshold),this._compress=l):(l=!1,c=0),r.fin&&(this._firstFragment=!0);let p={[lt]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:f,rsv1:l};Mr(e)?this._state!==bt?this.enqueue([this.getBlobData,e,this._compress,p,i]):this.getBlobData(e,this._compress,p,i):this._state!==bt?this.enqueue([this.dispatch,e,this._compress,p,i]):this.dispatch(e,this._compress,p,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[lt],this._state=Cb,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(_d,this,u,o);return}this._bufferedBytes-=i[lt];let l=Hn(c);r?this.dispatch(l,r,i,o):(this._state=bt,this.sendFrame(t.frame(l,i),o),this.dequeue())}).catch(c=>{process.nextTick(Rb,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Ax.extensionName];this._bufferedBytes+=i[lt],this._state=Tb,c.compress(e,i.fin,(l,u)=>{if(this._socket.destroyed){let f=new Error("The socket was closed while data was being compressed");_d(this,f,o);return}this._bufferedBytes-=i[lt],this._state=bt,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===bt&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][lt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][lt],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};Tx.exports=wd;function _d(t,e,r){typeof r=="function"&&r(e);for(let i=0;i<t._queue.length;i++){let o=t._queue[i],c=o[o.length-1];typeof c=="function"&&c(e)}}function Rb(t,e,r){_d(t,e,r),t.onerror(e)}});var Mx=ae(($3,Nx)=>{"use strict";var{kForOnEventAttribute:ji,kListener:Ed}=$t(),Cx=Symbol("kCode"),Rx=Symbol("kData"),kx=Symbol("kError"),Dx=Symbol("kMessage"),Px=Symbol("kReason"),Fr=Symbol("kTarget"),Ox=Symbol("kType"),Lx=Symbol("kWasClean"),Jt=class{constructor(e){this[Fr]=null,this[Ox]=e}get target(){return this[Fr]}get type(){return this[Ox]}};Object.defineProperty(Jt.prototype,"target",{enumerable:!0});Object.defineProperty(Jt.prototype,"type",{enumerable:!0});var Wn=class extends Jt{constructor(e,r={}){super(e),this[Cx]=r.code===void 0?0:r.code,this[Px]=r.reason===void 0?"":r.reason,this[Lx]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Cx]}get reason(){return this[Px]}get wasClean(){return this[Lx]}};Object.defineProperty(Wn.prototype,"code",{enumerable:!0});Object.defineProperty(Wn.prototype,"reason",{enumerable:!0});Object.defineProperty(Wn.prototype,"wasClean",{enumerable:!0});var zr=class extends Jt{constructor(e,r={}){super(e),this[kx]=r.error===void 0?null:r.error,this[Dx]=r.message===void 0?"":r.message}get error(){return this[kx]}get message(){return this[Dx]}};Object.defineProperty(zr.prototype,"error",{enumerable:!0});Object.defineProperty(zr.prototype,"message",{enumerable:!0});var Wi=class extends Jt{constructor(e,r={}){super(e),this[Rx]=r.data===void 0?null:r.data}get data(){return this[Rx]}};Object.defineProperty(Wi.prototype,"data",{enumerable:!0});var kb={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[ji]&&o[Ed]===e&&!o[ji])return;let i;if(t==="message")i=function(c,l){let u=new Wi("message",{data:l?c:c.toString()});u[Fr]=this,Do(e,this,u)};else if(t==="close")i=function(c,l){let u=new Wn("close",{code:c,reason:l.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Fr]=this,Do(e,this,u)};else if(t==="error")i=function(c){let l=new zr("error",{error:c,message:c.message});l[Fr]=this,Do(e,this,l)};else if(t==="open")i=function(){let c=new Jt("open");c[Fr]=this,Do(e,this,c)};else return;i[ji]=!!r[ji],i[Ed]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[Ed]===e&&!r[ji]){this.removeListener(t,r);break}}};Nx.exports={CloseEvent:Wn,ErrorEvent:zr,Event:Jt,EventTarget:kb,MessageEvent:Wi};function Do(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Po=ae((V3,Bx)=>{"use strict";var{tokenChars:Ki}=Nr();function Lt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function Db(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,l,u,f=-1,p=-1,m=-1,b=0;for(;b<t.length;b++)if(p=t.charCodeAt(b),l===void 0)if(m===-1&&Ki[p]===1)f===-1&&(f=b);else if(b!==0&&(p===32||p===9))m===-1&&f!==-1&&(m=b);else if(p===59||p===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${b}`);m===-1&&(m=b);let y=t.slice(f,m);p===44?(Lt(e,y,r),r=Object.create(null)):l=y,f=m=-1}else throw new SyntaxError(`Unexpected character at index ${b}`);else if(u===void 0)if(m===-1&&Ki[p]===1)f===-1&&(f=b);else if(p===32||p===9)m===-1&&f!==-1&&(m=b);else if(p===59||p===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${b}`);m===-1&&(m=b),Lt(r,t.slice(f,m),!0),p===44&&(Lt(e,l,r),r=Object.create(null),l=void 0),f=m=-1}else if(p===61&&f!==-1&&m===-1)u=t.slice(f,b),f=m=-1;else throw new SyntaxError(`Unexpected character at index ${b}`);else if(o){if(Ki[p]!==1)throw new SyntaxError(`Unexpected character at index ${b}`);f===-1?f=b:i||(i=!0),o=!1}else if(c)if(Ki[p]===1)f===-1&&(f=b);else if(p===34&&f!==-1)c=!1,m=b;else if(p===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${b}`);else if(p===34&&t.charCodeAt(b-1)===61)c=!0;else if(m===-1&&Ki[p]===1)f===-1&&(f=b);else if(f!==-1&&(p===32||p===9))m===-1&&(m=b);else if(p===59||p===44){if(f===-1)throw new SyntaxError(`Unexpected character at index ${b}`);m===-1&&(m=b);let y=t.slice(f,m);i&&(y=y.replace(/\\/g,""),i=!1),Lt(r,u,y),p===44&&(Lt(e,l,r),r=Object.create(null),l=void 0),u=void 0,f=m=-1}else throw new SyntaxError(`Unexpected character at index ${b}`);if(f===-1||c||p===32||p===9)throw new SyntaxError("Unexpected end of input");m===-1&&(m=b);let A=t.slice(f,m);return l===void 0?Lt(e,A,r):(u===void 0?Lt(r,A,!0):i?Lt(r,u,A.replace(/\\/g,"")):Lt(r,u,A),Lt(e,l,r)),e}function Pb(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(", ")}Bx.exports={format:Pb,parse:Db}});var Mo=ae((Y3,Jx)=>{"use strict";var Ob=ue("events"),Lb=ue("https"),Nb=ue("http"),Ux=ue("net"),Mb=ue("tls"),{randomBytes:Bb,createHash:Fb}=ue("crypto"),{Duplex:J3,Readable:Z3}=ue("stream"),{URL:bd}=ue("url"),Sn=Lr(),zb=md(),Ub=yd(),{isBlob:Gb}=Nr(),{BINARY_TYPES:Fx,CLOSE_TIMEOUT:qb,EMPTY_BUFFER:Oo,GUID:Hb,kForOnEventAttribute:vd,kListener:jb,kStatusCode:Wb,kWebSocket:Ge,NOOP:Gx}=$t(),{EventTarget:{addEventListener:Kb,removeEventListener:$b}}=Mx(),{format:Vb,parse:Jb}=Po(),{toBuffer:Zb}=qi(),qx=Symbol("kAborted"),Sd=[8,13],Zt=["CONNECTING","OPEN","CLOSING","CLOSED"],Yb=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,ge=class t extends Ob{constructor(e,r,i){super(),this._binaryType=Fx[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Oo,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(i=r,r=[]):r=[r]),Hx(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Fx.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 zb({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 Ub(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[Ge]=this,c[Ge]=this,e[Ge]=this,o.on("conclude",ev),o.on("drain",tv),o.on("error",nv),o.on("message",rv),o.on("ping",iv),o.on("pong",sv),c.onerror=ov,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Kx),e.on("data",No),e.on("end",$x),e.on("error",Vx),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[Sn.extensionName]&&this._extensions[Sn.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){st(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),Wx(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){Ad(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Oo,r,i)}pong(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=r=void 0):typeof r=="function"&&(i=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ad(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Oo,r,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(i=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Ad(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[Sn.extensionName]||(o.compress=!1),this._sender.send(e||Oo,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){st(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(ge,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(ge.prototype,"CONNECTING",{enumerable:!0,value:Zt.indexOf("CONNECTING")});Object.defineProperty(ge,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(ge.prototype,"OPEN",{enumerable:!0,value:Zt.indexOf("OPEN")});Object.defineProperty(ge,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(ge.prototype,"CLOSING",{enumerable:!0,value:Zt.indexOf("CLOSING")});Object.defineProperty(ge,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});Object.defineProperty(ge.prototype,"CLOSED",{enumerable:!0,value:Zt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(ge.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(ge.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[vd])return e[jb];return null},set(e){for(let r of this.listeners(t))if(r[vd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[vd]:!0})}})});ge.prototype.addEventListener=Kb;ge.prototype.removeEventListener=$b;Jx.exports=ge;function Hx(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:qb,protocolVersion:Sd[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,!Sd.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Sd.join(", ")})`);let c;if(e instanceof bd)c=e;else try{c=new bd(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let l=c.protocol==="wss:",u=c.protocol==="ws+unix:",f;if(c.protocol!=="ws:"&&!l&&!u?f=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?f="The URL's pathname is empty":c.hash&&(f="The URL contains a fragment identifier"),f){let I=new SyntaxError(f);if(t._redirects===0)throw I;Lo(t,I);return}let p=l?443:80,m=Bb(16).toString("base64"),b=l?Lb.request:Nb.request,A=new Set,y;if(o.createConnection=o.createConnection||(l?Qb:Xb),o.defaultPort=o.defaultPort||p,o.port=c.port||p,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":m,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(y=new Sn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=Vb({[Sn.extensionName]:y.offer()})),r.length){for(let I of r){if(typeof I!="string"||!Yb.test(I)||A.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");A.add(I)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),u){let I=o.path.split(":");o.socketPath=I[0],o.path=I[1]}let S;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=l,t._originalHostOrSocketPath=u?o.socketPath:c.host;let I=i&&i.headers;if(i={...i,headers:{}},I)for(let[T,R]of Object.entries(I))i.headers[T.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&&!l)&&(delete o.headers.authorization,delete o.headers.cookie,I||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),S=t._req=b(o),t._redirects&&t.emit("redirect",t.url,S)}else S=t._req=b(o);o.timeout&&S.on("timeout",()=>{st(t,S,"Opening handshake has timed out")}),S.on("error",I=>{S===null||S[qx]||(S=t._req=null,Lo(t,I))}),S.on("response",I=>{let T=I.headers.location,R=I.statusCode;if(T&&o.followRedirects&&R>=300&&R<400){if(++t._redirects>o.maxRedirects){st(t,S,"Maximum redirects exceeded");return}S.abort();let D;try{D=new bd(T,e)}catch{let k=new SyntaxError(`Invalid URL: ${T}`);Lo(t,k);return}Hx(t,D,r,i)}else t.emit("unexpected-response",S,I)||st(t,S,`Unexpected server response: ${I.statusCode}`)}),S.on("upgrade",(I,T,R)=>{if(t.emit("upgrade",I),t.readyState!==ge.CONNECTING)return;S=t._req=null;let D=I.headers.upgrade;if(D===void 0||D.toLowerCase()!=="websocket"){st(t,T,"Invalid Upgrade header");return}let E=Fb("sha1").update(m+Hb).digest("base64");if(I.headers["sec-websocket-accept"]!==E){st(t,T,"Invalid Sec-WebSocket-Accept header");return}let k=I.headers["sec-websocket-protocol"],P;if(k!==void 0?A.size?A.has(k)||(P="Server sent an invalid subprotocol"):P="Server sent a subprotocol but none was requested":A.size&&(P="Server sent no subprotocol"),P){st(t,T,P);return}k&&(t._protocol=k);let F=I.headers["sec-websocket-extensions"];if(F!==void 0){if(!y){st(t,T,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let M;try{M=Jb(F)}catch{st(t,T,"Invalid Sec-WebSocket-Extensions header");return}let J=Object.keys(M);if(J.length!==1||J[0]!==Sn.extensionName){st(t,T,"Server indicated an extension that was not requested");return}try{y.accept(M[Sn.extensionName])}catch{st(t,T,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[Sn.extensionName]=y}t.setSocket(T,R,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(S,t):S.end()}function Lo(t,e){t._readyState=ge.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Xb(t){return t.path=t.socketPath,Ux.connect(t)}function Qb(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Ux.isIP(t.host)?"":t.host),Mb.connect(t)}function st(t,e,r){t._readyState=ge.CLOSING;let i=new Error(r);Error.captureStackTrace(i,st),e.setHeader?(e[qx]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Lo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Ad(t,e,r){if(e){let i=Gb(e)?e.size:Zb(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Zt[t.readyState]})`);process.nextTick(r,i)}}function ev(t,e){let r=this[Ge];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Ge]!==void 0&&(r._socket.removeListener("data",No),process.nextTick(jx,r._socket),t===1005?r.close():r.close(t,e))}function tv(){let t=this[Ge];t.isPaused||t._socket.resume()}function nv(t){let e=this[Ge];e._socket[Ge]!==void 0&&(e._socket.removeListener("data",No),process.nextTick(jx,e._socket),e.close(t[Wb])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function zx(){this[Ge].emitClose()}function rv(t,e){this[Ge].emit("message",t,e)}function iv(t){let e=this[Ge];e._autoPong&&e.pong(t,!this._isServer,Gx),e.emit("ping",t)}function sv(t){this[Ge].emit("pong",t)}function jx(t){t.resume()}function ov(t){let e=this[Ge];e.readyState!==ge.CLOSED&&(e.readyState===ge.OPEN&&(e._readyState=ge.CLOSING,Wx(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function Wx(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Kx(){let t=this[Ge];if(this.removeListener("close",Kx),this.removeListener("data",No),this.removeListener("end",$x),t._readyState=ge.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[Ge]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",zx),t._receiver.on("finish",zx))}function No(t){this[Ge]._receiver.write(t)||this.pause()}function $x(){let t=this[Ge];t._readyState=ge.CLOSING,t._receiver.end(),this.end()}function Vx(){let t=this[Ge];this.removeListener("error",Vx),this.on("error",Gx),t&&(t._readyState=ge.CLOSING,this.destroy())}});var Qx=ae((Q3,Xx)=>{"use strict";var X3=Mo(),{Duplex:av}=ue("stream");function Zx(t){t.emit("close")}function cv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Yx(t){this.removeListener("error",Yx),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function dv(t,e){let r=!0,i=new av({...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(Zx,i);return}let l=!1;t.once("error",function(f){l=!0,c(f)}),t.once("close",function(){l||c(o),process.nextTick(Zx,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",cv),i.on("error",Yx),i}Xx.exports=dv});var Id=ae((eR,eh)=>{"use strict";var{tokenChars:lv}=Nr();function uv(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&&lv[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}eh.exports={parse:uv}});var ah=ae((nR,oh)=>{"use strict";var fv=ue("events"),Bo=ue("http"),{Duplex:tR}=ue("stream"),{createHash:xv}=ue("crypto"),th=Po(),Kn=Lr(),hv=Id(),pv=Mo(),{CLOSE_TIMEOUT:gv,GUID:mv,kWebSocket:wv}=$t(),_v=/^[+/0-9A-Za-z]{22}==$/,nh=0,rh=1,sh=2,Td=class extends fv{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:gv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:pv,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=Bo.createServer((i,o)=>{let c=Bo.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=yv(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=nh}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===sh){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick($i,this);return}if(e&&this.once("close",e),this._state!==rh)if(this._state=rh,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick($i,this):process.nextTick($i,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{$i(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,o){r.on("error",ih);let c=e.headers["sec-websocket-key"],l=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){$n(this,e,r,405,"Invalid HTTP method");return}if(l===void 0||l.toLowerCase()!=="websocket"){$n(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!_v.test(c)){$n(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){$n(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Vi(r,400);return}let f=e.headers["sec-websocket-protocol"],p=new Set;if(f!==void 0)try{p=hv.parse(f)}catch{$n(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let m=e.headers["sec-websocket-extensions"],b={};if(this.options.perMessageDeflate&&m!==void 0){let A=new Kn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let y=th.parse(m);y[Kn.extensionName]&&(A.accept(y[Kn.extensionName]),b[Kn.extensionName]=A)}catch{$n(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let A={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(A,(y,S,I,T)=>{if(!y)return Vi(r,S||401,I,T);this.completeUpgrade(b,c,p,e,r,i,o)});return}if(!this.options.verifyClient(A))return Vi(r,401)}this.completeUpgrade(b,c,p,e,r,i,o)}completeUpgrade(e,r,i,o,c,l,u){if(!c.readable||!c.writable)return c.destroy();if(c[wv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>nh)return Vi(c,503);let p=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${xv("sha1").update(r+mv).digest("base64")}`],m=new this.options.WebSocket(null,void 0,this.options);if(i.size){let b=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;b&&(p.push(`Sec-WebSocket-Protocol: ${b}`),m._protocol=b)}if(e[Kn.extensionName]){let b=e[Kn.extensionName].params,A=th.format({[Kn.extensionName]:[b]});p.push(`Sec-WebSocket-Extensions: ${A}`),m._extensions=e}this.emit("headers",p,o),c.write(p.concat(`\r
|
|
10
|
+
`),this.stream=void 0;return}this.currentDate!==void 0&&rs(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 xg,mkdirSync as hg}from"node:fs";import{join as pg}from"node:path";function fl(t){let e=t.retentionDays??wg,r=t.clock??(()=>kn(new Date));ss={bridgeSink:new Jr(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new Jr(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();rs(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])rs(t.agentLogsDir(o),"agent",i,e)}function _g(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function xl(t){Ea=t}function hl(t){return nr[Ea]<=nr[t]}function pl(t,e){let r=nr[t];return r===void 0?!0:r>=nr[e]}function os(t){ul={...t}}function gl(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`${kn(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${l}`}function St(t,e,r,i,o){try{let c=`${JSON.stringify({ts:gl(new Date),level:e,module:r,msg:i,...o})}
|
|
11
|
+
`;hg(t,{recursive:!0}),xg(pg(t,tr("bridge",kn(new Date))),c)}catch{}}function yg(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function is(t,e,r,i,o){if(nr[t]<nr[Ea])return;let c=`${JSON.stringify({ts:gl(new Date),level:t,module:e,msg:r,...ul,...i})}
|
|
12
|
+
`;if(ss){let l=yg(o,i),u=l?_g(ss,l):ss.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?mg.write(c):gg.write(c)}function G(t,e){return{debug:(r,i)=>is("debug",t,r,i,e),info:(r,i)=>is("info",t,r,i,e),warn:(r,i)=>is("warn",t,r,i,e),error:(r,i)=>is("error",t,r,i,e),child:r=>G(`${t}.${r}`,e),forAgent:r=>G(t,r)}}var nr,Ea,gg,mg,ul,wg,ss,ne=Ze(()=>{"use strict";er();ba();nr={debug:10,info:20,warn:30,error:40},Ea=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),gg=process.stdout,mg=process.stderr,ul={},wg=We("COZE_BRIDGE_LOG_RETENTION_DAYS",30),ss=null});var k,Ke=Ze(()=>{"use strict";k=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 yl={};_a(yl,{ACP_WRAPPER_NPM_PACKAGES:()=>Zr,_resetAcpInstallerForTests:()=>Ag,_setBinaryPathCacheForTests:()=>Tg,buildAcpSpawn:()=>Xr,ensureAcpInstalled:()=>rr,getAcpBinaryPath:()=>as,pickWhichLine:()=>Ia,probeAcpVersion:()=>Ig,resolveAcpCommand:()=>_l});import{readFileSync as ml}from"node:fs";import{createRequire as bg}from"node:module";import{dirname as Eg,resolve as vg}from"node:path";function Ia(t){let e=t.split(/\r?\n/).map(i=>i.trim()).filter(Boolean);if(e.length===0)return;if(process.platform!=="win32")return e[0];let r=i=>e.find(o=>o.toLowerCase().endsWith(i));return r(".cmd")??r(".exe")??r(".bat")??r(".ps1")??e[0]}function Sg(t){let e=wl.resolve(`${t.npmPackage}/package.json`),r=Eg(e),i=JSON.parse(ml(e,"utf8")),o=typeof i.bin=="string"?i.bin:i.bin?.[t.binary];if(!o)throw new Error(`${t.npmPackage} package.json \u7F3A bin[${t.binary}]`);return vg(r,o)}async function rr(t,e){let r=Sa[t];if(!r)throw new k("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=Yr.get(t);if(i)return i;try{let o=Sg(r);return Yr.set(t,o),va.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw va.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:r.npmPackage,err:String(o)}),new k("AGENT_DEPENDENCY_INSTALL_FAILED",[`ACP wrapper \u672A\u5C31\u7EEA: ${r.npmPackage} (framework=${t})`,"\u8BE5 wrapper \u968F coze-bridge \u4E00\u8D77\u5B89\u88C5 (\u56FA\u5316\u5230 ~/.coze/bridge/lib/node_modules)\u3002","\u8BF7\u91CD\u8DD1 `coze-bridge pair` / `connect` \u89E6\u53D1\u56FA\u5316\u5B89\u88C5; \u82E5\u4ECD\u5931\u8D25, \u68C0\u67E5\u7F51\u7EDC / npm \u7F13\u5B58\u3002"].join(`
|
|
13
|
+
`),{cause:o})}}async function Ig(t){let e=Sa[t];if(e)try{let r=wl.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(ml(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){va.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function as(t){return Yr.get(t)}function _l(t,e){if(e)return e;let r=as(t);if(!r)throw new k("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return r}function Xr(t,e,r){if(e)return{command:e,args:[...r]};let i=_l(t);return{command:process.execPath,args:[i,...r]}}function Ag(){Yr.clear()}function Tg(t,e){Yr.set(t,e)}var va,Sa,Zr,wl,Yr,rn=Ze(()=>{"use strict";Ke();ne();va=G("agents.acp-installer"),Sa={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@zed-industries/codex-acp",binary:"codex-acp"}},Zr=Object.values(Sa).filter(t=>t!==void 0).map(t=>t.npmPackage),wl=bg(import.meta.url),Yr=new Map});import{chmod as Cg,mkdir as Rg,readFile as Dg,rename as vl,writeFile as Sl}from"node:fs/promises";import{dirname as Pg}from"node:path";async function ir(t){try{let e=await Dg(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function sr(t,e,r){await Rg(Pg(t),{recursive:!0});let i=`${JSON.stringify(e,null,2)}
|
|
14
|
+
`,o=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{r?.mode!==void 0?await Sl(o,i,{encoding:"utf8",mode:r.mode}):await Sl(o,i,"utf8"),await vl(o,t),r?.mode!==void 0&&await Cg(t,r.mode)}catch(c){await vl(o,o).catch(()=>{});let{rm:l}=await import("node:fs/promises");throw await l(o,{force:!0}).catch(()=>{}),c}}var Qr=Ze(()=>{"use strict"});import{promises as Il,readdirSync as Og}from"node:fs";import{homedir as Lg}from"node:os";import{sep as Ng,join as Te,resolve as Al}from"node:path";function Q(t){let e=t??Lg(),r=Te(e,".coze"),i=Te(r,"bridge"),o=Te(i,"lib"),c=Te(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:Te(o,"index.js"),binDir:Te(i,"bin"),pidFile:Te(i,"bridge.pid"),portFile:Te(i,"bridge.port"),tokenFile:Te(i,"bridge.token"),patTokenFile:Te(i,"pat-token"),agentEnvFile:Te(i,"agent-env.json"),logFile:Te(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Te(c,"daemon-stdio.log"),installLock:Te(i,"install.lock"),configFile:Te(i,"config.json"),agentsRoot:Te(r,"agents")}}function Xe(t,e=Q()){let r=Te(e.agentsRoot,t);return{root:r,config:Te(r,"config.json"),workspace:Te(r,"workspace"),logs:Te(r,"logs")}}function cs(t=Q()){try{return Og(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function ei(t,e){let r=await Il.realpath(Al(t)).catch(()=>null);if(!r)return!1;let i=await Il.realpath(Al(e)).catch(()=>null);if(!i)return!1;let o=process.platform==="win32"?r.toLowerCase():r,c=process.platform==="win32"?i.toLowerCase():i;return o===c||o.startsWith(c+Ng)}var Pe=Ze(()=>{"use strict"});var us={};_a(us,{AGENT_CONFIG_FILE_MODE:()=>ds,enforceAgentConfigMode:()=>Fg,loadAgentConfig:()=>Me,persistAgentSessions:()=>ti,persistAgentSkills:()=>ls,saveAgentConfig:()=>Qe});import{chmod as Mg,stat as Bg}from"node:fs/promises";function Me(t,e){return ir(Xe(t,e).config)}function Qe(t,e){return sr(Xe(t.agentId,e).config,t,{mode:ds})}async function Fg(t,e){if(process.platform==="win32")return;let r=Xe(t,e).config;try{let i=await Bg(r);if(!i.isFile())return;let o=i.mode&511;o!==ds&&(await Mg(r,ds),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 ti(t,e,r){let i=await Me(t,r);i&&(i.sessions=Object.fromEntries(e),await Qe(i,r))}async function ls(t,e,r){let i=await Me(t,r);i&&(i.skills=e,await Qe(i,r))}var Tl,ds,sn=Ze(()=>{"use strict";Qr();ne();Pe();Tl=G("agent-config"),ds=384});var ka=ae((C1,Rl)=>{Rl.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 xs=ae(Pl=>{var Dl={INVALID_LOC:"Invalid LOC header (bad signature)",INVALID_CEN:"Invalid CEN header (bad signature)",INVALID_END:"Invalid END header (bad signature)",DESCRIPTOR_NOT_EXIST:"No descriptor present",DESCRIPTOR_UNKNOWN:"Unknown descriptor format",DESCRIPTOR_FAULTY:"Descriptor data is malformed",NO_DATA:"Nothing to decompress",BAD_CRC:"CRC32 checksum failed {0}",FILE_IN_THE_WAY:"There is a file in the way: {0}",UNKNOWN_METHOD:"Invalid/unsupported compression method",AVAIL_DATA:"inflate::Available inflate data did not terminate",INVALID_DISTANCE:"inflate::Invalid literal/length or distance code in fixed or dynamic block",TO_MANY_CODES:"inflate::Dynamic block code description: too many length or distance codes",INVALID_REPEAT_LEN:"inflate::Dynamic block code description: repeat more than specified lengths",INVALID_REPEAT_FIRST:"inflate::Dynamic block code description: repeat lengths with no first length",INCOMPLETE_CODES:"inflate::Dynamic block code description: code lengths codes incomplete",INVALID_DYN_DISTANCE:"inflate::Dynamic block code description: invalid distance code lengths",INVALID_CODES_LEN:"inflate::Dynamic block code description: invalid literal/length code lengths",INVALID_STORE_BLOCK:"inflate::Stored block length did not match one's complement",INVALID_BLOCK_TYPE:"inflate::Invalid block type (type == 3)",CANT_EXTRACT_FILE:"Could not extract the file",CANT_OVERRIDE:"Target file already exists",DISK_ENTRY_TOO_LARGE:"Number of disk entries is too large",NO_ZIP:"No zip file was loaded",NO_ENTRY:"Entry doesn't exist",DIRECTORY_CONTENT_ERROR:"A directory cannot have content",FILE_NOT_FOUND:'File not found: "{0}"',NOT_IMPLEMENTED:"Not implemented",INVALID_FILENAME:"Invalid filename",INVALID_FORMAT:"Invalid or unsupported zip format. No END header found",INVALID_PASS_PARAM:"Incompatible password parameter",WRONG_PASSWORD:"Wrong Password",COMMENT_TOO_LONG:"Comment is too long",EXTRA_FIELD_PARSE_ERROR:"Extra field parsing error"};function qg(t){return function(...e){return e.length&&(t=t.replace(/\{(\d)\}/g,(r,i)=>e[i]||"")),new Error("ADM-ZIP: "+t)}}for(let t of Object.keys(Dl))Pl[t]=qg(Dl[t])});var Bl=ae((D1,Ml)=>{var Wg=ue("fs"),Oe=ue("path"),Ol=ka(),Kg=xs(),$g=typeof process=="object"&&process.platform==="win32",Ll=t=>typeof t=="object"&&t!==null,Nl=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function Ee(t){this.sep=Oe.sep,this.fs=Wg,Ll(t)&&Ll(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Ml.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 Kg.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=Oe.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=Oe.dirname(t);c.fs.exists(h,function(m){m||c.makeDir(h),c.fs.open(t,"w",438,function(E,I){E?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(y,v){c.fs.write(v,e,0,e.length,0,function(){c.fs.close(v,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):I?c.fs.write(I,e,0,e.length,0,function(){c.fs.close(I,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};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=Oe.join(i,u),h=e.fs.statSync(x);(!o||o.test(x))&&l.push(Oe.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=Oe.join(t,u),r.fs.stat(u,function(x,h){if(x)return e(x);h&&(i.push(Oe.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 Nl[(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 Ol.STORED:return"STORED ("+t+")";case Ol.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Ee.canonical=function(t){if(!t)return"";let e=Oe.posix.normalize("/"+t.split("\\").join("/"));return Oe.join(".",e)};Ee.zipnamefix=function(t){if(!t)return"";let e=Oe.posix.normalize("/"+t.split("\\").join("/"));return Oe.posix.join(".",e)};Ee.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let r=t.length>>>0;for(let i=r-1;i>=0;i--)if(e(t[i],i,t))return t[i]};Ee.sanitize=function(t,e){t=Oe.resolve(Oe.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Oe.normalize(Oe.join(t,r.slice(i,o).join(Oe.sep)));if(c.indexOf(t)===0)return c}return Oe.normalize(Oe.join(t,Oe.basename(e)))};Ee.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};Ee.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};Ee.fromDOS2Date=function(t){return new Date((t>>25&127)+1980,Math.max((t>>21&15)-1,0),Math.max(t>>16&31,1),t>>11&31,t>>5&63,(t&31)<<1)};Ee.fromDate2DOS=function(t){let e=0,r=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),r=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|r};Ee.isWin=$g;Ee.crcTable=Nl});var zl=ae((P1,Fl)=>{var Vg=ue("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=Vg.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=ae((O1,Ul)=>{Ul.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var cr=ae((L1,ar)=>{ar.exports=Bl();ar.exports.Constants=ka();ar.exports.Errors=xs();ar.exports.FileAttr=zl();ar.exports.decoder=Gl()});var jl=ae((N1,Hl)=>{var on=cr(),z=on.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,I=0,y=0,v=0;t|=on.isWin?2560:768,r|=z.FLG_EFS;let A={extraLen:0},T=b=>Math.max(0,b)>>>0,C=b=>Math.max(0,b)&65535,P=b=>Math.max(0,b)&255;return o=on.fromDate2DOS(new Date),{get made(){return t},set made(b){t=b},get version(){return e},set version(b){e=b},get flags(){return r},set flags(b){r=b},get flags_efs(){return(r&z.FLG_EFS)>0},set flags_efs(b){b?r|=z.FLG_EFS:r&=~z.FLG_EFS},get flags_desc(){return(r&z.FLG_DESC)>0},set flags_desc(b){b?r|=z.FLG_DESC:r&=~z.FLG_DESC},get method(){return i},set method(b){switch(b){case z.STORED:this.version=10;case z.DEFLATED:default:this.version=20}i=b},get time(){return on.fromDOS2Date(this.timeval)},set time(b){b=new Date(b),this.timeval=on.fromDate2DOS(b)},get timeval(){return o},set timeval(b){o=T(b)},get timeHighByte(){return P(o>>>8)},get crc(){return c},set crc(b){c=T(b)},get compressedSize(){return l},set compressedSize(b){l=T(b)},get size(){return u},set size(b){u=T(b)},get fileNameLength(){return x},set fileNameLength(b){x=b},get extraLength(){return h},set extraLength(b){h=b},get extraLocalLength(){return A.extraLen},set extraLocalLength(b){A.extraLen=b},get commentLength(){return m},set commentLength(b){m=b},get diskNumStart(){return E},set diskNumStart(b){E=T(b)},get inAttr(){return I},set inAttr(b){I=T(b)},get attr(){return y},set attr(b){y=T(b)},get fileAttr(){return(y||0)>>16&4095},get offset(){return v},set offset(b){v=T(b)},get encrypted(){return(r&z.FLG_ENC)===z.FLG_ENC},get centralHeaderSize(){return z.CENHDR+x+h+m},get realDataOffset(){return v+z.LOCHDR+A.fnameLen+A.extraLen},get localHeader(){return A},loadLocalHeaderFromBinary:function(b){var R=b.slice(v,v+z.LOCHDR);if(R.readUInt32LE(0)!==z.LOCSIG)throw on.Errors.INVALID_LOC();A.version=R.readUInt16LE(z.LOCVER),A.flags=R.readUInt16LE(z.LOCFLG),A.flags_desc=(A.flags&z.FLG_DESC)>0,A.method=R.readUInt16LE(z.LOCHOW),A.time=R.readUInt32LE(z.LOCTIM),A.crc=R.readUInt32LE(z.LOCCRC),A.compressedSize=R.readUInt32LE(z.LOCSIZ),A.size=R.readUInt32LE(z.LOCLEN),A.fnameLen=R.readUInt16LE(z.LOCNAM),A.extraLen=R.readUInt16LE(z.LOCEXT);let O=v+z.LOCHDR+A.fnameLen,F=O+A.extraLen;return b.slice(O,F)},loadFromBinary:function(b){if(b.length!==z.CENHDR||b.readUInt32LE(0)!==z.CENSIG)throw on.Errors.INVALID_CEN();t=b.readUInt16LE(z.CENVEM),e=b.readUInt16LE(z.CENVER),r=b.readUInt16LE(z.CENFLG),i=b.readUInt16LE(z.CENHOW),o=b.readUInt32LE(z.CENTIM),c=b.readUInt32LE(z.CENCRC),l=b.readUInt32LE(z.CENSIZ),u=b.readUInt32LE(z.CENLEN),x=b.readUInt16LE(z.CENNAM),h=b.readUInt16LE(z.CENEXT),m=b.readUInt16LE(z.CENCOM),E=b.readUInt16LE(z.CENDSK),I=b.readUInt16LE(z.CENATT),y=b.readUInt32LE(z.CENATX),v=b.readUInt32LE(z.CENOFF)},localHeaderToBinary:function(){var b=Buffer.alloc(z.LOCHDR);return b.writeUInt32LE(z.LOCSIG,0),b.writeUInt16LE(e,z.LOCVER),b.writeUInt16LE(r,z.LOCFLG),b.writeUInt16LE(i,z.LOCHOW),b.writeUInt32LE(o,z.LOCTIM),b.writeUInt32LE(c,z.LOCCRC),b.writeUInt32LE(l,z.LOCSIZ),b.writeUInt32LE(u,z.LOCLEN),b.writeUInt16LE(x,z.LOCNAM),b.writeUInt16LE(A.extraLen,z.LOCEXT),b},centralHeaderToBinary:function(){var b=Buffer.alloc(z.CENHDR+x+h+m);return b.writeUInt32LE(z.CENSIG,0),b.writeUInt16LE(t,z.CENVEM),b.writeUInt16LE(e,z.CENVER),b.writeUInt16LE(r,z.CENFLG),b.writeUInt16LE(i,z.CENHOW),b.writeUInt32LE(o,z.CENTIM),b.writeUInt32LE(c,z.CENCRC),b.writeUInt32LE(l,z.CENSIZ),b.writeUInt32LE(u,z.CENLEN),b.writeUInt16LE(x,z.CENNAM),b.writeUInt16LE(h,z.CENEXT),b.writeUInt16LE(m,z.CENCOM),b.writeUInt16LE(E,z.CENDSK),b.writeUInt16LE(I,z.CENATT),b.writeUInt32LE(y,z.CENATX),b.writeUInt32LE(v,z.CENOFF),b},toJSON:function(){let b=function(R){return R+" bytes"};return{made:t,version:e,flags:r,method:on.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:b(l),size:b(u),fileNameLength:b(x),extraLength:b(h),commentLength:b(m),diskNumStart:E,inAttr:I,attr:y,offset:v,centralHeaderSize:b(z.CENHDR+x+h+m)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Wl=ae((M1,ql)=>{var dr=cr(),_e=dr.Constants;ql.exports=function(){var t=0,e=0,r=0,i=0,o=0;return{get diskEntries(){return t},set diskEntries(c){t=e=c},get totalEntries(){return e},set totalEntries(c){e=t=c},get size(){return r},set size(c){r=c},get offset(){return i},set offset(c){i=c},get commentLength(){return o},set commentLength(c){o=c},get mainHeaderSize(){return _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 dr.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=dr.readBigUInt64LE(c,_e.ZIP64SUB),e=dr.readBigUInt64LE(c,_e.ZIP64TOT),r=dr.readBigUInt64LE(c,_e.ZIP64SIZE),i=dr.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 Ra=ae(Ca=>{Ca.EntryHeader=jl();Ca.MainHeader=Wl()});var $l=ae((F1,Kl)=>{Kl.exports=function(t){var e=ue("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=ae((z1,Vl)=>{var Jg=+(process.versions?process.versions.node:"").split(".")[0]||0;Vl.exports=function(t,e){var r=ue("zlib");let i=Jg>=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 eu=ae((U1,Ql)=>{"use strict";var{randomFillSync:Yl}=ue("crypto"),Yg=xs(),Zg=new Uint32Array(256).map((t,e)=>{for(let r=0;r<8;r++)(e&1)!==0?e=e>>>1^3988292384:e>>>=1;return e>>>0}),Xl=(t,e)=>Math.imul(t,e)>>>0,Zl=(t,e)=>Zg[(t^e)&255]^t>>>8,ni=()=>typeof Yl=="function"?Yl(Buffer.alloc(12)):ni.node();ni.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 hs={genSalt:ni};function ps(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])}ps.prototype.updateKeys=function(t){let e=this.keys;return e[0]=Zl(e[0],t),e[1]+=e[0]&255,e[1]=Xl(e[1],134775813)+1,e[2]=Zl(e[2],e[1]>>>24),t};ps.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return Xl(t,t^1)>>8&255};function Xg(t){let e=new ps(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 Qg(t){let e=new ps(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 em(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Xg(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Yg.WRONG_PASSWORD();return i(t.slice(12))}function tm(t){Buffer.isBuffer(t)&&t.length>=12?hs.genSalt=function(){return t.slice(0,12)}:t==="node"?hs.genSalt=ni.node:hs.genSalt=ni}function nm(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Qg(r),c=hs.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)}Ql.exports={decrypt:em,encrypt:nm,_salter:tm}});var tu=ae(gs=>{gs.Deflater=$l();gs.Inflater=Jl();gs.ZipCrypto=eu()});var Pa=ae((H1,nu)=>{var ce=cr(),rm=Ra(),ve=ce.Constants,Da=tu();nu.exports=function(t,e){var r=new rm.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:ce.decoder;h=E.hasOwnProperty("efs")?E.efs:!1;function I(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(x=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function y(b){if(!r.flags_desc&&!r.localHeader.flags_desc){if(ce.crc32(b)!==r.localHeader.crc)return!1}else{let R={},O=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(O)==ve.LOCSIG||e.readUInt32LE(O)==ve.CENSIG)throw ce.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(O)==ve.EXTSIG)R.crc=e.readUInt32LE(O+ve.EXTCRC),R.compressedSize=e.readUInt32LE(O+ve.EXTSIZ),R.size=e.readUInt32LE(O+ve.EXTLEN);else if(e.readUInt16LE(O+12)===19280)R.crc=e.readUInt32LE(O+ve.EXTCRC-4),R.compressedSize=e.readUInt32LE(O+ve.EXTSIZ-4),R.size=e.readUInt32LE(O+ve.EXTLEN-4);else throw ce.Errors.DESCRIPTOR_UNKNOWN();if(R.compressedSize!==r.compressedSize||R.size!==r.size||R.crc!==r.crc)throw ce.Errors.DESCRIPTOR_FAULTY();if(ce.crc32(b)!==R.crc)return!1}return!0}function v(b,R,O){if(typeof R>"u"&&typeof b=="string"&&(O=b,b=void 0),c)return b&&R&&R(Buffer.alloc(0),ce.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var F=I();if(F.length===0)return b&&R&&R(F),F;if(r.encrypted){if(typeof O!="string"&&!Buffer.isBuffer(O))throw ce.Errors.INVALID_PASS_PARAM();F=Da.ZipCrypto.decrypt(F,r,O)}var B=Buffer.alloc(r.size);switch(r.method){case ce.Constants.STORED:if(F.copy(B),y(B))return b&&R&&R(B),B;throw b&&R&&R(B,ce.Errors.BAD_CRC()),ce.Errors.BAD_CRC();case ce.Constants.DEFLATED:var Y=new Da.Inflater(F,r.size);if(b)Y.inflateAsync(function($){$.copy($,0),R&&(y($)?R($):R($,ce.Errors.BAD_CRC()))});else{if(Y.inflate(B).copy(B,0),!y(B))throw ce.Errors.BAD_CRC(`"${E.decode(i)}"`);return B}break;default:throw b&&R&&R(Buffer.alloc(0),ce.Errors.UNKNOWN_METHOD()),ce.Errors.UNKNOWN_METHOD()}}function A(b,R){if((!l||!l.length)&&Buffer.isBuffer(e))return b&&R&&R(I()),I();if(l.length&&!c){var O;switch(r.method){case ce.Constants.STORED:return r.compressedSize=r.size,O=Buffer.alloc(l.length),l.copy(O),b&&R&&R(O),O;default:case ce.Constants.DEFLATED:var F=new Da.Deflater(l);if(b)F.deflateAsync(function(Y){O=Buffer.alloc(Y.length),r.compressedSize=Y.length,Y.copy(O),R&&R(O)});else{var B=F.deflate();return r.compressedSize=B.length,B}F=null;break}}else if(b&&R)R(Buffer.alloc(0));else return Buffer.alloc(0)}function T(b,R){return ce.readBigUInt64LE(b,R)}function C(b){try{for(var R=0,O,F,B;R+4<b.length;)O=b.readUInt16LE(R),R+=2,F=b.readUInt16LE(R),R+=2,B=b.slice(R,R+F),R+=F,ve.ID_ZIP64===O&&P(B)}catch{throw ce.Errors.EXTRA_FIELD_PARSE_ERROR()}}function P(b){var R,O,F,B;b.length>=ve.EF_ZIP64_SCOMP&&(R=T(b,ve.EF_ZIP64_SUNCOMP),r.size===ve.EF_ZIP64_OR_32&&(r.size=R)),b.length>=ve.EF_ZIP64_RHO&&(O=T(b,ve.EF_ZIP64_SCOMP),r.compressedSize===ve.EF_ZIP64_OR_32&&(r.compressedSize=O)),b.length>=ve.EF_ZIP64_DSN&&(F=T(b,ve.EF_ZIP64_RHO),r.offset===ve.EF_ZIP64_OR_32&&(r.offset=F)),b.length>=ve.EF_ZIP64_DSN+4&&(B=b.readUInt32LE(ve.EF_ZIP64_DSN),r.diskNumStart===ve.EF_ZIP64_OR_16&&(r.diskNumStart=B))}return{get entryName(){return E.decode(i)},get rawEntryName(){return i},set entryName(b){i=ce.toBuffer(b,E.encode);var R=i[i.length-1];c=R===47||R===92,r.fileNameLength=i.length},get efs(){return typeof h=="function"?h(this.entryName):h},get extra(){return u},set extra(b){u=b,r.extraLength=b.length,C(b)},get comment(){return E.decode(o)},set comment(b){if(o=ce.toBuffer(b,E.encode),r.commentLength=o.length,o.length>65535)throw ce.Errors.COMMENT_TOO_LONG()},get name(){var b=E.decode(i);return c?b.substr(b.length-1).split("/").pop():b.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return A(!1,null)},getCompressedDataAsync:function(b){A(!0,b)},setData:function(b){l=ce.toBuffer(b,ce.decoder.encode),!c&&l.length?(r.size=l.length,r.method=ce.Constants.DEFLATED,r.crc=ce.crc32(b),r.changed=!0):r.method=ce.Constants.STORED},getData:function(b){return r.changed?l:v(!1,null,b)},getDataAsync:function(b,R){r.changed?b(l):v(!0,b,R)},set attr(b){r.attr=b},get attr(){return r.attr},set header(b){r.loadFromBinary(b)},get header(){return r},packCentralHeader:function(){r.flags_efs=this.efs,r.extraLength=u.length;var b=r.centralHeaderToBinary(),R=ce.Constants.CENHDR;return i.copy(b,R),R+=i.length,u.copy(b,R),R+=r.extraLength,o.copy(b,R),b},packLocalHeader:function(){let b=0;r.flags_efs=this.efs,r.extraLocalLength=x.length;let R=r.localHeaderToBinary(),O=Buffer.alloc(R.length+i.length+r.extraLocalLength);return R.copy(O,b),b+=R.length,i.copy(O,b),b+=i.length,x.copy(O,b),b+=x.length,O},toJSON:function(){let b=function(R){return"<"+(R&&R.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:b(e),data:b(l)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var su=ae((j1,iu)=>{var ru=Pa(),im=Ra(),qe=cr();iu.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new im.MainHeader,l=!1,u=null;let x=new Set,h=e,{noSort:m,decoder:E}=h;t?v(h.readEntries):l=!0;function I(){let T=new Set;for(let C of Object.keys(i)){let P=C.split("/");if(P.pop(),!!P.length)for(let b=0;b<P.length;b++){let R=P.slice(0,b+1).join("/")+"/";T.add(R)}}for(let C of T)if(!(C in i)){let P=new ru(h);P.entryName=C,P.attr=16,P.temporary=!0,r.push(P),i[P.entryName]=P,x.add(P)}}function y(){if(l=!0,i={},c.diskEntries>(t.length-c.offset)/qe.Constants.CENHDR)throw qe.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var T=c.offset,C=0;C<r.length;C++){var P=T,b=new ru(h,t);b.header=t.slice(P,P+=qe.Constants.CENHDR),b.entryName=t.slice(P,P+=b.header.fileNameLength),b.header.extraLength&&(b.extra=t.slice(P,P+=b.header.extraLength)),b.header.commentLength&&(b.comment=t.slice(P,P+b.header.commentLength)),T+=b.header.centralHeaderSize,r[C]=b,i[b.entryName]=b}x.clear(),I()}function v(T){var C=t.length-qe.Constants.ENDHDR,P=Math.max(0,C-65535),b=P,R=t.length,O=-1,F=0;for(typeof h.trailingSpace=="boolean"&&h.trailingSpace&&(P=0),C;C>=b;C--)if(t[C]===80){if(t.readUInt32LE(C)===qe.Constants.ENDSIG){O=C,F=C,R=C+qe.Constants.ENDHDR,b=C-qe.Constants.END64HDR;continue}if(t.readUInt32LE(C)===qe.Constants.END64SIG){b=P;continue}if(t.readUInt32LE(C)===qe.Constants.ZIP64SIG){O=C,R=C+qe.readBigUInt64LE(t,C+qe.Constants.ZIP64SIZE)+qe.Constants.ZIP64LEAD;break}}if(O==-1)throw qe.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(O,R)),c.commentLength&&(o=t.slice(F+qe.Constants.ENDHDR)),T&&y()}function A(){r.length>1&&!m&&r.sort((T,C)=>T.entryName.toLowerCase().localeCompare(C.entryName.toLowerCase()))}return{get entries(){return l||y(),r.filter(T=>!x.has(T))},get comment(){return E.decode(o)},set comment(T){o=qe.toBuffer(T,E.encode),c.commentLength=o.length},getEntryCount:function(){return l?r.length:c.diskEntries},forEach:function(T){this.entries.forEach(T)},getEntry:function(T){return l||y(),i[T]||null},setEntry:function(T){l||y(),r.push(T),i[T.entryName]=T,c.totalEntries=r.length},deleteFile:function(T,C=!0){l||y();let P=i[T];this.getEntryChildren(P,C).map(R=>R.entryName).forEach(this.deleteEntry)},deleteEntry:function(T){l||y();let C=i[T],P=r.indexOf(C);P>=0&&(r.splice(P,1),delete i[T],c.totalEntries=r.length)},getEntryChildren:function(T,C=!0){if(l||y(),typeof T=="object")if(T.isDirectory&&C){let P=[],b=T.entryName;for(let R of r)R.entryName.startsWith(b)&&P.push(R);return P}else return[T];return[]},getChildCount:function(T){if(T&&T.isDirectory){let C=this.getEntryChildren(T);return C.includes(T)?C.length-1:C.length}return 0},compressToBuffer:function(){l||y(),A();let T=[],C=[],P=0,b=0;c.size=0,c.offset=0;let R=0;for(let B of this.entries){let Y=B.getCompressedData();B.header.offset=b;let $=B.packLocalHeader(),te=$.length+Y.length;b+=te,T.push($),T.push(Y);let Z=B.packCentralHeader();C.push(Z),c.size+=Z.length,P+=te+Z.length,R++}P+=c.mainHeaderSize,c.offset=b,c.totalEntries=R,b=0;let O=Buffer.alloc(P);for(let B of T)B.copy(O,b),b+=B.length;for(let B of C)B.copy(O,b),b+=B.length;let F=c.toBinary();return o&&o.copy(F,qe.Constants.ENDHDR),F.copy(O,b),t=O,l=!1,O},toAsyncBuffer:function(T,C,P,b){try{l||y(),A();let R=[],O=[],F=0,B=0,Y=0;c.size=0,c.offset=0;let $=function(te){if(te.length>0){let Z=te.shift(),ie=Z.entryName+Z.extra.toString();P&&P(ie),Z.getCompressedDataAsync(function(oe){b&&b(ie),Z.header.offset=B;let L=Z.packLocalHeader(),H=L.length+oe.length;B+=H,R.push(L),R.push(oe);let W=Z.packCentralHeader();O.push(W),c.size+=W.length,F+=H+W.length,Y++,$(te)})}else{F+=c.mainHeaderSize,c.offset=B,c.totalEntries=Y,B=0;let Z=Buffer.alloc(F);R.forEach(function(oe){oe.copy(Z,B),B+=oe.length}),O.forEach(function(oe){oe.copy(Z,B),B+=oe.length});let ie=c.toBinary();o&&o.copy(ie,qe.Constants.ENDHDR),ie.copy(Z,B),t=Z,l=!1,T(Z)}};$(Array.from(this.entries))}catch(R){C(R)}}}}});var cu=ae((q1,au)=>{var be=cr(),ye=ue("path"),sm=Pa(),om=su(),Cn=(...t)=>be.findLast(t,e=>typeof e=="boolean"),ou=(...t)=>be.findLast(t,e=>typeof e=="string"),am=(...t)=>be.findLast(t,e=>typeof e=="function"),cm={noSort:!1,readEntries:!1,method:be.Constants.NONE,fs:null};au.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),cm);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 om(r,i),{canonical:l,sanitize:u,zipnamefix:x}=be;function h(y){if(y&&c){var v;if(typeof y=="string"&&(v=c.getEntry(ye.posix.normalize(y))),typeof y=="object"&&typeof y.entryName<"u"&&typeof y.header<"u"&&(v=c.getEntry(y.entryName)),v)return v}return null}function m(y){let{join:v,normalize:A,sep:T}=ye.posix;return v(ye.isAbsolute(y)?"/":".",A(T+y.split("\\").join(T)+T))}function E(y){return y instanceof RegExp?(function(v){return function(A){return v.test(A)}})(y):typeof y!="function"?()=>!0:y}let I=(y,v)=>{let A=v.slice(-1);return A=A===o.sep?o.sep:"",ye.relative(y,v)+A};return{readFile:function(y,v){var A=h(y);return A&&A.getData(v)||null},childCount:function(y){let v=h(y);if(v)return c.getChildCount(v)},readFileAsync:function(y,v){var A=h(y);A?A.getDataAsync(v):v(null,"getEntry failed for:"+y)},readAsText:function(y,v){var A=h(y);if(A){var T=A.getData();if(T&&T.length)return T.toString(v||"utf8")}return""},readAsTextAsync:function(y,v,A){var T=h(y);T?T.getDataAsync(function(C,P){if(P){v(C,P);return}C&&C.length?v(C.toString(A||"utf8")):v("")}):v("")},deleteFile:function(y,v=!0){var A=h(y);A&&c.deleteFile(A.entryName,v)},deleteEntry:function(y){var v=h(y);v&&c.deleteEntry(v.entryName)},addZipComment:function(y){c.comment=y},getZipComment:function(){return c.comment||""},addZipEntryComment:function(y,v){var A=h(y);A&&(A.comment=v)},getZipEntryComment:function(y){var v=h(y);return v&&v.comment||""},updateFile:function(y,v){var A=h(y);A&&A.setData(v)},addLocalFile:function(y,v,A,T){if(o.fs.existsSync(y)){v=v?m(v):"";let C=ye.win32.basename(ye.win32.normalize(y));v+=A||C;let P=o.fs.statSync(y),b=P.isFile()?o.fs.readFileSync(y):Buffer.alloc(0);P.isDirectory()&&(v+=o.sep),this.addFile(v,b,T,P)}else throw be.Errors.FILE_NOT_FOUND(y)},addLocalFileAsync:function(y,v){y=typeof y=="object"?y:{localPath:y};let A=ye.resolve(y.localPath),{comment:T}=y,{zipPath:C,zipName:P}=y,b=this;o.fs.stat(A,function(R,O){if(R)return v(R,!1);C=C?m(C):"";let F=ye.win32.basename(ye.win32.normalize(A));if(C+=P||F,O.isFile())o.fs.readFile(A,function(B,Y){return B?v(B,!1):(b.addFile(C,Y,T,O),setImmediate(v,void 0,!0))});else if(O.isDirectory())return C+=o.sep,b.addFile(C,Buffer.alloc(0),T,O),setImmediate(v,void 0,!0)})},addLocalFolder:function(y,v,A){if(A=E(A),v=v?m(v):"",y=ye.normalize(y),o.fs.existsSync(y)){let T=o.findFiles(y),C=this;if(T.length)for(let P of T){let b=ye.join(v,I(y,P));A(b)&&C.addLocalFile(P,ye.dirname(b))}}else throw be.Errors.FILE_NOT_FOUND(y)},addLocalFolderAsync:function(y,v,A,T){T=E(T),A=A?m(A):"",y=ye.normalize(y);var C=this;o.fs.open(y,"r",function(P){if(P&&P.code==="ENOENT")v(void 0,be.Errors.FILE_NOT_FOUND(y));else if(P)v(void 0,P);else{var b=o.findFiles(y),R=-1,O=function(){if(R+=1,R<b.length){var F=b[R],B=I(y,F).split("\\").join("/");B=B.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),T(B)?o.fs.stat(F,function(Y,$){Y&&v(void 0,Y),$.isFile()?o.fs.readFile(F,function(te,Z){te?v(void 0,te):(C.addFile(A+B,Z,"",$),O())}):(C.addFile(A+B+"/",Buffer.alloc(0),"",$),O())}):process.nextTick(()=>{O()})}else v(!0,void 0)};O()}})},addLocalFolderAsync2:function(y,v){let A=this;y=typeof y=="object"?y:{localPath:y},localPath=ye.resolve(m(y.localPath));let{zipPath:T,filter:C,namefix:P}=y;C instanceof RegExp?C=(function(O){return function(F){return O.test(F)}})(C):typeof C!="function"&&(C=function(){return!0}),T=T?m(T):"",P=="latin1"&&(P=O=>O.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof P!="function"&&(P=O=>O);let b=O=>ye.join(T,P(I(localPath,O))),R=O=>ye.win32.basename(ye.win32.normalize(P(O)));o.fs.open(localPath,"r",function(O){O&&O.code==="ENOENT"?v(void 0,be.Errors.FILE_NOT_FOUND(localPath)):O?v(void 0,O):o.findFilesAsync(localPath,function(F,B){if(F)return v(F);B=B.filter(Y=>C(b(Y))),B.length||v(void 0,!1),setImmediate(B.reverse().reduce(function(Y,$){return function(te,Z){if(te||Z===!1)return setImmediate(Y,te,!1);A.addLocalFileAsync({localPath:$,zipPath:ye.dirname(b($)),zipName:R($)},Y)}},v))})})},addLocalFolderPromise:function(y,v){return new Promise((A,T)=>{this.addLocalFolderAsync2(Object.assign({localPath:y},v),(C,P)=>{C&&T(C),P&&A(this)})})},addFile:function(y,v,A,T){y=x(y);let C=h(y),P=C!=null;P||(C=new sm(i),C.entryName=y),C.comment=A||"";let b=typeof T=="object"&&T instanceof o.fs.Stats;b&&(C.header.time=T.mtime);var R=C.isDirectory?16:0;let O=C.isDirectory?16384:32768;return b?O|=4095&T.mode:typeof T=="number"?O|=4095&T:O|=C.isDirectory?493:420,R=(R|O<<16)>>>0,C.attr=R,C.setData(v),P||c.setEntry(C),C},getEntries:function(y){return c.password=y,c?c.entries:[]},getEntry:function(y){return h(y)},getEntryCount:function(){return c.getEntryCount()},forEach:function(y){return c.forEach(y)},extractEntryTo:function(y,v,A,T,C,P){T=Cn(!1,T),C=Cn(!1,C),A=Cn(!0,A),P=ou(C,P);var b=h(y);if(!b)throw be.Errors.NO_ENTRY();var R=l(b.entryName),O=u(v,P&&!b.isDirectory?P:A?R:ye.basename(R));if(b.isDirectory){var F=c.getEntryChildren(b);return F.forEach(function($){if($.isDirectory)return;var te=$.getData();if(!te)throw be.Errors.CANT_EXTRACT_FILE();var Z=l($.entryName),ie=u(v,A?Z:ye.basename(Z));let oe=C?$.header.fileAttr:void 0;o.writeFileTo(ie,te,T,oe)}),!0}var B=b.getData(c.password);if(!B)throw be.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(O)&&!T)throw be.Errors.CANT_OVERRIDE();let Y=C?y.header.fileAttr:void 0;return o.writeFileTo(O,B,T,Y),!0},test:function(y){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var A=c.entries[v].getData(y);if(!A)return!1}catch{return!1}return!0},extractAllTo:function(y,v,A,T){if(A=Cn(!1,A),T=ou(A,T),v=Cn(!1,v),!c)throw be.Errors.NO_ZIP();c.entries.forEach(function(C){var P=u(y,l(C.entryName));if(C.isDirectory){o.makeDir(P);return}var b=C.getData(T);if(!b)throw be.Errors.CANT_EXTRACT_FILE();let R=A?C.header.fileAttr:void 0;o.writeFileTo(P,b,v,R);try{o.fs.utimesSync(P,C.header.time,C.header.time)}catch{throw be.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(y,v,A,T){if(T=am(v,A,T),A=Cn(!1,A),v=Cn(!1,v),!T)return new Promise((O,F)=>{this.extractAllToAsync(y,v,A,function(B){B?F(B):O(this)})});if(!c){T(be.Errors.NO_ZIP());return}y=ye.resolve(y);let C=O=>u(y,ye.normalize(l(O.entryName))),P=(O,F)=>new Error(O+': "'+F+'"'),b=[],R=[];c.entries.forEach(O=>{O.isDirectory?b.push(O):R.push(O)});for(let O of b){let F=C(O),B=A?O.header.fileAttr:void 0;try{o.makeDir(F),B&&o.fs.chmodSync(F,B),o.fs.utimesSync(F,O.header.time,O.header.time)}catch{T(P("Unable to create folder",F))}}R.reverse().reduce(function(O,F){return function(B){if(B)O(B);else{let Y=ye.normalize(l(F.entryName)),$=u(y,Y);F.getDataAsync(function(te,Z){if(Z)O(Z);else if(!te)O(be.Errors.CANT_EXTRACT_FILE());else{let ie=A?F.header.fileAttr:void 0;o.writeFileToAsync($,te,v,ie,function(oe){oe||O(P("Unable to write file",$)),o.fs.utimes($,F.header.time,F.header.time,function(L){L?O(P("Unable to set times",$)):O()})})}})}}},T)()},writeZip:function(y,v){if(arguments.length===1&&typeof y=="function"&&(v=y,y=""),!y&&i.filename&&(y=i.filename),!!y){var A=c.compressToBuffer();if(A){var T=o.writeFileTo(y,A,!0);typeof v=="function"&&v(T?null:new Error("failed"),"")}}},writeZipPromise:function(y,v){let{overwrite:A,perm:T}=Object.assign({overwrite:!0},v);return new Promise((C,P)=>{!y&&i.filename&&(y=i.filename),y||P("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(b=>{let R=O=>O?C(O):P("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(y,b,A,T,R)},P)})},toBufferPromise:function(){return new Promise((y,v)=>{c.toAsyncBuffer(y,v)})},toBuffer:function(y,v,A,T){return typeof y=="function"?(c.toAsyncBuffer(y,v,A,T),null):c.compressToBuffer()}}}});import{execFile as h_,spawn as p_,spawnSync as cA}from"node:child_process";import{promisify as g_}from"node:util";function w_(t){if(process.platform!=="win32")return!1;if(kf.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(kf,"").toLowerCase();return m_.has(r)}function Cf(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return w_(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function nt(t,e=[],r={}){return p_(t,e,Cf(t,r))}function Rf(t,e=[],r={}){return __(t,e,Cf(t,r))}var m_,kf,__,Wt=Ze(()=>{"use strict";m_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),kf=/\.(cmd|bat|ps1)$/i;__=g_(h_)});var $t=ae((zC,sx)=>{"use strict";var rx=["nodebuffer","arraybuffer","fragments"],ix=typeof Blob<"u";ix&&rx.push("blob");sx.exports={BINARY_TYPES:rx,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:ix,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var ji=ae((UC,vo)=>{"use strict";var{EMPTY_BUFFER:tE}=$t(),sd=Buffer[Symbol.species];function nE(t,e){if(t.length===0)return tE;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 sd(r.buffer,r.byteOffset,i):r}function ox(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function ax(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function rE(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function od(t){if(od.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new sd(t):ArrayBuffer.isView(t)?e=new sd(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),od.readOnly=!1),e}vo.exports={concat:nE,mask:ox,toArrayBuffer:rE,toBuffer:od,unmask:ax};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=ue("bufferutil");vo.exports.mask=function(e,r,i,o,c){c<48?ox(e,r,i,o,c):t.mask(e,r,i,o,c)},vo.exports.unmask=function(e,r){e.length<32?ax(e,r):t.unmask(e,r)}}catch{}});var lx=ae((GC,dx)=>{"use strict";var cx=Symbol("kDone"),ad=Symbol("kRun"),cd=class{constructor(e){this[cx]=()=>{this.pending--,this[ad]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[ad]()}[ad](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[cx])}}};dx.exports=cd});var Nr=ae((HC,hx)=>{"use strict";var qi=ue("zlib"),ux=ji(),iE=lx(),{kStatusCode:fx}=$t(),sE=Buffer[Symbol.species],oE=Buffer.from([0,0,255,255]),Io=Symbol("permessage-deflate"),Vt=Symbol("total-length"),Or=Symbol("callback"),Sn=Symbol("buffers"),Lr=Symbol("error"),So,dd=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,!So){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;So=new iE(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[Or];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){So.add(o=>{this._decompress(e,r,(c,l)=>{o(),i(c,l)})})}compress(e,r,i){So.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"?qi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=qi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:l}),this._inflate[Io]=this,this._inflate[Vt]=0,this._inflate[Sn]=[],this._inflate.on("error",cE),this._inflate.on("data",xx)}this._inflate[Or]=i,this._inflate.write(e),r&&this._inflate.write(oE),this._inflate.flush(()=>{let c=this._inflate[Lr];if(c){this._inflate.close(),this._inflate=null,i(c);return}let l=ux.concat(this._inflate[Sn],this._inflate[Vt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Vt]=0,this._inflate[Sn]=[],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"?qi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=qi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:l}),this._deflate[Vt]=0,this._deflate[Sn]=[],this._deflate.on("data",aE)}this._deflate[Or]=i,this._deflate.write(e),this._deflate.flush(qi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=ux.concat(this._deflate[Sn],this._deflate[Vt]);r&&(c=new sE(c.buffer,c.byteOffset,c.length-4)),this._deflate[Or]=null,this._deflate[Vt]=0,this._deflate[Sn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};hx.exports=dd;function aE(t){this[Sn].push(t),this[Vt]+=t.length}function xx(t){if(this[Vt]+=t.length,this[Io]._maxPayload<1||this[Vt]<=this[Io]._maxPayload){this[Sn].push(t);return}this[Lr]=new RangeError("Max payload size exceeded"),this[Lr].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Lr][fx]=1009,this.removeListener("data",xx),this.reset()}function cE(t){if(this[Io]._inflate=null,this[Lr]){this[Or](this[Lr]);return}t[fx]=1007,this[Or](t)}});var Mr=ae((jC,Ao)=>{"use strict";var{isUtf8:px}=ue("buffer"),{hasBlob:dE}=$t(),lE=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function uE(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function ld(t){let e=t.length,r=0;for(;r<e;)if((t[r]&128)===0)r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return!1;r+=2}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return!1;r+=3}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return!1;r+=4}else return!1;return!0}function fE(t){return dE&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}Ao.exports={isBlob:fE,isValidStatusCode:uE,isValidUTF8:ld,tokenChars:lE};if(px)Ao.exports.isValidUTF8=function(t){return t.length<24?ld(t):px(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=ue("utf-8-validate");Ao.exports.isValidUTF8=function(e){return e.length<32?ld(e):t(e)}}catch{}});var pd=ae((qC,vx)=>{"use strict";var{Writable:xE}=ue("stream"),gx=Nr(),{BINARY_TYPES:hE,EMPTY_BUFFER:mx,kStatusCode:pE,kWebSocket:gE}=$t(),{concat:ud,toArrayBuffer:mE,unmask:wE}=ji(),{isValidStatusCode:_E,isValidUTF8:_x}=Mr(),To=Buffer[Symbol.species],lt=0,yx=1,bx=2,Ex=3,fd=4,xd=5,ko=6,hd=class extends xE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||hE[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxBufferedChunks=e.maxBufferedChunks|0,this._maxFragments=e.maxFragments|0,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[gE]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=lt}_write(e,r,i){if(this._opcode===8&&this._state==lt)return i();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){i(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new To(i.buffer,i.byteOffset+e,i.length-e),new To(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 To(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case lt:this.getInfo(e);break;case yx:this.getPayloadLength16(e);break;case bx:this.getPayloadLength64(e);break;case Ex:this.getMask();break;case fd:this.getData(e);break;case xd:case ko: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[gx.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=yx:this._payloadLength===127?this._state=bx: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=Ex:this._state=fd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=fd}getData(e){let r=mx;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&&wE(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=xd,this.decompress(r,e);return}if(r.length){if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let i=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(i);return}this._messageLength=this._totalPayloadLength,this._fragments.push(r)}this.dataMessage(e)}decompress(e,r){this._extensions[gx.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let l=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(l);return}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let l=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");r(l);return}this._fragments.push(c)}this.dataMessage(r),this._state===lt&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=lt;return}let r=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=ud(i,r):this._binaryType==="arraybuffer"?o=mE(ud(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=lt):(this._state=ko,setImmediate(()=>{this.emit("message",o,!0),this._state=lt,this.startLoop(e)}))}else{let o=ud(i,r);if(!this._skipUTF8Validation&&!_x(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===xd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=lt):(this._state=ko,setImmediate(()=>{this.emit("message",o,!1),this._state=lt,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,mx),this.end();else{let i=e.readUInt16BE(0);if(!_E(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new To(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!_x(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(c);return}this._loop=!1,this.emit("conclude",i,o),this.end()}this._state=lt;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=lt):(this._state=ko,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=lt,this.startLoop(r)}))}createError(e,r,i,o,c){this._loop=!1,this._errored=!0;let l=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(l,this.createError),l.code=c,l[pE]=o,l}};vx.exports=hd});var wd=ae((KC,Ax)=>{"use strict";var{Duplex:WC}=ue("stream"),{randomFillSync:yE}=ue("crypto"),{types:{isUint8Array:bE}}=ue("util"),Sx=Nr(),{EMPTY_BUFFER:EE,kWebSocket:vE,NOOP:SE}=$t(),{isBlob:Br,isValidStatusCode:IE}=Mr(),{mask:Ix,toBuffer:qn}=ji(),ut=Symbol("kByteLength"),AE=Buffer.alloc(4),Co=8*1024,Wn,Fr=Co,Et=0,TE=1,kE=2,gd=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=Et,this.onerror=SE,this[vE]=void 0}static frame(e,r){let i,o=!1,c=2,l=!1;r.mask&&(i=r.maskBuffer||AE,r.generateMask?r.generateMask(i):(Fr===Co&&(Wn===void 0&&(Wn=Buffer.alloc(Co)),yE(Wn,0,Co),Fr=0),i[0]=Wn[Fr++],i[1]=Wn[Fr++],i[2]=Wn[Fr++],i[3]=Wn[Fr++]),l=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||l)&&r[ut]!==void 0?u=r[ut]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!l);let x=u;u>=65536?(c+=8,x=127):u>125&&(c+=2,x=126);let 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?(Ix(e,i,h,c,u),[h]):(Ix(e,i,e,0,u),[h,e])):[h,e]}close(e,r,i,o){let c;if(e===void 0)c=EE;else{if(typeof e!="number"||!IE(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(bE(r))c.set(r,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let l={[ut]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==Et?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):Br(e)?(o=e.size,c=!1):(e=qn(e),o=e.length,c=qn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ut]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Br(e)?this._state!==Et?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==Et?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):Br(e)?(o=e.size,c=!1):(e=qn(e),o=e.length,c=qn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let l={[ut]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Br(e)?this._state!==Et?this.enqueue([this.getBlobData,e,!1,l,i]):this.getBlobData(e,!1,l,i):this._state!==Et?this.enqueue([this.dispatch,e,!1,l,i]):this.sendFrame(t.frame(e,l),i)}send(e,r,i){let o=this._extensions[Sx.extensionName],c=r.binary?2:1,l=r.compress,u,x;typeof e=="string"?(u=Buffer.byteLength(e),x=!1):Br(e)?(u=e.size,x=!1):(e=qn(e),u=e.length,x=qn.readOnly),this._firstFragment?(this._firstFragment=!1,l&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(l=u>=o._threshold),this._compress=l):(l=!1,c=0),r.fin&&(this._firstFragment=!0);let h={[ut]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:x,rsv1:l};Br(e)?this._state!==Et?this.enqueue([this.getBlobData,e,this._compress,h,i]):this.getBlobData(e,this._compress,h,i):this._state!==Et?this.enqueue([this.dispatch,e,this._compress,h,i]):this.dispatch(e,this._compress,h,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[ut],this._state=kE,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(md,this,u,o);return}this._bufferedBytes-=i[ut];let l=qn(c);r?this.dispatch(l,r,i,o):(this._state=Et,this.sendFrame(t.frame(l,i),o),this.dequeue())}).catch(c=>{process.nextTick(CE,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Sx.extensionName];this._bufferedBytes+=i[ut],this._state=TE,c.compress(e,i.fin,(l,u)=>{if(this._socket.destroyed){let x=new Error("The socket was closed while data was being compressed");md(this,x,o);return}this._bufferedBytes-=i[ut],this._state=Et,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===Et&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][ut],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][ut],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};Ax.exports=gd;function md(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 CE(t,e,r){md(t,e,r),t.onerror(e)}});var Nx=ae(($C,Lx)=>{"use strict";var{kForOnEventAttribute:Wi,kListener:_d}=$t(),Tx=Symbol("kCode"),kx=Symbol("kData"),Cx=Symbol("kError"),Rx=Symbol("kMessage"),Dx=Symbol("kReason"),zr=Symbol("kTarget"),Px=Symbol("kType"),Ox=Symbol("kWasClean"),Jt=class{constructor(e){this[zr]=null,this[Px]=e}get target(){return this[zr]}get type(){return this[Px]}};Object.defineProperty(Jt.prototype,"target",{enumerable:!0});Object.defineProperty(Jt.prototype,"type",{enumerable:!0});var Kn=class extends Jt{constructor(e,r={}){super(e),this[Tx]=r.code===void 0?0:r.code,this[Dx]=r.reason===void 0?"":r.reason,this[Ox]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Tx]}get reason(){return this[Dx]}get wasClean(){return this[Ox]}};Object.defineProperty(Kn.prototype,"code",{enumerable:!0});Object.defineProperty(Kn.prototype,"reason",{enumerable:!0});Object.defineProperty(Kn.prototype,"wasClean",{enumerable:!0});var Ur=class extends Jt{constructor(e,r={}){super(e),this[Cx]=r.error===void 0?null:r.error,this[Rx]=r.message===void 0?"":r.message}get error(){return this[Cx]}get message(){return this[Rx]}};Object.defineProperty(Ur.prototype,"error",{enumerable:!0});Object.defineProperty(Ur.prototype,"message",{enumerable:!0});var Ki=class extends Jt{constructor(e,r={}){super(e),this[kx]=r.data===void 0?null:r.data}get data(){return this[kx]}};Object.defineProperty(Ki.prototype,"data",{enumerable:!0});var RE={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Wi]&&o[_d]===e&&!o[Wi])return;let i;if(t==="message")i=function(c,l){let u=new Ki("message",{data:l?c:c.toString()});u[zr]=this,Ro(e,this,u)};else if(t==="close")i=function(c,l){let u=new Kn("close",{code:c,reason:l.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[zr]=this,Ro(e,this,u)};else if(t==="error")i=function(c){let l=new Ur("error",{error:c,message:c.message});l[zr]=this,Ro(e,this,l)};else if(t==="open")i=function(){let c=new Jt("open");c[zr]=this,Ro(e,this,c)};else return;i[Wi]=!!r[Wi],i[_d]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[_d]===e&&!r[Wi]){this.removeListener(t,r);break}}};Lx.exports={CloseEvent:Kn,ErrorEvent:Ur,Event:Jt,EventTarget:RE,MessageEvent:Ki};function Ro(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Do=ae((VC,Mx)=>{"use strict";var{tokenChars:$i}=Mr();function Lt(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function DE(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&&$i[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 y=t.slice(x,m);h===44?(Lt(e,y,r),r=Object.create(null)):l=y,x=m=-1}else throw new SyntaxError(`Unexpected character at index ${E}`);else if(u===void 0)if(m===-1&&$i[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),Lt(r,t.slice(x,m),!0),h===44&&(Lt(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($i[h]!==1)throw new SyntaxError(`Unexpected character at index ${E}`);x===-1?x=E:i||(i=!0),o=!1}else if(c)if($i[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&&$i[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 y=t.slice(x,m);i&&(y=y.replace(/\\/g,""),i=!1),Lt(r,u,y),h===44&&(Lt(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 I=t.slice(x,m);return l===void 0?Lt(e,I,r):(u===void 0?Lt(r,I,!0):i?Lt(r,u,I.replace(/\\/g,"")):Lt(r,u,I),Lt(e,l,r)),e}function PE(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(", ")}Mx.exports={format:PE,parse:DE}});var No=ae((ZC,Vx)=>{"use strict";var OE=ue("events"),LE=ue("https"),NE=ue("http"),zx=ue("net"),ME=ue("tls"),{randomBytes:BE,createHash:FE}=ue("crypto"),{Duplex:JC,Readable:YC}=ue("stream"),{URL:yd}=ue("url"),In=Nr(),zE=pd(),UE=wd(),{isBlob:GE}=Mr(),{BINARY_TYPES:Bx,CLOSE_TIMEOUT:HE,EMPTY_BUFFER:Po,GUID:jE,kForOnEventAttribute:bd,kListener:qE,kStatusCode:WE,kWebSocket:Ge,NOOP:Ux}=$t(),{EventTarget:{addEventListener:KE,removeEventListener:$E}}=Nx(),{format:VE,parse:JE}=Do(),{toBuffer:YE}=ji(),Gx=Symbol("kAborted"),Ed=[8,13],Yt=["CONNECTING","OPEN","CLOSING","CLOSED"],ZE=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,me=class t extends OE{constructor(e,r,i){super(),this._binaryType=Bx[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Po,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]),Hx(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Bx.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 zE({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 UE(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[Ge]=this,c[Ge]=this,e[Ge]=this,o.on("conclude",ev),o.on("drain",tv),o.on("error",nv),o.on("message",rv),o.on("ping",iv),o.on("pong",sv),c.onerror=ov,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",Wx),e.on("data",Lo),e.on("end",Kx),e.on("error",$x),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[In.extensionName]&&this._extensions[In.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){ot(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),qx(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){vd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Po,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){vd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Po,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){vd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[In.extensionName]||(o.compress=!1),this._sender.send(e||Po,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){ot(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(me,"CONNECTING",{enumerable:!0,value:Yt.indexOf("CONNECTING")});Object.defineProperty(me.prototype,"CONNECTING",{enumerable:!0,value:Yt.indexOf("CONNECTING")});Object.defineProperty(me,"OPEN",{enumerable:!0,value:Yt.indexOf("OPEN")});Object.defineProperty(me.prototype,"OPEN",{enumerable:!0,value:Yt.indexOf("OPEN")});Object.defineProperty(me,"CLOSING",{enumerable:!0,value:Yt.indexOf("CLOSING")});Object.defineProperty(me.prototype,"CLOSING",{enumerable:!0,value:Yt.indexOf("CLOSING")});Object.defineProperty(me,"CLOSED",{enumerable:!0,value:Yt.indexOf("CLOSED")});Object.defineProperty(me.prototype,"CLOSED",{enumerable:!0,value:Yt.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[bd])return e[qE];return null},set(e){for(let r of this.listeners(t))if(r[bd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[bd]:!0})}})});me.prototype.addEventListener=KE;me.prototype.removeEventListener=$E;Vx.exports=me;function Hx(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:HE,protocolVersion:Ed[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,!Ed.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Ed.join(", ")})`);let c;if(e instanceof yd)c=e;else try{c=new yd(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;Oo(t,A);return}let h=l?443:80,m=BE(16).toString("base64"),E=l?LE.request:NE.request,I=new Set,y;if(o.createConnection=o.createConnection||(l?QE:XE),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&&(y=new In({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=VE({[In.extensionName]:y.offer()})),r.length){for(let A of r){if(typeof A!="string"||!ZE.test(A)||I.has(A))throw new SyntaxError("An invalid or duplicated subprotocol was specified");I.add(A)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),u){let A=o.path.split(":");o.socketPath=A[0],o.path=A[1]}let v;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=l,t._originalHostOrSocketPath=u?o.socketPath:c.host;let A=i&&i.headers;if(i={...i,headers:{}},A)for(let[T,C]of Object.entries(A))i.headers[T.toLowerCase()]=C}else if(t.listenerCount("redirect")===0){let A=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!A||t._originalSecure&&!l)&&(delete o.headers.authorization,delete o.headers.cookie,A||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),v=t._req=E(o),t._redirects&&t.emit("redirect",t.url,v)}else v=t._req=E(o);o.timeout&&v.on("timeout",()=>{ot(t,v,"Opening handshake has timed out")}),v.on("error",A=>{v===null||v[Gx]||(v=t._req=null,Oo(t,A))}),v.on("response",A=>{let T=A.headers.location,C=A.statusCode;if(T&&o.followRedirects&&C>=300&&C<400){if(++t._redirects>o.maxRedirects){ot(t,v,"Maximum redirects exceeded");return}v.abort();let P;try{P=new yd(T,e)}catch{let R=new SyntaxError(`Invalid URL: ${T}`);Oo(t,R);return}Hx(t,P,r,i)}else t.emit("unexpected-response",v,A)||ot(t,v,`Unexpected server response: ${A.statusCode}`)}),v.on("upgrade",(A,T,C)=>{if(t.emit("upgrade",A),t.readyState!==me.CONNECTING)return;v=t._req=null;let P=A.headers.upgrade;if(P===void 0||P.toLowerCase()!=="websocket"){ot(t,T,"Invalid Upgrade header");return}let b=FE("sha1").update(m+jE).digest("base64");if(A.headers["sec-websocket-accept"]!==b){ot(t,T,"Invalid Sec-WebSocket-Accept header");return}let R=A.headers["sec-websocket-protocol"],O;if(R!==void 0?I.size?I.has(R)||(O="Server sent an invalid subprotocol"):O="Server sent a subprotocol but none was requested":I.size&&(O="Server sent no subprotocol"),O){ot(t,T,O);return}R&&(t._protocol=R);let F=A.headers["sec-websocket-extensions"];if(F!==void 0){if(!y){ot(t,T,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let B;try{B=JE(F)}catch{ot(t,T,"Invalid Sec-WebSocket-Extensions header");return}let Y=Object.keys(B);if(Y.length!==1||Y[0]!==In.extensionName){ot(t,T,"Server indicated an extension that was not requested");return}try{y.accept(B[In.extensionName])}catch{ot(t,T,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[In.extensionName]=y}t.setSocket(T,C,{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 Oo(t,e){t._readyState=me.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function XE(t){return t.path=t.socketPath,zx.connect(t)}function QE(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=zx.isIP(t.host)?"":t.host),ME.connect(t)}function ot(t,e,r){t._readyState=me.CLOSING;let i=new Error(r);Error.captureStackTrace(i,ot),e.setHeader?(e[Gx]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Oo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function vd(t,e,r){if(e){let i=GE(e)?e.size:YE(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Yt[t.readyState]})`);process.nextTick(r,i)}}function ev(t,e){let r=this[Ge];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Ge]!==void 0&&(r._socket.removeListener("data",Lo),process.nextTick(jx,r._socket),t===1005?r.close():r.close(t,e))}function tv(){let t=this[Ge];t.isPaused||t._socket.resume()}function nv(t){let e=this[Ge];e._socket[Ge]!==void 0&&(e._socket.removeListener("data",Lo),process.nextTick(jx,e._socket),e.close(t[WE])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function Fx(){this[Ge].emitClose()}function rv(t,e){this[Ge].emit("message",t,e)}function iv(t){let e=this[Ge];e._autoPong&&e.pong(t,!this._isServer,Ux),e.emit("ping",t)}function sv(t){this[Ge].emit("pong",t)}function jx(t){t.resume()}function ov(t){let e=this[Ge];e.readyState!==me.CLOSED&&(e.readyState===me.OPEN&&(e._readyState=me.CLOSING,qx(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function qx(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function Wx(){let t=this[Ge];if(this.removeListener("close",Wx),this.removeListener("data",Lo),this.removeListener("end",Kx),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[Ge]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Fx),t._receiver.on("finish",Fx))}function Lo(t){this[Ge]._receiver.write(t)||this.pause()}function Kx(){let t=this[Ge];t._readyState=me.CLOSING,t._receiver.end(),this.end()}function $x(){let t=this[Ge];this.removeListener("error",$x),this.on("error",Ux),t&&(t._readyState=me.CLOSING,this.destroy())}});var Xx=ae((QC,Zx)=>{"use strict";var XC=No(),{Duplex:av}=ue("stream");function Jx(t){t.emit("close")}function cv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function Yx(t){this.removeListener("error",Yx),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function dv(t,e){let r=!0,i=new av({...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(Jx,i);return}let l=!1;t.once("error",function(x){l=!0,c(x)}),t.once("close",function(){l||c(o),process.nextTick(Jx,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",cv),i.on("error",Yx),i}Zx.exports=dv});var Sd=ae((e5,Qx)=>{"use strict";var{tokenChars:lv}=Mr();function uv(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&&lv[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}Qx.exports={parse:uv}});var oh=ae((n5,sh)=>{"use strict";var fv=ue("events"),Mo=ue("http"),{Duplex:t5}=ue("stream"),{createHash:xv}=ue("crypto"),eh=Do(),$n=Nr(),hv=Sd(),pv=No(),{CLOSE_TIMEOUT:gv,GUID:mv,kWebSocket:wv}=$t(),_v=/^[+/0-9A-Za-z]{22}==$/,th=0,nh=1,ih=2,Id=class extends fv{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:gv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:pv,...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=Mo.createServer((i,o)=>{let c=Mo.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=yv(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=th}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===ih){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(Vi,this);return}if(e&&this.once("close",e),this._state!==nh)if(this._state=nh,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(Vi,this):process.nextTick(Vi,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{Vi(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,o){r.on("error",rh);let c=e.headers["sec-websocket-key"],l=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Vn(this,e,r,405,"Invalid HTTP method");return}if(l===void 0||l.toLowerCase()!=="websocket"){Vn(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!_v.test(c)){Vn(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){Vn(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){Ji(r,400);return}let x=e.headers["sec-websocket-protocol"],h=new Set;if(x!==void 0)try{h=hv.parse(x)}catch{Vn(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 I=new $n({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let y=eh.parse(m);y[$n.extensionName]&&(I.accept(y[$n.extensionName]),E[$n.extensionName]=I)}catch{Vn(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let I={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(I,(y,v,A,T)=>{if(!y)return Ji(r,v||401,A,T);this.completeUpgrade(E,c,h,e,r,i,o)});return}if(!this.options.verifyClient(I))return Ji(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[wv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>th)return Ji(c,503);let h=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${xv("sha1").update(r+mv).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[$n.extensionName]){let E=e[$n.extensionName].params,I=eh.format({[$n.extensionName]:[E]});h.push(`Sec-WebSocket-Extensions: ${I}`),m._extensions=e}this.emit("headers",h,o),c.write(h.concat(`\r
|
|
15
15
|
`).join(`\r
|
|
16
|
-
`)),c.removeListener("error",
|
|
16
|
+
`)),c.removeListener("error",rh),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(Vi,this)})),u(m,o)}};sh.exports=Id;function yv(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 Vi(t){t._state=ih,t.emit("close")}function rh(){this.destroy()}function Ji(t,e,r,i){r=r||Mo.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} ${Mo.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 $n(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let l=new Error(o);Error.captureStackTrace(l,$n),t.emit("wsClientError",l,r,e)}else Vi(r,i,o,c)}});var yh=ae(ke=>{"use strict";function j(t,e){t=t-395;let r=jo(),i=r[t];if(j.tsVITW===void 0){var o=function(f){let p="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",m="",b="";for(let A=0,y,S,I=0;S=f.charAt(I++);~S&&(y=A%4?y*64+S:S,A++%4)?m+=String.fromCharCode(255&y>>(-2*A&6)):0)S=p.indexOf(S);for(let A=0,y=m.length;A<y;A++)b+="%"+("00"+m.charCodeAt(A).toString(16)).slice(-2);return decodeURIComponent(b)};j.gqYlCE=o,j.hsDiCx={},j.tsVITW=!0}let c=r[0],l=t+c,u=j.hsDiCx[l];return u?i=u:(i=j.gqYlCE(i),j.hsDiCx[l]=i),i}var N=j;(function(t,e){let r=j,i=t();for(;;)try{if(-parseInt(r(470))/1+-parseInt(r(1520))/2+-parseInt(r(1208))/3*(parseInt(r(1455))/4)+-parseInt(r(1449))/5+-parseInt(r(638))/6+-parseInt(r(1833))/7+parseInt(r(1477))/8===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(jo,688614);var Cv=Object[N(1343)+"operty"],Rv=Object["getOwnPr"+N(762)+N(662)],ph=(t,e)=>function(){return t&&(e=(0,t[{MnpHj:function(c,l){return c(l)}}[N(1325)](Rv,t)[0]])(t=0)),e},kv=(t,e)=>{let r={NJHUa:function(o,c,l,u){return o(c,l,u)}};for(var i in e)r.NJHUa(Cv,t,i,{get:e[i],enumerable:!0})};function Dv(){return lh||(lh=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Pv(){let t=N;return uh||(uh=[IDBCursor.prototype[t(968)],IDBCursor[t(1682)+"e"][t(1494)],IDBCursor[t(1682)+"e"][t(1494)+t(1403)+"ey"]])}function Ov(t){let e=N,r={MJUdn:e(719),ajQEN:e(1822),YfVXC:function(o,c){return o!==c},FaMra:e(802),gExYq:function(o,c){return o(c)},ZpgMM:function(o){return o()},jqFta:function(o,c){return o>=c},ZKCbh:function(o,c){return o===c},OvggU:e(539)},i=new Promise((o,c)=>{let l=e;if(r[l(743)]!==l(1349)){let u=()=>{let m=l;t["removeEv"+m(1600)+m(1201)](r.MJUdn,f),t[m(981)+m(1600)+m(1201)](r[m(1119)],p)},f=()=>{let m=l;if(r.YfVXC(r[m(1399)],r[m(1399)]))return(this[m(1171)+"rs"][_0x5c6f61]||(this._listeners[_0x29790a]=[]))[m(1285)]({fn:_0x424982,ctx:_0x2c643e||this}),this;o(r[m(813)](Mt,t[m(1735)])),r[m(1878)](u)},p=()=>{let m=l;c(t.error),r[m(1878)](u)};t[l(1765)+l(1442)](r[l(402)],f),t["addEvent"+l(1442)](r[l(1119)],p)}else return!!(r[l(1452)](this[l(1078)+l(1377)],this[l(1471)+"s"][l(1594)])||this[l(1078)+l(1377)]===this[l(1471)+"s"].length-1&&r[l(685)](this[l(1929)+l(1602)+"riesCount"],this[l(1495)+"es"]))});return i[e(477)](o=>{o instanceof IDBCursor&&Rd.set(o,t)}).catch(()=>{}),qo[e(1241)](i,t),i}function Lv(t){let e=N,r={nTHRn:e(1892)+"t",uhiQe:e(1657)+e(794)+e(1921)+"ct",wYTOo:function(o,c){return o===c},ZAKTU:e(1250),bajbt:e(1763),nWtwB:e(1683),jDJeH:e(888),kYBRQ:function(o){return o()},cVqoZ:e(1596)+"or",qOora:"error"};if(Go[e(1595)](t))return;let i=new Promise((o,c)=>{let l=e,u=()=>{let m=j,b={TEkMr:r[m(610)],SSGuA:r.uhiQe};if(r[m(787)](r[m(1162)],r[m(1525)])){this._destroyWebSocket();let A=_0x564afb(b.TEkMr,{message:b[m(503)]});this[m(1428)+"mediatel"+m(1085)+"ct"]&&this["onStopIm"+m(438)+m(1085)+"ct"](A)}else t[m(981)+"entListe"+m(1201)](r[m(764)],f),t[m(981)+m(1600)+m(1201)](m(1822),p),t[m(981)+"entListe"+m(1201)](r[m(676)],p)},f=()=>{let m=j;r[m(1844)](o),r[m(1844)](u)},p=()=>{let m=j;c(t[m(1822)]||new DOMException(m(1596)+"or",r[m(1125)])),r[m(1844)](u)};t[l(1765)+l(1442)](r.nWtwB,f),t[l(1765)+l(1442)](r[l(1189)],p),t[l(1765)+l(1442)](r[l(676)],p)});Go[e(1241)](t,i)}function Nv(t){Ho={qOTCg:function(i,o){return i(o)}}[N(1855)](t,Ho)}function Mv(t){let e=N,r={nLdhN:function(i,o){return i(o)},JwDia:function(i,o){return i(o)},gNapY:function(i,o){return i|o},tdGwN:function(i,o){return i|o},Qmhvi:function(i,o){return i<<o},yHZpn:function(i,o){return i&o},aAzBM:function(i,o){return i&o},fwkmr:function(i,o){return i<o},sATHI:e(1717)+"2",YQqoF:e(1341),iKxby:"message",lpYwr:e(1858),aqLxP:function(i,o){return i!==o},hqhWk:"fGjWl",TouTo:function(i,o){return i(o)},DNxiJ:function(i,o){return i===o},pPxaP:"vbxoE"};if(t===IDBDatabase[e(1682)+"e"][e(407)+e(918)]&&!(e(776)+e(1672)in IDBTransaction[e(1682)+"e"]))return function(i,...o){let c=e,l=t[c(1697)](Ji(this),i,...o);return Cd[c(1241)](l,i[c(1501)]?i[c(1501)]():[i]),r[c(1781)](Mt,l)};if(Pv().includes(t)){if(r.DNxiJ("vbxoE",r[e(498)]))return function(...i){let o=e;return t[o(1027)](r.nLdhN(Ji,this),i),r[o(478)](Mt,Rd.get(this))};_0x3981bc=r[e(1256)](r[e(1181)](r[e(1808)](15&_0x1758d2,12),r[e(1808)](r[e(1692)](63,_0x350a9f),6)),r.aAzBM(63,_0x204270)),r[e(1896)](_0x20ee81,2048)||_0x40f5ac>=55296&&_0x191109<=57343?_0x4467d2+=_0x35a8f1:(_0x51c638+=_0x55d400(_0x638b2),_0xe621e8+=2)}return function(...i){let o=e,c={aGZWj:r[o(1712)],PFPvT:r[o(1097)],fXOma:r[o(742)],bfZMw:"error",vgXQv:r.lpYwr};if(r[o(1912)](r[o(1801)],r[o(1801)])){let l=c.aGZWj[o(606)]("|"),u=0;for(;;){switch(l[u++]){case"0":this._ws["addEvent"+o(1442)](c[o(652)],this._onOpen);continue;case"1":this._ws[o(1765)+o(1442)](c.fXOma,this._onMessage);continue;case"2":this[o(1131)]["addEvent"+o(1442)](c[o(1546)],this[o(681)]);continue;case"3":this[o(1131)][o(1765)+o(1442)](c[o(613)],this._onClose);continue;case"4":if(!this[o(1131)])return;continue}break}}else return r.TouTo(Mt,t.apply(r[o(1743)](Ji,this),i))}}function Bv(t){let e=N,r={DGTjW:"function",XNxzZ:function(i,o){return i(o)},SvOfZ:function(i,o,c){return i(o,c)},Ogvno:function(i){return i()}};return typeof t===r.DGTjW?r.XNxzZ(Mv,t):(t instanceof IDBTransaction&&r[e(1047)](Lv,t),r.SvOfZ(gh,t,r[e(557)](Dv))?new Proxy(t,Ho):t)}function Mt(t){let e=N,r={RjGwm:function(o,c){return o instanceof c},GbErC:function(o,c){return o(c)}};if(r.RjGwm(t,IDBRequest))return r[e(1780)](Ov,t);if(zo[e(1595)](t))return zo[e(416)](t);let i=Bv(t);return i!==t&&(zo[e(1241)](t,i),qo[e(1241)](i,t)),i}var gh,lh,uh,Rd,Go,Cd,zo,qo,Ho,Ji,fh=ph({"node_modules/idb/build/wrap-idb-value.js"(){let t=N,e={ShBPE:function(r,i){return r===i},OcaBT:"done",zhMvr:t(924),JprhD:function(r,i){return r(i)},XklAJ:function(r,i){return r>=i},RiiCN:function(r,i){return r>=i},oVztt:function(r,i){return r+i},nclhY:function(r,i){return r|i},HocyT:function(r,i){return r%i},ApIES:function(r,i){return r instanceof i},BOlnT:function(r,i){return r!==i},YDZPM:"aMGSC",PkWNm:function(r,i){return r in i}};gh=(r,i)=>i.some(o=>r instanceof o),Rd=new WeakMap,Go=new WeakMap,Cd=new WeakMap,zo=new WeakMap,qo=new WeakMap,Ho={get(r,i,o){let c=t;if(r instanceof IDBTransaction){if(e[c(1668)](i,e[c(1809)]))return Go.get(r);if(e[c(1668)](i,c(776)+c(1672)))return r[c(776)+"oreNames"]||Cd.get(r);if(i===e[c(437)])return o[c(776)+c(1672)][1]?void 0:o["objectSt"+c(418)](o[c(776)+"oreNames"][0])}return e.JprhD(Mt,r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t,c={kiObh:function(l,u){return e.JprhD(l,u)},jnmPQ:function(l,u){return e[j(1135)](l,u)},vsVIK:function(l,u){return e[j(1767)](l,u)},hNTUv:function(l,u){return e[j(874)](l,u)},GQeII:function(l,u){return e[j(1089)](l,u)},wcGNc:function(l,u){return e[j(1005)](l,u)},qjmFZ:function(l,u){return e[j(1089)](l,u)}};if(e.ApIES(r,IDBTransaction)&&(e[o(1668)](i,e[o(1809)])||e[o(1668)](i,e[o(437)])))if(e[o(1031)](e[o(1281)],e.YDZPM)){if(c[o(1516)](_0x319fdb,_0x439ca7))return _0x468b47?_0x9b57d3:_0xa965a9;if(_0x235b13){if(c[o(433)](_0x5c1a1d,_0x47e036))return _0x5755fc}else{if(_0x4624e4<=-_0x2d5afb)return _0x319916;if(c[o(1759)](c.hNTUv(_0x1e4d31,1),_0x50c0f0))return _0x357540}return _0x31c3f6[o(1724)](c[o(1393)](c[o(1169)](_0x13e05d,_0x162b2e),0),c.qjmFZ(_0x58b530/_0x74679,0),_0x13fb77)}else return!0;return e.PkWNm(i,r)}},Ji=r=>qo[t(416)](r)}}),mh={};kv(mh,{deleteDB:()=>zv,openDB:()=>Fv,unwrap:()=>Ji,wrap:()=>Mt});function Fv(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let l=N,u={owjAM:function(m,b){return m(b)},EeVSG:l(961)+l(525),PDXEF:l(1634)+l(1539),dTPIC:l(1334)},f=indexedDB[l(1341)](t,e),p=Mt(f);return i&&f[l(1765)+"Listener"](u[l(1278)],m=>{let b=l;i(Mt(f[b(1735)]),m[b(468)+"on"],m[b(1689)+"on"],u.owjAM(Mt,f[b(407)+b(918)]))}),r&&f[l(1765)+l(1442)](u[l(649)],()=>r()),p.then(m=>{let b=l;c&&m[b(1765)+"Listener"]("close",()=>c()),o&&m["addEvent"+b(1442)](u[b(842)],()=>o())})[l(450)](()=>{}),p}function zv(t,{blocked:e}={}){let r=N,i={Mknmx:r(1334),NQIUl:function(c,l){return c(l)}},o=indexedDB.deleteDatabase(t);return e&&o["addEvent"+r(1442)](i[r(763)],()=>e()),i.NQIUl(Mt,o)[r(477)](()=>{})}function xh(t,e){let r=N,i={yKJEM:"1|0|2|3|4",LNhdN:r(645),WxIAV:function(f,p){return f instanceof p},cDPpn:function(f,p){return f in p},AtRFL:function(f,p){return f!==p},xXpGt:function(f,p){return f in p},BNbdl:function(f,p){return f===p},xrszK:"cyOmm"};if(!(i.WxIAV(t,IDBDatabase)&&!i.cDPpn(e,t)&&typeof e=="string"))return;if(Uo.get(e))return Uo[r(416)](e);let o=e[r(1307)](/FromIndex$/,""),c=i.AtRFL(e,o),l=_h[r(974)](o);if(!i[r(1203)](o,(c?IDBIndex:IDBObjectStore)[r(1682)+"e"])||!(l||wh[r(974)](o))){if(i.BNbdl(i.xrszK,i[r(1791)]))return;if(!this[r(879)+r(1101)]){let f=i.yKJEM.split("|"),p=0;for(;;){switch(f[p++]){case"0":this[r(1420)+r(1847)]?.resetCounter();continue;case"1":this[r(678)+r(1363)]?.[r(1478)+r(1295)+r(739)]();continue;case"2":this[r(1903)+"osed"]=!1;continue;case"3":this[r(770)]=!0;continue;case"4":this[r(879)]();continue}break}}}let u=async function(f,...p){let m=r,b=this[m(407)+m(918)](f,l?m(1009)+"e":i[m(1834)]),A=b[m(924)];return c&&(A=A[m(1725)](p.shift())),(await Promise.all([A[o](...p),l&&b[m(906)]]))[0]};return Uo[r(1241)](e,u),u}function jo(){let t=["y3vNvMi","AhzoD3y","CMziBg0","q3jyz1a","mdaWma","Du1Swhu","zwvKzwq","ELfWsKC","zg9bCu0","x2LZtwLUAvC","vgLTzw91Da","Dgv4Dc9WBge","DMfSDwvZ","yMzAtxC","zMLSzw5HBwu","yxbWBgLJyxq","BMTHC24","ELPqCee","zgf0yq","ywnRDxbfBMq","B2fqALq","D3LQC0W","zKrvC3y","wNnKsvi","DwvTyK0","wwzjCxK","B25szwnLAxy","DwPHBgK","zLHcs3G","tvfYq3m","Cu11t0K","vNjmwKq","vvjurfq","ywnR","DNLyv3e","AevYCM9Yrxy","BgvY","rNfwBu4","AxnAzxjV","DMfxEMG","Aw47y2HHCNm","u2nmreG","v0Tps2i","svruEha","CMv0CNLdB3u","tuLuAeK","vxLnwg8","BMDLza","x2TLEvbHDgG","zcWG","x3jLBw92zvC","yxKSig5LDhC","t3bLBKv2zw4","Dg9cExrLC0W","sfDJrKy","Aw50zwDLCIa","uMvJB25Uzwm","rLDt","zMLSDgvY","D2zbsxy","qwzmCKC","BgvUz3rO","AgfZ","qwjVCNrfCNi","CMvWBgfJzui","u21KzK8","BgLTAxq","zw50tgLZDgu","tu9zqMK","BMrWB2LUDfq","uxvLDwu","Ew5pq0C","r1fUD0q","DgvmB2Djre4","uNrTAMO","s2nqzLy","q3PeDuW","DhLstgy","zMzmAw5L","Ae1LC3nHz2u","B25SAw5L","C2vUza","q0DLvgC","y3jLyxrLt3a","z0Tus3O","C0LUsxG","D2vI","y2XVC2veqG","y2vZC0HHBMq","nhWWFdn8mNW","CMfTugfYyw0","whnWruK","CNzHBa","ruDQDxm","qNjvBw4","CMfTzq","EfHJEKu","BerjrfK","B3viwLC","Aw5KzxGGB3u","B3P3rNu","DxbNCMfKzw4","BwHWBwK","DufjEee","ywX3yxLZ","x2jPBMfYEvq","x2n1CNnVCKy","y3vYDMfSDwu","uMTxqKy","Dg9Y","ywXPzcb1CMW","BfbVug4","wgruCwe","Eg1ouwm","Avvvywe","x3bHDgHlzxK","q1nRCe4","su1zCwu","u0vMyLm","zw5HyMXLvhi","uwDqsfu","u2HHCMvKv28","zcWGDw5RBM8","y3vYC29Yx24","C3rVCcbPBw0","y2zkv3y","EuvJDNa","ChjVy2vZCW","x3nLCuLK","DKzPzwq","x2LUAxq","AwXK","BfrPBwvVDxq","swX1ugK","B3nLza","u2Hcueu","C3nHz2vfDMu","rfPRDNe","BMvLzf9Hy2S","B3jLtMfTzxm","Exvhuw0","zuzOrK4","Ahr0Chm6","ywrKt25L","vgjcuw0","B1DkDxm","A2DVrwC","C2vYDMLJzs0","uMvHzcbWyxm","ChjVDg90Exa","y29TCgXLDgu","AfrYAKG","x3nVy2TLDa","v3n0r1C","zNDZxZeUmc4","zxq9DxrMltG","BMv3vMvYC2K","B3jpBMXPBMu","CYbHBhjLywq","EuHACg4","CMvJzxzPzwq","zhDnCLG","zffhCLm","x2LZv29YA2u","y2fSBa","qunOuLm","BxrWDuO","y2XVC2uSihC","BLblC2O","yvnzD2W","vg1Qsvq","BwvZC2fNztO","swziDgS","x2zVCM1HDeu","txrVyNe","mhWXmhWZFde","BM9Uzv9UB24","B25JBg9Zzq","zNDTzvq","C0fuseK","FdH8nhWYFde","CMvZB2X2zq","Dg9hzw5LCMe","B25TzxnZywC","nhWWFdn8mxW","ihn1y2nLC3m","yMLUyxj5","vuz6uMi","uMHLyw8","Cw9jBeG","quHMyvy","zNjVBujPDhm","Aw5KzxG","quzAwMS","AM92wee","z2vtEw5J","v1H6uwy","x2DLDeLUDgu","BvjYEw0","A21Vtgm","s3HYvgC","qM9iENy","CMvZDwX0","tMviDxK","Bu1esve","t09Vz1G","Dxbhz3q","EevquLK","AhLJtwy","mxW0Fdb8m3W","vg91vg8","Bg93","ywDLrxzLBNq","DgLTzw91Da","uxDysMK","q3LYwKC","tg9Pzgq","DcbSAw1PDa","B3jRig9MzMW","lcbOB3n0BMe","zxjHDg9Y","BLfYrKC","END6z1C","s2jiteK","t1bftL9fuLi","B2zMC2v0","DNnwsuS","vfLZCgm","uKzyEu8","wfnMq0y","rvPfqNO","zLPWA2K","ywrKrxzLBNq","CLD6uMC","uMLPq04","txfXBgW","ywrKq291BNq","x19LC01Vzhu","t1H5sMu","C2DPza","yNL0zu9MzNm","D0Dnt1e","C2vUzf9Hy2S","ihzHBgLKigq","vuXQtKy","vff0CMK","rKjXsMG","r2jfCKm","BKXKAe4","y2HnyxHuCMK","AxnmB25N","qLHhwLu","AenHrMy","C2nYAxb0","DMz5B3q","Aw1LCYbPBIa","Ew16zfC","DuPiEve","EhjZEKS","v1fwqM8","CvDOqLu","yxnZAwDU","DwP5z0W","CKHdrK4","CKnABNm","su5tvefova","s1fSAxu","vePJCfy","AhfOv2S","q0jXA1e","BNrLCG","Dgv4Dc9Qyxy","tLL4ywW","qNn1De8","zxjFCw9Zx2e","uw1ODMK","t2nHqLq","x2LZqNjVD3m","quXm","Evf6EgS","Aw5UAgi","zejhzxO","Du90zuq","x2rLC3rYB3K","DMvYC2LVBG","yMTTEeO","zeDitg8","Aw5N","ywDLu2HVDW","zxjYB3i","y2Lrt2m","BM15C0e","Aw5L","x0vysvnu","uxDUsuC","vxPlBhG","uNfLA0W","tfvPt2O","DMDkrwG","CLz4v3u","otKYnJaWB2XkqKPQ","te5Oze4","B25nzxnZywC","s01ZAg4","wKDYv1K","zMXVB3i","D21HzhC","ywXty29Wzq","renkrfK","A2jMze0","CM9YrxzLBNq","A1LcuLe","uvbHDxm","DuzIt0W","C0nVDw50zxi","EMT0yKu","x2LZtwLUAvq","AwXRCNa","Cw9Z","Ef9MCM9UDgK","x3bPBMC","B25tDgfYDfi","Cu9uq2C","C3rHCNq","uKDUBfm","y2XVC2u","shLVDKe","z2v0s2v5","Bg9NsurozxC","CKPtANy","CgjICdi","Dw50","BKrUEgu","vLL5tMu","AefJA01LC3m","yMTvA2e","qNjPzgDL","BMCGDxjSoIa","yw5ZzM9YBvq","Dhfvv0G","wMXpDMC","tujZAxm","AxrSu0G","t3zeEhq","AfnqDfa","wNbNtu0","se56seG","u3LTwxq","x25HDMLNyxq","x29Uq2XVC2u","AvrQB24","BfvODgS","twXRuMm","BwfUDwfSihi","ugvvB1m","vuDVzLC","s1PjDeC","zNjVBu51Bwi","v2PcsuS","CMvJB25Uzwm","BxnNsuq","AxnrB1nnzxm","rvryvNu","zNDRBxi","EufitNu","BML0AwfSAxO","A1bQtuO","EwTfsKO","BwvZC2fNzq","DM5irxK","x3jLywr5q2W","y3jLyxrLrxi","sLjvB2u","zufJAW","CgLUz0LUDgu","ALvhvKm","C2vYDMvYvgK","vfPcDue","AgrgvfO","yxfmEfa","x2fKzfDZtgK","y29Kzq","AgDOA2S","ihrYEsbYzwm","igzPzwXKoIa","r3DVrNG","DgDAwfa","D0LXA0K","ihjLy29UBMu","AhDeBum","C2vYDMLJzq","AxfYrKe","v1DnvKW","CNnVCKzPBgu","CMfUzg9T","twnyA0e","y3vYCMvUDeu","wfrbs3i","yw51Ce1LC3m","Ae9iuui","t0Dtvvi","uvbMEwu","DwPosMG","DeLK","tKTYtg0","Dg9mB3DLCKm","B0Htr0u","zxvowfC","yM9KEq","qwPxrfO","tuPvzg4","t1bftG","uMHiC1G","AenSB3nLrxy","t3jsv0C","DhjHBNnHy3q","tfvzweG","ihrPBwvVDxq","BMCGzMfPBgu","B25pCgvU","BxDyuLa","rgvKAwnHDgu","y3rVtvy","Dg9cExrLCW","z2v0","u3bevwW","B3jL","CKHVAuq","u2DNr0G","B2nRzxrgywK","yK1RDwK","ign1CNnVCIa","tvrNENi","wvL4r2u","nxW0","yuHrAuy","BLj0qM4","ufP3sw8","yuforuS","EgLxC0e","BvrmzLK","AM5Tufe","qw9Luwq","DhbizwfKzxi","mxW1FdeXFdy","EMHnDNi","BwvKAwf0zwW","x2rPC2nVBM4","yxv0BW","zxH0ugf5Bg8","verys1G","uejJA0O","zLLjCw4","B2vkBxy","ywnOzwqSihC","EejsCvy","Dev2zw50","uLPWufu","y2f0y2G","yNvMzMvYzwq","z2v0u3rVCMe","vLHXtgO","wwDVt3q","ywDL","y3jLyxrLrwW","zhDlzNy","DhLWzq","CxrWCgm","rNbxAw0","z2u6ia","ANDMCNi","wgPYBhK","yxKSihrYEsa","zwrKBwO","rfztuMm","svPoveW","B2XKvMvYC2K","rxviEuO","nZyYntK4t3DQzhvV","zw5HyMXLqxu","CNLOuhC","t3LptKO","q291BNq","DxbKyxrLq3u","zuTLtKy","DgHLBG","sNDeAwe","ufbzvxG","BeHHBMrSzxi","x2LUDgvYDMe","mNWWFdn8nNW","qxfSBem","B2fRwKK","zKjUtgu","s3v2q3e","Cw54wg8","x21LC3nHz2u","DKjeChC","D24GCMvHC28","AwXLtMfTzq","q3j3Beq","BMfTzq","mNWXFdr8nxW","tLrczMm","tw5VAwG","quP2qwq","Cfb4yva","wvH2A3y","B1HJzLO","zv9ZDwnJzxm","uvLmugS","u1nhDue","z3nZv1G","ywnOzwq","Ec1TC2CTCw8","DxrMofDYAxq","y3vYC29Y","tg51wvi","BwDUrfC","ruHJv24","zMzWtNq","CMvQzwn0","B3nLrxzLBNq","tKDjthy","uM9JwvO","q0Xpu0ve","CLfpCfC","v1Lxyxe","z0vRCve","AxL5zvi","y29UDgv4Da","DxjS","tNrNDgS","AgfUz2u","vK1VteG","q3fZsfC","AgvHzgvYCW","tg9Nsuq","B3zsC2q","BMDuAw1LCG","s1DRrvO","DMfSDwu","ENb0zeK","DKTvyNe","sK9SA2m","u05luva","sKDYu0W","zhH1yuO","z29PBMCGyxC","BezlwMi","sK1Ztwm","zeXPuKC","v2PSA3i","qw1VDw50","y29UC3rYDwm","txfnqK4","q3rhtNi","vwDuCNm","ChPiBgm","Ae9Wzw5fDMu","DgLTzw91DcW","C1bUD2O","tg9NsurozxC","r1bTAhm","zw5JvMK","t2D2BM8","Dw5RBM93BIa","CvPYqMG","D1j0q0O","v2vPEgLUsLm","DwHHCvu","z2vjBMzVu3K","ExH5yKm","q29UzMLN","yw5Hz2vY","BMrWB2LUDca","CLvruuO","B2zMBgLUzq","zM9Yy2u","yw1Lu3bHy2u","sujHq1m","q3vZDg9Trxi","zw1LBNq","u29hsKi","B2nRzxq","zxmGCMvHy2G","DxLTzNi","t2jQzwn0","sK9zs0m","BfPirwm","yMH4y2K","z1PqsLi","zuTkB3y","rMnlC28","qM9otLm","C3rYAw5NAwy","shnMEMe","rNzlEfq","serpufO","x2rPC3bHDgm","rgrQt3K","whnXC1C","t3r4wey","D0Tuq0C","y3jLyxrLq2W","q3LgwxC","qMThveS","u1H4yMG","C1vQEMy","u3jAqwS","zw50","qu5Hzuu","suznAe4","BfzKzgW","C3bSAxq","DffAEwW","zfn4ALa","q3vZDg9Tq2W","BLriuM4","zxHWB3j0CW","sMHHzfu","DMDyuxy","EMXhDMS","DM12z3a","wunPEM0","EKXZCMC","BKzRwe8","EwzTEMC","q2Lvr08","Ce1jvhy","CeL2C2C","r2rwBuu","z1rgAve","DwvIEgO","sfjyz3e","rNP1Cu4","BwvY","AwDHDg9Yt24","zgvSzxrLrge","y3ruAw1LB3u","CMvKDwnL","CNjVCK1LC3m","Bgr5tuK","uKXgrNi","D3LIBvq","zxjFAxnFywm","mtyWnZaYmKHcCvjPrW","DxrVuMvJB24","s1Lose4","y29UBMvJDfm","B0P5rhq","y2HLy2Tszwe","CNrYsw4","CMvHzg9UBhK","wvnyyvu","rNjVBNrPzxi","zwvet2y","zfrqsum","q0fPswi","m3W1Fdr8mhW","uezqDLq","A2D0vxe","BwLUAvbYB2C","yNL0zuXLBMC","ywXSB2nvBNm","zsbHihn0CMK","Dg9tDhjPBMC","ue5psgG","quDXzgq","q2XXBeG","BwvZ","ywnRpwzYB24","qwXpvvK","zgvIDwC","whfoD0O","CgfNzxnOB3C","EvvXsKi","vxzyqwW","BNrbBMrvCgq","ywnRx2nVzgu","Exfqr20","CNrsDNO","zwnVBM5Ly3q","u0XID24","AKrkzuG","ywrVCwu","x2vUzhbVAw4","C2v0y3vYC28","z2v0sxrLBq","x29UrxjYB3i","x2n1CNnVCK0","CMvJzwL2zwq","o2nOyxjZzxq","wKTdyMG","u3LYr3C","q0nItg4","s1rACM8","y291BNq","igXHCMDLCIa","CfHmA2i","tgfMte8","zvjdqKK","yLLLwNa","qxn4BuG","Dg9oDw1Izxi","Aw9UvgLTzw8","x2LUAxrqCM8","Be5Mshy","DhjPBq","v2L0DxK","C0Xf","vNvTA2K","x3DZsw5ZDge","A2v5","D1flEuC","yM9L","rKv4zxC","Cu9vD0e","zNjHBwvuExa","BKXPBMu","su1zCwy","zeDRwgi","yMLUza","z2zJDNG","tgf1vMe","yvfJz08","DeLUDgvYy2u","C3vJy2vZCW","x2n1CNnVCK4","ihzHBgLKihm","rw9TAxq","zxf1ywXZ","uNrbwgO","BgXwBKW","tvvkEhy","qvHoDhq","Bwf4tg9ZC0m","y1PTvwq","C2v0q3vYC28","qNjhtwG","zujZuvi","y09Wzw4","t3P4ENm","Aw5KzxHpzG","x3bPBMDqB24","C2v0u3rVCMe","aaaaaaaaaaa","zMLN","D2fZq2XLyw4","EhPXv3K","AuT4yNK","t3zNz1u","u1DHtMm","BNPQrw8","y29SBM8","z0PzDfi","uuvlDhC","tKDFrvjst1i","Cxvysw0","sePZyxi","Bg9Nsurhzw4","qKHUEvi","yKXPwhO","twvZC2fNzuu","x29UtwvZC2e","BNzOvvO","wLn1y2K","x3vYBa","x29Ut3bLBG","Eu5srLy","B3bLCNr5tMe","twTUBxG","BLD0D0i","zxH0zw5ZAw8","DgfIyxnL","ALzMEKi","sxzlq3q","EePfvMq","x2LZsw5PDa","EevWsw8","tu9JteO","DhjPzxmGCMu","tuPSy3y","AgXyr1G","B2jQzwn0u3q","yMfdzeW","wgjMDNC","shvKr1a","vxbKyxrLq28","qujlBg8","zgvJB2rLzey","AxnszwfKEq","qK9IExC","y2HHCKnVzgu","AePJD0C","D1Lut28","yNvMzMvY","x3jLy29UBMu","v2vIu29JA2u","uKfSzKq","y3jLyxrLt2i","uurzqvi","zwrPyxrLBhK","zNjVBunOyxi","tgXSyNy","rKD4wu4","CujSyKi","CvjRshG","vxLKENO","nhWXFdb8mNW","vgvJAeS","DMvY","tuvtu0fhrv8","zfbRuNC","qMrxEvO","rNDAwum","x1fVu01HBMe","zfvqB1O","BgPcywC","Dhj1y3rVCIa","DufMqMq","z0v4wxe","q09oveLovuu","AMvbrMW","CNzHBfzHBhu","ignVzgu6ia","y29UBMvJDeu","CMvTB3zLq2G","AMLOz0i","sejpCw0","DKLfuvG","yxrHlcbKyxq","CfnfBNq","yvDIzfu","zw5NDgG","tev2tKi","B3vUDa","zwj4t2e","CMfmsvO","yxv0B21HDgK","CKjIv1C","CLzHBhvLCW","FdD8m3W5Fda","zNfpwxG","CM92AwrLigi","qLnwB0e","zgLZywjSzue","DgvZDa","uLjpuG","Bwu6ia","rwvwu0C","s2zLDNi","zxnxELm","te5JBuK","zgrjrcWGzgu","BMnLq2XVC2u","qxbos1u","ELvdEgi","rvvyuu4","sKXzrMG","uLjjvvq","EeHPsLe","x2rYB3bhBg8","jMPZy2fSBgi","Ae5VD2y","CNfZDhK","BM5bCxK","zgLZCgf0y2G","s3niu0C","sNHbtNy","CMvZzxrdB3u","CKLuwK8","shnKA2y","Cgf5Bg9Hzeu","AwTItNe","tunhEuu","wgzNswe","DeXMsxy","zcbLCNjVCI4","z0TiDKu","BfHty3G","x3DHAxq","B1z6Dhq","C3vIyxjYyxK","uvvxEge","AKjjv2m","Cw9Zx18","x2nVBM5Ly3q","C3vIC3rYAw4","zuHzvwS","qNjIDxu","ywnRx2LK","z21Ut2u","AM9JuvO","zNHfqKu","y2fpAwW","ywjVCNq","x21PBMLoyxy","x3fVC0rc","CKjMzei","Efv5rxy","AfrnDgu","zNLgz3e","BxjmDMi","AxvpEKO","u3vlDeG","Ae9ZBwi","q0DSCNa","Dg9cExrLC0i","CM92AwrLige","zMTUyvC","uNLZrgS","CfLJy0K","ueHTs1i","zg9Uzq","sNbNCKy","Dxrjza","DevZzhO","z1rPBwvVDxq","zxjFDhrS","D0zYvMq","z3b5tee","twLHzMS","BenAr0m","C3jJ","v1HAq00","Aw9U","rxjYB3jdB2q","DxfeBKe","ELzeru4","C3bSAwnL","vLbTDvG","C3rVCMu","BwDYDfC","B0D3sKq","yw1LoIa","yw1L","s1jzC1G","D1jszge","mxWY","BxnN","D3m6lY8","uhjPA0O","tM5Kveq","sfrYv2O","zvvYBa","y3H5ENq","ChbL","BfzZs24","C3rLBMvYCW","DNj2ALa","AwXLx25HBwu","B3bLBKrc","rxzLBNq","tKfTy1q","Cgf5Bg9Hza","z0vYyLa","C254tuG","sLnptLa","y1jwBKq","m3W0","Aw5juee","ugfbwM8","qvbiAKC","ywnRtxnNswq","sxDMv0K","vfruBuu","u2nsDLO","zxjYtxnN","DMvYC2LVBMm","AgvHzgvY","D3Hbs1C","tLnsA0u","D2LHBLu","mdaWmdaWmda","zNjYAMG","ywr2yw5Jzq","yxnL","ufDOuxG","y0vzDuS","x29WDgLVBNm","Bgzwyu0","Aw5JBhvKzxm","BhrPCgXLihq","wwXbDKm","rLL0Dw4","AfjpuxG","wML1ANq","B25VCgvU","CMvTB3zLrxy","z2HNzKu","AgLNAa","CgLUz19VBMm","Auvezgq","A1Lzy2u","q0vjExK","thDev20","y3vYC29YlNm","rhrhB0O","ChnNwgi","C0XQDgS","thbZtwu","wNPkwvq","B1nXtMG","Aw9Ul2PZB24","BwvZC2fNzv8","txDst2i","uuLrCNi","zwn0","vwHyv3q","DxnLCKLW","DLz6Cvi","teDPDvC","sg9JEvq","A2v5CW","Ec11C2uT","wfP6EKq","CMvHzhDYAxq","ufzeAwK","CLzLz04","tMfTzq","qvDOC1m","Exv0uuq","swvSAxm","ugv2ufu","y29UBMvJDca","v2X0zhO","BNruCMLLC0m","uLrsAhy","ugfftMi","CMfNzvn5BMm","tufYywq","vwTZteS","qK5ev2u","D1npug0","yxbWBhK","u2vYDMLJzvC","DNfzyvG","x2HHBMrSzva","qK9SBLq","q29Kzq","B2nRzxrtDwm","wMjrEhy","yxrLq291BNq","ruzQCKW","DhjPzxm","zgzzB2m","EMT1BNa","zxrxB3jRq2G","B25dBg9Zzq","yK9nwNy","thLcCwy","mhWYFdr8mxW","zMX1C2HfEha","Ec1TC2CTy3u","we54ELO","shvfwLC","C0vwA0S","zw1PDa","quLiueC","B2fwBxC","CKf3A0O","EgTyr3y","qMj5suq","DMvUDa","y0D5uLy","suvtx0vsuK8","rLDVt00","BxfdzM0","Dw5ZAwDUzwq","BhzIBMq","C0ryBuq","DK5yCuW","C3rYAw5N","q0Xpu0LorW","ELfrAfm","B1PuDeO","vw5PBxbSzw0","y29UBMvJDgK","Au5tteS","CunUA0C","r3LXCNu","EhzpyMO","vfHpzuW","rfDlzey","CM16Cuy","y3vYCMvUDeK","C2XPy2u","tw9KDwXL","vuHiEfK","uxvRBMi","zgvS","CLHSAfG","EvjLy29UBMu","z0D1tfq","zfnLDuW","qKDJs0m","BMnSAfK","x2rItMfTzq","vwjWzeq","AgvKtwf4uMu","B25fCNjVCG","CwPiuu8","v1n1ru4","C2fNzq","wvfXB0y","BgLZDgvUtMu","uNzwDwq","wK15sKy","tg9JAW","u2zpC2C","wgfWChK","BMCGB3iGyw4","x2nSzwfYugK","CMvXDwLYzwq","x0rctMfTzq","Bwv0Ag9K","sKvMrxq","vMTpAMe","CM92AwrLihC","CMTLCKDSB2i","reiGzMfPBgu","v01stKS","vePbB1a","uKjjDgq","ChrVCG","B2LUDfjLywm","ywPrru4","teDvyNa","uvHvCfi","twPdEvG","AMrvy0O","BNHVywy","y1zXB1O","r1jPy2S","wgvJzg8","EKTjrLO","ywWGy3vYC28","yMfSrxzLBNq","x3DZ","lcbTyxGGCMu","wNfAwwm","C1r6uLK","wgTSquO","EKnprwy","q0ndwuO","A1nrCMC","ExnbC2G","Ahr0Ca","mNWZFdf8mhW","vxLky0W","tufyx1jfvfi","qwH3uNC","EvzmvuS","z1jOruy","quj4uxm","zNjVBuHHC2G","x2nYzwf0zvm","rePmBNm","C1LnuuG","vuPkEvq","Dgv4DfbHEwW","ExfvqvK","ywzL","x2HHBMrSzvi","zMTJyvq","uLr4u0C","s2jYwuS","wMvywem","CgXLyxnLiha","wKflvfu","tNPNCfO","tNDcyLu","yNLL","D3jPDgu","v0XoDKS","rerpBei","D2nhtMm","q1DSChG","x2XPC3rLBMu","uenYBNK","CgLUz0XVC3m","Exrczfy","tuLNtgm","CvjiqLe","rM1PveO","r2vswMu","Cg1lrK0","DMj1vey","DgrhD04","sMHOBxO","z2TJyuC","CeLRyKG","C0zIyvO","AxjLza","t1L4vvq","CgLUz09Uy2u","Cu9VCMe","BIWGAg9ZDg4","tgHMvhG","EwzAwg4","tvrWwfK","shjRvfC","yNncA1m","DxrJvMS","BNrfBMrWB2K","r1jxswe","zxj2AwnL","yNjQvMS","BMvY","u2DOq0O","EfHWr3q","EKvIseq","qwDLsMu","vK5SthO","BNPvDeO","ndK4ou1AtvjNyq","sLnZswW","mhWXFdn8mNW","rNvwtwG","twjRA2S","y3jLyxrLuMu","r1D2z0q","C2rSBgS","sMr5vMO","svPvDK4","B25ozxr3B3i","x2nSzwfYvgK","we1bAui","yxGGCMv0CMK","ALHNBeC","Cg9PBNrbBMq","Ahrptxm","u0XzueG","y2XLyxi","AMTIvve","t2vjwuC","DwH6uKm","AxnrB1nby2S","BM5Ly3q","zuLTq1m","rLjnBfq","uNL4sfe","wgLbwMO","CMLLC0nVDw4","DgLUzYbZzxi","zhrwu1m","rhLUwve","B2zM","C2v0","tuz0qM8","uKL4tMW","DujHque","ExbL","yxD2s0q","x29UugfNzu4","quLYz1u","B3bLCNr5","BwfQsfC","y1rWqLy","yK5Izxq","qu5IuNi","t0zRrhu","zw50zwqGDhK","z05HCfK","zKXXDxO","BwLUzW","qxP1yue","EfriA28","zxjYtM8","ANfVBwW","ExflvM4","pxv0zI04","zNvUy3rPB24","y3jLyxrLtwu","yLrMCuu","uezpu1m","x2HHBMrSzu8","uLjqAwK","AKPtzM8","werhtum","CMvHC29U","D2LSBfjLy28","Cgu6ia","yxbWzw5Kq2G","wefovgi","ueryruy","BgLUzw5V","EgrLuMC","wurAue0","u1nQDM8","CgvYC2LZDgu","ve9fu0G","ChvZAa","BLv2vwy","BxHeAw0","Cg93","B3jcsg0","DxzkEgK","vK1zzM4","rufRueu","weXIAKy","rvjst1i","Cg9PBNrdB24","BwHyEKG","x3bYB3rVy28","x194x21Zz18","BMnVzgLUzW","zv90Aw1LB3u","yNL0zxm","te9LrNu","Dw5KzwzPBMu","zw5JB2rLrNi","zfDVCMTLCKC","yNvTChG","CMvWBgfJzq","igzHAwWSig0","zKT3Aw0","B3bLBIa","ywDLsgLKzq","ChjVDg9JB2W","CgLUz1rPBwu","C09Prvq","rNHJBu0","s0nODNy","AxmGDw5Kzwy","Axnby2TdBgu","wLv5Avu","y2HnyxHdB3u","DhvwvNu","CvPgsNa","vw1guKe","vMrkA3q","tw5WsgO","rvzsBuO","t2rZEMm","AvjJCeG","sK5prLK","CLj5z0O","ELfszNi","wfL1v3q","zM9YrwfJAa","yMXVy2TLza","y29Uy2f0","ywrK","D3jPDgvvAw4","AxnbCNjHEq","z09prgy","wvHgAvq","B3bLBG","AMvJDfn0B3i","zgvMAw5Luhi","x3bYzwzPEa","B25LCNjVCG","BNzyuwS","whzYsgO","C0XPC3rLBMu","v3bpuK4","vLbqA1G","Bhm6ia","AM92BvG","yMLUyxj5vhK","DhDVCMTdAge","BhHhDwC","Bxf3zwy","BwfW","y2uGBM90igK","zfrpyLi","sKjet2O","x2rLyNvN","zvHpqva","De1HBMfNzxi","ANnRELG","zNjVBNrPzxi","Cgf5Bg9Hzfq","qxr6Cg0","y21lBfG","reviq2m","zNjVBuj5Dgu","D2PdtM4","yvvzuMC","DKXdzeW","BNHcz24","CMvHzhLtDge","q2rbBLG","BMrLEa","AgjNsuO","z1ftuui","twLZC2LUzYa","ANbHvui","BM93","shzmseu","mxWZFdb8nhW","BezSDxnO","vMzxwMK","CMvHzfvjBNq","Cg9W","qxL0DNy","t2HttKm","x29UvgLTzw8","BgLUzq","r1fLsuK","AuvxAMq","suXUEe4","AvrVvKu","Dg9VigXHCMC","Dwj0vfq","rMfnCMe","y3PTz0G","C0jf","DvzSBeq","uhjPBwfYEuS","yw5Nzq","AMXcs0K","z2v0qwXSs2u","CgfYC2u","EgLwteO","wKn3uwC","zw5JB2rPBMC","zenfrem","ufrJteW","zw5HyMXLuw8","DhfsBgu","BhfrBMu","sMLfte0","BNnlDLi","q09otKvdveK","r1jLveW","x3bPBMDmB3m","u2vXsuq","BKfrz3q","v1vtsum","B2fK","t2f4r2u","Chv0","z2v0qwXS","B25tDg9Wsw0","q0LcANK","zMLUza","z2v0q3vYC28","zuTUENO","Ehz5sLm","Dg9iyxnO","B2noEKy","DMrPt2G","Cw1Qsw0","vKXfB2G","zujtA2K","Eu1iAu0","y09myK0","tgLZDgvUzxi","DMfS","tMjWrLq","tuDlwwq","EgD3r04","rvD4z3q","C2v0sxrLBq","nJaWmte1mfjJsw9bzW","A2XOr2O","AMD1u2S","ANfgDge","zw5fDMvUDa","A2zfB2y","mJyYohPAvhfcrq","s3DyDgK","y2XLyxjtDg8","CNzPAhq","yxfUyLy","EKjfzhG","sgHXyvC","qMXdsMG","tgT6thm","yMfdCgi","BMvJDa","u2TPCcbWyxm","Du10ueu","B2rMuMi","D055uhq","C1fHvfG","zw5KCg9PBNq","BNLSv1m","C29hz3i","EvLzs0m","rwX2A2y","Bhf4q1i","ndqXndK4nJrdvw5HEMq","CMvZzxrfBMq","AwL4r20","DhD3vgW","z0TtzeC","Bg9N","y2nZEMS","z3nzrhu","z2v0q3vYCMu","ig1LC3nHz2u","CNHnEhO","z2DPB08","tff3A3q","vfLxrxy","v2LUzg93","z2vY","v0zIDw0","y29UDgLUDwu","Bwf4uMv0CMK","CeXirKe","s1nStM8","id4G","uffoufC","x2LUAxrhBg8","C29YDa","CLPqzge","veDSDKm","AM9PBG","wxLHA28","vNrRBeO","txH0A28","ihrPBwvZ","Dw9Zsu0","sKf1Bw4","B25mAw5L","vuDfuwi","u3vbyNm","DgLLCKPtt04","qxPRtMm","A2LpyMG","AfzjBhG","CMvUDevUzha","quzizKu","mJCZmdeYnLHltervBq","icSG","Aw52zMO","BwLZzq","CYbWyxjHBxm","yMfQyNq","CenpBwK","z3rLC0K","ugP6AuS","rvjLBgi","y0nbA3q","zMvADwS","u0D5qLu"];return jo=function(){return t},jo()}var wh,_h,Uo,Uv=ph({"node_modules/idb/build/index.js"(){let t=N,e={sqzle:t(1141)+t(426),xmNQc:t(1336),yQzxk:t(1226),YhKBh:t(416),NKrLm:t(1860),pMITv:t(1427),rGCkJ:t(1406)+"ys",NGILv:function(o){return o()}},r=e.sqzle[t(606)]("|"),i=0;for(;;){switch(r[i++]){case"0":_h=[t(1426),e[t(1646)],"delete",e[t(1812)]];continue;case"1":wh=[e.YhKBh,e[t(396)],e[t(621)],e.rGCkJ,"count"];continue;case"2":e[t(515)](fh);continue;case"3":e.NGILv(fh);continue;case"4":Nv(o=>({...o,get:(c,l,u)=>xh(c,l)||o.get(c,l,u),has:(c,l)=>!!xh(c,l)||o[t(1595)](c,l)}));continue;case"5":Uo=new Map;continue}break}}}),Gv={idb:function(t){let e=N;t.exports=Promise.resolve()[e(477)](()=>(Uv(),mh))[e(477)](function(r){return r})}},hh={};function Nt(t){let e=N,r={JpgrF:e(1742)+"2",AjWDZ:function(u,f){return u!==f}},i=r[e(907)].split("|"),o=0;for(;;){switch(i[o++]){case"0":var c=hh[t]={exports:{}};continue;case"1":var l=hh[t];continue;case"2":return c[e(611)];case"3":Gv[t](c,c[e(611)],Nt);continue;case"4":if(r[e(401)](void 0,l))return l.exports;continue}break}}(()=>{let t=N,e={vqYaX:function(r,i){return r!==i},aSNrI:t(1179)};Nt.d=(r,i)=>{let o=t;if(e[o(1029)](e.aSNrI,o(1179)))return ke[o(1929)+o(1602)+"riesCount"];for(var c in i)Nt.o(i,c)&&!Nt.o(r,c)&&Object["definePr"+o(1249)](r,c,{enumerable:!0,get:i[c]})}})(),(()=>{let t=N;Nt.o=(e,r)=>Object[t(1682)+"e"].hasOwnProperty[t(1697)](e,r)})(),(()=>{let t={FcKso:function(e,r){return e!=r},uembM:"undefined"};Nt.r=e=>{let r=j;t[r(585)](t[r(1557)],typeof Symbol)&&Symbol[r(658)+"Tag"]&&Object["definePr"+r(1249)](e,Symbol[r(658)+"Tag"],{value:r(1080)}),Object["definePr"+r(1249)](e,r(1770)+"le",{value:!0})}})();var Re={};(()=>{let t=N,e={MqMBN:function(a,n){return a(n)},Mqqll:function(a,n){return a+n},soGgr:function(a,n){return a+n},jBIWc:function(a,n){return a*n},nsKvR:function(a,n){return a*n},sTzRY:function(a,n){return a>=n},oSqNh:function(a,n){return a!==n},mhpmi:t(1227),SggGH:function(a,n){return a+n},xUyEv:function(a,n,s){return a(n,s)},lFKZb:function(a,n){return a(n)},lNfHv:t(1537),klhGj:t(966)+t(966)+"00000000"+t(966),fZpki:function(a,n){return a>n},fqOYx:function(a,n){return a===n},ilkrp:"ZGTvh",WjBIK:function(a,n){return a<n},lfVaM:function(a,n){return a!==n},XiAZj:function(a,n){return a!==n},MTgzr:t(1694),sYMQH:function(a,n){return a-n},PevPU:function(a,n){return a!==n},LUiOj:function(a,n){return a-n},FwZYC:function(a,n){return a===n},gKTKz:function(a,n){return a!==n},vyXWq:function(a,n,s){return a(n,s)},zkunp:function(a,n){return a(n)},mRrym:function(a,n){return a>>>n},qCnkG:function(a,n,s){return a(n,s)},vmvgp:function(a,n,s){return a(n,s)},JMsMc:t(1380)+t(1106)+t(1917)+t(705),vIEQX:function(a,n,s){return a(n,s)},jovmX:t(1901),LkzLs:function(a,n,s){return a(n,s)},OtxXF:function(a,n){return a!==n},SLYPH:function(a,n,s){return a(n,s)},jlBKI:function(a,n){return a(n)},NVxdc:function(a,n){return a!==n},eFhFN:function(a,n,s){return a(n,s)},xBRqV:function(a,n){return a(n)},UyMXo:function(a){return a()},ujali:function(a,n){return a!==n},yAHNu:"wjRlS",sEpQb:t(1373),rZPda:function(a,n){return a!==n},rBbWW:function(a,n,s){return a(n,s)},xPHXy:function(a,n){return a!==n},VYyNe:function(a,n,s){return a(n,s)},YXvkv:function(a,n,s){return a(n,s)},vbuTF:function(a,n,s){return a(n,s)},tgZXP:function(a,n){return a!==n},oJyDt:function(a,n){return a===n},JEfEt:t(1562),ZeXXC:function(a,n,s){return a(n,s)},BHnyR:function(a,n,s){return a(n,s)},WMRNK:function(a,n){return a(n)},XvrHj:function(a,n){return a>>>n},wianU:function(a,n,s){return a(n,s)},iuOzJ:function(a,n){return a(n)},Rtmjj:function(a,n){return a(n)},inIPA:function(a,n,s){return a(n,s)},hCaFf:function(a,n,s){return a(n,s)},nxayH:function(a,n){return a(n)},HTrWj:function(a,n){return a(n)},rHoiD:function(a,n,s){return a(n,s)},FRMlT:function(a,n){return a(n)},TYspc:function(a,n){return a&n},OYxUT:function(a,n){return a===n},Ntgtk:t(1380)+"required"+t(1917)+t(1108),RvVud:function(a,n){return a===n},llVnL:t(708),BObyw:function(a,n){return a(n)},Hsfza:function(a,n){return a+n},aWbdU:t(1069)+t(1255)+t(1275),XdTqa:function(a,n){return a>>n},WUSIC:function(a,n){return a===n},sEVkK:function(a,n){return a+n},nDnxe:t(651)+t(931),APHjG:"MESSAGE_"+t(1294),pSEnt:t(1757)+"OR",AChRS:"NATIVE_E"+t(840),MGKYd:"MAX_RETR"+t(1058)+"R",uosIM:t(1934),UbpdD:t(1054),gJYtR:function(a,n){return a+n},KcPfV:function(a,n){return a>n},CUwvS:function(a,n){return a*n},AJvAd:function(a,n){return a>n},HTqsx:t(1681)+t(1750),FxcmM:function(a,n){return a+n},MTpXY:"done",uAIxA:function(a,n){return a===n},uJHyQ:t(776)+t(1672),gZPJR:function(a,n){return a===n},XsqsW:"store",PBckJ:t(1334),UzKlx:function(a,n){return a(n)},HhqaW:function(a,n){return a===n},ABxQs:function(a,n){return a!==n},Mbkkk:function(a,n){return a&n},wSOPm:function(a,n){return a&n},bOMZv:function(a,n){return a==n},Mtobq:function(a,n){return a+n},eddmj:t(519),HpyHj:t(1575),lqxCR:function(a,n){return a+n},UGEQb:function(a,n){return a+n},UGofW:function(a,n){return a+n},MFtBo:function(a,n){return a<<n},VPPkX:function(a,n){return a|n},QwXJi:function(a,n){return a&n},LGUbp:function(a,n){return a&n},dUPoZ:function(a,n){return a<=n},baCpb:function(a,n){return a(n)},ScRvZ:function(a,n){return a==n},yYYKC:function(a,n){return a&n},cTpBV:function(a,n){return a+n},quXIm:function(a,n){return a+n},hycMf:function(a,n){return a+n},dPkRw:function(a,n){return a+n},ZCwQg:function(a,n){return a&n},cEYuK:function(a,n){return a|n},bkUka:function(a,n){return a|n},rBfdB:function(a,n){return a|n},invfj:function(a,n){return a<<n},gmnOe:function(a,n){return a<<n},yutQD:function(a,n){return a<n},CiUGO:function(a,n){return a>n},ERelb:function(a,n){return a+n},nQrFG:function(a,n){return a|n},gTFiQ:function(a,n){return a+n},jihgB:function(a,n){return a<<n},mtpuJ:function(a,n){return a+n},Ziujt:function(a,n){return a>=n},RhHsX:function(a,n){return a<n},AIjgO:function(a,n){return a-n},OeIYG:function(a,n){return a&n},RBItd:function(a,n){return a<n},MlkRc:function(a,n){return a|n},SuAbs:t(1200),sZiHb:t(1793),eKnzz:function(a,n){return a|n},SoGJB:function(a,n){return a&n},cfJWv:function(a,n){return a>>n},ILnxN:function(a,n){return a|n},iToVE:function(a,n){return a&n},cZmUd:function(a,n){return a>>n},Ielis:function(a,n){return a&n},oZTtJ:function(a,n,s){return a(n,s)},RocYZ:function(a,n,s){return a(n,s)},wfAIv:function(a,n,s){return a(n,s)},BdWyZ:function(a,n){return a!==n},czmgH:"xgwGN",LafLO:function(a,n){return a(n)},OGSUR:function(a,n){return a&n},pXLkb:function(a,n){return a&n},vfyot:function(a,n){return a!==n},Odszc:t(1922),kddVh:t(876),UhXWt:function(a,n,s){return a(n,s)},YYxGe:function(a,n){return a|n},CzDuL:function(a,n){return a&n},wxAKW:function(a,n){return a&n},RqekL:function(a,n){return a(n)},mgrtW:function(a,n){return a&n},RGnlS:function(a,n){return a&n},MBsis:t(605),cxyzt:t(623),JGrSL:function(a,n){return a(n)},kgtUq:function(a,n){return a&n},wRRda:function(a,n){return a(n)},Aytvv:function(a,n){return a<<n},SymYt:function(a,n){return a&n},dpxFn:function(a,n){return a&n},NAmcT:function(a,n){return a(n)},DEHCc:function(a,n){return a&n},NTBfc:function(a,n){return a&n},cCAkt:function(a,n){return a<<n},ozwFu:function(a,n){return a|n},AlOUY:function(a,n){return a>>>n},ocNzF:function(a,n){return a<<n},xvyJS:t(414),JxANv:function(a,n){return a|n},JRUoe:function(a,n){return a===n},DCJDY:function(a,n){return a<n},wQKyG:function(a,n){return a&n},AzuaA:function(a,n){return a!==n},rRygJ:function(a,n){return a>>>n},SghCJ:function(a,n){return a&n},BSVoA:function(a,n){return a>>>n},KxrTg:function(a,n){return a>>>n},Xappy:function(a,n){return a&n},jVfzB:function(a,n){return a!==n},nAQgt:function(a,n){return a|n},gfcvx:function(a,n){return a>>>n},uMtPE:function(a,n){return a>>>n},ZUyiU:function(a,n){return a!==n},DVSRc:function(a,n){return a|n},ZTMPs:function(a,n){return a&n},HBOqm:function(a,n){return a|n},JBDOj:function(a,n){return a&n},eRCBI:function(a,n){return a>>>n},esWzS:function(a,n){return a+n},FGmha:function(a,n){return a!==n},aANEK:function(a,n){return a|n},MIgLc:function(a,n){return a&n},eHYUk:function(a,n){return a>>>n},aqnbV:function(a,n){return a+n},IFMhN:function(a,n){return a|n},ymzdW:function(a,n){return a&n},VkOja:function(a,n){return a>>>n},rviht:function(a,n){return a!==n},BaZuW:function(a,n){return a|n},mqwef:t(1544)+t(1573)+t(1688),gKSdG:t(1243),pttqb:"txwSo",WSuEN:function(a,n){return a|n},TAcwE:function(a,n){return a|n},uowWc:function(a,n){return a|n},JOlkc:function(a,n){return a<<n},wybmT:function(a,n){return a<<n},KSlNo:function(a,n){return a|n},HDOPZ:function(a,n){return a<<n},uMlXu:function(a,n){return a|n},oXcfZ:function(a,n){return a|n},KczEy:function(a,n){return a<<n},NzgpZ:function(a,n){return a|n},zQQhS:function(a,n){return a|n},RAlfD:function(a,n){return a>>>n},JdyVj:function(a,n){return a|n},uQDWM:function(a,n){return a|n},pIkbH:function(a,n){return a<<n},xiWsA:function(a,n){return a|n},nmysA:function(a,n){return a<<n},cugVb:function(a,n){return a&n},uAfBd:function(a,n){return a>>>n},hNowf:function(a,n){return a>>>n},jJSfo:function(a,n){return a===n},uqDnA:t(1489),awvKD:function(a,n){return a<=n},uvJxi:function(a,n){return a>=n},TTTmE:function(a,n){return a|n},tLfIv:function(a,n){return a/n},AIrgU:function(a,n){return a>>>n},LEvNB:function(a,n){return a===n},XqNwJ:function(a,n){return a>>>n},HudGP:function(a,n){return a>>>n},rCZns:function(a,n){return a&n},GeRZe:function(a,n){return a&n},LGiuW:function(a,n){return a>>>n},mBkOL:function(a,n){return a+n},nxoaf:function(a,n){return a|n},XrCjZ:function(a,n){return a<<n},vAnfL:t(527),kYYce:t(921),yqUAY:function(a,n){return a!==n},yqPGm:function(a,n){return a===n},qMuOI:function(a,n){return a===n},euNXW:function(a,n){return a===n},LUYXH:function(a,n){return a===n},zCOEf:function(a,n){return a&n},htOMs:function(a,n){return a&n},TJAoP:function(a,n){return a>>>n},rmzqF:function(a,n){return a>>>n},snxMH:function(a,n){return a>>>n},mhXzH:function(a,n){return a>>>n},MCGyE:function(a,n){return a>>>n},CBqkQ:function(a,n){return a>>>n},fYIqn:t(494)+"0|3",BBVaY:t(1418)+t(749),jeAFl:"qENHI",nzjEo:function(a,n){return a+n},ffpNt:"JIPMb",HRXgq:t(985),PMNwN:t(1444),PTcLL:t(1683),LhfTx:t(1822),Atzpm:t(1596)+"or",rJSjv:t(888),FpWim:function(a,n){return a===n},aeBJi:t(1437),cOLbM:function(a,n){return a===n},BXGZU:function(a,n){return a===n},hghkk:function(a,n){return a>n},FXgCk:function(a,n){return a!==n},eDBvK:"zgifp",rqovZ:t(1593),oaPjT:function(a,n){return a===n},jwfrr:function(a,n){return a instanceof n},IMYqe:"Unhandle"+t(870),DynYQ:function(a,n){return a+n},YNDBs:function(a,n){return a===n},zwzgW:function(a,n){return a===n},wFrVd:function(a,n,s){return a(n,s)},Elvkf:function(a,n,s){return a(n,s)},hVIlx:t(1858),jqoml:function(a,n,s){return a(n,s)},WQVBo:"Wituy",SGyBU:function(a,n){return a!==n},RqiGg:"XWzsI",VdJkt:t(1470),SrZAk:t(719),UmFRA:t(984)+t(501)+"s",xPYdR:function(a,n){return a(n)},hROQx:t(1746),FBqJh:t(984)+t(1300)+"t",lUhtk:t(1183),ciQOc:t(1402),AzkNc:t(1138),AIMKl:"sapmm",CyFYw:function(a,n){return a||n},fKwim:t(1210)+"4",RRPii:function(a,n){return a!=n},Yyako:t(1303)+"d",GWvgD:function(a,n,s,d){return a(n,s,d)},OvDxt:t(1376),OFkDu:t(1541),BoNNS:"next() called mu"+t(975)+t(1788)+t(1660),PjziK:function(a,n){return a===n},IZUvN:function(a,n){return a+n},lZHEc:function(a,n){return a<n},gEkqQ:function(a,n){return a<n},rtrIn:function(a,n){return a+n},TZBuA:t(1526),UyJcL:t(798),donZQ:function(a,n){return a<n},TXOeL:function(a,n){return a<n},gGuLT:function(a,n){return a|n},TJcpV:function(a,n){return a<<n},tFIeC:function(a,n){return a&n},McXkA:function(a,n){return a|n},WXzQf:function(a,n){return a|n},XMAiB:function(a,n){return a<<n},TbBQm:function(a,n){return a<<n},AXNtt:function(a,n){return a&n},dBGez:function(a,n){return a>=n},iRHeh:function(a,n){return a|n},HIzTn:function(a,n){return a|n},RZpPU:function(a,n){return a&n},GPmhs:function(a,n){return a<<n},vrvjP:function(a,n){return a+n},ykEJJ:function(a,n){return a(n)},PeUoS:function(a,n){return a<n},OWKHV:function(a,n){return a|n},hvNwv:function(a,n){return a===n},jovXA:function(a,n){return a&n},CGeTg:t(954),UnyBO:"1|5|2|0|"+t(952),ANbRr:function(a,n){return a|n},sIEcx:function(a,n){return a>>n},QXUpR:function(a,n){return a|n},TOESH:function(a,n){return a>>n},DtGoJ:function(a,n){return a|n},WXZCM:function(a,n){return a&n},TYWEv:function(a,n){return a-n},innhb:t(1065),lVsKn:function(a,n){return a(n)},OyONJ:function(a,n,s,d){return a(n,s,d)},dtVSS:function(a,n){return a!=n},SfOsg:function(a,n){return a instanceof n},CExxS:function(a,n){return a==n},ZgLpo:t(707),Wltdz:t(939),Quknb:function(a,n){return a!==n},CrXgP:t(1150),oxreX:function(a,n){return a(n)},yEcvp:t(612),hSPtP:t(1777),KChvv:t(1804)+"ascript",ZlOvg:t(1140),DWKdF:t(855)+t(663)+t(1514)+"P",caOil:function(a,n){return a(n)},wIqkI:"unknown reason",BNqZr:function(a,n){return a!==n},EGjus:t(993),dSxjP:function(a,n){return a===n},dLiRG:function(a,n,s){return a(n,s)},GCGGL:t(1055),xEPRY:t(406),cVltB:t(1647),VfWZi:function(a,n){return a(n)},uOteD:t(1496),gpyLA:t(695),nPKsj:"pAslx",DZkvq:function(a,n){return a!==n},ypmlI:function(a,n){return a===n},PQNPW:t(1123),Ozxzs:function(a,n){return a||n},dSeuL:function(a,n){return a||n},nnAqy:function(a,n){return a||n},HhaxE:t(893),CmoJT:t(1859),FvKxT:function(a,n){return a instanceof n},sFbaZ:"applicat"+t(996),zEbHD:t(1548)+t(996)+";charset=utf-8",QIQrr:t(1709)+"e",bumpx:t(1719),PPYUx:function(a,n){return a===n},jGkSW:t(1925),sOiET:function(a,n,s,d){return a(n,s,d)},YoKsv:function(a,n){return a!==n},ouHZW:"SnAmu",IZNTL:function(a,n){return a||n},UJJyT:function(a,n){return a!==n},oeJmv:t(1451),LJysi:t(472),VrLZD:function(a,n){return a||n},eBsQR:function(a,n){return a===n},ZbQxv:"qnZpc",SyrGw:t(1192),qOUwA:t(1851),XSfCF:function(a,n){return a(n)},VXqLj:function(a,n,s){return a(n,s)},oWJus:t(915),ldyMI:function(a,n){return a(n)},jXglG:t(496),TDXKX:function(a,n){return a===n},VMYfn:t(810),Xbfvw:function(a,n,s,d){return a(n,s,d)},zUCxb:"x_fronti"+t(1807)+"ck",TduoN:"x_frontier_is_ack",baCdL:t(1852)+"er_ack_m"+t(1772),bcWVc:function(a,n,s,d){return a(n,s,d)},ZSuci:t(1671),pzwIj:function(a,n,s,d){return a(n,s,d)},eeDOf:"is_ack",kbfdM:t(883),lDIDY:t(683),zptdI:function(a){return a()},VJePD:function(a,n){return a instanceof n},GReTL:function(a,n){return a instanceof n},OhSNC:function(a,n){return a(n)},vKZiu:function(a,n){return a<n},fyFgq:function(a,n){return a+n},mfvdX:function(a,n){return a|n},xEpIo:t(483),EtbPl:function(a,n){return a||n},hdFTZ:function(a,n){return a>>>n},OXyJe:function(a,n){return a(n)},zQpJG:function(a,n){return a+n},tqRle:t(1632)+"t of ran"+t(461),CGhOr:t(1521),nFkXO:t(1498),Brbuu:t(1736),SXxbh:function(a,n){return a>n},VtklJ:t(1588)+t(1397)+"e",AWhsS:function(a,n){return a+n},fXBKx:function(a,n){return a+n},BqRNc:function(a,n){return a<n},UgTrs:t(1044)+"3",qMgTX:function(a,n){return a+n},xzRWB:function(a,n){return a<n},mwXRP:function(a,n,s,d){return a(n,s,d)},xvObj:function(a,n,s,d){return a(n,s,d)},yUHFz:t(1629),QYLPk:function(a,n){return a|n},hOHQB:function(a,n){return a|n},PVDii:function(a,n){return a<<n},Loidd:function(a,n){return a+n},tWoeK:function(a,n){return a|n},YlAvC:function(a,n){return a>>>n},LyBqf:function(a,n){return a+n},AGqdd:function(a,n){return a+n},JAumn:function(a,n){return a+n},SGOPi:function(a,n){return a>>>n},qZrBh:t(852),JSsIl:t(1756),TmjIT:function(a,n){return a&n},hLjWl:function(a,n){return a&n},qjNFz:t(436)+t(834)+t(1713)+"0",Miafk:function(a,n){return a&n},AFHfE:function(a,n){return a>n},tuVVu:function(a,n){return a<n},HzaEo:function(a,n){return a|n},BrGMh:function(a,n){return a>>>n},gssWX:function(a,n){return a<<n},YsrMA:function(a,n){return a>>>n},tuhyY:function(a,n){return a>>>n},YgoOt:function(a,n){return a<n},utcVk:function(a,n){return a(n)},IvKCt:"4|9|5|7|"+t(1708)+"|2|6|8",rITZO:t(1923),FWoOM:t(493),raLIZ:t(989)+t(1199),AhwRw:t(962),EHcWn:function(a,n,s,d){return a(n,s,d)},yMHiM:t(1640),FYtun:function(a,n,s,d){return a(n,s,d)},MjCyX:function(a,n,s,d){return a(n,s,d)},UHHxY:function(a,n){return a(n)},uhaqU:"cursor_f"+t(943),bhxci:function(a,n){return a<n},adoqe:function(a,n,s){return a(n,s)},IMYqf:function(a,n,s,d){return a(n,s,d)},SWaNc:function(a,n,s){return a(n,s)},SmdfO:function(a,n){return a|n},FzuqN:function(a,n){return a|n},sUjzf:function(a,n){return a<<n},mMDIQ:function(a,n){return a<<n},dmKuV:function(a,n){return a===n},dfYoc:t(886),RRshu:"FILE_NOT"+t(1826),iEWjd:function(a,n,s){return a(n,s)},bfnAB:function(a,n){return a===n},vNXqL:"gyYDa",vnHEy:"allCurso"+t(833),AximA:t(1811),SEtkK:t(814),XYuWt:"setdb",gtesI:t(1601),CAiIb:t(1613),eBSki:t(569),twwTl:"pagehide",yVLUK:"pageshow",efOPf:function(a,n){return a+n},ggioO:function(a,n){return a+n},Jhhmz:t(853),psgXb:function(a,n){return a||n},HNzHH:function(a,n){return a+n},BGcKC:t(537),VNlLz:t(1914),AoeQd:function(a,n,s,d){return a(n,s,d)},ubtTT:"x_frontier_msgid",ITTxp:t(506)+"s",mrLvb:function(a,n,s){return a(n,s)},Gyqru:"x-msg-cursor_name",PZwIo:t(1046)+"rsor_value",SpDUl:function(a){return a()},ABKlo:function(a,n){return a>n},jpaUB:function(a,n){return a>n},JzLDn:function(a,n){return a===n},WzXGQ:"QEKtw",aSYwl:function(a){return a()},XDmRG:function(a){return a()},VPmuX:function(a,n){return a===n},DDOlB:t(1137),RysDk:function(a,n){return a===n},MJlcv:function(a,n){return a&&n},feZuk:function(a){return a()},QPDZb:"YhbBJ",SyBnn:t(951),Xecdo:function(a,n){return a<n},frrjh:function(a,n){return a===n},kfEof:function(a,n){return a!==n},GRWIa:function(a,n,s){return a(n,s)},XDGMC:function(a,n,s,d){return a(n,s,d)},FuVMh:function(a,n,s){return a(n,s)},cIeyH:function(a,n){return a in n},WLNvK:t(1836),gQSQB:function(a,n,s){return a(n,s)},dwKfv:t(801)+"3",iNSLK:function(a,n){return a<n},EWxgt:function(a,n,s){return a(n,s)},PjiXH:function(a,n,s,d){return a(n,s,d)},xTHko:function(a,n){return a+n},SLbwn:function(a,n){return a===n},hJcwG:function(a,n){return a!==n},RzqnT:t(751),EVRmJ:function(a,n){return a===n},KUhlI:t(688),aUYRg:t(1895),dGkXb:t(1003),ovRsd:t(1165),gKHvE:t(1252),Vumki:t(484),cGyRV:function(a,n){return a(n)},KuvCq:"arraybuffer",gOODf:t(1863),XLbjF:t(440),KwXti:"please provide v"+t(1643),VtZEH:t(1161)+t(1111)+t(1524)+", WebSocket cons"+t(811)+t(1317)+"ined",ZsdIR:function(a,n){return a===n},AHfaV:t(521),FGxYN:t(1852)+"er_qos",PFGhW:function(a,n){return a===n},EAkPE:t(722),BlCJh:t(1170),jvNKZ:function(a,n){return a&n},jskzX:function(a,n){return a(n)},BkGTK:function(a,n){return a===n},wyjsL:"ScpBE",zOcnp:t(487),EuHyJ:t(1892)+"t",mtrTb:function(a,n){return a!==n},wRtCJ:t(1429),XTAKr:function(a,n){return a!==n},AFZZk:function(a,n){return a!==n},MArad:function(a,n){return a===n},fknaW:t(1158),CGlrp:function(a,n){return a==n},DuqOP:"wss://",IbMLu:t(933),mTLfY:"bd_did",VnGEB:"ttwid",MOcLJ:function(a,n){return a||n},gsYDu:function(a,n){return a==n},FMiun:function(a,n,s){return a(n,s)},dQGrS:t(1619),rUQQJ:function(a,n){return a!==n},Mxtko:t(625),zZPpA:t(1856),tyRLf:function(a,n){return a-n},jjOrn:function(a,n,s){return a(n,s)},StjBz:function(a,n){return a(n)},mxDim:function(a,n){return a(n)},FNzCj:t(1172),nkasn:"FRONTIER>",JLYFh:function(a,n){return a*n},eKeNF:function(a,n){return a===n},sInIx:function(a,n,s){return a(n,s)},NSRkE:"NYxal",iRcpH:function(a,n){return a!==n},zktbE:t(635),ghgfE:function(a,n){return a|n},WstGW:function(a,n){return a<<n},WFbum:function(a,n){return a<<n},bTfqE:function(a,n){return a|n},rQOpW:function(a,n){return a<<n},qoIlH:function(a,n){return a>>n},OPfBl:t(897),tQZyl:function(a,n){return a!==n},ebxOa:"kYNYK",LOeFu:t(552)+t(1916)+"onnecting",zLsrg:t(580),EUXQN:t(845),aIzIh:t(1775),KYNHN:function(a,n){return a(n)},yfmzg:function(a,n){return a===n},ClqlH:t(1257),KbrYK:"2|4|1|0|3",vKUbq:"open",VOAVk:function(a,n){return a===n},hlXGX:t(1024),snEOI:function(a,n,s){return a(n,s)},ytBdV:function(a,n,s){return a(n,s)},QwnIG:function(a,n,s){return a(n,s)},KRYsX:t(540)+t(1584)+t(1751)+t(1825),GRick:t(1566),OaxGe:"close, ws instan"+t(1358)+t(1898)+"ed",dGHLo:function(a,n){return a===n},IBaCS:t(1700)+t(1691)+"y closed",kgoEg:function(a,n){return a<<n},EFjrL:function(a,n){return a|n},dTObR:function(a,n){return a&n},AgeJe:function(a,n){return a|n},CEIyy:function(a,n){return a|n},CCbLn:function(a,n){return a&n},PPaKN:t(1177),SMNWH:t(1416),uhzRC:t(1161)+t(901)+t(1776)+t(823)+"a must b"+t(657)+t(1104)+" arraybuffer",aHQiF:"number",PWhQx:function(a,n){return a(n)},OOogX:t(1161)+t(901)+t(721)+t(1199),ehmJi:function(a,n){return a instanceof n},sLjtk:function(a,n){return a===n},UJWAl:"enqueue",eImCS:function(a,n){return a==n},KsHSG:function(a,n){return a!==n},XfgIa:t(1886)+"econnect"+t(1820),wGMOQ:t(1503),dTslh:t(738),KZups:function(a,n){return a*n},QDYAR:t(1491),ADtEB:function(a,n){return a===n},sDXmD:function(a,n){return a===n},bsBkS:t(413)+t(1305)+"lobalScope",MUJxv:t(579),zQRfr:function(a,n){return a==n},xzqWy:function(a,n){return a!=n},Rheao:function(a,n){return a===n},vSjBT:t(1028)+"orkerGlobalScope",MwROb:function(a,n){return a!=n},uymfr:function(a,n){return a===n},HuEZW:function(a,n){return a!=n},ujygL:function(a,n){return a!=n},zlGvk:function(a,n,s){return a(n,s)},QgPHU:t(1298)+t(878)};Nt.r(Re),Nt.d(Re,{FWS:()=>Qp,CustomErrorEvent:()=>Jd,createCloseEvent:()=>ft,ReconnectEvent:()=>Vd,createErrorEvent:()=>ot,decodedFrame:()=>Xt,createOpenEvent:()=>tl,CustomCloseEvent:()=>Zd,createReconnectEvent:()=>ca,FrontierMessageEvent:()=>Xd,encodeFrame:()=>Bt,createMessageEvent:()=>el,OpenEvent:()=>Qd,ErrorCode:()=>en,Event:()=>Zn,MessageEvent:()=>Yd});let r="";function i(a=""){let n=t,s="02",d=""+Date[n(1382)](),x=r||(r=e[n(547)](f,a)),g=Math[n(1927)]().toString(16).slice(-6);return e[n(1768)](e[n(1473)](s+d,x),g)}function o(){let a=t;return e.Mqqll(e[a(877)](1e4,Date[a(1382)]()),Math[a(1838)](e[a(1417)](1e4,Math[a(1927)]())))}function c(a){let n=t,s={nzUtJ:function(d,x){return e[j(1134)](d,x)}};return e.oSqNh(n(1761),e[n(1635)])?e[n(420)](Array(8)[n(1504)]("0"),e[n(892)](parseInt,a,10).toString(2))[n(1079)](-8):s[n(1207)](this[n(689)],this[n(728)+n(828)])}function l(a){let n=t;return e[n(1473)](e[n(547)](Array,4)[n(1504)]("0"),e.xUyEv(parseInt,a,2)[n(658)](16))[n(1079)](-4)}function u(a){let n=t,s=a[n(606)](/\./)[n(1357)](g=>c(g)),d=[];return d[0]=e[n(541)](l,e[n(1473)](s[0],s[1])),d[1]=e[n(541)](l,e[n(1768)](s[2],s[3])),[n(1537),e[n(699)],e[n(699)],e[n(699)],e[n(699)],"ffff",d[0],d[1]][n(1504)]("")}function f(a){let n=t,s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/.test(a),d=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[n(839)](a);return s?e[n(541)](u,a):d?e.MqMBN(p,a):e[n(1450)]}function p(a){let n=t,s="",d=[],x=0,g=0,w=!0,_=e[n(699)];if(e[n(1764)](a[n(735)]("::"),-1))if(e[n(835)](e[n(1850)],e.ilkrp)){let h=a[n(606)]("::");for(let L=0;e[n(1891)](L,h[n(1594)]);L++){let B=h[L];if(e[n(1764)](B.indexOf(":"),0)){let z=B[n(606)](":");w&&(x=z.length),g+=z[n(1594)];for(let G=0;e[n(1891)](G,z[n(1594)]);G++)if(e[n(973)](4,z[G][n(1594)])){if(e[n(1235)](e[n(424)],n(1694)))return new _0x26d12f(_0x460878,_0x27ad1,_0x5b8cda);{let re=_.substring(0,e[n(1151)](4,z[G].length)),ve=re[n(1335)](z[G]);d[n(1285)](ve)}}else d[n(1285)](z[G]);w=!1}else{if(e[n(1016)](4,B[n(1594)])){let z=_[n(880)+"g"](0,e[n(1830)](4,B[n(1594)])),G=z[n(1335)](B);d[n(1285)](G)}else d.push(B);w&&(x+=1),g+=1,w=!1}}let v="";for(let L=0;L<e[n(1830)](8,g);L++)v=v[n(1335)](_);for(let L=0;e[n(1891)](L,d[n(1594)]);L++)e[n(807)](L,x)?(s=s[n(1335)](v),s=s.concat(d[L])):s=s[n(1335)](d[L]);return s}else _0x4098aa(this,_0xb4f88d,[_0x368e30,_0x188513,_0x2fc145,_0x347cfb,_0x47921e,_0x50d8a3]);{let h=a[n(606)](":");for(let v=0;v<h[n(1594)];v++){let L=h[v];if(e[n(995)](4,h[v][n(1594)])){let B=_.substring(0,4-h[v][n(1594)]),z=B.concat(L);s=s[n(1335)](z)}else s=s.concat(L)}return s}}function m(a,n){let s=t,d=a[s(705)];e[s(1617)](void 0,d)&&(he(n,10),e[s(892)](H,n,d));let x=a.value;x!==void 0&&(he(n,18),e[s(1567)](H,n,x))}function b(a){let n=t,s={};e:for(;!e.zkunp(V,a);){let d=e[n(1039)](xe,a);switch(e[n(1731)](d,3)){case 0:break e;case 1:s[n(705)]=e[n(1072)](O,a,e[n(541)](xe,a));break;case 2:s[n(533)]=e[n(615)](O,a,xe(a));break;default:R(a,7&d)}}if(e.FwZYC(void 0,s.key))throw new Error(e[n(542)]);if(e[n(835)](void 0,s.value))throw new Error(n(1380)+"required"+n(1917)+n(533));return s}function A(a){let n=t,s=k();return e[n(822)](y,a,s),M(s)}function y(a,n){let s=t,d=a[s(1421)];d!==void 0&&(he(n,8),e[s(1463)](ut,n,d));let x=a.LogID;e[s(594)](void 0,x)&&(e.vmvgp(he,n,16),ut(n,x));let g=a[s(1923)];e.oSqNh(void 0,g)&&(e[s(1225)](he,n,24),e[s(822)](ut,n,e[s(1405)](D,g)));let w=a[s(1108)];e.NVxdc(void 0,w)&&(e[s(1674)](he,n,32),ut(n,e[s(447)](D,w)));let _=a[s(528)];if(_!==void 0)for(let ve of _){e[s(1674)](he,n,42);let xt=e[s(1579)](k);m(ve,xt),e.qCnkG(he,n,xt[s(1599)]),e[s(1225)]($,n,xt),e[s(1039)](P,xt)}let h=a[s(865)+"ncoding"];e[s(1617)](void 0,h)&&(e[s(1560)](e[s(1897)],e.sEpQb)?(e[s(1463)](he,n,50),H(n,h)):(_0x5df007[s(1153)+s(1424)]="",_0x1f69cf[s(1482)](_0x31b91a)));let v=a["payloadT"+s(1245)];e[s(1502)](void 0,v)&&(e[s(832)](he,n,58),H(n,v));let L=a[s(947)];e.xPHXy(void 0,L)&&(he(n,66),e[s(1866)](he,n,L[s(1594)]),e[s(499)](oe,n,L));let B=a[s(554)];B!==void 0&&(e[s(1567)](he,n,74),e[s(1463)](H,n,B));let z=a[s(1909)+s(1258)];e.lfVaM(void 0,z)&&(e.vmvgp(he,n,82),e[s(1180)](H,n,z));let G=a[s(1893)];e[s(1919)](void 0,G)&&(e[s(642)](e.JEfEt,e[s(1109)])?(he(n,90),e[s(822)](H,n,G)):this[s(1050)](e[s(1352)],e[s(892)](_0x1fa3dc,e.jovmX,{..._0x187d3b})));let re=a[s(710)+"e"];e.OtxXF(void 0,re)&&(e.ZeXXC(he,n,96),e.BHnyR(ut,n,e[s(447)](D,re)))}function S(a){return e[t(1039)](I,e.jlBKI(F,a))}function I(a){let n=t,s={};e:for(;!e[n(1114)](V,a);){let d=e[n(1114)](xe,a);switch(e[n(1347)](d,3)){case 0:break e;case 1:s[n(1421)]=vt(a,!0);break;case 2:s.LogID=e[n(965)](vt,a,!0);break;case 3:s.service=e[n(896)](xe,a);break;case 4:s[n(1108)]=xe(a);break;case 5:{let x=e[n(1607)](T,a);(s[n(528)]||(s[n(528)]=[]))[n(1285)](b(a)),a[n(1599)]=x;break}case 6:s[n(865)+n(1299)]=O(a,xe(a));break;case 7:s[n(1366)+n(1245)]=e.inIPA(O,a,xe(a));break;case 8:s[n(947)]=e[n(1785)](ie,a,e.nxayH(xe,a));break;case 9:s[n(554)]=O(a,e[n(936)](xe,a));break;case 10:s[n(1909)+n(1258)]=e[n(419)](O,a,e[n(1233)](xe,a));break;case 11:s[n(1893)]=e.vyXWq(O,a,e.zkunp(xe,a));break;case 12:s[n(710)+"e"]=e.xBRqV(xe,a);break;default:e[n(1160)](R,a,e[n(1760)](7,d))}}if(s[n(1421)]===void 0)throw new Error("Missing "+n(1106)+n(1917)+"SeqID");if(e[n(835)](void 0,s[n(529)]))throw new Error(n(1380)+n(1106)+n(1917)+n(529));if(e[n(1187)](void 0,s[n(1923)]))throw new Error(n(1380)+n(1106)+" field: "+n(1923));if(s[n(1108)]===void 0)throw new Error(e[n(524)]);return s}function T(a){let n=t,s=e[n(541)](xe,a),d=a.limit;return a[n(1599)]=e[n(1768)](a[n(1758)],s),d}function R(a,n){let s=t;if(e.RvVud(e.llVnL,e[s(725)]))switch(n){case 0:for(;e[s(1760)](128,e[s(784)](se,a)););break;case 2:e[s(1785)](J,a,e[s(1114)](xe,a));break;case 5:e[s(1180)](J,a,4);break;case 1:e[s(753)](J,a,8);break;default:throw new Error(e[s(588)](e[s(825)],n))}else return _0x326134.errMsg||_0x333df4[s(1261)]?(s(1704)+" "+(_0x5e093e[s(960)]||"")+" code: "+(_0x233245[s(1261)]||""))[s(700)]():_0x30fe37[s(587)+"y"](_0x587cc3)}function D(a){let n=t;return a|=0,{low:a,high:e[n(1645)](a,31),unsigned:e.sTzRY(a,0)}}let E=[];function k(){let a=t,n=E[a(1388)]();return n?(n.offset=n[a(1599)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function P(a){E.push(a)}function F(a){return{bytes:a,offset:0,limit:a.length}}function M(a){let n=t,s=a.bytes,d=a[n(1599)];return e[n(1423)](s[n(1594)],d)?s:s[n(875)](0,d)}function J(a,n){let s=t;if(e[s(1764)](e[s(1049)](a.offset,n),a[s(1599)]))throw new Error(s(1466)+"t limit");a[s(1758)]+=n}function V(a){let n=t;return e[n(1134)](a[n(1758)],a[n(1599)])}function ee(a,n){let s=t,d={lPoPn:e[s(1865)],vBDpw:e[s(955)],odfRb:e[s(824)],BoHzv:e[s(1698)],IwfWI:e[s(1445)],fwmeT:s(1418)+s(749)};if(e[s(1509)]!==e[s(1091)]){let x=a[s(1301)],g=a[s(1758)],w=a[s(1599)],_=e[s(747)](g,n);if(e[s(1608)](_,x.length)){let h=new Uint8Array(e.CUwvS(2,_));h[s(1241)](x),a[s(1301)]=h}return a[s(1758)]=_,e[s(497)](_,w)&&(a[s(1599)]=_),g}else{let x=d[s(1644)][s(606)]("|"),g=0;for(;;){switch(x[g++]){case"0":_0x22b62d[_0x250654[d[s(489)]]=5004]=d[s(489)];continue;case"1":_0xcc3bc0[_0x20dff9[d[s(1468)]]=5005]=d[s(1468)];continue;case"2":return _0x3c97c8;case"3":_0x51a1a1[_0x22c94f[d.BoHzv]=5001]=d[s(1734)];continue;case"4":_0x96012b[_0x252aef[d[s(957)]]=5003]=d[s(957)];continue;case"5":_0x7c3c87[_0x37fd8e[d[s(1711)]]=5002]=d[s(1711)];continue}break}}}function Z(a,n){let s=t,d=a.offset;if(e[s(1049)](d,n)>a.limit)throw new Error(e.HTqsx);return a[s(1758)]+=n,d}function ie(a,n){let s=t,d=e[s(1180)](Z,a,n);return a[s(1301)][s(875)](d,e[s(1315)](d,n))}function oe(a,n){let s=t;if(s(1025)!=="IaFIi"){let d=e[s(419)](ee,a,n[s(1594)]);a.bytes[s(1241)](n,d)}else{if(EHnDba[s(1187)](_0x3ac179,EHnDba[s(1193)]))return _0x28bdfd[s(416)](_0x3c4835);if(EHnDba.uAIxA(_0x3b01e8,EHnDba[s(1790)]))return _0x3a1445.objectStoreNames||_0x203b1f[s(416)](_0xb8a355);if(EHnDba[s(583)](_0x5dbe95,EHnDba[s(593)]))return _0x562d96[s(776)+s(1672)][1]?void 0:_0x3f8962["objectSt"+s(418)](_0x1ce251[s(776)+s(1672)][0])}}function O(a,n){let s=t,d=Z(a,n),x=String["fromChar"+s(1032)],g=a.bytes,w="\uFFFD",_="";for(let h=0;e.WjBIK(h,n);h++){let v=g[e[s(1473)](h,d)],L,B,z,G;if(e[s(642)](e.TYspc(128,v),0))_+=e.xBRqV(x,v);else if(e[s(1461)](224&v,192))e.sTzRY(e[s(420)](h,1),n)?_+=w:(L=g[h+d+1],e[s(1147)](e[s(1212)](192,L),128)?_+=w:(G=e[s(1026)](31,v)<<6|63&L,e.WjBIK(G,128)?_+=w:(_+=x(G),h++)));else if(e.bOMZv(240&v,224))if(e[s(1134)](e.Mtobq(h,2),n))_+=w;else if(e[s(465)]!==e.HpyHj)L=g[e.Mqqll(e.lqxCR(h,d),1)],B=g[e[s(1512)](e[s(1888)](h,d),2)],e[s(1760)](L|e[s(1242)](B,8),49344)!==32896?_+=w:(G=e[s(1350)](e[s(1350)](e[s(1747)](15,v)<<12,e.MFtBo(e[s(1120)](63,L),6)),e[s(1747)](63,B)),e[s(1891)](G,2048)||G>=55296&&e[s(809)](G,57343)?_+=w:(_+=e[s(1464)](x,G),h+=2));else{let re=_0x4f6426[s(630)+s(766)](_0x5c0877);return _0x1f7976&&re.addEventListener(EHnDba[s(443)],()=>_0xf25675()),EHnDba.UzKlx(_0x554031,re)[s(477)](()=>{})}else e[s(959)](e[s(1474)](248,v),240)?e[s(420)](h,3)>=n?_+=w:(L=g[e.cTpBV(e[s(750)](h,d),1)],B=g[e[s(1741)](e.dPkRw(h,d),2)],z=g[e[s(750)](e[s(805)](h,d),3)],e[s(1560)](e[s(1409)](e[s(971)](e[s(1868)](L,B<<8),e[s(1242)](z,16)),12632256),8421504)?_+=w:(G=e[s(891)](e[s(1350)](e.invfj(e[s(1474)](7,v),18)|e[s(884)](63&L,12),e[s(1522)](e[s(1409)](63,B),6)),e[s(1747)](63,z)),e[s(1014)](G,65536)||e[s(620)](G,1114111)?_+=w:(G-=65536,_+=e[s(953)](x,e[s(1741)](G>>10,55296),e[s(1529)](e.QwXJi(1023,G),56320)),h+=3))):_+=w}return _}function H(a,n){let s=t,d=n[s(1594)],x=0;for(let _=0;_<d;_++){let h=n[s(785)+"At"](_);e[s(979)](h,55296)&&e[s(809)](h,56319)&&e[s(404)](_+1,d)&&(h=e.sYMQH(e[s(1251)](h<<10,n[s(785)+"At"](++_)),56613888)),x+=h<128?1:h<2048?2:e[s(1014)](h,65536)?3:4}e.inIPA(he,a,x);let g=ee(a,x),w=a[s(1301)];for(let _=0;e[s(1014)](_,d);_++){let h=n[s(785)+"At"](_);if(h>=55296&&h<=56319&&e[s(1707)](_,1)<d&&(h=e.AIjgO(e[s(805)](e[s(884)](h,10),n[s(785)+"At"](++_)),56613888)),h<128)w[g++]=h;else{if(e.yutQD(h,2048))w[g++]=e[s(971)](e.OeIYG(h>>6,31),192);else{if(e.RBItd(h,65536))w[g++]=e[s(1885)](e.XdTqa(h,12)&15,224);else if(e[s(1513)]!==e.sZiHb)w[g++]=e[s(1432)](e[s(575)](e[s(1658)](h,18),7),240),w[g++]=e.ILnxN(e[s(1396)](e[s(729)](h,12),63),128);else{let v=new _0xb3918f(e[s(1754)](e[s(1350)](e[s(884)](_0x7e2f8[e[s(624)](_0x80c5a8,4)],24),e[s(820)](_0x297ad6[_0x3129b3+5],16)),e.jihgB(_0x1d2357[e[s(1529)](_0x553c26,6)],8))|_0x3c3f3d[e[s(1699)](_0x363bd4,7)],e[s(1350)](e[s(1754)](e.jihgB(_0x1b2c2f[_0x7cdf24+0],24)|_0x2f4d08[_0x447cd3+1]<<16,e[s(1522)](_0x3deaf5[e[s(1699)](_0x5f0a3d,2)],8)),_0x127d70[_0x5bebad+3]),!0);return _0x1b3d15+=8,{value:v,offset:_0x1277cb+8}}w[g++]=e.MlkRc(e[s(1015)](e.cZmUd(h,6),63),128)}w[g++]=e[s(1474)](63,h)|128}}}function $(a,n){let s=t,d=e[s(1068)](ee,a,n.limit),x=a.bytes,g=n[s(1301)];for(let w=0,_=n[s(1599)];e[s(1116)](w,_);w++)x[e.lqxCR(w,d)]=g[w]}function se(a){let n=t;return a[n(1301)][e[n(516)](Z,a,1)]}function Je(a,n){let s=t,d=e[s(953)](ee,a,1);a[s(1301)][d]=n}function xe(a){let n=t,s={CjAGY:function(d,x){return e.WjBIK(d,x)},CyrZG:function(d,x,g){return e[j(1592)](d,x,g)},RMgVf:function(d,x){return e[j(1347)](d,x)}};if(e[n(806)](n(1446),e[n(1400)])){let d=0,x=_0x34108b,g=_0xeaf01a+4;for(;s.CjAGY(x,g);){let{value:w,offset:_}=s[n(1748)](_0x2b22a7,_0x2e6f5e,x);x=_,d=s.RMgVf(d<<8,0),d+=w}return{value:d,offset:g}}else{let d=0,x=0,g;do g=e.LafLO(se,a),d<32&&(x|=e[n(820)](e[n(1933)](127,g),d)),d+=7;while(e[n(691)](128,g));return x}}function he(a,n){let s=t;if(e[s(1787)](e[s(1327)],e.kddVh)){for(n>>>=0;e[s(1134)](n,128);)e[s(1001)](Je,a,e[s(425)](e[s(1609)](127,n),128)),n>>>=7;e[s(1463)](Je,a,n)}else this[s(1171)+"rs"]={}}function vt(a,n){let s=t,d=0,x=0,g=0,w;return w=e[s(692)](se,a),d=e[s(1474)](127,w),e[s(963)](128,w)&&(w=e.RqekL(se,a),d|=(127&w)<<7,e[s(925)](128,w)&&(w=e[s(1828)](se,a),d|=e[s(1857)](127,w)<<14,e.pXLkb(128,w)&&(e[s(1099)](e[s(1874)],e[s(938)])?(this[s(1107)]=_0x572f79,this._pathKey=_0x55d40c,this[s(890)]=_0x4989f6?_0x52cd0c:_0x868b19?_0x2a60cb:null):(w=se(a),d|=e[s(884)](e[s(1747)](127,w),21),e[s(925)](128,w)&&(w=e.JGrSL(se,a),x=e.kgtUq(127,w),e[s(1228)](128,w)&&(w=e[s(930)](se,a),x|=e[s(1389)](e[s(1880)](127,w),7),e[s(1474)](128,w)&&(w=e[s(547)](se,a),x|=e[s(691)](127,w)<<14,128&w&&(w=e[s(1464)](se,a),x|=e[s(820)](e.dpxFn(127,w),21),e[s(1212)](128,w)&&(w=e[s(946)](se,a),g=127&w,e[s(1369)](128,w)&&(w=e[s(447)](se,a),g|=e.NTBfc(127,w)<<7)))))))))),{low:e[s(891)](d,e[s(1530)](x,28)),high:e[s(1633)](e[s(664)](x,4),e.ocNzF(g,24)),unsigned:n}}function ut(a,n){let s=t,d={qRHBQ:s(1892)+"t"};if(e[s(806)](e[s(1433)],e[s(1433)])){let x=_0x184adc(d[s(1176)],{message:"start"});this["onStartR"+s(674)]&&this[s(1854)+s(674)](x)}else{let x=n[s(1744)]>>>0,g=e[s(861)](e[s(1731)](n[s(1744)],28),n[s(983)]<<4)>>>0,w=n[s(983)]>>>24,_=w===0?e[s(1905)](0,g)?e[s(1841)](x,16384)?x<128?1:2:x<2097152?3:4:e[s(1891)](g,16384)?e[s(1116)](g,128)?5:6:g<2097152?7:8:e.RBItd(w,128)?9:10,h=ee(a,_),v=a.bytes;switch(_){case 10:v[e[s(1741)](h,9)]=e[s(706)](e[s(664)](w,7),1);case 9:v[e[s(588)](h,8)]=e[s(995)](9,_)?128|w:127&w;case 8:v[e[s(420)](h,7)]=e[s(1259)](8,_)?e.YYxGe(e.rRygJ(g,21),128):e[s(1202)](e[s(837)](g,21),127);case 7:v[e.soGgr(h,6)]=e[s(594)](7,_)?e[s(971)](e[s(1733)](g,14),128):e[s(1103)](g>>>14,127);case 6:v[e.mtpuJ(h,5)]=e[s(767)](6,_)?e[s(1422)](e[s(715)](g,7),128):e[s(691)](e[s(1467)](g,7),127);case 5:v[h+4]=e[s(1319)](5,_)?e[s(466)](128,g):e.ZTMPs(127,g);case 4:v[e[s(1707)](h,3)]=_!==4?e[s(821)](x>>>21,128):e[s(1360)](e[s(693)](x,21),127);case 3:v[e[s(844)](h,2)]=e.FGmha(3,_)?e[s(430)](e[s(1731)](x,14),128):e[s(1175)](e[s(881)](x,14),127);case 2:v[e[s(1459)](h,1)]=_!==2?e[s(604)](x>>>7,128):e[s(1789)](e[s(1110)](x,7),127);case 1:v[h]=e[s(1458)](1,_)?e.BaZuW(128,x):127&x}}}function Xt(a){let n=t,s={TIKyH:function(d,x){return d==x},rFbhG:e[n(1356)]};return e[n(1481)]===e.pttqb?s.TIKyH(n(1065),typeof _0xd14f25)?s.rFbhG:"":S(a)}function Bt(a){return e[t(1233)](A,a)}let Qt=65536,Wr=e.dTslh,me=e.CUwvS(Qt,Qt),Ie=e.KZups(me,me),Jn=Ie/2,Pe=String.prototype[t(785)+"At"];class fe{constructor(n,s,d){let x=t;this[x(1783)]=!0,this[x(1744)]=e.JxANv(0,n),this[x(983)]=e[x(1095)](0,s),this[x(1061)]=!!d}static[t(1783)](n){let s=t;return n&&e[s(807)](!0,n[s(1783)])}static[t(1724)](n,s,d){return new fe(n,s,d)}static[t(1370)+"s"](n,s,d){let x=t;return d?fe[x(1370)+x(702)](n,s):fe[x(1370)+x(1401)](n,s)}static[t(1370)+"sLE"](n,s){let d=t;return new fe(e.TAcwE(e.uowWc(n[0],e[d(536)](n[1],8)),e[d(636)](n[2],16))|e.jihgB(n[3],24),e[d(891)](e[d(1885)](e.KSlNo(n[4],e[d(590)](n[5],8)),n[6]<<16),e.jihgB(n[7],24)),s)}static[t(1370)+t(1401)](n,s){let d=t;return new fe(e[d(1538)](e[d(500)](e[d(466)](e[d(1530)](n[4],24),n[5]<<16),e.KczEy(n[6],8)),n[7]),e[d(430)](e[d(1163)](e[d(1067)](e.cCAkt(n[0],24),e[d(590)](n[1],16)),n[2]<<8),n[3]),s)}static[t(1148)](n){let s=t;return n===Wr?$d:new fe(e[s(791)](e[s(1216)](e.WSuEN(e.uQDWM(Pe[s(1697)](n,0),e[s(1184)](Pe[s(1697)](n,1),8)),e[s(820)](Pe[s(1697)](n,2),16)),e[s(884)](Pe.call(n,3),24)),0),e.gfcvx(e[s(431)](e[s(1497)](Pe[s(1697)](n,4),e[s(1184)](Pe[s(1697)](n,5),8))|e[s(1824)](Pe[s(1697)](n,6),16),Pe[s(1697)](n,7)<<24),0),!0)}[t(1434)](){let n=t;return String[n(795)+n(1032)](e[n(1360)](255,this[n(1744)]),e.cugVb(e[n(812)](this[n(1744)],8),255),e[n(1110)](this[n(1744)],16)&255,e.uAfBd(this.low,24),e.ZCwQg(255,this.high),e[n(1533)](e.eHYUk(this[n(983)],8),255),e[n(1360)](e[n(856)](this[n(983)],16),255),e[n(1467)](this[n(983)],24))}static[t(1890)+"er"](n,s=!0){let d=t;if(isNaN(n))return s?up:$d;if(s){if(e[d(1134)](n,Ie))return xp}else if(e[d(1271)](e[d(920)],d(1489))){if(e[d(1246)](n,-Jn))return hp;if(e.uvJxi(n+1,Jn))return fp}else try{this[d(890)]?.close(),this[d(890)]=void 0}catch(x){_0x22f6bf[d(1482)](x)}return fe[d(1724)](e[d(958)](n%me,0),e[d(466)](e[d(869)](n,me),0),s)}[t(696)](){let n=t;return this.unsigned?e[n(588)](e[n(1248)](this[n(983)],0)*me,this.low>>>0):e.esWzS(e.jBIWc(this[n(983)],me),e[n(715)](this[n(1744)],0))}[t(1571)](){let n=t;return this[n(983)]===0&&e[n(827)](0,this.low)}add(n){let s=t;fe.isLong(n)||(n=fe[s(1890)+"er"](n));let d=e[s(666)](this[s(983)],16),x=65535&this.high,g=e[s(779)](this[s(1744)],16),w=65535&this[s(1744)],_=e[s(779)](n[s(983)],16),h=e[s(1797)](65535,n[s(983)]),v=n.low>>>16,L=e[s(1178)](65535,n[s(1744)]),B=0,z=0,G=0,re=0;return re+=e[s(1459)](w,L),G+=e.LGiuW(re,16),re&=65535,G+=e.mBkOL(g,v),z+=e.hNowf(G,16),G&=65535,z+=e[s(1251)](x,h),B+=e[s(1330)](z,16),z&=65535,B+=d+_,B&=65535,fe.fromBits(G<<16|re,e[s(1124)](e.XrCjZ(B,16),z),this[s(1061)])}[t(723)](n){let s=t,d={kmoLc:function(x,g){return e.xBRqV(x,g)}};if(e.ABxQs(e.vAnfL,e[s(986)]))return fe[s(1783)](n)||(n=fe[s(1890)+"er"](n)),e[s(1154)](this[s(1061)],n[s(1061)])&&e[s(1187)](e[s(715)](this[s(983)],31),1)&&e[s(1187)](e[s(1467)](n[s(983)],31),1)?!1:e.yqPGm(this[s(983)],n[s(983)])&&e[s(1563)](this[s(1744)],n[s(1744)]);_0x203569+=WrRdDR[s(1732)](_0x2a7bfa,_0x56760b),_0x3973eb++}[t(1676)](){let n=t;return e.euNXW(-1,this[n(1744)])&&e[n(408)](-1,this[n(983)])?fe[n(1724)](0,0,this[n(1061)]):this.low===-1?fe[n(1724)](0,this.high+1,this[n(1061)]):fe.fromBits(e.ERelb(this[n(1744)],1),this[n(983)],this[n(1061)])}[t(415)](n){return n?this[t(1586)+"E"]():this.toBytesBE()}[t(1586)+"E"](){let n=t,s=this.high,d=this[n(1744)];return[e[n(1136)](255,d),d>>>8&255,e[n(706)](e[n(1347)](d,16),255),e[n(837)](d,24),e[n(1369)](255,s),e[n(1224)](e[n(1115)](s,8),255),e[n(1747)](e[n(1077)](s,16),255),e[n(791)](s,24)]}[t(900)+"E"](){let n=t,s=this.high,d=this.low;return[e[n(949)](s,24),e[n(1296)](s,16)&255,e[n(664)](s,8)&255,e[n(691)](255,s),e[n(867)](d,24),e[n(1802)](d,16)&255,e.HudGP(d,8)&255,255&d]}}let $d=new fe(0,0,!1),up=new fe(0,0,!0),fp=fe[t(1724)](-1,2147483647,!1),xp=fe.fromBits(-1,-1,!0),hp=fe[t(1724)](0,-2147483648,!1);var en=(function(a){let n=t,s=e[n(444)][n(606)]("|"),d=0;for(;;){switch(s[d++]){case"0":a[a[e[n(824)]]=5005]=e[n(824)];continue;case"1":a[a[n(1418)+n(749)]=5002]=e.BBVaY;continue;case"2":a[a[e[n(1698)]]=5001]=e[n(1698)];continue;case"3":return a;case"4":a[a[n(1143)+n(1058)+"R"]=5003]=e[n(1445)];continue;case"5":a[a[e.APHjG]=5004]=n(804)+"ERROR";continue}break}})({});class Zn{constructor(n){let s=t;this[s(458)]=n,this.target=null}}class Vd extends Zn{constructor(n,s){let d=t;super(n),this[d(1901)]=s&&s[d(1901)]||null}}class Jd extends Zn{constructor(n,s){let d=t,x=(d(482)+"5|4|1")[d(606)]("|"),g=0;for(;;){switch(x[g++]){case"0":this[d(1822)]=s&&s[d(1822)]||null;continue;case"1":this[d(1914)]=s&&s[d(1914)]||5001;continue;case"2":super(n);continue;case"3":this[d(746)]=s&&s[d(746)]||0;continue;case"4":this.message=s&&s[d(1901)]||"";continue;case"5":this[d(1279)]=s&&s[d(1279)]||0;continue;case"6":this[d(1547)]=s&&s[d(1547)]||"";continue}break}}}class Zd extends Zn{constructor(n,s){let d=t;e[d(815)]===e[d(815)]?(super(n),this.code=s&&s[d(1914)]||0,this[d(1273)]=s&&s[d(1273)]||"",this[d(740)]=s&&s[d(740)]||!1,this.willReconnect=s&&s[d(1274)+d(1231)]||!1):_0x2b6f0d[d(1482)](_0x4eec88)}}class Yd extends Zn{constructor(n,s){let d=t;super(n),this[d(1551)]=s&&s[d(1551)]||null}}class Xd extends Yd{constructor(n,s){let d=t;super(n),this[d(1551)]=s&&s[d(1551)]||null,this[d(1901)]=s&&s[d(1901)]||null}}class Qd extends Zn{constructor(n,s){let d=t;super(n),this[d(1551)]=s&&s[d(1551)]||null}}function ot(a,{message:n,code:s,error:d}){let x=t;return e[x(512)]!==e[x(626)]?new Jd(a,{message:n,code:s,error:d}):(_0x844358.writeUint8?_0x399c10.writeUint8(_0x2fd7f8,_0x51ff6d):_0x149c5a[_0x4e5269]=255&_0x90b8eb,e[x(745)](_0x191b43,1))}function ft(a,{code:n,reason:s,wasClean:d,willReconnect:x}){let g=t;if(e[g(1154)](e.PMNwN,g(1444))){let w=_0x10b846[_0x2edbdc];if(e[g(1502)](4,_0x2b2f22[_0x3f932f][g(1594)])){let _=_0x1e5958.substring(0,4-_0x3eccc0[_0x260c4b][g(1594)]),h=_[g(1335)](w);_0x189442=_0x280bca.concat(h)}else _0x4a1b8a=_0x5ac50d[g(1335)](w)}else return new Zd(a,{code:n,reason:s,wasClean:d,willReconnect:x})}function el(a,{data:n,message:s}){return new Xd(a,{data:n,message:s})}function tl(a,{data:n}){let s=t,d={VLEoh:e[s(1412)],bYeZp:e[s(1191)],ANaeE:e[s(1367)],xiVLJ:function(x){return x()},OWERc:e[s(1862)]};if(e[s(460)]("qmjIm",e.aeBJi))return new Qd(a,{data:n});{let x={fjAsT:function(h){return h()}},g=()=>{let h=s;_0x40581a[h(981)+h(1600)+h(1201)](tdiAKF[h(1438)],w),_0x558110[h(981)+h(1600)+"ner"](tdiAKF[h(694)],_),_0x52da34[h(981)+h(1600)+"ner"](h(888),_)},w=()=>{_0x48ecc2(),x.fjAsT(g)},_=()=>{let h=s;_0x159399(_0x3c0887.error||new _0x3f62c4(tdiAKF.ANaeE,tdiAKF[h(603)])),tdiAKF[h(1408)](g)};_0x999a22[s(1765)+s(1442)](tdiAKF.VLEoh,w),_0xfb1278["addEvent"+s(1442)](tdiAKF[s(694)],_),_0x523f25[s(1765)+s(1442)](tdiAKF.OWERc,_)}}function ca(a,{message:n}){return new Vd(a,{message:n})}class nl{constructor(n,s){let d=t;this[d(1471)+"s"]=n,this[d(1495)+"es"]=s,this[d(1078)+d(1377)]=0,this.currentEndpointTriesCount=0}[t(1478)+t(1295)+"fig"](){let n=t;this[n(1078)+n(1377)]=0,this[n(1929)+n(1602)+n(1236)+"t"]=0}resetTries(){let n=t;this[n(1929)+n(1602)+n(1236)+"t"]=0}[t(1485)+t(1197)+"nt"](){let n=t;return this[n(1471)+"s"][this[n(1078)+n(1377)]]}[t(1485)+t(1197)+t(1019)+"ount"](){let n=t;return this[n(1929)+n(1602)+n(1236)+"t"]}[t(643)+t(1782)+"es"](){let n=t;return!!(e[n(1290)](this[n(1078)+n(1377)],this.endpoints[n(1594)])||e.cOLbM(this["currentI"+n(1377)],this.endpoints[n(1594)]-1)&&e[n(1784)](this[n(1929)+"ndpointT"+n(1236)+"t"],this[n(1495)+"es"]))}["checkCur"+t(1518)+t(1118)+"hedMaxRe"+t(1037)](){let n=t;return e[n(1042)](this[n(1078)+n(1377)],this[n(1471)+"s"][n(1594)])?!0:e[n(1915)](this["currentE"+n(1602)+"riesCount"],this[n(1495)+"es"])}[t(1597)+t(1552)+t(1223)+"UpdateCo"+t(1864)](){let n=t;return this[n(1929)+"ndpointT"+n(1236)+"t"]=1,this["currentI"+n(1377)]++,this[n(1471)+"s"][this["currentI"+n(1377)]]}[t(1485)+t(1197)+t(670)+"ateCount"](){let n=t;if(e.FXgCk(e.eDBvK,e.rqovZ))return this[n(1929)+n(1602)+n(1236)+"t"]++,this[n(1485)+"ntEndpoint"]();this[n(1685)]&&this._socket[n(1858)]({code:_0xc4780f,reason:_0x28e107})}}let Yn=(e[t(1505)]!=typeof globalThis&&e[t(460)](e[t(793)],globalThis[t(546)+"tor"][t(493)])||t(1303)+"d"!=typeof window&&e.ADtEB(e[t(793)],window[t(546)+t(1642)][t(493)]))&&t(1303)+"d"!=typeof document,In=e[t(1505)]!=typeof globalThis&&(e[t(1063)]("Object",globalThis[t(546)+"tor"][t(493)])||e.ypmlI(e[t(1195)],globalThis[t(546)+t(1642)][t(493)]))&&e[t(1238)](e[t(1505)],typeof tt),Kr=(e[t(1505)]!=typeof globalThis&&e.PjziK(e[t(726)],globalThis[t(546)+t(1642)][t(493)])||e[t(1331)](e.Yyako,typeof globalThis)||e[t(741)](e[t(1505)],typeof globalThis)&&!!globalThis[t(561)+t(1869)])&&e[t(1505)]!=typeof wx,$r=e[t(1238)](t(1303)+"d",typeof globalThis)&&(e[t(1461)](e[t(1195)],globalThis[t(546)+t(1642)].name)||e[t(479)](t(1654)+t(1112)+t(1840),globalThis[t(546)+t(1642)][t(493)])||e[t(1721)](e.vSjBT,globalThis[t(546)+t(1642)][t(493)]))&&e[t(1505)]!=typeof self,pp=e[t(998)](e[t(1505)],typeof globalThis)&&e[t(578)](e[t(726)],globalThis.constructor[t(493)])&&e[t(1048)](e.Yyako,typeof global)&&e[t(726)]===global[t(546)+t(1642)][t(493)]&&e.RRPii(e[t(1505)],typeof process)&&!!process[t(1817)];class da{constructor(){let n=t;this[n(1171)+"rs"]={}}[t(1050)](n,...s){let d=t,x=this[d(1171)+"rs"][n];if(x)x[d(1079)]()[d(1333)](g=>g.fn.apply(g.ctx,s));else if(e[d(1553)](d(1822),n)&&!this.onerror){let g=s[d(1594)]&&s[0];if(e[d(462)](g,Error))throw g;let w=new Error(e.ERelb(e.IMYqe,g?e[d(1239)](e[d(805)](" (",g.message),")"):""));throw w[d(522)]=g,g}return this}[t(1240)](n,s){let d=t;if(e.YNDBs(void 0,n))this[d(1171)+"rs"]={};else if(e[d(827)](void 0,s))this[d(1171)+"rs"][n]=null;else{let x=this[d(1171)+"rs"][n];if(x)for(let g=0;e[d(404)](g,x[d(1594)]);)e[d(1755)](x[g].fn,s)?x[d(922)](g,1):++g}return this}on(n,s,d){let x=t;return(this[x(1171)+"rs"][n]||(this._listeners[n]=[]))[x(1285)]({fn:s,ctx:d||this}),this}}class gp extends da{[t(1706)+t(633)+t(455)](n){let s=t;return n.errMsg||n[s(1261)]?("message: "+(n.errMsg||"")+s(817)+(n[s(1261)]||""))[s(700)]():JSON[s(587)+"y"](n)}constructor(n,s,d){let x=t;super(),this[x(1685)]=null,Kr&&wx[x(641)+"ocket"]&&(this[x(1685)]=wx["connectS"+x(576)]({url:n,protocols:s,header:d,fail:this[x(1149)+x(421)+x(480)].bind(this),success:this[x(1149)+x(1033)+x(1621)+"ler"][x(714)](this)})),In&&tt[x(641)+x(576)]&&(this[x(1685)]=tt[x(641)+x(576)]({url:n,protocols:s,header:d,fail:this[x(1149)+"ocketFai"+x(480)][x(714)](this),success:this[x(1149)+x(1033)+x(1621)+x(1569)][x(714)](this)}))}[t(1149)+t(1033)+t(1621)+t(1569)](){let n=t;Promise.resolve()[n(477)](()=>{this[n(1913)+"steners"]()})}[t(1149)+t(421)+t(480)](n){let s=t;Promise[s(1714)]()[s(477)](()=>{let d=s,x=e[d(912)](ot,e[d(1191)],{message:this[d(1706)+d(633)+d(455)](n)});this[d(1050)](e[d(1191)],x);let g=e[d(1475)](ft,e[d(1517)],{reason:this[d(1706)+d(633)+d(455)](n)});this[d(1050)](e[d(1517)],g)})}[t(1913)+t(941)](){let n=t,s={LxugI:n(1341),pIvsg:function(d,x,g){return e.VYyNe(d,x,g)},HWcFF:e[n(1517)],YfIqy:function(d,x,g){return e.jqoml(d,x,g)},VczeG:function(d,x){return e[n(408)](d,x)},oGwJD:e[n(1792)],fDUsv:"error"};this._socket[n(411)](d=>{let x=n;this[x(1050)](s.LxugI,s[x(622)](tl,s.LxugI,{...d,data:d.errMsg||""}))}),this[n(1685)][n(1041)](d=>{let x=n;this[x(1050)](s[x(1587)],s[x(1558)](ft,x(1858),{...d}))}),this[n(1685)][n(1835)+"e"](d=>{let x=n;this.emit(x(1901),e[x(912)](el,e.jovmX,{...d}))}),this._socket[n(1093)](d=>{let x=n,g={wNyPt:function(w,_,h){return w(_,h)},QQZfd:function(w,_,h){return s[j(622)](w,_,h)},xdeRg:function(w,_,h){return w(_,h)}};s.VczeG(s[x(926)],x(701))?this[x(1050)](s.fDUsv,ot(s[x(1555)],{...d,message:d.errMsg||""})):(ZqOtSa[x(1469)](_0x871677,_0xa28889,66),ZqOtSa.QQZfd(_0x5b2f4b,_0xcc0e43,_0x441de1[x(1594)]),ZqOtSa[x(1280)](_0x2b0d15,_0x4d4150,_0x5eb9e9))})}[t(1614)](n){let s=t,d={CrwlD:e.SrZAk,HrkTW:e[s(1323)],bkmxJ:function(g,w){return e.xPYdR(g,w)},trGSr:e[s(978)],rxMxz:function(g,w,_){return g(w,_)},eXOAP:e.FBqJh,ZzJYT:e[s(1191)]};if(e.WUSIC(e[s(1884)],e[s(1823)]))for(var x in _0x375b0b)_0x55a534.o(_0x5d0c4a,x)&&!_0xe64e1d.o(_0x272216,x)&&_0x43387e[s(1343)+s(1249)](_0x1396b3,x,{enumerable:!0,get:_0x3d0af6[x]});else if(e[s(462)](n,Uint8Array))if(s(885)!=="TVvHG"){let g=n.buffer[s(1079)](n[s(1773)+"et"],n.byteLength+n.byteOffset);this[s(1685)]&&this._socket.send({data:g,fail:w=>{let _=s;e[_(1532)](e.RqiGg,e[_(1324)])?this[_(1050)](e[_(1191)],e.vmvgp(ot,e[_(1191)],{message:this[_(1706)+_(633)+_(455)](w)})):this[_(1131)]&&this[_(1131)][_(1858)](_0x49ff28,_0x428f09)}})}else{let g={YSXaU:function(h,v){return d[s(1818)](h,v)},QLKxi:d.trGSr,DAucu:d[s(1194)]};this[s(1105)+s(531)](),this["_pingPon"+s(910)+"Id"]=d[s(1487)](_0x3da1e9,this._ping.bind(this),this[s(972)][s(1907)+s(1625)]);let w=()=>{let h=s;_0xccadd1(d[h(492)]),this.off(d[h(1194)],w),this[h(1240)](h(984)+h(1300)+"t",_)},_=()=>{let h=s;g[h(646)](_0x1e1e2b,g.QLKxi),this[h(1240)](g.DAucu,w),this[h(1240)](h(984)+h(1300)+"t",_)};this.on(d[s(1194)],w),this.on(d[s(1362)],_),this[s(1853)]()}else this._socket&&this[s(1685)].send({data:n,fail:g=>{let w=s;this.emit(w(1822),ot(d[w(994)],{message:this["_formatE"+w(633)+w(455)](g)}))}})}close(n,s){let d=t;this[d(1685)]&&this._socket[d(1858)]({code:n,reason:s})}["addEvent"+t(1442)](n,s){let d=t;if(e[d(1147)](e[d(1515)],e.AIMKl))this.on(n,s);else return this._ws?this[d(1131)][d(1312)]:""}["removeEventListe"+t(1201)](n,s){this[t(1240)](n,s)}get[t(1375)+"te"](){let n=t;return this._socket[n(1375)+"te"]}get[t(1353)+"pe"](){let n=t;return this[n(1685)][n(1353)+"pe"]}set[t(1353)+"pe"](n){}get[t(523)](){return this[t(1685)].url}get[t(1312)](){return this._socket.protocol}get[t(765)+"ns"](){return this._socket.extensions}get["buffered"+t(545)](){return 0}}function mp(a,n){let s=t;if(n)return new n(a[s(523)],a[s(1312)]);if(e[s(597)](Kr,In))return new gp(a[s(523)],a[s(1312)],a[s(528)]);if(e[s(597)](Yn,$r)&&s(1303)+"d"!=typeof WebSocket&&WebSocket)return new WebSocket(a[s(523)],a.protocols)}function wp(a){let n=t,s=e[n(1309)][n(606)]("|"),d=0;for(;;){switch(s[d++]){case"0":if(a)return!0;continue;case"1":if(Kr&&wx["connectS"+n(576)])return!0;continue;case"2":if(e.CyFYw(Yn,$r)&&e[n(1270)](e[n(1505)],typeof WebSocket)&&WebSocket)return!0;continue;case"3":if(In&&tt[n(641)+"ocket"])return!0;continue;case"4":return!1}break}}function rl(a,n,s){let d=-1;async function x(g){let w=j,_={XOqzh:function(h,v,L,B){return e.GWvgD(h,v,L,B)},oHSGE:function(h,v){return e.sEVkK(h,v)}};if(e[w(399)](e[w(1876)],e[w(1254)])){let h=255&_0x1fee27;_.XOqzh(_0x346bb0,h,_0x3010ed,_[w(398)](_0x158ee5,_0x5bfeff)),_0x3552a6>>>=8,_0x4a6327--}else return e[w(809)](g,d)?Promise[w(513)](new Error(e[w(586)])):(d=g,e.PjziK(g,s[w(1594)])?Promise[w(1714)]():s[g].bind(a)(n,x[w(714)](null,e[w(1217)](g,1))))}x(0)}function il(a){let n=t,s=0,d=0;for(let x=0;x<a[n(1594)];++x)d=a[n(785)+"At"](x),e[n(581)](d,128)?s+=1:e[n(520)](d,2048)?s+=2:e[n(1528)](e.kgtUq(64512,d),55296)&&e[n(408)](e.CzDuL(64512,a[n(785)+"At"](e[n(644)](x,1))),56320)?(++x,s+=4):s+=3;return s}function sl(a,n,s){let d=t,x={HvLHE:function(g,w){return g(w)},efYZQ:e[d(601)],iqrFA:function(g,w,_){return e.vIEQX(g,w,_)},ujNJh:d(984)+"e_timeout"};if(e[d(1910)]!==e[d(1142)]){if(e.donZQ(e[d(1151)](s,n),1))return"";let g="";for(let w=n;e[d(1075)](w,s);){let _=a[w++];if(_<=127)g+=String[d(795)+"Code"](_);else if(e.Ziujt(_,192)&&e[d(581)](_,224))g+=String[d(795)+"Code"](e[d(1086)](e[d(1800)](e.tFIeC(31,_),6),63&a[w++]));else if(e[d(1134)](_,224)&&e.donZQ(_,240))g+=String["fromChar"+d(1032)](e[d(1928)](e[d(1729)](e[d(1220)](e[d(1026)](15,_),12),e[d(1677)](e[d(653)](63,a[w++]),6)),e[d(727)](63,a[w++])));else if(e[d(1814)](_,240)){let h=e.iRHeh(e.HIzTn(e[d(449)](7,_)<<18,e.Aytvv(e[d(1533)](63,a[w++]),12))|e[d(555)](63&a[w++],6),e[d(1120)](63,a[w++]))-65536;g+=String[d(795)+"Code"](e[d(942)](55296,e[d(1645)](h,10))),g+=String[d(795)+d(1032)](56320+(1023&h))}}return g}else{let g={SEfbS:function(w,_){return w(_)}};return new _0x33ee8e((w,_)=>{let h=d,v={zBEdx:function(z,G){return x[j(1383)](z,G)},hsoAe:x.efYZQ,encVi:h(984)+"e_success"};this[h(1105)+h(531)](),this[h(736)+"gTimeoutId"]=x[h(1924)](_0x591c8e,this[h(1853)][h(714)](this),this._options[h(1907)+h(1625)]);let L=()=>{let z=h;v[z(1460)](w,v.hsoAe),this[z(1240)](v[z(556)],L),this[z(1240)]("ping_once_timeout",B)},B=()=>{let z=h;g[z(1651)](_,"timeout"),this.off("ping_onc"+z(501)+"s",L),this[z(1240)](z(984)+z(1300)+"t",B)};this.on(h(984)+h(501)+"s",L),this.on(x[h(1935)],B),this[h(1853)]()})}}function la(a,n,s){let d=t,x=s,g,w;for(let _=0;_<a.length;++_)if(g=a[d(785)+"At"](_),e.RBItd(g,128))n[s++]=g;else if(e[d(1887)](g,2048))n[s++]=e.OWKHV(e[d(1658)](g,6),192),n[s++]=e[d(1885)](63&g,128);else if(e[d(1528)](e[d(1120)](64512,g),55296)&&e[d(1534)](e[d(1727)](64512,w=a[d(785)+"At"](_+1)),56320))if(e[d(1461)](e[d(1615)],e[d(1615)])){let h=e.UnyBO[d(606)]("|"),v=0;for(;;){switch(h[v++]){case"0":n[s++]=e[d(1729)](e.mgrtW(e[d(1658)](g,12),63),128);continue;case"1":g=e[d(644)](65536+e.invfj(1023&g,10),e.tFIeC(1023,w));continue;case"2":n[s++]=e[d(1253)](e.sIEcx(g,18),240);continue;case"3":n[s++]=e[d(1121)](e[d(1789)](g>>6,63),128);continue;case"4":n[s++]=e[d(1136)](63,g)|128;continue;case"5":++_;continue}break}}else e[d(1900)](_0x33a33d,this[d(879)+"ionTimeo"+d(908)]),this[d(879)+d(697)+d(908)]=null;else n[s++]=e.McXkA(e[d(1284)](g,12),224),n[s++]=e[d(1015)](e[d(1284)](g,6),63)|128,n[s++]=e[d(990)](e[d(917)](63,g),128);return e[d(1490)](s,x)}async function ol(a){let n=t;if(e[n(1813)]==typeof a){let s=new Uint8Array(e[n(940)](il,a));return e[n(473)](la,a,s,0),s}return e[n(462)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[n(788)],a[n(1773)+"et"],a[n(655)+"th"])}function _p(a){let n=t;try{return e[n(1238)](e[n(1813)],typeof a)&&(e.jwfrr(a,ArrayBuffer)||a[n(788)]&&e[n(1102)](a.buffer,ArrayBuffer))||e[n(1238)]("string",typeof a)?"":(JSON.parse(a),n(1548)+n(996))}catch{return e.CExxS(n(1065),typeof a)?n(1544)+n(1573)+n(1688):""}}let yp=(a,n)=>{let s=t;switch(a){case e.ZgLpo:case e[s(1018)]:return{[s(1007)+a]:1,"x-tt-env":n};default:return{}}};class Ep{constructor(n){let s=t;this[s(728)+s(828)]=n,this.count=0}[t(1769)](){let n=t;this[n(689)]++}[t(643)+t(1320)+"nt"](){let n=t;if(e[n(1082)]("DJLns",e[n(1536)])){this[n(1105)+"ngTimer"](),this[n(736)+n(910)+"Id"]=_0x3612da(this[n(1853)][n(714)](this),this[n(972)][n(1907)+n(1625)]);return}else return e[n(979)](this[n(689)],this["maxLossC"+n(828)])}["resetCou"+t(1803)](n=0){let s=t;this[s(728)+"ount"]=n,this[s(689)]=0}}async function bp(a){let n=t,s={dEaSw:e[n(1920)]};return new Promise(d=>{let x=n,g={lvbnd:function(w,_,h){return w(_,h)}};if(!Yn)return e.oxreX(d,x(558)+"reason");try{if(e[x(1919)](e[x(1659)],e[x(1877)])){let w=document[x(456)+x(574)]("script");window[x(1365)+x(950)]=_=>{let h=x;document[h(400)][h(819)+"ild"](w),window[h(1365)+h(950)]=void 0,d(_&&_[h(932)]||s.dEaSw)},w.type=e[x(1316)],w[x(916)]=e.DynYQ(a[x(1307)](/^ws/,e.ZlOvg),e[x(1076)]);try{document[x(400)]["appendCh"+x(1664)](w)}catch{document[x(400)][x(819)+"ild"](w)}}else return _0x271ae7[x(1301)][cVptgW[x(1062)](_0x40bc6d,_0x872425,1)]}catch{window["frontier"+x(950)]=void 0,e[x(887)](d,e[x(1920)])}})}function tn(a,n,s){let d=t;return!!a?.find(x=>x[d(705)]===n&&x.value===s)}function Xn(a,n){let s=t;return a?.[s(1430)](d=>d[s(705)]===n)?.[s(533)]}let ua=null;async function vp(){let a=t;if(e.BNqZr(a(1436),e[a(1626)]))return ua||(ua=Promise.resolve()[a(477)](Nt[a(714)](Nt,"idb"))),ua;{let n=_0x20da57.message[a(947)];n&&_0x334c8f[a(730)+"rs"](n)}}class Sp extends da{constructor(n,s){let d=t;if(e[d(608)]("lGeai","lGeai"))super(),this[d(1090)]=n,this[d(1581)]=s,this[d(890)]=void 0,this["_initPro"+d(1523)]=null;else return _0x9b657c[d(776)+d(1672)][1]?void 0:_0xefdc06["objectSt"+d(418)](_0x25d346["objectSt"+d(1672)][0])}async openDB(){let n=t;e.XiAZj(e.GCGGL,e[n(1740)])?await this._init():(e[n(543)](_0x36dda3,_0x5a43c6,90),e[n(1262)](_0x42de4d,_0x1891d3,_0x30f20d))}async _init(){let n=t,s={xLXgJ:function(d,x){return e.cOLbM(d,x)},ufzUM:e.cVltB,BFACx:function(d,x,g,w){return e.GWvgD(d,x,g,w)},rHCFN:function(d,x,g){return d(x,g)},lxGug:function(d,x){return e[j(1386)](d,x)}};if(e[n(1187)](e[n(1815)],e[n(1815)])){if(this[n(890)])return;if(this[n(698)+"mise"])return this[n(698)+n(1523)];try{let d=this._dbName,x=this._keyPath;this[n(698)+"mise"]=(async()=>{let g=n;if(s.xLXgJ(s.ufzUM,"iUUaa")){let{openDB:w}=await vp();this[g(890)]=await s.BFACx(w,"frontier_"+d,1,{upgrade(_){let h=g;_[h(792)+h(1342)+"e"](d,{keyPath:x})}})}else throw this[g(879)+g(1101)]=!1,_0x7c886c})(),await this[n(698)+"mise"]}catch(d){e[n(913)]===e[n(1701)]?(mEiViq[n(1796)](_0x4c9202,_0x1bc5aa,96),mEiViq[n(1796)](_0x543275,_0xe4bb0b,mEiViq[n(1355)](_0x155b98,_0x4da7ab))):console[n(1482)](d)}finally{this._initPromise=null}}else return!!this[n(890)]}async[t(416)](n){let s=t,d={PaENb:e.jovmX};try{if(e[s(1670)]("inMAC",s(843)))return await this[s(1663)](),this[s(890)]?.get(this._dbName,n);this[s(1050)](d[s(1021)],_0x4a0b49),this[s(1716)+"e"]&&this[s(1716)+"e"](_0x36d29f)}catch(x){e.ypmlI(e[s(1499)],"jdUcJ")?console.log(x):(this[s(1050)](e[s(1517)],_0x7819df),this.onclose&&this.onclose(_0x401d3a))}}async[t(1241)](n,s){let d=t;return await this[d(1663)](),this[d(890)]?.[d(1426)](this[d(1090)],n)}async[t(1083)](n){let s=t;try{return await this[s(1663)](),this[s(890)]?.delete(this[s(1090)],n)}catch(d){console.log(d)}}async[t(1226)](){let n=t;try{return await this[n(1663)](),this[n(890)]?.[n(1226)](this[n(1090)])}catch(s){console[n(1482)](s)}}async[t(1006)](){let n=t;return await this._init(),this[n(890)]?.[n(1406)+"ys"](this[n(1090)])}async[t(1427)](){let n=t;return await this[n(1663)](),this[n(890)]?.getAll(this[n(1090)])}async[t(1620)](){let n=t;try{this[n(890)]?.[n(1858)](),this._qosDB=void 0}catch(s){console[n(1482)](s)}}get isReady(){let n=t;try{return!!this[n(890)]}catch(s){return console.log(s),!1}}}class Ap{constructor(n,s){let d=t;e[d(1784)](d(1340),d(1806))?(this[d(1638)+d(1245)]=_0x14028d,this._ws&&(this._ws[d(1353)+"pe"]=_0x363f94)):(this[d(1107)]=n,this[d(1648)]=s,this[d(890)]=localStorage)}async[t(944)](){}get[t(1344)](){let n=t;return n(1365)+"_"+this[n(1107)]}async get(n){let s=t,d=this[s(890)][s(680)](this._prefix);return JSON[s(1407)](e[s(734)](d,"{}"))[n]}async[t(1241)](n,s){let d=t,x=this[d(890)].getItem(this[d(1344)]),g=JSON[d(1407)](e[d(734)](x,"{}"));return g[s||n[this[d(1648)]]]=n,this[d(890)][d(1448)](this._prefix,JSON[d(587)+"y"](g)),s||n[this[d(1648)]]}async[t(1083)](n){let s=t,d=this[s(890)][s(680)](this[s(1344)]),x=JSON[s(1407)](e.dSeuL(d,"{}"));return x[n]=void 0,this._qosDB.setItem(this[s(1344)],JSON[s(587)+"y"](x))}async[t(1226)](){let n=t;return this[n(890)][n(1226)]()}async[t(1006)](){let n=t,s=this._qosDB[n(680)](this[n(1344)]),d=JSON[n(1407)](s||"{}");return Object[n(1006)](d)}async[t(1427)](){let n=t,s=this[n(890)][n(680)](this[n(1344)]),d=JSON.parse(s||"{}");return Object[n(1545)](d)}[t(1620)](){return Promise[t(1714)]()}get[t(783)](){return!!this._qosDB}}class Ip{constructor(n,s){let d=t;this._DBName=n,this[d(1648)]=s,this[d(890)]=In?tt:Kr?wx:null}async[t(944)](){}get[t(1344)](){let n=t;return n(1365)+"_"+this[n(1107)]}async[t(416)](n){let s=t,d=this[s(890)]["getStora"+s(1728)](this._prefix);return JSON[s(1407)](e[s(858)](d,"{}"))[n]}async[t(1241)](n,s){let d=t;if(e[d(408)](e.HhaxE,e.CmoJT))return this[d(890)]?.[d(1241)]({message_id:_0x10c890,timestamp:_0x3889f5});{let x=this[d(890)]["getStora"+d(1728)](this[d(1344)]),g=JSON.parse(x||"{}");return g[s||n[this[d(1648)]]]=n,this._qosDB["setStora"+d(1728)](this[d(1344)],JSON[d(587)+"y"](g)),s||n[this[d(1648)]]}}async[t(1083)](n){let s=t,d=this[s(890)][s(452)+s(1728)](this[s(1344)]),x=JSON[s(1407)](e[s(858)](d,"{}"));return x[n]=void 0,this[s(890)][s(737)+"geSync"](this[s(1344)],JSON[s(587)+"y"](x))}async[t(1226)](){let n=t;if(e[n(479)]("WWMVL",e.jGkSW))return this._qosDB[n(1457)+n(1022)]();if(e.SfOsg(_0x557a6e[n(947)],_0x2d6af9)){let s=e[n(589)](this[n(972)][n(865)+n(1299)],_0x2ae931)?{force:!!this._options[n(865)+n(1299)][n(570)],encoding:this[n(972)][n(865)+n(1299)][n(1410)]?this[n(972)]["payloadE"+n(1299)][n(1410)][n(1307)](/\s/g,"")["toLowerC"+n(969)]():""}:{force:!1,encoding:this._options["payloadE"+n(1299)]?this[n(972)]["payloadE"+n(1299)][n(1307)](/\s/g,"")["toLowerC"+n(969)]():""},d=_0x9514ec[n(865)+n(1299)]?_0x22a71e[n(865)+n(1299)][n(1307)](/\s/g,"").toLowerCase():"",x=e[n(1102)](this[n(972)][n(1366)+n(1245)],_0x4fcdf8)?{force:!!this[n(972)]["payloadT"+n(1245)][n(570)],type:this[n(972)][n(1366)+n(1245)].type?this._options[n(1366)+n(1245)][n(458)].replace(/\s/g,"")[n(397)+"ase"]():""}:{force:!1,type:this[n(972)].payloadType?this[n(972)][n(1366)+n(1245)][n(1307)](/\s/g,"")[n(397)+"ase"]():""},g=_0x994711[n(1366)+"ype"]?_0x245bb8[n(1366)+n(1245)].replace(/\s/g,"")[n(397)+n(969)]():"",w=x.force?x.type:g||x[n(458)],_=s[n(570)]?s[n(1410)]:d||s[n(1410)],h=[e.mqwef,e[n(1185)],e[n(1204)],e.innhb],v=[e[n(999)],e[n(1306)]];this[n(972)][n(1652)+n(1871)+n(441)+"ad"]&&h[n(974)](w)&&(!_||v[n(974)](_))?_0x536fc3[n(1153)+n(1424)]=_0x215818(_0x1d0784[n(947)],0,_0x49aa69[n(947)].byteLength):_0x10b137[n(1153)+n(1424)]=""}else _0x434046[n(1153)+n(1424)]=""}async[t(1006)](){let n=t,s={sPnwj:function(d,x){return d instanceof x},tEsdz:e[n(1356)],rVegN:e[n(1185)],HeiBu:e[n(1813)],jUGVC:n(1709)+"e",Knyxx:n(1719),ikbNq:function(d,x,g,w){return e[n(1314)](d,x,g,w)}};if(e.YoKsv(e[n(1631)],"rbRhz")){let d=this[n(890)][n(452)+"geInfoSync"](this[n(1344)]),x=JSON.parse(e[n(467)](d,"{}"));return Object.keys(x)}else{let d=this[n(972)][n(865)+n(1299)]instanceof _0x5fead6?{force:!!this._options[n(865)+"ncoding"][n(570)],encoding:this[n(972)]["payloadE"+n(1299)][n(1410)]?this._options[n(865)+n(1299)][n(1410)][n(1307)](/\s/g,"")[n(397)+"ase"]():""}:{force:!1,encoding:this[n(972)].payloadEncoding?this[n(972)]["payloadE"+n(1299)][n(1307)](/\s/g,"")[n(397)+n(969)]():""},x=_0x266762[n(865)+"ncoding"]?_0xa8c63[n(865)+"ncoding"].replace(/\s/g,"")[n(397)+n(969)]():"",g=s[n(553)](this[n(972)]["payloadT"+n(1245)],_0x2144b9)?{force:!!this._options[n(1366)+"ype"][n(570)],type:this._options[n(1366)+n(1245)][n(458)]?this._options.payloadType[n(458)].replace(/\s/g,"")[n(397)+"ase"]():""}:{force:!1,type:this[n(972)][n(1366)+n(1245)]?this._options.payloadType[n(1307)](/\s/g,"")[n(397)+n(969)]():""},w=_0xb1d121.payloadType?_0x68d009[n(1366)+n(1245)][n(1307)](/\s/g,"")[n(397)+"ase"]():"",_=g.force?g[n(458)]:w||g[n(458)],h=d.force?d[n(1410)]:x||d.encoding,v=[s[n(909)],s[n(1011)],"applicat"+n(996)+n(684)+n(1264),s.HeiBu],L=[s[n(1908)],s.Knyxx];this._options["enableTr"+n(1871)+n(441)+"ad"]&&v[n(974)](_)&&(!h||L[n(974)](h))?_0x4ba0ba[n(1153)+n(1424)]=s[n(866)](_0x8239dc,_0xde1aab[n(947)],0,_0x38e0d3[n(947)].byteLength):_0x4c01d7["textPayl"+n(1424)]=""}}async[t(1427)](){let n=t,s={ScLDH:function(d,x){return d(x)},RTRhv:function(d,x){return d(x)}};if(e[n(1152)](e[n(445)],e.LJysi)){let d=this[n(890)][n(452)+n(563)+"nc"](this._prefix),x=JSON.parse(e[n(467)](d,"{}"));return Object[n(1545)](x)}else return function(d,...x){let g=n,w=_0x2a194a[g(1697)](yVSCGI[g(1574)](_0x50c176,this),d,...x);return _0x44fb9e[g(1241)](w,d[g(1501)]?d[g(1501)]():[d]),yVSCGI[g(1020)](_0x4cbae7,w)}}[t(1620)](){return Promise.resolve()}get[t(783)](){return!!this[t(890)]}}function al(a,n){let s=t;if(e[s(1087)](In,In))return new Ip(a,n);if((Yn||$r)&&e[s(1505)]!=typeof indexedDB)return new Sp(a,n);if(e.VrLZD(Yn,$r)&&e.Yyako!=typeof localStorage)return new Ap(a,n);throw new Error("init QoS"+s(1113)+"d")}class Tp{constructor(){let n=t;if(e[n(732)](e[n(1034)],e[n(686)]))try{e[n(1214)](_0x2a88e6,this,_0x2921a6,[_0xe0d2af,_0x577895,_0x4bdba1])}catch(s){let d=_0xdbc023(e[n(1191)],{message:s[n(1901)],code:_0x1ba64b[n(1757)+"OR"],error:s});this[n(591)+"hErrorEv"+n(602)](d)}else this[n(481)+"lTimeoutId"]=null,this[n(481)+"l"]=36e5,this._qosDB=al(e[n(709)],n(997)+"id")}async[t(481)+t(1385)](){let n=t;e[n(1762)](clearInterval,this[n(481)+n(1665)+"Id"]),this[n(481)+n(1665)+"Id"]=e[n(453)](setInterval,()=>{let s=n;this[s(1045)+s(1186)]()},this[n(481)+"l"])}async[t(944)](){let n=t;await this[n(890)][n(944)]()[n(477)](()=>{let s=n;this[s(481)+s(1385)]()})}async[t(1045)+"ired"](){let n=t;(await this[n(890)]?.[n(1427)]()||[]).filter(({timestamp:x})=>x<Date[n(1382)]())[n(1333)](x=>{let g=n;this[g(890)]?.[g(1083)](x[g(997)+"id"])})}async[t(1083)](n){let s=t;return e.OYxUT(e.oWJus,e[s(1678)])?this[s(890)]?.del(n):new _0x1c7415(_0x79900a)}async[t(1241)](n,s){let d=t;return this[d(890)]?.[d(1241)]({message_id:n,timestamp:s})}async[t(416)](n){return this[t(890)]?.get(n)}async[t(1620)](){let n=t,s={rfHlm:function(d,x){return e[j(589)](d,x)},NwBbU:function(d,x){return e.ldyMI(d,x)},URTDT:function(d,x){return e[j(1829)](d,x)},wLOmA:function(d,x){return e[j(995)](d,x)}};if(e[n(1563)](e[n(1222)],e.jXglG))e[n(1405)](clearInterval,this._intervalTimeoutId),await this[n(890)]?.closeDB();else{if(uYkCGK[n(1535)](_0x344a26,_0x18e9be))return uYkCGK[n(1164)](_0x26fbff,_0xb08d1f);if(_0x5ea9cc[n(1595)](_0x15305e))return _0x7ccaff[n(416)](_0x4a662b);let d=uYkCGK[n(1565)](_0x6ec3af,_0x41b141);return uYkCGK.wLOmA(d,_0x385b5a)&&(_0x1b2035[n(1241)](_0x157094,d),_0x3d7d00.set(d,_0x29d374)),d}}get isReady(){let n=t;if(e[n(442)](e[n(1291)],"ljBag"))return this._qosDB?.[n(783)];if(!this[n(1131)])return;this["_destroy"+n(790)+"t"](_0x282f98,_0x4a7ddd,_0x4fcd79)}}function fa(a){let n=t,s=!!this[n(972)].enableQoS;if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let d=e[n(473)](tn,a[n(1901)][n(528)],"x_frontier_qos","2"),x=d&&e.Xbfvw(tn,a[n(1901)][n(528)],e[n(849)],"1"),g=d&&tn(a.message[n(528)],e.TduoN,"1"),w=g?Xn(a[n(1901)][n(528)],e[n(777)])?.[n(606)](",")[n(1591)](Boolean)||[]:[];return{enabled:s,isQoSMessage:d,isQoSAck:x,isAckCleanupMessage:g,ackMsgIds:w}}async function cl(){let a=t;return this[a(808)+a(1492)]||(this["_QoSMana"+a(1492)]=new Tp),this[a(808)+a(1492)].isReady||await this[a(808)+a(1492)][a(944)](),this[a(808)+a(1492)]}async function Cp(a,n){let s=t,{enableAutoAck:d}=this[s(972)],x=e.bcWVc(tn,a[s(1901)].headers,e[s(758)],"1"),g=e.pzwIj(tn,a[s(1901)][s(528)],"is_ack","1"),w=fa[s(1697)](this,a);if(d&&x){let{SeqID:_,LogID:h,service:v,LogIDNew:L,method:B}=a.message;this._sendAck({SeqID:_,LogID:h,LogIDNew:L,service:v,method:B,headers:[{key:e.eeDOf,value:"1"},{key:e[s(1842)],value:e[s(1564)](L,"")},{key:s(671),value:"0"}]})}g&&!w[s(1230)]&&this[s(591)+s(1867)+s(1745)](a),e[s(1579)](n)}async function Rp(a,n){let s=t;this[s(1361)](e[s(1630)],a[s(1901)]),e[s(534)](n)}async function kp(a,n){let s=t,d=Xt(await ol(a[s(1551)]));try{if(e[s(589)](d[s(947)],Uint8Array)){let x=e.VJePD(this[s(972)][s(865)+"ncoding"],Object)?{force:!!this[s(972)][s(865)+s(1299)][s(570)],encoding:this[s(972)][s(865)+s(1299)][s(1410)]?this[s(972)]["payloadE"+s(1299)][s(1410)][s(1307)](/\s/g,"")[s(397)+s(969)]():""}:{force:!1,encoding:this[s(972)][s(865)+"ncoding"]?this._options[s(865)+s(1299)].replace(/\s/g,"")[s(397)+s(969)]():""},g=d[s(865)+"ncoding"]?d.payloadEncoding[s(1307)](/\s/g,"")[s(397)+s(969)]():"",w=e[s(1419)](this._options[s(1366)+s(1245)],Object)?{force:!!this[s(972)][s(1366)+s(1245)].force,type:this[s(972)][s(1366)+"ype"].type?this[s(972)]["payloadT"+s(1245)].type.replace(/\s/g,"")[s(397)+"ase"]():""}:{force:!1,type:this._options[s(1366)+"ype"]?this._options.payloadType[s(1307)](/\s/g,"")[s(397)+s(969)]():""},_=d[s(1366)+s(1245)]?d[s(1366)+s(1245)][s(1307)](/\s/g,"")["toLowerC"+s(969)]():"",h=w[s(570)]?w[s(458)]:_||w[s(458)],v=x[s(570)]?x.encoding:g||x.encoding,L=[s(1544)+"in;chars"+s(1688),e.sFbaZ,e[s(1204)],e[s(1813)]],B=[e[s(999)],e[s(1306)]];this[s(972)][s(1652)+s(1871)+s(441)+"ad"]&&L[s(974)](h)&&(!v||B[s(974)](v))?d.textPayload=sl(d[s(947)],0,d[s(947)][s(655)+"th"]):d[s(1153)+s(1424)]=""}else d[s(1153)+s(1424)]=""}catch(x){d[s(1153)+s(1424)]="",console[s(1482)](x)}a[s(1901)]=d,e[s(534)](n)}function Dp(a,n,s){let d=t;if(e[d(771)]!==e[d(771)]){let x=/(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}/[d(839)](_0x968026),g=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/.test(_0x5b8fa0);return x?e[d(1390)](_0x34033a,_0x3c5760):g?_0x422dd0(_0x32f682):e[d(1450)]}else{let x=e.EtbPl(s,8192),g=e[d(1911)](x,1),w=null,_=x;return function(h){let v=d;if(e.vKZiu(h,1)||h>g)return a(h);e[v(1915)](e[v(894)](_,h),x)&&(w=e[v(1386)](a,x),_=0);let L=n[v(1697)](w,_,_+=h);return e[v(1933)](7,_)&&(_=e.mfvdX(7,_)+1),L}}}let Pp=4294967295;function Op(a,n,s){let d=t;return e[d(1771)](RangeError,e[d(1540)](e[d(1768)](e[d(1414)]+a+e.CGhOr+e[d(1564)](n,1),e[d(618)]),s))}function Lp(a,n,s){let d=t;if(e.PPYUx(e[d(882)],d(717)))return this[d(1131)]?this._ws[d(523)]:this[d(759)];{if(e[d(599)](s,Pp))throw new Error(e[d(1506)]);let x=3;for(;e[d(979)](x,0);){let g=255&s;e[d(1314)](ha,g,a,n+x),s>>>=8,x--}return e[d(1013)](n,4)}}function Np(a,n){let s=t,d=0,x=n,g=e[s(1561)](n,4);for(;e.BqRNc(x,g);){let{value:w,offset:_}=xa(a,x);x=_,d=e[s(536)](d,8)>>>0,d+=w}return{value:d,offset:g}}function Mp(a,n,s){let d=t,x=e[d(549)][d(606)]("|"),g=0;for(;;){switch(x[g++]){case"0":if(!a)return s;continue;case"1":if(n[d(1166)])return e.qMgTX(n[d(1166)](a,s),s);continue;case"2":if(e.xzRWB(a[d(1594)],40))return e[d(644)](e[d(412)](la,a,n,s),s);continue;case"3":return e.rtrIn(e[d(1074)](la,a,n,s),s);case"4":if(n[d(507)+"e"])return e[d(1768)](n.utf8Write(a,s),s);continue}break}}function Bp(a,n){let s=t;if(e[s(995)](e.yUHFz,e.yUHFz))this["maxLossC"+s(828)]=_0x4d1e68,this.count=0;else{let d=new fe(e[s(502)](e[s(1932)](e[s(1010)](a[e[s(1749)](n,4)],24),e[s(820)](a[e[s(1315)](n,5)],16)),a[e[s(1013)](n,6)]<<8)|a[e[s(644)](n,7)],e.tWoeK(e[s(555)](a[e[s(894)](n,0)],24)|e[s(1435)](a[e[s(1749)](n,1)],16)|a[e[s(1239)](n,2)]<<8,a[e[s(1707)](n,3)]),!0);return n+=8,{value:d,offset:n+8}}}function Fp(a,n,s){let d=t,x=a.low,g=a[d(983)];return n[s]=e[d(976)](g,24),n[e.LyBqf(s,1)]=e[d(575)](g>>>16,255),n[e.gTFiQ(s,2)]=e[d(1609)](e[d(1004)](g,8),255),n[e[d(660)](s,3)]=e[d(1797)](255,g),n[e[d(747)](s,4)]=x>>>24,n[s+5]=e[d(666)](x,16)&255,n[e[d(1510)](s,6)]=e[d(1224)](e.SGOPi(x,8),255),n[e[d(644)](s,7)]=255&x,s+=8,s}function xa(a,n){let s=t;return e.Quknb(e[s(559)],e[s(1209)])?a[s(1387)+"8"]?{value:a.readUInt8(n),offset:n+1}:{value:e[s(1703)](255,a[n]),offset:e[s(1043)](n,1)}:_0x464914?.[s(1430)](d=>d[s(705)]===_0x364041)?.value}function ha(a,n,s){return n[t(1337)+"t8"]?n.writeUint8(a,s):n[s]=e.hLjWl(255,a),s+1}let zp=function(a){return new Uint8Array(a)},Up=e[t(1795)](e[t(1505)],typeof Buffer)?Buffer[t(656)+t(1155)]:e[t(614)](Dp,zp,Uint8Array[t(1682)+"e"][t(875)]);(()=>{let a={jgQMI:e.qjNFz,UCghU:function(s,d){return e[j(914)](s,d)},uPnIs:function(s,d){return e[j(1519)](s,d)},upGgt:function(s,d,x,g){return s(d,x,g)},FqVmN:function(s,d){return e[j(1321)](s,d)},iixGm:function(s,d){return e.HzaEo(s,d)},RkWBF:function(s,d){return e.bkUka(s,d)},BrUmn:function(s,d){return e[j(731)](s,d)},RfTqS:function(s,d){return s|d},pzHlc:function(s,d){return e[j(504)](s,d)},Wjlkr:function(s,d){return e.YsrMA(s,d)},iTjon:function(s,d){return e[j(1395)](s,d)},AIHPG:function(s,d){return s&d},bLiXz:function(s,d){return e.tuhyY(s,d)},GQnwD:function(s,d){return s<<d}},n=4294967295;return function(s,d,x=!0){let g=j,w=a.jgQMI[g(606)]("|"),_=0;for(;;){switch(w[_++]){case"0":if(s[d++]<128)return{value:x?n:0|n,offset:d};continue;case"1":n=a.UCghU(127,s[d])>>>0;continue;case"2":if(a.uPnIs(d+=5,s[g(1594)]))throw d=s[g(1594)],a[g(1739)](Op,d,10,s[g(1594)]);continue;case"3":if(a[g(1570)](s[d++],128))return{value:x?n:0|n,offset:d};continue;case"4":if(s[d++]<128)return{value:x?n:a[g(1479)](0,n),offset:d};continue;case"5":if(s[d++]<128)return{value:x?n:a[g(1641)](0,n),offset:d};continue;case"6":if(a[g(1570)](s[d++],128))return{value:x?n:a[g(1641)](0,n),offset:d};continue;case"7":n=a[g(1627)](a.RfTqS(n,a[g(550)](127&s[d],14)),0);continue;case"8":n=a[g(544)](a.iTjon(n,a[g(550)](a[g(1051)](15,s[d]),28)),0);continue;case"9":n=a[g(754)](a[g(1479)](n,a[g(550)](127&s[d],21)),0);continue;case"10":return{value:x?n:0|n,offset:d};case"11":n=a.bLiXz(a[g(1883)](n,a[g(1605)](127&s[d],7)),0);continue}break}}})();let Gp=16,pa=32;function qp(a){let n=t,s=0,d={};for(let x=0;e[n(454)](x,a[n(1594)]);x++)d[a[x][n(1656)+n(928)]]=e[n(1196)](il,a[x][n(1656)+"ame"]),s+=e[n(624)](14,d[a[x][n(1656)+"ame"]]);return[s,d]}function dl(a,n,s){let d=t,[x,g]=e[d(1081)](qp,a),w=e[d(1233)](Up,x),_=0;return a.forEach(h=>{let v=d,L=e[v(768)][v(606)]("|"),B=0;for(;;){switch(L[B++]){case"0":console[v(1482)](e[v(863)],_);continue;case"1":_=Mp(h["cursor_n"+v(928)],w,_);continue;case"2":console[v(1482)](e[v(1059)],_);continue;case"3":console[v(1482)](v(1680)+v(493),_);continue;case"4":console[v(1482)](e[v(830)],h,h[v(1923)]);continue;case"5":console[v(1482)](e[v(1144)],_);continue;case"6":_=e[v(511)](Fp,fe[v(1890)+"er"](h[v(508)]||n),w,_);continue;case"7":_=Lp(w,_,h[v(1923)]||0);continue;case"8":console.log(e[v(1440)],_);continue;case"9":_=e[v(977)](ha,0,w,_);continue;case"10":_=e[v(1122)](ha,g[h[v(1656)+v(928)]],w,_);continue}break}}),{frameType:pa,headers:[{key:e[d(562)],value:s}],payload:w}}function Hp(a){let n=t,s=0,d=[];for(;e[n(582)](s,a[n(655)+"th"]);){let{offset:x}=e[n(1225)](xa,a,s);s=x;let g={cursor_name:"",cursor:0,service:0},{value:w,offset:_}=e[n(677)](Np,a,s);g[n(1923)]=w,s=_;let{value:h,offset:v}=e[n(1068)](xa,a,s);s=v,g[n(1656)+n(928)]=e[n(712)](sl,a,s,s+h),s+=h;let{value:L,offset:B}=e[n(744)](Bp,a,s);g[n(508)]=L[n(696)](),s=B,d.push(g)}return d}function jp(){let a=t;return e.dmKuV(a(886),e[a(1038)])?{frameType:pa,headers:[{key:e[a(562)],value:e.RRshu}],payload:void 0}:new _0x3ed184(e.HBOqm(e.TbBQm(_0x1a999b[4],24)|_0x334f12[5]<<16,_0x278167[6]<<8)|_0xfcd5b8[7],e[a(1598)](e[a(627)](e[a(1677)](_0xe1e999[0],24),e[a(600)](_0x1bd147[1],16))|e[a(1737)](_0xee1ef9[2],8),_0x2a7336[3]),_0x1a538e)}class Wp{constructor(n,s,d){let x=t;this[x(720)+x(571)]=n,this[x(1639)+x(491)]=s,this[x(488)+"Strategy"]=d,this[x(890)]=e[x(1394)](al,this[x(720)+"ameSpace"],"cursor_n"+x(928))}async[t(944)](){let n=t,s={PHmKR:function(d,x,g){return e[j(753)](d,x,g)}};if(e.bfnAB(e[n(1064)],e[n(1064)]))await this[n(890)][n(944)]();else{let d=s[n(905)](_0x4057d3,n(1822),{message:_0x34be4e[n(1901)],code:_0x354163[n(1757)+"OR"],error:_0x2ed0e2});this["_dispatchErrorEv"+n(602)](d)}}async getCursors(){let n=t;if(!this._qosDB[n(783)])return;let s=this[n(488)+"Strategy"],d=await this[n(890)][n(1427)]();switch(console[n(1482)](e[n(1902)],d),s){case e.AximA:return d&&d.length?e.OyONJ(dl,d,0,this[n(1639)+n(491)]):void 0;case n(1798):return;case e.SEtkK:return d&&d.length?e[n(778)](dl,d,0,this[n(1639)+n(491)]):jp()}}async[t(1241)](n,s,d){let x=t;return console.log(e[x(1332)],n,s,d),this[x(890)].set({cursor_name:n,cursor:s,service:d})}async[t(730)+"rs"](n){let s=t,d=Hp(n);for(let x of d)console.log(s(679)+"r",d),await this[s(890)][s(1241)](x)}async[t(416)](n){let s=t;return(await this[s(890)][s(416)](n))?.[s(508)]}async closeDB(){await this._qosDB.closeDB()}["updateCu"+t(1926)+t(1012)](n){let s=t;if(e.FXgCk(e[s(1527)],e[s(1527)])){let{type:d}=_0x515200;this[s(1050)](d,_0x58844a)}else this[s(1639)+s(491)]=n}get[t(783)](){let n=t;if(e.FpWim(n(1666),"IluPi"))return this[n(890)][n(783)];this._isBrowser&&_0x15a4a7[n(1765)+n(1442)](e[n(650)],this[n(1269)+n(711)]),this[n(1810)+"er"]&&_0xf76161.addEventListener(e.eBSki,this._handleOffLine),this[n(1810)+"er"]&&_0x3c9912.addEventListener(e[n(1480)],this[n(1030)+"ageHide"]),this[n(1810)+"er"]&&_0x120123["addEvent"+n(1442)](e[n(1145)],this[n(1030)+n(1821)])}}let Kp=e[t(1653)];async function ll(a){let n=t,s={KQliu:function(d,x){return e.LUiOj(d,x)}};if(e[n(1670)](e[n(1182)],e.Jhhmz)){let d=this[n(1171)+"rs"][_0x4828e1];if(d)d[n(1079)]()[n(1333)](x=>x.fn[n(1027)](x.ctx,_0x3847a3));else if(e[n(642)](n(1822),_0x35c211)&&!this[n(1345)]){let x=_0x4e3053[n(1594)]&&_0x3d5b95[0];if(e[n(1419)](x,_0xa6e234))throw x;let g=new _0x3f05a0(e.efOPf(e[n(1650)],x?e[n(1488)](e.ggioO(" (",x[n(1901)]),")"):""));throw g[n(522)]=x,x}return this}else{if(!this[n(972)][n(1413)+"S"])return null;let{aID:d,fpID:x,messageStrategy:g}=this[n(972)],w=e[n(991)](a,Kp);try{if(n(1918)===n(1918))return this[n(682)+"anager"]?a&&this[n(682)+n(566)][n(475)+n(1926)+n(1012)](a):this[n(682)+n(566)]=new Wp(x+"_"+d+"_"+w,w,g),this[n(682)+n(566)].isReady||await this[n(682)+n(566)][n(944)](),this[n(682)+n(566)];{let _=_0x44a0fc[n(880)+"g"](0,XmnpCw[n(1799)](4,_0x456d0a[_0x55b460][n(1594)])),h=_[n(1335)](_0x2348a7[_0x36d410]);_0x2d5608[n(1285)](h)}}catch{return null}}}async function $p(a,n){let s=t,d={TQtri:e.KChvv,fBnLe:function(x,g){return e[j(1879)](x,g)},jchwn:e[s(1873)],ZixQT:e.DWKdF};if(e[s(642)](s(1268),e[s(1088)])){let x=this[s(890)][s(452)+s(1728)](this[s(1344)]),g=_0x116326[s(1407)](e.VrLZD(x,"{}"));return g[_0x2f580c]=void 0,this._qosDB[s(737)+s(1728)](this[s(1344)],_0x27d653[s(587)+"y"](g))}else{let x=e[s(712)](tn,a[s(1901)].headers,e[s(1206)],"-1"),g=e.AoeQd(tn,a[s(1901)][s(528)],e[s(648)],"1"),w=e[s(953)](Xn,a[s(1901)][s(528)],e[s(1398)]),_=Number(e[s(912)](Xn,a[s(1901)].headers,"x_fronti"+s(911)))||0,h=fa[s(1697)](this,a),v=e[s(473)](tn,a[s(1901)][s(528)],e[s(1576)],"2"),L=e[s(895)](Xn,a[s(1901)].headers,e[s(1073)]),B=e[s(634)](Number,Xn(a[s(1901)][s(528)],e[s(429)]));if(h.isQoSAck)return e[s(417)](n);let z=h[s(1894)+s(1096)]?await cl.call(this):null;if(e[s(781)](a[s(1901)][s(1923)],0)&&g&&!x||e[s(1381)](a[s(1901)][s(1923)],0)){if(w&&h[s(1894)+"sage"]&&z){if(e.JzLDn(s(748),e.WzXGQ))return!!!await z.get(w)&&(this[s(591)+s(1612)+s(945)](a),await z[s(1241)](w,e.rtrIn(Date[s(1382)](),_))),e[s(1702)](n);{let G=_0x31b221["createEl"+s(574)](s(1786));_0x4ea95e[s(1365)+s(950)]=re=>{let ve=s;_0x58ab07.body["removeCh"+ve(1664)](G),_0x3e1caa[ve(1365)+"JSONP"]=void 0,_0x1fafca(re&&re.msg||ve(558)+ve(1273))},G[s(458)]=ZJGRfa[s(1778)],G[s(916)]=ZJGRfa[s(485)](_0x213cc6[s(1307)](/^ws/,ZJGRfa.jchwn),ZJGRfa.ZixQT);try{_0x26352c.body[s(1276)+"ild"](G)}catch{_0x38ce5a[s(400)][s(819)+s(1664)](G)}}}if(v){let G=await ll[s(1697)](this);if(!G)return this[s(591)+"hMessage"+s(945)](a),e.XDmRG(n);let re=await G[s(416)](L)??-1;if(re<B)e[s(923)](e[s(1168)],e[s(1168)])?(this[s(591)+s(1612)+"Event"](a),G[s(1241)](L,B,a[s(1901)][s(1923)])):this[s(1913)+s(941)]();else throw new Error(s(1693)+s(1486)+s(423)+B+(s(690)+"than loc"+s(1129)+"r ")+re);return n()}return this[s(591)+s(1612)+s(945)](a),n()}}}async function Vp(a,n){let s=t,d=fa[s(1697)](this,a);if(!d.isQoSMessage)return n();let x=await cl.call(this);if(d[s(1318)+s(1931)+s(455)]&&d[s(956)+"s"][s(1594)])for(let g of d[s(956)+"s"])await x.del(g);n()}async function Jp(a,n){let s=t,d=a[s(1901)][s(710)+"e"]===Gp,x=e[s(903)](a[s(1901)][s(710)+"e"],pa);if(e[s(774)](!d,!x))return e.zptdI(n);let g=e[s(1463)](Xn,a.message[s(528)],e[s(562)]);if(!g)return e[s(1579)](n);let w=await ll[s(1697)](this,g);if(!w)return e[s(1531)](n);if(d){let _=await w[s(1431)+"rs"](),h={frameType:_?.["frameType"],SeqID:fe[s(1890)+"er"](this[s(1661)]++),LogID:fe[s(1890)+"er"](this[s(972)][s(752)+s(1753)]()),service:9e3,method:5,headers:_?.[s(528)],payload:_?.[s(947)]},v=e[s(692)](A,h);this._ws&&this[s(1131)][s(1375)+"te"]&&this._ws[s(1614)](v)}if(x)if(e.DZkvq(e.QPDZb,e.SyBnn)){let _=a[s(1901)].payload;_&&w.setCursors(_)}else try{this[s(1131)]&&this[s(1131)][s(1858)](_0x2953d0,_0x3d249f)}catch{}}let Zp=async function(a,n){let s=t;this[s(770)]=!1,e[s(541)](clearTimeout,this["_connect"+s(697)+s(908)]),n()},Yp=async function(a,n){let s=t;if(!this[s(1131)]||e[s(1154)](this[s(1131)][s(1375)+"te"],this[s(403)]))return e.SpDUl(n);let{pingInterval:d}=this[s(972)];this["_endpoin"+s(1363)]?.["resetEnd"+s(1295)+s(739)]();for(let g=0;e[s(1127)](g,this[s(488)+s(1603)][s(1594)]);g++){let w=this[s(488)+s(1603)][g];if(e[s(967)](this._ws[s(1375)+"te"],this[s(403)])&&e[s(1454)](null,w))this[s(1131)]&&this._ws[s(1614)](w),this[s(488)+s(1603)][g]=null;else break}this["_message"+s(1603)]=this[s(488)+s(1603)][s(1591)](g=>!!g),this["_pingPon"+s(910)+"Id"]=e[s(1198)](setTimeout,()=>this[s(1853)](),d),this[s(591)+"hOpenEvent"](a),this._isBrowser&&this[s(1131)]&&(this[s(1131)].binaryType=this["_binaryT"+s(1245)]);let x=this[s(678)+"tManager"]?.["getCurre"+s(1197)+"nt"]();this._debug(s(1310)+x+s(1718)),n()},Xp=async function(a,n){let s=t,d=this[s(678)+s(1363)]?.[s(1485)+s(1197)+"nt"]();this[s(1361)](s(1310)+d),e[s(1579)](n)};class Qp extends da{constructor(n){let s=t,d={RyxHQ:function(_,h){return e[j(1071)](_,h)},itlSH:function(_,h,v){return e.EWxgt(_,h,v)},WcPpe:function(_,h,v,L){return e.PjiXH(_,h,v,L)},CtGNr:function(_,h){return e[j(1260)](_,h)},sdllk:function(_,h){return e[j(462)](_,h)},KWkEZ:function(_,h){return e[j(675)](_,h)},mqCfm:e.MTpXY,znIfs:e[s(593)],lKPPo:function(_,h){return e[s(786)](_,h)},gErbP:e.RzqnT,yUqJB:function(_,h){return e[s(672)](_,h)},vFied:function(_,h){return e[s(1326)](_,h)},oUnnJ:e[s(1323)],wKTCG:e.KUhlI,Hsdkf:e[s(1372)],CSkpN:function(_,h,v,L){return e.Xbfvw(_,h,v,L)},oaVmw:function(_,h,v){return e[s(499)](_,h,v)},LnuYR:function(_,h){return e[s(1919)](_,h)},vknxa:s(1720),VMoLH:function(_,h){return _===h},lXScx:e[s(713)],PNOHh:function(_,h,v){return _(h,v)},IfHtk:"close",VnDFr:function(_,h,v){return e[s(516)](_,h,v)},XANTb:e[s(530)],wmadw:function(_,h){return e[s(1560)](_,h)},tqUWH:e[s(871)],ysAsh:e[s(703)],zLIkq:function(_,h){return e[s(1057)](_,h)},vgJEh:function(_,h,v){return _(h,v)},hbgIJ:e[s(1191)],UvXAl:function(_,h){return _!==h},nRtBn:s(1100),sFAom:function(_,h,v){return e[s(615)](_,h,v)}};super(),this[s(889)+s(629)+s(1392)]=!0,this._isBrowser=Yn,this._isNode=pp,this[s(1849)+"T"]=In,this[s(1542)+"X"]=Kr,this[s(1696)+"r"]=$r,this[s(488)+"Queue"]=[],this[s(678)+"tManager"]=null,this[s(1903)+s(1667)]=!1,this[s(1638)+s(1245)]=e[s(486)],this[s(879)+s(1101)]=!1,this[s(879)+"ionTimeoutId"]=null,this[s(789)+"ctTimeoutId"]=null,this[s(736)+s(910)+"Id"]=null,this[s(1661)]=0,this._isInit=!1,this[s(759)]="",this[s(808)+s(1492)]=null,this[s(682)+s(566)]=null,this[s(1420)+"sCounter"]=null,this[s(1297)+"ls"]=e[s(1339)],this[s(517)]=3,this[s(1418)+"NG"]=0,this[s(403)]=1,this[s(1066)]=2,this[s(760)]=_=>{let h=s;try{e[h(1272)](rl,this,_,[Zp,Yp,Xp])}catch(v){let L=e[h(1211)](ot,"error",{message:v[h(1901)],code:en.OPEN_ERROR,error:v});this[h(591)+h(1568)+h(602)](L)}},this[s(756)+"ge"]=async _=>{let h=s,v={PrikJ:function(L,B){return d[j(1215)](L,B)},MIThI:function(L,B){return d[j(532)](L,B)},nvhUZ:d[h(1060)],JjfTL:"objectSt"+h(1672),rVxWu:d.znIfs,zKIFZ:function(L,B){return L(B)}};if(d.lKPPo(h(751),d[h(948)])){let L=0,B=[];for(;yTmSrP[h(1234)](L,_0x4a791a[h(655)+"th"]);){let{offset:z}=_0x3eb0c9(_0x1cc021,L);L=z;let G={cursor_name:"",cursor:0,service:0},{value:re,offset:ve}=_0x41fa35(_0x106d87,L);G[h(1923)]=re,L=ve;let{value:xt,offset:ns}=yTmSrP[h(1875)](_0x53ffe5,_0x3b45e7,L);L=ns,G[h(1656)+h(928)]=yTmSrP.WcPpe(_0x5e24fc,_0x53ba3d,L,yTmSrP[h(548)](L,xt)),L+=xt;let{value:rs,offset:ga}=yTmSrP[h(1875)](_0x2d298d,_0x138292,L);G[h(508)]=rs.toNumber(),L=ga,B[h(1285)](G)}return B}else{let{pingInterval:L,pingFrequency:B}=this[h(972)];if((d[h(668)]("hi",_.data)&&d[h(1662)](h(1637),B)||d[h(532)](h(440),B))&&(this[h(1105)+"ngTimer"](),this[h(1050)](d.oUnnJ,h(719)),this[h(736)+h(910)+"Id"]=setTimeout(this[h(1853)][h(714)](this),L)),_[h(1551)]==="hi")return;try{if(d[h(1662)](d[h(595)],d[h(864)])){if(oXuJCg[h(934)](_0x19859a,_0x8232a)){if(oXuJCg[h(1578)](_0xbc58a2,oXuJCg[h(757)]))return _0x3e396f[h(416)](_0x3bbc44);if(_0x54224e===oXuJCg.JjfTL)return _0x4204b0[h(776)+"oreNames"]||_0xd6678[h(416)](_0x4b00b9);if(oXuJCg[h(1578)](_0x277128,oXuJCg[h(1832)]))return _0x395ebf[h(776)+h(1672)][1]?void 0:_0x837acc["objectSt"+h(418)](_0x3609d2["objectSt"+h(1672)][0])}return oXuJCg[h(1128)](_0x41a0e7,_0x236340[_0x1b727b])}else d[h(1649)](rl,this,_,[kp,Cp,Vp,Jp,$p,Rp])}catch(z){let G=d[h(1052)](ot,"error",{message:z[h(1901)],code:en[h(804)+"ERROR"],error:z});this[h(591)+h(1568)+h(602)](G)}}},this[s(681)]=_=>{let h=s,v={qtppc:function(z,G){return e[j(462)](z,G)},eKJov:function(z,G){return z===G},Uydzz:"done",LauVa:function(z,G){return e[j(967)](z,G)},dCEDC:"store",qZFJp:function(z,G){return e.cIeyH(z,G)}},L=this[h(678)+h(1363)]?.["checkRea"+h(1782)+"es"](),B=this["_endpoin"+h(1363)]?.[h(1485)+h(1197)+"nt"]();if(L&&!_[h(1901)]){if(e[h(1167)]===h(1684))return hCcvwK[h(459)](_0x3c86a5,_0x5460a2)&&(hCcvwK[h(584)](_0x574ad5,hCcvwK[h(800)])||hCcvwK[h(716)](_0x1f4d4c,hCcvwK[h(1411)]))?!0:hCcvwK[h(1322)](_0x174732,_0x594dfa);{let z="connect "+B+(h(1308)+h(1221)+"es reached");this[h(591)+h(1568)+h(602)](e[h(1379)](ot,e.LhfTx,{message:z,code:en[h(1143)+h(1058)+"R"],error:_}));return}}this[h(1131)]&&this[h(1131)][h(1375)+"te"]===this[h(403)]&&this[h(439)+"ect"](),this["_dispatc"+h(1568)+"ent"](e[h(1068)](ot,e[h(1191)],{message:_[h(1901)],code:en["NATIVE_E"+h(840)],error:_}))},this[s(1882)]=async _=>{let h=s,v={QFfaO:function(L,B){return d.yUqJB(L,B)},rWzRg:function(L,B,z){return L(B,z)}};if(d[h(509)](d.vknxa,h(1483))){this["_clearTi"+h(628)](),this[h(1105)+"ngTimer"](),this[h(1583)+h(1348)+"rs"](),this[h(1131)]=null,this[h(879)+h(1101)]=!1;let L=this[h(678)+"tManager"]?.[h(643)+h(1782)+"es"]();if(!L&&this[h(1881)+h(1690)]()&&!this[h(1903)+h(1667)])if(d[h(526)](d.lXScx,d[h(872)])){let B=this[h(678)+h(1363)]?.["getCurre"+h(1197)+"nt"](),z=this[h(972)][h(1892)+h(718)+h(1117)](_[h(1914)],_[h(1273)]);this[h(591)+h(405)+"ent"](d[h(659)](ft,d[h(1705)],{code:1006,reason:_[h(1273)]||h(1070)+h(410)+h(1655)+"wn reaso"+h(1190)+"ame: "+B,willReconnect:z})),z&&this[h(879)]();return}else this.type=_0x262a4b,this.target=null;if(_[h(1914)]!==1e3&&this["_readyCl"+h(1667)]){this["_dispatchCloseEv"+h(602)](d.VnDFr(ft,h(1858),{code:1e3,reason:d[h(1277)]})),this[h(678)+h(1363)]?.[h(1478)+"pointCon"+h(739)](),this["_pingLos"+h(1847)]?.[h(862)+h(1803)]();return}if(_[h(1914)]!==1e3&&L)if(d[h(1839)](d[h(1872)],d[h(1139)])){let B=this._endpointManager?.getCurrentEndpoint(),z=_.reason;z||(z=await d.zLIkq(bp,this._url)),z=h(1070)+h(410)+h(1582)+z+(h(1752)+h(841))+B+(h(1132)+h(773)+"ached"),this["_dispatc"+h(405)+h(602)](d[h(1831)](ft,h(1858),{code:_[h(1914)],reason:z}));let G=h(1017)+B+(h(1308)+"ax retri"+h(577)+"ed");this["_dispatc"+h(1568)+h(602)](d.oaVmw(ot,d[h(1378)],{message:G,code:en[h(1143)+h(1058)+"R"]})),this[h(678)+h(1363)]?.[h(1478)+"pointConfig"](),this[h(1420)+h(1847)]?.[h(862)+h(1803)]();return}else yTmSrP[h(1875)](_0x4faa90,_0xfe912f,58),yTmSrP[h(1052)](_0x53df24,_0x219edd,_0x2d4d99);if(d[h(669)](1e3,_[h(1914)])&&!_.reason)if(d[h(428)]===d[h(428)]){let B=this[h(678)+h(1363)]?.[h(1485)+h(1197)+"nt"]();this[h(591)+h(405)+h(602)](d.sFAom(ft,h(1858),{code:_[h(1914)],reason:"connecti"+h(410)+h(1655)+h(490)+"n, hostn"+h(927)+B})),this[h(678)+h(1363)]?.["resetEndpointCon"+h(739)](),this[h(1420)+h(1847)]?.[h(862)+h(1803)]();return}else return _0x4ff60d&&LBYVFF.QFfaO(!0,_0x200a20[h(1783)]);this[h(591)+h(405)+"ent"](_),this[h(678)+h(1363)]?.[h(1478)+"pointCon"+h(739)](),this._pingLossCounter?.[h(862)+h(1803)]()}else return new _0x2e43f8(L=>{let B=h;v[B(1766)](_0x272a2a,L,this[B(1730)+B(816)+"e"](_0x46bebf))})},this[s(1710)]=null,this[s(1345)]=null,this.onmessage=null,this[s(980)]=null,this["onStartR"+s(674)]=null,this["onReceiv"+s(1906)]=null,this[s(1428)+s(438)+s(1085)+"ct"]=null,this[s(1269)+s(711)]=this["_handleO"+s(711)].bind(this),this[s(1269)+s(1611)]=this[s(1269)+s(1611)][s(714)](this),this[s(1030)+s(1311)]=this[s(1030)+"ageHide"][s(714)](this),this[s(1030)+"ageShow"]=this[s(1030)+s(1821)][s(714)](this),this._options={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e.tLfIv(1,0),service:0,logIDGenerator:o,headers:void 0,payloadEncoding:"",payloadType:"",fpID:"",deviceID:"",accessKey:"",ttwID:"",bddID:"",aID:"",disableAutoReconnect:!1,customParams:{},pingInterval:15e3,pingTimeoutInterval:4e3,pingFrequency:e[s(1293)],pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e.SEtkK,env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:x,ws:g}=n,w=Array[s(1338)](x)?x:e[s(1813)]==typeof x?[x]:[];if(!w||e[s(1441)](0,w.length))throw new Error(e[s(1456)]);if(!e[s(930)](wp,g))throw new Error(e.VtZEH);if(Object[s(1794)](this[s(972)],n),this[s(678)+s(1363)]=new nl(w,this[s(972)].maxRetries),this[s(1420)+s(1847)]=new Ep(this[s(972)][s(1173)+s(474)]),this[s(972)][s(831)+s(733)])if(e[s(1556)](e[s(1723)],e[s(1723)]))this[s(770)]=!0,this[s(879)]();else{let _=e[s(457)].split("|"),h=0;for(;;){switch(_[h++]){case"0":this[s(1903)+s(1667)]=!1;continue;case"1":this[s(1420)+s(1847)]?.[s(862)+s(1803)]();continue;case"2":this[s(770)]=!0;continue;case"3":this[s(879)]();continue;case"4":this[s(678)+s(1363)]?.[s(1478)+s(1295)+s(739)]();continue}break}}this[s(972)][s(1098)+s(1354)+s(1580)]&&(this._isMiniTT||this._isMiniWX?this[s(1247)+s(1040)+s(1404)]():this[s(1810)+"er"]&&this["_initGlo"+s(1130)+s(1442)]())}[t(1269)+t(711)](){let n=t,s={ZGrWY:function(d,x,g,w){return e[j(1214)](d,x,g,w)},uFbOL:e[n(797)],KZItG:n(1852)+n(1807)+"ck",LwDWm:function(d,x,g,w){return e[n(434)](d,x,g,w)},rqsty:function(d,x,g){return d(x,g)},yxybC:e[n(777)]};if(e.PFGhW(e[n(1292)],e[n(1462)])){let d=!!this[n(972)].enableQoS;if(!d)return{enabled:d,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let x=hPhntf[n(1837)](_0x4d4c8a,_0x309874[n(1901)][n(528)],hPhntf[n(1846)],"2"),g=x&&_0x34e08f(_0x200d1e.message[n(528)],hPhntf[n(1889)],"1"),w=x&&hPhntf[n(988)](_0x38520a,_0x55d99b[n(1901)][n(528)],n(1852)+n(637)+"k","1"),_=w?hPhntf[n(857)](_0x361553,_0x535fa0.message.headers,hPhntf[n(564)])?.[n(606)](",")[n(1591)](_0x56b19a)||[]:[];return{enabled:d,isQoSMessage:x,isQoSAck:g,isAckCleanupMessage:w,ackMsgIds:_}}else{if(this[n(972)][n(838)+n(639)+n(1465)]||this[n(1903)+n(1667)])return;this[n(1156)+n(674)]()}}["_handleO"+t(1611)](){let n=t,s={ynOCG:function(d,x){return e[j(660)](d,x)},fkcaT:function(d,x){return e[j(1699)](d,x)},uBaAA:function(d,x){return e.vfyot(d,x)},yqKVn:function(d,x){return e.OeIYG(d,x)},SSjvo:function(d,x){return e[j(1220)](d,x)},kPjMJ:function(d,x){return e.jvNKZ(d,x)},pYccI:function(d,x){return d<x},kGGRQ:function(d,x){return e[j(1364)](d,x)}};if(e[n(598)](e[n(1554)],e.zOcnp))_0x17ae72=_0x3f9179[TWIgMF[n(1604)](TWIgMF[n(1157)](_0x4b70cb,_0x33ef03),1)],TWIgMF[n(1244)](TWIgMF[n(1263)](192,_0x1fd2a4),128)?_0x255ba1+=_0xf42574:(_0x45ed7a=TWIgMF[n(1282)](31&_0x3aeef7,6)|TWIgMF[n(1899)](63,_0xc409ac),TWIgMF[n(904)](_0x4d5fd9,128)?_0x21b9e9+=_0x59fb8f:(_0x3878b7+=TWIgMF.kGGRQ(_0x42c0eb,_0x456812),_0x2fa33f++));else{this[n(1816)+n(790)+"t"]();let d=e.gQSQB(ca,e[n(469)],{message:n(1657)+n(794)+" reconnect"});this[n(1428)+n(438)+n(1085)+"ct"]&&this[n(1428)+n(438)+n(1085)+"ct"](d)}}[t(1500)+t(1130)+t(1442)](){let n=t;this[n(1810)+"er"]&&window["addEvent"+n(1442)](e[n(650)],this[n(1269)+n(711)]),this[n(1810)+"er"]&&window[n(1765)+n(1442)](e.eBSki,this[n(1269)+n(1611)]),this[n(1810)+"er"]&&window[n(1765)+n(1442)](e[n(1480)],this[n(1030)+n(1311)]),this[n(1810)+"er"]&&window[n(1765)+n(1442)](e[n(1145)],this._handlePageShow)}[t(854)+"balEvent"+t(1442)](){let n=t;this[n(1810)+"er"]&&window["removeEv"+n(1600)+n(1201)](n(1613),this[n(1269)+"nLine"]),this._isBrowser&&window[n(981)+n(1600)+n(1201)](n(569),this[n(1269)+n(1611)]),this._isBrowser&&window[n(981)+n(1600)+n(1201)](e.twwTl,this._handlePageHide),this._isBrowser&&window[n(981)+n(1600)+n(1201)](n(667),this[n(1030)+n(1821)])}["_handleP"+t(1311)](n){let s=t;if(!n[s(1283)+"d"]){if(e.mtrTb(s(1429),e[s(560)]))return!!this._qosDB;this._isBrowser&&window[s(981)+s(1600)+s(1201)](e.twwTl,this[s(1030)+s(1311)]),this[s(1810)+"er"]&&window[s(981)+s(1600)+s(1201)](e[s(1145)],this[s(1030)+"ageShow"]),this[s(1858)]()}this[s(1810)+"er"]&&window[s(981)+s(1600)+"ner"]("online",this[s(1269)+s(711)]),this._isBrowser&&window[s(981)+s(1600)+s(1201)](e[s(1439)],this["_handleO"+s(1611)])}[t(1030)+"ageShow"](n){let s=t;n[s(1283)+"d"]&&(this["_navigat"+s(1690)]()&&(!this[s(1131)]||e.XTAKr(this[s(1131)][s(1375)+"te"],this[s(403)])||e[s(1726)](this[s(1131)].readyState,this[s(1418)+"NG"]))&&this[s(1269)+"nLine"](),this[s(1810)+"er"]&&window[s(1765)+s(1442)](e[s(650)],this[s(1269)+s(711)]),this._isBrowser&&window.addEventListener(s(569),this["_handleO"+s(1611)]))}async _generateUrl(n){let s=t;if(e[s(1023)](e[s(902)],s(1624)))this._DBName=_0x410755,this[s(1648)]=_0x5923b9,this._qosDB=_0x1cbd3d;else{let{fpID:d,deviceID:x,bddID:g,ttwID:w,accessKey:_,aID:h,customParams:v={},enableAutoAck:L,enableQoS:B,QoSLevel:z,env:G}=this._options,re,ve,xt;this[s(1810)+"er"]||this[s(1542)+"X"]||this[s(1849)+"T"]?(re=location&&e[s(899)](s(1675),location[s(1312)])?e.DuqOP:e.IbMLu,ve=n[s(1307)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),xt=/^wss(.*:\/\/)/[s(839)](n)?n:""+re+ve):(re=e.DuqOP,ve=n.replace(/(^http)((?:[s]*:\/\/))/,""),xt=/(^ws)((?:[s]*:\/\/))/[s(839)](ve)?ve:""+re+ve);let ns=g?e[s(432)]:w?e.VnGEB:"device_id",rs=g||w||x;if(e[s(772)](!rs,!ns))throw new Error(s(1161)+s(836)+s(846)+"viceID or ttwID");let ga=e.gsYDu(s(1265),typeof v)?await e.XDmRG(v):v,eg=G?e.FMiun(yp,G.xUseEnv,G.xTTEnv):{},ma=Object[s(1794)]({device_platform:e[s(1695)],version_code:s(1687)+"0",access_key:_,fpid:d,aid:h,[ns]:rs,xsack:L?1:0,xaack:L?1:0,xsqos:B?1:0,qos_level:B?z:void 0,qos_sdk_version:2,...eg},ga),tg=Object[s(1006)](ma)[s(632)]((wa,_a)=>ma[_a]!==void 0?""+wa+(wa?"&":"?")+_a+"="+ma[_a]:wa,"");return xt+"/ws/v2"+tg}}async _connect(){let n=t,s={MWLdK:function(d,x){return e[j(1114)](d,x)}};if(!(this[n(879)+n(1101)]||this[n(1903)+n(1667)])){this[n(879)+"Lock"]=!0;try{let d=this["_endpoin"+n(1363)]?.["checkCurrentEndp"+n(1118)+n(1092)+n(1037)](),{timeoutInterval:x}=this._options;if(d){let w=this[n(678)+n(1363)]?.[n(1485)+n(1197)+"nt"](),_=this[n(678)+n(1363)]?.[n(1597)+"ackupEnd"+n(1223)+n(780)+n(1864)](),h=this[n(678)+n(1363)]?.["getCurre"+n(1197)+n(1019)+n(828)]();if(_){let v="connect "+w+(n(409)+n(1132)+n(773)+n(446)+"ill use backup e"+n(567))+_+" to retry",L=ot(e[n(1191)],{message:v,code:en[n(1143)+n(1058)+"R"]});this[n(1361)](v),this["_dispatc"+n(1568)+n(602)](L),this[n(759)]=await this["_generat"+n(937)](_),this._debug(n(1017)+_+" "+h+n(1508)),this[n(1583)+"sListeners"]()}else{let v=n(1017)+w+(n(409)+n(1132)+n(773)+n(505));this[n(1361)](v),this[n(591)+n(1568)+n(602)](e[n(1567)](ot,e[n(1191)],{message:v,code:en[n(1143)+"IES_ERROR"]}));return}}else if(e[n(568)](e[n(1507)],e[n(1507)]))_0x521269(_0x1f17f3,24),_0x1024e9(_0x33588c,TnsvVA.MWLdK(_0x586f21,_0x263fe1));else{let w=this["_endpoin"+n(1363)]?.[n(1485)+n(1197)+n(670)+n(1035)](),_=this[n(678)+n(1363)]?.[n(1485)+n(1197)+"ntTriesC"+n(828)]();this[n(759)]=await this["_generat"+n(937)](w||""),this._debug("connect "+w+" "+_+n(1508)),this[n(1583)+"sListeners"]()}if(this[n(770)])this[n(770)]=!1;else{let w=e.inIPA(ca,e[n(469)],{message:e[n(1550)]});this["onStartR"+n(674)]&&this[n(1854)+"econnect"](w)}let g=this[n(678)+n(1363)]?.["getCurre"+n(1197)+n(1019)+"ount"]()||0;e.fZpki(g,1)&&await this[n(873)](e[n(1610)](g,1)),this[n(1361)](n(1070)+n(1870)+this[n(759)]+(" protoco"+n(1351))+this[n(1297)+"ls"]),this._ws=e[n(1447)](mp,{url:this[n(759)],protocols:[this[n(1297)+"ls"]],headers:this[n(972)][n(654)+n(1623)+"s"]["customHt"+n(435)]},this[n(972)].ws),(this[n(1810)+"er"]||this._isWorker)&&this[n(1131)]&&(this[n(1131)].binaryType=this[n(1638)+n(1245)]),this[n(1913)+"steners"](),this["_connect"+n(697)+n(908)]=e.jjOrn(setTimeout,this[n(1391)+"ut"].bind(this),x)}catch(d){throw this["_connect"+n(1101)]=!1,d}}}[t(1219)+"mer"](){let n=t;e.StjBz(clearTimeout,this[n(879)+"ionTimeoutId"]),this[n(879)+"ionTimeo"+n(908)]=null}[t(1105)+"ngTimer"](){let n=t;e[n(1287)](clearTimeout,this["_pingPon"+n(910)+"Id"]),e[n(538)](clearTimeout,this["_reconne"+n(631)+n(395)]),this[n(736)+n(910)+"Id"]=null,this[n(789)+n(631)+n(395)]=null}[t(1361)](...n){let s=t,d={QPaus:e[s(1191)],nUvUf:function(x,g,w){return x(g,w)}};if(e[s(408)]("PCrny",e.FNzCj))this._options[s(665)]&&console[s(1482)][s(1027)](console,[e[s(1549)],...n]);else{let x=_0x2fb336[s(788)][s(1079)](_0x281947.byteOffset,_0x58998a[s(655)+"th"]+_0x155bbe[s(1773)+"et"]);this[s(1685)]&&this[s(1685)][s(1614)]({data:x,fail:g=>{let w=s;this[w(1050)](zbzSuJ[w(1845)],zbzSuJ[w(1286)](_0x32bf26,zbzSuJ[w(1845)],{message:this[w(1706)+w(633)+w(455)](g)}))}})}}[t(1730)+"rvalValue"](n){let s=t,{initReconnectInterval:d,maxReconnectInterval:x,reconnectIntervalGrowFactor:g}=this._options,w=e[s(851)](d,Math[s(1288)](g,n-1));return w>x?x:w}_ping(){let n=t;if(this[n(1131)]&&e[n(476)](this[n(1131)][n(1375)+"te"],this[n(1418)+"NG"])){this[n(1105)+n(531)](),this["_pingPon"+n(910)+"Id"]=e[n(1618)](setTimeout,this[n(1853)][n(714)](this),this[n(972)][n(1907)+"rval"]);return}if(!this._ws||this._ws[n(1375)+"te"]!==this.OPEN)return void this[n(1156)+n(674)]();this[n(1131)]&&this[n(1131)][n(1614)]("hi"),this["_reconne"+n(631)+"tId"]=setTimeout(this[n(1156)+n(674)+n(1543)].bind(this),this[n(972)][n(1313)+"outInter"+n(1443)])}[t(1156)+t(674)+t(1543)](){let n=t;this[n(1420)+n(1847)]?.[n(1769)](),this[n(1050)](e[n(1779)],"timeout"),this[n(1420)+n(1847)]?.[n(643)+"chMaxCount"]()?this[n(1156)+n(674)]():this[n(1853)]()}["_navigat"+t(1690)](){let n=t;return this[n(1849)+"T"]||this[n(1542)+"X"]?this["_miniNav"+n(629)+n(1392)]:(this._isBrowser||this._isWorker)&&this._options["listenNe"+n(1354)+n(1580)]?navigator[n(1511)]:!0}[t(1156)+t(674)](){let n=t;!this[n(1881)+"orOnline"]()||this[n(1903)+n(1667)]||(this[n(678)+n(1363)]?.[n(1478)+n(1295)+n(739)](),this[n(1420)+"sCounter"]?.["resetCou"+n(1803)](),this[n(1131)]?this["_disconn"+n(1e3)](1001,n(540)+n(464)+"reconnec"+n(1237)+n(803),!0):this[n(879)]())}[t(1247)+t(1040)+t(1404)](){let n=t;this._isMiniTT?tt[n(1218)+"kStatusC"+n(525)](({isConnected:s})=>{let d=n;if(e[d(1154)](d(1805),e[d(964)]))return this[d(1131)]?this[d(1131)].binaryType:this[d(1638)+d(1245)];this[d(889)+"igatorOn"+d(1392)]=s,s?this["_handleO"+d(711)]():this[d(1269)+d(1611)]()}):this[n(1542)+"X"]&&wx[n(1218)+"kStatusChange"](({isConnected:s})=>{let d=n;e[d(1328)](e[d(1848)],e.zktbE)?(this[d(890)]?.close(),this._qosDB=void 0):(this[d(889)+d(629)+d(1392)]=s,s?this[d(1269)+d(711)]():this["_handleO"+d(1611)]())})}_wait(n){let s=t,d={wjCNn:function(x,g){return e[j(1930)](x,g)},NndTD:e.OPfBl};if(e[s(607)](e[s(829)],e.ebxOa)){let x=_0x4462e9[_0x45d3b1++];if(e[s(809)](x,127))_0x2d31b1+=_0x3634ee[s(795)+"Code"](x);else if(e[s(1814)](x,192)&&e.lZHEc(x,224))_0x4f0357+=_0x3eaa99[s(795)+"Code"](e[s(1677)](e[s(653)](31,x),6)|e.QwXJi(63,_0x216f85[_0x2cd3bb++]));else if(e[s(1814)](x,224)&&e[s(1887)](x,240))_0x2afae0+=_0x3c8231[s(795)+s(1032)](e[s(982)](e[s(1686)](e[s(1797)](15,x),12),e[s(1493)](63&_0x37159c[_0x90a739++],6))|63&_0xeaef65[_0x117404++]);else if(e[s(1134)](x,240)){let g=e[s(1490)](e[s(1868)](e[s(1267)](e[s(518)](e.JBDOj(7,x),18),e[s(1737)](e[s(1360)](63,_0x3edc92[_0x51c8e3++]),12)),e[s(1435)](e[s(495)](63,_0x5948d0[_0x31650b++]),6))|e[s(1933)](63,_0x4ddd71[_0x2778b3++]),65536);_0x36f1d5+=_0x3ff1c0[s(795)+"Code"](e[s(745)](55296,e[s(1722)](g,10))),_0x47a388+=_0x210779[s(795)+s(1032)](e[s(1476)](56320,1023&g))}}else return new Promise(x=>{let g=s;if(d[g(1371)](d[g(935)],g(761)))setTimeout(x,this[g(1730)+g(816)+"e"](n));else{let w=_0x51a7da[g(1388)]();return w?(w[g(1758)]=w[g(1599)]=0,w):{bytes:new _0x1dc5a4(64),offset:0,limit:0}}})}[t(439)+t(1e3)](n=1e3,s="",d=!1){let x=t;this._ws&&this["_destroy"+x(790)+"t"](n,s,d)}[t(1391)+"ut"](){let n=t,s=this[n(678)+n(1363)]?.[n(1485)+n(1197)+"nt"]();this[n(1361)](n(1017)+s+n(409)),this[n(439)+n(1e3)](1001,e[n(1302)],!0)}_sendAck(n){let s=t;if(e[s(608)](e[s(617)],e[s(850)]))this[s(1131)]&&this._ws.send(_0x43320b),this[s(488)+s(1603)][_0x3e542e]=null;else{let d=e[s(547)](Bt,n);this[s(1131)]&&e[s(583)](this[s(1131)][s(1375)+"te"],this[s(403)])&&(this[s(1131)]&&this[s(1131)][s(1614)](d),this[s(1361)](e.aIzIh,n))}}[t(1583)+t(1348)+"rs"](){let n=t;if(e[n(619)](e[n(661)],e[n(661)])){let s=e[n(1159)].split("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1131)][n(981)+n(1600)+n(1201)](e[n(1352)],this._onMessage);continue;case"1":this[n(1131)][n(981)+n(1600)+n(1201)](n(1858),this[n(1882)]);continue;case"2":if(!this._ws)return;continue;case"3":this[n(1131)]["removeEv"+n(1600)+n(1201)](e[n(1191)],this[n(681)]);continue;case"4":this[n(1131)][n(981)+n(1600)+n(1201)](e[n(535)],this[n(760)]);continue}break}}else e[n(640)](_0x4c7140,e.SrZAk),this[n(1240)](e[n(1323)],_0x413800),this[n(1240)](n(984)+"e_timeout",_0x344ed3)}[t(1913)+"steners"](){let n=t,s=(n(1622)+"1")[n(606)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1131)][n(1765)+n(1442)](n(1341),this[n(760)]);continue;case"1":this._ws[n(1765)+"Listener"](e[n(1191)],this[n(681)]);continue;case"2":this[n(1131)]["addEvent"+n(1442)](n(1901),this._onMessage);continue;case"3":this[n(1131)][n(1765)+"Listener"]("close",this[n(1882)]);continue;case"4":if(!this[n(1131)])return;continue}break}}[t(704)+t(847)](n=1e3,s=""){let d=t;if(e.VOAVk("QWDNo",e[d(775)]))return this._socket[d(523)];try{this[d(1131)]&&this[d(1131)].close(n,s)}catch{}}["_destroy"+t(790)+"t"](n=1e3,s="",d=!1){let x=t;if(this[x(1105)+"ngTimer"](),this[x(1219)+x(628)](),this[x(1583)+x(1348)+"rs"](),this[x(704)+x(847)](1e3,s),this[x(879)+"Lock"]=!1,d&&this[x(1881)+"orOnline"]()&&!this[x(1903)+x(1667)]){if(this["_endpoin"+x(1363)]?.checkReachMaxTries()){if(x(463)!==x(463))return this[x(1929)+"ndpointT"+x(1236)+"t"]++,this[x(1485)+x(1197)+"nt"]();{let w=this[x(678)+x(1363)]?.[x(1485)+"ntEndpoint"]();this[x(591)+"hCloseEv"+x(602)](e.snEOI(ft,x(1858),{code:1006,reason:x(1017)+w+(x(409)+x(1132)+x(773)+"ached"),wasClean:!0}))}}else{let w=this[x(972)][x(1892)+x(718)+x(1117)](n,s);this[x(591)+"hCloseEv"+x(602)](e[x(1174)](ft,e[x(1517)],{code:n,reason:s,wasClean:!0,willReconnect:w})),w&&this[x(879)]()}return}this["_navigat"+x(1690)]()||this["_readyCl"+x(1667)]?this[x(591)+x(405)+x(602)](e[x(1827)](ft,e[x(1517)],{code:n,reason:e[x(530)]})):this[x(591)+x(405)+x(602)](e[x(822)](ft,e[x(1517)],{code:1006,reason:e[x(929)]})),this._ws=null,this[x(678)+x(1363)]?.[x(1478)+x(1295)+x(739)](),this["_pingLos"+x(1847)]?.[x(862)+x(1803)]()}[t(591)+t(551)+"nt"](n){let s=t;this[s(1050)](s(1341),n),this[s(980)]&&this[s(980)](n)}["_dispatchMessage"+t(945)](n){let s=t;this[s(1050)](e.jovmX,n),this[s(1716)+"e"]&&this[s(1716)+"e"](n)}[t(591)+t(1867)+t(1745)](n){let s=t;this[s(1050)](e[s(1126)],n),this[s(1559)+s(1906)]&&this["onReceiv"+s(1906)](n)}["_dispatc"+t(1568)+t(602)](n){let s=t;this[s(1050)](e[s(1191)],n),this.onerror&&this[s(1345)](n)}["_dispatc"+t(405)+t(602)](n){let s=t;this[s(1050)](e[s(1517)],n),this[s(1710)]&&this[s(1710)](n)}get[t(1353)+"pe"](){let n=t;return this[n(1131)]?this[n(1131)][n(1353)+"pe"]:this[n(1638)+"ype"]}set binaryType(n){let s=t;this[s(1638)+s(1245)]=n,this[s(1131)]&&(this[s(1131)][s(1353)+"pe"]=n)}get[t(1577)+"nt"](){let n=t;return this["_endpoin"+n(1363)]?.["getCurrentEndpoi"+n(1019)+n(828)]()||0}get[t(451)+t(545)](){let n=t,s=this[n(488)+n(1603)][n(632)]((d,x)=>(d+=x&&x[n(655)+"th"]||0,d),0);return e[n(1741)](s,this[n(1131)]?this._ws.bufferedAmount:0)}get[t(765)+"ns"](){let n=t;return this[n(1131)]?this[n(1131)][n(765)+"ns"]:""}get[t(1312)](){return this[t(1131)]?this._ws.protocol:""}get[t(1375)+"te"](){let n=t;return this[n(1131)]?this[n(1131)].readyState:this[n(972)][n(831)+n(733)]?this.CONNECTING:this.CLOSED}get url(){let n=t;return this._ws?this[n(1131)].url:this._url}[t(1858)](n=1e3,s){let d=t;if(this[d(1903)+d(1667)]=!0,this[d(1219)+"mer"](),this[d(1105)+d(531)](),this[d(854)+"balEvent"+d(1442)](),this[d(808)+"ger"]?.[d(1620)](),!this._ws)return void this[d(1361)](e[d(1425)]);if(e[d(1636)](this._ws.readyState,this[d(517)])||e[d(1819)](this._ws.readyState,this[d(1066)]))return void this[d(1361)](e[d(572)]);this[d(1816)+d(790)+"t"](n,s)}async[t(1614)](n,s){let d=t,x={nvXQk:function(g,w){return e[j(979)](g,w)},rjSBF:function(g,w){return g<w},qjHQO:function(g,w){return e.esWzS(g,w)},rXlhX:function(g,w){return e.sYMQH(g,w)},xJEVd:function(g,w){return e[j(1679)](g,w)},JNOFY:function(g,w){return e[j(1036)](g,w)},YCizm:function(g,w){return e[j(1359)](g,w)},nylWS:function(g,w){return g>>w},cmKlX:function(g,w){return e[j(1205)](g,w)},UUxdk:function(g,w){return g|w},XZzzD:function(g,w){return e[j(987)](g,w)},ApNKU:function(g,w){return g&w},rAwkJ:function(g,w){return e[j(687)](g,w)}};if(e.PPaKN!==e.SMNWH){if(n==null)throw new Error(e[d(1229)]);e[d(1484)](e[d(427)],typeof n)&&(n=JSON.stringify(n)),e.innhb!=typeof n&&!(n instanceof ArrayBuffer)&&!(n[d(788)]&&n[d(788)]instanceof ArrayBuffer)&&(n=JSON[d(587)+"y"](n));let g=await e[d(970)](ol,n),w=_p(n),{method:_=0,service:h=this._options[d(1923)],logID:v=this[d(972)]["logIDGen"+d(1753)](),headers:L=this[d(972)][d(528)],payloadEncoding:B=this[d(972)][d(865)+d(1299)],payloadType:z=this[d(972)]["payloadT"+d(1245)],logIDNew:G=this[d(972)][d(1861)+"Config"][d(471)+d(1715)+d(1606)+"ew"]?i(this[d(972)][d(1861)+d(565)][d(1002)]):""}=e[d(858)](s,{});if(!h)throw new Error(e[d(1738)]);let re={SeqID:fe[d(1890)+"er"](this[d(1661)]++),LogID:fe[d(1890)+"er"](v),service:h,method:_,headers:L,payloadEncoding:e.ehmJi(B,Object)?B.encoding?B[d(1410)]:"":B,payloadType:e[d(1102)](z,Object)?z.type?z[d(458)]:w:z||w,payload:g,LogIDNew:G},ve=e[d(930)](Bt,re);return this[d(1131)]&&e[d(992)](this._ws[d(1375)+"te"],this[d(403)])?(this[d(1131)]&&this._ws[d(1614)](ve),this._debug("sent",re)):e[d(1887)](this[d(488)+d(1603)][d(1594)],this._options["maxMessageQueueL"+d(826)])?(this[d(488)+d(1603)][d(1285)](ve),this[d(1361)](e.UJWAl,re)):(this[d(488)+d(1603)].shift(),this["_message"+d(1603)][d(1285)](ve)),{seqID:this[d(1661)],logID:v,logIDNew:G}}else{let g=_0x509b61[d(785)+"At"](_0x319e88);dVeXRa[d(1346)](g,55296)&&g<=56319&&dVeXRa.rjSBF(dVeXRa[d(1094)](_0x500c57,1),_0x2cc51f)&&(g=dVeXRa[d(1084)](dVeXRa.qjHQO(dVeXRa[d(769)](g,10),_0x21d29b[d(785)+"At"](++_0x188ec5)),56613888)),g<128?_0x432638[_0x28615d++]=g:(dVeXRa.rjSBF(g,2048)?_0x45e4cb[_0x1337bb++]=dVeXRa[d(1329)](dVeXRa.YCizm(dVeXRa.nylWS(g,6),31),192):(g<65536?_0xb75647[_0x798a27++]=dVeXRa[d(1368)](dVeXRa[d(616)](dVeXRa[d(1472)](g,12),15),224):(_0xecda37[_0xe0610f++]=dVeXRa.UUxdk(dVeXRa[d(1472)](g,18)&7,240),_0x528389[_0x5a5d13++]=dVeXRa[d(1008)](dVeXRa[d(848)](dVeXRa[d(1472)](g,12),63),128)),_0x107e86[_0x56ecec++]=dVeXRa[d(1053)](g>>6,63)|128),_0x3eddb1[_0x4ba716++]=dVeXRa[d(1008)](dVeXRa.ApNKU(63,g),128))}}async[t(1892)+"t"](n){let s=t,{url:d}=n||{},x=Array[s(1338)](d)?d:e[s(1232)](e.innhb,typeof d)?[d]:[];n&&Object[s(1794)](this[s(972)],n),x&&x.length?this._endpointManager=new nl(x,this[s(972)][s(1495)+"es"]):this["_endpoin"+s(1363)]?.["resetEnd"+s(1295)+s(739)](),this[s(1420)+s(1847)]?.[s(862)+"nter"](this[s(972)][s(1173)+s(474)]),this["_readyCl"+s(1667)]=!1,this._ws&&e[s(860)](this[s(1131)][s(1375)+"te"],this[s(517)])?this._disconnect(1e3,e[s(868)],!0):(this[s(770)]=!0,this[s(879)]())}async connect(){let n=t;if(!this[n(879)+n(1101)]){let s=(n(1384)+"2").split("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1903)+"osed"]=!1;continue;case"1":this[n(678)+"tManager"]?.[n(1478)+n(1295)+"fig"]();continue;case"2":this[n(879)]();continue;case"3":this[n(1420)+n(1847)]?.[n(862)+"nter"]();continue;case"4":this[n(770)]=!0;continue}break}}}["addEvent"+t(1442)](n,s){this.on(n,s)}[t(859)+t(945)](n){let s=t,{type:d}=n;this[s(1050)](d,n)}[t(981)+"entListe"+t(1201)](n,s){this.off(n,s)}[t(1188)](){let n=t,s={YyXQv:function(d,x){return e.kfEof(d,x)},OmAGk:n(1673),ViTqQ:e[n(1774)],lqQne:e[n(601)],rtRvz:e[n(1779)],Lllbv:function(d,x,g){return e[n(453)](d,x,g)},HThuz:e[n(1517)],DNsAq:n(540)+n(1584)+n(1751)+n(1825),qRkHx:function(d,x){return d(x)},mgnDW:n(1746),nxBgn:n(984)+n(501)+"s"};return new Promise((d,x)=>{let g=n,w={bMkui:function(v,L,B){return v(L,B)},gRhEF:function(v,L,B){return s.Lllbv(v,L,B)},orBHm:s.HThuz,ZqZYc:s.DNsAq,hOsmb:function(v,L){return s[j(799)](v,L)},DdjOy:s[g(510)],vaWzh:"ping_onc"+g(501)+"s",RtAXj:s[g(673)]};this[g(1105)+g(531)](),this[g(736)+g(910)+"Id"]=s[g(796)](setTimeout,this[g(1853)][g(714)](this),this._options[g(1907)+g(1625)]);let _=()=>{let v=g;if(s.YyXQv(s.OmAGk,s.ViTqQ))d(s[v(1415)]),this.off(v(984)+v(501)+"s",_),this[v(1240)](s[v(673)],h);else{if(this[v(1105)+v(531)](),this[v(1219)+v(628)](),this[v(1583)+"sListeners"](),this[v(704)+"nceClose"](1e3,_0x3c04aa),this[v(879)+v(1101)]=!1,_0x550dec&&this[v(1881)+v(1690)]()&&!this[v(1903)+v(1667)]){if(this[v(678)+v(1363)]?.[v(643)+v(1782)+"es"]()){let B=this[v(678)+v(1363)]?.[v(1485)+"ntEndpoint"]();this[v(591)+v(405)+v(602)](ttLDVT[v(422)](_0x4a02ee,v(1858),{code:1006,reason:v(1017)+B+(v(409)+v(1132)+v(773)+v(505)),wasClean:!0}))}else{let B=this[v(972)][v(1892)+v(718)+v(1117)](_0x2ff14e,_0x711094);this[v(591)+v(405)+v(602)](ttLDVT[v(1146)](_0x26dae5,"close",{code:_0x20b5f0,reason:_0x2c6b82,wasClean:!0,willReconnect:B})),B&&this[v(879)]()}return}this[v(1881)+"orOnline"]()||this[v(1903)+"osed"]?this["_dispatc"+v(405)+v(602)](ttLDVT.gRhEF(_0x376539,ttLDVT[v(1289)],{code:_0x180a8d,reason:v(1165)})):this["_dispatc"+v(405)+v(602)](ttLDVT.bMkui(_0x52313e,ttLDVT[v(1289)],{code:1006,reason:ttLDVT[v(1133)]})),this[v(1131)]=null,this[v(678)+v(1363)]?.[v(1478)+v(1295)+v(739)](),this[v(1420)+"sCounter"]?.[v(862)+v(1803)]()}},h=()=>{let v=g;w[v(898)](x,w[v(592)]),this.off(w[v(1572)],_),this[v(1240)](w[v(724)],h)};this.on(s[g(1374)],_),this.on(s.rtRvz,h),this[g(1853)]()})}}})(),ke[N(609)+N(514)]=Re[N(609)+N(514)],ke[N(573)+N(1843)]=Re[N(573)+N(1843)],ke[N(919)+"e"]=Re.ErrorCode,ke[N(945)]=Re[N(945)],ke[N(1590)]=Re.FWS,ke[N(647)+N(755)+N(1056)]=Re["FrontierMessageE"+N(1056)],ke[N(755)+N(1056)]=Re[N(755)+N(1056)],ke[N(1585)+"t"]=Re[N(1585)+"t"],ke[N(1589)+"tEvent"]=Re[N(1589)+N(448)],ke.createCloseEvent=Re[N(596)+N(514)],ke[N(1904)+N(1843)]=Re[N(1904)+"rorEvent"],ke["createMe"+N(1669)+"nt"]=Re[N(1266)+N(1669)+"nt"],ke[N(1616)+"enEvent"]=Re[N(1616)+"enEvent"],ke["createRe"+N(818)+N(1056)]=Re[N(1213)+N(818)+N(1056)],ke[N(782)+N(1628)]=Re[N(782)+N(1628)],ke[N(1304)+N(928)]=Re[N(1304)+N(928)];for(Fo in Re)["CustomCl"+N(514),N(573)+N(1843),N(919)+"e",N(945),N(1590),N(647)+"MessageE"+N(1056),N(755)+"vent","OpenEvent",N(1589)+N(448),N(596)+"oseEvent",N(1904)+N(1843),"createMessageEvent",N(1616)+N(1453),"createRe"+N(818)+N(1056),N(782)+N(1628),N(1304)+N(928)][N(735)](Fo)===-1&&(ke[Fo]=Re[Fo]);var Fo;Object[N(1343)+N(1249)](ke,"__esModule",{value:!0})});import{existsSync as aS,openSync as cS}from"node:fs";import{mkdir as dS}from"node:fs/promises";import{dirname as lS}from"node:path";import{fileURLToPath as uS}from"node:url";function xS(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Ld(t=X()){return aS(t.libEntry)?t.libEntry:uS(new URL("../index.ts",import.meta.url))}async function kh(t={}){let e=t.paths??X(),r=t.entryOverride??Ld(e),i=xS(e,process.env.COZE_BRIDGE_LOG_MODE);await dS(lS(i),{recursive:!0});let o=cS(i,"a"),l=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=et(process.execPath,l,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[Xi]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return fS.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var fS,Xi,Jo=Ze(()=>{"use strict";Wt();te();Oe();fS=q("spawn-daemon"),Xi="COZE_BRIDGE_DAEMON"});import{spawn as o1}from"node:child_process";import{mkdir as a1,unlink as c1,writeFile as d1}from"node:fs/promises";import{dirname as l1,join as u1}from"node:path";function Hr(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function f1(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Hr(r)}</key>
|
|
21
|
-
<string>${
|
|
20
|
+
`+r)}function Vn(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let l=new Error(o);Error.captureStackTrace(l,Vn),t.emit("wsClientError",l,r,e)}else Ji(r,i,o,c)}});var _h=ae(Ne=>{"use strict";var M=K;(function(t,e){let r=K,i=t();for(;;)try{if(-parseInt(r(1400))/1*(-parseInt(r(1133))/2)+parseInt(r(1825))/3*(-parseInt(r(1590))/4)+-parseInt(r(1744))/5*(parseInt(r(1372))/6)+-parseInt(r(705))/7*(parseInt(r(707))/8)+parseInt(r(1751))/9+parseInt(r(1846))/10+-parseInt(r(1217))/11*(parseInt(r(1329))/12)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(jo,616720);var kv=Object["definePr"+M(1354)],Cv=Object[M(1668)+M(1294)+"mes"],hh=(t,e)=>function(){return t&&(e=(0,t[{jpNpX:function(c,l){return c(l)}}[M(855)](Cv,t)[0]])(t=0)),e},Rv=(t,e)=>{let r={hjlvc:function(o,c,l,u){return o(c,l,u)}};for(var i in e)r.hjlvc(kv,t,i,{get:e[i],enumerable:!0})};function Dv(){return dh||(dh=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Pv(){let t=M;return lh||(lh=[IDBCursor[t(1081)+"e"].advance,IDBCursor[t(1081)+"e"][t(911)],IDBCursor[t(1081)+"e"]["continue"+t(674)+"ey"]])}function Ov(t){let e=M,r={WHHte:e(751),QIwen:function(o,c){return o===c},MTMdC:e(1804),pIFZl:function(o){return o()},Fomub:function(o,c){return o(c)},eibdR:e(515),pdaVU:function(o,c){return o instanceof c}},i=new Promise((o,c)=>{let l=e,u={rUWsU:r[l(471)]},x=()=>{let E=l;t[E(1189)+"entListe"+E(1315)](E(1908),h),t[E(1189)+E(1566)+"ner"](r.WHHte,m)},h=()=>{let E=l;r[E(1724)]("zUobG",r[E(1771)])?(this._isBrowser&&_0x20e49f[E(1189)+E(1566)+"ner"](u.rUWsU,this[E(1160)+E(1985)]),this[E(1742)+"er"]&&_0x20921e[E(1189)+E(1566)+E(1315)](E(1107),this[E(1160)+E(747)]),this[E(1150)]()):(o(Mt(t.result)),r[E(1159)](x))},m=()=>{let E=l;r[E(1881)](c,t[E(751)]),r[E(1159)](x)};t[l(1893)+l(1405)](l(1908),h),t[l(1893)+l(1405)](r[l(1649)],m)});return i.then(o=>{let c=e;r[c(1585)](o,IDBCursor)&&Td[c(1378)](o,t)})[e(502)](()=>{}),Go[e(1378)](i,t),i}function Lv(t){let e=M,r={rgzyZ:e(941),xVShn:"abort",xAwoO:function(o){return o()},rqflw:function(o,c){return o(c)},pSeew:e(1347)+"or",NiOGE:function(o){return o()},VDXGY:e(988)};if(Uo[e(1714)](t))return;let i=new Promise((o,c)=>{let l=e;if(r.VDXGY!==l(988))return _0x1374c5||(_0x45d8a5=[_0x4ab26d[l(1081)+"e"][l(1603)],_0x5e97e6[l(1081)+"e"][l(911)],_0x557dd1.prototype[l(911)+"PrimaryKey"]]);{let u=()=>{let m=l;t[m(1189)+m(1566)+m(1315)](r[m(1477)],x),t["removeEv"+m(1566)+"ner"](m(751),h),t["removeEv"+m(1566)+m(1315)](r[m(1522)],h)},x=()=>{let m=l;r[m(1316)](o),r[m(1316)](u)},h=()=>{let m=l;r[m(1789)](c,t[m(751)]||new DOMException(r[m(650)],r.pSeew)),r[m(832)](u)};t[l(1893)+l(1405)](r[l(1477)],x),t[l(1893)+"Listener"](l(751),h),t[l(1893)+l(1405)](r.xVShn,h)}});Uo[e(1378)](t,i)}function Nv(t){Ho={zYYIF:function(i,o){return i(o)}}[M(1058)](t,Ho)}function Mv(t){let e=M,r={Bwjse:function(i,o){return i(o)},AJswL:function(i,o){return i(o)},RkeuZ:function(i,o){return i===o},CKAIu:e(1537)+e(1663),PiAzj:function(i){return i()}};return r.RkeuZ(t,IDBDatabase[e(1081)+"e"][e(1984)+e(1610)])&&!(r[e(1005)]in IDBTransaction.prototype)?function(i,...o){let c=e,l=t[c(1832)](r[c(1749)](Yi,this),i,...o);return Ad.set(l,i[c(1128)]?i.sort():[i]),Mt(l)}:r.PiAzj(Pv)[e(463)](t)?function(...i){let o=e;return t.apply(r[o(1749)](Yi,this),i),Mt(Td.get(this))}:function(...i){let o=e;return r.Bwjse(Mt,t.apply(r[o(1858)](Yi,this),i))}}function Bv(t){let e=M,r={JkfFk:function(i,o){return i===o},jTEVh:e(575),cSsss:function(i,o){return i instanceof o},Qnltg:function(i,o){return i(o)},xdeNz:function(i){return i()}};return r.JkfFk(typeof t,r[e(1426)])?Mv(t):(r[e(791)](t,IDBTransaction)&&r[e(1419)](Lv,t),ph(t,r.xdeNz(Dv))?new Proxy(t,Ho):t)}function Mt(t){let e=M,r={rLoeK:function(o,c){return o instanceof c},kGaVK:function(o,c){return o(c)}};if(r[e(1872)](t,IDBRequest))return r[e(1655)](Ov,t);if(Fo[e(1714)](t))return Fo.get(t);let i=Bv(t);return i!==t&&(Fo[e(1378)](t,i),Go.set(i,t)),i}var ph,dh,lh,Td,Uo,Ad,Fo,Go,Ho,Yi,uh=hh({"node_modules/idb/build/wrap-idb-value.js"(){let t=M,e={BwvRx:t(1461),xbsjN:function(r,i){return r===i},XEotO:function(r,i){return r===i},BWRLk:t(1788),IkiWb:function(r,i){return r(i)},NcEka:function(r,i){return r instanceof i},kLbyl:function(r,i){return r===i},cpbmz:function(r,i){return r in i}};ph=(r,i)=>i[t(780)](o=>r instanceof o),Td=new WeakMap,Uo=new WeakMap,Ad=new WeakMap,Fo=new WeakMap,Go=new WeakMap,Ho={get(r,i,o){let c=t;if(r instanceof IDBTransaction){if(i===e[c(752)])return Uo.get(r);if(e[c(1656)](i,"objectStoreNames"))return r[c(1537)+c(1663)]||Ad.get(r);if(e[c(685)](i,e[c(635)]))return o[c(1537)+c(1663)][1]?void 0:o[c(1537)+c(1840)](o[c(1537)+c(1663)][0])}return e[c(587)](Mt,r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t;return e[o(771)](r,IDBTransaction)&&(e[o(1038)](i,"done")||i===e[o(635)])?!0:e[o(1851)](i,r)}},Yi=r=>Go[t(1039)](r)}}),gh={};function K(t,e){t=t-461;let r=jo(),i=r[t];if(K.BOJbaz===void 0){var o=function(x){let h="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",m="",E="";for(let I=0,y,v,A=0;v=x.charAt(A++);~v&&(y=I%4?y*64+v:v,I++%4)?m+=String.fromCharCode(255&y>>(-2*I&6)):0)v=h.indexOf(v);for(let I=0,y=m.length;I<y;I++)E+="%"+("00"+m.charCodeAt(I).toString(16)).slice(-2);return decodeURIComponent(E)};K.voawPa=o,K.UTYbTX={},K.BOJbaz=!0}let c=r[0],l=t+c,u=K.UTYbTX[l];return u?i=u:(i=K.voawPa(i),K.UTYbTX[l]=i),i}Rv(gh,{deleteDB:()=>zv,openDB:()=>Fv,unwrap:()=>Yi,wrap:()=>Mt});function Fv(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let l=M,u={PTWSY:function(m,E){return m(E)},epmIu:l(1150),wLpqZ:l(1988)+"hange",lyfTY:"upgradeneeded",uFUNf:l(1031)},x=indexedDB[l(1641)](t,e),h=Mt(x);return i&&x[l(1893)+l(1405)](u[l(1575)],m=>{let E=l;i(u[E(1156)](Mt,x[E(798)]),m.oldVersion,m.newVersion,u[E(1156)](Mt,x[E(1984)+"ion"]))}),r&&x[l(1893)+l(1405)](u.uFUNf,()=>r()),h[l(923)](m=>{let E=l;c&&m[E(1893)+E(1405)](u[E(605)],()=>c()),o&&m["addEvent"+E(1405)](u[E(474)],()=>o())})[l(502)](()=>{}),h}function jo(){let t=["qMvIAKO","ign1CNnVCIa","BLvXBNq","DM1gD0C","x2zVCM1HDeu","z2fKquS","BMv4DcGPigm","s3HcBgG","CKXVzuS","BNrLCG","wKncr2e","B2zgsvm","rejsrva","ihrPBwvVDxq","DerHAxO","twzxDxC","ChvZAa","rM9TDwi","sLjMAMS","r3jHugq","tgDhz2u","sgjVB04","Cg9PBNrbBMq","Chv0","vK5LEvK","ALzIDKi","CMvQzwn0","u3jRuNy","y29UC3rYDwm","ywrKrxzLBNq","rhv6D2O","qKXbuKG","v2jIv3G","x194x21Zz18","tKrOtu8","x29Ut3bLBG","DNr0uwi","CNzHBfzHBhu","z2vtEw5J","s3zrDuy","ywXS","x1fVu01HBMe","D2LSBfjLy28","tK5IvvC","C3vJy2vZCW","C3nHz2vfDMu","wgv0twm","C3rHCNq","A1HUBLy","zMDUq0u","sMvkEeC","DKzRyuO","s2rhr2m","BwvZC2fNztO","EK1lt0e","wvHQu0S","x3nLBMrby2S","pxv0zI04","CMvHC29U","Axnby2TdBgu","teXtDvm","zKPHr3q","CNrgwLG","y3jLyxrLrxi","vuX6tvu","ywnRpwzYB24","igfYCMf5yNu","rw1ktfa","u1D4CMi","zNjVBu51Bwi","x2rYB3bhBg8","q2j5qKy","sgXkvxe","yLHWu1G","y29UBMvJDca","DfvRtNq","rfzgC3K","ruHyBLy","DMvYC2LVBG","CMvHzhDYAxq","rMnTqwO","CMvHzhLtDge","t1LjzKK","v2Lcq1i","qLvgBee","CxzgA2S","shrnyLO","mxWYFdy","rxDPvuK","BwfUDwfSihi","qwnAtM8","x2HHBMrSzvi","t1f2qu4","DK5prMi","uhnesM8","sgPrs00","zezlvuO","r09szem","tMPqEMW","x3nLCuLK","D2jIuK8","q21ks1y","Bhm6ia","zxrxB3jRq2G","BKvttMS","Agr0AeS","BwvY","ueHtDuS","yuPjCvi","DujgCfy","r2TUEu0","B3nLrxzLBNq","yvn5vxu","C1nOv0W","D3nZoI8V","sxn6D1y","qxvoshO","x29UugfNzu4","x2LUAxq","CgjICdi","DhjHBNnHy3q","ywDLsgLKzq","u3rrrLC","yKPguei","DMvYC2LVBMm","DvnlB2G","rLjptLrjrvi","vK9jtuS","tKz6Bgm","wxDWt1y","wKDfDMm","DwvptfK","D0rpu1G","D3jPDgvvAw4","x2DLDeLUDgu","Aw5JBhvKzxm","uejZr28","BLzSBum","Dxr2yw4","yxjpvxC","y2HnyxHdB3u","B25nzxnZywC","z29sA3K","zwLIzfi","DLfMA3y","swLfCwe","D0XWCvO","CfvAthG","CMv0CNLdB3u","AhjoCe8","sLHSu2S","ALDeugy","zhHsCem","A1voD3O","CMvXDwLYzwq","r0vwA0S","ze5sBeS","C0nVDw50zxi","Bwfnq2S","wKL3wLu","uvDpq0m","r0j1s0y","zNjVBuHHC2G","BLDvDhm","wNHXzfK","CM9YrxzLBNq","zw5HyMXLqxu","BMDLza","C2nVChG","BMCGDxjSoIa","AevYCM9Yrxy","AefJA01LC3m","CuH0suW","DMHlBK0","y2f0y2G","DKn5A0C","t3bLBKv2zw4","rxzLBNq","CfzfAgC","DxPQB3y","DhfNueG","AwXSihvZzsa","BgvUz3rO","ywX3yxLZ","EfLXDKq","vfjkq0C","C2v0zgi","CgfNzwHPzgu","wxjwAgO","yNL0zu9MzNm","tKXpCLO","thb1z08","EuL6Cem","Egznvue","u0fYAKC","C2vYDMLJzq","qvP1r2i","zgzov2q","DffRuNi","DhPbBeC","C2XPy2u","x2nVBM5Ly3q","ENLUEva","BuvTueW","x2nYzwf0zvm","Buf0yKe","qwDQBuS","zw5JB2rLrNi","DeXsD28","zw5HyMXLvhi","qwjHtNu","DgLUzYbZzxi","q0rvwwy","BxnNsuq","z0vmEe8","z0zxBKS","tKDFrvjst1i","BNrfBMrWB2K","EwXctKu","tfDhtMC","tufyx1jfvfi","quD1qNC","BNvTyMvY","z2HIEMS","zMH4zM0","ww9lr2W","z29PBMCGyxC","CYbWyxjHBxm","x29UvgLTzw8","jMPZy2fSBgi","BwfW","CvjfCfy","rezRA24","q2Lpy2q","r1f4A2K","t05jtuW","zv9ZDwnJzxm","tunHDwe","turrDLC","D1flBKK","wMTSy2O","v0TguK4","yxnJCMLWDa","wengyLq","vuHmwMe","yNfeEe4","zhDLzfC","zNvUy3rPB24","z2v0qwXSs2u","tND6tvm","x3bPBMDqB24","r1DtsfC","C2v0q3vYC28","rurHv3i","DfrSsLC","zMX1C2HfEha","nhWY","Bwf4twvZC2e","AxnrB1nnzxm","swTPv2i","zMXVB3i","y3ruAw1LB3u","tvfsq0S","EvPIzuK","v0XMC1i","z1nWBeC","B29ZrxK","uejtz0W","Dg9iyxnO","CuzzEvG","BgHKu2m","tND0Bxy","yxrLq291BNq","De1HBMfNzxi","zxq9DxrMltG","x3DZ","zfPoD0C","zxbTsxu","x21PBMLoyxy","x29Uq2XVC2u","vxbKyxrLq28","vMTWExG","ufnXAe0","ihrYEsbYzwm","AxnFywnR","D3bAAhG","tfnSDMi","Dgv4Dc9Qyxy","DNb4uuC","Ec1TC2CTy3u","B0PmCvy","z1rPBwvVDxq","tfD0Eum","tgvhwum","B25fCNjVCG","B3bLBKrc","txHzDhO","zuz5zgm","uLjpuG","DxHJCha","BMvLzf9Hy2S","y3jLyxrLt3a","y2HLy2TdDxi","D0P0DfC","zhvZwMO","tuf1qLe","x3bHDgHlzxK","qLDstgS","mdaWma","mhWZFdr8mxW","tfbbu0G","tNzfvu0","zu5HBui","vgrXAfK","t0rAAMm","BgLTAxq","ELf0zwi","C3vTv0G","zNjVBujPDhm","t1bTsKe","y2vLr0y","wwPvCKe","CfnLzxC","q1z2tMi","vMr2Cfa","zgvMAw5Luhi","qKTlA0y","wMDqD3a","qNjPzgDL","DhrNAgC","sLnptLa","EfvAwvO","Dgv4Dc9WBge","zMLuAwq","thHHwu0","Dgv4DfbHEwW","rwLWr04","sLnVvMy","AgvHzgvY","CKvYwem","B3nLza","BMPuEe0","zMzLCG","vgLTzw91Da","v2vPEgLUsLm","CMvWBgfJzui","uhjPBwfYEuS","CMfUzg9T","DNzwCvq","wunwuxK","DwfuAgC","ywWGy3vYC28","ENP2sue","BgLUzq","vhL4wKu","ChzoAMm","zhnQENa","wevVDe8","sgnSA3e","D0fSDMS","Ew5xBxa","zv90Aw1LB3u","BfrPBwvVDxq","BNruCMLLC0m","AfvKweK","vKnmzLK","t3P6tNC","m3WX","wvn6t3u","zwn0","swjTDLa","ywDL","r01wB1u","uxnMCuy","ExrxAgu","CMvZzxrfBMq","x2LUDgvYDMe","mJe0ovPwwur1wq","uLDiAwu","mtqXmtjfuMfUrgK","igzPzwXKoIa","sKLIvfm","Cgf5Bg9Hzeu","C2vUza","AxjLza","lcbTyxGGCMu","y3vYDMfSDwu","rxjYB3jdB2q","DgvZDa","y2XVC2veqG","sfrwvxy","AwXLtMfTzq","yM9KEq","suP5shG","uwDMuhe","CeHgrvG","EujLz28","y29SBM8","C1v0quq","rejcqNO","y3DSs3K","x2n1CNnVCK0","CM92AwrLihC","qNvqrgG","B3jRzxjhBg8","ruPbwu0","x3jLy29UBMu","yNj0sxq","CMvZzxrdB3u","ywDLrxzLBNq","ywXPzcb1CMW","AfbMvNa","ig1LC3nHz2u","rKHfAu8","zgvIDwC","uwP5B0O","se1mz3K","zg95C2e","yxHJBfm","ywDLu2HVDW","A2v5CW","ihn1y2nLC3m","veHxA1K","zxjYB3i","qND2uNG","Dg9hzw5LCMe","Ae9Wzw5fDMu","x2nSzwfYugK","z3rivMy","zg5YDwe","y3jLyxrLuMu","AKPNA1e","z3f5rwu","B1zNtvC","sen5uwW","zLbMzgy","v2PcuM8","B25SAw5L","x3nVy2TLDa","qKzmz0W","zxmGCMvHy2G","yMXHqNG","CM92AwrLige","tMnfA2e","ywnRDxbfBMq","tKXYqMe","AxnszwfKEq","AKjmsfe","B25mAw5L","D2jnAfO","EuHZr0i","CMTLCKDSB2i","C29Tzq","C2vUDa","D09uBee","r1neBxq","yxbjwwC","v2XWC0O","CIb0DhDjra","uwvlu2i","CMvJB25Uzwm","q1f2s28","DwHkrLq","y1nZC3m","zxjFAxnFywm","CMHqyxy","zgvSzxrL","BhLRC0W","yLLWwxq","rwrVtKm","CMvZDwX0","Ec11C2uT","Dw5KzwzPBMu","zLLWsue","x3DHAxq","DNnSy0i","wNbxEM8","D2zYCxe","tuHkvNm","yLj5EM4","tKfjrfq","EMzxEK8","CxDYrw4","BMDuAw1LCG","BeHHBMrSzxi","B0HNrg8","CgLUz0XVC3m","y3vYCMvUDeK","uxb1que","ExbXsg4","tM9Pvu0","Ce1trNi","sgviCNG","reDjBMq","u1rzr2G","EhHgv00","tKXvs0e","y212C24","CxLnt0y","ze50ufG","DLLwsvO","DgfIyxnL","AKXYvLO","BvbsB2W","tMLpr0u","Ae9vExi","A1n0yxr1C0m","C3rYAw5NAwy","D3jPDgu","sMHAwM8","rwzts2e","Ce9erhO","CeHiyNm","x29UrxjYB3i","yLfmyuO","q29UzMLN","qwD0vg8","y2XLyxi","C3HXz0O","C1fuy0S","Bfb4rNm","zNjVBunOyxi","uunswuO","qKjvExq","y29UBMvJDeu","quD4A0C","rerovMS","ANboCfG","A3DPzMm","Dw9pALu","zxLOt2O","x2rItMfTzq","BMfTzq","yw1LoIa","uLDLq1C","Ahr0Ca","AePkExm","ihrVihjLDhi","B2vTuhu","vgrJvLO","A2XysLa","A05Is0W","y3r4","ywrKq291BNq","Bg9Nsurhzw4","zgPXuMu","B1bTwKe","A2nduu8","ChbL","yxnZAwDU","AuPhCw8","zNvbz0q","A2v0ignVBNm","DLvYz1C","r09VCuC","vffyvMi","sLPgCgO","x2LUAxrqCM8","u2TsCgK","ru5QCve","yufMD2m","CwnqueS","zhf1seu","q2H4C1i","EgX2rge","BhP6zxi","rwjNAwK","DMvUDa","CLb6svm","tKfusvzfx0u","x2nSzwfYvgK","DxrVuMvJB24","twPKq3O","uM1nDhC","zMLUza","C3bSAxq","ywnOzwq","z3jqCMq","ueLpBKC","rfrLDM4","EfL5uK8","y2XVC2uSihC","zM9Yy2u","y29UDgLUDwu","BevsBwK","u29NDwO","CNrHDKC","vLLPq0O","DNbksK0","ChjVy2vZCW","yNDgv3O","zxjFDhrS","wNbWAwK","vw5PBxbSzw0","vur4EKy","DgHLBG","y2HnyxHuCMK","Ae9oseK","EhDNrLO","B01tA2u","v0r2CM0","vLD6txa","icSG","DhnfqNi","ugnmEhO","mxWYFdr8mhW","ve1greW","z2v0sxrLBq","BgLUzw5V","CgDVuvu","A2DQEwm","Cgf5Bg9Hzfq","Ec1TC2CTCw8","y29TCgXLDgu","D3PJtMK","CeXms1O","ANzpvfm","tezMq0q","EKP3quG","txvZugy","C216u0y","Bg9NsurozxC","y3vZDg9Tshq","zxH0ugf5Bg8","y29Kzq","CMntAM4","BezSDxnO","qKjfAK8","DgjItNG","yNLrD3C","shfRC24","q21Yzfi","DuPyEfG","uxfZtNK","EKvVAfy","Bg9N","tw1cuNO","A0rkD1a","r09jswy","BMnVzgLUzW","BM5Ly3q","y3D1A0m","CM92AwrLihy","Aw9ywM4","uMPHrNC","zwXyswO","uuPZCw4","sgj3CM8","C3rLBMvYCW","uhLQD3i","zePSyKW","z0rUseK","t21pAKO","rMXeq0i","wwPZBMK","yvvgyMS","AwDHDg9Yt24","B3PhtMu","yxbWBgLJyxq","B25LCNjVCG","tNn0wuO","ALrIuLG","Aw47y2HHCNm","twzLEwe","x3jLBw92zvC","rfbbq2y","wuzYrLe","zgvJB2rLzey","B2Lhyuy","zcWGDw5RBM8","ww9frfG","yvvtAMC","zNjVBuj5Dgu","rgfgCva","sMHhrxu","CuHztLO","u2LyBNq","q0Tbsxu","B2fK","Aev6A3u","zKLyDKC","ANzxwu4","vKLfquu","CwTMq08","q0vozhO","x2LZtwLUAvC","x19LC01Vzhu","yxnL","weDlugC","z2PfAui","A3HjCfC","ELfvCKu","Dg9oDw1Izxi","C2fNzq","tg9NsurozxC","r1npCNq","Aw5L","suvtx0vsuK8","yLrtCei","wujVD2W","Euf4rwW","vgffsfi","CMvUDevUzha","yMXVy2TLza","EvjLy29UBMu","qxvxq0W","zw5fDMvUDa","Aw5KzxG","EuHPBeO","BfnQAwm","A0XIEwW","z2v0","ywXSzwqGBxu","Exjvtu8","zw5HyMXLuw8","ugrNCLO","zw5KCg9PBNq","v3P5Dwi","uMvHzcbWyxm","D24GCMvHC28","ALfpqNe","ihrPBwvZ","x3DZsw5ZDge","tgHnB0C","wNnMv2O","CgLUz0LUDgu","tLPKDui","D3Hwzui","ExvAyKq","zMfjsgy","ELLzsuy","sw5pBwy","v2LUzg93","rNLwC3y","vKTlEwS","rLz1ufq","AwXK","tvDZCuG","uMXryva","q1jmwhq","zxLdEhO","rePwvhm","rKvWEfy","x3jLywr5q2W","D0nsre4","C3rVCcbPBw0","wurzyLC","rgDut1u","CLPyr0W","Bvjxugi","C1f3v0W","BvDWq0S","q29Kzq","ChjVDg90Exa","BgLZDgvUtMu","Aw1LCYbPBIa","zuTRB3i","q0Xpu0LorW","DhLWzq","x2n1CNnVCKy","r3zJBMm","B2nRzxrtDwm","BMrLEa","DhDVCMTdAge","twflrhO","zwnVBM5Ly3q","CNnVCL92ywW","AgLjzvm","suzLD0K","zujzvLa","z25quvy","r3bQCKm","BKTHBLq","zxf1ywXZ","z2v0s2v5","Dw5ZAwDUzwq","q3vZDg9Trxi","BwLUAvbYB2C","Dhb3D20","CgfNzxnOB3C","y2Dwr1G","yKj2ANi","yMrFzgLK","Be52v1G","D2nKvu4","tMfTzq","qwT3thG","ywrIzg0","B3vUDa","uvfzsw8","BwvZC2fNzv8","C0Xf","r2DTsuW","zePYqum","AeL2Cvi","AKDUCeq","AgfUz2u","u2HHCMvKv28","zcWG","t2rvDvu","C29YDa","twjXteq","B25ozxr3B3i","veLAyxi","v2rJBKu","mtrxB25PELG","y3LPq2O","qMPNyMO","u2vXsuq","wefHv0e","DgLTzw91DcW","r3zdDxe","C1LLuum","uNzSBeC","DurzuNm","vMzisNy","CMvJzwL2zwq","AuPpBxm","zufyy1O","ufDODvi","vfrxrum","rfnvzuC","y2XVC2u","wgr5DLK","we5Zr0S","qM5NCwG","vNn1vM4","DwPxu0W","ufrxu1K","DMLJzuLeig8","Bg1tB1a","CeLgwMW","x2HHBMrSzva","CefJB3u","qKfYswe","x3bPBMDmB3m","vKf1sNq","CwDssMG","CgLUz1rPBwu","DKTVwhe","ChrVCG","zw5JB2rPBMC","ywnRx2nVzgu","yMnSBMK","werqz0q","zcbLCNjVCI4","mNW2Fdn8ma","whPxuee","ExPisvq","su9SDwq","yxv0BW","CMvZB2X2zq","rLzNBhq","reLurKK","CNnyCu8","CKP0tvO","DK1fqLa","x29WDgLVBNm","C0T4zKW","ELzmEfy","v3HOrfe","CMvTB3zLrxy","C3vIyxjYyxK","rgvbs3a","zvvYBa","thnywwy","ywzL","Cw1gre4","BM9Uzv9UB24","x2rPC2nVBM4","D3PfBM0","Ae56EhK","t0nuzeO","CMfTugfYyw0","EvHgzeC","yMLUyxj5vhK","yK93vK8","AuHVz1m","ihbYB3rVy28","C3bSAwnL","AMvJDfn0B3i","B25TzxnZywC","rLDt","tg92A0S","BgrJzvu","ufvyyKi","zNfitwS","D29mu0K","B1buANy","ntvssxDUquy","D2z2CwC","AvDKvwi","y0zpseO","wxjhuxy","v1nXDMG","Dxnlwg0","ChfhBxq","yMLUza","CYbPBNn0yw4","BNHjCMi","A1fKBum","yKrHBvO","B3jpBMXPBMu","Dw50","DhPdAxC","BwvKAwf0zwW","CgLUz19VBMm","ChPpswC","CMfTzq","sNHmyK4","AwXLx25HBwu","sND6yMy","y1HVshe","sxHis1m","venzBMK","DgDPwvm","u3DZDNa","AujszK0","y3vYC29Yx24","CgXLyxnLiha","qK9RDfi","DxbxueO","zw1PDa","wvvutfq","zxLTyMC","A0zSsLm","EMjRAfu","Be9kEe8","B25tDg9Wsw0","AxnrB1nby2S","qMnPDxO","EfbiAhK","CYbHBhjLywq","zxjHDg9Y","z29Yrxy","Au9nCKy","zgfXqwC","wvvzzvC","ChHfy1y","DhjPBq","v2HIu3K","BM1nq2W","rM1ntvm","u1jLrKy","z0fTque","zMPwvuq","x2n1CNnVCK4","Ef9MCM9UDgK","u3rYyxrLz3K","y29UBMvJDa","vhjrvxG","B25Uzwn0Aw4","Cg9W","CgTKAMC","x2rLC3rYB3K","C2v0y3vYC28","DLrwq1C","uu9ys2e","AgLNAa","wNLgC3G","y3jLyxrLq2W","r25bCgG","yxznufO","Ahr0Chm6","D3PVwue","Fdr8ohW1","B3bLCNr5tMe","q2vSrxe","EuvXsw0","ywnOzwqSihC","Aw5PDcbrB1m","CNjVCK1LC3m","t1bftG","Bg93","z09yAKe","DgHnD3O","DMfSDwu","BffWt0m","txfHyw4","DeLUDgvYy2u","yuTkseK","Bg9iwvC","whHqwgC","vM9VCfm","x2fKzfDZtgK","senqtvC","x3bYB3rVy28","BMvY","Eef3B08","zMLSzw5HBwu","qKzSEva","s1D6sNO","ExDHC24","AwXbuM8","B2nRzxrgywK","AgvHzgvYCW","sMjQsxC","y3vYCMvUDeu","zxjYtM8","se9wwxe","CNnVCKzPBgu","mta2nteYmevMD3PmDa","zNLxAgu","yxHcqwK","AhPfDuK","x3vYBa","yNL0zxm","Eg1TuNG","CMvTB3zLq2G","serkzhO","vwHKy0O","ufDgzMe","rvjst1i","AxnAzxjV","yw5ZzM9YBvq","vwTtCwS","AuPRCwi","ufnzq3i","ELv0wNe","qwjVCNrfCNi","tNr2suK","qvzHuvm","tvPsz2G","A3bRug0","sKDZsfe","Bwf4tg9ZC0m","B3bLCNr5","CMHLqLu","sezTsM8","zNDZxZeUmc4","AhDuv3u","EfvZzuvUDG","C0jf","tND3D24","x2LZtwLUAvq","A0HzueW","EMjYrxq","zxHWB3j0CW","z2vrDwv1zuW","B3fIqxm","v2TbweO","x3fVC0rc","yw1L","EsbJBg9Zzwq","mti3ody2u3LgALHs","AeTWvfi","q0Hmt3e","zMLN","AwrI","vMjyz1O","C2v0","s3vyzxe","EKjcDgm","C2vYDMvYvgK","yNvMzMvYzwq","zw1LBNq","DMD6sxa","yxGGCMv0CMK","EhDJBKG","aaaaaaaaaaa","rKLmrv9ot1q","x2HHBMrSzu8","id4G","zw5XDwv1zq","sgXmBNa","tfv3A2O","A0vKvui","qvflC0W","qvr3Awq","v0HUt0q","AxmGDw5Kzwy","ExbL","mtC0mdu1AefeCMTQ","Aw9Ul2PZB24","twvZC2fNzuu","CMvKDwnL","x2TLEvbHDgG","tgLZDgvUzxi","r3HUtK0","r0P5EgO","DgfYz2v0","qw1VDw50","zfrtthe","B2LUDfjLywm","y29Uy2f0","wNLrCLm","v2D0t0q","q3vZDg9Tq2W","CfvUzwq","DhjPzxmGCMu","s2DmBw8","uw5SDgC","s3vVCvi","zKXMwKC","rNLqq0K","zMLSDgvY","AeTbAve","y0vsree","ALrfvMG","Dhr3Awq","EKfbBeC","DNnztva","DwL2rwq","x21LC3nHz2u","C3vIC3rYAw4","C2HPzNq","AM1Jyxy","DgvmB2Djre4","z0XYu3m","rNjVBNrPzxi","teLAufq","Dg9Y","y2HHCKnVzgu","wMrsDgm","x0vysvnu","AwHzuuC","rgvKAwnHDgu","Bwzcs3y","zK9Lwxa","CMvWBgfJzq","D2vI","BMnLq2XVC2u","qNn4AMS","tgzlBwm","Bg9IywXty28","ywnR","y29UBMvJDfm","Cg93","q0Xpu0ve","qwfbvKK","Cg9PBNrdB24","yxbWBhK","BwvZC2fNzq","zg9Uzq","x2rLyNvN","sxfqAKy","y291BNq","y3vYC29YlNm","v05tywO","s3DuBNC","BeH2z1u","z1LVsMq","tgj3Avm","Afvltu4","AuD4reK","y3vYC29Y","zM9YrwfJAa","wKnmu1G","Dg9cExrLC0i","CMD6EvO","x2DLBMvYyxq","DNPltum","zfzctNG","CuPOzKC","C2vYDMLJzs0","B3v0sw50zxi","sfnIqKq","B09Lvfq","Aw5KzxHpzG","DMfS","B25dBg9Zzq","uwnzA0W","yNvMzMvY","yw5Hz2vY","C3Hxvw8","tgjTre0","tuPtsNu","sNfvue4","yw1Lu3bHy2u","AgvKtwf4uMu","uKrnteW","zgvS","B1vqrLm","yMfJA3vWigu","s2fXrNC","rLrVBNO","sKvtv2u","u0LzDee","v3rTqMK","y2Xzzve","ywXSq3vYC28","sMzQBNK","zufJAW","rgriCvi","yxv0B21HDgK","x3bPBMC","A2fIDue","DezXvwu","yMLUyxj5","DMfSDwvZ","y2HLy2Tszwe","Cw9Zx18","zw5NDgG","o2nOyxjZzxq","EfztAg4","nhW1Fdf8n3W","zxj2AwnL","q2vmtwu","t3fOtKC","x2rPC3bHDgm","CgPtAxq","u3LdCLa","CMvZzxruCMK","yxrHlcbKyxq","BNrbBMrvCgq","EeHYtvC","Cwj4tKC","q0DMquu","u2Lhuhm","B2jQzwn0u3q","sgHnB3y","q09oveLovuu","yNL0zuXLBMC","tvHJAvu","CNjqEfG","C0XPC3rLBMu","wgP0rLa","u2zSALa","BMvJDa","C3rYAw5N","t3vIy0G","uMvJB25Uzwm","D3njsve","yKLrwxu","y0feBLK","B1vYywG","Dg9cExrLC0W","zMvY","Durrt3i","mdaWmdaWmda","rMr2vK0","Dxrjza","Cw9Z","rhfeBwK","x0rctMfTzq","tujpzxa","sxPMAKW","uMflBxe","zw50tgLZDgu","x2LUAxrhBg8","z2v0qwXS","D1zzBLu","ywnRtxnNswq","ywrK","CNzHBa","se5PthO","BKXPBMu","BhLMvfK","uu9oDw0","wfrXtxi","t1bftL9fuLi","Be9Qz3m","BMrWB2LUDfq","D1rMAMO","BfL2BKK","BuvYuvm","t0zRrLm","CgrHvLu","z2nPwgG","tuzPBu4","rhb0quO","vxL0rvO","nJa3odHWBM1LDM4","yM9L","q0nOuKS","CezXtfy","CfbWwMy","sxHqufG","AvLZvuG","Bwu6ia","vhfXrLi","vLPZDg8","B25VCgvU","x2jPBMfYEvq","CgvYC2LZDgu","ywr2yw5Jzq","u2Lhr0y","AeTKzxu","uvrLqMW","rwHjs0e","ExvdEwu","vLHyzw4","Aw9U","z2v0u3rVCMe","nxWYFdr8mhW","B25szwnLAxy","zKjrEgO","y3jLyxrLtwu","AhjpwMq","yvHvEfe","nNWXFdeWFda","tLbRquO","ChjVDg9JB2W","A2v5","zsbHihn0CMK","lcbxzwjtB2m","zwrds3K","AenSB3nLrxy","Fdj8m3W3FdK","z2vY","uxvLDwu","suftru0","BM93","vfDcA1q","EgHRz3e","zgvSzxrLrge","Aw5N","tgLjBw4","qNPbuhi","u2fxs0u","CKTTDeW","rLHlEeW","zxjYtxnN","B3bLBG","B2nRzxq","tw9KDwXL","zNPKB3a","vgfN","zMzmAw5L","yMj4wxe","zxnZDvG","v0HiDgu","Aw5Lza","qM1WsM4","uuzUAu0","rNv1Bwy","vw5Oyw5KBgu","A0DHvKS","EgjZAK4","y3vYC29Yx2y","y2H3DeK","y01hA2O","tg9Nsuq","ihzHBgLKigq","uMTuyNK","B3jLtMfTzxm","ww1oD1e","rwDRDgm","BeHtz28","CMvHzfvjBNq","z2v0t3DUuhi","DMrvrgO","De5VtKG","s25IswS","quHHs3u","Aw9UvgLTzw8","CvbWCgy","zhrLCuC","B2zMBgLUzq","ihzHBgLKihm","u0XPrfG","Eg9MA3O","CMLLC0nVDw4","wLbNDfG","ELnusNm","sfvdqNK","tfblBe8","DMvY","qKDTA1a","u21WrKS","vwzLrfm","B25JBg9Zzq","uw12zNy","BMCGzMfPBgu","zw50","u0LgtMW","uxzxufy","nxWWFdr8mNW","twLZC2LUzYa","vgTXqLm","qNLKy2O","Bwf4uMv0CMK","q3DAsfK","AxnbCNjHEq","DxPMBgS","zNjHBwvuExa","uwvAvwq","EMnfA3C","y09Wzw4","wuzUCMu","DxbKyxrLq3u","wLnQEeS","vvjpAM0","x2LZsw5PDa","tK9yrwe","y3jLyxrLt2i","AgfZ","twjQCwy","Bw5wEvy","x2vUzhbVAw4","z2PvA3y","sNzkveK","DwPQsgC","Cw5jt3G","DgLTzw91Da","BhrPCgXLihq","uuL3zw4","zwrPyxrLBhK","CgfYC2u","q1PAvNK","vMXVvgi","uNzYzgW","AxnmB25N","CNnVCL9Uyw0","BKrrtxm","EhnOteC","AvrSs0W","ywjVCNq","AM9PBG","vgn4rhm","yMfSrxzLBNq","z2LmDMW","Cgf5Bg9Hza","D1fZzNC","x2LZqNjVD3m","z3jdqK4","mtiWzgDQuhny","Dg9mB3DLCKm","yxjYyxLIDwy","uNfOre0","DgLuuhi","qNDQC2u","D3z2tMS","otm0nti1ofngzNvPyG","vfnkzhi","vunArLC","x2XPC3rLBMu","igzHAwWSig0","tufOzK8","z2u6ia","A3viEgG","Dev2zw50","A0ffsge","Euruu3C","vhHMywC","tuvtu0fhrv8","vuvKzuK","y2XLyxjtDg8","tg9JAW","qvHkDvy","Dfnus1u","ANzkwei","t2T5z3O","tvrnzem","y3DsuwC","y2vZC0HHBMq","C2v0u3rVCMe","rgDUsLa","v1zPqLK","mNWWFdn8mxW","Dg5ouhO","vhbrDha","tM5fvNK","x3bYzwzPEa","DgfezfO","zgf0yq","yxPctLa","zhnmCK0","qKvht0C","x25HDMLNyxq","C3rVCMu","CNfMBhC","CgLUz09Uy2u","z2v0q3vYC28","DxPfsge","DxjS","yuDyDfa","z3vdA24","BKHryLy","DMXODuG","tuf1veS","CMvJzxzPzwq","Ae1LC3nHz2u","Du5zEKu","B2zM","BgvY","ufbqsgu","teLqsha","C3z4ww4","DhjPzxm","EgTyvxe","yxKSihrYEsa","C015yKO","v2vIu29JA2u","B2zMC2v0","ywXty29Wzq","C2v0sxrLBq","x29UtwvZC2e","y3POrhm","zgv2u0m","DwDSBgW","A2LNDLK","uurhuu4","zxjFywnRx20","Dg9tDhjPBMC","ugvwwvC","sLjiwxu","otneD0TmEwC","zw50zwqGDhK","BwLZzq","Bwv0Ag9K","uKDbuLO","zejlBgO","sufry2C","y2fSBa","EwXOBKC","u2vYDMLJzvC","y29UBMvJDgK","sffOs1O","DgTzwe8","CMvHzg9UBhK","DcbSAw1PDa","B3jL","DwrxDey","zNjVBNrPzxi","uurwquy","yNLL","x2LZv29YA2u","mZi3odKYmgDIsLvvvq","De9SzMy","yw5Nzq","s05Mzgy","uLP0rfy","y3bIBxO","zxH0zw5ZAw8","shHss3m","z2v0q3vYCMu","qxfeuNu","su5tvefova","q09otKvdveK","quPZD0W","zxjFCw9Zx2e","DeLK","B25tDgfYDfi","C3jTtLa","sgDhAuO"];return jo=function(){return t},jo()}function zv(t,{blocked:e}={}){let r=M,i={FTonz:r(1031),dNRlK:function(c,l){return c(l)}},o=indexedDB[r(1633)+r(829)](t);return e&&o.addEventListener(i[r(1503)],()=>e()),i[r(484)](Mt,o)[r(923)](()=>{})}function fh(t,e){let r=M,i={WgtOD:function(x,h){return x|h},sZkQb:function(x,h){return x|h},dsLrM:function(x,h){return x&h},LIZPT:function(x,h){return x<h},dteqG:function(x,h){return x<=h},Nwtmv:function(x,h){return x(h)},UEdeI:r(1943)+"e",Joprc:r(1838),gadAK:function(x,h){return x instanceof h},JIbTS:function(x,h){return x in h},gFWnK:r(1547),tqgPH:r(525),CQvKo:function(x,h){return x!==h},jWDPf:function(x,h){return x in h}};if(!(i[r(1869)](t,IDBDatabase)&&!i[r(709)](e,t)&&typeof e===i[r(543)]))if(r(525)!==i[r(508)])_0x53f8c8=i[r(1414)](i.sZkQb((15&_0x5782b1)<<12,i[r(1785)](63,_0x22b47a)<<6),i[r(1785)](63,_0x33a00b)),i[r(1438)](_0x56831f,2048)||_0x1570e8>=55296&&i[r(1675)](_0x514d98,57343)?_0x42dd2a+=_0x2eefa2:(_0x541aed+=i[r(599)](_0x2f746c,_0x1a9cd9),_0x1d3498+=2);else return;if(zo[r(1039)](e))return zo[r(1039)](e);let o=e[r(1447)](/FromIndex$/,""),c=i[r(789)](e,o),l=wh[r(463)](o);if(!i[r(479)](o,(c?IDBIndex:IDBObjectStore).prototype)||!(l||mh[r(463)](o)))return;let u=async function(x,...h){let m=r,E=this[m(1984)+m(1610)](x,l?i[m(1764)]:i.Joprc),I=E[m(1788)];return c&&(I=I[m(1035)](h[m(1433)]())),(await Promise[m(1904)]([I[o](...h),l&&E[m(1461)]]))[0]};return zo.set(e,u),u}var mh,wh,zo,Uv=hh({"node_modules/idb/build/index.js"(){let t=M,e={QjvMt:t(1695)+t(695),pVEhg:function(o,c){return o(c)},JxLbN:t(1887),qEzxo:"add",fIXvG:"delete",RvllG:t(1039),SLiDX:t(1102),iHogS:t(1568),jGnpD:t(1464),yEqIm:function(o){return o()}},r=e.QjvMt.split("|"),i=0;for(;;){switch(r[i++]){case"0":uh();continue;case"1":e[t(506)](Nv,o=>({...o,get:(c,l,u)=>fh(c,l)||o[t(1039)](c,l,u),has:(c,l)=>!!fh(c,l)||o[t(1714)](c,l)}));continue;case"2":wh=[e[t(1237)],e.qEzxo,e[t(1008)],t(845)];continue;case"3":zo=new Map;continue;case"4":mh=[e[t(1141)],e[t(1678)],e[t(1205)],"getAllKeys",e[t(1123)]];continue;case"5":e[t(1296)](uh);continue}break}}}),Gv={idb:function(t){let e=M;t.exports=Promise[e(1179)]().then(()=>(Uv(),gh))[e(923)](function(r){return r})}},xh={};function Nt(t){let e=M,r={zEohV:function(u,x){return u!==x}},i="3|4|0|2|1"[e(903)]("|"),o=0;for(;;){switch(i[o++]){case"0":var c=xh[t]={exports:{}};continue;case"1":return c.exports;case"2":Gv[t](c,c[e(1365)],Nt);continue;case"3":var l=xh[t];continue;case"4":if(r[e(962)](void 0,l))return l[e(1365)];continue}break}}Nt.d=(t,e)=>{let r=K;for(var i in e)Nt.o(e,i)&&!Nt.o(t,i)&&Object[r(653)+"operty"](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=M;Nt.o=(e,r)=>Object[t(1081)+"e"]["hasOwnPr"+t(1354)][t(1832)](e,r)})(),(()=>{let t=M,e={RWeCW:function(r,i){return r!=i},uBFpV:"undefined",NNbUW:t(1643)};Nt.r=r=>{let i=t;e[i(862)](e[i(1973)],typeof Symbol)&&Symbol[i(1822)+i(1645)]&&Object[i(653)+"operty"](r,Symbol[i(1822)+"Tag"],{value:e[i(1907)]}),Object["definePr"+i(1354)](r,i(1014)+"le",{value:!0})}})();var Ce={};(()=>{let t=M,e={MCaua:function(a,n){return a(n)},ZCBGa:function(a,n){return a+n},wfrqq:function(a,n){return a+n},pvNjc:function(a,n){return a*n},thMwz:function(a,n){return a*n},FVglt:function(a,n){return a+n},YCVQy:function(a,n,s){return a(n,s)},TpQtp:function(a,n){return a>>n},xofkz:function(a,n){return a===n},bQLaJ:t(1538),ZSjxK:function(a,n){return a(n)},FyVsv:function(a,n){return a(n)},XCFbT:t(636),NOXEa:"ffff",hwTWu:function(a,n){return a(n)},EmJLP:t(1557)+t(1557)+t(1557)+t(1557),NPkAJ:function(a,n){return a>n},UkSqk:function(a,n){return a!==n},bRyzn:"PdgrZ",ZPXuj:function(a,n){return a-n},mEmPL:"nWzxP",hJJys:function(a,n){return a<n},zfWzO:function(a,n){return a-n},wbMhZ:function(a,n){return a<n},SIFNl:function(a,n){return a<n},BYPTp:"LgkzH",VAuJt:t(1977),scopx:function(a,n){return a-n},pMSFr:function(a,n,s){return a(n,s)},KxBlh:t(1150),IxHKS:t(1853),XTqMr:function(a,n,s){return a(n,s)},lYvnI:function(a,n){return a&n},fBQxj:"Missing "+t(482)+t(708)+t(1621),fPfdf:t(1696)+t(482)+t(708)+t(1304),SReFF:function(a,n){return a===n},UhdcJ:t(1461),YmNwQ:t(1537)+t(1663),ZyFsx:function(a,n,s){return a(n,s)},Mfeya:function(a,n,s){return a(n,s)},pODDz:function(a,n,s){return a(n,s)},rJtMZ:t(554)+"ay, network offl"+t(1024),jJgkQ:function(a,n,s){return a(n,s)},WzDdz:function(a,n,s){return a(n,s)},UytEZ:function(a,n,s){return a(n,s)},kgjyc:t(1606),yuZbD:function(a,n,s){return a(n,s)},JhZZo:function(a,n,s){return a(n,s)},fOeYp:function(a,n){return a!==n},vTVCW:function(a,n,s){return a(n,s)},Qmvfv:function(a,n){return a(n)},XAaWA:function(a,n){return a!==n},uzflk:function(a,n,s){return a(n,s)},kHOBW:function(a,n,s){return a(n,s)},QDVAF:function(a,n,s){return a(n,s)},Zppii:function(a,n,s){return a(n,s)},axclS:function(a,n,s){return a(n,s)},clYeQ:function(a,n){return a!==n},rtFZX:function(a,n,s){return a(n,s)},VfHJv:function(a,n,s){return a(n,s)},nDQMs:function(a,n,s){return a(n,s)},BGmkP:function(a,n){return a===n},pKYcK:t(473),hrOZd:function(a,n){return a!==n},gqyEe:function(a,n){return a!==n},NvEUM:function(a,n,s){return a(n,s)},QsfqF:function(a,n){return a!==n},Bydcj:function(a,n,s){return a(n,s)},Hclkq:function(a,n){return a(n)},FKDae:function(a,n){return a(n)},CelEq:function(a,n){return a>>>n},dVaSe:function(a,n){return a(n)},MXciU:function(a,n){return a(n)},xYqvD:function(a,n,s){return a(n,s)},tzCiw:function(a,n){return a(n)},rErXC:function(a,n,s){return a(n,s)},qPppf:function(a,n){return a(n)},EffWp:function(a,n,s){return a(n,s)},BBEjO:t(1696)+t(482)+t(708)+"SeqID",HeHrx:function(a,n){return a===n},bJFPB:t(1696)+t(482)+" field: "+t(1660),CChRK:function(a,n){return a===n},RqhDM:t(1696)+"required"+t(708)+t(523),HwtKy:t(1696)+"required"+t(708)+t(1828),qyMOF:function(a,n){return a&n},QcYkL:function(a,n){return a(n)},cmvsn:function(a,n,s){return a(n,s)},aXUxQ:function(a,n){return a+n},vkjZI:t(921)+t(1826)+"pe: ",Pyjwr:function(a,n){return a>>n},qHYNZ:function(a,n){return a>=n},svxYn:function(a,n,s,d){return a(n,s,d)},wAlvk:function(a,n){return a===n},GgmIL:t(914),yrUMO:t(1121),YXjSK:function(a,n){return a===n},fLfMN:t(1214),AgjmK:function(a,n){return a>n},RZtDV:function(a,n){return a+n},adbdm:"Skip pas"+t(1839),lHSgo:function(a,n){return a>=n},FlDCB:function(a,n){return a*n},faIHf:function(a,n){return a>n},zAAlG:function(a,n){return a+n},ENjqQ:t(1046)+t(1839),kFlJS:t(1556),GknyM:function(a,n){return a+n},ypqHn:function(a,n,s,d){return a(n,s,d)},gOXjA:function(a,n){return a+n},pjSit:function(a,n,s){return a(n,s)},kpkPm:function(a,n,s){return a(n,s)},cgVGX:t(1324),FdvVM:function(a,n){return a(n)},zzvIA:function(a,n){return a&n},TQXVb:function(a,n){return a!==n},edCKy:function(a,n){return a&n},WSqvh:function(a,n){return a|n},uSKoh:function(a,n){return a<<n},ghbzk:function(a,n){return a<n},vgzIp:function(a,n){return a(n)},kigvY:function(a,n){return a==n},HlJUq:function(a,n){return a+n},CeLMe:function(a,n){return a+n},xaXwu:function(a,n){return a!==n},GnAph:function(a,n){return a===n},PcLxz:t(651),TyxZE:function(a,n){return a<<n},kuHxh:function(a,n){return a&n},pqGmt:function(a,n){return a>=n},tpwwm:function(a,n){return a<=n},VYiCJ:function(a,n){return a(n)},ahQrf:function(a,n){return a>=n},AuNHz:function(a,n){return a+n},PUXbB:function(a,n){return a+n},XGKPg:function(a,n){return a!==n},XNsGK:function(a,n){return a&n},sQTcK:function(a,n){return a<<n},azBNP:function(a,n){return a|n},KvQuF:function(a,n){return a&n},TSJdr:function(a,n){return a<<n},HgGiJ:function(a,n,s){return a(n,s)},sQwWL:function(a,n,s){return a(n,s)},oJLqV:function(a,n){return a&n},djqRe:function(a,n){return a>>>n},QeKSb:function(a,n){return a&n},XDPgD:function(a,n){return a&n},kXPOg:t(971),uJXxX:function(a,n){return a<n},zynyP:"eLwkX",HOKoK:function(a,n){return a<=n},qYMEy:function(a,n){return a+n},GBuKF:function(a,n){return a<n},Jwzbf:function(a,n){return a<n},oVgMW:function(a,n,s){return a(n,s)},JGsHQ:function(a,n){return a<=n},Bsxjk:function(a,n){return a!==n},jVbvB:"iTONV",SWxrb:"SrSXG",lSjic:function(a,n){return a|n},kcCQO:function(a,n){return a|n},fhxfm:function(a,n){return a&n},vlhuH:function(a,n){return a|n},mRWPb:function(a,n){return a&n},qkfCO:function(a,n,s){return a(n,s)},lhdSc:function(a,n){return a&n},avMPZ:function(a,n){return a===n},ZdRtc:t(1505),LbwiS:function(a,n){return a(n)},UHLZa:function(a,n){return a&n},HNiLz:function(a,n){return a===n},xUZYZ:function(a,n,s){return a(n,s)},cALZG:"ws://",zJwAH:function(a,n){return a&n},DeAKp:function(a,n){return a&n},RGARZ:function(a,n){return a(n)},rPzIS:function(a,n){return a&n},yAxEl:function(a,n){return a(n)},ChxsR:function(a,n){return a<<n},LeGYC:function(a,n){return a&n},tOlff:function(a,n){return a&n},BuPDh:function(a,n){return a&n},CpYwo:t(823),MHJVs:function(a,n){return a<<n},hPfVp:function(a,n){return a>>>n},LiWOc:function(a,n){return a<<n},ZsfWj:t(1657)+t(1238),zMKOA:function(a,n){return a===n},jBLHQ:t(1114),SiGGF:function(a,n){return a>>>n},KREeG:function(a,n){return a<<n},WhbSy:function(a,n){return a===n},ZyQrS:function(a,n){return a<n},TTWEC:function(a,n){return a<n},EfSKa:function(a,n){return a<n},gSplG:function(a,n){return a&n},TMFDL:function(a,n){return a+n},bqDxN:function(a,n){return a+n},gDnHI:function(a,n){return a>>>n},MAuBQ:function(a,n){return a&n},klXJP:function(a,n){return a>>>n},yHsGB:function(a,n){return a>>>n},Soguj:function(a,n){return a>>>n},QqsNy:function(a,n){return a+n},Okygz:function(a,n){return a!==n},qZyln:function(a,n){return a>>>n},kxIpW:function(a,n){return a>>>n},hrNpO:function(a,n){return a+n},qFYyX:function(a,n){return a>>>n},wzcNi:function(a,n){return a&n},ZTrnU:function(a,n){return a+n},IxPPX:function(a,n){return a|n},xlvDa:function(a,n){return a|n},OQvAN:function(a,n){return a(n)},jvJXB:"MqbBW",ytWhe:function(a,n){return a===n},vdUDj:function(a,n){return a|n},OmOjJ:function(a,n){return a|n},tFqUe:function(a,n){return a<<n},RmMtw:function(a,n){return a|n},WjBRo:function(a,n){return a<<n},xJbOZ:function(a,n){return a|n},gCAhW:function(a,n){return a|n},wzEnm:function(a,n){return a<<n},hUKMN:function(a,n){return a<<n},WdcnE:function(a,n){return a|n},HTVUv:function(a,n){return a|n},RwGPN:function(a,n){return a>>>n},Bngqh:function(a,n){return a>>>n},uNYzE:function(a,n){return a&n},KnbIk:function(a,n){return a>>>n},PWhuR:function(a,n){return a>>>n},GOIIf:"text/pla"+t(990)+t(602),hKdeu:t(1196)+"e",iOMrF:"binary",TWBkT:function(a,n,s,d){return a(n,s,d)},BKKkF:function(a,n){return a(n)},JzTxW:"YeCLl",NAIDT:t(533),MaKDz:function(a,n){return a>=n},nWUts:function(a,n){return a%n},Mqaan:function(a,n,s,d){return a(n,s,d)},MWsqH:t(1888),wCRDN:function(a,n){return a+n},PeVYW:function(a,n){return a*n},VKKyk:function(a,n){return a(n)},THWkY:t(501),UDxzF:t(1710),anlDA:function(a,n){return a&n},GOoqG:function(a,n){return a>>>n},LFfCD:function(a,n){return a+n},VOIMK:function(a,n){return a>>>n},EhIKA:function(a,n){return a+n},hKpTR:function(a,n){return a<<n},hIvqR:function(a,n){return a===n},BFLgL:function(a,n){return a===n},SiGPs:function(a,n){return a===n},zSTJs:"QeZUd",CmrdR:function(a,n){return a===n},bTSpB:function(a,n){return a!==n},DFkkn:t(700),SkRpi:t(1542),tNoNH:function(a,n){return a&n},rKmtL:function(a,n){return a&n},MjdCz:function(a,n){return a&n},CbyBF:function(a,n){return a&n},thUPA:function(a,n){return a>>>n},dVBNx:function(a,n){return a>>>n},NnEVy:function(a,n){return a>>>n},RaKmq:function(a,n){return a&n},WNSaj:function(a,n){return a&n},YrGQv:t(1612)+t(695),ksggl:t(1763)+t(1340),GSOrt:t(1857)+t(544),HOVYq:"OPEN_ERROR",FHEiO:t(548)+"IES_ERROR",sYeQC:"NATIVE_E"+t(626),fGAlH:t(1777)+"4",uRWek:function(a,n){return a!==n},nKanT:t(745),CENdz:function(a,n){return a>=n},pHHbs:function(a,n){return a===n},zYcUi:function(a,n){return a-n},HDJdz:function(a,n){return a+n},fgnCE:function(a,n){return a===n},wQKnI:t(1348),vslcB:t(751),ujjHg:function(a,n){return a instanceof n},ujWSL:function(a,n){return a+n},CmJKV:"versionc"+t(1124),uzjov:function(a,n){return a===n},KWzJz:t(1895),GORdC:function(a,n,s){return a(n,s)},vMEBP:t(1641),LpugO:function(a,n,s){return a(n,s)},HjYYT:t(1460),ZNvAz:t(1609),LovkK:t(1332),IqPjF:function(a,n,s){return a(n,s)},rheBU:function(a,n){return a||n},upWPJ:function(a,n){return a||n},gMLyO:function(a,n){return a!=n},tzAlG:t(800)+"d",STYGh:function(a,n){return a instanceof n},JESWe:function(a,n){return a===n},Hqksn:"uqpNI",LPASH:"yyhMM",hJmrk:function(a,n){return a!==n},uzEHa:t(1219),MQRCK:t(566),SrkRv:"1|3|0|2|4",WViBY:function(a,n){return a||n},FVuPT:function(a,n){return a!=n},VCLfY:function(a,n){return a===n},lHvgU:function(a,n){return a+n},VIEAE:function(a,n){return a<n},WHnOD:function(a,n){return a<n},cMGkj:function(a,n){return a&n},gDGaQ:function(a,n){return a-n},QpuAA:function(a,n){return a===n},BFlyP:t(869),GraPd:"VynNP",YwpOV:function(a,n){return a<n},jzpKG:function(a,n){return a-n},vpxQG:t(1436),JvJTI:function(a,n){return a<=n},IszwV:function(a,n){return a<<n},TkSCF:function(a,n){return a>=n},dNtPX:function(a,n){return a|n},gELxO:function(a,n){return a&n},vUrgW:function(a,n){return a>=n},eFydc:function(a,n){return a&n},tRGta:function(a,n){return a&n},AGuBw:function(a,n){return a+n},seJjv:function(a,n){return a>>n},QvWPV:function(a,n){return a+n},eyhOj:function(a,n){return a>>n},bOwVO:function(a,n){return a<n},vKoXq:t(1894),zcEkw:function(a,n){return a<n},aUFbk:function(a,n){return a|n},Egktc:function(a,n){return a>>n},cwRQg:function(a,n){return a|n},ODZjc:function(a,n){return a&n},HwRjj:function(a,n){return a===n},wOTlA:function(a,n){return a|n},qJhfG:function(a,n){return a+n},brtIt:function(a,n){return a|n},ZIwZU:function(a,n){return a>>n},TdcVZ:function(a,n){return a&n},uglll:function(a,n){return a>>n},zbkhU:function(a,n){return a>>n},mPOYV:function(a,n){return a|n},hYhwv:function(a,n){return a&n},ULzMU:function(a,n){return a|n},FlKau:function(a,n){return a&n},dJlbL:t(1547),RlQaP:function(a,n,s,d){return a(n,s,d)},LbmDM:function(a,n){return a!=n},vmFwG:function(a,n){return a instanceof n},YFrFQ:function(a,n){return a instanceof n},xHrMW:t(986)+"ion/json",OvqBt:t(813),blaBx:t(1484),cERDA:t(1591),nmMCl:t(876),HbooN:function(a,n){return a!==n},MusPf:"bXeQb",GEVkK:t(1968),EJAYM:function(a,n){return a(n)},eBYVP:"unknown reason",HjQKM:"script",oiGaF:function(a,n){return a+n},CGfAE:t(863),wVYnU:t(557)+t(1929)+"tierJSONP",lERmi:"klVah",gorEv:function(a,n){return a!==n},HUCBy:t(1139),rsXqO:function(a,n){return a!==n},oemPu:"vjsTJ",sxWUo:t(1700),rHPQy:t(1376),QJsqn:function(a){return a()},jvWYN:function(a,n,s){return a(n,s)},YrVhj:function(a,n){return a+n},vYVIZ:function(a,n){return a===n},tgiYS:t(1451),gnPQV:function(a,n){return a!==n},QWOCC:t(1356),PBsGo:function(a,n){return a&n},QtFrm:function(a,n){return a&n},NjPzl:function(a,n){return a|n},DPACf:t(1331),KgLmo:function(a,n){return a===n},grPrd:t(466),KNfdf:function(a,n){return a||n},Vxnnv:t(1048),TdqhY:t(1581),wxVeB:function(a,n){return a||n},mBNeh:function(a,n){return a+n},essuX:function(a,n){return a+n},nVlmC:function(a,n){return a+n},NZduB:function(a,n){return a!==n},ynWmp:function(a,n){return a&n},EwiUI:function(a,n){return a<<n},LPKlO:function(a,n){return a|n},DDNVk:function(a,n){return a<<n},PIOnG:function(a,n){return a&n},gYoJd:function(a,n){return a!==n},oosEy:t(1129),DCsOP:function(a,n){return a||n},wXrif:function(a,n){return a!==n},hPmhQ:function(a,n){return a-n},pSQgf:function(a,n){return a===n},ZCLSX:t(475),Wzyub:function(a,n){return a+n},SiXnt:function(a,n){return a&n},FcmAj:function(a,n){return a<<n},oMSke:function(a,n){return a<<n},wMgXZ:function(a,n){return a|n},lNvWX:function(a,n){return a|n},aVWZE:function(a,n){return a&n},SKAFo:function(a,n){return a<<n},vqzGS:function(a,n){return a&n},Yjsni:function(a,n){return a&n},TXWbF:function(a,n){return a<n},mlGRN:function(a,n,s){return a(n,s)},iJGqo:"AnfZq",nHQbV:function(a,n){return a||n},lOjgs:function(a,n){return a||n},fzdop:function(a,n){return a||n},elXIj:function(a,n){return a||n},pLLKZ:function(a,n){return a!=n},wzoYA:t(1298)+"DB failed",SyCrP:t(1560),dusZj:t(1118)+"id",oqbAs:function(a,n){return a!==n},NoiUM:"ZnbJN",DHynw:function(a,n){return a!==n},Nwwwn:t(547),kHYPL:t(1272),sumWH:function(a,n){return a(n)},oOeTT:t(1275)+"er_qos",gjUkv:t(1275)+t(1859)+"ck",JSoVf:t(1275)+t(792)+"k",dZNwG:t(1275)+t(1821)+"sgid",HtMbZ:function(a,n){return a&n},YFnre:function(a,n){return a!==n},uYOaa:"KEVqv",yDTSw:t(1392),OFkFS:function(a,n,s,d){return a(n,s,d)},sxqgJ:function(a,n){return a&&n},qwrEn:"is_ack",lmSoP:"ack_id",WbbWx:t(1170),fjVUD:function(a){return a()},Fuumf:t(1453),zUtZq:t(706),IAQcg:t(1144),YoEDX:function(a,n,s,d){return a(n,s,d)},qmFDN:function(a,n){return a&&n},cwlKy:function(a,n){return a||n},NLOrZ:function(a,n){return a(n)},qnIOx:t(1059),kabuA:t(1940),OCTdJ:function(a,n){return a instanceof n},zQteb:"applicat"+t(1401)+";charset"+t(1921),apIYg:function(a,n,s,d){return a(n,s,d)},oPmZA:t(1368),DzmIb:function(a,n){return a+n},dwedW:function(a,n){return a&n},DaFqP:function(a,n){return a|n},AXJuV:function(a,n){return a||n},bBvjr:function(a,n){return a>>>n},xKqNA:t(930),njTxM:t(1390),maMCk:"integer too large",QCRYJ:function(a,n){return a===n},uoOjU:t(925),lPxFs:function(a,n,s,d){return a(n,s,d)},CBCzw:t(933)+"3",AuWCL:function(a,n){return a+n},ihYQG:function(a,n){return a+n},NFzlc:function(a,n){return a+n},gvsDM:function(a,n){return a|n},kEdUB:function(a,n){return a|n},QgfPq:function(a,n){return a<<n},WxhDQ:function(a,n){return a+n},CHLOq:function(a,n){return a+n},kUNwz:function(a,n){return a<<n},ZpWzo:function(a,n){return a+n},Hbwro:function(a,n){return a|n},wDOSX:function(a,n){return a<<n},VdvpP:function(a,n){return a+n},SaWKE:function(a,n){return a+n},LWtyC:function(a,n){return a&n},bclni:function(a,n){return a&n},BzAPr:function(a,n){return a>>>n},ldceU:function(a,n){return a>>>n},PSYCr:function(a,n){return a&n},QQYIo:"ruBSm",DgnJP:function(a,n){return a+n},wcdUN:function(a,n){return a&n},SmpFK:function(a,n){return a+n},IOlud:function(a,n){return a&n},XhdhL:function(a,n){return a|n},wRkkN:function(a,n){return a<<n},SjbFO:function(a,n){return a|n},XxPXg:t(1618)+t(1626)+t(1293),xwgFZ:function(a,n,s,d){return a(n,s,d)},smzSF:function(a,n,s,d){return a(n,s,d)},mErQS:function(a,n,s,d){return a(n,s,d)},JLYFT:t(860),oPTjv:t(1465)+t(1524),loHYW:t(1482)+"name",ZGEvc:t(666),tnNPz:function(a,n){return a(n)},VWzMp:function(a,n,s){return a(n,s)},kjQgU:function(a,n){return a+n},PoLlO:"FILE_NOT"+t(1442),iBXlU:function(a,n){return a!==n},jmcav:t(1142),RjaFw:t(1227),JRfjk:function(a,n,s){return a(n,s)},Zklcj:t(1246)+t(1370),BBUyt:t(1508)+"rValues",hUdXI:t(1856),dTSLq:t(1539),gtHVf:function(a,n,s,d){return a(n,s,d)},BmpJn:function(a,n){return a instanceof n},LLSuS:function(a,n){return a!=n},eNamB:function(a,n){return a===n},dxRpC:t(1879),ueOLY:"kRMWV",GJyxj:t(514),JeJxG:"MIlaa",VoopS:t(1283)+"r",OhKlA:function(a,n){return a||n},eAXcZ:t(561),uBUdI:function(a,n,s,d){return a(n,s,d)},gEjhr:function(a,n,s){return a(n,s)},kwifc:function(a,n){return a(n)},aGXtP:t(1275)+t(919),tECDw:function(a,n,s,d){return a(n,s,d)},GWSHW:"x-msg-cu"+t(1731)+"e",iKTnq:t(617)+t(1094)+"ue",iJkqb:function(a){return a()},wpZhx:function(a,n){return a>n},MxYtz:function(a){return a()},byQww:function(a,n){return a===n},JRHYu:function(a,n,s){return a(n,s)},ATwid:function(a){return a()},DgTOU:function(a){return a()},eyCxz:function(a,n){return a(n)},hOUyr:function(a){return a()},wQsfw:function(a,n){return a<n},Bseja:function(a,n){return a===n},WqrgY:function(a,n){return a!==n},DqDmi:function(a,n){return a!==n},LxaYM:"HCyQl",LUwkj:function(a){return a()},WKFRN:function(a,n){return a==n},LsXYf:t(1506),woLSI:function(a,n){return a!==n},MAhfO:t(1278),kDJwP:function(a,n,s){return a(n,s)},hEzku:function(a,n,s,d){return a(n,s,d)},hFquf:t(511),FyPCI:t(1178),AHaKu:t(676),Rvrdl:"KVzXe",DBREP:t(1234)+t(564)+"s",tTlJW:function(a,n,s){return a(n,s)},oUrah:function(a,n,s){return a(n,s)},LIPHp:"bye",SArjG:function(a,n){return a!==n},EipGN:t(1820),KaqFw:"daPRt",pgoQU:t(1746)+t(1555),bYpYt:function(a,n){return a==n},YUTLT:function(a,n){return a===n},uivEd:t(1247)+t(970)+t(738),sKQUg:t(1247)+t(730)+t(555)+t(1623)+t(880)+"tructor "+t(1398)+t(1650),ttghg:function(a,n,s){return a(n,s)},nUqnt:t(788)+"t",wbbRO:t(765),AcZNo:t(1676),OdUuU:t(515),TIZar:t(1107),yzHIT:function(a,n){return a!==n},xhkgq:function(a,n){return a==n},Vkpyx:t(1291),tiTPr:t(1978),ofFIS:t(1110),wsIIQ:t(1427),mnVyV:t(1247)+"rovide bddID, de"+t(1157)+t(786),EDaWr:t(575),esHKB:function(a,n,s){return a(n,s)},vttQb:t(1448),ozGNe:t(1357)+"0",CjiPN:function(a,n,s){return a(n,s)},udWtF:function(a,n,s){return a(n,s)},CDUYf:function(a,n){return a!==n},fuAgD:t(1753),AaAVI:t(1911),yHilJ:function(a,n){return a>n},xwcnH:function(a,n){return a(n)},Lkgcn:t(1990)+">",wvvNk:t(1379),kQdmC:t(853),VloTb:function(a,n){return a*n},TRJCG:function(a,n){return a>n},pkdjg:t(1722),MAuTK:"going aw"+t(1809)+t(788)+t(539)+t(1685),goRky:function(a,n){return a<=n},pFqLV:t(1870)+"alled mu"+t(1723)+t(1083)+t(917),QONum:t(1971),xkXUq:t(1349),RnsaP:t(1138)+t(611)+t(1279)+"g",Jfjny:function(a,n,s){return a(n,s)},tUkNt:"iAwve",cADnY:"send_ack",lyksL:"0|1|2|3|4",zBBtc:"1|4|2|0|3",BUFlA:t(944),XDbpb:function(a,n,s){return a(n,s)},FmMMS:function(a,n,s){return a(n,s)},xmmRx:function(a,n,s){return a(n,s)},CXcUj:t(1915),cXoHq:function(a,n){return a===n},chwtI:t(1737),IzfjL:function(a,n){return a+n},fiTid:t(1234)+t(689)+"t",cwukC:function(a,n){return a(n)},sKxfL:t(1908),YBowl:t(1229),musAu:t(941),OAxZY:t(1735),OzzNw:function(a){return a()},tUldS:t(1347)+"or",GSDmt:t(1019),TqqFR:t(1864),dBKlj:t(1070),vNOFb:t(1523)+t(1174),LiImn:function(a,n){return a===n},tSTKU:t(909)+t(1260)+t(1371),GkeVV:t(1247)+t(770)+t(1661)+t(1531)+"a must b"+t(1622)+"ng or an"+t(1930)+t(670),yZbeI:function(a,n){return a==n},CZZVy:t(550),XzWPA:"please p"+t(770)+t(1677)+t(1524),YDYbW:function(a,n){return a instanceof n},OubcH:t(781),QEmxw:function(a,n){return a<n},YUYeW:t(1391),bXpSX:function(a,n){return a==n},ceeGF:t(1953)+t(1093)+t(1634),XjtFP:t(637)+"2",LCxIX:function(a,n,s){return a(n,s)},QTowl:function(a,n){return a(n)},IFewI:"TfywN",tXylL:t(1563),MwIoa:function(a,n){return a*n},eKkor:"Window",QjyoJ:function(a,n){return a!=n},fYpIA:function(a,n){return a!=n},FXKxL:function(a,n){return a!=n},xYyRO:function(a,n){return a===n},pAcou:"Object",qREpV:t(1444)+"dWorkerG"+t(1452)+"pe",OYIfI:function(a,n){return a!=n},vizpS:function(a,n){return a===n},xirxG:function(a,n){return a===n},aKJHI:function(a,n){return a===n},mPRol:t(1834)+t(732)+"balScope",BFfFX:function(a,n){return a!=n},KdGGc:function(a,n){return a===n},JZFpj:function(a,n){return a!=n},zUdGA:t(1897)+t(1519)};Nt.r(Ce),Nt.d(Ce,{FWS:()=>Xp,CustomErrorEvent:()=>$d,createCloseEvent:()=>xt,ReconnectEvent:()=>Kd,createErrorEvent:()=>at,decodedFrame:()=>Xt,createOpenEvent:()=>Qd,CustomCloseEvent:()=>Vd,createReconnectEvent:()=>aa,FrontierMessageEvent:()=>Yd,encodeFrame:()=>Bt,createMessageEvent:()=>Xd,OpenEvent:()=>Zd,ErrorCode:()=>en,Event:()=>Zn,MessageEvent:()=>Jd});let r="";function i(a=""){let n=t,s="02",d=""+Date[n(1630)](),f=r||(r=e.MCaua(x,a)),p=Math[n(675)]()[n(1822)](16)[n(528)](-6);return e[n(1874)](e[n(1874)](e[n(805)](s,d),f),p)}function o(){let a=t;return e.ZCBGa(e[a(683)](1e4,Date[a(1630)]()),Math[a(588)](e[a(1303)](1e4,Math.random())))}function c(a){let n=t;return e.FVglt(Array(8).join("0"),e[n(677)](parseInt,a,10)[n(1822)](2)).slice(-8)}function l(a){let n=t;return e.xofkz(e[n(842)],e.bQLaJ)?e[n(805)](e[n(1709)](Array,4).join("0"),parseInt(a,2)[n(1822)](16)).slice(-4):(_0x20ce6e|=0,{low:_0x17d603,high:e[n(1779)](_0x4e5e54,31),unsigned:_0x222897>=0})}function u(a){let n=t,s=a[n(903)](/\./)[n(558)](p=>c(p)),d=[];return d[0]=l(s[0]+s[1]),d[1]=e[n(1061)](l,s[2]+s[3]),[e.XCFbT,e.XCFbT,e[n(571)],e[n(571)],e[n(571)],e[n(1712)],d[0],d[1]][n(1736)]("")}function x(a){let n=t,s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[n(716)](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(716)](a);return s?u(a):d?e[n(1358)](h,a):e[n(1931)]}function h(a){let n=t,s={NwzMS:function(S,D,N){return S(D,N)}},d="",f=[],p=0,_=0,w=!0,g=n(636);if(e[n(1619)](a[n(1486)]("::"),-1)){if(e[n(1343)](e[n(807)],n(1043)))return!!this[n(1369)];{let S=a[n(903)]("::");for(let N=0;N<S[n(510)];N++){let U=S[N];if(e[n(1619)](U[n(1486)](":"),0)){let V=U[n(903)](":");w&&(p=V[n(510)]),_+=V[n(510)];for(let J=0;J<V[n(510)];J++)if(e[n(1343)](4,V[J].length)){let je=g.substring(0,e.ZPXuj(4,V[J][n(510)])),ge=je[n(1412)](V[J]);f[n(1880)](ge)}else f[n(1880)](V[J]);w=!1}else{if(e[n(531)]===n(797))return this["currentE"+n(1580)+n(1680)+"t"];if(e.UkSqk(4,U[n(510)])){let V=g[n(1432)+"g"](0,4-U[n(510)]),J=V.concat(U);f.push(J)}else f[n(1880)](U);w&&(p+=1),_+=1,w=!1}}let D="";for(let N=0;e.hJJys(N,e.zfWzO(8,_));N++)D=D[n(1412)](g);for(let N=0;e.wbMhZ(N,f[n(510)]);N++)N===p&&(d=d[n(1412)](D)),d=d.concat(f[N]);return d}}{let S=a[n(903)](":");for(let D=0;e[n(1693)](D,S[n(510)]);D++){let N=S[D];if(S[D].length!==4)if(e[n(1343)](e.BYPTp,e[n(1164)])){let U=g[n(1432)+"g"](0,e[n(496)](4,S[D][n(510)])),V=U.concat(N);d=d[n(1412)](V)}else s[n(577)](_0x3b9189,_0x21d5be,90),_0x259c2d(_0x1c6f35,_0x78c6e);else d=d[n(1412)](N)}return d}}function m(a,n){let s=t,d=a.key;e[s(1343)](void 0,d)&&(e[s(819)](he,n,10),e.pMSFr(H,n,d));let f=a.value;e.UkSqk(void 0,f)&&(e.YCVQy(he,n,18),e[s(819)](H,n,f))}function E(a){let n=t,s={ULEaD:function(d,f,p){return d(f,p)},ZxqdY:e.KxBlh};if(e[n(1241)]===e.IxHKS){let d={};e:for(;!$(a);){let f=e[n(1709)](xe,a);switch(f>>>3){case 0:break e;case 1:d[n(1621)]=e[n(677)](L,a,e[n(565)](xe,a));break;case 2:d.value=e[n(1577)](L,a,xe(a));break;default:e[n(677)](C,a,e[n(1582)](7,f))}}if(e[n(1679)](void 0,d[n(1621)]))throw new Error(e[n(1614)]);if(e[n(1679)](void 0,d.value))throw new Error(e[n(763)]);return d}else{let d=this[n(1185)][n(788)+n(1307)+n(1168)](_0x324500,_0x3c7bda);this[n(1527)+"hCloseEvent"](s.ULEaD(_0x3e9e51,s[n(492)],{code:_0x8fe5cc,reason:_0x37a28c,wasClean:!0,willReconnect:d})),d&&this[n(529)]()}}function I(a){let n=R();return y(a,n),B(n)}function y(a,n){let s=t,d=a[s(1136)];e[s(1343)](void 0,d)&&(he(n,8),e.jJgkQ(ft,n,d));let f=a[s(1660)];e[s(1343)](void 0,f)&&(e.WzDdz(he,n,16),e[s(1589)](ft,n,f));let p=a[s(523)];if(e[s(1343)](void 0,p))if(e[s(1343)](e[s(938)],e[s(938)])){if(gwCvCj[s(1271)](_0x73f4e8,gwCvCj[s(1338)]))return _0x21ef87[s(1039)](_0x27618a);if(gwCvCj[s(1271)](_0x3feb51,gwCvCj.YmNwQ))return _0x4cd7de[s(1537)+s(1663)]||_0x59d3ed[s(1039)](_0xbbe5d6);if(gwCvCj.xofkz(_0x345a4d,s(1788)))return _0x4bace1[s(1537)+"oreNames"][1]?void 0:_0x256dc1.objectStore(_0x6c9119["objectSt"+s(1663)][0])}else e[s(1056)](he,n,24),e[s(837)](ft,n,e[s(565)](P,p));let _=a[s(1828)];e[s(1446)](void 0,_)&&(e[s(1284)](he,n,32),ft(n,e.Qmvfv(P,_)));let w=a[s(1323)];if(e[s(1137)](void 0,w))for(let je of w){e[s(1702)](he,n,42);let ge=R();e.kHOBW(m,je,ge),e[s(1843)](he,n,ge.limit),e[s(920)](W,n,ge),O(ge)}let g=a["payloadE"+s(967)];e[s(1137)](void 0,g)&&(e[s(839)](he,n,50),e.axclS(H,n,g));let S=a[s(939)+"ype"];e[s(1507)](void 0,S)&&(e[s(1926)](he,n,58),e[s(1143)](H,n,S));let D=a[s(1740)];D!==void 0&&(e.ZyFsx(he,n,66),e[s(1702)](he,n,D[s(510)]),e[s(1732)](oe,n,D));let N=a[s(1022)];if(N!==void 0)if(e[s(1686)](e.pKYcK,s(473)))e[s(746)](he,n,74),e[s(677)](H,n,N);else{if(this[s(755)+s(811)](),this["_clearTi"+s(1970)](),this[s(992)+"sListeners"](),this[s(1050)+s(1449)](1e3,_0x3c5927),this[s(529)+"Lock"]=!1,_0x5f5563&&this["_navigat"+s(1230)]()&&!this[s(1071)+s(668)]){if(this[s(1717)+"tManager"]?.[s(1518)+s(924)+"es"]()){let ge=this[s(1717)+s(601)]?.[s(1854)+"ntEndpoint"]();this[s(1527)+s(1625)+"ent"](e[s(1287)](_0x1a7f69,s(1150),{code:1006,reason:s(1938)+ge+(s(1877)+", max re"+s(1417)+"ached"),wasClean:!0}))}else{let ge=this[s(1185)][s(788)+s(1307)+"ptor"](_0x218f14,_0x2fde36);this["_dispatc"+s(1625)+s(1692)](e[s(991)](_0x844d0e,s(1150),{code:_0x4f8a54,reason:_0x447755,wasClean:!0,willReconnect:ge})),ge&&this[s(529)]()}return}this[s(1787)+s(1230)]()||this[s(1071)+s(668)]?this[s(1527)+s(1625)+s(1692)](e[s(839)](_0x2fa0c5,e[s(1871)],{code:_0x54faae,reason:s(1844)})):this[s(1527)+s(1625)+s(1692)](_0x180c20(e[s(1871)],{code:1006,reason:e[s(1183)]})),this[s(603)]=null,this[s(1717)+s(601)]?.[s(703)+"pointCon"+s(1375)](),this[s(1163)+s(485)]?.[s(736)+"nter"]()}let U=a[s(1381)+"ming"];e[s(1616)](void 0,U)&&(e[s(677)](he,n,82),e[s(759)](H,n,U));let V=a[s(541)];e[s(760)](void 0,V)&&(e[s(639)](he,n,90),H(n,V));let J=a[s(1703)+"e"];e[s(701)](void 0,J)&&(e[s(1287)](he,n,96),e[s(1698)](ft,n,P(J)))}function v(a){let n=t;return e[n(1358)](A,e[n(686)](F,a))}function A(a){let n=t,s={};e:for(;!e.FKDae($,a);){let d=xe(a);switch(e[n(1295)](d,3)){case 0:break e;case 1:s[n(1136)]=e.yuZbD(vt,a,!0);break;case 2:s[n(1660)]=e[n(1287)](vt,a,!0);break;case 3:s[n(523)]=e[n(565)](xe,a);break;case 4:s[n(1828)]=e.dVaSe(xe,a);break;case 5:{let f=e[n(1690)](T,a);(s[n(1323)]||(s[n(1323)]=[]))[n(1880)](e[n(565)](E,a)),a[n(643)]=f;break}case 6:s[n(710)+n(967)]=e[n(1926)](L,a,e[n(1541)](xe,a));break;case 7:s["payloadT"+n(1399)]=e[n(837)](L,a,e[n(565)](xe,a));break;case 8:s.payload=e[n(512)](ie,a,e[n(1232)](xe,a));break;case 9:s[n(1022)]=e.rErXC(L,a,e[n(1061)](xe,a));break;case 10:s[n(1381)+"ming"]=e[n(837)](L,a,xe(a));break;case 11:s[n(541)]=L(a,e[n(1709)](xe,a));break;case 12:s[n(1703)+"e"]=e[n(1674)](xe,a);break;default:e.EffWp(C,a,7&d)}}if(e[n(1679)](void 0,s[n(1136)]))throw new Error(e[n(955)]);if(e[n(820)](void 0,s[n(1660)]))throw new Error(e[n(1987)]);if(e.CChRK(void 0,s[n(523)]))throw new Error(e[n(1747)]);if(s.method===void 0)throw new Error(e.HwtKy);return s}function T(a){let n=t,s=xe(a),d=a[n(643)];return a[n(643)]=a[n(1812)]+s,d}function C(a,n){let s=t;switch(n){case 0:for(;e[s(826)](128,se(a)););break;case 2:e[s(1926)](Y,a,e[s(1489)](xe,a));break;case 5:e[s(825)](Y,a,4);break;case 1:e.YCVQy(Y,a,8);break;default:throw new Error(e[s(1617)](e.vkjZI,n))}}function P(a){let n=t;return a|=0,{low:a,high:e[n(977)](a,31),unsigned:e.qHYNZ(a,0)}}let b=[];function R(){let a=t;if(e[a(687)](e[a(1120)],e[a(1041)]))for(var n in _0x499b1d)gwCvCj[a(1806)](_0x54fc54,_0x5bd4dc,n,{get:_0x4a8e11[n],enumerable:!0});else{let s=b[a(1280)]();return s?(s[a(1812)]=s[a(643)]=0,s):{bytes:new Uint8Array(64),offset:0,limit:0}}}function O(a){b[t(1880)](a)}function F(a){return{bytes:a,offset:0,limit:a[t(510)]}}function B(a){let n=t;if(e.YXjSK(e.fLfMN,n(627)))_0x5d5263+=e[n(1690)](_0x1e6224,_0x4f734d),_0x14c2b8++;else{let s=a[n(1334)],d=a[n(643)];return s[n(510)]===d?s:s[n(1190)](0,d)}}function Y(a,n){let s=t;if(e[s(534)](e[s(1850)](a.offset,n),a[s(643)]))throw new Error(e[s(1115)]);a[s(1812)]+=n}function $(a){let n=t;return e[n(1666)](a[n(1812)],a.limit)}function te(a,n){let s=t,d=a[s(1334)],f=a[s(1812)],p=a[s(643)],_=e[s(1874)](f,n);if(e[s(1619)](_,d[s(510)])){let w=new Uint8Array(e[s(981)](2,_));w[s(1378)](d),a[s(1334)]=w}return a.offset=_,_>p&&(a[s(643)]=_),f}function Z(a,n){let s=t,d=a[s(1812)];if(e[s(1057)](e.zAAlG(d,n),a[s(643)]))throw new Error(e[s(887)]);return a[s(1812)]+=n,d}function ie(a,n){let s=t,d={mrPJs:function(f,p,_){return e[K(1702)](f,p,_)}};if(e[s(687)](e[s(1253)],e[s(1253)])){let f=e[s(1589)](Z,a,n);return a.bytes[s(1190)](f,e[s(1974)](f,n))}else{let f=d.mrPJs(_0x527b44,_0x135b45,_0x42d0a8[s(510)]);_0x43c5d5[s(1334)].set(_0x27ed76,f)}}function oe(a,n){let s=t,d=te(a,n[s(510)]);a[s(1334)].set(n,d)}function L(a,n){let s=t,d={ONIML:s(751),AgtTo:function(S,D,N){return e[s(1351)](S,D,N)},WLfsR:function(S,D,N){return e[s(1284)](S,D,N)},dquHE:function(S,D){return S instanceof D},NLrBa:function(S,D){return S+D}},f=Z(a,n),p=String[s(849)+s(1080)],_=a[s(1334)],w="\uFFFD",g="";for(let S=0;e[s(864)](S,n);S++)if(e[s(1108)]!==s(655)){let D=_[S+f],N,U,V,J;if(e[s(687)](128&D,0))g+=e[s(1558)](p,D);else if(e[s(1271)](e[s(680)](224,D),192))e[s(1666)](e[s(1974)](S,1),n)?g+=w:(N=_[e[s(1428)](e[s(1974)](S,f),1)],e[s(883)](e.edCKy(192,N),128)?g+=w:(J=e[s(1222)](e[s(1989)](e[s(680)](31,D),6),e[s(680)](63,N)),e[s(551)](J,128)?g+=w:(g+=e[s(1384)](p,J),S++)));else if(e[s(1819)](240&D,224))if(e[s(1666)](S+2,n))g+=w;else if(N=_[e[s(1936)](e[s(1180)](S,f),1)],U=_[e[s(1525)](S,f)+2],e.xaXwu(e[s(826)](N|e.uSKoh(U,8),49344),32896))g+=w;else if(e.GnAph(s(651),e[s(932)]))J=e[s(1222)](e[s(1989)](e[s(1624)](15,D),12),e.TyxZE(e[s(680)](63,N),6))|e[s(1758)](63,U),J<2048||e[s(1224)](J,55296)&&e[s(1106)](J,57343)?g+=w:(g+=e[s(915)](p,J),S+=2);else if(d[s(890)](_0x274bd5,_0x496e3f)){let je=_0x1e9be0[s(1490)].slice(_0x5749aa.byteOffset,d[s(773)](_0x57a445.byteLength,_0x28ed5b[s(517)+"et"]));this[s(766)]&&this[s(766)].send({data:je,fail:ge=>{let nn=s;this.emit(d.ONIML,d[nn(844)](_0x2bffd7,"error",{message:this[nn(1868)+"rrorMess"+nn(699)](ge)}))}})}else this[s(766)]&&this[s(766)][s(711)]({data:_0x407b1f,fail:je=>{let ge=s;this.emit("error",d[ge(592)](_0x360b24,d[ge(563)],{message:this["_formatE"+ge(1299)+ge(699)](je)}))}});else e[s(1819)](248&D,240)?e.ahQrf(e.RZtDV(S,3),n)?g+=w:(N=_[e.GknyM(e.ZCBGa(S,f),1)],U=_[e.AuNHz(e[s(1980)](S,f),2)],V=_[e[s(805)](e[s(1213)](S,f),3)],e.XGKPg(e.XNsGK(e[s(1222)](N,e.sQTcK(U,8))|e[s(682)](V,16),12632256),8421504)?g+=w:(J=e[s(1222)](e.azBNP(e.sQTcK(e[s(1903)](7,D),18)|e.sQTcK(63&N,12),e.TSJdr(e[s(1758)](63,U),6)),e[s(1152)](63,V)),e.ghbzk(J,65536)||e.NPkAJ(J,1114111)?g+=w:(J-=65536,g+=e[s(1863)](p,e.RZtDV(e[s(1779)](J,10),55296),e[s(1624)](1023,J)+56320),S+=3))):g+=w}else{let{offset:D}=e.Zppii(_0x291988,_0x59ee5e,_0x43b58c);_0xea38e0=D;let N={cursor_name:"",cursor:0,service:0},{value:U,offset:V}=_0x17e981(_0x17b185,_0x4146cd);N[s(523)]=U,_0x2a7345=V;let{value:J,offset:je}=e.QDVAF(_0x438542,_0x546f8b,_0x487c0c);_0x578072=je,N[s(1246)+s(1370)]=e[s(817)](_0x2040cf,_0x7172c6,_0x1dbe5,e[s(1302)](_0x5a09fc,J)),_0x4d468d+=J;let{value:ge,offset:nn}=e[s(1528)](_0x2d6413,_0x491576,_0x2eb45a);N.cursor=ge.toNumber(),_0x4c309f=nn,_0x5e245f[s(1880)](N)}return g}function H(a,n){let s=t,d={qbxNG:function(f,p,_){return e.sQwWL(f,p,_)},DITFI:function(f,p){return f&p},ylhnG:function(f,p){return e[K(618)](f,p)},RDMLL:function(f,p){return e[K(873)](f,p)},PWFfa:function(f,p){return e[K(787)](f,p)},aSyUu:function(f,p){return e[K(1172)](f,p)},ERqVz:function(f,p){return e.qyMOF(f,p)},VxglQ:function(f,p){return f>>>p}};if(e[s(760)](s(1599),e.kXPOg)){let f=n.length,p=0;for(let g=0;e[s(960)](g,f);g++)if(e.hrOZd(e[s(530)],"eLwkX"))HIILru[s(1534)](_0x2a5d34,_0x36ce9e,10),HIILru[s(1534)](_0x392208,_0x55f487,_0x1ce87b);else{let S=n[s(1440)+"At"](g);e.ahQrf(S,55296)&&e.HOKoK(S,56319)&&e[s(777)](e.qYMEy(g,1),f)&&(S=e[s(496)]((S<<10)+n[s(1440)+"At"](++g),56613888)),p+=e[s(551)](S,128)?1:e[s(489)](S,2048)?2:e[s(1239)](S,65536)?3:4}e[s(761)](he,a,p);let _=e[s(1589)](te,a,p),w=a[s(1334)];for(let g=0;e[s(960)](g,f);g++){let S=n[s(1440)+"At"](g);if(S>=55296&&e[s(1352)](S,56319)&&e[s(1693)](e[s(1850)](g,1),f)&&(S=e[s(1180)](e[s(1989)](S,10),n[s(1440)+"At"](++g))-56613888),e[s(489)](S,128))w[_++]=S;else if(e[s(1450)](e[s(1889)],e[s(1932)]))e[s(1239)](S,2048)?w[_++]=S>>6&31|192:(e.uJXxX(S,65536)?w[_++]=e.lSjic(S>>12&15,224):(w[_++]=e[s(875)](e[s(552)](S>>18,7),240),w[_++]=e[s(1797)](e[s(1077)](S>>12,63),128)),w[_++]=e[s(1222)](e[s(977)](S,6)&63,128)),w[_++]=e.azBNP(63&S,128);else return null}}else{let f=this.high,p=this[s(1301)];return[d[s(1181)](255,p),d.DITFI(p>>>8,255),d[s(1833)](p>>>16,255),d[s(1498)](p,24),d[s(1339)](255,f),d[s(1976)](d[s(1498)](f,8),255),d.ERqVz(d[s(1498)](f,16),255),d.VxglQ(f,24)]}}function W(a,n){let s=t,d=e[s(1011)](te,a,n.limit),f=a[s(1334)],p=n.bytes;for(let _=0,w=n[s(643)];e[s(1693)](_,w);_++)f[e[s(1525)](_,d)]=p[_]}function se(a){return a[t(1334)][Z(a,1)]}function Ye(a,n){let s=t,d={yHIMR:function(f,p){return e[K(977)](f,p)},wrtIh:function(f,p){return e[K(1152)](f,p)},pakbv:function(f,p){return e.lSjic(f,p)},WlpsJ:function(f,p){return e.lhdSc(f,p)}};if(e[s(1290)](e[s(1441)],e[s(1441)])){let f=e[s(1702)](te,a,1);a[s(1334)][f]=n}else _0x5cd06e[_0x1c393c++]=d.yHIMR(_0x23d096,12)|224,_0x668800[_0x36f7dc++]=d.wrtIh(_0x21cae4>>6,63)|128,_0x5d875a[_0x50d170++]=d.pakbv(d[s(785)](63,_0xc534d4),128)}function xe(a){let n=t,s=0,d=0,f;do f=e[n(1470)](se,a),e[n(1693)](s,32)&&(d|=e[n(572)](127,f)<<s),s+=7;while(128&f);return d}function he(a,n){let s=t;if(e[s(1573)](s(1782),"taDdZ")){for(n>>>=0;e[s(1003)](n,128);)Ye(a,e[s(1582)](127,n)|128),n>>>=7;e[s(659)](Ye,a,n)}else _0x3aa0c7[s(1378)](_0x44edd9,_0x5cb031)}function vt(a,n){let s=t,d={akQzk:function(g,S){return g==S},Bciuz:e.cALZG},f=0,p=0,_=0,w;return w=se(a),f=e[s(1903)](127,w),e[s(946)](128,w)&&(w=se(a),f|=e[s(680)](127,w)<<7,e[s(1191)](128,w)&&(w=e[s(1829)](se,a),f|=e[s(1989)](e[s(826)](127,w),14),e[s(946)](128,w)&&(w=e[s(1384)](se,a),f|=e[s(682)](e[s(896)](127,w),21),e.zzvIA(128,w)&&(w=e[s(1028)](se,a),p=127&w,e.XDPgD(128,w)&&(w=e[s(686)](se,a),p|=e[s(1752)](127&w,7),128&w&&(w=se(a),p|=e[s(1752)](127&w,14),e[s(680)](128,w)&&(w=se(a),p|=e[s(891)](e[s(621)](127,w),21),e[s(1847)](128,w)&&(w=se(a),_=127&w,e[s(731)](128,w)&&(e.XAaWA(e.CpYwo,s(1416))?(w=se(a),_|=e.LeGYC(127,w)<<7):(_0x2e8d16=_0x21c697&&d.akQzk(s(1291),_0x452c9e[s(1620)])?s(1978):d[s(1258)],_0x18f31b=_0x3209a2.replace(/((^ws)|(^http))((?:[s]*:\/\/))/,""),_0x3f023a=/^wss(.*:\/\/)/[s(716)](_0x24d68a)?_0x384a30:""+_0x257450+_0x1646d5)))))))))),{low:f|e[s(806)](p,28),high:e[s(739)](p,4)|e.LiWOc(_,24),unsigned:n}}function ft(a,n){let s=t,d={pGVyh:e[s(1052)],pxEcV:s(1388)+s(1442)};if(e[s(1918)](e.jBLHQ,e[s(775)])){let f=e.CelEq(n.low,0),p=e[s(873)](e[s(1604)](n[s(1301)],28)|e.KREeG(n[s(1286)],4),0),_=e[s(873)](n.high,24),w=e[s(1290)](0,_)?e[s(1268)](0,p)?e[s(1413)](f,16384)?f<128?1:2:e[s(1693)](f,2097152)?3:4:p<16384?p<128?5:6:e.TTWEC(p,2097152)?7:8:e[s(838)](_,128)?9:10,g=e[s(1078)](te,a,w),S=a[s(1334)];switch(w){case 10:S[g+9]=e[s(593)](_>>>7,1);case 9:S[e[s(934)](g,8)]=e.gqyEe(9,w)?e[s(1797)](128,_):127&_;case 8:S[e[s(573)](g,7)]=e.gqyEe(8,w)?e.WSqvh(e[s(979)](p,21),128):e.MAuBQ(e.klXJP(p,21),127);case 7:S[e[s(805)](g,6)]=w!==7?e.azBNP(e[s(778)](p,14),128):e.edCKy(e[s(913)](p,14),127);case 6:S[e[s(961)](g,5)]=e[s(1770)](6,w)?e[s(875)](e.qZyln(p,7),128):e[s(1018)](p,7)&127;case 5:S[e[s(1850)](g,4)]=w!==5?e[s(1037)](128,p):e[s(1582)](127,p);case 4:S[e[s(477)](g,3)]=w!==4?e[s(597)](f,21)|128:e[s(942)](e[s(979)](f,21),127);case 3:S[e[s(934)](g,2)]=e[s(1770)](3,w)?e[s(1784)](f>>>14,128):e[s(942)](e[s(913)](f,14),127);case 2:S[e.ZTrnU(g,1)]=w!==2?e[s(1595)](e[s(913)](f,7),128):e[s(826)](e[s(778)](f,7),127);case 1:S[g]=e[s(1137)](1,w)?e[s(892)](128,f):e[s(680)](127,f)}}else return{frameType:_0x68921e,headers:[{key:d.pGVyh,value:d[s(1266)]}],payload:void 0}}function Xt(a){return v(a)}function Bt(a){return e[t(1956)](I,a)}let Qt=65536,Kr=t(1387),we=Qt*Qt,Ae=e.MwIoa(we,we),Yn=Ae/2,De=String.prototype[t(1440)+"At"];class fe{constructor(n,s,d){let f=t;this[f(1730)]=!0,this[f(1301)]=e[f(1222)](0,n),this[f(1286)]=0|s,this[f(1103)]=!!d}static[t(1730)](n){let s=t;return e[s(1343)](e[s(1769)],e[s(1769)])?e.LbwiS(_0x3666ae,_0x262ca2):n&&e[s(702)](!0,n[s(1730)])}static[t(646)](n,s,d){return new fe(n,s,d)}static[t(1e3)+"s"](n,s,d){let f=t;return d?fe[f(1e3)+f(1119)](n,s):fe[f(1e3)+"sBE"](n,s)}static[t(1e3)+"sLE"](n,s){let d=t;return new fe(e[d(1797)](e[d(892)](e[d(1669)](n[0],e[d(891)](n[1],8)),n[2]<<16),e.MHJVs(n[3],24)),e[d(980)](e.IxPPX(n[4],e[d(891)](n[5],8)),e[d(1515)](n[6],16))|n[7]<<24,s)}static[t(1e3)+t(1360)](n,s){let d=t;return new fe(e[d(1037)](e[d(1797)](e[d(901)](e[d(806)](n[4],24),e[d(764)](n[5],16)),n[6]<<8),n[7]),e.xJbOZ(e.gCAhW(n[0]<<24,e[d(1752)](n[1],16)),e.KREeG(n[2],8))|n[3],s)}static[t(490)](n){let s=t;return e[s(1679)](n,Kr)?Wd:new fe(e[s(979)](e.vlhuH(De[s(1832)](n,0)|De[s(1832)](n,1)<<8|e[s(1198)](De.call(n,2),16),e[s(1471)](De[s(1832)](n,3),24)),0),e.klXJP(e[s(1132)](e[s(718)](e[s(1037)](De[s(1832)](n,4),De.call(n,5)<<8),e[s(1471)](De[s(1832)](n,6),16)),e[s(1198)](De[s(1832)](n,7),24)),0),!0)}[t(596)](){let n=t;return String[n(849)+n(1080)](255&this[n(1301)],e[n(598)](e[n(979)](this[n(1301)],8),255),e[n(1903)](e.RwGPN(this.low,16),255),e[n(1153)](this[n(1301)],24),255&this[n(1286)],e[n(633)](this[n(1286)]>>>8,255),e[n(1801)](e[n(1671)](this.high,16),255),e[n(1147)](this[n(1286)],24))}static[t(1933)+"er"](n,s=!0){let d=t,f={hKAiQ:function(p,_){return p instanceof _},pnCMd:e[d(966)],MFimN:d(986)+"ion/json",GAkzt:d(986)+d(1401)+d(1521)+"=utf-8",BCcin:e[d(1605)],LgGge:e[d(1263)],DBBBz:function(p,_,w,g){return e.TWBkT(p,_,w,g)}};if(e[d(654)](isNaN,n))return s?lp:Wd;if(s){if(e[d(1224)](n,Ae))return fp}else if(e.JzTxW===e[d(808)])if(_0x5bb9b6[d(1740)]instanceof _0x4eb549){let p=f.hKAiQ(this._options["payloadE"+d(967)],_0x44ddd0)?{force:!!this._options[d(710)+d(967)][d(910)],encoding:this[d(1185)][d(710)+d(967)][d(1169)]?this[d(1185)][d(710)+d(967)][d(1169)][d(1447)](/\s/g,"")[d(1745)+"ase"]():""}:{force:!1,encoding:this[d(1185)][d(710)+d(967)]?this._options[d(710)+"ncoding"][d(1447)](/\s/g,"")[d(1745)+d(1015)]():""},_=_0x4990cf[d(710)+d(967)]?_0x2c324c[d(710)+"ncoding"][d(1447)](/\s/g,"")["toLowerC"+d(1015)]():"",w=f[d(1424)](this[d(1185)][d(939)+"ype"],_0x464435)?{force:!!this._options["payloadT"+d(1399)][d(910)],type:this[d(1185)][d(939)+"ype"][d(1086)]?this[d(1185)][d(939)+d(1399)][d(1086)].replace(/\s/g,"")[d(1745)+d(1015)]():""}:{force:!1,type:this[d(1185)][d(939)+d(1399)]?this[d(1185)]["payloadT"+d(1399)].replace(/\s/g,"")[d(1745)+d(1015)]():""},g=_0x13ba17[d(939)+d(1399)]?_0x46023e[d(939)+d(1399)][d(1447)](/\s/g,"")[d(1745)+d(1015)]():"",S=w[d(910)]?w.type:g||w[d(1086)],D=p[d(910)]?p[d(1169)]:_||p[d(1169)],N=[f.pnCMd,f[d(1587)],f.GAkzt,d(1547)],U=[f.BCcin,f[d(1884)]];this[d(1185)][d(537)+d(1342)+d(951)+"ad"]&&N[d(463)](S)&&(!D||U.includes(D))?_0xfc7791.textPayload=f[d(727)](_0x67b622,_0x278e16[d(1740)],0,_0xac71b0[d(1740)].byteLength):_0x4f6069[d(663)+"oad"]=""}else _0x52e8c4["textPayl"+d(1006)]="";else{if(n<=-Yn)return xp;if(e[d(1092)](n+1,Yn))return up}return fe.fromBits(e[d(901)](e[d(491)](n,we),0),e.IxPPX(n/we,0),s)}toNumber(){let n=t,s={ywasn:function(d,f,p,_){return e[K(1306)](d,f,p,_)}};if(e[n(1918)](e[n(1065)],"mwFQE"))s[n(1320)](_0x515302,this,_0x31050f,[_0xc862b1,_0x111a3d,_0x3b6928]);else return this[n(1103)]?(this[n(1286)]>>>0)*we+e[n(1147)](this[n(1301)],0):e[n(1072)](e[n(1823)](this[n(1286)],we),e.RwGPN(this.low,0))}[t(1341)](){let n=t;return e[n(1271)](e[n(750)],e[n(922)])?e[n(1062)](_0x2c7d00,_0x3a90f1):e.HeHrx(0,this[n(1286)])&&e[n(1686)](0,this[n(1301)])}[t(1571)](n){let s=t;fe.isLong(n)||(n=fe[s(1933)+"er"](n));let d=this[s(1286)]>>>16,f=65535&this.high,p=e[s(873)](this.low,16),_=65535&this[s(1301)],w=e.kxIpW(n[s(1286)],16),g=e.anlDA(65535,n[s(1286)]),S=e[s(913)](n.low,16),D=e[s(1624)](65535,n[s(1301)]),N=0,U=0,V=0,J=0;return J+=_+D,V+=e.qZyln(J,16),J&=65535,V+=p+S,U+=e[s(882)](V,16),V&=65535,U+=e[s(945)](f,g),N+=e[s(1991)](U,16),U&=65535,N+=e[s(1607)](d,w),N&=65535,fe[s(646)](e[s(806)](V,16)|J,e[s(1373)](N,16)|U,this[s(1103)])}[t(1101)](n){let s=t;return fe.isLong(n)||(n=fe[s(1933)+"er"](n)),e[s(883)](this[s(1103)],n[s(1103)])&&e[s(1573)](e.SiGGF(this.high,31),1)&&e[s(1122)](n[s(1286)]>>>31,1)?!1:e[s(767)](this.high,n[s(1286)])&&e[s(1536)](this[s(1301)],n[s(1301)])}addOne(){let n=t;if(n(1704)===e[n(1682)])return e[n(1919)](-1,this[n(1301)])&&e[n(1919)](-1,this[n(1286)])?fe[n(646)](0,0,this[n(1103)]):e[n(959)](-1,this.low)?fe[n(646)](0,e.CeLMe(this[n(1286)],1),this[n(1103)]):fe[n(646)](e[n(1936)](this[n(1301)],1),this[n(1286)],this[n(1103)]);_0x19f6a3=_0x1be007[n(1412)](_0x4c9ed2),_0x536f3a=_0xaf6d9b.concat(_0x531538[_0x5a1fdc])}toBytes(n){return n?this[t(1554)+"E"]():this.toBytesBE()}[t(1554)+"E"](){let n=t;if(e[n(1026)](e[n(560)],e[n(886)])){let s=this[n(1286)],d=this[n(1301)];return[e[n(1670)](255,d),e[n(868)](d,8)&255,e[n(1638)](d>>>16,255),e.SiGGF(d,24),e[n(900)](255,s),e[n(1935)](e.thUPA(s,8),255),e[n(1480)](s,16)&255,e[n(1018)](s,24)]}else{let s=_0x4a25cb[n(1432)+"g"](0,e[n(809)](4,_0x4868b4.length)),d=s[n(1412)](_0x31fc54);_0x3a7a61[n(1880)](d)}}[t(1476)+"E"](){let n=t,s=this.high,d=this[n(1301)];return[e[n(1780)](s,24),e.UHLZa(s>>>16,255),e[n(1565)](s>>>8,255),e[n(1466)](255,s),d>>>24,e.UHLZa(d>>>16,255),e[n(826)](e[n(1604)](d,8),255),255&d]}}let Wd=new fe(0,0,!1),lp=new fe(0,0,!0),up=fe.fromBits(-1,2147483647,!1),fp=fe.fromBits(-1,-1,!0),xp=fe[t(646)](0,-2147483648,!1);var en=(function(a){let n=t,s=e[n(1221)][n(903)]("|"),d=0;for(;;){switch(s[d++]){case"0":a[a[e.ksggl]=5004]=n(1763)+n(1340);continue;case"1":return a;case"2":a[a[e[n(1023)]]=5002]=n(1857)+n(544);continue;case"3":a[a[e[n(1327)]]=5005]=e[n(1327)];continue;case"4":a[a["MAX_RETR"+n(1025)+"R"]=5003]=e[n(741)];continue;case"5":a[a[e[n(1140)]]=5001]=n(897)+"RROR";continue}break}})({});class Zn{constructor(n){let s=t;this[s(1086)]=n,this.target=null}}class Kd extends Zn{constructor(n,s){let d=t;super(n),this.message=s&&s[d(1460)]||null}}class $d extends Zn{constructor(n,s){let d=t,f=("0|5|4|3|"+d(1951))[d(903)]("|"),p=0;for(;;){switch(f[p++]){case"0":super(n);continue;case"1":this.lineno=s&&s[d(936)]||0;continue;case"2":this.message=s&&s[d(1460)]||"";continue;case"3":this[d(1317)]=s&&s[d(1317)]||"";continue;case"4":this[d(725)]=s&&s[d(725)]||0;continue;case"5":this[d(751)]=s&&s[d(751)]||null;continue;case"6":this[d(952)]=s&&s.code||5001;continue}break}}}class Vd extends Zn{constructor(n,s){let d=t,f=e.fGAlH[d(903)]("|"),p=0;for(;;){switch(f[p++]){case"0":this[d(952)]=s&&s[d(952)]||0;continue;case"1":this.wasClean=s&&s.wasClean||!1;continue;case"2":super(n);continue;case"3":this[d(1922)]=s&&s[d(1922)]||"";continue;case"4":this["willReco"+d(968)]=s&&s[d(1906)+d(968)]||!1;continue}break}}}class Jd extends Zn{constructor(n,s){let d=t;e.uRWek(e[d(1100)],d(1220))?(super(n),this[d(1783)]=s&&s.data||null):(this[d(1527)+d(1800)+d(505)](_0x4f7f9a),_0x472c92[d(1378)](_0x5a90a1,_0x1c26cb,_0xc18ccd[d(1460)][d(523)]))}}class Yd extends Jd{constructor(n,s){let d=t;super(n),this[d(1783)]=s&&s.data||null,this[d(1460)]=s&&s[d(1460)]||null}}class Zd extends Zn{constructor(n,s){let d=t;super(n),this[d(1783)]=s&&s[d(1783)]||null}}function at(a,{message:n,code:s,error:d}){return new $d(a,{message:n,code:s,error:d})}function xt(a,{code:n,reason:s,wasClean:d,willReconnect:f}){return new Vd(a,{code:n,reason:s,wasClean:d,willReconnect:f})}function Xd(a,{data:n,message:s}){return new Yd(a,{data:n,message:s})}function Qd(a,{data:n}){return new Zd(a,{data:n})}function aa(a,{message:n}){return new Kd(a,{message:n})}class el{constructor(n,s){let d=t;this.endpoints=n,this.maxRetries=s,this["currentI"+d(1090)]=0,this[d(1325)+d(1580)+d(1680)+"t"]=0}["resetEnd"+t(1458)+t(1375)](){let n=t;this[n(815)+"ndex"]=0,this[n(1325)+n(1580)+n(1680)+"t"]=0}[t(1530)+"es"](){let n=t;this[n(1325)+n(1580)+"riesCount"]=0}[t(1854)+t(545)+"nt"](){let n=t;return this[n(1044)+"s"][this[n(815)+"ndex"]]}[t(1854)+"ntEndpoi"+t(691)+t(1116)](){let n=t;return this[n(1325)+n(1580)+n(1680)+"t"]}[t(1518)+t(924)+"es"](){let n=t;return!!(e[n(1012)](this[n(815)+"ndex"],this[n(1044)+"s"].length)||e.pHHbs(this.currentIndex,e.zYcUi(this[n(1044)+"s"][n(510)],1))&&this[n(1325)+n(1580)+n(1680)+"t"]===this[n(1699)+"es"])}[t(630)+"rentEndp"+t(1411)+t(1497)+"tries"](){let n=t;return e.kigvY(this["currentI"+n(1090)],this[n(1044)+"s"].length)?!0:e[n(534)](this["currentE"+n(1580)+n(1680)+"t"],this[n(1699)+"es"])}[t(673)+t(772)+"pointAnd"+t(608)+t(1231)](){let n=t;return this[n(1325)+n(1580)+n(1680)+"t"]=1,this[n(815)+n(1090)]++,this[n(1044)+"s"][this[n(815)+n(1090)]]}[t(1854)+t(545)+t(1532)+t(600)](){let n=t;return this[n(1325)+n(1580)+n(1680)+"t"]++,this[n(1854)+n(545)+"nt"]()}}let Xn=(e[t(1063)](e.tzAlG,typeof globalThis)&&e[t(1122)](e[t(1084)],globalThis["construc"+t(1439)][t(860)])||e[t(743)](e[t(527)],typeof window)&&t(1060)===window[t(1892)+"tor"][t(860)])&&e[t(801)](e.tzAlG,typeof document),Tn=e[t(1639)]("undefined",typeof globalThis)&&(e[t(908)](e[t(1161)],globalThis.constructor[t(860)])||e[t(559)]===globalThis[t(1892)+t(1439)].name)&&e[t(1639)]("undefined",typeof tt),$r=(e[t(1946)](e[t(527)],typeof globalThis)&&e.GnAph(e.pAcou,globalThis[t(1892)+t(1439)].name)||e.bYpYt(t(800)+"d",typeof globalThis)||typeof globalThis<"u"&&!!globalThis[t(672)+t(656)])&&e.OYIfI(t(800)+"d",typeof wx),Vr=e[t(527)]!=typeof globalThis&&(e.vizpS(e[t(559)],globalThis["construc"+t(1439)][t(860)])||e.xirxG(t(1125)+t(779)+t(1813),globalThis[t(1892)+t(1439)][t(860)])||e[t(1308)](e[t(831)],globalThis[t(1892)+t(1439)][t(860)]))&&e.BFfFX("undefined",typeof self),hp=e[t(527)]!=typeof globalThis&&e[t(1916)](e[t(1161)],globalThis[t(1892)+t(1439)][t(860)])&&e[t(527)]!=typeof global&&e[t(1916)](e.pAcou,global[t(1892)+t(1439)].name)&&e.LLSuS(e.tzAlG,typeof process)&&!!process[t(1942)];class ca{constructor(){let n=t,s={bbxYq:function(d,f){return e[K(534)](d,f)},sUtAD:function(d,f){return e[K(1337)](d,f)},kAEHa:e[n(1115)]};if(e[n(1913)](e[n(567)],e.wQKnI))this[n(1754)+"rs"]={};else{if(heMrhs[n(1647)](heMrhs[n(726)](_0x4b1637[n(1812)],_0x2f345e),_0x1cc05e.limit))throw new _0x2c1b31(heMrhs[n(1760)]);_0x5ed4bf.offset+=_0x18fe76}}[t(1250)](n,...s){let d=t,f=this[d(1754)+"rs"][n];if(f)f.slice()[d(1474)](p=>p.fn.apply(p[d(870)],s));else if(e[d(803)]===n&&!this.onerror){let p=s[d(510)]&&s[0];if(e[d(1720)](p,Error))throw p;let _=new Error(e[d(1155)](d(1654)+d(1173),p?e[d(1617)](" (",p[d(1460)])+")":""));throw _.context=p,p}return this}[t(1802)](n,s){let d=t;if(e[d(1919)](void 0,n))this[d(1754)+"rs"]={};else if(e.BFLgL(void 0,s))this._listeners[n]=null;else if(e[d(701)]("NLUKA",d(824)))_0x2caaf9&&_0x20f982[d(1893)+d(1405)](gwCvCj[d(1871)],()=>_0x4ab251()),_0x5b4b4c&&_0x14387f[d(1893)+"Listener"](gwCvCj[d(1965)],()=>_0x2ecbd1());else{let f=this[d(1754)+"rs"][n];if(f)for(let p=0;e[d(1693)](p,f[d(510)]);)e[d(507)](f[p].fn,s)?f[d(1207)](p,1):++p}return this}on(n,s,d){let f=t,p={vQfkv:f(1234)+f(564)+"s",QFniM:function(_,w,g){return _(w,g)}};if(e[f(840)](e.KWzJz,e[f(1319)]))return(this[f(1754)+"rs"][n]||(this[f(1754)+"rs"][n]=[]))[f(1880)]({fn:s,ctx:d||this}),this;this[f(755)+f(811)](),this.emit(p[f(472)],f(1908)),this[f(578)+f(619)+"Id"]=p[f(1652)](_0x3864ce,this[f(1513)][f(1225)](this),_0x470646)}}class pp extends ca{[t(1868)+"rrorMessage"](n){let s=t;return n[s(1640)]||n[s(1326)]?(s(1917)+" "+(n[s(1640)]||"")+" code: "+(n.errNo||""))[s(1267)]():JSON.stringify(n)}constructor(n,s,d){let f=t;super(),this._socket=null,$r&&wx[f(1454)+f(1642)]&&(this[f(766)]=wx[f(1454)+"ocket"]({url:n,protocols:s,header:d,fail:this[f(532)+"ocketFailHandler"][f(1225)](this),success:this[f(532)+f(1089)+"cessHand"+f(1803)][f(1225)](this)})),Tn&&tt.connectSocket&&(this._socket=tt[f(1454)+"ocket"]({url:n,protocols:s,header:d,fail:this[f(532)+f(1322)+f(812)].bind(this),success:this["_createSocketSuc"+f(1773)+f(1803)][f(1225)](this)}))}[t(532)+t(1089)+t(1773)+t(1803)](){let n=t;Promise[n(1179)]()[n(923)](()=>{let s=n;this[s(1312)+s(976)]()})}[t(532)+"ocketFai"+t(812)](n){let s=t;Promise[s(1179)]().then(()=>{let d=s,f=e.Mfeya(at,e[d(803)],{message:this[d(1868)+d(1299)+d(699)](n)});this[d(1250)](d(751),f);let p=e[d(1961)](xt,d(1150),{reason:this[d(1868)+d(1299)+"age"](n)});this[d(1250)](d(1150),p)})}[t(1312)+"steners"](){let n=t,s={MJSJu:e[n(1871)],oQtaZ:function(d,f,p){return e[n(639)](d,f,p)},fyWhe:e.vslcB,TaEHR:function(d,f,p){return d(f,p)}};this._socket.onOpen(d=>{let f=n;this[f(1250)](e[f(1184)],Qd(f(1641),{...d,data:d[f(1640)]||""}))}),this[n(766)][n(1488)](d=>{let f=n;this[f(1250)](s[f(1494)],s.oQtaZ(xt,f(1150),{...d}))}),this[n(766)][n(469)+"e"](d=>{let f=n;this[f(1250)](f(1460),e[f(519)](Xd,e.HjYYT,{...d}))}),this[n(766)][n(622)](d=>{let f=n;this[f(1250)](s[f(1330)],s[f(1029)](at,s.fyWhe,{...d,message:d[f(1640)]||""}))})}[t(711)](n){let s=t,d={DptAJ:function(f,p){return e[K(1355)](f,p)},tVTtT:function(f,p){return e[K(1249)](f,p)},EHXnV:function(f,p){return e.gMLyO(f,p)},iBRfM:e[s(527)],eymbg:function(f,p){return e.bTSpB(f,p)},SfljP:s(1421),qvFkk:function(f,p,_){return f(p,_)}};if(e[s(822)](n,Uint8Array))if(e[s(1504)](e[s(958)],e[s(638)])){if(_0xdc44fe)return new _0x36d04e(_0x2f0d32.url,_0x325552[s(1620)]);if(d[s(1588)](_0x35676b,_0x594b25))return new _0x5d3d00(_0x110d66[s(1793)],_0x33f28c[s(1620)],_0x4095eb[s(1323)]);if(d.tVTtT(_0x506431,_0x5ea25d)&&d[s(1941)](d[s(1245)],typeof _0x451207)&&_0x163924)return new _0x293ce8(_0x425253[s(1793)],_0x365720.protocols)}else{let f=n[s(1490)][s(528)](n.byteOffset,e[s(1428)](n[s(1540)+"th"],n[s(517)+"et"]));this[s(766)]&&this[s(766)][s(711)]({data:f,fail:p=>{let _=s;if(e.Bsxjk(e.ZNvAz,e[_(1211)]))this[_(1250)](e[_(803)],e[_(1463)](at,e.vslcB,{message:this[_(1868)+_(1299)+_(699)](p)}));else return this[_(1362)+"T"]||this._isMiniWX?this["_miniNav"+_(984)+_(681)]:(this[_(1742)+"er"]||this[_(1845)+"r"])&&this[_(1185)]["listenNetworkCha"+_(495)]?_0x5f3665[_(776)]:!0}})}else this[s(766)]&&this._socket[s(711)]({data:n,fail:f=>{let p=s;d[p(1252)](d[p(1545)],d[p(1545)])?this._ws&&this[p(603)][p(1150)](_0x118d92,_0x264cee):this[p(1250)]("error",d[p(1949)](at,p(751),{message:this["_formatE"+p(1299)+p(699)](f)}))}})}[t(1150)](n,s){let d=t;this._socket&&this._socket[d(1150)]({code:n,reason:s})}[t(1893)+t(1405)](n,s){this.on(n,s)}[t(1189)+"entListe"+t(1315)](n,s){this[t(1802)](n,s)}get readyState(){let n=t;return this[n(766)][n(1945)+"te"]}get[t(1203)+"pe"](){let n=t;return this._socket[n(1203)+"pe"]}set[t(1203)+"pe"](n){}get url(){let n=t;return this[n(766)][n(1793)]}get[t(1620)](){let n=t;return this[n(766)][n(1620)]}get[t(1852)+"ns"](){let n=t;return this._socket[n(1852)+"ns"]}get[t(1382)+t(1409)](){return 0}}function gp(a,n){let s=t;if(n)return new n(a.url,a[s(1620)]);if($r||Tn)return new pp(a[s(1793)],a.protocol,a[s(1323)]);if((Xn||Vr)&&s(800)+"d"!=typeof WebSocket&&WebSocket)return new WebSocket(a[s(1793)],a[s(1620)+"s"])}function mp(a){let n=t;if(e.hJmrk(e[n(1792)],e[n(590)])){let s=e[n(1891)].split("|"),d=0;for(;;){switch(s[d++]){case"0":if(Tn&&tt[n(1454)+n(1642)])return!0;continue;case"1":if(a)return!0;continue;case"2":if(e[n(1776)](Xn,Vr)&&e[n(1063)](e.tzAlG,typeof WebSocket)&&WebSocket)return!0;continue;case"3":if($r&&wx[n(1454)+n(1642)])return!0;continue;case"4":return!1}break}}else return new _0x2b23df(_0xbf0fcb,{message:_0x4adbbe})}function tl(a,n,s){let d=t,f={LhMoG:function(w,g){return w<=g},Mbjqf:d(1870)+d(1040)+d(1723)+"imes in process",tkYXO:function(w,g){return e[d(693)](w,g)},uWbEb:function(w,g){return e[d(1468)](w,g)}},p=-1;async function _(w){let g=d;return f[g(1051)](w,p)?Promise[g(1890)](new Error(f[g(1715)])):(p=w,f[g(1837)](w,s[g(510)])?Promise[g(1179)]():s[w][g(1225)](a)(n,_[g(1225)](null,f.uWbEb(w,1))))}_(0)}function nl(a){let n=t,s=0,d=0;for(let f=0;e[n(1239)](f,a[n(510)]);++f)d=a[n(1440)+"At"](f),e[n(1010)](d,128)?s+=1:e[n(1397)](d,2048)?s+=2:e.HeHrx(e[n(1659)](64512,d),55296)&&e[n(621)](64512,a.charCodeAt(f+1))===56320?(++f,s+=4):s+=3;return s}function rl(a,n,s){let d=t,f={devSC:function(p,_){return e.gDGaQ(p,_)}};if(e[d(816)](e[d(1318)],e[d(1883)])){let p=_0x3bdac7[d(1432)+"g"](0,tyiNOJ[d(1817)](4,_0x3eb1fa[_0x1853fd][d(510)])),_=p.concat(_0x5f00b5[_0x57708a]);_0x570d55[d(1880)](_)}else{if(e.YwpOV(e.jzpKG(s,n),1))return"";let p="";for(let _=n;_<s;)if(e[d(1289)](e[d(616)],e[d(616)])){let w=a[_++];if(e[d(1719)](w,127))p+=String[d(849)+d(1080)](w);else if(e[d(1666)](w,192)&&e[d(960)](w,224))p+=String[d(849)+"Code"](e.kcCQO(e.IszwV(e.lYvnI(31,w),6),e[d(1172)](63,a[_++])));else if(e.TkSCF(w,224)&&e[d(1993)](w,240))p+=String[d(849)+d(1080)](e[d(827)](e.vdUDj((15&w)<<12,e[d(542)](63,a[_++])<<6),e[d(1935)](63,a[_++])));else if(e[d(881)](w,240)){let g=e[d(496)](e[d(1784)](e[d(1979)](7&w,18)|e[d(1989)](e[d(625)](63,a[_++]),12),e.tRGta(63,a[_++])<<6)|e[d(1659)](63,a[_++]),65536);p+=String[d(849)+d(1080)](e[d(549)](55296,e.seJjv(g,10))),p+=String.fromCharCode(e[d(1694)](56320,e[d(1565)](1023,g)))}}else this[d(1086)]=_0x2c7a3a,this[d(1408)]=null;return p}}function da(a,n,s){let d=t,f={qcPPK:function(g,S){return e[K(858)](g,S)},HzEuF:function(g,S){return e[K(1669)](g,S)},ByYds:function(g,S){return g&S}},p=s,_,w;for(let g=0;e[d(1204)](g,a.length);++g)if(e[d(1290)](e[d(1167)],d(1855)))_0x1fa415[_0x75185a++]=f[d(889)](_0x4a1520,6)|192,_0x151399[_0x3b6bc8++]=f.HzEuF(f.ByYds(63,_0x530810),128);else if(_=a.charCodeAt(g),_<128)n[s++]=_;else if(e[d(1705)](_,2048))n[s++]=e[d(983)](e[d(1665)](_,6),192),n[s++]=e.cwRQg(e[d(1191)](63,_),128);else if(e[d(507)](e[d(642)](64512,_),55296)&&e.HwRjj(64512&(w=a[d(1440)+"At"](g+1)),56320)){let S=("3|0|1|5|"+d(584))[d(903)]("|"),D=0;for(;;){switch(S[D++]){case"0":++g;continue;case"1":n[s++]=_>>18|240;continue;case"2":n[s++]=e[d(782)](e[d(946)](63,_),128);continue;case"3":_=e[d(1481)](e.aXUxQ(65536,e[d(621)](1023,_)<<10),e[d(731)](1023,w));continue;case"4":n[s++]=e[d(735)](e.uNYzE(e[d(487)](_,6),63),128);continue;case"5":n[s++]=e[d(782)](e[d(867)](e[d(1818)](_,12),63),128);continue}break}}else n[s++]=e[d(1254)](_,12)|224,n[s++]=e.mPOYV(e.hYhwv(e.ZIwZU(_,6),63),128),n[s++]=e[d(1928)](e.FlKau(63,_),128);return e[d(496)](s,p)}async function il(a){let n=t;if(e[n(978)]==typeof a){let s=new Uint8Array(e.Qmvfv(nl,a));return e.RlQaP(da,a,s,0),s}return a instanceof ArrayBuffer?new Uint8Array(a):new Uint8Array(a[n(1490)],a[n(517)+"et"],a[n(1540)+"th"])}function wp(a){let n=t,s={pfLkb:function(d,f){return d(f)}};try{return e[n(1493)](e.dJlbL,typeof a)&&(e[n(1867)](a,ArrayBuffer)||a.buffer&&e[n(994)](a.buffer,ArrayBuffer))||e[n(978)]!=typeof a?"":(JSON.parse(a),e[n(1533)])}catch{if(e[n(1919)](e.OvqBt,e[n(769)]))_0x2ffd64=s.pfLkb(_0x519ee1,_0x1aad4d),_0x1df571=0;else return e[n(1819)](e[n(978)],typeof a)?n(660)+"in;chars"+n(602):""}}let _p=(a,n)=>{let s=t;switch(a){case e[s(1425)]:case e[s(1269)]:return{[s(799)+a]:1,"x-tt-env":n};default:return{}}};class yp{constructor(n){let s=t;this[s(1353)+s(1116)]=n,this[s(1464)]=0}[t(871)](){let n=t;this[n(1464)]++}[t(1518)+t(468)+"nt"](){let n=t;if(e[n(1885)](e[n(947)],e[n(483)]))return e.pqGmt(this[n(1464)],this[n(1353)+"ount"]);this[n(766)]&&this[n(766)][n(1150)]({code:_0x4e7efc,reason:_0xbb8836})}[t(736)+t(1873)](n=0){let s=t;this["maxLossC"+s(1116)]=n,this[s(1464)]=0}}async function bp(a){let n=t,s={GxnNM:function(d,f){return d(f)},fJaGt:e[n(1097)]};if(e[n(1182)](e[n(866)],e[n(1492)]))return new Promise(d=>{let f=n;if(!Xn)return e[f(733)](d,e[f(1097)]);try{let p=document["createEl"+f(1383)](e[f(1959)]);window[f(1842)+"JSONP"]=_=>{let w=f;document[w(720)][w(1336)+w(1064)](p),window[w(1842)+w(658)]=void 0,s[w(1406)](d,_&&_.msg||s[w(1925)])},p[f(1086)]=f(615)+f(570),p.src=e[f(996)](a.replace(/^ws/,e[f(1535)]),e[f(1569)]);try{if(e[f(1616)](e[f(912)],f(1969)))document[f(720)]["appendCh"+f(1064)](p);else return this[f(766)][f(1945)+"te"]}catch{if(e[f(1262)](e[f(1683)],f(1395)))document.body[f(1336)+f(1064)](p);else return this.count>=this[f(1353)+f(1116)]}}catch{window[f(1842)+f(658)]=void 0,e[f(1674)](d,e[f(1097)])}})}function tn(a,n,s){let d=t;return!!a?.[d(902)](f=>f[d(1621)]===n&&f[d(1304)]===s)}function Qn(a,n){let s=t;return a?.[s(902)](d=>d[s(1621)]===n)?.[s(1304)]}let la=null;async function Ep(){let a=t;return la||(la=Promise[a(1179)]()[a(923)](Nt.bind(Nt,e.rHPQy))),la}class vp extends ca{constructor(n,s){let d=t;super(),this[d(859)]=n,this._keyPath=s,this[d(1369)]=void 0,this["_initPro"+d(1827)]=null}async[t(623)](){await this[t(1982)]()}async[t(1982)](){let n=t,s={hiIeS:function(d){return e[K(974)](d)},fnBks:function(d,f,p,_){return d(f,p,_)}};if(!this._qosDB){if(this[n(885)+n(1827)])return this[n(885)+"mise"];try{let d=this._dbName,f=this[n(1404)];this[n(885)+n(1827)]=(async()=>{let p=n,{openDB:_}=await s[p(1095)](Ep);this._qosDB=await s.fnBks(_,p(1842)+"_"+d,1,{upgrade(w){let g=p;w[g(1713)+g(1208)+"e"](d,{keyPath:f})}})})(),await this[n(885)+n(1827)]}catch(d){console[n(963)](d)}finally{this[n(885)+n(1827)]=null}}}async get(n){let s=t;try{return await this[s(1982)](),this[s(1369)]?.get(this[s(859)],n)}catch(d){console[s(963)](d)}}async[t(1378)](n,s){let d=t;return await this[d(1982)](),this[d(1369)]?.[d(1887)](this[d(859)],n)}async[t(1499)](n){let s=t;if(e[s(828)](e[s(1243)],"LfKmc"))try{if(e[s(1098)](s(1356),e[s(488)]))_0x350ad0=e[s(1489)](_0x150bd7,_0x297fba),e[s(1993)](_0x581349,32)&&(_0x72d4f6|=e[s(1752)](127&_0xc30bfe,_0xf0f33e)),_0x10ddaa+=7;else return await this[s(1982)](),this[s(1369)]?.[s(794)](this[s(859)],n)}catch(d){console[s(963)](d)}else{let d=e[s(1009)](_0x36f290,_0x118436,_0x5980ef[s(643)]),f=_0x26a52c[s(1334)],p=_0x427bc6.bytes;for(let _=0,w=_0x3f76ac[s(643)];e[s(1148)](_,w);_++)f[e.YrVhj(_,d)]=p[_]}}async[t(845)](){let n=t,s={Swsvp:function(d,f){return d<f},tQkRr:function(d,f){return e.jzpKG(d,f)},XetMc:function(d,f){return d<=f},gAxtP:function(d,f){return d>=f},xshLG:function(d,f){return d|f},Ebgii:function(d,f){return d<<f},NDhMO:function(d,f){return e[K(464)](d,f)},rcSjn:function(d,f){return d>=f},mfBKv:function(d,f){return d|f},wfvqg:function(d,f){return e.QtFrm(d,f)},yIzpC:function(d,f){return e[K(618)](d,f)},HQhKZ:function(d,f){return d-f},TCYni:function(d,f){return d|f},gciXh:function(d,f){return e[K(1962)](d,f)},MmBRz:function(d,f){return d<<f},gjEiB:function(d,f){return e[K(961)](d,f)},DdHqR:function(d,f){return e.uglll(d,f)}};if(n(1079)!==e[n(993)])try{return await this._init(),this._qosDB?.[n(845)](this[n(859)])}catch(d){console.log(d)}else{if(mVBESk[n(1244)](mVBESk[n(526)](_0x2430f1,_0x4cdded),1))return"";let d="";for(let f=_0x5a580c;mVBESk[n(1244)](f,_0x41320d);){let p=_0xb32e6d[f++];if(mVBESk[n(1910)](p,127))d+=_0xaf96a1[n(849)+n(1080)](p);else if(mVBESk.gAxtP(p,192)&&mVBESk[n(1244)](p,224))d+=_0x45d536[n(849)+n(1080)](mVBESk[n(1733)](mVBESk[n(894)](mVBESk[n(1898)](31,p),6),63&_0x532f36[f++]));else if(mVBESk[n(953)](p,224)&&p<240)d+=_0x50fc69[n(849)+n(1080)](mVBESk[n(1445)](mVBESk[n(894)](mVBESk[n(1218)](15,p),12),mVBESk[n(894)](mVBESk[n(520)](63,_0x353f0a[f++]),6))|63&_0x3e7a88[f++]);else if(p>=240){let _=mVBESk[n(1836)](mVBESk.TCYni(mVBESk[n(1242)](mVBESk[n(1586)](mVBESk[n(894)](mVBESk[n(1218)](7,p),18),mVBESk[n(1898)](63,_0x4caf52[f++])<<12),mVBESk[n(964)](63&_0x2b8fed[f++],6)),mVBESk[n(1218)](63,_0x31f277[f++])),65536);d+=_0xbd1d3a[n(849)+n(1080)](mVBESk[n(1017)](55296,mVBESk[n(1511)](_,10))),d+=_0x32aef4.fromCharCode(mVBESk.gjEiB(56320,1023&_))}}return d}}async[t(748)](){let n=t;return await this._init(),this[n(1369)]?.[n(576)+"ys"](this[n(859)])}async[t(1568)](){let n=t;return await this[n(1982)](),this._qosDB?.[n(1568)](this._dbName)}async[t(717)](){let n=t;try{this[n(1369)]?.[n(1150)](),this._qosDB=void 0}catch(s){console[n(963)](s)}}get[t(774)](){let n=t;try{return!!this[n(1369)]}catch(s){return console.log(s),!1}}}class Sp{constructor(n,s){let d=t;this[d(1562)]=n,this[d(634)]=s,this[d(1369)]=localStorage}async[t(623)](){}get[t(1781)](){return"frontier_"+this[t(1562)]}async[t(1039)](n){let s=t,d={rhPav:function(f,p){return f*p},iTlKL:function(f,p){return f>p}};if(e[s(1418)](s(546),e[s(905)])){let f=_0x5a9482.bytes,p=_0x3fd209.offset,_=_0x5925a3.limit,w=p+_0x4571fa;if(w>f.length){let g=new _0x160c7f(WPfjcU[s(793)](2,w));g[s(1378)](f),_0x17b76f[s(1334)]=g}return _0x5a86eb.offset=w,WPfjcU[s(1734)](w,_)&&(_0x40a422[s(643)]=w),p}else{let f=this[s(1369)][s(935)](this[s(1781)]);return JSON[s(1726)](e[s(1249)](f,"{}"))[n]}}async[t(1378)](n,s){let d=t,f=this._qosDB.getItem(this[d(1781)]),p=JSON[d(1726)](e[d(1849)](f,"{}"));return p[s||n[this[d(634)]]]=n,this[d(1369)][d(1814)](this[d(1781)],JSON[d(835)+"y"](p)),s||n[this[d(634)]]}async[t(1499)](n){let s=t;if(e[s(1262)](e.Vxnnv,e[s(641)])){let d=this[s(1369)][s(935)](this[s(1781)]),f=JSON[s(1726)](e[s(1055)](d,"{}"));return f[n]=void 0,this[s(1369)][s(1814)](this[s(1781)],JSON[s(835)+"y"](f))}else return _0x120610[s(963)](_0x89b7b2),!1}async clear(){let n=t;if(e[n(1469)](e[n(594)],n(1129)))_0x5641e6=_0x31fcd8[e.mBNeh(e[n(1648)](_0x376a4f,_0xf4baf4),1)],_0x15587b=_0x4d7b5c[e[n(465)](e[n(1850)](_0x2b7cea,_0x48fa),2)],e[n(1054)](e[n(688)](e[n(1772)](_0x371935,e[n(1952)](_0x34b18b,8)),49344),32896)?_0x4e4893+=_0x56990c:(_0xe16a9f=e[n(1684)](e.tFqUe(e[n(1903)](15,_0x109acb),12),e[n(854)](e.ODZjc(63,_0x5aeb65),6))|e[n(906)](63,_0x9366a4),_0x1d3df2<2048||e[n(1003)](_0x10a07c,55296)&&_0x6eb5a4<=57343?_0x3e58d4+=_0x3d4f60:(_0x48e77b+=_0x325890(_0x389d11),_0x123cdf+=2));else return this[n(1369)][n(845)]()}async keys(){let n=t,s=this[n(1369)].getItem(this[n(1781)]),d=JSON[n(1726)](s||"{}");return Object.keys(d)}async[t(1568)](){let n=t,s=this[n(1369)].getItem(this[n(1781)]),d=JSON[n(1726)](e.DCsOP(s,"{}"));return Object.values(d)}[t(717)](){return Promise[t(1179)]()}get[t(774)](){let n=t,s={lOJxO:function(d,f){return d(f)},PSqhM:e.eBYVP};if(n(1134)==="uLVQv")_0x73ec6b[n(720)][n(1336)+"ild"](_0x2ace50),_0x5974ad[n(1842)+n(658)]=void 0,GVSJNM[n(1255)](_0x460d3e,_0x4cc8db&&_0x40f464.msg||GVSJNM[n(610)]);else return!!this[n(1369)]}}class Ip{constructor(n,s){let d=t;this._DBName=n,this[d(634)]=s,this[d(1369)]=Tn?tt:$r?wx:null}async[t(623)](){}get[t(1781)](){let n=t;return n(1842)+"_"+this[n(1562)]}async[t(1039)](n){let s=t,d=this._qosDB.getStorageSync(this[s(1781)]);return JSON[s(1726)](e.wxVeB(d,"{}"))[n]}async set(n,s){let d=t;if(e.pSQgf(e[d(1475)],e[d(1475)])){let f=this[d(1369)][d(1611)+d(1902)](this[d(1781)]),p=JSON[d(1726)](f||"{}");return p[s||n[this[d(634)]]]=n,this[d(1369)][d(1774)+"geSync"](this[d(1781)],JSON[d(835)+"y"](p)),s||n[this[d(634)]]}else{let f=_0x22ac1b[d(903)](":");for(let p=0;e.uJXxX(p,f[d(510)]);p++){let _=f[p];if(e.wXrif(4,f[p].length)){let w=_0x5e9966.substring(0,e.hPmhQ(4,f[p][d(510)])),g=w[d(1412)](_);_0x2c0456=_0x55600f.concat(g)}else _0x1c68fc=_0x45282e[d(1412)](_)}return _0x177dad}}async del(n){let s=t;if(e[s(1885)](e[s(878)],s(1526))){let d=this._qosDB["getStora"+s(1902)](this[s(1781)]),f=JSON[s(1726)](d||"{}");return f[n]=void 0,this[s(1369)].setStorageSync(this[s(1781)],JSON[s(835)+"y"](f))}else _0x2fde6a=_0x22e2d4[e[s(1045)](e[s(1874)](_0x4b8854,_0x15f68c),1)],_0x5e39af=_0x3fca46[e[s(996)](_0x102ebc+_0x537f33,2)],_0x379570=_0x27ac7a[e[s(1974)](_0x332ea8,_0x5728fe)+3],e[s(1004)](e[s(782)](_0x3c60d8,e[s(1944)](_0xbf63c3,8))|e[s(927)](_0x51e8d5,16),12632256)!==8421504?_0x44e2b2+=_0x45c0c2:(_0x587398=e.wMgXZ(e[s(1111)](e[s(847)](e.aVWZE(7,_0x44d00a),18)|e.SKAFo(63&_0x52ffc7,12),e.vqzGS(63,_0x4d074d)<<6),e[s(982)](63,_0x33cdf8)),e.TXWbF(_0x5acc33,65536)||_0x30a77b>1114111?_0x5f21df+=_0x42e638:(_0x2f9826-=65536,_0x44bcea+=e.mlGRN(_0x2d5f82,e[s(1525)](_0x4b8c6f>>10,55296),e[s(945)](e[s(787)](1023,_0x3b0e82),56320)),_0x3a4cc0+=3))}async[t(845)](){let n=t;return this[n(1369)][n(1765)+"rageSync"]()}async keys(){let n=t,s=this[n(1369)][n(1611)+"geInfoSync"](this[n(1781)]),d=JSON[n(1726)](e.nHQbV(s,"{}"));return Object[n(748)](d)}async getAll(){let n=t,s=this[n(1369)][n(1611)+"geInfoSync"](this[n(1781)]),d=JSON[n(1726)](e[n(1579)](s,"{}"));return Object[n(1517)](d)}[t(717)](){return Promise[t(1179)]()}get[t(774)](){return!!this[t(1369)]}}function sl(a,n){let s=t;if(e[s(1055)](Tn,Tn))return new Ip(a,n);if(e[s(1644)](Xn,Vr)&&e[s(1493)](e[s(527)],typeof indexedDB))return new vp(a,n);if(e[s(973)](Xn,Vr)&&e[s(943)]("undefined",typeof localStorage))return new Sp(a,n);throw new Error(e[s(1292)])}class Ap{constructor(){let n=t;this[n(704)+n(690)+"Id"]=null,this[n(704)+"l"]=36e5,this[n(1369)]=e.HgGiJ(sl,e[n(1529)],e[n(632)])}async[t(704)+"lFlush"](){let n=t;if(e[n(1367)](e[n(818)],e[n(818)]))try{this[n(603)]&&this._ws[n(1150)](_0x5765dc,_0x50620e)}catch{}else clearInterval(this[n(704)+n(690)+"Id"]),this[n(704)+n(690)+"Id"]=e[n(920)](setInterval,()=>{let s=n;this[s(583)+s(712)]()},this[n(704)+"l"])}async[t(623)](){let n=t;await this._qosDB[n(623)]()[n(923)](()=>{let s=n;this[s(704)+s(954)]()})}async[t(583)+"ired"](){let n=t;(await this[n(1369)]?.[n(1568)]()||[]).filter(({timestamp:f})=>f<Date[n(1630)]())[n(1474)](f=>{let p=n;this[p(1369)]?.[p(1499)](f[p(1118)+"id"])})}async del(n){let s=t;if(e.DHynw(e[s(1361)],e[s(1363)]))return this._qosDB?.del(n);this[s(1353)+s(1116)]=_0x2e695c,this.count=0}async[t(1378)](n,s){let d=t;return this[d(1369)]?.[d(1378)]({message_id:n,timestamp:s})}async[t(1039)](n){let s=t;return this[s(1369)]?.[s(1039)](n)}async[t(717)](){let n=t;e[n(645)](clearInterval,this[n(704)+n(690)+"Id"]),await this[n(1369)]?.closeDB()}get[t(774)](){return this._qosDB?.isReady}}function ua(a){let n=t,s=!!this[n(1185)][n(1042)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let d=e.TWBkT(tn,a[n(1460)][n(1323)],e[n(1485)],"2"),f=d&&e[n(1066)](tn,a[n(1460)].headers,e[n(1718)],"1"),p=d&&e[n(1631)](tn,a.message[n(1323)],e[n(665)],"1"),_=p?Qn(a.message[n(1323)],e[n(604)])?.[n(903)](",")[n(1423)](Boolean)||[]:[];return{enabled:s,isQoSMessage:d,isQoSAck:f,isAckCleanupMessage:p,ackMsgIds:_}}async function ol(){let a=t,n={xuwqL:function(s,d,f){return e.UytEZ(s,d,f)},mbLDg:function(s,d){return s|d},jhvXJ:function(s,d){return e[K(1950)](s,d)}};if(e[a(1707)](e.uYOaa,e[a(1761)]))return this[a(1905)+a(1627)]||(this[a(1905)+a(1627)]=new Ap),this["_QoSMana"+a(1627)][a(774)]||await this["_QoSMana"+a(1627)][a(623)](),this["_QoSMana"+a(1627)];pTMagO.xuwqL(_0xebd643,_0x4701df,pTMagO.mbLDg(pTMagO.jhvXJ(127,_0x24e2c5),128)),_0x1e6162>>>=7}async function Tp(a,n){let s=t,{enableAutoAck:d}=this[s(1185)],f=e.RlQaP(tn,a[s(1460)][s(1323)],s(628),"1"),p=e[s(1584)](tn,a[s(1460)][s(1323)],"is_ack","1"),_=ua[s(1832)](this,a);if(e[s(846)](d,f)){let{SeqID:w,LogID:g,service:S,LogIDNew:D,method:N}=a[s(1460)];this[s(1920)]({SeqID:w,LogID:g,LogIDNew:D,service:S,method:N,headers:[{key:e[s(810)],value:"1"},{key:e[s(1158)],value:D||""},{key:e[s(1896)],value:"0"}]})}p&&!_[s(1257)]&&this["_dispatc"+s(499)+s(737)](a),e[s(1273)](n)}async function kp(a,n){let s=t;e.WhbSy(e.zUtZq,e[s(1346)])?(this._debug(e[s(1831)],a[s(1460)]),e[s(974)](n)):(this.emit(e[s(1653)],_0x2b93fb),this[s(1613)+s(1510)]&&this[s(1613)+s(1510)](_0x431c38))}async function Cp(a,n){let s=t,d={MEgEY:function(p,_,w,g){return e[K(998)](p,_,w,g)},IJyHx:function(p,_){return e[K(1195)](p,_)},qHtIL:e.lmSoP,GpjrC:function(p,_){return e[K(728)](p,_)},uaThg:function(p){return p()}},f=e[s(518)](Xt,await il(a.data));try{if(e[s(994)](f[s(1740)],Uint8Array))if(e.Okygz(e[s(1721)],e[s(1514)])){let p=e[s(1200)](this[s(1185)][s(710)+s(967)],Object)?{force:!!this[s(1185)][s(710)+s(967)][s(910)],encoding:this[s(1185)][s(710)+s(967)][s(1169)]?this._options.payloadEncoding[s(1169)][s(1447)](/\s/g,"")[s(1745)+s(1015)]():""}:{force:!1,encoding:this[s(1185)][s(710)+s(967)]?this._options[s(710)+"ncoding"][s(1447)](/\s/g,"")[s(1745)+"ase"]():""},_=f[s(710)+s(967)]?f[s(710)+s(967)][s(1447)](/\s/g,"")[s(1745)+s(1015)]():"",w=e.OCTdJ(this[s(1185)][s(939)+s(1399)],Object)?{force:!!this[s(1185)][s(939)+s(1399)][s(910)],type:this[s(1185)][s(939)+"ype"][s(1086)]?this._options[s(939)+s(1399)][s(1086)].replace(/\s/g,"")["toLowerC"+s(1015)]():""}:{force:!1,type:this[s(1185)]["payloadT"+s(1399)]?this[s(1185)][s(939)+s(1399)][s(1447)](/\s/g,"")[s(1745)+s(1015)]():""},g=f[s(939)+s(1399)]?f[s(939)+s(1399)][s(1447)](/\s/g,"")["toLowerC"+s(1015)]():"",S=w[s(910)]?w.type:g||w[s(1086)],D=p[s(910)]?p[s(1169)]:_||p[s(1169)],N=[e[s(966)],s(986)+"ion/json",e[s(644)],e.dJlbL],U=[e.hKdeu,"binary"];this._options[s(537)+s(1342)+s(951)+"ad"]&&N.includes(S)&&(!D||U[s(463)](D))?f[s(663)+s(1006)]=e[s(784)](rl,f[s(1740)],0,f[s(1740)][s(1540)+"th"]):f[s(663)+s(1006)]=""}else{let{enableAutoAck:p}=this._options,_=_0x25f860(_0x3cdbf3[s(1460)][s(1323)],s(628),"1"),w=AfNLTQ.MEgEY(_0x34df95,_0x4e00f1[s(1460)].headers,s(612),"1"),g=_0x87ccf1.call(this,_0xbc65e);if(AfNLTQ[s(721)](p,_)){let{SeqID:S,LogID:D,service:N,LogIDNew:U,method:V}=_0x456399[s(1460)];this[s(1920)]({SeqID:S,LogID:D,LogIDNew:U,service:N,method:V,headers:[{key:s(612),value:"1"},{key:AfNLTQ[s(500)],value:AfNLTQ[s(1099)](U,"")},{key:s(1170),value:"0"}]})}w&&!g[s(1257)]&&this["_dispatc"+s(499)+s(737)](_0x3fd689),AfNLTQ[s(678)](_0xb10a46)}else f[s(663)+s(1006)]=""}catch(p){f[s(663)+"oad"]="",console[s(963)](p)}a.message=f,n()}function Rp(a,n,s){let d=t,f={vsYMP:function(S){return S()},DTevn:function(S,D){return e.NZduB(S,D)},xPHhy:d(723),vpJJM:e[d(874)],RkTby:function(S,D){return S<D},zVLxV:function(S,D){return e[d(1057)](S,D)},pPpZf:function(S,D){return S(D)},LWGli:function(S,D){return e[d(1057)](S,D)},DJVTs:function(S,D){return e.DzmIb(S,D)},zwGPw:function(S,D){return e[d(574)](S,D)},Gvcnc:function(S,D){return e[d(1001)](S,D)}},p=e[d(1767)](s,8192),_=e[d(1109)](p,1),w=null,g=p;return function(S){let D=d,N={AOAlX:function(U){return f[K(1429)](U)},QOXKa:function(U,V,J){return U(V,J)}};if(f[D(907)](f[D(1259)],f[D(916)])){if(f[D(1662)](S,1)||f[D(1187)](S,_))return f[D(1594)](a,S);f.LWGli(f[D(1069)](g,S),p)&&(w=f[D(1594)](a,p),g=0);let U=n[D(1832)](w,g,g+=S);return f.zwGPw(7,g)&&(g=f[D(1088)](7,g)+1),U}else{let U=JyIjdn.AOAlX(_0x4d47dd);return JyIjdn[D(1285)](_0x2d1304,_0x2df348,U),_0x590ca3(U)}}}let Dp=4294967295;function Pp(a,n,s){let d=t;return e[d(1384)](RangeError,e[d(573)](e.QvWPV(e[d(1072)](e[d(945)](e[d(805)]("index out of ran"+d(1757),a),e.xKqNA),e[d(728)](n,1)),e[d(669)]),s))}function Op(a,n,s){let d=t;if(s>Dp)throw new Error(e[d(486)]);let f=3;for(;e[d(1224)](f,0);)if(e[d(850)](e[d(857)],d(1629))){let{type:p}=_0x1a610d;this[d(1250)](p,_0x2dc01d)}else{let p=e[d(906)](255,s);e[d(848)](xa,p,a,e[d(996)](n,f)),s>>>=8,f--}return e[d(516)](n,4)}function Lp(a,n){let s=t,d=0,f=n,p=n+4;for(;e[s(838)](f,p);){let{value:_,offset:w}=fa(a,f);f=w,d=e.qZyln(d<<8,0),d+=_}return{value:d,offset:p}}function Np(a,n,s){let d=t,f=e.CBCzw[d(903)]("|"),p=0;for(;;){switch(f[p++]){case"0":if(n[d(836)])return e[d(1033)](n[d(836)](a,s),s);continue;case"1":if(!a)return s;continue;case"2":if(e[d(1413)](a[d(510)],40))return e[d(1443)](da(a,n,s),s);continue;case"3":return da(a,n,s)+s;case"4":if(n.utf8Write)return e[d(1992)](n.utf8Write(a,s),s);continue}break}}function Mp(a,n){let s=t,d=new fe(e.gvsDM(e.vdUDj(e[s(1394)](e[s(722)](a[e[s(1188)](n,4)],24),e[s(847)](a[e[s(1374)](n,5)],16)),e[s(481)](a[n+6],8)),a[e[s(804)](n,7)]),e[s(975)](e.gvsDM(e[s(718)](e[s(1996)](a[e[s(652)](n,0)],24),a[n+1]<<16),a[e[s(996)](n,2)]<<8),a[e[s(1648)](n,3)]),!0);return n+=8,{value:d,offset:e[s(1637)](n,8)}}function Bp(a,n,s){let d=t,f=a[d(1301)],p=a[d(1286)];return n[s]=e.bBvjr(p,24),n[s+1]=e[d(620)](e[d(778)](p,16),255),n[e[d(1525)](s,2)]=e[d(1171)](e[d(1604)](p,8),255),n[e[d(1694)](s,3)]=255&p,n[e[d(1374)](s,4)]=e[d(1636)](f,24),n[e[d(1374)](s,5)]=e[d(942)](f>>>16,255),n[e.bqDxN(s,6)]=e[d(1935)](e[d(1212)](f,8),255),n[e[d(1980)](s,7)]=e[d(1345)](255,f),s+=8,s}function fa(a,n){let s=t,d={MZRgh:function(f){return f()}};if(e[s(1016)](e[s(1117)],e[s(1117)]))this[s(1711)]=!1,_0x149414(this[s(529)+s(1673)+"utId"]),d[s(1350)](_0x47cfe3);else return a.readUInt8?{value:a[s(1667)+"8"](n),offset:e[s(1775)](n,1)}:{value:e[s(1112)](255,a[n]),offset:e[s(805)](n,1)}}function xa(a,n,s){let d=t;return n[d(461)+"t8"]?n.writeUint8(a,s):n[s]=e[d(1847)](255,a),e[d(1687)](s,1)}let Fp=function(a){return new Uint8Array(a)},zp=e[t(884)](e[t(527)],typeof Buffer)?Buffer["allocUns"+t(1194)]:e[t(1463)](Rp,Fp,Uint8Array.prototype.subarray),Up=16,ha=32;function Gp(a){let n=t,s=0,d={};for(let f=0;e[n(1993)](f,a.length);f++)d[a[f][n(1246)+n(1370)]]=e[n(518)](nl,a[f]["cursor_n"+n(1370)]),s+=e.gOXjA(14,d[a[f][n(1246)+"ame"]]);return[s,d]}function al(a,n,s){let d=t,[f,p]=e[d(1674)](Gp,a),_=e[d(1778)](zp,f),w=0;return a[d(1474)](g=>{let S=d,D=e[S(1310)][S(903)]("|"),N=0;for(;;){switch(D[N++]){case"0":w=e[S(926)](Op,_,w,g.service||0);continue;case"1":w=e[S(948)](xa,0,_,w);continue;case"2":console[S(963)](S(523),w);continue;case"3":w=e[S(1583)](xa,p[g["cursor_n"+S(1370)]],_,w);continue;case"4":console[S(963)](e.JLYFT,w);continue;case"5":console.log(S(714),w);continue;case"6":console.log(e[S(1216)],g,g[S(523)]);continue;case"7":console[S(963)](e[S(1309)],w);continue;case"8":w=e[S(998)](Bp,fe[S(1933)+"er"](g[S(1473)]||n),_,w);continue;case"9":w=e.ypqHn(Np,g[S(1246)+S(1370)],_,w);continue;case"10":console[S(963)](e[S(1994)],w);continue}break}}),{frameType:ha,headers:[{key:e.ZsfWj,value:s}],payload:_}}function Hp(a){let n=t,s=0,d=[];for(;e[n(1204)](s,a[n(1540)+"th"]);){let{offset:f}=e[n(929)](fa,a,s);s=f;let p={cursor_name:"",cursor:0,service:0},{value:_,offset:w}=Lp(a,s);p.service=_,s=w;let{value:g,offset:S}=e[n(1577)](fa,a,s);s=S,p[n(1246)+n(1370)]=rl(a,s,e.kjQgU(s,g)),s+=g;let{value:D,offset:N}=Mp(a,s);p.cursor=D[n(1020)](),s=N,d.push(p)}return d}function jp(){return{frameType:ha,headers:[{key:"cursor_f"+t(1238),value:e.PoLlO}],payload:void 0}}class qp{constructor(n,s,d){let f=t;e.iBXlU(e[f(1434)],e[f(972)])?(this[f(1274)+f(1496)]=n,this["_cursorF"+f(719)]=s,this[f(1431)+f(1276)]=d,this[f(1369)]=e[f(1882)](sl,this[f(1274)+f(1496)],e[f(568)])):this[f(1362)+"T"]?_0x2de5ee[f(1130)+f(834)+f(1124)](({isConnected:p})=>{let _=f;this[_(606)+"igatorOn"+_(681)]=p,p?this[_(1389)+_(1574)]():this._handleOffLine()}):this[f(1013)+"X"]&&_0x3de357[f(1130)+f(834)+f(1124)](({isConnected:p})=>{let _=f;this[_(606)+"igatorOn"+_(681)]=p,p?this._handleOnLine():this[_(1389)+_(1646)]()})}async[t(623)](){await this[t(1369)].openDB()}async[t(1791)+"rs"](){let n=t;if(!this._qosDB[n(774)])return;let s=this[n(1431)+n(1276)],d=await this[n(1369)].getAll();switch(console[n(963)](e[n(851)],d),s){case"ALL":return d&&d[n(510)]?al(d,0,this[n(1087)+"ileName"]):void 0;case e[n(692)]:return;case e[n(1410)]:return d&&d.length?e[n(756)](al,d,0,this["_cursorF"+n(719)]):e[n(974)](jp)}}async set(n,s,d){let f=t,p={RVjOw:function(_,w){return e[K(943)](_,w)},kXnnV:function(_,w){return e[K(1651)](_,w)},dFKUJ:function(_,w){return e[K(1924)](_,w)},HMLgy:f(1547),ilARo:f(986)+f(1401),TswMB:function(_,w){return e[f(1819)](_,w)}};if(e[f(640)](e[f(480)],e[f(1995)]))try{return wHJTkE.RVjOw("string",typeof _0x41a7b1)&&(wHJTkE[f(1912)](_0x3aee39,_0x5c2391)||_0x4a1a67.buffer&&wHJTkE[f(1912)](_0x494517[f(1490)],_0xd1cb8f))||wHJTkE[f(1960)](wHJTkE[f(744)],typeof _0x54919d)?"":(_0x32d19f[f(1726)](_0x20d355),wHJTkE[f(1321)])}catch{return wHJTkE.TswMB(wHJTkE[f(744)],typeof _0x4b1c49)?"text/pla"+f(990)+"et=utf-8":""}else return console[f(963)](e[f(1407)],n,s,d),this[f(1369)][f(1378)]({cursor_name:n,cursor:s,service:d})}async[t(580)+"rs"](n){let s=t;if(e[s(1914)]!==e.JeJxG)this[s(1087)+s(719)]=_0x5cb2bd;else{let d=e[s(1384)](Hp,n);for(let f of d)console[s(963)](e[s(1311)],d),await this[s(1369)].set(f)}}async[t(1039)](n){let s=t;return(await this[s(1369)][s(1039)](n))?.[s(1473)]}async closeDB(){let n=t;await this._qosDB[n(717)]()}[t(1708)+"rsorFile"+t(1113)](n){let s=t;this["_cursorF"+s(719)]=n}get[t(774)](){return this[t(1369)].isReady}}let Wp=e.zUdGA;async function cl(a){let n=t;if(!this[n(1185)][n(1042)+"S"])return null;let{aID:s,fpID:d,messageStrategy:f}=this[n(1185)],p=e.OhKlA(a,Wp);try{return this[n(729)+n(1491)]?e[n(1367)](e[n(1146)],e[n(1146)])?(this.emit(e[n(1871)],_0x1a7bcf),this[n(1689)]&&this[n(1689)](_0x4ef8f3)):a&&this[n(729)+n(1491)][n(1708)+n(1328)+n(1113)](a):this._cursorManager=new qp(d+"_"+s+"_"+p,p,f),this[n(729)+n(1491)][n(774)]||await this[n(729)+n(1491)][n(623)](),this[n(729)+n(1491)]}catch{return null}}async function Kp(a,n){let s=t,d=e[s(1306)](tn,a[s(1460)][s(1323)],s(952),"-1"),f=e.uBUdI(tn,a[s(1460)][s(1323)],e[s(810)],"1"),p=e.gEjhr(Qn,a[s(1460)][s(1323)],"x_frontier_msgid"),_=e[s(856)](Number,Qn(a[s(1460)][s(1323)],e[s(1794)]))||0,w=ua[s(1832)](this,a),g=e.tECDw(tn,a[s(1460)][s(1323)],s(940)+"s","2"),S=e.LpugO(Qn,a[s(1460)].headers,e[s(579)]),D=Number(Qn(a[s(1460)][s(1323)],e.iKTnq));if(w[s(1257)])return e[s(1344)](n);let N=w[s(586)+s(1021)]?await ol[s(1832)](this):null;if(e.AgjmK(a.message[s(523)],0)&&f&&!d||e[s(613)](a.message.service,0)){if(p&&w[s(586)+s(1021)]&&N)return!!!await N[s(1039)](p)&&(this[s(1527)+s(1800)+s(505)](a),await N.set(p,e[s(805)](Date[s(1630)](),_))),e.fjVUD(n);if(g){let U=await cl[s(1832)](this);if(!U)return this[s(1527)+s(1800)+s(505)](a),e[s(1273)](n);let V=await U[s(1039)](S)??-1;if(V<D)this[s(1527)+s(1800)+s(505)](a),U.set(S,D,a[s(1460)][s(523)]);else throw new Error(s(1799)+s(740)+s(1865)+D+(" larger than loc"+s(679)+"r ")+V);return e[s(1273)](n)}return this[s(1527)+s(1800)+s(505)](a),n()}}async function $p(a,n){let s=t,d=ua[s(1832)](this,a);if(!d[s(586)+"sage"])return e[s(624)](n);let f=await ol.call(this);if(d[s(1923)+"anupMess"+s(699)]&&d.ackMsgIds[s(510)])for(let p of d[s(1570)+"s"])await f[s(1499)](p);n()}async function Vp(a,n){let s=t,d=e.byQww(a.message[s(1703)+"e"],Up),f=e[s(957)](a[s(1460)][s(1703)+"e"],ha);if(!d&&!f)return e[s(624)](n);let p=e[s(1824)](Qn,a[s(1460)][s(1323)],e[s(1052)]);if(!p)return e[s(1396)](n);let _=await cl.call(this,p);if(!_)return e[s(1075)](n);if(d){let w=await _.getCursors(),g={frameType:w?.[s(1703)+"e"],SeqID:fe[s(1933)+"er"](this[s(1963)]++),LogID:fe.fromNumber(this[s(1185)][s(872)+s(1261)]()),service:9e3,method:5,headers:w?.[s(1323)],payload:w?.payload},S=e[s(1068)](I,g);this[s(603)]&&this._ws[s(1945)+"te"]&&this[s(603)][s(711)](S)}if(f){let w=a[s(1460)][s(1740)];w&&_[s(580)+"rs"](w)}}let Jp=async function(a,n){let s=t;this[s(1711)]=!1,e[s(686)](clearTimeout,this[s(529)+s(1673)+"utId"]),e[s(833)](n)},Yp=async function(a,n){let s=t;if(!this[s(603)]||e[s(1616)](this[s(603)].readyState,this[s(1300)]))return n();let{pingInterval:d}=this[s(1185)];this[s(1717)+s(601)]?.[s(703)+s(1458)+"fig"]();for(let p=0;e[s(1741)](p,this[s(1431)+s(1628)][s(510)]);p++){let _=this["_message"+s(1628)][p];if(e.Bseja(this[s(603)][s(1945)+"te"],this[s(1300)])&&e.WqrgY(null,_)){if(e.DqDmi(e[s(662)],s(762)))return new _0xbd8cfc(_0x174f0a,{data:_0x572273});this[s(603)]&&this[s(603)][s(711)](_),this[s(1431)+s(1628)][p]=null}else break}this[s(1431)+s(1628)]=this[s(1431)+"Queue"][s(1423)](p=>!!p),this[s(578)+"gTimeoutId"]=e.HgGiJ(setTimeout,()=>this[s(1513)](),d),this[s(1527)+s(754)+"nt"](a),this[s(1742)+"er"]&&this[s(603)]&&(this._ws[s(1203)+"pe"]=this["_binaryT"+s(1399)]);let f=this[s(1717)+s(601)]?.[s(1854)+s(545)+"nt"]();this[s(1462)]("open "+f+s(749)),e[s(833)](n)},Zp=async function(a,n){let s=t,d=this[s(1717)+"tManager"]?.[s(1854)+s(545)+"nt"]();this[s(1462)]("open "+d),e[s(1393)](n)};class Xp extends ca{constructor(n){let s=t,d={rZXGL:function(f,p,_,w){return e[K(1007)](f,p,_,w)},GQxki:e[s(803)],aJIqR:function(f,p){return f===p},StQFW:e.hFquf,uhJFT:function(f,p){return e[s(1592)](f,p)},xfMUA:e[s(1422)],czhDs:function(f,p){return e[s(1561)](f,p)},qgRJh:e[s(1672)],pzOIg:e[s(1729)],arOUw:e[s(1876)],YjUrA:function(f,p,_,w){return e.xwgFZ(f,p,_,w)},zbrEt:function(f,p,_){return e[s(582)](f,p,_)},DGInd:function(f,p,_){return e[s(837)](f,p,_)},DSUeG:e[s(1871)],iJOms:function(f,p,_){return e[s(1553)](f,p,_)},ugeJM:e[s(1805)],HCPMW:function(f,p){return e.SArjG(f,p)},XdyvY:function(f,p){return f(p)},iGxDI:function(f,p,_){return f(p,_)}};if(e[s(1016)](e[s(664)],e[s(1502)])){super(),this["_miniNav"+s(984)+s(681)]=!0,this[s(1742)+"er"]=Xn,this._isNode=hp,this[s(1362)+"T"]=Tn,this[s(1013)+"X"]=$r,this._isWorker=Vr,this["_message"+s(1628)]=[],this[s(1717)+s(601)]=null,this[s(1071)+s(668)]=!1,this[s(1601)+s(1399)]=e[s(937)],this[s(529)+s(1766)]=!1,this[s(529)+s(1673)+s(1559)]=null,this["_reconne"+s(589)+"tId"]=null,this[s(578)+s(619)+"Id"]=null,this._seqId=0,this[s(1711)]=!1,this._url="",this[s(1905)+"ger"]=null,this["_cursorM"+s(1491)]=null,this[s(1163)+"sCounter"]=null,this[s(1314)+"ls"]=s(1983),this[s(1456)]=3,this.CONNECTING=0,this.OPEN=1,this[s(1085)]=2,this._onOpen=w=>{let g=s;try{d[g(1076)](tl,this,w,[Jp,Yp,Zp])}catch(S){let D=at(d.GQxki,{message:S[g(1460)],code:en[g(1578)+"OR"],error:S});this[g(1527)+"hErrorEv"+g(1692)](D)}},this[s(1815)+"ge"]=async w=>{let g=s,{pingInterval:S,pingFrequency:D}=this[g(1185)];if((w[g(1783)]==="hi"&&d[g(1972)](d[g(1986)],D)||d[g(790)](d[g(521)],D))&&(d[g(1816)](d[g(1165)],d[g(1235)])?(this[g(755)+"ngTimer"](),this[g(1250)](d[g(467)],g(1908)),this["_pingPon"+g(619)+"Id"]=setTimeout(this._ping[g(1225)](this),S)):_0x2b1079[g(720)][g(1336)+g(1064)](_0x7ac9ab)),w[g(1783)]!=="hi")try{d[g(649)](tl,this,w,[Cp,Tp,$p,Vp,Kp,kp])}catch(N){let U=d[g(1364)](at,d[g(562)],{message:N[g(1460)],code:en["MESSAGE_"+g(1340)],error:N});this[g(1527)+g(498)+g(1692)](U)}},this._onError=w=>{let g=s,S={VbXgZ:function(D,N){return D instanceof N},AZuGb:function(D,N){return e.KgLmo(D,N)},lQpOC:e[g(1338)],hNzxy:e[g(1664)],LSlvb:function(D,N){return e.FdvVM(D,N)},dsjzp:function(D,N){return e[g(569)](D,N)},YoKGl:e.dJlbL,tDaiz:function(D,N){return D(N)},aAfwc:function(D,N,U,V){return D(N,U,V)}};if(e[g(1193)]!==g(536)){let D=this[g(1717)+g(601)]?.[g(1518)+g(924)+"es"](),N=this[g(1717)+"tManager"]?.[g(1854)+g(545)+"nt"]();if(D&&!w[g(1460)])if(e[g(1215)](e[g(1756)],g(696))){let U=g(1938)+N+(g(1755)+g(1385)+g(768)+"ed");this["_dispatc"+g(498)+g(1692)](e[g(965)](at,e[g(803)],{message:U,code:en[g(548)+"IES_ERROR"],error:w}));return}else{if(lRtkKm[g(1377)](_0x371539,_0x2ddb62)){if(lRtkKm[g(524)](_0x3d100e,lRtkKm[g(1305)]))return _0x1aeb74.get(_0x230685);if(lRtkKm.AZuGb(_0x2dbdce,lRtkKm[g(1199)]))return _0x2386e4[g(1537)+g(1663)]||_0xf98cd6[g(1039)](_0x4f114f);if(_0x475a74===g(1788))return _0x39e294[g(1537)+"oreNames"][1]?void 0:_0x2aafa4["objectSt"+g(1840)](_0x112553[g(1537)+g(1663)][0])}return lRtkKm[g(614)](_0x33744c,_0x2383a5[_0x3596cd])}this[g(603)]&&e.xofkz(this[g(603)][g(1945)+"te"],this[g(1300)])&&this["_disconn"+g(697)](),this[g(1527)+g(498)+g(1692)](e[g(639)](at,g(751),{message:w[g(1460)],code:en[g(897)+g(626)],error:w}))}else{if(lRtkKm[g(684)](lRtkKm[g(553)],typeof _0x1b09a1)){let D=new _0x530c93(lRtkKm[g(1878)](_0x53c7f9,_0x2f5b04));return lRtkKm[g(888)](_0x14834b,_0x28cc7,D,0),D}return lRtkKm[g(1377)](_0x369797,_0x1022a5)?new _0x2a6386(_0x81129b):new _0x5fddda(_0x5aabf1[g(1490)],_0x3c5eb2[g(517)+"et"],_0x5da1c9[g(1540)+"th"])}},this[s(607)]=async w=>{let g=s;this[g(898)+g(1970)](),this[g(755)+g(811)](),this[g(992)+g(1543)+"rs"](),this[g(603)]=null,this[g(529)+g(1766)]=!1;let S=this["_endpoin"+g(601)]?.["checkRea"+g(924)+"es"]();if(!S&&this[g(1787)+g(1230)]()&&!this[g(1071)+g(668)]){let D=this[g(1717)+"tManager"]?.["getCurre"+g(545)+"nt"](),N=this[g(1185)][g(788)+g(1307)+g(1168)](w[g(952)],w[g(1922)]);this[g(1527)+g(1625)+g(1692)](d[g(821)](xt,d[g(1149)],{code:1006,reason:w[g(1922)]||g(1835)+g(1691)+g(997)+g(1047)+"n, hostn"+g(861)+D,willReconnect:N})),N&&this._connect();return}if(d.czhDs(1e3,w[g(952)])&&this[g(1071)+g(668)]){this["_dispatc"+g(1625)+g(1692)](d[g(1145)](xt,d[g(1149)],{code:1e3,reason:d.ugeJM})),this[g(1717)+g(601)]?.[g(703)+"pointCon"+g(1375)](),this[g(1163)+g(485)]?.[g(736)+"nter"]();return}if(d[g(1313)](1e3,w[g(952)])&&S){let D=this[g(1717)+"tManager"]?.[g(1854)+g(545)+"nt"](),N=w.reason;N||(N=await d[g(1151)](bp,this._url)),N=g(1835)+g(1691)+g(1126)+N+(", hostna"+g(1597))+D+(", max re"+g(1417)+g(904)),this["_dispatc"+g(1625)+g(1692)](d.zbrEt(xt,d.DSUeG,{code:w[g(952)],reason:N}));let U="connect "+D+(" fail, m"+g(1385)+"es reached");this[g(1527)+"hErrorEv"+g(1692)](at(g(751),{message:U,code:en[g(548)+g(1025)+"R"]})),this["_endpoin"+g(601)]?.[g(703)+"pointConfig"](),this["_pingLos"+g(485)]?.[g(736)+g(1873)]();return}if(w[g(952)]!==1e3&&!w.reason){let D=this[g(1717)+g(601)]?.[g(1854)+g(545)+"nt"]();this[g(1527)+g(1625)+g(1692)](d[g(1472)](xt,d[g(1149)],{code:w[g(952)],reason:g(1835)+g(1691)+g(997)+g(1047)+"n, hostn"+g(861)+D})),this[g(1717)+g(601)]?.[g(703)+"pointCon"+g(1375)](),this[g(1163)+"sCounter"]?.[g(736)+"nter"]();return}this[g(1527)+g(1625)+g(1692)](w),this[g(1717)+g(601)]?.["resetEnd"+g(1458)+g(1375)](),this[g(1163)+g(485)]?.[g(736)+"nter"]()},this[s(1689)]=null,this[s(987)]=null,this[s(1209)+"e"]=null,this[s(1600)]=null,this[s(1861)+s(1093)]=null,this[s(1613)+s(1510)]=null,this[s(1256)+s(1233)+s(1032)+"ct"]=null,this["_handleO"+s(1574)]=this[s(1389)+s(1574)].bind(this),this[s(1389)+s(1646)]=this[s(1389)+s(1646)].bind(this),this[s(1160)+s(1985)]=this[s(1160)+"ageHide"][s(1225)](this),this[s(1160)+s(747)]=this["_handleP"+s(747)][s(1225)](this),this[s(1185)]={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(1178),pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(1410)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:p}=n,_=Array[s(1701)](f)?f:e[s(796)](s(1547),typeof f)?[f]:[];if(!_||e[s(1251)](0,_[s(510)]))throw new Error(e[s(1430)]);if(!e[s(1028)](mp,p))throw new Error(e.sKQUg);Object[s(877)](this[s(1185)],n),this[s(1717)+s(601)]=new el(_,this[s(1185)].maxRetries),this[s(1163)+s(485)]=new yp(this._options.pingLossCount),this[s(1185)][s(1512)+s(1706)]&&(this[s(1711)]=!0,this[s(529)]()),this._options[s(1082)+s(1091)+s(495)]&&(this._isMiniTT||this[s(1013)+"X"]?this[s(1981)+"etWorkCh"+s(1848)]():this[s(1742)+"er"]&&this[s(1567)+s(1738)+s(1405)]())}else this["currentI"+s(1090)]=0,this[s(1325)+s(1580)+s(1680)+"t"]=0}[t(1389)+t(1574)](){let n=t;this[n(1185)]["disableA"+n(899)+n(1546)]||this[n(1071)+n(668)]||this[n(1955)+n(1093)]()}["_handleO"+t(1646)](){let n=t;this[n(1282)+n(1811)+"t"]();let s=e[n(657)](aa,e[n(1866)],{message:n(1073)+n(1725)+" reconnect"});this[n(1256)+n(1233)+n(1032)+"ct"]&&this[n(1256)+n(1233)+n(1032)+"ct"](s)}["_initGlo"+t(1738)+t(1405)](){let n=t;this[n(1742)+"er"]&&window[n(1893)+n(1405)](e[n(1964)],this[n(1389)+"nLine"]),this._isBrowser&&window[n(1893)+n(1405)](e[n(1954)],this["_handleO"+n(1646)]),this[n(1742)+"er"]&&window[n(1893)+"Listener"](e[n(1127)],this[n(1160)+n(1985)]),this[n(1742)+"er"]&&window[n(1893)+n(1405)](e[n(1131)],this[n(1160)+n(747)])}[t(1934)+"balEvent"+t(1405)](){let n=t;this[n(1742)+"er"]&&window["removeEv"+n(1566)+n(1315)](n(765),this[n(1389)+"nLine"]),this[n(1742)+"er"]&&window["removeEv"+n(1566)+"ner"](e[n(1954)],this[n(1389)+n(1646)]),this._isBrowser&&window[n(1189)+n(1566)+n(1315)](n(515),this[n(1160)+n(1985)]),this[n(1742)+"er"]&&window[n(1189)+"entListener"](e[n(1131)],this[n(1160)+n(747)])}["_handleP"+t(1985)](n){let s=t;!n[s(1602)+"d"]&&(this[s(1742)+"er"]&&window[s(1189)+"entListe"+s(1315)](e[s(1127)],this[s(1160)+s(1985)]),this[s(1742)+"er"]&&window["removeEv"+s(1566)+"ner"](e[s(1131)],this[s(1160)+s(747)]),this[s(1150)]()),this[s(1742)+"er"]&&window["removeEv"+s(1566)+s(1315)](s(765),this["_handleO"+s(1574)]),this._isBrowser&&window["removeEv"+s(1566)+s(1315)](e.AcZNo,this["_handleO"+s(1646)])}[t(1160)+t(747)](n){let s=t;n.persisted&&(this[s(1787)+s(1230)]()&&(!this[s(603)]||e[s(1885)](this[s(603)][s(1945)+"te"],this.OPEN)||e[s(1176)](this[s(603)][s(1945)+"te"],this.CONNECTING))&&this[s(1389)+s(1574)](),this._isBrowser&&window["addEvent"+s(1405)](e.wbbRO,this[s(1389)+s(1574)]),this[s(1742)+"er"]&&window[s(1893)+"Listener"](e[s(1954)],this[s(1389)+s(1646)]))}async[t(1478)+"eUrl"](n){let s=t,{fpID:d,deviceID:f,bddID:p,ttwID:_,accessKey:w,aID:g,customParams:S={},enableAutoAck:D,enableQoS:N,QoSLevel:U,env:V}=this[s(1185)],J,je,ge;this[s(1742)+"er"]||this[s(1013)+"X"]||this._isMiniTT?(J=location&&e[s(1632)](e[s(609)],location[s(1620)])?e[s(1748)]:e.cALZG,je=n[s(1447)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),ge=/^wss(.*:\/\/)/[s(716)](n)?n:""+J+je):(J=e[s(1748)],je=n[s(1447)](/(^http)((?:[s]*:\/\/))/,""),ge=/(^ws)((?:[s]*:\/\/))/[s(716)](je)?je:""+J+je);let nn=p?e[s(1875)]:_?e[s(1550)]:"device_id",dl=p||_||f;if(e[s(973)](!dl,!nn))throw new Error(e[s(1716)]);let Qp=e[s(1632)](e[s(581)],typeof S)?await e[s(833)](S):S,eg=V?e.esHKB(_p,V[s(1359)],V.xTTEnv):{},pa=Object[s(877)]({device_platform:e[s(1900)],version_code:e[s(985)],access_key:w,fpid:d,aid:g,[nn]:dl,xsack:D?1:0,xaack:D?1:0,xsqos:N?1:0,qos_level:N?U:void 0,qos_sdk_version:2,...eg},Qp),tg=Object[s(748)](pa)[s(1403)]((ga,ma)=>pa[ma]!==void 0?""+ga+(ga?"&":"?")+ma+"="+pa[ma]:ga,"");return ge+"/ws/v2"+tg}async[t(529)](){let n=t,s={tHwcT:function(d,f){return e[K(994)](d,f)},WmcoQ:e[n(966)],srmNP:e[n(644)],jViJW:e.hKdeu,bIQYu:n(1516),JqUPN:function(d,f,p,_){return d(f,p,_)}};if(!(this[n(529)+n(1766)]||this[n(1071)+"osed"])){this[n(529)+"Lock"]=!0;try{let d=this[n(1717)+n(601)]?.[n(630)+n(1030)+n(1411)+n(1497)+n(1807)](),{timeoutInterval:f}=this._options;if(d){let _=this[n(1717)+n(601)]?.[n(1854)+"ntEndpoint"](),w=this[n(1717)+n(601)]?.["replaceB"+n(772)+n(1886)+"UpdateCo"+n(1231)](),g=this[n(1717)+n(601)]?.[n(1854)+n(545)+n(691)+n(1116)]();if(w){let S=n(1938)+_+(n(1877)+n(713)+"tries re"+n(1297)+n(509)+n(1501)+"ndpoint ")+w+(n(865)+"y"),D=e.CjiPN(at,n(751),{message:S,code:en[n(548)+n(1025)+"R"]});this._debug(S),this[n(1527)+n(498)+n(1692)](D),this[n(1333)]=await this._generateUrl(w),this._debug(n(1938)+w+" "+g+n(1049)),this["_removeW"+n(1543)+"rs"]()}else{let S="connect "+_+(n(1877)+n(713)+n(1417)+n(904));this[n(1462)](S),this["_dispatc"+n(498)+n(1692)](e[n(1841)](at,e[n(803)],{message:S,code:en[n(548)+n(1025)+"R"]}));return}}else if(e[n(540)](n(1688),e[n(879)])){let _=this[n(1717)+n(601)]?.[n(1854)+n(545)+n(1532)+n(600)](),w=this["_endpoin"+n(601)]?.[n(1854)+n(545)+n(691)+n(1116)]();this[n(1333)]=await this["_generat"+n(1192)](_||""),this[n(1462)](n(1938)+_+" "+w+n(1049)),this["_removeW"+n(1543)+"rs"]()}else{let _=this._options[n(710)+n(967)]instanceof _0x69a1c0?{force:!!this._options[n(710)+n(967)][n(910)],encoding:this[n(1185)]["payloadE"+n(967)][n(1169)]?this[n(1185)]["payloadE"+n(967)][n(1169)].replace(/\s/g,"")[n(1745)+n(1015)]():""}:{force:!1,encoding:this[n(1185)]["payloadE"+n(967)]?this[n(1185)][n(710)+n(967)][n(1447)](/\s/g,"")[n(1745)+n(1015)]():""},w=_0x16bc45[n(710)+n(967)]?_0x31988d[n(710)+n(967)][n(1447)](/\s/g,"")["toLowerC"+n(1015)]():"",g=WBitfE.tHwcT(this[n(1185)][n(939)+n(1399)],_0x577dda)?{force:!!this[n(1185)][n(939)+n(1399)][n(910)],type:this[n(1185)][n(939)+n(1399)][n(1086)]?this[n(1185)]["payloadT"+n(1399)][n(1086)][n(1447)](/\s/g,"")[n(1745)+n(1015)]():""}:{force:!1,type:this[n(1185)][n(939)+n(1399)]?this[n(1185)][n(939)+n(1399)][n(1447)](/\s/g,"")[n(1745)+"ase"]():""},S=_0x2b2aa1["payloadT"+n(1399)]?_0x223193[n(939)+n(1399)][n(1447)](/\s/g,"")[n(1745)+n(1015)]():"",D=g.force?g[n(1086)]:S||g[n(1086)],N=_[n(910)]?_[n(1169)]:w||_[n(1169)],U=[WBitfE.WmcoQ,n(986)+n(1401),WBitfE[n(1862)],"string"],V=[WBitfE.jViJW,WBitfE[n(1551)]];this[n(1185)][n(537)+"ansformT"+n(951)+"ad"]&&U[n(463)](D)&&(!N||V[n(463)](N))?_0x2a14db["textPayl"+n(1006)]=WBitfE[n(1495)](_0x8a3398,_0x13eb2f.payload,0,_0x299166[n(1740)][n(1540)+"th"]):_0x375f27[n(663)+n(1006)]=""}if(this._isInit)this[n(1711)]=!1;else{let _=aa(e[n(1866)],{message:e[n(1457)]});this[n(1861)+n(1093)]&&this.onStartReconnect(_)}let p=this[n(1717)+n(601)]?.[n(1854)+n(545)+n(691)+n(1116)]()||0;e[n(1036)](p,1)&&await this[n(802)](p-1),this._debug(n(1835)+n(497)+this._url+(n(1206)+n(1966))+this[n(1314)+"ls"]),this[n(603)]=e[n(1287)](gp,{url:this[n(1333)],protocols:[this[n(1314)+"ls"]],headers:this[n(1185)][n(1105)+n(1201)+"s"][n(950)+"tpHeader"]},this[n(1185)].ws),(this[n(1742)+"er"]||this._isWorker)&&this[n(603)]&&(this._ws.binaryType=this[n(1601)+n(1399)]),this[n(1312)+"steners"](),this["_connect"+n(1673)+n(1559)]=setTimeout(this[n(556)+"ut"].bind(this),f)}catch(d){throw this[n(529)+n(1766)]=!1,d}}}[t(898)+t(1970)](){let n=t;clearTimeout(this[n(529)+n(1673)+n(1559)]),this[n(529)+"ionTimeo"+n(1559)]=null}[t(755)+"ngTimer"](){let n=t;e[n(1386)](clearTimeout,this[n(578)+n(619)+"Id"]),clearTimeout(this[n(734)+n(589)+n(1860)]),this[n(578)+n(619)+"Id"]=null,this["_reconnectTimeou"+n(1860)]=null}_debug(...n){let s=t;this[s(1185)][s(742)]&&console[s(963)][s(1459)](console,[e.Lkgcn,...n])}[t(462)+t(1901)+"e"](n){let s=t,d={otKIF:e.vslcB};if(e[s(1750)]!==e[s(1228)]){let{initReconnectInterval:f,maxReconnectInterval:p,reconnectIntervalGrowFactor:_}=this[s(1185)],w=e[s(1728)](f,Math[s(1455)](_,n-1));return e[s(513)](w,p)?p:w}else this.emit(s(751),_0x11abec(reHcKs.otKIF,{message:this[s(1868)+s(1299)+"age"](_0x4b2ced)}))}[t(1513)](){let n=t;if(this[n(603)]&&e[n(1536)](this[n(603)][n(1945)+"te"],this[n(1857)+"NG"])){this[n(755)+"ngTimer"](),this[n(578)+n(619)+"Id"]=e[n(1589)](setTimeout,this[n(1513)][n(1225)](this),this[n(1185)][n(1053)+n(1572)]);return}if(!this._ws||e.XAaWA(this._ws[n(1945)+"te"],this[n(1300)]))return void this[n(1955)+n(1093)]();this[n(603)]&&this[n(603)][n(711)]("hi"),this[n(734)+"ctTimeoutId"]=e[n(667)](setTimeout,this[n(1955)+n(1093)+n(671)][n(1225)](this),this[n(1185)][n(1166)+n(1483)+n(1487)])}["_handleReconnect"+t(671)](){let n=t;this[n(1163)+n(485)]?.[n(871)](),this[n(1250)](n(1234)+n(689)+"t",e[n(1281)]),this[n(1163)+n(485)]?.[n(1518)+"chMaxCount"]()?this[n(1955)+"econnect"]():this[n(1513)]()}[t(1787)+t(1230)](){let n=t;return this._isMiniTT||this[n(1013)+"X"]?this[n(606)+n(984)+n(681)]:(this[n(1742)+"er"]||this[n(1845)+"r"])&&this[n(1185)]["listenNe"+n(1091)+"nged"]?navigator[n(776)]:!0}[t(1955)+t(1093)](){let n=t;!this[n(1787)+n(1230)]()||this._readyClosed||(this[n(1717)+"tManager"]?.[n(703)+n(1458)+n(1375)](),this[n(1163)+"sCounter"]?.[n(736)+n(1873)](),this[n(603)]?this[n(1197)+n(697)](1001,e[n(1798)],!0):this[n(529)]())}["_onPageN"+t(1967)+t(1848)](){let n=t,s={pfIcl:e[n(1576)]};if(e.CChRK(e[n(1808)],n(1264)))return e[n(470)](_0x1d5294,_0x50d7bb)?_0x1eb2bb[n(1890)](new _0x1f6fa3(e[n(1593)])):(_0x2e43dc=_0x2e01db,e[n(820)](_0x3b6a4a,_0x19336c[n(510)])?_0x56fbc8[n(1179)]():_0x10fa11[_0x3b5d21][n(1225)](_0x2eaae4)(_0x2e1fcc,_0x47d57.bind(null,e[n(516)](_0x25016d,1))));this[n(1362)+"T"]?tt[n(1130)+"kStatusC"+n(1124)](({isConnected:d})=>{let f=n;this[f(606)+"igatorOn"+f(681)]=d,d?this["_handleO"+f(1574)]():this[f(1389)+f(1646)]()}):this[n(1013)+"X"]&&wx[n(1130)+n(834)+n(1124)](({isConnected:d})=>{let f=n,p={udjuO:function(_,w){return _*w}};if(s.pfIcl!==f(1971)){let _=new _0x503237(BrErMD.udjuO(2,_0x595f7a));_[f(1378)](_0x25d681),_0x213984[f(1334)]=_}else this["_miniNav"+f(984)+f(681)]=d,d?this["_handleO"+f(1574)]():this[f(1389)+f(1646)]()})}[t(802)](n){return new Promise(s=>{let d=K;e[d(1698)](setTimeout,s,this[d(462)+d(1901)+"e"](n))})}[t(1197)+"ect"](n=1e3,s="",d=!1){let f=t;this[f(603)]&&this[f(1282)+f(1811)+"t"](n,s,d)}[t(556)+"ut"](){let n=t,s=this["_endpoin"+n(601)]?.["getCurre"+n(545)+"nt"]();this[n(1462)](n(1938)+s+n(1877)),this["_disconn"+n(697)](1001,e.RnsaP,!0)}[t(1920)](n){let s=t,d=Bt(n);if(this[s(603)]&&e.HeHrx(this[s(603)].readyState,this.OPEN))if(e[s(1939)]!==s(918))this[s(603)]&&this[s(603)][s(711)](d),this[s(1462)](e[s(1552)],n);else{let f=this["_endpoin"+s(601)]?.[s(1854)+s(545)+"nt"]();this[s(1527)+s(1625)+"ent"](e[s(1509)](_0x4cd706,e[s(1871)],{code:1006,reason:s(1938)+f+(s(1877)+s(713)+"tries re"+s(904)),wasClean:!0}))}}[t(992)+t(1543)+"rs"](){let n=t,s=e[n(795)][n(903)]("|"),d=0;for(;;){switch(s[d++]){case"0":if(!this[n(603)])return;continue;case"1":this[n(603)][n(1189)+n(1566)+n(1315)](e[n(1184)],this[n(1899)]);continue;case"2":this[n(603)][n(1189)+n(1566)+n(1315)](e.KxBlh,this[n(607)]);continue;case"3":this[n(603)][n(1189)+"entListe"+n(1315)](e.HjYYT,this._onMessage);continue;case"4":this[n(603)][n(1189)+n(1566)+"ner"](e[n(803)],this[n(841)]);continue}break}}[t(1312)+"steners"](){let n=t,s=e[n(1380)].split("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(603)][n(1893)+n(1405)](n(1460),this[n(1815)+"ge"]);continue;case"1":if(!this._ws)return;continue;case"2":this._ws[n(1893)+n(1405)](e[n(1871)],this[n(607)]);continue;case"3":this._ws["addEvent"+n(1405)](n(751),this[n(841)]);continue;case"4":this[n(603)][n(1893)+n(1405)](n(1641),this._onOpen);continue}break}}[t(1050)+t(1449)](n=1e3,s=""){let d=t;try{this[d(603)]&&this[d(603)][d(1150)](n,s)}catch{}}[t(1282)+"WebSocket"](n=1e3,s="",d=!1){let f=t;if(this[f(755)+f(811)](),this[f(898)+"mer"](),this[f(992)+"sListeners"](),this[f(1050)+f(1449)](1e3,s),this[f(529)+f(1766)]=!1,d&&this[f(1787)+f(1230)]()&&!this[f(1071)+f(668)]){if(this[f(1717)+f(601)]?.[f(1518)+f(924)+"es"]())if(e.HeHrx(e[f(1948)],"hzfyn"))this[f(606)+"igatorOn"+f(681)]=_0x4565fc,_0x171edb?this[f(1389)+f(1574)]():this[f(1389)+"ffLine"]();else{let _=this[f(1717)+f(601)]?.[f(1854)+f(545)+"nt"]();this[f(1527)+"hCloseEv"+f(1692)](e[f(519)](xt,e[f(1871)],{code:1006,reason:"connect "+_+(f(1877)+f(713)+f(1417)+f(904)),wasClean:!0}))}else{let _=this[f(1185)][f(788)+"tInterce"+f(1168)](n,s);this[f(1527)+f(1625)+"ent"](e.XDbpb(xt,e.KxBlh,{code:n,reason:s,wasClean:!0,willReconnect:_})),_&&this[f(529)]()}return}this._navigatorOnline()||this[f(1071)+f(668)]?this["_dispatchCloseEv"+f(1692)](e[f(1270)](xt,e.KxBlh,{code:n,reason:f(1844)})):this[f(1527)+f(1625)+"ent"](e[f(1335)](xt,e[f(1871)],{code:1006,reason:e[f(1183)]})),this[f(603)]=null,this[f(1717)+f(601)]?.[f(703)+f(1458)+f(1375)](),this["_pingLos"+f(485)]?.[f(736)+f(1873)]()}["_dispatc"+t(754)+"nt"](n){let s=t;this[s(1250)](e[s(1184)],n),this.onopen&&this[s(1600)](n)}[t(1527)+"hMessage"+t(505)](n){let s=t;this[s(1250)]("message",n),this[s(1209)+"e"]&&this[s(1209)+"e"](n)}[t(1527)+t(499)+t(737)](n){let s=t;this[s(1250)](e[s(1653)],n),this[s(1613)+"eAck"]&&this[s(1613)+s(1510)](n)}[t(1527)+t(498)+t(1692)](n){let s=t;this.emit(e.vslcB,n),this[s(987)]&&this[s(987)](n)}["_dispatc"+t(1625)+t(1692)](n){let s=t,d={dcpus:function(f,p){return e[K(1666)](f,p)},WiBCR:function(f,p,_){return e[K(1577)](f,p,_)},AbBry:function(f,p){return e[K(827)](f,p)}};if(e.CXcUj!==s(1915)){for(_0x31e2b6>>>=0;GdhwCQ.dcpus(_0x4eb184,128);)GdhwCQ[s(1947)](_0x306d31,_0x2ac9a2,GdhwCQ.AbBry(127&_0x37c328,128)),_0x5bcba5>>>=7;_0x5e5c8f(_0x1b51d4,_0x4116bd)}else this[s(1250)](e[s(1871)],n),this[s(1689)]&&this[s(1689)](n)}get[t(1203)+"pe"](){let n=t;return this[n(603)]?this[n(603)][n(1203)+"pe"]:this[n(1601)+n(1399)]}set[t(1203)+"pe"](n){let s=t;this[s(1601)+s(1399)]=n,this[s(603)]&&(this._ws[s(1203)+"pe"]=n)}get[t(476)+"nt"](){let n=t;return this["_endpoin"+n(601)]?.[n(1854)+n(545)+n(691)+n(1116)]()||0}get[t(1382)+t(1409)](){let n=t;if(e[n(1240)](e[n(1658)],e[n(1658)])){let s=this[n(1431)+n(1628)][n(1403)]((d,f)=>(d+=f&&f[n(1540)+"th"]||0,d),0);return e[n(1564)](s,this[n(603)]?this[n(603)][n(1382)+n(1409)]:0)}else{let s=this._qosDB["getStora"+n(1902)](this[n(1781)]),d=_0x3c4d4e[n(1726)](e[n(1355)](s,"{}"));return d[_0x301e58]=void 0,this[n(1369)][n(1774)+n(1902)](this[n(1781)],_0x243c96[n(835)+"y"](d))}}get[t(1852)+"ns"](){let n=t;if(n(1229)===e[n(1027)])return this[n(603)]?this._ws[n(1852)+"ns"]:"";{let s={guCkn:e[n(1281)],xuWeQ:e[n(1876)],vCykG:e[n(661)],RkKUH:function(d,f){return e[n(969)](d,f)},BEGOG:e[n(1186)],KwTnw:function(d,f,p){return d(f,p)}};return new _0x338f4f((d,f)=>{let p=n,_={aUSjg:function(S,D){return s.RkKUH(S,D)},AbaNu:s[p(1786)],usKXm:s[p(503)]};this[p(755)+p(811)](),this[p(578)+"gTimeoutId"]=s[p(1467)](_0x23f19a,this[p(1513)][p(1225)](this),this[p(1185)][p(1053)+p(1572)]);let w=()=>{let S=p;_[S(999)](d,_[S(538)]),this.off(S(1234)+S(564)+"s",w),this[S(1802)](_[S(1223)],g)},g=()=>{let S=p;f(s[S(1795)]),this[S(1802)](s.xuWeQ,w),this[S(1802)](s[S(503)],g)};this.on(s.xuWeQ,w),this.on(s[p(503)],g),this[p(1513)]()})}}get[t(1620)](){let n=t,s={KuoqR:e.musAu,lzzer:e.OAxZY,yXFdG:function(d){return e[K(694)](d)},grCBN:e.tUldS,yuCye:n(751)};if(e[n(1679)](e[n(783)],e[n(1598)])){let d={WDvrm:hbbVhi[n(1420)],giLvl:hbbVhi[n(893)],sMybJ:function(w){let g=n;return hbbVhi[g(1202)](w)},BOktR:function(w,g){return w(g)},wJttW:hbbVhi[n(1743)],Txfag:function(w){let g=n;return hbbVhi[g(1202)](w)}},f=()=>{let w=n;_0x4bba35[w(1189)+w(1566)+w(1315)](d[w(928)],p),_0x5709da[w(1189)+w(1566)+w(1315)](w(751),_),_0x31f12e["removeEv"+w(1566)+w(1315)](d[w(1739)],_)},p=()=>{let w=n;d.sMybJ(_0x25ca79),d[w(1810)](f)},_=()=>{let w=n;d[w(1248)](_0x3c3863,_0x12e56a.error||new _0x2862d8(d[w(631)],d[w(631)])),d[w(1762)](f)};_0x19de55["addEvent"+n(1405)](hbbVhi[n(1420)],p),_0x42bf76[n(1893)+n(1405)](hbbVhi[n(1608)],_),_0x30a8d4[n(1893)+n(1405)](hbbVhi[n(893)],_)}else return this[n(603)]?this[n(603)][n(1620)]:""}get[t(1945)+"te"](){let n=t,s={jTbRX:"timeout,"+n(611)+n(1279)+"g"};if(e[n(840)](e[n(1830)],e[n(1830)]))return this[n(603)]?this[n(603)][n(1945)+"te"]:this[n(1185)]["automati"+n(1706)]?this[n(1857)+"NG"]:this[n(1456)];{let d=this[n(1717)+"tManager"]?.[n(1854)+n(545)+"nt"]();this[n(1462)]("connect "+d+n(1877)),this[n(1197)+n(697)](1001,ycSLzL[n(989)],!0)}}get[t(1793)](){let n=t;return this[n(603)]?this[n(603)][n(1793)]:this[n(1333)]}[t(1150)](n=1e3,s){let d=t,f=e[d(1957)][d(903)]("|"),p=0;for(;;){switch(f[p++]){case"0":this[d(1282)+d(1811)+"t"](n,s);continue;case"1":this[d(755)+d(811)]();continue;case"2":this[d(1905)+d(1627)]?.closeDB();continue;case"3":if(e[d(1635)](this[d(603)].readyState,this[d(1456)])||e[d(840)](this[d(603)][d(1945)+"te"],this[d(1085)]))return void this[d(1462)](e[d(1768)]);continue;case"4":this[d(1071)+d(668)]=!0;continue;case"5":this[d(898)+d(1970)]();continue;case"6":if(!this[d(603)])return void this[d(1462)](d(909)+d(1226)+"ce not initialized");continue;case"7":this["_dropGlo"+d(1738)+d(1405)]();continue}break}}async[t(711)](n,s){let d=t;if(e[d(1632)](null,n))throw new Error(e.GkeVV);e[d(591)](e[d(1727)],typeof n)&&(n=JSON.stringify(n)),d(1547)!=typeof n&&!e[d(1867)](n,ArrayBuffer)&&!(n.buffer&&e[d(1867)](n[d(1490)],ArrayBuffer))&&(n=JSON[d(835)+"y"](n));let f=await il(n),p=wp(n),{method:_=0,service:w=this[d(1185)].service,logID:g=this[d(1185)].logIDGenerator(),headers:S=this[d(1185)][d(1323)],payloadEncoding:D=this[d(1185)][d(710)+"ncoding"],payloadType:N=this._options["payloadT"+d(1399)],logIDNew:U=this[d(1185)][d(949)+d(843)][d(494)+d(753)+d(1435)+"ew"]?e[d(1386)](i,this[d(1185)][d(949)+d(843)].userIp):""}=e[d(1796)](s,{});if(!w)throw new Error(e[d(1175)]);let V={SeqID:fe[d(1933)+"er"](this[d(1963)]++),LogID:fe[d(1933)+"er"](g),service:w,method:_,headers:S,payloadEncoding:D instanceof Object?D[d(1169)]?D[d(1169)]:"":D,payloadType:e[d(1074)](N,Object)?N[d(1086)]?N[d(1086)]:p:N||p,payload:f,LogIDNew:U},J=e.sumWH(Bt,V);return this._ws&&e[d(1122)](this[d(603)][d(1945)+"te"],this.OPEN)?(this._ws&&this[d(603)][d(711)](J),this._debug(e[d(1548)],V)):e.QEmxw(this[d(1431)+"Queue"].length,this._options[d(585)+d(1366)+d(1520)])?(this[d(1431)+d(1628)][d(1880)](J),this[d(1462)](e[d(1265)],V)):(this[d(1431)+d(1628)][d(1433)](),this[d(1431)+d(1628)][d(1880)](J)),{seqID:this[d(1963)],logID:g,logIDNew:U}}async[t(788)+"t"](n){let s=t,{url:d}=e[s(1579)](n,{}),f=Array[s(1701)](d)?d:e[s(1937)](e[s(978)],typeof d)?[d]:[];n&&Object[s(877)](this._options,n),f&&f[s(510)]?this[s(1717)+s(601)]=new el(f,this[s(1185)][s(1699)+"es"]):this[s(1717)+"tManager"]?.[s(703)+s(1458)+s(1375)](),this["_pingLos"+s(485)]?.[s(736)+s(1873)](this[s(1185)][s(814)+"Count"]),this[s(1071)+"osed"]=!1,this._ws&&e[s(760)](this[s(603)].readyState,this[s(1456)])?this[s(1197)+s(697)](1e3,e[s(648)],!0):(this[s(1711)]=!0,this._connect())}async[t(1277)](){let n=t;if(!this[n(529)+n(1766)]){let s=e[n(1544)][n(903)]("|"),d=0;for(;;){switch(s[d++]){case"0":this[n(1717)+n(601)]?.[n(703)+"pointCon"+n(1375)]();continue;case"1":this[n(1711)]=!0;continue;case"2":this[n(529)]();continue;case"3":this[n(1163)+n(485)]?.[n(736)+"nter"]();continue;case"4":this[n(1071)+n(668)]=!1;continue}break}}}[t(1893)+t(1405)](n,s){this.on(n,s)}dispatchEvent(n){let s=t,{type:d}=n;this[s(1250)](d,n)}[t(1189)+t(1566)+"ner"](n,s){let d=t;if(e[d(840)](d(647),"OPmJA"))this.off(n,s);else{if(this[d(603)]&&this[d(603)].readyState===this[d(1857)+"NG"]){this[d(755)+d(811)](),this[d(578)+d(619)+"Id"]=_0x571f55(this._ping[d(1225)](this),this[d(1185)][d(1053)+"rval"]);return}if(!this[d(603)]||this._ws[d(1945)+"te"]!==this.OPEN)return void this[d(1955)+d(1093)]();this[d(603)]&&this[d(603)][d(711)]("hi"),this[d(734)+d(589)+"tId"]=e.LCxIX(_0x3d2a6c,this[d(1955)+d(1093)+d(671)][d(1225)](this),this[d(1185)][d(1166)+d(1483)+d(1487)])}}[t(1790)](){let n=t,s={VsuVn:function(d,f){return e.QTowl(d,f)},ExHdh:n(1908),JhGEu:e[n(1876)],PsDJo:e[n(661)]};if(e[n(522)](e[n(1096)],e.tXylL))return new Promise((d,f)=>{let p=n,_={tsEBr:function(S,D){return S(D)},CRLXt:e[p(1281)],tbbNx:e[p(1876)],BArIa:e[p(661)]};this[p(755)+p(811)](),this[p(578)+p(619)+"Id"]=e[p(929)](setTimeout,this[p(1513)][p(1225)](this),this[p(1185)]["pingInte"+p(1572)]);let w=()=>{let S=p;s[S(1154)](d,s.ExHdh),this.off(s[S(1002)],w),this[S(1802)](s[S(1958)],g)},g=()=>{let S=p;_[S(931)](f,_[S(1067)]),this[S(1802)](_[S(956)],w),this[S(1802)](_[S(1162)],g)};this.on(e.DBREP,w),this.on(e[p(661)],g),this[p(1513)]()});{let d=_0x594f9f[n(1832)](gwCvCj[n(1674)](_0x4d0b93,this),_0x3ec39a,..._0x474491);return _0x30debb[n(1378)](d,_0xe52af2.sort?_0x2aa9ac[n(1128)]():[_0xf83ada]),gwCvCj.FdvVM(_0x423cf7,d)}}}})(),Ne[M(1415)+"oseEvent"]=Ce["CustomCl"+M(1975)],Ne[M(1104)+M(493)]=Ce[M(1104)+M(493)],Ne[M(715)+"e"]=Ce[M(715)+"e"],Ne[M(505)]=Ce.Event,Ne[M(1210)]=Ce[M(1210)],Ne["FrontierMessageE"+M(895)]=Ce[M(1437)+M(1402)+M(895)],Ne.MessageEvent=Ce[M(1402)+M(895)],Ne.OpenEvent=Ce[M(504)+"t"],Ne[M(1549)+M(1759)]=Ce[M(1549)+M(1759)],Ne["createCl"+M(1975)]=Ce[M(1288)+M(1975)],Ne[M(1927)+"rorEvent"]=Ce[M(1927)+M(493)],Ne["createMe"+M(1909)+"nt"]=Ce[M(1615)+M(1909)+"nt"],Ne[M(629)+M(1034)]=Ce["createOp"+M(1034)],Ne[M(758)+M(852)+"vent"]=Ce[M(758)+"connectE"+M(895)],Ne[M(995)+M(1236)]=Ce["decodedF"+M(1236)],Ne[M(535)+"ame"]=Ce["encodeFr"+M(1370)];for(Bo in Ce)[M(1415)+"oseEvent","CustomEr"+M(493),M(715)+"e",M(505),M(1210),"Frontier"+M(1402)+M(895),M(1402)+M(895),M(504)+"t",M(1549)+M(1759),"createCl"+M(1975),M(1927)+M(493),M(1615)+M(1909)+"nt",M(629)+"enEvent",M(758)+M(852)+M(895),M(995)+M(1236),M(535)+M(1370)].indexOf(Bo)===-1&&(Ne[Bo]=Ce[Bo]);var Bo;Object[M(653)+M(1354)](Ne,M(1014)+"le",{value:!0})});import{existsSync as aS,openSync as cS}from"node:fs";import{mkdir as dS}from"node:fs/promises";import{dirname as lS}from"node:path";import{fileURLToPath as uS}from"node:url";function xS(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Pd(t=Q()){return aS(t.libEntry)?t.libEntry:uS(new URL("../index.ts",import.meta.url))}async function Ch(t={}){let e=t.paths??Q(),r=t.entryOverride??Pd(e),i=xS(e,process.env.COZE_BRIDGE_LOG_MODE);await dS(lS(i),{recursive:!0});let o=cS(i,"a"),l=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=nt(process.execPath,l,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[Qi]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return fS.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var fS,Qi,Vo=Ze(()=>{"use strict";Wt();ne();Pe();fS=G("spawn-daemon"),Qi="COZE_BRIDGE_DAEMON"});import{spawn as o2}from"node:child_process";import{mkdir as a2,unlink as c2,writeFile as d2}from"node:fs/promises";import{dirname as l2,join as u2}from"node:path";function qr(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function f2(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${qr(r)}</key>
|
|
21
|
+
<string>${qr(i)}</string>`).join(`
|
|
22
22
|
`);return e?`
|
|
23
23
|
<key>EnvironmentVariables</key>
|
|
24
24
|
<dict>
|
|
25
25
|
${e}
|
|
26
|
-
</dict>`:""}function
|
|
26
|
+
</dict>`:""}function x2(t,e){return new Promise((r,i)=>{let o=o2(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 jr,ts,ta,Gd,Jh=Ze(()=>{"use strict";ne();jr=G("supervisor.launchd"),ts="ai.coze.bridge",ta=x2,Gd={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>${
|
|
31
|
+
<string>${ts}</string>
|
|
32
32
|
<key>ProgramArguments</key>
|
|
33
33
|
<array>
|
|
34
|
-
<string>${
|
|
35
|
-
<string>${
|
|
34
|
+
<string>${qr(t.nodeBin)}</string>
|
|
35
|
+
<string>${qr(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>${
|
|
45
|
+
<string>${qr(t.logFile)}</string>
|
|
46
46
|
<key>StandardErrorPath</key>
|
|
47
|
-
<string>${
|
|
47
|
+
<string>${qr(t.logFile)}</string>${f2(t.env)}
|
|
48
48
|
</dict>
|
|
49
49
|
</plist>
|
|
50
|
-
`},configPath(t){return
|
|
51
|
-
`):""}function
|
|
50
|
+
`},configPath(t){return u2(t.homeDir,"Library","LaunchAgents",`${ts}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await a2(l2(i),{recursive:!0}),await d2(i,this.renderConfig(t),"utf8"),jr.info("plist written",{plistPath:i,activate:r}),!r)return;await ta("launchctl",["unload","-w",i]).catch(c=>jr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await ta("launchctl",["load","-w",i]),jr.info("launchd job loaded",{label:ts});let o=process.getuid?.()??0;await ta("launchctl",["kickstart","-k",`gui/${o}/${ts}`]),jr.info("launchd job kickstarted",{label:ts,uid:o})},async uninstall(t){let e=this.configPath(t);await ta("launchctl",["unload","-w",e]).catch(r=>jr.warn("launchctl unload failed (ignored)",{err:String(r)})),await c2(e).catch(r=>{if(r.code!=="ENOENT")throw r}),jr.info("launchd job removed",{plistPath:e})}}});import{spawn as h2}from"node:child_process";import{mkdir as p2,unlink as g2,writeFile as m2}from"node:fs/promises";import{dirname as w2,join as Yh}from"node:path";function ra(t,e){return t.isRoot?e:["--user",...e]}function y2(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
|
|
51
|
+
`):""}function ia(t,e){return new Promise((r,i)=>{let o=h2(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 na,Wr,_2,Hd,Zh=Ze(()=>{"use strict";ne();na=G("supervisor.systemd"),Wr="coze-bridge.service",_2="/etc/systemd/system";Hd={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
|
-
${
|
|
62
|
+
${y2(t.env)}
|
|
63
63
|
[Install]
|
|
64
64
|
WantedBy=${e}
|
|
65
|
-
`},configPath(t){return t.isRoot?Yh(
|
|
65
|
+
`},configPath(t){return t.isRoot?Yh(_2,Wr):Yh(t.homeDir,".config","systemd","user",Wr)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await p2(w2(i),{recursive:!0}),await m2(i,this.renderConfig(t),"utf8"),na.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await ia("systemctl",ra(t,["daemon-reload"])),await ia("systemctl",ra(t,r?["enable","--now",Wr]:["enable",Wr])),na.info("systemd unit enabled",{unitName:Wr,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await ia("systemctl",ra(t,["disable","--now",Wr])).catch(r=>na.warn("systemctl disable failed (ignored)",{err:String(r)})),await g2(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await ia("systemctl",ra(t,["daemon-reload"])).catch(()=>{}),na.info("systemd unit removed",{unitPath:e})}}});import{spawn as b2}from"node:child_process";import{join as E2}from"node:path";function Xh(t,e){return new Promise((r,i)=>{let o=b2(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 jd,sa,qd,Qh=Ze(()=>{"use strict";ne();jd=G("supervisor.taskscheduler"),sa="CozeBridge",qd={platform:"win32",renderConfig(t){return`<?xml version="1.0" encoding="UTF-16"?>
|
|
66
66
|
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
|
|
67
67
|
<RegistrationInfo>
|
|
68
68
|
<Description>Coze Bridge daemon</Description>
|
|
@@ -86,48 +86,48 @@ WantedBy=${e}
|
|
|
86
86
|
</Exec>
|
|
87
87
|
</Actions>
|
|
88
88
|
</Task>
|
|
89
|
-
`},configPath(t){return b1(t.homeDir,".coze","bridge","task.xml")},async install(t){let r=`cmd.exe /c ${[`^"${t.nodeBin}^"`,`^"${t.entry}^"`,"--daemon",`>> ^"${t.logFile}^" 2>&1`].join(" ")}`;await Qh("schtasks",["/Create","/SC","ONLOGON","/TN",oa,"/TR",r,"/RU",t.userName,"/F"]),Wd.info("task scheduler entry created",{task:oa,logFile:t.logFile})},async uninstall(t){await Qh("schtasks",["/Delete","/TN",oa,"/F"]).catch(e=>Wd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),Wd.info("task scheduler entry removed",{task:oa})}}});var tp={};Ea(tp,{buildContext:()=>C1,getSupervisor:()=>A1,launchdSupervisor:()=>Hd,systemdSupervisor:()=>jd,taskSchedulerSupervisor:()=>Kd});import{homedir as v1,userInfo as S1}from"node:os";function A1(t=process.platform){switch(t){case"darwin":return Hd;case"linux":return jd;case"win32":return Kd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function T1(){let t={};for(let e of I1){let r=process.env[e];r&&(t[e]=r)}return t}function C1(){let t=X();return{nodeBin:process.execPath,entry:Ld(t),logFile:t.logFile,homeDir:v1(),userName:S1().username,isRoot:process.getuid?.()===0,env:T1()}}var I1,np=Ze(()=>{"use strict";Oe();Jo();Zh();Xh();ep();I1=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});te();nn();var bl=q("acp-installer-warmup"),Cg=["claude-code","codex"];async function vl(t={}){let e=t.ensure??nr,i=(await Promise.allSettled(Cg.map(async o=>{let c=await e(o);bl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&bl.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}rn();te();import{readdir as Gg}from"node:fs/promises";import{mkdir as Rl,readFile as zg,writeFile as kl}from"node:fs/promises";import{join as Ca}from"node:path";var Ug={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function sr(t,e,r){await Rl(t,{recursive:!0});let i=Ug[e],o=Ca(t,i);return await kl(o,r??"","utf8"),o}async function Ra(t,e,r){let i=Ca(t,".claude");await Rl(i,{recursive:!0});let o=Ca(i,"settings.local.json"),c={};try{let u=await zg(o,"utf8"),f=JSON.parse(u);typeof f=="object"&&f!==null&&!Array.isArray(f)&&(c=f)}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 kl(o,JSON.stringify(c,null,2),"utf8"),o}var $e=q("agent-detail-sync"),qg=6e4,Hg=5*6e4,xs=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await Gg(r)}catch(o){$e.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}$e.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Me(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){$e.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(l){$e.warn("detail sync failed for agent, skipping",{agentId:o,err:String(l)})}}})),$e.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),r=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&r.push(i);if(r.length!==0){$e.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){$e.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Me(e,this.opts.paths);if(!i){$e.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(f){$e.warn("detail RPC failed, using local data",{agentId:e,err:String(f)});let p=this.retryQueue.get(e),m=p?Math.min(p.currentDelay*2,Hg):qg;this.retryQueue.set(e,{dueAt:Date.now()+m,currentDelay:m});return}if(o.agentId&&o.agentId!==e){$e.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,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"?($e.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&$e.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){$e.debug("detail sync: no diff",{agentId:e});return}await Xe(i,this.opts.paths),$e.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}),$e.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):l&&(await sr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var Yf=Ft(du(),1);import{lstat as Hc,mkdir as jc,readFile as $f,readdir as v_,rm as S_,stat as A_,writeFile as Wc}from"node:fs/promises";import{dirname as I_,join as Dt,normalize as T_,relative as Vc,resolve as Kc,sep as Vf}from"node:path";import{Readable as Jf}from"node:stream";import{pipeline as Zf}from"node:stream/promises";import um from"events";import Qe from"fs";import{EventEmitter as Cc}from"node:events";import ju from"node:stream";import{StringDecoder as fm}from"node:string_decoder";import $u from"node:path";import mr from"node:fs";import{dirname as Am,parse as Im}from"path";import{EventEmitter as Lm}from"events";import dc from"assert";import{Buffer as Fn}from"buffer";import*as hu from"zlib";import Nm from"zlib";import{posix as lr}from"node:path";import{basename as cw}from"node:path";import Ws from"fs";import Ct from"fs";import Eu from"path";import{win32 as yw}from"node:path";import Cu from"path";import df from"node:fs";import Bw from"node:assert";import{randomBytes as lf}from"node:crypto";import ne from"node:fs";import Ne from"node:path";import uf from"fs";import eo from"node:fs";import _i from"node:path";import it from"node:fs";import jw from"node:fs/promises";import Vs from"node:path";import{join as bf}from"node:path";import rt from"node:fs";import Af from"node:path";var dm=Object.defineProperty,lm=(t,e)=>{for(var r in e)dm(t,r,{get:e[r],enumerable:!0})},lu=typeof process=="object"&&process?process:{stdout:null,stderr:null},xm=t=>!!t&&typeof t=="object"&&(t instanceof Gn||t instanceof ju||hm(t)||pm(t)),hm=t=>!!t&&typeof t=="object"&&t instanceof Cc&&typeof t.pipe=="function"&&t.pipe!==ju.Writable.prototype.pipe,pm=t=>!!t&&typeof t=="object"&&t instanceof Cc&&typeof t.write=="function"&&typeof t.end=="function",zt=Symbol("EOF"),Ut=Symbol("maybeEmitEnd"),on=Symbol("emittedEnd"),ws=Symbol("emittingEnd"),ni=Symbol("emittedError"),_s=Symbol("closed"),uu=Symbol("read"),ys=Symbol("flush"),fu=Symbol("flushChunk"),ht=Symbol("encoding"),dr=Symbol("decoder"),Be=Symbol("flowing"),ri=Symbol("paused"),hr=Symbol("resume"),Fe=Symbol("buffer"),Ve=Symbol("pipes"),ze=Symbol("bufferLength"),Na=Symbol("bufferPush"),Es=Symbol("bufferShift"),Ke=Symbol("objectMode"),Se=Symbol("destroyed"),Ma=Symbol("error"),Ba=Symbol("emitData"),xu=Symbol("emitEnd"),Fa=Symbol("emitEnd2"),At=Symbol("async"),za=Symbol("abort"),bs=Symbol("aborted"),ii=Symbol("signal"),Rn=Symbol("dataListeners"),nt=Symbol("discarded"),si=t=>Promise.resolve().then(t),gm=t=>t(),mm=t=>t==="end"||t==="finish"||t==="prefinish",wm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,_m=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[hr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},ym=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)}},Em=t=>!!t.objectMode,bm=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Gn=class extends Cc{[Be]=!1;[ri]=!1;[Ve]=[];[Fe]=[];[Ke];[ht];[At];[dr];[zt]=!1;[on]=!1;[ws]=!1;[_s]=!1;[ni]=null;[ze]=0;[Se]=!1;[ii];[bs]=!1;[Rn]=0;[nt]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");Em(e)?(this[Ke]=!0,this[ht]=null):bm(e)?(this[ht]=e.encoding,this[Ke]=!1):(this[Ke]=!1,this[ht]=null),this[At]=!!e.async,this[dr]=this[ht]?new fm(this[ht]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Fe]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Ve]});let{signal:r}=e;r&&(this[ii]=r,r.aborted?this[za]():r.addEventListener("abort",()=>this[za]()))}get bufferLength(){return this[ze]}get encoding(){return this[ht]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[Ke]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[At]}set async(t){this[At]=this[At]||!!t}[za](){this[bs]=!0,this.emit("abort",this[ii]?.reason),this.destroy(this[ii]?.reason)}get aborted(){return this[bs]}set aborted(t){}write(t,e,r){if(this[bs])return!1;if(this[zt])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]?si:gm;if(!this[Ke]&&!Buffer.isBuffer(t)){if(_m(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(wm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Ke]?(this[Be]&&this[ze]!==0&&this[ys](!0),this[Be]?this.emit("data",t):this[Na](t),this[ze]!==0&&this.emit("readable"),r&&i(r),this[Be]):t.length?(typeof t=="string"&&!(e===this[ht]&&!this[dr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[ht]&&(t=this[dr].write(t)),this[Be]&&this[ze]!==0&&this[ys](!0),this[Be]?this.emit("data",t):this[Na](t),this[ze]!==0&&this.emit("readable"),r&&i(r),this[Be]):(this[ze]!==0&&this.emit("readable"),r&&i(r),this[Be])}read(t){if(this[Se])return null;if(this[nt]=!1,this[ze]===0||t===0||t&&t>this[ze])return this[Ut](),null;this[Ke]&&(t=null),this[Fe].length>1&&!this[Ke]&&(this[Fe]=[this[ht]?this[Fe].join(""):Buffer.concat(this[Fe],this[ze])]);let e=this[uu](t||null,this[Fe][0]);return this[Ut](),e}[uu](t,e){if(this[Ke])this[Es]();else{let r=e;t===r.length||t===null?this[Es]():typeof r=="string"?(this[Fe][0]=r.slice(t),e=r.slice(0,t),this[ze]-=t):(this[Fe][0]=r.subarray(t),e=r.subarray(0,t),this[ze]-=t)}return this.emit("data",e),!this[Fe].length&&!this[zt]&&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[zt]=!0,this.writable=!1,(this[Be]||!this[ri])&&this[Ut](),this}[hr](){this[Se]||(!this[Rn]&&!this[Ve].length&&(this[nt]=!0),this[ri]=!1,this[Be]=!0,this.emit("resume"),this[Fe].length?this[ys]():this[zt]?this[Ut]():this.emit("drain"))}resume(){return this[hr]()}pause(){this[Be]=!1,this[ri]=!0,this[nt]=!1}get destroyed(){return this[Se]}get flowing(){return this[Be]}get paused(){return this[ri]}[Na](t){this[Ke]?this[ze]+=1:this[ze]+=t.length,this[Fe].push(t)}[Es](){return this[Ke]?this[ze]-=1:this[ze]-=this[Fe][0].length,this[Fe].shift()}[ys](t=!1){do;while(this[fu](this[Es]())&&this[Fe].length);!t&&!this[Fe].length&&!this[zt]&&this.emit("drain")}[fu](t){return this.emit("data",t),this[Be]}pipe(t,e){if(this[Se])return t;this[nt]=!1;let r=this[on];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[Ve].push(e.proxyErrors?new ym(this,t,e):new Wu(this,t,e)),this[At]?si(()=>this[hr]()):this[hr]()),t}unpipe(t){let e=this[Ve].find(r=>r.dest===t);e&&(this[Ve].length===1?(this[Be]&&this[Rn]===0&&(this[Be]=!1),this[Ve]=[]):this[Ve].splice(this[Ve].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[nt]=!1,this[Rn]++,!this[Ve].length&&!this[Be]&&this[hr]();else if(t==="readable"&&this[ze]!==0)super.emit("readable");else if(mm(t)&&this[on])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[ni]){let i=e;this[At]?si(()=>i.call(this,this[ni])):i.call(this,this[ni])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Rn]=this.listeners("data").length,this[Rn]===0&&!this[nt]&&!this[Ve].length&&(this[Be]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Rn]=0,!this[nt]&&!this[Ve].length&&(this[Be]=!1)),e}get emittedEnd(){return this[on]}[Ut](){!this[ws]&&!this[on]&&!this[Se]&&this[Fe].length===0&&this[zt]&&(this[ws]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[_s]&&this.emit("close"),this[ws]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Se&&this[Se])return!1;if(t==="data")return!this[Ke]&&!r?!1:this[At]?(si(()=>this[Ba](r)),!0):this[Ba](r);if(t==="end")return this[xu]();if(t==="close"){if(this[_s]=!0,!this[on]&&!this[Se])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[ni]=r,super.emit(Ma,r);let o=!this[ii]||this.listeners("error").length?super.emit("error",r):!1;return this[Ut](),o}else if(t==="resume"){let o=super.emit("resume");return this[Ut](),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[Ut](),i}[Ba](t){for(let r of this[Ve])r.dest.write(t)===!1&&this.pause();let e=this[nt]?!1:super.emit("data",t);return this[Ut](),e}[xu](){return this[on]?!1:(this[on]=!0,this.readable=!1,this[At]?(si(()=>this[Fa]()),!0):this[Fa]())}[Fa](){if(this[dr]){let e=this[dr].end();if(e){for(let r of this[Ve])r.dest.write(e);this[nt]||super.emit("data",e)}}for(let e of this[Ve])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Ke]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[Ke]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[Ke])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[ht]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Se,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[nt]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[zt])return e();let i,o,c=p=>{this.off("data",l),this.off("end",u),this.off(Se,f),e(),o(p)},l=p=>{this.off("error",c),this.off("end",u),this.off(Se,f),this.pause(),i({value:p,done:!!this[zt]})},u=()=>{this.off("error",c),this.off("data",l),this.off(Se,f),e(),i({done:!0,value:void 0})},f=()=>c(new Error("stream destroyed"));return new Promise((p,m)=>{o=m,i=p,this.once(Se,f),this.once("error",c),this.once("end",u),this.once("data",l)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[nt]=!1;let t=!1,e=()=>(this.pause(),this.off(Ma,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(Ma,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[nt]=!0,this[Fe].length=0,this[ze]=0;let e=this;return typeof e.close=="function"&&!this[_s]&&e.close(),t?this.emit("error",t):this.emit(Se),this}static get isStream(){return xm}},vm=Qe.writev,gn=Symbol("_autoClose"),wt=Symbol("_close"),oi=Symbol("_ended"),de=Symbol("_fd"),Ua=Symbol("_finished"),jt=Symbol("_flags"),Ga=Symbol("_flush"),ac=Symbol("_handleChunk"),cc=Symbol("_makeBuf"),mi=Symbol("_mode"),vs=Symbol("_needDrain"),_r=Symbol("_onerror"),yr=Symbol("_onopen"),qa=Symbol("_onread"),pr=Symbol("_onwrite"),mn=Symbol("_open"),mt=Symbol("_path"),un=Symbol("_pos"),It=Symbol("_queue"),gr=Symbol("_read"),Ha=Symbol("_readSize"),Ht=Symbol("_reading"),ai=Symbol("_remain"),ja=Symbol("_size"),Os=Symbol("_write"),kn=Symbol("_writing"),Ls=Symbol("_defaultFlag"),Bn=Symbol("_errored"),Rc=class extends Gn{[Bn]=!1;[de];[mt];[Ha];[Ht]=!1;[ja];[ai];[gn];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[Bn]=!1,this[de]=typeof e.fd=="number"?e.fd:void 0,this[mt]=t,this[Ha]=e.readSize||16*1024*1024,this[Ht]=!1,this[ja]=typeof e.size=="number"?e.size:1/0,this[ai]=this[ja],this[gn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[de]=="number"?this[gr]():this[mn]()}get fd(){return this[de]}get path(){return this[mt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[mn](){Qe.open(this[mt],"r",(t,e)=>this[yr](t,e))}[yr](t,e){t?this[_r](t):(this[de]=e,this.emit("open",e),this[gr]())}[cc](){return Buffer.allocUnsafe(Math.min(this[Ha],this[ai]))}[gr](){if(!this[Ht]){this[Ht]=!0;let t=this[cc]();if(t.length===0)return process.nextTick(()=>this[qa](null,0,t));Qe.read(this[de],t,0,t.length,null,(e,r,i)=>this[qa](e,r,i))}}[qa](t,e,r){this[Ht]=!1,t?this[_r](t):this[ac](e,r)&&this[gr]()}[wt](){if(this[gn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,Qe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[_r](t){this[Ht]=!0,this[wt](),this.emit("error",t)}[ac](t,e){let r=!1;return this[ai]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[ai]<=0)&&(r=!1,this[wt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[de]=="number"&&this[gr](),!1;case"error":return this[Bn]?!1:(this[Bn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Sm=class extends Rc{[mn](){let t=!0;try{this[yr](null,Qe.openSync(this[mt],"r")),t=!1}finally{t&&this[wt]()}}[gr](){let t=!0;try{if(!this[Ht]){this[Ht]=!0;do{let e=this[cc](),r=e.length===0?0:Qe.readSync(this[de],e,0,e.length,null);if(!this[ac](r,e))break}while(!0);this[Ht]=!1}t=!1}finally{t&&this[wt]()}}[wt](){if(this[gn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,Qe.closeSync(t),this.emit("close")}}},Js=class extends um{readable=!1;writable=!0;[Bn]=!1;[kn]=!1;[oi]=!1;[It]=[];[vs]=!1;[mt];[mi];[gn];[de];[Ls];[jt];[Ua]=!1;[un];constructor(t,e){e=e||{},super(e),this[mt]=t,this[de]=typeof e.fd=="number"?e.fd:void 0,this[mi]=e.mode===void 0?438:e.mode,this[un]=typeof e.start=="number"?e.start:void 0,this[gn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[un]!==void 0?"r+":"w";this[Ls]=e.flags===void 0,this[jt]=e.flags===void 0?r:e.flags,this[de]===void 0&&this[mn]()}emit(t,...e){if(t==="error"){if(this[Bn])return!1;this[Bn]=!0}return super.emit(t,...e)}get fd(){return this[de]}get path(){return this[mt]}[_r](t){this[wt](),this[kn]=!0,this.emit("error",t)}[mn](){Qe.open(this[mt],this[jt],this[mi],(t,e)=>this[yr](t,e))}[yr](t,e){this[Ls]&&this[jt]==="r+"&&t&&t.code==="ENOENT"?(this[jt]="w",this[mn]()):t?this[_r](t):(this[de]=e,this.emit("open",e),this[kn]||this[Ga]())}end(t,e){return t&&this.write(t,e),this[oi]=!0,!this[kn]&&!this[It].length&&typeof this[de]=="number"&&this[pr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[oi]?(this.emit("error",new Error("write() after end()")),!1):this[de]===void 0||this[kn]||this[It].length?(this[It].push(t),this[vs]=!0,!1):(this[kn]=!0,this[Os](t),!0)}[Os](t){Qe.write(this[de],t,0,t.length,this[un],(e,r)=>this[pr](e,r))}[pr](t,e){t?this[_r](t):(this[un]!==void 0&&typeof e=="number"&&(this[un]+=e),this[It].length?this[Ga]():(this[kn]=!1,this[oi]&&!this[Ua]?(this[Ua]=!0,this[wt](),this.emit("finish")):this[vs]&&(this[vs]=!1,this.emit("drain"))))}[Ga](){if(this[It].length===0)this[oi]&&this[pr](null,0);else if(this[It].length===1)this[Os](this[It].pop());else{let t=this[It];this[It]=[],vm(this[de],t,this[un],(e,r)=>this[pr](e,r))}}[wt](){if(this[gn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,Qe.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Ku=class extends Js{[mn](){let t;if(this[Ls]&&this[jt]==="r+")try{t=Qe.openSync(this[mt],this[jt],this[mi])}catch(e){if(e?.code==="ENOENT")return this[jt]="w",this[mn]();throw e}else t=Qe.openSync(this[mt],this[jt],this[mi]);this[yr](null,t)}[wt](){if(this[gn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,Qe.closeSync(t),this.emit("close")}}[Os](t){let e=!0;try{this[pr](null,Qe.writeSync(this[de],t,0,t.length,this[un])),e=!1}finally{if(e)try{this[wt]()}catch{}}}},Tm=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"]]),Cm=t=>!!t.sync&&!!t.file,Rm=t=>!t.sync&&!!t.file,km=t=>!!t.sync&&!t.file,Dm=t=>!t.sync&&!t.file,Pm=t=>!!t.file,Om=t=>Tm.get(t)||t,kc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=Om(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ii=(t,e,r,i,o)=>Object.assign((c=[],l,u)=>{Array.isArray(c)&&(l=c,c={}),typeof l=="function"&&(u=l,l=void 0),l=l?Array.from(l):[];let f=kc(c);if(o?.(f,l),Cm(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(f,l)}else if(Rm(f)){let p=e(f,l);return u?p.then(()=>u(),u):p}else if(km(f)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(f,l)}else if(Dm(f)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(f,l)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),Mm=Nm.constants||{ZLIB_VERNUM:4736},kt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},Mm)),Bm=Fn.concat,pu=Object.getOwnPropertyDescriptor(Fn,"concat"),Fm=t=>t,Wa=pu?.writable===!0||pu?.set!==void 0?t=>{Fn.concat=t?Fm:Bm}:t=>{},zn=Symbol("_superWrite"),Ss=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"}},Ka=Symbol("flushFlag"),Dc=class extends Gn{#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 Ss(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 Ss(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return dc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Fn.alloc(0),{[Ka]:t})))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(r)}get ended(){return this.#n}[zn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=Fn.from(t,e)),this.#e)return;dc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},Wa(!0);let l;try{let f=typeof t[Ka]=="number"?t[Ka]:this.#r;l=this.#t._processChunk(t,f),Wa(!1)}catch(f){Wa(!1),this.#o(new Ss(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 Ss(f,this.write)));let u;if(l)if(Array.isArray(l)&&l.length>0){let f=l[0];u=this[zn](Fn.from(f));for(let p=1;p<l.length;p++)u=this[zn](l[p])}else u=this[zn](Fn.from(l));return r&&r(),u}},Vu=class extends Dc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||kt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||kt.Z_FINISH,t.fullFlushFlag=kt.Z_FULL_FLUSH,super(t,e),this.#e=t.level,this.#n=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==t||this.#n!==e){this.flush(kt.Z_SYNC_FLUSH),dc(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)}}}},zm=class extends Vu{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[zn](t){return this.#e?(this.#e=!1,t[9]=255,super[zn](t)):super[zn](t)}},Um=class extends Vu{constructor(t){super(t,"Unzip")}},Ju=class extends Dc{constructor(t,e){t=t||{},t.flush=t.flush||kt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||kt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=kt.BROTLI_OPERATION_FLUSH,super(t,e)}},Gm=class extends Ju{constructor(t){super(t,"BrotliCompress")}},qm=class extends Ju{constructor(t){super(t,"BrotliDecompress")}},Zu=class extends Dc{constructor(t,e){t=t||{},t.flush=t.flush||kt.ZSTD_e_continue,t.finishFlush=t.finishFlush||kt.ZSTD_e_end,t.fullFlushFlag=kt.ZSTD_e_flush,super(t,e)}},Hm=class extends Zu{constructor(t){super(t,"ZstdCompress")}},jm=class extends Zu{constructor(t){super(t,"ZstdDecompress")}},Wm=(t,e)=>{if(Number.isSafeInteger(t))t<0?$m(t,e):Km(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Km=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},$m=(t,e)=>{e[0]=255;var r=!1;t=t*-1;for(var i=e.length;i>1;i--){var o=t&255;t=Math.floor(t/256),r?e[i-1]=Yu(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Xu(o))}},Vm=t=>{let e=t[0],r=e===128?Zm(t.subarray(1,t.length)):e===255?Jm(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},Jm=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),l;i?l=Yu(c):c===0?l=c:(i=!0,l=Xu(c)),l!==0&&(r-=l*Math.pow(256,e-o-1))}return r},Zm=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},Yu=t=>(255^t)&255,Xu=t=>(255^t)+1&255,Ym={};lm(Ym,{code:()=>Pc,isCode:()=>Ns,isName:()=>Xm,name:()=>Zs,normalFsTypes:()=>Qu});var Ns=t=>Zs.has(t),Xm=t=>Pc.has(t),Qu=new Set(["0","","1","2","3","4","5","6","7","D"]),Zs=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"]]),Pc=new Map(Array.from(Zs).map(t=>[t[1],t[0]])),Un=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,r,i){Buffer.isBuffer(t)?this.decode(t,e||0,r,i):t&&this.#n(t)}decode(t,e,r,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");let o=Dn(t,e+156,1),c=Qu.has(o),l=c?r:void 0,u=c?i:void 0;if(this.path=l?.path??Dn(t,e,100),this.mode=l?.mode??u?.mode??fn(t,e+100,8),this.uid=l?.uid??u?.uid??fn(t,e+108,8),this.gid=l?.gid??u?.gid??fn(t,e+116,8),this.size=l?.size??u?.size??fn(t,e+124,12),this.mtime=l?.mtime??u?.mtime??$a(t,e+136,12),this.cksum=fn(t,e+148,12),u&&this.#n(u,!0),l&&this.#n(l),Ns(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Dn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=l?.uname??u?.uname??Dn(t,e+265,32),this.gname=l?.gname??u?.gname??Dn(t,e+297,32),this.devmaj=l?.devmaj??u?.devmaj??fn(t,e+329,8)??0,this.devmin=l?.devmin??u?.devmin??fn(t,e+337,8)??0,t[e+475]!==0){let p=Dn(t,e+345,155);this.path=p+"/"+this.path}else{let p=Dn(t,e+345,130);p&&(this.path=p+"/"+this.path),this.atime=r?.atime??i?.atime??$a(t,e+476,12),this.ctime=r?.ctime??i?.ctime??$a(t,e+488,12)}let f=256;for(let p=e;p<e+148;p++)f+=t[p];for(let p=e+156;p<e+512;p++)f+=t[p];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=Qm(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Pn(t,e,100,o)||this.needPax,this.needPax=xn(t,e+100,8,this.mode)||this.needPax,this.needPax=xn(t,e+108,8,this.uid)||this.needPax,this.needPax=xn(t,e+116,8,this.gid)||this.needPax,this.needPax=xn(t,e+124,12,this.size)||this.needPax,this.needPax=Va(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Pn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Pn(t,e+265,32,this.uname)||this.needPax,this.needPax=Pn(t,e+297,32,this.gname)||this.needPax,this.needPax=xn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=xn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Pn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=Pn(t,e+345,155,c)||this.needPax:(this.needPax=Pn(t,e+345,130,c)||this.needPax,this.needPax=Va(t,e+476,12,this.atime)||this.needPax,this.needPax=Va(t,e+488,12,this.ctime)||this.needPax);let l=256;for(let u=e;u<e+148;u++)l+=t[u];for(let u=e+156;u<e+512;u++)l+=t[u];return this.cksum=l,xn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:Zs.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Pc.get(t));if(Ns(e)||e==="Unsupported")this.#e=e;else if(Ns(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Qm=(t,e)=>{let r=t,i="",o,c=lr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=lr.dirname(r),r=lr.basename(r);do Buffer.byteLength(r)<=100&&Buffer.byteLength(i)<=e?o=[r,i,!1]:Buffer.byteLength(r)>100&&Buffer.byteLength(i)<=e?o=[r.slice(0,99),i,!0]:(r=lr.join(lr.basename(i),r),i=lr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Dn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),$a=(t,e,r)=>ew(fn(t,e,r)),ew=t=>t===void 0?void 0:new Date(t*1e3),fn=(t,e,r)=>Number(t[e])&128?Vm(t.subarray(e,e+r)):nw(t,e,r),tw=t=>isNaN(t)?void 0:t,nw=(t,e,r)=>tw(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),rw={12:8589934591,8:2097151},xn=(t,e,r,i)=>i===void 0?!1:i>rw[r]||i<0?(Wm(i,t.subarray(e,e+r)),!0):(iw(t,e,r,i),!1),iw=(t,e,r,i)=>t.write(sw(i,r),e,r,"ascii"),sw=(t,e)=>ow(Math.floor(t).toString(8),e),ow=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Va=(t,e,r,i)=>i===void 0?!1:xn(t,e,r,i.getTime()/1e3),aw=new Array(156).join("\0"),Pn=(t,e,r,i)=>i===void 0?!1:(t.write(i+aw,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),js=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 Un({path:("PaxHeader/"+cw(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
|
|
91
|
-
`).reduce(uw,Object.create(null)),uw=(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},fw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Y=fw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),xw=class extends Gn{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))))}},Ys=(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))},hw=1024*1024,lc=Buffer.from([31,139]),uc=Buffer.from([40,181,47,253]),pw=Math.max(lc.length,uc.length),at=Symbol("state"),On=Symbol("writeEntry"),Gt=Symbol("readEntry"),Ja=Symbol("nextEntry"),gu=Symbol("processEntry"),Tt=Symbol("extendedHeader"),ci=Symbol("globalExtendedHeader"),an=Symbol("meta"),mu=Symbol("emitMeta"),pe=Symbol("buffer"),qt=Symbol("queue"),cn=Symbol("ended"),Za=Symbol("emittedEnd"),Ln=Symbol("emit"),Ce=Symbol("unzip"),As=Symbol("consumeChunk"),Is=Symbol("consumeChunkSub"),Ya=Symbol("consumeBody"),wu=Symbol("consumeMeta"),_u=Symbol("consumeHeader"),di=Symbol("consuming"),Xa=Symbol("bufferConcat"),Ts=Symbol("maybeEnd"),ur=Symbol("writing"),dn=Symbol("aborted"),Cs=Symbol("onDone"),Nn=Symbol("sawValidEntry"),Rs=Symbol("sawNullBlock"),ks=Symbol("sawEOF"),yu=Symbol("closeStream"),gw=()=>!0,Ai=class extends Lm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[qt]=[];[pe];[Gt];[On];[at]="begin";[an]="";[Tt];[ci];[cn]=!1;[Ce];[dn]=!1;[Nn];[Rs]=!1;[ks]=!1;[ur]=!1;[di]=!1;[Za]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Cs,()=>{(this[at]==="begin"||this[Nn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Cs,t.ondone):this.on(Cs,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||hw,this.filter=typeof t.filter=="function"?t.filter:gw;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={}){Ys(this,t,e,r)}[_u](t,e){this[Nn]===void 0&&(this[Nn]=!1);let r;try{r=new Un(t,e,this[Tt],this[ci])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Rs]?(this[ks]=!0,this[at]==="begin"&&(this[at]="header"),this[Ln]("eof")):(this[Rs]=!0,this[Ln]("nullBlock"));else if(this[Rs]=!1,!r.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:r});else if(!r.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:r});else{let i=r.type;if(/^(Symbolic)?Link$/.test(i)&&!r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:r});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:r});else{let o=this[On]=new xw(r,this[Tt],this[ci]);if(!this[Nn])if(o.remain){let c=()=>{o.invalid||(this[Nn]=!0)};o.on("end",c)}else this[Nn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Ln]("ignoredEntry",o),this[at]="ignore",o.resume()):o.size>0&&(this[an]="",o.on("data",c=>this[an]+=c),this[at]="meta"):(this[Tt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Ln]("ignoredEntry",o),this[at]=o.remain?"ignore":"header",o.resume()):(o.remain?this[at]="body":(this[at]="header",o.end()),this[Gt]?this[qt].push(o):(this[qt].push(o),this[Ja]())))}}}[yu](){queueMicrotask(()=>this.emit("close"))}[gu](t){let e=!0;if(!t)this[Gt]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[Gt]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Ja]()),e=!1);return e}[Ja](){do;while(this[gu](this[qt].shift()));if(this[qt].length===0){let t=this[Gt];!t||t.flowing||t.size===t.remain?this[ur]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Ya](t,e){let r=this[On];if(!r)throw new Error("attempt to consume body without entry??");let i=r.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return r.write(o),r.blockRemain||(this[at]="header",this[On]=void 0,r.end()),o.length}[wu](t,e){let r=this[On],i=this[Ya](t,e);return!this[On]&&r&&this[mu](r),i}[Ln](t,e,r){this[qt].length===0&&!this[Gt]?this.emit(t,e,r):this[qt].push([t,e,r])}[mu](t){switch(this[Ln]("meta",this[an]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Tt]=js.parse(this[an],this[Tt],!1);break;case"GlobalExtendedHeader":this[ci]=js.parse(this[an],this[ci],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Tt]??Object.create(null);this[Tt]=e,e.path=this[an].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Tt]||Object.create(null);this[Tt]=e,e.linkpath=this[an].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[dn]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[dn])return r?.(),!1;if((this[Ce]===void 0||this.brotli===void 0&&this[Ce]===!1)&&t){if(this[pe]&&(t=Buffer.concat([this[pe],t]),this[pe]=void 0),t.length<pw)return this[pe]=t,r?.(),!0;for(let l=0;this[Ce]===void 0&&l<lc.length;l++)t[l]!==lc[l]&&(this[Ce]=!1);let o=!1;if(this[Ce]===!1&&this.zstd!==!1){o=!0;for(let l=0;l<uc.length;l++)if(t[l]!==uc[l]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Ce]===!1&&c)if(t.length<512)if(this[cn])this.brotli=!0;else return this[pe]=t,r?.(),!0;else try{new Un(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Ce]===void 0||this[Ce]===!1&&(this.brotli||o)){let l=this[cn];this[cn]=!1,this[Ce]=this[Ce]===void 0?new Um({}):o?new jm({}):new qm({}),this[Ce].on("data",f=>this[As](f)),this[Ce].on("error",f=>this.abort(f)),this[Ce].on("end",()=>{this[cn]=!0,this[As]()}),this[ur]=!0;let u=!!this[Ce][l?"end":"write"](t);return this[ur]=!1,r?.(),u}}this[ur]=!0,this[Ce]?this[Ce].write(t):this[As](t),this[ur]=!1;let i=this[qt].length>0?!1:this[Gt]?this[Gt].flowing:!0;return!i&&this[qt].length===0&&this[Gt]?.once("drain",()=>this.emit("drain")),r?.(),i}[Xa](t){t&&!this[dn]&&(this[pe]=this[pe]?Buffer.concat([this[pe],t]):t)}[Ts](){if(this[cn]&&!this[Za]&&!this[dn]&&!this[di]){this[Za]=!0;let t=this[On];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[Ln](Cs)}}[As](t){if(this[di]&&t)this[Xa](t);else if(!t&&!this[pe])this[Ts]();else if(t){if(this[di]=!0,this[pe]){this[Xa](t);let e=this[pe];this[pe]=void 0,this[Is](e)}else this[Is](t);for(;this[pe]&&this[pe]?.length>=512&&!this[dn]&&!this[ks];){let e=this[pe];this[pe]=void 0,this[Is](e)}this[di]=!1}(!this[pe]||this[cn])&&this[Ts]()}[Is](t){let e=0,r=t.length;for(;e+512<=r&&!this[dn]&&!this[ks];)switch(this[at]){case"begin":case"header":this[_u](t,e),e+=512;break;case"ignore":case"body":e+=this[Ya](t,e);break;case"meta":e+=this[wu](t,e);break;default:throw new Error("invalid state: "+this[at])}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[dn]||(this[Ce]?(t&&this[Ce].write(t),this[Ce].end()):(this[cn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Ts]())),this}},wi=t=>{let e=t.length-1,r=-1;for(;e>-1&&t.charAt(e)==="/";)r=e,e--;return r===-1?t:t.slice(0,r)},mw=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=>[wi(c),!0])),i=t.filter,o=(c,l="")=>{let u=l||Im(c).root||".",f;if(c===u)f=!1;else{let p=r.get(c);f=p!==void 0?p:o(Am(c),u)}return r.set(c,f),f};t.filter=i?(c,l)=>i(c,l)&&o(wi(c)):c=>o(wi(c))},ww=t=>{let e=new Ai(t),r=t.file,i;try{i=mr.openSync(r,"r");let o=mr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let l=Buffer.allocUnsafe(o.size),u=mr.readSync(i,l,0,o.size,0);e.end(u===l.byteLength?l:l.subarray(0,u))}else{let l=0,u=Buffer.allocUnsafe(c);for(;l<o.size;){let f=mr.readSync(i,u,0,c,l);if(f===0)break;l+=f,e.write(u.subarray(0,f))}e.end()}}finally{if(typeof i=="number")try{mr.closeSync(i)}catch{}}},_w=(t,e)=>{let r=new Ai(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("end",c),mr.stat(o,(u,f)=>{if(u)l(u);else{let p=new Rc(o,{readSize:i,size:f.size});p.on("error",l),p.pipe(r)}})})},Er=Ii(ww,_w,t=>new Ai(t),t=>new Ai(t),(t,e)=>{e?.length&&tf(t,e),t.noResume||mw(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:Ew,parse:bu}=yw,Oc=t=>{let e="",r=bu(t);for(;Ew(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=bu(t)}return[e,t]},Xs=["|","<",">","?",":"],Lc=Xs.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),bw=new Map(Xs.map((t,e)=>[t,Lc[e]])),vw=new Map(Lc.map((t,e)=>[t,Xs[e]])),vu=t=>Xs.reduce((e,r)=>e.split(r).join(bw.get(r)),t),Sw=t=>Lc.reduce((e,r)=>e.split(r).join(vw.get(r)),t),rf=(t,e)=>e?(t=Y(t).replace(/^\.(\/|$)/,""),wi(e)+"/"+t):Y(t),Aw=16*1024*1024,Su=Symbol("process"),Au=Symbol("file"),Iu=Symbol("directory"),fc=Symbol("symlink"),Tu=Symbol("hardlink"),li=Symbol("header"),Ms=Symbol("read"),xc=Symbol("lstat"),Bs=Symbol("onlstat"),hc=Symbol("onread"),pc=Symbol("onreadlink"),gc=Symbol("openfile"),mc=Symbol("onopenfile"),hn=Symbol("close"),Ks=Symbol("mode"),wc=Symbol("awaitDrain"),Qa=Symbol("ondrain"),Rt=Symbol("prefix"),sf=class extends Gn{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=kc(e);super(),this.path=Y(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||Aw,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]=Oc(this.path);c&&typeof l=="string"&&(this.path=l,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Sw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=Y(r.absolute||Eu.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[Bs](o):this[xc]()}warn(t,e,r={}){return Ys(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[xc](){Ct.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Bs](e)})}[Bs](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=Cw(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[fc]();default:return this.end()}}[Ks](t){return nf(t,this.type==="Directory",this.portable)}[Rt](t){return rf(t,this.prefix)}[li](){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 Un({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this[Ks](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 js({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let t=this.header?.block;if(!t)throw new Error("failed to encode header");super.write(t)}[Iu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[li](),this.end()}[fc](){Ct.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[pc](e)})}[pc](t){this.linkpath=Y(t),this[li](),this.end()}[Tu](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=Y(Eu.relative(this.cwd,t)),this.stat.size=0,this[li](),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[Tu](e);this.linkCache.set(t,this.absolute)}if(this[li](),this.stat.size===0)return this.end();this[gc]()}[gc](){Ct.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[mc](e)})}[mc](t){if(this.fd=t,this.#e)return this[hn]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[Ms]()}[Ms](){let{fd:t,buf:e,offset:r,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");Ct.read(t,e,r,i,o,(c,l)=>{if(c)return this[hn](()=>this.emit("error",c));this[hc](l)})}[hn](t=()=>{}){this.fd!==void 0&&Ct.close(this.fd,t)}[hc](t){if(t<=0&&this.remain>0){let r=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[hn](()=>this.emit("error",r))}if(t>this.remain){let r=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[hn](()=>this.emit("error",r))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let r=t;r<this.length&&t<this.blockRemain;r++)this.buf[r+this.offset]=0,t++,this.remain++;let e=this.offset===0&&t===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+t);this.write(e)?this[Qa]():this[wc](()=>this[Qa]())}[wc](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)}[Qa](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[hn](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[Ms]()}},Iw=class extends sf{sync=!0;[xc](){this[Bs](Ct.lstatSync(this.absolute))}[fc](){this[pc](Ct.readlinkSync(this.absolute))}[gc](){this[mc](Ct.openSync(this.absolute,"r"))}[Ms](){let t=!0;try{let{fd:e,buf:r,offset:i,length:o,pos:c}=this;if(e===void 0||r===void 0)throw new Error("fd and buf must be set in READ method");let l=Ct.readSync(e,r,i,o,c);this[hc](l),t=!1}finally{if(t)try{this[hn](()=>{})}catch{}}}[wc](t){t()}[hn](t=()=>{}){this.fd!==void 0&&Ct.closeSync(this.fd),t()}},Tw=class extends Gn{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 Ys(this,t,e,r)}constructor(t,e={}){let r=kc(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[Ks](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]=Oc(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 Un({path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),o&&this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute path`,{entry:this,path:o+this.path}),this.header.encode()&&!this.noPax&&super.write(new js({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Rt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Rt](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let c=this.header?.block;if(!c)throw new Error("failed to encode header");super.write(c),t.pipe(this)}[Rt](t){return rf(t,this.prefix)}[Ks](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}},Cw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",Rw=class wr{tail;head;length=0;static create(e=[]){return new wr(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++)Dw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)Pw(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 wr;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 wr;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 wr;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 wr;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=kw(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 kw(t,e,r){let i=e,o=e?e.next:t.head,c=new Nc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function Dw(t,e){t.tail=new Nc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function Pw(t,e){t.head=new Nc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Nc=class{list;next;prev;value;constructor(t,e,r,i){this.list=i,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,r?(r.prev=this,this.next=r):this.next=void 0}},Ru=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},ku=Buffer.alloc(1024),Fs=Symbol("onStat"),ui=Symbol("ended"),pt=Symbol("queue"),fi=Symbol("pendingLinks"),ln=Symbol("current"),Mn=Symbol("process"),xi=Symbol("processing"),Ds=Symbol("processJob"),gt=Symbol("jobs"),ec=Symbol("jobDone"),zs=Symbol("addFSEntry"),Du=Symbol("addTarEntry"),_c=Symbol("stat"),yc=Symbol("readdir"),Us=Symbol("onreaddir"),Gs=Symbol("pipe"),Pu=Symbol("entry"),tc=Symbol("entryOpt"),qs=Symbol("writeEntryClass"),of=Symbol("write"),nc=Symbol("ondrain"),Qs=class extends Gn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[qs];onWriteEntry;[pt];[fi]=new Map;[gt]=0;[xi]=!1;[ui]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=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[qs]=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 zm(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new Gm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new Hm(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[nc]()),this.on("resume",()=>e.resume())}else this.on("drain",this[nc]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[pt]=new Rw,this[gt]=0,this.jobs=Number(t.jobs)||4,this[xi]=!1,this[ui]=!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[ui]=!0,this[Mn](),r&&r(),this}write(t){if(this[ui])throw new Error("write after end");return typeof t=="string"?this[zs](t):this[Du](t),this.flowing}[Du](t){let e=Y(Cu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Ru(t.path,e);r.entry=new Tw(t,this[tc](r)),r.entry.on("end",()=>this[ec](r)),this[gt]+=1,this[pt].push(r)}this[Mn]()}[zs](t){let e=Y(Cu.resolve(this.cwd,t));this[pt].push(new Ru(t,e)),this[Mn]()}[_c](t){t.pending=!0,this[gt]+=1;let e=this.follow?"stat":"lstat";Ws[e](t.absolute,(r,i)=>{t.pending=!1,this[gt]-=1,r?this.emit("error",r):this[Fs](t,i)})}[Fs](t,e){if(this.statCache.set(t.absolute,e),t.stat=e,!this.filter(t.path,e))t.ignore=!0;else if(e.isFile()&&e.nlink>1&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync)if(t===this[ln])this[Ds](t);else{let r=`${e.dev}:${e.ino}`,i=this[fi].get(r);i?i.push(t):this[fi].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Mn]()}[yc](t){t.pending=!0,this[gt]+=1,Ws.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[gt]-=1,e)return this.emit("error",e);this[Us](t,r)})}[Us](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Mn]()}[Mn](){if(!this[xi]){this[xi]=!0;for(let t=this[pt].head;t&&this[gt]<this.jobs;t=t.next)if(this[Ds](t.value),t.value.ignore){let e=t.next;this[pt].removeNode(t),t.next=e}this[xi]=!1,this[ui]&&this[pt].length===0&&this[gt]===0&&(this.zip?this.zip.end(ku):(super.write(ku),super.end()))}}get[ln](){return this[pt]&&this[pt].head&&this[pt].head.value}[ec](t){this[pt].shift(),this[gt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[fi].get(r);if(i){this[fi].delete(r);for(let o of i)o.pending=!1,this[Ds](o)}}this[Mn]()}[Ds](t){if(t.pending&&t.pendingLink&&t===this[ln]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[ln]&&!t.piped&&this[Gs](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Fs](t,e):this[_c](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[Us](t,e):this[yc](t),!t.readdir)return}if(t.entry=this[Pu](t),!t.entry){t.ignore=!0;return}t===this[ln]&&!t.piped&&this[Gs](t)}}}[tc](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[gt]+=1;try{return new this[qs](t.path,this[tc](t)).on("end",()=>this[ec](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[nc](){this[ln]&&this[ln].entry&&this[ln].entry.resume()}[Gs](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[zs](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={}){Ys(this,t,e,r)}},Mc=class extends Qs{sync=!0;constructor(t){super(t),this[qs]=Iw}pause(){}resume(){}[_c](t){let e=this.follow?"statSync":"lstatSync";this[Fs](t,Ws[e](t.absolute))}[yc](t){this[Us](t,Ws.readdirSync(t.absolute))}[Gs](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[zs](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)})}},Ow=(t,e)=>{let r=new Mc(t),i=new Ku(t.file,{mode:t.mode||438});r.pipe(i),af(r,e)},Lw=(t,e)=>{let r=new Qs(t),i=new Js(t.file,{mode:t.mode||438});r.pipe(i);let o=new Promise((c,l)=>{i.on("error",l),i.on("close",c),r.on("error",l)});return cf(r,e).catch(c=>r.emit("error",c)),o},af=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Er({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 Er({file:$u.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},Nw=(t,e)=>{let r=new Mc(t);return af(r,e),r},Mw=(t,e)=>{let r=new Qs(t);return cf(r,e).catch(i=>r.emit("error",i)),r},lA=Ii(Ow,Lw,Nw,Mw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),Fw=process.env.__FAKE_PLATFORM__||process.platform,ff=Fw==="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,zw=ff&&!!gf,Uw=512*1024,Gw=gf|hf|xf|pf,Lu=!ff&&typeof Ou=="number"?Ou|hf|xf|pf:null,mf=Lu!==null?()=>Lu:zw?t=>t<Uw?Gw:"w":()=>"w",Ec=(t,e,r)=>{try{return eo.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},$s=(t,e,r,i)=>{eo.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},qw=(t,e,r,i,o)=>{if(e.isDirectory())wf(_i.resolve(t,e.name),r,i,c=>{if(c)return o(c);let l=_i.resolve(t,e.name);$s(l,r,i,o)});else{let c=_i.resolve(t,e.name);$s(c,r,i,o)}},wf=(t,e,r,i)=>{eo.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 $s(t,e,r,i);let l=c.length,u=null,f=p=>{if(!u){if(p)return i(u=p);if(--l===0)return $s(t,e,r,i)}};for(let p of c)qw(t,p,e,r,f)})},Hw=(t,e,r,i)=>{e.isDirectory()&&_f(_i.resolve(t,e.name),r,i),Ec(_i.resolve(t,e.name),r,i)},_f=(t,e,r)=>{let i;try{i=eo.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return Ec(t,e,r);throw c}for(let o of i)Hw(t,o,e,r);return Ec(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"}},to=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"}},Ww=(t,e)=>{it.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new yf(t,r?.code||"ENOTDIR")),e(r)})},Kw=(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,f=typeof l=="number"&&typeof u=="number"&&(l!==e.processUid||u!==e.processGid),p=e.preserve,m=e.unlink,b=Y(e.cwd),A=(S,I)=>{S?r(S):I&&f?wf(I,l,u,T=>A(T)):c?it.chmod(t,o,r):r()};if(t===b)return Ww(t,A);if(p)return jw.mkdir(t,{mode:o,recursive:!0}).then(S=>A(null,S??void 0),A);let y=Y(Vs.relative(b,t)).split("/");bc(b,y,o,m,b,void 0,A)},bc=(t,e,r,i,o,c,l)=>{if(e.length===0)return l(null,c);let u=e.shift(),f=Y(Vs.resolve(t+"/"+u));it.mkdir(f,r,Ef(f,e,r,i,o,c,l))},Ef=(t,e,r,i,o,c,l)=>u=>{u?it.lstat(t,(f,p)=>{if(f)f.path=f.path&&Y(f.path),l(f);else if(p.isDirectory())bc(t,e,r,i,o,c,l);else if(i)it.unlink(t,m=>{if(m)return l(m);it.mkdir(t,r,Ef(t,e,r,i,o,c,l))});else{if(p.isSymbolicLink())return l(new to(t,t+"/"+e.join("/")));l(u)}}):(c=c||t,bc(t,e,r,i,o,c,l))},$w=t=>{let e=!1,r;try{e=it.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new yf(t,r??"ENOTDIR")}},Vw=(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),f=e.preserve,p=e.unlink,m=Y(e.cwd),b=S=>{S&&u&&_f(S,c,l),o&&it.chmodSync(t,i)};if(t===m)return $w(m),b();if(f)return b(it.mkdirSync(t,{mode:i,recursive:!0})??void 0);let A=Y(Vs.relative(m,t)).split("/"),y;for(let S=A.shift(),I=m;S&&(I+="/"+S);S=A.shift()){I=Y(Vs.resolve(I));try{it.mkdirSync(I,i),y=y||I}catch{let T=it.lstatSync(I);if(T.isDirectory())continue;if(p){it.unlinkSync(I),it.mkdirSync(I,i),y=y||I;continue}else if(T.isSymbolicLink())return new to(I,I+"/"+A.join("/"))}}return b(y)},rc=Object.create(null),Nu=1e4,fr=new Set,Jw=t=>{fr.has(t)?fr.delete(t):rc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),fr.add(t);let e=rc[t],r=fr.size-Nu;if(r>Nu/10){for(let i of fr)if(fr.delete(i),delete rc[i],--r<=0)break}return e},Zw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Yw=Zw==="win32",Xw=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=bf(i,r)),e.push(r||"/"),e},[]),Qw=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=Yw?["win32 parallelization disabled"]:t.map(i=>wi(bf(Jw(i))));let r=new Set(t.map(i=>Xw(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let l=this.#e.get(c);if(!l||l?.[0]!==t)continue;let u=l[1];if(!u){this.#e.delete(c);continue}if(l.shift(),typeof u=="function")o.add(u);else for(let f of u)o.add(f)}for(let c of i){let l=this.#e.get(c),u=l?.[0];if(!(!l||!(u instanceof Set)))if(u.size===1&&l.length===1){this.#e.delete(c);continue}else if(u.size===1){l.shift();let f=l[0];typeof f=="function"&&o.add(f)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},e_=()=>process.umask(),Mu=Symbol("onEntry"),vc=Symbol("checkFs"),Bu=Symbol("checkFs2"),Sc=Symbol("isReusable"),ct=Symbol("makeFs"),Ac=Symbol("file"),Ic=Symbol("directory"),Hs=Symbol("link"),Fu=Symbol("symlink"),zu=Symbol("hardlink"),gi=Symbol("ensureNoSymlink"),Uu=Symbol("unsupported"),Gu=Symbol("checkPath"),ic=Symbol("stripAbsolutePath"),pn=Symbol("mkdir"),Ue=Symbol("onError"),Ps=Symbol("pending"),qu=Symbol("pend"),xr=Symbol("unpend"),sc=Symbol("ended"),oc=Symbol("maybeClose"),Tc=Symbol("skip"),yi=Symbol("doChown"),Ei=Symbol("uid"),bi=Symbol("gid"),vi=Symbol("checkedCwd"),t_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Si=t_==="win32",n_=1024,r_=(t,e)=>{if(!Si)return ne.unlink(t,e);let r=t+".DELETE."+lf(16).toString("hex");ne.rename(t,r,i=>{if(i)return e(i);ne.unlink(r,e)})},i_=t=>{if(!Si)return ne.unlinkSync(t);let e=t+".DELETE."+lf(16).toString("hex");ne.renameSync(t,e),ne.unlinkSync(e)},Hu=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Bc=class extends Ai{[sc]=!1;[vi]=!1;[Ps]=0;reservations=new Qw;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[sc]=!0,this[oc]()},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:n_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Si,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=Y(Ne.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:e_():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)}[oc](){this[sc]&&this[Ps]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[ic](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Oc(r),l=c.replaceAll(/\\/g,"/").split("/");if(l.includes("..")||Si&&/^[a-z]:\.\.$/i.test(l[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let u=Ne.posix.dirname(t.path),f=Ne.posix.normalize(Ne.posix.join(u,l.join("/")));if(f.startsWith("../")||f==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:r}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:r})),!0}[Gu](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[ic](t,"path")||!this[ic](t,"linkpath"))return!1;if(t.absolute=Ne.isAbsolute(t.path)?Y(Ne.resolve(t.path)):Y(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: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}=Ne.win32.parse(String(t.absolute));t.absolute=i+vu(String(t.absolute).slice(i.length));let{root:o}=Ne.win32.parse(t.path);t.path=o+vu(t.path.slice(o.length))}return!0}[Mu](t){if(!this[Gu](t))return t.resume();switch(Bw.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[vc](t);default:return this[Uu](t)}}[Ue](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[xr](),e.resume())}[pn](t,e,r){Kw(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)}[yi](t){return this.forceChown||this.preserveOwner&&(typeof t.uid=="number"&&t.uid!==this.processUid||typeof t.gid=="number"&&t.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[Ei](t){return Hu(this.uid,t.uid,this.processUid)}[bi](t){return Hu(this.gid,t.gid,this.processGid)}[Ac](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Js(String(t.absolute),{flags:mf(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&ne.close(i.fd,()=>{}),i.write=()=>!0,this[Ue](u,t),e()});let o=1,c=u=>{if(u){i.fd&&ne.close(i.fd,()=>{}),this[Ue](u,t),e();return}--o===0&&i.fd!==void 0&&ne.close(i.fd,f=>{f?this[Ue](f,t):this[xr](),e()})};i.on("finish",()=>{let u=String(t.absolute),f=i.fd;if(typeof f=="number"&&t.mtime&&!this.noMtime){o++;let p=t.atime||new Date,m=t.mtime;ne.futimes(f,p,m,b=>b?ne.utimes(u,p,m,A=>c(A&&b)):c())}if(typeof f=="number"&&this[yi](t)){o++;let p=this[Ei](t),m=this[bi](t);typeof p=="number"&&typeof m=="number"&&ne.fchown(f,p,m,b=>b?ne.chown(u,p,m,A=>c(A&&b)):c())}c()});let l=this.transform&&this.transform(t)||t;l!==t&&(l.on("error",u=>{this[Ue](u,t),e()}),t.pipe(l)),l.pipe(i)}[Ic](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[pn](String(t.absolute),r,i=>{if(i){this[Ue](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[xr](),t.resume())};t.mtime&&!this.noMtime&&(o++,ne.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[yi](t)&&(o++,ne.chown(String(t.absolute),Number(this[Ei](t)),Number(this[bi](t)),c)),c()})}[Uu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Fu](t,e){let r=Y(Ne.relative(this.cwd,Ne.resolve(Ne.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[gi](t,this.cwd,r,()=>this[Hs](t,String(t.linkpath),"symlink",e),i=>{this[Ue](i,t),e()})}[zu](t,e){let r=Y(Ne.resolve(this.cwd,String(t.linkpath))),i=Y(String(t.linkpath)).split("/");this[gi](t,this.cwd,i,()=>this[Hs](t,r,"link",e),o=>{this[Ue](o,t),e()})}[gi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let l=Ne.resolve(e,c);ne.lstat(l,(u,f)=>{if(u)return i();if(f?.isSymbolicLink())return o(new to(l,Ne.resolve(l,r.join("/"))));this[gi](t,l,r,i,o)})}[qu](){this[Ps]++}[xr](){this[Ps]--,this[oc]()}[Tc](t){this[xr](),t.resume()}[Sc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Si}[vc](t){this[qu]();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[pn](this.cwd,this.dmode,l=>{if(l){this[Ue](l,t),r();return}this[vi]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let l=Y(Ne.dirname(String(t.absolute)));if(l!==this.cwd)return this[pn](l,this.dmode,u=>{if(u){this[Ue](u,t),r();return}c()})}c()},c=()=>{ne.lstat(String(t.absolute),(l,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Tc](t),r();return}if(l||this[Sc](t,u))return this[ct](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let f=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,p=m=>this[ct](m??null,t,r);return f?ne.chmod(String(t.absolute),Number(t.mode),p):p()}if(t.absolute!==this.cwd)return ne.rmdir(String(t.absolute),f=>this[ct](f??null,t,r))}if(t.absolute===this.cwd)return this[ct](null,t,r);r_(String(t.absolute),f=>this[ct](f??null,t,r))})};this[vi]?o():i()}[ct](t,e,r){if(t){this[Ue](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[Ac](e,r);case"Link":return this[zu](e,r);case"SymbolicLink":return this[Fu](e,r);case"Directory":case"GNUDumpDir":return this[Ic](e,r)}}[Hs](t,e,r,i){ne[r](e,String(t.absolute),o=>{o?this[Ue](o,t):(this[xr](),t.resume()),i()})}},hi=t=>{try{return[null,t()]}catch(e){return[e,null]}},vf=class extends Bc{sync=!0;[ct](t,e){return super[ct](t,e,()=>{})}[vc](t){if(!this[vi]){let o=this[pn](this.cwd,this.dmode);if(o)return this[Ue](o,t);this[vi]=!0}if(t.absolute!==this.cwd){let o=Y(Ne.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[pn](o,this.dmode);if(c)return this[Ue](c,t)}}let[e,r]=hi(()=>ne.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Tc](t);if(e||this[Sc](t,r))return this[ct](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[l]=c?hi(()=>{ne.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ct](l,t)}let[o]=hi(()=>ne.rmdirSync(String(t.absolute)));this[ct](o,t)}let[i]=t.absolute===this.cwd?[]:hi(()=>i_(String(t.absolute)));this[ct](i,t)}[Ac](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=l=>{let u;try{ne.closeSync(o)}catch(f){u=f}(l||u)&&this[Ue](l||u,t),e()},o;try{o=ne.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[Ue](l,t)),t.pipe(c)),c.on("data",l=>{try{ne.writeSync(o,l,0,l.length)}catch(u){i(u)}}),c.on("end",()=>{let l=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,f=t.mtime;try{ne.futimesSync(o,u,f)}catch(p){try{ne.utimesSync(String(t.absolute),u,f)}catch{l=p}}}if(this[yi](t)){let u=this[Ei](t),f=this[bi](t);try{ne.fchownSync(o,Number(u),Number(f))}catch(p){try{ne.chownSync(String(t.absolute),Number(u),Number(f))}catch{l=l||p}}}i(l)})}[Ic](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[pn](String(t.absolute),r);if(i){this[Ue](i,t),e();return}if(t.mtime&&!this.noMtime)try{ne.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[yi](t))try{ne.chownSync(String(t.absolute),Number(this[Ei](t)),Number(this[bi](t)))}catch{}e(),t.resume()}[pn](t,e){try{return Vw(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}}[gi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let l of r){c=Ne.resolve(c,l);let[u,f]=hi(()=>ne.lstatSync(c));if(u)return i();if(f.isSymbolicLink())return o(new to(c,Ne.resolve(e,r.join("/"))))}i()}[Hs](t,e,r,i){let o=`${r}Sync`;try{ne[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[Ue](c,t)}}},s_=t=>{let e=new vf(t),r=t.file,i=df.statSync(r),o=t.maxReadSize||16*1024*1024;new Sm(r,{readSize:o,size:i.size}).pipe(e)},o_=(t,e)=>{let r=new Bc(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,f)=>{if(u)l(u);else{let p=new Rc(o,{readSize:i,size:f.size});p.on("error",l),p.pipe(r)}})})},Sf=Ii(s_,o_,t=>new vf(t),t=>new Bc(t),(t,e)=>{e?.length&&tf(t,e)}),a_=(t,e)=>{let r=new Mc(t),i=!0,o,c;try{try{o=rt.openSync(t.file,"r+")}catch(f){if(f?.code==="ENOENT")o=rt.openSync(t.file,"w+");else throw f}let l=rt.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<l.size;c+=512){for(let m=0,b=0;m<512;m+=b){if(b=rt.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(!b)break e}let f=new Un(u);if(!f.cksumValid)break;let p=512*Math.ceil((f.size||0)/512);if(c+p+512>l.size)break;c+=p,t.mtimeCache&&f.mtime&&t.mtimeCache.set(String(f.path),f.mtime)}i=!1,c_(t,r,c,o,e)}finally{if(i)try{rt.closeSync(o)}catch{}}},c_=(t,e,r,i,o)=>{let c=new Ku(t.file,{fd:i,start:r});e.pipe(c),l_(e,o)},d_=(t,e)=>{e=Array.from(e);let r=new Qs(t),i=(o,c,l)=>{let u=(A,y)=>{A?rt.close(o,S=>l(A)):l(null,y)},f=0;if(c===0)return u(null,0);let p=0,m=Buffer.alloc(512),b=(A,y)=>{if(A||y===void 0)return u(A);if(p+=y,p<512&&y)return rt.read(o,m,p,m.length-p,f+p,b);if(f===0&&m[0]===31&&m[1]===139)return u(new Error("cannot append to compressed archives"));if(p<512)return u(null,f);let S=new Un(m);if(!S.cksumValid)return u(null,f);let I=512*Math.ceil((S.size??0)/512);if(f+I+512>c||(f+=I+512,f>=c))return u(null,f);t.mtimeCache&&S.mtime&&t.mtimeCache.set(String(S.path),S.mtime),p=0,rt.read(o,m,0,512,f,b)};rt.read(o,m,0,512,f,b)};return new Promise((o,c)=>{r.on("error",c);let l="r+",u=(f,p)=>{if(f&&f.code==="ENOENT"&&l==="r+")return l="w+",rt.open(t.file,l,u);if(f||!p)return c(f);rt.fstat(p,(m,b)=>{if(m)return rt.close(p,()=>c(m));i(p,b.size,(A,y)=>{if(A)return c(A);let S=new Js(t.file,{fd:p,start:y});r.pipe(S),S.on("error",c),S.on("close",o),u_(r,e)})})};rt.open(t.file,l,u)})},l_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Er({file:Af.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},u_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Er({file:Af.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},pi=Ii(a_,d_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!Pm(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")}),AA=Ii(pi.syncFile,pi.asyncFile,pi.syncNoFile,pi.asyncNoFile,(t,e=[])=>{pi.validate?.(t,e),f_(t)}),f_=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(r,i)=>e(r,i)&&!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0)):(r,i)=>!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0))};rn();var _t={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",UPGRADE:"_agent/upgrade",DELETE:"_agent/delete"};function no(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function If(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function ro(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Tf(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function Cf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function br(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Wt();We();te();Oe();We();function wn(t,e){if(no(t)!=="cloud")throw new C("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Ti(t){return t.startsWith("http://")||t.startsWith("https://")}function io(t){return t.endsWith("/")?t.slice(0,-1):t}We();te();var so="1008033",Pf="1289";var Of="pbbp2",Lf="https://www.coze.cn",Nf="/api/coze_claw/resource/get_frontier_key",y_="https://www.coze.cn",E_="wss://frontier.coze.cn";function oo(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??y_}function Mf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??E_}function vr(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 Ri(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Ci=q("handshake");async function Fc(t){let e=oo(t.endpoint),r=t.timeoutMs??1e4,i=`${io(e)}${Nf}?aid=${encodeURIComponent(so)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...vr(t.ppeOverride)},c=new AbortController,l=setTimeout(()=>c.abort(),r);Ci.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")??"",p=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let S=await u.text().catch(()=>"");throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${f}: ${S.slice(0,200)}`)}let m=await u.json();if(m.code!==void 0&&m.code!==0)throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${m.code} msg=${m.msg??"-"} logid=${f}`);let b=m.data??{},A=typeof b.access_key=="string"&&b.access_key||typeof b.accessKey=="string"&&b.accessKey||void 0,y=typeof b.device_id=="string"&&b.device_id||typeof b.deviceId=="string"&&b.deviceId||void 0;if(!A||!y){let S=JSON.stringify(m).slice(0,500);throw new C("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${f}: ${S}`)}return Ci.info("handshake ok",{remoteDeviceId:y,logid:f,traceId:p}),{accessKey:A,deviceId:y}}catch(u){if(u instanceof C)throw Ci.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Ci.warn("handshake timeout",{base:e,timeoutMs:r}),new C("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let f=u.cause;throw Ci.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:f?.code,syscall:f?.syscall,cause:String(u).slice(0,300)}),new C("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(l)}}var zc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",yt="auto",Bf=15e4;function Ff(t){return{model:Uc(t.model)??yt,...t.modelToken?{modelToken:t.modelToken}:{}}}function zf(t){return!t||t===yt}var b_=new Set(["auto","\u81EA\u52A8"]);function Uc(t){let e=t?.trim();if(e)return b_.has(e.toLowerCase())?yt:e}function Uf(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=zc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||yt;e.ANTHROPIC_MODEL=r,e.ANTHROPIC_SMALL_FAST_MODEL=r,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=r,e.ANTHROPIC_DEFAULT_OPUS_MODEL=r,e.ANTHROPIC_DEFAULT_SONNET_MODEL=r,e.CLAUDE_CODE_SUBAGENT_MODEL=r,e.CLAUDE_CODE_ATTRIBUTION_HEADER="0",t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else zf(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Gf(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||yt}"`):zf(t.model)||e.push("-c",`model="${t.model}"`),t.modelToken){e.push("-c",'model_providers.coze.name="coze"'),e.push("-c",`model_providers.coze.base_url="${zc}/v1"`),e.push("-c",'model_providers.coze.env_key="OPENAI_API_KEY"'),e.push("-c",'model_providers.coze.wire_api="responses"'),e.push("-c","model_providers.coze.requires_openai_auth=false"),e.push("-c","model_providers.coze.supports_websockets=false"),e.push("-c",'model_provider="coze"');let r=t.modelInfo?.contextWindow??Bf;e.push("-c",`model_context_window=${r}`)}return e}function qf(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function Gc(t,e){let{ttEnv:r,usePpe:i}=Ri(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Hf(t,e,r){if(!t.modelToken)return{};let i=Gc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,l])=>`${c}:${l}`).join(`
|
|
92
|
-
`)}}function qc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function jf(t,e,r){if(!t.modelToken)return null;let i=t.model||yt,o=Gc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let l={baseUrl:`${zc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:[{id:i,name:i,reasoning:!1,input:c,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:t.modelInfo?.contextWindow??Bf,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(l.headers=o),l}function Wf(t,e,r){if(!t.modelToken)return[];let i=Gc(e,r),o=[];for(let[c,l]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${l}"`);return o}var Ae=q("agent-handlers"),Kf=5*1024*1024,C_=1,R_=6,k_=new Set(["node_modules",".git",".coze","dist","build",".next"]),D_=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,P_=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,O_=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function L_(t){let e=t?.trim();return e?O_.test(e)||P_.test(e)?e:(Ae.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function N_(t){return new Promise((e,r)=>{let i=et("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 ao=class{constructor(e){this.opts=e}opts;async listSkills(e){wn(e._meta,"_agent/listSkills");let r=br(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Ye(r).workspace,c=i?.skills??[],l=[];for(let u of c){let f=Dt(o,u.relPath,"SKILL.md");await A_(f).then(m=>m.isFile()).catch(()=>!1)&&l.push(U_(u))}return{skills:l}}async addSkills(e){let r=br(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],l=new Map(c.map((f,p)=>[f.skillId,p])),u=[];for(let f of o){let p=await Jc({agentId:r,workspace:i.workspace,framework:i.framework,skill:f});Zc(c,l,p),u.push(f)}return await us(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){wn(e._meta,"_agent/removeSkills");let r=br(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],l=[];for(let u of c){if(!o.has(u.skillId)){l.push(u);continue}let f=Dt(i.workspace,u.relPath);await S_(f,{recursive:!0,force:!0}),Ae.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await us(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 f=c.downstream;c.downstream=void 0,Ae.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l}),f.stop(r).catch(p=>Ae.warn("downstream stop failed during reload (ignored)",{reason:r,agentId:e,cloudId:o,err:String(p)}))}}isRuntimePendingPermission(e){let r=this.opts.isRuntimePendingPermission;return!r||!e.downstream?!1:r(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return Ae.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await Me(r);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Ae.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await sr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Ae.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new C("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Xe(i),Ae.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async upgradeBridge(e){let r=e.agentId||e._meta?.cozeAgentId;if(!r)throw new C("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await Me(r))throw new C("AGENT_NOT_FOUND",`agent not found: ${r}`);let o=["-y"];e.registry&&Ti(e.registry)&&o.push(`--registry=${e.registry}`);let c=L_(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let l=e._meta?.cozeEnv;l&&D_.test(l)&&o.push("--env",l);let u=await N_(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 C("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Me(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Xe(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(wn(e._meta,"_agent/switchModel"),!e.agentId)throw new C("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Uc(e.model)??yt,i=await Me(e.agentId);if(!i)throw new C("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Xe(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 f=o.sessions.get(l);f?.downstream&&(await f.downstream.stop(`switchModel: ${r}`).catch(()=>{}),f.downstream=void 0)}));return await Promise.all(c),Ae.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:r,cloudSessions:c.length}),{ok:!0}}async resetAgent(e){if(wn(e._meta,_t.RESET),!e.agentId)throw new C("IPC_BAD_REQUEST",`${_t.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,_t.RESET),await this.runDetailSync(e.agentId,_t.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),Ae.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(r);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,l]of i.sessions)o.set(c,{modelToken:l.modelToken,tokenGeneratedAt:l.tokenGeneratedAt});await ei(e,o)}async clearPersistedAcpSessionIds(e){let r=await Me(e).catch(()=>null);if(!r?.sessions)return;let i=!1;for(let o of Object.values(r.sessions))o.acpSessionId&&(o.acpSessionId=void 0,i=!0);i&&await Xe(r)}async repairAgent(e){if(wn(e._meta,_t.REPAIR),!e.agentId)throw new C("IPC_BAD_REQUEST",`${_t.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new C("IPC_BAD_REQUEST",`${_t.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){Ae.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,_t.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){Ae.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Ae.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){wn(e._meta,"_agent/getFileTree");let r=e._meta,i=br(r),o=await this.resolveWorkspace(i),c=e.filePath??"",l=this.safeJoin(o,c),u=await Hc(l).catch(()=>null);if(!u)throw new C("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await Qr(l,o))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let f=Y_(e.depth);return u.isDirectory()?{tree:await Z_(o,l,c,f)}:{tree:[{name:X_(c),path:Qf(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){wn(e._meta,"_agent/getFileContent");let r=br(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new C("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await Hc(o).catch(()=>null);if(!c||!c.isFile())throw new C("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new C("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await Qr(o,i))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Kf)throw new C("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Kf})`);let l=await $f(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 Me(e).catch(()=>null))?.workspace??Ye(e).workspace}safeJoin(e,r){let i=Kc(e,r||"."),o=Vc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${Vf}`))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return Me(e)}async requireAgentCfg(e){let r=await this.loadAgentCfg(e);if(!r)throw new C("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function M_(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new C("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new C("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function B_(t){return t==="claude-code"?Dt(".claude","skills"):Dt(".agents","skills")}var F_=3e4,z_=50*1024*1024,Sr=3e4;async function Jc(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new C("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,l=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!l)throw new C("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=M_(o.skillName),f=B_(i),p=Dt(f,u),m=Dt(r,p);if(await jc(m,{recursive:!0}),c){let A=Buffer.from(o.content,"utf8");ki(A.length),await Wc(Dt(m,"SKILL.md"),A,"utf8")}else{let A=await G_(o.downloadUrl);H_(A)?await $_(A,m):j_(A)?await W_(A,m):await Wc(Dt(m,"SKILL.md"),A.toString("utf8"),"utf8")}let b={skillId:o.skillId,skillName:o.skillName,relPath:p,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return Ae.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:p,source:c?"content":"downloadUrl"}),b}function Zc(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 U_(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function G_(t){if(!t)throw new C("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);ki(e);let r=q_(t);return ki(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await $f(e);return ki(r.length),r}if(Ti(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),F_);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new C("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return ki(o.byteLength),Buffer.from(o)}finally{clearTimeout(r)}}throw new C("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function ki(t){if(t>z_)throw new C("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function q_(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new C("IPC_BAD_REQUEST","bad data URL");let r=!!e[2],i=e[3]??"";return r?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function H_(t){return t.length>=2&&t[0]===31&&t[1]===139}function j_(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 $c(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function W_(t,e){let r,i;try{r=new Yf.default(t),i=r.getEntries()}catch(l){throw new C("IPC_BAD_REQUEST",`zip parse failed: ${l.message}`,{cause:l})}for(let l of i){let u=l.entryName;if(!u||$c(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new C("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(p=>p===".."))throw new C("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let f=l.header.attr>>>16&61440;if(f!==0&&f!==32768&&f!==16384)throw new C("IPC_BAD_REQUEST",`zip entry kind 0x${f.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=K_(i),c=Kc(e);for(let l of i){if($c(l.entryName))continue;let u=l.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let f=Kc(e,u),p=Vc(c,f);if(p.startsWith("..")||p==="..")throw new C("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(l.isDirectory){await jc(f,{recursive:!0});continue}await jc(I_(f),{recursive:!0});let m;try{m=l.getData()}catch(b){throw new C("IPC_BAD_REQUEST",`zip entry getData failed (${l.entryName}): ${b.message}`,{cause:b})}await Wc(f,m)}}function K_(t){let e;for(let r of t){let i=r.entryName;if(!i||$c(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 $_(t,e){await V_(t);let r=Sf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new C("IPC_BAD_REQUEST",`tar extract timeout (${Sr}ms)`))},Sr);try{await Zf(Jf.from(t),r)}catch(c){throw c instanceof C?c:i?new C("IPC_BAD_REQUEST",`tar extract timeout (${Sr}ms)`):new C("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function V_(t){let e=[],r=Er({onReadEntry:c=>{let l=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' not allowed (symlink/hardlink/special): ${l.slice(0,100)}`);return}if(l.startsWith("/")||l.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(l)){e.push(`tar entry absolute path: ${l}`);return}l.split(/[/\\]/).some(p=>p==="..")&&e.push(`tar entry contains '..': ${l}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new C("IPC_BAD_REQUEST",`tar list timeout (${Sr}ms)`))},Sr);try{await Zf(Jf.from(t),r)}catch(c){throw i?new C("IPC_BAD_REQUEST",`tar list timeout (${Sr}ms)`):new C("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new C("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var J_=5e3;async function Z_(t,e,r,i){return Xf(t,e,r,i,{count:0})}async function Xf(t,e,r,i,o){if(i<=0)return[];let c;try{c=await v_(e,{withFileTypes:!0})}catch{return[]}let l=[];for(let u of c){if(k_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=J_){l.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let f=Dt(e,u.name),p=T_(Dt(r,u.name)),m=null;try{m=await Hc(f)}catch{continue}if(m.isSymbolicLink())continue;o.count++;let b={name:u.name,path:Qf(Vc(t,f)),isDir:m.isDirectory(),size:m.size,modifiedAt:Math.floor(m.mtimeMs)};m.isDirectory()&&i>1&&(b.children=await Xf(t,f,p,i-1,o)),l.push(b)}return l.sort((u,f)=>u.isDir!==f.isDir?u.isDir?-1:1:u.name.localeCompare(f.name)),l}function Y_(t){return!t||t<=0?C_:Math.min(t,R_)}function X_(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function Qf(t){return t.split(Vf).join("/")}te();import{readFileSync as UI}from"node:fs";import{dirname as qI,join as HI}from"node:path";import{fileURLToPath as WI}from"node:url";var Ar="0.2.0-alpha.5";var _n=q("agent-health-reporter"),Q_=1e4,Di=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??Q_}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()}),_n.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),_n.info("heartbeat stopped"))}async tick(){if(this.inFlight){_n.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){_n.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=ey(l);if(!u)continue;let f={agentId:l.agentId,status:u};l.patToken&&(f.patToken=l.patToken),l.accountId&&(f.accountId=l.accountId),r.push(f)}if(r.length===0)return;let i={agents:r,bridgeVersion:Ar,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(l){_n.warn("heartbeat batch send failed",{count:r.length,err:String(l)})}let c=o?.authFailures;if(c&&c.length>0&&(_n.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){_n.warn("onAuthFailures callback failed (ignored)",{err:String(l)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){_n.warn("onTickEnd hook failed",{err:String(r)})}}};function ey(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}rn();import{chmod as Wy,mkdir as mo,rm as Ky,stat as $y,writeFile as Vy}from"node:fs/promises";import{homedir as Jy}from"node:os";import{join as T0}from"node:path";nn();import{existsSync as xy}from"node:fs";import{release as hy}from"node:os";import{basename as py,isAbsolute as gy}from"node:path";function Pi(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Ir(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Tr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function yn(t,e){return{jsonrpc:"2.0",id:t,error:e}}We();var co=class extends Error{code;data;constructor(e){super(`JSON-RPC error code=${e.code} ${e.message}`),this.name="RemoteRpcError",this.code=e.code,e.data!==void 0&&(this.data=e.data)}},Q={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32022};function e0(t){return"method"in t&&"id"in t&&t.id!==void 0}function t0(t){return"method"in t&&!("id"in t)}function lo(t){return!("method"in t)&&"id"in t}var ty={AGENT_NOT_FOUND:Q.AGENT_NOT_FOUND,AGENT_BUSY:Q.AGENT_BUSY,AGENT_DISCONNECTED:Q.AGENT_DISCONNECTED,AGENT_TIMEOUT:Q.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:Q.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:Q.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:Q.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:Q.INTERNAL_ERROR,BRIDGE_INTERNAL:Q.INTERNAL_ERROR,IPC_AUTH_FAILED:Q.INTERNAL_ERROR,IPC_BAD_REQUEST:Q.INVALID_REQUEST,METHOD_NOT_FOUND:Q.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:Q.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:Q.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:Q.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:Q.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:Q.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:Q.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:Q.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:Q.FILE_TOO_LARGE,UNSUPPORTED_MIME:Q.UNSUPPORTED_MIME,UPLOAD_FAILED:Q.UPLOAD_FAILED,UPSTREAM_NOT_READY:Q.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:Q.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:Q.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:Q.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:Q.AGENT_ENV_NOT_READY};function ny(t){if(t!=null)return t instanceof Error?{name:t.name,message:Oi(t.message)}:typeof t=="string"?Oi(t):typeof t=="object"?iy(t):t}var ry=[[/\/Users\/[^/\s'"`)]+/g,"/Users/<redacted>"],[/\/home\/[^/\s'"`)]+/g,"/home/<redacted>"],[/[A-Za-z]:\\Users\\[^\\\s'"`)]+/g,"C:\\Users\\<redacted>"],[/(Bearer|Token|Authorization:)\s+[\w._-]+/gi,"$1 <redacted>"],[/\b(sk|pat|ak)[-_][A-Za-z0-9_-]{20,}\b/g,"<redacted-key>"]];function Oi(t){let e=t;for(let[r,i]of ry)e=e.replace(r,i);return e}function iy(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Oi(i):e[r]=i;return e}function Li(t){if(t instanceof C){let e=ny(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:ty[t.code]??Q.INTERNAL_ERROR,message:Oi(t.message),data:r}}return{code:Q.INTERNAL_ERROR,message:Oi(t instanceof Error?t.message:String(t))}}function n0(t){let e=t.data,r=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:l,...u}=e;c=u}return new C(r,o,{retriable:e?.retriable??!1,cause:c})}function i0(t){return`${JSON.stringify(t)}
|
|
93
|
-
`}var
|
|
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
|
|
95
|
-
`).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function f0(t,e){if(t.length===0)return;let r=e?.killFn??Mi,i=e?.isAliveFn??Ni,o=e?.sleepFn??(u=>new Promise(f=>setTimeout(f,u))),c=e?.graceMs??3e3,l=e?.pollMs??100;for(let u of t)r(u,"SIGTERM");for(let u=0;u<c&&t.some(f=>i(f));u+=l)await o(Math.min(l,c-u));for(let u of t)i(u)&&r(u,"SIGKILL")}var fy=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: (Node binary not found|QCLAW_CLI_NODE_BINARY not set)/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @zed-industries\/codex-acp|optional dependency was not installed|\.resolve is not a function/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"acp_module_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code","codex"],match:/Cannot find module[^\n]*node_modules[\\/]@(agentclientprotocol[\\/]claude-agent-acp|zed-industries[\\/]codex-acp)/i,message:"ACP \u4F9D\u8D56\u672A\u6B63\u786E\u5B89\u88C5 (wrapper \u5165\u53E3\u7F3A\u5931)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u91CD\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"},{reason:"prompt_too_long",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code"],match:/Prompt is too long|bad request: failed to read body: length limit exceeded/i,message:"\u672C\u8F6E\u8F93\u5165\u8FC7\u957F\uFF0C\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u7CBE\u7B80\u8F93\u5165\u6216\u5F00\u542F\u65B0\u4F1A\u8BDD\u540E\u91CD\u8BD5"}];function x0(t,e){if(!e)return null;for(let r of fy)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function h0(t,e){return x0(t,e)}function p0(t,e){return x0(t,e)}function kr(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 g0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let p=t.suspendedMs+o,m=r-t.startedAt-p;return{action:"suspend",suspendedDeltaMs:o,rearmMs:kr(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:kr(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:kr(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:kr(c,!1,e)}}var m0=je("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),my=200,wy=40,_y=je("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),yy=je("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),Ey=je("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),by=je("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),vy=je("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Sy=je("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),w0=500;function Ay(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=w0?t:`${e.slice(0,w0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Iy(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 _0(t){try{return xy(t)}catch{return}}function Ty(t,e){return{platform:process.platform,osRelease:hy(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:gy(e.command)?_0(e.command):void 0,cwd:e.cwd,cwdExists:_0(e.cwd),envKeys:e.envKeys}}function Cy(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${py(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Pt=class{constructor(e){this.opts=e;this.log=q(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new uo({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Cr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new C("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=a0(process.env,this.opts.agentEnvFile??X().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=et(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,c0(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>my&&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,d0(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=Ty(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(r).length});this.log.error("child error",{err:String(o),diag:l}),this.failAllPending(new C("AGENT_SPAWN_FAILED",Cy(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()));Mi(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Mi(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:vy,phase2GateMs:_y,livenessWindowMs:yy,absoluteMaxMs:Ey,approvalMaxMs:Sy,suspendThresholdMs:by,...r};return this.call("session/prompt",e,m0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Ir("session/cancel",e))}setSessionMode(e){return this.call("session/set_mode",e)}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Tr(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(yn(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=m0,o){if(!this.child||this.stopped)return Promise.reject(new C("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),l=Pi(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,p)=>{let m={resolve:f,reject:p,timer:null,method:e,promptTimeout:null};if(o){let b=this.now(),A={cfg:o,startedAt:b,lastActivityAt:b,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:b,expectedIntervalMs:kr(0,!1,o),sessionId:u};m.promptTimeout=A;let y=()=>{let S={startedAt:A.startedAt,lastActivityAt:A.lastActivityAt,firstFrameSeen:A.firstFrameSeen,hasActiveTool:A.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:A.suspendedMs,armedAt:A.armedAt,expectedIntervalMs:A.expectedIntervalMs},I=this.now(),T=g0(S,A.cfg,I),R=D=>{A.armedAt=I,A.expectedIntervalMs=D,m.timer=setTimeout(y,D)};if(T.action==="suspend"){A.suspendedMs+=T.suspendedDeltaMs,A.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:T.suspendedDeltaMs,suspendedMs:A.suspendedMs,...A.sessionId?{sessionId:A.sessionId}:{}}),R(T.rearmMs);return}if(T.action==="continue"){R(T.rearmMs);return}this.pending.delete(c),T.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:T.awaitingApproval,...A.sessionId?{sessionId:A.sessionId}:{}}),p(T.awaitingApproval?new C("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${A.cfg.approvalMaxMs}ms`):new C("AGENT_TIMEOUT",`${e} timed out after ${A.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...A.sessionId?{sessionId:A.sessionId}:{}}),p(new C("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${A.cfg.livenessWindowMs}ms`)))};m.timer=setTimeout(y,A.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(m.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),p(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,m);try{this.writeFrame(l)}catch(b){m.timer&&clearTimeout(m.timer),this.pending.delete(c),p(b)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new C("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(i0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(lo(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new C("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:Ay(e.result)}),r.resolve(e.result));return}if(t0(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(e0(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(yn(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(yn(e.id,Li(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=n0(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=p0(this.framework,Iy(e));return i?new C(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):r}buildExitError(e,r){if(this.stopReason!==void 0)return new C("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(wy).join(`
|
|
96
|
-
`),o=h0(this.framework,i);return o?new C(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new C("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function Ry(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 fo=class extends Pt{framework="claude-code";constructor(e){let{command:r,args:i}=Yr("claude-code",e.command,e.args??[]),o={command:r,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o)}sanitizeEnv(e){return Ry(e)}};nn();import{mkdtempSync as ky,rmSync as Dy}from"node:fs";import{tmpdir as Py}from"node:os";import{join as Oy}from"node:path";var xo=class extends Pt{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=Yr("codex",e.command,i),l=e.isolateCodexHome?ky(Oy(Py(),"coze-bridge-codex-home-")):void 0,u=l?{...e.env??{},CODEX_HOME:l}:e.env,f={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(f),this.authMethodId=e.authMethodId,this.codexHomeDir=l}async initialize(e){let r=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),r}async stop(e){if(await super.stop(e),this.codexHomeDir)try{Dy(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};We();var Ly=3e4,Dr=class extends Pt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},Ly))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new C("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var y0=["default","acceptEdits","plan","auto","bypassPermissions"],E0=["read-only","auto","full-access"];function En(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return y0.includes(e);case"codex":return E0.includes(e);case"openclaw":return!1}}function ed(t){switch(t){case"claude-code":return y0.join("/");case"codex":return E0.join("/");case"openclaw":return""}}We();te();Oe();function td(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}nn();var bn=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 ho=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 bn,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)Bi(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 Bi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function Kt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Wt();te();import{constants as b0}from"node:fs";import{access as Ny}from"node:fs/promises";import{delimiter as My,join as By}from"node:path";var Et=q("framework-detector"),v0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},Fy=[".exe",".cmd",".bat",".ps1"],qn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??et,access:e.access??Ny}}async detect(e){let r=v0[e],i=await this.which(r);if(!i)return Et.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,l]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return l&&(u.defaultAgent=l),u}async detectAll(){let e=await Promise.all(Object.keys(v0).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(My).filter(Boolean),i=this.env.platform==="win32"?["",...Fy]:[""];for(let o of r)for(let c of i){let l=By(o,e+c);if(await this.isExecutable(l))return l}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?b0.F_OK:b0.X_OK;return await this.env.access(e,r),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let r=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!r)return Et.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return Et.warn("openclaw default agent probe: non-zero exit",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)}),null;let i=r.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return Et.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:r.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return Et.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(l=>l?.isDefault===!0);return c?!c.id||!c.workspace?(Et.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(Et.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return Et.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let r=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!r)return Et.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||Et.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let l=JSON.parse(c[0]);typeof l.gateway?.port=="number"&&(o.port=l.gateway.port),typeof l.service?.runtime?.status=="string"&&(o.runtime=l.service.runtime.status),!i&&typeof l.rpc?.error=="string"&&(o.detail=l.rpc.error)}catch(l){Et.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(l)})}return o}async probeVersion(e,r=[]){let i=await this.runProbe(e,[...r,"--version"]);return i&&(Uy(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,l,u=f=>{c||(c=!0,l&&clearTimeout(l),i(f))};try{let f=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});l=setTimeout(()=>{f.kill("SIGKILL"),u(null)},15e3),f.stdout?.on("data",p=>{o+=p.toString("utf8")}),f.on("error",()=>u(null)),f.on("close",p=>u({code:p,stdout:o}))}catch{u(null)}})}},zy=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function Uy(t){return t.replace(zy,"")}import{homedir as Gy}from"node:os";import{join as qy}from"node:path";Wt();Qn();We();Xr();te();async function I0(){let t=qy(Gy(),".openclaw/openclaw.json");return(await rr(t))?.gateway?.auth?.token??""}var S0=q("openclaw.config"),Hy=[0,5e3,5e3],jy=je("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),A0="models.providers.",po="agents.defaults.models",go=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new bn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??Hy,this.cliTimeoutMs=e.cliTimeoutMs??jy}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,S0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(l)})}}throw new C("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=et(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",l=!1,u=p=>{l||(l=!0,clearTimeout(f),p())};o.stderr?.on("data",p=>{c+=p.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",p=>u(()=>i(p))),o.on("close",p=>u(()=>{p===0?r():i(new Error(`exit ${p}: ${c.trim().slice(0,500)}`))}))})}async runCliTolerant(e,r){try{await this.runCli(e)}catch(i){let o=String(i);if(r.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,r){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",r])))}catch(i){S0.warn(`${e} failed (best-effort)`,{configPath:r,err:String(i)})}}ensureProvider(e,r){return this.queue.enqueue(()=>this.withRetry(`config set models.providers.${e}`,()=>this.runCli(["config","set",`${A0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${A0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${po}[${e}]`,()=>this.runCli(["config","set",po,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${po}[${e}]`,`${po}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var le=q("agent-manager"),rd="acceptEdits",k0="full-access",D0="read-only";function Zy(t){switch(t){case"read-only":return["-c",'sandbox_mode="read-only"',"-c",'approval_policy="on-request"'];case"auto":return["-c",'sandbox_mode="workspace-write"',"-c",'approval_policy="on-failure"'];case"full-access":return["-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"']}}var Yy=(t,e,r,i,o,c,l,u,f,p)=>{switch(t){case"claude-code":{let m={...o?{...Uf(o),...Hf(o,l,u)}:{},...f??{},IS_SANDBOX:"1"};return new fo({cwd:r,env:m,agentId:i})}case"codex":{let m=o?[...Gf(o),...Wf(o,l,u)]:[],b=k0;p!==void 0&&(En("codex",p)?b=p:le.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:p}));let A=[...m,...Zy(b)],y={...o?qf(o):{},...f??{}},S=!!o;return new xo({cwd:r,agentId:i,...A.length>0?{extraArgs:A}:{},...Object.keys(y).length>0?{env:y}:{},...S?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Dr({command:e,cwd:r,agentId:i,...c?{sessionName:td(c)}:{}})}};function nd(t){return t==="claude-code"||t==="codex"}function Xy(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(Qy(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
|
|
89
|
+
`},configPath(t){return E2(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 Xh("schtasks",["/Create","/SC","ONLOGON","/TN",sa,"/TR",r,"/RU",t.userName,"/F"]),jd.info("task scheduler entry created",{task:sa,logFile:t.logFile})},async uninstall(t){await Xh("schtasks",["/Delete","/TN",sa,"/F"]).catch(e=>jd.warn("schtasks /Delete failed (ignored)",{err:String(e)})),jd.info("task scheduler entry removed",{task:sa})}}});var ep={};_a(ep,{buildContext:()=>k2,getSupervisor:()=>I2,launchdSupervisor:()=>Gd,systemdSupervisor:()=>Hd,taskSchedulerSupervisor:()=>qd});import{homedir as v2,userInfo as S2}from"node:os";function I2(t=process.platform){switch(t){case"darwin":return Gd;case"linux":return Hd;case"win32":return qd;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function T2(){let t={};for(let e of A2){let r=process.env[e];r&&(t[e]=r)}return t}function k2(){let t=Q();return{nodeBin:process.execPath,entry:Pd(t),logFile:t.logFile,homeDir:v2(),userName:S2().username,isRoot:process.getuid?.()===0,env:T2()}}var A2,tp=Ze(()=>{"use strict";Pe();Vo();Jh();Zh();Qh();A2=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ne();rn();var bl=G("acp-installer-warmup"),kg=["claude-code","codex"];async function El(t={}){let e=t.ensure??rr,i=(await Promise.allSettled(kg.map(async o=>{let c=await e(o);bl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&bl.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))})}sn();ne();import{readdir as Gg}from"node:fs/promises";import{mkdir as kl,readFile as zg,writeFile as Cl}from"node:fs/promises";import{join as Aa}from"node:path";var Ug={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function or(t,e,r){await kl(t,{recursive:!0});let i=Ug[e],o=Aa(t,i);return await Cl(o,r??"","utf8"),o}async function Ta(t,e,r){let i=Aa(t,".claude");await kl(i,{recursive:!0});let o=Aa(i,"settings.local.json"),c={};try{let u=await zg(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 Cl(o,JSON.stringify(c,null,2),"utf8"),o}var Ve=G("agent-detail-sync"),Hg=6e4,jg=5*6e4,fs=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await Gg(r)}catch(o){Ve.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}Ve.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Me(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Ve.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(l){Ve.warn("detail sync failed for agent, skipping",{agentId:o,err:String(l)})}}})),Ve.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){Ve.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){Ve.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Me(e,this.opts.paths);if(!i){Ve.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){Ve.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,jg):Hg;this.retryQueue.set(e,{dueAt:Date.now()+m,currentDelay:m});return}if(o.agentId&&o.agentId!==e){Ve.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"?(Ve.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&Ve.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Ve.debug("detail sync: no diff",{agentId:e});return}await Qe(i,this.opts.paths),Ve.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}),Ve.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):l&&(await or(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var Yf=Ft(cu(),1);import{lstat as Gc,mkdir as Hc,readFile as Kf,readdir as v_,rm as S_,stat as I_,writeFile as jc}from"node:fs/promises";import{dirname as A_,join as Dt,normalize as T_,relative as Kc,resolve as qc,sep as $f}from"node:path";import{Readable as Vf}from"node:stream";import{pipeline as Jf}from"node:stream/promises";import um from"events";import et from"fs";import{EventEmitter as Ac}from"node:events";import ju from"node:stream";import{StringDecoder as fm}from"node:string_decoder";import Ku from"node:path";import wr from"node:fs";import{dirname as Im,parse as Am}from"path";import{EventEmitter as Lm}from"events";import ac from"assert";import{Buffer as zn}from"buffer";import*as xu from"zlib";import Nm from"zlib";import{posix as ur}from"node:path";import{basename as cw}from"node:path";import qs from"fs";import kt from"fs";import yu from"path";import{win32 as yw}from"node:path";import Tu from"path";import cf from"node:fs";import Bw from"node:assert";import{randomBytes as df}from"node:crypto";import re from"node:fs";import Le from"node:path";import lf from"fs";import Qs from"node:fs";import yi from"node:path";import st from"node:fs";import qw from"node:fs/promises";import $s from"node:path";import{join as bf}from"node:path";import it from"node:fs";import Sf from"node:path";var dm=Object.defineProperty,lm=(t,e)=>{for(var r in e)dm(t,r,{get:e[r],enumerable:!0})},du=typeof process=="object"&&process?process:{stdout:null,stderr:null},xm=t=>!!t&&typeof t=="object"&&(t instanceof Hn||t instanceof ju||hm(t)||pm(t)),hm=t=>!!t&&typeof t=="object"&&t instanceof Ac&&typeof t.pipe=="function"&&t.pipe!==ju.Writable.prototype.pipe,pm=t=>!!t&&typeof t=="object"&&t instanceof Ac&&typeof t.write=="function"&&typeof t.end=="function",zt=Symbol("EOF"),Ut=Symbol("maybeEmitEnd"),an=Symbol("emittedEnd"),ms=Symbol("emittingEnd"),ri=Symbol("emittedError"),ws=Symbol("closed"),lu=Symbol("read"),_s=Symbol("flush"),uu=Symbol("flushChunk"),ht=Symbol("encoding"),lr=Symbol("decoder"),Be=Symbol("flowing"),ii=Symbol("paused"),pr=Symbol("resume"),Fe=Symbol("buffer"),Je=Symbol("pipes"),ze=Symbol("bufferLength"),Oa=Symbol("bufferPush"),ys=Symbol("bufferShift"),$e=Symbol("objectMode"),Se=Symbol("destroyed"),La=Symbol("error"),Na=Symbol("emitData"),fu=Symbol("emitEnd"),Ma=Symbol("emitEnd2"),It=Symbol("async"),Ba=Symbol("abort"),bs=Symbol("aborted"),si=Symbol("signal"),Rn=Symbol("dataListeners"),rt=Symbol("discarded"),oi=t=>Promise.resolve().then(t),gm=t=>t(),mm=t=>t==="end"||t==="finish"||t==="prefinish",wm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,_m=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),qu=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[pr](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},ym=class extends qu{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,r){super(t,e,r),this.proxyErrors=i=>this.dest.emit("error",i),t.on("error",this.proxyErrors)}},bm=t=>!!t.objectMode,Em=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Hn=class extends Ac{[Be]=!1;[ii]=!1;[Je]=[];[Fe]=[];[$e];[ht];[It];[lr];[zt]=!1;[an]=!1;[ms]=!1;[ws]=!1;[ri]=null;[ze]=0;[Se]=!1;[si];[bs]=!1;[Rn]=0;[rt]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");bm(e)?(this[$e]=!0,this[ht]=null):Em(e)?(this[ht]=e.encoding,this[$e]=!1):(this[$e]=!1,this[ht]=null),this[It]=!!e.async,this[lr]=this[ht]?new fm(this[ht]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Fe]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Je]});let{signal:r}=e;r&&(this[si]=r,r.aborted?this[Ba]():r.addEventListener("abort",()=>this[Ba]()))}get bufferLength(){return this[ze]}get encoding(){return this[ht]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[$e]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[It]}set async(t){this[It]=this[It]||!!t}[Ba](){this[bs]=!0,this.emit("abort",this[si]?.reason),this.destroy(this[si]?.reason)}get aborted(){return this[bs]}set aborted(t){}write(t,e,r){if(this[bs])return!1;if(this[zt])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[It]?oi:gm;if(!this[$e]&&!Buffer.isBuffer(t)){if(_m(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(wm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[$e]?(this[Be]&&this[ze]!==0&&this[_s](!0),this[Be]?this.emit("data",t):this[Oa](t),this[ze]!==0&&this.emit("readable"),r&&i(r),this[Be]):t.length?(typeof t=="string"&&!(e===this[ht]&&!this[lr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[ht]&&(t=this[lr].write(t)),this[Be]&&this[ze]!==0&&this[_s](!0),this[Be]?this.emit("data",t):this[Oa](t),this[ze]!==0&&this.emit("readable"),r&&i(r),this[Be]):(this[ze]!==0&&this.emit("readable"),r&&i(r),this[Be])}read(t){if(this[Se])return null;if(this[rt]=!1,this[ze]===0||t===0||t&&t>this[ze])return this[Ut](),null;this[$e]&&(t=null),this[Fe].length>1&&!this[$e]&&(this[Fe]=[this[ht]?this[Fe].join(""):Buffer.concat(this[Fe],this[ze])]);let e=this[lu](t||null,this[Fe][0]);return this[Ut](),e}[lu](t,e){if(this[$e])this[ys]();else{let r=e;t===r.length||t===null?this[ys]():typeof r=="string"?(this[Fe][0]=r.slice(t),e=r.slice(0,t),this[ze]-=t):(this[Fe][0]=r.subarray(t),e=r.subarray(0,t),this[ze]-=t)}return this.emit("data",e),!this[Fe].length&&!this[zt]&&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[zt]=!0,this.writable=!1,(this[Be]||!this[ii])&&this[Ut](),this}[pr](){this[Se]||(!this[Rn]&&!this[Je].length&&(this[rt]=!0),this[ii]=!1,this[Be]=!0,this.emit("resume"),this[Fe].length?this[_s]():this[zt]?this[Ut]():this.emit("drain"))}resume(){return this[pr]()}pause(){this[Be]=!1,this[ii]=!0,this[rt]=!1}get destroyed(){return this[Se]}get flowing(){return this[Be]}get paused(){return this[ii]}[Oa](t){this[$e]?this[ze]+=1:this[ze]+=t.length,this[Fe].push(t)}[ys](){return this[$e]?this[ze]-=1:this[ze]-=this[Fe][0].length,this[Fe].shift()}[_s](t=!1){do;while(this[uu](this[ys]())&&this[Fe].length);!t&&!this[Fe].length&&!this[zt]&&this.emit("drain")}[uu](t){return this.emit("data",t),this[Be]}pipe(t,e){if(this[Se])return t;this[rt]=!1;let r=this[an];return e=e||{},t===du.stdout||t===du.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[Je].push(e.proxyErrors?new ym(this,t,e):new qu(this,t,e)),this[It]?oi(()=>this[pr]()):this[pr]()),t}unpipe(t){let e=this[Je].find(r=>r.dest===t);e&&(this[Je].length===1?(this[Be]&&this[Rn]===0&&(this[Be]=!1),this[Je]=[]):this[Je].splice(this[Je].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let r=super.on(t,e);if(t==="data")this[rt]=!1,this[Rn]++,!this[Je].length&&!this[Be]&&this[pr]();else if(t==="readable"&&this[ze]!==0)super.emit("readable");else if(mm(t)&&this[an])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[ri]){let i=e;this[It]?oi(()=>i.call(this,this[ri])):i.call(this,this[ri])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Rn]=this.listeners("data").length,this[Rn]===0&&!this[rt]&&!this[Je].length&&(this[Be]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Rn]=0,!this[rt]&&!this[Je].length&&(this[Be]=!1)),e}get emittedEnd(){return this[an]}[Ut](){!this[ms]&&!this[an]&&!this[Se]&&this[Fe].length===0&&this[zt]&&(this[ms]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[ws]&&this.emit("close"),this[ms]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Se&&this[Se])return!1;if(t==="data")return!this[$e]&&!r?!1:this[It]?(oi(()=>this[Na](r)),!0):this[Na](r);if(t==="end")return this[fu]();if(t==="close"){if(this[ws]=!0,!this[an]&&!this[Se])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[ri]=r,super.emit(La,r);let o=!this[si]||this.listeners("error").length?super.emit("error",r):!1;return this[Ut](),o}else if(t==="resume"){let o=super.emit("resume");return this[Ut](),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[Ut](),i}[Na](t){for(let r of this[Je])r.dest.write(t)===!1&&this.pause();let e=this[rt]?!1:super.emit("data",t);return this[Ut](),e}[fu](){return this[an]?!1:(this[an]=!0,this.readable=!1,this[It]?(oi(()=>this[Ma]()),!0):this[Ma]())}[Ma](){if(this[lr]){let e=this[lr].end();if(e){for(let r of this[Je])r.dest.write(e);this[rt]||super.emit("data",e)}}for(let e of this[Je])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[$e]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[$e]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[$e])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[ht]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Se,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[rt]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[zt])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[zt]})},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[rt]=!1;let t=!1,e=()=>(this.pause(),this.off(La,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(La,e),this.once(Se,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Se])return t?this.emit("error",t):this.emit(Se),this;this[Se]=!0,this[rt]=!0,this[Fe].length=0,this[ze]=0;let e=this;return typeof e.close=="function"&&!this[ws]&&e.close(),t?this.emit("error",t):this.emit(Se),this}static get isStream(){return xm}},vm=et.writev,mn=Symbol("_autoClose"),wt=Symbol("_close"),ai=Symbol("_ended"),de=Symbol("_fd"),Fa=Symbol("_finished"),qt=Symbol("_flags"),za=Symbol("_flush"),sc=Symbol("_handleChunk"),oc=Symbol("_makeBuf"),wi=Symbol("_mode"),Es=Symbol("_needDrain"),yr=Symbol("_onerror"),br=Symbol("_onopen"),Ua=Symbol("_onread"),gr=Symbol("_onwrite"),wn=Symbol("_open"),mt=Symbol("_path"),fn=Symbol("_pos"),At=Symbol("_queue"),mr=Symbol("_read"),Ga=Symbol("_readSize"),jt=Symbol("_reading"),ci=Symbol("_remain"),Ha=Symbol("_size"),Ps=Symbol("_write"),Dn=Symbol("_writing"),Os=Symbol("_defaultFlag"),Fn=Symbol("_errored"),Tc=class extends Hn{[Fn]=!1;[de];[mt];[Ga];[jt]=!1;[Ha];[ci];[mn];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[Fn]=!1,this[de]=typeof e.fd=="number"?e.fd:void 0,this[mt]=t,this[Ga]=e.readSize||16*1024*1024,this[jt]=!1,this[Ha]=typeof e.size=="number"?e.size:1/0,this[ci]=this[Ha],this[mn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[de]=="number"?this[mr]():this[wn]()}get fd(){return this[de]}get path(){return this[mt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[wn](){et.open(this[mt],"r",(t,e)=>this[br](t,e))}[br](t,e){t?this[yr](t):(this[de]=e,this.emit("open",e),this[mr]())}[oc](){return Buffer.allocUnsafe(Math.min(this[Ga],this[ci]))}[mr](){if(!this[jt]){this[jt]=!0;let t=this[oc]();if(t.length===0)return process.nextTick(()=>this[Ua](null,0,t));et.read(this[de],t,0,t.length,null,(e,r,i)=>this[Ua](e,r,i))}}[Ua](t,e,r){this[jt]=!1,t?this[yr](t):this[sc](e,r)&&this[mr]()}[wt](){if(this[mn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,et.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[yr](t){this[jt]=!0,this[wt](),this.emit("error",t)}[sc](t,e){let r=!1;return this[ci]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[ci]<=0)&&(r=!1,this[wt](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[de]=="number"&&this[mr](),!1;case"error":return this[Fn]?!1:(this[Fn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},Sm=class extends Tc{[wn](){let t=!0;try{this[br](null,et.openSync(this[mt],"r")),t=!1}finally{t&&this[wt]()}}[mr](){let t=!0;try{if(!this[jt]){this[jt]=!0;do{let e=this[oc](),r=e.length===0?0:et.readSync(this[de],e,0,e.length,null);if(!this[sc](r,e))break}while(!0);this[jt]=!1}t=!1}finally{t&&this[wt]()}}[wt](){if(this[mn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,et.closeSync(t),this.emit("close")}}},Vs=class extends um{readable=!1;writable=!0;[Fn]=!1;[Dn]=!1;[ai]=!1;[At]=[];[Es]=!1;[mt];[wi];[mn];[de];[Os];[qt];[Fa]=!1;[fn];constructor(t,e){e=e||{},super(e),this[mt]=t,this[de]=typeof e.fd=="number"?e.fd:void 0,this[wi]=e.mode===void 0?438:e.mode,this[fn]=typeof e.start=="number"?e.start:void 0,this[mn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[fn]!==void 0?"r+":"w";this[Os]=e.flags===void 0,this[qt]=e.flags===void 0?r:e.flags,this[de]===void 0&&this[wn]()}emit(t,...e){if(t==="error"){if(this[Fn])return!1;this[Fn]=!0}return super.emit(t,...e)}get fd(){return this[de]}get path(){return this[mt]}[yr](t){this[wt](),this[Dn]=!0,this.emit("error",t)}[wn](){et.open(this[mt],this[qt],this[wi],(t,e)=>this[br](t,e))}[br](t,e){this[Os]&&this[qt]==="r+"&&t&&t.code==="ENOENT"?(this[qt]="w",this[wn]()):t?this[yr](t):(this[de]=e,this.emit("open",e),this[Dn]||this[za]())}end(t,e){return t&&this.write(t,e),this[ai]=!0,!this[Dn]&&!this[At].length&&typeof this[de]=="number"&&this[gr](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[ai]?(this.emit("error",new Error("write() after end()")),!1):this[de]===void 0||this[Dn]||this[At].length?(this[At].push(t),this[Es]=!0,!1):(this[Dn]=!0,this[Ps](t),!0)}[Ps](t){et.write(this[de],t,0,t.length,this[fn],(e,r)=>this[gr](e,r))}[gr](t,e){t?this[yr](t):(this[fn]!==void 0&&typeof e=="number"&&(this[fn]+=e),this[At].length?this[za]():(this[Dn]=!1,this[ai]&&!this[Fa]?(this[Fa]=!0,this[wt](),this.emit("finish")):this[Es]&&(this[Es]=!1,this.emit("drain"))))}[za](){if(this[At].length===0)this[ai]&&this[gr](null,0);else if(this[At].length===1)this[Ps](this[At].pop());else{let t=this[At];this[At]=[],vm(this[de],t,this[fn],(e,r)=>this[gr](e,r))}}[wt](){if(this[mn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,et.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},Wu=class extends Vs{[wn](){let t;if(this[Os]&&this[qt]==="r+")try{t=et.openSync(this[mt],this[qt],this[wi])}catch(e){if(e?.code==="ENOENT")return this[qt]="w",this[wn]();throw e}else t=et.openSync(this[mt],this[qt],this[wi]);this[br](null,t)}[wt](){if(this[mn]&&typeof this[de]=="number"){let t=this[de];this[de]=void 0,et.closeSync(t),this.emit("close")}}[Ps](t){let e=!0;try{this[gr](null,et.writeSync(this[de],t,0,t.length,this[fn])),e=!1}finally{if(e)try{this[wt]()}catch{}}}},Tm=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,Cm=t=>!t.sync&&!!t.file,Rm=t=>!!t.sync&&!t.file,Dm=t=>!t.sync&&!t.file,Pm=t=>!!t.file,Om=t=>Tm.get(t)||t,kc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=Om(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Ti=(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=kc(c);if(o?.(x,l),km(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(x,l)}else if(Cm(x)){let h=e(x,l);return u?h.then(()=>u(),u):h}else if(Rm(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(x,l)}else if(Dm(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}),Mm=Nm.constants||{ZLIB_VERNUM:4736},Rt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},Mm)),Bm=zn.concat,hu=Object.getOwnPropertyDescriptor(zn,"concat"),Fm=t=>t,ja=hu?.writable===!0||hu?.set!==void 0?t=>{zn.concat=t?Fm:Bm}:t=>{},Un=Symbol("_superWrite"),vs=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"}},qa=Symbol("flushFlag"),Cc=class extends Hn{#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 xu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new xu[e](t)}catch(r){throw new vs(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 vs(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return ac(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(zn.alloc(0),{[qa]: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}[Un](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=zn.from(t,e)),this.#e)return;ac(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},ja(!0);let l;try{let x=typeof t[qa]=="number"?t[qa]:this.#r;l=this.#t._processChunk(t,x),ja(!1)}catch(x){ja(!1),this.#o(new vs(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 vs(x,this.write)));let u;if(l)if(Array.isArray(l)&&l.length>0){let x=l[0];u=this[Un](zn.from(x));for(let h=1;h<l.length;h++)u=this[Un](l[h])}else u=this[Un](zn.from(l));return r&&r(),u}},$u=class extends Cc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Rt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Rt.Z_FINISH,t.fullFlushFlag=Rt.Z_FULL_FLUSH,super(t,e),this.#e=t.level,this.#n=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==t||this.#n!==e){this.flush(Rt.Z_SYNC_FLUSH),ac(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)}}}},zm=class extends $u{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Un](t){return this.#e?(this.#e=!1,t[9]=255,super[Un](t)):super[Un](t)}},Um=class extends $u{constructor(t){super(t,"Unzip")}},Vu=class extends Cc{constructor(t,e){t=t||{},t.flush=t.flush||Rt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Rt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Rt.BROTLI_OPERATION_FLUSH,super(t,e)}},Gm=class extends Vu{constructor(t){super(t,"BrotliCompress")}},Hm=class extends Vu{constructor(t){super(t,"BrotliDecompress")}},Ju=class extends Cc{constructor(t,e){t=t||{},t.flush=t.flush||Rt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Rt.ZSTD_e_end,t.fullFlushFlag=Rt.ZSTD_e_flush,super(t,e)}},jm=class extends Ju{constructor(t){super(t,"ZstdCompress")}},qm=class extends Ju{constructor(t){super(t,"ZstdDecompress")}},Wm=(t,e)=>{if(Number.isSafeInteger(t))t<0?$m(t,e):Km(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Km=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},$m=(t,e)=>{e[0]=255;var r=!1;t=t*-1;for(var i=e.length;i>1;i--){var o=t&255;t=Math.floor(t/256),r?e[i-1]=Yu(o):o===0?e[i-1]=0:(r=!0,e[i-1]=Zu(o))}},Vm=t=>{let e=t[0],r=e===128?Ym(t.subarray(1,t.length)):e===255?Jm(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},Jm=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),l;i?l=Yu(c):c===0?l=c:(i=!0,l=Zu(c)),l!==0&&(r-=l*Math.pow(256,e-o-1))}return r},Ym=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},Yu=t=>(255^t)&255,Zu=t=>(255^t)+1&255,Zm={};lm(Zm,{code:()=>Rc,isCode:()=>Ls,isName:()=>Xm,name:()=>Js,normalFsTypes:()=>Xu});var Ls=t=>Js.has(t),Xm=t=>Rc.has(t),Xu=new Set(["0","","1","2","3","4","5","6","7","D"]),Js=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),Rc=new Map(Array.from(Js).map(t=>[t[1],t[0]])),Gn=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=Pn(t,e+156,1),c=Xu.has(o),l=c?r:void 0,u=c?i:void 0;if(this.path=l?.path??Pn(t,e,100),this.mode=l?.mode??u?.mode??xn(t,e+100,8),this.uid=l?.uid??u?.uid??xn(t,e+108,8),this.gid=l?.gid??u?.gid??xn(t,e+116,8),this.size=l?.size??u?.size??xn(t,e+124,12),this.mtime=l?.mtime??u?.mtime??Wa(t,e+136,12),this.cksum=xn(t,e+148,12),u&&this.#n(u,!0),l&&this.#n(l),Ls(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Pn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=l?.uname??u?.uname??Pn(t,e+265,32),this.gname=l?.gname??u?.gname??Pn(t,e+297,32),this.devmaj=l?.devmaj??u?.devmaj??xn(t,e+329,8)??0,this.devmin=l?.devmin??u?.devmin??xn(t,e+337,8)??0,t[e+475]!==0){let h=Pn(t,e+345,155);this.path=h+"/"+this.path}else{let h=Pn(t,e+345,130);h&&(this.path=h+"/"+this.path),this.atime=r?.atime??i?.atime??Wa(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Wa(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=Qm(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=On(t,e,100,o)||this.needPax,this.needPax=hn(t,e+100,8,this.mode)||this.needPax,this.needPax=hn(t,e+108,8,this.uid)||this.needPax,this.needPax=hn(t,e+116,8,this.gid)||this.needPax,this.needPax=hn(t,e+124,12,this.size)||this.needPax,this.needPax=Ka(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=On(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=On(t,e+265,32,this.uname)||this.needPax,this.needPax=On(t,e+297,32,this.gname)||this.needPax,this.needPax=hn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=hn(t,e+337,8,this.devmin)||this.needPax,this.needPax=On(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=On(t,e+345,155,c)||this.needPax:(this.needPax=On(t,e+345,130,c)||this.needPax,this.needPax=Ka(t,e+476,12,this.atime)||this.needPax,this.needPax=Ka(t,e+488,12,this.ctime)||this.needPax);let l=256;for(let u=e;u<e+148;u++)l+=t[u];for(let u=e+156;u<e+512;u++)l+=t[u];return this.cksum=l,hn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:Js.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Rc.get(t));if(Ls(e)||e==="Unsupported")this.#e=e;else if(Ls(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Qm=(t,e)=>{let r=t,i="",o,c=ur.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=ur.dirname(r),r=ur.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=ur.join(ur.basename(i),r),i=ur.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Pn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Wa=(t,e,r)=>ew(xn(t,e,r)),ew=t=>t===void 0?void 0:new Date(t*1e3),xn=(t,e,r)=>Number(t[e])&128?Vm(t.subarray(e,e+r)):nw(t,e,r),tw=t=>isNaN(t)?void 0:t,nw=(t,e,r)=>tw(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),rw={12:8589934591,8:2097151},hn=(t,e,r,i)=>i===void 0?!1:i>rw[r]||i<0?(Wm(i,t.subarray(e,e+r)),!0):(iw(t,e,r,i),!1),iw=(t,e,r,i)=>t.write(sw(i,r),e,r,"ascii"),sw=(t,e)=>ow(Math.floor(t).toString(8),e),ow=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Ka=(t,e,r,i)=>i===void 0?!1:hn(t,e,r,i.getTime()/1e3),aw=new Array(156).join("\0"),On=(t,e,r,i)=>i===void 0?!1:(t.write(i+aw,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),js=class Qu{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,r=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=r,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return Buffer.allocUnsafe(0);let r=Buffer.byteLength(e),i=512*Math.ceil(1+r/512),o=Buffer.allocUnsafe(i);for(let c=0;c<512;c++)o[c]=0;new Gn({path:("PaxHeader/"+cw(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 Qu(dw(lw(e),r),i)}},dw=(t,e)=>e?Object.assign({},e,t):t,lw=t=>t.replace(/\n$/,"").split(`
|
|
91
|
+
`).reduce(uw,Object.create(null)),uw=(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},fw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,X=fw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),xw=class extends Hn{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))))}},Ys=(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))},hw=1024*1024,cc=Buffer.from([31,139]),dc=Buffer.from([40,181,47,253]),pw=Math.max(cc.length,dc.length),ct=Symbol("state"),Ln=Symbol("writeEntry"),Gt=Symbol("readEntry"),$a=Symbol("nextEntry"),pu=Symbol("processEntry"),Tt=Symbol("extendedHeader"),di=Symbol("globalExtendedHeader"),cn=Symbol("meta"),gu=Symbol("emitMeta"),pe=Symbol("buffer"),Ht=Symbol("queue"),dn=Symbol("ended"),Va=Symbol("emittedEnd"),Nn=Symbol("emit"),ke=Symbol("unzip"),Ss=Symbol("consumeChunk"),Is=Symbol("consumeChunkSub"),Ja=Symbol("consumeBody"),mu=Symbol("consumeMeta"),wu=Symbol("consumeHeader"),li=Symbol("consuming"),Ya=Symbol("bufferConcat"),As=Symbol("maybeEnd"),fr=Symbol("writing"),ln=Symbol("aborted"),Ts=Symbol("onDone"),Mn=Symbol("sawValidEntry"),ks=Symbol("sawNullBlock"),Cs=Symbol("sawEOF"),_u=Symbol("closeStream"),gw=()=>!0,Ai=class extends Lm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Ht]=[];[pe];[Gt];[Ln];[ct]="begin";[cn]="";[Tt];[di];[dn]=!1;[ke];[ln]=!1;[Mn];[ks]=!1;[Cs]=!1;[fr]=!1;[li]=!1;[Va]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Ts,()=>{(this[ct]==="begin"||this[Mn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Ts,t.ondone):this.on(Ts,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||hw,this.filter=typeof t.filter=="function"?t.filter:gw;let e=t.file&&(t.file.endsWith(".tar.br")||t.file.endsWith(".tbr"));this.brotli=!(t.gzip||t.zstd)&&t.brotli!==void 0?t.brotli:e?void 0:!1;let r=t.file&&(t.file.endsWith(".tar.zst")||t.file.endsWith(".tzst"));this.zstd=!(t.gzip||t.brotli)&&t.zstd!==void 0?t.zstd:r?!0:void 0,this.on("end",()=>this[_u]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){Ys(this,t,e,r)}[wu](t,e){this[Mn]===void 0&&(this[Mn]=!1);let r;try{r=new Gn(t,e,this[Tt],this[di])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[ks]?(this[Cs]=!0,this[ct]==="begin"&&(this[ct]="header"),this[Nn]("eof")):(this[ks]=!0,this[Nn]("nullBlock"));else if(this[ks]=!1,!r.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:r});else if(!r.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:r});else{let i=r.type;if(/^(Symbolic)?Link$/.test(i)&&!r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:r});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:r});else{let o=this[Ln]=new xw(r,this[Tt],this[di]);if(!this[Mn])if(o.remain){let c=()=>{o.invalid||(this[Mn]=!0)};o.on("end",c)}else this[Mn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Nn]("ignoredEntry",o),this[ct]="ignore",o.resume()):o.size>0&&(this[cn]="",o.on("data",c=>this[cn]+=c),this[ct]="meta"):(this[Tt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Nn]("ignoredEntry",o),this[ct]=o.remain?"ignore":"header",o.resume()):(o.remain?this[ct]="body":(this[ct]="header",o.end()),this[Gt]?this[Ht].push(o):(this[Ht].push(o),this[$a]())))}}}[_u](){queueMicrotask(()=>this.emit("close"))}[pu](t){let e=!0;if(!t)this[Gt]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[Gt]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[$a]()),e=!1);return e}[$a](){do;while(this[pu](this[Ht].shift()));if(this[Ht].length===0){let t=this[Gt];!t||t.flowing||t.size===t.remain?this[fr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[Ja](t,e){let r=this[Ln];if(!r)throw new Error("attempt to consume body without entry??");let i=r.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return r.write(o),r.blockRemain||(this[ct]="header",this[Ln]=void 0,r.end()),o.length}[mu](t,e){let r=this[Ln],i=this[Ja](t,e);return!this[Ln]&&r&&this[gu](r),i}[Nn](t,e,r){this[Ht].length===0&&!this[Gt]?this.emit(t,e,r):this[Ht].push([t,e,r])}[gu](t){switch(this[Nn]("meta",this[cn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Tt]=js.parse(this[cn],this[Tt],!1);break;case"GlobalExtendedHeader":this[di]=js.parse(this[cn],this[di],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Tt]??Object.create(null);this[Tt]=e,e.path=this[cn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Tt]||Object.create(null);this[Tt]=e,e.linkpath=this[cn].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[ln]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[ln])return r?.(),!1;if((this[ke]===void 0||this.brotli===void 0&&this[ke]===!1)&&t){if(this[pe]&&(t=Buffer.concat([this[pe],t]),this[pe]=void 0),t.length<pw)return this[pe]=t,r?.(),!0;for(let l=0;this[ke]===void 0&&l<cc.length;l++)t[l]!==cc[l]&&(this[ke]=!1);let o=!1;if(this[ke]===!1&&this.zstd!==!1){o=!0;for(let l=0;l<dc.length;l++)if(t[l]!==dc[l]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[ke]===!1&&c)if(t.length<512)if(this[dn])this.brotli=!0;else return this[pe]=t,r?.(),!0;else try{new Gn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[ke]===void 0||this[ke]===!1&&(this.brotli||o)){let l=this[dn];this[dn]=!1,this[ke]=this[ke]===void 0?new Um({}):o?new qm({}):new Hm({}),this[ke].on("data",x=>this[Ss](x)),this[ke].on("error",x=>this.abort(x)),this[ke].on("end",()=>{this[dn]=!0,this[Ss]()}),this[fr]=!0;let u=!!this[ke][l?"end":"write"](t);return this[fr]=!1,r?.(),u}}this[fr]=!0,this[ke]?this[ke].write(t):this[Ss](t),this[fr]=!1;let i=this[Ht].length>0?!1:this[Gt]?this[Gt].flowing:!0;return!i&&this[Ht].length===0&&this[Gt]?.once("drain",()=>this.emit("drain")),r?.(),i}[Ya](t){t&&!this[ln]&&(this[pe]=this[pe]?Buffer.concat([this[pe],t]):t)}[As](){if(this[dn]&&!this[Va]&&!this[ln]&&!this[li]){this[Va]=!0;let t=this[Ln];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[Nn](Ts)}}[Ss](t){if(this[li]&&t)this[Ya](t);else if(!t&&!this[pe])this[As]();else if(t){if(this[li]=!0,this[pe]){this[Ya](t);let e=this[pe];this[pe]=void 0,this[Is](e)}else this[Is](t);for(;this[pe]&&this[pe]?.length>=512&&!this[ln]&&!this[Cs];){let e=this[pe];this[pe]=void 0,this[Is](e)}this[li]=!1}(!this[pe]||this[dn])&&this[As]()}[Is](t){let e=0,r=t.length;for(;e+512<=r&&!this[ln]&&!this[Cs];)switch(this[ct]){case"begin":case"header":this[wu](t,e),e+=512;break;case"ignore":case"body":e+=this[Ja](t,e);break;case"meta":e+=this[mu](t,e);break;default:throw new Error("invalid state: "+this[ct])}e<r&&(this[pe]=this[pe]?Buffer.concat([t.subarray(e),this[pe]]):t.subarray(e))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),r&&this.once("finish",r),this[ln]||(this[ke]?(t&&this[ke].write(t),this[ke].end()):(this[dn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[As]())),this}},_i=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)},mw=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},ef=(t,e)=>{let r=new Map(e.map(c=>[_i(c),!0])),i=t.filter,o=(c,l="")=>{let u=l||Am(c).root||".",x;if(c===u)x=!1;else{let h=r.get(c);x=h!==void 0?h:o(Im(c),u)}return r.set(c,x),x};t.filter=i?(c,l)=>i(c,l)&&o(_i(c)):c=>o(_i(c))},ww=t=>{let e=new Ai(t),r=t.file,i;try{i=wr.openSync(r,"r");let o=wr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let l=Buffer.allocUnsafe(o.size),u=wr.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=wr.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{wr.closeSync(i)}catch{}}},_w=(t,e)=>{let r=new Ai(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("end",c),wr.stat(o,(u,x)=>{if(u)l(u);else{let h=new Tc(o,{readSize:i,size:x.size});h.on("error",l),h.pipe(r)}})})},Er=Ti(ww,_w,t=>new Ai(t),t=>new Ai(t),(t,e)=>{e?.length&&ef(t,e),t.noResume||mw(t)}),tf=(t,e,r)=>(t&=4095,r&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t),{isAbsolute:bw,parse:bu}=yw,Dc=t=>{let e="",r=bu(t);for(;bw(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=bu(t)}return[e,t]},Zs=["|","<",">","?",":"],Pc=Zs.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),Ew=new Map(Zs.map((t,e)=>[t,Pc[e]])),vw=new Map(Pc.map((t,e)=>[t,Zs[e]])),Eu=t=>Zs.reduce((e,r)=>e.split(r).join(Ew.get(r)),t),Sw=t=>Pc.reduce((e,r)=>e.split(r).join(vw.get(r)),t),nf=(t,e)=>e?(t=X(t).replace(/^\.(\/|$)/,""),_i(e)+"/"+t):X(t),Iw=16*1024*1024,vu=Symbol("process"),Su=Symbol("file"),Iu=Symbol("directory"),lc=Symbol("symlink"),Au=Symbol("hardlink"),ui=Symbol("header"),Ns=Symbol("read"),uc=Symbol("lstat"),Ms=Symbol("onlstat"),fc=Symbol("onread"),xc=Symbol("onreadlink"),hc=Symbol("openfile"),pc=Symbol("onopenfile"),pn=Symbol("close"),Ws=Symbol("mode"),gc=Symbol("awaitDrain"),Za=Symbol("ondrain"),Ct=Symbol("prefix"),rf=class extends Hn{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=kc(e);super(),this.path=X(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||Iw,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=X(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?X(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,l]=Dc(this.path);c&&typeof l=="string"&&(this.path=l,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=Sw(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=X(r.absolute||yu.resolve(this.cwd,t)),this.path===""&&(this.path="./"),i&&this.warn("TAR_ENTRY_INFO",`stripping ${i} from absolute path`,{entry:this,path:i+this.path});let o=this.statCache.get(this.absolute);o?this[Ms](o):this[uc]()}warn(t,e,r={}){return Ys(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[uc](){kt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Ms](e)})}[Ms](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=kw(t),this.emit("stat",t),this[vu]()}[vu](){switch(this.type){case"File":return this[Su]();case"Directory":return this[Iu]();case"SymbolicLink":return this[lc]();default:return this.end()}}[Ws](t){return tf(t,this.type==="Directory",this.portable)}[Ct](t){return nf(t,this.prefix)}[ui](){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 Gn({path:this[Ct](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ct](this.linkpath):this.linkpath,mode:this[Ws](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 js({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)}[Iu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[ui](),this.end()}[lc](){kt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[xc](e)})}[xc](t){this.linkpath=X(t),this[ui](),this.end()}[Au](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=X(yu.relative(this.cwd,t)),this.stat.size=0,this[ui](),this.end()}[Su](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){let t=`${this.stat.dev}:${this.stat.ino}`,e=this.linkCache.get(t);if(e?.indexOf(this.cwd)===0)return this[Au](e);this.linkCache.set(t,this.absolute)}if(this[ui](),this.stat.size===0)return this.end();this[hc]()}[hc](){kt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[pc](e)})}[pc](t){if(this.fd=t,this.#e)return this[pn]();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[Ns]()}[Ns](){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[pn](()=>this.emit("error",c));this[fc](l)})}[pn](t=()=>{}){this.fd!==void 0&&kt.close(this.fd,t)}[fc](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[pn](()=>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[pn](()=>this.emit("error",r))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let r=t;r<this.length&&t<this.blockRemain;r++)this.buf[r+this.offset]=0,t++,this.remain++;let e=this.offset===0&&t===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+t);this.write(e)?this[Za]():this[gc](()=>this[Za]())}[gc](t){this.once("drain",t)}write(t,e,r){if(typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this.blockRemain<t.length){let i=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",i)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,r)}[Za](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[pn](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[Ns]()}},Aw=class extends rf{sync=!0;[uc](){this[Ms](kt.lstatSync(this.absolute))}[lc](){this[xc](kt.readlinkSync(this.absolute))}[hc](){this[pc](kt.openSync(this.absolute,"r"))}[Ns](){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[fc](l),t=!1}finally{if(t)try{this[pn](()=>{})}catch{}}}[gc](t){t()}[pn](t=()=>{}){this.fd!==void 0&&kt.closeSync(this.fd),t()}},Tw=class extends Hn{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 Ys(this,t,e,r)}constructor(t,e={}){let r=kc(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[Ws](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?X(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[l,u]=Dc(this.path);l&&typeof u=="string"&&(this.path=u,o=l)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Gn({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 js({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 nf(t,this.prefix)}[Ws](t){return tf(t,this.type==="Directory",this.portable)}write(t,e,r){typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8"));let i=t.length;if(i>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=i,super.write(t,r)}end(t,e,r){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e??"utf8")),r&&this.once("finish",r),t?super.end(t,r):super.end(r),this}},kw=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",Cw=class _r{tail;head;length=0;static create(e=[]){return new _r(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++)Dw(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)Pw(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 _r;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 _r;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 _r;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 _r;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=Rw(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 Rw(t,e,r){let i=e,o=e?e.next:t.head,c=new Oc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function Dw(t,e){t.tail=new Oc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function Pw(t,e){t.head=new Oc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Oc=class{list;next;prev;value;constructor(t,e,r,i){this.list=i,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,r?(r.prev=this,this.next=r):this.next=void 0}},ku=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Cu=Buffer.alloc(1024),Bs=Symbol("onStat"),fi=Symbol("ended"),pt=Symbol("queue"),xi=Symbol("pendingLinks"),un=Symbol("current"),Bn=Symbol("process"),hi=Symbol("processing"),Rs=Symbol("processJob"),gt=Symbol("jobs"),Xa=Symbol("jobDone"),Fs=Symbol("addFSEntry"),Ru=Symbol("addTarEntry"),mc=Symbol("stat"),wc=Symbol("readdir"),zs=Symbol("onreaddir"),Us=Symbol("pipe"),Du=Symbol("entry"),Qa=Symbol("entryOpt"),Gs=Symbol("writeEntryClass"),sf=Symbol("write"),ec=Symbol("ondrain"),Xs=class extends Hn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Gs];onWriteEntry;[pt];[xi]=new Map;[gt]=0;[hi]=!1;[fi]=!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[Gs]=rf,typeof t.onwarn=="function"&&this.on("warn",t.onwarn),this.portable=!!t.portable,t.gzip||t.brotli||t.zstd){if((t.gzip?1:0)+(t.brotli?1:0)+(t.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(t.gzip&&(typeof t.gzip!="object"&&(t.gzip={}),this.portable&&(t.gzip.portable=!0),this.zip=new zm(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new Gm(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new jm(t.zstd)),!this.zip)throw new Error("impossible");let e=this.zip;e.on("data",r=>super.write(r)),e.on("end",()=>super.end()),e.on("drain",()=>this[ec]()),this.on("resume",()=>e.resume())}else this.on("drain",this[ec]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter=typeof t.filter=="function"?t.filter:()=>!0,this[pt]=new Cw,this[gt]=0,this.jobs=Number(t.jobs)||4,this[hi]=!1,this[fi]=!1}[sf](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&this.add(t),this[fi]=!0,this[Bn](),r&&r(),this}write(t){if(this[fi])throw new Error("write after end");return typeof t=="string"?this[Fs](t):this[Ru](t),this.flowing}[Ru](t){let e=X(Tu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new ku(t.path,e);r.entry=new Tw(t,this[Qa](r)),r.entry.on("end",()=>this[Xa](r)),this[gt]+=1,this[pt].push(r)}this[Bn]()}[Fs](t){let e=X(Tu.resolve(this.cwd,t));this[pt].push(new ku(t,e)),this[Bn]()}[mc](t){t.pending=!0,this[gt]+=1;let e=this.follow?"stat":"lstat";qs[e](t.absolute,(r,i)=>{t.pending=!1,this[gt]-=1,r?this.emit("error",r):this[Bs](t,i)})}[Bs](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[un])this[Rs](t);else{let r=`${e.dev}:${e.ino}`,i=this[xi].get(r);i?i.push(t):this[xi].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Bn]()}[wc](t){t.pending=!0,this[gt]+=1,qs.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[gt]-=1,e)return this.emit("error",e);this[zs](t,r)})}[zs](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Bn]()}[Bn](){if(!this[hi]){this[hi]=!0;for(let t=this[pt].head;t&&this[gt]<this.jobs;t=t.next)if(this[Rs](t.value),t.value.ignore){let e=t.next;this[pt].removeNode(t),t.next=e}this[hi]=!1,this[fi]&&this[pt].length===0&&this[gt]===0&&(this.zip?this.zip.end(Cu):(super.write(Cu),super.end()))}}get[un](){return this[pt]&&this[pt].head&&this[pt].head.value}[Xa](t){this[pt].shift(),this[gt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[xi].get(r);if(i){this[xi].delete(r);for(let o of i)o.pending=!1,this[Rs](o)}}this[Bn]()}[Rs](t){if(t.pending&&t.pendingLink&&t===this[un]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[un]&&!t.piped&&this[Us](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Bs](t,e):this[mc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[zs](t,e):this[wc](t),!t.readdir)return}if(t.entry=this[Du](t),!t.entry){t.ignore=!0;return}t===this[un]&&!t.piped&&this[Us](t)}}}[Qa](t){return{onwarn:(e,r,i)=>this.warn(e,r,i),noPax:this.noPax,cwd:this.cwd,absolute:t.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[Du](t){this[gt]+=1;try{return new this[Gs](t.path,this[Qa](t)).on("end",()=>this[Xa](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[ec](){this[un]&&this[un].entry&&this[un].entry.resume()}[Us](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Fs](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={}){Ys(this,t,e,r)}},Lc=class extends Xs{sync=!0;constructor(t){super(t),this[Gs]=Aw}pause(){}resume(){}[mc](t){let e=this.follow?"statSync":"lstatSync";this[Bs](t,qs[e](t.absolute))}[wc](t){this[zs](t,qs.readdirSync(t.absolute))}[Us](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Fs](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[sf](i)})}},Ow=(t,e)=>{let r=new Lc(t),i=new Wu(t.file,{mode:t.mode||438});r.pipe(i),of(r,e)},Lw=(t,e)=>{let r=new Xs(t),i=new Vs(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 af(r,e).catch(c=>r.emit("error",c)),o},of=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Er({file:Ku.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},af=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Er({file:Ku.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},Nw=(t,e)=>{let r=new Lc(t);return of(r,e),r},Mw=(t,e)=>{let r=new Xs(t);return af(r,e).catch(i=>r.emit("error",i)),r},lI=Ti(Ow,Lw,Nw,Mw,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),Fw=process.env.__FAKE_PLATFORM__||process.platform,uf=Fw==="win32",{O_CREAT:ff,O_NOFOLLOW:Pu,O_TRUNC:xf,O_WRONLY:hf}=lf.constants,pf=Number(process.env.__FAKE_FS_O_FILENAME__)||lf.constants.UV_FS_O_FILEMAP||0,zw=uf&&!!pf,Uw=512*1024,Gw=pf|xf|ff|hf,Ou=!uf&&typeof Pu=="number"?Pu|xf|ff|hf:null,gf=Ou!==null?()=>Ou:zw?t=>t<Uw?Gw:"w":()=>"w",_c=(t,e,r)=>{try{return Qs.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},Ks=(t,e,r,i)=>{Qs.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},Hw=(t,e,r,i,o)=>{if(e.isDirectory())mf(yi.resolve(t,e.name),r,i,c=>{if(c)return o(c);let l=yi.resolve(t,e.name);Ks(l,r,i,o)});else{let c=yi.resolve(t,e.name);Ks(c,r,i,o)}},mf=(t,e,r,i)=>{Qs.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 Ks(t,e,r,i);let l=c.length,u=null,x=h=>{if(!u){if(h)return i(u=h);if(--l===0)return Ks(t,e,r,i)}};for(let h of c)Hw(t,h,e,r,x)})},jw=(t,e,r,i)=>{e.isDirectory()&&wf(yi.resolve(t,e.name),r,i),_c(yi.resolve(t,e.name),r,i)},wf=(t,e,r)=>{let i;try{i=Qs.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return _c(t,e,r);throw c}for(let o of i)jw(t,o,e,r);return _c(t,e,r)},_f=class extends Error{path;code;syscall="chdir";constructor(t,e){super(`${e}: Cannot cd into '${t}'`),this.path=t,this.code=e}get name(){return"CwdError"}},eo=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"}},Ww=(t,e)=>{st.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new _f(t,r?.code||"ENOTDIR")),e(r)})},Kw=(t,e,r)=>{t=X(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,l=e.uid,u=e.gid,x=typeof l=="number"&&typeof u=="number"&&(l!==e.processUid||u!==e.processGid),h=e.preserve,m=e.unlink,E=X(e.cwd),I=(v,A)=>{v?r(v):A&&x?mf(A,l,u,T=>I(T)):c?st.chmod(t,o,r):r()};if(t===E)return Ww(t,I);if(h)return qw.mkdir(t,{mode:o,recursive:!0}).then(v=>I(null,v??void 0),I);let y=X($s.relative(E,t)).split("/");yc(E,y,o,m,E,void 0,I)},yc=(t,e,r,i,o,c,l)=>{if(e.length===0)return l(null,c);let u=e.shift(),x=X($s.resolve(t+"/"+u));st.mkdir(x,r,yf(x,e,r,i,o,c,l))},yf=(t,e,r,i,o,c,l)=>u=>{u?st.lstat(t,(x,h)=>{if(x)x.path=x.path&&X(x.path),l(x);else if(h.isDirectory())yc(t,e,r,i,o,c,l);else if(i)st.unlink(t,m=>{if(m)return l(m);st.mkdir(t,r,yf(t,e,r,i,o,c,l))});else{if(h.isSymbolicLink())return l(new eo(t,t+"/"+e.join("/")));l(u)}}):(c=c||t,yc(t,e,r,i,o,c,l))},$w=t=>{let e=!1,r;try{e=st.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new _f(t,r??"ENOTDIR")}},Vw=(t,e)=>{t=X(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,l=e.gid,u=typeof c=="number"&&typeof l=="number"&&(c!==e.processUid||l!==e.processGid),x=e.preserve,h=e.unlink,m=X(e.cwd),E=v=>{v&&u&&wf(v,c,l),o&&st.chmodSync(t,i)};if(t===m)return $w(m),E();if(x)return E(st.mkdirSync(t,{mode:i,recursive:!0})??void 0);let I=X($s.relative(m,t)).split("/"),y;for(let v=I.shift(),A=m;v&&(A+="/"+v);v=I.shift()){A=X($s.resolve(A));try{st.mkdirSync(A,i),y=y||A}catch{let T=st.lstatSync(A);if(T.isDirectory())continue;if(h){st.unlinkSync(A),st.mkdirSync(A,i),y=y||A;continue}else if(T.isSymbolicLink())return new eo(A,A+"/"+I.join("/"))}}return E(y)},tc=Object.create(null),Lu=1e4,xr=new Set,Jw=t=>{xr.has(t)?xr.delete(t):tc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),xr.add(t);let e=tc[t],r=xr.size-Lu;if(r>Lu/10){for(let i of xr)if(xr.delete(i),delete tc[i],--r<=0)break}return e},Yw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Zw=Yw==="win32",Xw=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=bf(i,r)),e.push(r||"/"),e},[]),Qw=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=Zw?["win32 parallelization disabled"]:t.map(i=>_i(bf(Jw(i))));let r=new Set(t.map(i=>Xw(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}},e_=()=>process.umask(),Nu=Symbol("onEntry"),bc=Symbol("checkFs"),Mu=Symbol("checkFs2"),Ec=Symbol("isReusable"),dt=Symbol("makeFs"),vc=Symbol("file"),Sc=Symbol("directory"),Hs=Symbol("link"),Bu=Symbol("symlink"),Fu=Symbol("hardlink"),mi=Symbol("ensureNoSymlink"),zu=Symbol("unsupported"),Uu=Symbol("checkPath"),nc=Symbol("stripAbsolutePath"),gn=Symbol("mkdir"),Ue=Symbol("onError"),Ds=Symbol("pending"),Gu=Symbol("pend"),hr=Symbol("unpend"),rc=Symbol("ended"),ic=Symbol("maybeClose"),Ic=Symbol("skip"),bi=Symbol("doChown"),Ei=Symbol("uid"),vi=Symbol("gid"),Si=Symbol("checkedCwd"),t_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ii=t_==="win32",n_=1024,r_=(t,e)=>{if(!Ii)return re.unlink(t,e);let r=t+".DELETE."+df(16).toString("hex");re.rename(t,r,i=>{if(i)return e(i);re.unlink(r,e)})},i_=t=>{if(!Ii)return re.unlinkSync(t);let e=t+".DELETE."+df(16).toString("hex");re.renameSync(t,e),re.unlinkSync(e)},Hu=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,Nc=class extends Ai{[rc]=!1;[Si]=!1;[Ds]=0;reservations=new Qw;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[rc]=!0,this[ic]()},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:n_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Ii,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=X(Le.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:e_():0,this.umask=typeof t.umask=="number"?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.on("entry",e=>this[Nu](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[ic](){this[rc]&&this[Ds]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[nc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Dc(r),l=c.replaceAll(/\\/g,"/").split("/");if(l.includes("..")||Ii&&/^[a-z]:\.\.$/i.test(l[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let u=Le.posix.dirname(t.path),x=Le.posix.normalize(Le.posix.join(u,l.join("/")));if(x.startsWith("../")||x==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:r}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:r})),!0}[Uu](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[nc](t,"path")||!this[nc](t,"linkpath"))return!1;if(t.absolute=Le.isAbsolute(t.path)?X(Le.resolve(t.path)):X(Le.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path: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}=Le.win32.parse(String(t.absolute));t.absolute=i+Eu(String(t.absolute).slice(i.length));let{root:o}=Le.win32.parse(t.path);t.path=o+Eu(t.path.slice(o.length))}return!0}[Nu](t){if(!this[Uu](t))return t.resume();switch(Bw.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[bc](t);default:return this[zu](t)}}[Ue](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[hr](),e.resume())}[gn](t,e,r){Kw(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)}[bi](t){return this.forceChown||this.preserveOwner&&(typeof t.uid=="number"&&t.uid!==this.processUid||typeof t.gid=="number"&&t.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[Ei](t){return Hu(this.uid,t.uid,this.processUid)}[vi](t){return Hu(this.gid,t.gid,this.processGid)}[vc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new Vs(String(t.absolute),{flags:gf(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&re.close(i.fd,()=>{}),i.write=()=>!0,this[Ue](u,t),e()});let o=1,c=u=>{if(u){i.fd&&re.close(i.fd,()=>{}),this[Ue](u,t),e();return}--o===0&&i.fd!==void 0&&re.close(i.fd,x=>{x?this[Ue](x,t):this[hr](),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;re.futimes(x,h,m,E=>E?re.utimes(u,h,m,I=>c(I&&E)):c())}if(typeof x=="number"&&this[bi](t)){o++;let h=this[Ei](t),m=this[vi](t);typeof h=="number"&&typeof m=="number"&&re.fchown(x,h,m,E=>E?re.chown(u,h,m,I=>c(I&&E)):c())}c()});let l=this.transform&&this.transform(t)||t;l!==t&&(l.on("error",u=>{this[Ue](u,t),e()}),t.pipe(l)),l.pipe(i)}[Sc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[gn](String(t.absolute),r,i=>{if(i){this[Ue](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[hr](),t.resume())};t.mtime&&!this.noMtime&&(o++,re.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[bi](t)&&(o++,re.chown(String(t.absolute),Number(this[Ei](t)),Number(this[vi](t)),c)),c()})}[zu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Bu](t,e){let r=X(Le.relative(this.cwd,Le.resolve(Le.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[mi](t,this.cwd,r,()=>this[Hs](t,String(t.linkpath),"symlink",e),i=>{this[Ue](i,t),e()})}[Fu](t,e){let r=X(Le.resolve(this.cwd,String(t.linkpath))),i=X(String(t.linkpath)).split("/");this[mi](t,this.cwd,i,()=>this[Hs](t,r,"link",e),o=>{this[Ue](o,t),e()})}[mi](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let l=Le.resolve(e,c);re.lstat(l,(u,x)=>{if(u)return i();if(x?.isSymbolicLink())return o(new eo(l,Le.resolve(l,r.join("/"))));this[mi](t,l,r,i,o)})}[Gu](){this[Ds]++}[hr](){this[Ds]--,this[ic]()}[Ic](t){this[hr](),t.resume()}[Ec](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Ii}[bc](t){this[Gu]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Mu](t,r))}[Mu](t,e){let r=l=>{e(l)},i=()=>{this[gn](this.cwd,this.dmode,l=>{if(l){this[Ue](l,t),r();return}this[Si]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let l=X(Le.dirname(String(t.absolute)));if(l!==this.cwd)return this[gn](l,this.dmode,u=>{if(u){this[Ue](u,t),r();return}c()})}c()},c=()=>{re.lstat(String(t.absolute),(l,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Ic](t),r();return}if(l||this[Ec](t,u))return this[dt](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let x=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,h=m=>this[dt](m??null,t,r);return x?re.chmod(String(t.absolute),Number(t.mode),h):h()}if(t.absolute!==this.cwd)return re.rmdir(String(t.absolute),x=>this[dt](x??null,t,r))}if(t.absolute===this.cwd)return this[dt](null,t,r);r_(String(t.absolute),x=>this[dt](x??null,t,r))})};this[Si]?o():i()}[dt](t,e,r){if(t){this[Ue](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[vc](e,r);case"Link":return this[Fu](e,r);case"SymbolicLink":return this[Bu](e,r);case"Directory":case"GNUDumpDir":return this[Sc](e,r)}}[Hs](t,e,r,i){re[r](e,String(t.absolute),o=>{o?this[Ue](o,t):(this[hr](),t.resume()),i()})}},pi=t=>{try{return[null,t()]}catch(e){return[e,null]}},Ef=class extends Nc{sync=!0;[dt](t,e){return super[dt](t,e,()=>{})}[bc](t){if(!this[Si]){let o=this[gn](this.cwd,this.dmode);if(o)return this[Ue](o,t);this[Si]=!0}if(t.absolute!==this.cwd){let o=X(Le.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[gn](o,this.dmode);if(c)return this[Ue](c,t)}}let[e,r]=pi(()=>re.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Ic](t);if(e||this[Ec](t,r))return this[dt](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[l]=c?pi(()=>{re.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[dt](l,t)}let[o]=pi(()=>re.rmdirSync(String(t.absolute)));this[dt](o,t)}let[i]=t.absolute===this.cwd?[]:pi(()=>i_(String(t.absolute)));this[dt](i,t)}[vc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=l=>{let u;try{re.closeSync(o)}catch(x){u=x}(l||u)&&this[Ue](l||u,t),e()},o;try{o=re.openSync(String(t.absolute),gf(t.size),r)}catch(l){return i(l)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",l=>this[Ue](l,t)),t.pipe(c)),c.on("data",l=>{try{re.writeSync(o,l,0,l.length)}catch(u){i(u)}}),c.on("end",()=>{let l=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,x=t.mtime;try{re.futimesSync(o,u,x)}catch(h){try{re.utimesSync(String(t.absolute),u,x)}catch{l=h}}}if(this[bi](t)){let u=this[Ei](t),x=this[vi](t);try{re.fchownSync(o,Number(u),Number(x))}catch(h){try{re.chownSync(String(t.absolute),Number(u),Number(x))}catch{l=l||h}}}i(l)})}[Sc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[gn](String(t.absolute),r);if(i){this[Ue](i,t),e();return}if(t.mtime&&!this.noMtime)try{re.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[bi](t))try{re.chownSync(String(t.absolute),Number(this[Ei](t)),Number(this[vi](t)))}catch{}e(),t.resume()}[gn](t,e){try{return Vw(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}}[mi](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let l of r){c=Le.resolve(c,l);let[u,x]=pi(()=>re.lstatSync(c));if(u)return i();if(x.isSymbolicLink())return o(new eo(c,Le.resolve(e,r.join("/"))))}i()}[Hs](t,e,r,i){let o=`${r}Sync`;try{re[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[Ue](c,t)}}},s_=t=>{let e=new Ef(t),r=t.file,i=cf.statSync(r),o=t.maxReadSize||16*1024*1024;new Sm(r,{readSize:o,size:i.size}).pipe(e)},o_=(t,e)=>{let r=new Nc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,l)=>{r.on("error",l),r.on("close",c),cf.stat(o,(u,x)=>{if(u)l(u);else{let h=new Tc(o,{readSize:i,size:x.size});h.on("error",l),h.pipe(r)}})})},vf=Ti(s_,o_,t=>new Ef(t),t=>new Nc(t),(t,e)=>{e?.length&&ef(t,e)}),a_=(t,e)=>{let r=new Lc(t),i=!0,o,c;try{try{o=it.openSync(t.file,"r+")}catch(x){if(x?.code==="ENOENT")o=it.openSync(t.file,"w+");else throw x}let l=it.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=it.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 Gn(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,c_(t,r,c,o,e)}finally{if(i)try{it.closeSync(o)}catch{}}},c_=(t,e,r,i,o)=>{let c=new Wu(t.file,{fd:i,start:r});e.pipe(c),l_(e,o)},d_=(t,e)=>{e=Array.from(e);let r=new Xs(t),i=(o,c,l)=>{let u=(I,y)=>{I?it.close(o,v=>l(I)):l(null,y)},x=0;if(c===0)return u(null,0);let h=0,m=Buffer.alloc(512),E=(I,y)=>{if(I||y===void 0)return u(I);if(h+=y,h<512&&y)return it.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 Gn(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,it.read(o,m,0,512,x,E)};it.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+",it.open(t.file,l,u);if(x||!h)return c(x);it.fstat(h,(m,E)=>{if(m)return it.close(h,()=>c(m));i(h,E.size,(I,y)=>{if(I)return c(I);let v=new Vs(t.file,{fd:h,start:y});r.pipe(v),v.on("error",c),v.on("close",o),u_(r,e)})})};it.open(t.file,l,u)})},l_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Er({file:Sf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},u_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Er({file:Sf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},gi=Ti(a_,d_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!Pm(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")}),II=Ti(gi.syncFile,gi.asyncFile,gi.syncNoFile,gi.asyncNoFile,(t,e=[])=>{gi.validate?.(t,e),f_(t)}),f_=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))};sn();var _t={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",UPGRADE:"_agent/upgrade",DELETE:"_agent/delete"};function to(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function If(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function no(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Af(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function Tf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function vr(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Wt();Ke();ne();Pe();Ke();function _n(t,e){if(to(t)!=="cloud")throw new k("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function ki(t){return t.startsWith("http://")||t.startsWith("https://")}function ro(t){return t.endsWith("/")?t.slice(0,-1):t}Ke();ne();var io="1008033",Df="1289";var Pf="pbbp2",Of="https://www.coze.cn",Lf="/api/coze_claw/resource/get_frontier_key",y_="https://www.coze.cn",b_="wss://frontier.coze.cn";function so(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??y_}function Nf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??b_}function Sr(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 Ri(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Ci=G("handshake");async function Mc(t){let e=so(t.endpoint),r=t.timeoutMs??1e4,i=`${ro(e)}${Lf}?aid=${encodeURIComponent(io)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...Sr(t.ppeOverride)},c=new AbortController,l=setTimeout(()=>c.abort(),r);Ci.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 k("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 k("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${m.code} msg=${m.msg??"-"} logid=${x}`);let E=m.data??{},I=typeof E.access_key=="string"&&E.access_key||typeof E.accessKey=="string"&&E.accessKey||void 0,y=typeof E.device_id=="string"&&E.device_id||typeof E.deviceId=="string"&&E.deviceId||void 0;if(!I||!y){let v=JSON.stringify(m).slice(0,500);throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${x}: ${v}`)}return Ci.info("handshake ok",{remoteDeviceId:y,logid:x,traceId:h}),{accessKey:I,deviceId:y}}catch(u){if(u instanceof k)throw Ci.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Ci.warn("handshake timeout",{base:e,timeoutMs:r}),new k("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let x=u.cause;throw Ci.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 k("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(l)}}var Bc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",yt="auto",Mf=15e4;function Bf(t){return{model:Fc(t.model)??yt,...t.modelToken?{modelToken:t.modelToken}:{}}}function Ff(t){return!t||t===yt}var E_=new Set(["auto","\u81EA\u52A8"]);function Fc(t){let e=t?.trim();if(e)return E_.has(e.toLowerCase())?yt:e}function zf(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Bc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||yt;e.ANTHROPIC_MODEL=r,e.ANTHROPIC_SMALL_FAST_MODEL=r,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=r,e.ANTHROPIC_DEFAULT_OPUS_MODEL=r,e.ANTHROPIC_DEFAULT_SONNET_MODEL=r,e.CLAUDE_CODE_SUBAGENT_MODEL=r,e.CLAUDE_CODE_ATTRIBUTION_HEADER="0",t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow))}else Ff(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Uf(t){let e=[];if(t.modelToken?e.push("-c",`model="${t.model||yt}"`):Ff(t.model)||e.push("-c",`model="${t.model}"`),t.modelToken){e.push("-c",'model_providers.coze.name="coze"'),e.push("-c",`model_providers.coze.base_url="${Bc}/v1"`),e.push("-c",'model_providers.coze.env_key="OPENAI_API_KEY"'),e.push("-c",'model_providers.coze.wire_api="responses"'),e.push("-c","model_providers.coze.requires_openai_auth=false"),e.push("-c","model_providers.coze.supports_websockets=false"),e.push("-c",'model_provider="coze"');let r=t.modelInfo?.contextWindow??Mf;e.push("-c",`model_context_window=${r}`)}return e}function Gf(t){return t.modelToken?{OPENAI_API_KEY:t.modelToken}:{}}function zc(t,e){let{ttEnv:r,usePpe:i}=Ri(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Hf(t,e,r){if(!t.modelToken)return{};let i=zc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,l])=>`${c}:${l}`).join(`
|
|
92
|
+
`)}}function Uc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function jf(t,e,r){if(!t.modelToken)return null;let i=t.model||yt,o=zc(e,r),c=["text"];t.modelInfo?.capabilities?.image===!0&&c.push("image");let l={baseUrl:`${Bc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:[{id:i,name:i,reasoning:!1,input:c,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:t.modelInfo?.contextWindow??Mf,maxTokens:8192,api:"openai-completions"}]};return Object.keys(o).length>0&&(l.headers=o),l}function qf(t,e,r){if(!t.modelToken)return[];let i=zc(e,r),o=[];for(let[c,l]of Object.entries(i))o.push("-c",`model_providers.coze.http_headers.${c}="${l}"`);return o}var Ie=G("agent-handlers"),Wf=5*1024*1024,k_=1,C_=6,R_=new Set(["node_modules",".git",".coze","dist","build",".next"]),D_=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,P_=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,O_=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function L_(t){let e=t?.trim();return e?O_.test(e)||P_.test(e)?e:(Ie.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function N_(t){return new Promise((e,r)=>{let i=nt("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 oo=class{constructor(e){this.opts=e}opts;async listSkills(e){_n(e._meta,"_agent/listSkills");let r=vr(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Xe(r).workspace,c=i?.skills??[],l=[];for(let u of c){let x=Dt(o,u.relPath,"SKILL.md");await I_(x).then(m=>m.isFile()).catch(()=>!1)&&l.push(U_(u))}return{skills:l}}async addSkills(e){let r=vr(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 $c({agentId:r,workspace:i.workspace,framework:i.framework,skill:x});Vc(c,l,h),u.push(x)}return await ls(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){_n(e._meta,"_agent/removeSkills");let r=vr(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=Dt(i.workspace,u.relPath);await S_(x,{recursive:!0,force:!0}),Ie.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await ls(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,Ie.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,Ie.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:l}),x.stop(r).catch(h=>Ie.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 Ie.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await Me(r);if(!i)throw new k("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return Ie.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await or(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw Ie.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new k("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Qe(i),Ie.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 k("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await Me(r))throw new k("AGENT_NOT_FOUND",`agent not found: ${r}`);let o=["-y"];e.registry&&ki(e.registry)&&o.push(`--registry=${e.registry}`);let c=L_(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let l=e._meta?.cozeEnv;l&&D_.test(l)&&o.push("--env",l);let u=await N_(o);return Ie.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 k("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Me(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Qe(i),Ie.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}):(Ie.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async switchModel(e){if(_n(e._meta,"_agent/switchModel"),!e.agentId)throw new k("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Fc(e.model)??yt,i=await Me(e.agentId);if(!i)throw new k("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Qe(i),Ie.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return Ie.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=>Ie.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),Ie.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(_n(e._meta,_t.RESET),!e.agentId)throw new k("IPC_BAD_REQUEST",`${_t.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,_t.RESET),await this.runDetailSync(e.agentId,_t.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),Ie.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 ti(e,o)}async clearPersistedAcpSessionIds(e){let r=await Me(e).catch(()=>null);if(!r?.sessions)return;let i=!1;for(let o of Object.values(r.sessions))o.acpSessionId&&(o.acpSessionId=void 0,i=!0);i&&await Qe(r)}async repairAgent(e){if(_n(e._meta,_t.REPAIR),!e.agentId)throw new k("IPC_BAD_REQUEST",`${_t.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new k("IPC_BAD_REQUEST",`${_t.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){Ie.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,_t.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){Ie.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){Ie.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){_n(e._meta,"_agent/getFileTree");let r=e._meta,i=vr(r),o=await this.resolveWorkspace(i),c=e.filePath??"",l=this.safeJoin(o,c),u=await Gc(l).catch(()=>null);if(!u)throw new k("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new k("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await ei(l,o))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let x=Z_(e.depth);return u.isDirectory()?{tree:await Y_(o,l,c,x)}:{tree:[{name:X_(c),path:Xf(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){_n(e._meta,"_agent/getFileContent");let r=vr(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new k("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await Gc(o).catch(()=>null);if(!c||!c.isFile())throw new k("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new k("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await ei(o,i))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>Wf)throw new k("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${Wf})`);let l=await Kf(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 Me(e).catch(()=>null))?.workspace??Xe(e).workspace}safeJoin(e,r){let i=qc(e,r||"."),o=Kc(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${$f}`))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return Me(e)}async requireAgentCfg(e){let r=await this.loadAgentCfg(e);if(!r)throw new k("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function M_(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new k("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new k("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function B_(t){return t==="claude-code"?Dt(".claude","skills"):Dt(".agents","skills")}var F_=3e4,z_=50*1024*1024,Ir=3e4;async function $c(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new k("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 k("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=M_(o.skillName),x=B_(i),h=Dt(x,u),m=Dt(r,h);if(await Hc(m,{recursive:!0}),c){let I=Buffer.from(o.content,"utf8");Di(I.length),await jc(Dt(m,"SKILL.md"),I,"utf8")}else{let I=await G_(o.downloadUrl);j_(I)?await $_(I,m):q_(I)?await W_(I,m):await jc(Dt(m,"SKILL.md"),I.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 Ie.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:h,source:c?"content":"downloadUrl"}),E}function Vc(t,e,r){let i=e.get(r.skillId);if(i!==void 0){t[i]=r;return}e.set(r.skillId,t.length),t.push(r)}function U_(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function G_(t){if(!t)throw new k("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Di(e);let r=H_(t);return Di(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await Kf(e);return Di(r.length),r}if(ki(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),F_);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new k("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Di(o.byteLength),Buffer.from(o)}finally{clearTimeout(r)}}throw new k("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Di(t){if(t>z_)throw new k("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function H_(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new k("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 q_(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],r=t[3];return e===3&&r===4||e===5&&r===6}function Wc(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function W_(t,e){let r,i;try{r=new Yf.default(t),i=r.getEntries()}catch(l){throw new k("IPC_BAD_REQUEST",`zip parse failed: ${l.message}`,{cause:l})}for(let l of i){let u=l.entryName;if(!u||Wc(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new k("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(h=>h===".."))throw new k("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let x=l.header.attr>>>16&61440;if(x!==0&&x!==32768&&x!==16384)throw new k("IPC_BAD_REQUEST",`zip entry kind 0x${x.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=K_(i),c=qc(e);for(let l of i){if(Wc(l.entryName))continue;let u=l.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let x=qc(e,u),h=Kc(c,x);if(h.startsWith("..")||h==="..")throw new k("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(l.isDirectory){await Hc(x,{recursive:!0});continue}await Hc(A_(x),{recursive:!0});let m;try{m=l.getData()}catch(E){throw new k("IPC_BAD_REQUEST",`zip entry getData failed (${l.entryName}): ${E.message}`,{cause:E})}await jc(x,m)}}function K_(t){let e;for(let r of t){let i=r.entryName;if(!i||Wc(i))continue;let o=i.indexOf("/");if(o<=0)return;let c=i.slice(0,o+1);if(e===void 0)e=c;else if(e!==c)return}return e}async function $_(t,e){await V_(t);let r=vf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new k("IPC_BAD_REQUEST",`tar extract timeout (${Ir}ms)`))},Ir);try{await Jf(Vf.from(t),r)}catch(c){throw c instanceof k?c:i?new k("IPC_BAD_REQUEST",`tar extract timeout (${Ir}ms)`):new k("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function V_(t){let e=[],r=Er({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 k("IPC_BAD_REQUEST",`tar list timeout (${Ir}ms)`))},Ir);try{await Jf(Vf.from(t),r)}catch(c){throw i?new k("IPC_BAD_REQUEST",`tar list timeout (${Ir}ms)`):new k("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new k("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var J_=5e3;async function Y_(t,e,r,i){return Zf(t,e,r,i,{count:0})}async function Zf(t,e,r,i,o){if(i<=0)return[];let c;try{c=await v_(e,{withFileTypes:!0})}catch{return[]}let l=[];for(let u of c){if(R_.has(u.name)||u.isSymbolicLink())continue;if(o.count>=J_){l.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let x=Dt(e,u.name),h=T_(Dt(r,u.name)),m=null;try{m=await Gc(x)}catch{continue}if(m.isSymbolicLink())continue;o.count++;let E={name:u.name,path:Xf(Kc(t,x)),isDir:m.isDirectory(),size:m.size,modifiedAt:Math.floor(m.mtimeMs)};m.isDirectory()&&i>1&&(E.children=await Zf(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 Z_(t){return!t||t<=0?k_:Math.min(t,C_)}function X_(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function Xf(t){return t.split($f).join("/")}ne();import{readFileSync as UA}from"node:fs";import{dirname as HA,join as jA}from"node:path";import{fileURLToPath as WA}from"node:url";var Ar="0.2.0-alpha.6";var yn=G("agent-health-reporter"),Q_=1e4,Pi=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??Q_}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()}),yn.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),yn.info("heartbeat stopped"))}async tick(){if(this.inFlight){yn.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){yn.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=ey(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:Ar,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3)}catch(l){yn.warn("heartbeat batch send failed",{count:r.length,err:String(l)})}let c=o?.authFailures;if(c&&c.length>0&&(yn.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){yn.warn("onAuthFailures callback failed (ignored)",{err:String(l)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){yn.warn("onTickEnd hook failed",{err:String(r)})}}};function ey(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}sn();import{chmod as Wy,mkdir as go,rm as Ky,stat as $y,writeFile as Vy}from"node:fs/promises";import{homedir as Jy}from"node:os";import{join as A0}from"node:path";rn();import{existsSync as xy}from"node:fs";import{release as hy}from"node:os";import{basename as py,isAbsolute as gy}from"node:path";function Oi(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Tr(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function kr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function bn(t,e){return{jsonrpc:"2.0",id:t,error:e}}Ke();var ao=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 Qf(t){return"method"in t&&"id"in t&&t.id!==void 0}function e0(t){return"method"in t&&!("id"in t)}function co(t){return!("method"in t)&&"id"in t}var ty={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 ny(t){if(t!=null)return t instanceof Error?{name:t.name,message:Li(t.message)}:typeof t=="string"?Li(t):typeof t=="object"?iy(t):t}var ry=[[/\/Users\/[^/\s'"`)]+/g,"/Users/<redacted>"],[/\/home\/[^/\s'"`)]+/g,"/home/<redacted>"],[/[A-Za-z]:\\Users\\[^\\\s'"`)]+/g,"C:\\Users\\<redacted>"],[/(Bearer|Token|Authorization:)\s+[\w._-]+/gi,"$1 <redacted>"],[/\b(sk|pat|ak)[-_][A-Za-z0-9_-]{20,}\b/g,"<redacted-key>"]];function Li(t){let e=t;for(let[r,i]of ry)e=e.replace(r,i);return e}function iy(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Li(i):e[r]=i;return e}function Ni(t){if(t instanceof k){let e=ny(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:ty[t.code]??ee.INTERNAL_ERROR,message:Li(t.message),data:r}}return{code:ee.INTERNAL_ERROR,message:Li(t instanceof Error?t.message:String(t))}}function t0(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 k(r,o,{retriable:e?.retriable??!1,cause:c})}function r0(t){return`${JSON.stringify(t)}
|
|
93
|
+
`}var n0=10*1024*1024,lo=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>n0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${n0} 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 s0={"session/prompt":"session.prompt","session/cancel":"session.cancel","session/new":"session.new","session/load":"session.load","_agent/create":"agent.create","_agent/health":"agent.health","_agent/pair":"agent.pair","_agent/listSkills":"agent.listSkills","_agent/addSkills":"agent.addSkills","_agent/removeSkills":"agent.removeSkills","_agent/getFileTree":"agent.getFileTree","_agent/getFileContent":"agent.getFileContent","_agent/detail":"agent.detail","_agent/update":"agent.update","_agent/disconnect":"agent.disconnect","_agent/switchModel":"agent.switchModel","_agent/genModelToken":"agent.genModelToken","_agent/reset":"agent.reset","_agent/repair":"agent.repair","session/request_permission":"session.requestPermission","session/set_mode":"session.setMode",initialize:"initialize"},nT=Object.fromEntries(Object.entries(s0).map(([t,e])=>[e,t])),sy={"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:[]},Cr=class{seq=0;next(e,r){this.seq+=1;let i=s0[e]??oy(e),o=sy[i]??[],c=[i,String(this.seq)];if(o.length>0){let l=o.map(x=>i0(r?.[x]??"")),u=ay(l).join(":");u&&c.push(u)}else r&&Object.values(r).some(l=>l)&&c.push(Object.values(r).filter(Boolean).map(l=>i0(String(l))).join(":"));return c.join("_")}reset(){this.seq=0}};function oy(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function i0(t){return t.replace(/[:_\s]+/g,"-")}function ay(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}Qr();import{readFileSync as cy}from"node:fs";var dy=384;async function Jc(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await sr(t.agentEnvFile,r,{mode:dy})}function Yc(t){try{let e=JSON.parse(cy(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function o0(t,e,r={},i=o=>o){return{...i({...t,...Yc(e)}),...r}}Wt();er();Ke();ne();Pe();import{execFileSync as ly,spawnSync as uy}from"node:child_process";function Mi(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function Bi(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),uy("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var Zc=new Set;function a0(t){typeof t=="number"&&t>0&&Zc.add(t)}function c0(t){typeof t=="number"&&Zc.delete(t)}function d0(){for(let t of Zc)Bi(t,"SIGKILL")}var Rr="coze-bridge-daemon";function l0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return ly("pgrep",["-U",String(o),"-f",Rr],{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 u0(t,e){if(t.length===0)return;let r=e?.killFn??Bi,i=e?.isAliveFn??Mi,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 fy=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: (Node binary not found|QCLAW_CLI_NODE_BINARY not set)/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @zed-industries\/codex-acp|optional dependency was not installed|\.resolve is not a function/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"acp_module_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code","codex"],match:/Cannot find module[^\n]*node_modules[\\/]@(agentclientprotocol[\\/]claude-agent-acp|zed-industries[\\/]codex-acp)/i,message:"ACP \u4F9D\u8D56\u672A\u6B63\u786E\u5B89\u88C5 (wrapper \u5165\u53E3\u7F3A\u5931)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u91CD\u88C5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code","openclaw"],match:/import .* with \{ type: ["']json["'] \}|import assertion|import attribute|openclaw\.mjs[\s\S]*Unexpected token '\.'/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (ACP \u9700\u8981\u8F83\u65B0 Node \u624D\u652F\u6301 import attributes / \u53EF\u9009\u94FE)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20.10 \u540E\u91CD\u8BD5"},{reason:"acp_cmd_misexec",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code"],match:/claude-agent-acp\.cmd.*@ECHO off|\.cmd:\d+/i,message:"claude ACP wrapper \u542F\u52A8\u65B9\u5F0F\u5F02\u5E38 (Windows .cmd \u88AB\u8BEF\u5F53\u811A\u672C\u6267\u884C)\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect"},{reason:"prompt_too_long",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["claude-code"],match:/Prompt is too long|bad request: failed to read body: length limit exceeded/i,message:"\u672C\u8F6E\u8F93\u5165\u8FC7\u957F\uFF0C\u8D85\u8FC7\u6A21\u578B\u4E0A\u4E0B\u6587\u4E0A\u9650\uFF0C\u8BF7\u7CBE\u7B80\u8F93\u5165\u6216\u5F00\u542F\u65B0\u4F1A\u8BDD\u540E\u91CD\u8BD5"}];function f0(t,e){if(!e)return null;for(let r of fy)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function x0(t,e){return f0(t,e)}function h0(t,e){return f0(t,e)}function Dr(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 p0(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:Dr(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:Dr(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Dr(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Dr(c,!1,e)}}var g0=We("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),my=200,wy=40,_y=We("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),yy=We("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),by=We("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),Ey=We("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),vy=We("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),Sy=We("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),m0=500;function Iy(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=m0?t:`${e.slice(0,m0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function Ay(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 w0(t){try{return xy(t)}catch{return}}function Ty(t,e){return{platform:process.platform,osRelease:hy(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:gy(e.command)?w0(e.command):void 0,cwd:e.cwd,cwdExists:w0(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=${py(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Pt=class{constructor(e){this.opts=e;this.log=G(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new lo({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Cr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new k("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=o0(process.env,this.opts.agentEnvFile??Q().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=nt(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,a0(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>my&&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,c0(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=Ty(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 k("AGENT_SPAWN_FAILED",ky(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()));Bi(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||Bi(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:vy,phase2GateMs:_y,livenessWindowMs:yy,absoluteMaxMs:by,approvalMaxMs:Sy,suspendThresholdMs:Ey,...r};return this.call("session/prompt",e,g0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Tr("session/cancel",e))}setSessionMode(e){return this.call("session/set_mode",e)}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(kr(e,r))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(bn(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=g0,o){if(!this.child||this.stopped)return Promise.reject(new k("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),l=Oi(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(),I={cfg:o,startedAt:E,lastActivityAt:E,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:E,expectedIntervalMs:Dr(0,!1,o),sessionId:u};m.promptTimeout=I;let y=()=>{let v={startedAt:I.startedAt,lastActivityAt:I.lastActivityAt,firstFrameSeen:I.firstFrameSeen,hasActiveTool:I.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:I.suspendedMs,armedAt:I.armedAt,expectedIntervalMs:I.expectedIntervalMs},A=this.now(),T=p0(v,I.cfg,A),C=P=>{I.armedAt=A,I.expectedIntervalMs=P,m.timer=setTimeout(y,P)};if(T.action==="suspend"){I.suspendedMs+=T.suspendedDeltaMs,I.lastActivityAt=A,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:T.suspendedDeltaMs,suspendedMs:I.suspendedMs,...I.sessionId?{sessionId:I.sessionId}:{}}),C(T.rearmMs);return}if(T.action==="continue"){C(T.rearmMs);return}this.pending.delete(c),T.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:T.awaitingApproval,...I.sessionId?{sessionId:I.sessionId}:{}}),h(T.awaitingApproval?new k("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${I.cfg.approvalMaxMs}ms`):new k("AGENT_TIMEOUT",`${e} timed out after ${I.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...I.sessionId?{sessionId:I.sessionId}:{}}),h(new k("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${I.cfg.livenessWindowMs}ms`)))};m.timer=setTimeout(y,I.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 k("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 k("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(r0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(co(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 k("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:Iy(e.result)}),r.resolve(e.result));return}if(e0(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(Qf(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(bn(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(bn(e.id,Ni(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=t0(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=h0(this.framework,Ay(e));return i?new k(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 k("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(wy).join(`
|
|
96
|
+
`),o=x0(this.framework,i);return o?new k(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new k("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 Cy(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 uo=class extends Pt{framework="claude-code";constructor(e){let{command:r,args:i}=Xr("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 Cy(e)}};rn();import{mkdtempSync as Ry,rmSync as Dy}from"node:fs";import{tmpdir as Py}from"node:os";import{join as Oy}from"node:path";var fo=class extends Pt{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=Xr("codex",e.command,i),l=e.isolateCodexHome?Ry(Oy(Py(),"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.authMethodId=e.authMethodId,this.codexHomeDir=l}async initialize(e){let r=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),r}async stop(e){if(await super.stop(e),this.codexHomeDir)try{Dy(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};Ke();var Ly=3e4,Pr=class extends Pt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let r=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${r}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=r,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},Ly))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new k("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};var _0=["default","acceptEdits","plan","auto","bypassPermissions"],y0=["read-only","auto","full-access"];function En(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return _0.includes(e);case"codex":return y0.includes(e);case"openclaw":return!1}}function Xc(t){switch(t){case"claude-code":return _0.join("/");case"codex":return y0.join("/");case"openclaw":return""}}Ke();ne();Pe();function Qc(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}rn();var vn=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 xo=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 vn,this.sessionQueues.set(e,r)),r}allSessionQueues(){return this.sessionQueues.entries()}hasSessionQueue(e){let r=this.sessionQueues.get(e);return!!r&&!r.isDisposed}async dispose(e){this.status="stopped";let r=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let i of this.sessionQueues.values())i.dispose(r);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let r=[];for(let[,i]of this.sessions)Fi(i),i.downstream&&(r.push(i.downstream.stop(e).catch(()=>{})),i.downstream=void 0);await Promise.all(r),this.activeTriggers.clear(),this.activeGroupIds.clear()}};function Fi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function Kt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Wt();ne();import{constants as b0}from"node:fs";import{access as Ny}from"node:fs/promises";import{delimiter as My,join as By}from"node:path";var bt=G("framework-detector"),E0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},Fy=[".exe",".cmd",".bat",".ps1"],jn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??nt,access:e.access??Ny}}async detect(e){let r=E0[e],i=await this.which(r);if(!i)return bt.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,l]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return l&&(u.defaultAgent=l),u}async detectAll(){let e=await Promise.all(Object.keys(E0).map(async i=>[i,await this.detect(i)])),r={};for(let[i,o]of e)o&&(r[i]=o);return r}async which(e){let r=this.env.pathEnv.split(My).filter(Boolean),i=this.env.platform==="win32"?["",...Fy]:[""];for(let o of r)for(let c of i){let l=By(o,e+c);if(await this.isExecutable(l))return l}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?b0.F_OK:b0.X_OK;return await this.env.access(e,r),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let r=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!r)return bt.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return bt.warn("openclaw default agent probe: non-zero exit",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)}),null;let i=r.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return bt.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:r.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return bt.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(l=>l?.isDefault===!0);return c?!c.id||!c.workspace?(bt.warn("openclaw default agent probe: default agent missing id or workspace",{path:e,hasId:!!c.id,hasWorkspace:!!c.workspace}),null):{id:c.id,workspace:c.workspace}:(bt.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return bt.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let r=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!r)return bt.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||bt.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let l=JSON.parse(c[0]);typeof l.gateway?.port=="number"&&(o.port=l.gateway.port),typeof l.service?.runtime?.status=="string"&&(o.runtime=l.service.runtime.status),!i&&typeof l.rpc?.error=="string"&&(o.detail=l.rpc.error)}catch(l){bt.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(l)})}return o}async probeVersion(e,r=[]){let i=await this.runProbe(e,[...r,"--version"]);return i&&(Uy(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 Uy(t){return t.replace(zy,"")}import{homedir as Gy}from"node:os";import{join as Hy}from"node:path";Wt();er();Ke();Qr();ne();async function I0(){let t=Hy(Gy(),".openclaw/openclaw.json");return(await ir(t))?.gateway?.auth?.token??""}var v0=G("openclaw.config"),jy=[0,5e3,5e3],qy=We("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),S0="models.providers.",ho="agents.defaults.models",po=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new vn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??jy,this.cliTimeoutMs=e.cliTimeoutMs??qy}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,v0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(l)})}}throw new k("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=nt(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",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){v0.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",`${S0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${S0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${ho}[${e}]`,()=>this.runCli(["config","set",ho,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${ho}[${e}]`,`${ho}.${e}`)}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var le=G("agent-manager"),td="acceptEdits",C0="full-access",R0="read-only";function Yy(t){switch(t){case"read-only":return["-c",'sandbox_mode="read-only"',"-c",'approval_policy="on-request"'];case"auto":return["-c",'sandbox_mode="workspace-write"',"-c",'approval_policy="on-failure"'];case"full-access":return["-c",'sandbox_mode="danger-full-access"',"-c",'approval_policy="never"']}}var Zy=(t,e,r,i,o,c,l,u,x,h)=>{switch(t){case"claude-code":{let m={...o?{...zf(o),...Hf(o,l,u)}:{},...x??{},IS_SANDBOX:"1"};return new uo({cwd:r,env:m,agentId:i})}case"codex":{let m=o?[...Uf(o),...qf(o,l,u)]:[],E=C0;h!==void 0&&(En("codex",h)?E=h:le.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:h}));let I=[...m,...Yy(E)],y={...o?Gf(o):{},...x??{}},v=!!o;return new fo({cwd:r,agentId:i,...I.length>0?{extraArgs:I}:{},...Object.keys(y).length>0?{env:y}:{},...v?{authMethodId:"openai-api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Pr({command:e,cwd:r,agentId:i,...c?{sessionName:Qc(c)}:{}})}};function ed(t){return t==="claude-code"||t==="codex"}function Xy(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(Qy(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
|
|
97
97
|
`)}
|
|
98
98
|
`}function Qy(t){if(t.includes(`
|
|
99
|
-
`)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var eE={path:"",version:"cloud-deployed"},C0="openclaw_gateway_unavailable",tE="openclaw_default_agent_missing";function R0(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 nE={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},rE=6e4,wo=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;detectorFactory;openclawEnvBootstrapPromise;openclawConfigFactory;openclawConfigDir;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??Yy,this.createTimeoutMs=e.createTimeoutMs??rE,this.detectorFactory=e.detectorFactory??(()=>new qn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new go({command:r})),this.openclawConfigDir=e.openclawConfigDir??T0(Jy(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new C("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{le.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=T0(e,".env");if(await $y(r).then(c=>c.isFile()).catch(()=>!1)){le.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}await mo(e,{recursive:!0});let o=Xy({...process.env,...Xc(this.paths.agentEnvFile)});if(await Vy(r,o,"utf8"),process.platform!=="win32")try{await Wy(r,384)}catch(c){le.warn("chmod ~/.openclaw/.env to 0600 failed (ignored)",{err:String(c)})}le.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),le.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new C("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new C("IPC_BAD_REQUEST","framework required");let i=await Me(e.agentId,this.paths).catch(()=>null),o=no(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let c=this.registry.get(e.agentId);if(c){if(c.framework!==e.framework)throw new C("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")le.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(R=>le.warn("dispose stale agent failed (ignored)",{err:String(R)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")le.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(R=>le.warn("dispose drifted agent failed (ignored)",{err:String(R)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){le.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let R=await Me(e.agentId,this.paths).catch(()=>null);R&&(R.patToken=e.patToken,await Xe(R,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){le.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let R=await Me(e.agentId,this.paths).catch(()=>null);R&&(R.modelInfo=e.modelInfo,await Xe(R,this.paths))}return le.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=Ye(e.agentId,this.paths),f=o?"cloud":"local",p=e.framework==="openclaw"&&f==="local",m;p&&!r?.revive&&(m=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let b=m??(p?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),A=e.workspace??b??u.workspace,y=new AbortController,S=setTimeout(()=>y.abort(new C("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),I,T=!1;try{o&&nd(e.framework)&&await nr(e.framework,y.signal);let R=()=>{if(y.signal.aborted)throw y.signal.reason instanceof Error?y.signal.reason:new C("AGENT_TIMEOUT","_agent/create aborted")};await mo(u.root,{recursive:!0}),await mo(A,{recursive:!0}),await mo(u.logs,{recursive:!0}),R(),p||await sr(A,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(f==="cloud"?await Ra(A,"cloud"):await Ra(A,"local",rd)),R();let D=i,E=Ff({model:e.model??D?.model}),k=If(e._meta)??D?.accountId,P=e.patToken??D?.patToken,F=f==="cloud"?e.modelInfo??D?.modelInfo:void 0;if(I=new ho({agentId:e.agentId,framework:e.framework,workspace:A,model:E.model??yt,deployType:f,...k?{accountId:k}:{},...P?{patToken:P}:{},...F?{modelInfo:F}:{}}),I.status="ok",D?.sessions){let V=f==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[Z,ie]of Object.entries(D.sessions)){let oe={acpSessionId:ie.acpSessionId,modelToken:ie.modelToken,tokenGeneratedAt:ie.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};V?ie.permissionMode===void 0?(oe.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",le.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:Z,framework:e.framework,fallback:oe.permissionMode})):En(e.framework,ie.permissionMode)?oe.permissionMode=ie.permissionMode:le.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:Z,framework:e.framework,value:ie.permissionMode}):ie.permissionMode!==void 0&&le.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:Z,framework:e.framework,deployType:f}),ie.cozeGroupId&&(oe.cozeGroupId=ie.cozeGroupId),I.sessions.set(Z,oe)}let ee=Object.keys(D.sessions).length;ee>0&&le.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:ee})}this.registry.register(I),T=!0;let M={agentId:e.agentId,framework:e.framework,workspace:A,cozeIdentity:e.cozeIdentity,createdAt:D?.createdAt??Date.now(),sessions:D?.sessions??{},model:E.model};f==="cloud"&&(M.deployType="cloud"),k&&(M.accountId=k),P&&(M.patToken=P),F&&(M.modelInfo=F),D?.skills&&(M.skills=D.skills),D?.agentName&&(M.agentName=D.agentName),D?.description&&(M.description=D.description),e.framework==="openclaw"&&f==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,A)):le.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId}));let J=e.initialSkills??[];if(J.length>0){let V=[...M.skills??[]],ee=new Map(V.map((oe,O)=>[oe.skillId,O])),Z=await Promise.allSettled(J.map(oe=>Jc({agentId:e.agentId,workspace:A,framework:e.framework,skill:oe}))),ie=0;for(let[oe,O]of Z.entries()){let H=J[oe];H&&(O.status==="fulfilled"?(Zc(V,ee,O.value),ie++):le.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:H.skillId,skillName:H.skillName,err:String(O.reason)}))}ie>0&&(M.skills=V,le.info("initialSkills installed",{agentId:e.agentId,installed:ie,requested:J.length}))}return await Xe(M,this.paths),le.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:f}),{ok:!0,agentId:e.agentId,workspace:A,framework:e.framework}}catch(R){throw le.error("agent create failed, rolling back",{agentId:e.agentId,err:String(R)}),T&&I&&(await I.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Ky(u.root,{recursive:!0,force:!0}).catch(D=>le.warn("rm agent dir failed (ignored)",{err:String(D)})),R instanceof C?R:new C("AGENT_SPAWN_FAILED",String(R),{cause:R})}finally{clearTimeout(S)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&nd(e.framework))u=eE;else throw new C("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);nd(e.framework)&&!cs(e.framework)&&(le.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await nr(e.framework));let f=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,p;if(e.framework==="openclaw")p=await this.buildOpenclawDownstream({session:e,modelConfig:f,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path});else{let m=e.sessions.get(i),b=Kt(e)?m?.permissionMode??k0:"full-access";p=this.factory(e.framework,u.path,e.workspace,e.agentId,f,i,o,c,this.buildBinShimPathEnv(),b)}try{return await p.start(),await p.initialize(nE),p}catch(m){let b=p instanceof Pt?p.getStderrTail():[];throw b.length>0&&le.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:m instanceof C?m.code:"unknown",recentStderr:b}),await p.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,m)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new C("AGENT_ENV_NOT_READY",R0(o),{cause:{reason:C0}})}catch(o){le.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof C?i:new C("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};le.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return le.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new C("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:tE}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new C("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new C("AGENT_ENV_NOT_READY",R0(r),{cause:{reason:C0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:l,command:u}=e,f=td(o);if(r.deployType==="local"){let A=await this.ensureOpenclawDefaultAgent();return new Dr({command:u,cwd:A.workspace,agentId:A.id,sessionName:f})}let p=await I0(),m=i?jf(i,c,l):null,b;if(m){let A=qc(o),S=m.models[0]?.id??yt,I=`${A}/${S}`;if(!this.ensuredProviders.has(I)){let T=this.getOpenclawConfig();await T.ensureProvider(A,m),await T.addModelToAllowlist(I),this.ensuredProviders.add(I)}b=I}return new Dr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:f,...p?{gatewayToken:p}:{},...b?{slashModelOnStart:b}:{}})}async openclawRepair(e,r){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,r)}async cleanupOpenclawSessionProviders(e){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let r=this.openclawConfigCache;for(let i of e.sessions.keys()){let o=qc(i),c=`${o}/${e.model}`,l=!0;try{await r.removeProvider(o)}catch(u){l=!1,le.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){l=!1,le.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}l&&this.ensuredProviders.delete(c)}}};import{randomUUID as M0}from"node:crypto";import{promises as uE}from"node:fs";import{basename as B0}from"node:path";We();te();import{promises as sE}from"node:fs";import{basename as oE}from"node:path";var P0=q("file-upload"),aE="/api/coze_claw/file/agent_upload",cE=6e4;async function O0(t,e={}){let i=`${io(oo(e.handshakeBase))}${aE}`,o=e.timeoutMs??cE,c=await sE.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",...vr(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},f=new AbortController,p=setTimeout(()=>f.abort(),o);P0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let m=await fetch(i,{method:"POST",headers:u,body:l,signal:f.signal}),b=m.headers.get("x-tt-logid")??"";if(!m.ok){let S=await m.text().catch(()=>"");throw new C("UPLOAD_FAILED",`upload HTTP ${m.status} logid=${b}: ${S.slice(0,200)}`)}let A=await m.json();if(A.code!==void 0&&A.code!==0)throw new C("UPLOAD_FAILED",`upload code=${A.code} msg=${A.msg??"-"} logid=${b}`);let y=A.data?.file?.file_url;if(!y)throw new C("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${b}: ${JSON.stringify(A).slice(0,200)}`);return P0.info("file upload ok",{uri:y,logid:b}),{uri:y}}catch(m){throw m instanceof C?m:m.name==="AbortError"?new C("UPLOAD_FAILED",`upload timeout (${o}ms) for ${oE(t.path)}`):new C("UPLOAD_FAILED",String(m),{cause:m})}finally{clearTimeout(p)}}We();te();import{extname as dE}from"node:path";var lE={".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 L0(t){let e=dE(t).toLowerCase();return lE[e]??"application/octet-stream"}Oe();var _o=q("agent-send"),N0=50*1024*1024;function F0(t,e,r){let i=t.get(e);if(!i)throw new C("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new C("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new C("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function z0(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(p){u=p,f<2&&(_o.warn("sendAgentFileUpdate failed, retrying",{attempt:f+1,err:String(p)}),await new Promise(m=>setTimeout(m,5e3)))}throw new C("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function U0(t,e){let{session:r,runtime:i}=F0(e.core,t.agentId,t.sessionId);if(!await Qr(t.path,r.workspace))throw new C("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await uE.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new C("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>N0)throw new C("FILE_TOO_LARGE",`${o.size} bytes > limit ${N0}`);let c=await L0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new C("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new C("UPSTREAM_NOT_READY","cloud WS not connected");let l=t.name??B0(t.path),u;try{u=await O0({patToken:r.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:l,sizeBytes:o.size,...r.accountId?{accountId:r.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(p){throw _o.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:p instanceof C?p.code:"UNKNOWN",message:p instanceof Error?p.message:String(p)}),p}let f={sessionUpdate:"agent_file",messageId:M0(),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 z0(e,r,i,t.sessionId,f,"agent file uploaded to cloud but sendAgentFileUpdate failed"),_o.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 G0(t,e){let{session:r,runtime:i}=F0(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new C("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new C("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??B0(t.path),c={sessionUpdate:"group_file",messageId:M0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await z0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),_o.info("agent group file sent",{agentId:t.agentId,sessionId:t.sessionId,uri:t.path,name:o,mime:t.mimeType}),{ok:!0,uri:t.path,bytes:0,mimeType:t.mimeType}}function q0(t,e){let r=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(r.length,i.length);for(let c=0;c<o;c++){let l=r[c]??0,u=i[c]??0;if(l<u)return!0;if(l>u)return!1}return!1}nn();Wt();te();var Ot=q("coze-cli-installer"),H0="@coze/cli@latest",fE="coze",j0="0.1.8",xE=5e3,hE=5e3,pE=9e4,W0=1e4,Fi=null,yo=!1;async function id(t,e={}){if(yo)return;if(Fi)return Fi;let r=e.exec??Df;return Fi=(async()=>{try{let i=await gE(fE,r),o=!1;if(i){let l=await mE(r);if(l===void 0)Ot.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(q0(l,j0))Ot.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:l,min:j0}),o=!0;else{Ot.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:l}),yo=!0;return}}let c=o?"upgrade-only":"full";Ot.info("coze-cli install start",{package:H0,mode:c});try{await r("npm",["i","-g","--prefer-online",H0],{timeout:pE,maxBuffer:10*1024*1024}),Ot.info("coze-cli install ok")}catch(l){Ot.warn("coze-cli install failed (skip subsequent steps)",{err:String(l)});return}if(o){yo=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:W0}),Ot.info("coze config set xTTEnv ok",{env:t.env})}catch(l){Ot.warn("coze config set failed (continue to auth login)",{err:String(l)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:W0}),Ot.info("coze auth login ok")}catch(l){Ot.warn("coze auth login failed",{err:String(l)});return}yo=!0}finally{Fi=null}})(),Fi}async function gE(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:xE});return Ta(i)}catch{return}}async function mE(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:hE});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}Xr();Oe();var wE=10*6e4;function K0(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?wE:e}function Eo(t){return rr(t??X().configFile)}function zi(t,e){return ir(e??X().configFile,t)}import{randomBytes as FE}from"node:crypto";Qn();We();te();import{createReadStream as _E}from"node:fs";import{mkdir as yE,readFile as EE,realpath as bE,stat as vE,writeFile as SE}from"node:fs/promises";import{basename as AE,dirname as sd,isAbsolute as IE,join as TE,relative as CE,resolve as $0,sep as RE}from"node:path";import{createInterface as kE}from"node:readline";var J0=q("fs-rpc"),Ui=je("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function Z0(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Ui)throw new C("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Ui} bytes`);let i=await X0(t.path,e);return await yE(sd(i),{recursive:!0}),await SE(i,t.content,"utf8"),J0.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function Y0(t,e){let r=await X0(t.path,e),i=await vE(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Ui&&!o)throw new C("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Ui} bytes`);let c;if(o&&i.size>Ui)c=await DE(r,t.line??1,t.limit);else{let l=await EE(r,"utf8");if(o){let u=l.split(`
|
|
100
|
-
`),
|
|
101
|
-
`)}else c=l}return
|
|
102
|
-
`)}async function X0(t,e){if(typeof t!="string"||t.length===0)throw new C("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([V0($0(e)),V0($0(t))]),o=CE(r,i);if(PE(o,RE,IE(o)))throw new C("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function PE(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function V0(t){let e=[],r=t;for(;r!==sd(r);)try{let i=await bE(r);return e.length?TE(i,...e.reverse()):i}catch{e.push(AE(r)),r=sd(r)}return t}te();var Q0=q("prompt-multimodal"),ex=10*1024*1024,OE=15e3,LE=6;async function tx(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 NE(l))}}let o=Array.from({length:Math.min(LE,t.length)},()=>i());return await Promise.all(o),e}function nx(t){return t.some(e=>e.type==="image")}async function NE(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Ti(e.uri))return t;try{let{buf:r,contentType:i}=await BE(e.uri),o=e.mimeType||ME(i)||"application/octet-stream";return Q0.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 Q0.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function ME(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function BE(t){let e=new AbortController,r=setTimeout(()=>e.abort(),OE);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>ex)throw new Error(`image too large: ${o.byteLength} bytes (max ${ex})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}rn();We();te();var K=q("core"),zE=3e4,UE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,GE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",qE="\u5BA1\u6279\u5DF2\u8D85\u65F6",HE=3e4,bo=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Cr;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=K0(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}),Bi(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(yn(o,{code:Q.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(l=>K.debug("send error response to upstream failed (ignored)",{err:String(l)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:Q.INTERNAL_ERROR,message:`bridge: ${r}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,r=this.pendingBridge.size;if(!(e===0&&r===0)){K.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:r});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:Q.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new C("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(lo(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let r="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&UE.test(i)?this.currentCozeEnv=i:i&&K.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});try{if(e.method.startsWith("_agent/")){let o=this.extensions[e.method];if(!o){r!==null?await this.sendError(r,Q.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):K.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(Tr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Tr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Tr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,Q.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):K.warn("drop unknown notification",{method:e.method})}catch(o){K.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(yn(r,Li(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new C("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new C("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new C("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new C("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||e.method==="session/set_mode"||!c)return this.dispatchSessionCall(o,e.method,r);if(e.method==="session/prompt"){let f=o.sessions.get(c);if(f?.pendingPermission){let p=r._meta?.cozeTriggerMsgId,m=ro(r._meta);return K.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,f,c,GE,p,m)}}let l=Date.now(),u=!1;try{let f=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,f}finally{K.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-l,ok:u})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=Cf(i);switch(r){case"session/new":{let c=jE();return K.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return K.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,l=c.sessionId;if(!l)throw new C("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=Kt(e)?Tf(i._meta):void 0;if(u!==void 0&&!En(e.framework,u))throw new C("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${ed(e.framework)}`);let f=await this.ensureRuntime(e,l);if(u!==void 0&&f.permissionMode===void 0&&(f.permissionMode=u,await this.persistSessionMapping(e)),f.replySeq=0,await this.ensureDownstream(e,l,f),!f.downstream||!f.acpSessionId)throw new C("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&f.permissionMode!==void 0&&f.permissionMode!==u){let A=f.permissionMode;f.permissionMode=u,await this.persistSessionMapping(e);try{await f.downstream.setSessionMode({sessionId:f.acpSessionId,modeId:u})}catch(y){throw f.permissionMode=A,await this.persistSessionMapping(e).catch(()=>{}),y}}let p=i._meta?.cozeTriggerMsgId;p?e.activeTriggers.set(f.acpSessionId,p):e.activeTriggers.delete(f.acpSessionId);let m=ro(i._meta);if(m?e.activeGroupIds.set(f.acpSessionId,m):e.activeGroupIds.delete(f.acpSessionId),m&&f.cozeGroupId!==m&&(f.cozeGroupId=m,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&nx(c.prompt))throw new C("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let b=await tx(c.prompt);try{let A=await f.downstream.sessionPrompt({...c,sessionId:f.acpSessionId,prompt:b});return f.lastActiveAt=Date.now(),A}catch(A){if(A instanceof C&&A.code==="AGENT_APPROVAL_TIMEOUT"){let y=f.pendingPermission;y&&(y.downstream.respondAgentRequest(y.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(y.upstreamId),f.pendingPermission=void 0);let S=f.acpSessionId,I=S?e.activeTriggers.get(S):void 0,T=S?e.activeGroupIds.get(S):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,f,l,qE,I,T)}throw A}finally{if(e.activeTriggers.delete(f.acpSessionId),e.activeGroupIds.delete(f.acpSessionId),f.pendingPermission=void 0,f.reloadAfterTurn){f.reloadAfterTurn=!1;let A=f.downstream;A&&(f.downstream=void 0,K.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:l,acpId:f.acpSessionId}),A.stop("reload-after-turn").catch(y=>K.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:l,err:String(y)})))}else f.downstream?.isAlive()&&this.armIdleTimer(e,l,f)}}case"session/cancel":{let l=o.sessionId;if(!l)throw new C("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(l);if(e.hasSessionQueue(l)){let f=e.getSessionQueue(l);f.size>0&&(K.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:l,queuedCount:f.size}),f.dispose(new C("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${l}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,l=c.sessionId,u=c.modeId,f=ro(i._meta);if(!l)throw new C("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Kt(e))throw e.framework==="openclaw"?new C("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new C("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!En(e.framework,u))throw new C("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${ed(e.framework)}`);if(f)return await this.handleGroupSetMode(e,f,u);let p=e.sessions.get(l)??await this.ensureRuntime(e,l);if(p.permissionMode===u)return{};let m=p.permissionMode;if(p.permissionMode=u,await this.persistSessionMapping(e),p.downstream?.isAlive()&&p.acpSessionId)try{await p.downstream.setSessionMode({sessionId:p.acpSessionId,modeId:u})}catch(b){throw p.permissionMode=m,await this.persistSessionMapping(e).catch(()=>{}),b}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 C("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async handleGroupSetMode(e,r,i){let o=[];for(let[l,u]of e.sessions)u.cozeGroupId===r&&u.permissionMode!==i&&o.push({cloudId:l,runtime:u,oldMode:u.permissionMode});if(o.length===0)return 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,f=l.runtime.acpSessionId;u?.isAlive()&&f&&c.push({downstream:u,acpSessionId:f,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 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 Kt(e)&&(c.permissionMode=e.framework==="claude-code"?rd:D0),e.sessions.set(r,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,r){let i={sessionId:r,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(_t.GEN_MODEL_TOKEN,i,HE);if(!o?.modelToken)throw new C("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof C&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new C("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(Bi(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new C("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,l=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(l>=o&&Date.now()-u<c)throw new C("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${l} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let f;try{f=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(p){throw i.spawnFailCount=l+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(K.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),p}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(p){K.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(p)}),i.acpSessionId=void 0;let m=await f.sessionNew({cwd:e.workspace});i.acpSessionId=m.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let p=await f.sessionNew({cwd:e.workspace});i.acpSessionId=p.sessionId,await this.persistSessionMapping(e)}}catch(p){throw K.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(p)}),await f.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,p}if(f.afterSessionEstablished&&i.acpSessionId&&await f.afterSessionEstablished(i.acpSessionId),Kt(e)&&i.acpSessionId&&i.permissionMode)try{await f.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(p){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(p)})}}armIdleTimer(e,r,i){if(Bi(i),this.isRuntimeBusy(e,i)){K.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:r});return}i.idleTimer=setTimeout(()=>{if(i.idleTimer=void 0,this.isRuntimeBusy(e,i)){K.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}K.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:r});let o=i.downstream;i.downstream=void 0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),o&&o.stop("idle timeout").catch(c=>K.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:r,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,r){if(r.acpSessionId&&e.activeTriggers.has(r.acpSessionId))return!0;let i=r.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,r,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};if(r.acpSessionId){let l=e.activeTriggers.get(r.acpSessionId);l&&(c.cozeTriggerMsgId=l);let u=e.activeGroupIds.get(r.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Ir("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,l){let u={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(u.cozeTriggerMsgId=c),l&&(u.cozeGroupId=l),await this.upstream.send(Ir("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(f=>K.warn("synthesizePromptReply update send failed (ignored)",{err:String(f)})),{stopReason:"end_turn"}}forwardUpdate(e,r){let i=r.sessionId,o=this.reverseSessionId(e,i);if(!o){K.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){K.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if($E(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"&&Kt(e)){let m=l.currentModeId;En(e.framework,m)&&c.permissionMode!==m?(c.permissionMode=m,this.persistSessionMapping(e).catch(b=>K.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(b)}))):typeof m=="string"&&!En(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},f=e.activeTriggers.get(i);f&&(u.cozeTriggerMsgId=f);let p=e.activeGroupIds.get(i);p&&(u.cozeGroupId=p),this.upstream.send(Ir("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:Q.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},l=await Z0(c,o);r.respondAgentRequest(i.id,l)}else{let c=i.params??{},l=await Y0(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,Li(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,p={cozeAgentId:e.agentId};f&&(p.cozeTriggerMsgId=f);let m=u?e.activeGroupIds.get(u):void 0;m&&(p.cozeGroupId=m);let b=u?this.reverseSessionId(e,u):void 0,A=b?e.sessions.get(b):void 0;A&&(A.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let y={...c,...b?{sessionId:b}:{},_meta:p};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:b}),K.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:b,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(S=>({optionId:S.optionId,kind:S.kind,name:S.name}))}),this.upstream.send(Pi(o,"session/request_permission",y)).catch(S=>{this.pendingUpstream.delete(o),K.error("forward permission request failed",{agentId:e.agentId,err:String(S)}),r.respondAgentRequestError(i.id,{code:Q.INTERNAL_ERROR,message:`upstream send failed: ${String(S)}`})})}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"&&WE(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 co(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=zE){let o=this.upstreamIds.next(e);return new Promise((c,l)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),l(new C("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:l,timer:u}),this.upstream.send(Pi(o,e,r)).catch(f=>{let p=this.pendingBridge.get(o);p&&(clearTimeout(p.timer),this.pendingBridge.delete(o)),l(f)})})}async persistSessionMapping(e){if(this.paths)try{let r=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),o.permissionMode&&Kt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await ei(e.agentId,r,this.paths)}catch(r){K.warn("persist session mapping failed",{agentId:e.agentId,err:String(r)})}}reverseSessionId(e,r){for(let[i,o]of e.sessions.entries())if(o.acpSessionId===r)return i}sendError(e,r,i){return this.upstream.send(yn(e,{code:r,message:i,data:{bridgeVersion:Ar}}))}};function jE(){return FE(16).toString("hex")}function WE(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 KE=["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 $E(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 KE.some(c=>o.startsWith(c))}te();Oe();import{randomBytes as VE}from"node:crypto";import{chmod as JE,mkdir as ZE,writeFile as rx}from"node:fs/promises";import{createServer as YE}from"node:http";import{dirname as XE}from"node:path";var QE=1e6,od=q("ipc"),vo=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(r=>[`${r.method} ${r.path}`,r])),this.paths=e.paths??X()}async start(){this.token=VE(32).toString("hex");let e=YE((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(),od.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 ZE(XE(this.paths.portFile),{recursive:!0}),await rx(this.paths.portFile,String(this.port),"utf8"),await rx(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await JE(this.paths.tokenFile,384)}catch(e){od.warn("chmod token file failed (non-POSIX?)",{err:String(e)})}}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Gi(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Gi(r,404,{error:"not found"});return}let l=null;if(e.method==="POST")try{l=await eb(e)}catch(u){Gi(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(l,e);Gi(r,200,u??{ok:!0})}catch(u){od.error("IPC handler failed",{key:o,err:String(u)}),Gi(r,500,{error:u instanceof Error?u.message:String(u)})}}};function Gi(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function eb(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>QE)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 Ev=Ft(Qx(),1),bv=Ft(Po(),1),vv=Ft(Lr(),1),Sv=Ft(md(),1),Av=Ft(yd(),1),Iv=Ft(Id(),1),ch=Ft(Mo(),1),Tv=Ft(ah(),1);var dh=ch.default;We();te();var{FWS:Hv}=yh(),De=q("upstream.frontier"),bh="application/json",vh="none",jv=15e3;function Wv(t){class e extends dh{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(pl("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 Zi=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,...vr(this.opts.ppeOverride)},r=Wv(e),i=Mf(this.opts.urlOverride),o={url:i,ws:r,fpID:Pf,aID:so,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:bh,force:!0},payloadEncoding:{encoding:vh,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new Hv(o),l=!1,u=null,f,p,m=new Promise((y,S)=>{f=y,p=S}),b=y=>{l||(l=!0,u&&(clearTimeout(u),u=null),y?p(y):f())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let y=this.openCount===1;De.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:y,openCount:this.openCount}),y&&b();for(let S of this.connectHandlers)Promise.resolve(S({initial:y})).catch(I=>De.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=y=>{this.opened=!1,De.info("frontier closed",{code:y.code,reason:y.reason,willReconnect:y.willReconnect})},c.onerror=y=>{De.warn("frontier error",{code:y.code,msg:y.message}),b(new C("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${y.code} msg=${y.message??""}`))},c.onmessage=y=>this.handleMessage(y),this.fws=c;let A=this.opts.openTimeoutMs??jv;u=setTimeout(()=>{b(new C("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${A}ms (handshake or upgrade slow)`))},A),await c.connect();try{await m}catch(y){try{c.close(1e3,"open failed")}catch(S){De.warn("fws close during start failure threw (ignored)",{err:String(S)})}throw this.fws=null,this.opened=!1,y}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){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 C("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 C("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${r.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;Sh(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:bh,payloadEncoding:vh})}catch(u){throw De.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new C("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){De.debug("drop non-adapter frontier frame",{service:r});return}let i=Vv(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;Sh(c)||De.info("frontier frame in",{logid:$v(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:Kv(i)}),Promise.resolve(this.handler(o)).catch(l=>De.warn("frontier frame handler threw",{err:String(l)}))}};function Sh(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Ah=2e3;function Kv(t){return t.length<=Ah?t:`${t.slice(0,Ah)}...<truncated, total ${t.length} chars>`}function $v(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function Vv(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}}te();var kd=q("upstream.switchable"),Wo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;kd.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 kd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>kd.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 Dd=q("upstream"),Ur=class{handler=null;async start(){Dd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Dd.info("NoopUpstream stopped",{reason:e})}async send(e){Dd.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();te();Oe();import{promises as Pd}from"node:fs";import{dirname as Jv}from"node:path";var Zv=q("pat-token-store");async function Ko(t=X()){try{let r=(await Pd.readFile(t.patTokenFile,"utf8")).trim();return r.length>0?r:null}catch(e){let r=e?.code;return r!=="ENOENT"&&Zv.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function Yi(t,e=X()){if(!t)throw new Error("writePatToken: empty patToken");await Pd.mkdir(Jv(e.patTokenFile),{recursive:!0}),await Pd.writeFile(e.patTokenFile,t,{encoding:"utf8",mode:384})}Oe();Oe();import{promises as $o}from"node:fs";import{join as Yv}from"node:path";function Xv(t,e){return`#!/bin/sh
|
|
99
|
+
`)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var eb={path:"",version:"cloud-deployed"},T0="openclaw_gateway_unavailable",tb="openclaw_default_agent_missing";function k0(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 nb={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},rb=6e4,mo=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;detectorFactory;openclawEnvBootstrapPromise;openclawConfigFactory;openclawConfigDir;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??Zy,this.createTimeoutMs=e.createTimeoutMs??rb,this.detectorFactory=e.detectorFactory??(()=>new jn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new po({command:r})),this.openclawConfigDir=e.openclawConfigDir??A0(Jy(),".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 k("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{le.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=A0(e,".env");if(await $y(r).then(c=>c.isFile()).catch(()=>!1)){le.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}await go(e,{recursive:!0});let o=Xy({...process.env,...Yc(this.paths.agentEnvFile)});if(await Vy(r,o,"utf8"),process.platform!=="win32")try{await Wy(r,384)}catch(c){le.warn("chmod ~/.openclaw/.env to 0600 failed (ignored)",{err:String(c)})}le.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),le.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new k("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new k("IPC_BAD_REQUEST","framework required");let i=await Me(e.agentId,this.paths).catch(()=>null),o=to(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 k("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")le.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(C=>le.warn("dispose stale agent failed (ignored)",{err:String(C)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")le.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(C=>le.warn("dispose drifted agent failed (ignored)",{err:String(C)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){le.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let C=await Me(e.agentId,this.paths).catch(()=>null);C&&(C.patToken=e.patToken,await Qe(C,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){le.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let C=await Me(e.agentId,this.paths).catch(()=>null);C&&(C.modelInfo=e.modelInfo,await Qe(C,this.paths))}return le.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new k("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=Xe(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),I=e.workspace??E??u.workspace,y=new AbortController,v=setTimeout(()=>y.abort(new k("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),A,T=!1;try{o&&ed(e.framework)&&await rr(e.framework,y.signal);let C=()=>{if(y.signal.aborted)throw y.signal.reason instanceof Error?y.signal.reason:new k("AGENT_TIMEOUT","_agent/create aborted")};await go(u.root,{recursive:!0}),await go(I,{recursive:!0}),await go(u.logs,{recursive:!0}),C(),h||await or(I,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(x==="cloud"?await Ta(I,"cloud"):await Ta(I,"local",td)),C();let P=i,b=Bf({model:e.model??P?.model}),R=If(e._meta)??P?.accountId,O=e.patToken??P?.patToken,F=x==="cloud"?e.modelInfo??P?.modelInfo:void 0;if(A=new xo({agentId:e.agentId,framework:e.framework,workspace:I,model:b.model??yt,deployType:x,...R?{accountId:R}:{},...O?{patToken:O}:{},...F?{modelInfo:F}:{}}),A.status="ok",P?.sessions){let $=x==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[Z,ie]of Object.entries(P.sessions)){let oe={acpSessionId:ie.acpSessionId,modelToken:ie.modelToken,tokenGeneratedAt:ie.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};$?ie.permissionMode===void 0?(oe.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",le.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:Z,framework:e.framework,fallback:oe.permissionMode})):En(e.framework,ie.permissionMode)?oe.permissionMode=ie.permissionMode:le.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:Z,framework:e.framework,value:ie.permissionMode}):ie.permissionMode!==void 0&&le.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:Z,framework:e.framework,deployType:x}),ie.cozeGroupId&&(oe.cozeGroupId=ie.cozeGroupId),A.sessions.set(Z,oe)}let te=Object.keys(P.sessions).length;te>0&&le.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:te})}this.registry.register(A),T=!0;let B={agentId:e.agentId,framework:e.framework,workspace:I,cozeIdentity:e.cozeIdentity,createdAt:P?.createdAt??Date.now(),sessions:P?.sessions??{},model:b.model};x==="cloud"&&(B.deployType="cloud"),R&&(B.accountId=R),O&&(B.patToken=O),F&&(B.modelInfo=F),P?.skills&&(B.skills=P.skills),P?.agentName&&(B.agentName=P.agentName),P?.description&&(B.description=P.description),e.framework==="openclaw"&&x==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,I)):le.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 $=[...B.skills??[]],te=new Map($.map((oe,L)=>[oe.skillId,L])),Z=await Promise.allSettled(Y.map(oe=>$c({agentId:e.agentId,workspace:I,framework:e.framework,skill:oe}))),ie=0;for(let[oe,L]of Z.entries()){let H=Y[oe];H&&(L.status==="fulfilled"?(Vc($,te,L.value),ie++):le.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:H.skillId,skillName:H.skillName,err:String(L.reason)}))}ie>0&&(B.skills=$,le.info("initialSkills installed",{agentId:e.agentId,installed:ie,requested:Y.length}))}return await Qe(B,this.paths),le.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:x}),{ok:!0,agentId:e.agentId,workspace:I,framework:e.framework}}catch(C){throw le.error("agent create failed, rolling back",{agentId:e.agentId,err:String(C)}),T&&A&&(await A.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Ky(u.root,{recursive:!0,force:!0}).catch(P=>le.warn("rm agent dir failed (ignored)",{err:String(P)})),C instanceof k?C:new k("AGENT_SPAWN_FAILED",String(C),{cause:C})}finally{clearTimeout(v)}}async spawnSessionDownstream(e,r,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&ed(e.framework))u=eb;else throw new k("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);ed(e.framework)&&!as(e.framework)&&(le.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await rr(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=Kt(e)?m?.permissionMode??C0:"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(nb),h}catch(m){let E=h instanceof Pt?h.getStderrTail():[];throw E.length>0&&le.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:m instanceof k?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 k("AGENT_ENV_NOT_READY",k0(o),{cause:{reason:T0}})}catch(o){le.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof k?i:new k("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};le.warn("openclaw default agent stale or missing, attempting lazy re-detect");let r=await this.detectorFactory().detect("openclaw");if(r?.defaultAgent?.id&&r.defaultAgent.workspace)return le.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new k("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:tb}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new k("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new k("AGENT_ENV_NOT_READY",k0(r),{cause:{reason:T0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:l,command:u}=e,x=Qc(o);if(r.deployType==="local"){let I=await this.ensureOpenclawDefaultAgent();return new Pr({command:u,cwd:I.workspace,agentId:I.id,sessionName:x})}let h=await I0(),m=i?jf(i,c,l):null,E;if(m){let I=Uc(o),v=m.models[0]?.id??yt,A=`${I}/${v}`;if(!this.ensuredProviders.has(A)){let T=this.getOpenclawConfig();await T.ensureProvider(I,m),await T.addModelToAllowlist(A),this.ensuredProviders.add(A)}E=A}return new Pr({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=Uc(i),c=`${o}/${e.model}`,l=!0;try{await r.removeProvider(o)}catch(u){l=!1,le.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:o,err:String(u)})}try{await r.removeModelFromAllowlist(c)}catch(u){l=!1,le.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:c,err:String(u)})}l&&this.ensuredProviders.delete(c)}}};import{randomUUID as N0}from"node:crypto";import{promises as ub}from"node:fs";import{basename as M0}from"node:path";Ke();ne();import{promises as sb}from"node:fs";import{basename as ob}from"node:path";var D0=G("file-upload"),ab="/api/coze_claw/file/agent_upload",cb=6e4;async function P0(t,e={}){let i=`${ro(so(e.handshakeBase))}${ab}`,o=e.timeoutMs??cb,c=await sb.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",...Sr(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},x=new AbortController,h=setTimeout(()=>x.abort(),o);D0.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 k("UPLOAD_FAILED",`upload HTTP ${m.status} logid=${E}: ${v.slice(0,200)}`)}let I=await m.json();if(I.code!==void 0&&I.code!==0)throw new k("UPLOAD_FAILED",`upload code=${I.code} msg=${I.msg??"-"} logid=${E}`);let y=I.data?.file?.file_url;if(!y)throw new k("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${E}: ${JSON.stringify(I).slice(0,200)}`);return D0.info("file upload ok",{uri:y,logid:E}),{uri:y}}catch(m){throw m instanceof k?m:m.name==="AbortError"?new k("UPLOAD_FAILED",`upload timeout (${o}ms) for ${ob(t.path)}`):new k("UPLOAD_FAILED",String(m),{cause:m})}finally{clearTimeout(h)}}Ke();ne();import{extname as db}from"node:path";var lb={".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 O0(t){let e=db(t).toLowerCase();return lb[e]??"application/octet-stream"}Pe();var wo=G("agent-send"),L0=50*1024*1024;function B0(t,e,r){let i=t.get(e);if(!i)throw new k("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new k("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new k("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function F0(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&&(wo.warn("sendAgentFileUpdate failed, retrying",{attempt:x+1,err:String(h)}),await new Promise(m=>setTimeout(m,5e3)))}throw new k("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function z0(t,e){let{session:r,runtime:i}=B0(e.core,t.agentId,t.sessionId);if(!await ei(t.path,r.workspace))throw new k("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await ub.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new k("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>L0)throw new k("FILE_TOO_LARGE",`${o.size} bytes > limit ${L0}`);let c=await O0(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new k("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new k("UPSTREAM_NOT_READY","cloud WS not connected");let l=t.name??M0(t.path),u;try{u=await P0({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 wo.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:h instanceof k?h.code:"UNKNOWN",message:h instanceof Error?h.message:String(h)}),h}let x={sessionUpdate:"agent_file",messageId:N0(),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 F0(e,r,i,t.sessionId,x,"agent file uploaded to cloud but sendAgentFileUpdate failed"),wo.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 U0(t,e){let{session:r,runtime:i}=B0(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new k("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new k("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??M0(t.path),c={sessionUpdate:"group_file",messageId:N0(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await F0(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),wo.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 G0(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}rn();Wt();ne();var Ot=G("coze-cli-installer"),H0="@coze/cli@latest",fb="coze",j0="0.1.8",xb=5e3,hb=5e3,pb=9e4,q0=1e4,zi=null,_o=!1;async function nd(t,e={}){if(_o)return;if(zi)return zi;let r=e.exec??Rf;return zi=(async()=>{try{let i=await gb(fb,r),o=!1;if(i){let l=await mb(r);if(l===void 0)Ot.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(G0(l,j0))Ot.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:l,min:j0}),o=!0;else{Ot.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:l}),_o=!0;return}}let c=o?"upgrade-only":"full";Ot.info("coze-cli install start",{package:H0,mode:c});try{await r("npm",["i","-g","--prefer-online",H0],{timeout:pb,maxBuffer:10*1024*1024}),Ot.info("coze-cli install ok")}catch(l){Ot.warn("coze-cli install failed (skip subsequent steps)",{err:String(l)});return}if(o){_o=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:q0}),Ot.info("coze config set xTTEnv ok",{env:t.env})}catch(l){Ot.warn("coze config set failed (continue to auth login)",{err:String(l)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:q0}),Ot.info("coze auth login ok")}catch(l){Ot.warn("coze auth login failed",{err:String(l)});return}_o=!0}finally{zi=null}})(),zi}async function gb(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:xb});return Ia(i)}catch{return}}async function mb(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:hb});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}Qr();Pe();var wb=10*6e4;function W0(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?wb:e}function yo(t){return ir(t??Q().configFile)}function Ui(t,e){return sr(e??Q().configFile,t)}import{randomBytes as Fb}from"node:crypto";er();Ke();ne();import{createReadStream as _b}from"node:fs";import{mkdir as yb,readFile as bb,realpath as Eb,stat as vb,writeFile as Sb}from"node:fs/promises";import{basename as Ib,dirname as rd,isAbsolute as Ab,join as Tb,relative as kb,resolve as K0,sep as Cb}from"node:path";import{createInterface as Rb}from"node:readline";var V0=G("fs-rpc"),Gi=We("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function J0(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Gi)throw new k("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Gi} bytes`);let i=await Z0(t.path,e);return await yb(rd(i),{recursive:!0}),await Sb(i,t.content,"utf8"),V0.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function Y0(t,e){let r=await Z0(t.path,e),i=await vb(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Gi&&!o)throw new k("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Gi} bytes`);let c;if(o&&i.size>Gi)c=await Db(r,t.line??1,t.limit);else{let l=await bb(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 V0.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function Db(t,e,r){let i=Rb({input:_b(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 Z0(t,e){if(typeof t!="string"||t.length===0)throw new k("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([$0(K0(e)),$0(K0(t))]),o=kb(r,i);if(Pb(o,Cb,Ab(o)))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function Pb(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function $0(t){let e=[],r=t;for(;r!==rd(r);)try{let i=await Eb(r);return e.length?Tb(i,...e.reverse()):i}catch{e.push(Ib(r)),r=rd(r)}return t}ne();var X0=G("prompt-multimodal"),Q0=10*1024*1024,Ob=15e3,Lb=6;async function ex(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 Nb(l))}}let o=Array.from({length:Math.min(Lb,t.length)},()=>i());return await Promise.all(o),e}function tx(t){return t.some(e=>e.type==="image")}async function Nb(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!ki(e.uri))return t;try{let{buf:r,contentType:i}=await Bb(e.uri),o=e.mimeType||Mb(i)||"application/octet-stream";return X0.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 X0.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function Mb(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function Bb(t){let e=new AbortController,r=setTimeout(()=>e.abort(),Ob);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>Q0)throw new Error(`image too large: ${o.byteLength} bytes (max ${Q0})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}sn();Ke();ne();var q=G("core"),zb=3e4,Ub=/^(boe|ppe)_[A-Za-z0-9_-]+$/,Gb="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",Hb="\u5BA1\u6279\u5DF2\u8D85\u65F6",jb=3e4,bo=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Cr;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=W0(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(),q.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){q.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),q.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){q.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)&&q.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)=>{q.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:l}),Fi(i),i.downstream=void 0,i.replySeq=0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),this.rejectPendingForDownstream(o,"downstream exited")}))}hasPendingPermissionFor(e){for(let r of this.pendingUpstream.values())if(r.downstream===e)return!0;return!1}rejectPendingForDownstream(e,r){let i=[];for(let[o,c]of this.pendingUpstream)c.downstream===e&&i.push(o);if(i.length!==0){q.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(bn(o,{code:ee.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(l=>q.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)){q.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 k("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(co(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&&Ub.test(i)?this.currentCozeEnv=i:i&&q.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}`):q.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(kr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(kr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(kr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,ee.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):q.warn("drop unknown notification",{method:e.method})}catch(o){q.error("handleFrame failed",{method:e.method,err:String(o)}),r!==null&&await this.upstream.send(bn(r,Ni(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new k("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new k("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new k("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new k("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=no(r._meta);return q.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,x,c,Gb,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{q.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=qb();return q.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return q.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 k("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=Kt(e)?Af(i._meta):void 0;if(u!==void 0&&!En(e.framework,u))throw new k("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${Xc(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 k("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&x.permissionMode!==void 0&&x.permissionMode!==u){let I=x.permissionMode;x.permissionMode=u,await this.persistSessionMapping(e);try{await x.downstream.setSessionMode({sessionId:x.acpSessionId,modeId:u})}catch(y){throw x.permissionMode=I,await this.persistSessionMapping(e).catch(()=>{}),y}}let h=i._meta?.cozeTriggerMsgId;h?e.activeTriggers.set(x.acpSessionId,h):e.activeTriggers.delete(x.acpSessionId);let m=no(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&&tx(c.prompt))throw new k("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let E=await ex(c.prompt);try{let I=await x.downstream.sessionPrompt({...c,sessionId:x.acpSessionId,prompt:E});return x.lastActiveAt=Date.now(),I}catch(I){if(I instanceof k&&I.code==="AGENT_APPROVAL_TIMEOUT"){let y=x.pendingPermission;y&&(y.downstream.respondAgentRequest(y.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(y.upstreamId),x.pendingPermission=void 0);let v=x.acpSessionId,A=v?e.activeTriggers.get(v):void 0,T=v?e.activeGroupIds.get(v):void 0;return q.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:l}),await this.synthesizePromptReply(e,x,l,Hb,A,T)}throw I}finally{if(e.activeTriggers.delete(x.acpSessionId),e.activeGroupIds.delete(x.acpSessionId),x.pendingPermission=void 0,x.reloadAfterTurn){x.reloadAfterTurn=!1;let I=x.downstream;I&&(x.downstream=void 0,q.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:l,acpId:x.acpSessionId}),I.stop("reload-after-turn").catch(y=>q.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:l,err:String(y)})))}else x.downstream?.isAlive()&&this.armIdleTimer(e,l,x)}}case"session/cancel":{let l=o.sessionId;if(!l)throw new k("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&&(q.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:l,queuedCount:x.size}),x.dispose(new k("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=no(i._meta);if(!l)throw new k("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Kt(e))throw e.framework==="openclaw"?new k("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new k("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!En(e.framework,u))throw new k("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${Xc(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 q.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:l,modeId:u});return{}}default:throw new k("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 q.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i}),{};q.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 Kt(e)&&(c.permissionMode=e.framework==="claude-code"?td:R0),e.sessions.set(r,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,r){let i={sessionId:r,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(_t.GEN_MODEL_TOKEN,i,jb);if(!o?.modelToken)throw new k("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof k&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new k("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(Fi(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new k("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 k("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&&(q.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}),q.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(h){q.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 q.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),Kt(e)&&i.acpSessionId&&i.permissionMode)try{await x.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(h){q.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(Fi(i),this.isRuntimeBusy(e,i)){q.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)){q.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}q.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=>q.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(Tr("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(Tr("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(x=>q.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){q.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){q.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if($b(r)){q.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"&&Kt(e)){let m=l.currentModeId;En(e.framework,m)&&c.permissionMode!==m?(c.permissionMode=m,this.persistSessionMapping(e).catch(E=>q.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(E)}))):typeof m=="string"&&!En(e.framework,m)&&q.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(Tr("session/update",{...r,sessionId:o,_meta:u})).catch(m=>q.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}q.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:ee.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},l=await J0(c,o);r.respondAgentRequest(i.id,l)}else{let c=i.params??{},l=await Y0(c,o);r.respondAgentRequest(i.id,l)}}catch(o){q.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Ni(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,I=E?e.sessions.get(E):void 0;I&&(I.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let y={...c,...E?{sessionId:E}:{},_meta:h};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:E}),q.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(Oi(o,"session/request_permission",y)).catch(v=>{this.pendingUpstream.delete(o),q.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?(q.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"&&Wb(e.result,o),q.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 ao(e.error)):i.value.resolve(e.result);return}q.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 q.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:l,key:c}}}sendRequest(e,r,i=zb){let o=this.upstreamIds.next(e);return new Promise((c,l)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),l(new k("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:l,timer:u}),this.upstream.send(Oi(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&&Kt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await ti(e.agentId,r,this.paths)}catch(r){q.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(bn(e,{code:r,message:i,data:{bridgeVersion:Ar}}))}};function qb(){return Fb(16).toString("hex")}function Wb(t,e){if(!t||typeof t!="object"){q.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){q.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"){q.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")&&q.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var Kb=["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 $b(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 Kb.some(c=>o.startsWith(c))}ne();Pe();import{randomBytes as Vb}from"node:crypto";import{chmod as Jb,mkdir as Yb,writeFile as nx}from"node:fs/promises";import{createServer as Zb}from"node:http";import{dirname as Xb}from"node:path";var Qb=1e6,id=G("ipc"),Eo=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=Vb(32).toString("hex");let e=Zb((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(),id.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 Yb(Xb(this.paths.portFile),{recursive:!0}),await nx(this.paths.portFile,String(this.port),"utf8"),await nx(this.paths.tokenFile,this.token,{encoding:"utf8",mode:384});try{await Jb(this.paths.tokenFile,384)}catch(e){id.warn("chmod token file failed (non-POSIX?)",{err:String(e)})}}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Hi(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Hi(r,404,{error:"not found"});return}let l=null;if(e.method==="POST")try{l=await eE(e)}catch(u){Hi(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(l,e);Hi(r,200,u??{ok:!0})}catch(u){id.error("IPC handler failed",{key:o,err:String(u)}),Hi(r,500,{error:u instanceof Error?u.message:String(u)})}}};function Hi(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function eE(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>Qb)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 bv=Ft(Xx(),1),Ev=Ft(Do(),1),vv=Ft(Nr(),1),Sv=Ft(pd(),1),Iv=Ft(wd(),1),Av=Ft(Sd(),1),ah=Ft(No(),1),Tv=Ft(oh(),1);var ch=ah.default;Ke();ne();var{FWS:jv}=_h(),Re=G("upstream.frontier"),bh="application/json",Eh="none",qv=15e3;function Wv(t){class e extends ch{constructor(i){super(i,Pf,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>Re.warn("frontier ws error during teardown (handled, prevents daemon crash)",{err:i instanceof Error?i.message:String(i)}))}close(i,o){this.guardTeardown(),super.close(i,o)}terminate(){this.guardTeardown(),super.terminate()}send(i,...o){if(hl("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let l=Buffer.from(c.slice(0,128)).toString("hex");Re.debug("WS raw frame out",{bytes:c.byteLength,headHex:l})}catch(c){Re.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var Zi=class{constructor(e){this.opts=e}opts;fws=null;handler=null;connectHandlers=[];opened=!1;lastSendRefusedLogAt=0;sendRefusedSuppressed=0;openCount=0;async start(){if(this.fws){Re.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Of,...Sr(this.opts.ppeOverride)},r=Wv(e),i=Nf(this.opts.urlOverride),o={url:i,ws:r,fpID:Df,aID:io,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:bh,force:!0},payloadEncoding:{encoding:Eh,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new jv(o),l=!1,u=null,x,h,m=new Promise((y,v)=>{x=y,h=v}),E=y=>{l||(l=!0,u&&(clearTimeout(u),u=null),y?h(y):x())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let y=this.openCount===1;Re.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:y,openCount:this.openCount}),y&&E();for(let v of this.connectHandlers)Promise.resolve(v({initial:y})).catch(A=>Re.warn("onConnect handler threw (ignored)",{err:String(A)}))},c.onclose=y=>{this.opened=!1,Re.info("frontier closed",{code:y.code,reason:y.reason,willReconnect:y.willReconnect})},c.onerror=y=>{Re.warn("frontier error",{code:y.code,msg:y.message}),E(new k("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${y.code} msg=${y.message??""}`))},c.onmessage=y=>this.handleMessage(y),this.fws=c;let I=this.opts.openTimeoutMs??qv;u=setTimeout(()=>{E(new k("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${I}ms (handshake or upgrade slow)`))},I),await c.connect();try{await m}catch(y){try{c.close(1e3,"open failed")}catch(v){Re.warn("fws close during start failure threw (ignored)",{err:String(v)})}throw this.fws=null,this.opened=!1,y}}async stop(e){let r=this.fws;if(r){this.fws=null,this.opened=!1;try{r.close(1e3,e??"bridge shutdown")}catch(i){Re.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw Re.warn("frontier send refused: upstream not started",{method:i}),new k("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let u=Date.now();throw u-this.lastSendRefusedLogAt>1e3?(Re.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:r.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=u,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new k("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;vh(c)||Re.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:bh,payloadEncoding:Eh})}catch(u){throw Re.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new k("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){Re.debug("drop non-adapter frontier frame",{service:r});return}let i=Vv(e);if(!i){Re.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){Re.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(l){Re.warn("frontier message JSON parse failed",{err:String(l),head:i.slice(0,80)});return}let c=o;vh(c)||Re.info("frontier frame in",{logid:$v(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:Kv(i)}),Promise.resolve(this.handler(o)).catch(l=>Re.warn("frontier frame handler threw",{err:String(l)}))}};function vh(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Sh=2e3;function Kv(t){return t.length<=Sh?t:`${t.slice(0,Sh)}...<truncated, total ${t.length} chars>`}function $v(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function Vv(t){let e=t.message;if(e?.textPayload)return e.textPayload;let r=e?.payload;if(!r)return null;try{return Buffer.from(r).toString("utf8")}catch{return null}}ne();var kd=G("upstream.switchable"),qo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;kd.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 kd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>kd.warn("previous upstream stop threw (ignored)",{err:String(o)}))}current(){return this.inner}start(){return this.inner.start()}stop(e){return this.inner.stop(e)}send(e){return this.inner.send(e)}onFrame(e){this.handler=e,this.inner.onFrame(e)}onConnect(e){this.connectHandlers.push(e),this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};ne();var Cd=G("upstream"),Gr=class{handler=null;async start(){Cd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){Cd.info("NoopUpstream stopped",{reason:e})}async send(e){Cd.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};Ke();ne();ne();Pe();import{promises as Rd}from"node:fs";import{dirname as Jv}from"node:path";var Yv=G("pat-token-store");async function Wo(t=Q()){try{let r=(await Rd.readFile(t.patTokenFile,"utf8")).trim();return r.length>0?r:null}catch(e){let r=e?.code;return r!=="ENOENT"&&Yv.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function Xi(t,e=Q()){if(!t)throw new Error("writePatToken: empty patToken");await Rd.mkdir(Jv(e.patTokenFile),{recursive:!0}),await Rd.writeFile(e.patTokenFile,t,{encoding:"utf8",mode:384})}Pe();Pe();import{promises as Ko}from"node:fs";import{join as Zv}from"node:path";function Xv(t,e){return`#!/bin/sh
|
|
103
103
|
exec ${JSON.stringify(e)} ${JSON.stringify(t)} "$@"
|
|
104
104
|
`}function Qv(t,e){return`@echo off\r
|
|
105
105
|
"${e}" "${t}" %*\r
|
|
106
|
-
`}async function Ih(t,e=
|
|
106
|
+
`}async function Ih(t,e=Q()){let r=e.binDir;await Ko.mkdir(r,{recursive:!0});let i=Zv(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?Qv(t,o):Xv(t,o);return await Ko.readFile(i,"utf8").catch(()=>null)===c||(await Ko.writeFile(i,c,"utf8"),process.platform!=="win32"&&await Ko.chmod(i,493)),r}ne();Pe();import{execSync as Ah}from"node:child_process";import{readFileSync as Th,unlinkSync as eS}from"node:fs";import{mkdir as tS,open as nS,readFile as kh,unlink as Dd,writeFile as rS}from"node:fs/promises";import{dirname as iS}from"node:path";var sS=G("single-instance"),oS=t=>new Promise(e=>setTimeout(e,t)),$o=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=>Mi(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&&sS.warn("removing stale pid file",{stalePid:i}),await rS(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 kh(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Dd(this.pidFile)}catch{}this.acquired=!1}}isLiveDaemon(e){return this.probe.isAlive(e)&&this.probe.isDaemon(e)}async readExistingPid(){return this.readPidFrom(this.pidFile)}async readPidFrom(e){try{let r=await kh(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 tS(iS(r),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await nS(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 oS(this.claimLockIntervalMs);continue}await Dd(r).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Dd(r).catch(()=>{})}}throw new Error(`failed to acquire claim lock: ${r} (after ${this.claimLockMaxAttempts} attempts)`)}matchesDaemonTitle(e){if(process.platform==="win32")return this.matchesDaemonTitleWindows(e);try{let r=Th(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes(Rr)||r.includes("lib/index.js"))}catch{}try{let r=Ah(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes(Rr)||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=Ah(`tasklist /FI "PID eq ${e}" /FO CSV /NH`,{stdio:["ignore","pipe","ignore"],timeout:2e3}).toString().trim();if(!i||/^(INFO|信息)[::]/.test(i))return!1;let o=i.split(",",1)[0]?.replace(/^"|"$/g,"").toLowerCase()??"";return o.includes("node")||o.includes("coze-bridge")}catch{return!0}}installCleanupHooks(){process.once("exit",()=>{if(this.acquired)try{Th(this.pidFile,"utf8").trim()===String(this.selfPid)&&eS(this.pidFile)}catch{}})}};Vo();ne();var Jn=G("daemon.upstream-watchdog"),hS=12e4,pS=9e5,gS=3e4;function Od(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var Jo=class{constructor(e){this.opts=e;this.softMs=e.softMs??Od("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",hS),this.hardMs=e.hardMs??Od("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",pS),this.intervalMs=e.intervalMs??Od("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",gS),this.now=e.now??Date.now}opts;softMs;hardMs;intervalMs;now;timer=null;downSince=null;forcedAt=null;forcing=!1;lastTickAt=null;start(){this.timer||(this.timer=setInterval(()=>this.tick(),this.intervalMs),this.timer.unref?.(),Jn.info("upstream watchdog started",{softMs:this.softMs,hardMs:this.hardMs,intervalMs:this.intervalMs}))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null),this.downSince=null,this.forcedAt=null,this.lastTickAt=null}tick(){let e=this.now();if(this.lastTickAt!==null&&e-this.lastTickAt>this.intervalMs*3&&(this.downSince!==null&&Jn.warn("upstream watchdog: large tick gap (likely sleep/suspend), resetting downSince",{gapMs:e-this.lastTickAt}),this.downSince=null,this.forcedAt=null),this.lastTickAt=e,this.opts.isConnected()){this.downSince!==null&&Jn.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,Jn.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){Jn.error("upstream watchdog: disconnected too long, exiting for supervisor restart",{downMs:r,hardMs:this.hardMs}),this.opts.onFatal(r);return}r>=this.softMs&&this.shouldForceNow(e)&&(this.forcedAt=e,this.forcing=!0,Jn.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>Jn.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var j=G("daemon");async function Dh(){let t=Q();if(process.env.COZE_BRIDGE_LOG_MODE!=="legacy"){fl({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:L=>Xe(L,t).logs,listAgentIds:()=>cs(t)});try{let{writeFileSync:L}=await import("node:fs");L(t.logFile,`\u8FD0\u884C\u65E5\u5FD7\u5DF2\u8FC1\u79FB\u5230 dated \u6587\u4EF6, \u6B64\u6587\u4EF6 (bridge.log) \u4E0D\u518D\u5199\u5165\u8FD0\u884C\u65E5\u5FD7\u3002
|
|
107
107
|
\u8BF7\u67E5\u770B: ${t.bridgeLogsDir}/bridge-<YYYY-MM-DD>.log
|
|
108
108
|
\u6216\u4F7F\u7528: coze-bridge log [-f] [--lines N]
|
|
109
|
-
`)}catch{}}let e=new Vo({processTitle:Rr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await Eo(),o=i??{};as({pid:process.pid}),W.info(i?"loaded bridge config":"initialized bridge config");let c=new Wo(new Ur),l=null,u=new bo({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(O,H,$,se)=>{if(!l)throw new Error("agentManager not ready");return l.spawnSessionDownstream(O,H,$,se)}}),f=new wo({paths:t,config:o,registry:u});l=f;let p,m,b=null,A={},y,S=null,I=null,T=null,R=new bn;function D(O,H){return R.enqueue(()=>k(O,H))}function E(){I||(I=new Zo({isConnected:()=>c.isConnected(),forceReconnect:()=>T?D(T,{force:!0}):void 0,onFatal:O=>{if(process.env[Xi]==="1"){W.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:O});return}W.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:O}),process.exit(1)}})),I.start()}async function k(O,H){let $=O,se=$?.privatecode;if(!se)throw new C("IPC_BAD_REQUEST","/connect requires privatecode");let Je=Ri($.env),xe=$.handshake_url,he=$.frontier_url,vt=Dh($.env,xe,he);if(T=$,!H?.force&&p===se&&m===vt){let me=await mS(t);return u.agents.size===0&&me?(W.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),Xo(t,f).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 ut=!!p&&p!==se,Xt=m!==void 0&&m!==vt,Bt=ut||Xt,Qt=await Fc({privatecode:se,...xe?{endpoint:xe}:{},ppeOverride:Je});if(Bt){W.warn("connect config switched, resetting agents",{pcChanged:ut,envChanged:Xt,previousPc:p?Yo(p):"",nextPc:Yo(se)});for(let me of[...u.agents.values()])await me.dispose("connect config switch").catch(()=>{}),u.agents.delete(me.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 Ur,"connect switch").catch(()=>{})}b=Qt.deviceId,as({deviceId:b,pid:process.pid}),id({patToken:se,env:$.env}).catch(me=>W.warn("coze-cli setup error (ignored)",{err:String(me)}));let Wr=new Zi({handshake:Qt,privatecode:se,...he?{urlOverride:he}:{},ppeOverride:Je,getPatTokenForAgent:me=>u.agents.get(me)?.patToken});return await c.swap(Wr,"connect"),p=se,m=vt,A=Je,y=xe,$.mock_scenario!==void 0&&(u.setMockScenario($.mock_scenario),W.info("mock scenario set",{scenario:$.mock_scenario})),S||(S=new Di({core:u,getDeviceId:()=>b??"",onTickEnd:()=>M.retryPending().catch(me=>W.warn("detailSync.retryPending failed (ignored)",{err:String(me)})),onAuthFailures:J})),S.start(),E(),Bt&&Xo(t,f).catch(me=>W.warn("post-connect-switch auto-revive error (ignored)",{err:String(me)})),Yi(se,t).catch(me=>W.warn("writePatToken after /connect failed (ignored)",{err:String(me)})),W.info("/connect: WS established",{deviceId:b}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async O=>f.createAgent(O.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let P={},F=new ao({agents:u.agents,disposeAndMarkDisconnected:async(O,H)=>{let $=u.agents.get(O);if($){await f.cleanupOpenclawSessionProviders($).catch(Je=>W.warn("cleanup openclaw providers failed (ignored)",{agentId:O,err:String(Je)}));let se=!0;try{await $.dispose(`disconnect: ${H}`)}catch(Je){se=!1,W.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:O,err:String(Je)}),$.status="error"}se&&($.status="disconnected",u.unregister(O),u.disconnectedAgents.add(O))}else u.disconnectedAgents.add(O)},detailSyncer:async O=>{if(!P.ref)throw new Error("agent-detail-sync not initialized yet");await P.ref.syncOne(O)},cleanupOpenclawProviders:async O=>{await f.cleanupOpenclawSessionProviders(O)},openclawRepair:async(O,H)=>{await f.openclawRepair(O,H)},isRuntimePendingPermission:O=>u.hasPendingPermissionFor(O)});u.registerExtension("_agent/listSkills",O=>F.listSkills(O.params)),u.registerExtension("_agent/addSkills",O=>F.addSkills(O.params)),u.registerExtension("_agent/removeSkills",O=>F.removeSkills(O.params)),u.registerExtension("_agent/getFileTree",O=>F.getFileTree(O.params)),u.registerExtension("_agent/getFileContent",O=>F.getFileContent(O.params)),u.registerExtension("_agent/update",O=>F.updateAgent(O.params)),u.registerExtension("_agent/disconnect",O=>F.disconnectAgent(O.params)),u.registerExtension("_agent/switchModel",O=>F.switchModel(O.params)),u.registerExtension("_agent/reset",O=>F.resetAgent(O.params)),u.registerExtension("_agent/repair",O=>F.repairAgent(O.params)),u.registerExtension("_agent/upgrade",O=>F.upgradeBridge(O.params));let M=new xs({paths:t,handlers:F,agentManager:f,sendDetail:O=>u.sendRequest("_agent/detail",O)});P.ref=M;let J=async O=>{await Promise.allSettled(O.map(async H=>{try{await F.disconnectAgent({agentId:H.agentId,reason:`auth_failure: code=${H.code} ${H.message}`}),W.info("agent disconnected due to auth failure from heartbeat response",{agentId:H.agentId,code:H.code,message:H.message})}catch($){W.warn("disconnect during authFailure handling failed (ignored)",{agentId:H.agentId,err:String($)})}}))};c.onConnect(({initial:O})=>{W.info("frontier upstream connected, triggering detail sync",{initial:O}),M.syncAll(O?"initial-connect":"reconnect").catch(H=>W.warn("detail sync top-level error (ignored)",{err:String(H)}))});let V=new vo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let O=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[Xi]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:b??"",frameworksCache:o.frameworksCache??{},...O?{mockScenario:O}:{}}}},{method:"POST",path:"/pair",handler:async O=>{let H=O,$=H?.privatecode,se=H?.pairing_code;if(!$||!se)throw new C("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Je=Ri(H.env),xe=H.handshake_url,he=H.frontier_url,vt=Dh(H.env,xe,he),ut=!!p&&p!==$,Xt=m!==void 0&&m!==vt,Bt=ut||Xt,Qt=await Fc({privatecode:$,...xe?{endpoint:xe}:{},ppeOverride:Je});if(Bt){W.warn("pair config switched, resetting agents",{pcChanged:ut,envChanged:Xt,previousPc:p?Yo(p):"",nextPc:Yo($),previousEnvKey:m??"",nextEnvKey:vt});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 Ur,"pair switch").catch(()=>{})}b=Qt.deviceId,as({deviceId:b,pid:process.pid}),id({patToken:$,env:H.env}).catch(Ie=>W.warn("coze-cli setup error (ignored)",{err:String(Ie)}));let Wr=new Zi({handshake:Qt,privatecode:$,...he?{urlOverride:he}:{},ppeOverride:Je,getPatTokenForAgent:Ie=>u.agents.get(Ie)?.patToken});await c.swap(Wr,"pair");try{let Ie=new qn;o.frameworksCache=await Ie.detectAll(),await zi(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 me=Object.keys(o.frameworksCache??{});try{let Ie=await u.sendRequest("_agent/pair",{pairCode:se,patToken:$,frameworks:me,_meta:{cozeDeviceId:b}});W.info("_agent/pair ok",{pairResult:Ie}),p=$,m=vt,A=Je,y=xe,H.mock_scenario!==void 0&&(u.setMockScenario(H.mock_scenario),W.info("mock scenario set",{scenario:H.mock_scenario})),Yi($,t).catch(Pe=>W.warn("writePatToken after /pair failed (ignored)",{err:String(Pe)})),S||(S=new Di({core:u,getDeviceId:()=>b??"",onTickEnd:()=>M.retryPending().catch(Pe=>W.warn("detailSync.retryPending failed (ignored)",{err:String(Pe)})),onAuthFailures:J})),S.start(),E(),Bt&&Xo(t,f).catch(Pe=>W.warn("post-pair-switch auto-revive error (ignored)",{err:String(Pe)}));let Jn;return H.agent_id&&(Jn=await _S(H.agent_id,t,f,Pe=>u.sendRequest("_agent/detail",Pe),$).catch(Pe=>(W.error("--agent-id ensureAgent failed",{agentId:H.agent_id,err:String(Pe)}),{ok:!1,agentId:H.agent_id??"",note:String(Pe)}))),{ok:!0,note:"paired with cloud",...Jn?{agent:Jn}:{}}}catch(Ie){return W.error("_agent/pair failed",{err:String(Ie)}),{ok:!1,note:`pair failed: ${String(Ie)}`}}}},{method:"POST",path:"/connect",handler:O=>D(O)},{method:"POST",path:"/_agent/create",handler:async O=>{let H=O;return{ok:!0,result:await f.createAgent(H)}}},{method:"POST",path:"/agent/send",handler:async O=>{let H=O;if(!H?.agentId||!H?.sessionId||!H?.kind||!H?.path)throw new C("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!p)throw new C("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let $=H;return await($.groupFile?G0:U0)($,{core:u,patToken:p,handshakeBase:y,ppeOverride:A})}catch($){if($ instanceof C)return{ok:!1,code:$.code,message:$.message};throw $}}},{method:"POST",path:"/reload",handler:async O=>{let H=O?.agent_id,$=await u.reloadAgents(H);return W.info("IPC /reload: recycled agent subprocesses",{agentId:H??"(all)",recycled:$}),{ok:!0,recycled:$}}},{method:"POST",path:"/shutdown",handler:async()=>(W.info("IPC /shutdown received"),setImmediate(()=>{oe.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:ee,token:Z}=await V.start();try{await Ih(t.libEntry,t)}catch(O){W.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(O)})}await u.start(),yS({paths:t,core:u,agentManager:f,detectAll:async()=>(o.frameworksCache=await new qn().detectAll(),await zi(o),o.frameworksCache)}).catch(O=>W.warn("startup warmup error (ignored)",{err:String(O)})),vl().then(async()=>{let{probeAcpVersion:O}=await Promise.resolve().then(()=>(nn(),El));for(let H of["claude-code","codex"]){let $=await O(H);$&&W.info("acp wrapper version",{framework:H,version:$})}}).catch(O=>W.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(O)}));let ie=null,oe={port:ee,token:Z,core:u,ipc:V,shutdown(O){return ie||(W.info("daemon shutdown",{reason:O}),ie=(async()=>{S?.stop(),I?.stop(),await u.stop(O),await V.stop(),await e.release()})(),ie)}};for(let O of["SIGTERM","SIGINT"])process.on(O,()=>{oe.shutdown(O).then(()=>process.exit(0))});return process.on("exit",()=>l0()),process.on("unhandledRejection",O=>{W.error("unhandledRejection",{reason:O instanceof Error?O.message:String(O),stack:O instanceof Error?O.stack:void 0})}),process.on("uncaughtException",O=>{W.error("uncaughtException (will exit, supervisor will restart)",{message:O.message,stack:O.stack,name:O.name});try{process.stderr.write(`FATAL uncaughtException: ${O.stack??O.message}
|
|
110
|
-
`)}catch{}process.exit(1)}),
|
|
111
|
-
`)){let u=l.indexOf("=");u<=0||(c[l.slice(0,u)]=l.slice(u+1))}return c}function
|
|
112
|
-
`;await
|
|
113
|
-
`).filter(l=>l.length>0).filter(l=>
|
|
114
|
-
`)}async function
|
|
115
|
-
`),1;for(let
|
|
116
|
-
`);return 0}let o=t.date??
|
|
109
|
+
`)}catch{}}let e=new $o({processTitle:Rr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await yo(),o=i??{};os({pid:process.pid}),j.info(i?"loaded bridge config":"initialized bridge config");let c=new qo(new Gr),l=null,u=new bo({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(L,H,W,se)=>{if(!l)throw new Error("agentManager not ready");return l.spawnSessionDownstream(L,H,W,se)}}),x=new mo({paths:t,config:o,registry:u});l=x;let h,m,E=null,I={},y,v=null,A=null,T=null,C=new vn;function P(L,H){return C.enqueue(()=>R(L,H))}function b(){A||(A=new Jo({isConnected:()=>c.isConnected(),forceReconnect:()=>T?P(T,{force:!0}):void 0,onFatal:L=>{if(process.env[Qi]==="1"){j.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:L});return}j.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:L}),process.exit(1)}})),A.start()}async function R(L,H){let W=L,se=W?.privatecode;if(!se)throw new k("IPC_BAD_REQUEST","/connect requires privatecode");let Ye=Ri(W.env),xe=W.handshake_url,he=W.frontier_url,vt=Rh(W.env,xe,he);if(T=W,!H?.force&&h===se&&m===vt){let we=await mS(t);return u.agents.size===0&&we?(j.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),Zo(t,x).catch(Ae=>j.warn("connect-noop auto-revive error (ignored)",{err:String(Ae)}))):j.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let ft=!!h&&h!==se,Xt=m!==void 0&&m!==vt,Bt=ft||Xt,Qt=await Mc({privatecode:se,...xe?{endpoint:xe}:{},ppeOverride:Ye});if(Bt){j.warn("connect config switched, resetting agents",{pcChanged:ft,envChanged:Xt,previousPc:h?Yo(h):"",nextPc:Yo(se)});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 Gr,"connect switch").catch(()=>{})}E=Qt.deviceId,os({deviceId:E,pid:process.pid}),nd({patToken:se,env:W.env}).catch(we=>j.warn("coze-cli setup error (ignored)",{err:String(we)}));let Kr=new Zi({handshake:Qt,privatecode:se,...he?{urlOverride:he}:{},ppeOverride:Ye,getPatTokenForAgent:we=>u.agents.get(we)?.patToken});return await c.swap(Kr,"connect"),h=se,m=vt,I=Ye,y=xe,W.mock_scenario!==void 0&&(u.setMockScenario(W.mock_scenario),j.info("mock scenario set",{scenario:W.mock_scenario})),v||(v=new Pi({core:u,getDeviceId:()=>E??"",onTickEnd:()=>B.retryPending().catch(we=>j.warn("detailSync.retryPending failed (ignored)",{err:String(we)})),onAuthFailures:Y})),v.start(),b(),Bt&&Zo(t,x).catch(we=>j.warn("post-connect-switch auto-revive error (ignored)",{err:String(we)})),Xi(se,t).catch(we=>j.warn("writePatToken after /connect failed (ignored)",{err:String(we)})),j.info("/connect: WS established",{deviceId:E}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async L=>x.createAgent(L.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let O={},F=new oo({agents:u.agents,disposeAndMarkDisconnected:async(L,H)=>{let W=u.agents.get(L);if(W){await x.cleanupOpenclawSessionProviders(W).catch(Ye=>j.warn("cleanup openclaw providers failed (ignored)",{agentId:L,err:String(Ye)}));let se=!0;try{await W.dispose(`disconnect: ${H}`)}catch(Ye){se=!1,j.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:L,err:String(Ye)}),W.status="error"}se&&(W.status="disconnected",u.unregister(L),u.disconnectedAgents.add(L))}else u.disconnectedAgents.add(L)},detailSyncer:async L=>{if(!O.ref)throw new Error("agent-detail-sync not initialized yet");await O.ref.syncOne(L)},cleanupOpenclawProviders:async L=>{await x.cleanupOpenclawSessionProviders(L)},openclawRepair:async(L,H)=>{await x.openclawRepair(L,H)},isRuntimePendingPermission:L=>u.hasPendingPermissionFor(L)});u.registerExtension("_agent/listSkills",L=>F.listSkills(L.params)),u.registerExtension("_agent/addSkills",L=>F.addSkills(L.params)),u.registerExtension("_agent/removeSkills",L=>F.removeSkills(L.params)),u.registerExtension("_agent/getFileTree",L=>F.getFileTree(L.params)),u.registerExtension("_agent/getFileContent",L=>F.getFileContent(L.params)),u.registerExtension("_agent/update",L=>F.updateAgent(L.params)),u.registerExtension("_agent/disconnect",L=>F.disconnectAgent(L.params)),u.registerExtension("_agent/switchModel",L=>F.switchModel(L.params)),u.registerExtension("_agent/reset",L=>F.resetAgent(L.params)),u.registerExtension("_agent/repair",L=>F.repairAgent(L.params)),u.registerExtension("_agent/upgrade",L=>F.upgradeBridge(L.params));let B=new fs({paths:t,handlers:F,agentManager:x,sendDetail:L=>u.sendRequest("_agent/detail",L)});O.ref=B;let Y=async L=>{await Promise.allSettled(L.map(async H=>{try{await F.disconnectAgent({agentId:H.agentId,reason:`auth_failure: code=${H.code} ${H.message}`}),j.info("agent disconnected due to auth failure from heartbeat response",{agentId:H.agentId,code:H.code,message:H.message})}catch(W){j.warn("disconnect during authFailure handling failed (ignored)",{agentId:H.agentId,err:String(W)})}}))};c.onConnect(({initial:L})=>{j.info("frontier upstream connected, triggering detail sync",{initial:L}),B.syncAll(L?"initial-connect":"reconnect").catch(H=>j.warn("detail sync top-level error (ignored)",{err:String(H)}))});let $=new Eo({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let L=u.getMockScenario();return{running:!0,pid:process.pid,spawnedBy:process.env[Qi]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:E??"",frameworksCache:o.frameworksCache??{},...L?{mockScenario:L}:{}}}},{method:"POST",path:"/pair",handler:async L=>{let H=L,W=H?.privatecode,se=H?.pairing_code;if(!W||!se)throw new k("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let Ye=Ri(H.env),xe=H.handshake_url,he=H.frontier_url,vt=Rh(H.env,xe,he),ft=!!h&&h!==W,Xt=m!==void 0&&m!==vt,Bt=ft||Xt,Qt=await Mc({privatecode:W,...xe?{endpoint:xe}:{},ppeOverride:Ye});if(Bt){j.warn("pair config switched, resetting agents",{pcChanged:ft,envChanged:Xt,previousPc:h?Yo(h):"",nextPc:Yo(W),previousEnvKey:m??"",nextEnvKey:vt});for(let Ae of[...u.agents.values()])await Ae.dispose("pair config switch").catch(()=>{}),u.agents.delete(Ae.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 Gr,"pair switch").catch(()=>{})}E=Qt.deviceId,os({deviceId:E,pid:process.pid}),nd({patToken:W,env:H.env}).catch(Ae=>j.warn("coze-cli setup error (ignored)",{err:String(Ae)}));let Kr=new Zi({handshake:Qt,privatecode:W,...he?{urlOverride:he}:{},ppeOverride:Ye,getPatTokenForAgent:Ae=>u.agents.get(Ae)?.patToken});await c.swap(Kr,"pair");try{let Ae=new jn;o.frameworksCache=await Ae.detectAll(),await Ui(o),j.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Ae){j.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Ae)})}let we=Object.keys(o.frameworksCache??{});try{let Ae=await u.sendRequest("_agent/pair",{pairCode:se,patToken:W,frameworks:we,_meta:{cozeDeviceId:E}});j.info("_agent/pair ok",{pairResult:Ae}),h=W,m=vt,I=Ye,y=xe,H.mock_scenario!==void 0&&(u.setMockScenario(H.mock_scenario),j.info("mock scenario set",{scenario:H.mock_scenario})),Xi(W,t).catch(De=>j.warn("writePatToken after /pair failed (ignored)",{err:String(De)})),v||(v=new Pi({core:u,getDeviceId:()=>E??"",onTickEnd:()=>B.retryPending().catch(De=>j.warn("detailSync.retryPending failed (ignored)",{err:String(De)})),onAuthFailures:Y})),v.start(),b(),Bt&&Zo(t,x).catch(De=>j.warn("post-pair-switch auto-revive error (ignored)",{err:String(De)}));let Yn;return H.agent_id&&(Yn=await _S(H.agent_id,t,x,De=>u.sendRequest("_agent/detail",De),W).catch(De=>(j.error("--agent-id ensureAgent failed",{agentId:H.agent_id,err:String(De)}),{ok:!1,agentId:H.agent_id??"",note:String(De)}))),{ok:!0,note:"paired with cloud",...Yn?{agent:Yn}:{}}}catch(Ae){return j.error("_agent/pair failed",{err:String(Ae)}),{ok:!1,note:`pair failed: ${String(Ae)}`}}}},{method:"POST",path:"/connect",handler:L=>P(L)},{method:"POST",path:"/_agent/create",handler:async L=>{let H=L;return{ok:!0,result:await x.createAgent(H)}}},{method:"POST",path:"/agent/send",handler:async L=>{let H=L;if(!H?.agentId||!H?.sessionId||!H?.kind||!H?.path)throw new k("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!h)throw new k("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let W=H;return await(W.groupFile?U0:z0)(W,{core:u,patToken:h,handshakeBase:y,ppeOverride:I})}catch(W){if(W instanceof k)return{ok:!1,code:W.code,message:W.message};throw W}}},{method:"POST",path:"/reload",handler:async L=>{let H=L?.agent_id,W=await u.reloadAgents(H);return j.info("IPC /reload: recycled agent subprocesses",{agentId:H??"(all)",recycled:W}),{ok:!0,recycled:W}}},{method:"POST",path:"/shutdown",handler:async()=>(j.info("IPC /shutdown received"),setImmediate(()=>{oe.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:te,token:Z}=await $.start();try{await Ih(t.libEntry,t)}catch(L){j.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(L)})}await u.start(),yS({paths:t,core:u,agentManager:x,detectAll:async()=>(o.frameworksCache=await new jn().detectAll(),await Ui(o),o.frameworksCache)}).catch(L=>j.warn("startup warmup error (ignored)",{err:String(L)})),El().then(async()=>{let{probeAcpVersion:L}=await Promise.resolve().then(()=>(rn(),yl));for(let H of["claude-code","codex"]){let W=await L(H);W&&j.info("acp wrapper version",{framework:H,version:W})}}).catch(L=>j.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(L)}));let ie=null,oe={port:te,token:Z,core:u,ipc:$,shutdown(L){return ie||(j.info("daemon shutdown",{reason:L}),ie=(async()=>{v?.stop(),A?.stop(),await u.stop(L),await $.stop(),await e.release()})(),ie)}};for(let L of["SIGTERM","SIGINT"])process.on(L,()=>{oe.shutdown(L).then(()=>process.exit(0))});return process.on("exit",()=>d0()),process.on("unhandledRejection",L=>{j.error("unhandledRejection",{reason:L instanceof Error?L.message:String(L),stack:L instanceof Error?L.stack:void 0})}),process.on("uncaughtException",L=>{j.error("uncaughtException (will exit, supervisor will restart)",{message:L.message,stack:L.stack,name:L.name});try{process.stderr.write(`FATAL uncaughtException: ${L.stack??L.message}
|
|
110
|
+
`)}catch{}process.exit(1)}),j.info("daemon ready",{port:te,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),bS({cliSpawned:process.env[Qi]==="1",readPatToken:()=>Wo(t),connect:P}).catch(L=>j.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(L)})),oe}async function mS(t){return cs(t).length>0}function Yo(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function Rh(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function wS(t,e){let r=cs(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(sn(),us));for(let c of r){await o(c,t).catch(l=>j.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(l)}));try{let l=await i(c,t);l?.disconnectedAt&&(e.disconnectedAgents.add(c),j.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:l.disconnectedAt,reason:l.disconnectReason??""}))}catch(l){j.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(l)})}}}async function _S(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(sn(),us)),l=await c(t,e);if(l){j.info("--agent-id: local config found, reconnecting",{agentId:t,framework:l.framework,hadDisconnect:!!l.disconnectedAt});let m=Ph(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"}}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 k("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 yS(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 wS(t.paths,t.core).catch(r=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(r)})),await Zo(t.paths,t.agentManager).catch(r=>e.warn("auto-revive top-level error (ignored)",{err:String(r)}))}async function Zo(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(()=>(sn(),us));j.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){j.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(h)}),l+=1;continue}if(!x){l+=1;continue}if(x.disconnectedAt){j.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:x.disconnectedAt}),l+=1;continue}try{j.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:x.framework});let h=Ph(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){j.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:x.framework,err:String(h)}),l+=1}}return j.info("auto-revive: done",{revived:c,skipped:l,total:i.length}),{revived:c,skipped:l,total:i.length}}async function bS(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 Ph(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}Vo();Pe();import{readFile as Oh}from"node:fs/promises";var Zt=class{paths;constructor(e){this.paths=e??Q()}async probe(e=1e3){let r=await Xo(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:vS(i)}}}async request(e){let r=await Xo(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:ES(x)}}finally{clearTimeout(l)}}};async function Xo(t){try{let[e,r]=await Promise.all([Oh(t.portFile,"utf8"),Oh(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 ES(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function vS(t){return t instanceof Error?t.message:String(t)}Wt();ne();er();import{spawn as SS}from"node:child_process";import{userInfo as Nh}from"node:os";var Ld="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",IS=new Set(["bash","zsh","sh","dash","ksh"]),Lh=We("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),AS=2e3;function TS(t,e=Ld){let r=t.indexOf(e);if(r===-1)return null;let i=t.indexOf(e,r+e.length);if(i===-1)return null;let o=t.slice(r+e.length,i),c={};for(let l of o.split(`
|
|
111
|
+
`)){let u=l.indexOf("=");u<=0||(c[l.slice(0,u)]=l.slice(u+1))}return c}function kS(){let t=(process.env.SHELL??"").trim()||(Nh().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return IS.has(e)?t:null}function CS(t){return new Promise(e=>{let r=`printf '%s' '${Ld}'; env; printf '%s' '${Ld}'`,i;try{i=SS(t,["-ilc",r],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??Nh().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"),Lh),h=setTimeout(()=>{l("SIGKILL"),u(o.length>0?o:null)},Lh+AS)})}async function Nd(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let r=kS();if(!r)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??CS)(r);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=TS(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}Pe();function An(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}}rn();import{chmod as RS,copyFile as Mh,mkdir as Fh,readFile as Qo,rename as Bh,rm as Md,stat as zh,writeFile as DS}from"node:fs/promises";import{homedir as IR}from"node:os";import{dirname as PS,join as Hr,resolve as Bd,sep as es}from"node:path";import{fileURLToPath as OS}from"node:url";Wt();ne();Pe();var Fd=G("dist-install");function LS(t){let e=OS(t),r=PS(e),i=`${es}src${es}`;if(r.includes(i)||r.endsWith(`${es}src${es}cli`))return null;let o=Bd(r,"index.js"),c=Bd(r,"..","package.json");return{dist:o,pkgJson:c}}async function Ud(t={}){let e=t.paths??Q(),r=LS(import.meta.url),i=t.sourceDist??r?.dist,o=t.sourcePackageJson??r?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,l;try{let I=JSON.parse(await Qo(o,"utf8"));c=I.version??"unknown",l=I.dependencies??{}}catch(I){return Fd.warn("cannot read source package.json,skip dist install",{err:String(I)}),{kind:"dev-mode-skip",reason:`package.json read failed: ${String(I)}`}}let u=Zr.map(I=>`${I}@${l[I]??"latest"}`),x=await yo(e.configFile)??{},h=x.libVersion,m=await Qo(e.libEntry).then(()=>!0).catch(()=>!1),E=h===c;if(E&&m&&await zd(e))return{kind:"already-current",libVersion:c};if(!E||!m){await Fh(e.libDir,{recursive:!0}),await Mh(i,e.libEntry),await Mh(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let I=Bd(e.libDir,"package.json"),y=`${JSON.stringify({type:"module"},null,2)}
|
|
112
|
+
`;await Qo(I,"utf8").catch(()=>null)!==y&&await DS(I,y)}return(!E||!await zd(e))&&await(t.installWrappers??NS)(e,u),x.libVersion=c,await Ui(x,e.configFile),Fd.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 zd(t){for(let e of Zr){let r=Hr(t.libDir,"node_modules",...e.split("/"),"package.json");if(!await zh(r).then(o=>o.isFile()).catch(()=>!1))return!1}return!0}async function NS(t,e){await FS(t.installLock,async()=>{if(await zd(t))return;let r=Math.random().toString(36).slice(2,10),i=`${t.libDir}${es}.staging-${process.pid}-${r}`,o=Hr(i,"node_modules"),c=Hr(t.libDir,"node_modules");try{await Fh(i,{recursive:!0}),await MS(e,i),await BS(o);let l=`${c}.trash-${r}`;await Bh(c,l).catch(()=>{}),await Bh(o,c),await Md(l,{recursive:!0,force:!0}).catch(()=>{}),Fd.info("wrapper closure installed",{liveNm:c,specs:e})}finally{await Md(i,{recursive:!0,force:!0}).catch(()=>{})}})}function MS(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=nt("npm",r,{stdio:["ignore","pipe","pipe"]}),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 BS(t){for(let e of Zr){let r=Hr(t,...e.split("/")),i=JSON.parse(await Qo(Hr(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=Hr(t,".bin",o),l=await zh(c);process.platform!=="win32"&&!(l.mode&73)&&await RS(c,l.mode|73).catch(()=>{})}}async function FS(t,e){let{open:r}=await import("node:fs/promises"),i=!1;for(let o=0;o<60&&!i;o++)try{await(await r(t,"wx")).close(),i=!0}catch{await new Promise(c=>setTimeout(c,500))}try{return await e()}finally{i&&await Md(t,{force:!0}).catch(()=>{})}}ba();ne();Pe();import{closeSync as Gh,fstatSync as Hh,openSync as jh,readFileSync as zS,readSync as US,readdirSync as GS,statSync as HS}from"node:fs";import{join as ea}from"node:path";var jS=new Set(["debug","info","warn","error"]);function qh(t){let e=t,r=An(e,"--agent-id");e=r.rest;let i=An(e,"--date");e=i.rest;let o=An(e,"-n","--lines");e=o.rest;let c=An(e,"--level");e=c.rest;let l=An(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&&jS.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 qS(t,e){return t.agentId?ea(Xe(t.agentId,e).logs,tr("agent",t.date)):ea(e.bridgeLogsDir,tr("bridge",t.date))}function WS(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function KS(t,e){let r;try{r=GS(t)}catch{return[]}let i=[];for(let o of r){let c=ya(o,e);if(!c)continue;let l=0;try{l=HS(ea(t,o)).size}catch{}i.push({file:ea(t,o),date:c,size:l})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function Wh(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"&&!pl(r,e.level))return!1}return!0}var Uh={debug:"90",info:"36",warn:"33",error:"31"},$S=new Set(["ts","level","module","msg"]);function VS(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function Kh(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=VS(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&Uh[o]&&(c=`\x1B[${Uh[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])=>!$S.has(h)).map(([h,m])=>` ${h}=${typeof m=="string"?m:JSON.stringify(m)}`).join("");return`${i} ${c} ${l} ${u}${x}`}function JS(t,e,r){let c=zS(t,"utf8").split(`
|
|
113
|
+
`).filter(l=>l.length>0).filter(l=>Wh(l,{level:e.level,grep:e.grep}));for(let l of WS(c,e.lines))process.stdout.write(`${Kh(l,{raw:e.raw,color:r})}
|
|
114
|
+
`)}async function $h(t,e){let r=e.paths??Q(),i=process.stdout.isTTY===!0;if(t.list){let l=t.agentId?Xe(t.agentId,r).logs:r.bridgeLogsDir,u=t.agentId?"agent":"bridge",x=KS(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??kn(new Date),c=qS({agentId:t.agentId,date:o},r);try{JS(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
|
|
117
117
|
\u7528 'coze-bridge log${t.agentId?` --agent-id ${t.agentId}`:""} --list' \u770B\u6709\u54EA\u4E9B\u65E5\u671F\u3002
|
|
118
118
|
(legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${r.logFile})
|
|
119
|
-
`),1}return t.follow&&await XS(c,t,i),0}var
|
|
120
|
-
`);o=
|
|
121
|
-
`)}await new Promise(
|
|
119
|
+
`),1}return t.follow&&await XS(c,t,i),0}var YS=500;function ZS(t){try{let e=jh(t,"r");try{return Hh(e).size}finally{Gh(e)}}catch{return 0}}async function XS(t,e,r){let i=ZS(t),o="",c=!1,l=()=>{c=!0};process.on("SIGINT",l);try{for(;!c;){let u="";try{let x=jh(t,"r");try{let h=Hh(x).size;if(h>i){let m=Buffer.allocUnsafe(h-i),E=US(x,m,0,m.length,i);u=m.subarray(0,E).toString("utf8"),i+=E}}finally{Gh(x)}}catch{}if(u){let x=(o+u).split(`
|
|
120
|
+
`);o=x.pop()??"";for(let h of x)h.length>0&&Wh(h,{level:e.level,grep:e.grep})&&process.stdout.write(`${Kh(h,{raw:e.raw,color:r})}
|
|
121
|
+
`)}await new Promise(x=>setTimeout(x,YS))}}finally{process.off("SIGINT",l)}}import{basename as QS,resolve as e2}from"node:path";Pe();var t2=9e4,n2={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 r2(t){return n2[t]??1}async function Vh(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
122
|
`),4;if(t.groupFile&&!t.mimeType)return process.stderr.write(`Error: --group-file requires --mime <mimeType> (e.g. application/pdf, image/png). No local file is read in group-file mode, mime cannot be auto-detected.
|
|
123
|
-
`),3;let i=await
|
|
124
|
-
`),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:
|
|
123
|
+
`),3;let i=await Xo(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:e2(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 i2(i,"/agent/send",o,t2)}catch(l){return process.stderr.write(`Error: daemon IPC failed: ${l instanceof Error?l.message:String(l)}
|
|
125
125
|
`),4}if(!c.ok)return process.stderr.write(`Error: ${c.code}: ${c.message}
|
|
126
|
-
`),
|
|
126
|
+
`),r2(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
|
|
127
127
|
`);else{let l=t.name??QS(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} (${
|
|
129
|
-
`)}return 0}async function
|
|
130
|
-
`)}function
|
|
128
|
+
`)}else process.stdout.write(`Sent ${t.kind} ${l} (${s2(c.bytes)})
|
|
129
|
+
`)}return 0}async function i2(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 s2(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var rp=G("cli");function He(t,e){let{value:r,rest:i}=An(t,e);return{value:r,rest:i}}function oa(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
|
|
130
|
+
`)}function C2(t){let e=t.slice(2);if(e.includes("--version")||e.includes("-v"))return{mode:"version"};if(e.includes("--daemon"))return{mode:"daemon"};if(e[0]==="status")return{mode:"status"};if(e[0]==="stop")return{mode:"stop"};if(e[0]==="reload"){let{value:P}=He(e.slice(1),"--agent-id");return P?{mode:"reload",agentId:P}:{mode:"reload"}}if(e[0]==="update")return{mode:"update"};if(e[0]==="purge")return{mode:"purge"};if(e[0]==="service")return e[1]==="install"?{mode:"service-install"}:e[1]==="uninstall"?{mode:"service-uninstall"}:{mode:"help"};if(e[0]==="send")return R2(e.slice(1));if(e[0]==="log")return{mode:"log",...qh(e.slice(1))};if(e[0]==="connect")return D2(e.slice(1));if(e.includes("--status"))return oa("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return oa("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return oa("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return oa("--install-service","coze-bridge service install"),{mode:"service-install"};if(e.includes("--help")||e.includes("-h")||e.length===0)return{mode:"help"};let r=e,{value:i,rest:o}=He(r,"--pat-token");r=o;let{value:c,rest:l}=He(r,"--pair-code");r=l;let{value:u,rest:x}=He(r,"--env");r=x;let{value:h,rest:m}=He(r,"--handshake-url");r=m;let{value:E,rest:I}=He(r,"--frontier-url");r=I;let{value:y,rest:v}=He(r,"--mock-scenario");r=v;let{value:A}=He(r,"--agent-id"),T=r.includes("--skip-rebuild-env");if(!i||!c)return{mode:"help"};let C={mode:"pair",privatecode:i,pairingCode:c};return u&&(C.env=u),h&&(C.handshakeUrl=h),E&&(C.frontierUrl=E),y&&(C.mockScenario=y),A&&(C.agentId=A),T&&(C.skipRebuildEnv=!0),C}function R2(t){let e=t[0],r=t[1];if(e!=="image"&&e!=="file")return{mode:"help"};if(!r||r.startsWith("--"))return{mode:"help"};let i=t.slice(2),{value:o,rest:c}=He(i,"--caption");i=c;let{value:l,rest:u}=He(i,"--name");i=u;let{value:x,rest:h}=He(i,"--agent-id");i=h;let{value:m,rest:E}=He(i,"--session-id");i=E;let{value:I,rest:y}=He(i,"--mime");i=y;let v=i.includes("--group-file");i=i.filter(C=>C!=="--group-file");let A=i.includes("--json"),T={mode:"send",kind:e,path:r,json:A};return o&&(T.caption=o),l&&(T.name=l),x&&(T.agentId=x),m&&(T.sessionId=m),v&&(T.groupFile=!0),I&&(T.mimeType=I),T}function D2(t){let e=t,{value:r,rest:i}=He(e,"--pat-token");e=i;let{value:o,rest:c}=He(e,"--env");e=c;let{value:l,rest:u}=He(e,"--handshake-url");e=u;let{value:x,rest:h}=He(e,"--frontier-url");e=h;let{value:m,rest:E}=He(e,"--mock-scenario");e=E;let I=e.includes("--skip-rebuild-env"),y={mode:"connect"};return r&&(y.privatecode=r),o&&(y.env=o),l&&(y.handshakeUrl=l),x&&(y.frontierUrl=x),m&&(y.mockScenario=m),I&&(y.skipRebuildEnv=!0),y}var P2=`
|
|
131
131
|
coze-bridge - local bridge daemon for cloud Agent Service
|
|
132
132
|
|
|
133
133
|
Pair (paste from cloud UI; start/reuse daemon and deliver pair-code):
|
|
@@ -208,57 +208,57 @@ Deprecated flags (still work, but emit a warning; will be removed in a future re
|
|
|
208
208
|
|
|
209
209
|
Internal:
|
|
210
210
|
<node> <entry> --daemon daemon mode (OS supervisor only)
|
|
211
|
-
`.trimStart();async function
|
|
212
|
-
`),0;case"daemon":{try{await
|
|
213
|
-
`),1;if(i.kind==="stale")return await
|
|
211
|
+
`.trimStart();async function ip(t=process.argv,e={}){let r=C2(t);switch(r.mode){case"help":return process.stdout.write(P2),0;case"version":return process.stdout.write(`${Ar}
|
|
212
|
+
`),0;case"daemon":{try{await Dh()}catch(i){return rp.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return O2(e);case"stop":return op(e);case"reload":return M2(r.agentId,e);case"log":return $h(r,e);case"update":return L2(e);case"purge":return B2(e);case"service-install":return F2(e);case"service-uninstall":return z2(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),U2(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),G2(r.privatecode,e,i,r.skipRebuildEnv)}case"send":return Vh({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 sp(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 O2(t){let e=t.paths??Q(),r=new Zt(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 sp(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
214
214
|
`),1;let o=await r.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
|
|
215
215
|
${JSON.stringify(o.body,null,2)}
|
|
216
|
-
`),0}async function
|
|
216
|
+
`),0}async function op(t){let e=t.paths??Q(),r=new Zt(e),i=t.daemonSweep??(async()=>{let x=l0();return await u0(x),x}),o=async()=>{t.skipProcessKill||await i(e)},c=await ns(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
217
|
`)}let u=await r.probe();if(u.kind==="not-running")return await o(),process.stdout.write(l?`coze-bridge: stopped
|
|
218
218
|
`:`coze-bridge: not running
|
|
219
|
-
`),0;if(u.kind==="stale")return await
|
|
219
|
+
`),0;if(u.kind==="stale")return await sp(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
220
220
|
`),0;try{return await r.request({method:"POST",path:"/shutdown"}),await o(),process.stdout.write(`coze-bridge: stopped
|
|
221
|
-
`),0}catch(
|
|
222
|
-
`),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(
|
|
223
|
-
`),1)}}async function
|
|
224
|
-
`),e(1)})})}async function
|
|
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 L2(t){return await op(t),(t.spawnNpx??N2)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function N2(t){return new Promise(e=>{let r=nt("npx",t,{stdio:"inherit"});r.on("exit",i=>e(i??1)),r.on("error",i=>{process.stderr.write(`coze-bridge: spawn npx failed: ${String(i)}
|
|
224
|
+
`),e(1)})})}async function M2(t,e){let r=new Zt(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
|
|
225
225
|
`),1;try{let o=await r.request({method:"POST",path:"/reload",body:t?{agent_id:t}:{},timeoutMs:35e3});if(o.status===200&&o.body?.ok){let c=o.body.recycled??[];return t&&c.length===0?process.stdout.write(`coze-bridge: agent ${t} \u65E0\u8FD0\u884C\u4E2D\u5B50\u8FDB\u7A0B\u53EF\u56DE\u6536 (\u672A\u6CE8\u518C / \u5DF2 idle)
|
|
226
226
|
`):process.stdout.write(`coze-bridge: reloaded ${c.length} agent(s): ${c.join(", ")||"(none)"}
|
|
227
227
|
`),0}return process.stderr.write(`coze-bridge: reload failed: ${JSON.stringify(o.body)}
|
|
228
228
|
`),1}catch(o){return process.stderr.write(`coze-bridge: reload failed: ${String(o)}
|
|
229
|
-
`),1}}async function
|
|
229
|
+
`),1}}async function ns(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(()=>(tp(),ep)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function ap(t,e){let r=await e.probe();if(r.kind==="connected")return r;let i=t.spawnDaemon??Ch,o=t.waitTimeoutMs??15e3,c=t.sleep??j2,l=t.paths??Q(),u=await ns(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let x=await np(e,o,c);if(x.kind==="connected")return x;St(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){St(l.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(x)})}St(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 H2(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)}
|
|
230
230
|
`));return process.stdout.write(`coze-bridge: starting daemon...
|
|
231
|
-
`),await i({paths:t.paths}),
|
|
231
|
+
`),await i({paths:t.paths}),np(e,o,c)}async function B2(t){let e=new Zt(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
|
|
232
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
|
|
233
|
+
`)}await new Promise(l=>setTimeout(l,500))}let i=await ns(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
|
|
234
234
|
`)}catch(l){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(l)}
|
|
235
|
-
`)}let o=t.paths??
|
|
235
|
+
`)}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
236
|
`)}catch(l){return process.stderr.write(`coze-bridge: remove failed: ${String(l)}
|
|
237
237
|
`),1}return process.stdout.write(`coze-bridge: purged (agents workspaces preserved under ~/.coze/agents)
|
|
238
|
-
`),0}async function
|
|
238
|
+
`),0}async function F2(t){let e=await ns(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
|
|
239
239
|
`),await e.install(),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
|
|
240
240
|
`),0}catch(r){return process.stderr.write(`coze-bridge: service install failed: ${String(r)}
|
|
241
|
-
`),1}}async function
|
|
241
|
+
`),1}}async function z2(t){let e=await ns(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
|
|
242
242
|
`),0}catch(r){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(r)}
|
|
243
|
-
`),1}}async function
|
|
244
|
-
`),St(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function
|
|
245
|
-
`),(await l.probe()).kind==="connected"&&(await l.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(y=>setTimeout(y,500)))):
|
|
246
|
-
`)}let
|
|
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
|
|
243
|
+
`),1}}async function cp(t,e,r){if(e)return St(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await r();return i.kind==="ok"?(St(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(St(t.bridgeLogsDir,"info","cli","agent-env: rebuild not applicable, use process.env",{reason:i.reason}),process.env):(process.stderr.write(`coze-bridge: \u91CD\u5EFA shell \u73AF\u5883\u5931\u8D25, \u56DE\u9000\u5F53\u524D\u8FDB\u7A0B\u73AF\u5883 (\u53EF\u7528 --skip-rebuild-env \u663E\u5F0F\u8DF3\u8FC7)
|
|
244
|
+
`),St(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function U2(t,e,r,i={},o,c){let l=new Zt(r.paths),u=r.paths??Q(),x=await cp(u,c,r.reconstructEnv??Nd);if(await Jc(u,x).catch(E=>St(u.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(E)})),!r.skipDistInstall){let E=await Ud({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(y=>setTimeout(y,500)))):E.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${E.libVersion}
|
|
246
|
+
`)}let h=await ap(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 I=E.body.agent;return I&&!I.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${I.agentId}): ${I.note}
|
|
248
248
|
`),1):(process.stdout.write(`\u5DF2\u914D\u5BF9\u8FDE\u63A5\u5B8C\u6210\uFF0C\u8BF7\u8FD4\u56DE\u5230 coze \u5E73\u53F0\u4E0A\u70B9\u51FB "\u6211\u5DF2\u6267\u884C"
|
|
249
|
-
`),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(
|
|
250
|
-
`),1}catch(
|
|
251
|
-
`),1}}async function
|
|
252
|
-
`),(await l.probe()).kind==="connected"&&(await l.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(
|
|
253
|
-
`)}let
|
|
254
|
-
`),1;let
|
|
255
|
-
`),await
|
|
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 G2(t,e,r={},i){let o=e.paths??Q(),c=t??await Wo(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 Zt(e.paths),u=await cp(o,i,e.reconstructEnv??Nd);if(await Jc(o,u).catch(m=>St(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(m)})),!e.skipDistInstall){let m=await Ud({paths:e.paths});m.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${m.fromVersion} \u2192 ${m.toVersion}
|
|
252
|
+
`),(await l.probe()).kind==="connected"&&(await l.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(I=>setTimeout(I,500)))):m.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${m.libVersion}
|
|
253
|
+
`)}let x=await ap(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
|
+
`),await Xi(c,o).catch(E=>rp.warn("writePatToken after connect failed (ignored)",{err:String(E)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(m.body)}
|
|
256
256
|
`),1)}catch(m){return process.stderr.write(`coze-bridge: connect failed: ${String(m)}
|
|
257
|
-
`),1}}async function
|
|
257
|
+
`),1}}async function np(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 H2(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||!Mi(u))return;await e(i)}}function j2(t){return new Promise(e=>setTimeout(e,t))}ne();function q2(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 dp(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=q2(t);if(i==="ok")return;let o=t.replace(/^v/,"");i==="fatal"?(e(`[coze-bridge] \u5F53\u524D Node.js \u7248\u672C v${o} \u8FC7\u4F4E,\u65E0\u6CD5\u8FD0\u884C(\u6700\u4F4E v18.4.0,\u63A8\u8350 v20+)\u3002\u8BF7\u5347\u7EA7\u540E\u91CD\u8BD5:https://nodejs.org(\u6216\u7528 nvm/fnm)\u3002
|
|
258
258
|
`),r(1)):e(`[coze-bridge] \u68C0\u6D4B\u5230 Node.js v${o},\u672C\u9879\u76EE\u63A8\u8350 v20+,\u4F4E\u4E8E v20 \u540E\u7EED\u5347\u7EA7\u53EF\u80FD\u6709\u517C\u5BB9\u95EE\u9898,\u5EFA\u8BAE\u5347\u7EA7\u3002
|
|
259
259
|
\u5347\u7EA7\u5B8C\u540E\u9700\u8981\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u91CD\u65B0\u8FDE\u63A5:
|
|
260
260
|
npx -y coze-bridge@latest stop
|
|
261
261
|
npx -y coze-bridge@latest connect
|
|
262
262
|
|
|
263
|
-
`)}
|
|
263
|
+
`)}dp();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&xl("warn");ip(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
|
|
264
264
|
`),process.exit(1)});
|