coze-bridge 0.2.4-beta.2 → 0.2.4
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 +95 -89
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,30 +5,30 @@ 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
|
|
9
|
-
`)),this.stream=
|
|
10
|
-
`),this.stream=void 0;return}this.currentDate!==void 0&&us(this.dir,this.prefix,e,this.opts.retentionDays),this.currentDate=e}close(){this.stream?.end(),this.stream=void 0,this.currentDate=void 0}}});import{appendFileSync as
|
|
11
|
-
`;
|
|
12
|
-
`;if(
|
|
13
|
-
`),{cause:o})}}async function
|
|
14
|
-
`,n)}var dn=nt(()=>{"use strict"});import{promises as Ll,readdirSync as dm}from"node:fs";import{homedir as lm}from"node:os";import{sep as um,join as Ce,resolve as Nl}from"node:path";function te(t){let e=t??lm(),n=Ce(e,".coze"),i=Ce(n,"bridge"),o=Ce(i,"lib"),c=Ce(i,"logs");return{cozeRoot:n,bridgeRoot:i,libDir:o,libEntry:Ce(o,"index.js"),binDir:Ce(i,"bin"),pidFile:Ce(i,"bridge.pid"),portFile:Ce(i,"bridge.port"),tokenFile:Ce(i,"bridge.token"),patTokenFile:Ce(i,"pat-token"),agentEnvFile:Ce(i,"agent-env.json"),logFile:Ce(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:Ce(c,"daemon-stdio.log"),installLock:Ce(i,"install.lock"),configFile:Ce(i,"config.json"),agentsRoot:Ce(n,"agents")}}function Ze(t,e=te()){let n=Ce(e.agentsRoot,t);return{root:n,config:Ce(n,"config.json"),workspace:Ce(n,"workspace"),logs:Ce(n,"logs")}}function ms(t=te()){try{return dm(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function si(t,e){let n=await Ll.realpath(Nl(t)).catch(()=>null);if(!n)return!1;let i=await Ll.realpath(Nl(e)).catch(()=>null);if(!i)return!1;let o=process.platform==="win32"?n.toLowerCase():n,c=process.platform==="win32"?i.toLowerCase():i;return o===c||o.startsWith(c+um)}var Me=nt(()=>{"use strict"});var _s={};Aa(_s,{AGENT_CONFIG_FILE_MODE:()=>ws,enforceAgentConfigMode:()=>hm,loadAgentConfig:()=>Pe,persistAgentSessions:()=>oi,persistAgentSkills:()=>ai,saveAgentConfig:()=>Ue});import{chmod as fm,stat as xm}from"node:fs/promises";function Pe(t,e){return lr(Ze(t,e).config)}function Ue(t,e){return ur(Ze(t.agentId,e).config,t,{mode:ws})}async function hm(t,e){if(process.platform==="win32")return;let n=Ze(t,e).config;try{let i=await xm(n);if(!i.isFile())return;let o=i.mode&511;o!==ws&&(await fm(n,ws),Ml.warn("agent config mode auto-corrected to 0600",{path:n,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Ml.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:n,err:String(i)})}}async function oi(t,e,n){let i=await Pe(t,n);i&&(i.sessions=Object.fromEntries(e),await Ue(i,n))}async function ai(t,e,n){let i=await Pe(t,n);i&&(i.skills=e,await Ue(i,n))}var Ml,ws,ln=nt(()=>{"use strict";dn();ie();Me();Ml=K("agent-config"),ws=384});var Na=de((oA,zl)=>{zl.exports={LOCHDR:30,LOCSIG:67324752,LOCVER:4,LOCFLG:6,LOCHOW:8,LOCTIM:10,LOCCRC:14,LOCSIZ:18,LOCLEN:22,LOCNAM:26,LOCEXT:28,EXTSIG:134695760,EXTHDR:16,EXTCRC:4,EXTSIZ:8,EXTLEN:12,CENHDR:46,CENSIG:33639248,CENVEM:4,CENVER:6,CENFLG:8,CENHOW:10,CENTIM:12,CENCRC:16,CENSIZ:20,CENLEN:24,CENNAM:28,CENEXT:30,CENCOM:32,CENDSK:34,CENATT:36,CENATX:38,CENOFF:42,ENDHDR:22,ENDSIG:101010256,ENDSUB:8,ENDTOT:10,ENDSIZ:12,ENDOFF:16,ENDCOM:20,END64HDR:20,END64SIG:117853008,END64START:4,END64OFF:8,END64NUMDISKS:16,ZIP64SIG:101075792,ZIP64HDR:56,ZIP64LEAD:12,ZIP64SIZE:4,ZIP64VEM:12,ZIP64VER:14,ZIP64DSK:16,ZIP64DSKDIR:20,ZIP64SUB:24,ZIP64TOT:32,ZIP64SIZB:40,ZIP64OFF:48,ZIP64EXTRA:56,STORED:0,SHRUNK:1,REDUCED1:2,REDUCED2:3,REDUCED3:4,REDUCED4:5,IMPLODED:6,DEFLATED:8,ENHANCED_DEFLATED:9,PKWARE:10,BZIP2:12,LZMA:14,IBM_TERSE:18,IBM_LZ77:19,AES_ENCRYPT:99,FLG_ENC:1,FLG_COMP1:2,FLG_COMP2:4,FLG_DESC:8,FLG_ENH:16,FLG_PATCH:32,FLG_STR:64,FLG_EFS:2048,FLG_MSK:4096,FILE:2,BUFFER:1,NONE:0,EF_ID:0,EF_SIZE:2,ID_ZIP64:1,ID_AVINFO:7,ID_PFS:8,ID_OS2:9,ID_NTFS:10,ID_OPENVMS:12,ID_UNIX:13,ID_FORK:14,ID_PATCH:15,ID_X509_PKCS7:20,ID_X509_CERTID_F:21,ID_X509_CERTID_C:22,ID_STRONGENC:23,ID_RECORD_MGT:24,ID_X509_PKCS7_RL:25,ID_IBM1:101,ID_IBM2:102,ID_POSZIP:18064,EF_ZIP64_OR_32:4294967295,EF_ZIP64_OR_16:65535,EF_ZIP64_SUNCOMP:0,EF_ZIP64_SCOMP:8,EF_ZIP64_RHO:16,EF_ZIP64_DSN:24}});var bs=de(Gl=>{var Ul={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 ym(t){return function(...e){return e.length&&(t=t.replace(/\{(\d)\}/g,(n,i)=>e[i]||"")),new Error("ADM-ZIP: "+t)}}for(let t of Object.keys(Ul))Gl[t]=ym(Ul[t])});var Kl=de((cA,Wl)=>{var bm=xe("fs"),Be=xe("path"),jl=Na(),Em=bs(),vm=typeof process=="object"&&process.platform==="win32",Hl=t=>typeof t=="object"&&t!==null,ql=new Uint32Array(256).map((t,e)=>{for(let n=0;n<8;n++)(e&1)!==0?e=3988292384^e>>>1:e>>>=1;return e>>>0});function Ie(t){this.sep=Be.sep,this.fs=bm,Hl(t)&&Hl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}Wl.exports=Ie;Ie.prototype.makeDir=function(t){let e=this;function n(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var d;try{d=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(d&&d.isFile())throw Em.FILE_IN_THE_WAY(`"${o}"`)}})}n(t)};Ie.prototype.writeFileTo=function(t,e,n,i){let o=this;if(o.fs.existsSync(t)){if(!n)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var d=Be.dirname(t);o.fs.existsSync(d)||o.makeDir(d);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};Ie.prototype.writeFileToAsync=function(t,e,n,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(d){if(d&&!n)return o(!1);c.fs.stat(t,function(u,x){if(d&&x.isDirectory())return o(!1);var h=Be.dirname(t);c.fs.exists(h,function(g){g||c.makeDir(h),c.fs.open(t,"w",438,function(w,v){w?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(_,E){c.fs.write(E,e,0,e.length,0,function(){c.fs.close(E,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):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)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};Ie.prototype.findFiles=function(t){let e=this;function n(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let d=[];return e.fs.readdirSync(i).forEach(function(u){let x=Be.join(i,u),h=e.fs.statSync(x);(!o||o.test(x))&&d.push(Be.normalize(x)+(h.isDirectory()?e.sep:"")),h.isDirectory()&&c&&(d=d.concat(n(x,o,c)))}),d}return n(t,void 0,!0)};Ie.prototype.findFilesAsync=function(t,e){let n=this,i=[];n.fs.readdir(t,function(o,c){if(o)return e(o);let d=c.length;if(!d)return e(null,i);c.forEach(function(u){u=Be.join(t,u),n.fs.stat(u,function(x,h){if(x)return e(x);h&&(i.push(Be.normalize(u)+(h.isDirectory()?n.sep:"")),h.isDirectory()?n.findFilesAsync(u,function(g,w){if(g)return e(g);i=i.concat(w),--d||e(null,i)}):--d||e(null,i))})})})};Ie.prototype.getAttributes=function(){};Ie.prototype.setAttributes=function(){};Ie.crc32update=function(t,e){return ql[(t^e)&255]^t>>>8};Ie.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,n=-1;for(let i=0;i<e;)n=Ie.crc32update(n,t[i++]);return~n>>>0};Ie.methodToString=function(t){switch(t){case jl.STORED:return"STORED ("+t+")";case jl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Ie.canonical=function(t){if(!t)return"";let e=Be.posix.normalize("/"+t.split("\\").join("/"));return Be.join(".",e)};Ie.zipnamefix=function(t){if(!t)return"";let e=Be.posix.normalize("/"+t.split("\\").join("/"));return Be.posix.join(".",e)};Ie.findLast=function(t,e){if(!Array.isArray(t))throw new TypeError("arr is not array");let n=t.length>>>0;for(let i=n-1;i>=0;i--)if(e(t[i],i,t))return t[i]};Ie.sanitize=function(t,e){t=Be.resolve(Be.normalize(t));for(var n=e.split("/"),i=0,o=n.length;i<o;i++){var c=Be.normalize(Be.join(t,n.slice(i,o).join(Be.sep)));if(c.indexOf(t)===0)return c}return Be.normalize(Be.join(t,Be.basename(e)))};Ie.toBuffer=function(e,n){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?n(e):Buffer.alloc(0)};Ie.readBigUInt64LE=function(t,e){let n=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+n};Ie.fromDOS2Date=function(t){return new Date((t>>25&127)+1980,Math.max((t>>21&15)-1,0),Math.max(t>>16&31,1),t>>11&31,t>>5&63,(t&31)<<1)};Ie.fromDate2DOS=function(t){let e=0,n=0;return t.getFullYear()>1979&&(e=(t.getFullYear()-1980&127)<<9|t.getMonth()+1<<5|t.getDate(),n=t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1),e<<16|n};Ie.isWin=vm;Ie.crcTable=ql});var Vl=de((dA,$l)=>{var Sm=xe("path");$l.exports=function(t,{fs:e}){var n=t||"",i=c(),o=null;function c(){return{directory:!1,readonly:!1,hidden:!1,executable:!1,mtime:0,atime:0}}return n&&e.existsSync(n)?(o=e.statSync(n),i.directory=o.isDirectory(),i.mtime=o.mtime,i.atime=o.atime,i.executable=(73&o.mode)!==0,i.readonly=(128&o.mode)===0,i.hidden=Sm.basename(n)[0]==="."):console.warn("Invalid path: "+n),{get directory(){return i.directory},get readOnly(){return i.readonly},get hidden(){return i.hidden},get mtime(){return i.mtime},get atime(){return i.atime},get executable(){return i.executable},decodeAttributes:function(){},encodeAttributes:function(){},toJSON:function(){return{path:n,isDirectory:i.directory,isReadOnly:i.readonly,isHidden:i.hidden,isExecutable:i.executable,mTime:i.mtime,aTime:i.atime}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Zl=de((lA,Jl)=>{Jl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var hr=de((uA,xr)=>{xr.exports=Kl();xr.exports.Constants=Na();xr.exports.Errors=bs();xr.exports.FileAttr=Vl();xr.exports.decoder=Zl()});var Xl=de((fA,Yl)=>{var un=hr(),G=un.Constants;Yl.exports=function(){var t=20,e=10,n=0,i=0,o=0,c=0,d=0,u=0,x=0,h=0,g=0,w=0,v=0,_=0,E=0;t|=un.isWin?2560:768,n|=G.FLG_EFS;let I={extraLen:0},A=y=>Math.max(0,y)>>>0,T=y=>Math.max(0,y)&65535,R=y=>Math.max(0,y)&255;return o=un.fromDate2DOS(new Date),{get made(){return t},set made(y){t=y},get version(){return e},set version(y){e=y},get flags(){return n},set flags(y){n=y},get flags_efs(){return(n&G.FLG_EFS)>0},set flags_efs(y){y?n|=G.FLG_EFS:n&=~G.FLG_EFS},get flags_desc(){return(n&G.FLG_DESC)>0},set flags_desc(y){y?n|=G.FLG_DESC:n&=~G.FLG_DESC},get method(){return i},set method(y){switch(y){case G.STORED:this.version=10;case G.DEFLATED:default:this.version=20}i=y},get time(){return un.fromDOS2Date(this.timeval)},set time(y){y=new Date(y),this.timeval=un.fromDate2DOS(y)},get timeval(){return o},set timeval(y){o=A(y)},get timeHighByte(){return R(o>>>8)},get crc(){return c},set crc(y){c=A(y)},get compressedSize(){return d},set compressedSize(y){d=A(y)},get size(){return u},set size(y){u=A(y)},get fileNameLength(){return x},set fileNameLength(y){x=y},get extraLength(){return h},set extraLength(y){h=y},get extraLocalLength(){return I.extraLen},set extraLocalLength(y){I.extraLen=y},get commentLength(){return g},set commentLength(y){g=y},get diskNumStart(){return w},set diskNumStart(y){w=A(y)},get inAttr(){return v},set inAttr(y){v=A(y)},get attr(){return _},set attr(y){_=A(y)},get fileAttr(){return(_||0)>>16&4095},get offset(){return E},set offset(y){E=A(y)},get encrypted(){return(n&G.FLG_ENC)===G.FLG_ENC},get centralHeaderSize(){return G.CENHDR+x+h+g},get realDataOffset(){return E+G.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(y){var C=y.slice(E,E+G.LOCHDR);if(C.readUInt32LE(0)!==G.LOCSIG)throw un.Errors.INVALID_LOC();I.version=C.readUInt16LE(G.LOCVER),I.flags=C.readUInt16LE(G.LOCFLG),I.flags_desc=(I.flags&G.FLG_DESC)>0,I.method=C.readUInt16LE(G.LOCHOW),I.time=C.readUInt32LE(G.LOCTIM),I.crc=C.readUInt32LE(G.LOCCRC),I.compressedSize=C.readUInt32LE(G.LOCSIZ),I.size=C.readUInt32LE(G.LOCLEN),I.fnameLen=C.readUInt16LE(G.LOCNAM),I.extraLen=C.readUInt16LE(G.LOCEXT);let D=E+G.LOCHDR+I.fnameLen,F=D+I.extraLen;return y.slice(D,F)},loadFromBinary:function(y){if(y.length!==G.CENHDR||y.readUInt32LE(0)!==G.CENSIG)throw un.Errors.INVALID_CEN();t=y.readUInt16LE(G.CENVEM),e=y.readUInt16LE(G.CENVER),n=y.readUInt16LE(G.CENFLG),i=y.readUInt16LE(G.CENHOW),o=y.readUInt32LE(G.CENTIM),c=y.readUInt32LE(G.CENCRC),d=y.readUInt32LE(G.CENSIZ),u=y.readUInt32LE(G.CENLEN),x=y.readUInt16LE(G.CENNAM),h=y.readUInt16LE(G.CENEXT),g=y.readUInt16LE(G.CENCOM),w=y.readUInt16LE(G.CENDSK),v=y.readUInt16LE(G.CENATT),_=y.readUInt32LE(G.CENATX),E=y.readUInt32LE(G.CENOFF)},localHeaderToBinary:function(){var y=Buffer.alloc(G.LOCHDR);return y.writeUInt32LE(G.LOCSIG,0),y.writeUInt16LE(e,G.LOCVER),y.writeUInt16LE(n,G.LOCFLG),y.writeUInt16LE(i,G.LOCHOW),y.writeUInt32LE(o,G.LOCTIM),y.writeUInt32LE(c,G.LOCCRC),y.writeUInt32LE(d,G.LOCSIZ),y.writeUInt32LE(u,G.LOCLEN),y.writeUInt16LE(x,G.LOCNAM),y.writeUInt16LE(I.extraLen,G.LOCEXT),y},centralHeaderToBinary:function(){var y=Buffer.alloc(G.CENHDR+x+h+g);return y.writeUInt32LE(G.CENSIG,0),y.writeUInt16LE(t,G.CENVEM),y.writeUInt16LE(e,G.CENVER),y.writeUInt16LE(n,G.CENFLG),y.writeUInt16LE(i,G.CENHOW),y.writeUInt32LE(o,G.CENTIM),y.writeUInt32LE(c,G.CENCRC),y.writeUInt32LE(d,G.CENSIZ),y.writeUInt32LE(u,G.CENLEN),y.writeUInt16LE(x,G.CENNAM),y.writeUInt16LE(h,G.CENEXT),y.writeUInt16LE(g,G.CENCOM),y.writeUInt16LE(w,G.CENDSK),y.writeUInt16LE(v,G.CENATT),y.writeUInt32LE(_,G.CENATX),y.writeUInt32LE(E,G.CENOFF),y},toJSON:function(){let y=function(C){return C+" bytes"};return{made:t,version:e,flags:n,method:un.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:y(d),size:y(u),fileNameLength:y(x),extraLength:y(h),commentLength:y(g),diskNumStart:w,inAttr:v,attr:_,offset:E,centralHeaderSize:y(G.CENHDR+x+h+g)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var eu=de((xA,Ql)=>{var pr=hr(),Ee=pr.Constants;Ql.exports=function(){var t=0,e=0,n=0,i=0,o=0;return{get diskEntries(){return t},set diskEntries(c){t=e=c},get totalEntries(){return e},set totalEntries(c){e=t=c},get size(){return n},set size(c){n=c},get offset(){return i},set offset(c){i=c},get commentLength(){return o},set commentLength(c){o=c},get mainHeaderSize(){return Ee.ENDHDR+o},loadFromBinary:function(c){if((c.length!==Ee.ENDHDR||c.readUInt32LE(0)!==Ee.ENDSIG)&&(c.length<Ee.ZIP64HDR||c.readUInt32LE(0)!==Ee.ZIP64SIG))throw pr.Errors.INVALID_END();c.readUInt32LE(0)===Ee.ENDSIG?(t=c.readUInt16LE(Ee.ENDSUB),e=c.readUInt16LE(Ee.ENDTOT),n=c.readUInt32LE(Ee.ENDSIZ),i=c.readUInt32LE(Ee.ENDOFF),o=c.readUInt16LE(Ee.ENDCOM)):(t=pr.readBigUInt64LE(c,Ee.ZIP64SUB),e=pr.readBigUInt64LE(c,Ee.ZIP64TOT),n=pr.readBigUInt64LE(c,Ee.ZIP64SIZE),i=pr.readBigUInt64LE(c,Ee.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(Ee.ENDHDR+o);return c.writeUInt32LE(Ee.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,Ee.ENDSUB),c.writeUInt16LE(e,Ee.ENDTOT),c.writeUInt32LE(n,Ee.ENDSIZ),c.writeUInt32LE(i,Ee.ENDOFF),c.writeUInt16LE(o,Ee.ENDCOM),c.fill(" ",Ee.ENDHDR),c},toJSON:function(){let c=function(d,u){let x=d.toString(16).toUpperCase();for(;x.length<u;)x="0"+x;return"0x"+x};return{diskEntries:t,totalEntries:e,size:n+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Ba=de(Ma=>{Ma.EntryHeader=Xl();Ma.MainHeader=eu()});var nu=de((pA,tu)=>{tu.exports=function(t){var e=xe("zlib"),n={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,n)},deflateAsync:function(i){var o=e.createDeflateRaw(n),c=[],d=0;o.on("data",function(u){c.push(u),d+=u.length}),o.on("end",function(){var u=Buffer.alloc(d),x=0;u.fill(0);for(var h=0;h<c.length;h++){var g=c[h];g.copy(u,x),x+=g.length}i&&i(u)}),o.end(t)}}}});var iu=de((gA,ru)=>{var Im=+(process.versions?process.versions.node:"").split(".")[0]||0;ru.exports=function(t,e){var n=xe("zlib");let i=Im>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return n.inflateRawSync(t,i)},inflateAsync:function(o){var c=n.createInflateRaw(i),d=[],u=0;c.on("data",function(x){d.push(x),u+=x.length}),c.on("end",function(){var x=Buffer.alloc(u),h=0;x.fill(0);for(var g=0;g<d.length;g++){var w=d[g];w.copy(x,h),h+=w.length}o&&o(x)}),c.end(t)}}}});var du=de((mA,cu)=>{"use strict";var{randomFillSync:su}=xe("crypto"),Am=bs(),km=new Uint32Array(256).map((t,e)=>{for(let n=0;n<8;n++)(e&1)!==0?e=e>>>1^3988292384:e>>>=1;return e>>>0}),au=(t,e)=>Math.imul(t,e)>>>0,ou=(t,e)=>km[(t^e)&255]^t>>>8,ci=()=>typeof su=="function"?su(Buffer.alloc(12)):ci.node();ci.node=()=>{let t=Buffer.alloc(12),e=t.length;for(let n=0;n<e;n++)t[n]=Math.random()*256&255;return t};var Es={genSalt:ci};function vs(t){let e=Buffer.isBuffer(t)?t:Buffer.from(t);this.keys=new Uint32Array([305419896,591751049,878082192]);for(let n=0;n<e.length;n++)this.updateKeys(e[n])}vs.prototype.updateKeys=function(t){let e=this.keys;return e[0]=ou(e[0],t),e[1]+=e[0]&255,e[1]=au(e[1],134775813)+1,e[2]=ou(e[2],e[1]>>>24),t};vs.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return au(t,t^1)>>8&255};function Tm(t){let e=new vs(t);return function(n){let i=Buffer.alloc(n.length),o=0;for(let c of n)i[o++]=e.updateKeys(c^e.next());return i}}function Cm(t){let e=new vs(t);return function(n,i,o=0){i||(i=Buffer.alloc(n.length));for(let c of n){let d=e.next();i[o++]=c^d,e.updateKeys(c)}return i}}function Pm(t,e,n){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Tm(n),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Am.WRONG_PASSWORD();return i(t.slice(12))}function Rm(t){Buffer.isBuffer(t)&&t.length>=12?Es.genSalt=function(){return t.slice(0,12)}:t==="node"?Es.genSalt=ci.node:Es.genSalt=ci}function Dm(t,e,n,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Cm(n),c=Es.genSalt();c[11]=e.crc>>>24&255,i&&(c[10]=e.crc>>>16&255);let d=Buffer.alloc(t.length+12);return o(c,d),o(t,d,12)}cu.exports={decrypt:Pm,encrypt:Dm,_salter:Rm}});var lu=de(Ss=>{Ss.Deflater=nu();Ss.Inflater=iu();Ss.ZipCrypto=du()});var za=de((_A,uu)=>{var le=hr(),Om=Ba(),Ae=le.Constants,Fa=lu();uu.exports=function(t,e){var n=new Om.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,d=null,u=Buffer.alloc(0),x=Buffer.alloc(0),h=!0;let g=t,w=typeof g.decoder=="object"?g.decoder:le.decoder;h=w.hasOwnProperty("efs")?w.efs:!1;function v(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(x=n.loadLocalHeaderFromBinary(e),e.slice(n.realDataOffset,n.realDataOffset+n.compressedSize))}function _(y){if(!n.flags_desc&&!n.localHeader.flags_desc){if(le.crc32(y)!==n.localHeader.crc)return!1}else{let C={},D=n.realDataOffset+n.compressedSize;if(e.readUInt32LE(D)==Ae.LOCSIG||e.readUInt32LE(D)==Ae.CENSIG)throw le.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(D)==Ae.EXTSIG)C.crc=e.readUInt32LE(D+Ae.EXTCRC),C.compressedSize=e.readUInt32LE(D+Ae.EXTSIZ),C.size=e.readUInt32LE(D+Ae.EXTLEN);else if(e.readUInt16LE(D+12)===19280)C.crc=e.readUInt32LE(D+Ae.EXTCRC-4),C.compressedSize=e.readUInt32LE(D+Ae.EXTSIZ-4),C.size=e.readUInt32LE(D+Ae.EXTLEN-4);else throw le.Errors.DESCRIPTOR_UNKNOWN();if(C.compressedSize!==n.compressedSize||C.size!==n.size||C.crc!==n.crc)throw le.Errors.DESCRIPTOR_FAULTY();if(le.crc32(y)!==C.crc)return!1}return!0}function E(y,C,D){if(typeof C>"u"&&typeof y=="string"&&(D=y,y=void 0),c)return y&&C&&C(Buffer.alloc(0),le.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var F=v();if(F.length===0)return y&&C&&C(F),F;if(n.encrypted){if(typeof D!="string"&&!Buffer.isBuffer(D))throw le.Errors.INVALID_PASS_PARAM();F=Fa.ZipCrypto.decrypt(F,n,D)}var B=Buffer.alloc(n.size);switch(n.method){case le.Constants.STORED:if(F.copy(B),_(B))return y&&C&&C(B),B;throw y&&C&&C(B,le.Errors.BAD_CRC()),le.Errors.BAD_CRC();case le.Constants.DEFLATED:var Y=new Fa.Inflater(F,n.size);if(y)Y.inflateAsync(function(Z){Z.copy(Z,0),C&&(_(Z)?C(Z):C(Z,le.Errors.BAD_CRC()))});else{if(Y.inflate(B).copy(B,0),!_(B))throw le.Errors.BAD_CRC(`"${w.decode(i)}"`);return B}break;default:throw y&&C&&C(Buffer.alloc(0),le.Errors.UNKNOWN_METHOD()),le.Errors.UNKNOWN_METHOD()}}function I(y,C){if((!d||!d.length)&&Buffer.isBuffer(e))return y&&C&&C(v()),v();if(d.length&&!c){var D;switch(n.method){case le.Constants.STORED:return n.compressedSize=n.size,D=Buffer.alloc(d.length),d.copy(D),y&&C&&C(D),D;default:case le.Constants.DEFLATED:var F=new Fa.Deflater(d);if(y)F.deflateAsync(function(Y){D=Buffer.alloc(Y.length),n.compressedSize=Y.length,Y.copy(D),C&&C(D)});else{var B=F.deflate();return n.compressedSize=B.length,B}F=null;break}}else if(y&&C)C(Buffer.alloc(0));else return Buffer.alloc(0)}function A(y,C){return le.readBigUInt64LE(y,C)}function T(y){try{for(var C=0,D,F,B;C+4<y.length;)D=y.readUInt16LE(C),C+=2,F=y.readUInt16LE(C),C+=2,B=y.slice(C,C+F),C+=F,Ae.ID_ZIP64===D&&R(B)}catch{throw le.Errors.EXTRA_FIELD_PARSE_ERROR()}}function R(y){var C,D,F,B;y.length>=Ae.EF_ZIP64_SCOMP&&(C=A(y,Ae.EF_ZIP64_SUNCOMP),n.size===Ae.EF_ZIP64_OR_32&&(n.size=C)),y.length>=Ae.EF_ZIP64_RHO&&(D=A(y,Ae.EF_ZIP64_SCOMP),n.compressedSize===Ae.EF_ZIP64_OR_32&&(n.compressedSize=D)),y.length>=Ae.EF_ZIP64_DSN&&(F=A(y,Ae.EF_ZIP64_RHO),n.offset===Ae.EF_ZIP64_OR_32&&(n.offset=F)),y.length>=Ae.EF_ZIP64_DSN+4&&(B=y.readUInt32LE(Ae.EF_ZIP64_DSN),n.diskNumStart===Ae.EF_ZIP64_OR_16&&(n.diskNumStart=B))}return{get entryName(){return w.decode(i)},get rawEntryName(){return i},set entryName(y){i=le.toBuffer(y,w.encode);var C=i[i.length-1];c=C===47||C===92,n.fileNameLength=i.length},get efs(){return typeof h=="function"?h(this.entryName):h},get extra(){return u},set extra(y){u=y,n.extraLength=y.length,T(y)},get comment(){return w.decode(o)},set comment(y){if(o=le.toBuffer(y,w.encode),n.commentLength=o.length,o.length>65535)throw le.Errors.COMMENT_TOO_LONG()},get name(){var y=w.decode(i);return c?y.substr(y.length-1).split("/").pop():y.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(y){I(!0,y)},setData:function(y){d=le.toBuffer(y,le.decoder.encode),!c&&d.length?(n.size=d.length,n.method=le.Constants.DEFLATED,n.crc=le.crc32(y),n.changed=!0):n.method=le.Constants.STORED},getData:function(y){return n.changed?d:E(!1,null,y)},getDataAsync:function(y,C){n.changed?y(d):E(!0,y,C)},set attr(y){n.attr=y},get attr(){return n.attr},set header(y){n.loadFromBinary(y)},get header(){return n},packCentralHeader:function(){n.flags_efs=this.efs,n.extraLength=u.length;var y=n.centralHeaderToBinary(),C=le.Constants.CENHDR;return i.copy(y,C),C+=i.length,u.copy(y,C),C+=n.extraLength,o.copy(y,C),y},packLocalHeader:function(){let y=0;n.flags_efs=this.efs,n.extraLocalLength=x.length;let C=n.localHeaderToBinary(),D=Buffer.alloc(C.length+i.length+n.extraLocalLength);return C.copy(D,y),y+=C.length,i.copy(D,y),y+=i.length,x.copy(D,y),y+=x.length,D},toJSON:function(){let y=function(C){return"<"+(C&&C.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:n.toJSON(),compressedData:y(e),data:y(d)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var hu=de((yA,xu)=>{var fu=za(),Lm=Ba(),Ve=hr();xu.exports=function(t,e){var n=[],i={},o=Buffer.alloc(0),c=new Lm.MainHeader,d=!1,u=null;let x=new Set,h=e,{noSort:g,decoder:w}=h;t?E(h.readEntries):d=!0;function v(){let A=new Set;for(let T of Object.keys(i)){let R=T.split("/");if(R.pop(),!!R.length)for(let y=0;y<R.length;y++){let C=R.slice(0,y+1).join("/")+"/";A.add(C)}}for(let T of A)if(!(T in i)){let R=new fu(h);R.entryName=T,R.attr=16,R.temporary=!0,n.push(R),i[R.entryName]=R,x.add(R)}}function _(){if(d=!0,i={},c.diskEntries>(t.length-c.offset)/Ve.Constants.CENHDR)throw Ve.Errors.DISK_ENTRY_TOO_LARGE();n=new Array(c.diskEntries);for(var A=c.offset,T=0;T<n.length;T++){var R=A,y=new fu(h,t);y.header=t.slice(R,R+=Ve.Constants.CENHDR),y.entryName=t.slice(R,R+=y.header.fileNameLength),y.header.extraLength&&(y.extra=t.slice(R,R+=y.header.extraLength)),y.header.commentLength&&(y.comment=t.slice(R,R+y.header.commentLength)),A+=y.header.centralHeaderSize,n[T]=y,i[y.entryName]=y}x.clear(),v()}function E(A){var T=t.length-Ve.Constants.ENDHDR,R=Math.max(0,T-65535),y=R,C=t.length,D=-1,F=0;for(typeof h.trailingSpace=="boolean"&&h.trailingSpace&&(R=0),T;T>=y;T--)if(t[T]===80){if(t.readUInt32LE(T)===Ve.Constants.ENDSIG){D=T,F=T,C=T+Ve.Constants.ENDHDR,y=T-Ve.Constants.END64HDR;continue}if(t.readUInt32LE(T)===Ve.Constants.END64SIG){y=R;continue}if(t.readUInt32LE(T)===Ve.Constants.ZIP64SIG){D=T,C=T+Ve.readBigUInt64LE(t,T+Ve.Constants.ZIP64SIZE)+Ve.Constants.ZIP64LEAD;break}}if(D==-1)throw Ve.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(D,C)),c.commentLength&&(o=t.slice(F+Ve.Constants.ENDHDR)),A&&_()}function I(){n.length>1&&!g&&n.sort((A,T)=>A.entryName.toLowerCase().localeCompare(T.entryName.toLowerCase()))}return{get entries(){return d||_(),n.filter(A=>!x.has(A))},get comment(){return w.decode(o)},set comment(A){o=Ve.toBuffer(A,w.encode),c.commentLength=o.length},getEntryCount:function(){return d?n.length:c.diskEntries},forEach:function(A){this.entries.forEach(A)},getEntry:function(A){return d||_(),i[A]||null},setEntry:function(A){d||_(),n.push(A),i[A.entryName]=A,c.totalEntries=n.length},deleteFile:function(A,T=!0){d||_();let R=i[A];this.getEntryChildren(R,T).map(C=>C.entryName).forEach(this.deleteEntry)},deleteEntry:function(A){d||_();let T=i[A],R=n.indexOf(T);R>=0&&(n.splice(R,1),delete i[A],c.totalEntries=n.length)},getEntryChildren:function(A,T=!0){if(d||_(),typeof A=="object")if(A.isDirectory&&T){let R=[],y=A.entryName;for(let C of n)C.entryName.startsWith(y)&&R.push(C);return R}else return[A];return[]},getChildCount:function(A){if(A&&A.isDirectory){let T=this.getEntryChildren(A);return T.includes(A)?T.length-1:T.length}return 0},compressToBuffer:function(){d||_(),I();let A=[],T=[],R=0,y=0;c.size=0,c.offset=0;let C=0;for(let B of this.entries){let Y=B.getCompressedData();B.header.offset=y;let Z=B.packLocalHeader(),se=Z.length+Y.length;y+=se,A.push(Z),A.push(Y);let Q=B.packCentralHeader();T.push(Q),c.size+=Q.length,R+=se+Q.length,C++}R+=c.mainHeaderSize,c.offset=y,c.totalEntries=C,y=0;let D=Buffer.alloc(R);for(let B of A)B.copy(D,y),y+=B.length;for(let B of T)B.copy(D,y),y+=B.length;let F=c.toBinary();return o&&o.copy(F,Ve.Constants.ENDHDR),F.copy(D,y),t=D,d=!1,D},toAsyncBuffer:function(A,T,R,y){try{d||_(),I();let C=[],D=[],F=0,B=0,Y=0;c.size=0,c.offset=0;let Z=function(se){if(se.length>0){let Q=se.shift(),ae=Q.entryName+Q.extra.toString();R&&R(ae),Q.getCompressedDataAsync(function(ce){y&&y(ae),Q.header.offset=B;let P=Q.packLocalHeader(),j=P.length+ce.length;B+=j,C.push(P),C.push(ce);let V=Q.packCentralHeader();D.push(V),c.size+=V.length,F+=j+V.length,Y++,Z(se)})}else{F+=c.mainHeaderSize,c.offset=B,c.totalEntries=Y,B=0;let Q=Buffer.alloc(F);C.forEach(function(ce){ce.copy(Q,B),B+=ce.length}),D.forEach(function(ce){ce.copy(Q,B),B+=ce.length});let ae=c.toBinary();o&&o.copy(ae,Ve.Constants.ENDHDR),ae.copy(Q,B),t=Q,d=!1,A(Q)}};Z(Array.from(this.entries))}catch(C){T(C)}}}}});var mu=de((bA,gu)=>{var Se=hr(),ve=xe("path"),Nm=za(),Mm=hu(),On=(...t)=>Se.findLast(t,e=>typeof e=="boolean"),pu=(...t)=>Se.findLast(t,e=>typeof e=="string"),Bm=(...t)=>Se.findLast(t,e=>typeof e=="function"),Fm={noSort:!1,readEntries:!1,method:Se.Constants.NONE,fs:null};gu.exports=function(t,e){let n=null,i=Object.assign(Object.create(null),Fm);t&&typeof t=="object"&&(t instanceof Uint8Array||(Object.assign(i,t),t=i.input?i.input:void 0,i.input&&delete i.input),Buffer.isBuffer(t)&&(n=t,i.method=Se.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new Se(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=Se.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=Se.Constants.FILE,i.filename=t,n=o.fs.readFileSync(t);else throw Se.Errors.INVALID_FILENAME();let c=new Mm(n,i),{canonical:d,sanitize:u,zipnamefix:x}=Se;function h(_){if(_&&c){var E;if(typeof _=="string"&&(E=c.getEntry(ve.posix.normalize(_))),typeof _=="object"&&typeof _.entryName<"u"&&typeof _.header<"u"&&(E=c.getEntry(_.entryName)),E)return E}return null}function g(_){let{join:E,normalize:I,sep:A}=ve.posix;return E(ve.isAbsolute(_)?"/":".",I(A+_.split("\\").join(A)+A))}function w(_){return _ instanceof RegExp?(function(E){return function(I){return E.test(I)}})(_):typeof _!="function"?()=>!0:_}let v=(_,E)=>{let I=E.slice(-1);return I=I===o.sep?o.sep:"",ve.relative(_,E)+I};return{readFile:function(_,E){var I=h(_);return I&&I.getData(E)||null},childCount:function(_){let E=h(_);if(E)return c.getChildCount(E)},readFileAsync:function(_,E){var I=h(_);I?I.getDataAsync(E):E(null,"getEntry failed for:"+_)},readAsText:function(_,E){var I=h(_);if(I){var A=I.getData();if(A&&A.length)return A.toString(E||"utf8")}return""},readAsTextAsync:function(_,E,I){var A=h(_);A?A.getDataAsync(function(T,R){if(R){E(T,R);return}T&&T.length?E(T.toString(I||"utf8")):E("")}):E("")},deleteFile:function(_,E=!0){var I=h(_);I&&c.deleteFile(I.entryName,E)},deleteEntry:function(_){var E=h(_);E&&c.deleteEntry(E.entryName)},addZipComment:function(_){c.comment=_},getZipComment:function(){return c.comment||""},addZipEntryComment:function(_,E){var I=h(_);I&&(I.comment=E)},getZipEntryComment:function(_){var E=h(_);return E&&E.comment||""},updateFile:function(_,E){var I=h(_);I&&I.setData(E)},addLocalFile:function(_,E,I,A){if(o.fs.existsSync(_)){E=E?g(E):"";let T=ve.win32.basename(ve.win32.normalize(_));E+=I||T;let R=o.fs.statSync(_),y=R.isFile()?o.fs.readFileSync(_):Buffer.alloc(0);R.isDirectory()&&(E+=o.sep),this.addFile(E,y,A,R)}else throw Se.Errors.FILE_NOT_FOUND(_)},addLocalFileAsync:function(_,E){_=typeof _=="object"?_:{localPath:_};let I=ve.resolve(_.localPath),{comment:A}=_,{zipPath:T,zipName:R}=_,y=this;o.fs.stat(I,function(C,D){if(C)return E(C,!1);T=T?g(T):"";let F=ve.win32.basename(ve.win32.normalize(I));if(T+=R||F,D.isFile())o.fs.readFile(I,function(B,Y){return B?E(B,!1):(y.addFile(T,Y,A,D),setImmediate(E,void 0,!0))});else if(D.isDirectory())return T+=o.sep,y.addFile(T,Buffer.alloc(0),A,D),setImmediate(E,void 0,!0)})},addLocalFolder:function(_,E,I){if(I=w(I),E=E?g(E):"",_=ve.normalize(_),o.fs.existsSync(_)){let A=o.findFiles(_),T=this;if(A.length)for(let R of A){let y=ve.join(E,v(_,R));I(y)&&T.addLocalFile(R,ve.dirname(y))}}else throw Se.Errors.FILE_NOT_FOUND(_)},addLocalFolderAsync:function(_,E,I,A){A=w(A),I=I?g(I):"",_=ve.normalize(_);var T=this;o.fs.open(_,"r",function(R){if(R&&R.code==="ENOENT")E(void 0,Se.Errors.FILE_NOT_FOUND(_));else if(R)E(void 0,R);else{var y=o.findFiles(_),C=-1,D=function(){if(C+=1,C<y.length){var F=y[C],B=v(_,F).split("\\").join("/");B=B.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),A(B)?o.fs.stat(F,function(Y,Z){Y&&E(void 0,Y),Z.isFile()?o.fs.readFile(F,function(se,Q){se?E(void 0,se):(T.addFile(I+B,Q,"",Z),D())}):(T.addFile(I+B+"/",Buffer.alloc(0),"",Z),D())}):process.nextTick(()=>{D()})}else E(!0,void 0)};D()}})},addLocalFolderAsync2:function(_,E){let I=this;_=typeof _=="object"?_:{localPath:_},localPath=ve.resolve(g(_.localPath));let{zipPath:A,filter:T,namefix:R}=_;T instanceof RegExp?T=(function(D){return function(F){return D.test(F)}})(T):typeof T!="function"&&(T=function(){return!0}),A=A?g(A):"",R=="latin1"&&(R=D=>D.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof R!="function"&&(R=D=>D);let y=D=>ve.join(A,R(v(localPath,D))),C=D=>ve.win32.basename(ve.win32.normalize(R(D)));o.fs.open(localPath,"r",function(D){D&&D.code==="ENOENT"?E(void 0,Se.Errors.FILE_NOT_FOUND(localPath)):D?E(void 0,D):o.findFilesAsync(localPath,function(F,B){if(F)return E(F);B=B.filter(Y=>T(y(Y))),B.length||E(void 0,!1),setImmediate(B.reverse().reduce(function(Y,Z){return function(se,Q){if(se||Q===!1)return setImmediate(Y,se,!1);I.addLocalFileAsync({localPath:Z,zipPath:ve.dirname(y(Z)),zipName:C(Z)},Y)}},E))})})},addLocalFolderPromise:function(_,E){return new Promise((I,A)=>{this.addLocalFolderAsync2(Object.assign({localPath:_},E),(T,R)=>{T&&A(T),R&&I(this)})})},addFile:function(_,E,I,A){_=x(_);let T=h(_),R=T!=null;R||(T=new Nm(i),T.entryName=_),T.comment=I||"";let y=typeof A=="object"&&A instanceof o.fs.Stats;y&&(T.header.time=A.mtime);var C=T.isDirectory?16:0;let D=T.isDirectory?16384:32768;return y?D|=4095&A.mode:typeof A=="number"?D|=4095&A:D|=T.isDirectory?493:420,C=(C|D<<16)>>>0,T.attr=C,T.setData(E),R||c.setEntry(T),T},getEntries:function(_){return c.password=_,c?c.entries:[]},getEntry:function(_){return h(_)},getEntryCount:function(){return c.getEntryCount()},forEach:function(_){return c.forEach(_)},extractEntryTo:function(_,E,I,A,T,R){A=On(!1,A),T=On(!1,T),I=On(!0,I),R=pu(T,R);var y=h(_);if(!y)throw Se.Errors.NO_ENTRY();var C=d(y.entryName),D=u(E,R&&!y.isDirectory?R:I?C:ve.basename(C));if(y.isDirectory){var F=c.getEntryChildren(y);return F.forEach(function(Z){if(Z.isDirectory)return;var se=Z.getData();if(!se)throw Se.Errors.CANT_EXTRACT_FILE();var Q=d(Z.entryName),ae=u(E,I?Q:ve.basename(Q));let ce=T?Z.header.fileAttr:void 0;o.writeFileTo(ae,se,A,ce)}),!0}var B=y.getData(c.password);if(!B)throw Se.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(D)&&!A)throw Se.Errors.CANT_OVERRIDE();let Y=T?_.header.fileAttr:void 0;return o.writeFileTo(D,B,A,Y),!0},test:function(_){if(!c)return!1;for(var E in c.entries)try{if(E.isDirectory)continue;var I=c.entries[E].getData(_);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(_,E,I,A){if(I=On(!1,I),A=pu(I,A),E=On(!1,E),!c)throw Se.Errors.NO_ZIP();c.entries.forEach(function(T){var R=u(_,d(T.entryName));if(T.isDirectory){o.makeDir(R);return}var y=T.getData(A);if(!y)throw Se.Errors.CANT_EXTRACT_FILE();let C=I?T.header.fileAttr:void 0;o.writeFileTo(R,y,E,C);try{o.fs.utimesSync(R,T.header.time,T.header.time)}catch{throw Se.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(_,E,I,A){if(A=Bm(E,I,A),I=On(!1,I),E=On(!1,E),!A)return new Promise((D,F)=>{this.extractAllToAsync(_,E,I,function(B){B?F(B):D(this)})});if(!c){A(Se.Errors.NO_ZIP());return}_=ve.resolve(_);let T=D=>u(_,ve.normalize(d(D.entryName))),R=(D,F)=>new Error(D+': "'+F+'"'),y=[],C=[];c.entries.forEach(D=>{D.isDirectory?y.push(D):C.push(D)});for(let D of y){let F=T(D),B=I?D.header.fileAttr:void 0;try{o.makeDir(F),B&&o.fs.chmodSync(F,B),o.fs.utimesSync(F,D.header.time,D.header.time)}catch{A(R("Unable to create folder",F))}}C.reverse().reduce(function(D,F){return function(B){if(B)D(B);else{let Y=ve.normalize(d(F.entryName)),Z=u(_,Y);F.getDataAsync(function(se,Q){if(Q)D(Q);else if(!se)D(Se.Errors.CANT_EXTRACT_FILE());else{let ae=I?F.header.fileAttr:void 0;o.writeFileToAsync(Z,se,E,ae,function(ce){ce||D(R("Unable to write file",Z)),o.fs.utimes(Z,F.header.time,F.header.time,function(P){P?D(R("Unable to set times",Z)):D()})})}})}}},A)()},writeZip:function(_,E){if(arguments.length===1&&typeof _=="function"&&(E=_,_=""),!_&&i.filename&&(_=i.filename),!!_){var I=c.compressToBuffer();if(I){var A=o.writeFileTo(_,I,!0);typeof E=="function"&&E(A?null:new Error("failed"),"")}}},writeZipPromise:function(_,E){let{overwrite:I,perm:A}=Object.assign({overwrite:!0},E);return new Promise((T,R)=>{!_&&i.filename&&(_=i.filename),_||R("ADM-ZIP: ZIP File Name Missing"),this.toBufferPromise().then(y=>{let C=D=>D?T(D):R("ADM-ZIP: Wasn't able to write zip file");o.writeFileToAsync(_,y,I,A,C)},R)})},toBufferPromise:function(){return new Promise((_,E)=>{c.toAsyncBuffer(_,E)})},toBuffer:function(_,E,I,A){return typeof _=="function"?(c.toAsyncBuffer(_,E,I,A),null):c.compressToBuffer()}}}});import{execFile as q_,spawn as W_,spawnSync as z2}from"node:child_process";import{promisify as K_}from"node:util";function V_(t){if(process.platform!=="win32")return!1;if(Bf.test(t))return!0;let n=(t.split(/[/\\]/).pop()??t).replace(Bf,"").toLowerCase();return $_.has(n)}function Ff(t,e){if(process.platform!=="win32")return e??{};let n={...e??{}};return V_(t)&&n.shell===void 0&&(n.shell=!0),n.windowsHide===void 0&&(n.windowsHide=!0),n}function st(t,e=[],n={}){return W_(t,e,Ff(t,n))}function zf(t,e=[],n={}){return J_(t,e,Ff(t,n))}var $_,Bf,J_,Vt=nt(()=>{"use strict";$_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Bf=/\.(cmd|bat|ps1)$/i;J_=K_(q_)});var Zt=de((EP,kx)=>{"use strict";var Ix=["nodebuffer","arraybuffer","fragments"],Ax=typeof Blob<"u";Ax&&Ix.push("blob");kx.exports={BINARY_TYPES:Ix,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:Ax,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var Ji=de((vP,Do)=>{"use strict";var{EMPTY_BUFFER:kE}=Zt(),md=Buffer[Symbol.species];function TE(t,e){if(t.length===0)return kE;if(t.length===1)return t[0];let n=Buffer.allocUnsafe(e),i=0;for(let o=0;o<t.length;o++){let c=t[o];n.set(c,i),i+=c.length}return i<e?new md(n.buffer,n.byteOffset,i):n}function Tx(t,e,n,i,o){for(let c=0;c<o;c++)n[i+c]=t[c]^e[c&3]}function Cx(t,e){for(let n=0;n<t.length;n++)t[n]^=e[n&3]}function CE(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function wd(t){if(wd.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new md(t):ArrayBuffer.isView(t)?e=new md(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),wd.readOnly=!1),e}Do.exports={concat:TE,mask:Tx,toArrayBuffer:CE,toBuffer:wd,unmask:Cx};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=xe("bufferutil");Do.exports.mask=function(e,n,i,o,c){c<48?Tx(e,n,i,o,c):t.mask(e,n,i,o,c)},Do.exports.unmask=function(e,n){e.length<32?Cx(e,n):t.unmask(e,n)}}catch{}});var Dx=de((SP,Rx)=>{"use strict";var Px=Symbol("kDone"),_d=Symbol("kRun"),yd=class{constructor(e){this[Px]=()=>{this.pending--,this[_d]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[_d]()}[_d](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Px])}}};Rx.exports=yd});var Gr=de((IP,Mx)=>{"use strict";var Zi=xe("zlib"),Ox=Ji(),PE=Dx(),{kStatusCode:Lx}=Zt(),RE=Buffer[Symbol.species],DE=Buffer.from([0,0,255,255]),Lo=Symbol("permessage-deflate"),Yt=Symbol("total-length"),zr=Symbol("callback"),Tn=Symbol("buffers"),Ur=Symbol("error"),Oo,bd=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,!Oo){let n=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Oo=new PE(n)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[zr];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let n=this._options,i=e.find(o=>!(n.serverNoContextTakeover===!1&&o.server_no_context_takeover||o.server_max_window_bits&&(n.serverMaxWindowBits===!1||typeof n.serverMaxWindowBits=="number"&&n.serverMaxWindowBits>o.server_max_window_bits)||typeof n.clientMaxWindowBits=="number"&&!o.client_max_window_bits));if(!i)throw new Error("None of the extension offers can be accepted");return n.serverNoContextTakeover&&(i.server_no_context_takeover=!0),n.clientNoContextTakeover&&(i.client_no_context_takeover=!0),typeof n.serverMaxWindowBits=="number"&&(i.server_max_window_bits=n.serverMaxWindowBits),typeof n.clientMaxWindowBits=="number"?i.client_max_window_bits=n.clientMaxWindowBits:(i.client_max_window_bits===!0||n.clientMaxWindowBits===!1)&&delete i.client_max_window_bits,i}acceptAsClient(e){let n=e[0];if(this._options.clientNoContextTakeover===!1&&n.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!n.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(n.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&n.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return n}normalizeParams(e){return e.forEach(n=>{Object.keys(n).forEach(i=>{let o=n[i];if(o.length>1)throw new Error(`Parameter "${i}" must have only a single value`);if(o=o[0],i==="client_max_window_bits"){if(o!==!0){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else if(i==="server_max_window_bits"){let c=+o;if(!Number.isInteger(c)||c<8||c>15)throw new TypeError(`Invalid value for parameter "${i}": ${o}`);o=c}else if(i==="client_no_context_takeover"||i==="server_no_context_takeover"){if(o!==!0)throw new TypeError(`Invalid value for parameter "${i}": ${o}`)}else throw new Error(`Unknown parameter "${i}"`);n[i]=o})}),e}decompress(e,n,i){Oo.add(o=>{this._decompress(e,n,(c,d)=>{o(),i(c,d)})})}compress(e,n,i){Oo.add(o=>{this._compress(e,n,(c,d)=>{o(),i(c,d)})})}_decompress(e,n,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,d=typeof this.params[c]!="number"?Zi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Zi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:d}),this._inflate[Lo]=this,this._inflate[Yt]=0,this._inflate[Tn]=[],this._inflate.on("error",LE),this._inflate.on("data",Nx)}this._inflate[zr]=i,this._inflate.write(e),n&&this._inflate.write(DE),this._inflate.flush(()=>{let c=this._inflate[Ur];if(c){this._inflate.close(),this._inflate=null,i(c);return}let d=Ox.concat(this._inflate[Tn],this._inflate[Yt]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[Yt]=0,this._inflate[Tn]=[],n&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,d)})}_compress(e,n,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,d=typeof this.params[c]!="number"?Zi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Zi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:d}),this._deflate[Yt]=0,this._deflate[Tn]=[],this._deflate.on("data",OE)}this._deflate[zr]=i,this._deflate.write(e),this._deflate.flush(Zi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=Ox.concat(this._deflate[Tn],this._deflate[Yt]);n&&(c=new RE(c.buffer,c.byteOffset,c.length-4)),this._deflate[zr]=null,this._deflate[Yt]=0,this._deflate[Tn]=[],n&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};Mx.exports=bd;function OE(t){this[Tn].push(t),this[Yt]+=t.length}function Nx(t){if(this[Yt]+=t.length,this[Lo]._maxPayload<1||this[Yt]<=this[Lo]._maxPayload){this[Tn].push(t);return}this[Ur]=new RangeError("Max payload size exceeded"),this[Ur].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Ur][Lx]=1009,this.removeListener("data",Nx),this.reset()}function LE(t){if(this[Lo]._inflate=null,this[Ur]){this[zr](this[Ur]);return}t[Lx]=1007,this[zr](t)}});var jr=de((AP,No)=>{"use strict";var{isUtf8:Bx}=xe("buffer"),{hasBlob:NE}=Zt(),ME=[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 BE(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function Ed(t){let e=t.length,n=0;for(;n<e;)if((t[n]&128)===0)n++;else if((t[n]&224)===192){if(n+1===e||(t[n+1]&192)!==128||(t[n]&254)===192)return!1;n+=2}else if((t[n]&240)===224){if(n+2>=e||(t[n+1]&192)!==128||(t[n+2]&192)!==128||t[n]===224&&(t[n+1]&224)===128||t[n]===237&&(t[n+1]&224)===160)return!1;n+=3}else if((t[n]&248)===240){if(n+3>=e||(t[n+1]&192)!==128||(t[n+2]&192)!==128||(t[n+3]&192)!==128||t[n]===240&&(t[n+1]&240)===128||t[n]===244&&t[n+1]>143||t[n]>244)return!1;n+=4}else return!1;return!0}function FE(t){return NE&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}No.exports={isBlob:FE,isValidStatusCode:BE,isValidUTF8:Ed,tokenChars:ME};if(Bx)No.exports.isValidUTF8=function(t){return t.length<24?Ed(t):Bx(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=xe("utf-8-validate");No.exports.isValidUTF8=function(e){return e.length<32?Ed(e):t(e)}}catch{}});var kd=de((kP,qx)=>{"use strict";var{Writable:zE}=xe("stream"),Fx=Gr(),{BINARY_TYPES:UE,EMPTY_BUFFER:zx,kStatusCode:GE,kWebSocket:jE}=Zt(),{concat:vd,toArrayBuffer:HE,unmask:qE}=Ji(),{isValidStatusCode:WE,isValidUTF8:Ux}=jr(),Mo=Buffer[Symbol.species],ht=0,Gx=1,jx=2,Hx=3,Sd=4,Id=5,Bo=6,Ad=class extends zE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||UE[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[jE]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=ht}_write(e,n,i){if(this._opcode===8&&this._state==ht)return i();if(this._maxBufferedChunks>0&&this._buffers.length>=this._maxBufferedChunks){i(this.createError(RangeError,"Too many buffered chunks",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS"));return}this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new Mo(i.buffer,i.byteOffset+e,i.length-e),new Mo(i.buffer,i.byteOffset,e)}let n=Buffer.allocUnsafe(e);do{let i=this._buffers[0],o=n.length-e;e>=i.length?n.set(this._buffers.shift(),o):(n.set(new Uint8Array(i.buffer,i.byteOffset,e),o),this._buffers[0]=new Mo(i.buffer,i.byteOffset+e,i.length-e)),e-=i.length}while(e>0);return n}startLoop(e){this._loop=!0;do switch(this._state){case ht:this.getInfo(e);break;case Gx:this.getPayloadLength16(e);break;case jx:this.getPayloadLength64(e);break;case Hx:this.getMask();break;case Sd:this.getData(e);break;case Id:case Bo:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let n=this.consume(2);if((n[0]&48)!==0){let o=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(o);return}let i=(n[0]&64)===64;if(i&&!this._extensions[Fx.extensionName]){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._fin=(n[0]&128)===128,this._opcode=n[0]&15,this._payloadLength=n[1]&127,this._opcode===0){if(i){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(!this._fragmented){let o=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let o=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}this._compressed=i}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let o=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(o);return}if(i){let o=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(o);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let o=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(o);return}}else{let o=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(o);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(n[1]&128)===128,this._isServer){if(!this._masked){let o=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(o);return}}else if(this._masked){let o=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(o);return}this._payloadLength===126?this._state=Gx:this._payloadLength===127?this._state=jx:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let n=this.consume(8),i=n.readUInt32BE(0);if(i>Math.pow(2,21)-1){let o=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(o);return}this._payloadLength=i*Math.pow(2,32)+n.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let n=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(n);return}this._masked?this._state=Hx:this._state=Sd}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Sd}getData(e){let n=zx;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}n=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&qE(n,this._mask)}if(this._opcode>7){this.controlMessage(n,e);return}if(this._compressed){this._state=Id,this.decompress(n,e);return}if(n.length){if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let i=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");e(i);return}this._messageLength=this._totalPayloadLength,this._fragments.push(n)}this.dataMessage(e)}decompress(e,n){this._extensions[Fx.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return n(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let d=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");n(d);return}if(this._maxFragments>0&&this._fragments.length>=this._maxFragments){let d=this.createError(RangeError,"Too many message fragments",!1,1008,"WS_ERR_TOO_MANY_BUFFERED_PARTS");n(d);return}this._fragments.push(c)}this.dataMessage(n),this._state===ht&&this.startLoop(n)})}dataMessage(e){if(!this._fin){this._state=ht;return}let n=this._messageLength,i=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let o;this._binaryType==="nodebuffer"?o=vd(i,n):this._binaryType==="arraybuffer"?o=HE(vd(i,n)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=ht):(this._state=Bo,setImmediate(()=>{this.emit("message",o,!0),this._state=ht,this.startLoop(e)}))}else{let o=vd(i,n);if(!this._skipUTF8Validation&&!Ux(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===Id||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=ht):(this._state=Bo,setImmediate(()=>{this.emit("message",o,!1),this._state=ht,this.startLoop(e)}))}}controlMessage(e,n){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,zx),this.end();else{let i=e.readUInt16BE(0);if(!WE(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");n(c);return}let o=new Mo(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!Ux(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");n(c);return}this._loop=!1,this.emit("conclude",i,o),this.end()}this._state=ht;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=ht):(this._state=Bo,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=ht,this.startLoop(n)}))}createError(e,n,i,o,c){this._loop=!1,this._errored=!0;let d=new e(i?`Invalid WebSocket frame: ${n}`:n);return Error.captureStackTrace(d,this.createError),d.code=c,d[GE]=o,d}};qx.exports=Ad});var Pd=de((CP,$x)=>{"use strict";var{Duplex:TP}=xe("stream"),{randomFillSync:KE}=xe("crypto"),{types:{isUint8Array:$E}}=xe("util"),Wx=Gr(),{EMPTY_BUFFER:VE,kWebSocket:JE,NOOP:ZE}=Zt(),{isBlob:Hr,isValidStatusCode:YE}=jr(),{mask:Kx,toBuffer:Jn}=Ji(),pt=Symbol("kByteLength"),XE=Buffer.alloc(4),Fo=8*1024,Zn,qr=Fo,St=0,QE=1,ev=2,Td=class t{constructor(e,n,i){this._extensions=n||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=St,this.onerror=ZE,this[JE]=void 0}static frame(e,n){let i,o=!1,c=2,d=!1;n.mask&&(i=n.maskBuffer||XE,n.generateMask?n.generateMask(i):(qr===Fo&&(Zn===void 0&&(Zn=Buffer.alloc(Fo)),KE(Zn,0,Fo),qr=0),i[0]=Zn[qr++],i[1]=Zn[qr++],i[2]=Zn[qr++],i[3]=Zn[qr++]),d=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!n.mask||d)&&n[pt]!==void 0?u=n[pt]:(e=Buffer.from(e),u=e.length):(u=e.length,o=n.mask&&n.readOnly&&!d);let x=u;u>=65536?(c+=8,x=127):u>125&&(c+=2,x=126);let h=Buffer.allocUnsafe(o?u+c:c);return h[0]=n.fin?n.opcode|128:n.opcode,n.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)),n.mask?(h[1]|=128,h[c-4]=i[0],h[c-3]=i[1],h[c-2]=i[2],h[c-1]=i[3],d?[h,e]:o?(Kx(e,i,h,c,u),[h]):(Kx(e,i,e,0,u),[h,e])):[h,e]}close(e,n,i,o){let c;if(e===void 0)c=VE;else{if(typeof e!="number"||!YE(e))throw new TypeError("First argument must be a valid error code number");if(n===void 0||!n.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(n);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");if(c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof n=="string")c.write(n,2);else if($E(n))c.set(n,2);else throw new TypeError("Second argument must be a string or a Uint8Array")}}let d={[pt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==St?this.enqueue([this.dispatch,c,!1,d,o]):this.sendFrame(t.frame(c,d),o)}ping(e,n,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Hr(e)?(o=e.size,c=!1):(e=Jn(e),o=e.length,c=Jn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[pt]:o,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};Hr(e)?this._state!==St?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==St?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}pong(e,n,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):Hr(e)?(o=e.size,c=!1):(e=Jn(e),o=e.length,c=Jn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[pt]:o,fin:!0,generateMask:this._generateMask,mask:n,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};Hr(e)?this._state!==St?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==St?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}send(e,n,i){let o=this._extensions[Wx.extensionName],c=n.binary?2:1,d=n.compress,u,x;typeof e=="string"?(u=Buffer.byteLength(e),x=!1):Hr(e)?(u=e.size,x=!1):(e=Jn(e),u=e.length,x=Jn.readOnly),this._firstFragment?(this._firstFragment=!1,d&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(d=u>=o._threshold),this._compress=d):(d=!1,c=0),n.fin&&(this._firstFragment=!0);let h={[pt]:u,fin:n.fin,generateMask:this._generateMask,mask:n.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:x,rsv1:d};Hr(e)?this._state!==St?this.enqueue([this.getBlobData,e,this._compress,h,i]):this.getBlobData(e,this._compress,h,i):this._state!==St?this.enqueue([this.dispatch,e,this._compress,h,i]):this.dispatch(e,this._compress,h,i)}getBlobData(e,n,i,o){this._bufferedBytes+=i[pt],this._state=ev,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(Cd,this,u,o);return}this._bufferedBytes-=i[pt];let d=Jn(c);n?this.dispatch(d,n,i,o):(this._state=St,this.sendFrame(t.frame(d,i),o),this.dequeue())}).catch(c=>{process.nextTick(tv,this,c,o)})}dispatch(e,n,i,o){if(!n){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[Wx.extensionName];this._bufferedBytes+=i[pt],this._state=QE,c.compress(e,i.fin,(d,u)=>{if(this._socket.destroyed){let x=new Error("The socket was closed while data was being compressed");Cd(this,x,o);return}this._bufferedBytes-=i[pt],this._state=St,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===St&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][pt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][pt],this._queue.push(e)}sendFrame(e,n){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],n),this._socket.uncork()):this._socket.write(e[0],n)}};$x.exports=Td;function Cd(t,e,n){typeof n=="function"&&n(e);for(let i=0;i<t._queue.length;i++){let o=t._queue[i],c=o[o.length-1];typeof c=="function"&&c(e)}}function tv(t,e,n){Cd(t,e,n),t.onerror(e)}});var nh=de((PP,th)=>{"use strict";var{kForOnEventAttribute:Yi,kListener:Rd}=Zt(),Vx=Symbol("kCode"),Jx=Symbol("kData"),Zx=Symbol("kError"),Yx=Symbol("kMessage"),Xx=Symbol("kReason"),Wr=Symbol("kTarget"),Qx=Symbol("kType"),eh=Symbol("kWasClean"),Xt=class{constructor(e){this[Wr]=null,this[Qx]=e}get target(){return this[Wr]}get type(){return this[Qx]}};Object.defineProperty(Xt.prototype,"target",{enumerable:!0});Object.defineProperty(Xt.prototype,"type",{enumerable:!0});var Yn=class extends Xt{constructor(e,n={}){super(e),this[Vx]=n.code===void 0?0:n.code,this[Xx]=n.reason===void 0?"":n.reason,this[eh]=n.wasClean===void 0?!1:n.wasClean}get code(){return this[Vx]}get reason(){return this[Xx]}get wasClean(){return this[eh]}};Object.defineProperty(Yn.prototype,"code",{enumerable:!0});Object.defineProperty(Yn.prototype,"reason",{enumerable:!0});Object.defineProperty(Yn.prototype,"wasClean",{enumerable:!0});var Kr=class extends Xt{constructor(e,n={}){super(e),this[Zx]=n.error===void 0?null:n.error,this[Yx]=n.message===void 0?"":n.message}get error(){return this[Zx]}get message(){return this[Yx]}};Object.defineProperty(Kr.prototype,"error",{enumerable:!0});Object.defineProperty(Kr.prototype,"message",{enumerable:!0});var Xi=class extends Xt{constructor(e,n={}){super(e),this[Jx]=n.data===void 0?null:n.data}get data(){return this[Jx]}};Object.defineProperty(Xi.prototype,"data",{enumerable:!0});var nv={addEventListener(t,e,n={}){for(let o of this.listeners(t))if(!n[Yi]&&o[Rd]===e&&!o[Yi])return;let i;if(t==="message")i=function(c,d){let u=new Xi("message",{data:d?c:c.toString()});u[Wr]=this,zo(e,this,u)};else if(t==="close")i=function(c,d){let u=new Yn("close",{code:c,reason:d.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Wr]=this,zo(e,this,u)};else if(t==="error")i=function(c){let d=new Kr("error",{error:c,message:c.message});d[Wr]=this,zo(e,this,d)};else if(t==="open")i=function(){let c=new Xt("open");c[Wr]=this,zo(e,this,c)};else return;i[Yi]=!!n[Yi],i[Rd]=e,n.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let n of this.listeners(t))if(n[Rd]===e&&!n[Yi]){this.removeListener(t,n);break}}};th.exports={CloseEvent:Yn,ErrorEvent:Kr,Event:Xt,EventTarget:nv,MessageEvent:Xi};function zo(t,e,n){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,n):t.call(e,n)}});var Uo=de((RP,rh)=>{"use strict";var{tokenChars:Qi}=jr();function Bt(t,e,n){t[e]===void 0?t[e]=[n]:t[e].push(n)}function rv(t){let e=Object.create(null),n=Object.create(null),i=!1,o=!1,c=!1,d,u,x=-1,h=-1,g=-1,w=0;for(;w<t.length;w++)if(h=t.charCodeAt(w),d===void 0)if(g===-1&&Qi[h]===1)x===-1&&(x=w);else if(w!==0&&(h===32||h===9))g===-1&&x!==-1&&(g=w);else if(h===59||h===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w);let _=t.slice(x,g);h===44?(Bt(e,_,n),n=Object.create(null)):d=_,x=g=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);else if(u===void 0)if(g===-1&&Qi[h]===1)x===-1&&(x=w);else if(h===32||h===9)g===-1&&x!==-1&&(g=w);else if(h===59||h===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w),Bt(n,t.slice(x,g),!0),h===44&&(Bt(e,d,n),n=Object.create(null),d=void 0),x=g=-1}else if(h===61&&x!==-1&&g===-1)u=t.slice(x,w),x=g=-1;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(o){if(Qi[h]!==1)throw new SyntaxError(`Unexpected character at index ${w}`);x===-1?x=w:i||(i=!0),o=!1}else if(c)if(Qi[h]===1)x===-1&&(x=w);else if(h===34&&x!==-1)c=!1,g=w;else if(h===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${w}`);else if(h===34&&t.charCodeAt(w-1)===61)c=!0;else if(g===-1&&Qi[h]===1)x===-1&&(x=w);else if(x!==-1&&(h===32||h===9))g===-1&&(g=w);else if(h===59||h===44){if(x===-1)throw new SyntaxError(`Unexpected character at index ${w}`);g===-1&&(g=w);let _=t.slice(x,g);i&&(_=_.replace(/\\/g,""),i=!1),Bt(n,u,_),h===44&&(Bt(e,d,n),n=Object.create(null),d=void 0),u=void 0,x=g=-1}else throw new SyntaxError(`Unexpected character at index ${w}`);if(x===-1||c||h===32||h===9)throw new SyntaxError("Unexpected end of input");g===-1&&(g=w);let v=t.slice(x,g);return d===void 0?Bt(e,v,n):(u===void 0?Bt(n,v,!0):i?Bt(n,u,v.replace(/\\/g,"")):Bt(n,u,v),Bt(e,d,n)),e}function iv(t){return Object.keys(t).map(e=>{let n=t[e];return Array.isArray(n)||(n=[n]),n.map(i=>[e].concat(Object.keys(i).map(o=>{let c=i[o];return Array.isArray(c)||(c=[c]),c.map(d=>d===!0?o:`${o}=${d}`).join("; ")})).join("; ")).join(", ")}).join(", ")}rh.exports={format:iv,parse:rv}});var qo=de((LP,ph)=>{"use strict";var sv=xe("events"),ov=xe("https"),av=xe("http"),oh=xe("net"),cv=xe("tls"),{randomBytes:dv,createHash:lv}=xe("crypto"),{Duplex:DP,Readable:OP}=xe("stream"),{URL:Dd}=xe("url"),Cn=Gr(),uv=kd(),fv=Pd(),{isBlob:xv}=jr(),{BINARY_TYPES:ih,CLOSE_TIMEOUT:hv,EMPTY_BUFFER:Go,GUID:pv,kForOnEventAttribute:Od,kListener:gv,kStatusCode:mv,kWebSocket:We,NOOP:ah}=Zt(),{EventTarget:{addEventListener:wv,removeEventListener:_v}}=nh(),{format:yv,parse:bv}=Uo(),{toBuffer:Ev}=Ji(),ch=Symbol("kAborted"),Ld=[8,13],Qt=["CONNECTING","OPEN","CLOSING","CLOSED"],vv=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,ye=class t extends sv{constructor(e,n,i){super(),this._binaryType=ih[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Go,this._closeTimer=null,this._errorEmitted=!1,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,n===void 0?n=[]:Array.isArray(n)||(typeof n=="object"&&n!==null?(i=n,n=[]):n=[n]),dh(this,e,n,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){ih.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,n,i){let o=new uv({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 fv(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[We]=this,c[We]=this,e[We]=this,o.on("conclude",Av),o.on("drain",kv),o.on("error",Tv),o.on("message",Cv),o.on("ping",Pv),o.on("pong",Rv),c.onerror=Dv,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),n.length>0&&e.unshift(n),e.on("close",fh),e.on("data",Ho),e.on("end",xh),e.on("error",hh),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[Cn.extensionName]&&this._extensions[Cn.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,n){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){dt(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,n,!this._isServer,i=>{i||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),uh(this)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,n,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=n=void 0):typeof n=="function"&&(i=n,n=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Nd(this,e,i);return}n===void 0&&(n=!this._isServer),this._sender.ping(e||Go,n,i)}pong(e,n,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(i=e,e=n=void 0):typeof n=="function"&&(i=n,n=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Nd(this,e,i);return}n===void 0&&(n=!this._isServer),this._sender.pong(e||Go,n,i)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,n,i){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof n=="function"&&(i=n,n={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Nd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...n};this._extensions[Cn.extensionName]||(o.compress=!1),this._sender.send(e||Go,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){dt(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(ye,"CONNECTING",{enumerable:!0,value:Qt.indexOf("CONNECTING")});Object.defineProperty(ye.prototype,"CONNECTING",{enumerable:!0,value:Qt.indexOf("CONNECTING")});Object.defineProperty(ye,"OPEN",{enumerable:!0,value:Qt.indexOf("OPEN")});Object.defineProperty(ye.prototype,"OPEN",{enumerable:!0,value:Qt.indexOf("OPEN")});Object.defineProperty(ye,"CLOSING",{enumerable:!0,value:Qt.indexOf("CLOSING")});Object.defineProperty(ye.prototype,"CLOSING",{enumerable:!0,value:Qt.indexOf("CLOSING")});Object.defineProperty(ye,"CLOSED",{enumerable:!0,value:Qt.indexOf("CLOSED")});Object.defineProperty(ye.prototype,"CLOSED",{enumerable:!0,value:Qt.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(ye.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(ye.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Od])return e[gv];return null},set(e){for(let n of this.listeners(t))if(n[Od]){this.removeListener(t,n);break}typeof e=="function"&&this.addEventListener(t,e,{[Od]:!0})}})});ye.prototype.addEventListener=wv;ye.prototype.removeEventListener=_v;ph.exports=ye;function dh(t,e,n,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:hv,protocolVersion:Ld[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,!Ld.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Ld.join(", ")})`);let c;if(e instanceof Dd)c=e;else try{c=new Dd(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let d=c.protocol==="wss:",u=c.protocol==="ws+unix:",x;if(c.protocol!=="ws:"&&!d&&!u?x=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?x="The URL's pathname is empty":c.hash&&(x="The URL contains a fragment identifier"),x){let I=new SyntaxError(x);if(t._redirects===0)throw I;jo(t,I);return}let h=d?443:80,g=dv(16).toString("base64"),w=d?ov.request:av.request,v=new Set,_;if(o.createConnection=o.createConnection||(d?Iv:Sv),o.defaultPort=o.defaultPort||h,o.port=c.port||h,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":g,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(_=new Cn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=yv({[Cn.extensionName]:_.offer()})),n.length){for(let I of n){if(typeof I!="string"||!vv.test(I)||v.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");v.add(I)}o.headers["Sec-WebSocket-Protocol"]=n.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),u){let I=o.path.split(":");o.socketPath=I[0],o.path=I[1]}let E;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=d,t._originalHostOrSocketPath=u?o.socketPath:c.host;let I=i&&i.headers;if(i={...i,headers:{}},I)for(let[A,T]of Object.entries(I))i.headers[A.toLowerCase()]=T}else if(t.listenerCount("redirect")===0){let I=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!I||t._originalSecure&&!d)&&(delete o.headers.authorization,delete o.headers.cookie,I||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),E=t._req=w(o),t._redirects&&t.emit("redirect",t.url,E)}else E=t._req=w(o);o.timeout&&E.on("timeout",()=>{dt(t,E,"Opening handshake has timed out")}),E.on("error",I=>{E===null||E[ch]||(E=t._req=null,jo(t,I))}),E.on("response",I=>{let A=I.headers.location,T=I.statusCode;if(A&&o.followRedirects&&T>=300&&T<400){if(++t._redirects>o.maxRedirects){dt(t,E,"Maximum redirects exceeded");return}E.abort();let R;try{R=new Dd(A,e)}catch{let C=new SyntaxError(`Invalid URL: ${A}`);jo(t,C);return}dh(t,R,n,i)}else t.emit("unexpected-response",E,I)||dt(t,E,`Unexpected server response: ${I.statusCode}`)}),E.on("upgrade",(I,A,T)=>{if(t.emit("upgrade",I),t.readyState!==ye.CONNECTING)return;E=t._req=null;let R=I.headers.upgrade;if(R===void 0||R.toLowerCase()!=="websocket"){dt(t,A,"Invalid Upgrade header");return}let y=lv("sha1").update(g+pv).digest("base64");if(I.headers["sec-websocket-accept"]!==y){dt(t,A,"Invalid Sec-WebSocket-Accept header");return}let C=I.headers["sec-websocket-protocol"],D;if(C!==void 0?v.size?v.has(C)||(D="Server sent an invalid subprotocol"):D="Server sent a subprotocol but none was requested":v.size&&(D="Server sent no subprotocol"),D){dt(t,A,D);return}C&&(t._protocol=C);let F=I.headers["sec-websocket-extensions"];if(F!==void 0){if(!_){dt(t,A,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let B;try{B=bv(F)}catch{dt(t,A,"Invalid Sec-WebSocket-Extensions header");return}let Y=Object.keys(B);if(Y.length!==1||Y[0]!==Cn.extensionName){dt(t,A,"Server indicated an extension that was not requested");return}try{_.accept(B[Cn.extensionName])}catch{dt(t,A,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[Cn.extensionName]=_}t.setSocket(A,T,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxBufferedChunks:o.maxBufferedChunks,maxFragments:o.maxFragments,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(E,t):E.end()}function jo(t,e){t._readyState=ye.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Sv(t){return t.path=t.socketPath,oh.connect(t)}function Iv(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=oh.isIP(t.host)?"":t.host),cv.connect(t)}function dt(t,e,n){t._readyState=ye.CLOSING;let i=new Error(n);Error.captureStackTrace(i,dt),e.setHeader?(e[ch]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(jo,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Nd(t,e,n){if(e){let i=xv(e)?e.size:Ev(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(n){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${Qt[t.readyState]})`);process.nextTick(n,i)}}function Av(t,e){let n=this[We];n._closeFrameReceived=!0,n._closeMessage=e,n._closeCode=t,n._socket[We]!==void 0&&(n._socket.removeListener("data",Ho),process.nextTick(lh,n._socket),t===1005?n.close():n.close(t,e))}function kv(){let t=this[We];t.isPaused||t._socket.resume()}function Tv(t){let e=this[We];e._socket[We]!==void 0&&(e._socket.removeListener("data",Ho),process.nextTick(lh,e._socket),e.close(t[mv])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function sh(){this[We].emitClose()}function Cv(t,e){this[We].emit("message",t,e)}function Pv(t){let e=this[We];e._autoPong&&e.pong(t,!this._isServer,ah),e.emit("ping",t)}function Rv(t){this[We].emit("pong",t)}function lh(t){t.resume()}function Dv(t){let e=this[We];e.readyState!==ye.CLOSED&&(e.readyState===ye.OPEN&&(e._readyState=ye.CLOSING,uh(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function uh(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function fh(){let t=this[We];if(this.removeListener("close",fh),this.removeListener("data",Ho),this.removeListener("end",xh),t._readyState=ye.CLOSING,!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&this._readableState.length!==0){let e=this.read(this._readableState.length);t._receiver.write(e)}t._receiver.end(),this[We]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",sh),t._receiver.on("finish",sh))}function Ho(t){this[We]._receiver.write(t)||this.pause()}function xh(){let t=this[We];t._readyState=ye.CLOSING,t._receiver.end(),this.end()}function hh(){let t=this[We];this.removeListener("error",hh),this.on("error",ah),t&&(t._readyState=ye.CLOSING,this.destroy())}});var _h=de((MP,wh)=>{"use strict";var NP=qo(),{Duplex:Ov}=xe("stream");function gh(t){t.emit("close")}function Lv(){!this.destroyed&&this._writableState.finished&&this.destroy()}function mh(t){this.removeListener("error",mh),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function Nv(t,e){let n=!0,i=new Ov({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,d){let u=!d&&i._readableState.objectMode?c.toString():c;i.push(u)||t.pause()}),t.once("error",function(c){i.destroyed||(n=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick(gh,i);return}let d=!1;t.once("error",function(x){d=!0,c(x)}),t.once("close",function(){d||c(o),process.nextTick(gh,i)}),n&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,d){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,d)});return}t.send(o,d)},i.on("end",Lv),i.on("error",mh),i}wh.exports=Nv});var Md=de((BP,yh)=>{"use strict";var{tokenChars:Mv}=jr();function Bv(t){let e=new Set,n=-1,i=-1,o=0;for(o;o<t.length;o++){let d=t.charCodeAt(o);if(i===-1&&Mv[d]===1)n===-1&&(n=o);else if(o!==0&&(d===32||d===9))i===-1&&n!==-1&&(i=o);else if(d===44){if(n===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let u=t.slice(n,i);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);e.add(u),n=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(n===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(n,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}yh.exports={parse:Bv}});var kh=de((zP,Ah)=>{"use strict";var Fv=xe("events"),Wo=xe("http"),{Duplex:FP}=xe("stream"),{createHash:zv}=xe("crypto"),bh=Uo(),Xn=Gr(),Uv=Md(),Gv=qo(),{CLOSE_TIMEOUT:jv,GUID:Hv,kWebSocket:qv}=Zt(),Wv=/^[+/0-9A-Za-z]{22}==$/,Eh=0,vh=1,Ih=2,Bd=class extends Fv{constructor(e,n){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxBufferedChunks:1024*1024,maxFragments:128*1024,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:jv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Gv,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=Wo.createServer((i,o)=>{let c=Wo.STATUS_CODES[426];o.writeHead(426,{"Content-Length":c.length,"Content-Type":"text/plain"}),o.end(c)}),this._server.listen(e.port,e.host,e.backlog,n)):e.server&&(this._server=e.server),this._server){let i=this.emit.bind(this,"connection");this._removeListeners=Kv(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(o,c,d)=>{this.handleUpgrade(o,c,d,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Eh}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(es,this);return}if(e&&this.once("close",e),this._state!==vh)if(this._state=vh,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(es,this):process.nextTick(es,this);else{let n=this._server;this._removeListeners(),this._removeListeners=this._server=null,n.close(()=>{es(this)})}}shouldHandle(e){if(this.options.path){let n=e.url.indexOf("?");if((n!==-1?e.url.slice(0,n):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,n,i,o){n.on("error",Sh);let c=e.headers["sec-websocket-key"],d=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){Qn(this,e,n,405,"Invalid HTTP method");return}if(d===void 0||d.toLowerCase()!=="websocket"){Qn(this,e,n,400,"Invalid Upgrade header");return}if(c===void 0||!Wv.test(c)){Qn(this,e,n,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){Qn(this,e,n,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){ts(n,400);return}let x=e.headers["sec-websocket-protocol"],h=new Set;if(x!==void 0)try{h=Uv.parse(x)}catch{Qn(this,e,n,400,"Invalid Sec-WebSocket-Protocol header");return}let g=e.headers["sec-websocket-extensions"],w={};if(this.options.perMessageDeflate&&g!==void 0){let v=new Xn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let _=bh.parse(g);_[Xn.extensionName]&&(v.accept(_[Xn.extensionName]),w[Xn.extensionName]=v)}catch{Qn(this,e,n,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let v={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(v,(_,E,I,A)=>{if(!_)return ts(n,E||401,I,A);this.completeUpgrade(w,c,h,e,n,i,o)});return}if(!this.options.verifyClient(v))return ts(n,401)}this.completeUpgrade(w,c,h,e,n,i,o)}completeUpgrade(e,n,i,o,c,d,u){if(!c.readable||!c.writable)return c.destroy();if(c[qv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Eh)return ts(c,503);let h=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${zv("sha1").update(n+Hv).digest("base64")}`],g=new this.options.WebSocket(null,void 0,this.options);if(i.size){let w=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;w&&(h.push(`Sec-WebSocket-Protocol: ${w}`),g._protocol=w)}if(e[Xn.extensionName]){let w=e[Xn.extensionName].params,v=bh.format({[Xn.extensionName]:[w]});h.push(`Sec-WebSocket-Extensions: ${v}`),g._extensions=e}this.emit("headers",h,o),c.write(h.concat(`\r
|
|
8
|
+
var Dg=Object.create;var Aa=Object.defineProperty;var Pg=Object.getOwnPropertyDescriptor;var Og=Object.getOwnPropertyNames;var Lg=Object.getPrototypeOf,Ng=Object.prototype.hasOwnProperty;var fe=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var rt=(t,e)=>()=>(t&&(e=t(t=0)),e);var ce=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ka=(t,e)=>{for(var r in e)Aa(t,r,{get:e[r],enumerable:!0})},Mg=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Og(e))!Ng.call(t,o)&&o!==r&&Aa(t,o,{get:()=>e[o],enumerable:!(i=Pg(e,o))||i.enumerable});return t};var jt=(t,e,r)=>(r=t!=null?Dg(Lg(t)):{},Mg(e||!t||!t.__esModule?Aa(r,"default",{value:t,enumerable:!0}):r,t));function Ze(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var or=rt(()=>{"use strict"});import{createWriteStream as Bg,mkdirSync as Fg,readdirSync as zg,unlinkSync as Ug}from"node:fs";import{join as vl}from"node:path";function On(t){let e=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())}`}function ar(t,e){return`${t}-${e}.log`}function Ta(t,e){let r=t.match(/^(.+)-(\d{4}-\d{2}-\d{2})\.log$/);return!r||r[1]!==e?null:r[2]??null}function Gg(t,e,r){let i=c=>{let[d,u,h]=c.split("-").map(Number);return Date.UTC(d??0,(u??1)-1,h??1)};return Math.floor((i(e)-i(t))/864e5)>r}function us(t,e,r,i){let o;try{o=zg(t)}catch{return}for(let c of o){let d=Ta(c,e);if(d&&Gg(d,r,i))try{Ug(vl(t,c))}catch{}}}var ni,Ca=rt(()=>{"use strict";ni=class{constructor(e,r,i){this.dir=e;this.prefix=r;this.opts=i;this.clock=i.clock??(()=>On(new Date))}dir;prefix;opts;currentDate;stream;clock;write(e){let r=this.clock();r!==this.currentDate&&this.rotate(r),this.stream?.write(e)}rotate(e){this.stream?.end();try{Fg(this.dir,{recursive:!0});let r=Bg(vl(this.dir,ar(this.prefix,e)),{flags:"a"});r.on("error",i=>process.stderr.write(`[log-sink] stream error: ${String(i)}
|
|
9
|
+
`)),this.stream=r}catch(r){process.stderr.write(`[log-sink] rotate failed: ${String(r)}
|
|
10
|
+
`),this.stream=void 0;return}this.currentDate!==void 0&&us(this.dir,this.prefix,e,this.opts.retentionDays),this.currentDate=e}close(){this.stream?.end(),this.stream=void 0,this.currentDate=void 0}}});import{appendFileSync as Hg,mkdirSync as qg}from"node:fs";import{join as jg}from"node:path";function Il(t){let e=t.retentionDays??$g,r=t.clock??(()=>On(new Date));hs={bridgeSink:new ni(t.bridgeLogsDir,"bridge",{retentionDays:e,clock:r}),agentSinks:new Map,makeAgentSink:o=>new ni(t.agentLogsDir(o),"agent",{retentionDays:e,clock:r})};let i=r();us(t.bridgeLogsDir,"bridge",i,e);for(let o of t.listAgentIds?.()??[])us(t.agentLogsDir(o),"agent",i,e)}function Vg(t,e){let r=t.agentSinks.get(e);return r||(r=t.makeAgentSink(e),t.agentSinks.set(e,r)),r}function Al(t){Ra=t}function kl(t){return cr[Ra]<=cr[t]}function Tl(t,e){let r=cr[t];return r===void 0?!0:r>=cr[e]}function xs(t){Sl={...t}}function Cl(t){let e=(u,h=2)=>String(u).padStart(h,"0"),r=-t.getTimezoneOffset(),i=r>=0?"+":"-",o=Math.abs(r),c=e(Math.floor(o/60)),d=e(o%60);return`${On(t)}T${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}.${e(t.getMilliseconds(),3)}${i}${c}:${d}`}function it(t,e,r,i,o){try{let c=`${JSON.stringify({ts:Cl(new Date),level:e,module:r,msg:i,...o})}
|
|
11
|
+
`;qg(t,{recursive:!0}),Hg(jg(t,ar("bridge",On(new Date))),c)}catch{}}function Jg(t,e){if(t)return t;let r=e?.agentId;return typeof r=="string"&&r.length>0?r:void 0}function fs(t,e,r,i,o){if(cr[t]<cr[Ra])return;let c=`${JSON.stringify({ts:Cl(new Date),level:t,module:e,msg:r,...Sl,...i})}
|
|
12
|
+
`;if(hs){let d=Jg(o,i),u=d?Vg(hs,d):hs.bridgeSink;try{u.write(c)}catch{process.stderr.write(c)}return}t==="error"||t==="warn"?Kg.write(c):Wg.write(c)}function H(t,e){return{debug:(r,i)=>fs("debug",t,r,i,e),info:(r,i)=>fs("info",t,r,i,e),warn:(r,i)=>fs("warn",t,r,i,e),error:(r,i)=>fs("error",t,r,i,e),child:r=>H(`${t}.${r}`,e),forAgent:r=>H(t,r)}}var cr,Ra,Wg,Kg,Sl,$g,hs,ne=rt(()=>{"use strict";or();Ca();cr={debug:10,info:20,warn:30,error:40},Ra=(()=>{let t=process.env.COZE_BRIDGE_LOG_LEVEL;return t==="debug"||t==="info"||t==="warn"||t==="error"?t:"info"})(),Wg=process.stdout,Kg=process.stderr,Sl={},$g=Ze("COZE_BRIDGE_LOG_RETENTION_DAYS",30),hs=null});var T,Ve=rt(()=>{"use strict";T=class extends Error{code;retriable;cause;constructor(e,r,i){super(r),this.name="BridgeError",this.code=e,this.retriable=i?.retriable??!1,i?.cause!==void 0&&(this.cause=i.cause)}}});var Ol={};ka(Ol,{ACP_WRAPPER_NPM_PACKAGES:()=>ps,_resetAcpInstallerForTests:()=>tm,_setBinaryPathCacheForTests:()=>nm,buildAcpSpawn:()=>ii,ensureAcpInstalled:()=>dr,getAcpBinaryPath:()=>gs,pickWhichLine:()=>Oa,probeAcpVersion:()=>em,resolveAcpCommand:()=>Pl});import{readFileSync as Rl}from"node:fs";import{createRequire as Zg}from"node:module";import{dirname as Xg,resolve as Yg}from"node:path";function Oa(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 Qg(t){let e=Dl.resolve(`${t.npmPackage}/package.json`),r=Xg(e),i=JSON.parse(Rl(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 Yg(r,o)}async function dr(t,e){let r=Pa[t];if(!r)throw new T("BRIDGE_INTERNAL",`ensureAcpInstalled called for non-npm framework: ${t}`);let i=ri.get(t);if(i)return i;try{let o=Qg(r);return ri.set(t,o),Da.info("acp wrapper resolved",{framework:t,binary:r.binary,path:o}),o}catch(o){throw Da.warn("acp wrapper \u89E3\u6790\u5931\u8D25 (\u672A\u968F\u5305\u56FA\u5316\u5230 lib/node_modules?)",{framework:t,npmPackage:r.npmPackage,err:String(o)}),new T("AGENT_DEPENDENCY_INSTALL_FAILED",[`ACP wrapper \u672A\u5C31\u7EEA: ${r.npmPackage} (framework=${t})`,"\u8BE5 wrapper \u968F coze-bridge \u4E00\u8D77\u5B89\u88C5 (\u56FA\u5316\u5230 ~/.coze/bridge/lib/node_modules)\u3002","\u8BF7\u91CD\u8DD1 `coze-bridge pair` / `connect` \u89E6\u53D1\u56FA\u5316\u5B89\u88C5; \u82E5\u4ECD\u5931\u8D25, \u68C0\u67E5\u7F51\u7EDC / npm \u7F13\u5B58\u3002"].join(`
|
|
13
|
+
`),{cause:o})}}async function em(t){let e=Pa[t];if(e)try{let r=Dl.resolve(`${e.npmPackage}/package.json`),i=JSON.parse(Rl(r,"utf8"));return typeof i.version=="string"&&i.version.length>0?i.version:void 0}catch(r){Da.warn("acp wrapper probe: \u89E3\u6790 package.json \u5931\u8D25",{framework:t,npmPackage:e.npmPackage,err:String(r)});return}}function gs(t){return ri.get(t)}function Pl(t,e){if(e)return e;let r=gs(t);if(!r)throw new T("BRIDGE_INTERNAL",`${t} ACP wrapper \u8DEF\u5F84\u672A\u89E3\u6790 (ensureAcpInstalled \u672A\u5728\u6784\u9020\u524D\u8DD1\u901A)`);return r}function ii(t,e,r){if(e)return{command:e,args:[...r]};let i=Pl(t);return{command:process.execPath,args:[i,...r]}}function tm(){ri.clear()}function nm(t,e){ri.set(t,e)}var Da,Pa,ps,Dl,ri,dn=rt(()=>{"use strict";Ve();ne();Da=H("agents.acp-installer"),Pa={"claude-code":{npmPackage:"@agentclientprotocol/claude-agent-acp",binary:"claude-agent-acp"},codex:{npmPackage:"@agentclientprotocol/codex-acp",binary:"codex-acp"}},ps=Object.values(Pa).filter(t=>t!==void 0).map(t=>t.npmPackage),Dl=Zg(import.meta.url),ri=new Map});import{chmod as im,mkdir as sm,readFile as om,rename as am,rm as cm,writeFile as dm}from"node:fs/promises";import{dirname as lm}from"node:path";async function lr(t){try{let e=await om(t,"utf8");return JSON.parse(e)}catch(e){if(e.code==="ENOENT")return null;throw e}}async function ln(t,e,r){await sm(lm(t),{recursive:!0});let i=`${t}.tmp-${process.pid}-${Math.random().toString(36).slice(2,10)}`;try{await dm(i,e,{encoding:"utf8",mode:r?.mode}),await am(i,t),r?.mode!==void 0&&await im(t,r.mode)}catch(o){throw await cm(i,{force:!0}).catch(()=>{}),o}}async function ur(t,e,r){await ln(t,`${JSON.stringify(e,null,2)}
|
|
14
|
+
`,r)}var un=rt(()=>{"use strict"});import{promises as Ml,readdirSync as um}from"node:fs";import{homedir as fm}from"node:os";import{sep as hm,join as De,resolve as Bl}from"node:path";function ee(t){let e=t??fm(),r=De(e,".coze"),i=De(r,"bridge"),o=De(i,"lib"),c=De(i,"logs");return{cozeRoot:r,bridgeRoot:i,libDir:o,libEntry:De(o,"index.js"),binDir:De(i,"bin"),pidFile:De(i,"bridge.pid"),portFile:De(i,"bridge.port"),tokenFile:De(i,"bridge.token"),patTokenFile:De(i,"pat-token"),agentEnvFile:De(i,"agent-env.json"),logFile:De(i,"bridge.log"),bridgeLogsDir:c,daemonStdioLog:De(c,"daemon-stdio.log"),installLock:De(i,"install.lock"),configFile:De(i,"config.json"),agentsRoot:De(r,"agents")}}function Xe(t,e=ee()){let r=De(e.agentsRoot,t);return{root:r,config:De(r,"config.json"),workspace:De(r,"workspace"),logs:De(r,"logs")}}function ms(t=ee()){try{return um(t.agentsRoot,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(e=>e.name)}catch{return[]}}async function si(t,e){let r=await Ml.realpath(Bl(t)).catch(()=>null);if(!r)return!1;let i=await Ml.realpath(Bl(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+hm)}var Be=rt(()=>{"use strict"});var _s={};ka(_s,{AGENT_CONFIG_FILE_MODE:()=>ws,enforceAgentConfigMode:()=>gm,loadAgentConfig:()=>Pe,persistAgentSessions:()=>oi,persistAgentSkills:()=>ai,saveAgentConfig:()=>Ge});import{chmod as xm,stat as pm}from"node:fs/promises";function Pe(t,e){return lr(Xe(t,e).config)}function Ge(t,e){return ur(Xe(t.agentId,e).config,t,{mode:ws})}async function gm(t,e){if(process.platform==="win32")return;let r=Xe(t,e).config;try{let i=await pm(r);if(!i.isFile())return;let o=i.mode&511;o!==ws&&(await xm(r,ws),Fl.warn("agent config mode auto-corrected to 0600",{path:r,from:o.toString(8)}))}catch(i){if(i.code==="ENOENT")return;Fl.warn("enforceAgentConfigMode: chmod failed (ignored)",{path:r,err:String(i)})}}async function oi(t,e,r){let i=await Pe(t,r);i&&(i.sessions=Object.fromEntries(e),await Ge(i,r))}async function ai(t,e,r){let i=await Pe(t,r);i&&(i.skills=e,await Ge(i,r))}var Fl,ws,fn=rt(()=>{"use strict";un();ne();Be();Fl=H("agent-config"),ws=384});var Ma=ce((p2,Gl)=>{Gl.exports={LOCHDR:30,LOCSIG:67324752,LOCVER:4,LOCFLG:6,LOCHOW:8,LOCTIM:10,LOCCRC:14,LOCSIZ:18,LOCLEN:22,LOCNAM:26,LOCEXT:28,EXTSIG:134695760,EXTHDR:16,EXTCRC:4,EXTSIZ:8,EXTLEN:12,CENHDR:46,CENSIG:33639248,CENVEM:4,CENVER:6,CENFLG:8,CENHOW:10,CENTIM:12,CENCRC:16,CENSIZ:20,CENLEN:24,CENNAM:28,CENEXT:30,CENCOM:32,CENDSK:34,CENATT:36,CENATX:38,CENOFF:42,ENDHDR:22,ENDSIG:101010256,ENDSUB:8,ENDTOT:10,ENDSIZ:12,ENDOFF:16,ENDCOM:20,END64HDR:20,END64SIG:117853008,END64START:4,END64OFF:8,END64NUMDISKS:16,ZIP64SIG:101075792,ZIP64HDR:56,ZIP64LEAD:12,ZIP64SIZE:4,ZIP64VEM:12,ZIP64VER:14,ZIP64DSK:16,ZIP64DSKDIR:20,ZIP64SUB:24,ZIP64TOT:32,ZIP64SIZB:40,ZIP64OFF:48,ZIP64EXTRA:56,STORED:0,SHRUNK:1,REDUCED1:2,REDUCED2:3,REDUCED3:4,REDUCED4:5,IMPLODED:6,DEFLATED:8,ENHANCED_DEFLATED:9,PKWARE:10,BZIP2:12,LZMA:14,IBM_TERSE:18,IBM_LZ77:19,AES_ENCRYPT:99,FLG_ENC:1,FLG_COMP1:2,FLG_COMP2:4,FLG_DESC:8,FLG_ENH:16,FLG_PATCH:32,FLG_STR:64,FLG_EFS:2048,FLG_MSK:4096,FILE:2,BUFFER:1,NONE:0,EF_ID:0,EF_SIZE:2,ID_ZIP64:1,ID_AVINFO:7,ID_PFS:8,ID_OS2:9,ID_NTFS:10,ID_OPENVMS:12,ID_UNIX:13,ID_FORK:14,ID_PATCH:15,ID_X509_PKCS7:20,ID_X509_CERTID_F:21,ID_X509_CERTID_C:22,ID_STRONGENC:23,ID_RECORD_MGT:24,ID_X509_PKCS7_RL:25,ID_IBM1:101,ID_IBM2:102,ID_POSZIP:18064,EF_ZIP64_OR_32:4294967295,EF_ZIP64_OR_16:65535,EF_ZIP64_SUNCOMP:0,EF_ZIP64_SCOMP:8,EF_ZIP64_RHO:16,EF_ZIP64_DSN:24}});var bs=ce(ql=>{var Hl={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 Em(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(Hl))ql[t]=Em(Hl[t])});var Vl=ce((m2,$l)=>{var vm=fe("fs"),Fe=fe("path"),jl=Ma(),Sm=bs(),Im=typeof process=="object"&&process.platform==="win32",Wl=t=>typeof t=="object"&&t!==null,Kl=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 Ae(t){this.sep=Fe.sep,this.fs=vm,Wl(t)&&Wl(t.fs)&&typeof t.fs.statSync=="function"&&(this.fs=t.fs)}$l.exports=Ae;Ae.prototype.makeDir=function(t){let e=this;function r(i){let o=i.split(e.sep)[0];i.split(e.sep).forEach(function(c){if(!(!c||c.substr(-1,1)===":")){o+=e.sep+c;var d;try{d=e.fs.statSync(o)}catch(u){if(u.message&&u.message.startsWith("ENOENT"))e.fs.mkdirSync(o);else throw u}if(d&&d.isFile())throw Sm.FILE_IN_THE_WAY(`"${o}"`)}})}r(t)};Ae.prototype.writeFileTo=function(t,e,r,i){let o=this;if(o.fs.existsSync(t)){if(!r)return!1;var c=o.fs.statSync(t);if(c.isDirectory())return!1}var d=Fe.dirname(t);o.fs.existsSync(d)||o.makeDir(d);var u;try{u=o.fs.openSync(t,"w",438)}catch{o.fs.chmodSync(t,438),u=o.fs.openSync(t,"w",438)}if(u)try{o.fs.writeSync(u,e,0,e.length,0)}finally{o.fs.closeSync(u)}return o.fs.chmodSync(t,i||438),!0};Ae.prototype.writeFileToAsync=function(t,e,r,i,o){typeof i=="function"&&(o=i,i=void 0);let c=this;c.fs.exists(t,function(d){if(d&&!r)return o(!1);c.fs.stat(t,function(u,h){if(d&&h.isDirectory())return o(!1);var x=Fe.dirname(t);c.fs.exists(x,function(m){m||c.makeDir(x),c.fs.open(t,"w",438,function(_,S){_?c.fs.chmod(t,438,function(){c.fs.open(t,"w",438,function(y,v){c.fs.write(v,e,0,e.length,0,function(){c.fs.close(v,function(){c.fs.chmod(t,i||438,function(){o(!0)})})})})}):S?c.fs.write(S,e,0,e.length,0,function(){c.fs.close(S,function(){c.fs.chmod(t,i||438,function(){o(!0)})})}):c.fs.chmod(t,i||438,function(){o(!0)})})})})})};Ae.prototype.findFiles=function(t){let e=this;function r(i,o,c){typeof o=="boolean"&&(c=o,o=void 0);let d=[];return e.fs.readdirSync(i).forEach(function(u){let h=Fe.join(i,u),x=e.fs.statSync(h);(!o||o.test(h))&&d.push(Fe.normalize(h)+(x.isDirectory()?e.sep:"")),x.isDirectory()&&c&&(d=d.concat(r(h,o,c)))}),d}return r(t,void 0,!0)};Ae.prototype.findFilesAsync=function(t,e){let r=this,i=[];r.fs.readdir(t,function(o,c){if(o)return e(o);let d=c.length;if(!d)return e(null,i);c.forEach(function(u){u=Fe.join(t,u),r.fs.stat(u,function(h,x){if(h)return e(h);x&&(i.push(Fe.normalize(u)+(x.isDirectory()?r.sep:"")),x.isDirectory()?r.findFilesAsync(u,function(m,_){if(m)return e(m);i=i.concat(_),--d||e(null,i)}):--d||e(null,i))})})})};Ae.prototype.getAttributes=function(){};Ae.prototype.setAttributes=function(){};Ae.crc32update=function(t,e){return Kl[(t^e)&255]^t>>>8};Ae.crc32=function(t){typeof t=="string"&&(t=Buffer.from(t,"utf8"));let e=t.length,r=-1;for(let i=0;i<e;)r=Ae.crc32update(r,t[i++]);return~r>>>0};Ae.methodToString=function(t){switch(t){case jl.STORED:return"STORED ("+t+")";case jl.DEFLATED:return"DEFLATED ("+t+")";default:return"UNSUPPORTED ("+t+")"}};Ae.canonical=function(t){if(!t)return"";let e=Fe.posix.normalize("/"+t.split("\\").join("/"));return Fe.join(".",e)};Ae.zipnamefix=function(t){if(!t)return"";let e=Fe.posix.normalize("/"+t.split("\\").join("/"));return Fe.posix.join(".",e)};Ae.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]};Ae.sanitize=function(t,e){t=Fe.resolve(Fe.normalize(t));for(var r=e.split("/"),i=0,o=r.length;i<o;i++){var c=Fe.normalize(Fe.join(t,r.slice(i,o).join(Fe.sep)));if(c.indexOf(t)===0)return c}return Fe.normalize(Fe.join(t,Fe.basename(e)))};Ae.toBuffer=function(e,r){return Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e):typeof e=="string"?r(e):Buffer.alloc(0)};Ae.readBigUInt64LE=function(t,e){let r=t.readUInt32LE(e);return t.readUInt32LE(e+4)*4294967296+r};Ae.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)};Ae.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};Ae.isWin=Im;Ae.crcTable=Kl});var Zl=ce((w2,Jl)=>{var Am=fe("path");Jl.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=Am.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 Yl=ce((_2,Xl)=>{Xl.exports={efs:!0,encode:t=>Buffer.from(t,"utf8"),decode:t=>t.toString("utf8")}});var xr=ce((y2,hr)=>{hr.exports=Vl();hr.exports.Constants=Ma();hr.exports.Errors=bs();hr.exports.FileAttr=Zl();hr.exports.decoder=Yl()});var eu=ce((b2,Ql)=>{var hn=xr(),z=hn.Constants;Ql.exports=function(){var t=20,e=10,r=0,i=0,o=0,c=0,d=0,u=0,h=0,x=0,m=0,_=0,S=0,y=0,v=0;t|=hn.isWin?2560:768,r|=z.FLG_EFS;let I={extraLen:0},A=b=>Math.max(0,b)>>>0,C=b=>Math.max(0,b)&65535,P=b=>Math.max(0,b)&255;return o=hn.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 hn.fromDOS2Date(this.timeval)},set time(b){b=new Date(b),this.timeval=hn.fromDate2DOS(b)},get timeval(){return o},set timeval(b){o=A(b)},get timeHighByte(){return P(o>>>8)},get crc(){return c},set crc(b){c=A(b)},get compressedSize(){return d},set compressedSize(b){d=A(b)},get size(){return u},set size(b){u=A(b)},get fileNameLength(){return h},set fileNameLength(b){h=b},get extraLength(){return x},set extraLength(b){x=b},get extraLocalLength(){return I.extraLen},set extraLocalLength(b){I.extraLen=b},get commentLength(){return m},set commentLength(b){m=b},get diskNumStart(){return _},set diskNumStart(b){_=A(b)},get inAttr(){return S},set inAttr(b){S=A(b)},get attr(){return y},set attr(b){y=A(b)},get fileAttr(){return(y||0)>>16&4095},get offset(){return v},set offset(b){v=A(b)},get encrypted(){return(r&z.FLG_ENC)===z.FLG_ENC},get centralHeaderSize(){return z.CENHDR+h+x+m},get realDataOffset(){return v+z.LOCHDR+I.fnameLen+I.extraLen},get localHeader(){return I},loadLocalHeaderFromBinary:function(b){var R=b.slice(v,v+z.LOCHDR);if(R.readUInt32LE(0)!==z.LOCSIG)throw hn.Errors.INVALID_LOC();I.version=R.readUInt16LE(z.LOCVER),I.flags=R.readUInt16LE(z.LOCFLG),I.flags_desc=(I.flags&z.FLG_DESC)>0,I.method=R.readUInt16LE(z.LOCHOW),I.time=R.readUInt32LE(z.LOCTIM),I.crc=R.readUInt32LE(z.LOCCRC),I.compressedSize=R.readUInt32LE(z.LOCSIZ),I.size=R.readUInt32LE(z.LOCLEN),I.fnameLen=R.readUInt16LE(z.LOCNAM),I.extraLen=R.readUInt16LE(z.LOCEXT);let O=v+z.LOCHDR+I.fnameLen,M=O+I.extraLen;return b.slice(O,M)},loadFromBinary:function(b){if(b.length!==z.CENHDR||b.readUInt32LE(0)!==z.CENSIG)throw hn.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),d=b.readUInt32LE(z.CENSIZ),u=b.readUInt32LE(z.CENLEN),h=b.readUInt16LE(z.CENNAM),x=b.readUInt16LE(z.CENEXT),m=b.readUInt16LE(z.CENCOM),_=b.readUInt16LE(z.CENDSK),S=b.readUInt16LE(z.CENATT),y=b.readUInt32LE(z.CENATX),v=b.readUInt32LE(z.CENOFF)},localHeaderToBinary:function(){var b=Buffer.alloc(z.LOCHDR);return b.writeUInt32LE(z.LOCSIG,0),b.writeUInt16LE(e,z.LOCVER),b.writeUInt16LE(r,z.LOCFLG),b.writeUInt16LE(i,z.LOCHOW),b.writeUInt32LE(o,z.LOCTIM),b.writeUInt32LE(c,z.LOCCRC),b.writeUInt32LE(d,z.LOCSIZ),b.writeUInt32LE(u,z.LOCLEN),b.writeUInt16LE(h,z.LOCNAM),b.writeUInt16LE(I.extraLen,z.LOCEXT),b},centralHeaderToBinary:function(){var b=Buffer.alloc(z.CENHDR+h+x+m);return b.writeUInt32LE(z.CENSIG,0),b.writeUInt16LE(t,z.CENVEM),b.writeUInt16LE(e,z.CENVER),b.writeUInt16LE(r,z.CENFLG),b.writeUInt16LE(i,z.CENHOW),b.writeUInt32LE(o,z.CENTIM),b.writeUInt32LE(c,z.CENCRC),b.writeUInt32LE(d,z.CENSIZ),b.writeUInt32LE(u,z.CENLEN),b.writeUInt16LE(h,z.CENNAM),b.writeUInt16LE(x,z.CENEXT),b.writeUInt16LE(m,z.CENCOM),b.writeUInt16LE(_,z.CENDSK),b.writeUInt16LE(S,z.CENATT),b.writeUInt32LE(y,z.CENATX),b.writeUInt32LE(v,z.CENOFF),b},toJSON:function(){let b=function(R){return R+" bytes"};return{made:t,version:e,flags:r,method:hn.methodToString(i),time:this.time,crc:"0x"+c.toString(16).toUpperCase(),compressedSize:b(d),size:b(u),fileNameLength:b(h),extraLength:b(x),commentLength:b(m),diskNumStart:_,inAttr:S,attr:y,offset:v,centralHeaderSize:b(z.CENHDR+h+x+m)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var nu=ce((E2,tu)=>{var pr=xr(),Ee=pr.Constants;tu.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 Ee.ENDHDR+o},loadFromBinary:function(c){if((c.length!==Ee.ENDHDR||c.readUInt32LE(0)!==Ee.ENDSIG)&&(c.length<Ee.ZIP64HDR||c.readUInt32LE(0)!==Ee.ZIP64SIG))throw pr.Errors.INVALID_END();c.readUInt32LE(0)===Ee.ENDSIG?(t=c.readUInt16LE(Ee.ENDSUB),e=c.readUInt16LE(Ee.ENDTOT),r=c.readUInt32LE(Ee.ENDSIZ),i=c.readUInt32LE(Ee.ENDOFF),o=c.readUInt16LE(Ee.ENDCOM)):(t=pr.readBigUInt64LE(c,Ee.ZIP64SUB),e=pr.readBigUInt64LE(c,Ee.ZIP64TOT),r=pr.readBigUInt64LE(c,Ee.ZIP64SIZE),i=pr.readBigUInt64LE(c,Ee.ZIP64OFF),o=0)},toBinary:function(){var c=Buffer.alloc(Ee.ENDHDR+o);return c.writeUInt32LE(Ee.ENDSIG,0),c.writeUInt32LE(0,4),c.writeUInt16LE(t,Ee.ENDSUB),c.writeUInt16LE(e,Ee.ENDTOT),c.writeUInt32LE(r,Ee.ENDSIZ),c.writeUInt32LE(i,Ee.ENDOFF),c.writeUInt16LE(o,Ee.ENDCOM),c.fill(" ",Ee.ENDHDR),c},toJSON:function(){let c=function(d,u){let h=d.toString(16).toUpperCase();for(;h.length<u;)h="0"+h;return"0x"+h};return{diskEntries:t,totalEntries:e,size:r+" bytes",offset:c(i,4),commentLength:o}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var Fa=ce(Ba=>{Ba.EntryHeader=eu();Ba.MainHeader=nu()});var iu=ce((S2,ru)=>{ru.exports=function(t){var e=fe("zlib"),r={chunkSize:(parseInt(t.length/1024)+1)*1024};return{deflate:function(){return e.deflateRawSync(t,r)},deflateAsync:function(i){var o=e.createDeflateRaw(r),c=[],d=0;o.on("data",function(u){c.push(u),d+=u.length}),o.on("end",function(){var u=Buffer.alloc(d),h=0;u.fill(0);for(var x=0;x<c.length;x++){var m=c[x];m.copy(u,h),h+=m.length}i&&i(u)}),o.end(t)}}}});var ou=ce((I2,su)=>{var km=+(process.versions?process.versions.node:"").split(".")[0]||0;su.exports=function(t,e){var r=fe("zlib");let i=km>=15&&e>0?{maxOutputLength:e}:{};return{inflate:function(){return r.inflateRawSync(t,i)},inflateAsync:function(o){var c=r.createInflateRaw(i),d=[],u=0;c.on("data",function(h){d.push(h),u+=h.length}),c.on("end",function(){var h=Buffer.alloc(u),x=0;h.fill(0);for(var m=0;m<d.length;m++){var _=d[m];_.copy(h,x),x+=_.length}o&&o(h)}),c.end(t)}}}});var uu=ce((A2,lu)=>{"use strict";var{randomFillSync:au}=fe("crypto"),Tm=bs(),Cm=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}),du=(t,e)=>Math.imul(t,e)>>>0,cu=(t,e)=>Cm[(t^e)&255]^t>>>8,ci=()=>typeof au=="function"?au(Buffer.alloc(12)):ci.node();ci.node=()=>{let t=Buffer.alloc(12),e=t.length;for(let r=0;r<e;r++)t[r]=Math.random()*256&255;return t};var Es={genSalt:ci};function vs(t){let e=Buffer.isBuffer(t)?t:Buffer.from(t);this.keys=new Uint32Array([305419896,591751049,878082192]);for(let r=0;r<e.length;r++)this.updateKeys(e[r])}vs.prototype.updateKeys=function(t){let e=this.keys;return e[0]=cu(e[0],t),e[1]+=e[0]&255,e[1]=du(e[1],134775813)+1,e[2]=cu(e[2],e[1]>>>24),t};vs.prototype.next=function(){let t=(this.keys[2]|2)>>>0;return du(t,t^1)>>8&255};function Rm(t){let e=new vs(t);return function(r){let i=Buffer.alloc(r.length),o=0;for(let c of r)i[o++]=e.updateKeys(c^e.next());return i}}function Dm(t){let e=new vs(t);return function(r,i,o=0){i||(i=Buffer.alloc(r.length));for(let c of r){let d=e.next();i[o++]=c^d,e.updateKeys(c)}return i}}function Pm(t,e,r){if(!t||!Buffer.isBuffer(t)||t.length<12)return Buffer.alloc(0);let i=Rm(r),o=i(t.slice(0,12)),c=(e.flags&8)===8?e.timeHighByte:e.crc>>>24;if(o[11]!==c)throw Tm.WRONG_PASSWORD();return i(t.slice(12))}function Om(t){Buffer.isBuffer(t)&&t.length>=12?Es.genSalt=function(){return t.slice(0,12)}:t==="node"?Es.genSalt=ci.node:Es.genSalt=ci}function Lm(t,e,r,i=!1){t==null&&(t=Buffer.alloc(0)),Buffer.isBuffer(t)||(t=Buffer.from(t.toString()));let o=Dm(r),c=Es.genSalt();c[11]=e.crc>>>24&255,i&&(c[10]=e.crc>>>16&255);let d=Buffer.alloc(t.length+12);return o(c,d),o(t,d,12)}lu.exports={decrypt:Pm,encrypt:Lm,_salter:Om}});var fu=ce(Ss=>{Ss.Deflater=iu();Ss.Inflater=ou();Ss.ZipCrypto=uu()});var Ua=ce((T2,hu)=>{var de=xr(),Nm=Fa(),ke=de.Constants,za=fu();hu.exports=function(t,e){var r=new Nm.EntryHeader,i=Buffer.alloc(0),o=Buffer.alloc(0),c=!1,d=null,u=Buffer.alloc(0),h=Buffer.alloc(0),x=!0;let m=t,_=typeof m.decoder=="object"?m.decoder:de.decoder;x=_.hasOwnProperty("efs")?_.efs:!1;function S(){return!e||!(e instanceof Uint8Array)?Buffer.alloc(0):(h=r.loadLocalHeaderFromBinary(e),e.slice(r.realDataOffset,r.realDataOffset+r.compressedSize))}function y(b){if(!r.flags_desc&&!r.localHeader.flags_desc){if(de.crc32(b)!==r.localHeader.crc)return!1}else{let R={},O=r.realDataOffset+r.compressedSize;if(e.readUInt32LE(O)==ke.LOCSIG||e.readUInt32LE(O)==ke.CENSIG)throw de.Errors.DESCRIPTOR_NOT_EXIST();if(e.readUInt32LE(O)==ke.EXTSIG)R.crc=e.readUInt32LE(O+ke.EXTCRC),R.compressedSize=e.readUInt32LE(O+ke.EXTSIZ),R.size=e.readUInt32LE(O+ke.EXTLEN);else if(e.readUInt16LE(O+12)===19280)R.crc=e.readUInt32LE(O+ke.EXTCRC-4),R.compressedSize=e.readUInt32LE(O+ke.EXTSIZ-4),R.size=e.readUInt32LE(O+ke.EXTLEN-4);else throw de.Errors.DESCRIPTOR_UNKNOWN();if(R.compressedSize!==r.compressedSize||R.size!==r.size||R.crc!==r.crc)throw de.Errors.DESCRIPTOR_FAULTY();if(de.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),de.Errors.DIRECTORY_CONTENT_ERROR()),Buffer.alloc(0);var M=S();if(M.length===0)return b&&R&&R(M),M;if(r.encrypted){if(typeof O!="string"&&!Buffer.isBuffer(O))throw de.Errors.INVALID_PASS_PARAM();M=za.ZipCrypto.decrypt(M,r,O)}var N=Buffer.alloc(r.size);switch(r.method){case de.Constants.STORED:if(M.copy(N),y(N))return b&&R&&R(N),N;throw b&&R&&R(N,de.Errors.BAD_CRC()),de.Errors.BAD_CRC();case de.Constants.DEFLATED:var J=new za.Inflater(M,r.size);if(b)J.inflateAsync(function(V){V.copy(V,0),R&&(y(V)?R(V):R(V,de.Errors.BAD_CRC()))});else{if(J.inflate(N).copy(N,0),!y(N))throw de.Errors.BAD_CRC(`"${_.decode(i)}"`);return N}break;default:throw b&&R&&R(Buffer.alloc(0),de.Errors.UNKNOWN_METHOD()),de.Errors.UNKNOWN_METHOD()}}function I(b,R){if((!d||!d.length)&&Buffer.isBuffer(e))return b&&R&&R(S()),S();if(d.length&&!c){var O;switch(r.method){case de.Constants.STORED:return r.compressedSize=r.size,O=Buffer.alloc(d.length),d.copy(O),b&&R&&R(O),O;default:case de.Constants.DEFLATED:var M=new za.Deflater(d);if(b)M.deflateAsync(function(J){O=Buffer.alloc(J.length),r.compressedSize=J.length,J.copy(O),R&&R(O)});else{var N=M.deflate();return r.compressedSize=N.length,N}M=null;break}}else if(b&&R)R(Buffer.alloc(0));else return Buffer.alloc(0)}function A(b,R){return de.readBigUInt64LE(b,R)}function C(b){try{for(var R=0,O,M,N;R+4<b.length;)O=b.readUInt16LE(R),R+=2,M=b.readUInt16LE(R),R+=2,N=b.slice(R,R+M),R+=M,ke.ID_ZIP64===O&&P(N)}catch{throw de.Errors.EXTRA_FIELD_PARSE_ERROR()}}function P(b){var R,O,M,N;b.length>=ke.EF_ZIP64_SCOMP&&(R=A(b,ke.EF_ZIP64_SUNCOMP),r.size===ke.EF_ZIP64_OR_32&&(r.size=R)),b.length>=ke.EF_ZIP64_RHO&&(O=A(b,ke.EF_ZIP64_SCOMP),r.compressedSize===ke.EF_ZIP64_OR_32&&(r.compressedSize=O)),b.length>=ke.EF_ZIP64_DSN&&(M=A(b,ke.EF_ZIP64_RHO),r.offset===ke.EF_ZIP64_OR_32&&(r.offset=M)),b.length>=ke.EF_ZIP64_DSN+4&&(N=b.readUInt32LE(ke.EF_ZIP64_DSN),r.diskNumStart===ke.EF_ZIP64_OR_16&&(r.diskNumStart=N))}return{get entryName(){return _.decode(i)},get rawEntryName(){return i},set entryName(b){i=de.toBuffer(b,_.encode);var R=i[i.length-1];c=R===47||R===92,r.fileNameLength=i.length},get efs(){return typeof x=="function"?x(this.entryName):x},get extra(){return u},set extra(b){u=b,r.extraLength=b.length,C(b)},get comment(){return _.decode(o)},set comment(b){if(o=de.toBuffer(b,_.encode),r.commentLength=o.length,o.length>65535)throw de.Errors.COMMENT_TOO_LONG()},get name(){var b=_.decode(i);return c?b.substr(b.length-1).split("/").pop():b.split("/").pop()},get isDirectory(){return c},getCompressedData:function(){return I(!1,null)},getCompressedDataAsync:function(b){I(!0,b)},setData:function(b){d=de.toBuffer(b,de.decoder.encode),!c&&d.length?(r.size=d.length,r.method=de.Constants.DEFLATED,r.crc=de.crc32(b),r.changed=!0):r.method=de.Constants.STORED},getData:function(b){return r.changed?d:v(!1,null,b)},getDataAsync:function(b,R){r.changed?b(d):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=de.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=h.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,h.copy(O,b),b+=h.length,O},toJSON:function(){let b=function(R){return"<"+(R&&R.length+" bytes buffer"||"null")+">"};return{entryName:this.entryName,name:this.name,comment:this.comment,isDirectory:this.isDirectory,header:r.toJSON(),compressedData:b(e),data:b(d)}},toString:function(){return JSON.stringify(this.toJSON(),null," ")}}}});var gu=ce((C2,pu)=>{var xu=Ua(),Mm=Fa(),Je=xr();pu.exports=function(t,e){var r=[],i={},o=Buffer.alloc(0),c=new Mm.MainHeader,d=!1,u=null;let h=new Set,x=e,{noSort:m,decoder:_}=x;t?v(x.readEntries):d=!0;function S(){let A=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("/")+"/";A.add(R)}}for(let C of A)if(!(C in i)){let P=new xu(x);P.entryName=C,P.attr=16,P.temporary=!0,r.push(P),i[P.entryName]=P,h.add(P)}}function y(){if(d=!0,i={},c.diskEntries>(t.length-c.offset)/Je.Constants.CENHDR)throw Je.Errors.DISK_ENTRY_TOO_LARGE();r=new Array(c.diskEntries);for(var A=c.offset,C=0;C<r.length;C++){var P=A,b=new xu(x,t);b.header=t.slice(P,P+=Je.Constants.CENHDR),b.entryName=t.slice(P,P+=b.header.fileNameLength),b.header.extraLength&&(b.extra=t.slice(P,P+=b.header.extraLength)),b.header.commentLength&&(b.comment=t.slice(P,P+b.header.commentLength)),A+=b.header.centralHeaderSize,r[C]=b,i[b.entryName]=b}h.clear(),S()}function v(A){var C=t.length-Je.Constants.ENDHDR,P=Math.max(0,C-65535),b=P,R=t.length,O=-1,M=0;for(typeof x.trailingSpace=="boolean"&&x.trailingSpace&&(P=0),C;C>=b;C--)if(t[C]===80){if(t.readUInt32LE(C)===Je.Constants.ENDSIG){O=C,M=C,R=C+Je.Constants.ENDHDR,b=C-Je.Constants.END64HDR;continue}if(t.readUInt32LE(C)===Je.Constants.END64SIG){b=P;continue}if(t.readUInt32LE(C)===Je.Constants.ZIP64SIG){O=C,R=C+Je.readBigUInt64LE(t,C+Je.Constants.ZIP64SIZE)+Je.Constants.ZIP64LEAD;break}}if(O==-1)throw Je.Errors.INVALID_FORMAT();c.loadFromBinary(t.slice(O,R)),c.commentLength&&(o=t.slice(M+Je.Constants.ENDHDR)),A&&y()}function I(){r.length>1&&!m&&r.sort((A,C)=>A.entryName.toLowerCase().localeCompare(C.entryName.toLowerCase()))}return{get entries(){return d||y(),r.filter(A=>!h.has(A))},get comment(){return _.decode(o)},set comment(A){o=Je.toBuffer(A,_.encode),c.commentLength=o.length},getEntryCount:function(){return d?r.length:c.diskEntries},forEach:function(A){this.entries.forEach(A)},getEntry:function(A){return d||y(),i[A]||null},setEntry:function(A){d||y(),r.push(A),i[A.entryName]=A,c.totalEntries=r.length},deleteFile:function(A,C=!0){d||y();let P=i[A];this.getEntryChildren(P,C).map(R=>R.entryName).forEach(this.deleteEntry)},deleteEntry:function(A){d||y();let C=i[A],P=r.indexOf(C);P>=0&&(r.splice(P,1),delete i[A],c.totalEntries=r.length)},getEntryChildren:function(A,C=!0){if(d||y(),typeof A=="object")if(A.isDirectory&&C){let P=[],b=A.entryName;for(let R of r)R.entryName.startsWith(b)&&P.push(R);return P}else return[A];return[]},getChildCount:function(A){if(A&&A.isDirectory){let C=this.getEntryChildren(A);return C.includes(A)?C.length-1:C.length}return 0},compressToBuffer:function(){d||y(),I();let A=[],C=[],P=0,b=0;c.size=0,c.offset=0;let R=0;for(let N of this.entries){let J=N.getCompressedData();N.header.offset=b;let V=N.packLocalHeader(),re=V.length+J.length;b+=re,A.push(V),A.push(J);let Y=N.packCentralHeader();C.push(Y),c.size+=Y.length,P+=re+Y.length,R++}P+=c.mainHeaderSize,c.offset=b,c.totalEntries=R,b=0;let O=Buffer.alloc(P);for(let N of A)N.copy(O,b),b+=N.length;for(let N of C)N.copy(O,b),b+=N.length;let M=c.toBinary();return o&&o.copy(M,Je.Constants.ENDHDR),M.copy(O,b),t=O,d=!1,O},toAsyncBuffer:function(A,C,P,b){try{d||y(),I();let R=[],O=[],M=0,N=0,J=0;c.size=0,c.offset=0;let V=function(re){if(re.length>0){let Y=re.shift(),se=Y.entryName+Y.extra.toString();P&&P(se),Y.getCompressedDataAsync(function(ae){b&&b(se),Y.header.offset=N;let D=Y.packLocalHeader(),U=D.length+ae.length;N+=U,R.push(D),R.push(ae);let W=Y.packCentralHeader();O.push(W),c.size+=W.length,M+=U+W.length,J++,V(re)})}else{M+=c.mainHeaderSize,c.offset=N,c.totalEntries=J,N=0;let Y=Buffer.alloc(M);R.forEach(function(ae){ae.copy(Y,N),N+=ae.length}),O.forEach(function(ae){ae.copy(Y,N),N+=ae.length});let se=c.toBinary();o&&o.copy(se,Je.Constants.ENDHDR),se.copy(Y,N),t=Y,d=!1,A(Y)}};V(Array.from(this.entries))}catch(R){C(R)}}}}});var _u=ce((R2,wu)=>{var Se=xr(),ve=fe("path"),Bm=Ua(),Fm=gu(),Ln=(...t)=>Se.findLast(t,e=>typeof e=="boolean"),mu=(...t)=>Se.findLast(t,e=>typeof e=="string"),zm=(...t)=>Se.findLast(t,e=>typeof e=="function"),Um={noSort:!1,readEntries:!1,method:Se.Constants.NONE,fs:null};wu.exports=function(t,e){let r=null,i=Object.assign(Object.create(null),Um);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=Se.Constants.BUFFER,t=void 0)),Object.assign(i,e);let o=new Se(i);if((typeof i.decoder!="object"||typeof i.decoder.encode!="function"||typeof i.decoder.decode!="function")&&(i.decoder=Se.decoder),t&&typeof t=="string")if(o.fs.existsSync(t))i.method=Se.Constants.FILE,i.filename=t,r=o.fs.readFileSync(t);else throw Se.Errors.INVALID_FILENAME();let c=new Fm(r,i),{canonical:d,sanitize:u,zipnamefix:h}=Se;function x(y){if(y&&c){var v;if(typeof y=="string"&&(v=c.getEntry(ve.posix.normalize(y))),typeof y=="object"&&typeof y.entryName<"u"&&typeof y.header<"u"&&(v=c.getEntry(y.entryName)),v)return v}return null}function m(y){let{join:v,normalize:I,sep:A}=ve.posix;return v(ve.isAbsolute(y)?"/":".",I(A+y.split("\\").join(A)+A))}function _(y){return y instanceof RegExp?(function(v){return function(I){return v.test(I)}})(y):typeof y!="function"?()=>!0:y}let S=(y,v)=>{let I=v.slice(-1);return I=I===o.sep?o.sep:"",ve.relative(y,v)+I};return{readFile:function(y,v){var I=x(y);return I&&I.getData(v)||null},childCount:function(y){let v=x(y);if(v)return c.getChildCount(v)},readFileAsync:function(y,v){var I=x(y);I?I.getDataAsync(v):v(null,"getEntry failed for:"+y)},readAsText:function(y,v){var I=x(y);if(I){var A=I.getData();if(A&&A.length)return A.toString(v||"utf8")}return""},readAsTextAsync:function(y,v,I){var A=x(y);A?A.getDataAsync(function(C,P){if(P){v(C,P);return}C&&C.length?v(C.toString(I||"utf8")):v("")}):v("")},deleteFile:function(y,v=!0){var I=x(y);I&&c.deleteFile(I.entryName,v)},deleteEntry:function(y){var v=x(y);v&&c.deleteEntry(v.entryName)},addZipComment:function(y){c.comment=y},getZipComment:function(){return c.comment||""},addZipEntryComment:function(y,v){var I=x(y);I&&(I.comment=v)},getZipEntryComment:function(y){var v=x(y);return v&&v.comment||""},updateFile:function(y,v){var I=x(y);I&&I.setData(v)},addLocalFile:function(y,v,I,A){if(o.fs.existsSync(y)){v=v?m(v):"";let C=ve.win32.basename(ve.win32.normalize(y));v+=I||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,A,P)}else throw Se.Errors.FILE_NOT_FOUND(y)},addLocalFileAsync:function(y,v){y=typeof y=="object"?y:{localPath:y};let I=ve.resolve(y.localPath),{comment:A}=y,{zipPath:C,zipName:P}=y,b=this;o.fs.stat(I,function(R,O){if(R)return v(R,!1);C=C?m(C):"";let M=ve.win32.basename(ve.win32.normalize(I));if(C+=P||M,O.isFile())o.fs.readFile(I,function(N,J){return N?v(N,!1):(b.addFile(C,J,A,O),setImmediate(v,void 0,!0))});else if(O.isDirectory())return C+=o.sep,b.addFile(C,Buffer.alloc(0),A,O),setImmediate(v,void 0,!0)})},addLocalFolder:function(y,v,I){if(I=_(I),v=v?m(v):"",y=ve.normalize(y),o.fs.existsSync(y)){let A=o.findFiles(y),C=this;if(A.length)for(let P of A){let b=ve.join(v,S(y,P));I(b)&&C.addLocalFile(P,ve.dirname(b))}}else throw Se.Errors.FILE_NOT_FOUND(y)},addLocalFolderAsync:function(y,v,I,A){A=_(A),I=I?m(I):"",y=ve.normalize(y);var C=this;o.fs.open(y,"r",function(P){if(P&&P.code==="ENOENT")v(void 0,Se.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 M=b[R],N=S(y,M).split("\\").join("/");N=N.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,""),A(N)?o.fs.stat(M,function(J,V){J&&v(void 0,J),V.isFile()?o.fs.readFile(M,function(re,Y){re?v(void 0,re):(C.addFile(I+N,Y,"",V),O())}):(C.addFile(I+N+"/",Buffer.alloc(0),"",V),O())}):process.nextTick(()=>{O()})}else v(!0,void 0)};O()}})},addLocalFolderAsync2:function(y,v){let I=this;y=typeof y=="object"?y:{localPath:y},localPath=ve.resolve(m(y.localPath));let{zipPath:A,filter:C,namefix:P}=y;C instanceof RegExp?C=(function(O){return function(M){return O.test(M)}})(C):typeof C!="function"&&(C=function(){return!0}),A=A?m(A):"",P=="latin1"&&(P=O=>O.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^\x20-\x7E]/g,"")),typeof P!="function"&&(P=O=>O);let b=O=>ve.join(A,P(S(localPath,O))),R=O=>ve.win32.basename(ve.win32.normalize(P(O)));o.fs.open(localPath,"r",function(O){O&&O.code==="ENOENT"?v(void 0,Se.Errors.FILE_NOT_FOUND(localPath)):O?v(void 0,O):o.findFilesAsync(localPath,function(M,N){if(M)return v(M);N=N.filter(J=>C(b(J))),N.length||v(void 0,!1),setImmediate(N.reverse().reduce(function(J,V){return function(re,Y){if(re||Y===!1)return setImmediate(J,re,!1);I.addLocalFileAsync({localPath:V,zipPath:ve.dirname(b(V)),zipName:R(V)},J)}},v))})})},addLocalFolderPromise:function(y,v){return new Promise((I,A)=>{this.addLocalFolderAsync2(Object.assign({localPath:y},v),(C,P)=>{C&&A(C),P&&I(this)})})},addFile:function(y,v,I,A){y=h(y);let C=x(y),P=C!=null;P||(C=new Bm(i),C.entryName=y),C.comment=I||"";let b=typeof A=="object"&&A instanceof o.fs.Stats;b&&(C.header.time=A.mtime);var R=C.isDirectory?16:0;let O=C.isDirectory?16384:32768;return b?O|=4095&A.mode:typeof A=="number"?O|=4095&A: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 x(y)},getEntryCount:function(){return c.getEntryCount()},forEach:function(y){return c.forEach(y)},extractEntryTo:function(y,v,I,A,C,P){A=Ln(!1,A),C=Ln(!1,C),I=Ln(!0,I),P=mu(C,P);var b=x(y);if(!b)throw Se.Errors.NO_ENTRY();var R=d(b.entryName),O=u(v,P&&!b.isDirectory?P:I?R:ve.basename(R));if(b.isDirectory){var M=c.getEntryChildren(b);return M.forEach(function(V){if(V.isDirectory)return;var re=V.getData();if(!re)throw Se.Errors.CANT_EXTRACT_FILE();var Y=d(V.entryName),se=u(v,I?Y:ve.basename(Y));let ae=C?V.header.fileAttr:void 0;o.writeFileTo(se,re,A,ae)}),!0}var N=b.getData(c.password);if(!N)throw Se.Errors.CANT_EXTRACT_FILE();if(o.fs.existsSync(O)&&!A)throw Se.Errors.CANT_OVERRIDE();let J=C?y.header.fileAttr:void 0;return o.writeFileTo(O,N,A,J),!0},test:function(y){if(!c)return!1;for(var v in c.entries)try{if(v.isDirectory)continue;var I=c.entries[v].getData(y);if(!I)return!1}catch{return!1}return!0},extractAllTo:function(y,v,I,A){if(I=Ln(!1,I),A=mu(I,A),v=Ln(!1,v),!c)throw Se.Errors.NO_ZIP();c.entries.forEach(function(C){var P=u(y,d(C.entryName));if(C.isDirectory){o.makeDir(P);return}var b=C.getData(A);if(!b)throw Se.Errors.CANT_EXTRACT_FILE();let R=I?C.header.fileAttr:void 0;o.writeFileTo(P,b,v,R);try{o.fs.utimesSync(P,C.header.time,C.header.time)}catch{throw Se.Errors.CANT_EXTRACT_FILE()}})},extractAllToAsync:function(y,v,I,A){if(A=zm(v,I,A),I=Ln(!1,I),v=Ln(!1,v),!A)return new Promise((O,M)=>{this.extractAllToAsync(y,v,I,function(N){N?M(N):O(this)})});if(!c){A(Se.Errors.NO_ZIP());return}y=ve.resolve(y);let C=O=>u(y,ve.normalize(d(O.entryName))),P=(O,M)=>new Error(O+': "'+M+'"'),b=[],R=[];c.entries.forEach(O=>{O.isDirectory?b.push(O):R.push(O)});for(let O of b){let M=C(O),N=I?O.header.fileAttr:void 0;try{o.makeDir(M),N&&o.fs.chmodSync(M,N),o.fs.utimesSync(M,O.header.time,O.header.time)}catch{A(P("Unable to create folder",M))}}R.reverse().reduce(function(O,M){return function(N){if(N)O(N);else{let J=ve.normalize(d(M.entryName)),V=u(y,J);M.getDataAsync(function(re,Y){if(Y)O(Y);else if(!re)O(Se.Errors.CANT_EXTRACT_FILE());else{let se=I?M.header.fileAttr:void 0;o.writeFileToAsync(V,re,v,se,function(ae){ae||O(P("Unable to write file",V)),o.fs.utimes(V,M.header.time,M.header.time,function(D){D?O(P("Unable to set times",V)):O()})})}})}}},A)()},writeZip:function(y,v){if(arguments.length===1&&typeof y=="function"&&(v=y,y=""),!y&&i.filename&&(y=i.filename),!!y){var I=c.compressToBuffer();if(I){var A=o.writeFileTo(y,I,!0);typeof v=="function"&&v(A?null:new Error("failed"),"")}}},writeZipPromise:function(y,v){let{overwrite:I,perm:A}=Object.assign({overwrite:!0},v);return new Promise((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,I,A,R)},P)})},toBufferPromise:function(){return new Promise((y,v)=>{c.toAsyncBuffer(y,v)})},toBuffer:function(y,v,I,A){return typeof y=="function"?(c.toAsyncBuffer(y,v,I,A),null):c.compressToBuffer()}}}});import{execFile as V_,spawn as J_,spawnSync as VA}from"node:child_process";import{promisify as Z_}from"node:util";function Y_(t){if(process.platform!=="win32")return!1;if(Uf.test(t))return!0;let r=(t.split(/[/\\]/).pop()??t).replace(Uf,"").toLowerCase();return X_.has(r)}function Gf(t,e){if(process.platform!=="win32")return e??{};let r={...e??{}};return Y_(t)&&r.shell===void 0&&(r.shell=!0),r.windowsHide===void 0&&(r.windowsHide=!0),r}function ot(t,e=[],r={}){return J_(t,e,Gf(t,r))}function Hf(t,e=[],r={}){return Q_(t,e,Gf(t,r))}var X_,Uf,Q_,Xt=rt(()=>{"use strict";X_=new Set(["npm","npx","yarn","pnpm","coze","tsx","claude-agent-acp","codex-acp","openclaw"]),Uf=/\.(cmd|bat|ps1)$/i;Q_=Z_(V_)});var Qt=ce((NR,Ch)=>{"use strict";var kh=["nodebuffer","arraybuffer","fragments"],Th=typeof Blob<"u";Th&&kh.push("blob");Ch.exports={BINARY_TYPES:kh,CLOSE_TIMEOUT:3e4,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:Th,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var Zi=ce((MR,Po)=>{"use strict";var{EMPTY_BUFFER:BE}=Qt(),_d=Buffer[Symbol.species];function FE(t,e){if(t.length===0)return BE;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 _d(r.buffer,r.byteOffset,i):r}function Rh(t,e,r,i,o){for(let c=0;c<o;c++)r[i+c]=t[c]^e[c&3]}function Dh(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function zE(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function yd(t){if(yd.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new _d(t):ArrayBuffer.isView(t)?e=new _d(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),yd.readOnly=!1),e}Po.exports={concat:FE,mask:Rh,toArrayBuffer:zE,toBuffer:yd,unmask:Dh};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=fe("bufferutil");Po.exports.mask=function(e,r,i,o,c){c<48?Rh(e,r,i,o,c):t.mask(e,r,i,o,c)},Po.exports.unmask=function(e,r){e.length<32?Dh(e,r):t.unmask(e,r)}}catch{}});var Lh=ce((BR,Oh)=>{"use strict";var Ph=Symbol("kDone"),bd=Symbol("kRun"),Ed=class{constructor(e){this[Ph]=()=>{this.pending--,this[bd]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[bd]()}[bd](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Ph])}}};Oh.exports=Ed});var Gr=ce((FR,Fh)=>{"use strict";var Xi=fe("zlib"),Nh=Zi(),UE=Lh(),{kStatusCode:Mh}=Qt(),GE=Buffer[Symbol.species],HE=Buffer.from([0,0,255,255]),Lo=Symbol("permessage-deflate"),en=Symbol("total-length"),zr=Symbol("callback"),Cn=Symbol("buffers"),Ur=Symbol("error"),Oo,vd=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,!Oo){let r=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Oo=new UE(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[zr];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){Oo.add(o=>{this._decompress(e,r,(c,d)=>{o(),i(c,d)})})}compress(e,r,i){Oo.add(o=>{this._compress(e,r,(c,d)=>{o(),i(c,d)})})}_decompress(e,r,i){let o=this._isServer?"client":"server";if(!this._inflate){let c=`${o}_max_window_bits`,d=typeof this.params[c]!="number"?Xi.Z_DEFAULT_WINDOWBITS:this.params[c];this._inflate=Xi.createInflateRaw({...this._options.zlibInflateOptions,windowBits:d}),this._inflate[Lo]=this,this._inflate[en]=0,this._inflate[Cn]=[],this._inflate.on("error",jE),this._inflate.on("data",Bh)}this._inflate[zr]=i,this._inflate.write(e),r&&this._inflate.write(HE),this._inflate.flush(()=>{let c=this._inflate[Ur];if(c){this._inflate.close(),this._inflate=null,i(c);return}let d=Nh.concat(this._inflate[Cn],this._inflate[en]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[en]=0,this._inflate[Cn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._inflate.reset()),i(null,d)})}_compress(e,r,i){let o=this._isServer?"server":"client";if(!this._deflate){let c=`${o}_max_window_bits`,d=typeof this.params[c]!="number"?Xi.Z_DEFAULT_WINDOWBITS:this.params[c];this._deflate=Xi.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:d}),this._deflate[en]=0,this._deflate[Cn]=[],this._deflate.on("data",qE)}this._deflate[zr]=i,this._deflate.write(e),this._deflate.flush(Xi.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let c=Nh.concat(this._deflate[Cn],this._deflate[en]);r&&(c=new GE(c.buffer,c.byteOffset,c.length-4)),this._deflate[zr]=null,this._deflate[en]=0,this._deflate[Cn]=[],r&&this.params[`${o}_no_context_takeover`]&&this._deflate.reset(),i(null,c)})}};Fh.exports=vd;function qE(t){this[Cn].push(t),this[en]+=t.length}function Bh(t){if(this[en]+=t.length,this[Lo]._maxPayload<1||this[en]<=this[Lo]._maxPayload){this[Cn].push(t);return}this[Ur]=new RangeError("Max payload size exceeded"),this[Ur].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[Ur][Mh]=1009,this.removeListener("data",Bh),this.reset()}function jE(t){if(this[Lo]._inflate=null,this[Ur]){this[zr](this[Ur]);return}t[Mh]=1007,this[zr](t)}});var Hr=ce((zR,No)=>{"use strict";var{isUtf8:zh}=fe("buffer"),{hasBlob:WE}=Qt(),KE=[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 $E(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function Sd(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 VE(t){return WE&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}No.exports={isBlob:VE,isValidStatusCode:$E,isValidUTF8:Sd,tokenChars:KE};if(zh)No.exports.isValidUTF8=function(t){return t.length<24?Sd(t):zh(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=fe("utf-8-validate");No.exports.isValidUTF8=function(e){return e.length<32?Sd(e):t(e)}}catch{}});var Cd=ce((UR,Kh)=>{"use strict";var{Writable:JE}=fe("stream"),Uh=Gr(),{BINARY_TYPES:ZE,EMPTY_BUFFER:Gh,kStatusCode:XE,kWebSocket:YE}=Qt(),{concat:Id,toArrayBuffer:QE,unmask:ev}=Zi(),{isValidStatusCode:tv,isValidUTF8:Hh}=Hr(),Mo=Buffer[Symbol.species],gt=0,qh=1,jh=2,Wh=3,Ad=4,kd=5,Bo=6,Td=class extends JE{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||ZE[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[YE]=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=gt}_write(e,r,i){if(this._opcode===8&&this._state==gt)return i();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(i)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let i=this._buffers[0];return this._buffers[0]=new Mo(i.buffer,i.byteOffset+e,i.length-e),new Mo(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 Mo(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 gt:this.getInfo(e);break;case qh:this.getPayloadLength16(e);break;case jh:this.getPayloadLength64(e);break;case Wh:this.getMask();break;case Ad:this.getData(e);break;case kd:case Bo: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[Uh.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=qh:this._payloadLength===127?this._state=jh: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=Wh:this._state=Ad}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Ad}getData(e){let r=Gh;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&&ev(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=kd,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[Uh.extensionName].decompress(e,this._fin,(o,c)=>{if(o)return r(o);if(c.length){if(this._messageLength+=c.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let d=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(d);return}this._fragments.push(c)}this.dataMessage(r),this._state===gt&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=gt;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=Id(i,r):this._binaryType==="arraybuffer"?o=QE(Id(i,r)):this._binaryType==="blob"?o=new Blob(i):o=i,this._allowSynchronousEvents?(this.emit("message",o,!0),this._state=gt):(this._state=Bo,setImmediate(()=>{this.emit("message",o,!0),this._state=gt,this.startLoop(e)}))}else{let o=Id(i,r);if(!this._skipUTF8Validation&&!Hh(o)){let c=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(c);return}this._state===kd||this._allowSynchronousEvents?(this.emit("message",o,!1),this._state=gt):(this._state=Bo,setImmediate(()=>{this.emit("message",o,!1),this._state=gt,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,Gh),this.end();else{let i=e.readUInt16BE(0);if(!tv(i)){let c=this.createError(RangeError,`invalid status code ${i}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(c);return}let o=new Mo(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!Hh(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=gt;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=gt):(this._state=Bo,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=gt,this.startLoop(r)}))}createError(e,r,i,o,c){this._loop=!1,this._errored=!0;let d=new e(i?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(d,this.createError),d.code=c,d[XE]=o,d}};Kh.exports=Td});var Pd=ce((HR,Jh)=>{"use strict";var{Duplex:GR}=fe("stream"),{randomFillSync:nv}=fe("crypto"),$h=Gr(),{EMPTY_BUFFER:rv,kWebSocket:iv,NOOP:sv}=Qt(),{isBlob:qr,isValidStatusCode:ov}=Hr(),{mask:Vh,toBuffer:Zn}=Zi(),mt=Symbol("kByteLength"),av=Buffer.alloc(4),Fo=8*1024,Xn,jr=Fo,At=0,cv=1,dv=2,Rd=class t{constructor(e,r,i){this._extensions=r||{},i&&(this._generateMask=i,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._queue=[],this._state=At,this.onerror=sv,this[iv]=void 0}static frame(e,r){let i,o=!1,c=2,d=!1;r.mask&&(i=r.maskBuffer||av,r.generateMask?r.generateMask(i):(jr===Fo&&(Xn===void 0&&(Xn=Buffer.alloc(Fo)),nv(Xn,0,Fo),jr=0),i[0]=Xn[jr++],i[1]=Xn[jr++],i[2]=Xn[jr++],i[3]=Xn[jr++]),d=(i[0]|i[1]|i[2]|i[3])===0,c=6);let u;typeof e=="string"?(!r.mask||d)&&r[mt]!==void 0?u=r[mt]:(e=Buffer.from(e),u=e.length):(u=e.length,o=r.mask&&r.readOnly&&!d);let h=u;u>=65536?(c+=8,h=127):u>125&&(c+=2,h=126);let x=Buffer.allocUnsafe(o?u+c:c);return x[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(x[0]|=64),x[1]=h,h===126?x.writeUInt16BE(u,2):h===127&&(x[2]=x[3]=0,x.writeUIntBE(u,4,6)),r.mask?(x[1]|=128,x[c-4]=i[0],x[c-3]=i[1],x[c-2]=i[2],x[c-1]=i[3],d?[x,e]:o?(Vh(e,i,x,c,u),[x]):(Vh(e,i,e,0,u),[x,e])):[x,e]}close(e,r,i,o){let c;if(e===void 0)c=rv;else{if(typeof e!="number"||!ov(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)c=Buffer.allocUnsafe(2),c.writeUInt16BE(e,0);else{let u=Buffer.byteLength(r);if(u>123)throw new RangeError("The message must not be greater than 123 bytes");c=Buffer.allocUnsafe(2+u),c.writeUInt16BE(e,0),typeof r=="string"?c.write(r,2):c.set(r,2)}}let d={[mt]:c.length,fin:!0,generateMask:this._generateMask,mask:i,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._state!==At?this.enqueue([this.dispatch,c,!1,d,o]):this.sendFrame(t.frame(c,d),o)}ping(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):qr(e)?(o=e.size,c=!1):(e=Zn(e),o=e.length,c=Zn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[mt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:c,rsv1:!1};qr(e)?this._state!==At?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==At?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}pong(e,r,i){let o,c;if(typeof e=="string"?(o=Buffer.byteLength(e),c=!1):qr(e)?(o=e.size,c=!1):(e=Zn(e),o=e.length,c=Zn.readOnly),o>125)throw new RangeError("The data size must not be greater than 125 bytes");let d={[mt]:o,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:c,rsv1:!1};qr(e)?this._state!==At?this.enqueue([this.getBlobData,e,!1,d,i]):this.getBlobData(e,!1,d,i):this._state!==At?this.enqueue([this.dispatch,e,!1,d,i]):this.sendFrame(t.frame(e,d),i)}send(e,r,i){let o=this._extensions[$h.extensionName],c=r.binary?2:1,d=r.compress,u,h;typeof e=="string"?(u=Buffer.byteLength(e),h=!1):qr(e)?(u=e.size,h=!1):(e=Zn(e),u=e.length,h=Zn.readOnly),this._firstFragment?(this._firstFragment=!1,d&&o&&o.params[o._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(d=u>=o._threshold),this._compress=d):(d=!1,c=0),r.fin&&(this._firstFragment=!0);let x={[mt]:u,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:c,readOnly:h,rsv1:d};qr(e)?this._state!==At?this.enqueue([this.getBlobData,e,this._compress,x,i]):this.getBlobData(e,this._compress,x,i):this._state!==At?this.enqueue([this.dispatch,e,this._compress,x,i]):this.dispatch(e,this._compress,x,i)}getBlobData(e,r,i,o){this._bufferedBytes+=i[mt],this._state=dv,e.arrayBuffer().then(c=>{if(this._socket.destroyed){let u=new Error("The socket was closed while the blob was being read");process.nextTick(Dd,this,u,o);return}this._bufferedBytes-=i[mt];let d=Zn(c);r?this.dispatch(d,r,i,o):(this._state=At,this.sendFrame(t.frame(d,i),o),this.dequeue())}).catch(c=>{process.nextTick(lv,this,c,o)})}dispatch(e,r,i,o){if(!r){this.sendFrame(t.frame(e,i),o);return}let c=this._extensions[$h.extensionName];this._bufferedBytes+=i[mt],this._state=cv,c.compress(e,i.fin,(d,u)=>{if(this._socket.destroyed){let h=new Error("The socket was closed while data was being compressed");Dd(this,h,o);return}this._bufferedBytes-=i[mt],this._state=At,i.readOnly=!1,this.sendFrame(t.frame(u,i),o),this.dequeue()})}dequeue(){for(;this._state===At&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][mt],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][mt],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)}};Jh.exports=Rd;function Dd(t,e,r){typeof r=="function"&&r(e);for(let i=0;i<t._queue.length;i++){let o=t._queue[i],c=o[o.length-1];typeof c=="function"&&c(e)}}function lv(t,e,r){Dd(t,e,r),t.onerror(e)}});var ix=ce((qR,rx)=>{"use strict";var{kForOnEventAttribute:Yi,kListener:Od}=Qt(),Zh=Symbol("kCode"),Xh=Symbol("kData"),Yh=Symbol("kError"),Qh=Symbol("kMessage"),ex=Symbol("kReason"),Wr=Symbol("kTarget"),tx=Symbol("kType"),nx=Symbol("kWasClean"),tn=class{constructor(e){this[Wr]=null,this[tx]=e}get target(){return this[Wr]}get type(){return this[tx]}};Object.defineProperty(tn.prototype,"target",{enumerable:!0});Object.defineProperty(tn.prototype,"type",{enumerable:!0});var Yn=class extends tn{constructor(e,r={}){super(e),this[Zh]=r.code===void 0?0:r.code,this[ex]=r.reason===void 0?"":r.reason,this[nx]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Zh]}get reason(){return this[ex]}get wasClean(){return this[nx]}};Object.defineProperty(Yn.prototype,"code",{enumerable:!0});Object.defineProperty(Yn.prototype,"reason",{enumerable:!0});Object.defineProperty(Yn.prototype,"wasClean",{enumerable:!0});var Kr=class extends tn{constructor(e,r={}){super(e),this[Yh]=r.error===void 0?null:r.error,this[Qh]=r.message===void 0?"":r.message}get error(){return this[Yh]}get message(){return this[Qh]}};Object.defineProperty(Kr.prototype,"error",{enumerable:!0});Object.defineProperty(Kr.prototype,"message",{enumerable:!0});var Qi=class extends tn{constructor(e,r={}){super(e),this[Xh]=r.data===void 0?null:r.data}get data(){return this[Xh]}};Object.defineProperty(Qi.prototype,"data",{enumerable:!0});var uv={addEventListener(t,e,r={}){for(let o of this.listeners(t))if(!r[Yi]&&o[Od]===e&&!o[Yi])return;let i;if(t==="message")i=function(c,d){let u=new Qi("message",{data:d?c:c.toString()});u[Wr]=this,zo(e,this,u)};else if(t==="close")i=function(c,d){let u=new Yn("close",{code:c,reason:d.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});u[Wr]=this,zo(e,this,u)};else if(t==="error")i=function(c){let d=new Kr("error",{error:c,message:c.message});d[Wr]=this,zo(e,this,d)};else if(t==="open")i=function(){let c=new tn("open");c[Wr]=this,zo(e,this,c)};else return;i[Yi]=!!r[Yi],i[Od]=e,r.once?this.once(t,i):this.on(t,i)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[Od]===e&&!r[Yi]){this.removeListener(t,r);break}}};rx.exports={CloseEvent:Yn,ErrorEvent:Kr,Event:tn,EventTarget:uv,MessageEvent:Qi};function zo(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var Uo=ce((jR,sx)=>{"use strict";var{tokenChars:es}=Hr();function Ut(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function fv(t){let e=Object.create(null),r=Object.create(null),i=!1,o=!1,c=!1,d,u,h=-1,x=-1,m=-1,_=0;for(;_<t.length;_++)if(x=t.charCodeAt(_),d===void 0)if(m===-1&&es[x]===1)h===-1&&(h=_);else if(_!==0&&(x===32||x===9))m===-1&&h!==-1&&(m=_);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${_}`);m===-1&&(m=_);let y=t.slice(h,m);x===44?(Ut(e,y,r),r=Object.create(null)):d=y,h=m=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);else if(u===void 0)if(m===-1&&es[x]===1)h===-1&&(h=_);else if(x===32||x===9)m===-1&&h!==-1&&(m=_);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${_}`);m===-1&&(m=_),Ut(r,t.slice(h,m),!0),x===44&&(Ut(e,d,r),r=Object.create(null),d=void 0),h=m=-1}else if(x===61&&h!==-1&&m===-1)u=t.slice(h,_),h=m=-1;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(o){if(es[x]!==1)throw new SyntaxError(`Unexpected character at index ${_}`);h===-1?h=_:i||(i=!0),o=!1}else if(c)if(es[x]===1)h===-1&&(h=_);else if(x===34&&h!==-1)c=!1,m=_;else if(x===92)o=!0;else throw new SyntaxError(`Unexpected character at index ${_}`);else if(x===34&&t.charCodeAt(_-1)===61)c=!0;else if(m===-1&&es[x]===1)h===-1&&(h=_);else if(h!==-1&&(x===32||x===9))m===-1&&(m=_);else if(x===59||x===44){if(h===-1)throw new SyntaxError(`Unexpected character at index ${_}`);m===-1&&(m=_);let y=t.slice(h,m);i&&(y=y.replace(/\\/g,""),i=!1),Ut(r,u,y),x===44&&(Ut(e,d,r),r=Object.create(null),d=void 0),u=void 0,h=m=-1}else throw new SyntaxError(`Unexpected character at index ${_}`);if(h===-1||c||x===32||x===9)throw new SyntaxError("Unexpected end of input");m===-1&&(m=_);let S=t.slice(h,m);return d===void 0?Ut(e,S,r):(u===void 0?Ut(r,S,!0):i?Ut(r,u,S.replace(/\\/g,"")):Ut(r,u,S),Ut(e,d,r)),e}function hv(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(i=>[e].concat(Object.keys(i).map(o=>{let c=i[o];return Array.isArray(c)||(c=[c]),c.map(d=>d===!0?o:`${o}=${d}`).join("; ")})).join("; ")).join(", ")}).join(", ")}sx.exports={format:hv,parse:fv}});var jo=ce(($R,mx)=>{"use strict";var xv=fe("events"),pv=fe("https"),gv=fe("http"),cx=fe("net"),mv=fe("tls"),{randomBytes:wv,createHash:_v}=fe("crypto"),{Duplex:WR,Readable:KR}=fe("stream"),{URL:Ld}=fe("url"),Rn=Gr(),yv=Cd(),bv=Pd(),{isBlob:Ev}=Hr(),{BINARY_TYPES:ox,CLOSE_TIMEOUT:vv,EMPTY_BUFFER:Go,GUID:Sv,kForOnEventAttribute:Nd,kListener:Iv,kStatusCode:Av,kWebSocket:Ke,NOOP:dx}=Qt(),{EventTarget:{addEventListener:kv,removeEventListener:Tv}}=ix(),{format:Cv,parse:Rv}=Uo(),{toBuffer:Dv}=Zi(),lx=Symbol("kAborted"),Md=[8,13],nn=["CONNECTING","OPEN","CLOSING","CLOSED"],Pv=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,_e=class t extends xv{constructor(e,r,i){super(),this._binaryType=ox[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Go,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]),ux(this,e,r,i)):(this._autoPong=i.autoPong,this._closeTimeout=i.closeTimeout,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){ox.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 yv({allowSynchronousEvents:i.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation}),c=new bv(e,this._extensions,i.generateMask);this._receiver=o,this._sender=c,this._socket=e,o[Ke]=this,c[Ke]=this,e[Ke]=this,o.on("conclude",Nv),o.on("drain",Mv),o.on("error",Bv),o.on("message",Fv),o.on("ping",zv),o.on("pong",Uv),c.onerror=Gv,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",xx),e.on("data",qo),e.on("end",px),e.on("error",gx),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[Rn.extensionName]&&this._extensions[Rn.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){lt(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())}),hx(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){Bd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Go,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){Bd(this,e,i);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Go,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){Bd(this,e,i);return}let o={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[Rn.extensionName]||(o.compress=!1),this._sender.send(e||Go,o,i)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){lt(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(_e,"CONNECTING",{enumerable:!0,value:nn.indexOf("CONNECTING")});Object.defineProperty(_e.prototype,"CONNECTING",{enumerable:!0,value:nn.indexOf("CONNECTING")});Object.defineProperty(_e,"OPEN",{enumerable:!0,value:nn.indexOf("OPEN")});Object.defineProperty(_e.prototype,"OPEN",{enumerable:!0,value:nn.indexOf("OPEN")});Object.defineProperty(_e,"CLOSING",{enumerable:!0,value:nn.indexOf("CLOSING")});Object.defineProperty(_e.prototype,"CLOSING",{enumerable:!0,value:nn.indexOf("CLOSING")});Object.defineProperty(_e,"CLOSED",{enumerable:!0,value:nn.indexOf("CLOSED")});Object.defineProperty(_e.prototype,"CLOSED",{enumerable:!0,value:nn.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(_e.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(_e.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[Nd])return e[Iv];return null},set(e){for(let r of this.listeners(t))if(r[Nd]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[Nd]:!0})}})});_e.prototype.addEventListener=kv;_e.prototype.removeEventListener=Tv;mx.exports=_e;function ux(t,e,r,i){let o={allowSynchronousEvents:!0,autoPong:!0,closeTimeout:vv,protocolVersion:Md[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...i,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=o.autoPong,t._closeTimeout=o.closeTimeout,!Md.includes(o.protocolVersion))throw new RangeError(`Unsupported protocol version: ${o.protocolVersion} (supported versions: ${Md.join(", ")})`);let c;if(e instanceof Ld)c=e;else try{c=new Ld(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}c.protocol==="http:"?c.protocol="ws:":c.protocol==="https:"&&(c.protocol="wss:"),t._url=c.href;let d=c.protocol==="wss:",u=c.protocol==="ws+unix:",h;if(c.protocol!=="ws:"&&!d&&!u?h=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:u&&!c.pathname?h="The URL's pathname is empty":c.hash&&(h="The URL contains a fragment identifier"),h){let I=new SyntaxError(h);if(t._redirects===0)throw I;Ho(t,I);return}let x=d?443:80,m=wv(16).toString("base64"),_=d?pv.request:gv.request,S=new Set,y;if(o.createConnection=o.createConnection||(d?Lv:Ov),o.defaultPort=o.defaultPort||x,o.port=c.port||x,o.host=c.hostname.startsWith("[")?c.hostname.slice(1,-1):c.hostname,o.headers={...o.headers,"Sec-WebSocket-Version":o.protocolVersion,"Sec-WebSocket-Key":m,Connection:"Upgrade",Upgrade:"websocket"},o.path=c.pathname+c.search,o.timeout=o.handshakeTimeout,o.perMessageDeflate&&(y=new Rn({...o.perMessageDeflate,isServer:!1,maxPayload:o.maxPayload}),o.headers["Sec-WebSocket-Extensions"]=Cv({[Rn.extensionName]:y.offer()})),r.length){for(let I of r){if(typeof I!="string"||!Pv.test(I)||S.has(I))throw new SyntaxError("An invalid or duplicated subprotocol was specified");S.add(I)}o.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(o.origin&&(o.protocolVersion<13?o.headers["Sec-WebSocket-Origin"]=o.origin:o.headers.Origin=o.origin),(c.username||c.password)&&(o.auth=`${c.username}:${c.password}`),u){let I=o.path.split(":");o.socketPath=I[0],o.path=I[1]}let v;if(o.followRedirects){if(t._redirects===0){t._originalIpc=u,t._originalSecure=d,t._originalHostOrSocketPath=u?o.socketPath:c.host;let I=i&&i.headers;if(i={...i,headers:{}},I)for(let[A,C]of Object.entries(I))i.headers[A.toLowerCase()]=C}else if(t.listenerCount("redirect")===0){let I=u?t._originalIpc?o.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:c.host===t._originalHostOrSocketPath;(!I||t._originalSecure&&!d)&&(delete o.headers.authorization,delete o.headers.cookie,I||delete o.headers.host,o.auth=void 0)}o.auth&&!i.headers.authorization&&(i.headers.authorization="Basic "+Buffer.from(o.auth).toString("base64")),v=t._req=_(o),t._redirects&&t.emit("redirect",t.url,v)}else v=t._req=_(o);o.timeout&&v.on("timeout",()=>{lt(t,v,"Opening handshake has timed out")}),v.on("error",I=>{v===null||v[lx]||(v=t._req=null,Ho(t,I))}),v.on("response",I=>{let A=I.headers.location,C=I.statusCode;if(A&&o.followRedirects&&C>=300&&C<400){if(++t._redirects>o.maxRedirects){lt(t,v,"Maximum redirects exceeded");return}v.abort();let P;try{P=new Ld(A,e)}catch{let R=new SyntaxError(`Invalid URL: ${A}`);Ho(t,R);return}ux(t,P,r,i)}else t.emit("unexpected-response",v,I)||lt(t,v,`Unexpected server response: ${I.statusCode}`)}),v.on("upgrade",(I,A,C)=>{if(t.emit("upgrade",I),t.readyState!==_e.CONNECTING)return;v=t._req=null;let P=I.headers.upgrade;if(P===void 0||P.toLowerCase()!=="websocket"){lt(t,A,"Invalid Upgrade header");return}let b=_v("sha1").update(m+Sv).digest("base64");if(I.headers["sec-websocket-accept"]!==b){lt(t,A,"Invalid Sec-WebSocket-Accept header");return}let R=I.headers["sec-websocket-protocol"],O;if(R!==void 0?S.size?S.has(R)||(O="Server sent an invalid subprotocol"):O="Server sent a subprotocol but none was requested":S.size&&(O="Server sent no subprotocol"),O){lt(t,A,O);return}R&&(t._protocol=R);let M=I.headers["sec-websocket-extensions"];if(M!==void 0){if(!y){lt(t,A,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let N;try{N=Rv(M)}catch{lt(t,A,"Invalid Sec-WebSocket-Extensions header");return}let J=Object.keys(N);if(J.length!==1||J[0]!==Rn.extensionName){lt(t,A,"Server indicated an extension that was not requested");return}try{y.accept(N[Rn.extensionName])}catch{lt(t,A,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[Rn.extensionName]=y}t.setSocket(A,C,{allowSynchronousEvents:o.allowSynchronousEvents,generateMask:o.generateMask,maxPayload:o.maxPayload,skipUTF8Validation:o.skipUTF8Validation})}),o.finishRequest?o.finishRequest(v,t):v.end()}function Ho(t,e){t._readyState=_e.CLOSING,t._errorEmitted=!0,t.emit("error",e),t.emitClose()}function Ov(t){return t.path=t.socketPath,cx.connect(t)}function Lv(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=cx.isIP(t.host)?"":t.host),mv.connect(t)}function lt(t,e,r){t._readyState=_e.CLOSING;let i=new Error(r);Error.captureStackTrace(i,lt),e.setHeader?(e[lx]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Ho,t,i)):(e.destroy(i),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function Bd(t,e,r){if(e){let i=Ev(e)?e.size:Dv(e).length;t._socket?t._sender._bufferedBytes+=i:t._bufferedAmount+=i}if(r){let i=new Error(`WebSocket is not open: readyState ${t.readyState} (${nn[t.readyState]})`);process.nextTick(r,i)}}function Nv(t,e){let r=this[Ke];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[Ke]!==void 0&&(r._socket.removeListener("data",qo),process.nextTick(fx,r._socket),t===1005?r.close():r.close(t,e))}function Mv(){let t=this[Ke];t.isPaused||t._socket.resume()}function Bv(t){let e=this[Ke];e._socket[Ke]!==void 0&&(e._socket.removeListener("data",qo),process.nextTick(fx,e._socket),e.close(t[Av])),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t))}function ax(){this[Ke].emitClose()}function Fv(t,e){this[Ke].emit("message",t,e)}function zv(t){let e=this[Ke];e._autoPong&&e.pong(t,!this._isServer,dx),e.emit("ping",t)}function Uv(t){this[Ke].emit("pong",t)}function fx(t){t.resume()}function Gv(t){let e=this[Ke];e.readyState!==_e.CLOSED&&(e.readyState===_e.OPEN&&(e._readyState=_e.CLOSING,hx(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=!0,e.emit("error",t)))}function hx(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),t._closeTimeout)}function xx(){let t=this[Ke];if(this.removeListener("close",xx),this.removeListener("data",qo),this.removeListener("end",px),t._readyState=_e.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[Ke]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",ax),t._receiver.on("finish",ax))}function qo(t){this[Ke]._receiver.write(t)||this.pause()}function px(){let t=this[Ke];t._readyState=_e.CLOSING,t._receiver.end(),this.end()}function gx(){let t=this[Ke];this.removeListener("error",gx),this.on("error",dx),t&&(t._readyState=_e.CLOSING,this.destroy())}});var Ex=ce((JR,bx)=>{"use strict";var VR=jo(),{Duplex:Hv}=fe("stream");function _x(t){t.emit("close")}function qv(){!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 jv(t,e){let r=!0,i=new Hv({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(c,d){let u=!d&&i._readableState.objectMode?c.toString():c;i.push(u)||t.pause()}),t.once("error",function(c){i.destroyed||(r=!1,i.destroy(c))}),t.once("close",function(){i.destroyed||i.push(null)}),i._destroy=function(o,c){if(t.readyState===t.CLOSED){c(o),process.nextTick(_x,i);return}let d=!1;t.once("error",function(h){d=!0,c(h)}),t.once("close",function(){d||c(o),process.nextTick(_x,i)}),r&&t.terminate()},i._final=function(o){if(t.readyState===t.CONNECTING){t.once("open",function(){i._final(o)});return}t._socket!==null&&(t._socket._writableState.finished?(o(),i._readableState.endEmitted&&i.destroy()):(t._socket.once("finish",function(){o()}),t.close()))},i._read=function(){t.isPaused&&t.resume()},i._write=function(o,c,d){if(t.readyState===t.CONNECTING){t.once("open",function(){i._write(o,c,d)});return}t.send(o,d)},i.on("end",qv),i.on("error",yx),i}bx.exports=jv});var Fd=ce((ZR,vx)=>{"use strict";var{tokenChars:Wv}=Hr();function Kv(t){let e=new Set,r=-1,i=-1,o=0;for(o;o<t.length;o++){let d=t.charCodeAt(o);if(i===-1&&Wv[d]===1)r===-1&&(r=o);else if(o!==0&&(d===32||d===9))i===-1&&r!==-1&&(i=o);else if(d===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${o}`);i===-1&&(i=o);let u=t.slice(r,i);if(e.has(u))throw new SyntaxError(`The "${u}" subprotocol is duplicated`);e.add(u),r=i=-1}else throw new SyntaxError(`Unexpected character at index ${o}`)}if(r===-1||i!==-1)throw new SyntaxError("Unexpected end of input");let c=t.slice(r,o);if(e.has(c))throw new SyntaxError(`The "${c}" subprotocol is duplicated`);return e.add(c),e}vx.exports={parse:Kv}});var Rx=ce((YR,Cx)=>{"use strict";var $v=fe("events"),Wo=fe("http"),{Duplex:XR}=fe("stream"),{createHash:Vv}=fe("crypto"),Sx=Uo(),Qn=Gr(),Jv=Fd(),Zv=jo(),{CLOSE_TIMEOUT:Xv,GUID:Yv,kWebSocket:Qv}=Qt(),eS=/^[+/0-9A-Za-z]{22}==$/,Ix=0,Ax=1,Tx=2,zd=class extends $v{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,closeTimeout:Xv,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Zv,...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=Wo.createServer((i,o)=>{let c=Wo.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=tS(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(o,c,d)=>{this.handleUpgrade(o,c,d,i)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Ix}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===Tx){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(ts,this);return}if(e&&this.once("close",e),this._state!==Ax)if(this._state=Ax,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(ts,this):process.nextTick(ts,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{ts(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,i,o){r.on("error",kx);let c=e.headers["sec-websocket-key"],d=e.headers.upgrade,u=+e.headers["sec-websocket-version"];if(e.method!=="GET"){er(this,e,r,405,"Invalid HTTP method");return}if(d===void 0||d.toLowerCase()!=="websocket"){er(this,e,r,400,"Invalid Upgrade header");return}if(c===void 0||!eS.test(c)){er(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(u!==13&&u!==8){er(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){ns(r,400);return}let h=e.headers["sec-websocket-protocol"],x=new Set;if(h!==void 0)try{x=Jv.parse(h)}catch{er(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let m=e.headers["sec-websocket-extensions"],_={};if(this.options.perMessageDeflate&&m!==void 0){let S=new Qn({...this.options.perMessageDeflate,isServer:!0,maxPayload:this.options.maxPayload});try{let y=Sx.parse(m);y[Qn.extensionName]&&(S.accept(y[Qn.extensionName]),_[Qn.extensionName]=S)}catch{er(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let S={origin:e.headers[`${u===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(S,(y,v,I,A)=>{if(!y)return ns(r,v||401,I,A);this.completeUpgrade(_,c,x,e,r,i,o)});return}if(!this.options.verifyClient(S))return ns(r,401)}this.completeUpgrade(_,c,x,e,r,i,o)}completeUpgrade(e,r,i,o,c,d,u){if(!c.readable||!c.writable)return c.destroy();if(c[Qv])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Ix)return ns(c,503);let x=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Vv("sha1").update(r+Yv).digest("base64")}`],m=new this.options.WebSocket(null,void 0,this.options);if(i.size){let _=this.options.handleProtocols?this.options.handleProtocols(i,o):i.values().next().value;_&&(x.push(`Sec-WebSocket-Protocol: ${_}`),m._protocol=_)}if(e[Qn.extensionName]){let _=e[Qn.extensionName].params,S=Sx.format({[Qn.extensionName]:[_]});x.push(`Sec-WebSocket-Extensions: ${S}`),m._extensions=e}this.emit("headers",x,o),c.write(x.concat(`\r
|
|
15
15
|
`).join(`\r
|
|
16
|
-
`)),c.removeListener("error",
|
|
16
|
+
`)),c.removeListener("error",kx),m.setSocket(c,d,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(m),m.on("close",()=>{this.clients.delete(m),this._shouldEmitClose&&!this.clients.size&&process.nextTick(ts,this)})),u(m,o)}};Cx.exports=zd;function tS(t,e){for(let r of Object.keys(e))t.on(r,e[r]);return function(){for(let i of Object.keys(e))t.removeListener(i,e[i])}}function ts(t){t._state=Tx,t.emit("close")}function kx(){this.destroy()}function ns(t,e,r,i){r=r||Wo.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} ${Wo.STATUS_CODES[e]}\r
|
|
17
17
|
`+Object.keys(i).map(o=>`${o}: ${i[o]}`).join(`\r
|
|
18
18
|
`)+`\r
|
|
19
19
|
\r
|
|
20
|
-
`+n)}function Qn(t,e,n,i,o,c){if(t.listenerCount("wsClientError")){let d=new Error(o);Error.captureStackTrace(d,Qn),t.emit("wsClientError",d,n,e)}else ts(n,i,o,c)}});var Uh=de(ze=>{"use strict";var M=W;(function(t,e){let n=W,i=t();for(;;)try{if(parseInt(n(395))/1*(parseInt(n(1111))/2)+-parseInt(n(701))/3+-parseInt(n(514))/4*(-parseInt(n(1238))/5)+parseInt(n(686))/6+parseInt(n(360))/7+-parseInt(n(1489))/8+-parseInt(n(816))/9===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(Xo,390204);var e1=Object[M(607)+M(1447)],t1=Object["getOwnPr"+M(447)+M(896)],Nh=(t,e)=>function(){return t&&(e=(0,t[t1(t)[0]])(t=0)),e},n1=(t,e)=>{let n=M,i={AIqno:function(c,d,u,x){return c(d,u,x)}};for(var o in e)i[n(1333)](e1,t,o,{get:e[o],enumerable:!0})};function r1(){return Ph||(Ph=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function i1(){let t=M;return Rh||(Rh=[IDBCursor.prototype[t(749)],IDBCursor.prototype[t(1194)],IDBCursor[t(733)+"e"][t(1194)+t(420)+"ey"]])}function s1(t){let e=M,n={dAZFw:function(o,c){return o(c)},XFiHn:function(o){return o()},wipGR:function(o,c){return o<c},AfgeX:function(o,c){return o===c},ZxQOG:e(325),IrhzB:e(246),ReWpX:e(884),yVWDo:function(o,c){return o(c)},VrFFG:function(o,c){return o!==c},nTCFV:e(994)},i=new Promise((o,c)=>{let d=e,u={hYLJf:function(w,v){return n[W(340)](w,v)},Eoduw:function(w,v){return n.AfgeX(w,v)},nAdCX:n.ZxQOG,gZyxo:d(853),SZIpl:n[d(1291)],ZTvgd:n[d(727)],NVwYi:function(w,v){return n[d(703)](w,v)},oDOCp:function(w,v){return n[d(412)](w,v)},bivfQ:n[d(456)],rhRvC:function(w){return w()}},x=()=>{let w=d;if(u[w(507)]!==u[w(720)])t[w(1176)+w(945)+w(1437)](w(1655),h),t[w(1176)+"entListe"+w(1437)](u.SZIpl,g);else{let v=this[w(971)+"rs"][_0x3ce7a3];if(v)for(let _=0;u[w(589)](_,v[w(284)]);)u[w(285)](v[_].fn,_0x376511)?v[w(332)](_,1):++_}},h=()=>{let w=d;if(u[w(848)](u[w(512)],u[w(512)])){let v=_0x3e4335["deleteDa"+w(1144)](_0x12b38f);return _0xd7fb70&&v["addEvent"+w(1503)](u[w(283)],()=>_0x593682()),u[w(576)](_0x1c974b,v)[w(326)](()=>{})}else o(zt(t[w(1274)])),u[w(1247)](x)},g=()=>{let w=d;n[w(389)](c,t[w(246)]),n[w(288)](x)};t.addEventListener(d(1655),h),t[d(1139)+d(1503)](n[d(1291)],g)});return i.then(o=>{o instanceof IDBCursor&&zd.set(o,t)})[e(836)](()=>{}),Zo[e(841)](i,t),i}function o1(t){let e=M,n={weeJW:function(o,c,d){return o(c,d)},uhSWM:e(246),cRwkQ:function(o){return o()},vUVxT:"AbortError",oLZaU:function(o){return o()},QsQsG:e(1255)};if(Jo[e(1110)](t))return;let i=new Promise((o,c)=>{let d=e;if(d(480)==="VMTHg")n[d(1541)](_0x1dd7e8,_0x548daf,24),n.weeJW(_0x3811ea,_0x2fa9b4,_0x4407b9(_0x32d2e8));else{let u=()=>{let g=d;t[g(1176)+g(945)+g(1437)](g(1255),x),t[g(1176)+g(945)+g(1437)](n.uhSWM,h),t[g(1176)+g(945)+g(1437)](g(491),h)},x=()=>{let g=d;n[g(481)](o),n[g(481)](u)},h=()=>{let g=d;c(t.error||new DOMException(n[g(211)],g(1207)+"or")),n[g(267)](u)};t[d(1139)+"Listener"](n[d(1136)],x),t[d(1139)+d(1503)](n[d(1570)],h),t[d(1139)+d(1503)]("abort",h)}});Jo[e(841)](t,i)}function a1(t){Yo=t(Yo)}function c1(t){let e=M,n={oBtOV:function(i,o){return i||o},kjpNd:function(i,o){return i===o},dMrfB:"EFWWX",vYECY:e(654),BYUSL:function(i,o){return i(o)},ZpPFw:function(i,o){return i(o)},lKAeW:function(i,o){return i===o},sThJe:e(899)+"oreNames",EnINI:function(i){return i()}};return n[e(510)](t,IDBDatabase.prototype["transact"+e(1202)])&&!(n[e(331)]in IDBTransaction.prototype)?function(i,...o){let c=e,d={rDzxQ:function(u,x){return n[W(1053)](u,x)}};if(n.kjpNd(n[c(838)],n[c(1170)])){let u=this[c(239)][c(1379)+c(1621)](this[c(1629)]);return _0x8ce9dd[c(1648)](d.rDzxQ(u,"{}"))[_0x346b24]}else{let u=t[c(851)](n[c(1132)](ns,this),i,...o);return Fd.set(u,i[c(591)]?i[c(591)]():[i]),n[c(1513)](zt,u)}}:n.EnINI(i1)[e(1443)](t)?function(...i){return t.apply(ns(this),i),zt(zd.get(this))}:function(...i){return zt(t[e(1324)](n.BYUSL(ns,this),i))}}function d1(t){let e=M,n={jVoxB:function(i,o){return i===o},zpAzm:function(i,o){return i(o)},aLwHe:function(i,o){return i instanceof o},NOICb:function(i,o){return i(o)},ATQKF:function(i){return i()}};return n[e(1578)](typeof t,e(1107))?n[e(893)](c1,t):(n.aLwHe(t,IDBTransaction)&&n.NOICb(o1,t),Mh(t,n[e(1270)](r1))?new Proxy(t,Yo):t)}function zt(t){let e=M,n={PDTQB:function(o,c){return o instanceof c},UdbHi:function(o,c){return o(c)}};if(n.PDTQB(t,IDBRequest))return n[e(470)](s1,t);if($o[e(1110)](t))return $o[e(1575)](t);let i=d1(t);return i!==t&&($o[e(841)](t,i),Zo[e(841)](i,t)),i}var Mh,Ph,Rh,zd,Jo,Fd,$o,Zo,Yo,ns,Dh=Nh({"node_modules/idb/build/wrap-idb-value.js"(){let t=M,e={ybJuQ:function(n,i){return n<i},kWKra:function(n,i){return n===i},HBUsi:function(n,i){return n+i},ATJeC:function(n,i){return n instanceof i},Oqrnm:function(n,i){return n===i},DfnSz:t(1201),fZLFz:function(n,i){return n===i},szHig:t(222),BAYpZ:t(899)+t(1405),aplaK:"store",aFdQt:function(n,i){return n(i)}};Mh=(n,i)=>i[t(174)](o=>n instanceof o),zd=new WeakMap,Jo=new WeakMap,Fd=new WeakMap,$o=new WeakMap,Zo=new WeakMap,Yo={get(n,i,o){let c=t,d={PRJiM:function(u,x){return e[W(1475)](u,x)},IcSzp:function(u,x){return e[W(1305)](u,x)},IQrPC:function(u,x){return u&x},ZOQTK:function(u,x){return e[W(1041)](u,x)}};if(e[c(856)](n,IDBTransaction))if(e[c(1343)](c(624),e[c(1546)])){let u=0,x=0;for(let h=0;h<_0x3502b1.length;++h)x=_0x19ad14.charCodeAt(h),d[c(551)](x,128)?u+=1:d[c(551)](x,2048)?u+=2:d[c(1285)](64512&x,55296)&&d[c(1410)](64512,_0x9c40a2[c(1395)+"At"](d[c(891)](h,1)))===56320?(++h,u+=4):u+=3;return u}else{if(e[c(1450)](i,e.szHig))return Jo[c(1575)](n);if(i===e[c(605)])return n[c(899)+"oreNames"]||Fd[c(1575)](n);if(e[c(1450)](i,e[c(1445)]))return o.objectStoreNames[1]?void 0:o["objectSt"+c(446)](o[c(899)+c(1405)][0])}return e[c(1369)](zt,n[i])},set(n,i,o){return n[i]=o,!0},has(n,i){let o=t;return e[o(856)](n,IDBTransaction)&&(i===e[o(1190)]||i===o(1135))?!0:i in n}},ns=n=>Zo.get(n)}}),Bh={};function Xo(){let t=["yNvMzMvY","q0Xpu0LorW","yxKSihrYEsa","BMDuAw1LCG","C29isK4","AuztD2C","AxLosK4","wvfHEeC","z0zbq0W","q291BNq","qMv3z2e","AMjrzwK","zNzKrNG","Ew1YwgK","yNLYDKW","EengDgi","zMPdsLa","ywXSzwqGBxu","DenWAgG","wLjotxa","AMTwDfu","t0zoALi","uvbLzu0","ywnR","EwjkDve","ihbYB3rVy28","B3bLBG","sfPbr24","ufrZrgO","q29Kzq","x2LZtwLUAvq","BwLUzW","Dwvnq3C","Au1IyM4","yMLUyxj5vhK","zw5HyMXLvhi","x2DLBMvYyxq","zMLSDgvY","mteXoda0meD4zLryyq","Ahr0Chm6","yxrLq291BNq","zwnVBM5Ly3q","zfLhBMe","tufyx1jfvfi","t1bftG","yxr4AK0","yxbWzw5Kq2G","BMrLEa","rLjptLrjrvi","CeHQAvC","reT2Age","uwrABfC","tgLZDgvUzxi","x3bPBMC","CKvdAKq","r2TRwuy","CgLUz19VBMm","ywfjuee","BMnVzgLUzW","C2nYAxb0","DLvsqM8","v1LNsvu","wNbqrNC","r0Ddvgy","zxjFCw9Z","CMvXDwLYzwq","vxbKyxrLq28","zgvSzxrLrge","x25HDMLNyxq","v2nUDvK","y0DsBhm","CNjVCK1LC3m","ignVzgu6ia","rMXdC0i","B0HAugW","wgjiDNi","qKHLChm","tNPbte4","DMvYC2LVBMm","rNDJCK8","t2jQzwn0","z2v0q3vYCMu","ywrKt25L","uePkrva","Be90tvi","AuHrBKS","z29PBMCGyxC","wNLHzeO","wLfNq3a","z1zys3e","D2vLsLC","Ae1Kt3q","zNDZxZeUmc4","AwXLx25HBwu","AKvYv0q","rgzUu3O","s2T0A0O","twvZC2fNzuu","BMLuEKC","whPPwwu","wLjrqNe","AMvAs00","A09HC2C","C2vUDa","B2zM","D0HvzM4","CxHtzeS","x2HHBMrSzva","uffbywq","Bwf4twvZC2e","Dhr3Awq","DMvUDa","EuzVtem","B3jpBMXPBMu","uxvLDwu","Eu9fCKC","ELD0DLy","D3DTwKG","vLDssLe","DwHtv00","vwTQvNK","rhb1tg8","DMrvANK","DgHHBIbSB2m","z2v0","DhjPzxm","AujIq1q","ALzVEei","zNjVBu51Bwi","C3vIC3rYAw4","yxGGCMv0CMK","x2nYzwf0zvm","q3vZDg9Trxi","Ae9Wzw5fDMu","ExbL","y3jLyxrLq2W","qKTlr0q","rNvLsem","rxLbsM4","AxnbCNjHEq","z2v0sxrLBq","AvH4veG","AhjIsgq","mdaWmdaWmda","wLjhDLq","B3bLBIa","CgXYweO","qMTQELO","CvHMwfa","zxjHDg9Y","ugHUB1G","txzlyvK","zhPZBgW","CK9ptxe","BxnNsuq","DeLK","AwDHDg9Yt24","BMvLzf9Hy2S","DMDOvue","wxbIAMm","CMvJB25Uzwm","z3vAqKe","y29UBMvJDgK","CfjfugW","Aw5ezxy","z2vjBMzVu3K","D2PsDKS","Dwj0ywW","CMzduNi","ywXty29Wzq","z2vtEw5J","EvDQDhi","q1Prr2i","y2HLy2TdDxi","D09Ur1i","tfv5wMK","sujmCxm","ywnRtxnNswq","x3bYzwzPEa","Dg1eBwC","CMXZyNO","A1blzLa","tgnezwK","sNvhC3q","yxv0BW","D1HVsNq","rvjdC0K","u0HjrvO","sLzVsKK","uw1YsKS","y2XLyxi","y29UBMvJDca","C3rtywq","zM9Yy2u","x29WDgLVBNm","vuzurue","B2zMC2v0","CgfYC2u","D3DlEge","whLQDMq","DKnsBwy","zM9YrwfJAa","CK5wA3a","B2LUDfjLywm","C3vJy2vZCW","l3DZl3yY","wNzhwuu","zMLN","D2LSBfjLy28","AgLNAa","ENDeww0","rMflrhe","DxHNtLK","AxLiuvu","ywrKq291BNq","t05TshK","s05oAfe","twLYD1i","Cgf5Bg9Hzfq","t2Tir3G","r2P0CeC","rw1Mz1y","z1rPBwvVDxq","r3jIz3u","x2nSzwfYvgK","Dgv4Dc9WBge","CfPrs3y","zNjVv0m","y29Kzq","s2Txse4","x2n1CNnVCKy","Dg9VigXHCMC","x2LUDgvYDMe","AwXK","x3jLy29UBMu","rLvNBw8","B0PTEhe","C29Tzq","s0XJs2q","BfrcsKq","u2vYDMLJzvC","BenOD2u","C1b6wwq","CMv0CNLdB3u","EKHst04","C3vIyxjYyxK","Cu9cy3e","ALD6su4","yxKSig5LDhC","uNbgwvK","Evz4Efi","Ec1TC2CTy3u","ywXSB2nvBNm","ChvZAa","AhDIEfe","twHxtLm","sNHSwhi","Cw5cD2m","ihzHBgLKigq","AwvcBfu","CMTLCKDSB2i","Dgv4Dc9Qyxy","CxPVzgu","igXHCMDLCIa","DMvY","zMzLCG","ign1CNnVCIa","x2TLEvbHDgG","teH2Cfu","v3DKrwK","zxH0zw5ZAw8","wfvMAK4","y2zozwO","B2nRzxq","DLvwEfq","reiGzMfPBgu","y3vYC29Y","qKvju2u","AxvTCg8","AxL1D1O","y3jLyxrLtwu","C3rYAw5NAwy","Dg9iyxnO","z2v0q3vYC28","y29UBMvJDeu","zg9Uzq","vvfzrfq","mNWWFdn8mxW","y3jLyxrLt3a","igzPzwXKoIa","zfzzA2S","wePpq0G","AxnszwfKEq","B25TzxnZywC","ywDLrxzLBNq","ugfYtgK","u2Pes0m","A2v5","EuLZwwS","tMvzs1K","DxrMofDYAxq","rxP5zvq","x3fVC0rc","DKnMAKu","CKXlsuK","mxWYFdb8nhW","zMLUza","yNL0zu9MzNm","ugrcBgy","zxjYB3i","s2jVreq","y29UBMvJDa","C3nHz2vfDMu","sNLbwvC","DhLWzq","z05IAuW","zxq9DxrMltG","C1vSuMi","yK5Wqxm","BLP4rwG","Cw9HDhK","u2D6C2i","s1DttwC","B25nzxnZywC","BgLUzw5V","CufgB1O","EKPNC0q","r1fRCui","AwXLtMfTzq","y2XVC2veqG","B0XAyvu","ywXSq3vYC28","tg9Nsuq","CMvUDevUzha","tvzhANK","y3jLyxrLrwW","CM9YrxzLBNq","vNv1z0m","z2rKrwu","AhfQzLa","tLHYqLC","r0ryz1q","vgfN","AgPAtvy","yNvMzMvYzwq","x2n1CNnVCK4","wLr2z2q","BgvUz3rO","rw9KDxC","CMfTzq","CgfNzxnOB3C","wezPsg4","Bg9NsurozxC","DgDmu1a","CMPOu2W","we1SA0S","tLjLquO","x2HHBMrSzu8","wKP3u2i","CK1XyMO","vwDRwNy","B25JBg9Zzq","tfDRs3a","y2D2uLG","BwvZC2fNzq","ywngtKe","s0rdveq","D0n4A3e","t0DvD3q","r1v0re0","y3nfsuu","zgzHD0i","s3fAENO","rgXiyvm","Cg9PBNrdB24","ChLzq2i","DgHlsgm","wMrPseO","x1fVu01HBMe","ywXPzcb1CMW","tNj3B1O","rvjst1i","Ef9MCM9UDgK","EvHsCgO","A2DRBg4","rxDov2O","ELjtEwW","zu1duLG","quHxrwC","DgHLBG","Dg9oDw1Izxi","DLjzyLC","BLffzgK","Dg9tDhjPBMC","C1rOsMu","C3bSAwnL","AKTmyK8","zxjFAxnFywm","vxjJqNO","s0vnBKK","vxLprgG","CMPKq0e","vNj2qwq","D2LWr1i","sgnnyNK","yw1L","yw5Hz2vY","vgroz0i","mxWZFdL8nNW","rwvJtKu","CNjRrNe","uMvJB25Uzwm","v21Owvq","icSG","BwDfqKK","DhjPBq","wuXWv2y","svnqsgi","EvbIv3O","tw9KDwXL","rNvXswS","z1rXuem","zxjYtM8","mtm3nJu5mK1izMrHwa","zxjYtxnN","Bg93","yw51Ce1LC3m","x2vUzhbVAw4","zgvSzxrL","ugzmy2m","ywnRx2LK","yunKzKS","wKTYvMO","y2zyEuy","AuD6B3y","ALbJy3m","AfbywwS","A2viDMG","D3jPDgu","x3jLywr5q2W","x21LC3nHz2u","x3bPBMDqB24","sNLVAK4","twHSAee","yxnZAwDU","uMfVweW","D3zIBeq","tMjSCuW","wNjNywq","Aw9UvgLTzw8","m3W0Fdf8mNW","qLr3zwq","zefArNC","qw1VDw50","CgjICdi","yMLUyxj5","Bg9IywXty28","zuTQsNG","mJaWndi5r0zwrxDd","q09oveLovuu","CgHJCwi","rMfbthG","rvr2CuW","AwHuuwK","uLfsBve","Ehz3ve0","BM5ACwy","x2rPC3bHDgm","B3fHy1m","Dg9hzw5LCMe","CMvWBgfJzui","DcbSAw1PDa","BNruCMLLC0m","DK5VDKS","AwX2zfi","vNjgrKC","yMfJA3vWigu","BwvZC2fNztO","wuLZuxu","DuzKAhK","q0j5ueW","DLjqA1m","ChjVy2vZCW","uhjPBwfYEuS","C2rfzwy","tfjMBwq","m3W1","Cw9Zx18","zLnsrxu","ihzHBgLKihm","Dunxyum","Cgn2BxK","wu5rs1O","zMT4ufm","C1zmqMW","Ahr0Ca","su5tvefova","CMvJzxzPzwq","vvvnrvm","tgHuBvK","qKT3B1O","x3nLCuLK","B25szwnLAxy","zezfz3O","yLfpD2i","y29UBMvJDfm","BMrWB2LUDca","DuLpBvi","CgLvD1O","B3jL","B3bLCNr5tMe","zcWG","zwPwD24","C0Xf","BNjvs3q","qvniuwO","y29SBM8","uwLxB3i","zeLJANi","BLrdrLy","wejxuKm","q01JBKC","x3DZsw5ZDge","AxDtvK4","ugzvBe0","BwLZzq","C2fNzq","wM1ss0K","B25SAw5L","Dg9mB3DLCKm","uxjswuG","Cur4wKC","B3jsvxG","vwrIsgK","B2zMBgLUzq","Dfv3BwO","uLLoCum","AxnmB25N","AhvhEvy","x194x21Zz18","A2fADKO","zuneELO","rgvKAwnHDgu","rM10A2G","y1j3A1e","terHEwy","BKXPBMu","shHXwu8","z2v0qwXS","ChPZv2K","B2fK","AuL5vfO","uNzSugu","Aurqz04","ywjVCNq","ve5wwMG","C3rLBMvYCW","sefcz1G","AKnhu3G","CMfTugfYyw0","B2L3uLy","rvbRzeO","rwrQywe","t2XAue8","uvLLueW","x3jLBw92zvC","DejttvC","CMvJzwL2zwq","B25ozxr3B3i","zv9ZDwnJzxm","BKfKq1G","Ae1LC3nHz2u","y3r4","BeTbzvC","yxjYyxLIDwy","yML2zLe","BgLVDxy","mJeWotjKDfvLC3u","y2HnyxHdB3u","rxzLBNq","suvtx0vsuK8","CgXLyxnLiha","zfDYqxO","B25tDgfYDfi","DvjICMG","tejjs1i","x3bYB3rVy28","zw5fDMvUDa","uhfMugS","veHUs2G","wNnIr3O","rfvQqMm","BMv3vMvYC2K","x2zVCM1HDeu","BezSDxnO","ywXS","zgLZywjSzue","EezmA0C","BwDluNO","A1bPwuK","mhW1Fdr8mxW","zwvLDxO","AevuCey","wLbivuK","Axnby2TdBgu","B1DuDvm","z3P0D1u","DMjszfC","wxrct2i","u0TSALK","vwrpBwK","ALjxrLm","ANDyq0W","y3vYCMvUDeK","ufjkAu0","uMnhBwS","vhHUB3K","CMvHC29U","whPXELO","CgLUz09Uy2u","y29UDgv4Da","zMXVB3i","Bgz3tem","qK9hC24","De1HBMfNzxi","mdaWma","DMfSDwu","EvPyu0y","rwrzEeK","mxW0Fdb8mNW","D0HOzee","Aw9Ul2PZB24","q0j3EM4","zgvJB2rLzey","BNrLCG","AenSB3nLrxy","wKLcyLe","BLjxEfu","vxv6Awu","tLz3wwK","D1zpq1m","id4G","sLnptLa","wMHSAhC","vKz2C28","u0Dzs3i","EvrNt1K","u2nZz3a","tvnMBfC","x2LZv29YA2u","q1jTsvK","CeLOtKy","AfLmsMy","CMvZzxrfBMq","C29YDa","CM92AwrLige","wejRzKG","re5iAxe","yMLUza","BfrPBwvVDxq","txnRDKW","ChrjrgG","t1bftL9fuLi","rMPovfi","Ae5kDg4","uNLdshy","lcbxzwjtB2m","BwvZC2fNzv8","qKfzCfO","zw5NDgG","zgvMAw5Luhi","CunMEfy","zwrOEK0","DKvvu2q","wwX1t20","wfPRB1a","u3zctMu","Dw5ZAwDUzwq","BMrWB2LUDfq","rgDVr3G","zMDRBxa","zxj2AwnL","BuPmtNK","yw1Lu3bHy2u","ywDL","uKvrBxq","BgzKrg4","vunWEwq","yw1LoIa","CMvZzxruCMK","twjPqLC","y09Wzw4","x2LUAxrqCM8","s1zVz3q","zgvS","CgnwA20","zNjVBNrPzxi","CfbZr2i","y3vYDMfSDwu","zw50zwqGDhK","Dw5KzwzPBMu","ue9Qwg8","zeXIwMW","m3WWFdr8mxW","x2rItMfTzq","s0XdB2u","D1vyuKW","B25tDg9Wsw0","r0fKChe","A1nwsuy","zwn0","Dvnxy2u","tfboA0C","uvbnvLC","r0jUqLO","zg5KqNm","zcWGDw5RBM8","DgXACe4","ugPgEuK","Aw5KzxGGB3u","EfzlyMC","B1r6s0O","sMnMu2q","v2LUzg93","ugjKEgq","zv90Aw1LB3u","AfDhwgu","DhDVCMTdAge","yuTgquy","D2vI","zNPYAgS","CxDKBfG","ALjQvKK","AeHpuxa","sfnczfe","EgnHANO","DMLTsMi","BxbYvum","uKLVCLC","BwLUAvbYB2C","zufJAW","ww5treu","DhjeuNO","EvfdENi","sejPAg8","zw5JB2rLrNi","wNvAwKS","qMjIq3y","twv6CxO","mJyWmJC4oePSAePxza","x2LZtwLUAvC","Bw1hvee","CNnVCL92ywW","CNzHBfzHBhu","B3LkAuW","C2HPzNq","vhfJsNG","yxLQy2W","CM92AwrLihy","twLZC2LUzYa","te5jC3G","y2zPBeO","seL4CM0","AuT3Egi","nteWndvTELv6EMC","AxnAzxjV","Evzxrg8","Dg9Y","A0LjDMC","nhWZFdj8mxW","DhjPzxmGCMu","EK90B2K","DeLUDgvYy2u","zgj2Deq","x2nVBM5Ly3q","DxjS","EfvZzuvUDG","CgLUz0LUDgu","y3vYCMvUDeu","u0j2CKW","rfPbBva","zM9cy3y","Bg9N","z1P5Eg8","B3b5CuK","yKPSv2G","zcbLCNjVCI4","CLjnEve","BuPIzeG","vLHtrxO","uMvxCfG","u05Wt0W","yKfOEge","DhjrCwK","u1npqLy","C1Houu4","ChjVDg90Exa","zvvYBa","wenywxK","zw50","CNnVCL9Uyw0","vevJr3q","tMfTzq","ugL3ENy","Bxvwt1q","C0Htugy","u2LtsxG","EfPQCKK","A3vVAhu","qNnhvwK","A0P1zxG","BgLUzq","ywr2yw5Jzq","Dw50","D2vlA2G","AwPOBhC","wffZt2K","zxH0ugf5Bg8","zg1XsMS","zKvpBKO","C0XPC3rLBMu","z3jIvKK","qNbmDgS","vLLqB3C","D2fZq2XLyw4","CxHmz2O","CLLwu0O","DLfkzw4","s21OvwK","ALniwKG","tuvtu0fhrv8","r2zQA0i","zKXhrxK","FdD8oxWZFde","EKjOteO","CwvLtNC","Bwf4tg9ZC0m","BwvKAwf0zwW","ywnRpwzYB24","svbyB0m","BhrPCgXLihq","thjHDee","vefIvwy","y3vYC29Yx2y","Bfn0wfa","AgvHzgvY","s3jtr3m","DxDOshi","yNL0zuXLBMC","q0rptgS","qLDbAuG","x29UugfNzu4","BvfpDgy","vevnqK0","wMDnvMi","wLLKAu8","BgLZDgvUtMu","z2vY","ywT6uKC","BeHHBMrSzxi","uMzJBeq","y25uvMm","rwLbvvG","zwrPyxrLBhK","Aw5N","CMvZzxrdB3u","shjYs1y","B3bpuMe","tvbyALu","qwrnwMO","yM9cELK","vxbTBLy","C2v0sxrLBq","wxnqEwi","C3bSAxq","uevUBxy","q1LZvMy","B25Uzwn0Aw4","zMX1C2HfEha","nZe1oduXmgfuzNvgCa","wwnTuLe","AhrMCwm","zMvY","CvLQq0C","sw5lzeS","Agj2twC","AhrTzMm","C2DPza","rKDtuxi","y2HnyxHuCMK","AxjLza","C2v0u3rVCMe","u3rYyxrLz3K","r0rhyw4","zw5HyMXLqxu","zxrxB3jRq2G","zKTAtNq","AxnrB1nnzxm","tKDFrvjst1i","y2f0y2G","A1n0yxr1C0m","ze1YzKi","v2vIu29JA2u","thrmDha","C2v0","uenHreW","ihjLy29UBMu","Dg9cExrLCW","tuX0zMq","Cfj2BMS","Aw50zwDLCIa","B0rpq3a","CxLYy1e","Aw5PDcbrB1m","y2fSBa","uuz3q3q","t2DsBhC","BMnLq2XVC2u","zgvIDwC","qvrkzum","CMvZB2X2zq","vNbsEfm","DMvYC2LVBG","uhr3wMi","sMDpDhO","shjXAum","Ehzdqva","zKTRqxy","CMzSz0e","v2TVshe","BMfTzq","zNjHBwvuExa","AgfUz2u","BIWGAg9ZDg4","Bg9Nsurhzw4","ihrPBwvZ","DhDXBM8","y2jpA2y","uLfdBei","ywnkExO","AhP0vfC","rg5UzwK","x0rctMfTzq","aaaaaaaaaaa","BvDVBuC","zwfxt08","x2LZqNjVD3m","yMXVy2TLza","sxz5rxu","D1HoCxC","CgLUz0XVC3m","DhjHBNnHy3q","tfz0CfC","z3HpAgS","wK9rveS","x2nSzwfYugK","ENbbEM0","yNLL","CNzHBa","BwvZ","veHryvK","rKLuwxu","B2jQzwn0u3q","qKLMve8","v291qNC","BM5Ly3q","Bxbry2W","AvPYv0i","ruX6AwK","BeDxDMC","CMvHzhLtDge","vuHLque","qxv0CfG","y2PPBu8","CMvHzg9UBhK","AhDcq0y","Dvz1yLm","rKDWrhi","t2PlDNq","uKT6wwi","C3rYAw5N","qKnMwgW","uMHSCxu","wgHvyvC","Dgv4DfbHEwW","wxfYAMW","quXMs0q","uuDvBhG","zhLoAg4","tKTcBK0","BKHktM4","ueffqwS","q29UzMLN","yxv0B21HDgK","qxPJuhy","x21PBMLoyxy","y29Uy2f0","Au1zvgy","rwvrAg4","igzHAwWSig0","svn1qLy","x29UrxjYB3i","AevYCM9Yrxy","C0fXt3m","mxWZFdr8mNW","BgP5ze0","Bwv0Ag9K","wfzMr20","zw50tgLZDgu","vMnXvvO","zNjVBuj5Dgu","Ec1TC2CTCw8","EffOuwi","D3v1tu4","ANfSyMG","v3btEwe","lcbOB3n0BMe","z3buuwW","mNWW","v05rAfa","BNrfBMrWB2K","B25dBg9Zzq","Dg9TD2K","nxW0Fdj8mta","DLPisKm","vLPSzeq","u2HHCMvKv28","wNvXA3m","veXfs2W","BMv4DcGPigm","zxHWB3j0CW","rgjKwKi","vLLkvhy","y2vZC0HHBMq","x2XPC3rLBMu","x2LZsw5PDa","CuLQzgy","x2rLyNvN","CMvHzhDYAxq","ChrVCG","x29Ut3bLBG","uuH3EeO","EKnuA24","ysbTDxn0igi","s2P5v08","x0vysvnu","ywWGy3vYC28","Efrurw52","reLSyxa","y3vZDg9Tshq","x29UtwvZC2e","zw1LBNq","wxbgCu0","A1vVq3C","veXvqK0","AgrOuhi","vKT0z2m","s0v0sgO","yKPuwhm","ve9xzfG","A2v5CW","wevesLe","vgvtuhC","ueHYsMm","BMDLza","rgLSveu","thvrC3G","q1PpBwW","v0ncwu8","DxbNCMfKzw4","ChjVDg9JB2W","yvvPEu4","s2ftDeG","AMvJDfn0B3i","Dxrjza","CfDOvw4","CgfhB0O","AgfZt3DUuhi","B2nRzxrgywK","zhnHq04","C2v0r0W","zuLyyM0","tg1SB0y","EwfpuNy","Cef2v3K","yw5Nzq","ihrPBwvVDxq","yxnL","Cg93","DgLTzw91DcW","rgr6t24","vNrhDMi","z2P3u3q","Dg9cExrLC0i","CKrvy1a","zeLNqvm","D2vOuu8","uLjpuG","BfPlrNm","Agn2Dui","vNPJDvq","v2v3AMq","zeDsA1y","ywrK","sejvC2K","tuPODhi","x3bHDgHlzxK","rfLSr3K","A2v0ignVBNm","ANzzyvm","B3vUDa","rxjYB3jdB2q","r0Hiy1K","Cw1YyMW","s1fVBLe","AwXSihvZzsa","B0j0t1y","CMvQzwn0","wu9zvu8","zNjVBujPDhm","x2fKzfDZtgK","thjWwhO","DgvZDa","BKHcyLm","Cgu6ia","mxWWFdj8m3W","refeqNq","ChrJA3u","tgHyA3G","wwPZwvu","uePAsLq","BxnN","B25pCgvU","y29UC3rYDwm","D3LvqNy","vwThvNy","txHzDuO","ALDZr04","D2fuu28","q09otKvdveK","uKrpquq","wwv6zgC","uuDPB0O","r1b4teu","y1z0tuS","EMLrBu0","DgfYz2v0","x3bPBMDmB3m","D1HZvNG","s3ndzNe","uvrOrKS","vgrgAKe","C2vYDMLJzq","A2HbwgK","C1rQC20","lcbTyxGGCMu","mxWWFdz8ohW","swL2DgO","u2vXsuq","Bhm6ia","qKfouhK","whDjrge","rufdDKS","B3nLza","tg9JAW","s3bkq0O","t0ftq1i","yxrHlcbKyxq","u3PmvK0","t2DOA2O","zNvUy3rPB24","zxjFywnRx20","zwDqtKy","AgfZ","mMzvv09pqW","EeDICLy","qwLfru8","ww9jBuC","BvDbsxy","qwLOAMS","tKfusvzfx0u","yMfSrxzLBNq","zeHRyuS","CMLLC0nVDw4","x29Uq2XVC2u","BM9Uzv9UB24","wwPurMi","BNrbBMrvCgq","Chv0","q3vZDg9Tq2W","rvzHqxq","ywDLsgLKzq","AxmGDw5Kzwy","x3DHAxq","yM9KEq","qLLvu0W","x2jPBMfYEvq","Bwf2v1O","C3rVCMu","uxnrC0C","Dg9cExrLC0W","ru14rva","ywrKrxzLBNq","sKf4qMC","uvj2vMK","y3jLyxrLrxi","C2vYDMLJzs0","DgfIyxnL","D24GCMvHC28","Ehfprgm","AwTvtKy","CYbWyxjHBxm","AgvKtwf4uMu","DgLLCKPtt04","DxnLCKLW","AgnhzeC","v1Dhwfy","qw9Qs1q","CMvHzfvjBNq","AxnrB1nby2S","tNjku1K","tKDzCfm","C0jzy1m","DxjewuW","pxv0zI04","DMHtteG","rKPWq0u","DgvmB2Djre4","CMvTB3zLq2G","y2vKC2y","q1zPr2W","vKX2CfK","B3nLrxzLBNq","DLLfq1K","x2rPC2nVBM4","y3ruAw1LB3u","C2vUza","CNnVCKzPBgu","Cg9PBNrbBMq","CMvTB3zLrxy","x2LZtM9Kzq","zfb4CMK","EuvtvgC","tg9NsurozxC","rwnWu1a","B3bLBKrc","qKTjvKu","wwnwswO","yvrxDue","Bwu6ia","qKPjzey","C2v0zgi","zw5KCg9PBNq","C3PiAwC","Dufitxm","y3jLyxrLuMu","BNbRuvC","y29UDgLUDwu","ywDLu2HVDW","vgLTzw91Da","u1fIEK0","C0jf","AgvHzgvYCW","zKPeCgC","Dejyr3y","Aw9U","vu1gwxO","y2uGBM90igK","Dvjxt0i","q0Xpu0ve","qwjVCNrfCNi","m3WY","rNjVBNrPzxi","txrgDxy","vunluhe","uMnIs2S","CMvKDwnL","Aw5Lza","BML0AwfSAxO","B25mAw5L","DxHcsg8","D3jPDgvvAw4","D0vpq2i","thjHzuO","vxzqvw0","CxHzuK0","Cgf5Bg9Hza","ChbL","x2LUAxq","qvHQAwe","zMLSzw5HBwu","y291BNq","y01JEMW","qNrRteG","x2HHBMrSzvi","DxrVuMvJB24","r0Lpt1m","ANbpq3K","AMfbteG","ywzL","CKnxAuO","ndG1weXREKjW","Egr4tLO","BwLkzxm","vKfhAKK","C2vYDMvYvgK","EKn6yuy","s1fwr1u","qKfoy20","rgX2CeS","CMHsDKm","D3neuuK","EKHKv1i","u1fIENa","vMXiz3i","z2v0qwXSs2u","Cxrir1O","C0nVDw50zxi","y29TCgXLDgu","vK1eAxG","qLPQAwG","uw5lCe4","A1jwuvO","A0PMAwK","vw5PBxbSzw0","EufYEeS","vMnvAva","C1Ddv2G","ufbsuM8","BgvY","BhLgrwG","tLjMteO","A1f1ywm","qvrrs0y","Aw5KzxG","vMvlCwW","t1zvzwi","CMvZDwX0","x29UvgLTzw8","AM9PBG","x2DLDeLUDgu","yNL0zxm","Cgf5Bg9Hzeu","yKLvqK8","rejJuxq","BePoDuy","CYbHBhjLywq","u2TPCcbWyxm","swntENa","y2HLy2Tszwe","rLj6CwO","CLzHBhvLCW","tMHwsvC","ywnOzwq","sxjOEKi","x2LUAxrhBg8","z3HyveO","B2X0DgC","re9nEKm","r1r6y20","x2n1CNnVCK0","zxjqqvG","rfLYrha","zw5JB2rPBMC","yvLMrvi","y1zxCu4","CIb0DhDjra","Aw5KzxHpzG","A1DlCMe","Dvj5A2u","CuDntxa","tu9gzLm","zgv2AwnLx2K","yxbWBgLJyxq","BMCGDxjSoIa","vw5Oyw5KBgu","zLf4zMq","BLDlBLa","x2rYB3bhBg8","DxbKyxrLq3u","q25ouxe","BgnOD0G","x19LC01Vzhu","BvzTz3i","ruLOthe","B25LCNjVCG","CM92AwrLihC","yxbWBhK","C1nSyLK","DurWuKW","Be5Ly2q","jMPZy2fSBgi","D01QzKe","x2rLC3rYB3K","B25VCgvU","uMvHzcbWyxm","quLXBM8","AxnFywnR","yMrYEeK","BNbdD28","C2XPy2u","qwLUzgK","uhDAAuW","CMvWBgfJzq","uvfLCw0","zw1PDa","t3fYBM0","sNLequ8","EvDYs0i","Dw5RBM93BIa","BwvY","CLnes0C","sNPnEfO","y2XLyxjtDg8","thD4r1O","BM93","q0nRDu8","Dev2zw50","C3rHCNq","EvHQzfK","Dw1JA3u","DgrXwu4","y3jLyxrLt2i","EeLfAgW","r0nHAMG","DNvKsxm","C3nvyMq","BNDyDM8","ENjyC3q","ywnOzwqSihC","Cu1lvKG","zw5eteG","yuzKuxq","EvjLy29UBMu","vffZtKS","EgH5we4","BMCGzMfPBgu","z1nUse8","vNHsv1i","t1HgBuu","y3vYC29Yx24","AuztzuK","z2v0u3rVCMe","Ec11C2uT","z2vrDwv1zuW","EsbJBg9Zzwq","u2TTB2e","x3nLBMrby2S","zMzmAw5L","AvvwCgC","yM9L","Bhbuwwm","zw5HyMXLuw8","C2v0y3vYC28","thLiC2i","B2nRzxrtDwm","x3nVy2TLDa","Bwf4uMv0CMK","y2HHCKnVzgu","wgXbvhO","DgXmBxm","ru5ptMK","BNvTyMvY","tLDYwxC","AMPZvg0","CMn2v3e","u1jKuhy","seDhAgC","B3jLtMfTzxm","z0jAAxa","x3vYBa","y1nUDgW","BMvJDa","svfYuem","zNjVBuHHC2G","DgzhrMG","twrhC0q","u3HewNy","uKjeDvm","zgrjrcWGzgu","y2XVC2u","zxmGCMvHy2G","BgLTAxq","rLDt","tfvpELa","y2XVC2uSihC","txrYuwO","ExrkDvy","sLbHAwy","tNb2Dvq","CNvcqwC","shzOBey","yxnJCMLWDa","ywnRDxbfBMq","yxfxzvu","t3bLBKv2zw4","wwjJD2i","C2v0q3vYC28","x3DZ","AgTVCuG","BMvY","CKfvy08","zKXyAxe","v3Lxufe","zNjVBunOyxi","reTdD2S","Aw5JBhvKzxm","DvHYufK","yxbSyuS","yw5ZzM9YBvq","B3bLCNr5","zgf0yq","BMCGB3iGyw4","zLPmrNO"];return Xo=function(){return t},Xo()}n1(Bh,{deleteDB:()=>u1,openDB:()=>l1,unwrap:()=>ns,wrap:()=>zt});function l1(t,e,{blocked:n,upgrade:i,blocking:o,terminated:c}={}){let d=M,u={strfC:function(g,w){return g(w)},ubtal:d(1062)+"4",htmfc:function(g,w){return g+w},CViGl:function(g,w,v,_){return g(w,v,_)},VFvso:function(g,w){return g!==w},sSlbY:d(1646),CyjYr:d(1417),BTwed:d(1529)+d(869),hNJtn:function(g,w){return g(w)},RYNqC:d(1006)+"eeded",qkKpr:d(884)},x=indexedDB[d(1477)](t,e),h=u[d(601)](zt,x);return i&&x[d(1139)+d(1503)](u[d(473)],g=>{let w=d;i(zt(x.result),g.oldVersion,g[w(529)+"on"],u.strfC(zt,x[w(888)+"ion"]))}),n&&x[d(1139)+d(1503)](u.qkKpr,()=>n()),h[d(326)](g=>{let w=d;if(u[w(581)](u[w(1325)],u[w(1325)])){let v=u[w(1618)][w(811)]("|"),_=0;for(;;){switch(v[_++]){case"0":if(_0x37c5fa[w(284)]<40)return u[w(823)](u[w(1167)](_0x2d02fa,_0x2cb689,_0x1727be,_0x277521),_0x3ce238);continue;case"1":if(!_0x3a93d5)return _0x2ea039;continue;case"2":if(_0x234e95[w(237)+"e"])return _0x17fb79[w(237)+"e"](_0x2cb5f4,_0xfde881)+_0x5801b5;continue;case"3":if(_0x559880[w(375)])return u[w(823)](_0x239172[w(375)](_0x36aaf0,_0x17887f),_0x162f32);continue;case"4":return u.htmfc(u.CViGl(_0xcf5a6,_0xb8e7c1,_0x26c458,_0x133349),_0x388f72)}break}}else c&&g["addEvent"+w(1503)](u.CyjYr,()=>c()),o&&g[w(1139)+w(1503)](u[w(388)],()=>o())})[d(836)](()=>{}),h}function u1(t,{blocked:e}={}){let n=M,i={XJOCH:n(884),DbdZB:function(c,d){return c(d)}},o=indexedDB[n(1518)+n(1144)](t);return e&&o[n(1139)+n(1503)](i[n(228)],()=>e()),i[n(968)](zt,o).then(()=>{})}function Oh(t,e){let n=M,i={mprUC:function(x,h){return x-h},qoaty:function(x,h){return x!==h},TLUBM:n(643),RyCHv:n(911),kJfii:function(x,h){return x instanceof h},JPaif:function(x,h){return x===h},Sgzsb:n(917),lvmPE:n(183),UrcBz:function(x,h){return x!==h},IQONj:function(x,h){return x in h}};if(!(i[n(1260)](t,IDBDatabase)&&!(e in t)&&i[n(1425)](typeof e,i[n(258)])))if(i.lvmPE!=="qOBcq"){if(_0x42c809[n(284)]!==4){let x=_0x36bd5b[n(1580)+"g"](0,i[n(674)](4,_0x6c2798.length)),h=x[n(933)](_0xcb81b);_0x4f46ee.push(h)}else _0x303961[n(190)](_0x30414a);_0x16b768&&(_0x362435+=1),_0x523ab1+=1,_0x23f8ad=!1}else return;if(Vo[n(1575)](e))return Vo.get(e);let o=e[n(1340)](/FromIndex$/,""),c=i[n(335)](e,o),d=zh[n(1443)](o);if(!i.IQONj(o,(c?IDBIndex:IDBObjectStore)[n(733)+"e"])||!(d||Fh.includes(o)))return;let u=async function(x,...h){let g=n;if(i[g(257)]("zvHdp",i[g(991)])){let w=this[g(888)+"ion"](x,d?g(975)+"e":i[g(602)]),v=w[g(1135)];return c&&(v=v[g(1271)](h.shift())),(await Promise[g(532)]([v[o](...h),d&&w.done]))[0]}else this["_cursorF"+g(265)]=_0x5926d9};return Vo[n(841)](e,u),u}var Fh,zh,Vo,f1=Nh({"node_modules/idb/build/index.js"(){let t=M,e={XUfjN:t(537)+t(1208),jpOCy:function(o){return o()},YNwgn:t(1040),CByPL:t(365),vimJb:"clear",AXjia:function(o,c){return o(c)},JyojN:"getKey",VuugC:t(1252)+"ys",qjpYe:t(1228),pcvmy:function(o){return o()}},n=e[t(208)].split("|"),i=0;for(;;){switch(n[i++]){case"0":e[t(1234)](Dh);continue;case"1":zh=[t(1125),e.YNwgn,e[t(417)],e[t(673)]];continue;case"2":e[t(1226)](a1,o=>({...o,get:(c,d,u)=>Oh(c,d)||o.get(c,d,u),has:(c,d)=>!!Oh(c,d)||o.has(c,d)}));continue;case"3":Vo=new Map;continue;case"4":Fh=[t(1575),e[t(379)],t(485),e[t(274)],e.qjpYe];continue;case"5":e[t(428)](Dh);continue}break}}}),x1={idb:function(t){let e=M;t.exports=Promise[e(857)]()[e(326)](()=>(f1(),Bh))[e(326)](function(n){return n})}},Lh={};function Ft(t){let e=M,n={vudIs:e(640)+"2",IfWkQ:function(u,x){return u!==x}},i=n[e(1362)].split("|"),o=0;for(;;){switch(i[o++]){case"0":if(n.IfWkQ(void 0,c))return c[e(967)];continue;case"1":x1[t](d,d[e(967)],Ft);continue;case"2":return d[e(967)];case"3":var c=Lh[t];continue;case"4":var d=Lh[t]={exports:{}};continue}break}}Ft.d=(t,e)=>{let n=W;for(var i in e)Ft.o(e,i)&&!Ft.o(t,i)&&Object["definePr"+n(1447)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=M;Ft.o=(e,n)=>Object.prototype[t(1014)+t(1447)][t(851)](e,n)})(),(()=>{let t=M,e={qgmiR:function(n,i){return n!=i},qYjCG:t(637)+"d",FaKDq:t(356)};Ft.r=n=>{let i=t;e.qgmiR(e[i(820)],typeof Symbol)&&Symbol[i(330)+i(279)]&&Object[i(607)+i(1447)](n,Symbol.toStringTag,{value:e[i(1662)]}),Object[i(607)+"operty"](n,i(1319)+"le",{value:!0})}})();var De={};(()=>{let t=M,e={yIsYk:function(a,r){return a+r},rOOMq:function(a,r){return a+r},bAhxa:function(a,r){return a+r},hMdOt:function(a,r){return a*r},wOnGR:function(a,r,s){return a(r,s)},FGSQr:function(a,r){return a(r)},HBiho:t(1417),dwCji:t(1529)+t(869),cfilJ:function(a,r){return a!==r},RTiPa:t(937),xdxNZ:"izZns",HGGhg:function(a,r){return a+r},tCphh:function(a,r){return a(r)},OjKvt:"0000",waTSo:"ffff",ijhlw:t(1594)+t(1594)+t(1594)+t(1594),fzrhk:function(a,r){return a===r},qGMMp:"send_ack",BWAiH:t(1530),UQYDT:function(a,r){return a>r},IKpaK:t(766),OXFmE:"FAmsW",sdEef:function(a,r){return a<r},PJJEP:function(a,r){return a<r},KLcKd:function(a,r){return a-r},QRvVi:function(a,r){return a-r},KLCoe:function(a,r){return a<r},PAEAk:function(a,r){return a<r},PCaDL:function(a,r){return a-r},tmDmg:t(1346)+t(554),hrbHd:function(a,r){return a!==r},VYJTv:function(a,r,s){return a(r,s)},hwBCF:t(1431),KaStH:function(a,r,s){return a(r,s)},Jizco:function(a,r){return a(r)},npkQW:function(a,r){return a(r)},bJlWh:function(a,r){return a(r)},nwXvo:function(a,r,s){return a(r,s)},kgkln:function(a,r){return a(r)},DlvpK:function(a,r,s){return a(r,s)},iZrWB:function(a,r){return a&r},paGoJ:function(a,r){return a===r},niTzG:t(696)+t(1516)+t(226)+"key",iyHQU:t(696)+"required"+t(226)+"value",UpmnV:function(a,r,s){return a(r,s)},AiEEO:function(a,r){return a(r)},qDxZG:function(a,r){return a(r)},gjwSt:function(a,r,s,l){return a(r,s,l)},hcGdG:function(a,r,s){return a(r,s)},ZPHUI:function(a,r){return a!==r},QnKpN:"YbiJp",cSntl:function(a,r){return a!==r},XlATz:function(a,r,s){return a(r,s)},pREPl:function(a){return a()},SjDKC:function(a,r,s){return a(r,s)},yPbWz:function(a,r,s){return a(r,s)},lNxBv:"JBlFh",uCWaC:t(422),EecNE:function(a,r,s){return a(r,s)},UgkZv:function(a,r){return a!==r},OlZPO:t(278),bNpAs:function(a,r,s){return a(r,s)},sBaXw:function(a,r){return a!==r},oFrHG:"wQLgv",KmhUi:t(1436),gxOhk:function(a,r){return a>>>r},KjyWO:function(a,r){return a(r)},rYVSJ:function(a,r){return a(r)},XhUaW:function(a,r){return a(r)},CDOLk:function(a,r,s){return a(r,s)},EPkdJ:function(a,r,s){return a(r,s)},QGUlx:function(a,r){return a(r)},YQaxG:function(a,r){return a&r},OkHGx:function(a,r){return a===r},ziQmM:t(696)+"required field: "+t(1095),UCKPq:t(696)+"required"+t(226)+"LogID",qeeNw:function(a,r){return a===r},wwFFE:t(696)+t(1516)+t(226)+t(1089),khAXi:function(a,r){return a(r)},VrvAd:function(a,r,s){return a(r,s)},HABgX:function(a,r){return a+r},YtBOb:t(1261)+t(636)+t(1061),YNQKZ:function(a,r){return a>=r},jaALH:function(a,r){return a===r},wwKxa:t(1397),wEOCb:t(1115),XzqzZ:t(1284)+t(408),CZOml:function(a,r){return a>=r},rMqbj:function(a,r){return a(r)},ihTQi:function(a,r){return a+r},DNHiq:"yXjdY",wHhdA:function(a,r){return a*r},yTgOY:function(a,r){return a>r},Yqrjl:function(a,r){return a!==r},UULdO:t(1229),LwxGZ:function(a,r){return a>r},tJwcD:function(a,r){return a+r},zWtvV:t(1332)+t(408),cngnN:function(a,r,s){return a(r,s)},QHwxJ:function(a,r,s){return a(r,s)},lChwe:function(a,r){return a(r)},XVfGm:t(399),mavWZ:function(a,r,s){return a(r,s)},vRYbW:function(a,r){return a<r},htfqc:function(a,r){return a+r},sWCWh:function(a,r){return a+r},lpTYc:function(a,r){return a+r},VMDix:function(a,r){return a+r},DBcQt:function(a,r){return a&r},BIfTO:t(728),dzsll:t(1217),UUMES:function(a,r){return a|r},CMlai:function(a,r){return a<r},YsPyb:function(a,r){return a==r},SzLVM:function(a,r){return a+r},iUVpg:function(a,r){return a&r},RQRmQ:function(a,r){return a<<r},hPXYk:function(a,r){return a!==r},GjtpG:t(680),NzALN:function(a,r){return a|r},Rhlqu:function(a,r){return a|r},VZldD:function(a,r){return a&r},wXNqw:function(a,r){return a<=r},ParLi:function(a,r){return a==r},jRjVI:function(a,r){return a+r},vEUSd:function(a,r){return a+r},KsCfq:function(a,r){return a+r},ISPHb:function(a,r){return a===r},MiQYt:t(1667),QQeqm:function(a,r){return a|r},gTqPC:function(a,r){return a|r},qnBwc:function(a,r){return a&r},XZkoP:function(a,r,s){return a(r,s)},ZQgCp:function(a,r){return a>>r},plaJG:function(a,r){return a+r},mgKRz:t(1520),qwdlX:function(a,r){return a<r},urDYL:function(a,r){return a>=r},LhXkx:function(a,r){return a+r},csEIE:function(a,r){return a-r},FjNTR:function(a,r){return a+r},Mezqz:function(a,r){return a<<r},SzmoB:function(a,r){return a<r},JuGst:function(a,r,s){return a(r,s)},PfLcc:function(a,r){return a<=r},NReAJ:function(a,r){return a-r},mWomG:function(a,r){return a+r},yJFMv:function(a,r){return a<r},SGYKr:function(a,r){return a&r},opyqI:function(a,r){return a>>r},TdFjA:function(a,r){return a>>r},dGRkV:function(a,r,s){return a(r,s)},UHeAA:function(a,r){return a<r},GfxNX:function(a,r){return a<<r},lchwH:function(a,r){return a|r},Zrgad:function(a,r){return a<<r},LtLtp:function(a,r){return a&r},ikUNF:function(a,r){return a&r},iXxTH:function(a,r){return a(r)},iwSVN:function(a,r){return a===r},HxqYO:t(862),acJyz:t(845),sBYcS:function(a,r){return a>=r},MOFfS:function(a,r,s){return a(r,s)},NpvuT:function(a,r){return a&r},plrXJ:function(a,r,s){return a(r,s)},SSOBV:function(a,r){return a&r},PziCq:function(a,r){return a(r)},NWrYw:function(a,r){return a&r},Txnoy:function(a,r){return a&r},axKKV:function(a,r){return a&r},wXoJt:function(a,r){return a<<r},dyNhn:function(a,r){return a&r},LratA:function(a,r){return a&r},ITxPG:function(a,r){return a&r},sHSPf:function(a,r){return a(r)},QdZlW:function(a,r){return a(r)},BOGsn:function(a,r){return a<<r},VcUiP:function(a,r){return a&r},VtGvb:function(a,r){return a(r)},OFNjR:function(a,r){return a<<r},IvyEu:function(a,r){return a&r},GIOOS:function(a,r){return a&r},nZxEh:function(a,r){return a(r)},npCwo:function(a,r){return a>>>r},lNecd:function(a,r){return a<<r},sPzYd:t(1055),SQbzp:function(a,r){return a>>>r},dndBs:function(a,r){return a>>>r},WstYS:function(a,r){return a<<r},WNQhP:function(a,r){return a===r},MwfCl:function(a,r){return a===r},RaoXL:function(a,r){return a<r},dWrAz:function(a,r){return a<r},hbvMg:function(a,r){return a&r},ELzii:function(a,r){return a+r},vRPkS:function(a,r){return a!==r},wehQO:function(a,r){return a&r},oyJiL:function(a,r){return a|r},EIhLq:function(a,r){return a>>>r},ptIDh:function(a,r){return a>>>r},MtrQj:function(a,r){return a&r},EeQhn:function(a,r){return a!==r},SRdPv:function(a,r){return a+r},QrRYH:function(a,r){return a|r},TAbUf:function(a,r){return a>>>r},LraeJ:function(a,r){return a&r},ZdiHJ:function(a,r){return a>>>r},orRUx:function(a,r){return a+r},KQonQ:function(a,r){return a+r},lZKFs:function(a,r){return a!==r},cVWqN:function(a,r){return a!==r},FaALx:function(a,r){return a&r},NrJSY:function(a,r){return a+r},jPccs:function(a,r){return a+r},uDpRL:function(a,r){return a|r},CRmIY:function(a,r){return a<r},soHJN:t(1298),YIsQu:function(a,r){return a(r)},uRbrh:function(a,r){return a|r},setGL:function(a,r){return a<<r},iDPgN:function(a,r){return a<<r},iyuwZ:function(a,r){return a|r},JVoJI:function(a,r){return a<<r},VYPow:function(a,r){return a|r},ljydM:function(a,r){return a|r},NRfLJ:function(a,r){return a<<r},zCzaF:function(a,r){return a<<r},QGVOT:t(1179),TEcGt:t(650),foBcv:function(a,r){return a<<r},xxOQy:function(a,r){return a|r},cfXyF:function(a,r){return a<<r},jPhEb:function(a,r){return a<<r},vNovK:function(a,r){return a&r},NXrBW:function(a,r){return a&r},MhWNS:function(a,r){return a>>>r},ejVwn:function(a,r){return a>=r},SQbzM:function(a,r){return a%r},mJbdH:function(a,r){return a+r},gFACL:function(a,r){return a>>>r},qbAzx:function(a,r){return a+r},ruHUa:function(a,r){return a*r},iHQnK:function(a,r){return a===r},ZVQAB:function(a,r){return a>>>r},DdzOn:function(a,r){return a>>>r},opORa:function(a,r){return a&r},zBhLJ:function(a,r){return a>>>r},yaORv:function(a,r){return a>>>r},rjdCA:function(a,r){return a>>>r},aaIPA:function(a,r){return a<<r},CYsVf:function(a,r){return a!==r},zwDYm:function(a,r){return a===r},gSnHO:function(a,r){return a+r},DlHaS:function(a,r){return a&r},rLKII:function(a,r){return a&r},Wewjd:function(a,r){return a>>>r},TOWdX:function(a,r){return a&r},sAqOs:function(a,r){return a>>>r},KboDD:function(a,r){return a>>>r},ZyadJ:function(a,r){return a>>>r},UkjVy:function(a,r){return a>>>r},CZQGb:function(a,r){return a>>>r},QZhRi:"3|1|5|4|"+t(955),VlHgr:t(1076)+t(835),JbJwm:t(599)+"OR",MJhtr:t(1117)+t(1034),RcbKk:t(767)+"ERROR",mJLNy:t(1494)+"IES_ERROR",MVGjy:function(a,r,s){return a(r,s)},EzyeT:"error",xvwTM:function(a,r){return a===r},Xyjvd:"GUbKh",wyUBv:t(941)+"5|6|0",kIIvg:t(224)+"4",UvPUm:t(1631),LrpXz:function(a,r){return a>r},uXrPY:function(a,r){return a instanceof r},PwZiL:function(a,r){return a+r},YcmRQ:t(1312)+t(723),pcVkm:function(a,r){return a===r},AutpX:t(961),ASHQj:function(a,r){return a>=r},yFoLC:function(a,r,s,l){return a(r,s,l)},FlCsB:function(a,r){return a!==r},SxDZv:function(a,r,s){return a(r,s)},dfawB:"open",GlqJu:function(a,r,s){return a(r,s)},Aihjk:function(a,r){return a!==r},XMlkK:t(1595),PJZJT:function(a,r,s){return a(r,s)},QGioJ:function(a,r,s){return a(r,s)},olttg:function(a,r){return a===r},nnZqf:t(1087),ueMCw:function(a,r){return a||r},cfNej:t(637)+"d",pAvWy:function(a,r){return a||r},rrkFq:function(a,r){return a!=r},gpTQl:t(1611)+"t",jWzIN:t(1355),KWSMg:t(215),XBkfH:function(a,r){return a===r},rfCRr:function(a,r){return a+r},sVLBl:function(a,r){return a(r)},rAUcO:function(a,r){return a<r},GUtDM:function(a,r){return a&r},RfclD:function(a,r,s,l){return a(r,s,l)},AzcPv:function(a,r){return a===r},yWrKB:function(a,r){return a-r},dIcjr:function(a,r){return a<<r},dPxri:function(a,r){return a<r},MPXjU:function(a,r){return a<<r},WyWPQ:function(a,r){return a>=r},yOErG:function(a,r){return a-r},wuuMN:function(a,r){return a|r},dmqJk:function(a,r){return a|r},vdUjy:function(a,r){return a&r},Zuqks:function(a,r){return a&r},tomwi:function(a,r){return a+r},iMbbn:function(a,r){return a+r},pIhNF:function(a,r){return a<r},BpLtk:function(a,r){return a>>r},Zgjav:function(a,r){return a&r},BANcm:function(a,r){return a&r},BHeps:function(a,r){return a|r},kaZvJ:function(a,r){return a+r},vbhlS:function(a,r){return a&r},AfcvZ:function(a,r){return a&r},WRXfM:function(a,r){return a>>r},RvlPe:function(a,r){return a&r},KDCTD:function(a,r){return a|r},kZXIJ:function(a,r){return a|r},eIXbm:function(a,r){return a>>r},JgOtz:function(a,r){return a&r},fLXiq:t(917),jErWD:function(a,r,s,l){return a(r,s,l)},QYePL:function(a,r){return a instanceof r},DPOBb:t(1310)+t(568),xqODc:function(a,r){return a==r},CtRdI:t(1676)+"in;charset=utf-8",EjiKR:t(1387),HSBdQ:t(990),YjsYU:function(a,r){return a>=r},pPiYr:"going aw"+t(1453)+t(1611)+"ting ser"+t(201),LWkKp:function(a,r){return a(r)},wVOCS:function(a,r){return a!==r},GQkqB:function(a,r){return a(r)},fSREu:t(1510),THnKh:t(1328)+t(775)+t(1150)+"P",Yezdg:t(849),TdNgB:"idb",lByjl:function(a){return a()},JAxBg:function(a,r){return a!==r},stSad:t(1237),VpRxS:function(a,r){return a===r},SKljY:t(522),pZQKv:function(a,r){return a instanceof r},iFSwg:t(1310)+t(568)+";charset"+t(1161),RGNrB:"none_none",uFdhy:t(1162),PhnoX:t(525),hETpF:function(a,r){return a===r},ZgMVb:t(1428),thKHc:t(353),tFZYX:t(609),yHgTi:t(538),ETiVu:function(a,r){return a||r},Wysxz:"trDRz",vQJen:function(a,r){return a||r},uRyke:function(a,r){return a instanceof r},YluOm:function(a,r){return a===r},trQqi:t(1109),axccn:t(1064),PGUtW:function(a,r){return a||r},zRSyl:function(a,r){return a>>>r},zHRON:function(a,r){return a>>>r},MSflW:function(a,r){return a&r},NblqL:function(a,r){return a>>>r},lTBJD:t(411),vWOBM:function(a,r){return a||r},SHIEZ:t(850)+t(212)+"d",hdhPr:"qos",GPxLE:function(a,r){return a&r},AojKT:function(a,r){return a>>r},hWGXe:function(a,r){return a>>r},BkjzZ:function(a,r){return a!==r},Grbgu:"HZAGn",aCdfK:t(1107),atxjM:function(a,r){return a instanceof r},CnNQq:t(1421),zCTkn:t(1526),Pbdxd:function(a,r){return a===r},mQOtf:t(1203),THQaY:function(a,r){return a!==r},ZJwSb:"lhYqK",gtZCw:t(319)+t(1515),KktkJ:function(a,r,s,l){return a(r,s,l)},GAdpq:t(319)+t(334)+"k",cbOkf:"x_fronti"+t(1108)+t(824),NrwoZ:t(1334),BbbCv:t(367),LhTmY:function(a,r){return a||r},FuqIk:"ack_code",QiWor:t(504),fgkmp:function(a){return a()},hjZMV:t(616),EwNWj:t(575),MbiBW:function(a,r){return a instanceof r},WkoHq:t(392),sXNQN:function(a,r){return a<r},OASCR:function(a,r){return a&r},dbvtD:function(a,r){return a+r},nRWxU:function(a,r){return a+r},GCajh:t(1427),qtHGZ:function(a,r){return a||r},DpuLo:function(a,r){return a>>>r},MskvL:function(a,r){return a+r},uRWOB:function(a,r){return a+r},wCxkq:t(656)+"t of range: ",Aindi:t(350),ZvGYE:function(a,r){return a||r},lfwLC:t(578),KpJCJ:"SXVGP",TdHzM:t(847)+t(168)+"e",kEPZI:function(a,r){return a+r},rSDKG:t(1462),jRWFS:function(a,r){return a<r},djQzp:function(a,r){return a<r},aTWuA:function(a,r,s,l){return a(r,s,l)},DYrDp:function(a,r){return a+r},uAHMs:function(a,r){return a+r},uIOmR:function(a,r){return a+r},uVubS:function(a,r){return a+r},zngkG:function(a,r){return a+r},nHJNn:function(a,r){return a>>>r},PJJvx:function(a,r){return a+r},ytJuV:function(a,r){return a>>>r},dFEgz:function(a,r){return a+r},cgvRX:function(a,r){return a&r},DdEBS:function(a,r){return a+r},wMjfA:function(a,r){return a+r},yArxK:function(a,r){return a&r},MirwR:function(a,r){return a>>>r},pPsGb:function(a,r){return a&r},CMcnG:function(a,r){return a+r},yZXSF:function(a,r){return a&r},gNbiL:t(301),dIgAS:function(a,r,s){return a(r,s)},LyHsb:function(a,r){return a===r},tBSMW:"kpTVx",JyAYW:"PPZKU",BEISe:"10|11|4|"+t(345)+"2|7|8|5|0",lStXP:function(a,r){return a<r},aIhgz:function(a,r){return a|r},CXlAE:function(a,r){return a&r},XziYe:function(a,r){return a>>>r},BJIdF:function(a,r){return a<<r},weKkh:function(a,r){return a|r},RfmNr:function(a,r){return a<r},dsaCN:function(a,r){return a<r},ZsbGz:function(a,r){return a|r},YFgge:function(a,r){return a<r},iBbCT:function(a,r){return a<<r},MtFuv:function(a,r){return a===r},kOasg:t(914),Bewga:function(a,r){return a+r},doJEv:t(782),Ypbjc:function(a,r,s,l){return a(r,s,l)},jXZow:"service",EUhRf:t(1143)+t(867),akzRG:function(a,r,s,l){return a(r,s,l)},cVtMK:"cursor_f"+t(1544),kJuex:function(a,r,s){return a(r,s)},YPfOm:"FILE_NOT"+t(982),eCDzZ:t(1377)+"ame",jPFQM:t(268)+t(1288),YjTFb:"ALL",UdOmi:function(a){return a()},TTDTK:function(a,r){return a!==r},BCfXl:t(1188),yJTSZ:t(1390)+"r",aKFAF:function(a,r){return a===r},jqlbh:t(1077),qAFoZ:function(a,r,s){return a(r,s)},teUjz:function(a,r,s,l){return a(r,s,l)},vURBo:function(a,r){return a===r},gVXKq:t(1493),DIlap:function(a,r){return a||r},rflgA:t(1255),OGUwt:function(a,r){return a!=r},hwbxQ:t(1072),wmQbH:function(a,r,s){return a(r,s)},MJlms:t(319)+"er_msgid",LcDei:t(319)+"er_ttl",PpMXg:t(948)+"s",zrXst:t(188)+t(737)+"e",LUyZi:function(a,r,s){return a(r,s)},hcvuB:t(188)+t(689)+"ue",jwXCL:function(a,r){return a>r},ETPTm:function(a,r){return a>r},ZuZZK:t(783),sbcBF:function(a){return a()},NhVIW:function(a){return a()},UyODh:function(a){return a()},tMbql:function(a){return a()},wNPiE:t(566)+"3",acFNA:function(a){return a()},IcClp:function(a,r){return a!==r},jCGSx:"JhZdd",doroo:t(790),GfjkB:function(a){return a()},DKCwk:function(a,r){return a+r},keHvh:function(a){return a()},Piwzv:t(1293),nOdIZ:function(a,r,s){return a(r,s)},MSeMK:t(860),aYfER:t(1589),oTzKJ:function(a,r){return a===r},UZjkK:t(1635),vCRmf:t(1507)+t(506)+"s",Skmoa:t(1655),BKKGD:function(a,r,s,l){return a(r,s,l)},miJes:function(a,r){return a===r},XCXYy:function(a,r,s){return a(r,s)},xGpIL:function(a,r){return a*r},grbVI:t(960)+t(770)+t(1093)+"1",kSVIF:t(461),qROXn:t(1060),cjimO:t(657),bdrxI:function(a,r,s){return a(r,s)},TJcCd:"AzibR",YcVIj:t(894),GTzcm:t(693),ieBlU:t(275),sUlRb:t(1026)+" try rec"+t(814)+"g",XBWRC:function(a,r){return a(r)},xvCAP:t(511)+t(819),KQVGU:function(a,r){return a/r},lghoX:t(396),mmGTA:"please p"+t(695)+t(316),mAxtc:t(518)+t(1323)+t(1148)+t(603)+t(1045)+"tructor "+t(1129)+t(1214),wHUfn:function(a,r,s){return a(r,s)},fEOnJ:"stop imm"+t(800)+t(843)+"ct",PEnmv:"online",XXprd:t(471),kRVQZ:"pagehide",oiwRV:"pageshow",DaCFp:function(a,r){return a!==r},VJAiy:function(a,r){return a|r},XQsOi:function(a,r){return a+r},ZIBbQ:function(a,r){return a|r},uZtKF:function(a,r){return a+r},oqacS:t(906),mhJtz:t(1002),JcfSd:function(a,r){return a==r},MvKaY:t(1490),uwhHr:"wss://",fQIyA:"ws://",PQAad:function(a,r){return a===r},DUjBc:t(1368),phcqb:"cTXJX",NeYKY:t(1561),IPXoC:t(1309)+"d",liouv:t(518)+"rovide b"+t(1416)+"viceID o"+t(1303),BANPy:function(a,r){return a===r},tUwmj:t(875),nrUKt:function(a,r){return a||r},KbWNN:function(a,r){return a!==r},ERCsI:t(1320),dHYXl:"DiiUF",kuohu:t(1499)+">",JxlXr:function(a,r){return a*r},DKvha:function(a,r){return a>r},zbNhK:function(a,r,s){return a(r,s)},OhIGs:function(a,r){return a!==r},XEDJQ:function(a,r,s){return a(r,s)},Oghkj:t(1507)+t(662)+"t",KVogt:function(a,r){return a!==r},eMCRX:t(1568),qxYRM:function(a,r){return a(r)},xFLkG:function(a,r){return a===r},yVxxR:t(1112),ONmHy:function(a,r,s){return a(r,s)},AdMZj:t(1371),fQxfd:function(a,r){return a(r)},HrrKV:t(290),dfabB:function(a,r){return a(r)},dVYkk:function(a,r){return a===r},LVtpW:t(1474),ibLfS:function(a,r){return a<r},kYvGN:function(a,r){return a&r},wvblD:function(a,r){return a===r},EByLI:function(a,r){return a&r},ENONi:function(a,r){return a<<r},EMxEP:function(a,r){return a>>r},hqjfP:function(a,r){return a===r},SiSIx:function(a,r){return a===r},TLEKl:t(1422)+t(1283)+t(1382),gwqMS:function(a,r){return a>=r},RIorW:function(a,r){return a<=r},XiuGM:function(a,r){return a-r},DYlGy:function(a,r){return a+r},VKtgc:function(a,r){return a<<r},fKZNt:function(a,r){return a|r},UnZrB:function(a,r){return a>>r},DADBt:function(a,r){return a&r},GBnBZ:function(a,r){return a>>r},dLbZl:function(a,r){return a|r},mgEBI:function(a,r){return a&r},PjFyI:function(a,r){return a|r},ZRQBq:function(a,r){return a>>r},LHvpU:function(a,r){return a&r},Ybcwb:function(a,r){return a<r},AqkBW:function(a,r,s){return a(r,s)},KkWHN:function(a,r){return a==r},hwFJf:"please p"+t(592)+t(195)+t(1104)+t(980)+"e a stri"+t(1449)+" arraybu"+t(202),VLvpY:t(1399),fKkAv:function(a,r){return a instanceof r},hgvaZ:function(a,r){return a instanceof r},zBPjQ:function(a,r){return a(r)},tfGFh:function(a,r){return a(r)},qxSdK:function(a,r){return a(r)},GMGyB:t(518)+t(592)+t(426)+"ervice",YnSDE:function(a,r){return a instanceof r},XwIDa:function(a,r){return a===r},VWRJQ:t(1554),RcGmk:t(916),FCwlr:"enqueue",LDayf:function(a,r){return a!==r},PmHCU:t(1470),GkkYF:t(491),qIjdf:function(a,r){return a(r)},EcpSP:t(1207)+"or",yXRpj:function(a,r){return a||r},QmrJK:"manual reconnect"+t(801),bQOwb:t(877),rjhSl:"timeout",muVOT:t(880),YpFqM:function(a,r){return a/r},xVmyZ:function(a,r){return a===r},xmrHB:"Window",fjCJP:function(a,r){return a!=r},HIxrm:function(a,r){return a!=r},QdClB:function(a,r){return a===r},xcajz:t(1531),WmhYT:function(a,r){return a===r},RBDuS:t(479)+"dWorkerG"+t(393)+"pe",inDev:function(a,r){return a!=r},WWGXV:function(a,r){return a===r},TNSRA:function(a,r){return a==r},CqdJM:function(a,r){return a!=r},jeZKM:t(963)+t(197)+t(1620),NKBnM:function(a,r){return a===r},VeKql:t(177)+"orkerGlobalScope",DZAmP:function(a,r){return a!=r},vUegQ:function(a,r){return a!=r},nTmNw:function(a,r){return a!=r},rcvWq:t(476)+t(424)};Ft.r(De),Ft.d(De,{FWS:()=>Ig,CustomErrorEvent:()=>sl,createCloseEvent:()=>mt,ReconnectEvent:()=>il,createErrorEvent:()=>lt,decodedFrame:()=>tn,createOpenEvent:()=>ul,CustomCloseEvent:()=>ol,createReconnectEvent:()=>pa,FrontierMessageEvent:()=>cl,encodeFrame:()=>Ut,createMessageEvent:()=>ll,OpenEvent:()=>dl,ErrorCode:()=>rn,Event:()=>nr,MessageEvent:()=>al});let n="";function i(a=""){let r=t,s="02",l=""+Date.now(),f=n||(n=x(a)),m=Math.random().toString(16).slice(-6);return e.yIsYk(e[r(235)](e[r(1604)](s,l),f),m)}function o(){let a=t;return e[a(729)](e[a(1542)](1e4,Date[a(1352)]()),Math[a(558)](e[a(1542)](1e4,Math.random())))}function c(a){let r=t;return e[r(235)](Array(8).join("0"),e.wOnGR(parseInt,a,10)[r(330)](2)).slice(-8)}function d(a){let r=t;return e.bAhxa(e.FGSQr(Array,4).join("0"),parseInt(a,2)[r(330)](16)).slice(-4)}function u(a){let r=t,s={VGXUu:e[r(681)],TeSPw:e.dwCji};if(e.cfilJ(e.RTiPa,e[r(1239)])){let l=a[r(811)](/\./).map(b=>c(b)),f=[];return f[0]=d(e[r(1404)](l[0],l[1])),f[1]=e[r(1469)](d,e[r(235)](l[2],l[3])),[e[r(915)],e[r(915)],e.OjKvt,e[r(915)],r(562),e[r(1075)],f[0],f[1]].join("")}else _0x371d25&&_0x78d3bf[r(1139)+"Listener"](cvbqjr.VGXUu,()=>_0x1b9252()),_0x1212bf&&_0x21e7c9.addEventListener(cvbqjr[r(999)],()=>_0x396c08())}function x(a){let r=t,s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[r(1059)](a),l=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[r(1059)](a);return s?e[r(825)](u,a):l?h(a):e[r(752)]}function h(a){let r=t;if(e[r(787)]===r(1530)){let s="",l=[],f=0,m=0,b=!0,S="0000";if(e[r(223)](a[r(1304)]("::"),-1))if(e[r(698)](e.IKpaK,e[r(1376)])){let p=a[r(811)]("::");for(let L=0;e[r(421)](L,p[r(284)]);L++){let N=p[L];if(N.indexOf(":")>0){let U=N.split(":");b&&(f=U[r(284)]),m+=U.length;for(let H=0;e[r(1534)](H,U[r(284)]);H++)if(e[r(698)](4,U[H][r(284)])){let z=S[r(1580)+"g"](0,e[r(175)](4,U[H][r(284)])),q=z.concat(U[H]);l.push(q)}else l.push(U[H]);b=!1}else{if(N[r(284)]!==4){let U=S[r(1580)+"g"](0,e[r(1141)](4,N[r(284)])),H=U[r(933)](N);l[r(190)](H)}else l[r(190)](N);b&&(f+=1),m+=1,b=!1}}let O="";for(let L=0;e[r(1534)](L,e[r(1141)](8,m));L++)O=O[r(933)](S);for(let L=0;e.KLCoe(L,l[r(284)]);L++)L===f?(s=s[r(933)](O),s=s[r(933)](l[L])):s=s.concat(l[L]);return s}else{let p=_0x5c5024(_0x50744f);this[r(1435)]&&e[r(667)](this[r(1435)][r(907)+"te"],this.OPEN)&&(this._ws&&this[r(1435)][r(1173)](p),this[r(974)](e[r(1307)],_0xcc37a7))}{let p=a[r(811)](":");for(let O=0;e[r(928)](O,p.length);O++){let L=p[O];if(e[r(698)](4,p[O].length)){let N=S[r(1580)+"g"](0,e[r(842)](4,p[O][r(284)])),U=N[r(933)](L);s=s[r(933)](U)}else s=s[r(933)](L)}return s}}else{let s=e[r(1625)](_0x4eea8e,r(246),{message:_0x4eb59f[r(301)],code:_0x168992[r(599)+"OR"],error:_0x446142});this[r(404)+r(939)+r(736)](s)}}function g(a,r){let s=t,l=a[s(234)];e[s(1593)](void 0,l)&&(e[s(969)](we,r,10),e[s(1625)](j,r,l));let f=a[s(563)];e[s(698)](void 0,f)&&(e.hwBCF!==e[s(912)]?(_0x1eebfa[s(1131)][s(1165)+s(170)](_0x49dd48),_0x3b4be6[s(633)+s(579)]=void 0,e[s(1469)](_0xc56816,_0x144e26&&_0x2c66e5[s(1068)]||e[s(1630)])):(we(r,18),e[s(1009)](j,r,f)))}function w(a){let r=t,s={};e:for(;!e.Jizco(Z,a);){let l=e[r(1193)](me,a);switch(l>>>3){case 0:break e;case 1:s.key=e[r(1009)](P,a,e[r(722)](me,a));break;case 2:s[r(563)]=e[r(1364)](P,a,e.kgkln(me,a));break;default:e[r(1246)](T,a,e[r(904)](7,l))}}if(e[r(1013)](void 0,s[r(234)]))throw new Error(e[r(1549)]);if(e[r(667)](void 0,s[r(563)]))throw new Error(e[r(1664)]);return s}function v(a){let r=t,s=C();return e[r(808)](_,a,s),B(s)}function _(a,r){let s=t,l=a.SeqID;l!==void 0&&(we(r,8),e[s(969)](gt,r,l));let f=a[s(269)];e.hrbHd(void 0,f)&&(e[s(1009)](we,r,16),e.hcGdG(gt,r,f));let m=a.service;if(e[s(540)](void 0,m))if(e[s(540)](e[s(1258)],e[s(1258)])){let q=/(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}/[s(1059)](_0x1f3ff3),ne=/(([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]))/[s(1059)](_0xb2110a);return q?e[s(1113)](_0x426375,_0x3ba25b):ne?e.qDxZG(_0x4121a2,_0x51cf3f):s(1594)+"00000000"+s(1594)+s(1594)}else we(r,24),gt(r,e[s(1113)](R,m));let b=a[s(943)];e[s(1408)](void 0,b)&&(e[s(1364)](we,r,32),e[s(1396)](gt,r,e[s(321)](R,b)));let S=a[s(1199)];if(e[s(1408)](void 0,S))for(let q of S){e[s(1152)](we,r,42);let ne=e[s(1614)](C);e[s(233)](g,q,ne),e.XlATz(we,r,ne[s(1419)]),e[s(1364)](V,r,ne),D(ne)}let p=a[s(1279)+s(1509)];e.cSntl(void 0,p)&&(e.DlvpK(we,r,50),j(r,p));let O=a[s(1669)+"ype"];O!==void 0&&(e[s(355)](we,r,58),e[s(1625)](j,r,O));let L=a.payload;if(e[s(698)](void 0,L))if(e[s(698)](e.lNxBv,e[s(427)]))we(r,66),e.KaStH(we,r,L[s(284)]),e[s(346)](ce,r,L);else{if(!this[s(1435)])return;this[s(1330)+s(839)+"t"](_0x25f24e,_0x2d33a5,_0x5bf0ce)}let N=a[s(1180)];if(e.UgkZv(void 0,N))if(e[s(667)](e[s(500)],s(1401))){let q=e[s(904)](255,_0x282d8b);e[s(1029)](_0x32c860,q,_0x357e5b,_0x319fa8+_0x2bc29d),_0x52920b>>>=8,_0x10b6b2--}else we(r,74),j(r,N);let U=a["serverTi"+s(1482)];U!==void 0&&(e[s(1396)](we,r,82),j(r,U));let H=a.msgID;e[s(1593)](void 0,H)&&(we(r,90),e[s(255)](j,r,H));let z=a[s(868)+"e"];z!==void 0&&(e[s(1364)](we,r,96),gt(r,e[s(1469)](R,z)))}function E(a){let r=t,s={xCFtb:function(l,f){return l+f}};if(e.sBaXw(e.oFrHG,e[r(765)]))return e[r(468)](I,F(a));if(s[r(1466)](_0x22f618[r(1647)],_0x53f376)>_0x50438f[r(1419)])throw new _0x25af2e(r(1284)+"t limit");_0x408da5[r(1647)]+=_0x3ff13b}function I(a){let r=t,s={};e:for(;!Z(a);){let l=me(a);switch(e[r(890)](l,3)){case 0:break e;case 1:s[r(1095)]=It(a,!0);break;case 2:s[r(269)]=It(a,!0);break;case 3:s[r(1089)]=e[r(468)](me,a);break;case 4:s[r(943)]=e[r(981)](me,a);break;case 5:{let f=e[r(763)](A,a);(s[r(1199)]||(s[r(1199)]=[])).push(e[r(920)](w,a)),a.limit=f;break}case 6:s[r(1279)+"ncoding"]=e[r(786)](P,a,me(a));break;case 7:s["payloadT"+r(1585)]=e[r(498)](P,a,e.tCphh(me,a));break;case 8:s[r(1223)]=e[r(1625)](ae,a,me(a));break;case 9:s[r(1180)]=e.EPkdJ(P,a,me(a));break;case 10:s[r(1242)+r(1482)]=P(a,e[r(981)](me,a));break;case 11:s[r(1605)]=P(a,e.QGUlx(me,a));break;case 12:s[r(868)+"e"]=e[r(1193)](me,a);break;default:e[r(498)](T,a,e[r(1458)](7,l))}}if(e[r(1670)](void 0,s.SeqID))throw new Error(e[r(1082)]);if(e[r(667)](void 0,s[r(269)]))throw new Error(e[r(1211)]);if(e.qeeNw(void 0,s[r(1089)]))throw new Error(e.wwFFE);if(s.method===void 0)throw new Error(r(696)+"required field: "+r(943));return s}function A(a){let r=t,s=e[r(722)](me,a),l=a[r(1419)];return a[r(1419)]=a.offset+s,l}function T(a,r){let s=t;switch(r){case 0:for(;e[s(1458)](128,re(a)););break;case 2:e.SjDKC(Y,a,e[s(1090)](me,a));break;case 5:Y(a,4);break;case 1:e.VrvAd(Y,a,8);break;default:throw new Error(e[s(494)](e[s(545)],r))}}function R(a){return a|=0,{low:a,high:a>>31,unsigned:e.YNQKZ(a,0)}}let y=[];function C(){let a=t,r=y.pop();return r?(r.offset=r[a(1419)]=0,r):{bytes:new Uint8Array(64),offset:0,limit:0}}function D(a){y[t(190)](a)}function F(a){return{bytes:a,offset:0,limit:a[t(284)]}}function B(a){let r=t,s=a[r(1278)],l=a[r(1419)];return e[r(1235)](s[r(284)],l)?s:s[r(182)](0,l)}function Y(a,r){let s=t,l={EdYxI:function(f,m){return e[W(1193)](f,m)}};if(e[s(1649)]!==e[s(1219)]){if(e[s(223)](e[s(235)](a[s(1647)],r),a.limit))throw new Error(e[s(555)]);a[s(1647)]+=r}else return l[s(565)](_0x257f64,_0x9d961a)}function Z(a){let r=t;return e[r(1004)](a[r(1647)],a[r(1419)])}function se(a,r){let s=t,l={PPRRo:function(p,O){return e[W(296)](p,O)}},f=a[s(1278)],m=a[s(1647)],b=a.limit,S=e[s(400)](m,r);if(S>f[s(284)])if(e[s(594)]===s(1356)){let p=new Uint8Array(2*S);p[s(841)](f),a.bytes=p}else return nYYtPX.PPRRo(_0x255b34,nYYtPX[s(1265)](_0x3c20f5,_0x53a5f0));return a.offset=S,e.UQYDT(S,b)&&(a[s(1419)]=S),m}function Q(a,r){let s=t,l={LPNkG:function(f,m){return e[W(567)](f,m)},Zhlhw:function(f,m){return e[W(175)](f,m)},ayjcl:function(f,m){return e.yTgOY(f,m)}};if(e.Yqrjl(e.UULdO,s(1230))){let f=a.offset;if(e[s(1351)](e.tJwcD(f,r),a.limit))throw new Error(e[s(1567)]);return a[s(1647)]+=r,f}else{let{initReconnectInterval:f,maxReconnectInterval:m,reconnectIntervalGrowFactor:b}=this._options,S=l[s(649)](f,_0x39f59d.pow(b,l[s(580)](_0x5be876,1)));return l[s(694)](S,m)?m:S}}function ae(a,r){let s=t,l=Q(a,r);return a[s(1278)][s(182)](l,e[s(494)](l,r))}function ce(a,r){let s=t,l=e.cngnN(se,a,r[s(284)]);a.bytes[s(841)](r,l)}function P(a,r){let s=t,l={RpFYY:function(f,m){return f===m},xhyXN:function(f,m,b){return e[W(978)](f,m,b)},IBLqs:function(f,m){return e[W(178)](f,m)}};if(e.XVfGm!==e[s(944)])return l[s(186)](0,this[s(1660)])&&this[s(362)]===0;{let f=e[s(1134)](Q,a,r),m=String[s(1441)+s(1480)],b=a[s(1278)],S="\uFFFD",p="";for(let O=0;e[s(328)](O,r);O++){let L=b[e[s(818)](O,f)],N,U,H,z;if(e[s(1458)](128,L)===0)p+=e.tCphh(m,L);else if(e[s(772)](e.iZrWB(224,L),192))if(e[s(429)](e[s(1264)](O,1),r))p+=S;else if(N=b[e.lpTYc(e[s(1256)](O,f),1)],e[s(1281)](192,N)!==128)p+=S;else{if(e[s(667)](e[s(900)],e[s(1603)]))return this[s(239)][s(229)];z=e[s(435)](e[s(1458)](31,L)<<6,63&N),e.CMlai(z,128)?p+=S:(p+=m(z),O++)}else if(e[s(810)](240&L,224))if(e[s(429)](e[s(1604)](O,2),r))p+=S;else if(N=b[e.SzLVM(e.sWCWh(O,f),1)],U=b[O+f+2],e[s(1386)](e[s(435)](N,e[s(401)](U,8)),49344)!==32896)p+=S;else{if(e[s(373)](e.GjtpG,e[s(1671)]))return _0x6281ca["objectSt"+s(1405)]||_0x498be6[s(1575)](_0x1ffb2a);z=e[s(1528)](e.Rhlqu(e[s(962)](15,L)<<12,e.RQRmQ(e[s(1386)](63,N),6)),63&U),e.KLCoe(z,2048)||z>=55296&&e[s(886)](z,57343)?p+=S:(p+=e[s(178)](m,z),O+=2)}else if(e[s(232)](248&L,240))if(e.jRjVI(O,3)>=r)p+=S;else if(N=b[O+f+1],U=b[e[s(610)](e[s(610)](O,f),2)],H=b[e[s(1086)](e[s(1388)](O,f),3)],(e[s(435)](N|U<<8,H<<16)&12632256)!==8421504)p+=S;else if(e[s(354)](e.MiQYt,s(1667)))z=e[s(1341)](e[s(358)]((7&L)<<18,e[s(1458)](63,N)<<12)|e[s(401)](e[s(194)](63,U),6),e.iZrWB(63,H)),e.CMlai(z,65536)||e[s(583)](z,1114111)?p+=S:(z-=65536,p+=e[s(612)](m,e[s(1604)](e[s(1539)](z,10),55296),e.plaJG(1023&z,56320)),O+=3);else{_0x34efe4(_0x1d3ca9,42);let q=_0x159a2f();YZVraI[s(1372)](_0x3cf8a2,_0x11378f,q),YZVraI.xhyXN(_0x142720,_0xa37085,q[s(1419)]),_0x195127(_0x5bdbf7,q),YZVraI[s(1627)](_0x35a58f,q)}else p+=S}return p}}function j(a,r){let s=t;if(e[s(354)](e[s(535)],s(206)))this[s(1057)+s(493)]();else{let l=r[s(284)],f=0;for(let S=0;e[s(668)](S,l);S++){let p=r[s(1395)+"At"](S);e[s(1160)](p,55296)&&p<=56319&&e[s(1065)](S,1)<l&&(p=e[s(307)](e[s(600)](e[s(685)](p,10),r[s(1395)+"At"](++S)),56613888)),f+=p<128?1:e.SzmoB(p,2048)?2:e[s(328)](p,65536)?3:4}e.wOnGR(we,a,f);let m=e[s(1634)](se,a,f),b=a[s(1278)];for(let S=0;e[s(928)](S,l);S++){let p=r.charCodeAt(S);p>=55296&&e[s(366)](p,56319)&&e[s(1534)](e[s(235)](S,1),l)&&(p=e[s(293)](e[s(881)](p<<10,r.charCodeAt(++S)),56613888)),e[s(421)](p,128)?b[m++]=p:(e.yJFMv(p,2048)?b[m++]=e.QQeqm(e[s(194)](e.ZQgCp(p,6),31),192):(p<65536?b[m++]=e[s(582)](e[s(721)](p,12),15)|224:(b[m++]=e[s(1281)](e.ZQgCp(p,18),7)|240,b[m++]=e[s(962)](e[s(1088)](p,12),63)|128),b[m++]=e[s(1341)](e[s(1088)](p,6)&63,128)),b[m++]=e[s(358)](63&p,128))}}}function V(a,r){let s=t,l=se(a,r[s(1419)]),f=a[s(1278)],m=r[s(1278)];for(let b=0,S=r.limit;e[s(928)](b,S);b++)f[b+l]=m[b]}function re(a){let r=t;return a[r(1278)][e[r(612)](Q,a,1)]}function et(a,r){let s=t,l=e[s(1039)](se,a,1);a[s(1278)][l]=r}function me(a){let r=t,s=0,l=0,f;do f=re(a),e[r(908)](s,32)&&(l|=e.GfxNX(127&f,s)),s+=7;while(128&f);return l}function we(a,r){let s=t;if(e[s(460)](e[s(484)],e[s(876)]))_0x5cb343=e[s(1318)](e[s(385)](e[s(840)](31,_0x5dd088),6),e[s(1147)](63,_0x145274)),e[s(928)](_0x4ab65c,128)?_0x26b8ad+=_0x4d145c:(_0x4f3b13+=e[s(1592)](_0x560da4,_0x457a17),_0x590b43++);else{for(r>>>=0;e[s(1159)](r,128);)e[s(1308)](et,a,e[s(1528)](e[s(1426)](127,r),128)),r>>>=7;e[s(1597)](et,a,r)}}function It(a,r){let s=t,l=0,f=0,m=0,b;return b=e.KjyWO(re,a),l=e.SSOBV(127,b),128&b&&(b=e.PziCq(re,a),l|=e[s(1400)](127,b)<<7,128&b&&(b=re(a),l|=e.Zrgad(e[s(553)](127,b),14),e.axKKV(128,b)&&(b=e[s(1469)](re,a),l|=e[s(1636)](127&b,21),e[s(925)](128,b)&&(b=e[s(763)](re,a),f=e[s(778)](127,b),e.ITxPG(128,b)&&(b=e.sHSPf(re,a),f|=e[s(1636)](e.YQaxG(127,b),7),e[s(1426)](128,b)&&(b=e[s(1502)](re,a),f|=e.BOGsn(e[s(731)](127,b),14),e[s(1263)](128,b)&&(b=e[s(1028)](re,a),f|=e[s(1472)](e[s(885)](127,b),21),e[s(1233)](128,b)&&(b=e[s(256)](re,a),m=e[s(731)](127,b),128&b&&(b=e[s(468)](re,a),m|=(127&b)<<7))))))))),{low:l|e[s(685)](f,28),high:e[s(1341)](e.npCwo(f,4),e[s(1327)](m,24)),unsigned:r}}function gt(a,r){let s=t;if(e[s(297)](e[s(179)],s(1055)))_0xb61d52(_0x4aab14.error),_0x476ff1();else{let l=e[s(1250)](r[s(362)],0),f=e.dndBs(e.gTqPC(e.npCwo(r[s(362)],28),e.WstYS(r[s(1660)],4)),0),m=r[s(1660)]>>>24,b=e[s(956)](0,m)?e.MwfCl(0,f)?l<16384?e.RaoXL(l,128)?1:2:e[s(519)](l,2097152)?3:4:e.dWrAz(f,16384)?f<128?5:6:e[s(908)](f,2097152)?7:8:m<128?9:10,S=e[s(498)](se,a,b),p=a.bytes;switch(b){case 10:p[e.htfqc(S,9)]=e[s(822)](e[s(890)](m,7),1);case 9:p[e.ELzii(S,8)]=e[s(418)](9,b)?e[s(1318)](128,m):e[s(1033)](127,m);case 8:p[e[s(905)](S,7)]=b!==8?e.gTqPC(e.dndBs(f,21),128):e.gxOhk(f,21)&127;case 7:p[e[s(669)](S,6)]=b!==7?e[s(691)](e[s(1321)](f,14),128):e[s(598)](f,14)&127;case 6:p[e[s(669)](S,5)]=e[s(1408)](6,b)?e[s(919)](f>>>7,128):e[s(1423)](e[s(652)](f,7),127);case 5:p[S+4]=e[s(935)](5,b)?128|f:127&f;case 4:p[e[s(1403)](S,3)]=e[s(418)](4,b)?e.QrRYH(e[s(779)](l,21),128):e.LraeJ(e[s(314)](l,21),127);case 3:p[e.orRUx(S,2)]=e.ZPHUI(3,b)?e.Rhlqu(e.ZdiHJ(l,14),128):e[s(314)](l,14)&127;case 2:p[e[s(1051)](S,1)]=e[s(1035)](2,b)?e[s(467)](e[s(1250)](l,7),128):l>>>7&127;case 1:p[S]=e[s(1302)](1,b)?e[s(467)](128,l):e[s(398)](127,l)}}}function tn(a){return E(a)}function Ut(a){let r=t,s={cGRls:function(l,f){return e[W(1157)](l,f)},rdGXW:function(l,f){return e[W(372)](l,f)},yWjtr:function(l,f){return e[W(1604)](l,f)},eKjJx:function(l,f){return e[W(553)](l,f)},dHkaK:function(l,f){return e[W(1326)](l,f)},JyDAO:function(l,f){return l<<f},tdqYN:function(l,f){return e[W(587)](l,f)},pzsWi:function(l,f){return l>=f},kPKfP:function(l,f){return l<=f}};if(e.lZKFs(r(1298),e[r(1455)]))_0x15422c=_0x469334[bAtbjw[r(1521)](_0xe50db8+_0x2b7506,1)],_0x3d1179=_0x2e1c7c[bAtbjw.rdGXW(bAtbjw[r(1622)](_0x5f37c7,_0x461af0),2)],bAtbjw[r(394)](bAtbjw[r(1119)](_0x212efa,bAtbjw[r(1344)](_0xe10810,8)),49344)!==32896?_0x2ab2a7+=_0x547407:(_0x1521df=bAtbjw[r(1119)](bAtbjw.dHkaK(bAtbjw[r(1344)](15&_0x5caf4d,12),(63&_0x2346d7)<<6),63&_0x14eee7),bAtbjw[r(1358)](_0x540eca,2048)||bAtbjw[r(486)](_0x56fbe0,55296)&&bAtbjw[r(1632)](_0x4d7a1d,57343)?_0x210563+=_0x5af7a8:(_0x1506ff+=_0x423ab3(_0x46f42f),_0x1a4470+=2));else return e[r(415)](v,a)}let nn=65536,Xr=e[t(741)],be=e[t(1542)](nn,nn),Te=be*be,tr=e[t(989)](Te,2),Ne=String[t(733)+"e"][t(1395)+"At"];class he{constructor(r,s,l){let f=t;this[f(474)]=!0,this.low=e[f(521)](0,r),this.high=e.QrRYH(0,s),this.unsigned=!!l}static[t(474)](r){return r&&r.isLong===!0}static[t(1056)](r,s,l){return new he(r,s,l)}static[t(947)+"s"](r,s,l){let f=t;return l?he[f(947)+f(450)](r,s):he["fromByte"+f(1198)](r,s)}static[t(947)+"sLE"](r,s){let l=t;return new he(e[l(1318)](r[0],e[l(560)](r[1],8))|e[l(1017)](r[2],16)|e.iDPgN(r[3],24),e[l(435)](e[l(216)](r[4]|r[5]<<8,e[l(1636)](r[6],16)),e[l(1639)](r[7],24)),s)}static[t(947)+t(1198)](r,s){let l=t;return new he(e.UUMES(e[l(919)](e[l(760)](r[4]<<24,r[5]<<16),e[l(1639)](r[6],8)),r[7]),e.ljydM(e[l(1268)](r[0],24),e[l(1243)](r[1],16))|e[l(1243)](r[2],8)|r[3],s)}static[t(1411)](r){let s=t;if(e.QGVOT===e[s(738)])_0x3b8f5d[s(921)+"oad"]="",_0x330b70.log(_0x25564b);else return e[s(667)](r,Xr)?rl:new he(e.uDpRL(e[s(760)](e.VYPow(Ne[s(851)](r,0),e[s(385)](Ne.call(r,1),8)),e.foBcv(Ne[s(851)](r,2),16)),Ne[s(851)](r,3)<<24)>>>0,e.TAbUf(e.xxOQy(Ne[s(851)](r,4)|e[s(370)](Ne[s(851)](r,5),8)|Ne[s(851)](r,6)<<16,e.jPhEb(Ne.call(r,7),24)),0),!0)}[t(219)](){let r=t;return String["fromChar"+r(1480)](e[r(410)](255,this[r(362)]),e[r(277)](this[r(362)]>>>8,255),e[r(1423)](e[r(598)](this.low,16),255),this[r(362)]>>>24,255&this[r(1660)],e[r(1033)](this.high>>>8,255),e[r(192)](this[r(1660)],16)&255,this[r(1660)]>>>24)}static[t(1579)+"er"](r,s=!0){let l=t;if(isNaN(r))return s?Bp:rl;if(s){if(e[l(1004)](r,Te))return zp}else{if(r<=-tr)return Up;if(e[l(449)](e.KQonQ(r,1),tr))return Fp}return he[l(1056)](e[l(1197)](r,be)|0,r/be|0,s)}[t(327)](){let r=t;return this[r(614)]?e[r(725)](e.hMdOt(e[r(652)](this[r(1660)],0),be),e.gFACL(this[r(362)],0)):e.qbAzx(e.ruHUa(this[r(1660)],be),e[r(1321)](this[r(362)],0))}[t(702)](){let r=t;return e[r(1536)](0,this[r(1660)])&&this.low===0}add(r){let s=t;he[s(474)](r)||(r=he[s(1579)+"er"](r));let l=e.ZVQAB(this[s(1660)],16),f=65535&this[s(1660)],m=this[s(362)]>>>16,b=65535&this.low,S=e[s(1027)](r[s(1660)],16),p=e.opORa(65535,r.high),O=e[s(1027)](r[s(362)],16),L=65535&r[s(362)],N=0,U=0,H=0,z=0;return z+=e[s(1604)](b,L),H+=e[s(771)](z,16),z&=65535,H+=e[s(1404)](m,O),U+=e[s(1020)](H,16),H&=65535,U+=f+p,N+=e[s(338)](U,16),U&=65535,N+=e[s(1105)](l,S),N&=65535,he[s(1056)](e[s(919)](e[s(1508)](H,16),z),e[s(490)](N,16)|U,this[s(614)])}equals(r){let s=t;return he[s(474)](r)||(r=he[s(1579)+"er"](r)),e.CYsVf(this[s(614)],r.unsigned)&&e.ZVQAB(this[s(1660)],31)===1&&e[s(1235)](e[s(192)](r[s(1660)],31),1)?!1:e.jaALH(this.high,r[s(1660)])&&this[s(362)]===r[s(362)]}[t(1533)](){let r=t;return this[r(362)]===-1&&e[r(667)](-1,this.high)?he[r(1056)](0,0,this[r(614)]):e[r(1661)](-1,this.low)?he[r(1056)](0,this.high+1,this[r(614)]):he[r(1056)](e[r(1374)](this[r(362)],1),this[r(1660)],this.unsigned)}[t(844)](r){let s=t;return r?this[s(1137)+"E"]():this[s(1030)+"E"]()}[t(1137)+"E"](){let r=t,s=this[r(1660)],l=this.low;return[e[r(310)](255,l),e.rLKII(e[r(1020)](l,8),255),e[r(1263)](e.ZVQAB(l,16),255),e[r(1038)](l,24),e[r(996)](255,s),e[r(398)](e[r(940)](s,8),255),s>>>16&255,e[r(598)](s,24)]}[t(1030)+"E"](){let r=t,s=this.high,l=this[r(362)];return[e[r(247)](s,24),e[r(804)](e[r(1459)](s,16),255),e[r(1538)](s,8)&255,e[r(904)](255,s),e[r(1571)](l,24),e[r(1220)](e[r(1623)](l,16),255),e[r(1458)](e[r(1336)](l,8),255),255&l]}}let rl=new he(0,0,!1),Bp=new he(0,0,!0),Fp=he[t(1056)](-1,2147483647,!1),zp=he[t(1056)](-1,-1,!0),Up=he[t(1056)](0,-2147483648,!1);var rn=(function(a){let r=t,s=e.QZhRi[r(811)]("|"),l=0;for(;;){switch(s[l++]){case"0":return a;case"1":a[a[e[r(1251)]]=5002]=e[r(1251)];continue;case"2":a[a[r(599)+"OR"]=5005]=e.JbJwm;continue;case"3":a[a[e[r(1042)]]=5001]=e[r(1042)];continue;case"4":a[a[e[r(1212)]]=5004]=r(767)+r(318);continue;case"5":a[a[e[r(619)]]=5003]=e.mJLNy;continue}break}})({});class nr{constructor(r){let s=t;this[s(251)]=r,this[s(1083)]=null}}class il extends nr{constructor(r,s){let l=t,f={FRzqj:function(m,b,S){return e[W(271)](m,b,S)},vghUA:e[l(238)]};if(e[l(402)](e[l(1650)],l(1200))){let m=f[l(1287)](_0x7d987e,f[l(1609)],{message:_0x20a0cc[l(301)],code:_0x283403[l(767)+l(318)],error:_0x2f617a});this[l(404)+l(939)+l(736)](m)}else super(r),this[l(301)]=s&&s[l(301)]||null}}class sl extends nr{constructor(r,s){let l=t,f=e[l(1071)][l(811)]("|"),m=0;for(;;){switch(f[m++]){case"0":this.code=s&&s[l(1679)]||5001;continue;case"1":super(r);continue;case"2":this[l(1227)]=s&&s[l(1227)]||"";continue;case"3":this.error=s&&s[l(246)]||null;continue;case"4":this[l(453)]=s&&s[l(453)]||0;continue;case"5":this[l(261)]=s&&s.lineno||0;continue;case"6":this[l(301)]=s&&s[l(301)]||"";continue}break}}}class ol extends nr{constructor(r,s){let l=t,f=e[l(705)][l(811)]("|"),m=0;for(;;){switch(f[m++]){case"0":this[l(1679)]=s&&s.code||0;continue;case"1":this[l(761)]=s&&s[l(761)]||!1;continue;case"2":super(r);continue;case"3":this[l(554)]=s&&s[l(554)]||"";continue;case"4":this["willReco"+l(902)]=s&&s[l(1659)+"nnect"]||!1;continue}break}}}class al extends nr{constructor(r,s){let l=t;super(r),this[l(1448)]=s&&s.data||null}}class cl extends al{constructor(r,s){let l=t;super(r),this[l(1448)]=s&&s[l(1448)]||null,this[l(301)]=s&&s[l(301)]||null}}class dl extends nr{constructor(r,s){let l=t;super(r),this[l(1448)]=s&&s.data||null}}function lt(a,{message:r,code:s,error:l}){return new sl(a,{message:r,code:s,error:l})}function mt(a,{code:r,reason:s,wasClean:l,willReconnect:f}){return new ol(a,{code:r,reason:s,wasClean:l,willReconnect:f})}function ll(a,{data:r,message:s}){return new cl(a,{data:r,message:s})}function ul(a,{data:r}){return new dl(a,{data:r})}function pa(a,{message:r}){return new il(a,{message:r})}class fl{constructor(r,s){let l=t;this[l(1189)+"s"]=r,this[l(1394)+"es"]=s,this[l(550)+l(1498)]=0,this[l(715)+l(615)+l(1120)+"t"]=0}[t(590)+t(311)+t(1658)](){let r=t;this[r(550)+"ndex"]=0,this[r(715)+r(615)+r(1120)+"t"]=0}[t(626)+"es"](){let r=t;this[r(715)+r(615)+"riesCount"]=0}[t(1532)+"ntEndpoint"](){let r=t;return this[r(1189)+"s"][this[r(550)+"ndex"]]}[t(1532)+t(957)+t(409)+"ount"](){return this["currentEndpointT"+t(1120)+"t"]}[t(1286)+t(826)+"es"](){let r=t;if(e[r(373)](e[r(1221)],r(1631)))_0x4251c7[r(719)](_0xf70e6f);else return!!(this[r(550)+"ndex"]>=this[r(1189)+"s"][r(284)]||e[r(1670)](this[r(550)+r(1498)],e[r(175)](this.endpoints[r(284)],1))&&this["currentE"+r(615)+r(1120)+"t"]===this.maxRetries)}[t(1624)+t(270)+"ointReachedMaxRe"+t(1576)](){let r=t;return this["currentI"+r(1498)]==this[r(1189)+"s"][r(284)]?!0:e[r(1058)](this[r(715)+"ndpointT"+r(1120)+"t"],this[r(1394)+"es"])}[t(407)+t(1430)+t(1175)+t(1517)+t(750)](){let r=t;return this["currentE"+r(615)+"riesCount"]=1,this["currentI"+r(1498)]++,this[r(1189)+"s"][this["currentI"+r(1498)]]}[t(1532)+t(957)+t(1124)+"ateCount"](){let r=t;return this["currentE"+r(615)+r(1120)+"t"]++,this[r(1532)+r(957)+"nt"]()}}let rr=(e[t(209)]!=typeof globalThis&&e.xVmyZ(e.xmrHB,globalThis[t(1070)+t(704)][t(867)])||e.fjCJP(e[t(209)],typeof window)&&t(660)===window[t(1070)+t(704)][t(867)])&&e[t(305)](e[t(209)],typeof document),Rn=e[t(699)](t(637)+"d",typeof globalThis)&&(e.QdClB(e.xcajz,globalThis[t(1070)+"tor"][t(867)])||e[t(349)](e[t(1415)],globalThis[t(1070)+t(704)][t(867)]))&&e.cfNej!=typeof tt,Qr=(e[t(1615)](e[t(209)],typeof globalThis)&&e[t(1153)](t(1531),globalThis[t(1070)+t(704)].name)||e.TNSRA("undefined",typeof globalThis)||e.CqdJM(e.cfNej,typeof globalThis)&&!!globalThis.WeixinJSBridge)&&e[t(209)]!=typeof wx,ei=e[t(1467)](e[t(209)],typeof globalThis)&&(e[t(383)](e[t(1415)],globalThis.constructor[t(867)])||e[t(1552)]===globalThis[t(1070)+t(704)][t(867)]||e[t(926)](e[t(1272)],globalThis.constructor[t(867)]))&&e.cfNej!=typeof self,Gp=e.cfNej!=typeof globalThis&&t(1531)===globalThis[t(1070)+t(704)][t(867)]&&e[t(717)](t(637)+"d",typeof global)&&e.xFLkG(e[t(672)],global["construc"+t(704)][t(867)])&&e.vUegQ(e.cfNej,typeof process)&&!!process[t(859)];class ga{constructor(){let r=t;this[r(971)+"rs"]={}}emit(r,...s){let l=t,f=this._listeners[r];if(f)f[l(1337)]()[l(1652)](m=>m.fn[l(1324)](m[l(509)],s));else if(e[l(1013)](l(246),r)&&!this[l(1322)]){let m=s.length&&s[0];if(e.uXrPY(m,Error))throw m;let b=new Error(e[l(1339)](e.YcmRQ,m?e[l(1403)](" (",m[l(301)])+")":""));throw b[l(557)]=m,m}return this}[t(1555)](r,s){let l=t;if(e[l(667)](void 0,r))this[l(971)+"rs"]={};else if(e[l(632)](void 0,s))this._listeners[r]=null;else if(e.AutpX!==e[l(909)])this._qosDB?.[l(631)](_0x482e4b[l(604)+"id"]);else{let f=this[l(971)+"rs"][r];if(f)for(let m=0;m<f[l(284)];)f[m].fn===s?f.splice(m,1):++m}return this}on(r,s,l){let f=t;return(this[f(971)+"rs"][r]||(this[f(971)+"rs"][r]=[]))[f(190)]({fn:s,ctx:l||this}),this}}class jp extends ga{[t(530)+t(1522)+"age"](r){let s=t;if(e[s(1524)](s(499),"TxHYt"))return r.errMsg||r[s(359)]?(s(414)+" "+(r[s(361)]||"")+s(1523)+(r[s(359)]||""))[s(352)]():JSON[s(218)+"y"](r);{if(e.UQYDT(_0x5813a8,_0x3318bd))throw new _0xe16382(s(847)+s(168)+"e");let l=3;for(;e[s(452)](l,0);){let f=e[s(1263)](255,_0xa4a61e);e.yFoLC(_0x4ed1cc,f,_0x445d03,e[s(1604)](_0x4805bd,l)),_0x203fa3>>>=8,l--}return _0xa042b9+4}}constructor(r,s,l){let f=t;super(),this._socket=null,Qr&&wx[f(442)+f(210)]&&(this._socket=wx.connectSocket({url:r,protocols:s,header:l,fail:this[f(1582)+f(1015)+f(796)][f(595)](this),success:this[f(1582)+f(1392)+f(970)+f(1266)][f(595)](this)})),Rn&&tt.connectSocket&&(this[f(1393)]=tt[f(442)+f(210)]({url:r,protocols:s,header:l,fail:this[f(1582)+f(1015)+f(796)][f(595)](this),success:this[f(1582)+f(1392)+f(970)+"ler"][f(595)](this)}))}["_createS"+t(1392)+t(970)+t(1266)](){let r=t;Promise.resolve()[r(326)](()=>{let s=r;this[s(1057)+s(493)]()})}[t(1582)+t(1015)+"lHandler"](r){let s=t,l={BZjih:e[s(238)],EVaAt:function(f,m,b){return e.SxDZv(f,m,b)},jWsGN:s(1417)};Promise[s(857)]().then(()=>{let f=s,m=lt(l.BZjih,{message:this[f(530)+f(1522)+f(621)](r)});this.emit(l[f(1257)],m);let b=l[f(1127)](mt,"close",{reason:this["_formatE"+f(1522)+f(621)](r)});this.emit(l[f(1074)],b)})}["_addWsLi"+t(493)](){let r=t,s={xZjrI:function(l,f){return e[W(1116)](l,f)},Iivtj:e[r(292)],qxLgj:r(1525),VAGjI:e[r(681)],VzcuT:function(l,f,m){return e[r(1067)](l,f,m)}};this._socket[r(1069)](l=>{let f=r;this[f(1342)](e[f(308)],e[f(255)](ul,f(1477),{...l,data:l[f(361)]||""}))}),this._socket[r(958)](l=>{let f=r,m={mpQcl:function(b,S){return b!==S}};if(s[f(744)](s[f(1094)],s[f(762)]))this[f(1342)](s[f(1241)],s[f(1037)](mt,s[f(1241)],{...l}));else{let b=_0x81501[_0x1f36c5];if(LJpFho[f(903)](4,_0x50ace7[_0x2e1c5b][f(284)])){let S=_0x29d01b.substring(0,4-_0x1cf388[_0x1276a7][f(284)]),p=S[f(933)](b);_0x22141d=_0x4a0f6b[f(933)](p)}else _0x359998=_0x3722d3[f(933)](b)}}),this[r(1393)][r(260)+"e"](l=>{let f=r;this[f(1342)](f(301),ll("message",{...l}))}),this._socket.onError(l=>{let f=r;this[f(1342)](e.EzyeT,e.GlqJu(lt,e[f(238)],{...l,message:l[f(361)]||""}))})}[t(1173)](r){let s=t;if(r instanceof Uint8Array){let l=r.buffer[s(1337)](r.byteOffset,e[s(1388)](r.byteLength,r[s(244)+"et"]));this._socket&&this[s(1393)].send({data:l,fail:f=>{let m=s;this[m(1342)](e[m(238)],e.QGioJ(lt,e[m(238)],{message:this["_formatE"+m(1522)+m(621)](f)}))}})}else this[s(1393)]&&this[s(1393)][s(1173)]({data:r,fail:l=>{let f=s;this[f(1342)](e[f(238)],lt(e.EzyeT,{message:this[f(530)+"rrorMessage"](l)}))}})}[t(1417)](r,s){let l=t;if(e[l(1294)](e[l(403)],e[l(403)]))this._socket&&this._socket[l(1417)]({code:r,reason:s});else return}[t(1139)+t(1503)](r,s){this.on(r,s)}[t(1176)+t(945)+t(1437)](r,s){this[t(1555)](r,s)}get[t(907)+"te"](){let r=t;return this._socket[r(907)+"te"]}get[t(1485)+"pe"](){let r=t;return this[r(1393)][r(1485)+"pe"]}set[t(1485)+"pe"](r){}get[t(712)](){let r=t;return this._socket[r(712)]}get[t(1007)](){return this[t(1393)].protocol}get[t(207)+"ns"](){let r=t;return this._socket[r(207)+"ns"]}get["buffered"+t(390)](){return 0}}function Hp(a,r){let s=t;if(r)return new r(a[s(712)],a[s(1007)]);if(e[s(1483)](Qr,Rn))return new jp(a[s(712)],a[s(1007)],a.headers);if(e[s(1483)](rr,ei)&&e[s(209)]!=typeof WebSocket&&WebSocket)return new WebSocket(a[s(712)],a[s(1007)+"s"])}function qp(a){let r=t,s="3|4|0|1|2"[r(811)]("|"),l=0;for(;;){switch(s[l++]){case"0":if(Rn&&tt[r(442)+r(210)])return!0;continue;case"1":if(e[r(1021)](rr,ei)&&e[r(347)]("undefined",typeof WebSocket)&&WebSocket)return!0;continue;case"2":return!1;case"3":if(a)return!0;continue;case"4":if(Qr&&wx[r(442)+r(210)])return!0;continue}break}}function xl(a,r,s){let l=t,f={WouBw:function(S,p,O){return e[W(786)](S,p,O)},WpSya:e[l(954)],kpcoa:e[l(184)],MxYuJ:function(S,p){return S!==p},LNIsx:e[l(259)],twqno:function(S,p){return e.XBkfH(S,p)},lfdDn:function(S,p){return e.rfCRr(S,p)}},m=-1;async function b(S){let p=l;if(f[p(1073)](f[p(697)],f.LNIsx)){let O=f[p(901)](_0x531977,f[p(952)],{message:f.kpcoa});this[p(520)+"econnect"]&&this[p(520)+p(1492)](O)}else return S<=m?Promise[p(1054)](new Error(p(966)+p(1468)+p(777)+"imes in "+p(419))):(m=S,f[p(873)](S,s.length)?Promise[p(857)]():s[S][p(595)](a)(r,b.bind(null,f[p(623)](S,1))))}e[l(431)](b,0)}function hl(a){let r=t,s=0,l=0;for(let f=0;e.yJFMv(f,a.length);++f)l=a.charCodeAt(f),e[r(519)](l,128)?s+=1:e[r(1438)](l,2048)?s+=2:e[r(354)](e[r(306)](64512,l),55296)&&(64512&a[r(1395)+"At"](e.tJwcD(f,1)))===56320?(++f,s+=4):s+=3;return s}function pl(a,r,s){let l=t;if(e[l(931)](l(199),"qzode")){if(e[l(382)](e[l(1345)](s,r),1))return"";let f="";for(let m=r;m<s;){let b=a[m++];if(e[l(886)](b,127))f+=String[l(1441)+"Code"](b);else if(b>=192&&e[l(668)](b,224))f+=String[l(1441)+"Code"](e[l(216)](e[l(455)](31&b,6),e[l(1400)](63,a[m++])));else if(e.ejVwn(b,224)&&e[l(1178)](b,240))f+=String["fromChar"+l(1480)](e.NzALN(e[l(455)](e.DlHaS(15,b),12),e[l(805)](63&a[m++],6))|e[l(310)](63,a[m++]));else if(e[l(1440)](b,240)){let S=e[l(1566)](e[l(950)](e.dmqJk(e.GfxNX(e[l(1573)](7,b),18)|e[l(718)](e[l(822)](63,a[m++]),12),e[l(805)](e[l(964)](63,a[m++]),6)),e.LtLtp(63,a[m++])),65536);f+=String["fromChar"+l(1480)](e[l(959)](55296,e.opyqI(S,10))),f+=String[l(1441)+l(1480)](e[l(1484)](56320,e[l(904)](1023,S)))}}return f}else{let f=new _0x538c02(e[l(296)](_0x454b24,_0x4f3bf1));return e[l(797)](_0x4fe074,_0x557b05,f,0),f}}function ma(a,r,s){let l=t,f=s,m,b;for(let S=0;e[l(642)](S,a.length);++S)if(m=a[l(1395)+"At"](S),e[l(588)](m,128))r[s++]=m;else if(e[l(328)](m,2048))r[s++]=e[l(919)](e[l(759)](m,6),192),r[s++]=e[l(755)](e.DBcQt(63,m),128);else if(e[l(1670)](e.Zgjav(64512,m),55296)&&e[l(667)](e[l(1245)](64512,b=a[l(1395)+"At"](e[l(600)](S,1))),56320)){let p=(l(242)+l(423)).split("|"),O=0;for(;;){switch(p[O++]){case"0":r[s++]=e.BHeps(m>>18,240);continue;case"1":m=e[l(477)](65536,e[l(401)](e.vbhlS(1023,m),10))+(1023&b);continue;case"2":++S;continue;case"3":r[s++]=e[l(1326)](e.AfcvZ(e.WRXfM(m,6),63),128);continue;case"4":r[s++]=e[l(216)](e[l(489)](m>>12,63),128);continue;case"5":r[s++]=e[l(303)](e.qnBwc(63,m),128);continue}break}}else r[s++]=e.kZXIJ(e[l(759)](m,12),224),r[s++]=e[l(1018)](m,6)&63|128,r[s++]=e[l(861)](63,m)|128;return e[l(842)](s,f)}async function gl(a){let r=t;if(e[r(810)](e.fLXiq,typeof a)){let s=new Uint8Array(e[r(920)](hl,a));return e.jErWD(ma,a,s,0),s}return e.uXrPY(a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a[r(1451)],a[r(244)+"et"],a[r(785)+"th"])}function Wp(a){let r=t;try{return e[r(347)](e.fLXiq,typeof a)&&(a instanceof ArrayBuffer||a[r(1451)]&&e[r(501)](a[r(1451)],ArrayBuffer))||e.rrkFq(r(917),typeof a)?"":(JSON[r(1648)](a),e.DPOBb)}catch{return e[r(1146)](r(917),typeof a)?e.CtRdI:""}}let Kp=(a,r)=>{let s=t;switch(a){case e.EjiKR:case s(1224):return{[s(1380)+a]:1,"x-tt-env":r};default:return{}}};class $p{constructor(r){let s=t;this[s(773)+s(1047)]=r,this[s(1228)]=0}[t(1665)](){this.count++}[t(1286)+t(515)+"nt"](){let r=t,s={FUgmo:function(l,f,m){return l(f,m)}};if(e[r(772)](r(1612),e[r(671)])){this["_clearPi"+r(1454)](),this["_pingPon"+r(1673)+"Id"]=s[r(172)](_0x578c84,this[r(1504)][r(595)](this),this[r(1645)]["pingInte"+r(895)]);return}else return e[r(1066)](this.count,this[r(773)+r(1047)])}["resetCou"+t(571)](r=0){let s=t;this[s(773)+s(1047)]=r,this[s(1228)]=0}}async function Vp(a){let r=t,s={huGyV:e.pPiYr,QcYud:function(l,f){return e[W(299)](l,f)},TNVZh:e[r(1630)],rRMyQ:function(l,f){return e[r(577)](l,f)},lWKBq:"ydrWe",NGYpS:function(l,f){return e.GQkqB(l,f)},xQhQb:e[r(425)],Scsgp:function(l,f){return e[r(1484)](l,f)},tVBZm:r(432),Bjmgn:e[r(526)],pKXZG:function(l,f){return e.AzcPv(l,f)},CtAus:e[r(1078)],KqZzz:function(l,f){return e[r(296)](l,f)}};return new Promise(l=>{let f=r,m={fvdFx:function(b,S){return s.QcYud(b,S)},hvIsX:s[f(492)]};if(s[f(724)](s.lWKBq,f(1535))){if(!rr)return s[f(1158)](l,s[f(492)]);try{let b=document[f(272)+f(988)](s[f(949)]);window[f(633)+f(579)]=S=>{let p=f;document[p(1131)][p(1165)+p(170)](b),window[p(633)+p(579)]=void 0,m[p(1463)](l,S&&S.msg||m.hvIsX)},b[f(251)]=f(198)+f(1429),b.src=s[f(584)](a[f(1340)](/^ws/,s.tVBZm),s.Bjmgn);try{document[f(1131)][f(1497)+f(170)](b)}catch{if(s.pKXZG(s.CtAus,f(849)))document[f(1131)][f(1165)+f(170)](b);else{if(!this["_navigat"+f(1564)]()||this[f(376)+"osed"])return;this._endpointManager?.[f(590)+f(311)+f(1658)](),this._pingLossCounter?.[f(802)+f(571)](),this[f(1435)]?this[f(1171)+f(647)](1001,s[f(475)],!0):this[f(711)]()}}}catch{window["frontier"+f(579)]=void 0,s[f(309)](l,s.TNVZh)}}else return _0x1ba440||(_0x4ac331=[_0x251ce6[f(733)+"e"][f(749)],_0x1c2c2c[f(733)+"e"][f(1194)],_0x13d317[f(733)+"e"]["continue"+f(420)+"ey"]])})}function sn(a,r,s){let l=t;return!!a?.find(f=>f[l(234)]===r&&f[l(563)]===s)}function ir(a,r){let s=t;return a?.[s(243)](l=>l[s(234)]===r)?.[s(563)]}let wa=null;async function Jp(){let a=t;return wa||(wa=Promise[a(857)]()[a(326)](Ft[a(595)](Ft,e[a(344)]))),wa}class Zp extends ga{constructor(r,s){let l=t;super(),this[l(641)]=r,this[l(204)]=s,this[l(239)]=void 0,this[l(629)+"mise"]=null}async[t(1182)](){await this[t(1225)]()}async _init(){let r=t,s={BsGUi:function(l){return e.lByjl(l)}};if(!this[r(239)]){if(this[r(629)+"mise"])return this[r(629)+r(462)];try{let l=this[r(641)],f=this[r(204)];this[r(629)+"mise"]=(async()=>{let m=r,{openDB:b}=await s[m(746)](Jp);this._qosDB=await b(m(633)+"_"+l,1,{upgrade(S){let p=m;S[p(1359)+p(1010)+"e"](l,{keyPath:f})}})})(),await this[r(629)+r(462)]}catch(l){console.log(l)}finally{e[r(1140)](r(1237),e[r(1643)])?this[r(1555)](_0x465cce,_0x589401):this[r(629)+r(462)]=null}}}async[t(1575)](r){let s=t;if(e.VpRxS(e[s(546)],"LBIKR"))try{return await this[s(1225)](),this[s(239)]?.[s(1575)](this[s(641)],r)}catch(l){console.log(l)}else return null}async set(r,s){let l=t;return await this[l(1225)](),this[l(239)]?.[l(1125)](this[l(641)],r)}async del(r){let s=t;try{return await this._init(),this[s(239)]?.[s(365)](this[s(641)],r)}catch(l){console[s(719)](l)}}async[t(1641)](){let r=t;try{return await this[r(1225)](),this._qosDB?.clear(this[r(641)])}catch(s){if(e[r(373)](r(1464),r(1464)))if(e[r(1677)](_0x5336a6.payload,_0x6da4f9)){let l=e[r(1444)](this[r(1645)]["payloadE"+r(1509)],_0x31c347)?{force:!!this._options.payloadEncoding[r(1644)],encoding:this[r(1645)][r(1279)+"ncoding"][r(1300)]?this[r(1645)]["payloadE"+r(1509)][r(1300)][r(1340)](/\s/g,"")["toLowerC"+r(1024)]():""}:{force:!1,encoding:this[r(1645)][r(1279)+r(1509)]?this[r(1645)][r(1279)+r(1509)][r(1340)](/\s/g,"")[r(466)+"ase"]():""},f=_0x366165[r(1279)+r(1509)]?_0x2e2495[r(1279)+r(1509)][r(1340)](/\s/g,"")[r(466)+r(1024)]():"",m=e.uXrPY(this._options[r(1669)+"ype"],_0x4368e8)?{force:!!this._options[r(1669)+r(1585)].force,type:this._options.payloadType[r(251)]?this[r(1645)][r(1669)+r(1585)][r(251)].replace(/\s/g,"")[r(466)+r(1024)]():""}:{force:!1,type:this._options[r(1669)+r(1585)]?this[r(1645)][r(1669)+"ype"][r(1340)](/\s/g,"")[r(466)+"ase"]():""},b=_0x388343[r(1669)+r(1585)]?_0x36070b[r(1669)+r(1585)][r(1340)](/\s/g,"")[r(466)+"ase"]():"",S=m.force?m[r(251)]:b||m[r(251)],p=l[r(1644)]?l[r(1300)]:f||l[r(1300)],O=[e.CtRdI,"applicat"+r(568),e[r(1456)],e[r(1439)]],L=[e.RGNrB,r(392)];this[r(1645)][r(1486)+r(1446)+r(754)+"ad"]&&O.includes(S)&&(!p||L.includes(p))?_0x487b12[r(921)+"oad"]=e[r(797)](_0x16ddc1,_0x2453c5[r(1223)],0,_0x4ee7bf[r(1223)][r(785)+"th"]):_0x335976[r(921)+r(487)]=""}else _0x3aa6d1["textPayl"+r(487)]="";else console[r(719)](s)}}async keys(){let r=t;return await this[r(1225)](),this[r(239)]?.[r(1252)+"ys"](this._dbName)}async getAll(){let r=t;return await this[r(1225)](),this[r(239)]?.[r(485)](this[r(641)])}async closeDB(){let r=t;try{e[r(1408)](e[r(416)],e[r(1601)])?(this[r(239)]?.[r(1417)](),this._qosDB=void 0):(this.emit(e[r(308)],_0x4e6d57),this[r(1331)]&&this[r(1331)](_0x206f3e))}catch(s){console[r(719)](s)}}get[t(229)](){let r=t;if(e[r(539)](e.ZgMVb,e[r(791)]))try{return!!this[r(239)]}catch(s){if(e[r(313)]!==e[r(313)])_0x330479=e[r(981)](_0x586997,_0xeb3c7),_0x3c041f=0;else return console[r(719)](s),!1}else _0x2a1a9d[r(841)](_0x203ad9,_0x9bb622)}}class Yp{constructor(r,s){let l=t;this[l(879)]=r,this[l(1043)]=s,this._qosDB=localStorage}async[t(1182)](){}get[t(1629)](){return t(633)+"_"+this._DBName}async[t(1575)](r){let s=t;if(e[s(935)](s(609),e.tFZYX))this[s(169)+s(531)]();else{let l=this._qosDB.getItem(this[s(1629)]);return JSON.parse(l||"{}")[r]}}async[t(841)](r,s){let l=t,f=this._qosDB[l(1591)](this[l(1629)]),m=JSON.parse(e[l(1483)](f,"{}"));return m[s||r[this[l(1043)]]]=r,this[l(239)][l(809)](this._prefix,JSON[l(218)+"y"](m)),s||r[this._pathKey]}async[t(631)](r){let s=t;if(e.yHgTi!=="hdRSf"){let l=this[s(239)][s(1591)](this[s(1629)]),f=JSON[s(1648)](e.ETiVu(l,"{}"));return f[r]=void 0,this._qosDB.setItem(this[s(1629)],JSON.stringify(f))}else _0x184a79.exports=_0x2ba893[s(857)]().then(()=>(_0x3b333e(),_0x276ae5))[s(326)](function(l){return l})}async[t(1641)](){let r=t;return e.CYsVf(r(679),e.Wysxz)?_0x3e214a[r(857)]():this[r(239)][r(1641)]()}async[t(997)](){let r=t,s=this[r(239)].getItem(this[r(1629)]),l=JSON[r(1648)](e[r(1483)](s,"{}"));return Object.keys(l)}async getAll(){let r=t,s=this[r(239)][r(1591)](this[r(1629)]),l=JSON[r(1648)](e[r(764)](s,"{}"));return Object.values(l)}[t(266)](){let r=t;return r(1085)===r(1085)?Promise.resolve():new _0x2eaff2(_0x42e368,{data:_0x57dc68,message:_0x528034})}get[t(229)](){return!!this._qosDB}}class Xp{constructor(r,s){let l=t;this[l(879)]=r,this[l(1043)]=s,this._qosDB=Rn?tt:Qr?wx:null}async[t(1182)](){}get[t(1629)](){let r=t;if(e[r(611)](e[r(730)],e.axccn)){let s=this[r(971)+"rs"][_0xafe5a2];if(s)s[r(1337)]()[r(1652)](l=>l.fn[r(1324)](l[r(509)],_0x177ef4));else if(_0x4c48ae==="error"&&!this[r(1322)]){let l=_0x333eac.length&&_0x497dfd[0];if(e[r(1306)](l,_0x28b1ce))throw l;let f=new _0x98ad1e(e[r(817)]+(l?e[r(729)](e[r(1619)](" (",l.message),")"):""));throw f.context=l,l}return this}else return r(633)+"_"+this._DBName}async get(r){let s=t,l=this[s(239)][s(1379)+"geSync"](this._prefix);return JSON[s(1648)](e[s(764)](l,"{}"))[r]}async set(r,s){let l=t,f=this[l(239)][l(1379)+l(1621)](this[l(1629)]),m=JSON.parse(e.ETiVu(f,"{}"));return m[s||r[this._pathKey]]=r,this[l(239)][l(828)+l(1621)](this[l(1629)],JSON.stringify(m)),s||r[this._pathKey]}async[t(631)](r){let s=t,l=this[s(239)][s(1379)+s(1621)](this[s(1629)]),f=JSON.parse(e[s(1021)](l,"{}"));return f[r]=void 0,this._qosDB[s(828)+s(1621)](this._prefix,JSON[s(218)+"y"](f))}async clear(){let r=t;return this[r(239)][r(1350)+"rageSync"]()}async[t(997)](){let r=t,s=this[r(239)]["getStora"+r(1616)+"nc"](this._prefix),l=JSON.parse(s||"{}");return Object[r(997)](l)}async getAll(){let r=t,s=this[r(239)]["getStora"+r(1616)+"nc"](this[r(1629)]),l=JSON[r(1648)](e.PGUtW(s,"{}"));return Object.values(l)}[t(266)](){return Promise.resolve()}get isReady(){return!!this[t(239)]}}function ml(a,r){let s=t,l={QPeeM:function(f,m){return e[W(323)](f,m)},pWhUn:function(f,m){return f+m},wsDQI:function(f,m){return e[W(731)](f,m)},boBzY:function(f,m){return e[W(600)](f,m)},kmHWh:function(f,m){return e[W(181)](f,m)},qXfXP:function(f,m){return e[W(729)](f,m)},HcMby:function(f,m){return e[W(585)](f,m)},nQEdi:function(f,m){return e[W(384)](f,m)},pHjiW:function(f,m){return f+m},qjHDr:function(f,m){return e[W(1281)](f,m)}};if(e[s(956)](s(445),e[s(176)])){let f=_0x1aa63f.low,m=_0x4ae274[s(1660)];return _0x355769[_0xff6ed8]=l.QPeeM(m,24),_0x12c8fb[l[s(1012)](_0x1f191c,1)]=l[s(1248)](m>>>16,255),_0x579377[l[s(807)](_0x4a0979,2)]=l.kmHWh(m,8)&255,_0x46be74[l[s(807)](_0x26ff2d,3)]=l[s(1248)](255,m),_0x30304f[l[s(1012)](_0xdd41f0,4)]=f>>>24,_0x239f55[l[s(1599)](_0x3293bd,5)]=l[s(1248)](l[s(1473)](f,16),255),_0x4168b9[_0xc65c4b+6]=l[s(341)](l[s(329)](f,8),255),_0x2ae498[l[s(1500)](_0x5cc29e,7)]=l.qjHDr(255,f),_0x5bd36f+=8,_0x31e2d4}else{if(e.vWOBM(Rn,Rn))return new Xp(a,r);if(e[s(1021)](rr,ei)&&e[s(209)]!=typeof indexedDB)return new Zp(a,r);if(e.ueMCw(rr,ei)&&e[s(209)]!=typeof localStorage)return new Yp(a,r);throw new Error(e[s(1638)])}}class Qp{constructor(){let r=t;this[r(169)+r(596)+"Id"]=null,this._interval=36e5,this[r(239)]=ml(e[r(992)],r(604)+"id")}async[t(169)+t(531)](){let r=t,s={zOtoi:function(l,f){return l|f},REQmt:function(l,f){return e.GPxLE(l,f)},gMYEV:function(l,f){return l>>f},SvBNe:function(l,f){return l>>f},VxRWR:function(l,f){return l&f},FmNbM:function(l,f){return e[W(1154)](l,f)},QWYvA:function(l,f){return e[W(663)](l,f)}};e.BkjzZ(r(1478),e[r(1674)])?(_0x31f7be<65536?_0x498b69[_0x3a41b4++]=bSyhiK[r(708)](bSyhiK[r(622)](bSyhiK.gMYEV(_0x517397,12),15),224):(_0x2f8c40[_0xc0d2bf++]=bSyhiK.zOtoi(bSyhiK[r(622)](bSyhiK[r(613)](_0x1ec337,18),7),240),_0x15a077[_0x91cac2++]=bSyhiK[r(708)](bSyhiK.VxRWR(bSyhiK.FmNbM(_0x10edc9,12),63),128)),_0x419869[_0x39f13d++]=bSyhiK[r(708)](bSyhiK[r(1375)](bSyhiK.QWYvA(_0x5ad8a0,6),63),128)):(e[r(825)](clearInterval,this[r(169)+r(596)+"Id"]),this["_interva"+r(596)+"Id"]=e.XlATz(setInterval,()=>{this[r(815)+"ired"]()},this._interval))}async[t(1182)](){let r=t,s={kPcAF:function(l,f){return l===f},pyYCb:e[r(368)],MdGsD:function(l,f){return l(f)},SOCeJ:function(l,f){return e[r(1496)](l,f)},fBJXn:function(l){return l()}};if(e[r(813)](e[r(1317)],e[r(979)]))await this[r(239)][r(1182)]()[r(326)](()=>{this[r(169)+"lFlush"]()});else return BlGfbl.kPcAF(typeof _0x423a2f,BlGfbl[r(312)])?BlGfbl[r(1413)](_0x4f3c74,_0x337919):(BlGfbl.SOCeJ(_0x2d0010,_0x4d391e)&&_0x48ff79(_0x344dee),_0x512fdb(_0x122250,BlGfbl.fBJXn(_0x26e960))?new _0x21a981(_0x41e10f,_0x3535d8):_0x572b0e)}async["flushExp"+t(827)](){let r=t;(await this[r(239)]?.[r(485)]()||[])[r(1488)](({timestamp:f})=>f<Date.now()).forEach(f=>{let m=r;this._qosDB?.[m(631)](f[m(604)+"id"])})}async[t(631)](r){let s=t;if(e[s(661)](e[s(789)],e[s(789)]))return this[s(239)]?.[s(631)](r);{let l=_0x42fabf(_0x297ed2,_0x39eeb2[s(284)]);_0x2751c7[s(1278)][s(841)](_0x28a43e,l)}}async set(r,s){let l=t;return this[l(239)]?.[l(841)]({message_id:r,timestamp:s})}async get(r){let s=t;return this[s(239)]?.[s(1575)](r)}async[t(266)](){let r=t;e[r(1592)](clearInterval,this._intervalTimeoutId),await this[r(239)]?.closeDB()}get[t(229)](){let r=t;return this[r(239)]?.[r(229)]}}function _a(a){let r=t;if(e[r(897)](e.ZJwSb,e[r(295)]))return _0x5beafb|=0,{low:_0x123dc7,high:e[r(1154)](_0x1a6c49,31),unsigned:_0x521564>=0};{let s=!!this[r(1645)][r(1389)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=e[r(1029)](sn,a[r(301)][r(1199)],e.gtZCw,"2"),f=l&&sn(a[r(301)][r(1199)],r(319)+"er_qos_ack","1"),m=l&&e[r(1547)](sn,a[r(301)][r(1199)],e[r(645)],"1"),b=m?ir(a[r(301)].headers,e[r(874)])?.[r(811)](",")[r(1488)](Boolean)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:f,isAckCleanupMessage:m,ackMsgIds:b}}}async function wl(){let a=t;return this[a(315)+a(794)]||(this[a(315)+"ger"]=new Qp),this["_QoSMana"+a(794)][a(229)]||await this[a(315)+a(794)][a(1182)](),this[a(315)+"ger"]}async function eg(a,r){let s=t,{enableAutoAck:l}=this[s(1645)],f=e.KktkJ(sn,a.message.headers,s(1608),"1"),m=e[s(1545)](sn,a[s(301)].headers,e[s(317)],"1"),b=_a.call(this,a);if(l&&f){let{SeqID:S,LogID:p,service:O,LogIDNew:L,method:N}=a.message;this[s(1384)]({SeqID:S,LogID:p,LogIDNew:L,service:O,method:N,headers:[{key:e[s(317)],value:"1"},{key:e[s(684)],value:e[s(436)](L,"")},{key:e[s(357)],value:"0"}]})}m&&!b[s(1156)]&&this["_dispatchAckMess"+s(231)](a),r()}async function tg(a,r){let s=t;this[s(974)](e[s(454)],a[s(301)]),e[s(617)](r)}async function ng(a,r){let s=t,l={nWKnP:function(f,m,b,S){return e.gjwSt(f,m,b,S)},sTjsm:"error"};if(e[s(1302)](e[s(280)],e[s(322)])){let f=e.kgkln(tn,await e.qDxZG(gl,a[s(1448)]));try{if(e[s(627)](f[s(1223)],Uint8Array)){let m=this[s(1645)][s(1279)+s(1509)]instanceof Object?{force:!!this[s(1645)][s(1279)+s(1509)][s(1644)],encoding:this._options[s(1279)+"ncoding"].encoding?this[s(1645)]["payloadE"+s(1509)][s(1300)][s(1340)](/\s/g,"")["toLowerC"+s(1024)]():""}:{force:!1,encoding:this[s(1645)][s(1279)+s(1509)]?this[s(1645)][s(1279)+s(1509)][s(1340)](/\s/g,"")[s(466)+s(1024)]():""},b=f["payloadE"+s(1509)]?f[s(1279)+s(1509)].replace(/\s/g,"")[s(466)+"ase"]():"",S=this[s(1645)][s(1669)+s(1585)]instanceof Object?{force:!!this[s(1645)][s(1669)+"ype"][s(1644)],type:this[s(1645)]["payloadT"+s(1585)][s(251)]?this[s(1645)][s(1669)+"ype"][s(251)][s(1340)](/\s/g,"")[s(466)+s(1024)]():""}:{force:!1,type:this._options["payloadT"+s(1585)]?this._options[s(1669)+s(1585)][s(1340)](/\s/g,"")[s(466)+s(1024)]():""},p=f[s(1669)+"ype"]?f[s(1669)+s(1585)][s(1340)](/\s/g,"")[s(466)+s(1024)]():"",O=S[s(1644)]?S.type:p||S[s(251)],L=m[s(1644)]?m[s(1300)]:b||m[s(1300)],N=[s(1676)+"in;chars"+s(253),e.DPOBb,e[s(1456)],e[s(1439)]],U=[s(1122)+"e",e[s(866)]];this._options[s(1486)+s(1446)+"extPayload"]&&N[s(1443)](O)&&(!L||U[s(1443)](L))?f["textPayl"+s(487)]=pl(f.payload,0,f[s(1223)][s(785)+"th"]):f[s(921)+s(487)]=""}else f[s(921)+"oad"]=""}catch(m){f[s(921)+"oad"]="",console[s(719)](m)}a[s(301)]=f,e.fgkmp(r)}else try{l[s(1314)](_0x50c418,this,_0x5acd80,[_0x3a2422,_0x889225,_0x50c1f6])}catch(f){let m=_0x32b111(l[s(1091)],{message:f[s(301)],code:_0x44e88c[s(599)+"OR"],error:f});this[s(404)+s(939)+s(736)](m)}}function rg(a,r,s){let l=t;if(e[l(1361)]!==e[l(1361)])_0x496228=_0x5f08e8.charCodeAt(_0x114fc3),_0x33813c<128?_0x10c8ad+=1:e[l(732)](_0x4c9ef6,2048)?_0x4881cf+=2:e.WNQhP(e[l(1103)](64512,_0x263b53),55296)&&e[l(858)](e[l(241)](64512,_0x3e4b53[l(1395)+"At"](_0x2d3843+1)),56320)?(++_0xe831e1,_0x9b1733+=4):_0x291f76+=3;else{let f=e[l(1253)](s,8192),m=e[l(1572)](f,1),b=null,S=f;return function(p){let O=l;if(e[O(328)](p,1)||p>m)return e[O(1193)](a,p);e.yTgOY(e[O(710)](S,p),f)&&(b=a(f),S=0);let L=r.call(b,S,S+=p);return e[O(194)](7,S)&&(S=e[O(574)](7|S,1)),L}}}let ig=4294967295;function sg(a,r,s){let l=t;return RangeError(e[l(1105)](e[l(597)](e[l(1205)](e[l(304)]+a,e[l(1338)]),e[l(1657)](r,1)),e[l(559)])+s)}function og(a,r,s){let l=t;if(e[l(1102)]===e[l(1102)]){if(e[l(1058)](s,ig))throw new Error(e.TdHzM);let f=3;for(;e.urDYL(f,0);){let m=255&s;e[l(1029)](ba,m,a,r+f),s>>>=8,f--}return e.kEPZI(r,4)}else{let f=_0x31ba1b(_0x48ee04),m=_0x166c33.limit;return _0x2ece5b[l(1419)]=e.PwZiL(_0x3f0ed6[l(1647)],f),m}}function ag(a,r){let s=t;if(e.olttg(e[s(1348)],e.rSDKG)){let l=0,f=r,m=e[s(1051)](r,4);for(;e[s(548)](f,m);){let{value:b,offset:S}=ya(a,f);f=S,l=e.lNecd(l,8)>>>0,l+=b}return{value:l,offset:m}}else return this[s(1393)][s(1485)+"pe"]}function cg(a,r,s){let l=t,f=(l(387)+"0")[l(811)]("|"),m=0;for(;;){switch(f[m++]){case"0":return e[l(1086)](ma(a,r,s),s);case"1":if(r[l(237)+"e"])return e[l(1086)](r.utf8Write(a,s),s);continue;case"2":if(r[l(375)])return e[l(725)](r[l(375)](a,s),s);continue;case"3":if(!a)return s;continue;case"4":if(e.djQzp(a[l(284)],40))return e[l(1185)](ma,a,r,s)+s;continue}break}}function dg(a,r){let s=t,l=new he(e[s(942)](e[s(467)](e[s(385)](a[r+4],24)|a[e.DYrDp(r,5)]<<16,a[e[s(1191)](r,6)]<<8),a[e[s(444)](r,7)]),a[e.rOOMq(r,0)]<<24|e[s(1243)](a[r+1],16)|e[s(1508)](a[e[s(913)](r,2)],8)|a[r+3],!0);return r+=8,{value:l,offset:e.zngkG(r,8)}}function lg(a,r,s){let l=t,f=a[l(362)],m=a[l(1660)];return r[s]=e[l(1571)](m,24),r[e[l(235)](s,1)]=e.FaALx(e[l(927)](m,16),255),r[e.PJJvx(s,2)]=e[l(1080)](e[l(1424)](m,8),255),r[e[l(440)](s,3)]=e[l(300)](255,m),r[e.DdEBS(s,4)]=e[l(1020)](f,24),r[e[l(1329)](s,5)]=e[l(1262)](e[l(1668)](f,16),255),r[e[l(1604)](s,6)]=e[l(634)](e[l(771)](f,8),255),r[s+7]=e[l(1458)](255,f),s+=8,s}function ya(a,r){let s=t;return a.readUInt8?{value:a[s(1155)+"8"](r),offset:e[s(458)](r,1)}:{value:e[s(564)](255,a[r]),offset:e[s(1299)](r,1)}}function ba(a,r,s){let l=t;return r[l(1218)+"t8"]?r[l(1218)+"t8"](a,s):r[s]=255&a,e[l(1157)](s,1)}let ug=function(a){let r=t;if(e[r(1391)](e[r(503)],e[r(503)]))return new Uint8Array(a);this[r(1342)](e[r(252)],e[r(1032)](_0x45be09,e.gNbiL,{..._0x15e8dc}))},fg=e.nTmNw(e.cfNej,typeof Buffer)?Buffer[t(189)+t(1236)]:e[t(1067)](rg,ug,Uint8Array[t(733)+"e"].subarray),xg=16,Ea=32;function hg(a){let r=t,s={qmrbl:function(m,b){return m(b)},FJpCE:function(m,b){return e[W(1577)](m,b)},uSMyH:function(m,b){return e[W(778)](m,b)},aUiyN:function(m,b){return e.YQaxG(m,b)},iGzov:function(m,b){return m(b)},acHQo:function(m,b){return e.LratA(m,b)},CBwzn:function(m,b){return e[W(306)](m,b)},yXTnZ:function(m,b){return e.Jizco(m,b)}},l=0,f={};for(let m=0;m<a[r(284)];m++)e[r(1210)](e[r(1553)],r(821))?(_0x416c1a=zeaAIb[r(1050)](_0x302c8f,_0x8a456),_0x56ad72|=zeaAIb[r(1163)](zeaAIb.uSMyH(127,_0x46b4af),14),zeaAIb.uSMyH(128,_0xac03bf)&&(_0x24b22d=_0x11e50a(_0x3630be),_0x3fe088|=(127&_0x482872)<<21,zeaAIb[r(1008)](128,_0x6c86e3)&&(_0x963914=zeaAIb[r(371)](_0x5822df,_0x442fb7),_0x3cf563=zeaAIb.acHQo(127,_0x3c7b7a),zeaAIb[r(569)](128,_0x377dd2)&&(_0x1bfb2c=zeaAIb.yXTnZ(_0x3c3236,_0x8b0c97),_0x3ea024|=zeaAIb[r(1163)](zeaAIb[r(1008)](127,_0x3e6460),7))))):(f[a[m][r(1377)+r(342)]]=e[r(1502)](hl,a[m][r(1377)+r(342)]),l+=e[r(1461)](14,f[a[m][r(1377)+r(342)]]));return[l,f]}function _l(a,r,s){let l=t,[f,m]=e[l(256)](hg,a),b=e[l(1193)](fg,f),S=0;return a.forEach(p=>{let O=l;console[O(719)]("cursor.s"+O(618),p,p[O(1089)]),S=ba(0,b,S),console.log(e.doJEv,S),S=e.Ypbjc(og,b,S,p.service||0),console[O(719)](e.jXZow,S),S=e[O(1610)](ba,m[p[O(1377)+O(342)]],b,S),console[O(719)](e.EUhRf,S),S=e.akzRG(cg,p[O(1377)+O(342)],b,S),console[O(719)]("name",S),S=e[O(797)](lg,he[O(1579)+"er"](p[O(213)]||r),b,S),console[O(719)](O(635),S)}),{frameType:Ea,headers:[{key:e[l(1081)],value:s}],payload:b}}function pg(a){let r=t,s=0,l=[];for(;e[r(328)](s,a[r(785)+"th"]);){let{offset:f}=e[r(339)](ya,a,s);s=f;let m={cursor_name:"",cursor:0,service:0},{value:b,offset:S}=e[r(747)](ag,a,s);m[r(1089)]=b,s=S;let{value:p,offset:O}=ya(a,s);s=O,m.cursor_name=e[r(795)](pl,a,s,e.CMcnG(s,p)),s+=p;let{value:L,offset:N}=e[r(1308)](dg,a,s);m[r(213)]=L[r(327)](),s=N,l[r(190)](m)}return l}function gg(){return{frameType:Ea,headers:[{key:t(780)+"ile_name",value:e.YPfOm}],payload:void 0}}class mg{constructor(r,s,l){let f=t;this["_cursorN"+f(620)]=r,this[f(167)+f(265)]=s,this._messageStrategy=l,this[f(239)]=e.EPkdJ(ml,this[f(282)+f(620)],e[f(478)])}async[t(1182)](){let r=t;await this[r(239)][r(1182)]()}async[t(220)+"rs"](){let r=t;if(!this[r(239)][r(229)])return;let s=this[r(377)+r(829)],l=await this[r(239)][r(485)]();switch(console[r(719)](e.jPFQM,l),s){case e[r(1123)]:return l&&l[r(284)]?_l(l,0,this[r(167)+r(265)]):void 0;case r(433):return;case r(396):return l&&l[r(284)]?e[r(1029)](_l,l,0,this[r(167)+"ileName"]):e[r(547)](gg)}}async[t(841)](r,s,l){let f=t;if(e.TTDTK(f(1003),f(1617)))return console[f(719)](e[f(918)],r,s,l),this[f(239)][f(841)]({cursor_name:r,cursor:s,service:l});CLxnFX[f(1469)](_0x38bf33,_0x5ea82d(_0x576fae[f(1274)])),_0x457998()}async[t(1434)+"rs"](r){let s=t,l=e[s(981)](pg,r);for(let f of l)console[s(719)](e.yJTSZ,l),await this[s(239)].set(f)}async[t(1575)](r){let s=t;return(await this._qosDB[s(1575)](r))?.cursor}async[t(266)](){let r=t;e.aKFAF(r(1077),e[r(951)])?await this[r(239)].closeDB():this[r(1555)](_0x2e2510,_0x2fa2f6)}[t(1316)+t(1174)+t(739)](r){let s=t;this["_cursorF"+s(265)]=r}get[t(229)](){let r=t,s={EiAUX:function(l,f,m){return e[W(262)](l,f,m)},fLGEy:function(l,f,m,b){return e.teUjz(l,f,m,b)},LaJDK:function(l,f){return e.KsCfq(l,f)}};if(e[r(1511)](e[r(1540)],r(1493)))return this[r(239)][r(229)];{let{offset:l}=TNkmef[r(799)](_0x102753,_0x186267,_0x29ad0b);_0x3512fd=l;let f={cursor_name:"",cursor:0,service:0},{value:m,offset:b}=TNkmef.EiAUX(_0x22740a,_0x4c9aaf,_0x18f7f6);f[r(1089)]=m,_0x2dc543=b;let{value:S,offset:p}=TNkmef.EiAUX(_0x1ec5ff,_0x1adfcd,_0x4388fc);_0x277306=p,f[r(1377)+r(342)]=TNkmef[r(769)](_0x2c0237,_0x2c398b,_0x5d1c48,TNkmef.LaJDK(_0x306b3e,S)),_0x3e78d3+=S;let{value:O,offset:L}=TNkmef[r(799)](_0x388cca,_0x571520,_0x41a7af);f[r(213)]=O[r(327)](),_0x430194=L,_0x271cc8[r(190)](f)}}}let wg=e[t(1402)];async function yl(a){let r=t;if(!this[r(1645)].enableQoS)return null;let{aID:s,fpID:l,messageStrategy:f}=this[r(1645)],m=e[r(985)](a,wg);try{return this[r(1297)+r(343)]?a&&this[r(1297)+r(343)]["updateCu"+r(1174)+"Name"](a):this[r(1297)+r(343)]=new mg(l+"_"+s+"_"+m,m,f),this[r(1297)+r(343)][r(229)]||await this[r(1297)+r(343)][r(1182)](),this[r(1297)+"anager"]}catch{return null}}async function _g(a,r){let s=t,l={PTsDj:function(f,m){return e[W(305)](f,m)},kPiYI:e[s(209)],PdBlf:s(356)};if(e[s(661)](e[s(191)],e[s(191)])){let f=sn(a[s(301)].headers,s(1679),"-1"),m=e[s(1563)](sn,a.message.headers,e[s(317)],"1"),b=e.wmQbH(ir,a[s(301)][s(1199)],e.MJlms),S=Number(e[s(233)](ir,a[s(301)].headers,e[s(1633)]))||0,p=_a[s(851)](this,a),O=e.KktkJ(sn,a.message[s(1199)],e.PpMXg,"2"),L=ir(a[s(301)][s(1199)],e[s(1365)]),N=e[s(264)](Number,e[s(1626)](ir,a.message[s(1199)],e[s(1036)]));if(p[s(1156)])return e[s(1614)](r);let U=p[s(834)+"sage"]?await wl[s(851)](this):null;if(e[s(549)](a.message.service,0)&&m&&!f||e.ETPTm(a.message[s(1089)],0)){if(b&&p[s(834)+s(463)]&&U)return!!!await U[s(1575)](b)&&(e[s(858)](e[s(683)],e[s(683)])?(this[s(404)+s(508)+s(516)](a),await U[s(841)](b,Date[s(1352)]()+S)):_0x20c195.r=z=>{let q=s;zMsjWM[q(1479)](zMsjWM[q(536)],typeof _0x4c8be8)&&_0x27b026["toString"+q(279)]&&_0xf8c448[q(607)+q(1447)](z,_0xa967e2[q(330)+q(279)],{value:zMsjWM[q(245)]}),_0x460c19[q(607)+q(1447)](z,"__esModule",{value:!0})}),e.sbcBF(r);if(O){let H=await yl.call(this);if(!H)return this[s(404)+s(508)+"Event"](a),e[s(1614)](r);let z=await H.get(L)??-1;if(e.sdEef(z,N))s(263)!=="zJgsD"?(_0x393496[s(1176)+s(945)+s(1437)](CLxnFX[s(865)],_0x1f5dad),_0x19caa6[s(1176)+s(945)+"ner"](CLxnFX[s(238)],_0xfa461e),_0x3d0920["removeEventListe"+s(1437)](s(491),_0x214468)):(this[s(404)+s(508)+s(516)](a),H[s(841)](L,N,a[s(301)][s(1089)]));else throw new Error(s(434)+" message"+s(203)+N+(s(200)+s(1574)+s(983)+"r ")+z);return e.NhVIW(r)}return this[s(404)+s(508)+s(516)](a),e[s(337)](r)}}else this[s(879)]=_0x2f1213,this[s(1043)]=_0x29c57a,this[s(239)]=_0xda90c9?_0x35640d:_0x4c9bd0?_0x12120b:null}async function yg(a,r){let s=t,l=_a[s(851)](this,a);if(!l[s(834)+s(463)])return r();let f=await wl[s(851)](this);if(l[s(541)+s(363)+s(621)]&&l[s(1628)+"s"][s(284)])for(let m of l[s(1628)+"s"])await f[s(631)](m);e.tMbql(r)}async function bg(a,r){let s=t,l=a[s(301)][s(868)+"e"]===xg,f=e[s(665)](a[s(301)][s(868)+"e"],Ea);if(!l&&!f)return e.fgkmp(r);let m=e[s(339)](ir,a[s(301)][s(1199)],s(780)+"ile_name");if(!m)return e[s(1289)](r);let b=await yl[s(851)](this,m);if(!b)return e.acFNA(r);if(l){let S=await b[s(220)+"rs"](),p={frameType:S?.[s(868)+"e"],SeqID:he[s(1579)+"er"](this._seqId++),LogID:he.fromNumber(this._options[s(871)+"erator"]()),service:9e3,method:5,headers:S?.headers,payload:S?.[s(1223)]},O=e.FGSQr(v,p);this[s(1435)]&&this._ws[s(907)+"te"]&&this[s(1435)][s(1173)](O)}if(f)if(e.IcClp(e[s(495)],e.doroo)){let S=a[s(301)][s(1223)];S&&b[s(1434)+"rs"](S)}else{let S=e.wNPiE[s(811)]("|"),p=0;for(;;){switch(S[p++]){case"0":this[s(1435)][s(1139)+s(1503)](e[s(681)],this[s(1121)]);continue;case"1":if(!this[s(1435)])return;continue;case"2":this[s(1435)][s(1139)+s(1503)](e[s(252)],this[s(987)+"ge"]);continue;case"3":this[s(1435)]["addEvent"+s(1503)](e[s(238)],this[s(938)]);continue;case"4":this[s(1435)][s(1139)+s(1503)](e[s(308)],this[s(977)]);continue}break}}}let Eg=async function(a,r){let s=t;this._isInit=!1,e[s(415)](clearTimeout,this[s(711)+s(386)+s(1011)]),e[s(768)](r)},vg=async function(a,r){let s=t;if(!this[s(1435)]||this[s(1435)].readyState!==this[s(1495)])return e[s(374)](r);let{pingInterval:l}=this[s(1645)];this[s(364)+s(561)]?.[s(590)+s(311)+s(1658)]();for(let m=0;e[s(382)](m,this[s(377)+s(1565)][s(284)]);m++)if(e[s(772)](s(1293),e[s(740)])){let b=this["_message"+s(1565)][m];if(e[s(1391)](this[s(1435)][s(907)+"te"],this[s(1495)])&&e[s(418)](null,b))this[s(1435)]&&this._ws[s(1173)](b),this["_message"+s(1565)][m]=null;else break}else return e[s(1442)](e[s(1028)](_0x2aa426,4)[s(1276)]("0"),e[s(1079)](_0x27dc89,_0x2d2c3f,2)[s(330)](16))[s(1337)](-4);this[s(377)+s(1565)]=this[s(377)+s(1565)][s(1488)](m=>!!m),this[s(378)+s(1673)+"Id"]=e.nOdIZ(setTimeout,()=>this[s(1504)](),l),this["_dispatc"+s(1584)+"nt"](a),this[s(883)+"er"]&&this._ws&&(this[s(1435)][s(1485)+"pe"]=this[s(1133)+"ype"]);let f=this._endpointManager?.[s(1532)+s(957)+"nt"]();this[s(974)]("open "+f+" success"),e[s(374)](r)},Sg=async function(a,r){let s=t,l=this[s(364)+s(561)]?.[s(1532)+s(957)+"nt"]();this._debug(s(1596)+l),e.UyODh(r)};class Ig extends ga{constructor(r){let s=t,l={fkxPS:e[s(254)],BWkxv:function(S,p){return e.CMcnG(S,p)},wmMYJ:function(S,p){return e[s(577)](S,p)},LmloF:function(S,p){return e[s(582)](S,p)},PHrJc:function(S,p){return e[s(751)](S,p)},lJNuF:function(S,p){return e[s(1577)](S,p)},QFwCt:function(S,p){return e.NXrBW(S,p)},JzMxZ:function(S,p){return S&p},GGCTf:function(S,p){return S<p},cnTVc:function(S,p){return e[s(457)](S,p)}};super(),this["_miniNavigatorOn"+s(748)]=!0,this._isBrowser=rr,this[s(1177)]=Gp,this._isMiniTT=Rn,this._isMiniWX=Qr,this._isWorker=ei,this["_message"+s(1565)]=[],this["_endpoin"+s(561)]=null,this[s(376)+s(1100)]=!1,this["_binaryT"+s(1585)]=e[s(863)],this[s(711)+s(1101)]=!1,this[s(711)+s(386)+s(1011)]=null,this["_reconnectTimeou"+s(1606)]=null,this[s(378)+s(1673)+"Id"]=null,this[s(438)]=0,this[s(972)]=!1,this[s(1407)]="",this[s(315)+s(794)]=null,this["_cursorM"+s(343)]=null,this[s(1084)+s(1254)]=null,this[s(523)+"ls"]=s(391),this[s(1206)]=3,this[s(1076)+"NG"]=0,this[s(1495)]=1,this[s(1452)]=2,this[s(977)]=S=>{let p=s;try{e[p(1545)](xl,this,S,[Eg,vg,Sg])}catch(O){let L=e[p(271)](lt,e[p(238)],{message:O[p(301)],code:rn[p(599)+"OR"],error:O});this[p(404)+p(939)+p(736)](L)}},this[s(987)+"ge"]=async S=>{let p=s;if(e.MSeMK!==e[p(1301)]){let{pingInterval:O,pingFrequency:L}=this[p(1645)];if((e[p(593)]("hi",S.data)&&e[p(658)]("always",L)||e.paGoJ(e.UZjkK,L))&&(this[p(892)+p(1454)](),this[p(1342)](e[p(1651)],e[p(1383)]),this[p(378)+p(1673)+"Id"]=e.plrXJ(setTimeout,this[p(1504)][p(595)](this),O)),S[p(1448)]==="hi")return;try{e[p(1587)](xl,this,S,[ng,eg,yg,bg,_g,tg])}catch(N){let U=e[p(1414)](lt,e[p(238)],{message:N[p(301)],code:rn.MESSAGE_ERROR,error:N});this[p(404)+p(939)+p(736)](U)}}else{let O=this[p(364)+p(561)]?.[p(1532)+p(957)+"nt"]();this[p(974)](p(1642)+O+p(1023)),this[p(1171)+p(647)](1001,l[p(430)],!0)}},this[s(938)]=S=>{let p=s,O=this[p(364)+"tManager"]?.[p(1286)+p(826)+"es"](),L=this[p(364)+"tManager"]?.["getCurre"+p(957)+"nt"]();if(O&&!S[p(301)]){let N="connect "+L+(p(936)+p(1581)+"es reached");this[p(404)+p(939)+p(736)](lt(e[p(238)],{message:N,code:rn[p(1494)+p(517)+"R"],error:S}));return}this._ws&&e[p(1240)](this[p(1435)].readyState,this.OPEN)&&this[p(1171)+p(647)](),this[p(404)+p(939)+p(736)](e[p(735)](lt,e[p(238)],{message:S[p(301)],code:rn[p(1117)+p(1034)],error:S}))},this._onClose=async S=>{let p=s,O={uSWce:function(L,N){return L+N},iMYTf:function(L,N){return L>N},VcqUZ:function(L,N){return e.xGpIL(L,N)},jKLbO:e[p(758)],bJTXs:function(L,N){return e[p(582)](L,N)},rNVkp:function(L,N){return e[p(691)](L,N)},VeCWd:function(L,N){return L>>>N},LLGMu:function(L,N){return e.YFgge(L,N)}};if(e[p(646)]!==e[p(646)])return this[p(239)]?.isReady;{this._clearTimer(),this["_clearPi"+p(1454)](),this["_removeW"+p(757)+"rs"](),this[p(1435)]=null,this[p(711)+p(1101)]=!1;let L=this["_endpoin"+p(561)]?.[p(1286)+p(826)+"es"]();if(!L&&this[p(1519)+p(1564)]()&&!this[p(376)+"osed"])if(e.qROXn===e[p(910)]){let N=_0x51b1d9.bytes,U=_0x23148d[p(1647)],H=_0x48b83e[p(1419)],z=HyPDog[p(648)](U,_0x303c16);if(HyPDog[p(934)](z,N[p(284)])){let q=new _0x2d0c5e(HyPDog[p(946)](2,z));q.set(N),_0x35ee77.bytes=q}return _0x34486e[p(1647)]=z,HyPDog[p(934)](z,H)&&(_0x552e09[p(1419)]=z),U}else{let N=this["_endpoin"+p(561)]?.[p(1532)+p(957)+"nt"](),U=this._options[p(1611)+p(709)+p(976)](S[p(1679)],S.reason);this["_dispatchCloseEv"+p(736)](e[p(1335)](mt,e[p(681)],{code:1006,reason:S[p(554)]||p(1613)+p(1373)+"d, unknown reaso"+p(870)+p(625)+N,willReconnect:U})),U&&this[p(711)]();return}if(S[p(1679)]!==1e3&&this[p(376)+p(1100)])if(e[p(1598)](e.TJcCd,e.TJcCd)){let N={VXSEz:HyPDog[p(333)],SBvrL:function(H,z){return H|z},ZYdiO:function(H,z){let q=p;return HyPDog[q(995)](H,z)},BKIVE:function(H,z){let q=p;return HyPDog[q(1653)](H,z)},EmfgV:function(H,z){let q=p;return HyPDog[q(1653)](H,z)},eaWOO:function(H,z){return HyPDog.VeCWd(H,z)},WCBYO:function(H,z){return HyPDog.LLGMu(H,z)},Dnnei:function(H,z){let q=p;return HyPDog[q(995)](H,z)},lTNLP:function(H,z){return H<<z},FITYu:function(H,z){let q=p;return HyPDog[q(1653)](H,z)}},U=4294967295;return function(H,z,q=!0){let ne=p,on=N[ne(726)][ne(811)]("|"),sr=0;for(;;){switch(on[sr++]){case"0":U=N[ne(716)](U,N[ne(792)](15,H[z])<<28)>>>0;continue;case"1":return{value:q?U:N[ne(1183)](0,U),offset:z};case"2":U=N[ne(1672)](U,(127&H[z])<<7)>>>0;continue;case"3":U=N[ne(882)](N[ne(716)](U,N[ne(792)](127,H[z])<<21),0);continue;case"4":if(N.WCBYO(H[z++],128))return{value:q?U:0|U,offset:z};continue;case"5":U=N[ne(882)](N[ne(878)](127,H[z]),0);continue;case"6":if(H[z++]<128)return{value:q?U:N.EmfgV(0,U),offset:z};continue;case"7":U=N[ne(882)](N[ne(1672)](U,N.lTNLP(127&H[z],14)),0);continue;case"8":if((z+=5)>H.length)throw z=H[ne(284)],_0x148176(z,10,H[ne(284)]);continue;case"9":if(N[ne(1005)](H[z++],128))return{value:q?U:0|U,offset:z};continue;case"10":if(H[z++]<128)return{value:q?U:N.SBvrL(0,U),offset:z};continue;case"11":if(N[ne(1005)](H[z++],128))return{value:q?U:N[ne(898)](0,U),offset:z};continue}break}}}else{this[p(404)+p(572)+p(736)](e[p(1597)](mt,e[p(681)],{code:1e3,reason:e.YcVIj})),this[p(364)+p(561)]?.[p(590)+p(311)+p(1658)](),this[p(1084)+p(1254)]?.[p(802)+p(571)]();return}if(e[p(922)](1e3,S[p(1679)])&&L){let N=this[p(364)+p(561)]?.["getCurre"+p(957)+"nt"](),U=S[p(554)];U||(U=await e[p(742)](Vp,this._url)),U=p(1613)+p(1373)+p(448)+U+(p(953)+p(1186))+N+(", max re"+p(707)+p(1290)),this[p(404)+p(572)+p(736)](e[p(1134)](mt,e[p(681)],{code:S.code,reason:U}));let H=p(1642)+N+(" fail, m"+p(1581)+p(1418)+"ed");this[p(404)+p(939)+p(736)](lt(e[p(238)],{message:H,code:rn[p(1494)+p(517)+"R"]})),this[p(364)+p(561)]?.[p(590)+p(311)+p(1658)](),this[p(1084)+"sCounter"]?.[p(802)+p(571)]();return}if(e.IcClp(1e3,S[p(1679)])&&!S[p(554)])if(e[p(539)](e[p(1296)],e[p(196)]))_0x3bf4b5=_0x27322c[cQazrw.BWkxv(_0x2d8cf6+_0x1a081e,1)],cQazrw.wmMYJ(cQazrw[p(1019)](192,_0x8ae782),128)?_0x3a6d0a+=_0x5b6358:(_0x2eed97=cQazrw[p(1e3)](cQazrw[p(1282)](cQazrw[p(852)](31,_0x3fd151),6),cQazrw[p(1349)](63,_0x1ce952)),cQazrw[p(1514)](_0x5e5a37,128)?_0x3e781f+=_0xda677:(_0x110207+=cQazrw[p(798)](_0x1e59ff,_0x3b3745),_0x335f3f++));else{let N=this[p(364)+"tManager"]?.[p(1532)+p(957)+"nt"]();this[p(404)+p(572)+p(736)](mt(p(1417),{code:S[p(1679)],reason:p(1613)+p(1373)+p(653)+p(1145)+p(870)+p(625)+N})),this[p(364)+p(561)]?.[p(590)+p(311)+p(1658)](),this[p(1084)+p(1254)]?.[p(802)+p(571)]();return}this[p(404)+p(572)+p(736)](S),this[p(364)+p(561)]?.["resetEnd"+p(311)+p(1658)](),this[p(1084)+p(1254)]?.resetCounter()}},this[s(298)]=null,this.onerror=null,this[s(230)+"e"]=null,this[s(1331)]=null,this.onStartReconnect=null,this["onReceiv"+s(677)]=null,this[s(644)+"mediatel"+s(1370)+"ct"]=null,this[s(294)+s(483)]=this[s(294)+s(483)][s(595)](this),this[s(294)+s(1385)]=this["_handleO"+s(1385)][s(595)](this),this[s(1558)+s(1128)]=this[s(1558)+"ageHide"][s(595)](this),this[s(1558)+s(1195)]=this[s(1558)+s(1195)][s(595)](this),this[s(1645)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(1244)](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.UZjkK,pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e.lghoX,env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:m}=r,b=Array[s(1590)](f)?f:s(917)==typeof f?[f]:[];if(!b||b[s(284)]===0)throw new Error(e[s(688)]);if(!e[s(468)](qp,m))throw new Error(e.mAxtc);Object[s(381)](this[s(1645)],r),this[s(364)+s(561)]=new fl(b,this[s(1645)].maxRetries),this[s(1084)+s(1254)]=new $p(this._options[s(887)+s(1460)]),this[s(1645)][s(930)+"cOpen"]&&(this[s(972)]=!0,this[s(711)]()),this[s(1645)][s(793)+s(664)+s(1001)]&&(this._isMiniTT||this[s(687)+"X"]?this[s(788)+s(832)+s(1022)]():this[s(883)+"er"]&&this[s(1292)+s(1118)+s(1503)]())}[t(294)+t(483)](){let r=t;this[r(1645)][r(533)+r(1232)+r(1409)]||this._readyClosed||this[r(1231)+"econnect"]()}["_handleO"+t(1385)](){let r=t;this["_destroy"+r(839)+"t"]();let s=e[r(1556)](pa,e[r(954)],{message:e[r(756)]});this[r(644)+r(774)+r(1370)+"ct"]&&this[r(644)+"mediatel"+r(1370)+"ct"](s)}[t(1292)+t(1118)+"Listener"](){let r=t;this[r(883)+"er"]&&window[r(1139)+"Listener"](e[r(812)],this[r(294)+"nLine"]),this[r(883)+"er"]&&window.addEventListener(e.XXprd,this[r(294)+"ffLine"]),this._isBrowser&&window[r(1139)+r(1503)](e.kRVQZ,this["_handleP"+r(1128)]),this[r(883)+"er"]&&window[r(1139)+"Listener"](r(287),this[r(1558)+"ageShow"])}["_dropGlo"+t(1118)+"Listener"](){let r=t;this._isBrowser&&window[r(1176)+"entListener"](r(465),this[r(294)+r(483)]),this[r(883)+"er"]&&window[r(1176)+r(945)+r(1437)](r(471),this[r(294)+"ffLine"]),this[r(883)+"er"]&&window[r(1176)+r(945)+r(1437)](e[r(1259)],this[r(1558)+"ageHide"]),this[r(883)+"er"]&&window["removeEventListe"+r(1437)](e[r(497)],this["_handleP"+r(1195)])}[t(1558)+t(1128)](r){let s=t;!r.persisted&&(this[s(883)+"er"]&&window[s(1176)+"entListener"](e.kRVQZ,this["_handleP"+s(1128)]),this[s(883)+"er"]&&window["removeEv"+s(945)+"ner"](s(287),this["_handleP"+s(1195)]),this[s(1417)]()),this[s(883)+"er"]&&window[s(1176)+s(945)+s(1437)](e[s(812)],this[s(294)+s(483)]),this[s(883)+"er"]&&window[s(1176)+s(945)+s(1437)](s(471),this["_handleO"+s(1385)])}[t(1558)+t(1195)](r){let s=t;r.persisted&&(this["_navigat"+s(1564)]()&&(!this._ws||e.DaCFp(this[s(1435)][s(907)+"te"],this[s(1495)])||this[s(1435)].readyState!==this.CONNECTING)&&this["_handleO"+s(483)](),this[s(883)+"er"]&&window.addEventListener(e[s(812)],this[s(294)+s(483)]),this._isBrowser&&window[s(1139)+"Listener"](s(471),this["_handleO"+s(1385)]))}async[t(1487)+t(734)](r){let s=t,l={EACvK:function(f,m){return e.VJAiy(f,m)},oJmxq:function(f,m){return e[W(1326)](f,m)},WYgIU:function(f,m){return e.BOGsn(f,m)},ALfKD:function(f,m){return e[W(718)](f,m)},froWC:function(f,m){return e[W(1205)](f,m)},KEMnI:function(f,m){return e[W(753)](f,m)},xvLlt:function(f,m){return f|m},bovDN:function(f,m){return e[W(573)](f,m)},rECjD:function(f,m){return e.jPhEb(f,m)},HBOso:function(f,m){return e.uZtKF(f,m)},CCkuO:function(f,m){return e.jPhEb(f,m)},NlaJO:function(f,m){return e[W(669)](f,m)}};if(e[s(405)]!==e.mhJtz){let{fpID:f,deviceID:m,bddID:b,ttwID:S,accessKey:p,aID:O,customParams:L={},enableAutoAck:N,enableQoS:U,QoSLevel:H,env:z}=this[s(1645)],q,ne,on;if(this[s(883)+"er"]||this._isMiniWX||this[s(1481)+"T"])q=location&&e[s(659)](e[s(1602)],location[s(1007)])?e.uwhHr:e.fQIyA,ne=r.replace(/((^ws)|(^http))((?:[s]*:\/\/))/,""),on=/^wss(.*:\/\/)/.test(r)?r:""+q+ne;else if(e[s(1559)](e[s(528)],e[s(397)])){let ti=new _0xf843f6(JVHPXm[s(1099)](JVHPXm[s(1099)](JVHPXm[s(173)](JVHPXm[s(1512)](_0x127dbb[_0x3ddfc3+4],24),JVHPXm[s(923)](_0x2c8706[JVHPXm[s(1678)](_0x5ad86f,5)],16)),JVHPXm[s(1512)](_0x3293c9[JVHPXm[s(1678)](_0x58b7de,6)],8)),_0x4494cc[JVHPXm[s(336)](_0x1beaf3,7)]),JVHPXm.xvLlt(JVHPXm.bovDN(JVHPXm[s(173)](JVHPXm[s(923)](_0x455035[_0x1ba980+0],24),JVHPXm[s(1505)](_0x400bbd[JVHPXm.HBOso(_0x1b0951,1)],16)),JVHPXm[s(1353)](_0x54d446[JVHPXm[s(336)](_0x1dd1e8,2)],8)),_0x256c27[JVHPXm[s(336)](_0x3ca445,3)]),!0);return _0x25156d+=8,{value:ti,offset:JVHPXm.NlaJO(_0x3ef5ac,8)}}else q=e[s(784)],ne=r[s(1340)](/(^http)((?:[s]*:\/\/))/,""),on=/(^ws)((?:[s]*:\/\/))/[s(1059)](ne)?ne:""+q+ne;let sr=b?"bd_did":S?e[s(236)]:e[s(776)],ls=b||S||m;if(!ls||!sr)throw new Error(e[s(513)]);let Ag=e[s(232)]("function",typeof L)?await e[s(302)](L):L,kg=z?e.UpmnV(Kp,z[s(713)],z[s(984)]):{},va=Object[s(381)]({device_platform:s(666),version_code:s(1543)+"0",access_key:p,fpid:f,aid:O,[sr]:ls,xsack:N?1:0,xaack:N?1:0,xsqos:U?1:0,qos_level:U?H:void 0,qos_sdk_version:2,...kg},Ag),Tg=Object.keys(va)[s(1213)]((ti,Sa)=>va[Sa]!==void 0?""+ti+(ti?"&":"?")+Sa+"="+va[Sa]:ti,"");return on+s(1656)+Tg}else _0x1b92d3[s(1131)][s(1497)+"ild"](_0x29f276)}async[t(711)](){let r=t;if(!(this[r(711)+r(1101)]||this[r(376)+r(1100)])){this[r(711)+r(1101)]=!0;try{let s=this["_endpoin"+r(561)]?.[r(1624)+r(270)+r(1654)+r(1149)+r(1576)](),{timeoutInterval:l}=this._options;if(s){let m=this[r(364)+r(561)]?.[r(1532)+"ntEndpoint"](),b=this["_endpoin"+r(561)]?.[r(407)+"ackupEnd"+r(1175)+r(1517)+r(750)](),S=this["_endpoin"+r(561)]?.[r(1532)+r(957)+r(409)+r(1047)]();if(b){let p=r(1642)+m+(r(1023)+r(1092)+r(707)+r(1366)+r(1052)+r(413)+r(443))+b+" to retry",O=lt(e[r(238)],{message:p,code:rn[r(1494)+r(517)+"R"]});this._debug(p),this[r(404)+r(939)+r(736)](O),this[r(1407)]=await this[r(1487)+r(734)](b),this._debug(r(1642)+b+" "+S+r(872)),this[r(502)+r(757)+"rs"]()}else{let p=r(1642)+m+(r(1023)+", max retries re"+r(1290));this[r(974)](p),this[r(404)+r(939)+r(736)](e[r(498)](lt,r(246),{message:p,code:rn[r(1494)+r(517)+"R"]}));return}}else if(e[r(1097)](e[r(472)],r(875))){let m=this["_endpoin"+r(561)]?.["getCurre"+r(957)+r(1124)+r(1491)](),b=this[r(364)+r(561)]?.[r(1532)+r(957)+r(409)+"ount"]();this[r(1407)]=await this[r(1487)+"eUrl"](e[r(451)](m,"")),this[r(974)](r(1642)+m+" "+b+r(872)),this[r(502)+"sListeners"]()}else _0x24ebf7=_0x1407c5[r(933)](_0x317635),_0x238050=_0x2b1f63[r(933)](_0xa4056[_0x14f9c7]);if(this._isInit)this[r(972)]=!1;else{let m=pa(e[r(954)],{message:e[r(184)]});this[r(520)+"econnect"]&&this[r(520)+r(1492)](m)}let f=this._endpointManager?.[r(1532)+r(957)+r(409)+r(1047)]()||0;f>1&&await this[r(1130)](f-1),this[r(974)]("connecti"+r(1311)+this[r(1407)]+(r(1476)+r(1096))+this[r(523)+"ls"]),this[r(1435)]=e[r(786)](Hp,{url:this[r(1407)],protocols:[this[r(523)+"ls"]],headers:this._options[r(676)+r(496)+"s"][r(986)+"tpHeader"]},this[r(1645)].ws),(this[r(883)+"er"]||this[r(586)+"r"])&&this[r(1435)]&&(this[r(1435)][r(1485)+"pe"]=this[r(1133)+r(1585)]),this[r(1057)+"steners"](),this[r(711)+r(386)+r(1011)]=e[r(1364)](setTimeout,this[r(1275)+"ut"][r(595)](this),l)}catch(s){if(e.KbWNN(e[r(1637)],e.dHYXl))throw this[r(711)+r(1101)]=!1,s;return _0x4156ff[r(899)+r(1405)][1]?void 0:_0x370ba0[r(899)+"ore"](_0x5ae0a9[r(899)+r(1405)][0])}}}[t(1675)+t(1347)](){let r=t;clearTimeout(this["_connect"+r(386)+r(1011)]),this["_connect"+r(386)+r(1011)]=null}[t(892)+t(1454)](){let r=t;e[r(924)](clearTimeout,this[r(378)+r(1673)+"Id"]),e[r(981)](clearTimeout,this[r(171)+"ctTimeou"+r(1606)]),this[r(378)+"gTimeoutId"]=null,this[r(171)+r(1172)+r(1606)]=null}[t(974)](...r){let s=t;this[s(1645)][s(855)]&&console[s(719)][s(1324)](console,[e[s(745)],...r])}[t(1277)+t(690)+"e"](r){let s=t,{initReconnectInterval:l,maxReconnectInterval:f,reconnectIntervalGrowFactor:m}=this._options,b=e[s(193)](l,Math[s(1025)](m,e[s(175)](r,1)));return e[s(1501)](b,f)?f:b}[t(1504)](){let r=t;if(this[r(1435)]&&this[r(1435)][r(907)+"te"]===this[r(1076)+"NG"]){this[r(892)+r(1454)](),this[r(378)+r(1673)+"Id"]=e.zbNhK(setTimeout,this._ping[r(595)](this),this[r(1645)]["pingInte"+r(895)]);return}if(!this[r(1435)]||e.OhIGs(this[r(1435)][r(907)+"te"],this[r(1495)]))return void this[r(1231)+"econnect"]();this[r(1435)]&&this._ws[r(1173)]("hi"),this[r(171)+r(1172)+r(1606)]=e[r(998)](setTimeout,this["_handleR"+r(1492)+r(1196)].bind(this),this[r(1645)].pingTimeoutInterval)}[t(1231)+t(1492)+t(1196)](){let r=t;this[r(1084)+r(1254)]?.[r(1665)](),this[r(1342)](e[r(1106)],"timeout"),this[r(1084)+r(1254)]?.[r(1286)+"chMaxCount"]()?this[r(1231)+r(1492)]():this[r(1504)]()}[t(1519)+t(1564)](){let r=t;return this._isMiniTT||this[r(687)+"X"]?this["_miniNav"+r(1607)+r(748)]:(this[r(883)+"er"]||this[r(586)+"r"])&&this._options["listenNe"+r(664)+r(1001)]?navigator[r(1216)]:!0}["_handleR"+t(1492)](){let r=t;!this[r(1519)+r(1564)]()||this._readyClosed||(this[r(364)+r(561)]?.["resetEnd"+r(311)+r(1658)](),this[r(1084)+"sCounter"]?.resetCounter(),this[r(1435)]?this[r(1171)+r(647)](1001,r(1537)+"ay, try reconnecting ser"+r(201),!0):this[r(711)]())}[t(788)+t(832)+t(1022)](){let r=t,s={FueHC:function(l,f){return e[W(1222)](l,f)},OVUeb:function(l,f){return e[W(1472)](l,f)},pRvnk:function(l,f){return l&f}};e[r(534)](e[r(187)],e[r(187)])?this[r(1481)+"T"]?tt["onNetwor"+r(837)+r(869)](({isConnected:l})=>{let f=r;if(e[f(630)](e[f(324)],e[f(324)]))return 0;this["_miniNav"+f(1607)+f(748)]=l,l?this[f(294)+f(483)]():this[f(294)+f(1385)]()}):this._isMiniWX&&wx[r(505)+r(837)+r(869)](({isConnected:l})=>{let f=r;this[f(932)+f(1607)+"line"]=l,l?this[f(294)+"nLine"]():this[f(294)+f(1385)]()}):(_0xeb1a04=lgHAhM[r(1588)](_0xc09c33,_0x411e4e),_0x48164d<32&&(_0x656cb7|=lgHAhM[r(1273)](lgHAhM[r(846)](127,_0x4467be),_0x4166e7)),_0xc02087+=7)}[t(1130)](r){let s={vCfjE:function(l,f,m){return e[W(1666)](l,f,m)}};return new Promise(l=>{let f=W;s[f(240)](setTimeout,l,this[f(1277)+f(690)+"e"](r))})}[t(1171)+t(647)](r=1e3,s="",l=!1){let f=t;if(e.AdMZj===e[f(806)]){if(!this[f(1435)])return;this[f(1330)+f(839)+"t"](r,s,l)}else return new _0x2d67b8(_0x270923,_0x327133,_0x39fbf3)}[t(1275)+"ut"](){let r=t,s=this[r(364)+r(561)]?.[r(1532)+"ntEndpoint"]();this[r(974)]("connect "+s+" timeout"),this[r(1171)+r(647)](1001,e[r(254)],!0)}_sendAck(r){let s=t,l={oWTuS:function(f,m){return e[W(1313)](f,m)}};if(e[s(540)](s(1457),e[s(803)])){let f=e.dfabB(Ut,r);this._ws&&e[s(227)](this._ws.readyState,this.OPEN)&&(this[s(1435)]&&this[s(1435)][s(1173)](f),this[s(974)](e[s(1307)],r))}else _0x191ba7=iQPcxj[s(542)](_0x24d96a,_0x487d46)}[t(502)+t(757)+"rs"](){let r=t;this[r(1435)]&&(this[r(1435)]["removeEv"+r(945)+r(1437)](e.dfawB,this[r(977)]),this[r(1435)][r(1176)+r(945)+r(1437)](e[r(681)],this[r(1121)]),this._ws["removeEv"+r(945)+r(1437)](e.gNbiL,this[r(987)+"ge"]),this[r(1435)][r(1176)+r(945)+r(1437)](e[r(238)],this[r(938)]))}[t(1057)+t(493)](){let r=t,s=(r(706)+"0")[r(811)]("|"),l=0;for(;;){switch(s[l++]){case"0":this[r(1435)].addEventListener(r(246),this[r(938)]);continue;case"1":this[r(1435)]["addEvent"+r(1503)](e.gNbiL,this[r(987)+"ge"]);continue;case"2":this[r(1435)]["addEvent"+r(1503)](r(1417),this._onClose);continue;case"3":this[r(1435)][r(1139)+r(1503)](e[r(308)],this[r(977)]);continue;case"4":if(!this[r(1435)])return;continue}break}}[t(459)+t(854)](r=1e3,s=""){let l=t;try{this[l(1435)]&&this[l(1435)][l(1417)](r,s)}catch{}}[t(1330)+t(839)+"t"](r=1e3,s="",l=!1){let f=t;if(this[f(892)+f(1454)](),this["_clearTi"+f(1347)](),this._removeWsListeners(),this[f(459)+"nceClose"](1e3,s),this[f(711)+f(1101)]=!1,l&&this["_navigat"+f(1564)]()&&!this[f(376)+f(1100)]){if(this[f(364)+f(561)]?.[f(1286)+"chMaxTries"]()){let b=this[f(364)+f(561)]?.[f(1532)+f(957)+"nt"]();this[f(404)+f(572)+f(736)](e[f(1308)](mt,e[f(681)],{code:1006,reason:f(1642)+b+(f(1023)+", max re"+f(707)+"ached"),wasClean:!0}))}else{let b=this[f(1645)][f(1611)+"tInterce"+f(976)](r,s);this["_dispatc"+f(572)+f(736)](e[f(1039)](mt,f(1417),{code:r,reason:s,wasClean:!0,willReconnect:b})),b&&this._connect()}return}this._navigatorOnline()||this[f(376)+f(1100)]?this[f(404)+f(572)+"ent"](mt(e[f(681)],{code:r,reason:e[f(1184)]})):this[f(404)+f(572)+f(736)](e[f(1335)](mt,e[f(681)],{code:1006,reason:f(1537)+f(185)+"ork offline"})),this[f(1435)]=null,this[f(364)+f(561)]?.[f(590)+"pointCon"+f(1658)](),this[f(1084)+f(1254)]?.resetCounter()}[t(404)+t(1584)+"nt"](r){let s=t;this.emit(e[s(308)],r),this[s(1331)]&&this.onopen(r)}["_dispatc"+t(508)+t(516)](r){let s=t;this.emit(e.gNbiL,r),this[s(230)+"e"]&&this.onmessage(r)}["_dispatchAckMess"+t(231)](r){let s=t;this[s(1342)](e[s(889)],r),this[s(439)+s(677)]&&this[s(439)+s(677)](r)}["_dispatc"+t(939)+t(736)](r){let s=t;this.emit(e.EzyeT,r),this[s(1322)]&&this[s(1322)](r)}["_dispatc"+t(572)+"ent"](r){let s=t;this[s(1342)](e[s(681)],r),this.onclose&&this[s(298)](r)}get[t(1485)+"pe"](){let r=t;return this[r(1435)]?this._ws[r(1485)+"pe"]:this["_binaryT"+r(1585)]}set[t(1485)+"pe"](r){let s=t;this[s(1133)+s(1585)]=r,this._ws&&(this[s(1435)][s(1485)+"pe"]=r)}get[t(180)+"nt"](){let r=t;return this["_endpoin"+r(561)]?.[r(1532)+"ntEndpoi"+r(409)+r(1047)]()||0}get[t(281)+"Amount"](){let r=t,s=this[r(377)+r(1565)][r(1213)]((l,f)=>(l+=f&&f[r(785)+"th"]||0,l),0);return e[r(610)](s,this._ws?this._ws[r(281)+"Amount"]:0)}get extensions(){let r=t;return this[r(1435)]?this[r(1435)].extensions:""}get protocol(){let r=t,s={qCfxV:function(l,f){return e.ibLfS(l,f)},IJFpO:function(l,f){return l<f},iIyTZ:function(l,f){return e[W(1528)](l,f)},iFSeI:function(l,f){return l>>f},lyFEh:function(l,f){return e.Rhlqu(l,f)},BKwoZ:function(l,f){return e.kYvGN(l,f)},kQuac:function(l,f){return e[W(383)](l,f)},iKwxb:function(l,f){return e.EByLI(l,f)},DOMzC:function(l,f){return e[W(469)](l,f)},MhlhA:function(l,f){return e[W(1398)](l,f)},ZKrVj:function(l,f){return e[W(1423)](l,f)},gztwU:function(l,f){return e[W(1528)](l,f)},zHdWR:function(l,f){return l&f},byrvL:function(l,f){return l|f},hHOQp:function(l,f){return e[W(691)](l,f)},ZmRKI:function(l,f){return e[W(1138)](l,f)}};if(r(1663)==="uxgNY")return this[r(1435)]?this[r(1435)][r(1007)]:"";_0x2a678b=_0x17ce11[r(1395)+"At"](_0x5e971c),eLuyww[r(608)](_0x1597d1,128)?_0xbae3ca[_0x483c24++]=_0x2ba941:eLuyww.IJFpO(_0x1f67d2,2048)?(_0x20b93a[_0x258e64++]=eLuyww.iIyTZ(eLuyww.iFSeI(_0x199116,6),192),_0x96353b[_0x4f0eef++]=eLuyww[r(1267)](eLuyww[r(437)](63,_0x32561c),128)):eLuyww[r(1269)](eLuyww.iKwxb(64512,_0x547d41),55296)&&eLuyww[r(1269)](eLuyww[r(700)](64512,_0xdd1c7c=_0x429a6b.charCodeAt(eLuyww[r(1295)](_0x9a9638,1))),56320)?(_0x2c6078=eLuyww[r(1295)](65536+eLuyww[r(380)](eLuyww[r(369)](1023,_0x16baf5),10),1023&_0x21978c),++_0x445524,_0x3fb90a[_0x6da381++]=eLuyww[r(543)](eLuyww[r(1378)](_0x486d95,18),240),_0x1de376[_0x20bb0f++]=eLuyww[r(543)](eLuyww[r(1249)](_0x3403bf>>12,63),128),_0x33da64[_0x2b0207++]=_0x4531a1>>6&63|128,_0x370a23[_0x24faf3++]=eLuyww[r(488)](eLuyww[r(700)](63,_0x11ce4b),128)):(_0x1fa9c5[_0x9199aa++]=eLuyww[r(1465)](_0x4f1691>>12,224),_0x34a436[_0x19e62d++]=eLuyww[r(670)](eLuyww[r(369)](eLuyww[r(464)](_0x36f25d,6),63),128),_0x11b907[_0x465731++]=eLuyww.zHdWR(63,_0x49e8a0)|128)}get readyState(){let r=t;return this[r(1435)]?this._ws.readyState:this._options[r(930)+r(628)]?this[r(1076)+"NG"]:this.CLOSED}get[t(712)](){let r=t;return this[r(1435)]?this[r(1435)][r(712)]:this._url}[t(1417)](r=1e3,s){let l=t;if(this._readyClosed=!0,this[l(1675)+l(1347)](),this[l(892)+l(1454)](),this[l(1315)+l(1118)+l(1503)](),this[l(315)+"ger"]?.[l(266)](),!this[l(1435)])return void this[l(974)](l(1422)+"s instan"+l(1204)+l(1215)+"ed");if(e[l(276)](this[l(1435)].readyState,this[l(1206)])||e[l(743)](this[l(1435)][l(907)+"te"],this.CLOSING))return void this[l(974)](e[l(965)]);this[l(1330)+l(839)+"t"](r,s)}async send(r,s){let l=t;if(e[l(166)](null,r))throw new Error(e.hwFJf);e[l(232)](e[l(1168)],typeof r)&&(r=JSON[l(218)+"y"](r)),e[l(1439)]!=typeof r&&!e[l(864)](r,ArrayBuffer)&&!(r[l(1451)]&&e.hgvaZ(r[l(1451)],ArrayBuffer))&&(r=JSON[l(218)+"y"](r));let f=await e.zBPjQ(gl,r),m=e[l(1412)](Wp,r),{method:b=0,service:S=this[l(1645)][l(1089)],logID:p=this[l(1645)]["logIDGen"+l(1600)](),headers:O=this[l(1645)][l(1199)],payloadEncoding:L=this[l(1645)][l(1279)+l(1509)],payloadType:N=this._options[l(1669)+l(1585)],logIDNew:U=this[l(1645)][l(289)+l(929)][l(831)+l(406)+l(1164)+"ew"]?e[l(1557)](i,this[l(1645)][l(289)+"Config"][l(1151)]):""}=e.ueMCw(s,{});if(!S)throw new Error(e.GMGyB);let H={SeqID:he.fromNumber(this[l(438)]++),LogID:he.fromNumber(p),service:S,method:b,headers:O,payloadEncoding:e[l(678)](L,Object)?L[l(1300)]?L[l(1300)]:"":L,payloadType:e[l(678)](N,Object)?N[l(251)]?N[l(251)]:m:N||m,payload:f,LogIDNew:U},z=e[l(1469)](Ut,H);if(this._ws&&e[l(1098)](this._ws[l(907)+"te"],this[l(1495)]))this._ws&&this[l(1435)].send(z),this[l(974)](e[l(1569)],H);else if(this[l(377)+l(1565)].length<this._options[l(1560)+l(1381)+l(606)])if(e[l(552)]!==e[l(552)]){let q=_0x1e7223.charCodeAt(_0x5a21dc);e.gwqMS(q,55296)&&e[l(675)](q,56319)&&e[l(732)](_0x30fc78+1,_0x345663)&&(q=e.XiuGM(e[l(1044)](e[l(993)](q,10),_0xe93296[l(1395)+"At"](++_0x5f243f)),56613888)),e.pIhNF(q,128)?_0x504ba3[_0x5f31d5++]=q:(e[l(382)](q,2048)?_0x4c7cc5[_0x37a597++]=e[l(833)](e[l(731)](e.UnZrB(q,6),31),192):(e[l(732)](q,65536)?_0x4fa87f[_0x3ee7be++]=e[l(1063)](e[l(651)](q,12),15)|224:(_0x14baa6[_0x14cbd9++]=e[l(639)](e[l(351)](q>>18,7),240),_0x30df17[_0x4e61ea++]=e[l(655)](e[l(1063)](q>>12,63),128)),_0x5a6a9d[_0x58ee8b++]=e[l(1527)](e[l(410)](e[l(1551)](q,6),63),128)),_0x5ceb15[_0x3da811++]=e[l(751)](e[l(205)](63,q),128))}else this[l(377)+l(1565)][l(190)](z),this._debug(e.FCwlr,H);else if(e[l(482)]("RzPna",e.PmHCU))this[l(377)+l(1565)][l(692)](),this[l(377)+"Queue"][l(190)](z);else{let q=0,ne=_0x3d9680,on=e.uAHMs(_0x3fa9e3,4);for(;e[l(1433)](ne,on);){let{value:sr,offset:ls}=e.AqkBW(_0x550305,_0x5ef58c,ne);ne=ls,q=e.DdzOn(e[l(1327)](q,8),0),q+=sr}return{value:q,offset:on}}return{seqID:this[l(438)],logID:p,logIDNew:U}}async[t(1611)+"t"](r){let s=t,l={xIEhl:function(b,S){return e[W(973)](b,S)},rDUcP:e[s(1181)]},{url:f}=e[s(320)](r,{}),m=Array.isArray(f)?f:e[s(1439)]==typeof f?[f]:[];if(r&&Object[s(381)](this[s(1645)],r),m&&m[s(284)]?this[s(364)+s(561)]=new fl(m,this[s(1645)][s(1394)+"es"]):this[s(364)+s(561)]?.[s(590)+s(311)+s(1658)](),this[s(1084)+"sCounter"]?.[s(802)+s(571)](this[s(1645)][s(887)+s(1460)]),this[s(376)+s(1100)]=!1,this[s(1435)]&&this[s(1435)].readyState!==this[s(1206)])this[s(1171)+s(647)](1e3,e[s(1640)],!0);else if(e[s(297)](e[s(441)],e[s(441)])){let b={POjXo:CLxnFX[s(865)],YoImG:s(246),GHHcY:CLxnFX[s(1506)],vbRdW:function(L){return CLxnFX.tMbql(L)}},S=()=>{let L=s;_0x5210a3["removeEv"+L(945)+"ner"](b[L(638)],p),_0x247677[L(1176)+L(945)+L(1437)](b[L(1114)],O),_0x27b396[L(1176)+L(945)+L(1437)](b[L(1049)],O)},p=()=>{b[s(544)](_0x2d4b86),S()},O=()=>{let L=s;JUFZZj[L(1360)](_0x46ba0f,_0x4aab34.error||new _0x1c320c(JUFZZj[L(1031)],JUFZZj[L(1031)])),S()};_0x21b193[s(1139)+s(1503)](CLxnFX[s(865)],p),_0x520df5[s(1139)+s(1503)](CLxnFX[s(238)],O),_0x454b2c["addEvent"+s(1503)](s(491),O)}else this[s(972)]=!0,this._connect()}async[t(248)](){let r=t;!this._connectLock&&(this["_endpoin"+r(561)]?.[r(590)+r(311)+r(1658)](),this[r(1084)+"sCounter"]?.[r(802)+r(571)](),this[r(376)+r(1100)]=!1,this[r(972)]=!0,this._connect())}[t(1139)+t(1503)](r,s){this.on(r,s)}["dispatch"+t(516)](r){let s=t,{type:l}=r;this[s(1342)](l,r)}[t(1176)+t(945)+"ner"](r,s){this[t(1555)](r,s)}[t(556)](){let r=t,s={qMKVH:function(l,f){return e.qxYRM(l,f)},umcku:function(l,f){return e.qxSdK(l,f)},gBZip:e[r(291)],bIUBO:function(l,f,m){return e.plrXJ(l,f,m)},BjhBV:e[r(1651)]};return new Promise((l,f)=>{let m=r,b={GDGan:function(O,L){return s[W(1367)](O,L)},eaMpP:m(1655),ssUbd:m(1507)+"e_timeout",jvYaS:function(O,L){return s[m(1357)](O,L)},jkVtU:s[m(1406)],cedsf:m(1507)+m(506)+"s"};this[m(892)+m(1454)](),this[m(378)+m(1673)+"Id"]=s[m(1280)](setTimeout,this[m(1504)][m(595)](this),this[m(1645)][m(714)+m(895)]);let S=()=>{let O=m;b[O(830)](l,b.eaMpP),this[O(1555)]("ping_onc"+O(506)+"s",S),this[O(1555)](b[O(1363)],p)},p=()=>{let O=m;b[O(1046)](f,b[O(1471)]),this[O(1555)](b[O(1166)],S),this[O(1555)](b[O(1363)],p)};this.on(s.BjhBV,S),this.on(m(1507)+m(662)+"t",p),this._ping()})}}})(),ze["CustomCl"+M(1169)]=De[M(1126)+M(1169)],ze[M(1583)+"rorEvent"]=De[M(1583)+M(273)],ze[M(1048)+"e"]=De[M(1048)+"e"],ze.Event=De[M(516)],ze.FWS=De[M(1420)],ze[M(1209)+"MessageE"+M(1562)]=De[M(1209)+M(1548)+M(1562)],ze[M(1548)+M(1562)]=De[M(1548)+"vent"],ze[M(1432)+"t"]=De[M(1432)+"t"],ze[M(348)+"tEvent"]=De[M(348)+"tEvent"],ze[M(1586)+"oseEvent"]=De.createCloseEvent,ze[M(1142)+M(273)]=De[M(1142)+M(273)],ze[M(217)+M(249)+"nt"]=De["createMe"+M(249)+"nt"],ze[M(225)+M(524)]=De["createOp"+M(524)],ze["createRe"+M(221)+"vent"]=De[M(1192)+M(221)+M(1562)],ze["decodedF"+M(286)]=De[M(570)+"rame"],ze["encodeFr"+M(342)]=De[M(682)+M(342)];for(Ko in De)[M(1126)+M(1169),M(1583)+M(273),M(1048)+"e",M(516),M(1420),M(1209)+M(1548)+M(1562),"MessageE"+M(1562),M(1432)+"t",M(348)+M(1354),M(1586)+"oseEvent",M(1142)+M(273),"createMessageEvent",M(225)+M(524),M(1192)+M(221)+M(1562),M(570)+"rame",M(682)+"ame"][M(1304)](Ko)===-1&&(ze[Ko]=De[Ko]);function W(t,e){t=t-166;let n=Xo(),i=n[t];if(W.tVINte===void 0){var o=function(x){let h="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",g="",w="";for(let v=0,_,E,I=0;E=x.charAt(I++);~E&&(_=v%4?_*64+E:E,v++%4)?g+=String.fromCharCode(255&_>>(-2*v&6)):0)E=h.indexOf(E);for(let v=0,_=g.length;v<_;v++)w+="%"+("00"+g.charCodeAt(v).toString(16)).slice(-2);return decodeURIComponent(w)};W.UQIcAe=o,W.mPkSxc={},W.tVINte=!0}let c=n[0],d=t+c,u=W.mPkSxc[d];return u?i=u:(i=W.UQIcAe(i),W.mPkSxc[d]=i),i}var Ko;Object["definePr"+M(1447)](ze,M(1319)+"le",{value:!0})});import{existsSync as L1,openSync as N1}from"node:fs";import{mkdir as M1}from"node:fs/promises";import{dirname as B1}from"node:path";import{fileURLToPath as F1}from"node:url";function U1(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function qd(t=te()){return L1(t.libEntry)?t.libEntry:F1(new URL("../index.ts",import.meta.url))}async function Xh(t={}){let e=t.paths??te(),n=t.entryOverride??qd(e),i=U1(e,process.env.COZE_BRIDGE_LOG_MODE);await M1(B1(i),{recursive:!0});let o=N1(i,"a"),d=n.endsWith(".ts")?["--import","tsx/esm",n,"--daemon"]:[n,"--daemon"],u=st(process.execPath,d,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[ss]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return z1.info("daemon spawned",{pid:u.pid,entry:n}),{pid:u.pid,entry:n}}var z1,ss,ra=nt(()=>{"use strict";Vt();ie();Me();z1=K("spawn-daemon"),ss="COZE_BRIDGE_DAEMON"});import{spawn as BS}from"node:child_process";import{mkdir as FS,unlink as zS,writeFile as US}from"node:fs/promises";import{dirname as GS,join as jS}from"node:path";function Zr(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function HS(t){if(!t)return"";let e=Object.entries(t).map(([n,i])=>` <key>${Zr(n)}</key>
|
|
20
|
+
`+r)}function er(t,e,r,i,o,c){if(t.listenerCount("wsClientError")){let d=new Error(o);Error.captureStackTrace(d,er),t.emit("wsClientError",d,r,e)}else ns(r,i,o,c)}});var qx=ce(Ue=>{"use strict";var F=Z;(function(t,e){let r=Z,i=t();for(;;)try{if(-parseInt(r(874))/1*(-parseInt(r(1186))/2)+parseInt(r(1257))/3*(parseInt(r(1227))/4)+parseInt(r(1407))/5+-parseInt(r(1098))/6*(parseInt(r(1188))/7)+parseInt(r(1247))/8*(-parseInt(r(1504))/9)+-parseInt(r(858))/10+parseInt(r(1216))/11*(parseInt(r(1631))/12)===e)break;i.push(i.shift())}catch{i.push(i.shift())}})(Yo,594557);var dS=Object[F(436)+F(852)],lS=Object["getOwnPr"+F(758)+F(1035)],Fx=(t,e)=>function(){return t&&(e=(0,t[lS(t)[0]])(t=0)),e},uS=(t,e)=>{for(var r in e)dS(t,r,{get:e[r],enumerable:!0})};function fS(){return Ox||(Ox=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function hS(){let t=F;return Lx||(Lx=[IDBCursor[t(1353)+"e"][t(1068)],IDBCursor[t(1353)+"e"][t(1579)],IDBCursor[t(1353)+"e"][t(1579)+t(632)+"ey"]])}function xS(t){let e=F,r={ZOPoI:function(o,c){return o(c)},EpjNg:e(913),aERwo:function(o,c){return o===c},sXXfW:"kjIad",RSjIw:function(o,c){return o(c)},MdBxJ:"error",pWOYS:"pbdnf"},i=new Promise((o,c)=>{let d=e,u={KNrqn:r[d(341)],NzGGF:function(_,S){return r[d(711)](_,S)},JMTnm:r.sXXfW,edipy:function(_,S){return r[d(1263)](_,S)}},h=()=>{let _=d;t["removeEv"+_(1327)+_(895)](u.KNrqn,x),t[_(475)+_(1327)+_(895)](_(1473),m)},x=()=>{let _=d;r[_(547)](o,r[_(547)](Ht,t[_(1393)])),h()},m=()=>{let _=d,S={OErSc:function(y,v){return y-v}};if(u[_(1535)](u[_(346)],u[_(346)]))u[_(479)](c,t[_(1473)]),h();else{let y=_0xc1bc1d[_(626)+"g"](0,S[_(642)](4,_0x1ac06a[_0x5758f6][_(1818)])),v=y[_(456)](_0x9459d1[_0x421ee4]);_0x494edd[_(1241)](v)}};t[d(480)+d(1147)](r.EpjNg,x),t[d(480)+d(1147)](r[d(971)],m)});return i[e(1486)](o=>{let c=e,d={CQGij:r[c(971)]};o instanceof IDBCursor&&(c(571)===r[c(1595)]?(this[c(1433)](d[c(783)],_0x553b7b),this.onerror&&this[c(522)](_0x17bfb4)):Gd[c(1172)](o,t))}).catch(()=>{}),Zo.set(i,t),i}function pS(t){let e=F,r={DRHWY:e(724),BzXoC:e(1473),XFrAJ:function(o){return o()},AXvjq:function(o,c){return o(c)},LqJKE:e(785)+"or",YuVAd:function(o){return o()},aVBGU:function(o,c){return o!==c},SXCeJ:e(1660),gLKdm:"GuDcx",tiigc:e(1808)};if(Jo[e(840)](t))return;let i=new Promise((o,c)=>{let d=e;if(r[d(735)](r[d(712)],r[d(1715)])){let u=()=>{let m=d;t["removeEv"+m(1327)+"ner"](r[m(1023)],h),t[m(475)+"entListe"+m(895)](r.BzXoC,x),t["removeEv"+m(1327)+"ner"](m(1808),x)},h=()=>{let m=d;o(),r[m(584)](u)},x=()=>{let m=d;r.AXvjq(c,t[m(1473)]||new DOMException(r[m(738)],r[m(738)])),r.YuVAd(u)};t["addEvent"+d(1147)](r[d(1023)],h),t[d(480)+d(1147)](r[d(555)],x),t["addEvent"+d(1147)](r[d(1532)],x)}else return this[d(1028)+d(519)+"riesCount"]++,this[d(875)+d(1420)+"nt"]()});Jo[e(1172)](t,i)}function gS(t){Xo=t(Xo)}function mS(t){let e=F,r={eWxsC:function(i,o){return i(o)},yPwST:function(i,o){return i(o)},wZcNC:function(i,o,c){return i(o,c)},CRbQS:e(399),oOBbC:e(1345),yBbzs:"going away, network offl"+e(334),daJZY:function(i,o){return i!==o},QZANj:e(734),KrDHj:function(i,o){return i(o)},FHPOB:function(i,o){return i(o)},nHsuU:function(i,o,c){return i(o,c)},yDjqM:function(i,o,c){return i(o,c)},DkgHL:function(i,o){return i instanceof o},YOJiu:function(i,o){return i+o},YZewQ:function(i,o){return i(o)},IZWes:function(i,o){return i(o)},odczj:function(i,o){return i in o},TcaWR:e(995)+e(1359),wAoKe:function(i,o){return i===o},cdYeb:e(1600),lAtXH:e(1463),LWZPr:e(1118)};if(t===IDBDatabase.prototype["transact"+e(1038)]&&!r.odczj(r.TcaWR,IDBTransaction.prototype)){if(r[e(1804)](r[e(304)],r[e(304)]))return function(i,...o){let c=e,d=t[c(994)](r[c(990)](rs,this),i,...o);return Ud[c(1172)](d,i[c(624)]?i[c(624)]():[i]),r[c(795)](Ht,d)};if(this[e(967)+e(732)](),this[e(1322)+"mer"](),this[e(1567)+e(1037)+"rs"](),this[e(1784)+e(280)](1e3,_0x10245c),this["_connect"+e(1703)]=!1,_0x16ad32&&this[e(1025)+e(1469)]()&&!this["_readyCl"+e(1108)]){if(this[e(1464)+"tManager"]?.[e(1301)+e(1461)+"es"]()){let o=this[e(1464)+e(933)]?.[e(875)+"ntEndpoint"]();this["_dispatchCloseEv"+e(1558)](r[e(1638)](_0x29195b,"close",{code:1006,reason:e(1201)+o+(e(417)+", max re"+e(1308)+e(972)),wasClean:!0}))}else{let o=this[e(1796)][e(1620)+e(1695)+e(1815)](_0x597161,_0x57c1db);this[e(1713)+"hCloseEv"+e(1558)](_0x41f21c(r[e(702)],{code:_0x1a1e82,reason:_0x48b1a0,wasClean:!0,willReconnect:o})),o&&this[e(371)]()}return}this[e(1025)+e(1469)]()||this[e(1580)+"osed"]?this[e(1713)+"hCloseEv"+e(1558)](r[e(1638)](_0x31430a,r[e(702)],{code:_0x3cf574,reason:r[e(1716)]})):this[e(1713)+e(904)+e(1558)](r[e(1638)](_0x17236e,r[e(702)],{code:1006,reason:r.yBbzs})),this[e(1226)]=null,this["_endpoin"+e(933)]?.resetEndpointConfig(),this[e(886)+e(1801)]?.[e(1126)+e(1466)]()}if(hS()[e(934)](t)){if(r[e(1798)](r[e(1619)],r[e(1066)]))return function(...i){let o=e;if(r[o(1798)](o(311),r.QZANj))return t[o(832)](r.KrDHj(rs,this),i),r[o(515)](Ht,Gd[o(928)](this));throw this[o(371)+"Lock"]=!1,_0x568130};{let i={ehHvf:e(1473),YtHzB:function(o,c,d){return r[e(1816)](o,c,d)},IUeFz:function(o,c,d){return r[e(1207)](o,c,d)}};if(r[e(1678)](_0x4fbaba,_0x4f9ddc)){let o=_0x2baebb[e(923)][e(1573)](_0x28e04f[e(1640)+"et"],r[e(1094)](_0x4f1112[e(1553)+"th"],_0x91f47d[e(1640)+"et"]));this[e(1236)]&&this[e(1236)][e(925)]({data:o,fail:c=>{let d=e;this.emit(i[d(1157)],i[d(1507)](_0x84970a,i[d(1157)],{message:this[d(1637)+d(892)+d(1312)](c)}))}})}else this._socket&&this[e(1236)][e(925)]({data:_0x2aa13f,fail:o=>{let c=e;this[c(1433)]("error",i[c(541)](_0x4d1f44,"error",{message:this[c(1637)+c(892)+c(1312)](o)}))}})}}return function(...i){return r[e(794)](Ht,t.apply(r.IZWes(rs,this),i))}}function wS(t){let e=F,r={gKTrJ:function(i,o){return i===o},IZrhK:e(567),PpnVn:function(i,o){return i(o)},VWQwv:function(i,o){return i instanceof o},QwQwj:function(i,o,c){return i(o,c)},mdClv:function(i){return i()}};return r[e(1616)](typeof t,r[e(616)])?r.PpnVn(mS,t):(r.VWQwv(t,IDBTransaction)&&r[e(297)](pS,t),r[e(1300)](zx,t,r[e(464)](fS))?new Proxy(t,Xo):t)}function Ht(t){let e=F,r={VdoWB:function(o,c){return o instanceof c},RUcLO:function(o,c){return o(c)},jRkdy:function(o,c){return o(c)},nCInT:function(o,c){return o!==c}};if(r[e(1283)](t,IDBRequest))return r.RUcLO(xS,t);if($o[e(840)](t))return $o[e(928)](t);let i=r[e(1129)](wS,t);return r[e(705)](i,t)&&($o[e(1172)](t,i),Zo[e(1172)](i,t)),i}var zx,Ox,Lx,Gd,Jo,Ud,$o,Zo,Xo,rs,Nx=Fx({"node_modules/idb/build/wrap-idb-value.js"(){let t=F,e={kRwbs:function(r,i){return r instanceof i},fdICC:function(r,i){return r===i},AJWds:t(1538),kFbff:"store",rQISd:function(r,i){return r(i)},nmeIZ:function(r,i,o,c,d){return r(i,o,c,d)},pkGaw:function(r,i){return r(i)},NYCMS:function(r,i){return r!==i},UZllr:t(1577),RvEmh:t(1072),jabRd:function(r,i){return r in i}};zx=(r,i)=>i[t(455)](o=>r instanceof o),Gd=new WeakMap,Jo=new WeakMap,Ud=new WeakMap,$o=new WeakMap,Zo=new WeakMap,Xo={get(r,i,o){let c=t;if(e[c(366)](r,IDBTransaction)){if(e.fdICC(i,e[c(546)]))return Jo[c(928)](r);if(e[c(1731)](i,c(995)+c(1359)))return r[c(995)+c(1359)]||Ud[c(928)](r);if(e.fdICC(i,e[c(1279)]))return o[c(995)+c(1359)][1]?void 0:o["objectSt"+c(1272)](o["objectSt"+c(1359)][0])}return e[c(966)](Ht,r[i])},set(r,i,o){return r[i]=o,!0},has(r,i){let o=t,c={MnjsE:function(d,u,h,x,m){return e.nmeIZ(d,u,h,x,m)},pNkVJ:function(d,u){return e[Z(1254)](d,u)},XGOUG:o(974)+o(561)};if(e.kRwbs(r,IDBTransaction)&&(e[o(1731)](i,e[o(546)])||e[o(1731)](i,e[o(1279)]))){if(e.NYCMS(e[o(880)],e[o(382)]))return!0;{let d={lXAXR:function(u,h,x,m,_){return c[o(1471)](u,h,x,m,_)},xqBhF:function(u,h){return c[o(953)](u,h)}};_0x22e9d1[o(480)+o(1147)](c.XGOUG,u=>{let h=o;d.lXAXR(_0x384ad3,d[h(532)](_0x48b1a6,_0x437151.result),u[h(1627)+"on"],u.newVersion,_0x554e39(_0x54c997[h(943)+h(1038)]))})}}return e.jabRd(i,r)}},rs=r=>Zo.get(r)}}),Ux={};uS(Ux,{deleteDB:()=>yS,openDB:()=>_S,unwrap:()=>rs,wrap:()=>Ht});function _S(t,e,{blocked:r,upgrade:i,blocking:o,terminated:c}={}){let d=F,u={pqRia:function(m,_,S,y,v){return m(_,S,y,v)},pXHij:function(m,_){return m(_)},cguCA:function(m,_){return m(_)},RCRFa:d(1785)+"hange",MNVvB:d(974)+d(561)},h=indexedDB[d(1556)](t,e),x=Ht(h);return i&&h[d(480)+d(1147)](u[d(716)],m=>{let _=d;u[_(1542)](i,u[_(1614)](Ht,h.result),m.oldVersion,m[_(962)+"on"],u.cguCA(Ht,h[_(943)+_(1038)]))}),r&&h[d(480)+d(1147)](d(825),()=>r()),x[d(1486)](m=>{let _=d;c&&m[_(480)+_(1147)](_(399),()=>c()),o&&m[_(480)+_(1147)](u[_(1778)],()=>o())})[d(513)](()=>{}),x}function yS(t,{blocked:e}={}){let r=F,i={CQOIm:"blocked",lNZzl:function(c,d){return c(d)}},o=indexedDB[r(1512)+"tabase"](t);return e&&o[r(480)+r(1147)](i.CQOIm,()=>e()),i[r(761)](Ht,o)[r(1486)](()=>{})}function Mx(t,e){let r=F,i={oBECP:"readwrite",wwqMl:r(997),arRPP:function(h,x){return h in x},RejIP:function(h,x){return h===x},sWXsj:"string",Dcunz:function(h,x){return h===x},bEZNv:r(830),LQpPW:r(509)};if(!(t instanceof IDBDatabase&&!i[r(1682)](e,t)&&i.RejIP(typeof e,i[r(1103)])))if(i[r(682)](i.bEZNv,i[r(688)]))this[r(640)+r(529)]=_0x2e572e,this._ws&&(this._ws[r(1166)+"pe"]=_0x305c23);else return;if(Vo[r(928)](e))return Vo[r(928)](e);let o=e[r(581)](/FromIndex$/,""),c=e!==o,d=Hx.includes(o);if(!(o in(c?IDBIndex:IDBObjectStore).prototype)||!(d||Gx[r(934)](o)))return;let u=async function(h,...x){let m=r,_=this[m(943)+m(1038)](h,d?i[m(1670)]:i[m(1370)]),S=_[m(976)];return c&&(S=S[m(1421)](x[m(1498)]())),(await Promise[m(857)]([S[o](...x),d&&_[m(1538)]]))[0]};return Vo[r(1172)](e,u),u}var Gx,Hx,Vo,bS=Fx({"node_modules/idb/build/index.js"(){let t=F,e={oacIA:t(1230)+t(927),gfovn:function(o){return o()},kxVbp:t(490),kzOQd:t(374),okGcS:t(1480),BybKp:t(1390),cnect:t(1185),LthFp:"getAllKeys",cLHzW:t(1110),BqFDi:function(o){return o()},rIGNf:function(o,c){return o(c)}},r=e[t(1585)].split("|"),i=0;for(;;){switch(r[i++]){case"0":e.gfovn(Nx);continue;case"1":Vo=new Map;continue;case"2":Hx=[e[t(760)],e[t(1091)],e[t(1598)],e[t(1802)]];continue;case"3":Gx=[t(928),t(710),e[t(460)],e[t(1184)],e[t(609)]];continue;case"4":e[t(1238)](Nx);continue;case"5":e[t(930)](gS,o=>({...o,get:(c,d,u)=>Mx(c,d)||o[t(928)](c,d,u),has:(c,d)=>!!Mx(c,d)||o[t(840)](c,d)}));continue}break}}}),ES={idb:function(t){let e=F;t[e(931)]=Promise[e(718)]()[e(1486)](()=>(bS(),Ux))[e(1486)](function(r){return r})}},Bx={};function Gt(t){let e=F,r={uUhhK:function(u,h){return u!==h}},i=(e(1602)+"4")[e(1414)]("|"),o=0;for(;;){switch(i[o++]){case"0":var c=Bx[t]={exports:{}};continue;case"1":var d=Bx[t];continue;case"2":ES[t](c,c[e(931)],Gt);continue;case"3":if(r.uUhhK(void 0,d))return d[e(931)];continue;case"4":return c[e(931)]}break}}Gt.d=(t,e)=>{let r=Z;for(var i in e)Gt.o(e,i)&&!Gt.o(t,i)&&Object[r(436)+r(852)](t,i,{enumerable:!0,get:e[i]})},(()=>{let t=F;Gt.o=(e,r)=>Object[t(1353)+"e"][t(802)+t(852)][t(994)](e,r)})(),(()=>{let t=F,e={HjxjP:function(r,i){return r!=i},YtBPX:t(1456)+"d",dbHxy:t(954),NVUJQ:t(1809)+"le",ZIRfw:function(r,i){return r===i},HTjXa:t(828),KyCbX:t(603)};Gt.r=r=>{let i=t;e[i(1040)](e[i(1633)],e.KyCbX)?(e.HjxjP(e[i(1793)],typeof _0x2d4f40)&&_0x21fe05.toStringTag&&_0x5b8b40["definePr"+i(852)](_0x3bc1cf,_0x137ccc["toString"+i(1275)],{value:e.dbHxy}),_0x2a1f57[i(436)+i(852)](_0x25ccbc,e.NVUJQ,{value:!0})):(e[i(1793)]!=typeof Symbol&&Symbol[i(1375)+i(1275)]&&Object[i(436)+i(852)](r,Symbol["toString"+i(1275)],{value:e[i(1694)]}),Object[i(436)+i(852)](r,e[i(1522)],{value:!0}))}})();function Yo(){let t=["CfDpwvm","CgzRDgu","C0vcsgC","B2Thy1m","rMnerLG","s295wg4","C2vUzf9Hy2S","mxWZFdb8mNW","B25nzxnZywC","x2LZv29YA2u","yw51Ce1LC3m","r3vxtKu","qNj1B28","zM9YrwfJAa","C3nHz2vfDMu","ELLZz0e","sLjrz2q","Cgfxr0y","yuzcqLO","CfHiAwO","txHhqw0","z0TuCKO","uvrhwe0","tKfusvzfx0u","Bef0weG","CMvJB25Uzwm","AKXSwuu","BMCGB3iGyw4","ueDlEMS","uLjpuG","s2f4vha","rhzTteq","B2XKvMvYC2K","CNzHBfzHBhu","sgnKBwq","zuDRvxK","mty0ndGYoe9AC01oDq","teTACwu","sfrQwge","yNnPBw8","Aw5KzxHpzG","ign1CNnVCIa","x2zVCM1HDeu","D1PJtKm","v0rPyuW","yNL0zu9MzNm","ExvOwfi","x2n1CNnVCK4","qLvUtgq","qM50CuC","ohW3Fdj8nhW","A0zkAeS","igfYCMf5yNu","Cw9fCNC","Cw9Zx18","A01twhy","AxnszwfKEq","Cwr1wNa","CMvWBgfJzui","zvvYBa","CLPXuvG","BhHQte4","x3vYBa","BfvLvxm","v2LUzg93","A3DtyxG","yxnJCMLWDa","vfLQs3G","uKfcAve","s2vts0W","wezMsvC","Ewj1uMu","x3bYB3rVy28","z3Ldv0q","x2LZtwLUAvC","B0jfq1a","AwDHDg9Yt24","EgnuEwq","ALH6vNO","C1f6t1O","x29UvgLTzw8","q0Xpu0LorW","BgjfAgu","rgTNseW","u3P3rLG","yxGGCMv0CMK","x2LUAxq","yxjsufa","quXcBhi","igzHAwWSig0","rfPSqMO","B3bLBIa","sgfKtuK","q09otKvdveK","DhLPzg8","CgLUz09Uy2u","uwLlEwG","CgXcuM4","wuPODgy","zgjiEhK","DeLUDgvYy2u","ALfcuw0","Cwzovgm","B2fuB24","BgDgvw8","tMjRsKC","B25JBg9Zzq","Dg9iyxnO","tg9JAW","yLvZvuG","Dg9cExrLC0W","zwHoELy","De11u2q","Cg1ZzKm","u0DXEM4","tezXwwS","Bg93","u3zpt0q","x2rPC3bHDgm","qwT2C3a","z0Xlzg0","B09cyKm","CMvZzxrfBMq","DhbizwfKzxi","B2zMBgLUzq","rNvzDw8","rwzXrva","ywXPzcb1CMW","zgLZywjSzue","yNbitfy","BMTdCwm","v1LxCvi","o2nOyxjZzxq","EMTWB0W","tMDNvLa","C3rHCNq","zMrjq0m","rNjVBNrPzxi","vgLTzw91Da","y29UDgv4Da","BNvTyMvY","C2v0y3vYC28","x3bPBMDqB24","x29UrxjYB3i","CMvQzwn0","CNbTsLy","C1PQyKK","CgfNzwHPzgu","u1vdyM4","BwfUDwfSihi","yxv0BW","whHevM0","wwXjCui","yMLUyxj5","yMfJA3vWigu","u2vXsuq","x29UtwvZC2e","rLjptLrjrvi","tvn0tKm","EurSENe","s25kB3y","zhf0tKy","rgfTDwO","zKzKy1m","ve5Ny0i","q2Lot1K","B2vrwgK","DgLTzw91Da","rMHXy0O","y29UBMvJDeu","A256veO","DM5lB3u","Aw47y2HHCNm","ChjVDg9JB2W","CNDZrva","ExHlv08","uuvvC0S","D29cuMO","Dg9oDw1Izxi","BhbeD08","r3rHs2m","weHAy0m","t3L0Awe","uKnsrMe","te5dChu","uMXLDe0","uKnPA0K","q291sfy","BgLTAxq","x3DZsw5ZDge","DMvYC2LVBMm","pxv0zI04","EhDKwg4","qwvgyNy","CMvHzhLtDge","uMvHzcbWyxm","tKDFrvjst1i","DxrKzfC","wxrcufG","v2ztuva","tM9KqvK","x29WDgLVBNm","yuzurfe","zgfkwLK","tKXurNm","seP1rMW","C0nVDw50zxi","qNLIs3a","v2vPEgLUsLm","D0fVs2u","s0r1z3O","q1fyDwq","yMTOzfi","ywjVCNq","x19LC01Vzhu","qw1VDw50","yMr0CeW","q29Kzq","Cgf5Bg9Hzeu","zLLgyuO","ChrVCG","BKHZDvu","D2vIsgy","BgvUz3rO","AwrI","sMvVyMO","txDfwvC","y3jLyxrLuMu","C1bvuM8","A1r2s2W","t09VANC","BMnLq2XVC2u","ChLyzKi","rvniz0S","DvrVExG","DLzXyui","BgvY","m3W0Fdj8mxW","A2v5CW","AwXLtMfTzq","s050qMq","x3bPBMC","CKHXEvy","wKXHyKG","EKL6Due","aaaaaaaaaaa","shfLt0y","Bg9Nsurhzw4","uhbUvM4","BM93","ywXty29Wzq","r2fQsxK","B3nLrxzLBNq","zKHMyK4","tgnUAKO","y2rzzwi","vw5Oyw5KBgu","wffnqNO","z2vjBMzVu3K","sM9vAxu","ywHHBgu","u21iwu4","v2frEeS","v0fAtLy","rgnyv3e","sgjxBee","uMnUwvK","txvXvha","A2LRDwK","vuDqzLa","ywXSB2nvBNm","x0rctMfTzq","tufyx1jfvfi","AxnbCNjHEq","s1jMvhm","q3Hmyue","ywnRx2LK","uxHSuhq","uxvLDwu","DMfSDwvZ","CMvJzwL2zwq","sufIBLa","yKTKsKS","zw5JB2rLrNi","rgjPuhO","Aw5L","rgLJBei","Bwu6ia","wKjqswW","Bxjrsuu","D3jPDgvvAw4","Ec11C2uT","rxbQtMC","yLj1zMK","qKnoqu0","wfLVtKO","B0LOyvi","sK1uBM0","Dw50","y09Wzw4","Dw1xCKS","wvrjwfy","y0ndBei","ywDLsgLKzq","v1jszvO","twLZC2LUzYa","zwzQqva","x2HHBMrSzva","rgzvruO","CeziEw0","t21vAwu","A1L3Dg0","C3rYAw5NAwy","z1vxzuO","vhzkwLy","uKvrANC","x29Uq2XVC2u","A1j3yNm","CLLqEvO","uw1qANq","EvjLy29UBMu","z1PQBLC","x2nVBM5Ly3q","swLhwuS","DxjS","ywrK","zw5XDwv1zq","AMHcuK8","ru9nqvK","uxbfweq","u2npEwu","EvrZthm","BNruCMLLC0m","uNzfBwG","zwn0","CxfJt04","D3DyrKK","rLLbrxO","EMHQvgC","Eu1zruG","rvjst1i","z0zJtge","wfDuz2K","zNDZxZeUmc4","zgvJB2rLzey","De5uweC","D24GCMvHC28","z2j0wK0","Bg9IywXty28","s0XPswG","y2XVC2u","DhLWzq","D3nZoI8V","qLHxq28","zcWGDw5RBM8","wNrcwge","nhWZFdf8mNW","wvrLvei","x2n1CNnVCKy","y2zxCum","B0fUs2K","vxbKyxrLq28","v0Prwxe","ywnOzwqSihC","y2n2ruW","u01wthy","DgnHDhC","CMvZzxruCMK","ihrPBwvVDxq","vuLKAg4","qM52y0O","yxjYyxLIDwy","yujVDKm","BMvJDa","B3zwBfu","vM9PBhC","B01Ut0q","BwLZzq","DK1NvLy","EwjpvMW","txz6yLO","AevYCM9Yrxy","y09wrvy","nhW2Fdi","sNz3DwK","zfrkCuW","BMzpsLq","zgvMAw5Luhi","vuH4z0C","q1rNzLC","B3jwuMK","CMzYvuS","Cw9JtKy","tKPsCKK","DgfYz2v0","ze1gywC","yuDfrwO","D1fhzvG","AxnrB1nby2S","rLfpEuG","wevLrLu","ALLNtNe","AejNCLG","D3b5qva","B25TzxnZywC","uKL1DLm","C29Tzq","y29Uy2f0","D2vlAMm","CNnVCL92ywW","whvPvum","y25Ly3q","zxq9DxrMltG","zw5KCg9PBNq","ywnRpwzYB24","BwrdBhy","mxW1FdeWFdy","CgvYC2LZDgu","zxjFAxnFywm","C2vUDa","y09lB24","uwfotNu","y3vYC29Y","CYbWyxjHBxm","B3bLBKrc","sfbRAfK","CMvTB3zLrxy","y2vZC0HHBMq","y3H6rue","sMfnzvu","zwrPChK","ywrKrxzLBNq","B2HRt1C","sxLrvha","AxvAqxm","DgvZDa","DNbRrMy","EKnPru8","sgXMC1C","x29UugfNzu4","zezowxu","Chv0","ue52thK","DvPtvLu","wwfKA2S","ENfbwwW","uMriEhG","ywDLrxzLBNq","yMfSrxzLBNq","A1n0yxr1C0m","AxPrCe4","Cu5dD3K","BMnVzgLUzW","C2v0zgi","x2HHBMrSzvi","lcbTyxGGCMu","whvTtvi","DcbVzIbYyw4","zgvIDwC","ANHOAxi","vfHpEuu","AvbhyNm","zw5HyMXLuw8","se1NteG","y2f0y2G","Dg9VigXHCMC","rKHqt0i","lcbxzwjtB2m","D29uzvm","x1fVu01HBMe","BMrWB2LUDfq","qKLiEva","BNDHsxe","B25LCNjVCG","yxrLq291BNq","CgfNzxnOB3C","qwjjsge","zxjYtM8","ywXSzwqGBxu","t0rUDfO","ExbL","A0z3C3m","Ehjdtfq","EhfcAey","vKH1C2C","BgLUzw5V","vuDNrLm","Dg9Vy24","x2rItMfTzq","A0Tkt2e","BvrQwM8","wMr0A1u","svvLrNO","zM5wzK0","DeLK","AKzju1q","uxb0wLy","quPxzhm","wK9qB0K","CfzyzMO","ALb6rNC","wNPXBe0","Bg9N","y29Kzq","B0HSveO","Aw5Lza","qNPyB0m","ywzL","AMXwqwi","uK1sBfG","txbqu2S","yNvMzMvYzwq","zwvKzwq","sxDjr0i","zxjFDhrS","EevMu3a","ENHAr2e","Aw50zwDLCIa","zNvUy3rPB24","vxjcAuy","Ae9Wzw5fDMu","y3r4","zezpuhK","sKT2y3C","wgviufu","swPvsfm","B2fK","z3LUBvu","EK1qtNq","Egr1s0O","CM9YrxzLBNq","vffLtLu","CMvWBgfJzq","vNjlsfe","tM9gsgK","wezYquO","q3HiCw0","y2HnyxHdB3u","zKPjt04","vMH1wMW","CK5qswe","CgPbquS","CgfYC2u","BIWGAg9ZDg4","rxLnBwG","tKDnAeC","s1HPtKC","re9qu1y","u3DpA3a","wgXvtgO","q0TYy3m","DMvUDa","AvLlAfi","vwTTDgi","uK5Tu2S","zKzoEfi","vLjkDg8","AeXiz2m","rfrvuxm","Dg9Y","y0XiELC","DLnZr2S","wvHTrvu","CLnqCgS","EufoEvG","ywLTqM0","zxjHDg9Y","svPYAeS","yuTxwwq","wg5iu2S","r2fRB0O","txj0zxq","Eu5uAe0","sfHoBuG","CMfUzg9T","C29YDa","zNjHBwvuExa","C3vIC3rYAw4","Auz3A1i","C0jf","s3DiBgS","DgXOsMm","zxj2AwnL","uhjPBwfYEuS","ihzHBgLKihm","zKXIthK","ENPPzvi","x2n1CNnVCK0","s3z3Bfm","s0fxExe","wNrhBvC","x2jPBMfYEvq","EwLuA2W","t0vYu2m","EfrXzhq","Bgn5teS","tfDtswy","Cg9PBNrdB24","y3jLyxrLt2i","yNvHv0m","zM9Yy2u","vwrHDgC","EvziyuC","zNjVBunOyxi","r0TkvwS","rgvxtuC","v2Pxv20","zxjFCw9Z","wujmq0i","C1jptwC","wMnnz2i","rxjYB3jdB2q","zwfiwKu","x3DHAxq","B2zMC2v0","Du9dwue","wu9WtNC","u1rZtg0","ELDAyMC","m3W0Fdb8mxW","qMLtsMu","q3LMsg0","x2rLC3rYB3K","rertBLC","vwvNyM4","BNrbBMrvCgq","zNrQrva","CM92AwrLige","A1vsvLq","y29UBMvJDa","B25ozxr3B3i","q291BNq","tw5PvhK","rgn1BNO","qMPVrM0","BxrcqvG","BKLdA1i","Bwf4twvZC2e","y29UC3rYDwm","tffWufC","B3zzBLe","ufvSwK8","tgDwrhG","uxPpqNq","ue5csNO","sfDfCuO","vuDiBuK","De1eseu","tuvtu0fhrv8","uvLZEhO","DxHHvxu","CgLUz1rPBwu","sw5tvhK","q1jIuvm","ve1Tu0u","q0Xpu0ve","BKnjBLq","weXMug0","z2HfAg8","Aezbque","C3vIyxjYyxK","z2v0s2v5","yuvsD28","u1HdzuO","wMPyDuO","FdeXFdb8oxW","DxDoswS","tu5wDKi","u2rwrei","CMvZB2X2zq","y3vYCMvUDeK","zgztChK","z3fPBMu","zxmGCMvHy2G","C0Tnzeu","y29TCgXLDgu","zMX1C2HfEha","CMvTB3zLq2G","A2HYBve","CfH2y0u","yvrOtfq","x3bYzwzPEa","Aur1A3y","BMDuAw1LCG","qMnKCKG","EhfUvvC","yvzcr1u","u25Wwxq","u0fIsgG","thfks0u","rK1MtKy","x3bHDgHlzxK","qwjHuvy","AgLqDfK","DxrMofDYAxq","wLPbCgm","BeXIqvi","D2fZq2XLyw4","Dg9cExrLC0i","Cgf5Bg9Hzfq","BwLUAvbYB2C","t3H5vNO","y3jLyxrLt3a","rNbKBfa","AwXK","C2jou0e","zhvyAxe","x3nLBMrby2S","tgTtsgq","B3bLCNr5tMe","y09NzxC","A3HwyNa","Be5AEMW","y1fMAMG","EMHnzuy","EfvZzuvUDG","ufrTCNK","x2LZtwLUAvq","BKDHwLm","zw5JB2rPBMC","DenoB1a","q2vjzeW","BKXPBMu","DxD2v3C","s0Dmt20","DvnftvC","B25szwnLAxy","Cgf3D3m","rNzLsvy","y1v0Eum","zgzkzxq","icSG","A0HQtxe","ywrKq291BNq","q1fhAwO","A0rTz1q","qwjVCNrfCNi","yKffzgO","Efrurw52","CwDyCxq","BM5Ly3q","CMfNzvn5BMm","CM92AwrLihC","Axnby2TdBgu","vgP5Chi","wvPLD1e","Evb3u1q","CMvJzxzPzwq","C2vYDMLJzq","mhWXFdv8m3W","AvDTAvK","v3DQELu","ywDLu2HVDW","AgfZt3DUuhi","zsbHihn0CMK","wLvqz08","CNnVCKzPBgu","B25VCgvU","v2nRwKK","AhPXC3m","rhnJDLG","vgrJquS","vezdzNu","zNLKzuu","yw5ZzM9YBvq","t1bftG","Ef9MCM9UDgK","qwnAsvG","twXotxm","C2v0u3rVCMe","B0rzzuu","swnQz3C","ELfns0u","qKjYDwq","DMfS","yMDhzwi","yMXVy2TLza","Bwv0Ag9K","CgfWs2e","uKDKDhK","D0Twvuq","Bhvcqwi","y2rkvw0","yxbWBhK","sNvUzxa","wgLgtfm","serjBg0","Au9UAMW","u3jREwy","DwrMqKq","C1n5B3K","AgfZ","BwvKAwf0zwW","yKDzwKm","r0TqCwm","BeD0s00","Cu9rqNa","CM92AwrLihy","y3jLyxrLq2W","suvtx0vsuK8","t1zuDvq","DMfSDwu","z1rPBwvVDxq","B3bLCNr5","sNziu2G","EwPSsMO","BwfW","yxLPuMq","ywXS","mJeYmZqYmeXhC3vSDq","ywX3yxLZ","DLbxr0W","t095r3C","y05Svgq","C09kufq","q3vRsgu","wwvmEgC","EK1JBui","wgDcrvu","s1Hkt1C","sxrnwMO","A0HArfq","tw1sr2q","C3nzrw8","yw1L","odq4mdu0uvDmug9R","z2v0q3vYCMu","Dg9hzw5LCMe","vuPxCwW","AxnFywnR","Ahn6yvu","vvPSBhi","Aw5N","vwzsuK8","s1HHwuy","EfPjsMe","rxrvwLC","x3bPBMDmB3m","zNjVBNrPzxi","zLbPs2C","BMrLEa","C2nYAxb0","vuftrha","CNjVCK1LC3m","x2LUAxrhBg8","ueTSAKO","BMvY","EwfyBwq","BMrWB2LUDca","Ae1LC3nHz2u","AxnAzxjV","q1PUCw0","sxrnEvG","y3PbD3m","l3DZl3yY","AenSB3nLrxy","x2XPC3rLBMu","BMCGzMfPBgu","q3vZDg9Tq2W","CurOtxa","vvb4rNG","BfrPBwvVDxq","qLvPz3q","qNDtDM0","C3vJy2vZCW","D0T0swi","Aw9UvgLTzw8","zMLUza","CMvUDevUzha","Bwfgs1q","AxjltxC","BhjjAMS","qLPoBuq","q010DLC","yNvMzMvY","y2PdugK","C2vUza","tu1tvu0","mxW1","z2v0","y2XVC2uSihC","CKLhtMy","zxHWB3j0CW","qMP5Efq","De1HBMfNzxi","Aw5JBhvKzxm","Ec1TC2CTCw8","zu10Dhi","C2Pgqvu","tvrHshK","y3ruAw1LB3u","wvLZDhG","uLvuAu0","EuLbDu0","DhjHBNnHy3q","ywWGy3vYC28","t1LVBum","yvHstgC","uLrcz1q","svjbv0e","yunrue4","z0PdrM4","yMLUza","tNn1DNu","Ce5RvKO","tw9KDwXL","zw5fDMvUDa","tLfzBxa","DhjPzxm","BwvZC2fNzq","EfjWv0y","B1rfv2C","DwvWDwm","BMv3vMvYC2K","zNjVBujPDhm","x2LUAxrqCM8","t2PPt0q","CLfju2q","x2nSzwfYugK","BgTTBM4","y1fIEM0","tuDXz0G","twrcEeO","ywnOzwq","y3rsvK0","DxbNCMfKzw4","zNjstM8","C3rVCMu","uNjbs3q","C2vYDMvYvgK","vw5PBxbSzw0","u09SDLK","BLbAvva","wwXesgW","C1fTv1e","DM5KEfe","z0zyCKG","C3bmqK0","Dgv4Dc9WBge","B2nRzxrgywK","C3jJ","zvD4C0m","uhzlyNO","yLffv1q","AxjLza","y2fSBa","B2jQzwn0u3q","CNnVCL9Uyw0","CMvHzg9UBhK","z0fjA1G","rhLkveq","BfjRyK8","CM92AwrLigi","zhD1vM8","BKztB3K","DMLJzuLeig8","qNH0EK0","CvDQEuu","z1rHz04","A2DTz00","DM9HugW","q1LOtKm","Dg9mB3DLCKm","x2TLEvbHDgG","C2vLvLa","ywnRtxnNswq","ywLHCNy","DhDVCMTdAge","rwjPuLi","AfvJCey","sLPty2W","A3vusKi","CMDswwK","s0ziC2e","rfjiv1K","suTdAwu","x25HDMLNyxq","x3jLy29UBMu","zv9ZDwnJzxm","y3vYCMvUDeu","zNjVBuj5Dgu","vw1OBMS","B2nRzxq","shvcBvq","reXOB2C","wMzmrK4","BwvZ","BvrfywW","C0XPC3rLBMu","Aw9U","DgThrgq","wKLszNC","B2LUDfjLywm","AeTuzuO","t0TMu2i","r2zTB2u","AMvJDfn0B3i","t1bftL9fuLi","zKD4wLa","ChbL","CKXABMu","zNDntKG","s3HdruC","D2Hfuw8","z3PQDgy","y29UBMvJDfm","D3D2wKe","Dg5NrKy","zhnitgm","rLDt","uhHLqvm","ww5Oy3a","wgT1Efq","AgDKCxC","AxnmB25N","ywnRDxbfBMq","B3jRig9MzMW","tfDAuhi","Dg9LAvq","ywr2yw5Jzq","s29QDhG","x2LZsw5PDa","ELLkAuq","s1nqDgy","wfjuqNO","CMvHzfvjBNq","C3rYAw5N","x29Ut3bLBG","B25tDgfYDfi","Bxz6ELy","sxnryvy","Cw9Z","BfrODei","zxP4CMu","ChjVy2vZCW","A3LvBe0","DgLUzYbZzxi","BLDTs1O","mNW0Fdb8mxW","CgLUz19VBMm","u3f6DxC","BK11Ee0","A3Ppuwq","BMHuuhC","D3jPDgu","wu9kAxu","AxmGDw5Kzwy","z29PBMCGyxC","B1DWv2S","ndK4uNv3qNfQ","z2v0qwXSs2u","yxbWBgLJyxq","Cg9PBNrbBMq","Bwf4uMv0CMK","C1DyC2O","nNW0Fdn8mxW","y2DyDvy","DLLSsNm","sNrvweq","B3nLza","Dwj2twS","y291BNq","CunKwMS","zgf0yq","BfDqwwu","BwvZC2fNzv8","AgvHzgvYCW","DcbSAw1PDa","twvZC2fNzuu","Cfburxm","sgf1B2i","zeH3EwS","CNzHBa","ALjJEgi","sw9rqwS","sLnptLa","z2vY","CMvZzxrdB3u","CMv0CNLdB3u","rMnvEMy","ALjRzhK","zMvY","BMDLza","ig1LC3nHz2u","CejQvw0","rfDvvui","rg12qKG","yKXuDxe","rK9QrfK","CMvKDwnL","Cgf5Bg9Hza","y3jLyxrLrwW","tw1vqMW","ENf2z2m","wfnlwgm","ihbYB3rVy28","DMDMzgy","zMLN","tgLZDgvUzxi","De5Zr2i","t3bLBKv2zw4","A1jyq0e","CMvXDwLYzwq","Aw5KzxGGB3u","B25fCNjVCG","zMzmAw5L","Dhj1y3rVCIa","ELzdy1G","zwHiDMy","C2v0q3vYC28","uen4q0u","yxbWzw5Kq2G","r3fgAwq","B2nRzxrtDwm","BwrSyui","yxnZAwDU","ufzotKq","yMLUyxj5vhK","r2TJrMG","igzPzwXKoIa","uLrSAw0","AM9PBG","rKf1tgu","C2v0","Bu54D3e","vgr3q1e","Dw5ZAwDUzwq","wMXPAu0","x2fKzfDZtgK","wKLuvgm","tvHRCfe","x2HHBMrSzu8","rvzLBLm","t2jQzwn0","u2D6zNq","thrOrNa","z2v0qwXS","mMfODgHvzq","zMLSDgvY","otu2nJLoCMzRyNO","qwHYDwi","rhvTv2K","ihjLy29UBMu","zhbVqxC","t05irMq","sezlD0C","AhvJDuq","qLjezK4","C2fNzq","yKPbA3a","r3fMsuq","rMjSEKS","y29UBMvJDca","q0fOEgG","y2XVC2veqG","wKDdtxy","AxnrB1nnzxm","wKndDMe","EurQCu0","y3vYC29YlNm","B25pCgvU","y1DSAfm","jMPZy2fSBgi","AMznyuy","z2vtEw5J","zufJAW","rNnzzwm","mtfOqLLXEgG","A2XZrKW","D3LXzem","zgLZCgf0y2G","BeHHBMrSzxi","z2v0u3rVCMe","EgfWvhe","CuPiwe4","r0vWBxu","Exzrz2K","x3DZ","mtj4txPwwuq","y2Tqs2O","BwvY","mhW0Fdn8mNW","C2zTu2G","B3vUDa","tg9NsurozxC","uMHHBNK","ywzqCfi","x3nVy2TLDa","q0Pys08","qNfgrgK","zxH0zw5ZAw8","B2zcyKy","ChvZAa","ue5KqMK","DxbKyxrLq3u","CgXLyxnLiha","zhLJzgu","yw5Hz2vY","mJy4mg9xwwrZva","r05LweW","A2v5","yw5Nzq","Bw14D0e","DxnLCKLW","AgvHzgvY","CgThyxC","y2HHCKnVzgu","x2rYB3bhBg8","otmWotq1B0TRBxvu","r3voy2q","Bg9NsurozxC","AMzYsfa","wKXOwK8","BwvZC2fNztO","uLnQsxC","DxrVuMvJB24","ihzHBgLKigq","Aw9Ul2PZB24","DKHOA0y","y3ftDgS","CMLLC0nVDw4","v1jYCvC","D2nzt3y","B3jL","yvbUwK4","yM9KEq","vgfN","zw1LBNq","BM9Uzv9UB24","BMD3ruW","A0zIzMy","AeDlzuO","rxzLBNq","z3n3tfe","vMrVv0i","ANz4Evy","AuLuuK4","BezSDxnO","y0neuhG","BMjpvKK","q05PCwu","zKfcy3y","Bhfxq3e","tg9Nsuq","B1HnsvC","zuvyEKG","CIb0DhDjra","rhjIvui","AwXSihvZzsa","DwvHt1a","zfbRshi","uxDrD2O","y2HLy2Tszwe","BxnNsuq","rwfXExK","Ahr0Ca","q0rsuMq","yvfMqLK","twXjyKK","DhjPzxmGCMu","C3jAvem","AefJA01LC3m","ignVzgu6ia","ywDL","x2LZtM9Kzq","ihrPBwvZ","DujNr0G","vwryz0G","yw1LoIa","zNjVBuHHC2G","tMfTzq","v2DQruC","ywXSq3vYC28","x2nSzwfYvgK","zMzLCG","wxvQt2y","zv90Aw1LB3u","CgLUz0XVC3m","zw50tgLZDgu","y3nJvhO","ysbTDxn0igi","yM1bzg0","q29UzMLN","D2LSBfjLy28","ugfjz2u","DhjPBq","yKXrEhe","EK10q2G","r3fqExi","zNPvq1u","wK91te0","B3v0sw50zxi","AvjkEeW","z2vrDwv1zuW","vhDoruy","zKfNt2S","yNLL","ywnRx2nVzgu","x3fVC0rc","zKXbv3e","zMLdywy","zxH0ugf5Bg8","sxHkwvi","uevjrLy","ChjVDg90Exa","vMvbt0u","BgLizgu","terkt20","reiGzMfPBgu","wKrKCMO","B3jLtMfTzxm","u2zbr2G","Axrjtwu","DwnQzNa","we1drhC","yxv0B21HDgK","s1LnBgW","r1v1Bgi","B25Uzwn0Aw4","tu5lswu","CMTLCKDSB2i","D3DXtwW","AvLuuwu","q2jTr08","v1Dks3G","x2rPC2nVBM4","Dg9tDhjPBMC","zvLyBfO","Aw1LCYbPBIa","x21PBMLoyxy","Dhr3Awq","tKn4AwC","B09AC0i","D3v5AuG","qK1rAxq","B25SAw5L","vhrbCMm","wvnbC2e","zxrxB3jRq2G","C3rVCcbPBw0","z2v0q3vYC28","y2XLyxi","lcbOB3n0BMe","teryDNG","CMvZDwX0","ywrKt25L","EwndzvG","ruPzthy","x2LUDgvYDMe","D3LVvhy","B2zM","DwHPzNi","zwnVBM5Ly3q","wLrQEu4","q25gr3G","ENf3uKS","x3nLCuLK","wfPAwg0","mZmZmdiZnwjguMv0BG","Dxrjza","zNjVBu51Bwi","y2HLy2TdDxi","EvH2twG","Cgu6ia","ugTiree","C3bSAxq","zgvS","zvL0DNy","AKvjDvK","Dev2zw50","u1LPq0u","BNrfBMrWB2K","Aw5KzxG","tKndBuK","C1DwAwu","Ec1TC2CTy3u","vNbXrM8","CgLUz0LUDgu","q0zgEuS","BMvvuey","igXHCMDLCIa","yMP4swu","r0LZyK0","zxjYtxnN","zw1PDa","C3rLBMvYCW","BMCGDxjSoIa","u2HHCMvKv28","AhDZvNq","Dgv4DfbHEwW","EKrLBvC","AK9squ4","rxfiDhq","AhvuEKC","B0HQvem","C3bSAwnL","vu1LsMm","y2uGBM90igK","y2XLyxjtDg8","wNLXC1C","vxPmBwS","x2nYzwf0zvm","rvr2A2q","zLH5zfm","s1HSwgG","z21VqvK","Bhm6ia","Dw5KzwzPBMu","B21JBum","EeDQtMe","C0fStvG","EMvhve8","y2HnyxHuCMK","x2rLyNvN","sKP2zgW","x2vUzhbVAw4","Eg51Awe","BNrLCG","whvnsKq","v1nwBuO","B3jpBMXPBMu","Dxb6BNu","tw5QC0u","DgLLCKPtt04","zxjYB3i","BLvKAM8","rwfmA3O","uMvJB25Uzwm","q2fNz2O","CND5sNK","DffSCw8","zgvSzxrL","x0vysvnu","Cxn1zwC","whj1vMu","yNL0zxm","AgLNAa","DgHLBG","twjIt04","AvvSy3e","twrXyKm","DeH5zem","CMvHC29U","terky0O","rLzswM8","y3zbExO","D3rYCwi","q2zuq1G","rhvbywe","C2HPzNq","vg5myw4","y3vYC29Yx24","x2DLBMvYyxq","BMfTzq","y29UBMvJDgK","mtCYmtDoA3ffvgi","ExLtEfO","B25mAw5L","wxriEKi","AgvKtwf4uMu","vfPUr24","DezMrwK","DwLjCvm","zgvSzxrLrge","yxKSihrYEsa","EvLXwMm","wKLLwgG","qwnJy3y","C3vqDu4","id4G","t1fHwee","yxnL","x2DLDeLUDgu","tLzvsLe","r2vsuuG","zxjFCw9Zx2e","vK9nyuW","ugv1A3y","wK1pD0C","r0L1Evy","vvzWuMW","A0LZtey","EeDevNm","DgLPz2m","tuDtDwC","v25Jyue","tNPhr0y","C2XHvhi","y1HpvuW","zg9Uzq","wfbYu1a","ugftAvu","CMfTzq","ChfsAwe","zw5HyMXLqxu","yMfSu2nVCgu","AgfUz2u","AwTHsMW","s1jtD28","BgLZDgvUtMu","u3rYyxrLz3K","uK9YBKG","tNvezK4","D2vI","yNL0zuXLBMC","sNbnq1u","wK1MCKK","B3bLBG","BMvLzf9Hy2S","zw50","Bwf4tg9ZC0m","DwD1C2K","DNriyxi","z3n2BxO","swjyD1G","BMXWweS","zLnVDfi","AeDJteq","x3jLBw92zvC","Ahr0Chm6","mdaWmdaWmda","quLXrvq","x2LZqNjVD3m","zu1ZrLa","C2XPy2u","AMLizgC","A2v0ignVBNm","mdaWma","z2LQtKi","zK5RuMi","y29UDgLUDwu","x3jLywr5q2W","x21LC3nHz2u","z2v0sxrLBq","AvrAv0u","zMLSzw5HBwu","B2fJsue","DezozLO","BgLUzq","Au5Rz04","DLjIque","tKLpuvK","CKLpDe0","B25tDg9Wsw0","DLrxEu0","qvLRzLe"];return Yo=function(){return t},Yo()}var Oe={};(()=>{let t=F,e={KLiIh:function(a,n){return a===n},Uegbn:function(a,n){return a<n},rSPpk:"XaTLg",nPZUP:t(1005),fzUCU:function(a,n){return a(n)},NLTFs:function(a,n){return a+n},LgVDx:function(a,n){return a*n},fHfbN:function(a,n){return a(n)},VpqFo:function(a,n){return a+n},EfqEP:function(a,n,s){return a(n,s)},XxDVm:function(a,n){return a+n},ONHFd:t(1576),SAbHh:"ffff",CKrcs:t(1569)+t(1569)+t(1569)+t(1569),VRJto:function(a,n){return a||n},LNCpu:t(1762),Icjgw:"ping_once_success",DZlBj:function(a,n){return a>n},gTagN:function(a,n){return a(n)},MXkpQ:function(a,n){return a+n},zCiEO:function(a,n){return a&n},cfWqC:function(a,n){return a|n},xGDVs:function(a,n){return a||n},KNtBd:function(a,n){return a>>>n},kURVT:function(a,n){return a>n},OjiOD:function(a,n){return a!==n},uwNIk:"XtcvL",ZLabH:function(a,n){return a===n},vJIls:t(278),ZIeXh:function(a,n){return a>n},nbOVI:function(a,n){return a<n},afPpR:function(a,n){return a!==n},FYAEz:function(a,n){return a-n},FMfNF:function(a,n){return a!==n},nWmKZ:"eYXlZ",SOlvY:function(a,n){return a<n},bAEdj:function(a,n){return a!==n},ghEho:function(a,n,s){return a(n,s)},bmAdm:function(a,n){return a(n)},PNdBi:function(a,n){return a(n)},zYJiD:function(a,n){return a(n)},WRReZ:function(a,n){return a(n)},HJuFl:function(a,n){return a&n},xGjNa:"Missing "+t(1151)+" field: "+t(850),BUnLd:function(a){return a()},zqAYl:function(a,n){return a!==n},ZtGmW:function(a,n,s){return a(n,s)},ZcMgb:function(a,n,s){return a(n,s)},MvzbZ:function(a,n,s){return a(n,s)},neUPF:function(a,n,s){return a(n,s)},KGLOm:function(a,n,s){return a(n,s)},ovYnQ:function(a,n){return a(n)},Zksqy:function(a,n){return a===n},tMuSd:t(452),UPxFx:function(a,n){return a!==n},TNgcB:function(a,n,s){return a(n,s)},VrKHQ:function(a,n,s){return a(n,s)},bKdJK:function(a,n){return a!==n},MNKIe:function(a,n,s){return a(n,s)},ueaOP:function(a,n,s){return a(n,s)},woTeS:function(a,n,s){return a(n,s)},utddW:function(a,n){return a|n},aQfBY:function(a,n){return a>>n},OOyGw:function(a,n){return a|n},CDRRd:function(a,n){return a&n},BiSJe:function(a,n){return a>>n},wOrmA:function(a,n){return a>>n},SnpYt:function(a,n){return a===n},IZCYd:t(1141),ScOye:function(a,n){return a(n)},wwvZA:function(a,n){return a(n)},ZMfrI:function(a,n){return a>>>n},nGaZS:function(a,n){return a(n)},TQeNU:function(a,n){return a(n)},HqeOF:function(a,n,s){return a(n,s)},DwJqg:function(a,n,s){return a(n,s)},MlIbI:function(a,n){return a(n)},kMSXv:function(a,n,s){return a(n,s)},sOJPT:function(a,n){return a&n},tkGDd:function(a,n){return a===n},ftjEP:t(354)+"required"+t(1168)+"SeqID",xapTq:t(354)+t(1151)+t(1168)+t(1292),fNkRb:t(354)+t(1151)+t(1168)+"service",KaxTp:function(a,n){return a===n},Hcdmd:t(354)+t(1151)+t(1168)+t(826),YlDHl:function(a,n){return a+n},zqvgc:function(a,n){return a(n)},JtUXD:function(a,n){return a(n)},toqgY:function(a,n,s){return a(n,s)},iFPXW:function(a,n,s){return a(n,s)},NGMhG:function(a,n){return a>=n},gFXrH:"Skip pas"+t(1116),YYstx:function(a,n){return a>n},cCjeT:function(a,n){return a+n},bJAkp:t(1790)+t(1116),xrCLT:function(a,n){return a(n)},Bruoo:function(a,n){return a!==n},kDmgT:t(601),fwMNH:function(a,n,s){return a(n,s)},AeFbv:function(a,n,s){return a(n,s)},JKvcw:function(a,n){return a<n},GtaKc:function(a,n){return a+n},oDYeE:function(a,n){return a|n},KwHlk:function(a,n){return a<<n},TvJZV:function(a,n){return a&n},WncaA:function(a,n){return a&n},jYgNq:function(a,n){return a<n},ZUsYz:function(a,n){return a==n},EcfEX:function(a,n){return a+n},MdqbC:function(a,n){return a|n},HXNmH:function(a,n){return a|n},Oytia:function(a,n){return a<=n},aThLT:function(a,n){return a(n)},YBLCB:function(a,n){return a&n},WjWWm:function(a,n){return a>=n},PkHDA:function(a,n){return a+n},aCQPN:function(a,n){return a+n},wuyiH:function(a,n){return a+n},yiTkl:function(a,n){return a+n},sWVie:function(a,n){return a&n},papKa:function(a,n){return a|n},FcUzf:function(a,n){return a<<n},nICkR:function(a,n){return a<<n},dsHLc:function(a,n){return a&n},ZfLFN:function(a,n){return a&n},lgFUo:function(a,n){return a&n},SvOOD:function(a,n){return a<n},KXaYF:function(a,n){return a>n},ndMcx:t(448),yvQgi:function(a,n,s){return a(n,s)},KeSKL:function(a,n,s){return a(n,s)},GqPyr:function(a,n){return a+n},RTBgT:function(a,n){return a<n},mTEal:function(a,n){return a<<n},GIuyV:function(a,n){return a&n},CouHV:function(a,n){return a!==n},FhqcJ:"ZGBup",uiIqS:function(a,n){return a&n},UNSWy:function(a,n){return a|n},fSotR:function(a,n){return a|n},pmsfC:function(a,n){return a>>n},ODntZ:function(a,n){return a&n},kuTJB:function(a,n,s){return a(n,s)},fFdcS:function(a,n,s){return a(n,s)},SIfiz:function(a,n,s){return a(n,s)},YlIqB:function(a,n){return a<n},OVTuT:t(1075),GEpmu:"GbFzY",cWlhS:t(1296),buaWC:function(a,n){return a|n},UpXNq:function(a,n,s){return a(n,s)},yySxZ:t(399),ctRVM:function(a,n,s){return a(n,s)},yANyX:function(a,n){return a|n},aFTDQ:function(a,n){return a&n},dqtNF:function(a,n){return a>>n},ycCeX:function(a,n){return a|n},cgXuV:function(a,n){return a&n},HYGFM:function(a,n){return a&n},JZScl:function(a,n){return a&n},wzRjX:t(1530),izQpN:function(a,n){return a&n},EMHzH:function(a,n){return a&n},sQzOZ:function(a,n){return a(n)},tQxNq:function(a,n){return a&n},EbiRR:function(a,n){return a&n},PVNND:function(a,n){return a===n},XFfIW:"Spvuq",iDukv:function(a,n){return a&n},bdtpL:function(a,n){return a(n)},QyQSf:function(a,n){return a(n)},iUlcq:function(a,n){return a&n},nfOJT:function(a,n){return a|n},CAhxh:function(a,n){return a|n},zkpoL:function(a,n){return a>>>n},IoQAk:function(a,n){return a===n},OOojw:function(a,n){return a<n},ahale:function(a,n){return a<n},Acccv:function(a,n){return a+n},jlVAb:function(a,n){return a|n},jRcxb:function(a,n){return a&n},ZzqlM:function(a,n){return a+n},KxCEG:function(a,n){return a|n},KXJOW:function(a,n){return a>>>n},FsYec:function(a,n){return a>>>n},UmyxN:function(a,n){return a|n},ZLhZO:function(a,n){return a!==n},dycde:function(a,n){return a&n},mNxwq:function(a,n){return a!==n},pawws:function(a,n){return a>>>n},lWPYe:function(a,n){return a&n},hzqss:function(a,n){return a|n},UGPfP:function(a,n){return a!==n},DscvX:function(a,n){return a(n)},XZZXm:function(a,n){return a|n},RletM:function(a,n){return a<<n},wyoTv:function(a,n){return a|n},AbaQV:function(a,n){return a<<n},DDSnW:function(a,n){return a|n},NCCmI:function(a,n){return a|n},hGKeJ:function(a,n){return a<<n},tFNfZ:function(a,n){return a<<n},XgBEU:function(a,n){return a<<n},NoFHi:function(a,n){return a|n},fGxZP:function(a,n){return a<<n},mmxwA:function(a,n){return a<<n},MBSfp:"0|5|2|4|3|1",tNsGb:function(a,n){return a<<n},uFBLz:function(a,n){return a|n},CxHqm:function(a,n){return a>>n},hiPtY:t(1109),ohkOW:function(a,n){return a===n},PvKbz:function(a,n){return a|n},ETvkd:function(a,n){return a|n},sAlMX:function(a,n){return a|n},dwuVo:function(a,n){return a|n},HDIlm:function(a,n){return a|n},Caggj:function(a,n){return a|n},Damuj:function(a,n){return a!==n},CUgCu:t(1106),IAbnP:function(a,n){return a&n},toeiT:function(a,n){return a>>>n},MuqTp:function(a,n){return a&n},PGKzk:function(a,n){return a&n},ucjfp:function(a,n){return a>>>n},JaMeU:function(a,n,s){return a(n,s)},ItMZj:"CtRdA",pfkte:function(a,n){return a>=n},oTEWg:function(a,n){return a<=n},vHhkF:function(a,n){return a+n},ZOuLM:function(a,n){return a%n},vIHlN:function(a,n){return a/n},CxLaA:function(a,n){return a instanceof n},Voilw:function(a,n){return a!=n},Eaqyy:t(1100)+t(1266),RrAKt:"text/plain;chars"+t(461),PKljJ:t(1696),mdlaB:function(a,n){return a*n},zVCcX:function(a,n){return a===n},XHZcC:function(a,n){return a===n},Jeobj:t(1474),XPrSP:function(a,n){return a>>>n},rLZne:function(a,n){return a&n},cCClB:function(a,n){return a>>>n},Mrtet:function(a,n){return a+n},OOOwN:function(a,n){return a>>>n},eQnVr:function(a,n){return a+n},PaSiU:function(a,n){return a|n},ZtBXa:function(a,n){return a<<n},liHde:function(a,n){return a===n},oIhaR:function(a,n){return a>>>n},lRkbO:function(a,n){return a>>>n},Sgzft:function(a,n){return a===n},aHbvs:function(a,n){return a<=n},zYsgA:function(a,n){return a>=n},LFqYk:function(a,n){return a+n},XQMBz:t(1030),CeIdL:function(a,n){return a===n},bQEWT:"PhHnf",JiXqr:t(1150),vgfdf:function(a,n){return a&n},XkuxT:function(a,n){return a>>>n},UMeJc:function(a,n){return a&n},pFWJq:function(a,n){return a>>>n},hszaU:function(a,n){return a>>>n},gmoAY:function(a,n){return a&n},UrBiF:function(a,n){return a>>>n},hUcpF:function(a,n){return a>>>n},ybuRe:function(a,n){return a&n},wKtIb:t(465)+t(714)+t(1645)+"3",cvAyz:function(a,n){return a<n},iFwkR:function(a,n){return a>>>n},vYeJh:function(a,n){return a!==n},lbEhe:t(1755),lGtKM:"suPjW",VLOTe:"NATIVE_E"+t(1624),pXvcE:"CONNECTI"+t(1791),YVqPt:t(321)+"IES_ERROR",XruVe:t(697)+"ERROR",qWjyE:"OPEN_ERROR",UVpRl:function(a,n){return a===n},DeWMG:t(696),EOMAY:function(a,n){return a>=n},UdXgH:function(a,n){return a-n},wyqdC:function(a,n){return a===n},cHTQj:function(a,n){return a===n},oXMIW:"yQcXj",rOuhT:t(1361),cdJUm:function(a,n){return a==n},REQjw:t(1473),omcmC:t(305)+"d error.",lnUGS:function(a,n){return a+n},KAWyq:function(a,n){return a===n},lrIjk:function(a,n){return a===n},zxZGa:function(a,n){return a===n},jfMaF:t(487),uSLQv:function(a,n){return a!==n},mVVyF:"fFNxR",EaLkz:t(1556),sjFAU:function(a,n,s){return a(n,s)},fYFaJ:t(958),WAZNV:t(1384),voaPl:t(1719),GIsbM:"xHnEZ",SzwFX:"zZwVK",FveIV:function(a,n){return a!==n},mpsaj:t(1419),cCDPx:t(1456)+"d",QzOBt:"cursor_file_name",GUulb:t(824),fLbLy:t(405)+"0",lpDwO:function(a,n){return a!=n},VHusg:function(a,n){return a+n},tFfEi:function(a,n){return a===n},kYwtm:function(a,n,s){return a(n,s)},Gfmoe:"BzZZw",TYjKx:t(932),UGHmI:function(a,n){return a<n},IsQaV:function(a,n){return a&n},QiKyh:t(1328),JzyBV:t(1606),TMmSE:"QbCJm",WDiaL:function(a,n){return a>=n},hunoO:function(a,n){return a&n},bUsUH:function(a,n){return a&n},jORAN:function(a,n){return a>=n},MmRGd:function(a,n){return a<n},KDugz:function(a,n){return a|n},rYPyZ:function(a,n){return a|n},dTJqL:function(a,n){return a&n},lIEhF:function(a,n){return a|n},CTgfW:function(a,n){return a<<n},nwaIq:function(a,n){return a&n},Yuhfx:function(a,n){return a&n},ZskHr:function(a,n){return a<<n},wcYOv:function(a,n){return a+n},cQfjh:function(a,n){return a&n},KFHsa:function(a,n){return a<n},EqHtt:function(a,n){return a|n},zYvtM:function(a,n){return a&n},gwaUQ:function(a,n){return a===n},RABiQ:function(a,n){return a&n},wkMIS:function(a,n){return a+n},jEIuY:t(668)+"2|5",UzLmk:function(a,n){return a|n},XuMJD:function(a,n){return a>>n},iWmiY:function(a,n){return a>>n},kHjMq:function(a,n){return a|n},XeHPU:function(a,n){return a+n},iHxYc:function(a,n){return a&n},zeGTO:function(a,n){return a&n},NQYmp:function(a,n){return a|n},nMuxM:function(a,n){return a&n},ufjLR:function(a,n){return a&n},zzieR:function(a,n){return a||n},aBovC:function(a,n){return a===n},rwsEP:t(1231),wtrqb:function(a,n){return a(n)},UIdhn:function(a,n,s,l){return a(n,s,l)},FblzK:function(a,n){return a instanceof n},QxlPt:"timeout, try rec"+t(1367)+"g",BCNAM:function(a,n){return a===n},jXzVz:"NTuzE",sEBHg:function(a,n){return a instanceof n},KuJmH:function(a,n){return a instanceof n},OKfSb:function(a,n){return a===n},pyXfB:t(1190),tngFF:t(358),Junep:"boe",srZTC:function(a,n){return a>=n},Vbklf:function(a,n){return a(n)},LkSHd:"unknown "+t(1491),YeLxg:function(a,n,s){return a(n,s)},qfNTc:function(a,n){return a!==n},gqine:t(838),uToyx:t(1052),MStNC:t(890),uOCYA:"text/jav"+t(1661),ayiRd:function(a,n){return a+n},jxhir:function(a,n){return a(n)},vRbAA:t(273),MniTy:function(a){return a()},Ahrub:t(1181),AbIHa:"yBbWH",PxeAS:"ZkLDM",slaTr:"VOKdx",ptuas:t(921),CYhNC:"wLCtF",KYMll:function(a,n){return a||n},WRrqW:function(a,n){return a||n},BIHyP:t(1547),GkcFh:function(a,n){return a>>n},CbmGO:t(1089),ccvEL:function(a,n){return a(n)},qocNF:function(a,n){return a<<n},XumMR:function(a,n){return a&n},JRQgd:function(a,n){return a&n},vhyWr:function(a,n){return a&n},oHlTJ:function(a,n){return a&n},SGpHP:function(a,n){return a&n},fPiKg:function(a,n){return a(n)},OGBQc:function(a,n){return a!==n},ZZApc:"zgIVm",azFsn:function(a,n){return a||n},cxzEA:function(a,n){return a||n},NJRrI:function(a,n){return a!==n},qOQBp:t(1493),BMQit:function(a,n){return a||n},xxZrn:t(1080),yMYEH:t(1114)+"id",WWJKx:t(815)+t(1524)+"ck",hgdqw:t(815)+t(467)+"k",FuYuo:function(a,n,s,l){return a(n,s,l)},fFglu:t(1557),vSsGk:function(a,n,s,l){return a(n,s,l)},DfUEJ:"is_ack",BUigt:function(a,n){return a&&n},IiGYK:t(325),pjAAK:t(1346),GakoJ:t(329),BntqG:function(a,n){return a(n)},DvmLD:t(752),woBRj:t(1748),YSAsa:function(a){return a()},xTqdt:function(a,n){return a>n},YXmEU:"DjuVG",maFKT:t(474),zMPNt:function(a,n){return a(n)},CJXKO:function(a,n){return a+n},fRmzk:function(a,n){return a|n},PNvLy:function(a,n){return a+n},QTGXM:t(902),kKJOa:function(a,n){return a||n},HWEqJ:function(a,n){return a>>>n},fMLnf:function(a,n){return a(n)},lLbAR:function(a,n){return a+n},Udatg:t(1152)+t(506)+"ge: ",DuAaa:function(a,n){return a||n},qduZp:t(1518),DmvBH:function(a,n,s,l){return a(n,s,l)},PEIFV:function(a,n){return a<n},iduUF:function(a,n){return a<<n},ssYEo:t(724),DOPSV:t(1808),FvLNp:function(a,n){return a!==n},GqfID:"wUwUr",wwXFI:"1|2|4|0|3",iSxyE:function(a,n){return a+n},qJHXN:function(a,n){return a+n},qoErw:function(a,n){return a!==n},dxIMo:function(a,n){return a!==n},tHydC:t(998),gFcLa:function(a,n){return a|n},hKTeJ:function(a,n){return a<<n},umWrK:function(a,n){return a+n},mrQIE:function(a,n){return a+n},yTsLs:function(a,n){return a<<n},XuiUC:function(a,n){return a+n},ugusi:function(a,n){return a<<n},OsffD:function(a,n){return a+n},XYeyc:function(a,n){return a+n},dFNYu:function(a,n){return a&n},yaXmd:function(a,n){return a+n},uSEMW:function(a,n){return a>>>n},fABcv:function(a,n){return a&n},BXWCo:function(a,n){return a+n},SGqzn:function(a,n){return a>>>n},XnHSk:function(a,n,s,l){return a(n,s,l)},ntTeO:function(a,n){return a!==n},jbsBz:t(683),aiarv:"vnghg",ZITTc:function(a,n){return a&n},uAqgY:function(a,n){return a|n},fwJgn:function(a,n){return a<n},xnuia:function(a,n){return a<<n},ESHgK:function(a,n){return a<n},LDJOm:function(a,n){return a|n},WfSQP:function(a,n){return a|n},rnMST:function(a,n){return a|n},Jvwui:function(a,n){return a>n},tlhJc:function(a,n){return a!==n},gsvmz:t(836),bqDkD:function(a,n,s,l){return a(n,s,l)},NNpgz:t(1208)+t(631),nlnJh:t(1253),zMtCh:t(797),pVXfj:"name",hHTni:"curvalue",huTzG:t(1668),rpmJV:t(1282),VlNFi:function(a,n){return a<n},fSXnq:function(a,n,s){return a(n,s)},fiCaf:function(a,n){return a+n},SdVDB:function(a,n,s){return a(n,s)},jLlYE:"FILE_NOT"+t(1481),uepuc:function(a,n,s){return a(n,s)},ZGCMv:t(1321)+"rValues",aRqgA:"ALL",xduKJ:function(a,n,s,l){return a(n,s,l)},rfrUK:"CONTINUE",wQGeX:function(a,n){return a||n},JoUiu:function(a,n){return a!==n},aVJwm:t(699),plBRn:"UAjRq",HMgLH:t(502),DxQpE:function(a,n){return a>n},dpoAw:function(a,n){return a(n)},vndxQ:t(549),STsLm:t(1736)+"r",dHwyk:function(a,n){return a|n},AcZIX:function(a,n){return a|n},ZTjyN:function(a,n){return a<<n},WYWqR:function(a,n){return a+n},zQMKE:function(a,n){return a+n},xRpWF:function(a,n){return a+n},SUCbn:function(a,n){return a*n},Srkyf:function(a,n){return a>>>n},yXvMh:function(a,n){return a>>>n},ehNzV:function(a,n,s){return a(n,s)},cjCPi:t(954),gynmU:function(a,n,s,l){return a(n,s,l)},GuNcd:t(552),oMnOD:function(a,n,s,l){return a(n,s,l)},sKMdE:function(a,n,s){return a(n,s)},bLTuq:t(815)+"er_msgid",XYoNJ:t(815)+t(563),kSdye:function(a,n,s,l){return a(n,s,l)},RIuvS:t(935)+"s",tcatw:"x-msg-cu"+t(996)+"e",GNeXL:t(1424)+t(458)+"ue",GTsks:function(a,n){return a>n},bRufi:t(588),QpEXD:t(1591),SmHYN:function(a){return a()},oAnKi:t(750),ItMyX:t(1354),eEXzH:function(a){return a()},FOjDY:function(a,n){return a<n},OQaXA:function(a,n){return a===n},mTjZo:function(a,n){return a===n},hwsVt:function(a,n){return a&&n},WSVmJ:function(a,n){return a(n)},yFMBk:function(a,n){return a===n},CiNOY:function(a,n){return a!==n},DTUQs:function(a){return a()},bLQxq:function(a,n){return a===n},UJWql:function(a,n,s){return a(n,s)},rwyJy:function(a,n,s){return a(n,s)},yIAuM:"bye",bkhdR:function(a,n){return a(n)},eMsFP:function(a,n,s){return a(n,s)},VXTgt:function(a,n,s){return a(n,s)},QYsxz:function(a,n){return a!==n},zZYIb:function(a,n){return a===n},CfTCX:t(859),kHZDT:function(a,n,s){return a(n,s)},PTmry:t(420)+t(1130),LWSIf:"pbbp2",EtUZW:function(a,n){return a/n},iTZWE:function(a,n){return a==n},sSyoy:t(1244)+t(846)+t(1722),CnFGx:function(a,n){return a(n)},KXKct:t(1244)+t(791)+t(472)+t(516)+t(1575)+t(1155)+t(1095)+t(554),TlYTr:function(a,n){return a!==n},paWGF:t(1742),HbWlA:t(524),SMVLv:function(a,n){return a+n},oaTon:function(a,n){return a+n},WckZI:function(a,n){return a<<n},CukHe:function(a,n){return a|n},fJION:function(a,n){return a&n},ddhdZ:function(a,n){return a<n},fAgOk:function(a,n){return a>n},zMcmB:function(a,n,s){return a(n,s)},iRJxL:function(a,n){return a+n},GeRQH:function(a,n){return a!==n},GajIy:t(919),aimBm:t(564),IxJYR:t(843),ckPKj:function(a){return a()},LjRIS:t(1568),gzjtf:t(401),MwEYW:"ws://",HFKwG:function(a,n){return a!==n},gZjnW:t(1479),upznu:"bd_did",WhLAv:"device_id",AIqET:function(a,n){return a||n},yxKWO:t(1244)+t(1001)+"ddID, de"+t(1004)+t(1295),ZDdrj:function(a,n){return a==n},nhTPw:function(a){return a()},irCEw:function(a,n,s){return a(n,s)},Qnxtr:t(392)+"0",dHBsV:t(1291),bsimo:t(368),ZMOwG:function(a,n,s){return a(n,s)},jFIST:t(1620)+"t",UASDp:function(a,n,s){return a(n,s)},sbNSA:t(485),WwjzU:t(293),yACXm:t(1752)+">",cUtyC:function(a,n){return a*n},NbkJG:function(a,n){return a===n},vtHar:function(a,n,s){return a(n,s)},RTlim:function(a,n,s){return a(n,s)},IKCie:t(1088)+t(1325)+"t",EJYLv:t(1096)+t(1513)+t(1620)+t(1085)+"ver",yxilM:t(1277)+"e",XWTgi:function(a,n,s,l){return a(n,s,l)},YvcrV:function(a,n){return a===n},xcTyd:"Tjypr",bEawr:function(a,n){return a||n},jhBRO:function(a,n){return a||n},ngwEL:function(a,n){return a!==n},CZnqm:t(451),iPGbs:function(a,n){return a||n},MGSug:t(1566),knzTJ:function(a,n){return a(n)},IbXwX:t(1601),AYkfQ:t(690),LsABw:t(1087)+"3",Yadkk:function(a,n){return a>n},XlULj:function(a,n){return a+n},MGqgH:"TJCPp",SCVVP:t(1096)+"ay, netw"+t(1065)+"ine",spLBM:function(a,n){return a instanceof n},zWZbg:function(a,n){return a+n},YujOf:t(1111),KRfTs:t(701),fXydS:function(a,n,s){return a(n,s)},HigQG:function(a,n){return a+n},NuDfN:t(941),TdwCQ:function(a,n,s,l){return a(n,s,l)},AwzIt:function(a,n){return a||n},nEsNf:function(a){return a()},MxGAm:t(1360),kGOuq:function(a,n){return a+n},uhifr:function(a,n){return a!==n},zhjTg:t(651),rHqyV:function(a,n){return a<<n},CFFyK:function(a,n){return a!==n},QaNNu:t(559),JpMCU:t(1806),UfRRO:t(1104)+"2|7|0|5",ezxre:function(a,n){return a===n},Akvsp:function(a,n){return a===n},vUEAm:t(929)+"s already closed",Peukv:function(a,n){return a==n},yNThM:t(1244)+t(676)+t(1265)+"ata, dat"+t(1329)+t(803)+t(1622)+t(1647)+t(1323),ALBlr:function(a,n){return a!=n},zqwRK:function(a,n){return a(n)},orVRi:t(1244)+"rovide a"+t(633)+"ervice",QEUsK:function(a,n){return a instanceof n},wUghq:function(a,n){return a(n)},EAqIb:t(468),CMtvW:function(a,n){return a<n},mvzzV:function(a,n){return a||n},BBrud:function(a,n){return a==n},khrmQ:t(1744)+t(1401)+"ing",nFSoy:t(1416),jfrHP:t(286)+"0",PCxCE:t(913),cOVEV:function(a,n){return a(n)},DtBmA:t(294),bjxIe:function(a,n){return a*n},zhMeF:function(a,n){return a!=n},aiIWg:function(a,n){return a===n},pBjUm:t(1659),qDhMp:function(a,n){return a===n},webHf:function(a,n){return a===n},iNkgN:t(1182),Kojtx:function(a,n){return a===n},FAuLe:function(a,n){return a!=n},eMttr:function(a,n){return a!=n},yjlJj:function(a,n){return a!=n},ovVlU:function(a,n){return a!=n},ZliiM:function(a,n){return a===n},XMCDw:t(1436)+t(1369)+t(299),NggVP:function(a,n){return a===n},EGZTY:function(a,n){return a!=n},BwSvm:function(a,n){return a!=n},ekRLk:function(a,n){return a===n},cOKon:function(a,n){return a!=n},sROMg:function(a,n){return a!=n}};Gt.r(Oe),Gt.d(Oe,{FWS:()=>Tg,CustomErrorEvent:()=>al,createCloseEvent:()=>_t,ReconnectEvent:()=>ol,createErrorEvent:()=>ut,decodedFrame:()=>sn,createOpenEvent:()=>hl,CustomCloseEvent:()=>cl,createReconnectEvent:()=>pa,FrontierMessageEvent:()=>ll,encodeFrame:()=>qt,createMessageEvent:()=>fl,OpenEvent:()=>ul,ErrorCode:()=>an,Event:()=>rr,MessageEvent:()=>dl});let r="";function i(a=""){let n=t,s={qsueg:function(l,f){return e.KLiIh(l,f)},lcyLK:function(l,f){return e[Z(673)](l,f)},qgXqt:function(l,f){return l===f}};if(e[n(612)]!==e[n(981)]){let f=""+Date[n(298)](),g=r||(r=e[n(1338)](h,a)),w=Math[n(623)]().toString(16)[n(1573)](-6);return e[n(1799)](e[n(1799)]("02",f),g)+w}else{if(s[n(1482)](void 0,_0x216b7d))this[n(905)+"rs"]={};else if(s.qsueg(void 0,_0x32415b))this[n(905)+"rs"][_0x52e84a]=null;else{let l=this[n(905)+"rs"][_0x1920be];if(l)for(let f=0;s[n(644)](f,l[n(1818)]);)s[n(788)](l[f].fn,_0x8457b0)?l[n(1444)](f,1):++f}return this}}function o(){let a=t;return e[a(691)](1e4,Date[a(298)]())+Math.floor(1e4*Math[a(623)]())}function c(a){let n=t;return(e.fHfbN(Array,8)[n(1170)]("0")+parseInt(a,10)[n(1375)](2))[n(1573)](-8)}function d(a){let n=t;return e[n(1425)](e[n(1338)](Array,4)[n(1170)]("0"),e[n(1721)](parseInt,a,2).toString(16))[n(1573)](-4)}function u(a){let n=t,s=a[n(1414)](/\./)[n(855)](g=>c(g)),l=[];return l[0]=e.fzUCU(d,e[n(1425)](s[0],s[1])),l[1]=d(e[n(1746)](s[2],s[3])),[e.ONHFd,e.ONHFd,e[n(1193)],e[n(1193)],e[n(1193)],e[n(737)],l[0],l[1]][n(1170)]("")}function h(a){let n=t,s=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/[n(484)](a),l=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[n(484)](a);return s?u(a):l?x(a):e[n(599)]}function x(a){let n=t,s={LDJcJ:function(k){return k()},FLYCR:e[n(1779)],KXiNG:e.Icjgw,fnVfM:function(k,L){return k<L},ZdtkU:function(k,L){return e[n(1685)](k,L)},dfSpy:function(k,L){return e.gTagN(k,L)},KvwlS:function(k,L){return e[n(1179)](k,L)},YTIXV:function(k,L){return e[n(486)](k,L)},NIOQY:function(k,L){return e[n(408)](k,L)},PNBJz:function(k,L){return e.xGDVs(k,L)},wMJzq:function(k,L){return e[n(289)](k,L)}},l="",f=[],g=0,w=0,E=!0,p=e.ONHFd;if(e[n(677)](a[n(1635)]("::"),-1)){if(e.OjiOD(e[n(715)],e[n(715)]))return this[n(1713)+n(898)+n(1281)](_0x33d8a1),s[n(1492)](_0x250427);{let k=a[n(1414)]("::");for(let B=0;e[n(673)](B,k[n(1818)]);B++)if(e[n(292)](e.vJIls,n(492))){let $=this[n(1347)][n(1221)+n(307)+"nc"](this[n(730)]),G=_0x563eb1[n(591)](e.VRJto($,"{}"));return _0x1008ed[n(328)](G)}else{let $=k[B];if(e[n(1515)]($[n(1635)](":"),0)){let G=$[n(1414)](":");E&&(g=G[n(1818)]),w+=G[n(1818)];for(let j=0;e[n(1288)](j,G[n(1818)]);j++)if(e[n(1235)](4,G[j][n(1818)]))if(e[n(398)](n(812),n(948)))_0xd5f736(s.FLYCR),this.off(s[n(595)],_0x1d15b7),this[n(1399)](n(1088)+n(1325)+"t",_0x55227c);else{let be=p.substring(0,e[n(386)](4,G[j][n(1818)])),me=be[n(456)](G[j]);f[n(1241)](me)}else f[n(1241)](G[j]);E=!1}else{if(e[n(739)](4,$[n(1818)]))if(e.KLiIh(n(1376),e[n(1086)])){let G=p[n(626)+"g"](0,4-$[n(1818)]),j=G[n(456)]($);f[n(1241)](j)}else{let G=s[n(693)](_0x13932f,8192),j=s.wMJzq(G,1),be=null,me=G;return function(Ie){let ft=n;if(s[ft(542)](Ie,1)||s[ft(540)](Ie,j))return s[ft(720)](_0x37a165,Ie);s[ft(637)](me,Ie)>G&&(be=s[ft(720)](_0x3c4324,G),me=0);let va=_0x4e20e3[ft(994)](be,me,me+=Ie);return s[ft(350)](7,me)&&(me=s[ft(637)](s[ft(1590)](7,me),1)),va}}else f[n(1241)]($);E&&(g+=1),w+=1,E=!1}}let L="";for(let B=0;e[n(980)](B,8-w);B++)L=L[n(456)](p);for(let B=0;e[n(1288)](B,f[n(1818)]);B++)B===g&&(l=l[n(456)](L)),l=l[n(456)](f[B]);return l}}{let k=a[n(1414)](":");for(let L=0;e[n(980)](L,k.length);L++){let B=k[L];if(e[n(1235)](4,k[L][n(1818)])){let $=p[n(626)+"g"](0,e[n(386)](4,k[L][n(1818)])),G=$.concat(B);l=l[n(456)](G)}else l=l.concat(B)}return l}}function m(a,n){let s=t,l=a[s(1249)];e[s(965)](void 0,l)&&(ge(n,10),e[s(1721)](U,n,l));let f=a.value;e[s(786)](void 0,f)&&(e[s(1721)](ge,n,18),e[s(707)](U,n,f))}function _(a){let n=t,s={};e:for(;!e[n(1330)](V,a);){let l=e[n(1242)](pe,a);switch(l>>>3){case 0:break e;case 1:s.key=e[n(707)](D,a,e.zYJiD(pe,a));break;case 2:s[n(850)]=e[n(1721)](D,a,e.WRReZ(pe,a));break;default:e[n(1721)](C,a,e[n(1800)](7,l))}}if(e[n(398)](void 0,s.key))throw new Error(n(354)+n(1151)+" field: "+n(1249));if(s[n(850)]===void 0)throw new Error(e[n(1458)]);return s}function S(a){let n=t,s=e[n(1643)](R);return e[n(707)](y,a,s),e[n(302)](N,s)}function y(a,n){let s=t,l=a[s(1750)];e[s(494)](void 0,l)&&(ge(n,8),e[s(707)](wt,n,l));let f=a.LogID;e[s(1235)](void 0,f)&&(e[s(707)](ge,n,16),e[s(639)](wt,n,f));let g=a[s(797)];g!==void 0&&(e[s(659)](ge,n,24),e[s(429)](wt,n,e.gTagN(P,g)));let w=a.method;w!==void 0&&(e[s(1428)](ge,n,32),e[s(429)](wt,n,e[s(353)](P,w)));let E=a[s(1115)];if(e.zqAYl(void 0,E))for(let be of E){e[s(659)](ge,n,42);let me=e[s(1643)](R);m(be,me),ge(n,me[s(1783)]),e[s(773)](W,n,me),e[s(689)](O,me)}let p=a[s(1813)+s(501)];if(p!==void 0)if(e.Zksqy(s(452),e[s(1707)]))e[s(1721)](ge,n,50),e[s(1721)](U,n,p);else return this[s(1226)]?this._ws[s(1239)+"ns"]:"";let k=a["payloadT"+s(529)];e[s(909)](void 0,k)&&(ge(n,58),U(n,k));let L=a[s(1139)];e[s(786)](void 0,L)&&(e.KGLOm(ge,n,66),ge(n,L[s(1818)]),ae(n,L));let B=a[s(1233)];e.FMfNF(void 0,B)&&(e[s(1759)](ge,n,74),e.VrKHQ(U,n,B));let $=a[s(978)+"ming"];$!==void 0&&(e[s(1721)](ge,n,82),U(n,$));let G=a[s(1302)];e[s(331)](void 0,G)&&(e[s(582)](ge,n,90),e[s(1368)](U,n,G));let j=a[s(625)+"e"];e[s(786)](void 0,j)&&(e[s(1298)](ge,n,96),e.woTeS(wt,n,e.fzUCU(P,j)))}function v(a){let n=t;if(e[n(736)](e.IZCYd,n(1141)))return e[n(379)](I,M(a));e[n(1288)](_0x527d8e,65536)?_0x3e7f2e[_0x33c0f3++]=e[n(1792)](e.aQfBY(_0x969319,12)&15,224):(_0x29b904[_0x10bebf++]=e[n(861)](e[n(1305)](_0x1f52ba>>18,7),240),_0x3406b1[_0x50e233++]=e[n(1792)](e[n(1800)](e[n(669)](_0x5d85e3,12),63),128)),_0x43f957[_0x31940f++]=e.zCiEO(e.wOrmA(_0x20cb6c,6),63)|128}function I(a){let n=t,s={};e:for(;!e[n(1055)](V,a);){let l=e[n(302)](pe,a);switch(e[n(1555)](l,3)){case 0:break e;case 1:s[n(1750)]=kt(a,!0);break;case 2:s[n(1292)]=kt(a,!0);break;case 3:s[n(797)]=e[n(767)](pe,a);break;case 4:s[n(826)]=pe(a);break;case 5:{let f=e[n(302)](A,a);(s.headers||(s[n(1115)]=[]))[n(1241)](e[n(580)](_,a)),a[n(1783)]=f;break}case 6:s[n(1813)+n(501)]=e[n(295)](D,a,pe(a));break;case 7:s[n(748)+"ype"]=e.MNKIe(D,a,e[n(767)](pe,a));break;case 8:s.payload=e.DwJqg(se,a,pe(a));break;case 9:s.LogIDNew=D(a,e.MlIbI(pe,a));break;case 10:s.serverTiming=e[n(1721)](D,a,e[n(302)](pe,a));break;case 11:s[n(1302)]=e.ZtGmW(D,a,e[n(689)](pe,a));break;case 12:s[n(625)+"e"]=e[n(1007)](pe,a);break;default:e[n(1650)](C,a,e[n(863)](7,l))}}if(e[n(1039)](void 0,s[n(1750)]))throw new Error(e[n(675)]);if(s[n(1292)]===void 0)throw new Error(e[n(1222)]);if(e[n(398)](void 0,s.service))throw new Error(e[n(1578)]);if(e[n(1625)](void 0,s.method))throw new Error(e[n(1629)]);return s}function A(a){let n=t,s=e[n(302)](pe,a),l=a[n(1783)];return a[n(1783)]=e[n(982)](a[n(663)],s),l}function C(a,n){let s=t;switch(n){case 0:for(;e[s(1305)](128,e[s(1142)](te,a)););break;case 2:e.MvzbZ(J,a,e[s(1107)](pe,a));break;case 5:e.toqgY(J,a,4);break;case 1:e.iFPXW(J,a,8);break;default:throw new Error(e[s(982)](s(979)+"ented ty"+s(1412),n))}}function P(a){let n=t;return a|=0,{low:a,high:a>>31,unsigned:e[n(594)](a,0)}}let b=[];function R(){let a=t,n=b.pop();return n?(n[a(663)]=n[a(1783)]=0,n):{bytes:new Uint8Array(64),offset:0,limit:0}}function O(a){b[t(1241)](a)}function M(a){return{bytes:a,offset:0,limit:a[t(1818)]}}function N(a){let n=t,s=a.bytes,l=a.limit;return e[n(398)](s[n(1818)],l)?s:s[n(709)](0,l)}function J(a,n){let s=t;if(e.DZlBj(e.VpqFo(a[s(663)],n),a[s(1783)]))throw new Error(e[s(985)]);a[s(663)]+=n}function V(a){let n=t;return e[n(594)](a[n(663)],a.limit)}function re(a,n){let s=t,l=a[s(1484)],f=a[s(663)],g=a.limit,w=e[s(982)](f,n);if(e[s(1515)](w,l.length)){let E=new Uint8Array(2*w);E.set(l),a[s(1484)]=E}return a.offset=w,e[s(940)](w,g)&&(a.limit=w),f}function Y(a,n){let s=t,l=a.offset;if(e[s(940)](e.cCjeT(l,n),a[s(1783)]))throw new Error(e[s(1198)]);return a[s(663)]+=n,l}function se(a,n){let s=t,l=e[s(1759)](Y,a,n);return a[s(1484)].subarray(l,e.XxDVm(l,n))}function ae(a,n){let s=t,l={ZZAVh:function(f,g,w){return e[Z(1759)](f,g,w)},gUWeJ:function(f,g){return e.xrCLT(f,g)}};if(e.Bruoo(s(1134),e[s(784)])){let f=e[s(1050)](re,a,n[s(1818)]);a[s(1484)][s(1172)](n,f)}else _0x558029(_0x131b8d,32),utAswd.ZZAVh(_0x232252,_0x29a2fb,utAswd[s(362)](_0x48ceb7,_0x2a45da))}function D(a,n){let s=t,l={WPsxj:function(k,L){return k(L)}},f=e[s(1788)](Y,a,n),g=String["fromChar"+s(1812)],w=a.bytes,E="\uFFFD",p="";for(let k=0;e.JKvcw(k,n);k++){let L=w[e.GtaKc(k,f)],B,$,G,j;if(e.KaxTp(e.sOJPT(128,L),0))p+=e[s(531)](g,L);else if(e[s(736)](e.sOJPT(224,L),192))e.NGMhG(e[s(982)](k,1),n)?p+=E:(B=w[e[s(1775)](k,f)+1],e.OjiOD(192&B,128)?p+=E:(j=e[s(819)](e[s(629)](e.TvJZV(31,L),6),e[s(1534)](63,B)),e[s(450)](j,128)?p+=E:(p+=g(j),k++)));else if(e.ZUsYz(e[s(363)](240,L),224))e[s(1799)](k,2)>=n?p+=E:(B=w[e[s(1746)](k+f,1)],$=w[e.EcfEX(k,f)+2],e[s(486)](e[s(861)](B,e[s(629)]($,8)),49344)!==32896?p+=E:(j=e[s(1489)](e[s(622)]((15&L)<<12,e[s(629)](e.sOJPT(63,B),6)),e[s(363)](63,$)),e.nbOVI(j,2048)||j>=55296&&e[s(1777)](j,57343)?p+=E:(p+=e[s(729)](g,j),k+=2)));else if(e[s(657)](248,L)==240)if(e[s(655)](e.PkHDA(k,3),n))p+=E;else if(B=w[e[s(949)](e[s(1775)](k,f),1)],$=w[e[s(1382)](k,f)+2],G=w[e[s(1413)](e[s(641)](k,f),3)],e[s(909)](e[s(1423)](e[s(827)](e[s(408)](B,e[s(1128)]($,8)),e[s(685)](G,16)),12632256),8421504))p+=E;else if(j=e.utddW(e.HXNmH(e[s(685)](e[s(863)](7,L),18),e[s(685)](e.dsHLc(63,B),12)),e[s(629)](e.ZfLFN(63,$),6))|e[s(1699)](63,G),e.SvOOD(j,65536)||e[s(883)](j,1114111))p+=E;else{if(s(384)===e.ndMcx)return l.WPsxj(_0x17dac1,_0x1e783e);j-=65536,p+=e[s(1225)](g,(j>>10)+55296,e[s(1799)](1023&j,56320)),k+=3}else p+=E}return p}function U(a,n){let s=t,l={WJQYq:function(p,k,L){return e[Z(1664)](p,k,L)},vPWGL:s(399)},f=n[s(1818)],g=0;for(let p=0;e[s(980)](p,f);p++){let k=n[s(1255)+"At"](p);e.WjWWm(k,55296)&&e.Oytia(k,56319)&&e[s(450)](p+1,f)&&(k=e[s(386)](e[s(1337)](e[s(1128)](k,10),n[s(1255)+"At"](++p)),56613888)),g+=e[s(673)](k,128)?1:e.RTBgT(k,2048)?2:k<65536?3:4}e[s(639)](ge,a,g);let w=e[s(517)](re,a,g),E=a.bytes;for(let p=0;e[s(572)](p,f);p++){let k=n.charCodeAt(p);if(e[s(655)](k,55296)&&k<=56319&&e[s(1712)](e[s(1179)](p,1),f)&&(k=e[s(1036)](k,10)+n[s(1255)+"At"](++p)-56613888),e[s(1288)](k,128))E[w++]=k;else{if(e.jYgNq(k,2048))E[w++]=e[s(622)](e[s(1528)](k>>6,31),192);else if(e[s(1782)](e[s(1763)],s(313)))e[s(673)](k,65536)?E[w++]=e[s(408)](e[s(1511)](e[s(669)](k,12),15),224):(E[w++]=e.UNSWy(k>>18&7,240),E[w++]=e[s(1565)](e[s(1708)](k,12)&63,128)),E[w++]=e.fSotR(e[s(1708)](k,6)&63,128);else{let L=this[s(1464)+s(933)]?.[s(875)+s(1420)+"nt"](),B=this[s(1796)]["reconnectInterce"+s(1815)](_0x4b62bd[s(552)],_0x46bd05[s(1491)]);this["_dispatc"+s(904)+s(1558)](l[s(411)](_0x24f045,l[s(860)],{code:1006,reason:_0xd8b58b[s(1491)]||s(1503)+s(906)+s(403)+s(395)+s(592)+"ame: "+L,willReconnect:B})),B&&this[s(371)]();return}E[w++]=e[s(528)](63,k)|128}}}function W(a,n){let s=t,l=e.kuTJB(re,a,n[s(1783)]),f=a.bytes,g=n[s(1484)];for(let w=0,E=n[s(1783)];e[s(673)](w,E);w++)f[w+l]=g[w]}function te(a){let n=t;return a[n(1484)][e[n(1758)](Y,a,1)]}function nt(a,n){let s=t,l=e.SIfiz(re,a,1);a[s(1484)][l]=n}function pe(a){let n=t,s=0,l=0,f;do f=e[n(1055)](te,a),e[n(1747)](s,32)&&(l|=e[n(1528)](127,f)<<s),s+=7;while(e[n(363)](128,f));return l}function ge(a,n){let s=t;for(n>>>=0;n>=128;)if(e[s(739)](e[s(1224)],e[s(1210)]))nt(a,e.buaWC(127&n,128)),n>>>=7;else{let{url:l}=_0x5beb19||{},f=_0x287c96.isArray(l)?l:e.ZUsYz(e[s(849)],typeof l)?[l]:[];_0x3a916f&&_0x147fe9.assign(this[s(1796)],_0xb41b5),f&&f[s(1818)]?this[s(1464)+s(933)]=new _0x278f53(f,this._options[s(1102)+"es"]):this["_endpoin"+s(933)]?.["resetEnd"+s(646)+"fig"](),this[s(886)+s(1801)]?.[s(1126)+"nter"](this[s(1796)]["pingLoss"+s(680)]),this[s(1580)+s(1108)]=!1,this._ws&&e.Bruoo(this._ws[s(1789)+"te"],this[s(704)])?this[s(1374)+s(383)](1e3,s(1744)+s(1401)+s(881),!0):(this._isInit=!0,this[s(371)]())}e.UpXNq(nt,a,n)}function kt(a,n){let s=t,l=0,f=0,g=0,w;return w=e.MlIbI(te,a),l=e[s(657)](127,w),e.JZScl(128,w)&&(e.wzRjX===s(1530)?(w=e.wwvZA(te,a),l|=e[s(499)](127,w)<<7,e.JZScl(128,w)&&(w=te(a),l|=e.nICkR(e[s(1019)](127,w),14),e.EMHzH(128,w)&&(w=e[s(1674)](te,a),l|=e.mTEal(e.tQxNq(127,w),21),128&w&&(w=e[s(1007)](te,a),f=e[s(1017)](127,w),e[s(363)](128,w)&&(e[s(1165)](e[s(1665)],e[s(1665)])?(w=e[s(689)](te,a),f|=e[s(685)](127&w,7),e[s(731)](128,w)&&(w=e[s(1811)](te,a),f|=e[s(1800)](127,w)<<14,128&w&&(w=e.QyQSf(te,a),f|=e[s(629)](e[s(1534)](127,w),21),e.sWVie(128,w)&&(w=e[s(1307)](te,a),g=e[s(1057)](127,w),128&w&&(w=te(a),g|=e[s(1488)](127,w)<<7))))):this.emit(e.yySxZ,e[s(973)](_0x70c67c,e.yySxZ,{..._0x140f5b}))))))):(e[s(947)](_0x52a366,2048)?_0xc1a259[_0x4a3601++]=e[s(613)](e[s(1797)](e[s(1306)](_0x3c5fbb,6),31),192):(e.jYgNq(_0x47d7da,65536)?_0x23ded4[_0x364306++]=e[s(819)](e[s(1756)](_0x577491,12)&15,224):(_0x13ea58[_0x22382f++]=e.ycCeX(e[s(1105)](_0x759072>>18,7),240),_0x4db8cd[_0x5e7ae1++]=e[s(622)](e[s(1800)](e[s(669)](_0x191cbf,12),63),128)),_0x47c0c9[_0x2ba39e++]=e.HYGFM(_0x5c93e4>>6,63)|128),_0x5c77c2[_0x1555b3++]=e[s(648)](63&_0x275caf,128))),{low:l|e[s(1128)](f,28),high:e[s(435)](e[s(289)](f,4),g<<24),unsigned:n}}function wt(a,n){let s=t,l=e[s(1555)](n[s(1711)],0),f=e[s(289)](e[s(1202)](n[s(1711)]>>>28,n[s(1485)]<<4),0),g=e[s(1728)](n[s(1485)],24),w=e[s(1625)](0,g)?e[s(1123)](0,f)?e[s(279)](l,16384)?l<128?1:2:l<2097152?3:4:e[s(1712)](f,16384)?e[s(309)](f,128)?5:6:e.YlIqB(f,2097152)?7:8:e[s(450)](g,128)?9:10,E=e.MNKIe(re,a,w),p=a[s(1484)];switch(w){case 10:p[e.PkHDA(E,9)]=e[s(1534)](e[s(1728)](g,7),1);case 9:p[e[s(1516)](E,8)]=e[s(331)](9,w)?e[s(557)](128,g):e[s(1122)](127,g);case 8:p[e[s(550)](E,7)]=e[s(331)](8,w)?e[s(1051)](e[s(1728)](f,21),128):e.cgXuV(e[s(868)](f,21),127);case 7:p[e[s(1425)](E,6)]=w!==7?f>>>14|128:e[s(1215)](f,14)&127;case 6:p[E+5]=e.CouHV(6,w)?e.UmyxN(e[s(1555)](f,7),128):e[s(1797)](e[s(1728)](f,7),127);case 5:p[E+4]=e[s(1261)](5,w)?e[s(648)](128,f):e.dycde(127,f);case 4:p[e[s(1425)](E,3)]=e[s(1173)](4,w)?e[s(1792)](e.KNtBd(l,21),128):e[s(776)](l,21)&127;case 3:p[e[s(1179)](E,2)]=e[s(1607)](3,w)?e[s(622)](e[s(776)](l,14),128):e[s(1113)](l>>>14,127);case 2:p[E+1]=w!==2?e.hzqss(e[s(289)](l,7),128):e[s(776)](l,7)&127;case 1:p[E]=e.UGPfP(1,w)?e.papKa(128,l):e[s(1699)](127,l)}}function sn(a){return e[t(809)](v,a)}function qt(a){return e[t(1071)](S,a)}let on=65536,Yr=e.DtBmA,ye=e[t(1430)](on,on),Re=e[t(1163)](ye,ye),nr=Re/2,Me=String[t(1353)+"e"].charCodeAt;class ue{constructor(n,s,l){let f=t;this[f(1063)]=!0,this[f(1711)]=0|n,this[f(1485)]=e.jlVAb(0,s),this[f(1175)]=!!l}static[t(1063)](n){let s=t;return n&&e[s(398)](!0,n[s(1063)])}static[t(963)](n,s,l){return new ue(n,s,l)}static[t(1029)+"s"](n,s,l){return l?ue[t(1029)+"sLE"](n,s):ue.fromBytesBE(n,s)}static[t(1029)+"sLE"](n,s){let l=t;return new ue(e[l(827)](e[l(1406)](n[0]|e[l(1780)](n[1],8),n[2]<<16),n[3]<<24),e[l(1398)](n[4],e[l(741)](n[5],8))|n[6]<<16|e.KwHlk(n[7],24),s)}static["fromByte"+t(628)](n,s){let l=t;return new ue(e[l(672)](e[l(1422)](e.hGKeJ(n[4],24),e[l(1586)](n[5],16)),e.XgBEU(n[6],8))|n[7],e[l(861)](e[l(583)](e[l(1395)](e.fGxZP(n[0],24),e[l(1251)](n[1],16)),n[2]<<8),n[3]),s)}static[t(1318)](n){let s=t,l={Rhany:e.MBSfp,YTeTB:function(f,g){return f+g},XRTBz:function(f,g){return e[Z(1148)](f,g)},lkmnn:function(f,g){return e[Z(1423)](f,g)},yYqZc:function(f,g){return e.uFBLz(f,g)},seeVP:function(f,g){return e.wOrmA(f,g)},rgRYi:function(f,g){return e[Z(585)](f,g)}};if(e[s(742)]!=="kAFdh")return e.ohkOW(n,Yr)?sl:new ue(e.FsYec(e[s(991)](e[s(1451)](e[s(1459)](Me[s(994)](n,0),e[s(629)](Me.call(n,1),8)),e[s(867)](Me[s(994)](n,2),16)),Me.call(n,3)<<24),0),e[s(1002)](e[s(835)](e[s(1477)](Me[s(994)](n,4),e[s(685)](Me[s(994)](n,5),8)),e[s(1280)](Me[s(994)](n,6),16)),Me[s(994)](n,7)<<24)>>>0,!0);{let f=l[s(1234)].split("|"),g=0;for(;;){switch(f[g++]){case"0":_0x1c259d=l[s(406)](65536+l[s(1073)](l[s(968)](1023,_0x1695df),10),1023&_0x93ecb9);continue;case"1":_0x4b983a[_0x38eb6d++]=l[s(968)](63,_0x3e05ec)|128;continue;case"2":_0x394a9e[_0x1c9c94++]=l[s(1514)](l[s(1013)](_0x33bedb,18),240);continue;case"3":_0x2af229[_0x32ef89++]=l[s(968)](_0x2c835>>6,63)|128;continue;case"4":_0x390d44[_0x5952ca++]=l[s(1514)](l[s(968)](l[s(1021)](_0xed19ae,12),63),128);continue;case"5":++_0x59361f;continue}break}}}[t(1702)](){let n=t;if(e[n(1757)](e.CUgCu,n(617)))return String[n(652)+"Code"](e[n(1019)](255,this.low),e.IAbnP(e[n(1067)](this[n(1711)],8),255),this[n(1711)]>>>16&255,e.FsYec(this[n(1711)],24),e[n(316)](255,this[n(1485)]),this[n(1485)]>>>8&255,e.PGKzk(this[n(1485)]>>>16,255),e[n(1362)](this[n(1485)],24));this[n(964)+n(426)]=null}static fromNumber(n,s=!0){let l=t;if(isNaN(n))return s?Up:sl;if(s){if(e.ItMZj!==e[l(869)])e[l(1298)](_0x24ff3c,_0x47963c,74),e[l(478)](_0x5a9e59,_0xa29c09,_0x31bcc8);else if(e[l(1596)](n,Re))return Hp}else{if(e[l(960)](n,-nr))return qp;if(e[l(594)](e[l(1267)](n,1),nr))return Gp}return ue[l(963)](e[l(808)](e[l(1339)](n,ye),0),e.vIHlN(n,ye)|0,s)}[t(1773)](){let n=t;if(e[n(494)](e[n(894)],e[n(894)]))try{return n(1075)!=typeof _0x2bc067&&(e[n(324)](_0x1f1b0f,_0x221a06)||_0x46b48b[n(923)]&&e[n(324)](_0x1a9e54[n(923)],_0x5a7174))||e.Voilw(e[n(849)],typeof _0x635c5b)?"":(_0x1dc4ba[n(591)](_0x368987),e.Eaqyy)}catch{return e.ZUsYz(e[n(849)],typeof _0x8eea21)?e[n(977)]:""}else return this.unsigned?e[n(289)](this.high,0)*ye+e[n(1215)](this[n(1711)],0):e[n(949)](e[n(1163)](this[n(1485)],ye),e.KNtBd(this[n(1711)],0))}[t(899)](){let n=t;return e[n(1156)](0,this.high)&&e[n(1776)](0,this[n(1711)])}add(n){let s=t;if(e[s(1782)](s(277),e[s(274)])){ue[s(1063)](n)||(n=ue[s(1409)+"er"](n));let l=this.high>>>16,f=65535&this[s(1485)],g=e[s(1539)](this[s(1711)],16),w=e[s(1019)](65535,this.low),E=e[s(289)](n.high,16),p=e[s(1049)](65535,n[s(1485)]),k=e[s(1555)](n.low,16),L=65535&n[s(1711)],B=0,$=0,G=0,j=0;return j+=e[s(1425)](w,L),G+=e[s(351)](j,16),j&=65535,G+=g+k,$+=e[s(1539)](G,16),G&=65535,$+=e[s(620)](f,p),B+=e.OOOwN($,16),$&=65535,B+=e.eQnVr(l,E),B&=65535,ue[s(963)](e[s(1540)](e.ZtBXa(G,16),j),B<<16|$,this.unsigned)}else return this[s(1236)][s(1239)+"ns"]}equals(n){let s=t;return ue[s(1063)](n)||(n=ue[s(1409)+"er"](n)),e[s(739)](this.unsigned,n[s(1175)])&&e[s(1355)](e[s(345)](this[s(1485)],31),1)&&e[s(1776)](e[s(1e3)](n.high,31),1)?!1:e.Sgzft(this[s(1485)],n[s(1485)])&&this.low===n[s(1711)]}[t(1394)](){let n=t;if(e[n(736)](e[n(306)],n(1030)))return e[n(481)](-1,this[n(1711)])&&this[n(1485)]===-1?ue[n(963)](0,0,this[n(1175)]):e.CeIdL(-1,this[n(1711)])?ue[n(963)](0,this[n(1485)]+1,this[n(1175)]):ue[n(963)](e.XxDVm(this[n(1711)],1),this[n(1485)],this[n(1175)]);if(e.aHbvs(_0x21eb26,-_0x24cab8))return _0x495e6a;if(e[n(1610)](e[n(1710)](_0x309bac,1),_0x5e3f87))return _0x2620d4}toBytes(n){let s=t;if(e.Sgzft(e[s(992)],e.JiXqr))_0x5a2c19(this[s(1397)+"lTimeoutId"]),this[s(1397)+"lTimeoutId"]=e[s(659)](_0x1ed3ca,()=>{let l=s;this[l(725)+l(993)]()},this._interval);else return n?this[s(1705)+"E"]():this[s(747)+"E"]()}[t(1705)+"E"](){let n=t,s=this.high,l=this[n(1711)];return[e[n(1034)](255,l),e[n(1145)](e.ucjfp(l,8),255),e[n(1539)](l,16)&255,e[n(1061)](l,24),255&s,e[n(1445)](e[n(289)](s,8),255),s>>>16&255,s>>>24]}toBytesBE(){let n=t,s=this[n(1485)],l=this[n(1711)];return[e.pFWJq(s,24),e[n(363)](e[n(879)](s,16),255),e[n(657)](s>>>8,255),e[n(1454)](255,s),e[n(568)](l,24),e[n(1245)](l>>>16,255),e.JZScl(e[n(1018)](l,8),255),e[n(1666)](255,l)]}}let sl=new ue(0,0,!1),Up=new ue(0,0,!0),Gp=ue.fromBits(-1,2147483647,!1),Hp=ue[t(963)](-1,-1,!0),qp=ue[t(963)](0,-2147483648,!1);var an=(function(a){let n=t,s={UlvDV:e[n(914)],NCxig:function(l,f){return e[n(528)](l,f)},ZCCva:function(l,f){return l|f},nkCqc:function(l,f){return l<f},Nsuvu:function(l,f){return e.OOOwN(l,f)},TZnGn:function(l,f){return e[n(629)](l,f)},TnABD:function(l,f){return e.cvAyz(l,f)},dfJet:function(l,f){return e[n(627)](l,f)}};if(e.vYeJh(e[n(1677)],e[n(844)]))return a[a[e.VLOTe]=5001]=n(1618)+n(1624),a[a[e[n(728)]]=5002]=e[n(728)],a[a.MAX_RETRIES_ERROR=5003]=e.YVqPt,a[a[e.XruVe]=5004]=e[n(1483)],a[a[e[n(1006)]]=5005]=n(1046)+"OR",a;{let l={GyRkR:s.UlvDV,PaIge:function(g,w){return g<w},uwvWw:function(g,w){return s[n(1380)](g,w)},ROrnH:function(g,w){return g<w},vVqaB:function(g,w){return s[n(1206)](g,w)},pZAsq:function(g,w){return s[n(1725)](g,w)},aGEEj:function(g,w){return s[n(952)](g,w)},suPuN:function(g,w){return s[n(1509)](g,w)},hFAAA:function(g,w){return s.TnABD(g,w)},RjZcb:function(g,w){return s[n(779)](g,w)},ZyqsW:function(g,w){return g|w},vMgVV:function(g,w){return s.TZnGn(g,w)},EyMmh:function(g,w){return g&w},xZIJa:function(g,w){return s[n(779)](g,w)},FZTno:function(g,w){return g&w}},f=4294967295;return function(g,w,E=!0){let p=n,k=l.GyRkR[p(1414)]("|"),L=0;for(;;){switch(k[L++]){case"0":if(l[p(1333)](g[w++],128))return{value:E?f:0|f,offset:w};continue;case"1":f=l[p(772)](127,g[w])>>>0;continue;case"2":if(l[p(1550)](g[w++],128))return{value:E?f:l[p(284)](0,f),offset:w};continue;case"3":return{value:E?f:l[p(284)](0,f),offset:w};case"4":if((w+=5)>g[p(1818)])throw w=g.length,_0x3cc3e7(w,10,g[p(1818)]);continue;case"5":if(l.pZAsq(g[w++],128))return{value:E?f:l[p(284)](0,f),offset:w};continue;case"6":if(l[p(1550)](g[w++],128))return{value:E?f:l[p(284)](0,f),offset:w};continue;case"7":f=l[p(445)](f|l[p(1517)](15&g[w],28),0);continue;case"8":if(l[p(708)](g[w++],128))return{value:E?f:l[p(284)](0,f),offset:w};continue;case"9":f=l.RjZcb(l[p(1448)](f,l[p(427)](l.uwvWw(127,g[w]),21)),0);continue;case"10":f=l.ZyqsW(f,l[p(427)](l[p(593)](127,g[w]),7))>>>0;continue;case"11":f=l[p(884)](l[p(1448)](f,l.vMgVV(l.FZTno(127,g[w]),14)),0);continue}break}}}})({});class rr{constructor(n){let s=t;this[s(400)]=n,this[s(443)]=null}}class ol extends rr{constructor(n,s){let l=t;super(n),this[l(958)]=s&&s[l(958)]||null}}class al extends rr{constructor(n,s){let l=t,f=(l(798)+l(432))[l(1414)]("|"),g=0;for(;;){switch(f[g++]){case"0":super(n);continue;case"1":this.error=s&&s[l(1473)]||null;continue;case"2":this[l(552)]=s&&s[l(552)]||5001;continue;case"3":this.filename=s&&s[l(1584)]||"";continue;case"4":this[l(534)]=s&&s[l(534)]||0;continue;case"5":this.colno=s&&s.colno||0;continue;case"6":this[l(958)]=s&&s[l(958)]||"";continue}break}}}class cl extends rr{constructor(n,s){let l=t,f="1|2|3|4|0"[l(1414)]("|"),g=0;for(;;){switch(f[g++]){case"0":this[l(1332)+l(789)]=s&&s[l(1332)+l(789)]||!1;continue;case"1":super(n);continue;case"2":this[l(552)]=s&&s.code||0;continue;case"3":this[l(1491)]=s&&s[l(1491)]||"";continue;case"4":this[l(746)]=s&&s.wasClean||!1;continue}break}}}class dl extends rr{constructor(n,s){let l=t;super(n),this[l(1112)]=s&&s[l(1112)]||null}}class ll extends dl{constructor(n,s){let l=t;super(n),this[l(1112)]=s&&s[l(1112)]||null,this[l(958)]=s&&s[l(958)]||null}}class ul extends rr{constructor(n,s){let l=t;super(n),this[l(1112)]=s&&s.data||null}}function ut(a,{message:n,code:s,error:l}){return new al(a,{message:n,code:s,error:l})}function _t(a,{code:n,reason:s,wasClean:l,willReconnect:f}){let g=t;if(e[g(1529)](e[g(654)],"mteyi"))this[g(766)+"T"]?_0x1cd5dc["onNetwor"+g(498)+g(1545)](({isConnected:w})=>{let E=g;this["_miniNav"+E(1671)+"line"]=w,w?this[E(1180)+E(771)]():this[E(1180)+"ffLine"]()}):this[g(1669)+"X"]&&_0x17c92c[g(679)+"kStatusC"+g(1545)](({isConnected:w})=>{let E=g;this[E(1378)+E(1671)+E(1587)]=w,w?this[E(1180)+E(771)]():this[E(1180)+E(1154)]()});else return new cl(a,{code:n,reason:s,wasClean:l,willReconnect:f})}function fl(a,{data:n,message:s}){return new ll(a,{data:n,message:s})}function hl(a,{data:n}){return new ul(a,{data:n})}function pa(a,{message:n}){return new ol(a,{message:n})}class xl{constructor(n,s){let l=t;this.endpoints=n,this[l(1102)+"es"]=s,this[l(719)+l(889)]=0,this[l(1028)+l(519)+l(1269)+"t"]=0}[t(1717)+"pointCon"+t(1146)](){let n=t;this[n(719)+n(889)]=0,this["currentE"+n(519)+n(1269)+"t"]=0}[t(416)+"es"](){let n=t;this[n(1028)+n(519)+n(1269)+"t"]=0}[t(875)+t(1420)+"nt"](){let n=t;return this[n(462)+"s"][this[n(719)+n(889)]]}[t(875)+"ntEndpoi"+t(381)+t(1232)](){let n=t;return this[n(1028)+n(519)+"riesCount"]}[t(1301)+"chMaxTries"](){let n=t;return!!(e[n(377)](this[n(719)+n(889)],this.endpoints[n(1818)])||e.SnpYt(this["currentI"+n(889)],e.UdXgH(this.endpoints.length,1))&&e[n(1218)](this[n(1028)+n(519)+n(1269)+"t"],this.maxRetries))}[t(1410)+t(917)+t(1041)+t(1508)+"tries"](){let n=t;return e.cHTQj(e[n(1293)],e.rOuhT)?this[n(1226)]?this[n(1226)][n(1166)+"pe"]:this[n(640)+n(529)]:e[n(831)](this[n(719)+"ndex"],this[n(462)+"s"][n(1818)])?!0:this[n(1028)+"ndpointTriesCount"]>this[n(1102)+"es"]}["replaceBackupEnd"+t(1101)+t(410)+t(347)](){let n=t;return this[n(1028)+n(519)+n(1269)+"t"]=1,this[n(719)+n(889)]++,this.endpoints[this[n(719)+n(889)]]}[t(875)+t(1420)+t(674)+t(523)](){let n=t;return this["currentE"+n(519)+n(1269)+"t"]++,this[n(875)+"ntEndpoint"]()}}let ir=(e[t(763)](e[t(1287)],typeof globalThis)&&e.aiIWg(e[t(1133)],globalThis["construc"+t(608)].name)||t(1456)+"d"!=typeof window&&e[t(908)](e[t(1133)],window[t(687)+"tor"][t(1502)]))&&e.cCDPx!=typeof document,Pn=e[t(1287)]!=typeof globalThis&&(e[t(1817)](e[t(1588)],globalThis[t(687)+t(608)][t(1502)])||e[t(1069)]("DedicatedWorkerGlobalScope",globalThis[t(687)+t(608)][t(1502)]))&&e[t(1171)](e[t(1287)],typeof tt),Qr=(e[t(936)](t(1456)+"d",typeof globalThis)&&e[t(1588)]===globalThis[t(687)+t(608)][t(1502)]||e[t(1526)](e[t(1287)],typeof globalThis)||e.cCDPx!=typeof globalThis&&!!globalThis[t(1803)+"Bridge"])&&e.yjlJj(e[t(1287)],typeof wx),ei=e[t(423)](e.cCDPx,typeof globalThis)&&(e[t(1176)]("DedicatedWorkerG"+t(397)+"pe",globalThis["construc"+t(608)].name)||e[t(1363)]===globalThis[t(687)+t(608)][t(1502)]||e[t(1729)]("ServiceWorkerGlo"+t(1544),globalThis[t(687)+t(608)][t(1502)]))&&e.EGZTY(e[t(1287)],typeof self),jp=e[t(912)](e[t(1287)],typeof globalThis)&&e.ekRLk(e[t(1588)],globalThis[t(687)+"tor"][t(1502)])&&e[t(854)](e[t(1287)],typeof global)&&e[t(1355)](t(1182),global[t(687)+t(608)][t(1502)])&&e[t(469)](e[t(1287)],typeof process)&&!!process.version;class ga{constructor(){let n=t;this[n(905)+"rs"]={}}[t(1433)](n,...s){let l=t,f=this._listeners[n];if(f)f[l(1573)]().forEach(g=>g.fn.apply(g.ctx,s));else if(e[l(1776)](e[l(364)],n)&&!this.onerror){let g=s.length&&s[0];if(e[l(324)](g,Error))throw g;let w=new Error(e[l(1457)]+(g?e.lnUGS(" ("+g[l(958)],")"):""));throw w[l(1734)]=g,g}return this}[t(1399)](n,s){let l=t;if(e[l(1625)](void 0,n))this._listeners={};else if(e[l(638)](void 0,s))this._listeners[n]=null;else{let f=this[l(905)+"rs"][n];if(f)for(let g=0;e[l(450)](g,f[l(1818)]);)e[l(920)](f[g].fn,s)?f[l(1444)](g,1):++g}return this}on(n,s,l){let f=t;if(e[f(565)](e[f(1212)],e.jfMaF))return(this._listeners[n]||(this[f(905)+"rs"][n]=[]))[f(1241)]({fn:s,ctx:l||this}),this;this[f(1347)]?.[f(399)](),this[f(1347)]=void 0}}class Wp extends ga{["_formatE"+t(892)+"age"](n){let s=t;return n[s(1432)]||n[s(526)]?(s(1262)+" "+(n.errMsg||"")+s(1311)+(n[s(526)]||""))[s(1334)]():JSON.stringify(n)}constructor(n,s,l){let f=t;super(),this._socket=null,Qr&&wx["connectS"+f(1031)]&&(this[f(1236)]=wx[f(1054)+"ocket"]({url:n,protocols:s,header:l,fail:this[f(1450)+"ocketFai"+f(1220)][f(951)](this),success:this[f(1450)+f(1162)+f(476)+f(285)][f(951)](this)})),Pn&&tt.connectSocket&&(this[f(1236)]=tt[f(1054)+"ocket"]({url:n,protocols:s,header:l,fail:this[f(1450)+f(988)+"lHandler"][f(951)](this),success:this[f(1450)+f(1162)+f(476)+f(285)][f(951)](this)}))}[t(1450)+"ocketSuc"+t(476)+t(285)](){let n=t;Promise[n(718)]()[n(1486)](()=>{this["_addWsLi"+n(1434)]()})}[t(1450)+t(988)+t(1220)](n){let s=t,l={CcoEt:function(f,g,w){return f(g,w)},kikui:e[s(364)],MbbON:e.yySxZ};e.uSLQv(s(604),e.mVVyF)?this[s(1399)](_0x4c3d01,_0x2b3a7b):Promise[s(718)]().then(()=>{let f=s,g=l.CcoEt(ut,l[f(317)],{message:this[f(1637)+"rrorMess"+f(1312)](n)});this[f(1433)](l[f(317)],g);let w=l.CcoEt(_t,l[f(1487)],{reason:this[f(1637)+f(892)+"age"](n)});this.emit(l.MbbON,w)})}["_addWsLi"+t(1434)](){let n=t,s={CyfHm:function(l,f){return l!==f},LKZqe:function(l,f){return l!==f},BnvcJ:e[n(312)],GqFid:e[n(1009)],yuhXR:e[n(1431)],sQmWQ:function(l,f,g){return l(f,g)},LhSjn:e[n(1505)],ZUPgO:n(1473)};this[n(1236)][n(1209)](l=>{let f=n;this[f(1433)](e[f(1475)],e[f(937)](hl,f(1556),{...l,data:l[f(1432)]||""}))}),this[n(1236)].onClose(l=>{let f=n;s.LKZqe(s[f(1641)],s[f(1641)])?_0x9beb95.persisted&&(this[f(1025)+f(1469)]()&&(!this[f(1226)]||s[f(670)](this[f(1226)].readyState,this[f(814)])||s[f(1632)](this._ws[f(1789)+"te"],this[f(1688)+"NG"]))&&this[f(1180)+f(771)](),this[f(1571)+"er"]&&_0x350357.addEventListener(s[f(419)],this[f(1180)+f(771)]),this._isBrowser&&_0xb6333d[f(480)+f(1147)](s[f(1161)],this[f(1180)+f(1154)])):this.emit(f(399),s.sQmWQ(_t,s.LhSjn,{...l}))}),this._socket[n(1603)+"e"](l=>{let f=n;this.emit("message",e[f(639)](fl,e[f(1814)],{...l}))}),this[n(1236)][n(1153)](l=>{let f=n;this.emit(s[f(804)],s[f(983)](ut,s[f(804)],{...l,message:l.errMsg||""}))})}[t(925)](n){let s=t,l={JvHSh:function(f,g){return e[Z(863)](f,g)},DbiPz:function(f,g){return f|g},zDemW:function(f,g){return e.vYeJh(f,g)},sZjbI:e[s(1679)],RCikI:e[s(364)]};if(e[s(324)](n,Uint8Array)){let f=n.buffer[s(1573)](n[s(1640)+"et"],n[s(1553)+"th"]+n.byteOffset);this[s(1236)]&&this._socket.send({data:f,fail:g=>{let w=s;this[w(1433)](e[w(364)],e[w(937)](ut,e[w(364)],{message:this[w(1637)+"rrorMessage"](g)}))}})}else this[s(1236)]&&this[s(1236)].send({data:n,fail:f=>{let g=s,w={kgmgM:function(E,p){return E<p},UfMam:function(E,p){return E+p},TdcAK:function(E,p){return l[Z(853)](E,p)},togVD:function(E,p){return E+p},kFJhK:function(E,p){return l[Z(333)](E,p)}};if(l[g(1439)]("Iepkt",l[g(1741)]))this[g(1433)](l[g(1781)],ut(l.RCikI,{message:this["_formatE"+g(892)+g(1312)](f)}));else{if(w[g(1008)](_0x568c7c,1)||_0x10f500>_0x5d2885)return _0x42291f(_0x302959);w.UfMam(_0x6242bd,_0x1b1cc6)>_0x33a318&&(_0x691b17=_0xdc7147(_0x1cec56),_0x7d4dd7=0);let E=_0x59da92.call(_0xd13782,_0x5efbf6,_0x43fcf7+=_0x16d94c);return w[g(810)](7,_0x3843a0)&&(_0x393616=w.togVD(w[g(1646)](7,_0x281d81),1)),E}}})}[t(399)](n,s){let l=t;this._socket&&this._socket[l(399)]({code:n,reason:s})}[t(480)+"Listener"](n,s){this.on(n,s)}[t(475)+t(1327)+t(895)](n,s){this.off(n,s)}get[t(1789)+"te"](){let n=t;return this[n(1236)][n(1789)+"te"]}get binaryType(){let n=t;if(e.FveIV("cNlTd",n(862)))this[n(1226)]&&this[n(1226)][n(399)](_0x546573,_0x53594b);else return this[n(1236)][n(1166)+"pe"]}set[t(1166)+"pe"](n){}get[t(373)](){let n=t;return this[n(1236)][n(373)]}get protocol(){let n=t;return this._socket[n(1768)]}get extensions(){let n=t;return this[n(1236)][n(1239)+"ns"]}get["buffered"+t(1810)](){return 0}}function Kp(a,n){let s=t;if(e.mpsaj!==e.mpsaj)for(var l in _0x33c64b)_0x3bc88c(_0x5d1c23,l,{get:_0x393df2[l],enumerable:!0});else{if(n)return new n(a[s(373)],a[s(1768)]);if(e.VRJto(Qr,Pn))return new Wp(a[s(373)],a[s(1768)],a[s(1115)]);if(e[s(605)](ir,ei)&&e[s(1287)]!=typeof WebSocket&&WebSocket)return new WebSocket(a[s(373)],a[s(1768)+"s"])}}function $p(a){let n=t,s={RMRlX:e[n(692)],DwTeC:"FILE_NOT_EXIST"};if(e[n(1776)](e[n(1366)],e[n(1366)])){let l=e[n(634)].split("|"),f=0;for(;;){switch(l[f++]){case"0":return!1;case"1":if(Pn&&tt[n(1054)+n(1031)])return!0;continue;case"2":if(e[n(605)](ir,ei)&&e.lpDwO(e[n(1287)],typeof WebSocket)&&WebSocket)return!0;continue;case"3":if(Qr&&wx[n(1054)+n(1031)])return!0;continue;case"4":if(a)return!0;continue}break}}else return{frameType:_0x7aff3f,headers:[{key:s[n(558)],value:s.DwTeC}],payload:void 0}}function pl(a,n,s){let l=t,f={TtArc:function(E,p){return E<=p},iITRN:"next() c"+l(527)+"ltiple t"+l(1377)+l(1083),WgjEG:function(E,p){return e[l(533)](E,p)}},g=-1;async function w(E){let p=l;return f[p(1385)](E,g)?Promise[p(1739)](new Error(f[p(1285)])):(g=E,E===s[p(1818)]?Promise[p(718)]():s[E].bind(a)(n,w[p(951)](null,f[p(1320)](E,1))))}e.MlIbI(w,0)}function gl(a){let n=t,s={gbtZM:function(l,f,g){return e.kYwtm(l,f,g)},XiFLS:e.yySxZ};if(e[n(1044)]!==e[n(1662)]){let l=0,f=0;for(let g=0;e.UGHmI(g,a[n(1818)]);++g)if(f=a.charCodeAt(g),e[n(695)](f,128))l+=1;else if(f<2048)l+=2;else if(e[n(1049)](64512,f)===55296&&e[n(1079)](64512,a[n(1255)+"At"](g+1))===56320)if(e[n(777)](e[n(1691)],e.JzyBV))++g,l+=4;else{this[n(1713)+n(904)+n(1558)](s[n(396)](_0x49be45,s[n(834)],{code:1e3,reason:n(1345)})),this[n(1464)+n(933)]?.[n(1717)+n(646)+n(1146)](),this[n(886)+n(1801)]?.[n(1126)+"nter"]();return}else l+=3;return l}else return e[n(1156)](0,this[n(1485)])&&e[n(1510)](0,this[n(1711)])}function ml(a,n,s){let l=t;if(e[l(695)](s-n,1))return"";let f="";for(let g=n;g<s;)if(e.vYeJh(e[l(703)],l(1081))){let w=a[g++];if(e[l(960)](w,127))f+=String[l(652)+l(1812)](w);else if(e[l(1639)](w,192)&&e[l(450)](w,224))f+=String[l(652)+l(1812)](e.hunoO(31,w)<<6|e[l(1704)](63,a[g++]));else if(e[l(1440)](w,224)&&e[l(871)](w,240))f+=String[l(652)+l(1812)](e[l(1805)](e[l(367)]((15&w)<<12,e.tNsGb(e.dsHLc(63,a[g++]),6)),e[l(434)](63,a[g++])));else if(e.EOMAY(w,240)){let E=e[l(1316)](e[l(1202)](e.buaWC(e.lIEhF(e[l(438)](e[l(521)](7,w),18),e.ZtBXa(e.Yuhfx(63,a[g++]),12)),e.ZskHr(e[l(1034)](63,a[g++]),6)),63&a[g++]),65536);f+=String[l(652)+"Code"](e[l(1271)](55296,e[l(1756)](E,10))),f+=String["fromChar"+l(1812)](e[l(1413)](56320,e[l(762)](1023,E)))}}else this[l(320)]=_0x2aa457,this[l(740)]=_0x3b3f44,this[l(1347)]=_0x20e51d?_0x605aae:_0x4fd3f1?_0x6eb008:null;return f}function ma(a,n,s){let l=t,f=s,g,w;for(let E=0;e[l(1022)](E,a[l(1818)]);++E)if(g=a[l(1255)+"At"](E),e[l(1494)](g,128))n[s++]=g;else if(g<2048)n[s++]=e.ETvkd(g>>6,192),n[s++]=e[l(1441)](e.zYvtM(63,g),128);else if(e.gwaUQ(e.nwaIq(64512,g),55296)&&e.PVNND(e[l(1663)](64512,w=a[l(1255)+"At"](e.wkMIS(E,1))),56320)){let p=e[l(1417)][l(1414)]("|"),k=0;for(;;){switch(p[k++]){case"0":n[s++]=e[l(1449)](e[l(1467)](g,18),240);continue;case"1":n[s++]=e[l(1449)](e[l(799)](g,12)&63,128);continue;case"2":n[s++]=e[l(781)](g>>6&63,128);continue;case"3":g=e[l(573)](65536+(e.iHxYc(1023,g)<<10),e[l(1460)](1023,w));continue;case"4":++E;continue;case"5":n[s++]=e.UzLmk(63&g,128);continue}break}}else n[s++]=g>>12|224,n[s++]=e[l(956)](e[l(1090)](e[l(1756)](g,6),63),128),n[s++]=e[l(1805)](e.ufjLR(63,g),128);return e[l(386)](s,f)}async function wl(a){let n=t,s={RdHxx:function(l,f){return e[Z(635)](l,f)}};if(e[n(421)](e[n(1769)],e[n(1769)])){if(e[n(849)]==typeof a){let l=new Uint8Array(e[n(1495)](gl,a));return e.UIdhn(ma,a,l,0),l}return e[n(1200)](a,ArrayBuffer)?new Uint8Array(a):new Uint8Array(a.buffer,a[n(1640)+"et"],a[n(1553)+"th"])}else{let l=this[n(1347)][n(1221)+n(307)+"nc"](this._prefix),f=_0x11902f[n(591)](s[n(495)](l,"{}"));return _0x2833d9[n(287)](f)}}function Vp(a){let n=t,s={LjLqc:e[n(326)]};if(e[n(343)](e[n(1673)],e.jXzVz))try{return e[n(1774)](e[n(849)],typeof a)&&(e[n(1597)](a,ArrayBuffer)||a[n(923)]&&e.KuJmH(a[n(923)],ArrayBuffer))||e[n(1774)](e[n(849)],typeof a)?"":(JSON.parse(a),e[n(1303)])}catch{if(e.OKfSb(e[n(281)],e[n(1056)])){let l=this[n(1464)+n(933)]?.["getCurre"+n(1420)+"nt"]();this[n(1462)](n(1201)+l+" timeout"),this[n(1374)+"ect"](1001,s.LjLqc,!0)}else return e.ZUsYz(n(1075),typeof a)?n(987)+n(1767)+n(461):""}else _0x32c514[n(551)](_0x240115)}let Jp=(a,n)=>{let s=t;switch(a){case e[s(833)]:case s(1048):return{[s(340)+a]:1,"x-tt-env":n};default:return{}}};class Zp{constructor(n){let s=t;this.maxLossCount=n,this[s(1110)]=0}[t(782)](){let n=t;this[n(1110)]++}[t(1301)+t(586)+"nt"](){let n=t;return e[n(1309)](this[n(1110)],this["maxLossC"+n(1232)])}resetCounter(n=0){let s=t;this[s(1559)+s(1232)]=n,this[s(1110)]=0}}async function Xp(a){let n=t,s={RCNoA:function(l,f){return e[Z(1413)](l,f)},IIXpw:function(l,f){return e[Z(1494)](l,f)},OYomC:function(l,f,g){return l(f,g)},MMSUM:function(l,f){return e.hGKeJ(l,f)},qGMGi:function(l,f){return l===f},bGYZC:n(1693),wKVUD:function(l,f){return e.Vbklf(l,f)},TwNEF:e[n(757)],toocn:function(l){return l()},nXeKI:function(l,f,g){return e[n(865)](l,f,g)},vDywr:function(l,f){return e[n(1697)](l,f)},duXiq:e[n(721)],lxjLN:e[n(283)],LcoHF:e[n(1753)],FcDFX:e[n(664)],iYTQe:function(l,f){return e[n(856)](l,f)},wyJfC:n(1304),rNPIa:function(l,f){return e[n(508)](l,f)}};return new Promise(l=>{let f=n,g={oHjTC:function(w,E){return s.qGMGi(w,E)},Hauob:f(1613),APyzS:s[f(842)],GKJUk:function(w,E){return s[f(829)](w,E)},pcFQk:s.TwNEF,HviDY:function(w,E,p){return w(E,p)},eaHZE:function(w){return s[f(536)](w)},UHxgG:function(w,E,p){return s.nXeKI(w,E,p)},irevI:function(w,E,p){return s.OYomC(w,E,p)}};if(s.vDywr(s[f(755)],s[f(1656)])){if(!ir)return s[f(829)](l,s.TwNEF);try{let w=document[f(1140)+f(1276)](s.LcoHF);window["frontier"+f(1124)]=E=>{let p=f;if(g[p(1443)](g[p(1119)],g.APyzS)){if(this[p(1796)][p(1723)+p(1264)+p(422)]||this[p(1580)+"osed"])return;this[p(503)+"econnect"]()}else document[p(1274)]["removeCh"+p(753)](w),window[p(887)+p(1124)]=void 0,g[p(653)](l,E&&E.msg||g.pcFQk)},w[f(400)]=s[f(1599)],w[f(989)]=s[f(1371)](a[f(581)](/^ws/,s.wyJfC),f(1211)+f(463)+f(1472)+"P");try{document[f(1274)][f(1160)+f(753)](w)}catch{document[f(1274)][f(726)+f(753)](w)}}catch{if(f(1787)===f(1787))window[f(887)+"JSONP"]=void 0,s[f(589)](l,s[f(1343)]);else{let w=0,E=_0x21f00c,p=s.RCNoA(_0x3c1a1e,4);for(;s.IIXpw(E,p);){let{value:k,offset:L}=s[f(945)](_0xb534d5,_0x2d01b6,E);E=L,w=s[f(926)](w,8)>>>0,w+=k}return{value:w,offset:p}}}}else{pNOeSp.HviDY(_0xb046c9,_0x12ad36,42);let w=pNOeSp[f(661)](_0x197006);pNOeSp[f(437)](_0x4cd60f,_0x5ec1e5,w),pNOeSp.irevI(_0x142226,_0x5138bd,w[f(1783)]),_0x5c18c2(_0x2d636f,w),pNOeSp.GKJUk(_0x37cb20,w)}})}function cn(a,n,s){let l=t;return!!a?.[l(916)](f=>f[l(1249)]===n&&f[l(850)]===s)}function sr(a,n){let s=t;return a?.[s(916)](l=>l[s(1249)]===n)?.[s(850)]}let wa=null;async function Yp(){let a=t;return wa||(wa=Promise.resolve().then(Gt.bind(Gt,e[a(1589)]))),wa}class Qp extends ga{constructor(n,s){let l=t;super(),this[l(537)]=n,this._keyPath=s,this[l(1347)]=void 0,this[l(964)+l(426)]=null}async openDB(){await this[t(1681)]()}async _init(){let n=t,s={Ynhcp:function(l){return e[Z(681)](l)},BRDfN:function(l,f,g,w){return e[Z(418)](l,f,g,w)}};if(!this[n(1347)]){if(this[n(964)+n(426)])return this[n(964)+"mise"];try{let l=this._dbName,f=this[n(1012)];this[n(964)+n(426)]=(async()=>{let g=n,{openDB:w}=await s[g(1060)](Yp);this[g(1347)]=await s[g(1196)](w,g(887)+"_"+l,1,{upgrade(E){let p=g;E[p(647)+p(1045)+"e"](l,{keyPath:f})}})})(),await this[n(964)+n(426)]}catch(l){console.log(l)}finally{this[n(964)+"mise"]=null}}}async[t(928)](n){let s=t;if(e[s(1189)]===e[s(1189)])try{return e[s(1218)](e[s(525)],e.AbIHa)?(await this[s(1681)](),this[s(1347)]?.[s(928)](this[s(537)],n)):!!_0x3ab1cd?.[s(916)](l=>l.key===_0xc44cc&&l[s(850)]===_0x114275)}catch(l){console[s(551)](l)}else return s(887)+"_"+this[s(320)]}async[t(1172)](n,s){let l=t;return await this[l(1681)](),this[l(1347)]?.[l(490)](this[l(537)],n)}async[t(1415)](n){let s=t,l={rmFid:function(f,g,w,E){return e.UIdhn(f,g,w,E)},tuguI:e[s(364)]};if(e[s(1059)]!==e[s(1059)])try{l.rmFid(_0x2b800e,this,_0x5176fb,[_0x1fdf80,_0x358fea,_0x2d797c])}catch(f){let g=_0x236339(l.tuguI,{message:f[s(958)],code:_0x59f170.OPEN_ERROR,error:f});this[s(1713)+s(430)+"ent"](g)}else try{return await this[s(1681)](),this[s(1347)]?.[s(1480)](this[s(537)],n)}catch(f){e[s(1536)]!==e[s(1536)]?(_0x4cd016[s(1438)+s(575)]="",_0x4b7c61.log(_0x2e83db)):console.log(f)}}async[t(1390)](){let n=t;try{return await this[n(1681)](),this[n(1347)]?.[n(1390)](this._dbName)}catch(s){console[n(551)](s)}}async keys(){let n=t;return await this[n(1681)](),this[n(1347)]?.[n(1099)+"ys"](this._dbName)}async[t(1185)](){let n=t;if(e[n(1235)](e.ptuas,e[n(1010)]))return await this[n(1681)](),this[n(1347)]?.getAll(this[n(537)]);this._messageQueue.shift(),this[n(1581)+n(327)].push(_0xbffa67)}async[t(1203)](){let n=t;try{this[n(1347)]?.close(),this[n(1347)]=void 0}catch(s){console[n(551)](s)}}get[t(1651)](){let n=t;try{return!!this[n(1347)]}catch(s){return console.log(s),!1}}}class eg{constructor(n,s){let l=t;this[l(320)]=n,this[l(740)]=s,this._qosDB=localStorage}async[t(473)](){}get[t(730)](){return t(887)+"_"+this._DBName}async[t(928)](n){let s=t,l=this[s(1347)][s(1582)](this[s(730)]);return JSON[s(591)](e[s(1365)](l,"{}"))[n]}async[t(1172)](n,s){let l=t,f=this[l(1347)][l(1582)](this[l(730)]),g=JSON[l(591)](e[l(1531)](f,"{}"));return g[s||n[this[l(740)]]]=n,this._qosDB.setItem(this[l(730)],JSON[l(361)+"y"](g)),s||n[this[l(740)]]}async del(n){let s=t,l=this[s(1347)].getItem(this[s(730)]),f=JSON[s(591)](e.xGDVs(l,"{}"));return f[n]=void 0,this[s(1347)].setItem(this[s(730)],JSON[s(361)+"y"](f))}async clear(){let n=t;return this[n(1347)][n(1390)]()}async[t(287)](){let n=t,s=this._qosDB[n(1582)](this[n(730)]),l=JSON[n(591)](e[n(1270)](s,"{}"));return Object[n(287)](l)}async getAll(){let n=t,s=this._qosDB.getItem(this[n(730)]),l=JSON.parse(s||"{}");return Object[n(328)](l)}[t(1203)](){let n=t;return e[n(520)]==="igFtS"?0:Promise[n(718)]()}get[t(1651)](){return!!this[t(1347)]}}class tg{constructor(n,s){let l=t;this[l(320)]=n,this[l(740)]=s,this[l(1347)]=Pn?tt:Qr?wx:null}async[t(473)](){}get _prefix(){let n=t;if(e[n(1782)](e[n(1372)],e[n(1372)]))_0x5a8b2c[_0x22cff1++]=e[n(367)](e[n(1467)](_0x465ceb,18)&7,240),_0x10a12d[_0x1d48bb++]=e.HDIlm(e[n(1167)](_0x5bbf87,12)&63,128);else return n(887)+"_"+this[n(320)]}async[t(928)](n){let s=t;if(e.OGBQc(e.ZZApc,e[s(744)]))_0x3906b2=e[s(413)](_0x277ff2,_0x482931),_0x5b527c|=e[s(441)](e[s(505)](127,_0x566419),14),e[s(1611)](128,_0x21ef08)&&(_0x41651b=e[s(1107)](_0x30f861,_0x48f6f6),_0xa33329|=e[s(441)](e[s(330)](127,_0xdfb199),21),e.vhyWr(128,_0x3fd6c3)&&(_0x4d71e5=e[s(1107)](_0x3ca696,_0x4b3398),_0x288908=e.oHlTJ(127,_0x46b644),e.SGpHP(128,_0x3c4bc6)&&(_0xab8ab0=e.fPiKg(_0x1a0382,_0x2dab2c),_0x1a92bc|=(127&_0x4ceb47)<<7)));else{let l=this[s(1347)][s(1221)+s(1213)](this[s(730)]);return JSON[s(591)](e[s(635)](l,"{}"))[n]}}async set(n,s){let l=t,f=this[l(1347)][l(1221)+l(1213)](this[l(730)]),g=JSON[l(591)](f||"{}");return g[s||n[this[l(740)]]]=n,this._qosDB[l(818)+l(1213)](this[l(730)],JSON[l(361)+"y"](g)),s||n[this[l(740)]]}async[t(1415)](n){let s=t,l=this._qosDB[s(1221)+s(1213)](this[s(730)]),f=JSON.parse(e.azFsn(l,"{}"));return f[n]=void 0,this._qosDB.setStorageSync(this[s(730)],JSON[s(361)+"y"](f))}async clear(){let n=t;return this[n(1347)][n(1447)+n(790)]()}async keys(){let n=t,s=this[n(1347)]["getStora"+n(307)+"nc"](this._prefix),l=JSON[n(591)](e[n(477)](s,"{}"));return Object[n(287)](l)}async getAll(){let n=t;if(e[n(442)](e.qOQBp,e[n(845)])){if(_0x209f1b>=_0xa0dea6)return _0xf30161}else{let s=this[n(1347)][n(1221)+"geInfoSync"](this[n(730)]),l=JSON.parse(s||"{}");return Object[n(328)](l)}}[t(1203)](){return Promise.resolve()}get isReady(){return!!this[t(1347)]}}function _l(a,n){let s=t;if(e[s(635)](Pn,Pn))return new tg(a,n);if(e[s(1383)](ir,ei)&&e[s(1287)]!=typeof indexedDB)return new Qp(a,n);if((ir||ei)&&e[s(424)](s(1456)+"d",typeof localStorage))return new eg(a,n);throw new Error("init QoS"+s(1357)+"d")}class ng{constructor(){let n=t;this[n(1397)+n(910)+"Id"]=null,this[n(1397)+"l"]=36e5,this._qosDB=_l(e.xxZrn,e[n(388)])}async[t(1397)+t(1286)](){let n=t;clearInterval(this._intervalTimeoutId),this[n(1397)+"lTimeoutId"]=e[n(360)](setInterval,()=>{this[n(725)+"ired"]()},this[n(1397)+"l"])}async openDB(){let n=t;await this._qosDB.openDB()[n(1486)](()=>{let s=n;this[s(1397)+s(1286)]()})}async[t(725)+t(993)](){let n=t;(await this._qosDB?.[n(1185)]()||[])[n(1187)](({timestamp:f})=>f<Date[n(298)]())[n(1608)](f=>{let g=n;this[g(1347)]?.[g(1415)](f[g(1114)+"id"])})}async[t(1415)](n){return this[t(1347)]?.del(n)}async[t(1172)](n,s){return this[t(1347)]?.set({message_id:n,timestamp:s})}async[t(928)](n){let s=t;return this[s(1347)]?.[s(928)](n)}async[t(1203)](){let n=t;e[n(1007)](clearInterval,this[n(1397)+"lTimeoutId"]),await this[n(1347)]?.[n(1203)]()}get[t(1651)](){return this[t(1347)]?.isReady}}function _a(a){let n=t,s=!!this._options[n(511)+"S"];if(!s)return{enabled:s,isQoSMessage:!1,isQoSAck:!1,isAckCleanupMessage:!1,ackMsgIds:[]};let l=e[n(418)](cn,a[n(958)][n(1115)],"x_fronti"+n(656),"2"),f=l&&cn(a[n(958)][n(1115)],e[n(1373)],"1"),g=l&&e[n(418)](cn,a[n(958)][n(1115)],e[n(1062)],"1"),w=g?e.ueaOP(sr,a[n(958)][n(1115)],n(815)+"er_ack_msgid")?.split(",")[n(1187)](Boolean)||[]:[];return{enabled:s,isQoSMessage:l,isQoSAck:f,isAckCleanupMessage:g,ackMsgIds:w}}async function yl(){let a=t;return this[a(518)+a(1125)]||(this[a(518)+a(1125)]=new ng),this[a(518)+a(1125)][a(1651)]||await this[a(518)+a(1125)].openDB(),this[a(518)+a(1125)]}async function rg(a,n){let s=t,{enableAutoAck:l}=this[s(1796)],f=e[s(1720)](cn,a[s(958)].headers,e.fFglu,"1"),g=e[s(610)](cn,a[s(958)][s(1115)],e[s(357)],"1"),w=_a[s(994)](this,a);if(e.BUigt(l,f)){let{SeqID:E,LogID:p,service:k,LogIDNew:L,method:B}=a.message;this._sendAck({SeqID:E,LogID:p,LogIDNew:L,service:k,method:B,headers:[{key:s(878),value:"1"},{key:e[s(372)],value:e.KYMll(L,"")},{key:e[s(590)],value:"0"}]})}g&&!w[s(447)]&&this["_dispatc"+s(1310)+"ageEvent"](a),e[s(1643)](n)}async function ig(a,n){let s=t;this[s(1462)](e[s(619)],a[s(958)]),e[s(1643)](n)}async function sg(a,n){let s=t,l=e[s(1644)](sn,await e[s(413)](wl,a[s(1112)]));try{if(e[s(324)](l.payload,Uint8Array))if(e.qfNTc(e.DvmLD,e[s(1626)])){let f=this[s(1347)][s(1221)+s(1213)](this[s(730)]),g=_0x2256e9[s(591)](e.cxzEA(f,"{}"));return g[_0xaf89d5||_0x208f7a[this._pathKey]]=_0x5efc27,this[s(1347)]["setStora"+s(1213)](this._prefix,_0x15fe8b.stringify(g)),_0x279260||_0x4dbf02[this[s(740)]]}else{let f=e[s(324)](this[s(1796)][s(1813)+s(501)],Object)?{force:!!this._options[s(1813)+s(501)][s(649)],encoding:this[s(1796)][s(1813)+"ncoding"].encoding?this[s(1796)][s(1813)+s(501)].encoding[s(581)](/\s/g,"")["toLowerC"+s(1520)]():""}:{force:!1,encoding:this._options.payloadEncoding?this[s(1796)]["payloadE"+s(501)][s(581)](/\s/g,"")[s(1011)+"ase"]():""},g=l[s(1813)+"ncoding"]?l[s(1813)+s(501)][s(581)](/\s/g,"")[s(1011)+s(1520)]():"",w=this._options[s(748)+s(529)]instanceof Object?{force:!!this[s(1796)][s(748)+s(529)][s(649)],type:this[s(1796)].payloadType[s(400)]?this[s(1796)][s(748)+"ype"].type[s(581)](/\s/g,"").toLowerCase():""}:{force:!1,type:this[s(1796)][s(748)+s(529)]?this._options[s(748)+s(529)].replace(/\s/g,"")[s(1011)+s(1520)]():""},E=l[s(748)+s(529)]?l[s(748)+"ype"][s(581)](/\s/g,"")[s(1011)+s(1520)]():"",p=w[s(649)]?w[s(400)]:E||w.type,k=f.force?f[s(768)]:g||f[s(768)],L=[s(987)+"in;charset=utf-8",e[s(1303)],s(1100)+s(1266)+s(1727)+"=utf-8",e[s(849)]],B=[s(1277)+"e",e.woBRj];this[s(1796)]["enableTr"+s(813)+s(1350)+"ad"]&&L[s(934)](p)&&(!k||B[s(934)](k))?l[s(1438)+s(575)]=e[s(610)](ml,l[s(1139)],0,l.payload[s(1553)+"th"]):l[s(1438)+"oad"]=""}else l[s(1438)+s(575)]=""}catch(f){l["textPayl"+s(575)]="",console[s(551)](f)}a.message=l,e[s(1386)](n)}function og(a,n,s){let l=t,f={IjUHS:function(g,w){return e[Z(491)](g,w)},kFwss:function(g,w){return e.YBLCB(g,w)}};if(e.Sgzft(l(444),e[l(1617)]))return _0x20a449[l(1074)+"8"]?{value:_0x3ffa00.readUInt8(_0x2e7c75),offset:f[l(574)](_0x40bc0e,1)}:{value:f[l(530)](255,_0x219c58[_0xd5a66c]),offset:_0x98137a+1};{let g=e.kKJOa(s,8192),w=e[l(694)](g,1),E=null,p=g;return function(k){let L=l,B={rZqQX:L(1075),GIbkz:function(G,j){return e[L(888)](G,j)},cqStk:function(G,j,be,me){return e[L(418)](G,j,be,me)}};if(e[L(572)](k,1)||e[L(940)](k,w))return a(k);if(e[L(643)](e[L(1516)](p,k),g))if(e[L(611)]===e[L(918)]){if(INJpLR[L(1655)]==typeof _0x1b6d9f){let G=new _0x16034f(INJpLR.GIbkz(_0x50f77b,_0x265a41));return INJpLR[L(1268)](_0xfaf540,_0xd87637,G,0),G}return _0x56504b instanceof _0x692566?new _0xbe2ec2(_0x4e79ca):new _0x1e4e5b(_0xf55b67.buffer,_0x31e50c[L(1640)+"et"],_0x4bea69.byteLength)}else E=e[L(577)](a,g),p=0;let $=n.call(E,p,p+=k);return e[L(1623)](7,p)&&(p=e[L(1237)](e.fRmzk(7,p),1)),$}}}let ag=4294967295;function cg(a,n,s){let l=t;return e.fMLnf(RangeError,e[l(1271)](e[l(745)](e[l(1425)](e.MXkpQ(e[l(650)]+a,l(780)),e[l(1497)](n,1)),e[l(1652)]),s))}function dg(a,n,s){let l=t;if(s>ag)throw new Error(l(566)+l(514)+"e");let f=3;for(;f>=0;){let g=e[l(553)](255,s);e[l(1135)](ba,g,a,e[l(1799)](n,f)),s>>>=8,f--}return e[l(982)](n,4)}function lg(a,n){let s=t,l=0,f=n,g=n+4;for(;e[s(1352)](f,g);){let{value:w,offset:E}=e[s(1664)](ya,a,f);f=E,l=e[s(1728)](e.iduUF(l,8),0),l+=w}return{value:l,offset:g}}function ug(a,n,s){let l=t;if(e.FvLNp(l(684),e[l(1199)])){let f=e[l(385)][l(1414)]("|"),g=0;for(;;){switch(f[g++]){case"0":if(n[l(1093)])return e.iSxyE(n[l(1093)](a,s),s);continue;case"1":if(!a)return s;continue;case"2":if(a.length<40)return e.qJHXN(e.FuYuo(ma,a,n,s),s);continue;case"3":return ma(a,n,s)+s;case"4":if(n[l(743)+"e"])return n[l(743)+"e"](a,s)+s;continue}break}}else _0x113843[l(475)+"entListe"+l(895)](KTBVfb[l(872)],_0x323ca0),_0x1f57d5["removeEventListe"+l(895)](KTBVfb.REQjw,_0x5790d3),_0x49cfc4[l(475)+l(1327)+l(895)](KTBVfb[l(596)],_0x224d74)}function fg(a,n){let s=t,l={BcdrH:function(f,g){return e[Z(1648)](f,g)},oeQXi:s(1384),QptZV:s(1719)};if(e.dxIMo(s(359),e[s(1490)])){let f=new ue(e[s(1477)](e[s(390)](e[s(1047)](a[e[s(1179)](n,4)],24)|e[s(1042)](a[e[s(349)](n,5)],16),e[s(1280)](a[n+6],8)),a[n+7]),e[s(672)](e.nfOJT(e[s(1047)](a[e[s(338)](n,0)],24),e[s(380)](a[e[s(459)](n,1)],16)),e[s(1560)](a[e.OsffD(n,2)],8))|a[n+3],!0);return n+=8,{value:f,offset:e.XYeyc(n,8)}}else this["_navigat"+s(1469)]()&&(!this._ws||this[s(1226)].readyState!==this[s(814)]||l[s(733)](this._ws[s(1789)+"te"],this[s(1688)+"NG"]))&&this[s(1180)+s(771)](),this[s(1571)+"er"]&&_0x16fd95[s(480)+s(1147)](l[s(1761)],this[s(1180)+s(771)]),this._isBrowser&&_0x51acc1[s(480)+"Listener"](l[s(545)],this[s(1180)+"ffLine"])}function hg(a,n,s){let l=t,f=a[l(1711)],g=a[l(1485)];return n[s]=e[l(1067)](g,24),n[e.LFqYk(s,1)]=e[l(489)](g>>>16,255),n[e[l(896)](s,2)]=e[l(774)](g,8)&255,n[e[l(1425)](s,3)]=e[l(1290)](255,g),n[e[l(402)](s,4)]=e.SGqzn(f,24),n[e[l(1223)](s,5)]=f>>>16&255,n[s+6]=e[l(1445)](e[l(776)](f,8),255),n[s+7]=255&f,s+=8,s}function ya(a,n){let s=t;return a[s(1074)+"8"]?{value:a.readUInt8(n),offset:e[s(550)](n,1)}:{value:e[s(1534)](255,a[n]),offset:e[s(550)](n,1)}}function ba(a,n,s){let l=t;if(e.ntTeO(e.jbsBz,e[l(1015)]))return n[l(339)+"t8"]?n[l(339)+"t8"](a,s):n[s]=e.UMeJc(255,a),e.BXWCo(s,1);{let f=new _0xab3be2(e[l(1007)](_0x1d5f28,_0x5c2b36));return e[l(618)](_0x449f60,_0x1263d3,f,0),f}}let xg=function(a){return new Uint8Array(a)},pg=e[t(658)](e[t(1287)],typeof Buffer)?Buffer[t(319)+t(556)]:og(xg,Uint8Array[t(1353)+"e"][t(709)]),gg=16,Ea=32;function mg(a){let n=t,s=0,l={};for(let f=0;f<a[n(1818)];f++)l[a[f]["cursor_n"+n(873)]]=gl(a[f][n(1500)+n(873)]),s+=e[n(1516)](14,l[a[f][n(1500)+n(873)]]);return[s,l]}function bl(a,n,s){let l=t,[f,g]=mg(a),w=e[l(1674)](pg,f),E=0;return a[l(1608)](p=>{let k=l;console[k(551)](e.NNpgz,p,p[k(797)]),E=ba(0,w,E),console[k(551)](e.nlnJh,E),E=dg(w,E,p.service||0),console[k(551)](e[k(1336)],E),E=e[k(610)](ba,g[p[k(1500)+"ame"]],w,E),console[k(551)]("service-"+k(1502),E),E=e.XnHSk(ug,p[k(1500)+k(873)],w,E),console[k(551)](e[k(548)],E),E=e[k(1135)](hg,ue[k(1409)+"er"](p[k(471)]||n),w,E),console.log(e.hHTni,E)}),{frameType:Ea,headers:[{key:e[l(692)],value:s}],payload:w}}function wg(a){let n=t,s={TnLan:e[n(1505)]};if(e.CeIdL(e[n(1442)],e[n(1740)]))this[n(1433)](s[n(1499)],_0x52bf25),this.onclose&&this[n(1701)](_0x2b0364);else{let l=0,f=[];for(;e.VlNFi(l,a[n(1553)+"th"]);){let{offset:g}=e.fSXnq(ya,a,l);l=g;let w={cursor_name:"",cursor:0,service:0},{value:E,offset:p}=e[n(937)](lg,a,l);w[n(797)]=E,l=p;let{value:k,offset:L}=e[n(1020)](ya,a,l);l=L,w[n(1500)+n(873)]=e.XnHSk(ml,a,l,e[n(1349)](l,k)),l+=k;let{value:B,offset:$}=e[n(717)](fg,a,l);w.cursor=B[n(1773)](),l=$,f[n(1241)](w)}return f}}function _g(){let a=t;return{frameType:Ea,headers:[{key:e.QzOBt,value:e[a(1621)]}],payload:void 0}}class yg{constructor(n,s,l){let f=t;this[f(1642)+"ameSpace"]=n,this["_cursorF"+f(288)]=s,this["_message"+f(1549)]=l,this[f(1347)]=e[f(961)](_l,this[f(1642)+"ameSpace"],f(1500)+f(873))}async[t(473)](){let n=t;await this[n(1347)][n(473)]()}async[t(1389)+"rs"](){let n=t;if(!this[n(1347)].isReady)return;let s=this[n(1581)+n(1549)],l=await this[n(1347)][n(1185)]();switch(console[n(551)](e[n(1204)],l),s){case e.aRqgA:return l&&l[n(1818)]?e[n(578)](bl,l,0,this[n(407)+n(288)]):void 0;case"INSTANT":return;case e.rfrUK:return l&&l[n(1818)]?e[n(578)](bl,l,0,this[n(407)+n(288)]):e[n(681)](_g)}}async[t(1172)](n,s,l){let f=t;if(e[f(308)](e.aVJwm,e[f(1692)]))return console[f(551)](e[f(512)],n,s,l),this[f(1347)][f(1172)]({cursor_name:n,cursor:s,service:l});{let g=this[f(1347)][f(1221)+"geSync"](this[f(730)]),w=_0x1551b1[f(591)](e[f(446)](g,"{}"));return w[_0x4dd2e0]=void 0,this[f(1347)]["setStora"+f(1213)](this[f(730)],_0x35973d[f(361)+"y"](w))}}async setCursors(n){let s=t,l={aXRLg:function(g,w){return e.DxQpE(g,w)}},f=e[s(1192)](wg,n);for(let g of f)if(e[s(984)]!==s(549)){let w=_0x574a2c[s(663)];if(pfPfeZ[s(946)](w+_0x3d77ef,_0x3142fe[s(1783)]))throw new _0x1a7ae9(s(1790)+s(1116));return _0xb7fb99[s(663)]+=_0x889bd2,w}else console[s(551)](e[s(666)],f),await this[s(1347)][s(1172)](g)}async get(n){let s=t;return(await this._qosDB[s(928)](n))?.[s(471)]}async[t(1203)](){await this._qosDB.closeDB()}["updateCu"+t(805)+t(1319)](n){let s=t;this["_cursorF"+s(288)]=n}get[t(1651)](){let n=t;return this[n(1347)][n(1651)]}}let bg="__x_msg_"+t(1649);async function El(a){let n=t,s={HBCZH:function(E,p){return E|p},XEeFU:function(E,p){return e[Z(1120)](E,p)},UnMnt:function(E,p){return e[Z(816)](E,p)},mhUeH:function(E,p){return e[Z(1402)](E,p)},dPkHr:function(E,p){return E<<p},aPnZN:function(E,p){return e[Z(1611)](E,p)},jiHdg:function(E,p){return e[Z(1685)](E,p)},ofBbF:function(E,p){return e.WYWqR(E,p)},frRNo:function(E,p){return e[Z(821)](E,p)}};if(!this[n(1796)].enableQoS)return null;let{aID:l,fpID:f,messageStrategy:g}=this[n(1796)],w=e[n(538)](a,bg);try{if(n(759)===n(562))_0xef6e53=aVdKQL.HBCZH(aVdKQL[n(449)](aVdKQL.UnMnt(aVdKQL.mhUeH(7&_0x24f857,18),aVdKQL[n(1299)](aVdKQL[n(1273)](63,_0x351d3c),12)),aVdKQL[n(1273)](63,_0x41be51)<<6),63&_0x53a635),_0x3ea539<65536||aVdKQL[n(1574)](_0x37db01,1114111)?_0x560933+=_0x998faa:(_0x4f0757-=65536,_0x1d7fc5+=_0x281477(aVdKQL[n(1240)](_0x2a695c>>10,55296),aVdKQL[n(975)](1023&_0xc24af1,56320)),_0x13d1e7+=3);else return this[n(636)+n(1246)]?a&&this[n(636)+n(1246)][n(1243)+"rsorFile"+n(1319)](a):this[n(636)+"anager"]=new yg(f+"_"+l+"_"+w,w,g),this[n(636)+n(1246)][n(1651)]||await this[n(636)+n(1246)][n(473)](),this[n(636)+n(1246)]}catch{return null}}async function Eg(a,n){let s=t,l={vIgIe:function(G,j){return e.Voilw(G,j)},TFCfu:e[s(1287)],cxJTF:e[s(924)],LcnjJ:s(1809)+"le"},f=e[s(576)](cn,a.message.headers,e[s(1258)],"-1"),g=e[s(425)](cn,a[s(958)][s(1115)],e[s(357)],"1"),w=e[s(723)](sr,a.message[s(1115)],e[s(1136)]),E=e[s(508)](Number,sr(a[s(958)].headers,e[s(344)]))||0,p=_a[s(994)](this,a),k=e.kSdye(cn,a[s(958)][s(1115)],e[s(454)],"2"),L=e[s(1706)](sr,a[s(958)][s(1115)],e[s(415)]),B=Number(e[s(937)](sr,a[s(958)].headers,e[s(1248)]));if(p.isQoSAck)return n();let $=p[s(1205)+s(1197)]?await yl.call(this):null;if(e.GTsks(a[s(958)][s(797)],0)&&g&&!f||a.message[s(797)]>0){if(e[s(770)](e[s(342)],e[s(378)]))return this[s(1175)]?e[s(959)](e[s(1743)](e[s(837)](this[s(1485)],0),_0x45c83d),e[s(1215)](this[s(1711)],0)):this.high*_0x3b27ec+e[s(1411)](this[s(1711)],0);if(w&&p[s(1205)+s(1197)]&&$)return!!!await $[s(928)](w)&&(this[s(1713)+s(898)+s(1281)](a),await $[s(1172)](w,e.WYWqR(Date.now(),E))),e[s(310)](n);if(k)if(e[s(409)]!==e[s(901)]){let G=await El.call(this);if(!G)return this["_dispatc"+s(898)+"Event"](a),e[s(1294)](n);let j=await G[s(928)](L)??-1;if(e[s(1137)](j,B))if(e[s(1519)](s(500),s(500)))this[s(1713)+s(898)+s(1281)](a),G[s(1172)](L,B,a.message[s(797)]);else{let be={lUeUs:function(me,Ie){return xqGrTX.vIgIe(me,Ie)},DLhog:xqGrTX[s(811)],yDlzq:xqGrTX.cxJTF,Ukmtb:xqGrTX[s(303)]};_0x5322ed.r=me=>{let Ie=s;be[Ie(1658)](be[Ie(1033)],typeof _0x59ab2e)&&_0xee9bd4[Ie(1375)+Ie(1275)]&&_0x437a50["definePr"+Ie(852)](me,_0x3d86a6[Ie(1375)+Ie(1275)],{value:be[Ie(1754)]}),_0x372ffb["definePr"+Ie(852)](me,be[Ie(602)],{value:!0})}}else throw new Error(s(796)+s(1132)+s(1636)+B+(s(1429)+"than loc"+s(944)+"r ")+j);return n()}else{let G=_0x1b5a75(e[s(364)],{message:this["_formatE"+s(892)+s(1312)](_0x18987f)});this.emit(e[s(364)],G);let j=e[s(1706)](_0x4989a8,e[s(1505)],{reason:this[s(1637)+s(892)+"age"](_0x5d3910)});this[s(1433)](e.yySxZ,j)}return this[s(1713)+s(898)+s(1281)](a),e[s(1386)](n)}}async function vg(a,n){let s=t,l=_a[s(994)](this,a);if(!l[s(1205)+s(1197)])return n();let f=await yl[s(994)](this);if(l[s(792)+s(1605)+"age"]&&l.ackMsgIds[s(1818)])for(let g of l[s(1014)+"s"])await f[s(1415)](g);n()}async function Sg(a,n){let s=t,l=e.mTjZo(a[s(958)][s(625)+"e"],gg),f=e[s(539)](a.message[s(625)+"e"],Ea);if(e[s(1437)](!l,!f))return n();let g=e[s(773)](sr,a[s(958)][s(1115)],e[s(692)]);if(!g)return e.SmHYN(n);let w=await El[s(994)](this,g);if(!w)return n();if(l){let E=await w.getCursors(),p={frameType:E?.[s(625)+"e"],SeqID:ue[s(1409)+"er"](this[s(1405)]++),LogID:ue.fromNumber(this[s(1796)][s(296)+s(615)]()),service:9e3,method:5,headers:E?.headers,payload:E?.payload},k=e[s(1242)](S,p);this._ws&&this[s(1226)].readyState&&this[s(1226)][s(925)](k)}if(f){let E=a[s(958)][s(1139)];E&&w[s(1158)+"rs"](E)}}let Ig=async function(a,n){let s=t;this[s(1070)]=!1,e[s(1468)](clearTimeout,this[s(371)+s(915)+s(1408)]),e[s(1386)](n)},Ag=async function(a,n){let s=t;if(!this[s(1226)]||e[s(1757)](this[s(1226)].readyState,this.OPEN))return n();let{pingInterval:l}=this._options;this[s(1464)+"tManager"]?.[s(1717)+s(646)+s(1146)]();for(let g=0;g<this[s(1581)+s(327)].length;g++){let w=this[s(1581)+"Queue"][g];if(e.yFMBk(this[s(1226)][s(1789)+"te"],this[s(814)])&&e[s(1760)](null,w))this._ws&&this[s(1226)][s(925)](w),this[s(1581)+s(327)][g]=null;else break}this[s(1581)+s(327)]=this[s(1581)+s(327)][s(1187)](g=>!!g),this._pingPongTimeoutId=e[s(1788)](setTimeout,()=>this[s(290)](),l),this[s(1713)+s(569)+"nt"](a),this._isBrowser&&this[s(1226)]&&(this[s(1226)][s(1166)+"pe"]=this[s(640)+s(529)]);let f=this[s(1464)+s(933)]?.["getCurre"+s(1420)+"nt"]();this[s(1462)](s(1686)+f+" success"),e[s(607)](n)},kg=async function(a,n){let s=t,l=this[s(1464)+s(933)]?.getCurrentEndpoint();this._debug(s(1686)+l),e[s(310)](n)};class Tg extends ga{constructor(n){let s=t,l={QPJGN:function(E,p,k,L){return e[Z(610)](E,p,k,L)},XSKXc:function(E,p,k){return e[Z(429)](E,p,k)},YOpNw:e.REQjw,cXOUL:function(E,p){return e.zZYIb(E,p)},eGkUy:e[s(1496)],MlNMs:s(1745),bpHLV:function(E,p){return e[s(965)](E,p)},MTaHy:function(E,p,k){return e[s(870)](E,p,k)},mMsty:function(E,p,k,L){return e.oMnOD(E,p,k,L)}};super(),this[s(1378)+s(1671)+s(1587)]=!0,this._isBrowser=ir,this[s(1313)]=jp,this[s(766)+"T"]=Pn,this._isMiniWX=Qr,this[s(1604)+"r"]=ei,this["_message"+s(327)]=[],this[s(1464)+s(933)]=null,this[s(1580)+s(1108)]=!1,this[s(640)+s(529)]=e[s(765)],this[s(371)+s(1703)]=!1,this._connectionTimeoutId=null,this[s(1026)+"ctTimeoutId"]=null,this[s(1737)+s(851)+"Id"]=null,this[s(1405)]=0,this[s(1070)]=!1,this[s(1657)]="",this[s(518)+s(1125)]=null,this[s(636)+s(1246)]=null,this[s(886)+"sCounter"]=null,this[s(1667)+"ls"]=e[s(645)],this.CLOSED=3,this[s(1688)+"NG"]=0,this[s(814)]=1,this[s(1676)]=2,this._onOpen=E=>{let p=s;try{l.QPJGN(pl,this,E,[Ig,Ag,kg])}catch(k){let L=l[p(1143)](ut,l[p(665)],{message:k[p(958)],code:an.OPEN_ERROR,error:k});this[p(1713)+p(430)+p(1558)](L)}},this[s(1751)+"ge"]=async E=>{let p=s,k={CNiqe:function($,G){return l[Z(1537)]($,G)}},{pingInterval:L,pingFrequency:B}=this._options;if(E[p(1112)]==="hi"&&l[p(1630)]===B||l[p(1537)](l[p(817)],B))if(l[p(1724)](p(1217),p(1217))){let $=_0x4af046.bytes,G=_0x477ef8[p(1783)];return nTdZVf[p(1289)]($[p(1818)],G)?$:$[p(709)](0,G)}else this[p(967)+p(732)](),this.emit("ping_onc"+p(1027)+"s","success"),this[p(1737)+p(851)+"Id"]=l[p(938)](setTimeout,this[p(290)][p(951)](this),L);if(!l[p(1537)]("hi",E[p(1112)]))try{l.mMsty(pl,this,E,[sg,rg,vg,Sg,Eg,ig])}catch($){let G=l[p(1143)](ut,l[p(665)],{message:$[p(958)],code:an[p(697)+p(389)],error:$});this[p(1713)+p(430)+p(1558)](G)}},this[s(1738)]=E=>{let p=s,k=this["_endpoin"+p(933)]?.[p(1301)+p(1461)+"es"](),L=this[p(1464)+p(933)]?.[p(875)+p(1420)+"nt"]();if(k&&!E[p(958)]){let B="connect "+L+(" fail, m"+p(1680)+p(722)+"ed");this[p(1713)+p(430)+p(1558)](ut(e.REQjw,{message:B,code:an[p(321)+p(848)+"R"],error:E}));return}this[p(1226)]&&e[p(1335)](this._ws[p(1789)+"te"],this[p(814)])&&this[p(1374)+"ect"](),this[p(1713)+p(430)+p(1558)](e[p(877)](ut,e[p(364)],{message:E.message,code:an.NATIVE_ERROR,error:E}))},this[s(365)]=async E=>{let p=s;this[p(1322)+p(1229)](),this._clearPingTimer(),this[p(1567)+p(1037)+"rs"](),this[p(1226)]=null,this["_connect"+p(1703)]=!1;let k=this[p(1464)+p(933)]?.[p(1301)+p(1461)+"es"]();if(!k&&this[p(1025)+p(1469)]()&&!this._readyClosed){let L=this[p(1464)+p(933)]?.[p(875)+p(1420)+"nt"](),B=this._options[p(1620)+"tInterce"+p(1815)](E.code,E[p(1491)]);this["_dispatc"+p(904)+p(1558)](e[p(360)](_t,p(399),{code:1006,reason:E[p(1491)]||p(1503)+p(906)+p(403)+p(395)+p(592)+p(1317)+L,willReconnect:B})),B&&this[p(371)]();return}if(e[p(1261)](1e3,E[p(552)])&&this[p(1580)+p(1108)]){this["_dispatc"+p(904)+p(1558)](e[p(1478)](_t,p(399),{code:1e3,reason:e[p(942)]})),this[p(1464)+"tManager"]?.[p(1717)+"pointCon"+p(1146)](),this[p(886)+p(1801)]?.["resetCou"+p(1466)]();return}if(e[p(1760)](1e3,E[p(552)])&&k){let L=this["_endpoin"+p(933)]?.[p(875)+p(1420)+"nt"](),B=E[p(1491)];B||(B=await e[p(1807)](Xp,this[p(1657)])),B=p(1503)+p(906)+"d, "+B+(p(1391)+p(336))+L+(", max re"+p(1308)+p(972)),this["_dispatc"+p(904)+"ent"](e[p(1572)](_t,e.yySxZ,{code:E[p(552)],reason:B}));let $="connect "+L+(p(1684)+p(1680)+"es reached");this[p(1713)+p(430)+"ent"](e.VXTgt(ut,e.REQjw,{message:$,code:an[p(321)+p(848)+"R"]})),this[p(1464)+p(933)]?.[p(1717)+p(646)+p(1146)](),this["_pingLos"+p(1801)]?.["resetCou"+p(1466)]();return}if(e[p(698)](1e3,E[p(552)])&&!E.reason){let L=this[p(1464)+"tManager"]?.[p(875)+p(1420)+"nt"]();this[p(1713)+p(904)+"ent"](e.sjFAU(_t,e[p(1505)],{code:E[p(552)],reason:p(1503)+p(906)+"d, unkno"+p(395)+"n, hostn"+p(1317)+L})),this["_endpoin"+p(933)]?.[p(1717)+p(646)+p(1146)](),this[p(886)+p(1801)]?.[p(1126)+p(1466)]();return}this[p(1713)+"hCloseEv"+p(1558)](E),this[p(1464)+p(933)]?.[p(1717)+p(646)+"fig"](),this[p(886)+"sCounter"]?.[p(1126)+"nter"]()},this.onclose=null,this[s(522)]=null,this[s(453)+"e"]=null,this[s(806)]=null,this["onStartR"+s(1401)]=null,this[s(775)+s(1214)]=null,this[s(1592)+s(841)+s(369)+"ct"]=null,this[s(1180)+s(771)]=this["_handleO"+s(771)][s(951)](this),this[s(1180)+s(1154)]=this[s(1180)+s(1154)].bind(this),this[s(356)+s(352)]=this["_handleP"+s(352)].bind(this),this[s(356)+s(801)]=this[s(356)+s(801)][s(951)](this),this[s(1796)]={url:"",automaticOpen:!0,initReconnectInterval:1e3,maxReconnectInterval:1e4,reconnectIntervalGrowFactor:2,timeoutInterval:5e3,maxRetries:5,debug:!1,maxMessageQueueLength:e[s(885)](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(1745),pingLossCount:2,enableTransformTextPayload:!1,logIDNewConfig:{enableAutoGenerateLogIDNew:!1,userIp:""},miniProgramParams:{customHttpHeader:{}},enableAutoAck:!1,reconnectInterceptor:()=>!0,enableQoS:!1,QoSLevel:2,messageStrategy:e[s(440)],env:{xTTEnv:"",xUseEnv:""},listenNetworkChanged:!0};let{url:f,ws:g}=n,w=Array[s(322)](f)?f:e[s(1583)](e[s(849)],typeof f)?[f]:[];if(!w||e[s(1776)](0,w[s(1818)]))throw new Error(e[s(839)]);if(!e[s(1403)]($p,g))throw new Error(e.KXKct);Object[s(1164)](this._options,n),this[s(1464)+"tManager"]=new xl(w,this[s(1796)].maxRetries),this[s(886)+s(1801)]=new Zp(this[s(1796)][s(1326)+s(680)]),this[s(1796)][s(1364)+"cOpen"]&&(this._isInit=!0,this._connect()),this._options[s(1548)+s(1016)+s(1131)]&&(this[s(766)+"T"]||this[s(1669)+"X"]?this[s(488)+s(1387)+s(1250)]():this._isBrowser&&this._initGlobalEventListener())}[t(1180)+t(771)](){let n=t;this[n(1796)][n(1723)+n(1264)+n(422)]||this["_readyCl"+n(1108)]||this[n(503)+n(1401)]()}[t(1180)+"ffLine"](){let n=t;if(e.TlYTr(n(1084),n(1084)))_0x24f850[n(1241)](_0x43ee17);else{this[n(671)+"WebSocket"]();let s=e[n(1788)](pa,"reconnect",{message:n(1388)+"ediately"+n(1191)+"ct"});this[n(1592)+n(841)+n(369)+"ct"]&&this[n(1592)+n(841)+n(369)+"ct"](s)}}[t(893)+t(497)+t(1147)](){let n=t;this._isBrowser&&window[n(480)+n(1147)](e.WAZNV,this[n(1180)+"nLine"]),this._isBrowser&&window[n(480)+n(1147)](e[n(1009)],this[n(1180)+n(1154)]),this[n(1571)+"er"]&&window[n(480)+n(1147)](e[n(1612)],this[n(356)+n(352)]),this[n(1571)+"er"]&&window["addEvent"+n(1147)](e.HbWlA,this[n(356)+n(801)])}["_dropGlo"+t(497)+t(1147)](){let n=t;this[n(1571)+"er"]&&window[n(475)+n(1327)+"ner"](e[n(312)],this[n(1180)+"nLine"]),this[n(1571)+"er"]&&window[n(475)+n(1327)+n(895)]("offline",this[n(1180)+n(1154)]),this[n(1571)+"er"]&&window[n(475)+n(1327)+n(895)](n(1742),this[n(356)+"ageHide"]),this[n(1571)+"er"]&&window["removeEv"+n(1327)+"ner"](e[n(314)],this[n(356)+"ageShow"])}[t(356)+t(352)](n){let s=t;!n[s(466)+"d"]&&(this._isBrowser&&window[s(475)+"entListe"+s(895)](s(1742),this["_handleP"+s(352)]),this[s(1571)+"er"]&&window["removeEv"+s(1327)+s(895)](e[s(314)],this[s(356)+"ageShow"]),this[s(399)]()),this[s(1571)+"er"]&&window[s(475)+"entListe"+s(895)]("online",this[s(1180)+"nLine"]),this[s(1571)+"er"]&&window[s(475)+"entListener"](e.voaPl,this[s(1180)+s(1154)])}[t(356)+t(801)](n){let s=t;e[s(1523)](e[s(300)],s(919))?_0x54bc81.log(_0x37e6b8):n.persisted&&(e.KaxTp(e[s(614)],e[s(1351)])?(_0x498e66=_0x2c2c3c[e.SMVLv(e[s(414)](_0x2c993e,_0x566f85),1)],_0x1b3323=_0x88cd1f[_0x5ac288+_0x46e58d+2],_0x42cc6e=_0x1da210[e[s(349)](e[s(1698)](_0x1942bf,_0x362a0b),3)],e.QYsxz(e.lWPYe(e[s(672)](e.NCCmI(_0x3de9d4,_0x398501<<8),e[s(807)](_0x513b3b,16)),12632256),8421504)?_0x2c03e6+=_0x4f8157:(_0x11b596=e[s(864)](e[s(1449)](e[s(807)](e[s(1800)](7,_0x4cac90),18),e[s(404)](e[s(587)](63,_0x1d9a7e),12)),e[s(863)](63,_0x5a0f37)<<6)|e[s(1245)](63,_0x3d19e3),e.ddhdZ(_0x2c6bb2,65536)||e[s(1344)](_0x369d51,1114111)?_0x14d2d8+=_0x21b842:(_0x5666c6-=65536,_0x8550df+=e[s(866)](_0x265b2a,e[s(1341)](e[s(585)](_0x3ff2a9,10),55296),e[s(1726)](e.oHlTJ(1023,_0x25ea88),56320)),_0x1412b1+=3))):(this["_navigat"+s(1469)]()&&(!this._ws||this[s(1226)].readyState!==this.OPEN||e.OGBQc(this[s(1226)][s(1789)+"te"],this[s(1688)+"NG"]))&&this[s(1180)+s(771)](),this[s(1571)+"er"]&&window.addEventListener(e.WAZNV,this["_handleO"+s(771)]),this._isBrowser&&window[s(480)+s(1147)](e[s(1009)],this[s(1180)+"ffLine"])))}async["_generat"+t(1654)](n){let s=t,{fpID:l,deviceID:f,bddID:g,ttwID:w,accessKey:E,aID:p,customParams:k={},enableAutoAck:L,enableQoS:B,QoSLevel:$,env:G}=this[s(1796)],j,be,me;if(this[s(1571)+"er"]||this[s(1669)+"X"]||this._isMiniTT)j=location&&e.LjRIS==location[s(1768)]?e[s(1053)]:e[s(275)],be=n[s(581)](/((^ws)|(^http))((?:[s]*:\/\/))/,""),me=/^wss(.*:\/\/)/[s(484)](n)?n:""+j+be;else if(e[s(1194)](e[s(370)],"NKyCW"))j=e[s(1053)],be=n[s(581)](/(^http)((?:[s]*:\/\/))/,""),me=/(^ws)((?:[s]*:\/\/))/[s(484)](be)?be:""+j+be;else{let ti=this["_endpoin"+s(933)]?.[s(875)+s(1420)+"nt"]();this[s(1462)](s(1686)+ti),e[s(1228)](_0x26a526)}let Ie=g?e[s(1470)]:w?s(1379):e.WhLAv,ft=g||w||f;if(e[s(1570)](!ft,!Ie))throw new Error(e[s(1770)]);let va=e[s(1358)](s(567),typeof k)?await e[s(1092)](k):k,Cg=G?e.irCEw(Jp,G[s(764)],G[s(787)]):{},Sa=Object[s(1164)]({device_platform:s(1552),version_code:e.Qnxtr,access_key:E,fpid:l,aid:p,[Ie]:ft,xsack:L?1:0,xaack:L?1:0,xsqos:B?1:0,qos_level:B?$:void 0,qos_sdk_version:2,...Cg},va),Rg=Object.keys(Sa).reduce((ti,Ia)=>Sa[Ia]!==void 0?""+ti+(ti?"&":"?")+Ia+"="+Sa[Ia]:ti,"");return me+s(903)+Rg}async[t(371)](){let n=t,s={tCNoP:function(l,f){return e.nGaZS(l,f)},LDXvx:e[n(599)]};if(e[n(1183)](e.dHBsV,e[n(1634)])){let l=/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/.test(_0x2935f8),f=/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/[n(484)](_0x473a37);return l?_0x567977(_0x3737cc):f?VkDtKC[n(769)](_0x921b8b,_0x33270a):VkDtKC[n(1392)]}else{if(this[n(371)+n(1703)]||this[n(1580)+n(1108)])return;this[n(371)+n(1703)]=!0;try{let l=this[n(1464)+n(933)]?.[n(1410)+n(917)+n(1041)+n(1508)+n(957)](),{timeoutInterval:f}=this[n(1796)];if(l){let w=this[n(1464)+n(933)]?.[n(875)+"ntEndpoint"](),E=this[n(1464)+n(933)]?.[n(1653)+n(1064)+"pointAnd"+n(410)+n(347)](),p=this[n(1464)+"tManager"]?.[n(875)+"ntEndpoi"+n(381)+n(1232)]();if(E){let k=n(1201)+w+(n(417)+n(504)+n(1308)+n(412)+n(1297)+n(1749)+n(897))+E+" to retry",L=e[n(1527)](ut,e[n(364)],{message:k,code:an.MAX_RETRIES_ERROR});this._debug(k),this[n(1713)+"hErrorEv"+n(1558)](L),this[n(1657)]=await this[n(1501)+n(1654)](E),this[n(1462)]("connect "+E+" "+p+n(1314)),this[n(1567)+n(1037)+"rs"]()}else{let k=n(1201)+w+(n(417)+n(504)+"tries re"+n(972));this[n(1462)](k),this[n(1713)+n(430)+n(1558)](ut(e[n(364)],{message:k,code:an[n(321)+"IES_ERROR"]}));return}}else{let w=this["_endpoin"+n(933)]?.[n(875)+n(1420)+n(674)+n(523)](),E=this[n(1464)+n(933)]?.[n(875)+"ntEndpoi"+n(381)+n(1232)]();this[n(1657)]=await this[n(1501)+n(1654)](w||""),this[n(1462)]("connect "+w+" "+E+" times"),this["_removeW"+n(1037)+"rs"]()}if(this._isInit)this[n(1070)]=!1;else{let w=pa(e[n(544)],{message:n(1730)});this[n(1077)+n(1401)]&&this[n(1077)+n(1401)](w)}let g=this[n(1464)+n(933)]?.[n(875)+n(1420)+"ntTriesCount"]()||0;g>1&&await this._wait(e[n(1316)](g,1)),this[n(1462)]("connecti"+n(1435)+this[n(1657)]+(n(1144)+n(1455))+this[n(1667)+"ls"]),this._ws=e[n(517)](Kp,{url:this[n(1657)],protocols:[this._protocols],headers:this[n(1796)][n(749)+"ramParams"]["customHt"+n(1718)]},this[n(1796)].ws),(this[n(1571)+"er"]||this[n(1604)+"r"])&&this._ws&&(this[n(1226)][n(1166)+"pe"]=this[n(640)+n(529)]),this[n(1177)+n(1434)](),this[n(371)+n(915)+n(1408)]=e[n(891)](setTimeout,this[n(1675)+"ut"].bind(this),f)}catch(l){throw this._connectLock=!1,l}}}[t(1322)+"mer"](){let n=t;e[n(1403)](clearTimeout,this[n(371)+n(915)+n(1408)]),this["_connect"+n(915)+n(1408)]=null}["_clearPi"+t(732)](){let n=t;clearTimeout(this[n(1737)+n(851)+"Id"]),clearTimeout(this[n(1026)+"ctTimeou"+n(543)]),this[n(1737)+n(851)+"Id"]=null,this[n(1026)+"ctTimeou"+n(543)]=null}[t(1462)](...n){let s=t,l={vnKou:function(f,g){return e[Z(1090)](f,g)},nlpXK:function(f,g){return f&g},ZjXuJ:function(f,g){return e[Z(1709)](f,g)},ybOVl:function(f,g){return f>>>g}};if(e[s(1039)](e[s(754)],e[s(800)])){let f=this[s(1485)],g=this[s(1711)];return[NsnXnf.vnKou(255,g),NsnXnf[s(1564)](g>>>8,255),NsnXnf[s(713)](g,16)&255,NsnXnf[s(713)](g,24),255&f,NsnXnf[s(1766)](NsnXnf[s(428)](f,8),255),NsnXnf.ZjXuJ(f,16)&255,NsnXnf.ZjXuJ(f,24)]}else this[s(1796)][s(507)]&&console[s(551)][s(832)](console,[e.yACXm,...n])}[t(1521)+t(1628)+"e"](n){let s=t,{initReconnectInterval:l,maxReconnectInterval:f,reconnectIntervalGrowFactor:g}=this[s(1796)],w=e[s(778)](l,Math.pow(g,e[s(1316)](n,1)));return e[s(1685)](w,f)?f:w}[t(290)](){let n=t;if(this[n(1226)]&&e[n(1700)](this._ws.readyState,this[n(1688)+"NG"])){this[n(967)+"ngTimer"](),this["_pingPon"+n(851)+"Id"]=e[n(1561)](setTimeout,this[n(290)][n(951)](this),this[n(1796)].pingInterval);return}if(!this[n(1226)]||this[n(1226)].readyState!==this[n(814)])return void this["_handleR"+n(1401)]();this[n(1226)]&&this._ws.send("hi"),this[n(1026)+n(939)+"tId"]=e[n(1169)](setTimeout,this[n(503)+n(1401)+n(1733)][n(951)](this),this._options[n(700)+n(1340)+n(823)])}[t(503)+t(1401)+t(1733)](){let n=t;this[n(886)+n(1801)]?.[n(782)](),this[n(1433)](e.IKCie,n(1762)),this["_pingLos"+n(1801)]?.[n(1301)+n(586)+"nt"]()?this["_handleR"+n(1401)]():this[n(290)]()}[t(1025)+t(1469)](){let n=t;return this[n(766)+"T"]||this._isMiniWX?this[n(1378)+n(1671)+n(1587)]:(this[n(1571)+"er"]||this[n(1604)+"r"])&&this[n(1796)][n(1548)+n(1016)+"nged"]?navigator[n(1506)]:!0}[t(503)+t(1401)](){let n=t;!this[n(1025)+n(1469)]()||this[n(1580)+n(1108)]||(this[n(1464)+n(933)]?.[n(1717)+"pointCon"+n(1146)](),this[n(886)+n(1801)]?.[n(1126)+"nter"](),this[n(1226)]?this[n(1374)+n(383)](1001,e[n(1396)],!0):this[n(371)]())}[t(488)+t(1387)+t(1250)](){let n=t;this[n(766)+"T"]?tt[n(679)+n(498)+n(1545)](({isConnected:s})=>{let l=n;this["_miniNav"+l(1671)+l(1587)]=s,s?this[l(1180)+l(771)]():this._handleOffLine()}):this[n(1669)+"X"]&&wx["onNetwor"+n(498)+n(1545)](({isConnected:s})=>{let l=n;this[l(1378)+l(1671)+l(1587)]=s,s?this[l(1180)+l(771)]():this[l(1180)+"ffLine"]()})}[t(662)](n){let s=t,l={uBgGH:function(f,g){return f instanceof g},DiclB:function(f,g){return e.FblzK(f,g)},HadMI:e[s(977)],gkXaU:e.Eaqyy,RcnYY:s(1100)+"ion/json"+s(1727)+s(1786),hLHgc:e.yxilM,MjKno:e[s(1772)],SwOkp:function(f,g,w,E){return e[s(391)](f,g,w,E)}};if(e.YvcrV(s(793),e[s(1672)]))return new Promise(f=>{let g=s;e.TNgcB(setTimeout,f,this[g(1521)+g(1628)+"e"](n))});if(iLlvXR[s(1315)](_0x3cad3.payload,_0x1c191d)){let f=iLlvXR[s(335)](this[s(1796)]["payloadE"+s(501)],_0x5e1f10)?{force:!!this[s(1796)][s(1813)+"ncoding"].force,encoding:this[s(1796)][s(1813)+s(501)][s(768)]?this[s(1796)][s(1813)+s(501)][s(768)][s(581)](/\s/g,"")[s(1011)+s(1520)]():""}:{force:!1,encoding:this[s(1796)]["payloadE"+s(501)]?this._options[s(1813)+s(501)][s(581)](/\s/g,"")[s(1011)+s(1520)]():""},g=_0x37305d[s(1813)+s(501)]?_0xdabcf["payloadE"+s(501)][s(581)](/\s/g,"")[s(1011)+s(1520)]():"",w=iLlvXR[s(1315)](this[s(1796)][s(748)+s(529)],_0x64dc04)?{force:!!this._options[s(748)+s(529)][s(649)],type:this._options["payloadT"+s(529)][s(400)]?this[s(1796)]["payloadT"+s(529)][s(400)][s(581)](/\s/g,"")[s(1011)+s(1520)]():""}:{force:!1,type:this[s(1796)]["payloadT"+s(529)]?this._options[s(748)+s(529)].replace(/\s/g,"")[s(1011)+s(1520)]():""},E=_0x3b3aff["payloadT"+s(529)]?_0x1c9589[s(748)+"ype"][s(581)](/\s/g,"")[s(1011)+"ase"]():"",p=w[s(649)]?w.type:E||w[s(400)],k=f[s(649)]?f[s(768)]:g||f[s(768)],L=[iLlvXR[s(1687)],iLlvXR.gkXaU,iLlvXR[s(315)],"string"],B=[iLlvXR[s(606)],iLlvXR.MjKno];this._options.enableTransformTextPayload&&L[s(934)](p)&&(!k||B.includes(k))?_0x30e36b[s(1438)+s(575)]=iLlvXR[s(597)](_0x26a66,_0x1d332c.payload,0,_0x474d7d[s(1139)].byteLength):_0x54d51d[s(1438)+s(575)]=""}else _0x2263c4[s(1438)+s(575)]=""}["_disconn"+t(383)](n=1e3,s="",l=!1){let f=t;if(e[f(1278)](e[f(900)],f(1284))){if(!this[f(1226)])return;this[f(671)+"WebSocket"](n,s,l)}else{if(_0x366d53)return new _0x18b7a0(_0x4f1f3f[f(373)],_0x3666d2[f(1768)]);if(e.bEawr(_0x3f110b,_0x1d5703))return new _0xb592f7(_0x1aff10[f(373)],_0x46d58a.protocol,_0x4b777c.headers);if(e[f(376)](_0x323a05,_0x8bc5f0)&&e.cCDPx!=typeof _0x5c0c3b&&_0x2015b4)return new _0x19e612(_0x1dd24e[f(373)],_0x2b12cd[f(1768)+"s"])}}[t(1675)+"ut"](){let n=t,s=this[n(1464)+n(933)]?.["getCurre"+n(1420)+"nt"]();this._debug(n(1201)+s+n(417)),this["_disconn"+n(383)](1001,e[n(326)],!0)}[t(756)](n){let s=t;if(e[s(1529)]("hGcLD",e[s(1533)])){let l=e[s(1765)](qt,n);if(this._ws&&e[s(343)](this._ws.readyState,this[s(814)]))if(e[s(481)]("kwiFk",s(950))){let f=this[s(1347)][s(1582)](this[s(730)]);return _0x268f50[s(591)](e[s(510)](f,"{}"))[_0x5b74fb]}else this[s(1226)]&&this[s(1226)][s(925)](l),this[s(1462)](e[s(1563)],n)}else this[s(1433)](e.fYFaJ,_0x3ea67a),this[s(453)+"e"]&&this[s(453)+"e"](_0xa6975f)}[t(1567)+t(1037)+"rs"](){let n=t,s={XLfPm:function(l,f){return e.dpoAw(l,f)},GLxyG:function(l){return l()}};if(n(690)===e[n(1594)]){let l=e.LsABw[n(1414)]("|"),f=0;for(;;){switch(l[f++]){case"0":this[n(1226)][n(475)+n(1327)+n(895)](e[n(1505)],this[n(365)]);continue;case"1":this[n(1226)][n(475)+n(1327)+"ner"](e.fYFaJ,this[n(1751)+"ge"]);continue;case"2":if(!this[n(1226)])return;continue;case"3":this[n(1226)]["removeEv"+n(1327)+"ner"](e.REQjw,this[n(1738)]);continue;case"4":this._ws[n(475)+n(1327)+n(895)](e.EaLkz,this._onOpen);continue}break}}else JVDxDZ[n(706)](_0x2f4651,_0x509eed[n(1473)]),JVDxDZ.GLxyG(_0x624afb)}["_addWsLi"+t(1434)](){let n=t;if(e.yFMBk(e[n(970)],n(1525))){if(e[n(493)](e[n(598)](_0x283901.offset,_0x16c509),_0x2d54b9[n(1783)]))throw new _0x294de5(e[n(985)]);_0x1117a7[n(663)]+=_0x8b279b}else{if(!this[n(1226)])return;this[n(1226)][n(480)+n(1147)](e[n(1475)],this[n(1076)]),this[n(1226)][n(480)+n(1147)](e[n(1505)],this[n(365)]),this._ws[n(480)+n(1147)](e[n(1814)],this._onMessage),this[n(1226)]["addEvent"+n(1147)](e[n(364)],this[n(1738)])}}[t(1784)+t(280)](n=1e3,s=""){let l=t;try{this[l(1226)]&&this[l(1226)][l(399)](n,s)}catch{}}_destroyWebSocket(n=1e3,s="",l=!1){let f=t;if(this[f(967)+f(732)](),this[f(1322)+f(1229)](),this["_removeW"+f(1037)+"rs"](),this[f(1784)+f(280)](1e3,s),this[f(371)+f(1703)]=!1,l&&this[f(1025)+f(1469)]()&&!this[f(1580)+f(1108)]){if(this[f(1464)+f(933)]?.[f(1301)+f(1461)+"es"]()){let w=this[f(1464)+f(933)]?.["getCurre"+f(1420)+"nt"]();this[f(1713)+"hCloseEv"+f(1558)](_t(e[f(1505)],{code:1006,reason:f(1201)+w+(f(417)+f(504)+f(1308)+f(972)),wasClean:!0}))}else{let w=this._options["reconnec"+f(1695)+"ptor"](n,s);this["_dispatc"+f(904)+"ent"](_t(e[f(1505)],{code:n,reason:s,wasClean:!0,willReconnect:w})),w&&this[f(371)]()}return}this[f(1025)+f(1469)]()||this["_readyCl"+f(1108)]?this[f(1713)+f(904)+f(1558)](_t(e[f(1505)],{code:n,reason:e.yIAuM})):this["_dispatchCloseEv"+f(1558)](_t(e.yySxZ,{code:1006,reason:e.SCVVP})),this[f(1226)]=null,this["_endpoin"+f(933)]?.[f(1717)+f(646)+f(1146)](),this[f(886)+f(1801)]?.[f(1126)+f(1466)]()}[t(1713)+"hOpenEvent"](n){let s=t;this[s(1433)](e[s(1475)],n),this[s(806)]&&this[s(806)](n)}[t(1713)+t(898)+t(1281)](n){let s=t;this[s(1433)](e[s(1814)],n),this[s(453)+"e"]&&this[s(453)+"e"](n)}[t(1713)+t(1310)+t(496)](n){let s=t;this[s(1433)]("ack",n),this[s(775)+s(1214)]&&this[s(775)+s(1214)](n)}[t(1713)+t(430)+"ent"](n){let s=t;if(e[s(1335)](e[s(1324)],e[s(323)])){let l=this[s(905)+"rs"][_0x2cc6e5];if(l)l[s(1573)]()[s(1608)](f=>f.fn[s(832)](f[s(570)],_0x1d098a));else if(e[s(364)]===_0x561d6a&&!this.onerror){let f=_0x5ee8b8.length&&_0x2e9beb[0];if(e[s(986)](f,_0x346b1f))throw f;let g=new _0x30178f(e[s(667)](e[s(1457)],f?e[s(1710)](" ("+f.message,")"):""));throw g[s(1734)]=f,f}return this}else this.emit(s(1473),n),this[s(522)]&&this.onerror(n)}[t(1713)+"hCloseEv"+t(1558)](n){let s=t;this[s(1433)](e[s(1505)],n),this[s(1701)]&&this[s(1701)](n)}get[t(1166)+"pe"](){let n=t;return this[n(1226)]?this[n(1226)].binaryType:this[n(640)+n(529)]}set binaryType(n){let s=t;if(e.CouHV(e.NuDfN,e[s(1551)])){let l=e[s(1452)](_0x42aa1b,_0x2501a1,_0x7221a9[s(1783)]),f=_0x2572ae[s(1484)],g=_0x56b30c[s(1484)];for(let w=0,E=_0x41e53c.limit;w<E;w++)f[e.HigQG(w,l)]=g[w]}else this._binaryType=n,this[s(1226)]&&(this[s(1226)].binaryType=n)}get[t(1127)+"nt"](){let n=t;return this["_endpoin"+n(933)]?.["getCurre"+n(1420)+n(381)+n(1232)]()||0}get[t(560)+t(1810)](){let n=t,s={IyQTp:function(f,g,w,E){return e[Z(1174)](f,g,w,E)},tyido:e[n(357)],arPer:function(f,g){return e[n(911)](f,g)},fLAWq:n(325),NodAY:function(f,g){return e.AwzIt(f,g)},hucuD:"ack_code",UGgFS:function(f){return e.nEsNf(f)},efjAP:e[n(1615)]},l=this[n(1581)+"Queue"][n(1138)]((f,g)=>{let w=n;if(w(1453)!==s[w(355)])return f+=g&&g[w(1553)+"th"]||0,f;{let{enableAutoAck:E}=this[w(1796)],p=_0xc864c5(_0x43e23f.message.headers,w(1557),"1"),k=jVylDf[w(482)](_0x197a25,_0x479c0b[w(958)][w(1115)],jVylDf[w(1689)],"1"),L=_0xfeba40.call(this,_0x7a230f);if(jVylDf.arPer(E,p)){let{SeqID:B,LogID:$,service:G,LogIDNew:j,method:be}=_0xa6dbe6.message;this[w(756)]({SeqID:B,LogID:$,LogIDNew:j,service:G,method:be,headers:[{key:jVylDf.tyido,value:"1"},{key:jVylDf[w(1348)],value:jVylDf[w(1795)](j,"")},{key:jVylDf[w(1195)],value:"0"}]})}k&&!L[w(447)]&&this[w(1713)+w(1310)+w(496)](_0x30e646),jVylDf[w(535)](_0x430929)}},0);return e.kGOuq(l,this[n(1226)]?this[n(1226)][n(560)+"Amount"]:0)}get[t(1239)+"ns"](){let n=t;return this[n(1226)]?this[n(1226)][n(1239)+"ns"]:""}get[t(1768)](){let n=t,s={JRjzc:n(1742),GbfIO:e.HbWlA,UQrLs:e[n(312)]};if(e[n(1400)](e[n(387)],e[n(387)]))!_0x2d1c59.persisted&&(this[n(1571)+"er"]&&_0x235329[n(475)+n(1327)+"ner"](TJXQdh.JRjzc,this[n(356)+n(352)]),this[n(1571)+"er"]&&_0x5e5f24["removeEventListe"+n(895)](TJXQdh.GbfIO,this[n(356)+n(801)]),this[n(399)]()),this[n(1571)+"er"]&&_0x182ad4[n(475)+n(1327)+"ner"](TJXQdh.UQrLs,this[n(1180)+"nLine"]),this._isBrowser&&_0xd11416[n(475)+n(1327)+n(895)]("offline",this[n(1180)+n(1154)]);else return this[n(1226)]?this[n(1226)].protocol:""}get[t(1789)+"te"](){let n=t;return this[n(1226)]?this[n(1226)][n(1789)+"te"]:this[n(1796)][n(1364)+n(348)]?this[n(1688)+"NG"]:this[n(704)]}get[t(373)](){let n=t,s={oOZsB:function(l,f){return e[Z(291)](l,f)},tNTXG:function(l,f){return l<f},HuBmT:function(l,f){return l(f)}};if(e[n(1427)](e[n(470)],e[n(1554)]))return this[n(1226)]?this._ws[n(373)]:this[n(1657)];_0x1a329f=pyOdin[n(1381)](31&_0x37ac60,6)|63&_0x3fd8e7,pyOdin[n(394)](_0x3ea55a,128)?_0x29be40+=_0x3b295e:(_0x408232+=pyOdin[n(1032)](_0x447fe1,_0x5f145e),_0x58173e++)}[t(399)](n=1e3,s){let l=t,f=e[l(882)][l(1414)]("|"),g=0;for(;;){switch(f[g++]){case"0":if(e[l(1082)](this._ws[l(1789)+"te"],this[l(704)])||e[l(1714)](this[l(1226)][l(1789)+"te"],this[l(1676)]))return void this[l(1462)](e.vUEAm);continue;case"1":this[l(1256)+l(497)+l(1147)]();continue;case"2":this[l(518)+l(1125)]?.[l(1203)]();continue;case"3":this[l(967)+l(732)]();continue;case"4":this["_clearTi"+l(1229)]();continue;case"5":this[l(671)+"WebSocket"](n,s);continue;case"6":this[l(1580)+"osed"]=!0;continue;case"7":if(!this[l(1226)])return void this._debug(l(929)+"s instan"+l(1446)+"nitialized");continue}break}}async[t(925)](n,s){let l=t;if(e[l(1526)](null,n))throw new Error(e[l(621)]);l(1735)==typeof n&&(n=JSON[l(361)+"y"](n)),e[l(1683)](e[l(849)],typeof n)&&!(n instanceof ArrayBuffer)&&!(n[l(923)]&&e.spLBM(n.buffer,ArrayBuffer))&&(n=JSON[l(361)+"y"](n));let f=await e[l(1404)](wl,n),g=e[l(580)](Vp,n),{method:w=0,service:E=this[l(1796)][l(797)],logID:p=this._options[l(296)+l(615)](),headers:k=this[l(1796)][l(1115)],payloadEncoding:L=this._options[l(1813)+"ncoding"],payloadType:B=this._options[l(748)+l(529)],logIDNew:$=this[l(1796)]["logIDNew"+l(1331)][l(1543)+l(876)+"teLogIDNew"]?i(this[l(1796)][l(1259)+l(1331)][l(1252)]):""}=s||{};if(!E)throw new Error(e[l(439)]);let G={SeqID:ue[l(1409)+"er"](this[l(1405)]++),LogID:ue[l(1409)+"er"](p),service:E,method:w,headers:k,payloadEncoding:L instanceof Object?L[l(768)]?L.encoding:"":L,payloadType:e[l(1771)](B,Object)?B.type?B[l(400)]:g:B||g,payload:f,LogIDNew:$},j=e.wUghq(qt,G);return this[l(1226)]&&e[l(1043)](this[l(1226)].readyState,this[l(814)])?(this[l(1226)]&&this[l(1226)][l(925)](j),this[l(1462)](e.EAqIb,G)):e[l(922)](this[l(1581)+l(327)][l(1818)],this[l(1796)][l(686)+l(1342)+"ength"])?(this["_message"+l(327)][l(1241)](j),this[l(1462)](l(375),G)):(this[l(1581)+l(327)].shift(),this["_message"+l(327)].push(j)),{seqID:this[l(1405)],logID:p,logIDNew:$}}async[t(1620)+"t"](n){let s=t,{url:l}=e[s(1078)](n,{}),f=Array[s(322)](l)?l:e[s(822)](e[s(849)],typeof l)?[l]:[];n&&Object[s(1164)](this[s(1796)],n),f&&f.length?this[s(1464)+"tManager"]=new xl(f,this[s(1796)][s(1102)+"es"]):this[s(1464)+s(933)]?.[s(1717)+s(646)+s(1146)](),this[s(886)+"sCounter"]?.[s(1126)+"nter"](this[s(1796)][s(1326)+"Count"]),this[s(1580)+s(1108)]=!1,this[s(1226)]&&e[s(630)](this[s(1226)][s(1789)+"te"],this.CLOSED)?this._disconnect(1e3,e[s(727)],!0):(this._isInit=!0,this[s(371)]())}async[t(678)](){let n=t;if(e[n(318)](e.nFSoy,e[n(1003)]))return _0x5ab49e?.[n(916)](s=>s[n(1249)]===_0x47d9e1)?.[n(850)];if(!this[n(371)+n(1703)]){let s=e[n(1260)][n(1414)]("|"),l=0;for(;;){switch(s[l++]){case"0":this[n(371)]();continue;case"1":this[n(1070)]=!0;continue;case"2":this[n(1580)+"osed"]=!1;continue;case"3":this[n(1464)+n(933)]?.[n(1717)+"pointConfig"]();continue;case"4":this["_pingLos"+n(1801)]?.["resetCou"+n(1466)]();continue}break}}}[t(480)+"Listener"](n,s){this.on(n,s)}[t(1219)+t(1281)](n){let s=t,{type:l}=n;this[s(1433)](l,n)}["removeEv"+t(1327)+t(895)](n,s){this[t(1399)](n,s)}[t(1690)](){let n=t,s={oWpWk:function(l,f){return e[Z(431)](l,f)},XbJOK:e[n(1779)],weKjc:e[n(820)],iuZAs:e[n(1024)]};return new Promise((l,f)=>{let g=n,w={ikaJl:function(k,L){return e[Z(1307)](k,L)},vTWyM:e[g(1159)],DyJTD:g(1088)+g(1027)+"s"};this[g(967)+g(732)](),this[g(1737)+"gTimeoutId"]=e.sKMdE(setTimeout,this[g(290)][g(951)](this),this[g(1796)][g(1426)+g(1121)]);let E=()=>{let k=g;w[k(1546)](l,w[k(1593)]),this[k(1399)](w[k(999)],E),this.off(k(1088)+k(1325)+"t",p)},p=()=>{let k=g;s[k(1097)](f,s.XbJOK),this[k(1399)](s[k(457)],E),this[k(1399)](s[k(483)],p)};this.on(e[g(820)],E),this.on("ping_onc"+g(1325)+"t",p),this[g(290)]()})}}})(),Ue[F(907)+F(301)]=Oe[F(907)+"oseEvent"],Ue.CustomErrorEvent=Oe.CustomErrorEvent,Ue[F(660)+"e"]=Oe.ErrorCode,Ue[F(1281)]=Oe[F(1281)],Ue.FWS=Oe[F(1058)],Ue[F(1732)+F(1117)+F(600)]=Oe[F(1732)+F(1117)+F(600)],Ue[F(1117)+F(600)]=Oe[F(1117)+"vent"],Ue[F(1149)+"t"]=Oe.OpenEvent,Ue["Reconnec"+F(1418)]=Oe[F(1476)+F(1418)],Ue["createCl"+F(301)]=Oe.createCloseEvent,Ue["createEr"+F(579)]=Oe.createErrorEvent,Ue["createMe"+F(1609)+"nt"]=Oe["createMe"+F(1609)+"nt"],Ue[F(751)+F(955)]=Oe["createOp"+F(955)],Ue[F(276)+F(1764)+F(600)]=Oe["createRe"+F(1764)+F(600)],Ue.decodedFrame=Oe[F(393)+F(1541)],Ue[F(332)+F(873)]=Oe[F(332)+F(873)];for(Ko in Oe)[F(907)+F(301),"CustomEr"+F(579),F(660)+"e","Event","FWS",F(1732)+"MessageE"+F(600),F(1117)+F(600),"OpenEvent",F(1476)+"tEvent",F(847)+F(301),"createEr"+F(579),"createMe"+F(1609)+"nt",F(751)+"enEvent",F(276)+F(1764)+"vent",F(393)+F(1541),F(332)+"ame"][F(1635)](Ko)===-1&&(Ue[Ko]=Oe[Ko]);var Ko;function Z(t,e){t=t-273;let r=Yo(),i=r[t];if(Z.EJXnYs===void 0){var o=function(h){let x="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=",m="",_="";for(let S=0,y,v,I=0;v=h.charAt(I++);~v&&(y=S%4?y*64+v:v,S++%4)?m+=String.fromCharCode(255&y>>(-2*S&6)):0)v=x.indexOf(v);for(let S=0,y=m.length;S<y;S++)_+="%"+("00"+m.charCodeAt(S).toString(16)).slice(-2);return decodeURIComponent(_)};Z.yKxlVb=o,Z.nehYNN={},Z.EJXnYs=!0}let c=r[0],d=t+c,u=Z.nehYNN[d];return u?i=u:(i=Z.yKxlVb(i),Z.nehYNN[d]=i),i}Object["definePr"+F(852)](Ue,F(1809)+"le",{value:!0})});import{existsSync as qS,openSync as jS}from"node:fs";import{mkdir as WS}from"node:fs/promises";import{dirname as KS}from"node:path";import{fileURLToPath as $S}from"node:url";function JS(t,e){return e==="legacy"?t.logFile:t.daemonStdioLog}function Kd(t=ee()){return qS(t.libEntry)?t.libEntry:$S(new URL("../index.ts",import.meta.url))}async function tp(t={}){let e=t.paths??ee(),r=t.entryOverride??Kd(e),i=JS(e,process.env.COZE_BRIDGE_LOG_MODE);await WS(KS(i),{recursive:!0});let o=jS(i,"a"),d=r.endsWith(".ts")?["--import","tsx/esm",r,"--daemon"]:[r,"--daemon"],u=ot(process.execPath,d,{detached:!0,stdio:["ignore",o,o],env:{...process.env,[os]:"1"}});if(u.unref(),typeof u.pid!="number")throw new Error("failed to spawn daemon (no pid)");return VS.info("daemon spawned",{pid:u.pid,entry:r}),{pid:u.pid,entry:r}}var VS,os,ra=rt(()=>{"use strict";Xt();ne();Be();VS=H("spawn-daemon"),os="COZE_BRIDGE_DAEMON"});import{spawn as K1}from"node:child_process";import{mkdir as $1,unlink as V1,writeFile as J1}from"node:fs/promises";import{dirname as Z1,join as X1}from"node:path";function Zr(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function Y1(t){if(!t)return"";let e=Object.entries(t).map(([r,i])=>` <key>${Zr(r)}</key>
|
|
21
21
|
<string>${Zr(i)}</string>`).join(`
|
|
22
22
|
`);return e?`
|
|
23
23
|
<key>EnvironmentVariables</key>
|
|
24
24
|
<dict>
|
|
25
25
|
${e}
|
|
26
|
-
</dict>`:""}function
|
|
26
|
+
</dict>`:""}function Q1(t,e){return new Promise((r,i)=>{let o=K1(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var Jr,ds,da,tl,Sp=rt(()=>{"use strict";ne();Jr=H("supervisor.launchd"),ds="ai.coze.bridge",da=Q1,tl={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>${ds}</string>
|
|
32
32
|
<key>ProgramArguments</key>
|
|
33
33
|
<array>
|
|
34
34
|
<string>${Zr(t.nodeBin)}</string>
|
|
@@ -44,11 +44,11 @@ ${e}
|
|
|
44
44
|
<key>StandardOutPath</key>
|
|
45
45
|
<string>${Zr(t.logFile)}</string>
|
|
46
46
|
<key>StandardErrorPath</key>
|
|
47
|
-
<string>${Zr(t.logFile)}</string>${
|
|
47
|
+
<string>${Zr(t.logFile)}</string>${Y1(t.env)}
|
|
48
48
|
</dict>
|
|
49
49
|
</plist>
|
|
50
|
-
`},configPath(t){return
|
|
51
|
-
`):""}function fa(t,e){return new Promise((
|
|
50
|
+
`},configPath(t){return X1(t.homeDir,"Library","LaunchAgents",`${ds}.plist`)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t);if(await $1(Z1(i),{recursive:!0}),await J1(i,this.renderConfig(t),"utf8"),Jr.info("plist written",{plistPath:i,activate:r}),!r)return;await da("launchctl",["unload","-w",i]).catch(c=>Jr.info("launchctl unload before load (ignored, likely not loaded yet)",{err:String(c)})),await da("launchctl",["load","-w",i]),Jr.info("launchd job loaded",{label:ds});let o=process.getuid?.()??0;await da("launchctl",["kickstart","-k",`gui/${o}/${ds}`]),Jr.info("launchd job kickstarted",{label:ds,uid:o})},async uninstall(t){let e=this.configPath(t);await da("launchctl",["unload","-w",e]).catch(r=>Jr.warn("launchctl unload failed (ignored)",{err:String(r)})),await V1(e).catch(r=>{if(r.code!=="ENOENT")throw r}),Jr.info("launchd job removed",{plistPath:e})}}});import{spawn as eI}from"node:child_process";import{mkdir as tI,unlink as nI,writeFile as rI}from"node:fs/promises";import{dirname as iI,join as Ip}from"node:path";function ua(t,e){return t.isRoot?e:["--user",...e]}function oI(t){return t?Object.entries(t).map(([e,r])=>{let i=r.replace(/\\/g,"\\\\").replace(/"/g,'\\"');return`Environment="${e}=${i}"`}).join(`
|
|
51
|
+
`):""}function fa(t,e){return new Promise((r,i)=>{let o=eI(t,e,{stdio:["ignore","pipe","pipe"]}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var la,Xr,sI,nl,Ap=rt(()=>{"use strict";ne();la=H("supervisor.systemd"),Xr="coze-bridge.service",sI="/etc/systemd/system";nl={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
|
+
${oI(t.env)}
|
|
63
63
|
[Install]
|
|
64
64
|
WantedBy=${e}
|
|
65
|
-
`},configPath(t){return t.isRoot?
|
|
65
|
+
`},configPath(t){return t.isRoot?Ip(sI,Xr):Ip(t.homeDir,".config","systemd","user",Xr)},async install(t,e){let r=e?.activate!==!1,i=this.configPath(t),o=t.isRoot?"system":"user";await tI(iI(i),{recursive:!0}),await rI(i,this.renderConfig(t),"utf8"),la.info("systemd unit written",{unitPath:i,mode:o,activate:r}),await fa("systemctl",ua(t,["daemon-reload"])),await fa("systemctl",ua(t,r?["enable","--now",Xr]:["enable",Xr])),la.info("systemd unit enabled",{unitName:Xr,mode:o,activate:r})},async uninstall(t){let e=this.configPath(t);await fa("systemctl",ua(t,["disable","--now",Xr])).catch(r=>la.warn("systemctl disable failed (ignored)",{err:String(r)})),await nI(e).catch(r=>{if(r.code!=="ENOENT")throw r}),await fa("systemctl",ua(t,["daemon-reload"])).catch(()=>{}),la.info("systemd unit removed",{unitPath:e})}}});import{spawn as aI}from"node:child_process";import{join as cI}from"node:path";function kp(t,e){return new Promise((r,i)=>{let o=aI(t,e,{stdio:["ignore","pipe","pipe"],shell:!1}),c="";o.stderr?.on("data",d=>{c+=d.toString("utf8")}),o.on("error",i),o.on("close",d=>{d===0?r():i(new Error(`${t} ${e.join(" ")} exited ${d}: ${c.trim()}`))})})}var rl,ha,il,Tp=rt(()=>{"use strict";ne();rl=H("supervisor.taskscheduler"),ha="CozeBridge",il={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,50 +86,56 @@ WantedBy=${e}
|
|
|
86
86
|
</Exec>
|
|
87
87
|
</Actions>
|
|
88
88
|
</Task>
|
|
89
|
-
`},configPath(t){return QS(t.homeDir,".coze","bridge","task.xml")},async install(t){let n=`cmd.exe /c ${[`^"${t.nodeBin}^"`,`^"${t.entry}^"`,"--daemon",`>> ^"${t.logFile}^" 2>&1`].join(" ")}`;await Sp("schtasks",["/Create","/SC","ONLOGON","/TN",xa,"/TR",n,"/RU",t.userName,"/F"]),tl.info("task scheduler entry created",{task:xa,logFile:t.logFile})},async uninstall(t){await Sp("schtasks",["/Delete","/TN",xa,"/F"]).catch(e=>tl.warn("schtasks /Delete failed (ignored)",{err:String(e)})),tl.info("task scheduler entry removed",{task:xa})}}});var Ap={};Aa(Ap,{buildContext:()=>sI,getSupervisor:()=>nI,launchdSupervisor:()=>Qd,systemdSupervisor:()=>el,taskSchedulerSupervisor:()=>nl});import{homedir as eI,userInfo as tI}from"node:os";function nI(t=process.platform){switch(t){case"darwin":return Qd;case"linux":return el;case"win32":return nl;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function iI(){let t={};for(let e of rI){let n=process.env[e];n&&(t[e]=n)}return t}function sI(){let t=te();return{nodeBin:process.execPath,entry:qd(t),logFile:t.logFile,homeDir:eI(),userName:tI().username,isRoot:process.getuid?.()===0,env:iI()}}var rI,kp=nt(()=>{"use strict";Me();ra();bp();vp();Ip();rI=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ie();an();var Dl=K("acp-installer-warmup"),tm=["claude-code","codex"];async function Ol(t={}){let e=t.ensure??dr,i=(await Promise.allSettled(tm.map(async o=>{let c=await e(o);Dl.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&Dl.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}ln();ie();import{readdir as mm}from"node:fs/promises";import{mkdir as Bl,readFile as pm,writeFile as Fl}from"node:fs/promises";import{join as Oa}from"node:path";var gm={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function fr(t,e,n){await Bl(t,{recursive:!0});let i=gm[e],o=Oa(t,i);return await Fl(o,n??"","utf8"),o}async function La(t,e,n){let i=Oa(t,".claude");await Bl(i,{recursive:!0});let o=Oa(i,"settings.local.json"),c={};try{let u=await pm(o,"utf8"),x=JSON.parse(u);typeof x=="object"&&x!==null&&!Array.isArray(x)&&(c=x)}catch{}let d=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")d.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!n)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");d.defaultMode===void 0&&(d.defaultMode=n)}return c.permissions=d,await Fl(o,JSON.stringify(c,null,2),"utf8"),o}var Xe=K("agent-detail-sync"),wm=6e4,_m=5*6e4,ys=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let n=this.opts.paths.agentsRoot,i;try{i=await mm(n)}catch(o){Xe.info("agents dir not found, skip detail sync",{root:n,err:String(o)});return}Xe.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Pe(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Xe.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(d){Xe.warn("detail sync failed for agent, skipping",{agentId:o,err:String(d)})}}})),Xe.info("detail sync done",{reason:e})}async retryPending(){if(this.retryQueue.size===0)return;let e=Date.now(),n=[];for(let[i,o]of this.retryQueue)e>=o.dueAt&&n.push(i);if(n.length!==0){Xe.info("retrying pending detail syncs",{count:n.length});for(let i of n)try{await this.syncOne(i)}catch(o){Xe.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,n){let i=n??await Pe(e,this.opts.paths);if(!i){Xe.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(x){Xe.warn("detail RPC failed, using local data",{agentId:e,err:String(x)});let h=this.retryQueue.get(e),g=h?Math.min(h.currentDelay*2,_m):wm;this.retryQueue.set(e,{dueAt:Date.now()+g,currentDelay:g});return}if(o.agentId&&o.agentId!==e){Xe.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,d=!1;o.agentName&&o.agentName!==i.agentName&&(i.agentName=o.agentName,c=!0),o.description!==void 0&&o.description!==i.description&&(i.description=o.description,c=!0),o.cozeIdentity&&o.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=o.cozeIdentity,c=!0,d=!0);let u=!1;if(o.deployType==="cloud"&&i.deployType!=="cloud"?(Xe.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&Xe.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Xe.debug("detail sync: no diff",{agentId:e});return}await Ue(i,this.opts.paths),Xe.info("detail sync: config updated",{agentId:e,identityChanged:d,agentName:i.agentName}),u?(await this.opts.agentManager.createAgent({agentId:e,framework:i.framework,_meta:{cozeDeployType:"cloud"},cozeIdentity:i.cozeIdentity,model:i.model}),Xe.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):d&&(await fr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var id=Gt(mu(),1);import{createHash as Q_}from"node:crypto";import{lstat as Zc,mkdir as Yc,readFile as xo,readdir as r0,rm as Xc,stat as nd,writeFile as Qc}from"node:fs/promises";import{homedir as ey}from"node:os";import{basename as e0,dirname as ty,join as ge,normalize as ny,relative as rd,resolve as ed,sep as i0}from"node:path";import{Readable as s0}from"node:stream";import{pipeline as o0}from"node:stream/promises";import Gm from"events";import it from"fs";import{EventEmitter as Oc}from"node:events";import Xu from"node:stream";import{StringDecoder as jm}from"node:string_decoder";import tf from"node:path";import Sr from"node:fs";import{dirname as tw,parse as nw}from"path";import{EventEmitter as lw}from"events";import hc from"assert";import{Buffer as Hn}from"buffer";import*as Eu from"zlib";import uw from"zlib";import{posix as mr}from"node:path";import{basename as Fw}from"node:path";import Xs from"fs";import Ct from"fs";import Cu from"path";import{win32 as Zw}from"node:path";import Mu from"path";import mf from"node:fs";import x_ from"node:assert";import{randomBytes as wf}from"node:crypto";import oe from"node:fs";import Fe from"node:path";import _f from"fs";import ao from"node:fs";import Ai from"node:path";import ct from"node:fs";import y_ from"node:fs/promises";import to from"node:path";import{join as Pf}from"node:path";import at from"node:fs";import Of from"node:path";var zm=Object.defineProperty,Um=(t,e)=>{for(var n in e)zm(t,n,{get:e[n],enumerable:!0})},wu=typeof process=="object"&&process?process:{stdout:null,stderr:null},Hm=t=>!!t&&typeof t=="object"&&(t instanceof Kn||t instanceof Xu||qm(t)||Wm(t)),qm=t=>!!t&&typeof t=="object"&&t instanceof Oc&&typeof t.pipe=="function"&&t.pipe!==Xu.Writable.prototype.pipe,Wm=t=>!!t&&typeof t=="object"&&t instanceof Oc&&typeof t.write=="function"&&typeof t.end=="function",jt=Symbol("EOF"),Ht=Symbol("maybeEmitEnd"),fn=Symbol("emittedEnd"),Is=Symbol("emittingEnd"),di=Symbol("emittedError"),As=Symbol("closed"),_u=Symbol("read"),ks=Symbol("flush"),yu=Symbol("flushChunk"),wt=Symbol("encoding"),gr=Symbol("decoder"),Ge=Symbol("flowing"),li=Symbol("paused"),br=Symbol("resume"),je=Symbol("buffer"),Qe=Symbol("pipes"),He=Symbol("bufferLength"),Ua=Symbol("bufferPush"),Ts=Symbol("bufferShift"),Ye=Symbol("objectMode"),ke=Symbol("destroyed"),Ga=Symbol("error"),ja=Symbol("emitData"),bu=Symbol("emitEnd"),Ha=Symbol("emitEnd2"),At=Symbol("async"),qa=Symbol("abort"),Cs=Symbol("aborted"),ui=Symbol("signal"),Ln=Symbol("dataListeners"),ot=Symbol("discarded"),fi=t=>Promise.resolve().then(t),Km=t=>t(),$m=t=>t==="end"||t==="finish"||t==="prefinish",Vm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,Jm=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Qu=class{src;dest;opts;ondrain;constructor(t,e,n){this.src=t,this.dest=e,this.opts=n,this.ondrain=()=>t[br](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Zm=class extends Qu{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,n){super(t,e,n),this.proxyErrors=i=>this.dest.emit("error",i),t.on("error",this.proxyErrors)}},Ym=t=>!!t.objectMode,Xm=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Kn=class extends Oc{[Ge]=!1;[li]=!1;[Qe]=[];[je]=[];[Ye];[wt];[At];[gr];[jt]=!1;[fn]=!1;[Is]=!1;[As]=!1;[di]=null;[He]=0;[ke]=!1;[ui];[Cs]=!1;[Ln]=0;[ot]=!1;writable=!0;readable=!0;constructor(...t){let e=t[0]||{};if(super(),e.objectMode&&typeof e.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");Ym(e)?(this[Ye]=!0,this[wt]=null):Xm(e)?(this[wt]=e.encoding,this[Ye]=!1):(this[Ye]=!1,this[wt]=null),this[At]=!!e.async,this[gr]=this[wt]?new jm(this[wt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[je]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[Qe]});let{signal:n}=e;n&&(this[ui]=n,n.aborted?this[qa]():n.addEventListener("abort",()=>this[qa]()))}get bufferLength(){return this[He]}get encoding(){return this[wt]}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[Ye]}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}[qa](){this[Cs]=!0,this.emit("abort",this[ui]?.reason),this.destroy(this[ui]?.reason)}get aborted(){return this[Cs]}set aborted(t){}write(t,e,n){if(this[Cs])return!1;if(this[jt])throw new Error("write after end");if(this[ke])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof e=="function"&&(n=e,e="utf8"),e||(e="utf8");let i=this[At]?fi:Km;if(!this[Ye]&&!Buffer.isBuffer(t)){if(Jm(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(Vm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Ye]?(this[Ge]&&this[He]!==0&&this[ks](!0),this[Ge]?this.emit("data",t):this[Ua](t),this[He]!==0&&this.emit("readable"),n&&i(n),this[Ge]):t.length?(typeof t=="string"&&!(e===this[wt]&&!this[gr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[wt]&&(t=this[gr].write(t)),this[Ge]&&this[He]!==0&&this[ks](!0),this[Ge]?this.emit("data",t):this[Ua](t),this[He]!==0&&this.emit("readable"),n&&i(n),this[Ge]):(this[He]!==0&&this.emit("readable"),n&&i(n),this[Ge])}read(t){if(this[ke])return null;if(this[ot]=!1,this[He]===0||t===0||t&&t>this[He])return this[Ht](),null;this[Ye]&&(t=null),this[je].length>1&&!this[Ye]&&(this[je]=[this[wt]?this[je].join(""):Buffer.concat(this[je],this[He])]);let e=this[_u](t||null,this[je][0]);return this[Ht](),e}[_u](t,e){if(this[Ye])this[Ts]();else{let n=e;t===n.length||t===null?this[Ts]():typeof n=="string"?(this[je][0]=n.slice(t),e=n.slice(0,t),this[He]-=t):(this[je][0]=n.subarray(t),e=n.subarray(0,t),this[He]-=t)}return this.emit("data",e),!this[je].length&&!this[jt]&&this.emit("drain"),e}end(t,e,n){return typeof t=="function"&&(n=t,t=void 0),typeof e=="function"&&(n=e,e="utf8"),t!==void 0&&this.write(t,e),n&&this.once("end",n),this[jt]=!0,this.writable=!1,(this[Ge]||!this[li])&&this[Ht](),this}[br](){this[ke]||(!this[Ln]&&!this[Qe].length&&(this[ot]=!0),this[li]=!1,this[Ge]=!0,this.emit("resume"),this[je].length?this[ks]():this[jt]?this[Ht]():this.emit("drain"))}resume(){return this[br]()}pause(){this[Ge]=!1,this[li]=!0,this[ot]=!1}get destroyed(){return this[ke]}get flowing(){return this[Ge]}get paused(){return this[li]}[Ua](t){this[Ye]?this[He]+=1:this[He]+=t.length,this[je].push(t)}[Ts](){return this[Ye]?this[He]-=1:this[He]-=this[je][0].length,this[je].shift()}[ks](t=!1){do;while(this[yu](this[Ts]())&&this[je].length);!t&&!this[je].length&&!this[jt]&&this.emit("drain")}[yu](t){return this.emit("data",t),this[Ge]}pipe(t,e){if(this[ke])return t;this[ot]=!1;let n=this[fn];return e=e||{},t===wu.stdout||t===wu.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,n?e.end&&t.end():(this[Qe].push(e.proxyErrors?new Zm(this,t,e):new Qu(this,t,e)),this[At]?fi(()=>this[br]()):this[br]()),t}unpipe(t){let e=this[Qe].find(n=>n.dest===t);e&&(this[Qe].length===1?(this[Ge]&&this[Ln]===0&&(this[Ge]=!1),this[Qe]=[]):this[Qe].splice(this[Qe].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){let n=super.on(t,e);if(t==="data")this[ot]=!1,this[Ln]++,!this[Qe].length&&!this[Ge]&&this[br]();else if(t==="readable"&&this[He]!==0)super.emit("readable");else if($m(t)&&this[fn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[di]){let i=e;this[At]?fi(()=>i.call(this,this[di])):i.call(this,this[di])}return n}removeListener(t,e){return this.off(t,e)}off(t,e){let n=super.off(t,e);return t==="data"&&(this[Ln]=this.listeners("data").length,this[Ln]===0&&!this[ot]&&!this[Qe].length&&(this[Ge]=!1)),n}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Ln]=0,!this[ot]&&!this[Qe].length&&(this[Ge]=!1)),e}get emittedEnd(){return this[fn]}[Ht](){!this[Is]&&!this[fn]&&!this[ke]&&this[je].length===0&&this[jt]&&(this[Is]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[As]&&this.emit("close"),this[Is]=!1)}emit(t,...e){let n=e[0];if(t!=="error"&&t!=="close"&&t!==ke&&this[ke])return!1;if(t==="data")return!this[Ye]&&!n?!1:this[At]?(fi(()=>this[ja](n)),!0):this[ja](n);if(t==="end")return this[bu]();if(t==="close"){if(this[As]=!0,!this[fn]&&!this[ke])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[di]=n,super.emit(Ga,n);let o=!this[ui]||this.listeners("error").length?super.emit("error",n):!1;return this[Ht](),o}else if(t==="resume"){let o=super.emit("resume");return this[Ht](),o}else if(t==="finish"||t==="prefinish"){let o=super.emit(t);return this.removeAllListeners(t),o}let i=super.emit(t,...e);return this[Ht](),i}[ja](t){for(let n of this[Qe])n.dest.write(t)===!1&&this.pause();let e=this[ot]?!1:super.emit("data",t);return this[Ht](),e}[bu](){return this[fn]?!1:(this[fn]=!0,this.readable=!1,this[At]?(fi(()=>this[Ha]()),!0):this[Ha]())}[Ha](){if(this[gr]){let e=this[gr].end();if(e){for(let n of this[Qe])n.dest.write(e);this[ot]||super.emit("data",e)}}for(let e of this[Qe])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Ye]||(t.dataLength=0);let e=this.promise();return this.on("data",n=>{t.push(n),this[Ye]||(t.dataLength+=n.length)}),await e,t}async concat(){if(this[Ye])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[wt]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(ke,()=>e(new Error("stream destroyed"))),this.on("error",n=>e(n)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[ot]=!1;let t=!1,e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();let n=this.read();if(n!==null)return Promise.resolve({done:!1,value:n});if(this[jt])return e();let i,o,c=h=>{this.off("data",d),this.off("end",u),this.off(ke,x),e(),o(h)},d=h=>{this.off("error",c),this.off("end",u),this.off(ke,x),this.pause(),i({value:h,done:!!this[jt]})},u=()=>{this.off("error",c),this.off("data",d),this.off(ke,x),e(),i({done:!0,value:void 0})},x=()=>c(new Error("stream destroyed"));return new Promise((h,g)=>{o=g,i=h,this.once(ke,x),this.once("error",c),this.once("end",u),this.once("data",d)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[ot]=!1;let t=!1,e=()=>(this.pause(),this.off(Ga,e),this.off(ke,e),this.off("end",e),t=!0,{done:!0,value:void 0}),n=()=>{if(t)return e();let i=this.read();return i===null?e():{done:!1,value:i}};return this.once("end",e),this.once(Ga,e),this.once(ke,e),{next:n,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[ke])return t?this.emit("error",t):this.emit(ke),this;this[ke]=!0,this[ot]=!0,this[je].length=0,this[He]=0;let e=this;return typeof e.close=="function"&&!this[As]&&e.close(),t?this.emit("error",t):this.emit(ke),this}static get isStream(){return Hm}},Qm=it.writev,En=Symbol("_autoClose"),Et=Symbol("_close"),xi=Symbol("_ended"),ue=Symbol("_fd"),Wa=Symbol("_finished"),$t=Symbol("_flags"),Ka=Symbol("_flush"),fc=Symbol("_handleChunk"),xc=Symbol("_makeBuf"),Si=Symbol("_mode"),Ps=Symbol("_needDrain"),Ar=Symbol("_onerror"),kr=Symbol("_onopen"),$a=Symbol("_onread"),Er=Symbol("_onwrite"),vn=Symbol("_open"),bt=Symbol("_path"),mn=Symbol("_pos"),kt=Symbol("_queue"),vr=Symbol("_read"),Va=Symbol("_readSize"),Kt=Symbol("_reading"),hi=Symbol("_remain"),Ja=Symbol("_size"),Us=Symbol("_write"),Nn=Symbol("_writing"),Gs=Symbol("_defaultFlag"),jn=Symbol("_errored"),Lc=class extends Kn{[jn]=!1;[ue];[bt];[Va];[Kt]=!1;[Ja];[hi];[En];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[jn]=!1,this[ue]=typeof e.fd=="number"?e.fd:void 0,this[bt]=t,this[Va]=e.readSize||16*1024*1024,this[Kt]=!1,this[Ja]=typeof e.size=="number"?e.size:1/0,this[hi]=this[Ja],this[En]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[ue]=="number"?this[vr]():this[vn]()}get fd(){return this[ue]}get path(){return this[bt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[vn](){it.open(this[bt],"r",(t,e)=>this[kr](t,e))}[kr](t,e){t?this[Ar](t):(this[ue]=e,this.emit("open",e),this[vr]())}[xc](){return Buffer.allocUnsafe(Math.min(this[Va],this[hi]))}[vr](){if(!this[Kt]){this[Kt]=!0;let t=this[xc]();if(t.length===0)return process.nextTick(()=>this[$a](null,0,t));it.read(this[ue],t,0,t.length,null,(e,n,i)=>this[$a](e,n,i))}}[$a](t,e,n){this[Kt]=!1,t?this[Ar](t):this[fc](e,n)&&this[vr]()}[Et](){if(this[En]&&typeof this[ue]=="number"){let t=this[ue];this[ue]=void 0,it.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[Ar](t){this[Kt]=!0,this[Et](),this.emit("error",t)}[fc](t,e){let n=!1;return this[hi]-=t,t>0&&(n=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[hi]<=0)&&(n=!1,this[Et](),super.end()),n}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[ue]=="number"&&this[vr](),!1;case"error":return this[jn]?!1:(this[jn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},ew=class extends Lc{[vn](){let t=!0;try{this[kr](null,it.openSync(this[bt],"r")),t=!1}finally{t&&this[Et]()}}[vr](){let t=!0;try{if(!this[Kt]){this[Kt]=!0;do{let e=this[xc](),n=e.length===0?0:it.readSync(this[ue],e,0,e.length,null);if(!this[fc](n,e))break}while(!0);this[Kt]=!1}t=!1}finally{t&&this[Et]()}}[Et](){if(this[En]&&typeof this[ue]=="number"){let t=this[ue];this[ue]=void 0,it.closeSync(t),this.emit("close")}}},no=class extends Gm{readable=!1;writable=!0;[jn]=!1;[Nn]=!1;[xi]=!1;[kt]=[];[Ps]=!1;[bt];[Si];[En];[ue];[Gs];[$t];[Wa]=!1;[mn];constructor(t,e){e=e||{},super(e),this[bt]=t,this[ue]=typeof e.fd=="number"?e.fd:void 0,this[Si]=e.mode===void 0?438:e.mode,this[mn]=typeof e.start=="number"?e.start:void 0,this[En]=typeof e.autoClose=="boolean"?e.autoClose:!0;let n=this[mn]!==void 0?"r+":"w";this[Gs]=e.flags===void 0,this[$t]=e.flags===void 0?n:e.flags,this[ue]===void 0&&this[vn]()}emit(t,...e){if(t==="error"){if(this[jn])return!1;this[jn]=!0}return super.emit(t,...e)}get fd(){return this[ue]}get path(){return this[bt]}[Ar](t){this[Et](),this[Nn]=!0,this.emit("error",t)}[vn](){it.open(this[bt],this[$t],this[Si],(t,e)=>this[kr](t,e))}[kr](t,e){this[Gs]&&this[$t]==="r+"&&t&&t.code==="ENOENT"?(this[$t]="w",this[vn]()):t?this[Ar](t):(this[ue]=e,this.emit("open",e),this[Nn]||this[Ka]())}end(t,e){return t&&this.write(t,e),this[xi]=!0,!this[Nn]&&!this[kt].length&&typeof this[ue]=="number"&&this[Er](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[xi]?(this.emit("error",new Error("write() after end()")),!1):this[ue]===void 0||this[Nn]||this[kt].length?(this[kt].push(t),this[Ps]=!0,!1):(this[Nn]=!0,this[Us](t),!0)}[Us](t){it.write(this[ue],t,0,t.length,this[mn],(e,n)=>this[Er](e,n))}[Er](t,e){t?this[Ar](t):(this[mn]!==void 0&&typeof e=="number"&&(this[mn]+=e),this[kt].length?this[Ka]():(this[Nn]=!1,this[xi]&&!this[Wa]?(this[Wa]=!0,this[Et](),this.emit("finish")):this[Ps]&&(this[Ps]=!1,this.emit("drain"))))}[Ka](){if(this[kt].length===0)this[xi]&&this[Er](null,0);else if(this[kt].length===1)this[Us](this[kt].pop());else{let t=this[kt];this[kt]=[],Qm(this[ue],t,this[mn],(e,n)=>this[Er](e,n))}}[Et](){if(this[En]&&typeof this[ue]=="number"){let t=this[ue];this[ue]=void 0,it.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},ef=class extends no{[vn](){let t;if(this[Gs]&&this[$t]==="r+")try{t=it.openSync(this[bt],this[$t],this[Si])}catch(e){if(e?.code==="ENOENT")return this[$t]="w",this[vn]();throw e}else t=it.openSync(this[bt],this[$t],this[Si]);this[kr](null,t)}[Et](){if(this[En]&&typeof this[ue]=="number"){let t=this[ue];this[ue]=void 0,it.closeSync(t),this.emit("close")}}[Us](t){let e=!0;try{this[Er](null,it.writeSync(this[ue],t,0,t.length,this[mn])),e=!1}finally{if(e)try{this[Et]()}catch{}}}},rw=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"]]),iw=t=>!!t.sync&&!!t.file,sw=t=>!t.sync&&!!t.file,ow=t=>!!t.sync&&!t.file,aw=t=>!t.sync&&!t.file,cw=t=>!!t.file,dw=t=>rw.get(t)||t,Nc=(t={})=>{if(!t)return{};let e={};for(let[n,i]of Object.entries(t)){let o=dw(n);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Oi=(t,e,n,i,o)=>Object.assign((c=[],d,u)=>{Array.isArray(c)&&(d=c,c={}),typeof d=="function"&&(u=d,d=void 0),d=d?Array.from(d):[];let x=Nc(c);if(o?.(x,d),iw(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(x,d)}else if(sw(x)){let h=e(x,d);return u?h.then(()=>u(),u):h}else if(ow(x)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return n(x,d)}else if(aw(x)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(x,d)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:n,asyncNoFile:i,validate:o}),fw=uw.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},fw)),xw=Hn.concat,vu=Object.getOwnPropertyDescriptor(Hn,"concat"),hw=t=>t,Za=vu?.writable===!0||vu?.set!==void 0?t=>{Hn.concat=t?hw:xw}:t=>{},qn=Symbol("_superWrite"),Rs=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"}},Ya=Symbol("flushFlag"),Mc=class extends Kn{#e=!1;#n=!1;#r;#s;#i;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#r}constructor(t,e){if(!t||typeof t!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#r=t.flush??0,this.#s=t.finishFlush??0,this.#i=t.fullFlushFlag??0,typeof Eu[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new Eu[e](t)}catch(n){throw new Rs(n,this.constructor)}this.#o=n=>{this.#e||(this.#e=!0,this.close(),this.emit("error",n))},this.#t?.on("error",n=>this.#o(new Rs(n))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return hc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(Hn.alloc(0),{[Ya]:t})))}end(t,e,n){return typeof t=="function"&&(n=t,e=void 0,t=void 0),typeof e=="function"&&(n=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#n=!0,super.end(n)}get ended(){return this.#n}[qn](t){return super.write(t)}write(t,e,n){if(typeof e=="function"&&(n=e,e="utf8"),typeof t=="string"&&(t=Hn.from(t,e)),this.#e)return;hc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},Za(!0);let d;try{let x=typeof t[Ya]=="number"?t[Ya]:this.#r;d=this.#t._processChunk(t,x),Za(!1)}catch(x){Za(!1),this.#o(new Rs(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 Rs(x,this.write)));let u;if(d)if(Array.isArray(d)&&d.length>0){let x=d[0];u=this[qn](Hn.from(x));for(let h=1;h<d.length;h++)u=this[qn](d[h])}else u=this[qn](Hn.from(d));return n&&n(),u}},nf=class extends Mc{#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),hc(this.handle,"zlib binding closed");let n=this.handle.flush;this.handle.flush=(i,o)=>{typeof i=="function"&&(o=i,i=this.flushFlag),this.flush(i),o?.()};try{this.handle.params(t,e)}finally{this.handle.flush=n}this.handle&&(this.#e=t,this.#n=e)}}}},pw=class extends nf{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[qn](t){return this.#e?(this.#e=!1,t[9]=255,super[qn](t)):super[qn](t)}},gw=class extends nf{constructor(t){super(t,"Unzip")}},rf=class extends Mc{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)}},mw=class extends rf{constructor(t){super(t,"BrotliCompress")}},ww=class extends rf{constructor(t){super(t,"BrotliDecompress")}},sf=class extends Mc{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)}},_w=class extends sf{constructor(t){super(t,"ZstdCompress")}},yw=class extends sf{constructor(t){super(t,"ZstdDecompress")}},bw=(t,e)=>{if(Number.isSafeInteger(t))t<0?vw(t,e):Ew(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Ew=(t,e)=>{e[0]=128;for(var n=e.length;n>1;n--)e[n-1]=t&255,t=Math.floor(t/256)},vw=(t,e)=>{e[0]=255;var n=!1;t=t*-1;for(var i=e.length;i>1;i--){var o=t&255;t=Math.floor(t/256),n?e[i-1]=of(o):o===0?e[i-1]=0:(n=!0,e[i-1]=af(o))}},Sw=t=>{let e=t[0],n=e===128?Aw(t.subarray(1,t.length)):e===255?Iw(t):null;if(n===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(n))throw Error("parsed number outside of javascript safe integer range");return n},Iw=t=>{for(var e=t.length,n=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),d;i?d=of(c):c===0?d=c:(i=!0,d=af(c)),d!==0&&(n-=d*Math.pow(256,e-o-1))}return n},Aw=t=>{for(var e=t.length,n=0,i=e-1;i>-1;i--){var o=Number(t[i]);o!==0&&(n+=o*Math.pow(256,e-i-1))}return n},of=t=>(255^t)&255,af=t=>(255^t)+1&255,kw={};Um(kw,{code:()=>Bc,isCode:()=>js,isName:()=>Tw,name:()=>ro,normalFsTypes:()=>cf});var js=t=>ro.has(t),Tw=t=>Bc.has(t),cf=new Set(["0","","1","2","3","4","5","6","7","D"]),ro=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),Bc=new Map(Array.from(ro).map(t=>[t[1],t[0]])),Wn=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,n,i){Buffer.isBuffer(t)?this.decode(t,e||0,n,i):t&&this.#n(t)}decode(t,e,n,i){if(e||(e=0),!t||!(t.length>=e+512))throw new Error("need 512 bytes for header");let o=Mn(t,e+156,1),c=cf.has(o),d=c?n:void 0,u=c?i:void 0;if(this.path=d?.path??Mn(t,e,100),this.mode=d?.mode??u?.mode??wn(t,e+100,8),this.uid=d?.uid??u?.uid??wn(t,e+108,8),this.gid=d?.gid??u?.gid??wn(t,e+116,8),this.size=d?.size??u?.size??wn(t,e+124,12),this.mtime=d?.mtime??u?.mtime??Xa(t,e+136,12),this.cksum=wn(t,e+148,12),u&&this.#n(u,!0),d&&this.#n(d),js(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Mn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=d?.uname??u?.uname??Mn(t,e+265,32),this.gname=d?.gname??u?.gname??Mn(t,e+297,32),this.devmaj=d?.devmaj??u?.devmaj??wn(t,e+329,8)??0,this.devmin=d?.devmin??u?.devmin??wn(t,e+337,8)??0,t[e+475]!==0){let h=Mn(t,e+345,155);this.path=h+"/"+this.path}else{let h=Mn(t,e+345,130);h&&(this.path=h+"/"+this.path),this.atime=n?.atime??i?.atime??Xa(t,e+476,12),this.ctime=n?.ctime??i?.ctime??Xa(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(([n,i])=>!(i==null||n==="path"&&e||n==="linkpath"&&e||n==="global"))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");let n=this.ctime||this.atime?130:155,i=Cw(this.path||"",n),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Bn(t,e,100,o)||this.needPax,this.needPax=_n(t,e+100,8,this.mode)||this.needPax,this.needPax=_n(t,e+108,8,this.uid)||this.needPax,this.needPax=_n(t,e+116,8,this.gid)||this.needPax,this.needPax=_n(t,e+124,12,this.size)||this.needPax,this.needPax=Qa(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Bn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Bn(t,e+265,32,this.uname)||this.needPax,this.needPax=Bn(t,e+297,32,this.gname)||this.needPax,this.needPax=_n(t,e+329,8,this.devmaj)||this.needPax,this.needPax=_n(t,e+337,8,this.devmin)||this.needPax,this.needPax=Bn(t,e+345,n,c)||this.needPax,t[e+475]!==0?this.needPax=Bn(t,e+345,155,c)||this.needPax:(this.needPax=Bn(t,e+345,130,c)||this.needPax,this.needPax=Qa(t,e+476,12,this.atime)||this.needPax,this.needPax=Qa(t,e+488,12,this.ctime)||this.needPax);let d=256;for(let u=e;u<e+148;u++)d+=t[u];for(let u=e+156;u<e+512;u++)d+=t[u];return this.cksum=d,_n(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:ro.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(Bc.get(t));if(js(e)||e==="Unsupported")this.#e=e;else if(js(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Cw=(t,e)=>{let n=t,i="",o,c=mr.parse(t).root||".";if(Buffer.byteLength(n)<100)o=[n,i,!1];else{i=mr.dirname(n),n=mr.basename(n);do Buffer.byteLength(n)<=100&&Buffer.byteLength(i)<=e?o=[n,i,!1]:Buffer.byteLength(n)>100&&Buffer.byteLength(i)<=e?o=[n.slice(0,99),i,!0]:(n=mr.join(mr.basename(i),n),i=mr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Mn=(t,e,n)=>t.subarray(e,e+n).toString("utf8").replace(/\0.*/,""),Xa=(t,e,n)=>Pw(wn(t,e,n)),Pw=t=>t===void 0?void 0:new Date(t*1e3),wn=(t,e,n)=>Number(t[e])&128?Sw(t.subarray(e,e+n)):Dw(t,e,n),Rw=t=>isNaN(t)?void 0:t,Dw=(t,e,n)=>Rw(parseInt(t.subarray(e,e+n).toString("utf8").replace(/\0.*$/,"").trim(),8)),Ow={12:8589934591,8:2097151},_n=(t,e,n,i)=>i===void 0?!1:i>Ow[n]||i<0?(bw(i,t.subarray(e,e+n)),!0):(Lw(t,e,n,i),!1),Lw=(t,e,n,i)=>t.write(Nw(i,n),e,n,"ascii"),Nw=(t,e)=>Mw(Math.floor(t).toString(8),e),Mw=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Qa=(t,e,n,i)=>i===void 0?!1:_n(t,e,n,i.getTime()/1e3),Bw=new Array(156).join("\0"),Bn=(t,e,n,i)=>i===void 0?!1:(t.write(i+Bw,e,n,"utf8"),i.length!==Buffer.byteLength(i)||i.length>n),Ys=class df{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,n=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=n,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return Buffer.allocUnsafe(0);let n=Buffer.byteLength(e),i=512*Math.ceil(1+n/512),o=Buffer.allocUnsafe(i);for(let c=0;c<512;c++)o[c]=0;new Wn({path:("PaxHeader/"+Fw(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:n,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(o),o.write(e,512,n,"utf8");for(let c=n+512;c<o.length;c++)o[c]=0;return o}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let n=this[e],i=n instanceof Date?n.getTime()/1e3:n,o=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+i+`
|
|
90
|
-
`,c=Buffer.byteLength(o),d=Math.floor(Math.log(c)/Math.log(10))+1;return c+d>=Math.pow(10,d)&&(d+=1),d+c+o}static parse(e,
|
|
91
|
-
`).reduce(Gw,Object.create(null)),Gw=(t,e)=>{let n=parseInt(e,10);if(n!==Buffer.byteLength(e)+1)return t;e=e.slice((n+" ").length);let i=e.split("="),o=i.shift();if(!o)return t;let c=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),d=i.join("=");return t[c]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(c)?new Date(Number(d)*1e3):/^[0-9]+$/.test(d)?+d:d,t},jw=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,ee=jw!=="win32"?t=>t:t=>t&&t.replaceAll(/\\/g,"/"),Hw=class extends Kn{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,n){switch(super({}),this.pause(),this.extended=e,this.globalExtended=n,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=ee(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?ee(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#e(e),n&&this.#e(n,!0)}write(t){let e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");let n=this.remain,i=this.blockRemain;return this.remain=Math.max(0,n-e),this.blockRemain=Math.max(0,i-e),this.ignore?!0:n>=e?super.write(t):super.write(t.subarray(0,n))}#e(t,e=!1){t.path&&(t.path=ee(t.path)),t.linkpath&&(t.linkpath=ee(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([n,i])=>!(i==null||n==="path"&&e))))}},io=(t,e,n,i={})=>{t.file&&(i.file=t.file),t.cwd&&(i.cwd=t.cwd),i.code=n instanceof Error&&n.code||e,i.tarCode=e,!t.strict&&i.recoverable!==!1?(n instanceof Error&&(i=Object.assign(n,i),n=n.message),t.emit("warn",e,n,i)):n instanceof Error?t.emit("error",Object.assign(n,i)):t.emit("error",Object.assign(new Error(`${e}: ${n}`),i))},qw=1024*1024,pc=Buffer.from([31,139]),gc=Buffer.from([40,181,47,253]),Ww=Math.max(pc.length,gc.length),ut=Symbol("state"),Fn=Symbol("writeEntry"),qt=Symbol("readEntry"),ec=Symbol("nextEntry"),Su=Symbol("processEntry"),Tt=Symbol("extendedHeader"),pi=Symbol("globalExtendedHeader"),xn=Symbol("meta"),Iu=Symbol("emitMeta"),_e=Symbol("buffer"),Wt=Symbol("queue"),hn=Symbol("ended"),tc=Symbol("emittedEnd"),zn=Symbol("emit"),Re=Symbol("unzip"),Ds=Symbol("consumeChunk"),Os=Symbol("consumeChunkSub"),nc=Symbol("consumeBody"),Au=Symbol("consumeMeta"),ku=Symbol("consumeHeader"),gi=Symbol("consuming"),rc=Symbol("bufferConcat"),Ls=Symbol("maybeEnd"),wr=Symbol("writing"),pn=Symbol("aborted"),Ns=Symbol("onDone"),Un=Symbol("sawValidEntry"),Ms=Symbol("sawNullBlock"),Bs=Symbol("sawEOF"),Tu=Symbol("closeStream"),Kw=()=>!0,Di=class extends lw{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Wt]=[];[_e];[qt];[Fn];[ut]="begin";[xn]="";[Tt];[pi];[hn]=!1;[Re];[pn]=!1;[Un];[Ms]=!1;[Bs]=!1;[wr]=!1;[gi]=!1;[tc]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(Ns,()=>{(this[ut]==="begin"||this[Un]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Ns,t.ondone):this.on(Ns,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||qw,this.filter=typeof t.filter=="function"?t.filter:Kw;let e=t.file&&(t.file.endsWith(".tar.br")||t.file.endsWith(".tbr"));this.brotli=!(t.gzip||t.zstd)&&t.brotli!==void 0?t.brotli:e?void 0:!1;let n=t.file&&(t.file.endsWith(".tar.zst")||t.file.endsWith(".tzst"));this.zstd=!(t.gzip||t.brotli)&&t.zstd!==void 0?t.zstd:n?!0:void 0,this.on("end",()=>this[Tu]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,n={}){io(this,t,e,n)}[ku](t,e){this[Un]===void 0&&(this[Un]=!1);let n;try{n=new Wn(t,e,this[Tt],this[pi])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(n.nullBlock)this[Ms]?(this[Bs]=!0,this[ut]==="begin"&&(this[ut]="header"),this[zn]("eof")):(this[Ms]=!0,this[zn]("nullBlock"));else if(this[Ms]=!1,!n.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:n});else if(!n.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:n});else{let i=n.type;if(/^(Symbolic)?Link$/.test(i)&&!n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:n});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:n});else{let o=this[Fn]=new Hw(n,this[Tt],this[pi]);if(!this[Un])if(o.remain){let c=()=>{o.invalid||(this[Un]=!0)};o.on("end",c)}else this[Un]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[zn]("ignoredEntry",o),this[ut]="ignore",o.resume()):o.size>0&&(this[xn]="",o.on("data",c=>this[xn]+=c),this[ut]="meta"):(this[Tt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[zn]("ignoredEntry",o),this[ut]=o.remain?"ignore":"header",o.resume()):(o.remain?this[ut]="body":(this[ut]="header",o.end()),this[qt]?this[Wt].push(o):(this[Wt].push(o),this[ec]())))}}}[Tu](){queueMicrotask(()=>this.emit("close"))}[Su](t){let e=!0;if(!t)this[qt]=void 0,e=!1;else if(Array.isArray(t)){let[n,...i]=t;this.emit(n,...i)}else this[qt]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[ec]()),e=!1);return e}[ec](){do;while(this[Su](this[Wt].shift()));if(this[Wt].length===0){let t=this[qt];!t||t.flowing||t.size===t.remain?this[wr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[nc](t,e){let n=this[Fn];if(!n)throw new Error("attempt to consume body without entry??");let i=n.blockRemain??0,o=i>=t.length&&e===0?t:t.subarray(e,e+i);return n.write(o),n.blockRemain||(this[ut]="header",this[Fn]=void 0,n.end()),o.length}[Au](t,e){let n=this[Fn],i=this[nc](t,e);return!this[Fn]&&n&&this[Iu](n),i}[zn](t,e,n){this[Wt].length===0&&!this[qt]?this.emit(t,e,n):this[Wt].push([t,e,n])}[Iu](t){switch(this[zn]("meta",this[xn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Tt]=Ys.parse(this[xn],this[Tt],!1);break;case"GlobalExtendedHeader":this[pi]=Ys.parse(this[xn],this[pi],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Tt]??Object.create(null);this[Tt]=e,e.path=this[xn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Tt]||Object.create(null);this[Tt]=e,e.linkpath=this[xn].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[pn]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,n){if(typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this[pn])return n?.(),!1;if((this[Re]===void 0||this.brotli===void 0&&this[Re]===!1)&&t){if(this[_e]&&(t=Buffer.concat([this[_e],t]),this[_e]=void 0),t.length<Ww)return this[_e]=t,n?.(),!0;for(let d=0;this[Re]===void 0&&d<pc.length;d++)t[d]!==pc[d]&&(this[Re]=!1);let o=!1;if(this[Re]===!1&&this.zstd!==!1){o=!0;for(let d=0;d<gc.length;d++)if(t[d]!==gc[d]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Re]===!1&&c)if(t.length<512)if(this[hn])this.brotli=!0;else return this[_e]=t,n?.(),!0;else try{new Wn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Re]===void 0||this[Re]===!1&&(this.brotli||o)){let d=this[hn];this[hn]=!1,this[Re]=this[Re]===void 0?new gw({}):o?new yw({}):new ww({}),this[Re].on("data",x=>this[Ds](x)),this[Re].on("error",x=>this.abort(x)),this[Re].on("end",()=>{this[hn]=!0,this[Ds]()}),this[wr]=!0;let u=!!this[Re][d?"end":"write"](t);return this[wr]=!1,n?.(),u}}this[wr]=!0,this[Re]?this[Re].write(t):this[Ds](t),this[wr]=!1;let i=this[Wt].length>0?!1:this[qt]?this[qt].flowing:!0;return!i&&this[Wt].length===0&&this[qt]?.once("drain",()=>this.emit("drain")),n?.(),i}[rc](t){t&&!this[pn]&&(this[_e]=this[_e]?Buffer.concat([this[_e],t]):t)}[Ls](){if(this[hn]&&!this[tc]&&!this[pn]&&!this[gi]){this[tc]=!0;let t=this[Fn];if(t&&t.blockRemain){let e=this[_e]?this[_e].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[_e]&&t.write(this[_e]),t.end()}this[zn](Ns)}}[Ds](t){if(this[gi]&&t)this[rc](t);else if(!t&&!this[_e])this[Ls]();else if(t){if(this[gi]=!0,this[_e]){this[rc](t);let e=this[_e];this[_e]=void 0,this[Os](e)}else this[Os](t);for(;this[_e]&&this[_e]?.length>=512&&!this[pn]&&!this[Bs];){let e=this[_e];this[_e]=void 0,this[Os](e)}this[gi]=!1}(!this[_e]||this[hn])&&this[Ls]()}[Os](t){let e=0,n=t.length;for(;e+512<=n&&!this[pn]&&!this[Bs];)switch(this[ut]){case"begin":case"header":this[ku](t,e),e+=512;break;case"ignore":case"body":e+=this[nc](t,e);break;case"meta":e+=this[Au](t,e);break;default:throw new Error("invalid state: "+this[ut])}e<n&&(this[_e]=this[_e]?Buffer.concat([t.subarray(e),this[_e]]):t.subarray(e))}end(t,e,n){return typeof t=="function"&&(n=t,e=void 0,t=void 0),typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),n&&this.once("finish",n),this[pn]||(this[Re]?(t&&this[Re].write(t),this[Re].end()):(this[hn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Ls]())),this}},Ii=t=>{let e=t.length-1,n=-1;for(;e>-1&&t.charAt(e)==="/";)n=e,e--;return n===-1?t:t.slice(0,n)},$w=t=>{let e=t.onReadEntry;t.onReadEntry=e?n=>{e(n),n.resume()}:n=>n.resume()},lf=(t,e)=>{let n=new Map(e.map(c=>[Ii(c),!0])),i=t.filter,o=(c,d="")=>{let u=d||nw(c).root||".",x;if(c===u)x=!1;else{let h=n.get(c);x=h!==void 0?h:o(tw(c),u)}return n.set(c,x),x};t.filter=i?(c,d)=>i(c,d)&&o(Ii(c)):c=>o(Ii(c))},Vw=t=>{let e=new Di(t),n=t.file,i;try{i=Sr.openSync(n,"r");let o=Sr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let d=Buffer.allocUnsafe(o.size),u=Sr.readSync(i,d,0,o.size,0);e.end(u===d.byteLength?d:d.subarray(0,u))}else{let d=0,u=Buffer.allocUnsafe(c);for(;d<o.size;){let x=Sr.readSync(i,u,0,c,d);if(x===0)break;d+=x,e.write(u.subarray(0,x))}e.end()}}finally{if(typeof i=="number")try{Sr.closeSync(i)}catch{}}},Jw=(t,e)=>{let n=new Di(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{n.on("error",d),n.on("end",c),Sr.stat(o,(u,x)=>{if(u)d(u);else{let h=new Lc(o,{readSize:i,size:x.size});h.on("error",d),h.pipe(n)}})})},Tr=Oi(Vw,Jw,t=>new Di(t),t=>new Di(t),(t,e)=>{e?.length&&lf(t,e),t.noResume||$w(t)}),uf=(t,e,n)=>(t&=4095,n&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t),{isAbsolute:Yw,parse:Pu}=Zw,Fc=t=>{let e="",n=Pu(t);for(;Yw(t)||n.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":n.root;t=t.slice(i.length),e+=i,n=Pu(t)}return[e,t]},so=["|","<",">","?",":"],zc=so.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),Xw=new Map(so.map((t,e)=>[t,zc[e]])),Qw=new Map(zc.map((t,e)=>[t,so[e]])),Ru=t=>so.reduce((e,n)=>e.split(n).join(Xw.get(n)),t),e_=t=>zc.reduce((e,n)=>e.split(n).join(Qw.get(n)),t),ff=(t,e)=>e?(t=ee(t).replace(/^\.(\/|$)/,""),Ii(e)+"/"+t):ee(t),t_=16*1024*1024,Du=Symbol("process"),Ou=Symbol("file"),Lu=Symbol("directory"),mc=Symbol("symlink"),Nu=Symbol("hardlink"),mi=Symbol("header"),Hs=Symbol("read"),wc=Symbol("lstat"),qs=Symbol("onlstat"),_c=Symbol("onread"),yc=Symbol("onreadlink"),bc=Symbol("openfile"),Ec=Symbol("onopenfile"),yn=Symbol("close"),Qs=Symbol("mode"),vc=Symbol("awaitDrain"),ic=Symbol("ondrain"),Pt=Symbol("prefix"),xf=class extends Kn{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(t,e={}){let n=Nc(e);super(),this.path=ee(t),this.portable=!!n.portable,this.maxReadSize=n.maxReadSize||t_,this.linkCache=n.linkCache||new Map,this.statCache=n.statCache||new Map,this.preservePaths=!!n.preservePaths,this.cwd=ee(n.cwd||process.cwd()),this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.mtime=n.mtime,this.prefix=n.prefix?ee(n.prefix):void 0,this.onWriteEntry=n.onWriteEntry,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let i=!1;if(!this.preservePaths){let[c,d]=Fc(this.path);c&&typeof d=="string"&&(this.path=d,i=c)}this.win32=!!n.win32||process.platform==="win32",this.win32&&(this.path=e_(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=ee(n.absolute||Cu.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[qs](o):this[wc]()}warn(t,e,n={}){return io(this,t,e,n)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[wc](){Ct.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[qs](e)})}[qs](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=i_(t),this.emit("stat",t),this[Du]()}[Du](){switch(this.type){case"File":return this[Ou]();case"Directory":return this[Lu]();case"SymbolicLink":return this[mc]();default:return this.end()}}[Qs](t){return uf(t,this.type==="Directory",this.portable)}[Pt](t){return ff(t,this.prefix)}[mi](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new Wn({path:this[Pt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Pt](this.linkpath):this.linkpath,mode:this[Qs](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new Ys({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[Pt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Pt](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let t=this.header?.block;if(!t)throw new Error("failed to encode header");super.write(t)}[Lu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[mi](),this.end()}[mc](){Ct.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[yc](e)})}[yc](t){this.linkpath=ee(t),this[mi](),this.end()}[Nu](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=ee(Cu.relative(this.cwd,t)),this.stat.size=0,this[mi](),this.end()}[Ou](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){let t=`${this.stat.dev}:${this.stat.ino}`,e=this.linkCache.get(t);if(e?.indexOf(this.cwd)===0)return this[Nu](e);this.linkCache.set(t,this.absolute)}if(this[mi](),this.stat.size===0)return this.end();this[bc]()}[bc](){Ct.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[Ec](e)})}[Ec](t){if(this.fd=t,this.#e)return this[yn]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[Hs]()}[Hs](){let{fd:t,buf:e,offset:n,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,n,i,o,(c,d)=>{if(c)return this[yn](()=>this.emit("error",c));this[_c](d)})}[yn](t=()=>{}){this.fd!==void 0&&Ct.close(this.fd,t)}[_c](t){if(t<=0&&this.remain>0){let n=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[yn](()=>this.emit("error",n))}if(t>this.remain){let n=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[yn](()=>this.emit("error",n))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let n=t;n<this.length&&t<this.blockRemain;n++)this.buf[n+this.offset]=0,t++,this.remain++;let e=this.offset===0&&t===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+t);this.write(e)?this[ic]():this[vc](()=>this[ic]())}[vc](t){this.once("drain",t)}write(t,e,n){if(typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8")),this.blockRemain<t.length){let i=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",i)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,n)}[ic](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[yn](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[Hs]()}},n_=class extends xf{sync=!0;[wc](){this[qs](Ct.lstatSync(this.absolute))}[mc](){this[yc](Ct.readlinkSync(this.absolute))}[bc](){this[Ec](Ct.openSync(this.absolute,"r"))}[Hs](){let t=!0;try{let{fd:e,buf:n,offset:i,length:o,pos:c}=this;if(e===void 0||n===void 0)throw new Error("fd and buf must be set in READ method");let d=Ct.readSync(e,n,i,o,c);this[_c](d),t=!1}finally{if(t)try{this[yn](()=>{})}catch{}}}[vc](t){t()}[yn](t=()=>{}){this.fd!==void 0&&Ct.closeSync(this.fd),t()}},r_=class extends Kn{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,n={}){return io(this,t,e,n)}constructor(t,e={}){let n=Nc(e);super(),this.preservePaths=!!n.preservePaths,this.portable=!!n.portable,this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.onWriteEntry=n.onWriteEntry,this.readEntry=t;let{type:i}=t;if(i==="Unsupported")throw new Error("writing entry that should be ignored");this.type=i,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=n.prefix,this.path=ee(t.path),this.mode=t.mode!==void 0?this[Qs](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:n.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?ee(t.linkpath):void 0,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let o=!1;if(!this.preservePaths){let[d,u]=Fc(this.path);d&&typeof u=="string"&&(this.path=u,o=d)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Wn({path:this[Pt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Pt](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),o&&this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute path`,{entry:this,path:o+this.path}),this.header.encode()&&!this.noPax&&super.write(new Ys({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Pt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Pt](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let c=this.header?.block;if(!c)throw new Error("failed to encode header");super.write(c),t.pipe(this)}[Pt](t){return ff(t,this.prefix)}[Qs](t){return uf(t,this.type==="Directory",this.portable)}write(t,e,n){typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8"));let i=t.length;if(i>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=i,super.write(t,n)}end(t,e,n){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof t=="function"&&(n=t,e=void 0,t=void 0),typeof e=="function"&&(n=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e??"utf8")),n&&this.once("finish",n),t?super.end(t,n):super.end(n),this}},i_=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",s_=class Ir{tail;head;length=0;static create(e=[]){return new Ir(e)}constructor(e=[]){for(let n of e)this.push(n)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let n=e.next,i=e.prev;return n&&(n.prev=i),i&&(i.next=n),e===this.head&&(this.head=n),e===this.tail&&(this.tail=i),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,n}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let n=this.head;e.list=this,e.next=n,n&&(n.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let n=this.tail;e.list=this,e.prev=n,n&&(n.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let n=0,i=e.length;n<i;n++)a_(this,e[n]);return this.length}unshift(...e){for(var n=0,i=e.length;n<i;n++)c_(this,e[n]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,n=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,n.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,n=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,n.list=void 0,this.length--,e}forEach(e,n){n=n||this;for(let i=this.head,o=0;i;o++)e.call(n,i.value,o,this),i=i.next}forEachReverse(e,n){n=n||this;for(let i=this.tail,o=this.length-1;i;o--)e.call(n,i.value,o,this),i=i.prev}get(e){let n=0,i=this.head;for(;i&&n<e;n++)i=i.next;if(n===e&&i)return i.value}getReverse(e){let n=0,i=this.tail;for(;i&&n<e;n++)i=i.prev;if(n===e&&i)return i.value}map(e,n){n=n||this;let i=new Ir;for(let o=this.head;o;)i.push(e.call(n,o.value,this)),o=o.next;return i}mapReverse(e,n){n=n||this;var i=new Ir;for(let o=this.tail;o;)i.push(e.call(n,o.value,this)),o=o.prev;return i}reduce(e,n){let i,o=this.head;if(arguments.length>1)i=n;else if(this.head)o=this.head.next,i=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var c=0;o;c++)i=e(i,o.value,c),o=o.next;return i}reduceReverse(e,n){let i,o=this.tail;if(arguments.length>1)i=n;else if(this.tail)o=this.tail.prev,i=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let c=this.length-1;o;c--)i=e(i,o.value,c),o=o.prev;return i}toArray(){let e=new Array(this.length);for(let n=0,i=this.head;i;n++)e[n]=i.value,i=i.next;return e}toArrayReverse(){let e=new Array(this.length);for(let n=0,i=this.tail;i;n++)e[n]=i.value,i=i.prev;return e}slice(e=0,n=this.length){n<0&&(n+=this.length),e<0&&(e+=this.length);let i=new Ir;if(n<e||n<0)return i;e<0&&(e=0),n>this.length&&(n=this.length);let o=this.head,c=0;for(c=0;o&&c<e;c++)o=o.next;for(;o&&c<n;c++,o=o.next)i.push(o.value);return i}sliceReverse(e=0,n=this.length){n<0&&(n+=this.length),e<0&&(e+=this.length);let i=new Ir;if(n<e||n<0)return i;e<0&&(e=0),n>this.length&&(n=this.length);let o=this.length,c=this.tail;for(;c&&o>n;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,n=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let d=0;o&&d<e;d++)o=o.next;let c=[];for(let d=0;o&&d<n;d++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let d of i)o=o_(this,o,d);return c}reverse(){let e=this.head,n=this.tail;for(let i=e;i;i=i.prev){let o=i.prev;i.prev=i.next,i.next=o}return this.head=n,this.tail=e,this}};function o_(t,e,n){let i=e,o=e?e.next:t.head,c=new Uc(n,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function a_(t,e){t.tail=new Uc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function c_(t,e){t.head=new Uc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Uc=class{list;next;prev;value;constructor(t,e,n,i){this.list=i,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,n?(n.prev=this,this.next=n):this.next=void 0}},Bu=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Fu=Buffer.alloc(1024),Ws=Symbol("onStat"),wi=Symbol("ended"),_t=Symbol("queue"),_i=Symbol("pendingLinks"),gn=Symbol("current"),Gn=Symbol("process"),yi=Symbol("processing"),Fs=Symbol("processJob"),yt=Symbol("jobs"),sc=Symbol("jobDone"),Ks=Symbol("addFSEntry"),zu=Symbol("addTarEntry"),Sc=Symbol("stat"),Ic=Symbol("readdir"),$s=Symbol("onreaddir"),Vs=Symbol("pipe"),Uu=Symbol("entry"),oc=Symbol("entryOpt"),Js=Symbol("writeEntryClass"),hf=Symbol("write"),ac=Symbol("ondrain"),oo=class extends Kn{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Js];onWriteEntry;[_t];[_i]=new Map;[yt]=0;[yi]=!1;[wi]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=ee(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[Js]=xf,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 pw(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new mw(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new _w(t.zstd)),!this.zip)throw new Error("impossible");let e=this.zip;e.on("data",n=>super.write(n)),e.on("end",()=>super.end()),e.on("drain",()=>this[ac]()),this.on("resume",()=>e.resume())}else this.on("drain",this[ac]);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[_t]=new s_,this[yt]=0,this.jobs=Number(t.jobs)||4,this[yi]=!1,this[wi]=!1}[hf](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,n){return typeof t=="function"&&(n=t,t=void 0),typeof e=="function"&&(n=e,e=void 0),t&&this.add(t),this[wi]=!0,this[Gn](),n&&n(),this}write(t){if(this[wi])throw new Error("write after end");return typeof t=="string"?this[Ks](t):this[zu](t),this.flowing}[zu](t){let e=ee(Mu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let n=new Bu(t.path,e);n.entry=new r_(t,this[oc](n)),n.entry.on("end",()=>this[sc](n)),this[yt]+=1,this[_t].push(n)}this[Gn]()}[Ks](t){let e=ee(Mu.resolve(this.cwd,t));this[_t].push(new Bu(t,e)),this[Gn]()}[Sc](t){t.pending=!0,this[yt]+=1;let e=this.follow?"stat":"lstat";Xs[e](t.absolute,(n,i)=>{t.pending=!1,this[yt]-=1,n?this.emit("error",n):this[Ws](t,i)})}[Ws](t,e){if(this.statCache.set(t.absolute,e),t.stat=e,!this.filter(t.path,e))t.ignore=!0;else if(e.isFile()&&e.nlink>1&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync)if(t===this[gn])this[Fs](t);else{let n=`${e.dev}:${e.ino}`,i=this[_i].get(n);i?i.push(t):this[_i].set(n,[t]),t.pendingLink=!0,t.pending=!0}this[Gn]()}[Ic](t){t.pending=!0,this[yt]+=1,Xs.readdir(t.absolute,(e,n)=>{if(t.pending=!1,this[yt]-=1,e)return this.emit("error",e);this[$s](t,n)})}[$s](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Gn]()}[Gn](){if(!this[yi]){this[yi]=!0;for(let t=this[_t].head;t&&this[yt]<this.jobs;t=t.next)if(this[Fs](t.value),t.value.ignore){let e=t.next;this[_t].removeNode(t),t.next=e}this[yi]=!1,this[wi]&&this[_t].length===0&&this[yt]===0&&(this.zip?this.zip.end(Fu):(super.write(Fu),super.end()))}}get[gn](){return this[_t]&&this[_t].head&&this[_t].head.value}[sc](t){this[_t].shift(),this[yt]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let n=`${e.dev}:${e.ino}`,i=this[_i].get(n);if(i){this[_i].delete(n);for(let o of i)o.pending=!1,this[Fs](o)}}this[Gn]()}[Fs](t){if(t.pending&&t.pendingLink&&t===this[gn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[gn]&&!t.piped&&this[Vs](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Ws](t,e):this[Sc](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[$s](t,e):this[Ic](t),!t.readdir)return}if(t.entry=this[Uu](t),!t.entry){t.ignore=!0;return}t===this[gn]&&!t.piped&&this[Vs](t)}}}[oc](t){return{onwarn:(e,n,i)=>this.warn(e,n,i),noPax:this.noPax,cwd:this.cwd,absolute:t.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[Uu](t){this[yt]+=1;try{return new this[Js](t.path,this[oc](t)).on("end",()=>this[sc](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[ac](){this[gn]&&this[gn].entry&&this[gn].entry.resume()}[Vs](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ks](c+i)});let e=t.entry,n=this.zip;if(!e)throw new Error("cannot pipe without source");n?e.on("data",i=>{n.write(i)||e.pause()}):e.on("data",i=>{super.write(i)||e.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(t,e,n={}){io(this,t,e,n)}},Gc=class extends oo{sync=!0;constructor(t){super(t),this[Js]=n_}pause(){}resume(){}[Sc](t){let e=this.follow?"statSync":"lstatSync";this[Ws](t,Xs[e](t.absolute))}[Ic](t){this[$s](t,Xs.readdirSync(t.absolute))}[Vs](t){let e=t.entry,n=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ks](c+i)}),!e)throw new Error("Cannot pipe without source");n?e.on("data",i=>{n.write(i)}):e.on("data",i=>{super[hf](i)})}},d_=(t,e)=>{let n=new Gc(t),i=new ef(t.file,{mode:t.mode||438});n.pipe(i),pf(n,e)},l_=(t,e)=>{let n=new oo(t),i=new no(t.file,{mode:t.mode||438});n.pipe(i);let o=new Promise((c,d)=>{i.on("error",d),i.on("close",c),n.on("error",d)});return gf(n,e).catch(c=>n.emit("error",c)),o},pf=(t,e)=>{e.forEach(n=>{n.charAt(0)==="@"?Tr({file:tf.resolve(t.cwd,n.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n)}),t.end()},gf=async(t,e)=>{for(let n of e)n.charAt(0)==="@"?await Tr({file:tf.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(n);t.end()},u_=(t,e)=>{let n=new Gc(t);return pf(n,e),n},f_=(t,e)=>{let n=new oo(t);return gf(n,e).catch(i=>n.emit("error",i)),n},GA=Oi(d_,l_,u_,f_,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),h_=process.env.__FAKE_PLATFORM__||process.platform,yf=h_==="win32",{O_CREAT:bf,O_NOFOLLOW:Gu,O_TRUNC:Ef,O_WRONLY:vf}=_f.constants,Sf=Number(process.env.__FAKE_FS_O_FILENAME__)||_f.constants.UV_FS_O_FILEMAP||0,p_=yf&&!!Sf,g_=512*1024,m_=Sf|Ef|bf|vf,ju=!yf&&typeof Gu=="number"?Gu|Ef|bf|vf:null,If=ju!==null?()=>ju:p_?t=>t<g_?m_:"w":()=>"w",Ac=(t,e,n)=>{try{return ao.lchownSync(t,e,n)}catch(i){if(i?.code!=="ENOENT")throw i}},eo=(t,e,n,i)=>{ao.lchown(t,e,n,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},w_=(t,e,n,i,o)=>{if(e.isDirectory())Af(Ai.resolve(t,e.name),n,i,c=>{if(c)return o(c);let d=Ai.resolve(t,e.name);eo(d,n,i,o)});else{let c=Ai.resolve(t,e.name);eo(c,n,i,o)}},Af=(t,e,n,i)=>{ao.readdir(t,{withFileTypes:!0},(o,c)=>{if(o){if(o.code==="ENOENT")return i();if(o.code!=="ENOTDIR"&&o.code!=="ENOTSUP")return i(o)}if(o||!c.length)return eo(t,e,n,i);let d=c.length,u=null,x=h=>{if(!u){if(h)return i(u=h);if(--d===0)return eo(t,e,n,i)}};for(let h of c)w_(t,h,e,n,x)})},__=(t,e,n,i)=>{e.isDirectory()&&kf(Ai.resolve(t,e.name),n,i),Ac(Ai.resolve(t,e.name),n,i)},kf=(t,e,n)=>{let i;try{i=ao.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return Ac(t,e,n);throw c}for(let o of i)__(t,o,e,n);return Ac(t,e,n)},Tf=class extends Error{path;code;syscall="chdir";constructor(t,e){super(`${e}: Cannot cd into '${t}'`),this.path=t,this.code=e}get name(){return"CwdError"}},co=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(t,e){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=t,this.path=e}get name(){return"SymlinkError"}},b_=(t,e)=>{ct.stat(t,(n,i)=>{(n||!i.isDirectory())&&(n=new Tf(t,n?.code||"ENOTDIR")),e(n)})},E_=(t,e,n)=>{t=ee(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,d=e.uid,u=e.gid,x=typeof d=="number"&&typeof u=="number"&&(d!==e.processUid||u!==e.processGid),h=e.preserve,g=e.unlink,w=ee(e.cwd),v=(E,I)=>{E?n(E):I&&x?Af(I,d,u,A=>v(A)):c?ct.chmod(t,o,n):n()};if(t===w)return b_(t,v);if(h)return y_.mkdir(t,{mode:o,recursive:!0}).then(E=>v(null,E??void 0),v);let _=ee(to.relative(w,t)).split("/");kc(w,_,o,g,w,void 0,v)},kc=(t,e,n,i,o,c,d)=>{if(e.length===0)return d(null,c);let u=e.shift(),x=ee(to.resolve(t+"/"+u));ct.mkdir(x,n,Cf(x,e,n,i,o,c,d))},Cf=(t,e,n,i,o,c,d)=>u=>{u?ct.lstat(t,(x,h)=>{if(x)x.path=x.path&&ee(x.path),d(x);else if(h.isDirectory())kc(t,e,n,i,o,c,d);else if(i)ct.unlink(t,g=>{if(g)return d(g);ct.mkdir(t,n,Cf(t,e,n,i,o,c,d))});else{if(h.isSymbolicLink())return d(new co(t,t+"/"+e.join("/")));d(u)}}):(c=c||t,kc(t,e,n,i,o,c,d))},v_=t=>{let e=!1,n;try{e=ct.statSync(t).isDirectory()}catch(i){n=i?.code}finally{if(!e)throw new Tf(t,n??"ENOTDIR")}},S_=(t,e)=>{t=ee(t);let n=e.umask??18,i=e.mode|448,o=(i&n)!==0,c=e.uid,d=e.gid,u=typeof c=="number"&&typeof d=="number"&&(c!==e.processUid||d!==e.processGid),x=e.preserve,h=e.unlink,g=ee(e.cwd),w=E=>{E&&u&&kf(E,c,d),o&&ct.chmodSync(t,i)};if(t===g)return v_(g),w();if(x)return w(ct.mkdirSync(t,{mode:i,recursive:!0})??void 0);let v=ee(to.relative(g,t)).split("/"),_;for(let E=v.shift(),I=g;E&&(I+="/"+E);E=v.shift()){I=ee(to.resolve(I));try{ct.mkdirSync(I,i),_=_||I}catch{let A=ct.lstatSync(I);if(A.isDirectory())continue;if(h){ct.unlinkSync(I),ct.mkdirSync(I,i),_=_||I;continue}else if(A.isSymbolicLink())return new co(I,I+"/"+v.join("/"))}}return w(_)},cc=Object.create(null),Hu=1e4,_r=new Set,I_=t=>{_r.has(t)?_r.delete(t):cc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),_r.add(t);let e=cc[t],n=_r.size-Hu;if(n>Hu/10){for(let i of _r)if(_r.delete(i),delete cc[i],--n<=0)break}return e},A_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,k_=A_==="win32",T_=t=>t.split("/").slice(0,-1).reduce((e,n)=>{let i=e.at(-1);return i!==void 0&&(n=Pf(i,n)),e.push(n||"/"),e},[]),C_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=k_?["win32 parallelization disabled"]:t.map(i=>Ii(Pf(I_(i))));let n=new Set(t.map(i=>T_(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:n,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of n){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(n=>this.#e.get(n)),dirs:[...e.dirs].map(n=>this.#e.get(n))}}check(t){let{paths:e,dirs:n}=this.#s(t);return e.every(i=>i&&i[0]===t)&&n.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:n,dirs:i}=e,o=new Set;for(let c of n){let d=this.#e.get(c);if(!d||d?.[0]!==t)continue;let u=d[1];if(!u){this.#e.delete(c);continue}if(d.shift(),typeof u=="function")o.add(u);else for(let x of u)o.add(x)}for(let c of i){let d=this.#e.get(c),u=d?.[0];if(!(!d||!(u instanceof Set)))if(u.size===1&&d.length===1){this.#e.delete(c);continue}else if(u.size===1){d.shift();let x=d[0];typeof x=="function"&&o.add(x)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},P_=()=>process.umask(),qu=Symbol("onEntry"),Tc=Symbol("checkFs"),Wu=Symbol("checkFs2"),Cc=Symbol("isReusable"),ft=Symbol("makeFs"),Pc=Symbol("file"),Rc=Symbol("directory"),Zs=Symbol("link"),Ku=Symbol("symlink"),$u=Symbol("hardlink"),vi=Symbol("ensureNoSymlink"),Vu=Symbol("unsupported"),Ju=Symbol("checkPath"),dc=Symbol("stripAbsolutePath"),bn=Symbol("mkdir"),qe=Symbol("onError"),zs=Symbol("pending"),Zu=Symbol("pend"),yr=Symbol("unpend"),lc=Symbol("ended"),uc=Symbol("maybeClose"),Dc=Symbol("skip"),ki=Symbol("doChown"),Ti=Symbol("uid"),Ci=Symbol("gid"),Pi=Symbol("checkedCwd"),R_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Ri=R_==="win32",D_=1024,O_=(t,e)=>{if(!Ri)return oe.unlink(t,e);let n=t+".DELETE."+wf(16).toString("hex");oe.rename(t,n,i=>{if(i)return e(i);oe.unlink(n,e)})},L_=t=>{if(!Ri)return oe.unlinkSync(t);let e=t+".DELETE."+wf(16).toString("hex");oe.renameSync(t,e),oe.unlinkSync(e)},Yu=(t,e,n)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:n,jc=class extends Di{[lc]=!1;[Pi]=!1;[zs]=0;reservations=new C_;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[lc]=!0,this[uc]()},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:D_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Ri,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=ee(Fe.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:P_():0,this.umask=typeof t.umask=="number"?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.on("entry",e=>this[qu](e))}warn(t,e,n={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(n.recoverable=!1),super.warn(t,e,n)}[uc](){this[lc]&&this[zs]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[dc](t,e){let n=t[e],{type:i}=t;if(!n||this.preservePaths)return!0;let[o,c]=Fc(n),d=c.replaceAll(/\\/g,"/").split("/");if(d.includes("..")||Ri&&/^[a-z]:\.\.$/i.test(d[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:n}),!1;let u=Fe.posix.dirname(t.path),x=Fe.posix.normalize(Fe.posix.join(u,d.join("/")));if(x.startsWith("../")||x==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:n}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:n})),!0}[Ju](t){let e=ee(t.path),n=e.split("/");if(this.strip){if(n.length<this.strip)return!1;if(t.type==="Link"){let i=ee(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}n.splice(0,this.strip),t.path=n.join("/")}if(isFinite(this.maxDepth)&&n.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:n.length,maxDepth:this.maxDepth}),!1;if(!this[dc](t,"path")||!this[dc](t,"linkpath"))return!1;if(t.absolute=Fe.isAbsolute(t.path)?ee(Fe.resolve(t.path)):ee(Fe.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:ee(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}=Fe.win32.parse(String(t.absolute));t.absolute=i+Ru(String(t.absolute).slice(i.length));let{root:o}=Fe.win32.parse(t.path);t.path=o+Ru(t.path.slice(o.length))}return!0}[qu](t){if(!this[Ju](t))return t.resume();switch(x_.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[Tc](t);default:return this[Vu](t)}}[qe](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[yr](),e.resume())}[bn](t,e,n){E_(ee(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},n)}[ki](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}[Ti](t){return Yu(this.uid,t.uid,this.processUid)}[Ci](t){return Yu(this.gid,t.gid,this.processGid)}[Pc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new no(String(t.absolute),{flags:If(t.size),mode:n,autoClose:!1});i.on("error",u=>{i.fd&&oe.close(i.fd,()=>{}),i.write=()=>!0,this[qe](u,t),e()});let o=1,c=u=>{if(u){i.fd&&oe.close(i.fd,()=>{}),this[qe](u,t),e();return}--o===0&&i.fd!==void 0&&oe.close(i.fd,x=>{x?this[qe](x,t):this[yr](),e()})};i.on("finish",()=>{let u=String(t.absolute),x=i.fd;if(typeof x=="number"&&t.mtime&&!this.noMtime){o++;let h=t.atime||new Date,g=t.mtime;oe.futimes(x,h,g,w=>w?oe.utimes(u,h,g,v=>c(v&&w)):c())}if(typeof x=="number"&&this[ki](t)){o++;let h=this[Ti](t),g=this[Ci](t);typeof h=="number"&&typeof g=="number"&&oe.fchown(x,h,g,w=>w?oe.chown(u,h,g,v=>c(v&&w)):c())}c()});let d=this.transform&&this.transform(t)||t;d!==t&&(d.on("error",u=>{this[qe](u,t),e()}),t.pipe(d)),d.pipe(i)}[Rc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.dmode;this[bn](String(t.absolute),n,i=>{if(i){this[qe](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[yr](),t.resume())};t.mtime&&!this.noMtime&&(o++,oe.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[ki](t)&&(o++,oe.chown(String(t.absolute),Number(this[Ti](t)),Number(this[Ci](t)),c)),c()})}[Vu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Ku](t,e){let n=ee(Fe.relative(this.cwd,Fe.resolve(Fe.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[vi](t,this.cwd,n,()=>this[Zs](t,String(t.linkpath),"symlink",e),i=>{this[qe](i,t),e()})}[$u](t,e){let n=ee(Fe.resolve(this.cwd,String(t.linkpath))),i=ee(String(t.linkpath)).split("/");this[vi](t,this.cwd,i,()=>this[Zs](t,n,"link",e),o=>{this[qe](o,t),e()})}[vi](t,e,n,i,o){let c=n.shift();if(this.preservePaths||c===void 0)return i();let d=Fe.resolve(e,c);oe.lstat(d,(u,x)=>{if(u)return i();if(x?.isSymbolicLink())return o(new co(d,Fe.resolve(d,n.join("/"))));this[vi](t,d,n,i,o)})}[Zu](){this[zs]++}[yr](){this[zs]--,this[uc]()}[Dc](t){this[yr](),t.resume()}[Cc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Ri}[Tc](t){this[Zu]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,n=>this[Wu](t,n))}[Wu](t,e){let n=d=>{e(d)},i=()=>{this[bn](this.cwd,this.dmode,d=>{if(d){this[qe](d,t),n();return}this[Pi]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let d=ee(Fe.dirname(String(t.absolute)));if(d!==this.cwd)return this[bn](d,this.dmode,u=>{if(u){this[qe](u,t),n();return}c()})}c()},c=()=>{oe.lstat(String(t.absolute),(d,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Dc](t),n();return}if(d||this[Cc](t,u))return this[ft](null,t,n);if(u.isDirectory()){if(t.type==="Directory"){let x=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,h=g=>this[ft](g??null,t,n);return x?oe.chmod(String(t.absolute),Number(t.mode),h):h()}if(t.absolute!==this.cwd)return oe.rmdir(String(t.absolute),x=>this[ft](x??null,t,n))}if(t.absolute===this.cwd)return this[ft](null,t,n);O_(String(t.absolute),x=>this[ft](x??null,t,n))})};this[Pi]?o():i()}[ft](t,e,n){if(t){this[qe](t,e),n();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[Pc](e,n);case"Link":return this[$u](e,n);case"SymbolicLink":return this[Ku](e,n);case"Directory":case"GNUDumpDir":return this[Rc](e,n)}}[Zs](t,e,n,i){oe[n](e,String(t.absolute),o=>{o?this[qe](o,t):(this[yr](),t.resume()),i()})}},bi=t=>{try{return[null,t()]}catch(e){return[e,null]}},Rf=class extends jc{sync=!0;[ft](t,e){return super[ft](t,e,()=>{})}[Tc](t){if(!this[Pi]){let o=this[bn](this.cwd,this.dmode);if(o)return this[qe](o,t);this[Pi]=!0}if(t.absolute!==this.cwd){let o=ee(Fe.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[bn](o,this.dmode);if(c)return this[qe](c,t)}}let[e,n]=bi(()=>oe.lstatSync(String(t.absolute)));if(n&&(this.keep||this.newer&&n.mtime>(t.mtime??n.mtime)))return this[Dc](t);if(e||this[Cc](t,n))return this[ft](null,t);if(n.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(n.mode&4095)!==t.mode,[d]=c?bi(()=>{oe.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[ft](d,t)}let[o]=bi(()=>oe.rmdirSync(String(t.absolute)));this[ft](o,t)}let[i]=t.absolute===this.cwd?[]:bi(()=>L_(String(t.absolute)));this[ft](i,t)}[Pc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.fmode,i=d=>{let u;try{oe.closeSync(o)}catch(x){u=x}(d||u)&&this[qe](d||u,t),e()},o;try{o=oe.openSync(String(t.absolute),If(t.size),n)}catch(d){return i(d)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",d=>this[qe](d,t)),t.pipe(c)),c.on("data",d=>{try{oe.writeSync(o,d,0,d.length)}catch(u){i(u)}}),c.on("end",()=>{let d=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,x=t.mtime;try{oe.futimesSync(o,u,x)}catch(h){try{oe.utimesSync(String(t.absolute),u,x)}catch{d=h}}}if(this[ki](t)){let u=this[Ti](t),x=this[Ci](t);try{oe.fchownSync(o,Number(u),Number(x))}catch(h){try{oe.chownSync(String(t.absolute),Number(u),Number(x))}catch{d=d||h}}}i(d)})}[Rc](t,e){let n=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[bn](String(t.absolute),n);if(i){this[qe](i,t),e();return}if(t.mtime&&!this.noMtime)try{oe.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[ki](t))try{oe.chownSync(String(t.absolute),Number(this[Ti](t)),Number(this[Ci](t)))}catch{}e(),t.resume()}[bn](t,e){try{return S_(ee(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(n){return n}}[vi](t,e,n,i,o){if(this.preservePaths||n.length===0)return i();let c=e;for(let d of n){c=Fe.resolve(c,d);let[u,x]=bi(()=>oe.lstatSync(c));if(u)return i();if(x.isSymbolicLink())return o(new co(c,Fe.resolve(e,n.join("/"))))}i()}[Zs](t,e,n,i){let o=`${n}Sync`;try{oe[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[qe](c,t)}}},N_=t=>{let e=new Rf(t),n=t.file,i=mf.statSync(n),o=t.maxReadSize||16*1024*1024;new ew(n,{readSize:o,size:i.size}).pipe(e)},M_=(t,e)=>{let n=new jc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{n.on("error",d),n.on("close",c),mf.stat(o,(u,x)=>{if(u)d(u);else{let h=new Lc(o,{readSize:i,size:x.size});h.on("error",d),h.pipe(n)}})})},Df=Oi(N_,M_,t=>new Rf(t),t=>new jc(t),(t,e)=>{e?.length&&lf(t,e)}),B_=(t,e)=>{let n=new Gc(t),i=!0,o,c;try{try{o=at.openSync(t.file,"r+")}catch(x){if(x?.code==="ENOENT")o=at.openSync(t.file,"w+");else throw x}let d=at.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<d.size;c+=512){for(let g=0,w=0;g<512;g+=w){if(w=at.readSync(o,u,g,u.length-g,c+g),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!w)break e}let x=new Wn(u);if(!x.cksumValid)break;let h=512*Math.ceil((x.size||0)/512);if(c+h+512>d.size)break;c+=h,t.mtimeCache&&x.mtime&&t.mtimeCache.set(String(x.path),x.mtime)}i=!1,F_(t,n,c,o,e)}finally{if(i)try{at.closeSync(o)}catch{}}},F_=(t,e,n,i,o)=>{let c=new ef(t.file,{fd:i,start:n});e.pipe(c),U_(e,o)},z_=(t,e)=>{e=Array.from(e);let n=new oo(t),i=(o,c,d)=>{let u=(v,_)=>{v?at.close(o,E=>d(v)):d(null,_)},x=0;if(c===0)return u(null,0);let h=0,g=Buffer.alloc(512),w=(v,_)=>{if(v||_===void 0)return u(v);if(h+=_,h<512&&_)return at.read(o,g,h,g.length-h,x+h,w);if(x===0&&g[0]===31&&g[1]===139)return u(new Error("cannot append to compressed archives"));if(h<512)return u(null,x);let E=new Wn(g);if(!E.cksumValid)return u(null,x);let I=512*Math.ceil((E.size??0)/512);if(x+I+512>c||(x+=I+512,x>=c))return u(null,x);t.mtimeCache&&E.mtime&&t.mtimeCache.set(String(E.path),E.mtime),h=0,at.read(o,g,0,512,x,w)};at.read(o,g,0,512,x,w)};return new Promise((o,c)=>{n.on("error",c);let d="r+",u=(x,h)=>{if(x&&x.code==="ENOENT"&&d==="r+")return d="w+",at.open(t.file,d,u);if(x||!h)return c(x);at.fstat(h,(g,w)=>{if(g)return at.close(h,()=>c(g));i(h,w.size,(v,_)=>{if(v)return c(v);let E=new no(t.file,{fd:h,start:_});n.pipe(E),E.on("error",c),E.on("close",o),G_(n,e)})})};at.open(t.file,d,u)})},U_=(t,e)=>{e.forEach(n=>{n.charAt(0)==="@"?Tr({file:Of.resolve(t.cwd,n.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n)}),t.end()},G_=async(t,e)=>{for(let n of e)n.charAt(0)==="@"?await Tr({file:Of.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(n);t.end()},Ei=Oi(B_,z_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!cw(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")}),n2=Oi(Ei.syncFile,Ei.asyncFile,Ei.syncNoFile,Ei.asyncNoFile,(t,e=[])=>{Ei.validate?.(t,e),j_(t)}),j_=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(n,i)=>e(n,i)&&!((t.mtimeCache?.get(n)??i.mtime??0)>(i.mtime??0)):(n,i)=>!((t.mtimeCache?.get(n)??i.mtime??0)>(i.mtime??0))};ln();var xt={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",UPGRADE:"_agent/upgrade",DELETE:"_agent/delete",PUBLISH_SKILL:"_agent/publishSkill"};function lo(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function Lf(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function uo(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Nf(t){let e=t?.permissionMode;if(typeof e!="string")return;let n=e.trim();return n===""?void 0:n}function Mf(t){let{_meta:e,...n}=t;return{stripped:n,meta:e}}function $n(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Vt();$e();ie();Me();$e();function Cr(t,e){if(lo(t)!=="cloud")throw new k("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Li(t){return t.startsWith("http://")||t.startsWith("https://")}function Pr(t){return t.endsWith("/")?t.slice(0,-1):t}import{readFileSync as $2}from"node:fs";import{dirname as J2,join as Z2}from"node:path";import{fileURLToPath as X2}from"node:url";var Dt="0.2.4-beta.2";$e();ie();var fo="1008033",Uf="1289";var Gf="pbbp2",jf="https://www.coze.cn",Hf="/api/coze_claw/resource/get_frontier_key",Z_="https://www.coze.cn",Y_="wss://frontier.coze.cn";function Rr(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??Z_}function qf(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??Y_}function Sn(t){let e={},n=t?.ttEnv??process.env.COZE_BRIDGE_TT_ENV,i=t?.usePpe??process.env.COZE_BRIDGE_USE_PPE;return n&&(e["x-tt-env"]=n),i&&(e["x-use-ppe"]=i),e}function Mi(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Ni=K("handshake");async function Hc(t){let e=Rr(t.endpoint),n=t.timeoutMs??1e4,i=`${Pr(e)}${Hf}?aid=${encodeURIComponent(fo)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...Sn(t.ppeOverride)},c=new AbortController,d=setTimeout(()=>c.abort(),n);Ni.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 E=await u.text().catch(()=>"");throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${x}: ${E.slice(0,200)}`)}let g=await u.json();if(g.code!==void 0&&g.code!==0)throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${g.code} msg=${g.msg??"-"} logid=${x}`);let w=g.data??{},v=typeof w.access_key=="string"&&w.access_key||typeof w.accessKey=="string"&&w.accessKey||void 0,_=typeof w.device_id=="string"&&w.device_id||typeof w.deviceId=="string"&&w.deviceId||void 0;if(!v||!_){let E=JSON.stringify(g).slice(0,500);throw new k("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${x}: ${E}`)}return Ni.info("handshake ok",{remoteDeviceId:_,logid:x,traceId:h}),{accessKey:v,deviceId:_}}catch(u){if(u instanceof k)throw Ni.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Ni.warn("handshake timeout",{base:e,timeoutMs:n}),new k("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${n}ms)`,{cause:u});let x=u.cause;throw Ni.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(d)}}var Wc=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",Ot="auto",qc=15e4,Wf=8192;function $f(t){return{model:Kc(t.model)??Ot,...t.modelToken?{modelToken:t.modelToken}:{}}}function Vf(t){return!t||t===Ot}var X_=new Set(["auto","\u81EA\u52A8"]);function Kc(t){let e=t?.trim();if(e)return X_.has(e.toLowerCase())?Ot:e}function Jf(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=Wc,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let n=t.model||Ot;e.ANTHROPIC_MODEL=n,e.ANTHROPIC_SMALL_FAST_MODEL=n,e.ANTHROPIC_DEFAULT_HAIKU_MODEL=n,e.ANTHROPIC_DEFAULT_OPUS_MODEL=n,e.ANTHROPIC_DEFAULT_SONNET_MODEL=n,e.CLAUDE_CODE_SUBAGENT_MODEL=n,e.CLAUDE_CODE_ATTRIBUTION_HEADER="0",t.modelInfo?.contextWindow&&(e.CLAUDE_CODE_MAX_CONTEXT_TOKENS=String(t.modelInfo.contextWindow)),t.modelInfo?.maxOutput&&(e.CLAUDE_CODE_MAX_OUTPUT_TOKENS=String(t.modelInfo.maxOutput))}else Vf(t.model)||(e.ANTHROPIC_MODEL=t.model);return e}function Zf(t,e,n){let i={};if(t.modelToken?i.model=t.model||Ot:Vf(t.model)||(i.model=t.model),t.modelToken){let o={name:"coze",base_url:`${Wc}/v1`,env_key:"CODEX_API_KEY",wire_api:"responses",requires_openai_auth:!1,supports_websockets:!1},c=$c(e,n);Object.keys(c).length>0&&(o.http_headers=c),i.model_providers={coze:o},i.model_context_window=t.modelInfo?.contextWindow??qc}return Object.keys(i).length===0?{}:{CODEX_CONFIG:JSON.stringify(i),...t.modelToken?{MODEL_PROVIDER:"coze"}:{}}}function Yf(t){return t.modelToken?{CODEX_API_KEY:t.modelToken,OPENAI_API_KEY:t.modelToken}:{}}function $c(t,e){let{ttEnv:n,usePpe:i}=Mi(t),o={};return n&&(o["x-tt-env"]=n),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function Xf(t,e,n){if(!t.modelToken)return{};let i=$c(e,n);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,d])=>`${c}:${d}`).join(`
|
|
92
|
-
`)}}function Vc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function Jc(t){return t.model||Ot}function Kf(t,e,n,i){return{id:t,name:t,reasoning:!1,input:e,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:n,maxTokens:i,api:"openai-completions"}}function Qf(t,e,n,i){if(!t.modelToken)return null;let o=Jc(t),c=$c(e,n),d=["text"];t.modelInfo?.capabilities?.image===!0&&d.push("image");let u=[Kf(o,d,t.modelInfo?.contextWindow??qc,t.modelInfo?.maxOutput??Wf)],x=new Set([o]);for(let g of i??[])!g||x.has(g)||(x.add(g),u.push(Kf(g,["text"],qc,Wf)));let h={baseUrl:`${Wc}/v1`,api:"openai-completions",apiKey:t.modelToken,models:u};return Object.keys(c).length>0&&(h.headers=c),h}var pe=K("agent-handlers"),t0=5*1024*1024,ry=1,iy=6,sy=new Set(["node_modules",".git",".coze","dist","build",".next"]),oy=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,ay=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,cy=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function dy(t){let e=t?.trim();return e?cy.test(e)||ay.test(e)?e:(pe.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function ly(t){return new Promise((e,n)=>{let i=st("npx",t,{detached:!0,stdio:"ignore",windowsHide:!0}),o=!1,c=d=>{o||(o=!0,d?n(d):e(i.pid??0))};i.once("spawn",()=>{i.unref(),c()}),i.once("error",d=>c(d))})}var ho=class{constructor(e){this.opts=e}opts;async listSkills(e){e._meta;let n=$n(e._meta),i=await this.loadAgentCfg(n),o=i?.workspace??Ze(n).workspace,c=i?.skills??[],d=[],u=new Set;for(let x of c){let h=ge(o,x.relPath,"SKILL.md");await nd(h).then(w=>w.isFile()).catch(()=>!1)&&(d.push(py(x)),u.add(x.relPath))}if(e.scanLocal){let x=i?.framework??"claude-code",h=await f0(n,o,x),g=await x0(n,x);for(let w of[...h,...g])u.has(w.relPath)||(u.add(w.relPath),d.push(w.skill))}return{skills:d}}async addSkills(e){e._meta;let n=$n(e._meta),i=await this.requireAgentCfg(n),o=e.skills??[],c=[...i.skills??[]],d=new Map(c.map((x,h)=>[x.skillId,h])),u=[];for(let x of o){let h=await po({agentId:n,workspace:i.workspace,framework:i.framework,skill:x});go(c,d,h),u.push(x)}return await ai(n,c),this.reloadAgentSessions(n,"skills-added"),{installedSkills:u}}async removeSkills(e){e._meta;let n=$n(e._meta),i=await this.requireAgentCfg(n),o=new Set(e.skillIds??[]),c=i.skills??[],d=[];for(let u of c){if(!o.has(u.skillId)){d.push(u);continue}let x=ge(i.workspace,u.relPath);await Xc(x,{recursive:!0,force:!0}),pe.info("skill removed",{agentId:n,skillId:u.skillId,relPath:u.relPath})}return await ai(n,d),this.reloadAgentSessions(n,"skills-removed"),{ok:!0}}async publishSkill(e){e._meta;let n=$n(e._meta);if(!e.skillName)throw new k("IPC_BAD_REQUEST","_agent/publishSkill: missing skillName");pe.info("_agent/publishSkill start",{agentId:n,skillId:e.skillId??"",skillName:e.skillName,userId:e.userId??"",accountId:e.accountId??""});let i=await this.loadAgentCfg(n),o=i?.workspace??Ze(n).workspace,c=i?.framework??"claude-code",d=e.isGlobal??!1,u=await fy(n,o,c,e.skillName,d);if(!u){let R=d?"global":"workspace";throw new k("SKILL_NOT_FOUND",`skill not found in ${R}: ${e.skillName}`)}let{absDir:x,relPath:h,dirName:g}=u,w=ge(x,"SKILL.md"),v=new id.default;v.addLocalFolder(x,g);let _=v.toBuffer();if(_.length>n0)throw new k("SKILL_ZIP_TOO_LARGE",`skill zip ${_.length} bytes exceeds limit ${n0}`);let E=await xo(w,{encoding:"utf8"}).then(R=>l0(R).description).catch(()=>{}),I={};this.opts.publishSkillToMarketplace?I=await this.opts.publishSkillToMarketplace({zip:_,...e.skillId?{skillId:e.skillId}:{},skillName:e.skillName,...E?{description:E}:{},agentId:n,...e.userId?{userId:e.userId}:{},...e.accountId?{accountId:e.accountId}:{}}):pe.warn("_agent/publishSkill: publishSkillToMarketplace not injected, skip upload",{agentId:n,skillName:e.skillName});let A=I.version??"v1.0",T=I.skillId??e.skillId??d0(n,h);if(i&&!d){let R=i.skills??[],y=R.find(C=>C.relPath===h);y?(y.version=A,y.skillId=T):R.push({skillId:T,skillName:e.skillName,relPath:h,version:A,installedAt:Date.now(),...E?{description:E}:{}}),await ai(n,R)}return pe.info("skill published",{agentId:n,skillName:e.skillName,relPath:h,zipBytes:_.length,skillId:T,version:A}),{ok:!0,skillId:T,version:A}}reloadAgentSessionsPublic(e,n){this.reloadAgentSessions(e,n)}reloadAgentSessions(e,n){let i=this.opts.agents.get(e);if(i)for(let[o,c]of i.sessions){if(!c.downstream)continue;let d=c.acpSessionId;if(d&&i.activeTriggers.has(d)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,pe.info("downstream busy, scheduling reload after turn",{reason:n,agentId:e,framework:i.framework,cloudId:o,acpId:d});continue}let x=c.downstream;c.downstream=void 0,pe.info("killing downstream for workspace reload (idle)",{reason:n,agentId:e,framework:i.framework,cloudId:o,acpId:d}),x.stop(n).catch(h=>pe.warn("downstream stop failed during reload (ignored)",{reason:n,agentId:e,cloudId:o,err:String(h)}))}}isRuntimePendingPermission(e){let n=this.opts.isRuntimePendingPermission;return!n||!e.downstream?!1:n(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return pe.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let n=e.agentId,i=await Pe(n);if(!i)throw new k("AGENT_NOT_FOUND",`agent not found: ${n}`);if(i.cozeIdentity===e.cozeIdentity)return pe.info("_agent/update: cozeIdentity unchanged, noop",{agentId:n}),{ok:!0};try{await fr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw pe.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:n,framework:i.framework,workspace:i.workspace,err:String(o)}),new k("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${n}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Ue(i),pe.info("_agent/update: cozeIdentity rewritten",{agentId:n,framework:i.framework}),this.reloadAgentSessions(n,"identity-changed"),{ok:!0}}async upgradeBridge(e){let n=e.agentId||e._meta?.cozeAgentId;if(!n)throw new k("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await Pe(n))throw new k("AGENT_NOT_FOUND",`agent not found: ${n}`);let o=["-y"];e.registry&&Li(e.registry)&&o.push(`--registry=${e.registry}`);let c=dy(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let d=e._meta?.cozeEnv;d&&oy.test(d)&&o.push("--env",d);let u=await ly(o);return pe.info("_agent/upgrade: spawned bridge upgrade process",{agentId:n,pid:u,targetVersion:c,currentVersion:e.currentVersion??"",reason:e.reason??""}),{ok:!0,accepted:!0,pid:u,message:"bridge upgrade started"}}async disconnectAgent(e){let n=e.agentId;if(!n)throw new k("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Pe(n);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Ue(i),pe.info("agent disconnected",{agentId:n,reason:e.reason??"",force:e.force??!1}),this.opts.disposeAndMarkDisconnected&&await this.opts.disposeAndMarkDisconnected(n,e.reason??"disconnect"),{ok:!0}):(pe.warn("_agent/disconnect: agent not found, ignoring",{agentId:n}),{ok:!0})}async deleteAgent(e){let n=e.agentId;if(!n)throw new k("IPC_BAD_REQUEST",`${xt.DELETE}: missing agentId`);let i=await Pe(n),o=e._meta?.cozeDeployType==="cloud"||e._meta?.cozeDeployType==="local"?e._meta.cozeDeployType:void 0,c=e.deployType??o??i?.deployType??"local";this.opts.disposeForDelete&&await this.opts.disposeForDelete(n,e.reason??"delete");let d=Ze(n);return c==="cloud"?await Xc(d.root,{recursive:!0,force:!0}):i&&(i.deletedAt=Date.now(),i.deleteReason=e.reason??"deleted",await Ue(i)),pe.info("agent deleted",{agentId:n,reason:e.reason??"",deployType:c,configFound:!!i}),{ok:!0}}async switchModel(e){if(Cr(e._meta,"_agent/switchModel"),!e.agentId)throw new k("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let n=Kc(e.model)??Ot,i=await Pe(e.agentId);if(!i)throw new k("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=n,e.modelInfo&&(i.modelInfo=e.modelInfo),await Ue(i),pe.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:n,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return pe.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};let c=o.model;o.model=n,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o,c).catch(u=>pe.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(u)}));let d=[];for(let[u,x]of o.allSessionQueues())d.push(x.enqueue(async()=>{let h=o.sessions.get(u);h?.downstream&&(await h.downstream.stop(`switchModel: ${n}`).catch(()=>{}),h.downstream=void 0)}));return await Promise.all(d),pe.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:n,cloudSessions:d.length}),{ok:!0}}async resetAgent(e){if(Cr(e._meta,xt.RESET),!e.agentId)throw new k("IPC_BAD_REQUEST",`${xt.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,xt.RESET),await this.runDetailSync(e.agentId,xt.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,n){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),pe.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(n);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,d]of i.sessions)o.set(c,{modelToken:d.modelToken,tokenGeneratedAt:d.tokenGeneratedAt});await oi(e,o)}async clearPersistedAcpSessionIds(e){let n=await Pe(e).catch(()=>null);if(!n?.sessions)return;let i=!1;for(let o of Object.values(n.sessions))o.acpSessionId&&(o.acpSessionId=void 0,i=!0);i&&await Ue(n)}async repairAgent(e){if(Cr(e._meta,xt.REPAIR),!e.agentId)throw new k("IPC_BAD_REQUEST",`${xt.REPAIR}: missing agentId`);let n=await this.loadAgentCfg(e.agentId);if(n&&n.framework!=="openclaw")throw new k("IPC_BAD_REQUEST",`${xt.REPAIR} only allowed for openclaw, got ${n.framework}`);if(n&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,n.workspace)}catch(i){pe.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,xt.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,n,i){if(!this.opts.detailSyncer){pe.warn("detailSyncer not wired, skipping sync",{method:n,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){pe.warn("detail sync failed (ignored)",{method:n,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){Cr(e._meta,"_agent/getFileTree");let n=e._meta,i=$n(n),o=await this.resolveWorkspace(i),c=e.filePath??"",d=this.safeJoin(o,c),u=await Zc(d).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 si(d,o))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let x=ky(e.depth);return u.isDirectory()?{tree:await Ay(o,d,c,x)}:{tree:[{name:Ty(c),path:g0(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){Cr(e._meta,"_agent/getFileContent");let n=$n(e._meta),i=await this.resolveWorkspace(n);if(!e.filePath)throw new k("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await Zc(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 si(o,i))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>t0)throw new k("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${t0})`);let d=await xo(o);return d.includes(0)?{content:d.toString("base64"),encoding:"base64",size:c.size}:{content:d.toString("utf8"),encoding:"utf-8",size:c.size}}async resolveWorkspace(e){let n=this.opts.agents.get(e);return n?n.workspace:(await Pe(e).catch(()=>null))?.workspace??Ze(e).workspace}safeJoin(e,n){let i=ed(e,n||"."),o=rd(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${i0}`))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${n}`);return i}loadAgentCfg(e){return Pe(e)}async requireAgentCfg(e){let n=await this.loadAgentCfg(e);if(!n)throw new k("AGENT_NOT_FOUND",`no config for agent: ${e}`);return n}};function a0(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 sd(t){return t==="claude-code"?ge(".claude","skills"):ge(".agents","skills")}function c0(t){let e=ey();return t==="claude-code"?[ge(e,".claude","skills")]:t==="codex"?[ge(e,".agents","skills"),ge(e,".codex","skills")]:[ge(e,".agents","skills"),ge(e,".openclaw","skills")]}async function uy(t,e,n,i){let o=async c=>nd(ge(c,"SKILL.md")).then(d=>d.isFile()).catch(()=>!1);if(!i){let c=ge(sd(e),n),d=ge(t,c);return await o(d)?{absDir:d,relPath:c}:null}for(let c of c0(e)){let d=ge(c,n);if(await o(d))return{absDir:d,relPath:d}}return null}async function fy(t,e,n,i,o){let c=a0(i),d=await uy(e,n,c,o);if(d)return{...d,dirName:c};let x=(o?await x0(t,n):await f0(t,e,n)).filter(w=>w.skill.skillName===i);if(x.length>1)throw new k("SKILL_NOT_FOUND",`multiple skills named "${i}" in ${o?"global":"workspace"}: ${x.map(w=>e0(w.relPath)).join(", ")} \u2014 rename or remove duplicates`);let h=x[0];return h?{absDir:o?h.relPath:ge(e,h.relPath),relPath:h.relPath,dirName:e0(h.relPath)}:null}function d0(t,e){return(Q_("sha256").update(`${t}\0${e}`).digest().readBigUInt64BE(0)&0x7fffffffffffffffn).toString()}function l0(t){if(!t.startsWith("---"))return{};let e=t.indexOf(`
|
|
93
|
-
---`,3);if(e<0)return{};let
|
|
94
|
-
`)){let c=/^\s*(name|description)\s*:\s*(.+?)\s*$/.exec(o);if(!c||!c[2])continue;let d=c[1],u=c[2].trim();(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))&&(u=u.slice(1,-1)),u&&(i[d]=u)}return i}async function u0(t,e,n,i){let o=await r0(e,{withFileTypes:!0}).catch(()=>null);if(!o)return[];let c=[];for(let d of o){let u=d.isDirectory();if(!u&&d.isSymbolicLink()&&(u=!!(await nd(ge(e,d.name)).catch(()=>null))?.isDirectory()),!u)continue;let x=d.name,h=ge(n,x),g=ge(e,x,"SKILL.md"),w=await xo(g,{encoding:"utf8"}).catch(()=>null);if(w===null)continue;let v=l0(w);c.push({relPath:h,skill:{skillId:d0(t,h),skillName:v.name||x,...v.description?{description:v.description}:{},...i?{isGlobal:!0}:{}}})}return c}async function f0(t,e,n){let i=sd(n);return u0(t,ge(e,i),i,!1)}async function x0(t,e){let n=[],i=new Set;for(let o of c0(e)){let c=await u0(t,o,o,!0);for(let d of c)i.has(d.relPath)||(i.add(d.relPath),n.push(d))}return n}var xy=3e4,hy=50*1024*1024,n0=10*1024*1024,Dr=3e4;async function po(t){let{agentId:e,workspace:n,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,d=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!d)throw new k("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=a0(o.skillName),x=sd(i),h=ge(x,u),g=ge(n,h);if(await Yc(g,{recursive:!0}),c){let v=Buffer.from(o.content,"utf8");Bi(v.length),await Qc(ge(g,"SKILL.md"),v,"utf8")}else{let v=await my(o.downloadUrl);_y(v)?await vy(v,g):yy(v)?await by(v,g):await Qc(ge(g,"SKILL.md"),v.toString("utf8"),"utf8")}let w={skillId:o.skillId,skillName:o.skillName,relPath:h,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return pe.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:h,source:c?"content":"downloadUrl"}),w}function go(t,e,n){let i=e.get(n.skillId);if(i!==void 0){t[i]=n;return}e.set(n.skillId,t.length),t.push(n)}function py(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}function gy(t){return{skillId:t.skillId,skillName:t.skillName,...t.downloadUrl?{downloadUrl:t.downloadUrl}:{},...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function h0(t,e){let n=await Pe(t,e);if(!n)return{status:"skipped",count:0};if(n.disconnectedAt)return{status:"skipped",count:0};let i=Dt,o=n.skillsRefreshedForVersion;if(o===i)return{status:"noop",count:0};if(!o)return n.skillsRefreshedForVersion=i,await Ue(n,e),{status:"seeded",count:0};let c=[...n.skills??[]],d=new Map(c.map((g,w)=>[g.skillId,w])),u=c.filter(g=>g.builtin===!0&&!!g.downloadUrl);if(u.length===0)return n.skillsRefreshedForVersion=i,await Ue(n,e),{status:"noop",count:0};let x=0,h=0;for(let g of u)try{await Xc(ge(n.workspace,g.relPath),{recursive:!0,force:!0});let w=await po({agentId:t,workspace:n.workspace,framework:n.framework,skill:gy(g)});go(c,d,w),x+=1}catch(w){h+=1,pe.warn("refresh builtin skill failed (skipping)",{agentId:t,skillId:g.skillId,skillName:g.skillName,err:String(w)})}return n.skills=c,h===0&&(n.skillsRefreshedForVersion=i),await Ue(n,e),pe.info("builtin skills refreshed after bridge upgrade",{agentId:t,from:o,to:i,ok:x,failed:h}),{status:"refreshed",count:x}}async function my(t){if(!t)throw new k("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Bi(e);let n=wy(t);return Bi(n.length),n}if(t.startsWith("file:")){let e=new URL(t).pathname,n=await xo(e);return Bi(n.length),n}if(Li(t)){let e=new AbortController,n=setTimeout(()=>e.abort(),xy);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 Bi(o.byteLength),Buffer.from(o)}finally{clearTimeout(n)}}throw new k("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Bi(t){if(t>hy)throw new k("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function wy(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new k("IPC_BAD_REQUEST","bad data URL");let n=!!e[2],i=e[3]??"";return n?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function _y(t){return t.length>=2&&t[0]===31&&t[1]===139}function yy(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],n=t[3];return e===3&&n===4||e===5&&n===6}function td(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function by(t,e){let n,i;try{n=new id.default(t),i=n.getEntries()}catch(d){throw new k("IPC_BAD_REQUEST",`zip parse failed: ${d.message}`,{cause:d})}for(let d of i){let u=d.entryName;if(!u||td(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=d.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=Ey(i),c=ed(e);for(let d of i){if(td(d.entryName))continue;let u=d.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let x=ed(e,u),h=rd(c,x);if(h.startsWith("..")||h==="..")throw new k("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(d.isDirectory){await Yc(x,{recursive:!0});continue}await Yc(ty(x),{recursive:!0});let g;try{g=d.getData()}catch(w){throw new k("IPC_BAD_REQUEST",`zip entry getData failed (${d.entryName}): ${w.message}`,{cause:w})}await Qc(x,g)}}function Ey(t){let e;for(let n of t){let i=n.entryName;if(!i||td(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 vy(t,e){await Sy(t);let n=Df({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,n.destroy(new k("IPC_BAD_REQUEST",`tar extract timeout (${Dr}ms)`))},Dr);try{await o0(s0.from(t),n)}catch(c){throw c instanceof k?c:i?new k("IPC_BAD_REQUEST",`tar extract timeout (${Dr}ms)`):new k("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function Sy(t){let e=[],n=Tr({onReadEntry:c=>{let d=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' not allowed (symlink/hardlink/special): ${d.slice(0,100)}`);return}if(d.startsWith("/")||d.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(d)){e.push(`tar entry absolute path: ${d}`);return}d.split(/[/\\]/).some(h=>h==="..")&&e.push(`tar entry contains '..': ${d}`)}}),i=!1,o=setTimeout(()=>{i=!0,n.destroy(new k("IPC_BAD_REQUEST",`tar list timeout (${Dr}ms)`))},Dr);try{await o0(s0.from(t),n)}catch(c){throw i?new k("IPC_BAD_REQUEST",`tar list timeout (${Dr}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 Iy=5e3;async function Ay(t,e,n,i){return p0(t,e,n,i,{count:0})}async function p0(t,e,n,i,o){if(i<=0)return[];let c;try{c=await r0(e,{withFileTypes:!0})}catch{return[]}let d=[];for(let u of c){if(sy.has(u.name)||u.isSymbolicLink())continue;if(o.count>=Iy){d.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let x=ge(e,u.name),h=ny(ge(n,u.name)),g=null;try{g=await Zc(x)}catch{continue}if(g.isSymbolicLink())continue;o.count++;let w={name:u.name,path:g0(rd(t,x)),isDir:g.isDirectory(),size:g.size,modifiedAt:Math.floor(g.mtimeMs)};g.isDirectory()&&i>1&&(w.children=await p0(t,x,h,i-1,o)),d.push(w)}return d.sort((u,x)=>u.isDir!==x.isDir?u.isDir?-1:1:u.name.localeCompare(x.name)),d}function ky(t){return!t||t<=0?ry:Math.min(t,iy)}function Ty(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function g0(t){return t.split(i0).join("/")}ie();var In=K("agent-health-reporter"),Cy=1e4,Py=3,Fi=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??Cy,this.livenessFailureThreshold=e.livenessFailureThreshold??Py}opts;timer=null;inFlight=!1;unsubscribeRegister=null;intervalMs;livenessFailureThreshold;consecutiveFailures=0;isLivenessLost(){return this.consecutiveFailures>=this.livenessFailureThreshold}start(){this.timer||(this.timer=setInterval(()=>{this.tick()},this.intervalMs),this.timer.unref?.(),this.unsubscribeRegister=this.opts.core.onAgentRegister(()=>{this.tick()}),In.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),In.info("heartbeat stopped"))}async tick(){if(this.inFlight){In.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){this.consecutiveFailures=0,In.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let n=[];for(let d of this.opts.core.agents.values()){let u=Ry(d);if(!u)continue;let x={agentId:d.agentId,status:u};d.patToken&&(x.patToken=d.patToken),d.accountId&&(x.accountId=d.accountId),n.push(x)}if(n.length===0){this.consecutiveFailures=0;return}let i={agents:n,bridgeVersion:Dt,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3),this.consecutiveFailures=0}catch(d){this.consecutiveFailures+=1,In.warn("heartbeat batch send failed",{count:n.length,consecutiveFailures:this.consecutiveFailures,err:String(d)})}let c=o?.authFailures;if(c&&c.length>0&&(In.warn("heartbeat received authFailures from cloud",{count:c.length,agentIds:c.map(d=>d.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(c)}catch(d){In.warn("onAuthFailures callback failed (ignored)",{err:String(d)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(n){In.warn("onTickEnd hook failed",{err:String(n)})}}};function Ry(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}ln();import{mkdir as ud,rm as vb,stat as Sb}from"node:fs/promises";import{homedir as Ib}from"node:os";import{join as K0}from"node:path";an();import{existsSync as qy}from"node:fs";import{release as Wy}from"node:os";import{basename as Ky,isAbsolute as $y}from"node:path";function zi(t,e,n){return n===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:n}}function Or(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Lr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function An(t,e){return{jsonrpc:"2.0",id:t,error:e}}$e();var mo=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)}},X={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021,SKILL_NOT_FOUND:-32022,SKILL_ZIP_TOO_LARGE:-32023,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32024};function m0(t){return"method"in t&&"id"in t&&t.id!==void 0}function w0(t){return"method"in t&&!("id"in t)}function wo(t){return!("method"in t)&&"id"in t}var Dy={AGENT_NOT_FOUND:X.AGENT_NOT_FOUND,AGENT_BUSY:X.AGENT_BUSY,AGENT_DISCONNECTED:X.AGENT_DISCONNECTED,AGENT_TIMEOUT:X.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:X.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:X.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:X.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:X.INTERNAL_ERROR,BRIDGE_INTERNAL:X.INTERNAL_ERROR,IPC_AUTH_FAILED:X.INTERNAL_ERROR,IPC_BAD_REQUEST:X.INVALID_REQUEST,METHOD_NOT_FOUND:X.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:X.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:X.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:X.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:X.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:X.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:X.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:X.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:X.FILE_TOO_LARGE,UNSUPPORTED_MIME:X.UNSUPPORTED_MIME,UPLOAD_FAILED:X.UPLOAD_FAILED,UPSTREAM_NOT_READY:X.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:X.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:X.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:X.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:X.AGENT_ENV_NOT_READY,SKILL_NOT_FOUND:X.SKILL_NOT_FOUND,SKILL_ZIP_TOO_LARGE:X.SKILL_ZIP_TOO_LARGE};function Oy(t){if(t!=null)return t instanceof Error?{name:t.name,message:Ui(t.message)}:typeof t=="string"?Ui(t):typeof t=="object"?Ny(t):t}var Ly=[[/\/Users\/[^/\s'"`)]+/g,"/Users/<redacted>"],[/\/home\/[^/\s'"`)]+/g,"/home/<redacted>"],[/[A-Za-z]:\\Users\\[^\\\s'"`)]+/g,"C:\\Users\\<redacted>"],[/(Bearer|Token|Authorization:)\s+[\w._-]+/gi,"$1 <redacted>"],[/\b(sk|pat|ak)[-_][A-Za-z0-9_-]{20,}\b/g,"<redacted-key>"]];function Ui(t){let e=t;for(let[n,i]of Ly)e=e.replace(n,i);return e}function Ny(t){let e={};for(let[n,i]of Object.entries(t))typeof i=="string"?e[n]=Ui(i):e[n]=i;return e}function Gi(t){if(t instanceof k){let e=Oy(t.cause),n={bridgeCode:t.code,retriable:t.retriable};return e!==void 0&&(n.cause=e),e&&typeof e=="object"&&"reason"in e&&typeof e.reason=="string"&&(n.reason=e.reason),{code:Dy[t.code]??X.INTERNAL_ERROR,message:Ui(t.message),data:n}}return{code:X.INTERNAL_ERROR,message:Ui(t instanceof Error?t.message:String(t))}}function _0(t){let e=t.data,n=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:d,...u}=e;c=u}return new k(n,o,{retriable:e?.retriable??!1,cause:c})}function b0(t){return`${JSON.stringify(t)}
|
|
95
|
-
`}var
|
|
96
|
-
`);this.buffer=
|
|
97
|
-
`).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function C0(t,e){if(t.length===0)return;let n=e?.killFn??Hi,i=e?.isAliveFn??ji,o=e?.sleepFn??(u=>new Promise(x=>setTimeout(x,u))),c=e?.graceMs??3e3,d=e?.pollMs??100;for(let u of t)n(u,"SIGTERM");for(let u=0;u<c&&t.some(x=>i(x));u+=d)await o(Math.min(d,c-u));for(let u of t)i(u)&&n(u,"SIGKILL")}var Hy=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: (Node binary not found|QCLAW_CLI_NODE_BINARY not set)/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/import\.meta\.resolve is not a function|\.resolve is not a function/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (codex ACP \u9700\u8981 import.meta.resolve)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20 \u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @zed-industries\/codex-acp|optional dependency was not installed/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"acp_module_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code","codex"],match:/Cannot find (module|package)[^\n]*node_modules[\\/]@(agentclientprotocol[\\/](claude-agent-acp|codex-acp)|openai[\\/]codex|zed-industries[\\/]codex-acp)|Cannot find package ['"]@openai[\\/]codex['"][\s\S]*node_modules[\\/]@agentclientprotocol[\\/]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 P0(t,e){if(!e)return null;for(let n of Hy)if(!(n.frameworks&&!n.frameworks.includes(t))&&n.match.test(e))return{bridgeCode:n.bridgeCode,reason:n.reason,message:n.message};return null}function R0(t,e){return P0(t,e)}function D0(t,e){return P0(t,e)}function Br(t,e,n){return!e&&n.firstUpdateMs>0&&t<n.firstUpdateMs?Math.max(1,n.firstUpdateMs-t):t<n.phase2GateMs?Math.max(1,n.phase2GateMs-t):Math.max(1,n.livenessWindowMs)}function O0(t,e,n){let o=n-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let h=t.suspendedMs+o,g=n-t.startedAt-h;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Br(g,t.firstFrameSeen,e)}}let c=n-t.startedAt-t.suspendedMs,d=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=d?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Br(c,!0,e)}:n-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Br(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Br(c,!1,e)}}var L0=Je("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),Vy=200,Jy=40,Zy=Je("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),Yy=Je("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),Xy=Je("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),Qy=Je("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),eb=Je("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),tb=Je("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),N0=500;function nb(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=N0?t:`${e.slice(0,N0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function rb(t){let e=[];typeof t.message=="string"&&e.push(t.message);let{data:n}=t;if(typeof n=="string")e.push(n);else if(n&&typeof n=="object")try{e.push(JSON.stringify(n))}catch{}return e.join(" ")}function M0(t){try{return qy(t)}catch{return}}function ib(t,e){return{platform:process.platform,osRelease:Wy(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:$y(e.command)?M0(e.command):void 0,cwd:e.cwd,cwdExists:M0(e.cwd),envKeys:e.envKeys}}function sb(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${Ky(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Lt=class{constructor(e){this.opts=e;this.log=K(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new _o({onError:n=>this.log.warn("decode line failed",{line:n.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Nr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new k("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",n=S0(process.env,this.opts.agentEnvFile??te().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=st(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:n,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,I0(i.pid),i.stdout?.setEncoding("utf8"),i.stdout?.on("data",o=>{try{for(let c of this.decoder.push(o))this.dispatch(c)}catch(c){this.log.warn("stdout dispatch threw, swallowed to keep daemon alive",{err:String(c)})}}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",o=>{let c=o.trimEnd();this.stderrRing.push(c),this.stderrRing.length>Vy&&this.stderrRing.shift(),this.log.debug("stderr",{text:c})}),i.stdin?.on("error",o=>{this.log.warn("child stdin error",{err:String(o)})}),i.stdout?.on("error",o=>{this.log.warn("child stdout error",{err:String(o)})}),i.stderr?.on("error",o=>{this.log.warn("child stderr error",{err:String(o)})}),i.on("exit",(o,c)=>{this.stopped=!0,A0(i.pid),(o!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:c,recentStderr:[...this.stderrRing]});try{for(let u of this.decoder.flush())this.dispatch(u)}catch(u){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(u)})}this.failAllPending(this.buildExitError(o,c));for(let u of this.exitHandlers)u(o,c)}),i.on("error",o=>{let c=o,d=ib(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(n).length});this.log.error("child error",{err:String(o),diag:d}),this.failAllPending(new k("AGENT_SPAWN_FAILED",sb(c,d),{cause:d}))}),this.log.info("downstream started",{command:this.opts.command,pid:i.pid,cwd:this.opts.cwd})}async stop(e){if(!this.child||this.stopped)return;this.stopped=!0,this.stopReason=e??"stopped",this.log.info("downstream stopping",{reason:e});let n=this.child,i=new Promise(c=>n.once("exit",()=>c()));Hi(n.pid,"SIGTERM");let o=setTimeout(()=>{n.killed||Hi(n.pid,"SIGKILL")},5e3);try{await i}finally{clearTimeout(o)}}pid(){return this.child?.pid}isAlive(){return!!this.child&&!this.stopped}getStderrTail(e){return e===void 0?[...this.stderrRing]:this.stderrRing.slice(-e)}initialize(e){return this.call("initialize",e)}sessionNew(e){return this.call("session/new",{mcpServers:[],...e})}sessionLoad(e){return this.call("session/load",{mcpServers:[],...e})}sessionPrompt(e,n){let i={firstUpdateMs:eb,phase2GateMs:Zy,livenessWindowMs:Yy,absoluteMaxMs:Xy,approvalMaxMs:tb,suspendThresholdMs:Qy,...n};return this.call("session/prompt",e,L0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Or("session/cancel",e))}setSessionMode(e){return this.call("session/set_mode",e)}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,n){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Lr(e,n))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,n){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(An(e,n))}catch(i){this.log.warn("respondAgentRequestError write failed",{id:e,err:String(i)})}}onExit(e){this.exitHandlers.push(e)}call(e,n,i=L0,o){if(!this.child||this.stopped)return Promise.reject(new k("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),d=zi(c,e,n),u=(()=>{if(typeof n!="object"||n===null)return;let x=n.sessionId;return typeof x=="string"?x:void 0})();return new Promise((x,h)=>{let g={resolve:x,reject:h,timer:null,method:e,promptTimeout:null};if(o){let w=this.now(),v={cfg:o,startedAt:w,lastActivityAt:w,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:w,expectedIntervalMs:Br(0,!1,o),sessionId:u};g.promptTimeout=v;let _=()=>{let E={startedAt:v.startedAt,lastActivityAt:v.lastActivityAt,firstFrameSeen:v.firstFrameSeen,hasActiveTool:v.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:v.suspendedMs,armedAt:v.armedAt,expectedIntervalMs:v.expectedIntervalMs},I=this.now(),A=O0(E,v.cfg,I),T=R=>{v.armedAt=I,v.expectedIntervalMs=R,g.timer=setTimeout(_,R)};if(A.action==="suspend"){v.suspendedMs+=A.suspendedDeltaMs,v.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:A.suspendedDeltaMs,suspendedMs:v.suspendedMs,...v.sessionId?{sessionId:v.sessionId}:{}}),T(A.rearmMs);return}if(A.action==="continue"){T(A.rearmMs);return}this.pending.delete(c),A.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:A.awaitingApproval,...v.sessionId?{sessionId:v.sessionId}:{}}),h(A.awaitingApproval?new k("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${v.cfg.approvalMaxMs}ms`):new k("AGENT_TIMEOUT",`${e} timed out after ${v.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...v.sessionId?{sessionId:v.sessionId}:{}}),h(new k("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${v.cfg.livenessWindowMs}ms`)))};g.timer=setTimeout(_,v.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(g.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),h(new k("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,g);try{this.writeFrame(d)}catch(w){g.timer&&clearTimeout(g.timer),this.pending.delete(c),h(w)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new k("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(b0(e),n=>{n&&this.log.warn("stdin write callback err",{err:String(n)})})}dispatch(e){if(wo(e)){let n=e.id!==null?this.pending.get(e.id):void 0;if(!n){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),n.timer&&clearTimeout(n.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:n.method,code:e.error.code,message:e.error.message,data:e.error.data}),n.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:n.method}),n.reject(new k("AGENT_PROTOCOL_ERROR",`${n.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:n.method,result:nb(e.result)}),n.resolve(e.result));return}if(w0(e)){if(e.method==="session/update"){let n=e.params;for(let i of this.pending.values()){let o=i.promptTimeout;o&&(o.firstFrameSeen=!0,o.lastActivityAt=this.now(),this.trackToolCall(o,n))}for(let i of this.updateHandlers)try{Promise.resolve(i(n)).catch(o=>this.log.warn("update handler failed (async)",{err:String(o)}))}catch(o){this.log.warn("update handler threw sync, swallowed",{err:String(o)})}}else this.log.info("unknown notification (drop, not forwarded)",{method:e.method});return}if(m0(e)){let n=e;try{this.handleAgentRequest(n).catch(i=>this.log.error("agent request handler failed (async)",{method:n.method,err:String(i)}))}catch(i){this.log.warn("handleAgentRequest threw sync, swallowed",{method:n.method,err:String(i)})}}}trackToolCall(e,n){let i=n.update,o=i?.sessionUpdate;if(o!=="tool_call"&&o!=="tool_call_update")return;let c=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!c)return;let d=typeof i.status=="string"?i.status:void 0,u=d==="completed"||d==="failed"||d==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(An(e.id,{code:-32601,message:`method not handled by Bridge: ${e.method}`}));return}this.inflightAgentRequests.set(e.id,e.method);for(let n of this.agentRequestHandlers)try{await n(e)}catch(i){this.log.error("agentRequestHandler threw",{method:e.method,err:String(i)});try{this.writeFrame(An(e.id,Gi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let n=_0(e);if(n.code!=="AGENT_PROTOCOL_ERROR")return n;let i=D0(this.framework,rb(e));return i?new k(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):n}buildExitError(e,n){if(this.stopReason!==void 0)return new k("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(Jy).join(`
|
|
98
|
-
`),o=R0(this.framework,i);return o?new k(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:n,stderrTail:i}}):new k("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${n})`,{cause:{code:e,signal:n,stderrTail:i}})}failAllPending(e){for(let n of this.pending.values())n.timer&&clearTimeout(n.timer),n.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function ob(t){let e={};for(let[n,i]of Object.entries(t))i!==void 0&&(n.startsWith("CLAUDE")||n==="AI_AGENT"||n==="BAGGAGE"||(e[n]=i));return e}var yo=class extends Lt{framework="claude-code";constructor(e){let{command:n,args:i}=ii("claude-code",e.command,e.args??[]),o={command:n,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o)}sanitizeEnv(e){return ob(e)}};an();import{mkdtempSync as ab,rmSync as cb}from"node:fs";import{tmpdir as db}from"node:os";import{join as lb}from"node:path";var B0=["default","acceptEdits","plan","auto","bypassPermissions"],F0=["read-only","auto","full-access"];function Nt(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return B0.includes(e);case"codex":return F0.includes(e);case"openclaw":return!1}}function bo(t){switch(t){case"read-only":return"read-only";case"auto":return"agent";case"full-access":return"agent-full-access"}}function z0(t){switch(t){case"read-only":return"read-only";case"agent":return"auto";case"agent-full-access":return"full-access";default:return}}function dd(t){switch(t){case"claude-code":return B0.join("/");case"codex":return F0.join("/");case"openclaw":return""}}var Eo=class extends Lt{framework="codex";authMethodId;codexHomeDir;constructor(e){let n=e.args??[],i=e.extraArgs?[...n,...e.extraArgs]:n,{command:o,args:c}=ii("codex",e.command,i),d=e.isolateCodexHome?ab(lb(db(),"coze-bridge-codex-home-")):void 0,u=d?{...e.env??{},CODEX_HOME:d}:e.env,x={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(x),this.authMethodId=e.authMethodId,this.codexHomeDir=d}async initialize(e){let n=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),n}setSessionMode(e){let n=Nt("codex",e.modeId)?bo(e.modeId):e.modeId;return super.setSessionMode({...e,modeId:n})}onUpdate(e){super.onUpdate(n=>e(ub(n)))}async stop(e){if(await super.stop(e),this.codexHomeDir)try{cb(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};function ub(t){let e=t.update;if(e.sessionUpdate!=="current_mode_update"||typeof e.currentModeId!="string")return t;let n=z0(e.currentModeId);return!n||n===e.currentModeId?t:{...t,update:{...t.update,currentModeId:n}}}$e();var fb=3e4,Fr=class extends Lt{framework="openclaw";agentId;sessionName;slashModelOnStart;constructor(e){let n=e.sessionName??"default",i=["acp","--session",`agent:${e.agentId}:${n}`];e.gatewayToken&&i.push("--token",e.gatewayToken);let o={command:e.command,args:i,cwd:e.cwd,agentId:e.agentId,...e.env?{env:e.env}:{}};super(o),this.agentId=e.agentId,this.sessionName=n,this.slashModelOnStart=e.slashModelOnStart}async afterSessionEstablished(e){this.slashModelOnStart&&(this.log.info("switching session to per-session provider via /model",{agentId:this.agentId,sessionName:this.sessionName,slash:this.slashModelOnStart}),await this.call("session/prompt",{sessionId:e,prompt:[{type:"text",text:`/model ${this.slashModelOnStart}`}]},fb))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new k("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};dn();$e();ie();Me();function ld(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}an();var kn=class{slots=[];running=!1;closed=!1;disposed=!1;enqueue(e){return this.disposed?Promise.reject(new Error("AsyncQueue disposed")):this.closed?Promise.reject(new Error("AsyncQueue closed")):new Promise((n,i)=>{this.slots.push({task:e,resolve:n,reject:i}),this.drain()})}close(){this.closed=!0}dispose(e=new Error("AsyncQueue disposed")){for(this.disposed=!0,this.closed=!0;this.slots.length>0;)this.slots.shift()?.reject(e)}get size(){return this.slots.length}get isRunning(){return this.running}get isDisposed(){return this.disposed}async drain(){if(!this.running){this.running=!0;try{for(;this.slots.length>0&&!this.disposed;){let e=this.slots.shift();if(!e)break;try{let n=await e.task();e.resolve(n)}catch(n){e.reject(n)}}}finally{this.running=!1}}}};var vo=class{agentId;framework;workspace;deployType;accountId;patToken;modelInfo;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;activeGroupIds=new Map;status="ok";model;lastActiveAt=Date.now();constructor(e){this.agentId=e.agentId,this.framework=e.framework,this.workspace=e.workspace,this.model=e.model,this.deployType=e.deployType??"local",e.accountId&&(this.accountId=e.accountId),e.patToken&&(this.patToken=e.patToken),e.modelInfo&&(this.modelInfo=e.modelInfo)}setPatToken(e){this.patToken=e}setModelInfo(e){this.modelInfo=e}getSessionQueue(e){let n=this.sessionQueues.get(e);return(!n||n.isDisposed)&&(n=new kn,this.sessionQueues.set(e,n)),n}allSessionQueues(){return this.sessionQueues.entries()}hasSessionQueue(e){let n=this.sessionQueues.get(e);return!!n&&!n.isDisposed}async dispose(e){this.status="stopped";let n=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let i of this.sessionQueues.values())i.dispose(n);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let n=[];for(let[,i]of this.sessions)qi(i),i.downstream&&(n.push(i.downstream.stop(e).catch(()=>{})),i.downstream=void 0);await Promise.all(n),this.activeTriggers.clear(),this.activeGroupIds.clear()}};function qi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function Jt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Vt();ie();import{constants as U0}from"node:fs";import{access as xb}from"node:fs/promises";import{delimiter as hb,join as pb}from"node:path";var vt=K("framework-detector"),G0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},gb=[".exe",".cmd",".bat",".ps1"],Vn=class{env;constructor(e={}){this.env={pathEnv:e.pathEnv??process.env.PATH??"",platform:e.platform??process.platform,spawn:e.spawn??st,access:e.access??xb}}async detect(e){let n=G0[e],i=await this.which(n);if(!i)return vt.debug("framework binary not found",{framework:e,bin:n}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,d]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return d&&(u.defaultAgent=d),u}async detectAll(){let e=await Promise.all(Object.keys(G0).map(async i=>[i,await this.detect(i)])),n={};for(let[i,o]of e)o&&(n[i]=o);return n}async which(e){let n=this.env.pathEnv.split(hb).filter(Boolean),i=this.env.platform==="win32"?["",...gb]:[""];for(let o of n)for(let c of i){let d=pb(o,e+c);if(await this.isExecutable(d))return d}return null}async isExecutable(e){try{let n=this.env.platform==="win32"?U0.F_OK:U0.X_OK;return await this.env.access(e,n),!0}catch{return!1}}async probeOpenclawDefaultAgent(e){let n=await this.runProbe(e,["--log-level","silent","agents","list","--json"]);if(!n)return vt.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(n.code!==0)return vt.warn("openclaw default agent probe: non-zero exit",{path:e,code:n.code,stdoutHead:n.stdout.slice(0,200)}),null;let i=n.stdout.match(/\[\s*\{[\s\S]*\}\s*\]/);if(!i)return vt.warn("openclaw default agent probe: regex no match (no JSON array in stdout)",{path:e,stdoutHead:n.stdout.slice(0,200)}),null;try{let o=JSON.parse(i[0]);if(!Array.isArray(o))return vt.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(d=>d?.isDefault===!0);return c?!c.id||!c.workspace?(vt.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}:(vt.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return vt.warn("openclaw default agent probe: JSON.parse failed",{path:e,err:String(o),matchHead:i[0].slice(0,200)}),null}}async probeOpenclawGateway(e){let n=await this.runProbe(e,["--log-level","silent","gateway","status","--json","--require-rpc","--timeout","5000"]);if(!n)return vt.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=n.code===0;i||vt.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:n.code,stdoutHead:n.stdout.slice(0,200)});let o={reachable:i},c=n.stdout.match(/\{[\s\S]*\}/);if(c)try{let d=JSON.parse(c[0]);typeof d.gateway?.port=="number"&&(o.port=d.gateway.port),typeof d.service?.runtime?.status=="string"&&(o.runtime=d.service.runtime.status),!i&&typeof d.rpc?.error=="string"&&(o.detail=d.rpc.error)}catch(d){vt.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(d)})}return o}async probeVersion(e,n=[]){let i=await this.runProbe(e,[...n,"--version"]);return i&&(wb(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,n){return new Promise(i=>{let o="",c=!1,d,u=x=>{c||(c=!0,d&&clearTimeout(d),i(x))};try{let x=this.env.spawn(e,n,{stdio:["ignore","pipe","pipe"]});d=setTimeout(()=>{x.kill("SIGKILL"),u(null)},15e3),x.stdout?.on("data",h=>{o+=h.toString("utf8")}),x.on("error",()=>u(null)),x.on("close",h=>u({code:h,stdout:o}))}catch{u(null)}})}},mb=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function wb(t){return t.replace(mb,"")}import{homedir as _b}from"node:os";import{join as yb}from"node:path";dn();Vt();or();$e();ie();async function q0(){let t=yb(_b(),".openclaw/openclaw.json");return lr(t)}async function W0(){return(await q0())?.gateway?.auth?.token??""}var j0=K("openclaw.config"),bb=[0,5e3,5e3],Eb=Je("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),H0="models.providers.",So="agents.defaults.models",Io=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new kn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??bb,this.cliTimeoutMs=e.cliTimeoutMs??Eb}async withRetry(e,n){let i;for(let o=0;o<this.retryDelaysMs.length;o++){let c=this.retryDelaysMs[o]??0;c>0&&await new Promise(d=>setTimeout(d,c));try{return await n()}catch(d){i=d,j0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(d)})}}throw new k("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((n,i)=>{let o=st(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",d=!1,u=h=>{d||(d=!0,clearTimeout(x),h())};o.stderr?.on("data",h=>{c+=h.toString("utf8")});let x=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);x.unref(),o.on("error",h=>u(()=>i(h))),o.on("close",h=>u(()=>{h===0?n():i(new Error(`exit ${h}: ${c.trim().slice(0,500)}`))}))})}async runCliTolerant(e,n){try{await this.runCli(e)}catch(i){let o=String(i);if(n.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,n){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCliTolerant(["config","unset",n],["Config path not found","Nothing was changed"])))}catch(i){j0.warn(`${e} failed (best-effort)`,{configPath:n,err:String(i)})}}ensureProvider(e,n){return this.queue.enqueue(()=>this.withRetry(`config set models.providers.${e}`,()=>this.runCli(["config","set",`${H0}${e}`,JSON.stringify(n),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${H0}${e}`)}addModelToAllowlist(e,n){let i={[e]:n?{alias:n}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${So}[${e}]`,()=>this.runCli(["config","set",So,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${So}[${e}]`,`${So}.${e}`)}async getAllowlistModelsForProvider(e){let i=(await q0())?.agents?.defaults?.models;if(!i||typeof i!="object")return[];let o=`${e}/`,c=[];for(let d of Object.keys(i))d.startsWith(o)&&c.push(d.slice(o.length));return c}ensureAgent(e,n,i){let o=["agents","add",e,"--workspace",n,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}restartGateway(){return this.queue.enqueue(()=>this.withRetry("gateway restart",()=>this.runCli(["gateway","restart"])))}deleteAgent(e){return this.queue.enqueue(()=>this.withRetry(`agents delete ${e}`,()=>this.runCliTolerant(["agents","delete",e,"--force"],["not found","does not exist"])))}};var fe=K("agent-manager"),xd="acceptEdits",J0="full-access",Z0="read-only";function Ab(t){return{INITIAL_AGENT_MODE:bo(t)}}var kb=(t,e,n,i,o,c,d,u,x,h)=>{switch(t){case"claude-code":{let g={...o?{...Jf(o),...Xf(o,d,u)}:{},...x??{},IS_SANDBOX:"1"};return new yo({cwd:n,env:g,agentId:i})}case"codex":{let g=J0;h!==void 0&&(Nt("codex",h)?g=h:fe.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:h}));let w=!!o,v={...o?{...Yf(o),...Zf(o,d,u)}:{},...Ab(g),...w?{NO_BROWSER:"1"}:{},...x??{}};return new Eo({cwd:n,agentId:i,...Object.keys(v).length>0?{env:v}:{},...w?{authMethodId:"api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Fr({command:e,cwd:n,agentId:i,...c?{sessionName:ld(c)}:{}})}};function fd(t){return t==="claude-code"||t==="codex"}function Tb(t){let e=[],n=Object.keys(t).sort();for(let i of n){let o=t[i];o!==void 0&&(Cb(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
|
|
89
|
+
`},configPath(t){return cI(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 kp("schtasks",["/Create","/SC","ONLOGON","/TN",ha,"/TR",r,"/RU",t.userName,"/F"]),rl.info("task scheduler entry created",{task:ha,logFile:t.logFile})},async uninstall(t){await kp("schtasks",["/Delete","/TN",ha,"/F"]).catch(e=>rl.warn("schtasks /Delete failed (ignored)",{err:String(e)})),rl.info("task scheduler entry removed",{task:ha})}}});var Cp={};ka(Cp,{buildContext:()=>xI,getSupervisor:()=>uI,launchdSupervisor:()=>tl,systemdSupervisor:()=>nl,taskSchedulerSupervisor:()=>il});import{homedir as dI,userInfo as lI}from"node:os";function uI(t=process.platform){switch(t){case"darwin":return tl;case"linux":return nl;case"win32":return il;default:throw new Error(`unsupported platform for OS supervisor: ${t}`)}}function hI(){let t={};for(let e of fI){let r=process.env[e];r&&(t[e]=r)}return t}function xI(){let t=ee();return{nodeBin:process.execPath,entry:Kd(t),logFile:t.logFile,homeDir:dI(),userName:lI().username,isRoot:process.getuid?.()===0,env:hI()}}var fI,Rp=rt(()=>{"use strict";Be();ra();Sp();Ap();Tp();fI=["PATH","HOME","HTTP_PROXY","HTTPS_PROXY","NO_PROXY","ALL_PROXY","http_proxy","https_proxy","no_proxy","all_proxy","NODE_EXTRA_CA_CERTS"]});ne();dn();var Ll=H("acp-installer-warmup"),rm=["claude-code","codex"];async function Nl(t={}){let e=t.ensure??dr,i=(await Promise.allSettled(rm.map(async o=>{let c=await e(o);Ll.info("acp wrapper warmup ok",{framework:o,path:c})}))).filter(o=>o.status==="rejected");i.length>0&&Ll.warn("acp wrapper warmup partial failure (\u5C06\u5728\u4E0B\u6B21 createAgent \u65F6\u91CD\u8BD5\u5E76\u629B\u9519\u7ED9\u7528\u6237)",{failedCount:i.length,reasons:i.map(o=>o.reason instanceof Error?o.reason.message:String(o.reason))})}fn();ne();import{readdir as _m}from"node:fs/promises";import{mkdir as zl,readFile as mm,writeFile as Ul}from"node:fs/promises";import{join as La}from"node:path";var wm={"claude-code":"CLAUDE.md",codex:"AGENTS.md",openclaw:"SOUL.md"};async function fr(t,e,r){await zl(t,{recursive:!0});let i=wm[e],o=La(t,i);return await Ul(o,r??"","utf8"),o}async function Na(t,e,r){let i=La(t,".claude");await zl(i,{recursive:!0});let o=La(i,"settings.local.json"),c={};try{let u=await mm(o,"utf8"),h=JSON.parse(u);typeof h=="object"&&h!==null&&!Array.isArray(h)&&(c=h)}catch{}let d=typeof c.permissions=="object"&&c.permissions!==null&&!Array.isArray(c.permissions)?c.permissions:{};if(e==="cloud")d.defaultMode="bypassPermissions",c.autoCompactWindow=15e4;else{if(!r)throw new Error("writeCcPermissionSettings: local deployType requires permissionMode (caller bug)");d.defaultMode===void 0&&(d.defaultMode=r)}return c.permissions=d,await Ul(o,JSON.stringify(c,null,2),"utf8"),o}var Qe=H("agent-detail-sync"),ym=6e4,bm=5*6e4,ys=class{constructor(e){this.opts=e}opts;retryQueue=new Map;async syncAll(e){let r=this.opts.paths.agentsRoot,i;try{i=await _m(r)}catch(o){Qe.info("agents dir not found, skip detail sync",{root:r,err:String(o)});return}Qe.info("starting detail sync",{reason:e,count:i.length}),await Promise.allSettled(i.map(async o=>{let c=await Pe(o,this.opts.paths).catch(()=>null);if(c){if(c.disconnectedAt){Qe.debug("detail sync: skip disconnected agent",{agentId:o});return}try{await this.syncOne(o,c)}catch(d){Qe.warn("detail sync failed for agent, skipping",{agentId:o,err:String(d)})}}})),Qe.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){Qe.info("retrying pending detail syncs",{count:r.length});for(let i of r)try{await this.syncOne(i)}catch(o){Qe.debug("detail sync retry still failing, will try again",{agentId:i,err:String(o)})}}}async syncOne(e,r){let i=r??await Pe(e,this.opts.paths);if(!i){Qe.info("detail sync: agent config missing, skip",{agentId:e});return}let o;try{o=await this.opts.sendDetail({_meta:{cozeAgentId:e}}),this.retryQueue.delete(e)}catch(h){Qe.warn("detail RPC failed, using local data",{agentId:e,err:String(h)});let x=this.retryQueue.get(e),m=x?Math.min(x.currentDelay*2,bm):ym;this.retryQueue.set(e,{dueAt:Date.now()+m,currentDelay:m});return}if(o.agentId&&o.agentId!==e){Qe.warn("detail response agentId mismatch, ignoring",{agentId:e,responseAgentId:o.agentId});return}let c=!1,d=!1;o.agentName&&o.agentName!==i.agentName&&(i.agentName=o.agentName,c=!0),o.description!==void 0&&o.description!==i.description&&(i.description=o.description,c=!0),o.cozeIdentity&&o.cozeIdentity!==i.cozeIdentity&&(i.cozeIdentity=o.cozeIdentity,c=!0,d=!0);let u=!1;if(o.deployType==="cloud"&&i.deployType!=="cloud"?(Qe.warn("detail sync: agent demoted to local, repairing to cloud",{agentId:e}),i.deployType="cloud",c=!0,u=!0):o.deployType&&Qe.info("detail.deployType",{agentId:e,deployType:o.deployType}),!c){Qe.debug("detail sync: no diff",{agentId:e});return}await Ge(i,this.opts.paths),Qe.info("detail sync: config updated",{agentId:e,identityChanged:d,agentName:i.agentName}),u?(await this.opts.agentManager.createAgent({agentId:e,framework:i.framework,_meta:{cozeDeployType:"cloud"},cozeIdentity:i.cozeIdentity,model:i.model}),Qe.info("detail sync: repaired demoted agent back to cloud",{agentId:e})):d&&(await fr(i.workspace,i.framework,i.cozeIdentity),this.opts.handlers.reloadAgentSessionsPublic(e,"detail-sync"))}};var od=jt(_u(),1);import{createHash as ry}from"node:crypto";import{lstat as Yc,mkdir as Qc,readFile as ho,readdir as s0,rm as ed,stat as id,writeFile as td}from"node:fs/promises";import{homedir as iy}from"node:os";import{basename as n0,dirname as sy,join as xe,normalize as oy,relative as sd,resolve as nd,sep as o0}from"node:path";import{Readable as a0}from"node:stream";import{pipeline as c0}from"node:stream/promises";import qm from"events";import st from"fs";import{EventEmitter as Nc}from"node:events";import tf from"node:stream";import{StringDecoder as jm}from"node:string_decoder";import sf from"node:path";import Sr from"node:fs";import{dirname as rw,parse as iw}from"path";import{EventEmitter as fw}from"events";import gc from"assert";import{Buffer as jn}from"buffer";import*as Su from"zlib";import hw from"zlib";import{posix as mr}from"node:path";import{basename as Gw}from"node:path";import Ys from"fs";import Pt from"fs";import Pu from"path";import{win32 as e_}from"node:path";import zu from"path";import yf from"node:fs";import m_ from"node:assert";import{randomBytes as bf}from"node:crypto";import ie from"node:fs";import ze from"node:path";import Ef from"fs";import ao from"node:fs";import ki from"node:path";import dt from"node:fs";import S_ from"node:fs/promises";import to from"node:path";import{join as Of}from"node:path";import ct from"node:fs";import Mf from"node:path";var Gm=Object.defineProperty,Hm=(t,e)=>{for(var r in e)Gm(t,r,{get:e[r],enumerable:!0})},yu=typeof process=="object"&&process?process:{stdout:null,stderr:null},Wm=t=>!!t&&typeof t=="object"&&(t instanceof $n||t instanceof tf||Km(t)||$m(t)),Km=t=>!!t&&typeof t=="object"&&t instanceof Nc&&typeof t.pipe=="function"&&t.pipe!==tf.Writable.prototype.pipe,$m=t=>!!t&&typeof t=="object"&&t instanceof Nc&&typeof t.write=="function"&&typeof t.end=="function",Wt=Symbol("EOF"),Kt=Symbol("maybeEmitEnd"),xn=Symbol("emittedEnd"),Is=Symbol("emittingEnd"),di=Symbol("emittedError"),As=Symbol("closed"),bu=Symbol("read"),ks=Symbol("flush"),Eu=Symbol("flushChunk"),yt=Symbol("encoding"),gr=Symbol("decoder"),He=Symbol("flowing"),li=Symbol("paused"),br=Symbol("resume"),qe=Symbol("buffer"),et=Symbol("pipes"),je=Symbol("bufferLength"),Ga=Symbol("bufferPush"),Ts=Symbol("bufferShift"),Ye=Symbol("objectMode"),Ce=Symbol("destroyed"),Ha=Symbol("error"),qa=Symbol("emitData"),vu=Symbol("emitEnd"),ja=Symbol("emitEnd2"),Tt=Symbol("async"),Wa=Symbol("abort"),Cs=Symbol("aborted"),ui=Symbol("signal"),Nn=Symbol("dataListeners"),at=Symbol("discarded"),fi=t=>Promise.resolve().then(t),Vm=t=>t(),Jm=t=>t==="end"||t==="finish"||t==="prefinish",Zm=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,Xm=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),nf=class{src;dest;opts;ondrain;constructor(t,e,r){this.src=t,this.dest=e,this.opts=r,this.ondrain=()=>t[br](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Ym=class extends nf{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)}},Qm=t=>!!t.objectMode,ew=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",$n=class extends Nc{[He]=!1;[li]=!1;[et]=[];[qe]=[];[Ye];[yt];[Tt];[gr];[Wt]=!1;[xn]=!1;[Is]=!1;[As]=!1;[di]=null;[je]=0;[Ce]=!1;[ui];[Cs]=!1;[Nn]=0;[at]=!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");Qm(e)?(this[Ye]=!0,this[yt]=null):ew(e)?(this[yt]=e.encoding,this[Ye]=!1):(this[Ye]=!1,this[yt]=null),this[Tt]=!!e.async,this[gr]=this[yt]?new jm(this[yt]):null,e&&e.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[qe]}),e&&e.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[et]});let{signal:r}=e;r&&(this[ui]=r,r.aborted?this[Wa]():r.addEventListener("abort",()=>this[Wa]()))}get bufferLength(){return this[je]}get encoding(){return this[yt]}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[Ye]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[Tt]}set async(t){this[Tt]=this[Tt]||!!t}[Wa](){this[Cs]=!0,this.emit("abort",this[ui]?.reason),this.destroy(this[ui]?.reason)}get aborted(){return this[Cs]}set aborted(t){}write(t,e,r){if(this[Cs])return!1;if(this[Wt])throw new Error("write after end");if(this[Ce])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof e=="function"&&(r=e,e="utf8"),e||(e="utf8");let i=this[Tt]?fi:Vm;if(!this[Ye]&&!Buffer.isBuffer(t)){if(Xm(t))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if(Zm(t))t=Buffer.from(t);else if(typeof t!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[Ye]?(this[He]&&this[je]!==0&&this[ks](!0),this[He]?this.emit("data",t):this[Ga](t),this[je]!==0&&this.emit("readable"),r&&i(r),this[He]):t.length?(typeof t=="string"&&!(e===this[yt]&&!this[gr]?.lastNeed)&&(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[yt]&&(t=this[gr].write(t)),this[He]&&this[je]!==0&&this[ks](!0),this[He]?this.emit("data",t):this[Ga](t),this[je]!==0&&this.emit("readable"),r&&i(r),this[He]):(this[je]!==0&&this.emit("readable"),r&&i(r),this[He])}read(t){if(this[Ce])return null;if(this[at]=!1,this[je]===0||t===0||t&&t>this[je])return this[Kt](),null;this[Ye]&&(t=null),this[qe].length>1&&!this[Ye]&&(this[qe]=[this[yt]?this[qe].join(""):Buffer.concat(this[qe],this[je])]);let e=this[bu](t||null,this[qe][0]);return this[Kt](),e}[bu](t,e){if(this[Ye])this[Ts]();else{let r=e;t===r.length||t===null?this[Ts]():typeof r=="string"?(this[qe][0]=r.slice(t),e=r.slice(0,t),this[je]-=t):(this[qe][0]=r.subarray(t),e=r.subarray(0,t),this[je]-=t)}return this.emit("data",e),!this[qe].length&&!this[Wt]&&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[Wt]=!0,this.writable=!1,(this[He]||!this[li])&&this[Kt](),this}[br](){this[Ce]||(!this[Nn]&&!this[et].length&&(this[at]=!0),this[li]=!1,this[He]=!0,this.emit("resume"),this[qe].length?this[ks]():this[Wt]?this[Kt]():this.emit("drain"))}resume(){return this[br]()}pause(){this[He]=!1,this[li]=!0,this[at]=!1}get destroyed(){return this[Ce]}get flowing(){return this[He]}get paused(){return this[li]}[Ga](t){this[Ye]?this[je]+=1:this[je]+=t.length,this[qe].push(t)}[Ts](){return this[Ye]?this[je]-=1:this[je]-=this[qe][0].length,this[qe].shift()}[ks](t=!1){do;while(this[Eu](this[Ts]())&&this[qe].length);!t&&!this[qe].length&&!this[Wt]&&this.emit("drain")}[Eu](t){return this.emit("data",t),this[He]}pipe(t,e){if(this[Ce])return t;this[at]=!1;let r=this[xn];return e=e||{},t===yu.stdout||t===yu.stderr?e.end=!1:e.end=e.end!==!1,e.proxyErrors=!!e.proxyErrors,r?e.end&&t.end():(this[et].push(e.proxyErrors?new Ym(this,t,e):new nf(this,t,e)),this[Tt]?fi(()=>this[br]()):this[br]()),t}unpipe(t){let e=this[et].find(r=>r.dest===t);e&&(this[et].length===1?(this[He]&&this[Nn]===0&&(this[He]=!1),this[et]=[]):this[et].splice(this[et].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[at]=!1,this[Nn]++,!this[et].length&&!this[He]&&this[br]();else if(t==="readable"&&this[je]!==0)super.emit("readable");else if(Jm(t)&&this[xn])super.emit(t),this.removeAllListeners(t);else if(t==="error"&&this[di]){let i=e;this[Tt]?fi(()=>i.call(this,this[di])):i.call(this,this[di])}return r}removeListener(t,e){return this.off(t,e)}off(t,e){let r=super.off(t,e);return t==="data"&&(this[Nn]=this.listeners("data").length,this[Nn]===0&&!this[at]&&!this[et].length&&(this[He]=!1)),r}removeAllListeners(t){let e=super.removeAllListeners(t);return(t==="data"||t===void 0)&&(this[Nn]=0,!this[at]&&!this[et].length&&(this[He]=!1)),e}get emittedEnd(){return this[xn]}[Kt](){!this[Is]&&!this[xn]&&!this[Ce]&&this[qe].length===0&&this[Wt]&&(this[Is]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[As]&&this.emit("close"),this[Is]=!1)}emit(t,...e){let r=e[0];if(t!=="error"&&t!=="close"&&t!==Ce&&this[Ce])return!1;if(t==="data")return!this[Ye]&&!r?!1:this[Tt]?(fi(()=>this[qa](r)),!0):this[qa](r);if(t==="end")return this[vu]();if(t==="close"){if(this[As]=!0,!this[xn]&&!this[Ce])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(t==="error"){this[di]=r,super.emit(Ha,r);let o=!this[ui]||this.listeners("error").length?super.emit("error",r):!1;return this[Kt](),o}else if(t==="resume"){let o=super.emit("resume");return this[Kt](),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[Kt](),i}[qa](t){for(let r of this[et])r.dest.write(t)===!1&&this.pause();let e=this[at]?!1:super.emit("data",t);return this[Kt](),e}[vu](){return this[xn]?!1:(this[xn]=!0,this.readable=!1,this[Tt]?(fi(()=>this[ja]()),!0):this[ja]())}[ja](){if(this[gr]){let e=this[gr].end();if(e){for(let r of this[et])r.dest.write(e);this[at]||super.emit("data",e)}}for(let e of this[et])e.end();let t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){let t=Object.assign([],{dataLength:0});this[Ye]||(t.dataLength=0);let e=this.promise();return this.on("data",r=>{t.push(r),this[Ye]||(t.dataLength+=r.length)}),await e,t}async concat(){if(this[Ye])throw new Error("cannot concat in objectMode");let t=await this.collect();return this[yt]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Ce,()=>e(new Error("stream destroyed"))),this.on("error",r=>e(r)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[at]=!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[Wt])return e();let i,o,c=x=>{this.off("data",d),this.off("end",u),this.off(Ce,h),e(),o(x)},d=x=>{this.off("error",c),this.off("end",u),this.off(Ce,h),this.pause(),i({value:x,done:!!this[Wt]})},u=()=>{this.off("error",c),this.off("data",d),this.off(Ce,h),e(),i({done:!0,value:void 0})},h=()=>c(new Error("stream destroyed"));return new Promise((x,m)=>{o=m,i=x,this.once(Ce,h),this.once("error",c),this.once("end",u),this.once("data",d)})},throw:e,return:e,[Symbol.asyncIterator](){return this},[Symbol.asyncDispose]:async()=>{}}}[Symbol.iterator](){this[at]=!1;let t=!1,e=()=>(this.pause(),this.off(Ha,e),this.off(Ce,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(Ha,e),this.once(Ce,e),{next:r,throw:e,return:e,[Symbol.iterator](){return this},[Symbol.dispose]:()=>{}}}destroy(t){if(this[Ce])return t?this.emit("error",t):this.emit(Ce),this;this[Ce]=!0,this[at]=!0,this[qe].length=0,this[je]=0;let e=this;return typeof e.close=="function"&&!this[As]&&e.close(),t?this.emit("error",t):this.emit(Ce),this}static get isStream(){return Wm}},tw=st.writev,vn=Symbol("_autoClose"),St=Symbol("_close"),hi=Symbol("_ended"),le=Symbol("_fd"),Ka=Symbol("_finished"),Zt=Symbol("_flags"),$a=Symbol("_flush"),xc=Symbol("_handleChunk"),pc=Symbol("_makeBuf"),Ii=Symbol("_mode"),Rs=Symbol("_needDrain"),Ar=Symbol("_onerror"),kr=Symbol("_onopen"),Va=Symbol("_onread"),Er=Symbol("_onwrite"),Sn=Symbol("_open"),vt=Symbol("_path"),wn=Symbol("_pos"),Ct=Symbol("_queue"),vr=Symbol("_read"),Ja=Symbol("_readSize"),Jt=Symbol("_reading"),xi=Symbol("_remain"),Za=Symbol("_size"),Us=Symbol("_write"),Mn=Symbol("_writing"),Gs=Symbol("_defaultFlag"),qn=Symbol("_errored"),Mc=class extends $n{[qn]=!1;[le];[vt];[Ja];[Jt]=!1;[Za];[xi];[vn];constructor(t,e){if(e=e||{},super(e),this.readable=!0,this.writable=!1,typeof t!="string")throw new TypeError("path must be a string");this[qn]=!1,this[le]=typeof e.fd=="number"?e.fd:void 0,this[vt]=t,this[Ja]=e.readSize||16*1024*1024,this[Jt]=!1,this[Za]=typeof e.size=="number"?e.size:1/0,this[xi]=this[Za],this[vn]=typeof e.autoClose=="boolean"?e.autoClose:!0,typeof this[le]=="number"?this[vr]():this[Sn]()}get fd(){return this[le]}get path(){return this[vt]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[Sn](){st.open(this[vt],"r",(t,e)=>this[kr](t,e))}[kr](t,e){t?this[Ar](t):(this[le]=e,this.emit("open",e),this[vr]())}[pc](){return Buffer.allocUnsafe(Math.min(this[Ja],this[xi]))}[vr](){if(!this[Jt]){this[Jt]=!0;let t=this[pc]();if(t.length===0)return process.nextTick(()=>this[Va](null,0,t));st.read(this[le],t,0,t.length,null,(e,r,i)=>this[Va](e,r,i))}}[Va](t,e,r){this[Jt]=!1,t?this[Ar](t):this[xc](e,r)&&this[vr]()}[St](){if(this[vn]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,st.close(t,e=>e?this.emit("error",e):this.emit("close"))}}[Ar](t){this[Jt]=!0,this[St](),this.emit("error",t)}[xc](t,e){let r=!1;return this[xi]-=t,t>0&&(r=super.write(t<e.length?e.subarray(0,t):e)),(t===0||this[xi]<=0)&&(r=!1,this[St](),super.end()),r}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return typeof this[le]=="number"&&this[vr](),!1;case"error":return this[qn]?!1:(this[qn]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}},nw=class extends Mc{[Sn](){let t=!0;try{this[kr](null,st.openSync(this[vt],"r")),t=!1}finally{t&&this[St]()}}[vr](){let t=!0;try{if(!this[Jt]){this[Jt]=!0;do{let e=this[pc](),r=e.length===0?0:st.readSync(this[le],e,0,e.length,null);if(!this[xc](r,e))break}while(!0);this[Jt]=!1}t=!1}finally{t&&this[St]()}}[St](){if(this[vn]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,st.closeSync(t),this.emit("close")}}},no=class extends qm{readable=!1;writable=!0;[qn]=!1;[Mn]=!1;[hi]=!1;[Ct]=[];[Rs]=!1;[vt];[Ii];[vn];[le];[Gs];[Zt];[Ka]=!1;[wn];constructor(t,e){e=e||{},super(e),this[vt]=t,this[le]=typeof e.fd=="number"?e.fd:void 0,this[Ii]=e.mode===void 0?438:e.mode,this[wn]=typeof e.start=="number"?e.start:void 0,this[vn]=typeof e.autoClose=="boolean"?e.autoClose:!0;let r=this[wn]!==void 0?"r+":"w";this[Gs]=e.flags===void 0,this[Zt]=e.flags===void 0?r:e.flags,this[le]===void 0&&this[Sn]()}emit(t,...e){if(t==="error"){if(this[qn])return!1;this[qn]=!0}return super.emit(t,...e)}get fd(){return this[le]}get path(){return this[vt]}[Ar](t){this[St](),this[Mn]=!0,this.emit("error",t)}[Sn](){st.open(this[vt],this[Zt],this[Ii],(t,e)=>this[kr](t,e))}[kr](t,e){this[Gs]&&this[Zt]==="r+"&&t&&t.code==="ENOENT"?(this[Zt]="w",this[Sn]()):t?this[Ar](t):(this[le]=e,this.emit("open",e),this[Mn]||this[$a]())}end(t,e){return t&&this.write(t,e),this[hi]=!0,!this[Mn]&&!this[Ct].length&&typeof this[le]=="number"&&this[Er](null,0),this}write(t,e){return typeof t=="string"&&(t=Buffer.from(t,e)),this[hi]?(this.emit("error",new Error("write() after end()")),!1):this[le]===void 0||this[Mn]||this[Ct].length?(this[Ct].push(t),this[Rs]=!0,!1):(this[Mn]=!0,this[Us](t),!0)}[Us](t){st.write(this[le],t,0,t.length,this[wn],(e,r)=>this[Er](e,r))}[Er](t,e){t?this[Ar](t):(this[wn]!==void 0&&typeof e=="number"&&(this[wn]+=e),this[Ct].length?this[$a]():(this[Mn]=!1,this[hi]&&!this[Ka]?(this[Ka]=!0,this[St](),this.emit("finish")):this[Rs]&&(this[Rs]=!1,this.emit("drain"))))}[$a](){if(this[Ct].length===0)this[hi]&&this[Er](null,0);else if(this[Ct].length===1)this[Us](this[Ct].pop());else{let t=this[Ct];this[Ct]=[],tw(this[le],t,this[wn],(e,r)=>this[Er](e,r))}}[St](){if(this[vn]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,st.close(t,e=>e?this.emit("error",e):this.emit("close"))}}},rf=class extends no{[Sn](){let t;if(this[Gs]&&this[Zt]==="r+")try{t=st.openSync(this[vt],this[Zt],this[Ii])}catch(e){if(e?.code==="ENOENT")return this[Zt]="w",this[Sn]();throw e}else t=st.openSync(this[vt],this[Zt],this[Ii]);this[kr](null,t)}[St](){if(this[vn]&&typeof this[le]=="number"){let t=this[le];this[le]=void 0,st.closeSync(t),this.emit("close")}}[Us](t){let e=!0;try{this[Er](null,st.writeSync(this[le],t,0,t.length,this[wn])),e=!1}finally{if(e)try{this[St]()}catch{}}}},sw=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"]]),ow=t=>!!t.sync&&!!t.file,aw=t=>!t.sync&&!!t.file,cw=t=>!!t.sync&&!t.file,dw=t=>!t.sync&&!t.file,lw=t=>!!t.file,uw=t=>sw.get(t)||t,Bc=(t={})=>{if(!t)return{};let e={};for(let[r,i]of Object.entries(t)){let o=uw(r);e[o]=i}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e},Li=(t,e,r,i,o)=>Object.assign((c=[],d,u)=>{Array.isArray(c)&&(d=c,c={}),typeof d=="function"&&(u=d,d=void 0),d=d?Array.from(d):[];let h=Bc(c);if(o?.(h,d),ow(h)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return t(h,d)}else if(aw(h)){let x=e(h,d);return u?x.then(()=>u(),u):x}else if(cw(h)){if(typeof u=="function")throw new TypeError("callback not supported for sync tar functions");return r(h,d)}else if(dw(h)){if(typeof u=="function")throw new TypeError("callback only supported with file option");return i(h,d)}throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:r,asyncNoFile:i,validate:o}),xw=hw.constants||{ZLIB_VERNUM:4736},Lt=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},xw)),pw=jn.concat,Iu=Object.getOwnPropertyDescriptor(jn,"concat"),gw=t=>t,Xa=Iu?.writable===!0||Iu?.set!==void 0?t=>{jn.concat=t?gw:pw}:t=>{},Wn=Symbol("_superWrite"),Ds=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"}},Ya=Symbol("flushFlag"),Fc=class extends $n{#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 Su[e]!="function")throw new TypeError("Compression method not supported: "+e);try{this.#t=new Su[e](t)}catch(r){throw new Ds(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 Ds(r))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return gc(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(t){this.ended||(typeof t!="number"&&(t=this.#i),this.write(Object.assign(jn.alloc(0),{[Ya]: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}[Wn](t){return super.write(t)}write(t,e,r){if(typeof e=="function"&&(r=e,e="utf8"),typeof t=="string"&&(t=jn.from(t,e)),this.#e)return;gc(this.#t,"zlib binding closed");let i=this.#t._handle,o=i.close;i.close=()=>{};let c=this.#t.close;this.#t.close=()=>{},Xa(!0);let d;try{let h=typeof t[Ya]=="number"?t[Ya]:this.#r;d=this.#t._processChunk(t,h),Xa(!1)}catch(h){Xa(!1),this.#o(new Ds(h,this.write))}finally{this.#t&&(this.#t._handle=i,i.close=o,this.#t.close=c,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",h=>this.#o(new Ds(h,this.write)));let u;if(d)if(Array.isArray(d)&&d.length>0){let h=d[0];u=this[Wn](jn.from(h));for(let x=1;x<d.length;x++)u=this[Wn](d[x])}else u=this[Wn](jn.from(d));return r&&r(),u}},of=class extends Fc{#e;#n;constructor(t,e){t=t||{},t.flush=t.flush||Lt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Lt.Z_FINISH,t.fullFlushFlag=Lt.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(Lt.Z_SYNC_FLUSH),gc(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)}}}},mw=class extends of{#e;constructor(t){super(t,"Gzip"),this.#e=t&&!!t.portable}[Wn](t){return this.#e?(this.#e=!1,t[9]=255,super[Wn](t)):super[Wn](t)}},ww=class extends of{constructor(t){super(t,"Unzip")}},af=class extends Fc{constructor(t,e){t=t||{},t.flush=t.flush||Lt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Lt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Lt.BROTLI_OPERATION_FLUSH,super(t,e)}},_w=class extends af{constructor(t){super(t,"BrotliCompress")}},yw=class extends af{constructor(t){super(t,"BrotliDecompress")}},cf=class extends Fc{constructor(t,e){t=t||{},t.flush=t.flush||Lt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Lt.ZSTD_e_end,t.fullFlushFlag=Lt.ZSTD_e_flush,super(t,e)}},bw=class extends cf{constructor(t){super(t,"ZstdCompress")}},Ew=class extends cf{constructor(t){super(t,"ZstdDecompress")}},vw=(t,e)=>{if(Number.isSafeInteger(t))t<0?Iw(t,e):Sw(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Sw=(t,e)=>{e[0]=128;for(var r=e.length;r>1;r--)e[r-1]=t&255,t=Math.floor(t/256)},Iw=(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]=df(o):o===0?e[i-1]=0:(r=!0,e[i-1]=lf(o))}},Aw=t=>{let e=t[0],r=e===128?Tw(t.subarray(1,t.length)):e===255?kw(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},kw=t=>{for(var e=t.length,r=0,i=!1,o=e-1;o>-1;o--){var c=Number(t[o]),d;i?d=df(c):c===0?d=c:(i=!0,d=lf(c)),d!==0&&(r-=d*Math.pow(256,e-o-1))}return r},Tw=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},df=t=>(255^t)&255,lf=t=>(255^t)+1&255,Cw={};Hm(Cw,{code:()=>zc,isCode:()=>Hs,isName:()=>Rw,name:()=>ro,normalFsTypes:()=>uf});var Hs=t=>ro.has(t),Rw=t=>zc.has(t),uf=new Set(["0","","1","2","3","4","5","6","7","D"]),ro=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),zc=new Map(Array.from(ro).map(t=>[t[1],t[0]])),Dw=t=>t===void 0||t<0?void 0:t,Kn=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=Bn(t,e+156,1),c=uf.has(o),d=c?r:void 0,u=c?i:void 0;if(this.path=d?.path??Bn(t,e,100),this.mode=d?.mode??u?.mode??_n(t,e+100,8),this.uid=d?.uid??u?.uid??_n(t,e+108,8),this.gid=d?.gid??u?.gid??_n(t,e+116,8),this.size=Dw(d?.size??u?.size??_n(t,e+124,12)),this.mtime=d?.mtime??u?.mtime??Qa(t,e+136,12),this.cksum=_n(t,e+148,12),u&&this.#n(u,!0),d&&this.#n(d),Hs(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Bn(t,e+157,100),t.subarray(e+257,e+265).toString()==="ustar\x0000")if(this.uname=d?.uname??u?.uname??Bn(t,e+265,32),this.gname=d?.gname??u?.gname??Bn(t,e+297,32),this.devmaj=d?.devmaj??u?.devmaj??_n(t,e+329,8)??0,this.devmin=d?.devmin??u?.devmin??_n(t,e+337,8)??0,t[e+475]!==0){let x=Bn(t,e+345,155);this.path=x+"/"+this.path}else{let x=Bn(t,e+345,130);x&&(this.path=x+"/"+this.path),this.atime=r?.atime??i?.atime??Qa(t,e+476,12),this.ctime=r?.ctime??i?.ctime??Qa(t,e+488,12)}let h=256;for(let x=e;x<e+148;x++)h+=t[x];for(let x=e+156;x<e+512;x++)h+=t[x];this.cksumValid=h===this.cksum,this.cksum===void 0&&h===256&&(this.nullBlock=!0)}#n(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="size"&&Number(i)<0||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=Pw(this.path||"",r),o=i[0],c=i[1];this.needPax=!!i[2],this.needPax=Fn(t,e,100,o)||this.needPax,this.needPax=yn(t,e+100,8,this.mode)||this.needPax,this.needPax=yn(t,e+108,8,this.uid)||this.needPax,this.needPax=yn(t,e+116,8,this.gid)||this.needPax,this.needPax=yn(t,e+124,12,this.size)||this.needPax,this.needPax=ec(t,e+136,12,this.mtime)||this.needPax,t[e+156]=Number(this.#e.codePointAt(0)),this.needPax=Fn(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Fn(t,e+265,32,this.uname)||this.needPax,this.needPax=Fn(t,e+297,32,this.gname)||this.needPax,this.needPax=yn(t,e+329,8,this.devmaj)||this.needPax,this.needPax=yn(t,e+337,8,this.devmin)||this.needPax,this.needPax=Fn(t,e+345,r,c)||this.needPax,t[e+475]!==0?this.needPax=Fn(t,e+345,155,c)||this.needPax:(this.needPax=Fn(t,e+345,130,c)||this.needPax,this.needPax=ec(t,e+476,12,this.atime)||this.needPax,this.needPax=ec(t,e+488,12,this.ctime)||this.needPax);let d=256;for(let u=e;u<e+148;u++)d+=t[u];for(let u=e+156;u<e+512;u++)d+=t[u];return this.cksum=d,yn(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:ro.get(this.#e)}get typeKey(){return this.#e}set type(t){let e=String(zc.get(t));if(Hs(e)||e==="Unsupported")this.#e=e;else if(Hs(t))this.#e=t;else throw new TypeError("invalid entry type: "+t)}},Pw=(t,e)=>{let r=t,i="",o,c=mr.parse(t).root||".";if(Buffer.byteLength(r)<100)o=[r,i,!1];else{i=mr.dirname(r),r=mr.basename(r);do Buffer.byteLength(r)<=100&&Buffer.byteLength(i)<=e?o=[r,i,!1]:Buffer.byteLength(r)>100&&Buffer.byteLength(i)<=e?o=[r.slice(0,99),i,!0]:(r=mr.join(mr.basename(i),r),i=mr.dirname(i));while(i!==c&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},Bn=(t,e,r)=>t.subarray(e,e+r).toString("utf8").replace(/\0.*/,""),Qa=(t,e,r)=>Ow(_n(t,e,r)),Ow=t=>t===void 0?void 0:new Date(t*1e3),_n=(t,e,r)=>Number(t[e])&128?Aw(t.subarray(e,e+r)):Nw(t,e,r),Lw=t=>isNaN(t)?void 0:t,Nw=(t,e,r)=>Lw(parseInt(t.subarray(e,e+r).toString("utf8").replace(/\0.*$/,"").trim(),8)),Mw={12:8589934591,8:2097151},yn=(t,e,r,i)=>i===void 0?!1:i>Mw[r]||i<0?(vw(i,t.subarray(e,e+r)),!0):(Bw(t,e,r,i),!1),Bw=(t,e,r,i)=>t.write(Fw(i,r),e,r,"ascii"),Fw=(t,e)=>zw(Math.floor(t).toString(8),e),zw=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",ec=(t,e,r,i)=>i===void 0?!1:yn(t,e,r,i.getTime()/1e3),Uw=new Array(156).join("\0"),Fn=(t,e,r,i)=>i===void 0?!1:(t.write(i+Uw,e,r,"utf8"),i.length!==Buffer.byteLength(i)||i.length>r),Xs=class ff{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 Kn({path:("PaxHeader/"+Gw(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:r,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(o),o.write(e,512,r,"utf8");for(let c=r+512;c<o.length;c++)o[c]=0;return o}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let r=this[e],i=r instanceof Date?r.getTime()/1e3:r,o=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+i+`
|
|
90
|
+
`,c=Buffer.byteLength(o),d=Math.floor(Math.log(c)/Math.log(10))+1;return c+d>=Math.pow(10,d)&&(d+=1),d+c+o}static parse(e,r,i=!1){return new ff(Hw(qw(e),r),i)}},Hw=(t,e)=>e?Object.assign({},e,t):t,qw=t=>t.replace(/\n$/,"").split(`
|
|
91
|
+
`).reduce(jw,Object.create(null)),jw=(t,e)=>{let r=parseInt(e,10);if(r!==Buffer.byteLength(e)+1)return t;e=e.slice((r+" ").length);let i=e.split("="),o=i.shift();if(!o)return t;let c=o.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),d=i.join("=").replace(/\0.*/,"");switch(c){case"path":case"linkpath":case"type":case"charset":case"comment":case"gname":case"uname":t[c]=d;break;case"ctime":case"atime":case"mtime":t[c]=new Date(Number(d)*1e3);break;case"size":let u=+d;u>=0&&(t[c]=u);break;case"gid":case"uid":case"dev":case"ino":case"nlink":case"mode":t[c]=+d;break}return t},Ww=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Q=Ww!=="win32"?t=>String(t):t=>String(t).replaceAll(/\\/g,"/"),Kw=class extends $n{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=Q(t.path),this.mode=t.mode,this.mode&&(this.mode=this.mode&4095),this.uid=t.uid,this.gid=t.gid,this.uname=t.uname,this.gname=t.gname,this.size=this.remain,this.mtime=t.mtime,this.atime=t.atime,this.ctime=t.ctime,this.linkpath=t.linkpath?Q(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#e(e),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=Q(t.path)),t.linkpath&&(t.linkpath=Q(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([r,i])=>!(i==null||r==="path"&&e))))}},io=(t,e,r,i={})=>{t.file&&(i.file=t.file),t.cwd&&(i.cwd=t.cwd),i.code=r instanceof Error&&r.code||e,i.tarCode=e,!t.strict&&i.recoverable!==!1?(r instanceof Error&&(i=Object.assign(r,i),r=r.message),t.emit("warn",e,r,i)):r instanceof Error?t.emit("error",Object.assign(r,i)):t.emit("error",Object.assign(new Error(`${e}: ${r}`),i))},$w=1024*1024,mc=Buffer.from([31,139]),wc=Buffer.from([40,181,47,253]),Vw=Math.max(mc.length,wc.length),ht=Symbol("state"),zn=Symbol("writeEntry"),$t=Symbol("readEntry"),tc=Symbol("nextEntry"),Au=Symbol("processEntry"),Rt=Symbol("extendedHeader"),pi=Symbol("globalExtendedHeader"),pn=Symbol("meta"),ku=Symbol("emitMeta"),we=Symbol("buffer"),Vt=Symbol("queue"),gn=Symbol("ended"),nc=Symbol("emittedEnd"),Un=Symbol("emit"),Te=Symbol("unzip"),Ps=Symbol("consumeChunk"),Os=Symbol("consumeChunkSub"),rc=Symbol("consumeBody"),Tu=Symbol("consumeMeta"),Cu=Symbol("consumeHeader"),gi=Symbol("consuming"),ic=Symbol("bufferConcat"),Ls=Symbol("maybeEnd"),wr=Symbol("writing"),Dt=Symbol("aborted"),Ns=Symbol("onDone"),Gn=Symbol("sawValidEntry"),Ms=Symbol("sawNullBlock"),Bs=Symbol("sawEOF"),Ru=Symbol("closeStream"),Jw=1e3,mi=Symbol("compressedBytesRead"),sc=Symbol("decompressedBytesRead"),Du=Symbol("checkDecompressionRatio"),Zw=()=>!0,Oi=class extends fw{file;strict;maxMetaEntrySize;filter;brotli;zstd;maxDecompressionRatio;writable=!0;readable=!1;[Vt]=[];[we];[$t];[zn];[ht]="begin";[pn]="";[Rt];[pi];[gn]=!1;[Te];[Dt]=!1;[Gn];[Ms]=!1;[Bs]=!1;[wr]=!1;[gi]=!1;[nc]=!1;[mi]=0;[sc]=0;constructor(t={}){super(),this.file=t.file||"",this.on(Ns,()=>{(this[ht]==="begin"||this[Gn]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(Ns,t.ondone):this.on(Ns,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxDecompressionRatio=typeof t.maxDecompressionRatio=="number"?t.maxDecompressionRatio:Jw,this.maxMetaEntrySize=t.maxMetaEntrySize||$w,this.filter=typeof t.filter=="function"?t.filter:Zw;let e=t.file&&(t.file.endsWith(".tar.br")||t.file.endsWith(".tbr"));this.brotli=!(t.gzip||t.zstd)&&t.brotli!==void 0?t.brotli:e?void 0:!1;let r=t.file&&(t.file.endsWith(".tar.zst")||t.file.endsWith(".tzst"));this.zstd=!(t.gzip||t.brotli)&&t.zstd!==void 0?t.zstd:r?!0:void 0,this.on("end",()=>this[Ru]()),typeof t.onwarn=="function"&&this.on("warn",t.onwarn),typeof t.onReadEntry=="function"&&this.on("entry",t.onReadEntry)}warn(t,e,r={}){io(this,t,e,r)}[Cu](t,e){this[Gn]===void 0&&(this[Gn]=!1);let r;try{r=new Kn(t,e,this[Rt],this[pi])}catch(i){return this.warn("TAR_ENTRY_INVALID",i)}if(r.nullBlock)this[Ms]?(this[Bs]=!0,this[ht]==="begin"&&(this[ht]="header"),this[Un]("eof")):(this[Ms]=!0,this[Un]("nullBlock"));else if(this[Ms]=!1,!r.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:r});else if(!r.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:r});else{let i=r.type;if(/^(Symbolic)?Link$/.test(i)&&!r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:r});else if(!/^(Symbolic)?Link$/.test(i)&&!/^(Global)?ExtendedHeader$/.test(i)&&r.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:r});else{let o=this[zn]=new Kw(r,this[Rt],this[pi]);if(!this[Gn])if(o.remain){let c=()=>{o.invalid||(this[Gn]=!0)};o.on("end",c)}else this[Gn]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[Un]("ignoredEntry",o),this[ht]="ignore",o.resume()):o.size>0&&(this[pn]="",o.on("data",c=>this[pn]+=c),this[ht]="meta"):(this[Rt]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[Un]("ignoredEntry",o),this[ht]=o.remain?"ignore":"header",o.resume()):(o.remain?this[ht]="body":(this[ht]="header",o.end()),this[$t]?this[Vt].push(o):(this[Vt].push(o),this[tc]())))}}}[Ru](){queueMicrotask(()=>this.emit("close"))}[Au](t){let e=!0;if(!t)this[$t]=void 0,e=!1;else if(Array.isArray(t)){let[r,...i]=t;this.emit(r,...i)}else this[$t]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[tc]()),e=!1);return e}[tc](){do;while(this[Au](this[Vt].shift()));if(this[Vt].length===0){let t=this[$t];!t||t.flowing||t.size===t.remain?this[wr]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[rc](t,e){let r=this[zn];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[ht]="header",this[zn]=void 0,r.end()),o.length}[Tu](t,e){let r=this[zn],i=this[rc](t,e);return!this[zn]&&r&&this[ku](r),i}[Un](t,e,r){this[Vt].length===0&&!this[$t]?this.emit(t,e,r):this[Vt].push([t,e,r])}[ku](t){switch(this[Un]("meta",this[pn]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Rt]=Xs.parse(this[pn],this[Rt],!1);break;case"GlobalExtendedHeader":this[pi]=Xs.parse(this[pn],this[pi],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let e=this[Rt]??Object.create(null);this[Rt]=e,e.path=this[pn].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let e=this[Rt]||Object.create(null);this[Rt]=e,e.linkpath=this[pn].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){if(!this[Dt]){if(this[Te]){let e=this[Te];e.write=()=>!0,e.end=()=>e,e.emit=()=>!1,e.destroy?.()}this[Dt]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}}[Du](t){this[sc]+=t.length;let e=this[sc]/this[mi];return e>this.maxDecompressionRatio?(this.abort(new Error(`max decompression ratio exceeded: ${e.toFixed(2)} > ${this.maxDecompressionRatio}`)),!1):!0}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[Dt])return r?.(),!1;if((this[Te]===void 0||this.brotli===void 0&&this[Te]===!1)&&t){if(this[we]&&(t=Buffer.concat([this[we],t]),this[we]=void 0),t.length<Vw)return this[we]=t,r?.(),!0;for(let d=0;this[Te]===void 0&&d<mc.length;d++)t[d]!==mc[d]&&(this[Te]=!1);let o=!1;if(this[Te]===!1&&this.zstd!==!1){o=!0;for(let d=0;d<wc.length;d++)if(t[d]!==wc[d]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[Te]===!1&&c)if(t.length<512)if(this[gn])this.brotli=!0;else return this[we]=t,r?.(),!0;else try{new Kn(t.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[Te]===void 0||this[Te]===!1&&(this.brotli||o)){let d=this[gn];this[gn]=!1,this[Te]=this[Te]===void 0?new ww({}):o?new Ew({}):new yw({}),this[Te].on("data",h=>{this[Du](h)&&this[Ps](h)}),this[Te].on("error",h=>{this[Dt]||this.abort(h)}),this[Te].on("end",()=>{this[gn]=!0,this[Ps]()}),this[wr]=!0,this[mi]+=t.length;let u=!!this[Te][d?"end":"write"](t);return this[wr]=!1,r?.(),u}}this[wr]=!0,this[Te]?(this[mi]+=t.length,this[Te].write(t)):this[Ps](t),this[wr]=!1;let i=this[Vt].length>0?!1:this[$t]?this[$t].flowing:!0;return!i&&this[Vt].length===0&&this[$t]?.once("drain",()=>this.emit("drain")),r?.(),i}[ic](t){t&&!this[Dt]&&(this[we]=this[we]?Buffer.concat([this[we],t]):t)}[Ls](){if(this[gn]&&!this[nc]&&!this[Dt]&&!this[gi]){this[nc]=!0;let t=this[zn];if(t?.blockRemain){let e=this[we]?this[we].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[we]&&t.write(this[we]),t.end()}this[Un](Ns)}}[Ps](t){if(this[gi]&&t)this[ic](t);else if(!t&&!this[we])this[Ls]();else if(t){if(this[gi]=!0,this[we]){this[ic](t);let e=this[we];this[we]=void 0,this[Os](e)}else this[Os](t);for(;this[we]&&this[we]?.length>=512&&!this[Dt]&&!this[Bs];){let e=this[we];this[we]=void 0,this[Os](e)}this[gi]=!1}(!this[we]||this[gn])&&this[Ls]()}[Os](t){let e=0,r=t.length;for(;e+512<=r&&!this[Dt]&&!this[Bs];)switch(this[ht]){case"begin":case"header":this[Cu](t,e),e+=512;break;case"ignore":case"body":e+=this[rc](t,e);break;case"meta":e+=this[Tu](t,e);break;default:throw new Error("invalid state: "+this[ht])}e<r&&(this[we]=this[we]?Buffer.concat([t.subarray(e),this[we]]):t.subarray(e))}end(t,e,r){return typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e)),r&&this.once("finish",r),this[Dt]||(this[Te]?(t&&(this[mi]+=t.length,this[Te].write(t)),this[Te].end()):(this[gn]=!0,(this.brotli===void 0||this.zstd===void 0)&&(t=t||Buffer.alloc(0)),t&&this.write(t),this[Ls]())),this}},Ai=t=>{let e=t.length-1,r=-1;for(;e>-1&&t.charAt(e)==="/";)r=e,e--;return r===-1?t:t.slice(0,r)},Xw=t=>{let e=t.onReadEntry;t.onReadEntry=e?r=>{e(r),r.resume()}:r=>r.resume()},hf=(t,e)=>{let r=new Map(e.map(c=>[Ai(c),!0])),i=t.filter,o=(c,d="")=>{let u=d||iw(c).root||".",h;if(c===u)h=!1;else{let x=r.get(c);h=x!==void 0?x:o(rw(c),u)}return r.set(c,h),h};t.filter=i?(c,d)=>i(c,d)&&o(Ai(c)):c=>o(Ai(c))},Yw=t=>{let e=new Oi(t),r=t.file,i;try{i=Sr.openSync(r,"r");let o=Sr.fstatSync(i),c=t.maxReadSize||16*1024*1024;if(o.size<c){let d=Buffer.allocUnsafe(o.size),u=Sr.readSync(i,d,0,o.size,0);e.end(u===d.byteLength?d:d.subarray(0,u))}else{let d=0,u=Buffer.allocUnsafe(c);for(;d<o.size;){let h=Sr.readSync(i,u,0,c,d);if(h===0)break;d+=h,e.write(u.subarray(0,h))}e.end()}}finally{if(typeof i=="number")try{Sr.closeSync(i)}catch{}}},Qw=(t,e)=>{let r=new Oi(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("end",c),Sr.stat(o,(u,h)=>{if(u)d(u);else{let x=new Mc(o,{readSize:i,size:h.size});x.on("error",d),x.pipe(r)}})})},Tr=Li(Yw,Qw,t=>new Oi(t),t=>new Oi(t),(t,e)=>{e?.length&&hf(t,e),t.noResume||Xw(t)}),xf=(t,e,r)=>(t&=4095,r&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t),{isAbsolute:t_,parse:Ou}=e_,Uc=t=>{let e="",r=Ou(t);for(;t_(t)||r.root;){let i=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":r.root;t=t.slice(i.length),e+=i,r=Ou(t)}return[e,t]},so=["|","<",">","?",":"],Gc=so.map(t=>String.fromCodePoint(61440+Number(t.codePointAt(0)))),n_=new Map(so.map((t,e)=>[t,Gc[e]])),r_=new Map(Gc.map((t,e)=>[t,so[e]])),Lu=t=>so.reduce((e,r)=>e.split(r).join(n_.get(r)),t),i_=t=>Gc.reduce((e,r)=>e.split(r).join(r_.get(r)),t),pf=(t,e)=>e?(t=Q(t).replace(/^\.(\/|$)/,""),Ai(e)+"/"+t):Q(t),s_=16*1024*1024,Nu=Symbol("process"),Mu=Symbol("file"),Bu=Symbol("directory"),_c=Symbol("symlink"),Fu=Symbol("hardlink"),wi=Symbol("header"),qs=Symbol("read"),yc=Symbol("lstat"),js=Symbol("onlstat"),bc=Symbol("onread"),Ec=Symbol("onreadlink"),vc=Symbol("openfile"),Sc=Symbol("onopenfile"),bn=Symbol("close"),Qs=Symbol("mode"),Ic=Symbol("awaitDrain"),oc=Symbol("ondrain"),Ot=Symbol("prefix"),gf=class extends $n{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=Bc(e);super(),this.path=Q(t),this.portable=!!r.portable,this.maxReadSize=r.maxReadSize||s_,this.linkCache=r.linkCache||new Map,this.statCache=r.statCache||new Map,this.preservePaths=!!r.preservePaths,this.cwd=Q(r.cwd||process.cwd()),this.strict=!!r.strict,this.noPax=!!r.noPax,this.noMtime=!!r.noMtime,this.mtime=r.mtime,this.prefix=r.prefix?Q(r.prefix):void 0,this.onWriteEntry=r.onWriteEntry,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let i=!1;if(!this.preservePaths){let[c,d]=Uc(this.path);c&&typeof d=="string"&&(this.path=d,i=c)}this.win32=!!r.win32||process.platform==="win32",this.win32&&(this.path=i_(this.path.replaceAll(/\\/g,"/")),t=t.replaceAll(/\\/g,"/")),this.absolute=Q(r.absolute||Pu.resolve(this.cwd,t)),this.path===""&&(this.path="./"),i&&this.warn("TAR_ENTRY_INFO",`stripping ${i} from absolute path`,{entry:this,path:i+this.path});let o=this.statCache.get(this.absolute);o?this[js](o):this[yc]()}warn(t,e,r={}){return io(this,t,e,r)}emit(t,...e){return t==="error"&&(this.#e=!0),super.emit(t,...e)}[yc](){Pt.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[js](e)})}[js](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=c_(t),this.emit("stat",t),this[Nu]()}[Nu](){switch(this.type){case"File":return this[Mu]();case"Directory":return this[Bu]();case"SymbolicLink":return this[_c]();default:return this.end()}}[Qs](t){return xf(t,this.type==="Directory",this.portable)}[Ot](t){return pf(t,this.prefix)}[wi](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new Kn({path:this[Ot](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ot](this.linkpath):this.linkpath,mode:this[Qs](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new Xs({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[Ot](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ot](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let t=this.header?.block;if(!t)throw new Error("failed to encode header");super.write(t)}[Bu](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[wi](),this.end()}[_c](){Pt.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Ec](e)})}[Ec](t){this.linkpath=Q(t),this[wi](),this.end()}[Fu](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=Q(Pu.relative(this.cwd,t)),this.stat.size=0,this[wi](),this.end()}[Mu](){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[Fu](e);this.linkCache.set(t,this.absolute)}if(this[wi](),this.stat.size===0)return this.end();this[vc]()}[vc](){Pt.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[Sc](e)})}[Sc](t){if(this.fd=t,this.#e)return this[bn]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[qs]()}[qs](){let{fd:t,buf:e,offset:r,length:i,pos:o}=this;if(t===void 0||e===void 0)throw new Error("cannot read file without first opening");Pt.read(t,e,r,i,o,(c,d)=>{if(c)return this[bn](()=>this.emit("error",c));this[bc](d)})}[bn](t=()=>{}){this.fd!==void 0&&Pt.close(this.fd,t)}[bc](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[bn](()=>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[bn](()=>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[oc]():this[Ic](()=>this[oc]())}[Ic](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)}[oc](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[bn](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[qs]()}},o_=class extends gf{sync=!0;[yc](){this[js](Pt.lstatSync(this.absolute))}[_c](){this[Ec](Pt.readlinkSync(this.absolute))}[vc](){this[Sc](Pt.openSync(this.absolute,"r"))}[qs](){let t=!0;try{let{fd:e,buf:r,offset:i,length:o,pos:c}=this;if(e===void 0||r===void 0)throw new Error("fd and buf must be set in READ method");let d=Pt.readSync(e,r,i,o,c);this[bc](d),t=!1}finally{if(t)try{this[bn](()=>{})}catch{}}}[Ic](t){t()}[bn](t=()=>{}){this.fd!==void 0&&Pt.closeSync(this.fd),t()}},a_=class extends $n{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,r={}){return io(this,t,e,r)}constructor(t,e={}){let r=Bc(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=Q(t.path),this.mode=t.mode!==void 0?this[Qs](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:r.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=t.linkpath!==void 0?Q(t.linkpath):void 0,typeof r.onwarn=="function"&&this.on("warn",r.onwarn);let o=!1;if(!this.preservePaths){let[d,u]=Uc(this.path);d&&typeof u=="string"&&(this.path=u,o=d)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Kn({path:this[Ot](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ot](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),o&&this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute path`,{entry:this,path:o+this.path}),this.header.encode()&&!this.noPax&&super.write(new Xs({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Ot](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Ot](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)}[Ot](t){return pf(t,this.prefix)}[Qs](t){return xf(t,this.type==="Directory",this.portable)}write(t,e,r){typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,typeof e=="string"?e:"utf8"));let i=t.length;if(i>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=i,super.write(t,r)}end(t,e,r){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof t=="function"&&(r=t,e=void 0,t=void 0),typeof e=="function"&&(r=e,e=void 0),typeof t=="string"&&(t=Buffer.from(t,e??"utf8")),r&&this.once("finish",r),t?super.end(t,r):super.end(r),this}},c_=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported",d_=class Ir{tail;head;length=0;static create(e=[]){return new Ir(e)}constructor(e=[]){for(let r of e)this.push(r)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let r=e.next,i=e.prev;return r&&(r.prev=i),i&&(i.next=r),e===this.head&&(this.head=r),e===this.tail&&(this.tail=i),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,r}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let r=this.head;e.list=this,e.next=r,r&&(r.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let r=this.tail;e.list=this,e.prev=r,r&&(r.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let r=0,i=e.length;r<i;r++)u_(this,e[r]);return this.length}unshift(...e){for(var r=0,i=e.length;r<i;r++)f_(this,e[r]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,r=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,r.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,r=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,r.list=void 0,this.length--,e}forEach(e,r){r=r||this;for(let i=this.head,o=0;i;o++)e.call(r,i.value,o,this),i=i.next}forEachReverse(e,r){r=r||this;for(let i=this.tail,o=this.length-1;i;o--)e.call(r,i.value,o,this),i=i.prev}get(e){let r=0,i=this.head;for(;i&&r<e;r++)i=i.next;if(r===e&&i)return i.value}getReverse(e){let r=0,i=this.tail;for(;i&&r<e;r++)i=i.prev;if(r===e&&i)return i.value}map(e,r){r=r||this;let i=new Ir;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 Ir;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 Ir;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 Ir;if(r<e||r<0)return i;e<0&&(e=0),r>this.length&&(r=this.length);let o=this.length,c=this.tail;for(;c&&o>r;o--)c=c.prev;for(;c&&o>e;o--,c=c.prev)i.push(c.value);return i}splice(e,r=0,...i){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let o=this.head;for(let d=0;o&&d<e;d++)o=o.next;let c=[];for(let d=0;o&&d<r;d++)c.push(o.value),o=this.removeNode(o);o?o!==this.tail&&(o=o.prev):o=this.tail;for(let d of i)o=l_(this,o,d);return c}reverse(){let e=this.head,r=this.tail;for(let i=e;i;i=i.prev){let o=i.prev;i.prev=i.next,i.next=o}return this.head=r,this.tail=e,this}};function l_(t,e,r){let i=e,o=e?e.next:t.head,c=new Hc(r,i,o,t);return c.next===void 0&&(t.tail=c),c.prev===void 0&&(t.head=c),t.length++,c}function u_(t,e){t.tail=new Hc(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function f_(t,e){t.head=new Hc(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Hc=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}},Uu=class{path;absolute;entry;stat;readdir;pending=!1;pendingLink=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}},Gu=Buffer.alloc(1024),Ws=Symbol("onStat"),_i=Symbol("ended"),bt=Symbol("queue"),yi=Symbol("pendingLinks"),mn=Symbol("current"),Hn=Symbol("process"),bi=Symbol("processing"),Fs=Symbol("processJob"),Et=Symbol("jobs"),ac=Symbol("jobDone"),Ks=Symbol("addFSEntry"),Hu=Symbol("addTarEntry"),Ac=Symbol("stat"),kc=Symbol("readdir"),$s=Symbol("onreaddir"),Vs=Symbol("pipe"),qu=Symbol("entry"),cc=Symbol("entryOpt"),Js=Symbol("writeEntryClass"),mf=Symbol("write"),dc=Symbol("ondrain"),oo=class extends $n{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Js];onWriteEntry;[bt];[yi]=new Map;[Et]=0;[bi]=!1;[_i]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=Q(t.prefix||""),this.linkCache=t.linkCache||new Map,this.statCache=t.statCache||new Map,this.readdirCache=t.readdirCache||new Map,this.onWriteEntry=t.onWriteEntry,this[Js]=gf,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 mw(t.gzip)),t.brotli&&(typeof t.brotli!="object"&&(t.brotli={}),this.zip=new _w(t.brotli)),t.zstd&&(typeof t.zstd!="object"&&(t.zstd={}),this.zip=new bw(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[dc]()),this.on("resume",()=>e.resume())}else this.on("drain",this[dc]);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[bt]=new d_,this[Et]=0,this.jobs=Number(t.jobs)||4,this[bi]=!1,this[_i]=!1}[mf](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,r){return typeof t=="function"&&(r=t,t=void 0),typeof e=="function"&&(r=e,e=void 0),t&&this.add(t),this[_i]=!0,this[Hn](),r&&r(),this}write(t){if(this[_i])throw new Error("write after end");return typeof t=="string"?this[Ks](t):this[Hu](t),this.flowing}[Hu](t){let e=Q(zu.resolve(this.cwd,t.path));if(!this.filter(t.path,t))t.resume();else{let r=new Uu(t.path,e);r.entry=new a_(t,this[cc](r)),r.entry.on("end",()=>this[ac](r)),this[Et]+=1,this[bt].push(r)}this[Hn]()}[Ks](t){let e=Q(zu.resolve(this.cwd,t));this[bt].push(new Uu(t,e)),this[Hn]()}[Ac](t){t.pending=!0,this[Et]+=1;let e=this.follow?"stat":"lstat";Ys[e](t.absolute,(r,i)=>{t.pending=!1,this[Et]-=1,r?this.emit("error",r):this[Ws](t,i)})}[Ws](t,e){if(this.statCache.set(t.absolute,e),t.stat=e,!this.filter(t.path,e))t.ignore=!0;else if(e.isFile()&&e.nlink>1&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync)if(t===this[mn])this[Fs](t);else{let r=`${e.dev}:${e.ino}`,i=this[yi].get(r);i?i.push(t):this[yi].set(r,[t]),t.pendingLink=!0,t.pending=!0}this[Hn]()}[kc](t){t.pending=!0,this[Et]+=1,Ys.readdir(t.absolute,(e,r)=>{if(t.pending=!1,this[Et]-=1,e)return this.emit("error",e);this[$s](t,r)})}[$s](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[Hn]()}[Hn](){if(!this[bi]){this[bi]=!0;for(let t=this[bt].head;t&&this[Et]<this.jobs;t=t.next)if(this[Fs](t.value),t.value.ignore){let e=t.next;this[bt].removeNode(t),t.next=e}this[bi]=!1,this[_i]&&this[bt].length===0&&this[Et]===0&&(this.zip?this.zip.end(Gu):(super.write(Gu),super.end()))}}get[mn](){return this[bt]&&this[bt].head&&this[bt].head.value}[ac](t){this[bt].shift(),this[Et]-=1;let{stat:e}=t;if(e&&e.isFile()&&e.nlink>1){let r=`${e.dev}:${e.ino}`,i=this[yi].get(r);if(i){this[yi].delete(r);for(let o of i)o.pending=!1,this[Fs](o)}}this[Hn]()}[Fs](t){if(t.pending&&t.pendingLink&&t===this[mn]&&(t.pending=!1,t.pendingLink=!1),!t.pending){if(t.entry){t===this[mn]&&!t.piped&&this[Vs](t);return}if(!t.stat){let e=this.statCache.get(t.absolute);e?this[Ws](t,e):this[Ac](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){let e=this.readdirCache.get(t.absolute);if(e?this[$s](t,e):this[kc](t),!t.readdir)return}if(t.entry=this[qu](t),!t.entry){t.ignore=!0;return}t===this[mn]&&!t.piped&&this[Vs](t)}}}[cc](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}}[qu](t){this[Et]+=1;try{return new this[Js](t.path,this[cc](t)).on("end",()=>this[ac](t)).on("error",e=>this.emit("error",e))}catch(e){this.emit("error",e)}}[dc](){this[mn]&&this[mn].entry&&this[mn].entry.resume()}[Vs](t){t.piped=!0,t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ks](c+i)});let e=t.entry,r=this.zip;if(!e)throw new Error("cannot pipe without source");r?e.on("data",i=>{r.write(i)||e.pause()}):e.on("data",i=>{super.write(i)||e.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(t,e,r={}){io(this,t,e,r)}},qc=class extends oo{sync=!0;constructor(t){super(t),this[Js]=o_}pause(){}resume(){}[Ac](t){let e=this.follow?"statSync":"lstatSync";this[Ws](t,Ys[e](t.absolute))}[kc](t){this[$s](t,Ys.readdirSync(t.absolute))}[Vs](t){let e=t.entry,r=this.zip;if(t.readdir&&t.readdir.forEach(i=>{let o=t.path,c=o==="./"?"":o.replace(/\/*$/,"/");this[Ks](c+i)}),!e)throw new Error("Cannot pipe without source");r?e.on("data",i=>{r.write(i)}):e.on("data",i=>{super[mf](i)})}},h_=(t,e)=>{let r=new qc(t),i=new rf(t.file,{mode:t.mode||438});r.pipe(i),wf(r,e)},x_=(t,e)=>{let r=new oo(t),i=new no(t.file,{mode:t.mode||438});r.pipe(i);let o=new Promise((c,d)=>{i.on("error",d),i.on("close",c),r.on("error",d)});return _f(r,e).catch(c=>r.emit("error",c)),o},wf=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Tr({file:sf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},_f=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Tr({file:sf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>{t.add(i)}}):t.add(r);t.end()},p_=(t,e)=>{let r=new qc(t);return wf(r,e),r},g_=(t,e)=>{let r=new oo(t);return _f(r,e).catch(i=>r.emit("error",i)),r},Z2=Li(h_,x_,p_,g_,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),w_=process.env.__FAKE_PLATFORM__||process.platform,vf=w_==="win32",{O_CREAT:Sf,O_NOFOLLOW:ju,O_TRUNC:If,O_WRONLY:Af}=Ef.constants,kf=Number(process.env.__FAKE_FS_O_FILENAME__)||Ef.constants.UV_FS_O_FILEMAP||0,__=vf&&!!kf,y_=512*1024,b_=kf|If|Sf|Af,Wu=!vf&&typeof ju=="number"?ju|If|Sf|Af:null,Tf=Wu!==null?()=>Wu:__?t=>t<y_?b_:"w":()=>"w",Tc=(t,e,r)=>{try{return ao.lchownSync(t,e,r)}catch(i){if(i?.code!=="ENOENT")throw i}},eo=(t,e,r,i)=>{ao.lchown(t,e,r,o=>{i(o&&o?.code!=="ENOENT"?o:null)})},E_=(t,e,r,i,o)=>{if(e.isDirectory())Cf(ki.resolve(t,e.name),r,i,c=>{if(c)return o(c);let d=ki.resolve(t,e.name);eo(d,r,i,o)});else{let c=ki.resolve(t,e.name);eo(c,r,i,o)}},Cf=(t,e,r,i)=>{ao.readdir(t,{withFileTypes:!0},(o,c)=>{if(o){if(o.code==="ENOENT")return i();if(o.code!=="ENOTDIR"&&o.code!=="ENOTSUP")return i(o)}if(o||!c.length)return eo(t,e,r,i);let d=c.length,u=null,h=x=>{if(!u){if(x)return i(u=x);if(--d===0)return eo(t,e,r,i)}};for(let x of c)E_(t,x,e,r,h)})},v_=(t,e,r,i)=>{e.isDirectory()&&Rf(ki.resolve(t,e.name),r,i),Tc(ki.resolve(t,e.name),r,i)},Rf=(t,e,r)=>{let i;try{i=ao.readdirSync(t,{withFileTypes:!0})}catch(o){let c=o;if(c?.code==="ENOENT")return;if(c?.code==="ENOTDIR"||c?.code==="ENOTSUP")return Tc(t,e,r);throw c}for(let o of i)v_(t,o,e,r);return Tc(t,e,r)},Df=class extends Error{path;code;syscall="chdir";constructor(t,e){super(`${e}: Cannot cd into '${t}'`),this.path=t,this.code=e}get name(){return"CwdError"}},co=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(t,e){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=t,this.path=e}get name(){return"SymlinkError"}},I_=(t,e)=>{dt.stat(t,(r,i)=>{(r||!i.isDirectory())&&(r=new Df(t,r?.code||"ENOTDIR")),e(r)})},A_=(t,e,r)=>{t=Q(t);let i=e.umask??18,o=e.mode|448,c=(o&i)!==0,d=e.uid,u=e.gid,h=typeof d=="number"&&typeof u=="number"&&(d!==e.processUid||u!==e.processGid),x=e.preserve,m=e.unlink,_=Q(e.cwd),S=(v,I)=>{v?r(v):I&&h?Cf(I,d,u,A=>S(A)):c?dt.chmod(t,o,r):r()};if(t===_)return I_(t,S);if(x)return S_.mkdir(t,{mode:o,recursive:!0}).then(v=>S(null,v??void 0),S);let y=Q(to.relative(_,t)).split("/");Cc(_,y,o,m,_,void 0,S)},Cc=(t,e,r,i,o,c,d)=>{if(e.length===0)return d(null,c);let u=e.shift(),h=Q(to.resolve(t+"/"+u));dt.mkdir(h,r,Pf(h,e,r,i,o,c,d))},Pf=(t,e,r,i,o,c,d)=>u=>{u?dt.lstat(t,(h,x)=>{if(h)h.path=h.path&&Q(h.path),d(h);else if(x.isDirectory())Cc(t,e,r,i,o,c,d);else if(i)dt.unlink(t,m=>{if(m)return d(m);dt.mkdir(t,r,Pf(t,e,r,i,o,c,d))});else{if(x.isSymbolicLink())return d(new co(t,t+"/"+e.join("/")));d(u)}}):(c=c||t,Cc(t,e,r,i,o,c,d))},k_=t=>{let e=!1,r;try{e=dt.statSync(t).isDirectory()}catch(i){r=i?.code}finally{if(!e)throw new Df(t,r??"ENOTDIR")}},T_=(t,e)=>{t=Q(t);let r=e.umask??18,i=e.mode|448,o=(i&r)!==0,c=e.uid,d=e.gid,u=typeof c=="number"&&typeof d=="number"&&(c!==e.processUid||d!==e.processGid),h=e.preserve,x=e.unlink,m=Q(e.cwd),_=v=>{v&&u&&Rf(v,c,d),o&&dt.chmodSync(t,i)};if(t===m)return k_(m),_();if(h)return _(dt.mkdirSync(t,{mode:i,recursive:!0})??void 0);let S=Q(to.relative(m,t)).split("/"),y;for(let v=S.shift(),I=m;v&&(I+="/"+v);v=S.shift()){I=Q(to.resolve(I));try{dt.mkdirSync(I,i),y=y||I}catch{let A=dt.lstatSync(I);if(A.isDirectory())continue;if(x){dt.unlinkSync(I),dt.mkdirSync(I,i),y=y||I;continue}else if(A.isSymbolicLink())return new co(I,I+"/"+S.join("/"))}}return _(y)},lc=Object.create(null),Ku=1e4,_r=new Set,C_=t=>{_r.has(t)?_r.delete(t):lc[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),_r.add(t);let e=lc[t],r=_r.size-Ku;if(r>Ku/10){for(let i of _r)if(_r.delete(i),delete lc[i],--r<=0)break}return e},R_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,D_=R_==="win32",P_=t=>t.split("/").slice(0,-1).reduce((e,r)=>{let i=e.at(-1);return i!==void 0&&(r=Of(i,r)),e.push(r||"/"),e},[]),O_=class{#e=new Map;#n=new Map;#r=new Set;reserve(t,e){t=D_?["win32 parallelization disabled"]:t.map(i=>Ai(Of(C_(i))));let r=new Set(t.map(i=>P_(i)).reduce((i,o)=>i.concat(o)));this.#n.set(e,{dirs:r,paths:t});for(let i of t){let o=this.#e.get(i);o?o.push(e):this.#e.set(i,[e])}for(let i of r){let o=this.#e.get(i);if(!o)this.#e.set(i,[new Set([e])]);else{let c=o.at(-1);c instanceof Set?c.add(e):o.push(new Set([e]))}}return this.#i(e)}#s(t){let e=this.#n.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(r=>this.#e.get(r)),dirs:[...e.dirs].map(r=>this.#e.get(r))}}check(t){let{paths:e,dirs:r}=this.#s(t);return e.every(i=>i&&i[0]===t)&&r.every(i=>i&&i[0]instanceof Set&&i[0].has(t))}#i(t){return this.#r.has(t)||!this.check(t)?!1:(this.#r.add(t),t(()=>this.#t(t)),!0)}#t(t){if(!this.#r.has(t))return!1;let e=this.#n.get(t);if(!e)throw new Error("invalid reservation");let{paths:r,dirs:i}=e,o=new Set;for(let c of r){let d=this.#e.get(c);if(!d||d?.[0]!==t)continue;let u=d[1];if(!u){this.#e.delete(c);continue}if(d.shift(),typeof u=="function")o.add(u);else for(let h of u)o.add(h)}for(let c of i){let d=this.#e.get(c),u=d?.[0];if(!(!d||!(u instanceof Set)))if(u.size===1&&d.length===1){this.#e.delete(c);continue}else if(u.size===1){d.shift();let h=d[0];typeof h=="function"&&o.add(h)}else u.delete(t)}return this.#r.delete(t),o.forEach(c=>this.#i(c)),!0}},L_=()=>process.umask(),$u=Symbol("onEntry"),Rc=Symbol("checkFs"),Vu=Symbol("checkFs2"),Dc=Symbol("isReusable"),xt=Symbol("makeFs"),Pc=Symbol("file"),Oc=Symbol("directory"),Zs=Symbol("link"),Ju=Symbol("symlink"),Zu=Symbol("hardlink"),Si=Symbol("ensureNoSymlink"),Xu=Symbol("unsupported"),Yu=Symbol("checkPath"),uc=Symbol("stripAbsolutePath"),En=Symbol("mkdir"),We=Symbol("onError"),zs=Symbol("pending"),Qu=Symbol("pend"),yr=Symbol("unpend"),fc=Symbol("ended"),hc=Symbol("maybeClose"),Lc=Symbol("skip"),Ti=Symbol("doChown"),Ci=Symbol("uid"),Ri=Symbol("gid"),Di=Symbol("checkedCwd"),N_=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Pi=N_==="win32",M_=1024,B_=(t,e)=>{if(!Pi)return ie.unlink(t,e);let r=t+".DELETE."+bf(16).toString("hex");ie.rename(t,r,i=>{if(i)return e(i);ie.unlink(r,e)})},F_=t=>{if(!Pi)return ie.unlinkSync(t);let e=t+".DELETE."+bf(16).toString("hex");ie.renameSync(t,e),ie.unlinkSync(e)},ef=(t,e,r)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:r,jc=class extends Oi{[fc]=!1;[Di]=!1;[zs]=0;reservations=new O_;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(t={}){if(t.ondone=()=>{this[fc]=!0,this[hc]()},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?.()===0:!!t.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:M_,this.forceChown=t.forceChown===!0,this.win32=!!t.win32||Pi,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=Q(ze.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:L_():0,this.umask=typeof t.umask=="number"?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.on("entry",e=>this[$u](e))}warn(t,e,r={}){return(t==="TAR_BAD_ARCHIVE"||t==="TAR_ABORT")&&(r.recoverable=!1),super.warn(t,e,r)}[hc](){this[fc]&&this[zs]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[uc](t,e){let r=t[e],{type:i}=t;if(!r||this.preservePaths)return!0;let[o,c]=Uc(r),d=c.replaceAll(/\\/g,"/").split("/");if(d.includes("..")||Pi&&/^[a-z]:\.\.$/i.test(d[0]??"")){if(e==="path"||i==="Link")return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:r}),!1;let u=ze.posix.dirname(t.path),h=ze.posix.normalize(ze.posix.join(u,d.join("/")));if(h.startsWith("../")||h==="..")return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:r}),!1}return o&&(t[e]=String(c),this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute ${e}`,{entry:t,[e]:r})),!0}[Yu](t){let e=Q(t.path),r=e.split("/");if(this.strip){if(r.length<this.strip)return!1;if(t.type==="Link"){let i=Q(String(t.linkpath)).split("/");if(i.length>=this.strip)t.linkpath=i.slice(this.strip).join("/");else return!1}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[uc](t,"path")||!this[uc](t,"linkpath"))return!1;if(t.absolute=ze.isAbsolute(t.path)?Q(ze.resolve(t.path)):Q(ze.resolve(this.cwd,t.path)),!this.preservePaths&&typeof t.absolute=="string"&&t.absolute.indexOf(this.cwd+"/")!==0&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:Q(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&t.type!=="Directory"&&t.type!=="GNUDumpDir")return!1;if(this.win32){let{root:i}=ze.win32.parse(String(t.absolute));t.absolute=i+Lu(String(t.absolute).slice(i.length));let{root:o}=ze.win32.parse(t.path);t.path=o+Lu(t.path.slice(o.length))}return!0}[$u](t){if(!this[Yu](t))return t.resume();switch(m_.equal(typeof t.absolute,"string"),t.type){case"Directory":case"GNUDumpDir":t.mode&&(t.mode=t.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[Rc](t);default:return this[Xu](t)}}[We](t,e){t.name==="CwdError"?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[yr](),e.resume())}[En](t,e,r){A_(Q(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},r)}[Ti](t){return this.forceChown||this.preserveOwner&&(typeof t.uid=="number"&&t.uid!==this.processUid||typeof t.gid=="number"&&t.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[Ci](t){return ef(this.uid,t.uid,this.processUid)}[Ri](t){return ef(this.gid,t.gid,this.processGid)}[Pc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=new no(String(t.absolute),{flags:Tf(t.size),mode:r,autoClose:!1});i.on("error",u=>{i.fd&&ie.close(i.fd,()=>{}),i.write=()=>!0,this[We](u,t),e()});let o=1,c=u=>{if(u){i.fd&&ie.close(i.fd,()=>{}),this[We](u,t),e();return}--o===0&&i.fd!==void 0&&ie.close(i.fd,h=>{h?this[We](h,t):this[yr](),e()})};i.on("finish",()=>{let u=String(t.absolute),h=i.fd;if(typeof h=="number"&&t.mtime&&!this.noMtime){o++;let x=t.atime||new Date,m=t.mtime;ie.futimes(h,x,m,_=>_?ie.utimes(u,x,m,S=>c(S&&_)):c())}if(typeof h=="number"&&this[Ti](t)){o++;let x=this[Ci](t),m=this[Ri](t);typeof x=="number"&&typeof m=="number"&&ie.fchown(h,x,m,_=>_?ie.chown(u,x,m,S=>c(S&&_)):c())}c()});let d=this.transform&&this.transform(t)||t;d!==t&&(d.on("error",u=>{this[We](u,t),e()}),t.pipe(d)),d.pipe(i)}[Oc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode;this[En](String(t.absolute),r,i=>{if(i){this[We](i,t),e();return}let o=1,c=()=>{--o===0&&(e(),this[yr](),t.resume())};t.mtime&&!this.noMtime&&(o++,ie.utimes(String(t.absolute),t.atime||new Date,t.mtime,c)),this[Ti](t)&&(o++,ie.chown(String(t.absolute),Number(this[Ci](t)),Number(this[Ri](t)),c)),c()})}[Xu](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[Ju](t,e){let r=Q(ze.relative(this.cwd,ze.resolve(ze.dirname(String(t.absolute)),String(t.linkpath)))).split("/");this[Si](t,this.cwd,r,()=>this[Zs](t,String(t.linkpath),"symlink",e),i=>{this[We](i,t),e()})}[Zu](t,e){let r=Q(ze.resolve(this.cwd,String(t.linkpath))),i=Q(String(t.linkpath)).split("/");this[Si](t,this.cwd,i,()=>this[Zs](t,r,"link",e),o=>{this[We](o,t),e()})}[Si](t,e,r,i,o){let c=r.shift();if(this.preservePaths||c===void 0)return i();let d=ze.resolve(e,c);ie.lstat(d,(u,h)=>{if(u)return i();if(h?.isSymbolicLink())return o(new co(d,ze.resolve(d,r.join("/"))));this[Si](t,d,r,i,o)})}[Qu](){this[zs]++}[yr](){this[zs]--,this[hc]()}[Lc](t){this[yr](),t.resume()}[Dc](t,e){return t.type==="File"&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Pi}[Rc](t){this[Qu]();let e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,r=>this[Vu](t,r))}[Vu](t,e){let r=d=>{e(d)},i=()=>{this[En](this.cwd,this.dmode,d=>{if(d){this[We](d,t),r();return}this[Di]=!0,o()})},o=()=>{if(t.absolute!==this.cwd){let d=Q(ze.dirname(String(t.absolute)));if(d!==this.cwd)return this[En](d,this.dmode,u=>{if(u){this[We](u,t),r();return}c()})}c()},c=()=>{ie.lstat(String(t.absolute),(d,u)=>{if(u&&(this.keep||this.newer&&u.mtime>(t.mtime??u.mtime))){this[Lc](t),r();return}if(d||this[Dc](t,u))return this[xt](null,t,r);if(u.isDirectory()){if(t.type==="Directory"){let h=this.chmod&&t.mode&&(u.mode&4095)!==t.mode,x=m=>this[xt](m??null,t,r);return h?ie.chmod(String(t.absolute),Number(t.mode),x):x()}if(t.absolute!==this.cwd)return ie.rmdir(String(t.absolute),h=>this[xt](h??null,t,r))}if(t.absolute===this.cwd)return this[xt](null,t,r);B_(String(t.absolute),h=>this[xt](h??null,t,r))})};this[Di]?o():i()}[xt](t,e,r){if(t){this[We](t,e),r();return}switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[Pc](e,r);case"Link":return this[Zu](e,r);case"SymbolicLink":return this[Ju](e,r);case"Directory":case"GNUDumpDir":return this[Oc](e,r)}}[Zs](t,e,r,i){ie[r](e,String(t.absolute),o=>{o?this[We](o,t):(this[yr](),t.resume()),i()})}},Ei=t=>{try{return[null,t()]}catch(e){return[e,null]}},Lf=class extends jc{sync=!0;[xt](t,e){return super[xt](t,e,()=>{})}[Rc](t){if(!this[Di]){let o=this[En](this.cwd,this.dmode);if(o)return this[We](o,t);this[Di]=!0}if(t.absolute!==this.cwd){let o=Q(ze.dirname(String(t.absolute)));if(o!==this.cwd){let c=this[En](o,this.dmode);if(c)return this[We](c,t)}}let[e,r]=Ei(()=>ie.lstatSync(String(t.absolute)));if(r&&(this.keep||this.newer&&r.mtime>(t.mtime??r.mtime)))return this[Lc](t);if(e||this[Dc](t,r))return this[xt](null,t);if(r.isDirectory()){if(t.type==="Directory"){let c=this.chmod&&t.mode&&(r.mode&4095)!==t.mode,[d]=c?Ei(()=>{ie.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[xt](d,t)}let[o]=Ei(()=>ie.rmdirSync(String(t.absolute)));this[xt](o,t)}let[i]=t.absolute===this.cwd?[]:Ei(()=>F_(String(t.absolute)));this[xt](i,t)}[Pc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.fmode,i=d=>{let u;try{ie.closeSync(o)}catch(h){u=h}(d||u)&&this[We](d||u,t),e()},o;try{o=ie.openSync(String(t.absolute),Tf(t.size),r)}catch(d){return i(d)}let c=this.transform&&this.transform(t)||t;c!==t&&(c.on("error",d=>this[We](d,t)),t.pipe(c)),c.on("data",d=>{try{ie.writeSync(o,d,0,d.length)}catch(u){i(u)}}),c.on("end",()=>{let d=null;if(t.mtime&&!this.noMtime){let u=t.atime||new Date,h=t.mtime;try{ie.futimesSync(o,u,h)}catch(x){try{ie.utimesSync(String(t.absolute),u,h)}catch{d=x}}}if(this[Ti](t)){let u=this[Ci](t),h=this[Ri](t);try{ie.fchownSync(o,Number(u),Number(h))}catch(x){try{ie.chownSync(String(t.absolute),Number(u),Number(h))}catch{d=d||x}}}i(d)})}[Oc](t,e){let r=typeof t.mode=="number"?t.mode&4095:this.dmode,i=this[En](String(t.absolute),r);if(i){this[We](i,t),e();return}if(t.mtime&&!this.noMtime)try{ie.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch{}if(this[Ti](t))try{ie.chownSync(String(t.absolute),Number(this[Ci](t)),Number(this[Ri](t)))}catch{}e(),t.resume()}[En](t,e){try{return T_(Q(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(r){return r}}[Si](t,e,r,i,o){if(this.preservePaths||r.length===0)return i();let c=e;for(let d of r){c=ze.resolve(c,d);let[u,h]=Ei(()=>ie.lstatSync(c));if(u)return i();if(h.isSymbolicLink())return o(new co(c,ze.resolve(e,r.join("/"))))}i()}[Zs](t,e,r,i){let o=`${r}Sync`;try{ie[o](e,String(t.absolute)),i(),t.resume()}catch(c){return this[We](c,t)}}},z_=t=>{let e=new Lf(t),r=t.file,i=yf.statSync(r),o=t.maxReadSize||16*1024*1024;new nw(r,{readSize:o,size:i.size}).pipe(e)},U_=(t,e)=>{let r=new jc(t),i=t.maxReadSize||16*1024*1024,o=t.file;return new Promise((c,d)=>{r.on("error",d),r.on("close",c),yf.stat(o,(u,h)=>{if(u)d(u);else{let x=new Mc(o,{readSize:i,size:h.size});x.on("error",d),x.pipe(r)}})})},Nf=Li(z_,U_,t=>new Lf(t),t=>new jc(t),(t,e)=>{e?.length&&hf(t,e)}),G_=(t,e)=>{let r=new qc(t),i=!0,o,c;try{try{o=ct.openSync(t.file,"r+")}catch(h){if(h?.code==="ENOENT")o=ct.openSync(t.file,"w+");else throw h}let d=ct.fstatSync(o),u=Buffer.alloc(512);e:for(c=0;c<d.size;c+=512){for(let m=0,_=0;m<512;m+=_){if(_=ct.readSync(o,u,m,u.length-m,c+m),c===0&&u[0]===31&&u[1]===139)throw new Error("cannot append to compressed archives");if(!_)break e}let h=new Kn(u);if(!h.cksumValid)break;let x=512*Math.ceil((h.size||0)/512);if(c+x+512>d.size)break;c+=x,t.mtimeCache&&h.mtime&&t.mtimeCache.set(String(h.path),h.mtime)}i=!1,H_(t,r,c,o,e)}finally{if(i)try{ct.closeSync(o)}catch{}}},H_=(t,e,r,i,o)=>{let c=new rf(t.file,{fd:i,start:r});e.pipe(c),j_(e,o)},q_=(t,e)=>{e=Array.from(e);let r=new oo(t),i=(o,c,d)=>{let u=(S,y)=>{S?ct.close(o,v=>d(S)):d(null,y)},h=0;if(c===0)return u(null,0);let x=0,m=Buffer.alloc(512),_=(S,y)=>{if(S||y===void 0)return u(S);if(x+=y,x<512&&y)return ct.read(o,m,x,m.length-x,h+x,_);if(h===0&&m[0]===31&&m[1]===139)return u(new Error("cannot append to compressed archives"));if(x<512)return u(null,h);let v=new Kn(m);if(!v.cksumValid)return u(null,h);let I=512*Math.ceil((v.size??0)/512);if(h+I+512>c||(h+=I+512,h>=c))return u(null,h);t.mtimeCache&&v.mtime&&t.mtimeCache.set(String(v.path),v.mtime),x=0,ct.read(o,m,0,512,h,_)};ct.read(o,m,0,512,h,_)};return new Promise((o,c)=>{r.on("error",c);let d="r+",u=(h,x)=>{if(h&&h.code==="ENOENT"&&d==="r+")return d="w+",ct.open(t.file,d,u);if(h||!x)return c(h);ct.fstat(x,(m,_)=>{if(m)return ct.close(x,()=>c(m));i(x,_.size,(S,y)=>{if(S)return c(S);let v=new no(t.file,{fd:x,start:y});r.pipe(v),v.on("error",c),v.on("close",o),W_(r,e)})})};ct.open(t.file,d,u)})},j_=(t,e)=>{e.forEach(r=>{r.charAt(0)==="@"?Tr({file:Mf.resolve(t.cwd,r.slice(1)),sync:!0,noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r)}),t.end()},W_=async(t,e)=>{for(let r of e)r.charAt(0)==="@"?await Tr({file:Mf.resolve(String(t.cwd),r.slice(1)),noResume:!0,onReadEntry:i=>t.add(i)}):t.add(r);t.end()},vi=Li(G_,q_,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!lw(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")}),uA=Li(vi.syncFile,vi.asyncFile,vi.syncNoFile,vi.asyncNoFile,(t,e=[])=>{vi.validate?.(t,e),K_(t)}),K_=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(r,i)=>e(r,i)&&!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0)):(r,i)=>!((t.mtimeCache?.get(r)??i.mtime??0)>(i.mtime??0))};fn();var pt={PAIR:"_agent/pair",CREATE:"_agent/create",HEALTH:"_agent/health",LIST_SKILLS:"_agent/listSkills",ADD_SKILLS:"_agent/addSkills",REMOVE_SKILLS:"_agent/removeSkills",GET_FILE_TREE:"_agent/getFileTree",GET_FILE_CONTENT:"_agent/getFileContent",DETAIL:"_agent/detail",UPDATE:"_agent/update",DISCONNECT:"_agent/disconnect",SWITCH_MODEL:"_agent/switchModel",GEN_MODEL_TOKEN:"_agent/genModelToken",RESET:"_agent/reset",REPAIR:"_agent/repair",UPGRADE:"_agent/upgrade",DELETE:"_agent/delete",PUBLISH_SKILL:"_agent/publishSkill"};function lo(t){return t?.cozeDeployType==="cloud"?"cloud":"local"}function Bf(t){let e=t?.cozeAccountId?.trim();if(!(!e||e==="0"))return e}function uo(t){let e=t?.cozeGroupId?.trim();if(!(!e||e==="0"))return e}function Ff(t){let e=t?.permissionMode;if(typeof e!="string")return;let r=e.trim();return r===""?void 0:r}function zf(t){let{_meta:e,...r}=t;return{stripped:r,meta:e}}function Vn(t){if(!t?.cozeAgentId)throw new Error("missing _meta.cozeAgentId");return t.cozeAgentId}Xt();Ve();ne();Be();Ve();function Cr(t,e){if(lo(t)!=="cloud")throw new T("OPERATION_NOT_ALLOWED_FOR_LOCAL",`${e} is not allowed for local agent`)}function Ni(t){return t.startsWith("http://")||t.startsWith("https://")}function Rr(t){return t.endsWith("/")?t.slice(0,-1):t}import{readFileSync as nk}from"node:fs";import{dirname as ik,join as sk}from"node:path";import{fileURLToPath as ak}from"node:url";var Nt="0.2.4";Ve();ne();var fo="1008033",qf="1289";var jf="pbbp2",Wf="https://www.coze.cn",Kf="/api/coze_claw/resource/get_frontier_key",ey="https://www.coze.cn",ty="wss://frontier.coze.cn";function Dr(t){return t??process.env.COZE_BRIDGE_HANDSHAKE_URL??ey}function $f(t){return t??process.env.COZE_BRIDGE_FRONTIER_URL??ty}function In(t){let e={},r=t?.ttEnv??process.env.COZE_BRIDGE_TT_ENV,i=t?.usePpe??process.env.COZE_BRIDGE_USE_PPE;return r&&(e["x-tt-env"]=r),i&&(e["x-use-ppe"]=i),e}function Bi(t){return t?t.startsWith("boe_")?{ttEnv:t}:{ttEnv:t,usePpe:"1"}:{}}var Mi=H("handshake");async function Wc(t){let e=Dr(t.endpoint),r=t.timeoutMs??1e4,i=`${Rr(e)}${Kf}?aid=${encodeURIComponent(fo)}`,o={Authorization:`Bearer ${t.privatecode}`,Accept:"application/json",...In(t.ppeOverride)},c=new AbortController,d=setTimeout(()=>c.abort(),r);Mi.info("frontier key handshake",{base:e});try{let u=await fetch(i,{method:"GET",headers:o,signal:c.signal}),h=u.headers.get("x-tt-logid")??"",x=u.headers.get("x-tt-trace-id")??"";if(!u.ok){let v=await u.text().catch(()=>"");throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake HTTP ${u.status} logid=${h}: ${v.slice(0,200)}`)}let m=await u.json();if(m.code!==void 0&&m.code!==0)throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake code=${m.code} msg=${m.msg??"-"} logid=${h}`);let _=m.data??{},S=typeof _.access_key=="string"&&_.access_key||typeof _.accessKey=="string"&&_.accessKey||void 0,y=typeof _.device_id=="string"&&_.device_id||typeof _.deviceId=="string"&&_.deviceId||void 0;if(!S||!y){let v=JSON.stringify(m).slice(0,500);throw new T("UPSTREAM_HANDSHAKE_FAILED",`handshake response missing access_key/device_id (also tried camelCase) logid=${h}: ${v}`)}return Mi.info("handshake ok",{remoteDeviceId:y,logid:h,traceId:x}),{accessKey:S,deviceId:y}}catch(u){if(u instanceof T)throw Mi.error("handshake failed (bridge error)",{base:e,message:u.message,code:u.code}),u;if(u.name==="AbortError")throw Mi.warn("handshake timeout",{base:e,timeoutMs:r}),new T("UPSTREAM_HANDSHAKE_FAILED",`handshake timeout (${r}ms)`,{cause:u});let h=u.cause;throw Mi.error("handshake error",{base:e,message:u instanceof Error?u.message:String(u),errno:h?.code,syscall:h?.syscall,cause:String(u).slice(0,300)}),new T("UPSTREAM_HANDSHAKE_FAILED",String(u),{cause:u})}finally{clearTimeout(d)}}var $c=process.env.COZE_BRIDGE_LLM_GATEWAY_URL?.trim()||"https://llm-gateway.coze.cn",Mt="auto",Kc=15e4;function Jf(t){return{model:Vc(t.model)??Mt,...t.modelToken?{modelToken:t.modelToken}:{}}}function Zf(t){return!t||t===Mt}var ny=new Set(["auto","\u81EA\u52A8"]);function Vc(t){let e=t?.trim();if(e)return ny.has(e.toLowerCase())?Mt:e}function Xf(t){let e={};if(t.modelToken){e.ANTHROPIC_BASE_URL=$c,e.ANTHROPIC_AUTH_TOKEN=t.modelToken;let r=t.model||Mt;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 Yf(t,e,r){let i={};if(t.modelToken?i.model=t.model||Mt:Zf(t.model)||(i.model=t.model),t.modelToken){let o={name:"coze",base_url:`${$c}/v1`,env_key:"CODEX_API_KEY",wire_api:"responses",requires_openai_auth:!1,supports_websockets:!1},c=Jc(e,r);Object.keys(c).length>0&&(o.http_headers=c),i.model_providers={coze:o},i.model_context_window=t.modelInfo?.contextWindow??Kc}return Object.keys(i).length===0?{}:{CODEX_CONFIG:JSON.stringify(i),...t.modelToken?{MODEL_PROVIDER:"coze"}:{}}}function Qf(t){return t.modelToken?{CODEX_API_KEY:t.modelToken,OPENAI_API_KEY:t.modelToken}:{}}function Jc(t,e){let{ttEnv:r,usePpe:i}=Bi(t),o={};return r&&(o["x-tt-env"]=r),i&&(o["x-use-ppe"]=i),e&&(o["x-mock-scenario"]=e),o}function e0(t,e,r){if(!t.modelToken)return{};let i=Jc(e,r);return Object.keys(i).length===0?{}:{ANTHROPIC_CUSTOM_HEADERS:Object.entries(i).map(([c,d])=>`${c}:${d}`).join(`
|
|
92
|
+
`)}}function Zc(t){return`coze-session-${t.replace(/[^A-Za-z0-9_-]+/g,"-")}`}function Xc(t){return t.model||Mt}function Vf(t,e,r){return{id:t,name:t,reasoning:!1,input:e,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},contextWindow:r,maxTokens:8192,api:"openai-completions"}}function t0(t,e,r,i){if(!t.modelToken)return null;let o=Xc(t),c=Jc(e,r),d=["text"];t.modelInfo?.capabilities?.image===!0&&d.push("image");let u=[Vf(o,d,t.modelInfo?.contextWindow??Kc)],h=new Set([o]);for(let m of i??[])!m||h.has(m)||(h.add(m),u.push(Vf(m,["text"],Kc)));let x={baseUrl:`${$c}/v1`,api:"openai-completions",apiKey:t.modelToken,models:u};return Object.keys(c).length>0&&(x.headers=c),x}var he=H("agent-handlers"),r0=5*1024*1024,ay=1,cy=6,dy=new Set(["node_modules",".git",".coze","dist","build",".next"]),ly=/^(ppe|boe)_[A-Za-z0-9_-]{1,120}$/,uy=/^[A-Za-z][A-Za-z0-9._-]{0,63}$/,fy=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;function hy(t){let e=t?.trim();return e?fy.test(e)||uy.test(e)?e:(he.warn("_agent/upgrade: invalid targetVersion, fallback to latest",{targetVersion:t}),"latest"):"latest"}function xy(t){return new Promise((e,r)=>{let i=ot("npx",t,{detached:!0,stdio:"ignore",windowsHide:!0}),o=!1,c=d=>{o||(o=!0,d?r(d):e(i.pid??0))};i.once("spawn",()=>{i.unref(),c()}),i.once("error",d=>c(d))})}var xo=class{constructor(e){this.opts=e}opts;async listSkills(e){e._meta;let r=Vn(e._meta),i=await this.loadAgentCfg(r),o=i?.workspace??Xe(r).workspace,c=i?.skills??[],d=[],u=new Set;for(let h of c){let x=xe(o,h.relPath,"SKILL.md");await id(x).then(_=>_.isFile()).catch(()=>!1)&&(d.push(_y(h)),u.add(h.relPath))}if(e.scanLocal){let h=i?.framework??"claude-code",x=await x0(r,o,h),m=await p0(r,h);for(let _ of[...x,...m])u.has(_.relPath)||(u.add(_.relPath),d.push(_.skill))}return{skills:d}}async addSkills(e){e._meta;let r=Vn(e._meta),i=await this.requireAgentCfg(r),o=e.skills??[],c=[...i.skills??[]],d=new Map(c.map((h,x)=>[h.skillId,x])),u=[];for(let h of o){let x=await po({agentId:r,workspace:i.workspace,framework:i.framework,skill:h});go(c,d,x),u.push(h)}return await ai(r,c),this.reloadAgentSessions(r,"skills-added"),{installedSkills:u}}async removeSkills(e){e._meta;let r=Vn(e._meta),i=await this.requireAgentCfg(r),o=new Set(e.skillIds??[]),c=i.skills??[],d=[];for(let u of c){if(!o.has(u.skillId)){d.push(u);continue}let h=xe(i.workspace,u.relPath);await ed(h,{recursive:!0,force:!0}),he.info("skill removed",{agentId:r,skillId:u.skillId,relPath:u.relPath})}return await ai(r,d),this.reloadAgentSessions(r,"skills-removed"),{ok:!0}}async publishSkill(e){e._meta;let r=Vn(e._meta);if(!e.skillName)throw new T("IPC_BAD_REQUEST","_agent/publishSkill: missing skillName");he.info("_agent/publishSkill start",{agentId:r,skillId:e.skillId??"",skillName:e.skillName,userId:e.userId??"",accountId:e.accountId??""});let i=await this.loadAgentCfg(r),o=i?.workspace??Xe(r).workspace,c=i?.framework??"claude-code",d=e.isGlobal??!1,u=await gy(r,o,c,e.skillName,d);if(!u){let P=d?"global":"workspace";throw new T("SKILL_NOT_FOUND",`skill not found in ${P}: ${e.skillName}`)}let{absDir:h,relPath:x,dirName:m}=u,_=xe(h,"SKILL.md"),S=new od.default;S.addLocalFolder(h,m);let y=S.toBuffer();if(y.length>i0)throw new T("SKILL_ZIP_TOO_LARGE",`skill zip ${y.length} bytes exceeds limit ${i0}`);let v=await ho(_,{encoding:"utf8"}).then(P=>f0(P).description).catch(()=>{}),I={};this.opts.publishSkillToMarketplace?I=await this.opts.publishSkillToMarketplace({zip:y,...e.skillId?{skillId:e.skillId}:{},skillName:e.skillName,...v?{description:v}:{},agentId:r,...e.userId?{userId:e.userId}:{},...e.accountId?{accountId:e.accountId}:{}}):he.warn("_agent/publishSkill: publishSkillToMarketplace not injected, skip upload",{agentId:r,skillName:e.skillName});let A=I.version??"v1.0",C=I.skillId??e.skillId??u0(r,x);if(i&&!d){let P=i.skills??[],b=P.find(R=>R.relPath===x);b?(b.version=A,b.skillId=C):P.push({skillId:C,skillName:e.skillName,relPath:x,version:A,installedAt:Date.now(),...v?{description:v}:{}}),await ai(r,P)}return he.info("skill published",{agentId:r,skillName:e.skillName,relPath:x,zipBytes:y.length,skillId:C,version:A}),{ok:!0,skillId:C,version:A}}reloadAgentSessionsPublic(e,r){this.reloadAgentSessions(e,r)}reloadAgentSessions(e,r){let i=this.opts.agents.get(e);if(i)for(let[o,c]of i.sessions){if(!c.downstream)continue;let d=c.acpSessionId;if(d&&i.activeTriggers.has(d)||this.isRuntimePendingPermission(c)){c.reloadAfterTurn=!0,he.info("downstream busy, scheduling reload after turn",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d});continue}let h=c.downstream;c.downstream=void 0,he.info("killing downstream for workspace reload (idle)",{reason:r,agentId:e,framework:i.framework,cloudId:o,acpId:d}),h.stop(r).catch(x=>he.warn("downstream stop failed during reload (ignored)",{reason:r,agentId:e,cloudId:o,err:String(x)}))}}isRuntimePendingPermission(e){let r=this.opts.isRuntimePendingPermission;return!r||!e.downstream?!1:r(e.downstream)}async updateAgent(e){if(!e.cozeIdentity?.trim())return he.info("_agent/update: empty cozeIdentity, noop",{agentId:e.agentId}),{ok:!0};let r=e.agentId,i=await Pe(r);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${r}`);if(i.cozeIdentity===e.cozeIdentity)return he.info("_agent/update: cozeIdentity unchanged, noop",{agentId:r}),{ok:!0};try{await fr(i.workspace,i.framework,e.cozeIdentity)}catch(o){throw he.error("_agent/update: writeInstructionFile failed, aborting update",{agentId:r,framework:i.framework,workspace:i.workspace,err:String(o)}),new T("AGENT_PROTOCOL_ERROR",`failed to write instruction file for agent ${r}: ${String(o)}`,{cause:o})}return i.cozeIdentity=e.cozeIdentity,await Ge(i),he.info("_agent/update: cozeIdentity rewritten",{agentId:r,framework:i.framework}),this.reloadAgentSessions(r,"identity-changed"),{ok:!0}}async upgradeBridge(e){let r=e.agentId||e._meta?.cozeAgentId;if(!r)throw new T("IPC_BAD_REQUEST","_agent/upgrade: missing agentId");if(!await Pe(r))throw new T("AGENT_NOT_FOUND",`agent not found: ${r}`);let o=["-y"];e.registry&&Ni(e.registry)&&o.push(`--registry=${e.registry}`);let c=hy(e.targetVersion);o.push("--ignore-existing",`coze-bridge@${c}`,"connect");let d=e._meta?.cozeEnv;d&&ly.test(d)&&o.push("--env",d);let u=await xy(o);return he.info("_agent/upgrade: spawned bridge upgrade process",{agentId:r,pid:u,targetVersion:c,currentVersion:e.currentVersion??"",reason:e.reason??""}),{ok:!0,accepted:!0,pid:u,message:"bridge upgrade started"}}async disconnectAgent(e){let r=e.agentId;if(!r)throw new T("IPC_BAD_REQUEST","_agent/disconnect: missing agentId");let i=await Pe(r);return i?(i.disconnectedAt=Date.now(),i.disconnectReason=e.reason??"",await Ge(i),he.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}):(he.warn("_agent/disconnect: agent not found, ignoring",{agentId:r}),{ok:!0})}async deleteAgent(e){let r=e.agentId;if(!r)throw new T("IPC_BAD_REQUEST",`${pt.DELETE}: missing agentId`);let i=await Pe(r),o=e._meta?.cozeDeployType==="cloud"||e._meta?.cozeDeployType==="local"?e._meta.cozeDeployType:void 0,c=e.deployType??o??i?.deployType??"local";this.opts.disposeForDelete&&await this.opts.disposeForDelete(r,e.reason??"delete");let d=Xe(r);return c==="cloud"?await ed(d.root,{recursive:!0,force:!0}):i&&(i.deletedAt=Date.now(),i.deleteReason=e.reason??"deleted",await Ge(i)),he.info("agent deleted",{agentId:r,reason:e.reason??"",deployType:c,configFound:!!i}),{ok:!0}}async switchModel(e){if(Cr(e._meta,"_agent/switchModel"),!e.agentId)throw new T("IPC_BAD_REQUEST","_agent/switchModel: missing agentId");let r=Vc(e.model)??Mt,i=await Pe(e.agentId);if(!i)throw new T("AGENT_NOT_FOUND",`agent not found: ${e.agentId}`);i.model=r,e.modelInfo&&(i.modelInfo=e.modelInfo),await Ge(i),he.info("_agent/switchModel: model persisted",{agentId:e.agentId,model:r,reason:e.reason??""});let o=this.opts.agents.get(e.agentId);if(!o)return he.info("_agent/switchModel: agent not running, config persisted only",{agentId:e.agentId}),{ok:!0};let c=o.model;o.model=r,e.modelInfo&&o.setModelInfo(e.modelInfo),this.opts.cleanupOpenclawProviders&&await this.opts.cleanupOpenclawProviders(o,c).catch(u=>he.warn("cleanupOpenclawProviders before switchModel failed (ignored)",{agentId:e.agentId,err:String(u)}));let d=[];for(let[u,h]of o.allSessionQueues())d.push(h.enqueue(async()=>{let x=o.sessions.get(u);x?.downstream&&(await x.downstream.stop(`switchModel: ${r}`).catch(()=>{}),x.downstream=void 0)}));return await Promise.all(d),he.info("_agent/switchModel: all session runtimes killed, next prompt will respawn",{agentId:e.agentId,model:r,cloudSessions:d.length}),{ok:!0}}async resetAgent(e){if(Cr(e._meta,pt.RESET),!e.agentId)throw new T("IPC_BAD_REQUEST",`${pt.RESET}: missing agentId`);return await this.clearSessionMappings(e.agentId,pt.RESET),await this.runDetailSync(e.agentId,pt.RESET,e.reason),{ok:!0}}async clearSessionMappings(e,r){let i=this.opts.agents.get(e);if(!i){await this.clearPersistedAcpSessionIds(e),he.info("reset: agent not in memory, cleared persisted acpSessionIds only",{agentId:e});return}await i.killAllRuntimes(r);for(let c of i.sessions.values())c.acpSessionId=void 0,c.replySeq=0,c.loadingSession=!1,c.spawnFailCount=void 0,c.spawnFailedAt=void 0;let o=new Map;for(let[c,d]of i.sessions)o.set(c,{modelToken:d.modelToken,tokenGeneratedAt:d.tokenGeneratedAt});await oi(e,o)}async clearPersistedAcpSessionIds(e){let r=await Pe(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 Ge(r)}async repairAgent(e){if(Cr(e._meta,pt.REPAIR),!e.agentId)throw new T("IPC_BAD_REQUEST",`${pt.REPAIR}: missing agentId`);let r=await this.loadAgentCfg(e.agentId);if(r&&r.framework!=="openclaw")throw new T("IPC_BAD_REQUEST",`${pt.REPAIR} only allowed for openclaw, got ${r.framework}`);if(r&&this.opts.openclawRepair)try{await this.opts.openclawRepair(e.agentId,r.workspace)}catch(i){he.warn("openclaw repair (delete+add) failed (ignored)",{agentId:e.agentId,reason:e.reason,err:String(i)})}return await this.runDetailSync(e.agentId,pt.REPAIR,e.reason),{ok:!0}}async runDetailSync(e,r,i){if(!this.opts.detailSyncer){he.warn("detailSyncer not wired, skipping sync",{method:r,agentId:e});return}try{await this.opts.detailSyncer(e)}catch(o){he.warn("detail sync failed (ignored)",{method:r,agentId:e,reason:i,err:String(o)})}}async getFileTree(e){Cr(e._meta,"_agent/getFileTree");let r=e._meta,i=Vn(r),o=await this.resolveWorkspace(i),c=e.filePath??"",d=this.safeJoin(o,c),u=await Yc(d).catch(()=>null);if(!u)throw new T("IPC_BAD_REQUEST",`path not found: ${c}`);if(u.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${c}`);if(!await si(d,o))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${c}`);let h=Dy(e.depth);return u.isDirectory()?{tree:await Ry(o,d,c,h)}:{tree:[{name:Py(c),path:w0(c||"."),isDir:!1,size:u.size,modifiedAt:Math.floor(u.mtimeMs)}]}}async getFileContent(e){Cr(e._meta,"_agent/getFileContent");let r=Vn(e._meta),i=await this.resolveWorkspace(r);if(!e.filePath)throw new T("IPC_BAD_REQUEST","filePath required");let o=this.safeJoin(i,e.filePath),c=await Yc(o).catch(()=>null);if(!c||!c.isFile())throw new T("IPC_BAD_REQUEST",`not a file: ${e.filePath}`);if(c.isSymbolicLink())throw new T("IPC_BAD_REQUEST",`symlink not allowed: ${e.filePath}`);if(!await si(o,i))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${e.filePath}`);if(c.size>r0)throw new T("IPC_BAD_REQUEST",`file too large: ${c.size} bytes (max ${r0})`);let d=await ho(o);return d.includes(0)?{content:d.toString("base64"),encoding:"base64",size:c.size}:{content:d.toString("utf8"),encoding:"utf-8",size:c.size}}async resolveWorkspace(e){let r=this.opts.agents.get(e);return r?r.workspace:(await Pe(e).catch(()=>null))?.workspace??Xe(e).workspace}safeJoin(e,r){let i=nd(e,r||"."),o=sd(e,i);if(o.startsWith("..")||o===".."||o.startsWith(`..${o0}`))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${r}`);return i}loadAgentCfg(e){return Pe(e)}async requireAgentCfg(e){let r=await this.loadAgentCfg(e);if(!r)throw new T("AGENT_NOT_FOUND",`no config for agent: ${e}`);return r}};function d0(t){let e=t.trim().replace(/[\x00-\x1f<>:"|?*/\\]+/g,"-").replace(/^[\s.-]+|[\s.-]+$/g,"").slice(0,64);if(!e||e==="."||e==="..")throw new T("IPC_BAD_REQUEST",`invalid skill name: ${t}`);if(/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i.test(e))throw new T("IPC_BAD_REQUEST",`reserved windows filename: ${t}`);return e}function ad(t){return t==="claude-code"?xe(".claude","skills"):xe(".agents","skills")}function l0(t){let e=iy();return t==="claude-code"?[xe(e,".claude","skills")]:t==="codex"?[xe(e,".agents","skills"),xe(e,".codex","skills")]:[xe(e,".agents","skills"),xe(e,".openclaw","skills")]}async function py(t,e,r,i){let o=async c=>id(xe(c,"SKILL.md")).then(d=>d.isFile()).catch(()=>!1);if(!i){let c=xe(ad(e),r),d=xe(t,c);return await o(d)?{absDir:d,relPath:c}:null}for(let c of l0(e)){let d=xe(c,r);if(await o(d))return{absDir:d,relPath:d}}return null}async function gy(t,e,r,i,o){let c=d0(i),d=await py(e,r,c,o);if(d)return{...d,dirName:c};let h=(o?await p0(t,r):await x0(t,e,r)).filter(_=>_.skill.skillName===i);if(h.length>1)throw new T("SKILL_NOT_FOUND",`multiple skills named "${i}" in ${o?"global":"workspace"}: ${h.map(_=>n0(_.relPath)).join(", ")} \u2014 rename or remove duplicates`);let x=h[0];return x?{absDir:o?x.relPath:xe(e,x.relPath),relPath:x.relPath,dirName:n0(x.relPath)}:null}function u0(t,e){return(ry("sha256").update(`${t}\0${e}`).digest().readBigUInt64BE(0)&0x7fffffffffffffffn).toString()}function f0(t){if(!t.startsWith("---"))return{};let e=t.indexOf(`
|
|
93
|
+
---`,3);if(e<0)return{};let r=t.slice(3,e),i={};for(let o of r.split(`
|
|
94
|
+
`)){let c=/^\s*(name|description)\s*:\s*(.+?)\s*$/.exec(o);if(!c||!c[2])continue;let d=c[1],u=c[2].trim();(u.startsWith('"')&&u.endsWith('"')||u.startsWith("'")&&u.endsWith("'"))&&(u=u.slice(1,-1)),u&&(i[d]=u)}return i}async function h0(t,e,r,i){let o=await s0(e,{withFileTypes:!0}).catch(()=>null);if(!o)return[];let c=[];for(let d of o){let u=d.isDirectory();if(!u&&d.isSymbolicLink()&&(u=!!(await id(xe(e,d.name)).catch(()=>null))?.isDirectory()),!u)continue;let h=d.name,x=xe(r,h),m=xe(e,h,"SKILL.md"),_=await ho(m,{encoding:"utf8"}).catch(()=>null);if(_===null)continue;let S=f0(_);c.push({relPath:x,skill:{skillId:u0(t,x),skillName:S.name||h,...S.description?{description:S.description}:{},...i?{isGlobal:!0}:{}}})}return c}async function x0(t,e,r){let i=ad(r);return h0(t,xe(e,i),i,!1)}async function p0(t,e){let r=[],i=new Set;for(let o of l0(e)){let c=await h0(t,o,o,!0);for(let d of c)i.has(d.relPath)||(i.add(d.relPath),r.push(d))}return r}var my=3e4,wy=50*1024*1024,i0=10*1024*1024,Pr=3e4;async function po(t){let{agentId:e,workspace:r,framework:i,skill:o}=t;if(!o.skillName)throw new T("IPC_BAD_REQUEST","skill missing skillName");let c=typeof o.content=="string"&&o.content.length>0,d=typeof o.downloadUrl=="string"&&o.downloadUrl.length>0;if(!c&&!d)throw new T("IPC_BAD_REQUEST",`skill ${o.skillId} missing both content and downloadUrl`);let u=d0(o.skillName),h=ad(i),x=xe(h,u),m=xe(r,x);if(await Qc(m,{recursive:!0}),c){let S=Buffer.from(o.content,"utf8");Fi(S.length),await td(xe(m,"SKILL.md"),S,"utf8")}else{let S=await by(o.downloadUrl);vy(S)?await ky(S,m):Sy(S)?await Iy(S,m):await td(xe(m,"SKILL.md"),S.toString("utf8"),"utf8")}let _={skillId:o.skillId,skillName:o.skillName,relPath:x,installedAt:Date.now(),...o.description?{description:o.description}:{},...o.icon?{icon:o.icon}:{},...o.version?{version:o.version}:{},...o.downloadUrl?{downloadUrl:o.downloadUrl}:{},...o.config?{config:o.config}:{},...o.builtin?{builtin:o.builtin}:{}};return he.info("skill installed",{agentId:e,skillId:o.skillId,skillName:o.skillName,relPath:x,source:c?"content":"downloadUrl"}),_}function go(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 _y(t){return{skillId:t.skillId,skillName:t.skillName,...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}function yy(t){return{skillId:t.skillId,skillName:t.skillName,...t.downloadUrl?{downloadUrl:t.downloadUrl}:{},...t.description?{description:t.description}:{},...t.icon?{icon:t.icon}:{},...t.version?{version:t.version}:{},...t.config?{config:t.config}:{},...t.builtin?{builtin:t.builtin}:{}}}async function g0(t,e){let r=await Pe(t,e);if(!r)return{status:"skipped",count:0};if(r.disconnectedAt)return{status:"skipped",count:0};let i=Nt,o=r.skillsRefreshedForVersion;if(o===i)return{status:"noop",count:0};if(!o)return r.skillsRefreshedForVersion=i,await Ge(r,e),{status:"seeded",count:0};let c=[...r.skills??[]],d=new Map(c.map((m,_)=>[m.skillId,_])),u=c.filter(m=>m.builtin===!0&&!!m.downloadUrl);if(u.length===0)return r.skillsRefreshedForVersion=i,await Ge(r,e),{status:"noop",count:0};let h=0,x=0;for(let m of u)try{await ed(xe(r.workspace,m.relPath),{recursive:!0,force:!0});let _=await po({agentId:t,workspace:r.workspace,framework:r.framework,skill:yy(m)});go(c,d,_),h+=1}catch(_){x+=1,he.warn("refresh builtin skill failed (skipping)",{agentId:t,skillId:m.skillId,skillName:m.skillName,err:String(_)})}return r.skills=c,x===0&&(r.skillsRefreshedForVersion=i),await Ge(r,e),he.info("builtin skills refreshed after bridge upgrade",{agentId:t,from:o,to:i,ok:h,failed:x}),{status:"refreshed",count:h}}async function by(t){if(!t)throw new T("IPC_BAD_REQUEST","skill missing downloadUrl");if(t.startsWith("data:")){let e=Math.floor(t.length*3/4);Fi(e);let r=Ey(t);return Fi(r.length),r}if(t.startsWith("file:")){let e=new URL(t).pathname,r=await ho(e);return Fi(r.length),r}if(Ni(t)){let e=new AbortController,r=setTimeout(()=>e.abort(),my);try{let i=await fetch(t,{signal:e.signal});if(!i.ok)throw new T("IPC_BAD_REQUEST",`fetch skill failed HTTP ${i.status} ${t}`);let o=await i.arrayBuffer();return Fi(o.byteLength),Buffer.from(o)}finally{clearTimeout(r)}}throw new T("IPC_BAD_REQUEST",`unsupported downloadUrl scheme (\u8981 https/data/file): ${t.slice(0,80)}`)}function Fi(t){if(t>wy)throw new T("IPC_BAD_REQUEST",`skill too large: ${t} bytes`)}function Ey(t){let e=/^data:([^,;]*)(;base64)?,(.*)$/s.exec(t);if(!e)throw new T("IPC_BAD_REQUEST","bad data URL");let r=!!e[2],i=e[3]??"";return r?Buffer.from(i,"base64"):Buffer.from(decodeURIComponent(i),"utf8")}function vy(t){return t.length>=2&&t[0]===31&&t[1]===139}function Sy(t){if(t.length<4||t[0]!==80||t[1]!==75)return!1;let e=t[2],r=t[3];return e===3&&r===4||e===5&&r===6}function rd(t){return t==="__MACOSX"||t.startsWith("__MACOSX/")}async function Iy(t,e){let r,i;try{r=new od.default(t),i=r.getEntries()}catch(d){throw new T("IPC_BAD_REQUEST",`zip parse failed: ${d.message}`,{cause:d})}for(let d of i){let u=d.entryName;if(!u||rd(u))continue;if(u.startsWith("/")||/^[A-Za-z]:[\\/]/.test(u))throw new T("IPC_BAD_REQUEST",`zip entry absolute path: ${u}`);if(u.split(/[/\\]/).some(x=>x===".."))throw new T("IPC_BAD_REQUEST",`zip entry contains '..' (traversal): ${u}`);let h=d.header.attr>>>16&61440;if(h!==0&&h!==32768&&h!==16384)throw new T("IPC_BAD_REQUEST",`zip entry kind 0x${h.toString(16)} not allowed (symlink/hardlink/special): ${u}`)}let o=Ay(i),c=nd(e);for(let d of i){if(rd(d.entryName))continue;let u=d.entryName;if(o&&u.startsWith(o)&&(u=u.slice(o.length)),!u)continue;let h=nd(e,u),x=sd(c,h);if(x.startsWith("..")||x==="..")throw new T("IPC_BAD_REQUEST",`zip entry escapes destDir: ${u}`);if(d.isDirectory){await Qc(h,{recursive:!0});continue}await Qc(sy(h),{recursive:!0});let m;try{m=d.getData()}catch(_){throw new T("IPC_BAD_REQUEST",`zip entry getData failed (${d.entryName}): ${_.message}`,{cause:_})}await td(h,m)}}function Ay(t){let e;for(let r of t){let i=r.entryName;if(!i||rd(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 ky(t,e){await Ty(t);let r=Nf({cwd:e,strip:1}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar extract timeout (${Pr}ms)`))},Pr);try{await c0(a0.from(t),r)}catch(c){throw c instanceof T?c:i?new T("IPC_BAD_REQUEST",`tar extract timeout (${Pr}ms)`):new T("IPC_BAD_REQUEST",`tar extract failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}}async function Ty(t){let e=[],r=Tr({onReadEntry:c=>{let d=c.path,u=c.type;if(u!=="File"&&u!=="Directory"){e.push(`tar entry kind '${u}' not allowed (symlink/hardlink/special): ${d.slice(0,100)}`);return}if(d.startsWith("/")||d.startsWith("\\")||/^[a-zA-Z]:[\\/]/.test(d)){e.push(`tar entry absolute path: ${d}`);return}d.split(/[/\\]/).some(x=>x==="..")&&e.push(`tar entry contains '..': ${d}`)}}),i=!1,o=setTimeout(()=>{i=!0,r.destroy(new T("IPC_BAD_REQUEST",`tar list timeout (${Pr}ms)`))},Pr);try{await c0(a0.from(t),r)}catch(c){throw i?new T("IPC_BAD_REQUEST",`tar list timeout (${Pr}ms)`):new T("IPC_BAD_REQUEST",`tar list failed: ${c.message??String(c)}`,{cause:c})}finally{clearTimeout(o)}if(e.length>0)throw new T("IPC_BAD_REQUEST",e[0]??"tar entry validation failed")}var Cy=5e3;async function Ry(t,e,r,i){return m0(t,e,r,i,{count:0})}async function m0(t,e,r,i,o){if(i<=0)return[];let c;try{c=await s0(e,{withFileTypes:!0})}catch{return[]}let d=[];for(let u of c){if(dy.has(u.name)||u.isSymbolicLink())continue;if(o.count>=Cy){d.push({name:"...",path:"...",isDir:!1,size:0,modifiedAt:0,hasMore:!0});break}let h=xe(e,u.name),x=oy(xe(r,u.name)),m=null;try{m=await Yc(h)}catch{continue}if(m.isSymbolicLink())continue;o.count++;let _={name:u.name,path:w0(sd(t,h)),isDir:m.isDirectory(),size:m.size,modifiedAt:Math.floor(m.mtimeMs)};m.isDirectory()&&i>1&&(_.children=await m0(t,h,x,i-1,o)),d.push(_)}return d.sort((u,h)=>u.isDir!==h.isDir?u.isDir?-1:1:u.name.localeCompare(h.name)),d}function Dy(t){return!t||t<=0?ay:Math.min(t,cy)}function Py(t){if(!t||t==="."||t==="/")return".";let e=t.split(/[/\\]/);return e[e.length-1]||"."}function w0(t){return t.split(o0).join("/")}ne();var An=H("agent-health-reporter"),Oy=1e4,Ly=3,zi=class{constructor(e){this.opts=e;this.intervalMs=e.intervalMs??Oy,this.livenessFailureThreshold=e.livenessFailureThreshold??Ly}opts;timer=null;inFlight=!1;unsubscribeRegister=null;intervalMs;livenessFailureThreshold;consecutiveFailures=0;isLivenessLost(){return this.consecutiveFailures>=this.livenessFailureThreshold}start(){this.timer||(this.timer=setInterval(()=>{this.tick()},this.intervalMs),this.timer.unref?.(),this.unsubscribeRegister=this.opts.core.onAgentRegister(()=>{this.tick()}),An.info("heartbeat started",{intervalMs:this.intervalMs}),this.tick())}stop(){this.timer&&(clearInterval(this.timer),this.timer=null,this.unsubscribeRegister&&(this.unsubscribeRegister(),this.unsubscribeRegister=null),An.info("heartbeat stopped"))}async tick(){if(this.inFlight){An.debug("previous tick still in-flight, skip");return}let e=this.opts.getDeviceId();if(!e){this.consecutiveFailures=0,An.debug("deviceId not available, skip tick (\u5C1A\u672A pair)");return}this.inFlight=!0;try{let r=[];for(let d of this.opts.core.agents.values()){let u=Ny(d);if(!u)continue;let h={agentId:d.agentId,status:u};d.patToken&&(h.patToken=d.patToken),d.accountId&&(h.accountId=d.accountId),r.push(h)}if(r.length===0){this.consecutiveFailures=0;return}let i={agents:r,bridgeVersion:Nt,_meta:{cozeDeviceId:e}},o;try{o=await this.opts.core.sendRequest("_agent/health",i,5e3),this.consecutiveFailures=0}catch(d){this.consecutiveFailures+=1,An.warn("heartbeat batch send failed",{count:r.length,consecutiveFailures:this.consecutiveFailures,err:String(d)})}let c=o?.authFailures;if(c&&c.length>0&&(An.warn("heartbeat received authFailures from cloud",{count:c.length,agentIds:c.map(d=>d.agentId)}),this.opts.onAuthFailures))try{await this.opts.onAuthFailures(c)}catch(d){An.warn("onAuthFailures callback failed (ignored)",{err:String(d)})}}finally{this.inFlight=!1}if(this.opts.onTickEnd)try{await this.opts.onTickEnd()}catch(r){An.warn("onTickEnd hook failed",{err:String(r)})}}};function Ny(t){return t.status==="error"?"error":t.activeTriggers.size>0?"busy":t.status==="ok"?"online":null}fn();import{mkdir as hd,rm as Ob,stat as Lb}from"node:fs/promises";import{homedir as Nb}from"node:os";import{join as J0}from"node:path";dn();import{existsSync as Vy}from"node:fs";import{release as Jy}from"node:os";import{basename as Zy,isAbsolute as Xy}from"node:path";function Ui(t,e,r){return r===void 0?{jsonrpc:"2.0",id:t,method:e}:{jsonrpc:"2.0",id:t,method:e,params:r}}function Or(t,e){return e===void 0?{jsonrpc:"2.0",method:t}:{jsonrpc:"2.0",method:t,params:e}}function Lr(t,e){return{jsonrpc:"2.0",id:t,result:e}}function kn(t,e){return{jsonrpc:"2.0",id:t,error:e}}Ve();var mo=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)}},X={PARSE_ERROR:-32700,INVALID_REQUEST:-32600,METHOD_NOT_FOUND:-32601,INVALID_PARAMS:-32602,INTERNAL_ERROR:-32603,AGENT_NOT_FOUND:-32001,AGENT_BUSY:-32002,AGENT_TIMEOUT:-32003,AGENT_SPAWN_FAILED:-32004,OPERATION_NOT_ALLOWED_FOR_LOCAL:-32005,AGENT_DISCONNECTED:-32006,MODEL_TOKEN_GEN_FAILED:-32009,PATH_OUTSIDE_WORKSPACE:-32010,FILE_TOO_LARGE:-32011,UNSUPPORTED_MIME:-32012,UPLOAD_FAILED:-32013,UPSTREAM_NOT_READY:-32014,AGENT_FRAME_IDLE_TIMEOUT:-32016,MODEL_MODALITY_UNSUPPORTED:-32017,AGENT_DEPENDENCY_INSTALL_FAILED:-32018,AGENT_APPROVAL_TIMEOUT:-32019,AGENT_TURN_ABORTED:-32020,AGENT_ENV_NOT_READY:-32021,SKILL_NOT_FOUND:-32022,SKILL_ZIP_TOO_LARGE:-32023,OPERATION_NOT_ALLOWED_FOR_CLOUD:-32024};function _0(t){return"method"in t&&"id"in t&&t.id!==void 0}function y0(t){return"method"in t&&!("id"in t)}function wo(t){return!("method"in t)&&"id"in t}var My={AGENT_NOT_FOUND:X.AGENT_NOT_FOUND,AGENT_BUSY:X.AGENT_BUSY,AGENT_DISCONNECTED:X.AGENT_DISCONNECTED,AGENT_TIMEOUT:X.AGENT_TIMEOUT,AGENT_FRAME_IDLE_TIMEOUT:X.AGENT_FRAME_IDLE_TIMEOUT,AGENT_SPAWN_FAILED:X.AGENT_SPAWN_FAILED,AGENT_PROTOCOL_ERROR:X.INTERNAL_ERROR,BRIDGE_CONFIG_INVALID:X.INTERNAL_ERROR,BRIDGE_INTERNAL:X.INTERNAL_ERROR,IPC_AUTH_FAILED:X.INTERNAL_ERROR,IPC_BAD_REQUEST:X.INVALID_REQUEST,METHOD_NOT_FOUND:X.METHOD_NOT_FOUND,MODEL_TOKEN_GEN_FAILED:X.MODEL_TOKEN_GEN_FAILED,MODEL_MODALITY_UNSUPPORTED:X.MODEL_MODALITY_UNSUPPORTED,OPERATION_NOT_ALLOWED_FOR_LOCAL:X.OPERATION_NOT_ALLOWED_FOR_LOCAL,OPERATION_NOT_ALLOWED_FOR_CLOUD:X.OPERATION_NOT_ALLOWED_FOR_CLOUD,UPSTREAM_DISCONNECTED:X.INTERNAL_ERROR,UPSTREAM_HANDSHAKE_FAILED:X.INTERNAL_ERROR,PATH_OUTSIDE_WORKSPACE:X.PATH_OUTSIDE_WORKSPACE,FILE_TOO_LARGE:X.FILE_TOO_LARGE,UNSUPPORTED_MIME:X.UNSUPPORTED_MIME,UPLOAD_FAILED:X.UPLOAD_FAILED,UPSTREAM_NOT_READY:X.UPSTREAM_NOT_READY,AGENT_DEPENDENCY_INSTALL_FAILED:X.AGENT_DEPENDENCY_INSTALL_FAILED,AGENT_APPROVAL_TIMEOUT:X.AGENT_APPROVAL_TIMEOUT,AGENT_TURN_ABORTED:X.AGENT_TURN_ABORTED,AGENT_ENV_NOT_READY:X.AGENT_ENV_NOT_READY,SKILL_NOT_FOUND:X.SKILL_NOT_FOUND,SKILL_ZIP_TOO_LARGE:X.SKILL_ZIP_TOO_LARGE};function By(t){if(t!=null)return t instanceof Error?{name:t.name,message:Gi(t.message)}:typeof t=="string"?Gi(t):typeof t=="object"?zy(t):t}var Fy=[[/\/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 Gi(t){let e=t;for(let[r,i]of Fy)e=e.replace(r,i);return e}function zy(t){let e={};for(let[r,i]of Object.entries(t))typeof i=="string"?e[r]=Gi(i):e[r]=i;return e}function Hi(t){if(t instanceof T){let e=By(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:My[t.code]??X.INTERNAL_ERROR,message:Gi(t.message),data:r}}return{code:X.INTERNAL_ERROR,message:Gi(t instanceof Error?t.message:String(t))}}function b0(t){let e=t.data,r=e?.bridgeCode??"AGENT_PROTOCOL_ERROR",i=!!e&&typeof e.message=="string"&&!!e.message,o=i?e?.message:t.message,c=t.data;if(i&&e){let{message:d,...u}=e;c=u}return new T(r,o,{retriable:e?.retriable??!1,cause:c})}function v0(t){return`${JSON.stringify(t)}
|
|
95
|
+
`}var E0=10*1024*1024,_o=class{buffer="";onError;constructor(e={}){this.onError=e.onError}push(e){if(this.buffer+=typeof e=="string"?e:e.toString("utf8"),this.buffer.length>E0){let o=this.buffer.length;return this.buffer="",this.onError?.({line:`<buffer overflow: ${o} bytes, dropped>`,error:new Error(`LdjsonDecoder buffer exceeded ${E0} bytes`)}),[]}let r=this.buffer.split(`
|
|
96
|
+
`);this.buffer=r.pop()??"";let i=[];for(let o of r){let c=o.replace(/\r$/,"").trim();if(c)try{i.push(JSON.parse(c))}catch(d){this.onError?.({line:c,error:d})}}return i}flush(){if(!this.buffer)return[];let e=this.buffer.replace(/\r$/,"").trim();if(this.buffer="",!e)return[];try{return[JSON.parse(e)]}catch(r){return this.onError?.({line:e,error:r}),[]}}};var I0={"session/prompt":"session.prompt","session/cancel":"session.cancel","session/new":"session.new","session/load":"session.load","_agent/create":"agent.create","_agent/health":"agent.health","_agent/pair":"agent.pair","_agent/listSkills":"agent.listSkills","_agent/addSkills":"agent.addSkills","_agent/removeSkills":"agent.removeSkills","_agent/getFileTree":"agent.getFileTree","_agent/getFileContent":"agent.getFileContent","_agent/detail":"agent.detail","_agent/update":"agent.update","_agent/disconnect":"agent.disconnect","_agent/switchModel":"agent.switchModel","_agent/genModelToken":"agent.genModelToken","_agent/reset":"agent.reset","_agent/repair":"agent.repair","session/request_permission":"session.requestPermission","session/set_mode":"session.setMode",initialize:"initialize"},Kk=Object.fromEntries(Object.entries(I0).map(([t,e])=>[e,t])),Uy={"session.prompt":["agentId","triggerMsgId","sessionId"],"session.cancel":["agentId","triggerMsgId","sessionId"],"session.new":["agentId"],"session.load":["agentId"],"agent.create":["agentId"],"agent.health":[],"agent.listSkills":["agentId"],"agent.addSkills":["agentId"],"agent.removeSkills":["agentId"],"agent.getFileTree":["agentId"],"agent.getFileContent":["agentId"],"agent.detail":["agentId"],"agent.update":["agentId"],"agent.disconnect":["agentId"],"agent.switchModel":["agentId"],"agent.genModelToken":["agentId","sessionId"],"agent.reset":["agentId"],"agent.repair":["agentId"],"session.requestPermission":["agentId","sessionId"],"session.setMode":["agentId","sessionId"],"agent.pair":[],initialize:[]},Nr=class{seq=0;next(e,r){this.seq+=1;let i=I0[e]??Gy(e),o=Uy[i]??[],c=[i,String(this.seq)];if(o.length>0){let d=o.map(h=>S0(r?.[h]??"")),u=Hy(d).join(":");u&&c.push(u)}else r&&Object.values(r).some(d=>d)&&c.push(Object.values(r).filter(Boolean).map(d=>S0(String(d))).join(":"));return c.join("_")}reset(){this.seq=0}};function Gy(t){return t.replace(/[\s/]+/g,".").replace(/_+/g,"-")}function S0(t){return t.replace(/[:_\s]+/g,"-")}function Hy(t){let e=t.length;for(;e>0&&!t[e-1];)e-=1;return t.slice(0,e)}un();import{readFileSync as qy}from"node:fs";var jy=384;async function cd(t,e=process.env){let r={};for(let[i,o]of Object.entries(e))typeof o=="string"&&(r[i]=o);await ur(t.agentEnvFile,r,{mode:jy})}function dd(t){try{let e=JSON.parse(qy(t,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}}function A0(t,e,r={},i=o=>o){return{...i({...t,...dd(e)}),...r}}Xt();or();Ve();ne();Be();import{execFileSync as Wy,spawnSync as Ky}from"node:child_process";function qi(t){try{return process.kill(t,0),!0}catch(e){return e.code==="EPERM"}}function ji(t,e){if(!(typeof t!="number"||t<=0))try{if(process.platform==="win32"){let r=["/PID",String(t),"/T"];e==="SIGKILL"&&r.push("/F"),Ky("taskkill",r,{stdio:"ignore",windowsHide:!0})}else process.kill(-t,e)}catch{}}var ld=new Set;function k0(t){typeof t=="number"&&t>0&&ld.add(t)}function T0(t){typeof t=="number"&&ld.delete(t)}function C0(){for(let t of ld)ji(t,"SIGKILL")}var Mr="coze-bridge-daemon";function R0(t){let e=t?.execFn??(()=>{if(process.platform==="win32")return"";let o=process.getuid?.()??0;return Wy("pgrep",["-U",String(o),"-f",Mr],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:2e3})}),r;try{r=e()}catch{return[]}let i=process.pid;return r.split(`
|
|
97
|
+
`).map(o=>Number.parseInt(o.trim(),10)).filter(o=>Number.isFinite(o)&&o>0&&o!==i)}async function D0(t,e){if(t.length===0)return;let r=e?.killFn??ji,i=e?.isAliveFn??qi,o=e?.sleepFn??(u=>new Promise(h=>setTimeout(h,u))),c=e?.graceMs??3e3,d=e?.pollMs??100;for(let u of t)r(u,"SIGTERM");for(let u=0;u<c&&t.some(h=>i(h));u+=d)await o(Math.min(d,c-u));for(let u of t)i(u)&&r(u,"SIGKILL")}var $y=[{reason:"openclaw_scope_approval_pending",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/scope upgrade pending approval/i,message:"openclaw \u9700\u8981\u4F60\u5728\u672C\u673A\u6279\u51C6\u4E00\u6B21\u6743\u9650\u5347\u7EA7 (scope upgrade)\uFF0C\u8BF7\u5728\u672C\u673A openclaw \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5"},{reason:"openclaw_pairing_required",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/pairing required/i,message:"openclaw \u5C1A\u672A\u5B8C\u6210\u914D\u5BF9\uFF0C\u8BF7\u5148\u5728\u672C\u673A\u5B8C\u6210 openclaw \u914D\u5BF9\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_token_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway\.auth\.token.*(unavailable|secret reference)/i,message:"openclaw gateway token \u914D\u7F6E\u4E0D\u53EF\u7528 (\u914D\u6210\u4E86 secret \u5F15\u7528\u4F46\u5F53\u524D\u8DEF\u5F84\u53D6\u4E0D\u5230)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A openclaw \u7684 gateway.auth.token \u914D\u7F6E"},{reason:"openclaw_version_mismatch",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/protocol mismatch/i,message:"openclaw \u7248\u672C\u4E0E\u672C\u673A gateway \u4E0D\u517C\u5BB9 (protocol mismatch)\uFF0C\u8BF7\u5347\u7EA7\u672C\u673A openclaw \u5230\u6700\u65B0\u7248\u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_not_ready",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/gateway closed (before ready|\(\d+\))/i,message:"openclaw gateway \u672A\u5C31\u7EEA (\u53EF\u80FD\u6B63\u5728\u542F\u52A8)\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5"},{reason:"openclaw_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/OpenClaw config is invalid|Config invalid|Invalid config at|config was written by version/i,message:"\u4F60\u7684\u672C\u673A openclaw \u914D\u7F6E\u975E\u6CD5 (~/.openclaw/openclaw.json)\uFF0C\u8BF7\u8FD0\u884C `openclaw doctor --fix` \u6216 `openclaw config validate` \u4FEE\u590D\u540E\u91CD\u8BD5"},{reason:"openclaw_tls_self_signed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/self-signed certificate/i,message:"openclaw \u8FDE\u63A5\u88AB\u81EA\u7B7E\u8BC1\u4E66/\u4F01\u4E1A\u4EE3\u7406\u62E6\u622A (self-signed certificate)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A\u7F51\u7EDC/\u4EE3\u7406\u6216\u8BC1\u4E66\u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"openclaw_node_binary_not_found",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/\[qclaw-cli\] Error: (Node binary not found|QCLAW_CLI_NODE_BINARY not set)/i,message:"\u672C\u673A\u627E\u4E0D\u5230 node \u4E8C\u8FDB\u5236 (qclaw \u542F\u52A8\u5931\u8D25)\uFF0C\u8BF7\u68C0\u67E5\u672C\u673A Node \u5B89\u88C5\u4E0E PATH \u540E\u91CD\u8BD5"},{reason:"openclaw_gateway_unavailable",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["openclaw"],match:/ECONNREFUSED|\[object ErrorEvent\]|gateway connect failed|gateway (not connected|disconnected)/i,message:"openclaw gateway \u672A\u8FD0\u884C/\u672A\u8FDE\u63A5 (\u8FDE\u63A5\u672C\u673A gateway \u88AB\u62D2\u6216\u4F1A\u8BDD\u671F\u95F4\u65AD\u5F00)\uFF0C\u8BF7\u5728\u672C\u673A\u542F\u52A8 openclaw gateway \u540E\u91CD\u8BD5"},{reason:"openclaw_shim_bug",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["openclaw"],match:/openclaw-shim\/bin\/openclaw.*unbound variable/i,message:"openclaw \u542F\u52A8 shim \u811A\u672C\u5F02\u5E38 (unbound variable)\uFF0C\u8BF7\u53CD\u9988\u73AF\u5883\u7EF4\u62A4\u65B9\u4FEE\u590D shim"},{reason:"codex_user_config_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config:.*config\.toml|model_catalog_json|wire_api/i,message:"\u4F60\u7684\u672C\u673A ~/.codex/config.toml \u914D\u7F6E\u6709\u8BEF\uFF0C\u8BF7\u6309 codex \u62A5\u9519\u63D0\u793A\u4FEE\u6B63\u540E\u91CD\u8BD5"},{reason:"codex_provider_invalid",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/error loading config: Model provider .* not found/i,message:"\u4F60\u7684\u672C\u673A codex \u914D\u7F6E\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684 model provider\uFF0C\u8BF7\u4FEE\u6B63 ~/.codex \u914D\u7F6E\u540E\u91CD\u8BD5"},{reason:"codex_path_update_failed",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/could not update PATH[\s\S]*Operation not permitted/i,message:"codex \u56E0\u672C\u673A\u6743\u9650\u9650\u5236\u65E0\u6CD5\u66F4\u65B0 PATH/\u8BFB\u53D6\u914D\u7F6E (Operation not permitted)\uFF0C\u8BF7\u68C0\u67E5 ~/.codex \u76EE\u5F55\u6743\u9650\u6216\u91CD\u65B0\u6388\u4E88\u7EC8\u7AEF\u5B8C\u5168\u78C1\u76D8\u8BBF\u95EE\u540E\u91CD\u8BD5"},{reason:"node_version_too_old",bridgeCode:"AGENT_ENV_NOT_READY",frameworks:["codex"],match:/import\.meta\.resolve is not a function|\.resolve is not a function/i,message:"\u672C\u673A Node \u7248\u672C\u8FC7\u4F4E (codex ACP \u9700\u8981 import.meta.resolve)\uFF0C\u8BF7\u5347\u7EA7 Node \u5230 \u2265 20 \u540E\u91CD\u8BD5"},{reason:"codex_acp_exec_failed",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to execute[\s\S]*codex-acp|spawnSync[\s\S]*codex-acp/i,message:"codex ACP \u4E8C\u8FDB\u5236\u6267\u884C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"codex_platform_binary_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["codex"],match:/Failed to locate @zed-industries\/codex-acp|optional dependency was not installed/i,message:"codex ACP \u4F9D\u8D56\u7684\u5E73\u53F0\u4E8C\u8FDB\u5236\u7F3A\u5931\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C pair/connect \u89E6\u53D1\u4F9D\u8D56\u5B89\u88C5"},{reason:"acp_module_missing",bridgeCode:"AGENT_SPAWN_FAILED",frameworks:["claude-code","codex"],match:/Cannot find (module|package)[^\n]*node_modules[\\/]@(agentclientprotocol[\\/](claude-agent-acp|codex-acp)|openai[\\/]codex|zed-industries[\\/]codex-acp)|Cannot find package ['"]@openai[\\/]codex['"][\s\S]*node_modules[\\/]@agentclientprotocol[\\/]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 P0(t,e){if(!e)return null;for(let r of $y)if(!(r.frameworks&&!r.frameworks.includes(t))&&r.match.test(e))return{bridgeCode:r.bridgeCode,reason:r.reason,message:r.message};return null}function O0(t,e){return P0(t,e)}function L0(t,e){return P0(t,e)}function Br(t,e,r){return!e&&r.firstUpdateMs>0&&t<r.firstUpdateMs?Math.max(1,r.firstUpdateMs-t):t<r.phase2GateMs?Math.max(1,r.phase2GateMs-t):Math.max(1,r.livenessWindowMs)}function N0(t,e,r){let o=r-t.armedAt-t.expectedIntervalMs;if(o>e.suspendThresholdMs){let x=t.suspendedMs+o,m=r-t.startedAt-x;return{action:"suspend",suspendedDeltaMs:o,rearmMs:Br(m,t.firstFrameSeen,e)}}let c=r-t.startedAt-t.suspendedMs,d=t.awaitingApproval?e.approvalMaxMs:e.absoluteMaxMs;return c>=d?{action:"reject-backstop",awaitingApproval:t.awaitingApproval}:t.firstFrameSeen?c<e.phase2GateMs?{action:"continue",rearmMs:Br(c,!0,e)}:r-t.lastActivityAt<e.livenessWindowMs||t.hasActiveTool||t.awaitingApproval?{action:"continue",rearmMs:Br(c,!0,e)}:{action:"reject-idle"}:e.firstUpdateMs>0&&c>=e.firstUpdateMs&&!t.awaitingApproval?{action:"reject-idle"}:{action:"continue",rearmMs:Br(c,!1,e)}}var M0=Ze("COZE_BRIDGE_INITIALIZE_TIMEOUT_MS",3e4),Yy=200,Qy=40,eb=Ze("COZE_BRIDGE_SESSION_PROMPT_MAX_MS",3600*1e3),tb=Ze("COZE_BRIDGE_SESSION_PROMPT_IDLE_MS",600*1e3),nb=Ze("COZE_BRIDGE_SESSION_PROMPT_ABSOLUTE_MAX_MS",7200*1e3),rb=Ze("COZE_BRIDGE_SUSPEND_THRESHOLD_MS",60*1e3),ib=Ze("COZE_BRIDGE_SESSION_PROMPT_FIRST_UPDATE_MS",600*1e3),sb=Ze("COZE_BRIDGE_SESSION_PROMPT_APPROVAL_MAX_MS",1440*60*1e3),B0=500;function ob(t){try{let e=JSON.stringify(t);return e===void 0||e.length<=B0?t:`${e.slice(0,B0)}...<truncated, total ${e.length} chars>`}catch{return"<unserializable>"}}function ab(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 F0(t){try{return Vy(t)}catch{return}}function cb(t,e){return{platform:process.platform,osRelease:Jy(),code:t.code,errno:t.errno,syscall:t.syscall,errPath:t.path,command:e.command,commandExists:Xy(e.command)?F0(e.command):void 0,cwd:e.cwd,cwdExists:F0(e.cwd),envKeys:e.envKeys}}function db(t,e){return`${t.message} [diag: platform=${e.platform} os=${e.osRelease} code=${e.code} errno=${e.errno} syscall=${e.syscall} cmd=${Zy(e.command)} cmdExists=${e.commandExists} cwdExists=${e.cwdExists} envKeys=${e.envKeys}]`}var Bt=class{constructor(e){this.opts=e;this.log=H(`downstream.${this.constructor.name}`,this.opts.agentId),this.decoder=new _o({onError:r=>this.log.warn("decode line failed",{line:r.line})})}opts;child;decoder;pending=new Map;inflightAgentRequests=new Map;idAllocator=new Nr;updateHandlers=[];agentRequestHandlers=[];exitHandlers=[];log;stopped=!1;stopReason;stderrRing=[];now=Date.now;sanitizeEnv(e){return e}async start(){if(this.child)throw new T("BRIDGE_INTERNAL","Downstream already started");let e=process.platform!=="win32",r=A0(process.env,this.opts.agentEnvFile??ee().agentEnvFile,this.opts.env,o=>this.sanitizeEnv(o)),i=ot(this.opts.command,this.opts.args,{cwd:this.opts.cwd,env:r,stdio:["pipe","pipe","pipe"],detached:e});this.child=i,k0(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>Yy&&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,T0(i.pid),(o!==0||c!==null)&&this.stderrRing.length>0&&this.log.warn("downstream exited abnormally, recent stderr",{code:o,signal:c,recentStderr:[...this.stderrRing]});try{for(let u of this.decoder.flush())this.dispatch(u)}catch(u){this.log.debug("decoder.flush on exit threw (ignored)",{err:String(u)})}this.failAllPending(this.buildExitError(o,c));for(let u of this.exitHandlers)u(o,c)}),i.on("error",o=>{let c=o,d=cb(c,{command:this.opts.command,cwd:this.opts.cwd,envKeys:Object.keys(r).length});this.log.error("child error",{err:String(o),diag:d}),this.failAllPending(new T("AGENT_SPAWN_FAILED",db(c,d),{cause:d}))}),this.log.info("downstream started",{command:this.opts.command,pid:i.pid,cwd:this.opts.cwd})}async stop(e){if(!this.child||this.stopped)return;this.stopped=!0,this.stopReason=e??"stopped",this.log.info("downstream stopping",{reason:e});let r=this.child,i=new Promise(c=>r.once("exit",()=>c()));ji(r.pid,"SIGTERM");let o=setTimeout(()=>{r.killed||ji(r.pid,"SIGKILL")},5e3);try{await i}finally{clearTimeout(o)}}pid(){return this.child?.pid}isAlive(){return!!this.child&&!this.stopped}getStderrTail(e){return e===void 0?[...this.stderrRing]:this.stderrRing.slice(-e)}initialize(e){return this.call("initialize",e)}sessionNew(e){return this.call("session/new",{mcpServers:[],...e})}sessionLoad(e){return this.call("session/load",{mcpServers:[],...e})}sessionPrompt(e,r){let i={firstUpdateMs:ib,phase2GateMs:eb,livenessWindowMs:tb,absoluteMaxMs:nb,approvalMaxMs:sb,suspendThresholdMs:rb,...r};return this.call("session/prompt",e,M0,i)}async sessionCancel(e){!this.child||this.stopped||this.writeFrame(Or("session/cancel",e))}setSessionMode(e){return this.call("session/set_mode",e)}onUpdate(e){this.updateHandlers.push(e)}onAgentRequest(e){this.agentRequestHandlers.push(e)}respondAgentRequest(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(Lr(e,r))}catch(i){this.log.warn("respondAgentRequest write failed",{id:e,err:String(i)})}}respondAgentRequestError(e,r){if(this.inflightAgentRequests.delete(e),!(!this.child||this.stopped))try{this.writeFrame(kn(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 T("AGENT_PROTOCOL_ERROR","downstream not started"));let c=this.idAllocator.next(e),d=Ui(c,e,r),u=(()=>{if(typeof r!="object"||r===null)return;let h=r.sessionId;return typeof h=="string"?h:void 0})();return new Promise((h,x)=>{let m={resolve:h,reject:x,timer:null,method:e,promptTimeout:null};if(o){let _=this.now(),S={cfg:o,startedAt:_,lastActivityAt:_,firstFrameSeen:!1,activeToolCalls:new Set,suspendedMs:0,armedAt:_,expectedIntervalMs:Br(0,!1,o),sessionId:u};m.promptTimeout=S;let y=()=>{let v={startedAt:S.startedAt,lastActivityAt:S.lastActivityAt,firstFrameSeen:S.firstFrameSeen,hasActiveTool:S.activeToolCalls.size>0,awaitingApproval:this.inflightAgentRequests.size>0,suspendedMs:S.suspendedMs,armedAt:S.armedAt,expectedIntervalMs:S.expectedIntervalMs},I=this.now(),A=N0(v,S.cfg,I),C=P=>{S.armedAt=I,S.expectedIntervalMs=P,m.timer=setTimeout(y,P)};if(A.action==="suspend"){S.suspendedMs+=A.suspendedDeltaMs,S.lastActivityAt=I,this.log.warn("downstream prompt timer: suspend detected",{id:c,method:e,gapMs:A.suspendedDeltaMs,suspendedMs:S.suspendedMs,...S.sessionId?{sessionId:S.sessionId}:{}}),C(A.rearmMs);return}if(A.action==="continue"){C(A.rearmMs);return}this.pending.delete(c),A.action==="reject-backstop"?(this.log.warn("downstream prompt absolute timeout",{id:c,method:e,awaitingApproval:A.awaitingApproval,...S.sessionId?{sessionId:S.sessionId}:{}}),x(A.awaitingApproval?new T("AGENT_APPROVAL_TIMEOUT",`${e} awaiting permission timed out after ${S.cfg.approvalMaxMs}ms`):new T("AGENT_TIMEOUT",`${e} timed out after ${S.cfg.absoluteMaxMs}ms`))):(this.log.warn("downstream prompt idle timeout",{id:c,method:e,...S.sessionId?{sessionId:S.sessionId}:{}}),x(new T("AGENT_FRAME_IDLE_TIMEOUT",`${e} no progress within ${S.cfg.livenessWindowMs}ms`)))};m.timer=setTimeout(y,S.expectedIntervalMs)}else i>0&&Number.isFinite(i)&&(m.timer=setTimeout(()=>{this.pending.delete(c),this.log.warn("downstream call timeout",{id:c,method:e,timeoutMs:i}),x(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i));this.pending.set(c,m);try{this.writeFrame(d)}catch(_){m.timer&&clearTimeout(m.timer),this.pending.delete(c),x(_)}})}writeFrame(e){if(!this.child?.stdin||this.child.stdin.destroyed)throw new T("AGENT_PROTOCOL_ERROR","downstream stdin not writable");this.child.stdin.write(v0(e),r=>{r&&this.log.warn("stdin write callback err",{err:String(r)})})}dispatch(e){if(wo(e)){let r=e.id!==null?this.pending.get(e.id):void 0;if(!r){this.log.warn("orphan response",{id:e.id});return}this.pending.delete(e.id),r.timer&&clearTimeout(r.timer),e.error?(this.log.warn("downstream returned error frame",{id:e.id,method:r.method,code:e.error.code,message:e.error.message,data:e.error.data}),r.reject(this.wireErrorToBridge(e.error))):e.result===void 0?(this.log.warn("downstream response missing both result and error",{id:e.id,method:r.method}),r.reject(new T("AGENT_PROTOCOL_ERROR",`${r.method} response missing both result and error`))):(this.log.info("downstream returned result",{id:e.id,method:r.method,result:ob(e.result)}),r.resolve(e.result));return}if(y0(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(_0(e)){let r=e;try{this.handleAgentRequest(r).catch(i=>this.log.error("agent request handler failed (async)",{method:r.method,err:String(i)}))}catch(i){this.log.warn("handleAgentRequest threw sync, swallowed",{method:r.method,err:String(i)})}}}trackToolCall(e,r){let i=r.update,o=i?.sessionUpdate;if(o!=="tool_call"&&o!=="tool_call_update")return;let c=typeof i.toolCallId=="string"?i.toolCallId:void 0;if(!c)return;let d=typeof i.status=="string"?i.status:void 0,u=d==="completed"||d==="failed"||d==="cancelled";o==="tool_call"&&!u?e.activeToolCalls.add(c):u&&e.activeToolCalls.delete(c)}async handleAgentRequest(e){if(this.agentRequestHandlers.length===0){this.writeFrame(kn(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(kn(e.id,Hi(i)))}catch{}this.inflightAgentRequests.delete(e.id)}}wireErrorToBridge(e){let r=b0(e);if(r.code!=="AGENT_PROTOCOL_ERROR")return r;let i=L0(this.framework,ab(e));return i?new T(i.bridgeCode,i.message,{cause:{reason:i.reason,wireCode:e.code,wireMessage:e.message,wireData:e.data}}):r}buildExitError(e,r){if(this.stopReason!==void 0)return new T("AGENT_TURN_ABORTED",`turn aborted: ${this.stopReason}`,{cause:{reason:this.stopReason}});let i=this.getStderrTail(Qy).join(`
|
|
98
|
+
`),o=O0(this.framework,i);return o?new T(o.bridgeCode,o.message,{cause:{reason:o.reason,code:e,signal:r,stderrTail:i}}):new T("AGENT_PROTOCOL_ERROR",`agent exited (${e}/${r})`,{cause:{code:e,signal:r,stderrTail:i}})}failAllPending(e){for(let r of this.pending.values())r.timer&&clearTimeout(r.timer),r.reject(e);this.pending.clear(),this.inflightAgentRequests.clear()}};function lb(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 yo=class extends Bt{framework="claude-code";constructor(e){let{command:r,args:i}=ii("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 lb(e)}};dn();import{mkdtempSync as ub,rmSync as fb}from"node:fs";import{tmpdir as hb}from"node:os";import{join as xb}from"node:path";var z0=["default","acceptEdits","plan","auto","bypassPermissions"],U0=["read-only","auto","full-access"];function Ft(t,e){if(typeof e!="string")return!1;switch(t){case"claude-code":return z0.includes(e);case"codex":return U0.includes(e);case"openclaw":return!1}}function bo(t){switch(t){case"read-only":return"read-only";case"auto":return"agent";case"full-access":return"agent-full-access"}}function G0(t){switch(t){case"read-only":return"read-only";case"agent":return"auto";case"agent-full-access":return"full-access";default:return}}function ud(t){switch(t){case"claude-code":return z0.join("/");case"codex":return U0.join("/");case"openclaw":return""}}var Eo=class extends Bt{framework="codex";authMethodId;codexHomeDir;constructor(e){let r=e.args??[],i=e.extraArgs?[...r,...e.extraArgs]:r,{command:o,args:c}=ii("codex",e.command,i),d=e.isolateCodexHome?ub(xb(hb(),"coze-bridge-codex-home-")):void 0,u=d?{...e.env??{},CODEX_HOME:d}:e.env,h={command:o,args:c,cwd:e.cwd,agentId:e.agentId,...u?{env:u}:{}};super(h),this.authMethodId=e.authMethodId,this.codexHomeDir=d}async initialize(e){let r=await super.initialize(e);return this.authMethodId&&await this.call("authenticate",{methodId:this.authMethodId}),r}setSessionMode(e){let r=Ft("codex",e.modeId)?bo(e.modeId):e.modeId;return super.setSessionMode({...e,modeId:r})}onUpdate(e){super.onUpdate(r=>e(pb(r)))}async stop(e){if(await super.stop(e),this.codexHomeDir)try{fb(this.codexHomeDir,{recursive:!0,force:!0})}catch{}}};function pb(t){let e=t.update;if(e.sessionUpdate!=="current_mode_update"||typeof e.currentModeId!="string")return t;let r=G0(e.currentModeId);return!r||r===e.currentModeId?t:{...t,update:{...t.update,currentModeId:r}}}Ve();var gb=3e4,Fr=class extends Bt{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}`}]},gb))}get acpSessionName(){return this.sessionName}setSessionMode(e){return Promise.reject(new T("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"))}};un();Ve();ne();Be();function fd(t){return t.replace(/[^A-Za-z0-9._-]+/g,"-")}dn();var Tn=class{slots=[];running=!1;closed=!1;disposed=!1;enqueue(e){return this.disposed?Promise.reject(new Error("AsyncQueue disposed")):this.closed?Promise.reject(new Error("AsyncQueue closed")):new Promise((r,i)=>{this.slots.push({task:e,resolve:r,reject:i}),this.drain()})}close(){this.closed=!0}dispose(e=new Error("AsyncQueue disposed")){for(this.disposed=!0,this.closed=!0;this.slots.length>0;)this.slots.shift()?.reject(e)}get size(){return this.slots.length}get isRunning(){return this.running}get isDisposed(){return this.disposed}async drain(){if(!this.running){this.running=!0;try{for(;this.slots.length>0&&!this.disposed;){let e=this.slots.shift();if(!e)break;try{let r=await e.task();e.resolve(r)}catch(r){e.reject(r)}}}finally{this.running=!1}}}};var vo=class{agentId;framework;workspace;deployType;accountId;patToken;modelInfo;sessions=new Map;sessionQueues=new Map;activeTriggers=new Map;activeGroupIds=new Map;status="ok";model;lastActiveAt=Date.now();constructor(e){this.agentId=e.agentId,this.framework=e.framework,this.workspace=e.workspace,this.model=e.model,this.deployType=e.deployType??"local",e.accountId&&(this.accountId=e.accountId),e.patToken&&(this.patToken=e.patToken),e.modelInfo&&(this.modelInfo=e.modelInfo)}setPatToken(e){this.patToken=e}setModelInfo(e){this.modelInfo=e}getSessionQueue(e){let r=this.sessionQueues.get(e);return(!r||r.isDisposed)&&(r=new Tn,this.sessionQueues.set(e,r)),r}allSessionQueues(){return this.sessionQueues.entries()}hasSessionQueue(e){let r=this.sessionQueues.get(e);return!!r&&!r.isDisposed}async dispose(e){this.status="stopped";let r=new Error(`AgentSession disposed${e?`: ${e}`:""}`);for(let i of this.sessionQueues.values())i.dispose(r);this.sessionQueues.clear(),await this.killAllRuntimes(e??"dispose")}async killAllRuntimes(e){let r=[];for(let[,i]of this.sessions)Wi(i),i.downstream&&(r.push(i.downstream.stop(e).catch(()=>{})),i.downstream=void 0);await Promise.all(r),this.activeTriggers.clear(),this.activeGroupIds.clear()}};function Wi(t){t.idleTimer&&(clearTimeout(t.idleTimer),t.idleTimer=void 0)}function Yt(t){return t.deployType!=="local"?!1:t.framework==="claude-code"||t.framework==="codex"}Xt();ne();import{constants as H0}from"node:fs";import{access as mb}from"node:fs/promises";import{delimiter as wb,join as _b}from"node:path";var It=H("framework-detector"),q0={"claude-code":"claude",codex:"codex",openclaw:"openclaw"},yb=[".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??ot,access:e.access??mb}}async detect(e){let r=q0[e],i=await this.which(r);if(!i)return It.debug("framework binary not found",{framework:e,bin:r}),null;let o=e==="openclaw"?["--log-level","silent"]:[],[c,d]=await Promise.all([this.probeVersion(i,o),e==="openclaw"?this.probeOpenclawDefaultAgent(i):Promise.resolve(null)]),u={path:i,version:c};return d&&(u.defaultAgent=d),u}async detectAll(){let e=await Promise.all(Object.keys(q0).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(wb).filter(Boolean),i=this.env.platform==="win32"?["",...yb]:[""];for(let o of r)for(let c of i){let d=_b(o,e+c);if(await this.isExecutable(d))return d}return null}async isExecutable(e){try{let r=this.env.platform==="win32"?H0.F_OK:H0.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 It.warn("openclaw default agent probe: runProbe returned null (spawn err / timeout)",{path:e}),null;if(r.code!==0)return It.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 It.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 It.warn("openclaw default agent probe: JSON parsed but not an array",{path:e}),null;let c=o.find(d=>d?.isDefault===!0);return c?!c.id||!c.workspace?(It.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}:(It.info("openclaw default agent probe: no agent has isDefault=true",{path:e,agentCount:o.length}),null)}catch(o){return It.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 It.warn("openclaw gateway probe: runProbe returned null (spawn err / timeout)",{path:e}),{reachable:!1};let i=r.code===0;i||It.warn("openclaw gateway probe: non-zero exit (gateway unreachable)",{path:e,code:r.code,stdoutHead:r.stdout.slice(0,200)});let o={reachable:i},c=r.stdout.match(/\{[\s\S]*\}/);if(c)try{let d=JSON.parse(c[0]);typeof d.gateway?.port=="number"&&(o.port=d.gateway.port),typeof d.service?.runtime?.status=="string"&&(o.runtime=d.service.runtime.status),!i&&typeof d.rpc?.error=="string"&&(o.detail=d.rpc.error)}catch(d){It.warn("openclaw gateway probe: JSON.parse failed (detail omitted, gate by exit code)",{path:e,err:String(d)})}return o}async probeVersion(e,r=[]){let i=await this.runProbe(e,[...r,"--version"]);return i&&(Eb(i.stdout).split(/\r?\n/)[0]??"").trim()||"unknown"}runProbe(e,r){return new Promise(i=>{let o="",c=!1,d,u=h=>{c||(c=!0,d&&clearTimeout(d),i(h))};try{let h=this.env.spawn(e,r,{stdio:["ignore","pipe","pipe"]});d=setTimeout(()=>{h.kill("SIGKILL"),u(null)},15e3),h.stdout?.on("data",x=>{o+=x.toString("utf8")}),h.on("error",()=>u(null)),h.on("close",x=>u({code:x,stdout:o}))}catch{u(null)}})}},bb=new RegExp("\x1B\\[[0-9;]*[A-Za-z]","g");function Eb(t){return t.replace(bb,"")}import{homedir as vb}from"node:os";import{join as Sb}from"node:path";un();Xt();or();Ve();ne();async function K0(){let t=Sb(vb(),".openclaw/openclaw.json");return lr(t)}async function $0(){return(await K0())?.gateway?.auth?.token??""}var j0=H("openclaw.config"),Ib=[0,5e3,5e3],Ab=Ze("COZE_BRIDGE_OPENCLAW_CLI_TIMEOUT_MS",15e3),W0="models.providers.",So="agents.defaults.models",Io=class{command;env;retryDelaysMs;cliTimeoutMs;queue=new Tn;constructor(e){this.command=e.command,this.env=e.env??process.env,this.retryDelaysMs=e.retryDelaysMs??Ib,this.cliTimeoutMs=e.cliTimeoutMs??Ab}async withRetry(e,r){let i;for(let o=0;o<this.retryDelaysMs.length;o++){let c=this.retryDelaysMs[o]??0;c>0&&await new Promise(d=>setTimeout(d,c));try{return await r()}catch(d){i=d,j0.warn("openclaw cli failed, will retry",{label:e,attempt:o+1,err:String(d)})}}throw new T("AGENT_SPAWN_FAILED",`openclaw cli ${e} failed after ${this.retryDelaysMs.length} attempts: ${i?.message??"unknown"}`)}runCli(e){return new Promise((r,i)=>{let o=ot(this.command,e,{stdio:["ignore","ignore","pipe"],env:this.env}),c="",d=!1,u=x=>{d||(d=!0,clearTimeout(h),x())};o.stderr?.on("data",x=>{c+=x.toString("utf8")});let h=setTimeout(()=>{u(()=>{o.kill("SIGTERM"),setTimeout(()=>o.kill("SIGKILL"),250).unref(),i(new Error(`timeout after ${this.cliTimeoutMs}ms: ${e.join(" ")}`))})},this.cliTimeoutMs);h.unref(),o.on("error",x=>u(()=>i(x))),o.on("close",x=>u(()=>{x===0?r():i(new Error(`exit ${x}: ${c.trim().slice(0,500)}`))}))})}async runCliTolerant(e,r){try{await this.runCli(e)}catch(i){let o=String(i);if(r.some(c=>o.includes(c)))return;throw i}}async bestEffortUnset(e,r){try{await this.queue.enqueue(()=>this.withRetry(e,()=>this.runCli(["config","unset",r])))}catch(i){j0.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",`${W0}${e}`,JSON.stringify(r),"--strict-json","--merge"])))}removeProvider(e){return this.bestEffortUnset(`config unset models.providers.${e}`,`${W0}${e}`)}addModelToAllowlist(e,r){let i={[e]:r?{alias:r}:{}};return this.queue.enqueue(()=>this.withRetry(`config set ${So}[${e}]`,()=>this.runCli(["config","set",So,JSON.stringify(i),"--strict-json","--merge"])))}removeModelFromAllowlist(e){return this.bestEffortUnset(`config unset ${So}[${e}]`,`${So}.${e}`)}async getAllowlistModelsForProvider(e){let i=(await K0())?.agents?.defaults?.models;if(!i||typeof i!="object")return[];let o=`${e}/`,c=[];for(let d of Object.keys(i))d.startsWith(o)&&c.push(d.slice(o.length));return c}ensureAgent(e,r,i){let o=["agents","add",e,"--workspace",r,"--non-interactive"];return i&&o.push("--model",i),this.queue.enqueue(()=>this.withRetry(`agents add ${e}`,()=>this.runCliTolerant(o,["already exists","already registered"])))}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"])))}};import{readFile as kb,writeFile as Tb}from"node:fs/promises";import{join as Cb}from"node:path";var Rb=["```markdown","# Keep this file empty (or with only comments) to skip heartbeat API calls.","","# Add tasks below when you want the agent to check something periodically.","```","","## Related","","- [Heartbeat config](/gateway/config-agents)",""].join(`
|
|
99
|
+
`),Db=["# Keep this file empty (or with only comments) to skip heartbeat API calls.","","# Add tasks below when you want the agent to check something periodically.",""].join(`
|
|
100
|
+
`);function Pb(t){return t.length===0?t:`${(t.endsWith(`
|
|
101
|
+
`)?t.slice(0,-1):t).split(`
|
|
102
|
+
`).map(o=>o.endsWith("\r")?o.slice(0,-1):o).join(`
|
|
99
103
|
`)}
|
|
100
|
-
`}function Cb(t){
|
|
101
|
-
`)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var Pb={path:"",version:"cloud-deployed"},$0="openclaw_gateway_unavailable",Rb="openclaw_default_agent_missing";function V0(t){let e=[t.port!==void 0?`port=${t.port}`:"",t.runtime?`runtime=${t.runtime}`:"",t.detail??""].filter(Boolean).join(", ");return`openclaw gateway \u672A\u8FD0\u884C/\u4E0D\u53EF\u8FBE${e?` (${e})`:""}; \u8BF7\u542F\u52A8 openclaw gateway`}var Db={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},Ob=6e4,Ao=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??kb,this.createTimeoutMs=e.createTimeoutMs??Ob,this.detectorFactory=e.detectorFactory??(()=>new Vn),this.openclawConfigFactory=e.openclawConfigFactory??(n=>new Io({command:n})),this.openclawConfigDir=e.openclawConfigDir??K0(Ib(),".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=>{fe.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,n=K0(e,".env");if(await Sb(n).then(c=>c.isFile()).catch(()=>!1)){fe.debug("openclaw .env exists, skip bootstrap",{envFile:n});return}let o=Tb({...process.env,...ad(this.paths.agentEnvFile)});await cn(n,o,{mode:384}),fe.info("openclaw .env bootstrapped",{envFile:n,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),fe.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,n){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 Pe(e.agentId,this.paths).catch(()=>null),o=lo(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let c=this.registry.get(e.agentId);if(c){if(c.framework!==e.framework)throw new k("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")fe.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(T=>fe.warn("dispose stale agent failed (ignored)",{err:String(T)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")fe.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(T=>fe.warn("dispose drifted agent failed (ignored)",{err:String(T)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){fe.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let T=await Pe(e.agentId,this.paths).catch(()=>null);T&&(T.patToken=e.patToken,await Ue(T,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){fe.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let T=await Pe(e.agentId,this.paths).catch(()=>null);T&&(T.modelInfo=e.modelInfo,await Ue(T,this.paths))}return fe.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new k("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=Ze(e.agentId,this.paths),x=o?"cloud":"local",h=e.framework==="openclaw"&&x==="local",g;h&&!n?.revive&&(g=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let w=g??(h?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),v=e.workspace??w??u.workspace,_=new AbortController,E=setTimeout(()=>_.abort(new k("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),I,A=!1;try{o&&fd(e.framework)&&await dr(e.framework,_.signal);let T=()=>{if(_.signal.aborted)throw _.signal.reason instanceof Error?_.signal.reason:new k("AGENT_TIMEOUT","_agent/create aborted")};await ud(u.root,{recursive:!0}),await ud(v,{recursive:!0}),await ud(u.logs,{recursive:!0}),T(),h||await fr(v,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(x==="cloud"?await La(v,"cloud"):await La(v,"local",xd)),T();let R=i,y=$f({model:e.model??R?.model}),C=Lf(e._meta)??R?.accountId,D=e.patToken??R?.patToken,F=x==="cloud"?e.modelInfo??R?.modelInfo:void 0;if(I=new vo({agentId:e.agentId,framework:e.framework,workspace:v,model:y.model??Ot,deployType:x,...C?{accountId:C}:{},...D?{patToken:D}:{},...F?{modelInfo:F}:{}}),I.status="ok",R?.sessions){let Z=x==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[Q,ae]of Object.entries(R.sessions)){let ce={acpSessionId:ae.acpSessionId,modelToken:ae.modelToken,tokenGeneratedAt:ae.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};Z?ae.permissionMode===void 0?(ce.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",fe.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:Q,framework:e.framework,fallback:ce.permissionMode})):Nt(e.framework,ae.permissionMode)?ce.permissionMode=ae.permissionMode:fe.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:Q,framework:e.framework,value:ae.permissionMode}):ae.permissionMode!==void 0&&fe.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:Q,framework:e.framework,deployType:x}),ae.cozeGroupId&&(ce.cozeGroupId=ae.cozeGroupId),I.sessions.set(Q,ce)}let se=Object.keys(R.sessions).length;se>0&&fe.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:se})}this.registry.register(I),A=!0;let B={agentId:e.agentId,framework:e.framework,workspace:v,cozeIdentity:e.cozeIdentity,createdAt:R?.createdAt??Date.now(),sessions:R?.sessions??{},model:y.model};x==="cloud"&&(B.deployType="cloud"),C&&(B.accountId=C),D&&(B.patToken=D),F&&(B.modelInfo=F),R?.skills&&(B.skills=R.skills),R?.agentName&&(B.agentName=R.agentName),R?.description&&(B.description=R.description),B.skillsRefreshedForVersion=R?.skillsRefreshedForVersion??Dt,e.framework==="openclaw"&&x==="cloud"&&(this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,v)):fe.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 Z=[...B.skills??[]],se=new Map(Z.map((ce,P)=>[ce.skillId,P])),Q=await Promise.allSettled(Y.map(ce=>po({agentId:e.agentId,workspace:v,framework:e.framework,skill:ce}))),ae=0;for(let[ce,P]of Q.entries()){let j=Y[ce];j&&(P.status==="fulfilled"?(go(Z,se,P.value),ae++):fe.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:j.skillId,skillName:j.skillName,err:String(P.reason)}))}ae>0&&(B.skills=Z,fe.info("initialSkills installed",{agentId:e.agentId,installed:ae,requested:Y.length}))}return await Ue(B,this.paths),fe.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:x}),{ok:!0,agentId:e.agentId,workspace:v,framework:e.framework}}catch(T){throw fe.error("agent create failed, rolling back",{agentId:e.agentId,err:String(T)}),A&&I&&(await I.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await vb(u.root,{recursive:!0,force:!0}).catch(R=>fe.warn("rm agent dir failed (ignored)",{err:String(R)})),T instanceof k?T:new k("AGENT_SPAWN_FAILED",String(T),{cause:T})}finally{clearTimeout(E)}}async spawnSessionDownstream(e,n,i,o,c){let u=this.config.frameworksCache?.[e.framework];if(!u)if(e.deployType==="cloud"&&fd(e.framework))u=Pb;else throw new k("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);fd(e.framework)&&!gs(e.framework)&&(fe.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await dr(e.framework));let x=e.deployType==="cloud"?{model:e.model,modelToken:n,...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 g=e.sessions.get(i),w=Jt(e)?g?.permissionMode??J0:"full-access";h=this.factory(e.framework,u.path,e.workspace,e.agentId,x,i,o,c,this.buildBinShimPathEnv(),w)}try{return await h.start(),await h.initialize(Db),h}catch(g){let w=h instanceof Lt?h.getStderrTail():[];throw w.length>0&&fe.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:g instanceof k?g.code:"unknown",recentStderr:w}),await h.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,g)}}async resolveSpawnFailure(e,n,i){if(e.framework==="openclaw"&&e.deployType==="local"&&n)try{let o=await this.detectorFactory().probeOpenclawGateway(n);if(!o.reachable)return new k("AGENT_ENV_NOT_READY",V0(o),{cause:{reason:$0}})}catch(o){fe.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};fe.warn("openclaw default agent stale or missing, attempting lazy re-detect");let n=await this.detectorFactory().detect("openclaw");if(n?.defaultAgent?.id&&n.defaultAgent.workspace)return fe.info("openclaw lazy re-detect success",{agentId:n.defaultAgent.id,workspace:n.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=n,{id:n.defaultAgent.id,workspace:n.defaultAgent.workspace};throw new 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:Rb}})}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 n=await this.detectorFactory().probeOpenclawGateway(e);if(!n.reachable)throw new k("AGENT_ENV_NOT_READY",V0(n),{cause:{reason:$0}})}async buildOpenclawDownstream(e){let{session:n,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:d,command:u}=e,x=ld(o);if(n.deployType==="local"){let w=await this.ensureOpenclawDefaultAgent();return new Fr({command:u,cwd:w.workspace,agentId:w.id,sessionName:x})}let h=await W0(),g;if(i?.modelToken){let w=Vc(o),v=Jc(i),_=`${w}/${v}`;if(!this.ensuredProviders.has(_)){let E=this.getOpenclawConfig(),I=await E.getAllowlistModelsForProvider(w),A=Qf(i,c,d,I);A&&(await E.ensureProvider(w,A),await E.addModelToAllowlist(_),this.ensuredProviders.add(_))}g=_}return new Fr({command:u,cwd:n.workspace,agentId:n.agentId,sessionName:x,...h?{gatewayToken:h}:{},...g?{slashModelOnStart:g}:{}})}async openclawRepair(e,n){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,n)}async cleanupOpenclawSessionProviders(e,n){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let i=this.openclawConfigCache,o=n??e.model;for(let c of e.sessions.keys()){let d=Vc(c),u=`${d}/${o}`,x=!0;try{await i.removeProvider(d)}catch(h){x=!1,fe.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:d,err:String(h)})}try{await i.removeModelFromAllowlist(u)}catch(h){x=!1,fe.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:u,err:String(h)})}x&&this.ensuredProviders.delete(u)}}};import{randomUUID as tx}from"node:crypto";import{promises as Ub}from"node:fs";import{basename as nx}from"node:path";$e();ie();import{promises as Lb}from"node:fs";import{basename as Nb}from"node:path";var Y0=K("file-upload"),Mb="/api/coze_claw/file/agent_upload",Bb=6e4;async function X0(t,e={}){let i=`${Pr(Rr(e.handshakeBase))}${Mb}`,o=e.timeoutMs??Bb,c=await Lb.readFile(t.path),d=new FormData;d.append("agent_id",t.agentId),d.append("session_id",t.sessionId),d.append("file_name",t.name),d.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let u={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...Sn(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},x=new AbortController,h=setTimeout(()=>x.abort(),o);Y0.info("file upload start",{url:i,agentId:t.agentId,sessionId:t.sessionId,name:t.name,bytes:t.sizeBytes,mime:t.mimeType});try{let g=await fetch(i,{method:"POST",headers:u,body:d,signal:x.signal}),w=g.headers.get("x-tt-logid")??"";if(!g.ok){let E=await g.text().catch(()=>"");throw new k("UPLOAD_FAILED",`upload HTTP ${g.status} logid=${w}: ${E.slice(0,200)}`)}let v=await g.json();if(v.code!==void 0&&v.code!==0)throw new k("UPLOAD_FAILED",`upload code=${v.code} msg=${v.msg??"-"} logid=${w}`);let _=v.data?.file?.file_url;if(!_)throw new k("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${w}: ${JSON.stringify(v).slice(0,200)}`);return Y0.info("file upload ok",{uri:_,logid:w}),{uri:_}}catch(g){throw g instanceof k?g:g.name==="AbortError"?new k("UPLOAD_FAILED",`upload timeout (${o}ms) for ${Nb(t.path)}`):new k("UPLOAD_FAILED",String(g),{cause:g})}finally{clearTimeout(h)}}$e();ie();import{extname as Fb}from"node:path";var zb={".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 Q0(t){let e=Fb(t).toLowerCase();return zb[e]??"application/octet-stream"}Me();var ko=K("agent-send"),ex=50*1024*1024;function rx(t,e,n){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(n);if(!o)throw new k("AGENT_NOT_FOUND",`session=${n} not active in agent=${e}`);return{session:i,runtime:o}}async function ix(t,e,n,i,o,c){let u;for(let x=0;x<=2;x++)try{await t.core.sendAgentFileUpdate(e,n,i,o);return}catch(h){u=h,x<2&&(ko.warn("sendAgentFileUpdate failed, retrying",{attempt:x+1,err:String(h)}),await new Promise(g=>setTimeout(g,5e3)))}throw new k("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function sx(t,e){let{session:n,runtime:i}=rx(e.core,t.agentId,t.sessionId);if(!await si(t.path,n.workspace))throw new k("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${n.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>ex)throw new k("FILE_TOO_LARGE",`${o.size} bytes > limit ${ex}`);let c=await Q0(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 d=t.name??nx(t.path),u;try{u=await X0({patToken:n.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:d,sizeBytes:o.size,...n.accountId?{accountId:n.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(h){throw ko.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:tx(),content:{type:t.kind==="image"?"image":"resource",uri:u.uri,mimeType:c,name:d,sizeBytes:o.size,...u.fileId!==void 0?{fileId:u.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await ix(e,n,i,t.sessionId,x,"agent file uploaded to cloud but sendAgentFileUpdate failed"),ko.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:d,bytes:o.size,mime:c,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:c,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function ox(t,e){let{session:n,runtime:i}=rx(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??nx(t.path),c={sessionUpdate:"group_file",messageId:tx(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await ix(e,n,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),ko.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 ax(t,e){let n=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(n.length,i.length);for(let c=0;c<o;c++){let d=n[c]??0,u=i[c]??0;if(d<u)return!0;if(d>u)return!1}return!1}an();Vt();ie();var Mt=K("coze-cli-installer"),cx="@coze/cli@latest",Gb="coze",dx="0.1.8",jb=5e3,Hb=5e3,qb=9e4,lx=1e4,Wi=null,To=!1;async function pd(t,e={}){if(To)return;if(Wi)return Wi;let n=e.exec??zf;return Wi=(async()=>{try{let i=await Wb(Gb,n),o=!1;if(i){let d=await Kb(n);if(d===void 0)Mt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(ax(d,dx))Mt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:d,min:dx}),o=!0;else{Mt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:d}),To=!0;return}}let c=o?"upgrade-only":"full";Mt.info("coze-cli install start",{package:cx,mode:c});try{await n("npm",["i","-g","--prefer-online",cx],{timeout:qb,maxBuffer:10*1024*1024}),Mt.info("coze-cli install ok")}catch(d){Mt.warn("coze-cli install failed (skip subsequent steps)",{err:String(d)});return}if(o){To=!0;return}if(t.env)try{await n("coze",["config","set","xTTEnv",t.env],{timeout:lx}),Mt.info("coze config set xTTEnv ok",{env:t.env})}catch(d){Mt.warn("coze config set failed (continue to auth login)",{err:String(d)})}try{await n("coze",["auth","login","--token",t.patToken],{timeout:lx}),Mt.info("coze auth login ok")}catch(d){Mt.warn("coze auth login failed",{err:String(d)});return}To=!0}finally{Wi=null}})(),Wi}async function Wb(t,e){let n=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(n,[t],{timeout:jb});return Da(i)}catch{return}}async function Kb(t){try{let{stdout:e,stderr:n}=await t("coze",["--version"],{timeout:Hb});return(e||n).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}dn();Me();var $b=10*6e4;function ux(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?$b:e}function Co(t){return lr(t??te().configFile)}function Ki(t,e){return ur(e??te().configFile,t)}import{randomBytes as xE}from"node:crypto";or();$e();ie();import{createReadStream as Vb}from"node:fs";import{mkdir as Jb,readFile as Zb,realpath as Yb,stat as Xb,writeFile as Qb}from"node:fs/promises";import{basename as eE,dirname as gd,isAbsolute as tE,join as nE,relative as rE,resolve as fx,sep as iE}from"node:path";import{createInterface as sE}from"node:readline";var hx=K("fs-rpc"),$i=Je("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function px(t,e){let n=Buffer.byteLength(t.content,"utf8");if(n>$i)throw new k("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${n} bytes > limit ${$i} bytes`);let i=await mx(t.path,e);return await Jb(gd(i),{recursive:!0}),await Qb(i,t.content,"utf8"),hx.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function gx(t,e){let n=await mx(t.path,e),i=await Xb(n),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>$i&&!o)throw new k("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${$i} bytes`);let c;if(o&&i.size>$i)c=await oE(n,t.line??1,t.limit);else{let d=await Zb(n,"utf8");if(o){let u=d.split(`
|
|
102
|
-
`
|
|
103
|
-
`)}else c=d}return hx.info("fs/read_text_file ok",{path:n,size:c.length}),{content:c}}async function oE(t,e,n){let i=sE({input:Vb(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof n=="number"?o+n:Number.POSITIVE_INFINITY,d=[],u=0;try{for await(let x of i)if(u>=o&&u<c&&d.push(x),u++,u>=c)break}finally{i.close()}return d.join(`
|
|
104
|
-
`)}async function mx(t,e){if(typeof t!="string"||t.length===0)throw new k("IPC_BAD_REQUEST","path must be a non-empty string");let[n,i]=await Promise.all([xx(fx(e)),xx(fx(t))]),o=rE(n,i);if(aE(o,iE,tE(o)))throw new k("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function aE(t,e,n){return t===""?!1:n?!0:t===".."||t.startsWith(`..${e}`)}async function xx(t){let e=[],n=t;for(;n!==gd(n);)try{let i=await Yb(n);return e.length?nE(i,...e.reverse()):i}catch{e.push(eE(n)),n=gd(n)}return t}ie();var _x=K("prompt-multimodal"),yx=10*1024*1024,cE=15e3,dE=6;async function bx(t){let e=new Array(t.length),n=0;async function i(){for(;n<t.length;){let c=n++,d=t[c];d!==void 0&&(e[c]=await lE(d))}}let o=Array.from({length:Math.min(dE,t.length)},()=>i());return await Promise.all(o),e}function Ex(t){return t.some(e=>e.type==="image")}async function lE(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Li(e.uri))return t;try{let{buf:n,contentType:i}=await fE(e.uri),o=e.mimeType||uE(i)||"application/octet-stream";return _x.info("image uri fetched and inlined",{uri:e.uri,bytes:n.length,mimeType:o}),{type:"image",data:n.toString("base64"),mimeType:o}}catch(n){return _x.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(n)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function uE(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function fE(t){let e=new AbortController,n=setTimeout(()=>e.abort(),cE);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>yx)throw new Error(`image too large: ${o.byteLength} bytes (max ${yx})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(n)}}ln();$e();ie();var J=K("core"),hE=3e4,pE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,gE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",mE="\u5BA1\u6279\u5DF2\u8D85\u65F6",wE=3e4,Po=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Nr;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=ux(e.bridgeConfig)}registerExtension(e,n){this.extensions[e]=n}getCozeEnv(){return this.currentCozeEnv}getMockScenario(){return this.currentMockScenario}setMockScenario(e){this.currentMockScenario=e&&e.length>0?e:void 0}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),J.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){J.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(n=>n.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}async reloadAgents(e){let n=e?this.agents.has(e)?[e]:[]:[...this.agents.keys()];for(let i of n)await this.agents.get(i)?.killAllRuntimes("reload");return n}get(e){return this.agents.get(e)}register(e){this.agents.set(e.agentId,e),J.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let n of this.registerHandlers)try{n(e.agentId)}catch(i){J.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)&&J.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,n,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,d)=>{J.info("session runtime exited",{agentId:e.agentId,cloudId:n,code:c,signal:d}),qi(i),i.downstream=void 0,i.replySeq=0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),this.rejectPendingForDownstream(o,"downstream exited")}))}hasPendingPermissionFor(e){for(let n of this.pendingUpstream.values())if(n.downstream===e)return!0;return!1}rejectPendingForDownstream(e,n){let i=[];for(let[o,c]of this.pendingUpstream)c.downstream===e&&i.push(o);if(i.length!==0){J.info("reject pendingUpstream entries (downstream gone)",{reason:n,count:i.length});for(let o of i){let c=this.pendingUpstream.get(o);if(c){this.pendingUpstream.delete(o),this.upstream.send(An(o,{code:X.INTERNAL_ERROR,message:`bridge downstream gone: ${n}`})).catch(d=>J.debug("send error response to upstream failed (ignored)",{err:String(d)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:X.INTERNAL_ERROR,message:`bridge: ${n}`})}catch{}}}}}rejectAllPendingOnReconnect(){let e=this.pendingUpstream.size,n=this.pendingBridge.size;if(!(e===0&&n===0)){J.warn("upstream reconnected, rejecting stale pending requests",{pendingUpstream:e,pendingBridge:n});for(let[,i]of this.pendingUpstream){try{i.downstream.respondAgentRequestError(i.agentRequestId,{code:X.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(wo(e)){this.handleUpstreamResponse(e);return}if(!("method"in e)||typeof e.method!="string")return;let n="id"in e&&e.id!==void 0?e.id:null,i=e.params?._meta?.cozeEnv;i&&pE.test(i)?this.currentCozeEnv=i:i&&J.warn("rejecting cozeEnv with invalid shape, keeping previous",{rejected:i});try{if(e.method.startsWith("_agent/")){let o=this.extensions[e.method];if(!o){n!==null?await this.sendError(n,X.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):J.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);n!==null&&await this.upstream.send(Lr(n,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);n!==null&&await this.upstream.send(Lr(n,o));return}if(e.method==="initialize"){n!==null&&await this.upstream.send(Lr(n,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}n!==null?await this.sendError(n,X.METHOD_NOT_FOUND,`method not implemented: ${e.method}`):J.warn("drop unknown notification",{method:e.method})}catch(o){J.error("handleFrame failed",{method:e.method,err:String(o)}),n!==null&&await this.upstream.send(An(n,Gi(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new k("IPC_BAD_REQUEST",`${e.method} requires params`);let n=e.params,i=n._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 n.sessionId=="string"?n.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||e.method==="session/set_mode"||!c)return this.dispatchSessionCall(o,e.method,n);if(e.method==="session/prompt"){let x=o.sessions.get(c);if(x?.pendingPermission){let h=n._meta?.cozeTriggerMsgId,g=uo(n._meta);return J.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,x,c,gE,h,g)}}let d=Date.now(),u=!1;try{let x=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,n));return u=!0,x}finally{J.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-d,ok:u})}}async dispatchSessionCall(e,n,i){e.lastActiveAt=Date.now();let{stripped:o}=Mf(i);switch(n){case"session/new":{let c=_E();return J.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return J.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,d=c.sessionId;if(!d)throw new k("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=Jt(e)?Nf(i._meta):void 0;if(u!==void 0&&!Nt(e.framework,u))throw new k("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${dd(e.framework)}`);let x=await this.ensureRuntime(e,d);if(u!==void 0&&x.permissionMode===void 0&&(x.permissionMode=u,await this.persistSessionMapping(e)),x.replySeq=0,await this.ensureDownstream(e,d,x),!x.downstream||!x.acpSessionId)throw new k("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&x.permissionMode!==void 0&&x.permissionMode!==u){let v=x.permissionMode;x.permissionMode=u,await this.persistSessionMapping(e);try{await x.downstream.setSessionMode({sessionId:x.acpSessionId,modeId:u})}catch(_){throw x.permissionMode=v,await this.persistSessionMapping(e).catch(()=>{}),_}}let h=i._meta?.cozeTriggerMsgId;h?e.activeTriggers.set(x.acpSessionId,h):e.activeTriggers.delete(x.acpSessionId);let g=uo(i._meta);if(g?e.activeGroupIds.set(x.acpSessionId,g):e.activeGroupIds.delete(x.acpSessionId),g&&x.cozeGroupId!==g&&(x.cozeGroupId=g,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&Ex(c.prompt))throw new k("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let w=await bx(c.prompt);try{let v=await x.downstream.sessionPrompt({...c,sessionId:x.acpSessionId,prompt:w});return x.lastActiveAt=Date.now(),v}catch(v){if(v instanceof k&&v.code==="AGENT_APPROVAL_TIMEOUT"){let _=x.pendingPermission;_&&(_.downstream.respondAgentRequest(_.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(_.upstreamId),x.pendingPermission=void 0);let E=x.acpSessionId,I=E?e.activeTriggers.get(E):void 0,A=E?e.activeGroupIds.get(E):void 0;return J.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:d}),await this.synthesizePromptReply(e,x,d,mE,I,A)}throw v}finally{if(e.activeTriggers.delete(x.acpSessionId),e.activeGroupIds.delete(x.acpSessionId),x.pendingPermission=void 0,x.reloadAfterTurn){x.reloadAfterTurn=!1;let v=x.downstream;v&&(x.downstream=void 0,J.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:d,acpId:x.acpSessionId}),v.stop("reload-after-turn").catch(_=>J.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:d,err:String(_)})))}else x.downstream?.isAlive()&&this.armIdleTimer(e,d,x)}}case"session/cancel":{let d=o.sessionId;if(!d)throw new k("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(d);if(e.hasSessionQueue(d)){let x=e.getSessionQueue(d);x.size>0&&(J.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:d,queuedCount:x.size}),x.dispose(new k("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${d}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,d=c.sessionId,u=c.modeId,x=uo(i._meta);if(!d)throw new k("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Jt(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(!Nt(e.framework,u))throw new k("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${dd(e.framework)}`);if(x)return await this.handleGroupSetMode(e,x,u);let h=e.sessions.get(d)??await this.ensureRuntime(e,d);if(h.permissionMode===u)return{};let g=h.permissionMode;if(h.permissionMode=u,await this.persistSessionMapping(e),h.downstream?.isAlive()&&h.acpSessionId)try{await h.downstream.setSessionMode({sessionId:h.acpSessionId,modeId:u})}catch(w){throw h.permissionMode=g,await this.persistSessionMapping(e).catch(()=>{}),w}else J.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:d,modeId:u});return{}}default:throw new k("IPC_BAD_REQUEST",`session method not supported: ${n}`)}}async handleGroupSetMode(e,n,i){let o=[];for(let[d,u]of e.sessions)u.cozeGroupId===n&&u.permissionMode!==i&&o.push({cloudId:d,runtime:u,oldMode:u.permissionMode});if(o.length===0)return J.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:n,modeId:i}),{};J.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:n,modeId:i,targets:o.length});for(let d of o)d.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let d of o){let u=d.runtime.downstream,x=d.runtime.acpSessionId;u?.isAlive()&&x&&c.push({downstream:u,acpSessionId:x,oldMode:d.oldMode,runtime:d.runtime})}for(let d of c)try{await d.downstream.setSessionMode({sessionId:d.acpSessionId,modeId:i})}catch(u){for(let x of o)x.runtime.permissionMode=x.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),u}return{}}async ensureRuntime(e,n){let i=e.sessions.get(n);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,n):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return Jt(e)&&(c.permissionMode=e.framework==="claude-code"?xd:Z0),e.sessions.set(n,c),await this.persistSessionMapping(e),c}async requestSessionToken(e,n){let i={sessionId:n,_meta:{cozeAgentId:e}};try{let o=await this.sendRequest(xt.GEN_MODEL_TOKEN,i,wE);if(!o?.modelToken)throw new k("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${n})`);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,n,i){if(qi(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,d=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(d>=o&&Date.now()-u<c)throw new k("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${n} spawn failed ${d} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let x;try{x=await this.sessionSpawner(e,i.modelToken,n,this.currentCozeEnv,this.currentMockScenario)}catch(h){throw i.spawnFailCount=d+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(J.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:n,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),h}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=x,this.attachRuntimeHooks(e,n,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await x.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),J.info("session restored via session/load",{agentId:e.agentId,cloudId:n,acpId:i.acpSessionId})}catch(h){J.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:n,acpId:i.acpSessionId,err:String(h)}),i.acpSessionId=void 0;let g=await x.sessionNew({cwd:e.workspace});i.acpSessionId=g.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 J.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:n,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),Jt(e)&&i.acpSessionId&&i.permissionMode)try{await x.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(h){J.warn("post-spawn set_mode failed, framework using its own startup default",{framework:e.framework,agentId:e.agentId,cloudId:n,mode:i.permissionMode,err:String(h)})}}armIdleTimer(e,n,i){if(qi(i),this.isRuntimeBusy(e,i)){J.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:n});return}i.idleTimer=setTimeout(()=>{if(i.idleTimer=void 0,this.isRuntimeBusy(e,i)){J.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:n}),this.armIdleTimer(e,n,i);return}J.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:n});let o=i.downstream;i.downstream=void 0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),o&&o.stop("idle timeout").catch(c=>J.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:n,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,n){if(n.acpSessionId&&e.activeTriggers.has(n.acpSessionId))return!0;let i=n.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,n,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++n.replySeq};if(n.acpSessionId){let d=e.activeTriggers.get(n.acpSessionId);d&&(c.cozeTriggerMsgId=d);let u=e.activeGroupIds.get(n.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Or("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,n,i,o,c,d){let u={cozeAgentId:e.agentId,cozeReplySeqID:++n.replySeq};return c&&(u.cozeTriggerMsgId=c),d&&(u.cozeGroupId=d),await this.upstream.send(Or("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(x=>J.warn("synthesizePromptReply update send failed (ignored)",{err:String(x)})),{stopReason:"end_turn"}}forwardUpdate(e,n){let i=n.sessionId,o=this.reverseSessionId(e,i);if(!o){J.debug("drop update for unknown session",{agentId:e.agentId,acpId:i});return}let c=e.sessions.get(o);if(!c){J.debug("drop update: runtime gone",{agentId:e.agentId,cloudId:o});return}if(EE(n)){J.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let d=n.update;if(d&&typeof d=="object"&&d.sessionUpdate==="current_mode_update"&&Jt(e)){let g=d.currentModeId;Nt(e.framework,g)&&c.permissionMode!==g?(c.permissionMode=g,this.persistSessionMapping(e).catch(w=>J.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(w)}))):typeof g=="string"&&!Nt(e.framework,g)&&J.warn("current_mode_update with invalid modeId for framework, not persisting",{framework:e.framework,agentId:e.agentId,modeId:g})}let u={cozeAgentId:e.agentId,cozeReplySeqID:++c.replySeq},x=e.activeTriggers.get(i);x&&(u.cozeTriggerMsgId=x);let h=e.activeGroupIds.get(i);h&&(u.cozeGroupId=h),this.upstream.send(Or("session/update",{...n,sessionId:o,_meta:u})).catch(g=>J.warn("forward update failed",{agentId:e.agentId,err:String(g)}))}handleAgentRequest(e,n,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,n,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,n,i);return}J.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),n.respondAgentRequestError(i.id,{code:X.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,n,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},d=await px(c,o);n.respondAgentRequest(i.id,d)}else{let c=i.params??{},d=await gx(c,o);n.respondAgentRequest(i.id,d)}}catch(o){J.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),n.respondAgentRequestError(i.id,Gi(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let n=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);n&&(n.pendingPermission=void 0)}forwardPermissionRequest(e,n,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,x=u?e.activeTriggers.get(u):void 0,h={cozeAgentId:e.agentId};x&&(h.cozeTriggerMsgId=x);let g=u?e.activeGroupIds.get(u):void 0;g&&(h.cozeGroupId=g);let w=u?this.reverseSessionId(e,u):void 0,v=w?e.sessions.get(w):void 0;v&&(v.pendingPermission={downstream:n,agentRequestId:i.id,upstreamId:o});let _={...c,...w?{sessionId:w}:{},_meta:h};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:n,method:i.method,cloudSessionId:w}),J.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:w,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(E=>({optionId:E.optionId,kind:E.kind,name:E.name}))}),this.upstream.send(zi(o,"session/request_permission",_)).catch(E=>{this.pendingUpstream.delete(o),J.error("forward permission request failed",{agentId:e.agentId,err:String(E)}),n.respondAgentRequestError(i.id,{code:X.INTERNAL_ERROR,message:`upstream send failed: ${String(E)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let n=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(n){this.pendingUpstream.delete(n.key);let o=n.value;this.clearPendingPermissionFor(o),e.error?(J.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"&&yE(e.result,o),J.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 mo(e.error)):i.value.resolve(e.result);return}J.debug("orphan upstream response (no pending)",{id:e.id})}lookupPending(e,n,i){let o=e.get(n);if(o)return{value:o,key:n};if(typeof n=="number"){let c=String(n),d=e.get(c);if(d)return J.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:n,normalizedId:c}),{value:d,key:c}}}sendRequest(e,n,i=hE){let o=this.upstreamIds.next(e);return new Promise((c,d)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),d(new k("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:d,timer:u}),this.upstream.send(zi(o,e,n)).catch(x=>{let h=this.pendingBridge.get(o);h&&(clearTimeout(h.timer),this.pendingBridge.delete(o)),d(x)})})}async persistSessionMapping(e){if(this.paths)try{let n=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),o.permissionMode&&Jt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),n.set(i,c)}await oi(e.agentId,n,this.paths)}catch(n){J.warn("persist session mapping failed",{agentId:e.agentId,err:String(n)})}}reverseSessionId(e,n){for(let[i,o]of e.sessions.entries())if(o.acpSessionId===n)return i}sendError(e,n,i){return this.upstream.send(An(e,{code:n,message:i,data:{bridgeVersion:Dt}}))}};function _E(){return xE(16).toString("hex")}function yE(t,e){if(!t||typeof t!="object"){J.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let n=t;if("kind"in n&&!("outcome"in n)){J.warn('permission response: top-level "kind" field (D66 historical bug shape)',{agentId:e.agentId,result:t});return}let i=n.outcome;if(!i||typeof i!="object"){J.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")&&J.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var bE=["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."],vx="Warning: ";function EE(t){let e=t.update;if(e?.sessionUpdate!=="agent_message_chunk")return!1;let n=e.content;if(!n||typeof n!="object")return!1;let i=n;if(i.type!=="text"||typeof i.text!="string")return!1;let o=i.text.startsWith(vx)?i.text.slice(vx.length):i.text;return bE.some(c=>o.startsWith(c))}dn();ie();Me();import{randomBytes as vE}from"node:crypto";import{createServer as SE}from"node:http";var IE=1e6,Sx=K("ipc"),Ro=class{server=null;port=0;token="";routes;paths;constructor(e){this.routes=new Map(e.routes.map(n=>[`${n.method} ${n.path}`,n])),this.paths=e.paths??te()}async start(){this.token=vE(32).toString("hex");let e=SE((i,o)=>{this.dispatch(i,o)});this.server=e,await new Promise((i,o)=>{e.once("error",o),e.listen(0,"127.0.0.1",()=>i())});let n=e.address();if(!n||typeof n!="object")throw new Error("failed to obtain IPC port");return this.port=n.port,await this.persistAuthFiles(),Sx.info("IPC listening",{port:this.port}),{port:this.port,token:this.token}}async stop(){let e=this.server;e&&(await new Promise((n,i)=>{e.close(o=>o?i(o):n())}),this.server=null)}async persistAuthFiles(){await cn(this.paths.portFile,String(this.port)),await cn(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,n){if(e.headers.authorization!==`Bearer ${this.token}`){Vi(n,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Vi(n,404,{error:"not found"});return}let d=null;if(e.method==="POST")try{d=await AE(e)}catch(u){Vi(n,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(d,e);Vi(n,200,u??{ok:!0})}catch(u){Sx.error("IPC handler failed",{key:o,err:String(u)}),Vi(n,500,{error:u instanceof Error?u.message:String(u)})}}};function Vi(t,e,n){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(n))}async function AE(t){let e=[],n=0;for await(let o of t){let c=o;if(n+=c.length,n>IE)throw new Error("body too large");e.push(c)}let i=Buffer.concat(e).toString("utf8");return i?JSON.parse(i):null}import"node:module";var $v=Gt(_h(),1),Vv=Gt(Uo(),1),Jv=Gt(Gr(),1),Zv=Gt(kd(),1),Yv=Gt(Pd(),1),Xv=Gt(Md(),1),Th=Gt(qo(),1),Qv=Gt(kh(),1);var Ch=Th.default;$e();ie();var{FWS:p1}=Uh(),Oe=K("upstream.frontier"),jh="application/json",Hh="none",g1=15e3;function m1(t){class e extends Ch{constructor(i){super(i,Gf,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>Oe.warn("frontier ws error during teardown (handled, prevents daemon crash)",{err:i instanceof Error?i.message:String(i)}))}close(i,o){this.guardTeardown(),super.close(i,o)}terminate(){this.guardTeardown(),super.terminate()}send(i,...o){if(Il("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let d=Buffer.from(c.slice(0,128)).toString("hex");Oe.debug("WS raw frame out",{bytes:c.byteLength,headHex:d})}catch(c){Oe.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var rs=class{constructor(e){this.opts=e}opts;fws=null;handler=null;connectHandlers=[];opened=!1;lastSendRefusedLogAt=0;sendRefusedSuppressed=0;openCount=0;async start(){if(this.fws){Oe.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:jf,...Sn(this.opts.ppeOverride)},n=m1(e),i=qf(this.opts.urlOverride),o={url:i,ws:n,fpID:Uf,aID:fo,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:jh,force:!0},payloadEncoding:{encoding:Hh,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new p1(o),d=!1,u=null,x,h,g=new Promise((_,E)=>{x=_,h=E}),w=_=>{d||(d=!0,u&&(clearTimeout(u),u=null),_?h(_):x())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let _=this.openCount===1;Oe.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:_,openCount:this.openCount}),_&&w();for(let E of this.connectHandlers)Promise.resolve(E({initial:_})).catch(I=>Oe.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=_=>{this.opened=!1,Oe.info("frontier closed",{code:_.code,reason:_.reason,willReconnect:_.willReconnect})},c.onerror=_=>{Oe.warn("frontier error",{code:_.code,msg:_.message}),w(new k("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${_.code} msg=${_.message??""}`))},c.onmessage=_=>this.handleMessage(_),this.fws=c;let v=this.opts.openTimeoutMs??g1;u=setTimeout(()=>{w(new k("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${v}ms (handshake or upgrade slow)`))},v),await c.connect();try{await g}catch(_){try{c.close(1e3,"open failed")}catch(E){Oe.warn("fws close during start failure threw (ignored)",{err:String(E)})}throw this.fws=null,this.opened=!1,_}}async stop(e){let n=this.fws;if(n){this.fws=null,this.opened=!1;try{n.close(1e3,e??"bridge shutdown")}catch(i){Oe.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let n=this.fws,i=e.method;if(!n)throw Oe.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?(Oe.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:n.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=u,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new k("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${n.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;qh(c)||Oe.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await n.send(o,{service:33555712,method:1,payloadType:jh,payloadEncoding:Hh})}catch(u){throw Oe.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 n=this.opts.getPatTokenForAgent;if(!n)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=n(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let n=e.message?.service;if(n!==33555712){Oe.debug("drop non-adapter frontier frame",{service:n});return}let i=y1(e);if(!i){Oe.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){Oe.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(d){Oe.warn("frontier message JSON parse failed",{err:String(d),head:i.slice(0,80)});return}let c=o;qh(c)||Oe.info("frontier frame in",{logid:_1(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:w1(i)}),Promise.resolve(this.handler(o)).catch(d=>Oe.warn("frontier frame handler threw",{err:String(d)}))}};function qh(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Wh=2e3;function w1(t){return t.length<=Wh?t:`${t.slice(0,Wh)}...<truncated, total ${t.length} chars>`}function _1(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function y1(t){let e=t.message;if(e?.textPayload)return e.textPayload;let n=e?.payload;if(!n)return null;try{return Buffer.from(n).toString("utf8")}catch{return null}}$e();ie();var Ud=K("skill-publish"),b1="/api/marketplace/product/skill/publish_with_assets",E1=15e4;async function Kh(t,e={}){let i=`${Pr(Rr(e.handshakeBase))}${b1}`,o=e.timeoutMs??E1,c=new FormData;c.append("skill_id",t.skillId??""),c.append("skill_name",t.skillName),c.append("skill_description",t.description??""),c.append("agent_id",t.agentId),c.append("zip_file",new Blob([t.zip],{type:"application/zip"}),"skill.zip");let d={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...Sn(e.ppeOverride),...t.accountId&&t.accountId!=="0"?{"x-coze-account":t.accountId}:{}},u=new AbortController,x=setTimeout(()=>u.abort(),o);Ud.info("skill publish start",{url:i,method:"POST",form:{skill_id:t.skillId??"",skill_name:t.skillName,skill_description:t.description??"",agent_id:t.agentId,zip_file_bytes:t.zip.length},headers:{...d,Authorization:`Bearer ${t.patToken.slice(0,8)}...`}});try{let h=await fetch(i,{method:"POST",headers:d,body:c,signal:u.signal}),g=h.headers.get("x-tt-logid")??"";if(!h.ok){let _=await h.text().catch(()=>"");throw new k("UPLOAD_FAILED",`skill publish HTTP ${h.status} logid=${g}: ${_.slice(0,200)}`)}let w=await h.json();if(Ud.info("skill publish response",{logid:g,httpStatus:h.status,code:w.code,msg:w.msg,dataSkillId:w.data?.skill_id??"",dataVersion:w.data?.version??""}),w.code!==void 0&&w.code!==0)throw new k("UPLOAD_FAILED",`skill publish code=${w.code} msg=${w.msg??"-"} logid=${g}`);let v={};return w.data?.skill_id!==void 0&&w.data.skill_id!==""&&(v.skillId=String(w.data.skill_id)),w.data?.version&&(v.version=w.data.version),Ud.info("skill publish ok",{logid:g,skillId:v.skillId??"",version:v.version??""}),v}catch(h){throw h instanceof k?h:h.name==="AbortError"?new k("UPLOAD_FAILED",`skill publish timeout (${o}ms): ${t.skillName}`):new k("UPLOAD_FAILED",String(h),{cause:h})}finally{clearTimeout(x)}}ie();var Gd=K("upstream.switchable"),Qo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,n){if(this.inner===e)return;Gd.info("swap upstream",{reason:n});let i=this.inner;if(this.inner=e,this.handler&&e.onFrame(this.handler),e.onConnect)for(let o of this.connectHandlers)e.onConnect(o);try{await e.start()}catch(o){throw Gd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(n??"swapped").catch(o=>Gd.warn("previous upstream stop threw (ignored)",{err:String(o)}))}current(){return this.inner}start(){return this.inner.start()}stop(e){return this.inner.stop(e)}send(e){return this.inner.send(e)}onFrame(e){this.handler=e,this.inner.onFrame(e)}onConnect(e){this.connectHandlers.push(e),this.inner.onConnect?.(e)}isConnected(){return this.inner.isConnected()}};ie();var jd=K("upstream"),$r=class{handler=null;async start(){jd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){jd.info("NoopUpstream stopped",{reason:e})}async send(e){jd.debug("NoopUpstream.send (dropped)",{method:"method"in e?e.method:void 0})}onFrame(e){this.handler=e}isConnected(){return!1}async injectFrame(e){this.handler&&await this.handler(e)}};$e();ie();dn();ie();Me();import{promises as v1}from"node:fs";var $h=K("pat-token-store");async function ea(t=te()){try{let n=(await v1.readFile(t.patTokenFile,"utf8")).trim();return n.length===0?($h.warn("pat-token exists but empty (treating as missing; likely interrupted write)",{path:t.patTokenFile}),null):n}catch(e){let n=e?.code;return n!=="ENOENT"&&$h.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:n,message:e.message}),null}}async function is(t,e=te()){if(!t)throw new Error("writePatToken: empty patToken");await cn(e.patTokenFile,t,{mode:384})}Me();Me();import{promises as ta}from"node:fs";import{join as S1}from"node:path";function I1(t,e){return`#!/bin/sh
|
|
104
|
+
`}async function V0(t){let e=Cb(t,"HEARTBEAT.md"),r=await kb(e,"utf8");return Pb(r)!==Rb?!1:(await Tb(e,Db),!0)}var oe=H("agent-manager"),pd="acceptEdits",Y0="full-access",Q0="read-only";function Mb(t){return{INITIAL_AGENT_MODE:bo(t)}}var Bb=(t,e,r,i,o,c,d,u,h,x)=>{switch(t){case"claude-code":{let m={...o?{...Xf(o),...e0(o,d,u)}:{},...h??{},IS_SANDBOX:"1"};return new yo({cwd:r,env:m,agentId:i})}case"codex":{let m=Y0;x!==void 0&&(Ft("codex",x)?m=x:oe.warn("codex spawn: invalid codexPermissionMode, falling back to full-access",{agentId:i,received:x}));let _=!!o,S={...o?{...Qf(o),...Yf(o,d,u)}:{},...Mb(m),..._?{NO_BROWSER:"1"}:{},...h??{}};return new Eo({cwd:r,agentId:i,...Object.keys(S).length>0?{env:S}:{},..._?{authMethodId:"api-key",isolateCodexHome:!0}:{}})}case"openclaw":return new Fr({command:e,cwd:r,agentId:i,...c?{sessionName:fd(c)}:{}})}};function xd(t){return t==="claude-code"||t==="codex"}function Fb(t){let e=[],r=Object.keys(t).sort();for(let i of r){let o=t[i];o!==void 0&&(zb(o)||e.push(`${i}=${o}`))}return e.length===0?"":`${e.join(`
|
|
105
|
+
`)}
|
|
106
|
+
`}function zb(t){if(t.includes(`
|
|
107
|
+
`)||t.includes("\r")||t.includes("$")||t.includes("#"))return!0;let e=t[0];return e==="'"||e==='"'}var Ub={path:"",version:"cloud-deployed"},Z0="openclaw_gateway_unavailable",Gb="openclaw_default_agent_missing";function X0(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 Hb={protocolVersion:1,clientCapabilities:{fs:{readTextFile:!0,writeTextFile:!0}}},qb=6e4,Ao=class{paths;config;registry;factory;createTimeoutMs;openclawConfigCache;ensuredProviders=new Set;detectorFactory;openclawEnvBootstrapPromise;openclawConfigFactory;openclawConfigDir;constructor(e){this.paths=e.paths,this.config=e.config,this.registry=e.registry,this.factory=e.downstreamFactory??Bb,this.createTimeoutMs=e.createTimeoutMs??qb,this.detectorFactory=e.detectorFactory??(()=>new Jn),this.openclawConfigFactory=e.openclawConfigFactory??(r=>new Io({command:r})),this.openclawConfigDir=e.openclawConfigDir??J0(Nb(),".openclaw")}buildBinShimPathEnv(){let e=process.platform==="win32"?";":":";return{PATH:`${this.paths.binDir}${e}${process.env.PATH??""}`}}getOpenclawConfig(){if(!this.openclawConfigCache){let e=this.config.frameworksCache?.openclaw;if(!e?.path)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");this.openclawConfigCache=this.openclawConfigFactory(e.path)}return this.openclawConfigCache}bootstrapOpenclawEnvIfNeeded(){return this.openclawEnvBootstrapPromise?this.openclawEnvBootstrapPromise:(this.openclawEnvBootstrapPromise=this.doBootstrapOpenclawEnv().catch(e=>{oe.warn("openclaw env bootstrap failed (ignored)",{err:String(e)}),this.openclawEnvBootstrapPromise=void 0}),this.openclawEnvBootstrapPromise)}async doBootstrapOpenclawEnv(){let e=this.openclawConfigDir,r=J0(e,".env");if(await Lb(r).then(c=>c.isFile()).catch(()=>!1)){oe.debug("openclaw .env exists, skip bootstrap",{envFile:r});return}let o=Fb({...process.env,...dd(this.paths.agentEnvFile)});await ln(r,o,{mode:384}),oe.info("openclaw .env bootstrapped",{envFile:r,bytes:o.length}),await this.getOpenclawConfig().restartGateway(),oe.info("openclaw gateway restarted after env bootstrap")}async createAgent(e,r){if(!e.agentId)throw new T("IPC_BAD_REQUEST","agentId required");if(!e.framework)throw new T("IPC_BAD_REQUEST","framework required");let i=await Pe(e.agentId,this.paths).catch(()=>null),o=lo(e._meta)==="cloud"||i?.deployType==="cloud";this.registry.reviveIfDisconnected?.(e.agentId);let c=this.registry.get(e.agentId);if(c){if(c.framework!==e.framework)throw new T("AGENT_BUSY",`agent ${e.agentId} exists with different framework (${c.framework})`);if(c.status==="error")oe.warn("existing agent in error state, rebuilding",{agentId:e.agentId}),await c.dispose("rebuild after error").catch(C=>oe.warn("dispose stale agent failed (ignored)",{err:String(C)})),this.registry.unregister(e.agentId);else if(o&&c.deployType!=="cloud")oe.warn("existing agent deployType drifted to local, rebuilding as cloud",{agentId:e.agentId}),await c.dispose("rebuild after deployType drift").catch(C=>oe.warn("dispose drifted agent failed (ignored)",{err:String(C)})),this.registry.unregister(e.agentId);else{if(e.patToken&&e.patToken!==c.patToken){oe.info("updating agent patToken on re-create (reconnect with new PAT)",{agentId:e.agentId}),c.setPatToken(e.patToken);let C=await Pe(e.agentId,this.paths).catch(()=>null);C&&(C.patToken=e.patToken,await Ge(C,this.paths))}if(c.deployType==="cloud"&&e.modelInfo){oe.info("updating agent modelInfo on re-create",{agentId:e.agentId}),c.setModelInfo(e.modelInfo);let C=await Pe(e.agentId,this.paths).catch(()=>null);C&&(C.modelInfo=e.modelInfo,await Ge(C,this.paths))}return oe.info("agent already exists, return current",{agentId:e.agentId}),{ok:!0,agentId:c.agentId,workspace:c.workspace,framework:c.framework}}}if(!o&&!this.config.frameworksCache?.[e.framework])throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine; rerun daemon to refresh frameworks_cache`);let u=Xe(e.agentId,this.paths),h=o?"cloud":"local",x=e.framework==="openclaw"&&h==="local",m;x&&!r?.revive&&(m=(await this.ensureOpenclawDefaultAgent()).workspace,await this.ensureOpenclawGatewayReachable());let _=m??(x?this.config.frameworksCache?.openclaw?.defaultAgent?.workspace:void 0),S=e.workspace??_??u.workspace,y=new AbortController,v=setTimeout(()=>y.abort(new T("AGENT_TIMEOUT",`_agent/create timed out after ${this.createTimeoutMs}ms`)),this.createTimeoutMs),I,A=!1;try{o&&xd(e.framework)&&await dr(e.framework,y.signal);let C=()=>{if(y.signal.aborted)throw y.signal.reason instanceof Error?y.signal.reason:new T("AGENT_TIMEOUT","_agent/create aborted")};await hd(u.root,{recursive:!0}),await hd(S,{recursive:!0}),await hd(u.logs,{recursive:!0}),C(),x||await fr(S,e.framework,e.cozeIdentity),e.framework==="claude-code"&&(h==="cloud"?await Na(S,"cloud"):await Na(S,"local",pd)),C();let P=i,b=Jf({model:e.model??P?.model}),R=Bf(e._meta)??P?.accountId,O=e.patToken??P?.patToken,M=h==="cloud"?e.modelInfo??P?.modelInfo:void 0;if(I=new vo({agentId:e.agentId,framework:e.framework,workspace:S,model:b.model??Mt,deployType:h,...R?{accountId:R}:{},...O?{patToken:O}:{},...M?{modelInfo:M}:{}}),I.status="ok",P?.sessions){let V=h==="local"&&(e.framework==="claude-code"||e.framework==="codex");for(let[Y,se]of Object.entries(P.sessions)){let ae={acpSessionId:se.acpSessionId,modelToken:se.modelToken,tokenGeneratedAt:se.tokenGeneratedAt,lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};V?se.permissionMode===void 0?(ae.permissionMode=e.framework==="claude-code"?"bypassPermissions":"full-access",oe.info("autoRevive: legacy session (no permissionMode) \u2192 fallback to D80/D84 default",{agentId:e.agentId,cloudId:Y,framework:e.framework,fallback:ae.permissionMode})):Ft(e.framework,se.permissionMode)?ae.permissionMode=se.permissionMode:oe.warn("autoRevive: dropping invalid persisted permissionMode",{agentId:e.agentId,cloudId:Y,framework:e.framework,value:se.permissionMode}):se.permissionMode!==void 0&&oe.info("autoRevive: dropping persisted permissionMode (gate disabled)",{agentId:e.agentId,cloudId:Y,framework:e.framework,deployType:h}),se.cozeGroupId&&(ae.cozeGroupId=se.cozeGroupId),I.sessions.set(Y,ae)}let re=Object.keys(P.sessions).length;re>0&&oe.info("restored persisted session records (no spawn)",{agentId:e.agentId,count:re})}this.registry.register(I),A=!0;let N={agentId:e.agentId,framework:e.framework,workspace:S,cozeIdentity:e.cozeIdentity,createdAt:P?.createdAt??Date.now(),sessions:P?.sessions??{},model:b.model};if(h==="cloud"&&(N.deployType="cloud"),R&&(N.accountId=R),O&&(N.patToken=O),M&&(N.modelInfo=M),P?.skills&&(N.skills=P.skills),P?.agentName&&(N.agentName=P.agentName),P?.description&&(N.description=P.description),N.skillsRefreshedForVersion=P?.skillsRefreshedForVersion??Nt,e.framework==="openclaw"&&h==="cloud"){this.config.frameworksCache?.openclaw?.path?(await this.bootstrapOpenclawEnvIfNeeded(),await this.getOpenclawConfig().ensureAgent(e.agentId,S)):oe.warn("openclaw binary not on this machine, skip agents add (will fail at session/prompt)",{agentId:e.agentId});try{await V0(S)&&oe.info("legacy openclaw HEARTBEAT template fixed",{agentId:e.agentId,workspace:S})}catch(V){oe.warn("failed to fix legacy openclaw HEARTBEAT template (ignored)",{agentId:e.agentId,workspace:S,err:String(V)})}}let J=e.initialSkills??[];if(J.length>0){let V=[...N.skills??[]],re=new Map(V.map((ae,D)=>[ae.skillId,D])),Y=await Promise.allSettled(J.map(ae=>po({agentId:e.agentId,workspace:S,framework:e.framework,skill:ae}))),se=0;for(let[ae,D]of Y.entries()){let U=J[ae];U&&(D.status==="fulfilled"?(go(V,re,D.value),se++):oe.warn("initialSkill install failed (skipping)",{agentId:e.agentId,skillId:U.skillId,skillName:U.skillName,err:String(D.reason)}))}se>0&&(N.skills=V,oe.info("initialSkills installed",{agentId:e.agentId,installed:se,requested:J.length}))}return await Ge(N,this.paths),oe.info("agent created (no spawn, lazy on first prompt)",{agentId:e.agentId,framework:e.framework,deployType:h}),{ok:!0,agentId:e.agentId,workspace:S,framework:e.framework}}catch(C){throw oe.error("agent create failed, rolling back",{agentId:e.agentId,err:String(C)}),A&&I&&(await I.dispose("rollback").catch(()=>{}),this.registry.unregister(e.agentId)),await Ob(u.root,{recursive:!0,force:!0}).catch(P=>oe.warn("rm agent dir failed (ignored)",{err:String(P)})),C instanceof T?C:new T("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"&&xd(e.framework))u=Ub;else throw new T("AGENT_SPAWN_FAILED",`framework ${e.framework} not detected on this machine`);xd(e.framework)&&!gs(e.framework)&&(oe.info("spawn: resolving acp wrapper",{agentId:e.agentId,framework:e.framework}),await dr(e.framework));let h=e.deployType==="cloud"?{model:e.model,modelToken:r,...e.modelInfo?{modelInfo:e.modelInfo}:{}}:void 0,x;if(e.framework==="openclaw")x=await this.buildOpenclawDownstream({session:e,modelConfig:h,cloudSessionId:i,cozeEnv:o,mockScenario:c,command:u.path});else{let m=e.sessions.get(i),_=Yt(e)?m?.permissionMode??Y0:"full-access";x=this.factory(e.framework,u.path,e.workspace,e.agentId,h,i,o,c,this.buildBinShimPathEnv(),_)}try{return await x.start(),await x.initialize(Hb),x}catch(m){let _=x instanceof Bt?x.getStderrTail():[];throw _.length>0&&oe.warn("spawnSessionDownstream failed, recent stderr (D94)",{agentId:e.agentId,framework:e.framework,method:m instanceof T?m.code:"unknown",recentStderr:_}),await x.stop("spawnSessionDownstream failed").catch(()=>{}),await this.resolveSpawnFailure(e,u.path,m)}}async resolveSpawnFailure(e,r,i){if(e.framework==="openclaw"&&e.deployType==="local"&&r)try{let o=await this.detectorFactory().probeOpenclawGateway(r);if(!o.reachable)return new T("AGENT_ENV_NOT_READY",X0(o),{cause:{reason:Z0}})}catch(o){oe.warn("openclaw gateway diagnose failed (ignored, fall through to original error)",{agentId:e.agentId,err:String(o)})}return i instanceof T?i:new T("AGENT_SPAWN_FAILED",i instanceof Error?i.message:String(i),{cause:i})}async ensureOpenclawDefaultAgent(){let e=this.config.frameworksCache?.openclaw?.defaultAgent;if(e?.id&&e.workspace)return{id:e.id,workspace:e.workspace};oe.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 oe.info("openclaw lazy re-detect success",{agentId:r.defaultAgent.id,workspace:r.defaultAgent.workspace}),this.config.frameworksCache||(this.config.frameworksCache={}),this.config.frameworksCache.openclaw=r,{id:r.defaultAgent.id,workspace:r.defaultAgent.workspace};throw new T("AGENT_ENV_NOT_READY","openclaw default agent \u672A\u63A2\u6D4B\u5230; \u8BF7\u5148\u8DD1 `openclaw setup` \u6216 `openclaw agents add` \u521B\u5EFA\u9ED8\u8BA4 agent",{cause:{reason:Gb}})}async ensureOpenclawGatewayReachable(){let e=this.config.frameworksCache?.openclaw?.path;if(!e)throw new T("AGENT_SPAWN_FAILED","openclaw binary not detected on this machine");let r=await this.detectorFactory().probeOpenclawGateway(e);if(!r.reachable)throw new T("AGENT_ENV_NOT_READY",X0(r),{cause:{reason:Z0}})}async buildOpenclawDownstream(e){let{session:r,modelConfig:i,cloudSessionId:o,cozeEnv:c,mockScenario:d,command:u}=e,h=fd(o);if(r.deployType==="local"){let _=await this.ensureOpenclawDefaultAgent();return new Fr({command:u,cwd:_.workspace,agentId:_.id,sessionName:h})}let x=await $0(),m;if(i?.modelToken){let _=Zc(o),S=Xc(i),y=`${_}/${S}`;if(!this.ensuredProviders.has(y)){let v=this.getOpenclawConfig(),I=await v.getAllowlistModelsForProvider(_),A=t0(i,c,d,I);A&&(await v.ensureProvider(_,A),await v.addModelToAllowlist(y),this.ensuredProviders.add(y))}m=y}return new Fr({command:u,cwd:r.workspace,agentId:r.agentId,sessionName:h,...x?{gatewayToken:x}:{},...m?{slashModelOnStart:m}:{}})}async openclawRepair(e,r){let i=this.getOpenclawConfig();await i.deleteAgent(e),await i.ensureAgent(e,r)}async cleanupOpenclawSessionProviders(e,r){if(e.framework!=="openclaw"||!this.openclawConfigCache)return;let i=this.openclawConfigCache,o=r??e.model;for(let c of e.sessions.keys()){let d=Zc(c),u=`${d}/${o}`,h=!0;try{await i.removeProvider(d)}catch(x){h=!1,oe.warn("removeProvider failed, keeping ensuredProviders entry",{providerId:d,err:String(x)})}try{await i.removeModelFromAllowlist(u)}catch(x){h=!1,oe.warn("removeModelFromAllowlist failed, keeping ensuredProviders entry",{fullModelId:u,err:String(x)})}h&&this.ensuredProviders.delete(u)}}};import{randomUUID as ih}from"node:crypto";import{promises as Zb}from"node:fs";import{basename as sh}from"node:path";Ve();ne();import{promises as jb}from"node:fs";import{basename as Wb}from"node:path";var eh=H("file-upload"),Kb="/api/coze_claw/file/agent_upload",$b=6e4;async function th(t,e={}){let i=`${Rr(Dr(e.handshakeBase))}${Kb}`,o=e.timeoutMs??$b,c=await jb.readFile(t.path),d=new FormData;d.append("agent_id",t.agentId),d.append("session_id",t.sessionId),d.append("file_name",t.name),d.append("file_content",new Blob([c],{type:t.mimeType}),t.name);let u={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...In(e.ppeOverride),...t.accountId?{"x-coze-account":t.accountId}:{}},h=new AbortController,x=setTimeout(()=>h.abort(),o);eh.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:d,signal:h.signal}),_=m.headers.get("x-tt-logid")??"";if(!m.ok){let v=await m.text().catch(()=>"");throw new T("UPLOAD_FAILED",`upload HTTP ${m.status} logid=${_}: ${v.slice(0,200)}`)}let S=await m.json();if(S.code!==void 0&&S.code!==0)throw new T("UPLOAD_FAILED",`upload code=${S.code} msg=${S.msg??"-"} logid=${_}`);let y=S.data?.file?.file_url;if(!y)throw new T("UPLOAD_FAILED",`upload response missing data.file.file_url logid=${_}: ${JSON.stringify(S).slice(0,200)}`);return eh.info("file upload ok",{uri:y,logid:_}),{uri:y}}catch(m){throw m instanceof T?m:m.name==="AbortError"?new T("UPLOAD_FAILED",`upload timeout (${o}ms) for ${Wb(t.path)}`):new T("UPLOAD_FAILED",String(m),{cause:m})}finally{clearTimeout(x)}}Ve();ne();import{extname as Vb}from"node:path";var Jb={".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 nh(t){let e=Vb(t).toLowerCase();return Jb[e]??"application/octet-stream"}Be();var ko=H("agent-send"),rh=50*1024*1024;function oh(t,e,r){let i=t.get(e);if(!i)throw new T("AGENT_NOT_FOUND",`agent=${e}`);if(t.disconnectedAgents.has(e))throw new T("AGENT_DISCONNECTED",`agent=${e} was disconnected by cloud`);let o=i.sessions.get(r);if(!o)throw new T("AGENT_NOT_FOUND",`session=${r} not active in agent=${e}`);return{session:i,runtime:o}}async function ah(t,e,r,i,o,c){let u;for(let h=0;h<=2;h++)try{await t.core.sendAgentFileUpdate(e,r,i,o);return}catch(x){u=x,h<2&&(ko.warn("sendAgentFileUpdate failed, retrying",{attempt:h+1,err:String(x)}),await new Promise(m=>setTimeout(m,5e3)))}throw new T("UPSTREAM_NOT_READY",`${c} after 3 attempts: ${String(u)}`,{cause:u})}async function ch(t,e){let{session:r,runtime:i}=oh(e.core,t.agentId,t.sessionId);if(!await si(t.path,r.workspace))throw new T("PATH_OUTSIDE_WORKSPACE",`path=${t.path} not under workspace=${r.workspace}`);let o=await Zb.stat(t.path).catch(()=>null);if(!o||!o.isFile())throw new T("IPC_BAD_REQUEST",`path is not a regular file: ${t.path}`);if(o.size>rh)throw new T("FILE_TOO_LARGE",`${o.size} bytes > limit ${rh}`);let c=await nh(t.path);if(t.kind==="image"&&!c.startsWith("image/"))throw new T("UNSUPPORTED_MIME",`kind=image but mime=${c}`);if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let d=t.name??sh(t.path),u;try{u=await th({patToken:r.patToken??e.patToken,agentId:t.agentId,sessionId:t.sessionId,path:t.path,mimeType:c,name:d,sizeBytes:o.size,...r.accountId?{accountId:r.accountId}:{}},{handshakeBase:e.handshakeBase,ppeOverride:e.ppeOverride})}catch(x){throw ko.warn("agent file upload failed",{agentId:t.agentId,sessionId:t.sessionId,path:t.path,sizeBytes:o.size,mime:c,code:x instanceof T?x.code:"UNKNOWN",message:x instanceof Error?x.message:String(x)}),x}let h={sessionUpdate:"agent_file",messageId:ih(),content:{type:t.kind==="image"?"image":"resource",uri:u.uri,mimeType:c,name:d,sizeBytes:o.size,...u.fileId!==void 0?{fileId:u.fileId}:{},...t.caption!==void 0?{caption:t.caption}:{}}};return await ah(e,r,i,t.sessionId,h,"agent file uploaded to cloud but sendAgentFileUpdate failed"),ko.info("agent file sent",{agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,name:d,bytes:o.size,mime:c,uri:u.uri}),{ok:!0,uri:u.uri,bytes:o.size,mimeType:c,...u.fileId!==void 0?{fileId:u.fileId}:{}}}async function dh(t,e){let{session:r,runtime:i}=oh(e.core,t.agentId,t.sessionId);if(!t.mimeType)throw new T("IPC_BAD_REQUEST","group-file requires mimeType");if(!e.core.upstream.isConnected())throw new T("UPSTREAM_NOT_READY","cloud WS not connected");let o=t.name??sh(t.path),c={sessionUpdate:"group_file",messageId:ih(),content:{uri:t.path,name:o,mimeType:t.mimeType,...t.caption!==void 0?{caption:t.caption}:{}}};return await ah(e,r,i,t.sessionId,c,"agent group file sendAgentFileUpdate failed"),ko.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 lh(t,e){let r=t.split(".").map(Number),i=e.split(".").map(Number),o=Math.max(r.length,i.length);for(let c=0;c<o;c++){let d=r[c]??0,u=i[c]??0;if(d<u)return!0;if(d>u)return!1}return!1}dn();Xt();ne();var zt=H("coze-cli-installer"),uh="@coze/cli@latest",Xb="coze",fh="0.1.8",Yb=5e3,Qb=5e3,eE=9e4,hh=1e4,Ki=null,To=!1;async function md(t,e={}){if(To)return;if(Ki)return Ki;let r=e.exec??Hf;return Ki=(async()=>{try{let i=await tE(Xb,r),o=!1;if(i){let d=await nE(r);if(d===void 0)zt.warn("coze-cli found but version unparseable, fall through to full install",{path:i});else if(lh(d,fh))zt.info("coze-cli version too old, upgrade-only (preserve user config + auth)",{path:i,version:d,min:fh}),o=!0;else{zt.info("coze-cli already on PATH with sufficient version, skip",{path:i,version:d}),To=!0;return}}let c=o?"upgrade-only":"full";zt.info("coze-cli install start",{package:uh,mode:c});try{await r("npm",["i","-g","--prefer-online",uh],{timeout:eE,maxBuffer:10*1024*1024}),zt.info("coze-cli install ok")}catch(d){zt.warn("coze-cli install failed (skip subsequent steps)",{err:String(d)});return}if(o){To=!0;return}if(t.env)try{await r("coze",["config","set","xTTEnv",t.env],{timeout:hh}),zt.info("coze config set xTTEnv ok",{env:t.env})}catch(d){zt.warn("coze config set failed (continue to auth login)",{err:String(d)})}try{await r("coze",["auth","login","--token",t.patToken],{timeout:hh}),zt.info("coze auth login ok")}catch(d){zt.warn("coze auth login failed",{err:String(d)});return}To=!0}finally{Ki=null}})(),Ki}async function tE(t,e){let r=process.platform==="win32"?"where":"which";try{let{stdout:i}=await e(r,[t],{timeout:Yb});return Oa(i)}catch{return}}async function nE(t){try{let{stdout:e,stderr:r}=await t("coze",["--version"],{timeout:Qb});return(e||r).match(/(\d+\.\d+\.\d+)/)?.[1]}catch{return}}un();Be();var rE=10*6e4;function xh(t){let e=t?.sessionIdleTimeoutMs;return typeof e!="number"||!Number.isFinite(e)||e<=0?rE:e}function Co(t){return lr(t??ee().configFile)}function $i(t,e){return ur(e??ee().configFile,t)}import{randomBytes as vE}from"node:crypto";or();Ve();ne();import{createReadStream as iE}from"node:fs";import{mkdir as sE,readFile as oE,realpath as aE,stat as cE,writeFile as dE}from"node:fs/promises";import{basename as lE,dirname as wd,isAbsolute as uE,join as fE,relative as hE,resolve as ph,sep as xE}from"node:path";import{createInterface as pE}from"node:readline";var mh=H("fs-rpc"),Vi=Ze("COZE_BRIDGE_FS_RPC_MAX_BYTES",20*1024*1024);async function wh(t,e){let r=Buffer.byteLength(t.content,"utf8");if(r>Vi)throw new T("IPC_BAD_REQUEST",`fs/write_text_file content too large: ${r} bytes > limit ${Vi} bytes`);let i=await yh(t.path,e);return await sE(wd(i),{recursive:!0}),await dE(i,t.content,"utf8"),mh.info("fs/write_text_file ok",{path:i,size:t.content.length}),null}async function _h(t,e){let r=await yh(t.path,e),i=await cE(r),o=typeof t.line=="number"||typeof t.limit=="number";if(i.size>Vi&&!o)throw new T("IPC_BAD_REQUEST",`fs/read_text_file too large without line/limit slicing: ${i.size} bytes > ${Vi} bytes`);let c;if(o&&i.size>Vi)c=await gE(r,t.line??1,t.limit);else{let d=await oE(r,"utf8");if(o){let u=d.split(`
|
|
108
|
+
`),h=Math.max(0,(t.line??1)-1),x=typeof t.limit=="number"?h+t.limit:void 0;c=u.slice(h,x).join(`
|
|
109
|
+
`)}else c=d}return mh.info("fs/read_text_file ok",{path:r,size:c.length}),{content:c}}async function gE(t,e,r){let i=pE({input:iE(t,{encoding:"utf8"}),crlfDelay:Number.POSITIVE_INFINITY}),o=Math.max(0,e-1),c=typeof r=="number"?o+r:Number.POSITIVE_INFINITY,d=[],u=0;try{for await(let h of i)if(u>=o&&u<c&&d.push(h),u++,u>=c)break}finally{i.close()}return d.join(`
|
|
110
|
+
`)}async function yh(t,e){if(typeof t!="string"||t.length===0)throw new T("IPC_BAD_REQUEST","path must be a non-empty string");let[r,i]=await Promise.all([gh(ph(e)),gh(ph(t))]),o=hE(r,i);if(mE(o,xE,uE(o)))throw new T("IPC_BAD_REQUEST",`path escapes workspace: ${t}`);return i}function mE(t,e,r){return t===""?!1:r?!0:t===".."||t.startsWith(`..${e}`)}async function gh(t){let e=[],r=t;for(;r!==wd(r);)try{let i=await aE(r);return e.length?fE(i,...e.reverse()):i}catch{e.push(lE(r)),r=wd(r)}return t}ne();var bh=H("prompt-multimodal"),Eh=10*1024*1024,wE=15e3,_E=6;async function vh(t){let e=new Array(t.length),r=0;async function i(){for(;r<t.length;){let c=r++,d=t[c];d!==void 0&&(e[c]=await yE(d))}}let o=Array.from({length:Math.min(_E,t.length)},()=>i());return await Promise.all(o),e}function Sh(t){return t.some(e=>e.type==="image")}async function yE(t){if(t.type!=="image")return t;let e=t;if(e.data||!e.uri||!Ni(e.uri))return t;try{let{buf:r,contentType:i}=await EE(e.uri),o=e.mimeType||bE(i)||"application/octet-stream";return bh.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 bh.warn("image fetch failed, degrading to text block",{uri:e.uri,err:String(r)}),{type:"text",text:`[image load failed: ${e.uri}]`}}}function bE(t){if(!t)return;let e=t.indexOf(";");return(e===-1?t:t.slice(0,e)).trim()||void 0}async function EE(t){let e=new AbortController,r=setTimeout(()=>e.abort(),wE);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>Eh)throw new Error(`image too large: ${o.byteLength} bytes (max ${Eh})`);return{buf:Buffer.from(o),contentType:i.headers.get("content-type")??void 0}}finally{clearTimeout(r)}}fn();Ve();ne();var K=H("core"),SE=3e4,IE=/^(boe|ppe)_[A-Za-z0-9_-]+$/,AE="\u6211\u6B63\u5728\u7B49\u5F85\u5BA1\u6279\uFF0C\u8BF7\u7A0D\u540E\u518D\u8054\u7CFB\u6211",kE="\u5BA1\u6279\u5DF2\u8D85\u65F6",TE=3e4,Ro=class{upstream;agents=new Map;disconnectedAgents=new Set;extensions;paths;sessionSpawner;sessionIdleTimeoutMs;upstreamIds=new Nr;pendingUpstream=new Map;pendingBridge=new Map;currentCozeEnv;currentMockScenario;constructor(e){this.upstream=e.upstream,this.extensions=e.extensions??{},this.paths=e.paths,this.sessionSpawner=e.sessionSpawner,this.sessionIdleTimeoutMs=xh(e.bridgeConfig)}registerExtension(e,r){this.extensions[e]=r}getCozeEnv(){return this.currentCozeEnv}getMockScenario(){return this.currentMockScenario}setMockScenario(e){this.currentMockScenario=e&&e.length>0?e:void 0}async start(){this.upstream.onFrame(e=>this.handleFrame(e)),this.upstream.onConnect?.(({initial:e})=>{e||this.rejectAllPendingOnReconnect()}),await this.upstream.start(),K.info("Core started",{extensions:Object.keys(this.extensions)})}async stop(e){K.info("Core stopping",{reason:e}),await Promise.all([...this.agents.values()].map(r=>r.dispose(e))),this.agents.clear(),await this.upstream.stop(e)}async reloadAgents(e){let r=e?this.agents.has(e)?[e]:[]:[...this.agents.keys()];for(let i of r)await this.agents.get(i)?.killAllRuntimes("reload");return r}get(e){return this.agents.get(e)}register(e){this.agents.set(e.agentId,e),K.info("agent registered",{agentId:e.agentId,framework:e.framework});for(let r of this.registerHandlers)try{r(e.agentId)}catch(i){K.warn("onAgentRegister handler threw (ignored)",{agentId:e.agentId,err:String(i)})}}onAgentRegister(e){return this.registerHandlers.add(e),()=>this.registerHandlers.delete(e)}registerHandlers=new Set;unregister(e){this.agents.delete(e)}reviveIfDisconnected(e){this.disconnectedAgents.delete(e)&&K.info("agent revived from disconnect",{agentId:e})}attachRuntimeHooks(e,r,i){let o=i.downstream;o&&(o.onUpdate(c=>{i.loadingSession||this.forwardUpdate(e,c)}),o.onAgentRequest(c=>{this.handleAgentRequest(e,o,c)}),o.onExit((c,d)=>{K.info("session runtime exited",{agentId:e.agentId,cloudId:r,code:c,signal:d}),Wi(i),i.downstream=void 0,i.replySeq=0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),this.rejectPendingForDownstream(o,"downstream exited")}))}hasPendingPermissionFor(e){for(let r of this.pendingUpstream.values())if(r.downstream===e)return!0;return!1}rejectPendingForDownstream(e,r){let i=[];for(let[o,c]of this.pendingUpstream)c.downstream===e&&i.push(o);if(i.length!==0){K.info("reject pendingUpstream entries (downstream gone)",{reason:r,count:i.length});for(let o of i){let c=this.pendingUpstream.get(o);if(c){this.pendingUpstream.delete(o),this.upstream.send(kn(o,{code:X.INTERNAL_ERROR,message:`bridge downstream gone: ${r}`})).catch(d=>K.debug("send error response to upstream failed (ignored)",{err:String(d)}));try{c.downstream.respondAgentRequestError(c.agentRequestId,{code:X.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:X.INTERNAL_ERROR,message:"upstream reconnected; please retry"})}catch{}this.clearPendingPermissionFor(i)}this.pendingUpstream.clear();for(let[,i]of this.pendingBridge)clearTimeout(i.timer),i.reject(new T("UPSTREAM_DISCONNECTED",`${i.method} aborted: upstream reconnected`));this.pendingBridge.clear()}}async handleFrame(e){if(wo(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&&IE.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,X.METHOD_NOT_FOUND,`extension not registered: ${e.method}`):K.warn("drop notification: extension not registered",{method:e.method});return}let c=await o(e,this);r!==null&&await this.upstream.send(Lr(r,c));return}if(e.method.startsWith("session/")){let o=await this.routeSessionMethod(e);r!==null&&await this.upstream.send(Lr(r,o));return}if(e.method==="initialize"){r!==null&&await this.upstream.send(Lr(r,{protocolVersion:1,agentCapabilities:{loadSession:!0}}));return}r!==null?await this.sendError(r,X.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(kn(r,Hi(o)))}}async routeSessionMethod(e){if(!e.params||typeof e.params!="object")throw new T("IPC_BAD_REQUEST",`${e.method} requires params`);let r=e.params,i=r._meta?.cozeAgentId;if(!i)throw new T("IPC_BAD_REQUEST",`${e.method}: missing _meta.cozeAgentId`);let o=this.agents.get(i);if(!o)throw this.disconnectedAgents.has(i)?new T("AGENT_DISCONNECTED",`agent ${i} has been disconnected; cloud must _agent/create to revive`):new T("AGENT_NOT_FOUND",`agent not found: ${i}`);let c=typeof r.sessionId=="string"?r.sessionId:void 0;if(e.method==="session/cancel"||e.method==="session/new"||e.method==="session/set_mode"||!c)return this.dispatchSessionCall(o,e.method,r);if(e.method==="session/prompt"){let h=o.sessions.get(c);if(h?.pendingPermission){let x=r._meta?.cozeTriggerMsgId,m=uo(r._meta);return K.info("session in pendingPermission, bouncing new prompt",{agentId:o.agentId,cloudSessionId:c}),this.synthesizePromptReply(o,h,c,AE,x,m)}}let d=Date.now(),u=!1;try{let h=await o.getSessionQueue(c).enqueue(()=>this.dispatchSessionCall(o,e.method,r));return u=!0,h}finally{K.info("session call done",{agentId:o.agentId,method:e.method,durationMs:Date.now()-d,ok:u})}}async dispatchSessionCall(e,r,i){e.lastActiveAt=Date.now();let{stripped:o}=zf(i);switch(r){case"session/new":{let c=CE();return K.info("session/new ack (lazy spawn)",{agentId:e.agentId,cloudId:c}),{sessionId:c}}case"session/load":{let c=o;return K.info("session/load ack (lazy spawn)",{agentId:e.agentId,cloudId:c.sessionId}),{}}case"session/prompt":{let c=o,d=c.sessionId;if(!d)throw new T("IPC_BAD_REQUEST","session/prompt: missing sessionId");let u=Yt(e)?Ff(i._meta):void 0;if(u!==void 0&&!Ft(e.framework,u))throw new T("IPC_BAD_REQUEST",`unsupported permissionMode for ${e.framework}: ${u}; allowed: ${ud(e.framework)}`);let h=await this.ensureRuntime(e,d);if(u!==void 0&&h.permissionMode===void 0&&(h.permissionMode=u,await this.persistSessionMapping(e)),h.replySeq=0,await this.ensureDownstream(e,d,h),!h.downstream||!h.acpSessionId)throw new T("BRIDGE_INTERNAL","session runtime not ready after ensureDownstream");if(u!==void 0&&h.permissionMode!==void 0&&h.permissionMode!==u){let S=h.permissionMode;h.permissionMode=u,await this.persistSessionMapping(e);try{await h.downstream.setSessionMode({sessionId:h.acpSessionId,modeId:u})}catch(y){throw h.permissionMode=S,await this.persistSessionMapping(e).catch(()=>{}),y}}let x=i._meta?.cozeTriggerMsgId;x?e.activeTriggers.set(h.acpSessionId,x):e.activeTriggers.delete(h.acpSessionId);let m=uo(i._meta);if(m?e.activeGroupIds.set(h.acpSessionId,m):e.activeGroupIds.delete(h.acpSessionId),m&&h.cozeGroupId!==m&&(h.cozeGroupId=m,await this.persistSessionMapping(e)),e.deployType==="cloud"&&e.modelInfo?.capabilities?.image===!1&&Sh(c.prompt))throw new T("MODEL_MODALITY_UNSUPPORTED",`model=${e.modelInfo.id??e.model} does not support image input`);let _=await vh(c.prompt);try{let S=await h.downstream.sessionPrompt({...c,sessionId:h.acpSessionId,prompt:_});return h.lastActiveAt=Date.now(),S}catch(S){if(S instanceof T&&S.code==="AGENT_APPROVAL_TIMEOUT"){let y=h.pendingPermission;y&&(y.downstream.respondAgentRequest(y.agentRequestId,{outcome:{outcome:"cancelled"}}),this.pendingUpstream.delete(y.upstreamId),h.pendingPermission=void 0);let v=h.acpSessionId,I=v?e.activeTriggers.get(v):void 0,A=v?e.activeGroupIds.get(v):void 0;return K.warn("approval timed out, synthesizing \u5BA1\u6279\u5DF2\u8D85\u65F6 reply + recovering session",{agentId:e.agentId,cloudId:d}),await this.synthesizePromptReply(e,h,d,kE,I,A)}throw S}finally{if(e.activeTriggers.delete(h.acpSessionId),e.activeGroupIds.delete(h.acpSessionId),h.pendingPermission=void 0,h.reloadAfterTurn){h.reloadAfterTurn=!1;let S=h.downstream;S&&(h.downstream=void 0,K.info("reloadAfterTurn: stopping downstream",{agentId:e.agentId,cloudId:d,acpId:h.acpSessionId}),S.stop("reload-after-turn").catch(y=>K.warn("reload-after-turn stop failed (ignored)",{agentId:e.agentId,cloudId:d,err:String(y)})))}else h.downstream?.isAlive()&&this.armIdleTimer(e,d,h)}}case"session/cancel":{let d=o.sessionId;if(!d)throw new T("IPC_BAD_REQUEST","session/cancel: missing sessionId");let u=e.sessions.get(d);if(e.hasSessionQueue(d)){let h=e.getSessionQueue(d);h.size>0&&(K.info("session/cancel: draining queued tasks",{agentId:e.agentId,cloudId:d,queuedCount:h.size}),h.dispose(new T("AGENT_PROTOCOL_ERROR",`cancelled by session/cancel on ${d}`)))}return u?.downstream?.isAlive()&&u.acpSessionId&&await u.downstream.sessionCancel({sessionId:u.acpSessionId}),{ok:!0}}case"session/set_mode":{let c=o,d=c.sessionId,u=c.modeId,h=uo(i._meta);if(!d)throw new T("IPC_BAD_REQUEST","session/set_mode: missing sessionId");if(!Yt(e))throw e.framework==="openclaw"?new T("METHOD_NOT_FOUND","session/set_mode not supported on openclaw"):new T("OPERATION_NOT_ALLOWED_FOR_CLOUD","session/set_mode is local-deploy only in this iteration");if(!Ft(e.framework,u))throw new T("IPC_BAD_REQUEST",`unsupported modeId for ${e.framework}: ${String(u)}; allowed: ${ud(e.framework)}`);if(h)return await this.handleGroupSetMode(e,h,u);let x=e.sessions.get(d)??await this.ensureRuntime(e,d);if(x.permissionMode===u)return{};let m=x.permissionMode;if(x.permissionMode=u,await this.persistSessionMapping(e),x.downstream?.isAlive()&&x.acpSessionId)try{await x.downstream.setSessionMode({sessionId:x.acpSessionId,modeId:u})}catch(_){throw x.permissionMode=m,await this.persistSessionMapping(e).catch(()=>{}),_}else K.info("session/set_mode: runtime not active, persisted only",{framework:e.framework,agentId:e.agentId,cloudId:d,modeId:u});return{}}default:throw new T("IPC_BAD_REQUEST",`session method not supported: ${r}`)}}async handleGroupSetMode(e,r,i){let o=[];for(let[d,u]of e.sessions)u.cozeGroupId===r&&u.permissionMode!==i&&o.push({cloudId:d,runtime:u,oldMode:u.permissionMode});if(o.length===0)return K.info("group session/set_mode: no active runtime (db-only path)",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i}),{};K.info("group session/set_mode: applying to runtimes",{framework:e.framework,agentId:e.agentId,groupId:r,modeId:i,targets:o.length});for(let d of o)d.runtime.permissionMode=i;await this.persistSessionMapping(e);let c=[];for(let d of o){let u=d.runtime.downstream,h=d.runtime.acpSessionId;u?.isAlive()&&h&&c.push({downstream:u,acpSessionId:h,oldMode:d.oldMode,runtime:d.runtime})}for(let d of c)try{await d.downstream.setSessionMode({sessionId:d.acpSessionId,modeId:i})}catch(u){for(let h of o)h.runtime.permissionMode=h.oldMode;throw await this.persistSessionMapping(e).catch(()=>{}),u}return{}}async ensureRuntime(e,r){let i=e.sessions.get(r);if(i)return i;let c={modelToken:e.deployType==="cloud"?await this.requestSessionToken(e.agentId,r):"",tokenGeneratedAt:Date.now(),lastActiveAt:Date.now(),loadingSession:!1,replySeq:0};return Yt(e)&&(c.permissionMode=e.framework==="claude-code"?pd:Q0),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(pt.GEN_MODEL_TOKEN,i,TE);if(!o?.modelToken)throw new T("MODEL_TOKEN_GEN_FAILED",`cloud returned empty modelToken (agentId=${e}, cloudSessionId=${r})`);return o.modelToken}catch(o){throw o instanceof T&&o.code==="MODEL_TOKEN_GEN_FAILED"?o:new T("MODEL_TOKEN_GEN_FAILED",o instanceof Error?o.message:String(o),{cause:o})}}async ensureDownstream(e,r,i){if(Wi(i),i.downstream?.isAlive())return;if(!this.sessionSpawner)throw new T("AGENT_SPAWN_FAILED","sessionSpawner not wired (cannot spawn per-session downstream)");let o=3,c=3e4,d=i.spawnFailCount??0,u=i.spawnFailedAt??0;if(d>=o&&Date.now()-u<c)throw new T("AGENT_SPAWN_FAILED",`agent ${e.agentId} session ${r} spawn failed ${d} times in a row; please check framework binary / network and retry after ${Math.ceil((c-(Date.now()-u))/1e3)}s`);let h;try{h=await this.sessionSpawner(e,i.modelToken,r,this.currentCozeEnv,this.currentMockScenario)}catch(x){throw i.spawnFailCount=d+1,i.spawnFailedAt=Date.now(),i.spawnFailCount>=o&&i.acpSessionId&&(K.warn("clearing stale acpSessionId after repeated spawn failures",{agentId:e.agentId,cloudId:r,staleAcpId:i.acpSessionId}),i.acpSessionId=void 0),x}i.spawnFailCount=0,i.spawnFailedAt=void 0,i.downstream=h,this.attachRuntimeHooks(e,r,i);try{if(i.acpSessionId){i.loadingSession=!0;try{await h.sessionLoad({sessionId:i.acpSessionId,cwd:e.workspace}),K.info("session restored via session/load",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId})}catch(x){K.warn("session/load failed, fallback to session/new",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(x)}),i.acpSessionId=void 0;let m=await h.sessionNew({cwd:e.workspace});i.acpSessionId=m.sessionId,await this.persistSessionMapping(e)}finally{i.loadingSession=!1}}else{let x=await h.sessionNew({cwd:e.workspace});i.acpSessionId=x.sessionId,await this.persistSessionMapping(e)}}catch(x){throw K.warn("session init failed after spawn, tearing down half-spawned runtime",{agentId:e.agentId,cloudId:r,acpId:i.acpSessionId,err:String(x)}),await h.stop("session-init-failed").catch(()=>{}),i.downstream=void 0,i.acpSessionId=void 0,x}if(h.afterSessionEstablished&&i.acpSessionId&&await h.afterSessionEstablished(i.acpSessionId),Yt(e)&&i.acpSessionId&&i.permissionMode)try{await h.setSessionMode({sessionId:i.acpSessionId,modeId:i.permissionMode})}catch(x){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(x)})}}armIdleTimer(e,r,i){if(Wi(i),this.isRuntimeBusy(e,i)){K.debug("skip idle timer: runtime busy (in-flight turn / pending permission)",{agentId:e.agentId,cloudId:r});return}i.idleTimer=setTimeout(()=>{if(i.idleTimer=void 0,this.isRuntimeBusy(e,i)){K.info("idle reaper fired but runtime busy, re-arming",{agentId:e.agentId,cloudId:r}),this.armIdleTimer(e,r,i);return}K.info("session runtime idle timeout, killing downstream",{agentId:e.agentId,cloudId:r});let o=i.downstream;i.downstream=void 0,i.acpSessionId&&e.activeTriggers.delete(i.acpSessionId),o&&o.stop("idle timeout").catch(c=>K.warn("idle stop failed (ignored)",{agentId:e.agentId,cloudId:r,err:String(c)}))},this.sessionIdleTimeoutMs),i.idleTimer.unref?.()}isRuntimeBusy(e,r){if(r.acpSessionId&&e.activeTriggers.has(r.acpSessionId))return!0;let i=r.downstream;if(!i)return!1;for(let o of this.pendingUpstream.values())if(o.downstream===i)return!0;return!1}async sendAgentFileUpdate(e,r,i,o){let c={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};if(r.acpSessionId){let d=e.activeTriggers.get(r.acpSessionId);d&&(c.cozeTriggerMsgId=d);let u=e.activeGroupIds.get(r.acpSessionId);u&&(c.cozeGroupId=u)}await this.upstream.send(Or("session/update",{sessionId:i,update:o,_meta:c}))}async synthesizePromptReply(e,r,i,o,c,d){let u={cozeAgentId:e.agentId,cozeReplySeqID:++r.replySeq};return c&&(u.cozeTriggerMsgId=c),d&&(u.cozeGroupId=d),await this.upstream.send(Or("session/update",{sessionId:i,update:{sessionUpdate:"agent_message_chunk",content:{type:"text",text:o}},_meta:u})).catch(h=>K.warn("synthesizePromptReply update send failed (ignored)",{err:String(h)})),{stopReason:"end_turn"}}forwardUpdate(e,r){let i=r.sessionId,o=this.reverseSessionId(e,i);if(!o){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(PE(r)){K.debug("drop codex noise chunk",{agentId:e.agentId,acpId:i});return}let d=r.update;if(d&&typeof d=="object"&&d.sessionUpdate==="current_mode_update"&&Yt(e)){let m=d.currentModeId;Ft(e.framework,m)&&c.permissionMode!==m?(c.permissionMode=m,this.persistSessionMapping(e).catch(_=>K.warn("persist mode (from current_mode_update) failed",{framework:e.framework,agentId:e.agentId,err:String(_)}))):typeof m=="string"&&!Ft(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},h=e.activeTriggers.get(i);h&&(u.cozeTriggerMsgId=h);let x=e.activeGroupIds.get(i);x&&(u.cozeGroupId=x),this.upstream.send(Or("session/update",{...r,sessionId:o,_meta:u})).catch(m=>K.warn("forward update failed",{agentId:e.agentId,err:String(m)}))}handleAgentRequest(e,r,i){if(i.method==="session/request_permission"){this.forwardPermissionRequest(e,r,i);return}if(i.method==="fs/write_text_file"||i.method==="fs/read_text_file"){this.handleFsRpcRequest(e,r,i);return}K.warn("unhandled agent request,returning method_not_found",{agentId:e.agentId,method:i.method}),r.respondAgentRequestError(i.id,{code:X.METHOD_NOT_FOUND,message:`method not handled by Bridge: ${i.method}`})}async handleFsRpcRequest(e,r,i){try{let o=e.workspace;if(i.method==="fs/write_text_file"){let c=i.params??{},d=await wh(c,o);r.respondAgentRequest(i.id,d)}else{let c=i.params??{},d=await _h(c,o);r.respondAgentRequest(i.id,d)}}catch(o){K.warn("fs rpc handler failed",{agentId:e.agentId,method:i.method,err:String(o)}),r.respondAgentRequestError(i.id,Hi(o))}}clearPendingPermissionFor(e){if(e.method!=="session/request_permission"||!e.cloudSessionId)return;let r=this.agents.get(e.agentId)?.sessions.get(e.cloudSessionId);r&&(r.pendingPermission=void 0)}forwardPermissionRequest(e,r,i){let o=this.upstreamIds.next("session/request_permission"),c=i.params??{},u=c.sessionId,h=u?e.activeTriggers.get(u):void 0,x={cozeAgentId:e.agentId};h&&(x.cozeTriggerMsgId=h);let m=u?e.activeGroupIds.get(u):void 0;m&&(x.cozeGroupId=m);let _=u?this.reverseSessionId(e,u):void 0,S=_?e.sessions.get(_):void 0;S&&(S.pendingPermission={downstream:r,agentRequestId:i.id,upstreamId:o});let y={...c,..._?{sessionId:_}:{},_meta:x};this.pendingUpstream.set(o,{agentRequestId:i.id,agentId:e.agentId,downstream:r,method:i.method,cloudSessionId:_}),K.info("forward permission_request \u2192 upstream",{agentId:e.agentId,upstreamId:o,acpSessionId:u,cloudSessionId:_,toolCallId:c.toolCall?.toolCallId,options:c.options?.map(v=>({optionId:v.optionId,kind:v.kind,name:v.name}))}),this.upstream.send(Ui(o,"session/request_permission",y)).catch(v=>{this.pendingUpstream.delete(o),K.error("forward permission request failed",{agentId:e.agentId,err:String(v)}),r.respondAgentRequestError(i.id,{code:X.INTERNAL_ERROR,message:`upstream send failed: ${String(v)}`})})}handleUpstreamResponse(e){if(e.id===null)return;let r=this.lookupPending(this.pendingUpstream,e.id,"upstream");if(r){this.pendingUpstream.delete(r.key);let o=r.value;this.clearPendingPermissionFor(o),e.error?(K.info("upstream \u2192 permission response (error)",{agentId:o.agentId,upstreamId:e.id,method:o.method,error:e.error}),o.downstream.respondAgentRequestError(o.agentRequestId,e.error)):(o.method==="session/request_permission"&&RE(e.result,o),K.info("upstream \u2192 permission response (result)",{agentId:o.agentId,upstreamId:e.id,method:o.method,result:e.result}),o.downstream.respondAgentRequest(o.agentRequestId,e.result));return}let i=this.lookupPending(this.pendingBridge,e.id,"bridge");if(i){this.pendingBridge.delete(i.key),clearTimeout(i.value.timer),e.error?i.value.reject(new mo(e.error)):i.value.resolve(e.result);return}K.debug("orphan upstream response (no pending)",{id:e.id})}lookupPending(e,r,i){let o=e.get(r);if(o)return{value:o,key:r};if(typeof r=="number"){let c=String(r),d=e.get(c);if(d)return K.warn(`${i} id type mismatch: number received but Bridge expected string`,{rawId:r,normalizedId:c}),{value:d,key:c}}}sendRequest(e,r,i=SE){let o=this.upstreamIds.next(e);return new Promise((c,d)=>{let u=setTimeout(()=>{this.pendingBridge.delete(o),d(new T("AGENT_TIMEOUT",`${e} timed out after ${i}ms`))},i);this.pendingBridge.set(o,{method:e,resolve:c,reject:d,timer:u}),this.upstream.send(Ui(o,e,r)).catch(h=>{let x=this.pendingBridge.get(o);x&&(clearTimeout(x.timer),this.pendingBridge.delete(o)),d(h)})})}async persistSessionMapping(e){if(this.paths)try{let r=new Map;for(let[i,o]of e.sessions){let c={modelToken:o.modelToken,tokenGeneratedAt:o.tokenGeneratedAt};o.acpSessionId&&(c.acpSessionId=o.acpSessionId),o.permissionMode&&Yt(e)&&(c.permissionMode=o.permissionMode),o.cozeGroupId&&(c.cozeGroupId=o.cozeGroupId),r.set(i,c)}await oi(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(kn(e,{code:r,message:i,data:{bridgeVersion:Nt}}))}};function CE(){return vE(16).toString("hex")}function RE(t,e){if(!t||typeof t!="object"){K.warn("permission response: result not an object (suspicious)",{agentId:e.agentId,result:t});return}let r=t;if("kind"in r&&!("outcome"in r)){K.warn('permission response: top-level "kind" field (D66 historical bug shape)',{agentId:e.agentId,result:t});return}let i=r.outcome;if(!i||typeof i!="object"){K.warn("permission response: missing or non-object outcome field",{agentId:e.agentId,result:t});return}let c=i.outcome;(typeof c!="string"||c!=="selected"&&c!=="cancelled")&&K.warn("permission response: unknown outcome discriminant",{agentId:e.agentId,outcomeValue:c,result:t})}var DE=["Model metadata for `","Falling back from WebSockets to HTTPS transport.","Heads up: Long threads and multiple compactions can cause the model to be less accurate."],Ih="Warning: ";function PE(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 o=i.text.startsWith(Ih)?i.text.slice(Ih.length):i.text;return DE.some(c=>o.startsWith(c))}un();ne();Be();import{randomBytes as OE}from"node:crypto";import{createServer as LE}from"node:http";var NE=1e6,Ah=H("ipc"),Do=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??ee()}async start(){this.token=OE(32).toString("hex");let e=LE((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(),Ah.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 ln(this.paths.portFile,String(this.port)),await ln(this.paths.tokenFile,this.token,{mode:384})}async dispatch(e,r){if(e.headers.authorization!==`Bearer ${this.token}`){Ji(r,401,{error:"unauthorized"});return}let o=`${e.method} ${(e.url??"").split("?")[0]}`,c=this.routes.get(o);if(!c){Ji(r,404,{error:"not found"});return}let d=null;if(e.method==="POST")try{d=await ME(e)}catch(u){Ji(r,400,{error:"invalid json",detail:String(u)});return}try{let u=await c.handler(d,e);Ji(r,200,u??{ok:!0})}catch(u){Ah.error("IPC handler failed",{key:o,err:String(u)}),Ji(r,500,{error:u instanceof Error?u.message:String(u)})}}};function Ji(t,e,r){t.statusCode=e,t.setHeader("content-type","application/json"),t.end(JSON.stringify(r))}async function ME(t){let e=[],r=0;for await(let o of t){let c=o;if(r+=c.length,r>NE)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 nS=jt(Ex(),1),rS=jt(Uo(),1),iS=jt(Gr(),1),sS=jt(Cd(),1),oS=jt(Pd(),1),aS=jt(Fd(),1),Dx=jt(jo(),1),cS=jt(Rx(),1);var Px=Dx.default;Ve();ne();var{FWS:SS}=qx(),Le=H("upstream.frontier"),Wx="application/json",Kx="none",IS=15e3;function AS(t){class e extends Px{constructor(i){super(i,jf,{headers:t})}guardTeardown(){this.listenerCount("error")===0&&this.on("error",i=>Le.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(kl("debug"))try{let c;typeof i=="string"?c=Buffer.from(i,"utf8"):i instanceof Buffer?c=i:i instanceof ArrayBuffer?c=new Uint8Array(i):ArrayBuffer.isView(i)?c=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):c=new Uint8Array(0);let d=Buffer.from(c.slice(0,128)).toString("hex");Le.debug("WS raw frame out",{bytes:c.byteLength,headHex:d})}catch(c){Le.warn("WS raw frame dump failed",{err:String(c)})}super.send(i,...o)}}return e}var is=class{constructor(e){this.opts=e}opts;fws=null;handler=null;connectHandlers=[];opened=!1;lastSendRefusedLogAt=0;sendRefusedSuppressed=0;openCount=0;async start(){if(this.fws){Le.warn("start called on already-started FrontierUpstream; noop");return}let e={Authorization:`Bearer ${this.opts.privatecode}`,Origin:Wf,...In(this.opts.ppeOverride)},r=AS(e),i=$f(this.opts.urlOverride),o={url:i,ws:r,fpID:qf,aID:fo,accessKey:this.opts.handshake.accessKey,deviceID:this.opts.handshake.deviceId,payloadType:{type:Wx,force:!0},payloadEncoding:{encoding:Kx,force:!0},enableTransformTextPayload:!0,enableQoS:!1,enableAutoAck:!1,automaticOpen:!1,maxRetries:Number.POSITIVE_INFINITY,debug:this.opts.debug??!1},c=new SS(o),d=!1,u=null,h,x,m=new Promise((y,v)=>{h=y,x=v}),_=y=>{d||(d=!0,u&&(clearTimeout(u),u=null),y?x(y):h())};c.onopen=()=>{this.opened=!0,this.openCount+=1;let y=this.openCount===1;Le.info("frontier opened",{url:i,remoteDeviceId:this.opts.handshake.deviceId,initial:y,openCount:this.openCount}),y&&_();for(let v of this.connectHandlers)Promise.resolve(v({initial:y})).catch(I=>Le.warn("onConnect handler threw (ignored)",{err:String(I)}))},c.onclose=y=>{this.opened=!1,Le.info("frontier closed",{code:y.code,reason:y.reason,willReconnect:y.willReconnect})},c.onerror=y=>{Le.warn("frontier error",{code:y.code,msg:y.message}),_(new T("UPSTREAM_DISCONNECTED",`frontier connect error before open: code=${y.code} msg=${y.message??""}`))},c.onmessage=y=>this.handleMessage(y),this.fws=c;let S=this.opts.openTimeoutMs??IS;u=setTimeout(()=>{_(new T("UPSTREAM_DISCONNECTED",`frontier ws open timeout after ${S}ms (handshake or upgrade slow)`))},S),await c.connect();try{await m}catch(y){try{c.close(1e3,"open failed")}catch(v){Le.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){Le.warn("frontier close threw (ignored)",{err:String(i)})}}}async send(e){let r=this.fws,i=e.method;if(!r)throw Le.warn("frontier send refused: upstream not started",{method:i}),new T("UPSTREAM_DISCONNECTED","frontier upstream not started");if(!this.isConnected()){let u=Date.now();throw u-this.lastSendRefusedLogAt>1e3?(Le.warn("frontier send refused: ws not open",{method:i,opened:this.opened,readyState:r.readyState,...this.sendRefusedSuppressed>0?{suppressedSinceLast:this.sendRefusedSuppressed}:{}}),this.lastSendRefusedLogAt=u,this.sendRefusedSuppressed=0):this.sendRefusedSuppressed+=1,new T("UPSTREAM_DISCONNECTED",`frontier ws not open (opened=${this.opened}, readyState=${r.readyState}); refusing to silently buffer`)}this.injectAgentPatToken(e);let o=JSON.stringify(e),c=e;$x(c)||Le.info("frontier frame out",{method:c.method,jsonrpcId:c.id,size:o.length});try{await r.send(o,{service:33555712,method:1,payloadType:Wx,payloadEncoding:Kx})}catch(u){throw Le.warn("frontier frame send failed",{method:c.method,jsonrpcId:c.id,err:String(u)}),new T("UPSTREAM_DISCONNECTED",`frontier send failed: ${String(u)}`,{cause:u})}}onFrame(e){this.handler=e}onConnect(e){this.connectHandlers.push(e)}isConnected(){return this.opened&&this.fws?.readyState===1}injectAgentPatToken(e){let r=this.opts.getPatTokenForAgent;if(!r)return;let i=e.params?._meta;if(!i?.cozeAgentId)return;let o=r(i.cozeAgentId);o&&(i.cozePatToken=o)}handleMessage(e){let r=e.message?.service;if(r!==33555712){Le.debug("drop non-adapter frontier frame",{service:r});return}let i=CS(e);if(!i){Le.debug("frontier message without text payload, drop",{payloadType:e.message?.payloadType});return}if(!this.handler){Le.debug("frame received but no onFrame handler",{size:i.length});return}let o;try{o=JSON.parse(i)}catch(d){Le.warn("frontier message JSON parse failed",{err:String(d),head:i.slice(0,80)});return}let c=o;$x(c)||Le.info("frontier frame in",{logid:TS(e.message?.LogID),logidNew:e.message?.LogIDNew,msgId:e.message?.msgID,jsonrpcId:c.id,method:c.method,body:kS(i)}),Promise.resolve(this.handler(o)).catch(d=>Le.warn("frontier frame handler threw",{err:String(d)}))}};function $x(t){return t.method==="_agent/health"?!0:typeof t.id=="string"&&t.id.startsWith("agent.health_")}var Vx=2e3;function kS(t){return t.length<=Vx?t:`${t.slice(0,Vx)}...<truncated, total ${t.length} chars>`}function TS(t){return t?t.high===0?String(t.low>>>0):`${t.high.toString(16)}${(t.low>>>0).toString(16).padStart(8,"0")}`:""}function CS(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}}Ve();ne();var Hd=H("skill-publish"),RS="/api/marketplace/product/skill/publish_with_assets",DS=15e4;async function Jx(t,e={}){let i=`${Rr(Dr(e.handshakeBase))}${RS}`,o=e.timeoutMs??DS,c=new FormData;c.append("skill_id",t.skillId??""),c.append("skill_name",t.skillName),c.append("skill_description",t.description??""),c.append("agent_id",t.agentId),c.append("zip_file",new Blob([t.zip],{type:"application/zip"}),"skill.zip");let d={Authorization:`Bearer ${t.patToken}`,Accept:"application/json","x-coze-version":"3.0",...In(e.ppeOverride),...t.accountId&&t.accountId!=="0"?{"x-coze-account":t.accountId}:{}},u=new AbortController,h=setTimeout(()=>u.abort(),o);Hd.info("skill publish start",{url:i,method:"POST",form:{skill_id:t.skillId??"",skill_name:t.skillName,skill_description:t.description??"",agent_id:t.agentId,zip_file_bytes:t.zip.length},headers:{...d,Authorization:`Bearer ${t.patToken.slice(0,8)}...`}});try{let x=await fetch(i,{method:"POST",headers:d,body:c,signal:u.signal}),m=x.headers.get("x-tt-logid")??"";if(!x.ok){let y=await x.text().catch(()=>"");throw new T("UPLOAD_FAILED",`skill publish HTTP ${x.status} logid=${m}: ${y.slice(0,200)}`)}let _=await x.json();if(Hd.info("skill publish response",{logid:m,httpStatus:x.status,code:_.code,msg:_.msg,dataSkillId:_.data?.skill_id??"",dataVersion:_.data?.version??""}),_.code!==void 0&&_.code!==0)throw new T("UPLOAD_FAILED",`skill publish code=${_.code} msg=${_.msg??"-"} logid=${m}`);let S={};return _.data?.skill_id!==void 0&&_.data.skill_id!==""&&(S.skillId=String(_.data.skill_id)),_.data?.version&&(S.version=_.data.version),Hd.info("skill publish ok",{logid:m,skillId:S.skillId??"",version:S.version??""}),S}catch(x){throw x instanceof T?x:x.name==="AbortError"?new T("UPLOAD_FAILED",`skill publish timeout (${o}ms): ${t.skillName}`):new T("UPLOAD_FAILED",String(x),{cause:x})}finally{clearTimeout(h)}}ne();var qd=H("upstream.switchable"),Qo=class{inner;handler=null;connectHandlers=[];constructor(e){this.inner=e}async swap(e,r){if(this.inner===e)return;qd.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 qd.error("swap target start failed, reverting",{err:String(o)}),this.inner=i,o}await i.stop(r??"swapped").catch(o=>qd.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 jd=H("upstream"),$r=class{handler=null;async start(){jd.info("NoopUpstream started (M1 skeleton; real Frontier wired in M4)")}async stop(e){jd.info("NoopUpstream stopped",{reason:e})}async send(e){jd.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)}};Ve();ne();un();ne();Be();import{promises as PS}from"node:fs";var Zx=H("pat-token-store");async function ea(t=ee()){try{let r=(await PS.readFile(t.patTokenFile,"utf8")).trim();return r.length===0?(Zx.warn("pat-token exists but empty (treating as missing; likely interrupted write)",{path:t.patTokenFile}),null):r}catch(e){let r=e?.code;return r!=="ENOENT"&&Zx.warn("read pat-token failed (treating as missing)",{path:t.patTokenFile,code:r,message:e.message}),null}}async function ss(t,e=ee()){if(!t)throw new Error("writePatToken: empty patToken");await ln(e.patTokenFile,t,{mode:384})}Be();Be();import{promises as ta}from"node:fs";import{join as OS}from"node:path";function LS(t,e){return`#!/bin/sh
|
|
105
111
|
exec ${JSON.stringify(e)} ${JSON.stringify(t)} "$@"
|
|
106
|
-
`}function
|
|
112
|
+
`}function NS(t,e){return`@echo off\r
|
|
107
113
|
"${e}" "${t}" %*\r
|
|
108
|
-
`}async function
|
|
114
|
+
`}async function Xx(t,e=ee()){let r=e.binDir;await ta.mkdir(r,{recursive:!0});let i=OS(r,process.platform==="win32"?"coze-bridge.cmd":"coze-bridge"),o=process.execPath,c=process.platform==="win32"?NS(t,o):LS(t,o);return await ta.readFile(i,"utf8").catch(()=>null)===c||(await ta.writeFile(i,c,"utf8"),process.platform!=="win32"&&await ta.chmod(i,493)),r}ne();Be();import{execSync as Yx}from"node:child_process";import{readFileSync as Qx,unlinkSync as MS}from"node:fs";import{mkdir as BS,open as FS,readFile as ep,unlink as Wd,writeFile as zS}from"node:fs/promises";import{dirname as US}from"node:path";var GS=H("single-instance"),HS=t=>new Promise(e=>setTimeout(e,t)),na=class{pidFile;selfPid;probe;claimLockMaxAttempts;claimLockIntervalMs;acquired=!1;constructor(e={}){this.pidFile=e.pidFile??ee().pidFile,this.selfPid=e.selfPid??process.pid,this.claimLockMaxAttempts=e.claimLockMaxAttempts??50,this.claimLockIntervalMs=e.claimLockIntervalMs??20,this.probe=e.probe??{isAlive:r=>qi(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&&GS.warn("removing stale pid file",{stalePid:i}),await zS(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 ep(this.pidFile,"utf8")).trim()===String(this.selfPid)&&await Wd(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 ep(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 BS(US(r),{recursive:!0});for(let i=0;i<this.claimLockMaxAttempts;i++){let o;try{o=await FS(r,"wx")}catch(c){if(c.code!=="EEXIST")throw c;let d=await this.readPidFrom(r);if(d!==null&&d!==this.selfPid&&this.probe.isAlive(d)){await HS(this.claimLockIntervalMs);continue}await Wd(r).catch(()=>{});continue}try{return await o.writeFile(String(this.selfPid)),await e()}finally{await o.close().catch(()=>{}),await Wd(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=Qx(`/proc/${e}/cmdline`,"utf8").replace(/\0/g," ");return!!(r.includes(Mr)||r.includes("lib/index.js"))}catch{}try{let r=Yx(`ps -o command= -p ${e}`,{stdio:["ignore","pipe","ignore"],timeout:1e3}).toString();return r.trim()?r.includes(Mr)||r.includes("lib/index.js"):!1}catch{return!0}}matchesDaemonTitleWindows(e){try{let i=Yx(`tasklist /FI "PID eq ${e}" /FO CSV /NH`,{stdio:["ignore","pipe","ignore"],timeout:2e3}).toString().trim();if(!i||/^(INFO|信息)[::]/.test(i))return!1;let o=i.split(",",1)[0]?.replace(/^"|"$/g,"").toLowerCase()??"";return o.includes("node")||o.includes("coze-bridge")}catch{return!0}}installCleanupHooks(){process.once("exit",()=>{if(this.acquired)try{Qx(this.pidFile,"utf8").trim()===String(this.selfPid)&&MS(this.pidFile)}catch{}})}};ra();ne();var tr=H("daemon.upstream-watchdog"),ZS=12e4,XS=9e5,YS=3e4;function $d(t,e){let r=process.env[t];if(!r)return e;let i=Number(r);return Number.isFinite(i)&&i>0?i:e}var ia=class{constructor(e){this.opts=e;this.softMs=e.softMs??$d("COZE_BRIDGE_UPSTREAM_WATCHDOG_SOFT_MS",ZS),this.hardMs=e.hardMs??$d("COZE_BRIDGE_UPSTREAM_WATCHDOG_HARD_MS",XS),this.intervalMs=e.intervalMs??$d("COZE_BRIDGE_UPSTREAM_WATCHDOG_INTERVAL_MS",YS),this.now=e.now??Date.now}opts;softMs;hardMs;intervalMs;now;timer=null;downSince=null;forcedAt=null;forcing=!1;lastTickAt=null;start(){this.timer||(this.timer=setInterval(()=>this.tick(),this.intervalMs),this.timer.unref?.(),tr.info("upstream watchdog started",{softMs:this.softMs,hardMs:this.hardMs,intervalMs:this.intervalMs}))}stop(){this.timer&&(clearInterval(this.timer),this.timer=null),this.downSince=null,this.forcedAt=null,this.lastTickAt=null}tick(){let e=this.now();if(this.lastTickAt!==null&&e-this.lastTickAt>this.intervalMs*3&&(this.downSince!==null&&tr.warn("upstream watchdog: large tick gap (likely sleep/suspend), resetting downSince",{gapMs:e-this.lastTickAt}),this.downSince=null,this.forcedAt=null),this.lastTickAt=e,this.opts.isConnected()){this.downSince!==null&&tr.info("upstream watchdog: reconnected, reset",{downMs:this.now()-this.downSince}),this.downSince=null,this.forcedAt=null;return}if(this.downSince===null){this.downSince=e,tr.warn("upstream watchdog: disconnect detected, arming",{softMs:this.softMs,hardMs:this.hardMs});return}let r=e-this.downSince;if(r>=this.hardMs){tr.error("upstream watchdog: disconnected too long, exiting for supervisor restart",{downMs:r,hardMs:this.hardMs}),this.opts.onFatal(r);return}r>=this.softMs&&this.shouldForceNow(e)&&(this.forcedAt=e,this.forcing=!0,tr.warn("upstream watchdog: forcing reconnect",{downMs:r,softMs:this.softMs}),Promise.resolve().then(()=>this.opts.forceReconnect()).catch(i=>tr.warn("upstream watchdog: forceReconnect error (ignored)",{err:String(i)})).finally(()=>{this.forcing=!1}))}shouldForceNow(e){return!(this.forcing||this.forcedAt!==null&&e-this.forcedAt<this.softMs)}};var q=H("daemon");async function rp(){let t=ee();if(process.env.COZE_BRIDGE_LOG_MODE!=="legacy"){Il({bridgeLogsDir:t.bridgeLogsDir,agentLogsDir:D=>Xe(D,t).logs,listAgentIds:()=>ms(t)});try{let{writeFileSync:D}=await import("node:fs");D(t.logFile,`\u8FD0\u884C\u65E5\u5FD7\u5DF2\u8FC1\u79FB\u5230 dated \u6587\u4EF6, \u6B64\u6587\u4EF6 (bridge.log) \u4E0D\u518D\u5199\u5165\u8FD0\u884C\u65E5\u5FD7\u3002
|
|
109
115
|
\u8BF7\u67E5\u770B: ${t.bridgeLogsDir}/bridge-<YYYY-MM-DD>.log
|
|
110
116
|
\u6216\u4F7F\u7528: coze-bridge log [-f] [--lines N]
|
|
111
|
-
`)}catch{}}let e=new na({processTitle:Mr}),n=await e.acquire();if(n.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${n.pid})`);let i=await Co(),o=i??{};hs({pid:process.pid}),$.info(i?"loaded bridge config":"initialized bridge config");let c=new Qo(new $r),d=null,u=new Po({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(P,j,V,re)=>{if(!d)throw new Error("agentManager not ready");return d.spawnSessionDownstream(P,j,V,re)}}),x=new Ao({paths:t,config:o,registry:u});d=x;let h,g,w=null,v={},_,E=null,I=null,A=null,T=new kn;function R(P,j){return T.enqueue(()=>C(P,j))}function y(){I||(I=new ia({isConnected:()=>c.isConnected()&&!(E?.isLivenessLost()??!1),forceReconnect:()=>A?R(A,{force:!0}):void 0,onFatal:P=>{if(process.env[ss]==="1"){$.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:P});return}$.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:P}),process.exit(1)}})),I.start()}async function C(P,j){let V=P,re=V?.privatecode;if(!re)throw new k("IPC_BAD_REQUEST","/connect requires privatecode");let et=Mi(V.env),me=V.handshake_url,we=V.frontier_url,It=Qh(V.env,me,we);if(A=V,!j?.force&&h===re&&g===It){let be=await q1(t);return u.agents.size===0&&be?($.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),oa(t,x).catch(Te=>$.warn("connect-noop auto-revive error (ignored)",{err:String(Te)}))):$.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let gt=!!h&&h!==re,tn=g!==void 0&&g!==It,Ut=gt||tn,nn=await Hc({privatecode:re,...me?{endpoint:me}:{},ppeOverride:et});if(Ut){$.warn("connect config switched, resetting agents",{pcChanged:gt,envChanged:tn,previousPc:h?sa(h):"",nextPc:sa(re)});for(let be of[...u.agents.values()])await be.dispose("connect config switch").catch(()=>{}),u.agents.delete(be.agentId);u.disconnectedAgents.size>0&&($.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new $r,"connect switch").catch(()=>{})}w=nn.deviceId,hs({deviceId:w,pid:process.pid}),pd({patToken:re,env:V.env}).catch(be=>$.warn("coze-cli setup error (ignored)",{err:String(be)}));let Xr=new rs({handshake:nn,privatecode:re,...we?{urlOverride:we}:{},ppeOverride:et,getPatTokenForAgent:be=>u.agents.get(be)?.patToken});return await c.swap(Xr,"connect"),h=re,g=It,v=et,_=me,V.mock_scenario!==void 0&&(u.setMockScenario(V.mock_scenario),$.info("mock scenario set",{scenario:V.mock_scenario})),E||(E=new Fi({core:u,getDeviceId:()=>w??"",onTickEnd:()=>B.retryPending().catch(be=>$.warn("detailSync.retryPending failed (ignored)",{err:String(be)})),onAuthFailures:Y})),E.start(),y(),Ut&&oa(t,x).catch(be=>$.warn("post-connect-switch auto-revive error (ignored)",{err:String(be)})),is(re,t).catch(be=>$.warn("writePatToken after /connect failed (ignored)",{err:String(be)})),$.info("/connect: WS established",{deviceId:w}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async P=>x.createAgent(P.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let D={},F=new ho({agents:u.agents,publishSkillToMarketplace:async P=>{let j=u.agents.get(P.agentId)?.patToken??h;if(!j)throw new k("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");return Kh({patToken:j,zip:P.zip,...P.skillId?{skillId:P.skillId}:{},skillName:P.skillName,...P.description?{description:P.description}:{},agentId:P.agentId,...P.accountId?{accountId:P.accountId}:{}},{handshakeBase:_,ppeOverride:v})},disposeAndMarkDisconnected:async(P,j)=>{let V=u.agents.get(P);if(V){await x.cleanupOpenclawSessionProviders(V).catch(et=>$.warn("cleanup openclaw providers failed (ignored)",{agentId:P,err:String(et)}));let re=!0;try{await V.dispose(`disconnect: ${j}`)}catch(et){re=!1,$.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:P,err:String(et)}),V.status="error"}re&&(V.status="disconnected",u.unregister(P),u.disconnectedAgents.add(P))}else u.disconnectedAgents.add(P)},disposeForDelete:async(P,j)=>{let V=u.agents.get(P);V&&(await x.cleanupOpenclawSessionProviders(V).catch(re=>$.warn("cleanup openclaw providers during delete failed (ignored)",{agentId:P,err:String(re)})),await V.dispose(`delete: ${j}`).catch(re=>$.warn("dispose during delete failed (ignored)",{agentId:P,err:String(re)})),u.unregister(P)),u.disconnectedAgents.delete(P)},detailSyncer:async P=>{if(!D.ref)throw new Error("agent-detail-sync not initialized yet");await D.ref.syncOne(P)},cleanupOpenclawProviders:async(P,j)=>{await x.cleanupOpenclawSessionProviders(P,j)},openclawRepair:async(P,j)=>{await x.openclawRepair(P,j)},isRuntimePendingPermission:P=>u.hasPendingPermissionFor(P)});u.registerExtension("_agent/listSkills",P=>F.listSkills(P.params)),u.registerExtension("_agent/addSkills",P=>F.addSkills(P.params)),u.registerExtension("_agent/removeSkills",P=>F.removeSkills(P.params)),u.registerExtension("_agent/publishSkill",P=>F.publishSkill(P.params)),u.registerExtension("_agent/getFileTree",P=>F.getFileTree(P.params)),u.registerExtension("_agent/getFileContent",P=>F.getFileContent(P.params)),u.registerExtension("_agent/update",P=>F.updateAgent(P.params)),u.registerExtension("_agent/disconnect",P=>F.disconnectAgent(P.params)),u.registerExtension("_agent/switchModel",P=>F.switchModel(P.params)),u.registerExtension("_agent/reset",P=>F.resetAgent(P.params)),u.registerExtension("_agent/repair",P=>F.repairAgent(P.params)),u.registerExtension("_agent/delete",P=>F.deleteAgent(P.params)),u.registerExtension("_agent/upgrade",P=>F.upgradeBridge(P.params));let B=new ys({paths:t,handlers:F,agentManager:x,sendDetail:P=>u.sendRequest("_agent/detail",P)});D.ref=B;let Y=async P=>{await Promise.allSettled(P.map(async j=>{try{await F.disconnectAgent({agentId:j.agentId,reason:`auth_failure: code=${j.code} ${j.message}`}),$.info("agent disconnected due to auth failure from heartbeat response",{agentId:j.agentId,code:j.code,message:j.message})}catch(V){$.warn("disconnect during authFailure handling failed (ignored)",{agentId:j.agentId,err:String(V)})}}))};c.onConnect(({initial:P})=>{$.info("frontier upstream connected, triggering detail sync",{initial:P}),B.syncAll(P?"initial-connect":"reconnect").catch(j=>$.warn("detail sync top-level error (ignored)",{err:String(j)}))});let Z=new Ro({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let P=u.getMockScenario();return{running:!0,pid:process.pid,nodeExecPath:process.execPath,nodeVersion:process.version,nodeArch:process.arch,spawnedBy:process.env[ss]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:w??"",frameworksCache:o.frameworksCache??{},...P?{mockScenario:P}:{}}}},{method:"POST",path:"/pair",handler:async P=>{let j=P,V=j?.privatecode,re=j?.pairing_code;if(!V||!re)throw new k("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let et=Mi(j.env),me=j.handshake_url,we=j.frontier_url,It=Qh(j.env,me,we),gt=!!h&&h!==V,tn=g!==void 0&&g!==It,Ut=gt||tn,nn=await Hc({privatecode:V,...me?{endpoint:me}:{},ppeOverride:et});if(Ut){$.warn("pair config switched, resetting agents",{pcChanged:gt,envChanged:tn,previousPc:h?sa(h):"",nextPc:sa(V),previousEnvKey:g??"",nextEnvKey:It});for(let Te of[...u.agents.values()])await Te.dispose("pair config switch").catch(()=>{}),u.agents.delete(Te.agentId);u.disconnectedAgents.size>0&&($.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new $r,"pair switch").catch(()=>{})}w=nn.deviceId,hs({deviceId:w,pid:process.pid}),pd({patToken:V,env:j.env}).catch(Te=>$.warn("coze-cli setup error (ignored)",{err:String(Te)}));let Xr=new rs({handshake:nn,privatecode:V,...we?{urlOverride:we}:{},ppeOverride:et,getPatTokenForAgent:Te=>u.agents.get(Te)?.patToken});await c.swap(Xr,"pair");try{let Te=new Vn;o.frameworksCache=await Te.detectAll(),await Ki(o),$.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Te){$.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Te)})}let be=Object.keys(o.frameworksCache??{});try{let Te=await u.sendRequest("_agent/pair",{pairCode:re,patToken:V,frameworks:be,_meta:{cozeDeviceId:w}});$.info("_agent/pair ok",{pairResult:Te}),h=V,g=It,v=et,_=me,j.mock_scenario!==void 0&&(u.setMockScenario(j.mock_scenario),$.info("mock scenario set",{scenario:j.mock_scenario})),is(V,t).catch(Ne=>$.warn("writePatToken after /pair failed (ignored)",{err:String(Ne)})),E||(E=new Fi({core:u,getDeviceId:()=>w??"",onTickEnd:()=>B.retryPending().catch(Ne=>$.warn("detailSync.retryPending failed (ignored)",{err:String(Ne)})),onAuthFailures:Y})),E.start(),y(),Ut&&oa(t,x).catch(Ne=>$.warn("post-pair-switch auto-revive error (ignored)",{err:String(Ne)}));let tr;return j.agent_id&&(tr=await K1(j.agent_id,t,x,Ne=>u.sendRequest("_agent/detail",Ne),V).catch(Ne=>($.error("--agent-id ensureAgent failed",{agentId:j.agent_id,err:String(Ne)}),{ok:!1,agentId:j.agent_id??"",note:String(Ne)}))),{ok:!0,note:"paired with cloud",...tr?{agent:tr}:{}}}catch(Te){return $.error("_agent/pair failed",{err:String(Te)}),{ok:!1,note:`pair failed: ${String(Te)}`}}}},{method:"POST",path:"/connect",handler:P=>R(P)},{method:"POST",path:"/_agent/create",handler:async P=>{let j=P;return{ok:!0,result:await x.createAgent(j)}}},{method:"POST",path:"/agent/send",handler:async P=>{let j=P;if(!j?.agentId||!j?.sessionId||!j?.kind||!j?.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 V=j;return await(V.groupFile?ox:sx)(V,{core:u,patToken:h,handshakeBase:_,ppeOverride:v})}catch(V){if(V instanceof k)return{ok:!1,code:V.code,message:V.message};throw V}}},{method:"POST",path:"/reload",handler:async P=>{let j=P?.agent_id,V=await u.reloadAgents(j);return $.info("IPC /reload: recycled agent subprocesses",{agentId:j??"(all)",recycled:V}),{ok:!0,recycled:V}}},{method:"POST",path:"/shutdown",handler:async()=>($.info("IPC /shutdown received"),setImmediate(()=>{ce.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:se,token:Q}=await Z.start();try{await Vh(t.libEntry,t)}catch(P){$.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(P)})}await u.start(),$1({paths:t,core:u,agentManager:x,detectAll:async()=>(o.frameworksCache=await new Vn().detectAll(),await Ki(o),o.frameworksCache)}).catch(P=>$.warn("startup warmup error (ignored)",{err:String(P)})),Ol().then(async()=>{let{probeAcpVersion:P}=await Promise.resolve().then(()=>(an(),Rl));for(let j of["claude-code","codex"]){let V=await P(j);V&&$.info("acp wrapper version",{framework:j,version:V})}}).catch(P=>$.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(P)}));let ae=null,ce={port:se,token:Q,core:u,ipc:Z,shutdown(P){return ae||($.info("daemon shutdown",{reason:P}),ae=(async()=>{E?.stop(),I?.stop(),await u.stop(P),await Z.stop(),await e.release()})(),ae)}};for(let P of["SIGTERM","SIGINT"])process.on(P,()=>{ce.shutdown(P).then(()=>process.exit(0))});return process.on("exit",()=>k0()),process.on("unhandledRejection",P=>{$.error("unhandledRejection",{reason:P instanceof Error?P.message:String(P),stack:P instanceof Error?P.stack:void 0})}),process.on("uncaughtException",P=>{$.error("uncaughtException (will exit, supervisor will restart)",{message:P.message,stack:P.stack,name:P.name});try{process.stderr.write(`FATAL uncaughtException: ${P.stack??P.message}
|
|
112
|
-
`)}catch{}process.exit(1)})
|
|
113
|
-
`)){let u=d.indexOf("=");u<=0||(c[d.slice(0,u)]=d.slice(u+1))}return c}function
|
|
114
|
-
`;await
|
|
115
|
-
`).filter(d=>d.length>0).filter(d=>
|
|
116
|
-
`)}async function
|
|
117
|
-
`),1;for(let
|
|
118
|
-
`);return 0}let o=t.date??
|
|
117
|
+
`)}catch{}}let e=new na({processTitle:Mr}),r=await e.acquire();if(r.kind==="already-running")throw new Error(`coze-bridge daemon already running (pid=${r.pid})`);let i=await Co(),o=i??{};xs({pid:process.pid}),q.info(i?"loaded bridge config":"initialized bridge config");let c=new Qo(new $r),d=null,u=new Ro({upstream:c,paths:t,bridgeConfig:o,sessionSpawner:async(D,U,W,te)=>{if(!d)throw new Error("agentManager not ready");return d.spawnSessionDownstream(D,U,W,te)}}),h=new Ao({paths:t,config:o,registry:u});d=h;let x,m,_=null,S={},y,v=null,I=null,A=null,C=new Tn;function P(D,U){return C.enqueue(()=>R(D,U))}function b(){I||(I=new ia({isConnected:()=>c.isConnected()&&!(v?.isLivenessLost()??!1),forceReconnect:()=>A?P(A,{force:!0}):void 0,onFatal:D=>{if(process.env[os]==="1"){q.error("upstream watchdog fatal, but daemon is unmanaged (CLI-spawned) \u2014 staying alive for soft-reconnect instead of exiting",{downMs:D});return}q.error("upstream watchdog fatal: exiting for supervisor restart",{downMs:D}),process.exit(1)}})),I.start()}async function R(D,U){let W=D,te=W?.privatecode;if(!te)throw new T("IPC_BAD_REQUEST","/connect requires privatecode");let nt=Bi(W.env),pe=W.handshake_url,ge=W.frontier_url,kt=np(W.env,pe,ge);if(A=W,!U?.force&&x===te&&m===kt){let ye=await QS(t);return u.agents.size===0&&ye?(q.warn("/connect noop but core.agents empty with configs on disk; re-running auto-revive"),oa(t,h).catch(Re=>q.warn("connect-noop auto-revive error (ignored)",{err:String(Re)}))):q.info("/connect: already connected with same PAT + env, noop"),{ok:!0,note:"already connected"}}let wt=!!x&&x!==te,sn=m!==void 0&&m!==kt,qt=wt||sn,on=await Wc({privatecode:te,...pe?{endpoint:pe}:{},ppeOverride:nt});if(qt){q.warn("connect config switched, resetting agents",{pcChanged:wt,envChanged:sn,previousPc:x?sa(x):"",nextPc:sa(te)});for(let ye of[...u.agents.values()])await ye.dispose("connect config switch").catch(()=>{}),u.agents.delete(ye.agentId);u.disconnectedAgents.size>0&&(q.info("clearing disconnectedAgents set on connect config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new $r,"connect switch").catch(()=>{})}_=on.deviceId,xs({deviceId:_,pid:process.pid}),md({patToken:te,env:W.env}).catch(ye=>q.warn("coze-cli setup error (ignored)",{err:String(ye)}));let Yr=new is({handshake:on,privatecode:te,...ge?{urlOverride:ge}:{},ppeOverride:nt,getPatTokenForAgent:ye=>u.agents.get(ye)?.patToken});return await c.swap(Yr,"connect"),x=te,m=kt,S=nt,y=pe,W.mock_scenario!==void 0&&(u.setMockScenario(W.mock_scenario),q.info("mock scenario set",{scenario:W.mock_scenario})),v||(v=new zi({core:u,getDeviceId:()=>_??"",onTickEnd:()=>N.retryPending().catch(ye=>q.warn("detailSync.retryPending failed (ignored)",{err:String(ye)})),onAuthFailures:J})),v.start(),b(),qt&&oa(t,h).catch(ye=>q.warn("post-connect-switch auto-revive error (ignored)",{err:String(ye)})),ss(te,t).catch(ye=>q.warn("writePatToken after /connect failed (ignored)",{err:String(ye)})),q.info("/connect: WS established",{deviceId:_}),{ok:!0,note:"connected"}}u.registerExtension("_agent/create",async D=>h.createAgent(D.params)),u.registerExtension("_agent/health",async()=>({ok:!0}));let O={},M=new xo({agents:u.agents,publishSkillToMarketplace:async D=>{let U=u.agents.get(D.agentId)?.patToken??x;if(!U)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");return Jx({patToken:U,zip:D.zip,...D.skillId?{skillId:D.skillId}:{},skillName:D.skillName,...D.description?{description:D.description}:{},agentId:D.agentId,...D.accountId?{accountId:D.accountId}:{}},{handshakeBase:y,ppeOverride:S})},disposeAndMarkDisconnected:async(D,U)=>{let W=u.agents.get(D);if(W){await h.cleanupOpenclawSessionProviders(W).catch(nt=>q.warn("cleanup openclaw providers failed (ignored)",{agentId:D,err:String(nt)}));let te=!0;try{await W.dispose(`disconnect: ${U}`)}catch(nt){te=!1,q.error("dispose during disconnect FAILED, leaving agent in error state",{agentId:D,err:String(nt)}),W.status="error"}te&&(W.status="disconnected",u.unregister(D),u.disconnectedAgents.add(D))}else u.disconnectedAgents.add(D)},disposeForDelete:async(D,U)=>{let W=u.agents.get(D);W&&(await h.cleanupOpenclawSessionProviders(W).catch(te=>q.warn("cleanup openclaw providers during delete failed (ignored)",{agentId:D,err:String(te)})),await W.dispose(`delete: ${U}`).catch(te=>q.warn("dispose during delete failed (ignored)",{agentId:D,err:String(te)})),u.unregister(D)),u.disconnectedAgents.delete(D)},detailSyncer:async D=>{if(!O.ref)throw new Error("agent-detail-sync not initialized yet");await O.ref.syncOne(D)},cleanupOpenclawProviders:async(D,U)=>{await h.cleanupOpenclawSessionProviders(D,U)},openclawRepair:async(D,U)=>{await h.openclawRepair(D,U)},isRuntimePendingPermission:D=>u.hasPendingPermissionFor(D)});u.registerExtension("_agent/listSkills",D=>M.listSkills(D.params)),u.registerExtension("_agent/addSkills",D=>M.addSkills(D.params)),u.registerExtension("_agent/removeSkills",D=>M.removeSkills(D.params)),u.registerExtension("_agent/publishSkill",D=>M.publishSkill(D.params)),u.registerExtension("_agent/getFileTree",D=>M.getFileTree(D.params)),u.registerExtension("_agent/getFileContent",D=>M.getFileContent(D.params)),u.registerExtension("_agent/update",D=>M.updateAgent(D.params)),u.registerExtension("_agent/disconnect",D=>M.disconnectAgent(D.params)),u.registerExtension("_agent/switchModel",D=>M.switchModel(D.params)),u.registerExtension("_agent/reset",D=>M.resetAgent(D.params)),u.registerExtension("_agent/repair",D=>M.repairAgent(D.params)),u.registerExtension("_agent/delete",D=>M.deleteAgent(D.params)),u.registerExtension("_agent/upgrade",D=>M.upgradeBridge(D.params));let N=new ys({paths:t,handlers:M,agentManager:h,sendDetail:D=>u.sendRequest("_agent/detail",D)});O.ref=N;let J=async D=>{await Promise.allSettled(D.map(async U=>{try{await M.disconnectAgent({agentId:U.agentId,reason:`auth_failure: code=${U.code} ${U.message}`}),q.info("agent disconnected due to auth failure from heartbeat response",{agentId:U.agentId,code:U.code,message:U.message})}catch(W){q.warn("disconnect during authFailure handling failed (ignored)",{agentId:U.agentId,err:String(W)})}}))};c.onConnect(({initial:D})=>{q.info("frontier upstream connected, triggering detail sync",{initial:D}),N.syncAll(D?"initial-connect":"reconnect").catch(U=>q.warn("detail sync top-level error (ignored)",{err:String(U)}))});let V=new Do({paths:t,routes:[{method:"GET",path:"/status",handler:async()=>{let D=u.getMockScenario();return{running:!0,pid:process.pid,nodeExecPath:process.execPath,nodeVersion:process.version,nodeArch:process.arch,spawnedBy:process.env[os]==="1"?"manual":"supervisor",agents:[...u.agents.keys()],deviceId:_??"",frameworksCache:o.frameworksCache??{},...D?{mockScenario:D}:{}}}},{method:"POST",path:"/pair",handler:async D=>{let U=D,W=U?.privatecode,te=U?.pairing_code;if(!W||!te)throw new T("IPC_BAD_REQUEST","/pair requires privatecode + pairing_code");let nt=Bi(U.env),pe=U.handshake_url,ge=U.frontier_url,kt=np(U.env,pe,ge),wt=!!x&&x!==W,sn=m!==void 0&&m!==kt,qt=wt||sn,on=await Wc({privatecode:W,...pe?{endpoint:pe}:{},ppeOverride:nt});if(qt){q.warn("pair config switched, resetting agents",{pcChanged:wt,envChanged:sn,previousPc:x?sa(x):"",nextPc:sa(W),previousEnvKey:m??"",nextEnvKey:kt});for(let Re of[...u.agents.values()])await Re.dispose("pair config switch").catch(()=>{}),u.agents.delete(Re.agentId);u.disconnectedAgents.size>0&&(q.info("clearing disconnectedAgents set on pair config switch",{count:u.disconnectedAgents.size}),u.disconnectedAgents.clear()),await c.swap(new $r,"pair switch").catch(()=>{})}_=on.deviceId,xs({deviceId:_,pid:process.pid}),md({patToken:W,env:U.env}).catch(Re=>q.warn("coze-cli setup error (ignored)",{err:String(Re)}));let Yr=new is({handshake:on,privatecode:W,...ge?{urlOverride:ge}:{},ppeOverride:nt,getPatTokenForAgent:Re=>u.agents.get(Re)?.patToken});await c.swap(Yr,"pair");try{let Re=new Jn;o.frameworksCache=await Re.detectAll(),await $i(o),q.info("frameworks_cache refreshed before pair",{detected:Object.keys(o.frameworksCache)})}catch(Re){q.warn("frameworks_cache refresh failed (ignored, using cached)",{err:String(Re)})}let ye=Object.keys(o.frameworksCache??{});try{let Re=await u.sendRequest("_agent/pair",{pairCode:te,patToken:W,frameworks:ye,_meta:{cozeDeviceId:_}});q.info("_agent/pair ok",{pairResult:Re}),x=W,m=kt,S=nt,y=pe,U.mock_scenario!==void 0&&(u.setMockScenario(U.mock_scenario),q.info("mock scenario set",{scenario:U.mock_scenario})),ss(W,t).catch(Me=>q.warn("writePatToken after /pair failed (ignored)",{err:String(Me)})),v||(v=new zi({core:u,getDeviceId:()=>_??"",onTickEnd:()=>N.retryPending().catch(Me=>q.warn("detailSync.retryPending failed (ignored)",{err:String(Me)})),onAuthFailures:J})),v.start(),b(),qt&&oa(t,h).catch(Me=>q.warn("post-pair-switch auto-revive error (ignored)",{err:String(Me)}));let nr;return U.agent_id&&(nr=await t1(U.agent_id,t,h,Me=>u.sendRequest("_agent/detail",Me),W).catch(Me=>(q.error("--agent-id ensureAgent failed",{agentId:U.agent_id,err:String(Me)}),{ok:!1,agentId:U.agent_id??"",note:String(Me)}))),{ok:!0,note:"paired with cloud",...nr?{agent:nr}:{}}}catch(Re){return q.error("_agent/pair failed",{err:String(Re)}),{ok:!1,note:`pair failed: ${String(Re)}`}}}},{method:"POST",path:"/connect",handler:D=>P(D)},{method:"POST",path:"/_agent/create",handler:async D=>{let U=D;return{ok:!0,result:await h.createAgent(U)}}},{method:"POST",path:"/agent/send",handler:async D=>{let U=D;if(!U?.agentId||!U?.sessionId||!U?.kind||!U?.path)throw new T("IPC_BAD_REQUEST","/agent/send requires agentId, sessionId, kind, path");if(!x)throw new T("UPSTREAM_NOT_READY","daemon not yet paired with cloud (run --pair-code first)");try{let W=U;return await(W.groupFile?dh:ch)(W,{core:u,patToken:x,handshakeBase:y,ppeOverride:S})}catch(W){if(W instanceof T)return{ok:!1,code:W.code,message:W.message};throw W}}},{method:"POST",path:"/reload",handler:async D=>{let U=D?.agent_id,W=await u.reloadAgents(U);return q.info("IPC /reload: recycled agent subprocesses",{agentId:U??"(all)",recycled:W}),{ok:!0,recycled:W}}},{method:"POST",path:"/shutdown",handler:async()=>(q.info("IPC /shutdown received"),setImmediate(()=>{ae.shutdown("ipc /shutdown")}),{ok:!0})}]}),{port:re,token:Y}=await V.start();try{await Xx(t.libEntry,t)}catch(D){q.warn("bin shim install failed (D72 send \u547D\u4EE4\u53EF\u80FD\u4E0D\u53EF\u7528)",{err:String(D)})}await u.start(),n1({paths:t,core:u,agentManager:h,detectAll:async()=>(o.frameworksCache=await new Jn().detectAll(),await $i(o),o.frameworksCache)}).catch(D=>q.warn("startup warmup error (ignored)",{err:String(D)})),Nl().then(async()=>{let{probeAcpVersion:D}=await Promise.resolve().then(()=>(dn(),Ol));for(let U of["claude-code","codex"]){let W=await D(U);W&&q.info("acp wrapper version",{framework:U,version:W})}}).catch(D=>q.warn("acp wrapper warmup / probe top-level error (ignored)",{err:String(D)}));let se=null,ae={port:re,token:Y,core:u,ipc:V,shutdown(D){return se||(q.info("daemon shutdown",{reason:D}),se=(async()=>{v?.stop(),I?.stop(),await u.stop(D),await V.stop(),await e.release()})(),se)}};for(let D of["SIGTERM","SIGINT"])process.on(D,()=>{ae.shutdown(D).then(()=>process.exit(0))});return process.on("exit",()=>C0()),process.on("unhandledRejection",D=>{q.error("unhandledRejection",{reason:D instanceof Error?D.message:String(D),stack:D instanceof Error?D.stack:void 0})}),process.on("uncaughtException",D=>{q.error("uncaughtException (will exit, supervisor will restart)",{message:D.message,stack:D.stack,name:D.name});try{process.stderr.write(`FATAL uncaughtException: ${D.stack??D.message}
|
|
118
|
+
`)}catch{}process.exit(1)}),q.info("daemon ready",{port:re,pid:process.pid,nodeVersion:process.version,platform:process.platform,frameworks:Object.keys(o.frameworksCache??{}),libVersion:o.libVersion??"dev"}),i1({cliSpawned:process.env[os]==="1",readPatToken:()=>ea(t),connect:P}).catch(D=>q.warn("maybeAutoConnectOnStartup error (ignored)",{err:String(D)})),ae}async function QS(t){return ms(t).length>0}function sa(t){return t.length<=8?"***":`${t.slice(0,4)}***${t.slice(-4)}`}function np(t,e,r){return`${t??""}|${e??""}|${r??""}`}async function e1(t,e){let r=ms(t);if(r.length===0)return;let{loadAgentConfig:i,enforceAgentConfigMode:o}=await Promise.resolve().then(()=>(fn(),_s));for(let c of r){await o(c,t).catch(d=>q.warn("enforceAgentConfigMode failed (ignored)",{agentId:c,err:String(d)}));try{let d=await i(c,t);d?.deletedAt?(e.disconnectedAgents.add(c),q.info("agent marked deleted on startup",{agentId:c,deletedAt:d.deletedAt,reason:d.deleteReason??""})):d?.disconnectedAt&&(e.disconnectedAgents.add(c),q.info("agent marked disconnected on startup",{agentId:c,disconnectedAt:d.disconnectedAt,reason:d.disconnectReason??""}))}catch(d){q.warn("failed to load agent config on startup, skipping",{agentId:c,err:String(d)})}}}async function t1(t,e,r,i,o){let{loadAgentConfig:c}=await Promise.resolve().then(()=>(fn(),_s)),d=await c(t,e);if(d){if(d.deletedAt)throw new T("AGENT_NOT_FOUND",`agent ${t} \u5DF2\u88AB\u5220\u9664 (deletedAt=${d.deletedAt}), \u4E0D\u80FD\u901A\u8FC7 --agent-id \u590D\u6D3B`);q.info("--agent-id: local config found, reconnecting",{agentId:t,framework:d.framework,hadDisconnect:!!d.disconnectedAt});let m=ip(d),_={agentId:d.agentId,framework:d.framework,...d.cozeIdentity?{cozeIdentity:d.cozeIdentity}:{},...d.model?{model:d.model}:{},...o?{patToken:o}:{},...m?{_meta:m}:{}};return await r.createAgent(_),{ok:!0,agentId:t,note:d.disconnectedAt?"revived from local config":"connected from local config"}}q.info("--agent-id: local config missing, pulling _agent/detail from cloud",{agentId:t});let u=await i({_meta:{cozeAgentId:t}});if(!u.framework)throw new T("AGENT_NOT_FOUND",`agent ${t} \u4E0D\u5728\u672C\u5730; \u4E91\u7AEF _agent/detail \u54CD\u5E94\u7F3A framework \u5B57\u6BB5 (D36 \u534F\u8BAE\u6269\u5C55\u672A\u751F\u6548), \u65E0\u6CD5\u5728\u672C\u673A\u65B0\u5EFA`);let h={agentId:u.agentId,framework:u.framework,...u.cozeIdentity?{cozeIdentity:u.cozeIdentity}:{},...u.model?{model:u.model}:{},...o?{patToken:o}:{},...u.deployType?{_meta:{cozeDeployType:u.deployType}}:{}};await r.createAgent(h);let x=u.deployType==="cloud"&&u.framework==="openclaw";return{ok:!0,agentId:t,note:x?"cloud agent acknowledged":"created from cloud detail"}}async function n1(t){let e=t.logger??q;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 e1(t.paths,t.core).catch(r=>e.warn("scanAgentsOnStartup failed (ignored)",{err:String(r)})),await oa(t.paths,t.agentManager).catch(r=>e.warn("auto-revive top-level error (ignored)",{err:String(r)})),await r1(t.paths).catch(r=>e.warn("builtin skill refresh top-level error (ignored)",{err:String(r)}))}async function oa(t,e){let{readdir:r}=await import("node:fs/promises"),i;try{i=await r(t.agentsRoot)}catch{return{revived:0,skipped:0,total:0}}if(i.length===0)return{revived:0,skipped:0,total:0};let{loadAgentConfig:o}=await Promise.resolve().then(()=>(fn(),_s));q.info("auto-revive: scanning local agents on startup",{count:i.length});let c=0,d=0;for(let u of i){let h;try{h=await o(u,t)}catch(x){q.warn("auto-revive: load config failed (skipping)",{agentId:u,err:String(x)}),d+=1;continue}if(!h){d+=1;continue}if(h.deletedAt){q.info("auto-revive: skip deleted agent",{agentId:u,deletedAt:h.deletedAt}),d+=1;continue}if(h.disconnectedAt){q.info("auto-revive: skip disconnected agent",{agentId:u,disconnectedAt:h.disconnectedAt}),d+=1;continue}try{q.info("auto-revive: re-registering agent (D44 no spawn)",{agentId:u,framework:h.framework});let x=ip(h);await e.createAgent({agentId:h.agentId,framework:h.framework,...h.cozeIdentity?{cozeIdentity:h.cozeIdentity}:{},...h.model?{model:h.model}:{},...x?{_meta:x}:{}},{revive:!0}),c+=1}catch(x){q.warn("auto-revive: createAgent failed (skipping)",{agentId:u,framework:h.framework,err:String(x)}),d+=1}}return q.info("auto-revive: done",{revived:c,skipped:d,total:i.length}),{revived:c,skipped:d,total:i.length}}async function r1(t){let{readdir:e}=await import("node:fs/promises"),r;try{r=await e(t.agentsRoot)}catch{return{refreshed:0,total:0}}if(r.length===0)return{refreshed:0,total:0};let i=0;for(let o of r)try{(await g0(o,t)).status==="refreshed"&&(i+=1)}catch(c){q.warn("refresh builtin skills failed (skipping agent)",{agentId:o,err:String(c)})}return i>0&&q.info("builtin skills refresh on startup done",{refreshed:i,total:r.length}),{refreshed:i,total:r.length}}async function i1(t){let e=t.logger??q;if(t.cliSpawned)return"skipped-cli";let r=await t.readPatToken();return r?(e.info("supervisor-spawned daemon, auto-connecting with stored PAT"),t.connect({privatecode:r}).catch(i=>e.warn("startup auto-connect failed (staying idle)",{err:String(i)})),"connecting"):(e.info("no stored PAT, skip startup auto-connect"),"skipped-no-pat")}function ip(t){let e={};return t.deployType&&(e.cozeDeployType=t.deployType),t.accountId&&(e.cozeAccountId=t.accountId),Object.keys(e).length>0?e:void 0}ra();Be();import{readFile as sp}from"node:fs/promises";var rn=class{paths;constructor(e){this.paths=e??ee()}async probe(e=1e3){let r=await aa(this.paths);if(!r)return{kind:"not-running"};try{let i=await this.fetch(r,{method:"GET",path:"/status",timeoutMs:e});return i.status===200?{kind:"connected",...r,body:i.body}:{kind:"stale",reason:`unexpected status ${i.status}`}}catch(i){return{kind:"stale",reason:o1(i)}}}async request(e){let r=await aa(this.paths);if(!r)throw new Error("coze-bridge daemon not running (no port/token files)");return this.fetch(r,e)}async fetch(e,r){let i=r.body!==void 0,o={Authorization:`Bearer ${e.token}`};i&&(o["content-type"]="application/json");let c=new AbortController,d=setTimeout(()=>c.abort(),r.timeoutMs??5e3);try{let u=await fetch(`http://127.0.0.1:${e.port}${r.path}`,{method:r.method,headers:o,body:i?JSON.stringify(r.body):void 0,signal:c.signal}),h=await u.text();return{status:u.status,body:s1(h)}}finally{clearTimeout(d)}}};async function aa(t){try{let[e,r]=await Promise.all([sp(t.portFile,"utf8"),sp(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 s1(t){if(!t)return null;try{return JSON.parse(t)}catch{return t}}function o1(t){return t instanceof Error?t.message:String(t)}Xt();ne();or();import{spawn as a1}from"node:child_process";import{userInfo as ap}from"node:os";var Vd="__COZE_BRIDGE_ENV_SENTINEL_5f3c91__",c1=new Set(["bash","zsh","sh","dash","ksh"]),op=Ze("COZE_BRIDGE_SHELLENV_TIMEOUT_MS",1e4),d1=2e3;function l1(t,e=Vd){let r=t.indexOf(e);if(r===-1)return null;let i=t.indexOf(e,r+e.length);if(i===-1)return null;let o=t.slice(r+e.length,i),c={};for(let d of o.split(`
|
|
119
|
+
`)){let u=d.indexOf("=");u<=0||(c[d.slice(0,u)]=d.slice(u+1))}return c}function u1(){let t=(process.env.SHELL??"").trim()||(ap().shell??"").trim();if(!t)return null;let e=t.slice(t.lastIndexOf("/")+1);return c1.has(e)?t:null}function f1(t){return new Promise(e=>{let r=`printf '%s' '${Vd}'; env; printf '%s' '${Vd}'`,i;try{i=a1(t,["-ilc",r],{detached:!0,stdio:["ignore","pipe","ignore"],env:{...process.env,HOME:process.env.HOME??ap().homedir}})}catch{e(null);return}let o="",c=!1,d=m=>{try{i.pid&&process.kill(-i.pid,m)}catch{}},u=m=>{c||(c=!0,clearTimeout(h),clearTimeout(x),e(m))};i.stdout?.on("data",m=>{o+=m.toString("utf8")}),i.on("error",()=>u(null)),i.on("close",()=>u(o.length>0?o:null));let h=setTimeout(()=>d("SIGTERM"),op),x=setTimeout(()=>{d("SIGKILL"),u(o.length>0?o:null)},op+d1)})}async function Jd(t={}){if((t.platform??process.platform)==="win32")return{kind:"skipped",reason:"windows"};let r=u1();if(!r)return{kind:"skipped",reason:"no-supported-login-shell"};let i=await(t.run??f1)(r);if(i==null)return{kind:"failed",reason:"shell-timeout-or-error"};let o=l1(i);return o==null?{kind:"failed",reason:"unparseable-output"}:{kind:"ok",env:o}}Be();function Dn(t,...e){let r=[],i;for(let o=0;o<t.length;o++){let c=t[o],d=!1;for(let u of e){if(c===u){i=t[o+1],o+=1,d=!0;break}if(c.startsWith(`${u}=`)){i=c.slice(u.length+1),d=!0;break}}d||r.push(c)}return{value:i,rest:r}}dn();import{chmod as h1,copyFile as cp,mkdir as lp,readFile as cs,rename as dp,rm as Yd,stat as up,writeFile as x1}from"node:fs/promises";import{homedir as kP}from"node:os";import{dirname as p1,join as Ne,resolve as Qd,sep as as}from"node:path";import{fileURLToPath as g1}from"node:url";Xt();ne();Be();function Vr(t,e,r,i){it(t.bridgeLogsDir,e,"dist-install",r,i)}function fp(){return{darwin:{arm64:"@openai/codex-darwin-arm64",x64:"@openai/codex-darwin-x64"},linux:{arm64:"@openai/codex-linux-arm64",x64:"@openai/codex-linux-x64"},win32:{arm64:"@openai/codex-win32-arm64",x64:"@openai/codex-win32-x64"}}[process.platform]?.[process.arch]}function m1(){return{darwin:{arm64:Ne("vendor","aarch64-apple-darwin","bin","codex"),x64:Ne("vendor","x86_64-apple-darwin","bin","codex")},linux:{arm64:Ne("vendor","aarch64-unknown-linux-musl","bin","codex"),x64:Ne("vendor","x86_64-unknown-linux-musl","bin","codex")},win32:{arm64:Ne("vendor","aarch64-pc-windows-msvc","bin","codex.exe"),x64:Ne("vendor","x86_64-pc-windows-msvc","bin","codex.exe")}}[process.platform]?.[process.arch]}function w1(t){let e=g1(t),r=p1(e),i=`${as}src${as}`;if(r.includes(i)||r.endsWith(`${as}src${as}cli`))return null;let o=Qd(r,"index.js"),c=Qd(r,"..","package.json");return{dist:o,pkgJson:c}}async function el(t={}){let e=t.paths??ee(),r=w1(import.meta.url),i=t.sourceDist??r?.dist,o=t.sourcePackageJson??r?.pkgJson;if(!i||!o)return{kind:"dev-mode-skip",reason:"running from src/(tsx loader);no dist/ to install"};if(i===e.libEntry)return{kind:"dev-mode-skip",reason:"running from installed lib path; no re-install needed"};let c,d;try{let v=JSON.parse(await cs(o,"utf8"));c=v.version??"unknown",d=v.dependencies??{}}catch(v){throw Vr(e,"error","cannot read source package.json",{err:String(v)}),new Error(`cannot read source package.json: ${String(v)}`,{cause:v})}let u=ps.map(v=>({name:v,spec:d[v]??"latest"})),h=u.map(({name:v,spec:I})=>`${v}@${I}`),x=await Co(e.configFile)??{},m=x.libVersion,_=await cs(e.libEntry).then(()=>!0).catch(()=>!1),S=m===c,y=await hp(e,u);if(S&&_&&y)return{kind:"already-current",libVersion:c};if(!S||!_){await lp(e.libDir,{recursive:!0}),await cp(i,e.libEntry),await cp(`${i}.map`,`${e.libEntry}.map`).catch(()=>{});let v=Qd(e.libDir,"package.json"),I=`${JSON.stringify({type:"module"},null,2)}
|
|
120
|
+
`;await cs(v,"utf8").catch(()=>null)!==I&&await x1(v,I)}return y||(t.installWrappers?await t.installWrappers(e,h):await b1(e,h,u)),x.libVersion=c,await $i(x,e.configFile),Vr(e,"info","dist installed",{libEntry:e.libEntry,fromVersion:m,toVersion:c}),S&&_?{kind:"already-current",libVersion:c}:m?{kind:"version-changed",fromVersion:m,toVersion:c,libEntry:e.libEntry}:{kind:"first-install",libVersion:c,libEntry:e.libEntry}}async function hp(t,e){for(let r of e){let i=Ne(t.libDir,"node_modules",...r.name.split("/"),"package.json"),o;try{o=JSON.parse(await cs(i,"utf8"))}catch(d){return Vr(t,"debug","wrapper not ready: package.json read failed",{package:r.name,expected:r.spec,pkgJson:i,err:String(d)}),!1}let c=o.version;if(!c)return Vr(t,"debug","wrapper not ready: package.json \u7F3A version",{package:r.name,expected:r.spec,pkgJson:i}),!1;if(!_1(c,r.spec))return Vr(t,"debug","wrapper not ready: installed version does not satisfy expected range",{package:r.name,installed:c,expected:r.spec}),!1}return!!await xp(Ne(t.libDir,"node_modules"))}function _1(t,e){let r=Zd(t);if(!r)return!0;let i=e.trim();if(!i||i==="*"||i==="latest")return!0;if(i.startsWith("^")){let c=Zd(i.slice(1));if(!c)return!0;if(Xd(r,c)<0)return!1;let d=y1(c);return Xd(r,d)<0}let o=Zd(i);return o?Xd(r,o)===0:!0}function y1(t){return t[0]>0?[t[0]+1,0,0]:t[1]>0?[0,t[1]+1,0]:[0,0,t[2]+1]}function Zd(t){let e=t.match(/^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?$/);return e?[Number(e[1]),Number(e[2]??0),Number(e[3]??0)]:null}function Xd(t,e){for(let r=0;r<3;r++){let i=(t[r]??0)-(e[r]??0);if(i!==0)return i}return 0}async function b1(t,e,r){await S1(t.installLock,async()=>{if(await hp(t,r))return;let i=Math.random().toString(36).slice(2,10),o=`${t.libDir}${as}.staging-${process.pid}-${i}`,c=Ne(o,"node_modules"),d=Ne(t.libDir,"node_modules");try{await lp(o,{recursive:!0}),await E1(e,o),await v1(c);let u=`${d}.trash-${i}`;await dp(d,u).catch(()=>{}),await dp(c,d),await Yd(u,{recursive:!0,force:!0}).catch(()=>{}),Vr(t,"info","wrapper closure installed",{liveNm:d,specs:e})}finally{await Yd(o,{recursive:!0,force:!0}).catch(()=>{})}})}function E1(t,e){let r=["install",...t,"--prefix",e,"--omit=dev","--include=optional","--prefer-offline","--no-audit","--no-fund"];return new Promise((i,o)=>{let c=ot("npm",r,{stdio:["ignore","pipe","pipe"]}),d="";c.stderr?.on("data",h=>{d.length<8192&&(d+=h.toString("utf8"))});let u=setTimeout(()=>c.kill("SIGKILL"),18e4);c.once("error",h=>{clearTimeout(u),o(new Error(`spawn npm failed: ${String(h)}`))}),c.once("close",h=>{clearTimeout(u),h===0?i():o(new Error(`npm install \u9000\u51FA\u7801 ${h}: ${d.trim().slice(0,2e3)}`))})})}async function v1(t){for(let e of ps){let r=Ne(t,...e.split("/")),i=JSON.parse(await cs(Ne(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=Ne(t,".bin",o),d=await up(c);process.platform!=="win32"&&!(d.mode&73)&&await h1(c,d.mode|73).catch(()=>{})}if(!await xp(t)){let e=fp()??"<unsupported-platform>";throw new Error(`${e}: \u5F53\u524D\u5E73\u53F0 codex binary \u7F3A\u5931`)}}async function xp(t){let e=fp(),r=m1();if(!e||!r)return!0;let i=Ne(t,"@openai","codex"),o=Ne(t,...e.split("/")),c=[Ne(i,"package.json"),Ne(i,"bin","codex.js"),Ne(t,".bin",process.platform==="win32"?"codex.cmd":"codex"),Ne(o,"package.json"),Ne(o,r)];return(await Promise.all(c.map(u=>up(u).then(h=>h.isFile()).catch(()=>!1)))).every(Boolean)}async function S1(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 Yd(t,{force:!0}).catch(()=>{})}}Ca();ne();Be();import{closeSync as gp,fstatSync as mp,openSync as wp,readFileSync as I1,readSync as A1,readdirSync as k1,statSync as T1}from"node:fs";import{join as ca}from"node:path";var C1=new Set(["debug","info","warn","error"]);function _p(t){let e=t,r=Dn(e,"--agent-id");e=r.rest;let i=Dn(e,"--date");e=i.rest;let o=Dn(e,"-n","--lines");e=o.rest;let c=Dn(e,"--level");e=c.rest;let d=Dn(e,"--grep");e=d.rest;let u=o.value===void 0?200:Number(o.value),h=Number.isInteger(u)&&u>=0?u:200,x=c.value&&C1.has(c.value)?c.value:void 0,m={lines:h,follow:e.includes("-f")||e.includes("--follow"),raw:e.includes("--raw"),list:e.includes("--list")};return r.value&&(m.agentId=r.value),i.value&&(m.date=i.value),x&&(m.level=x),d.value&&(m.grep=d.value),m}function R1(t,e){return t.agentId?ca(Xe(t.agentId,e).logs,ar("agent",t.date)):ca(e.bridgeLogsDir,ar("bridge",t.date))}function D1(t,e){return e<=0||e>=t.length?t:t.slice(t.length-e)}function P1(t,e){let r;try{r=k1(t)}catch{return[]}let i=[];for(let o of r){let c=Ta(o,e);if(!c)continue;let d=0;try{d=T1(ca(t,o)).size}catch{}i.push({file:ca(t,o),date:c,size:d})}return i.sort((o,c)=>c.date.localeCompare(o.date)),i}function yp(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"&&!Tl(r,e.level))return!1}return!0}var pp={debug:"90",info:"36",warn:"33",error:"31"},O1=new Set(["ts","level","module","msg"]);function L1(t){if(typeof t!="string")return"";let e=t.split("T")[1];return e?e.slice(0,12):""}function bp(t,e){if(e.raw)return t;let r;try{r=JSON.parse(t)}catch{return t}let i=L1(r.ts),o=typeof r.level=="string"?r.level:"",c=o.toUpperCase().padEnd(5);e.color&&pp[o]&&(c=`\x1B[${pp[o]}m${c}\x1B[0m`);let d=typeof r.module=="string"?r.module:"",u=typeof r.msg=="string"?r.msg:"",h=Object.entries(r).filter(([x])=>!O1.has(x)).map(([x,m])=>` ${x}=${typeof m=="string"?m:JSON.stringify(m)}`).join("");return`${i} ${c} ${d} ${u}${h}`}function N1(t,e,r){let c=I1(t,"utf8").split(`
|
|
121
|
+
`).filter(d=>d.length>0).filter(d=>yp(d,{level:e.level,grep:e.grep}));for(let d of D1(c,e.lines))process.stdout.write(`${bp(d,{raw:e.raw,color:r})}
|
|
122
|
+
`)}async function Ep(t,e){let r=e.paths??ee(),i=process.stdout.isTTY===!0;if(t.list){let d=t.agentId?Xe(t.agentId,r).logs:r.bridgeLogsDir,u=t.agentId?"agent":"bridge",h=P1(d,u);if(h.length===0)return process.stderr.write(`coze-bridge log: \u65E0\u65E5\u5FD7\u6587\u4EF6\u4E8E ${d}
|
|
123
|
+
`),1;for(let x of h)process.stdout.write(`${x.date} ${(x.size/1024).toFixed(1)}KB ${x.file}
|
|
124
|
+
`);return 0}let o=t.date??On(new Date),c=R1({agentId:t.agentId,date:o},r);try{N1(c,t,i)}catch{return process.stderr.write(`coze-bridge log: \u627E\u4E0D\u5230\u65E5\u5FD7 ${c}
|
|
119
125
|
\u7528 'coze-bridge log${t.agentId?` --agent-id ${t.agentId}`:""} --list' \u770B\u6709\u54EA\u4E9B\u65E5\u671F\u3002
|
|
120
|
-
(legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${
|
|
121
|
-
`),1}return t.follow&&await
|
|
122
|
-
`);o=
|
|
123
|
-
`)}await new Promise(
|
|
126
|
+
(legacy \u6A21\u5F0F\u65E0 dated \u6587\u4EF6, \u89C1 ${r.logFile})
|
|
127
|
+
`),1}return t.follow&&await F1(c,t,i),0}var M1=500;function B1(t){try{let e=wp(t,"r");try{return mp(e).size}finally{gp(e)}}catch{return 0}}async function F1(t,e,r){let i=B1(t),o="",c=!1,d=()=>{c=!0};process.on("SIGINT",d);try{for(;!c;){let u="";try{let h=wp(t,"r");try{let x=mp(h).size;if(x>i){let m=Buffer.allocUnsafe(x-i),_=A1(h,m,0,m.length,i);u=m.subarray(0,_).toString("utf8"),i+=_}}finally{gp(h)}}catch{}if(u){let h=(o+u).split(`
|
|
128
|
+
`);o=h.pop()??"";for(let x of h)x.length>0&&yp(x,{level:e.level,grep:e.grep})&&process.stdout.write(`${bp(x,{raw:e.raw,color:r})}
|
|
129
|
+
`)}await new Promise(h=>setTimeout(h,M1))}}finally{process.off("SIGINT",d)}}import{basename as z1,resolve as U1}from"node:path";Be();var G1=9e4,H1={PATH_OUTSIDE_WORKSPACE:3,FILE_TOO_LARGE:3,UNSUPPORTED_MIME:3,MODEL_MODALITY_UNSUPPORTED:3,IPC_BAD_REQUEST:3,AGENT_NOT_FOUND:4,IPC_AUTH_FAILED:4,AGENT_DISCONNECTED:5,UPLOAD_FAILED:5,UPSTREAM_NOT_READY:5,UPSTREAM_DISCONNECTED:5,UPSTREAM_HANDSHAKE_FAILED:5,AGENT_BUSY:1,AGENT_SPAWN_FAILED:1,AGENT_TIMEOUT:1,AGENT_FRAME_IDLE_TIMEOUT:1,AGENT_PROTOCOL_ERROR:1,AGENT_TURN_ABORTED:1,BRIDGE_CONFIG_INVALID:1,BRIDGE_INTERNAL:1,MODEL_TOKEN_GEN_FAILED:1,OPERATION_NOT_ALLOWED_FOR_LOCAL:1,OPERATION_NOT_ALLOWED_FOR_CLOUD:1,METHOD_NOT_FOUND:1,AGENT_DEPENDENCY_INSTALL_FAILED:1,AGENT_APPROVAL_TIMEOUT:1,AGENT_ENV_NOT_READY:1,SKILL_NOT_FOUND:1,SKILL_ZIP_TOO_LARGE:1};function q1(t){return H1[t]??1}async function vp(t,e={}){let r=e.paths??ee();if(!t.agentId||!t.sessionId)return process.stderr.write(`Error: missing --agent-id and/or --session-id. These IDs come from the <coze-context> block injected at the top of each prompt \u2014 extract agentId and sessionId from there and pass them as flags. Example: coze-bridge send image x.png --agent-id <id> --session-id <id>
|
|
124
130
|
`),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.
|
|
125
|
-
`),3;let i=await aa(
|
|
126
|
-
`),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:
|
|
131
|
+
`),3;let i=await aa(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.
|
|
132
|
+
`),4;let o={agentId:t.agentId,sessionId:t.sessionId,kind:t.kind,path:t.groupFile?t.path:U1(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 j1(i,"/agent/send",o,G1)}catch(d){return process.stderr.write(`Error: daemon IPC failed: ${d instanceof Error?d.message:String(d)}
|
|
127
133
|
`),4}if(!c.ok)return process.stderr.write(`Error: ${c.code}: ${c.message}
|
|
128
|
-
`),
|
|
129
|
-
`);else{let d=t.name??
|
|
130
|
-
`)}else process.stdout.write(`Sent ${t.kind} ${d} (${
|
|
131
|
-
`)}return 0}async function
|
|
132
|
-
`)}function
|
|
134
|
+
`),q1(c.code);if(t.json)process.stdout.write(`${JSON.stringify(c)}
|
|
135
|
+
`);else{let d=t.name??z1(o.path);if(t.groupFile){let u=c.uri.length>60?`${c.uri.slice(0,57)}...`:c.uri;process.stdout.write(`Sent group file ${d} (uri=${u})
|
|
136
|
+
`)}else process.stdout.write(`Sent ${t.kind} ${d} (${W1(c.bytes)})
|
|
137
|
+
`)}return 0}async function j1(t,e,r,i){let o=new AbortController,c=setTimeout(()=>o.abort(),i);try{let d=await fetch(`http://127.0.0.1:${t.port}${e}`,{method:"POST",headers:{Authorization:`Bearer ${t.token}`,"content-type":"application/json"},body:JSON.stringify(r),signal:o.signal}),u=await d.text(),h=u?JSON.parse(u):null;return h&&typeof h=="object"&&"ok"in h?h:{ok:!1,code:"BRIDGE_INTERNAL",message:`unexpected daemon response (status=${d.status}): ${u.slice(0,200)}`}}finally{clearTimeout(c)}}function W1(t){return t<1024?`${t}B`:t<1024*1024?`${(t/1024).toFixed(1)}KB`:`${(t/1024/1024).toFixed(1)}MB`}var Op=H("cli");function $e(t,e){let{value:r,rest:i}=Dn(t,e);return{value:r,rest:i}}function xa(t,e){process.stderr.write(`[deprecated] '${t}' will be removed in a future release, use '${e}' instead
|
|
138
|
+
`)}function pI(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}=$e(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 gI(e.slice(1));if(e[0]==="log")return{mode:"log",..._p(e.slice(1))};if(e[0]==="connect")return mI(e.slice(1));if(e.includes("--status"))return xa("--status","coze-bridge status"),{mode:"status"};if(e.includes("--stop"))return xa("--stop","coze-bridge stop"),{mode:"stop"};if(e.includes("--uninstall"))return xa("--uninstall","coze-bridge purge"),{mode:"purge"};if(e.includes("--install-service"))return xa("--install-service","coze-bridge service install"),{mode:"service-install"};if(e.includes("--help")||e.includes("-h")||e.length===0)return{mode:"help"};let r=e,{value:i,rest:o}=$e(r,"--pat-token");r=o;let{value:c,rest:d}=$e(r,"--pair-code");r=d;let{value:u,rest:h}=$e(r,"--env");r=h;let{value:x,rest:m}=$e(r,"--handshake-url");r=m;let{value:_,rest:S}=$e(r,"--frontier-url");r=S;let{value:y,rest:v}=$e(r,"--mock-scenario");r=v;let{value:I}=$e(r,"--agent-id"),A=r.includes("--skip-rebuild-env");if(!i||!c)return{mode:"help"};let C={mode:"pair",privatecode:i,pairingCode:c};return u&&(C.env=u),x&&(C.handshakeUrl=x),_&&(C.frontierUrl=_),y&&(C.mockScenario=y),I&&(C.agentId=I),A&&(C.skipRebuildEnv=!0),C}function gI(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}=$e(i,"--caption");i=c;let{value:d,rest:u}=$e(i,"--name");i=u;let{value:h,rest:x}=$e(i,"--agent-id");i=x;let{value:m,rest:_}=$e(i,"--session-id");i=_;let{value:S,rest:y}=$e(i,"--mime");i=y;let v=i.includes("--group-file");i=i.filter(C=>C!=="--group-file");let I=i.includes("--json"),A={mode:"send",kind:e,path:r,json:I};return o&&(A.caption=o),d&&(A.name=d),h&&(A.agentId=h),m&&(A.sessionId=m),v&&(A.groupFile=!0),S&&(A.mimeType=S),A}function mI(t){let e=t,{value:r,rest:i}=$e(e,"--pat-token");e=i;let{value:o,rest:c}=$e(e,"--env");e=c;let{value:d,rest:u}=$e(e,"--handshake-url");e=u;let{value:h,rest:x}=$e(e,"--frontier-url");e=x;let{value:m,rest:_}=$e(e,"--mock-scenario");e=_;let S=e.includes("--skip-rebuild-env"),y={mode:"connect"};return r&&(y.privatecode=r),o&&(y.env=o),d&&(y.handshakeUrl=d),h&&(y.frontierUrl=h),m&&(y.mockScenario=m),S&&(y.skipRebuildEnv=!0),y}var wI=`
|
|
133
139
|
coze-bridge - local bridge daemon for cloud Agent Service
|
|
134
140
|
|
|
135
141
|
Pair (paste from cloud UI; start/reuse daemon and deliver pair-code):
|
|
@@ -210,57 +216,57 @@ Deprecated flags (still work, but emit a warning; will be removed in a future re
|
|
|
210
216
|
|
|
211
217
|
Internal:
|
|
212
218
|
<node> <entry> --daemon daemon mode (OS supervisor only)
|
|
213
|
-
`.trimStart();async function
|
|
214
|
-
`),0;case"daemon":{try{await
|
|
215
|
-
`),1;if(i.kind==="stale")return await
|
|
216
|
-
`),1;let o=await
|
|
219
|
+
`.trimStart();async function Lp(t=process.argv,e={}){let r=pI(t);switch(r.mode){case"help":return process.stdout.write(wI),0;case"version":return process.stdout.write(`${Nt}
|
|
220
|
+
`),0;case"daemon":{try{await rp()}catch(i){return Op.error("daemon start failed",{err:String(i)}),1}return new Promise(()=>{})}case"status":return _I(e);case"stop":return Mp(e);case"reload":return EI(r.agentId,e);case"log":return Ep(r,e);case"update":return yI(e);case"purge":return SI(e);case"service-install":return II(e);case"service-uninstall":return AI(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),kI(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),TI(r.privatecode,e,i,r.skipRebuildEnv)}case"send":return vp({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 Np(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 _I(t){let e=t.paths??ee(),r=new rn(e),i=await r.probe();if(i.kind==="not-running")return process.stdout.write(`coze-bridge: not running
|
|
221
|
+
`),1;if(i.kind==="stale")return await Np(e),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
222
|
+
`),1;let o=await r.request({method:"GET",path:"/status"});return process.stdout.write(`coze-bridge: running
|
|
217
223
|
${JSON.stringify(o.body,null,2)}
|
|
218
|
-
`),0}async function
|
|
219
|
-
`)}let u=await
|
|
224
|
+
`),0}async function Mp(t){let e=t.paths??ee(),r=new rn(e),i=t.daemonSweep??(async()=>{let h=R0();return await D0(h),h}),o=async()=>{t.skipProcessKill||await i(e)},c=await ls(t),d=!1;if(c)try{await c.uninstall(),d=!0}catch(h){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(h)}
|
|
225
|
+
`)}let u=await r.probe();if(u.kind==="not-running")return await o(),process.stdout.write(d?`coze-bridge: stopped
|
|
220
226
|
`:`coze-bridge: not running
|
|
221
|
-
`),0;if(u.kind==="stale")return await
|
|
222
|
-
`),0;try{return await
|
|
223
|
-
`),0}catch(
|
|
224
|
-
`),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(
|
|
225
|
-
`),1)}}async function
|
|
226
|
-
`),e(1)})})}async function
|
|
227
|
-
`),1;try{let o=await
|
|
227
|
+
`),0;if(u.kind==="stale")return await Np(e),await o(),process.stdout.write(`coze-bridge: not running (cleaned stale state)
|
|
228
|
+
`),0;try{return await r.request({method:"POST",path:"/shutdown"}),await o(),process.stdout.write(`coze-bridge: stopped
|
|
229
|
+
`),0}catch(h){return(await r.probe()).kind!=="connected"?(await o(),process.stdout.write(`coze-bridge: stopped
|
|
230
|
+
`),0):(await o(),process.stdout.write(`coze-bridge: stop failed: ${String(h)}
|
|
231
|
+
`),1)}}async function yI(t){return await Mp(t),(t.spawnNpx??bI)(["-y","--ignore-existing","coze-bridge@latest","connect"])}function bI(t){return new Promise(e=>{let r=ot("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)}
|
|
232
|
+
`),e(1)})})}async function EI(t,e){let r=new rn(e.paths);if((await r.probe()).kind==="not-running")return process.stdout.write(`coze-bridge: not running (start daemon first)
|
|
233
|
+
`),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)
|
|
228
234
|
`):process.stdout.write(`coze-bridge: reloaded ${c.length} agent(s): ${c.join(", ")||"(none)"}
|
|
229
235
|
`),0}return process.stderr.write(`coze-bridge: reload failed: ${JSON.stringify(o.body)}
|
|
230
236
|
`),1}catch(o){return process.stderr.write(`coze-bridge: reload failed: ${String(o)}
|
|
231
|
-
`),1}}async function
|
|
237
|
+
`),1}}async function ls(t){if(t.supervisor){let c=t.supervisor,d={nodeBin:"",entry:"",logFile:"",homeDir:"",userName:""};return{platform:c.platform,install:u=>c.install(d,u),uninstall:()=>c.uninstall(d)}}if(t.skipSupervisor)return;let{getSupervisor:e,buildContext:r}=await Promise.resolve().then(()=>(Rp(),Cp)),i=e(),o=r();return{platform:i.platform,install:c=>i.install(o,c),uninstall:()=>i.uninstall(o)}}async function Bp(t,e){let r=await e.probe(),i=t.waitTimeoutMs??15e3,o=t.sleep??CI,c=t.paths??ee();if(r.kind==="connected"){if(!vI(r.body))return r;it(c.bridgeLogsDir,"warn","cli","daemon Node \u4E0E\u5F53\u524D CLI \u4E0D\u4E00\u81F4, \u91CD\u542F daemon",{currentNode:process.execPath,currentArch:process.arch,daemon:r.body}),await e.request({method:"POST",path:"/shutdown"}).catch(h=>it(c.bridgeLogsDir,"warn","cli","restart for Node drift: shutdown failed",{err:String(h)})),await Pp(c.pidFile,o)}let d=t.spawnDaemon??tp,u=await ls(t);if(u&&(u.platform==="darwin"||u.platform==="linux")){try{await u.install({activate:!0});let h=await Dp(e,i,o);if(h.kind==="connected")return h;it(c.bridgeLogsDir,"warn","cli","supervisor \u8D77 daemon \u8D85\u65F6, \u56DE\u9000\u624B\u52A8 spawn (\u672C\u6B21\u65E0\u5D29\u6E83\u4FDD\u6D3B)",{waitMs:i})}catch(h){it(c.bridgeLogsDir,"warn","cli","supervisor \u63A5\u7BA1\u5931\u8D25, \u56DE\u9000\u624B\u52A8 spawn",{err:String(h)})}it(c.bridgeLogsDir,"warn","cli","\u79FB\u9664\u5F00\u673A\u81EA\u542F\u914D\u7F6E (supervisor \u63A5\u7BA1\u672A\u6210\u529F, \u56DE\u9000\u624B\u52A8 spawn; \u4E0B\u6B21\u91CD\u542F\u4E0D\u518D\u81EA\u542F, \u9700\u91CD\u65B0 service install)",{platform:u.platform}),await u.uninstall().catch(()=>{}),await Pp(c.pidFile,o)}else u&&await u.install({activate:!1}).catch(h=>process.stderr.write(`coze-bridge: \u81EA\u542F\u6CE8\u518C\u5931\u8D25(\u4E0D\u5F71\u54CD\u672C\u6B21): ${String(h)}
|
|
232
238
|
`));return process.stdout.write(`coze-bridge: starting daemon...
|
|
233
|
-
`),await d({paths:t.paths}),
|
|
239
|
+
`),await d({paths:t.paths}),Dp(e,i,o)}function vI(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.nodeExecPath!="string"||typeof e.nodeArch!="string"?!1:e.nodeExecPath!==process.execPath||e.nodeArch!==process.arch}async function SI(t){let e=new rn(t.paths);if((await e.probe()).kind==="connected"){process.stdout.write(`coze-bridge: stopping daemon...
|
|
234
240
|
`);try{await e.request({method:"POST",path:"/shutdown"})}catch(d){process.stderr.write(`coze-bridge: stop failed (continuing): ${String(d)}
|
|
235
|
-
`)}await new Promise(d=>setTimeout(d,500))}let i=await
|
|
241
|
+
`)}await new Promise(d=>setTimeout(d,500))}let i=await ls(t);if(i)try{await i.uninstall(),process.stdout.write(`coze-bridge: ${i.platform} supervisor unregistered
|
|
236
242
|
`)}catch(d){process.stderr.write(`coze-bridge: supervisor uninstall failed (continuing): ${String(d)}
|
|
237
|
-
`)}let o=t.paths??
|
|
243
|
+
`)}let o=t.paths??ee(),{rm:c}=await import("node:fs/promises");try{await c(o.bridgeRoot,{recursive:!0,force:!0}),process.stdout.write(`coze-bridge: removed ${o.bridgeRoot}
|
|
238
244
|
`)}catch(d){return process.stderr.write(`coze-bridge: remove failed: ${String(d)}
|
|
239
245
|
`),1}return process.stdout.write(`coze-bridge: purged (agents workspaces preserved under ~/.coze/agents)
|
|
240
|
-
`),0}async function
|
|
246
|
+
`),0}async function II(t){let e=await ls(t);if(!e)return 0;try{return process.stdout.write(`coze-bridge: installing ${e.platform} supervisor...
|
|
241
247
|
`),await e.install(),process.stdout.write(`coze-bridge: supervisor installed (daemon will auto-start on login)
|
|
242
|
-
`),0}catch(
|
|
243
|
-
`),1}}async function
|
|
244
|
-
`),0}catch(
|
|
245
|
-
`),1}}async function
|
|
246
|
-
`),
|
|
247
|
-
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(
|
|
248
|
-
`)}let
|
|
249
|
-
`),1;let
|
|
248
|
+
`),0}catch(r){return process.stderr.write(`coze-bridge: service install failed: ${String(r)}
|
|
249
|
+
`),1}}async function AI(t){let e=await ls(t);if(!e)return 0;try{return await e.uninstall(),process.stdout.write(`coze-bridge: ${e.platform} supervisor unregistered
|
|
250
|
+
`),0}catch(r){return process.stderr.write(`coze-bridge: service uninstall failed: ${String(r)}
|
|
251
|
+
`),1}}async function Fp(t,e,r){if(e)return it(t.bridgeLogsDir,"info","cli","agent-env: skip rebuild, use process.env",{}),process.env;let i=await r();return i.kind==="ok"?(it(t.bridgeLogsDir,"info","cli","agent-env: rebuilt from login shell",{vars:Object.keys(i.env).length}),i.env):i.kind==="skipped"?(it(t.bridgeLogsDir,"info","cli","agent-env: rebuild not applicable, use process.env",{reason:i.reason}),process.env):(process.stderr.write(`coze-bridge: \u91CD\u5EFA shell \u73AF\u5883\u5931\u8D25, \u56DE\u9000\u5F53\u524D\u8FDB\u7A0B\u73AF\u5883 (\u53EF\u7528 --skip-rebuild-env \u663E\u5F0F\u8DF3\u8FC7)
|
|
252
|
+
`),it(t.bridgeLogsDir,"warn","cli","reconstructLoginShellEnv failed, fell back to process.env",{reason:i.reason}),process.env)}async function kI(t,e,r,i={},o,c){let d=new rn(r.paths),u=r.paths??ee(),h=await Fp(u,c,r.reconstructEnv??Jd);if(await cd(u,h).catch(_=>it(u.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(_)})),!r.skipDistInstall){let _=await el({paths:r.paths});_.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${_.fromVersion} \u2192 ${_.toVersion}
|
|
253
|
+
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(y=>setTimeout(y,500)))):_.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${_.libVersion}
|
|
254
|
+
`)}let x=await Bp(r,d);if(x.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${x.kind}
|
|
255
|
+
`),1;let m={privatecode:t,pairing_code:e};i.env&&(m.env=i.env),i.handshakeUrl&&(m.handshake_url=i.handshakeUrl),i.frontierUrl&&(m.frontier_url=i.frontierUrl),i.mockScenario&&(m.mock_scenario=i.mockScenario),o&&(m.agent_id=o);try{let _=await d.request({method:"POST",path:"/pair",body:m,timeoutMs:35e3});if(_.status===200&&_.body?.ok){let S=_.body.agent;return S&&!S.ok?(process.stderr.write(`coze-bridge: paired but agent ensure failed (agentId=${S.agentId}): ${S.note}
|
|
250
256
|
`),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"
|
|
251
|
-
`),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(
|
|
252
|
-
`),1}catch(
|
|
253
|
-
`),1}}async function
|
|
254
|
-
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(
|
|
255
|
-
`)}let
|
|
256
|
-
`),1;let
|
|
257
|
-
`),t!==void 0&&await
|
|
258
|
-
`),1)}catch(
|
|
259
|
-
`),1}}async function
|
|
260
|
-
`),
|
|
257
|
+
`),0)}return process.stderr.write(`coze-bridge: pair failed: ${JSON.stringify(_.body)}
|
|
258
|
+
`),1}catch(_){return process.stderr.write(`coze-bridge: pair failed: ${String(_)}
|
|
259
|
+
`),1}}async function TI(t,e,r={},i){let o=e.paths??ee(),c=t??await ea(o);if(!c)return process.stderr.write("coze-bridge: \u627E\u4E0D\u5230 patToken \u2014 \u5148\u8DD1\u4E00\u6B21 `coze-bridge --pat-token=<sat_xxx> --pair-code=<xxx>` \u914D\u5BF9, \u6216\u672C\u6B21\u7528 `--pat-token` \u6307\u5B9A\n"),1;let d=new rn(e.paths),u=await Fp(o,i,e.reconstructEnv??Jd);if(await cd(o,u).catch(m=>it(o.bridgeLogsDir,"warn","cli","writeAgentEnv failed (ignored)",{err:String(m)})),!e.skipDistInstall){let m=await el({paths:e.paths});m.kind==="version-changed"?(process.stdout.write(`coze-bridge: upgraded ${m.fromVersion} \u2192 ${m.toVersion}
|
|
260
|
+
`),(await d.probe()).kind==="connected"&&(await d.request({method:"POST",path:"/shutdown"}).catch(()=>{}),await new Promise(S=>setTimeout(S,500)))):m.kind==="first-install"&&process.stdout.write(`coze-bridge: installed ${m.libVersion}
|
|
261
|
+
`)}let h=await Bp(e,d);if(h.kind!=="connected")return process.stderr.write(`coze-bridge: daemon did not come up: ${h.kind}
|
|
262
|
+
`),1;let x={privatecode:c};r.env&&(x.env=r.env),r.handshakeUrl&&(x.handshake_url=r.handshakeUrl),r.frontierUrl&&(x.frontier_url=r.frontierUrl),r.mockScenario&&(x.mock_scenario=r.mockScenario);try{let m=await d.request({method:"POST",path:"/connect",body:x,timeoutMs:35e3});return m.status===200&&m.body?.ok?(process.stdout.write(`coze-bridge: connected (${m.body.note??"ok"})
|
|
263
|
+
`),t!==void 0&&await ss(c,o).catch(_=>Op.warn("writePatToken after connect failed (ignored)",{err:String(_)})),0):(process.stderr.write(`coze-bridge: connect failed: ${JSON.stringify(m.body)}
|
|
264
|
+
`),1)}catch(m){return process.stderr.write(`coze-bridge: connect failed: ${String(m)}
|
|
265
|
+
`),1}}async function Dp(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 Pp(t,e,r=60,i=200){let{readFile:o}=await import("node:fs/promises");for(let c=0;c<r;c++){let d;try{d=await o(t,"utf8")}catch{return}let u=Number.parseInt(d.trim(),10);if(!Number.isFinite(u)||u<=0||!qi(u))return;await e(i)}}function CI(t){return new Promise(e=>setTimeout(e,t))}ne();function RI(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 zp(t=process.versions.node,e=i=>{process.stderr.write(i)},r=i=>process.exit(i)){let i=RI(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
|
|
266
|
+
`),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
|
|
261
267
|
\u5347\u7EA7\u5B8C\u540E\u9700\u8981\u6267\u884C\u4EE5\u4E0B\u547D\u4EE4\u91CD\u65B0\u8FDE\u63A5:
|
|
262
268
|
npx -y coze-bridge@latest stop
|
|
263
269
|
npx -y coze-bridge@latest connect
|
|
264
270
|
|
|
265
|
-
`)}
|
|
271
|
+
`)}zp();!process.argv.includes("--daemon")&&!process.env.COZE_BRIDGE_LOG_LEVEL&&Al("warn");Lp(process.argv).then(t=>process.exit(t),t=>{process.stderr.write(`fatal: ${t instanceof Error?t.stack??t.message:String(t)}
|
|
266
272
|
`),process.exit(1)});
|